Add a function to get the system accent color

This commit is contained in:
floppyhammer 2023-02-22 14:31:48 +08:00
parent c6b0894c57
commit 14d3920f6a

View File

@ -42,8 +42,12 @@
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
#endif
static void applySystemTheme(HWND handle) {
if (_glfw.win32.uxtheme.uxThemeAvailable && _glfw.win32.uxtheme.darkTitleAvailable) {
// Apply the system default theme
//
static void applySystemTheme(HWND handle)
{
if (_glfw.win32.uxtheme.uxThemeAvailable && _glfw.win32.uxtheme.darkTitleAvailable)
{
GLFWbool value = _glfw.win32.uxtheme.ShouldAppsUseDarkMode() & 0x1;
DwmSetWindowAttribute(handle,
DWMWA_USE_IMMERSIVE_DARK_MODE,
@ -52,6 +56,27 @@ static void applySystemTheme(HWND handle) {
}
}
static void getAccentColor(float color[4])
{
if (!_glfw.win32.uxtheme.uxThemeAvailable)
{
return;
}
UINT dwImmersiveColorType = _glfw.win32.uxtheme.GetImmersiveColorTypeFromName(L"ImmersiveSystemAccent");
UINT dwImmersiveColorSet = _glfw.win32.uxtheme.GetImmersiveUserColorSetPreference(FALSE, FALSE);
UINT rgba = _glfw.win32.uxtheme.GetImmersiveColorFromColorSetEx(dwImmersiveColorSet,
dwImmersiveColorType,
FALSE,
0);
color[0] = (0xFF & rgba);
color[1] = ((0xFF00 & rgba) >> 8) ;
color[2] = ((0xFF0000 & rgba) >> 16);
color[3] = ((0xFF000000 & rgba) >> 24);
}
// Returns the window style for the specified window
//
static DWORD getWindowStyle(const _GLFWwindow* window)
@ -1458,9 +1483,8 @@ static int createNativeWindow(_GLFWwindow* window,
_glfwGetWindowSizeWin32(window, &window->win32.width, &window->win32.height);
if (window->theme.variation == GLFW_THEME_DEFAULT) {
applySystemTheme(window->win32.handle);
}
// Use the system default when creating a window
applySystemTheme(window->win32.handle);
return GLFW_TRUE;
}
@ -2422,10 +2446,14 @@ _GLFWtheme* _glfwGetThemeWin32(_GLFWwindow* window)
theme->variation = GLFW_THEME_LIGHT;
theme->flags = 0;
if (_glfw.win32.uxtheme.uxThemeAvailable && _glfw.win32.uxtheme.darkTitleAvailable) {
if (_glfw.win32.uxtheme.uxThemeAvailable && _glfw.win32.uxtheme.darkTitleAvailable)
{
theme->variation = GLFW_THEME_DARK;
}
memset(theme->color, 0, sizeof(float) * 4);
getAccentColor(theme->color);
return theme;
}