-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathextension.js
386 lines (316 loc) · 13.2 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/*
Dock from Dash - GNOME Shell 46+ extension
Copyright Francois Thirioux 2025
GitHub contributors: @fthx, @rastersoft, @underlinejakez, @lucaxvi, @subpop
Some ideas picked from GNOME Shell native code
Bottom edge code adapted from @jdoda's Hot Edge extension
License GPL v3
*/
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 Main from 'resource:///org/gnome/shell/ui/main.js';
import * as Layout from 'resource:///org/gnome/shell/ui/layout.js'
import * as Dash from 'resource:///org/gnome/shell/ui/dash.js';
import * as AppDisplay from 'resource:///org/gnome/shell/ui/appDisplay.js';
// Dock settings
const DASH_MAX_HEIGHT_RATIO = 15; // %
const AUTO_HIDE_DELAY = 300; // ms
const SHOWING_ANIMATION_DURATION = 150; // ms
const HIDING_ANIMATION_DURATION = 150; // ms
const SHOW_OVERVIEW_AT_STARTUP = false;
// Bottom edge settings
const HOT_EDGE_PRESSURE_TIMEOUT = 1000; // ms
const PRESSURE_TRESHOLD = 150;
const BottomDock = GObject.registerClass(
{ Signals: {'toggle-dash': {}}, },
class BottomDock extends Clutter.Actor {
_init(layoutManager, monitor, x, y) {
super._init();
this._monitor = monitor;
this._x = x;
this._y = y;
this._pressure_threshold = PRESSURE_TRESHOLD;
this._pressure_barrier = new Layout.PressureBarrier(
this._pressure_threshold,
HOT_EDGE_PRESSURE_TIMEOUT,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW);
this._pressure_barrier.connectObject('trigger', this._toggle_dock.bind(this), this);
this.connectObject('destroy', this._on_destroy.bind(this), this);
}
setBarrierSize(size) {
if (this._barrier) {
this._pressure_barrier.removeBarrier(this._barrier);
this._barrier.destroy();
this._barrier = null;
}
if (size > 0) {
size = this._monitor.width;
let x_offset = (this._monitor.width - size) / 2;
this._barrier = new Meta.Barrier({
backend: global.backend,
x1: this._x + x_offset, x2: this._x + x_offset + size,
y1: this._y, y2: this._y,
directions: Meta.BarrierDirection.NEGATIVE_Y});
this._pressure_barrier.addBarrier(this._barrier);
}
}
_on_destroy() {
this.setBarrierSize(0);
this._pressure_barrier?.destroy();
this._pressure_barrier = null;
super.destroy();
}
_toggle_dock() {
if (Main.overview.shouldToggleByCornerOrButton())
this.emit('toggle-dash');
}
});
const Dock = GObject.registerClass(
class Dock extends Dash.Dash {
_init() {
super._init();
Main.layoutManager.addTopChrome(this);
this.showAppsButton.set_toggle_mode(false);
this._dashContainer.set_track_hover(true);
this._dashContainer.set_reactive(true);
this.show();
this._dock_animated = false;
this._keep_dock_shown = false;
this._dragging;
this._dashContainer.connectObject('notify::hover', this._on_dock_hover.bind(this), this);
this._dashContainer.connectObject('scroll-event', (actor, event) => Main.wm.handleWorkspaceScroll(event), this);
this.showAppsButton.connectObject('button-release-event', () => Main.overview.showApps(), this);
Main.overview.connectObject('item-drag-begin', () => {this._dragging = true;}, this);
Main.overview.connectObject('item-drag-end', () => {this._dragging = false;}, this);
global.display.connectObject('workareas-changed', this._dock_refresh.bind(this), this);
Main.overview.connectObject('shown', () => this.hide(), this);
this._dock_refresh();
}
_itemMenuStateChanged(item, opened) {
if (opened) {
if (this._showLabelTimeoutId > 0) {
GLib.source_remove(this._showLabelTimeoutId);
this._showLabelTimeoutId = 0;
}
item.hideLabel();
this._last_appicon_with_menu = item;
this._keep_dock_shown = true;
} else {
if (item == this._last_appicon_with_menu) {
this._last_appicon_with_menu = null;
this._keep_dock_shown = false
}
}
this._on_dock_hover();
}
_queueRedisplay() {
if (this._workId)
Main.queueDeferredWork(this._workId);
}
_on_dock_hover() {
if (!this._dashContainer.get_hover() && !this._keep_dock_shown) {
this._auto_hide_dock_timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, AUTO_HIDE_DELAY, () => {
if (!this._dashContainer.get_hover()) {
this._hide_dock();
this._auto_hide_dock_timeout = 0;
}
});
}
}
_ensure_auto_hide_dock() {
if (!this._dashContainer.get_hover() && !this._keep_dock_shown) {
this._ensure_auto_hide_dock_timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 3 * AUTO_HIDE_DELAY, () => {
if (!this._dashContainer.get_hover() && (this._auto_hide_dock_timeout == 0)) {
this._hide_dock();
this._ensure_auto_hide_dock_timeout = 0;
}
});
}
}
_hide_dock() {
if (this._dock_animated || !this.work_area || this._dragging)
return;
this._dock_animated = true;
this.ease({
duration: HIDING_ANIMATION_DURATION,
y: this.work_area.y + this.work_area.height,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => {
this._dock_animated = false;
this.hide();
},
});
}
_show_dock() {
if (this._dock_animated || !this.work_area)
return;
this.show();
this._dock_animated = true;
this.ease({
duration: SHOWING_ANIMATION_DURATION,
y: this.work_area.y + this.work_area.height - this.height,
mode: Clutter.AnimationMode.EASE_IN_QUAD,
onComplete: () => {
this._dock_animated = false;
},
});
}
_toggle_dock() {
if (Main.overview.visible)
return;
if (this.is_visible())
this._hide_dock();
else
this._show_dock();
}
_dock_refresh() {
if (this._dock_refreshing)
return;
this._dock_refreshing = true;
this.work_area = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
if (!this.work_area)
return;
this.max_dock_height = Math.round(this.work_area.height * DASH_MAX_HEIGHT_RATIO / 100);
this.set_width(this.work_area.width);
this.set_height(Math.min(this.get_preferred_height(this.work_area.width), this.max_dock_height));
this.setMaxSize(this.width, this.max_dock_height);
if (this.is_visible())
this.set_position(this.work_area.x, this.work_area.y + this.work_area.height - this.height);
else
this.set_position(this.work_area.x, this.work_area.y + this.work_area.height);
this.show();
if (!this._dashContainer.get_hover())
this._hide_dock();
this._dock_refreshing = false;
}
_destroy() {
Main.overview.disconnectObject(this);
this._dashContainer.disconnectObject(this);
this.showAppsButton.disconnectObject(this);
global.display.disconnectObject(this);
if (this._auto_hide_dock_timeout) {
GLib.source_remove(this._auto_hide_dock_timeout);
this._auto_hide_dock_timeout = 0;
}
if (this._ensure_auto_hide_dock_timeout) {
GLib.source_remove(this._ensure_auto_hide_dock_timeout);
this._ensure_auto_hide_dock = 0;
}
this._show_dock();
this._workId = null;
super.destroy();
}
});
export default class DockFromDashExtension {
constructor() {
this._edge_handler_id = null;
}
_update_hot_edges() {
Main.layoutManager._destroyHotCorners();
for (let i = 0; i < Main.layoutManager.monitors.length; i++) {
let monitor = Main.layoutManager.monitors[i];
let leftX = monitor.x;
let rightX = monitor.x + monitor.width;
let bottomY = monitor.y + monitor.height;
let size = monitor.width;
let haveBottom = true;
for (let j = 0; j < Main.layoutManager.monitors.length; j++) {
if (j != i) {
let otherMonitor = Main.layoutManager.monitors[j];
let otherLeftX = otherMonitor.x;
let otherRightX = otherMonitor.x + otherMonitor.width;
let otherTopY = otherMonitor.y;
if (otherTopY >= bottomY && otherLeftX < rightX && otherRightX > leftX) {
haveBottom = false;
}
}
}
if (haveBottom) {
let edge = new BottomDock(Main.layoutManager, monitor, leftX, bottomY);
edge.connectObject('toggle-dash', () => this._dock._toggle_dock(), this);
edge.connectObject('toggle-dash', () => this._dock._ensure_auto_hide_dock(), this);
edge.setBarrierSize(size);
Main.layoutManager.hotCorners.push(edge);
} else
Main.layoutManager.hotCorners.push(null);
}
}
_modify_native_click_behavior() {
this.original_click_function = AppDisplay.AppIcon.prototype.activate;
AppDisplay.AppIcon.prototype.activate = function(button) {
let event = Clutter.get_current_event();
let modifiers = event ? event.get_state() : 0;
let isMiddleButton = button && button == Clutter.BUTTON_MIDDLE;
let isCtrlPressed = (modifiers & Clutter.ModifierType.CONTROL_MASK) != 0;
let openNewWindow = this.app.can_open_new_window() && this.app.state == Shell.AppState.RUNNING && (isCtrlPressed || isMiddleButton);
if (this.app.state == Shell.AppState.STOPPED || openNewWindow)
this.animateLaunch();
if (openNewWindow) {
this.app.open_new_window(-1);
Main.overview.hide();
} else {
let app_windows = this.app
.get_windows()
.filter(window => !window.is_override_redirect() && !window.is_attached_dialog() && window.located_on_workspace(global.workspace_manager.get_active_workspace()))
.sort((w1, w2) => w1.get_id() - w2.get_id());
switch (app_windows.length) {
case 0:
this.app.activate();
Main.overview.hide();
break;
case 1:
if (app_windows[0].has_focus() && app_windows[0].can_minimize()) {
app_windows[0].minimize();
Main.overview.hide();
} else {
if (!app_windows[0].has_focus()) {
app_windows[0].activate(global.get_current_time());
Main.overview.hide();
}
}
break;
default:
if (Main.overview.visible) {
this.app.activate();
Main.overview.hide();
} else {
let app_has_focus = false;
let app_focused_window_index = 0;
for (var index = 0; index < app_windows.length; index++) {
if (app_windows[index].has_focus()) {
app_has_focus = true;
app_focused_window_index = index;
}
}
if (app_has_focus) {
let next_index = (app_focused_window_index + 1) % app_windows.length;
this.app.activate_window(app_windows[next_index], global.get_current_time());
} else
this.app.activate();
}
}
}
}
}
enable() {
this._modify_native_click_behavior();
this._dock = new Dock();
Main.layoutManager.connectObject('hot-corners-changed', this._update_hot_edges.bind(this), this);
Main.layoutManager._updateHotCorners();
Main.layoutManager.connectObject('startup-complete', () => {
if (!SHOW_OVERVIEW_AT_STARTUP)
Main.overview.hide();
},
this);
}
disable() {
AppDisplay.AppIcon.prototype.activate = this.original_click_function;
Main.layoutManager.disconnectObject(this);
this._dock._destroy();
this._dock = null;
Main.layoutManager._updateHotCorners();
}
}