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"
Instance Method Summary collapse
-
#debug_events(writer) ⇒ Integer
: (StringIO) -> Array.
-
#debug_events_command ⇒ Object
: () -> String.
-
#debug_events_with_options ⇒ Object
: () -> String.
-
#initialize(libinput_options: [], commands: {}) ⇒ LibinputCommand
constructor
: (?libinput_options: Array, ?commands: Hash[untyped, untyped]) -> void.
- #libinput_1_27_0_or_later? ⇒ Boolean
-
#list_devices {|gives| ... } ⇒ Object
: () { (String) -> void } -> void.
-
#list_devices_command ⇒ Object
: () -> String.
-
#new_cli_option_available? ⇒ Boolean
: () -> bool.
-
#version ⇒ String
: () -> String?.
-
#version_command ⇒ String
: () -> String?.
Constructor Details
#initialize(libinput_options: [], commands: {}) ⇒ LibinputCommand
: (?libinput_options: Array, ?commands: Hash[untyped, untyped]) -> void
9 10 11 12 13 14 |
# File 'lib/fusuma/libinput_command.rb', line 9 def initialize(libinput_options: [], commands: {}) @libinput_command = commands[:libinput_command] @debug_events_command = commands[:debug_events_command] @list_devices_command = commands[:list_devices_command] = end |
Instance Method Details
#debug_events(writer) ⇒ Integer
: (StringIO) -> Array
57 58 59 |
# File 'lib/fusuma/libinput_command.rb', line 57 def debug_events(writer) Open3.pipeline_start([], ["grep -v POINTER_ --line-buffered"], out: writer, in: "/dev/null") end |
#debug_events_command ⇒ Object
: () -> String
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/fusuma/libinput_command.rb', line 93 def debug_events_command if @libinput_command @libinput_command + " debug-events" elsif @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
: () -> String
106 107 108 109 |
# File 'lib/fusuma/libinput_command.rb', line 106 def prefix = "stdbuf -oL --" "#{prefix} #{debug_events_command} #{@libinput_options.join(" ")}".strip end |
#libinput_1_27_0_or_later? ⇒ Boolean
27 28 29 |
# File 'lib/fusuma/libinput_command.rb', line 27 def libinput_1_27_0_or_later? Gem::Version.new(version) >= Gem::Version.new("1.27.0") end |
#list_devices {|gives| ... } ⇒ Object
: () { (String) -> void } -> void
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fusuma/libinput_command.rb', line 40 def list_devices(&block) cmd = list_devices_command unless @logged_list_devices MultiLogger.debug(list_devices: cmd) @logged_list_devices = true end o, _, s = Open3.capture3(cmd) unless s.success? raise "libinput list-devices failed with output: #{o}" end o.each_line(&block) end |
#list_devices_command ⇒ Object
: () -> String
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fusuma/libinput_command.rb', line 80 def list_devices_command if @libinput_command @libinput_command + " list-devices" elsif @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
: () -> bool
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
: () -> String?
33 34 35 36 |
# File 'lib/fusuma/libinput_command.rb', line 33 def version # version_command prints "1.6.3\n" @version ||= `#{version_command}`.strip end |
#version_command ⇒ String
: () -> String?
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fusuma/libinput_command.rb', line 64 def version_command if @libinput_command "#{@libinput_command} --version" elsif @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 |