Sha256: 17d30c50a2c1aa9337776f201b7863e84a77db672481cd79cda5ab5573f66d56

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

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

module Xkeyrap
  class Command
    attr_accessor :keys
    attr_accessor :modifier_keys
    attr_accessor :output_device
    attr_accessor :config

    def initialize(device, config)
      self.keys = Set.new
      self.modifier_keys = Set.new
      self.output_device = device
      unless config
        self.config = {
          global: {
            KEY_CAPSLOCK: :KEY_LEFTCTRL,
            KEY_LEFTCTRL: :KEY_CAPSLOCK,
            KEY_LEFTALT:  :KEY_LEFTMETA,
            KEY_LEFTMETA: :KEY_LEFTALT
          },
          "Firefox": {
            KEY_LEFTALT: :KEY_LEFTCTRL,
            KEY_CAPSLOCK: :KEY_LEFTMETA,
            KEY_LEFTMETA: :KEY_LEFTALT  
          }
        }
      end
    end

    def receive(state, key, wm_class_name = "global")
      puts "origin: #{wm_class_name} | #{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 "mapped: #{wm_class_name} | #{state} | #{mapped_key}"
      self.output_device.send_event(:EV_KEY, mapped_key, state)
      self.output_device.send_event(:EV_SYN, :SYN_REPORT)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
xkeyrap-0.0.8 lib/xkeyrap/command.rb
xkeyrap-0.0.5 lib/xkeyrap/command.rb
xkeyrap-0.0.4 lib/xkeyrap/command.rb