[Xcb] How to associate user/misc pointer with an xcb_window_t

Josh Triplett josh at joshtriplett.org
Wed Dec 25 13:03:49 PST 2013


On Wed, Dec 25, 2013 at 11:18:59AM -0500, Sam Varshavchik wrote:
> I am going through xcb's developer documentation. I'm looking for a
> way to associate a generic miscellaneous pointer with a window,
> specifically an xcb_window_t.
> 
> It's a common design paradigm with UI libraries: a way to stash some
> generic/miscellaneous pointer to application-specific data,
> associating it with the UI library's resource, such as a window. The
> application can subsequently retrieve it, when it wants to find the
> application-specific data that's associated with the window.
> 
> So, for example, if I get an xcb_expose_event_t, I can take the
> referenced xcb_window_t, retrieve the application data, and know
> what to do with this window.

There's no built-in means of associating data with an XCB data
structure; XCB stores data as it appears in the X11 protocol, which does
not include auxiliary data pointers.

In the case of windows and other XID types, I'd suggest using the XIDs
as keys in an associative array of your own construction, with whatever
data you need as the corresponding value.  Most sensible UI libraries
either have or build on a library of data structures that C doesn't
already have, notably associative arrays.

- Josh Triplett


More information about the Xcb mailing list