class Vigilem::X11::EventQueue

Attributes

display[R]

Public Class Methods

acquire(display_obj_pointer_or_name) click to toggle source

finds an existing EventQueue with the given display or returns a new one based on the items passed in @param [Display || FFI::Pointer || String]

display_obj_pointer_or_name

@return [EventQueue]

# File lib/vigilem/x11/event_queue.rb, line 39
def acquire(display_obj_pointer_or_name)
  dip = Display.wrap(display_obj_pointer_or_name)
  eventq = all.find {|evq| evq.fileno == dip.fileno }
  
  eventq || new(dip)
end
new(display_obj_pointer_or_name) click to toggle source

@param [String || Display || ::FFI::Pointer]

display_pointer_or_name
Calls superclass method
# File lib/vigilem/x11/event_queue.rb, line 27
def new(display_obj_pointer_or_name)
  ret = obj_register(super(display_obj_pointer_or_name))
  same_display_check!
  ret
end
new(display_obj_pointer_or_name) click to toggle source

@param [String || Display || ::FFI::Pointer]

display_pointer_or_name
# File lib/vigilem/x11/event_queue.rb, line 67
def initialize(display_obj_pointer_or_name)
  @display = Display.wrap(display_obj_pointer_or_name)
end
same_display_check() click to toggle source

@return [Array]

# File lib/vigilem/x11/event_queue.rb, line 48
def same_display_check
  all.group_by {|ev| ev.display.fileno }.select {|k, v| v.size > 1 }
end
same_display_check!(err_type=ArgumentError) click to toggle source

@param [StandardError] err_type, defaults to ArgumentError @raise “EventQueues should not have the same display `#{array of event queues with same display}'” @return [NilClass]

# File lib/vigilem/x11/event_queue.rb, line 56
def same_display_check!(err_type=ArgumentError)
  unless (dups = same_display_check).empty?
    raise err_type, "EventQueues should not have the same display `#{dups}'"
  end
end

Public Instance Methods

concat(*args) click to toggle source

@raise [NotImplemented]

# File lib/vigilem/x11/event_queue.rb, line 125
def concat(*args)
  raise NotImplementedError
end
display!() click to toggle source

@raise [ArgumentError] @return

# File lib/vigilem/x11/event_queue.rb, line 101
def display!
  # a way to validate the pointer to prevent segfault?
  if display.is_a?(::FFI::Pointer) or display.respond_to?(:to_ptr)
    display
  else
    raise ArgumentError, "Display is a `#{display.inspect}'" + 
                        "and doesn't respond to :to_ptr"
  end
end
fileno() click to toggle source

@return [Fixnum]

# File lib/vigilem/x11/event_queue.rb, line 94
def fileno
  @fileno ||= display.fileno
end
next_event() click to toggle source

@return [Xlib::XEvent]

# File lib/vigilem/x11/event_queue.rb, line 86
def next_event
  x_event = Xlib::XEvent.new
  Xlib.XNextEvent(display!, x_event)
  x_event
end
peek() click to toggle source

@raise [NotImplemented]

# File lib/vigilem/x11/event_queue.rb, line 131
def peek
  raise NotImplementedError
  # @todo
  #if _internal_buffer.size > 0
  #  _internal_buffer[0]
  #else
  #  if pending! > 0
  #    next_event
  #  end
  #end
end
pending() click to toggle source

the XPending and items pulled from the queue that haven't propagated @return [Fixnum]

# File lib/vigilem/x11/event_queue.rb, line 74
def pending
  pending! + _internal_buffer.size
end
pending!() click to toggle source

only the number of events returned by XPending @return [Fixnum]

# File lib/vigilem/x11/event_queue.rb, line 80
def pending!
  Xlib.XPending(display!)
end
slice!(start_idx_range, len=nil) click to toggle source

@param [Integer || Range] start_idx_range @param [Integer] len @return [Array]

# File lib/vigilem/x11/event_queue.rb, line 115
def slice!(start_idx_range, len=nil)
  # this isn;t the most efficient way, but is the
  # most straight forward
  pending!.times.map do
    next_event
  end.compact.slice!(start_idx_range, *len)
end

Private Instance Methods

_internal_buffer() click to toggle source

@return [Array]

# File lib/vigilem/x11/event_queue.rb, line 146
def _internal_buffer
  @internal_buffer ||= []
end