x11 0.0.1a2 → 0.0.1a3

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.
Files changed (245) hide show
  1. data/lib/X11/X.rb +14 -9
  2. data/lib/X11/X/c.rb +21 -20
  3. data/lib/X11/XKBlib.rb +29 -0
  4. data/lib/X11/Xatom.rb +152 -136
  5. data/lib/X11/Xatom/c.rb +15 -15
  6. data/lib/X11/Xdefs.rb +7 -7
  7. data/lib/X11/Xdefs/c.rb +20 -20
  8. data/lib/X11/Xlib.rb +19 -7
  9. data/lib/X11/Xlib/c.rb +21 -8
  10. data/lib/X11/Xlib/c/functions.rb +373 -27
  11. data/lib/X11/Xlib/c/type/any_event.rb +13 -13
  12. data/lib/X11/Xlib/c/type/button_event.rb +23 -23
  13. data/lib/X11/Xlib/c/type/circulate_event.rb +15 -15
  14. data/lib/X11/Xlib/c/type/circulate_request_event.rb +15 -15
  15. data/lib/X11/Xlib/c/type/client_message_event.rb +22 -22
  16. data/lib/X11/Xlib/c/type/colormap_event.rb +16 -16
  17. data/lib/X11/Xlib/c/type/configure_event.rb +21 -21
  18. data/lib/X11/Xlib/c/type/configure_request_event.rb +22 -22
  19. data/lib/X11/Xlib/c/type/create_window_event.rb +20 -20
  20. data/lib/X11/Xlib/c/type/crossing_event.rb +25 -25
  21. data/lib/X11/Xlib/c/type/destroy_window_event.rb +14 -14
  22. data/lib/X11/Xlib/c/type/display.rb +52 -52
  23. data/lib/X11/Xlib/c/type/error_event.rb +15 -15
  24. data/lib/X11/Xlib/c/type/event.rb +43 -43
  25. data/lib/X11/Xlib/c/type/expose_event.rb +18 -18
  26. data/lib/X11/Xlib/c/type/focus_change_event.rb +15 -15
  27. data/lib/X11/Xlib/c/type/gc.rb +10 -10
  28. data/lib/X11/Xlib/c/type/gc_values.rb +54 -0
  29. data/lib/X11/Xlib/c/type/generic_event.rb +14 -14
  30. data/lib/X11/Xlib/c/type/generic_event_cookie.rb +16 -16
  31. data/lib/X11/Xlib/c/type/graphics_expose_event.rb +21 -21
  32. data/lib/X11/Xlib/c/type/gravity_event.rb +16 -16
  33. data/lib/X11/Xlib/c/type/image.rb +56 -0
  34. data/lib/X11/Xlib/c/type/key_event.rb +23 -23
  35. data/lib/X11/Xlib/c/type/key_sym.rb +15 -15
  36. data/lib/X11/Xlib/c/type/keymap_event.rb +14 -14
  37. data/lib/X11/Xlib/c/type/map_event.rb +15 -15
  38. data/lib/X11/Xlib/c/type/map_request_event.rb +18 -18
  39. data/lib/X11/Xlib/c/type/mapping_event.rb +16 -16
  40. data/lib/X11/Xlib/c/type/motion_event.rb +23 -23
  41. data/lib/X11/Xlib/c/type/no_expose_event.rb +15 -15
  42. data/lib/X11/Xlib/c/type/point.rb +33 -0
  43. data/lib/X11/Xlib/c/type/property_event.rb +16 -16
  44. data/lib/X11/Xlib/c/type/reparent_event.rb +18 -18
  45. data/lib/X11/Xlib/c/type/resize_request_event.rb +15 -15
  46. data/lib/X11/Xlib/c/type/screen.rb +27 -27
  47. data/lib/X11/Xlib/c/type/selection_clear_event.rb +15 -15
  48. data/lib/X11/Xlib/c/type/selection_event.rb +17 -17
  49. data/lib/X11/Xlib/c/type/selection_request_event.rb +18 -18
  50. data/lib/X11/Xlib/c/type/status.rb +15 -15
  51. data/lib/X11/Xlib/c/type/unmap_event.rb +15 -15
  52. data/lib/X11/Xlib/c/type/visibility_event.rb +14 -14
  53. data/lib/X11/Xlib/c/type/visual.rb +16 -16
  54. data/lib/X11/Xlib/c/type/window_attributes.rb +31 -31
  55. data/lib/X11/Xlib/c/types.rb +9 -7
  56. data/lib/X11/Xlib/display.rb +257 -174
  57. data/lib/X11/Xlib/display/extensions.rb +56 -0
  58. data/lib/X11/Xlib/drawable.rb +48 -0
  59. data/lib/X11/Xlib/error.rb +100 -0
  60. data/lib/X11/Xlib/event.rb +66 -37
  61. data/lib/X11/Xlib/event/any.rb +8 -10
  62. data/lib/X11/Xlib/event/button_press.rb +9 -20
  63. data/lib/X11/Xlib/event/button_release.rb +9 -20
  64. data/lib/X11/Xlib/event/circulate_notify.rb +11 -12
  65. data/lib/X11/Xlib/event/circulate_request.rb +11 -12
  66. data/lib/X11/Xlib/event/client_message.rb +11 -13
  67. data/lib/X11/Xlib/event/colormap_notify.rb +12 -13
  68. data/lib/X11/Xlib/event/configure_notify.rb +17 -18
  69. data/lib/X11/Xlib/event/configure_request.rb +18 -19
  70. data/lib/X11/Xlib/event/create_notify.rb +16 -17
  71. data/lib/X11/Xlib/event/destroy_notify.rb +10 -11
  72. data/lib/X11/Xlib/event/enter_notify.rb +10 -8
  73. data/lib/X11/Xlib/event/expose.rb +15 -16
  74. data/lib/X11/Xlib/event/focus_in.rb +9 -12
  75. data/lib/X11/Xlib/event/focus_out.rb +9 -12
  76. data/lib/X11/Xlib/event/generic.rb +35 -0
  77. data/lib/X11/Xlib/event/generic/button.rb +46 -0
  78. data/lib/X11/Xlib/event/generic/crossing.rb +48 -0
  79. data/lib/X11/Xlib/{window/properties/property/class.rb → event/generic/focus_change.rb} +16 -14
  80. data/lib/X11/Xlib/event/generic/key.rb +46 -0
  81. data/lib/X11/Xlib/event/generic/motion.rb +46 -0
  82. data/lib/X11/Xlib/event/generic_event.rb +12 -14
  83. data/lib/X11/Xlib/event/graphics_expose.rb +15 -14
  84. data/lib/X11/Xlib/event/gravity_notify.rb +12 -13
  85. data/lib/X11/Xlib/event/helper.rb +123 -91
  86. data/lib/X11/Xlib/event/key_press.rb +9 -20
  87. data/lib/X11/Xlib/event/key_release.rb +9 -20
  88. data/lib/X11/Xlib/event/keymap_notify.rb +13 -14
  89. data/lib/X11/Xlib/event/leave_notify.rb +10 -20
  90. data/lib/X11/Xlib/event/map_notify.rb +11 -12
  91. data/lib/X11/Xlib/event/map_request.rb +10 -11
  92. data/lib/X11/Xlib/event/mapping_notify.rb +11 -13
  93. data/lib/X11/Xlib/event/motion_notify.rb +10 -20
  94. data/lib/X11/Xlib/event/no_expose.rb +8 -9
  95. data/lib/X11/Xlib/event/property_notify.rb +12 -13
  96. data/lib/X11/Xlib/event/reparent_notify.rb +14 -15
  97. data/lib/X11/Xlib/event/resize_request.rb +11 -12
  98. data/lib/X11/Xlib/event/selection_clear.rb +10 -12
  99. data/lib/X11/Xlib/event/selection_notify.rb +13 -15
  100. data/lib/X11/Xlib/event/selection_request.rb +14 -16
  101. data/lib/X11/Xlib/event/unmap_notify.rb +11 -12
  102. data/lib/X11/Xlib/event/visibility_notify.rb +10 -11
  103. data/lib/X11/Xlib/events.rb +11 -7
  104. data/lib/X11/Xlib/exceptions.rb +10 -10
  105. data/lib/X11/Xlib/graphic_context.rb +69 -0
  106. data/lib/X11/Xlib/graphic_context/functions.rb +50 -0
  107. data/lib/X11/Xlib/{window/properties/property/command.rb → graphic_context/values.rb} +17 -13
  108. data/lib/X11/Xlib/hints.rb +19 -18
  109. data/lib/X11/Xlib/hints/flags.rb +15 -15
  110. data/lib/X11/Xlib/hints/icon.rb +14 -16
  111. data/lib/X11/Xlib/id.rb +75 -0
  112. data/lib/X11/Xlib/image.rb +64 -0
  113. data/lib/X11/Xlib/keysym.rb +53 -26
  114. data/lib/X11/Xlib/mask.rb +81 -55
  115. data/lib/X11/Xlib/pixmap.rb +60 -0
  116. data/lib/X11/Xlib/planes.rb +50 -0
  117. data/lib/X11/Xlib/revert_to.rb +10 -10
  118. data/lib/X11/Xlib/screen.rb +48 -31
  119. data/lib/X11/Xlib/status.rb +56 -56
  120. data/lib/X11/Xlib/transform.rb +25 -25
  121. data/lib/X11/Xlib/visual.rb +19 -19
  122. data/lib/X11/Xlib/window.rb +399 -188
  123. data/lib/X11/Xlib/window/attributes.rb +74 -41
  124. data/lib/X11/Xlib/window/properties.rb +57 -38
  125. data/lib/X11/Xlib/window/properties/property.rb +135 -70
  126. data/lib/X11/Xlib/window/properties/property/net_virtual_root.rb +13 -13
  127. data/lib/X11/Xlib/window/properties/property/parser.rb +45 -35
  128. data/lib/X11/Xlib/window/properties/property/parser/arc.rb +18 -16
  129. data/lib/X11/Xlib/window/properties/property/parser/atom.rb +14 -10
  130. data/lib/X11/Xlib/window/properties/property/parser/cardinal.rb +14 -9
  131. data/lib/X11/Xlib/window/properties/property/parser/hints.rb +17 -16
  132. data/lib/X11/Xlib/window/properties/property/parser/integer.rb +39 -0
  133. data/lib/X11/Xlib/window/properties/property/parser/state.rb +39 -0
  134. data/lib/X11/Xlib/window/properties/property/parser/string.rb +59 -0
  135. data/lib/X11/Xlib/window/properties/property/parser/window.rb +39 -0
  136. data/lib/X11/Xmd.rb +7 -7
  137. data/lib/X11/Xmd/c.rb +19 -19
  138. data/lib/X11/Xregion.rb +32 -0
  139. data/lib/X11/Xregion/c.rb +29 -0
  140. data/lib/X11/Xregion/c/type/box.rb +35 -0
  141. data/lib/X11/Xregion/c/type/point_block.rb +33 -0
  142. data/lib/X11/Xregion/c/type/rectangle.rb +35 -0
  143. data/lib/X11/Xregion/c/type/region.rb +35 -0
  144. data/lib/X11/Xregion/c/types.rb +32 -0
  145. data/lib/X11/Xutil.rb +12 -17
  146. data/lib/X11/Xutil/c.rb +7 -10
  147. data/lib/X11/Xutil/c/functions.rb +7 -7
  148. data/lib/X11/Xutil/c/type/class_hint.rb +10 -10
  149. data/lib/X11/Xutil/c/type/region.rb +31 -0
  150. data/lib/X11/Xutil/c/type/text_property.rb +12 -12
  151. data/lib/X11/Xutil/c/types.rb +8 -7
  152. data/lib/X11/Xutil/state.rb +43 -0
  153. data/lib/X11/Xutil/window.rb +28 -28
  154. data/lib/X11/cursorfont.rb +7 -7
  155. data/lib/X11/cursorfont/c.rb +8 -8
  156. data/lib/X11/cursorfont/font.rb +113 -113
  157. data/lib/X11/extension.rb +65 -0
  158. data/lib/X11/extensions.rb +105 -126
  159. data/lib/X11/extensions/Xrandr.rb +49 -0
  160. data/lib/X11/extensions/Xrandr/c.rb +30 -0
  161. data/lib/X11/extensions/Xrandr/c/functions.rb +106 -0
  162. data/lib/X11/extensions/Xrandr/c/type/crtc_gamma.rb +35 -0
  163. data/lib/X11/extensions/Xrandr/c/type/crtc_info.rb +43 -0
  164. data/lib/X11/extensions/Xrandr/c/type/crtc_transform_attributes.rb +39 -0
  165. data/lib/X11/extensions/Xrandr/c/type/mode_info.rb +45 -0
  166. data/lib/X11/extensions/Xrandr/c/type/output_info.rb +46 -0
  167. data/lib/X11/extensions/Xrandr/c/type/panning.rb +44 -0
  168. data/lib/X11/extensions/Xrandr/c/type/property_info.rb +36 -0
  169. data/lib/X11/extensions/Xrandr/c/type/screen_resources.rb +39 -0
  170. data/lib/X11/extensions/Xrandr/c/type/screen_size.rb +35 -0
  171. data/lib/X11/extensions/Xrandr/c/types.rb +48 -0
  172. data/lib/X11/extensions/Xrandr/crtc.rb +70 -0
  173. data/lib/X11/extensions/Xrandr/crtc/gamma.rb +100 -0
  174. data/lib/X11/extensions/Xrandr/crtc/info.rb +62 -0
  175. data/lib/X11/extensions/Xrandr/crtc/panning.rb +74 -0
  176. data/lib/X11/extensions/Xrandr/event.rb +29 -0
  177. data/lib/X11/extensions/Xrandr/output.rb +59 -0
  178. data/lib/X11/extensions/Xrandr/output/info.rb +105 -0
  179. data/lib/X11/extensions/Xrandr/output/properties.rb +78 -0
  180. data/lib/X11/extensions/Xrandr/output/properties/property.rb +161 -0
  181. data/lib/X11/extensions/Xrandr/output/properties/property/info.rb +73 -0
  182. data/lib/X11/extensions/Xrandr/output/properties/property/parser.rb +73 -0
  183. data/lib/X11/extensions/Xrandr/output/properties/property/parser/atom.rb +39 -0
  184. data/lib/X11/extensions/Xrandr/output/properties/property/parser/integer.rb +43 -0
  185. data/lib/X11/extensions/Xrandr/screen.rb +49 -0
  186. data/lib/X11/extensions/Xrandr/screen/backlight.rb +76 -0
  187. data/lib/X11/extensions/Xrandr/screen_resources.rb +81 -0
  188. data/lib/X11/extensions/Xrandr/window.rb +41 -0
  189. data/lib/X11/extensions/Xrender.rb +34 -0
  190. data/lib/X11/extensions/Xrender/c.rb +30 -0
  191. data/lib/X11/extensions/Xrender/c/functions.rb +50 -0
  192. data/lib/X11/extensions/Xrender/c/type/anim_cursor.rb +33 -0
  193. data/lib/X11/extensions/Xrender/c/type/circle.rb +34 -0
  194. data/lib/X11/extensions/Xrender/c/type/conical_gradient.rb +33 -0
  195. data/lib/X11/extensions/Xrender/c/type/filters.rb +35 -0
  196. data/lib/X11/extensions/Xrender/c/type/glyph_elt16.rb +36 -0
  197. data/lib/X11/extensions/Xrender/c/type/glyph_elt32.rb +36 -0
  198. data/lib/X11/extensions/Xrender/c/type/glyph_elt8.rb +36 -0
  199. data/lib/X11/extensions/Xrender/c/type/glyph_info.rb +37 -0
  200. data/lib/X11/extensions/Xrender/c/type/index_value.rb +36 -0
  201. data/lib/X11/extensions/Xrender/c/type/line_fixed.rb +33 -0
  202. data/lib/X11/extensions/Xrender/c/type/linear_gradient.rb +33 -0
  203. data/lib/X11/extensions/Xrender/c/type/point_double.rb +33 -0
  204. data/lib/X11/extensions/Xrender/c/type/point_fixed.rb +33 -0
  205. data/lib/X11/extensions/Xrender/c/type/radial_gradient.rb +33 -0
  206. data/lib/X11/extensions/Xrender/c/type/render_color.rb +35 -0
  207. data/lib/X11/extensions/Xrender/c/type/render_direct_format.rb +39 -0
  208. data/lib/X11/extensions/Xrender/c/type/render_pict_format.rb +36 -0
  209. data/lib/X11/extensions/Xrender/c/type/render_picture_attributes.rb +44 -0
  210. data/lib/X11/extensions/Xrender/c/type/span_fix.rb +34 -0
  211. data/lib/X11/extensions/Xrender/c/type/transform.rb +32 -0
  212. data/lib/X11/extensions/Xrender/c/type/trap.rb +33 -0
  213. data/lib/X11/extensions/Xrender/c/type/trapezoid.rb +35 -0
  214. data/lib/X11/extensions/Xrender/c/type/triangle.rb +34 -0
  215. data/lib/X11/extensions/Xrender/c/types.rb +56 -0
  216. data/lib/X11/extensions/Xrender/mask.rb +48 -0
  217. data/lib/X11/extensions/randr.rb +29 -0
  218. data/lib/X11/extensions/randr/c.rb +38 -0
  219. data/lib/X11/extensions/render.rb +29 -0
  220. data/lib/X11/extensions/render/c.rb +34 -0
  221. data/lib/X11/extensions/xf86vmode.rb +42 -0
  222. data/lib/X11/extensions/xf86vmode/c.rb +30 -0
  223. data/lib/X11/extensions/xf86vmode/c/functions.rb +59 -0
  224. data/lib/X11/extensions/xf86vmode/c/type/gamma.rb +34 -0
  225. data/lib/X11/extensions/xf86vmode/c/type/mode_info.rb +44 -0
  226. data/lib/X11/extensions/xf86vmode/c/type/mode_line.rb +43 -0
  227. data/lib/X11/extensions/xf86vmode/c/type/monitor.rb +38 -0
  228. data/lib/X11/extensions/xf86vmode/c/type/sync_range.rb +33 -0
  229. data/lib/X11/extensions/xf86vmode/c/types.rb +36 -0
  230. data/lib/X11/extensions/xf86vmode/screen.rb +53 -0
  231. data/lib/X11/extensions/xf86vmode/screen/gamma.rb +79 -0
  232. data/lib/X11/extensions/xf86vmode/screen/gamma/ramp.rb +86 -0
  233. data/lib/X11/keysym.rb +7 -25
  234. data/lib/X11/misc/temperature.rb +458 -0
  235. data/lib/X11/simple.rb +8 -7
  236. data/lib/X11/simple/display.rb +35 -37
  237. data/lib/X11/simple/window.rb +39 -19
  238. data/lib/X11/window_manager.rb +32 -0
  239. data/lib/X11/window_manager/desktops.rb +82 -0
  240. data/lib/X11/window_manager/desktops/desktop.rb +78 -0
  241. data/lib/X11/window_manager/supports.rb +56 -0
  242. data/lib/X11/window_manager/supports/feature.rb +46 -0
  243. data/lib/X11/window_manager/window.rb +102 -0
  244. data/lib/X11/window_manager/window_manager.rb +73 -0
  245. metadata +216 -66
