aboutsummaryrefslogtreecommitdiffstats
path: root/gtk-gui.c
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2012-09-21 22:09:48 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-21 20:55:33 -0700
commit882cb159a46d5d9dbd0a6b92bc587d39bd8b82bc (patch)
tree6af0d870a77c8171d6c122eafafd48d3aa3b5c07 /gtk-gui.c
parent2ddb50c5a54504a2196f5ec99e06be57cbf86b51 (diff)
downloadsubsurface-882cb159a46d5d9dbd0a6b92bc587d39bd8b82bc.tar.gz
Make sure windows behind forward dialogs are truly inactive
There are possible bugs when targeting GTK 2.24.10. When opening the "import XML files" file selector from the "import" dialog on Ubuntu 12.04, even with gtk_window_set_accept_focus() setting FALSE to the parent ("import"), it is still possible to click the title bar and buttons, causing actions. This can trigger undefined behaviour - e.g. opening multiple "import XML files" dialogs. While on Windows the situation is more acceptable, on Ubuntu it is also possible to click the [x] button on the title bar of the parent window, which will close the parent dialog _with_ the current forward dialog. Multiple proposed methods in the GTK documentation seem not to function as expected, such as: gtk_window_set_modal() and gtk_window_set_accept_focus(). Passing the correct parent on dialog creation doesn't seems to help either. The same problem occurs when selecting a default file from the preferences dialog. The proposed portable solution in this patch is to completely disable the background windows by hiding the titlebar (gtk_window_set_decorated), disabling child controls (gtk_widget_set_sensitive) and making the window "transient for" or putting it on top (gtk_window_set_transient_for). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'gtk-gui.c')
-rw-r--r--gtk-gui.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/gtk-gui.c b/gtk-gui.c
index 277c9343b..e15f72afb 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -485,7 +485,7 @@ static void event_toggle(GtkWidget *w, gpointer _data)
static void pick_default_file(GtkWidget *w, GtkButton *button)
{
- GtkWidget *fs_dialog, *preferences;
+ GtkWidget *fs_dialog, *parent;
const char *current_default;
char *current_def_file, *current_def_dir;
GtkFileFilter *filter;
@@ -497,8 +497,10 @@ static void pick_default_file(GtkWidget *w, GtkButton *button)
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
- preferences = gtk_widget_get_ancestor(w, GTK_TYPE_DIALOG);
- gtk_window_set_accept_focus(GTK_WINDOW(preferences), FALSE);
+ parent = gtk_widget_get_ancestor(w, GTK_TYPE_DIALOG);
+ gtk_widget_set_sensitive(parent, FALSE);
+ gtk_window_set_decorated(GTK_WINDOW(parent), FALSE);
+ gtk_window_set_transient_for(GTK_WINDOW(fs_dialog), GTK_WINDOW(parent));
current_default = subsurface_default_filename();
current_def_dir = g_path_get_dirname(current_default);
@@ -528,7 +530,9 @@ static void pick_default_file(GtkWidget *w, GtkButton *button)
free(current_def_file);
free((void *)current_default);
gtk_widget_destroy(fs_dialog);
- gtk_window_set_accept_focus(GTK_WINDOW(preferences), TRUE);
+
+ gtk_widget_set_sensitive(parent, TRUE);
+ gtk_window_set_decorated(GTK_WINDOW(parent), TRUE);
}
static void preferences_dialog(GtkWidget *w, gpointer data)
@@ -1305,7 +1309,7 @@ static GtkEntry *dive_computer_device(GtkWidget *vbox)
static void pick_import_files(GtkWidget *w, GSList **filelist)
{
- GtkWidget *fs_dialog, *import;
+ GtkWidget *fs_dialog, *parent;
const char *current_default;
char *current_def_dir;
GtkFileFilter *filter;
@@ -1318,8 +1322,10 @@ static void pick_import_files(GtkWidget *w, GSList **filelist)
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
- import = gtk_widget_get_ancestor(w, GTK_TYPE_DIALOG);
- gtk_window_set_accept_focus(GTK_WINDOW(import), FALSE);
+ parent = gtk_widget_get_ancestor(w, GTK_TYPE_DIALOG);
+ gtk_widget_set_sensitive(parent, FALSE);
+ gtk_window_set_decorated(GTK_WINDOW(parent), FALSE);
+ gtk_window_set_transient_for(GTK_WINDOW(fs_dialog), GTK_WINDOW(parent));
/* I'm not sure what the best default path should be... */
if (existing_filename) {
@@ -1344,10 +1350,13 @@ static void pick_import_files(GtkWidget *w, GSList **filelist)
*filelist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(fs_dialog));
free(current_def_dir);
gtk_widget_destroy(fs_dialog);
- gtk_window_set_accept_focus(GTK_WINDOW(import), TRUE);
+
+ gtk_widget_set_sensitive(parent, TRUE);
+ gtk_window_set_decorated(GTK_WINDOW(parent), TRUE);
+
/* if we selected one or more files, pretent that we clicked OK in the import dialog */
if (*filelist != NULL)
- gtk_dialog_response(GTK_DIALOG(import), GTK_RESPONSE_ACCEPT);
+ gtk_dialog_response(GTK_DIALOG(parent), GTK_RESPONSE_ACCEPT);
}
static void xml_file_selector(GtkWidget *vbox, GtkWidget *main_dialog, GSList **list)