From 155ccb5e402104370958ffdfd667b25767b2c767 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 2 Sep 2023 19:47:42 +0900 Subject: [PATCH 1/7] Support dark mode --- src/Application.vala | 27 ++++++++- src/Cards/UserCard.vala | 76 +++++++++++++++++++++----- src/PantheonAccountsServicePlugin.vala | 16 ++++-- 3 files changed, 99 insertions(+), 20 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 9695b4532..dc9ff6b28 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -29,13 +29,15 @@ public int main (string[] args) { // overrides GLib.Environment.set_variable ("XDG_CURRENT_DESKTOP", "Pantheon", true); - var settings_daemon = new Greeter.SettingsDaemon (); - settings_daemon.start (); + var gnome_settings_daemon = new Greeter.SettingsDaemon (); + gnome_settings_daemon.start (); Gtk.init (ref args); Greeter.SubprocessSupervisor compositor; + Greeter.SubprocessSupervisor portals; Greeter.SubprocessSupervisor wingpanel; + Greeter.SubprocessSupervisor settings_daemon; try { compositor = new Greeter.SubprocessSupervisor ({"io.elementary.greeter-compositor"}); @@ -46,12 +48,33 @@ public int main (string[] args) { var window = new Greeter.MainWindow (); window.show_all (); + try { + portals = new Greeter.SubprocessSupervisor ({"/usr/libexec/xdg-desktop-portal"}); + } catch (Error e) { + critical (e.message); + } + + unowned var gtk_settings = Gtk.Settings.get_default (); + unowned var granite_settings = Granite.Settings.get_default (); + + gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == DARK; + + granite_settings.notify["prefers-color-scheme"].connect (() => { + gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == DARK; + }); + try { wingpanel = new Greeter.SubprocessSupervisor ({"io.elementary.wingpanel", "-g"}); } catch (Error e) { critical (e.message); } + try { + settings_daemon = new Greeter.SubprocessSupervisor ({"io.elementary.settings-daemon"}); + } catch (Error e) { + critical (e.message); + } + Gtk.main (); return 0; diff --git a/src/Cards/UserCard.vala b/src/Cards/UserCard.vala index eb05105cb..e51b55c45 100644 --- a/src/Cards/UserCard.vala +++ b/src/Cards/UserCard.vala @@ -21,10 +21,14 @@ public class Greeter.UserCard : Greeter.BaseCard { public int sleep_inactive_battery_timeout { get; set; default = 1200; } public int sleep_inactive_battery_type { get; set; default = 1; } + private Act.User lightdm_user_act; private Act.User act_user; + private Pantheon.AccountsService lightdm_act; private Pantheon.AccountsService greeter_act; private Pantheon.SettingsDaemon.AccountsService settings_act; + private ulong dark_mode_sync_id = 0; + private Gtk.GestureMultiPress click_gesture; private Gtk.Revealer form_revealer; private Gtk.Stack login_stack; @@ -209,12 +213,16 @@ public class Greeter.UserCard : Greeter.BaseCard { child = card_overlay; + lightdm_user_act = Act.UserManager.get_default ().get_user (Environment.get_user_name ()); + act_user = Act.UserManager.get_default ().get_user (lightdm_user.name); act_user.bind_property ("locked", username_label, "sensitive", INVERT_BOOLEAN); act_user.bind_property ("locked", session_button, "visible", INVERT_BOOLEAN); act_user.notify["is-loaded"].connect (on_act_user_loaded); - on_act_user_loaded (); + if (act_user.is_loaded) { + on_act_user_loaded (); + } card_overlay.focus.connect ((direction) => { if (direction == LEFT) { @@ -244,6 +252,11 @@ public class Greeter.UserCard : Greeter.BaseCard { notify["show-input"].connect (() => { update_collapsed_class (); + + // Stop settings sync, that starts in `set_settings ()` + if (!show_input) { + stop_settings_sync (); + } }); notify["child-revealed"].connect (() => { @@ -352,18 +365,6 @@ public class Greeter.UserCard : Greeter.BaseCard { 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; - - ((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"; - - changed_properties.lookup ("PrefersAccentColor", "i", out _prefers_accent_color); - changed_properties.lookup ("SleepInactiveACTimeout", "i", out _sleep_inactive_ac_timeout); - 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); - }); } catch (Error e) { critical (e.message); } @@ -414,11 +415,13 @@ public class Greeter.UserCard : Greeter.BaseCard { return; } + update_style (); set_keyboard_layouts (); set_mouse_touchpad_settings (); set_interface_settings (); set_night_light_settings (); - update_style (); + + start_settings_sync (); } private void set_keyboard_layouts () { @@ -475,6 +478,17 @@ public class Greeter.UserCard : Greeter.BaseCard { interface_settings.set_value ("document-font-name", settings_act.document_font_name); interface_settings.set_value ("font-name", settings_act.font_name); interface_settings.set_value ("monospace-font-name", settings_act.monospace_font_name); + + var settings_daemon_settings = new GLib.Settings ("io.elementary.settings-daemon.prefers-color-scheme"); + + var latitude = new Variant.double (settings_act.prefer_dark_last_coordinates.latitude); + var longitude = new Variant.double (settings_act.prefer_dark_last_coordinates.longitude); + var coordinates = new Variant.tuple ({latitude, longitude}); + settings_daemon_settings.set_value ("last-coordinates", coordinates); + + settings_daemon_settings.set_enum ("prefer-dark-schedule", settings_act.prefer_dark_schedule); + settings_daemon_settings.set_value ("prefer-dark-schedule-from", settings_act.prefer_dark_schedule_from); + settings_daemon_settings.set_value ("prefer-dark-schedule-to", settings_act.prefer_dark_schedule_to); } private void set_night_light_settings () { @@ -495,6 +509,40 @@ public class Greeter.UserCard : Greeter.BaseCard { private void update_style () { var interface_settings = new GLib.Settings ("org.gnome.desktop.interface"); interface_settings.set_value ("gtk-theme", "io.elementary.stylesheet." + accent_to_string (prefers_accent_color)); + + unowned string? lightdm_act_path = lightdm_user_act.get_object_path (); + if (lightdm_act_path != null) { + try { + lightdm_act = Bus.get_proxy_sync ( + SYSTEM, + "org.freedesktop.Accounts", + lightdm_act_path, + GET_INVALIDATED_PROPERTIES + ); + + warning ("Set color_scheme %d for user %s", greeter_act.prefers_color_scheme, lightdm_user.name); + lightdm_act.prefers_color_scheme = greeter_act.prefers_color_scheme; + } catch (Error e) { + critical (e.message); + } + } + } + + private void start_settings_sync () { + debug ("Started settings sync for user %s", lightdm_user.name); + + dark_mode_sync_id = ((DBusProxy) lightdm_act).g_properties_changed.connect ((changed_properties, invalidated_properties) => { + warning ("OwO"); + int prefers_color_scheme; + changed_properties.lookup ("PrefersColorScheme", "i", out prefers_color_scheme); + greeter_act.prefers_color_scheme = prefers_color_scheme; + }); + } + + private void stop_settings_sync () { + debug ("Stopped settings sync for user %s", lightdm_user.name); + + lightdm_act.disconnect (dark_mode_sync_id); } public override void wrong_credentials () { diff --git a/src/PantheonAccountsServicePlugin.vala b/src/PantheonAccountsServicePlugin.vala index c390edbbe..9050288a6 100644 --- a/src/PantheonAccountsServicePlugin.vala +++ b/src/PantheonAccountsServicePlugin.vala @@ -2,6 +2,7 @@ interface Pantheon.AccountsService : Object { public abstract string time_format { owned get; set; } + public abstract int prefers_color_scheme { get; set; } public abstract int prefers_accent_color { get; set; } [DBus (name = "SleepInactiveACTimeout")] @@ -15,6 +16,11 @@ interface Pantheon.AccountsService : Object { [DBus (name = "io.elementary.SettingsDaemon.AccountsService")] interface Pantheon.SettingsDaemon.AccountsService : Object { + public struct Coordinates { + public double latitude; + public double longitude; + } + /* Keyboard */ public struct KeyboardLayout { public string backend; @@ -58,11 +64,13 @@ interface Pantheon.SettingsDaemon.AccountsService : Object { public abstract string font_name { owned get; set; } public abstract string monospace_font_name { owned get; set; } + /* Prefer Dark Schedule (part of interface settings)*/ + public abstract Coordinates prefer_dark_last_coordinates { get; set; } + public abstract int prefer_dark_schedule { get; set; } + public abstract double prefer_dark_schedule_from { get; set; } + public abstract double prefer_dark_schedule_to { get; set; } + /* Night Light */ - public struct Coordinates { - public double latitude; - public double longitude; - } public abstract bool night_light_enabled { get; set; } public abstract Coordinates night_light_last_coordinates { get; set; } From bb951470b76d3094516e14ce2546f3aeb72246fd Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 27 Jan 2024 21:04:08 +0900 Subject: [PATCH 2/7] Avoid loading lighdm_act many times --- src/Cards/UserCard.vala | 102 +++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 43 deletions(-) diff --git a/src/Cards/UserCard.vala b/src/Cards/UserCard.vala index e51b55c45..2341f24b4 100644 --- a/src/Cards/UserCard.vala +++ b/src/Cards/UserCard.vala @@ -6,6 +6,9 @@ */ public class Greeter.UserCard : Greeter.BaseCard { + private static Act.User lightdm_user_act; + private static Pantheon.AccountsService lightdm_act; + public signal void go_left (); public signal void go_right (); public signal void focus_requested (); @@ -21,9 +24,7 @@ public class Greeter.UserCard : Greeter.BaseCard { public int sleep_inactive_battery_timeout { get; set; default = 1200; } public int sleep_inactive_battery_type { get; set; default = 1; } - private Act.User lightdm_user_act; private Act.User act_user; - private Pantheon.AccountsService lightdm_act; private Pantheon.AccountsService greeter_act; private Pantheon.SettingsDaemon.AccountsService settings_act; @@ -213,15 +214,19 @@ public class Greeter.UserCard : Greeter.BaseCard { child = card_overlay; - lightdm_user_act = Act.UserManager.get_default ().get_user (Environment.get_user_name ()); - act_user = Act.UserManager.get_default ().get_user (lightdm_user.name); act_user.bind_property ("locked", username_label, "sensitive", INVERT_BOOLEAN); act_user.bind_property ("locked", session_button, "visible", INVERT_BOOLEAN); - act_user.notify["is-loaded"].connect (on_act_user_loaded); - if (act_user.is_loaded) { + if (lightdm_user_act == null) { + lightdm_user_act = Act.UserManager.get_default ().get_user (Environment.get_user_name ()); + } + + if (act_user.is_loaded && lightdm_user_act.is_loaded) { on_act_user_loaded (); + } else { + act_user.notify["is-loaded"].connect (on_act_user_loaded); + lightdm_user_act.notify["is-loaded"].connect (on_act_user_loaded); } card_overlay.focus.connect ((direction) => { @@ -338,35 +343,59 @@ public class Greeter.UserCard : Greeter.BaseCard { } private void on_act_user_loaded () { - if (!act_user.is_loaded) { + if (!act_user.is_loaded || !lightdm_user_act.is_loaded) { return; } unowned string? act_path = act_user.get_object_path (); - if (act_path != null) { - try { - greeter_act = Bus.get_proxy_sync ( - SYSTEM, - "org.freedesktop.Accounts", - act_path, - GET_INVALIDATED_PROPERTIES - ); + if (act_path == null) { + critical ("Couldn't load user act"); + return; + } - settings_act = Bus.get_proxy_sync ( + try { + greeter_act = Bus.get_proxy_sync ( + SYSTEM, + "org.freedesktop.Accounts", + act_path, + GET_INVALIDATED_PROPERTIES + ); + + settings_act = Bus.get_proxy_sync ( + SYSTEM, + "org.freedesktop.Accounts", + act_path, + GET_INVALIDATED_PROPERTIES + ); + + is_24h = greeter_act.time_format != "12h"; + prefers_accent_color = greeter_act.prefers_accent_color; + 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; + } catch (Error e) { + critical (e.message); + return; + } + + if (lightdm_act == null) { + unowned string? lightdm_act_path = lightdm_user_act.get_object_path (); + if (lightdm_act_path == null) { + critical ("Couldn't load lighdm act"); + return; + } + + try { + lightdm_act = Bus.get_proxy_sync ( SYSTEM, "org.freedesktop.Accounts", - act_path, + lightdm_act_path, GET_INVALIDATED_PROPERTIES ); - - is_24h = greeter_act.time_format != "12h"; - prefers_accent_color = greeter_act.prefers_accent_color; - 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; } catch (Error e) { critical (e.message); + return; } } @@ -410,7 +439,11 @@ public class Greeter.UserCard : Greeter.BaseCard { } public void set_settings () { - if (!act_user.is_loaded) { + if (!show_input) { + return; + } + + if (!act_user.is_loaded || !lightdm_user_act.is_loaded) { needs_settings_set = true; return; } @@ -509,30 +542,13 @@ public class Greeter.UserCard : Greeter.BaseCard { private void update_style () { var interface_settings = new GLib.Settings ("org.gnome.desktop.interface"); interface_settings.set_value ("gtk-theme", "io.elementary.stylesheet." + accent_to_string (prefers_accent_color)); - - unowned string? lightdm_act_path = lightdm_user_act.get_object_path (); - if (lightdm_act_path != null) { - try { - lightdm_act = Bus.get_proxy_sync ( - SYSTEM, - "org.freedesktop.Accounts", - lightdm_act_path, - GET_INVALIDATED_PROPERTIES - ); - - warning ("Set color_scheme %d for user %s", greeter_act.prefers_color_scheme, lightdm_user.name); - lightdm_act.prefers_color_scheme = greeter_act.prefers_color_scheme; - } catch (Error e) { - critical (e.message); - } - } + lightdm_act.prefers_color_scheme = greeter_act.prefers_color_scheme; } private void start_settings_sync () { debug ("Started settings sync for user %s", lightdm_user.name); dark_mode_sync_id = ((DBusProxy) lightdm_act).g_properties_changed.connect ((changed_properties, invalidated_properties) => { - warning ("OwO"); int prefers_color_scheme; changed_properties.lookup ("PrefersColorScheme", "i", out prefers_color_scheme); greeter_act.prefers_color_scheme = prefers_color_scheme; From dada4a6ec866fedcd641ddf602a0413bf3166b11 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 27 Jan 2024 21:05:23 +0900 Subject: [PATCH 3/7] Fix lint --- src/Cards/UserCard.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cards/UserCard.vala b/src/Cards/UserCard.vala index 2341f24b4..3ad9d3668 100644 --- a/src/Cards/UserCard.vala +++ b/src/Cards/UserCard.vala @@ -385,7 +385,7 @@ public class Greeter.UserCard : Greeter.BaseCard { critical ("Couldn't load lighdm act"); return; } - + try { lightdm_act = Bus.get_proxy_sync ( SYSTEM, From b01ac4b6aa80a07f527d2b5136c6a7327cdea5ac Mon Sep 17 00:00:00 2001 From: lenemter Date: Tue, 30 Jan 2024 18:22:21 +0900 Subject: [PATCH 4/7] Simplify last coordinates --- src/Cards/UserCard.vala | 8 ++++---- src/PantheonAccountsServicePlugin.vala | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Cards/UserCard.vala b/src/Cards/UserCard.vala index 7d3ab6dad..75247af07 100644 --- a/src/Cards/UserCard.vala +++ b/src/Cards/UserCard.vala @@ -514,8 +514,8 @@ public class Greeter.UserCard : Greeter.BaseCard { var settings_daemon_settings = new GLib.Settings ("io.elementary.settings-daemon.prefers-color-scheme"); - var latitude = new Variant.double (settings_act.prefer_dark_last_coordinates.latitude); - var longitude = new Variant.double (settings_act.prefer_dark_last_coordinates.longitude); + var latitude = new Variant.double (settings_act.last_coordinates.latitude); + var longitude = new Variant.double (settings_act.last_coordinates.longitude); var coordinates = new Variant.tuple ({latitude, longitude}); settings_daemon_settings.set_value ("last-coordinates", coordinates); @@ -531,8 +531,8 @@ public class Greeter.UserCard : Greeter.BaseCard { var night_light_settings = new GLib.Settings ("org.gnome.settings-daemon.plugins.color"); night_light_settings.set_value ("night-light-enabled", settings_act.night_light_enabled); - var latitude = new Variant.double (settings_act.night_light_last_coordinates.latitude); - var longitude = new Variant.double (settings_act.night_light_last_coordinates.longitude); + var latitude = new Variant.double (settings_act.last_coordinates.latitude); + var longitude = new Variant.double (settings_act.last_coordinates.longitude); var coordinates = new Variant.tuple ({latitude, longitude}); night_light_settings.set_value ("night-light-last-coordinates", coordinates); diff --git a/src/PantheonAccountsServicePlugin.vala b/src/PantheonAccountsServicePlugin.vala index b6515b8f6..46fe0e1a7 100644 --- a/src/PantheonAccountsServicePlugin.vala +++ b/src/PantheonAccountsServicePlugin.vala @@ -66,15 +66,14 @@ interface Pantheon.SettingsDaemon.AccountsService : Object { public abstract bool orientation_lock { get; set; } /* Prefer Dark Schedule (part of interface settings)*/ - public abstract Coordinates prefer_dark_last_coordinates { get; set; } + /* Last coordinates are reused for Night Light settings */ + public abstract Coordinates last_coordinates { get; set; } public abstract int prefer_dark_schedule { get; set; } public abstract double prefer_dark_schedule_from { get; set; } public abstract double prefer_dark_schedule_to { get; set; } /* Night Light */ - public abstract bool night_light_enabled { get; set; } - public abstract Coordinates night_light_last_coordinates { get; set; } public abstract bool night_light_schedule_automatic { get; set; } public abstract double night_light_schedule_from { get; set; } public abstract double night_light_schedule_to { get; set; } From 825b0a3e7ed05843a4182556efbd70819e923101 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 3 Feb 2024 19:34:16 +0900 Subject: [PATCH 5/7] Fix settings --- src/MainWindow.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 53266c34d..ca518abd4 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -556,8 +556,6 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow { binding.unbind (); } - user_card.set_settings (); - binding = user_card.bind_property ("is-24h", datetime_widget, "is-24h", GLib.BindingFlags.SYNC_CREATE); next_delta = user_cards.index (user_card); @@ -567,6 +565,8 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow { user_card.show_input = true; user_card.grab_focus (); + user_card.set_settings (); + if (index_delta != next_delta) { ((Greeter.UserCard) user_cards.peek_nth (index_delta)).show_input = false; } From 5d931381f46461d26966299afe7dd13382cf4d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 13 Feb 2024 10:06:48 -0800 Subject: [PATCH 6/7] Remove bad merge line --- src/MainWindow.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 0060bd071..344ad448e 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -545,7 +545,6 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow { } time_format_binding = user_card.bind_property ("is-24h", datetime_widget, "is-24h", GLib.BindingFlags.SYNC_CREATE); - binding = user_card.bind_property ("is-24h", datetime_widget, "is-24h", GLib.BindingFlags.SYNC_CREATE); current_card = user_card; carousel.scroll_to (user_card); From 143814f9c21b324397a7b01f2203c5b2f77a359a Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 4 Jul 2024 10:07:14 +0900 Subject: [PATCH 7/7] Fix build --- src/Application.vala | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 121f49d13..e0f495a60 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -31,10 +31,6 @@ public int main (string[] args) { Greeter.SubprocessSupervisor portals; Greeter.SubprocessSupervisor settings_daemon; - - var settings_daemon = new Greeter.SettingsDaemon (); - settings_daemon.start (); - Gtk.init (ref args); var window = new Greeter.MainWindow ();