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 +4 -4
- data/lib/fusuma.rb +7 -6
- data/lib/fusuma/action_stack.rb +55 -25
- data/lib/fusuma/gesture_action.rb +7 -7
- data/lib/fusuma/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3978122d47e2294dd5d8391e76a0507c1e21b8de
|
4
|
+
data.tar.gz: aa5df2c6707a715577a43e43e4a5ea7e9482a084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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.
|
76
|
+
case gesture_info.action_type
|
76
77
|
when 'swipe'
|
77
|
-
swipe(gesture_info.finger, gesture_info.direction
|
78
|
+
swipe(gesture_info.finger, gesture_info.direction)
|
78
79
|
when 'pinch'
|
79
|
-
pinch(gesture_info.direction
|
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(
|
89
|
-
shortcut = event_map['pinch'][
|
89
|
+
def pinch(direction)
|
90
|
+
shortcut = event_map['pinch'][direction]['shortcut']
|
90
91
|
`xdotool key #{shortcut}` unless shortcut.nil?
|
91
92
|
end
|
92
93
|
|
data/lib/fusuma/action_stack.rb
CHANGED
@@ -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
|
-
|
12
|
-
direction = detect_direction
|
13
|
-
|
14
|
-
|
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,
|
17
|
-
|
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, :
|
29
|
-
Direction = Struct.new(:move, :pinch)
|
30
|
+
GestureInfo = Struct.new(:finger, :direction, :action_type)
|
30
31
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
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
|
39
|
-
|
40
|
-
|
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
|
46
|
-
|
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
|
72
|
+
def sum_moves
|
54
73
|
move_x = sum_attrs(:move_x)
|
55
74
|
move_y = sum_attrs(:move_y)
|
56
|
-
|
57
|
-
|
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 >
|
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
|
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
|
-
@
|
10
|
+
@zoom = directions[:zoom].to_f
|
11
11
|
end
|
12
12
|
attr_reader :time, :action, :finger,
|
13
|
-
:move_x, :move_y, :
|
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,
|
30
|
+
finger, move_x, move_y, zoom =
|
31
31
|
parse_finger_directions(finger_directions)
|
32
|
-
directions = { move: { x: move_x, y: move_y },
|
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, _, _, _,
|
43
|
+
finger_num, move_x, move_y, _, _, _, zoom =
|
44
44
|
finger_directions_line.tr('/', ' ').split
|
45
|
-
[finger_num, move_x, move_y,
|
45
|
+
[finger_num, move_x, move_y, zoom]
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
data/lib/fusuma/version.rb
CHANGED