[mutter/gnome-3-10] meta_window_new: clean up error handling



commit e072295395458bfcea8d29916fe50997b8e4ef5e
Author: Daniel Drake <drake endlessm com>
Date:   Mon Jan 6 13:09:44 2014 -0600

    meta_window_new: clean up error handling
    
    The return code of XGetWindowAttributes() indicates whether an error
    was encountered or not. There is no need to specifically check the error
    trap.
    
    The trap around XAddToSaveSet() was superfluous. We have a global error
    trap to ignore any errors here, and there is no need to XSync() as GDK
    will later ignore the error asynchronously if one is raised.
    
    Also move common error exit path to an error label.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=721345

 src/core/window.c |   62 +++++++++++++++++-----------------------------------
 1 files changed, 20 insertions(+), 42 deletions(-)
---
diff --git a/src/core/window.c b/src/core/window.c
index ee7128d..4efd003 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -798,28 +798,12 @@ meta_window_new (MetaDisplay   *display,
                                    * creation, to reduce XSync() calls
                                    */
 
-  meta_error_trap_push_with_return (display);
-
-  if (XGetWindowAttributes (display->xdisplay, xwindow, &attrs))
-   {
-      if(meta_error_trap_pop_with_return (display) != Success)
-       {
-          meta_verbose ("Failed to get attributes for window 0x%lx\n",
-                        xwindow);
-          meta_error_trap_pop (display);
-          meta_display_ungrab (display);
-          return NULL;
-       }
-   }
-  else
-   {
-         meta_error_trap_pop_with_return (display);
-         meta_verbose ("Failed to get attributes for window 0x%lx\n",
-                        xwindow);
-         meta_error_trap_pop (display);
-         meta_display_ungrab (display);
-         return NULL;
-   }
+  if (!XGetWindowAttributes (display->xdisplay, xwindow, &attrs))
+    {
+      meta_verbose ("Failed to get attributes for window 0x%lx\n",
+                    xwindow);
+      goto error;
+    }
 
   screen = NULL;
   for (tmp = display->screens; tmp != NULL; tmp = tmp->next)
@@ -853,17 +837,13 @@ meta_window_new (MetaDisplay   *display,
       )
      ) {
     meta_verbose ("Not managing our own windows\n");
-    meta_error_trap_pop (display);
-    meta_display_ungrab (display);
-    return NULL;
+    goto error;
   }
 
   if (maybe_filter_window (display, xwindow, must_be_viewable, &attrs))
     {
       meta_verbose ("Not managing filtered window\n");
-      meta_error_trap_pop (display);
-      meta_display_ungrab (display);
-      return NULL;
+      goto error;
     }
 
   meta_verbose ("must_be_viewable = %d attrs.map_state = %d (%s)\n",
@@ -891,9 +871,7 @@ meta_window_new (MetaDisplay   *display,
             (state == IconicState || state == NormalState)))
         {
           meta_verbose ("Deciding not to manage unmapped or unviewable window 0x%lx\n", xwindow);
-          meta_error_trap_pop (display);
-          meta_display_ungrab (display);
-          return NULL;
+          goto error;
         }
 
       existing_wm_state = state;
@@ -901,19 +879,16 @@ meta_window_new (MetaDisplay   *display,
                     wm_state_to_string (existing_wm_state));
     }
 
-  meta_error_trap_push_with_return (display);
-
   /*
    * XAddToSaveSet can only be called on windows created by a different client.
    * with Mutter we want to be able to create manageable windows from within
-   * the process (such as a dummy desktop window), so we do not want this
-   * call failing to prevent the window from being managed -- wrap it in its
-   * own error trap (we use the _with_return() version here to ensure that
-   * XSync() is done on the pop, otherwise the error will not get caught).
+   * the process (such as a dummy desktop window). As we do not want this
+   * call failing to prevent the window from being managed, we call this
+   * before creating the return-checked error trap.
    */
-  meta_error_trap_push_with_return (display);
   XAddToSaveSet (display->xdisplay, xwindow);
-  meta_error_trap_pop_with_return (display);
+
+  meta_error_trap_push_with_return (display);
 
   event_mask = PropertyChangeMask | ColormapChangeMask;
   if (attrs.override_redirect)
@@ -965,9 +940,7 @@ meta_window_new (MetaDisplay   *display,
     {
       meta_verbose ("Window 0x%lx disappeared just as we tried to manage it\n",
                     xwindow);
-      meta_error_trap_pop (display);
-      meta_display_ungrab (display);
-      return NULL;
+      goto error;
     }
 
 
@@ -1474,6 +1447,11 @@ meta_window_new (MetaDisplay   *display,
     g_signal_emit_by_name (window->display, "window-marked-urgent", window);
 
   return window;
+
+error:
+  meta_error_trap_pop (display);
+  meta_display_ungrab (display);
+  return NULL;
 }
 
 /* This function should only be called from the end of meta_window_new_with_attrs () */


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