Skip to content

Commit

Permalink
Expose prefer dark schedule settings (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenemter authored Jan 31, 2024
1 parent c2fa02f commit 216ea5e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 27 deletions.
20 changes: 17 additions & 3 deletions data/io.elementary.SettingsDaemon.AccountsService.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,28 @@
<annotation name="org.freedesktop.Accounts.DefaultValue" value="false"/>
</property>

<property name="NightLightEnabled" type="b" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue" value="false"/>
<!-- Prefer dark schedule-->

<property name="PreferDarkSchedule" type="i" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue" value="0"/>
</property>

<property name="NightLightLastCoordinates" type="(dd)" access="readwrite">
<property name="LastCoordinates" type="(dd)" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue" value="(91.0, 181.0)"/>
</property>

<property name="PreferDarkScheduleFrom" type="d" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue" value="20"/>
</property>

<property name="PreferDarkScheduleTo" type="d" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue" value="6"/>
</property>

<property name="NightLightEnabled" type="b" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue" value="false"/>
</property>

<property name="NightLightScheduleAutomatic" type="b" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
</property>
Expand Down
18 changes: 12 additions & 6 deletions src/AccountsService.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,14 +69,15 @@ public interface SettingsDaemon.AccountsService : Object {
public abstract string monospace_font_name { owned get; set; }
public abstract bool orientation_lock { get; set; }

/* Night Light */
public struct Coordinates {
public double latitude;
public double longitude;
}
/* Prefer Dark Schedule (part of interface settings)*/
/* 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; }
Expand Down
34 changes: 34 additions & 0 deletions src/Backends/InterfaceSettings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ 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 ORIENTATION_LOCK = "orientation-lock";
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;
private GLib.Settings touchscreen_settings;

public InterfaceSettings (AccountsService accounts_service, DisplayManager.AccountsService display_manager_accounts_service) {
Expand All @@ -52,6 +57,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");
touchscreen_settings = new GLib.Settings ("org.gnome.settings-daemon.peripherals.touchscreen");

sync_gsettings_to_accountsservice ();
Expand Down Expand Up @@ -82,6 +88,15 @@ 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_TO) {
sync_gsettings_to_accountsservice ();
}
});

touchscreen_settings.changed.connect (sync_gsettings_to_accountsservice);
}

Expand All @@ -100,6 +115,25 @@ public class SettingsDaemon.Backends.InterfaceSettings : GLib.Object {
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.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);

accounts_service.orientation_lock = touchscreen_settings.get_boolean (ORIENTATION_LOCK);
}

Expand Down
18 changes: 0 additions & 18 deletions src/Backends/NightLightSettings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 ||
Expand All @@ -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);
Expand Down

0 comments on commit 216ea5e

Please sign in to comment.