fusuma-plugin-tap 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4bc96ae652bcda2a8d1cf2377ba820a07ee825153d6e1882522e58b2ab6858d
4
- data.tar.gz: f4f4d27eb30547306affe7b89667bbf8eea53e7da2aa0799acd88641593b1b22
3
+ metadata.gz: 60bbd57c723571a4116d0faf32b84b4857896be3fc13100095f612dde65c3a61
4
+ data.tar.gz: b6c3a85d4d2c97ddd8d465ea4489e970e0aec92e46bf1a85424c90a32531f0db
5
5
  SHA512:
6
- metadata.gz: e7b8e79803a6d2e2cbd0d3469a041620b7b89fb4e240815b6a91716a67142a42e02192e1fa32a68a964428fb90adc48955dd63894e6cbc551c6509892a34473c
7
- data.tar.gz: 2abf4137e293d5f0ed47a43258ee8027623347b1b178ccb665e27dccc06bfa49517af73f6902d0f41ca83a523f1899e2e8ce60b5764de02f87b3b86342d345bd
6
+ metadata.gz: 4cd7807637d102af21685411058462c2c1c895c655fb7de337bdc72d4e068bd883e7e8dc97fe8d37a7486e1bf6a71cae987d330517c33bd793512bc5a708e24b
7
+ data.tar.gz: d8513da9b395013a7cb5042d0b5d71f9645f09022d872decc5983ff9c860cf7e410bf6bcf336ec9cc4bcb059bdefeab821d12528c972852c04fd7bc244a1e293
data/.gitignore CHANGED
@@ -10,3 +10,6 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+
14
+ # direnv
15
+ .envrc
data/.rubocop.yml CHANGED
@@ -3,8 +3,24 @@ inherit_from: .rubocop_todo.yml
3
3
  Metrics/ModuleLength:
4
4
  Exclude:
5
5
  - "**/*_spec.rb"
6
+ - 'lib/fusuma/plugin/parsers/tap_parser.rb'
7
+ - 'lib/fusuma/plugin/parsers/tap_detector.rb'
6
8
 
7
9
  Metrics/BlockLength:
8
10
  Exclude:
9
11
  - "**/*_spec.rb"
10
12
  - "fusuma.gemspec"
13
+ - 'lib/fusuma/plugin/parsers/tap_parser.rb'
14
+ - 'lib/fusuma/plugin/parsers/tap_detector.rb'
15
+
16
+ Metrics/MethodLength:
17
+ Exclude:
18
+ - 'lib/fusuma/plugin/parsers/tap_parser.rb'
19
+ - 'lib/fusuma/plugin/parsers/tap_detector.rb'
20
+
21
+ Layout/LineLength:
22
+ Max: 100
23
+ Exclude:
24
+ - 'spec/**/*'
25
+ - 'lib/fusuma/plugin/parsers/tap_parser.rb'
26
+ - 'lib/fusuma/plugin/parsers/tap_detector.rb'
data/.rubocop_todo.yml CHANGED
@@ -1,12 +1,28 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-03-20 13:09:40 +0900 using RuboCop version 0.80.0.
3
+ # on 2020-04-20 01:40:44 +0900 using RuboCop version 0.82.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
- # Offense count: 3
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: TreatCommentsAsGroupSeparators, Include.
12
+ # Include: **/*.gemspec
13
+ Gemspec/OrderedDependencies:
14
+ Exclude:
15
+ - 'fusuma-plugin-tap.gemspec'
16
+
17
+ # Offense count: 1
18
+ # Configuration parameters: Include.
19
+ # Include: **/*.gemspec
20
+ Gemspec/RequiredRubyVersion:
21
+ Exclude:
22
+ - 'fusuma-plugin-tap.gemspec'
23
+
24
+ # Offense count: 5
25
+ # Configuration parameters: IgnoredMethods.
10
26
  Metrics/AbcSize:
11
27
  Max: 38
12
28
 
@@ -14,36 +30,26 @@ Metrics/AbcSize:
14
30
  # Configuration parameters: CountComments, ExcludedMethods.
15
31
  # ExcludedMethods: refine
16
32
  Metrics/BlockLength:
17
- Max: 26
33
+ Max: 33
18
34
 
19
35
  # Offense count: 1
36
+ # Configuration parameters: IgnoredMethods.
20
37
  Metrics/CyclomaticComplexity:
21
38
  Max: 22
22
39
 
23
- # Offense count: 4
40
+ # Offense count: 5
24
41
  # Configuration parameters: CountComments, ExcludedMethods.
25
42
  Metrics/MethodLength:
26
- Max: 64
43
+ Max: 45
27
44
 
28
45
  # Offense count: 1
46
+ # Configuration parameters: IgnoredMethods.
29
47
  Metrics/PerceivedComplexity:
