xkeyrap 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc2fe8eb39aa1e50cf8d7ad39e3823ff4b45f1eea0be50a2b5c7f755d54c5162
4
- data.tar.gz: 36c2677e59b9044b89f7531cebeea83a9fbaf3af8c10cd29a70f1c5549d06eca
3
+ metadata.gz: 42dd7731a5793052a73353b312fc26967590df30eddc805859eac4ec6e1e4553
4
+ data.tar.gz: 884417d5725d2fb0b8b6335dbdcefebf24b3b7e2235f28a8050042daa7636652
5
5
  SHA512:
6
- metadata.gz: '086a216bb4c9b12225cf5168b86b83726655e4abab7b6cba8a4e05a07c65b5c406da959708cf3730f20a6e66fe481d4e209d22dd3df543d57d57fa4fd1535dcc'
7
- data.tar.gz: 2c4666c41b40c1ff0aa427c9f9b249eeeeb00d7b6b8ac014235ecf2cbfd399cf964d9197ddd7ff6f37acf4daa9f39c42b0c44144a0f506a1da1c0274ef488f5e
6
+ metadata.gz: 7e87fbfa4dd4934c72d501e05948b1a6bf4825a73edc37908757d693a507e04d3ea5bccc272ac3072034d01cda3dfe00eab1147395463f1ba5040ea312b7c882
7
+ data.tar.gz: 73f4d87697fac3316c30871b45f6b0550010d0a9f1984c217a12a47bb1b0d9b15127ccb8d9e020a1b68a3db7ddc5824a920fefe2a09b3fd18485c958c0cc74d4
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xkeyrap (0.0.1)
5
- evdev
6
- libevdev
7
- uinput-device
8
- xlib-objects
4
+ xkeyrap (0.0.4)
5
+ evdev (~> 1.0)
6
+ libevdev (~> 1.0)
7
+ uinput-device (~> 0.4)
8
+ xlib-objects (~> 0.7)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,27 +1,3 @@
1
1
  # Xkeyrap
2
2
 
