/
panel.js
186 lines (157 loc) · 5.93 KB
/
panel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
'use strict';
const { St, Shell, Meta, Gio, GLib } = imports.gi;
const Main = imports.ui.main;
const backgroundSettings = new Gio.Settings({ schema: 'org.gnome.desktop.background' })
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Settings = Me.imports.settings;
let prefs = new Settings.Prefs;
const default_sigma = 30;
const default_brightness = 0.6;
// useful
const setTimeout = function (func, delay, ...args) {
return GLib.timeout_add(GLib.PRIORITY_DEFAULT, delay, () => {
func(...args);
return GLib.SOURCE_REMOVE;
});
};
var PanelBlur = class PanelBlur {
constructor(connections) {
this.connections = connections;
this.effect = new Shell.BlurEffect({
brightness: default_brightness,
sigma: default_sigma,
mode: prefs.STATIC_BLUR.get() ? 0 : 1
});
this.background_parent = new St.Widget({
style_class: 'topbar-blurred-background-parent',
x: this.monitor.x,
y: this.monitor.y,
width: this.monitor.width,
height: 0,
});
this.background = prefs.STATIC_BLUR.get() ? new Meta.BackgroundActor : new St.Widget({
style_class: 'topbar-blurred-background',
x: 0,
y: 0,
width: this.monitor.width,
height: Main.panel.height,
});
this.background_parent.add_child(this.background);
}
enable() {
this._log("blurring top panel");
// insert background parent
Main.panel.get_parent().insert_child_at_index(this.background_parent, 0);
// hide corners, can't style them
Main.panel._leftCorner.hide();
Main.panel._rightCorner.hide();
// perform updates
this.change_blur_type();
// connect to size, monitor or wallpaper changes
this.connections.connect(Main.panel, 'notify::height', () => {
this.update_size(prefs.STATIC_BLUR.get());
});
this.connections.connect(Main.layoutManager, 'monitors-changed', () => {
this.update_wallpaper(prefs.STATIC_BLUR.get());
this.update_size(prefs.STATIC_BLUR.get());
});
this.connections.connect(backgroundSettings, 'changed', () => {
setTimeout(() => { this.update_wallpaper(prefs.STATIC_BLUR.get()) }, 100);
});
}
change_blur_type() {
let is_static = prefs.STATIC_BLUR.get();
this.background_parent.remove_child(this.background);
this.background.remove_effect(this.effect);
this.background = is_static ? new Meta.BackgroundActor : new St.Widget({
style_class: 'topbar-blurred-background',
x: 0,
y: 0,
width: this.monitor.width,
height: Main.panel.height,
});
this.effect.set_mode(is_static ? 0 : 1);
this.background.add_effect(this.effect);
this.background_parent.add_child(this.background);
this.update_wallpaper(is_static);
this.update_size(is_static);
// HACK
if (!is_static) {
// ! DIRTY PART: hack because `Shell.BlurEffect` does not repaint when shadows are under it
// ! this does not entirely fix this bug (shadows caused by windows still cause artefacts)
// ! but it prevents the shadows of the panel buttons to cause artefacts on the panel itself
// ! note: issue opened at https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2857
if (prefs.HACKS_LEVEL.get() == 1) {
this._log("panel hack level 1");
let rp = () => {
this.effect.queue_repaint()
};
this.connections.connect(Main.panel, 'enter-event', rp);
this.connections.connect(Main.panel, 'leave-event', rp);
this.connections.connect(Main.panel, 'button-press-event', rp);
Main.panel.get_children().forEach(child => {
this.connections.connect(child, 'enter-event', rp);
this.connections.connect(child, 'leave-event', rp);
this.connections.connect(child, 'button-press-event', rp);
});
} else if (prefs.HACKS_LEVEL.get() == 2) {
this._log("panel hack level 2");
// disabled because of #31
/*
Main.panel.get_children().forEach(child => {
this.connections.connect(child, 'paint', () => {
this.effect.queue_repaint();
});
});
*/
}
// ! END OF DIRTY PART
}
}
update_wallpaper(is_static) {
if (is_static) {
let bg = Main.layoutManager._backgroundGroup.get_child_at_index(this.monitor.index);
this.background.set_content(bg.get_content());
}
}
update_size(is_static) {
if (is_static) {
this.background.set_clip(
this.monitor.x,
this.monitor.y,
Main.panel.width,
Main.panel.height
);
} else {
this.background.height = Main.panel.height
this.background.width = this.monitor.width;
this.background_parent.width = this.monitor.width;
}
}
get monitor() {
return Main.layoutManager.primaryMonitor
}
set_sigma(s) {
this.effect.sigma = s;
}
set_brightness(b) {
this.effect.brightness = b;
}
disable() {
this._log("removing blur from top panel");
Main.panel._leftCorner.show();
Main.panel._rightCorner.show();
try {
this.background_parent.get_parent().remove_child(this.background_parent);
} catch (e) { }
}
show() {
this.background_parent.show();
}
hide() {
this.background_parent.hide();
}
_log(str) {
log(`[Blur my Shell] ${str}`)
}
}