fusuma-plugin-remap 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,172 @@
1
+ require "ruinput"
2
+
3
+ class UinputTouchpad < Ruinput::UinputDevice
4
+ include Ruinput
5
+
6
+ # create from original event device
7
+ # copy absinfo using eviocgabs
8
+ def create_from_device(name:, device:)
9
+ id = Revdev::InputId.new(
10
+ {
11
+ bustype: Revdev::BUS_I8042,
12
+ vendor: device.device_id.vendor,
13
+ product: device.device_id.product,
14
+ version: device.device_id.version
15
+ }
16
+ )
17
+
18
+ absinfo = {
19
+ Revdev::ABS_X => device.absinfo_for_axis(Revdev::ABS_X),
20
+ Revdev::ABS_Y => device.absinfo_for_axis(Revdev::ABS_Y),
21
+ Revdev::ABS_MT_POSITION_X => device.absinfo_for_axis(Revdev::ABS_MT_POSITION_X),
22
+ Revdev::ABS_MT_POSITION_Y => device.absinfo_for_axis(Revdev::ABS_MT_POSITION_Y),
23
+ Revdev::ABS_MT_SLOT => device.absinfo_for_axis(Revdev::ABS_MT_SLOT),
24
+ Revdev::ABS_MT_TOOL_TYPE => device.absinfo_for_axis(Revdev::ABS_MT_TOOL_TYPE),
25
+ Revdev::ABS_MT_TRACKING_ID => device.absinfo_for_axis(Revdev::ABS_MT_TRACKING_ID)
26
+ }
27
+
28
+ uud = Ruinput::UinputUserDev.new({
29
+ name: name,
30
+ id: id,
31
+ ff_effects_max: 0,
32
+ absmax: Array.new(Revdev::ABS_CNT, 0).tap { |a| absinfo.each { |k, v| a[k] = v[:absmax] } },
33
+ absmin: Array.new(Revdev::ABS_CNT, 0).tap { |a| absinfo.each { |k, v| a[k] = v[:absmin] } },
34
+ absfuzz: Array.new(Revdev::ABS_CNT, 0).tap { |a| absinfo.each { |k, v| a[k] = v[:absfuzz] } },
35
+ absflat: Array.new(Revdev::ABS_CNT, 0).tap { |a| absinfo.each { |k, v| a[k] = v[:absflat] } },
36
+ resolution: Array.new(Revdev::ABS_CNT, 0).tap { |a| absinfo.each { |k, v| a[k] = v[:resolution] } }
37
+ })
38
+
39
+ @file.syswrite uud.to_byte_string
40
+
41
+ set_all_events
42
+
43
+ @file.ioctl UI_DEV_CREATE, nil
44
+ @is_created = true
45
+ end
46
+
47
+ def set_all_events
48
+ raise "invalid method call: this uinput is already created" if @is_created
49
+
50
+ mouse_btns = [
51
+ Revdev::BTN_0,
52
+ Revdev::BTN_MISC,
53
+ Revdev::BTN_1,
54
+ Revdev::BTN_2,
55
+ Revdev::BTN_3,
56
+ Revdev::BTN_4,
57
+ Revdev::BTN_5,
58
+ Revdev::BTN_6,
59
+ Revdev::BTN_7,
60
+ Revdev::BTN_8,
61
+ Revdev::BTN_9,
62
+ Revdev::BTN_LEFT,
63
+ Revdev::BTN_MOUSE,
64
+ Revdev::BTN_MIDDLE,
65
+ Revdev::BTN_RIGHT,
66
+ Revdev::BTN_SIDE,
67
+ Revdev::BTN_EXTRA,
68
+ Revdev::BTN_FORWARD,
69
+ Revdev::BTN_BACK,
70
+ Revdev::BTN_TASK
71
+ # Revdev::BTN_TRIGGER, # disable because libinput recognize this device as a joystick
72
+ ].freeze
73
+
74
+ touchpad_btns = [
75
+ Revdev::BTN_TOUCH,
76
+ Revdev::BTN_TOOL_FINGER,
77
+ Revdev::BTN_TOOL_DOUBLETAP,
78
+ Revdev::BTN_TOOL_TRIPLETAP,
79
+ Revdev::BTN_TOOL_QUADTAP,
80
+ 0x148 # define BTN_TOOL_QUINTTAP 0x148 /* Five fingers on trackpad */
81
+ ].freeze
82
+
83
+ @file.ioctl UI_SET_EVBIT, Revdev::EV_KEY
84
+ @counter = 0
85
+ Revdev::KEY_CNT.times do |i|
86
+ # https://github.com/mooz/xkeysnail/pull/101/files
87
+ if mouse_btns.include?(i) || touchpad_btns.include?(i)
88
+ # puts "setting #{i} (#{Revdev::REVERSE_MAPS[:KEY][i]})"
89
+ @file.ioctl UI_SET_KEYBIT, i
90
+ else
91
+ # puts "skipping #{i} (#{Revdev::REVERSE_MAPS[:KEY][i]})"
92
+ end
93
+ end
94
+
95
+ touchpad_abs = [
96
+ Revdev::ABS_X,
97
+ Revdev::ABS_Y,
98
+ # Revdev::ABS_PRESSURE,
99
+ Revdev::ABS_MT_SLOT,
100
+ # Revdev::ABS_MT_TOUCH_MAJOR,
101
+ # Revdev::ABS_MT_TOUCH_MINOR,
102
+ Revdev::ABS_MT_POSITION_X,
103
+ Revdev::ABS_MT_POSITION_Y,
104
+ Revdev::ABS_MT_TRACKING_ID,
105
+ Revdev::ABS_MT_TOOL_TYPE
106
+ ].freeze
107
+
108
+ # kernel bug: device has min == max on ABS_Y
109
+ @file.ioctl UI_SET_EVBIT, Revdev::EV_ABS
110
+ Revdev::ABS_CNT.times do |i|
111
+ if touchpad_abs.include?(i)
112
+ puts "setting #{i} (#{Revdev::REVERSE_MAPS[:ABS][i]})"
113
+ @file.ioctl UI_SET_ABSBIT, i
114
+ else
115
+ puts "skipping #{i} (#{Revdev::REVERSE_MAPS[:ABS][i]})"
116
+ end
117
+ end
118
+
119
+ touchpad_rels = [
120
+ Revdev::REL_X,
121
+ Revdev::REL_Y,
122
+ Revdev::REL_WHEEL,
123
+ Revdev::REL_HWHEEL
124
+ ].freeze
125
+
126
+ @file.ioctl UI_SET_EVBIT, Revdev::EV_REL
127
+ Revdev::REL_CNT.times do |i|
128
+ if touchpad_rels.include?(i)
129
+ puts "setting #{i} (#{Revdev::REVERSE_MAPS[:REL][i]})"
130
+ @file.ioctl UI_SET_RELBIT, i
131
+ else
132
+ puts "skipping #{i} (#{Revdev::REVERSE_MAPS[:REL][i]})"
133
+ end
134
+ end
135
+
136
+ @file.ioctl UI_SET_EVBIT, Revdev::EV_REP
137
+
138
+ touchpad_mscs = [
139
+ 0x05 # define MSC_TIMESTAMP 0x05
140
+ ]
141
+ @file.ioctl UI_SET_EVBIT, Revdev::EV_MSC
142
+ Revdev::MSC_CNT.times do |i|
143
+ if touchpad_mscs.include?(i)
144
+ # puts "setting #{i} (#{Revdev::REVERSE_MAPS[:MSC][i]})"
145
+ @file.ioctl UI_SET_MSCBIT, i
146
+ else
147
+ # puts "skipping #{i} (#{Revdev::REVERSE_MAPS[:MSC][i]})"
148
+ end
149
+ end
150
+ end
151
+ end
152
+
153
+ class Revdev::EventDevice
154
+ def absinfo_for_axis(abs)
155
+ data = read_ioctl_with(eviocgabs(abs))
156
+
157
+ {
158
+ value: data[0, 4].unpack1("l<"),
159
+ absmin: data[4, 4].unpack1("l<"),
160
+ absmax: data[8, 4].unpack1("l<"),
161
+ absfuzz: data[12, 4].unpack1("l<"),
162
+ absflat: data[16, 4].unpack1("l<"),
163
+ resolution: data[20, 4].unpack1("l<")
164
+ }
165
+ end
166
+
167
+ # FIXME: undefined constants in revdev
168
+ def eviocgabs(abs)
169
+ # #define EVIOCGABS(abs) _IOR('E', 0x40 + abs, struct input_absinfo)
170
+ 0x80404540 + abs # EVIOCGABS(abs)
171
+ end
172
+ end
@@ -3,7 +3,7 @@
3
3
  module Fusuma
