-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwindow-utils.js
More file actions
72 lines (62 loc) · 2.04 KB
/
window-utils.js
File metadata and controls
72 lines (62 loc) · 2.04 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
// utility functions for windows
const Main = imports.ui.main;
const Panel = imports.ui.panel;
// get the screen area excluding the panels
function getUsableScreenArea(displayIdx) {
// If we received a display index number, get the geometry
if (typeof displayIdx !== 'number') {
global.logError('getUsableScreenArea: displayIdx is not a number');
return null;
}
const display = global.display.get_monitor_geometry(displayIdx);
let top = display.y;
let bottom = display.y + display.height;
let left = display.x;
let right = display.x + display.width;
// Get panels for this display
for (let panel of Main.panelManager.getPanelsInMonitor(displayIdx)) {
if (!panel.isHideable()) {
switch (panel.panelPosition) {
case Panel.PanelLoc.top:
top += panel.height;
break;
case Panel.PanelLoc.bottom:
bottom -= panel.height;
break;
case Panel.PanelLoc.left:
left += panel.height;
break;
case Panel.PanelLoc.right:
right -= panel.height;
break;
}
}
}
let width = Math.max(0, right - left);
let height = Math.max(0, bottom - top);
return { x: left, y: top, width: width, height: height };
}
// Snap window to a node in the layout
function snapToRect(metaWindow, rect) {
if (!metaWindow || !rect) {
global.logError('No metaWindow or rect');
return;
}
let clientRect = metaWindow.get_frame_rect();
// Check if window is already at desired position and size
if (clientRect.x === rect.x &&
clientRect.y === rect.y &&
clientRect.width === rect.width &&
clientRect.height === rect.height) {
return;
}
metaWindow.move_resize_frame(
false,
rect.x, rect.y,
rect.width, rect.height);
}
// Export the module
module.exports = {
getUsableScreenArea,
snapToRect
};