[Xfce4-commits] r24048 - xfwm4/trunk/src

Olivier Fourdan olivier at xfce.org
Tue Dec 5 21:00:07 CET 2006


Author: olivier
Date: 2006-12-05 20:00:06 +0000 (Tue, 05 Dec 2006)
New Revision: 24048

Modified:
   xfwm4/trunk/src/client.c
   xfwm4/trunk/src/client.h
   xfwm4/trunk/src/events.c
   xfwm4/trunk/src/netwm.c
   xfwm4/trunk/src/netwm.h
Log:
Be a lot more paranoid about what broken apps set as struts.

Modified: xfwm4/trunk/src/client.c
===================================================================
--- xfwm4/trunk/src/client.c	2006-12-04 20:32:53 UTC (rev 24047)
+++ xfwm4/trunk/src/client.c	2006-12-05 20:00:06 UTC (rev 24048)
@@ -419,27 +419,25 @@
     g_return_if_fail (w != NULL);
     TRACE ("entering clientComputeWidth");
 
-    if (FLAG_TEST (c->flags, CLIENT_FLAG_FULLSCREEN)
-        || (FLAG_TEST_ALL (c->flags, CLIENT_FLAG_MAXIMIZED)
-            && (c->screen_info->params->borderless_maximize)))
+    /* Bypass resize increment and max sizes for fullscreen */
+    if (!FLAG_TEST (c->flags, CLIENT_FLAG_FULLSCREEN)
+        && !(FLAG_TEST_ALL (c->flags, CLIENT_FLAG_MAXIMIZED)
+             && (c->screen_info->params->borderless_maximize)))
     {
-        /* Bypass resize increment and max sizes for fullscreen */
-        c->width = *w;
-        return;
-    }
-
-    if ((c->size->flags & PResizeInc) && (c->size->width_inc))
-    {
-        w2 = (*w - c->size->min_width) / c->size->width_inc;
-        *w = c->size->min_width + (w2 * c->size->width_inc);
-    }
-    if (c->size->flags & PMaxSize)
-    {
-        if (*w > c->size->max_width)
+        if ((c->size->flags & PResizeInc) && (c->size->width_inc))
         {
-            *w = c->size->max_width;
+            w2 = (*w - c->size->min_width) / c->size->width_inc;
+            *w = c->size->min_width + (w2 * c->size->width_inc);
         }
+        if (c->size->flags & PMaxSize)
+        {
+            if (*w > c->size->max_width)
+            {
+                *w = c->size->max_width;
+            }
+        }
     }
