From 7a35b09a74b1836f92e256d2241583f283fa45e5 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Wed, 31 Aug 2022 16:34:30 +0800 Subject: [PATCH] add limited qmake support Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- examples/example.rc | 12 ++++ examples/mainwindow/main.cpp | 5 ++ examples/openglwidget/main.cpp | 5 ++ examples/quick/CMakeLists.txt | 6 +- examples/quick/main.cpp | 9 ++- examples/quick/quick.pro | 11 +++ examples/widget/main.cpp | 5 ++ examples/widget/widget.pro | 9 +++ .../Core/framelesshelpercore_global.h | 1 + .../Core/private/chromepalette_p.h | 3 +- .../Core/private/micamaterial_p.h | 3 +- .../Core/private/registrykey_p.h | 11 +++ .../Quick/private/framelessquickhelper_p.h | 2 +- .../Quick/private/framelessquickwindow_p_p.h | 3 +- .../Quick/private/quickimageitem_p.h | 3 +- .../Quick/private/quickmicamaterial_p.h | 2 +- .../Quick/private/quickstandardtitlebar_p.h | 2 +- .../Widgets/framelesswidgetshelper.h | 1 + .../Widgets/private/framelessmainwindow_p.h | 2 +- .../Widgets/private/framelesswidget_p.h | 2 +- .../private/framelesswidgetshelper_p.h | 2 +- .../Widgets/private/standardsystembutton_p.h | 5 +- .../Widgets/private/standardtitlebar_p.h | 2 +- .../Widgets/standardtitlebar.h | 4 +- qmake/core.pri | 71 +++++++++++++++++++ qmake/inc/core/framelesshelper.version | 44 ++++++++++++ qmake/quick.pri | 47 ++++++++++++ qmake/widgets.pri | 39 ++++++++++ src/core/CMakeLists.txt | 17 ++++- src/core/framelesshelper_qt.cpp | 5 +- src/core/framelesshelper_win.cpp | 21 +++--- ...bal.cpp => framelesshelpercore_global.cpp} | 20 ++++++ src/core/registrykey.cpp | 1 - src/core/utils_win.cpp | 50 +++++-------- src/quick/CMakeLists.txt | 2 +- ...al.cpp => framelesshelperquick_global.cpp} | 0 src/widgets/CMakeLists.txt | 2 +- ....cpp => framelesshelperwidgets_global.cpp} | 0 38 files changed, 352 insertions(+), 77 deletions(-) create mode 100644 examples/quick/quick.pro create mode 100644 examples/widget/widget.pro create mode 100644 qmake/core.pri create mode 100644 qmake/inc/core/framelesshelper.version create mode 100644 qmake/quick.pri create mode 100644 qmake/widgets.pri rename src/core/{global.cpp => framelesshelpercore_global.cpp} (94%) rename src/quick/{global.cpp => framelesshelperquick_global.cpp} (100%) rename src/widgets/{global.cpp => framelesshelperwidgets_global.cpp} (100%) diff --git a/examples/example.rc b/examples/example.rc index d71058c2..a5c32aa7 100644 --- a/examples/example.rc +++ b/examples/example.rc @@ -26,6 +26,18 @@ IDI_ICON1 ICON "example.ico" +#if 0 +#if (defined(WIDGET_USE_QMAKE) || defined(QUICK_USE_QMAKE)) +#ifndef CREATEPROCESS_MANIFEST_RESOURCE_ID +#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1 +#endif +#ifndef RT_MANIFEST +#define RT_MANIFEST 24 +#endif +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "example.manifest" +#endif +#endif + VS_VERSION_INFO VERSIONINFO FILEVERSION 1,0,0,0 PRODUCTVERSION 1,0,0,0 diff --git a/examples/mainwindow/main.cpp b/examples/mainwindow/main.cpp index e1132a06..3bbb107b 100644 --- a/examples/mainwindow/main.cpp +++ b/examples/mainwindow/main.cpp @@ -39,6 +39,11 @@ int main(int argc, char *argv[]) QApplication application(argc, argv); + // Must be called after QGuiApplication has been constructed, we are using + // some private functions from QPA which won't be available until there's + // a QGuiApplication instance. + FramelessHelper::Core::setApplicationOSThemeAware(true, false); + FramelessConfig::instance()->set(Global::Option::WindowUseRoundCorners); FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); diff --git a/examples/openglwidget/main.cpp b/examples/openglwidget/main.cpp index fcaf60c6..2eead111 100644 --- a/examples/openglwidget/main.cpp +++ b/examples/openglwidget/main.cpp @@ -76,6 +76,11 @@ int main(int argc, char *argv[]) QApplication application(argc, argv); + // Must be called after QGuiApplication has been constructed, we are using + // some private functions from QPA which won't be available until there's + // a QGuiApplication instance. + FramelessHelper::Core::setApplicationOSThemeAware(true, false); + FramelessConfig::instance()->set(Global::Option::WindowUseRoundCorners); FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); diff --git a/examples/quick/CMakeLists.txt b/examples/quick/CMakeLists.txt index c660c6aa..da12a494 100644 --- a/examples/quick/CMakeLists.txt +++ b/examples/quick/CMakeLists.txt @@ -57,8 +57,10 @@ if(${QT_VERSION} VERSION_GREATER_EQUAL 6.2) # There's some hope to get it supported in Qt 6.5. ) qt_add_resources(Quick resources - PREFIX "/Demo" - FILES "images/microsoft.svg" + PREFIX + "/Demo" + FILES + "images/microsoft.svg" ) endif() diff --git a/examples/quick/main.cpp b/examples/quick/main.cpp index c1f2373a..b7a20be7 100644 --- a/examples/quick/main.cpp +++ b/examples/quick/main.cpp @@ -51,6 +51,11 @@ int main(int argc, char *argv[]) QGuiApplication application(argc, argv); + // Must be called after QGuiApplication has been constructed, we are using + // some private functions from QPA which won't be available until there's + // a QGuiApplication instance. + FramelessHelper::Core::setApplicationOSThemeAware(true, true); + FramelessConfig::instance()->set(Global::Option::WindowUseRoundCorners); FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); @@ -75,11 +80,11 @@ int main(int argc, char *argv[]) } QQmlApplicationEngine engine; -#if !QMLTC_ENABLED +#if (!QMLTC_ENABLED && !defined(QUICK_USE_QMAKE)) engine.addImportPath(FRAMELESSHELPER_STRING_LITERAL("../imports")); #endif -#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) && !QMLTC_ENABLED +#if (((QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) || defined(QUICK_USE_QMAKE)) && !QMLTC_ENABLED) // Don't forget to register our own custom QML types! FramelessHelper::Quick::registerTypes(&engine); diff --git a/examples/quick/quick.pro b/examples/quick/quick.pro new file mode 100644 index 00000000..13ebb121 --- /dev/null +++ b/examples/quick/quick.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = Quick +QT += qml quick quickcontrols2 +CONFIG -= embed_manifest_exe +DEFINES += QUICK_USE_QMAKE +HEADERS += settings.h +SOURCES += settings.cpp main.cpp +RESOURCES += resources.qrc +win32: RC_FILE = ../example.rc +include(../../qmake/core.pri) +include(../../qmake/quick.pri) diff --git a/examples/widget/main.cpp b/examples/widget/main.cpp index a04e6a79..49589854 100644 --- a/examples/widget/main.cpp +++ b/examples/widget/main.cpp @@ -39,6 +39,11 @@ int main(int argc, char *argv[]) QApplication application(argc, argv); + // Must be called after QGuiApplication has been constructed, we are using + // some private functions from QPA which won't be available until there's + // a QGuiApplication instance. + FramelessHelper::Core::setApplicationOSThemeAware(true, false); + FramelessConfig::instance()->set(Global::Option::WindowUseRoundCorners); FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); diff --git a/examples/widget/widget.pro b/examples/widget/widget.pro new file mode 100644 index 00000000..1f817465 --- /dev/null +++ b/examples/widget/widget.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET = Widget +QT += widgets +CONFIG -= embed_manifest_exe +HEADERS += widget.h +SOURCES += widget.cpp main.cpp +win32: RC_FILE = ../example.rc +include(../../qmake/core.pri) +include(../../qmake/widgets.pri) diff --git a/include/FramelessHelper/Core/framelesshelpercore_global.h b/include/FramelessHelper/Core/framelesshelpercore_global.h index 28ecb2b0..623e7e82 100644 --- a/include/FramelessHelper/Core/framelesshelpercore_global.h +++ b/include/FramelessHelper/Core/framelesshelpercore_global.h @@ -566,6 +566,7 @@ FRAMELESSHELPER_CORE_API void uninitialize(); [[nodiscard]] FRAMELESSHELPER_CORE_API Global::VersionInfo version(); FRAMELESSHELPER_CORE_API void registerInitializeHook(const Global::InitializeHookCallback &cb); FRAMELESSHELPER_CORE_API void registerUninitializeHook(const Global::UninitializeHookCallback &cb); +FRAMELESSHELPER_CORE_API void setApplicationOSThemeAware(const bool enable, const bool pureQuick); } // namespace FramelessHelper::Core FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Core/private/chromepalette_p.h b/include/FramelessHelper/Core/private/chromepalette_p.h index 47322343..1ab14f19 100644 --- a/include/FramelessHelper/Core/private/chromepalette_p.h +++ b/include/FramelessHelper/Core/private/chromepalette_p.h @@ -25,14 +25,13 @@ #pragma once #include "framelesshelpercore_global.h" +#include "chromepalette.h" #include #include #include FRAMELESSHELPER_BEGIN_NAMESPACE -class ChromePalette; - class FRAMELESSHELPER_CORE_API ChromePalettePrivate : public QObject { Q_OBJECT diff --git a/include/FramelessHelper/Core/private/micamaterial_p.h b/include/FramelessHelper/Core/private/micamaterial_p.h index fb1a606b..076f6834 100644 --- a/include/FramelessHelper/Core/private/micamaterial_p.h +++ b/include/FramelessHelper/Core/private/micamaterial_p.h @@ -25,14 +25,13 @@ #pragma once #include "framelesshelpercore_global.h" +#include "micamaterial.h" #include #include #include FRAMELESSHELPER_BEGIN_NAMESPACE -class MicaMaterial; - class FRAMELESSHELPER_CORE_API MicaMaterialPrivate : public QObject { Q_OBJECT diff --git a/include/FramelessHelper/Core/private/registrykey_p.h b/include/FramelessHelper/Core/private/registrykey_p.h index 4743655e..34a2cbbc 100644 --- a/include/FramelessHelper/Core/private/registrykey_p.h +++ b/include/FramelessHelper/Core/private/registrykey_p.h @@ -26,6 +26,8 @@ #include "framelesshelpercore_global.h" #include +#include +#include QT_BEGIN_NAMESPACE class QWinRegistryKey; @@ -49,6 +51,15 @@ class FRAMELESSHELPER_CORE_API RegistryKey : public QObject Q_NODISCARD bool isValid() const; Q_NODISCARD QVariant value(const QString &name) const; + template + Q_NODISCARD std::optional value(const QString &name) const + { + const QVariant var = value(name); + if (var.isValid()) { + return qvariant_cast(var); + } + return std::nullopt; + } private: Global::RegistryRootKey m_rootKey = Global::RegistryRootKey::CurrentUser; diff --git a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h index 2ffc6ab4..01aa33f8 100644 --- a/include/FramelessHelper/Quick/private/framelessquickhelper_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickhelper_p.h @@ -25,6 +25,7 @@ #pragma once #include "framelesshelperquick_global.h" +#include "framelessquickhelper.h" #include #include @@ -35,7 +36,6 @@ QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE struct QuickHelperData; -class FramelessQuickHelper; class FRAMELESSHELPER_QUICK_API FramelessQuickHelperPrivate : public QObject { diff --git a/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h b/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h index 8976a2b4..df07e58b 100644 --- a/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h +++ b/include/FramelessHelper/Quick/private/framelessquickwindow_p_p.h @@ -26,6 +26,7 @@ #include "framelesshelperquick_global.h" #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include "framelessquickwindow_p.h" #include #include #include @@ -36,8 +37,6 @@ QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE -class FramelessQuickWindow; - class FRAMELESSHELPER_QUICK_API FramelessQuickWindowPrivate : public QObject { Q_OBJECT diff --git a/include/FramelessHelper/Quick/private/quickimageitem_p.h b/include/FramelessHelper/Quick/private/quickimageitem_p.h index 38373c0e..2f14a5b8 100644 --- a/include/FramelessHelper/Quick/private/quickimageitem_p.h +++ b/include/FramelessHelper/Quick/private/quickimageitem_p.h @@ -25,14 +25,13 @@ #pragma once #include "framelesshelperquick_global.h" +#include "quickimageitem.h" #include #include #include FRAMELESSHELPER_BEGIN_NAMESPACE -class QuickImageItem; - class FRAMELESSHELPER_QUICK_API QuickImageItemPrivate : public QObject { Q_OBJECT diff --git a/include/FramelessHelper/Quick/private/quickmicamaterial_p.h b/include/FramelessHelper/Quick/private/quickmicamaterial_p.h index 65d6ac79..a62f48f9 100644 --- a/include/FramelessHelper/Quick/private/quickmicamaterial_p.h +++ b/include/FramelessHelper/Quick/private/quickmicamaterial_p.h @@ -25,12 +25,12 @@ #pragma once #include "framelesshelperquick_global.h" +#include "quickmicamaterial.h" #include #include FRAMELESSHELPER_BEGIN_NAMESPACE -class QuickMicaMaterial; class WallpaperImageNode; class FRAMELESSHELPER_QUICK_API QuickMicaMaterialPrivate : public QObject diff --git a/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h b/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h index 23e10497..48457614 100644 --- a/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h +++ b/include/FramelessHelper/Quick/private/quickstandardtitlebar_p.h @@ -27,6 +27,7 @@ #include "framelesshelperquick_global.h" #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #include "quickchromepalette.h" +#include "quickstandardsystembutton_p.h" #include #include @@ -36,7 +37,6 @@ QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE -class QuickStandardSystemButton; class QuickImageItem; class FRAMELESSHELPER_QUICK_API QuickStandardTitleBar : public QQuickRectangle diff --git a/include/FramelessHelper/Widgets/framelesswidgetshelper.h b/include/FramelessHelper/Widgets/framelesswidgetshelper.h index 10e6dfdb..826b9ed0 100644 --- a/include/FramelessHelper/Widgets/framelesswidgetshelper.h +++ b/include/FramelessHelper/Widgets/framelesswidgetshelper.h @@ -27,6 +27,7 @@ #include "framelesshelperwidgets_global.h" #include #include +#include FRAMELESSHELPER_BEGIN_NAMESPACE diff --git a/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h b/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h index ecb25d07..74ce3e29 100644 --- a/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h +++ b/include/FramelessHelper/Widgets/private/framelessmainwindow_p.h @@ -25,12 +25,12 @@ #pragma once #include "framelesshelperwidgets_global.h" +#include "framelessmainwindow.h" #include #include FRAMELESSHELPER_BEGIN_NAMESPACE -class FramelessMainWindow; class WidgetsSharedHelper; class FRAMELESSHELPER_WIDGETS_API FramelessMainWindowPrivate : public QObject diff --git a/include/FramelessHelper/Widgets/private/framelesswidget_p.h b/include/FramelessHelper/Widgets/private/framelesswidget_p.h index ea6b0aba..589cfb86 100644 --- a/include/FramelessHelper/Widgets/private/framelesswidget_p.h +++ b/include/FramelessHelper/Widgets/private/framelesswidget_p.h @@ -25,12 +25,12 @@ #pragma once #include "framelesshelperwidgets_global.h" +#include "framelesswidget.h" #include #include FRAMELESSHELPER_BEGIN_NAMESPACE -class FramelessWidget; class WidgetsSharedHelper; class FRAMELESSHELPER_WIDGETS_API FramelessWidgetPrivate : public QObject diff --git a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h index 4668357e..694b196b 100644 --- a/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h +++ b/include/FramelessHelper/Widgets/private/framelesswidgetshelper_p.h @@ -25,13 +25,13 @@ #pragma once #include "framelesshelperwidgets_global.h" +#include "framelesswidgetshelper.h" #include #include FRAMELESSHELPER_BEGIN_NAMESPACE struct WidgetsHelperData; -class FramelessWidgetsHelper; class FRAMELESSHELPER_WIDGETS_API FramelessWidgetsHelperPrivate : public QObject { diff --git a/include/FramelessHelper/Widgets/private/standardsystembutton_p.h b/include/FramelessHelper/Widgets/private/standardsystembutton_p.h index aab3ce07..d60c493a 100644 --- a/include/FramelessHelper/Widgets/private/standardsystembutton_p.h +++ b/include/FramelessHelper/Widgets/private/standardsystembutton_p.h @@ -24,9 +24,10 @@ #pragma once +#include "framelesshelperwidgets_global.h" +#include "standardsystembutton.h" #include #include -#include "framelesshelperwidgets_global.h" QT_BEGIN_NAMESPACE class QEnterEvent; @@ -35,8 +36,6 @@ QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE -class StandardSystemButton; - class FRAMELESSHELPER_WIDGETS_API StandardSystemButtonPrivate : public QObject { Q_OBJECT diff --git a/include/FramelessHelper/Widgets/private/standardtitlebar_p.h b/include/FramelessHelper/Widgets/private/standardtitlebar_p.h index bc999387..ad8269f6 100644 --- a/include/FramelessHelper/Widgets/private/standardtitlebar_p.h +++ b/include/FramelessHelper/Widgets/private/standardtitlebar_p.h @@ -25,6 +25,7 @@ #pragma once #include "framelesshelperwidgets_global.h" +#include "standardtitlebar.h" #include #include @@ -34,7 +35,6 @@ QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE -class StandardTitleBar; class StandardSystemButton; class ChromePalette; diff --git a/include/FramelessHelper/Widgets/standardtitlebar.h b/include/FramelessHelper/Widgets/standardtitlebar.h index 9378cef0..3635a90d 100644 --- a/include/FramelessHelper/Widgets/standardtitlebar.h +++ b/include/FramelessHelper/Widgets/standardtitlebar.h @@ -25,8 +25,9 @@ #pragma once #include "framelesshelperwidgets_global.h" -#include +#include "standardsystembutton.h" #include +#include #include FRAMELESSHELPER_BEGIN_NAMESPACE @@ -34,7 +35,6 @@ FRAMELESSHELPER_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcStandardTitleBar) class StandardTitleBarPrivate; -class StandardSystemButton; class FRAMELESSHELPER_WIDGETS_API StandardTitleBar : public QWidget { diff --git a/qmake/core.pri b/qmake/core.pri new file mode 100644 index 00000000..b764123f --- /dev/null +++ b/qmake/core.pri @@ -0,0 +1,71 @@ +QT += core core-private gui gui-private + +CORE_PUB_INC_DIR = $$PWD/../include/FramelessHelper/Core +CORE_PRIV_INC_DIR = $$CORE_PUB_INC_DIR/private +CORE_EXTRA_INC_DIR = $$PWD/inc/core +CORE_SRC_DIR = $$PWD/../src/core + +DEFINES += \ + FRAMELESSHELPER_CORE_STATIC + +INCLUDEPATH += \ + $$CORE_PUB_INC_DIR \ + $$CORE_PRIV_INC_DIR \ + $$CORE_EXTRA_INC_DIR + +DEPENDPATH += \ + $$CORE_PUB_INC_DIR \ + $$CORE_PRIV_INC_DIR \ + $$CORE_EXTRA_INC_DIR + +HEADERS += \ + $$CORE_EXTRA_INC_DIR/framelesshelper.version \ + $$CORE_PUB_INC_DIR/chromepalette.h \ + $$CORE_PUB_INC_DIR/framelesshelper_qt.h \ + $$CORE_PUB_INC_DIR/framelesshelpercore_global.h \ + $$CORE_PUB_INC_DIR/framelessmanager.h \ + $$CORE_PUB_INC_DIR/micamaterial.h \ + $$CORE_PUB_INC_DIR/utils.h \ + $$CORE_PRIV_INC_DIR/chromepalette_p.h \ + $$CORE_PRIV_INC_DIR/framelessconfig_p.h \ + $$CORE_PRIV_INC_DIR/framelessmanager_p.h \ + $$CORE_PRIV_INC_DIR/micamaterial_p.h \ + $$CORE_PRIV_INC_DIR/registrykey_p.h \ + $$CORE_PRIV_INC_DIR/sysapiloader_p.h + +SOURCES += \ + $$CORE_SRC_DIR/chromepalette.cpp \ + $$CORE_SRC_DIR/framelessconfig.cpp \ + $$CORE_SRC_DIR/framelesshelper_qt.cpp \ + $$CORE_SRC_DIR/framelessmanager.cpp \ + $$CORE_SRC_DIR/framelesshelpercore_global.cpp \ + $$CORE_SRC_DIR/micamaterial.cpp \ + $$CORE_SRC_DIR/registrykey.cpp \ + $$CORE_SRC_DIR/sysapiloader.cpp \ + $$CORE_SRC_DIR/utils.cpp + +RESOURCES += \ + $$CORE_SRC_DIR/framelesshelpercore.qrc + +win32 { + HEADERS += \ + $$CORE_PUB_INC_DIR/framelesshelper_win.h \ + $$CORE_PUB_INC_DIR/framelesshelper_windows.h + SOURCES += \ + $$CORE_SRC_DIR/framelesshelper_win.cpp \ + $$CORE_SRC_DIR/utils_win.cpp + LIBS += -luser32 -lgdi32 +} + +unix:!macx { + CONFIG += link_pkgconfig + PKGCONFIG += gtk+-3.0 + DEFINES += GDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_6 + SOURCES += $$CORE_SRC_DIR/utils_linux.cpp + #LIBS += -lxcb # TODO +} + +macx { + SOURCES += $$CORE_SRC_DIR/utils_mac.mm + #LIBS += "-framework AppKit" "-framework Cocoa" "-framework Foundation" # TODO +} diff --git a/qmake/inc/core/framelesshelper.version b/qmake/inc/core/framelesshelper.version new file mode 100644 index 00000000..13fd9d15 --- /dev/null +++ b/qmake/inc/core/framelesshelper.version @@ -0,0 +1,44 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// Generated automatically by QMake. +// WARNING! DO NOT EDIT THIS FILE MANUALLY! +// ALL CHANGES WILL BE LOST AFTER RE-CONFIGURING! +// Also please do not include this file directly, +// it's designed to be included by FramelessHelper's own headers. + +#ifndef _FRAMELESSHELPER_VERSION_DEFINED_ +#define _FRAMELESSHELPER_VERSION_DEFINED_ + +#pragma once + +[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION_MAJOR = 2; +[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION_MINOR = 2; +[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION_PATCH = 0; +[[maybe_unused]] static constexpr const int FRAMELESSHELPER_VERSION_TWEAK = 0; +[[maybe_unused]] static constexpr const char FRAMELESSHELPER_VERSION_STR[] = "2.2.0.0\0"; +[[maybe_unused]] static constexpr const char FRAMELESSHELPER_COMMIT_STR[] = "UNKNOWN\0"; +[[maybe_unused]] static constexpr const char FRAMELESSHELPER_COMPILE_DATETIME_STR[] = "UNKNOWN\0"; + +#endif // _FRAMELESSHELPER_VERSION_DEFINED_ diff --git a/qmake/quick.pri b/qmake/quick.pri new file mode 100644 index 00000000..ddcec78b --- /dev/null +++ b/qmake/quick.pri @@ -0,0 +1,47 @@ +QT += \ + quick quick-private \ + quicktemplates2 quicktemplates2-private \ + quickcontrols2 quickcontrols2-private + +QUICK_PUB_INC_DIR = $$PWD/../include/FramelessHelper/Quick +QUICK_PRIV_INC_DIR = $$QUICK_PUB_INC_DIR/private +QUICK_SRC_DIR = $$PWD/../src/quick + +DEFINES += \ + FRAMELESSHELPER_QUICK_STATIC + +INCLUDEPATH += \ + $$QUICK_PUB_INC_DIR \ + $$QUICK_PRIV_INC_DIR + +DEPENDPATH += \ + $$QUICK_PUB_INC_DIR \ + $$QUICK_PRIV_INC_DIR + +HEADERS += \ + $$QUICK_PUB_INC_DIR/framelesshelperquick_global.h \ + $$QUICK_PUB_INC_DIR/framelessquickmodule.h \ + $$QUICK_PUB_INC_DIR/framelessquickhelper.h \ + $$QUICK_PUB_INC_DIR/framelessquickutils.h \ + $$QUICK_PUB_INC_DIR/quickchromepalette.h \ + $$QUICK_PUB_INC_DIR/quickmicamaterial.h \ + $$QUICK_PUB_INC_DIR/quickimageitem.h \ + $$QUICK_PRIV_INC_DIR/quickstandardsystembutton_p.h \ + $$QUICK_PRIV_INC_DIR/quickstandardtitlebar_p.h \ + $$QUICK_PRIV_INC_DIR/framelessquickhelper_p.h \ + $$QUICK_PRIV_INC_DIR/framelessquickwindow_p.h \ + $$QUICK_PRIV_INC_DIR/framelessquickwindow_p_p.h \ + $$QUICK_PRIV_INC_DIR/quickmicamaterial_p.h \ + $$QUICK_PRIV_INC_DIR/quickimageitem_p.h + +SOURCES += \ + $$QUICK_SRC_DIR/quickstandardsystembutton.cpp \ + $$QUICK_SRC_DIR/quickstandardtitlebar.cpp \ + $$QUICK_SRC_DIR/framelessquickutils.cpp \ + $$QUICK_SRC_DIR/framelessquickmodule.cpp \ + $$QUICK_SRC_DIR/framelessquickwindow.cpp \ + $$QUICK_SRC_DIR/framelessquickhelper.cpp \ + $$QUICK_SRC_DIR/quickchromepalette.cpp \ + $$QUICK_SRC_DIR/framelesshelperquick_global.cpp \ + $$QUICK_SRC_DIR/quickmicamaterial.cpp \ + $$QUICK_SRC_DIR/quickimageitem.cpp diff --git a/qmake/widgets.pri b/qmake/widgets.pri new file mode 100644 index 00000000..1e4ee510 --- /dev/null +++ b/qmake/widgets.pri @@ -0,0 +1,39 @@ +QT += widgets widgets-private + +WIDGETS_PUB_INC_DIR = $$PWD/../include/FramelessHelper/Widgets +WIDGETS_PRIV_INC_DIR = $$WIDGETS_PUB_INC_DIR/private +WIDGETS_SRC_DIR = $$PWD/../src/widgets + +DEFINES += \ + FRAMELESSHELPER_WIDGETS_STATIC + +INCLUDEPATH += \ + $$WIDGETS_PUB_INC_DIR \ + $$WIDGETS_PRIV_INC_DIR + +DEPENDPATH += \ + $$WIDGETS_PUB_INC_DIR \ + $$WIDGETS_PRIV_INC_DIR + +HEADERS += \ + $$WIDGETS_PUB_INC_DIR/framelesshelperwidgets_global.h \ + $$WIDGETS_PUB_INC_DIR/framelesswidget.h \ + $$WIDGETS_PUB_INC_DIR/framelessmainwindow.h \ + $$WIDGETS_PUB_INC_DIR/standardsystembutton.h \ + $$WIDGETS_PUB_INC_DIR/framelesswidgetshelper.h \ + $$WIDGETS_PUB_INC_DIR/standardtitlebar.h \ + $$WIDGETS_PRIV_INC_DIR/framelesswidgetshelper_p.h \ + $$WIDGETS_PRIV_INC_DIR/standardsystembutton_p.h \ + $$WIDGETS_PRIV_INC_DIR/standardtitlebar_p.h \ + $$WIDGETS_PRIV_INC_DIR/framelesswidget_p.h \ + $$WIDGETS_PRIV_INC_DIR/framelessmainwindow_p.h \ + $$WIDGETS_PRIV_INC_DIR/widgetssharedhelper_p.h + +SOURCES += \ + $$WIDGETS_SRC_DIR/framelessmainwindow.cpp \ + $$WIDGETS_SRC_DIR/framelesswidgetshelper.cpp \ + $$WIDGETS_SRC_DIR/framelesswidget.cpp \ + $$WIDGETS_SRC_DIR/standardsystembutton.cpp \ + $$WIDGETS_SRC_DIR/standardtitlebar.cpp \ + $$WIDGETS_SRC_DIR/widgetssharedhelper.cpp \ + $$WIDGETS_SRC_DIR/framelesshelperwidgets_global.cpp diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 87f8f3d3..31d45a17 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -65,14 +65,13 @@ set(PRIVATE_HEADERS ) set(SOURCES - framelesshelpercore.qrc utils.cpp framelesshelper_qt.cpp framelessmanager.cpp framelessconfig.cpp sysapiloader.cpp chromepalette.cpp - global.cpp + framelesshelpercore_global.cpp micamaterial.cpp ) @@ -119,6 +118,20 @@ endif() add_library(${PROJECT_NAME}::${SUB_PROJ_NAME} ALIAS ${SUB_PROJ_NAME}) add_library(${PROJECT_NAME}::${SUB_MOD_NAME} ALIAS ${SUB_PROJ_NAME}) +if(${QT_VERSION} VERSION_GREATER_EQUAL 6.2) + qt_add_resources(${SUB_PROJ_NAME} framelesshelpercore + PREFIX + "/org.wangwenx190.${PROJECT_NAME}" + FILES + "resources/fonts/Micon.ttf" + "resources/images/noise.png" + ) +else() + target_sources(${SUB_PROJ_NAME} PRIVATE + framelesshelpercore.qrc + ) +endif() + if(FRAMELESSHELPER_BUILD_STATIC) target_compile_definitions(${SUB_PROJ_NAME} PUBLIC FRAMELESSHELPER_CORE_STATIC diff --git a/src/core/framelesshelper_qt.cpp b/src/core/framelesshelper_qt.cpp index 15f7d656..46f8f699 100644 --- a/src/core/framelesshelper_qt.cpp +++ b/src/core/framelesshelper_qt.cpp @@ -95,12 +95,11 @@ void FramelessHelperQt::addWindow(const SystemParameters ¶ms) params.setWindowFlags(params.getWindowFlags() | Qt::FramelessWindowHint); } window->installEventFilter(data.eventFilter); -#if (defined(Q_OS_LINUX) && (QT_VERSION < QT_VERSION_CHECK(6, 4, 0))) - Utils::registerThemeChangeNotification(); -#endif #ifdef Q_OS_MACOS Utils::setSystemTitleBarVisible(windowId, false); #endif + static const bool isQtQuickApplication = (params.getCurrentApplicationType() == ApplicationType::Quick); + FramelessHelper::Core::setApplicationOSThemeAware(true, isQtQuickApplication); } bool FramelessHelperQt::eventFilter(QObject *object, QEvent *event) diff --git a/src/core/framelesshelper_win.cpp b/src/core/framelesshelper_win.cpp index 1918455a..5c38b90a 100644 --- a/src/core/framelesshelper_win.cpp +++ b/src/core/framelesshelper_win.cpp @@ -133,22 +133,23 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper) ((uMsg >= WM_NCMOUSEMOVE) && (uMsg <= WM_NCXBUTTONDBLCLK))); const auto releaseButtons = [&data](const std::optional exclude) -> void { static constexpr const auto defaultButtonState = ButtonState::Unspecified; - if (!exclude.has_value() || (exclude.value() != SystemButtonType::WindowIcon)) { + const SystemButtonType button = exclude.value_or(SystemButtonType::Unknown); + if (button != SystemButtonType::WindowIcon) { data.params.setSystemButtonState(SystemButtonType::WindowIcon, defaultButtonState); } - if (!exclude.has_value() || (exclude.value() != SystemButtonType::Help)) { + if (button != SystemButtonType::Help) { data.params.setSystemButtonState(SystemButtonType::Help, defaultButtonState); } - if (!exclude.has_value() || (exclude.value() != SystemButtonType::Minimize)) { + if (button != SystemButtonType::Minimize) { data.params.setSystemButtonState(SystemButtonType::Minimize, defaultButtonState); } - if (!exclude.has_value() || (exclude.value() != SystemButtonType::Maximize)) { + if (button != SystemButtonType::Maximize) { data.params.setSystemButtonState(SystemButtonType::Maximize, defaultButtonState); } - if (!exclude.has_value() || (exclude.value() != SystemButtonType::Restore)) { + if (button != SystemButtonType::Restore) { data.params.setSystemButtonState(SystemButtonType::Restore, defaultButtonState); } - if (!exclude.has_value() || (exclude.value() != SystemButtonType::Close)) { + if (button != SystemButtonType::Close) { data.params.setSystemButtonState(SystemButtonType::Close, defaultButtonState); } }; @@ -521,13 +522,7 @@ void FramelessHelperWin::addWindow(const SystemParameters ¶ms) const bool dark = Utils::shouldAppsUseDarkMode(); static const bool isQtQuickApplication = (params.getCurrentApplicationType() == ApplicationType::Quick); // Tell DWM we may need dark theme non-client area (title bar & frame border). -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) - static bool darkModeAwareSet = false; - if (!darkModeAwareSet) { - darkModeAwareSet = true; - Utils::setQtDarkModeAwareEnabled(true, isQtQuickApplication); - } -#endif + FramelessHelper::Core::setApplicationOSThemeAware(true, isQtQuickApplication); Utils::updateWindowFrameBorderColor(windowId, dark); static const bool isWin10RS5OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809); if (isWin10RS5OrGreater) { diff --git a/src/core/global.cpp b/src/core/framelesshelpercore_global.cpp similarity index 94% rename from src/core/global.cpp rename to src/core/framelesshelpercore_global.cpp index e56a4781..3b528aaa 100644 --- a/src/core/global.cpp +++ b/src/core/framelesshelpercore_global.cpp @@ -274,6 +274,26 @@ void registerUninitializeHook(const UninitializeHookCallback &cb) coreData()->uninitHooks.append(cb); } +void setApplicationOSThemeAware(const bool enable, const bool pureQuick) +{ + Q_UNUSED(enable); + Q_UNUSED(pureQuick); + + static bool set = false; + if (set) { + return; + } + set = true; + +#if (defined(Q_OS_WINDOWS) && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))) + Utils::setQtDarkModeAwareEnabled(enable, pureQuick); +#endif + +#if (defined(Q_OS_LINUX) && (QT_VERSION < QT_VERSION_CHECK(6, 4, 0))) + Utils::registerThemeChangeNotification(); +#endif +} + } FRAMELESSHELPER_END_NAMESPACE diff --git a/src/core/registrykey.cpp b/src/core/registrykey.cpp index 9b4c1100..574c906b 100644 --- a/src/core/registrykey.cpp +++ b/src/core/registrykey.cpp @@ -24,7 +24,6 @@ #include "registrykey_p.h" #include -#include #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) # include #else diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index 3cdb8482..0e9decf1 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -576,9 +576,8 @@ bool Utils::isDwmCompositionEnabled() if (!registry.isValid()) { return false; } - bool ok = false; - const DWORD value = registry.value(kComposition).toULongLong(&ok); - return (ok && (value != 0)); + const DWORD value = registry.value(kComposition).value_or(0); + return (value != 0); }; if (!API_DWM_AVAILABLE(DwmIsCompositionEnabled)) { return resultFromRegistry(); @@ -702,9 +701,8 @@ QColor Utils::getDwmColorizationColor() if (!registry.isValid()) { return kDefaultDarkGrayColor; } - bool ok = false; - const DWORD value = registry.value(kColorizationColor).toULongLong(&ok); - return (ok ? QColor::fromRgba(value) : kDefaultDarkGrayColor); + const DWORD value = registry.value(kColorizationColor).value_or(0); + return QColor::fromRgba(value); }; if (!API_DWM_AVAILABLE(DwmGetColorizationColor)) { return resultFromRegistry(); @@ -727,13 +725,11 @@ DwmColorizationArea Utils::getDwmColorizationArea() return DwmColorizationArea::None_; } const RegistryKey themeRegistry(RegistryRootKey::CurrentUser, personalizeRegistryKey()); - bool themeOk = false; - const DWORD themeValue = themeRegistry.isValid() ? themeRegistry.value(qDwmColorKeyName).toULongLong(&themeOk) : 0; + const DWORD themeValue = themeRegistry.isValid() ? themeRegistry.value(qDwmColorKeyName).value_or(0) : 0; const RegistryKey dwmRegistry(RegistryRootKey::CurrentUser, dwmRegistryKey()); - bool dwmOk = false; - const DWORD dwmValue = dwmRegistry.isValid() ? dwmRegistry.value(qDwmColorKeyName).toULongLong(&dwmOk) : 0; - const bool theme = (themeOk && (themeValue != 0)); - const bool dwm = (dwmOk && (dwmValue != 0)); + const DWORD dwmValue = dwmRegistry.isValid() ? dwmRegistry.value(qDwmColorKeyName).value_or(0) : 0; + const bool theme = (themeValue != 0); + const bool dwm = (dwmValue != 0); if (theme && dwm) { return DwmColorizationArea::All; } else if (theme) { @@ -1518,9 +1514,8 @@ bool Utils::shouldAppsUseDarkMode_windows() if (!registry.isValid()) { return false; } - bool ok = false; - const DWORD value = registry.value(kAppsUseLightTheme).toULongLong(&ok); - return (ok && (value == 0)); + const DWORD value = registry.value(kAppsUseLightTheme).value_or(0); + return (value == 0); }; // Starting from Windows 10 1903, "ShouldAppsUseDarkMode()" (exported by UXTHEME.DLL, // ordinal number 132) always return "TRUE" (actually, a random non-zero number at @@ -1752,11 +1747,7 @@ QColor Utils::getDwmAccentColor() if (!registry.isValid()) { return kDefaultDarkGrayColor; } - bool ok = false; - const DWORD value = registry.value(kAccentColor).toULongLong(&ok); - if (!ok) { - return kDefaultDarkGrayColor; - } + const DWORD value = registry.value(kAccentColor).value_or(0); // The retrieved value is in the #AABBGGRR format, we need to // convert it to the #AARRGGBB format that Qt accepts. const QColor abgr = QColor::fromRgba(value); @@ -1780,16 +1771,11 @@ WallpaperAspectStyle Utils::getWallpaperAspectStyle() if (!registry.isValid()) { return defaultStyle; } - bool ok = false; - const DWORD wallpaperStyle = registry.value(kWallpaperStyle).toULongLong(&ok); - if (!ok) { - return defaultStyle; - } + const DWORD wallpaperStyle = registry.value(kWallpaperStyle).value_or(0); switch (wallpaperStyle) { case 0: { - ok = false; - const DWORD tileWallpaper = registry.value(kTileWallpaper).toULongLong(&ok); - if (ok && (tileWallpaper != 0)) { + const DWORD tileWallpaper = registry.value(kTileWallpaper).value_or(0); + if (tileWallpaper != 0) { return WallpaperAspectStyle::Tile; } return WallpaperAspectStyle::Center; @@ -1860,22 +1846,22 @@ void Utils::setQtDarkModeAwareEnabled(const bool enable, const bool pureQuick) // There's no global dark theme for Qt Quick applications, so setting this // flag has no effect for pure Qt Quick applications. return {App::DarkModeWindowFrames | App::DarkModeStyle}; -#else +#else // (QT_VERSION < QT_VERSION_CHECK(6, 5, 0)) if (pureQuick) { // Pure Qt Quick application, it's OK to enable the DarkModeStyle flag. return {App::DarkModeWindowFrames | App::DarkModeStyle}; } // Don't try to use the broken dark theme for Qt Widgets applications. return {App::DarkModeWindowFrames}; -#endif +#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) }()); } else { WARNING << "QWindowsApplication is not available."; } -#else +#else // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) Q_UNUSED(enable); Q_UNUSED(pureQuick); -#endif +#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) } FRAMELESSHELPER_END_NAMESPACE diff --git a/src/quick/CMakeLists.txt b/src/quick/CMakeLists.txt index 2a1f6132..06d21154 100644 --- a/src/quick/CMakeLists.txt +++ b/src/quick/CMakeLists.txt @@ -69,7 +69,7 @@ set(SOURCES framelessquickwindow.cpp framelessquickhelper.cpp quickchromepalette.cpp - global.cpp + framelesshelperquick_global.cpp quickmicamaterial.cpp quickimageitem.cpp ) diff --git a/src/quick/global.cpp b/src/quick/framelesshelperquick_global.cpp similarity index 100% rename from src/quick/global.cpp rename to src/quick/framelesshelperquick_global.cpp diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index ac9b0de6..87bbb4f7 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -62,7 +62,7 @@ set(SOURCES standardsystembutton.cpp standardtitlebar.cpp widgetssharedhelper.cpp - global.cpp + framelesshelperwidgets_global.cpp ) if(WIN32 AND NOT FRAMELESSHELPER_BUILD_STATIC) diff --git a/src/widgets/global.cpp b/src/widgets/framelesshelperwidgets_global.cpp similarity index 100% rename from src/widgets/global.cpp rename to src/widgets/framelesshelperwidgets_global.cpp