diff options
| author | allusive-dev <[email protected]> | 2023-09-19 17:47:33 +1000 |
|---|---|---|
| committer | allusive-dev <[email protected]> | 2023-09-19 17:47:33 +1000 |
| commit | a93aba600b1c5d019b680b9f4ff3fa85d5d43a60 (patch) | |
| tree | 77f8152222655657472a70e0bfa413a0495dd555 /src/atom.c | |
| parent | reset (diff) | |
| download | compfy-a93aba600b1c5d019b680b9f4ff3fa85d5d43a60.tar.xz compfy-a93aba600b1c5d019b680b9f4ff3fa85d5d43a60.zip | |
Fixed broken files/code and other errors
Diffstat (limited to 'src/atom.c')
| -rw-r--r-- | src/atom.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/atom.c b/src/atom.c new file mode 100644 index 0000000..0272dc8 --- /dev/null +++ b/src/atom.c @@ -0,0 +1,37 @@ +#include <string.h> +#include <xcb/xcb.h> + +#include "atom.h" +#include "common.h" +#include "utils.h" +#include "log.h" + +static inline void *atom_getter(void *ud, const char *atom_name, int *err) { + xcb_connection_t *c = ud; + xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply( + c, xcb_intern_atom(c, 0, to_u16_checked(strlen(atom_name)), atom_name), NULL); + + xcb_atom_t atom = XCB_NONE; + if (reply) { + log_debug("Atom %s is %d", atom_name, reply->atom); + atom = reply->atom; + free(reply); + } else { + log_error("Failed to intern atoms"); + *err = 1; + } + return (void *)(intptr_t)atom; +} + +/** + * Create a new atom structure and fetch all predefined atoms + */ +struct atom *init_atoms(xcb_connection_t *c) { + auto atoms = ccalloc(1, struct atom); + atoms->c = new_cache((void *)c, atom_getter, NULL); +#define ATOM_GET(x) atoms->a##x = (xcb_atom_t)(intptr_t)cache_get(atoms->c, #x, NULL) + LIST_APPLY(ATOM_GET, SEP_COLON, ATOM_LIST1); + LIST_APPLY(ATOM_GET, SEP_COLON, ATOM_LIST2); +#undef ATOM_GET + return atoms; +} |