@@ -1,26 +1,26 @@
1
1
  #--
2
2
  # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
- #
3
+ #
4
4
  # Redistribution and use in source and binary forms, with or without modification, are
5
5
  # permitted provided that the following conditions are met:
6
- #
6
+ #
7
7
  # 1. Redistributions of source code must retain the above copyright notice, this list of
8
8
  # conditions and the following disclaimer.
9
- #
9
+ #
10
10
  # 2. Redistributions in binary form must reproduce the above copyright notice, this list
11
11
  # of conditions and the following disclaimer in the documentation and/or other materials
12
12
  # provided with the distribution.
13
- #
14
- # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
15
15
  # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16
- # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
16
+ # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
17
17
  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
18
  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
19
  # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
20
  # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
21
  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
22
  # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- #
23
+ #
24
24
  # The views and conclusions contained in the software and documentation are those of the
25
25
  # authors and should not be interpreted as representing official policies, either expressed
26
26
  # or implied.
@@ -29,17 +29,17 @@
29
29
  module X11; module C
30
30
 
31
31
  module Status
32
- extend FFI::DataConverter
32
+ extend FFI::DataConverter
33
33
 
34
- native_type :int
34
+ native_type :int
35
35
 
36
- def self.to_native (value, ctx)
37
- value.to_i
38
- end
36
+ def self.to_native (value, ctx)
37
+ value.to_i
38
+ end
39
39
 
