From 2c2e37f6feec6f5fcb48ee3726dbf160d1bd652d Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:24:08 +0000 Subject: [PATCH] Implemented immersive dark title bar --- UnleashedRecomp/ui/window.cpp | 4 ++++ UnleashedRecomp/ui/window.h | 25 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/UnleashedRecomp/ui/window.cpp b/UnleashedRecomp/ui/window.cpp index 304b93e..fa7abd1 100644 --- a/UnleashedRecomp/ui/window.cpp +++ b/UnleashedRecomp/ui/window.cpp @@ -162,6 +162,10 @@ void Window::Init() SDL_GetWindowWMInfo(s_pWindow, &info); s_handle = info.info.win.window; + + SetDarkTitleBar(true); + + SDL_ShowWindow(s_pWindow); } void Window::Update() diff --git a/UnleashedRecomp/ui/window.h b/UnleashedRecomp/ui/window.h index b560981..1d6764e 100644 --- a/UnleashedRecomp/ui/window.h +++ b/UnleashedRecomp/ui/window.h @@ -5,6 +5,12 @@ #include #include +#if _WIN32 +#include +#include +#pragma comment(lib, "dwmapi.lib") +#endif + #define DEFAULT_WIDTH 1280 #define DEFAULT_HEIGHT 720 @@ -70,6 +76,23 @@ public: SDL_SetWindowTitle(s_pWindow, title); } + static void SetDarkTitleBar(bool isEnabled) + { +#if _WIN32 + auto version = GetPlatformVersion(); + + if (version.Major < 10 || version.Build <= 17763) + return; + + auto flag = version.Build >= 18985 + ? DWMWA_USE_IMMERSIVE_DARK_MODE + : 19; // DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 + + const DWORD useImmersiveDarkMode = isEnabled; + DwmSetWindowAttribute(s_handle, flag, &useImmersiveDarkMode, sizeof(useImmersiveDarkMode)); +#endif + } + static bool IsFullscreen() { return SDL_GetWindowFlags(s_pWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP; @@ -139,7 +162,7 @@ public: static uint32_t GetWindowFlags() { - uint32_t flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE; + uint32_t flags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE; if (Config::WindowState == EWindowState::Maximised) flags |= SDL_WINDOW_MAXIMIZED;