Skip to content

Commit

Permalink
Merge branch 'lenemter/idk-what-im-doing' of https://github.com/eleme…
Browse files Browse the repository at this point in the history
…ntary/gala into lenemter/idk-what-im-doing
  • Loading branch information
lenemter committed Sep 29, 2023
2 parents 3026dcc + 4faea38 commit 166555e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 53 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
60 changes: 32 additions & 28 deletions src/Background/BackgroundSource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,38 @@ 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 Gee.HashMap<int,Background> backgrounds;
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 {
backgrounds = new Gee.HashMap<int,Background> ();
backgrounds = new GLib.HashTable<int, Background> (GLib.direct_hash, GLib.direct_equal);
hash_cache = new uint[OPTIONS.length];

unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
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 All @@ -77,23 +80,22 @@ namespace Gala {
var n = display.get_n_monitors ();
var i = 0;

foreach (var background in backgrounds.values) {
backgrounds.foreach_remove ((hash, background) => {
if (i++ < n) {
background.update_resolution ();
continue;
return false;
} else {
background.changed.disconnect (background_changed);
background.destroy ();
return true;
}

background.changed.disconnect (background_changed);
background.destroy ();
// TODO can we remove from a list while iterating?
backgrounds.unset (i);
}
});
}

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 @@ -105,25 +107,26 @@ namespace Gala {
if (filename == null || !filename.has_suffix (".xml"))
monitor_index = 0;

if (!backgrounds.has_key (monitor_index)) {
var background = new Background (display, monitor_index, filename, this, (GDesktop.BackgroundStyle) style);
var background = backgrounds.lookup (monitor_index);
if (background == null) {
background = new Background (display, monitor_index, filename, this, (GDesktop.BackgroundStyle) style);
background.changed.connect (background_changed);
backgrounds[monitor_index] = background;
backgrounds.insert (monitor_index, background);
}

return backgrounds[monitor_index];
return background;
}

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 All @@ -135,17 +138,18 @@ namespace Gala {
private void background_changed (Background background) {
background.changed.disconnect (background_changed);
background.destroy ();
backgrounds.unset (background.monitor_index);
backgrounds.remove (background.monitor_index);
}

public void destroy () {
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.disconnect (monitors_changed);
monitor_manager = null;

foreach (var background in backgrounds.values) {
backgrounds.foreach_remove ((hash, background) => {
background.changed.disconnect (background_changed);
background.destroy ();
}
return true;
});
}
}
}
4 changes: 0 additions & 4 deletions src/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,6 @@ namespace Gala {
// Most things inside this "later" depend on GTK. We get segfaults if we try to do GTK stuff before the window manager
// is initialized, so we hold this stuff off until we're ready to draw
laters.add (Meta.LaterType.BEFORE_REDRAW, () => {
string[] args = {};
unowned string[] _args = args;
Gtk.init (ref _args);

accent_color_manager = new AccentColorManager ();

// initialize plugins and add default components if no plugin overrides them
Expand Down

0 comments on commit 166555e

Please sign in to comment.