Make wmaker 0.11% smaller by avoiding code duplication
This patch cleans up an obvious code duplication case in the
different "placement" algorithms which was used several times.
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 :-)
[ma...@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 files changed, 21 insertions(+), 51 deletions(-)
diff --git a/src/placement.c b/src/placement.c
index b4f7825..e0eb1dd 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 compute_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 += 8;
+ }
+ if (HAS_BORDER(wwin)) {
+ *height += 2;
+ *width += 2;
+ }
+}
+
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;
+ compute_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;
- }
-
+ compute_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;
- }
+ compute_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;
- }
+ compute_width_height(wwin, &width, &height);
w = ((usableArea.x2 - X_ORIGIN) - width);
h = ((usableArea.y2 - Y_ORIGIN) - height);
--
1.6.4.183.g04423
--
To unsubscribe, send mail to [email protected].