Skip to content

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

Migrate wlr.KeyboardShortcutsInhibitManagerV1/InhibitorV1 off zig-wlroots

Claude5fed90abf936
diff --git a/src/wlr/c.zig b/src/wlr/c.zig
index 475989b..2cb2ca5 100644
--- a/src/wlr/c.zig
+++ b/src/wlr/c.zig
@@ -10,4 +10,5 @@ pub const c = @cImport({
@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");
+ @cInclude("wlr/types/wlr_keyboard_shortcuts_inhibit_v1.h");
});
diff --git a/src/wlr/keyboard_shortcuts_inhibit.zig b/src/wlr/keyboard_shortcuts_inhibit.zig
new file mode 100644
index 0000000..947044e
--- /dev/null
+++ b/src/wlr/keyboard_shortcuts_inhibit.zig
@@ -0,0 +1,78 @@
+//! wlr.KeyboardShortcutsInhibitManagerV1 / wlr.KeyboardShortcutsInhibitorV1,
+//! backed by @cImport against wlr/types/wlr_keyboard_shortcuts_inhibit_v1.h.
+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, comptime Seat: type) type {
+ return struct {
+ pub const KeyboardShortcutsInhibitorV1 = extern struct {
+ surface: *Surface,
+ seat: *Seat,
+ active: bool,
+ resource: *wl.Resource,
+ /// KeyboardShortcutsInhibitManagerV1.inhibitors
+ link: wl.list.Link,
+
+ events: extern struct {
+ destroy: wl.Signal(*KeyboardShortcutsInhibitorV1),
+ },
+
+ data: ?*anyopaque,
+
+ pub fn activate(inhibitor: *KeyboardShortcutsInhibitorV1) void {
+ c.wlr_keyboard_shortcuts_inhibitor_v1_activate(@ptrCast(inhibitor));
+ }
+
+ pub fn deactivate(inhibitor: *KeyboardShortcutsInhibitorV1) void {
+ c.wlr_keyboard_shortcuts_inhibitor_v1_deactivate(@ptrCast(inhibitor));
+ }
+
+ comptime {
+ const Real = c.wlr_keyboard_shortcuts_inhibitor_v1;
+ assertFieldOffset(KeyboardShortcutsInhibitorV1, Real, "surface");
+ assertFieldOffset(KeyboardShortcutsInhibitorV1, Real, "seat");
+ assertFieldOffset(KeyboardShortcutsInhibitorV1, Real, "active");
+ assertFieldOffset(KeyboardShortcutsInhibitorV1, Real, "resource");
+ assertFieldOffset(KeyboardShortcutsInhibitorV1, Real, "link");
+ assertFieldOffset(KeyboardShortcutsInhibitorV1, Real, "events");
+ assertFieldOffset(KeyboardShortcutsInhibitorV1, Real, "data");
+ assertSameLayout(@FieldType(KeyboardShortcutsInhibitorV1, "events"), @FieldType(Real, "events"));
+ }
+ };
+
+ pub const KeyboardShortcutsInhibitManagerV1 = extern struct {
+ inhibitors: wl.list.Head(KeyboardShortcutsInhibitorV1, .link),
+ global: *wl.Global,
+
+ events: extern struct {
+ new_inhibitor: wl.Signal(*KeyboardShortcutsInhibitorV1),
+ destroy: wl.Signal(*KeyboardShortcutsInhibitManagerV1),
+ },
+
+ data: ?*anyopaque,
+
+ pub fn create(server: *wl.Server) !*KeyboardShortcutsInhibitManagerV1 {
+ const raw = c.wlr_keyboard_shortcuts_inhibit_v1_create(@ptrCast(server));
+ return @as(?*KeyboardShortcutsInhibitManagerV1, @ptrCast(raw)) orelse error.OutOfMemory;
+ }
+
+ comptime {
+ const Real = c.wlr_keyboard_shortcuts_inhibit_manager_v1;
+ assertFieldOffset(KeyboardShortcutsInhibitManagerV1, Real, "inhibitors");
+ assertFieldOffset(KeyboardShortcutsInhibitManagerV1, Real, "global");
+ assertFieldOffset(KeyboardShortcutsInhibitManagerV1, Real, "events");
+ assertFieldOffset(KeyboardShortcutsInhibitManagerV1, Real, "data");
+
+ const Events = @FieldType(KeyboardShortcutsInhibitManagerV1, "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(KeyboardShortcutsInhibitorV1, .link), c.wl_list);
+ }
+ };
+ };
+}
diff --git a/src/wlr/wlr.zig b/src/wlr/wlr.zig
index b9e1923..c2fe6d0 100644
--- a/src/wlr/wlr.zig
+++ b/src/wlr/wlr.zig
@@ -19,6 +19,10 @@ const idle_inhibit = @import("idle_inhibit.zig").Types(old.Surface);
pub const IdleInhibitManagerV1 = idle_inhibit.IdleInhibitManagerV1;
pub const IdleInhibitorV1 = idle_inhibit.IdleInhibitorV1;
+const kb_shortcuts_inhibit = @import("keyboard_shortcuts_inhibit.zig").Types(old.Surface, old.Seat);
+pub const KeyboardShortcutsInhibitManagerV1 = kb_shortcuts_inhibit.KeyboardShortcutsInhibitManagerV1;
+pub const KeyboardShortcutsInhibitorV1 = kb_shortcuts_inhibit.KeyboardShortcutsInhibitorV1;
+
// --- Not yet migrated: forwarded straight to zig-wlroots. ---
//
// Box/FBox/Edges are drafted and verified against the real headers in
@@ -64,8 +68,6 @@ pub const InputMethodManagerV2 = old.InputMethodManagerV2;
pub const InputMethodV2 = old.InputMethodV2;
pub const InputPopupSurfaceV2 = old.InputPopupSurfaceV2;
pub const Keyboard = old.Keyboard;
-pub const KeyboardShortcutsInhibitManagerV1 = old.KeyboardShortcutsInhibitManagerV1;
-pub const KeyboardShortcutsInhibitorV1 = old.KeyboardShortcutsInhibitorV1;
pub const LayerShellV1 = old.LayerShellV1;
pub const LayerSurfaceV1 = old.LayerSurfaceV1;
pub const LinuxDmabufV1 = old.LinuxDmabufV1;