Skip to content

Commit

Permalink
Add basic per-window transparency setting
Browse files Browse the repository at this point in the history
This may be too hard to maintain, and does not add a lot of good to the extension.
  • Loading branch information
aunetx committed Aug 26, 2022
1 parent 9985fed commit 5947375
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 13 deletions.
15 changes: 15 additions & 0 deletions resources/ui/window-row.ui
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,20 @@
</child>
</object>
</child>

<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Opacity</property>
<property name="subtitle" translatable="yes">The opacity of the selected window, useful if the application itself is opaque.</property>
<property name="activatable-widget">window_opacity</property>

<child>
<object class="GtkScale" id="window_opacity">
<property name="valign">center</property>
<property name="hexpand">true</property>
</object>
</child>
</object>
</child>
</template>
</interface>
4 changes: 2 additions & 2 deletions schemas/org.gnome.shell.extensions.blur-my-shell.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@
<summary>Wether or not to blur all applications by default</summary>
</key>
<!-- WHITELIST -->
<key type="as" name="whitelist">
<default>[]</default>
<key type="aa{sd}" name="whitelist">
<default>{}</default>
<summary>List of applications to blur</summary>
</key>
<!-- BLACKLIST -->
Expand Down
48 changes: 42 additions & 6 deletions src/components/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/conveniences/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
]
},
Expand Down
16 changes: 15 additions & 1 deletion src/conveniences/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 () {
Expand Down
6 changes: 3 additions & 3 deletions src/preferences/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down

0 comments on commit 5947375

Please sign in to comment.