-
-
Notifications
You must be signed in to change notification settings - Fork 41
Support dark mode #684
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
Changes from 19 commits
155ccb5
0e29187
55f4d46
bb95147
dada4a6
7c5fcfe
b01ac4b
825b0a3
6da7d4a
29e535d
2844ca2
5d93138
a6a63aa
6c5998d
0ec938f
e279b07
971d451
6b34a15
d37ade6
143814f
7a1eeec
831e723
4c6e603
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,13 @@ public int main (string[] args) { | |
Intl.textdomain (Constants.GETTEXT_PACKAGE); | ||
Intl.bindtextdomain (Constants.GETTEXT_PACKAGE, Constants.LOCALE_DIR); | ||
|
||
var gnome_settings_daemon = new Greeter.SettingsDaemon (); | ||
gnome_settings_daemon.start (); | ||
|
||
Greeter.SubprocessSupervisor portals; | ||
Greeter.SubprocessSupervisor settings_daemon; | ||
|
||
|
||
var settings_daemon = new Greeter.SettingsDaemon (); | ||
settings_daemon.start (); | ||
|
||
|
@@ -33,6 +40,27 @@ public int main (string[] args) { | |
var window = new Greeter.MainWindow (); | ||
window.show_all (); | ||
|
||
try { | ||
portals = new Greeter.SubprocessSupervisor ({"/usr/libexec/xdg-desktop-portal"}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is unclear to me why you need to spawn this? |
||
} 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 { | ||
settings_daemon = new Greeter.SubprocessSupervisor ({"io.elementary.settings-daemon"}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also unclear? |
||
} catch (Error e) { | ||
critical (e.message); | ||
} | ||
|
||
Gtk.main (); | ||
|
||
return 0; | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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 (); | ||||||||||||
|
@@ -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; | ||||||||||||
|
@@ -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) { | ||||||||||||
|
@@ -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); | ||||||||||||
|
@@ -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; | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
|
@@ -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 () { | ||||||||||||
|
@@ -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); | ||||||||||||
|
||||||||||||
|
@@ -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); | ||||||||||||
|
||||||||||||
|
@@ -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; | ||||||||||||
Comment on lines
+561
to
+562
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
}); | ||||||||||||
} | ||||||||||||
|
||||||||||||
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 () { | ||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.