wmutils

X windows manipulation utilities
git clone git://z3bra.org/wmutils
Log | Files | Refs | LICENSE

commit 7723d4fac234c20276627bb58d4bf09aa03f8e74
parent 0c076cbec593e4b8b14ba88521793f4ceb6141f0
Author: z3bra <willy@mailoo.org>
Date:   Tue Dec  2 19:31:34 2014

Merge branch 'master' of github.com:wmutils/core

Conflicts:
	Makefile

Diffstat:
 Makefile |  3 ++-
 wname.c  | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -19,7 +19,8 @@ SRC = \ wtf.c \ wrs.c \ chwb.c \ - ignw.c + ignw.c \ + wname.c OBJ = $(SRC:.c=.o) BIN = $(SRC:.c=) diff --git a/wname.c b/wname.c @@ -0,0 +1,63 @@ +#include <stdio.h> +#include <stdlib.h> +#include <xcb/xcb.h> +#include <err.h> + +static xcb_connection_t *conn; + +static void usage (char *); +static void cleanup (void); +static int get_title (xcb_window_t); + +static void cleanup (void) +{ + if (conn) + xcb_disconnect(conn); +} + +static void +usage (char *name) +{ + fprintf(stderr, "usage: %s <wid>", name); + exit(1); +} + +static int +get_title (xcb_window_t win) +{ + int len = 0; + xcb_get_property_cookie_t cookie; + xcb_get_property_reply_t *r; + + cookie = xcb_get_property(conn, 0, win, + XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 0L, 32L); + r = xcb_get_property_reply(conn, cookie, NULL); + + if (r) { + len = xcb_get_property_value_length(r); + printf("%.*s\n", len, (char *) xcb_get_property_value(r)); + + return 0; + } + + warnx("could not get window title"); + free(r); + return 1; +} + +int main (int argc, char **argv) +{ + int r = 0; + + if (argc < 2) + usage(argv[0]); + + atexit(cleanup); + if (xcb_connection_has_error(conn = xcb_connect(NULL, NULL))) + errx(1, "error connecting to X"); + + for (int i=1; i < argc; i++) + r += get_title(strtoul(argv[i], NULL, 16)); + + return r; +}