clist and modal window block X-Server!



Hi!
I have found the described behaviour in a program of mine, and I could
reproduce it with the attached small example with GTK+-1.2.2

I have a clist in the main window, and when clicking on a particular row
(the second in the attached example), an error message is popped up.
This error message is a modal window. The effect is that GTK seems to
block the mouse events for all windows (the X-Server appears blocked!).
You can however still use the keyboard and make the message window
disappear.

In all other situations modal windows appear to work OK; it is just when
called from the select event in a clist (AFAIK).

Other people have also experienced the problem, so it is not only in my
configuration.

Is it a GTK bug?

Regards,
Roberto


/*
This program demonstrates how to block the X-Server.
Click on the second line of the clist, and the server does not respond
any more to mouse clicks.
You can only use the keyboard to close the message window
*/


#include <stdio.h>
#include <stdlib.h>

#include <gtk/gtk.h>
#include <gdk/gdkx.h>



void errormsg(char* msg)
{
  GtkWidget *errw, *okb, *label;

  errw = gtk_dialog_new();
  okb = gtk_button_new_with_label("OK");  
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(errw)->action_area), okb, 
		     FALSE, FALSE, 0);
  gtk_signal_connect_object(GTK_OBJECT(okb), "clicked", 
			    GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(errw));

  label = gtk_label_new(msg);
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(errw)->vbox), label, TRUE, FALSE, 0);

  gtk_window_set_modal(GTK_WINDOW(errw), TRUE);  /* This line HURTS!!!! */
  gtk_widget_show_all(errw);
}




void select_clist (GtkWidget *widget, gint row, gint column, GdkEventButton *event)
{
  printf("GtkCList Selection: row %d column %d button %d\n", row, column, event?event->button:0);
  if (row == 1) errormsg("Line 2 selected"); /* Pops up an error window */
}



main(int argc, char** argv)
{
  char* titles[] = {"Column 1"};
  char* rowentries[] = {"Line"}; 

  GtkWidget *mainwindow, *scwindow, *clist;
  gtk_init(&argc, &argv);

  mainwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_usize(mainwindow, 300, 300);
  gtk_signal_connect(GTK_OBJECT(mainwindow), "delete_event", 
		     GTK_SIGNAL_FUNC(gtk_false), NULL);
  gtk_signal_connect(GTK_OBJECT(mainwindow), "destroy", 
		     GTK_SIGNAL_FUNC(gtk_exit), NULL);

  scwindow = gtk_scrolled_window_new(NULL, NULL);
  clist = gtk_clist_new_with_titles(1, titles);
  gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_BROWSE);
  gtk_clist_append(GTK_CLIST(clist), rowentries);
  gtk_clist_append(GTK_CLIST(clist), rowentries);

  gtk_signal_connect(GTK_OBJECT(clist), "select_row", 
		     (GtkSignalFunc)select_clist, NULL);
  gtk_container_add(GTK_CONTAINER(scwindow), clist);

  gtk_container_add(GTK_CONTAINER(mainwindow), scwindow);
  gtk_widget_show_all(mainwindow);
  gtk_main();
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]