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.
- data/lib/X11/X.rb +3 -0
- data/lib/X11/X/c.rb +16 -15
- data/lib/X11/Xatom.rb +167 -0
- data/lib/X11/Xatom/c.rb +52 -0
- data/lib/X11/Xdefs/c.rb +10 -6
- data/lib/X11/Xlib.rb +6 -0
- data/lib/X11/Xlib/c/functions.rb +15 -0
- data/lib/X11/Xlib/c/type/key_sym.rb +47 -0
- data/lib/X11/Xlib/c/type/status.rb +47 -0
- data/lib/X11/Xlib/c/types.rb +2 -0
- data/lib/X11/Xlib/display.rb +128 -28
- data/lib/X11/Xlib/event.rb +15 -0
- data/lib/X11/Xlib/event/generic_event.rb +1 -1
- data/lib/X11/Xlib/event/helper.rb +19 -13
- data/lib/X11/Xlib/exceptions.rb +37 -0
- data/lib/X11/Xlib/hints.rb +49 -0
- data/lib/X11/Xlib/hints/flags.rb +42 -0
- data/lib/X11/Xlib/hints/icon.rb +44 -0
- data/lib/X11/Xlib/keysym.rb +53 -0
- data/lib/X11/Xlib/mask.rb +52 -40
- data/lib/X11/Xlib/revert_to.rb +37 -0
- data/lib/X11/Xlib/screen.rb +12 -1
- data/lib/X11/Xlib/status.rb +93 -0
- data/lib/X11/Xlib/transform.rb +58 -0
- data/lib/X11/Xlib/window.rb +164 -51
- data/lib/X11/Xlib/window/properties.rb +66 -0
- data/lib/X11/Xlib/window/properties/property.rb +98 -0
- data/lib/X11/Xlib/window/properties/property/class.rb +37 -0
- data/lib/X11/Xlib/window/properties/property/command.rb +37 -0
- data/lib/X11/Xlib/window/properties/property/net_virtual_root.rb +39 -0
- data/lib/X11/Xlib/window/properties/property/parser.rb +69 -0
- data/lib/X11/Xlib/window/properties/property/parser/arc.rb +41 -0
- data/lib/X11/Xlib/window/properties/property/parser/atom.rb +35 -0
- data/lib/X11/Xlib/window/properties/property/parser/cardinal.rb +34 -0
- data/lib/X11/Xlib/window/properties/property/parser/hints.rb +41 -0
- data/lib/X11/Xmd/c.rb +14 -12
- data/lib/X11/Xutil.rb +41 -0
- data/lib/X11/Xutil/c.rb +33 -0
- data/lib/X11/Xutil/c/functions.rb +37 -0
- data/lib/X11/Xutil/c/type/class_hint.rb +33 -0
- data/lib/X11/Xutil/c/type/text_property.rb +35 -0
- data/lib/X11/Xutil/c/types.rb +30 -0
- data/lib/X11/Xutil/window.rb +61 -0
- data/lib/X11/cursorfont.rb +31 -0
- data/lib/X11/cursorfont/c.rb +41 -0
- data/lib/X11/cursorfont/font.rb +147 -0
- data/lib/X11/extensions.rb +81 -16
- data/lib/X11/keysym.rb +47 -0
- data/lib/X11/simple.rb +33 -0
- data/lib/X11/simple/display.rb +64 -0
- data/lib/X11/simple/window.rb +45 -0
- metadata +63 -5
data/lib/X11/Xlib/c/types.rb
CHANGED
@@ -34,6 +34,8 @@ require 'X11/Xlib/c/type/gc'
|
|
34
34
|
require 'X11/Xlib/c/type/screen'
|
35
35
|
require 'X11/Xlib/c/type/window_attributes'
|
36
36
|
require 'X11/Xlib/c/type/visual'
|
37
|
+
require 'X11/Xlib/c/type/key_sym'
|
38
|
+
require 'X11/Xlib/c/type/status'
|
37
39
|
|
38
40
|
require 'X11/Xlib/c/type/any_event'
|
39
41
|
require 'X11/Xlib/c/type/key_event'
|
data/lib/X11/Xlib/display.rb
CHANGED
@@ -29,26 +29,72 @@
|
|
29
29
|
module X11
|
30
30
|
|
31
31
|
class Display
|
32
|
-
def
|
33
|
-
pointer
|
34
|
-
@display = pointer.is_a?(C::Display) ? pointer : pointer.typecast(C::Display)
|
32
|
+
def self.from (pointer, options={})
|
33
|
+
Display.new(pointer, options.merge(:close => false))
|
35
34
|
end
|
36
35
|
|
37
|
-
def
|
38
|
-
|
36
|
+
def self.all
|
37
|
+
@displays ||= []
|
39
38
|
end
|
40
39
|
|
41
|
-
def
|
42
|
-
|
40
|
+
def self.finalizer (display)
|
41
|
+
proc {
|
42
|
+
C::XCloseDisplay(FFI::Pointer.new(display))
|
43
|
+
}
|
43
44
|
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
at_exit do
|
47
|
+
Display.all.each {|d|
|
48
|
+
Display.finalizer(d).call
|
49
|
+
}
|
50
|
+
end
|
48
51
|
|
49
|
-
|
52
|
+
attr_reader :options
|
50
53
|
|
51
|
-
|
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)
|
52
98
|
end
|
53
99
|
|
54
100
|
def screen (which)
|
@@ -60,40 +106,94 @@ class Display
|
|
60
106
|
end
|
61
107
|
|
62
108
|
def screens
|
63
|
-
|
64
|
-
|
109
|
+
Enumerator.new {
|
110
|
+
(0 ... @display[:nscreens]).map {|i|
|
111
|
+
yield screen(i)
|
112
|
+
}
|
65
113
|
}
|
66
114
|
end
|
67
115
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
else
|
72
|
-
default_screen.width
|
116
|
+
[:root_window, :width, :height].each {|name|
|
117
|
+
define_method name do
|
118
|
+
default_screen.__send__ name
|
73
119
|
end
|
120
|
+
}
|
121
|
+
|
122
|
+
def grab_pointer (*args)
|
123
|
+
default_screen.root_window.grab_pointer(*args)
|
74
124
|
end
|
75
125
|
|
76
|
-
def
|
77
|
-
|
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
|
78
152
|
|
79
|
-
|
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
|
80
158
|
|
81
159
|
Event.new(ev)
|
82
160
|
end
|
83
161
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
+
}
|
88
182
|
}
|
89
183
|
}
|
90
184
|
end
|
91
185
|
|
92
186
|
def close
|
93
|
-
|
187
|
+
pointer, @display = to_ffi, nil
|
188
|
+
|
189
|
+
Display.all.delete pointer.to_i
|
190
|
+
|
191
|
+
C::XCloseDisplay(pointer)
|
94
192
|
end
|
95
193
|
|
96
|
-
def
|
194
|
+
def to_ffi
|
195
|
+
raise RuntimeError, 'this Display is unusable because it has been closed' unless @display
|
196
|
+
|
97
197
|
@display.pointer
|
98
198
|
end
|
99
199
|
end
|
data/lib/X11/Xlib/event.rb
CHANGED
@@ -31,6 +31,21 @@ require 'X11/Xlib/events'
|
|
31
31
|
module X11
|
32
32
|
|
33
33
|
class Event
|
34
|
+
module Mode
|
35
|
+
AsyncPointer = 0
|
36
|
+
SyncPointer = 1
|
37
|
+
ReplayPointer = 2
|
38
|
+
AsyncKeyboard = 3
|
39
|
+
SyncKeyboard = 4
|
40
|
+
ReplayKeyboard = 5
|
41
|
+
AsyncBoth = 6
|
42
|
+
SyncBoth = 7
|
43
|
+
|
44
|
+
def self.[] (name)
|
45
|
+
const_get name
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
34
49
|
def self.index (event)
|
35
50
|
Events.to_a.index(event)
|
36
51
|
end
|
@@ -36,7 +36,11 @@ class Helper
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.attribute (which=nil)
|
39
|
-
|
39
|
+
if which
|
40
|
+
@attribute = which.to_s.to_sym
|
41
|
+
else
|
42
|
+
@attribute
|
43
|
+
end
|
40
44
|
end
|
41
45
|
|
42
46
|
def self.attach_method (meth, &block)
|
@@ -59,31 +63,31 @@ class Helper
|
|
59
63
|
case args.size
|
60
64
|
when 0
|
61
65
|
attach_method(new) {
|
62
|
-
|
66
|
+
to_ffi[self.class.attribute][original]
|
63
67
|
}
|
64
68
|
|
65
69
|
attach_method("#{new}=") {|x|
|
66
|
-
|
70
|
+
to_ffi[self.class.attribute][original] = x
|
67
71
|
}
|
68
72
|
when 1
|
69
73
|
if args.first.is_a?(Class)
|
70
74
|
attach_method(new) {
|
71
|
-
args.first.new(
|
75
|
+
args.first.new(to_ffi[self.class.attribute][original])
|
72
76
|
}
|
73
77
|
|
74
78
|
attach_method("#{new}=") {|x|
|
75
|
-
|
79
|
+
to_ffi[self.class.attribute][original] = x.to_ffi
|
76
80
|
}
|
77
81
|
else
|
78
82
|
manage([original, new], args.first, nil)
|
79
83
|
end
|
80
84
|
when 2
|
81
85
|
attach_method(new) {
|
82
|
-
|
86
|
+
instance_exec(to_ffi[self.class.attribute][original], &args[0])
|
83
87
|
} if args[0]
|
84
88
|
|
85
89
|
attach_method("#{new}=") {|x|
|
86
|
-
|
90
|
+
to_ffi[attribute][original] = instance_exec(x, &args[1])
|
87
91
|
} if args[1]
|
88
92
|
end
|
89
93
|
end
|
@@ -92,23 +96,25 @@ class Helper
|
|
92
96
|
@struct = struct
|
93
97
|
end
|
94
98
|
|
95
|
-
def
|
99
|
+
def to_ffi
|
96
100
|
@struct
|
97
101
|
end
|
98
|
-
|
99
|
-
alias to_c struct
|
100
102
|
end
|
101
103
|
|
102
104
|
X11::Event::Window = [lambda {|w|
|
103
|
-
X11::
|
104
|
-
}, lambda(&:
|
105
|
+
X11::Window.new(display, w)
|
106
|
+
}, lambda(&:to_ffi)]
|
107
|
+
|
108
|
+
X11::Event::Display = [lambda {|pointer|
|
109
|
+
X11::Display.from(pointer)
|
110
|
+
}, lambda(&:to_ffi)]
|
105
111
|
|
106
112
|
module X11::Event::Common
|
107
113
|
def self.included (klass)
|
108
114
|
klass.class_eval {
|
109
115
|
manage :serial
|
110
116
|
manage [:send_event, :send_event?]
|
111
|
-
manage :display, X11::Display
|
117
|
+
manage :display, X11::Event::Display
|
112
118
|
manage :window, X11::Event::Window
|
113
119
|
}
|
114
120
|
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; module Exceptions
|
30
|
+
|
31
|
+
class InvalidKeysym < Exception
|
32
|
+
def initialize
|
33
|
+
super('Invalid keysym')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end; end
|
@@ -0,0 +1,49 @@
|
|
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
|
32
|
+
|
33
|
+
class Hints
|
34
|
+
attr_reader :flags, :state, :icon, :group
|
35
|
+
|
36
|
+
def initialize (flags, input, state, icon, group)
|
37
|
+
@flags = flags
|
38
|
+
@input = input
|
39
|
+
@state = state
|
40
|
+
@icon = icon
|
41
|
+
@group = group
|
42
|
+
end
|
43
|
+
|
44
|
+
def input?
|
45
|
+
@input
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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; class Hints
|
30
|
+
|
31
|
+
Flags = Bitmap.new(
|
32
|
+
:Input => (1 << 0),
|
33
|
+
:State => (1 << 1),
|
34
|
+
:IconPixmap => (1 << 2),
|
35
|
+
:IconWindow => (1 << 3),
|
36
|
+
:IconPosition => (1 << 4),
|
37
|
+
:IconMask => (1 << 5),
|
38
|
+
:WindowGroup => (1 << 6),
|
39
|
+
:Urgency => (1 << 8)
|
40
|
+
)
|
41
|
+
|
42
|
+
end; end
|