[mutter] Improve handling of errors when calling CompositeNameWindowPixmap



commit 63b1d6642cf1eb7a1a2a6c6ec4b18fed279384a8
Author: Owen W. Taylor <otaylor redhat com>
Date:   Sat Nov 22 10:27:00 2008 -0500

    Improve handling of errors when calling CompositeNameWindowPixmap
    
    To guard against CompositeNameWindowPixmap failing, just use an
    error trap. Previous code used:
    
     GrabServer/GetWindowAttributes/CompositeNameWindowPixmap/UngrabServer
    
    To prevent BadMatch errors from !viewable, but didn't check the
    return value of GetWindowAttributes and didn't check if an error
    occured during the error trap. This way is more correct and more
    efficient.
    
    http://bugzilla.gnome.org/show_bug.cgi?id=580023
---
 src/compositor/mutter/compositor-mutter.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/compositor/mutter/compositor-mutter.c b/src/compositor/mutter/compositor-mutter.c
index 5981f0c..4824395 100644
--- a/src/compositor/mutter/compositor-mutter.c
+++ b/src/compositor/mutter/compositor-mutter.c
@@ -1474,23 +1474,22 @@ repair_win (MutterWindow *cw)
   if (priv->back_pixmap == None)
     {
       gint pxm_width, pxm_height;
-      XWindowAttributes attr;
 
       meta_error_trap_push (display);
 
-      XGrabServer (xdisplay);
+      priv->back_pixmap = XCompositeNameWindowPixmap (xdisplay, xwindow);
 
-      XGetWindowAttributes (xdisplay, xwindow, &attr);
-
-      if (attr.map_state == IsViewable)
-	priv->back_pixmap = XCompositeNameWindowPixmap (xdisplay, xwindow);
-      else
-	{
-	  priv->back_pixmap = None;
-	}
-
-      XUngrabServer (xdisplay);
-      meta_error_trap_pop (display, FALSE);
+      if (meta_error_trap_pop_with_return (display, FALSE) != Success)
+        {
+          /* Probably a BadMatch if the window isn't viewable; we could
+           * GrabServer/GetWindowAttributes/NameWindowPixmap/UngrabServer/Sync
+           * to avoid this, but there's no reason to take two round trips
+           * when one will do. (We need that Sync if we want to handle failures
+           * for any reason other than !viewable. That's unlikely, but maybe
+           * we'll BadAlloc or something.)
+           */
+          priv->back_pixmap = None;
+        }
 
       if (priv->back_pixmap == None)
         {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]