diff --git a/Headers/Additions/GNUstepGUI/GSTheme.h b/Headers/Additions/GNUstepGUI/GSTheme.h index 643617cac8..e0892984d3 100644 --- a/Headers/Additions/GNUstepGUI/GSTheme.h +++ b/Headers/Additions/GNUstepGUI/GSTheme.h @@ -783,6 +783,41 @@ APPKIT_EXPORT_CLASS */ - (NSString*) license; +/** + * Returns YES if Theme is able to display in Light NSAppearance + * For a theme supporting both Light and Dark modes, it should return both + * supportsLightAppearance and supportsDarkAppearance + * Light is the "default" of the GNUstep theme like Cocoa Aqua. + */ +- (BOOL) supportsLightAppearance; + +/** + * Returns YES if Theme is able to display in Dark NSAppearance + * For a theme supporting both Light and Dark modes, it should return both + * supportsLightAppearance and supportsDarkAppearance + * Light is the default Aqua and GNUstep "classic", but a GNUstep can be dark only. + */ +- (BOOL) supportsDarkAppearance; + +/** + * Returns YES if displaying in Light NSAppearance (or non-Dark) + * Should match if theme is equivalent to Cocoa names like + * NSAppearanceNameAqua or NSAppearanceNameAccessibilityHighContrastAqua + * + * Being only Light and Dark supported, must be opposite of inDarkAppearance + */ +- (BOOL) inLightAppearance; + +/** + * Returns YES if displaying in dark NSAppearance + * Should match if theme is equivalent to Cocoa names like + * NSAppearanceNameDarkAqua or NSAppearanceNameAccessibilityHighContrastDarkAqua + * + * Being only Light and Dark supported, must be opposite of inLightAppearance + */ +- (BOOL) inDarkAppearance; + + @end /** diff --git a/Source/GSTheme.m b/Source/GSTheme.m index 2067be731f..35c214eaf0 100644 --- a/Source/GSTheme.m +++ b/Source/GSTheme.m @@ -1339,6 +1339,69 @@ - (NSString *) license return [[self infoDictionary] objectForKey: @"GSThemeLicense"]; } +- (BOOL) supportsLightAppearance +{ + NSString *val; + BOOL r; + + r = YES; // default themes are light + val = [[self infoDictionary] objectForKey: @"GSThemeSupportsLightAppearance"]; + + if (val && [val isEqualToString: @"YES"]) + r = YES; + + return r; +} + +- (BOOL) supportsDarkAppearance +{ + NSString *val; + BOOL r; + + r = NO; // default themes are light + val = [[self infoDictionary] objectForKey: @"GSThemeSupportsDarkAppearance"]; + + // Do we have the key or is it an old GSTheme? + if (val == nil) + { + // try heuristic on the theme name + if ([[self name] hasSuffix:@"Dark"]) + { + r = YES; + } + } + else + { + if ([val isEqualToString: @"YES"]) + { + r = YES; + } + } + + return r; +} + +- (BOOL) inLightAppearance +{ + // NOTE: maybe we should cache this in an ivar + if (![self supportsLightAppearance] && [self supportsDarkAppearance]) + { + return NO; + } + return YES; +} + +- (BOOL) inDarkAppearance; +{ + // NOTE: maybe we should cache this in an ivar + if (![self supportsLightAppearance] && [self supportsDarkAppearance]) + { + return YES; + } + return NO; +} + + @end @implementation GSTheme (Private)