-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathorientation-helper
executable file
·80 lines (69 loc) · 2.04 KB
/
orientation-helper
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
#!/bin/bash
PRIMARY_DISPLAY=$(xrandr | grep primary | awk '{print $1}')
GENERIC_PROP="Coordinate Transformation Matrix"
GENERIC=""
WACOM_PROP="Wacom Rotation"
WACOM=""
function usage {
echo "KDED Orientation Helper Arguments"
echo "-o | --output : A display name like eDP-1 (primary display is used by default)"
echo "-r | --rotation : normal, bottom-up, left-up, right-up"
echo "-h | --help : Arguments help"
exit 1
}
while [ "$1" != "" ]; do
case $1 in
-o | --output ) shift
PRIMARY_DISPLAY=$1
;;
-r | --rotation ) shift
ROTATION=$1
;;
-h | --help )
usage
;;
* )
usage
esac
shift
done
if [ -z "$ROTATION" ]; then
usage
fi
if [ "$ROTATION" == "normal" ]; then
xrandr --output $PRIMARY_DISPLAY --rotate normal
GENERIC="1 0 0 0 1 0 0 0 1"
WACOM="0"
elif [ "$ROTATION" == "bottom-up" ]; then
xrandr --output $PRIMARY_DISPLAY --rotate inverted
GENERIC="-1 0 1 0 -1 1 0 0 1"
WACOM="3"
elif [ "$ROTATION" == "left-up" ]; then
xrandr --output $PRIMARY_DISPLAY --rotate left
GENERIC="0 -1 1 1 0 0 0 0 1"
WACOM="2"
elif [ "$ROTATION" == "right-up" ]; then
xrandr --output $PRIMARY_DISPLAY --rotate right
GENERIC="0 1 0 -1 0 1 0 0 1"
WACOM="1"
fi
for id in $(xinput list --id-only)
do
props=$(xinput list-props $id)
# Filter for touch devices
IS_TOUCH=$(echo $props | grep -i 'Touchscreen\|ELAN\|Pen\|Eraser\|wacom\|maXTouch\|eGalaxTouch\|IPTS')
# Apply Input Matrix for touch devices
if [ -n "$IS_TOUCH" ];
then
# Detect type of touch
HAS_WACOM=$(echo "$props" | grep "$WACOM_PROP")
HAS_GENERIC=$(echo "$props" | grep "$GENERIC_PROP")
if [ -n "$HAS_WACOM" ]
then
xinput set-prop $id "$WACOM_PROP" $WACOM 2>/dev/null
elif [ -n "$HAS_GENERIC" ]
then
xinput set-prop $id "$GENERIC_PROP" $GENERIC 2>/dev/null
fi
fi
done