-
Notifications
You must be signed in to change notification settings - Fork 31
/
extension.js
115 lines (95 loc) · 4.18 KB
/
extension.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
const { Meta, St } = imports.gi;
const Main = imports.ui.main;
class Extension {
constructor() {
this._actorSignalIds = null;
this._windowSignalIds = null;
}
enable() {
this._actorSignalIds = new Map();
this._windowSignalIds = new Map();
this._actorSignalIds.set(Main.overview, [
Main.overview.connect('showing', this._updateTransparent.bind(this)),
Main.overview.connect('hiding', this._updateTransparent.bind(this))
]);
this._actorSignalIds.set(Main.sessionMode, [
Main.sessionMode.connect('updated', this._updateTransparent.bind(this))
]);
for (const metaWindowActor of global.get_window_actors()) {
this._onWindowActorAdded(metaWindowActor.get_parent(), metaWindowActor);
}
this._actorSignalIds.set(global.window_group, [
global.window_group.connect('actor-added', this._onWindowActorAdded.bind(this)),
global.window_group.connect('actor-removed', this._onWindowActorRemoved.bind(this))
]);
this._actorSignalIds.set(global.window_manager, [
global.window_manager.connect('switch-workspace', this._updateTransparent.bind(this))
]);
this._updateTransparent();
}
disable() {
for (const actorSignalIds of [this._actorSignalIds, this._windowSignalIds]) {
for (const [actor, signalIds] of actorSignalIds) {
for (const signalId of signalIds) {
actor.disconnect(signalId);
}
}
}
this._actorSignalIds = null;
this._windowSignalIds = null;
Main.panel.remove_style_class_name('transparent-top-bar--solid');
Main.panel.remove_style_class_name('transparent-top-bar--transparent');
}
_onWindowActorAdded(container, metaWindowActor) {
this._windowSignalIds.set(metaWindowActor, [
metaWindowActor.connect('notify::allocation', this._updateTransparent.bind(this)),
metaWindowActor.connect('notify::visible', this._updateTransparent.bind(this))
]);
}
_onWindowActorRemoved(container, metaWindowActor) {
for (const signalId of this._windowSignalIds.get(metaWindowActor)) {
metaWindowActor.disconnect(signalId);
}
this._windowSignalIds.delete(metaWindowActor);
this._updateTransparent();
}
_updateTransparent() {
if (Main.panel.has_style_pseudo_class('overview') || !Main.sessionMode.hasWindows) {
this._setTransparent(true);
return;
}
if (!Main.layoutManager.primaryMonitor) {
return;
}
// Get all the windows in the active workspace that are in the primary monitor and visible.
const workspaceManager = global.workspace_manager;
const activeWorkspace = workspaceManager.get_active_workspace();
const windows = activeWorkspace.list_windows().filter(metaWindow => {
return metaWindow.is_on_primary_monitor()
&& metaWindow.showing_on_its_workspace()
&& !metaWindow.is_hidden()
&& metaWindow.get_window_type() !== Meta.WindowType.DESKTOP;
});
// Check if at least one window is near enough to the panel.
const panelTop = Main.panel.get_transformed_position()[1];
const panelBottom = panelTop + Main.panel.get_height();
const scale = St.ThemeContext.get_for_stage(global.stage).scale_factor;
const isNearEnough = windows.some(metaWindow => {
const verticalPosition = metaWindow.get_frame_rect().y;
return verticalPosition < panelBottom + 5 * scale;
});
this._setTransparent(!isNearEnough);
}
_setTransparent(transparent) {
if (transparent) {
Main.panel.remove_style_class_name('transparent-top-bar--solid');
Main.panel.add_style_class_name('transparent-top-bar--transparent');
} else {
Main.panel.add_style_class_name('transparent-top-bar--solid');
Main.panel.remove_style_class_name('transparent-top-bar--transparent');
}
}
};
function init() {
return new Extension();
}