diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index ca8e1e87..61f0a5f8 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1394,6 +1394,18 @@ typedef struct GLFWwindow GLFWwindow; */ typedef struct GLFWcursor GLFWcursor; +/*! @brief Opaque theme object. + * + * Opaque theme object. + * + * @see @ref theme_object + * + * @since Added in version 3.4. + * + * @ingroup theme + */ +typedef struct GLFWtheme GLFWtheme; + /*! @brief The function pointer type for memory allocation callbacks. * * This is the function pointer type for memory allocation callbacks. A memory @@ -1964,6 +1976,28 @@ typedef void (* GLFWmonitorfun)(GLFWmonitor* monitor, int event); */ typedef void (* GLFWjoystickfun)(int jid, int event); +/*! @brief The function pointer type for system theme callbacks. + * + * This is the function pointer type for system theme callbacks. A system + * theme callback function has the following signature: + * @code + * void function_name(GLFWtheme* theme) + * @endcode + * + * @param[in] theme The new system theme. + * + * @pointer_lifetime The theme is valid until the callback + * function returns. + * + * @sa @ref theme + * @sa @ref glfwSetSystemThemeCallback + * + * @since Added in version 3.4. + * + * @ingroup theme + */ +typedef void (* GLFWthemefun)(GLFWtheme* theme); + /*! @brief Video mode type. * * This describes a single video mode. @@ -5845,15 +5879,6 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string); */ GLFWAPI const char* glfwGetClipboardString(GLFWwindow* window); -typedef struct GLFWtheme GLFWtheme; - -typedef struct _GLFWtheme -{ - int variation; // light/dark - int flags; - unsigned char color[4]; // TODO: change to 128 bit (4 floats) to support wider gamuts. -} _GLFWtheme; - GLFWAPI GLFWtheme* glfwCreateTheme(void); GLFWAPI void glfwDestroyTheme(GLFWtheme* theme); GLFWAPI void glfwCopyTheme(const GLFWtheme* source, GLFWtheme* target); @@ -5861,34 +5886,167 @@ GLFWAPI void glfwCopyTheme(const GLFWtheme* source, GLFWtheme* target); GLFWAPI int glfwThemeGetVariation(const GLFWtheme* theme); GLFWAPI void glfwThemeSetVariation(GLFWtheme* theme, int value); -GLFWAPI int glfwThemeGetFlags(const GLFWtheme* theme); -GLFWAPI void glfwThemeSetFlags(GLFWtheme* theme, int value); +GLFWAPI int glfwThemeGetAttribute(const GLFWtheme* theme, int attribute); +GLFWAPI void glfwThemeSetAttribute(GLFWtheme* theme, int attribute, int value); GLFWAPI void glfwThemeGetColor(const GLFWtheme* theme, float* red, float* green, float* blue, float* alpha); GLFWAPI void glfwThemeSetColor(GLFWtheme* theme, float red, float green, float blue, float alpha); +/*! @brief Theme variation type. + * + * Specifies that a theme is of a dark variation. + * + * @ingroup theme + */ #define GLFW_THEME_DARK -1 + +/*! @brief Theme variation type. + * + * Specifies that a theme has no specific variation. + * This is an invalid value for themes returned by GLFW, but this + * variation can be set to make GLFW use the default system theme when + * applying a user-specified theme. + * + * @ingroup theme + */ #define GLFW_THEME_DEFAULT 0 + +/*! @brief Theme variation type. + * + * Specifies that a theme is of a light variation. + * + * @ingroup theme + */ #define GLFW_THEME_LIGHT 1 -#define GLFW_THEME_FLAG_HAS_COLOR 1 -#define GLFW_THEME_FLAG_HIGH_CONTRAST 2 -#define GLFW_THEME_FLAG_VIBRANT 4 -typedef void (* GLFWthemefun)(GLFWtheme* theme); - -/*! @brief Notifies the application when the system default theme changes. +/*! @brief Theme attribute. * + * Specifies that a theme provides a color. If this flag is set on a theme + * returned by GLFW, this theme contains a color. If this flag is set on a + * theme supplied to GLFW, GLFW applies this theme if the platform supports it. + * If the flag is unset, the theme's color is ignored. + * + * @ingroup theme + */ +#define GLFW_THEME_ATTRIBUTE_HAS_COLOR 1 + +/*! @brief Theme attribute. + * + * Specifies that a theme uses a high contrast mode. + * + * @ingroup theme + */ +#define GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST 2 + +/*! @brief Theme attribute. + * + * Specifies that a theme is vibrant. + * + * @ingroup theme + */ +#define GLFW_THEME_ATTRIBUTE_VIBRANT 4 + +/*! @brief Sets the system theme callback. + * + * This function sets the system theme callback, or removes the + * currently set callback. This is called when the system theme changes, + * either because the user edited it, or the system automatically changed it. + * + * @param[in] callback The new callback, or `NULL` to remove the currently set + * callback. + * @return The previously set callback, or `NULL` if no callback was set or the + * library had not been [initialized](@ref intro_init). + * + * @callback_signature + * @code + * void function_name(GLFWtheme* theme) + * @endcode + * For more information about the callback parameters, see the + * [function pointer type](@ref GLFWthemefun). + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref theme_event + * + * @since Added in version 3.4. + * + * @ingroup theme */ GLFWAPI GLFWthemefun glfwSetSystemThemeCallback(GLFWthemefun callback); /*! @brief Sets the theme for a window. * - * @param[in] window The window to set the theme for. - * @param[in] theme The theme to set. Pass `NULL` to set it to the system default. + * @param[in] window The [window](@ref window) to set the theme for. + * @param[in] theme The [theme](@ref theme) to set. Pass `NULL` to set it to the system default. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, + * and @ref GLFW_FEATURE_UNIMPLEMENTED. + * + * @pointer_lifetime The returned theme is allocated and freed by GLFW. You + * should not free it yourself. It is valid until this function or @ref glfwGetTheme + * is called again for the specified window, or the window is destroyed. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref theme + * @sa @ref glfwGetTheme + * + * @since Added in version 3.4. + * + * @ingroup theme */ GLFWAPI void glfwSetTheme(GLFWwindow* handle, const GLFWtheme* theme); + +/*! @brief Returns the currently active system theme. + * + * @param[in] window The [window](@ref window) to retrieve the current theme for. + * + * @return A mutable [theme](@ref theme) object, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, + * and @ref GLFW_FEATURE_UNIMPLEMENTED. + * + * @pointer_lifetime The returned theme is allocated and freed by GLFW. You + * should not free it yourself. It is valid until this function or @ref glfwSetTheme + * is called again for the specified window, or the window is destroyed. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref theme + * @sa @ref glfwSetTheme + * + * @since Added in version 3.4. + * + * @ingroup theme + */ GLFWAPI GLFWtheme* glfwGetTheme(GLFWwindow* handle); + +/*! @brief Returns the currently active system theme. + * + * @return A mutable [theme](@ref theme) object, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, + * and @ref GLFW_FEATURE_UNIMPLEMENTED. + * + * @pointer_lifetime The returned theme is allocated and freed by GLFW. You + * should not free it yourself. It is valid until this function is called + * again, or the library is terminated. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref theme + * @sa @ref glfwSetSystemThemeCallback + * @sa @ref glfwSetTheme + * + * @since Added in version 3.4. + * + * @ingroup theme + */ GLFWAPI GLFWtheme* glfwGetSystemDefaultTheme(); /*! @brief Returns the GLFW time. diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 5c8b0e82..e92dcefe 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -205,13 +205,13 @@ void nsAppearanceToGLFWTheme(NSAppearance* appearance, _GLFWtheme* theme) if ([name isEqualToString:NSAppearanceNameVibrantLight]) { theme->variation = GLFW_THEME_LIGHT; - theme->flags |= GLFW_THEME_FLAG_VIBRANT; + theme->flags |= GLFW_THEME_ATTRIBUTE_VIBRANT; return; } if ([name isEqualToString:NSAppearanceNameVibrantDark]) { theme->variation = GLFW_THEME_DARK; - theme->flags |= GLFW_THEME_FLAG_VIBRANT; + theme->flags |= GLFW_THEME_ATTRIBUTE_VIBRANT; return; } } @@ -226,25 +226,25 @@ void nsAppearanceToGLFWTheme(NSAppearance* appearance, _GLFWtheme* theme) if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastAqua]) { theme->variation = GLFW_THEME_LIGHT; - theme->flags |= GLFW_THEME_FLAG_HIGH_CONTRAST; + theme->flags |= GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST; return; } if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastDarkAqua]) { theme->variation = GLFW_THEME_DARK; - theme->flags |= GLFW_THEME_FLAG_HIGH_CONTRAST; + theme->flags |= GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST; return; } if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastVibrantLight]) { theme->variation = GLFW_THEME_LIGHT; - theme->flags |= GLFW_THEME_FLAG_VIBRANT | GLFW_THEME_FLAG_HIGH_CONTRAST; + theme->flags |= GLFW_THEME_ATTRIBUTE_VIBRANT | GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST; return; } if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastVibrantDark]) { theme->variation = GLFW_THEME_DARK; - theme->flags |= GLFW_THEME_FLAG_VIBRANT | GLFW_THEME_FLAG_HIGH_CONTRAST; + theme->flags |= GLFW_THEME_ATTRIBUTE_VIBRANT | GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST; return; } } @@ -252,6 +252,28 @@ void nsAppearanceToGLFWTheme(NSAppearance* appearance, _GLFWtheme* theme) theme->variation = GLFW_THEME_LIGHT; } +static void getSystemTheme(_GLFWtheme* theme) +{ + theme->variation = GLFW_THEME_LIGHT; + theme->flags = 0; + + if (@available(macOS 10.14, *)) + { + // effectiveAppearance is actually not the system appearance, but the application appearance. + // As long as NSApplication.appearance is never set, using the effective appearance is fine + // to get and observe the system appearance. + nsAppearanceToGLFWTheme(NSApp.effectiveAppearance, theme); + + NSColor* color = [[NSColor controlAccentColor] colorUsingColorSpace:NSColorSpace.genericRGBColorSpace]; + + theme->flags |= GLFW_THEME_ATTRIBUTE_HAS_COLOR; + theme->color[0] = color.redComponent; + theme->color[1] = color.greenComponent; + theme->color[2] = color.blueComponent; + theme->color[3] = color.alphaComponent; + } +} + // Create key code translation tables // static void createKeyTables(void) @@ -491,22 +513,8 @@ static GLFWbool initializeTIS(void) // TODO: FIXME: this method is invoked twice when the high contrast setting is edited in the preferences. - _GLFWtheme theme = { GLFW_THEME_LIGHT, 0 }; - - if (@available(macOS 10.14, *)) { - // effectiveAppearance is actually not the system appearance, but the application appearance. - // As long as NSApplication.appearance is never set, using the effective appearance is fine - // to get and observe the system appearance. - 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; - } + _GLFWtheme theme; + getSystemTheme(&theme); _glfwInputSystemTheme(&theme); @@ -778,12 +786,13 @@ int _glfwInitCocoa(void) context:nil]; */ -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 - [NSApp addObserver:_glfw.ns.helper - forKeyPath:@"effectiveAppearance" - options:0 - context:nil]; -#endif + if (@available(macOS 10.14, *)) + { + [NSApp addObserver:_glfw.ns.helper + forKeyPath:@"effectiveAppearance" + options:0 + context:nil]; + } if (![[NSRunningApplication currentApplication] isFinishedLaunching]) [NSApp run]; @@ -847,8 +856,10 @@ void _glfwTerminateCocoa(void) _GLFWtheme* _glfwGetSystemDefaultThemeCocoa(void) { - _glfwInputError(GLFW_FEATURE_UNIMPLEMENTED, NULL); - return NULL; // TODO: implement + _GLFWtheme* theme = &_glfw.theme; + getSystemTheme(theme); + + return theme; } #endif // _GLFW_COCOA diff --git a/src/cocoa_window.m b/src/cocoa_window.m index b99a9e85..a8fa387a 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1898,7 +1898,7 @@ void _glfwSetThemeCocoa(_GLFWwindow* window, _GLFWtheme* theme) if (theme->variation == GLFW_THEME_LIGHT) { - if (theme->flags & GLFW_THEME_FLAG_VIBRANT) + if (theme->flags & GLFW_THEME_ATTRIBUTE_VIBRANT) { name = NSAppearanceNameVibrantLight; } @@ -1909,7 +1909,7 @@ void _glfwSetThemeCocoa(_GLFWwindow* window, _GLFWtheme* theme) } else { - if (theme->flags & GLFW_THEME_FLAG_VIBRANT) + if (theme->flags & GLFW_THEME_ATTRIBUTE_VIBRANT) { name = NSAppearanceNameVibrantDark; } @@ -1935,7 +1935,12 @@ _GLFWtheme* _glfwGetThemeCocoa(_GLFWwindow* window) if (@available(macOS 10.09, *)) { - nsAppearanceToGLFWTheme([(NSWindow*)window->ns.object appearance], theme); + NSAppearance* appearance = [(NSWindow*)window->ns.object appearance]; + + if (appearance == NULL) + appearance = [NSApp effectiveAppearance]; + + nsAppearanceToGLFWTheme(appearance, theme); } if (@available(macOS 10.14, *)) { @@ -1943,11 +1948,11 @@ _GLFWtheme* _glfwGetThemeCocoa(_GLFWwindow* window) 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; + theme->flags |= GLFW_THEME_ATTRIBUTE_HAS_COLOR; + theme->color[0] = color.redComponent; + theme->color[1] = color.greenComponent; + theme->color[2] = color.blueComponent; + theme->color[3] = color.alphaComponent; } return theme; diff --git a/src/init.c b/src/init.c index 69d391c1..6cd16a76 100644 --- a/src/init.c +++ b/src/init.c @@ -548,7 +548,7 @@ GLFWAPI GLFWtheme* glfwGetSystemDefaultTheme() _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFWtheme* theme = _glfw.platform.getSystemDefaultTheme(); - assert(theme->variation != GLFW_THEME_DEFAULT); + assert(theme->variation != GLFW_THEME_DEFAULT); return (GLFWtheme*) theme; } diff --git a/src/internal.h b/src/internal.h index 9795fc6b..d6d76851 100644 --- a/src/internal.h +++ b/src/internal.h @@ -72,6 +72,7 @@ typedef struct _GLFWplatform _GLFWplatform; typedef struct _GLFWlibrary _GLFWlibrary; typedef struct _GLFWmonitor _GLFWmonitor; typedef struct _GLFWcursor _GLFWcursor; +typedef struct _GLFWtheme _GLFWtheme; typedef struct _GLFWmapelement _GLFWmapelement; typedef struct _GLFWmapping _GLFWmapping; typedef struct _GLFWjoystick _GLFWjoystick; @@ -515,6 +516,20 @@ struct _GLFWcontext GLFW_PLATFORM_CONTEXT_STATE }; +// Theme structure +// +struct _GLFWtheme +{ + // The light/dark variation. If set to DEFAULT, use the system theme variation. + int variation; + + int flags; + + // When applying a theme, ignore this color if the HAS_COLOR + // flag is unset, and use the system theme color instead. + float color[4]; +}; + // Window and context structure // struct _GLFWwindow @@ -571,7 +586,8 @@ struct _GLFWwindow GLFWdropfun drop; } callbacks; - _GLFWtheme theme; // TODO: This data is mutable by clients, so remove it. + // Clients can mutate this theme data at any time + _GLFWtheme theme; // This is defined in platform.h GLFW_PLATFORM_WINDOW_STATE @@ -871,6 +887,9 @@ struct _GLFWlibrary GLFWjoystickfun joystick; GLFWthemefun theme; } callbacks; + + // Clients can mutate this theme data at any time + _GLFWtheme theme; // These are defined in platform.h GLFW_PLATFORM_LIBRARY_WINDOW_STATE diff --git a/src/theme.c b/src/theme.c index bcb119a0..356124d9 100644 --- a/src/theme.c +++ b/src/theme.c @@ -1,9 +1,26 @@ +//======================================================================== +// GLFW 3.4 - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2023 Andreas O. Jansen // -// theme.c -// glfw +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. // -// Created by Andreas Ormevik Jansen on 28/01/2023. +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: // +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. #include "internal.h" @@ -48,18 +65,30 @@ GLFWAPI void glfwThemeSetVariation(GLFWtheme* theme, int value) ((_GLFWtheme*) theme)->variation = value; } -GLFWAPI int glfwThemeGetFlags(const GLFWtheme* theme) +GLFWAPI int glfwThemeGetAttribute(const GLFWtheme* theme, int attribute) { assert(theme != NULL); - return ((_GLFWtheme*) theme)->flags; + assert((attribute & ~(GLFW_THEME_ATTRIBUTE_HAS_COLOR | + GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST | + GLFW_THEME_ATTRIBUTE_VIBRANT)) == 0); + + return ((_GLFWtheme*) theme)->flags & attribute ? GLFW_TRUE : GLFW_FALSE; } -GLFWAPI void glfwThemeSetFlags(GLFWtheme* theme, int value) +GLFWAPI void glfwThemeSetAttribute(GLFWtheme* theme, int attribute, int value) { assert(theme != NULL); - assert((value & ~(GLFW_THEME_FLAG_HAS_COLOR | GLFW_THEME_FLAG_HIGH_CONTRAST | GLFW_THEME_FLAG_VIBRANT)) == 0); + assert(value == GLFW_TRUE || value == GLFW_FALSE); + assert((attribute & ~(GLFW_THEME_ATTRIBUTE_HAS_COLOR | + GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST | + GLFW_THEME_ATTRIBUTE_VIBRANT)) == 0); - ((_GLFWtheme*) theme)->flags = value; + _GLFWtheme* _theme = (_GLFWtheme*) theme; + + if (value == GLFW_TRUE) + _theme->flags |= attribute; + else + _theme->flags &= ~attribute; } GLFWAPI void glfwThemeGetColor(const GLFWtheme* theme, float* red, float* green, float* blue, float* alpha) @@ -67,22 +96,22 @@ GLFWAPI void glfwThemeGetColor(const GLFWtheme* theme, float* red, float* green, assert(theme != NULL); assert(red != NULL && green != NULL && blue != NULL && alpha != NULL); - const _GLFWtheme* iTheme = ((_GLFWtheme*) theme); + const float* color = ((_GLFWtheme*) theme)->color; - *red = iTheme->color[0] / 255.0f; - *green = iTheme->color[1] / 255.0f; - *blue = iTheme->color[2] / 255.0f; - *alpha = iTheme->color[3] / 255.0f; + *red = color[0]; + *green = color[1]; + *blue = color[2]; + *alpha = color[3]; } GLFWAPI void glfwThemeSetColor(GLFWtheme* theme, float red, float green, float blue, float alpha) { assert(theme != NULL); - _GLFWtheme* iTheme = ((_GLFWtheme*) theme); + float* color = ((_GLFWtheme*) theme)->color; - iTheme->color[0] = red * 255.0f; - iTheme->color[1] = green * 255.0f; - iTheme->color[2] = blue * 255.0f; - iTheme->color[3] = alpha * 255.0f; + color[0] = red; + color[1] = green; + color[2] = blue; + color[3] = alpha; } diff --git a/tests/theming.c b/tests/theming.c index 21bab47b..41bfdf35 100644 --- a/tests/theming.c +++ b/tests/theming.c @@ -52,26 +52,25 @@ static GLFWtheme* theme; static void print_theme(GLFWtheme* theme, const char* title) { - const int flags = glfwThemeGetFlags(theme); int n = 0; printf("%s: {\n", title); printf(" Base: %s\n", glfwThemeGetVariation(theme) == GLFW_THEME_LIGHT ? "light" : "dark"); printf(" Flags: ["); - if (flags & GLFW_THEME_FLAG_HAS_COLOR) + if (glfwThemeGetAttribute(theme, GLFW_THEME_ATTRIBUTE_HAS_COLOR)) { printf(n++ > 0 ? ", %s" : "%s", "HAS_COLOR"); } - if (flags & GLFW_THEME_FLAG_VIBRANT) + if (glfwThemeGetAttribute(theme, GLFW_THEME_ATTRIBUTE_VIBRANT)) { printf(n++ > 0 ? ", %s" : "%s", "VIBRANT"); } - if (flags & GLFW_THEME_FLAG_HIGH_CONTRAST) + if (glfwThemeGetAttribute(theme, GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST)) { printf(n++ > 0 ? ", %s" : "%s", "HIGH_CONTRAST"); } printf("]\n"); - if (flags & GLFW_THEME_FLAG_HAS_COLOR) + if (glfwThemeGetAttribute(theme, GLFW_THEME_ATTRIBUTE_HAS_COLOR)) { float r, g, b, a; glfwThemeGetColor(theme, &r, &g, &b, &a); @@ -91,12 +90,9 @@ static void set_theme(GLFWwindow* window, int theme_color) ); if (theme_color == 6) - { - glfwThemeSetFlags(theme, glfwThemeGetFlags(theme) & ~GLFW_THEME_FLAG_HAS_COLOR); - } else - { - glfwThemeSetFlags(theme, glfwThemeGetFlags(theme) | GLFW_THEME_FLAG_HAS_COLOR); - } + glfwThemeSetAttribute(theme, GLFW_THEME_ATTRIBUTE_HAS_COLOR, GLFW_FALSE); + else + glfwThemeSetAttribute(theme, GLFW_THEME_ATTRIBUTE_HAS_COLOR, GLFW_TRUE); const char* title; @@ -166,6 +162,8 @@ int main(int argc, char** argv) fprintf(stderr, "Failed to initialize GLFW\n"); exit(EXIT_FAILURE); } + + print_theme(glfwGetSystemDefaultTheme(), "System theme"); window = glfwCreateWindow(200, 200, "Window Icon", NULL, NULL); if (!window) @@ -182,10 +180,6 @@ int main(int argc, char** argv) glfwSetKeyCallback(window, key_callback); theme = glfwCreateTheme(); - - glfwThemeSetVariation(theme, GLFW_THEME_DEFAULT); - glfwThemeSetFlags(theme, 0); - glfwThemeSetColor(theme, 0, 0, 0, 0); set_theme(window, cur_theme_color); glfwSetSystemThemeCallback(theme_callback); @@ -193,10 +187,10 @@ int main(int argc, char** argv) while (!glfwWindowShouldClose(window)) { glClearColor( - theme_colors[cur_theme_color][0] / 255.0f, - theme_colors[cur_theme_color][1] / 255.0f, - theme_colors[cur_theme_color][2] / 255.0f, - theme_colors[cur_theme_color][3] / 255.0f + theme_colors[cur_theme_color][0], + theme_colors[cur_theme_color][1], + theme_colors[cur_theme_color][2], + theme_colors[cur_theme_color][3] ); glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(window);