Reputation: 744
Platforms like Windows allow us to assign custom data to a window. With WinAPI, one can call SetWindowLongPtr
to assign custom data to a window. With AppKit, one extends his implementation of NSWindowDelegate
, which is assigned to a window, with the data required.
Is there an equivalent in xcb?
So far I tried...
I don't think either approach is good, thus I am wondering if there is built-in method to achieve what I need. Especially with latter, since I don't know how to make sure, that my properties do not collide with others, defined by the WM.
TL;DR: How can I annotate a window with custom data in xcb?
Upvotes: 1
Views: 470
Reputation: 8237
I don't know about xcb but what I used to do in X windows is somethintg like this. Say there is a structure where the data is being stored
struct CustomData
{
...
} custom;
When you allocate space for a pointer in the label, add sizeof(void*). Say the label is Fred.
const char* tag = "Fred";
size_t tag_len = strlen(tag) + 1;
Custom* custom_ptr = &custom;
size_t ptr_len = sizeof(Custom_ptr);
char* label = (char*) malloc(taglen + sizeof(void*));
strcpy(label, tag);
// Add pointer to custom
memcpy(&label[taglen], &custom_ptr, ptr_len);
XtSetValue(w, XtNLabel, label);
Then to get the value back
char* label;
Arg warg[16];
XtSetArg(warg[0], XtNLabel, &label);
XtGetValues(w, warg, 1);
size_t taglen = strlen(label) + 1;
Custom* custom_ptr;
memcpy(&custom_ptr, &label[taglen], sizeof(custom_ptr));
but that was in the mid-80s, way before STL was invented. Nowadays, I'd just do as @Ry said - create a map of widget ids and data.
Upvotes: 1