From ac64e68fcb864e9bc778fb8caf10c6e0443e0bcf Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 17 Sep 1999 16:18:37 +0000 Subject: [PATCH] - Fixed compilation warnings. - Readded 'Auto placement' mode, with the old behavior, and made 'Smart placement' mode behave in the new way. Auto and Smart are no longer aliases. --- ChangeLog | 2 + WPrefs.app/WindowHandling.c | 8 ++- src/WindowMaker.h | 1 + src/defaults.c | 2 +- src/placement.c | 124 +++++++++++++++++++++++++++++++++++- src/rootmenu.c | 4 +- 6 files changed, 135 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0d2d5f63..15be9e45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -43,6 +43,8 @@ Changes since version 0.60.0: - fixed crash when more than 1 dockapp fails to launch on startup - added a different dock setup config for each screen size - fixed PPosition handling +- New "Smart placement" mode. 'Smart' is no longer an alias to 'Auto' but + a different mode of placing windows. 'Auto' keeps the old behavior. Changes since version 0.53.0: diff --git a/WPrefs.app/WindowHandling.c b/WPrefs.app/WindowHandling.c index 1c047620..e27458df 100644 --- a/WPrefs.app/WindowHandling.c +++ b/WPrefs.app/WindowHandling.c @@ -76,7 +76,8 @@ static char *placements[] = { "auto", "random", "manual", - "cascade" + "cascade", + "smart" }; @@ -126,7 +127,7 @@ getPlacement(char *str) if (!str) return 0; - if (strcasecmp(str, "auto")==0 || strcasecmp(str, "smart")==0) + if (strcasecmp(str, "auto")==0) return 0; else if (strcasecmp(str, "random")==0) return 1; @@ -134,6 +135,8 @@ getPlacement(char *str) return 2; else if (strcasecmp(str, "cascade")==0) return 3; + else if (strcasecmp(str, "smart")==0) + return 4; else wwarning(_("bad option value %s in WindowPlacement. Using default value"), str); @@ -241,6 +244,7 @@ createPanel(Panel *p) WMAddPopUpButtonItem(panel->placP, _("Random")); WMAddPopUpButtonItem(panel->placP, _("Manual")); WMAddPopUpButtonItem(panel->placP, _("Cascade")); + WMAddPopUpButtonItem(panel->placP, _("Smart")); panel->porigL = WMCreateLabel(panel->placF); WMResizeWidget(panel->porigL, 120, 32); diff --git a/src/WindowMaker.h b/src/WindowMaker.h index f815f10a..5aa85b6c 100644 --- a/src/WindowMaker.h +++ b/src/WindowMaker.h @@ -147,6 +147,7 @@ typedef enum { #define WPM_CASCADE 1 #define WPM_SMART 2 #define WPM_RANDOM 3 +#define WPM_AUTO 4 /* text justification */ #define WTJ_CENTER 0 diff --git a/src/defaults.c b/src/defaults.c index f4afe0ae..4d0051c1 100644 --- a/src/defaults.c +++ b/src/defaults.c @@ -231,7 +231,7 @@ static WOptionEnumeration seColormapModes[] = { }; static WOptionEnumeration sePlacements[] = { - {"Auto", WPM_SMART, 0}, {"Smart", WPM_SMART, 1}, + {"Auto", WPM_AUTO, 0}, {"Smart", WPM_SMART, 0}, {"Cascade", WPM_CASCADE, 0}, {"Random", WPM_RANDOM, 0}, {"Manual", WPM_MANUAL, 0}, diff --git a/src/placement.c b/src/placement.c index 7ebde181..425826fb 100644 --- a/src/placement.c +++ b/src/placement.c @@ -412,6 +412,118 @@ smartPlaceWindow(WWindow *wwin, int *x_ret, int *y_ret, } +static Bool +autoPlaceWindow(WWindow *wwin, int *x_ret, int *y_ret, + unsigned int width, unsigned int height, int tryCount) +{ + WScreen *scr = wwin->screen_ptr; + int test_x = 0, test_y = Y_ORIGIN(scr); + int loc_ok = False, tw,tx,ty,th; + int swidth, sx; + WWindow *test_window; + int extra_height; + WArea usableArea = scr->totalUsableArea; + + if (wwin->frame) + extra_height = wwin->frame->top_width + wwin->frame->bottom_width + 2; + else + extra_height = 24; /* random value */ + + swidth = usableArea.x2-usableArea.x1; + sx = X_ORIGIN(scr); + + /* this was based on fvwm2's smart placement */ + + height += extra_height; + + while (((test_y + height) < (scr->scr_height)) && (!loc_ok)) { + + 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; + } +#if 0 + tw = test_window->client.width; + if (test_window->flags.shaded) + th = test_window->frame->top_width; + else + th = test_window->client.height + extra_height; +#else + tw = test_window->frame->core->width; + th = test_window->frame->core->height; +#endif + 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->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; + } +#if 0 + tw = test_window->client.width; + if (test_window->flags.shaded) + th = test_window->frame->top_width; + else + th = test_window->client.height + extra_height; +#else + tw = test_window->frame->core->width; + th = test_window->frame->core->height; +#endif + 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->flags.miniaturized || + test_window->flags.hidden)))) { + + loc_ok = False; + } + test_window = test_window->prev; + } + if (loc_ok == True) { + *x_ret = test_x; + *y_ret = test_y; + break; + } + test_x += PLACETEST_HSTEP; + } + test_y += PLACETEST_VSTEP; + } + + return loc_ok; +} + + static void cascadeWindow(WScreen *scr, WWindow *wwin, int *x_ret, int *y_ret, unsigned int width, unsigned int height, int h) @@ -452,8 +564,18 @@ PlaceWindow(WWindow *wwin, int *x_ret, int *y_ret, smartPlaceWindow(wwin, x_ret, y_ret, width, height); break; + case WPM_AUTO: + if (autoPlaceWindow(wwin, x_ret, y_ret, width, height, 0)) { + break; + } else if (autoPlaceWindow(wwin, x_ret, y_ret, width, height, 1)) { + break; + } + /* there isn't a break here, because if we fail, it should fall + through to cascade placement, as people who want tiling want + automagicness aren't going to want to place their window */ + case WPM_CASCADE: - if (wPreferences.window_placement == WPM_SMART) + if (wPreferences.window_placement == WPM_AUTO) scr->cascade_index++; cascadeWindow(scr, wwin, x_ret, y_ret, width, height, h); diff --git a/src/rootmenu.c b/src/rootmenu.c index 2c9c8124..d847402c 100644 --- a/src/rootmenu.c +++ b/src/rootmenu.c @@ -1270,9 +1270,9 @@ typedef struct { static int -myCompare(dir_data *d1, dir_data *d2) +myCompare(const void *d1, const void *d2) { - return strcmp(d1->name, d2->name); + return strcmp(((dir_data*) d1)->name, ((dir_data*) d2)->name); }