3
3
  Xkeyrap 是一个受 [https://github.com/mooz/xkeysnail](xkeysnail) 启发的项目。
4
-
5
- 如果你和我有一样的 [https://www.songofcode.com/posts/linux-shortcuts-for-macos/](改键需求), 可以使用下面的配置文件:
6
-
7
- ``` json
8
- {
9
- "Firefox": {
10
- "KEY_LEFTALT": "KEY_LEFTCTRL",
11
- "KEY_CAPSLOCK": "KEY_LEFTALT"
12
- },
13
- "Google-chrome": {
14
- "KEY_LEFTALT": "KEY_LEFTCTRL",
15
- "KEY_CAPSLOCK": "KEY_LEFTALT"
16
- }
17
- }
18
- ```
19
-
20
- ## Usage
21
-
22
- ``` shell
23
- sudo gem install xkeyrap # need sudo
24
-
25
- xhost +SI:localuser:root
26
- sudo xkeyrap config.json
27
- ```
data/bin/xkeyrap CHANGED
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'xkeyrap'
4
-
5
- input_device = ARGV[1] # '/dev/input/event4'
6
- config_file = ARGV[2] # 'config.json'
7
-
8
- Xkeyrap::Cli.run(input_device, config_file)
4
+ device = ARGV[1]
5
+ puts "grab device: #{device}"
6
+ Xkeyrap::Cli.run(device)
@@ -1,38 +1,43 @@
1
1
  require "evdev"
2
2
  require 'libevdev'
3
3
  require 'uinput/device'
4
- require 'json'
5
4
 
6
5
  module Xkeyrap
7
6
  class Command
7
+ attr_accessor :keys
8
+ attr_accessor :modifier_keys
8
9
  attr_accessor :output_device
9
10
  attr_accessor :config
10
11
 
11
- def initialize(device, config_file)
12
- self.config = default_config.merge(JSON.parse(config_file)) rescue default_config
12
+ def initialize(device, config)
13
+ self.keys = Set.new
14
+ self.modifier_keys = Set.new
13
15
  self.output_device = device
16
+ unless config
17
+ self.config = {
18
+ global: {
19
+ KEY_CAPSLOCK: :KEY_LEFTCTRL,
20
+ KEY_LEFTCTRL: :KEY_CAPSLOCK,
21
+ KEY_LEFTALT: :KEY_LEFTMETA,
22
+ KEY_LEFTMETA: :KEY_LEFTALT
23
+ },
24
+ "Firefox": {
25
+ KEY_LEFTALT: :KEY_LEFTCTRL,
26
+ KEY_CAPSLOCK: :KEY_LEFTMETA,
27
+ KEY_LEFTMETA: :KEY_LEFTALT
28
+ }
29
+ }
30
+ end
14
31
  end
15
32
 
16
33
  def receive(state, key, wm_class_name = "global")
17
- key = key.to_sym
18
- puts "input: #{state} ... #{key}"
34
+ puts "origin: #{wm_class_name} | #{state} | #{key}"
19
35
  sub_json = self.config[wm_class_name.to_sym] || self.config[:global]
20
36
  mapped_key = sub_json[key] || self.config[:global][key] || key
21
- puts "output: #{state} ... #{mapped_key}"
22
- self.output_device.send_event(:EV_KEY, mapped_key.to_sym, state)
37
+ puts "mapped: #{wm_class_name} | #{state} | #{mapped_key}"
38
+ self.output_device.send_event(:EV_KEY, mapped_key, state)
23
39
  self.output_device.send_event(:EV_SYN, :SYN_REPORT)
24
40
  end
25
41
 
26
- def default_config
27
- {
28
- global: {
29
- KEY_CAPSLOCK: :KEY_LEFTCTRL,
30
- KEY_LEFTCTRL: :KEY_CAPSLOCK,
31
- KEY_LEFTALT: :KEY_LEFTMETA,
32
- KEY_LEFTMETA: :KEY_LEFTALT
33
- }
34
- }
35
- end
36
-
37
42
  end
38
43
  end
data/lib/xkeyrap/key.rb CHANGED
@@ -98,6 +98,9 @@ module Xkeyrap
98
98
  :KEY_F10,
99
99
  :KEY_F11,
100
100
  :KEY_F12,
101
+ :MUTE,
102
+ :VOLUMEDOWN,
103
+ :VOLUMEUP
101
104
  ]
102
105
 
103
106
  ALL_KEYS = NUMBER_KEYS + MISC_KEYS + LETTER_KEYS + MODIFIER_KEYS + FUNCTION_KEYS
@@ -1,3 +1,3 @@
1
1
  module Xkeyrap
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/xkeyrap.rb CHANGED
@@ -10,7 +10,7 @@ require 'uinput/device'
10
10
  module Xkeyrap
11
11
  class Cli
12
12
 
13
- def self.run(input_device, config_file)
13
+ def self.run(device)
14
14
  display = XlibObj::Display.new(':0')
15
15
  device = Uinput::Device.new do
16
16
  self.name = "Xkeyrap virtual device"
@@ -24,10 +24,14 @@ module Xkeyrap
24
24
  self.add_event(:EV_SYN)
25
25
  end
26
26
 
27
- keyboard = Evdev.new(input_device)
27
+ keyboard = Evdev.new(device)
28
+
29
+
30
+ #puts keyboard.supports_event? :KEY_ENTER
31
+ #puts keyboard.supports_event? :KEY_KPENTER
28
32
  keyboard.grab
29
33
 
30
- command = Command.new(device, config_file)
34
+ command = Command.new(device, nil)
31
35
 
32
36
  key_handler = keyboard.on(*Xkeyrap::Key::ALL_KEYS) do |state, key|
33
37
  root_window = display.screens.first.root_window
@@ -57,10 +61,14 @@ module Xkeyrap
57
61
  parent = FFI::MemoryPointer.new :Window
58
62
  number = FFI::MemoryPointer.new :uint
59
63
  children = FFI::MemoryPointer.new :pointer
60
- q = Xlib.XQueryTree(display.to_native, focused_window.to_native, root, parent, children, number)
61
- parent_window_id = parent.read(:int)
62
- parent_window = top_level_windows.select {|tlw| tlw.id == parent_window_id }.first
63
- parent_window.property("WM_CLASS")[1]
64
+ begin
65
+ q = Xlib.XQueryTree(display.to_native, focused_window.to_native, root, parent, children, number)
66
+ parent_window_id = parent.read(:int)
67
+ parent_window = top_level_windows.select {|tlw| tlw.id == parent_window_id }.first
68
+ parent_window.property("WM_CLASS")[1]
69
+ rescue
70
+ "global"
71
+ end
64
72
  end
65
73
  end
66
74
  end
data/xkeyrap.gemspec CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  lib = File.expand_path("../lib", __FILE__)
2
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
  require "xkeyrap/version"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xkeyrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - teddy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-23 00:00:00.000000000 Z
11
+ date: 2018-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler