From 33d3481cde946df5f07164444bf6ad0621c06860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Hamy?= Date: Fri, 26 Aug 2022 18:59:45 +0200 Subject: [PATCH] Add basic per-window transparency setting This may be too hard to maintain, and does not add a lot of good to the extension. --- resources/ui/window-row.ui | 15 ++++++ ...shell.extensions.blur-my-shell.gschema.xml | 4 +- src/components/applications.js | 48 ++++++++++++++++--- src/conveniences/keys.js | 2 +- src/conveniences/settings.js | 16 ++++++- src/preferences/applications.js | 6 +-- 6 files changed, 78 insertions(+), 13 deletions(-) diff --git a/resources/ui/window-row.ui b/resources/ui/window-row.ui index 6cf82bbb..b8f0cd93 100644 --- a/resources/ui/window-row.ui +++ b/resources/ui/window-row.ui @@ -34,5 +34,20 @@ + + + + Opacity + The opacity of the selected window, useful if the application itself is opaque. + window_opacity + + + + center + true + + + + \ No newline at end of file diff --git a/schemas/org.gnome.shell.extensions.blur-my-shell.gschema.xml b/schemas/org.gnome.shell.extensions.blur-my-shell.gschema.xml index d6ccd9c6..3920a9ae 100644 --- a/schemas/org.gnome.shell.extensions.blur-my-shell.gschema.xml +++ b/schemas/org.gnome.shell.extensions.blur-my-shell.gschema.xml @@ -298,8 +298,8 @@ Wether or not to blur all applications by default - - [] + + {} List of applications to blur diff --git a/src/components/applications.js b/src/components/applications.js index b9050548..4150241d 100644 --- a/src/components/applications.js +++ b/src/components/applications.js @@ -132,15 +132,44 @@ var ApplicationsBlur = class ApplicationsBlur { let whitelist = this.prefs.applications.WHITELIST; let blacklist = this.prefs.applications.BLACKLIST; + // the element describing the window in whitelist, or undefined + let whitelist_element = whitelist.find( + element => element.wm_class == window_wm_class + ); + this._log(`checking blur for ${pid}`); // either the window is included in whitelist - if (window_wm_class !== "" - && ((enable_all && !blacklist.includes(window_wm_class)) - || (!enable_all && whitelist.includes(window_wm_class)) - ) + if ( + window_wm_class !== "" + && !enable_all + && whitelist_element + ) { + this._log(`application ${pid} whitelisted, blurring it`); + + // get blur effect parameters + + let brightness, sigma; + + if (this.prefs.applications.CUSTOMIZE) { + brightness = this.prefs.applications.BRIGHTNESS; + sigma = this.prefs.applications.SIGMA; + } else { + brightness = this.prefs.BRIGHTNESS; + sigma = this.prefs.SIGMA; + } + + this.set_opacity(window_actor, whitelist_element.opacity); + + this.update_blur(pid, window_actor, meta_window, brightness, sigma); + } + + // or enable_all is on, and application is not on blacklist + else if ( + enable_all + && !blacklist.includes(window_wm_class) ) { - this._log(`application ${pid} listed, blurring it`); + this._log(`application ${pid} not blacklisted, blurring it`); // get blur effect parameters @@ -177,6 +206,13 @@ var ApplicationsBlur = class ApplicationsBlur { } } + set_opacity(window_actor, opacity) { + window_actor.get_children().forEach(child => { + if (child.name !== "blur-actor") + child.opacity = opacity; + }); + } + /// When given the xprop property, returns the brightness and sigma values /// matching. If one of the two values is invalid, or missing, then it uses /// default values. @@ -360,7 +396,7 @@ var ApplicationsBlur = class ApplicationsBlur { }); // create the actor and add the constraints - let blur_actor = new Clutter.Actor(); + let blur_actor = new Clutter.Actor({ name: 'blur-actor' }); blur_actor.add_constraint(constraint_width); blur_actor.add_constraint(constraint_height); diff --git a/src/conveniences/keys.js b/src/conveniences/keys.js index d6176077..b4e5f511 100644 --- a/src/conveniences/keys.js +++ b/src/conveniences/keys.js @@ -82,7 +82,7 @@ var Keys = [ { type: Type.D, name: "noise-amount" }, { type: Type.D, name: "noise-lightness" }, { type: Type.B, name: "enable-all" }, - { type: Type.AS, name: "whitelist" }, + { type: Type.ASD, name: "whitelist" }, { type: Type.AS, name: "blacklist" }, ] }, diff --git a/src/conveniences/settings.js b/src/conveniences/settings.js index d62569fc..b2143b13 100644 --- a/src/conveniences/settings.js +++ b/src/conveniences/settings.js @@ -11,7 +11,8 @@ var Type = { D: 'Double', S: 'String', C: 'Color', - AS: 'StringArray' + AS: 'StringArray', + ASD: 'StringDoubleArray' }; /// An object to get and manage the gsettings preferences. @@ -120,6 +121,19 @@ var Prefs = class Prefs { } }); break; + + case Type.ASD: + Object.defineProperty(component, property_name, { + get() { + let val = component_settings.get_value(key.name); + return val.recursiveUnpack(); + }, + set(v) { + let val = new GLib.Variant("aa{sd}", v); + component_settings.set_value(key.name, val); + } + }); + break; } component[property_name + '_reset'] = function () { diff --git a/src/preferences/applications.js b/src/preferences/applications.js index 39cb75b9..9573a72c 100644 --- a/src/preferences/applications.js +++ b/src/preferences/applications.js @@ -72,7 +72,7 @@ var Applications = GObject.registerClass({ // add initial applications this.preferences.applications.WHITELIST.forEach( - app_name => this.add_to_whitelist(app_name) + app => this.add_to_whitelist(app) ); this.preferences.applications.BLACKLIST.forEach( app_name => this.add_to_blacklist(app_name) @@ -99,8 +99,8 @@ var Applications = GObject.registerClass({ } } - add_to_whitelist(app_name = null) { - let window_row = new WindowRow('whitelist', this, app_name); + add_to_whitelist(app = {}) { + let window_row = new WindowRow('whitelist', this, app.wm_class); this._whitelist.add(window_row); }