Skip to content

Commit

Permalink
StyleSwitcher: Let system-synced color preference available on any pl…
Browse files Browse the repository at this point in the history
…atforms (#196)
  • Loading branch information
ryonakano committed Jun 4, 2023
1 parent 22e295c commit 7eb1bf0
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions src/StyleSwitcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,20 @@ public class StyleSwitcher : Gtk.Box {

construct {
gtk_settings = Gtk.Settings.get_default ();
granite_settings = Granite.Settings.get_default ();

var style_label = new Gtk.Label (_("Style:")) {
halign = Gtk.Align.START
};

var buttons_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);

light_style_button = new StyleButton ("display-brightness-symbolic", _("Light"));
buttons_box.append (light_style_button);

dark_style_button = new StyleButton ("weather-clear-night-symbolic", _("Dark"), light_style_button);
buttons_box.append (dark_style_button);
system_style_button = new StyleButton ("emblem-system-symbolic", _("System"), light_style_button);

if (Application.IS_ON_PANTHEON) {
granite_settings = Granite.Settings.get_default ();

system_style_button = new StyleButton ("emblem-system-symbolic", _("System"), light_style_button);
buttons_box.append (system_style_button);

granite_settings.notify["prefers-color-scheme"].connect (() => {
construct_app_style ();
});

system_style_button.toggled.connect (() => {
set_app_style (
granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK,
true
);
});
}
var buttons_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
buttons_box.append (light_style_button);
buttons_box.append (dark_style_button);
buttons_box.append (system_style_button);

light_style_button.toggled.connect (() => {
set_app_style (false, false);
Expand All @@ -61,6 +45,17 @@ public class StyleSwitcher : Gtk.Box {
set_app_style (true, false);
});

system_style_button.toggled.connect (() => {
set_app_style (
granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK,
true
);
});

granite_settings.notify["prefers-color-scheme"].connect (() => {
construct_app_style ();
});

construct_app_style ();

append (style_label);
Expand All @@ -74,10 +69,6 @@ public class StyleSwitcher : Gtk.Box {
}

private void construct_app_style () {
if (!Application.IS_ON_PANTHEON) {
Application.settings.set_boolean ("is-follow-system-style", false);
}

if (Application.settings.get_boolean ("is-follow-system-style")) {
set_app_style (granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK, true);
system_style_button.active = true;
Expand Down

0 comments on commit 7eb1bf0

Please sign in to comment.