4
4
  module Plugin
5
5
  module Remap
6
- VERSION = "0.3.1"
6
+ VERSION = "0.4.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.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iberianpig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-04 00:00:00.000000000 Z
11
+ date: 2024-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fusuma
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
19
+ version: '3.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.1'
26
+ version: '3.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fusuma-plugin-keypress
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0.5'
33
+ version: 0.11.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0.5'
40
+ version: 0.11.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: msgpack
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -90,6 +90,7 @@ email:
90
90
  - yhkyky@gmail.com
91
91
  executables:
92
92
  - fusuma-remap
93
+ - fusuma-touchpad-remap
93
94
  extensions: []
94
95
  extra_rdoc_files: []
95
96
  files:
@@ -98,13 +99,18 @@ files:
98
99
  - bin/console
99
100
  - bin/setup
100
101
  - exe/fusuma-remap
102
+ - exe/fusuma-touchpad-remap
101
103
  - fusuma-plugin-remap.gemspec
102
104
  - lib/fusuma/plugin/inputs/remap_keyboard_input.rb
103
105
  - lib/fusuma/plugin/inputs/remap_keyboard_input.yml
106
+ - lib/fusuma/plugin/inputs/remap_touchpad_input.rb
107
+ - lib/fusuma/plugin/inputs/remap_touchpad_input.yml
104
108
  - lib/fusuma/plugin/remap.rb
