wmutils

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

commit e9e56d9de943d950f87987da9896386ea051d36d
parent acb1b1d9c78a46bb57f9ccb2699fdcabbcd00a7e
Author: z3bra <willy@mailoo.org>
Date:   Tue Dec  9 12:31:16 2014

mapw: util.c refactoring

Diffstat:
 mapw.c | 43 +++----------------------------------------
 1 file changed, 3 insertions(+), 40 deletions(-)

diff --git a/mapw.c b/mapw.c @@ -4,6 +4,7 @@ #include <xcb/xcb.h> #include "arg.h" +#include "util.h" enum { MAP = 1 << 0, @@ -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) @@ -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) { @@ -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); @@ -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);