fusuma 1.2 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 217ba27576aeda18f673e4519d622d564b5a41c0
4
- data.tar.gz: 985359605435d4a14a9a2fa5e69baf4ce08f874c
2
+ SHA256:
3
+ metadata.gz: f639aca336e61fc9c2a68d32bb31c52964c30eefb9c32ab2caba61dc6f37a9e7
4
+ data.tar.gz: 8055c1d8250c7062f314371129d51adc54f27c4a5f7e18e07452462233047c18
5
5
  SHA512:
6
- metadata.gz: 3ad557b7cd54f0647160280a9945d37c5aa1770b2002fe8bdef8ce9c1932da03584c8931795833e41b892fb1837fcb735b91e0b38bad6dcda911ee0fd8d2bb12
7
- data.tar.gz: b7f9b22cc2e22ff13387cbc6301331ae2e00f6af5ed7da20830a452b7a1eac839f6d0297893a2e400559278ddcbceec4ed71d706579b9561079806659327f45c
6
+ metadata.gz: 40f9f9aae6f9b281c474fbb65e2bb48ef4b1082c9065adbaea06dc51559504f5b652fb8716517a43d827f8b3e02f63961661d592e75fcfdf0d478c1723b9667f
7
+ data.tar.gz: d3ca5a6136544f760e8277e2629838e6903f5028478fd43b647218ee19b1b4fd4a8bb744ce6e5a9b8b708614a7689cf2f6178db77180bab4105b0db55430c457
@@ -1,6 +1,6 @@
1
1
  # These are supported funding model platforms
2
2
 
3
- github: # [iberianpig] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
3
+ github: [iberianpig] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
4
  patreon: iberianpig # Replace with a single Patreon username
5
5
  open_collective: # Replace with a single Open Collective username
6
6
  ko_fi: # Replace with a single Ko-fi username
@@ -13,3 +13,4 @@ Metrics/LineLength:
13
13
  Max: 100
14
14
  Exclude:
15
15
  - "fusuma.gemspec"
16
+ - "**/*_spec.rb"
@@ -37,7 +37,8 @@ module Fusuma
37
37
  print_enabled_plugins
38
38
 
39
39
  print_device_list if option[:list]
40
- Device.given_devices = option[:device]
40
+ # TODO: remove keep_device_from_option from command line options
41
+ Plugin::Filters::LibinputDeviceFilter::KeepDevice.from_option = option[:device]
41
42
  Process.daemon if option[:daemon]
42
43
  end
43
44
 
@@ -28,8 +28,6 @@ module Fusuma
28
28
  end
29
29
 
30
30
  class << self
31
- attr_reader :given_devices
32
-
33
31
  # @return [Array]
34
32
  def all
35
33
  @all ||= fetch_devices
@@ -53,19 +51,6 @@ module Fusuma
53
51
  @available = nil
54
52
  end
55
53
 
56
- # Narrow down available device list
57
- # @param names [String, Array]
58
- def given_devices=(names)
59
- # NOTE: convert to Array
60
- device_names = Array(names)
61
- return if device_names.empty?
62
-
63
- @given_devices = narrow_available_devices(device_names: device_names)
64
- return unless @given_devices.empty?
65
-
66
- exit 1
67
- end
68
-
69
54
  private
70
55
 
71
56
  # @return [Array]
@@ -77,17 +62,6 @@ module Fusuma
77
62
  line_parser.generate_devices
78
63
  end
79
64
 
80
- def narrow_available_devices(device_names:)
81
- device_names.select do |name|
82
- if available.map(&:name).include? name
83
- MultiLogger.info("Touchpad is found: #{name}")
84
- true
85
- else
86
- MultiLogger.warn("Touchpad is not found: #{name}")
87
- end
88
- end
89
- end
90
-
91
65
  # parse line and generate devices
92
66
  class LineParser
93
67
  attr_reader :lines
@@ -6,7 +6,7 @@ module Fusuma
6
6
  module Plugin
7
7
  # filter class
8
8
  module Filters
9
- # Inherite this base
9
+ # Filter record to keep
10
10
  class Filter < Base
11
11
  # Filter input event
12
12
  # @param event [Event]
@@ -24,7 +24,8 @@ module Fusuma
24
24
 
25
25
  # @abstract override `#keep?` to implement
