Class: Fusuma::Plugin::Inputs::LibinputCommandInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fusuma/plugin/inputs/libinput_command_input.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

Methods inherited from Input

#event, #tag

Methods inherited from Base

#config_index, #config_params, inherited, plugins

Instance Method Details

#config_param_typesObject



11
12
13
14
15
16
17
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 11

def config_param_types
  {
    'enable-tap': [TrueClass, FalseClass],
    'enable-dwt': [TrueClass, FalseClass],
    'device': [String]
  }
end

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

Yields:

  • (line)

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



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 50

def debug_events
  prefix = 'stdbuf -oL --'
  options = [*libinput_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 do |line|
      yield(line.chomp)
    end
  end
end

#debug_events_commandObject



83
84
85
86
87
88
89
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 83

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



41
42
43
44
45
46
47
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 41

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

#list_devices_commandObject



75
76
77
78
79
80
81
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 75

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

#new_cli_option_available?Boolean



30
31
32
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 30

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

#runObject



19
20
21
22
23
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 19

def run
  debug_events do |line|
    yield event(record: line)
  end
end

#versionString



35
36
37
38
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 35

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

#version_commandString

Returns command.

Raises:

  • (SystemExit)


64
65
66
67
68
69
70
71
72
73
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 64

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