Sha256: b731c5155001ec16c19a82841efdd9c87d97387b74b8eaa14d918c3c369b7632

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

module Fusuma
  # detect input device
  class Device
    class << self
      attr_writer :names

      def names
        return @names unless @names.nil?
        device_names = fetch_device_names
        MultiLogger.debug(device_names: device_names)
        raise 'Touchpad is not found' if device_names.empty?
        @names = device_names
      rescue => ex
        MultiLogger.error(ex.message)
        exit 1
      end

      private

      def fetch_device_names
        current_device = nil
        list_devices_logs.map do |line|
          current_device = extracted_input_device_from(line) || current_device
          next unless natural_scroll_is_available?(line)
          current_device
        end.compact
      end

      def list_devices_logs
        Open3.popen3('libinput-list-devices') do |_i, o, _e, _w|
          return o.to_a
        end
      end

      def extracted_input_device_from(line)
        return unless line =~ /^Kernel: /
        line.match(/event[0-9]+/).to_s
      end

      def natural_scroll_is_available?(line)
        return false unless line =~ /^Nat.scrolling: /
        return false if line =~ %r{n/a}
        true
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fusuma-0.5.0 lib/fusuma/device.rb
fusuma-0.4.1 lib/fusuma/device.rb
fusuma-0.4.0 lib/fusuma/device.rb
fusuma-0.3.7 lib/fusuma/device.rb
fusuma-0.3.5 lib/fusuma/device.rb