Class: Fusuma::Plugin::Remap::DeviceSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/fusuma/plugin/remap/device_selector.rb

Overview

Common device selector for touchpad and keyboard detection Unifies TouchpadSelector implementations across the codebase

Constant Summary collapse

POLL_INTERVAL =

seconds

3

Instance Method Summary collapse

Constructor Details

#initialize(name_patterns: nil, device_type: :touchpad) ⇒ DeviceSelector

Returns a new instance of DeviceSelector.

Parameters:

  • name_patterns (Array, String, nil) (defaults to: nil)

    patterns for device names

  • device_type (Symbol) (defaults to: :touchpad)

    :touchpad or :keyboard (for logging)



16
17
18
19
20
# File 'lib/fusuma/plugin/remap/device_selector.rb', line 16

def initialize(name_patterns: nil, device_type: :touchpad)
  @name_patterns = name_patterns
  @device_type = device_type
  @displayed_waiting = false
end

Instance Method Details

#select(wait: false) ⇒ Array<Revdev::EventDevice>

Select devices that match the name patterns

Parameters:

  • wait (Boolean) (defaults to: false)

    if true, wait until device is found (polling loop)

Returns:



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fusuma/plugin/remap/device_selector.rb', line 25

def select(wait: false)
  loop do
    Fusuma::Device.reset # reset cache to get the latest device information
    devices = find_devices
    return to_event_devices(devices) unless devices.empty?
    return [] unless wait

    log_waiting_message unless @displayed_waiting
    sleep POLL_INTERVAL
  end
end