Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to remap touchscreen on resume
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
logistiker
n00b
n00b


Joined: 16 Jun 2008
Posts: 39

PostPosted: Wed Jul 29, 2015 8:03 pm    Post subject: How to remap touchscreen on resume Reply with quote

Suspend to RAM removes all xinput settings so that when you resume from sleep, it does not restore your xinput settings. This is a particular problem for touchscreens since the touchscreen input needs to be mapped to the correct monitor for it to work correctly. Here's how you accomplish this:

install programs:

Code:
emerge xrandr xinput at


start atd and add it to the default runlevel:

Code:
/etc/init.d/atd start && rc-update add atd default


udev rule: (replace idVendor & idProduct with your touchscreen usb info)
Code:

# Map touchscreen input to monitor
ACTION=="add", ATTRS{idVendor}=="0eef", ATTRS{idProduct}=="a802", ENV{ID_TYPE}!="hid", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/[your username here]/.Xauthority", ENV{COMMAND}="/usr/local/bin/touchscreen-map-to-output", RUN+="/usr/local/bin/udev-xreceiver"


/usr/local/bin/udev-xreceiver
Code:
#!/bin/bash
at now <<EOF
XAUTHORITY="${XAUTHORITY}" DISPLAY="${DISPLAY}" ${COMMAND}
EOF


/usr/local/bin/touchscreen-map-to-output (Change DEVICES to match your display & xinput touchscreen input search string for each touchscreen plugged in - example already references two touchscreens and their referenced displays from xrandr):
Code:

#!/bin/bash
# Confine touchscreen area to its own screen when in using xinerama style monitor settings
# requires >= bash-4, gawk, xinput, xrandr, coreutils and util-linux
# Note: $DISPLAY & $XAUTHORITY environment variables will need to be defined (needed by xrandr
#       and xinput) if the script is automated and run as root (e.g. via at script within udev)

if [ ${BASH_VERSION:0:1} -lt 4 ]; then
        echo "This script requires bash version >= 4"
        logger -t $(basename $0) -i -p local7.err "This script requires bash version >= 4"
        exit 1
fi

declare -A DEVICES
DEVICES=(["eDP1"]="eGalaxTouch" ["HDMI1"]="CoolTouch")

for display in "${!DEVICES[@]}"
do
        TOUCH_DISPLAY=$(xrandr | grep "^${display} connected")
        TOUCH_DEVICE=$(xinput | grep ${DEVICES[$display]})
        if [ -n "${TOUCH_DEVICE}" ] && [ $(echo ${TOUCH_DEVICE} | wc -l) -eq 1 ] && [ -n "${TOUCH_DISPLAY}" ] && [ $(echo ${TOUCH_DISPLAY} | wc -l) -eq 1 ]; then
                xinput --map-to-output $(echo ${TOUCH_DEVICE} | awk -F= '{print $2}' | awk '{print $1}') ${display}
                if [ $? -eq 0  ]; then
                        logger -t $(basename $0) -i -p local7.info "Mapped ${DEVICES[$display]} output to touchscreen on ${display}"
                else
                        logger -t $(basename $0) -i -p local7.err "Failed to map ${DEVICES[$display]} output to touchscreen on ${display}"
                fi
        else
                logger -t $(basename $0) -i -p local7.notice "Could not detect touchscreen on ${display}"
        fi
done

unset DEVICES
unset TOUCH_DISPLAY
unset TOUCH_DEVICE
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum