x11 0.0.1a1 → 0.0.1a2

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 (52) hide show
  1. data/lib/X11/X.rb +3 -0
  2. data/lib/X11/X/c.rb +16 -15
  3. data/lib/X11/Xatom.rb +167 -0
  4. data/lib/X11/Xatom/c.rb +52 -0
  5. data/lib/X11/Xdefs/c.rb +10 -6
  6. data/lib/X11/Xlib.rb +6 -0
  7. data/lib/X11/Xlib/c/functions.rb +15 -0
  8. data/lib/X11/Xlib/c/type/key_sym.rb +47 -0
  9. data/lib/X11/Xlib/c/type/status.rb +47 -0
  10. data/lib/X11/Xlib/c/types.rb +2 -0
  11. data/lib/X11/Xlib/display.rb +128 -28
  12. data/lib/X11/Xlib/event.rb +15 -0
  13. data/lib/X11/Xlib/event/generic_event.rb +1 -1
  14. data/lib/X11/Xlib/event/helper.rb +19 -13
  15. data/lib/X11/Xlib/exceptions.rb +37 -0
  16. data/lib/X11/Xlib/hints.rb +49 -0
  17. data/lib/X11/Xlib/hints/flags.rb +42 -0
  18. data/lib/X11/Xlib/hints/icon.rb +44 -0
  19. data/lib/X11/Xlib/keysym.rb +53 -0
  20. data/lib/X11/Xlib/mask.rb +52 -40
  21. data/lib/X11/Xlib/revert_to.rb +37 -0
  22. data/lib/X11/Xlib/screen.rb +12 -1
  23. data/lib/X11/Xlib/status.rb +93 -0
  24. data/lib/X11/Xlib/transform.rb +58 -0
  25. data/lib/X11/Xlib/window.rb +164 -51
  26. data/lib/X11/Xlib/window/properties.rb +66 -0
  27. data/lib/X11/Xlib/window/properties/property.rb +98 -0
  28. data/lib/X11/Xlib/window/properties/property/class.rb +37 -0
  29. data/lib/X11/Xlib/window/properties/property/command.rb +37 -0
  30. data/lib/X11/Xlib/window/properties/property/net_virtual_root.rb +39 -0
  31. data/lib/X11/Xlib/window/properties/property/parser.rb +69 -0
  32. data/lib/X11/Xlib/window/properties/property/parser/arc.rb +41 -0
  33. data/lib/X11/Xlib/window/properties/property/parser/atom.rb +35 -0
  34. data/lib/X11/Xlib/window/properties/property/parser/cardinal.rb +34 -0
  35. data/lib/X11/Xlib/window/properties/property/parser/hints.rb +41 -0
  36. data/lib/X11/Xmd/c.rb +14 -12
  37. data/lib/X11/Xutil.rb +41 -0
  38. data/lib/X11/Xutil/c.rb +33 -0
  39. data/lib/X11/Xutil/c/functions.rb +37 -0
  40. data/lib/X11/Xutil/c/type/class_hint.rb +33 -0
  41. data/lib/X11/Xutil/c/type/text_property.rb +35 -0
  42. data/lib/X11/Xutil/c/types.rb +30 -0
  43. data/lib/X11/Xutil/window.rb +61 -0
  44. data/lib/X11/cursorfont.rb +31 -0
  45. data/lib/X11/cursorfont/c.rb +41 -0
  46. data/lib/X11/cursorfont/font.rb +147 -0
  47. data/lib/X11/extensions.rb +81 -16
  48. data/lib/X11/keysym.rb +47 -0
  49. data/lib/X11/simple.rb +33 -0
  50. data/lib/X11/simple/display.rb +64 -0
  51. data/lib/X11/simple/window.rb +45 -0
  52. metadata +63 -5
@@ -0,0 +1,44 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification, are
5
+ # permitted provided that the following conditions are met:
6
+ #
7
+ # 1. Redistributions of source code must retain the above copyright notice, this list of
8
+ # conditions and the following disclaimer.
9
+ #
10
+ # 2. Redistributions in binary form must reproduce the above copyright notice, this list
11
+ # of conditions and the following disclaimer in the documentation and/or other materials
12
+ # provided with the distribution.
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
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
17
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ #
24
+ # The views and conclusions contained in the software and documentation are those of the
25
+ # authors and should not be interpreted as representing official policies, either expressed
26
+ # or implied.
27
+ #++
28
+
29
+ require 'X11/Xlib/hints/icon'
30
+
31
+ module X11; class Hints
32
+
33
+ class Icon
34
+ attr_reader :pixmap, :window, :x, :y
35
+
36
+ def initialize (pixmap, window, x, y)
37
+ @pixmap = pixmap
38
+ @window = window
39
+ @x = x
40
+ @y = y
41
+ end
42
+ end
43
+
44
+ end; end
@@ -0,0 +1,53 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification, are
5
+ # permitted provided that the following conditions are met:
6
+ #
7
+ # 1. Redistributions of source code must retain the above copyright notice, this list of
8
+ # conditions and the following disclaimer.
9
+ #
10
+ # 2. Redistributions in binary form must reproduce the above copyright notice, this list
11
+ # of conditions and the following disclaimer in the documentation and/or other materials
12
+ # provided with the distribution.
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
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
17
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ #
24
+ # The views and conclusions contained in the software and documentation are those of the
25
+ # authors and should not be interpreted as representing official policies, either expressed
26
+ # or implied.
27
+ #++
28
+
29
+ module X11
30
+
31
+ class Keysym
32
+ def initialize (value)
33
+ if value.is_a?(Integer)
34
+ @number = value
35
+ @string = C::XKeysymToString(@number)
36
+ else
37
+ @string = value.to_s
38
+ @number = C::XStringToKeysym(@string).to_i
39
+ end
40
+
41
+ raise ArgumentError, 'invalid keysym' if @number.zero? or @string.nil?
42
+ end
43
+
44
+ def to_s
45
+ @string
46
+ end
47
+
48
+ def to_i
49
+ @number
50
+ end
51
+ end
52
+
53
+ end
@@ -28,45 +28,57 @@
28
28
 
29
29
  module X11
30
30
 
31
- Mask = Class.new(Hash) {
32
- def [] (what)
33
- super || super(what.to_s.to_sym)
34
- end
35
- }.new.merge(
36
- NoEvent: 0,
37
- KeyPress: 1,
38
- KeyRelease: (1 << 1),
39
- ButtonPress: (1 << 2),
40
- ButtonRelease: (1 << 3),
41
- EnterWindow: (1 << 4),
42
- LeaveWindow: (1 << 5),
43
- PointerMotion: (1 << 6),
44
- PointerMotionHint: (1 << 7),
45
- Button1Motion: (1 << 8),
46
- Button2Motion: (1 << 9),
47
- Button3Motion: (1 << 10),
48
- Button4Motion: (1 << 11),
49
- Button5Motion: (1 << 12),
50
- ButtonMotion: (1 << 13),
51
- KeymapState: (1 << 14),
52
- Exposure: (1 << 15),
53
- VisibilityChange: (1 << 16),
54
- StructureNotify: (1 << 17),
55
- ResizeRedirect: (1 << 18),
56
- SubstructureNotify: (1 << 19),
57
- SubstructureRedirect: (1 << 20),
58
- FocusChange: (1 << 21),
59
- PropertyChange: (1 << 22),
60
- ColormapChange: (1 << 23),
61
- OwnerGrabButton: (1 << 24),
62
- Shift: 1,
63
- Lock: (1 << 1),
64
- Control: (1 << 2),
65
- Mod1: (1 << 3),
66
- Mod2: (1 << 4),
67
- Mod3: (1 << 5),
68
- Mod4: (1 << 6),
69
- Mod5: (1 << 7)
70
- ).freeze
31
+ module Mask
32
+ Event = Bitmap.new(
33
+ :NoEvent => (0 << 0),
34
+ :KeyPress => (1 << 0),
35
+ :KeyRelease => (1 << 1),
36
+ :ButtonPress => (1 << 2),
37
+ :ButtonRelease => (1 << 3),
38
+ :EnterWindow => (1 << 4),
39
+ :LeaveWindow => (1 << 5),
40
+ :PointerMotion => (1 << 6),
41
+ :PointerMotionHint => (1 << 7),
42
+ :Button1Motion => (1 << 8),
43
+ :Button2Motion => (1 << 9),
44
+ :Button3Motion => (1 << 10),
45
+ :Button4Motion => (1 << 11),
46
+ :Button5Motion => (1 << 12),
47
+ :ButtonMotion => (1 << 13),
48
+ :KeymapState => (1 << 14),
49
+ :Exposure => (1 << 15),
50
+ :VisibilityChange => (1 << 16),
51
+ :StructureNotify => (1 << 17),
52
+ :ResizeRedirect => (1 << 18),
53
+ :SubstructureNotify => (1 << 19),
54
+ :SubstructureRedirect => (1 << 20),
55
+ :FocusChange => (1 << 21),
56
+ :PropertyChange => (1 << 22),
57
+ :ColormapChange => (1 << 23),
58
+ :OwnerGrabButton => (1 << 24)
59
+ )
60
+
61
+ Key = Bitmap.new(
62
+ :Shift => (1 << 0),
63
+ :Lock => (1 << 1),
64
+ :Control => (1 << 2),
65
+ :Mod1 => (1 << 3),
66
+ :Mod2 => (1 << 4),
67
+ :Mod3 => (1 << 5),
68
+ :Mod4 => (1 << 6),
69
+ :Mod5 => (1 << 7)
70
+ )
71
+
72
+ Hint = Bitmap.new(
73
+ :Input => (1 << 0),
74
+ :State => (1 << 1),
75
+ :IconPixmap => (1 << 2),
76
+ :IconWindow => (1 << 3),
77
+ :IconPosition => (1 << 4),
78
+ :IconMask => (1 << 5),
79
+ :WindowGroup => (1 << 6),
80
+ :Urgency => (1 << 8)
81
+ )
82
+ end
71
83
 
72
84
  end
@@ -0,0 +1,37 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification, are
5
+ # permitted provided that the following conditions are met:
6
+ #
7
+ # 1. Redistributions of source code must retain the above copyright notice, this list of
8
+ # conditions and the following disclaimer.
9
+ #
10
+ # 2. Redistributions in binary form must reproduce the above copyright notice, this list
11
+ # of conditions and the following disclaimer in the documentation and/or other materials
12
+ # provided with the distribution.
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
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
17
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ #
24
+ # The views and conclusions contained in the software and documentation are those of the
25
+ # authors and should not be interpreted as representing official policies, either expressed
26
+ # or implied.
27
+ #++
28
+
29
+ module X11
30
+
31
+ RevertTo = {
32
+ :None => 0,
33
+ :PointerRoot => 1,
34
+ :Parent => 2
35
+ }
36
+
37
+ end
@@ -46,7 +46,18 @@ class Screen
46
46
  Window.new(@display, @screen[:root])
47
47
  end
48
48
 
49
- def to_c
49
+ def windows (window=root_window)
50
+ result = []
51
+
52
+ window.subwindows.each {|win|
53
+ result << win
54
+ result << windows(win)
55
+ }
56
+
57
+ result.flatten.compact.uniq
58
+ end
59
+
60
+ def to_ffi
50
61
  @screen.pointer
51
62
  end
52
63
  end
@@ -0,0 +1,93 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification, are
5
+ # permitted provided that the following conditions are met:
6
+ #
7
+ # 1. Redistributions of source code must retain the above copyright notice, this list of
8
+ # conditions and the following disclaimer.
9
+ #
10
+ # 2. Redistributions in binary form must reproduce the above copyright notice, this list
11
+ # of conditions and the following disclaimer in the documentation and/or other materials
12
+ # provided with the distribution.
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
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
17
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ #
24
+ # The views and conclusions contained in the software and documentation are those of the
25
+ # authors and should not be interpreted as representing official policies, either expressed
26
+ # or implied.
27
+ #++
28
+
29
+ module X11
30
+
31
+ class Status
32
+ @codes = {
33
+ :Success => 0,
34
+ :BadRequest => 1,
35
+ :BadValue => 2,
36
+ :BadWindow => 3,
37
+ :BadPixmap => 4,
38
+ :BadAtom => 5,
39
+ :BadCursor => 6,
40
+ :BadFont => 7,
41
+ :BadMatch => 8,
42
+ :BadDrawable => 9,
43
+ :BadAccess => 10,
44
+ :BadAlloc => 11,
45
+ :BadColor => 12,
46
+ :BadGC => 13,
47
+ :BadIDChoice => 14,
48
+ :BadName => 15,
49
+ :BadLength => 16,
50
+ :BadImplementation => 17,
51
+
52
+ :FirstExtensionError => 128,
53
+ :LastExtensionError => 255
54
+ }
55
+
56
+ def self.to_hash
57
+ @codes
58
+ end
59
+
60
+ def self.const_missing (const)
61
+ Status.new(to_hash[const])
62
+ end
63
+
64
+ def initialize (value)
65
+ @value = value.is_a?(Integer) ? value : Atom.const_missing(value)
66
+ end
67
+
68
+ def ok?
69
+ self == Success
70
+ end
71
+
72
+ def == (value)
73
+ to_i == value || to_sym == value
74
+ end
75
+
76
+ def hash
77
+ @value.hash
78
+ end
79
+
80
+ def to_sym
81
+ Status.to_hash.key(@value)
82
+ end
83
+
84
+ def to_i
85
+ @value
86
+ end; alias to_ffi to_i
87
+
88
+ def inspect
89
+ to_sym.to_s
90
+ end
91
+ end
92
+
93
+ end
@@ -0,0 +1,58 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification, are
5
+ # permitted provided that the following conditions are met:
6
+ #
7
+ # 1. Redistributions of source code must retain the above copyright notice, this list of
8
+ # conditions and the following disclaimer.
9
+ #
10
+ # 2. Redistributions in binary form must reproduce the above copyright notice, this list
11
+ # of conditions and the following disclaimer in the documentation and/or other materials
12
+ # provided with the distribution.
13
+ #
14
+ # THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
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
17
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ #
24
+ # The views and conclusions contained in the software and documentation are those of the
25
+ # authors and should not be interpreted as representing official policies, either expressed
26
+ # or implied.
27
+ #++
28
+
29
+ module X11
30
+
31
+ class Transform
32
+ attr_reader :name
33
+
34
+ def initialize (name, &block)
35
+ @name = name
36
+ @callbacks = {}
37
+
38
+ instance_eval &block
39
+ end
40
+
41
+ def for (*args)
42
+ @for = args
43
+
44
+ self
45
+ end
46
+
47
+ def method_missing (name, *args, &block)
48
+ if block
49
+ @callbacks[name] = block
50
+ else
51
+ return super unless @callbacks[name]
52
+
53
+ @callbacks[name].call(*@for, *args)
54
+ end
55
+ end
56
+ end
57
+
58
+ end
@@ -27,78 +27,191 @@
27
27
  #++
28
28
 
29
29
  require 'X11/Xlib/window/attributes'
30
+ require 'X11/Xlib/window/properties'
30
31
 
31
32
  module X11
32
- class Window
33
33
 
34
- GRAB_MODE = {sync: false, async: true}
34
+ class Window
35
+ attr_reader :display, :parent, :revert_to
35
36
 
36
- def initialize (dpy, window)
37
- @dpy = dpy
38
- @win = window
39
- end
37
+ def initialize (display, window)
38
+ @display = display
39
+ @window = window
40
+
41
+ self.revert_to = nil
42
+ end
40
43
 
41
- def nil?
42
- @win.zero?
43
- end
44
+ def root
45
+ root = FFI::MemoryPointer.new :Window
46
+ parent = FFI::MemoryPointer.new :Window
47
+ number = FFI::MemoryPointer.new :uint
48
+ children = FFI::MemoryPointer.new :pointer
44
49
 
45
- def attributes
46
- attr = FFI::MemoryPointer.new(C::XWindowAttributes)
47
- C.XGetWindowAttributes(@dpy.to_c, @win, attr)
48
- Attributes.new(attr)
49
- end
50
- alias attr attributes
50
+ C::XQueryTree(display.to_ffi, id, root, parent, children, number)
51
+ C::XFree(children.typecast(:pointer))
51
52
 
