Minor tweaks

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2021-07-17 15:35:55 +08:00
parent 39aef26671
commit bdbfc96eb0
6 changed files with 38 additions and 48 deletions

View File

@ -127,6 +127,7 @@ if(WIN32)
endif() endif()
target_link_libraries(${PROJECT_NAME} PRIVATE target_link_libraries(${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::CorePrivate
Qt${QT_VERSION_MAJOR}::GuiPrivate Qt${QT_VERSION_MAJOR}::GuiPrivate
) )

View File

@ -74,7 +74,7 @@
#define GET_Y_LPARAM(lp) ((int) (short) HIWORD(lp)) #define GET_Y_LPARAM(lp) ((int) (short) HIWORD(lp))
#endif #endif
static inline bool shouldHaveWindowFrame() [[nodiscard]] static inline bool shouldHaveWindowFrame()
{ {
if (Utilities::shouldUseNativeTitleBar()) { if (Utilities::shouldUseNativeTitleBar()) {
// We have to use the original window frame unconditionally if we // We have to use the original window frame unconditionally if we

View File

@ -44,24 +44,24 @@ public:
explicit FramelessQuickHelper(QQuickItem *parent = nullptr); explicit FramelessQuickHelper(QQuickItem *parent = nullptr);
~FramelessQuickHelper() override = default; ~FramelessQuickHelper() override = default;
int borderWidth() const; [[nodiscard]] int borderWidth() const;
void setBorderWidth(const int val); void setBorderWidth(const int val);
int borderHeight() const; [[nodiscard]] int borderHeight() const;
void setBorderHeight(const int val); void setBorderHeight(const int val);
int titleBarHeight() const; [[nodiscard]] int titleBarHeight() const;
void setTitleBarHeight(const int val); void setTitleBarHeight(const int val);
bool resizable() const; [[nodiscard]] bool resizable() const;
void setResizable(const bool val); void setResizable(const bool val);
QColor nativeFrameColor() const; [[nodiscard]] QColor nativeFrameColor() const;
public Q_SLOTS: public Q_SLOTS:
void removeWindowFrame(); void removeWindowFrame();
void bringBackWindowFrame(); void bringBackWindowFrame();
bool isWindowFrameless() const; [[nodiscard]] bool isWindowFrameless() const;
void setHitTestVisibleInChrome(QQuickItem *item, const bool visible); void setHitTestVisibleInChrome(QQuickItem *item, const bool visible);
Q_SIGNALS: Q_SIGNALS:

View File

@ -35,15 +35,15 @@ namespace FramelessWindowsManager {
FRAMELESSHELPER_API void addWindow(QWindow *window); FRAMELESSHELPER_API void addWindow(QWindow *window);
FRAMELESSHELPER_API void removeWindow(QWindow *window); FRAMELESSHELPER_API void removeWindow(QWindow *window);
FRAMELESSHELPER_API bool isWindowFrameless(const QWindow *window); [[nodiscard]] FRAMELESSHELPER_API bool isWindowFrameless(const QWindow *window);
FRAMELESSHELPER_API void setHitTestVisibleInChrome(QWindow *window, QObject *object, const bool value = true); FRAMELESSHELPER_API void setHitTestVisibleInChrome(QWindow *window, QObject *object, const bool value = true);
FRAMELESSHELPER_API int getBorderWidth(const QWindow *window); [[nodiscard]] FRAMELESSHELPER_API int getBorderWidth(const QWindow *window);
FRAMELESSHELPER_API void setBorderWidth(QWindow *window, const int value); FRAMELESSHELPER_API void setBorderWidth(QWindow *window, const int value);
FRAMELESSHELPER_API int getBorderHeight(const QWindow *window); [[nodiscard]] FRAMELESSHELPER_API int getBorderHeight(const QWindow *window);
FRAMELESSHELPER_API void setBorderHeight(QWindow *window, const int value); FRAMELESSHELPER_API void setBorderHeight(QWindow *window, const int value);
FRAMELESSHELPER_API int getTitleBarHeight(const QWindow *window); [[nodiscard]] FRAMELESSHELPER_API int getTitleBarHeight(const QWindow *window);
FRAMELESSHELPER_API void setTitleBarHeight(QWindow *window, const int value); FRAMELESSHELPER_API void setTitleBarHeight(QWindow *window, const int value);
FRAMELESSHELPER_API bool getResizable(const QWindow *window); [[nodiscard]] FRAMELESSHELPER_API bool getResizable(const QWindow *window);
FRAMELESSHELPER_API void setResizable(QWindow *window, const bool value = true); FRAMELESSHELPER_API void setResizable(QWindow *window, const bool value = true);
} }

View File

@ -38,32 +38,31 @@ enum class SystemMetric
}; };
// Common // Common
FRAMELESSHELPER_API int getSystemMetric(const QWindow *window, const SystemMetric metric, const bool dpiAware, const bool forceSystemValue = false); [[nodiscard]] FRAMELESSHELPER_API int getSystemMetric(const QWindow *window, const SystemMetric metric, const bool dpiAware, const bool forceSystemValue = false);
FRAMELESSHELPER_API bool isLightThemeEnabled(); [[nodiscard]] FRAMELESSHELPER_API bool isLightThemeEnabled();
FRAMELESSHELPER_API bool isDarkThemeEnabled(); [[nodiscard]] FRAMELESSHELPER_API bool isDarkThemeEnabled();
FRAMELESSHELPER_API QWindow *findWindow(const WId winId); [[nodiscard]] FRAMELESSHELPER_API QWindow *findWindow(const WId winId);
FRAMELESSHELPER_API bool shouldUseNativeTitleBar(); [[nodiscard]] FRAMELESSHELPER_API bool shouldUseNativeTitleBar();
FRAMELESSHELPER_API bool isWindowFixedSize(const QWindow *window); [[nodiscard]] FRAMELESSHELPER_API bool isWindowFixedSize(const QWindow *window);
FRAMELESSHELPER_API QPointF getGlobalMousePosition(const QWindow *window); [[nodiscard]] FRAMELESSHELPER_API QPointF getGlobalMousePosition(const QWindow *window);
FRAMELESSHELPER_API bool isHitTestVisibleInChrome(const QWindow *window); [[nodiscard]] FRAMELESSHELPER_API bool isHitTestVisibleInChrome(const QWindow *window);
FRAMELESSHELPER_API QColor getNativeWindowFrameColor(const bool isActive = true); [[nodiscard]] FRAMELESSHELPER_API QColor getNativeWindowFrameColor(const bool isActive = true);
FRAMELESSHELPER_API QPointF mapOriginPointToWindow(const QObject *object); [[nodiscard]] FRAMELESSHELPER_API QPointF mapOriginPointToWindow(const QObject *object);
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
// Windows specific // Windows specific
FRAMELESSHELPER_API bool isWin7OrGreater(); [[nodiscard]] FRAMELESSHELPER_API bool isWin8OrGreater();
FRAMELESSHELPER_API bool isWin8OrGreater(); [[nodiscard]] FRAMELESSHELPER_API bool isWin8Point1OrGreater();
FRAMELESSHELPER_API bool isWin8Point1OrGreater(); [[nodiscard]] FRAMELESSHELPER_API bool isWin10OrGreater();
FRAMELESSHELPER_API bool isWin10OrGreater(); [[nodiscard]] FRAMELESSHELPER_API bool isWin10OrGreater(const int subVer);
FRAMELESSHELPER_API bool isWin10OrGreater(const int subVer); [[nodiscard]] FRAMELESSHELPER_API bool isDwmBlurAvailable();
FRAMELESSHELPER_API bool isDwmBlurAvailable(); [[nodiscard]] FRAMELESSHELPER_API bool isColorizationEnabled();
FRAMELESSHELPER_API bool isColorizationEnabled(); [[nodiscard]] FRAMELESSHELPER_API QColor getColorizationColor();
FRAMELESSHELPER_API QColor getColorizationColor();
FRAMELESSHELPER_API void triggerFrameChange(const QWindow *window); FRAMELESSHELPER_API void triggerFrameChange(const QWindow *window);
FRAMELESSHELPER_API void updateFrameMargins(const QWindow *window, const bool reset); FRAMELESSHELPER_API void updateFrameMargins(const QWindow *window, const bool reset);
FRAMELESSHELPER_API void updateQtFrameMargins(QWindow *window, const bool enable); FRAMELESSHELPER_API void updateQtFrameMargins(QWindow *window, const bool enable);
FRAMELESSHELPER_API quint32 getWindowDpi(const QWindow *window); [[nodiscard]] quint32 getWindowDpi(const QWindow *window);
FRAMELESSHELPER_API QMargins getWindowNativeFrameMargins(const QWindow *window); [[nodiscard]] FRAMELESSHELPER_API QMargins getWindowNativeFrameMargins(const QWindow *window);
FRAMELESSHELPER_API void displaySystemMenu(const QWindow *window, const QPointF &pos = {}); FRAMELESSHELPER_API void displaySystemMenu(const QWindow *window, const QPointF &pos = {});
#endif #endif

View File

@ -32,7 +32,7 @@
#include "utilities.h" #include "utilities.h"
#include <QtCore/qsettings.h> #include <QtCore/qsettings.h>
#include <QtCore/qlibrary.h> #include <QtCore/private/qsystemlibrary_p.h>
#include <QtCore/qt_windows.h> #include <QtCore/qt_windows.h>
#include <QtGui/qguiapplication.h> #include <QtGui/qguiapplication.h>
#include <QtCore/qdebug.h> #include <QtCore/qdebug.h>
@ -92,8 +92,6 @@ struct Win32Data
using GetSystemMetricsForDpiPtr = int(WINAPI *)(int, UINT); using GetSystemMetricsForDpiPtr = int(WINAPI *)(int, UINT);
using AdjustWindowRectExForDpiPtr = BOOL(WINAPI *)(LPRECT, DWORD, BOOL, DWORD, UINT); using AdjustWindowRectExForDpiPtr = BOOL(WINAPI *)(LPRECT, DWORD, BOOL, DWORD, UINT);
ShouldAppsUseDarkModePtr ShouldAppsUseDarkModePFN = nullptr; ShouldAppsUseDarkModePtr ShouldAppsUseDarkModePFN = nullptr;
ShouldSystemUseDarkModePtr ShouldSystemUseDarkModePFN = nullptr; ShouldSystemUseDarkModePtr ShouldSystemUseDarkModePFN = nullptr;
@ -112,18 +110,18 @@ struct Win32Data
void load() void load()
{ {
QLibrary User32Dll(QStringLiteral("User32")); QSystemLibrary User32Dll(QStringLiteral("User32.dll"));
GetDpiForWindowPFN = reinterpret_cast<GetDpiForWindowPtr>(User32Dll.resolve("GetDpiForWindow")); GetDpiForWindowPFN = reinterpret_cast<GetDpiForWindowPtr>(User32Dll.resolve("GetDpiForWindow"));
GetDpiForSystemPFN = reinterpret_cast<GetDpiForSystemPtr>(User32Dll.resolve("GetDpiForSystem")); GetDpiForSystemPFN = reinterpret_cast<GetDpiForSystemPtr>(User32Dll.resolve("GetDpiForSystem"));
GetSystemMetricsForDpiPFN = reinterpret_cast<GetSystemMetricsForDpiPtr>(User32Dll.resolve("GetSystemMetricsForDpi")); GetSystemMetricsForDpiPFN = reinterpret_cast<GetSystemMetricsForDpiPtr>(User32Dll.resolve("GetSystemMetricsForDpi"));
AdjustWindowRectExForDpiPFN = reinterpret_cast<AdjustWindowRectExForDpiPtr>(User32Dll.resolve("AdjustWindowRectExForDpi")); AdjustWindowRectExForDpiPFN = reinterpret_cast<AdjustWindowRectExForDpiPtr>(User32Dll.resolve("AdjustWindowRectExForDpi"));
GetSystemDpiForProcessPFN = reinterpret_cast<GetSystemDpiForProcessPtr>(User32Dll.resolve("GetSystemDpiForProcess")); GetSystemDpiForProcessPFN = reinterpret_cast<GetSystemDpiForProcessPtr>(User32Dll.resolve("GetSystemDpiForProcess"));
QLibrary UxThemeDll(QStringLiteral("UxTheme")); QSystemLibrary UxThemeDll(QStringLiteral("UxTheme.dll"));
ShouldAppsUseDarkModePFN = reinterpret_cast<ShouldAppsUseDarkModePtr>(UxThemeDll.resolve(MAKEINTRESOURCEA(132))); ShouldAppsUseDarkModePFN = reinterpret_cast<ShouldAppsUseDarkModePtr>(UxThemeDll.resolve(MAKEINTRESOURCEA(132)));
ShouldSystemUseDarkModePFN = reinterpret_cast<ShouldSystemUseDarkModePtr>(UxThemeDll.resolve(MAKEINTRESOURCEA(138))); ShouldSystemUseDarkModePFN = reinterpret_cast<ShouldSystemUseDarkModePtr>(UxThemeDll.resolve(MAKEINTRESOURCEA(138)));
QLibrary SHCoreDll(QStringLiteral("SHCore")); QSystemLibrary SHCoreDll(QStringLiteral("SHCore.dll"));
GetDpiForMonitorPFN = reinterpret_cast<GetDpiForMonitorPtr>(SHCoreDll.resolve("GetDpiForMonitor")); GetDpiForMonitorPFN = reinterpret_cast<GetDpiForMonitorPtr>(SHCoreDll.resolve("GetDpiForMonitor"));
GetProcessDpiAwarenessPFN = reinterpret_cast<GetProcessDpiAwarenessPtr>(SHCoreDll.resolve("GetProcessDpiAwareness")); GetProcessDpiAwarenessPFN = reinterpret_cast<GetProcessDpiAwarenessPtr>(SHCoreDll.resolve("GetProcessDpiAwareness"));
} }
@ -133,6 +131,7 @@ Q_GLOBAL_STATIC(Win32Data, win32Data)
bool Utilities::isDwmBlurAvailable() bool Utilities::isDwmBlurAvailable()
{ {
// DWM Composition is always enabled and can't be disabled since Windows 8.
if (isWin8OrGreater()) { if (isWin8OrGreater()) {
return true; return true;
} }
@ -141,7 +140,7 @@ bool Utilities::isDwmBlurAvailable()
qWarning() << "DwmIsCompositionEnabled failed."; qWarning() << "DwmIsCompositionEnabled failed.";
return false; return false;
} }
return isWin7OrGreater() && (enabled != FALSE); return (enabled != FALSE);
} }
int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric, const bool dpiAware, const bool forceSystemValue) int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric, const bool dpiAware, const bool forceSystemValue)
@ -415,15 +414,6 @@ void Utilities::updateQtFrameMargins(QWindow *window, const bool enable)
#endif #endif
} }
bool Utilities::isWin7OrGreater()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows7;
#else
return QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS7;
#endif
}
bool Utilities::isWin8OrGreater() bool Utilities::isWin8OrGreater()
{ {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))