Class: Vigilem::Evdev::FocusContextFilter

Inherits:
Object
  • Object
show all
Includes:
ContextFilter
Defined in:
lib/vigilem/evdev/focus_context_filter.rb

Overview

allows input_events through when the window has focus

Constant Summary

Constants included from ContextFilter::States

ContextFilter::States::OFF, ContextFilter::States::ON, ContextFilter::States::UNKNOWN

Instance Attribute Summary collapse

Attributes included from ContextFilter

#last_known_state

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContextFilter

included, #on_change, #state_hash, #was_off?, #was_on?

Constructor Details

#initialize(display = self.class.env_display, xwindow_id = nil) ⇒ FocusContextFilter

Returns a new instance of FocusContextFilter.

Parameters:

  • (String)
  • (Integer || NilClass)


59
60
61
62
63
64
# File 'lib/vigilem/evdev/focus_context_filter.rb', line 59

def initialize(display=self.class.env_display, xwindow_id=nil)
  self.class.lazy_require
  window_xid = xwindow_id || X11::TerminalWindowUtils.window_id
  
  @input_system_handler = X11::InputSystemHandler.new(window_xid, display, Xlib::FocusChangeMask)
end

Instance Attribute Details

#input_system_handlerObject

Returns the value of attribute input_system_handler.



52
53
54
# File 'lib/vigilem/evdev/focus_context_filter.rb', line 52

def input_system_handler
  @input_system_handler
end

Class Method Details

.env_displayString || NilClass

Returns:

  • (String || NilClass)


19
20
21
# File 'lib/vigilem/evdev/focus_context_filter.rb', line 19

def env_display
  ENV['DISPLAY']
end

.lazy_requireObject



25
26
27
28
# File 'lib/vigilem/evdev/focus_context_filter.rb', line 25

def lazy_require
  require 'vigilem/x11/terminal_window_utils'
  require 'vigilem/x11/input_system_handler'
end

.new_if_installed(display = env_display, xwindow_id = nil) ⇒ NilClass || self

Parameters:

  • display (String) (defaults to: env_display)
  • xwindow_id (Integer ||NilClass) (defaults to: nil)
  • (FocusContextFilter || NilClass)

Returns:

  • (NilClass || self)


35
36
37
38
39
# File 'lib/vigilem/evdev/focus_context_filter.rb', line 35

def new_if_installed(display=env_display, xwindow_id=nil)
  if X11::Stat.default.installed?
    new(display, xwindow_id)
  end
end

.new_if_installed!(display = env_display, xwindow_id = nil) ⇒ NilClass || self

Parameters:

  • display (String) (defaults to: env_display)
  • xwindow_id (Integer || NilClass) (defaults to: nil)

Returns:

  • (NilClass || self)

Raises:

  • (RuntimeError)


46
47
48
# File 'lib/vigilem/evdev/focus_context_filter.rb', line 46

def new_if_installed!(display=env_display, xwindow_id=nil)
  new_if_installed(display, xwindow_id) || raise('InputSystem unavailable')
end

Instance Method Details

#gained_focus?TrueClass || FalseClass

Returns:

  • (TrueClass || FalseClass)


95
96
97
# File 'lib/vigilem/evdev/focus_context_filter.rb', line 95

def gained_focus?
  (not had_focus?) and has_focus?
end

#has_focus?TrueClass || FalseClass

Returns:

  • (TrueClass || FalseClass)


68
69
70
71
72
# File 'lib/vigilem/evdev/focus_context_filter.rb', line 68

def has_focus?
  with_focus = X11.get_input_focus(self.display, window_xid)[1]
  with_focus == self.window_xid or
    self.window_xid == X11.query_tree(self.display, with_focus)[:parent_return]
end

#lost_focus?TrueClass || FalseClass

Returns:

  • (TrueClass || FalseClass)


101
102
103
# File 'lib/vigilem/evdev/focus_context_filter.rb', line 101

def lost_focus?
  had_focus? and not has_focus?
end

#off?TrueClass || FalseClass

Returns:

  • (TrueClass || FalseClass)


89
90
91
# File 'lib/vigilem/evdev/focus_context_filter.rb', line 89

def off?
  not on?
end

#on?TrueClass || FalseClass

Returns:

  • (TrueClass || FalseClass)


78
79
80
81
82
83
84
85
# File 'lib/vigilem/evdev/focus_context_filter.rb', line 78

def on?
  if gained_focus?
    on_change(OFF)
  elsif lost_focus?
    on_change(ON)
  end
  was_on?
end

#process(*events) ⇒ Array

Parameters:

  • events (Array)

Returns:

  • (Array)


108
109
110
111
112
113
114
# File 'lib/vigilem/evdev/focus_context_filter.rb', line 108

def process(*events)
  if on?
    []
  else
    events
  end
end