From 2294393663b9a8983690004e0c6dabd45eca4465 Mon Sep 17 00:00:00 2001 From: johanw Date: Wed, 24 Mar 2021 19:29:31 +0100 Subject: [PATCH 1/4] Added multiple execution of commands --- libinput-gestures | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/libinput-gestures b/libinput-gestures index c976ea6..1cd4b8b 100755 --- a/libinput-gestures +++ b/libinput-gestures @@ -350,9 +350,10 @@ class GESTURE: 'Initialise this gesture at program start' self.name = type(self).__name__ self.motions = OrderedDict() + self.thresholds = OrderedDict() self.has_extended = False - def add(self, motion, fingers, command): + def add(self, motion, fingers, command, threshold): 'Add a configured motion command for this gesture' if motion not in self.SUPPORTED_MOTIONS: return 'Gesture {} does not support motion "{}".\n' \ @@ -365,9 +366,9 @@ class GESTURE: # their discrimination if self.extended_text in motion: self.has_extended = True - + self.thresh = threshold key = (motion, fingers) if fingers else motion - + try: cmds = shlex.split(command) except Exception as e: @@ -377,6 +378,7 @@ class GESTURE: try: self.motions[key] = cls(cmds) + self.thresholds[key] = threshold except Exception as e: return str(e) @@ -386,8 +388,18 @@ class GESTURE: 'Initialise this gesture at the start of motion' self.fingers = fingers self.data = [0.0, 0.0] + self.moved=0 self.starttime = monotonic() + def thresholdmove(self, motion): + 'Get threshold for update command' + thresh = self.thresholds.get((motion, self.fingers)) or \ + self.thresholds.get(motion) + print(thresh) + if thresh == None: + thresh=0 + return int(thresh) + def action(self, motion): 'Action a motion command for this gesture' command = self.motions.get((motion, self.fingers)) or \ @@ -425,6 +437,21 @@ class SWIPE(GESTURE): self.data[0] += x self.data[1] += y + x2, y2 = self.data + abx = abs(x2) + aby = abs(y2) + if abx > aby: + motion = 'left' if x2 < 0 else 'right' + if self.has_extended and abx > 0 and aby / abx > OBLIQUE_RATIO: + motion += '_up' if y2 < 0 else '_down' + else: + motion = 'up' if y2 < 0 else 'down' + if self.has_extended and aby > 0 and abx / aby > OBLIQUE_RATIO: + motion = ('left_' if x2 < 0 else 'right_') + motion + if self.thresholdmove(motion) > 0: + if abx**2 + aby**2-self.moved > self.thresholdmove(motion): + self.action(motion) + self.moved+=abx**2 + aby**2 return True def end(self): @@ -509,9 +536,13 @@ def conf_gesture(lineargs): command = fcommand[0] if fcommand else '' else: fingers = None - + thresh, *gcommand = command.split(maxsplit=1) + if thresh.isnumeric(): + command = gcommand[0] if fcommand else '' + else: + thresh = 0 # Add the configured gesture - return handler.add(motion.lower(), fingers, command) + return handler.add(motion.lower(), fingers, command, thresh) @add_conf_command def conf_device(lineargs): From e3ecf7cbe7fdd403b411bfa14398cda196dac9c5 Mon Sep 17 00:00:00 2001 From: johanw Date: Wed, 24 Mar 2021 19:38:04 +0100 Subject: [PATCH 2/4] Bugfixes and removing of unused print statements --- libinput-gestures | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libinput-gestures b/libinput-gestures index 9ce25a7..859b6bd 100755 --- a/libinput-gestures +++ b/libinput-gestures @@ -411,7 +411,6 @@ class GESTURE: 'Get threshold for update command' thresh = self.thresholds.get((motion, self.fingers)) or \ self.thresholds.get(motion) - print(thresh) if thresh == None: thresh=0 return int(thresh) @@ -465,9 +464,10 @@ class SWIPE(GESTURE): if self.has_extended and aby > 0 and abx / aby > OBLIQUE_RATIO: motion = ('left_' if x2 < 0 else 'right_') + motion if self.thresholdmove(motion) > 0: - if abx**2 + aby**2-self.moved > self.thresholdmove(motion): + if abx**2 + aby**2-self.moved**2 > self.thresholdmove(motion): + self.moved+=self.thresholdmove(motion) self.action(motion) - self.moved+=abx**2 + aby**2 + return True def end(self): @@ -554,7 +554,7 @@ def conf_gesture(lineargs): fingers = None thresh, *gcommand = command.split(maxsplit=1) if thresh.isnumeric(): - command = gcommand[0] if fcommand else '' + command = gcommand[0] if gcommand else '' else: thresh = 0 # Add the configured gesture From 142846919f248988732a209b560d95cb178b1e29 Mon Sep 17 00:00:00 2001 From: johanw Date: Wed, 24 Mar 2021 23:39:21 +0100 Subject: [PATCH 3/4] removed unused statement --- libinput-gestures | 1 - 1 file changed, 1 deletion(-) diff --git a/libinput-gestures b/libinput-gestures index 859b6bd..ec12b5a 100755 --- a/libinput-gestures +++ b/libinput-gestures @@ -382,7 +382,6 @@ class GESTURE: # their discrimination if self.extended_text in motion: self.has_extended = True - self.thresh = threshold key = (motion, fingers) if fingers else motion try: From ef1d2014ec5a5db29f968a4b70751e5e6213b007 Mon Sep 17 00:00:00 2001 From: johanw Date: Wed, 24 Mar 2021 23:47:21 +0100 Subject: [PATCH 4/4] fix executing command another time at the end of the gesture --- libinput-gestures | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libinput-gestures b/libinput-gestures index ec12b5a..b575994 100755 --- a/libinput-gestures +++ b/libinput-gestures @@ -490,8 +490,8 @@ class SWIPE(GESTURE): motion = 'up' if y < 0 else 'down' if self.has_extended and aby > 0 and abx / aby > OBLIQUE_RATIO: motion = ('left_' if x < 0 else 'right_') + motion - - self.action(motion) + if self.thresholdmove(motion)==0: + self.action(motion) @add_gesture_handler class PINCH(GESTURE):