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
This commit is contained in:
Daniel Drake 2014-01-06 13:09:44 -06:00
parent bc9b923d5c
commit 69dfd07a7f

View File

@ -798,27 +798,11 @@ meta_window_new (MetaDisplay *display,
* creation, to reduce XSync() calls * creation, to reduce XSync() calls
*/ */
meta_error_trap_push_with_return (display); if (!XGetWindowAttributes (display->xdisplay, xwindow, &attrs))
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", meta_verbose ("Failed to get attributes for window 0x%lx\n",
xwindow); xwindow);
meta_error_trap_pop (display); goto error;
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;
} }
screen = NULL; screen = NULL;
@ -853,17 +837,13 @@ meta_window_new (MetaDisplay *display,
) )
) { ) {
meta_verbose ("Not managing our own windows\n"); meta_verbose ("Not managing our own windows\n");
meta_error_trap_pop (display); goto error;
meta_display_ungrab (display);
return NULL;
} }
if (maybe_filter_window (display, xwindow, must_be_viewable, &attrs)) if (maybe_filter_window (display, xwindow, must_be_viewable, &attrs))
{ {
meta_verbose ("Not managing filtered window\n"); meta_verbose ("Not managing filtered window\n");
meta_error_trap_pop (display); goto error;
meta_display_ungrab (display);
return NULL;
} }
meta_verbose ("must_be_viewable = %d attrs.map_state = %d (%s)\n", 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))) (state == IconicState || state == NormalState)))
{ {
meta_verbose ("Deciding not to manage unmapped or unviewable window 0x%lx\n", xwindow); meta_verbose ("Deciding not to manage unmapped or unviewable window 0x%lx\n", xwindow);
meta_error_trap_pop (display); goto error;
meta_display_ungrab (display);
return NULL;
} }
existing_wm_state = state; existing_wm_state = state;
@ -901,19 +879,16 @@ meta_window_new (MetaDisplay *display,
wm_state_to_string (existing_wm_state)); 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. * 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 * 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 * the process (such as a dummy desktop window). As we do not want this
* call failing to prevent the window from being managed -- wrap it in its * call failing to prevent the window from being managed, we call this
* own error trap (we use the _with_return() version here to ensure that * before creating the return-checked error trap.
* XSync() is done on the pop, otherwise the error will not get caught).
*/ */
meta_error_trap_push_with_return (display);
XAddToSaveSet (display->xdisplay, xwindow); XAddToSaveSet (display->xdisplay, xwindow);
meta_error_trap_pop_with_return (display);
meta_error_trap_push_with_return (display);
event_mask = PropertyChangeMask | ColormapChangeMask; event_mask = PropertyChangeMask | ColormapChangeMask;
if (attrs.override_redirect) 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", meta_verbose ("Window 0x%lx disappeared just as we tried to manage it\n",
xwindow); xwindow);
meta_error_trap_pop (display); goto error;
meta_display_ungrab (display);
return NULL;
} }
@ -1477,6 +1450,11 @@ meta_window_new (MetaDisplay *display,
g_signal_emit_by_name (window->display, "window-marked-urgent", window); g_signal_emit_by_name (window->display, "window-marked-urgent", window);
return 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 () */ /* This function should only be called from the end of meta_window_new_with_attrs () */