30
48
  Max: 10
31
49
 
32
50
  # Offense count: 1
33
- # Configuration parameters: MinBodyLength.
34
- Style/GuardClause:
35
- Exclude:
36
- - 'lib/fusuma/plugin/detectors/tap_detector.rb'
37
-
38
- # Offense count: 3
39
- # Cop supports --auto-correct.
40
- Style/IfUnlessModifier:
51
+ Style/Documentation:
41
52
  Exclude:
42
- - 'lib/fusuma/plugin/detectors/tap_detector.rb'
43
-
44
- # Offense count: 32
45
- # Cop supports --auto-correct.
46
- # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
47
- # URISchemes: http, https
48
- Layout/LineLength:
49
- Max: 135
53
+ - 'spec/**/*'
54
+ - 'test/**/*'
55
+ - 'bin/evemu_recorder.rb'
data/.travis.yml CHANGED
@@ -2,6 +2,20 @@
2
2
  sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
+
6
+ env:
7
+ matrix:
8
+ - SPEC_LIBINPUT_VERSION=1.10.4
9
+ - SPEC_LIBINPUT_VERSION=1.14.1
10
+
11
+ cache:
12
+ directories:
13
+ - vendor/bundle
14
+
5
15
  rvm:
6
- - 2.4.1
7
- before_install: gem install bundler -v 2.0.1
16
+ - 2.3.1
17
+ - 2.4
18
+ - 2.5
19
+ - 2.6
20
+
21
+ before_install: gem install bundler --no-document -v 2.0.1
data/bin/console CHANGED
@@ -9,5 +9,21 @@ require 'fusuma/plugin/tap'
9
9
  # with your gem easier. You can also use a different console, if you like.
10
10
 
11
11
  # (If you use this, don't forget to add pry to your Gemfile!)
12
+ def reload!(print = true)
13
+ puts 'Reloading ...' if print
14
+ # Main project directory.
15
+ root_dir = File.expand_path('..', __dir__)
16
+ # Directories within the project that should be reloaded.
17
+ reload_dirs = %w[lib]
18
+ # Loop through and reload every file in all relevant project directories.
19
+ reload_dirs.each do |dir|
20
+ glob = Dir.glob("#{root_dir}/#{dir}/**/*.rb")
21
+ additional = ['bin/libinput_debug_events_generator.rb']
22
+ (glob | additional).each { |f| load(f) }
23
+ end
24
+ # Return true when complete.
25
+ true
26
+ end
27
+
12
28
  require 'pry'
