logistiker n00b

Joined: 16 Jun 2008 Posts: 41
|
Posted: Wed Jul 29, 2015 8:03 pm Post subject: How to remap touchscreen on resume |
|
|
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
|
|
|