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