@@ -350,9 +350,10 @@ class GESTURE:
350
350
'Initialise this gesture at program start'
351
351
self .name = type (self ).__name__
352
352
self .motions = OrderedDict ()
353
+ self .thresholds = OrderedDict ()
353
354
self .has_extended = False
354
355
355
- def add (self , motion , fingers , command ):
356
+ def add (self , motion , fingers , command , threshold ):
356
357
'Add a configured motion command for this gesture'
357
358
if motion not in self .SUPPORTED_MOTIONS :
358
359
return 'Gesture {} does not support motion "{}".\n ' \
@@ -365,9 +366,9 @@ class GESTURE:
365
366
# their discrimination
366
367
if self .extended_text in motion :
367
368
self .has_extended = True
368
-
369
+ self . thresh = threshold
369
370
key = (motion , fingers ) if fingers else motion
370
-
371
+
371
372
try :
372
373
cmds = shlex .split (command )
373
374
except Exception as e :
@@ -377,6 +378,7 @@ class GESTURE:
377
378
378
379
try :
379
380
self .motions [key ] = cls (cmds )
381
+ self .thresholds [key ] = threshold
380
382
except Exception as e :
381
383
return str (e )
382
384
@@ -386,8 +388,18 @@ class GESTURE:
386
388
'Initialise this gesture at the start of motion'
387
389
self .fingers = fingers
388
390
self .data = [0.0 , 0.0 ]
391
+ self .moved = 0
389
392
self .starttime = monotonic ()
390
393
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
+
391
403
def action (self , motion ):
392
404
'Action a motion command for this gesture'
393
405
command = self .motions .get ((motion , self .fingers )) or \
@@ -425,6 +437,21 @@ class SWIPE(GESTURE):
425
437
426
438
self .data [0 ] += x
427
439
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
428
455
return True
429
456
430
457
def end (self ):
@@ -509,9 +536,13 @@ def conf_gesture(lineargs):
509
536
command = fcommand [0 ] if fcommand else ''
510
537
else :
511
538
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
513
544
# Add the configured gesture
514
- return handler .add (motion .lower (), fingers , command )
545
+ return handler .add (motion .lower (), fingers , command , thresh )
515
546
516
547
@add_conf_command
517
548
def conf_device (lineargs ):
0 commit comments