Explicitly handle case where not all globals exist
parent
e66fbb225b
commit
47c57a5b87
|
@ -31,9 +31,9 @@ pub fn main() !void {
|
||||||
try socket.writeAll(std.mem.sliceAsBytes(message));
|
try socket.writeAll(std.mem.sliceAsBytes(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
var shm_id: u32 = id_pool.create();
|
var shm_id_opt: ?u32 = null;
|
||||||
var compositor_id: u32 = id_pool.create();
|
var compositor_id_opt: ?u32 = null;
|
||||||
var xdg_wm_base_id: u32 = id_pool.create();
|
var xdg_wm_base_id_opt: ?u32 = null;
|
||||||
|
|
||||||
var message_buffer = std.ArrayList(u32).init(gpa);
|
var message_buffer = std.ArrayList(u32).init(gpa);
|
||||||
defer message_buffer.deinit();
|
defer message_buffer.deinit();
|
||||||
|
@ -54,6 +54,7 @@ pub fn main() !void {
|
||||||
.global => |global| {
|
.global => |global| {
|
||||||
var buffer: [20]u32 = undefined;
|
var buffer: [20]u32 = undefined;
|
||||||
if (std.mem.eql(u8, global.interface, "wl_shm")) {
|
if (std.mem.eql(u8, global.interface, "wl_shm")) {
|
||||||
|
shm_id_opt = id_pool.create();
|
||||||
const message = try wayland.serialize(
|
const message = try wayland.serialize(
|
||||||
wayland.core.Registry.Request,
|
wayland.core.Registry.Request,
|
||||||
&buffer,
|
&buffer,
|
||||||
|
@ -62,11 +63,12 @@ pub fn main() !void {
|
||||||
.name = global.name,
|
.name = global.name,
|
||||||
.interface = global.interface,
|
.interface = global.interface,
|
||||||
.version = global.version,
|
.version = global.version,
|
||||||
.new_id = shm_id,
|
.new_id = shm_id_opt.?,
|
||||||
} },
|
} },
|
||||||
);
|
);
|
||||||
try socket.writeAll(std.mem.sliceAsBytes(message));
|
try socket.writeAll(std.mem.sliceAsBytes(message));
|
||||||
} else if (std.mem.eql(u8, global.interface, "wl_compositor")) {
|
} else if (std.mem.eql(u8, global.interface, wayland.core.Compositor.INTERFACE)) {
|
||||||
|
compositor_id_opt = id_pool.create();
|
||||||
const message = try wayland.serialize(
|
const message = try wayland.serialize(
|
||||||
wayland.core.Registry.Request,
|
wayland.core.Registry.Request,
|
||||||
&buffer,
|
&buffer,
|
||||||
|
@ -75,11 +77,12 @@ pub fn main() !void {
|
||||||
.name = global.name,
|
.name = global.name,
|
||||||
.interface = global.interface,
|
.interface = global.interface,
|
||||||
.version = global.version,
|
.version = global.version,
|
||||||
.new_id = compositor_id,
|
.new_id = compositor_id_opt.?,
|
||||||
} },
|
} },
|
||||||
);
|
);
|
||||||
try socket.writeAll(std.mem.sliceAsBytes(message));
|
try socket.writeAll(std.mem.sliceAsBytes(message));
|
||||||
} else if (std.mem.eql(u8, global.interface, "xdg_wm_base")) {
|
} else if (std.mem.eql(u8, global.interface, "xdg_wm_base")) {
|
||||||
|
xdg_wm_base_id_opt = id_pool.create();
|
||||||
const message = try wayland.serialize(
|
const message = try wayland.serialize(
|
||||||
wayland.core.Registry.Request,
|
wayland.core.Registry.Request,
|
||||||
&buffer,
|
&buffer,
|
||||||
|
@ -88,7 +91,7 @@ pub fn main() !void {
|
||||||
.name = global.name,
|
.name = global.name,
|
||||||
.interface = global.interface,
|
.interface = global.interface,
|
||||||
.version = global.version,
|
.version = global.version,
|
||||||
.new_id = xdg_wm_base_id,
|
.new_id = xdg_wm_base_id_opt.?,
|
||||||
} },
|
} },
|
||||||
);
|
);
|
||||||
try socket.writeAll(std.mem.sliceAsBytes(message));
|
try socket.writeAll(std.mem.sliceAsBytes(message));
|
||||||
|
@ -103,6 +106,10 @@ pub fn main() !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const shm_id = shm_id_opt orelse return error.NeccessaryWaylandExtensionMissing;
|
||||||
|
const compositor_id = compositor_id_opt orelse return error.NeccessaryWaylandExtensionMissing;
|
||||||
|
const xdg_wm_base_id = xdg_wm_base_id_opt orelse return error.NeccessaryWaylandExtensionMissing;
|
||||||
|
|
||||||
const surface_id = id_pool.create();
|
const surface_id = id_pool.create();
|
||||||
{
|
{
|
||||||
var buffer: [10]u32 = undefined;
|
var buffer: [10]u32 = undefined;
|
||||||
|
|
|
@ -85,6 +85,8 @@ pub const Registry = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Compositor = struct {
|
pub const Compositor = struct {
|
||||||
|
pub const INTERFACE = "wl_compositor";
|
||||||
|
|
||||||
pub const Request = union(Request.Tag) {
|
pub const Request = union(Request.Tag) {
|
||||||
create_surface: CreateSurface,
|
create_surface: CreateSurface,
|
||||||
create_region: CreateRegion,
|
create_region: CreateRegion,
|
||||||
|
|
Loading…
Reference in New Issue