RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Migrate wlr.IdleNotifierV1/IdleInhibitManagerV1/IdleInhibitorV1 off zig-wlroots
Claude887860291418
diff --git a/src/wlr/c.zig b/src/wlr/c.zigindex e4ccd3f..475989b 100644--- a/src/wlr/c.zig+++ b/src/wlr/c.zig@@ -8,4 +8,6 @@ pub const c = @cImport({@cInclude("wlr/util/box.h");@cInclude("wlr/util/edges.h");@cInclude("wlr/types/wlr_output_power_management_v1.h");+ @cInclude("wlr/types/wlr_idle_notify_v1.h");+ @cInclude("wlr/types/wlr_idle_inhibit_v1.h");});diff --git a/src/wlr/idle_inhibit.zig b/src/wlr/idle_inhibit.zignew file mode 100644index 0000000..7ecba25--- /dev/null+++ b/src/wlr/idle_inhibit.zig@@ -0,0 +1,70 @@+//! wlr.IdleInhibitManagerV1 / wlr.IdleInhibitorV1, backed by @cImport+//! against wlr/types/wlr_idle_inhibit_v1.h. `events.destroy` on the+//! inhibitor type carries the surface, not the inhibitor itself (see+//! wlr-protocols) -- that's not a mistake, wlroots really does type it+//! that way, matching src/session/idle.zig's existing+//! `wl.Listener(*wlr.Surface)`.+const wl = @import("wayland").server.wl;+const c = @import("c.zig").c;+const assertSameLayout = @import("signal.zig").assertSameLayout;+const assertFieldOffset = @import("signal.zig").assertFieldOffset;++pub fn Types(comptime Surface: type) type {+ return struct {+ pub const IdleInhibitorV1 = extern struct {+ surface: *Surface,+ resource: *wl.Resource,+ /// IdleInhibitManagerV1.inhibitors+ link: wl.list.Link,++ events: extern struct {+ destroy: wl.Signal(*Surface),+ },++ data: ?*anyopaque,++ comptime {+ const Real = c.wlr_idle_inhibitor_v1;+ assertFieldOffset(IdleInhibitorV1, Real, "surface");+ assertFieldOffset(IdleInhibitorV1, Real, "resource");+ assertFieldOffset(IdleInhibitorV1, Real, "link");+ assertFieldOffset(IdleInhibitorV1, Real, "events");+ assertFieldOffset(IdleInhibitorV1, Real, "data");+ assertSameLayout(@FieldType(IdleInhibitorV1, "events"), @FieldType(Real, "events"));+ }+ };++ pub const IdleInhibitManagerV1 = extern struct {+ inhibitors: wl.list.Head(IdleInhibitorV1, .link),+ global: *wl.Global,++ events: extern struct {+ new_inhibitor: wl.Signal(*IdleInhibitorV1),+ destroy: wl.Signal(*IdleInhibitManagerV1),+ },++ data: ?*anyopaque,++ pub fn create(server: *wl.Server) !*IdleInhibitManagerV1 {+ const raw = c.wlr_idle_inhibit_v1_create(@ptrCast(server));+ return @as(?*IdleInhibitManagerV1, @ptrCast(raw)) orelse error.OutOfMemory;+ }++ comptime {+ const Real = c.wlr_idle_inhibit_manager_v1;+ assertFieldOffset(IdleInhibitManagerV1, Real, "inhibitors");+ assertFieldOffset(IdleInhibitManagerV1, Real, "global");+ assertFieldOffset(IdleInhibitManagerV1, Real, "events");+ assertFieldOffset(IdleInhibitManagerV1, Real, "data");++ const Events = @FieldType(IdleInhibitManagerV1, "events");+ const RealEvents = @FieldType(Real, "events");+ assertSameLayout(@FieldType(Events, "new_inhibitor"), c.wl_signal);+ assertSameLayout(@FieldType(Events, "destroy"), c.wl_signal);+ assertFieldOffset(Events, RealEvents, "new_inhibitor");+ assertFieldOffset(Events, RealEvents, "destroy");+ assertSameLayout(wl.list.Head(IdleInhibitorV1, .link), c.wl_list);+ }+ };+ };+}diff --git a/src/wlr/idle_notify.zig b/src/wlr/idle_notify.zignew file mode 100644index 0000000..203a81c--- /dev/null+++ b/src/wlr/idle_notify.zig@@ -0,0 +1,33 @@+//! wlr.IdleNotifierV1, backed by @cImport against+//! wlr/types/wlr_idle_notify_v1.h. Every field but `global` is+//! WLR_PRIVATE in the real struct, so there's nothing else to redeclare+//! or assert beyond it -- `global` is the struct's first field, so its+//! offset is always 0 regardless.+const wl = @import("wayland").server.wl;+const c = @import("c.zig").c;+const assertFieldOffset = @import("signal.zig").assertFieldOffset;++pub fn Types(comptime Seat: type) type {+ return struct {+ pub const IdleNotifierV1 = extern struct {+ global: *wl.Global,++ pub fn create(server: *wl.Server) !*IdleNotifierV1 {+ const raw = c.wlr_idle_notifier_v1_create(@ptrCast(server));+ return @as(?*IdleNotifierV1, @ptrCast(raw)) orelse error.OutOfMemory;+ }++ pub fn setInhibited(notifier: *IdleNotifierV1, inhibited: bool) void {+ c.wlr_idle_notifier_v1_set_inhibited(@ptrCast(notifier), inhibited);+ }++ pub fn notifyActivity(notifier: *IdleNotifierV1, seat: *Seat) void {+ c.wlr_idle_notifier_v1_notify_activity(@ptrCast(notifier), @ptrCast(seat));+ }++ comptime {+ assertFieldOffset(IdleNotifierV1, c.wlr_idle_notifier_v1, "global");+ }+ };+ };+}diff --git a/src/wlr/wlr.zig b/src/wlr/wlr.zigindex 4bd40f2..b9e1923 100644--- a/src/wlr/wlr.zig+++ b/src/wlr/wlr.zig@@ -12,6 +12,13 @@ const output_power = @import("output_power.zig").Types(old.Output);pub const OutputPowerManagerV1 = output_power.OutputPowerManagerV1;pub const OutputPowerV1 = output_power.OutputPowerV1;+const idle_notify = @import("idle_notify.zig").Types(old.Seat);+pub const IdleNotifierV1 = idle_notify.IdleNotifierV1;++const idle_inhibit = @import("idle_inhibit.zig").Types(old.Surface);+pub const IdleInhibitManagerV1 = idle_inhibit.IdleInhibitManagerV1;+pub const IdleInhibitorV1 = idle_inhibit.IdleInhibitorV1;+// --- Not yet migrated: forwarded straight to zig-wlroots. ---//// Box/FBox/Edges are drafted and verified against the real headers in@@ -52,9 +59,6 @@ pub const ExtOutputImageCaptureSourceManagerV1 = old.ExtOutputImageCaptureSourcepub const ForeignToplevelHandleV1 = old.ForeignToplevelHandleV1;pub const ForeignToplevelManagerV1 = old.ForeignToplevelManagerV1;pub const FractionalScaleManagerV1 = old.FractionalScaleManagerV1;-pub const IdleInhibitManagerV1 = old.IdleInhibitManagerV1;-pub const IdleInhibitorV1 = old.IdleInhibitorV1;-pub const IdleNotifierV1 = old.IdleNotifierV1;pub const InputDevice = old.InputDevice;pub const InputMethodManagerV2 = old.InputMethodManagerV2;pub const InputMethodV2 = old.InputMethodV2;