mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-10-30 07:11:05 +00:00
Respect system colour scheme for title bar colour (#109)
This commit is contained in:
parent
7c60e47eee
commit
f8e6b74551
9 changed files with 68 additions and 13 deletions
4
UnleashedRecomp/.gitignore
vendored
4
UnleashedRecomp/.gitignore
vendored
|
|
@ -1,2 +1,2 @@
|
|||
version.h
|
||||
version.cpp
|
||||
/version.h
|
||||
/version.cpp
|
||||
|
|
@ -91,6 +91,7 @@ set(SWA_OS_CXX_SOURCES
|
|||
"os/logger.cpp"
|
||||
"os/media.cpp"
|
||||
"os/process.cpp"
|
||||
"os/user.cpp"
|
||||
"os/version.cpp"
|
||||
)
|
||||
|
||||
|
|
@ -99,6 +100,7 @@ if (WIN32)
|
|||
"os/win32/logger_win32.cpp"
|
||||
"os/win32/media_win32.cpp"
|
||||
"os/win32/process_win32.cpp"
|
||||
"os/win32/user_win32.cpp"
|
||||
"os/win32/version_win32.cpp"
|
||||
)
|
||||
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
|
|
@ -106,6 +108,7 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
|||
"os/linux/logger_linux.cpp"
|
||||
"os/linux/media_linux.cpp"
|
||||
"os/linux/process_linux.cpp"
|
||||
"os/linux/user_linux.cpp"
|
||||
"os/linux/version_linux.cpp"
|
||||
)
|
||||
endif()
|
||||
|
|
|
|||
6
UnleashedRecomp/os/linux/user_linux.cpp
Normal file
6
UnleashedRecomp/os/linux/user_linux.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <os/user_detail.h>
|
||||
|
||||
bool os::user::detail::IsDarkTheme()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
7
UnleashedRecomp/os/user.cpp
Normal file
7
UnleashedRecomp/os/user.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include <os/user.h>
|
||||
#include <os/user_detail.h>
|
||||
|
||||
bool os::user::IsDarkTheme()
|
||||
{
|
||||
return detail::IsDarkTheme();
|
||||
}
|
||||
6
UnleashedRecomp/os/user.h
Normal file
6
UnleashedRecomp/os/user.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
namespace os::user
|
||||
{
|
||||
bool IsDarkTheme();
|
||||
}
|
||||
6
UnleashedRecomp/os/user_detail.h
Normal file
6
UnleashedRecomp/os/user_detail.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
namespace os::user::detail
|
||||
{
|
||||
bool IsDarkTheme();
|
||||
}
|
||||
23
UnleashedRecomp/os/win32/user_win32.cpp
Normal file
23
UnleashedRecomp/os/win32/user_win32.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include <os/user_detail.h>
|
||||
|
||||
bool os::user::detail::IsDarkTheme()
|
||||
{
|
||||
HKEY hKey;
|
||||
|
||||
if (RegOpenKeyExA(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
|
||||
{
|
||||
DWORD value = 0;
|
||||
DWORD valueSize = sizeof(value);
|
||||
|
||||
if (RegQueryValueExA(hKey, "AppsUseLightTheme", nullptr, nullptr, (LPBYTE)&value, &valueSize) == ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
|
||||
return value == 0;
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#include "game_window.h"
|
||||
#include <gpu/video.h>
|
||||
#include <os/logger.h>
|
||||
#include <os/user.h>
|
||||
#include <os/version.h>
|
||||
#include <ui/sdl_listener.h>
|
||||
#include <app.h>
|
||||
|
|
@ -238,7 +239,7 @@ void GameWindow::Init(const char* sdlVideoDriver)
|
|||
static_assert(false, "Unknown platform.");
|
||||
#endif
|
||||
|
||||
SetDarkTitleBar(true);
|
||||
SetTitleBarColour();
|
||||
|
||||
SDL_ShowWindow(s_pWindow);
|
||||
}
|
||||
|
|
@ -307,20 +308,23 @@ void GameWindow::SetTitle(const char* title)
|
|||
SDL_SetWindowTitle(s_pWindow, title ? title : GetTitle());
|
||||
}
|
||||
|
||||
void GameWindow::SetDarkTitleBar(bool isEnabled)
|
||||
void GameWindow::SetTitleBarColour()
|
||||
{
|
||||
#if _WIN32
|
||||
auto version = os::version::GetOSVersion();
|
||||
if (os::user::IsDarkTheme())
|
||||
{
|
||||
auto version = os::version::GetOSVersion();
|
||||
|
||||
if (version.Major < 10 || version.Build <= 17763)
|
||||
return;
|
||||
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
|
||||
auto flag = version.Build >= 18985
|
||||
? DWMWA_USE_IMMERSIVE_DARK_MODE
|
||||
: 19; // DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1
|
||||
|
||||
const DWORD useImmersiveDarkMode = isEnabled;
|
||||
DwmSetWindowAttribute(s_renderWindow, flag, &useImmersiveDarkMode, sizeof(useImmersiveDarkMode));
|
||||
const DWORD useImmersiveDarkMode = 1;
|
||||
DwmSetWindowAttribute(s_renderWindow, flag, &useImmersiveDarkMode, sizeof(useImmersiveDarkMode));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public:
|
|||
static void SetIcon(bool isNight = false);
|
||||
static const char* GetTitle();
|
||||
static void SetTitle(const char* title = nullptr);
|
||||
static void SetDarkTitleBar(bool isEnabled);
|
||||
static void SetTitleBarColour();
|
||||
static bool IsFullscreen();
|
||||
static bool SetFullscreen(bool isEnabled);
|
||||
static void SetFullscreenCursorVisibility(bool isVisible);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue