forked from github_mirror/framelesshelper
win: simplify code a little
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
af6d3c7380
commit
53bf6016df
|
@ -143,36 +143,26 @@
|
||||||
# define USER_DEFAULT_SCREEN_DPI (96)
|
# define USER_DEFAULT_SCREEN_DPI (96)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _DPI_AWARENESS_CONTEXTS_
|
DECLARE_HANDLE(_DPI_AWARENESS_CONTEXT);
|
||||||
# define _DPI_AWARENESS_CONTEXTS_
|
|
||||||
DECLARE_HANDLE(DPI_AWARENESS_CONTEXT);
|
#ifndef _DPI_AWARENESS_CONTEXT_UNAWARE
|
||||||
using DPI_AWARENESS = enum DPI_AWARENESS
|
# define _DPI_AWARENESS_CONTEXT_UNAWARE (reinterpret_cast<_DPI_AWARENESS_CONTEXT>(-1))
|
||||||
{
|
|
||||||
DPI_AWARENESS_INVALID = -1,
|
|
||||||
DPI_AWARENESS_UNAWARE = 0,
|
|
||||||
DPI_AWARENESS_SYSTEM_AWARE = 1,
|
|
||||||
DPI_AWARENESS_PER_MONITOR_AWARE = 2
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DPI_AWARENESS_CONTEXT_UNAWARE
|
#ifndef _DPI_AWARENESS_CONTEXT_SYSTEM_AWARE
|
||||||
# define DPI_AWARENESS_CONTEXT_UNAWARE (reinterpret_cast<DPI_AWARENESS_CONTEXT>(-1))
|
# define _DPI_AWARENESS_CONTEXT_SYSTEM_AWARE (reinterpret_cast<_DPI_AWARENESS_CONTEXT>(-2))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DPI_AWARENESS_CONTEXT_SYSTEM_AWARE
|
#ifndef _DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
|
||||||
# define DPI_AWARENESS_CONTEXT_SYSTEM_AWARE (reinterpret_cast<DPI_AWARENESS_CONTEXT>(-2))
|
# define _DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE (reinterpret_cast<_DPI_AWARENESS_CONTEXT>(-3))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
|
#ifndef _DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
|
||||||
# define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE (reinterpret_cast<DPI_AWARENESS_CONTEXT>(-3))
|
# define _DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 (reinterpret_cast<_DPI_AWARENESS_CONTEXT>(-4))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
|
#ifndef _DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED
|
||||||
# define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 (reinterpret_cast<DPI_AWARENESS_CONTEXT>(-4))
|
# define _DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED (reinterpret_cast<_DPI_AWARENESS_CONTEXT>(-5))
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED
|
|
||||||
# define DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED (reinterpret_cast<DPI_AWARENESS_CONTEXT>(-5))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HKEY_CLASSES_ROOT
|
#ifndef HKEY_CLASSES_ROOT
|
||||||
|
@ -443,93 +433,7 @@ using ShouldSystemUseDarkModePtr = BOOL(WINAPI *)(VOID); // Ordinal 138
|
||||||
using SetPreferredAppModePtr = PREFERRED_APP_MODE(WINAPI *)(PREFERRED_APP_MODE); // Ordinal 135
|
using SetPreferredAppModePtr = PREFERRED_APP_MODE(WINAPI *)(PREFERRED_APP_MODE); // Ordinal 135
|
||||||
using IsDarkModeAllowedForAppPtr = BOOL(WINAPI *)(VOID); // Ordinal 139
|
using IsDarkModeAllowedForAppPtr = BOOL(WINAPI *)(VOID); // Ordinal 139
|
||||||
|
|
||||||
EXTERN_C_START
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT _MMRESULT WINAPI
|
|
||||||
timeGetDevCaps(
|
|
||||||
_Out_writes_bytes_(cbtc) _PTIMECAPS ptc,
|
|
||||||
_In_ UINT cbtc
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT _MMRESULT WINAPI
|
|
||||||
timeBeginPeriod(
|
|
||||||
_In_ UINT uPeriod
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT _MMRESULT WINAPI
|
|
||||||
timeEndPeriod(
|
|
||||||
_In_ UINT uPeriod
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT HRESULT WINAPI
|
|
||||||
SetProcessDpiAwareness(
|
|
||||||
_In_ _PROCESS_DPI_AWARENESS value
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT HRESULT WINAPI
|
|
||||||
GetDpiForMonitor(
|
|
||||||
_In_ HMONITOR hMonitor,
|
|
||||||
_In_ _MONITOR_DPI_TYPE dpiType,
|
|
||||||
_Out_ UINT *dpiX,
|
|
||||||
_Out_ UINT *dpiY
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT int WINAPI
|
|
||||||
GetSystemMetricsForDpi(
|
|
||||||
_In_ int nIndex,
|
|
||||||
_In_ UINT dpi
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT UINT WINAPI
|
|
||||||
GetDpiForWindow(
|
|
||||||
_In_ HWND hWnd
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT UINT WINAPI
|
|
||||||
GetDpiForSystem(
|
|
||||||
VOID
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT UINT WINAPI
|
|
||||||
GetSystemDpiForProcess(
|
|
||||||
_In_ HANDLE hProcess
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT BOOL WINAPI
|
|
||||||
SetProcessDpiAwarenessContext(
|
|
||||||
_In_ DPI_AWARENESS_CONTEXT value
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT BOOL WINAPI
|
|
||||||
SetProcessDPIAware(
|
|
||||||
VOID
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT HRESULT WINAPI
|
|
||||||
GetScaleFactorForMonitor(
|
|
||||||
_In_ HMONITOR hMon,
|
|
||||||
_Out_ _DEVICE_SCALE_FACTOR *pScale
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT BOOL WINAPI
|
|
||||||
EnableNonClientDpiScaling(
|
|
||||||
_In_ HWND hWnd
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT DPI_AWARENESS_CONTEXT WINAPI
|
|
||||||
GetWindowDpiAwarenessContext(
|
|
||||||
_In_ HWND hWnd
|
|
||||||
);
|
|
||||||
|
|
||||||
DECLSPEC_IMPORT DPI_AWARENESS WINAPI
|
|
||||||
GetAwarenessFromDpiAwarenessContext(
|
|
||||||
_In_ DPI_AWARENESS_CONTEXT value
|
|
||||||
);
|
|
||||||
|
|
||||||
EXTERN_C_END
|
|
||||||
|
|
||||||
[[maybe_unused]] inline constexpr const int kAutoHideTaskBarThickness = 2; // The thickness of an auto-hide taskbar in pixels.
|
[[maybe_unused]] inline constexpr const int kAutoHideTaskBarThickness = 2; // The thickness of an auto-hide taskbar in pixels.
|
||||||
|
|
||||||
[[maybe_unused]] inline constexpr const wchar_t kDwmRegistryKey[] = LR"(Software\Microsoft\Windows\DWM)";
|
[[maybe_unused]] inline constexpr const wchar_t kDwmRegistryKey[] = LR"(Software\Microsoft\Windows\DWM)";
|
||||||
[[maybe_unused]] inline constexpr const wchar_t kPersonalizeRegistryKey[] = LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)";
|
[[maybe_unused]] inline constexpr const wchar_t kPersonalizeRegistryKey[] = LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)";
|
||||||
[[maybe_unused]] inline constexpr const wchar_t kThemeSettingChangeEventName[] = L"ImmersiveColorSet";
|
[[maybe_unused]] inline constexpr const wchar_t kThemeSettingChangeEventName[] = L"ImmersiveColorSet";
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
Q_NODISCARD QFunctionPointer get(const QString &function);
|
Q_NODISCARD QFunctionPointer get(const QString &function);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Q_NODISCARD inline T get(const QString &function)
|
Q_NODISCARD T get(const QString &function)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<T>(get(function));
|
return reinterpret_cast<T>(get(function));
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,8 @@ FRAMELESSHELPER_END_NAMESPACE
|
||||||
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(SysApiLoader))
|
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(SysApiLoader))
|
||||||
|
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
# define API_WIN_AVAILABLE(lib, func) (SysApiLoader::instance()->isAvailable(k##lib, k##func))
|
# define API_WIN_AVAILABLE(lib, func) \
|
||||||
|
(FRAMELESSHELPER_PREPEND_NAMESPACE(SysApiLoader)::instance()->isAvailable(k##lib, k##func))
|
||||||
# define API_USER_AVAILABLE(func) API_WIN_AVAILABLE(user32, func)
|
# define API_USER_AVAILABLE(func) API_WIN_AVAILABLE(user32, func)
|
||||||
# define API_THEME_AVAILABLE(func) API_WIN_AVAILABLE(uxtheme, func)
|
# define API_THEME_AVAILABLE(func) API_WIN_AVAILABLE(uxtheme, func)
|
||||||
# define API_DWM_AVAILABLE(func) API_WIN_AVAILABLE(dwmapi, func)
|
# define API_DWM_AVAILABLE(func) API_WIN_AVAILABLE(dwmapi, func)
|
||||||
|
@ -76,4 +77,14 @@ Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(SysApiLoader))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define API_CALL_FUNCTION(func, ...) \
|
#define API_CALL_FUNCTION(func, ...) \
|
||||||
((SysApiLoader::instance()->get<decltype(&::func)>(k##func))(__VA_ARGS__))
|
((FRAMELESSHELPER_PREPEND_NAMESPACE(SysApiLoader)::instance()->get<decltype(&func)>(k##func))(__VA_ARGS__))
|
||||||
|
|
||||||
|
#define API_CALL_FUNCTION2(func, type, ...) \
|
||||||
|
((FRAMELESSHELPER_PREPEND_NAMESPACE(SysApiLoader)::instance()->get<type>(k##func))(__VA_ARGS__))
|
||||||
|
|
||||||
|
#define API_CALL_FUNCTION3(func, name, ...) \
|
||||||
|
((FRAMELESSHELPER_PREPEND_NAMESPACE(SysApiLoader)::instance()->get<decltype(&func)>(k##name))(__VA_ARGS__))
|
||||||
|
|
||||||
|
#define API_CALL_FUNCTION4(func, ...) API_CALL_FUNCTION3(_##func, func, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define API_CALL_FUNCTION5(func, ...) API_CALL_FUNCTION3(func##2, func, __VA_ARGS__)
|
||||||
|
|
|
@ -44,6 +44,91 @@
|
||||||
#include "winverhelper_p.h"
|
#include "winverhelper_p.h"
|
||||||
#include <d2d1.h>
|
#include <d2d1.h>
|
||||||
|
|
||||||
|
EXTERN_C_START
|
||||||
|
|
||||||
|
_MMRESULT WINAPI
|
||||||
|
_timeGetDevCaps(
|
||||||
|
_Out_writes_bytes_(cbtc) _PTIMECAPS ptc,
|
||||||
|
_In_ UINT cbtc
|
||||||
|
);
|
||||||
|
|
||||||
|
_MMRESULT WINAPI
|
||||||
|
_timeBeginPeriod(
|
||||||
|
_In_ UINT uPeriod
|
||||||
|
);
|
||||||
|
|
||||||
|
_MMRESULT WINAPI
|
||||||
|
_timeEndPeriod(
|
||||||
|
_In_ UINT uPeriod
|
||||||
|
);
|
||||||
|
|
||||||
|
HRESULT WINAPI
|
||||||
|
_SetProcessDpiAwareness(
|
||||||
|
_In_ _PROCESS_DPI_AWARENESS value
|
||||||
|
);
|
||||||
|
|
||||||
|
HRESULT WINAPI
|
||||||
|
_GetDpiForMonitor(
|
||||||
|
_In_ HMONITOR hMonitor,
|
||||||
|
_In_ _MONITOR_DPI_TYPE dpiType,
|
||||||
|
_Out_ UINT *dpiX,
|
||||||
|
_Out_ UINT *dpiY
|
||||||
|
);
|
||||||
|
|
||||||
|
int WINAPI
|
||||||
|
_GetSystemMetricsForDpi(
|
||||||
|
_In_ int nIndex,
|
||||||
|
_In_ UINT dpi
|
||||||
|
);
|
||||||
|
|
||||||
|
UINT WINAPI
|
||||||
|
_GetDpiForWindow(
|
||||||
|
_In_ HWND hWnd
|
||||||
|
);
|
||||||
|
|
||||||
|
UINT WINAPI
|
||||||
|
_GetDpiForSystem(
|
||||||
|
VOID
|
||||||
|
);
|
||||||
|
|
||||||
|
UINT WINAPI
|
||||||
|
_GetSystemDpiForProcess(
|
||||||
|
_In_ HANDLE hProcess
|
||||||
|
);
|
||||||
|
|
||||||
|
BOOL WINAPI
|
||||||
|
_SetProcessDpiAwarenessContext(
|
||||||
|
_In_ _DPI_AWARENESS_CONTEXT value
|
||||||
|
);
|
||||||
|
|
||||||
|
BOOL WINAPI
|
||||||
|
_SetProcessDPIAware(
|
||||||
|
VOID
|
||||||
|
);
|
||||||
|
|
||||||
|
HRESULT WINAPI
|
||||||
|
_GetScaleFactorForMonitor(
|
||||||
|
_In_ HMONITOR hMon,
|
||||||
|
_Out_ _DEVICE_SCALE_FACTOR *pScale
|
||||||
|
);
|
||||||
|
|
||||||
|
BOOL WINAPI
|
||||||
|
_EnableNonClientDpiScaling(
|
||||||
|
_In_ HWND hWnd
|
||||||
|
);
|
||||||
|
|
||||||
|
_DPI_AWARENESS_CONTEXT WINAPI
|
||||||
|
_GetWindowDpiAwarenessContext(
|
||||||
|
_In_ HWND hWnd
|
||||||
|
);
|
||||||
|
|
||||||
|
_DPI_AWARENESS WINAPI
|
||||||
|
_GetAwarenessFromDpiAwarenessContext(
|
||||||
|
_In_ _DPI_AWARENESS_CONTEXT value
|
||||||
|
);
|
||||||
|
|
||||||
|
EXTERN_C_END
|
||||||
|
|
||||||
EXTERN_C [[nodiscard]] FRAMELESSHELPER_CORE_API BOOL WINAPI
|
EXTERN_C [[nodiscard]] FRAMELESSHELPER_CORE_API BOOL WINAPI
|
||||||
GetWindowCompositionAttribute(const HWND hWnd, PWINDOWCOMPOSITIONATTRIBDATA pvData)
|
GetWindowCompositionAttribute(const HWND hWnd, PWINDOWCOMPOSITIONATTRIBDATA pvData)
|
||||||
{
|
{
|
||||||
|
@ -53,15 +138,13 @@ GetWindowCompositionAttribute(const HWND hWnd, PWINDOWCOMPOSITIONATTRIBDATA pvDa
|
||||||
SetLastError(ERROR_INVALID_PARAMETER);
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
FRAMELESSHELPER_USE_NAMESPACE
|
|
||||||
FRAMELESSHELPER_STRING_CONSTANT(user32)
|
FRAMELESSHELPER_STRING_CONSTANT(user32)
|
||||||
FRAMELESSHELPER_STRING_CONSTANT(GetWindowCompositionAttribute)
|
FRAMELESSHELPER_STRING_CONSTANT(GetWindowCompositionAttribute)
|
||||||
const auto loader = SysApiLoader::instance();
|
if (!API_USER_AVAILABLE(GetWindowCompositionAttribute)) {
|
||||||
if (!loader->isAvailable(kuser32, kGetWindowCompositionAttribute)) {
|
|
||||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return (loader->get<GetWindowCompositionAttributePtr>(kGetWindowCompositionAttribute))(hWnd, pvData);
|
return API_CALL_FUNCTION(GetWindowCompositionAttribute, hWnd, pvData);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXTERN_C [[nodiscard]] FRAMELESSHELPER_CORE_API BOOL WINAPI
|
EXTERN_C [[nodiscard]] FRAMELESSHELPER_CORE_API BOOL WINAPI
|
||||||
|
@ -73,19 +156,17 @@ SetWindowCompositionAttribute(const HWND hWnd, PWINDOWCOMPOSITIONATTRIBDATA pvDa
|
||||||
SetLastError(ERROR_INVALID_PARAMETER);
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
FRAMELESSHELPER_USE_NAMESPACE
|
|
||||||
FRAMELESSHELPER_STRING_CONSTANT(user32)
|
FRAMELESSHELPER_STRING_CONSTANT(user32)
|
||||||
FRAMELESSHELPER_STRING_CONSTANT(SetWindowCompositionAttribute)
|
FRAMELESSHELPER_STRING_CONSTANT(SetWindowCompositionAttribute)
|
||||||
const auto loader = SysApiLoader::instance();
|
if (!API_USER_AVAILABLE(SetWindowCompositionAttribute)) {
|
||||||
if (!loader->isAvailable(kuser32, kSetWindowCompositionAttribute)) {
|
|
||||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return (loader->get<SetWindowCompositionAttributePtr>(kSetWindowCompositionAttribute))(hWnd, pvData);
|
return API_CALL_FUNCTION(SetWindowCompositionAttribute, hWnd, pvData);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXTERN_C [[nodiscard]] FRAMELESSHELPER_CORE_API HRESULT WINAPI
|
EXTERN_C [[nodiscard]] FRAMELESSHELPER_CORE_API HRESULT WINAPI
|
||||||
SetWindowThemeAttribute2(const HWND hWnd, const _WINDOWTHEMEATTRIBUTETYPE attrib,
|
_SetWindowThemeAttribute(const HWND hWnd, const _WINDOWTHEMEATTRIBUTETYPE attrib,
|
||||||
PVOID pvData, const DWORD cbData
|
PVOID pvData, const DWORD cbData
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -94,23 +175,21 @@ SetWindowThemeAttribute2(const HWND hWnd, const _WINDOWTHEMEATTRIBUTETYPE attrib
|
||||||
if (!hWnd || !pvData) {
|
if (!hWnd || !pvData) {
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
}
|
}
|
||||||
FRAMELESSHELPER_USE_NAMESPACE
|
|
||||||
FRAMELESSHELPER_STRING_CONSTANT(uxtheme)
|
FRAMELESSHELPER_STRING_CONSTANT(uxtheme)
|
||||||
FRAMELESSHELPER_STRING_CONSTANT(SetWindowThemeAttribute)
|
FRAMELESSHELPER_STRING_CONSTANT(SetWindowThemeAttribute)
|
||||||
const auto loader = SysApiLoader::instance();
|
if (!API_THEME_AVAILABLE(SetWindowThemeAttribute)) {
|
||||||
if (!loader->isAvailable(kuxtheme, kSetWindowThemeAttribute)) {
|
|
||||||
return E_NOTIMPL;
|
return E_NOTIMPL;
|
||||||
}
|
}
|
||||||
return (loader->get<decltype(&SetWindowThemeAttribute2)>(kSetWindowThemeAttribute))(hWnd, attrib, pvData, cbData);
|
return API_CALL_FUNCTION4(SetWindowThemeAttribute, hWnd, attrib, pvData, cbData);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXTERN_C [[nodiscard]] FRAMELESSHELPER_CORE_API HRESULT WINAPI
|
EXTERN_C [[nodiscard]] FRAMELESSHELPER_CORE_API HRESULT WINAPI
|
||||||
SetWindowThemeNonClientAttributes2(const HWND hWnd, const DWORD dwMask, const DWORD dwAttributes)
|
_SetWindowThemeNonClientAttributes(const HWND hWnd, const DWORD dwMask, const DWORD dwAttributes)
|
||||||
{
|
{
|
||||||
WTA_OPTIONS2 options = {};
|
WTA_OPTIONS2 options = {};
|
||||||
options.dwFlags = dwAttributes;
|
options.dwFlags = dwAttributes;
|
||||||
options.dwMask = dwMask;
|
options.dwMask = dwMask;
|
||||||
return SetWindowThemeAttribute2(hWnd, _WTA_NONCLIENT, &options, sizeof(options));
|
return _SetWindowThemeAttribute(hWnd, _WTA_NONCLIENT, &options, sizeof(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
EXTERN_C [[nodiscard]] FRAMELESSHELPER_CORE_API BOOL WINAPI
|
EXTERN_C [[nodiscard]] FRAMELESSHELPER_CORE_API BOOL WINAPI
|
||||||
|
@ -553,7 +632,7 @@ struct SYSTEM_METRIC
|
||||||
const UINT realDpi = Utils::getWindowDpi(windowId, horizontal);
|
const UINT realDpi = Utils::getWindowDpi(windowId, horizontal);
|
||||||
if (API_USER_AVAILABLE(GetSystemMetricsForDpi)) {
|
if (API_USER_AVAILABLE(GetSystemMetricsForDpi)) {
|
||||||
const UINT dpi = (scaled ? realDpi : USER_DEFAULT_SCREEN_DPI);
|
const UINT dpi = (scaled ? realDpi : USER_DEFAULT_SCREEN_DPI);
|
||||||
return API_CALL_FUNCTION(GetSystemMetricsForDpi, index, dpi);
|
return API_CALL_FUNCTION4(GetSystemMetricsForDpi, index, dpi);
|
||||||
} else {
|
} else {
|
||||||
const qreal dpr = (scaled ? qreal(1) : (qreal(realDpi) / qreal(USER_DEFAULT_SCREEN_DPI)));
|
const qreal dpr = (scaled ? qreal(1) : (qreal(realDpi) / qreal(USER_DEFAULT_SCREEN_DPI)));
|
||||||
return qRound(qreal(GetSystemMetrics(index)) / dpr);
|
return qRound(qreal(GetSystemMetrics(index)) / dpr);
|
||||||
|
@ -993,16 +1072,10 @@ void Utils::syncWmPaintWithDwm()
|
||||||
if (!isDwmCompositionEnabled()) {
|
if (!isDwmCompositionEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!API_WINMM_AVAILABLE(timeGetDevCaps)) {
|
if (!(API_WINMM_AVAILABLE(timeGetDevCaps)
|
||||||
return;
|
&& API_WINMM_AVAILABLE(timeBeginPeriod)
|
||||||
}
|
&& API_WINMM_AVAILABLE(timeEndPeriod)
|
||||||
if (!API_WINMM_AVAILABLE(timeBeginPeriod)) {
|
&& API_DWM_AVAILABLE(DwmGetCompositionTimingInfo))) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!API_WINMM_AVAILABLE(timeEndPeriod)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!API_DWM_AVAILABLE(DwmGetCompositionTimingInfo)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Dirty hack to workaround the resize flicker caused by DWM.
|
// Dirty hack to workaround the resize flicker caused by DWM.
|
||||||
|
@ -1012,12 +1085,12 @@ void Utils::syncWmPaintWithDwm()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_TIMECAPS tc = {};
|
_TIMECAPS tc = {};
|
||||||
if (API_CALL_FUNCTION(timeGetDevCaps, &tc, sizeof(tc)) != MMSYSERR_NOERROR) {
|
if (API_CALL_FUNCTION4(timeGetDevCaps, &tc, sizeof(tc)) != MMSYSERR_NOERROR) {
|
||||||
WARNING << "timeGetDevCaps() failed.";
|
WARNING << "timeGetDevCaps() failed.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const UINT ms_granularity = tc.wPeriodMin;
|
const UINT ms_granularity = tc.wPeriodMin;
|
||||||
if (API_CALL_FUNCTION(timeBeginPeriod, ms_granularity) != TIMERR_NOERROR) {
|
if (API_CALL_FUNCTION4(timeBeginPeriod, ms_granularity) != TIMERR_NOERROR) {
|
||||||
WARNING << "timeBeginPeriod() failed.";
|
WARNING << "timeBeginPeriod() failed.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1058,7 +1131,7 @@ void Utils::syncWmPaintWithDwm()
|
||||||
Q_ASSERT(m < period);
|
Q_ASSERT(m < period);
|
||||||
const qreal m_ms = (1000.0 * qreal(m) / qreal(freq.QuadPart));
|
const qreal m_ms = (1000.0 * qreal(m) / qreal(freq.QuadPart));
|
||||||
Sleep(static_cast<DWORD>(qRound(m_ms)));
|
Sleep(static_cast<DWORD>(qRound(m_ms)));
|
||||||
if (API_CALL_FUNCTION(timeEndPeriod, ms_granularity) != TIMERR_NOERROR) {
|
if (API_CALL_FUNCTION4(timeEndPeriod, ms_granularity) != TIMERR_NOERROR) {
|
||||||
WARNING << "timeEndPeriod() failed.";
|
WARNING << "timeEndPeriod() failed.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1082,7 +1155,7 @@ quint32 Utils::getPrimaryScreenDpi(const bool horizontal)
|
||||||
// GetDpiForMonitor() is only available on Windows 8 and onwards.
|
// GetDpiForMonitor() is only available on Windows 8 and onwards.
|
||||||
if (API_SHCORE_AVAILABLE(GetDpiForMonitor)) {
|
if (API_SHCORE_AVAILABLE(GetDpiForMonitor)) {
|
||||||
UINT dpiX = 0, dpiY = 0;
|
UINT dpiX = 0, dpiY = 0;
|
||||||
const HRESULT hr = API_CALL_FUNCTION(GetDpiForMonitor, hMonitor, _MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
|
const HRESULT hr = API_CALL_FUNCTION4(GetDpiForMonitor, hMonitor, _MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
|
||||||
if (SUCCEEDED(hr) && (dpiX > 0) && (dpiY > 0)) {
|
if (SUCCEEDED(hr) && (dpiX > 0) && (dpiY > 0)) {
|
||||||
return (horizontal ? dpiX : dpiY);
|
return (horizontal ? dpiX : dpiY);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1092,7 +1165,7 @@ quint32 Utils::getPrimaryScreenDpi(const bool horizontal)
|
||||||
// GetScaleFactorForMonitor() is only available on Windows 8 and onwards.
|
// GetScaleFactorForMonitor() is only available on Windows 8 and onwards.
|
||||||
if (API_SHCORE_AVAILABLE(GetScaleFactorForMonitor)) {
|
if (API_SHCORE_AVAILABLE(GetScaleFactorForMonitor)) {
|
||||||
_DEVICE_SCALE_FACTOR factor = _DEVICE_SCALE_FACTOR_INVALID;
|
_DEVICE_SCALE_FACTOR factor = _DEVICE_SCALE_FACTOR_INVALID;
|
||||||
const HRESULT hr = API_CALL_FUNCTION(GetScaleFactorForMonitor, hMonitor, &factor);
|
const HRESULT hr = API_CALL_FUNCTION4(GetScaleFactorForMonitor, hMonitor, &factor);
|
||||||
if (SUCCEEDED(hr) && (factor != _DEVICE_SCALE_FACTOR_INVALID)) {
|
if (SUCCEEDED(hr) && (factor != _DEVICE_SCALE_FACTOR_INVALID)) {
|
||||||
return quint32(qRound(qreal(USER_DEFAULT_SCREEN_DPI) * qreal(factor) / qreal(100)));
|
return quint32(qRound(qreal(USER_DEFAULT_SCREEN_DPI) * qreal(factor) / qreal(100)));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1198,7 +1271,7 @@ quint32 Utils::getWindowDpi(const WId windowId, const bool horizontal)
|
||||||
}
|
}
|
||||||
const auto hwnd = reinterpret_cast<HWND>(windowId);
|
const auto hwnd = reinterpret_cast<HWND>(windowId);
|
||||||
if (API_USER_AVAILABLE(GetDpiForWindow)) {
|
if (API_USER_AVAILABLE(GetDpiForWindow)) {
|
||||||
const UINT dpi = API_CALL_FUNCTION(GetDpiForWindow, hwnd);
|
const UINT dpi = API_CALL_FUNCTION4(GetDpiForWindow, hwnd);
|
||||||
if (dpi > 0) {
|
if (dpi > 0) {
|
||||||
return dpi;
|
return dpi;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1206,7 +1279,7 @@ quint32 Utils::getWindowDpi(const WId windowId, const bool horizontal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (API_USER_AVAILABLE(GetSystemDpiForProcess)) {
|
if (API_USER_AVAILABLE(GetSystemDpiForProcess)) {
|
||||||
const UINT dpi = API_CALL_FUNCTION(GetSystemDpiForProcess, GetCurrentProcess());
|
const UINT dpi = API_CALL_FUNCTION4(GetSystemDpiForProcess, GetCurrentProcess());
|
||||||
if (dpi > 0) {
|
if (dpi > 0) {
|
||||||
return dpi;
|
return dpi;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1214,7 +1287,7 @@ quint32 Utils::getWindowDpi(const WId windowId, const bool horizontal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (API_USER_AVAILABLE(GetDpiForSystem)) {
|
if (API_USER_AVAILABLE(GetDpiForSystem)) {
|
||||||
const UINT dpi = API_CALL_FUNCTION(GetDpiForSystem);
|
const UINT dpi = API_CALL_FUNCTION4(GetDpiForSystem);
|
||||||
if (dpi > 0) {
|
if (dpi > 0) {
|
||||||
return dpi;
|
return dpi;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1552,12 +1625,12 @@ void Utils::setAeroSnappingEnabled(const WId windowId, const bool enable)
|
||||||
void Utils::tryToEnableHighestDpiAwarenessLevel()
|
void Utils::tryToEnableHighestDpiAwarenessLevel()
|
||||||
{
|
{
|
||||||
if (API_USER_AVAILABLE(SetProcessDpiAwarenessContext)) {
|
if (API_USER_AVAILABLE(SetProcessDpiAwarenessContext)) {
|
||||||
const auto SetProcessDpiAwarenessContext2 = [](const DPI_AWARENESS_CONTEXT context) -> bool {
|
const auto SetProcessDpiAwarenessContext2 = [](const _DPI_AWARENESS_CONTEXT context) -> bool {
|
||||||
Q_ASSERT(context);
|
Q_ASSERT(context);
|
||||||
if (!context) {
|
if (!context) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (API_CALL_FUNCTION(SetProcessDpiAwarenessContext, context) != FALSE) {
|
if (API_CALL_FUNCTION4(SetProcessDpiAwarenessContext, context) != FALSE) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const DWORD dwError = GetLastError();
|
const DWORD dwError = GetLastError();
|
||||||
|
@ -1572,22 +1645,22 @@ void Utils::tryToEnableHighestDpiAwarenessLevel()
|
||||||
WARNING << __getSystemErrorMessage(kSetProcessDpiAwarenessContext, dwError);
|
WARNING << __getSystemErrorMessage(kSetProcessDpiAwarenessContext, dwError);
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
if (SetProcessDpiAwarenessContext2(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)) {
|
if (SetProcessDpiAwarenessContext2(_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (SetProcessDpiAwarenessContext2(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE)) {
|
if (SetProcessDpiAwarenessContext2(_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (SetProcessDpiAwarenessContext2(DPI_AWARENESS_CONTEXT_SYSTEM_AWARE)) {
|
if (SetProcessDpiAwarenessContext2(_DPI_AWARENESS_CONTEXT_SYSTEM_AWARE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (SetProcessDpiAwarenessContext2(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED)) {
|
if (SetProcessDpiAwarenessContext2(_DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (API_SHCORE_AVAILABLE(SetProcessDpiAwareness)) {
|
if (API_SHCORE_AVAILABLE(SetProcessDpiAwareness)) {
|
||||||
const auto SetProcessDpiAwareness2 = [](const _PROCESS_DPI_AWARENESS pda) -> bool {
|
const auto SetProcessDpiAwareness2 = [](const _PROCESS_DPI_AWARENESS pda) -> bool {
|
||||||
const HRESULT hr = API_CALL_FUNCTION(SetProcessDpiAwareness, pda);
|
const HRESULT hr = API_CALL_FUNCTION4(SetProcessDpiAwareness, pda);
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1618,7 +1691,7 @@ void Utils::tryToEnableHighestDpiAwarenessLevel()
|
||||||
// Some really old MinGW SDK may lack this function, we workaround this
|
// Some really old MinGW SDK may lack this function, we workaround this
|
||||||
// issue by always load it dynamically at runtime.
|
// issue by always load it dynamically at runtime.
|
||||||
if (API_USER_AVAILABLE(SetProcessDPIAware)) {
|
if (API_USER_AVAILABLE(SetProcessDPIAware)) {
|
||||||
if (API_CALL_FUNCTION(SetProcessDPIAware) == FALSE) {
|
if (API_CALL_FUNCTION4(SetProcessDPIAware) == FALSE) {
|
||||||
WARNING << getSystemErrorMessage(kSetProcessDPIAware);
|
WARNING << getSystemErrorMessage(kSetProcessDPIAware);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1731,10 +1804,8 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
|
||||||
}
|
}
|
||||||
const auto hwnd = reinterpret_cast<HWND>(windowId);
|
const auto hwnd = reinterpret_cast<HWND>(windowId);
|
||||||
if (WindowsVersionHelper::isWin8OrGreater()) {
|
if (WindowsVersionHelper::isWin8OrGreater()) {
|
||||||
if (!API_DWM_AVAILABLE(DwmSetWindowAttribute)) {
|
if (!(API_DWM_AVAILABLE(DwmSetWindowAttribute)
|
||||||
return false;
|
&& API_DWM_AVAILABLE(DwmExtendFrameIntoClientArea))) {
|
||||||
}
|
|
||||||
if (!API_DWM_AVAILABLE(DwmExtendFrameIntoClientArea)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const BlurMode blurMode = [mode]() -> BlurMode {
|
const BlurMode blurMode = [mode]() -> BlurMode {
|
||||||
|
@ -1975,7 +2046,7 @@ void Utils::hideOriginalTitleBarElements(const WId windowId, const bool disable)
|
||||||
const auto hwnd = reinterpret_cast<HWND>(windowId);
|
const auto hwnd = reinterpret_cast<HWND>(windowId);
|
||||||
static constexpr const DWORD validBits = (WTNCA_NODRAWCAPTION | WTNCA_NODRAWICON | WTNCA_NOSYSMENU);
|
static constexpr const DWORD validBits = (WTNCA_NODRAWCAPTION | WTNCA_NODRAWICON | WTNCA_NOSYSMENU);
|
||||||
const DWORD mask = (disable ? validBits : 0);
|
const DWORD mask = (disable ? validBits : 0);
|
||||||
const HRESULT hr = SetWindowThemeNonClientAttributes2(hwnd, mask, mask);
|
const HRESULT hr = _SetWindowThemeNonClientAttributes(hwnd, mask, mask);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
WARNING << __getSystemErrorMessage(kSetWindowThemeAttribute, hr);
|
WARNING << __getSystemErrorMessage(kSetWindowThemeAttribute, hr);
|
||||||
}
|
}
|
||||||
|
@ -2146,17 +2217,16 @@ void Utils::enableNonClientAreaDpiScalingForWindow(const WId windowId)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto hwnd = reinterpret_cast<HWND>(windowId);
|
const auto hwnd = reinterpret_cast<HWND>(windowId);
|
||||||
const DPI_AWARENESS_CONTEXT context = API_CALL_FUNCTION(GetWindowDpiAwarenessContext, hwnd);
|
const _DPI_AWARENESS_CONTEXT context = API_CALL_FUNCTION4(GetWindowDpiAwarenessContext, hwnd);
|
||||||
if (!context) {
|
if (!context) {
|
||||||
WARNING << getSystemErrorMessage(kGetWindowDpiAwarenessContext);
|
WARNING << getSystemErrorMessage(kGetWindowDpiAwarenessContext);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto awareness = static_cast<_DPI_AWARENESS>(
|
const _DPI_AWARENESS awareness = API_CALL_FUNCTION4(GetAwarenessFromDpiAwarenessContext, context);
|
||||||
API_CALL_FUNCTION(GetAwarenessFromDpiAwarenessContext, context));
|
|
||||||
if (awareness == _DPI_AWARENESS_PER_MONITOR_AWARE_V2) {
|
if (awareness == _DPI_AWARENESS_PER_MONITOR_AWARE_V2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (API_CALL_FUNCTION(EnableNonClientDpiScaling, hwnd) == FALSE) {
|
if (API_CALL_FUNCTION4(EnableNonClientDpiScaling, hwnd) == FALSE) {
|
||||||
WARNING << getSystemErrorMessage(kEnableNonClientDpiScaling);
|
WARNING << getSystemErrorMessage(kEnableNonClientDpiScaling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue