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,16 +219,25 @@ 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);
client_window,
gdk_x11_get_xatom_by_name_for_display (display, if (XGetWindowProperty (gdk_x11_display_get_xdisplay (display),
"_NET_WM_NAME"), client_window,
0, G_MAXLONG, False, gdk_x11_get_xatom_by_name_for_display (display,
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"),
"UTF8_STRING"), 0, G_MAXLONG, False,
&type, &format, gdk_x11_get_xatom_by_name_for_display (display,
&nitems, &bytes_after, "UTF8_STRING"),
(unsigned char **) &title); &type, &format,
&nitems, &bytes_after,
(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,15 +256,24 @@ 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);
client_window,
gdk_x11_get_xatom_by_name_for_display (display, if (XGetWindowProperty (gdk_x11_display_get_xdisplay (display),
"_MOTIF_WM_HINTS"), client_window,
0, sizeof (MotifWmHints) / sizeof (long), gdk_x11_get_xatom_by_name_for_display (display,
False, AnyPropertyType, "_MOTIF_WM_HINTS"),
&type, &format, 0, sizeof (MotifWmHints) / sizeof (long),
&nitems, &bytes_after, False, AnyPropertyType,
(unsigned char **) &mwm_hints); &type, &format,
&nitems, &bytes_after,
(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);
client_window,
&size_hints, if (XGetWMNormalHints (gdk_x11_display_get_xdisplay (display),
&nitems); client_window,
&size_hints,
&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)
XIUndefineCursor (xdisplay, crossing->deviceid, xwindow); {
gdk_x11_display_error_trap_push (display);
XIUndefineCursor (xdisplay, crossing->deviceid, xwindow);
gdk_x11_display_error_trap_pop_ignored (display);
}
} }
} }