]> git.sev.monster Git - dotfiles.git/blame - bin/rotate
in development
[dotfiles.git] / bin / rotate
CommitLineData
f29cd560 1#!/bin/sh
2
3default_output=LVDS1
4
5usage() {
6 echo "Usage:
7 rotate (left|right|invert) [output]
8 rotate set (normal|right|inverted|left) [output]
9Examples:
10 rotate left LVDS1
11 rotate set right HDMI2
12
13Only the first letter of each command is checked (case-insensitive), so they
14can be abbreviated or even cut to one letter each in lower or upper case.
15
16For example, the following commands do the same thing:
17 rotate set left
18 rotate SET LeFt
19 rotate s l
20 rotate salad lasagna"
21}
22
23rot_to_num() {
24 case $1 in
25 # normal right invert left
26 # convert to numbers to allow math to rotate
27 [nN]*) rot0=0;;
28 [rR]*) rot0=1;;
29 [iI]*) rot0=2;;
30 [lL]*) rot0=3;;
31 *) usage; exit 2;;
32 esac
33}
34num_to_rot() {
35 case $1 in
36 # maps to rot_to_num output
37 0) rot1=normal
38 rot2=none;;
39 1) rot1=right
40 rot2=cw;;
41 2) rot1=inverted
42 rot2=half;;
43 3) rot1=left
44 rot2=ccw;;
45 esac
46}
47
48case $1 in
49 [sS]*)
50 # set: rotate set (normal|right|inverted|left) [output]
51 output=${3:-$default_output}
52 rot_to_num $2
53 ;;
54 *)
55 # rotate (left|right|invert) [output]
56 output=${2:-$default_output}
57 rot_to_num `xrandr --query --verbose | grep $output | awk '{print $5}'`
58 case $1 in
59 [lL]*) rot0=$(($rot0 - 1));;
60 [rR]*) rot0=$(($rot0 + 1));;
61 [iI]*) rot0=$(($rot0 + 2));;
62 *) usage; exit 1;;
63 esac
64 ;;
65esac
66
67# add 4 modulo 4 to prevent negatives and overflows
68num_to_rot $((($rot0 + 4) % 4))
69
70xrandr --output $output --rotation $rot1
71# x220t
a5daf7a9 72if command -v xsetwacom >/dev/null 2>&1; then
f29cd560 73 xsetwacom --set stylus Rotate $rot2
74 xsetwacom --set eraser Rotate $rot2
75 xsetwacom --set touch Rotate $rot2
76fi
77
78# reload bg
a5daf7a9 79~/bin/wall
This page took 0.052701 seconds and 4 git commands to generate.