Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync display settings to Greeter #125

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
51 changes: 51 additions & 0 deletions src/Backends/DisplaySettings.vala
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down