frames: Push error traps around various X11 calls

It is a possibility that these requests result in an error, so handle
the possible fallout.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2745>
This commit is contained in:
Carlos Garnacho 2022-12-06 15:29:41 +01:00
parent 5816268c1d
commit c7b3d8c607
2 changed files with 68 additions and 24 deletions

View File

@ -179,6 +179,9 @@ meta_frame_update_extents (MetaFrame *frame,
data[3] = border.bottom; data[3] = border.bottom;
xframe = gdk_x11_surface_get_xid (surface); xframe = gdk_x11_surface_get_xid (surface);
gdk_x11_display_error_trap_push (display);
XChangeProperty (gdk_x11_display_get_xdisplay (display), XChangeProperty (gdk_x11_display_get_xdisplay (display),
xframe, xframe,
gdk_x11_get_xatom_by_name_for_display (display, "_MUTTER_FRAME_EXTENTS"), gdk_x11_get_xatom_by_name_for_display (display, "_MUTTER_FRAME_EXTENTS"),
@ -186,6 +189,8 @@ meta_frame_update_extents (MetaFrame *frame,
32, 32,
PropModeReplace, PropModeReplace,
(guchar *) &data, 4); (guchar *) &data, 4);
gdk_x11_display_error_trap_pop_ignored (display);
} }
static void static void
@ -214,7 +219,9 @@ frame_sync_title (GtkWindow *frame,
display = gtk_widget_get_display (GTK_WIDGET (frame)); display = gtk_widget_get_display (GTK_WIDGET (frame));
XGetWindowProperty (gdk_x11_display_get_xdisplay (display), gdk_x11_display_error_trap_push (display);
if (XGetWindowProperty (gdk_x11_display_get_xdisplay (display),
client_window, client_window,
gdk_x11_get_xatom_by_name_for_display (display, gdk_x11_get_xatom_by_name_for_display (display,
"_NET_WM_NAME"), "_NET_WM_NAME"),
@ -223,7 +230,14 @@ frame_sync_title (GtkWindow *frame,
"UTF8_STRING"), "UTF8_STRING"),
&type, &format, &type, &format,
&nitems, &bytes_after, &nitems, &bytes_after,
(unsigned char **) &title); (unsigned char **) &title) != Success)
{
gdk_x11_display_error_trap_pop_ignored (display);
return;
}
if (gdk_x11_display_error_trap_pop (display))
return;
gtk_window_set_title (frame, title); gtk_window_set_title (frame, title);
g_free (title); g_free (title);
@ -242,7 +256,9 @@ frame_sync_motif_wm_hints (GtkWindow *frame,
display = gtk_widget_get_display (GTK_WIDGET (frame)); display = gtk_widget_get_display (GTK_WIDGET (frame));
XGetWindowProperty (gdk_x11_display_get_xdisplay (display), gdk_x11_display_error_trap_push (display);
if (XGetWindowProperty (gdk_x11_display_get_xdisplay (display),
client_window, client_window,
gdk_x11_get_xatom_by_name_for_display (display, gdk_x11_get_xatom_by_name_for_display (display,
"_MOTIF_WM_HINTS"), "_MOTIF_WM_HINTS"),
@ -250,7 +266,14 @@ frame_sync_motif_wm_hints (GtkWindow *frame,
False, AnyPropertyType, False, AnyPropertyType,
&type, &format, &type, &format,
&nitems, &bytes_after, &nitems, &bytes_after,
(unsigned char **) &mwm_hints); (unsigned char **) &mwm_hints) != Success)
{
gdk_x11_display_error_trap_pop_ignored (display);
return;
}
if (gdk_x11_display_error_trap_pop (display))
return;
if (mwm_hints && if (mwm_hints &&
(mwm_hints->flags & MWM_HINTS_FUNCTIONS) != 0) (mwm_hints->flags & MWM_HINTS_FUNCTIONS) != 0)
@ -276,10 +299,19 @@ frame_sync_wm_normal_hints (GtkWindow *frame,
display = gtk_widget_get_display (GTK_WIDGET (frame)); display = gtk_widget_get_display (GTK_WIDGET (frame));
XGetWMNormalHints (gdk_x11_display_get_xdisplay (display), gdk_x11_display_error_trap_push (display);
if (XGetWMNormalHints (gdk_x11_display_get_xdisplay (display),
client_window, client_window,
&size_hints, &size_hints,
&nitems); &nitems) != Success)
{
gdk_x11_display_error_trap_pop_ignored (display);
return;
}
if (gdk_x11_display_error_trap_pop (display))
return;
if (nitems > 0) if (nitems > 0)
{ {

View File

@ -132,6 +132,8 @@ set_up_frame (MetaWindowTracker *window_tracker,
surface = gtk_native_get_surface (GTK_NATIVE (frame)); surface = gtk_native_get_surface (GTK_NATIVE (frame));
xframe = gdk_x11_surface_get_xid (surface); xframe = gdk_x11_surface_get_xid (surface);
gdk_x11_display_error_trap_push (display);
XAddToSaveSet (xdisplay, xwindow); XAddToSaveSet (xdisplay, xwindow);
data[0] = xwindow; data[0] = xwindow;
@ -143,6 +145,12 @@ set_up_frame (MetaWindowTracker *window_tracker,
PropModeReplace, PropModeReplace,
(guchar *) data, 1); (guchar *) data, 1);
if (gdk_x11_display_error_trap_pop (display))
{
gtk_window_destroy (GTK_WINDOW (frame));
return;
}
g_hash_table_insert (window_tracker->frames, g_hash_table_insert (window_tracker->frames,
GUINT_TO_POINTER (xframe), frame); GUINT_TO_POINTER (xframe), frame);
g_hash_table_insert (window_tracker->client_windows, g_hash_table_insert (window_tracker->client_windows,
@ -285,7 +293,11 @@ on_xevent (GdkDisplay *display,
* its default. * its default.
*/ */
if (frame && crossing->detail == XINotifyInferior) if (frame && crossing->detail == XINotifyInferior)
{
gdk_x11_display_error_trap_push (display);
XIUndefineCursor (xdisplay, crossing->deviceid, xwindow); XIUndefineCursor (xdisplay, crossing->deviceid, xwindow);
gdk_x11_display_error_trap_pop_ignored (display);
}
} }
} }