From: Michael D. Lowis Date: Sun, 15 Mar 2020 02:57:33 +0000 (-0400) Subject: added retrieval of size hints and minor refactoring X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=cea4a49bd3b270d15a82ce549bbb90197e28d475;p=proto%2Fanvil.git added retrieval of size hints and minor refactoring --- diff --git a/anvil.h b/anvil.h index 7adc09a..f5a2b92 100644 --- a/anvil.h +++ b/anvil.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,8 @@ typedef struct Client { char* name; Window frame, win; int flags, x, y, w, h; + long hint_flags; + XSizeHints hints; } Client; enum { diff --git a/client.c b/client.c index 89dc016..f518b38 100644 --- a/client.c +++ b/client.c @@ -29,38 +29,15 @@ Client* client_add(Window win, XWindowAttributes* attr) c->w = attr->width; c->h = attr->height; mons_addclient(c); - - /* get window name */ client_readprops(c); - /* get normal hints ? */ - /* get transient_for property ? */ - /* set client flags appropriately */ - - - /* get registered protocols */ - Atom* protos; - int nprotos; - if (XGetWMProtocols(X.disp, c->win, &protos, &nprotos) != 0) - { - for (int i = 0; i < nprotos; i++) - { - if (protos[i] == atom("WM_DELETE_WINDOW")) - { - c->flags |= F_WM_DELETE; - } - } - xfree(protos); - } - - /* Reparent the window if applicable */ c->frame = XCreateSimpleWindow(X.disp, X.root, c->x - BORDER_WIDTH, c->y - TITLE_HEIGHT - BORDER_WIDTH, c->w + (2 * BORDER_WIDTH), c->h + TITLE_HEIGHT + 2*BORDER_WIDTH, - 1, X.black, X.white); + 1, X.black, X.gray); XSelectInput(X.disp, c->frame, ExposureMask | EnterWindowMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | @@ -74,12 +51,9 @@ Client* client_add(Window win, XWindowAttributes* attr) /* Map the window and draw the frame */ XAddToSaveSet(X.disp, c->win); - XMapWindow(X.disp, c->frame); - XMapWindow(X.disp, c->win); + client_show(c, 1); client_draw(c); - /* Set focus and state? */ - return c; } @@ -175,25 +149,28 @@ void client_focus(Client* c) void client_show(Client* c, int show) { - if (show) - { - XMapWindow(X.disp, c->frame); - XMapWindow(X.disp, c->win); - } - else - { - XUnmapWindow(X.disp, c->frame); - XUnmapWindow(X.disp, c->win); - } + int (*mapfn)(Display*,Window) = (show ? XMapWindow : XUnmapWindow); + mapfn(X.disp, c->frame); + mapfn(X.disp, c->win); } void client_readprops(Client* c) { - Atom actual_type; - int format; + Atom *protos = NULL, actual_type; + int format, nprotos = 0; unsigned long n, extra; xfree(c->name); c->name = NULL; XGetWindowProperty( X.disp, c->win, XA_WM_NAME, 0L, 100L, False, AnyPropertyType, &actual_type, &format, &n, &extra, (unsigned char **)&c->name); + XGetWMNormalHints(X.disp, c->win, &(c->hints), &(c->hint_flags)); + XGetWMProtocols(X.disp, c->win, &protos, &nprotos); + for (int i = 0; i < nprotos; i++) + { + if (protos[i] == atom("WM_DELETE_WINDOW")) + { + c->flags |= F_WM_DELETE; + } + } + xfree(protos); }