40
- def self.from_native (value, ctx)
41
- X11::Status.new(value)
42
- end
40
+ def self.from_native (value, ctx)
41
+ X11::Status.new(value)
42
+ end
43
43
  end
44
44
 
45
45
  FFI.typedef Status, :Status
@@ -1,38 +1,38 @@
1
1
  #--
2
2
  # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
- #
3
+ #
4
4
  # Redistribution and use in source and binary forms, with or without modification, are
5
5
  # permitted provided that the following conditions are met:
6
- #
6
+ #
7
7
  # 1. Redistributions of source code must retain the above copyright notice, this list of
8
8
  # conditions and the following disclaimer.
9
- #
9
+ #
10
10
  # 2. Redistributions in binary form must reproduce the above copyright notice, this list
11
11
  # of conditions and the following disclaimer in the documentation and/or other materials
12
12
  # provided with the distribution.
13
- #
14
- # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
15
15
  # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16
- # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
16
+ # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
17
17
  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
18
  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
19
  # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
20
  # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
21
  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
22
  # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- #
23
+ #
24
24
  # The views and conclusions contained in the software and documentation are those of the
25
25
  # authors and should not be interpreted as representing official policies, either expressed
26
26
  # or implied.
27
27
  #++
28
28
 
29
29
  class X11::C::XUnmapEvent < FFI::Struct
