twm_get_atom_name(): retrieve the name of an atom - libwm - X windows manipulation library
(HTM) git clone git://z3bra.org/libwm
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 9d0180e7638d3ed2aee875484219b43490f9cc36
(DIR) parent ad7ca51e05973a6ab131a102e5a813a09ecee585
(HTM) Author: Willy Goiffon <dev@z3bra.org>
Date: Mon, 8 Jun 2020 16:04:35 +0200
wm_get_atom_name(): retrieve the name of an atom
Diffstat:
M README.md | 3 ++-
M libwm.c | 31 +++++++++++++++++++++++++++++++
M wm.h | 6 ++++++
3 files changed, 39 insertions(+), 1 deletion(-)
---
(DIR) diff --git a/README.md b/README.md
t@@ -29,7 +29,8 @@ Here is the list of all functions provided by `libwm`:
wm_is_mapped(wid);
wm_add_atom(name, len);
wm_set_atom(wid, atom, type, len, data);
- wm_get_atom_string(wid, atom, &value);
+ wm_get_atom(wid, atom, type, &len);
+ wm_get_atom_name(wid, atom, &len);
wm_get_screen();
wm_get_windows(wid, &list);
wm_get_focus();
(DIR) diff --git a/libwm.c b/libwm.c
t@@ -239,6 +239,37 @@ wm_get_atom(xcb_window_t wid, xcb_atom_t atom, xcb_atom_t type, size_t *len)
return d;
}
+char *
+wm_get_atom_name(xcb_atom_t atom, size_t *len)
+{
+ size_t n;
+ char *name;
+ xcb_get_atom_name_cookie_t c;
+ xcb_get_atom_name_reply_t *r;
+
+ c = xcb_get_atom_name(conn, atom);
+ r = xcb_get_atom_name_reply(conn, c, NULL);
+ if (!r)
+ return NULL;
+
+ n = xcb_get_atom_name_name_length(r) + 1;
+ name = malloc(xcb_get_atom_name_name_length(r) + 1);
+ if (!name) {
+ free(r);
+ return NULL;
+ }
+
+ if (len)
+ *len = n;
+
+ memset(name, 0, xcb_get_atom_name_name_length(r) + 1);
+ strncpy(name, xcb_get_atom_name_name(r), xcb_get_atom_name_name_length(r));
+ free(r);
+
+ return name;
+}
+
+
int
wm_get_cursor(int mode, uint32_t wid, int *x, int *y)
{
(DIR) diff --git a/wm.h b/wm.h
t@@ -108,6 +108,12 @@ int wm_set_atom(xcb_window_t wid, xcb_atom_t atom, xcb_atom_t type, size_t len,
void *wm_get_atom(xcb_window_t wid, xcb_atom_t atom, xcb_atom_t type, size_t *len);
/*
+ * Retrieve the name of the given atom. The name length is set in the
+ * `len` pointer if specified
+ */
+char *wm_get_atom_name(xcb_atom_t atom, size_t *len);
+
+/*
* Get the first screen, and set the `scrn` global variable accordingly.
*/
int wm_get_screen();