tnew tool: mapw - wmutils - X windows manipulation utilities
 (HTM) git clone git://z3bra.org/wmutils
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit d2bcf543e73fd93dea485f9ed93355a2ee7c3395
 (DIR) parent 4932423d13b593ded30807379a0f5972de727e59
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Thu, 27 Nov 2014 23:03:44 +0100
       
       new tool: mapw
       
       Diffstat:
         A mapw.c                              |     104 +++++++++++++++++++++++++++++++
       
       1 file changed, 104 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/mapw.c b/mapw.c
       t@@ -0,0 +1,104 @@
       +#include <stdio.h>
       +#include <stdlib.h>
       +#include <err.h>
       +#include <xcb/xcb.h>
       +
       +#include "arg.h"
       +
       +enum {
       +        MAP     = 1 << 0,
       +        UNMAP   = 1 << 1,
       +        TOGGLE  = 1 << 2
       +};
       +
       +char *argv0;
       +static xcb_connection_t *conn;
       +
       +static void usage(void);
       +static void xcbinit(void);
       +static void cleanup(void);
       +static int ismapped(xcb_window_t w);
       +
       +static void
       +usage(void)
       +{
       +        fprintf(stderr, "usage: %s [-hmut] <wid> [wid..]\n", argv0);
       +        exit(1);
       +}
       +
       +static void
       +xcbinit(void)
       +{
       +        conn = xcb_connect(NULL, NULL);
       +        if (xcb_connection_has_error(conn))
       +                errx(1, "xcb_connect");
       +}
       +
       +static void
       +cleanup(void)
       +{
       +        if (conn != NULL)
       +                xcb_disconnect(conn);
       +}
       +
       +static int
       +ismapped(xcb_window_t w)
       +{
       +        int ms;
       +        xcb_get_window_attributes_cookie_t c;
       +        xcb_get_window_attributes_reply_t  *r;
       +
       +        c = xcb_get_window_attributes(conn, w);
       +        r = xcb_get_window_attributes_reply(conn, c, NULL);
       +
       +        if (r == NULL)
       +                return 0;
       +
       +        ms = r->map_state;
       +
       +        free(r);
       +        return ms == XCB_MAP_STATE_VIEWABLE;
       +}
       +
       +int
       +main(int argc, char **argv)
       +{
       +        int i, mapflag = MAP;
       +        xcb_window_t w = 0;
       +
       +        ARGBEGIN {
       +                case 'm': mapflag = MAP;    break;
       +                case 'u': mapflag = UNMAP;  break;
       +                case 't': mapflag = TOGGLE; break;
       +                default : usage();
       +        } ARGEND;
       +
       +        if (argc < 1)
       +                usage();
       +
       +        atexit(cleanup);
       +        xcbinit();
       +
       +        for (i=0; i<argc; i++) {
       +                w = strtoul(argv[i], NULL, 16);
       +
       +                switch (mapflag) {
       +                case MAP:
       +                        xcb_map_window(conn, w);
       +                        break;
       +                case UNMAP:
       +                        xcb_unmap_window(conn, w);
       +                        break;
       +                case TOGGLE:
       +                        if (ismapped(w)) {
       +                                xcb_unmap_window(conn, w);
       +                        } else {
       +                                xcb_map_window(conn, w);
       +                        }
       +                        break;
       +                }
       +        }
       +        xcb_flush(conn);
       +
       +        return 0;
       +}