From f2d7c40117da5d7b4b9e7b9bd69627620b970a86 Mon Sep 17 00:00:00 2001 From: fs3o5 Date: Sun, 3 Jan 2021 01:45:33 +0100 Subject: [PATCH 1/2] use theme --- src/Cards/BaseCard.vala | 3 ++ src/Cards/UserCard.vala | 12 ++++++++ src/MainWindow.vala | 42 ++++++++++++++++++++++++++ src/PantheonAccountsServicePlugin.vala | 6 ++++ 4 files changed, 63 insertions(+) diff --git a/src/Cards/BaseCard.vala b/src/Cards/BaseCard.vala index 01445d2da..d1279315e 100644 --- a/src/Cards/BaseCard.vala +++ b/src/Cards/BaseCard.vala @@ -28,6 +28,9 @@ public abstract class Greeter.BaseCard : Gtk.Revealer { public bool need_password { get; set; default = false; } public bool use_fingerprint { get; set; default = false; } + public int prefers_color_scheme { get; set; default = 0; } + public int prefers_accent_color { get; set; default = 0; } + static construct { css_provider = new Gtk.CssProvider (); css_provider.load_from_resource ("/io/elementary/greeter/Card.css"); diff --git a/src/Cards/UserCard.vala b/src/Cards/UserCard.vala index 11ee86adc..226d522e1 100644 --- a/src/Cards/UserCard.vala +++ b/src/Cards/UserCard.vala @@ -252,6 +252,7 @@ public class Greeter.UserCard : Greeter.BaseCard { unowned string? act_path = act_user.get_object_path (); if (act_path != null) { try { + greeter_act = GLib.Bus.get_proxy_sync (GLib.BusType.SYSTEM, "org.freedesktop.Accounts", act_path, @@ -261,12 +262,16 @@ public class Greeter.UserCard : Greeter.BaseCard { "org.freedesktop.Accounts", act_path, GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES); + is_24h = greeter_act.time_format != "12h"; sleep_inactive_ac_timeout = greeter_act.sleep_inactive_ac_timeout; sleep_inactive_ac_type = greeter_act.sleep_inactive_ac_type; sleep_inactive_battery_timeout = greeter_act.sleep_inactive_battery_timeout; sleep_inactive_battery_type = greeter_act.sleep_inactive_battery_type; + prefers_color_scheme = greeter_act.prefers_color_scheme; + prefers_accent_color = greeter_act.prefers_accent_color; ((GLib.DBusProxy) greeter_act).g_properties_changed.connect ((changed_properties, invalidated_properties) => { + string time_format; changed_properties.lookup ("TimeFormat", "s", out time_format); is_24h = time_format != "12h"; @@ -275,6 +280,13 @@ public class Greeter.UserCard : Greeter.BaseCard { changed_properties.lookup ("SleepInactiveACType", "i", out _sleep_inactive_ac_type); changed_properties.lookup ("SleepInactiveBatteryTimeout", "i", out _sleep_inactive_battery_timeout); changed_properties.lookup ("SleepInactiveBatteryType", "i", out _sleep_inactive_battery_type); + + int prefers_color_scheme_out; + changed_properties.lookup ("PrefersColorScheme", "i", out prefers_color_scheme_out); + prefers_color_scheme = prefers_color_scheme_out; + int prefers_accent_color_out; + changed_properties.lookup ("PrefersColorScheme", "i", out prefers_accent_color_out); + prefers_accent_color = prefers_accent_color_out; }); } catch (Error e) { critical (e.message); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index de5c0f69c..14ca73b9a 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -538,6 +538,48 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow { binding.unbind (); } + var gtksettings = Gtk.Settings.get_default (); + if (current_card.prefers_color_scheme == 1) { + gtksettings.gtk_application_prefer_dark_theme = true; + } else { + gtksettings.gtk_application_prefer_dark_theme = false; + } + switch (current_card.prefers_accent_color) { + case 1: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.strawberry"; + break; + case 2: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.orange"; + break; + case 3: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.banana"; + break; + case 4: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.lime"; + break; + case 5: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.mint"; + break; + case 6: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.blueberry"; + break; + case 7: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.grape"; + break; + case 8: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.bubblegum"; + break; + case 9: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.cocoa"; + break; + case 10: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.slate"; + break; + default: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.blueberry"; + break; + } + user_card.set_keyboard_layouts (); binding = user_card.bind_property ("is-24h", datetime_widget, "is-24h", GLib.BindingFlags.SYNC_CREATE); diff --git a/src/PantheonAccountsServicePlugin.vala b/src/PantheonAccountsServicePlugin.vala index ea783fa76..e2dd1b8dd 100644 --- a/src/PantheonAccountsServicePlugin.vala +++ b/src/PantheonAccountsServicePlugin.vala @@ -9,6 +9,12 @@ interface Pantheon.AccountsService : Object { public abstract int sleep_inactive_battery_timeout { get; set; } public abstract int sleep_inactive_battery_type { get; set; } + + [DBus (name = "PrefersColorScheme")] + public abstract int prefers_color_scheme { get; set; } + + [DBus (name = "PrefersAccentColor")] + public abstract int prefers_accent_color { get; set; } } [DBus (name = "io.elementary.SettingsDaemon.AccountsService")] From bbd4db41262cc4989f4df85ff97da2735a98bb72 Mon Sep 17 00:00:00 2001 From: fs3o5 Date: Sun, 3 Jan 2021 02:23:53 +0100 Subject: [PATCH 2/2] use theme --- src/MainWindow.vala | 87 ++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 14ca73b9a..f563b276a 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -304,6 +304,7 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow { if (current_card != null) { current_card.grab_focus (); } + user_style (); } private void maximize_window () { @@ -538,47 +539,7 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow { binding.unbind (); } - var gtksettings = Gtk.Settings.get_default (); - if (current_card.prefers_color_scheme == 1) { - gtksettings.gtk_application_prefer_dark_theme = true; - } else { - gtksettings.gtk_application_prefer_dark_theme = false; - } - switch (current_card.prefers_accent_color) { - case 1: - gtksettings.gtk_theme_name = "io.elementary.stylesheet.strawberry"; - break; - case 2: - gtksettings.gtk_theme_name = "io.elementary.stylesheet.orange"; - break; - case 3: - gtksettings.gtk_theme_name = "io.elementary.stylesheet.banana"; - break; - case 4: - gtksettings.gtk_theme_name = "io.elementary.stylesheet.lime"; - break; - case 5: - gtksettings.gtk_theme_name = "io.elementary.stylesheet.mint"; - break; - case 6: - gtksettings.gtk_theme_name = "io.elementary.stylesheet.blueberry"; - break; - case 7: - gtksettings.gtk_theme_name = "io.elementary.stylesheet.grape"; - break; - case 8: - gtksettings.gtk_theme_name = "io.elementary.stylesheet.bubblegum"; - break; - case 9: - gtksettings.gtk_theme_name = "io.elementary.stylesheet.cocoa"; - break; - case 10: - gtksettings.gtk_theme_name = "io.elementary.stylesheet.slate"; - break; - default: - gtksettings.gtk_theme_name = "io.elementary.stylesheet.blueberry"; - break; - } + user_style (); user_card.set_keyboard_layouts (); @@ -667,4 +628,48 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow { switch_to_card (next_card); } } + + private void user_style () { + var gtksettings = Gtk.Settings.get_default (); + if (current_card.prefers_color_scheme == 1) { + gtksettings.gtk_application_prefer_dark_theme = true; + } else { + gtksettings.gtk_application_prefer_dark_theme = false; + } + switch (current_card.prefers_accent_color) { + case 1: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.strawberry"; + break; + case 2: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.orange"; + break; + case 3: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.banana"; + break; + case 4: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.lime"; + break; + case 5: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.mint"; + break; + case 6: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.blueberry"; + break; + case 7: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.grape"; + break; + case 8: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.bubblegum"; + break; + case 9: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.cocoa"; + break; + case 10: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.slate"; + break; + default: + gtksettings.gtk_theme_name = "io.elementary.stylesheet.blueberry"; + break; + } + } }