wmutils

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

commit 72795004667355453186c9bbc2ffe90cc9808a19
parent 34d28705f0c52a00eec1c01757c4526dc13d433b
Author: z3bra <willy@mailoo.org>
Date:   Mon Dec  8 23:47:03 2014

refactoring: added util.c and util.h

Diffstat:
 Makefile |  8 +++---
 util.c   | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 util.h   | 13 ++++++++++-
 3 files changed, 98 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile @@ -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 \ @@ -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 $<" @@ -50,4 +50,4 @@ uninstall: done clean : - rm -f $(OBJ) $(BIN) + rm -f $(OBJ) $(BIN) util.o diff --git a/util.c b/util.c @@ -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; +} diff --git a/util.h b/util.h @@ -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