From e8d23af0f2799337af0b0c69a34aa717bf88766e Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Mon, 31 Jul 2023 00:40:15 +0200 Subject: [PATCH] DolphinQt: Add function to set a QWidget's window decorations to dark ones on Windows. --- Source/Core/DolphinQt/CMakeLists.txt | 3 +++ Source/Core/DolphinQt/DolphinQt.vcxproj | 2 ++ .../QtUtils/SetWindowDecorations.cpp | 25 +++++++++++++++++++ .../DolphinQt/QtUtils/SetWindowDecorations.h | 9 +++++++ Source/VSProps/Base.Dolphin.props | 2 ++ 5 files changed, 41 insertions(+) create mode 100644 Source/Core/DolphinQt/QtUtils/SetWindowDecorations.cpp create mode 100644 Source/Core/DolphinQt/QtUtils/SetWindowDecorations.h diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt index 50dbbbf57a..2633b3d264 100644 --- a/Source/Core/DolphinQt/CMakeLists.txt +++ b/Source/Core/DolphinQt/CMakeLists.txt @@ -294,6 +294,8 @@ add_executable(dolphin-emu QtUtils/ParallelProgressDialog.h QtUtils/PartiallyClosableTabWidget.cpp QtUtils/PartiallyClosableTabWidget.h + QtUtils/SetWindowDecorations.cpp + QtUtils/SetWindowDecorations.h QtUtils/SignalBlocking.h QtUtils/UTF8CodePointCountValidator.cpp QtUtils/UTF8CodePointCountValidator.h @@ -403,6 +405,7 @@ if (WIN32) PRIVATE gdi32.lib shell32.lib + dwmapi.lib # Needed to set window decorations for dark theme ) endif() diff --git a/Source/Core/DolphinQt/DolphinQt.vcxproj b/Source/Core/DolphinQt/DolphinQt.vcxproj index 5eaf14fa9f..9217cc3788 100644 --- a/Source/Core/DolphinQt/DolphinQt.vcxproj +++ b/Source/Core/DolphinQt/DolphinQt.vcxproj @@ -188,6 +188,7 @@ + @@ -379,6 +380,7 @@ + diff --git a/Source/Core/DolphinQt/QtUtils/SetWindowDecorations.cpp b/Source/Core/DolphinQt/QtUtils/SetWindowDecorations.cpp new file mode 100644 index 0000000000..704e5a8f7f --- /dev/null +++ b/Source/Core/DolphinQt/QtUtils/SetWindowDecorations.cpp @@ -0,0 +1,25 @@ +// Copyright 2023 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "DolphinQt/QtUtils/SetWindowDecorations.h" + +#include + +#include "DolphinQt/Settings.h" + +#ifdef _WIN32 +#include +#endif + +void SetQWidgetWindowDecorations(QWidget* widget) +{ +#ifdef _WIN32 + if (!Settings::Instance().IsSystemDark()) + return; + + BOOL use_dark_title_bar = TRUE; + DwmSetWindowAttribute(HWND(widget->winId()), + 20 /* DWMWINDOWATTRIBUTE::DWMWA_USE_IMMERSIVE_DARK_MODE */, + &use_dark_title_bar, DWORD(sizeof(use_dark_title_bar))); +#endif +} diff --git a/Source/Core/DolphinQt/QtUtils/SetWindowDecorations.h b/Source/Core/DolphinQt/QtUtils/SetWindowDecorations.h new file mode 100644 index 0000000000..aa4b3d8687 --- /dev/null +++ b/Source/Core/DolphinQt/QtUtils/SetWindowDecorations.h @@ -0,0 +1,9 @@ +// Copyright 2023 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +class QWidget; + +// Changes the window decorations (title bar) to dark if the user uses dark mode on Windows. +void SetQWidgetWindowDecorations(QWidget* widget); diff --git a/Source/VSProps/Base.Dolphin.props b/Source/VSProps/Base.Dolphin.props index a575d9290b..96fe8b6d2a 100644 --- a/Source/VSProps/Base.Dolphin.props +++ b/Source/VSProps/Base.Dolphin.props @@ -79,6 +79,8 @@ avcodec.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;bcrypt.lib;%(AdditionalDependencies) Crypt32.lib;%(AdditionalDependencies) + + dwmapi.lib;%(AdditionalDependencies) enableCompatPatches