From d962e6a9a584e21623ee1cb2439c74d166aceaa0 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Tue, 28 Apr 2020 19:16:01 +0200 Subject: [PATCH] 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";