Sha256: 482db86fffa8fa757e2694e5fee35f87831ac81c87ac7b9d0ff445e6ead8602f

Contents?: true

Size: 1.98 KB

Versions: 8

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

require_relative '../../libinput_command'
require_relative './input'

module Fusuma
  module Plugin
    module Inputs
      # libinput commands wrapper
      class LibinputCommandInput < Input
        attr_reader :pid

        def config_param_types
          {
            device: [String],
            'enable-dwt': [TrueClass, FalseClass],
            'enable-tap': [TrueClass, FalseClass],
            'show-keycodes': [TrueClass, FalseClass],
            verbose: [TrueClass, FalseClass],
            'libinput-debug-events': [String],
            'libinput-list-devices': [String]
          }
        end

        # @return [IO]
        def io
          @io ||= begin
            reader, writer = create_io
            @pid = command.debug_events(writer)
            reader
          end
        end

        # @return [LibinputCommand]
        def command
          @command ||= LibinputCommand.new(
            libinput_options: libinput_options,
            commands: {
              debug_events_command: debug_events_command,
              list_devices_command: list_devices_command
            }
          )
        end

        # @return [Array]
        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')
          verbose = '--verbose' if config_params(:verbose)
          [
            device,
            enable_dwt,
            enable_tap,
            show_keycodes,
            verbose
          ].compact
        end

        def debug_events_command
          config_params(:'libinput-debug-events')
        end

        def list_devices_command
          config_params(:'libinput-list-devices')
        end

        private

        def create_io
          IO.pipe
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fusuma-2.4.1 lib/fusuma/plugin/inputs/libinput_command_input.rb
fusuma-2.4.0 lib/fusuma/plugin/inputs/libinput_command_input.rb
fusuma-2.3.0 lib/fusuma/plugin/inputs/libinput_command_input.rb
fusuma-2.2.0 lib/fusuma/plugin/inputs/libinput_command_input.rb
fusuma-2.1.0 lib/fusuma/plugin/inputs/libinput_command_input.rb
fusuma-2.0.5 lib/fusuma/plugin/inputs/libinput_command_input.rb
fusuma-2.0.4 lib/fusuma/plugin/inputs/libinput_command_input.rb
fusuma-2.0.3 lib/fusuma/plugin/inputs/libinput_command_input.rb