Class: Xkbcommon::State
- Inherits:
-
Object
- Object
- Xkbcommon::State
- Defined in:
- lib/xkbcommon/state.rb
Instance Attribute Summary collapse
-
#keymap ⇒ Object
readonly
Returns the value of attribute keymap.
-
#to_native ⇒ Object
readonly
Returns the value of attribute to_native.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(keymap) ⇒ State
constructor
A new instance of State.
- #modifier_active?(modifier) ⇒ Boolean
- #press_key(key) ⇒ Object
- #press_keys(keys) ⇒ Object
- #release_key(key) ⇒ Object
- #release_keys(keys) ⇒ Object
- #symbol_for_key(key) ⇒ Object
- #update_mask(depressed_mods: 0, latched_mods: 0, locked_mods: 0, depressed_layout: 0, latched_layout: 0, locked_layout: 0) ⇒ Object
- #utf8_of_key(key) ⇒ Object
Constructor Details
#initialize(keymap) ⇒ State
Returns a new instance of State.
9 10 11 12 13 14 |
# File 'lib/xkbcommon/state.rb', line 9 def initialize(keymap) @keymap = keymap @to_native = Libxkbcommon.xkb_state_new(keymap.to_native) ObjectSpace.define_finalizer(self, self.class.finalize(to_native)) end |
Instance Attribute Details
#keymap ⇒ Object (readonly)
Returns the value of attribute keymap.
16 17 18 |
# File 'lib/xkbcommon/state.rb', line 16 def keymap @keymap end |
#to_native ⇒ Object (readonly)
Returns the value of attribute to_native.
16 17 18 |
# File 'lib/xkbcommon/state.rb', line 16 def to_native @to_native end |
Class Method Details
.finalize(native) ⇒ Object
4 5 6 |
# File 'lib/xkbcommon/state.rb', line 4 def finalize(native) Proc.new { Libxkbcommon.xkb_state_unref(native) } end |
Instance Method Details
#modifier_active?(modifier) ⇒ Boolean
56 57 58 |
# File 'lib/xkbcommon/state.rb', line 56 def modifier_active?(modifier) 0 < Libxkbcommon.xkb_state_mod_index_is_active(to_native, modifier.index, Libxkbcommon::XKB_STATE_MODS_EFFECTIVE) end |
#press_key(key) ⇒ Object
28 29 30 |
# File 'lib/xkbcommon/state.rb', line 28 def press_key(key) Libxkbcommon.xkb_state_update_key(to_native, key.code, Libxkbcommon::XKB_KEY_DOWN) end |
#press_keys(keys) ⇒ Object
32 33 34 |
# File 'lib/xkbcommon/state.rb', line 32 def press_keys(keys) [*keys].map{ |key| press_key(key) }.last end |
#release_key(key) ⇒ Object
36 37 38 |
# File 'lib/xkbcommon/state.rb', line 36 def release_key(key) Libxkbcommon.xkb_state_update_key(to_native, key.code, Libxkbcommon::XKB_KEY_UP) end |
#release_keys(keys) ⇒ Object
40 41 42 |
# File 'lib/xkbcommon/state.rb', line 40 def release_keys(keys) [*keys].map{ |key| release_key(key) }.last end |
#symbol_for_key(key) ⇒ Object
51 52 53 54 |
# File 'lib/xkbcommon/state.rb', line 51 def symbol_for_key(key) keysym = Libxkbcommon.xkb_state_key_get_one_sym(to_native, key.code) Symbol.new(@keymap, keysym) if keysym end |
#update_mask(depressed_mods: 0, latched_mods: 0, locked_mods: 0, depressed_layout: 0, latched_layout: 0, locked_layout: 0) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/xkbcommon/state.rb', line 18 def update_mask(depressed_mods: 0, latched_mods: 0, locked_mods: 0, depressed_layout: 0, latched_layout: 0, locked_layout: 0) Libxkbcommon.xkb_state_update_mask(to_native, depressed_mods, latched_mods, locked_mods, depressed_layout, latched_layout, locked_layout) end |
#utf8_of_key(key) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/xkbcommon/state.rb', line 44 def utf8_of_key(key) utf8_size = 8 utf8 = FFI::MemoryPointer.new(:char, utf8_size) Libxkbcommon.xkb_state_key_get_utf8(to_native, key.code, utf8, utf8_size) utf8.read_string.force_encoding('UTF-8') end |