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

[WIP] Use the users dark style/accent color preference #499

Draft
wants to merge 2 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Cards/BaseCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public abstract class Greeter.BaseCard : Gtk.Revealer {
public bool need_password { get; set; default = false; }
public bool use_fingerprint { get; set; default = false; }

public int prefers_color_scheme { get; set; default = 0; }
public int prefers_accent_color { get; set; default = 0; }

static construct {
css_provider = new Gtk.CssProvider ();
css_provider.load_from_resource ("/io/elementary/greeter/Card.css");
Expand Down
12 changes: 12 additions & 0 deletions src/Cards/UserCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public class Greeter.UserCard : Greeter.BaseCard {
unowned string? act_path = act_user.get_object_path ();
if (act_path != null) {
try {

greeter_act = GLib.Bus.get_proxy_sync (GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
act_path,
Expand All @@ -261,12 +262,16 @@ public class Greeter.UserCard : Greeter.BaseCard {
"org.freedesktop.Accounts",
act_path,
GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES);

is_24h = greeter_act.time_format != "12h";
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;
prefers_color_scheme = greeter_act.prefers_color_scheme;
prefers_accent_color = greeter_act.prefers_accent_color;
((GLib.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";
Expand All @@ -275,6 +280,13 @@ public class Greeter.UserCard : Greeter.BaseCard {
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);

int prefers_color_scheme_out;
changed_properties.lookup ("PrefersColorScheme", "i", out prefers_color_scheme_out);
prefers_color_scheme = prefers_color_scheme_out;
int prefers_accent_color_out;
changed_properties.lookup ("PrefersColorScheme", "i", out prefers_accent_color_out);
prefers_accent_color = prefers_accent_color_out;
});
} catch (Error e) {
critical (e.message);
Expand Down
47 changes: 47 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
if (current_card != null) {
current_card.grab_focus ();
}
user_style ();
}

private void maximize_window () {
Expand Down Expand Up @@ -538,6 +539,8 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
binding.unbind ();
}

user_style ();

user_card.set_keyboard_layouts ();

binding = user_card.bind_property ("is-24h", datetime_widget, "is-24h", GLib.BindingFlags.SYNC_CREATE);
Expand Down Expand Up @@ -625,4 +628,48 @@ public class Greeter.MainWindow : Gtk.ApplicationWindow {
switch_to_card (next_card);
}
}

private void user_style () {
var gtksettings = Gtk.Settings.get_default ();
if (current_card.prefers_color_scheme == 1) {
gtksettings.gtk_application_prefer_dark_theme = true;
} else {
gtksettings.gtk_application_prefer_dark_theme = false;
}
switch (current_card.prefers_accent_color) {
case 1:
gtksettings.gtk_theme_name = "io.elementary.stylesheet.strawberry";
break;
case 2:
gtksettings.gtk_theme_name = "io.elementary.stylesheet.orange";
break;
case 3:
gtksettings.gtk_theme_name = "io.elementary.stylesheet.banana";
break;
case 4:
gtksettings.gtk_theme_name = "io.elementary.stylesheet.lime";
break;
case 5:
gtksettings.gtk_theme_name = "io.elementary.stylesheet.mint";
break;
case 6:
gtksettings.gtk_theme_name = "io.elementary.stylesheet.blueberry";
break;
case 7:
gtksettings.gtk_theme_name = "io.elementary.stylesheet.grape";
break;
case 8:
gtksettings.gtk_theme_name = "io.elementary.stylesheet.bubblegum";
break;
case 9:
gtksettings.gtk_theme_name = "io.elementary.stylesheet.cocoa";
break;
case 10:
gtksettings.gtk_theme_name = "io.elementary.stylesheet.slate";
break;
default:
gtksettings.gtk_theme_name = "io.elementary.stylesheet.blueberry";
break;
}
}
}
6 changes: 6 additions & 0 deletions src/PantheonAccountsServicePlugin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ interface Pantheon.AccountsService : Object {

public abstract int sleep_inactive_battery_timeout { get; set; }
public abstract int sleep_inactive_battery_type { get; set; }

[DBus (name = "PrefersColorScheme")]
public abstract int prefers_color_scheme { get; set; }

[DBus (name = "PrefersAccentColor")]
public abstract int prefers_accent_color { get; set; }
}

[DBus (name = "io.elementary.SettingsDaemon.AccountsService")]
Expand Down