Class: Fusuma::LibinputCommand
- Inherits:
-
Object
- Object
- Fusuma::LibinputCommand
- Defined in:
- lib/fusuma/libinput_command.rb
Overview
Execute libinput command
Constant Summary collapse
- NEW_CLI_OPTION_VERSION =
libinput-list-devicesandlibinput-debug-eventsare deprecated, use ‘libinput list-devices` and `libinput debug-events` from 1.8. 1.8- DEFAULT_WAIT_TIME =
0.3
- TIMEOUT_MESSAGE =
'LIBINPUT TIMEOUT'
Instance Method Summary collapse
-
#debug_events ⇒ Integer, IO
Return a latest line libinput debug-events.
- #debug_events_command ⇒ Object
- #debug_events_with_options ⇒ Object
-
#initialize(libinput_options: [], commands: {}) ⇒ LibinputCommand
constructor
A new instance of LibinputCommand.
- #list_devices {|gives| ... } ⇒ Object
- #list_devices_command ⇒ Object
- #new_cli_option_available? ⇒ Boolean
- #version ⇒ String
-
#version_command ⇒ String
Command.
Constructor Details
#initialize(libinput_options: [], commands: {}) ⇒ LibinputCommand
Returns a new instance of LibinputCommand.
8 9 10 11 12 |
# File 'lib/fusuma/libinput_command.rb', line 8 def initialize(libinput_options: [], commands: {}) @debug_events_command = commands[:debug_events_command] @list_devices_command = commands[:list_devices_command] = end |
Instance Method Details
#debug_events ⇒ Integer, IO
Return a latest line libinput debug-events
45 46 47 48 49 50 51 |
# File 'lib/fusuma/libinput_command.rb', line 45 def debug_events @debug_events = begin p, i, o, _e = POSIX::Spawn.popen4() i.close [p, o] end end |
#debug_events_command ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/fusuma/libinput_command.rb', line 78 def debug_events_command if @debug_events_command @debug_events_command elsif new_cli_option_available? 'libinput debug-events' else 'libinput-debug-events' end end |
#debug_events_with_options ⇒ Object
88 89 90 91 |
# File 'lib/fusuma/libinput_command.rb', line 88 def prefix = 'stdbuf -oL --' "#{prefix} #{debug_events_command} #{@libinput_options.join(' ')}".strip end |
#list_devices {|gives| ... } ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fusuma/libinput_command.rb', line 33 def list_devices(&block) cmd = list_devices_command MultiLogger.debug(list_devices: cmd) p, i, o, e = POSIX::Spawn.popen4(cmd) i.close o.each(&block) ensure [i, o, e].each { |io| io.close unless io.closed? } Process.waitpid(p) end |
#list_devices_command ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/fusuma/libinput_command.rb', line 68 def list_devices_command if @list_devices_command @list_devices_command elsif new_cli_option_available? 'libinput list-devices' else 'libinput-list-devices' end end |
#new_cli_option_available? ⇒ Boolean
22 23 24 |
# File 'lib/fusuma/libinput_command.rb', line 22 def new_cli_option_available? Gem::Version.new(version) >= Gem::Version.new(NEW_CLI_OPTION_VERSION) end |
#version ⇒ String
27 28 29 30 |
# File 'lib/fusuma/libinput_command.rb', line 27 def version # versiom_command prints "1.6.3\n" @version ||= `#{version_command}`.strip end |
#version_command ⇒ String
Returns command.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fusuma/libinput_command.rb', line 55 def version_command if @debug_events_command && @list_devices_command "#{@list_devices_command} --version" elsif which('libinput') 'libinput --version' elsif which('libinput-list-devices') 'libinput-list-devices --version' else MultiLogger.error 'Please install libinput-tools' exit 1 end end |