rem: if(update_selection) {  if(nx != ox) {     if(yp != oy && ox != xp) { segments[nsegs].x1 = ox; segments[nsegs].y1 = yp; segments[nsegs].x2 = ox; segments[nsegs].y2 = oy; nsegs++; }     if(yp != ny && nx != xp) { segments[nsegs].x1 = nx; segments[nsegs].y1 = yp; segments[nsegs].x2 = nx; segments[nsegs].y2 = ny; nsegs++; }     if(ny == oy && nx != xp) { segments[nsegs].x1 = ox; segments[nsegs].y1 = ny; segments[nsegs].x2 = nx; segments[nsegs].y2 = ny; nsegs++; }   segments[nsegs].x1 = nx; segments[nsegs].y1 = yp; segments[nsegs].x2 = ox; segments[nsegs].y2 = yp; nsegs++; }      if(ny != oy) {    if(xp != ox && oy != yp) { segments[nsegs].x1 = ox; segments[nsegs].y1 = oy; segments[nsegs].x2 = xp; segments[nsegs].y2 = oy; nsegs++; }    if(xp != nx && ny != yp) { segments[nsegs].x1 = nx; segments[nsegs].y1 = ny; segments[nsegs].x2 = xp; segments[nsegs].y2 = ny; nsegs++; }     if(nx == ox && nx != xp) { segments[nsegs].x1 = nx; segments[nsegs].y1 = oy; segments[nsegs].x2 = nx; segments[nsegs].y2 = ny; nsegs++; }   segments[nsegs].x1 = xp; segments[nsegs].y1 = oy; segments[nsegs].x2 = xp; segments[nsegs].y2 = ny; nsegs++; }  ox = nx; oy = ny; XDrawSegments(dpy, root, gc, segments, nsegs); }
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 nx = xp, ny = yp, ox = xp, oy = yp, update_selection = 0;    XSegment segments[8]; /* 8 segments is the most possible */			  /* it may be beneficial to use */			  /* XDrawRectangle for 8 segment case */    int	nsegs = 0;    #ifdef DEBUG    puts("Selecting windows");#endif    if (XGrabPointer(dpy, scr->root_win, True, PointerMotionMask		| ButtonMotionMask | ButtonReleaseMask | ButtonPressMask 		| EnterWindowMask | LeaveWindowMask , GrabModeAsync,		     GrabModeAsync, None, wCursor[WCUR_DEFAULT],		     CurrentTime) != Success) {	return;    }    XGrabServer(dpy);        wUnselectWindows(scr);        while (1) {	update_selection = 0;	WMMaskEvent(dpy, ButtonReleaseMask | PointerMotionMask | LeaveWindowMask		| EnterWindowMask | ButtonPressMask,		&event);		if (!checkMouseSamplingRate(&event))	    continue;		nsegs = 0;	switch (event.type) {	 case LeaveNotify:	 case EnterNotify:#ifdef DEBUG	 	dbputs("got Enter/LeaveNotify in selection");#endif	    nx = event.xcrossing.x_root;	    ny = event.xcrossing.y_root;	    update_selection = 1;	    break;					 case MotionNotify:#ifdef DEBUG	 	dbputs("got motionevent in selection");#endif	    nx = event.xmotion.x_root;	    ny = event.xmotion.y_root;	    update_selection = 1;	    break;	 case ButtonPress:	    break;	 case ButtonRelease:	    if (event.xbutton.button != ev->xbutton.button)		break;	    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);	    XUngrabServer(dpy);	    XUngrabPointer(dpy, CurrentTime);	    selectWindowsInside(scr, xp, yp, w + xp, h + yp);	   #ifdef KWM_HINTS	    wKWMSelectRootRegion(scr, xp, yp, w, h, 				 event.xbutton.state & ControlMask);#endif /* KWM_HINTS */#ifdef DEBUG	    dbputs("End window selection");#endif	    return;	    	 default:#ifdef DEBUG	    dbputs("unknown event");	    dbprintf("type: %u\n", event.type);#endif	    WMHandleEvent(&event);	    break;	}	if(update_selection) {	/* stuff to change for movement along X axis */	    if(nx != ox) {		/* erase old vertical line */		/* only if old vertical line exists */		/* and only if its different from other vertical line */		if(yp != oy && ox != xp) {			segments[nsegs].x1 = ox;			segments[nsegs].y1 = yp;			segments[nsegs].x2 = ox;			segments[nsegs].y2 = oy;			nsegs++;		}		/* draw new vertical line */		/* only if new vertical line exists */		/* and only if its different from the other vertical line */		if(yp != ny && nx != xp) {			segments[nsegs].x1 = nx;			segments[nsegs].y1 = yp;			segments[nsegs].x2 = nx;			segments[nsegs].y2 = ny;			nsegs++;		}	/* difference along x axis from old to new on ny horizontal */	/* only if our mouse doesnt move along Y, otherwise this gets */	/* done elsewhere */		if(ny == oy && nx != xp) {			segments[nsegs].x1 = ox;			segments[nsegs].y1 = ny;			segments[nsegs].x2 = nx;			segments[nsegs].y2 = ny;			nsegs++;		}	/* difference along x axis from old to new on yp horizontal */		segments[nsegs].x1 = nx;		segments[nsegs].y1 = yp;		segments[nsegs].x2 = ox;		segments[nsegs].y2 = yp;		nsegs++;	    }	/* now for stuff to change for movement along Y axis */	    if(ny != oy) {	/* erase old horizontal line */	/* only if old horizontal line exists */	/* and only if its different from other horizontal line */		if(xp != ox && oy != yp) {			segments[nsegs].x1 = ox;			segments[nsegs].y1 = oy;			segments[nsegs].x2 = xp;			segments[nsegs].y2 = oy;			nsegs++;		}	/* draw new horizontal line */	/* only if horizontal line exists, and if its different from other */		if(xp != nx && ny != yp) {			segments[nsegs].x1 = nx;			segments[nsegs].y1 = ny;			segments[nsegs].x2 = xp;			segments[nsegs].y2 = ny;			nsegs++;		}	/* difference along y axis from old to new on nx vertical */	/* only if no movement along x axis */	/* and only if we dont have duplicate lines */		if(nx == ox && nx != xp) {			segments[nsegs].x1 = nx;			segments[nsegs].y1 = oy;			segments[nsegs].x2 = nx;			segments[nsegs].y2 = ny;			nsegs++;		}	/* difference along y axis from old to new on xp vertical */		segments[nsegs].x1 = xp;		segments[nsegs].y1 = oy;		segments[nsegs].x2 = xp;		segments[nsegs].y2 = ny;		nsegs++;	    }	    ox = nx;	    oy = ny;	    XDrawSegments(dpy, root, gc, segments, nsegs);	}    }}