mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-04 12:54:20 +01:00
split autoPlaceWindow to smaller functions
This commit is contained in:
committed by
Carlos R. Mafra
parent
17c93f0947
commit
a7471fd82a
113
src/placement.c
113
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; i; i = i->prev) {
|
||||||
|
if (window_overlaps(i, x, y, w, h, ignore_sunken)) {
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
smartPlaceWindow(WWindow *wwin, int *x_ret, int *y_ret, unsigned int width,
|
smartPlaceWindow(WWindow *wwin, int *x_ret, int *y_ret, unsigned int width,
|
||||||
unsigned int height, WArea usableArea)
|
unsigned int height, WArea usableArea)
|
||||||
@@ -380,83 +427,29 @@ autoPlaceWindow(WWindow *wwin, int *x_ret, int *y_ret,
|
|||||||
{
|
{
|
||||||
WScreen *scr = wwin->screen_ptr;
|
WScreen *scr = wwin->screen_ptr;
|
||||||
int test_x = 0, test_y = Y_ORIGIN;
|
int test_x = 0, test_y = Y_ORIGIN;
|
||||||
int loc_ok = False, tw, tx, ty, th;
|
|
||||||
int swidth, sx;
|
int swidth, sx;
|
||||||
WWindow *test_window;
|
|
||||||
|
|
||||||
set_width_height(wwin, &width, &height);
|
set_width_height(wwin, &width, &height);
|
||||||
swidth = usableArea.x2 - usableArea.x1;
|
swidth = usableArea.x2 - usableArea.x1;
|
||||||
sx = X_ORIGIN;
|
sx = X_ORIGIN;
|
||||||
|
|
||||||
/* this was based on fvwm2's smart placement */
|
/* 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;
|
test_x = sx;
|
||||||
|
|
||||||
while (((test_x + width) < swidth) && (!loc_ok)) {
|
while (((test_x + width) < swidth)) {
|
||||||
|
if (screen_has_space(scr, test_x, test_y,
|
||||||
loc_ok = True;
|
width, height, tryCount)) {
|
||||||
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) {
|
|
||||||
*x_ret = test_x;
|
*x_ret = test_x;
|
||||||
*y_ret = test_y;
|
*y_ret = test_y;
|
||||||
break;
|
return True;
|
||||||
}
|
}
|
||||||
test_x += PLACETEST_HSTEP;
|
test_x += PLACETEST_HSTEP;
|
||||||
}
|
}
|
||||||
test_y += PLACETEST_VSTEP;
|
test_y += PLACETEST_VSTEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
return loc_ok;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user