tnew tool: wname - wmutils - X windows manipulation utilities
 (HTM) git clone git://z3bra.org/wmutils
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 26f9aa5f58e72be67c56b9dcc1f619f6c4dd1cad
 (DIR) parent 7362053d6865989c655e2089b88986d4462d5498
 (HTM) Author: dcat <dcat@iotek.org>
       Date:   Tue,  2 Dec 2014 19:23:32 +0100
       
       new tool: wname
       
       Diffstat:
         M Makefile                            |       3 ++-
         A wname.c                             |      63 +++++++++++++++++++++++++++++++
       
       2 files changed, 65 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/Makefile b/Makefile
       t@@ -18,7 +18,8 @@ SRC =           \
                chwso.c \
                wtf.c   \
                wrs.c   \
       -        chwb.c
       +        chwb.c  \
       +        wname.c
        
        OBJ = $(SRC:.c=.o)
        BIN = $(SRC:.c=)
 (DIR) diff --git a/wname.c b/wname.c
       t@@ -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;
       +}