зеркало из https://github.com/electron/electron.git
linux: Fix setting parent window for file dialogs.
This commit is contained in:
Родитель
b3bccd2e1e
Коммит
4609a8d2be
|
@ -4,16 +4,41 @@
|
|||
|
||||
#include "atom/browser/ui/file_dialog.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/file_util.h"
|
||||
#include "chrome/browser/ui/gtk/gtk_util.h"
|
||||
#include "ui/base/gtk/gtk_signal.h"
|
||||
#include "chrome/browser/ui/libgtk2ui/gtk2_signal.h"
|
||||
#include "ui/aura/window.h"
|
||||
#include "ui/aura/window_tree_host.h"
|
||||
|
||||
namespace file_dialog {
|
||||
|
||||
namespace {
|
||||
|
||||
const char kAuraTransientParent[] = "aura-transient-parent";
|
||||
|
||||
void SetGtkTransientForAura(GtkWidget* dialog, aura::Window* parent) {
|
||||
if (!parent || !parent->GetHost())
|
||||
return;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
class FileChooserDialog {
|
||||
public:
|
||||
FileChooserDialog(GtkFileChooserAction action,
|
||||
|
@ -27,14 +52,17 @@ class FileChooserDialog {
|
|||
else if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
|
||||
confirm_text = GTK_STOCK_OPEN;
|
||||
|
||||
GtkWindow* window = NULL;
|
||||
dialog_ = gtk_file_chooser_dialog_new(
|
||||
title.c_str(),
|
||||
window,
|
||||
NULL,
|
||||
action,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
confirm_text, GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
if (parent_window) {
|
||||
gfx::NativeWindow window = parent_window->GetNativeWindow();
|
||||
SetGtkTransientForAura(dialog_, window);
|
||||
}
|
||||
|
||||
if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog_),
|
||||
|
@ -42,10 +70,6 @@ class FileChooserDialog {
|
|||
if (action != GTK_FILE_CHOOSER_ACTION_OPEN)
|
||||
gtk_file_chooser_set_create_folders(GTK_FILE_CHOOSER(dialog_), TRUE);
|
||||
|
||||
// Set window-to-parent modality by adding the dialog to the same window
|
||||
// group as the parent.
|
||||
gtk_window_group_add_window(gtk_window_get_group(window),
|
||||
GTK_WINDOW(dialog_));
|
||||
gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE);
|
||||
|
||||
if (!default_path.empty()) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit c4426492f5d0321e4c824a0443e6a261fc985ac7
|
||||
Subproject commit 154ebc4161c92037f7b1b3804784bb55ce090020
|
Загрузка…
Ссылка в новой задаче