mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 03:35:41 +02:00
xcb: create atom if it doesn't exist
Fixes a bug where not all atoms have (yet) been created when starting f00bar as part of the WM startup (for example, with an 'exec' in i3's config).
This commit is contained in:
parent
ceb4770d7f
commit
c3930ef60a
1 changed files with 26 additions and 3 deletions
29
xcb.c
29
xcb.c
|
@ -9,6 +9,7 @@
|
|||
#include <xcb/render.h>
|
||||
|
||||
#define LOG_MODULE "xcb"
|
||||
#define LOG_ENABLE_DBG 0
|
||||
#include "log.h"
|
||||
|
||||
xcb_atom_t UTF8_STRING;
|
||||
|
@ -132,11 +133,25 @@ get_atom(xcb_connection_t *conn, const char *name)
|
|||
xcb_generic_error_t *e;
|
||||
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(
|
||||
conn,
|
||||
xcb_intern_atom(conn, 1, strlen(name), name),
|
||||
xcb_intern_atom(conn, 0, strlen(name), name),
|
||||
&e);
|
||||
assert(e == NULL);
|
||||
|
||||
if (e != NULL) {
|
||||
LOG_ERR("failed to get atom for %s", name);
|
||||
free(e);
|
||||
free(reply);
|
||||
|
||||
return (xcb_atom_t){0};
|
||||
}
|
||||
|
||||
xcb_atom_t ret = reply->atom;
|
||||
LOG_DBG("atom %s = 0x%08x", name, ret);
|
||||
|
||||
if (ret == XCB_ATOM_NONE)
|
||||
LOG_ERR("%s: no such atom", name);
|
||||
|
||||
assert(ret != XCB_ATOM_NONE);
|
||||
|
||||
free(reply);
|
||||
return ret;
|
||||
}
|
||||
|
@ -147,13 +162,21 @@ get_atom_name(xcb_connection_t *conn, xcb_atom_t atom)
|
|||
xcb_generic_error_t *e;
|
||||
xcb_get_atom_name_reply_t *reply = xcb_get_atom_name_reply(
|
||||
conn, xcb_get_atom_name(conn, atom), &e);
|
||||
assert(e == NULL);
|
||||
|
||||
if (e != NULL) {
|
||||
LOG_ERR("failed to get atom name");
|
||||
free(e);
|
||||
free(reply);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int len = xcb_get_atom_name_name_length(reply);
|
||||
char *name = malloc(len + 1);
|
||||
memcpy(name, xcb_get_atom_name_name(reply), len);
|
||||
name[len] = '\0';
|
||||
|
||||
LOG_DBG("atom name: %s", name);
|
||||
|
||||
free(reply);
|
||||
return name;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue