forked from shrugal/libinput-gestures
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmousemapper
executable file
·64 lines (52 loc) · 1.43 KB
/
mousemapper
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
#!/bin/bash
keyboard=$(libinput list-devices | grep keyboard -B4 | grep -E "keyboard$" -A1 | grep -o '/dev/input/event[1-9]*')
event_type=EV_KEY
action_type=POINTER_BUTTON
pressed="pressed,"
readarray -t devices <<<$(libinput list-devices | grep pointer -B4 | grep -o '/dev/input/event[0-9]*')
# COMMANDS MAP
BTN_EXTRA=(KEY_LEFTMETA KEY_PAGEUP)
BTN_SIDE=(KEY_LEFTMETA KEY_PAGEDOWN)
function pressKey(){
device=$1; key=$2; value=$3
# echo "pressing ${key} ${value}"
evemu-event ${keyboard} --sync --type ${event_type} --code ${key} --value ${value};
}
function pressCommand(){
device=$1; button=$2; movement=$3
var=$button[@]
command=${!var}
if [ ${movement} = ${pressed} ]; then
for key in ${command}; do
pressKey ${device} ${key} 1
done
else
for key in ${command}; do
pressKey ${device} ${key} 0
done | tac
fi
}
function parseEventLine(){
device=$1
action=$2
button=$4
movement=$6
# compute only if right action
if [ ${action} = ${action_type} ]; then
pressCommand ${device} ${button} ${movement}
fi
}
function mapDevice(){
device=$1
while read line; do
parseEventLine ${line}
done < <(stdbuf -oL libinput debug-events --device ${device} & )
}
if [[ ${devices[0]} == '' ]]; then
echo "No Pointers Found. Try again."
exit 1
fi
for device in ${devices[@]}; do
( mapDevice ${device} ) &
done
wait