mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-20 21:08:08 +01:00
Make wmaker 0.11% smaller by avoiding code duplication
This patch cleans up an obvious code duplication case in the different "placement" algorithms. Avoid this needless repetition by using a helper function, which in turn lets those functions a bit easier to read and also makes wmaker 0.11% smaller :-) [mafra@Pilar:wmaker.git]$ size src/.libs/wmaker.* text data bss dec hex filename 619824 19160 8544 647528 9e168 src/.libs/wmaker.new 620552 19160 8544 648256 9e440 src/.libs/wmaker.old
This commit is contained in:
@@ -318,6 +318,22 @@ static int calcSumOfCoveredAreas(WWindow * wwin, int x, int y, int w, int h)
|
|||||||
return sum_isect;
|
return sum_isect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_width_height(WWindow *wwin, unsigned int *width, unsigned int *height)
|
||||||
|
{
|
||||||
|
if (wwin->frame) {
|
||||||
|
*height += wwin->frame->top_width + wwin->frame->bottom_width;
|
||||||
|
} else {
|
||||||
|
if (HAS_TITLEBAR(wwin))
|
||||||
|
*height += 18;
|
||||||
|
if (HAS_RESIZEBAR(wwin))
|
||||||
|
*height += RESIZEBAR_HEIGHT;
|
||||||
|
}
|
||||||
|
if (HAS_BORDER(wwin)) {
|
||||||
|
*height += 2 * FRAME_BORDER_WIDTH;
|
||||||
|
*width += 2 * FRAME_BORDER_WIDTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
smartPlaceWindow(WWindow * wwin, int *x_ret, int *y_ret, unsigned int width, unsigned int height, WArea usableArea)
|
smartPlaceWindow(WWindow * wwin, int *x_ret, int *y_ret, unsigned int width, unsigned int height, WArea usableArea)
|
||||||
{
|
{
|
||||||
@@ -327,20 +343,9 @@ smartPlaceWindow(WWindow * wwin, int *x_ret, int *y_ret, unsigned int width, uns
|
|||||||
int min_isect, min_isect_x, min_isect_y;
|
int min_isect, min_isect_x, min_isect_y;
|
||||||
int sum_isect;
|
int sum_isect;
|
||||||
|
|
||||||
if (wwin->frame) {
|
set_width_height(wwin, &width, &height);
|
||||||
height += wwin->frame->top_width + wwin->frame->bottom_width;
|
|
||||||
} else {
|
|
||||||
if (HAS_TITLEBAR(wwin))
|
|
||||||
height += 18;
|
|
||||||
if (HAS_RESIZEBAR(wwin))
|
|
||||||
height += 8;
|
|
||||||
}
|
|
||||||
if (HAS_BORDER(wwin)) {
|
|
||||||
height += 2;
|
|
||||||
width += 2;
|
|
||||||
}
|
|
||||||
sx = X_ORIGIN;
|
|
||||||
|
|
||||||
|
sx = X_ORIGIN;
|
||||||
min_isect = INT_MAX;
|
min_isect = INT_MAX;
|
||||||
min_isect_x = sx;
|
min_isect_x = sx;
|
||||||
min_isect_y = test_y;
|
min_isect_y = test_y;
|
||||||
@@ -399,24 +404,11 @@ autoPlaceWindow(WWindow * wwin, int *x_ret, int *y_ret,
|
|||||||
int swidth, sx;
|
int swidth, sx;
|
||||||
WWindow *test_window;
|
WWindow *test_window;
|
||||||
|
|
||||||
if (wwin->frame) {
|
set_width_height(wwin, &width, &height);
|
||||||
height += wwin->frame->top_width + wwin->frame->bottom_width;
|
|
||||||
} else {
|
|
||||||
if (HAS_TITLEBAR(wwin))
|
|
||||||
height += 18;
|
|
||||||
if (HAS_RESIZEBAR(wwin))
|
|
||||||
height += 8;
|
|
||||||
}
|
|
||||||
if (HAS_BORDER(wwin)) {
|
|
||||||
height += 2;
|
|
||||||
width += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) && !loc_ok) {
|
||||||
test_x = sx;
|
test_x = sx;
|
||||||
|
|
||||||
@@ -507,18 +499,7 @@ static void
|
|||||||
cascadeWindow(WScreen * scr, WWindow * wwin, int *x_ret, int *y_ret,
|
cascadeWindow(WScreen * scr, WWindow * wwin, int *x_ret, int *y_ret,
|
||||||
unsigned int width, unsigned int height, int h, WArea usableArea)
|
unsigned int width, unsigned int height, int h, WArea usableArea)
|
||||||
{
|
{
|
||||||
if (wwin->frame) {
|
set_width_height(wwin, &width, &height);
|
||||||
height += wwin->frame->top_width + wwin->frame->bottom_width;
|
|
||||||
} else {
|
|
||||||
if (HAS_TITLEBAR(wwin))
|
|
||||||
height += 18;
|
|
||||||
if (HAS_RESIZEBAR(wwin))
|
|
||||||
height += 8;
|
|
||||||
}
|
|
||||||
if (HAS_BORDER(wwin)) {
|
|
||||||
height += 2;
|
|
||||||
width += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
*x_ret = h * scr->cascade_index + X_ORIGIN;
|
*x_ret = h * scr->cascade_index + X_ORIGIN;
|
||||||
*y_ret = h * scr->cascade_index + Y_ORIGIN;
|
*y_ret = h * scr->cascade_index + Y_ORIGIN;
|
||||||
@@ -536,18 +517,7 @@ randomPlaceWindow(WScreen * scr, WWindow * wwin, int *x_ret, int *y_ret,
|
|||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
|
|
||||||
if (wwin->frame) {
|
set_width_height(wwin, &width, &height);
|
||||||
height += wwin->frame->top_width + wwin->frame->bottom_width;
|
|
||||||
} else {
|
|
||||||
if (HAS_TITLEBAR(wwin))
|
|
||||||
height += 18;
|
|
||||||
if (HAS_RESIZEBAR(wwin))
|
|
||||||
height += 8;
|
|
||||||
}
|
|
||||||
if (HAS_BORDER(wwin)) {
|
|
||||||
height += 2;
|
|
||||||
width += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
w = ((usableArea.x2 - X_ORIGIN) - width);
|
w = ((usableArea.x2 - X_ORIGIN) - width);
|
||||||
h = ((usableArea.y2 - Y_ORIGIN) - height);
|
h = ((usableArea.y2 - Y_ORIGIN) - height);
|
||||||
|
|||||||
Reference in New Issue
Block a user