fusuma 0.11.1 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +8 -0
  3. data/.gitignore +6 -0
  4. data/.reek.yml +93 -45
  5. data/.rubocop.yml +2 -0
  6. data/.rubocop_todo.yml +16 -75
  7. data/Gemfile +2 -0
  8. data/README.md +12 -5
  9. data/Rakefile +2 -1
  10. data/bin/console +1 -1
  11. data/exe/fusuma +1 -0
  12. data/fusuma.gemspec +9 -2
  13. data/lib/fusuma.rb +88 -31
  14. data/lib/fusuma/config.rb +65 -66
  15. data/lib/fusuma/config/index.rb +49 -0
  16. data/lib/fusuma/device.rb +58 -37
  17. data/lib/fusuma/multi_logger.rb +3 -0
  18. data/lib/fusuma/plugin/base.rb +56 -0
  19. data/lib/fusuma/plugin/buffers/buffer.rb +41 -0
  20. data/lib/fusuma/plugin/buffers/gesture_buffer.rb +70 -0
  21. data/lib/fusuma/plugin/detectors/detector.rb +41 -0
  22. data/lib/fusuma/plugin/detectors/pinch_detector.rb +141 -0
  23. data/lib/fusuma/plugin/detectors/rotate_detector.rb +135 -0
  24. data/lib/fusuma/plugin/detectors/swipe_detector.rb +145 -0
  25. data/lib/fusuma/plugin/events/event.rb +38 -0
  26. data/lib/fusuma/plugin/events/records/gesture_record.rb +31 -0
  27. data/lib/fusuma/plugin/events/records/index_record.rb +53 -0
  28. data/lib/fusuma/plugin/events/records/record.rb +20 -0
  29. data/lib/fusuma/plugin/events/records/text_record.rb +28 -0
  30. data/lib/fusuma/plugin/executors/command_executor.rb +39 -0
  31. data/lib/fusuma/plugin/executors/executor.rb +27 -0
  32. data/lib/fusuma/plugin/filters/filter.rb +40 -0
  33. data/lib/fusuma/plugin/filters/libinput_device_filter.rb +42 -0
  34. data/lib/fusuma/plugin/inputs/input.rb +28 -0
  35. data/lib/fusuma/plugin/inputs/libinput_command_input.rb +133 -0
  36. data/lib/fusuma/plugin/manager.rb +118 -0
  37. data/lib/fusuma/plugin/parsers/libinput_gesture_parser.rb +54 -0
  38. data/lib/fusuma/plugin/parsers/parser.rb +46 -0
  39. data/lib/fusuma/version.rb +3 -1
  40. metadata +74 -14
  41. data/lib/fusuma/command_executor.rb +0 -43
  42. data/lib/fusuma/event_stack.rb +0 -87
  43. data/lib/fusuma/gesture_event.rb +0 -50
  44. data/lib/fusuma/libinput_commands.rb +0 -98
  45. data/lib/fusuma/pinch.rb +0 -58
  46. data/lib/fusuma/swipe.rb +0 -59
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6fe44afd179f0f4d30a1ebe074fd4d3794870ca417185bfdb3bb29254ad3a42e
4
- data.tar.gz: f7096bf6a130e9e0c3100ea6895090c629542397d5379696910045c5982bb568
3
+ metadata.gz: 80d93508637448b749150766ad39d75fffa6b993600ff40d3c95129fee193ba0
4
+ data.tar.gz: 408a2ab6bbe496f5a7d989400e3598fc9aa9371e9c13e6a9fc4e5b915033efbb
5
5
  SHA512:
6
- metadata.gz: 377f1415db80a150b9e725014585f015351376449eebf4f40b283c43d7cc53e1cd70e53ce26616172cdcc668a162e03e711f30a75871e208acf02da60ed539b7
7
- data.tar.gz: 6d5d7cb06e0d550fb8794b34671e65a89e321addc18866637c98c8b98cf966b2694de3279da505a2c9d7dbb01014f926fbd5ace4e90d50a870831232b7835271
6
+ metadata.gz: 8bbc0dbaee8c103c2d2c8d506975d85d531ba14ca204c886f2d95a6b7812f133e97e45e418086290b07e4f0aad653bf15296a1b4f7e74b63f25d02d9f4a89553
7
+ data.tar.gz: 71746fc05185021c81e54ff4956895b7e8e1644638a1b0e5917b86864175cd544085e90bf9422fb3910ecc33b8d199295ade1198eb5122b61856e5dcb58b9358
@@ -0,0 +1,8 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: # [iberianpig] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: iberianpig # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ custom: # Replace with a single custom sponsorship URL
data/.gitignore CHANGED
@@ -7,3 +7,9 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ # todo
15
+ todo.md
data/.reek.yml CHANGED
@@ -1,48 +1,96 @@
1
- ---
2
-
3
- ### Generic smell configuration
4
1
 
2
+ ---
3
+ ### enabled rules
5
4
  detectors:
6
- # # You can disable smells completely
7
- # IrresponsibleModule:
8
- # enabled: false
9
- UncommunicativeVariableName:
10
- enabled: false
5
+ TooManyInstanceVariables:
6
+ enabled: true
7
+ exclude: []
8
+ max_instance_variables: 50
9
+ TooManyMethods:
10
+ enabled: true
11
+ exclude: []
12
+ max_methods: 30
13
+ TooManyStatements:
14
+ enabled: true
15
+ exclude: []
16
+ max_statements: 80
17
+ TooManyConstants:
18
+ enabled: true
19
+ exclude: []
20
+ max_constants: 50
21
+ LongParameterList:
22
+ enabled: true
23
+ exclude: []
24
+ max_params: 8
25
+ LongYieldList:
26
+ enabled: true
27
+ exclude: []
28
+ max_params: 8
29
+ NestedIterators:
30
+ enabled: true
31
+ exclude: []
32
+ max_allowed_nesting: 5
33
+ ignore_iterators:
34
+ - tap
35
+ ModuleInitialize:
36
+ enabled: true
37
+ exclude: []
38
+ SubclassedFromCoreClass:
39
+ enabled: true
40
+ exclude: []
11
41
 
12
- #
13
- # # You can use filters to silence Reek warnings.
14
- # # Either because you simply disagree with Reek (we are not the police) or
15
- # # because you want to fix this at a later point in time.
16
- # NestedIterators:
17
- # exclude:
18
- # - "MyWorker#self.class_method" # should be refactored
19
- # - "AnotherWorker#instance_method" # should be refactored as well
20
- #
21
- # # A lot of smells allow fine tuning their configuration. You can look up all available options
22
- # # in the corresponding smell documentation in /docs. In most cases you probably can just go
23
- # # with the defaults as documented in defaults.reek.yml.
24
- # DataClump:
25
- # max_copies: 3
26
- # min_clump_size: 3
27
-
28
-
29
- # ### Directory specific configuration
30
- #
31
- # # You can configure smells on a per-directory base.
32
- # # E.g. the classic Rails case: controllers smell of NestedIterators (see /docs/Nested-Iterators.md) and
33
- # # helpers smell of UtilityFunction (see docs/Utility-Function.md)
34
- # # Note that we only allow configuration on a directory level, not a file level, so all paths have to point to directories.
35
- # directories:
36
- # "web_app/app/controllers":
37
- # NestedIterators:
38
- # enabled: false
39
- # "web_app/app/helpers":
40
- # UtilityFunction:
41
- # enabled: false
42
-
43
- # ### Excluding directories
44
- #
45
- # # Directories below will not be scanned at all
46
- # exclude_paths:
47
- # - lib/legacy
48
- # - lib/rake/legacy_tasks
42
+ ### unanabled rules
43
+ Attribute:
44
+ enabled: false
45
+ exclude: []
46
+ BooleanParameter:
47
+ enabled: false
48
+ exclude: []
49
+ ClassVariable:
50
+ enabled: false
51
+ exclude: []
52
+ ControlParameter:
53
+ enabled: false
54
+ exclude: []
55
+ DataClump:
56
+ enabled: false
57
+ exclude: []
58
+ DuplicateMethodCall:
59
+ enabled: false
60
+ exclude: []
61
+ FeatureEnvy:
62
+ enabled: false
63
+ exclude: []
64
+ InstanceVariableAssumption:
65
+ enabled: false
66
+ exclude: []
67
+ IrresponsibleModule:
68
+ enabled: false
69
+ exclude: []
70
+ ManualDispatch:
71
+ enabled: false
72
+ exclude: []
73
+ NilCheck:
74
+ enabled: false
75
+ exclude: []
76
+ RepeatedConditional:
77
+ enabled: false
78
+ exclude: []
79
+ UncommunicativeMethodName:
80
+ enabled: false
81
+ exclude: []
82
+ UncommunicativeModuleName:
83
+ enabled: false
84
+ exclude: []
85
+ UncommunicativeParameterName:
86
+ enabled: false
87
+ exclude: []
88
+ UncommunicativeVariableName:
89
+ enabled: false
90
+ exclude: []
91
+ UnusedParameters:
92
+ enabled: false
93
+ exclude: []
94
+ UtilityFunction:
95
+ enabled: false
96
+ exclude: []
@@ -7,7 +7,9 @@ Metrics/ModuleLength:
7
7
  Metrics/BlockLength:
8
8
  Exclude:
9
9
  - "**/*_spec.rb"
10
+ - "fusuma.gemspec"
10
11
 
11
12
  Metrics/LineLength:
13
+ Max: 100
12
14
  Exclude:
13
15
  - "fusuma.gemspec"
@@ -1,60 +1,28 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-05-24 12:59:49 +0900 using RuboCop version 0.70.0.
3
+ # on 2019-08-12 15:52:49 +0900 using RuboCop version 0.74.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
9
  # Offense count: 3
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
12
- # SupportedHashRocketStyles: key, separator, table
13
- # SupportedColonStyles: key, separator, table
14
- # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
15
- Layout/AlignHash:
16
- Exclude:
17
- - 'spec/lib/config_spec.rb'
18
-
19
- # Offense count: 20
20
- # Cop supports --auto-correct.
21
- Layout/EmptyLineAfterGuardClause:
22
- Exclude:
23
- - 'lib/fusuma.rb'
24
- - 'lib/fusuma/command_executor.rb'
25
- - 'lib/fusuma/config.rb'
26
- - 'lib/fusuma/device.rb'
27
- - 'lib/fusuma/event_stack.rb'
28
- - 'lib/fusuma/gesture_event.rb'
29
- - 'lib/fusuma/libinput_commands.rb'
30
- - 'lib/fusuma/multi_logger.rb'
31
- - 'lib/fusuma/pinch.rb'
32
- - 'lib/fusuma/swipe.rb'
10
+ Metrics/AbcSize:
11
+ Max: 25
33
12
 
34
- # Offense count: 1
35
- # Cop supports --auto-correct.
36
- # Configuration parameters: PreferredName.
37
- Naming/RescuedExceptionsVariableName:
38
- Exclude:
39
- - 'lib/fusuma/device.rb'
13
+ # Offense count: 6
14
+ # Configuration parameters: CountComments, ExcludedMethods.
15
+ Metrics/MethodLength:
16
+ Max: 15
40
17
 
41
- # Offense count: 1
42
- # Cop supports --auto-correct.
43
- # Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners.
44
- # SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
45
- # ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
46
- # FunctionalMethods: let, let!, subject, watch
47
- # IgnoredMethods: lambda, proc, it
48
- Style/BlockDelimiters:
18
+ # Offense count: 3
19
+ Style/Documentation:
49
20
  Exclude:
50
- - 'lib/fusuma/command_executor.rb'
51
-
52
- # Offense count: 23
53
- # Cop supports --auto-correct.
54
- # Configuration parameters: EnforcedStyle.
55
- # SupportedStyles: always, never
56
- Style/FrozenStringLiteralComment:
57
- Enabled: false
21
+ - 'spec/**/*'
22
+ - 'test/**/*'
23
+ - 'lib/fusuma/plugin/detectors/pinch_detector.rb'
24
+ - 'lib/fusuma/plugin/detectors/rotate_detector.rb'
25
+ - 'lib/fusuma/plugin/detectors/swipe_detector.rb'
58
26
 
59
27
  # Offense count: 3
60
28
  # Cop supports --auto-correct.
@@ -63,32 +31,5 @@ Style/FrozenStringLiteralComment:
63
31
  Style/NumericPredicate:
64
32
  Exclude:
65
33
  - 'spec/**/*'
66
- - 'lib/fusuma/pinch.rb'
67
- - 'lib/fusuma/swipe.rb'
68
-
69
- # Offense count: 1
70
- # Cop supports --auto-correct.
71
- # Configuration parameters: ConvertCodeThatCanStartToReturnNil, Whitelist.
72
- # Whitelist: present?, blank?, presence, try, try!
73
- Style/SafeNavigation:
74
- Exclude:
75
- - 'lib/fusuma.rb'
76
-
77
- # Offense count: 1
78
- # Cop supports --auto-correct.
79
- Style/UnneededInterpolation:
80
- Exclude:
81
- - 'lib/fusuma/command_executor.rb'
82
-
83
- # Offense count: 1
84
- # Cop supports --auto-correct.
85
- Style/UnneededPercentQ:
86
- Exclude:
87
- - 'spec/lib/command_executor_spec.rb'
88
-
89
- # Offense count: 3
90
- # Cop supports --auto-correct.
91
- # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
92
- # URISchemes: http, https
93
- Metrics/LineLength:
94
- Max: 87
34
+ - 'lib/fusuma/plugin/detectors/rotate_detector.rb'
35
+ - 'lib/fusuma/plugin/detectors/swipe_detector.rb'
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in fusuma.gemspec
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Fusuma [![Gem Version](https://badge.fury.io/rb/fusuma.svg)](https://badge.fury.io/rb/fusuma) [![Build Status](https://travis-ci.org/iberianpig/fusuma.svg?branch=master)](https://travis-ci.org/iberianpig/fusuma)
2
2
 
3
3
  Fusuma is multitouch gesture recognizer.
4
- This gem makes your linux PC able to recognize swipes or pinchs and assign commands to them.
4
+ This gem makes your linux able to recognize swipes or pinchs and assign commands to them.
5
5
 
6
6
  ![fusuma_image](https://i.gyazo.com/757fef526310b9d68f68e80eb1e4540f.png)
7
7
 
@@ -16,7 +16,7 @@ This gem makes your linux PC able to recognize swipes or pinchs and assign comma
16
16
  $ sudo gpasswd -a $USER input
17
17
  ```
18
18
 
19
- Then, You **MUST** **LOGOUT/LOGIN or REBOOT** to assign this group.
19
+ Then, You **MUST** **REBOOT** to assign this group.
20
20
 
21
21
  ### 2. Install libinput-tools
22
22
  You need `libinput` release 1.0 or later.
@@ -25,13 +25,20 @@ You need `libinput` release 1.0 or later.
25
25
  $ sudo apt-get install libinput-tools
26
26
  ```
27
27
 
28
- ### 3. Install Fusuma
28
+ ### 3. Install Ruby
29
+ Fusuma runs in Ruby, so you must install it first.
30
+
31
+ ```bash
32
+ $ sudo apt-get install ruby
33
+ ```
34
+
35
+ ### 4. Install Fusuma
29
36
 
30
37
  ```bash
31
38
  $ sudo gem install fusuma
32
39
  ```
33
40
 
34
- ### 4. Install xdotool(optional)
41
+ ### 5. Install xdotool (optional)
35
42
 
36
43
  For sending shortcuts:
37
44
  ```bash
@@ -126,7 +133,7 @@ swipe:
126
133
  command: 'xdotool key super'
127
134
  4:
128
135
  up:
129
- command: 'xdptool key super+m'
136
+ command: 'xdotool key super+m'
130
137
  down:
131
138
  command: 'xdotool key super+m'
132
139
  pinch:
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
@@ -5,7 +7,6 @@ RSpec::Core::RakeTask.new(:spec)
5
7
 
6
8
  task default: :spec
7
9
 
8
-
9
10
  require 'github_changelog_generator/task'
10
11
 
11
12
  GitHubChangelogGenerator::RakeTask.new :changelog do |config|
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'fusuma'
@@ -8,5 +9,4 @@ require 'fusuma'
8
9
 
9
10
  # (If you use this, don't forget to add pry to your Gemfile!)
10
11
  require 'pry'
11
- require 'pry-byebug'
12
12
  Pry.start
data/exe/fusuma CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'optparse'
4
5
  require_relative '../lib/fusuma'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'fusuma/version'
@@ -9,7 +11,7 @@ Gem::Specification.new do |spec|
9
11
  spec.email = ['yhkyky@gmail.com']
10
12
 
11
13
  spec.summary = 'Multitouch gestures with libinput dirver on X11, Linux'
12
- spec.description = 'Fusuma is multitouch gesture recognizer. This gem makes your linux PC able to recognize swipes or pinchs and assign command to them. Read installation on Github(https://github.com/iberianpig/fusuma#installation).'
14
+ spec.description = 'Fusuma is multitouch gesture recognizer. This gem makes your touchpad on Linux able to recognize swipes or pinchs and assign command to them. Read installation on Github(https://github.com/iberianpig/fusuma#installation).'
13
15
  spec.homepage = 'https://github.com/iberianpig/fusuma'
14
16
  spec.license = 'MIT'
15
17
 
@@ -19,12 +21,17 @@ Gem::Specification.new do |spec|
19
21
  spec.bindir = 'exe'
20
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
23
  spec.require_paths = ['lib']
24
+ spec.metadata['yard.run'] = 'yri' # use "yard" to build full HTML docs.
22
25
 
26
+ spec.required_ruby_version = '>= 2.3' # https://packages.ubuntu.com/search?keywords=ruby&searchon=names&exact=1&suite=all&section=main
23
27
  spec.add_development_dependency 'bundler'
24
28
  spec.add_development_dependency 'github_changelog_generator', '~> 1.14'
25
29
  spec.add_development_dependency 'pry-byebug', '~> 3.4'
26
- spec.add_development_dependency 'rake', '~> 12.3'
30
+ spec.add_development_dependency 'pry-doc'
31
+ spec.add_development_dependency 'pry-inline'
32
+ spec.add_development_dependency 'rake', '~> 13.0'
27
33
  spec.add_development_dependency 'reek'
28
34
  spec.add_development_dependency 'rspec', '~> 3.0'
29
35
  spec.add_development_dependency 'rubocop'
36
+ spec.add_development_dependency 'yard'
30
37
  end
@@ -1,16 +1,10 @@
1
- require_relative 'fusuma/version'
2
- require_relative 'fusuma/event_stack'
3
- require_relative 'fusuma/gesture_event'
4
- require_relative 'fusuma/command_executor'
5
- require_relative 'fusuma/swipe.rb'
6
- require_relative 'fusuma/pinch.rb'
7
- require_relative 'fusuma/multi_logger'
8
- require_relative 'fusuma/config.rb'
9
- require_relative 'fusuma/device.rb'
10
- require_relative 'fusuma/libinput_commands.rb'
11
- require 'logger'
12
- require 'open3'
13
- require 'yaml'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './fusuma/version'
4
+ require_relative './fusuma/multi_logger'
5
+ require_relative './fusuma/config.rb'
6
+ require_relative './fusuma/device.rb'
7
+ require_relative './fusuma/plugin/manager.rb'
14
8
 
15
9
  # this is top level module
16
10
  module Fusuma
@@ -32,53 +26,116 @@ module Fusuma
32
26
  end
33
27
 
34
28
  def read_options(option)
35
- print_version && exit(0) if option[:version]
29
+ MultiLogger.instance.debug_mode = option[:verbose]
30
+
31
+ load_custom_config(option[:config_path])
32
+
33
+ Plugin::Manager.require_plugins_from_relative
34
+ Plugin::Manager.require_plugins_from_config
35
+
36
+ print_version(then_exit: option[:version])
37
+ print_enabled_plugins
38
+
36
39
  print_device_list if option[:list]
37
- reload_custom_config(option[:config_path])
38
- debug_mode if option[:verbose]
39
- Device.given_device = option[:device]
40
+ Device.given_devices = option[:device]
40
41
  Process.daemon if option[:daemon]
41
42
  end
42
43
 
43
- def print_version
44
+ # TODO: print after reading plugins
45
+ def print_version(then_exit: false)
44
46
  MultiLogger.info '---------------------------------------------'
45
47
  MultiLogger.info "Fusuma: #{Fusuma::VERSION}"
46
- MultiLogger.info "libinput: #{LibinputCommands.new.version}"
48
+ MultiLogger.info "libinput: #{Plugin::Inputs::LibinputCommandInput.new.version}"
47
49
  MultiLogger.info "OS: #{`uname -rsv`}".strip
48
50
  MultiLogger.info "Distribution: #{`cat /etc/issue`}".strip
49
51
  MultiLogger.info "Desktop session: #{`echo $DESKTOP_SESSION`}".strip
50
52
  MultiLogger.info '---------------------------------------------'
53
+ Kernel.exit(0) if then_exit
54
+ end
55
+
56
+ def print_enabled_plugins
57
+ MultiLogger.debug '---------------------------------------------'
58
+ MultiLogger.debug 'Enabled Plugins: '
59
+ Plugin::Manager.plugins
60
+ .reject { |k, _v| k.to_s =~ /Base/ }
61
+ .map { |_base, plugins| plugins.map { |plugin| " #{plugin}" } }
62
+ .flatten.sort.each { |name| MultiLogger.debug name }
63
+ MultiLogger.debug '---------------------------------------------'
51
64
  end
52
65
 
53
66
  def print_device_list
54
- puts Device.names
67
+ puts Device.available.map(&:name)
55
68
  exit(0)
56
69
  end
57
70
 
58
- def reload_custom_config(config_path = nil)
71
+ def load_custom_config(config_path = nil)
59
72
  return unless config_path
60
- MultiLogger.info "use custom path: #{config_path}"
61
- Config.instance.custom_path = config_path
62
- Config.reload
73
+
74
+ Config.custom_path = config_path
63
75
  end
64
76
 
65
77
  def debug_mode
66
- print_version
67
78
  MultiLogger.instance.debug_mode = true
79
+ print_version
68
80
  end
69
81
  end
70
82
 
71
83
  def initialize
72
- @event_stack = EventStack.new
84
+ @inputs = Plugin::Inputs::Input.plugins.map(&:new)
85
+ @filters = Plugin::Filters::Filter.plugins.map(&:new)
86
+ @parsers = Plugin::Parsers::Parser.plugins.map(&:new)
87
+ @buffers = Plugin::Buffers::Buffer.plugins.map(&:new)
88
+ @detectors = Plugin::Detectors::Detector.plugins.map(&:new)
89
+ @executors = Plugin::Executors::Executor.plugins.map(&:new)
73
90
  end
74
91
 
75
92
  def run
76
- LibinputCommands.new.debug_events do |line|
77
- gesture_event = GestureEvent.initialize_by(line.to_s, Device.ids)
78
- next unless gesture_event
79
- @event_stack << gesture_event
80
- @event_stack.generate_command_executor.tap { |c| c.execute if c }
93
+ # TODO: run with multi thread
94
+ @inputs.first.run do |event|
95
+ filtered = filter(event)
96
+ parsed = parse(filtered)
97
+ buffered = buffer(parsed)
98
+ detected = detect(buffered)
99
+ execute(detected)
100
+ end
101
+ end
102
+
103
+ def filter(event)
104
+ @filters.reduce(event) { |e, f| f.filter(e) if e }
105
+ end
106
+
107
+ def parse(event)
108
+ @parsers.reduce(event) { |e, p| p.parse(e) if e }
109
+ end
110
+
111
+ def buffer(event)
112
+ @buffers.each { |b| b.buffer(event) }
113
+ end
114
+
115
+ # @param buffers [Array<Buffer>]
116
+ # @return [Event] if event is detected
117
+ # @return [NilClass] if event is NOT detected
118
+ def detect(buffers)
119
+ @detectors.each_with_object([]) do |detector, index_records|
120
+ event = detector.detect(buffers) # event
121
+
122
+ if event&.record&.mergable?
123
+ event.record.merge(records: index_records)
124
+ buffers.each(&:clear) # clear buffer
125
+ break(event)
126
+ end
127
+
128
+ break nil if @detectors.last == detector
129
+ end
130
+ end
131
+
132
+ def execute(event)
133
+ return unless event
134
+
135
+ executor = @executors.find do |e|
136
+ e.executable?(event)
81
137
  end
138
+ executor&.execute(event)
82
139
  end
83
140
  end
84
141
  end