109
+ - lib/fusuma/plugin/remap/keyboard_remapper.rb
105
110
  - lib/fusuma/plugin/remap/layer_manager.rb
106
- - lib/fusuma/plugin/remap/remapper.rb
107
- - lib/fusuma/plugin/remap/ruinput_device_patched.rb
111
+ - lib/fusuma/plugin/remap/touchpad_remapper.rb
112
+ - lib/fusuma/plugin/remap/uinput_keyboard.rb
113
+ - lib/fusuma/plugin/remap/uinput_touchpad.rb
108
114
  - lib/fusuma/plugin/remap/version.rb
109
115
  homepage: https://github.com/iberianpig/fusuma-plugin-remap
110
116
  licenses:
@@ -126,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
132
  - !ruby/object:Gem::Version
127
133
  version: '0'
128
134
  requirements: []
129
- rubygems_version: 3.4.10
135
+ rubygems_version: 3.4.19
130
136
  signing_key:
131
137
  specification_version: 4
132
138
  summary: A Fusuma plugin for remapping keyboard events into virtual input devices.
@@ -1,49 +0,0 @@
1
- require "ruinput"
2
-
3
- class RuinputDevicePatched < Ruinput::UinputDevice
4
- include Ruinput
5
- def set_all_events
6
- raise "invalid method call: this uinput is already created" if @is_created
7
-
8
- mouse_btns = [
9
- Revdev::BTN_0,
10
- Revdev::BTN_MISC,
11
- Revdev::BTN_1,
12
- Revdev::BTN_2,
13
- Revdev::BTN_3,
14
- Revdev::BTN_4,
15
- Revdev::BTN_5,
16
- Revdev::BTN_6,
17
- Revdev::BTN_7,
18
- Revdev::BTN_8,
19
- Revdev::BTN_9,
20
- Revdev::BTN_LEFT,
21
- Revdev::BTN_MOUSE,
22
- Revdev::BTN_MIDDLE,
23
- Revdev::BTN_RIGHT
24
- ].freeze
25
-
26
- keyboard_keys = Revdev.constants.select { |c| c.start_with? "KEY_" }.map { |c| Revdev.const_get(c) }.freeze
27
-
28
- @file.ioctl UI_SET_EVBIT, Revdev::EV_KEY
29
- (Revdev::KEY_RESERVED...Revdev::KEY_CNT).each do |n|
30
- # https://github.com/mooz/xkeysnail/pull/101/files
31
- next unless keyboard_keys.include?(n) || mouse_btns.include?(n)
32
-
33
- @file.ioctl UI_SET_KEYBIT, n
34
- end
35
-
36
- # @file.ioctl UI_SET_EVBIT, Revdev::EV_MSC
37
- # Revdev::MSC_CNT.times do |i|
38
- # @file.ioctl UI_SET_MSCBIT, i
39
- # end
40
-
41
- # kernel bug: device has min == max on ABS_Y
42
- # @file.ioctl UI_SET_EVBIT, Revdev::EV_ABS
43
- # Revdev::ABS_CNT.times do |i|
44
- # @file.ioctl UI_SET_ABSBIT, i
45
- # end
46
-
47
- @file.ioctl UI_SET_EVBIT, Revdev::EV_REP
48
- end
49
- end