Fix win32 theming implementation

This commit is contained in:
ws909 2023-02-24 00:19:12 +01:00
parent decb018a31
commit ac979c6d7f

View File

@ -70,10 +70,10 @@ static int getAccentColor(float color[4])
FALSE, FALSE,
0); 0);
color[0] = (double) (0xFF & rgba); color[0] = (float) (0xFF & rgba);
color[1] = (double) ((0xFF00 & rgba) >> 8); color[1] = (float) ((0xFF00 & rgba) >> 8);
color[2] = (double) ((0xFF0000 & rgba) >> 16); color[2] = (float) ((0xFF0000 & rgba) >> 16);
color[3] = (double) ((0xFF000000 & rgba) >> 24); color[3] = (float) ((0xFF000000 & rgba) >> 24);
return GLFW_TRUE; return GLFW_TRUE;
} }
@ -1189,7 +1189,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
case WM_THEMECHANGED: case WM_THEMECHANGED:
case WM_SETTINGCHANGE: { case WM_SETTINGCHANGE: {
if (window->theme.variation == GLFW_THEME_DEFAULT) { if (window->theme.internal.variation == GLFW_THEME_DEFAULT) {
applySystemTheme(window->win32.handle); applySystemTheme(window->win32.handle);
} }
} break; } break;
@ -2426,20 +2426,37 @@ const char* _glfwGetClipboardStringWin32(void)
void _glfwSetThemeWin32(_GLFWwindow* window, const _GLFWtheme* theme) void _glfwSetThemeWin32(_GLFWwindow* window, const _GLFWtheme* theme)
{ {
if (!theme || theme->variation == GLFW_THEME_DEFAULT) _GLFWtheme* currentTheme = &window->theme.internal;
_GLFWtheme newTheme;
if (!theme)
_glfwInitDefaultTheme(&newTheme);
else
memcpy(&newTheme, theme, sizeof(_GLFWtheme));
if (newTheme->variation == GLFW_THEME_DEFAULT)
{ {
applySystemTheme(window->win32.handle); applySystemTheme(window->win32.handle);
return;
} }
else
GLFWbool darkMode = theme->variation == GLFW_THEME_DARK; {
GLFWbool darkMode = theme->variation == GLFW_THEME_DARK;
DwmSetWindowAttribute(window->win32.handle,
DWMWA_USE_IMMERSIVE_DARK_MODE, DwmSetWindowAttribute(window->win32.handle,
&darkMode, DWMWA_USE_IMMERSIVE_DARK_MODE,
sizeof(darkMode)); &darkMode,
sizeof(darkMode));
}
// TODO: set accent color // TODO: set accent color
memcpy(currentTheme, &newTheme, sizeof(_GLFWtheme));
// Not available for setting in Win32.
currentTheme->flags &= ~(GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST |
GLFW_THEME_ATTRIBUTE_REDUCE_TRANSPARENCY |
GLFW_THEME_ATTRIBUTE_REDUCE_MOTION|
GLFW_THEME_COLOR_MAIN);
} }
_GLFWtheme* _glfwGetThemeWin32(_GLFWwindow* window, int inlineDefaults) _GLFWtheme* _glfwGetThemeWin32(_GLFWwindow* window, int inlineDefaults)
@ -2447,7 +2464,6 @@ _GLFWtheme* _glfwGetThemeWin32(_GLFWwindow* window, int inlineDefaults)
_GLFWtheme* theme = &window->theme.external; _GLFWtheme* theme = &window->theme.external;
memcpy(theme, &window->theme.internal, sizeof(_GLFWtheme)); memcpy(theme, &window->theme.internal, sizeof(_GLFWtheme));
// FIXME: fix not overriding specified properties.
if (!inlineDefaults) if (!inlineDefaults)
return theme; return theme;
@ -2461,7 +2477,7 @@ _GLFWtheme* _glfwGetThemeWin32(_GLFWwindow* window, int inlineDefaults)
if ((theme->flags & GLFW_THEME_COLOR_MAIN) == 0) if ((theme->flags & GLFW_THEME_COLOR_MAIN) == 0)
{ {
if (getAccentColor(&theme->color)) if (getAccentColor(theme->color))
theme->flags |= GLFW_THEME_COLOR_MAIN; theme->flags |= GLFW_THEME_COLOR_MAIN;
else else
memset(&theme->color, 0, sizeof(float) * 4); memset(&theme->color, 0, sizeof(float) * 4);