]> git.mdlowis.com Git - projs/tide.git/commitdiff
added stupid simple logic to tile windows
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 12 May 2019 03:17:25 +0000 (23:17 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 12 May 2019 03:17:25 +0000 (23:17 -0400)
src/tframe.c

index daa0aaecc38de7aeaa2bb66b3e812c4bfc5da956..65e9e3c020110a1610093f7dbcf562267a76418b 100644 (file)
 #define INCLUDE_DEFS
 #include "config.h"
 
+typedef struct child {
+    struct child* next;
+    Window wid;
+} Child_T;
+
 static View Tags;
 static int Divider;
 static int FontSel;
-Window Child = 0;
 int retile = 0;
 static KeyBinding Bindings[41];
 
+size_t NChildren = 0;
+Child_T* Children = NULL;
 
 /* X11 Font Code
  ******************************************************************************/
@@ -41,7 +47,30 @@ size_t glyph_width(View* view, int c) {
 static void xmaprequest(XConf* x, XEvent* e) {
     (void)x;
     XMapWindow(e->xmaprequest.display, e->xmaprequest.window);
-    Child = e->xmaprequest.window;
+    Child_T* child = calloc(1, sizeof(Child_T));
+    child->wid = e->xmaprequest.window;
+    child->next = Children;
+    Children = child;
+    NChildren++;
+    retile = 1;
+}
+
+static Child_T* win_delete(Child_T* child, Window id) {
+    if (!child) return NULL;
+    if (child->wid == id) {
+        Child_T* next = child->next;
+        free(child);
+        return next;
+    } else {
+        child->next = win_delete(child->next, id);
+        return child;
+    }
+}
+
+static void xdestroy(XConf* x, XEvent* e) {
+    (void)x;
+    NChildren--;
+    Children = win_delete(Children, e->xdestroywindow.window);
     retile = 1;
 }
 
@@ -132,6 +161,19 @@ static void xbtnmotion(XConf* x, XEvent* e) {
 /* X11 Drawing Code
  ******************************************************************************/
 
+static void retile_children(XConf* x) {
+    size_t width = x->width / NChildren;
+    size_t extra = x->width % NChildren;
+    size_t offset = width+extra;
+    Child_T* child = Children;
+    XMoveResizeWindow(x->display, child->wid, 0, Divider+2, width+extra, x->height - Divider - 2);
+    for (child = child->next; child; child = child->next) {
+        XMoveResizeWindow(x->display, child->wid, offset, Divider+2, width, x->height - Divider - 2);
+        offset += width;
+    }
+    retile = 0;
+}
+
 static void xredraw(XConf* x) {
     /* determine the size of the regions */
     size_t maxtagrows = ((x->height/4) / x->font->height);
@@ -145,9 +187,8 @@ static void xredraw(XConf* x) {
     Divider = draw_hrule(x, &csr);
     draw_rect(x, EditBg, 0, Divider+2, csr.w, csr.h);
     XCopyArea(x->display, x->pixmap, x->self, x->gc, 0, 0, x->width, x->height, 0, 0);
-    if ((retile || prev_div != Divider) && Child) {
-        XMoveResizeWindow(x->display, Child, 0, Divider+2, x->width, x->height - Divider - 2);
-        retile = 0;
+    if ((retile || prev_div != Divider) && NChildren) {
+        retile_children(x);
     }
     XFlush(x->display);
 }
@@ -189,6 +230,7 @@ void win_init(void) {
 
     /* register event handlers */
     X.eventfns[MapRequest] = xmaprequest;
+    X.eventfns[DestroyNotify] = xdestroy;
     X.eventfns[ConfigureNotify] = xconfigure;
     X.eventfns[ClientMessage] = xclientmsg;
     X.eventfns[Expose] = xexpose;