summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-12-06 21:45:25 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-12-06 21:47:11 -0500
commit7d36db862d15c7a393bd79dc25b857b4a778f6fb (patch)
tree04756996c58e0936f5f8e1f3a9574a00188eda92
parent1082e1228dcc6912d705c03beab1a2d6a1c9f0b9 (diff)
wmii: Support the rotate screen button on my x60 tablet
-rw-r--r--.config/wmii-hg/config.sh11
-rwxr-xr-x.local/bin/xrotate117
2 files changed, 128 insertions, 0 deletions
diff --git a/.config/wmii-hg/config.sh b/.config/wmii-hg/config.sh
index 1b48cc4..ffb5f20 100644
--- a/.config/wmii-hg/config.sh
+++ b/.config/wmii-hg/config.sh
@@ -263,6 +263,17 @@ Key() {
sel=$(sed 1q $WMII_DIR/client/sel/ctl)
tag=$(lstags | wimenu -h "${HIST}.tags" -n 50) || return
echo "$tag" >> $WMII_DIR/client/$sel/tags;;
+
+ ## Hardware keys
+ XF86RotateWindows) ## Rotate the screen
+ local old new
+ old="$(xrotate|cut -d $'\t' -f3|sort -u)"
+ case "$old" in
+ normal) new=right;;
+ *) new=normal;;
+ esac
+ xrotate "$new"
+ ;;
esac
}
diff --git a/.local/bin/xrotate b/.local/bin/xrotate
new file mode 100755
index 0000000..55b4e88
--- /dev/null
+++ b/.local/bin/xrotate
@@ -0,0 +1,117 @@
+#!/usr/bin/env bash
+
+# xrandr (graphical output) ############################################
+type xrandr &>/dev/null && modules+=(xrandr)
+
+xrandr.get() {
+ xrandr --query --verbose|awk -v OFS=$'\t' '/ connected /{print "xrandr", $1, $5}'
+}
+
+xrandr.set() {
+ xrandr --orientation "$1"
+}
+
+# xsetwacom (touchscreen input) ########################################
+type xsetwacom &>/dev/null && modules+=(xsetwacom)
+
+xsetwacom.get() {
+ local device
+ xsetwacom --list devices|cut -d $'\t' -f1|while read -r device; do
+ printf 'xsetwacom\t%s\t%s\n' "$device" "$(xsetwacom --get "$device" Rotate)"
+ done | sed -e $'s/\tnone$/\tnormal/' \
+ -e $'s/\tcw$/\tright/' \
+ -e $'s/\tccw$/\tleft/' \
+ -e $'s/\thalf$/\tinverted/'
+}
+
+xsetwacom.set() {
+ declare -A xrandr2wacom
+ xrandr2wacom[normal]=none
+ xrandr2wacom[left]=ccw
+ xrandr2wacom[right]=cw
+ xrandr2wacom[inverted]=half
+
+ local device
+ local r=0
+ xsetwacom --list devices|cut -d $'\t' -f1|while read -r device; do
+ xsetwacom --set "$device" Rotate ${xrandr2wacom[$1]} || r=$?
+ done
+ return $r
+}
+
+# xmodmap (D-pad input) ################################################
+type xmodmap &>/dev/null && modules+=(xmodmap)
+
+declare -A xrandr2xmodmap
+xrandr2xmodmap[keycode]=' 111 113 114 116 '
+xrandr2xmodmap[normal]=' Up Left Right Down '
+xrandr2xmodmap[left]=' Right Up Down Left '
+xrandr2xmodmap[right]=' Left Down Up Right'
+xrandr2xmodmap[inverted]='Down Right Left Up '
+
+xmodmap.get() {
+ local cur=malformed
+
+ local keys=($(xmodmap -pke | grep -f <(printf '^keycode %s =\n' ${xrandr2xmodmap[keycode]})|awk '{print $4}'))
+ local k
+ for k in normal left right inverted; do
+ if [[ "$(echo ${xrandr2xmodmap[$k]})" = "${keys[*]}" ]]; then
+ cur=$k
+ fi
+ done
+ printf 'xmodmap\t-\t%s\n' "$cur"
+}
+
+xmodmap.set() {
+ paste \
+ <(printf '%s\n' ${xrandr2xmodmap[keycode]}) \
+ <(printf '%s\n' ${xrandr2xmodmap[$1]}) \
+ | awk '{print "keycode", $1, "=", $2}' | xmodmap -
+}
+
+# main #################################################################
+
+usage() {
+ . libremessages
+ print 'Usage: %q [-h|--help|normal|left|right|inverted]' "${0##*/}"
+ print 'Get or set screen rotation.'
+ echo
+ prose 'Without any arguments, return the screen rotation as
+ reported by supported subsystems. The output format is:'
+ echo
+ print ' SUBSYSTEM <tab> DEVICE <tab> STATE <newline>'
+}
+
+xget() {
+ local r=0
+ local module
+ for module in "${modules[@]}"; do
+ "${module}.get" || r=$?
+ done
+ return $r
+}
+
+xset() {
+ local r=0
+ local module
+ for module in "${modules[@]}"; do
+ "${module}.set" "$1" || r=$?
+ done
+ return $r
+}
+
+main() {
+ case $# in
+ 0) xget;;
+ 1)
+ case "$1" in
+ normal|left|right|inverted) xset "$1";;
+ -h|--help) usage;;
+ *) usage >&2; exit 1;;
+ esac
+ ;;
+ *) usage >&2; exit 1;;
+ esac
+}
+
+main "$@"