From: Michael D. Lowis Date: Sun, 12 May 2019 03:17:25 +0000 (-0400) Subject: added stupid simple logic to tile windows X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=acd79b95a80bd044b055b5bdc264efa761efc936;p=projs%2Ftide.git added stupid simple logic to tile windows --- diff --git a/src/tframe.c b/src/tframe.c index daa0aae..65e9e3c 100644 --- a/src/tframe.c +++ b/src/tframe.c @@ -10,13 +10,19 @@ #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;