rem: XDrawRectangle(dpy, root, gc, x, y, w, h);
add: if(nx > xp) w = nx - xp; else if(nx < xp) { w = xp - nx; xp = nx; } else w = 0;  if(ny > yp) h = ny - yp; else if(ny < yp) { h = yp - ny; yp = ny; } else h = 0;  XDrawRectangle(dpy, root, gc, xp, yp, w, h);
context: wSelectWindows(WScreen *scr, XEvent *ev){    XEvent event;    Window root = scr->root_win;    GC gc = scr->frame_gc;    int xp = ev->xbutton.x_root;    int yp = ev->xbutton.y_root;    int w = 0, h = 0;    int x = xp, y = yp;    #ifdef DEBUG    puts("Selecting windows");#endif    if (XGrabPointer(dpy, scr->root_win, False, ButtonMotionMask		     | ButtonReleaseMask | ButtonPressMask, GrabModeAsync,		     GrabModeAsync, None, wCursor[WCUR_DEFAULT],		     CurrentTime) != Success) {	return;    }    XGrabServer(dpy);        wUnselectWindows(scr);        XDrawRectangle(dpy, root, gc, xp, yp, w, h);    while (1) {	WMMaskEvent(dpy, ButtonReleaseMask | PointerMotionMask		    | ButtonPressMask, &event);		switch (event.type) {	 case MotionNotify:	    XDrawRectangle(dpy, root, gc, x, y, w, h);	    x = event.xmotion.x_root;	    if (x < xp) {		w = xp - x;	    } else {		w = x - xp;		x = xp;	    }	    y = event.xmotion.y_root;	    if (y < yp) {		h = yp - y;	    } else {		h = y - yp;		y = yp;	    }	    XDrawRectangle(dpy, root, gc, x, y, w, h);	    break;	 case ButtonPress:	    break;	 case ButtonRelease:	    if (event.xbutton.button != ev->xbutton.button)		break;	    XDrawRectangle(dpy, root, gc, x, y, w, h);	    XUngrabServer(dpy);	    XUngrabPointer(dpy, CurrentTime);	    selectWindowsInside(scr, x, y, x + w, y + h);	   #ifdef KWM_HINTS	    wKWMSelectRootRegion(scr, x, y, w, h, 				 event.xbutton.state & ControlMask);#endif /* KWM_HINTS */#ifdef DEBUG	    puts("End window selection");#endif	    return;	    	 default:	    WMHandleEvent(&event);	    break;	}    }}