Files
zig-wayland/example/seats.zig
2023-07-20 23:19:59 +02:00

40 lines
1.3 KiB
Zig

const std = @import("std");
const wayland = @import("wayland");
const wl = wayland.client.wl;
pub fn main() !void {
const display = try wl.Display.connect(null);
const registry = try display.getRegistry();
var running: bool = true;
registry.setListener(*bool, listener, &running);
while (running) {
if (display.roundtrip() != .SUCCESS) return error.RoundtripFailed;
}
}
fn listener(registry: *wl.Registry, event: wl.Registry.Event, running: *bool) void {
switch (event) {
.global => |global| {
if (std.mem.orderZ(u8, global.interface, wl.Seat.getInterface().name) == .eq) {
const seat = registry.bind(global.name, wl.Seat, 1) catch return;
seat.setListener(*bool, seatListener, running);
}
},
.global_remove => {},
}
}
fn seatListener(_: *wl.Seat, event: wl.Seat.Event, running: *bool) void {
switch (event) {
.capabilities => |data| {
std.debug.print("Seat capabilities\n Pointer {}\n Keyboard {}\n Touch {}\n", .{
data.capabilities.pointer,
data.capabilities.keyboard,
data.capabilities.touch,
});
running.* = false;
},
.name => {},
}
}