tMerge branch 'master' of github.com:wmutils/core - wmutils - X windows manipulation utilities
 (HTM) git clone git://z3bra.org/wmutils
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 7723d4fac234c20276627bb58d4bf09aa03f8e74
 (DIR) parent 0c076cbec593e4b8b14ba88521793f4ceb6141f0
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Tue,  2 Dec 2014 19:31:34 +0100
       
       Merge branch 'master' of github.com:wmutils/core
       
       Conflicts:
               Makefile
       
       Diffstat:
         M Makefile                            |       3 ++-
         A wname.c                             |      63 +++++++++++++++++++++++++++++++
       
       2 files changed, 65 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/Makefile b/Makefile
       t@@ -19,7 +19,8 @@ SRC =           \
                wtf.c   \
                wrs.c   \
                chwb.c  \
       -        ignw.c
       +        ignw.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;
       +}