You are not logged in.

#1 2016-12-25 16:20:42

Chrysostomus
Member
Registered: 2015-09-13
Posts: 64
Website

Scripting libinput-debug-events: find direction of a gesture in dash

I'm writing a dash script to bind arbitary commands to touchpad gestures. The script is inspired by https://github.com/bulletmark/libinput-gestures/. Reason for writing a new tool for the same task is that I cannot adequately get pinch to zoom with libinput-gestures (it generates only one event for the whole zoom motion), and I do not understand python enough to modify bulletmarks excellent code to do so.

I'm listening to touchpad events with libinput-debug-events, piping its output to a while loop, reading it into different variables and then choosing actions with case statement.

The sample output of libinput-debug-events looks like this:

event8         GESTURE_PINCH_BEGIN  +3.61s     2
event8         GESTURE_PINCH_UPDATE  +3.80s    2  0.00/-0.58 ( 0.00/-1.85 unaccelerated)  0.63 @-0.19
event8         GESTURE_PINCH_END  +3.84s       2

My biggest problem is: How to figure out if it is pinch in or pinch out, based on GESTURE_PINCH_UPDATE event? As far as I can tell, this is how libinput-gestures does it (https://github.com/bulletmark/libinput- … t-gestures):


class PINCH(GESTURE):
    'Class to handle this type of gesture'
    SUPPORTED_MOTIONS = ('in', 'out')

    def begin(self, fingers):
        'Initialise this gesture at the start of motion'
        self.fingers = fingers
        self.data = 0.0

    def update(self, coords):
        'Update this gesture for a motion'
        self.data += 1.0 - float(coords[5])

    def end(self):
        'Action this gesture at the end of a motion sequence'
        if self.data != 0.0:
            self.action('in' if self.data >= 0.0 else 'out')

But I don't speak python, so I don't understand exactly what is calculated here.

Here is a sketch of the current script, with a lot of placeholder code:

#!/bin/dash

libinput-debug-events | while read -r device event time finger_count coordinates leftovers; do
    case $event in
        #
        GESTURE_PINCH_BEGIN) xdotool keydown Ctrl
        ;;
        GESTURE_PINCH_UPDATE) 	
        	#Get the first co-ordinate number for calculation
        	xdelta=$(echo "$coordinates" | cut -s --fields=1 --delimiter=/)
        	#Get the seconf co-ordinate number for calculation
        	ydelta=$(echo "$coordinates" | cut -s --fields=2 --delimiter=/ | cut -c1-4)
			#Do some kind of calculation with the numbers
        	dir=$(awk "BEGIN {print 1 - $xdelta+$ydelta; exit}")
        	#Decide was the pinch in or out based on that result
        	if [ "$dir" -gt 0 ]; then
        				xdotool key plus
        		else	
        				xdotool key minus 
        	fi
        ;;
        GESTURE_PINCH_END) xdotool keyup Ctrl
        ;;
    esac
done

Also, if someone knows a better way to get pinch to zoom working, I'm happy with that too.

Last edited by Chrysostomus (2016-12-25 16:22:24)


The difference between reality and fiction is that fiction has to make sense.

Offline

Board footer

Powered by FluxBB