#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
******************************************************************************/
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;
}
/* 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);
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);
}
/* register event handlers */
X.eventfns[MapRequest] = xmaprequest;
+ X.eventfns[DestroyNotify] = xdestroy;
X.eventfns[ConfigureNotify] = xconfigure;
X.eventfns[ClientMessage] = xclientmsg;
X.eventfns[Expose] = xexpose;