xcb_intern_atom(3)
π« xcb_intern_atom β get an atom identifier by name π«
okay bestie, sit down, we're learning about atoms today π this is from the XCB Requests corner of the manual, and it's genuinely so useful, i promise.
β¨ SYNOPSIS β¨
first things first, you gotta pull in the header:
#include <xcb/xproto.h>
π Request function
xcb_intern_atom_cookie_t xcb_intern_atom(xcb_connection_t *conn,
uint8_t only_if_exists, uint16_t name_len, const char *name);
π Reply datastructure
typedef struct xcb_intern_atom_reply_t {
uint8_t response_type;
uint8_t pad0;
uint16_t sequence;
uint32_t length;
xcb_atom_t atom;
} xcb_intern_atom_reply_t;
π Reply function
xcb_intern_atom_reply_t *xcb_intern_atom_reply(xcb_connection_t *conn,
xcb_intern_atom_cookie_t cookie, xcb_generic_error_t **e);
πΈ REQUEST ARGUMENTS πΈ
connβ the XCB connection to X11, your lil hotline to the server, periodt.only_if_existsβ when this is set, you only get back a valid atom id if the atom already exists. no new atoms, no surprises.name_lenβ the length of thenamethat comes right after it. yes, you gotta count it yourself, iykyk.nameβ the actual name of the atom. the whole point of the operation bestie π
π¦ REPLY FIELDS π¦
response_typeβ the type of this reply, which in this case isXCB_INTERN_ATOM. this field also lives in thexcb_generic_reply_t, so you can use it to tell your replies apart from each other. so handy β¨sequenceβ the sequence number of the last request processed by the X11 server. receipts, basically.lengthβ the length of the reply, in words (and a word here is 4 bytes, no cap).atomβTODO: NOT YET DOCUMENTED.yeah. the docs said what they said π iconic of them honestly.
π DESCRIPTION π
So what does it actually do? It retrieves the identifier (xcb_atom_t TODO) for the atom with the specified name. Atoms are used in protocols like EWMH, for example to store window titles (the _NET_WM_NAME atom) as a property of a window. the way that works is genuinely so cool π«Ά
Here's the vibe on only_if_exists:
- If
only_if_existsis0, the atom will be created if it does not already exist. - If
only_if_existsis1,XCB_ATOM_NONEwill be returned if the atom does not yet exist.
β RETURN VALUE β
Returns an xcb_intern_atom_cookie_t. Errors have to be handled when calling the reply function xcb_intern_atom_reply. don't skip that part bestie, that's the whole plot π
If you'd rather handle errors in the event loop instead, use xcb_intern_atom_unchecked. See xcb-requests(3) for details. pick your fighter π
π ERRORS π
xcb_alloc_error_tβTODO: reasons?that's literally what it says. mystery error, main character energy β¨xcb_value_error_tβ a value other than0or1was specified foronly_if_exists. so like, don't do that. binary means binary π«
π EXAMPLE π
here's the whole thing in action, resolving the _NET_WM_NAME atom:
/*
* Resolves the _NET_WM_NAME atom.
*
*/
void my_example(xcb_connection_t *c) {
xcb_intern_atom_cookie_t cookie;
xcb_intern_atom_reply_t *reply;
cookie = xcb_intern_atom(c, 0, strlen("_NET_WM_NAME"), "_NET_WM_NAME");
/* ... do other work here if possible ... */
if ((reply = xcb_intern_atom_reply(c, cookie, NULL))) {
printf("The _NET_WM_NAME atom has ID %u0, reply->atom);
free(reply);
}
}
notice how you fire off the request, go do other stuff while the server thinks, and only then come back for the reply? that's the async slay, we love to see it π₯
π SEE ALSO π
xcb-requests(3), xcb-examples(3), xcb_get_atom_name(3), xlsatoms(1)
π§ AUTHOR π§
Generated from xproto.xml. Contact xcb@lists.freedesktop.org for corrections and improvements. they're literally asking for feedback, so if you spot something, tell them π«Ά
okay that's the whole page, you ate it, no crumbs left π
this lil gem comes to you from X Version 11, libxcb 1.17.0. now go intern some atoms bestie, you're gonna do amazing πΈβ¨π¦
π¦ 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