fusuma-plugin-remap 0.4.1 → 0.6.0

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: c2455d59dcc7050237331988d27f8def95586791fd1f86974146ceb7a373ff35
4
- data.tar.gz: c39286dafd8112602c61953512d16f85f0e3b51c318e215431d5539efd33eadd
3
+ metadata.gz: eb8fcbe6eb272ae081100e9faa67846308cc7a9adb4cfbff7af5b693ffbcbd3e
4
+ data.tar.gz: 310ff2f96642be97fda21211d8ca7ed87aa2b8682a2cf70797882c9168e4df0b
5
5
  SHA512:
6
- metadata.gz: a40ff642c159e4f7a8f627929c01f99e44e666c0de24f5c977fff7c2967a37fce1693152053d6477edc9f4c87e7691b4b987ca7bd0fdbade5029d40f12d6e1a5
7
- data.tar.gz: efb92a3fb8c1d67b93e811ad631d0437e5f0a2000035a2c2637ae942d25072869efb7c88a00478dfb6606239a3283f86bf6fc4ab970feeb6c295c1ed99f70d5f
6
+ metadata.gz: 97b927263c174f2ffc7edf3648510a77c34433523b58373aa4e533a21fe2c2198c181922352c1044717fabdc02d3a093b0a8e091ab0b3e6ba003970151395d67
7
+ data.tar.gz: 8adf8cb9f59083639f0439a5107a0c8afd7f386aaef572db8f6bb85589585aad8aa939f12613120ced49f100a67646379227b728bed9ee80ad12d171039cd460
data/README.md CHANGED
@@ -65,12 +65,26 @@ remap:
65
65
  SPACE: BTN_LEFT