30
- layout \
31
- :type, :int,
32
- :serial, :ulong,
33
- :send_event, :Bool,
34
- :display, :pointer,
35
- :event, :Window,
36
- :window, :Window,
37
- :from_configure, :Bool
30
+ layout \
31
+ :type, :int,
32
+ :serial, :ulong,
33
+ :send_event, :Bool,
34
+ :display, :pointer,
35
+ :event, :Window,
36
+ :window, :Window,
37
+ :from_configure, :Bool
38
38
  end
@@ -1,37 +1,37 @@
1
1
  #--
2
2
  # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
- #
3
+ #
4
4
  # Redistribution and use in source and binary forms, with or without modification, are
5
5
  # permitted provided that the following conditions are met:
6
- #
6
+ #
7
7
  # 1. Redistributions of source code must retain the above copyright notice, this list of
8
8
  # conditions and the following disclaimer.
9
- #
9
+ #
10
10
  # 2. Redistributions in binary form must reproduce the above copyright notice, this list
11
11
  # of conditions and the following disclaimer in the documentation and/or other materials
12
12
  # provided with the distribution.
13
- #
14
- # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
15
15
  # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16
- # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
16
+ # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
17
17
  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
18
  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
19
  # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
20
  # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
21
  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
22
  # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- #
23
+ #
24
24
  # The views and conclusions contained in the software and documentation are those of the
