linux: Disable parent window when showing modal dialogs (#6160)

This commit is contained in:
Cheng Zhao 2016-06-21 08:54:55 +00:00 committed by GitHub
parent 00f5fa440d
commit 816b2ea8f2
2 changed files with 20 additions and 13 deletions

View file

@ -5,7 +5,7 @@
#include "atom/browser/ui/message_box.h"
#include "atom/browser/browser.h"
#include "atom/browser/native_window.h"
#include "atom/browser/native_window_views.h"
#include "base/callback.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@ -36,7 +36,8 @@ class GtkMessageBox {
const std::string& detail,
const gfx::ImageSkia& icon)
: dialog_scope_(parent_window),
cancel_id_(cancel_id) {
cancel_id_(cancel_id),
parent_(static_cast<NativeWindowViews*>(parent_window)) {
// Create dialog.
dialog_ = gtk_message_dialog_new(
nullptr, // parent
@ -75,14 +76,17 @@ class GtkMessageBox {
}
// Parent window.
if (parent_window) {
gfx::NativeWindow window = parent_window->GetNativeWindow();
libgtk2ui::SetGtkTransientForAura(dialog_, window);
if (parent_) {
parent_->SetEnabled(false);
libgtk2ui::SetGtkTransientForAura(dialog_, parent_->GetNativeWindow());
gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE);
}
}
~GtkMessageBox() {
gtk_widget_destroy(dialog_);
if (parent_)
parent_->SetEnabled(true);
}
GtkMessageType GetMessageType(MessageBoxType type) {
@ -123,7 +127,6 @@ class GtkMessageBox {
}
int RunSynchronous() {
gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE);
Show();
int response = gtk_dialog_run(GTK_DIALOG(dialog_));
if (response < 0)
@ -149,6 +152,7 @@ class GtkMessageBox {
// The id to return when the dialog is closed without pressing buttons.
int cancel_id_;
NativeWindowViews* parent_;
GtkWidget* dialog_;
MessageBoxCallback callback_;