From b5363d87d2d01055bf5cbedfefce9eab0bbb1f73 Mon Sep 17 00:00:00 2001 From: ws909 <37029098+ws909@users.noreply.github.com> Date: Thu, 26 Jan 2023 08:50:42 +0100 Subject: [PATCH] Fix remaining build errors for Cocoa. --- src/cocoa_init.m | 94 ++++++++++++++++++++++++---------------------- src/cocoa_window.m | 4 +- 2 files changed, 51 insertions(+), 47 deletions(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 8c60bb31..f9726f84 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -35,19 +35,6 @@ // Needed for _NSGetProgname #include - -#if MAC_OS_X_VERSION_MAX_ALLOWED < 101000 -NSAppearanceName const NSAppearanceNameVibrantLight = @"NSAppearanceNameVibrantLight"; -NSAppearanceName const NSAppearanceNameVibrantDark = @"NSAppearanceNameVibrantDark"; -#endif -#if MAC_OS_X_VERSION_MAX_ALLOWED < 101400 -NSAppearanceName const NSAppearanceNameDarkAqua = @"NSAppearanceNameDarkAqua"; -NSAppearanceName const NSAppearanceNameAccessibilityHighContrastAqua = @"NSAppearanceNameAccessibilityAqua"; -NSAppearanceName const NSAppearanceNameAccessibilityHighContrastDarkAqua = @"NSAppearanceNameAccessibilityDarkAqua"; -NSAppearanceName const NSAppearanceNameAccessibilityHighContrastVibrantLight = @"NSAppearanceNameAccessibilityVibrantLight"; -NSAppearanceName const NSAppearanceNameAccessibilityHighContrastVibrantDark = @"NSAppearanceNameAccessibilityVibrantDark"; -#endif - // Change to our application bundle's resources directory, if present // static void changeToResourcesDirectory(void) @@ -211,41 +198,58 @@ void nsAppearanceToGLFWTheme(NSAppearance* appearance, GLFWtheme* theme) if ([name isEqualToString:NSAppearanceNameAqua]) { theme->baseTheme = GLFW_BASE_THEME_LIGHT; + return; } - else if ([name isEqualToString:NSAppearanceNameDarkAqua]) + + if (@available(macOS 10.10, *)) { + if ([name isEqualToString:NSAppearanceNameVibrantLight]) + { + theme->baseTheme = GLFW_BASE_THEME_LIGHT; + theme->flags |= GLFW_THEME_FLAG_VIBRANT; + return; + } + if ([name isEqualToString:NSAppearanceNameVibrantDark]) + { + theme->baseTheme = GLFW_BASE_THEME_DARK; + theme->flags |= GLFW_THEME_FLAG_VIBRANT; + return; + } + } + + if (@available(macOS 10.14, *)) { - theme->baseTheme = GLFW_BASE_THEME_DARK; - } - else if ([name isEqualToString:NSAppearanceNameVibrantLight]) - { - theme->baseTheme = GLFW_BASE_THEME_LIGHT; - theme->flags |= GLFW_THEME_FLAG_VIBRANT; - } - else if ([name isEqualToString:NSAppearanceNameVibrantDark]) - { - theme->baseTheme = GLFW_BASE_THEME_DARK; - theme->flags |= GLFW_THEME_FLAG_VIBRANT; - } - if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastAqua]) - { - theme->baseTheme = GLFW_BASE_THEME_LIGHT; - theme->flags |= GLFW_THEME_FLAG_HIGH_CONTRAST; - } - else if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastDarkAqua]) - { - theme->baseTheme = GLFW_BASE_THEME_DARK; - theme->flags |= GLFW_THEME_FLAG_HIGH_CONTRAST; - } - else if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastVibrantLight]) - { - theme->baseTheme = GLFW_BASE_THEME_LIGHT; - theme->flags |= GLFW_THEME_FLAG_VIBRANT | GLFW_THEME_FLAG_HIGH_CONTRAST; - } - else if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastVibrantDark]) - { - theme->baseTheme = GLFW_BASE_THEME_DARK; - theme->flags |= GLFW_THEME_FLAG_VIBRANT | GLFW_THEME_FLAG_HIGH_CONTRAST; + if ([name isEqualToString:NSAppearanceNameDarkAqua]) + { + theme->baseTheme = GLFW_BASE_THEME_DARK; + return; + } + if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastAqua]) + { + theme->baseTheme = GLFW_BASE_THEME_LIGHT; + theme->flags |= GLFW_THEME_FLAG_HIGH_CONTRAST; + return; + } + if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastDarkAqua]) + { + theme->baseTheme = GLFW_BASE_THEME_DARK; + theme->flags |= GLFW_THEME_FLAG_HIGH_CONTRAST; + return; + } + if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastVibrantLight]) + { + theme->baseTheme = GLFW_BASE_THEME_LIGHT; + theme->flags |= GLFW_THEME_FLAG_VIBRANT | GLFW_THEME_FLAG_HIGH_CONTRAST; + return; + } + if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastVibrantDark]) + { + theme->baseTheme = GLFW_BASE_THEME_DARK; + theme->flags |= GLFW_THEME_FLAG_VIBRANT | GLFW_THEME_FLAG_HIGH_CONTRAST; + return; + } } + + theme->baseTheme = GLFW_BASE_THEME_LIGHT; } // Create key code translation tables diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 4e32731a..6ba54501 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1880,7 +1880,7 @@ void _glfwSetThemeCocoa(_GLFWwindow* window, GLFWtheme* theme) { if (!theme || theme->baseTheme == GLFW_BASE_THEME_DEFAULT) { - [window->ns.object setAppearance:nil]; + [(NSWindow*)window->ns.object setAppearance:nil]; return; } @@ -1923,7 +1923,7 @@ void _glfwSetThemeCocoa(_GLFWwindow* window, GLFWtheme* theme) } NSAppearance* appearance = [NSAppearance appearanceNamed:name]; - [window->ns.object setAppearance:appearance]; + [(NSWindow*)window->ns.object setAppearance:appearance]; } GLFWtheme* _glfwGetThemeCocoa(_GLFWwindow* window)