Skip to content

Commit

Permalink
Merge branch 'master' into dont-block-alt-shift
Browse files Browse the repository at this point in the history
  • Loading branch information
lenemter authored Sep 29, 2023
2 parents 4a6f2f8 + b9744dd commit daebc4b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/Background/Background.vala
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ namespace Gala {

Idle.add (() => {
loaded ();
return false;
return Source.REMOVE;
});
}

private void load_pattern () {
string color_string;
var settings = background_source.settings;
var settings = background_source.gnome_background_settings;

color_string = settings.get_string ("primary-color");
var color = Clutter.Color.from_string (color_string);
Expand Down Expand Up @@ -209,7 +209,7 @@ namespace Gala {
update_animation_timeout_id = Timeout.add (interval, () => {
update_animation_timeout_id = 0;
update_animation ();
return false;
return Source.REMOVE;
});
}

Expand Down
23 changes: 8 additions & 15 deletions src/Background/BackgroundCache.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Gala {
public signal void file_changed (string filename);

private Gee.HashMap<string,FileMonitor> file_monitors;
private Gee.HashMap<string,BackgroundSource> background_sources;
private BackgroundSource background_source;

private Animation animation;

Expand All @@ -39,7 +39,6 @@ namespace Gala {

construct {
file_monitors = new Gee.HashMap<string,FileMonitor> ();
background_sources = new Gee.HashMap<string,BackgroundSource> ();
}

public void monitor_file (string filename) {
Expand All @@ -63,7 +62,7 @@ namespace Gala {
if (animation != null && animation.filename == filename) {
Idle.add (() => {
get_animation.callback ();
return false;
return Source.REMOVE;
});
yield;

Expand All @@ -76,32 +75,26 @@ namespace Gala {

Idle.add (() => {
get_animation.callback ();
return false;
return Source.REMOVE;
});
yield;

return animation;
}

public BackgroundSource get_background_source (Meta.Display display, string settings_schema) {
var background_source = background_sources[settings_schema];
public BackgroundSource get_background_source (Meta.Display display) {
if (background_source == null) {
background_source = new BackgroundSource (display, settings_schema);
background_source = new BackgroundSource (display);
background_source.use_count = 1;
background_sources[settings_schema] = background_source;
} else
background_source.use_count++;

return background_source;
}

public void release_background_source (string settings_schema) {
if (background_sources.has_key (settings_schema)) {
var source = background_sources[settings_schema];
if (--source.use_count == 0) {
background_sources.unset (settings_schema);
source.destroy ();
}
public void release_background_source () {
if (--background_source.use_count == 0) {
background_source.destroy ();
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/Background/BackgroundManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace Gala {
public class BackgroundManager : Meta.BackgroundGroup {
private const string GNOME_BACKGROUND_SCHEMA = "org.gnome.desktop.background";
private const string GALA_BACKGROUND_SCHEMA = "io.elementary.desktop.background";
private const string DIM_WALLPAPER_KEY = "dim-wallpaper-in-dark-style";
private const double DIM_OPACITY = 0.55;
Expand Down Expand Up @@ -46,14 +45,14 @@ namespace Gala {
}

construct {
background_source = BackgroundCache.get_default ().get_background_source (display, GNOME_BACKGROUND_SCHEMA);
background_source = BackgroundCache.get_default ().get_background_source (display);
background_actor = create_background_actor ();

destroy.connect (on_destroy);
}

private void on_destroy () {
BackgroundCache.get_default ().release_background_source (GNOME_BACKGROUND_SCHEMA);
BackgroundCache.get_default ().release_background_source ();
background_source = null;

if (new_background_actor != null) {
Expand Down
20 changes: 11 additions & 9 deletions src/Background/BackgroundSource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ namespace Gala {
public signal void changed ();

public Meta.Display display { get; construct; }
public Settings settings { get; construct; }
public GLib.Settings gnome_background_settings { get; construct; }

internal int use_count { get; set; default = 0; }

private GLib.HashTable<int, Background> backgrounds;
private uint[] hash_cache;
private Meta.MonitorManager? monitor_manager;

public BackgroundSource (Meta.Display display, string settings_schema) {
Object (display: display, settings: new Settings (settings_schema));
public BackgroundSource (Meta.Display display) {
Object (display: display);
}

construct {
Expand All @@ -50,17 +50,19 @@ namespace Gala {
monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.connect (monitors_changed);

gnome_background_settings = new Settings ("org.gnome.desktop.background");

// unfortunately the settings sometimes tend to fire random changes even though
// nothing actually happened. The code below is used to prevent us from spamming
// new actors all the time, which lead to some problems in other areas of the code
for (int i = 0; i < OPTIONS.length; i++) {
hash_cache[i] = settings.get_value (OPTIONS[i]).hash ();
hash_cache[i] = gnome_background_settings.get_value (OPTIONS[i]).hash ();
}

settings.changed.connect ((key) => {
gnome_background_settings.changed.connect ((key) => {
for (int i = 0; i < OPTIONS.length; i++) {
if (key == OPTIONS[i]) {
uint new_hash = settings.get_value (key).hash ();
uint new_hash = gnome_background_settings.get_value (key).hash ();
if (hash_cache[i] != new_hash) {
hash_cache[i] = new_hash;
changed ();
Expand Down Expand Up @@ -93,7 +95,7 @@ namespace Gala {
public Background get_background (int monitor_index) {
string? filename = null;

var style = settings.get_enum ("picture-options");
var style = gnome_background_settings.get_enum ("picture-options");
if (style != GDesktop.BackgroundStyle.NONE) {
filename = get_background_path ();
}
Expand All @@ -117,14 +119,14 @@ namespace Gala {

private string get_background_path () {
if (Granite.Settings.get_default ().prefers_color_scheme == DARK) {
var uri = settings.get_string ("picture-uri-dark");
var uri = gnome_background_settings.get_string ("picture-uri-dark");
var path = File.new_for_uri (uri).get_path ();
if (FileUtils.test (path, EXISTS)) {
return path;
}
}

var uri = settings.get_string ("picture-uri");
var uri = gnome_background_settings.get_string ("picture-uri");
var path = File.new_for_uri (uri).get_path ();
if (FileUtils.test (path, EXISTS)) {
return path;
Expand Down

0 comments on commit daebc4b

Please sign in to comment.