-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.js
47 lines (43 loc) · 1.67 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
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
import Meta from 'gi://Meta';
export default class TandemRaiseExtension extends Extension {
enable() {
this.focusWindowNotifyConnection = global.display.connect(
'notify::focus-window', onFocusWindowNotify
);
}
disable() {
global.display.disconnect(this.focusWindowNotifyConnection);
}
}
function onFocusWindowNotify() {
let focusedWindow = global.display.get_focus_window();
if (focusedWindow) {
let siblingWindow = findSiblingWindow(focusedWindow);
if (siblingWindow) {
// Raise the sibling window
siblingWindow.raise();
// Raise the focused window again so it's still on top of the sibling window
focusedWindow.raise();
}
}
}
function findSiblingWindow(window) {
// Only vertically maximized windows can have a sibling
if (window.get_maximized() !== Meta.MaximizeFlags.VERTICAL) {
return null;
}
let windows = window.get_display().get_workspace_manager().get_active_workspace().list_windows();
for (let candidateWindow of windows) {
// Only consider other windows
let isOtherWindow = candidateWindow !== window;
// Only consider windows on the same monitor
let isSameMonitor = window.get_monitor() === candidateWindow.get_monitor();
// Only consider vertically maximized windows
let isVerticallyMaximized = candidateWindow.get_maximized() === Meta.MaximizeFlags.VERTICAL;
if (isOtherWindow && isSameMonitor && isVerticallyMaximized) {
return candidateWindow;
}
}
return null;
}