summaryrefslogtreecommitdiff
path: root/scripts/Scripts/xrotate
blob: fabe98b323aab169e0359442a0682549abadc80c (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
set -e

function help() {
    echo "Rotate the screen and mouse input"
    echo
    echo "Syntax: ${BINNAME} [<options>] <orientation>"
    echo "Orientation: normal,inverted,left,right"
    echo "Options:"
    echo "  -d, --disp <DISPLAY>    set for xrandr DISPLAY"
    echo "  -h, --help              this help message"
}

# Fix hardcode
DISP=LVDS1

BINNAME="xrotate"

# Parse some args
while [[ $# -gt 0 ]]; do
    case $1 in
        -d|--disp)
            shift
            DISP=$1
            shift
            ;;
        -h|--help)
            help
            exit 0
            ;;
        *)
            if [[ $1 == '-'* ]]; then
                echo unknown option $1
                help
                exit 1
            fi
            break
            ;;
    esac
done

O=$1

MOUSE=$(xinput list | grep "slave  pointer" | awk '{print $6}' | awk -F '=' '{print $2}')

case $O in
    normal)
        echo "Normal"
        MATRIX="1 0 0 0 1 0 0 0 1"
        ;;
    inverted)
        echo "Inverted"
        MATRIX="-1 0 0 0 -1 0 0 0 1"
        ;;
    left)
        echo "Left"
        MATRIX="0 -1 0 1 0 0 0 0 1"
        ;;
    right)
        echo "Right"
        MATRIX="0 1 0 -1 0 0 0 0 1"
        ;;
    *)
        echo "Not an supported orientation"
        help
        exit 1;
        ;;
esac


set -x

xrandr --output $DISP --rotate $O
for M in $MOUSE; do
    xinput set-prop $M "Coordinate Transformation Matrix" $MATRIX
done