]> git.mdlowis.com Git - proto/anvil.git/commitdiff
added retrieval of size hints and minor refactoring
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 15 Mar 2020 02:57:33 +0000 (22:57 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 15 Mar 2020 02:57:33 +0000 (22:57 -0400)
anvil.h
client.c

diff --git a/anvil.h b/anvil.h
index 7adc09a838d0c053ae53480206f3ee424cbbaa54..f5a2b92f76b3eb3d44e164b66824cbf450cee96f 100644 (file)
--- a/anvil.h
+++ b/anvil.h
@@ -5,6 +5,7 @@
 #include <X11/Xatom.h>
 #include <X11/cursorfont.h>
 #include <X11/Xproto.h>
+#include <X11/Xutil.h>
 #include <X11/extensions/Xinerama.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -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 {
index 89dc016dbbe309620413846b4e2d83665706ba76..f518b380e6260f116f0a1df4f421fc82f7e674d1 100644 (file)
--- 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);
 }