From db9fe43ca979659ab2b1934b8323c83adae5aab3 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 27 Jan 2024 21:58:19 +0900 Subject: [PATCH 1/2] Sync display settings to Greeter --- src/Application.vala | 2 ++ src/Backends/DisplaySettings.vala | 53 +++++++++++++++++++++++++++++++ src/meson.build | 1 + 3 files changed, 56 insertions(+) create mode 100644 src/Backends/DisplaySettings.vala diff --git a/src/Application.vala b/src/Application.vala index 1efb885e..696da756 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -17,6 +17,7 @@ public sealed class SettingsDaemon.Application : Gtk.Application { private Backends.InterfaceSettings interface_settings; private Backends.NightLightSettings night_light_settings; private Backends.PrefersColorSchemeSettings prefers_color_scheme_settings; + private Backends.DisplaySettings display_settings; private Backends.Housekeeping housekeeping; @@ -54,6 +55,7 @@ public sealed class SettingsDaemon.Application : Gtk.Application { base.startup (); housekeeping = new Backends.Housekeeping (); + display_settings = new Backends.DisplaySettings (); var check_firmware_updates_action = new GLib.SimpleAction ("check-firmware-updates", null); check_firmware_updates_action.activate.connect (check_firmware_updates); diff --git a/src/Backends/DisplaySettings.vala b/src/Backends/DisplaySettings.vala new file mode 100644 index 00000000..7a63ed77 --- /dev/null +++ b/src/Backends/DisplaySettings.vala @@ -0,0 +1,53 @@ +/* + * Copyright 2024 elementary, Inc. (https://elementary.io) + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +public class SettingsDaemon.Backends.DisplaySettings : GLib.Object { + private string monitors_path; + private FileMonitor? file_monitor; + + construct { + monitors_path = Path.build_filename (GLib.Environment.get_user_config_dir (), "monitors.xml"); + sync_monitors_to_greeter (); + + var file = File.new_for_path (monitors_path); + try { + file_monitor = file.monitor (GLib.FileMonitorFlags.NONE); + file_monitor.changed.connect ((file, other_file, type) => { + if (type == FileMonitorEvent.CHANGES_DONE_HINT) { + sync_monitors_to_greeter (); + } + }); + } catch (Error e) { + critical ("Couldn't obtain FileMonitor for %s", monitors_path); + file_monitor = null; + } + } + + private void sync_monitors_to_greeter () { + if (!FileUtils.test (monitors_path, EXISTS)) { + critical ("%s not found", monitors_path); + return; + } + + warning ("OwO"); + + var source = File.new_for_path (monitors_path); + 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 ("monitors.xml"); + + try { + if (!folder.query_exists ()) { + folder.make_directory_with_parents (); + } + + source.copy (dest, OVERWRITE | ALL_METADATA); + // Ensure monitors.xml is readable by greeter user (owner rw, others r) + FileUtils.chmod (dest.get_path (), 0604); + } catch (Error e) { + warning (e.message); + } + } +} diff --git a/src/meson.build b/src/meson.build index b35eed56..c071f6b8 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,6 +1,7 @@ sources = files( 'AccountsService.vala', 'Application.vala', + 'Backends/DisplaySettings.vala', 'Backends/Housekeeping.vala', 'Backends/InterfaceSettings.vala', 'Backends/KeyboardSettings.vala', From 3e0af958a8a03d010b3c688bb9f031c9cc6a30bd Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 27 Jan 2024 21:59:05 +0900 Subject: [PATCH 2/2] Remove debug --- src/Backends/DisplaySettings.vala | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Backends/DisplaySettings.vala b/src/Backends/DisplaySettings.vala index 7a63ed77..6ea83472 100644 --- a/src/Backends/DisplaySettings.vala +++ b/src/Backends/DisplaySettings.vala @@ -31,8 +31,6 @@ public class SettingsDaemon.Backends.DisplaySettings : GLib.Object { return; } - warning ("OwO"); - var source = File.new_for_path (monitors_path); 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);