How make multiple Modal windows behave consistently to the user?

Take the above example of an Application. It has one “main” window and two modal windows. If the user clicks on the main window, the modal windows stays behind, but the user cannot click the button on the main window since there are two modal windows blocking events.

I have a more complex use case where windows appear from other threads where gtk_window_set_transient_for cannot be used because the thread has no knowledge of other running windows.

Usually users are dealing with the first modal window and then clicking on other non modal window and thinking the system hanged (because events are blocked by the second modal).

Would it be possible to make modal windows always on top?

#include <gtk/gtk.h>

int main(int argc, char *argv[]) {
  gtk_init(&argc, &argv);

  GtkWidget * main = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size(GTK_WINDOW(main), 800, 600);
  gtk_window_set_position(GTK_WINDOW(main), GTK_WIN_POS_CENTER);

  GtkWidget * button = gtk_button_new_with_label("Button");
  gtk_widget_set_tooltip_text(button, "Button widget");

  GtkWidget * button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_container_add (GTK_CONTAINER (main), button_box);
  gtk_container_add (GTK_CONTAINER (button_box), button);

  GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  GtkWidget * window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  gtk_window_set_modal(GTK_WINDOW(window), TRUE);
  gtk_window_set_modal(GTK_WINDOW(window2), TRUE);
  gtk_window_set_title(GTK_WINDOW(window), "MODAL 1");
  gtk_window_set_title(GTK_WINDOW(window2), "MODAL 2");

  gtk_widget_show_all(main);
  gtk_widget_show(window);
  gtk_widget_show(window2);

  g_signal_connect(main, "destroy", G_CALLBACK(gtk_main_quit), NULL);

  gtk_main();

  return 0;
}

Humm, it seems gtk_window_set_keep_above (GtkWindow *window, gboolean setting) works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.