From 84f1e0fbaec1727693ce5993d99ed9897b93c4b5 Mon Sep 17 00:00:00 2001 From: VectorKappa Date: Sat, 9 Oct 2021 00:07:31 +0200 Subject: [PATCH] Upgraded desktop rotation --- bin/rotate_desktop | 61 +++++++++++++++++++++++++++++++++++++ sxhkd/.config/sxhkd/sxhkdrc | 2 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100755 bin/rotate_desktop diff --git a/bin/rotate_desktop b/bin/rotate_desktop new file mode 100755 index 0000000..d641e01 --- /dev/null +++ b/bin/rotate_desktop @@ -0,0 +1,61 @@ +#!/bin/bash +# +# rotate_desktop.sh +# +# Rotates modern Linux desktop screen and input devices to match. Handy for +# convertible notebooks. Call this script from panel launchers, keyboard +# shortcuts, or touch gesture bindings (xSwipe, touchegg, etc.). +# +# Using transformation matrix bits taken from: +# https://wiki.ubuntu.com/X/InputCoordinateTransformation +# +# Based off of: https://gist.github.com/mildmojo/48e9025070a2ba40795c + +# Configure these to match your hardware (names taken from `xinput` output). +TOUCHPAD='SynPS/2 Synaptics TouchPad' +TRACKPOINT='TPPS/2 IBM TrackPoint' + +if [ -z "$1" ]; then + echo "Missing orientation." + echo "Usage: $0 [normal|inverted|left|right] [revert_seconds]" + echo + exit 1 +fi + +function do_rotate +{ + xrandr --output $1 --rotate $2 + + TRANSFORM='Coordinate Transformation Matrix' + + case "$2" in + normal) + [ ! -z "$TOUCHPAD" ] && xinput set-prop "$TOUCHPAD" "$TRANSFORM" 1 0 0 0 1 0 0 0 1 + [ ! -z "$TRACKPOINT" ] && xinput set-prop "$TRACKPOINT" "$TRANSFORM" 1 0 0 0 1 0 0 0 1 + ;; + inverted) + [ ! -z "$TOUCHPAD" ] && xinput set-prop "$TOUCHPAD" "$TRANSFORM" -1 0 1 0 -1 1 0 0 1 + [ ! -z "$TRACKPOINT" ] && xinput set-prop "$TRACKPOINT" "$TRANSFORM" -1 0 1 0 -1 1 0 0 1 + ;; + left) + [ ! -z "$TOUCHPAD" ] && xinput set-prop "$TOUCHPAD" "$TRANSFORM" 0 -1 1 1 0 0 0 0 1 + [ ! -z "$TRACKPOINT" ] && xinput set-prop "$TRACKPOINT" "$TRANSFORM" 0 -1 1 1 0 0 0 0 1 + ;; + right) + [ ! -z "$TOUCHPAD" ] && xinput set-prop "$TOUCHPAD" "$TRANSFORM" 0 1 0 -1 0 1 0 0 1 + [ ! -z "$TRACKPOINT" ] && xinput set-prop "$TRACKPOINT" "$TRANSFORM" 0 1 0 -1 0 1 0 0 1 + ;; + esac +} + +XDISPLAY=`xrandr --current | grep primary | sed -e 's/ .*//g'` +XROT=`xrandr --current --verbose | grep primary | egrep -o ' (normal|left|inverted|right) '` + +do_rotate $XDISPLAY $1 + +if [ ! -z "$2" ]; then + sleep $2 + do_rotate $XDISPLAY $XROT + exit 0 +fi + diff --git a/sxhkd/.config/sxhkd/sxhkdrc b/sxhkd/.config/sxhkd/sxhkdrc index 5397dcf..685abc8 100755 --- a/sxhkd/.config/sxhkd/sxhkdrc +++ b/sxhkd/.config/sxhkd/sxhkdrc @@ -372,4 +372,4 @@ super + BackSpace # Rotate the screen. WARNING: Laggy. mod5 + {Left,Down,Up,Right} - xrandr --output LVDS1 --rotate {left,inverted,normal,right} + rotate_desktop {left,inverted,normal,right}