stevee

My wayland statusbar
git clone git://gtms.dev/stevee
Log | Files | Refs | README | LICENSE

seats.zig (1276B)


      1 const std = @import("std");
      2 const wayland = @import("wayland");
      3 const wl = wayland.client.wl;
      4 
      5 pub fn main() !void {
      6     const display = try wl.Display.connect(null);
      7     const registry = try display.getRegistry();
      8     var running: bool = true;
      9     registry.setListener(*bool, listener, &running);
     10     while (running) {
     11         if (display.roundtrip() != .SUCCESS) return error.RoundtripFailed;
     12     }
     13 }
     14 
     15 fn listener(registry: *wl.Registry, event: wl.Registry.Event, running: *bool) void {
     16     switch (event) {
     17         .global => |global| {
     18             if (std.mem.orderZ(u8, global.interface, wl.Seat.interface.name) == .eq) {
     19                 const seat = registry.bind(global.name, wl.Seat, 1) catch return;
     20                 seat.setListener(*bool, seatListener, running);
     21             }
     22         },
     23         .global_remove => {},
     24     }
     25 }
     26 
     27 fn seatListener(_: *wl.Seat, event: wl.Seat.Event, running: *bool) void {
     28     switch (event) {
     29         .capabilities => |data| {
     30             std.debug.print("Seat capabilities\n  Pointer {}\n  Keyboard {}\n  Touch {}\n", .{
     31                 data.capabilities.pointer,
     32                 data.capabilities.keyboard,
     33                 data.capabilities.touch,
     34             });
     35             running.* = false;
     36         },
     37         .name => {},
     38     }
     39 }