fusuma-plugin-keypress 0.5.0 → 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: e4dee24a10fad696ea3f6fd58e02e1c2358f522455bc9ec4aef6bc53b2004d2c
4
- data.tar.gz: 3e0016a1d55bc7cb4096c9a77916fa1910e8a81561992255c97b17a8a67d6ddf
3
+ metadata.gz: d551f984dfdbac5d6095387156cf211450a23e45701737713cc5c5be261081d2
4
+ data.tar.gz: e3446a313462ad562e0dd4eabb112c1e3d39735523315c0e34f90c51b12ad655
5
5
  SHA512:
6
- metadata.gz: 22187a3a208c1d0989eac56c565cf00124920bb141d38f3549743c473c0b42708256c73d6c7603c6776f245a46c3ae6df8f791ba4e51f9c09de47f529b8b008b
7
- data.tar.gz: e7f937130567f31bb3b226b3cb502f98fff973aceb21a68813170fa77d0ea80e1e531c5fabf1e0c57e56c463072ed14a1f3e9f28fc5201eca69610cdfea56f5b
6
+ metadata.gz: 69a1272b0938d590b72d8b94fcab0d37fdb6af71111e936e1e817a8acffca0c05a9907795027e796d081731a605b719e8999125d0124cb657996d95379340dd8
7
+ data.tar.gz: 7e26101b157dd1fcef0d061c3666a9c23402434667054a98e829f9969f8f1391e3c8c108d49220a7e8b9433b831b6507a4b543cbdb5a5c4b1334b456621292ea
data/README.md CHANGED
@@ -81,29 +81,6 @@ plugin:
81
81
  * Swipe up/down with four fingers while keypress LEFTMETA and LEFTALT keys to change audio volume.
82
82
  - If you want to combine a gesture with two keys, combine modifier keys with `+`
83
83
 
84
-
85
- ## Typing Gesture
86
-
87
- `typing:` is a trigger that fires when keys other than modifier keys are pressed. This trigger provides disable-while-typing similar to libinput and syndaemon.
88
- If you are using a keyremapper such as xkeysnail and libinput's disable-while-typing does not work, try setting it.
89
-
90
- It can be placed in the root of yaml and configured as a gesture.
91
- The following is a configuration that uses xinput to turn off tapping for 0.6 seconds to avoid false touches.
92
-
93
- ```yaml
94
- typing: # disable while typing
95
- command: |
96
- touchpad_id=$(xinput | grep Touchpad | grep -oE "id=[0-9]*" | cut -d"=" -f 2)
97
- xinput set-prop $touchpad_id "libinput Tapping Enabled" 0
98
- file=/tmp/typing_command_break
99
- touch "$file"
100
- sleep 0.6
101
- [ `find "$file" -mmin +0.01` ] && \
102
- xinput set-prop $touchpad_id "libinput Tapping Enabled" 1
103
- interval: 0.5
104
- ```
105
-
106
-
107
84
  ## Contributing
108
85
 
109
86
  Bug reports and pull requests are welcome on GitHub at https://github.com/iberianpig/fusuma-plugin-keypress. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -1,31 +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"
28
27
  spec.metadata = {
29
- 'rubygems_mfa_required' => 'true'
28
+ "rubygems_mfa_required" => "true"
30
29
  }
31
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,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
3
+ require "set"
4
4
 
5
5
  module Fusuma
6
6
  module Plugin
@@ -8,19 +8,19 @@ module Fusuma
8
8
  # Detect KeypressEvent from KeypressBuffer
9
9
  class KeypressDetector < Detector
10
10
  SOURCES = %w[keypress].freeze
11
- BUFFER_TYPE = 'keypress'
11
+ BUFFER_TYPE = "keypress"
12
12
 
13
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
- ])
14
+ CAPSLOCK
15
+ LEFTALT
16
+ LEFTCTRL
17
+ LEFTMETA
18
+ LEFTSHIFT
19
+ RIGHTALT
20
+ RIGHTCTRL
21
+ RIGHTSHIFT
22
+ RIGHTMETA
23
+ ])
24
24
 
25
25
  # Always watch buffers and detect them.
26
26
  def watch?
@@ -37,14 +37,12 @@ module Fusuma
37
37
 
38
38
  codes = pressed_codes(keypress_buffer.events.map(&:record))
39
39
 
40
- return if codes.empty?
40
+ return unless codes.any? { |code| MODIFIER_KEYS.include?(code) }
41
41
 
