fusuma 2.0.0.pre → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +50 -11
  3. data/fusuma.gemspec +5 -6
  4. data/lib/fusuma.rb +87 -33
  5. data/lib/fusuma/config.rb +33 -40
  6. data/lib/fusuma/config/index.rb +34 -8
  7. data/lib/fusuma/config/searcher.rb +80 -4
  8. data/lib/fusuma/custom_process.rb +13 -0
  9. data/lib/fusuma/device.rb +19 -6
  10. data/lib/fusuma/environment.rb +4 -3
  11. data/lib/fusuma/hash_support.rb +40 -0
  12. data/lib/fusuma/libinput_command.rb +10 -15
  13. data/lib/fusuma/multi_logger.rb +2 -6
  14. data/lib/fusuma/plugin/base.rb +18 -15
  15. data/lib/fusuma/plugin/buffers/buffer.rb +3 -2
  16. data/lib/fusuma/plugin/buffers/gesture_buffer.rb +34 -25
  17. data/lib/fusuma/plugin/buffers/timer_buffer.rb +3 -3
  18. data/lib/fusuma/plugin/detectors/detector.rb +26 -5
  19. data/lib/fusuma/plugin/detectors/pinch_detector.rb +109 -58
  20. data/lib/fusuma/plugin/detectors/rotate_detector.rb +91 -50
  21. data/lib/fusuma/plugin/detectors/swipe_detector.rb +93 -56
  22. data/lib/fusuma/plugin/events/event.rb +5 -4
  23. data/lib/fusuma/plugin/events/records/context_record.rb +27 -0
  24. data/lib/fusuma/plugin/events/records/gesture_record.rb +9 -6
  25. data/lib/fusuma/plugin/events/records/index_record.rb +46 -14
  26. data/lib/fusuma/plugin/events/records/record.rb +1 -1
  27. data/lib/fusuma/plugin/events/records/text_record.rb +2 -1
  28. data/lib/fusuma/plugin/executors/command_executor.rb +21 -4
  29. data/lib/fusuma/plugin/executors/executor.rb +45 -3
  30. data/lib/fusuma/plugin/filters/filter.rb +1 -1
  31. data/lib/fusuma/plugin/filters/libinput_device_filter.rb +6 -7
  32. data/lib/fusuma/plugin/filters/libinput_timeout_filter.rb +2 -2
  33. data/lib/fusuma/plugin/inputs/input.rb +20 -7
  34. data/lib/fusuma/plugin/inputs/libinput_command_input.rb +17 -5
  35. data/lib/fusuma/plugin/inputs/timer_input.rb +7 -7
  36. data/lib/fusuma/plugin/manager.rb +22 -29
  37. data/lib/fusuma/plugin/parsers/libinput_gesture_parser.rb +10 -8
  38. data/lib/fusuma/plugin/parsers/parser.rb +8 -9
  39. data/lib/fusuma/string_support.rb +16 -0
  40. data/lib/fusuma/version.rb +1 -1
  41. data/spec/helpers/config_helper.rb +20 -0
  42. data/spec/lib/config/searcher_spec.rb +97 -0
  43. data/spec/lib/config_spec.rb +112 -0
  44. data/spec/lib/custom_process_spec.rb +28 -0
  45. data/spec/lib/device_spec.rb +96 -0
  46. data/spec/lib/dummy_config.yml +31 -0
  47. data/spec/lib/fusuma_spec.rb +103 -0
  48. data/spec/lib/libinput-list-devices_iberianpig-XPS-9360.txt +181 -0
  49. data/spec/lib/libinput-list-devices_magic_trackpad.txt +51 -0
  50. data/spec/lib/libinput-list-devices_razer_razer_blade.txt +252 -0
  51. data/spec/lib/libinput-list-devices_thejinx0r.txt +361 -0
  52. data/spec/lib/libinput-list-devices_unavailable.txt +36 -0
  53. data/spec/lib/libinput_command_spec.rb +160 -0
  54. data/spec/lib/plugin/base_spec.rb +74 -0
  55. data/spec/lib/plugin/buffers/buffer_spec.rb +80 -0
  56. data/spec/lib/plugin/buffers/dummy_buffer.rb +20 -0
  57. data/spec/lib/plugin/buffers/gesture_buffer_spec.rb +172 -0
  58. data/spec/lib/plugin/detectors/detector_spec.rb +43 -0
  59. data/spec/lib/plugin/detectors/dummy_detector.rb +24 -0
  60. data/spec/lib/plugin/detectors/pinch_detector_spec.rb +119 -0
  61. data/spec/lib/plugin/detectors/rotate_detector_spec.rb +125 -0
  62. data/spec/lib/plugin/detectors/swipe_detector_spec.rb +118 -0
  63. data/spec/lib/plugin/events/event_spec.rb +30 -0
  64. data/spec/lib/plugin/events/records/gesture_record_spec.rb +22 -0
  65. data/spec/lib/plugin/events/records/record_spec.rb +31 -0
  66. data/spec/lib/plugin/events/records/text_record_spec.rb +26 -0
  67. data/spec/lib/plugin/executors/command_executor_spec.rb +57 -0
  68. data/spec/lib/plugin/executors/executor_spec.rb +160 -0
  69. data/spec/lib/plugin/filters/filter_spec.rb +92 -0
  70. data/spec/lib/plugin/filters/libinput_filter_spec.rb +120 -0
  71. data/spec/lib/plugin/inputs/input_spec.rb +70 -0
  72. data/spec/lib/plugin/inputs/libinput_command_input_spec.rb +121 -0
  73. data/spec/lib/plugin/inputs/timer_input_spec.rb +40 -0
  74. data/spec/lib/plugin/manager_spec.rb +27 -0
  75. data/spec/lib/plugin/parsers/parser_spec.rb +45 -0
  76. data/spec/spec_helper.rb +20 -0
  77. metadata +84 -38
  78. data/.github/FUNDING.yml +0 -8
  79. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -32
  80. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -17
  81. data/.github/pull_request_template.md +0 -9
  82. data/.github/stale.yml +0 -18
  83. data/.gitignore +0 -17
  84. data/.reek.yml +0 -96
  85. data/.rspec +0 -2
  86. data/.rubocop.yml +0 -40
  87. data/.rubocop_todo.yml +0 -40
  88. data/.travis.yml +0 -11
  89. data/CHANGELOG.md +0 -456
  90. data/CODE_OF_CONDUCT.md +0 -74
  91. data/CONTRIBUTING.md +0 -72
  92. data/Gemfile +0 -18
  93. data/Rakefile +0 -15
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'tempfile'
5
+
6
+ require './lib/fusuma/config'
7
+ require './lib/fusuma/plugin/filters/filter'
8
+ require './lib/fusuma/plugin/events/event'
9
+
10
+ module Fusuma
11
+ module Plugin
12
+ module Filters
13
+ class DummyFilter < Filter
14
+ DEFAULT_SOURCE = 'dummy_input'
15
+
16
+ def config_param_types
17
+ {
18
+ source: String
19
+ }
20
+ end
21
+ end
22
+
23
+ RSpec.describe DummyFilter do
24
+ let(:filter) { DummyFilter.new }
25
+
26
+ describe '#source' do
27
+ subject { filter.source }
28
+
29
+ it { is_expected.to eq DummyFilter::DEFAULT_SOURCE }
30
+
31
+ context 'with config' do
32
+ around do |example|
33
+ @custom_source = 'custom_input'
34
+
35
+ ConfigHelper.load_config_yml = <<~CONFIG
36
+ plugin:
37
+ filters:
38
+ dummy_filter:
39
+ source: #{@custom_source}
40
+ CONFIG
41
+
42
+ example.run
43
+
44
+ Config.custom_path = nil
45
+ end
46
+
47
+ it { is_expected.to eq @custom_source }
48
+ end
49
+ end
50
+
51
+ describe '#filter' do
52
+ subject { filter.filter(event) }
53
+ let(:event) { Events::Event.new(tag: 'dummy_input', record: 'dummy') }
54
+
55
+ context 'when filter#keep? return false' do
56
+ before do
57
+ allow(filter).to receive(:keep?).and_return(false)
58
+ end
59
+
60
+ it { is_expected.to be nil }
61
+ end
62
+
63
+ context 'when filter#keep? return true' do
64
+ before do
65
+ allow(filter).to receive(:keep?).and_return(true)
66
+ end
67
+
68
+ it { is_expected.to be event }
69
+ end
70
+ end
71
+
72
+ describe '#config_params' do
73
+ around do |example|
74
+ ConfigHelper.load_config_yml = <<~CONFIG
75
+ plugin:
76
+ filters:
77
+ dummy_filter:
78
+ dummy: dummy
79
+ CONFIG
80
+
81
+ example.run
82
+
83
+ Config.custom_path = nil
84
+ end
85
+
86
+ subject { filter.config_params }
87
+ it { is_expected.to eq(dummy: 'dummy') }
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'tempfile'
5
+
6
+ require './lib/fusuma/config'
7
+ require './lib/fusuma/plugin/filters/libinput_device_filter'
8
+ require './lib/fusuma/plugin/events/event'
9
+
10
+ module Fusuma
11
+ module Plugin
12
+ module Filters
13
+ RSpec.describe LibinputDeviceFilter do
14
+ before do
15
+ @filter = LibinputDeviceFilter.new
16
+ end
17
+
18
+ describe '#source' do
19
+ it { expect(@filter.source).to eq LibinputDeviceFilter::DEFAULT_SOURCE }
20
+
21
+ context 'with config' do
22
+ around do |example|
23
+ @custom_source = 'custom_input'
24
+
25
+ ConfigHelper.load_config_yml = <<~CONFIG
26
+ plugin:
27
+ filters:
28
+ libinput_device_filter:
29
+ source: #{@custom_source}
30
+ CONFIG
31
+
32
+ example.run
33
+
34
+ Config.custom_path = nil
35
+ end
36
+
37
+ it { expect(@filter.source).to eq @custom_source }
38
+ end
39
+ end
40
+
41
+ describe '#filter' do
42
+ before do
43
+ @event = Events::Event.new(tag: 'libinput_command_input', record: 'dummy')
44
+ end
45
+
46
+ context 'when filter#keep? return false' do
47
+ before do
48
+ allow(@filter).to receive(:keep?).and_return(false)
49
+ end
50
+
51
+ it { expect(@filter.filter(@event)).to be nil }
52
+ end
53
+
54
+ context 'when filter#keep? return true' do
55
+ before do
56
+ allow(@filter).to receive(:keep?).and_return(true)
57
+ end
58
+
59
+ it { expect(@filter.filter(@event)).to be @event }
60
+ end
61
+ end
62
+
63
+ describe '#keep?' do
64
+ before do
65
+ device = Device.new(id: 'event18', name: 'Awesome Touchpad', available: true)
66
+ allow(Device).to receive(:all).and_return([device])
67
+ @keep_device = LibinputDeviceFilter::KeepDevice.new(name_patterns: [])
68
+ allow(@filter).to receive(:keep_device).and_return(@keep_device)
69
+ end
70
+
71
+ context 'when including record generated from touchpad' do
72
+ before do
73
+ text = ' event18 GESTURE_SWIPE_UPDATE +1.44s 4 11.23/ 1.00 (36.91/ 3.28 unaccelerated) '
74
+ @event = Events::Event.new(tag: 'libinput_command_input', record: text)
75
+ end
76
+ it 'should keep record' do
77
+ expect(@filter.keep?(@event.record)).to be true
78
+ end
79
+
80
+ context 'when including -' do
81
+ before do
82
+ text = '-event18 GESTURE_SWIPE_UPDATE +1.44s 4 11.23/ 1.00 (36.91/ 3.28 unaccelerated) '
83
+ @event = Events::Event.new(tag: 'libinput_command_input', record: text)
84
+ end
85
+ it 'should keep record' do
86
+ expect(@filter.keep?(@event.record)).to be true
87
+ end
88
+ end
89
+ end
90
+ context 'when new device is added' do
91
+ before do
92
+ text = '-event18 DEVICE_ADDED Apple Wireless Trackpad seat0 default group13 cap:pg size 132x112mm tap(dl off) left scroll-nat scroll-2fg-edge click-buttonareas-clickfing '
93
+ @event = Events::Event.new(tag: 'libinput_command_input', record: text)
94
+ end
95
+ it 'should reset KeepDevice' do
96
+ expect(@keep_device).to receive(:reset)
97
+ @filter.keep?(@event.record)
98
+ end
99
+
100
+ it 'discard DEVICE_ADDED record' do
101
+ expect(@filter.keep?(@event.record)).to be false
102
+ end
103
+
104
+ context 'when keep device is NOT matched' do
105
+ before do
106
+ @keep_device = LibinputDeviceFilter::KeepDevice.new(name_patterns: ['Microsoft Arc Mouse'])
107
+ allow(@filter).to receive(:keep_device).and_return(@keep_device)
108
+ end
109
+ it 'should NOT reset KeepDevice' do
110
+ expect(@keep_device).not_to receive(:reset)
111
+ # NOTE: @event.record is 'Apple Wireless Touchpad'
112
+ @filter.keep?(@event.record)
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require './lib/fusuma/plugin/inputs/input'
5
+
6
+ module Fusuma
7
+ module Plugin
8
+ module Inputs
9
+ RSpec.describe Input do
10
+ let(:input) { described_class.new }
11
+
12
+ describe '#io' do
13
+ subject { input.io { 'dummy' } }
14
+ it { expect { subject }.to raise_error(NotImplementedError) }
15
+ end
16
+
17
+ describe '#create_event' do
18
+ subject { input.create_event }
19
+ it { is_expected.to be_a Events::Event }
20
+
21
+ it { expect(input.tag).to eq 'input' }
22
+ end
23
+
24
+ describe '.select' do
25
+ subject { Input.select([DummyInput.new]) }
26
+
27
+ it { is_expected.to be_a Events::Event }
28
+ end
29
+ end
30
+
31
+ class DummyInput < Input
32
+ def io
33
+ @io ||= begin
34
+ r, w = IO.pipe
35
+ w.puts 'hoge'
36
+ w.close
37
+ r
38
+ end
39
+ end
40
+ end
41
+
42
+ RSpec.describe DummyInput do
43
+ let(:dummy_input) { described_class.new }
44
+
45
+ around do |example|
46
+ ConfigHelper.load_config_yml = <<~CONFIG
47
+ plugin:
48
+ inputs:
49
+ dummy_input:
50
+ dummy: dummy
51
+ CONFIG
52
+
53
+ example.run
54
+
55
+ Config.custom_path = nil
56
+ end
57
+
58
+ describe '#io' do
59
+ subject { dummy_input.io }
60
+ it { is_expected.to be_a IO }
61
+ end
62
+
63
+ describe '#config_params' do
64
+ subject { dummy_input.config_params }
65
+ it { is_expected.to eq(dummy: 'dummy') }
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require './lib/fusuma/plugin/inputs/libinput_command_input'
5
+
6
+ module Fusuma
7
+ module Plugin
8
+ module Inputs
9
+ RSpec.describe LibinputCommandInput do
10
+ let(:input) { described_class.new }
11
+
12
+ describe '#io' do
13
+ before do
14
+ @dummy_io = StringIO.new('dummy')
15
+ dummy_pid = 999_999_999
16
+ libinput_command = instance_double(LibinputCommand)
17
+ allow(LibinputCommand).to receive(:new).and_return(libinput_command)
18
+ allow(libinput_command).to receive(:debug_events).with(@dummy_io).and_return(dummy_pid)
19
+ allow(input).to receive(:create_io).and_return [@dummy_io, @dummy_io]
20
+ end
21
+
22
+ it { expect(input.io).to eq @dummy_io }
23
+ end
24
+
25
+ describe '#libinput_options' do
26
+ it { expect(input.libinput_options).to be_a Array }
27
+
28
+ context 'when device: awesome_device is given as config_params' do
29
+ around do |example|
30
+ ConfigHelper.load_config_yml = <<~CONFIG
31
+ plugin:
32
+ inputs:
33
+ libinput_command_input:
34
+ device: awesome device
35
+ CONFIG
36
+
37
+ example.run
38
+
39
+ Config.custom_path = nil
40
+ end
41
+ it "contains --device='awesome device'" do
42
+ expect(input.libinput_options).to be_include "--device='awesome device'"
43
+ end
44
+ end
45
+
46
+ context 'when enable-tap: true is given as config_params' do
47
+ around do |example|
48
+ ConfigHelper.load_config_yml = <<~CONFIG
49
+ plugin:
50
+ inputs:
51
+ libinput_command_input:
52
+ enable-tap: true
53
+ CONFIG
54
+
55
+ example.run
56
+
57
+ Config.custom_path = nil
58
+ end
59
+ it 'contains --enable-tap' do
60
+ expect(input.libinput_options).to be_include '--enable-tap'
61
+ end
62
+ end
63
+
64
+ context 'when enable-dwt: true is given as config_params' do
65
+ around do |example|
66
+ ConfigHelper.load_config_yml = <<~CONFIG
67
+ plugin:
68
+ inputs:
69
+ libinput_command_input:
70
+ enable-dwt: true
71
+ CONFIG
72
+
73
+ example.run
74
+
75
+ Config.custom_path = nil
76
+ end
77
+ it 'contains --enable-dwt' do
78
+ expect(input.libinput_options).to be_include '--enable-dwt'
79
+ end
80
+ end
81
+
82
+ context 'when show-keycodes: true is given as config_params' do
83
+ around do |example|
84
+ ConfigHelper.load_config_yml = <<~CONFIG
85
+ plugin:
86
+ inputs:
87
+ libinput_command_input:
88
+ show-keycodes: true
89
+ CONFIG
90
+
91
+ example.run
92
+
93
+ Config.custom_path = nil
94
+ end
95
+ it 'contains --show-keycodes' do
96
+ expect(input.libinput_options).to be_include '--show-keycodes'
97
+ end
98
+ end
99
+
100
+ context 'when verbose: true is given as config_params' do
101
+ around do |example|
102
+ ConfigHelper.load_config_yml = <<~CONFIG
103
+ plugin:
104
+ inputs:
105
+ libinput_command_input:
106
+ verbose: true
107
+ CONFIG
108
+
109
+ example.run
110
+
111
+ Config.custom_path = nil
112
+ end
113
+ it 'contains --verbose' do
114
+ expect(input.libinput_options).to be_include '--verbose'
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require './lib/fusuma/plugin/inputs/timer_input'
5
+
6
+ module Fusuma
7
+ module Plugin
8
+ module Inputs
9
+ RSpec.describe TimerInput do
10
+ before do
11
+ @dummy_read = StringIO.new('dummy_read')
12
+ @dummy_write = StringIO.new('dummy_write')
13
+ @input = TimerInput.new
14
+ allow(@input).to receive(:create_io).and_return [@dummy_read, @dummy_write]
15
+ allow(@input).to receive(:fork)
16
+ allow(Process).to receive(:detach).with(anything)
17
+ end
18
+
19
+ describe '#io' do
20
+ it { expect(@input.io).to eq @dummy_read }
21
+
22
+ it 'should call #create_io' do
23
+ expect(@input).to receive(:create_io)
24
+ expect(@input).to receive(:start)
25
+ @input.io
26
+ end
27
+ end
28
+
29
+ describe '#start' do
30
+ it {
31
+ expect(@input).to receive(:fork).and_yield do |block_context|
32
+ expect(block_context).to receive(:timer_loop).with(@dummy_read, @dummy_write)
33
+ end
34
+ @input.start(@dummy_read, @dummy_write)
35
+ }
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end