Class: Fusuma::Plugin::Remap::KeyboardRemapper::KeyboardSelector
- Inherits:
-
Object
- Object
- Fusuma::Plugin::Remap::KeyboardRemapper::KeyboardSelector
- Defined in:
- lib/fusuma/plugin/remap/keyboard_remapper.rb
Overview
Devices to detect key presses and releases
Instance Method Summary collapse
-
#initialize(names = ["keyboard", "Keyboard", "KEYBOARD"]) ⇒ KeyboardSelector
constructor
A new instance of KeyboardSelector.
-
#select ⇒ Array<Revdev::EventDevice>
Select devices that match the name If no device is found, it will wait for 3 seconds and try again.
- #wait_for_device ⇒ Object
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
#select ⇒ Array<Revdev::EventDevice>
Select devices that match the name If no device is found, it will wait for 3 seconds and try again
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_device ⇒ Object
338 339 340 |
# File 'lib/fusuma/plugin/remap/keyboard_remapper.rb', line 338 def wait_for_device sleep 3 end |