diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 75ba656e..61f0a5f8 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -5886,8 +5886,8 @@ 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); @@ -5920,7 +5920,7 @@ GLFWAPI void glfwThemeSetColor(GLFWtheme* theme, float red, float green, float b #define GLFW_THEME_LIGHT 1 -/*! @brief Theme flag. +/*! @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 @@ -5929,23 +5929,23 @@ GLFWAPI void glfwThemeSetColor(GLFWtheme* theme, float red, float green, float b * * @ingroup theme */ -#define GLFW_THEME_FLAG_HAS_COLOR 1 +#define GLFW_THEME_ATTRIBUTE_HAS_COLOR 1 -/*! @brief Theme flag. +/*! @brief Theme attribute. * * Specifies that a theme uses a high contrast mode. * * @ingroup theme */ -#define GLFW_THEME_FLAG_HIGH_CONTRAST 2 +#define GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST 2 -/*! @brief Theme flag. +/*! @brief Theme attribute. * * Specifies that a theme is vibrant. * * @ingroup theme */ -#define GLFW_THEME_FLAG_VIBRANT 4 +#define GLFW_THEME_ATTRIBUTE_VIBRANT 4 /*! @brief Sets the system theme callback. * diff --git a/src/cocoa_init.m b/src/cocoa_init.m index d075a0e1..45708892 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; } } @@ -501,7 +501,7 @@ static GLFWbool initializeTIS(void) NSColor* color = [[NSColor controlAccentColor] colorUsingColorSpace:NSColorSpace.genericRGBColorSpace]; - theme.flags |= GLFW_THEME_FLAG_HAS_COLOR; + theme.flags |= GLFW_THEME_ATTRIBUTE_HAS_COLOR; theme.color[0] = color.redComponent; theme.color[1] = color.greenComponent; theme.color[2] = color.blueComponent; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index acb23f94..bb5c465a 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; } @@ -1943,7 +1943,7 @@ _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->flags |= GLFW_THEME_ATTRIBUTE_HAS_COLOR; theme->color[0] = color.redComponent; theme->color[1] = color.greenComponent; theme->color[2] = color.blueComponent; diff --git a/src/theme.c b/src/theme.c index b27d6bb3..356124d9 100644 --- a/src/theme.c +++ b/src/theme.c @@ -65,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) diff --git a/tests/theming.c b/tests/theming.c index 6c311950..8d22e0b4 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; @@ -183,8 +179,6 @@ int main(int argc, char** argv) theme = glfwCreateTheme(); - glfwThemeSetVariation(theme, GLFW_THEME_DEFAULT); - glfwThemeSetFlags(theme, 0); glfwThemeSetColor(theme, 0, 0, 0, 0); set_theme(window, cur_theme_color);