I've been attempting to rewrite some C code for a Wayland client in Zig using only the client API (via zig-wayland's scanner) and for some reason I can't grab the seat name when I set the listener, very frustrating
It's got to be the way Zig handles struct memory, I just don't know how... I doubt I actually need an extern struct but I bet if I can throw pointers around like it's C I'll figure out the rest later
#C #Zig #Wayland
If I could be bothered to stop slamming `zig build run` I bet I could turn my notes into some good, although insanely nerdy, blog posts
I probably won't, kind of obsessed with other stuff now, but I could ;)
@AndyScott yeah, you likely need to duplicate the string with an allocator. I expect the seat name string is only valid during the WL_seat callback. I know that's the case in my Wayland client API for zig, shimizu.
@AndyScott maybe the structs have padding between fields, try using packed structs and see if that makes a difference.
I did something similar recently in Odin and it turned out that the memory layout of the struct must not include padding between struct fields because of the wire protocol.
@AndyScott if you need a guaranteed memory layout (or c interop) you need an extern struct. Zig does not guarantee that it won't reorder the fields of regular structs.
@leroycep That's kind of what I figured - even packed structs seem to add padding now.
Even with a simple `ArrayListUnmanaged([:0] const u8)` if I pass a pointer to the array, allocate to a const slice (dupeZ), then append I get no joy either. But it occurs to me that the list is just a struct internally.
Although, nothing I do in the seat listener changes the rest of the program. Something is wrong ;)
Anyway... thanks! I'll see if I have better luck with an extern struct.
@AndyScott packed structs are used for bit-packing, they are backed by a single integer, unlike an extern struct, which you can think of as being backed by an array of bytes.
If you want more in depth help you might try https://ziggit.dev