diff --git a/src/Application.vala b/src/Application.vala index 31322ee4..44d70afe 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -16,9 +16,10 @@ 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.AccentColorManager accent_color_manager; + private Backends.DisplaySettings display_settings; private Backends.Housekeeping housekeeping; + private Backends.AccentColorManager accent_color_manager; private Backends.PowerProfilesSync power_profiles_sync; private const string FDO_ACCOUNTS_NAME = "org.freedesktop.Accounts"; @@ -55,6 +56,7 @@ public sealed class SettingsDaemon.Application : Gtk.Application { base.startup (); housekeeping = new Backends.Housekeeping (); + display_settings = new Backends.DisplaySettings (); power_profiles_sync = new Backends.PowerProfilesSync (); var check_firmware_updates_action = new GLib.SimpleAction ("check-firmware-updates", null); diff --git a/src/Backends/DisplaySettings.vala b/src/Backends/DisplaySettings.vala new file mode 100644 index 00000000..6ea83472 --- /dev/null +++ b/src/Backends/DisplaySettings.vala @@ -0,0 +1,51 @@ +/* + * 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; + } + + 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 eda9764c..95c51b30 100644 --- a/src/meson.build +++ b/src/meson.build @@ -2,6 +2,7 @@ sources = files( 'AccountsService.vala', 'Application.vala', 'Backends/AccentColorManager.vala', + 'Backends/DisplaySettings.vala', 'Backends/Housekeeping.vala', 'Backends/InterfaceSettings.vala', 'Backends/KeyboardSettings.vala',