From 45d6d6ac7175cf0720e39937abac0d4088814cb8 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Sat, 29 Sep 2012 21:13:05 +0300 Subject: Keep the "Add/Edit Cylinder & Weight" dialogs on top This is the same issue as 882cb159a46d5d9dbd0 (although now we don't have "Import XML Files" within a dialog). It applies when in the "Dive info" dialog. There is some sort of a GTK bug on Ubuntu 12.04 with GTK 2.24.10 that prevents us from using the gtk_window_set_accept_focus() and similar API to make the window behind fully inactive. The proposed portable solution is to completely disable the background window (NOTE: unless its the main window), disabling child controls (gtk_widget_set_sensitive) and making the top window "transient for" or putting it on top (gtk_window_set_transient_for). Still we do not want to hide the background window titlebar with gtk_window_set_decorated(), which makes it still clickable. Make this change to older code in gtk-gui.c as well. Signed-off-by: Lubomir I. Ivanov --- equipment.c | 46 ++++++++++++++++++++++++++++++---------------- gtk-gui.c | 2 -- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/equipment.c b/equipment.c index ccdee6268..503f238c5 100644 --- a/equipment.c +++ b/equipment.c @@ -1038,10 +1038,10 @@ static void ws_widget(GtkWidget *vbox, struct ws_widget *ws_widget, GtkListStore ws_widget->weight = GTK_SPIN_BUTTON(widget); } -static int edit_cylinder_dialog(int index, cylinder_t *cyl, int w_idx) +static int edit_cylinder_dialog(GtkWidget *w, int index, cylinder_t *cyl, int w_idx) { int success; - GtkWidget *dialog, *vbox; + GtkWidget *dialog, *vbox, *parent; struct cylinder_widget cylinder; struct dive *dive; @@ -1064,6 +1064,12 @@ static int edit_cylinder_dialog(int index, cylinder_t *cyl, int w_idx) GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); + parent = gtk_widget_get_ancestor(w, GTK_TYPE_DIALOG); + if (parent) { + gtk_widget_set_sensitive(parent, FALSE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent)); + } + vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); cylinder_widget(vbox, &cylinder, cylinder_model); @@ -1082,14 +1088,15 @@ static int edit_cylinder_dialog(int index, cylinder_t *cyl, int w_idx) } gtk_widget_destroy(dialog); - + if (parent) + gtk_widget_set_sensitive(parent, TRUE); return success; } -static int edit_weightsystem_dialog(int index, weightsystem_t *ws, int w_idx) +static int edit_weightsystem_dialog(GtkWidget *w, int index, weightsystem_t *ws, int w_idx) { int success; - GtkWidget *dialog, *vbox; + GtkWidget *dialog, *vbox, *parent; struct ws_widget weightsystem_widget; struct dive *dive; @@ -1112,6 +1119,12 @@ static int edit_weightsystem_dialog(int index, weightsystem_t *ws, int w_idx) GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); + parent = gtk_widget_get_ancestor(w, GTK_TYPE_DIALOG); + if (parent) { + gtk_widget_set_sensitive(parent, FALSE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent)); + } + vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); ws_widget(vbox, &weightsystem_widget, weightsystem_model); @@ -1129,7 +1142,8 @@ static int edit_weightsystem_dialog(int index, weightsystem_t *ws, int w_idx) } gtk_widget_destroy(dialog); - + if (parent) + gtk_widget_set_sensitive(parent, TRUE); return success; } @@ -1145,7 +1159,7 @@ static int get_model_index(GtkListStore *model, GtkTreeIter *iter) return index; } -static void edit_cb(GtkButton *button, int w_idx) +static void edit_cb(GtkWidget *w, int w_idx) { int index; GtkTreeIter iter; @@ -1161,14 +1175,14 @@ static void edit_cb(GtkButton *button, int w_idx) return; index = get_model_index(model, &iter); - if (!edit_cylinder_dialog(index, &cyl, w_idx)) + if (!edit_cylinder_dialog(w, index, &cyl, w_idx)) return; set_one_cylinder(&cyl, model, &iter); repaint_dive(); } -static void add_cb(GtkButton *button, int w_idx) +static void add_cb(GtkWidget *w, int w_idx) { int index = cylinder_list[w_idx].max_index; GtkTreeIter iter; @@ -1177,7 +1191,7 @@ static void add_cb(GtkButton *button, int w_idx) GtkTreeSelection *selection; cylinder_t cyl; - if (!edit_cylinder_dialog(index, &cyl, w_idx)) + if (!edit_cylinder_dialog(w, index, &cyl, w_idx)) return; gtk_list_store_append(model, &iter); @@ -1231,7 +1245,7 @@ static void del_cb(GtkButton *button, int w_idx) gtk_widget_set_sensitive(cylinder_list[w_idx].add, 1); } -static void ws_edit_cb(GtkButton *button, int w_idx) +static void ws_edit_cb(GtkWidget *w, int w_idx) { int index; GtkTreeIter iter; @@ -1247,14 +1261,14 @@ static void ws_edit_cb(GtkButton *button, int w_idx) return; index = get_model_index(model, &iter); - if (!edit_weightsystem_dialog(index, &ws, w_idx)) + if (!edit_weightsystem_dialog(w, index, &ws, w_idx)) return; set_one_weightsystem(&ws, model, &iter); repaint_dive(); } -static void ws_add_cb(GtkButton *button, int w_idx) +static void ws_add_cb(GtkWidget *w, int w_idx) { int index = weightsystem_list[w_idx].max_index; GtkTreeIter iter; @@ -1263,7 +1277,7 @@ static void ws_add_cb(GtkButton *button, int w_idx) GtkTreeSelection *selection; weightsystem_t ws; - if (!edit_weightsystem_dialog(index, &ws, w_idx)) + if (!edit_weightsystem_dialog(w, index, &ws, w_idx)) return; gtk_list_store_append(model, &iter); @@ -1436,7 +1450,7 @@ static void row_activated_cb(GtkTreeView *tree_view, GtkTreeViewColumn *column, int w_idx) { - edit_cb(NULL, w_idx); + edit_cb(GTK_WIDGET(tree_view), w_idx); } static void ws_row_activated_cb(GtkTreeView *tree_view, @@ -1444,7 +1458,7 @@ static void ws_row_activated_cb(GtkTreeView *tree_view, GtkTreeViewColumn *column, int w_idx) { - ws_edit_cb(NULL, w_idx); + ws_edit_cb(GTK_WIDGET(tree_view), w_idx); } GtkWidget *cylinder_list_widget(int w_idx) diff --git a/gtk-gui.c b/gtk-gui.c index 6395552d9..7f60b62fd 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -509,7 +509,6 @@ static void pick_default_file(GtkWidget *w, GtkButton *button) NULL); 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(); @@ -542,7 +541,6 @@ static void pick_default_file(GtkWidget *w, GtkButton *button) gtk_widget_destroy(fs_dialog); gtk_widget_set_sensitive(parent, TRUE); - gtk_window_set_decorated(GTK_WINDOW(parent), TRUE); } static void preferences_dialog(GtkWidget *w, gpointer data) -- cgit v1.2.3-70-g09d2