fusuma 2.0.0.pre2 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -6
  3. data/fusuma.gemspec +3 -5
  4. data/lib/fusuma/config/searcher.rb +2 -0
  5. data/lib/fusuma/device.rb +3 -3
  6. data/lib/fusuma/environment.rb +1 -0
  7. data/lib/fusuma/libinput_command.rb +12 -12
  8. data/lib/fusuma/plugin/executors/command_executor.rb +10 -10
  9. data/lib/fusuma/plugin/inputs/input.rb +1 -0
  10. data/lib/fusuma/plugin/inputs/libinput_command_input.rb +9 -2
  11. data/lib/fusuma/plugin/manager.rb +12 -1
  12. data/lib/fusuma/version.rb +1 -1
  13. data/spec/helpers/config_helper.rb +20 -0
  14. data/spec/lib/config/searcher_spec.rb +97 -0
  15. data/spec/lib/config_spec.rb +112 -0
  16. data/spec/lib/custom_process_spec.rb +28 -0
  17. data/spec/lib/device_spec.rb +96 -0
  18. data/spec/lib/dummy_config.yml +31 -0
  19. data/spec/lib/fusuma_spec.rb +103 -0
  20. data/spec/lib/libinput-list-devices_iberianpig-XPS-9360.txt +181 -0
  21. data/spec/lib/libinput-list-devices_magic_trackpad.txt +51 -0
  22. data/spec/lib/libinput-list-devices_razer_razer_blade.txt +252 -0
  23. data/spec/lib/libinput-list-devices_thejinx0r.txt +361 -0
  24. data/spec/lib/libinput-list-devices_unavailable.txt +36 -0
  25. data/spec/lib/libinput_command_spec.rb +164 -0
  26. data/spec/lib/plugin/base_spec.rb +74 -0
  27. data/spec/lib/plugin/buffers/buffer_spec.rb +80 -0
  28. data/spec/lib/plugin/buffers/dummy_buffer.rb +20 -0
  29. data/spec/lib/plugin/buffers/gesture_buffer_spec.rb +172 -0
  30. data/spec/lib/plugin/detectors/detector_spec.rb +43 -0
  31. data/spec/lib/plugin/detectors/dummy_detector.rb +24 -0
  32. data/spec/lib/plugin/detectors/pinch_detector_spec.rb +119 -0
  33. data/spec/lib/plugin/detectors/rotate_detector_spec.rb +125 -0
  34. data/spec/lib/plugin/detectors/swipe_detector_spec.rb +118 -0
  35. data/spec/lib/plugin/events/event_spec.rb +30 -0
  36. data/spec/lib/plugin/events/records/gesture_record_spec.rb +22 -0
  37. data/spec/lib/plugin/events/records/record_spec.rb +31 -0
  38. data/spec/lib/plugin/events/records/text_record_spec.rb +26 -0
  39. data/spec/lib/plugin/executors/command_executor_spec.rb +57 -0
  40. data/spec/lib/plugin/executors/executor_spec.rb +160 -0
  41. data/spec/lib/plugin/filters/filter_spec.rb +92 -0
  42. data/spec/lib/plugin/filters/libinput_filter_spec.rb +120 -0
  43. data/spec/lib/plugin/inputs/input_spec.rb +70 -0
  44. data/spec/lib/plugin/inputs/libinput_command_input_spec.rb +121 -0
  45. data/spec/lib/plugin/inputs/timer_input_spec.rb +40 -0
  46. data/spec/lib/plugin/manager_spec.rb +27 -0
  47. data/spec/lib/plugin/parsers/parser_spec.rb +45 -0
  48. data/spec/spec_helper.rb +20 -0
  49. metadata +83 -42
  50. data/.github/FUNDING.yml +0 -8
  51. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -32
  52. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -17
  53. data/.github/pull_request_template.md +0 -9
  54. data/.github/stale.yml +0 -18
  55. data/.gitignore +0 -17
  56. data/.reek.yml +0 -96
  57. data/.rspec +0 -2
  58. data/.rubocop.yml +0 -43
  59. data/.rubocop_todo.yml +0 -55
  60. data/.solargraph.yml +0 -16
  61. data/.travis.yml +0 -9
  62. data/CHANGELOG.md +0 -456
  63. data/CODE_OF_CONDUCT.md +0 -74
  64. data/CONTRIBUTING.md +0 -72
  65. data/Gemfile +0 -23
  66. data/Rakefile +0 -15
