From e8f077cb988774cee582a28ec419ca6a1f1fe75c Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Tue, 3 Nov 2020 11:24:29 +0100 Subject: [PATCH] tinywl: clean up build system, add LICENSE/README --- .gitmodules | 9 ++++++ README.md | 9 +++++- src/types/seat.zig | 4 ++- tinywl/LICENSE | 12 ++++++++ tinywl/README.md | 16 ++++++++++ tinywl/build.zig | 63 ++++++++------------------------------- tinywl/deps/zig-pixman | 1 + tinywl/deps/zig-wayland | 1 + tinywl/deps/zig-xkbcommon | 1 + tinywl/tinywl.zig | 5 ++-- 10 files changed, 65 insertions(+), 56 deletions(-) create mode 100644 .gitmodules create mode 100644 tinywl/LICENSE create mode 100644 tinywl/README.md create mode 160000 tinywl/deps/zig-pixman create mode 160000 tinywl/deps/zig-wayland create mode 160000 tinywl/deps/zig-xkbcommon diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e6e95af --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "tinywl/deps/zig-wayland"] + path = tinywl/deps/zig-wayland + url = https://github.com/ifreund/zig-wayland +[submodule "tinywl/deps/zig-xkbcommon"] + path = tinywl/deps/zig-xkbcommon + url = https://github.com/ifreund/zig-xkbcommon +[submodule "tinywl/deps/zig-pixman"] + path = tinywl/deps/zig-pixman + url = https://github.com/ifreund/zig-pixman diff --git a/README.md b/README.md index 6a65d8c..73d1a67 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,15 @@ addition the following zig bindings are required: - [zig-xkbcommon](https://github.com/ifreund/zig-xkbcommon) - [zig-pixman](https://github.com/ifreund/zig-pixman) +## Usage + +See [tinwyl.zig][./tinywl/] for an example compositor using zig-wlroots and an example +of how to integrate zig-wlroots and its dependencies into your build.zig. + +See the C headers of wlroots for documentation. + ## TODO -- [ ] Bind enough to port [tinwyl](https://github.com/swaywm/wlroots/tree/master/tinywl) +- [x] Bind enough to port [tinwyl](https://github.com/swaywm/wlroots/tree/master/tinywl) - [ ] Bind enough to port [river](https://github.com/ifreund/river) - [ ] Complete bindings diff --git a/src/types/seat.zig b/src/types/seat.zig index de86626..523a88a 100644 --- a/src/types/seat.zig +++ b/src/types/seat.zig @@ -303,7 +303,9 @@ pub const Seat = extern struct { pub const clientForWlClient = wlr_seat_client_for_wl_client; extern fn wlr_seat_set_capabilities(seat: *Seat, capabilities: u32) void; - pub const setCapabilities = wlr_seat_set_capabilities; + pub inline fn setCapabilities(seat: *Seat, capabilities: wl.Seat.Capability) void { + wlr_seat_set_capabilities(seat, @bitCast(u32, capabilities)); + } extern fn wlr_seat_set_name(seat: *Seat, name: [*:0]const u8) void; pub const setName = wlr_seat_set_name; diff --git a/tinywl/LICENSE b/tinywl/LICENSE new file mode 100644 index 0000000..357d014 --- /dev/null +++ b/tinywl/LICENSE @@ -0,0 +1,12 @@ +Copyright 2020 Isaac Freund + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/tinywl/README.md b/tinywl/README.md new file mode 100644 index 0000000..84bc2ca --- /dev/null +++ b/tinywl/README.md @@ -0,0 +1,16 @@ +# tinywl.zig + +This is an implmentation of +[tinywl](https://github.com/swaywm/wlroots/tree/master/tinywl) in zig using +zig-wlroots. + +## Building + +First make sure the submodules are initialized and updated with + +``` +git submodule update --init +``` + +Then simply run `zig build` to build tinywl.zig. + diff --git a/tinywl/build.zig b/tinywl/build.zig index 2906ceb..a8f0df6 100644 --- a/tinywl/build.zig +++ b/tinywl/build.zig @@ -1,24 +1,19 @@ const std = @import("std"); const Builder = std.build.Builder; -const Step = std.build.Step; const Pkg = std.build.Pkg; -pub fn build(b: *Builder) void { - // Standard target options allows the person running `zig build` to choose - // what target to build for. Here we do not override the defaults, which - // means any target is allowed, and the default is native. Other options - // for restricting supported target set are available. - const target = b.standardTargetOptions(.{}); +const ScanProtocolsStep = @import("deps/zig-wayland/build.zig").ScanProtocolsStep; - // Standard release options allow the person running `zig build` to select - // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. +pub fn build(b: *Builder) void { + const target = b.standardTargetOptions(.{}); const mode = b.standardReleaseOptions(); - const scan_protocols = ScanProtocolsStep.create(b); + const scanner = ScanProtocolsStep.create(b, "deps/zig-wayland"); + scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); - const wayland = Pkg{ .name = "wayland", .path = "../../zig-wayland/wayland.zig" }; - const xkbcommon = Pkg{ .name = "xkbcommon", .path = "../../zig-xkbcommon/src/xkbcommon.zig" }; - const pixman = Pkg{ .name = "pixman", .path = "../../zig-pixman/pixman.zig" }; + const wayland = scanner.getPkg(); + const xkbcommon = Pkg{ .name = "xkbcommon", .path = "deps/zig-xkbcommon/src/xkbcommon.zig" }; + const pixman = Pkg{ .name = "pixman", .path = "deps/zig-pixman/pixman.zig" }; const wlroots = Pkg{ .name = "wlroots", .path = "../src/wlroots.zig", @@ -33,8 +28,9 @@ pub fn build(b: *Builder) void { exe.addPackage(wayland); exe.linkSystemLibrary("wayland-server"); - exe.step.dependOn(&scan_protocols.step); - exe.addCSourceFile("xdg_shell.c", &[_][]const u8{"-std=c99"}); + exe.step.dependOn(&scanner.step); + // TODO: remove when https://github.com/ziglang/zig/issues/131 is implemented + scanner.addCSource(exe); exe.addPackage(xkbcommon); exe.linkSystemLibrary("xkbcommon"); @@ -48,41 +44,6 @@ pub fn build(b: *Builder) void { const run_cmd = exe.run(); run_cmd.step.dependOn(b.getInstallStep()); - const run_step = b.step("run", "Run the app"); + const run_step = b.step("run", "Run the compositor"); run_step.dependOn(&run_cmd.step); } - -const ScanProtocolsStep = struct { - builder: *Builder, - step: Step, - - fn create(builder: *Builder) *ScanProtocolsStep { - const self = builder.allocator.create(ScanProtocolsStep) catch @panic("out of memory"); - self.* = init(builder); - return self; - } - - fn init(builder: *Builder) ScanProtocolsStep { - return ScanProtocolsStep{ - .builder = builder, - .step = Step.init(.Custom, "Scan Protocols", builder.allocator, make), - }; - } - - fn make(step: *Step) !void { - const self = @fieldParentPtr(ScanProtocolsStep, "step", step); - - const protocol_dir = std.fmt.trim(try self.builder.exec( - &[_][]const u8{ "pkg-config", "--variable=pkgdatadir", "wayland-protocols" }, - )); - - const xml_path = try std.fs.path.join(self.builder.allocator, &[_][]const u8{ protocol_dir, "stable/xdg-shell/xdg-shell.xml" }); - - // Extension is .xml, so slice off the last 4 characters - const basename = std.fs.path.basename(xml_path); - const basename_no_ext = basename[0..(basename.len - 4)]; - _ = try self.builder.exec( - &[_][]const u8{ "wayland-scanner", "private-code", xml_path, "xdg_shell.c" }, - ); - } -}; diff --git a/tinywl/deps/zig-pixman b/tinywl/deps/zig-pixman new file mode 160000 index 0000000..7847fd1 --- /dev/null +++ b/tinywl/deps/zig-pixman @@ -0,0 +1 @@ +Subproject commit 7847fd1bae7021cdb572e77eac93676c551fd1eb diff --git a/tinywl/deps/zig-wayland b/tinywl/deps/zig-wayland new file mode 160000 index 0000000..931b6f7 --- /dev/null +++ b/tinywl/deps/zig-wayland @@ -0,0 +1 @@ +Subproject commit 931b6f767b5c25280df1252982322d6eb1580aca diff --git a/tinywl/deps/zig-xkbcommon b/tinywl/deps/zig-xkbcommon new file mode 160000 index 0000000..21a9b30 --- /dev/null +++ b/tinywl/deps/zig-xkbcommon @@ -0,0 +1 @@ +Subproject commit 21a9b30e9f23884e72a34643190a892925dd369c diff --git a/tinywl/tinywl.zig b/tinywl/tinywl.zig index f8afd0d..6f37470 100644 --- a/tinywl/tinywl.zig +++ b/tinywl/tinywl.zig @@ -232,9 +232,8 @@ const Server = struct { else => {}, } - var caps: u32 = @enumToInt(wl.Seat.Capability.pointer); - if (server.keyboards.len > 0) - caps |= @as(u32, @enumToInt(wl.Seat.Capability.keyboard)); + var caps = wl.Seat.Capability{ .pointer = true }; + if (server.keyboards.len > 0) caps.keyboard = true; server.seat.setCapabilities(caps); }