twattr, mapw: moved mapping check to wattr (m attribute) - wmutils - X windows manipulation utilities
 (HTM) git clone git://z3bra.org/wmutils
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 7ef7746061a08ca2a9f74d2f855cd50375fc2773
 (DIR) parent 6a73d08cd09a1b59c89be0727630f6c20e162da0
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Mon,  1 Dec 2014 21:15:53 +0100
       
       wattr, mapw: moved mapping check to wattr (m attribute)
       
       Diffstat:
         M mapw.c                              |       4 +---
         M wattr.c                             |      25 ++++++++++++++++++++++++-
       
       2 files changed, 25 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/mapw.c b/mapw.c
       t@@ -73,7 +73,7 @@ main(int argc, char **argv)
                        default : usage();
                } ARGEND;
        
       -        if (argc < 1)
       +        if (argc < 1 || mapflag == 0)
                        usage();
        
                atexit(cleanup);
       t@@ -96,8 +96,6 @@ main(int argc, char **argv)
                                        xcb_map_window(conn, w);
                                }
                                break;
       -                default:
       -                        return ismapped(w) ? 0 : 1;
                        }
                }
                xcb_flush(conn);
 (DIR) diff --git a/wattr.c b/wattr.c
       t@@ -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,
       t@@ -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);
        }
        
       t@@ -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;
       t@@ -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);
                        }