25
25
  # authors and should not be interpreted as representing official policies, either expressed
26
26
  # or implied.
27
27
  #++
28
28
 
29
29
  class X11::C::XVisibilityEvent < FFI::Struct
30
- layout \
31
- :type, :int,
32
- :serial, :ulong,
33
- :send_event, :Bool,
34
- :display, :pointer,
35
- :window, :Window,
36
- :state, :int
30
+ layout \
31
+ :type, :int,
32
+ :serial, :ulong,
33
+ :send_event, :Bool,
34
+ :display, :pointer,
35
+ :window, :Window,
36
+ :state, :int
37
37
  end
@@ -1,39 +1,39 @@
1
1
  #--
2
2
  # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
- #
3
+ #
4
4
  # Redistribution and use in source and binary forms, with or without modification, are
5
5
  # permitted provided that the following conditions are met:
6
- #
6
+ #
7
7
  # 1. Redistributions of source code must retain the above copyright notice, this list of
8
8
  # conditions and the following disclaimer.
9
- #
9
+ #
10
10
  # 2. Redistributions in binary form must reproduce the above copyright notice, this list
11
11
  # of conditions and the following disclaimer in the documentation and/or other materials
12
12
  # provided with the distribution.
13
- #
14
- # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
15
15
  # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16
- # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
16
+ # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
17
17
  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
18
  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
19
  # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
20
  # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
21
  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
22
  # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- #
23
+ #
24
24
  # The views and conclusions contained in the software and documentation are those of the
25
25
  # authors and should not be interpreted as representing official policies, either expressed
26
26
  # or implied.
27
27
  #++
28
28
 
29
29
  class X11::C::Visual < FFI::Struct
30
- layout \
31
- :ext_data, :pointer,
32
- :visualid, :VisualID,
33
- :class, :int,
34
- :read_mask, :ulong,
35
- :green_mask, :ulong,
36
- :blue_mask, :ulong,
37
- :buts_per_rgb, :int,
38
- :map_entries, :int
30
+ layout \
31
+ :ext_data, :pointer,
32
+ :visualid, :VisualID,
33
+ :class, :int,
34
+ :read_mask, :ulong,
35
+ :green_mask, :ulong,
36
+ :blue_mask, :ulong,
37
+ :buts_per_rgb, :int,
38
+ :map_entries, :int
39
39
  end
@@ -1,54 +1,54 @@
1
1
  #--
2
2
  # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
- #
3
+ #
4
4
  # Redistribution and use in source and binary forms, with or without modification, are
5
5
  # permitted provided that the following conditions are met:
6
- #
6
+ #
7
7
  # 1. Redistributions of source code must retain the above copyright notice, this list of
8
8
  # conditions and the following disclaimer.
9
- #
9
+ #
10
10
  # 2. Redistributions in binary form must reproduce the above copyright notice, this list
11
11
  # of conditions and the following disclaimer in the documentation and/or other materials
12
12
  # provided with the distribution.
13
- #
14
- # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
15
15
  # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16
- # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
16
+ # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
17
17
  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
18
  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
19
  # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
20
  # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
21
  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
22
  # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- #
23
+ #
24
24
  # The views and conclusions contained in the software and documentation are those of the
25
25
  # authors and should not be interpreted as representing official policies, either expressed
26
26
  # or implied.
27
27
  #++
28
28
 
29
29
  class X11::C::XWindowAttributes < FFI::Struct
