fusuma 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e54f849efbfb11bcf56c129f310e9b12b34e6ee
4
- data.tar.gz: 79fff6396e15de51fa7427b21cc92e58ab10aefd
3
+ metadata.gz: 3978122d47e2294dd5d8391e76a0507c1e21b8de
4
+ data.tar.gz: aa5df2c6707a715577a43e43e4a5ea7e9482a084
5
5
  SHA512:
6
- metadata.gz: 060dc7031139ae57d334b0d1824f96620361244b53ce62753c511225537bb6d68730b2cd235b297bea037ef59cc32571254f62444d9d60ea847002ce5208be06
7
- data.tar.gz: 3ae2d1a41001e113f57f398000892c67518910485a90520514ed5bbc0f7fd379f59aefc07f9aa0a7e29001145c81a20fb89d0ab9d8f6e6c453920a8a31796422
6
+ metadata.gz: 124a58da4e05ae6f4cf9881a0678942eb639728e326651106a4bc6938b1397a7db36bb50efa7fbca8d99e92fe513449291ba03ee5fa906b4e0b87df06e6134ad
7
+ data.tar.gz: 44cec21490f90665063ebbd3c7567dd595ade069efc583076ffb8842b42bcd9304b55c544f072c4a3be75a1ab6398179eb6bae247574e867d215d02743d2160c
data/lib/fusuma.rb CHANGED
@@ -42,8 +42,9 @@ module Fusuma
42
42
  private
43
43
 
44
44
  def libinput_command
45
+ # NOTE: --enable-dwt means "disable while typing"
45
46
  @libinput_command ||= "stdbuf -oL -- libinput-debug-events --device \
46
- /dev/input/#{device_name}"
47
+ /dev/input/#{device_name} --enable-dwt"
47
48
  MultiLogger.debug(libinput_command: @libinput_command)
48
49
  @libinput_command
49
50
  end
@@ -72,11 +73,11 @@ module Fusuma
72
73
  end
73
74
 
74
75
  def trigger_keyevent(gesture_info)
75
- case gesture_info.action
76
+ case gesture_info.action_type
76
77
  when 'swipe'
77
- swipe(gesture_info.finger, gesture_info.direction.move)
78
+ swipe(gesture_info.finger, gesture_info.direction)
78
79
  when 'pinch'
79
- pinch(gesture_info.direction.pinch)
80
+ pinch(gesture_info.direction)
80
81
  end
81
82
  end
82
83
 
@@ -85,8 +86,8 @@ module Fusuma
85
86
  `xdotool key #{shortcut}` unless shortcut.nil?
86
87
  end
87
88
 
88
- def pinch(zoom)
89
- shortcut = event_map['pinch'][zoom]['shortcut']
89
+ def pinch(direction)
90
+ shortcut = event_map['pinch'][direction]['shortcut']
90
91
  `xdotool key #{shortcut}` unless shortcut.nil?
91
92
  end
92
93
 
@@ -7,14 +7,16 @@ module Fusuma
7
7
 
8
8
  # return { finger:, direction:, action: } or nil
9
9
  def gesture_info
10
- return unless enough_actions?
11
- MultiLogger.debug(enough_actions?: enough_actions?)
12
- direction = detect_direction
13
- finger = detect_finger
14
- action = detect_action
10
+ return unless enough_actions? && enough_time_passed?
11
+ action_type = detect_action_type
12
+ direction = detect_direction(action_type)
13
+ return if direction.nil?
14
+ @last_triggered_time = last.time
15
+ finger = detect_finger
15
16
  clear
16
- MultiLogger.debug(finger: finger, direction: direction, action: action)
17
- GestureInfo.new(finger, direction, action)
17
+ MultiLogger.debug(finger: finger, direction: direction,
18
+ action_type: action_type)
19
+ GestureInfo.new(finger, direction, action_type)
18
20
  end
19
21
 
20
22
  def push(gesture_action)
@@ -25,36 +27,56 @@ module Fusuma
25
27
 
26
28
  private
27
29
 
28
- GestureInfo = Struct.new(:finger, :direction, :action)
29
- Direction = Struct.new(:move, :pinch)
30
+ GestureInfo = Struct.new(:finger, :direction, :action_type)
30
31
 
31
- def detect_direction
32
- direction_hash = sum_direction
33
- move = detect_move(direction_hash)
34
- pinch = detect_pinch(direction_hash)
35
- Direction.new(move, pinch)
32
+ def elapsed_time
33
+ return 0 if length == 0
34
+ last.time - first.time
36
35
  end
37
36
 