+
     if (c->size->flags & PMinSize)
     {
         if (*w < c->size->min_width)
@@ -475,27 +473,25 @@
     g_return_if_fail (c != NULL);
     TRACE ("entering clientComputeHeight");
 
-    if (FLAG_TEST (c->flags, CLIENT_FLAG_FULLSCREEN)
-        || (FLAG_TEST_ALL (c->flags, CLIENT_FLAG_MAXIMIZED)
-            && (c->screen_info->params->borderless_maximize)))
+    /* Bypass resize increment and max sizes for fullscreen */
+    if (!FLAG_TEST (c->flags, CLIENT_FLAG_FULLSCREEN)
+        && !(FLAG_TEST_ALL (c->flags, CLIENT_FLAG_MAXIMIZED)
+             && (c->screen_info->params->borderless_maximize)))
     {
-        /* Bypass resize increment and max sizes for fullscreen */
-        c->height = *h;
-        return;
-    }
-
-    if ((c->size->flags & PResizeInc) && (c->size->height_inc))
-    {
-        h2 = (*h - c->size->min_height) / c->size->height_inc;
-        *h = c->size->min_height + (h2 * c->size->height_inc);
-    }
-    if (c->size->flags & PMaxSize)
-    {
-        if (*h > c->size->max_height)
+        if ((c->size->flags & PResizeInc) && (c->size->height_inc))
         {
-            *h = c->size->max_height;
+            h2 = (*h - c->size->min_height) / c->size->height_inc;
+            *h = c->size->min_height + (h2 * c->size->height_inc);
         }
+        if (c->size->flags & PMaxSize)
+        {
+            if (*h > c->size->max_height)
+            {
+                *h = c->size->max_height;
+            }
+        }
     }
+
     if (c->size->flags & PMinSize)
     {
         if (*h < c->size->min_height)
@@ -1782,6 +1778,7 @@
     clientGetNetState (c);
     clientGetNetWmType (c);
     clientGetInitialNetWmDesktop (c);
+    /* workarea will be updated when shown, no need to worry here */
     clientGetNetStruts (c);
 
     /* Fullscreen for older legacy apps */
@@ -3207,6 +3204,16 @@
         return;
     }
 
+    /* Revalidate client struts */
+    for (index = list_of_windows; index; index = g_list_next (index))
+    {
+        c = (Client *) index->data;
+        if (FLAG_TEST (c->flags, CLIENT_FLAG_HAS_STRUT))
+        {
+            clientValidateNetStrut (c);
+        }
+    }
+
     myScreenGrabPointer (screen_info, EnterWindowMask, None, myDisplayGetCurrentTime (screen_info->display_info));
     for (index = list_of_windows; index; index = g_list_next (index))
     {

Modified: xfwm4/trunk/src/client.h
===================================================================
--- xfwm4/trunk/src/client.h	2006-12-04 20:32:53 UTC (rev 24047)
+++ xfwm4/trunk/src/client.h	2006-12-05 20:00:06 UTC (rev 24048)
@@ -85,6 +85,8 @@
                                          UPDATE_MAXIMIZE | \
                                          UPDATE_CACHE)
 
+#define STRUTS_SIZE                     12
+
 #ifndef CLIENT_MIN_VISIBLE
 #define CLIENT_MIN_VISIBLE              15
 #endif
@@ -267,7 +269,7 @@
     int initial_layer;
     int ncmap;
     int button_pressed[BUTTON_COUNT];
-    int struts[12];
+    int struts[STRUTS_SIZE];
     gchar *name;
     Time user_time;
     unsigned long flags;

Modified: xfwm4/trunk/src/events.c
===================================================================
--- xfwm4/trunk/src/events.c	2006-12-04 20:32:53 UTC (rev 24047)
+++ xfwm4/trunk/src/events.c	2006-12-05 20:00:06 UTC (rev 24048)
@@ -1866,7 +1866,10 @@
                  (ev->atom == display_info->atoms[NET_WM_STRUT_PARTIAL]))
         {
             TRACE ("client \"%s\" (0x%lx) has received a net_wm_strut notify", c->name, c->window);
-            clientGetNetStruts (c);
+            if (clientGetNetStruts (c) && FLAG_TEST (c->xfwm_flags, XFWM_FLAG_VISIBLE))
+            {
+                workspaceUpdateArea (c->screen_info);
+            }
         }
         else if (ev->atom == display_info->atoms[WM_COLORMAP_WINDOWS])
         {

Modified: xfwm4/trunk/src/netwm.c
===================================================================
--- xfwm4/trunk/src/netwm.c	2006-12-04 20:32:53 UTC (rev 24047)
+++ xfwm4/trunk/src/netwm.c	2006-12-05 20:00:06 UTC (rev 24048)
@@ -922,24 +922,56 @@
     }
 }
 
