fusuma 2.4.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +32 -0
- data/fusuma.gemspec +17 -18
- data/lib/fusuma/config/index.rb +17 -17
- data/lib/fusuma/config/searcher.rb +1 -1
- data/lib/fusuma/config/yaml_duplication_checker.rb +7 -7
- data/lib/fusuma/config.rb +17 -13
- data/lib/fusuma/device.rb +12 -12
- data/lib/fusuma/environment.rb +10 -10
- data/lib/fusuma/hash_support.rb +1 -1
- data/lib/fusuma/libinput_command.rb +18 -19
- data/lib/fusuma/multi_logger.rb +4 -4
- data/lib/fusuma/plugin/base.rb +6 -6
- data/lib/fusuma/plugin/buffers/buffer.rb +5 -4
- data/lib/fusuma/plugin/buffers/gesture_buffer.rb +6 -6
- data/lib/fusuma/plugin/buffers/timer_buffer.rb +2 -2
- data/lib/fusuma/plugin/detectors/detector.rb +5 -5
- data/lib/fusuma/plugin/detectors/hold_detector.rb +29 -29
- data/lib/fusuma/plugin/detectors/pinch_detector.rb +47 -47
- data/lib/fusuma/plugin/detectors/rotate_detector.rb +40 -40
- data/lib/fusuma/plugin/detectors/swipe_detector.rb +43 -43
- data/lib/fusuma/plugin/events/event.rb +11 -11
- data/lib/fusuma/plugin/events/records/gesture_record.rb +5 -5
- data/lib/fusuma/plugin/events/records/index_record.rb +5 -5
- data/lib/fusuma/plugin/events/records/record.rb +2 -2
- data/lib/fusuma/plugin/events/records/text_record.rb +1 -1
- data/lib/fusuma/plugin/executors/command_executor.rb +4 -4
- data/lib/fusuma/plugin/executors/executor.rb +3 -3
- data/lib/fusuma/plugin/filters/filter.rb +3 -3
- data/lib/fusuma/plugin/filters/libinput_device_filter.rb +12 -12
- data/lib/fusuma/plugin/inputs/input.rb +8 -8
- data/lib/fusuma/plugin/inputs/libinput_command_input.rb +13 -13
- data/lib/fusuma/plugin/inputs/timer_input.rb +3 -3
- data/lib/fusuma/plugin/manager.rb +27 -21
- data/lib/fusuma/plugin/parsers/libinput_gesture_parser.rb +10 -10
- data/lib/fusuma/plugin/parsers/parser.rb +3 -3
- data/lib/fusuma/string_support.rb +3 -3
- data/lib/fusuma/version.rb +1 -1
- data/lib/fusuma.rb +10 -10
- metadata +3 -79
- data/spec/helpers/config_helper.rb +0 -20
- data/spec/lib/config/searcher_spec.rb +0 -179
- data/spec/lib/config_spec.rb +0 -104
- data/spec/lib/custom_process_spec.rb +0 -29
- data/spec/lib/device_spec.rb +0 -96
- data/spec/lib/dummy_config.yml +0 -31
- data/spec/lib/fusuma_spec.rb +0 -103
- data/spec/lib/libinput-list-devices_iberianpig-XPS-9360.txt +0 -181
- data/spec/lib/libinput-list-devices_magic_trackpad.txt +0 -51
- data/spec/lib/libinput-list-devices_razer_razer_blade.txt +0 -252
- data/spec/lib/libinput-list-devices_thejinx0r.txt +0 -361
- data/spec/lib/libinput-list-devices_unavailable.txt +0 -36
- data/spec/lib/libinput_command_spec.rb +0 -164
- data/spec/lib/plugin/base_spec.rb +0 -74
- data/spec/lib/plugin/buffers/buffer_spec.rb +0 -80
- data/spec/lib/plugin/buffers/dummy_buffer.rb +0 -20
- data/spec/lib/plugin/buffers/gesture_buffer_spec.rb +0 -192
- data/spec/lib/plugin/detectors/detector_spec.rb +0 -43
- data/spec/lib/plugin/detectors/dummy_detector.rb +0 -24
- data/spec/lib/plugin/detectors/hold_detector_spec.rb +0 -145
- data/spec/lib/plugin/detectors/pinch_detector_spec.rb +0 -119
- data/spec/lib/plugin/detectors/rotate_detector_spec.rb +0 -125
- data/spec/lib/plugin/detectors/swipe_detector_spec.rb +0 -118
- data/spec/lib/plugin/events/event_spec.rb +0 -30
- data/spec/lib/plugin/events/records/gesture_record_spec.rb +0 -22
- data/spec/lib/plugin/events/records/record_spec.rb +0 -31
- data/spec/lib/plugin/events/records/text_record_spec.rb +0 -26
- data/spec/lib/plugin/executors/command_executor_spec.rb +0 -57
- data/spec/lib/plugin/executors/executor_spec.rb +0 -164
- data/spec/lib/plugin/filters/filter_spec.rb +0 -92
- data/spec/lib/plugin/filters/libinput_filter_spec.rb +0 -120
- data/spec/lib/plugin/inputs/input_spec.rb +0 -70
- data/spec/lib/plugin/inputs/libinput_command_input_spec.rb +0 -121
- data/spec/lib/plugin/inputs/timer_input_spec.rb +0 -40
- data/spec/lib/plugin/manager_spec.rb +0 -27
- data/spec/lib/plugin/parsers/libinput_gesture_parser_spec.rb +0 -76
- data/spec/lib/plugin/parsers/parser_spec.rb +0 -45
- data/spec/spec_helper.rb +0 -23
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative "../base"
|
4
|
+
require_relative "../events/event"
|
5
5
|
|
6
6
|
module Fusuma
|
7
7
|
module Plugin
|
@@ -10,7 +10,7 @@ module Fusuma
|
|
10
10
|
class Detector < Base
|
11
11
|
# @return [Array<String>]
|
12
12
|
def sources
|
13
|
-
@source ||= self.class.const_get(
|
13
|
+
@source ||= self.class.const_get(:SOURCES)
|
14
14
|
end
|
15
15
|
|
16
16
|
# Always watch buffers and detect them or not
|
@@ -53,11 +53,11 @@ module Fusuma
|
|
53
53
|
|
54
54
|
class << self
|
55
55
|
def tag
|
56
|
-
name.split(
|
56
|
+
name.split("Detectors::").last.underscore
|
57
57
|
end
|
58
58
|
|
59
59
|
def type(tag_name = tag)
|
60
|
-
tag_name.gsub(
|
60
|
+
tag_name.gsub("_detector", "")
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "./detector"
|
4
4
|
|
5
5
|
module Fusuma
|
6
6
|
module Plugin
|
@@ -8,8 +8,8 @@ module Fusuma
|
|
8
8
|
# Detect Hold gesture
|
9
9
|
class HoldDetector < Detector
|
10
10
|
SOURCES = %w[gesture timer].freeze
|
11
|
-
BUFFER_TYPE =
|
12
|
-
GESTURE_RECORD_TYPE =
|
11
|
+
BUFFER_TYPE = "gesture"
|
12
|
+
GESTURE_RECORD_TYPE = "hold"
|
13
13
|
|
14
14
|
BASE_THERESHOLD = 0.7
|
15
15
|
|
@@ -23,7 +23,7 @@ module Fusuma
|
|
23
23
|
|
24
24
|
hold_events = hold_buffer.events
|
25
25
|
|
26
|
-
timer_buffer = buffers.find { |b| b.type ==
|
26
|
+
timer_buffer = buffers.find { |b| b.type == "timer" }
|
27
27
|
timer_events = timer_buffer.events
|
28
28
|
|
29
29
|
finger = hold_buffer.finger
|
@@ -31,27 +31,27 @@ module Fusuma
|
|
31
31
|
|
32
32
|
@timeout ||= nil
|
33
33
|
status = case hold_events.last.record.status
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
34
|
+
when "begin"
|
35
|
+
if holding_time.zero?
|
36
|
+
"begin"
|
37
|
+
else
|
38
|
+
"timer"
|
39
|
+
end
|
40
|
+
when "cancelled"
|
41
|
+
"cancelled"
|
42
|
+
when "end"
|
43
|
+
"end"
|
44
|
+
else
|
45
|
+
last_record = hold_events.last.record.status
|
46
|
+
raise "Unexpected Status:#{last_record.status} in #{last_record}"
|
47
|
+
end
|
48
48
|
|
49
49
|
repeat_index = create_repeat_index(finger: finger, status: status)
|
50
50
|
oneshot_index = create_oneshot_index(finger: finger)
|
51
51
|
|
52
|
-
@timeout = nil if status ==
|
52
|
+
@timeout = nil if status == "begin"
|
53
53
|
|
54
|
-
if status ==
|
54
|
+
if status == "timer"
|
55
55
|
return if @timeout
|
56
56
|
|
57
57
|
return unless enough?(index: oneshot_index, holding_time: holding_time)
|
@@ -96,16 +96,16 @@ module Fusuma
|
|
96
96
|
# @return [Buffers::GestureBuffer]
|
97
97
|
def find_hold_buffer(buffers)
|
98
98
|
buffers.find { |b| b.type == BUFFER_TYPE }
|
99
|
-
|
100
|
-
|
99
|
+
.select_from_last_begin
|
100
|
+
.select_by_events { |e| e.record.gesture == GESTURE_RECORD_TYPE }
|
101
101
|
end
|
102
102
|
|
103
103
|
def calc_holding_time(hold_events:, timer_events:)
|
104
104
|
last_time = if !timer_events.empty? && (hold_events.last.time < timer_events.last.time)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
timer_events.last.time
|
106
|
+
else
|
107
|
+
hold_events.last.time
|
108
|
+
end
|
109
109
|
last_time - hold_events.first.time
|
110
110
|
end
|
111
111
|
|
@@ -116,10 +116,10 @@ module Fusuma
|
|
116
116
|
def threshold(index:)
|
117
117
|
@threshold ||= {}
|
118
118
|
@threshold[index.cache_key] ||= begin
|
119
|
-
keys_specific = Config::Index.new [*index.keys,
|
120
|
-
keys_global = Config::Index.new [
|
119
|
+
keys_specific = Config::Index.new [*index.keys, "threshold"]
|
120
|
+
keys_global = Config::Index.new ["threshold", type]
|
121
121
|
config_value = Config.search(keys_specific) ||
|
122
|
-
|
122
|
+
Config.search(keys_global) || 1
|
123
123
|
BASE_THERESHOLD * config_value
|
124
124
|
end
|
125
125
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "./detector"
|
4
4
|
|
5
5
|
module Fusuma
|
6
6
|
module Plugin
|
7
7
|
module Detectors
|
8
8
|
class PinchDetector < Detector
|
9
|
-
SOURCES = [
|
10
|
-
BUFFER_TYPE =
|
11
|
-
GESTURE_RECORD_TYPE =
|
9
|
+
SOURCES = ["gesture"].freeze
|
10
|
+
BUFFER_TYPE = "gesture"
|
11
|
+
GESTURE_RECORD_TYPE = "pinch"
|
12
12
|
|
13
13
|
FINGERS = [2, 3, 4].freeze
|
14
14
|
BASE_THERESHOLD = 1.3
|
@@ -18,8 +18,8 @@ module Fusuma
|
|
18
18
|
# @return [NilClass] if event is NOT detected
|
19
19
|
def detect(buffers)
|
20
20
|
gesture_buffer = buffers.find { |b| b.type == BUFFER_TYPE }
|
21
|
-
|
22
|
-
|
21
|
+
.select_from_last_begin
|
22
|
+
.select_by_events { |e| e.record.gesture == GESTURE_RECORD_TYPE }
|
23
23
|
|
24
24
|
updating_events = gesture_buffer.updating_events
|
25
25
|
return if updating_events.empty?
|
@@ -27,29 +27,29 @@ module Fusuma
|
|
27
27
|
finger = gesture_buffer.finger
|
28
28
|
|
29
29
|
status = case gesture_buffer.events.last.record.status
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
prev_event, event = if status ==
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
30
|
+
when "end"
|
31
|
+
"end"
|
32
|
+
when "update"
|
33
|
+
if updating_events.length == 1
|
34
|
+
"begin"
|
35
|
+
else
|
36
|
+
"update"
|
37
|
+
end
|
38
|
+
else
|
39
|
+
gesture_buffer.events.last.record.status
|
40
|
+
end
|
41
|
+
|
42
|
+
prev_event, event = if status == "end"
|
43
|
+
[
|
44
|
+
gesture_buffer.events[-3],
|
45
|
+
gesture_buffer.events[-2]
|
46
|
+
]
|
47
|
+
else
|
48
|
+
[
|
49
|
+
gesture_buffer.events[-2],
|
50
|
+
gesture_buffer.events[-1]
|
51
|
+
]
|
52
|
+
end
|
53
53
|
delta = event.record.delta
|
54
54
|
prev_delta = prev_event.record.delta
|
55
55
|
|
@@ -57,25 +57,25 @@ module Fusuma
|
|
57
57
|
# repeat_quantity = Quantity.new(target: delta.zoom, base: (prev_delta&.zoom || 1.0)).to_f
|
58
58
|
|
59
59
|
repeat_index = create_repeat_index(gesture: type, finger: finger,
|
60
|
-
|
61
|
-
|
62
|
-
if status ==
|
60
|
+
direction: repeat_direction,
|
61
|
+
status: status)
|
62
|
+
if status == "update"
|
63
63
|
return unless moved?(prev_event, event)
|
64
64
|
|
65
65
|
first_zoom, avg_zoom = if updating_events.size >= 10
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
[updating_events[-10].record.delta.zoom,
|
67
|
+
gesture_buffer.class.new(
|
68
|
+
updating_events[-10..-1]
|
69
|
+
).avg_attrs(:zoom)]
|
70
|
+
else
|
71
|
+
[updating_events.first.record.delta.zoom,
|
72
|
+
gesture_buffer.avg_attrs(:zoom)]
|
73
|
+
end
|
74
74
|
|
75
75
|
oneshot_quantity = Quantity.new(target: avg_zoom, base: first_zoom).to_f
|
76
76
|
oneshot_direction = Direction.new(target: avg_zoom, base: first_zoom).to_s
|
77
77
|
oneshot_index = create_oneshot_index(gesture: type, finger: finger,
|
78
|
-
|
78
|
+
direction: oneshot_direction)
|
79
79
|
if enough_oneshot_threshold?(index: oneshot_index, quantity: oneshot_quantity)
|
80
80
|
return [
|
81
81
|
create_event(record: Events::Records::IndexRecord.new(
|
@@ -137,18 +137,18 @@ module Fusuma
|
|
137
137
|
def threshold(index:)
|
138
138
|
@threshold ||= {}
|
139
139
|
@threshold[index.cache_key] ||= begin
|
140
|
-
keys_specific = Config::Index.new [*index.keys,
|
141
|
-
keys_global
|
142
|
-
config_value
|
143
|
-
|
140
|
+
keys_specific = Config::Index.new [*index.keys, "threshold"]
|
141
|
+
keys_global = Config::Index.new ["threshold", type]
|
142
|
+
config_value = Config.search(keys_specific) ||
|
143
|
+
Config.search(keys_global) || 1
|
144
144
|
BASE_THERESHOLD * config_value
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
148
|
# direction of gesture
|
149
149
|
class Direction
|
150
|
-
IN =
|
151
|
-
OUT =
|
150
|
+
IN = "in"
|
151
|
+
OUT = "out"
|
152
152
|
|
153
153
|
def initialize(target:, base:)
|
154
154
|
@target = target.to_f
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "./detector"
|
4
4
|
|
5
5
|
module Fusuma
|
6
6
|
module Plugin
|
7
7
|
module Detectors
|
8
8
|
class RotateDetector < Detector
|
9
|
-
SOURCES = [
|
10
|
-
BUFFER_TYPE =
|
11
|
-
GESTURE_RECORD_TYPE =
|
9
|
+
SOURCES = ["gesture"].freeze
|
10
|
+
BUFFER_TYPE = "gesture"
|
11
|
+
GESTURE_RECORD_TYPE = "pinch"
|
12
12
|
|
13
13
|
FINGERS = [2, 3, 4].freeze
|
14
14
|
BASE_THERESHOLD = 0.5
|
@@ -18,58 +18,58 @@ module Fusuma
|
|
18
18
|
# @return [NilClass] if event is NOT detected
|
19
19
|
def detect(buffers)
|
20
20
|
gesture_buffer = buffers.find { |b| b.type == BUFFER_TYPE }
|
21
|
-
|
22
|
-
|
21
|
+
.select_from_last_begin
|
22
|
+
.select_by_events { |e| e.record.gesture == GESTURE_RECORD_TYPE }
|
23
23
|
|
24
24
|
updating_events = gesture_buffer.updating_events
|
25
25
|
return if updating_events.empty?
|
26
26
|
|
27
27
|
oneshot_angle = if updating_events.size >= 10
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
updating_time = 100 * (updating_events[-1].time - updating_events[-10].time)
|
29
|
+
last_10 = gesture_buffer.class.new(updating_events[-10..-1])
|
30
|
+
last_10.sum_attrs(:rotate) / updating_time
|
31
|
+
else
|
32
|
+
updating_time = 100 * (updating_events.last.time - updating_events.first.time)
|
33
|
+
gesture_buffer.sum_attrs(:rotate) / updating_time
|
34
|
+
end
|
35
35
|
|
36
36
|
return if updating_events.empty?
|
37
37
|
|
38
38
|
finger = gesture_buffer.finger
|
39
39
|
|
40
40
|
status = case gesture_buffer.events.last.record.status
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
delta = if status ==
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
41
|
+
when "end"
|
42
|
+
"end"
|
43
|
+
when "update"
|
44
|
+
if updating_events.length == 1
|
45
|
+
"begin"
|
46
|
+
else
|
47
|
+
"update"
|
48
|
+
end
|
49
|
+
else
|
50
|
+
gesture_buffer.events.last.record.status
|
51
|
+
end
|
52
|
+
|
53
|
+
delta = if status == "end"
|
54
|
+
gesture_buffer.events[-2].record.delta
|
55
|
+
else
|
56
|
+
gesture_buffer.events.last.record.delta
|
57
|
+
end
|
58
58
|
|
59
59
|
repeat_direction = Direction.new(angle: delta.rotate).to_s
|
60
60
|
repeat_quantity = Quantity.new(angle: delta.rotate).to_f
|
61
61
|
|
62
62
|
repeat_index = create_repeat_index(gesture: type, finger: finger,
|
63
|
-
|
64
|
-
|
63
|
+
direction: repeat_direction,
|
64
|
+
status: status)
|
65
65
|
|
66
|
-
if status ==
|
66
|
+
if status == "update"
|
67
67
|
return unless moved?(repeat_quantity)
|
68
68
|
|
69
69
|
oneshot_direction = Direction.new(angle: oneshot_angle).to_s
|
70
70
|
oneshot_quantity = Quantity.new(angle: oneshot_angle).to_f
|
71
71
|
oneshot_index = create_oneshot_index(gesture: type, finger: finger,
|
72
|
-
|
72
|
+
direction: oneshot_direction)
|
73
73
|
if enough_oneshot_threshold?(index: oneshot_index, quantity: oneshot_quantity)
|
74
74
|
return [
|
75
75
|
create_event(record: Events::Records::IndexRecord.new(
|
@@ -129,18 +129,18 @@ module Fusuma
|
|
129
129
|
def threshold(index:)
|
130
130
|
@threshold ||= {}
|
131
131
|
@threshold[index.cache_key] ||= begin
|
132
|
-
keys_specific = Config::Index.new [*index.keys,
|
133
|
-
keys_global
|
134
|
-
config_value
|
135
|
-
|
132
|
+
keys_specific = Config::Index.new [*index.keys, "threshold"]
|
133
|
+
keys_global = Config::Index.new ["threshold", type]
|
134
|
+
config_value = Config.search(keys_specific) ||
|
135
|
+
Config.search(keys_global) || 1
|
136
136
|
BASE_THERESHOLD * config_value
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
140
|
# direction of gesture
|
141
141
|
class Direction
|
142
|
-
CLOCKWISE =
|
143
|
-
COUNTERCLOCKWISE =
|
142
|
+
CLOCKWISE = "clockwise"
|
143
|
+
COUNTERCLOCKWISE = "counterclockwise"
|
144
144
|
|
145
145
|
def initialize(angle:)
|
146
146
|
@angle = angle.to_f
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "./detector"
|
4
4
|
|
5
5
|
module Fusuma
|
6
6
|
module Plugin
|
7
7
|
module Detectors
|
8
8
|
class SwipeDetector < Detector
|
9
|
-
SOURCES = [
|
10
|
-
BUFFER_TYPE =
|
11
|
-
GESTURE_RECORD_TYPE =
|
9
|
+
SOURCES = ["gesture"].freeze
|
10
|
+
BUFFER_TYPE = "gesture"
|
11
|
+
GESTURE_RECORD_TYPE = "swipe"
|
12
12
|
|
13
13
|
FINGERS = [3, 4].freeze
|
14
14
|
BASE_THERESHOLD = 25
|
@@ -18,57 +18,57 @@ module Fusuma
|
|
18
18
|
# @return [NilClass] if event is NOT detected
|
19
19
|
def detect(buffers)
|
20
20
|
gesture_buffer = buffers.find { |b| b.type == BUFFER_TYPE }
|
21
|
-
|
22
|
-
|
21
|
+
.select_from_last_begin
|
22
|
+
.select_by_events { |e| e.record.gesture == GESTURE_RECORD_TYPE }
|
23
23
|
|
24
24
|
updating_events = gesture_buffer.updating_events
|
25
25
|
return if updating_events.empty?
|
26
26
|
|
27
27
|
oneshot_move_x, oneshot_move_y = if updating_events.size >= 10
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
gesture_buffer.sum_attrs(:move_x) / updating_time
|
28
|
+
updating_time = 100 * (updating_events[-1].time - updating_events[-10].time)
|
29
|
+
last_10 = gesture_buffer.class.new(updating_events[-10..-1])
|
30
|
+
[last_10.sum_attrs(:move_x) / updating_time,
|
31
|
+
last_10.sum_attrs(:move_y) / updating_time]
|
32
|
+
else
|
33
|
+
updating_time = 100 * (updating_events.last.time - updating_events.first.time)
|
34
|
+
[gesture_buffer.sum_attrs(:move_x) / updating_time,
|
35
|
+
gesture_buffer.sum_attrs(:move_y) / updating_time]
|
36
|
+
end
|
37
|
+
(gesture_buffer.sum_attrs(:move_x) / updating_time)
|
38
38
|
|
39
39
|
finger = gesture_buffer.finger
|
40
40
|
status = case gesture_buffer.events.last.record.status
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
delta = if status ==
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
41
|
+
when "end"
|
42
|
+
"end"
|
43
|
+
when "update"
|
44
|
+
if updating_events.length == 1
|
45
|
+
"begin"
|
46
|
+
else
|
47
|
+
"update"
|
48
|
+
end
|
49
|
+
else
|
50
|
+
gesture_buffer.events.last.record.status
|
51
|
+
end
|
52
|
+
|
53
|
+
delta = if status == "end"
|
54
|
+
gesture_buffer.events[-2].record.delta
|
55
|
+
else
|
56
|
+
gesture_buffer.events.last.record.delta
|
57
|
+
end
|
58
58
|
|
59
59
|
repeat_direction = Direction.new(move_x: delta.move_x, move_y: delta.move_y).to_s
|
60
60
|
repeat_quantity = Quantity.new(move_x: delta.move_x, move_y: delta.move_y).to_f
|
61
61
|
|
62
62
|
repeat_index = create_repeat_index(gesture: type, finger: finger,
|
63
|
-
|
63
|
+
direction: repeat_direction, status: status)
|
64
64
|
|
65
|
-
if status ==
|
65
|
+
if status == "update"
|
66
66
|
return unless moved?(repeat_quantity)
|
67
67
|
|
68
68
|
oneshot_direction = Direction.new(move_x: oneshot_move_x, move_y: oneshot_move_y).to_s
|
69
69
|
oneshot_quantity = Quantity.new(move_x: oneshot_move_x, move_y: oneshot_move_y).to_f
|
70
70
|
oneshot_index = create_oneshot_index(gesture: type, finger: finger,
|
71
|
-
|
71
|
+
direction: oneshot_direction)
|
72
72
|
if enough_oneshot_threshold?(index: oneshot_index, quantity: oneshot_quantity)
|
73
73
|
return [
|
74
74
|
create_event(record: Events::Records::IndexRecord.new(
|
@@ -128,20 +128,20 @@ module Fusuma
|
|
128
128
|
def threshold(index:)
|
129
129
|
@threshold ||= {}
|
130
130
|
@threshold[index.cache_key] ||= begin
|
131
|
-
keys_specific = Config::Index.new [*index.keys,
|
132
|
-
keys_global = Config::Index.new [
|
131
|
+
keys_specific = Config::Index.new [*index.keys, "threshold"]
|
132
|
+
keys_global = Config::Index.new ["threshold", type]
|
133
133
|
config_value = Config.search(keys_specific) ||
|
134
|
-
|
134
|
+
Config.search(keys_global) || 1
|
135
135
|
BASE_THERESHOLD * config_value
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
139
|
# direction of gesture
|
140
140
|
class Direction
|
141
|
-
RIGHT =
|
142
|
-
LEFT =
|
143
|
-
DOWN =
|
144
|
-
UP =
|
141
|
+
RIGHT = "right"
|
142
|
+
LEFT = "left"
|
143
|
+
DOWN = "down"
|
144
|
+
UP = "up"
|
145
145
|
|
146
146
|
def initialize(move_x:, move_y:)
|
147
147
|
@move_x = move_x.to_f
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
3
|
+
require_relative "../base"
|
4
|
+
require_relative "./records/record"
|
5
|
+
require_relative "./records/text_record"
|
6
6
|
|
7
7
|
module Fusuma
|
8
8
|
module Plugin
|
@@ -20,14 +20,14 @@ module Fusuma
|
|
20
20
|
@time = time
|
21
21
|
@tag = tag
|
22
22
|
@record = case record
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
when Records::Record
|
24
|
+
record
|
25
|
+
when String
|
26
|
+
Records::TextRecord.new(record)
|
27
|
+
else
|
28
|
+
raise ArgumentError,
|
29
|
+
"@record should be String or Record"
|
30
|
+
end
|
31
31
|
end
|
32
32
|
|
33
33
|
def inspect
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "./text_record"
|
4
4
|
|
5
5
|
module Fusuma
|
6
6
|
module Plugin
|
@@ -12,8 +12,8 @@ module Fusuma
|
|
12
12
|
attr_reader :status, :gesture, :finger, :delta
|
13
13
|
|
14
14
|
Delta = Struct.new(:move_x, :move_y,
|
15
|
-
|
16
|
-
|
15
|
+
:unaccelerated_x, :unaccelerated_y,
|
16
|
+
:zoom, :rotate)
|
17
17
|
|
18
18
|
# @param status [String]
|
19
19
|
# @param gesture [String]
|
@@ -21,9 +21,9 @@ module Fusuma
|
|
21
21
|
# @param delta [Delta, NilClass]
|
22
22
|
def initialize(status:, gesture:, finger:, delta:)
|
23
23
|
super()
|
24
|
-
@status
|
24
|
+
@status = status
|
25
25
|
@gesture = gesture
|
26
|
-
@finger
|
26
|
+
@finger = finger.to_i
|
27
27
|
@delta = delta
|
28
28
|
end
|
29
29
|
end
|
@@ -44,11 +44,11 @@ module Fusuma
|
|
44
44
|
|
45
45
|
record = records.shift
|
46
46
|
new_index = case record.position
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
when :surfix
|
48
|
+
Config::Index.new([*index.keys, *record.index.keys])
|
49
|
+
else
|
50
|
+
raise "invalid index position: #{record}"
|
51
|
+
end
|
52
52
|
|
53
53
|
return unless exist_on_conf?(new_index)
|
54
54
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../../base"
|
4
4
|
|
5
5
|
module Fusuma
|
6
6
|
module Plugin
|
@@ -11,7 +11,7 @@ module Fusuma
|
|
11
11
|
class Record < Base
|
12
12
|
# @return [Symbol]
|
13
13
|
def type
|
14
|
-
raise NotImplementedError,
|
14
|
+
raise NotImplementedError, "override #type"
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|