Class: Vigilem::Evdev::System::KeymapLoaders::DumpkeysLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/vigilem/evdev/system/keymap_loaders/dumpkeys_loader.rb

Overview

this takes longer than keymap_loader, but is more thorough

Constant Summary collapse

KeyMap =
Support::KeyMap

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#key_mapKeyMap

Returns:



38
39
40
# File 'lib/vigilem/evdev/system/keymap_loaders/dumpkeys_loader.rb', line 38

def key_map
  @key_map ||= exec
end

Class Method Details

.available?FalseClass || TrueClass

Returns:

  • (FalseClass || TrueClass)


57
58
59
# File 'lib/vigilem/evdev/system/keymap_loaders/dumpkeys_loader.rb', line 57

def available?
  tty and command
end

.commandString || NilClass

Returns the command path, otherwise returns nil if there isn’t one

Returns:

  • (String || NilClass)

    returns the command path, otherwise returns nil if there isn’t one



64
65
66
67
68
69
70
71
72
# File 'lib/vigilem/evdev/system/keymap_loaders/dumpkeys_loader.rb', line 64

def command
  if not @checked_for_command
    str = `which dumpkeys`.chomp
    @checked_for_command = true
    @command = str.empty? ? nil : str
  else
    @command
  end
end

.run_dumpkeys(*dumpkeys_args) ⇒ String || nil

needs sudo on xserver loads dumpkeys string from system command

Parameters:

  • *dumpkeys_args (Array)

Returns:

  • (String || nil)

Raises:

  • command not run?



86
87
88
89
90
91
# File 'lib/vigilem/evdev/system/keymap_loaders/dumpkeys_loader.rb', line 86

def run_dumpkeys(*dumpkeys_args)
  if tty and command
    args = dumpkeys_args.empty? ? '' : "-#{dumpkeys_args.join}"
    `#{command} #{args} < #{tty}`
  end
end

.ttyString || nil

as long as it’s sudo does this matter?

Returns:

  • (String || nil)


76
77
78
79
# File 'lib/vigilem/evdev/system/keymap_loaders/dumpkeys_loader.rb', line 76

def tty
  @tty_command ||= `which tty`.chomp
  @tty ||= `#{@tty_command}` if @tty_command
end

Instance Method Details

#available?TrueClass || FalseClass

Returns:

  • (TrueClass || FalseClass)


50
51
52
# File 'lib/vigilem/evdev/system/keymap_loaders/dumpkeys_loader.rb', line 50

def available?
  self.class.available?
end

#exec(args = '') ⇒ KeyMap Also known as: key_map!

Parameters:

  • args (String) (defaults to: '')

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vigilem/evdev/system/keymap_loaders/dumpkeys_loader.rb', line 20

def exec(args='')
  @key_map = if self.class.available?
        if args =~ /\s+/
          raise ArgumentError, "Argument: `#{args}' invalid"
        else
          k = KeyMap.load_string(self.class.run_dumpkeys("fn#{args}"))
          k.[:loader] = self
          k
        end
      end
  key_map_info
  @key_map
end

#key_map_infoKeyMapInfo

Returns:

  • (KeyMapInfo)


44
45
46
# File 'lib/vigilem/evdev/system/keymap_loaders/dumpkeys_loader.rb', line 44

def key_map_info
  key_map.info ||= key_map.info(self.class.run_dumpkeys('l'))
end