From 2f87d01a411d7aeccdb26ec7c80a124c1f20b112 Mon Sep 17 00:00:00 2001 From: "Carlos R. Mafra" Date: Fri, 28 Aug 2009 16:44:54 +0200 Subject: [PATCH] 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 --- src/placement.c | 72 +++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 51 deletions(-) diff --git a/src/placement.c b/src/placement.c index b4f78252..b045352c 100644 --- a/src/placement.c +++ b/src/placement.c @@ -318,6 +318,22 @@ static int calcSumOfCoveredAreas(WWindow * wwin, int x, int y, int w, int h) 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 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 sum_isect; - if (wwin->frame) { - 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; + set_width_height(wwin, &width, &height); + sx = X_ORIGIN; min_isect = INT_MAX; min_isect_x = sx; min_isect_y = test_y; @@ -399,24 +404,11 @@ autoPlaceWindow(WWindow * wwin, int *x_ret, int *y_ret, int swidth, sx; WWindow *test_window; - if (wwin->frame) { - 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; - } - + set_width_height(wwin, &width, &height); swidth = usableArea.x2 - usableArea.x1; sx = X_ORIGIN; /* this was based on fvwm2's smart placement */ - while (((test_y + height) < (usableArea.y2 - usableArea.y1)) && !loc_ok) { test_x = sx; @@ -507,18 +499,7 @@ static void cascadeWindow(WScreen * scr, WWindow * wwin, int *x_ret, int *y_ret, unsigned int width, unsigned int height, int h, WArea usableArea) { - if (wwin->frame) { - 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; - } + set_width_height(wwin, &width, &height); *x_ret = h * scr->cascade_index + X_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; - if (wwin->frame) { - 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; - } + set_width_height(wwin, &width, &height); w = ((usableArea.x2 - X_ORIGIN) - width); h = ((usableArea.y2 - Y_ORIGIN) - height);