mirror of
https://github.com/elementary/gala.git
synced 2024-09-19 03:17:56 +03:00
fix problems with settings changed events firing on startup randomly
This commit is contained in:
parent
3ab490aaf4
commit
e61b9b8e22
@ -27,7 +27,7 @@ namespace Gala
|
||||
|
||||
public Meta.Screen screen { get; construct; }
|
||||
public int monitor_index { get; construct; }
|
||||
public Settings settings { get; construct; }
|
||||
public BackgroundSource background_source { get; construct; }
|
||||
public bool is_loaded { get; private set; default = false; }
|
||||
public GDesktop.BackgroundStyle style { get; construct; }
|
||||
public string? filename { get; construct; }
|
||||
@ -38,9 +38,14 @@ namespace Gala
|
||||
Cancellable cancellable;
|
||||
uint update_animation_timeout_id = 0;
|
||||
|
||||
public Background (Meta.Screen screen, int monitor_index, string? filename, Settings settings, GDesktop.BackgroundStyle style)
|
||||
public Background (Meta.Screen screen, int monitor_index, string? filename,
|
||||
BackgroundSource background_source, GDesktop.BackgroundStyle style)
|
||||
{
|
||||
Object (screen: screen, monitor_index: monitor_index, settings: settings, style: style, filename: filename);
|
||||
Object (screen: screen,
|
||||
monitor_index: monitor_index,
|
||||
background_source: background_source,
|
||||
style: style,
|
||||
filename: filename);
|
||||
}
|
||||
|
||||
construct
|
||||
@ -51,7 +56,7 @@ namespace Gala
|
||||
file_watches = new Gee.HashMap<string,ulong> ();
|
||||
cancellable = new Cancellable ();
|
||||
|
||||
settings.changed.connect (settings_changed);
|
||||
background_source.changed.connect (settings_changed);
|
||||
|
||||
load ();
|
||||
}
|
||||
@ -67,7 +72,7 @@ namespace Gala
|
||||
SignalHandler.disconnect (cache, watch);
|
||||
}
|
||||
|
||||
settings.changed.disconnect (settings_changed);
|
||||
background_source.settings.changed.disconnect (settings_changed);
|
||||
}
|
||||
|
||||
public void update_resolution ()
|
||||
@ -94,6 +99,7 @@ namespace Gala
|
||||
void load_pattern ()
|
||||
{
|
||||
string color_string;
|
||||
var settings = background_source.settings;
|
||||
|
||||
color_string = settings.get_string ("primary-color");
|
||||
var color = Clutter.Color.from_string (color_string);
|
||||
@ -275,7 +281,7 @@ namespace Gala
|
||||
load_file (filename);
|
||||
}
|
||||
|
||||
void settings_changed (Settings settings, string key)
|
||||
void settings_changed ()
|
||||
{
|
||||
changed ();
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ namespace Gala
|
||||
|
||||
void update ()
|
||||
{
|
||||
var reference_child = (get_child_at_index (0) as Background);
|
||||
var reference_child = (get_child_at_index (0) as BackgroundManager);
|
||||
if (reference_child != null)
|
||||
reference_child.changed.disconnect (background_changed);
|
||||
|
||||
|
@ -133,20 +133,24 @@ namespace Gala
|
||||
background_actor.set_position (monitor.x, monitor.y);
|
||||
}
|
||||
|
||||
ulong handler = 0;
|
||||
handler = background.changed.connect (() => {
|
||||
SignalHandler.disconnect (background, handler);
|
||||
handler = 0;
|
||||
ulong changed_handler = 0;
|
||||
changed_handler = background.changed.connect (() => {
|
||||
SignalHandler.disconnect (background, changed_handler);
|
||||
changed_handler = 0;
|
||||
update_background_actor ();
|
||||
});
|
||||
|
||||
background_actor.destroy.connect (() => {
|
||||
if (handler != 0)
|
||||
SignalHandler.disconnect (background, handler);
|
||||
if (changed_handler != 0) {
|
||||
SignalHandler.disconnect (background, changed_handler);
|
||||
changed_handler = 0;
|
||||
}
|
||||
|
||||
var loaded_handler = background.get_data<ulong> ("background-loaded-handler");
|
||||
if (loaded_handler != 0)
|
||||
if (loaded_handler != 0) {
|
||||
SignalHandler.disconnect (background, loaded_handler);
|
||||
background.set_data<ulong> ("background-loaded-handler", 0);
|
||||
}
|
||||
});
|
||||
|
||||
return background_actor;
|
||||
|
@ -19,6 +19,8 @@ namespace Gala
|
||||
{
|
||||
public class BackgroundSource : Object
|
||||
{
|
||||
public signal void changed ();
|
||||
|
||||
public Meta.Screen screen { get; construct; }
|
||||
public Settings settings { get; construct; }
|
||||
|
||||
@ -36,6 +38,9 @@ namespace Gala
|
||||
backgrounds = new Gee.HashMap<int,Background> ();
|
||||
|
||||
screen.monitors_changed.connect (monitors_changed);
|
||||
|
||||
settings_hash_cache = get_current_settings_hash_cache ();
|
||||
settings.changed.connect (settings_changed);
|
||||
}
|
||||
|
||||
void monitors_changed ()
|
||||
@ -77,7 +82,7 @@ namespace Gala
|
||||
monitor_index = 0;
|
||||
|
||||
if (!backgrounds.has_key (monitor_index)) {
|
||||
var background = new Background (screen, monitor_index, filename, settings, (GDesktop.BackgroundStyle) style);
|
||||
var background = new Background (screen, monitor_index, filename, this, (GDesktop.BackgroundStyle) style);
|
||||
|
||||
background.changed.connect (background_changed);
|
||||
|
||||
@ -103,6 +108,55 @@ namespace Gala
|
||||
background.destroy ();
|
||||
}
|
||||
}
|
||||
|
||||
// unfortunately the settings sometimes tend to fire random changes even though
|
||||
// nothing actually happend. 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
|
||||
|
||||
// helper struct which stores the hash values generated by g_variant_hash
|
||||
struct SettingsHashCache
|
||||
{
|
||||
uint color_shading_type;
|
||||
uint picture_opacity;
|
||||
uint picture_options;
|
||||
uint picture_uri;
|
||||
uint primar_color;
|
||||
uint secondary_color;
|
||||
}
|
||||
|
||||
SettingsHashCache settings_hash_cache;
|
||||
|
||||
// list of keys that are actually relevant for us
|
||||
const string[] options = { "color-shading-type", "picture-opacity",
|
||||
"picture-options", "picture-uri", "primary-color", "secondary-color" };
|
||||
|
||||
void settings_changed (string key)
|
||||
{
|
||||
if (!(key in options))
|
||||
return;
|
||||
|
||||
var current = get_current_settings_hash_cache ();
|
||||
|
||||
if (Memory.cmp (&settings_hash_cache, ¤t, sizeof (SettingsHashCache)) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Memory.copy (&settings_hash_cache, ¤t, sizeof (SettingsHashCache));
|
||||
|
||||
changed ();
|
||||
}
|
||||
|
||||
SettingsHashCache get_current_settings_hash_cache ()
|
||||
{
|
||||
return {
|
||||
settings.get_value ("color-shading-type").hash (),
|
||||
settings.get_value ("picture-opacity").hash (),
|
||||
settings.get_value ("picture-options").hash (),
|
||||
settings.get_value ("picture-uri").hash (),
|
||||
settings.get_value ("primary-color").hash (),
|
||||
settings.get_value ("secondary-color").hash ()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user