-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
148 lines (113 loc) · 4.3 KB
/
extension.js
File metadata and controls
148 lines (113 loc) · 4.3 KB
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
/*
Bottom Overview
GNOME Shell 46+ extension
@fthx 2026
*/
import Clutter from 'gi://Clutter';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Meta from 'gi://Meta';
import Shell from 'gi://Shell';
import * as Layout from 'resource:///org/gnome/shell/ui/layout.js'
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
const PRESSURE_THRESHOLD = 150; // px
const HOT_EDGE_PRESSURE_TIMEOUT = 1000; // ms
const BottomOverview = GObject.registerClass(
class BottomOverview extends Clutter.Actor {
_init() {
super._init();
this._initPressureBarrier();
this._setHotEdges();
Main.layoutManager.connectObject('monitors-changed', () => this._setHotEdges(), this);
}
_initPressureBarrier() {
this._pressureBarrier = new Layout.PressureBarrier(
PRESSURE_THRESHOLD,
HOT_EDGE_PRESSURE_TIMEOUT,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW);
this._pressureBarrier?.connectObject('trigger', () => this._toggleOverview(), this);
}
_toggleOverview() {
const monitor = Main.layoutManager.primaryMonitor;
if (Main.overview.shouldToggleByCornerOrButton()
&& !(global.get_pointer()[2] & Clutter.ModifierType.BUTTON1_MASK)
&& !monitor?.inFullscreen)
Main.overview.toggle();
}
_setHotEdges() {
this._destroyBarriers();
if (this._hotEdgesTimeout)
GLib.Source.remove(this._hotEdgesTimeout);
this._hotEdgesTimeout = GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
this._setBarriers();
this._hotEdgesTimeout = null;
return GLib.SOURCE_REMOVE;
});
}
_setBarriers() {
const monitors = Main.layoutManager.monitors;
if (!monitors)
return;
for (const monitor of monitors) {
const { width: width, height: height, x, y } = monitor;
let hasBottom = true;
for (const otherMonitor of monitors) {
if (!otherMonitor || otherMonitor === monitor)
continue;
if (otherMonitor.y >= y + height
&& otherMonitor.x < x + width
&& otherMonitor.x + otherMonitor.width > x)
hasBottom = false;
}
if (hasBottom) {
const barrier = new Meta.Barrier({
backend: global.backend,
x1: x,
y1: y + height,
x2: x + width,
y2: y + height,
directions: Meta.BarrierDirection.NEGATIVE_Y
});
this._pressureBarrier?.addBarrier(barrier);
}
}
}
_destroyBarriers() {
while (this._pressureBarrier?._barriers.length > 0) {
const barrier = this._pressureBarrier?._barriers[0];
this._pressureBarrier?.removeBarrier(barrier);
barrier.destroy();
}
}
_destroyPressureBarrier() {
this._pressureBarrier?.disconnectObject(this);
this._pressureBarrier?.destroy();
this._pressureBarrier = null;
}
destroy() {
if (this._hotEdgesTimeout) {
GLib.Source.remove(this._hotEdgesTimeout);
this._hotEdgesTimeout = null;
}
Main.layoutManager.disconnectObject(this);
this._destroyBarriers();
this._destroyPressureBarrier();
super.destroy();
}
});
export default class BottomOverviewExtension {
_initBottomOverview() {
this._bottomOverview = new BottomOverview();
}
enable() {
if (Main.layoutManager._startingUp)
Main.layoutManager.connectObject('startup-complete', () => this._initBottomOverview(), this);
else
this._initBottomOverview();
}
disable() {
Main.layoutManager.disconnectObject(this);
this._bottomOverview?.destroy();
this._bottomOverview = null;
}
}