Class: Vigilem::Evdev::VTYContextFilter
- Inherits:
-
Object
- Object
- Vigilem::Evdev::VTYContextFilter
show all
- Includes:
- ContextFilter
- Defined in:
- lib/vigilem/evdev/vty_context_filter.rb
Overview
filters events if the VTY differs from the one of this process
Constant Summary
collapse
- KeyMap =
Support::KeyMap
ContextFilter::States::OFF, ContextFilter::States::ON, ContextFilter::States::UNKNOWN
Instance Attribute Summary collapse
#last_known_state
Class Method Summary
collapse
Instance Method Summary
collapse
included, #on_change, #state_hash, #was_off?, #was_on?
Constructor Details
#initialize(keymap = Evdev.key_map) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 25
def initialize(keymap=Evdev.key_map)
@key_map = keymap unless keymap.eql? Evdev.key_map
@current_console_num = `fgconsole`.rstrip.to_i
curr_con_keys, oth_con_keys =
self.class.console_keys(keymap).partition {|syms,v| v == "Console_#{@current_console_num}" }
@current_console_keys, @other_console_keys = KeyMap[curr_con_keys], KeyMap[oth_con_keys]
@current_console_keys.left_side_aliases(:keycode, :keycodes)
@current_console_keys.right_side_aliases(:keysym, :keysyms)
@other_console_keys.left_side_aliases(:keycode, :keycodes)
@other_console_keys.right_side_aliases(:keysym, :keysyms)
@current_keys = []
end
|
Instance Attribute Details
#console_keys ⇒ Object
19
20
21
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 19
def console_keys
@console_keys
end
|
#current_console_keys ⇒ Object
19
20
21
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 19
def current_console_keys
@current_console_keys
end
|
#current_console_num ⇒ Object
19
20
21
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 19
def current_console_num
@current_console_num
end
|
#other_console_keys ⇒ Object
19
20
21
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 19
def other_console_keys
@other_console_keys
end
|
Class Method Details
.console_keys(keymap) ⇒ KeyMap
45
46
47
48
49
50
51
52
53
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 45
def self.console_keys(keymap)
@console_keys = if keymap.metadata[:loader].class.name =~ /KmapLoader/
keymap.select {|k,v| v =~ /console_\d+/i }
else
console_syms = keymap.info.keysyms.select {|k,v| v =~ /console_\d+/i }
tmp = keymap.select {|k,v| v =~ /^#{console_syms.keys.join('|')}$/ }
tmp.each {|k,v| tmp[k] = console_syms[v] }
end
end
|
Instance Method Details
#add_key(keycode_or_keysym) ⇒ Array
102
103
104
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 102
def add_key(keycode_or_keysym)
current_keys << keycode_or_keysym
end
|
#changed_vty? ⇒ TrueClass || FalseClass
157
158
159
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 157
def changed_vty?
was_off? and other_console_keys.keysym(current_keys_downcase)
end
|
#current_keys ⇒ Array
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 63
def current_keys
if @current_keys and current_keys_changed?
max_and_one = KeyMap.mod_weights.values.max + 1
@current_keys.sort_by! {|ksym| KeyMap.mod_weights[ksym.downcase] || max_and_one }
@current_keys_hash_cache = @current_keys.hash
@current_keys
else
if @current_keys.nil?
@current_keys = []
@current_keys_hash_cache = @current_keys.hash
end
@current_keys
end
end
|
57
58
59
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 57
def key_map
@key_map || Evdev.key_map
end
|
#keysym(keycode) ⇒ String
TODO:
move to KeyMapUtils, or something like that
128
129
130
131
132
133
134
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 128
def keysym(keycode)
if key_map.metadata[:loader].class.name =~ /KmapLoader/
key_map.keysym(keycode)
else
key_map.info.keysyms[key_map.char_ref(keycode)]
end
end
|
#keysym_or_keycode(key_num) ⇒ String
116
117
118
119
120
121
122
123
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 116
def keysym_or_keycode(key_num)
sym = keysym(keycode = "keycode#{key_num}")
if sym =~ /shift|alt|c(on)?tro?l|capsshift/i
sym
else
keycode
end
end
|
#off? ⇒ TrueClass || FalseClass
163
164
165
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 163
def off?
not on?
end
|
#on? ⇒ TrueClass || FalseClass || NilClass
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 138
def on?
if changed_vty?
self.filter_ommisions = current_keys_downcase
on_change(ON)
elsif reverted_vty?
self.filter_ommisions = current_keys_downcase
on_change(OFF)
end
was_on?
end
|
#process(*events) ⇒ Array
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 81
def process(*events)
events.select do |event|
off_status = off?
key_check = if event.type == System::Input::EV_KEY
if event.value == 1
add_key(keysym_or_keycode(event.code))
off_status
elsif event.value == 0
kork = keysym_or_keycode(event.code)
release_status = allow_release?(kork)
remove_key(kork)
release_status
end
end
if key_check.nil? then off_status else key_check end
end
end
|
#remove_key(keycode_or_keysym) ⇒ Object
109
110
111
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 109
def remove_key(keycode_or_keysym)
current_keys.delete(keycode_or_keysym)
end
|
#reverted_vty? ⇒ TrueClass || FalseClass
151
152
153
|
# File 'lib/vigilem/evdev/vty_context_filter.rb', line 151
def reverted_vty?
was_on? and current_console_keys.keysym(current_keys_downcase)
end
|