Skip to content

Commit

Permalink
working and installable version achived
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Leon Happel committed Nov 7, 2021
0 parents commit dbee083
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
29 changes: 29 additions & 0 deletions autoscreenrotation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
#
# @AUTHOR: Luca Leon Happel
# @DATE : 2021-11-07 So 19:12 32
#

function processnewcommand {
case $1 in
"Accelerometer orientation changed: normal")
echo "screen rotated to normal"
./screenrotation.sh "normal"
;;
"Accelerometer orientation changed: bottom-up")
echo "screen rotated to inverted"
./screenrotation.sh "inverted"
;;
"Accelerometer orientation changed: left-up")
echo "screen rotated to left"
./screenrotation.sh "left"
;;
"Accelerometer orientation changed: right-up")
echo "screen rotated to right"
./screenrotation.sh "right"
;;
esac
}

export -f processnewcommand
monitor-sensor | xargs --replace=% bash -c 'processnewcommand "%"'
21 changes: 21 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ pkgs ? import <nixpkgs> {} }: with pkgs;

stdenv.mkDerivation {
version = "1.0";
name = "flex5ScreenRotate";
src = ./.;
buildInputs = [
libwacom
xf86_input_wacom
xorg.xrandr
iio-sensor-proxy
];
dontBuild = true;
installPhase = ''
mkdir -pv $out/bin/
cp ./screenrotation.sh $out/bin/
chmod +x $out/bin/screenrotation.sh
cp ./autoscreenrotation.sh $out/bin/
chmod +x $out/bin/autoscreenrotation.sh
'';
}
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# flex5ScreenRotate

Automatically rotate the Lenovo Flex 5 screen and Wacom inputs
given the accelerometer picks up an orientation change

## Requirements

Please look in `default.nix` under `buildInputs = [ ... ];` which
programs are reqired. `iio-sensor-proxy` is also needed.

## Usage

Run `./autoscreenrotation.sh`
36 changes: 36 additions & 0 deletions screenrotation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
#
# @AUTHOR: Luca Leon Happel
# @DATE : 2021-06-13 So 00:50 57
#
# This is a script that toggles rotation of the screen through xrandr,
# and also toggles rotation of the stylus, eraser and cursor through xsetwacom

screen=`xrandr --current | grep " connected" | awk '{print $1;}'`
orientation=`xrandr --verbose -q | grep $screen | awk '{print $6}'`

echo $screen
echo $orientation

function wacom_setup {
xsetwacom set "Wacom HID 5218 Pen stylus" Rotate $1
xsetwacom set "Wacom HID 5218 Finger touch" Rotate $1
xsetwacom set "Wacom HID 5218 Pen eraser" Rotate $1
}

if [[ -z "$1" ]]; then
echo "Missing argument!"
echo "Possible values are: normal, inverted, left, right"
elif [ "$1" = "normal" ]; then
xrandr --output $screen --rotate normal
wacom_setup none
elif [ "$1" = "inverted" ]; then
xrandr --output $screen --rotate inverted
wacom_setup half
elif [ "$1" = "left" ]; then
xrandr --output $screen --rotate left
wacom_setup ccw
elif [ "$1" = "right" ]; then
xrandr --output $screen --rotate right
wacom_setup cw
fi

0 comments on commit dbee083

Please sign in to comment.