Skip to content

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

Migrate wlr.Output/wlr.OutputLayout off zig-wlroots; finish Box/Edges

Claude9917dc56d847
diff --git a/src/Input.zig b/src/Input.zig
index 20a4407..c1bdafe 100644
--- a/src/Input.zig
+++ b/src/Input.zig
@@ -322,7 +322,8 @@ pub fn init(input: *Input, server: *Server) Server.CompositorError!void {
input.seat.events.request_set_primary_selection.add(&input.request_set_primary_selection);
errdefer input.request_set_primary_selection.link.remove();
- input.cursor.attachOutputLayout(server.output_layout);
+ // Cursor hasn't migrated off zig-wlroots; see wlr.zig's `zig_wlroots` note.
+ input.cursor.attachOutputLayout(@ptrCast(server.output_layout));
input.cursor_mgr.load(1) catch return error.XcursorCreateFailed;
input.cursor.events.motion.add(&input.cursor_motion);
input.cursor.events.motion_absolute.add(&input.cursor_motion_absolute);
diff --git a/src/LayerSurface.zig b/src/LayerSurface.zig
index 01b9e95..14d4ccd 100644
--- a/src/LayerSurface.zig
+++ b/src/LayerSurface.zig
@@ -20,11 +20,13 @@ output_destroy: wl.Listener(*wlr.Output) = .init(outputDestroyed),
output_commit: wl.Listener(*wlr.Output.event.Commit) = .init(outputCommitted),
pub fn create(server: *Server, layer: *wlr.LayerSurfaceV1) !void {
- const output = layer.output orelse defaultOutput(server) orelse {
+ // LayerSurfaceV1 hasn't migrated off zig-wlroots, so layer.output is
+ // still zig-wlroots's own Output; cast both ways at this boundary.
+ const output: *wlr.Output = (if (layer.output) |o| @as(*wlr.Output, @ptrCast(o)) else null) orelse defaultOutput(server) orelse {
layer.destroy();
return;
};
- layer.output = output;
+ layer.output = @ptrCast(output);
const self = try gpa.create(Self);
errdefer gpa.destroy(self);
const tree = try server.desktop_tree.createSceneTree();
@@ -70,8 +72,10 @@ pub fn arrange(self: *Self) void {
};
self.tree.node.reparent(parent);
var full: wlr.Box = undefined;
- self.server.output_layout.getBox(self.layer.output, &full);
- const output = Output.fromWlr(self.layer.output.?);
+ // LayerSurfaceV1 hasn't migrated off zig-wlroots; see create()'s cast.
+ const wlr_output: ?*wlr.Output = @ptrCast(self.layer.output);
+ self.server.output_layout.getBox(wlr_output, &full);
+ const output = Output.fromWlr(wlr_output.?);
if (output) |out| if (out.idle_blanked) {
full = out.cached_box;
};
diff --git a/src/Popup.zig b/src/Popup.zig
index d71458f..311b3f9 100644
--- a/src/Popup.zig
+++ b/src/Popup.zig
@@ -94,7 +94,9 @@ fn unconstrainToOutput(server: *Server, xdg_popup: *wlr.XdgPopup) void {
windowConstraintBox(server, toplevel, ox, oy)
else
layoutConstraintBox(server, ox, oy)) orelse return;
- xdg_popup.unconstrainFromBox(&box);
+ // XdgPopup hasn't migrated off zig-wlroots; see wlr.zig's
+ // assertSameLayout(Box, old.Box) for why this cast is safe.
+ xdg_popup.unconstrainFromBox(@ptrCast(&box));
}
/// Popups of layer surfaces live in layout space, like the output box.
diff --git a/src/Server.zig b/src/Server.zig
index e87862a..4958888 100644
--- a/src/Server.zig
+++ b/src/Server.zig
@@ -114,7 +114,10 @@ output_renderer: *scene_output_mod.Renderer = undefined,
read_fence: ?*explicit_sync.ReadFence = null,
output_layout: *wlr.OutputLayout,
-new_output: wl.Listener(*wlr.Output) = .init(newOutput),
+// Backend hasn't migrated off zig-wlroots yet, so its new_output signal
+// still emits zig-wlroots's own Output (see src/wlr/wlr.zig's
+// `zig_wlroots` note); server/outputs.zig's newOutput casts it back.
+new_output: wl.Listener(*wlr.zig_wlroots.Output) = .init(newOutput),
shell: Shell,
background_tree: *sn.Tree,
@@ -638,7 +641,9 @@ pub fn init(server: *Server, scale: ?f32, icon_theme_cfg: icon_theme.Config, io:
} else {
log.info("init: explicit sync unavailable (renderer/backend lack timelines or disabled)", .{});
}
- server.xdg_output_manager = wlr.XdgOutputManagerV1.create(server.wl_server, server.output_layout) catch return error.XdgOutputManagerCreateFailed;
+ // XdgOutputManagerV1 hasn't migrated off zig-wlroots; see wlr.zig's
+ // `zig_wlroots` note.
+ server.xdg_output_manager = wlr.XdgOutputManagerV1.create(server.wl_server, @ptrCast(server.output_layout)) catch return error.XdgOutputManagerCreateFailed;
_ = wlr.Presentation.create(server.wl_server, server.backend, 2) catch return error.PresentationCreateFailed;
server.capture_mgr = capture.Manager.create(server) catch |err| blk: {
log.warn("init: could not create screen-capture manager, sharing disabled: {}", .{err});
diff --git a/src/Switcher.zig b/src/Switcher.zig
index 4c193ab..64d46c0 100644
--- a/src/Switcher.zig
+++ b/src/Switcher.zig
@@ -218,7 +218,9 @@ fn updatePreview(card: *Card, tl: *@import("Toplevel.zig")) void {
card.pw = 0;
if (tl.surface()) |surface| {
if (surface.current.transform == .normal) if (surface.buffer) |buffer| {
- surface.getBufferSourceBox(&card.source);
+ // Surface hasn't migrated off zig-wlroots; see wlr.zig's
+ // assertSameLayout(FBox, old.FBox) for why this cast is safe.
+ surface.getBufferSourceBox(@ptrCast(&card.source));
const sw: f32 = @floatFromInt(@max(1, surface.current.width));
const sh: f32 = @floatFromInt(@max(1, surface.current.height));
const fit = @min(208 / sw, 140 / sh);
diff --git a/src/capture/manager.zig b/src/capture/manager.zig
index bdb190a..3f5643f 100644
--- a/src/capture/manager.zig
+++ b/src/capture/manager.zig
@@ -241,11 +241,14 @@ pub const Manager = struct {
/// wlroots copies in its own commit listener, so refusing means
/// disconnecting the client first, as `handleNewSession` does.
pub fn guardScreencopy(mgr: *Manager, output: *wlr.Output) void {
+ // ScreencopyFrameV1 hasn't migrated off zig-wlroots; see wlr.zig's
+ // `zig_wlroots` note.
+ const old_output: *wlr.zig_wlroots.Output = @ptrCast(output);
const refuse = mgr.server.polkit_dialog != null or mgr.server.locker != null;
var copying = false;
var it = mgr.screencopy.frames.safeIterator(.forward);
while (it.next()) |frame| {
- if (frame.output != output or !copyRequested(frame)) continue;
+ if (frame.output != old_output or !copyRequested(frame)) continue;
if (refuse) {
// Destroying the client frees its other frames too.
frame.resource.getClient().destroy();
@@ -333,7 +336,9 @@ const Session = struct {
tracked.* = .{
.manager = manager,
.resource = session.resource,
- .output = session.source.toOutput(),
+ // ExtImageCaptureSourceV1 hasn't migrated off zig-wlroots; see
+ // wlr.zig's `zig_wlroots` note.
+ .output = @ptrCast(session.source.toOutput()),
.window_id = if (findWindowSource(manager, session.source)) |ws| ws.window_id else null,
};
session.events.destroy.add(&tracked.destroy);
diff --git a/src/capture/window_source.zig b/src/capture/window_source.zig
index f896f74..7cf0595 100644
--- a/src/capture/window_source.zig
+++ b/src/capture/window_source.zig
@@ -294,7 +294,9 @@ pub const WindowCaptureSource = struct {
var luminance_multiplier: f32 = 1.0;
const options: wlr.RenderPass.TextureOptions = .{
.texture = texture,
- .src_box = scene_buffer.src_box,
+ // RenderPass hasn't migrated off zig-wlroots; see wlr.zig's
+ // assertSameLayout(FBox, old.FBox) for why this cast is safe.
+ .src_box = @bitCast(scene_buffer.src_box),
.dst_box = .{
.x = sx - ctx.off_x,
.y = sy - ctx.off_y,
diff --git a/src/foreign_toplevel.zig b/src/foreign_toplevel.zig
index 85da473..ebe95ab 100644
--- a/src/foreign_toplevel.zig
+++ b/src/foreign_toplevel.zig
@@ -76,8 +76,10 @@ pub const Handle = struct {
self.output
else if (toplevel.currentOutput()) |o| o.wlr_output else null;
if (output != self.output) {
- if (self.output) |old| handle.outputLeave(old);
- if (output) |new| handle.outputEnter(new);
+ // ForeignToplevelHandleV1 hasn't migrated off zig-wlroots; see
+ // Server.zig's new_output for the same kind of crossing.
+ if (self.output) |o| handle.outputLeave(@ptrCast(o));
+ if (output) |o| handle.outputEnter(@ptrCast(o));
self.output = output;
}
diff --git a/src/input/text_input.zig b/src/input/text_input.zig
index 041eb0e..a7e25ba 100644
--- a/src/input/text_input.zig
+++ b/src/input/text_input.zig
@@ -397,7 +397,10 @@ pub fn updatePopups(self: *Self) void {
y = layout.y;
scale *= self.server.world.camera.zoom();
} else if (wlr.LayerSurfaceV1.tryFromWlrSurface(surface.getRootSurface()) == null) break :visible false;
- const rect = if (input.active_features.cursor_rectangle) input.current.cursor_rectangle else wlr.Box{ .x = 0, .y = 0, .width = surface.current.width, .height = surface.current.height };
+ // TextInputV3 hasn't migrated off zig-wlroots, so
+ // cursor_rectangle is still its own Box type; match it here
+ // instead of casting, since only .x/.y/.width are read below.
+ const rect = if (input.active_features.cursor_rectangle) input.current.cursor_rectangle else @TypeOf(input.current.cursor_rectangle){ .x = 0, .y = 0, .width = surface.current.width, .height = surface.current.height };
// Rectangle coordinates are client-controlled signed 32-bit values.
// Zoom and adding the scene origin can exceed that range.
const rx: i64 = @intFromFloat(@round(x + @as(f64, @floatFromInt(rect.x)) * scale));
@@ -415,7 +418,10 @@ pub fn updatePopups(self: *Self) void {
const relative = wlr.Box{ .x = wireCoordinate(rx - px), .y = wireCoordinate(ry - py), .width = wireCoordinate(rw), .height = wireCoordinate(rh) };
if (popup.last_rectangle == null or !std.meta.eql(popup.last_rectangle.?, relative)) {
var box = relative;
- popup.popup.sendTextInputRectangle(&box);
+ // InputPopupSurfaceV2 hasn't migrated off zig-wlroots; see
+ // wlr.zig's assertSameLayout(Box, old.Box) for why this
+ // cast is safe.
+ popup.popup.sendTextInputRectangle(@ptrCast(&box));
popup.last_rectangle = relative;
}
break :visible true;
diff --git a/src/input/touch.zig b/src/input/touch.zig
index 31eac1e..8a3922d 100644
--- a/src/input/touch.zig
+++ b/src/input/touch.zig
@@ -106,7 +106,8 @@ fn mapDevice(self: *Self, device: *wlr.InputDevice) void {
target = output;
}
}
- self.input.cursor.mapInputToOutput(device, if (target) |t| t.wlr_output else null);
+ // Cursor hasn't migrated off zig-wlroots; see wlr.zig's `zig_wlroots` note.
+ self.input.cursor.mapInputToOutput(device, if (target) |t| @ptrCast(t.wlr_output) else null);
}
fn handleDestroy(listener: *wl.Listener(*wlr.InputDevice), _: *wlr.InputDevice) void {
diff --git a/src/ipc/handlers_state.zig b/src/ipc/handlers_state.zig
index ea4c009..9ea3203 100644
--- a/src/ipc/handlers_state.zig
+++ b/src/ipc/handlers_state.zig
@@ -63,7 +63,9 @@ pub fn handleStateRequest(
};
const surface = toplevel.surface() orelse return .{ .err = "WindowNotVisible" };
var src_box: wlr.FBox = undefined;
- surface.getBufferSourceBox(&src_box);
+ // Surface hasn't migrated off zig-wlroots; see wlr.zig's
+ // assertSameLayout(FBox, old.FBox) for why this cast is safe.
+ surface.getBufferSourceBox(@ptrCast(&src_box));
const geometry_box = toplevel.clientGeometry();
const decorated = toplevel.hasServerDecorations();
diff --git a/src/notifications_tests.zig b/src/notifications_tests.zig
index a8f0521..9ef139f 100644
--- a/src/notifications_tests.zig
+++ b/src/notifications_tests.zig
@@ -39,7 +39,8 @@ test "notifications unit: replaces_id, urgency, DND, lock suppression" {
server.outputs.init();
server.input.cursor = &dummy_cursor;
- const wlr_out = try backend.headlessAddOutput(1280, 720);
+ // Backend hasn't migrated off zig-wlroots; see Server.zig's new_output.
+ const wlr_out: *wlr.Output = @ptrCast(try backend.headlessAddOutput(1280, 720));
var mode = wlr.Output.State.init();
defer mode.finish();
mode.setEnabled(true);
diff --git a/src/osd.zig b/src/osd.zig
index e088b15..422a966 100644
--- a/src/osd.zig
+++ b/src/osd.zig
@@ -226,7 +226,8 @@ test "OSD is noninteractive, stays above lock covers, rescales and releases its
server.overlay_tree = try fixture.nodes.tree.createSceneTree();
server.lock_tree = try fixture.nodes.tree.createSceneTree();
server.locker = null;
- const output = try backend.headlessAddOutput(1280, 720);
+ // Backend hasn't migrated off zig-wlroots; see Server.zig's new_output.
+ const output: *wlr.Output = @ptrCast(try backend.headlessAddOutput(1280, 720));
var mode = wlr.Output.State.init();
defer mode.finish();
mode.setEnabled(true);
@@ -281,7 +282,8 @@ test "OSD sound and brightness glides smoothly between levels" {
server.overlay_tree = try fixture.nodes.tree.createSceneTree();
server.lock_tree = try fixture.nodes.tree.createSceneTree();
server.locker = null;
- const output = try backend.headlessAddOutput(1280, 720);
+ // Backend hasn't migrated off zig-wlroots; see Server.zig's new_output.
+ const output: *wlr.Output = @ptrCast(try backend.headlessAddOutput(1280, 720));
var mode = wlr.Output.State.init();
defer mode.finish();
mode.setEnabled(true);
diff --git a/src/output/layout.zig b/src/output/layout.zig
index 2e9b1b0..a3d828e 100644
--- a/src/output/layout.zig
+++ b/src/output/layout.zig
@@ -321,7 +321,9 @@ pub fn syncLayout(server: *Server) void {
var layers = server.layer_surfaces.iterator(.forward);
while (layers.next()) |layer| {
if (!layer.layer.initialized) continue;
- const out = fromWlr(layer.layer.output orelse continue) orelse continue;
+ // LayerSurfaceV1 hasn't migrated off zig-wlroots; see
+ // LayerSurface.zig's create() for the same crossing.
+ const out = fromWlr(@ptrCast(layer.layer.output orelse continue)) orelse continue;
if (!out.idle_blanked and !out.user_disabled) layer.arrange();
}
recomputeWorldBounds(server);
diff --git a/src/output_management.zig b/src/output_management.zig
index e03d199..00c7a04 100644
--- a/src/output_management.zig
+++ b/src/output_management.zig
@@ -48,7 +48,9 @@ pub const Manager = struct {
const config = wlr.OutputConfigurationV1.create() catch return;
var it = self.server.outputs.iterator(.forward);
while (it.next()) |output| {
- const head = wlr.OutputConfigurationV1.Head.create(config, output.wlr_output) catch {
+ // OutputConfigurationV1 hasn't migrated off zig-wlroots; see
+ // wlr.zig's `zig_wlroots` note.
+ const head = wlr.OutputConfigurationV1.Head.create(config, @ptrCast(output.wlr_output)) catch {
config.destroy();
return;
};
@@ -93,7 +95,9 @@ pub const Manager = struct {
// Validate and backend-test everything before changing anything.
var heads = config.heads.iterator(.forward);
while (heads.next()) |head| {
- const output = Output.fromWlr(head.state.output) orelse return false;
+ // OutputConfigurationV1 hasn't migrated off zig-wlroots; see
+ // wlr.zig's `zig_wlroots` note.
+ const output = Output.fromWlr(@ptrCast(head.state.output)) orelse return false;
const p = diff(self.server, output, &head.state);
if (isEmpty(p)) continue;
p.validate() catch return refuse(output, "invalid settings");
@@ -101,7 +105,9 @@ pub const Manager = struct {
if (!head.state.enabled or !output.wlr_output.enabled) continue;
var state = wlr.Output.State.init();
defer state.finish();
- head.state.apply(&state);
+ // OutputHeadV1 hasn't migrated off zig-wlroots; see wlr.zig's
+ // `zig_wlroots` note.
+ head.state.apply(@ptrCast(&state));
if (!output.wlr_output.testState(&state)) return refuse(output, "rejected by the backend");
}
if (!commit) return true;
@@ -109,7 +115,9 @@ pub const Manager = struct {
for ([_]Phase{ .enable, .change, .disable }) |phase| {
heads = config.heads.iterator(.forward);
while (heads.next()) |head| {
- const output = Output.fromWlr(head.state.output) orelse return false;
+ // OutputConfigurationV1 hasn't migrated off zig-wlroots; see
+ // wlr.zig's `zig_wlroots` note.
+ const output = Output.fromWlr(@ptrCast(head.state.output)) orelse return false;
const p = phase.select(diff(self.server, output, &head.state));
if (isEmpty(p)) continue;
output.applyAndPersist(p) catch |err| {
@@ -151,9 +159,12 @@ fn isEmpty(p: Patch) bool {
}
fn findHead(config: *wlr.OutputConfigurationV1, output: *wlr.Output) ?*wlr.OutputConfigurationV1.Head {
+ // OutputConfigurationV1 hasn't migrated off zig-wlroots; see wlr.zig's
+ // `zig_wlroots` note.
+ const old_output: *wlr.zig_wlroots.Output = @ptrCast(output);
var it = config.heads.iterator(.forward);
while (it.next()) |head| {
- if (head.state.output == output) return head;
+ if (head.state.output == old_output) return head;
}
return null;
}
diff --git a/src/server/outputs.zig b/src/server/outputs.zig
index 5aaba9b..cfcf6b5 100644
--- a/src/server/outputs.zig
+++ b/src/server/outputs.zig
@@ -8,8 +8,10 @@ const Output = @import("../Output.zig");
const geometry = @import("../geometry.zig");
const log = std.log.scoped(.compositor);
-pub fn newOutput(listener: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
+pub fn newOutput(listener: *wl.Listener(*wlr.zig_wlroots.Output), old_output: *wlr.zig_wlroots.Output) void {
const server: *Server = @fieldParentPtr("new_output", listener);
+ // Backend hasn't migrated off zig-wlroots; see Server.zig's new_output.
+ const wlr_output: *wlr.Output = @ptrCast(old_output);
// wlroots' own `wlr_ext_image_capture_source_v1_create_with_scene_node`
// (capture/manager.zig, stage 3 window capture) creates a private
diff --git a/src/session/client_lock.zig b/src/session/client_lock.zig
index 8b3a229..60a5578 100644
--- a/src/session/client_lock.zig
+++ b/src/session/client_lock.zig
@@ -227,7 +227,9 @@ pub const ClientLock = struct {
fn handleNewSurface(listener: *wl.Listener(*wlr.SessionLockSurfaceV1), lock_surface: *wlr.SessionLockSurfaceV1) void {
const self: *ClientLock = @fieldParentPtr("new_surface", listener);
- const output = Output.fromWlr(lock_surface.output) orelse return;
+ // SessionLockSurfaceV1 hasn't migrated off zig-wlroots; see
+ // wlr.zig's `zig_wlroots` note.
+ const output = Output.fromWlr(@ptrCast(lock_surface.output)) orelse return;
const surface = gpa.create(Surface) catch return;
const tree = output.lock_view.tree.createSceneSubsurfaceTree(lock_surface.surface) catch {
gpa.destroy(surface);
diff --git a/src/session/idle.zig b/src/session/idle.zig
index 69dacea..5892e33 100644
--- a/src/session/idle.zig
+++ b/src/session/idle.zig
@@ -390,7 +390,9 @@ pub const IdleManager = struct {
return .{ .visible = false, .reason = "unmapped layer surface" };
}
if (layer.layer.output) |out| {
- if (Output.fromWlr(out)) |output| {
+ // LayerSurfaceV1 hasn't migrated off zig-wlroots; see
+ // LayerSurface.zig's create() for the same crossing.
+ if (Output.fromWlr(@ptrCast(out))) |output| {
if (output.isLogicallyEnabled()) {
return .{ .visible = true, .reason = "visible layer surface" };
}
diff --git a/src/session/lock_tests.zig b/src/session/lock_tests.zig
index 56aa600..8693cb8 100644
--- a/src/session/lock_tests.zig
+++ b/src/session/lock_tests.zig
@@ -240,7 +240,8 @@ test "lock covers new outputs and follows layout and mode changes without UI" {
server.output_layout = output_layout;
server.lock_tree = try fixture.nodes.tree.createSceneTree();
for (0..2) |i| {
- const output = try backend.headlessAddOutput(1280, 720);
+ // Backend hasn't migrated off zig-wlroots; see Server.zig's new_output.
+ const output: *wlr.Output = @ptrCast(try backend.headlessAddOutput(1280, 720));
var state = wlr.Output.State.init();
defer state.finish();
state.setEnabled(true);
diff --git a/src/startup_tasks.zig b/src/startup_tasks.zig
index ae66185..1cde8df 100644
--- a/src/startup_tasks.zig
+++ b/src/startup_tasks.zig
@@ -125,9 +125,10 @@ test "staged backends retain multi ownership and only start in their own stage"
_ = try display.headlessAddOutput(32, 32);
_ = try input.headlessAddOutput(32, 32);
const Observer = struct {
- listener: wl.Listener(*wlr.Output) = .init(newOutput),
+ // Backend hasn't migrated off zig-wlroots; see Server.zig's new_output.
+ listener: wl.Listener(*wlr.zig_wlroots.Output) = .init(newOutput),
count: usize = 0,
- fn newOutput(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
+ fn newOutput(listener: *wl.Listener(*wlr.zig_wlroots.Output), _: *wlr.zig_wlroots.Output) void {
const self: *@This() = @fieldParentPtr("listener", listener);
self.count += 1;
}
diff --git a/src/toplevel/info.zig b/src/toplevel/info.zig
index ac5d38d..8dde4d5 100644
--- a/src/toplevel/info.zig
+++ b/src/toplevel/info.zig
@@ -121,7 +121,9 @@ pub fn surfaceScale(toplevel: *const Toplevel) f64 {
pub fn clientSurfaceGeometry(toplevel: *const Toplevel) wlr.Box {
if (toplevel.backend_gone) return .{ .x = 0, .y = 0, .width = 0, .height = 0 };
return switch (toplevel.backend) {
- .xdg => |*adapter| adapter.xdg_toplevel.base.geometry,
+ // XdgSurface hasn't migrated off zig-wlroots; see wlr.zig's
+ // assertSameLayout(Box, old.Box) for why this cast is safe.
+ .xdg => |*adapter| @bitCast(adapter.xdg_toplevel.base.geometry),
.xwayland => |*adapter| blk: {
if (adapter.xsurface.surface) |s| {
if (s.current.width > 0 and s.current.height > 0) {
diff --git a/src/toplevel/layout.zig b/src/toplevel/layout.zig
index 35b0fbe..e73392a 100644
--- a/src/toplevel/layout.zig
+++ b/src/toplevel/layout.zig
@@ -309,7 +309,9 @@ pub fn sendTiled(toplevel: *Toplevel, edges: wlr.Edges) void {
if (toplevel.backend_gone) return;
switch (toplevel.backend) {
// wlroots asserts an xdg_wm_base of version 2 or later (Shell.zig).
- .xdg => |*adapter| _ = adapter.xdg_toplevel.setTiled(edges),
+ // XdgToplevel hasn't migrated off zig-wlroots; see wlr.zig's
+ // assertSameLayout(Edges, old.Edges) for why this cast is safe.
+ .xdg => |*adapter| _ = adapter.xdg_toplevel.setTiled(@bitCast(edges)),
.xwayland, .placeholder, .shell => {},
}
}
diff --git a/src/wlr/AGENTS.md b/src/wlr/AGENTS.md
index 2f3bbb8..be587f2 100644
--- a/src/wlr/AGENTS.md
+++ b/src/wlr/AGENTS.md
@@ -46,16 +46,37 @@ header produce two incompatible Zig types.
4. **Check who else takes or returns this type before wiring it into
`wlr.zig`.** Zig's `extern struct`s are nominally typed: a function
still on `old` that takes `*old.Box` will not accept a `*wlr.Box` built
- from `c.zig`, even though the two are byte-for-byte identical. `Box`,
- `FBox`, and `Edges` hit this — they're drafted in `box.zig`/`edges.zig`
- and verified against the real headers, but `wlr.zig` still forwards
- them to `old` because `OutputLayout.getBox`, `XdgToplevel.setTiled`,
- and others haven't migrated yet. A type like that moves together with
- (or after) every not-yet-migrated signature that references it, not
- on its own. A protocol-generated header wlroots itself doesn't install
- (anything under `wlr_types_*_v1.h` that `#include`s its own
- `*-protocol.h`) needs that header generated at build time — see
+ from `c.zig`, even though the two are byte-for-byte identical. Add a
+ `comptime { assertSameLayout(NewType, old.OldType); }` next to the
+ migrated type's declaration in `wlr.zig` (see `Box`/`FBox`/`Edges`),
+ then `@ptrCast` (pointers) or `@bitCast` (value types passed by value,
+ e.g. `Edges`) at each of the handful of call sites that still cross
+ into an unmigrated function or signal — one line at each site, with a
+ comment pointing back at the assert. That assert is what makes the
+ cast provably safe, not a convention to trust blindly. This is almost
+ always cheaper than waiting for every referencing type to migrate
+ first: `Output`/`OutputLayout` crossed into `Backend` (the
+ `new_output` signal — see `wlr.zig`'s `zig_wlroots` re-export and
+ Server.zig/server/outputs.zig/startup_tasks.zig),
+ `ForeignToplevelHandleV1`, `Cursor`, `OutputConfigurationV1`,
+ `XdgSurface`/`XdgToplevel`, `LayerSurfaceV1`, `SessionLockSurfaceV1`,
+ and a few test files' direct `Backend.headlessAddOutput` calls — each
+ handled with one cast, not a bigger migration. Only wait when the
+ type is a signal/event *payload* type itself and nothing else, or the
+ crossing count looks larger than just migrating the other side too. A
+ protocol-generated header wlroots itself doesn't install (anything
+ under `wlr_types_*_v1.h` that `#include`s its own `*-protocol.h`)
+ needs that header generated at build time — see
`output_power_protocol_header` in `build.zig` for the
`wayland-scanner`-based pattern.
-5. Build Debug and `-Doptimize=ReleaseSafe`, run `zig build test`, per the
- top-level AGENTS.md.
+5. Before trusting a signal's payload type, check who actually connects
+ to it (`grep` for `.events.<name>.add(`) rather than assuming from the
+ header comment. `wlr_output`'s `frame`/`description`/`destroy`
+ signals carry the output itself as payload by convention, with no
+ comment saying so and no dedicated event struct — only
+ `damage`/`precommit`/`bind` (which nothing in RediWM connects to) were
+ safe to leave as placeholder `wl.Signal(void)`.
+6. Build Debug and `-Doptimize=ReleaseSafe`, run `zig build test`, per the
+ top-level AGENTS.md. A pre-existing/environmental test failure doesn't
+ excuse skipping this: compare against a `git worktree` of the commit
+ before your change, per the top-level AGENTS.md, rather than assuming.
diff --git a/src/wlr/c.zig b/src/wlr/c.zig
index 8b9d477..2e34348 100644
--- a/src/wlr/c.zig
+++ b/src/wlr/c.zig
@@ -15,4 +15,12 @@ pub const c = @cImport({
@cInclude("wlr/types/wlr_fractional_scale_v1.h");
@cInclude("wlr/types/wlr_relative_pointer_v1.h");
@cInclude("wlr/types/wlr_pointer_constraints_v1.h");
+ @cInclude("wlr/types/wlr_output.h");
+ @cInclude("wlr/types/wlr_output_layout.h");
+ // isDrm/isWl/isX11/isHeadless are backend-specific predicates, declared
+ // in each backend's own header rather than wlr_output.h.
+ @cInclude("wlr/backend/drm.h");
+ @cInclude("wlr/backend/headless.h");
+ @cInclude("wlr/backend/wayland.h");
+ @cInclude("wlr/backend/x11.h");
});
diff --git a/src/wlr/output.zig b/src/wlr/output.zig
new file mode 100644
index 0000000..c11d301
--- /dev/null
+++ b/src/wlr/output.zig
@@ -0,0 +1,540 @@
+//! wlr.Output / wlr.OutputCursor, backed by @cImport against
+//! wlr/types/wlr_output.h. The single biggest type in the facade so far:
+//! see src/wlr/AGENTS.md for the general pattern and the top-level
+//! AGENTS.md's rendering/damage notes before changing anything here.
+//!
+//! Scoped to what RediWM actually reads, per the usage audit done before
+//! writing this file, not the full wlroots API:
+//!
+//! - `Output` is declared field-for-field up through `data` (its last
+//! field RediWM touches, via the `output.wlr_output.data` pattern for
+//! stashing a back-pointer) and then truncated -- the trailing
+//! WLR_PRIVATE block is never declared, same as every other migrated
+//! type. `allocator`/`renderer`/`swapchain`/`addons`/`layers` sit in
+//! that range but are never read as *fields* (only ever passed as
+//! *parameters*, e.g. to `initRender`), so they're typed as opaque
+//! placeholders purely to hold their byte offset -- correctness there
+//! is about size, not type.
+//! - `OutputCursor` is truncated after `hotspot_y`: nothing past it
+//! (texture, wait_timeline, link, ...) is read.
+//! - Of the ten `events.*` signals, only `frame`, `commit`, `present`,
+//! `description`, `request_state` and `destroy` are ever connected to
+//! in RediWM. `frame`/`description`/`destroy` carry the output itself
+//! as payload, by wlroots convention, matching the existing listener
+//! types in Output.zig/xwayland_output.zig. `damage`/`needs_frame`/
+//! `precommit`/`bind` are typed `wl.Signal(void)` as a placeholder:
+//! still correctly *sized* (every wl.Signal(T) is one wl_list
+//! regardless of T, see signal.zig), but not a real payload type.
+//! Connecting one of those later needs its real event struct filled
+//! in first -- that's a compile error pointing here, not a silent bug.
+//! - `Present`'s payload is truncated after `presented` (only
+//! `commit_seq`/`presented` are read); `Damage`/`Precommit`/`Bind`
+//! aren't defined at all since nothing connects those signals.
+//!
+//! `Backend`, `Renderer`, `Allocator`, `Buffer`, `ColorTransform` are
+//! still on the old zig-wlroots dependency, so this file takes them as
+//! parameters the same way output_power.zig took `Output`.
+const std = @import("std");
+const wl = @import("wayland").server.wl;
+const pixman = @import("pixman");
+const c = @import("c.zig").c;
+const assertSameLayout = @import("signal.zig").assertSameLayout;
+const assertFieldOffset = @import("signal.zig").assertFieldOffset;
+const box = @import("box.zig");
+
+pub fn Types(
+ comptime Backend: type,
+ comptime Renderer: type,
+ comptime Allocator: type,
+ comptime Buffer: type,
+ comptime ColorTransform: type,
+) type {
+ return struct {
+ pub const OutputCursor = extern struct {
+ output: *Output,
+ x: f64,
+ y: f64,
+ enabled: bool,
+ visible: bool,
+ width: u32,
+ height: u32,
+ src_box: box.FBox,
+ transform: wl.Output.Transform,
+ hotspot_x: i32,
+ hotspot_y: i32,
+
+ comptime {
+ const Real = c.wlr_output_cursor;
+ assertFieldOffset(OutputCursor, Real, "output");
+ assertFieldOffset(OutputCursor, Real, "x");
+ assertFieldOffset(OutputCursor, Real, "y");
+ assertFieldOffset(OutputCursor, Real, "enabled");
+ assertFieldOffset(OutputCursor, Real, "visible");
+ assertFieldOffset(OutputCursor, Real, "width");
+ assertFieldOffset(OutputCursor, Real, "height");
+ assertFieldOffset(OutputCursor, Real, "src_box");
+ assertFieldOffset(OutputCursor, Real, "transform");
+ assertFieldOffset(OutputCursor, Real, "hotspot_x");
+ assertFieldOffset(OutputCursor, Real, "hotspot_y");
+ }
+ };
+
+ pub const Output = extern struct {
+ pub const Mode = extern struct {
+ pub const AspectRatio = enum(c_int) {
+ none,
+ @"4_3",
+ @"16_9",
+ @"64_27",
+ @"256_135",
+ };
+
+ width: i32,
+ height: i32,
+ refresh: i32,
+ preferred: bool,
+ picture_aspect_ratio: AspectRatio,
+ /// Output.modes
+ link: wl.list.Link,
+
+ comptime {
+ const Real = c.wlr_output_mode;
+ assertFieldOffset(Mode, Real, "width");
+ assertFieldOffset(Mode, Real, "height");
+ assertFieldOffset(Mode, Real, "refresh");
+ assertFieldOffset(Mode, Real, "preferred");
+ assertFieldOffset(Mode, Real, "picture_aspect_ratio");
+ assertFieldOffset(Mode, Real, "link");
+ assertSameLayout(Mode, Real);
+ assertSameLayout(AspectRatio, c.wlr_output_mode_aspect_ratio);
+ }
+ };
+
+ pub const AdaptiveSyncStatus = enum(c_int) {
+ disabled,
+ enabled,
+ };
+
+ pub const State = extern struct {
+ pub const Fields = packed struct(u32) {
+ buffer: bool = false,
+ damage: bool = false,
+ mode: bool = false,
+ enabled: bool = false,
+ scale: bool = false,
+ transform: bool = false,
+ adaptive_sync_enabled: bool = false,
+ render_format: bool = false,
+ subpixel: bool = false,
+ layers: bool = false,
+ wait_timeline: bool = false,
+ signal_timeline: bool = false,
+ color_transform: bool = false,
+ image_description: bool = false,
+ _: u18 = 0,
+ };
+
+ pub const ModeType = enum(c_int) {
+ fixed,
+ custom,
+ };
+
+ committed: Fields,
+ allow_reconfiguration: bool,
+ damage: pixman.Region32,
+ enabled: bool,
+ scale: f32,
+ transform: wl.Output.Transform,
+ adaptive_sync_enabled: bool,
+ render_format: u32,
+ subpixel: wl.Output.Subpixel,
+
+ buffer: ?*Buffer,
+ buffer_src_box: box.FBox,
+ buffer_dst_box: box.Box,
+
+ tearing_page_flip: bool,
+
+ mode_type: ModeType,
+ mode: ?*Mode,
+ custom_mode: extern struct {
+ width: i32,
+ height: i32,
+ refresh: i32,
+ },
+
+ layers: ?*anyopaque,
+ layers_len: usize,
+
+ wait_timeline: ?*anyopaque,
+ wait_point: u64,
+ signal_timeline: ?*anyopaque,
+ signal_point: u64,
+
+ color_transform: ?*ColorTransform,
+ image_description: ?*anyopaque,
+
+ pub fn init() State {
+ var state: State = undefined;
+ c.wlr_output_state_init(@ptrCast(&state));
+ return state;
+ }
+
+ pub fn finish(state: *State) void {
+ c.wlr_output_state_finish(@ptrCast(state));
+ }
+
+ pub fn setEnabled(state: *State, enabled: bool) void {
+ c.wlr_output_state_set_enabled(@ptrCast(state), enabled);
+ }
+
+ pub fn setMode(state: *State, mode: *Mode) void {
+ c.wlr_output_state_set_mode(@ptrCast(state), @ptrCast(mode));
+ }
+
+ pub fn setCustomMode(state: *State, width: i32, height: i32, refresh: i32) void {
+ c.wlr_output_state_set_custom_mode(@ptrCast(state), width, height, refresh);
+ }
+
+ pub fn setScale(state: *State, scale: f32) void {
+ c.wlr_output_state_set_scale(@ptrCast(state), scale);
+ }
+
+ pub fn setTransform(state: *State, transform: wl.Output.Transform) void {
+ c.wlr_output_state_set_transform(@ptrCast(state), @intCast(@intFromEnum(transform)));
+ }
+
+ pub fn setAdaptiveSyncEnabled(state: *State, enabled: bool) void {
+ c.wlr_output_state_set_adaptive_sync_enabled(@ptrCast(state), enabled);
+ }
+
+ pub fn setRenderFormat(state: *State, format: u32) void {
+ c.wlr_output_state_set_render_format(@ptrCast(state), format);
+ }
+
+ pub fn setSubpixel(state: *State, subpixel: wl.Output.Subpixel) void {
+ c.wlr_output_state_set_subpixel(@ptrCast(state), @intCast(@intFromEnum(subpixel)));
+ }
+
+ pub fn setBuffer(state: *State, buffer: *Buffer) void {
+ c.wlr_output_state_set_buffer(@ptrCast(state), @ptrCast(buffer));
+ }
+
+ pub fn setDamage(state: *State, damage: *const pixman.Region32) void {
+ c.wlr_output_state_set_damage(@ptrCast(state), @ptrCast(damage));
+ }
+
+ pub fn copy(dst: *State, src: *const State) bool {
+ return c.wlr_output_state_copy(@ptrCast(dst), @ptrCast(src));
+ }
+
+ comptime {
+ const Real = c.wlr_output_state;
+ assertFieldOffset(State, Real, "committed");
+ assertFieldOffset(State, Real, "allow_reconfiguration");
+ assertFieldOffset(State, Real, "damage");
+ assertFieldOffset(State, Real, "enabled");
+ assertFieldOffset(State, Real, "scale");
+ assertFieldOffset(State, Real, "transform");
+ assertFieldOffset(State, Real, "adaptive_sync_enabled");
+ assertFieldOffset(State, Real, "render_format");
+ assertFieldOffset(State, Real, "subpixel");
+ assertFieldOffset(State, Real, "buffer");
+ assertFieldOffset(State, Real, "buffer_src_box");
+ assertFieldOffset(State, Real, "buffer_dst_box");
+ assertFieldOffset(State, Real, "tearing_page_flip");
+ assertFieldOffset(State, Real, "mode_type");
+ assertFieldOffset(State, Real, "mode");
+ assertFieldOffset(State, Real, "custom_mode");
+ assertFieldOffset(State, Real, "layers");
+ assertFieldOffset(State, Real, "layers_len");
+ assertFieldOffset(State, Real, "wait_timeline");
+ assertFieldOffset(State, Real, "wait_point");
+ assertFieldOffset(State, Real, "signal_timeline");
+ assertFieldOffset(State, Real, "signal_point");
+ assertFieldOffset(State, Real, "color_transform");
+ assertFieldOffset(State, Real, "image_description");
+ assertSameLayout(State, Real);
+ }
+ };
+
+ pub const event = struct {
+ /// Truncated after `presented`: nothing else is read.
+ pub const Present = extern struct {
+ output: *Output,
+ commit_seq: u32,
+ presented: bool,
+
+ comptime {
+ const Real = c.wlr_output_event_present;
+ assertFieldOffset(Present, Real, "output");
+ assertFieldOffset(Present, Real, "commit_seq");
+ assertFieldOffset(Present, Real, "presented");
+ }
+ };
+
+ pub const Commit = extern struct {
+ output: *Output,
+ when: std.posix.timespec,
+ state: *const State,
+
+ comptime {
+ const Real = c.wlr_output_event_commit;
+ assertFieldOffset(Commit, Real, "output");
+ assertFieldOffset(Commit, Real, "when");
+ assertFieldOffset(Commit, Real, "state");
+ assertSameLayout(Commit, Real);
+ }
+ };
+
+ pub const RequestState = extern struct {
+ output: *Output,
+ state: *const State,
+
+ comptime {
+ const Real = c.wlr_output_event_request_state;
+ assertFieldOffset(RequestState, Real, "output");
+ assertFieldOffset(RequestState, Real, "state");
+ assertSameLayout(RequestState, Real);
+ }
+ };
+ };
+
+ const Impl = opaque {};
+
+ impl: *const Impl,
+ backend: *Backend,
+ event_loop: *wl.EventLoop,
+
+ global: ?*wl.Global,
+ resources: wl.list.Head(wl.Output, null),
+
+ name: [*:0]u8,
+ description: ?[*:0]u8,
+ make: ?[*:0]u8,
+ model: ?[*:0]u8,
+ serial: ?[*:0]u8,
+ phys_width: i32,
+ phys_height: i32,
+ default_primaries: ?*const anyopaque,
+
+ modes: wl.list.Head(Mode, .link),
+ current_mode: ?*Mode,
+ width: i32,
+ height: i32,
+ refresh: i32,
+
+ supported_primaries: u32,
+ supported_transfer_functions: u32,
+
+ enabled: bool,
+ scale: f32,
+ subpixel: wl.Output.Subpixel,
+ transform: wl.Output.Transform,
+ adaptive_sync_status: AdaptiveSyncStatus,
+ render_format: u32,
+ image_description: ?*const anyopaque,
+
+ adaptive_sync_supported: bool,
+
+ needs_frame: bool,
+ frame_pending: bool,
+
+ non_desktop: bool,
+
+ commit_seq: u32,
+
+ events: extern struct {
+ /// Self-payload by wlroots convention (no dedicated event struct).
+ frame: wl.Signal(*Output),
+ /// Placeholder payload: nothing connects this signal (see file doc).
+ damage: wl.Signal(void),
+ /// Placeholder payload: nothing connects this signal (see file doc).
+ needs_frame: wl.Signal(void),
+ /// Placeholder payload: nothing connects this signal (see file doc).
+ precommit: wl.Signal(void),
+ commit: wl.Signal(*event.Commit),
+ present: wl.Signal(*event.Present),
+ /// Placeholder payload: nothing connects this signal (see file doc).
+ bind: wl.Signal(void),
+ /// Self-payload by wlroots convention (no dedicated event struct).
+ description: wl.Signal(*Output),
+ request_state: wl.Signal(*event.RequestState),
+ /// Self-payload by wlroots convention (no dedicated event struct).
+ destroy: wl.Signal(*Output),
+ },
+
+ idle_frame: ?*wl.EventSource,
+ idle_done: ?*wl.EventSource,
+
+ attach_render_locks: c_int,
+
+ cursors: wl.list.Head(OutputCursor, .link),
+
+ hardware_cursor: ?*OutputCursor,
+ cursor_swapchain: ?*anyopaque,
+ cursor_front_buffer: ?*Buffer,
+ software_cursor_locks: c_int,
+
+ layers: wl.list.Link,
+
+ allocator: ?*anyopaque,
+ renderer: ?*anyopaque,
+ swapchain: ?*anyopaque,
+
+ addons: wl.list.Link,
+
+ data: ?*anyopaque,
+
+ pub fn createGlobal(output: *Output, server: *wl.Server) void {
+ c.wlr_output_create_global(@ptrCast(output), @ptrCast(server));
+ }
+
+ pub fn destroyGlobal(output: *Output) void {
+ c.wlr_output_destroy_global(@ptrCast(output));
+ }
+
+ pub fn initRender(output: *Output, allocator: *Allocator, renderer: *Renderer) bool {
+ return c.wlr_output_init_render(@ptrCast(output), @ptrCast(allocator), @ptrCast(renderer));
+ }
+
+ pub fn preferredMode(output: *Output) ?*Mode {
+ return @ptrCast(c.wlr_output_preferred_mode(@ptrCast(output)));
+ }
+
+ pub fn setName(output: *Output, name: [*:0]const u8) void {
+ c.wlr_output_set_name(@ptrCast(output), name);
+ }
+
+ pub fn setDescription(output: *Output, desc: [*:0]const u8) void {
+ c.wlr_output_set_description(@ptrCast(output), desc);
+ }
+
+ pub fn scheduleDone(output: *Output) void {
+ c.wlr_output_schedule_done(@ptrCast(output));
+ }
+
+ pub fn destroy(output: *Output) void {
+ c.wlr_output_destroy(@ptrCast(output));
+ }
+
+ pub fn transformedResolution(output: *Output, width: *c_int, height: *c_int) void {
+ c.wlr_output_transformed_resolution(@ptrCast(output), width, height);
+ }
+
+ pub fn effectiveResolution(output: *Output, width: *c_int, height: *c_int) void {
+ c.wlr_output_effective_resolution(@ptrCast(output), width, height);
+ }
+
+ pub fn testState(output: *Output, state: *const State) bool {
+ return c.wlr_output_test_state(@ptrCast(output), @ptrCast(state));
+ }
+
+ pub fn commitState(output: *Output, state: *const State) bool {
+ return c.wlr_output_commit_state(@ptrCast(output), @ptrCast(state));
+ }
+
+ pub fn scheduleFrame(output: *Output) void {
+ c.wlr_output_schedule_frame(@ptrCast(output));
+ }
+
+ pub fn getGammaSize(output: *Output) usize {
+ return c.wlr_output_get_gamma_size(@ptrCast(output));
+ }
+
+ pub fn fromWlOutput(resource: *wl.Output) ?*Output {
+ return @ptrCast(c.wlr_output_from_resource(@ptrCast(@alignCast(resource))));
+ }
+
+ pub fn lockAttachRender(output: *Output, lock: bool) void {
+ c.wlr_output_lock_attach_render(@ptrCast(output), lock);
+ }
+
+ pub fn lockSoftwareCursors(output: *Output, lock: bool) void {
+ c.wlr_output_lock_software_cursors(@ptrCast(output), lock);
+ }
+
+ pub fn isDirectScanoutAllowed(output: *Output) bool {
+ return c.wlr_output_is_direct_scanout_allowed(@ptrCast(output));
+ }
+
+ pub fn isDrm(output: *Output) bool {
+ return c.wlr_output_is_drm(@ptrCast(output));
+ }
+
+ pub fn isHeadless(output: *Output) bool {
+ return c.wlr_output_is_headless(@ptrCast(output));
+ }
+
+ pub fn isWl(output: *Output) bool {
+ return c.wlr_output_is_wl(@ptrCast(output));
+ }
+
+ pub fn isX11(output: *Output) bool {
+ return c.wlr_output_is_x11(@ptrCast(output));
+ }
+
+ comptime {
+ const Real = c.wlr_output;
+ assertFieldOffset(Output, Real, "impl");
+ assertFieldOffset(Output, Real, "backend");
+ assertFieldOffset(Output, Real, "event_loop");
+ assertFieldOffset(Output, Real, "global");
+ assertFieldOffset(Output, Real, "resources");
+ assertFieldOffset(Output, Real, "name");
+ assertFieldOffset(Output, Real, "description");
+ assertFieldOffset(Output, Real, "make");
+ assertFieldOffset(Output, Real, "model");
+ assertFieldOffset(Output, Real, "serial");
+ assertFieldOffset(Output, Real, "phys_width");
+ assertFieldOffset(Output, Real, "phys_height");
+ assertFieldOffset(Output, Real, "default_primaries");
+ assertFieldOffset(Output, Real, "modes");
+ assertFieldOffset(Output, Real, "current_mode");
+ assertFieldOffset(Output, Real, "width");
+ assertFieldOffset(Output, Real, "height");
+ assertFieldOffset(Output, Real, "refresh");
+ assertFieldOffset(Output, Real, "supported_primaries");
+ assertFieldOffset(Output, Real, "supported_transfer_functions");
+ assertFieldOffset(Output, Real, "enabled");
+ assertFieldOffset(Output, Real, "scale");
+ assertFieldOffset(Output, Real, "subpixel");
+ assertFieldOffset(Output, Real, "transform");
+ assertFieldOffset(Output, Real, "adaptive_sync_status");
+ assertFieldOffset(Output, Real, "render_format");
+ assertFieldOffset(Output, Real, "image_description");
+ assertFieldOffset(Output, Real, "adaptive_sync_supported");
+ assertFieldOffset(Output, Real, "needs_frame");
+ assertFieldOffset(Output, Real, "frame_pending");
+ assertFieldOffset(Output, Real, "non_desktop");
+ assertFieldOffset(Output, Real, "commit_seq");
+ assertFieldOffset(Output, Real, "events");
+ assertFieldOffset(Output, Real, "idle_frame");
+ assertFieldOffset(Output, Real, "idle_done");
+ assertFieldOffset(Output, Real, "attach_render_locks");
+ assertFieldOffset(Output, Real, "cursors");
+ assertFieldOffset(Output, Real, "hardware_cursor");
+ assertFieldOffset(Output, Real, "cursor_swapchain");
+ assertFieldOffset(Output, Real, "cursor_front_buffer");
+ assertFieldOffset(Output, Real, "software_cursor_locks");
+ assertFieldOffset(Output, Real, "layers");
+ assertFieldOffset(Output, Real, "allocator");
+ assertFieldOffset(Output, Real, "renderer");
+ assertFieldOffset(Output, Real, "swapchain");
+ assertFieldOffset(Output, Real, "addons");
+ assertFieldOffset(Output, Real, "data");
+
+ const Events = @FieldType(Output, "events");
+ const RealEvents = @FieldType(Real, "events");
+ for (.{ "frame", "damage", "needs_frame", "precommit", "commit", "present", "bind", "description", "request_state", "destroy" }) |field| {
+ assertSameLayout(@FieldType(Events, field), c.wl_signal);
+ assertFieldOffset(Events, RealEvents, field);
+ }
+ assertSameLayout(wl.list.Head(OutputCursor, .link), c.wl_list);
+ assertSameLayout(wl.list.Head(Mode, .link), c.wl_list);
+ assertSameLayout(wl.list.Head(wl.Output, null), c.wl_list);
+ assertSameLayout(AdaptiveSyncStatus, c.wlr_output_adaptive_sync_status);
+ }
+ };
+ };
+}
diff --git a/src/wlr/output_layout.zig b/src/wlr/output_layout.zig
new file mode 100644
index 0000000..89d4075
--- /dev/null
+++ b/src/wlr/output_layout.zig
@@ -0,0 +1,101 @@
+//! wlr.OutputLayout, backed by @cImport against
+//! wlr/types/wlr_output_layout.h. `OutputLayout.Output` (the per-output
+//! layout entry) is declared only far enough to be a valid
+//! `wl.list.Head` element -- RediWM never calls `.get()` or walks
+//! `layout.outputs` itself, only `events.change` on the layout itself.
+const wl = @import("wayland").server.wl;
+const c = @import("c.zig").c;
+const assertSameLayout = @import("signal.zig").assertSameLayout;
+const assertFieldOffset = @import("signal.zig").assertFieldOffset;
+const box = @import("box.zig");
+
+pub fn Types(comptime WlrOutput: type) type {
+ return struct {
+ pub const OutputLayout = extern struct {
+ pub const Output = extern struct {
+ layout: *OutputLayout,
+ output: *WlrOutput,
+ x: c_int,
+ y: c_int,
+ /// OutputLayout.outputs
+ link: wl.list.Link,
+ auto_configured: bool,
+
+ events: extern struct {
+ destroy: wl.Signal(*Output),
+ },
+
+ comptime {
+ const Real = c.wlr_output_layout_output;
+ assertFieldOffset(Output, Real, "layout");
+ assertFieldOffset(Output, Real, "output");
+ assertFieldOffset(Output, Real, "x");
+ assertFieldOffset(Output, Real, "y");
+ assertFieldOffset(Output, Real, "link");
+ assertFieldOffset(Output, Real, "auto_configured");
+ assertFieldOffset(Output, Real, "events");
+ assertSameLayout(@FieldType(Output, "events"), @FieldType(Real, "events"));
+ }
+ };
+
+ outputs: wl.list.Head(Output, .link),
+ server: *wl.Server,
+
+ events: extern struct {
+ add: wl.Signal(*Output),
+ change: wl.Signal(*OutputLayout),
+ destroy: wl.Signal(*OutputLayout),
+ },
+
+ data: ?*anyopaque,
+
+ pub fn create(server: *wl.Server) !*OutputLayout {
+ const raw = c.wlr_output_layout_create(@ptrCast(server));
+ return @as(?*OutputLayout, @ptrCast(raw)) orelse error.OutOfMemory;
+ }
+
+ pub fn destroy(layout: *OutputLayout) void {
+ c.wlr_output_layout_destroy(@ptrCast(layout));
+ }
+
+ pub fn outputAt(layout: *OutputLayout, lx: f64, ly: f64) ?*WlrOutput {
+ return @ptrCast(c.wlr_output_layout_output_at(@ptrCast(layout), lx, ly));
+ }
+
+ pub fn add(layout: *OutputLayout, output: *WlrOutput, lx: c_int, ly: c_int) !*Output {
+ const raw = c.wlr_output_layout_add(@ptrCast(layout), @ptrCast(output), lx, ly);
+ return @as(?*Output, @ptrCast(raw)) orelse error.OutOfMemory;
+ }
+
+ pub fn addAuto(layout: *OutputLayout, output: *WlrOutput) !*Output {
+ const raw = c.wlr_output_layout_add_auto(@ptrCast(layout), @ptrCast(output));
+ return @as(?*Output, @ptrCast(raw)) orelse error.OutOfMemory;
+ }
+
+ pub fn remove(layout: *OutputLayout, output: *WlrOutput) void {
+ c.wlr_output_layout_remove(@ptrCast(layout), @ptrCast(output));
+ }
+
+ pub fn getBox(layout: *OutputLayout, reference: ?*WlrOutput, dest_box: ?*box.Box) void {
+ c.wlr_output_layout_get_box(@ptrCast(layout), @ptrCast(reference), @ptrCast(dest_box));
+ }
+
+ comptime {
+ const Real = c.wlr_output_layout;
+ assertFieldOffset(OutputLayout, Real, "outputs");
+ assertFieldOffset(OutputLayout, Real, "events");
+ assertFieldOffset(OutputLayout, Real, "data");
+
+ const Events = @FieldType(OutputLayout, "events");
+ const RealEvents = @FieldType(Real, "events");
+ assertSameLayout(@FieldType(Events, "add"), c.wl_signal);
+ assertSameLayout(@FieldType(Events, "change"), c.wl_signal);
+ assertSameLayout(@FieldType(Events, "destroy"), c.wl_signal);
+ assertFieldOffset(Events, RealEvents, "add");
+ assertFieldOffset(Events, RealEvents, "change");
+ assertFieldOffset(Events, RealEvents, "destroy");
+ assertSameLayout(wl.list.Head(Output, .link), c.wl_list);
+ }
+ };
+ };
+}
diff --git a/src/wlr/wlr.zig b/src/wlr/wlr.zig
index ce2f2a0..4109dbc 100644
--- a/src/wlr/wlr.zig
+++ b/src/wlr/wlr.zig
@@ -8,7 +8,7 @@
//! until a type actually moves off it.
const old = @import("old");
-const output_power = @import("output_power.zig").Types(old.Output);
+const output_power = @import("output_power.zig").Types(Output);
pub const OutputPowerManagerV1 = output_power.OutputPowerManagerV1;
pub const OutputPowerV1 = output_power.OutputPowerV1;
@@ -38,19 +38,40 @@ const pointer_constraints = @import("pointer_constraints.zig").Types(old.Surface
pub const PointerConstraintsV1 = pointer_constraints.PointerConstraintsV1;
pub const PointerConstraintV1 = pointer_constraints.PointerConstraintV1;
-// --- Not yet migrated: forwarded straight to zig-wlroots. ---
-//
-// Box/FBox/Edges are drafted and verified against the real headers in
-// box.zig/edges.zig, but NOT wired in here yet: Zig's extern structs are
-// nominally typed, and OutputLayout.getBox, XdgToplevel.setTiled, and
-// others still on `old` take/return *their* Box/Edges in their own
-// signatures. Swapping Box/Edges alone makes those calls a hard type
-// error. They migrate together with (or after) everything that
-// references them in a public signature -- see the migration-order note
-// in the plan. Until then they stay on `old` like everything else below.
-pub const Box = old.Box;
-pub const FBox = old.FBox;
-pub const Edges = old.Edges;
+const output_mod = @import("output.zig").Types(old.Backend, old.Renderer, old.Allocator, old.Buffer, old.ColorTransform);
+pub const Output = output_mod.Output;
+pub const OutputCursor = output_mod.OutputCursor;
+
+const output_layout_mod = @import("output_layout.zig").Types(Output);
+pub const OutputLayout = output_layout_mod.OutputLayout;
+
+// Box/FBox/Edges: OutputLayout.getBox was their main blocker (45 call
+// sites) and just migrated above. The remaining crossings
+// (Surface.getBufferSourceBox, XdgPopup.unconstrainFromBox,
+// InputPopupSurfaceV2.sendTextInputRectangle, XdgToplevel.setTiled) are
+// single-digit call counts against types that haven't migrated, each
+// handled with a `@ptrCast` at that one call site instead of waiting for
+// those types too -- see assertSameLayout(Box, old.Box) below, which is
+// exactly what makes that cast provably safe.
+pub const Box = @import("box.zig").Box;
+pub const FBox = @import("box.zig").FBox;
+pub const Edges = @import("edges.zig").Edges;
+
+comptime {
+ const assertSameLayout = @import("signal.zig").assertSameLayout;
+ assertSameLayout(Box, old.Box);
+ assertSameLayout(FBox, old.FBox);
+ assertSameLayout(Edges, old.Edges);
+}
+
+/// Backend, ForeignToplevelHandleV1 and anything else still on `old`
+/// that embeds `*wlr.Output` in its own signature (a signal payload, a
+/// method parameter) is pinned to zig-wlroots's own Output type, not
+/// ours, for exactly that crossing -- see Server.zig's `new_output`
+/// listener and foreign_toplevel.zig's `outputEnter`/`outputLeave` for
+/// the two places that needs a `@ptrCast`. Exposed here rather than
+/// scattered `@import("old")`s so every such crossing reads the same way.
+pub const zig_wlroots = old;
pub const AddonSet = old.AddonSet;
pub const Allocator = old.Allocator;
@@ -86,11 +107,8 @@ pub const LayerShellV1 = old.LayerShellV1;
pub const LayerSurfaceV1 = old.LayerSurfaceV1;
pub const LinuxDmabufV1 = old.LinuxDmabufV1;
pub const LinuxDrmSyncobjManagerV1 = old.LinuxDrmSyncobjManagerV1;
-pub const Output = old.Output;
pub const OutputConfigurationV1 = old.OutputConfigurationV1;
-pub const OutputCursor = old.OutputCursor;
pub const OutputHeadV1 = old.OutputHeadV1;
-pub const OutputLayout = old.OutputLayout;
pub const OutputManagerV1 = old.OutputManagerV1;
pub const Pointer = old.Pointer;
pub const PointerGesturesV1 = old.PointerGesturesV1;
diff --git a/src/xdg.zig b/src/xdg.zig
index 95c6498..57fef94 100644
--- a/src/xdg.zig
+++ b/src/xdg.zig
@@ -110,7 +110,9 @@ fn handleRequestResize(
const toplevel = adapter.window;
const surface = adapter.xdg_toplevel.base.surface;
if (!toplevel.server.input.seat.validatePointerGrabSerial(surface, event.serial)) return;
- toplevel.server.input.startResize(toplevel, event.edges, null, 0x110);
+ // XdgToplevel hasn't migrated off zig-wlroots; see wlr.zig's
+ // assertSameLayout(Edges, old.Edges) for why this cast is safe.
+ toplevel.server.input.startResize(toplevel, @bitCast(event.edges), null, 0x110);
}
fn handleRequestMaximize(listener: *wl.Listener(void)) void {