rwayland 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/example/02_window.rb +32 -22
- data/example/rwaylandtk/custom_wl_interface.rb +16 -11
- data/example/rwaylandtk/toplevel_window.rb +18 -4
- data/example/rwaylandtk.rb +4 -1
- data/lib/wayland/message_buffer.rb +20 -8
- data/lib/wayland/object_manager.rb +1 -1
- data/lib/wayland/protocol.rb +182 -7
- data/lib/wayland/util.rb +24 -2
- data/lib/wayland/wl/display.rb +9 -18
- data/lib/wayland/wl/registry.rb +7 -1
- data/lib/wayland/wlobject.rb +0 -33
- metadata +3 -6
- data/lib/wayland/code_generator.rb +0 -70
- data/lib/wayland/code_template.erb +0 -91
- data/lib/wayland/dispatcher.rb +0 -82
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f91aba8d86f8ded1353cd09b58a79d77eebd831378672a364af00b7c51f8380a
|
|
4
|
+
data.tar.gz: 62fb1be58aa82c29c7f7d488be92a119af82dea9f70e16c03a522f65c45a6932
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c2c9e50388216991c98aedc251257b6c7bda2edc2d636e3ca12c8fe262a43c73c1131e73a9914c19600dbaf04cc6bcac2fb9f1c6a978f995997172af867e8028
|
|
7
|
+
data.tar.gz: a9e6dc2ecb14b95b5b961a732fc72c1140217ab34443f898b52072c5d9f716ed10b7330b6e2a742f8bc69a87e57dd891d8fda76a07432a08f1bcab2cfa64561f
|
data/example/02_window.rb
CHANGED
|
@@ -13,7 +13,7 @@ class MyApplicationWindow < RWaylandTk::ToplevelWindow
|
|
|
13
13
|
super
|
|
14
14
|
set_title("Example Window", "Example App")
|
|
15
15
|
@text = File.read __FILE__
|
|
16
|
-
@ty = TITLE_BAR_SIZE
|
|
16
|
+
@ty = server_decoration ? 0 : TITLE_BAR_SIZE
|
|
17
17
|
@cursor = 0
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -23,12 +23,19 @@ class MyApplicationWindow < RWaylandTk::ToplevelWindow
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def mouse_down(button, time, serial)
|
|
26
|
+
return unless @py
|
|
26
27
|
seat = @display[:wl_seat]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
consumed = false
|
|
29
|
+
unless server_decoration
|
|
30
|
+
if @py < TITLE_BAR_SIZE
|
|
31
|
+
@xdg_toplevel.move(seat, serial)
|
|
32
|
+
consumed = true
|
|
33
|
+
elsif @px > width - RESIZER_SIZE && @py > height - RESIZER_SIZE
|
|
34
|
+
@xdg_toplevel.resize(seat, serial, Wayland::Xdg::Toplevel[:resize_edge].bottom_right)
|
|
35
|
+
consumed = true
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
unless consumed
|
|
32
39
|
lx = @px
|
|
33
40
|
ly = @py - @ty
|
|
34
41
|
ans = content_pango_layout.xy_to_index lx * Pango::SCALE, ly * Pango::SCALE
|
|
@@ -143,27 +150,30 @@ class MyApplicationWindow < RWaylandTk::ToplevelWindow
|
|
|
143
150
|
context.set_source_color [0.2, 0.3, 0.2, 1]
|
|
144
151
|
context.show_pango_layout layout
|
|
145
152
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
153
|
+
unless server_decoration
|
|
154
|
+
# title bar
|
|
155
|
+
title_bar_layout = title_bar_pango_layout
|
|
156
|
+
tw, th = title_bar_layout.pixel_size
|
|
157
|
+
tx = (width - tw) / 2
|
|
158
|
+
ty = (TITLE_BAR_SIZE - th) / 2
|
|
159
|
+
context.set_source_color [0, 0, 0, 0.5]
|
|
160
|
+
context.rectangle 0, 0, width, TITLE_BAR_SIZE
|
|
161
|
+
context.fill
|
|
162
|
+
context.move_to tx, ty
|
|
163
|
+
context.set_source_color [0.9, 0.9, 0.9, 1]
|
|
164
|
+
context.show_pango_layout title_bar_layout
|
|
165
|
+
|
|
166
|
+
# resizer
|
|
167
|
+
context.set_source_color [0, 0, 0, 0.5]
|
|
168
|
+
context.rectangle width - RESIZER_SIZE, height - RESIZER_SIZE, RESIZER_SIZE, RESIZER_SIZE
|
|
169
|
+
context.fill
|
|
170
|
+
end
|
|
162
171
|
end
|
|
163
172
|
end
|
|
164
173
|
end
|
|
165
174
|
|
|
166
175
|
if __FILE__ == $0
|
|
176
|
+
Wayland::Protocol.load_yaml File.join(File.dirname(__FILE__), "xdg-decoration-unstable-v1.yaml")
|
|
167
177
|
RWaylandTk.init
|
|
168
178
|
w = MyApplicationWindow.new(640, 480).show
|
|
169
179
|
RWaylandTk.main_loop
|
|
@@ -27,8 +27,8 @@ module RWaylandTk
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def configure(serial)
|
|
30
|
-
@window._configure serial
|
|
31
30
|
ack_configure serial
|
|
31
|
+
@window._configure serial
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -102,16 +102,20 @@ module RWaylandTk
|
|
|
102
102
|
|
|
103
103
|
module WlKeyboard
|
|
104
104
|
def keymap(fmt, fd, size)
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
case fmt
|
|
106
|
+
when Wayland::Wl::Keyboard[:keymap_format].no_keymap
|
|
107
|
+
fd.close
|
|
108
|
+
when Wayland::Wl::Keyboard[:keymap_format].xkb_v1
|
|
109
|
+
shm = Wayland::SharedMemory.new fd, size: size, prot: Wayland::SharedMemory::PROT_READ
|
|
110
|
+
@xkb_ctx = Wayland::Xkb::Context.new
|
|
111
|
+
@xkb_keymap = @xkb_ctx.keymap_new_from_string(shm.address,
|
|
112
|
+
Wayland::XkbSupport::XKB_KEYMAP_FORMAT_TEXT_V1,
|
|
113
|
+
Wayland::XkbSupport::XKB_KEYMAP_COMPILE_NO_FLAGS)
|
|
114
|
+
@xkb_state = @xkb_keymap.state_new
|
|
115
|
+
shm.close
|
|
116
|
+
else
|
|
117
|
+
raise "unknonw keymap format received #{fmt}"
|
|
107
118
|
end
|
|
108
|
-
shm = Wayland::SharedMemory.new fd, size: size, prot: Wayland::SharedMemory::PROT_READ
|
|
109
|
-
@xkb_ctx = Wayland::Xkb::Context.new
|
|
110
|
-
@xkb_keymap = @xkb_ctx.keymap_new_from_string(shm.address,
|
|
111
|
-
Wayland::XkbSupport::XKB_KEYMAP_FORMAT_TEXT_V1,
|
|
112
|
-
Wayland::XkbSupport::XKB_KEYMAP_COMPILE_NO_FLAGS)
|
|
113
|
-
@xkb_state = @xkb_keymap.state_new
|
|
114
|
-
shm.close
|
|
115
119
|
end
|
|
116
120
|
|
|
117
121
|
def enter(serial, surface, keys)
|
|
@@ -157,7 +161,8 @@ module RWaylandTk
|
|
|
157
161
|
module WlRegistry
|
|
158
162
|
def global(name, interface, version)
|
|
159
163
|
if interface == "wl_seat"
|
|
160
|
-
|
|
164
|
+
intf = Wayland::Protocol[:wl_seat]
|
|
165
|
+
bind name, interface, [version, intf[:version]].min, :wl_seat, as: WlSeat
|
|
161
166
|
else
|
|
162
167
|
super
|
|
163
168
|
end
|
|
@@ -14,8 +14,18 @@ module RWaylandTk
|
|
|
14
14
|
@wl_surface = @display[:wl_compositor].create_surface as: [WlSurface, self]
|
|
15
15
|
@xdg_surface = @display[:xdg_wm_base].get_xdg_surface @wl_surface, as: [XdgSurface, self]
|
|
16
16
|
@xdg_toplevel = @xdg_surface.get_toplevel as: [XdgToplevel, self]
|
|
17
|
+
if @display[:zxdg_decoration_manager_v1]
|
|
18
|
+
@server_decoration = true
|
|
19
|
+
dm = @display[:zxdg_decoration_manager_v1]
|
|
20
|
+
@zxdg_toplevel_decoration = dm.get_toplevel_decoration @xdg_toplevel
|
|
21
|
+
mode = @server_decoration ?
|
|
22
|
+
Wayland::Zxdg::ToplevelDecorationV1[:mode][:server_side] :
|
|
23
|
+
Wayland::Zxdg::ToplevelDecorationV1[:mode][:client_side]
|
|
24
|
+
@zxdg_toplevel_decoration.set_mode mode
|
|
25
|
+
end
|
|
17
26
|
end
|
|
18
27
|
attr_reader :width, :height
|
|
28
|
+
attr_reader :server_decoration
|
|
19
29
|
|
|
20
30
|
# User hook
|
|
21
31
|
|
|
@@ -99,6 +109,10 @@ module RWaylandTk
|
|
|
99
109
|
end
|
|
100
110
|
|
|
101
111
|
def _configure(serial)
|
|
112
|
+
p :_configure
|
|
113
|
+
realloc_buffer
|
|
114
|
+
draw
|
|
115
|
+
_expose
|
|
102
116
|
end
|
|
103
117
|
|
|
104
118
|
def _key_down(data)
|
|
@@ -185,10 +199,10 @@ module RWaylandTk
|
|
|
185
199
|
end
|
|
186
200
|
|
|
187
201
|
def show
|
|
188
|
-
invalidate
|
|
189
|
-
realloc_buffer
|
|
190
|
-
draw
|
|
191
|
-
_expose
|
|
202
|
+
# invalidate
|
|
203
|
+
# realloc_buffer
|
|
204
|
+
# draw
|
|
205
|
+
# _expose
|
|
192
206
|
end
|
|
193
207
|
end
|
|
194
208
|
end
|
data/example/rwaylandtk.rb
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
require 'wayland'
|
|
2
2
|
require 'rwaylandtk/custom_wl_interface'
|
|
3
3
|
require 'rwaylandtk/toplevel_window'
|
|
4
|
+
require 'logger'
|
|
4
5
|
|
|
5
6
|
module RWaylandTk
|
|
6
7
|
def self.init
|
|
7
8
|
@@display = Wayland::Wl::Display.connect
|
|
8
|
-
@@display.
|
|
9
|
+
@@display.set_logger Logger.new(STDOUT)
|
|
10
|
+
registry = @@display.get_registry
|
|
11
|
+
registry.set_global_module :wl_seat => CustomWaylandInterface::WlSeat
|
|
9
12
|
@@display.roundtrip
|
|
10
13
|
nil
|
|
11
14
|
end
|
|
@@ -42,22 +42,34 @@ module Wayland
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
def read(bytes)
|
|
46
|
-
retval = String.new
|
|
47
|
-
|
|
45
|
+
def read(bytes, opt = nil)
|
|
46
|
+
retval = opt == :discard ? nil : String.new
|
|
47
|
+
if bytes > self.bytesize
|
|
48
|
+
raise RangeError
|
|
49
|
+
end
|
|
48
50
|
rem = bytes
|
|
51
|
+
rd = @rd
|
|
49
52
|
while rem > 0
|
|
50
|
-
cp_last = (
|
|
51
|
-
cp_cap = cp_last -
|
|
53
|
+
cp_last = (rd <= @wr ? @wr : @buffer.bytesize)
|
|
54
|
+
cp_cap = cp_last - rd
|
|
52
55
|
cp_sz = rem < cp_cap ? rem : cp_cap
|
|
53
|
-
retval << @buffer.byteslice(
|
|
56
|
+
retval << @buffer.byteslice(rd, cp_sz) unless opt == :discard
|
|
54
57
|
rem -= cp_sz
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
rd += cp_sz
|
|
59
|
+
rd = 0 if rd >= @buffer.bytesize
|
|
57
60
|
end
|
|
61
|
+
@rd = rd unless opt == :peek
|
|
58
62
|
retval
|
|
59
63
|
end
|
|
60
64
|
|
|
65
|
+
def peek(bytesize)
|
|
66
|
+
read bytesize, :peek
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def discard(bytesize)
|
|
70
|
+
read bytesize, :discard
|
|
71
|
+
end
|
|
72
|
+
|
|
61
73
|
def read_object
|
|
62
74
|
read_uint
|
|
63
75
|
end
|
data/lib/wayland/protocol.rb
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
require 'yaml'
|
|
2
2
|
require 'wayland/wlobject'
|
|
3
|
-
require 'wayland/
|
|
3
|
+
require 'wayland/util'
|
|
4
4
|
|
|
5
5
|
module Wayland
|
|
6
6
|
module Protocol
|
|
7
|
+
INT_RANGE = (-2147483648..2147483647)
|
|
8
|
+
UINT_RANGE = (0..4294967295)
|
|
9
|
+
CLIENT_OBJECT_RANGE = (1..0xFEFFFFFF)
|
|
10
|
+
FIXED_RANGE = ((-0x80000000.to_f / 2**8)..(0x7fffffff.to_f / 2**8))
|
|
11
|
+
|
|
7
12
|
@interfaces = {}
|
|
8
13
|
|
|
9
14
|
TYPE_TEMPLATE_CHAR = {
|
|
@@ -20,15 +25,185 @@ module Wayland
|
|
|
20
25
|
self.load YAML.load_file(yaml)
|
|
21
26
|
end
|
|
22
27
|
|
|
28
|
+
def get_module(mname)
|
|
29
|
+
if Wayland.const_defined? mname
|
|
30
|
+
Wayland.const_get mname
|
|
31
|
+
else
|
|
32
|
+
Wayland.const_set mname, Module.new
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def setup_request_methods(clazz, requests)
|
|
37
|
+
requests.each do |name, rspec|
|
|
38
|
+
arg_types = rspec[:args].map{|a| a[:type] }
|
|
39
|
+
rspec[:pack_template] = "LL" + TYPE_TEMPLATE_CHAR.values_at(*arg_types).join
|
|
40
|
+
rspec[:base_size] = arg_types.inject(8 << 16) do |r, type|
|
|
41
|
+
r + case type
|
|
42
|
+
when :string, :array, :fd
|
|
43
|
+
0
|
|
44
|
+
else
|
|
45
|
+
4 << 16
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
clazz.define_method name do |*args, **hash|
|
|
49
|
+
rspec = Wayland::Protocol[ifname][:requests][__callee__]
|
|
50
|
+
Protocol.send_request @display, self, __callee__, rspec, *args, **hash
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def setup_enums(clazz, enums)
|
|
56
|
+
hash = Hash.new
|
|
57
|
+
enums.each do |enum|
|
|
58
|
+
ename = enum[:name]
|
|
59
|
+
names = enum[:entries].map{|ent| ent[:name] }
|
|
60
|
+
values = enum[:entries].map{|ent| ent[:value] }
|
|
61
|
+
hash[ename] = Struct.new(*names).new(*values).freeze
|
|
62
|
+
end
|
|
63
|
+
hash.freeze
|
|
64
|
+
clazz.const_set :WL_ENUMS, hash
|
|
65
|
+
clazz.define_singleton_method(:[]){|n| self.const_get(:WL_ENUMS)[n] }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def define_class(ifname)
|
|
69
|
+
mname, cname = Util.ifname_to_cname ifname
|
|
70
|
+
mod = get_module(mname)
|
|
71
|
+
clazz = Class.new(Wayland::WLObject)
|
|
72
|
+
mod.const_set cname, clazz
|
|
73
|
+
clazz.const_set :IFNAME, ifname.freeze
|
|
74
|
+
clazz.define_method(:ifname){ self.class.const_get(:IFNAME) }
|
|
75
|
+
clazz
|
|
76
|
+
end
|
|
77
|
+
|
|
23
78
|
def load(data)
|
|
24
|
-
ns = Wayland
|
|
25
79
|
@interfaces.merge! data
|
|
26
|
-
data.each do |ifname,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
80
|
+
data.each do |ifname, ispec|
|
|
81
|
+
clazz = define_class(ifname)
|
|
82
|
+
setup_request_methods clazz, ispec[:requests]
|
|
83
|
+
setup_enums clazz, ispec[:enums]
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def check_int(value)
|
|
88
|
+
value.is_a?(Integer) && INT_RANGE.include?(value)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def check_uint(value)
|
|
92
|
+
value.is_a?(Integer) && UINT_RANGE.include?(value)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def check_fixed(value)
|
|
96
|
+
value.is_a?(Float) && FIXED_RANGE.include?(value)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def send_request(display, wlobj, sym, rspec, *margs, as: nil)
|
|
100
|
+
pack_template = rspec[:pack_template]
|
|
101
|
+
size = rspec[:base_size]
|
|
102
|
+
opcode = rspec[:opcode]
|
|
103
|
+
alist = [wlobj.wl_object_id, 0]
|
|
104
|
+
obj = nil
|
|
105
|
+
ancdata = nil
|
|
106
|
+
i = 0
|
|
107
|
+
rspec[:args].each do |arg|
|
|
108
|
+
case arg[:type]
|
|
109
|
+
when :string, :array
|
|
110
|
+
str, str_size = Util.pad_string margs[i], arg[:type] == :string
|
|
111
|
+
size += (str.bytesize + 4) << 16
|
|
112
|
+
alist << str_size
|
|
113
|
+
alist << str
|
|
114
|
+
i += 1
|
|
115
|
+
when :new_id
|
|
116
|
+
interface = arg[:interface]
|
|
117
|
+
if interface
|
|
118
|
+
obj = display.create_object interface, nil, as
|
|
119
|
+
else
|
|
120
|
+
obj = display.create_object margs[i], nil, as
|
|
121
|
+
i += 1
|
|
122
|
+
end
|
|
123
|
+
alist << obj.wl_object_id
|
|
124
|
+
when :fd
|
|
125
|
+
ancdata = Socket::AncillaryData.int(:UNIX, :SOCKET, :RIGHTS, margs[i])
|
|
126
|
+
i += 1
|
|
127
|
+
when :object
|
|
128
|
+
alist << margs[i].wl_object_id
|
|
129
|
+
i += 1
|
|
130
|
+
when :fixed
|
|
131
|
+
alist << (margs[i] * (2 ** 8)).to_i
|
|
132
|
+
i += 1
|
|
133
|
+
else
|
|
134
|
+
alist << margs[i]
|
|
135
|
+
i += 1
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
alist[1] = opcode | size
|
|
139
|
+
message = alist.pack pack_template
|
|
140
|
+
display.request_log wlobj, sym, pack_template, *alist, message
|
|
141
|
+
if ancdata
|
|
142
|
+
display.socket.sendmsg message, 0, nil, ancdata
|
|
143
|
+
else
|
|
144
|
+
display.socket.sendmsg message, 0, nil
|
|
145
|
+
end
|
|
146
|
+
return obj
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def dispatch(display, buffer, ios)
|
|
150
|
+
count = 0
|
|
151
|
+
loop do
|
|
152
|
+
break if buffer.bytesize < 8
|
|
153
|
+
oid, opsz = buffer.peek(8).unpack "LL"
|
|
154
|
+
if oid == 0
|
|
155
|
+
buffer.discard 8
|
|
156
|
+
next
|
|
157
|
+
end
|
|
158
|
+
opcode = opsz & 0xffff
|
|
159
|
+
size = (opsz >> 16)
|
|
160
|
+
break if buffer.bytesize < size
|
|
161
|
+
buffer.discard 8
|
|
162
|
+
dispatch_event display, oid, opcode, buffer, size - 8, ios
|
|
163
|
+
count += 1
|
|
164
|
+
end
|
|
165
|
+
count
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
GUARD = WLObject.new nil, nil
|
|
169
|
+
|
|
170
|
+
def dispatch_event(display, oid, opcode, buffer, size, ios)
|
|
171
|
+
object = display.get_object oid
|
|
172
|
+
raise "object 0x#{oid.to_s(16)} not found" unless object
|
|
173
|
+
intf = Protocol[object.ifname]
|
|
174
|
+
evs = intf[:events]
|
|
175
|
+
ev = evs ? evs[opcode] : nil
|
|
176
|
+
unless ev
|
|
177
|
+
pp [opcode, object.ifname, evs]
|
|
178
|
+
raise RuntimeError
|
|
179
|
+
end
|
|
180
|
+
name = ev[:name]
|
|
181
|
+
args = ev[:args].map do |a|
|
|
182
|
+
case a[:type]
|
|
183
|
+
when :int
|
|
184
|
+
buffer.read_int
|
|
185
|
+
when :uint
|
|
186
|
+
buffer.read_uint
|
|
187
|
+
when :object
|
|
188
|
+
display.get_object buffer.read_object
|
|
189
|
+
when :fixed
|
|
190
|
+
buffer.read_fixed
|
|
191
|
+
when :new_id
|
|
192
|
+
display.create_object a[:interface], buffer.read_object
|
|
193
|
+
when :string
|
|
194
|
+
buffer.read_string
|
|
195
|
+
when :array
|
|
196
|
+
buffer.read_array
|
|
197
|
+
when :fd
|
|
198
|
+
ios.shift || raise("no io for fd arg")
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
f = object.respond_to?(name)
|
|
202
|
+
if f && GUARD.respond_to?(name)
|
|
203
|
+
raise "event #{name} rejected"
|
|
31
204
|
end
|
|
205
|
+
display.event_log f, oid, object.ifname, name, *args
|
|
206
|
+
object.__send__ name, *args if f
|
|
32
207
|
end
|
|
33
208
|
end
|
|
34
209
|
end
|
data/lib/wayland/util.rb
CHANGED
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
module Wayland
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
module Util
|
|
3
|
+
ZERO4 = "\0" * 4
|
|
4
|
+
|
|
5
|
+
module_function
|
|
6
|
+
|
|
7
|
+
def ifname_to_cname(ifname)
|
|
4
8
|
a = ifname.to_s.split("_").map{|i| i.capitalize }
|
|
5
9
|
mod = a.shift
|
|
6
10
|
c = a.join
|
|
7
11
|
return mod, c
|
|
8
12
|
end
|
|
13
|
+
|
|
14
|
+
# append zero to +str+ to be 4B aligned
|
|
15
|
+
#
|
|
16
|
+
# +str+ :: string
|
|
17
|
+
# +zterm+ :: returns zero terminated string
|
|
18
|
+
# +return+ :: string, str_size
|
|
19
|
+
#
|
|
20
|
+
def pad_string(str, zterm)
|
|
21
|
+
len = str.bytesize
|
|
22
|
+
pad = 4 - (len % 4)
|
|
23
|
+
zterm = zterm && (str.getbyte(-1) != 0)
|
|
24
|
+
if pad == 4 && !zterm
|
|
25
|
+
str
|
|
26
|
+
else
|
|
27
|
+
str.dup.bytesplice(len, pad, ZERO4, 0, pad)
|
|
28
|
+
end
|
|
29
|
+
return str, len + (zterm ? 1 : 0)
|
|
30
|
+
end
|
|
9
31
|
end
|
|
10
32
|
end
|
data/lib/wayland/wl/display.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'socket'
|
|
2
2
|
require 'wayland/wlobject'
|
|
3
|
-
require 'wayland/
|
|
3
|
+
require 'wayland/message_buffer'
|
|
4
4
|
require 'wayland/free_list'
|
|
5
5
|
require 'wayland/object_manager'
|
|
6
6
|
require 'wayland/util'
|
|
@@ -14,25 +14,24 @@ module Wayland
|
|
|
14
14
|
|
|
15
15
|
def initialize(wl_object_id)
|
|
16
16
|
super wl_object_id, self
|
|
17
|
-
@
|
|
17
|
+
@message_buffer = MessageBuffer.new
|
|
18
|
+
@ios = []
|
|
18
19
|
end
|
|
20
|
+
attr_reader :socket
|
|
19
21
|
|
|
20
22
|
def dispatch(timeout = nil)
|
|
21
23
|
count = 0
|
|
22
24
|
rd = [@socket]
|
|
23
|
-
ios = []
|
|
24
25
|
loop do
|
|
25
26
|
if IO.select(rd, [], [], timeout)
|
|
26
27
|
str, addr, int, *ctls = @socket.recvmsg(256, 0, nil, :scm_rights => true)
|
|
27
|
-
|
|
28
|
+
@message_buffer.write str
|
|
28
29
|
ctls.each do |a|
|
|
29
30
|
if a.cmsg_is?(:SOCKET, :RIGHTS)
|
|
30
|
-
a.unix_rights.each{|io| ios << io }
|
|
31
|
+
a.unix_rights.each{|io| @ios << io }
|
|
31
32
|
end
|
|
32
33
|
end
|
|
33
|
-
|
|
34
|
-
count = @dispatcher.feed str, ios
|
|
35
|
-
ios.clear
|
|
34
|
+
count = Protocol.dispatch self, @message_buffer, @ios
|
|
36
35
|
end
|
|
37
36
|
break if count > 0 || timeout
|
|
38
37
|
end
|
|
@@ -101,17 +100,8 @@ module Wayland
|
|
|
101
100
|
@object_manager[key]
|
|
102
101
|
end
|
|
103
102
|
|
|
104
|
-
def sendmsg(message, ancdata = nil)
|
|
105
|
-
if ancdata
|
|
106
|
-
@socket.sendmsg message, 0, nil, ancdata
|
|
107
|
-
else
|
|
108
|
-
@socket.sendmsg message, 0, nil
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
103
|
def disconnect
|
|
113
104
|
if @socket
|
|
114
|
-
@dispatcher.close
|
|
115
105
|
@socket.close
|
|
116
106
|
@socket = nil
|
|
117
107
|
end
|
|
@@ -137,7 +127,8 @@ module Wayland
|
|
|
137
127
|
end
|
|
138
128
|
|
|
139
129
|
def request_log(obj, name, *a)
|
|
140
|
-
|
|
130
|
+
b = a.map{|e| Integer === e ? "0x%08x" % e : e }
|
|
131
|
+
@logger&.debug "RQ: (#{obj.wl_object_id}) #{obj.ifname}::#{name} #{b}"
|
|
141
132
|
end
|
|
142
133
|
|
|
143
134
|
def create_log(obj)
|
data/lib/wayland/wl/registry.rb
CHANGED
|
@@ -4,11 +4,17 @@ require 'wayland/protocol'
|
|
|
4
4
|
module Wayland
|
|
5
5
|
module Wl
|
|
6
6
|
class Registry < WLObject
|
|
7
|
+
def set_global_module(hash)
|
|
8
|
+
@global_modules ||= Hash.new
|
|
9
|
+
@global_modules.merge! hash
|
|
10
|
+
end
|
|
11
|
+
|
|
7
12
|
def global(name, interface, version)
|
|
8
13
|
sym = interface.to_sym
|
|
9
14
|
intf = Protocol[sym]
|
|
10
15
|
if intf
|
|
11
|
-
|
|
16
|
+
mod = @global_modules ? @global_modules[sym] : nil
|
|
17
|
+
bind name, interface, [version, intf[:version]].min, sym, as: mod
|
|
12
18
|
end
|
|
13
19
|
end
|
|
14
20
|
end
|
data/lib/wayland/wlobject.rb
CHANGED
|
@@ -2,11 +2,6 @@ require 'wayland/protocol'
|
|
|
2
2
|
|
|
3
3
|
module Wayland
|
|
4
4
|
class WLObject
|
|
5
|
-
INT_RANGE = (-2147483648..2147483647)
|
|
6
|
-
UINT_RANGE = (0..4294967295)
|
|
7
|
-
CLIENT_OBJECT_RANGE = (1..0xFEFFFFFF)
|
|
8
|
-
FIXED_RANGE = ((-0x80000000.to_f / 2**8)..(0x7fffffff.to_f / 2**8))
|
|
9
|
-
|
|
10
5
|
attr_reader :wl_object_id
|
|
11
6
|
undef :initialize_copy
|
|
12
7
|
|
|
@@ -34,33 +29,5 @@ module Wayland
|
|
|
34
29
|
define_singleton_method event do |*a| delegate.__send__ name, *a end
|
|
35
30
|
self
|
|
36
31
|
end
|
|
37
|
-
|
|
38
|
-
def pad_array(s)
|
|
39
|
-
len = s.bytesize
|
|
40
|
-
pad = (4 - (len & 3)) & 3
|
|
41
|
-
s << "\0" * pad
|
|
42
|
-
s
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def pad_string(str)
|
|
46
|
-
s = str.getbyte(-1) > 0 ? str + "\0" : str
|
|
47
|
-
pad_array(s)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def check_int(value)
|
|
51
|
-
value.is_a?(Integer) && INT_RANGE.include?(value)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def check_uint(value)
|
|
55
|
-
value.is_a?(Integer) && UINT_RANGE.include?(value)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def check_fixed(value)
|
|
59
|
-
value.is_a?(Float) && FIXED_RANGE.include?(value)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def deleted
|
|
63
|
-
@display.delete_log self
|
|
64
|
-
end
|
|
65
32
|
end
|
|
66
33
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rwayland
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- nmbits
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: Ruby bindings for Wayland protocol.
|
|
13
13
|
email:
|
|
@@ -26,9 +26,6 @@ files:
|
|
|
26
26
|
- example/rwaylandtk/toplevel_window.rb
|
|
27
27
|
- lib/wayland.rb
|
|
28
28
|
- lib/wayland/cairo_support.rb
|
|
29
|
-
- lib/wayland/code_generator.rb
|
|
30
|
-
- lib/wayland/code_template.erb
|
|
31
|
-
- lib/wayland/dispatcher.rb
|
|
32
29
|
- lib/wayland/free_list.rb
|
|
33
30
|
- lib/wayland/message_buffer.rb
|
|
34
31
|
- lib/wayland/object_manager.rb
|
|
@@ -61,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
61
58
|
- !ruby/object:Gem::Version
|
|
62
59
|
version: '0'
|
|
63
60
|
requirements: []
|
|
64
|
-
rubygems_version: 3.6.
|
|
61
|
+
rubygems_version: 3.6.7
|
|
65
62
|
specification_version: 4
|
|
66
63
|
summary: Ruby bindings for Wayland protocol.
|
|
67
64
|
test_files: []
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
require 'erb'
|
|
2
|
-
require 'wayland/util'
|
|
3
|
-
require 'wayland/wlobject'
|
|
4
|
-
|
|
5
|
-
module Wayland
|
|
6
|
-
class CodeGenerator
|
|
7
|
-
TYPE_TEMPLATE_CHAR = {
|
|
8
|
-
int: 'l', uint: 'L', fixed: 'l', object: 'L', new_id: 'L', string: 'La*', array: 'La*', fd: ''
|
|
9
|
-
}
|
|
10
|
-
TEMPLATE_FILE_NAME = "code_template.erb"
|
|
11
|
-
|
|
12
|
-
def initialize(ifname, ispec, arg_check: false)
|
|
13
|
-
mod_name, class_name = Util.ifname_to_cname ifname
|
|
14
|
-
@ifname = ifname
|
|
15
|
-
@mod_name = mod_name
|
|
16
|
-
@class_name = class_name
|
|
17
|
-
@ispec = ispec
|
|
18
|
-
@arg_check = arg_check
|
|
19
|
-
end
|
|
20
|
-
attr_reader :mod_name, :class_name, :ispec, :ifname, :arg_check
|
|
21
|
-
|
|
22
|
-
def generate
|
|
23
|
-
template_file = File.join File.dirname(__FILE__), TEMPLATE_FILE_NAME
|
|
24
|
-
template = File.read template_file
|
|
25
|
-
erb = ERB.new template, trim_mode: '%'
|
|
26
|
-
erb.result binding
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def args_string(args)
|
|
30
|
-
ary = []
|
|
31
|
-
new_id = false
|
|
32
|
-
args.each do |a|
|
|
33
|
-
case a[:type]
|
|
34
|
-
when :int, :uint, :object, :string, :array, :fd
|
|
35
|
-
ary << a[:name]
|
|
36
|
-
when :new_id
|
|
37
|
-
ary << a[:name] unless a[:interface]
|
|
38
|
-
new_id = true
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
ary << "as: nil" if new_id
|
|
42
|
-
ary.join(', ')
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def pack_template_char(type)
|
|
46
|
-
TYPE_TEMPLATE_CHAR[type]
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def message_base_size(args)
|
|
50
|
-
args.inject(8 << 16) do |r, a|
|
|
51
|
-
r + case a[:type]
|
|
52
|
-
when :string, :array, :fd
|
|
53
|
-
0
|
|
54
|
-
else
|
|
55
|
-
4 << 16
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
if __FILE__ == $0
|
|
63
|
-
require 'yaml'
|
|
64
|
-
yaml = File.join File.dirname(__FILE__), 'wayland.yaml'
|
|
65
|
-
data = YAML.load_file yaml
|
|
66
|
-
data.each do |ifname, ispec|
|
|
67
|
-
gen = Wayland::CodeGenerator.new ifname, ispec
|
|
68
|
-
print gen.generate
|
|
69
|
-
end
|
|
70
|
-
end
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
module Wayland::<%= mod_name %>
|
|
2
|
-
class <%= class_name %> < Wayland::WLObject
|
|
3
|
-
VERSION = <%= ispec[:version] %>
|
|
4
|
-
% ispec[:requests].each do |name, rspec|
|
|
5
|
-
% opcode = rspec[:opcode]
|
|
6
|
-
% f_anc = false
|
|
7
|
-
% f_new = false
|
|
8
|
-
% message_size = 0
|
|
9
|
-
% astring = args_string rspec[:args]
|
|
10
|
-
def <%= name %>(<%= astring %>)
|
|
11
|
-
_alist = [wl_object_id, 0]
|
|
12
|
-
_size = 0x<%= message_base_size(rspec[:args]).to_s(16) %>
|
|
13
|
-
% pack_template = "LL"
|
|
14
|
-
% rspec[:args].each_with_index do |arg, i|
|
|
15
|
-
% type = arg[:type]
|
|
16
|
-
% name = arg[:name]
|
|
17
|
-
% pack_template << pack_template_char(type)
|
|
18
|
-
% case type
|
|
19
|
-
% when :string, :array
|
|
20
|
-
% if arg_check
|
|
21
|
-
check_<%= type %>(<%= name %>) || raise(ArgumentError, "invalid argument #<%= i %>")
|
|
22
|
-
% end
|
|
23
|
-
_str = pad_<%= type %> <%= name %>
|
|
24
|
-
_str_size = _str.bytesize
|
|
25
|
-
_size += (_str_size + 4) << 16
|
|
26
|
-
_alist << _str_size
|
|
27
|
-
_alist << _str
|
|
28
|
-
% when :new_id
|
|
29
|
-
% f_new = true
|
|
30
|
-
% interface = arg[:interface]
|
|
31
|
-
% if interface
|
|
32
|
-
_obj = @display.create_object :<%= interface %>, nil, as
|
|
33
|
-
% else
|
|
34
|
-
_obj = @display.create_object <%= name %>, nil, as
|
|
35
|
-
% end
|
|
36
|
-
_alist << _obj.wl_object_id
|
|
37
|
-
% when :fd
|
|
38
|
-
% f_anc = true
|
|
39
|
-
_ancdata = Socket::AncillaryData.int(:UNIX, :SOCKET, :RIGHTS, <%= name %>)
|
|
40
|
-
% when :object
|
|
41
|
-
_alist << <%= name %>.wl_object_id
|
|
42
|
-
% when :fixed
|
|
43
|
-
% if arg_check
|
|
44
|
-
check_fixed(<%= name %>) || raise(ArgumentError, "invalid argument #<%= i %>")
|
|
45
|
-
% end
|
|
46
|
-
_alist << (<%= name %> * (2 ** 8)).to_i
|
|
47
|
-
% else
|
|
48
|
-
% if arg_check
|
|
49
|
-
check_<%= type %>(<%= name %>) || raise(ArgumentError, "invalid argument #<%= i %>")
|
|
50
|
-
% end
|
|
51
|
-
_alist << <%= name %>
|
|
52
|
-
% end # case type
|
|
53
|
-
% end
|
|
54
|
-
_alist[1] = <%= opcode %> | _size
|
|
55
|
-
_message = _alist.pack "<%= pack_template %>"
|
|
56
|
-
% if f_anc
|
|
57
|
-
@display.sendmsg _message, _ancdata
|
|
58
|
-
% else
|
|
59
|
-
@display.sendmsg _message
|
|
60
|
-
% end
|
|
61
|
-
% if astring.empty?
|
|
62
|
-
@display.request_log self, __callee__
|
|
63
|
-
% else
|
|
64
|
-
@display.request_log self, __callee__, *_alist
|
|
65
|
-
% end
|
|
66
|
-
% if f_new
|
|
67
|
-
return _obj
|
|
68
|
-
% else
|
|
69
|
-
return nil
|
|
70
|
-
% end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
% end # ispec[:requests].each
|
|
74
|
-
% if ispec[:enums].size > 0
|
|
75
|
-
@__enums = {}
|
|
76
|
-
% ispec[:enums].each do |e|
|
|
77
|
-
% n = e[:name]
|
|
78
|
-
% names = e[:entries].map {|ent| ":\"" + ent[:name].to_s + "\"" }.join(", ")
|
|
79
|
-
% values = e[:entries].map {|ent| ent[:value] }.join(", ")
|
|
80
|
-
@__enums[:<%= n %>] = Struct.new(<%= names %>).new(<%= values %>).freeze
|
|
81
|
-
% end
|
|
82
|
-
@__enums.freeze
|
|
83
|
-
def self.[](n); @__enums[n] end
|
|
84
|
-
% end
|
|
85
|
-
|
|
86
|
-
# ifname
|
|
87
|
-
def ifname; :<%= ifname %> end
|
|
88
|
-
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
data/lib/wayland/dispatcher.rb
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
require 'wayland/wlobject'
|
|
2
|
-
require 'wayland/protocol'
|
|
3
|
-
require 'wayland/message_buffer'
|
|
4
|
-
|
|
5
|
-
module Wayland
|
|
6
|
-
class Dispatcher
|
|
7
|
-
def initialize(wl_display)
|
|
8
|
-
@phase = :header
|
|
9
|
-
@buffer = MessageBuffer.new
|
|
10
|
-
@ios = []
|
|
11
|
-
@display = wl_display
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def feed(data, ios)
|
|
15
|
-
raise "closed" if @close_requested
|
|
16
|
-
count = 0
|
|
17
|
-
@buffer.write data
|
|
18
|
-
@ios.concat ios
|
|
19
|
-
loop do
|
|
20
|
-
case @phase
|
|
21
|
-
when :header
|
|
22
|
-
break if @buffer.bytesize < 8
|
|
23
|
-
@oid = @buffer.read_object
|
|
24
|
-
opsz = @buffer.read_uint
|
|
25
|
-
@opcode = opsz & 0xffff
|
|
26
|
-
@size = (opsz >> 16) - 8
|
|
27
|
-
next if @oid == 0
|
|
28
|
-
@phase = :args
|
|
29
|
-
when :args
|
|
30
|
-
break if @buffer.bytesize < @size
|
|
31
|
-
dispatch @oid, @opcode, @buffer, @size
|
|
32
|
-
count += 1
|
|
33
|
-
@phase = :header
|
|
34
|
-
break if @close_requested
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
# Wayland.logger.debug "feed: #{@buffer.bytesize}"
|
|
38
|
-
count
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def dispatch(oid, op, buffer, size)
|
|
42
|
-
object = @display.get_object oid
|
|
43
|
-
raise "object 0x#{@oid.to_s(16)} not found" unless object
|
|
44
|
-
intf = Protocol[object.ifname]
|
|
45
|
-
evs = intf[:events]
|
|
46
|
-
ev = evs ? evs[op] : nil
|
|
47
|
-
unless ev
|
|
48
|
-
pp [op, object.ifname, evs]
|
|
49
|
-
raise RuntimeError
|
|
50
|
-
end
|
|
51
|
-
name = ev[:name]
|
|
52
|
-
args = ev[:args].map do |a|
|
|
53
|
-
case a[:type]
|
|
54
|
-
when :int
|
|
55
|
-
buffer.read_int
|
|
56
|
-
when :uint
|
|
57
|
-
buffer.read_uint
|
|
58
|
-
when :object
|
|
59
|
-
@display.get_object buffer.read_object
|
|
60
|
-
when :fixed
|
|
61
|
-
buffer.read_fixed
|
|
62
|
-
when :new_id
|
|
63
|
-
@display.create_object a[:interface], buffer.read_object
|
|
64
|
-
when :string
|
|
65
|
-
buffer.read_string
|
|
66
|
-
when :array
|
|
67
|
-
buffer.read_array
|
|
68
|
-
when :fd
|
|
69
|
-
@ios.shift || raise("no io for fd arg")
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
f = object.respond_to? name
|
|
73
|
-
@display.event_log f, oid, object.ifname, name, *args
|
|
74
|
-
object.__send__ name, *args if f
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def close
|
|
78
|
-
@buffer.clear
|
|
79
|
-
@close_requested = true
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|