summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2022-04-16 18:41:34 -0500
committerPatrick Griffis <tingping@tingping.se>2022-04-16 18:41:34 -0500
commit13b6a40b9c3d1f2215ff87cdaff9e38a4020ee92 (patch)
tree29b3d01d4be5596c2aa2c5321ca21bbf3557ae10
parentdd167b4c8393677f465c03d66b438d519c43fb87 (diff)
Change preferences sub-dialogs to be modal
This solves the issue where the parent dialog is closed and then
the child dialog is used.

This is however only a partial fix:

- Many other dialogs throughout the codebase do not currently have
  parent windows and need to be refactored.

- Not all window managers respect modal so users can still trigger
  bugs. We can be more defensive against this but it requires more
  refactoring.

Closes #2686
-rw-r--r--src/common/fe.h1
-rw-r--r--src/fe-gtk/chanlist.c2
-rw-r--r--src/fe-gtk/dccgui.c2
-rw-r--r--src/fe-gtk/fe-gtk.c4
-rw-r--r--src/fe-gtk/gtkutil.c12
-rw-r--r--src/fe-gtk/gtkutil.h2
-rw-r--r--src/fe-gtk/menu.c2
-rw-r--r--src/fe-gtk/plugingui.c2
-rw-r--r--src/fe-gtk/rawlog.c2
-rw-r--r--src/fe-gtk/setup.c18
-rw-r--r--src/fe-gtk/textgui.c4
-rw-r--r--src/fe-gtk/urlgrab.c2
12 files changed, 34 insertions, 19 deletions
diff --git a/src/common/fe.h b/src/common/fe.h
index 9da4e230..b8a6279e 100644
--- a/src/common/fe.h
+++ b/src/common/fe.h
@@ -141,6 +141,7 @@ void fe_get_int (char *prompt, int def, void *callback, void *ud);
 #define FRF_NOASKOVERWRITE 32	/* don't ask to overwrite existing files */
 #define FRF_EXTENSIONS 64		/* specify file extensions to be displayed */
 #define FRF_MIMETYPES 128		/* specify file mimetypes to be displayed */
+#define FRF_MODAL 256           /* dialog should be modal to parent */
 void fe_get_file (const char *title, char *initial,
 				 void (*callback) (void *userdata, char *file), void *userdata,
 				 int flags);
diff --git a/src/fe-gtk/chanlist.c b/src/fe-gtk/chanlist.c
index aeddc417..abf62843 100644
--- a/src/fe-gtk/chanlist.c
+++ b/src/fe-gtk/chanlist.c
@@ -512,7 +512,7 @@ chanlist_save (GtkWidget * wid, server *serv)
 	GtkTreeModel *model = GET_MODEL (serv);
 
 	if (gtk_tree_model_get_iter_first (model, &iter))
-		gtkutil_file_req (_("Select an output filename"), chanlist_filereq_done,
+		gtkutil_file_req (NULL, _("Select an output filename"), chanlist_filereq_done,
 								serv, NULL, NULL, FRF_WRITE);
 }
 
diff --git a/src/fe-gtk/dccgui.c b/src/fe-gtk/dccgui.c
index 5b8dbac9..728698e3 100644
--- a/src/fe-gtk/dccgui.c
+++ b/src/fe-gtk/dccgui.c
@@ -146,7 +146,7 @@ fe_dcc_send_filereq (struct session *sess, char *nick, int maxcps, int passive)
 	mdc->maxcps = maxcps;
 	mdc->passive = passive;
 
-	gtkutil_file_req (tbuf, dcc_send_filereq_file, mdc, prefs.hex_dcc_dir, NULL, FRF_MULTIPLE|FRF_FILTERISINITIAL);
+	gtkutil_file_req (NULL, tbuf, dcc_send_filereq_file, mdc, prefs.hex_dcc_dir, NULL, FRF_MULTIPLE|FRF_FILTERISINITIAL);
 
 	g_free (tbuf);
 }
diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c
index 7eca0710..38e6172d 100644
--- a/src/fe-gtk/fe-gtk.c
+++ b/src/fe-gtk/fe-gtk.c
@@ -903,7 +903,7 @@ fe_confirm (const char *message, void (*yesproc)(void *), void (*noproc)(void *)
 	if (dcc->file)
 	{
 		char *filepath = g_build_filename (prefs.hex_dcc_dir, dcc->file, NULL);
-		gtkutil_file_req (message, dcc_saveas_cb, ud, filepath, NULL,
+		gtkutil_file_req (NULL, message, dcc_saveas_cb, ud, filepath, NULL,
 								FRF_WRITE|FRF_NOASKOVERWRITE|FRF_FILTERISINITIAL);
 		g_free (filepath);
 	}
@@ -1216,7 +1216,7 @@ fe_get_file (const char *title, char *initial,
 {
 	/* OK: Call callback once per file, then once more with file=NULL. */
 	/* CANCEL: Call callback once with file=NULL. */
-	gtkutil_file_req (title, callback, userdata, initial, NULL, flags | FRF_FILTERISINITIAL);
+	gtkutil_file_req (NULL, title, callback, userdata, initial, NULL, flags | FRF_FILTERISINITIAL);
 }
 
 void
diff --git a/src/fe-gtk/gtkutil.c b/src/fe-gtk/gtkutil.c
index 674ad4fc..98a971f9 100644
--- a/src/fe-gtk/gtkutil.c
+++ b/src/fe-gtk/gtkutil.c
@@ -190,7 +190,7 @@ gtkutil_file_req_response (GtkWidget *dialog, gint res, struct file_req *freq)
 }
 
 void
-gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter, char *extensions,
+gtkutil_file_req (GtkWindow *parent, const char *title, void *callback, void *userdata, char *filter, char *extensions,
 						int flags)
 {
 	struct file_req *freq;
@@ -269,6 +269,16 @@ gtkutil_file_req (const char *title, void *callback, void *userdata, char *filte
 							G_CALLBACK (gtkutil_file_req_response), freq);
 	g_signal_connect (G_OBJECT (dialog), "destroy",
 						   G_CALLBACK (gtkutil_file_req_destroy), (gpointer) freq);
+
+	if (parent)
+		gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+
+	if (flags & FRF_MODAL)
+	{
+		g_assert (parent);
+		gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+	}
+
 	gtk_widget_show (dialog);
 }
 
diff --git a/src/fe-gtk/gtkutil.h b/src/fe-gtk/gtkutil.h
index 0aa36439..c6e380e9 100644
--- a/src/fe-gtk/gtkutil.h
+++ b/src/fe-gtk/gtkutil.h
@@ -25,7 +25,7 @@
 
 typedef void (*filereqcallback) (void *, char *file);
 
-void gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter, char *extensions, int flags);
+void gtkutil_file_req (GtkWindow *parent, const char *title, void *callback, void *userdata, char *filter, char *extensions, int flags);
 void gtkutil_destroy (GtkWidget * igad, GtkWidget * dgad);
 void gtkutil_destroy_on_esc (GtkWidget *win);
 GtkWidget *gtkutil_button (GtkWidget *box, char *stock, char *tip, void *callback,
diff --git a/src/fe-gtk/menu.c b/src/fe-gtk/menu.c
index 233715e5..76bc3906 100644
--- a/src/fe-gtk/menu.c
+++ b/src/fe-gtk/menu.c
@@ -1362,7 +1362,7 @@ savebuffer_req_done (session *sess, char *file)
 static void
 menu_savebuffer (GtkWidget * wid, gpointer none)
 {
-	gtkutil_file_req (_("Select an output filename"), savebuffer_req_done,
+	gtkutil_file_req (NULL, _("Select an output filename"), savebuffer_req_done,
 							current_sess, NULL, NULL, FRF_WRITE);
 }
 
diff --git a/src/fe-gtk/plugingui.c b/src/fe-gtk/plugingui.c
index 83bb745f..c40ac304 100644
--- a/src/fe-gtk/plugingui.c
+++ b/src/fe-gtk/plugingui.c
@@ -161,7 +161,7 @@ plugingui_load (void)
 {
 	char *sub_dir = g_build_filename (get_xdir(), "addons", NULL);
 
-	gtkutil_file_req (_("Select a Plugin or Script to load"), plugingui_load_cb, current_sess,
+	gtkutil_file_req (NULL, _("Select a Plugin or Script to load"), plugingui_load_cb, current_sess,
 							sub_dir, "*."PLUGIN_SUFFIX";*.lua;*.pl;*.py;*.tcl;*.js", FRF_FILTERISINITIAL|FRF_EXTENSIONS);
 
 	g_free (sub_dir);
diff --git a/src/fe-gtk/rawlog.c b/src/fe-gtk/rawlog.c
index 52a77267..666059c6 100644
--- a/src/fe-gtk/rawlog.c
+++ b/src/fe-gtk/rawlog.c
@@ -77,7 +77,7 @@ rawlog_clearbutton (GtkWidget * wid, server *serv)
 static int
 rawlog_savebutton (GtkWidget * wid, server *serv)
 {
-	gtkutil_file_req (_("Save As..."), rawlog_save, serv, NULL, NULL, FRF_WRITE);
+	gtkutil_file_req (NULL, _("Save As..."), rawlog_save, serv, NULL, NULL, FRF_WRITE);
 	return FALSE;
 }
 
diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c
index a7e3a15c..2f0589bd 100644
--- a/src/fe-gtk/setup.c
+++ b/src/fe-gtk/setup.c
@@ -48,6 +48,7 @@ GtkStyle *create_input_style (GtkStyle *);
 
 #define LABEL_INDENT 12
 
+static GtkWidget *setup_window = NULL;
 static int last_selected_page = 0;
 static int last_selected_row = 0; /* sound row */
 static gboolean color_change;
@@ -1105,8 +1106,8 @@ setup_browsefile_cb (GtkWidget *button, GtkWidget *entry)
 	filter = "image/*";
 	filter_type = FRF_MIMETYPES;
 #endif
-	gtkutil_file_req (_("Select an Image File"), setup_filereq_cb,
-					entry, NULL, filter, filter_type|FRF_RECENTLYUSED);
+	gtkutil_file_req (GTK_WINDOW (setup_window), _("Select an Image File"), setup_filereq_cb,
+					entry, NULL, filter, filter_type|FRF_RECENTLYUSED|FRF_MODAL);
 }
 
 static void
@@ -1141,7 +1142,7 @@ setup_fontsel_cancel (GtkWidget *button, GtkFontSelectionDialog *dialog)
 static void
 setup_browsefolder_cb (GtkWidget *button, GtkEntry *entry)
 {
-	gtkutil_file_req (_("Select Download Folder"), setup_filereq_cb, entry, (char*)gtk_entry_get_text (entry), NULL, FRF_CHOOSEFOLDER);
+	gtkutil_file_req (GTK_WINDOW (setup_window), _("Select Download Folder"), setup_filereq_cb, entry, (char*)gtk_entry_get_text (entry), NULL, FRF_CHOOSEFOLDER|FRF_MODAL);
 }
 
 static void
@@ -1154,6 +1155,9 @@ setup_browsefont_cb (GtkWidget *button, GtkWidget *entry)
 	dialog = (GtkFontSelectionDialog *) gtk_font_selection_dialog_new (_("Select font"));
 	font_dialog = (GtkWidget *)dialog;	/* global var */
 
+	gtk_window_set_transient_for (GTK_WINDOW (font_dialog), GTK_WINDOW (setup_window));
+	gtk_window_set_modal (GTK_WINDOW (font_dialog), TRUE);
+
 	sel = (GtkFontSelection *) gtk_font_selection_dialog_get_font_selection (dialog);
 
 	if (gtk_entry_get_text (GTK_ENTRY (entry))[0])
@@ -1457,6 +1461,8 @@ setup_color_cb (GtkWidget *button, gpointer userdata)
 	g_object_set_data (G_OBJECT (ok_button), "b", button);
 	gtk_widget_set_sensitive (help_button, FALSE);
 	gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (cdialog)), color);
+	gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (setup_window));
+	gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
 	gtk_widget_show (dialog);
 
 	g_object_unref (cancel_button);
@@ -1711,8 +1717,8 @@ setup_snd_browse_cb (GtkWidget *button, GtkEntry *entry)
 	filter_type = FRF_MIMETYPES;
 #endif
 
-	gtkutil_file_req (_("Select a sound file"), setup_snd_filereq_cb, entry,
-						sounds_dir, filter, FRF_FILTERISINITIAL|filter_type);
+	gtkutil_file_req (GTK_WINDOW (setup_window), _("Select a sound file"), setup_snd_filereq_cb, entry,
+						sounds_dir, filter, FRF_MODAL|FRF_FILTERISINITIAL|filter_type);
 	g_free (sounds_dir);
 }
 
