rwm 0.0.1.alpha.1
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.
- data/bin/rwm +38 -0
- data/lib/rwm.rb +41 -0
- data/lib/rwm/extensions.rb +66 -0
- data/lib/rwm/x11.rb +61 -0
- data/lib/rwm/x11/c.rb +31 -0
- data/lib/rwm/x11/c/functions.rb +45 -0
- data/lib/rwm/x11/c/types.rb +647 -0
- data/lib/rwm/x11/events.rb +472 -0
- data/lib/rwm/x11/masks.rb +64 -0
- data/lib/rwm/x11/types.rb +227 -0
- metadata +89 -0
@@ -0,0 +1,472 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
3
|
+
#
|
4
|
+
# This file is part of rwm.
|
5
|
+
#
|
6
|
+
# rwm is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# rwm is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with rwm. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
module X11
|
21
|
+
module Events
|
22
|
+
class Helper
|
23
|
+
def self.attribute (which)
|
24
|
+
@__attribute__ = which.to_s.to_sym
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.attach_method (meth, &block)
|
28
|
+
return unless block_given?
|
29
|
+
|
30
|
+
class_eval {
|
31
|
+
define_method(meth, &block)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.manage (attr, *args)
|
36
|
+
if attr.is_a?(Array)
|
37
|
+
original, new = attr[0, 2]
|
38
|
+
else
|
39
|
+
original, new = [attr] * 2
|
40
|
+
end
|
41
|
+
attribute = @__attribute__
|
42
|
+
args.flatten!
|
43
|
+
|
44
|
+
case args.size
|
45
|
+
when 0
|
46
|
+
attach_method(new) {
|
47
|
+
struct[attribute][original]
|
48
|
+
}
|
49
|
+
|
50
|
+
attach_method("#{new}=") {|x|
|
51
|
+
struct[attribute][original] = x
|
52
|
+
}
|
53
|
+
when 1
|
54
|
+
if args.first.is_a?(Class)
|
55
|
+
attach_method(new) {
|
56
|
+
args.first.new(struct[attribute][original])
|
57
|
+
}
|
58
|
+
|
59
|
+
attach_method("#{new}=") {|x|
|
60
|
+
struct[attribute][original] = x.to_c
|
61
|
+
}
|
62
|
+
else
|
63
|
+
manage([original, new], args.first, nil)
|
64
|
+
end
|
65
|
+
when 2
|
66
|
+
attach_method(new) {
|
67
|
+
self.instance_exec(struct[attribute][original], &args[0])
|
68
|
+
} if args[0]
|
69
|
+
|
70
|
+
attach_method("#{new}=") {|x|
|
71
|
+
struct[attribute][original] = self.instance_exec(x, &args[1])
|
72
|
+
} if args[1]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def initialize (struct)
|
77
|
+
@struct = struct
|
78
|
+
end
|
79
|
+
|
80
|
+
def struct
|
81
|
+
@struct
|
82
|
+
end
|
83
|
+
alias to_c struct
|
84
|
+
end
|
85
|
+
|
86
|
+
Window = [lambda {|w|
|
87
|
+
X11::Window.new(self.display, w)
|
88
|
+
}, lambda(&:to_c)]
|
89
|
+
|
90
|
+
module Common
|
91
|
+
def self.included (klass)
|
92
|
+
klass.class_eval {
|
93
|
+
manage :serial
|
94
|
+
manage [:send_event, :send_event?]
|
95
|
+
manage :display, Display
|
96
|
+
manage :window, Window
|
97
|
+
}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class Any < Helper
|
102
|
+
attribute :xany
|
103
|
+
include Common
|
104
|
+
end
|
105
|
+
|
106
|
+
class Key < Helper
|
107
|
+
attribute :xkey
|
108
|
+
include Common
|
109
|
+
|
110
|
+
manage :root, Window
|
111
|
+
manage :subwindow, Window
|
112
|
+
manage :time
|
113
|
+
manage :x
|
114
|
+
manage :y
|
115
|
+
manage :x_root
|
116
|
+
manage :y_root
|
117
|
+
manage :state
|
118
|
+
manage :keycode
|
119
|
+
manage [:same_screen, :same_screen?]
|
120
|
+
end
|
121
|
+
|
122
|
+
class KeyPress < Key
|
123
|
+
end
|
124
|
+
|
125
|
+
class KeyRelease < Key
|
126
|
+
end
|
127
|
+
|
128
|
+
class Button < Helper
|
129
|
+
attribute :xbutton
|
130
|
+
include Common
|
131
|
+
|
132
|
+
manage :root, Window
|
133
|
+
manage :subwindow, Window
|
134
|
+
manage :time
|
135
|
+
manage :x
|
136
|
+
manage :y
|
137
|
+
manage :x_root
|
138
|
+
manage :y_root
|
139
|
+
manage :state
|
140
|
+
manage :button
|
141
|
+
manage [:same_screen, :same_screen?]
|
142
|
+
end
|
143
|
+
|
144
|
+
class ButtonPress < Button
|
145
|
+
end
|
146
|
+
|
147
|
+
class ButtonRelease < Button
|
148
|
+
end
|
149
|
+
|
150
|
+
class MotionNotify < Helper
|
151
|
+
attribute :xmotion
|
152
|
+
include Common
|
153
|
+
|
154
|
+
manage :root, Window
|
155
|
+
manage :subwindow, Window
|
156
|
+
manage :time
|
157
|
+
manage :x
|
158
|
+
manage :y
|
159
|
+
manage :x_root
|
160
|
+
manage :y_root
|
161
|
+
manage :state
|
162
|
+
manage :is_hint
|
163
|
+
manage [:same_screen, :same_screen?]
|
164
|
+
end
|
165
|
+
|
166
|
+
class EnterNotify < Helper
|
167
|
+
attribute :xcrossing
|
168
|
+
end
|
169
|
+
|
170
|
+
class LeaveNotify < Helper
|
171
|
+
attribute :xcrossing
|
172
|
+
include Common
|
173
|
+
|
174
|
+
manage :root, Window
|
175
|
+
manage :subwindow, Window
|
176
|
+
manage :time
|
177
|
+
manage :x
|
178
|
+
manage :y
|
179
|
+
manage :x_root
|
180
|
+
manage :y_root
|
181
|
+
manage :mode
|
182
|
+
manage :detail
|
183
|
+
end
|
184
|
+
|
185
|
+
class Focus < Helper
|
186
|
+
attribute :xfocus
|
187
|
+
include Common
|
188
|
+
|
189
|
+
manage :mode
|
190
|
+
manage :detail
|
191
|
+
end
|
192
|
+
|
193
|
+
class FocusIn < Focus
|
194
|
+
end
|
195
|
+
|
196
|
+
class FocusOut < Focus
|
197
|
+
end
|
198
|
+
|
199
|
+
class KeymapNotify < Helper
|
200
|
+
attribute :xkeymap
|
201
|
+
include Common
|
202
|
+
|
203
|
+
manage :key_vector, lambda {|v|
|
204
|
+
v.to_a
|
205
|
+
}, lambda {|v|
|
206
|
+
v = v.join if v.is_a?(Array)
|
207
|
+
FFI::MemoryPointer.from_string(v[0, 32])
|
208
|
+
}
|
209
|
+
end
|
210
|
+
|
211
|
+
class Expose < Helper
|
212
|
+
attribute :xexpose
|
213
|
+
include Common
|
214
|
+
|
215
|
+
manage :x
|
216
|
+
manage :y
|
217
|
+
manage :width
|
218
|
+
manage :height
|
219
|
+
manage :count
|
220
|
+
end
|
221
|
+
|
222
|
+
class GraphicsExpose < Helper
|
223
|
+
attribute :xgraphicsexpose
|
224
|
+
include Common
|
225
|
+
|
226
|
+
manage :x
|
227
|
+
manage :y
|
228
|
+
manage :width
|
229
|
+
manage :height
|
230
|
+
manage :count
|
231
|
+
manage :major_code
|
232
|
+
manage :minor_code
|
233
|
+
end
|
234
|
+
|
235
|
+
class NoExpose < Helper
|
236
|
+
attribute :xnoexpose
|
237
|
+
|
238
|
+
manage :serial
|
239
|
+
manage [:send_event, :send_event?]
|
240
|
+
manage :display
|
241
|
+
manage :drawable
|
242
|
+
manage :major_code
|
243
|
+
manage :minor_code
|
244
|
+
end
|
245
|
+
|
246
|
+
class VisibilityNotify < Helper
|
247
|
+
attribute :xvisibility
|
248
|
+
include Common
|
249
|
+
|
250
|
+
manage :state
|
251
|
+
end
|
252
|
+
|
253
|
+
class CreateNotify < Helper
|
254
|
+
attribute :xcreatewindow
|
255
|
+
include Common
|
256
|
+
|
257
|
+
manage :parent, Window
|
258
|
+
manage :x
|
259
|
+
manage :y
|
260
|
+
manage :width
|
261
|
+
manage :height
|
262
|
+
manage :border_width
|
263
|
+
manage [:override_redirect, :override_redirect?]
|
264
|
+
end
|
265
|
+
|
266
|
+
class DestroyNotify < Helper
|
267
|
+
attribute :xdestroywindow
|
268
|
+
include Common
|
269
|
+
|
270
|
+
manage :event, Window
|
271
|
+
end
|
272
|
+
|
273
|
+
class UnmapNotify < Helper
|
274
|
+
attribute :xunmap
|
275
|
+
include Common
|
276
|
+
|
277
|
+
manage :event, Window
|
278
|
+
manage [:from_configure, :from_configure?]
|
279
|
+
end
|
280
|
+
|
281
|
+
class MapNotify < Helper
|
282
|
+
attribute :xmap
|
283
|
+
include Common
|
284
|
+
|
285
|
+
manage :event, Window
|
286
|
+
manage [:override_redirect, :override_redirect?]
|
287
|
+
end
|
288
|
+
|
289
|
+
class MapRequest < Helper
|
290
|
+
attribute :xmaprequest
|
291
|
+
include Common
|
292
|
+
|
293
|
+
manage :parent, Window
|
294
|
+
end
|
295
|
+
|
296
|
+
class ReparentNotify < Helper
|
297
|
+
attribute :xreparent
|
298
|
+
include Common
|
299
|
+
|
300
|
+
manage :event, Window
|
301
|
+
manage :parent, Window
|
302
|
+
manage :x
|
303
|
+
manage :y
|
304
|
+
manage [:override_redirect, :override_redirect?]
|
305
|
+
end
|
306
|
+
|
307
|
+
class ConfigureNotify < Helper
|
308
|
+
attribute :xconfigure
|
309
|
+
include Common
|
310
|
+
|
311
|
+
manage :event, Window
|
312
|
+
manage :x
|
313
|
+
manage :y
|
314
|
+
manage :width
|
315
|
+
manage :height
|
316
|
+
manage :border_width
|
317
|
+
manage :above, Window
|
318
|
+
manage [:override_redirect, :override_redirect?]
|
319
|
+
end
|
320
|
+
|
321
|
+
class ConfigureRequest < Helper
|
322
|
+
attribute :xconfigurerequest
|
323
|
+
include Common
|
324
|
+
|
325
|
+
manage :parent, Window
|
326
|
+
manage :x
|
327
|
+
manage :y
|
328
|
+
manage :width
|
329
|
+
manage :height
|
330
|
+
manage :border_width
|
331
|
+
manage :above, Window
|
332
|
+
manage :detail
|
333
|
+
manage :value_mask
|
334
|
+
end
|
335
|
+
|
336
|
+
class GravityNotify < Helper
|
337
|
+
attribute :xgravity
|
338
|
+
include Common
|
339
|
+
|
340
|
+
manage :event, Window
|
341
|
+
manage :x
|
342
|
+
manage :y
|
343
|
+
end
|
344
|
+
|
345
|
+
class ResizeRequest < Helper
|
346
|
+
attribute :xresizerequest
|
347
|
+
include Common
|
348
|
+
|
349
|
+
manage :width
|
350
|
+
manage :height
|
351
|
+
end
|
352
|
+
|
353
|
+
class CirculateNotify < Helper
|
354
|
+
attribute :xcirculate
|
355
|
+
include Common
|
356
|
+
|
357
|
+
manage :event, Window
|
358
|
+
manage :place
|
359
|
+
end
|
360
|
+
|
361
|
+
class CirculateRequest < Helper
|
362
|
+
attribute :xcirculaterequest
|
363
|
+
include Common
|
364
|
+
|
365
|
+
manage :event, Window
|
366
|
+
manage :place
|
367
|
+
end
|
368
|
+
|
369
|
+
class PropertyNotify < Helper
|
370
|
+
attribute :xproperty
|
371
|
+
include Common
|
372
|
+
|
373
|
+
manage :atom
|
374
|
+
manage :time
|
375
|
+
manage :state
|
376
|
+
end
|
377
|
+
|
378
|
+
class SelectionClear < Helper
|
379
|
+
attribute :xselectionclear
|
380
|
+
include Common
|
381
|
+
|
382
|
+
manage :selection
|
383
|
+
manage :time
|
384
|
+
end
|
385
|
+
|
386
|
+
class SelectionRequest < Helper
|
387
|
+
attribute :xselectionrequest
|
388
|
+
|
389
|
+
manage :serial
|
390
|
+
manage [:send_event, :send_event?]
|
391
|
+
manage :display, Display
|
392
|
+
manage :owner, Window
|
393
|
+
manage :requestor, Window
|
394
|
+
manage :selection
|
395
|
+
manage :target
|
396
|
+
manage :property
|
397
|
+
manage :time
|
398
|
+
end
|
399
|
+
|
400
|
+
class SelectionNotify < Helper
|
401
|
+
attribute :xselection
|
402
|
+
|
403
|
+
manage :serial
|
404
|
+
manage [:send_event, :send_event?]
|
405
|
+
manage :display, Display
|
406
|
+
manage :requestor, Window
|
407
|
+
manage :selection
|
408
|
+
manage :target
|
409
|
+
manage :property
|
410
|
+
manage :time
|
411
|
+
end
|
412
|
+
|
413
|
+
class ColormapNotify < Helper
|
414
|
+
attribute :xcolormap
|
415
|
+
include Common
|
416
|
+
|
417
|
+
manage :colormap
|
418
|
+
manage [:new, :c_new]
|
419
|
+
manage :state
|
420
|
+
end
|
421
|
+
|
422
|
+
class ClientMessage < Helper
|
423
|
+
attribute :xclient
|
424
|
+
include Common
|
425
|
+
|
426
|
+
manage :message_type
|
427
|
+
manage :format
|
428
|
+
manage :data, lambda {|x|x}, false
|
429
|
+
end
|
430
|
+
|
431
|
+
class MappingNotify < Helper
|
432
|
+
attribute :xmapping
|
433
|
+
include Common
|
434
|
+
|
435
|
+
manage :request
|
436
|
+
manage :first_keycode
|
437
|
+
manage :count
|
438
|
+
end
|
439
|
+
|
440
|
+
class GenericEvent < Helper
|
441
|
+
attribute :xgeneric
|
442
|
+
|
443
|
+
manage :display, Display
|
444
|
+
manage :resourceid
|
445
|
+
manage :serial
|
446
|
+
manage :error_code
|
447
|
+
manage :request_code
|
448
|
+
manage :minor_code
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
class Event
|
453
|
+
include Events
|
454
|
+
|
455
|
+
TYPE2EVENT = [nil, Any, KeyPress, KeyRelease, ButtonPress, ButtonRelease,
|
456
|
+
MotionNotify, EnterNotify, LeaveNotify, FocusIn, FocusOut, KeymapNotify,
|
457
|
+
Expose, GraphicsExpose, NoExpose, VisibilityNotify, CreateNotify,
|
458
|
+
DestroyNotify, UnmapNotify, MapNotify, MapRequest, ReparentNotify,
|
459
|
+
ConfigureNotify, ResizeRequest, CirculateNotify, CirculateRequest,
|
460
|
+
PropertyNotify, SelectionClear, SelectionRequest, SelectionNotify,
|
461
|
+
ColormapNotify, ClientMessage, MappingNotify, GenericEvent]
|
462
|
+
|
463
|
+
def self.index (event)
|
464
|
+
TYPE2EVENT.index(event)
|
465
|
+
end
|
466
|
+
|
467
|
+
def self.new (event)
|
468
|
+
event = event.typecast(C::XEvent) unless event.is_a?(C::XEvent)
|
469
|
+
(TYPE2EVENT[event[:type]] || Any).new(event)
|
470
|
+
end
|
471
|
+
end
|
472
|
+
end
|