fusuma-plugin-keypress 0.4.2 → 0.6.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: 958f90d65b6a5bfe120a5462bbfc1d21e01dbdf95d97f279e824a6ad6aafa5a3
4
- data.tar.gz: 6d8c96cb5be6b003f00c0d20bc6bf68af693857e82d9ceb87837a1b752678e0f
3
+ metadata.gz: d551f984dfdbac5d6095387156cf211450a23e45701737713cc5c5be261081d2
4
+ data.tar.gz: e3446a313462ad562e0dd4eabb112c1e3d39735523315c0e34f90c51b12ad655
5
5
  SHA512:
6
- metadata.gz: 7be790c59d66696f078c89121f32f9dd61630a0debfe3584899cac8b0ed73d335b2858aca88e7d84b511dcb1cbaf9a0e36ac487300c519f2c5480ac7f16a4040
7
- data.tar.gz: 858e05f1aca03e80be587ed315e79717a5c6815336c5b1ef8e1c112603df698be6d3b720853c18f2b200137b8c9eb866907e325032c8727ee6d1ffba368bc07e
6
+ metadata.gz: 69a1272b0938d590b72d8b94fcab0d37fdb6af71111e936e1e817a8acffca0c05a9907795027e796d081731a605b719e8999125d0124cb657996d95379340dd8
7
+ data.tar.gz: 7e26101b157dd1fcef0d061c3666a9c23402434667054a98e829f9969f8f1391e3c8c108d49220a7e8b9433b831b6507a4b543cbdb5a5c4b1334b456621292ea
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Fusuma::Plugin::Keypress [![Gem Version](https://badge.fury.io/rb/fusuma-plugin-keypress.svg)](https://badge.fury.io/rb/fusuma-plugin-keypress) [![Build Status](https://travis-ci.com/iberianpig/fusuma-plugin-keypress.svg?branch=master)](https://travis-ci.com/iberianpig/fusuma-plugin-keypress)
1
+ # Fusuma::Plugin::Keypress [![Gem Version](https://badge.fury.io/rb/fusuma-plugin-keypress.svg)](https://badge.fury.io/rb/fusuma-plugin-keypress) [![Build Status](https://github.com/iberianpig/fusuma-plugin-keypress/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/iberianpig/fusuma-plugin-keypress/actions/workflows/ubuntu.yml)
2
2
 
3
3
 
4
4
  Keyboard + Touchpad combination plugin for [Fusuma](https://github.com/iberianpig/fusuma)
@@ -33,6 +33,7 @@ plugin:
33
33
 
34
34
  ## Properties
35
35
 
36
+ ### Keypress
36
37
  Add `keypress:` property in `~/.config/fusuma/config.yml`.
37
38
 
38
39
  Keys following are available for `keypress`.
@@ -1,28 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('lib', __dir__)
3
+ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'fusuma/plugin/keypress/version'
5
+ require "fusuma/plugin/keypress/version"
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = 'fusuma-plugin-keypress'
9
- spec.version = Fusuma::Plugin::Keypress::VERSION
10
- spec.authors = ['iberianpig']
11
- spec.email = ['yhkyky@gmail.com']
8
+ spec.name = "fusuma-plugin-keypress"
9
+ spec.version = Fusuma::Plugin::Keypress::VERSION
10
+ spec.authors = ["iberianpig"]
11
+ spec.email = ["yhkyky@gmail.com"]
12
12
 
13
- spec.summary = 'Keypress plugin for Fusuma '
14
- spec.description = 'fusuma-plugin-keypress is Fusuma plugin for keypress combination.'
15
- spec.homepage = 'https://github.com/iberianpig/fusuma-plugin-keypress'
16
- spec.license = 'MIT'
13
+ spec.summary = "Keypress plugin for Fusuma "
14
+ spec.description = "fusuma-plugin-keypress is Fusuma plugin for keypress combination."
15
+ spec.homepage = "https://github.com/iberianpig/fusuma-plugin-keypress"
16
+ spec.license = "MIT"
17
17
 
18
18
  # Specify which files should be added to the gem when it is released.
19
- spec.files = Dir['{bin,lib,exe}/**/*', 'LICENSE*', 'README*', '*.gemspec']
20
- spec.test_files = Dir['{test,spec,features}/**/*']
21
- spec.bindir = 'exe'
22
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
- spec.require_paths = ['lib']
19
+ spec.files = Dir["{bin,lib,exe}/**/*", "LICENSE*", "README*", "*.gemspec"]
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
24
23
 
25
- spec.required_ruby_version = '>= 2.5.1' # https://packages.ubuntu.com/search?keywords=ruby&searchon=names&exact=1&suite=all&section=main
24
+ spec.required_ruby_version = ">= 2.5.1" # https://packages.ubuntu.com/search?keywords=ruby&searchon=names&exact=1&suite=all&section=main
26
25
  # support bionic (18.04LTS) 2.5.1
27
- spec.add_dependency 'fusuma', '~> 2.0'
26
+ spec.add_dependency "fusuma", "~> 2.0"
27
+ spec.metadata = {
28
+ "rubygems_mfa_required" => "true"
29
+ }
28
30
  end
@@ -5,7 +5,7 @@ module Fusuma
5
5
  module Buffers
6
6
  # Buffer events having KeypressRecord
7
7
  class KeypressBuffer < Buffer
8
- DEFAULT_SOURCE = 'keypress_parser'
8
+ DEFAULT_SOURCE = "keypress_parser"
9
9
 
10
10
  # @param event [Event]
11
11
  def buffer(event)
@@ -30,7 +30,7 @@ module Fusuma
30
30
  private
31
31
 
32
32
  def released?
33
- true if @events.last.record.status =~ /released/
33
+ true if /released/.match?(@events.last.record.status)
34
34
  end
35
35
  end
36
36
  end
@@ -1,12 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "set"
4
+
3
5
  module Fusuma
4
6
  module Plugin
5
7
  module Detectors
6
8
  # Detect KeypressEvent from KeypressBuffer
7
9
  class KeypressDetector < Detector
8
- SOURCES = ['keypress'].freeze
9
- BUFFER_TYPE = 'keypress'
10
+ SOURCES = %w[keypress].freeze
11
+ BUFFER_TYPE = "keypress"
12
+
13
+ MODIFIER_KEYS = Set.new(%w[
14
+ CAPSLOCK
15
+ LEFTALT
16
+ LEFTCTRL
17
+ LEFTMETA
18
+ LEFTSHIFT
19
+ RIGHTALT
20
+ RIGHTCTRL
21
+ RIGHTSHIFT
22
+ RIGHTMETA
23
+ ])
10
24
 
11
25
  # Always watch buffers and detect them.
12
26
  def watch?
@@ -17,28 +31,47 @@ module Fusuma
17
31
  # @return [Event] if event is detected
18
32
  # @return [NilClass] if event is NOT detected
19
33
  def detect(buffers)
20
- buffer = buffers.find { |b| b.type == BUFFER_TYPE }
34
+ keypress_buffer = find_buffer(buffers)
21
35
 
22
- return if buffer.empty?
36
+ return if keypress_buffer.empty?
23
37
 
24
- records = buffer.events.select { |e| e.record.status == 'pressed' }.map(&:record)
38
+ codes = pressed_codes(keypress_buffer.events.map(&:record))
25
39
 
26
- index_record = Events::Records::IndexRecord.new(
27
- index: create_index(records: records),
40
+ return unless codes.any? { |code| MODIFIER_KEYS.include?(code) }
41
+
42
+ record = Events::Records::IndexRecord.new(
43
+ index: create_index(codes: codes),
28
44
  position: :surfix
29
45
  )
30
46
 
31
- create_event(record: index_record)
47
+ create_event(record: record)
48
+ end
49
+
50
+ private
51
+
52
+ def find_buffer(buffers)
53
+ buffers.find { |b| b.type == BUFFER_TYPE }
54
+ end
55
+
56
+ def pressed_codes(records)
57
+ codes = []
58
+ records.each do |r|
59
+ if r.status == "pressed"
60
+ codes << r.code
61
+ else
62
+ codes.delete_if { |code| code == r.code }
63
+ end
64
+ end
65
+ codes
32
66
  end
33
67
 
34
- # @param records [Array<Events::Records::KeypressRecord>]
68
+ # @param code [String]
35
69
  # @return [Config::Index]
36
- def create_index(records:)
37
- code = records.map(&:code).join('+')
70
+ def create_index(codes:)
38
71
  Config::Index.new(
39
72
  [
40
- Config::Index::Key.new('keypress', skippable: true),
41
- Config::Index::Key.new(code, skippable: true)
73
+ Config::Index::Key.new("keypress", skippable: true),
74
+ Config::Index::Key.new(codes.join("+"), skippable: true)
42
75
  ]
43
76
  )
44
77
  end
@@ -12,6 +12,7 @@ module Fusuma
12
12
  def initialize(status:, code:)
13
13
  @status = status
14
14
  @code = code
15
+ super()
15
16
  end
16
17
  end
17
18
  end
@@ -1,16 +1,62 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "fusuma/device"
4
+
3
5
  module Fusuma
4
6
  module Plugin
5
7
  module Filters
6
8
  # Filter keyboard events from libinput_command_input
7
9
  class KeypressFilter < Filter
8
- DEFAULT_SOURCE = 'libinput_command_input'
10
+ DEFAULT_SOURCE = "libinput_command_input"
11
+
12
+ def config_param_types
13
+ {
14
+ source: String,
15
+ keep_device_names: [Array, String]
16
+ }
17
+ end
18
+
19
+ # NOTE: example of line# Select keyboard devices for filtering devices pressed/released
20
+ # event4 KEYBOARD_KEY +4.81s KEY_LEFTSHIFT (42) pressed
21
+ # event4 KEYBOARD_KEY +4.90s KEY_LEFTSHIFT (42) released
22
+ # event4 KEYBOARD_KEY +7.39s KEY_CAPSLOCK (58) pressed
23
+ # event4 KEYBOARD_KEY +7.52s KEY_CAPSLOCK (58) released
24
+ # event4 KEYBOARD_KEY +8.98s KEY_LEFTCTRL (29) pressed
25
+ # event4 KEYBOARD_KEY +9.14s KEY_LEFTCTRL (29) released
9
26
 
10
27
  # @return [TrueClass] when keeping it
11
28
  # @return [FalseClass] when discarding it
12
29
  def keep?(record)
13
- record.to_s =~ /\sKEYBOARD_KEY\s/
30
+ keep_devices.any? do |d|
31
+ record.to_s =~ /#{d.id}\s+KEYBOARD_KEY\s/
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ # @return [Array<Fusuma::Device>]
38
+ def keep_devices
39
+ @keep_devices ||= KeepDevice.new(config_params(:keep_device_names)).select
40
+ end
41
+
42
+ # Devices to detect key presses and releases
43
+ class KeepDevice
44
+ def initialize(names)
45
+ @names = names
46
+ end
47
+
48
+ # @return [Array<Fusuma::Device>]
49
+ def select
50
+ if @names
51
+ Fusuma::Device.all.select do |d|
52
+ Array(config_params(:keep_device_names)).any? do |name|
53
+ d.name =~ name
54
+ end
55
+ end
56
+ else
57
+ Fusuma::Device.all.select { |d| d.capabilities =~ /keyboard/ }
58
+ end
59
+ end
14
60
  end
15
61
  end
16
62
  end
@@ -3,7 +3,7 @@
3
3
  module Fusuma
4
4
  module Plugin
5
5
  module Keypress
6
- VERSION = '0.4.2'
6
+ VERSION = "0.6.1"
7
7
  end
8
8
  end
9
9
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  # fusuma will `require fusuma-plugin-xxxx/plugin/xxxx.rb`
4
4
 
5
- require_relative './keypress/version'
6
- require_relative './events/records/keypress_record'
7
- require_relative './filters/keypress_filter'
8
- require_relative './parsers/keypress_parser'
9
- require_relative './buffers/keypress_buffer'
10
- require_relative './detectors/keypress_detector'
5
+ require_relative "./keypress/version"
6
+ require_relative "./events/records/keypress_record"
7
+ require_relative "./filters/keypress_filter"
8
+ require_relative "./parsers/keypress_parser"
9
+ require_relative "./buffers/keypress_buffer"
10
+ require_relative "./detectors/keypress_detector"
@@ -5,19 +5,7 @@ module Fusuma
5
5
  module Parsers
6
6
  # Generate KeypressRecord from libinput_command_input
7
7
  class KeypressParser < Parser
8
- DEFAULT_SOURCE = 'libinput_command_input'
9
-
10
- AVAILABLE_KEYS = %w[
11
- CAPSLOCK
12
- LEFTALT
13
- LEFTCTRL
14
- LEFTMETA
15
- LEFTSHIFT
16
- RIGHTALT
17
- RIGHTCTRL
18
- RIGHTSHIFT
19
- RIGHTMETA
20
- ].freeze
8
+ DEFAULT_SOURCE = "libinput_command_input"
21
9
 
22
10
  # @param record [String]
23
11
  # @return [Records::Gesture, nil]
@@ -36,17 +24,15 @@ module Fusuma
36
24
  when /KEYBOARD_KEY.+(\d+\.\d+)s.*KEY_([A-Z]+).*(pressed|released)/
37
25
  matched = Regexp.last_match
38
26
  # time = matched[1] # 4.81
39
- code = matched[2] # LEFTSHIFT
27
+ code = matched[2] # LEFTSHIFT
40
28
  status = matched[3] # pressed
41
29
 
42
- return unless AVAILABLE_KEYS.include?(code)
43
-
44
30
  Events::Records::KeypressRecord.new(status: status, code: code)
45
31
  end
46
32
  end
47
33
 
48
34
  def tag
49
- 'keypress_parser'
35
+ "keypress_parser"
50
36
  end
51
37
  end
52
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusuma-plugin-keypress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - iberianpig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-03 00:00:00.000000000 Z
11
+ date: 2022-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fusuma
@@ -43,14 +43,11 @@ files:
43
43
  - lib/fusuma/plugin/keypress.rb
44
44
  - lib/fusuma/plugin/keypress/version.rb
45
45
  - lib/fusuma/plugin/parsers/keypress_parser.rb
46
- - spec/fusuma/plugin/detectors/keypress_detector_spec.rb
47
- - spec/fusuma/plugin/keypress_spec.rb
48
- - spec/helpers/config_helper.rb
49
- - spec/spec_helper.rb
50
46
  homepage: https://github.com/iberianpig/fusuma-plugin-keypress
51
47
  licenses:
52
48
  - MIT
53
- metadata: {}
49
+ metadata:
50
+ rubygems_mfa_required: 'true'
54
51
  post_install_message:
55
52
  rdoc_options: []
56
53
  require_paths:
@@ -66,12 +63,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
63
  - !ruby/object:Gem::Version
67
64
  version: '0'
68
65
  requirements: []
69
- rubygems_version: 3.1.4
66
+ rubygems_version: 3.3.26
70
67
  signing_key:
71
68
  specification_version: 4
72
69
  summary: Keypress plugin for Fusuma
73
- test_files:
74
- - spec/fusuma/plugin/detectors/keypress_detector_spec.rb
75
- - spec/fusuma/plugin/keypress_spec.rb
76
- - spec/helpers/config_helper.rb
77
- - spec/spec_helper.rb
70
+ test_files: []
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- require 'fusuma/plugin/detectors/detector'
6
- require 'fusuma/plugin/buffers/buffer'
7
-
8
- require './lib/fusuma/plugin/buffers/keypress_buffer'
9
- require './lib/fusuma/plugin/detectors/keypress_detector'
10
-
11
- module Fusuma
12
- module Plugin
13
- module Detectors
14
- RSpec.describe KeypressDetector do
15
- before do
16
- @detector = KeypressDetector.new
17
- @buffer = Buffers::KeypressBuffer.new
18
- end
19
-
20
- describe '#detector' do
21
- context 'with no keypress event in buffer' do
22
- before do
23
- @buffer.clear
24
- end
25
-
26
- it { expect(@detector.detect([@buffer])).to eq nil }
27
- end
28
- end
29
-
30
- context 'with keypress events in buffer' do
31
- before do
32
- record = Events::Records::KeypressRecord.new(status: 'pressed', code: 'LEFTSHIFT')
33
- event = Events::Event.new(tag: 'keypress_parser', record: record)
34
-
35
- @buffer.buffer(event)
36
- end
37
- it { expect(@detector.detect([@buffer])).to be_a Events::Event }
38
- it { expect(@detector.detect([@buffer]).record).to be_a Events::Records::IndexRecord }
39
- it { expect(@detector.detect([@buffer]).record.index).to be_a Config::Index }
40
-
41
- it 'should detect LEFTSHIFT' do
42
- expect(@detector.detect([@buffer]).record.index.keys.map(&:symbol))
43
- .to eq(%i[keypress LEFTSHIFT])
44
- end
45
- end
46
-
47
- context 'with two different keypress events in buffer' do
48
- before do
49
- record1 = Events::Records::KeypressRecord.new(status: 'pressed', code: 'LEFTSHIFT')
50
- record2 = Events::Records::KeypressRecord.new(status: 'pressed', code: 'LEFTCTRL')
51
- event1 = Events::Event.new(tag: 'keypress_parser', record: record1)
52
- event2 = Events::Event.new(tag: 'keypress_parser', record: record2)
53
-
54
- @buffer.buffer(event1)
55
- @buffer.buffer(event2)
56
- end
57
-
58
- it 'should detect LEFTSHIFT+LEFTCTRL' do
59
- expect(@detector.detect([@buffer]).record.index.keys.map(&:symbol))
60
- .to eq(%i[keypress LEFTSHIFT+LEFTCTRL])
61
- end
62
- end
63
- end
64
- end
65
- end
66
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Fusuma::Plugin::Keypress do
6
- it 'has a version number' do
7
- expect(Fusuma::Plugin::Keypress::VERSION).not_to be nil
8
- end
9
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'tempfile'
4
- require 'fusuma/config'
5
-
6
- module Fusuma
7
- module ConfigHelper
8
- module_function
9
-
10
- def load_config_yml=(string)
11
- Config.custom_path = Tempfile.open do |temp_file|
12
- temp_file.tap { |f| f.write(string) }
13
- end
14
- end
15
- end
16
- end
data/spec/spec_helper.rb DELETED
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/setup'
4
- require 'helpers/config_helper'
5
-
6
- RSpec.configure do |config|
7
- # Enable flags like --only-failures and --next-failure
8
- config.example_status_persistence_file_path = '.rspec_status'
9
-
10
- # Disable RSpec exposing methods globally on `Module` and `main`
11
- config.disable_monkey_patching!
12
-
13
- config.expect_with :rspec do |c|
14
- c.syntax = :expect
15
- end
16
-
17
- config.include(Fusuma::ConfigHelper)
18
- end