38
- def detect_move(direction_hash)
39
- if direction_hash[:move][:x].abs > direction_hash[:move][:y].abs
40
- return direction_hash[:move][:x] > 0 ? 'right' : 'left'
37
+ def detect_direction(action_type)
38
+ case action_type
39
+ when 'swipe'
40
+ detect_move
41
+ when 'pinch'
42
+ detect_zoom
41
43
  end
42
- direction_hash[:move][:y] > 0 ? 'down' : 'up'
43
44
  end
44
45
 
45
- def detect_pinch(direction_hash)
46
- direction_hash[:pinch] > 1 ? 'in' : 'out'
46
+ def detect_move
47
+ moves = sum_moves
48
+ return nil if moves[:x].zero? && moves[:y].zero?
49
+ # MultiLogger.debug(moves: moves)
50
+ return nil if (moves[:x].abs < 200) && (moves[:y].abs < 200)
51
+ if moves[:x].abs > moves[:y].abs
52
+ return moves[:x] > 0 ? 'right' : 'left'
53
+ else
54
+ moves[:y] > 0 ? 'down' : 'up'
55
+ end
56
+ end
57
+
58
+ def detect_zoom
59
+ diameter = mul_diameter
60
+ # TODO: change threshold from config files
61
+ if diameter > 10
62
+ 'in'
63
+ elsif diameter < 0.1
64
+ 'out'
65
+ end
47
66
  end
48
67
 
49
68
  def detect_finger
50
69
  last.finger
51
70
  end
52
71
 
53
- def sum_direction
72
+ def sum_moves
54
73
  move_x = sum_attrs(:move_x)
55
74
  move_y = sum_attrs(:move_y)
56
- pinch = mul_attrs(:pinch)
57
- { move: { x: move_x, y: move_y }, pinch: pinch }
75
+ { x: move_x, y: move_y }
76
+ end
77
+
78
+ def mul_diameter
79
+ mul_attrs(:zoom)
58
80
  end
59
81
 
60
82
  def sum_attrs(attr)
@@ -81,10 +103,18 @@ module Fusuma
81
103
  end
82
104
 
83
105
  def enough_actions?
84
- length > 7 # TODO: should be detected by move per time
106
+ (length > 1) && (elapsed_time > 0.1)
107
+ end
108
+
109
+ def enough_time_passed?
110
+ (last.time - last_triggerd_time) > 0.5
111
+ end
112
+
113
+ def last_triggerd_time
114
+ @last_triggered_time || 0
85
115
  end
86
116
 
87
- def detect_action
117
+ def detect_action_type
88
118
  first.action =~ /GESTURE_(.*?)_/
89
119
  Regexp.last_match(1).downcase
90
120
  end
@@ -2,15 +2,15 @@ module Fusuma
2
2
  # pinch or swipe action
3
3
  class GestureAction
4
4
  def initialize(time, action, finger, directions)
5
- @time = time
5
+ @time = time.to_f
6
6
  @action = action
7
7
  @finger = finger
8
8
  @move_x = directions[:move][:x].to_f
9
9
  @move_y = directions[:move][:y].to_f
10
- @pinch = directions[:pinch].to_f
10
+ @zoom = directions[:zoom].to_f
11
11
  end
12
12
  attr_reader :time, :action, :finger,
13
- :move_x, :move_y, :pinch
13
+ :move_x, :move_y, :zoom
14
14
 
15
15
  class << self
16
16
  def initialize_by(line, device_name)
@@ -27,9 +27,9 @@ module Fusuma
27
27
 
28
28
  def gesture_action_arguments(libinput_line)
29
29
  action, time, finger_directions = parse_libinput(libinput_line)
30
- finger, move_x, move_y, pinch =
30
+ finger, move_x, move_y, zoom =
31
31
  parse_finger_directions(finger_directions)
32
- directions = { move: { x: move_x, y: move_y }, pinch: pinch }
32
+ directions = { move: { x: move_x, y: move_y }, zoom: zoom }
33
33
  [time, action, finger, directions]
34
34
  end
35
35
 
@@ -40,9 +40,9 @@ module Fusuma
40
40
  end
41
41
 
42
42
  def parse_finger_directions(finger_directions_line)
43
- finger_num, move_x, move_y, _, _, _, pinch =
43
+ finger_num, move_x, move_y, _, _, _, zoom =
44
44
  finger_directions_line.tr('/', ' ').split
45
- [finger_num, move_x, move_y, pinch]
45
+ [finger_num, move_x, move_y, zoom]
46
46
  end
47
47
  end
48
48
  end
@@ -1,3 +1,3 @@
1
1
  module Fusuma
2
- VERSION = '0.1.8'.freeze
2
+ VERSION = '0.1.9'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusuma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - iberianpig