Class: Fusuma::Plugin::Remap::KeyboardRemapper::KeyboardSelector

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

Overview

Devices to detect key presses and releases

Instance Method Summary collapse

Constructor Details

#initialize(names = ["keyboard", "Keyboard", "KEYBOARD"]) ⇒ KeyboardSelector

Returns a new instance of KeyboardSelector.



312
313
314
# File 'lib/fusuma/plugin/remap/keyboard_remapper.rb', line 312

def initialize(names = ["keyboard", "Keyboard", "KEYBOARD"])
  @names = names
end

Instance Method Details

#selectArray<Revdev::EventDevice>

Select devices that match the name If no device is found, it will wait for 3 seconds and try again

Returns:



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/fusuma/plugin/remap/keyboard_remapper.rb', line 319

def select
  displayed_no_keyboard = false
  loop do
    Fusuma::Device.reset # reset cache to get the latest device information
    devices = Fusuma::Device.all.select { |d| Array(@names).any? { |name| d.name =~ /#{name}/ } }
    if devices.empty?
      unless displayed_no_keyboard
        MultiLogger.warn "No keyboard found: #{@names}"
        displayed_no_keyboard = true
      end
      wait_for_device

      next
    end

    return devices.map { |d| Revdev::EventDevice.new("/dev/input/#{d.id}") }
  end
end

#wait_for_deviceObject



338
339
340
# File 'lib/fusuma/plugin/remap/keyboard_remapper.rb', line 338

def wait_for_device
  sleep 3
end