Add a dark theme toggle to GSettings
This commit is contained in:
parent
fa034a1a6a
commit
9f1041988d
23
fiv.c
23
fiv.c
|
@ -1099,6 +1099,16 @@ show_help_shortcuts(void)
|
||||||
gtk_widget_show(window);
|
gtk_widget_show(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
toggle_sunlight(void)
|
||||||
|
{
|
||||||
|
GtkSettings *settings = gtk_settings_get_default();
|
||||||
|
const char *property = "gtk-application-prefer-dark-theme";
|
||||||
|
gboolean set = FALSE;
|
||||||
|
g_object_get(settings, property, &set, NULL);
|
||||||
|
g_object_set(settings, property, !set, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
// Cursor keys, e.g., simply cannot be bound through accelerators
|
// Cursor keys, e.g., simply cannot be bound through accelerators
|
||||||
// (and GtkWidget::keynav-failed would arguably be an awful solution).
|
// (and GtkWidget::keynav-failed would arguably be an awful solution).
|
||||||
//
|
//
|
||||||
|
@ -1116,13 +1126,8 @@ on_key_press(G_GNUC_UNUSED GtkWidget *widget, GdkEventKey *event,
|
||||||
{
|
{
|
||||||
switch (event->state & gtk_accelerator_get_default_mod_mask()) {
|
switch (event->state & gtk_accelerator_get_default_mod_mask()) {
|
||||||
case GDK_MOD1_MASK | GDK_SHIFT_MASK:
|
case GDK_MOD1_MASK | GDK_SHIFT_MASK:
|
||||||
if (event->keyval == GDK_KEY_D) {
|
if (event->keyval == GDK_KEY_D)
|
||||||
GtkSettings *settings = gtk_settings_get_default();
|
toggle_sunlight();
|
||||||
const char *property = "gtk-application-prefer-dark-theme";
|
|
||||||
gboolean set = FALSE;
|
|
||||||
g_object_get(settings, property, &set, NULL);
|
|
||||||
g_object_set(settings, property, !set, NULL);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case GDK_CONTROL_MASK:
|
case GDK_CONTROL_MASK:
|
||||||
case GDK_CONTROL_MASK | GDK_SHIFT_MASK:
|
case GDK_CONTROL_MASK | GDK_SHIFT_MASK:
|
||||||
|
@ -1907,6 +1912,10 @@ main(int argc, char *argv[])
|
||||||
gtk_icon_theme_add_resource_path(
|
gtk_icon_theme_add_resource_path(
|
||||||
gtk_icon_theme_get_default(), "/org/gnome/design/IconLibrary/");
|
gtk_icon_theme_get_default(), "/org/gnome/design/IconLibrary/");
|
||||||
|
|
||||||
|
GSettings *settings = g_settings_new(PROJECT_NS PROJECT_NAME);
|
||||||
|
if (g_settings_get_boolean(settings, "dark-theme"))
|
||||||
|
toggle_sunlight();
|
||||||
|
|
||||||
GtkCssProvider *provider = gtk_css_provider_new();
|
GtkCssProvider *provider = gtk_css_provider_new();
|
||||||
gtk_css_provider_load_from_data(
|
gtk_css_provider_load_from_data(
|
||||||
provider, stylesheet, sizeof stylesheet - 1, NULL);
|
provider, stylesheet, sizeof stylesheet - 1, NULL);
|
||||||
|
|
|
@ -10,5 +10,9 @@
|
||||||
double buffering.
|
double buffering.
|
||||||
</description>
|
</description>
|
||||||
</key>
|
</key>
|
||||||
|
<key name='dark-theme' type='b'>
|
||||||
|
<default>false</default>
|
||||||
|
<summary>Use a dark theme variant</summary>
|
||||||
|
</key>
|
||||||
</schema>
|
</schema>
|
||||||
</schemalist>
|
</schemalist>
|
||||||
|
|
Loading…
Reference in New Issue