[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to rotate screen AND input (consistently)



On Sat 20 Nov 2021 at 06:46:45 (-0500), Dan Ritter wrote:
> riveravaldez wrote: 
> > 
> > I'm on Debian 11 in a ThinkPad X220 Tablet (convertible)
> > and I need to rotate the display (both physically and GUI)
> > which I do with:
> > 
> > $ xrandr --output LVDS-1 --rotate inverted
> > 
> > But then the input (trackpad/mouse, stylus, touchscreen, etc.)
> > doesn't rotate accordingly, so it gets unusable...
> 
> Right, because for most cases, rotating a monitor doesn't mean
> picking up your mouse and rotating it, too.
> 
> If you've got an external mouse, you'll see that works just
> fine, but that defeats the point of a tablet.
> 
> > I've been reading different recommendations online
> > but can't figure out which would be the best/proper/simpler
> > approach to achieve this reliably (that hardware input
> > stays consistent with the GUI in display when rotated).
> > 
> > What should I do? Any hint?
> 
> I haven't done this, but I believe xinput is going to be your
> friend. It can list devices, list properties, and set whatever
> needs to be set.
> 
> The older way of doing this is to get into the Mouse section of 
> your xorg.conf.
> 
> Wayland has its own ways, which perhaps someone else can
> explain.

Indeed, I do this with xinput in X. My function is called
synaps for historical reasons. The xinput is extracted from
my bin/xinput-xsession, which itself is called from .xsession
because keeping it separate allows you to call it at any time,
nut just when X starts.

Anyway, they're both attached, lightly anonymised, The
reference to viewports may only make sense if you use fvwm.

Cheers,
David.
function synaps {
    [ "$1" = "-?" ] && printf '%s\n' "Usage:	${FUNCNAME[0]} [ l | r | u | i | m ]
	rotates the screen left, right, or upside down, or inverted or
	mirrored, and takes account of the touchpad and touchpoint.
	Normality is restored with no argument (or anything else).
	The only remaining confusion is that the viewports keys don't correspond." >&2 && return 1
    local Matrix="X 0 0 0 X 0 0 0 1"
    case "$1" in
	l)
	    xrandr -o 1
	    Matrix="0 -X 0 X 0 0 0 0 1"
	    ;;
	r)
	    xrandr -o 3
	    Matrix="0 X 0 -X 0 0 0 0 1"
	    ;;
	u)
	    xrandr -o 2
	    Matrix="-X 0 0 0 -X 0 0 0 1"
	    ;;
	i)
	    xrandr -y --q1
	    Matrix="-X 0 0 0 -X 0 0 0 1"
	    ;;
	m)
	    xrandr -x --q1
	    Matrix="-X 0 0 0 -X 0 0 0 1"
	    ;;
	*)
	    xrandr -o 0
	    ;;
    esac
    xinput --set-prop "AlpsPS/2 ALPS DualPoint TouchPad" "Coordinate Transformation Matrix" ${Matrix//X/.8} 2>/dev/null # west
    xinput --set-prop "DualPoint Stick" "Coordinate Transformation Matrix" ${Matrix//X/.2} 2>/dev/null # west
    xinput --set-prop "SynPS/2 Synaptics TouchPad" "Coordinate Transformation Matrix" ${Matrix//X/.4} 2>/dev/null # wren
    xinput --set-prop "Logitech M325" "Coordinate Transformation Matrix" ${Matrix//X/.3} 2>/dev/null
    xinput --set-prop "Logitech M310" "Coordinate Transformation Matrix" ${Matrix//X/.3} 2>/dev/null
    xinput --set-prop "Logitech M510" "Coordinate Transformation Matrix" ${Matrix//X/.3} 2>/dev/null
    xinput --set-prop "USB Wheel Mouse" "Coordinate Transformation Matrix" ${Matrix//X/.4} 2>/dev/null
}
#!/bin/bash
#
# ~/bin/xinput-xsession last edited 2021-10-11
# Normally called from .xsession but is made available separately so that it can
# be called easily after, say, the mouse/keyboard dongle is removed and reinserted.

[ -n "$1" ] && set -x

Unique="$(mktemp --suffix .list ${Uniquetrash:-/tmp}/xinput-"$(date +%s)"-XXXX)"
xinput | tee "$Unique"

# Pointers tend to be too sensitive.
# Leave the last number as 1: the other numbers are ratio'd with it.
# My M325 mouse wheel is unreliable and unsafe for button 2, so use buttons 1&3.
# Set the same for most other mice, because my fingers are wired for it.

Matrix="X 0 0 0 X 0 0 0 1"

Devicetype="pointer"

Device="Logitech M325" # purple wireless
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && xinput --set-prop "$Id" "Coordinate Transformation Matrix" ${Matrix//X/.3} && xinput --set-prop "$Id" "libinput Middle Emulation Enabled" 1

Device="Logitech M310" # not sure, might be a mistake
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && xinput --set-prop "$Id" "Coordinate Transformation Matrix" ${Matrix//X/.3} && xinput --set-prop "$Id" "libinput Middle Emulation Enabled" 1

Device="Logitech M510" # Xyz's and its evil twin
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && xinput --set-prop "$Id" "Coordinate Transformation Matrix" ${Matrix//X/.3} && xinput --set-prop "$Id" "libinput Middle Emulation Enabled" 1

Device="Logitech K520" # wireless (2 off)
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && xinput --set-prop "$Id" "Coordinate Transformation Matrix" ${Matrix//X/.3}

Device="Logitech K540/K545" # Xyz's desk
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && xinput --set-prop "$Id" "Coordinate Transformation Matrix" ${Matrix//X/.0003}

Device="USB Wheel Mouse" # transparent
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && xinput --set-prop "$Id" "Coordinate Transformation Matrix" ${Matrix//X/.4} && xinput --set-prop "$Id" "libinput Middle Emulation Enabled" 1

Device="PS/2 Logitech Mouse" # white
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && xinput --set-prop "$Id" "Coordinate Transformation Matrix" ${Matrix//X/.6}

Device="Microsoft Microsoft® Comfort Mouse 4500" # grey/black
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && xinput --set-prop "$Id" "Coordinate Transformation Matrix" ${Matrix//X/.4}

# Scrolling with another finger on the touchpad is awkward, but is OK on the right edge,
# but just not all the time (and use function key to toggle NYA).
# 1,0,0 put finger on touchpad, scroll with other finger.
# 0,1,0 scroll at extreme right edge of touchpad.
# 0,0,1 invalid.

Device="SynPS/2 Synaptics TouchPad" # wren and acer
grep -q "${Device/*:/}[[:space:]]*id" "$Unique" && xinput --list-props "$Device" && xinput --set-prop "$Device" "Coordinate Transformation Matrix" ${Matrix//X/.4} && xinput --set-prop "$Device" "libinput Scroll Method Enabled" 0, 0, 0

Device="ELAN Touchscreen" # Turn off touchscreen (and use function key to toggle NYA).
grep -q "${Device/*:/}[[:space:]]*id" "$Unique" && xinput --list-props "$Device" && xinput --set-prop "$Device" "Device Enabled" 0

Device="ELAN22CA:00 04F3:22CA" # Turn off touchscreen (and use function key to toggle NYA).
grep -q "${Device/*:/}[[:space:]]*id" "$Unique" && xinput --list-props "$Device" && xinput --set-prop "$Device" "Device Enabled" 0

# Keyboards can have their layout set here.
Devicetype="keyboard"

Device="AT Translated Set 2 keyboard" # IBM is only usable on apex; set it to GB layout
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && [ "$HOSTNAME" = "ajax" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && setxkbmap gb -device "$Id"

Device="Logitech K520" # wireless (2 off)
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && setxkbmap us -device "$Id"

Device="Logitech K540/K545" # wireless
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && setxkbmap us -device "$Id"

Device="DELL Dell USB Entry Keyboard" # (loan)
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && setxkbmap us -device "$Id"

Device="Microsoft Internet Keyboard Pro" # (2 loans)
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id" && setxkbmap us -device "$Id"

Device="Microsoft Microsoft® Comfort Mouse 4500" # grey/black
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id"

Device="ELAN22CA:00 04F3:22CA Pen" # (???)
grep -q "${Device/*:/}[[:space:]]*id" "$Unique" && xinput --list-props "$Device" # && setxkbmap us -device "$(grep "${Device/*:/}[[:space:]]*id" "$Unique" | sed -e 's/[^=]\+=//;s/\t.*//;' )"

Device="HP TrueVision FHD RGB-IR: HP Tr" # (???)
grep -q "${Device/*:/}[[:space:]]*id" "$Unique" && xinput --list-props "$Device"

Device="Integrated_Webcam_HD: Integrate" # axis
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id"

Device="Dell AIO WMI hotkeys" # axis
Id="$(grep "$Device[[:space:]]*id.*$Devicetype" "$Unique" | sed 's/^[^=]\+=//;s/\t.*//;')"
[ -n "$Id" ] && printf '\nXID %2s %s ' "$Id" "$Devicetype" && xinput --list-props "$Id"

[ -n "$1" ] && set +x

#

Reply to: