diff --git a/src/placement.c b/src/placement.c index 01f2590..5e00fff 100644 --- a/src/placement.c +++ b/src/placement.c @@ -565,10 +565,17 @@ smartPlacement (Client * c, int full_x, int full_y, int full_w, int full_h) test_y = full_y + frameTop (c); do { + gint next_test_y = G_MAXINT; test_x = full_x + frameLeft (c); do { gfloat count_overlaps = 0.0; + gint next_test_x = G_MAXINT; + gint c2_next_test_x; + gint c2_next_test_y; + gint c2_frame_height; + gint c2_frame_width; + TRACE ("analyzing %i clients", screen_info->client_count); for (c2 = screen_info->clients, i = 0; i < screen_info->client_count; c2 = c2->next, i++) { @@ -577,7 +584,21 @@ smartPlacement (Client * c, int full_x, int full_y, int full_w, int full_h) && FLAG_TEST (c2->xfwm_flags, XFWM_FLAG_VISIBLE)) { c2_x = frameX (c2); + if (c2_x > xmax) + { + /* skip windows on other monitors right-off */ + continue; + } + c2_y = frameY (c2); + if (c2_y > ymax) + { + /* skip windows on other monitors below */ + continue; + } + + c2_frame_width = frameWidth (c2); + c2_frame_height = frameHeight (c2); count_overlaps += overlap (test_x - frame_left, test_y - frame_top, @@ -585,8 +606,36 @@ smartPlacement (Client * c, int full_x, int full_y, int full_w, int full_h) test_y - frame_top + frame_height, c2_x, c2_y, - c2_x + frameWidth (c2), - c2_y + frameHeight (c2)); + c2_x + c2_frame_width, + c2_y + c2_frame_height); + + /* find the next x boundy change */ + if (test_x >= c2_x) + { + /* test location is beyond the x of the window, + * take the window right corner as next target */ + c2_x += c2_frame_width; + } + c2_next_test_x = MIN (c2_x, xmax); + if (c2_next_test_x < next_test_x + && c2_next_test_x > test_x) + { + next_test_x = c2_next_test_x; + } + + /* find the next y boundy change */ + if (test_y >= c2_y) + { + /* test location is beyond the y of the window, + * take the window bottom corner as next target */ + c2_y += c2_frame_height; + } + c2_next_test_y = MIN (c2_y, ymax); + if (c2_next_test_y < next_test_y + && c2_next_test_y > test_y) + { + next_test_y = c2_next_test_y; + } } } if (count_overlaps < 0.1) @@ -607,10 +656,26 @@ smartPlacement (Client * c, int full_x, int full_y, int full_w, int full_h) { first = FALSE; } - test_x += 8; + + if (next_test_x != G_MAXINT) + { + test_x = next_test_x; + } + else + { + test_x++; + } } while (test_x <= xmax); - test_y += 8; + + if (next_test_y != G_MAXINT) + { + test_y = next_test_y; + } + else + { + test_y++; + } } while (test_y <= ymax);