fusuma 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -2
  3. data/fusuma.gemspec +17 -18
  4. data/lib/fusuma/config/index.rb +17 -17
  5. data/lib/fusuma/config/searcher.rb +1 -1
  6. data/lib/fusuma/config/yaml_duplication_checker.rb +7 -7
  7. data/lib/fusuma/config.rb +17 -13
  8. data/lib/fusuma/device.rb +12 -12
  9. data/lib/fusuma/environment.rb +10 -10
  10. data/lib/fusuma/hash_support.rb +1 -1
  11. data/lib/fusuma/libinput_command.rb +18 -19
  12. data/lib/fusuma/multi_logger.rb +4 -4
  13. data/lib/fusuma/plugin/base.rb +6 -6
  14. data/lib/fusuma/plugin/buffers/buffer.rb +5 -4
  15. data/lib/fusuma/plugin/buffers/gesture_buffer.rb +6 -6
  16. data/lib/fusuma/plugin/buffers/timer_buffer.rb +2 -2
  17. data/lib/fusuma/plugin/detectors/detector.rb +5 -5
  18. data/lib/fusuma/plugin/detectors/hold_detector.rb +29 -29
  19. data/lib/fusuma/plugin/detectors/pinch_detector.rb +47 -47
  20. data/lib/fusuma/plugin/detectors/rotate_detector.rb +40 -40
  21. data/lib/fusuma/plugin/detectors/swipe_detector.rb +43 -43
  22. data/lib/fusuma/plugin/events/event.rb +11 -11
  23. data/lib/fusuma/plugin/events/records/gesture_record.rb +5 -5
  24. data/lib/fusuma/plugin/events/records/index_record.rb +5 -5
  25. data/lib/fusuma/plugin/events/records/record.rb +2 -2
  26. data/lib/fusuma/plugin/events/records/text_record.rb +1 -1
  27. data/lib/fusuma/plugin/executors/command_executor.rb +4 -4
  28. data/lib/fusuma/plugin/executors/executor.rb +3 -3
  29. data/lib/fusuma/plugin/filters/filter.rb +3 -3
  30. data/lib/fusuma/plugin/filters/libinput_device_filter.rb +12 -12
  31. data/lib/fusuma/plugin/inputs/input.rb +8 -8
  32. data/lib/fusuma/plugin/inputs/libinput_command_input.rb +13 -13
  33. data/lib/fusuma/plugin/inputs/timer_input.rb +3 -3
  34. data/lib/fusuma/plugin/manager.rb +27 -21
  35. data/lib/fusuma/plugin/parsers/libinput_gesture_parser.rb +10 -10
  36. data/lib/fusuma/plugin/parsers/parser.rb +3 -3
  37. data/lib/fusuma/string_support.rb +3 -3
  38. data/lib/fusuma/version.rb +1 -1
  39. data/lib/fusuma.rb +10 -10
  40. metadata +3 -79
  41. data/spec/helpers/config_helper.rb +0 -20
  42. data/spec/lib/config/searcher_spec.rb +0 -179
  43. data/spec/lib/config_spec.rb +0 -104
  44. data/spec/lib/custom_process_spec.rb +0 -28
  45. data/spec/lib/device_spec.rb +0 -96
  46. data/spec/lib/dummy_config.yml +0 -31
  47. data/spec/lib/fusuma_spec.rb +0 -103
  48. data/spec/lib/libinput-list-devices_iberianpig-XPS-9360.txt +0 -181
  49. data/spec/lib/libinput-list-devices_magic_trackpad.txt +0 -51
  50. data/spec/lib/libinput-list-devices_razer_razer_blade.txt +0 -252
  51. data/spec/lib/libinput-list-devices_thejinx0r.txt +0 -361
  52. data/spec/lib/libinput-list-devices_unavailable.txt +0 -36
  53. data/spec/lib/libinput_command_spec.rb +0 -164
  54. data/spec/lib/plugin/base_spec.rb +0 -74
  55. data/spec/lib/plugin/buffers/buffer_spec.rb +0 -80
  56. data/spec/lib/plugin/buffers/dummy_buffer.rb +0 -20
  57. data/spec/lib/plugin/buffers/gesture_buffer_spec.rb +0 -192
  58. data/spec/lib/plugin/detectors/detector_spec.rb +0 -43
  59. data/spec/lib/plugin/detectors/dummy_detector.rb +0 -24
  60. data/spec/lib/plugin/detectors/hold_detector_spec.rb +0 -145
  61. data/spec/lib/plugin/detectors/pinch_detector_spec.rb +0 -119
  62. data/spec/lib/plugin/detectors/rotate_detector_spec.rb +0 -125
  63. data/spec/lib/plugin/detectors/swipe_detector_spec.rb +0 -118
  64. data/spec/lib/plugin/events/event_spec.rb +0 -30
  65. data/spec/lib/plugin/events/records/gesture_record_spec.rb +0 -22
  66. data/spec/lib/plugin/events/records/record_spec.rb +0 -31
  67. data/spec/lib/plugin/events/records/text_record_spec.rb +0 -26
  68. data/spec/lib/plugin/executors/command_executor_spec.rb +0 -57
  69. data/spec/lib/plugin/executors/executor_spec.rb +0 -164
  70. data/spec/lib/plugin/filters/filter_spec.rb +0 -92
  71. data/spec/lib/plugin/filters/libinput_filter_spec.rb +0 -120
  72. data/spec/lib/plugin/inputs/input_spec.rb +0 -70
  73. data/spec/lib/plugin/inputs/libinput_command_input_spec.rb +0 -121
  74. data/spec/lib/plugin/inputs/timer_input_spec.rb +0 -40
  75. data/spec/lib/plugin/manager_spec.rb +0 -27
  76. data/spec/lib/plugin/parsers/libinput_gesture_parser_spec.rb +0 -76
  77. data/spec/lib/plugin/parsers/parser_spec.rb +0 -45
  78. data/spec/spec_helper.rb +0 -20
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require './lib/fusuma/plugin/buffers/buffer'
4
-
5
- module Fusuma
6
- module Plugin
7
- module Buffers
8
- class DummyBuffer < Buffer
9
- DEFAULT_SOURCE = 'dummy'
10
-
11
- def config_param_types
12
- {
13
- source: String,
14
- dummy: String
15
- }
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,192 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'rspec-parameterized'
5
-
6
- require './lib/fusuma/plugin/events/event'
7
- require './lib/fusuma/plugin/events/records/gesture_record'
8
- require './lib/fusuma/plugin/buffers/gesture_buffer'
9
-
10
- module Fusuma
11
- module Plugin
12
- module Buffers
13
- RSpec.describe GestureBuffer do
14
- before do
15
- @buffer = GestureBuffer.new
16
- delta = Events::Records::GestureRecord::Delta.new(-1, 0, 0, 0, 0, 0)
17
- @event_generator = lambda { |time = nil, status = 'update'|
18
- Events::Event.new(time: time,
19
- tag: 'libinput_gesture_parser',
20
- record: Events::Records::GestureRecord.new(
21
- status: status,
22
- gesture: 'SWIPE',
23
- finger: 3,
24
- delta: delta
25
- ))
26
- }
27
- end
28
-
29
- describe '#type' do
30
- it { expect(@buffer.type).to eq 'gesture' }
31
- end
32
-
33
- describe '#buffer' do
34
- it 'should buffer gesture event' do
35
- event = @event_generator.call
36
- @buffer.buffer(event)
37
- expect(@buffer.events).to eq [event]
38
- end
39
-
40
- it 'should NOT buffer other event' do
41
- event = Events::Event.new(tag: 'SHOULD NOT BUFFER', record: 'dummy record')
42
- @buffer.buffer(event)
43
- expect(@buffer.events).to eq []
44
- end
45
-
46
- it 'should buffer begin/end' do
47
- begin_event = @event_generator.call(nil, 'begin')
48
- @buffer.buffer(begin_event)
49
- expect(@buffer.events).to eq [begin_event]
50
- end_event = @event_generator.call(nil, 'end')
51
- @buffer.buffer(end_event)
52
- expect(@buffer.events).to eq [begin_event, end_event]
53
- end
54
- end
55
-
56
- describe '#clear_expired' do
57
- context 'default' do
58
- before do
59
- @time = Time.now
60
- event1 = @event_generator.call(@time)
61
- @buffer.buffer(event1)
62
- @event2 = @event_generator.call(@time + 100)
63
- @event3 = @event_generator.call(@time + 100)
64
- @buffer.buffer(@event2)
65
- @buffer.buffer(@event3)
66
- end
67
- it 'should keep only events generated within 30 seconds' do
68
- @buffer.clear_expired(current_time: @time + 100.1)
69
- expect(@buffer.events).to eq [@event2, @event3]
70
- end
71
- context 'with cancelled or ended' do
72
- where(:last_state, :want) do
73
- [
74
- ['end', []],
75
- ['cancelled', []]
76
- ]
77
- end
78
-
79
- with_them do
80
- it 'should clear events' do
81
- event4 = @event_generator.call(@time + 100, last_state)
82
- @buffer.buffer(event4)
83
-
84
- @buffer.clear_expired(current_time: @time + 100.1)
85
- expect(@buffer.events).to eq want
86
- end
87
- end
88
- end
89
- end
90
- context 'change seconds to keep' do
91
- around do |example|
92
- ConfigHelper.load_config_yml = <<~CONFIG
93
- plugin:
94
- buffers:
95
- gesture_buffer:
96
- seconds_to_keep: 0.3
97
- CONFIG
98
-
99
- example.run
100
-
101
- Config.custom_path = nil
102
- end
103
-
104
- it 'should keep only events generated within 0.3 seconds' do
105
- expect(@buffer.config_params).to eq(seconds_to_keep: 0.3)
106
- time = Time.now
107
- event1 = @event_generator.call(time)
108
- @buffer.buffer(event1)
109
- event2 = @event_generator.call(time + 0.1)
110
- @buffer.buffer(event2)
111
- event3 = @event_generator.call(time + 0.2)
112
- @buffer.buffer(event3)
113
- @buffer.clear_expired(current_time: time + 0.29)
114
- expect(@buffer.events).to eq [event1, event2, event3]
115
-
116
- @buffer.clear_expired(current_time: time + 0.3)
117
- expect(@buffer.events).to eq [event2, event3]
118
- end
119
- end
120
- end
121
-
122
- describe '#source' do
123
- it { expect(@buffer.source).to eq GestureBuffer::DEFAULT_SOURCE }
124
-
125
- context 'with config' do
126
- around do |example|
127
- @source = 'custom_event'
128
-
129
- ConfigHelper.load_config_yml = <<~CONFIG
130
- plugin:
131
- buffers:
132
- gesture_buffer:
133
- source: #{@source}
134
- CONFIG
135
-
136
- example.run
137
-
138
- Config.custom_path = nil
139
- end
140
-
141
- it { expect(@buffer.source).to eq @source }
142
- end
143
- end
144
-
145
- describe '#sum_attrs' do
146
- it 'should calculate the sum of each attribute'
147
- end
148
-
149
- describe '#avg_attrs' do
150
- it 'should calculate the average of each attribute'
151
- end
152
-
153
- describe '#finger' do
154
- it 'should return number of fingers in gestures'
155
- end
156
-
157
- describe '#gesture' do
158
- it 'should return string of gesture type'
159
- end
160
-
161
- describe '#empty?' do
162
- context 'no gestures in buffer' do
163
- before { @buffer.clear }
164
- it { expect(@buffer.empty?).to be true }
165
- end
166
-
167
- context 'buffered some gestures' do
168
- before { @buffer.buffer(@event_generator.call) }
169
- it { expect(@buffer.empty?).to be false }
170
- end
171
- end
172
-
173
- describe '#slect_by_events' do
174
- context 'without block' do
175
- it { expect(@buffer.select_by_events).to be_a Enumerator }
176
- end
177
-
178
- context 'with block' do
179
- before do
180
- @e1 = @event_generator.call(nil, 'hoge')
181
- @e2 = @event_generator.call(nil, 'hoge')
182
- @e3 = @event_generator.call(nil, 'fuga')
183
- [@e1, @e2, @e3].each { |event| @buffer.buffer(event) }
184
- end
185
- it { expect(@buffer.select_by_events { |e| e.record.status == 'hoge' }).to be_a GestureBuffer }
186
- it { expect(@buffer.select_by_events { |e| e.record.status == 'hoge' }.events).to eq [@e1, @e2] }
187
- end
188
- end
189
- end
190
- end
191
- end
192
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- require './lib/fusuma/plugin/events/event'
6
- require './lib/fusuma/plugin/detectors/detector'
7
- require './lib/fusuma/config'
8
- require_relative '../buffers/dummy_buffer'
9
- require_relative './dummy_detector'
10
-
11
- module Fusuma
12
- module Plugin
13
- module Detectors
14
- RSpec.describe DummyDetector do
15
- before do
16
- @detector = DummyDetector.new
17
- @buffer = Buffers::DummyBuffer.new
18
- end
19
-
20
- around do |example|
21
- ConfigHelper.load_config_yml = <<~CONFIG
22
- plugin:
23
- detectors:
24
- dummy_detector:
25
- dummy: dummy
26
- CONFIG
27
-
28
- example.run
29
-
30
- ConfigHelper.clear_config_yml
31
- end
32
-
33
- describe '#detect' do
34
- it { expect(@detector.detect([@buffer])).to be_a(Events::Event) }
35
- end
36
-
37
- describe '#config_params' do
38
- it { expect(@detector.config_params).to eq(dummy: 'dummy') }
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require './lib/fusuma/plugin/detectors/detector'
4
- require './lib/fusuma/plugin/buffers/buffer'
5
- require './lib/fusuma/plugin/events/records/index_record'
6
-
7
- module Fusuma
8
- module Plugin
9
- module Detectors
10
- class DummyDetector < Detector
11
- # @param buffers [Array<Buffers::Buffer>]
12
- # @return [Event]
13
- def detect(buffers)
14
- buffers.each do |buffer|
15
- next unless buffer.type == 'dummy'
16
-
17
- record = Events::Records::IndexRecord.new(index: Config::Index.new(%w[dummy index]))
18
- return create_event(record: record)
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,145 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- require './lib/fusuma/plugin/detectors/hold_detector'
6
- require './lib/fusuma/plugin/buffers/gesture_buffer'
7
- require './lib/fusuma/plugin/events/records/gesture_record'
8
- require './lib/fusuma/config'
9
-
10
- module Fusuma
11
- module Plugin
12
- module Detectors
13
- RSpec.describe HoldDetector do
14
- before do
15
- @detector = HoldDetector.new
16
- @buffer = Buffers::GestureBuffer.new
17
- @timer_buffer = Buffers::TimerBuffer.new
18
- end
19
-
20
- around do |example|
21
- ConfigHelper.load_config_yml = <<~CONFIG
22
- threshold:
23
- hold: 1
24
- CONFIG
25
-
26
- example.run
27
-
28
- Config.custom_path = nil
29
- end
30
-
31
- describe '#detect' do
32
- context 'with no hold event in buffer' do
33
- before do
34
- @buffer.clear
35
- end
36
- it { expect(@detector.detect([@buffer, @timer_buffer])).to eq nil }
37
- end
38
-
39
- context 'with only hold begin event' do
40
- before do
41
- events = create_hold_events(statuses: ['begin'])
42
- events.each { |event| @buffer.buffer(event) }
43
- end
44
- it { expect(@detector.detect([@buffer, @timer_buffer])).to be_a Events::Event }
45
- it { expect(@detector.detect([@buffer, @timer_buffer]).record).to be_a Events::Records::IndexRecord }
46
- it { expect(@detector.detect([@buffer, @timer_buffer]).record.index).to be_a Config::Index }
47
- it 'should detect 3 fingers hold' do
48
- event = @detector.detect([@buffer, @timer_buffer])
49
- expect(event.record.index.keys.map(&:symbol)).to eq([:hold, 3, :begin])
50
- end
51
- end
52
-
53
- context 'with hold events(begin,cancelled)' do
54
- before do
55
- events = create_hold_events(statuses: %w[begin cancelled])
56
- events.each { |event| @buffer.buffer(event) }
57
- end
58
- it { expect(@detector.detect([@buffer, @timer_buffer])).to be_a Events::Event }
59
- it { expect(@detector.detect([@buffer, @timer_buffer]).record).to be_a Events::Records::IndexRecord }
60
- it { expect(@detector.detect([@buffer, @timer_buffer]).record.index).to be_a Config::Index }
61
- it 'should detect 3 fingers hold canclled' do
62
- event = @detector.detect([@buffer, @timer_buffer])
63
- expect(event.record.index.keys.map(&:symbol)).to eq([:hold, 3, :cancelled])
64
- end
65
- end
66
-
67
- context 'with hold events(begin,end)' do
68
- before do
69
- events = create_hold_events(statuses: %w[begin end])
70
- events.each { |event| @buffer.buffer(event) }
71
- end
72
- it { expect(@detector.detect([@buffer, @timer_buffer])).to be_a Events::Event }
73
- it { expect(@detector.detect([@buffer, @timer_buffer]).record).to be_a Events::Records::IndexRecord }
74
- it { expect(@detector.detect([@buffer, @timer_buffer]).record.index).to be_a Config::Index }
75
- it 'should detect 3 fingers hold' do
76
- events = @detector.detect([@buffer, @timer_buffer])
77
- expect(events.record.index.keys.map(&:symbol)).to eq([:hold, 3, :end])
78
- end
79
- end
80
-
81
- context 'with hold events and timer events' do
82
- context 'with begin event and timer events' do
83
- before do
84
- events = create_hold_events(statuses: %w[begin])
85
- events.each { |event| @buffer.buffer(event) }
86
- @time = events.last.time
87
- @timer_buffer.buffer(create_timer_event(time: @time + HoldDetector::BASE_THERESHOLD))
88
- end
89
- it { expect(@detector.detect([@buffer, @timer_buffer])).to eq nil }
90
-
91
- context 'with enough holding time' do
92
- before do
93
- @timer_buffer.clear
94
- @timer_buffer.buffer(create_timer_event(time: @time + HoldDetector::BASE_THERESHOLD + 0.01))
95
- end
96
- it { expect(@detector.detect([@buffer, @timer_buffer])).to be_a Events::Event }
97
- it { expect(@detector.detect([@buffer, @timer_buffer]).record).to be_a Events::Records::IndexRecord }
98
- it { expect(@detector.detect([@buffer, @timer_buffer]).record.index).to be_a Config::Index }
99
- it 'should detect 3 fingers hold' do
100
- events = @detector.detect([@buffer, @timer_buffer])
101
- expect(events.record.index.keys.map(&:symbol)).to eq([:hold, 3])
102
- end
103
- end
104
- context 'with changing threshold' do
105
- around do |example|
106
- ConfigHelper.load_config_yml = <<~CONFIG
107
- threshold:
108
- hold: 0.9
109
- CONFIG
110
-
111
- example.run
112
-
113
- Config.custom_path = nil
114
- end
115
-
116
- it { expect(@detector.detect([@buffer, @timer_buffer])).not_to eq nil }
117
- it 'should detect 3 fingers hold' do
118
- events = @detector.detect([@buffer, @timer_buffer])
119
- expect(events.record.index.keys.map(&:symbol)).to eq([:hold, 3])
120
- end
121
- end
122
- end
123
- end
124
- end
125
-
126
- private
127
-
128
- def create_hold_events(statuses:)
129
- record_type = HoldDetector::GESTURE_RECORD_TYPE
130
- statuses.map do |status|
131
- gesture_record = Events::Records::GestureRecord.new(status: status,
132
- gesture: record_type,
133
- finger: 3,
134
- delta: nil)
135
- Events::Event.new(tag: 'libinput_gesture_parser', record: gesture_record)
136
- end
137
- end
138
-
139
- def create_timer_event(time: Time.now)
140
- Events::Event.new(time: time, tag: 'timer_input', record: Events::Records::TextRecord.new('timer'))
141
- end
142
- end
143
- end
144
- end
145
- end
@@ -1,119 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- require './lib/fusuma/plugin/detectors/pinch_detector'
6
- require './lib/fusuma/plugin/buffers/gesture_buffer'
7
- require './lib/fusuma/plugin/events/event'
8
- require './lib/fusuma/config'
9
-
10
- module Fusuma
11
- module Plugin
12
- module Detectors
13
- RSpec.describe PinchDetector do
14
- before do
15
- @detector = PinchDetector.new
16
- @buffer = Buffers::GestureBuffer.new
17
- end
18
-
19
- around do |example|
20
- ConfigHelper.load_config_yml = <<~CONFIG
21
- threshold:
22
- rotate: 1
23
- CONFIG
24
-
25
- example.run
26
-
27
- Config.custom_path = nil
28
- end
29
-
30
- describe '#detect' do
31
- context 'with no pinch event in buffer' do
32
- before do
33
- @buffer.clear
34
- end
35
- it { expect(@detector.detect([@buffer])).to eq nil }
36
- end
37
-
38
- context 'with not enough pinch events in buffer' do
39
- before do
40
- deltas = [
41
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 1, 0),
42
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 1.1, 0)
43
- ]
44
- events = create_events(deltas: deltas)
45
-
46
- events.each { |event| @buffer.buffer(event) }
47
- end
48
- it 'should have repeat record' do
49
- expect(@detector.detect([@buffer]).record.trigger).to eq :repeat
50
- end
51
- end
52
-
53
- context 'with enough pinch IN event' do
54
- before do
55
- deltas = [
56
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 1.0, 0),
57
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 1.0, 0),
58
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 2.0, 0)
59
- ]
60
- events = create_events(deltas: deltas)
61
-
62
- events.each { |event| @buffer.buffer(event) }
63
- end
64
- it { expect(@detector.detect([@buffer])).to all be_a Events::Event }
65
- it { expect(@detector.detect([@buffer]).map(&:record)).to all be_a Events::Records::IndexRecord }
66
- it { expect(@detector.detect([@buffer]).map(&:record).map(&:index)).to all be_a Config::Index }
67
-
68
- it 'should detect 3 fingers pinch-in (oneshot/repeat)' do
69
- events = @detector.detect([@buffer])
70
- expect(events[0].record.index.keys.map(&:symbol))
71
- .to eq([:pinch, 3, :in])
72
- expect(events[1].record.index.keys.map(&:symbol))
73
- .to eq([:pinch, 3, :in, :update])
74
- end
75
- end
76
-
77
- context 'with enough pinch OUT event' do
78
- before do
79
- deltas = [
80
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 1.0, 0),
81
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0.6, 0),
82
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0.3, 0)
83
- ]
84
- events = create_events(deltas: deltas)
85
-
86
- events.each { |event| @buffer.buffer(event) }
87
- end
88
- it 'should detect 3 fingers pinch-out (oneshot/repeat)' do
89
- events = @detector.detect([@buffer])
90
- expect(events[0].record.index.keys.map(&:symbol))
91
- .to eq([:pinch, 3, :out])
92
- expect(events[1].record.index.keys.map(&:symbol))
93
- .to eq([:pinch, 3, :out, :update])
94
- end
95
- end
96
- end
97
-
98
- private
99
-
100
- def create_events(deltas: [])
101
- record_type = PinchDetector::GESTURE_RECORD_TYPE
102
- deltas.map do |delta|
103
- status = if deltas[0].equal? delta
104
- 'begin'
105
- else
106
- 'update'
107
- end
108
-
109
- gesture_record = Events::Records::GestureRecord.new(status: status,
110
- gesture: record_type,
111
- finger: 3,
112
- delta: delta)
113
- Events::Event.new(tag: 'libinput_gesture_parser', record: gesture_record)
114
- end
115
- end
116
- end
117
- end
118
- end
119
- end
@@ -1,125 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- require './lib/fusuma/plugin/detectors/rotate_detector'
6
- require './lib/fusuma/plugin/buffers/gesture_buffer'
7
- require './lib/fusuma/plugin/events/event'
8
- require './lib/fusuma/config'
9
-
10
- module Fusuma
11
- module Plugin
12
- module Detectors
13
- RSpec.describe RotateDetector do
14
- before do
15
- @detector = RotateDetector.new
16
- @buffer = Buffers::GestureBuffer.new
17
- end
18
-
19
- around do |example|
20
- ConfigHelper.load_config_yml = <<~CONFIG
21
- threshold:
22
- rotate: 1
23
- CONFIG
24
-
25
- example.run
26
-
27
- Config.custom_path = nil
28
- end
29
-
30
- describe '#detect' do
31
- context 'with no rotate event in buffer' do
32
- before do
33
- @buffer.clear
34
- end
35
- it { expect(@detector.detect([@buffer])).to eq nil }
36
- end
37
-
38
- context 'with not enough rotate events in buffer' do
39
- before do
40
- deltas = [
41
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0, 0.4),
42
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0, 0.5)
43
- ]
44
- events = create_events(deltas: deltas)
45
-
46
- events.each { |event| @buffer.buffer(event) }
47
- end
48
- it 'should have repeat record' do
49
- expect(@detector.detect([@buffer]).record.trigger).to eq :repeat
50
- end
51
- end
52
-
53
- context 'with enough rotate IN event' do
54
- before do
55
- deltas = [
56
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0, 0.5),
57
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0, 0.6),
58
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0, 0.6)
59
- ]
60
- events = create_events(deltas: deltas)
61
-
62
- events.each { |event| @buffer.buffer(event) }
63
- end
64
- it { expect(@detector.detect([@buffer])).to all be_a Events::Event }
65
- it {
66
- expect(@detector.detect([@buffer]).map(&:record)).to all be_a Events::Records::IndexRecord
67
- }
68
- it {
69
- expect(@detector.detect([@buffer]).map(&:record).map(&:index)).to all be_a Config::Index
70
- }
71
- it 'should detect 3 fingers rotate-clockwise (oneshot/repeat)' do
72
- events = @detector.detect([@buffer])
73
- expect(events[0].record.index.keys.map(&:symbol))
74
- .to eq([:rotate, 3, :clockwise])
75
- expect(events[1].record.index.keys.map(&:symbol))
76
- .to eq([:rotate, 3, :clockwise, :update])
77
- end
78
- end
79
-
80
- context 'with enough rotate OUT event' do
81
- before do
82
- deltas = [
83
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0, -0.5),
84
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0, -0.6),
85
- Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0, -0.6)
86
- ]
87
- events = create_events(deltas: deltas)
88
-
89
- events.each { |event| @buffer.buffer(event) }
90
- end
91
- it 'should detect 3 fingers rotate-counterclockwise' do
92
- events = @detector.detect([@buffer])
93
- indexes = events.map { |e| e.record.index.keys.map(&:symbol) }
94
- expect(indexes).to eq(
95
- [
96
- [:rotate, 3, :counterclockwise],
97
- [:rotate, 3, :counterclockwise, :update]
98
- ]
99
- )
100
- end
101
- end
102
- end
103
-
104
- private
105
-
106
- def create_events(deltas: [])
107
- record_type = RotateDetector::GESTURE_RECORD_TYPE
108
- deltas.map do |delta|
109
- status = if deltas[0].equal? delta
110
- 'begin'
111
- else
112
- 'update'
113
- end
114
-
115
- gesture_record = Events::Records::GestureRecord.new(status: status,
116
- gesture: record_type,
117
- finger: 3,
118
- delta: delta)
119
- Events::Event.new(tag: 'libinput_gesture_parser', record: gesture_record)
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end