-void
+gboolean
+clientValidateNetStrut (Client * c)
+{
+    ScreenInfo *screen_info;
+    gboolean valid;
+    int max_value;
+    int i;
+
+    g_return_val_if_fail (c != NULL, TRUE);
+    TRACE ("entering clientValidateNetStrut for \"%s\" (0x%lx)", c->name, c->window);
+    screen_info = c->screen_info;
+    max_value = MIN (screen_info->width, screen_info->height) / 4;
+    valid = TRUE;
+
+    for (i = 0; i < 4; i++)
+    {
+        if (c->struts[i] > max_value)
+        {
+           g_warning ("Strut value for application window 0x%lx changed from %d to %d", c->window, c->struts[i], max_value);
+           c->struts[i] = max_value;
+           valid = FALSE;
+        }
+    }
+
+    return valid;
+}
+
+gboolean
 clientGetNetStruts (Client * c)
 {
     ScreenInfo *screen_info;
     DisplayInfo *display_info;
+    unsigned long old_flags, new_flags;
+    int old_struts[STRUTS_SIZE];
     gulong *struts;
     int nitems;
     int i;
 
-    g_return_if_fail (c != NULL);
+    g_return_val_if_fail (c != NULL, FALSE);
     TRACE ("entering clientGetNetStruts for \"%s\" (0x%lx)", c->name, c->window);
 
     screen_info = c->screen_info;
     display_info = screen_info->display_info;
     struts = NULL;
 
-    for (i = 0; i < 12; i++)
+    /* Save old values */
+    old_flags = c->flags & (CLIENT_FLAG_HAS_STRUT | CLIENT_FLAG_HAS_STRUT_PARTIAL);
+    for (i = 0; i < STRUTS_SIZE; i++)
     {
+        old_struts[i] = c->struts[i];
         c->struts[i] = 0;
     }
     FLAG_UNSET (c->flags, CLIENT_FLAG_HAS_STRUT);
@@ -947,24 +979,32 @@
 
     if (getCardinalList (display_info, c->window, NET_WM_STRUT_PARTIAL, &struts, &nitems))
     {
-        if (nitems != 12)
+        if (nitems != STRUTS_SIZE)
         {
             if (struts)
             {
                 XFree (struts);
             }
-            return;
+            /* Restore old values */
+            if (old_flags)
+            {
+                FLAG_SET (c->flags, old_flags);
+                for (i = 0; i < STRUTS_SIZE; i++)
+                {
+                    c->struts[i] = old_struts[i];
+                }
+            }
+            return FALSE;
         }
 
         FLAG_SET (c->flags, CLIENT_FLAG_HAS_STRUT);
         FLAG_SET (c->flags, CLIENT_FLAG_HAS_STRUT_PARTIAL);
-        for (i = 0; i < 12; i++)
+        for (i = 0; i < STRUTS_SIZE; i++)
         {
             c->struts[i] = (int) struts[i];
         }
 
         XFree (struts);
-        workspaceUpdateArea (c->screen_info);
     }
     else if (getCardinalList (display_info, c->window, NET_WM_STRUT, &struts, &nitems))
     {
@@ -974,7 +1014,16 @@
             {
                 XFree (struts);
             }
-            return;
+            /* Restore old values */
+            if (old_flags)
+            {
+                FLAG_SET (c->flags, old_flags);
+                for (i = 0; i < STRUTS_SIZE; i++)
+                {
+                    c->struts[i] = old_struts[i];
+                }
+            }
+            return FALSE;
         }
 
         FLAG_SET (c->flags, CLIENT_FLAG_HAS_STRUT);
@@ -982,7 +1031,7 @@
         {
             c->struts[i] = (int) struts[i];
         }
-        for (i = 4; i < 12; i++)
+        for (i = 4; i < STRUTS_SIZE; i++)
         {
             c->struts[i] = 0;
         }
@@ -995,8 +1044,33 @@
             c->screen_info->height;
 
         XFree (struts);
-        workspaceUpdateArea (c->screen_info);
     }
+
+    if (FLAG_TEST (c->flags, CLIENT_FLAG_HAS_STRUT))
+    {
+        clientValidateNetStrut (c);
+    }
+
+    /* check for a change in struts flags */
+    new_flags = c->flags & (CLIENT_FLAG_HAS_STRUT | CLIENT_FLAG_HAS_STRUT_PARTIAL);
+    if (old_flags != new_flags)
+    {
+        return TRUE;
+    }
+
+    /* Flags haven't changed, check values */
+    if (new_flags)
+    {
+        for (i = 0; i < STRUTS_SIZE; i++)
+        {
+            if (old_struts[i] != c->struts[i])
+            {
+                return TRUE;
+            }
+        }
+    }
+
+    return FALSE;
 }
 
 void

Modified: xfwm4/trunk/src/netwm.h
===================================================================
--- xfwm4/trunk/src/netwm.h	2006-12-04 20:32:53 UTC (rev 24047)
+++ xfwm4/trunk/src/netwm.h	2006-12-05 20:00:06 UTC (rev 24048)
@@ -43,7 +43,8 @@
 void                     clientSetNetClientList                 (ScreenInfo *, 
                                                                  Atom, 
                                                                  GList *);
-void                     clientGetNetStruts                     (Client *);
+gboolean                 clientValidateNetStrut                 (Client *);
+gboolean                 clientGetNetStruts                     (Client *);
 void                     clientSetNetActions                    (Client *);
 void                     clientWindowType                       (Client *);
 void                     clientUpdateAboveState                 (Client *);



More information about the Xfce4-commits mailing list