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

Support dark mode #684

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 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
27 changes: 25 additions & 2 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ public int main (string[] args) {
// overrides
GLib.Environment.set_variable ("XDG_CURRENT_DESKTOP", "Pantheon", true);

var settings_daemon = new Greeter.SettingsDaemon ();
settings_daemon.start ();
var gnome_settings_daemon = new Greeter.SettingsDaemon ();
gnome_settings_daemon.start ();

Greeter.SubprocessSupervisor compositor;
Greeter.SubprocessSupervisor portals;
Greeter.SubprocessSupervisor wingpanel;
Greeter.SubprocessSupervisor settings_daemon;

try {
compositor = new Greeter.SubprocessSupervisor ({"io.elementary.greeter-compositor"});
Expand All @@ -46,12 +48,33 @@ public int main (string[] args) {
var window = new Greeter.MainWindow ();
window.show_all ();

try {
portals = new Greeter.SubprocessSupervisor ({"/usr/libexec/xdg-desktop-portal"});
} catch (Error e) {
critical (e.message);
}

unowned var gtk_settings = Gtk.Settings.get_default ();
unowned var granite_settings = Granite.Settings.get_default ();

gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == DARK;

granite_settings.notify["prefers-color-scheme"].connect (() => {
gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == DARK;
});

try {
wingpanel = new Greeter.SubprocessSupervisor ({"io.elementary.wingpanel", "-g"});
} catch (Error e) {
critical (e.message);
}

try {
settings_daemon = new Greeter.SubprocessSupervisor ({"io.elementary.settings-daemon"});
} catch (Error e) {
critical (e.message);
}

Gtk.main ();

return 0;
Expand Down
136 changes: 100 additions & 36 deletions src/Cards/UserCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/

public class Greeter.UserCard : Greeter.BaseCard {
private static Act.User lightdm_user_act;
private static Pantheon.AccountsService lightdm_act;

public signal void go_left ();
public signal void go_right ();
public signal void focus_requested ();
Expand All @@ -24,6 +27,8 @@ public class Greeter.UserCard : Greeter.BaseCard {
private Pantheon.AccountsService greeter_act;
private Pantheon.SettingsDaemon.AccountsService settings_act;

private ulong dark_mode_sync_id = 0;

private Gtk.GestureMultiPress click_gesture;
private Gtk.Revealer form_revealer;
private Gtk.Stack login_stack;
Expand Down Expand Up @@ -211,9 +216,17 @@ public class Greeter.UserCard : Greeter.BaseCard {
act_user = Act.UserManager.get_default ().get_user (lightdm_user.name);
act_user.bind_property ("locked", username_label, "sensitive", INVERT_BOOLEAN);
act_user.bind_property ("locked", session_button, "visible", INVERT_BOOLEAN);
act_user.notify["is-loaded"].connect (on_act_user_loaded);

on_act_user_loaded ();
if (lightdm_user_act == null) {
lightdm_user_act = Act.UserManager.get_default ().get_user (Environment.get_user_name ());
}

if (act_user.is_loaded && lightdm_user_act.is_loaded) {
on_act_user_loaded ();
} else {
act_user.notify["is-loaded"].connect (on_act_user_loaded);
lightdm_user_act.notify["is-loaded"].connect (on_act_user_loaded);
}

card_overlay.focus.connect ((direction) => {
if (direction == LEFT) {
Expand All @@ -237,6 +250,11 @@ public class Greeter.UserCard : Greeter.BaseCard {

notify["show-input"].connect (() => {
update_collapsed_class ();

// Stop settings sync, that starts in `set_settings ()`
if (!show_input) {
stop_settings_sync ();
}
});

password_entry.activate.connect (on_login);
Expand Down Expand Up @@ -314,47 +332,59 @@ public class Greeter.UserCard : Greeter.BaseCard {
}

private void on_act_user_loaded () {
if (!act_user.is_loaded) {
if (!act_user.is_loaded || !lightdm_user_act.is_loaded) {
return;
}

unowned string? act_path = act_user.get_object_path ();
if (act_path != null) {
try {
greeter_act = Bus.get_proxy_sync (
SYSTEM,
"org.freedesktop.Accounts",
act_path,
GET_INVALIDATED_PROPERTIES
);
if (act_path == null) {
critical ("Couldn't load user act");
return;
}

try {
greeter_act = Bus.get_proxy_sync (
SYSTEM,
"org.freedesktop.Accounts",
act_path,
GET_INVALIDATED_PROPERTIES
);

settings_act = Bus.get_proxy_sync (
SYSTEM,
"org.freedesktop.Accounts",
act_path,
GET_INVALIDATED_PROPERTIES
);

is_24h = greeter_act.time_format != "12h";
prefers_accent_color = greeter_act.prefers_accent_color;
sleep_inactive_ac_timeout = greeter_act.sleep_inactive_ac_timeout;
sleep_inactive_ac_type = greeter_act.sleep_inactive_ac_type;
sleep_inactive_battery_timeout = greeter_act.sleep_inactive_battery_timeout;
sleep_inactive_battery_type = greeter_act.sleep_inactive_battery_type;
} catch (Error e) {
critical (e.message);
return;
}

if (lightdm_act == null) {
unowned string? lightdm_act_path = lightdm_user_act.get_object_path ();
if (lightdm_act_path == null) {
critical ("Couldn't load lighdm act");
return;
}

settings_act = Bus.get_proxy_sync (
try {
lightdm_act = Bus.get_proxy_sync (
SYSTEM,
"org.freedesktop.Accounts",
act_path,
lightdm_act_path,
GET_INVALIDATED_PROPERTIES
);

is_24h = greeter_act.time_format != "12h";
prefers_accent_color = greeter_act.prefers_accent_color;
sleep_inactive_ac_timeout = greeter_act.sleep_inactive_ac_timeout;
sleep_inactive_ac_type = greeter_act.sleep_inactive_ac_type;
sleep_inactive_battery_timeout = greeter_act.sleep_inactive_battery_timeout;
sleep_inactive_battery_type = greeter_act.sleep_inactive_battery_type;

((DBusProxy) greeter_act).g_properties_changed.connect ((changed_properties, invalidated_properties) => {
string time_format;
changed_properties.lookup ("TimeFormat", "s", out time_format);
is_24h = time_format != "12h";

changed_properties.lookup ("PrefersAccentColor", "i", out _prefers_accent_color);
changed_properties.lookup ("SleepInactiveACTimeout", "i", out _sleep_inactive_ac_timeout);
changed_properties.lookup ("SleepInactiveACType", "i", out _sleep_inactive_ac_type);
changed_properties.lookup ("SleepInactiveBatteryTimeout", "i", out _sleep_inactive_battery_timeout);
changed_properties.lookup ("SleepInactiveBatteryType", "i", out _sleep_inactive_battery_type);
});
} catch (Error e) {
critical (e.message);
return;
}
}

Expand Down Expand Up @@ -398,16 +428,22 @@ public class Greeter.UserCard : Greeter.BaseCard {
}

public void set_settings () {
if (!act_user.is_loaded) {
if (!show_input) {
return;
}

if (!act_user.is_loaded || !lightdm_user_act.is_loaded) {
needs_settings_set = true;
return;
}

update_style ();
set_keyboard_layouts ();
set_mouse_touchpad_settings ();
set_interface_settings ();
set_night_light_settings ();
update_style ();

start_settings_sync ();
}

private void set_keyboard_layouts () {
Expand Down Expand Up @@ -477,6 +513,17 @@ public class Greeter.UserCard : Greeter.BaseCard {
set_or_reset_settings_key (interface_settings, "font-name", settings_act.font_name);
set_or_reset_settings_key (interface_settings, "monospace-font-name", settings_act.monospace_font_name);

var settings_daemon_settings = new GLib.Settings ("io.elementary.settings-daemon.prefers-color-scheme");

var latitude = new Variant.double (settings_act.last_coordinates.latitude);
var longitude = new Variant.double (settings_act.last_coordinates.longitude);
var coordinates = new Variant.tuple ({latitude, longitude});
settings_daemon_settings.set_value ("last-coordinates", coordinates);

settings_daemon_settings.set_enum ("prefer-dark-schedule", settings_act.prefer_dark_schedule);
settings_daemon_settings.set_value ("prefer-dark-schedule-from", settings_act.prefer_dark_schedule_from);
settings_daemon_settings.set_value ("prefer-dark-schedule-to", settings_act.prefer_dark_schedule_to);

var touchscreen_settings = new GLib.Settings ("org.gnome.settings-daemon.peripherals.touchscreen");
touchscreen_settings.set_boolean ("orientation-lock", settings_act.orientation_lock);

Expand All @@ -495,8 +542,8 @@ public class Greeter.UserCard : Greeter.BaseCard {
var night_light_settings = new GLib.Settings ("org.gnome.settings-daemon.plugins.color");
night_light_settings.set_value ("night-light-enabled", settings_act.night_light_enabled);

var latitude = new Variant.double (settings_act.night_light_last_coordinates.latitude);
var longitude = new Variant.double (settings_act.night_light_last_coordinates.longitude);
var latitude = new Variant.double (settings_act.last_coordinates.latitude);
var longitude = new Variant.double (settings_act.last_coordinates.longitude);
var coordinates = new Variant.tuple ({latitude, longitude});
night_light_settings.set_value ("night-light-last-coordinates", coordinates);

Expand All @@ -509,6 +556,23 @@ public class Greeter.UserCard : Greeter.BaseCard {
private void update_style () {
var interface_settings = new GLib.Settings ("org.gnome.desktop.interface");
interface_settings.set_value ("gtk-theme", "io.elementary.stylesheet." + accent_to_string (prefers_accent_color));
lightdm_act.prefers_color_scheme = greeter_act.prefers_color_scheme;
}

private void start_settings_sync () {
debug ("Started settings sync for user %s", lightdm_user.name);

dark_mode_sync_id = ((DBusProxy) lightdm_act).g_properties_changed.connect ((changed_properties, invalidated_properties) => {
int prefers_color_scheme;
changed_properties.lookup ("PrefersColorScheme", "i", out prefers_color_scheme);
greeter_act.prefers_color_scheme = prefers_color_scheme;
});
}

private void stop_settings_sync () {
debug ("Stopped settings sync for user %s", lightdm_user.name);

lightdm_act.disconnect (dark_mode_sync_id);
}

public override void wrong_credentials () {
Expand Down
19 changes: 13 additions & 6 deletions src/PantheonAccountsServicePlugin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
interface Pantheon.AccountsService : Object {
public abstract string time_format { owned get; set; }

public abstract int prefers_color_scheme { get; set; }
public abstract int prefers_accent_color { get; set; }

[DBus (name = "SleepInactiveACTimeout")]
Expand All @@ -15,6 +16,11 @@ interface Pantheon.AccountsService : Object {

[DBus (name = "io.elementary.SettingsDaemon.AccountsService")]
interface Pantheon.SettingsDaemon.AccountsService : Object {
public struct Coordinates {
public double latitude;
public double longitude;
}

/* Keyboard */
public struct KeyboardLayout {
public string backend;
Expand Down Expand Up @@ -59,14 +65,15 @@ interface Pantheon.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