26
26
  # @param record [String]
27
- # @return [True, False]
27
+ # @return [True] when keeping record
28
+ # @return [False] when discarding record
28
29
  def keep?(record)
29
30
  true if record
30
31
  end
@@ -17,23 +17,59 @@ module Fusuma
17
17
  }
18
18
  end
19
19
 
20
+ # @return [TrueClass] when keeping it
21
+ # @return [FalseClass] when discarding it
20
22
  def keep?(record)
21
- keep_device_ids.any? { |device_id| record.to_s =~ /^\s?#{device_id}/ }
22
- end
23
+ # NOTE: purge cache when found new device
24
+ if record.to_s =~ /\sDEVICE_ADDED\s/ && keep_device.match_pattern?(record.to_s)
25
+ keep_device.reset
26
+ return false
27
+ end
23
28
 
24
- private
29
+ keep_device.all.map(&:id).any? { |device_id| record.to_s =~ /^\s?#{device_id}\s/ }
30
+ end
25
31
 
26
- # @return [Array]
27
- def keep_device_ids
28
- @keep_device_ids ||= Device.all.select do |device|
29
- keep_device_names.any? { |name| device.name.match(name) }
30
- end.map(&:id)
32
+ def keep_device
33
+ @keep_device ||= begin
34
+ from_config = Array(config_params(:keep_device_names))
35
+ KeepDevice.new(name_patterns: from_config)
36
+ end
31
37
  end
32
38
 
33
- # @return [Array]
34
- def keep_device_names
35
- Array(config_params(:keep_device_names)).tap do |names|
36
- break Device.all.map(&:name) if names.empty?
39
+ # Select Device to keep
40
+ class KeepDevice
41
+ def initialize(name_patterns:)
42
+ @name_patterns = name_patterns | Array(self.class.from_option)
43
+ end
44
+
45
+ # remove cache for reloading new devices
46
+ def reset
47
+ @all = nil
48
+ Device.reset
49
+ end
50
+
51
+ # @return [Array]
52
+ def all
53
+ @all ||= if @name_patterns.empty?
54
+ Device.available
55
+ else
56
+ Device.all.select do |device|
57
+ match_pattern?(device.name)
58
+ end
59
+ end
60
+ end
61
+
62
+ # @return [TrueClass]
63
+ # @return [FalseClass]
64
+ def match_pattern?(string)
65
+ return true if @name_patterns.empty?
66
+
67
+ @name_patterns.any? { |name_pattern| string.match(name_pattern) }
68
+ end
69
+
70
+ class << self
71
+ # TODO: remove from_option and command line options
72
+ attr_accessor :from_option
37
73
  end
38
74
  end
39
75
  end
@@ -49,7 +49,7 @@ module Fusuma
49
49
  # @yield [line] gives a line in libinput debug-events output to the block
50
50
  def debug_events
51
51
  prefix = 'stdbuf -oL --'
52
- options = [*libinput_options, device_option]
52
+ options = [*libinput_options]
53
53
  cmd = "#{prefix} #{debug_events_command} #{options.join(' ')}".strip
54
54
  MultiLogger.debug(debug_events: cmd)
55
55
  Open3.popen3(cmd) do |_i, o, _e, _w|
@@ -90,14 +90,6 @@ module Fusuma
90
90
 
91
91
  private
92
92
 
93
- # use device option only if libinput detect only 1 device
94
- # @return [String]
95
- def device_option
96
- return unless Device.available.size == 1
97
-
98
- "--device=/dev/input/#{Device.available.first.id}"
99
- end
100
-
101
93
  # TODO: add specs
102
94
  def libinput_options
103
95
  enable_tap = '--enable-tap' if config_params(:'enable-tap')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fusuma
4
- VERSION = '1.2'
4
+ VERSION = '1.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusuma
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - iberianpig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-13 00:00:00.000000000 Z
11
+ date: 2019-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -228,8 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
228
  - !ruby/object:Gem::Version
229
229
  version: '0'
230
230
  requirements: []
231
- rubyforge_project:
232
- rubygems_version: 2.5.1
231
+ rubygems_version: 3.0.3
233
232
  signing_key:
234
233
  specification_version: 4
235
234
  summary: Multitouch gestures with libinput dirver on X11, Linux