Fork of https://github.com/ifreund/zig-wayland update to master Zig
Go to file
2024-04-18 23:31:44 +02:00
.github/workflows ci: update to Zig 0.11.0 2023-08-12 16:05:39 +02:00
example Track deprecating std.cstr namespace 2023-07-20 23:19:59 +02:00
src chore: port to latest Zig master 2024-04-18 23:31:44 +02:00
.gitignore scanner: refactor to use new std.fmt features 2021-05-23 14:38:38 +02:00
build.zig feat: port to latest zig 2024-01-07 19:03:54 +01:00
LICENSE Add MIT (expat) license 2020-09-23 20:47:32 +02:00
README.md docs: Update to addCustomProtocol() in README 2023-09-25 23:32:38 +02:00

zig-wayland

Zig 0.11 bindings and protocol scanner for libwayland.

Usage

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

const std = @import("std");

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

pub fn build(b: *std.build.Builder) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const scanner = Scanner.create(b, .{});

    const wayland = b.createModule(.{ .source_file = scanner.result });

    scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
    scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml");
    scanner.addCustomProtocol("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 as well.
    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(.{
        .name = "foobar",
        .root_source_file = .{ .path = "foobar.zig" },
        .target = target,
        .optimize = optimize,
    });

    exe.addModule("wayland", wayland);
    exe.linkLibC();
    exe.linkSystemLibrary("wayland-client");

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

    b.installArtifact(exe);
}

Then, you may import the provided module 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.