tmapw: util.c refactoring - wmutils - X windows manipulation utilities
 (HTM) git clone git://z3bra.org/wmutils
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit e9e56d9de943d950f87987da9896386ea051d36d
 (DIR) parent acb1b1d9c78a46bb57f9ccb2699fdcabbcd00a7e
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Tue,  9 Dec 2014 12:31:16 +0100
       
       mapw: util.c refactoring
       
       Diffstat:
         M mapw.c                              |      43 +++----------------------------
       
       1 file changed, 3 insertions(+), 40 deletions(-)
       ---
 (DIR) diff --git a/mapw.c b/mapw.c
       t@@ -4,6 +4,7 @@
        #include <xcb/xcb.h>
        
        #include "arg.h"
       +#include "util.h"
        
        enum {
                MAP     = 1 << 0,
       t@@ -15,9 +16,6 @@ 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)
       t@@ -26,40 +24,6 @@ usage(void)
                exit(1);
        }
        
       -static void
       -xcbinit(void)
       -{
       -        conn = xcb_connect(NULL, NULL);
       -        if (xcb_connection_has_error(conn))
       -                errx(1, "unable to connect to the X server");
       -}
       -
       -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)
        {
       t@@ -76,8 +40,7 @@ main(int argc, char **argv)
                if (argc < 1 || mapflag == 0)
                        usage();
        
       -        atexit(cleanup);
       -        xcbinit();
       +        init_xcb(&conn);
        
                while (*argv) {
                        w = strtoul(*argv++, NULL, 16);
       t@@ -90,7 +53,7 @@ main(int argc, char **argv)
                                xcb_unmap_window(conn, w);
                                break;
                        case TOGGLE:
       -                        if (ismapped(w)) {
       +                        if (mapped(conn, w)) {
                                        xcb_unmap_window(conn, w);
                                } else {
                                        xcb_map_window(conn, w);