Index: src/window.cpp =================================================================== --- src/window.cpp (revision 24919) +++ src/window.cpp (working copy) @@ -1868,6 +1870,70 @@ int GetMainViewBottom() static bool _dragging_window; ///< A window is being dragged or resized. /** + * Checks border visibility between edges of dragging window. + * @param v Window to which snap. + * @param w Dragging window. + * @param is_horisontal True if snap to left or to right border. + * @param snap_to_left_or_top_border True if snap to left or to top border. + * @return Bool variable. True if window can snap and false if can't. + */ +bool SnapChecking(const Window *v, const Window *w, bool is_horisontal, bool snap_to_left_or_top_border) +{ + int a; // upper border of gap + int b; // lower border of gap + int v_edge; + int wt_edge_first; + int wt_edge_second; + int wt_first_border; + int wt_second_border; + int windows_sort_direction = 1; + const Window *wt; + + if (is_horisontal){ + a = (v->top > w->top) ? v->top : w->top; + b = (v->top + v->height < w->top + w->height) ? v->top + v->height : w->top + w->height; + } else { + a = (v->left > w->left) ? v->left : w->left; + b = (v->left + v->width < w->left + w->width) ? v->left + v->width : w->left + w->width; + } + + wt = v; + while (true){ + if (wt->z_front == NULL) windows_sort_direction = -1; + if (windows_sort_direction == 1){ + wt = wt->z_front; + } else { + wt = wt->z_back; + } + if (wt == w) continue; + if (wt == v || wt == v->z_back) break; // Second condition need if snap to window which over dragging window + + if (is_horisontal){ + wt_first_border = wt->top; + wt_second_border = wt->top + wt->height; + v_edge = (snap_to_left_or_top_border) ? v->left : v->left + v->width; + wt_edge_first = wt->left; + wt_edge_second = wt->left + wt->width; + } else { + wt_first_border = wt->left; + wt_second_border = wt->left + wt->width; + v_edge = (snap_to_left_or_top_border) ? v->top : v->top + v->height; + wt_edge_first = wt->top; + wt_edge_second = wt->top + wt->height; + } + + if (IsInsideMM(v_edge, wt_edge_first, wt_edge_second)){ + if (wt_first_border > b || wt_second_border < a) continue; + if (wt_first_border > a && wt_second_border < b) continue; + if (wt_first_border < a && wt_second_border > b) {a = 0; b = 0; break;} + if (wt_first_border <= a && wt_second_border > a) {a = wt_second_border; continue;} + if (wt_first_border > a && wt_second_border >= b) {b = wt_first_border; continue;} + } + } + return (a >= b) ? false : true; +} + +/** * Handle dragging/resizing of a window. * @return State of handling the event. */ @@ -1910,31 +1976,36 @@ static EventState HandleWindowDragging() /* Your left border <-> other right border */ delta = abs(v->left + v->width - x); if (delta <= hsnap) { - nx = v->left + v->width; - hsnap = delta; + if (SnapChecking(v, w, true, false)){ + nx = v->left + v->width; + hsnap = delta; + } } - /* Your right border <-> other left border */ delta = abs(v->left - x - w->width); if (delta <= hsnap) { - nx = v->left - w->width; - hsnap = delta; + if (SnapChecking(v, w, true, true)){ + nx = v->left - w->width; + hsnap = delta; + } } } - if (w->top + w->height >= v->top && w->top <= v->top + v->height) { - /* Your left border <-> other left border */ + /* Your left border <-> other left border */ delta = abs(v->left - x); if (delta <= hsnap) { - nx = v->left; - hsnap = delta; + if (SnapChecking(v, w, true, true)){ + nx = v->left; + hsnap = delta; + } } - /* Your right border <-> other right border */ delta = abs(v->left + v->width - x - w->width); if (delta <= hsnap) { - nx = v->left + v->width - w->width; - hsnap = delta; + if (SnapChecking(v, w, true, false)){ + nx = v->left + v->width - w->width; + hsnap = delta; + } } } @@ -1942,15 +2013,18 @@ static EventState HandleWindowDragging() /* Your top border <-> other bottom border */ delta = abs(v->top + v->height - y); if (delta <= vsnap) { - ny = v->top + v->height; - vsnap = delta; + if (SnapChecking(v, w, false, false)){ + ny = v->top + v->height; + vsnap = delta; + } } - /* Your bottom border <-> other top border */ delta = abs(v->top - y - w->height); if (delta <= vsnap) { - ny = v->top - w->height; - vsnap = delta; + if (SnapChecking(v, w, false, true)){ + ny = v->top - w->height; + vsnap = delta; + } } } @@ -1958,15 +2032,19 @@ static EventState HandleWindowDragging() /* Your top border <-> other top border */ delta = abs(v->top - y); if (delta <= vsnap) { - ny = v->top; - vsnap = delta; + if (SnapChecking(v, w, false, true)){ + ny = v->top; + vsnap = delta; + } } /* Your bottom border <-> other bottom border */ delta = abs(v->top + v->height - y - w->height); if (delta <= vsnap) { - ny = v->top + v->height - w->height; - vsnap = delta; + if (SnapChecking(v, w, false, false)){ + ny = v->top + v->height - w->height; + vsnap = delta; + } } } }