From 3e03b1092aa6a5c50a498dfe745a8f1d8f7a0aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Guelfucci?= Date: Tue, 13 Apr 2010 00:05:25 +0200 Subject: [PATCH] Possible fix to the workarea computation. Simplify the function to compute the workarea to make it actually understandable and hopefully fix the issue described in bug #6380. --- xfce4-notifyd/xfce-notify-daemon.c | 87 +++++++++++++++++++++--------------- 1 files changed, 51 insertions(+), 36 deletions(-) diff --git a/xfce4-notifyd/xfce-notify-daemon.c b/xfce4-notifyd/xfce-notify-daemon.c index 5b2fd36..24f75bb 100644 --- a/xfce4-notifyd/xfce-notify-daemon.c +++ b/xfce4-notifyd/xfce-notify-daemon.c @@ -391,47 +391,62 @@ xfce_notify_daemon_window_closed(XfceNotifyWindow *window, #endif } -/* Gets the largest rectangle in src1 which does not contain src2. */ +/* Gets the largest rectangle in src1 which does not contain src2. + * src2 is totally included in src1. */ +/* + * 1 + * ____________________ + * | ^ | + * | d1 | + * 4 |     ___|_ | 2 + * | < d4  >|_____|| + * | ^ | + * |___________d3______| + * + * 3 + */ static void xfce_gdk_rectangle_largest_box(GdkRectangle *src1, GdkRectangle *src2, GdkRectangle *dest) { - gint top = MAX(src2->y, src1->y); - gint left = MAX(src2->x, src1->x); - gint bottom = MAX(src2->height, src1->height) - - MIN(src2->y + src2->height, src1->y + src1->height); - gint right = MAX(src2->width, src1->width) - - MIN(src2->x + src2->width, src1->x + src1->width); - gint medium_h = MAX(top, bottom); - gint medium_w = MAX(left ,right); - - if(medium_h >= medium_w) { - /* Height is largest */ - if(top >= bottom) { - dest->x = src1->x; - dest->y = src1->y; - dest->width = src1->width; - dest->height = top + MIN(0, bottom); - } else { - dest->x = src1->x; - dest->y = src2->y + src2->height; - dest->width = src1->width; - dest->height = bottom + MIN(0, top); - } - } else { - /* Width is largest */ - if(left >= right) { - dest->x = src1->x; - dest->y = src1->y; - dest->width = medium_w + MIN(0, right); - dest->height = src1->height; - } else { - dest->x = src2->x + src2->width; - dest->y = src1->y; - dest->width = medium_w + MIN(0, left); - dest->height = src1->height; - } + gint d1, d2, d3, d4; /* distance to the different sides of src1, see drawing above */ + gint max; + + d1 = src2->y - src1->y; + d4 = src2->x - src1->x; + d2 = src1->width - d4 - src2->width; + d3 = src1->height - d1 - src2->height; + + /* Get the max of rectangles implied by d1, d2, d3 and d4 */ + max = MAX (d1 * src1->width, d2 * src1->height); + max = MAX (max, d3 * src1->width); + max = MAX (max, d4 * src1->height); + + if (max == d1 * src1->width) { + dest->x = src1->x; + dest->y = src1->y; + dest->height = d1; + dest->width = src1->width; + } + else if (max == d2 * src1->height) { + dest->x = src2->x + src2->width; + dest->y = src1->y; + dest->width = d2; + dest->height = src1->height; + } + else if (max == d3 * src1->width) { + dest->x = src1->x; + dest->y = src2->y + src2->height; + dest->width = src1->width; + dest->height = d3; + } + else { + /* max == d4 * src1->height */ + dest->x = src1->x; + dest->y = src1->y; + dest->height = src1->height; + dest->width = d4; } } -- 1.7.0