Add a color-scheme setting

This is the desktop-wide prefer-dark/prefer-light setting.
This commit is contained in:
Matthias Clasen
2024-06-03 23:17:07 -04:00
parent c18a7ff5cf
commit 2b5ec9e879
2 changed files with 41 additions and 1 deletions

View File

@@ -1245,7 +1245,8 @@ typedef enum {
GTK_SYSTEM_SETTING_FONT_NAME,
GTK_SYSTEM_SETTING_FONT_CONFIG,
GTK_SYSTEM_SETTING_DISPLAY,
GTK_SYSTEM_SETTING_ICON_THEME
GTK_SYSTEM_SETTING_ICON_THEME,
GTK_SYSTEM_SETTING_COLOR_SCHEME,
} GtkSystemSetting;
/**
@@ -1880,4 +1881,22 @@ typedef enum {
GTK_FONT_RENDERING_MANUAL,
} GtkFontRendering;
/**
* GtkColorScheme:
* @GTK_COLOR_SCHEME_LIGHT: A light color scheme is used
* @GTK_COLOR_SCHEME_DARK: A dark color scheme is used
*
* Values for the [property@Gtk.Settings:gtk-color-scheme] property
* that indicate what color scheme is used.
*
* This information can be used inside CSS to select appropriate colors
* with the light-dark() function.
*
* Since: 4.16
*/
typedef enum {
GTK_COLOR_SCHEME_LIGHT,
GTK_COLOR_SCHEME_DARK
} GtkColorScheme;
G_END_DECLS

View File

@@ -203,6 +203,7 @@ enum {
PROP_KEYNAV_USE_CARET,
PROP_OVERLAY_SCROLLING,
PROP_FONT_RENDERING,
PROP_COLOR_SCHEME,
NUM_PROPERTIES
};
@@ -977,6 +978,24 @@ gtk_settings_class_init (GtkSettingsClass *class)
GTK_FONT_RENDERING_AUTOMATIC,
GTK_PARAM_READWRITE);
/**
* GtkSettings:gtk-color-scheme:
*
* The used color scheme.
*
* GTK can not determine this on its own and relies on application or
* platform libraries to set this property appropriately.
*
* The used color scheme can affect color selection inside CSS with
* the light-dark() function.
*
* Since: 4.16
*/
pspecs[PROP_COLOR_SCHEME] = g_param_spec_enum ("gtk-color-scheme", NULL, NULL,
GTK_TYPE_COLOR_SCHEME,
GTK_COLOR_SCHEME_LIGHT,
GTK_PARAM_READWRITE);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, pspecs);
}
@@ -1292,6 +1311,8 @@ gtk_settings_notify (GObject *object,
case PROP_CURSOR_THEME_SIZE:
settings_update_cursor_theme (settings);
break;
case PROP_COLOR_SCHEME:
gtk_system_setting_changed (settings->display, GTK_SYSTEM_SETTING_COLOR_SCHEME);
default:
break;
}