Index: chrome/browser/ui/libgtk2ui/gtk2_util.cc |
diff --git a/chrome/browser/ui/libgtk2ui/gtk2_util.cc b/chrome/browser/ui/libgtk2ui/gtk2_util.cc |
index d057a2ee86e7d1d0545625325f59c695889ad660..a2c1e6c801a7e1ff6a15e13b446c17ab090d7aa9 100644 |
--- a/chrome/browser/ui/libgtk2ui/gtk2_util.cc |
+++ b/chrome/browser/ui/libgtk2ui/gtk2_util.cc |
@@ -4,11 +4,15 @@ |
#include "chrome/browser/ui/libgtk2ui/gtk2_util.h" |
+#include <gdk/gdk.h> |
+#include <gdk/gdkx.h> |
#include <gtk/gtk.h> |
#include "base/command_line.h" |
#include "base/environment.h" |
#include "base/memory/scoped_ptr.h" |
+#include "ui/aura/window.h" |
+#include "ui/aura/window_tree_host.h" |
#include "ui/base/accelerators/accelerator.h" |
#include "ui/events/event_constants.h" |
#include "ui/events/keycodes/keyboard_code_conversion_x.h" |
@@ -16,6 +20,8 @@ |
namespace { |
+const char kAuraTransientParent[] = "aura-transient-parent"; |
+ |
void CommonInitFromCommandLine(const CommandLine& command_line, |
void (*init_func)(gint*, gchar***)) { |
const std::vector<std::string>& args = command_line.argv(); |
@@ -97,4 +103,30 @@ int EventFlagsFromGdkState(guint state) { |
return flags; |
} |
+// Set |dialog| as transient for |parent|, which will keep it on top and center |
+// it above |parent|. |
+void SetGtkTransientForAura(GtkWidget* dialog, aura::Window* parent) { |
+ gtk_widget_realize(dialog); |
+ GdkWindow* gdk_window = gtk_widget_get_window(dialog); |
+ |
+ // TODO(erg): Check to make sure we're using X11 if wayland or some other |
+ // display server ever happens. Otherwise, this will crash. |
+ XSetTransientForHint(GDK_WINDOW_XDISPLAY(gdk_window), |
+ GDK_WINDOW_XID(gdk_window), |
+ parent->GetHost()->GetAcceleratedWidget()); |
+ |
+ // We also set the |parent| as a property of |dialog|, so that we can unlink |
+ // the two later. |
+ g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, parent); |
+} |
+ |
+aura::Window* GetAuraTransientParent(GtkWidget* dialog) { |
+ return reinterpret_cast<aura::Window*>( |
+ g_object_get_data(G_OBJECT(dialog), kAuraTransientParent)); |
+} |
+ |
+void ClearAuraTransientParent(GtkWidget* dialog) { |
+ g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, NULL); |
+} |
+ |
} // namespace libgtk2ui |