30
- layout \
31
- :x, :int,
32
- :y, :int,
33
- :width, :int,
34
- :height, :int,
35
- :border_width, :int,
36
- :depth, :int,
37
- :visual, :pointer,
38
- :root, :Window,
39
- :class, :int,
40
- :bit_gravity, :int,
41
- :win_gravity, :int,
42
- :backing_store, :int,
43
- :backing_planes, :ulong,
44
- :backing_pixel, :ulong,
45
- :save_under, :Bool,
46
- :colormap, :Colormap,
47
- :map_installed, :Bool,
48
- :map_state, :int,
49
- :all_event_masks, :long,
50
- :your_event_masks, :long,
51
- :do_not_propagate_mask, :long,
52
- :override_redirect, :Bool,
53
- :screen, :pointer
30
+ layout \
31
+ :x, :int,
32
+ :y, :int,
33
+ :width, :int,
34
+ :height, :int,
35
+ :border_width, :int,
36
+ :depth, :int,
37
+ :visual, :pointer,
38
+ :root, :Window,
39
+ :class, :int,
40
+ :bit_gravity, :int,
41
+ :win_gravity, :int,
42
+ :backing_store, :int,
43
+ :backing_planes, :ulong,
44
+ :backing_pixel, :ulong,
45
+ :save_under, :Bool,
46
+ :colormap, :Colormap,
47
+ :map_installed, :Bool,
48
+ :map_state, :int,
49
+ :all_event_masks, :long,
50
+ :your_event_masks, :long,
51
+ :do_not_propagate_mask, :long,
52
+ :override_redirect, :Bool,
53
+ :screen, :pointer
54
54
  end
@@ -1,26 +1,26 @@
1
1
  #--
2
2
  # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
- #
3
+ #
4
4
  # Redistribution and use in source and binary forms, with or without modification, are
5
5
  # permitted provided that the following conditions are met:
6
- #
6
+ #
7
7
  # 1. Redistributions of source code must retain the above copyright notice, this list of
8
8
  # conditions and the following disclaimer.
9
- #
9
+ #
10
10
  # 2. Redistributions in binary form must reproduce the above copyright notice, this list
11
11
  # of conditions and the following disclaimer in the documentation and/or other materials
12
12
  # provided with the distribution.
13
- #
14
- # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
15
15
  # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16
- # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
16
+ # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
17
17
  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
18
  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
19
  # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
20
  # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
21
  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
22
  # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- #
23
+ #
24
24
  # The views and conclusions contained in the software and documentation are those of the
25
25
  # authors and should not be interpreted as representing official policies, either expressed
26
26
  # or implied.
@@ -31,11 +31,13 @@ require 'X11/Xdefs'
31
31
 
32
32
  require 'X11/Xlib/c/type/display'
33
33
  require 'X11/Xlib/c/type/gc'
34
+ require 'X11/Xlib/c/type/gc_values'
34
35
  require 'X11/Xlib/c/type/screen'
35
36
  require 'X11/Xlib/c/type/window_attributes'
36
37
  require 'X11/Xlib/c/type/visual'
37
38
  require 'X11/Xlib/c/type/key_sym'
38
39
  require 'X11/Xlib/c/type/status'
40
+ require 'X11/Xlib/c/type/point'
39
41
 
40
42
  require 'X11/Xlib/c/type/any_event'
41
43
  require 'X11/Xlib/c/type/key_event'
@@ -1,201 +1,284 @@
1
1
  #--
2
2
  # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
- #
3
+ #
4
4
  # Redistribution and use in source and binary forms, with or without modification, are
5
5
  # permitted provided that the following conditions are met:
6
- #
6
+ #
7
7
  # 1. Redistributions of source code must retain the above copyright notice, this list of
8
8
  # conditions and the following disclaimer.
9
- #
9
+ #
10
10
  # 2. Redistributions in binary form must reproduce the above copyright notice, this list
11
11
  # of conditions and the following disclaimer in the documentation and/or other materials
12
12
  # provided with the distribution.
13
- #
14
- # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
15
15
  # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16
- # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
16
+ # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
17
17
  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
18
  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
19
  # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
20
  # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
21
  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
22
  # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- #
23
+ #
24
24
  # The views and conclusions contained in the software and documentation are those of the
25
25
  # authors and should not be interpreted as representing official policies, either expressed
26
26
  # or implied.
27
27
  #++
28
28
 
29
+ require 'X11/Xlib/display/extensions'
30
+
29
31
  module X11
30
32
 
31
33
  class Display
