mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +01:00
Add "Center" window placement strategy
Center strategy: try to put window at the center of the usable area. If window would overlap with existing windows, fall back to "Auto" placement strategy. It's very useful for fresh workplaces.
This commit is contained in:
committed by
Carlos R. Mafra
parent
1a594de74e
commit
9d3d34599f
@@ -82,7 +82,8 @@ static char *placements[] = {
|
|||||||
"random",
|
"random",
|
||||||
"manual",
|
"manual",
|
||||||
"cascade",
|
"cascade",
|
||||||
"smart"
|
"smart",
|
||||||
|
"center"
|
||||||
};
|
};
|
||||||
|
|
||||||
static void sliderCallback(WMWidget * w, void *data)
|
static void sliderCallback(WMWidget * w, void *data)
|
||||||
@@ -151,6 +152,8 @@ static int getPlacement(char *str)
|
|||||||
return 3;
|
return 3;
|
||||||
else if (strcasecmp(str, "smart") == 0)
|
else if (strcasecmp(str, "smart") == 0)
|
||||||
return 4;
|
return 4;
|
||||||
|
else if (strcasecmp(str, "center") == 0)
|
||||||
|
return 5;
|
||||||
else
|
else
|
||||||
wwarning(_("bad option value %s in WindowPlacement. Using default value"), str);
|
wwarning(_("bad option value %s in WindowPlacement. Using default value"), str);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -266,6 +269,7 @@ static void createPanel(Panel * p)
|
|||||||
WMAddPopUpButtonItem(panel->placP, _("Manual"));
|
WMAddPopUpButtonItem(panel->placP, _("Manual"));
|
||||||
WMAddPopUpButtonItem(panel->placP, _("Cascade"));
|
WMAddPopUpButtonItem(panel->placP, _("Cascade"));
|
||||||
WMAddPopUpButtonItem(panel->placP, _("Smart"));
|
WMAddPopUpButtonItem(panel->placP, _("Smart"));
|
||||||
|
WMAddPopUpButtonItem(panel->placP, _("Center"));
|
||||||
|
|
||||||
panel->porigL = WMCreateLabel(panel->placF);
|
panel->porigL = WMCreateLabel(panel->placF);
|
||||||
WMResizeWidget(panel->porigL, 120, 32);
|
WMResizeWidget(panel->porigL, 120, 32);
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ typedef enum {
|
|||||||
#define WPM_SMART 2
|
#define WPM_SMART 2
|
||||||
#define WPM_RANDOM 3
|
#define WPM_RANDOM 3
|
||||||
#define WPM_AUTO 4
|
#define WPM_AUTO 4
|
||||||
|
#define WPM_CENTER 5
|
||||||
|
|
||||||
/* text justification */
|
/* text justification */
|
||||||
#define WTJ_CENTER 0
|
#define WTJ_CENTER 0
|
||||||
|
|||||||
@@ -204,6 +204,7 @@ static WOptionEnumeration sePlacements[] = {
|
|||||||
{"Cascade", WPM_CASCADE, 0},
|
{"Cascade", WPM_CASCADE, 0},
|
||||||
{"Random", WPM_RANDOM, 0},
|
{"Random", WPM_RANDOM, 0},
|
||||||
{"Manual", WPM_MANUAL, 0},
|
{"Manual", WPM_MANUAL, 0},
|
||||||
|
{"Center", WPM_CENTER, 0},
|
||||||
{NULL, 0, 0}
|
{NULL, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -360,6 +360,46 @@ smartPlaceWindow(WWindow *wwin, int *x_ret, int *y_ret, unsigned int width,
|
|||||||
*y_ret = min_isect_y;
|
*y_ret = min_isect_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Bool
|
||||||
|
center_place_window(WWindow *wwin, int *x_ret, int *y_ret,
|
||||||
|
unsigned int width, unsigned int height, WArea usableArea)
|
||||||
|
{
|
||||||
|
WScreen *scr = wwin->screen_ptr;
|
||||||
|
int try_x, try_y;
|
||||||
|
int swidth, sheight;
|
||||||
|
WWindow *win;
|
||||||
|
|
||||||
|
set_width_height(wwin, &width, &height);
|
||||||
|
swidth = usableArea.x2 - usableArea.x1;
|
||||||
|
sheight = usableArea.y2 - usableArea.y1;
|
||||||
|
|
||||||
|
if (width > swidth || height > sheight)
|
||||||
|
return False;
|
||||||
|
|
||||||
|
try_x = (usableArea.x1 + usableArea.x2 - width) / 2;
|
||||||
|
try_y = (usableArea.y1 + usableArea.y2 - height) / 2;
|
||||||
|
|
||||||
|
for (win = scr->focused_window; win != NULL; win = win->next) {
|
||||||
|
int w = win->frame->core->width;
|
||||||
|
int h = win->frame->core->height;
|
||||||
|
int x = win->frame_x;
|
||||||
|
int y = win->frame_y;
|
||||||
|
|
||||||
|
if ((x < (try_x + width)) && ((x + w) > try_x) &&
|
||||||
|
(y < (try_y + height)) && ((y + h) > try_y) &&
|
||||||
|
(win->flags.mapped ||
|
||||||
|
(win->flags.shaded &&
|
||||||
|
win->frame->workspace == scr->current_workspace &&
|
||||||
|
!(win->flags.miniaturized || win->flags.hidden))))
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
*x_ret = try_x;
|
||||||
|
*y_ret = try_y;
|
||||||
|
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
|
||||||
static Bool
|
static Bool
|
||||||
autoPlaceWindow(WWindow *wwin, int *x_ret, int *y_ret,
|
autoPlaceWindow(WWindow *wwin, int *x_ret, int *y_ret,
|
||||||
unsigned int width, unsigned int height, int tryCount, WArea usableArea)
|
unsigned int width, unsigned int height, int tryCount, WArea usableArea)
|
||||||
@@ -502,6 +542,11 @@ void PlaceWindow(WWindow *wwin, int *x_ret, int *y_ret, unsigned width, unsigned
|
|||||||
smartPlaceWindow(wwin, x_ret, y_ret, width, height, usableArea);
|
smartPlaceWindow(wwin, x_ret, y_ret, width, height, usableArea);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WPM_CENTER:
|
||||||
|
if (center_place_window(wwin, x_ret, y_ret, width, height, usableArea))
|
||||||
|
break;
|
||||||
|
/* fall through to auto placement */
|
||||||
|
|
||||||
case WPM_AUTO:
|
case WPM_AUTO:
|
||||||
if (autoPlaceWindow(wwin, x_ret, y_ret, width, height, 0, usableArea)) {
|
if (autoPlaceWindow(wwin, x_ret, y_ret, width, height, 0, usableArea)) {
|
||||||
break;
|
break;
|
||||||
@@ -513,7 +558,7 @@ void PlaceWindow(WWindow *wwin, int *x_ret, int *y_ret, unsigned width, unsigned
|
|||||||
automagicness aren't going to want to place their window */
|
automagicness aren't going to want to place their window */
|
||||||
|
|
||||||
case WPM_CASCADE:
|
case WPM_CASCADE:
|
||||||
if (wPreferences.window_placement == WPM_AUTO)
|
if (wPreferences.window_placement == WPM_AUTO || wPreferences.window_placement == WPM_CENTER)
|
||||||
scr->cascade_index++;
|
scr->cascade_index++;
|
||||||
|
|
||||||
cascadeWindow(scr, wwin, x_ret, y_ret, width, height, h, usableArea);
|
cascadeWindow(scr, wwin, x_ret, y_ret, width, height, h, usableArea);
|
||||||
|
|||||||
Reference in New Issue
Block a user