wmutils

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

commit d2bcf543e73fd93dea485f9ed93355a2ee7c3395
parent 4932423d13b593ded30807379a0f5972de727e59
Author: z3bra <willy@mailoo.org>
Date:   Thu Nov 27 23:03:44 2014

new tool: mapw

Diffstat:
 mapw.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 104 insertions(+), 0 deletions(-)

diff --git a/mapw.c b/mapw.c @@ -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; +}