32
- def self.from (pointer, options={})
33
- Display.new(pointer, options.merge(:close => false))
34
- end
35
-
36
- def self.all
37
- @displays ||= []
38
- end
39
-
40
- def self.finalizer (display)
41
- proc {
42
- C::XCloseDisplay(FFI::Pointer.new(display))
43
- }
44
- end
45
-
46
- at_exit do
47
- Display.all.each {|d|
48
- Display.finalizer(d).call
49
- }
50
- end
51
-
52
- attr_reader :options
53
-
54
- def initialize (*args)
55
- name, options = if args.first.is_a?(Hash)
56
- [nil, args.first]
57
- else
58
- args
59
- end
60
-
61
- @display = if name.is_a?(FFI::Pointer)
62
- name
63
- elsif name.is_a?(C::Display)
64
- name.pointer
65
- else
66
- X11::C::XOpenDisplay(name)
67
- end.typecast(C::Display)
68
-
69
- if @display.pointer.null?
70
- raise ArgumentError, "could not connect to display #{name}"
71
- end
72
-
73
- @options = {
74
- :flush => true
75
- }.merge(options || {})
76
-
77
- if @options[:close]
78
- ObjectSpace.define_finalizer self, self.class.finalizer(to_ffi.to_i)
79
- else
80
- (Display.all << to_ffi.to_i).uniq!
81
- end
82
- end
83
-
84
- C::Display.layout.members.each_with_index {|name, index|
85
- define_method name do
86
- @display[name]
87
- end
88
- }
89
-
90
- def flush
91
- return unless options[:flush]
92
-
93
- flush!
94
- end
95
-
96
- def flush!
97
- C::XFlush(to_ffi)
98
- end
99
-
100
- def screen (which)
101
- Screen.new(self, @display[:screens] + (which * C::Screen.size))
102
- end
103
-
104
- def default_screen
105
- screen(@display[:default_screen])
106
- end
107
-
108
- def screens
109
- Enumerator.new {
110
- (0 ... @display[:nscreens]).map {|i|
111
- yield screen(i)
112
- }
113
- }
114
- end
115
-
116
- [:root_window, :width, :height].each {|name|
117
- define_method name do
118
- default_screen.__send__ name
119
- end
120
- }
121
-
122
- def grab_pointer (*args)
123
- default_screen.root_window.grab_pointer(*args)
124
- end
125
-
126
- def ungrab_pointer (time=0)
127
- C::XUngrabPointer(to_ffi, time)
128
- end
129
-
130
- def keysym_to_keycode (keysym)
131
- C::XKeysymToKeycode(to_ffi, keysym)
132
- end
133
-
134
- def focused
135
- window = FFI::MemoryPointer.new :Window
136
- revert = FFI::MemoryPointer.new :int
137
-
138
- C::XGetInputFocus(to_ffi, window, revert)
139
-
140
- Window.new(self, window.typecast(:Window)).tap {|w|
141
- w.revert_to = revert.typecast(:int)
142
- }
143
- end
144
-
145
- def focus (window, revert=:ToParent, time=0)
146
- C::XSetInputFocus(to_ffi, window.to_ffi, revert.is_a?(Integer) ? revert : RevertTo[revert], time)
147
- end
148
-
149
- def allow_events (mode, time=0)
150
- C::XAllowEvents(to_ffi, mode, time)
151
- end
152
-
153
- def check_typed_event (event)
154
- event = Event.index(event)
155
- ev = FFI::MemoryPointer.new(C::XEvent)
156
-
157
- C::XCheckTypedEvent(to_ffi, event, ev) or return
158
-
159
- Event.new(ev)
160
- end
161
-
162
- def next_event (mask=nil)
163
- event = FFI::MemoryPointer.new(C::XEvent)
164
-
165
- if mask
166
- C::XMaskEvent(to_ffi, mask.to_ffi, event)
167
- else
168
- C::XNextEvent(to_ffi, event)
169
- end
170
-
171
- Event.new(event)
172
- end
173
-
174
- def each_event (mask=nil, &block)
175
- return unless block
176
-
177
- catch(:skip) {
178
- loop {
179
- next_event(mask).tap {|event|
180
- block.call event
181
- }
182
- }
183
- }
184
- end
185
-
186
- def close
187
- pointer, @display = to_ffi, nil
188
-
189
- Display.all.delete pointer.to_i
190
-
191
- C::XCloseDisplay(pointer)
192
- end
193
-
194
- def to_ffi
195
- raise RuntimeError, 'this Display is unusable because it has been closed' unless @display
196
-
197
- @display.pointer
198
- end
34
+ def self.open (*args)
35
+ name, options = if args.first.is_a?(Hash)
36
+ [nil, args.first]
37
+ else
38
+ args
39
+ end
40
+
41
+ X11::C::XOpenDisplay(name).tap! {|pointer|
42
+ raise ArgumentError, "could not connect to display #{name}" if pointer.null?
43
+
44
+ Display.new(pointer, options)
45
+ }.tap {|display|
46
+ X11::Extension.list.each {|extension|
47
+ display.extensions.load(extension)
48
+ }
49
+ }
50
+ end
51
+
52
+ include ForwardTo
53
+
54
+ attr_reader :options, :extensions
55
+ forward_to :default_screen
56
+
57
+ def initialize (pointer, options={})
58
+ @internal = pointer.is_a?(C::Display) ? pointer : C::Display.new(pointer)
59
+ @extensions = Extensions.new(self)
60
+
61
+ @options = {
62
+ :flush => true
63
+ }.merge(options || {})
64
+ end
65
+
66
+ C::Display.layout.members.each {|name|
67
+ define_method name do
68
+ @internal[name]
69
+ end
70
+ }
71
+
72
+ def name
73
+ C::XDisplayString(to_ffi)
74
+ end
75
+
76
+ def autoflush?; !!options[:flush]; end
77
+ def autoflush!; options[:flush] = true; end
78
+ def no_autoflush!; options[:flush] = false; end
79
+
80
+ def flush
81
+ flush! if options[:flush]
82
+ end
83
+
84
+ def flush!
85
+ C::XFlush(to_ffi)
86
+ end
87
+
88
+ def sync! (discard=false)
89
+ C::XSync(to_ffi, discard)
90
+ end
91
+
92
+ def pending
93
+ C::XPending(to_ffi)
94
+ end
95
+
96
+ def screen (which)
97
+ Screen.new(self, @internal[:screens] + (which * C::Screen.size))
98
+ end
99
+
100
+ def default_screen
101
+ screen(@internal[:default_screen])
102
+ end
103
+
104
+ def screens
105
+ Enumerator.new {|e|
106
+ (0 ... @internal[:nscreens]).map {|i|
107
+ e.yield screen(i)
108
+ }
109
+ }
110
+ end
111
+
112
+ def window (id)
113
+ X11::Window.new(self, id.to_i)
114
+ end
115
+
116
+ def create_window (*args)
117
+ if args.first.is_a?(Hash)
118
+ X11::Window.create(args.first.tap {|args|
119
+ args[:display] = self
120
+ })
121
+ else
122
+ X11::Window.create(self, *args)
123
+ end
124
+ end
125
+
126
+ def grab_pointer (*args, &block)
127
+ default_screen.root_window.grab_pointer(*args, &block)
128
+ end
129
+
130
+ def ungrab_pointer (time=0)
131
+ C::XUngrabPointer(to_ffi, time)
132
+ end
133
+
134
+ def ungrab_key (*args, &block)
135
+ default_screen.root_window.ungrab_key(*args, &block)
136
+ end
137
+
138
+ def keysym_to_keycode (keysym)
139
+ return keysym if keysym.is_a?(Integer)
140
+
141
+ C::XKeysymToKeycode(to_ffi, keysym)
142
+ end
143
+
144
+ def focused
145
+ window = FFI::MemoryPointer.new :Window
146
+ revert = FFI::MemoryPointer.new :int
147
+
148
+ C::XGetInputFocus(to_ffi, window, revert)
149
+
150
+ Window.new(self, window.typecast(:Window)).tap {|w|
151
+ w.revert_to revert.typecast(:int)
152
+ }
153
+ end
154
+
155
+ def focus (window, revert=:ToParent, time=0)
156
+ C::XSetInputFocus(to_ffi, window.to_ffi, revert.is_a?(Integer) ? revert : RevertTo[revert], time)
157
+ end
158
+
159
+ def allow_events (mode, time=0)
160
+ C::XAllowEvents(to_ffi, mode, time)
161
+ end
162
+
163
+ def next_event (what=nil, options=nil, &block)
164
+ what, options = if what.is_a?(Hash)
165
+ [Mask::Event.all, what]
166
+ else
167
+ [what, options || {}]
168
+ end
169
+
170
+ event = FFI::MemoryPointer.new(C::XEvent)
171
+
172
+ # this would be cool, but it's slow as hell, if anyone finds a way to optimize it, let me know
173
+ =begin
174
+ callback = FFI::Function.new(:Bool, [:pointer, :pointer, :pointer]) {|_, event|
175
+ event = Event.new(event)
176
+
177
+ if event.matches?(what)
178
+ block ? block.call(event) : true
179
+ end
180
+ }
181
+
182
+ unless options[:blocking?] == false
183
+ unless options[:delete] == false
184
+ C::XIfEvent(to_ffi, event, callback, nil)
185
+ else
186
+ C::XPeekIfEvent(to_ffi, event, callback, nil)
187
+ end
188
+ else
189
+ if options[:delete] == true
190
+ raise ArgumentError, 'cannot delete and not block at the same time'
191
+ end
192
+
193
+ C::XCheckIfEvent(to_ffi, event, callback, nil) or return
194
+ end
195
+ =end
196
+
197
+ if block
198
+ callback = FFI::Function.new(:Bool, [:pointer, :pointer, :pointer]) do |_, event|
199
+ block.call Event.new(event)
200
+ end
201
+
202
+ if options[:blocking?] == false
203
+ C::XCheckIfEvent(to_ffi, event, callback, nil) or return
204
+
205
+ if options[:delete] == false
206
+ C::XPutBackEvent(to_ffi, event.to_ffi)
207
+ end
208
+ else
209
+ if options[:delete] != false
210
+ C::XIfEvent(to_ffi, event, callback, nil)
211
+ else
212
+ C::XPeekIfEvent(to_ffi, event, callback, nil)
213
+ end
214
+ end
215
+ else
216
+ if what.is_a?(Symbol) && options[:blocking?] != false
217
+ raise ArgumentError, 'cannot look for event by type and block'
218
+ end
219
+
220
+ if !what.is_a?(Symbol) && options[:blocking?] != false
221
+ if options[:delete] != false
222
+ if what
223
+ C::XMaskEvent(to_ffi, what.to_ffi, event)
224
+ else
225
+ C::XNextEvent(to_ffi, event)
226
+ end
227
+ else
228
+ C::XPeekEvent(to_ffi, event)
229
+ end
230
+ else
231
+ if what.is_a?(Symbol)
232
+ C::XCheckTypedEvent(to_ffi, Event.index(what), event) or return
233
+ else
234
+ C::XCheckMaskEvent(to_ffi, what.to_ffi, event) or return
235
+ end
236
+
237
+ if options[:delete] == false
238
+ C::XPutBackEvent(to_ffi, event.to_ffi)
239
+ end
240
+ end
241
+ end
242
+
243
+ Event.new(event)
244
+ end
245
+
246
+ def each_event (what=nil, options=nil, &block)
247
+ return unless block
248
+
249
+ catch(:skip) {
250
+ loop {
251
+ next_event(what, options).tap {|event|
252
+ if !event
253
+ return if options[:blocking] == false
254
+ next
255
+ end
256
+
257
+ block.call event
258
+ }
259
+ }
260
+ }
261
+ end
262
+
263
+ def close
264
+ C::XCloseDisplay(to_ffi)
265
+
266
+ methods.each {|name|
267
+ next if (Object.instance_method(name) rescue false)
268
+
269
+ define_singleton_method name do |*|
270
+ raise RuntimeError, 'this Display is unusable because it has been closed'
271
+ end
272
+ }
273
+ end
274
+
275
+ def atom (name)
276
+ Atom[name, self]
277
+ end
278
+
279
+ def to_ffi
280
+ @internal.pointer
281
+ end
199
282
  end
200
283
 
201
284
  end