@@ -350,9 +350,10 @@ class GESTURE:
350350 'Initialise this gesture at program start'
351351 self .name = type (self ).__name__
352352 self .motions = OrderedDict ()
353+ self .thresholds = OrderedDict ()
353354 self .has_extended = False
354355
355- def add (self , motion , fingers , command ):
356+ def add (self , motion , fingers , command , threshold ):
356357 'Add a configured motion command for this gesture'
357358 if motion not in self .SUPPORTED_MOTIONS :
358359 return 'Gesture {} does not support motion "{}".\n ' \
@@ -365,9 +366,9 @@ class GESTURE:
365366 # their discrimination
366367 if self .extended_text in motion :
367368 self .has_extended = True
368-
369+ self . thresh = threshold
369370 key = (motion , fingers ) if fingers else motion
370-
371+
371372 try :
372373 cmds = shlex .split (command )
373374 except Exception as e :
@@ -377,6 +378,7 @@ class GESTURE:
377378
378379 try :
379380 self .motions [key ] = cls (cmds )
381+ self .thresholds [key ] = threshold
380382 except Exception as e :
381383 return str (e )
382384
@@ -386,8 +388,18 @@ class GESTURE:
386388 'Initialise this gesture at the start of motion'
387389 self .fingers = fingers
388390 self .data = [0.0 , 0.0 ]
391+ self .moved = 0
389392 self .starttime = monotonic ()
390393
394+ def thresholdmove (self , motion ):
395+ 'Get threshold for update command'
396+ thresh = self .thresholds .get ((motion , self .fingers )) or \
397+ self .thresholds .get (motion )
398+ print (thresh )
399+ if thresh == None :
400+ thresh = 0
401+ return int (thresh )
402+
391403 def action (self , motion ):
392404 'Action a motion command for this gesture'
393405 command = self .motions .get ((motion , self .fingers )) or \
@@ -425,6 +437,21 @@ class SWIPE(GESTURE):
425437
426438 self .data [0 ] += x
427439 self .data [1 ] += y
440+ x2 , y2 = self .data
441+ abx = abs (x2 )
442+ aby = abs (y2 )
443+ if abx > aby :
444+ motion = 'left' if x2 < 0 else 'right'
445+ if self .has_extended and abx > 0 and aby / abx > OBLIQUE_RATIO :
446+ motion += '_up' if y2 < 0 else '_down'
447+ else :
448+ motion = 'up' if y2 < 0 else 'down'
449+ if self .has_extended and aby > 0 and abx / aby > OBLIQUE_RATIO :
450+ motion = ('left_' if x2 < 0 else 'right_' ) + motion
451+ if self .thresholdmove (motion ) > 0 :
452+ if abx ** 2 + aby ** 2 - self .moved > self .thresholdmove (motion ):
453+ self .action (motion )
454+ self .moved += abx ** 2 + aby ** 2
428455 return True
429456
430457 def end (self ):
@@ -509,9 +536,13 @@ def conf_gesture(lineargs):
509536 command = fcommand [0 ] if fcommand else ''
510537 else :
511538 fingers = None
512-
539+ thresh , * gcommand = command .split (maxsplit = 1 )
540+ if thresh .isnumeric ():
541+ command = gcommand [0 ] if fcommand else ''
542+ else :
543+ thresh = 0
513544 # Add the configured gesture
514- return handler .add (motion .lower (), fingers , command )
545+ return handler .add (motion .lower (), fingers , command , thresh )
515546
516547@add_conf_command
517548def conf_device (lineargs ):
0 commit comments