-
Notifications
You must be signed in to change notification settings - Fork 0
/
mx_master_3_bindings.sh
executable file
·65 lines (49 loc) · 1.35 KB
/
mx_master_3_bindings.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
#!/usr/bin/env bash
# Dependencies:
# xdotool
# /dev/shm
set -euo pipefail
button=$1
hScrollIndexBuffer="/dev/shm/mx_master_3_scroll_buffer"
# Create temporarily file if it doesn't already exist
if [ ! -f "$hScrollIndexBuffer" ]; then
printf "L\n0\n" > "$hScrollIndexBuffer"
fi
# Horizontal scroll sensitivity reduction
hScrollModulo=3
temporizeHorizontalScroll() {
local newDirection=$@;
readarray -t buffer < "$hScrollIndexBuffer"
local oldDirection=${buffer[0]}
local value=${buffer[1]}
if [ "$oldDirection" = "$newDirection" ]; then
# increment
value=$((value+1))
value=$((value%$hScrollModulo))
else
# reset on direction change
value=1
fi
# write buffer
printf "$newDirection\n$value\n" > $hScrollIndexBuffer || value=0
# temporize scroll
if [ ${value} -ne 0 ]; then
exit
fi
}
case "$button" in
"Scroll_L")
temporizeHorizontalScroll "L"
notify-send --urgency=low "Scroll <<<"
if [[ $(xdotool getwindowfocus getwindowname) == *"Google Chrome"* ]]; then
xdotool key --clearmodifiers Control_L+Page_Up # Previous tab
fi
;;
"Scroll_R")
temporizeHorizontalScroll "R"
notify-send --urgency=low "Scroll >>>"
if [[ $(xdotool getwindowfocus getwindowname) == *"Google Chrome"* ]]; then
xdotool key --clearmodifiers Control_L+Page_Down # Next tab
fi
;;
esac