-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonswap
executable file
·70 lines (55 loc) · 1.45 KB
/
monswap
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
#!/usr/bin/env zsh
INPUT_ADDR=0x60
# DDC/CI codes for inputs sources
INPUT_DISPLAYPORT1=15
INPUT_DISPLAYPORT2=16
INPUT_HDMI=17
INPUT_HDMI2=18
# serial numbers of monitors
MONITOR_CENTER=D2FPF43
MONITOR_LEFT=3XGX623
MONITOR_RIGHT=7SGX623
SLEEP_MULTIPLIER=0.01
DISPLAY_DATA_FILE="/tmp/vix_monitor_ids"
typeset -A display_alias=(
[center]=$MONITOR_CENTER
[left]=$MONITOR_LEFT
[right]=$MONITOR_RIGHT
)
typeset -A input_alias=(
[dp]=$INPUT_DISPLAYPORT1
[dp2]=$INPUT_DISPLAYPORT2
[hdmi]=$INPUT_HDMI
[hdmi2]=$INPUT_HDMI2
)
swapinput() {
if [ ! -f $DISPLAY_DATA_FILE ]; then
echo $(ddcutil detect --sleep-multiplier $SLEEP_MULTIPLIER --dsa | awk -v RS= -F'\n' '
BEGIN { print "typeset -A displays=(" }
match($2, / +I2C bus: \/dev\/i2c-([0-9]+)/, b) \
match($8, / +Serial number: +(\w+)/, s) \
{ print " [" s[1] "]=" b[1] }
END { print ")" }') > $DISPLAY_DATA_FILE
fi
eval $(cat $DISPLAY_DATA_FILE)
local _id=$display_alias[$1]
local _dsp=$displays[$_id]
local _inp=$input_alias[$2]
local _bar_hook_idx
case "$2" in
dp|dp2)
_bar_hook_idx=1
;;
hdmi|hdmi2)
_bar_hook_idx=2
;;
esac
ddcutil --sleep-multiplier $SLEEP_MULTIPLIER --dsa \
--bus $_dsp setvcp $INPUT_ADDR $_inp && update_bar_icon $1 $_bar_hook_idx
}
update_bar_icon() {
for i in $(pgrep -a "polybar" | cut -d" " -f1); do
polybar-msg -p "$i" hook $1-monitor-control $2 1>/dev/null 2>&1
done
}
swapinput $1 $2