blob: c4b0c2bb880018fc800023ffd10485da9cc2b3ab (
plain)
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
|
#!/bin/bash
# This script handles rotation of the screen and related input devices automatically
# using the output of the monitor-sensor command (part of the iio-sensor-proxy package)
# for sway.
# The target screen and input device names should be configured in the below variables.
# Note: input devices using the libinput driver (e.g. touchscreens) should be included
# in the WAYLANDINPUT array.
#
# You can get a list of input devices with the `swaymsg -t output` command.
#
# This scritp was frok from https://gitlab.com/snippets/1793649 by Fishonadish
SCREEN="eDP-1"
WAYLANDINPUT=("1118:2485:Microsoft_Surface_Keyboard_Touchpad" "1267:10780:ELAN9038:00_04F3:2A1C")
function rotate_ms {
case $1 in
"normal")
rotate 0
;;
"right-up")
rotate 90
;;
"bottom-up")
rotate 180
;;
"left-up")
rotate 270
;;
esac
}
function rotate {
TARGET_ORIENTATION=$1
echo "Rotating to" $TARGET_ORIENTATION
swaymsg output $SCREEN transform $TARGET_ORIENTATION
for i in "${WAYLANDINPUT[@]}"
do
swaymsg input "$i" map_to_output "$SCREEN"
done
}
while IFS='$\n' read -r line; do
rotation="$(echo $line | sed -En "s/^.*orientation changed: (.*)/\1/p")"
[[ ! -z $rotation ]] && rotate_ms $rotation
done < <(stdbuf -oL monitor-sensor)
|