From 6f92ef8da3ebd361869323bdf6af2ddcdffda15c Mon Sep 17 00:00:00 2001 From: lenemter Date: Fri, 30 Jun 2023 20:20:45 +0300 Subject: [PATCH 01/20] Expose interface settings --- ...mentary.SettingsDaemon.AccountsService.xml | 20 ++++++ src/AccountsService.vala | 5 ++ src/Application.vala | 3 + src/Backends/InterfaceSettings.vala | 67 +++++++++++++++++++ src/Backends/MouseSettings.vala | 2 - src/meson.build | 1 + 6 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 src/Backends/InterfaceSettings.vala diff --git a/data/io.elementary.SettingsDaemon.AccountsService.xml b/data/io.elementary.SettingsDaemon.AccountsService.xml index 20bd48c0..fc9e9dec 100644 --- a/data/io.elementary.SettingsDaemon.AccountsService.xml +++ b/data/io.elementary.SettingsDaemon.AccountsService.xml @@ -84,8 +84,28 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AccountsService.vala b/src/AccountsService.vala index d02ec508..e08f378d 100644 --- a/src/AccountsService.vala +++ b/src/AccountsService.vala @@ -48,7 +48,12 @@ public interface SettingsDaemon.AccountsService : Object { public abstract bool touchpad_tap_to_click { get; set; } public abstract bool touchpad_two_finger_scrolling { get; set; } + public abstract bool cursor_blink { get; set; } + public abstract int cursor_blink_time { get; set; } + public abstract int cursor_blink_timeout { get; set; } public abstract int cursor_size { get; set; } + public abstract bool locate_pointer { get; set; } + public abstract double text_scaling_factor { get; set; } } [DBus (name = "io.elementary.pantheon.AccountsService")] diff --git a/src/Application.vala b/src/Application.vala index a4c69228..088c2e1e 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -34,6 +34,8 @@ public class SettingsDaemon.Application : GLib.Application { private PantheonShell.Pantheon.AccountsService pantheon_accounts_service; + private Backends.InterfaceSettings interface_settings; + private Backends.KeyboardSettings keyboard_settings; private Backends.MouseSettings mouse_settings; @@ -150,6 +152,7 @@ public class SettingsDaemon.Application : GLib.Application { if (accounts_service != null) { keyboard_settings = new Backends.KeyboardSettings (accounts_service); mouse_settings = new Backends.MouseSettings (accounts_service); + interface_settings = new Backends.InterfaceSettings (accounts_service); } try { diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala new file mode 100644 index 00000000..302cdb7b --- /dev/null +++ b/src/Backends/InterfaceSettings.vala @@ -0,0 +1,67 @@ +/* + * Copyright 2021 elementary, Inc. (https://elementary.io) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * Authored by: Marius Meisenzahl + */ + +public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { + private const string CURSOR_BLINK = "cursor-blink"; + private const string CURSOR_BLINK_TIME = "cursor-blink-time"; + private const string CURSOR_BLINK_TIMEOUT = "cursor-blink-timeout"; + private const string CURSOR_SIZE = "cursor-size"; + private const string LOCATE_POINTER = "locate-pointer"; + private const string TEXT_SCALING_FACTOR = "text-scaling-factor"; + + public unowned AccountsService accounts_service { get; construct; } + + private GLib.Settings interface_settings; + + public InterfaceSettings (AccountsService accounts_service) { + Object (accounts_service: accounts_service); + } + + construct { + interface_settings = new GLib.Settings ("org.gnome.desktop.interface"); + + // in case user changes text scaling in greeter session using a11y indicator + if (accounts_service.text_scaling_factor != interface_settings.get_double (TEXT_SCALING_FACTOR)) { + interface_settings.set_value (TEXT_SCALING_FACTOR, accounts_service.text_scaling_factor); + } + + sync_gsettings_to_accountsservice (); + + interface_settings.changed.connect ((key) => { + if (key == CURSOR_BLINK || + key == CURSOR_BLINK_TIME || + key == CURSOR_BLINK_TIMEOUT || + key == CURSOR_SIZE || + key == LOCATE_POINTER || + key == TEXT_SCALING_FACTOR) { + sync_gsettings_to_accountsservice (); + } + }); + } + + private void sync_gsettings_to_accountsservice () { + accounts_service.cursor_blink = interface_settings.get_boolean (CURSOR_BLINK); + accounts_service.cursor_blink_time = interface_settings.get_int (CURSOR_BLINK_TIME); + accounts_service.cursor_blink_timeout = interface_settings.get_int (CURSOR_BLINK_TIMEOUT); + accounts_service.cursor_size = interface_settings.get_int (CURSOR_SIZE); + accounts_service.locate_pointer = interface_settings.get_boolean (LOCATE_POINTER); + accounts_service.text_scaling_factor = interface_settings.get_double (TEXT_SCALING_FACTOR); + } +} diff --git a/src/Backends/MouseSettings.vala b/src/Backends/MouseSettings.vala index 49f6b574..07a360df 100644 --- a/src/Backends/MouseSettings.vala +++ b/src/Backends/MouseSettings.vala @@ -85,7 +85,5 @@ public class SettingsDaemon.Backends.MouseSettings : GLib.Object { accounts_service.touchpad_speed = touchpad_settings.get_double ("speed"); accounts_service.touchpad_tap_to_click = touchpad_settings.get_boolean ("tap-to-click"); accounts_service.touchpad_two_finger_scrolling = touchpad_settings.get_boolean ("two-finger-scrolling-enabled"); - - accounts_service.cursor_size = interface_settings.get_int ("cursor-size"); } } diff --git a/src/meson.build b/src/meson.build index a61bb9e6..863cbb20 100644 --- a/src/meson.build +++ b/src/meson.build @@ -3,6 +3,7 @@ sources = files( 'Application.vala', 'SessionManager.vala', 'Backends/Housekeeping.vala', + 'Backends/InterfaceSettings.vala', 'Backends/KeyboardSettings.vala', 'Backends/MouseSettings.vala', 'Backends/PrefersColorSchemeSettings.vala', From e41b46647373b2493378922e316afb7661aff6cf Mon Sep 17 00:00:00 2001 From: lenemter Date: Fri, 30 Jun 2023 20:22:46 +0300 Subject: [PATCH 02/20] Update copyright --- src/Backends/InterfaceSettings.vala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 302cdb7b..4eecb675 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -1,5 +1,5 @@ /* - * Copyright 2021 elementary, Inc. (https://elementary.io) + * Copyright 2023 elementary, Inc. (https://elementary.io) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public @@ -15,7 +15,6 @@ * License along with this program; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA - * Authored by: Marius Meisenzahl */ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { From 9b80c8d7a322ee32b94796207227063c37c484af Mon Sep 17 00:00:00 2001 From: lenemter Date: Fri, 30 Jun 2023 20:39:06 +0300 Subject: [PATCH 03/20] Cleanup --- src/Backends/MouseSettings.vala | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Backends/MouseSettings.vala b/src/Backends/MouseSettings.vala index 07a360df..4912dee3 100644 --- a/src/Backends/MouseSettings.vala +++ b/src/Backends/MouseSettings.vala @@ -23,7 +23,6 @@ public class SettingsDaemon.Backends.MouseSettings : GLib.Object { private GLib.Settings mouse_settings; private GLib.Settings touchpad_settings; - private GLib.Settings interface_settings; public MouseSettings (AccountsService accounts_service) { Object (accounts_service: accounts_service); @@ -32,7 +31,6 @@ public class SettingsDaemon.Backends.MouseSettings : GLib.Object { construct { mouse_settings = new GLib.Settings ("org.gnome.desktop.peripherals.mouse"); touchpad_settings = new GLib.Settings ("org.gnome.desktop.peripherals.touchpad"); - interface_settings = new GLib.Settings ("org.gnome.desktop.interface"); // This is used by installer to set left-handed mode if (accounts_service.left_handed != mouse_settings.get_boolean ("left-handed")) { @@ -62,12 +60,6 @@ public class SettingsDaemon.Backends.MouseSettings : GLib.Object { sync_gsettings_to_accountsservice (); } }); - - interface_settings.changed.connect ((key) => { - if (key == "cursor-size") { - sync_gsettings_to_accountsservice (); - } - }); } private void sync_gsettings_to_accountsservice () { From 797cde4420fe40b387a9662dc009e859857149e0 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 1 Jul 2023 01:36:17 +0300 Subject: [PATCH 04/20] Sync wallpaper to greeter --- ...mentary.SettingsDaemon.AccountsService.xml | 8 +++ src/AccountsService.vala | 2 + src/Backends/InterfaceSettings.vala | 55 +++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/data/io.elementary.SettingsDaemon.AccountsService.xml b/data/io.elementary.SettingsDaemon.AccountsService.xml index fc9e9dec..d1a7cd6d 100644 --- a/data/io.elementary.SettingsDaemon.AccountsService.xml +++ b/data/io.elementary.SettingsDaemon.AccountsService.xml @@ -107,5 +107,13 @@ + + + + + + + + \ No newline at end of file diff --git a/src/AccountsService.vala b/src/AccountsService.vala index e08f378d..ce07c0a8 100644 --- a/src/AccountsService.vala +++ b/src/AccountsService.vala @@ -54,6 +54,8 @@ public interface SettingsDaemon.AccountsService : Object { public abstract int cursor_size { get; set; } public abstract bool locate_pointer { get; set; } public abstract double text_scaling_factor { get; set; } + public abstract int picture_options { get; set; } + public abstract string primary_color { owned get; set; } } [DBus (name = "io.elementary.pantheon.AccountsService")] diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 4eecb675..346cbebc 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -24,10 +24,15 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { private const string CURSOR_SIZE = "cursor-size"; private const string LOCATE_POINTER = "locate-pointer"; private const string TEXT_SCALING_FACTOR = "text-scaling-factor"; + private const string PICTURE_OPTIONS = "picture-options"; + private const string PICTURE_URI = "picture-uri"; + private const string PICTURE_URI_DARK = "picture-uri-dark"; + private const string PRIMARY_COLOR = "primary-color"; public unowned AccountsService accounts_service { get; construct; } private GLib.Settings interface_settings; + private GLib.Settings background_settings; public InterfaceSettings (AccountsService accounts_service) { Object (accounts_service: accounts_service); @@ -35,6 +40,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"); // in case user changes text scaling in greeter session using a11y indicator if (accounts_service.text_scaling_factor != interface_settings.get_double (TEXT_SCALING_FACTOR)) { @@ -42,6 +48,7 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { } sync_gsettings_to_accountsservice (); + sync_background_to_greeter (); interface_settings.changed.connect ((key) => { if (key == CURSOR_BLINK || @@ -53,6 +60,19 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { sync_gsettings_to_accountsservice (); } }); + + background_settings.changed.connect ((key) => { + if (key == PICTURE_OPTIONS || + key == PRIMARY_COLOR) { + sync_gsettings_to_accountsservice (); + return; + } + if (key == PICTURE_URI || + key == PICTURE_URI_DARK) { + sync_background_to_greeter (); + } + }); + } private void sync_gsettings_to_accountsservice () { @@ -62,5 +82,40 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { accounts_service.cursor_size = interface_settings.get_int (CURSOR_SIZE); accounts_service.locate_pointer = interface_settings.get_boolean (LOCATE_POINTER); accounts_service.text_scaling_factor = interface_settings.get_double (TEXT_SCALING_FACTOR); + + accounts_service.picture_options = background_settings.get_enum (PICTURE_OPTIONS); + accounts_service.primary_color = background_settings.get_string (PRIMARY_COLOR); + } + + private void sync_background_to_greeter () { + // File.new_for_uri creates file with broken get_basename method, so do this + var source = File.new_for_path (File.new_for_uri (background_settings.get_string (PICTURE_URI)).get_parse_name ()); + + var greeter_data_dir = Path.build_filename (Environment.get_variable ("XDG_GREETER_DATA_DIR"), "wallpaper"); + if (greeter_data_dir == "") { + greeter_data_dir = Path.build_filename ("/var/lib/lightdm-data/", Environment.get_user_name (), "wallpaper"); + } + var folder = File.new_for_path (greeter_data_dir); + var dest = File.new_for_path (Path.build_filename (greeter_data_dir, source.get_basename ())); + + try { + if (folder.query_exists ()) { + var enumerator = folder.enumerate_children ("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS); + FileInfo? info = null; + while ((info = enumerator.next_file ()) != null) { + enumerator.get_child (info).@delete (); + } + } else { + folder.make_directory_with_parents (); + } + + source.copy (dest, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA); + } catch (Error e) { + warning (e.message); + return; + } + + // Ensure wallpaper is readable by greeter user (owner rw, others r) + FileUtils.chmod (dest.get_path (), 0604); } } From 15aee40245fdc3fd3c6ef293f035a4869aea458f Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 1 Jul 2023 01:43:00 +0300 Subject: [PATCH 05/20] Fix lint --- src/Backends/InterfaceSettings.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 346cbebc..6c9e1675 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -67,7 +67,7 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { sync_gsettings_to_accountsservice (); return; } - if (key == PICTURE_URI || + if (key == PICTURE_URI || key == PICTURE_URI_DARK) { sync_background_to_greeter (); } From a5166f75025720e08f6f5f485957a82bd938405f Mon Sep 17 00:00:00 2001 From: lenemter Date: Mon, 3 Jul 2023 19:05:25 +0900 Subject: [PATCH 06/20] Fix build. Remove reference to dark wallpaper --- src/Application.vala | 2 -- src/Backends/InterfaceSettings.vala | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index a9aa48e8..130df744 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -34,8 +34,6 @@ public class SettingsDaemon.Application : GLib.Application { private PantheonShell.Pantheon.AccountsService pantheon_accounts_service; - private Backends.InterfaceSettings interface_settings; - private Backends.KeyboardSettings keyboard_settings; private Backends.MouseSettings mouse_settings; diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index edd30a97..9c6318f8 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -26,7 +26,6 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { private const string TEXT_SCALING_FACTOR = "text-scaling-factor"; private const string PICTURE_OPTIONS = "picture-options"; private const string PICTURE_URI = "picture-uri"; - private const string PICTURE_URI_DARK = "picture-uri-dark"; private const string PRIMARY_COLOR = "primary-color"; public unowned AccountsService accounts_service { get; construct; } @@ -62,8 +61,7 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { sync_gsettings_to_accountsservice (); return; } - if (key == PICTURE_URI || - key == PICTURE_URI_DARK) { + if (key == PICTURE_URI) { sync_background_to_greeter (); } }); @@ -83,7 +81,9 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { private void sync_background_to_greeter () { // File.new_for_uri creates file with broken get_basename method, so do this - var source = File.new_for_path (File.new_for_uri (background_settings.get_string (PICTURE_URI)).get_parse_name ()); + var wallpaper_uri = background_settings.get_string (PICTURE_URI); + var wallpaper_path = File.new_for_uri (wallpaper_uri).get_path (); + var source = File.new_for_path (wallpaper_path); var greeter_data_dir = Path.build_filename (Environment.get_variable ("XDG_GREETER_DATA_DIR"), "wallpaper"); if (greeter_data_dir == "") { From cfd0430c447e3f1ee248c7a2a164998bdbd7df02 Mon Sep 17 00:00:00 2001 From: lenemter Date: Mon, 3 Jul 2023 21:41:24 +0900 Subject: [PATCH 07/20] Simplify --- src/Backends/InterfaceSettings.vala | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 9c6318f8..57f2cf82 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -80,17 +80,11 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { } private void sync_background_to_greeter () { - // File.new_for_uri creates file with broken get_basename method, so do this - var wallpaper_uri = background_settings.get_string (PICTURE_URI); - var wallpaper_path = File.new_for_uri (wallpaper_uri).get_path (); - var source = File.new_for_path (wallpaper_path); - var greeter_data_dir = Path.build_filename (Environment.get_variable ("XDG_GREETER_DATA_DIR"), "wallpaper"); if (greeter_data_dir == "") { greeter_data_dir = Path.build_filename ("/var/lib/lightdm-data/", Environment.get_user_name (), "wallpaper"); } var folder = File.new_for_path (greeter_data_dir); - var dest = File.new_for_path (Path.build_filename (greeter_data_dir, source.get_basename ())); try { if (folder.query_exists ()) { @@ -103,13 +97,16 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { folder.make_directory_with_parents (); } + var source = File.new_for_uri (background_settings.get_string (PICTURE_URI)); + var dest = File.new_for_path (Path.build_filename (greeter_data_dir, "wallpaper")); + source.copy (dest, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA); + + // Ensure wallpaper is readable by greeter user (owner rw, others r) + FileUtils.chmod (dest.get_path (), 0604); } catch (Error e) { warning (e.message); return; } - - // Ensure wallpaper is readable by greeter user (owner rw, others r) - FileUtils.chmod (dest.get_path (), 0604); } } From 858f40e38f235a15cc4291a434ed094b88c1fea7 Mon Sep 17 00:00:00 2001 From: lenemter Date: Tue, 4 Jul 2023 01:31:07 +0900 Subject: [PATCH 08/20] Set background_file --- src/AccountsService.vala | 5 +++++ src/Application.vala | 21 ++++++++++++++++++++- src/Backends/InterfaceSettings.vala | 18 ++++++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/AccountsService.vala b/src/AccountsService.vala index 88e3850b..3f0da543 100644 --- a/src/AccountsService.vala +++ b/src/AccountsService.vala @@ -79,6 +79,11 @@ public interface PantheonShell.Pantheon.AccountsService : Object { public abstract int prefers_color_scheme { get; set; } } +[DBus (name = "org.freedesktop.DisplayManager.AccountsService")] +public interface DisplayManager.AccountsService : Object { + public abstract string background_file { owned get; set; } +} + [DBus (name = "org.freedesktop.Accounts")] public interface SettingsDaemon.FDO.Accounts : Object { public abstract string find_user_by_name (string username) throws GLib.Error; diff --git a/src/Application.vala b/src/Application.vala index 130df744..ea48e318 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -34,6 +34,8 @@ public class SettingsDaemon.Application : GLib.Application { private PantheonShell.Pantheon.AccountsService pantheon_accounts_service; + private DisplayManager.AccountsService display_manager_accounts_service; + private Backends.KeyboardSettings keyboard_settings; private Backends.MouseSettings mouse_settings; @@ -154,10 +156,27 @@ public class SettingsDaemon.Application : GLib.Application { if (accounts_service != null) { keyboard_settings = new Backends.KeyboardSettings (accounts_service); mouse_settings = new Backends.MouseSettings (accounts_service); - interface_settings = new Backends.InterfaceSettings (accounts_service); night_light_settings = new Backends.NightLightSettings (accounts_service); } + try { + var act_service = yield GLib.Bus.get_proxy (GLib.BusType.SYSTEM, + "org.freedesktop.Accounts", + "/org/freedesktop/Accounts"); + var user_path = act_service.find_user_by_name (GLib.Environment.get_user_name ()); + + display_manager_accounts_service = yield GLib.Bus.get_proxy (GLib.BusType.SYSTEM, + "org.freedesktop.Accounts", + user_path, + GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES); + } catch (Error e) { + warning ("Unable to get AccountsService proxy, background file might be incorrect"); + } + + if (display_manager_accounts_service != null) { + interface_settings = new Backends.InterfaceSettings (accounts_service, display_manager_accounts_service); + } + try { var act_service = yield GLib.Bus.get_proxy (GLib.BusType.SYSTEM, "org.freedesktop.Accounts", diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 57f2cf82..8aa8588c 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -29,6 +29,7 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { private const string PRIMARY_COLOR = "primary-color"; 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; @@ -80,11 +81,17 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { } private void sync_background_to_greeter () { + // File.new_for_uri creates file with broken get_basename method, so do this + var wallpaper_uri = background_settings.get_string (PICTURE_URI); + var wallpaper_path = File.new_for_uri (wallpaper_uri).get_path (); + var source = File.new_for_path (wallpaper_path); + var greeter_data_dir = Path.build_filename (Environment.get_variable ("XDG_GREETER_DATA_DIR"), "wallpaper"); if (greeter_data_dir == "") { greeter_data_dir = Path.build_filename ("/var/lib/lightdm-data/", Environment.get_user_name (), "wallpaper"); } var folder = File.new_for_path (greeter_data_dir); + var dest = File.new_for_path (Path.build_filename (greeter_data_dir, source.get_basename ())); try { if (folder.query_exists ()) { @@ -97,16 +104,15 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { folder.make_directory_with_parents (); } - var source = File.new_for_uri (background_settings.get_string (PICTURE_URI)); - var dest = File.new_for_path (Path.build_filename (greeter_data_dir, "wallpaper")); - source.copy (dest, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA); - - // Ensure wallpaper is readable by greeter user (owner rw, others r) - FileUtils.chmod (dest.get_path (), 0604); } catch (Error e) { warning (e.message); return; } + + // Ensure wallpaper is readable by greeter user (owner rw, others r) + FileUtils.chmod (dest.get_path (), 0604); + + display_manager_accounts_service.background_file = dest.get_path (); } } From b43799f783f87be9ecaf3cbcf6644b48f4c12725 Mon Sep 17 00:00:00 2001 From: lenemter Date: Tue, 4 Jul 2023 01:33:54 +0900 Subject: [PATCH 09/20] Fix build --- src/Backends/InterfaceSettings.vala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 8aa8588c..e324e229 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -34,8 +34,11 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { private GLib.Settings interface_settings; private GLib.Settings background_settings; - public InterfaceSettings (AccountsService accounts_service) { - Object (accounts_service: accounts_service); + public InterfaceSettings (AccountsService accounts_service, DisplayManager.AccountsService display_manager_accounts_service) { + Object ( + accounts_service: accounts_service, + display_manager_accounts_service: display_manager_accounts_service + ); } construct { From f0f23235a33d8271e0209acb9d3f5a192ab9283c Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 4 Jul 2023 17:06:54 +0000 Subject: [PATCH 10/20] Update src/Backends/InterfaceSettings.vala Co-authored-by: Gustavo Marques --- src/Backends/InterfaceSettings.vala | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index e324e229..4351a71e 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -89,12 +89,8 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { var wallpaper_path = File.new_for_uri (wallpaper_uri).get_path (); var source = File.new_for_path (wallpaper_path); - var greeter_data_dir = Path.build_filename (Environment.get_variable ("XDG_GREETER_DATA_DIR"), "wallpaper"); - if (greeter_data_dir == "") { - greeter_data_dir = Path.build_filename ("/var/lib/lightdm-data/", Environment.get_user_name (), "wallpaper"); - } - var folder = File.new_for_path (greeter_data_dir); - var dest = File.new_for_path (Path.build_filename (greeter_data_dir, source.get_basename ())); + var greeter_data_dir = Environment.get_variable ("XDG_GREETER_DATA_DIR") ?? Path.build_filename ("/var/lib/lightdm-data", Environment.get_user_name ()); + var folder = File.new_build_filename (greeter_data_dir, "wallpaper"); try { if (folder.query_exists ()) { From 948c6a195c50693c851772adbe4298629d113bad Mon Sep 17 00:00:00 2001 From: lenemter Date: Wed, 5 Jul 2023 02:30:13 +0900 Subject: [PATCH 11/20] Review suggestions --- src/Backends/InterfaceSettings.vala | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 4351a71e..131b35b4 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -84,34 +84,26 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { } private void sync_background_to_greeter () { - // File.new_for_uri creates file with broken get_basename method, so do this - var wallpaper_uri = background_settings.get_string (PICTURE_URI); - var wallpaper_path = File.new_for_uri (wallpaper_uri).get_path (); - var source = File.new_for_path (wallpaper_path); + var source = File.new_for_uri (background_settings.get_string (PICTURE_URI)); + var wallpaper_name = source.get_basename (); var greeter_data_dir = Environment.get_variable ("XDG_GREETER_DATA_DIR") ?? Path.build_filename ("/var/lib/lightdm-data", Environment.get_user_name ()); var folder = File.new_build_filename (greeter_data_dir, "wallpaper"); try { - if (folder.query_exists ()) { - var enumerator = folder.enumerate_children ("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS); - FileInfo? info = null; - while ((info = enumerator.next_file ()) != null) { - enumerator.get_child (info).@delete (); - } - } else { + if (!folder.query_exists ()) { folder.make_directory_with_parents (); } - source.copy (dest, FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA); + source.copy (folder.get_child (wallpaper_name), FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA); } catch (Error e) { warning (e.message); return; } // Ensure wallpaper is readable by greeter user (owner rw, others r) - FileUtils.chmod (dest.get_path (), 0604); + FileUtils.chmod (folder.get_child (wallpaper_name).get_path (), 0604); - display_manager_accounts_service.background_file = dest.get_path (); + display_manager_accounts_service.background_file = folder.get_child (wallpaper_name).get_path (); } } From 35a56e510146e38f28985e956882ba780c80e4bb Mon Sep 17 00:00:00 2001 From: lenemter Date: Wed, 5 Jul 2023 02:31:05 +0900 Subject: [PATCH 12/20] Check for `accounts_service` --- src/Application.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index ea48e318..b7336241 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -173,7 +173,7 @@ public class SettingsDaemon.Application : GLib.Application { warning ("Unable to get AccountsService proxy, background file might be incorrect"); } - if (display_manager_accounts_service != null) { + if (accounts_service != null && display_manager_accounts_service != null) { interface_settings = new Backends.InterfaceSettings (accounts_service, display_manager_accounts_service); } From 3a5e68e59e3f936f95370af1a682cf7844fa8708 Mon Sep 17 00:00:00 2001 From: lenemter Date: Wed, 5 Jul 2023 02:53:37 +0900 Subject: [PATCH 13/20] Check if file exists --- src/Backends/InterfaceSettings.vala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 131b35b4..7ad67eea 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -85,6 +85,11 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { private void sync_background_to_greeter () { var source = File.new_for_uri (background_settings.get_string (PICTURE_URI)); + if (!FileUtils.test (source.get_path (), EXISTS)) { + display_manager_accounts_service.background_file = ""; + return; + } + var wallpaper_name = source.get_basename (); var greeter_data_dir = Environment.get_variable ("XDG_GREETER_DATA_DIR") ?? Path.build_filename ("/var/lib/lightdm-data", Environment.get_user_name ()); From 8089ce466c666dc881197c67ecb789b19e438c9b Mon Sep 17 00:00:00 2001 From: lenemter Date: Wed, 5 Jul 2023 05:16:20 +0900 Subject: [PATCH 14/20] Put chmod in try block --- src/Backends/InterfaceSettings.vala | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 7ad67eea..da014ada 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -101,14 +101,15 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { } source.copy (folder.get_child (wallpaper_name), FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA); + + // Ensure wallpaper is readable by greeter user (owner rw, others r) + FileUtils.chmod (folder.get_child (wallpaper_name).get_path (), 0604); + + display_manager_accounts_service.background_file = folder.get_child (wallpaper_name).get_path (); } catch (Error e) { warning (e.message); + display_manager_accounts_service.background_file = ""; return; } - - // Ensure wallpaper is readable by greeter user (owner rw, others r) - FileUtils.chmod (folder.get_child (wallpaper_name).get_path (), 0604); - - display_manager_accounts_service.background_file = folder.get_child (wallpaper_name).get_path (); } } From c1fe409dc5c40462790b2ce32b09b6e4acf92a65 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sun, 9 Jul 2023 00:34:00 +0900 Subject: [PATCH 15/20] Handle dark wallpaper. Use `wallpaper` name --- src/Backends/InterfaceSettings.vala | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index da014ada..1293c11c 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -25,8 +25,9 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { private const string LOCATE_POINTER = "locate-pointer"; private const string TEXT_SCALING_FACTOR = "text-scaling-factor"; private const string PICTURE_OPTIONS = "picture-options"; - private const string PICTURE_URI = "picture-uri"; private const string PRIMARY_COLOR = "primary-color"; + private const string PICTURE_URI = "picture-uri"; + private const string PICTURE_URI_DARK = "picture-uri-dark"; public unowned AccountsService accounts_service { get; construct; } public unowned DisplayManager.AccountsService display_manager_accounts_service { get; construct; } @@ -65,7 +66,9 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { sync_gsettings_to_accountsservice (); return; } - if (key == PICTURE_URI) { + + if (key == PICTURE_URI || + key == PICTURE_URI_DARK) { sync_background_to_greeter (); } }); @@ -85,15 +88,19 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { private void sync_background_to_greeter () { var source = File.new_for_uri (background_settings.get_string (PICTURE_URI)); + var source_dark = File.new_for_uri (background_settings.get_string (PICTURE_URI_DARK)); + if (!FileUtils.test (source.get_path (), EXISTS)) { + debug ("Wallpaper path is invalid"); display_manager_accounts_service.background_file = ""; return; } - var wallpaper_name = source.get_basename (); + var wallpaper_name = "wallpaper"; + var wallpaper_dark_name = "wallpaper-dark"; var greeter_data_dir = Environment.get_variable ("XDG_GREETER_DATA_DIR") ?? Path.build_filename ("/var/lib/lightdm-data", Environment.get_user_name ()); - var folder = File.new_build_filename (greeter_data_dir, "wallpaper"); + var folder = File.new_for_path (greeter_data_dir); try { if (!folder.query_exists ()) { @@ -101,10 +108,15 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { } source.copy (folder.get_child (wallpaper_name), FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA); - // Ensure wallpaper is readable by greeter user (owner rw, others r) FileUtils.chmod (folder.get_child (wallpaper_name).get_path (), 0604); + if (FileUtils.test (source_dark.get_path (), EXISTS)) { + source_dark.copy (folder.get_child (wallpaper_dark_name), FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA); + // Ensure wallpaper is readable by greeter user (owner rw, others r) + FileUtils.chmod (folder.get_child (wallpaper_dark_name).get_path (), 0604); + } + display_manager_accounts_service.background_file = folder.get_child (wallpaper_name).get_path (); } catch (Error e) { warning (e.message); From ce0ccbfade4e88c2bbdd6a5a93014189665d49bf Mon Sep 17 00:00:00 2001 From: lenemter Date: Sun, 9 Jul 2023 13:50:17 +0900 Subject: [PATCH 16/20] Don't handle dark wallpaper --- src/Backends/InterfaceSettings.vala | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 1293c11c..fa9a1a14 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -88,16 +88,14 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { private void sync_background_to_greeter () { var source = File.new_for_uri (background_settings.get_string (PICTURE_URI)); - var source_dark = File.new_for_uri (background_settings.get_string (PICTURE_URI_DARK)); - if (!FileUtils.test (source.get_path (), EXISTS)) { + if (!source.query_exists ()) { debug ("Wallpaper path is invalid"); display_manager_accounts_service.background_file = ""; return; } var wallpaper_name = "wallpaper"; - var wallpaper_dark_name = "wallpaper-dark"; var greeter_data_dir = Environment.get_variable ("XDG_GREETER_DATA_DIR") ?? Path.build_filename ("/var/lib/lightdm-data", Environment.get_user_name ()); var folder = File.new_for_path (greeter_data_dir); @@ -111,12 +109,6 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { // Ensure wallpaper is readable by greeter user (owner rw, others r) FileUtils.chmod (folder.get_child (wallpaper_name).get_path (), 0604); - if (FileUtils.test (source_dark.get_path (), EXISTS)) { - source_dark.copy (folder.get_child (wallpaper_dark_name), FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA); - // Ensure wallpaper is readable by greeter user (owner rw, others r) - FileUtils.chmod (folder.get_child (wallpaper_dark_name).get_path (), 0604); - } - display_manager_accounts_service.background_file = folder.get_child (wallpaper_name).get_path (); } catch (Error e) { warning (e.message); From a64c14b406ec2c34cb737f8fd65369b159351527 Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 13 Jul 2023 14:26:42 +0900 Subject: [PATCH 17/20] Fix lint --- src/Backends/InterfaceSettings.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 1200d1fc..b87165ee 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -92,7 +92,7 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { accounts_service.picture_options = background_settings.get_enum (PICTURE_OPTIONS); accounts_service.primary_color = background_settings.get_string (PRIMARY_COLOR); - + 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); From 53d4b20fdcee8abdbc36670d398f57e939683275 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sun, 16 Jul 2023 15:28:21 +0900 Subject: [PATCH 18/20] Review comments --- src/Backends/InterfaceSettings.vala | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index b87165ee..3eb07f9d 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -28,7 +28,6 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { private const string PICTURE_OPTIONS = "picture-options"; private const string PRIMARY_COLOR = "primary-color"; private const string PICTURE_URI = "picture-uri"; - private const string PICTURE_URI_DARK = "picture-uri-dark"; private const string DOCUMENT_FONT_NAME = "document-font-name"; private const string FONT_NAME = "font-name"; @@ -52,7 +51,6 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { background_settings = new GLib.Settings ("org.gnome.desktop.background"); sync_gsettings_to_accountsservice (); - sync_background_to_greeter (); interface_settings.changed.connect ((key) => { if (key == CURSOR_BLINK || @@ -75,8 +73,7 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { return; } - if (key == PICTURE_URI || - key == PICTURE_URI_DARK) { + if (key == PICTURE_URI) { sync_background_to_greeter (); } }); From 1ecef3f7c43cc387a442b27e83d8c0497c73856b Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 20 Jul 2023 00:59:44 +0900 Subject: [PATCH 19/20] Add migration path --- src/Backends/InterfaceSettings.vala | 34 ++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index 3eb07f9d..cf037d37 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -108,21 +108,49 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { var greeter_data_dir = Environment.get_variable ("XDG_GREETER_DATA_DIR") ?? Path.build_filename ("/var/lib/lightdm-data", Environment.get_user_name ()); var folder = File.new_for_path (greeter_data_dir); + var dest = folder.get_child (wallpaper_name); try { if (!folder.query_exists ()) { folder.make_directory_with_parents (); } - source.copy (folder.get_child (wallpaper_name), FileCopyFlags.OVERWRITE | FileCopyFlags.ALL_METADATA); + if (FileUtils.test (dest.get_path (), IS_DIR)) { + debug ("Migrating to new wallpaper directory"); + remove_directory (dest); + } + + source.copy (dest, OVERWRITE | ALL_METADATA); // Ensure wallpaper is readable by greeter user (owner rw, others r) - FileUtils.chmod (folder.get_child (wallpaper_name).get_path (), 0604); + FileUtils.chmod (dest.get_path (), 0604); - display_manager_accounts_service.background_file = folder.get_child (wallpaper_name).get_path (); + display_manager_accounts_service.background_file = dest.get_path (); + } catch (IOError.IS_DIRECTORY e) { + critical ("Migration failed %s", e.message); } catch (Error e) { warning (e.message); display_manager_accounts_service.background_file = ""; return; } } + + private void remove_directory (File directory) { + try { + var enumerator = directory.enumerate_children ( + FileAttribute.STANDARD_NAME, NOFOLLOW_SYMLINKS + ); + + FileInfo file_info; + while ((file_info = enumerator.next_file ()) != null) { + var file = directory.get_child (file_info.get_name ()); + if (file_info.get_file_type () == DIRECTORY) { + remove_directory (file); + } + file.delete (); + } + directory.delete (); + } catch (Error e) { + critical ("Couldn't remove directory %s: %s", directory.get_path (), e.message); + } + } } From 152fd86a3c442a247436a0b86ad1f7f92d4c1103 Mon Sep 17 00:00:00 2001 From: lenemter Date: Thu, 20 Jul 2023 01:00:28 +0900 Subject: [PATCH 20/20] Cleanup --- src/Backends/InterfaceSettings.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Backends/InterfaceSettings.vala b/src/Backends/InterfaceSettings.vala index cf037d37..6053d5e2 100644 --- a/src/Backends/InterfaceSettings.vala +++ b/src/Backends/InterfaceSettings.vala @@ -127,10 +127,10 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object { display_manager_accounts_service.background_file = dest.get_path (); } catch (IOError.IS_DIRECTORY e) { critical ("Migration failed %s", e.message); + display_manager_accounts_service.background_file = ""; } catch (Error e) { warning (e.message); display_manager_accounts_service.background_file = ""; - return; } }