Skip to content

Commit

Permalink
BackgroundManager: Don't rely on delays, read the GNOME settings at s…
Browse files Browse the repository at this point in the history
…tartup and update Cinnamon if and only if they actually change.
  • Loading branch information
clefebvre committed Mar 24, 2015
1 parent a14eab1 commit 7f4751a
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions js/ui/backgroundManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,56 @@ BackgroundManager.prototype = {
this._cinnamonSettings = new Gio.Settings({ schema: "org.cinnamon.desktop.background" });

this._string_keys = ["color-shading-type", "picture-options", "picture-uri", "primary-color", "secondary-color"];
this._string_values = [];
this._int_keys = ["picture-opacity"];
this._int_values = [];

// The GNOME background is set when the user presses "Set as Wallpaper" in EOG, Firefox and a few other apps
// So we listen to the GNOME background key and set the Cinnamon background appropriately when it is changed.
// We also use a timeout here because gsettings is super-dodgy at session-startup, it basically fires "changed" signals
// on keys which values haven't changed.
Mainloop.timeout_add_seconds(10, Lang.bind(this, this.listen_to_gnome_bg_changes));
},
for (var i in this._string_keys) {
this._string_values[i] = this._gnomeSettings.get_string(this._string_keys[i]);
}

listen_to_gnome_bg_changes: function() {
let schema = Gio.SettingsSchemaSource.get_default();
if (schema.lookup("org.gnome.desktop.background", true)) {
this._gnomeSettings = new Gio.Settings({ schema: 'org.gnome.desktop.background' });
this._changedId = this._gnomeSettings.connect('changed', Lang.bind(this, this._onGnomeSettingsChanged));
for (var i in this._int_keys) {
this._int_values[i] = this._gnomeSettings.get_int(this._int_keys[i]);
}

this._gnomeSettings.connect('changed', Lang.bind(this, this._onGnomeSettingsChanged));
},

_onGnomeSettingsChanged: function() {
somethingChanged = false;
for (var i in this._string_keys) {
key = this._string_keys[i];
value = this._string_values[i];
newValue = this._gnomeSettings.get_string(key);
if (value != newValue) {
global.log("BackgroundManager: org.gnome.desktop.background %s changed (%s -> %s)!".format(key, value, newValue));
this._string_values[i] = newValue;
somethingChanged = true;
}
}
for (var i in this._int_keys) {
key = this._int_keys[i];
value = this._int_values[i];
newValue = this._gnomeSettings.get_int(key);
if (value != newValue) {
global.log("BackgroundManager: org.gnome.desktop.background %s changed (%d -> %d)!".format(key, value, newValue));
this._int_values[i] = newValue;
somethingChanged = true;
}
}
if (somethingChanged == true) {
this._overwriteCinnamonSettings();
}
},

_overwriteCinnamonSettings: function() {
for (var i in this._string_keys) {
let key = this._string_keys[i];
let gnomeValue = this._gnomeSettings.get_string(key);
if (this._cinnamonSettings.get_string(key) != gnomeValue) {
this._cinnamonSettings.set_string(key, gnomeValue);
}
}
}
for (var i in this._int_keys) {
let key = this._int_keys[i];
let gnomeValue = this._gnomeSettings.get_int(key);
Expand Down

0 comments on commit 7f4751a

Please sign in to comment.