42
- record = if codes.any? { |code| MODIFIER_KEYS.include?(code) }
43
- Events::Records::IndexRecord.new(index: create_index(codes: codes),
44
- position: :surfix)
45
- else
46
- Events::Records::IndexRecord.new(index: create_typing_index)
47
- end
42
+ record = Events::Records::IndexRecord.new(
43
+ index: create_index(codes: codes),
44
+ position: :surfix
45
+ )
48
46
 
49
47
  create_event(record: record)
50
48
  end
@@ -58,7 +56,7 @@ module Fusuma
58
56
  def pressed_codes(records)
59
57
  codes = []
60
58
  records.each do |r|
61
- if r.status == 'pressed'
59
+ if r.status == "pressed"
62
60
  codes << r.code
63
61
  else
64
62
  codes.delete_if { |code| code == r.code }
@@ -72,18 +70,8 @@ module Fusuma
72
70
  def create_index(codes:)
73
71
  Config::Index.new(
74
72
  [
75
- Config::Index::Key.new('keypress', skippable: true),
76
- Config::Index::Key.new(codes.join('+'), skippable: true)
77
- ]
78
- )
79
- end
80
-
81
- # @param status [String]
82
- # @return [Config::Index]
83
- def create_typing_index
84
- Config::Index.new(
85
- [
86
- Config::Index::Key.new('typing')
73
+ Config::Index::Key.new("keypress", skippable: true),
74
+ Config::Index::Key.new(codes.join("+"), skippable: true)
87
75
  ]
88
76
  )
89
77
  end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fusuma/device'
3
+ require "fusuma/device"
4
4
 
5
5
  module Fusuma
6
6
  module Plugin
7
7
  module Filters
8
8
  # Filter keyboard events from libinput_command_input
9
9
  class KeypressFilter < Filter
10
- DEFAULT_SOURCE = 'libinput_command_input'
10
+ DEFAULT_SOURCE = "libinput_command_input"
11
11
 
12
12
  def config_param_types
