rem: for (i = data->rightIndex - 1; i >= 0; i--) { looprw = data->rightList[i]; if (!(data->realY > WBOTTOM(looprw) || (data->realY + data->winHeight) < WTOP(looprw))) { if (attract || (data->realX < (WRIGHT(looprw) + 2)) && dx < 0) { l_edge = WRIGHT(looprw) + 1; resist = WIN_RESISTANCE(wPreferences.edge_resistance); } break; } }  if (attract) { for (i = data->rightIndex; i < data->count; i++) { looprw = data->rightList[i]; if(!(data->realY > WBOTTOM(looprw) || (data->realY + data->winHeight) < WTOP(looprw))) { r_edge = WRIGHT(looprw) + 1; resist = WIN_RESISTANCE(wPreferences.edge_resistance); break; } } } }
add: for (i = data->rightIndex - 1; i >= 0; i--) { looprw = data->rightList[i]; if (!(data->realY > WBOTTOM(looprw) || (data->realY + data->winHeight) < WTOP(looprw))) { if (attract || ((data->realX < (WRIGHT(looprw) + 2)) && dx < 0)) { l_edge = WRIGHT(looprw) + 1; resist = WIN_RESISTANCE(wPreferences.edge_resistance); } break; } }  if (attract) { for (i = data->rightIndex; i < data->count; i++) { looprw = data->rightList[i]; if(!(data->realY > WBOTTOM(looprw) || (data->realY + data->winHeight) < WTOP(looprw))) { r_edge = WRIGHT(looprw) + 1; resist = WIN_RESISTANCE(wPreferences.edge_resistance); break; } } } }
context: updateWindowPosition(WWindow *wwin, MoveData *data, Bool doResistance,		     Bool opaqueMove, int newMouseX, int newMouseY){    WScreen *scr = wwin->screen_ptr;    int dx, dy;			       /* how much mouse moved */    int winL, winR, winT, winB;	       /* requested new window position */    int newX, newY;		       /* actual new window position */    Bool hresist, vresist;    Bool updateIndex;    Bool attract;    hresist = False;    vresist = False;    updateIndex = False;    /* check the direction of the movement */    dx = newMouseX - data->mouseX;    dy = newMouseY - data->mouseY;    data->omouseX = data->mouseX;    data->omouseY = data->mouseY;    data->mouseX = newMouseX;    data->mouseY = newMouseY;    winL = data->calcX + dx;    winR = data->calcX + data->winWidth + dx;    winT = data->calcY + dy;    winB = data->calcY + data->winHeight + dy;    newX = data->realX;    newY = data->realY;    if (doResistance) {	int l_edge, r_edge;	int edge_l, edge_r;	int t_edge, b_edge;	int edge_t, edge_b;	int resist;	WWindow *rwin;    WWindow *rrwin;    resist = WIN_RESISTANCE(wPreferences.edge_resistance);    attract = wPreferences.attract;	/* horizontal movement: check horizontal edge resistances */	if (dx || dy) {        int i;	    /* window is the leftmost window: check against screen edge */	    l_edge = scr->totalUsableArea.x1;	    r_edge = scr->totalUsableArea.x2 + resist;	    edge_l = scr->totalUsableArea.x1 - resist;	    edge_r = scr->totalUsableArea.x2;        /* 1 */	    if ((data->rightIndex >= 0) && (data->rightIndex <= data->count)) {            WWindow *looprw;                                    for (i = data->rightIndex - 1; i >= 0; i--) {                looprw = data->rightList[i];                if (!(data->realY > WBOTTOM(looprw)                             || (data->realY + data->winHeight) < WTOP(looprw))) {                    if (attract || (data->realX < (WRIGHT(looprw) + 2)) && dx < 0) {                        l_edge = WRIGHT(looprw) + 1;                        resist = WIN_RESISTANCE(wPreferences.edge_resistance);                    }                    break;                }            }            if (attract) {            for (i = data->rightIndex; i < data->count; i++) {                looprw = data->rightList[i];                if(!(data->realY > WBOTTOM(looprw)                             || (data->realY + data->winHeight) < WTOP(looprw))) {                    r_edge = WRIGHT(looprw) + 1;                    resist = WIN_RESISTANCE(wPreferences.edge_resistance);                    break;                }            }            }        }	    if ((data->leftIndex >= 0) && (data->leftIndex <= data->count)) {            WWindow *looprw;                                    for (i = data->leftIndex - 1; i >= 0; i--) {                looprw = data->leftList[i];                if (!(data->realY > WBOTTOM(looprw)                             || (data->realY + data->winHeight) < WTOP(looprw))) {                    if (attract || ((data->realX + data->winWidth) > (WLEFT(looprw) - 1)) && dx > 0) {                        edge_r = WLEFT(looprw);                        resist = WIN_RESISTANCE(wPreferences.edge_resistance);                    }                    break;                }            }            if (attract)            for (i = data->leftIndex; i < data->count; i++) {                looprw = data->leftList[i];                if(!(data->realY > WBOTTOM(looprw)                             || (data->realY + data->winHeight) < WTOP(looprw))) {                    edge_l = WLEFT(looprw);                    resist = WIN_RESISTANCE(wPreferences.edge_resistance);                    break;                }            }        }        /*        printf("%d %d\n",winL,winR);        printf("l_ %d r_ %d _l %d _r %d\n",l_edge,r_edge,edge_l,edge_r);        */        if ((winL - l_edge) < (r_edge - winL)) {            if (resist > 0) {            if ((attract && winL <= l_edge + resist && winL >= l_edge - resist)                || (dx < 0 && winL <= l_edge && winL >= l_edge - resist)) {                newX = l_edge;                hresist = True;            }            }        }        else {            if (resist > 0 && attract && winL >= r_edge - resist && winL <= r_edge + resist) {                newX = r_edge;                hresist = True;            }        }        if ((winR - edge_l) < (edge_r - winR)) {            if (resist > 0 && attract && winR <= edge_l + resist && winR >= edge_l - resist) {                newX = edge_l - data->winWidth;                hresist = True;            }        }        else {            if (resist > 0) {            if ((attract && winR >= edge_r - resist && winR <= edge_r + resist)                 || (dx > 0 && winR >= edge_r && winR <= edge_r + resist)) {                newX = edge_r - data->winWidth;                hresist = True;            }            }        }        /* VeRT */	    t_edge = scr->totalUsableArea.y1;	    b_edge = scr->totalUsableArea.y2 + resist;	    edge_t = scr->totalUsableArea.y1 - resist;	    edge_b = scr->totalUsableArea.y2;	    if ((data->bottomIndex >= 0) && (data->bottomIndex <= data->count)) {            WWindow *looprw;                                    for (i = data->bottomIndex - 1; i >= 0; i--) {                looprw = data->bottomList[i];                if (!(data->realX > WRIGHT(looprw)                             || (data->realX + data->winWidth) < WLEFT(looprw))) {                    if (attract || (data->realY < (WBOTTOM(looprw) + 2)) && dy < 0) {                        t_edge = WBOTTOM(looprw) + 1;                        resist = WIN_RESISTANCE(wPreferences.edge_resistance);                    }                    break;                }            }            if (attract) {            for (i = data->bottomIndex; i < data->count; i++) {                looprw = data->bottomList[i];                if(!(data->realX > WRIGHT(looprw)                             || (data->realX + data->winWidth) < WLEFT(looprw))) {                    b_edge = WBOTTOM(looprw) + 1;                    resist = WIN_RESISTANCE(wPreferences.edge_resistance);                    break;                }            }            }        }	    if ((data->topIndex >= 0) && (data->topIndex <= data->count)) {            WWindow *looprw;                                    for (i = data->topIndex - 1; i >= 0; i--) {                looprw = data->topList[i];                if (!(data->realX > WRIGHT(looprw)                             || (data->realX + data->winWidth) < WLEFT(looprw))) {                    if (attract || ((data->realY + data->winHeight) > (WTOP(looprw) - 1)) && dy > 0) {                        edge_b = WTOP(looprw);                        resist = WIN_RESISTANCE(wPreferences.edge_resistance);                    }                    break;                }            }            if (attract)            for (i = data->topIndex; i < data->count; i++) {                looprw = data->topList[i];                if(!(data->realX > WRIGHT(looprw)                             || (data->realX + data->winWidth) < WLEFT(looprw))) {                    edge_t = WTOP(looprw);                    resist = WIN_RESISTANCE(wPreferences.edge_resistance);                    break;                }            }        }        if ((winT - t_edge) < (b_edge - winT)) {            if (resist > 0) {            if ((attract && winT <= t_edge + resist && winT >= t_edge - resist)                || (dy < 0 && winT <= t_edge && winT >= t_edge - resist)) {                newY = t_edge;                vresist = True;            }            }        }        else {            if (resist > 0 && attract && winT >= b_edge - resist && winT <= b_edge + resist) {                newY = b_edge;                vresist = True;            }        }        if ((winB - edge_t) < (edge_b - winB)) {            if (resist > 0 && attract && winB <= edge_t + resist && winB >= edge_t - resist) {                newY = edge_t - data->winHeight;                vresist = True;            }        }        else {            if (resist > 0) {            if ((attract && winB >= edge_b - resist && winB <= edge_b + resist)                 || (dy > 0 && winB >= edge_b && winB <= edge_b + resist)) {                newY = edge_b - data->winHeight;                vresist = True;            }            }        }	}    /* END VeRT */    }    /* update window position */    data->calcX += dx;    data->calcY += dy;    if (((dx > 0 && data->calcX - data->realX > 0)	 || (dx < 0 && data->calcX - data->realX < 0)) && !hresist)	newX = data->calcX;    if (((dy > 0 && data->calcY - data->realY > 0)	 || (dy < 0 && data->calcY - data->realY < 0)) && !vresist)	newY = data->calcY;    if (data->realX != newX || data->realY != newY) {	if (wPreferences.move_display == WDIS_NEW	    && !scr->selected_windows) {	    showPosition(wwin, data->realX, data->realY);	}	if (opaqueMove) {	    doWindowMove(wwin, scr->selected_windows,			 newX - wwin->frame_x,			 newY - wwin->frame_y);	} else {	    /* erase frames */	    drawFrames(wwin, scr->selected_windows, 		       data->realX - wwin->frame_x,		       data->realY - wwin->frame_y);	}		if (!scr->selected_windows	    && wPreferences.move_display == WDIS_FRAME_CENTER) {			    moveGeometryDisplayCentered(scr, newX + data->winWidth/2, 					newY + data->winHeight/2);	}	if (!opaqueMove) {	    /* draw frames */	    drawFrames(wwin, scr->selected_windows, 		       newX - wwin->frame_x,		       newY - wwin->frame_y);	}	if (!scr->selected_windows) {	    showPosition(wwin, newX, newY);	}    }    /* recalc relative window position */    if (doResistance && (data->realX != newX || data->realY != newY)) {	updateResistance(wwin, data, newX, newY);    }    data->realX = newX;    data->realY = newY;}