From 14d3920f6a7b199e751cd1bad57499d8e3a96473 Mon Sep 17 00:00:00 2001 From: floppyhammer Date: Wed, 22 Feb 2023 14:31:48 +0800 Subject: [PATCH] Add a function to get the system accent color --- src/win32_window.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 819dbc90..fcc822c3 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -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; }