-
Notifications
You must be signed in to change notification settings - Fork 0
/
cycle-monitors.sh
executable file
·98 lines (85 loc) · 2.73 KB
/
cycle-monitors.sh
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
#!/bin/bash
####################################################################
# For current viewport information, in a fullscreen xterm:
# `xdotool getwindowgeometry --shell "$(xdotool getactivewindow)"`
# To do:
# - Load monitor configuration from ~/.config/monitors.xml
# - Daemonize at startup
# - Listen for hotkeys
# - Maintain details of MRU window in each monitor
####################################################################
#####################
# CONFIGURATION BEGIN
# Monitor sequence
C=0 # Center
L=1 # Left
R=2 # Right
# Monitor resolutions
# X Y
C_dim=( 1920 1080 )
L_dim=( 1920 1080 )
R_dim=( 1920 1080 )
# CONFIGURATION END
###################
# Minimal edge information required to work with given arrangement
L_Xr=${L_dim[0]} # | L ] R |
C_Yt=${L_dim[1]} # --=====--
C_Xl=$(( L_dim[0] / 2 )) # [ C |
# Calculate midpoint coordinates of monitors
# Center Left Right
Xmid=( $(( C_Xl + (C_dim[0] / 2) )) $(( L_dim[0] / 2 )) $(( L_Xr + (R_dim[0] / 2) )) )
Ymid=( $(( C_Yt + (C_dim[1] / 2) )) $(( L_dim[1] / 2 )) $(( R_dim[1] / 2 )) )
# Load current mouse coordinates
eval "$( xdotool getmouselocation --shell )"
# Cycle direction based on optional presence of script argument(s)
if (( "$#" > 0 )); then # Counter-clockwise
if (( Y > C_Yt )); then
# C -> R
next_mon="$R"
elif (( X < L_Xr )); then
# L -> C
next_mon="$C"
else
# R -> L
next_mon="$L"
fi
else # Clockwise
if (( Y > C_Yt )); then
# C -> L
next_mon="$L"
elif (( X < L_Xr )); then
# L -> R
next_mon="$R"
else
# R -> C
next_mon="$C"
fi
fi
###########################
# SLOPPY WINDOW FOCUS MODE:
xdotool mousemove "${Xmid[$next_mon]}" "${Ymid[$next_mon]}"
############################
## MANUAL WINDOW FOCUS MODE:
#
## Load active window coordinates
#eval "$(xdotool getwindowgeometry --shell "$(xdotool getactivewindow)")"
#
#get_window_at() {
# # Move mouse to coordinates; get window ID beneath
# eval "$(xdotool mousemove --shell "$1" "$2" getmouselocation)"
#
# # Move mouse to coordinates; get window ID beneath it; restore mouse position
# #eval "$(xdotool mousemove --shell "$1" "$2" getmouselocation mousemove restore)""
#
# # Return window ID
# echo "$WINDOW"
#}
#
#xdotool windowactivate "$(get_window_at "${Xmid[$next_mon]}" "${Ymid[$next_mon]}")"
#
## Inlining function contents does not work for some reason
## Activate window at the center of next monitor
##xdotool windowactivate \
## "$(eval \
## "$(xdotool mousemove --shell --sync "${Xmid[$next_mon]}" "${Ymid[$next_mon]}")" getmouselocation; \
## echo "$WINDOW")"