rkremap 0.5.0 → 0.5.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: 2052faf03d55e5ca684ee7c991fe42ecb187f2294376216e333d9aced2a45188
4
- data.tar.gz: cc901a01fec47fcafc320ea355c5ea71dd8cc8e54c05f4f7774f02beda3ab328
3
+ metadata.gz: 93f0a2d7d2c705b779d942618d4da708ef395386bc9529d06cc4c4f644243bac
4
+ data.tar.gz: bddb932d29c287b3e00105adac03fc420506253c5f00c309dee22da46678502f
5
5
  SHA512:
6
- metadata.gz: dad24b3679af4213746a787811812afe8791d4964eba2ea018debffb94f7558dec29915a9be18e3aa1952a6817ea6ec823045c0ab8ae45afc9d22649f8c90374
7
- data.tar.gz: 6dbef790e758293b32891d2aabd4cc939b3259b55b5c6d5ed297d2a96ffe9feaeb657675c98b16cd3c73480f3d6f0b35e98f12fadd0d0f41a3020cca894cf069
6
+ metadata.gz: 41fff4f8444a6c585403ac5a3655eb5b4e1d631332594c95e4d3149a973dced926b4a726cf912522e7ac3c0dcbb4ba0e3ea6461dfe6853e04c1a9086162307e2
7
+ data.tar.gz: 88b6bdb97c04ed2629d1eac337e89f9854f954daf392b4e0a395e6df94699ff1c7e7e66be78ea3adeb3221fff8a6a88d2d8a38699f503575c5376bbdfcf96556
@@ -16,8 +16,10 @@ rk.remap(hold: 0.5, map: {
16
16
 
17
17
  # マウスボタンイベントはそのまま
18
18
  rk.match(device: :mouse) do |event|
19
- rk.event(code: event.code, type: event.type)
20
- event.skip
19
+ unless Rkremap::CODE_KEY[event.code] =~ /^KEY_/
20
+ rk.event(code: event.code, type: event.type)
21
+ event.skip
22
+ end
21
23
  end
22
24
 
23
25
  rk.start do |code, mod|
data/example/tmtms.rb CHANGED
@@ -20,8 +20,10 @@ rk.remap(hold: 0.5, map: {
20
20
 
21
21
  # マウスボタンイベントはそのまま
22
22
  rk.match(device: :mouse) do |event|
23
- rk.event(code: event.code, type: event.type)
24
- event.skip
23
+ unless Rkremap::CODE_KEY[event.code] =~ /^KEY_/
24
+ rk.event(code: event.code, type: event.type)
25
+ event.skip
26
+ end
25
27
  end
26
28
 
27
29
  # CAPSLOCK は CTRL に変換
@@ -55,12 +57,26 @@ mod_disable_meta = {
55
57
  }
56
58
  mod_disable_all = {}.merge(mod_disable_ctrl, mod_disable_shift, mod_disable_alt, mod_disable_meta)
57
59
 
58
- # Emacs や VirtualBox ではそのまま
59
- rk.match(app: /Emacs|VirtualBox Machine/) do |event|
60
+ # VirtualBox
61
+ rk.match(app: /VirtualBox Machine/) do |event|
60
62
  rk.event(code: event.code, type: event.type)
61
63
  event.skip
62
64
  end
63
65
 
66
+ # Emacs
67
+ rk.match(app: {class_name: 'Emacs'}) do |event, mod|
68
+ # 修飾キーが Super だけの場合は Alt として扱う。ただしキーが TAB の場合は除く。
69
+ mod_enabled = mod.select{_2}.keys
70
+ if !mod_enabled.empty? && mod_enabled.all?{_1 == KEY_LEFTMETA || _1 == KEY_RIGHTMETA} && event.code != KEY_TAB
71
+ rk.with_modifier(mod_disable_meta.merge(KEY_LEFTALT => true)) do
72
+ rk.event(code: event.code, type: event.type)
73
+ end
74
+ else
75
+ rk.event(code: event.code, type: event.type)
76
+ end
77
+ event.skip
78
+ end
79
+
64
80
  # 端末
65
81
  rk.match(app: /terminal/i) do |event, mod|
66
82
  # Super+Ctrl はそのまま
@@ -83,6 +99,16 @@ rk.match(app: /terminal/i) do |event, mod|
83
99
  event.skip
84
100
  end
85
101
 
102
+ # Firefox で Super+Ctrl+C は Alt+Ctrl+C に変換
103
+ rk.match(app: {class_name: 'firefox'}) do |event, mod|
104
+ if (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && (mod[KEY_LEFTCTRL] || mod[KEY_RIGHTCTRL]) && event.code == KEY_C
105
+ rk.with_modifier(mod_disable_meta.merge(KEY_LEFTCTRL => true, KEY_LEFTALT => true)) do
106
+ rk.event(code: event.code, type: event.type)
107
+ end
108
+ event.skip
109
+ end
110
+ end
111
+
86
112
  # その他のウィンドウ
87
113
  ctrl_map = {
88
114
  KEY_A => KEY_HOME,
@@ -108,6 +134,11 @@ rk.start do |code, mod|
108
134
  rk.key(code, mod.merge(mod_disable_meta, KEY_LEFTCTRL => true))
109
135
  next
110
136
  end
137
+ # Super+[←→] を Alt+[←→] に変換
138
+ if (mod[KEY_LEFTMETA] || mod[KEY_RIGHTMETA]) && (Rkremap::CODE_KEY[code] =~ /\AKEY_(LEFT|RIGHT)\z/)
139
+ rk.key(code, mod.merge(mod_disable_meta, KEY_LEFTALT => true))
140
+ next
141
+ end
111
142
 
112
143
  # Alt + F, B は Ctrl + →, ← に変換
113
144
  if (mod[KEY_LEFTALT] || mod[KEY_RIGHTALT]) && (code == KEY_F || code == KEY_B)
data/lib/rkremap/event.rb CHANGED
@@ -23,11 +23,15 @@ class Rkremap
23
23
  end
24
24
 
25
25
  def inspect
26
- "#<Rkremap::Event: #{code}(#{CODE_KEY[code]}) #{value} #{device.inspect}>"
26
+ if ev_type == EV_KEY
27
+ "#<Rkremap::Event: #{code}(#{CODE_KEY[code]}) #{value} #{device.inspect}>"
28
+ else
29
+ "#<Rkremap::Event: type: #{ev_type}>"
30
+ end
27
31
  end
28
32
 
29
33
  def type
30
- @type ||= value == 1 ? :press : value == 0 ? :release : :repeat
34
+ value == 1 ? :press : value == 0 ? :release : :repeat
31
35
  end
32
36
 
33
37
  def match?(device:, code:, type:, app:)
data/lib/rkremap/remap.rb CHANGED
@@ -26,6 +26,10 @@ class Rkremap
26
26
  end
27
27
  end
28
28
 
29
+ @rk.match(code: keycodes, type: :repeat) do |event|
30
+ event.skip
31
+ end
32
+
29
33
  @rk.match(code: keycodes, type: :release) do |event|
30
34
  if @pressed[event.code]
31
35
  @rk.event(code: @pressed[event.code], type: :release)
@@ -59,12 +63,17 @@ class Rkremap
59
63
  end
60
64
 
61
65
  @rk.match(code: keycodes, type: :release) do |event|
62
- if jobs[event.code]&.cancel
63
- @rk.key(event.code)
64
- elsif map[event.code]
65
- @rk.event(code: map[event.code], type: :release)
66
+ code = event.code
67
+ if jobs[code]
68
+ if jobs[code].cancel
69
+ event.value = 1
70
+ @rk.append_event(Event.new(event.device, event.time, event.ev_type, event.code, 0))
71
+ elsif map[code]
72
+ event.code = map[code]
73
+ @pressed[code] = nil
74
+ end
75
+ jobs[code] = nil
66
76
  end
67
- event.skip
68
77
  end
69
78
 
70
79
  @rk.match(type: :press) do
@@ -89,17 +98,21 @@ class Rkremap
89
98
  # @param to [Integer, Array<Integer>]
90
99
  # @param event [Rkremap::Event, nil]
91
100
  def make_press_event(to, event=nil)
92
- Array(to).each do |key|
101
+ to = Array(to)
102
+ f = true
103
+ to.each do |key|
93
104
  @pressed[event.code] = key if event
94
105
  if @rk.modifiers.include? key
95
106
  @rk.event(code: key, type: :press)
96
- event&.skip
97
107
  elsif event
98
108
  event.code = key
109
+ f = false
99
110
  else
100
- @rk.key(code: key, type: :press)
111
+ @rk.key(key)
112
+ f = false
101
113
  end
102
114
  end
115
+ event&.skip if f
103
116
  end
104
117
  end
105
118
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Rkremap
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.1"
5
5
  end
data/lib/rkremap.rb CHANGED
@@ -83,9 +83,10 @@ class Rkremap
83
83
  @evdev_list.detect_loop
84
84
  @mod_state = @modifiers.map.to_h{|m| [m, false]}
85
85
  winattr = WinAttr.new if @x11
86
+ @events = []
86
87
  while true
87
88
  @keys = []
88
- event = @evdev_list.read_event
89
+ event = @events.shift || @evdev_list.read_event
89
90
  if event.ev_type != EV_KEY
90
91
  if event.device.grab?
91
92
  @uinput.write_event(event.ev_type, event.code, event.value)
@@ -138,6 +139,12 @@ class Rkremap
138
139
  end
139
140
  end
140
141
 
142
+ # @param event [Rkremap::Event]
143
+ def append_event(event)
144
+ @events.push event
145
+ @events.push Event.new(event.device, event.time, EV_SYN, SYN_REPORT, 0)
146
+ end
147
+
141
148
  private
142
149
 
143
150
  def update_modifiers(code, value)
@@ -190,7 +197,7 @@ class Rkremap
190
197
  # @param app [Array, Hash, String, Regexp]
191
198
  # @return [Boolean]
192
199
  def match?(app)
193
- Array(app).each do |a|
200
+ [app].flatten.each do |a|
194
201
  a = {class_name: a, title: a} unless a.is_a? Hash
195
202
  return true if match_sub(a[:class_name], class_name) || match_sub(a[:title], title)
196
203
  end
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.5.0
4
+ version: 0.5.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-09-04 00:00:00.000000000 Z
11
+ date: 2023-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tmtms_timer
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubygems_version: 3.3.7
71
+ rubygems_version: 3.5.0.dev
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: key remapper