git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit2e849c742d9e620eec5ceffeff9d867e3c451c14
parent35d3ecdf2e
authorIsaac Freund <[email protected]>
date2020-04-28 19:16
Workaround global anonymous field name counter

Fixes https://github.com/ifreund/river/issues/17

 src/c.zig            | 6 ++++++
 src/keyboard.zig     | 4 ++--
 src/xdg_toplevel.zig | 5 ++++-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/c.zig b/src/c.zig
index a551d8e..72bbc04 100644
--- a/src/c.zig
+++ b/src/c.zig
@@ -30,3 +30,9 @@ pub usingnamespace @cImport({
     // that can be automatically imported
     @cInclude("include/bindings.h");
 });
+
+// These are needed because zig currently names translated anonymous unions
+// with a global counter, which makes code unportable.
+// See https://github.com/ifreund/river/issues/17
+pub const wlr_xdg_surface_union = @typeInfo(wlr_xdg_surface).Struct.fields[5].name;
+pub const wlr_input_device_union = @typeInfo(wlr_input_device).Struct.fields[8].name;
diff --git a/src/keyboard.zig b/src/keyboard.zig
index 86d40d6..c1a46dc 100644
--- a/src/keyboard.zig
+++ b/src/keyboard.zig
@@ -17,7 +17,7 @@ pub const Keyboard = struct {
     pub fn init(self: *Self, seat: *Seat, device: *c.wlr_input_device) !void {
         self.seat = seat;
         self.device = device;
-        self.wlr_keyboard = device.unnamed_134.keyboard;
+        self.wlr_keyboard = @field(device, c.wlr_input_device_union).keyboard;
 
         // We need to prepare an XKB keymap and assign it to the keyboard. This
         // assumes the defaults (e.g. layout = "us").
@@ -60,7 +60,7 @@ pub const Keyboard = struct {
             @alignCast(@alignOf(*c.wlr_event_keyboard_key), data),
         );
 
-        const wlr_keyboard: *c.wlr_keyboard = self.device.unnamed_134.keyboard;
+        const wlr_keyboard = self.wlr_keyboard;
 
         // Translate libinput keycode -> xkbcommon
         const keycode = event.keycode + 8;
diff --git a/src/xdg_toplevel.zig b/src/xdg_toplevel.zig
index 7abcd6e..8f20af0 100644
--- a/src/xdg_toplevel.zig
+++ b/src/xdg_toplevel.zig
@@ -110,7 +110,10 @@ fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
         view.natural_height = @intCast(u32, self.wlr_xdg_surface.surface.*.current.height);
     }
 
-    const wlr_xdg_toplevel: *c.wlr_xdg_toplevel = self.wlr_xdg_surface.unnamed_166.toplevel;
+    const wlr_xdg_toplevel: *c.wlr_xdg_toplevel = @field(
+        self.wlr_xdg_surface,
+        c.wlr_xdg_surface_union,
+    ).toplevel;
     const state = &wlr_xdg_toplevel.current;
     const app_id: [*:0]const u8 = if (wlr_xdg_toplevel.app_id) |id| id else "NULL";