[Xfce4-commits] <xfce4-notifyd:master> Fix to the workarea computation (Bug #6380).

Jérôme Guelfucci noreply at xfce.org
Sun Nov 7 13:32:01 CET 2010


Updating branch refs/heads/master
         to 302332feb7d3a43dcaec49c4806be45d126d62de (commit)
       from 384695c78ded2bff8cbc72c8366218a74df46665 (commit)

commit 302332feb7d3a43dcaec49c4806be45d126d62de
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date:   Tue Apr 13 00:05:25 2010 +0200

    Fix to the workarea computation (Bug #6380).
    
    Simplify the function to compute the workarea to make it actually
    understandable and usable.

 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  >|_____|<d2>|
+ *          |            ^      |
+ *          |___________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;
     }
 }
 



More information about the Xfce4-commits mailing list