wmutils

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

commit 7ef7746061a08ca2a9f74d2f855cd50375fc2773
parent 6a73d08cd09a1b59c89be0727630f6c20e162da0
Author: z3bra <willy@mailoo.org>
Date:   Mon Dec  1 21:15:53 2014

wattr, mapw: moved mapping check to wattr (m attribute)

Diffstat:
 mapw.c  |  4 +---
 wattr.c | 25 ++++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/mapw.c b/mapw.c @@ -73,7 +73,7 @@ main(int argc, char **argv) default : usage(); } ARGEND; - if (argc < 1) + if (argc < 1 || mapflag == 0) usage(); atexit(cleanup); @@ -96,8 +96,6 @@ main(int argc, char **argv) xcb_map_window(conn, w); } break; - default: - return ismapped(w) ? 0 : 1; } } xcb_flush(conn); diff --git a/wattr.c b/wattr.c @@ -11,6 +11,8 @@ static void usage(void); static void xcbinit(void); static void cleanup(void); static int getattribute(xcb_window_t, int); +static int mapped(xcb_window_t); +static int exists(xcb_window_t); enum { ATTR_W = 1 << 0, @@ -18,13 +20,14 @@ enum { ATTR_X = 1 << 2, ATTR_Y = 1 << 3, ATTR_B = 1 << 4, + ATTR_M = 1 << 5, ATTR_MAX }; static void usage(void) { - fprintf(stderr, "usage: %s [-h] [bwhxy] <wid>\n", argv0); + fprintf(stderr, "usage: %s [-h] [bmwhxy] <wid>\n", argv0); exit(1); } @@ -60,6 +63,25 @@ exists(xcb_window_t w) } static int +mapped(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; +} + +static int getattribute(xcb_window_t w, int attr) { xcb_get_geometry_cookie_t c; @@ -106,6 +128,7 @@ main(int argc, char **argv) case 'x': printf("%d", getattribute(w, ATTR_X)); break; case 'y': printf("%d", getattribute(w, ATTR_Y)); break; case 'w': printf("%d", getattribute(w, ATTR_W)); break; + case 'm': mapped(w) ? exit(0) : exit(1); default : exists(w) ? exit(0) : exit(1); }