Trying out some XCB in kotlin with cinterop, and i am struggling to set a window atom.
xcb_change_property(
this.connection,
XCB_PROP_MODE_REPLACE.toUByte(),
window,
windowTypeReply.pointed.atom,
XCB_ATOM_ATOM,
32,
2,
windowTypeDockReply.pointed.atom // THIS needs to be a CValuesRef
)
The windowTypeDockReply is of the type CPointer<xcb_intern_atom_reply_t>, which has a property atom of the type xcb_atom_t which can be accessed through the .pointed property.
The function xcb_change_property in c requires a const void *data as its last parameter. In Kotlin however it requires a kotlinx.cinterop.CValuesRef<*>? .
So i am wondering how i can make windowTypeDockReply.pointed.atom into a CValuesRef?
Documentation states:
The .pointed property for CPointer<T> returns the lvalue of type T , pointed by this pointer. The reverse operation is .ptr : it takes the lvalue and returns the pointer to it.
But windowTypeReply.pointed.atom does not have a .ptr property.
Edit: or in other words, how to get the pointer to a field of the structure xcb_intern_atom_reply_t?
After countless hours of trial and error, and a lot of help on Slack, a workaround would be to allocating a temporary variable of the type xcb_atom_t inside a memscoped, assigning windowTypeDockReply.pointed.atom as its value, and then using its .ptr in the function call where it was needed initially:
val windowTypeReply = xcb_intern_atom_reply(
this.connection,
xcb_intern_atom(connection, 0, "_NET_WM_WINDOW_TYPE".length.toUShort(), "_NET_WM_WINDOW_TYPE"),
null
) ?: error("could not get atom")
val windowTypeDockReply = xcb_intern_atom_reply(
connection,
xcb_intern_atom(connection, 0, "_NET_WM_WINDOW_TYPE_DOCK".length.toUShort(), "_NET_WM_WINDOW_TYPE_DOCK"),
null
) ?: error("could not get atom")
memScoped {
val temporary = alloc<xcb_atom_tVar> {
value = windowTypeDockReply.pointed.atom
}
xcb_change_property(
connection,
XCB_PROP_MODE_REPLACE.toUByte(),
window,
windowTypeReply.pointed.atom,
XCB_ATOM_ATOM,
32,
1,
temporary.ptr
)
}
I can probably live with this, but i would really like to know why i can’t access the pointer of windowTypeDockReply.pointed.atom directly, and if there is a better solution to this problem?