xlib-objects 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/event/mask.rb ADDED
@@ -0,0 +1,17 @@
1
+ module XlibObj
2
+ class Event::Mask
3
+ def initialize
4
+ @mask = 0
5
+ end
6
+
7
+ attr_reader :mask
8
+
9
+ def add(mask)
10
+ @mask |= mask
11
+ end
12
+
13
+ def subtract(mask)
14
+ @mask &= ~mask
15
+ end
16
+ end
17
+ end
data/lib/extension.rb ADDED
@@ -0,0 +1,85 @@
1
+ module XlibObj
2
+ class Extension
3
+ class << self
4
+ def for(display, name)
5
+ class_for(name).new(display, name)
6
+ end
7
+
8
+ private
9
+
10
+ def class_for(name)
11
+ case name
12
+ when 'CORE' then Core
13
+ when 'RANDR' then XRR
14
+ when 'XInputExtension' then XI
15
+ else self
16
+ end
17
+ end
18
+ end
19
+
20
+ def initialize(display, name)
21
+ @display = display
22
+ @name = name
23
+ @event_masks = Hash.new{ |hash, key| hash[key] = Event::Mask.new }
24
+ @attributes = Xlib::X.query_extension(@display, @name) || {}
25
+ end
26
+
27
+ attr_reader :display, :name
28
+
29
+ def exists?
30
+ not opcode.nil?
31
+ end
32
+
33
+ def opcode
34
+ @attributes[:opcode]
35
+ end
36
+
37
+ def first_event
38
+ @attributes[:first_event]
39
+ end
40
+
41
+ def last_event
42
+ first_event
43
+ end
44
+
45
+ def event_range
46
+ first_event..last_event
47
+ end
48
+
49
+ def first_error
50
+ @attributes[:first_error]
51
+ end
52
+
53
+ def last_error
54
+ first_error
55
+ end
56
+
57
+ def error_range
58
+ first_error..last_error
59
+ end
60
+
61
+ def event(xevent)
62
+ self.class::Event.new(self, xevent) if self.class.const_defined? :Event
63
+ end
64
+
65
+ def select_mask(window, mask)
66
+ modify_mask(window, :add, mask)
67
+ end
68
+
69
+ def deselect_mask(window, mask)
70
+ modify_mask(window, :subtract, mask)
71
+ end
72
+
73
+ def handles_event_mask?(mask)
74
+ !!(self.class::Event::MASKS[mask] if self.class.const_defined?(:Event))
75
+ end
76
+
77
+ private
78
+
79
+ def modify_mask(window, modification, mask)
80
+ bit = self.class::Event::MASKS[mask]
81
+ bit_mask = @event_masks[window.id].__send__(modification, bit)
82
+ select_input(@display, window, bit_mask)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,33 @@
1
+ module XlibObj
2
+ class Extension::Core < Extension
3
+ def exists?
4
+ true
5
+ end
6
+
7
+ def opcode
8
+ 0..127
9
+ end
10
+
11
+ def first_event
12
+ 2
13
+ end
14
+
15
+ def last_event
16
+ Xlib::LASTEvent-1
17
+ end
18
+
19
+ def first_error
20
+ 0
21
+ end
22
+
23
+ def last_error
24
+ 127
25
+ end
26
+
27
+ private
28
+
29
+ def select_input(display, window, bit_mask)
30
+ Xlib::X.select_input(display, window, bit_mask)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,139 @@
1
+ #
2
+ # Copyright (c) 2014 Christopher Aue <mail@christopheraue.net>
3
+ #
4
+ # This file is part of the ruby xlib-objects gem. It is subject to the license
5
+ # terms in the LICENSE file found in the top-level directory of this
6
+ # distribution and at http://github.com/christopheraue/ruby-xlib-objects.
7
+ #
8
+
9
+ module XlibObj
10
+ class Extension::Core
11
+ class Event
12
+ def initialize(extension, event)
13
+ @extension = extension
14
+ @struct ||= begin
15
+ type = event[:type]
16
+ union_member = self.class::TYPE_TO_UNION_MEMBER[type]
17
+ event[union_member]
18
+ end
19
+ end
20
+
21
+ def handle
22
+ window_id = event || parent || window || owner || requestor
23
+ Window.new(@extension.display, window_id).handle(self)
24
+ end
25
+
26
+ def name
27
+ TYPES.key(type)
28
+ end
29
+
30
+ def method_missing(name)
31
+ @struct.members.include?(name) ? @struct[name] : nil
32
+ end
33
+
34
+ MASKS = {
35
+ no_event: Xlib::NoEventMask,
36
+ key_press: Xlib::KeyPressMask,
37
+ key_release: Xlib::KeyReleaseMask,
38
+ button_press: Xlib::ButtonPressMask,
39
+ button_release: Xlib::ButtonReleaseMask,
40
+ enter_window: Xlib::EnterWindowMask,
41
+ leave_window: Xlib::LeaveWindowMask,
42
+ pointer_motion: Xlib::PointerMotionMask,
43
+ pointer_motion_hint: Xlib::PointerMotionHintMask,
44
+ button1_motion: Xlib::Button1MotionMask,
45
+ button2_motion: Xlib::Button2MotionMask,
46
+ button3_motion: Xlib::Button3MotionMask,
47
+ button4_motion: Xlib::Button4MotionMask,
48
+ button5_motion: Xlib::Button5MotionMask,
49
+ button_motion: Xlib::ButtonMotionMask,
50
+ keymap_state: Xlib::KeymapStateMask,
51
+ exposure: Xlib::ExposureMask,
52
+ visibility_change: Xlib::VisibilityChangeMask,
53
+ structure_notify: Xlib::StructureNotifyMask,
54
+ resize_redirect: Xlib::ResizeRedirectMask,
55
+ substructure_notify: Xlib::SubstructureNotifyMask,
56
+ substructure_redirect: Xlib::SubstructureRedirectMask,
57
+ focus_change: Xlib::FocusChangeMask,
58
+ property_change: Xlib::PropertyChangeMask,
59
+ colormap_change: Xlib::ColormapChangeMask,
60
+ owner_grab_button: Xlib::OwnerGrabButtonMask
61
+ }
62
+
63
+ TYPES = {
64
+ key_press: Xlib::KeyPress,
65
+ key_release: Xlib::KeyRelease,
66
+ button_press: Xlib::ButtonPress,
67
+ button_release: Xlib::ButtonRelease,
68
+ motion_notify: Xlib::MotionNotify,
69
+ enter_notify: Xlib::EnterNotify,
70
+ leave_notify: Xlib::LeaveNotify,
71
+ focus_in: Xlib::FocusIn,
72
+ focus_out: Xlib::FocusOut,
73
+ keymap_notify: Xlib::KeymapNotify,
74
+ expose: Xlib::Expose,
75
+ graphics_expose: Xlib::GraphicsExpose,
76
+ no_expose: Xlib::NoExpose,
77
+ visibility_notify: Xlib::VisibilityNotify,
78
+ create_notify: Xlib::CreateNotify,
79
+ destroy_notify: Xlib::DestroyNotify,
80
+ unmap_notify: Xlib::UnmapNotify,
81
+ map_notify: Xlib::MapNotify,
82
+ map_request: Xlib::MapRequest,
83
+ reparent_notify: Xlib::ReparentNotify,
84
+ configure_notify: Xlib::ConfigureNotify,
85
+ configure_request: Xlib::ConfigureRequest,
86
+ gravity_notify: Xlib::GravityNotify,
87
+ resize_request: Xlib::ResizeRequest,
88
+ circulate_notify: Xlib::CirculateNotify,
89
+ circulate_request: Xlib::CirculateRequest,
90
+ property_notify: Xlib::PropertyNotify,
91
+ selection_clear: Xlib::SelectionClear,
92
+ selection_request: Xlib::SelectionRequest,
93
+ selection_notify: Xlib::SelectionNotify,
94
+ colormap_notify: Xlib::ColormapNotify,
95
+ client_message: Xlib::ClientMessage,
96
+ mapping_notify: Xlib::MappingNotify,
97
+ generic_event: Xlib::GenericEvent,
98
+ last_event: Xlib::LASTEvent
99
+ }
100
+
101
+ TYPE_TO_UNION_MEMBER = {
102
+ Xlib::KeyPress => :xkey,
103
+ Xlib::KeyRelease => :xkey,
104
+ Xlib::ButtonPress => :xbutton,
105
+ Xlib::ButtonRelease => :xbutton,
106
+ Xlib::MotionNotify => :xmotion,
107
+ Xlib::EnterNotify => :xcrossing,
108
+ Xlib::LeaveNotify => :xcrossing,
109
+ Xlib::FocusIn => :xfocus,
110
+ Xlib::FocusOut => :xfocus,
111
+ Xlib::KeymapNotify => :xkeymap,
112
+ Xlib::Expose => :xexpose,
113
+ Xlib::GraphicsExpose => :xgraphicsexpose,
114
+ Xlib::NoExpose => :xnoexpose,
115
+ Xlib::VisibilityNotify => :xvisibility,
116
+ Xlib::CreateNotify => :xcreatewindow,
117
+ Xlib::DestroyNotify => :xdestroywindow,
118
+ Xlib::UnmapNotify => :xunmap,
119
+ Xlib::MapNotify => :xmap,
120
+ Xlib::MapRequest => :xmaprequest,
121
+ Xlib::ReparentNotify => :xreparent,
122
+ Xlib::ConfigureNotify => :xconfigure,
123
+ Xlib::ConfigureRequest => :xconfigurerequest,
124
+ Xlib::GravityNotify => :xgravity,
125
+ Xlib::ResizeRequest => :xresizerequest,
126
+ Xlib::CirculateNotify => :xcirculate,
127
+ Xlib::CirculateRequest => :xcirculaterequest,
128
+ Xlib::PropertyNotify => :xproperty,
129
+ Xlib::SelectionClear => :xselectionclear,
130
+ Xlib::SelectionRequest => :xselectionrequest,
131
+ Xlib::SelectionNotify => :xselection,
132
+ Xlib::ColormapNotify => :xcolormap,
133
+ Xlib::ClientMessage => :xclient,
134
+ Xlib::MappingNotify => :xmapping,
135
+ Xlib::GenericEvent => :xgeneric
136
+ }
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,9 @@
1
+ module XlibObj
2
+ class Extension::XI < Extension
3
+ private
4
+
5
+ def select_input(display, window, bit_mask)
6
+ Xlib::XI.select_events(display, display.input_devices.reject(&:master?), window, bit_mask)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,109 @@
1
+ module XlibObj
2
+ class Extension::XI
3
+ class Event
4
+ def initialize(extension, event)
5
+ @extension = extension
6
+ @struct = self.class::TYPE_TO_STRUCT[event[:evtype]].new(event[:data])
7
+ end
8
+
9
+ def handle
10
+ Window.new(@extension.display, event).handle(self)
11
+ end
12
+
13
+ def name
14
+ TYPES.key(evtype)
15
+ end
16
+
17
+ def method_missing(name)
18
+ @struct.members.include?(name) ? @struct[name] : nil
19
+ end
20
+
21
+ MASKS = {
22
+ xi_device_changed: Xlib::XI_DeviceChangedMask,
23
+ xi_key_press: Xlib::XI_KeyPressMask,
24
+ xi_key_release: Xlib::XI_KeyReleaseMask,
25
+ xi_button_press: Xlib::XI_ButtonPressMask,
26
+ xi_button_release: Xlib::XI_ButtonReleaseMask,
27
+ xi_motion: Xlib::XI_MotionMask,
28
+ xi_enter: Xlib::XI_EnterMask,
29
+ xi_leave: Xlib::XI_LeaveMask,
30
+ xi_focus_in: Xlib::XI_FocusInMask,
31
+ xi_focus_out: Xlib::XI_FocusOutMask,
32
+ xi_hierarchy_changed: Xlib::XI_HierarchyChangedMask,
33
+ xi_property_event: Xlib::XI_PropertyEventMask,
34
+ xi_raw_key_press: Xlib::XI_RawKeyPressMask,
35
+ xi_raw_key_release: Xlib::XI_RawKeyReleaseMask,
36
+ xi_raw_button_press: Xlib::XI_RawButtonPressMask,
37
+ xi_raw_button_release: Xlib::XI_RawButtonReleaseMask,
38
+ xi_raw_motion: Xlib::XI_RawMotionMask,
39
+ xi_touch_begin: Xlib::XI_TouchBeginMask,
40
+ xi_touch_end: Xlib::XI_TouchEndMask,
41
+ xi_touch_ownership_changed: Xlib::XI_TouchOwnershipChangedMask,
42
+ xi_touch_update: Xlib::XI_TouchUpdateMask,
43
+ xi_raw_touch_begin: Xlib::XI_RawTouchBeginMask,
44
+ xi_raw_touch_end: Xlib::XI_RawTouchEndMask,
45
+ xi_raw_touch_update: Xlib::XI_RawTouchUpdateMask,
46
+ xi_barrier_hit: Xlib::XI_BarrierHitMask,
47
+ xi_barrier_leave: Xlib::XI_BarrierLeaveMask
48
+ }
49
+
50
+ TYPES = {
51
+ xi_device_changed: Xlib::XI_DeviceChanged,
52
+ xi_key_press: Xlib::XI_KeyPress,
53
+ xi_key_release: Xlib::XI_KeyRelease,
54
+ xi_button_press: Xlib::XI_ButtonPress,
55
+ xi_button_release: Xlib::XI_ButtonRelease,
56
+ xi_motion: Xlib::XI_Motion,
57
+ xi_enter: Xlib::XI_Enter,
58
+ xi_leave: Xlib::XI_Leave,
59
+ xi_focus_in: Xlib::XI_FocusIn,
60
+ xi_focus_out: Xlib::XI_FocusOut,
61
+ xi_hierarchy_changed: Xlib::XI_HierarchyChanged,
62
+ xi_property_event: Xlib::XI_PropertyEvent,
63
+ xi_raw_key_press: Xlib::XI_RawKeyPress,
64
+ xi_raw_key_release: Xlib::XI_RawKeyRelease,
65
+ xi_raw_button_press: Xlib::XI_RawButtonPress,
66
+ xi_raw_button_release: Xlib::XI_RawButtonRelease,
67
+ xi_raw_motion: Xlib::XI_RawMotion,
68
+ xi_touch_begin: Xlib::XI_TouchBegin,
69
+ xi_touch_end: Xlib::XI_TouchEnd,
70
+ xi_touch_ownership_changed: Xlib::XI_TouchOwnership,
71
+ xi_touch_update: Xlib::XI_TouchUpdate,
72
+ xi_raw_touch_begin: Xlib::XI_RawTouchBegin,
73
+ xi_raw_touch_end: Xlib::XI_RawTouchEnd,
74
+ xi_raw_touch_update: Xlib::XI_RawTouchUpdate,
75
+ xi_barrier_hit: Xlib::XI_BarrierHit,
76
+ xi_barrier_leave: Xlib::XI_BarrierLeave
77
+ }
78
+
79
+ TYPE_TO_STRUCT = {
80
+ Xlib::XI_DeviceChanged => Xlib::XIDeviceChangedEvent,
81
+ Xlib::XI_KeyPress => Xlib::XIDeviceEvent,
82
+ Xlib::XI_KeyRelease => Xlib::XIDeviceEvent,
83
+ Xlib::XI_ButtonPress => Xlib::XIDeviceEvent,
84
+ Xlib::XI_ButtonRelease => Xlib::XIDeviceEvent,
85
+ Xlib::XI_Motion => Xlib::XIDeviceEvent,
86
+ Xlib::XI_Enter => Xlib::XIEnterEvent,
87
+ Xlib::XI_Leave => Xlib::XILeaveEvent,
88
+ Xlib::XI_FocusIn => Xlib::XIFocusInEvent,
89
+ Xlib::XI_FocusOut => Xlib::XIFocusOutEvent,
90
+ Xlib::XI_HierarchyChanged => Xlib::XIHierarchyEvent,
91
+ Xlib::XI_PropertyEvent => Xlib::XIPropertyEvent,
92
+ Xlib::XI_RawKeyPress => Xlib::XIRawEvent,
93
+ Xlib::XI_RawKeyRelease => Xlib::XIRawEvent,
94
+ Xlib::XI_RawButtonPress => Xlib::XIRawEvent,
95
+ Xlib::XI_RawButtonRelease => Xlib::XIRawEvent,
96
+ Xlib::XI_RawMotion => Xlib::XIRawEvent,
97
+ Xlib::XI_TouchBegin => Xlib::XIDeviceEvent,
98
+ Xlib::XI_TouchEnd => Xlib::XIDeviceEvent,
99
+ Xlib::XI_TouchOwnership => Xlib::XITouchOwnershipEvent,
100
+ Xlib::XI_TouchUpdate => Xlib::XIDeviceEvent,
101
+ Xlib::XI_RawTouchBegin => Xlib::XIRawEvent,
102
+ Xlib::XI_RawTouchEnd => Xlib::XIRawEvent,
103
+ Xlib::XI_RawTouchUpdate => Xlib::XIRawEvent,
104
+ Xlib::XI_BarrierHit => Xlib::XIBarrierEvent,
105
+ Xlib::XI_BarrierLeave => Xlib::XIBarrierEvent
106
+ }
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,17 @@
1
+ module XlibObj
2
+ class Extension::XRR < Extension
3
+ def last_event
4
+ first_event + Xlib::RRNumberEvents-1
5
+ end
6
+
7
+ def last_error
8
+ first_error + Xlib::RRNumberErrors-1
9
+ end
10
+
11
+ private
12
+
13
+ def select_input(display, window, bit_mask)
14
+ Xlib::XRR.select_input(display, window, bit_mask)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,76 @@
1
+ #
2
+ # Copyright (c) 2014 Christopher Aue <mail@christopheraue.net>
3
+ #
4
+ # This file is part of the ruby xlib-objects gem. It is subject to the license
5
+ # terms in the LICENSE file found in the top-level directory of this
6
+ # distribution and at http://github.com/christopheraue/ruby-xlib-objects.
7
+ #
8
+
9
+ module XlibObj
10
+ class Extension::XRR
11
+ class Event
12
+ def initialize(extension, event)
13
+ @extension = extension
14
+ @xrr_type = event[:type] - extension.first_event
15
+
16
+ type_struct = TYPE_TO_STRUCT[@xrr_type].new(event.pointer)
17
+
18
+ @struct = if type_struct.members.include?(:subtype)
19
+ SUBTYPE_TO_STRUCT[type_struct[:subtype]].new(event.pointer)
20
+ else
21
+ type_struct
22
+ end
23
+ end
24
+
25
+ def handle
26
+ Window.new(@extension.display, window).handle(self)
27
+ end
28
+
29
+ def name
30
+ @name ||= subtype ? SUBTYPES.key(subtype) : TYPES.key(@xrr_type)
31
+ end
32
+
33
+ def method_missing(name)
34
+ @struct.members.include?(name) ? @struct[name] : nil
35
+ end
36
+
37
+ MASKS = {
38
+ screen_change_notify: Xlib::RRScreenChangeNotifyMask,
39
+ crtc_change_notify: Xlib::RRCrtcChangeNotifyMask,
40
+ output_change_notify: Xlib::RROutputChangeNotifyMask,
41
+ output_property_notify: Xlib::RROutputPropertyNotifyMask,
42
+ provider_change_notify: Xlib::RRProviderChangeNotifyMask,
43
+ provider_property_notify: Xlib::RRProviderPropertyNotifyMask,
44
+ resource_change_notify: Xlib::RRResourceChangeNotifyMask
45
+ }
46
+
47
+ TYPES = {
48
+ screen_change_notify: Xlib::RRScreenChangeNotify,
49
+ notify: Xlib::RRNotify
50
+ }
51
+
52
+ SUBTYPES = {
53
+ crtc_change_notify: Xlib::RRNotify_CrtcChange,
54
+ output_change_notify: Xlib::RRNotify_OutputChange,
55
+ output_property_notify: Xlib::RRNotify_OutputProperty,
56
+ provider_change_notify: Xlib::RRNotify_ProviderChange,
57
+ provider_property_notify: Xlib::RRNotify_ProviderProperty,
58
+ resource_change_notify: Xlib::RRNotify_ResourceChange
59
+ }
60
+
61
+ TYPE_TO_STRUCT = {
62
+ Xlib::RRScreenChangeNotify => Xlib::XRRScreenChangeNotifyEvent,
63
+ Xlib::RRNotify => Xlib::XRRNotifyEvent
64
+ }
65
+
66
+ SUBTYPE_TO_STRUCT = {
67
+ Xlib::RRNotify_CrtcChange => Xlib::XRRCrtcChangeNotifyEvent,
68
+ Xlib::RRNotify_OutputChange => Xlib::XRROutputChangeNotifyEvent,
69
+ Xlib::RRNotify_OutputProperty => Xlib::XRROutputPropertyNotifyEvent,
70
+ Xlib::RRNotify_ProviderChange => Xlib::XRRProviderChangeNotifyEvent,
71
+ Xlib::RRNotify_ProviderProperty => Xlib::XRRProviderPropertyNotifyEvent,
72
+ Xlib::RRNotify_ResourceChange => Xlib::XRRResourceChangeNotifyEvent
73
+ }
74
+ end
75
+ end
76
+ end