From 73367237be1c901eaff95fc8a1d87221cc50f1ff Mon Sep 17 00:00:00 2001
From: David Maciejak <david.maciejak@gmail.com>
Date: Fri, 22 Aug 2014 19:29:19 +0800
Subject: [PATCH] wmaker: src/action.c merge duplicate code

This patch is merging some duplicate code related
to animation position.
---
 src/actions.c | 81 ++++++++++++++++++++++++++---------------------------------
 1 file changed, 35 insertions(+), 46 deletions(-)

diff --git a/src/actions.c b/src/actions.c
index ae326a1..aa88633 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -1060,6 +1060,34 @@ static WWindow *recursiveTransientFor(WWindow * wwin)
 	return wwin;
 }
 
+static int getAnimationGeometry(WWindow *wwin, int *ix, int *iy, int *iw, int *ih)
+{
+	if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
+		&& !wwin->flags.skip_next_animation && wwin->icon != NULL) {
+		if (!wPreferences.disable_miniwindows
+		    && !wwin->flags.net_handle_icon) {
+			*ix = wwin->icon_x;
+			*iy = wwin->icon_y;
+			*iw = wwin->icon->core->width;
+			*ih = wwin->icon->core->height;
+		} else {
+			if (wwin->flags.net_handle_icon) {
+				*ix = wwin->icon_x;
+				*iy = wwin->icon_y;
+				*iw = wwin->icon_w;
+				*ih = wwin->icon_h;
+			} else {
+				*ix = 0;
+				*iy = 0;
+				*iw = wwin->screen_ptr->scr_width;
+				*ih = wwin->screen_ptr->scr_height;
+			}
+		}
+		return 1;
+	}
+	return 0;
+}
+
 void wIconifyWindow(WWindow * wwin)
 {
 	XWindowAttributes attribs;
@@ -1137,6 +1165,9 @@ void wIconifyWindow(WWindow * wwin)
 	unmapTransientsFor(wwin);
 
 	if (present) {
+#ifdef ANIMATIONS
+		int ix, iy, iw, ih;
+#endif
 		XUngrabPointer(dpy, CurrentTime);
 		wWindowUnmap(wwin);
 		/* let all Expose events arrive so that we can repaint
@@ -1150,28 +1181,7 @@ void wIconifyWindow(WWindow * wwin)
 
 		flushExpose();
 #ifdef ANIMATIONS
-		if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
-		    && !wPreferences.no_animations) {
-			int ix, iy, iw, ih;
-
-			if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
-				ix = wwin->icon_x;
-				iy = wwin->icon_y;
-				iw = wwin->icon->core->width;
-				ih = wwin->icon->core->height;
-			} else {
-				if (wwin->flags.net_handle_icon) {
-					ix = wwin->icon_x;
-					iy = wwin->icon_y;
-					iw = wwin->icon_w;
-					ih = wwin->icon_h;
-				} else {
-					ix = 0;
-					iy = 0;
-					iw = wwin->screen_ptr->scr_width;
-					ih = wwin->screen_ptr->scr_height;
-				}
-			}
+		if (getAnimationGeometry(wwin, &ix, &iy, &iw, &ih)) {
 			animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
 				      wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
 		}
@@ -1291,34 +1301,13 @@ void wDeiconifyWindow(WWindow *wwin)
 	/* if the window is in another workspace, do it silently */
 	if (!netwm_hidden) {
 #ifdef ANIMATIONS
-		if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
-		    && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
-			int ix, iy, iw, ih;
-
-			if (!wPreferences.disable_miniwindows
-			    && !wwin->flags.net_handle_icon) {
-				ix = wwin->icon_x;
-				iy = wwin->icon_y;
-				iw = wwin->icon->core->width;
-				ih = wwin->icon->core->height;
-			} else {
-				if (wwin->flags.net_handle_icon) {
-					ix = wwin->icon_x;
-					iy = wwin->icon_y;
-					iw = wwin->icon_w;
-					ih = wwin->icon_h;
-				} else {
-					ix = 0;
-					iy = 0;
-					iw = wwin->screen_ptr->scr_width;
-					ih = wwin->screen_ptr->scr_height;
-				}
-			}
+		int ix, iy, iw, ih;
+		if (getAnimationGeometry(wwin, &ix, &iy, &iw, &ih)) {
 			animateResize(wwin->screen_ptr, ix, iy, iw, ih,
 				      wwin->frame_x, wwin->frame_y,
 				      wwin->frame->core->width, wwin->frame->core->height);
 		}
-#endif	/* ANIMATIONS */
+#endif
 		wwin->flags.skip_next_animation = 0;
 		XGrabServer(dpy);
 		if (!wwin->flags.shaded)
-- 
1.8.3.2

