mirror of
https://github.com/glfw/glfw.git
synced 2024-11-29 15:44:35 +00:00
Conditionally execute theming based on OS version
This commit is contained in:
parent
2db9a368f7
commit
fe1eddc2ad
@ -190,16 +190,23 @@ static void createMenuBar(void)
|
||||
|
||||
void nsAppearanceToGLFWTheme(NSAppearance* appearance, GLFWtheme* theme)
|
||||
{
|
||||
NSAppearanceName name = [appearance bestMatchFromAppearancesWithNames:@[
|
||||
NSAppearanceNameAqua,
|
||||
NSAppearanceNameDarkAqua,
|
||||
NSAppearanceNameVibrantLight,
|
||||
NSAppearanceNameVibrantDark,
|
||||
NSAppearanceNameAccessibilityHighContrastAqua,
|
||||
NSAppearanceNameAccessibilityHighContrastDarkAqua,
|
||||
NSAppearanceNameAccessibilityHighContrastVibrantLight,
|
||||
NSAppearanceNameAccessibilityHighContrastVibrantDark
|
||||
]];
|
||||
NSAppearanceName name;
|
||||
|
||||
if (@available(macOS 10.14, *))
|
||||
{
|
||||
name = [appearance bestMatchFromAppearancesWithNames:@[
|
||||
NSAppearanceNameAqua,
|
||||
NSAppearanceNameDarkAqua,
|
||||
NSAppearanceNameVibrantLight,
|
||||
NSAppearanceNameVibrantDark,
|
||||
NSAppearanceNameAccessibilityHighContrastAqua,
|
||||
NSAppearanceNameAccessibilityHighContrastDarkAqua,
|
||||
NSAppearanceNameAccessibilityHighContrastVibrantLight,
|
||||
NSAppearanceNameAccessibilityHighContrastVibrantDark
|
||||
]];
|
||||
} else {
|
||||
name = appearance.name;
|
||||
}
|
||||
|
||||
if ([name isEqualToString:NSAppearanceNameAqua])
|
||||
{
|
||||
@ -480,16 +487,19 @@ static GLFWbool initializeTIS(void)
|
||||
|
||||
// TODO: FIXME: this method is invoked twice when the high contrast setting is edited in the preferences.
|
||||
|
||||
GLFWtheme theme = { 0, 0 };
|
||||
nsAppearanceToGLFWTheme(NSApp.effectiveAppearance, &theme);
|
||||
GLFWtheme theme = { GLFW_BASE_THEME_LIGHT, 0 };
|
||||
|
||||
NSColor* color = [[NSColor controlAccentColor] colorUsingColorSpace:NSColorSpace.genericRGBColorSpace];
|
||||
|
||||
theme.flags |= GLFW_THEME_FLAG_HAS_COLOR;
|
||||
theme.color[0] = color.redComponent * 255;
|
||||
theme.color[1] = color.greenComponent * 255;
|
||||
theme.color[2] = color.blueComponent * 255;
|
||||
theme.color[3] = color.alphaComponent * 255;
|
||||
if (@available(macOS 10.14, *)) {
|
||||
nsAppearanceToGLFWTheme(NSApp.effectiveAppearance, &theme);
|
||||
|
||||
NSColor* color = [[NSColor controlAccentColor] colorUsingColorSpace:NSColorSpace.genericRGBColorSpace];
|
||||
|
||||
theme.flags |= GLFW_THEME_FLAG_HAS_COLOR;
|
||||
theme.color[0] = color.redComponent * 255;
|
||||
theme.color[1] = color.greenComponent * 255;
|
||||
theme.color[2] = color.blueComponent * 255;
|
||||
theme.color[3] = color.alphaComponent * 255;
|
||||
}
|
||||
|
||||
_glfwInputSystemTheme(&theme);
|
||||
|
||||
|
@ -1883,6 +1883,12 @@ void _glfwSetThemeCocoa(_GLFWwindow* window, GLFWtheme* theme)
|
||||
[window->ns.object setAppearance:nil];
|
||||
return;
|
||||
}
|
||||
|
||||
if (@available(macOS 10.10, *)) {} else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: support color
|
||||
// TODO: fix vibrancy
|
||||
|
||||
@ -1892,7 +1898,8 @@ void _glfwSetThemeCocoa(_GLFWwindow* window, GLFWtheme* theme)
|
||||
|
||||
if (theme->baseTheme == GLFW_BASE_THEME_LIGHT)
|
||||
{
|
||||
if (theme->flags & GLFW_THEME_FLAG_VIBRANT) {
|
||||
if (theme->flags & GLFW_THEME_FLAG_VIBRANT)
|
||||
{
|
||||
name = NSAppearanceNameVibrantLight;
|
||||
}
|
||||
else
|
||||
@ -1902,12 +1909,16 @@ void _glfwSetThemeCocoa(_GLFWwindow* window, GLFWtheme* theme)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (theme->flags & GLFW_THEME_FLAG_VIBRANT) {
|
||||
if (theme->flags & GLFW_THEME_FLAG_VIBRANT)
|
||||
{
|
||||
name = NSAppearanceNameVibrantDark;
|
||||
}
|
||||
else
|
||||
else if (@available(macOS 10.14, *))
|
||||
{
|
||||
name = NSAppearanceNameDarkAqua;
|
||||
} else
|
||||
{
|
||||
name = NSAppearanceNameAqua;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1919,20 +1930,25 @@ GLFWtheme* _glfwGetThemeCocoa(_GLFWwindow* window)
|
||||
{
|
||||
GLFWtheme* theme = &window->theme;
|
||||
|
||||
theme->baseTheme = 0;
|
||||
theme->baseTheme = GLFW_BASE_THEME_LIGHT;
|
||||
theme->flags = 0;
|
||||
|
||||
nsAppearanceToGLFWTheme([window->ns.object appearance], theme);
|
||||
if (@available(macOS 10.09, *))
|
||||
{
|
||||
nsAppearanceToGLFWTheme([window->ns.object appearance], theme);
|
||||
}
|
||||
|
||||
// TODO: this is not settable. Is there any reason in overriding a similar value? Does it apply to menu item highlights? If yes, then it must be overridden.
|
||||
NSColor* color = [[NSColor controlAccentColor] colorUsingColorSpace:NSColorSpace.genericRGBColorSpace];
|
||||
// TODO: Cannot use the accent color directly, for window themes, because the accent color is never overridden.
|
||||
|
||||
theme->flags |= GLFW_THEME_FLAG_HAS_COLOR;
|
||||
theme->color[0] = color.redComponent * 255;
|
||||
theme->color[1] = color.greenComponent * 255;
|
||||
theme->color[2] = color.blueComponent * 255;
|
||||
theme->color[3] = color.alphaComponent * 255;
|
||||
if (@available(macOS 10.14, *)) {
|
||||
// TODO: this is not settable. Is there any reason in overriding a similar value? Does it apply to menu item highlights? If yes, then it must be overridden.
|
||||
NSColor* color = [[NSColor controlAccentColor] colorUsingColorSpace:NSColorSpace.genericRGBColorSpace];
|
||||
// TODO: Cannot use the accent color directly, for window themes, because the accent color is never overridden.
|
||||
|
||||
theme->flags |= GLFW_THEME_FLAG_HAS_COLOR;
|
||||
theme->color[0] = color.redComponent * 255;
|
||||
theme->color[1] = color.greenComponent * 255;
|
||||
theme->color[2] = color.blueComponent * 255;
|
||||
theme->color[3] = color.alphaComponent * 255;
|
||||
}
|
||||
|
||||
return theme;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user