[conspire] tip- touchscreen / table style scrolling

Nick Moffitt nick at zork.net
Wed Apr 17 01:55:11 PDT 2013


Tony Godshall:
> It scrolls backwards!?  Yup, it's called "Natural Scrolling" and it
> seems wrong wrong wrong.  Until you get a laptop with a touch-screen.  

I have a four-year-old daughter, and her first instinct with a mouse's
scroll-wheel is that it should turn in the direction the viewport moves,
rather than in the direction of travel within the pane.  To her,
"Natural Scrolling" is the most natural option even without a
touchscreen.

> for id in $(xinput list|perl -ne
> 'if(m{XTEST}){}elsif(m{id=([0-9]+).*slave.*pointer}){print "$1\n"}');
> do xinput set-button-map $id $(xinput get-button-map $id|perl -pe 's{
> 4 5 }{ 5 4 }'); done
> 
> If any folks on the list would like a breakdown of that, let me know.

As a recovered 1990s Perl 5.005 refugee (Thank you, Python!  Thank you,
awk!), I feel duty-bound to translate this to awk:

    xinput list | \ 
    awk -F "[\t=]" '$1 !~ /XTEST/ && $4 ~ /slave.+pointer/ {print $3}' | \
    while read id
    do 
      xinput set-button-map $id $(xinput get-button-map $id | sed 's/ 4 5/ 5 4/')
    done

xinput uses tab-delimited output, but has a single = in the id field, so
I used the -F parameter to split on both tabs and =.

We filter out the "Virtual core XTEST" objects with a negative match on
XTEST in the first column, then match for "slave  pointer" (or similar)
in the third column.  Note that this is $4 because we also split on = to
get a pure ID integer in our $3 column variable, which we print.

Then we use set-button-map on a transformation on get-button-map, and
this is one of the rare cases where sed is clear enough.  Note also that
I did not require a space after the 5 in the get output, so this would
work on devices that have no map for buttons 6 or 7.

Also by switching to a pipe and a while-do loop, I removed one of the
$() subshells, which I feel aids clarity.

-- 
"If, as they say, God spanked the town
for being over frisky,
why did He burn the churches down
and save Hotaling's whisky?" -- 1906 SF Earthquake rhyme




More information about the conspire mailing list