13
13
  {
@@ -3,7 +3,7 @@
3
3
  module Fusuma
4
4
  module Plugin
5
5
  module Keypress
6
- VERSION = '0.5.0'
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,7 +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'
8
+ DEFAULT_SOURCE = "libinput_command_input"
9
9
 
10
10
  # @param record [String]
11
11
  # @return [Records::Gesture, nil]
@@ -24,7 +24,7 @@ module Fusuma
24
24
  when /KEYBOARD_KEY.+(\d+\.\d+)s.*KEY_([A-Z]+).*(pressed|released)/
25
25
  matched = Regexp.last_match
26
26
  # time = matched[1] # 4.81
27
- code = matched[2] # LEFTSHIFT
27
+ code = matched[2] # LEFTSHIFT
28
28
  status = matched[3] # pressed
29
29
 
30
30
  Events::Records::KeypressRecord.new(status: status, code: code)
@@ -32,7 +32,7 @@ module Fusuma
32
32
  end
33
33
 
34
34
  def tag
35
- 'keypress_parser'
35
+ "keypress_parser"
36
36
  end
37
37
  end
38
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.5.0
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-11-24 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,11 +43,6 @@ 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/filters/keypress_filter_spec.rb
48
- - spec/fusuma/plugin/keypress_spec.rb
49
- - spec/helpers/config_helper.rb
50
- - spec/spec_helper.rb
51
46
  homepage: https://github.com/iberianpig/fusuma-plugin-keypress
52
47
  licenses:
53
48
  - MIT
@@ -68,13 +63,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
63
  - !ruby/object:Gem::Version
69
64
  version: '0'
70
65
  requirements: []
71
- rubygems_version: 3.0.3.1
66
+ rubygems_version: 3.3.26
72
67
  signing_key:
73
68
  specification_version: 4
74
69
  summary: Keypress plugin for Fusuma
75
- test_files:
76
- - spec/spec_helper.rb
77
- - spec/helpers/config_helper.rb
78
- - spec/fusuma/plugin/filters/keypress_filter_spec.rb
79
- - spec/fusuma/plugin/keypress_spec.rb
80
- - spec/fusuma/plugin/detectors/keypress_detector_spec.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,131 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- require 'fusuma/plugin/filters/filter'
6
- require 'fusuma/plugin/inputs/input'
7
-
8
- require './lib/fusuma/plugin/filters/keypress_filter'
9
-
10
- module Fusuma
11
- module Plugin
12
- module Filters
13
- RSpec.describe KeypressFilter do
14
- describe '#keep?' do
15
- before { @filter = KeypressFilter.new }
16
- context 'with keyboard event' do
17
- before do
18
- keyboard = double(Fusuma::Device, id: 'event4')
19
- allow(@filter).to receive(:keep_devices).and_return([keyboard])
20
- text = " #{keyboard.id} KEYBOARD_KEY +4.81s KEY_LEFTSHIFT (42) pressed"
21
- @event = Events::Event.new(tag: 'libinput_command_input', record: text)
22
- # @filter = KeypressFilter.new
23
- end
24
- it 'should be true' do
25
- expect(@filter.keep?(@event.record)).to eq true
26
- end
27
- end
28
- context 'with multiple keyboards' do
29
- before do
30
- keyboard1 = double(Fusuma::Device, id: 'event1')
31
- keyboard2 = double(Fusuma::Device, id: 'event2')
32
- allow(@filter).to receive(:keep_devices).and_return([
33
- keyboard1, keyboard2
34
- ])
35
- text1 = " #{keyboard1.id} KEYBOARD_KEY +4.81s KEY_LEFTSHIFT (42) pressed"
36
- text2 = " #{keyboard2.id} KEYBOARD_KEY +4.81s KEY_LEFTSHIFT (42) pressed"
37
- @event1 = Events::Event.new(tag: 'libinput_command_input', record: text1)
38
- @event2 = Events::Event.new(tag: 'libinput_command_input', record: text2)
39
- end
40
- it 'should return multiple keyboards' do
41
- expect(@filter.keep?(@event1.record)).to eq true
42
- expect(@filter.keep?(@event2.record)).to eq true
43
- end
44
- end
45
- context 'when touchpad events' do
46
- before do
47
- touchpad = double(Fusuma::Device, id: 'event18')
48
- allow(@filter).to receive(:keep_devices).and_return([touchpad])
49
- text = " #{touchpad.id} GESTURE_SWIPE_UPDATE +1.44s 4 11.23/ 1.00 (36.91/ 3.28 unaccelerated) "
50
- # ^^^^^^^^^^^^^^^^^^^^ Shoud be KEYBOARD_KEY
51
- @event = Events::Event.new(tag: 'libinput_command_input', record: text)
52
- end
53
- it 'should be false' do
54
- expect(@filter.keep?(@event.record)).to eq false
55
- end
56
- end
57
-
58
- context 'with plugins.filters.keypress_filter.source=CUSTOM_INPUT' do
59
- it { expect(@filter.source).to eq 'libinput_command_input' }
60
-
61
- context 'with config' do
62
- around do |example|
63
- @custom_source = 'CUSTOM_INPUT'
64
-
65
- ConfigHelper.load_config_yml = <<~CONFIG
66
- plugin:
67
- filters:
68
- keypress_filter:
69
- source: #{@custom_source}
70
- CONFIG
71
-
72
- example.run
73
-
74
- Config.custom_path = nil
75
- end
76
-
77
- it { expect(@filter.source).to eq @custom_source }
78
- end
79
- end
80
- context "with config file having plugins.filters.keypress.keep_device_names='CUSTOM_KEYBOARD'" do
81
- it { expect(@filter.source).to eq 'libinput_command_input' }
82
-
83
- context 'with config' do
84
- around do |example|
85
- @name = 'CUSTOM_KEYBOARD'
86
-
87
- ConfigHelper.load_config_yml = <<~CONFIG
88
- plugin:
89
- filters:
90
- keypress_filter:
91
- keep_device_names: #{@name}
92
- CONFIG
93
-
94
- example.run
95
-
96
- Config.custom_path = nil
97
- end
98
-
99
- it { expect(@filter.config_params[:keep_device_names]).to eq @name }
100
- end
101
- end
102
- context "with config file having plugins.filters.keypress.keep_device_names=['INTERNAL_KEYBOARD','EXTERNAL_KEYBOARD']" do
103
- it { expect(@filter.source).to eq 'libinput_command_input' }
104
-
105
- context 'with config' do
106
- around do |example|
107
- @name1 = 'INTERNAL_KEYBOARD'
108
- @name2 = 'EXTERNAL_KEYBOARD'
109
-
110
- ConfigHelper.load_config_yml = <<~CONFIG
111
- plugin:
112
- filters:
113
- keypress_filter:
114
- keep_device_names:
115
- - #{@name1}
116
- - #{@name2}
117
- CONFIG
118
-
119
- example.run
120
-
121
- Config.custom_path = nil
122
- end
123
-
124
- it { expect(@filter.config_params(:keep_device_names)).to eq [@name1, @name2] }
125
- end
126
- end
127
- end
128
- end
129
- end
130
- end
131
- 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