Skip to content

Commit 6834e2d

Browse files
committed
Use account service for dark scheme and fix build
1 parent 7081e6b commit 6834e2d

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

background/Background.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public interface Gala.Background.Background : Object, Gdk.Paintable {
134134
}
135135

136136
public void snapshot (Gdk.Snapshot gdk_snapshot, double width, double height) {
137-
texture.snapshot (gdk_snapshot, render_width, render_height);
137+
texture.snapshot (gdk_snapshot, width, height);
138138
}
139139
}
140140
}

background/BackgroundManager.vala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ public class Gala.Background.BackgroundManager : Object {
1818
private uint idle_id = 0;
1919

2020
construct {
21+
/*
22+
* We can't use Granite for the color scheme since it connects to the portal which only becomes available
23+
* some time after we are already showing.
24+
*/
25+
Utils.init_color_scheme_watcher (queue_set_background);
26+
2127
setup_background ();
2228
Gdk.Display.get_default ().get_monitors ().items_changed.connect (setup_background);
2329

2430
set_background ();
2531
gnome_settings.changed.connect (queue_set_background);
2632
elementary_settings.changed.connect (queue_set_background);
27-
28-
Granite.Settings.get_default ().notify["prefers-color-scheme"].connect (queue_set_background);
2933
}
3034

3135
private void setup_background () {
@@ -71,7 +75,7 @@ public class Gala.Background.BackgroundManager : Object {
7175
}
7276

7377
if (elementary_settings.get_boolean ("dim-wallpaper-in-dark-style")
74-
// && Granite.Settings.get_default ().prefers_color_scheme == DARK //todo: other thread?
78+
&& Utils.get_color_scheme () == DARK
7579
) {
7680
current_background = Background.get_dimmed (current_background);
7781
}

background/Utils.vala

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,58 @@
44
*/
55

66
namespace Gala.Background.Utils {
7+
public enum ColorScheme {
8+
NO_PREFERENCE,
9+
DARK,
10+
LIGHT
11+
}
12+
13+
public delegate void OnStyleChange (ColorScheme new_style);
14+
15+
[DBus (name = "org.freedesktop.Accounts")]
16+
private interface Accounts : Object {
17+
public abstract string find_user_by_name (string name) throws IOError, DBusError;
18+
}
19+
20+
[DBus (name = "io.elementary.pantheon.AccountsService")]
21+
private interface AccountsService : DBusProxy {
22+
public abstract int prefers_color_scheme { get; set; }
23+
public abstract int prefers_accent_color { get; set; }
24+
}
25+
26+
private const string FDO_ACCOUNTS_NAME = "org.freedesktop.Accounts";
27+
private const string FDO_ACCOUNTS_PATH = "/org/freedesktop/Accounts";
28+
29+
private static AccountsService? accounts_service_proxy;
30+
31+
public static void init_color_scheme_watcher (OnStyleChange style_change_callback) {
32+
try {
33+
var accounts = Bus.get_proxy_sync<Accounts> (SYSTEM, FDO_ACCOUNTS_NAME, FDO_ACCOUNTS_PATH);
34+
35+
var path = accounts.find_user_by_name (Environment.get_user_name ());
36+
37+
accounts_service_proxy = Bus.get_proxy_sync<AccountsService> (SYSTEM, FDO_ACCOUNTS_NAME, path, GET_INVALIDATED_PROPERTIES);
38+
} catch {
39+
warning ("Could not connect to AccountsService. Default style will be used");
40+
return;
41+
}
42+
43+
accounts_service_proxy.g_properties_changed.connect ((changed, invalid) => {
44+
var value = changed.lookup_value ("PrefersColorScheme", new VariantType ("i"));
45+
if (value != null) {
46+
style_change_callback (value.get_int32 ());
47+
}
48+
});
49+
}
50+
51+
public static ColorScheme get_color_scheme () {
52+
if (accounts_service_proxy != null) {
53+
return accounts_service_proxy.prefers_color_scheme;
54+
}
55+
56+
return LIGHT;
57+
}
58+
759
private const double SATURATION_WEIGHT = 1.5;
860
private const double WEIGHT_THRESHOLD = 1.0;
961

0 commit comments

Comments
 (0)