From 5227102169d010c041ce1c4aabc06091aa713349 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 2 Sep 2023 19:53:09 +0900 Subject: [PATCH 1/5] Expose prefer dark schedule settings --- src/AccountsService.vala | 15 +++++++++---- src/Backends/InterfaceSettings.vala | 35 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/AccountsService.vala b/src/AccountsService.vala index f7405b3d..7da54317 100644 --- a/src/AccountsService.vala +++ b/src/AccountsService.vala @@ -20,6 +20,11 @@ [DBus (name = "io.elementary.SettingsDaemon.AccountsService")] public interface SettingsDaemon.AccountsService : Object { + public struct Coordinates { + public double latitude; + public double longitude; + } + /* Keyboard */ public struct KeyboardLayout { public string backend; @@ -63,11 +68,13 @@ public interface 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; } diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 6053d5e2..d8b84890 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -33,11 +33,17 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { private const string FONT_NAME = "font-name"; private const string MONOSPACE_FONT_NAME = "monospace-font-name"; + private const string LAST_COORDINATES = "last-coordinates"; + private const string PREFER_DARK_SCHEDULE = "prefer-dark-schedule"; + private const string PREFER_DARK_SCHEDULE_FROM = "prefer-dark-schedule-from"; + private const string PREFER_DARK_SCHEDULE_TO = "prefer-dark-schedule-to"; + public unowned AccountsService accounts_service { get; construct; } public unowned DisplayManager.AccountsService display_manager_accounts_service { get; construct; } private GLib.Settings interface_settings; private GLib.Settings background_settings; + private GLib.Settings settings_daemon_settings; public InterfaceSettings (AccountsService accounts_service, DisplayManager.AccountsService display_manager_accounts_service) { Object ( @@ -49,6 +55,7 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { construct { interface_settings = new GLib.Settings ("org.gnome.desktop.interface"); background_settings = new GLib.Settings ("org.gnome.desktop.background"); + settings_daemon_settings = new GLib.Settings ("io.elementary.settings-daemon.prefers-color-scheme"); sync_gsettings_to_accountsservice (); @@ -77,6 +84,15 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { sync_background_to_greeter (); } }); + + settings_daemon_settings.changed.connect ((key) => { + if (key == LAST_COORDINATES || + key == PREFER_DARK_SCHEDULE || + key == PREFER_DARK_SCHEDULE_FROM || + key == PREFER_DARK_SCHEDULE_TO) { + sync_gsettings_to_accountsservice (); + } + }); } private void sync_gsettings_to_accountsservice () { @@ -93,6 +109,25 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { accounts_service.document_font_name = interface_settings.get_string (DOCUMENT_FONT_NAME); accounts_service.font_name = interface_settings.get_string (FONT_NAME); accounts_service.monospace_font_name = interface_settings.get_string (MONOSPACE_FONT_NAME); + + var last_coordinates_value = settings_daemon_settings.get_value (LAST_COORDINATES); + if (last_coordinates_value.is_of_type (GLib.VariantType.TUPLE)) { + double latitude; + double longitude; + + last_coordinates_value.@get ("(dd)", out latitude, out longitude); + + accounts_service.prefer_dark_last_coordinates = AccountsService.Coordinates () { + latitude = latitude, + longitude = longitude + }; + } else { + warning ("Unknown prefer dark coordinates type, unable to save to AccountsService"); + } + + accounts_service.prefer_dark_schedule = settings_daemon_settings.get_enum (PREFER_DARK_SCHEDULE); + accounts_service.prefer_dark_schedule_from = settings_daemon_settings.get_double (PREFER_DARK_SCHEDULE_FROM); + accounts_service.prefer_dark_schedule_to = settings_daemon_settings.get_double (PREFER_DARK_SCHEDULE_TO); } private void sync_background_to_greeter () { From 68ea468d6686e4d4f1e61655a71bfdae44a970a1 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sun, 22 Oct 2023 11:23:08 +0900 Subject: [PATCH 2/5] Update xml file --- ...ementary.SettingsDaemon.AccountsService.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/data/io.elementary.SettingsDaemon.AccountsService.xml b/data/io.elementary.SettingsDaemon.AccountsService.xml index efe8372f..ca3124a3 100644 --- a/data/io.elementary.SettingsDaemon.AccountsService.xml +++ b/data/io.elementary.SettingsDaemon.AccountsService.xml @@ -151,5 +151,23 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file From 471a11346f22bcc991549b78cc7abb9c4de5686c Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 27 Jan 2024 21:07:30 +0900 Subject: [PATCH 3/5] Fix lint --- src/Backends/InterfaceSettings.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index d8b84890..78503e57 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -88,10 +88,10 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { settings_daemon_settings.changed.connect ((key) => { if (key == LAST_COORDINATES || key == PREFER_DARK_SCHEDULE || - key == PREFER_DARK_SCHEDULE_FROM || + key == PREFER_DARK_SCHEDULE_FROM || key == PREFER_DARK_SCHEDULE_TO) { sync_gsettings_to_accountsservice (); - } + } }); } From 8c3dd080ebb726d8cd57fc8c57a88298a3b17dfe Mon Sep 17 00:00:00 2001 From: lenemter Date: Tue, 30 Jan 2024 18:18:04 +0900 Subject: [PATCH 4/5] Reuse last coordinates --- src/AccountsService.vala | 5 ++--- src/Backends/InterfaceSettings.vala | 2 +- src/Backends/NightLightSettings.vala | 18 ------------------ 3 files changed, 3 insertions(+), 22 deletions(-) diff --git a/src/AccountsService.vala b/src/AccountsService.vala index 90afc96f..7e06e06b 100644 --- a/src/AccountsService.vala +++ b/src/AccountsService.vala @@ -70,15 +70,14 @@ public interface 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; } diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index b318387a..a2e06444 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -122,7 +122,7 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { last_coordinates_value.@get ("(dd)", out latitude, out longitude); - accounts_service.prefer_dark_last_coordinates = AccountsService.Coordinates () { + accounts_service.last_coordinates = AccountsService.Coordinates () { latitude = latitude, longitude = longitude }; diff --git a/src/Backends/NightLightSettings.vala b/src/Backends/NightLightSettings.vala index b3d30d71..0110fd7a 100644 --- a/src/Backends/NightLightSettings.vala +++ b/src/Backends/NightLightSettings.vala @@ -6,7 +6,6 @@ public class SettingsDaemon.Backends.NightLightSettings : GLib.Object { private const string NIGHT_LIGHT_SCHEMA = "org.gnome.settings-daemon.plugins.color"; private const string NIGHT_LIGHT_ENABLED = "night-light-enabled"; - private const string NIGHT_LIGHT_LAST_COORDINATES = "night-light-last-coordinates"; private const string NIGHT_LIGHT_SCHEDULE_AUTOMATIC = "night-light-schedule-automatic"; private const string NIGHT_LIGHT_SCHEDULE_FROM = "night-light-schedule-from"; private const string NIGHT_LIGHT_SCHEDULE_TO = "night-light-schedule-to"; @@ -33,7 +32,6 @@ night_light_settings.changed.connect ((key) => { if (key == NIGHT_LIGHT_ENABLED || - key == NIGHT_LIGHT_LAST_COORDINATES || key == NIGHT_LIGHT_SCHEDULE_AUTOMATIC || key == NIGHT_LIGHT_SCHEDULE_FROM || key == NIGHT_LIGHT_SCHEDULE_TO || @@ -45,22 +43,6 @@ private void sync_gsettings_to_accountsservice () { accounts_service.night_light_enabled = night_light_settings.get_boolean (NIGHT_LIGHT_ENABLED); - - var last_coordinates_value = night_light_settings.get_value (NIGHT_LIGHT_LAST_COORDINATES); - if (last_coordinates_value.is_of_type (GLib.VariantType.TUPLE)) { - double latitude; - double longitude; - - last_coordinates_value.@get ("(dd)", out latitude, out longitude); - - accounts_service.night_light_last_coordinates = AccountsService.Coordinates () { - latitude = latitude, - longitude = longitude - }; - } else { - warning ("Unknown night light coordinates type, unable to save to AccountsService"); - } - accounts_service.night_light_schedule_automatic = night_light_settings.get_boolean (NIGHT_LIGHT_SCHEDULE_AUTOMATIC); accounts_service.night_light_schedule_from = night_light_settings.get_double (NIGHT_LIGHT_SCHEDULE_FROM); accounts_service.night_light_schedule_to = night_light_settings.get_double (NIGHT_LIGHT_SCHEDULE_TO); From beb5f230ae1ae639348fabfaa6a071ec043fa427 Mon Sep 17 00:00:00 2001 From: lenemter Date: Wed, 31 Jan 2024 07:31:14 +0900 Subject: [PATCH 5/5] Fix xml file --- ...mentary.SettingsDaemon.AccountsService.xml | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/data/io.elementary.SettingsDaemon.AccountsService.xml b/data/io.elementary.SettingsDaemon.AccountsService.xml index 6fed1761..9bf2b681 100644 --- a/data/io.elementary.SettingsDaemon.AccountsService.xml +++ b/data/io.elementary.SettingsDaemon.AccountsService.xml @@ -132,46 +132,42 @@ - - - + - - + + - - + + - + - + - - - - - - - - + + - - + + - + - + + + + + \ No newline at end of file