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

Watch for xdg-desktop-portal starting before binding style scheme #34

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Changes from all 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
21 changes: 17 additions & 4 deletions src/XdgDesktopPortalPantheon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,26 @@ private void on_bus_acquired (DBusConnection connection, string name) {

private void on_name_acquired () {
debug ("org.freedesktop.impl.portal.desktop.panthon acquired");
var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.Settings.get_default ();

gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
granite_settings.notify["prefers-color-scheme"].connect (() => {
// We're probably being started by xdg-desktop-portal, which won't be fully initialised until all the backends have loaded.
// Granite depends on the settings portal to get the style preference, but can't DBus activate it because it's already starting.
// The settings portal can't fully start because it's waiting on us, so break the cyclic nonsense by watching for xdg-desktop-portal
// appearing before binding the style scheme
uint watch_id = 0;
watch_id = Bus.watch_name (BusType.SESSION, "org.freedesktop.portal.Desktop", BusNameWatcherFlags.NONE, () => {
var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.Settings.get_default ();

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

if (watch_id != 0) {
Bus.unwatch_name (watch_id);
}
});

}

int main (string[] args) {
Expand Down