Isaac Freund 6e298f878e client: limit version passed to wl.Registry.bind()
Passing the version advertised by the server directly to
wl_registry_bind() is a common bug in clients using libwayland (e.g.
chromium, some of my own programs, many others). Clients should instead
compare the server advertised version with the maximum version the
client supports to avoid forwards compatibility bugs.

To make such bugs impossible, leverage the compile time known max
supported interface versions we now have to limit the version passed to
wl.Registry.bind().
2022-05-18 10:55:51 +02:00
2022-02-17 19:41:57 +02:00
2022-04-28 16:18:01 +02:00
2022-05-11 17:37:06 +02:00
2020-09-23 20:47:32 +02:00
2022-05-11 17:22:05 +02:00

zig-wayland

Zig 0.9 bindings and protocol scanner for libwayland.

Usage

A ScanProtocolsStep is provided which you may integrate with your build.zig:

const std = @import("std");
const Builder = std.build.Builder;

const ScanProtocolsStep = @import("zig-wayland/build.zig").ScanProtocolsStep;

pub fn build(b: *Builder) void {
    const target = b.standardTargetOptions(.{});
    const mode = b.standardReleaseOptions();

    const scanner = ScanProtocolsStep.create(b);
    scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
    scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml");
    scanner.addProtocolPath("protocol/private_foobar.xml");

    // Pass the maximum version implemented by your wayland server or client.
    // Requests, events, enums, etc. from newer versions will not be generated,
    // ensuring forwards compatibility with newer protocol xml.
    // This will also generate code for interfaces created using the provided
    // global interface, in this example wl_keyboard, wl_pointer, xdg_surface,
    // xdg_toplevel, etc. would be generated.
    scanner.generate("wl_seat", 4);
    scanner.generate("xdg_wm_base", 3);
    scanner.generate("ext_session_lock_manager_v1", 1);
    scanner.generate("private_foobar_manager", 1);

    const exe = b.addExecutable("foo", "foo.zig");
    exe.setTarget(target);
    exe.setBuildMode(mode);

    exe.addPackage(.{
        .name = "wayland",
        .path = .{ .generated = &scanner.result },
    });
    exe.step.dependOn(&scanner.step);
    exe.linkLibC();
    exe.linkSystemLibrary("wayland-client");

    // TODO: remove when https://github.com/ziglang/zig/issues/131 is implemented
    scanner.addCSource(exe);

    exe.install();
}

Then, you may import the provided package in your project:

const wayland = @import("wayland");
const wl = wayland.client.wl;

There is an example project using zig-wayland here: hello-zig-wayland.

Note that zig-wayland does not currently do extensive verification of Wayland protocol xml or provide good error messages if protocol xml is invalid. It is recommend to use wayland-scanner --strict to debug protocol xml instead.

License

zig-wayland is released under the MIT (expat) license.

Description
Zig wayland scanner and libwayland bindings (forked to update to zig's nightly)
Readme MIT 375 KiB
Languages
Zig 100%