summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Bazley <sambazley@fastmail.com>2020-10-25 15:30:50 +0000
committerSam Bazley <sambazley@fastmail.com>2020-10-27 18:29:21 +0000
commita91de44755539f8eafa760d8d6005cb206bad20e (patch)
tree445a5e08a84b72e9c2dd0c5bc82832df02458f3d
parentd955636da584d9f21a3cb875bbe0fcf0cd8aa9aa (diff)
downloadgtk+-a91de44755539f8eafa760d8d6005cb206bad20e.tar.gz
gdk: Fix parent relative background crash
When setting a window's background to ParentRelative on X11, the window depths must match to avoid a BadMatch error. Query the X server for the parent window rather that relying on the parent passed to gtk_window_new() to prevent crashes with reparented windows. Fixes: #3288
-rw-r--r--gdk/x11/gdkwindow-x11.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c
index 1fe7b90cd0..38ff91da6d 100644
--- a/gdk/x11/gdkwindow-x11.c
+++ b/gdk/x11/gdkwindow-x11.c
@@ -3025,12 +3025,29 @@ G_GNUC_END_IGNORE_DEPRECATIONS
if (pattern == parent_relative_pattern)
{
- GdkWindow *parent;
+ Window xroot, xparent, *xchildren;
+ guint nxchildren, xparent_depth;
+ XWindowAttributes xattrs;
+
+ if (!XQueryTree (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
+ &xroot, &xparent, &xchildren, &nxchildren))
+ {
+ XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),
+ GDK_WINDOW_XID (window), None);
+ return;
+ }
+
+ if (xchildren)
+ XFree (xchildren);
+
+ if (xparent) {
+ XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window), xparent, &xattrs);
+ xparent_depth = xattrs.depth;
+ }
/* X throws BadMatch if the parent has a different depth when
* using ParentRelative */
- parent = gdk_window_get_parent (window);
- if (parent != NULL && window->depth == parent->depth &&
+ if (xparent && window->depth == xparent_depth &&
cairo_pattern_status (pattern) == CAIRO_STATUS_SUCCESS)
{
XSetWindowBackgroundPixmap (GDK_WINDOW_XDISPLAY (window),