mirror of
https://github.com/elementary/gala.git
synced 2024-08-16 18:40:27 +03:00
Option to dim wallpapers when dark style is active (#1462)
This commit is contained in:
parent
d9ebac365c
commit
16492b1f71
@ -24,6 +24,14 @@
|
||||
</key>
|
||||
</schema>
|
||||
|
||||
<schema path="/io/elementary/desktop/background/" id="io.elementary.desktop.background">
|
||||
<key type="b" name="dim-wallpaper-in-dark-style">
|
||||
<default>false</default>
|
||||
<summary>Dim wallpapers when dark style is active</summary>
|
||||
<description></description>
|
||||
</key>
|
||||
</schema>
|
||||
|
||||
<schema path="/org/pantheon/desktop/gala/behavior/" id="org.pantheon.desktop.gala.behavior">
|
||||
<key enum="GalaActionType" name="hotcorner-topleft">
|
||||
<default>"none"</default>
|
||||
|
@ -17,7 +17,10 @@
|
||||
|
||||
namespace Gala {
|
||||
public class BackgroundManager : Meta.BackgroundGroup {
|
||||
const string BACKGROUND_SCHEMA = "org.gnome.desktop.background";
|
||||
const string GNOME_BACKGROUND_SCHEMA = "org.gnome.desktop.background";
|
||||
const string GALA_BACKGROUND_SCHEMA = "io.elementary.desktop.background";
|
||||
const string DIM_WALLPAPER_KEY = "dim-wallpaper-in-dark-style";
|
||||
const double DIM_OPACITY = 0.85;
|
||||
const int FADE_ANIMATION_TIME = 1000;
|
||||
|
||||
public signal void changed ();
|
||||
@ -30,19 +33,27 @@ namespace Gala {
|
||||
Meta.BackgroundActor background_actor;
|
||||
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_SCHEMA);
|
||||
background_source = BackgroundCache.get_default ().get_background_source (display, GNOME_BACKGROUND_SCHEMA);
|
||||
background_actor = create_background_actor ();
|
||||
|
||||
destroy.connect (on_destroy);
|
||||
}
|
||||
|
||||
void on_destroy () {
|
||||
BackgroundCache.get_default ().release_background_source (BACKGROUND_SCHEMA);
|
||||
BackgroundCache.get_default ().release_background_source (GNOME_BACKGROUND_SCHEMA);
|
||||
background_source = null;
|
||||
|
||||
if (new_background_actor != null) {
|
||||
@ -139,10 +150,24 @@ namespace Gala {
|
||||
|
||||
#if HAS_MUTTER338
|
||||
((Meta.BackgroundContent)background_actor.content).background = background.background;
|
||||
((Meta.BackgroundContent)background_actor.content).vignette = true;
|
||||
#else
|
||||
background_actor.background = background.background;
|
||||
background_actor.vignette = true;
|
||||
#endif
|
||||
|
||||
// Don't play dim animation when launching gala or switching wallpaper
|
||||
if (should_dim ()) {
|
||||
#if HAS_MUTTER338
|
||||
((Meta.BackgroundContent)background_actor.content).brightness = DIM_OPACITY;
|
||||
#else
|
||||
background_actor.brightness = DIM_OPACITY;
|
||||
#endif
|
||||
}
|
||||
|
||||
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);
|
||||
@ -174,5 +199,64 @@ namespace Gala {
|
||||
|
||||
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",
|
||||
#if HAS_MUTTER338
|
||||
(Meta.BackgroundContent) background_actor.content,
|
||||
#else
|
||||
background_actor,
|
||||
#endif
|
||||
"brightness",
|
||||
BindingFlags.DEFAULT
|
||||
);
|
||||
|
||||
var transition = new Clutter.PropertyTransition ("opacity");
|
||||
transition.set_from_value (
|
||||
#if HAS_MUTTER338
|
||||
((Meta.BackgroundContent) background_actor.content).brightness
|
||||
#else
|
||||
background_actor.brightness
|
||||
#endif
|
||||
);
|
||||
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 ();
|
||||
});
|
||||
|
||||
dim_actor.add_transition ("wallpaper-dim", transition);
|
||||
|
||||
last_dim_transition = transition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user