1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/base/gtk/gtk_windowing.h"
9 #include "base/logging.h"
10 #include "ui/base/x/x11_util.h"
11 #include "ui/gfx/gtk_compat.h"
15 void StackPopupWindow(GtkWidget
* popup
, GtkWidget
* toplevel
) {
16 DCHECK(GTK_IS_WINDOW(popup
) && gtk_widget_is_toplevel(popup
) &&
17 gtk_widget_get_realized(popup
));
18 DCHECK(GTK_IS_WINDOW(toplevel
) && gtk_widget_is_toplevel(toplevel
) &&
19 gtk_widget_get_realized(toplevel
));
21 // Stack the |popup| window directly above the |toplevel| window.
22 // The popup window is a direct child of the root window, so we need to
23 // find a similar ancestor for the toplevel window (which might have been
24 // reparented by a window manager). We grab the server while we're doing
25 // this -- otherwise, we'll get an error if the window manager reparents the
26 // toplevel window right after we call GetHighestAncestorWindow().
27 gdk_x11_display_grab(gtk_widget_get_display(toplevel
));
28 XID toplevel_window_base
= ui::GetHighestAncestorWindow(
29 ui::GetX11WindowFromGtkWidget(toplevel
),
30 ui::GetX11RootWindow());
31 if (toplevel_window_base
) {
32 XID window_xid
= ui::GetX11WindowFromGtkWidget(popup
);
33 XID window_parent
= ui::GetParentWindow(window_xid
);
34 if (window_parent
== ui::GetX11RootWindow()) {
35 ui::RestackWindow(window_xid
, toplevel_window_base
, true);
37 // The window manager shouldn't reparent override-redirect windows.
38 DLOG(ERROR
) << "override-redirect window " << window_xid
39 << "'s parent is " << window_parent
40 << ", rather than root window "
41 << ui::GetX11RootWindow();
44 gdk_x11_display_ungrab(gtk_widget_get_display(toplevel
));