Add support for reading arrays from messages
parent
8b50eeb7eb
commit
846f81b838
|
@ -370,16 +370,13 @@ pub fn main() !void {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else if (header.object_id == xdg_toplevel_id) {
|
} else if (header.object_id == xdg_toplevel_id) {
|
||||||
// const event = try wayland.deserialize(wayland.xdg.Toplevel.Event, header, message_buffer.items);
|
const event = try wayland.deserialize(wayland.xdg.Toplevel.Event, header, message_buffer.items);
|
||||||
// std.debug.print("<- {}\n", .{event});
|
switch (event) {
|
||||||
switch (@as(std.meta.Tag(wayland.xdg.Toplevel.Event), @enumFromInt(header.size_and_opcode.opcode))) {
|
.configure => |conf| {
|
||||||
.configure => {
|
std.debug.print("<- xdg_toplevel@{} configure <{}, {}> {any}\n", .{ header.object_id, conf.width, conf.height, conf.states });
|
||||||
const width: i32 = @intCast(message_buffer.items[0]);
|
|
||||||
const height: i32 = @intCast(message_buffer.items[1]);
|
|
||||||
std.debug.print("<- xdg_toplevel@{} configure <{}, {}>\n", .{ header.object_id, width, height });
|
|
||||||
},
|
},
|
||||||
.close => running = false,
|
.close => running = false,
|
||||||
else => |tag| std.debug.print("<- xdg_toplevel@{} {s} {}\n", .{ header.object_id, @tagName(tag), std.zig.fmtEscapes(std.mem.sliceAsBytes(message_buffer.items)) }),
|
else => |tag| std.debug.print("<- xdg_toplevel@{} {s} {}\n", .{ header.object_id, @tagName(tag), event }),
|
||||||
}
|
}
|
||||||
} else if (header.object_id == wl_buffer_id) {
|
} else if (header.object_id == wl_buffer_id) {
|
||||||
const event = try wayland.deserialize(wayland.core.Buffer.Event, header, message_buffer.items);
|
const event = try wayland.deserialize(wayland.core.Buffer.Event, header, message_buffer.items);
|
||||||
|
|
16
src/main.zig
16
src/main.zig
|
@ -91,6 +91,18 @@ pub fn readString(buffer: []const u32, parent_pos: *usize) ![:0]const u8 {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn readArray(comptime T: type, buffer: []const u32, parent_pos: *usize) ![]const T {
|
||||||
|
var pos = parent_pos.*;
|
||||||
|
|
||||||
|
const byte_size = try readUInt(buffer, &pos);
|
||||||
|
|
||||||
|
const array = @as([*]const T, @ptrCast(buffer[pos..].ptr))[0 .. byte_size / @sizeOf(T)];
|
||||||
|
pos += byte_size / @sizeOf(u32);
|
||||||
|
|
||||||
|
parent_pos.* = pos;
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn deserializeArguments(comptime Signature: type, buffer: []const u32) !Signature {
|
pub fn deserializeArguments(comptime Signature: type, buffer: []const u32) !Signature {
|
||||||
if (Signature == void) return {};
|
if (Signature == void) return {};
|
||||||
var result: Signature = undefined;
|
var result: Signature = undefined;
|
||||||
|
@ -102,8 +114,10 @@ pub fn deserializeArguments(comptime Signature: type, buffer: []const u32) !Sign
|
||||||
.unsigned => @field(result, field.name) = try readUInt(buffer, &pos),
|
.unsigned => @field(result, field.name) = try readUInt(buffer, &pos),
|
||||||
},
|
},
|
||||||
.Pointer => |ptr| switch (ptr.size) {
|
.Pointer => |ptr| switch (ptr.size) {
|
||||||
.Slice => {
|
.Slice => if (ptr.child == u8) {
|
||||||
@field(result, field.name) = try readString(buffer, &pos);
|
@field(result, field.name) = try readString(buffer, &pos);
|
||||||
|
} else {
|
||||||
|
@field(result, field.name) = try readArray(ptr.child, buffer, &pos);
|
||||||
},
|
},
|
||||||
else => @compileError("Unsupported type " ++ @typeName(field.type)),
|
else => @compileError("Unsupported type " ++ @typeName(field.type)),
|
||||||
},
|
},
|
||||||
|
|
|
@ -110,7 +110,7 @@ pub const Toplevel = struct {
|
||||||
configure: struct {
|
configure: struct {
|
||||||
width: i32,
|
width: i32,
|
||||||
height: i32,
|
height: i32,
|
||||||
states: []Toplevel.State,
|
states: []const Toplevel.State,
|
||||||
},
|
},
|
||||||
close: void,
|
close: void,
|
||||||
configure_bounds: struct {
|
configure_bounds: struct {
|
||||||
|
@ -118,7 +118,7 @@ pub const Toplevel = struct {
|
||||||
height: i32,
|
height: i32,
|
||||||
},
|
},
|
||||||
wm_capabilities: struct {
|
wm_capabilities: struct {
|
||||||
capabilities: []Toplevel.WmCapabilities,
|
capabilities: []const Toplevel.WmCapabilities,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue