trefactoring: added util.c and util.h - wmutils - X windows manipulation utilities
 (HTM) git clone git://z3bra.org/wmutils
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 72795004667355453186c9bbc2ffe90cc9808a19
 (DIR) parent 34d28705f0c52a00eec1c01757c4526dc13d433b
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Mon,  8 Dec 2014 23:47:03 +0100
       
       refactoring: added util.c and util.h
       
       Diffstat:
         M Makefile                            |       8 ++++----
         A util.c                              |      81 ++++++++++++++++++++++++++++++
         A util.h                              |      13 +++++++++++++
       
       3 files changed, 98 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/Makefile b/Makefile
       t@@ -6,7 +6,7 @@ LD      := $(CC)
        CFLAGS  += -std=c99 -pedantic -Wall -Os
        LDFLAGS += -lxcb
        
       -HDR = arg.h
       +HDR = arg.h util.h
        SRC =           \
                pfw.c   \
                lsw.c   \
       t@@ -29,11 +29,11 @@ BIN = $(SRC:.c=)
        
        all: $(BIN)
        
       -$(OBJ): $(HDR)
       +$(OBJ): $(HDR) util.o
        
        .o:
                @echo "LD $@"
       -        @$(LD) $< -o $@ $(LDFLAGS)
       +        @$(LD) $< -o $@ $(LDFLAGS) util.o
        
        .c.o:
                @echo "CC $<"
       t@@ -50,4 +50,4 @@ uninstall:
                done
        
        clean :
       -        rm -f $(OBJ) $(BIN)
       +        rm -f $(OBJ) $(BIN) util.o
 (DIR) diff --git a/util.c b/util.c
       t@@ -0,0 +1,81 @@
       +#include <err.h>
       +#include <stdlib.h>
       +#include <xcb/xcb.h>
       +
       +#include "util.h"
       +
       +void
       +init_xcb(xcb_connection_t **con)
       +{
       +        *con = xcb_connect(NULL, NULL);
       +        if (xcb_connection_has_error(*con))
       +                errx(1, "unable connect to the X server");
       +}
       +
       +void
       +kill_xcb(xcb_connection_t **con)
       +{
       +        if (*con)
       +                xcb_disconnect(*con);
       +}
       +
       +void
       +get_screen(xcb_connection_t *con, xcb_screen_t **scr)
       +{
       +        *scr = xcb_setup_roots_iterator(xcb_get_setup(con)).data;
       +        if (*scr == NULL)
       +                errx(1, "unable to retrieve screen informations");
       +}
       +
       +int
       +exists(xcb_connection_t *con, xcb_window_t w)
       +{
       +        xcb_get_window_attributes_cookie_t c;
       +        xcb_get_window_attributes_reply_t  *r;
       +
       +        c = xcb_get_window_attributes(con, w);
       +        r = xcb_get_window_attributes_reply(con, c, NULL);
       +
       +        if (r == NULL)
       +                return 0;
       +
       +        return 1;
       +}
       +
       +int
       +mapped(xcb_connection_t *con, 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(con, w);
       +        r = xcb_get_window_attributes_reply(con, c, NULL);
       +
       +        if (r == NULL)
       +                return 0;
       +
       +        ms = r->map_state;
       +
       +        free(r);
       +        return ms == XCB_MAP_STATE_VIEWABLE;
       +}
       +
       +int
       +ignore(xcb_connection_t *con, xcb_window_t w)
       +{
       +        int or;
       +        xcb_get_window_attributes_cookie_t c;
       +        xcb_get_window_attributes_reply_t  *r;
       +
       +        c = xcb_get_window_attributes(con, w);
       +        r = xcb_get_window_attributes_reply(con, c, NULL);
       +
       +        if (r == NULL)
       +                return 0;
       +
       +        or = r->override_redirect;
       +
       +        free(r);
       +        return or;
       +}
 (DIR) diff --git a/util.h b/util.h
       t@@ -0,0 +1,13 @@
       +#ifndef UTIL_H__
       +#define UTIL_H__
       +
       +void init_xcb(xcb_connection_t **);
       +void kill_xcb(xcb_connection_t **);
       +
       +void get_screen(xcb_connection_t *, xcb_screen_t **);
       +
       +int exists(xcb_connection_t *, xcb_window_t);
       +int mapped(xcb_connection_t *, xcb_window_t);
       +int ignore(xcb_connection_t *, xcb_window_t);
       +
       +#endif