diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2023-01-10 08:48:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-10 08:48:17 +0100 |
commit | 61144f7a219995fa29531683ed36e8e4002848b5 (patch) | |
tree | 0b56a4949c9fb64d38b805afac59a5bfecab2c2b | |
parent | ca9b2525c8e45c6dfe2911e895dcb25e0c9e5933 (diff) | |
parent | 78bbcac0eaf1bb9df1ac87dafffbef659116fd80 (diff) | |
download | PrismLauncher-61144f7a219995fa29531683ed36e8e4002848b5.tar.gz PrismLauncher-61144f7a219995fa29531683ed36e8e4002848b5.tar.bz2 PrismLauncher-61144f7a219995fa29531683ed36e8e4002848b5.zip |
Merge pull request #726 from TheLastRar/qt6-win-darkmode
Closes https://github.com/PrismLauncher/PrismLauncher/issues/158
-rw-r--r-- | launcher/Application.cpp | 16 | ||||
-rw-r--r-- | launcher/CMakeLists.txt | 10 | ||||
-rw-r--r-- | launcher/ui/WinDarkmode.cpp | 32 | ||||
-rw-r--r-- | launcher/ui/WinDarkmode.h | 60 | ||||
-rw-r--r-- | launcher/ui/themes/ThemeManager.cpp | 17 |
5 files changed, 1 insertions, 134 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp index ff34a168..9d528d7a 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -62,11 +62,6 @@ #include "ui/pages/global/APIPage.h" #include "ui/pages/global/CustomCommandsPage.h" -#ifdef Q_OS_WIN -#include "ui/WinDarkmode.h" -#include <versionhelpers.h> -#endif - #include "ui/setupwizard/SetupWizard.h" #include "ui/setupwizard/LanguageWizardPage.h" #include "ui/setupwizard/JavaWizardPage.h" @@ -1353,16 +1348,7 @@ MainWindow* Application::showMainWindow(bool minimized) m_mainWindow = new MainWindow(); m_mainWindow->restoreState(QByteArray::fromBase64(APPLICATION->settings()->get("MainWindowState").toByteArray())); m_mainWindow->restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get("MainWindowGeometry").toByteArray())); -#ifdef Q_OS_WIN - if (IsWindows10OrGreater()) - { - if (QString::compare(settings()->get("ApplicationTheme").toString(), "dark") == 0) { - WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), true); - } else { - WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), false); - } - } -#endif + if(minimized) { m_mainWindow->showMinimized(); diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 8b5c63ff..57480671 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -937,16 +937,6 @@ SET(LAUNCHER_SOURCES ui/instanceview/VisualGroup.h ) -if(WIN32) - set(LAUNCHER_SOURCES - ${LAUNCHER_SOURCES} - - # GUI - dark titlebar for Windows 10/11 - ui/WinDarkmode.h - ui/WinDarkmode.cpp - ) -endif() - qt_wrap_ui(LAUNCHER_UI ui/setupwizard/PasteWizardPage.ui ui/pages/global/AccountListPage.ui diff --git a/launcher/ui/WinDarkmode.cpp b/launcher/ui/WinDarkmode.cpp deleted file mode 100644 index eac68e4f..00000000 --- a/launcher/ui/WinDarkmode.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include <QWidget> - -#include "WinDarkmode.h" - -namespace WinDarkmode { - -/* See https://github.com/statiolake/neovim-qt/commit/da8eaba7f0e38b6b51f3bacd02a8cc2d1f7a34d8 */ -void setDarkWinTitlebar(WId winid, bool darkmode) -{ - HWND hwnd = reinterpret_cast<HWND>(winid); - BOOL dark = (BOOL) darkmode; - - HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); - HMODULE hUser32 = GetModuleHandleW(L"user32.dll"); - fnAllowDarkModeForWindow AllowDarkModeForWindow - = reinterpret_cast<fnAllowDarkModeForWindow>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(133))); - fnSetPreferredAppMode SetPreferredAppMode - = reinterpret_cast<fnSetPreferredAppMode>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135))); - fnSetWindowCompositionAttribute SetWindowCompositionAttribute - = reinterpret_cast<fnSetWindowCompositionAttribute>(GetProcAddress(hUser32, "SetWindowCompositionAttribute")); - - SetPreferredAppMode(AllowDark); - AllowDarkModeForWindow(hwnd, dark); - WINDOWCOMPOSITIONATTRIBDATA data = { - WCA_USEDARKMODECOLORS, - &dark, - sizeof(dark) - }; - SetWindowCompositionAttribute(hwnd, &data); -} - -} diff --git a/launcher/ui/WinDarkmode.h b/launcher/ui/WinDarkmode.h deleted file mode 100644 index 5b567c6b..00000000 --- a/launcher/ui/WinDarkmode.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once - -#include <windows.h> -#include <dwmapi.h> - - -namespace WinDarkmode { - -void setDarkWinTitlebar(WId winid, bool darkmode); - -enum PreferredAppMode { - Default, - AllowDark, - ForceDark, - ForceLight, - Max -}; - -enum WINDOWCOMPOSITIONATTRIB { - WCA_UNDEFINED = 0, - WCA_NCRENDERING_ENABLED = 1, - WCA_NCRENDERING_POLICY = 2, - WCA_TRANSITIONS_FORCEDISABLED = 3, - WCA_ALLOW_NCPAINT = 4, - WCA_CAPTION_BUTTON_BOUNDS = 5, - WCA_NONCLIENT_RTL_LAYOUT = 6, - WCA_FORCE_ICONIC_REPRESENTATION = 7, - WCA_EXTENDED_FRAME_BOUNDS = 8, - WCA_HAS_ICONIC_BITMAP = 9, - WCA_THEME_ATTRIBUTES = 10, - WCA_NCRENDERING_EXILED = 11, - WCA_NCADORNMENTINFO = 12, - WCA_EXCLUDED_FROM_LIVEPREVIEW = 13, - WCA_VIDEO_OVERLAY_ACTIVE = 14, - WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15, - WCA_DISALLOW_PEEK = 16, - WCA_CLOAK = 17, - WCA_CLOAKED = 18, - WCA_ACCENT_POLICY = 19, - WCA_FREEZE_REPRESENTATION = 20, - WCA_EVER_UNCLOAKED = 21, - WCA_VISUAL_OWNER = 22, - WCA_HOLOGRAPHIC = 23, - WCA_EXCLUDED_FROM_DDA = 24, - WCA_PASSIVEUPDATEMODE = 25, - WCA_USEDARKMODECOLORS = 26, - WCA_LAST = 27 -}; - -struct WINDOWCOMPOSITIONATTRIBDATA { - WINDOWCOMPOSITIONATTRIB Attrib; - PVOID pvData; - SIZE_T cbData; -}; - -using fnAllowDarkModeForWindow = BOOL (WINAPI *)(HWND hWnd, BOOL allow); -using fnSetPreferredAppMode = PreferredAppMode (WINAPI *)(PreferredAppMode appMode); -using fnSetWindowCompositionAttribute = BOOL (WINAPI *)(HWND hwnd, WINDOWCOMPOSITIONATTRIBDATA *); - -} diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index 01a38a86..5a612472 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -28,14 +28,6 @@ #include "Application.h"
-#ifdef Q_OS_WIN
-#include <windows.h>
-// this is needed for versionhelpers.h, it is also included in WinDarkmode, but we can't rely on that.
-// Ultimately this should be included in versionhelpers, but that is outside of the project.
-#include "ui/WinDarkmode.h"
-#include <versionhelpers.h>
-#endif
-
ThemeManager::ThemeManager(MainWindow* mainWindow)
{
m_mainWindow = mainWindow;
@@ -140,15 +132,6 @@ void ThemeManager::setApplicationTheme(const QString& name, bool initial) auto& theme = themeIter->second;
themeDebugLog() << "applying theme" << theme->name();
theme->apply(initial);
-#ifdef Q_OS_WIN
- if (m_mainWindow && IsWindows10OrGreater()) {
- if (QString::compare(theme->id(), "dark") == 0) {
- WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), true);
- } else {
- WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), false);
- }
- }
-#endif
} else {
themeWarningLog() << "Tried to set invalid theme:" << name;
}
|