52
- def grab_pointer (owner_events=true, event_mask=0, pointer_mode=:async,
53
- keyboard_mode=:async, confine_to=0, cursor=0, time=0)
54
- C.XGrabPointer(@dpy.to_c, @win, !!owner_events, event_mask, mode2int(pointer_mode),
55
- mode2int(keyboard_mode), confine_to.to_c, cursor, time)
56
- end
53
+ Window.new(display, root.typecast(:Window))
54
+ end
57
55
 
58
- def ungrab_pointer (time=0)
59
- @dpy.ungrab_pointer(time)
60
- end
56
+ def parent
57
+ root = FFI::MemoryPointer.new :Window
58
+ parent = FFI::MemoryPointer.new :Window
59
+ number = FFI::MemoryPointer.new :uint
60
+ children = FFI::MemoryPointer.new :pointer
61
61
 
62
- def keysym_to_keycode (keysym)
63
- C.XKeysymToKeycode(to_c, keysym)
64
- end
62
+ C::XQueryTree(display.to_ffi, id, root, parent, children, number)
63
+ C::XFree(children.typecast(:pointer))
65
64
 
66
- def move_resize (x, y, width, height)
67
- C.XMoveResizeWindow(@dpy.to_c, @win, x, y, width, height)
68
- end
65
+ Window.new(display, parent.typecast(:Window))
66
+ end
69
67
 
70
- def raise
71
- C.XRaiseWindow(@dpy.to_c, @win)
72
- end
68
+ def id
69
+ @window
70
+ end; alias hash id
73
71
 
74
- def grab_key (keycode, modifiers=0, owner_events=true, pointer_mode=:async, keyboard_mode=:async)
75
- C.XGrabKey(@dpy.to_c, keycode.to_keycode, modifiers, @win, !!owner_events,
76
- mode2int(pointer_mode), mode2int(keyboard_mode))
77
- end
72
+ def == (value)
73
+ id == value.id
74
+ end
78
75
 
79
- def ungrab_key (keycode, modifiers=0)
80
- C.XUngrabKey(@dpy.to_c, keycode.to_keycode, modifiers, @win)
81
- end
76
+ def nil?
77
+ id.zero?
78
+ end
82
79
 
83
- def grab_button (button, modifiers=0, owner_events=true, event_mask=4,
84
- pointer_mode=:async, keyboard_mode=:async, confine_to=0, cursor=0)
85
- C.XGrabButton(@dpy.to_c, button, modifiers, @win, !!owner_events, event_mask,
86
- mode2int(pointer_mode), mode2int(keyboard_mode), confine_to.to_c, cursor.to_c)
80
+ def revert_to= (value)
81
+ @revert_to = if value.is_a?(Integer)
82
+ RevertTo.key(value)
83
+ else
84
+ self.revert_to = RevertTo[value] || 0
87
85
  end
86
+ end
88
87
 
89
- def ungrab_button (button, modifiers=0)
90
- C.XUngrabButton(@dpy.to_c, button, modifiers, @win)
91
- end
88
+ def attributes
89
+ attr = FFI::MemoryPointer.new(C::XWindowAttributes)
90
+
91
+ C::XGetWindowAttributes(display.to_ffi, to_ffi, attr)
92
+
93
+ Attributes.new(attr)
94
+ end
95
+
96
+ def properties
97
+ Properties.new(self)
98
+ end
99
+
100
+ def move (x, y)
101
+ C::XMoveWindow(display.to_ffi, to_ffi, x, y)
102
+
103
+ display.flush
104
+ end
105
+
106
+ def resize (width, height)
107
+ C::XResizeWindow(display.to_ffi, to_ffi, width, height)
108
+
109
+ display.flush
110
+ end
111
+
112
+ def raise
113
+ C::XRaiseWindow(display.to_ffi, to_ffi)
114
+
115
+ display.flush
116
+ end
117
+
118
+ def subwindows
119
+ result = []
120
+ root = FFI::MemoryPointer.new :Window
121
+ parent = FFI::MemoryPointer.new :Window
122
+ number = FFI::MemoryPointer.new :uint
123
+ children = FFI::MemoryPointer.new :pointer
124
+
125
+ C::XQueryTree(display.to_ffi, id, root, parent, children, number)
126
+
127
+ return result if children.typecast(:pointer).null?
128
+
129
+ children.typecast(:pointer).read_array_of(:Window, number.typecast(:uint)).each {|win|
130
+ result << Window.new(display, win)
131
+ }
92
132
 
93
- def to_c
94
- @win
133
+ C::XFree(children.typecast(:pointer))
134
+
135
+ result
136
+ end
137
+
138
+ def grab_pointer (owner_events=true, event_mask=Mask::Event[:NoEvent], pointer_mode=:sync, keyboard_mode=:async, confine_to=0, cursor=0, time=0)
139
+ C::XGrabPointer(display.to_ffi, to_ffi, !!owner_events, event_mask.to_ffi, mode2int(pointer_mode), mode2int(keyboard_mode), confine_to.to_ffi, cursor.to_ffi, time).zero?
140
+ end
141
+
142
+ def ungrab_pointer (time=0)
143
+ display.ungrab_pointer(time)
144
+ end
145
+
146
+ def keysym_to_keycode (keysym)
147
+ C::XKeysymToKeycode(to_ffi, keysym)
148
+ end
149
+
150
+ def grab_key (keycode, modifiers=0, owner_events=true, pointer_mode=:async, keyboard_mode=:sync)
151
+ C::XGrabKey(display.to_ffi, keycode.to_keycode, modifiers, to_ffi, !!owner_events, mode2int(pointer_mode), mode2int(keyboard_mode))
152
+ end
153
+
154
+ def ungrab_key (keycode, modifiers=0)
155
+ C::XUngrabKey(display.to_ffi, keycode.to_keycode, modifiers, to_ffi)
156
+ end
157
+
158
+ def grab_button (button, modifiers=0, owner_events=true, event_mask=Mask::Event[:ButtonPress], pointer_mode=:async, keyboard_mode=:sync, confine_to=0, cursor=0)
159
+ C::XGrabButton(display.to_ffi, button, modifiers, to_ffi, !!owner_events, event_mask.to_ffi, mode2int(pointer_mode), mode2int(keyboard_mode), confine_to.to_ffi, cursor.to_ffi)
160
+ end
161
+
162
+ def ungrab_button (button, modifiers=0)
163
+ C::XUngrabButton(display.to_ffi, button, modifiers, to_ffi)
164
+ end
165
+
166
+ def pointer_on?
167
+ root = FFI::MemoryPointer.new :Window
168
+ child = FFI::MemoryPointer.new :Window
169
+ dummy = FFI::MemoryPointer.new :int
170
+
171
+ C::XQueryPointer(display.to_ffi, to_ffi, root, child, dummy, dummy, dummy, dummy, dummy)
172
+
173
+ Window.new(display, child.typecast(:Window))
174
+ end
175
+
176
+ def pointer_at? (on_root=false)
177
+ dummy = FFI::MemoryPointer.new :Window
178
+ y = FFI::MemoryPointer.new :int
179
+ x = FFI::MemoryPointer.new :int
180
+
181
+ if on_root
182
+ C::XQueryPointer(display.to_ffi, to_ffi, dummy, dummy, x, y, dummy, dummy, dummy)
183
+ else
184
+ C::XQueryPointer(display.to_ffi, to_ffi, dummy, dummy, dummy, dummy, x, y, dummy)
95
185
  end
96
186
 
97
- private
98
- def mode2int (mode)
99
- (mode == true or GRAB_MODE[mode]) ? 1 : 0
187
+ [x.typecast(:int), y.typecast(:int)]
188
+ end
189
+
190
+ def next_event (mask=Mask::Event[:NoEvent])
191
+ event = FFI::MemoryPointer.new(C::XEvent)
192
+
193
+ C::XWindowEvent(display.to_ffi, to_ffi, mask.to_ffi, event)
194
+
195
+ Event.new(event)
196
+ end
197
+
198
+ def to_ffi
199
+ id
200
+ end
201
+
202
+ def inspect
203
+ with attributes do |attr|
204
+ "#<X11::Window: #{attr.width}x#{attr.height} (#{attr.x}; #{attr.y})>"
100
205
  end
101
206
  end
102
207
 
208
+ private
209
+
210
+ GRAB_MODE = { :sync => false, :async => true }
211
+
212
+ def mode2int (mode)
213
+ (mode == true or GRAB_MODE[mode]) ? 1 : 0
214
+ end
215
+ end
103
216
 
104
217
  end