Something went wrong. Try again.
An example of how to hack DVUI and layer shell protocol together.
Something went wrong. Try again.
dvui-layer-shell-example build.zig
3.1 kB · 82 lines
Zig
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283const std = @import("std");const trim = std.mem.trim;const replace = std.mem.replace;const replacementSize = std.mem.replacementSize;const whitespace = std.ascii.whitespace;const concat = std.mem.concat;
const builtin = @import("builtin");const Scanner = @import("wayland").Scanner;
pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{});
const app = b.addExecutable(.{ .name = "hello", .root_module = b.createModule(.{ .target = target, .optimize = optimize, .root_source_file = b.path("src/main.zig"), }), }); b.installArtifact(app);
const run_app = b.addRunArtifact(app);
const run = b.step("run", "Run the app"); run.dependOn(&run_app.step);
// Wayland configuration
// `pkg-config --variable=pkgdatadir wayland-protocols` returns a string // with double slashes at the beginning, hence the replace trick. ideally, // this should be handled by `addSystemProtocol`.
const wayland_protocols_base_path = brk: { const base_path_broken = trim(u8, b.run(&.{ "pkg-config", "--variable=pkgdatadir", "wayland-protocols" }), &whitespace); const base_path_fixed_size = replacementSize(u8, base_path_broken, "//", "/"); const base_path = try b.allocator.alloc(u8, base_path_fixed_size); _ = replace(u8, base_path_broken, "//", "/", base_path); break :brk base_path; };
std.debug.print("{s}\n", .{wayland_protocols_base_path});
const wayland_scanner = Scanner.create(b, .{ .wayland_protocols = .{ .cwd_relative = wayland_protocols_base_path } });
const wayland = b.createModule(.{ .root_source_file = wayland_scanner.result });
wayland_scanner.generate("wl_compositor", 5); wayland_scanner.generate("wl_seat", 8); wayland_scanner.generate("wl_output", 4);
// const stable__xdg_shell_xml = try concat(b.allocator, u8, &[_][]const u8{ wayland_protocols_base_path, "/stable/xdg-shell/xdg-shell.xml" });
wayland_scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); // xdg_popup is a child interface; target the global that owns it. wayland_scanner.generate("xdg_wm_base", 7);
const wlr_protocols_base_path = trim(u8, b.run(&.{ "pkg-config", "--variable=pkgdatadir", "wlr-protocols" }), &whitespace); const layer_shell_xml = try concat(b.allocator, u8, &[_][]const u8{ wlr_protocols_base_path, "/unstable/wlr-layer-shell-unstable-v1.xml" }); wayland_scanner.addCustomProtocol(.{ .cwd_relative = layer_shell_xml, }); wayland_scanner.generate("zwlr_layer_shell_v1", 4);
// Dependencies!
const dvui_dep = b.dependency( "dvui", .{ .target = target, .optimize = optimize, .backend = .sdl3, }, ); app.root_module.addImport("dvui", dvui_dep.module("dvui_sdl3")); app.root_module.addImport("backend", dvui_dep.module("sdl3"));
app.root_module.addImport("wayland", wayland); app.root_module.linkSystemLibrary("wayland-client", .{});}