Class: Fusuma::LibinputCommands

Inherits:
Object
  • Object
show all
Defined in:
lib/fusuma/libinput_commands.rb

Overview

libinput commands wrapper

Constant Summary collapse

NEW_CLI_OPTION_VERSION =

‘libinput-list-devices` and `libinput-debug-events` are deprecated, use `libinput list-devices` and `libinput debug-events` from 1.8.

1.8

Instance Method Summary collapse

Constructor Details

#initialize(*options) ⇒ LibinputCommands

Returns a new instance of LibinputCommands.



4
5
6
# File 'lib/fusuma/libinput_commands.rb', line 4

def initialize(*options)
  @options = options
end

Instance Method Details

#debug_events {|line| ... } ⇒ Object

Yields:

  • (line)

    gives a line in libinput debug-events output to the block



33
34
35
36
37
38
39
40
41
# File 'lib/fusuma/libinput_commands.rb', line 33

def debug_events
  prefix = 'stdbuf -oL --'
  options = [*@options, device_option]
  cmd = "#{prefix} #{debug_events_command} #{options.join(' ')}".strip
  MultiLogger.debug(debug_events: cmd)
  Open3.popen3(cmd) do |_i, o, _e, _w|
    o.each { |line| yield(line) }
  end
end

#debug_events_commandObject



64
65
66
67
68
69
70
# File 'lib/fusuma/libinput_commands.rb', line 64

def debug_events_command
  if new_cli_option_available?
    'libinput debug-events'
  else
    'libinput-debug-events'
  end
end

#list_devices {|line| ... } ⇒ Object

Yields:

  • (line)

    gives a line in libinput list-devices output to the block



24
25
26
27
28
29
30
# File 'lib/fusuma/libinput_commands.rb', line 24

def list_devices
  cmd = list_devices_command
  MultiLogger.debug(debug_events: cmd)
  Open3.popen3(cmd) do |_i, o, _e, _w|
    o.each { |line| yield(line) }
  end
end

#list_devices_commandObject



56
57
58
59
60
61
62
# File 'lib/fusuma/libinput_commands.rb', line 56

def list_devices_command
  if new_cli_option_available?
    'libinput list-devices'
  else
    'libinput-list-devices'
  end
end

#new_cli_option_available?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/fusuma/libinput_commands.rb', line 13

def new_cli_option_available?
  Gem::Version.new(version) >= Gem::Version.new(NEW_CLI_OPTION_VERSION)
end

#versionString

Returns:

  • (String)


18
19
20
21
# File 'lib/fusuma/libinput_commands.rb', line 18

def version
  # versiom_command prints "1.6.3\n"
  @version ||= `#{version_command}`.strip
end

#version_commandString

Returns command.

Returns:

  • (String)

    command

Raises:

  • (SystemExit)


45
46
47
48
49
50
51
52
53
54
# File 'lib/fusuma/libinput_commands.rb', line 45

def version_command
  if which('libinput')
    'libinput --version'
  elsif which('libinput-list-devices')
    'libinput-list-devices --version'
  else
    MultiLogger.error 'install libinput-tools'
    exit 1
  end
end