Class: Vigilem::Evdev::InputSystemHandler

Inherits:
Object
  • Object
show all
Includes:
Core::Eventable, Core::InputSystemHandler
Defined in:
lib/vigilem/evdev/input_system_handler.rb

Overview

Handles input from Evdev InputSystem

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*devices) ⇒ Object

Parameters:

  • devices (Array)


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vigilem/evdev/input_system_handler.rb', line 20

def initialize(*devices)
  self.class.lazy_require
  initialize_input_system_handler
  
  self.context_filters.concat([VTYContextFilter.new, FocusContextFilter.new_if_installed].compact)
  
  @transfer_agent = Evdev::TransferAgent.acquire(:inputs => devices, :outputs => {self.buffer => {:func => :concat}})
  
  @source = @transfer_agent
  
  @link = self.buffer
end

Class Method Details

.lazy_requireTrueClass || FalseClass

Returns:

  • (TrueClass || FalseClass)


35
36
37
38
39
40
41
42
43
44
# File 'lib/vigilem/evdev/input_system_handler.rb', line 35

def self.lazy_require
  unless @loaded
    require 'vigilem/evdev/at_exit'
    require 'vigilem/evdev/vty_context_filter'
    require 'vigilem/evdev/focus_context_filter'
    require 'vigilem/evdev/transfer_agent'
    @loaded = true
  end
  @loaded
end

Instance Method Details

#context_filtersArray

Returns:

  • (Array)


48
49
50
# File 'lib/vigilem/evdev/input_system_handler.rb', line 48

def context_filters
  @context_filters ||= []
end

#read_many_nonblock(max_number_of_events = 1) ⇒ Array<InputEvent>

Parameters:

  • num, (Integer)

    defaults to 1

Returns:

  • (Array<InputEvent>)


55
56
57
58
59
60
61
62
# File 'lib/vigilem/evdev/input_system_handler.rb', line 55

def read_many_nonblock(max_number_of_events=1)
  synchronize {
    raise ArgumentError, "max_number_of_events cannot be <= than 0:`#{max_number_of_events}'" if max_number_of_events.to_i <= 0
    transfer_agent.relay(max_number_of_events) if buffer.empty?
    events = buffer.shift(max_number_of_events)
    context_filters.reduce(events) {|memo, ctx| ctx.process(*memo) }
  }
end