From 2f85a8cf3e7c97daf9e665ea72aeb8b8fe0c96df Mon Sep 17 00:00:00 2001 From: iberianpig Date: Thu, 19 Jul 2018 11:23:09 +0900 Subject: [PATCH] stop to trigger unnecessary xdotool command --- lib/fusuma.rb | 2 +- lib/fusuma/config.yml | 15 +++++++++++---- lib/fusuma/event_trigger.rb | 12 +++++------- lib/fusuma/gesture_action.rb | 3 +-- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/fusuma.rb b/lib/fusuma.rb index ec11840..e507902 100644 --- a/lib/fusuma.rb +++ b/lib/fusuma.rb @@ -75,7 +75,7 @@ def run @action_stack ||= ActionStack.new @action_stack << gesture_action event_trigger = @action_stack.generate_event_trigger - event_trigger.send_command unless event_trigger.nil? + event_trigger.exec_command unless event_trigger.nil? end end end diff --git a/lib/fusuma/config.yml b/lib/fusuma/config.yml index 7222347..76b6476 100644 --- a/lib/fusuma/config.yml +++ b/lib/fusuma/config.yml @@ -17,11 +17,18 @@ swipe: command: 'xdotool key super+a' down: command: 'xdotool key super+s' + pinch: - in: - command: 'xdotool key ctrl+plus' - out: - command: 'xdotool key ctrl+minus' + 2: + in: + command: 'xdotool key ctrl+equal' + out: + command: 'xdotool key ctrl+minus' + 4: + in: + command: 'xdotool key super+a' + out: + command: 'xdotool key super+s' threshold: swipe: 0.3 diff --git a/lib/fusuma/event_trigger.rb b/lib/fusuma/event_trigger.rb index 75a66d8..09c65d6 100644 --- a/lib/fusuma/event_trigger.rb +++ b/lib/fusuma/event_trigger.rb @@ -8,19 +8,17 @@ def initialize(finger, direction, action_type) end attr_reader :finger, :direction, :action_type - def send_command + def exec_command + return if command.nil? + `#{command}` MultiLogger.info("trigger event: #{command}") - exec_command(command) end private - def exec_command(command) - `#{command}` unless command.nil? - end - def command - Config.command(self) || "xdotool key #{Config.shortcut(self)}" + Config.command(self).tap { |c| return c if c } + Config.shortcut(self).tap { |s| return "xdotool key #{shortcut}" if s } end end end diff --git a/lib/fusuma/gesture_action.rb b/lib/fusuma/gesture_action.rb index 1214b65..c8eca5b 100644 --- a/lib/fusuma/gesture_action.rb +++ b/lib/fusuma/gesture_action.rb @@ -29,8 +29,7 @@ def initialize_by(line, device_names) def gesture_action_arguments(libinput_line) action, time, finger, other = parse_libinput(libinput_line) - move_x, move_y, zoom = - parse_finger_directions(other) + move_x, move_y, zoom = parse_finger_directions(other) directions = { move: { x: move_x, y: move_y }, zoom: zoom } [time, action, finger, directions] end