xinput_wrapper 0.6.1 → 0.7.0

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: 7685727622dac6285e86dcf8095525fde1d6d129b7f210aed3ad2512138efdaa
4
- data.tar.gz: f404c6286c440432f6b9ad26db6f8b6d36fc6e3ea0d6141baa439bf74c572e16
3
+ metadata.gz: af1558bd803a67895343a73b2001a42194b5402bc8998d410d9c388b4836a593
4
+ data.tar.gz: 63e171df3280f2385b404f82673037a2a69e47e758be649253dc6701bc61a089
5
5
  SHA512:
6
- metadata.gz: 9ce3aaf5e903c982201b1ac8802b109f8388083b0e9f0de02454811e4300069a043b84a6bdf66db2604c70dec57c3a0564747d908beadf2b0216d49e4b9b0dd2
7
- data.tar.gz: 9c2ae2545e99ba3d1a13789f5d7c24c11b15011f7a623169b1a7bfee9883a88091fcf9d182ead686df0564e9bdd384b0f8918f40f9a0374aca2f08c8a5533c1d
6
+ metadata.gz: 1874c64eed6da4e726bc9e2e8ae755e0e7e3162cce593db5109aa344210b10f414c4917daecd8e188a28287c4a1d13188b23912e42680354adcc114714476e6b
7
+ data.tar.gz: 9af8809d460ff318ff88fc6f49e310bff9ad612f8c800a9aceae0efe55d4a8f70f32cac93e704de837f6683cb09ef8a366b029d78283587bd1af6450b7246b33
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -14,10 +14,15 @@ require 'c32'
14
14
  MOTION = 6
15
15
  RAWKEY_PRESS = 13
16
16
  RAWKEY_RELEASE = 14
17
+ RAWBUTTON_PRESS = 15
18
+ RAWBUTTON_RELEASE = 16
19
+ BUTTONS = %i(left middle right scrollup scrolldown)
17
20
 
18
21
 
19
22
  class XInputWrapper
20
23
  using ColouredText
24
+
25
+ attr_accessor :stop
21
26
 
22
27
  # device list:
23
28
  # 3 = Virtual core keyboard
@@ -26,8 +31,11 @@ class XInputWrapper
26
31
  # 10 = USB Optical Mouse (locally attached)
27
32
  # 11 = Microsoft Wired Keyboard 600 (locally attached)
28
33
  #
29
- def initialize(device: nil, verbose: true, lookup: {}, debug: false )
34
+ def initialize(device: nil, verbose: true, lookup: {}, debug: false,
35
+ callback: nil )
30
36
 
37
+ @callback = callback
38
+
31
39
  # defaults to QWERTY keyboard layout
