windowManager: Replace custom shader with builtin ClutterEffects
While modal dialogs were attached to the parent's titlebar, it made sense to leave the top of the parent window at full color. With the new position of modal dialogs, it makes more sense to dim the entire parent window, so we can use a combination of Clutter's BrightnessContrast- and DesaturateEffect instead of our own custom shader. https://bugzilla.gnome.org/show_bug.cgi?id=674499
This commit is contained in:
@ -15,59 +15,38 @@ const Tweener = imports.ui.tweener;
|
||||
|
||||
const SHELL_KEYBINDINGS_SCHEMA = 'org.gnome.shell.keybindings';
|
||||
const WINDOW_ANIMATION_TIME = 0.25;
|
||||
const DIM_DESATURATION = 0.6;
|
||||
const DIM_BRIGHTNESS = -0.1;
|
||||
const DIM_TIME = 0.500;
|
||||
const UNDIM_TIME = 0.250;
|
||||
|
||||
var dimShader = undefined;
|
||||
|
||||
function getDimShaderSource() {
|
||||
if (!dimShader)
|
||||
dimShader = Shell.get_file_contents_utf8_sync(global.datadir + '/shaders/dim-window.glsl');
|
||||
return dimShader;
|
||||
}
|
||||
|
||||
const WindowDimmer = new Lang.Class({
|
||||
Name: 'WindowDimmer',
|
||||
|
||||
_init: function(actor) {
|
||||
if (Clutter.feature_available(Clutter.FeatureFlags.SHADERS_GLSL)) {
|
||||
this._effect = new Clutter.ShaderEffect({ shader_type: Clutter.ShaderType.FRAGMENT_SHADER });
|
||||
this._effect.set_shader_source(getDimShaderSource());
|
||||
} else {
|
||||
this._effect = null;
|
||||
}
|
||||
|
||||
this._desaturateEffect = new Clutter.DesaturateEffect();
|
||||
this._brightnessEffect = new Clutter.BrightnessContrastEffect();
|
||||
actor.add_effect(this._desaturateEffect);
|
||||
actor.add_effect(this._brightnessEffect);
|
||||
this.actor = actor;
|
||||
this._dimFactor = 0.0;
|
||||
},
|
||||
|
||||
set dimFraction(fraction) {
|
||||
this._dimFraction = fraction;
|
||||
|
||||
if (this._effect == null)
|
||||
return;
|
||||
|
||||
if (!Meta.prefs_get_attach_modal_dialogs()) {
|
||||
this._effect.enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (fraction > 0.01) {
|
||||
Shell.shader_effect_set_double_uniform(this._effect, 'height', this.actor.get_height());
|
||||
Shell.shader_effect_set_double_uniform(this._effect, 'fraction', fraction);
|
||||
|
||||
if (!this._effect.actor)
|
||||
this.actor.add_effect(this._effect);
|
||||
} else {
|
||||
if (this._effect.actor)
|
||||
this.actor.remove_effect(this._effect);
|
||||
}
|
||||
setEnabled: function(enabled) {
|
||||
this._desaturateEffect.enabled = enabled;
|
||||
this._brightnessEffect.enabled = enabled;
|
||||
},
|
||||
|
||||
get dimFraction() {
|
||||
return this._dimFraction;
|
||||
set dimFactor(factor) {
|
||||
this._dimFactor = factor;
|
||||
this._desaturateEffect.set_factor(factor * DIM_DESATURATION);
|
||||
this._brightnessEffect.set_brightness(factor * DIM_BRIGHTNESS);
|
||||
},
|
||||
|
||||
_dimFraction: 0.0
|
||||
get dimFactor() {
|
||||
return this._dimFactor;
|
||||
}
|
||||
});
|
||||
|
||||
function getWindowDimmer(actor) {
|
||||
@ -280,8 +259,13 @@ const WindowManager = new Lang.Class({
|
||||
let actor = window.get_compositor_private();
|
||||
if (!actor)
|
||||
return;
|
||||
Tweener.addTween(getWindowDimmer(actor),
|
||||
{ dimFraction: 1.0,
|
||||
let dimmer = getWindowDimmer(actor);
|
||||
let enabled = Meta.prefs_get_attach_modal_dialogs();
|
||||
dimmer.setEnabled(enabled);
|
||||
if (!enabled)
|
||||
return;
|
||||
Tweener.addTween(dimmer,
|
||||
{ dimFactor: 1.0,
|
||||
time: DIM_TIME,
|
||||
transition: 'linear'
|
||||
});
|
||||
@ -291,8 +275,13 @@ const WindowManager = new Lang.Class({
|
||||
let actor = window.get_compositor_private();
|
||||
if (!actor)
|
||||
return;
|
||||
Tweener.addTween(getWindowDimmer(actor),
|
||||
{ dimFraction: 0.0,
|
||||
let dimmer = getWindowDimmer(actor);
|
||||
let enabled = Meta.prefs_get_attach_modal_dialogs();
|
||||
dimmer.setEnabled(enabled);
|
||||
if (!enabled)
|
||||
return;
|
||||
Tweener.addTween(dimmer,
|
||||
{ dimFactor: 0.0,
|
||||
time: UNDIM_TIME,
|
||||
transition: 'linear'
|
||||
});
|
||||
|
Reference in New Issue
Block a user