Screen rotation, 2-in-1-Laptop, how to calibrate pen & touch?

hy
since i had a working solution i might share it with you :slight_smile:

For this you need iio-sensor-proxy and x but then you are good to go.
The list of devices may need to be changed by you. There are also scripts that support any device but these seem to have some bugs most times (atleas for me).

#!/bin/sh

DISPLAY=:0
export DISPLAY

devices=("Wacom HID 5201 Pen stylus" "Wacom HID 5201 Pen eraser" "Wacom HID 5201 Finger touch")

rotate_cursor() {
    for p in "${devices[@]}";
    do
        xinput set-prop "$p" "Coordinate Transformation Matrix" "$@"
        #echo '''"xinput set-prop '"$p"' "Coordinate Transformation Matrix" "$@""'''
    done
    sleep 1s
    for p in "${devices[@]}";
    do
        xinput --map-to-output "$p" "$MAIN_SCREEN"
        #echo '''xinput --map-to-output '"$p"' '"$MAIN_SCREEN"' '''
    done
}

MAIN_SCREEN=eDP-1
echo "$MAIN_SCREEN"
monitor-sensor | while read -r line
do
    line="${line##*: }"
    echo "$line"
    sleep 1s
    # Set the actions to be taken for each possible orientation
    case "$line" in
        normal)
            xrandr --output "$MAIN_SCREEN" --rotate normal
            rotate_cursor 1 0 0 0 1 0 0 0 1
            ;;
        bottom-up)
            xrandr --output "$MAIN_SCREEN" --rotate inverted
            rotate_cursor -1 0 1 0 -1 1 0 0 1
            ;; 
        right-up)
            xrandr --output "$MAIN_SCREEN" --rotate right
            rotate_cursor 0 1 0 -1 0 1 0 0 1
            ;;
        left-up)
            xrandr --output "$MAIN_SCREEN" --rotate left
            rotate_cursor 0 -1 1 1 0 0 0 0 1
            ;;
    esac
done
exit 0

Another thing you may want to consider when working on a 2in1 is to use a display keyboard like “onboard” this can be started when you turn the display 180deg. For this you can use the keyboard shortkut which disables the mouse pad since its executed when you turn the display.
For that i use this script…
but keep in mind the keypress may differ for your maschine

#!/bin/sh

line2=""
line3=""

xinput test-xi2 --root 3 | while read -r line
do  
    if [[ $line == *"detail: 201" ]]; then
        if [[ $line3 == *"RawKeyPress"* ]]; then
            onboard &
            #echo "start onboard"
        fi
        
    fi
    if [[ $line == *"detail: 200" ]]; then
        if [[ $line3 == *"RawKeyPress"* ]]; then
            killall onboard
            #echo "start onboard"
        fi
        
    fi    
    line3=$line2
    line2=$line
    
done
exit 0

also when working with the active pen 2 (which has a button at the top) the top button is normaly not supported. Therefor the following script allows to use the top button to start applications or whatever you like…

#!/bin/sh

DISPLAY=:0
export DISPLAY

SERVICE="xournalpp"


udevadm monitor | while read -r line
do
    if [[ $line == "KERNEL"*"add"*"hci0:3585"*"bluetooth"* ]]; then
        if pgrep -x "$SERVICE" >/dev/null
        then
            #xournal  is running wannt to open the sidebar
            xte "key F12"
            
        else
            #xournal not running open it now
            sudo -u felix_j xournalpp &>/dev/null &
        fi
        sudo -u felix_j xinput --map-to-output 11 eDP-1
        sudo -u felix_j xinput --map-to-output 12 eDP-1
        sudo -u felix_j xinput --map-to-output 15 eDP-1
    fi
done 
exit 0

the sudo statements at the bottom map my inputs(touch and pen) to the laptop display such that when i have multiple displays attached i can simply press the active pen button and all inputs (from touch and pen) are correctly on the laptop display.

Right now i have some problems with the iio-sensor-proxy which i cant resolve but since these scripts worked before i would guess they still do if the iio-sensor has proper output !

Edit: with the newest verison of iio-proxy it works so use these as u please :slight_smile:

1 Like