diff --git a/thinkpad-yoga-rotate/PKGBUILD b/thinkpad-yoga-rotate/PKGBUILD new file mode 100644 index 0000000..35a1a22 --- /dev/null +++ b/thinkpad-yoga-rotate/PKGBUILD @@ -0,0 +1,26 @@ +# Maintainer: oggy + +pkgname=thinkpad-yoga-rotate +pkgver=0.1 +pkgrel=1 +pkgdesc="A small Thinkpad Yoga utility to automatically rotate the screen in tablet mode" +url="https://github.com/oggy-/thinkpad-yoga-rotate" +license=('GPL-3') +arch=('any') +depends=('xorg-xrandr' 'acpid') +source=('rotate-screen.sh' 'tablet-mode') +sha1sums=('81eebe35cbfc61f17ecaef51506cadefc9412155' + 'adf3aa47174d32f23f4f52186bdc8de07a802ddc') + +package() { + # "Register" the tablet-mode event and set the handler + mkdir -p "$pkgdir/etc/acpi/events" + install -m 644 tablet-mode "$pkgdir/etc/acpi/events" + + # Install the handler + mkdir -p "$pkgdir/etc/acpi/actions" + install -m 644 rotate-screen.sh "$pkgdir/etc/acpi/actions" +} + + + diff --git a/thinkpad-yoga-rotate/rotate-screen.sh b/thinkpad-yoga-rotate/rotate-screen.sh new file mode 100755 index 0000000..3ba2cb6 --- /dev/null +++ b/thinkpad-yoga-rotate/rotate-screen.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Note: xrandr needs to execute in the context of the X server + +# Find the user running the X server +user="$(who -u | grep -F '(:0)' | head -n 1 | awk '{print $1}')" + +# A convenience function to run a command in the X server context +with_display() { DISPLAY=:0.0 su -c "$(printf "%q " "$@")" "$user"; } + +# As the same ACPI event is currently emitted for both going in and out +# of the tablet mode, we need to toggle the orientation + +# Figure out the current rotation: +current=`with_display xrandr -q --verbose | grep eDP1 | cut -d " " -f5` + +# Set the next orientation +case $current in + normal) next=left;; + left) next=normal;; +esac + +with_display xrandr -o $next diff --git a/thinkpad-yoga-rotate/tablet-mode b/thinkpad-yoga-rotate/tablet-mode new file mode 100644 index 0000000..3e79724 --- /dev/null +++ b/thinkpad-yoga-rotate/tablet-mode @@ -0,0 +1,2 @@ +event=ibm/hotkey LEN0068:00 00000080 000060c0 +action=/etc/acpi/actions/rotate-screen.sh