add de-p1st-rotate

This commit is contained in:
Daniel Langbein 2021-06-17 16:25:38 +02:00
parent d52fedadef
commit e9d1a17a75
8 changed files with 114 additions and 1 deletions

View File

@ -1,4 +1,4 @@
de-p1st-locale de-p1st-systemd de-p1st-sudo de-p1st-screen de-p1st-htop de-p1st-pacman de-p1st-pacman-mirrorlist de-p1st-networkmanager de-p1st-ucode-placeholder de-p1st-ucode-intel de-p1st-ucode-amd de-p1st-nano de-p1st-mkinitcpio de-p1st-makepkg de-p1st-grub de-p1st-font de-p1st-keyboard-de de-p1st-keyboard-x11-de de-p1st-gnupg de-p1st-redshift de-p1st-theme de-p1st-sddm-autologin-placeholder de-p1st-sddm-autologin-yoda de-p1st-sddm-theme-default de-p1st-sddm-theme-nordic de-p1st-gpu-generic de-p1st-gpu-amdgpu de-p1st-installer de-p1st-repo de-p1st-ssh-key-placeholder de-p1st-ssh-key-yoda de-p1st-rotate de-p1st-locale de-p1st-systemd de-p1st-sudo de-p1st-screen de-p1st-htop de-p1st-pacman de-p1st-pacman-mirrorlist de-p1st-networkmanager de-p1st-ucode-placeholder de-p1st-ucode-intel de-p1st-ucode-amd de-p1st-nano de-p1st-mkinitcpio de-p1st-makepkg de-p1st-grub de-p1st-font de-p1st-keyboard-de de-p1st-keyboard-x11-de de-p1st-gnupg de-p1st-redshift de-p1st-theme de-p1st-sddm-autologin-placeholder de-p1st-sddm-autologin-yoda de-p1st-sddm-theme-default de-p1st-sddm-theme-nordic de-p1st-gpu-generic de-p1st-gpu-amdgpu de-p1st-installer de-p1st-repo de-p1st-ssh-key-placeholder de-p1st-ssh-key-yoda
de-p1st-smartcard de-p1st-kernel-default de-p1st-kernel-lts de-p1st-dns de-p1st-ssh de-p1st-smartcard de-p1st-kernel-default de-p1st-kernel-lts de-p1st-dns de-p1st-ssh
de-p1st-base de-p1st-base
de-p1st-xfce4 de-p1st-xfce4

View File

@ -0,0 +1,23 @@
# Maintainer: Daniel Langbein <daniel@systemli.org>
_pkgname=rotate
_reponame=arch
pkgname="de-p1st-$_pkgname"
pkgver=0.0.1
pkgrel=1
pkgdesc="Scripts to automate screen rotation"
arch=('any')
url="https://codeberg.org/privacy1st/${_reponame}"
license=('MIT')
depends=('iio-sensor-proxy-git') # iio-sensor-proxy did not work on my Surface Go 2 but the git version dos
makedepends=('git') # to fetch source(s) via git
source=("git+${url}.git")
sha256sums=('SKIP') # 'SKIP' for git sources; Otherwise: autofill using updpkgsums, see https://man.archlinux.org/man/updpkgsums.8.en
package() {
cd "${_reponame}/pkg/${pkgname}"
install -Dm0544 usr/bin/de-p1st-rotate-screen "$pkgdir"/usr/bin/de-p1st-rotate-screen
install -Dm0544 usr/bin/de-p1st-auto-rotate "$pkgdir"/usr/bin/de-p1st-auto-rotate
install -Dm0644 -o0 etc/de-p1st-rotate/config.cfg "$pkgdir"/etc/de-p1st-rotate/config.cfg
}

View File

@ -0,0 +1,16 @@
# The screen to rotate
SCREEN=eDP-1 # other values could be "eDP1" or "HDMI1"
# xrandr devices to rotate together with the screen
DEVICES=()
#DEVICES+=( 'pointer:Wacom Pen and multitouch sensor Finger touch' ) # LenovoYoga460
#DEVICES+=( 'pointer:Wacom Pen and multitouch sensor Pen stylus' ) # LenovoYoga460
#DEVICES+=( 'pointer:Wacom Pen and multitouch sensor Pen eraser' ) # LenovoYoga460
#
DEVICES+=( 'pointer:ELAN9038:00 04F3:2A1C' ) # SurfaceGo2 (default)
DEVICES+=( 'pointer:ELAN9038:00 04F3:2A1C Pen (0)' ) # SurfaceGo2 (default)
DEVICES+=( 'pointer:ELAN9038:00 04F3:2A1C Eraser (0)' ) # SurfaceGo2 (default)
#
#DEVICES+=( 'pointer:ELAN9038:00 04F3:2A1C touch' ) # SurfaceGo2
#DEVICES+=( 'pointer:ELAN9038:00 04F3:2A1C stylus' ) # SurfaceGo2
#DEVICES+=( 'pointer:ELAN9038:00 04F3:2A1C eraser' ) # SurfaceGo2

View File

@ -0,0 +1,3 @@
#!/bin/bash
de-p1st-rotate-screen "inverted"

View File

@ -0,0 +1,3 @@
#!/bin/bash
de-p1st-rotate-screen "left"

View File

@ -0,0 +1,3 @@
#!/bin/bash
de-p1st-rotate-screen "normal"

View File

@ -0,0 +1,29 @@
#!/bin/bash
# Output of "monitor-sensor --accel | grep 'orientation'":
# === Has accelerometer (orientation: normal)
# Accelerometer orientation changed: right-up
# Feed output of 'monitor-sensor' and stop after first match of 'orientation'
ORIENTATION_STR="$(grep -m 1 'orientation' <( monitor-sensor ))" || exit $?
case "${ORIENTATION_STR}" in
*": normal"*)
ORIENTATION="normal";
;;
*": bottom-up"*)
ORIENTATION="inverted";
;;
*": right-up"*)
ORIENTATION="left";
;;
*": left-up"*)
ORIENTATION="right";
;;
*)
echo "Could not parse ORIENTATION_STR!";
exit 1;
esac
# echo "Detected device orientation ${ORIENTATION}"
de-p1st-rotate-screen "${ORIENTATION}"

View File

@ -0,0 +1,36 @@
#!/bin/bash
# @post: $SCREEN variable and $DEVICES array are set
source /etc/de-1st-rotate/config.cfg || exit $?
if [ "$#" -ne "1" ]; then
echo "usage: $0 ORIENTATION";
exit 1;
fi
ORIENTATION="$1"
# "xrandr ... || exit 1" does not work to check if $SCREEN exists.
# if e.g. the given output "$SCREEN" does not exist.
# Thus we check if $SCREEN is valid with grep:
xrandr --listmonitors | grep --quiet "\s${SCREEN}\$" || {
echo "The given screen ${SCREEN} does not exist.";
exit 1;
}
xrandr --output "${SCREEN}" --rotate "${ORIENTATION}" || {
echo "Could not rotate ${SCREEN}!";
exit 1;
}
for i in "${DEVICES[@]}"; do
xinput --map-to-output "${i}" "${SCREEN}" || {
echo "Could not map device ${i} to screen ${SCREEN}!";
FAILURE=true
}
done
if [ "${FAILURE}" = "true" ]; then
# At least one error occurred.
exit 1;
fi