66
66
  ```
67
67
 
68
- ## Emergency stop keybind for virtual keyboard
68
+ ## Emergency Stop Keybind for Virtual Keyboard
69
69
 
70
- This is a special keybind for emergency stop.
71
- If you press following keybind, physical keyboard will be ungrabbed and Fusuma process will be terminated.
70
+ This plugin includes a special keybind for emergency stop. Pressing this key combination will ungrab the physical keyboard and terminate the Fusuma process. This feature is particularly useful in situations where the plugin or system becomes unresponsive.
72
71
 
73
- <kbd>RIGHTCTRL</kbd> <kbd>LEFTCTRL</kbd>
72
+ ### How to Use
73
+ To execute the emergency stop, press the following key combination(default):
74
+ - <kbd>RIGHTCTRL</kbd> → <kbd>LEFTCTRL</kbd>
75
+
76
+ ### Configuration Example
77
+ You can configure the emergency stop key in your Fusuma configuration file (`~/.config/fusuma/config.yml`) as follows:
78
+
79
+ ```yaml
80
+ plugin:
81
+ inputs:
82
+ remap_keyboard_input:
83
+ emergency_ungrab_keys: RIGHTCTRL+LEFTCTRL # keybind
84
+ ```
85
+
86
+ This configuration allows you to specify which keys will trigger the emergency stop functionality.
87
+ It is important to verify this keybind to ensure a swift response during unexpected situations.
74
88
 
75
89
  ## Contributing
76
90
 
@@ -13,13 +13,12 @@ module Fusuma
13
13
 
14
14
  def config_param_types
15
15
  {
16
+ emergency_ungrab_keys: [String],
16
17
  keyboard_name_patterns: [Array, String],
17
18
  touchpad_name_patterns: [Array, String]
18
19
  }
19
20
  end
20
21
 
21
- attr_reader :pid
22
-
23
22
  def initialize
24
23
  super
25
24
  setup_remapper
@@ -49,6 +48,7 @@ module Fusuma
49
48
 
50
49
  def setup_remapper
51
50
  config = {
51
+ emergency_ungrab_keys: config_params(:emergency_ungrab_keys),
52
52
  keyboard_name_patterns: config_params(:keyboard_name_patterns),
53
53
  touchpad_name_patterns: config_params(:touchpad_name_patterns)
54
54
  }
@@ -58,7 +58,7 @@ module Fusuma
58
58
  # physical keyboard input event
59
59
  @fusuma_reader, fusuma_writer = IO.pipe
60
60
 
61
- @pid = fork do
61
+ fork do
62
62
  layer_manager.writer.close
63
63
  @fusuma_reader.close
64
64
  remapper = Remap::KeyboardRemapper.new(
@@ -2,6 +2,7 @@ plugin:
2
2
  inputs:
3
3
  remap_keyboard_input:
4
4
  keyboard_name_patterns: ["keyboard", "Keyboard", "KEYBOARD"]
5
+ emergency_ungrab_keys: RIGHTCTRL+LEFTCTRL
5
6
  buffers:
6
7
  keypress_buffer:
7
8
  source: remap_keyboard_input
@@ -17,8 +17,6 @@ module Fusuma
17
17
  }
18
18
  end
19
19
 
20
- attr_reader :pid
21
-
22
20
  def initialize
23
21
  super
24
22
  setup_remapper
@@ -79,7 +77,7 @@ module Fusuma
79
77
  # physical touchpad input event
80
78
  @fusuma_reader, fusuma_writer = IO.pipe
81
79
 
82
- @pid = fork do
80
+ fork do
83
81
  # layer_manager.writer.close
84
82
  @fusuma_reader.close
85
83
  remapper = Remap::TouchpadRemapper.new(
@@ -92,7 +92,7 @@ module Fusuma
92
92
  rescue EOFError => e # device is closed
93
93
  MultiLogger.error "Device is closed: #{e.message}"
94
94
  ensure
95
- @destroy.call
95
+ @destroy&.call
96
96
  end
97
97
 
98
98
  private
@@ -103,9 +103,7 @@ module Fusuma
103
103
  MultiLogger.info("Reload keyboards: #{source_keyboards.map(&:device_name)}")
104
104
 
105
105
  set_trap(source_keyboards)
106
- # TODO: Extract to a configuration file or make it optional
107
- # it should stop other remappers
108
- set_emergency_ungrab_keybinds("RIGHTCTRL", "LEFTCTRL")
106
+ set_emergency_ungrab_keys(@config[:emergency_ungrab_keys])
109
107
  grab_keyboards(source_keyboards)
110
108
  rescue => e
111
109
  MultiLogger.error "Failed to reload keyboards: #{e.message}"
@@ -174,9 +172,9 @@ module Fusuma
174
172
  wait_release_all_keys(keyboard)
175
173
  begin
176
174
  keyboard.grab
177
- MultiLogger.info "Grabbed #{keyboard.device_name}"
175
+ MultiLogger.info "Grabbed keyboard: #{keyboard.device_name}"
178
176
  rescue Errno::EBUSY
179
- MultiLogger.error "Failed to grab #{keyboard.device_name}"
177
+ MultiLogger.error "Failed to grab keyboard: #{keyboard.device_name}"
180
178
  end
181
179
  end
182
180
  end
@@ -205,14 +203,31 @@ module Fusuma
205
203
  end
206
204
 
207
205
  # Emergency stop keybind for virtual keyboard
208
- def set_emergency_ungrab_keybinds(first_key, second_key)
209
- first_keycode = find_code_from_key(first_key)
210
- second_keycode = find_code_from_key(second_key)
211
- MultiLogger.info "Emergency ungrab keybind: #{first_key} + #{second_key}"
206
+ def set_emergency_ungrab_keys(keybind_string)
207
+ keybinds = keybind_string&.split("+")
208
+ # TODO: Extract to a configuration file or make it optional
209
+ # it should stop other remappers
210
+ if keybinds&.size != 2
211
+ MultiLogger.error "Invalid emergency ungrab keybinds: #{keybinds}"
212
+ MultiLogger.error "Please set two keys separated by '+'"
213
+ MultiLogger.error <<~YAML
214
+ plugin:
215
+ inputs:
216
+ remap_keyboard_input:
217
+ emergency_ungrab_keys: RIGHTCTRL+LEFTCTRL
218
+ YAML
219
+
220
+ exit 1
221
+ end
222
+
223
+ MultiLogger.info "Emergency ungrab keybind: #{keybinds[0]}+#{keybinds[1]}"
224
+
225
+ first_keycode = find_code_from_key(keybinds[0])
226
+ second_keycode = find_code_from_key(keybinds[1])
212
227
 
213
228
  @emergency_stop = lambda do |prev, current|
214
229
  if (prev&.code == first_keycode && prev.value != 0) && (current.code == second_keycode && current.value != 0)
215
- MultiLogger.info "Emergency ungrab keybind: #{first_key} + #{second_key}"
230
+ MultiLogger.info "Emergency ungrab keybind is pressed: #{keybinds[0]}+#{keybinds[1]}"
216
231
  @destroy.call
217
232
  end
218
233
  end
@@ -278,7 +293,7 @@ module Fusuma
278
293
  def released_all_keys?(device)
279
294
  # key status if all bytes are 0, the key is not pressed
280
295
  bytes = device.read_ioctl_with(Revdev::EVIOCGKEY)
281
- bytes.unpack("C*").all? { |byte| byte == 0 }
296
+ bytes.unpack("C*").all?(0)
282
297
  end
283
298
 
284
299
  def wait_release_all_keys(device, &block)
@@ -18,6 +18,8 @@ module Fusuma
18
18
  @source_touchpad = source_touchpad # original touchpad
19
19
  @fusuma_writer = fusuma_writer # write event to fusuma_input
20
20
  @palm_detector ||= PalmDetection.new(source_touchpad)
21
+
22
+ set_trap
21
23
  end
22
24
 
23
25
  # TODO: grab touchpad events and remap them
@@ -125,6 +127,10 @@ module Fusuma
125
127
  @fusuma_writer.write(data.to_msgpack)
126
128
  end
127
129
  end
130
+ rescue => e
131
+ MultiLogger.error "An error occurred: #{e.message}"
132
+ ensure
133
+ @destroy&.call
128
134
  end
129
135
 
130
136
  private
@@ -134,11 +140,24 @@ module Fusuma
134
140
  end
135
141
 
136
142
  def create_virtual_touchpad
137
- MultiLogger.info "Create virtual keyboard: #{VIRTUAL_TOUCHPAD_NAME}"
138
-
143
+ MultiLogger.info "Create virtual touchpad: #{VIRTUAL_TOUCHPAD_NAME}"
139
144
  uinput.create_from_device(name: VIRTUAL_TOUCHPAD_NAME, device: @source_touchpad)
140
145
  end
141
146
 
147
+ def set_trap
148
+ @destroy = lambda do
149
+ begin
150
+ uinput.destroy
151
+ rescue IOError
152
+ # already destroyed
153
+ end
154
+ exit 0
155
+ end
156
+
157
+ Signal.trap(:INT) { @destroy.call }
158
+ Signal.trap(:TERM) { @destroy.call }
159
+ end
160
+
142
161
  # Detect palm touch
143
162
  class PalmDetection
144
163
  def initialize(touchpad)
@@ -3,7 +3,7 @@
3
3
  module Fusuma
4
4
  module Plugin
5
5
  module Remap
6
- VERSION = "0.4.1"
6
+ VERSION = "0.6.0"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusuma-plugin-remap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iberianpig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-07 00:00:00.000000000 Z
11
+ date: 2024-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fusuma