Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

Replace zig-pixman with an in-tree facade

oxydizer95b4a7ac4b5e
diff --git a/build.zig b/build.zig
index b9e77e8..9e589e1 100644
--- a/build.zig
+++ b/build.zig
@@ -40,7 +40,9 @@ pub fn build(b: *std.Build) void {
const c_headers = support.cHeaders(b, target, optimize);
const wayland = protocols.module(b);
const xkbcommon = b.dependency("xkbcommon", .{}).module("xkbcommon");
- const pixman = b.dependency("pixman", .{}).module("pixman");
+ // Hand-written facade over pixman's region API (the only part this
+ // compositor uses); see src/wlr/pixman.zig. No package dependency.
+ const pixman = b.createModule(.{ .root_source_file = b.path("src/wlr/pixman.zig") });
// One header-backed module supplies every compositor wlroots binding.
const wlr_facade = b.createModule(.{
.root_source_file = b.path("src/wlr/wlr.zig"),
diff --git a/build.zig.zon b/build.zig.zon
index ab0f9a0..6a621da 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -17,10 +17,6 @@
.url = "https://www.leonerd.org.uk/code/libvterm/libvterm-0.3.3.tar.gz",
.hash = "N-V-__8AAFwIBQAS1j3S14ozuJ18ebNtLQ-c5Kl6W4J7PoJt",
},
- .pixman = .{
- .url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.4.0.tar.gz",
- .hash = "pixman-0.4.0-LClMn_eWAAAa2zACATDpPwjuI5fWlO5cBp_F_M33hnNZ",
- },
.wayland = .{
.url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.7.0.tar.gz",
.hash = "wayland-0.7.0-lQa1kuP8AQD5dW7_o-VKLVD_QbqXe7Zob78r2su7Pyex",
diff --git a/src/wlr/AGENTS.md b/src/wlr/AGENTS.md
index 1cccc02..cff3c0c 100644
--- a/src/wlr/AGENTS.md
+++ b/src/wlr/AGENTS.md
@@ -4,6 +4,15 @@
0.20 headers. There is no zig-wlroots package dependency. Some API shapes
were adapted from that project; keep `LICENSE.zig-wlroots` and attribution.
+`@import("pixman")` resolves to `pixman.zig`, a hand-written facade over the
+small part of pixman's region API this compositor actually calls (`Region32`
++ `init`/`initRect`/`deinit`/`unionRect`/`notEmpty`/`containsPoint`). There
+is no zig-pixman package dependency either; the struct layout is adapted
+from that project (keep `LICENSE.zig-pixman`) and must keep matching the
+real `pixman_region32_t`, since `Region32` is embedded by value in
+`node.zig`'s `Buffer` and crosses into wlroots calls via `abi.bind`. Extend
+it rather than reintroducing the package if more of the API is needed.
+
## Boundary and layouts
* `c.h` lists every wlroots header; the build translates it once into
diff --git a/src/wlr/LICENSE.zig-pixman b/src/wlr/LICENSE.zig-pixman
new file mode 100644
index 0000000..6588f3b
--- /dev/null
+++ b/src/wlr/LICENSE.zig-pixman
@@ -0,0 +1,19 @@
+Copyright 2020 Isaac Freund
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/src/wlr/pixman.zig b/src/wlr/pixman.zig
new file mode 100644
index 0000000..a1c806d
--- /dev/null
+++ b/src/wlr/pixman.zig
@@ -0,0 +1,46 @@
+//! Minimal facade over pixman's 32-bit region API, the only pixman surface
+//! this compositor uses (wlroots damage/opaque/clip regions). Adapted from
+//! zig-pixman; see LICENSE.zig-pixman. `Region32`'s layout must keep
+//! matching pixman's `pixman_region32_t` (checked structurally wherever it
+//! crosses the wlroots boundary, see abi.zig).
+
+pub const Box32 = extern struct {
+ x1: i32,
+ y1: i32,
+ x2: i32,
+ y2: i32,
+};
+
+const Region32Data = extern struct {
+ size: c_long,
+ num_rects: c_long,
+};
+
+pub const Region32 = extern struct {
+ extents: Box32,
+ data: ?*Region32Data,
+
+ extern fn pixman_region32_init(region: *Region32) void;
+ pub const init = pixman_region32_init;
+
+ extern fn pixman_region32_init_rect(region: *Region32, x: c_int, y: c_int, width: c_uint, height: c_uint) void;
+ pub const initRect = pixman_region32_init_rect;
+
+ extern fn pixman_region32_fini(region: *Region32) void;
+ pub const deinit = pixman_region32_fini;
+
+ extern fn pixman_region32_union_rect(dest: *Region32, source: *Region32, x: c_int, y: c_int, width: c_uint, height: c_uint) c_int;
+ pub fn unionRect(dest: *Region32, source: *Region32, x: c_int, y: c_int, width: c_uint, height: c_uint) bool {
+ return pixman_region32_union_rect(dest, source, x, y, width, height) != 0;
+ }
+
+ extern fn pixman_region32_not_empty(region: *Region32) c_int;
+ pub fn notEmpty(region: *Region32) bool {
+ return pixman_region32_not_empty(region) != 0;
+ }
+
+ extern fn pixman_region32_contains_point(region: *Region32, x: c_int, y: c_int, box: ?*Box32) c_int;
+ pub fn containsPoint(region: *Region32, x: c_int, y: c_int, box: ?*Box32) bool {
+ return pixman_region32_contains_point(region, x, y, box) != 0;
+ }
+};