From: Yuri Karaban <[email protected]>

---
 src/placement.c | 113 ++++++++++++++++++++++++++------------------------------
 1 file changed, 53 insertions(+), 60 deletions(-)

diff --git a/src/placement.c b/src/placement.c
index f48ee3c..fb7a17f 100644
--- a/src/placement.c
+++ b/src/placement.c
@@ -294,6 +294,53 @@ static void set_width_height(WWindow *wwin, unsigned int 
*width, unsigned int *h
        }
 }
 
+static Bool
+window_overlaps(WWindow *win, int x, int y, int w, int h, Bool ignore_sunken)
+{
+       int tw, th, tx, ty;
+
+       if (ignore_sunken &&
+           win->frame->core->stacking->window_level < WMNormalLevel) {
+               return False;
+       }
+
+       tw = win->frame->core->width;
+       th = win->frame->core->height;
+       tx = win->frame_x;
+       ty = win->frame_y;
+
+       if ((tx < (x + w)) && ((tx + tw) > x) &&
+           (ty < (y + h)) && ((ty + th) > y) &&
+           (win->flags.mapped ||
+            (win->flags.shaded &&
+             win->frame->workspace == w_global.workspace.current &&
+             !(win->flags.miniaturized || win->flags.hidden)))) {
+               return True;
+       }
+
+       return False;
+}
+
+static Bool
+screen_has_space(WScreen *scr, int x, int y, int w, int h, Bool ignore_sunken)
+{
+       WWindow *focused = scr->focused_window, *i;
+
+       for (i = focused; i; i = i->next) {
+               if (window_overlaps(i, x, y, w, h, ignore_sunken)) {
+                       return False;
+               }
+       }
+
+       for (i = focused->prev; i; i = i->prev) {
+               if (window_overlaps(i, x, y, w, h, ignore_sunken)) {
+                       return False;
+               }
+       }
+
+       return True;
+}
+
 static void
 smartPlaceWindow(WWindow *wwin, int *x_ret, int *y_ret, unsigned int width,
                 unsigned int height, WArea usableArea)
@@ -380,83 +427,29 @@ autoPlaceWindow(WWindow *wwin, int *x_ret, int *y_ret,
 {
        WScreen *scr = wwin->screen_ptr;
        int test_x = 0, test_y = Y_ORIGIN;
-       int loc_ok = False, tw, tx, ty, th;
        int swidth, sx;
-       WWindow *test_window;
 
        set_width_height(wwin, &width, &height);
        swidth = usableArea.x2 - usableArea.x1;
        sx = X_ORIGIN;
 
        /* this was based on fvwm2's smart placement */
-       while (((test_y + height) < (usableArea.y2 - usableArea.y1)) && 
!loc_ok) {
+       while (((test_y + height) < (usableArea.y2 - usableArea.y1))) {
                test_x = sx;
 
-               while (((test_x + width) < swidth) && (!loc_ok)) {
-
-                       loc_ok = True;
-                       test_window = scr->focused_window;
-
-                       while ((test_window != NULL) && (loc_ok == True)) {
-
-                               if 
(test_window->frame->core->stacking->window_level
-                                   < WMNormalLevel && tryCount > 0) {
-                                       test_window = test_window->next;
-                                       continue;
-                               }
-                               tw = test_window->frame->core->width;
-                               th = test_window->frame->core->height;
-                               tx = test_window->frame_x;
-                               ty = test_window->frame_y;
-
-                               if ((tx < (test_x + width)) && ((tx + tw) > 
test_x) &&
-                                   (ty < (test_y + height)) && ((ty + th) > 
test_y) &&
-                                   (test_window->flags.mapped ||
-                                    (test_window->flags.shaded &&
-                                     test_window->frame->workspace == 
w_global.workspace.current &&
-                                     !(test_window->flags.miniaturized || 
test_window->flags.hidden)))) {
-
-                                       loc_ok = False;
-                               }
-                               test_window = test_window->next;
-                       }
-
-                       test_window = scr->focused_window;
-
-                       while ((test_window != NULL) && (loc_ok == True)) {
-
-                               if 
(test_window->frame->core->stacking->window_level
-                                   < WMNormalLevel && tryCount > 0) {
-                                       test_window = test_window->prev;
-                                       continue;
-                               }
-                               tw = test_window->frame->core->width;
-                               th = test_window->frame->core->height;
-                               tx = test_window->frame_x;
-                               ty = test_window->frame_y;
-
-                               if ((tx < (test_x + width)) && ((tx + tw) > 
test_x) &&
-                                   (ty < (test_y + height)) && ((ty + th) > 
test_y) &&
-                                   (test_window->flags.mapped ||
-                                    (test_window->flags.shaded &&
-                                     test_window->frame->workspace == 
w_global.workspace.current &&
-                                     !(test_window->flags.miniaturized || 
test_window->flags.hidden)))) {
-
-                                       loc_ok = False;
-                               }
-                               test_window = test_window->prev;
-                       }
-                       if (loc_ok == True) {
+               while (((test_x + width) < swidth)) {
+                       if (screen_has_space(scr, test_x, test_y,
+                                            width, height, tryCount)) {
                                *x_ret = test_x;
                                *y_ret = test_y;
-                               break;
+                               return True;
                        }
                        test_x += PLACETEST_HSTEP;
                }
                test_y += PLACETEST_VSTEP;
        }
 
-       return loc_ok;
+       return False;
 }
 
 static void
-- 
1.9.1


-- 
To unsubscribe, send mail to [email protected].

Reply via email to