32
40
  @modifiers = {
33
41
  62 => :shift, # right control
@@ -97,16 +105,19 @@ class XInputWrapper
97
105
 
98
106
  def listen()
99
107
 
108
+ @stop = false
109
+
100
110
  command = "xinput test-xi2 --root #{@device}"
101
111
 
102
112
  type = 0
103
113
  raw_keys = []
104
114
  t1 = Time.now
105
- lines = []
115
+ lines = []
106
116
 
107
117
  IO.popen(command).each_line do |x|
108
118
 
109
- print "GOT ", x
119
+ break if @stop
120
+ #print "GOT ", x
110
121
  if x[/EVENT type \d \(Motion\)/] and (Time.now > (t1 + 0.06125)) then
111
122
 
112
123
  type = x[/EVENT type (\d+)/,1].to_i
@@ -118,19 +129,23 @@ class XInputWrapper
118
129
  x1, y1 = r.split('/').map(&:to_f)
119
130
  puts "x1: %s y1: %s" % [x1, y1] if @debug
120
131
  on_mousemove(x1, y1)
132
+ @callback.on_mousemove(x1, y1) if @callback
133
+ @mouse_pos = [x1,y1]
121
134
  t1 = Time.now
122
135
 
123
136
  end
124
137
 
125
138
  lines = [x]
126
139
 
127
- elsif x[/EVENT type \d+ \(RawKey(?:Release|Press)\)/]
140
+ elsif x[/EVENT type \d+ \(Raw(?:Key|Button)(?:Release|Press)\)/]
128
141
 
129
142
  type = x[/EVENT type (\d+)/,1].to_i
130
143
 
131
144
  lines = [x]
145
+
132
146
 
133
- elsif type == MOTION or type == RAWKEY_PRESS or type == RAWKEY_RELEASE
147
+ elsif [MOTION, RAWKEY_PRESS, RAWKEY_RELEASE, RAWBUTTON_PRESS,
148
+ RAWBUTTON_RELEASE].include? type
134
149
 
135
150
  lines << x
136
151
 
@@ -151,6 +166,23 @@ class XInputWrapper
151
166
  keycode = r.to_i if r
152
167
 
153
168
  type = lines.join[/EVENT type (\d+)/,1] .to_i
169
+
170
+
171
+ when RAWBUTTON_PRESS
172
+
173
+ r = lines.join[/detail: (\d+)/,1]
174
+
175
+ buttoncode = r.to_i if r
176
+
177
+ type = lines.join[/EVENT type (\d+)/,1] .to_i
178
+
179
+ when RAWBUTTON_RELEASE
180
+
181
+ r = lines.join[/detail: (\d+)/,1]
182
+
183
+ buttoncode = r.to_i if r
184
+
185
+ type = lines.join[/EVENT type (\d+)/,1] .to_i
154
186
 
155
187
  end
156
188
 
@@ -163,8 +195,9 @@ class XInputWrapper
163
195
  next
164
196
  end
165
197
 
166
- next unless keycode
198
+ next unless keycode or buttoncode
167
199
  puts 'keycode: ' + keycode.inspect if @debug
200
+ puts 'buttoncode: ' + buttoncode.inspect if @debug
168
201
 
169
202
  # type = 13 means a key has been pressed
170
203
  if type == RAWKEY_PRESS then
@@ -195,6 +228,7 @@ class XInputWrapper
195
228
 
196
229
  keystring = ((key.length > 1 or key == ' ') ? "{%s}" % key : key)
197
230
  block_given? ? yield(keystring) : on_key_press(keystring, keycode)
231
+ @callback.on_keypress(keystring, keycode) if @callback
198
232
 
199
233
  end
200
234
 
@@ -207,6 +241,7 @@ class XInputWrapper
207
241
  yield(format_key(keys.last, keys[0..-2]))
208
242
  else
209
243
  on_key_press(keys.last, keycode, keys[0..-2])
244
+ @callback.on_keypress(keys.last, keycode, keys[0..-2]) if @callback
210
245
  end
211
246
 
212
247
  raw_keys = []
@@ -234,12 +269,34 @@ class XInputWrapper
234
269
  name = "on_#{key}_key".to_sym
235
270
  method(name).call if self.protected_methods.include? name
236
271
  on_key_press(key, keycode)
272
+ @callback.on_keypress(key, keycode) if @callback
237
273
  end
238
274
  end
239
275
 
240
276
  index = raw_keys.rindex(keycode)
241
277
  raw_keys.delete_at index if index
242
-
278
+
279
+ elsif type == RAWBUTTON_PRESS
280
+
281
+ button = BUTTONS[buttoncode-1]
282
+
283
+ case button
284
+ when :scrollup
285
+ on_mouse_scrollup()
286
+ @callback.on_mouse_scrollup() if @callback
287
+ when :scrolldown
288
+ on_mouse_scrolldown()
289
+ @callback.on_mouse_scrolldown() if @callback
290
+ else
291
+ on_mousedown(button, *@mouse_pos)
292
+ @callback.on_mousedown(button, *@mouse_pos) if @callback
293
+ end
294
+
295
+ elsif type == RAWBUTTON_RELEASE
296
+
297
+ button = BUTTONS[buttoncode-1]
298
+ on_mouseup(BUTTONS[buttoncode-1], *@mouse_pos)
299
+
243
300
  end
244
301
 
245
302
  end
@@ -259,6 +316,14 @@ class XInputWrapper
259
316
 
260
317
  end
261
318
 
319
+ def on_mousedown(button, x,y)
320
+
321
+ if @debug then
322
+ puts "on_mousedown() %s click x: %s y: %s" % [button, x, y]
323
+ end
324
+
325
+ end
326
+
262
327
  def on_mousemove(x,y)
263
328
 
264
329
  if @debug then
@@ -266,6 +331,31 @@ class XInputWrapper
266
331
  end
267
332
 
268
333
  end
334
+
335
+ def on_mouseup(button, x,y)
336
+
337
+ if @debug then
338
+ puts "on_mousedown() %s click x: %s y: %s" % [button, x, y]
339
+ end
340
+
341
+ end
342
+
343
+ def on_mouse_scrolldown()
344
+
345
+ if @debug then
346
+ puts "on_mouse_scrolldown()"
347
+ end
348
+
349
+ end
350
+
351
+ def on_mouse_scrollup()
352
+
353
+ if @debug then
354
+ puts "on_mouse_scrollup()"
355
+ end
356
+
357
+ end
358
+
269
359
 
270
360
  def on_shift_key() end
271
361
  def on_super_key() end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xinput_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  B//EUqLB2VKtMmcrYMc2FfbLwllNLY4TRq+/lgVLoDb7oLHsiggYSLZS6lPBIQj/
36
36
  YnYsDKwN5siDA79sB0fqq2ml
37
37
  -----END CERTIFICATE-----
38
- date: 2020-08-03 00:00:00.000000000 Z
38
+ date: 2020-08-04 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: c32
metadata.gz.sig CHANGED
Binary file