Class: Fusuma::Plugin::Buffers::TapBuffer
- Inherits:
-
Buffer
- Object
- Buffer
- Fusuma::Plugin::Buffers::TapBuffer
- Defined in:
- lib/fusuma/plugin/buffers/tap_buffer.rb
Overview
manage events and generate command
Constant Summary collapse
- DEFAULT_SOURCE =
'libinput_tap_parser'
- DEFAULT_SECONDS_TO_KEEP =
0.1
Instance Method Summary collapse
- #begin?(event) ⇒ Boolean
- #buffer(event) ⇒ NilClass, TapBuffer
- #bufferable?(event) ⇒ Boolean
-
#clear_expired ⇒ Object
clear old events.
- #config_param_types ⇒ Object
- #empty? ⇒ Boolean
- #ended?(event) ⇒ Boolean
-
#finger ⇒ Object
return [Integer].
- #present? ⇒ Boolean
- #select_by_events ⇒ Object
Instance Method Details
#begin?(event) ⇒ Boolean
79 80 81 |
# File 'lib/fusuma/plugin/buffers/tap_buffer.rb', line 79 def begin?(event) event.record.status == 'begin' end |
#buffer(event) ⇒ NilClass, TapBuffer
24 25 26 27 28 29 30 31 32 |
# File 'lib/fusuma/plugin/buffers/tap_buffer.rb', line 24 def buffer(event) return unless event&.tag == source # NOTE: need to set `begin` event at first of buffer clear && return unless bufferable?(event) @events.push(event) self end |
#bufferable?(event) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fusuma/plugin/buffers/tap_buffer.rb', line 43 def bufferable?(event) case event.record.status when 'end' true when 'begin' if empty? true else false end when 'keep', 'touch', 'hold', 'release', 'move' if empty? false else true end else raise "Unexpected status: #{event.record.status}" end end |
#clear_expired ⇒ Object
clear old events
18 19 20 |
# File 'lib/fusuma/plugin/buffers/tap_buffer.rb', line 18 def clear_expired(*) clear if @events.any? { |e| ended?(e) } end |
#config_param_types ⇒ Object
11 12 13 14 15 |
# File 'lib/fusuma/plugin/buffers/tap_buffer.rb', line 11 def config_param_types { 'source': [String] } end |
#empty? ⇒ Boolean
39 40 41 |
# File 'lib/fusuma/plugin/buffers/tap_buffer.rb', line 39 def empty? @events.empty? end |
#ended?(event) ⇒ Boolean
75 76 77 |
# File 'lib/fusuma/plugin/buffers/tap_buffer.rb', line 75 def ended?(event) event.record.status == 'end' end |
#finger ⇒ Object
return [Integer]
35 36 37 |
# File 'lib/fusuma/plugin/buffers/tap_buffer.rb', line 35 def finger @events.map { |e| e.record.finger }.max end |
#present? ⇒ Boolean
64 65 66 |
# File 'lib/fusuma/plugin/buffers/tap_buffer.rb', line 64 def present? !empty? end |
#select_by_events ⇒ Object
68 69 70 71 72 73 |
# File 'lib/fusuma/plugin/buffers/tap_buffer.rb', line 68 def select_by_events return enum_for(:select) unless block_given? events = @events.select { |event| yield event } self.class.new events end |