Module: Vigilem::Evdev::System::KeymapLoaders

Extended by:
Support::Metadata, KeymapLoaders
Included in:
KeymapLoaders
Defined in:
lib/vigilem/evdev/system/keymap_loaders.rb,
lib/vigilem/evdev/system/keymap_loaders/kmap_loader.rb,
lib/vigilem/evdev/system/keymap_loaders/dumpkeys_loader.rb

Overview

the entry point for loading keymaps

Defined Under Namespace

Classes: DumpkeysLoader, KmapLoader

Constant Summary collapse

KeyMap =
Support::KeyMap

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#allArray<KeymapLoader>

Returns:

  • (Array<KeymapLoader>)


22
23
24
# File 'lib/vigilem/evdev/system/keymap_loaders.rb', line 22

def all
  @all ||= []
end

#loaderObject (readonly)

Returns the value of attribute loader.



18
19
20
# File 'lib/vigilem/evdev/system/keymap_loaders.rb', line 18

def loader
  @loader
end

Instance Method Details

#cached?FalseClass || TrueClass

Returns:

  • (FalseClass || TrueClass)


28
29
30
# File 'lib/vigilem/evdev/system/keymap_loaders.rb', line 28

def cached?
  Evdev::KeyMapCache.exists?
end

#execKeyMap

Returns:

Raises:

  • (NotImplementedError)

    ‘Cannot find keymap’



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vigilem/evdev/system/keymap_loaders.rb', line 35

def exec
  attempt ||= 1
  if cached?
    k = KeyMapCache.restore
    @loader = k.[:loader]
    [:cached] = true
  else
        #@todo just gets the first
    if @loader = all.find(&:available?)
      @loader.exec
    else
      raise NotImplementedError, 'Cannot find keymap'
    end
  end
rescue ArgumentError #, 'marshal data too short'
  KeyMapCache.delete
  retry unless (attempts -= 1).zero?
else
  KeyMapCache.dump((mapping = @loader.key_map))
  mapping[:cached] = true
  mapping.left_side_aliases(:keycode, :keycodes)
  mapping.right_side_aliases(:keysym, :keysyms, :char_ref, :char_refs)
  mapping
end

#key_mapKeyMap Also known as: build_cache

returns the default system keymap

Returns:



71
72
73
74
75
76
77
78
# File 'lib/vigilem/evdev/system/keymap_loaders.rb', line 71

def key_map
  set_default
  if loader
    loader.key_map
  else
    exec
  end
end

#set_defaultArray<KeymapLoader>

Returns:

  • (Array<KeymapLoader>)


62
63
64
65
66
67
# File 'lib/vigilem/evdev/system/keymap_loaders.rb', line 62

def set_default
  if not @set
    @set = true
    all.concat([DumpkeysLoader.new, KmapLoader.new])
  end
end