-
Notifications
You must be signed in to change notification settings - Fork 1
/
x230t-rotate
executable file
·81 lines (76 loc) · 2.46 KB
/
x230t-rotate
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
81
#!/bin/sh
#
# NAME
#
# x230t-rotate - rotate ThinkPad X230t's display
#
# SYNOPSIS
#
# x230t-rotate [<rotation>]
#
# DESCRIPTION
#
# This is a display rotation script to be used with a ThinkPad X230t
# tablet. With trivial modifications one should also be able use it
# with other Wacom tablets. The supplied rotation can be the usual
# ones defined by xrandr(1) and xsetwacom(1), i.e.,
#
# normal, none no rotation
# inverted, half inverted display, "left", and "right".
# left, ccw ccw rotation from normal by 90 degrees
# right, cw cw rotation from normal by 90 degrees
#
# Additionally, we define the following two rotations:
#
# flip switch between normal and inverted,
# or left and right
# sideways switch between normal and left,
# or inverted and right
#
# Since switching between rotations requires knowledge of current
# rotation, the current state is always written to ~/.x230t-rotate
# at the end of execution.
#
# DEPENDENCIES
#
# xrandr(1) and xsetwacom(1)
#
# SEE ALSO
#
# <https://github.com/martin-ueding/thinkpad-scripts>
# More featureful scripts that automate screen rotation.
#
# Check the output of xrandr(1) and xinput(1) and change accordingly.
# We could parse the outputs, but that'd create an unnecessary overhead.
screen="LVDS1"
stylus="Wacom ISDv4 E6 Pen stylus"
finger="Wacom ISDv4 E6 Finger touch"
# If there's no state file, assume that the display isn't rotated.
state="$HOME/.x230t-rotate"
[ -f "$state" ] && current=$(cat "$state") || current="normal"
case "$1" in
n*) set -- "normal" "none" ;;
i*|half) set -- "inverted" "half" ;;
l*|ccw) set -- "left" "ccw" ;;
r*|cw) set -- "right" "cw" ;;
f*) case "$current" in
n*) set -- "inverted" "half" ;;
i*) set -- "normal" "none" ;;
l*) set -- "right" "cw" ;;
r*) set -- "left" "ccw" ;;
esac
;;
s*) case "$current" in
n*) set -- "left" "ccw" ;;
i*) set -- "right" "cw" ;;
l*) set -- "normal" "none" ;;
r*) set -- "inverted" "half" ;;
esac
;;
*) set -- "normal" "none" ;;
esac
xrandr --output "$screen" --rotate "$1"
xsetwacom set "$stylus" Rotate "$2"
xsetwacom set "$finger" Rotate "$2"
# Write current rotation to state file.
echo "$1" >"$state"