Sha256: 8037abcdb77d9fba76ee1c77f2f4708f82ce52ef44eaa2c21a4f9516e95adb6e

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require "evdev"
require 'libevdev'
require 'uinput/device'
require 'json'

module Xkeyrap
  class Command
    attr_accessor :output_device
    attr_accessor :config

    def initialize(device, config_file)
      self.config = default_config.merge(JSON.parse(config_file)) rescue default_config
      self.output_device = device
    end

    def receive(state, key, wm_class_name = "global")
      key = key.to_sym
      puts "input: #{state} ... #{key}"
      sub_json = self.config[wm_class_name.to_sym] || self.config[:global]
      mapped_key = sub_json[key] || self.config[:global][key] || key
      puts "output: #{state} ... #{mapped_key}"
      self.output_device.send_event(:EV_KEY, mapped_key.to_sym, state)
      self.output_device.send_event(:EV_SYN, :SYN_REPORT)
    end

    def default_config
      {
        global: {
          KEY_CAPSLOCK: :KEY_LEFTCTRL,
          KEY_LEFTCTRL: :KEY_CAPSLOCK,
          KEY_LEFTALT:  :KEY_LEFTMETA,
          KEY_LEFTMETA: :KEY_LEFTALT
        }
      }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xkeyrap-0.0.2 lib/xkeyrap/command.rb