Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic per-window transparency setting #325

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions resources/ui/window-row.ui
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@
</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>

<object class="AdwToast" id="picking_failure_toast">
Expand Down
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 @@ -319,8 +319,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
62 changes: 51 additions & 11 deletions src/components/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,52 @@ export const ApplicationsBlur = class ApplicationsBlur {
let whitelist = this.settings.applications.WHITELIST;
let blacklist = this.settings.applications.BLACKLIST;

// the element describing the window in whitelist, or undefined
let whitelist_element = whitelist.find(
element => element.wm_class == window_wm_class
);
// verify we are dealing with a real window
let is_a_window = [
Meta.FrameType.NORMAL,
Meta.FrameType.DIALOG,
Meta.FrameType.MODAL_DIALOG
].includes(meta_window.get_frame_type())

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))
)
&& [
Meta.FrameType.NORMAL,
Meta.FrameType.DIALOG,
Meta.FrameType.MODAL_DIALOG
].includes(meta_window.get_frame_type())
// either the window is included in whitelist or not blacklisted
if (
window_wm_class !== ""
&& !enable_all
&& whitelist_element
&& is_a_window
) {
this._log(`application ${pid} listed, blurring it`);
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
&& !(window_wm_class !== "" && blacklist.includes(window_wm_class))
&& is_a_window
) {
this._log(`application ${pid} not blacklisted, blurring it`);

// get blur effect parameters

Expand Down Expand Up @@ -220,6 +252,13 @@ export const 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 @@ -448,6 +487,7 @@ export const ApplicationsBlur = class ApplicationsBlur {

// create the actor
let blur_actor = new Clutter.Actor({
name: 'blur-actor',
x: allocation.x,
y: allocation.y,
width: allocation.width,
Expand Down
2 changes: 1 addition & 1 deletion src/conveniences/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const Keys = [
{ type: Type.I, name: "opacity" },
{ type: Type.B, name: "blur-on-overview" },
{ 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 @@ -9,7 +9,8 @@ export const 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 @@ -118,6 +119,19 @@ export const Settings = class Settings {
}
});
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 @@ -109,7 +109,7 @@ export const Applications = GObject.registerClass({

add_widgets_from_lists() {
this.preferences.applications.WHITELIST.forEach(
app_name => this.add_to_whitelist(app_name)
app => this.add_to_whitelist(app)
);

this.preferences.applications.BLACKLIST.forEach(
Expand All @@ -136,8 +136,8 @@ export const 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