[PATCH 4/4] A small test app for ewmh_get_wm_icon_*

Uli Schlachter psychon at znc.in
Fri Mar 11 02:27:44 PST 2011


This is not intended to be merged anywhere! I just wanted to make sure this
stuff works.

NOT-Signed-off-by: Uli Schlachter <psychon at znc.in>
---
 ewmh/Makefile.am |    4 +++
 ewmh/foo.c       |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)
 create mode 100644 ewmh/foo.c

diff --git a/ewmh/Makefile.am b/ewmh/Makefile.am
index 42b3a40..78fe295 100644
--- a/ewmh/Makefile.am
+++ b/ewmh/Makefile.am
@@ -23,3 +23,7 @@ ewmh.c: ewmh.c.m4 atomlist.m4
 
 xcb_ewmh.h: xcb_ewmh.h.m4 atomlist.m4
 	$(M4) -I$(srcdir) $< >$@
+
+bin_PROGRAMS = foo
+foo_LDADD = libxcb-ewmh.la -lxcb
+foo_SOURCES = foo.c
diff --git a/ewmh/foo.c b/ewmh/foo.c
new file mode 100644
index 0000000..afa4f51
--- /dev/null
+++ b/ewmh/foo.c
@@ -0,0 +1,57 @@
+#include <xcb_ewmh.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+	xcb_connection_t *c;
+	xcb_window_t w;
+	xcb_intern_atom_cookie_t *atom_cookie;
+	xcb_get_property_cookie_t prop_cookie;
+	xcb_ewmh_connection_t ewmh;
+	xcb_ewmh_get_wm_icon_reply_t wm_icon;
+	xcb_ewmh_wm_icon_iterator_t iter;
+
+	if (argc < 2) {
+		printf("Usage: %s <win-id>\n", argv[0]);
+		return 1;
+	}
+
+	w = strtol(argv[1], NULL, 0);
+	if (w == XCB_NONE) {
+		fprintf(stderr, "Invalid argument!\n");
+		return 1;
+	}
+	c = xcb_connect(NULL, NULL);
+	atom_cookie = xcb_ewmh_init_atoms(c, &ewmh);
+	if (atom_cookie == NULL) {
+		fprintf(stderr, "Can not request atoms\n");
+		xcb_disconnect(c);
+		return 1;
+	}
+	if (!xcb_ewmh_init_atoms_replies(&ewmh, atom_cookie, NULL)) {
+		fprintf(stderr, "Can not get atom replies\n");
+		xcb_disconnect(c);
+		return 1;
+	}
+	prop_cookie = xcb_ewmh_get_wm_icon(&ewmh, w);
+	if (!xcb_ewmh_get_wm_icon_reply(&ewmh, prop_cookie, &wm_icon, NULL)) {
+		fprintf(stderr, "Can not get icon (window got no icon?)\n");
+		xcb_ewmh_connection_wipe(&ewmh);
+		xcb_disconnect(c);
+		return 1;
+	}
+
+	iter = xcb_ewmh_get_wm_icon_iterator(&wm_icon);
+	printf("There are %u icons\n", xcb_ewmh_get_wm_icon_length(&wm_icon));
+
+	while (iter.rem) {
+		printf("Icon %2d: Width %u, Height %u, Data %p\n",
+				iter.index, iter.width, iter.height, iter.data);
+		xcb_ewmh_get_wm_icon_next(&iter);
+	}
+	xcb_ewmh_get_wm_icon_reply_wipe(&wm_icon);
+	xcb_ewmh_connection_wipe(&ewmh);
+	xcb_disconnect(c);
+	return 0;
+}
-- 
1.7.4.1


--------------050606080800060709000007--


More information about the Xcb mailing list