Class: Xkbcommon::Keymap::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/xkbcommon/keymap/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keymap) ⇒ Parser

Returns a new instance of Parser.



4
5
6
# File 'lib/xkbcommon/keymap/parser.rb', line 4

def initialize(keymap)
  @keymap = keymap
end

Instance Attribute Details

#keymapObject (readonly)

Returns the value of attribute keymap.



8
9
10
# File 'lib/xkbcommon/keymap/parser.rb', line 8

def keymap
  @keymap
end

Instance Method Details

#charactersObject



45
46
47
48
# File 'lib/xkbcommon/keymap/parser.rb', line 45

def characters
  symbols # will be parsed while parsing symbols
  @characters
end

#keysObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/xkbcommon/keymap/parser.rb', line 10

def keys
  @keys ||= begin
    min_code = Libxkbcommon.xkb_keymap_min_keycode(@keymap.to_native)
    max_code = Libxkbcommon.xkb_keymap_max_keycode(@keymap.to_native)
    keycode_range = min_code..max_code

    codes = keycode_range.select do |code|
      # Todo: This does not seem to filter out keys that do not exist on the keyboard?
      0 < Libxkbcommon.xkb_keymap_num_layouts_for_key(@keymap.to_native, code)
    end
    codes.map{ |code| Key.new(self, code) }
  end
end

#modifiersObject



24
25
26
27
# File 'lib/xkbcommon/keymap/parser.rb', line 24

def modifiers
  symbols # will be parsed while parsing symbols
  @modifiers
end

#symbolsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/xkbcommon/keymap/parser.rb', line 29

def symbols
  @symbols ||= begin
    symbols = parse_symbols
    # first parse round will give us all modifier keys, so we can parse
    # what keys active which modifiers next

    @modifiers = parse_modifiers(symbols)

    all_combinations(@modifiers).each do |modifiers|
      symbols = parse_symbols(symbols, modifiers)
    end

    symbols
  end
end