Class: Fusuma::Plugin::Inputs::LibinputCommandInput
- Inherits:
-
Input
- Object
- Base
- Input
- Fusuma::Plugin::Inputs::LibinputCommandInput
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_types ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 11
def config_param_types
{
'device': [String],
'enable-dwt': [TrueClass, FalseClass],
'enable-tap': [TrueClass, FalseClass],
'show-keycodes': [TrueClass, FalseClass]
}
end
|
#debug_events {|line| ... } ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 51
def debug_events
prefix = 'stdbuf -oL --'
options = [*libinput_options]
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_command ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 84
def debug_events_command
if new_cli_option_available?
'libinput debug-events'
else
'libinput-debug-events'
end
end
|
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 92
def libinput_options
device = ("--device='#{config_params(:device)}'" if config_params(:device))
enable_tap = '--enable-tap' if config_params(:'enable-tap')
enable_dwt = '--enable-dwt' if config_params(:'enable-dwt')
show_keycodes = '--show-keycodes' if config_params(:'show-keycodes')
[
device,
enable_dwt,
enable_tap,
show_keycodes
].compact
end
|
#list_devices {|line| ... } ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 42
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_command ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 76
def list_devices_command
if new_cli_option_available?
'libinput list-devices'
else
'libinput-list-devices'
end
end
|
#new_cli_option_available? ⇒ Boolean
31
32
33
|
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 31
def new_cli_option_available?
Gem::Version.new(version) >= Gem::Version.new(NEW_CLI_OPTION_VERSION)
end
|
#run ⇒ Object
20
21
22
23
24
|
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 20
def run
debug_events do |line|
yield event(record: line)
end
end
|
36
37
38
39
|
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 36
def version
@version ||= `#{version_command}`.strip
end
|
#version_command ⇒ String
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/fusuma/plugin/inputs/libinput_command_input.rb', line 65
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
|