-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonitor-select.awk
More file actions
37 lines (27 loc) · 951 Bytes
/
monitor-select.awk
File metadata and controls
37 lines (27 loc) · 951 Bytes
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
# Gets the primary monitor from xrandr 1.4.3
# If there is no primary monitor, gets the topmost leftmost monitor
# Skip all checks if we found the primary monitor already
got_primary == 1 { next; }
# Skip any unconnected monitors or non-monitor lines
$2 != "connected" { next; }
# Choose the primary monitor above all other monitors
$3 == "primary" { mode = $4; got_primary = 1; next; }
# This is the first monitor; take it
mode == "" { mode = $3; next; }
# This monitor is a candidate; compare it to the current monitor
function afterplus(mode)
{
return substr(mode, index(mode, "+")+1)
}
{
cur_offset = afterplus(mode);
new_offset = afterplus($3);
cur_x = cur_offset+0;
cur_y = afterplus(cur_offset)+0;
new_x = new_offset+0;
new_y = afterplus(new_offset)+0;
if (new_x < cur_x || (new_x == cur_x && new_y < cur_y))
mode = $3;
}
# Print the best monitor in a manner parsable by read(1)
END { gsub(/[x+]/, " ", mode); print mode; }