mirror of
https://github.com/elementary/gala.git
synced 2024-08-17 02:50:38 +03:00
Background: Cleanup (#1776)
This commit is contained in:
parent
031e210f81
commit
6cc836017e
@ -33,6 +33,7 @@
|
||||
</ul>
|
||||
</description>
|
||||
<issues>
|
||||
<issue url="https://github.com/elementary/gala/issues/1774">Scheduled switch to dark style does not dim the wallpaper after cold reboot on elementary OS 7.1</issue>
|
||||
<issue url="https://github.com/elementary/gala/issues/1261">Alt + Shift unnecessarily blocked when there is only one keyboard layout</issue>
|
||||
</issues>
|
||||
</release>
|
||||
|
@ -74,7 +74,7 @@ namespace Gala {
|
||||
var cache = BackgroundCache.get_default ();
|
||||
|
||||
foreach (var watch in file_watches.values) {
|
||||
SignalHandler.disconnect (cache, watch);
|
||||
cache.disconnect (watch);
|
||||
}
|
||||
|
||||
background_source.changed.disconnect (settings_changed);
|
||||
@ -179,7 +179,7 @@ namespace Gala {
|
||||
} else {
|
||||
ulong handler = 0;
|
||||
handler = image.loaded.connect (() => {
|
||||
SignalHandler.disconnect (image, handler);
|
||||
image.disconnect (handler);
|
||||
if (--num_pending_images == 0) {
|
||||
finish_animation (files);
|
||||
}
|
||||
@ -237,7 +237,7 @@ namespace Gala {
|
||||
ulong handler = 0;
|
||||
handler = image.loaded.connect (() => {
|
||||
set_loaded ();
|
||||
SignalHandler.disconnect (image, handler);
|
||||
image.disconnect (handler);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
namespace Gala {
|
||||
public class BackgroundManager : Meta.BackgroundGroup {
|
||||
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;
|
||||
private const int FADE_ANIMATION_TIME = 1000;
|
||||
|
||||
@ -32,18 +30,10 @@ namespace Gala {
|
||||
private Meta.BackgroundActor background_actor;
|
||||
private Meta.BackgroundActor? new_background_actor = null;
|
||||
|
||||
private Clutter.PropertyTransition? last_dim_transition = null;
|
||||
|
||||
private static Settings gala_background_settings;
|
||||
|
||||
public BackgroundManager (Meta.Display display, int monitor_index, bool control_position = true) {
|
||||
Object (display: display, monitor_index: monitor_index, control_position: control_position);
|
||||
}
|
||||
|
||||
static construct {
|
||||
gala_background_settings = new Settings (GALA_BACKGROUND_SCHEMA);
|
||||
}
|
||||
|
||||
construct {
|
||||
background_source = BackgroundCache.get_default ().get_background_source (display);
|
||||
background_actor = create_background_actor ();
|
||||
@ -120,7 +110,7 @@ namespace Gala {
|
||||
|
||||
ulong handler = 0;
|
||||
handler = background.loaded.connect (() => {
|
||||
SignalHandler.disconnect (background, handler);
|
||||
background.disconnect (handler);
|
||||
background.set_data<ulong> ("background-loaded-handler", 0);
|
||||
|
||||
swap_background_actor (animate);
|
||||
@ -138,17 +128,18 @@ namespace Gala {
|
||||
var background = background_source.get_background (monitor_index);
|
||||
var background_actor = new Meta.BackgroundActor (display, monitor_index);
|
||||
|
||||
((Meta.BackgroundContent)background_actor.content).background = background.background;
|
||||
((Meta.BackgroundContent)background_actor.content).vignette = true;
|
||||
unowned var content = (Meta.BackgroundContent) background_actor.content;
|
||||
content.background = background.background;
|
||||
|
||||
// Don't play dim animation when launching gala or switching wallpaper
|
||||
if (should_dim ()) {
|
||||
((Meta.BackgroundContent)background_actor.content).brightness = DIM_OPACITY;
|
||||
if (background_source.should_dim) {
|
||||
// It doesn't work without Idle :(
|
||||
Idle.add (() => {
|
||||
content.vignette = true;
|
||||
content.brightness = DIM_OPACITY;
|
||||
return Source.REMOVE;
|
||||
});
|
||||
}
|
||||
|
||||
Granite.Settings.get_default ().notify["prefers-color-scheme"].connect (update_dim_wallpaper);
|
||||
gala_background_settings.changed[DIM_WALLPAPER_KEY].connect (update_dim_wallpaper);
|
||||
|
||||
insert_child_below (background_actor, null);
|
||||
|
||||
var monitor = display.get_monitor_geometry (monitor_index);
|
||||
@ -160,78 +151,25 @@ namespace Gala {
|
||||
|
||||
ulong changed_handler = 0;
|
||||
changed_handler = background.changed.connect (() => {
|
||||
SignalHandler.disconnect (background, changed_handler);
|
||||
background.disconnect (changed_handler);
|
||||
changed_handler = 0;
|
||||
update_background_actor ();
|
||||
});
|
||||
|
||||
background_actor.destroy.connect (() => {
|
||||
if (changed_handler != 0) {
|
||||
SignalHandler.disconnect (background, changed_handler);
|
||||
background.disconnect (changed_handler);
|
||||
changed_handler = 0;
|
||||
}
|
||||
|
||||
var loaded_handler = background.get_data<ulong> ("background-loaded-handler");
|
||||
if (loaded_handler != 0) {
|
||||
SignalHandler.disconnect (background, loaded_handler);
|
||||
background.disconnect (loaded_handler);
|
||||
background.set_data<ulong> ("background-loaded-handler", 0);
|
||||
}
|
||||
});
|
||||
|
||||
return background_actor;
|
||||
}
|
||||
|
||||
private bool should_dim () {
|
||||
return (
|
||||
Granite.Settings.get_default ().prefers_color_scheme == Granite.Settings.ColorScheme.DARK &&
|
||||
gala_background_settings.get_boolean (DIM_WALLPAPER_KEY)
|
||||
);
|
||||
}
|
||||
|
||||
// OpacityDimActor is used for transitioning background actor's vignette brightness
|
||||
// In mutter 3.38+ vignette's properties are contained in Meta.BackgroundContent
|
||||
// which doesn't support transitions
|
||||
// so we bind OpacityDimActor.opacity to ((Meta.BackgroundContent) background_actor.content).brightness
|
||||
// and then create transition for OpacityDimActor.opacity
|
||||
|
||||
private class OpacityDimActor : Clutter.Actor {
|
||||
public new double opacity { get; set; }
|
||||
}
|
||||
|
||||
private void update_dim_wallpaper () {
|
||||
if (last_dim_transition != null) {
|
||||
last_dim_transition.stop ();
|
||||
}
|
||||
|
||||
var dim_actor = new OpacityDimActor ();
|
||||
background_actor.add_child (dim_actor);
|
||||
var binding = dim_actor.bind_property (
|
||||
"opacity",
|
||||
(Meta.BackgroundContent) background_actor.content,
|
||||
"brightness",
|
||||
BindingFlags.DEFAULT
|
||||
);
|
||||
|
||||
var transition = new Clutter.PropertyTransition ("opacity");
|
||||
transition.set_from_value (
|
||||
((Meta.BackgroundContent) background_actor.content).brightness
|
||||
);
|
||||
transition.set_to_value (should_dim () ? DIM_OPACITY : 1.0);
|
||||
transition.duration = FADE_ANIMATION_TIME;
|
||||
transition.progress_mode = Clutter.AnimationMode.EASE_OUT_QUAD;
|
||||
transition.remove_on_complete = true;
|
||||
transition.completed.connect (() => {
|
||||
binding.unbind ();
|
||||
|
||||
background_actor.remove_child (dim_actor);
|
||||
dim_actor.destroy ();
|
||||
|
||||
changed ();
|
||||
});
|
||||
|
||||
dim_actor.add_transition ("wallpaper-dim", transition);
|
||||
|
||||
last_dim_transition = transition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ namespace Gala {
|
||||
// list of keys that are actually relevant for us
|
||||
private const string[] OPTIONS = {
|
||||
"color-shading-type",
|
||||
"picture-opacity",
|
||||
"picture-options",
|
||||
"picture-uri",
|
||||
"picture-uri-dark",
|
||||
@ -31,13 +30,23 @@ namespace Gala {
|
||||
public signal void changed ();
|
||||
|
||||
public Meta.Display display { get; construct; }
|
||||
public GLib.Settings gnome_background_settings { get; construct; }
|
||||
public GLib.Settings gnome_background_settings { get; private set; }
|
||||
|
||||
internal int use_count { get; set; default = 0; }
|
||||
|
||||
private GLib.HashTable<int, Background> backgrounds;
|
||||
private uint[] hash_cache;
|
||||
private Meta.MonitorManager? monitor_manager;
|
||||
private GLib.Settings gala_background_settings;
|
||||
|
||||
public bool should_dim {
|
||||
get {
|
||||
return (
|
||||
Granite.Settings.get_default ().prefers_color_scheme == DARK &&
|
||||
gala_background_settings.get_boolean ("dim-wallpaper-in-dark-style")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public BackgroundSource (Meta.Display display) {
|
||||
Object (display: display);
|
||||
@ -50,7 +59,12 @@ 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");
|
||||
gala_background_settings = new GLib.Settings ("io.elementary.desktop.background");
|
||||
gala_background_settings.changed["dim-wallpaper-in-dark-style"].connect (() => changed ());
|
||||
|
||||
Granite.Settings.get_default ().notify["prefers-color-scheme"].connect (() => changed ());
|
||||
|
||||
gnome_background_settings = new GLib.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
|
||||
@ -71,9 +85,6 @@ namespace Gala {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
unowned var granite_settings = Granite.Settings.get_default ();
|
||||
granite_settings.notify["prefers-color-scheme"].connect (() => changed ());
|
||||
}
|
||||
|
||||
private void monitors_changed () {
|
||||
|
Loading…
Reference in New Issue
Block a user