From 2731d09da9c2da252112a400b6474a9777633a1c Mon Sep 17 00:00:00 2001 From: Cloud Date: Tue, 21 Jul 2026 19:51:07 +0800 Subject: [PATCH 1/2] fix: fix dtkgui build on MSYS2/ucrt64 environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add Win32 platform window interface (DWin32PlatformWindowInterface) with DWM rounded corners, system theme detection, and window property management - Fix compilation errors from Linux-only headers on Windows: conditionally compile qwaylandwindow_p.h and WaylandClient deps - Add LIBDTKGUISHARED_EXPORT macro to handle DLL export/import symbol issues on Windows correctly - Add D_DISABLE_DCONFIG macro to disable DConfig dependency on non-Linux platforms, using QSettings as theme persistence fallback - Make librsvg optional so the build can skip it on Windows - Guard Treeland/Wayland and dde-kwin-debug to Linux-only builds - Compile DSvgRenderer only on Linux (depends on librsvg) - Replace LIBDTKCORESHARED_EXPORT with LIBDTKGUISHARED_EXPORT in private headers for correct symbol visibility fix: 修复 MSYS2/ucrt64 环境下 dtkgui 编译问题 - 添加 Win32 平台窗口接口 (DWin32PlatformWindowInterface),支持 DWM 圆角、系统主题检测和窗口属性管理 - 修复 Linux 特有头文件在 Windows 上的编译错误: 条件编译 qwaylandwindow_p.h、WaylandClient 相关依赖 - 添加 LIBDTKGUISHARED_EXPORT 宏,正确处理 Windows DLL 的 导出/导入符号问题 - 添加 D_DISABLE_DCONFIG 宏,非 Linux 平台禁用 DConfig 依赖, 使用 QSettings 作为主题持久化方案 - 修复 librsvg 设为可选,Windows 上可跳过依赖 - 修复 Treeland/Wayland 和 dde-kwin-debug 仅在 Linux 上构建 - 修复 DSvgRenderer 仅在 Linux 上编译(依赖 librsvg) - 修复 private 头文件中 LIBDTKCORESHARED_EXPORT 替换为 LIBDTKGUISHARED_EXPORT --- dtkgui.cmake | 14 +- include/global/dtkgui_global.h | 10 +- include/kernel/dpalette.h | 10 +- include/util/ddciiconpalette.h | 4 +- src/CMakeLists.txt | 14 +- src/kernel/dguiapplicationhelper.cpp | 89 +++- src/kernel/dplatformhandle.cpp | 12 +- src/kernel/dwindowmanagerhelper.cpp | 9 +- src/kernel/kernel.cmake | 8 +- .../win32/dwin32platformwindowinterface.cpp | 452 ++++++++++++++++++ .../win32/dwin32platformwindowinterface.h | 92 ++++ src/plugins/platform/win32/win32.cmake | 10 + .../xcb/dxcbplatformwindowinterface.cpp | 4 +- src/plugins/plugins.cmake | 25 +- src/private/dplatforminterface_p.h | 6 +- src/private/dplatformwindowinterface_p.h | 6 +- src/util/dsvgrenderer.cpp | 7 +- tools/CMakeLists.txt | 4 +- 18 files changed, 721 insertions(+), 55 deletions(-) create mode 100644 src/plugins/platform/win32/dwin32platformwindowinterface.cpp create mode 100644 src/plugins/platform/win32/dwin32platformwindowinterface.h create mode 100644 src/plugins/platform/win32/win32.cmake diff --git a/dtkgui.cmake b/dtkgui.cmake index dd311287..288e6e01 100644 --- a/dtkgui.cmake +++ b/dtkgui.cmake @@ -23,6 +23,10 @@ option(DTK_DISABLE_EX_IMAGE_FORMAT "Disable libraw and freeimage" OFF) set(CMAKE_CXX_STANDARD 17) +if(NOT LINUX) + add_definitions(-DD_DISABLE_DCONFIG) +endif() + if("${QT_VERSION_MAJOR}" STREQUAL "5") set (BUILD_DOCS ON CACHE BOOL "Generate doxygen-based documentation") else() @@ -113,7 +117,9 @@ find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui DBus Network) find_package(PkgConfig REQUIRED) find_package(Dtk${DTK_NAME_SUFFIX} REQUIRED Core Tools) find_package(DtkBuildHelper REQUIRED) -pkg_check_modules(librsvg REQUIRED IMPORTED_TARGET librsvg-2.0) +if(NOT DTK_DISABLE_LIBRSVG) + pkg_check_modules(librsvg REQUIRED IMPORTED_TARGET librsvg-2.0) +endif() if(NOT DTK_DISABLE_LIBXDG) if (${QT_VERSION_MAJOR} STREQUAL "5") @@ -138,6 +144,12 @@ if(FreeImage_FOUND AND libraw_FOUND) set(EX_IMAGE_FORMAT_LIBS_FOUND ON) endif() +# Export all symbols on Windows to avoid dllimport issues +if(WIN32 AND NOT MSVC) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols") + add_definitions(-DLIBDTKGUI_LIBRARY) +endif() + set(OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(src ${OUTPUT_DIR}/src) if(BUILD_TESTING) diff --git a/include/global/dtkgui_global.h b/include/global/dtkgui_global.h index fd0ac377..f2bcd277 100644 --- a/include/global/dtkgui_global.h +++ b/include/global/dtkgui_global.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -16,4 +16,12 @@ #define DGUI_END_NAMESPACE }} #define DGUI_USE_NAMESPACE using namespace DTK_GUI_NAMESPACE; +#if defined(DTK_STATIC_LIB) +# define LIBDTKGUISHARED_EXPORT +#elif defined(LIBDTKGUI_LIBRARY) +# define LIBDTKGUISHARED_EXPORT Q_DECL_EXPORT +#else +# define LIBDTKGUISHARED_EXPORT Q_DECL_IMPORT +#endif + #endif // DTKGUI_GLOBAL_H diff --git a/include/kernel/dpalette.h b/include/kernel/dpalette.h index 5c5faec8..824b2e50 100644 --- a/include/kernel/dpalette.h +++ b/include/kernel/dpalette.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -76,7 +76,7 @@ class DPalette : public QPalette protected: QScopedPointer d; - friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const DPalette &p); + friend LIBDTKGUISHARED_EXPORT QDataStream &operator<<(QDataStream &s, const DPalette &p); }; DGUI_END_NAMESPACE @@ -86,12 +86,12 @@ QT_BEGIN_NAMESPACE DPalette stream functions *****************************************************************************/ #ifndef QT_NO_DATASTREAM -Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const DTK_GUI_NAMESPACE::DPalette &p); -Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, DTK_GUI_NAMESPACE::DPalette &p); +LIBDTKGUISHARED_EXPORT QDataStream &operator<<(QDataStream &ds, const DTK_GUI_NAMESPACE::DPalette &p); +LIBDTKGUISHARED_EXPORT QDataStream &operator>>(QDataStream &ds, DTK_GUI_NAMESPACE::DPalette &p); #endif // QT_NO_DATASTREAM #ifndef QT_NO_DEBUG_STREAM -Q_GUI_EXPORT QDebug operator<<(QDebug, const DTK_GUI_NAMESPACE::DPalette &); +LIBDTKGUISHARED_EXPORT QDebug operator<<(QDebug, const DTK_GUI_NAMESPACE::DPalette &); #endif QT_END_NAMESPACE diff --git a/include/util/ddciiconpalette.h b/include/util/ddciiconpalette.h index 8677841d..d67a1639 100644 --- a/include/util/ddciiconpalette.h +++ b/include/util/ddciiconpalette.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -63,7 +63,7 @@ DGUI_END_NAMESPACE QT_BEGIN_NAMESPACE #ifndef QT_NO_DEBUG_STREAM -Q_GUI_EXPORT QDebug operator<<(QDebug, const DTK_GUI_NAMESPACE::DDciIconPalette &); +LIBDTKGUISHARED_EXPORT QDebug operator<<(QDebug, const DTK_GUI_NAMESPACE::DDciIconPalette &); #endif QT_END_NAMESPACE #endif // DDCIICONPALETTE_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d29242f3..82142aee 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,9 +1,15 @@ if("${QT_VERSION_MAJOR}" STREQUAL "6") - find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets WaylandClient) + find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) + if(LINUX) + find_package(Qt6 REQUIRED COMPONENTS WaylandClient) + endif() if (${Qt6Core_VERSION} VERSION_GREATER_EQUAL "6.10.0") set(QT_NO_PRIVATE_MODULE_WARNING ON) - find_package(Qt6 REQUIRED COMPONENTS CorePrivate GuiPrivate WaylandClientPrivate) + find_package(Qt6 REQUIRED COMPONENTS CorePrivate GuiPrivate) + if(LINUX) + find_package(Qt6 REQUIRED COMPONENTS WaylandClientPrivate) + endif() endif() else() find_package(Qt5 REQUIRED COMPONENTS WaylandClient XkbCommonSupport) @@ -49,8 +55,10 @@ PRIVATE Qt${QT_VERSION_MAJOR}::GuiPrivate Qt${QT_VERSION_MAJOR}::CorePrivate Qt${QT_VERSION_MAJOR}::DBus - Qt${QT_VERSION_MAJOR}::WaylandClientPrivate ) +if(LINUX) + target_link_libraries(${LIB_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::WaylandClientPrivate) +endif() if("${QT_VERSION_MAJOR}" STREQUAL "5") target_link_libraries(${LIB_NAME} diff --git a/src/kernel/dguiapplicationhelper.cpp b/src/kernel/dguiapplicationhelper.cpp index 70c63884..5b8465a9 100644 --- a/src/kernel/dguiapplicationhelper.cpp +++ b/src/kernel/dguiapplicationhelper.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -27,20 +28,11 @@ #include #include #include +#include -#ifdef Q_OS_UNIX -#include -#include -#include -#include -#include -#include -#include +#ifdef Q_OS_WIN +#include #endif -#include -#include -#include -#include #ifdef Q_OS_UNIX #include @@ -50,7 +42,6 @@ #include #include #include -#include #endif #include @@ -125,8 +116,14 @@ Q_GLOBAL_STATIC(DFontManager, _globalFM) #define DTK_ANIMATIONS_ENV "D_DTK_DISABLE_ANIMATIONS" #define DTK_DISABLE_INWINDOWBLUR_ENV "D_DTK_DISABLE_INWINDOWBLUR" +#ifndef D_DISABLE_DCONFIG Q_GLOBAL_STATIC_WITH_ARGS(OrgDeepinDTKPreference, _d_dconfig, (DTK_CORE_NAMESPACE::DConfig::globalThread(), nullptr, "org.deepin.dtk.preference", DTK_CORE_NAMESPACE::DSGApplication::id(), {}, false, nullptr)) +#define DTK_DCONFIG_PTR _d_dconfig +#else +static OrgDeepinDTKPreference* _d_dconfig_instance = nullptr; +#define DTK_DCONFIG_PTR _d_dconfig_instance +#endif // Keys allowed to be forwarded between single-instance client and server. static const QStringList s_singleInstanceForwardEnvKeys = { @@ -210,9 +207,11 @@ LoadManualServiceWorker::~LoadManualServiceWorker() void LoadManualServiceWorker::run() { +#ifdef Q_OS_UNIX QDBusInterface("com.deepin.Manual.Search", "/com/deepin/Manual/Search", "com.deepin.Manual.Search"); +#endif } void LoadManualServiceWorker::checkManualServiceWakeUp() @@ -478,21 +477,54 @@ void DGuiApplicationHelperPrivate::initPaletteType() const const_cast(this)->paletteTypeInited = true; auto applyThemeType = [this](bool emitSignal){ - int ct = _d_dconfig->themeType(); - if (ct > DGuiApplicationHelper::DarkType || ct < DGuiApplicationHelper::UnknownType) - ct = DGuiApplicationHelper::UnknownType; - + int ct = DGuiApplicationHelper::UnknownType; + if (DTK_DCONFIG_PTR) { + ct = DTK_DCONFIG_PTR->themeType(); + if (ct > DGuiApplicationHelper::DarkType || ct < DGuiApplicationHelper::UnknownType) + ct = DGuiApplicationHelper::UnknownType; + } const_cast(this)->setPaletteType(DGuiApplicationHelper::ColorType(ct), emitSignal); }; // 读取配置文件中的主题类型并立即应用 +#ifndef D_DISABLE_DCONFIG DTK_CORE_NAMESPACE::DConfig dconfig("org.deepin.dtk.preference"); int ct = dconfig.value("themeType", DGuiApplicationHelper::UnknownType).toInt(); const_cast(this)->setPaletteType(DGuiApplicationHelper::ColorType(ct), false); +#else +#ifdef Q_OS_WIN + // Windows: read from QSettings, fallback to system theme detection + int ct = DGuiApplicationHelper::UnknownType; + QSettings winSettings("deepin", "deepin-music"); + if (winSettings.contains("themeType")) { + ct = winSettings.value("themeType", DGuiApplicationHelper::UnknownType).toInt(); + } else { + // Detect system dark/light mode from Windows registry + HKEY hKey; + DWORD value = 1; // default: light + DWORD size = sizeof(value); + if (RegOpenKeyExW(HKEY_CURRENT_USER, + L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", + 0, KEY_READ, &hKey) == ERROR_SUCCESS) { + if (RegQueryValueExW(hKey, L"AppsUseLightTheme", nullptr, nullptr, + reinterpret_cast(&value), &size) == ERROR_SUCCESS) { + ct = value ? DGuiApplicationHelper::LightType : DGuiApplicationHelper::DarkType; + } + RegCloseKey(hKey); + } + } + const_cast(this)->setPaletteType(DGuiApplicationHelper::ColorType(ct), false); +#else + int ct = DGuiApplicationHelper::UnknownType; + const_cast(this)->setPaletteType(DGuiApplicationHelper::ColorType(ct), false); +#endif +#endif - QObject::connect(_d_dconfig.operator ()(), &OrgDeepinDTKPreference::themeTypeChanged, q_func(), [applyThemeType] { - applyThemeType(true); - }); + if (DTK_DCONFIG_PTR) { + QObject::connect(DTK_DCONFIG_PTR, &OrgDeepinDTKPreference::themeTypeChanged, q_func(), [applyThemeType] { + applyThemeType(true); + }); + } } void DGuiApplicationHelperPrivate::_q_sizeModeChanged(int mode) @@ -1886,14 +1918,14 @@ bool DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::Attribute attri if (isDisable) return false; - return _d_dconfig->enableDtkAnimations(); + return DTK_DCONFIG_PTR ? DTK_DCONFIG_PTR->enableDtkAnimations() : false; } case HasInWindowBlur: { static bool isDisable = qEnvironmentVariableIsSet(DTK_DISABLE_INWINDOWBLUR_ENV); if (isDisable) return false; - return !_d_dconfig->disableInWindowBlur(); + return DTK_DCONFIG_PTR ? !DTK_DCONFIG_PTR->disableInWindowBlur() : false; } default: return DGuiApplicationHelperPrivate::attributes.testFlag(attribute); @@ -1934,8 +1966,17 @@ void DGuiApplicationHelper::setPaletteType(DGuiApplicationHelper::ColorType pale d->initPaletteType(); d->setPaletteType(paletteType, true); - if (!DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::DontSaveApplicationTheme)) - _d_dconfig->setThemeType(static_cast(paletteType)); + if (!DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::DontSaveApplicationTheme)) { + if (DTK_DCONFIG_PTR) { + DTK_DCONFIG_PTR->setThemeType(static_cast(paletteType)); + } +#ifdef Q_OS_WIN + else { + QSettings winSettings("deepin", "deepin-music"); + winSettings.setValue("themeType", static_cast(paletteType)); + } +#endif + } } /*! diff --git a/src/kernel/dplatformhandle.cpp b/src/kernel/dplatformhandle.cpp index bc466026..a9083397 100644 --- a/src/kernel/dplatformhandle.cpp +++ b/src/kernel/dplatformhandle.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022-2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -11,6 +11,9 @@ #ifndef DTK_DISABLE_TREELAND #include "plugins/platform/treeland/dtreelandplatformwindowinterface.h" #endif +#ifdef Q_OS_WIN +#include "plugins/platform/win32/dwin32platformwindowinterface.h" +#endif DGUI_BEGIN_NAMESPACE @@ -322,6 +325,13 @@ static DPlatformWindowInterface *createWindowInterface(QWindow *window, DPlatfor impl = new DTreeLandPlatformWindowInterface(window, platformHandle); } #endif + +#ifdef Q_OS_WIN + if (!impl) { + qDebug() << "Creating DWin32PlatformWindowInterface for window" << window; + impl = new DWin32PlatformWindowInterface(window, platformHandle); + } +#endif } return impl; diff --git a/src/kernel/dwindowmanagerhelper.cpp b/src/kernel/dwindowmanagerhelper.cpp index cd61b542..43c5e035 100644 --- a/src/kernel/dwindowmanagerhelper.cpp +++ b/src/kernel/dwindowmanagerhelper.cpp @@ -9,7 +9,7 @@ #include #include - +#ifdef Q_OS_LINUX #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #include #define D_XCB_WINDOW_TYPE QNativeInterface::Private::QXcbWindow::WindowType @@ -17,7 +17,7 @@ #include #define D_XCB_WINDOW_TYPE QXcbWindowFunctions::WmWindowType #endif - +#endif #include #include @@ -492,6 +492,7 @@ DWindowManagerHelper::MotifDecorations DWindowManagerHelper::getMotifDecorations */ void DWindowManagerHelper::setWmWindowTypes(QWindow *window, WmWindowTypes types) { +#ifdef Q_OS_LINUX const int _types = static_cast(types); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) @@ -504,6 +505,10 @@ void DWindowManagerHelper::setWmWindowTypes(QWindow *window, WmWindowTypes types #else QXcbWindowFunctions::setWmWindowType(window, static_cast(_types)); #endif +#else + Q_UNUSED(window) + Q_UNUSED(types) +#endif } /*! diff --git a/src/kernel/kernel.cmake b/src/kernel/kernel.cmake index bbccd2fd..0bdf8d01 100644 --- a/src/kernel/kernel.cmake +++ b/src/kernel/kernel.cmake @@ -9,7 +9,13 @@ set(kernel_SRC ${KERNEL_SOURCE} ) -dtk_add_config_to_cpp(kernel_SRC /usr/share/dsg/configs/org.deepin.dtk.preference.json +if(LINUX) + set(_PREF_CONFIG_JSON /usr/share/dsg/configs/org.deepin.dtk.preference.json) +else() + set(_PREF_CONFIG_JSON ${CMAKE_INSTALL_PREFIX}/share/dsg/configs/org.deepin.dtk.preference.json) +endif() + +dtk_add_config_to_cpp(kernel_SRC ${_PREF_CONFIG_JSON} OUTPUT_FILE_NAME orgdeepindtkpreference.hpp CLASS_NAME OrgDeepinDTKPreference ) diff --git a/src/plugins/platform/win32/dwin32platformwindowinterface.cpp b/src/plugins/platform/win32/dwin32platformwindowinterface.cpp new file mode 100644 index 00000000..8e7ff369 --- /dev/null +++ b/src/plugins/platform/win32/dwin32platformwindowinterface.cpp @@ -0,0 +1,452 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dwin32platformwindowinterface.h" +#include "dguiapplicationhelper.h" + +#include +#include +#include +#include +#include + +#ifdef Q_OS_WIN +#include +#include + +// Global native event filter to detect WM_SETTINGCHANGE (system theme change) +class WinThemeWatcher : public QAbstractNativeEventFilter +{ +public: + bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) override + { + if (eventType != "windows_generic_MSG") + return false; + + MSG *msg = static_cast(message); + if (msg->message != WM_SETTINGCHANGE) + return false; + + // Check if the personalization settings changed + if (msg->lParam && wcscmp(reinterpret_cast(msg->lParam), + L"ImmersiveColorSet") == 0) { + QSettings winSettings("deepin", "deepin-music"); + if (!winSettings.contains("themeType")) { + // No user preference — detect system theme and apply + HKEY hKey; + DWORD value = 1; + DWORD size = sizeof(value); + bool dark = false; + if (RegOpenKeyExW(HKEY_CURRENT_USER, + L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", + 0, KEY_READ, &hKey) == ERROR_SUCCESS) { + if (RegQueryValueExW(hKey, L"AppsUseLightTheme", nullptr, nullptr, + reinterpret_cast(&value), &size) == ERROR_SUCCESS) { + dark = (value == 0); + } + RegCloseKey(hKey); + } + QMetaObject::invokeMethod(qApp, [dark]() { + DGuiApplicationHelper::instance()->setPaletteType( + dark ? DGuiApplicationHelper::DarkType : DGuiApplicationHelper::LightType); + }, Qt::QueuedConnection); + } + } + return false; + } +}; + +// DWMWA_WINDOW_CORNER_PREFERENCE (Win 11 build 22000+) +#ifndef DWMWA_WINDOW_CORNER_PREFERENCE +#define DWMWA_WINDOW_CORNER_PREFERENCE 33 +#endif + +#ifndef DWMWCP_ROUND +#define DWMWCP_ROUND 2 +#endif + +#ifndef DWMWCP_DONOTROUND +#define DWMWCP_DONOTROUND 1 +#endif + +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 +#endif + +// Runtime check for Windows 11 build 22000+ +static bool isWin11OrLater() +{ + typedef NTSTATUS (WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); + static RtlGetVersionPtr fnVersion = nullptr; + static bool checked = false; + static bool result = false; + + if (!checked) { + fnVersion = reinterpret_cast( + GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion")); + if (fnVersion) { + RTL_OSVERSIONINFOW osvi = {}; + osvi.dwOSVersionInfoSize = sizeof(osvi); + if (fnVersion(&osvi) == 0) { + result = (osvi.dwBuildNumber >= 22000); + } + } + checked = true; + } + return result; +} + +static HWND getHwnd(QWindow *window) +{ + if (!window) + return nullptr; + return reinterpret_cast(window->winId()); +} + +#endif // Q_OS_WIN + +DGUI_BEGIN_NAMESPACE + +DWin32PlatformWindowInterface::DWin32PlatformWindowInterface(QWindow *window, DPlatformHandle *platformHandle, QObject *parent) + : QObject(parent) + , DPlatformWindowInterface(window, platformHandle) +{ + if (m_window) { + m_window->installEventFilter(this); + } + +#ifdef Q_OS_WIN + // Install global native event filter for system theme detection (once) + static bool filterInstalled = false; + if (!filterInstalled) { + qApp->installNativeEventFilter(new WinThemeWatcher); + filterInstalled = true; + } +#endif +} + +DWin32PlatformWindowInterface::~DWin32PlatformWindowInterface() +{ + if (m_window) { + m_window->removeEventFilter(this); + } +} + +void *DWin32PlatformWindowInterface::hwnd() const +{ +#ifdef Q_OS_WIN + return getHwnd(m_window); +#else + return nullptr; +#endif +} + +void DWin32PlatformWindowInterface::setEnabled(bool enabled) +{ + m_enabled = enabled; + Q_UNUSED(enabled) +} + +bool DWin32PlatformWindowInterface::isEnabled() const +{ + return m_enabled; +} + +bool DWin32PlatformWindowInterface::isEnabledNoTitlebar() const +{ + return true; +} + +bool DWin32PlatformWindowInterface::setEnabledNoTitlebar(bool enable) +{ + Q_UNUSED(enable) + return true; +} + +int DWin32PlatformWindowInterface::windowRadius() const +{ + return m_windowRadius; +} + +void DWin32PlatformWindowInterface::setWindowRadius(int windowRadius) +{ + if (m_windowRadius == windowRadius) + return; + + qDebug() << "DWin32PlatformWindowInterface::setWindowRadius:" << windowRadius; + m_windowRadius = windowRadius; + +#ifdef Q_OS_WIN + // Defer to showEvent if window not yet visible + if (m_windowVisible) + updateRoundedCorners(); +#endif + + if (m_platformHandle) + Q_EMIT m_platformHandle->windowRadiusChanged(); +} + +int DWin32PlatformWindowInterface::borderWidth() const +{ + return m_borderWidth; +} + +void DWin32PlatformWindowInterface::setBorderWidth(int borderWidth) +{ + if (m_borderWidth == borderWidth) + return; + + m_borderWidth = borderWidth; + + if (m_platformHandle) + Q_EMIT m_platformHandle->borderWidthChanged(); +} + +QColor DWin32PlatformWindowInterface::borderColor() const +{ + return m_borderColor; +} + +void DWin32PlatformWindowInterface::setBorderColor(const QColor &borderColor) +{ + if (m_borderColor == borderColor) + return; + + m_borderColor = borderColor; + + if (m_platformHandle) + Q_EMIT m_platformHandle->borderColorChanged(); +} + +int DWin32PlatformWindowInterface::shadowRadius() const +{ + return m_shadowRadius; +} + +void DWin32PlatformWindowInterface::setShadowRadius(int shadowRadius) +{ + if (m_shadowRadius == shadowRadius) + return; + + m_shadowRadius = shadowRadius; + + if (m_platformHandle) + Q_EMIT m_platformHandle->shadowRadiusChanged(); +} + +QPoint DWin32PlatformWindowInterface::shadowOffset() const +{ + return m_shadowOffset; +} + +void DWin32PlatformWindowInterface::setShadowOffset(const QPoint &shadowOffset) +{ + if (m_shadowOffset == shadowOffset) + return; + + m_shadowOffset = shadowOffset; + + if (m_platformHandle) + Q_EMIT m_platformHandle->shadowOffsetChanged(); +} + +QColor DWin32PlatformWindowInterface::shadowColor() const +{ + return m_shadowColor; +} + +void DWin32PlatformWindowInterface::setShadowColor(const QColor &shadowColor) +{ + if (m_shadowColor == shadowColor) + return; + + m_shadowColor = shadowColor; + + if (m_platformHandle) + Q_EMIT m_platformHandle->shadowColorChanged(); +} + +DPlatformHandle::EffectScene DWin32PlatformWindowInterface::windowEffect() +{ + return {}; +} + +void DWin32PlatformWindowInterface::setWindowEffect(DPlatformHandle::EffectScenes effectScene) +{ + Q_UNUSED(effectScene) +} + +QPainterPath DWin32PlatformWindowInterface::clipPath() const +{ + return {}; +} + +void DWin32PlatformWindowInterface::setClipPath(const QPainterPath &clipPath) +{ + Q_UNUSED(clipPath) +} + +QRegion DWin32PlatformWindowInterface::frameMask() const +{ + return {}; +} + +void DWin32PlatformWindowInterface::setFrameMask(const QRegion &frameMask) +{ + Q_UNUSED(frameMask) +} + +QMargins DWin32PlatformWindowInterface::frameMargins() const +{ + return {}; +} + +bool DWin32PlatformWindowInterface::translucentBackground() const +{ + return m_translucentBackground; +} + +void DWin32PlatformWindowInterface::setTranslucentBackground(bool translucentBackground) +{ + if (m_translucentBackground == translucentBackground) + return; + + m_translucentBackground = translucentBackground; +} + +bool DWin32PlatformWindowInterface::enableSystemResize() const +{ + return m_enableSystemResize; +} + +void DWin32PlatformWindowInterface::setEnableSystemResize(bool enableSystemResize) +{ + m_enableSystemResize = enableSystemResize; +} + +bool DWin32PlatformWindowInterface::enableSystemMove() const +{ + return m_enableSystemMove; +} + +void DWin32PlatformWindowInterface::setEnableSystemMove(bool enableSystemMove) +{ + m_enableSystemMove = enableSystemMove; +} + +bool DWin32PlatformWindowInterface::enableBlurWindow() const +{ + return DPlatformWindowInterface::enableBlurWindow(); +} + +void DWin32PlatformWindowInterface::setEnableBlurWindow(bool enableBlurWindow) +{ + DPlatformWindowInterface::setEnableBlurWindow(enableBlurWindow); +} + +bool DWin32PlatformWindowInterface::eventFilter(QObject *watched, QEvent *event) +{ + if (watched != m_window) + return QObject::eventFilter(watched, event); + +#ifdef Q_OS_WIN + switch (event->type()) { + case QEvent::Show: + m_windowVisible = true; + updateShadow(); + updateRoundedCorners(); + updateSystemTheme(); + break; + case QEvent::PlatformSurface: { + auto *surfaceEvent = static_cast(event); + if (surfaceEvent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) { + qDebug() << "DWin32PlatformWindowInterface: SurfaceCreated, waiting for Show"; + } + break; + } + default: + break; + } +#endif + + return QObject::eventFilter(watched, event); +} + +void DWin32PlatformWindowInterface::updateSystemTheme() +{ +#ifdef Q_OS_WIN + HKEY hKey; + DWORD value = 1; + DWORD size = sizeof(value); + bool darkMode = false; + + if (RegOpenKeyExW(HKEY_CURRENT_USER, + L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", + 0, KEY_READ, &hKey) == ERROR_SUCCESS) { + if (RegQueryValueExW(hKey, L"AppsUseLightTheme", nullptr, nullptr, + reinterpret_cast(&value), &size) == ERROR_SUCCESS) { + darkMode = (value == 0); + } + RegCloseKey(hKey); + } + + if (darkMode != m_systemDarkMode) { + m_systemDarkMode = darkMode; + qDebug() << "DWin32PlatformWindowInterface: System theme changed to" + << (darkMode ? "dark" : "light"); + + // Notify DGuiApplicationHelper of the system theme change + // Only update if user hasn't manually set a theme (DontSaveApplicationTheme is not set) + if (!DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::DontSaveApplicationTheme)) { + QSettings winSettings("deepin", "deepin-music"); + if (!winSettings.contains("themeType")) { + // No user preference saved — follow system theme + DGuiApplicationHelper::instance()->setPaletteType( + darkMode ? DGuiApplicationHelper::DarkType : DGuiApplicationHelper::LightType); + } + } + } +#endif +} + +void DWin32PlatformWindowInterface::updateShadow() +{ +#ifdef Q_OS_WIN + HWND h = getHwnd(m_window); + if (!h) { + qWarning() << "DWin32PlatformWindowInterface::updateShadow: HWND is null"; + return; + } + + // DwmExtendFrameIntoClientArea with {-1,-1,-1,-1} would make the entire + // window glass/transparent — not what we want. Skip it for now. + // A proper shadow implementation would use DWMWA_NCRENDERING_POLICY or + // a custom shadow surface. For now, just log. + qDebug() << "DWin32PlatformWindowInterface::updateShadow: shadow deferred (DWM glass not applied)"; +#endif +} + +void DWin32PlatformWindowInterface::updateRoundedCorners() +{ +#ifdef Q_OS_WIN + HWND h = getHwnd(m_window); + if (!h) + return; + + if (!isWin11OrLater()) { + qDebug() << "DWin32PlatformWindowInterface::updateRoundedCorners: not Win11+, skipping"; + return; + } + + int preference = (m_windowRadius > 0) ? DWMWCP_ROUND : DWMWCP_DONOTROUND; + qDebug() << "DWin32PlatformWindowInterface::updateRoundedCorners: radius=" << m_windowRadius << "preference=" << preference; + HRESULT hr = DwmSetWindowAttribute(h, DWMWA_WINDOW_CORNER_PREFERENCE, + &preference, sizeof(preference)); + if (FAILED(hr)) { + qWarning() << "DwmSetWindowAttribute(DWMWA_WINDOW_CORNER_PREFERENCE) failed:" << QString::number(hr, 16); + } +#endif +} + +DGUI_END_NAMESPACE diff --git a/src/plugins/platform/win32/dwin32platformwindowinterface.h b/src/plugins/platform/win32/dwin32platformwindowinterface.h new file mode 100644 index 00000000..1b0b3823 --- /dev/null +++ b/src/plugins/platform/win32/dwin32platformwindowinterface.h @@ -0,0 +1,92 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DWIN32PLATFORMWINDOWINTERFACE_H +#define DWIN32PLATFORMWINDOWINTERFACE_H + +#include "private/dplatformwindowinterface_p.h" + +#include + +DGUI_BEGIN_NAMESPACE + +class DWin32PlatformWindowInterface : public QObject, public DPlatformWindowInterface +{ + Q_OBJECT +public: + DWin32PlatformWindowInterface(QWindow *window, DPlatformHandle *platformHandle, QObject *parent = nullptr); + ~DWin32PlatformWindowInterface() override; + + void setEnabled(bool enabled) override; + bool isEnabled() const override; + + bool isEnabledNoTitlebar() const override; + bool setEnabledNoTitlebar(bool enable) override; + + int windowRadius() const override; + void setWindowRadius(int windowRadius) override; + + int borderWidth() const override; + void setBorderWidth(int borderWidth) override; + + QColor borderColor() const override; + void setBorderColor(const QColor &borderColor) override; + + int shadowRadius() const override; + void setShadowRadius(int shadowRadius) override; + + QPoint shadowOffset() const override; + void setShadowOffset(const QPoint &shadowOffset) override; + + QColor shadowColor() const override; + void setShadowColor(const QColor &shadowColor) override; + + DPlatformHandle::EffectScene windowEffect() override; + void setWindowEffect(DPlatformHandle::EffectScenes effectScene) override; + + QPainterPath clipPath() const override; + void setClipPath(const QPainterPath &clipPath) override; + + QRegion frameMask() const override; + void setFrameMask(const QRegion &frameMask) override; + + QMargins frameMargins() const override; + + bool translucentBackground() const override; + void setTranslucentBackground(bool translucentBackground) override; + + bool enableSystemResize() const override; + void setEnableSystemResize(bool enableSystemResize) override; + + bool enableSystemMove() const override; + void setEnableSystemMove(bool enableSystemMove) override; + + bool enableBlurWindow() const override; + void setEnableBlurWindow(bool enableBlurWindow) override; + +protected: + bool eventFilter(QObject *watched, QEvent *event) override; + +private: + void updateShadow(); + void updateRoundedCorners(); + void updateSystemTheme(); + void *hwnd() const; + + int m_windowRadius = -1; + int m_borderWidth = 1; + QColor m_borderColor; + int m_shadowRadius = -1; + QPoint m_shadowOffset; + QColor m_shadowColor; + bool m_translucentBackground = false; + bool m_enableSystemResize = true; + bool m_enableSystemMove = true; + bool m_enabled = false; + bool m_windowVisible = false; + bool m_systemDarkMode = false; +}; + +DGUI_END_NAMESPACE +#endif // DWIN32PLATFORMWINDOWINTERFACE_H diff --git a/src/plugins/platform/win32/win32.cmake b/src/plugins/platform/win32/win32.cmake new file mode 100644 index 00000000..b115afb4 --- /dev/null +++ b/src/plugins/platform/win32/win32.cmake @@ -0,0 +1,10 @@ +file(GLOB WIN32_HEADER + ${CMAKE_CURRENT_LIST_DIR}/*.h +) +file(GLOB WIN32_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/*.cpp +) +set(win32_SRC + ${WIN32_HEADER} + ${WIN32_SOURCE} +) diff --git a/src/plugins/platform/xcb/dxcbplatformwindowinterface.cpp b/src/plugins/platform/xcb/dxcbplatformwindowinterface.cpp index a31f0c05..08e0c198 100644 --- a/src/plugins/platform/xcb/dxcbplatformwindowinterface.cpp +++ b/src/plugins/platform/xcb/dxcbplatformwindowinterface.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -7,7 +7,9 @@ #include "dplatformtheme.h" #include "dwindowmanagerhelper.h" +#ifndef Q_OS_WIN #include +#endif #include #include diff --git a/src/plugins/plugins.cmake b/src/plugins/plugins.cmake index 7289cc71..bfaa5b47 100644 --- a/src/plugins/plugins.cmake +++ b/src/plugins/plugins.cmake @@ -31,14 +31,27 @@ else() target_compile_definitions(${LIB_NAME} PRIVATE DTK_DISABLE_XCB) endif() -# Treeland +# Win32 +if(WIN32) + message("Support Win32!") + include(plugins/platform/win32/win32.cmake) + target_sources(${LIB_NAME} PRIVATE + ${win32_SRC} + ) + target_link_libraries(${LIB_NAME} PRIVATE dwmapi) +endif() -try_compile(DEEPIN_WAYLAND_TEST_COMPILE_RESULT ${CMAKE_CURRENT_BINARY_DIR}/treeland_test - ${CMAKE_CURRENT_LIST_DIR}/platform/config.tests/treeland_test treeland_test CMAKE_FLAGS -DQT_VERSION_MAJOR=${QT_VERSION_MAJOR}) +# Treeland +if(LINUX) + try_compile(DEEPIN_WAYLAND_TEST_COMPILE_RESULT ${CMAKE_CURRENT_BINARY_DIR}/treeland_test + ${CMAKE_CURRENT_LIST_DIR}/platform/config.tests/treeland_test treeland_test CMAKE_FLAGS -DQT_VERSION_MAJOR=${QT_VERSION_MAJOR}) -if(NOT DEEPIN_WAYLAND_TEST_COMPILE_RESULT) - message("wayland_test failed, disable treeland support") - set(DTK_DISABLE_TREELAND ON) + if(NOT DEEPIN_WAYLAND_TEST_COMPILE_RESULT) + message("wayland_test failed, disable treeland support") + set(DTK_DISABLE_TREELAND ON) + endif() +else() + set(DTK_DISABLE_TREELAND ON) endif() if(NOT DTK_DISABLE_TREELAND) diff --git a/src/private/dplatforminterface_p.h b/src/private/dplatforminterface_p.h index 5236c3ee..783e7599 100644 --- a/src/private/dplatforminterface_p.h +++ b/src/private/dplatforminterface_p.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -14,7 +14,7 @@ DGUI_BEGIN_NAMESPACE class DPlatformTheme; -class LIBDTKCORESHARED_EXPORT DPlatformInterface +class LIBDTKGUISHARED_EXPORT DPlatformInterface { public: explicit DPlatformInterface(DPlatformTheme *platformTheme); @@ -126,7 +126,7 @@ class LIBDTKCORESHARED_EXPORT DPlatformInterface DPlatformTheme *m_platformTheme; }; -class LIBDTKCORESHARED_EXPORT DPlatformInterfaceFactory { +class LIBDTKGUISHARED_EXPORT DPlatformInterfaceFactory { public: using HelperCreator = DPlatformInterface * (*)(DPlatformTheme*); static void registerInterface(HelperCreator creator); diff --git a/src/private/dplatformwindowinterface_p.h b/src/private/dplatformwindowinterface_p.h index b9e4f629..b5c7fc79 100644 --- a/src/private/dplatformwindowinterface_p.h +++ b/src/private/dplatformwindowinterface_p.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -12,7 +12,7 @@ DGUI_BEGIN_NAMESPACE -class LIBDTKCORESHARED_EXPORT DPlatformWindowInterface +class LIBDTKGUISHARED_EXPORT DPlatformWindowInterface { public: explicit DPlatformWindowInterface(QWindow *window, DPlatformHandle *platformHandle); @@ -76,7 +76,7 @@ class LIBDTKCORESHARED_EXPORT DPlatformWindowInterface QPointer m_platformHandle; }; -class LIBDTKCORESHARED_EXPORT DPlatformWindowInterfaceFactory { +class LIBDTKGUISHARED_EXPORT DPlatformWindowInterfaceFactory { public: using Creator = DPlatformWindowInterface * (*)(QWindow *, DPlatformHandle*); static void registerInterface(Creator creator); diff --git a/src/util/dsvgrenderer.cpp b/src/util/dsvgrenderer.cpp index f1d3db86..0f45e0cd 100644 --- a/src/util/dsvgrenderer.cpp +++ b/src/util/dsvgrenderer.cpp @@ -1,7 +1,10 @@ -// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later +#include +#ifdef Q_OS_LINUX + #ifndef DTK_DISABLE_LIBRSVG #include #else @@ -435,3 +438,5 @@ void DSvgRenderer::render(QPainter *p, const QString &elementId, const QRectF &b } DGUI_END_NAMESPACE + +#endif // Q_OS_LINUX diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 8ded869d..28313e7f 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,6 +1,8 @@ add_subdirectory(deepin-gui-settings) add_subdirectory(dci-image-converter) add_subdirectory(dci-icon-theme) -add_subdirectory(dde-kwin-debug) +if(LINUX) + add_subdirectory(dde-kwin-debug) +endif() add_subdirectory(image-handler) add_subdirectory(dci-iconfinder) From 6740c822e6b4f65e6467809fbf9169c316d723e2 Mon Sep 17 00:00:00 2001 From: Cloud Date: Tue, 21 Jul 2026 21:02:57 +0800 Subject: [PATCH 2/2] refactor: use Q_OS_WIN instead of D_DISABLE_DCONFIG for DConfig conditional compilation Replace the CMake-defined D_DISABLE_DCONFIG macro with direct #ifndef Q_OS_WIN preprocessor checks in dguiapplicationhelper.cpp. Remove the DTK_DCONFIG_PTR macro and _d_dconfig_instance variable, using _d_dconfig directly with platform guards. --- dtkgui.cmake | 4 -- src/kernel/dguiapplicationhelper.cpp | 78 +++++++++------------------- 2 files changed, 25 insertions(+), 57 deletions(-) diff --git a/dtkgui.cmake b/dtkgui.cmake index 288e6e01..50d374b2 100644 --- a/dtkgui.cmake +++ b/dtkgui.cmake @@ -23,10 +23,6 @@ option(DTK_DISABLE_EX_IMAGE_FORMAT "Disable libraw and freeimage" OFF) set(CMAKE_CXX_STANDARD 17) -if(NOT LINUX) - add_definitions(-DD_DISABLE_DCONFIG) -endif() - if("${QT_VERSION_MAJOR}" STREQUAL "5") set (BUILD_DOCS ON CACHE BOOL "Generate doxygen-based documentation") else() diff --git a/src/kernel/dguiapplicationhelper.cpp b/src/kernel/dguiapplicationhelper.cpp index 5b8465a9..e3fa195f 100644 --- a/src/kernel/dguiapplicationhelper.cpp +++ b/src/kernel/dguiapplicationhelper.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include @@ -27,8 +26,8 @@ #include #include #include +#include #include -#include #ifdef Q_OS_WIN #include @@ -116,13 +115,9 @@ Q_GLOBAL_STATIC(DFontManager, _globalFM) #define DTK_ANIMATIONS_ENV "D_DTK_DISABLE_ANIMATIONS" #define DTK_DISABLE_INWINDOWBLUR_ENV "D_DTK_DISABLE_INWINDOWBLUR" -#ifndef D_DISABLE_DCONFIG +#ifndef Q_OS_WIN Q_GLOBAL_STATIC_WITH_ARGS(OrgDeepinDTKPreference, _d_dconfig, (DTK_CORE_NAMESPACE::DConfig::globalThread(), nullptr, "org.deepin.dtk.preference", DTK_CORE_NAMESPACE::DSGApplication::id(), {}, false, nullptr)) -#define DTK_DCONFIG_PTR _d_dconfig -#else -static OrgDeepinDTKPreference* _d_dconfig_instance = nullptr; -#define DTK_DCONFIG_PTR _d_dconfig_instance #endif // Keys allowed to be forwarded between single-instance client and server. @@ -477,54 +472,29 @@ void DGuiApplicationHelperPrivate::initPaletteType() const const_cast(this)->paletteTypeInited = true; auto applyThemeType = [this](bool emitSignal){ +#ifndef Q_OS_WIN + int ct = _d_dconfig->themeType(); + if (ct > DGuiApplicationHelper::DarkType || ct < DGuiApplicationHelper::UnknownType) + ct = DGuiApplicationHelper::UnknownType; +#else int ct = DGuiApplicationHelper::UnknownType; - if (DTK_DCONFIG_PTR) { - ct = DTK_DCONFIG_PTR->themeType(); - if (ct > DGuiApplicationHelper::DarkType || ct < DGuiApplicationHelper::UnknownType) - ct = DGuiApplicationHelper::UnknownType; - } +#endif const_cast(this)->setPaletteType(DGuiApplicationHelper::ColorType(ct), emitSignal); }; // 读取配置文件中的主题类型并立即应用 -#ifndef D_DISABLE_DCONFIG +#ifndef Q_OS_WIN DTK_CORE_NAMESPACE::DConfig dconfig("org.deepin.dtk.preference"); int ct = dconfig.value("themeType", DGuiApplicationHelper::UnknownType).toInt(); const_cast(this)->setPaletteType(DGuiApplicationHelper::ColorType(ct), false); -#else -#ifdef Q_OS_WIN - // Windows: read from QSettings, fallback to system theme detection - int ct = DGuiApplicationHelper::UnknownType; - QSettings winSettings("deepin", "deepin-music"); - if (winSettings.contains("themeType")) { - ct = winSettings.value("themeType", DGuiApplicationHelper::UnknownType).toInt(); - } else { - // Detect system dark/light mode from Windows registry - HKEY hKey; - DWORD value = 1; // default: light - DWORD size = sizeof(value); - if (RegOpenKeyExW(HKEY_CURRENT_USER, - L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", - 0, KEY_READ, &hKey) == ERROR_SUCCESS) { - if (RegQueryValueExW(hKey, L"AppsUseLightTheme", nullptr, nullptr, - reinterpret_cast(&value), &size) == ERROR_SUCCESS) { - ct = value ? DGuiApplicationHelper::LightType : DGuiApplicationHelper::DarkType; - } - RegCloseKey(hKey); - } - } - const_cast(this)->setPaletteType(DGuiApplicationHelper::ColorType(ct), false); + + QObject::connect(_d_dconfig.operator ()(), &OrgDeepinDTKPreference::themeTypeChanged, q_func(), [applyThemeType] { + applyThemeType(true); + }); #else int ct = DGuiApplicationHelper::UnknownType; const_cast(this)->setPaletteType(DGuiApplicationHelper::ColorType(ct), false); #endif -#endif - - if (DTK_DCONFIG_PTR) { - QObject::connect(DTK_DCONFIG_PTR, &OrgDeepinDTKPreference::themeTypeChanged, q_func(), [applyThemeType] { - applyThemeType(true); - }); - } } void DGuiApplicationHelperPrivate::_q_sizeModeChanged(int mode) @@ -1918,14 +1888,22 @@ bool DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::Attribute attri if (isDisable) return false; - return DTK_DCONFIG_PTR ? DTK_DCONFIG_PTR->enableDtkAnimations() : false; +#ifndef Q_OS_WIN + return _d_dconfig->enableDtkAnimations(); +#else + return false; +#endif } case HasInWindowBlur: { static bool isDisable = qEnvironmentVariableIsSet(DTK_DISABLE_INWINDOWBLUR_ENV); if (isDisable) return false; - return DTK_DCONFIG_PTR ? !DTK_DCONFIG_PTR->disableInWindowBlur() : false; +#ifndef Q_OS_WIN + return !_d_dconfig->disableInWindowBlur(); +#else + return false; +#endif } default: return DGuiApplicationHelperPrivate::attributes.testFlag(attribute); @@ -1967,14 +1945,8 @@ void DGuiApplicationHelper::setPaletteType(DGuiApplicationHelper::ColorType pale d->initPaletteType(); d->setPaletteType(paletteType, true); if (!DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::DontSaveApplicationTheme)) { - if (DTK_DCONFIG_PTR) { - DTK_DCONFIG_PTR->setThemeType(static_cast(paletteType)); - } -#ifdef Q_OS_WIN - else { - QSettings winSettings("deepin", "deepin-music"); - winSettings.setValue("themeType", static_cast(paletteType)); - } +#ifndef Q_OS_WIN + _d_dconfig->setThemeType(static_cast(paletteType)); #endif } }