@@ -0,0 +1,43 @@
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
+ Config.custom_path = nil
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
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,119 @@
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
@@ -0,0 +1,125 @@
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
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ require './lib/fusuma/plugin/detectors/swipe_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 SwipeDetector do
14
+ before do
15
+ @detector = SwipeDetector.new
16
+ @buffer = Buffers::GestureBuffer.new
17
+ end
18
+
19
+ around do |example|
20
+ ConfigHelper.load_config_yml = <<~CONFIG
21
+ threshold:
22
+ swipe: 1
23
+ CONFIG
24
+
25
+ example.run
26
+
27
+ Config.custom_path = nil
28
+ end
29
+
30
+ describe '#detect' do
31
+ context 'with no swipe 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 swipe events in buffer' do
39
+ before do
40
+ deltas = [
41
+ Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0, 0), # begin
42
+ Events::Records::GestureRecord::Delta.new(20, 0, 0, 0, 0, 0) # update
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
+ event = @detector.detect([@buffer])
50
+ expect(event.record.trigger).to eq :repeat
51
+ end
52
+ end
53
+
54
+ context 'with enough swipe RIGHT event' do
55
+ before do
56
+ deltas = [
57
+ Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0, 0), # begin
58
+ Events::Records::GestureRecord::Delta.new(0, 0, 0, 0, 0, 0), # update
59
+ Events::Records::GestureRecord::Delta.new(31, 0, 0, 0, 0, 0) # update
60
+ ]
61
+ events = create_events(deltas: deltas)
62
+
63
+ events.each { |event| @buffer.buffer(event) }
64
+ end
65
+ it { expect(@detector.detect([@buffer])).to all be_a Events::Event }
66
+ it { expect(@detector.detect([@buffer]).map(&:record)).to all be_a Events::Records::IndexRecord }
67
+ it { expect(@detector.detect([@buffer]).map(&:record).map(&:index)).to all be_a Config::Index }
68
+ it 'should detect 3 fingers swipe-right' do
69
+ events = @detector.detect([@buffer])
70
+ expect(events[0].record.index.keys.map(&:symbol))
71
+ .to eq([:swipe, 3, :right])
72
+ expect(events[1].record.index.keys.map(&:symbol))
73
+ .to eq([:swipe, 3, :right, :update])
74
+ end
75
+ end
76
+
77
+ context 'with enough swipe DOWN event' do
78
+ before do
79
+ deltas = [
80
+ Events::Records::GestureRecord::Delta.new(0, 0, 0, 0),
81
+ Events::Records::GestureRecord::Delta.new(0, 0, 0, 0),
82
+ Events::Records::GestureRecord::Delta.new(0, 31, 0, 0)
83
+ ]
84
+ events = create_events(deltas: deltas)
85
+
86
+ events.each { |event| @buffer.buffer(event) }
87
+ end
88
+ it 'should detect 3 fingers swipe-down' do
89
+ events = @detector.detect([@buffer])
90
+ expect(events[0].record.index.keys.map(&:symbol))
91
+ .to eq([:swipe, 3, :down])
92
+ expect(events[1].record.index.keys.map(&:symbol))
93
+ .to eq([:swipe, 3, :down, :update])
94
+ end
95
+ end
96
+ end
97
+
98
+ private
99
+
100
+ def create_events(deltas: [])
101
+ record_type = SwipeDetector::GESTURE_RECORD_TYPE
102
+ deltas.map do |delta|
103
+ status = if deltas[0].equal? delta
104
+ 'begin'
105
+ else
106
+ 'update'
107
+ end
108
+ gesture_record = Events::Records::GestureRecord.new(status: status,
109
+ gesture: record_type,
110
+ finger: 3,
111
+ delta: delta)
112
+ Events::Event.new(tag: 'libinput_gesture_parser', record: gesture_record)
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require './lib/fusuma/plugin/events/event'
5
+
6
+ module Fusuma
7
+ module Plugin
8
+ module Events
9
+ RSpec.describe Event do
10
+ let(:event) { Event.new(**args) }
11
+ let(:args) { { tag: 'text', record: 'dummy_text' } }
12
+
13
+ class DummyRecord < Records::Record
14
+ end
15
+
16
+ describe '#record' do
17
+ context 'with text' do
18
+ it { expect(event.record).to be_a Records::Record }
19
+ end
20
+
21
+ context 'with Record' do
22
+ let(:args) { { tag: 'dummy_record', record: DummyRecord.new } }
23
+
24
+ it { expect(event.record).to be_a Records::Record }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end