@@ -2336,8 +2342,6 @@ setup_close_cb (GtkWidget *win, GtkWidget **swin)
 void
 setup_open (void)
 {
-	static GtkWidget *setup_window = NULL;
-
 	if (setup_window)
 	{
 		gtk_window_present (GTK_WINDOW (setup_window));
diff --git a/src/fe-gtk/textgui.c b/src/fe-gtk/textgui.c
index b0f2f392..b5eaf893 100644
--- a/src/fe-gtk/textgui.c
+++ b/src/fe-gtk/textgui.c
@@ -282,7 +282,7 @@ pevent_save_cb (GtkWidget * wid, void *data)
 {
 	if (data)
 	{
-		gtkutil_file_req (_("Print Texts File"), pevent_save_req_cb, NULL,
+		gtkutil_file_req (NULL, _("Print Texts File"), pevent_save_req_cb, NULL,
 								NULL, NULL, FRF_WRITE);
 		return;
 	}
@@ -304,7 +304,7 @@ pevent_load_req_cb (void *arg1, char *file)
 static void
 pevent_load_cb (GtkWidget * wid, void *data)
 {
-	gtkutil_file_req (_("Print Texts File"), pevent_load_req_cb, NULL, NULL, NULL, 0);
+	gtkutil_file_req (NULL, _("Print Texts File"), pevent_load_req_cb, NULL, NULL, NULL, 0);
 }
 
 static void
diff --git a/src/fe-gtk/urlgrab.c b/src/fe-gtk/urlgrab.c
index fd8d8d91..fc2f4b5a 100644
--- a/src/fe-gtk/urlgrab.c
+++ b/src/fe-gtk/urlgrab.c
@@ -145,7 +145,7 @@ url_save_callback (void *arg1, char *file)
 static void
 url_button_save (void)
 {
-	gtkutil_file_req (_("Select an output filename"),
+	gtkutil_file_req (NULL, _("Select an output filename"),
 							url_save_callback, NULL, NULL, NULL, FRF_WRITE);
 }