rkremap 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 127371f8cab9cd5ff002b35b886b79a3a4424d779f4bf938b9006fb633917a51
4
- data.tar.gz: a02bd1649a62f30916e125582409f9b9ab8d57c33caf10bdfc5f7e6392ece992
3
+ metadata.gz: 6476d10293c91c5afb744c6ebe1162d26ab253ad06aade6f5f2568db05bb7631
4
+ data.tar.gz: 35fd73d5a2d71ca797fd626397a789e8f22b5bd54cfa2ef0ca08f46adc6efa7f
5
5
  SHA512:
6
- metadata.gz: 111e0d08dfaec939535f150eb8d2852c5bbda078d705191d8d03d0d035782088cf73f7c861029cc49b99860f8645be46c1ef557326bae1e17170d15116ee887d
7
- data.tar.gz: a1124ae0dabd8f87286d7ae2cc375a0490ffc58a884c2fb0f9694f51cee9d97b309ea83842afeb46f86184a1523e96c06429688bf71aa05e1a6e9555d6f488cb
6
+ metadata.gz: bdf4f1364db8aa24dc49dab823e4f16200994058a6ff8d8e3323272d0783139af49f6fcdbb7f22b573dab92554d39d92429d24aa7b5fedf80e27139cf62bd120
7
+ data.tar.gz: d868e6b7af37edfa90324014669ff7de5595f392116bedeaf011cf95cd49ce9621782f1dda6e402c4e6117509ae0a0337322447028975ab743324da318479d0b
data/README.md CHANGED
@@ -22,6 +22,7 @@ KERNEL=="uinput", GROUP="input"
22
22
  ```
23
23
  という内容で作れば `/dev/uinput` のグループを `input` にできるっぽい。
24
24
 
25
+ `$VERBOSE` が真の場合はデバイスを検出したときと切断を検出したときにデバイス名を標準出力に出力する。
25
26
 
26
27
  ## Rkremap
27
28
 
@@ -48,18 +48,24 @@ rk.match(app: /terminal/i) do |event, mod|
48
48
  # Super+Ctrl はそのまま
49
49
  if (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && (mod[KEY_LEFTCTRL] || mod[KEY_RIGHTCTRL])
50
50
  rk.event(code: event.code, type: event.type)
51
- end
51
+ # Super+0/Minus は Ctrl+0/Minus に変換
52
+ elsif (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && Rkremap::CODE_KEY[event.code] =~ /\AKEY_(0|MINUS)\z/
53
+ rk.with_modifier(mod_disable_all.merge(KEY_LEFTCTRL => true)) do
54
+ rk.event(code: event.code, type: event.type)
55
+ end
52
56
  # Super+KEY は Ctrl+Shift+KEY に変換
53
- if (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && Rkremap::CODE_KEY[event.code] =~ /\AKEY_[A-Z]\z/
57
+ elsif (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && Rkremap::CODE_KEY[event.code] =~ /\AKEY_([A-Z]|EQUAL)\z/
54
58
  rk.with_modifier(mod_disable_meta.merge(KEY_LEFTCTRL => true, KEY_LEFTSHIFT => true)) do
55
59
  rk.event(code: event.code, type: event.type)
56
60
  end
57
- else
61
+ # それ以外はそのまま
62
+ else # rubocop:disable Lint/DuplicateBranch
58
63
  rk.event(code: event.code, type: event.type)
59
64
  end
60
65
  event.skip
61
66
  end
62
67
 
68
+ # その他のウィンドウ
63
69
  rk.start do |code, mod|
64
70
  # Super + Ctrl + 何か はそのまま
65
71
  if (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && (mod[KEY_LEFTCTRL] || mod[KEY_RIGHTCTRL])
@@ -67,8 +73,8 @@ rk.start do |code, mod|
67
73
  next
68
74
  end
69
75
 
70
- # SUPER+[A-Z]/Enter を Ctrl+[A-Z]/Enter に変換
71
- if (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && (Rkremap::CODE_KEY[code] =~ /\AKEY_[A-Z]\z/ || code == KEY_ENTER)
76
+ # Super+[A-Z]/Minus/Equal/Enter を Ctrl+[A-Z]/Minus/Equal/Enter に変換
77
+ if (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && (Rkremap::CODE_KEY[code] =~ /\AKEY_([0-9A-Z]|MINUS|EQUAL|ENTER)\z/)
72
78
  rk.key(code, mod.merge(mod_disable_meta, KEY_LEFTCTRL => true))
73
79
  next
74
80
  end
data/example/tmtms.rb CHANGED
@@ -5,7 +5,7 @@ require 'tmtms_timer'
5
5
 
6
6
  include Rkremap::KeyCode
7
7
 
8
- rk = Rkremap.new(*ARGV, mouse: true, exclude: /touchpad/)
8
+ rk = Rkremap.new(*ARGV, mouse: true, exclude: /touchpad/i)
9
9
  rk.grab = true
10
10
  rk.x11 = true
11
11
 
@@ -107,13 +107,18 @@ rk.match(app: /terminal/i) do |event, mod|
107
107
  # Super+Ctrl はそのまま
108
108
  if (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && (mod[KEY_LEFTCTRL] || mod[KEY_RIGHTCTRL])
109
109
  rk.event(code: event.code, type: event.type)
110
- end
110
+ # Super+0/Minus は Ctrl+0/Minus に変換
111
+ elsif (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && Rkremap::CODE_KEY[event.code] =~ /\AKEY_(0|MINUS)\z/
112
+ rk.with_modifier(mod_disable_all.merge(KEY_LEFTCTRL => true)) do
113
+ rk.event(code: event.code, type: event.type)
114
+ end
111
115
  # Super+KEY は Ctrl+Shift+KEY に変換
112
- if (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && Rkremap::CODE_KEY[event.code] =~ /\AKEY_[A-Z]\z/
116
+ elsif (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && Rkremap::CODE_KEY[event.code] =~ /\AKEY_([A-Z]|EQUAL)\z/
113
117
  rk.with_modifier(mod_disable_meta.merge(KEY_LEFTCTRL => true, KEY_LEFTSHIFT => true)) do
114
118
  rk.event(code: event.code, type: event.type)
115
119
  end
116
- else
120
+ # それ以外はそのまま
121
+ else # rubocop:disable Lint/DuplicateBranch
117
122
  rk.event(code: event.code, type: event.type)
118
123
  end
119
124
  event.skip
@@ -139,8 +144,8 @@ rk.start do |code, mod|
139
144
  next
140
145
  end
141
146
 
142
- # Super+[A-Z]/Enter を Ctrl+[A-Z]/Enter に変換
143
- if (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && (Rkremap::CODE_KEY[code] =~ /\AKEY_[A-Z]\z/ || code == KEY_ENTER)
147
+ # Super+[A-Z]/Minus/Equal/Enter を Ctrl+[A-Z]/Minus/Equal/Enter に変換
148
+ if (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && (Rkremap::CODE_KEY[code] =~ /\AKEY_([0-9A-Z]|MINUS|EQUAL|ENTER)\z/)
144
149
  rk.key(code, mod.merge(mod_disable_meta, KEY_LEFTCTRL => true))
145
150
  next
146
151
  end
data/lib/rkremap/evdev.rb CHANGED
@@ -18,6 +18,10 @@ class Rkremap
18
18
  @grab = false
19
19
  end
20
20
 
21
+ def inspect
22
+ "#<Rkremap::Evdev: #{name} (#{path})>"
23
+ end
24
+
21
25
  def eql?(other)
22
26
  other.is_a?(Evdev) && self.path == other.path
23
27
  end
@@ -92,12 +96,12 @@ class Rkremap
92
96
  # unsigned short code;
93
97
  # unsigned int value;
94
98
  # };
95
- # @return [Array<Time, Integer, Integer, Integer>]
99
+ # @return [Rkremap::Event]
96
100
  def read_event
97
101
  raw = io.sysread(24) # sizeof(struct input_event)
98
102
  sec, usec, type, code, value = raw.unpack('Q!Q!SSl')
99
103
  time = Time.at(sec, usec)
100
- return time, type, code, value
104
+ Event.new(self, time, type, code, value)
101
105
  end
102
106
 
103
107
  # @param pattern [Symbol, Regexp]
@@ -44,19 +44,25 @@ class Rkremap
44
44
  new_devs -= @device_list.keys
45
45
  new_devs.each do |path|
46
46
  ev = Evdev.new(path)
47
- next if @exclude && ev.name =~ @exclude
48
- if ev.keyboard? || (@detect_mouse && ev.mouse?)
47
+ stat = nil
48
+ if @exclude && ev.name =~ @exclude
49
+ stat = 'excluded'
50
+ elsif ev.keyboard? || (@detect_mouse && ev.mouse?)
49
51
  ev.grab if ev.match?(@grab)
50
- puts "detect: #{ev.name} (#{ev.path}) #{ev.grab? ? 'grab' : 'not grab'}" if $VERBOSE
51
52
  @io2evdev[ev.io] = ev
52
53
  @device_list[path] = ev
54
+ stat = ev.grab? ? 'grabbed' : 'not grabbed'
55
+ else
56
+ stat = 'ignored'
53
57
  end
58
+ puts "detect: #{ev.name} (#{ev.path}) #{stat}" if $VERBOSE
54
59
  end
55
60
  end
56
61
 
57
62
  # @param evdev [path]
58
63
  def remove_device(path)
59
64
  evdev = @device_list[path]
65
+ puts "disconnect: #{evdev.name} (#{evdev.path})" if $VERBOSE
60
66
  @io2evdev.delete evdev.io
61
67
  evdev.close
62
68
  @device_list.delete path
@@ -74,7 +80,7 @@ class Rkremap
74
80
  evdev = select(3)
75
81
  next unless evdev
76
82
  begin
77
- return Event.new(evdev)
83
+ return evdev.read_event
78
84
  rescue Errno::ENODEV
79
85
  remove_device(evdev.path)
80
86
  end
data/lib/rkremap/event.rb CHANGED
@@ -1,39 +1,29 @@
1
1
  class Rkremap
2
2
  class Event
3
- Raw = Struct.new(:time, :type, :code, :value)
4
-
5
3
  attr_accessor :app
6
- attr_reader :raw, :ev_type
7
- attr_writer :code
4
+ attr_reader :device
5
+ attr_reader :time
6
+ attr_reader :ev_type
7
+ attr_accessor :code
8
+ attr_accessor :value
8
9
 
9
10
  # @param evdev [Rkremap::Evdev]
10
- # @param app [Rkremap::App]
11
- def initialize(evdev)
12
- @evdev = evdev
13
- @raw = []
14
- while true
15
- s = evdev.read_event
16
- @raw.push Raw.new(*s)
17
- break if s[1] == EV_SYN
18
- end
19
- @ev_type = (@raw.find{_1[1] != EV_MSC && _1[1] != EV_SYN} || @raw.first)[1]
20
- end
21
-
22
- # @return [Rkremap::Event::Raw]
23
- def key
24
- @key ||= @raw.find{_1.type == EV_KEY}
25
- end
26
-
27
- def device
28
- @evdev
29
- end
30
-
31
- def code
32
- @code ||= key.code
33
- end
34
-
35
- def value
36
- key.value
11
+ # @param time [Time]
12
+ # @param type [Integer]
13
+ # @param code [Integer]
14
+ # @param value [Integer]
15
+ def initialize(evdev, time, type, code, value)
16
+ @device = evdev
17
+ @time = time
18
+ @ev_type = type
19
+ @code = code
20
+ @value = value
21
+ @app = nil
22
+ @skipped = false
23
+ end
24
+
25
+ def inspect
26
+ "#<Rkremap::Event: #{code}(#{CODE_KEY[code]}) #{value} #{device.inspect}>"
37
27
  end
38
28
 
39
29
  def type
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Rkremap
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
data/lib/rkremap.rb CHANGED
@@ -76,9 +76,7 @@ class Rkremap
76
76
  event = @evdev_list.read_event
77
77
  if event.ev_type != EV_KEY
78
78
  if event.device.grab?
79
- event.raw.each do |r|
80
- @uinput.write_event(r.type, r.code, r.value)
81
- end
79
+ @uinput.write_event(event.ev_type, event.code, event.value)
82
80
  end
83
81
  next
84
82
  end
@@ -158,7 +156,6 @@ class Rkremap
158
156
  # @param value [Integer] 0:release / 1:press / 2:repeat
159
157
  def write_event(code, value)
160
158
  @uinput.write_event(EV_KEY, code, value)
161
- @uinput.write_event(EV_SYN, SYN_REPORT, 0)
162
159
  end
163
160
 
164
161
  class App
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rkremap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TOMITA Masahiro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-19 00:00:00.000000000 Z
11
+ date: 2022-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tmtms_timer