x11: Handle parent being NULL when creating windows

We want to make toplevels have a NULL parent, this
gets us ready for it.
This commit is contained in:
Matthias Clasen 2017-11-05 19:25:22 -05:00
parent c16a0bd9b7
commit 119c433882

View File

@ -789,15 +789,14 @@ ensure_sync_counter (GdkWindow *window)
} }
static void static void
setup_toplevel_window (GdkWindow *window, setup_toplevel_window (GdkWindow *window,
GdkWindow *parent) GdkX11Screen *x11_screen)
{ {
GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window); GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl); GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
GdkDisplay *display = gdk_window_get_display (window); GdkDisplay *display = gdk_window_get_display (window);
Display *xdisplay = GDK_WINDOW_XDISPLAY (window); Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
XID xid = GDK_WINDOW_XID (window); XID xid = GDK_WINDOW_XID (window);
GdkX11Screen *x11_screen = GDK_X11_SCREEN (GDK_WINDOW_SCREEN (parent));
XSizeHints size_hints; XSizeHints size_hints;
long pid; long pid;
Window leader_window; Window leader_window;
@ -919,9 +918,15 @@ _gdk_x11_display_create_window_impl (GdkDisplay *display,
unsigned int class; unsigned int class;
int depth; int depth;
int abs_x;
int abs_y;
display_x11 = GDK_X11_DISPLAY (display); display_x11 = GDK_X11_DISPLAY (display);
xparent = GDK_WINDOW_XID (real_parent);
x11_screen = GDK_X11_SCREEN (display_x11->screen); x11_screen = GDK_X11_SCREEN (display_x11->screen);
if (real_parent)
xparent = GDK_WINDOW_XID (real_parent);
else
xparent = GDK_SCREEN_XROOTWIN (x11_screen);
impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL); impl = g_object_new (GDK_TYPE_WINDOW_IMPL_X11, NULL);
window->impl = GDK_WINDOW_IMPL (impl); window->impl = GDK_WINDOW_IMPL (impl);
@ -941,7 +946,7 @@ _gdk_x11_display_create_window_impl (GdkDisplay *display,
{ {
case GDK_WINDOW_TOPLEVEL: case GDK_WINDOW_TOPLEVEL:
case GDK_WINDOW_TEMP: case GDK_WINDOW_TEMP:
if (GDK_WINDOW_TYPE (window->parent) != GDK_WINDOW_ROOT) if (window->parent && GDK_WINDOW_TYPE (window->parent) != GDK_WINDOW_ROOT)
{ {
/* The common code warns for this case */ /* The common code warns for this case */
xparent = GDK_SCREEN_XROOTWIN (x11_screen); xparent = GDK_SCREEN_XROOTWIN (x11_screen);
@ -1010,9 +1015,20 @@ _gdk_x11_display_create_window_impl (GdkDisplay *display,
impl->unscaled_width = window->width * impl->window_scale; impl->unscaled_width = window->width * impl->window_scale;
impl->unscaled_height = window->height * impl->window_scale; impl->unscaled_height = window->height * impl->window_scale;
if (window->parent)
{
abs_x = window->parent->abs_x;
abs_y = window->parent->abs_y;
}
else
{
abs_x = 0;
abs_y = 0;
}
impl->xid = XCreateWindow (xdisplay, xparent, impl->xid = XCreateWindow (xdisplay, xparent,
(window->x + window->parent->abs_x) * impl->window_scale, (window->x + abs_x) * impl->window_scale,
(window->y + window->parent->abs_y) * impl->window_scale, (window->y + abs_y) * impl->window_scale,
window->width * impl->window_scale, window->height * impl->window_scale, window->width * impl->window_scale, window->height * impl->window_scale,
0, depth, class, xvisual, 0, depth, class, xvisual,
xattributes_mask, &xattributes); xattributes_mask, &xattributes);
@ -1032,7 +1048,7 @@ _gdk_x11_display_create_window_impl (GdkDisplay *display,
XSetClassHint (xdisplay, impl->xid, class_hint); XSetClassHint (xdisplay, impl->xid, class_hint);
XFree (class_hint); XFree (class_hint);
setup_toplevel_window (window, window->parent); setup_toplevel_window (window, x11_screen);
break; break;
case GDK_WINDOW_CHILD: case GDK_WINDOW_CHILD: