Workaround global anonymous field name counter

Fixes https://github.com/ifreund/river/issues/17
This commit is contained in:
Isaac Freund 2020-04-28 19:16:01 +02:00
parent 7988a2e934
commit d962e6a9a5
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
3 changed files with 12 additions and 3 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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";