13
29
  Pry.start
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'fileutils'
5
+ require 'optparse'
6
+ require 'fusuma/device'
7
+
8
+ class EvemuRecorder
9
+ def initialize(option)
10
+ @gesture_name = option[:gesture_name]
11
+ @overwrite = option[:overwrite]
12
+ @record_command = 'evemu-record'
13
+ end
14
+
15
+ def record
16
+ if File.exist?(filepath)
17
+ raise "exist file: #{@filepath}" unless @overwrite
18
+ end
19
+
20
+ puts '----DO NOT TOUCH YOUR TRACKPAD----'
21
+
22
+ require 'pty'
23
+ require 'timeout'
24
+ PTY.spawn("#{@record_command} /dev/input/#{device_id}") do |r, w, pid|
25
+ w.close_write
26
+ r.sync = true
27
+ log = ''
28
+
29
+ begin
30
+ log = r.read_nonblock(100_000)
31
+ rescue IO::EAGAINWaitReadable
32
+ retry
33
+ end
34
+
35
+ begin
36
+ Timeout.timeout(5) do
37
+ loop { log += r.getc }
38
+ end
39
+ rescue Timeout::Error
40
+ puts 'cut out device infos'
41
+ end
42
+
43
+ file = File.open(filepath, 'w')
44
+ file.puts log
45
+ file.close
46
+
47
+ puts Process.kill(:TERM, pid)
48
+ Process.wait(pid)
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def mkdir
55
+ dir = 'spec/fusuma/plugin/parsers/evemu'
56
+ FileUtils.mkdir_p(dir)
57
+ end
58
+
59
+ def filepath
60
+ "#{mkdir.first}/#{@gesture_name}"
61
+ end
62
+
63
+ def device_id
64
+ Fusuma::Device.available.first.id
65
+ end
66
+
67
+ def version
68
+ @version ||= `#{@list_devices} --version`.chomp
69
+ end
70
+ end
71
+
72
+ option = {}
73
+ opt = OptionParser.new
74
+
75
+ opt.on('-f', 'force overwrite record file') do |v|
76
+ option[:overwrite] = v
77
+ end
78
+
79
+ opt.on('-g', '--gesture_name=', 'gesture filename: like 1finger-tap.txt') do |v|
80
+ option[:gesture_name] = v
81
+ end
82
+
83
+ opt.parse!(ARGV)
84
+
85
+ raise 'require filename -g 1finger-tap.txt' unless option[:gesture_name]
86
+
87
+ EvemuRecorder.new(option).record
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'fileutils'
5
+ require 'pathname'
6
+ require 'fusuma/device'
7
+
8
+ # Generate libinput generator
9
+ class LibinputDebugEventsGenerator
10
+ def initialize(evemu_record:)
11
+ @evemu_record = evemu_record
12
+ @gesture_name = Pathname.new(evemu_record).basename
13
+ @list_devices = ENV.fetch('LIBINPUT_LIST_DEVICES', 'libinput list-devices')
14
+ @debug_events = ENV.fetch('LIBINPUT_DEBUG_EVENTS', 'libinput debug-events')
15
+ end
16
+
17
+ def generate_debug_events
18
+ if File.exist?(filepath)
19
+ puts "exist file: #{filepath}"
20
+ return
21
+ end
22
+
23
+ require 'pty'
24
+ require 'timeout'
25
+
26
+ puts "----#{@gesture_name}--------------"
27
+ puts '----DO NOT TOUCH YOUR TRACKPAD----'
28
+ sleep 3
29
+
30
+ options = "--enable-tap --verbose --device=/dev/input/#{device_id}"
31
+
32
+ PTY.spawn("#{@debug_events} #{options}") do |r, w, pid|
33
+ w.close_write
34
+ r.sync = true
35
+
36
+ begin
37
+ Timeout.timeout(5) do
38
+ loop { print r.getc }
39
+ end
40
+ rescue Timeout::Error
41
+ puts 'cut out device infos'
42
+ end
43
+
44
+ command = "evemu-play /dev/input/#{device_id} < #{@evemu_record}"
45
+
46
+ begin
47
+ Timeout.timeout(3) do
48
+ Kernel.system(command)
49
+ end
50
+ rescue Timeout::Error
51
+ puts command
52
+ end
53
+
54
+ log = ''
55
+ begin
56
+ Timeout.timeout(5) do
57
+ loop { log += r.getc }
58
+ end
59
+ rescue Timeout::Error
60
+ puts 'cut out device infos'
61
+ end
62
+
63
+ r.close
64
+ puts log
65
+
66
+ file = File.open(filepath, 'w')
67
+ file.puts log
68
+ file.close
69
+
70
+ puts Process.kill(:TERM, pid)
71
+ Process.wait(pid)
72
+ sleep 3
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def mkdir
79
+ dir = "spec/fusuma/plugin/parsers/#{version}"
80
+ FileUtils.mkdir_p(dir)
81
+ end
82
+
83
+ def filepath
84
+ "#{mkdir.first}/#{@gesture_name}"
85
+ end
86
+
87
+ def device_id
88
+ Fusuma::Device.available.first.id
89
+ end
90
+
91
+ def version
92
+ @version ||= `#{@list_devices} --version`.chomp
93
+ end
94
+ end
95
+
96
+ evemu_records = Dir.glob 'spec/fusuma/plugin/parsers/evemu/*'
97
+
98
+ evemu_records.each do |evemu_record|
99
+ LibinputDebugEventsGenerator
100
+ .new(evemu_record: evemu_record)
101
+ .generate_debug_events
102
+ end
@@ -28,11 +28,10 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_dependency 'fusuma', '~> 1.5'
30
30
 
31
+ spec.add_development_dependency 'systemu'
31
32
  spec.add_development_dependency 'bundler'
32
33
  spec.add_development_dependency 'github_changelog_generator', '~> 1.14'
33
- spec.add_development_dependency 'pry-byebug', '~> 3.4'
34
- spec.add_development_dependency 'pry-doc'
35
- spec.add_development_dependency 'pry-inline'
34
+ spec.add_development_dependency 'pry-byebug'
36
35
  spec.add_development_dependency 'rake', '~> 13.0'
37
36
  spec.add_development_dependency 'reek'
38
37
  spec.add_development_dependency 'rspec', '~> 3.0'
@@ -38,9 +38,9 @@ module Fusuma
38
38
 
39
39
  index = create_index(finger: finger, direction: direction)
40
40
 
41
- return create_event(record: Events::Records::IndexRecord.new(index: index)) if enough?(index: index, direction: direction)
41
+ return unless enough?(index: index, direction: direction)
42
42
 
43
- nil
43
+ create_event(record: Events::Records::IndexRecord.new(index: index))
44
44
  end
45
45
 
46
46
  # @return [Config::Index]
@@ -56,7 +56,9 @@ module Fusuma
56
56
  def hold?(buffer, holding_time)
57
57
  return false if holding_time < 1
58
58
 
