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

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
155ccb5
Support dark mode
lenemter Sep 2, 2023
0e29187
Merge branch 'master' into lenemter/support-dark-mode
lenemter Oct 21, 2023
55f4d46
Merge branch 'master' into lenemter/support-dark-mode
lenemter Jan 27, 2024
bb95147
Avoid loading lighdm_act many times
lenemter Jan 27, 2024
dada4a6
Fix lint
lenemter Jan 27, 2024
7c5fcfe
Merge branch 'master' into lenemter/support-dark-mode
danirabbit Jan 29, 2024
b01ac4b
Simplify last coordinates
lenemter Jan 30, 2024
825b0a3
Fix settings
lenemter Feb 3, 2024
6da7d4a
Merge branch 'master' into lenemter/support-dark-mode
lenemter Feb 3, 2024
29e535d
Merge branch 'master' into lenemter/support-dark-mode
lenemter Feb 8, 2024
2844ca2
Merge branch 'master' into lenemter/support-dark-mode
danirabbit Feb 13, 2024
5d93138
Remove bad merge line
danirabbit Feb 13, 2024
a6a63aa
Merge branch 'master' into lenemter/support-dark-mode
danirabbit Mar 10, 2024
6c5998d
Merge branch 'master' into lenemter/support-dark-mode
danirabbit Mar 12, 2024
0ec938f
Merge branch 'master' into lenemter/support-dark-mode
zeebok Apr 3, 2024
e279b07
Merge branch 'master' into lenemter/support-dark-mode
zeebok Apr 18, 2024
971d451
Merge branch 'master' into lenemter/support-dark-mode
zeebok May 1, 2024
6b34a15
Merge branch 'master' into lenemter/support-dark-mode
lenemter Jun 23, 2024
d37ade6
Merge branch 'master' into lenemter/support-dark-mode
zeebok Jun 24, 2024
143814f
Fix build
lenemter Jul 4, 2024
7a1eeec
Merge branch 'master' into lenemter/support-dark-mode
zeebok Aug 6, 2024
831e723
Merge branch 'master' into lenemter/support-dark-mode
zeebok Aug 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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"});
Copy link
Member

Choose a reason for hiding this comment

The 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 {
wingpanel = new Greeter.SubprocessSupervisor ({"io.elementary.wingpanel", "-g"});
} catch (Error e) {
critical (e.message);
}

try {
settings_daemon = new Greeter.SubprocessSupervisor ({"io.elementary.settings-daemon"});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also unclear?

} catch (Error e) {
critical (e.message);
}

Gtk.main ();

return 0;
Expand Down
132 changes: 98 additions & 34 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 @@ -25,6 +28,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 @@ -212,9 +217,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 Down Expand Up @@ -244,6 +257,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 ();
}
});

notify["child-revealed"].connect (() => {
Expand Down Expand Up @@ -325,47 +343,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 @@ -409,16 +439,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 @@ -476,6 +512,17 @@ public class Greeter.UserCard : Greeter.BaseCard {
interface_settings.set_value ("font-name", settings_act.font_name);
interface_settings.set_value ("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.prefer_dark_last_coordinates.latitude);
var longitude = new Variant.double (settings_act.prefer_dark_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 @@ -498,6 +545,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 +567 to +568
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
changed_properties.lookup ("PrefersColorScheme", "i", out prefers_color_scheme);
greeter_act.prefers_color_scheme = prefers_color_scheme;
if (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
16 changes: 12 additions & 4 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,11 +65,13 @@ interface Pantheon.SettingsDaemon.AccountsService : Object {
public abstract string monospace_font_name { owned get; set; }
public abstract bool orientation_lock { get; set; }

/* Prefer Dark Schedule (part of interface settings)*/
public abstract Coordinates prefer_dark_last_coordinates { get; set; }
lenemter marked this conversation as resolved.
Show resolved Hide resolved
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 struct Coordinates {
public double latitude;
public double longitude;
}

public abstract bool night_light_enabled { get; set; }
public abstract Coordinates night_light_last_coordinates { get; set; }
Expand Down