diff --git a/Makefile b/Makefile index 732d191..70c0b9c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ CC=gcc -CFLAGS=-Wall -lX11 -g -lm +PRECFLAGS=-Wall -g +POSTCFLAGS=-lX11 -lm VPATH=./src WM_OBJS= atoms.o events.o tree.o commands.o responses.o util.o window.o lookup.o foo-wm.o @@ -11,10 +12,10 @@ src/config.h: cp src/config.def.h src/config.h foo-wm: src/config.h $(WM_OBJS) - $(CC) $(CFLAGS) $(WM_OBJS) -o foo-wm + $(CC) $(PRECFLAGS) $(WM_OBJS) $(POSTCFLAGS) -o foo-wm foo-wm-c: $(CLI_OBJS) - $(CC) $(CFLAGS) $(CLI_OBJS) -o foo-wm-c + $(CC) $(PRECFLAGS) $(CLI_OBJS) $(POSTCFLAGS) -o foo-wm-c clean: rm -rf foo-wm foo-wm-c *.o diff --git a/TODO.md b/TODO.md index 66ebcc6..48cc921 100644 --- a/TODO.md +++ b/TODO.md @@ -7,7 +7,6 @@ Bugs - 'containerize' 'containerize' -- case of the missing container - brotherNode() in tree.c, node->parent = brother->parent ? * This could potentially break the old node's brothers and node parent child ptr -- XMapWindow and XRaiseWindow always called for Windows in placeNode regardless if already mapped/raised - Destroying last client doesn't focus container / set focusedNode * Tree: - Container (1) diff --git a/src/tree.c b/src/tree.c index ba8faad..30abb37 100644 --- a/src/tree.c +++ b/src/tree.c @@ -325,8 +325,38 @@ void placeNode(Node * node, int x, int y, int width, int height) { if (isClient(node)) { fprintf(stderr,"Rendering window\n"); - XMapWindow(display, node -> window); + XWindowAttributes attr; + XGetWindowAttributes(display, node -> window, &attr); + + // Make sure that the window isn't already visible before remapping it. + if (attr.map_state != IsViewable) + XMapWindow(display, node -> window); + + /* Making sure that a window isn't already raised requires some gymnastics: + * According to 'http://tronche.com/gui/x/xlib/window-information/XQueryTree.html' + * XQueryTree produces children in stacking order. Thus, the final child + * is on top. + * + * Note that I comment this out because it is probably very dumb to + * use this code - XRaiseWindow is probably fast compared to + * the XQueryTree request, the XQueryTree response, and freeing the array. + */ + + /* + Window root_window = RootWindow(display, DefaultScreen(display)); + Window root_tmp, parent_tmp; + Window *children; + int n_children; + XQueryTree(display, root, &root_tmp, &parent_tmp, &children, *n_children); + + Window top_window = children[n_children - 1]; + XFree(children); + + if (node -> window != top_window) + XRaiseWindow(display, node -> window); + */ XRaiseWindow(display, node -> window); + XMoveResizeWindow(display, node -> window, (x < 0) ? 0 : x, (y < 0) ? 0 : y, (width - (border * 2)) > 0 ? (width - border * 2) : 1,