59
- true if buffer.finger == 4 || buffer.events.any? { |e| e.record.status == 'hold' }
59
+ return true if buffer.finger == 4
60
+
61
+ true if buffer.events.any? { |e| e.record.status == 'hold' }
60
62
  end
61
63
 
62
64
  def tap?(buffer, holding_time)
@@ -55,12 +55,12 @@ module Fusuma
55
55
 
56
56
  case record.to_s
57
57
  # BEGIN
58
- when /\stap state:\s.*TAP_STATE_IDLE → TAP_EVENT_TOUCH → TAP_STATE_TOUCH/
58
+ when /\stap(| state):\s.*TAP_STATE_IDLE → TAP_EVENT_TOUCH → TAP_STATE_TOUCH/
59
59
  status = 'begin'
60
60
  finger = 1
61
61
 
62
62
  # TOUCH
63
- when /\stap state:\s.*(#{STATE[:touches].join('|')}) → TAP_EVENT_TOUCH → (#{STATE[:touches].join('|')})/
63
+ when /\stap(| state):\s.*(#{STATE[:touches].join('|')}) → TAP_EVENT_TOUCH → (#{STATE[:touches].join('|')})/
64
64
 
65
65
  status = 'touch'
66
66
 
@@ -76,7 +76,7 @@ module Fusuma
76
76
  end
77
77
 
78
78
  # HOLD
79
- when /\stap state:\s.*(#{STATE[:touches].join('|')}) → TAP_EVENT_TIMEOUT → (#{STATE[:holds].join('|')})/
79
+ when /\stap(| state):\s.*(#{STATE[:touches].join('|')}) → TAP_EVENT_TIMEOUT → (#{STATE[:holds].join('|')})/
80
80
 
81
81
  status = 'hold'
82
82
 
@@ -93,13 +93,13 @@ module Fusuma
93
93
  1
94
94
  end
95
95
  # KEEP
96
- when /\sgesture state:\s/
97
- # NOTE: treat the "gesture state:" as KEEP
96
+ when /\sgesture(| state):\s/
97
+ # NOTE: treat the "gesture(| state):" as KEEP
98
98
  status = 'keep'
99
99
  finger = 0
100
100
 
101
101
  # RELEASE
102
- when /\stap state:\s.*(#{(STATE[:touches] | STATE[:holds]).join('|')}) → TAP_EVENT_RELEASE → (#{STATE[:releases].join('|')})/
102
+ when /\stap(| state):\s.*(#{(STATE[:touches] | STATE[:holds]).join('|')}) → TAP_EVENT_RELEASE → (#{STATE[:releases].join('|')})/
103
103
 
104
104
  status = 'release'
105
105
  matched = Regexp.last_match
@@ -116,7 +116,7 @@ module Fusuma
116
116
  end
117
117
 
118
118
  # END
119
- when /\stap state:\s.*(#{STATE[:releases].join('|')}) → TAP_EVENT_(.*) → #{STATE[:idle]}/
119
+ when /\stap(| state):\s.*(#{STATE[:releases].join('|')}) → TAP_EVENT_(.*) → #{STATE[:idle]}/
120
120
  status = 'end'
121
121
 
122
122
  matched = Regexp.last_match
@@ -3,7 +3,7 @@
3
3
  module Fusuma
4
4
  module Plugin
5
5
  module Tap
6
- VERSION = '0.1.0'
6
+ VERSION = '0.1.1'
7
7
  end
8
8
  end
9
9
  end
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fusuma/plugin/detectors/detector.rb'
4
+ require 'fusuma/plugin/parsers/parser.rb'
5
+ require 'fusuma/plugin/buffers/buffer.rb'
6
+
3
7
  require_relative './tap/version'
4
8
  require_relative './detectors/tap_detector.rb'
5
9
  require_relative './parsers/tap_parser.rb'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusuma-plugin-tap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - iberianpig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-20 00:00:00.000000000 Z
11
+ date: 2020-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fusuma
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: systemu
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,49 +39,35 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: github_changelog_generator
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.14'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.14'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: pry-byebug
56
+ name: github_changelog_generator
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.4'
61
+ version: '1.14'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.4'
69
- - !ruby/object:Gem::Dependency
70
- name: pry-doc
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
68
+ version: '1.14'
83
69
  - !ruby/object:Gem::Dependency
84
- name: pry-inline
70
+ name: pry-byebug
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ">="
@@ -182,6 +168,8 @@ files:
182
168
  - README.md
183
169
  - Rakefile
184
170
  - bin/console
171
+ - bin/evemu_recorder.rb
172
+ - bin/libinput_debug_events_generator.rb
185
173
  - bin/setup
186
174
  - fusuma-plugin-tap.gemspec
187
175
  - lib/fusuma/plugin/buffers/tap_buffer.rb