xcb_get_property(3)
π xcb_get_property(3) β the XCB Requests glow-up π
okay bestie, sit down, hydrate, because today we're learning how to get a window property and honestly? it's giving main character energy. this is xcb_get_property, straight from the XCB Requests lineup, and by the end of this page you're gonna be reading other windows' properties like it's their diary. π¦
β¨ NAME β¨
xcb_get_property β Gets a window property π
πΈ SYNOPSIS πΈ
first things first, you gotta bring in the header:
#include <xcb/xproto.h>
π Request function
xcb_get_property_cookie_t xcb_get_property(xcb_connection_t *conn,
uint8_t _delete, xcb_window_t window, xcb_atom_t property,
xcb_atom_t type, uint32_t long_offset, uint32_t long_length);
π Reply datastructure
typedef struct xcb_get_property_reply_t {
uint8_t response_type;
uint8_t format;
uint16_t sequence;
uint32_t length;
xcb_atom_t type;
uint32_t bytes_after;
uint32_t value_len;
uint8_t pad0[12];
} xcb_get_property_reply_t;
π Reply function
xcb_get_property_reply_t *xcb_get_property_reply(xcb_connection_t *conn,
xcb_get_property_cookie_t cookie, xcb_generic_error_t **e);
π Reply accessors
void *xcb_get_property_value(const xcb_get_property_request_t *reply);
int xcb_get_property_value_length(const xcb_get_property_reply_t
*reply);
xcb_generic_iterator_t xcb_get_property_value_end(const
xcb_get_property_reply_t *reply);
β REQUEST ARGUMENTS β
like, every single one, no skipping, periodt:
connβ your XCB connection to X11. the whole vibe starts here._deleteβ whether the property should actually get deleted. and heads up bestie: if you're deleting a property, thetypeyou specify has to match the actual property type. no catfishing allowed. πwindowβ the window whose property you're trying to get. yes, that window.propertyβ the property you want to get (it's an atom).typeβ the type of the property you want to get (also an atom).long_offsetβ the offset (in 32-bit multiples!) in the specified property where the data should start being retrieved from.long_lengthβ how many 32-bit multiples of data should be retrieved. so if you setlong_lengthto4, you'll receive16bytes of data. math! we love her. β¨
π REPLY FIELDS π
response_typeβ the type of this reply, which in this case isXCB_GET_PROPERTY. this field is also chillin' in thexcb_generic_reply_t, and you can use it to tell replies apart from each other.sequenceβ the sequence number of the last request processed by the X11 server.lengthβ the length of the reply, in words (and a word is4bytes, ikr).formatβ tells you whether the data should be viewed as a list of 8-bit, 16-bit, or 32-bit quantities. possible values are8,16, and32. this info lets the X server correctly do byte-swap operations when it needs to. so thoughtful of it.typeβ the actual type of the property (an atom).bytes_afterβ how many bytes are remaining to be read in the property if a partial read happened.value_lenβ the length of value. and bestie, please use the corresponding accessor instead of this field. i'm literally begging. π«Ά
π¦ DESCRIPTION π¦
so what does it do? it gets the specified property from the specified window. properties are things like the window title (WM_NAME) or its minimum size (WM_NORMAL_HINTS). protocols like EWMH also use properties β for example, EWMH defines the window title, encoded as a UTF-8 string, in the _NET_WM_NAME property.
and then, iconic honesty from the original authors:
TODO: talk about typeTODO: talk about deleteTODO: talk about the offset/length thing. what's a valid use case?
we respect the transparency. π
π₯ RETURN VALUE π₯
it returns an xcb_get_property_cookie_t. errors have to be handled when you call the reply function xcb_get_property_reply.
but if you'd rather handle errors in the event loop instead, use xcb_get_property_unchecked. see xcb-requests(3) for the deets.
π ERRORS π
xcb_atom_error_tβpropertyortypedo not refer to a valid atom. fake atoms get denied, sorry.xcb_value_error_tβ the specifiedlong_offsetis beyond the actual property length (e.g. the property has a length of3bytes and you are settinglong_offsetto1, resulting in a byte offset of4). yeah, that's out of bounds, bestie.xcb_window_error_tβ the specified window does not exist. it's not there. it never was. π
π EXAMPLE π
here's the whole thing, verbatim, no notes:
/*
* Prints the WM_NAME property of the window.
*
*/
void my_example(xcb_connection_t *c, xcb_window_t window) {
xcb_get_property_cookie_t cookie;
xcb_get_property_reply_t *reply;
/* These atoms are predefined in the X11 protocol. */
xcb_atom_t property = XCB_ATOM_WM_NAME;
xcb_atom_t type = XCB_ATOM_STRING;
// TODO: a reasonable long_length for WM_NAME?
cookie = xcb_get_property(c, 0, window, property, type, 0, 0);
if ((reply = xcb_get_property_reply(c, cookie, NULL))) {
int len = xcb_get_property_value_length(reply);
if (len == 0) {
printf("TODO\n");
free(reply);
return;
}
printf("WM_NAME is %.*s\n", len,
(char*)xcb_get_property_value(reply));
}
free(reply);
}
and yes, don't forget the free(reply) at the end. memory leaks are not the vibe. π
π§ SEE ALSO π§
xcb-requests(3), xcb-examples(3), xcb_intern_atom(3), xprop(1)
go read them, iykyk. β¨
π AUTHOR π
Generated from xproto.xml. Contact xcb@lists.freedesktop.org for corrections and improvements.
okay that's the whole page bestie, you ate that fr fr. this was libxcb 1.17.0, X Version 11, and you just read the xcb_get_property(3) manual page β slay, go get those properties. π
πΈπ
π¦ where this page comes from
- alpine 3.22: libxcb-doc 1.17.0-r0 Β· MIT
- alpine 3.23: libxcb-doc 1.17.0-r1 Β· MIT
- alpine 3.24: libxcb-doc 1.17.0-r2 Β· MIT
- arch rolling: libxcb 1.17.0-1 Β· X11
- centos-stream 10: libxcb-devel 1.17.0-3.el10 Β· X11
- debian trixie: libxcb-doc 1.17.0-2
- fedora 43: libxcb-devel 1.17.0-6.fc43 Β· X11
- fedora 43: libxcb-devel 1.17.0-6.fc43 Β· X11
- fedora 44: libxcb-devel 1.17.0-7.fc44 Β· X11
- fedora 44: libxcb-devel 1.17.0-7.fc44 Β· X11
- nixpkgs unstable: libxcb 1.17.0
- opensuse-leap 16.0: libxcb-devel-doc 1.17.0-160000.2.2 Β· MIT
- ubuntu questing: libxcb-doc 1.17.0-2build1
- ubuntu resolute: libxcb-doc 1.17.0-2ubuntu1
- ubuntu stonking: libxcb-doc 1.17.0-2ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms