Bug in get_set_sensitive on button with grab



The following is a test program that shows some very nasty behaviour
that I recently experienced.  The program that I saw the bug in sets a
button sensitivity based upon network traffic.  I had the entire GUI
freeze up on me when I pressed the button, then a network event told
the GUI to make it insensitive before I had released the button.

The follow test program illustrates the bug quite nicely.

Fire up the program and check that the Test Me button works.  Now
press the Click Me button.  After 2 seconds the button will be made
insensitive, click and hold it until it goes insensitive.

At this point the button has a grab, but can never release it (I
assume that is what is happening).

- Dave

P.S.  I can sort of code around the problem, but I do think it is a
      bug in Gtk+

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#include <gtk/gtk.h>

static gint timer_id;

static void lock_gui_cb(GtkWidget *btn)
{
	gtk_widget_set_sensitive(btn, FALSE);
	gtk_label_set_text(GTK_LABEL(GTK_BIN(btn)->child),
			   "GUI is locked");
	gtk_timeout_remove(timer_id);
	timer_id = 0;
}

static void clicked_cb(GtkWidget *btn, gpointer user_data)
{
	if (timer_id == 0) {
		gtk_label_set_text(GTK_LABEL(GTK_BIN(btn)->child),
				   "Press and hold me down");
		timer_id = gtk_timeout_add(2000, (GtkFunction)lock_gui_cb,
					   btn);
	}
}

int main(int argc, char *argv[])
{
	GtkWidget *top;
	GtkWidget *box;
	GtkWidget *btn;

	gtk_init(&argc, &argv);

	top = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_widget_show(top);
	gtk_window_set_title(GTK_WINDOW(top), "Grab bug");
	gtk_window_set_policy(GTK_WINDOW(top), TRUE, TRUE, FALSE);
	gtk_signal_connect(GTK_OBJECT(top), "delete_event",
			   GTK_SIGNAL_FUNC(gtk_main_quit), NULL);

	box = gtk_vbox_new(FALSE, 10);
	gtk_container_border_width(GTK_CONTAINER(box), 10);
	gtk_container_add(GTK_CONTAINER(top), box);

	btn = gtk_button_new_with_label("Click Me");
	gtk_signal_connect(GTK_OBJECT(btn), "clicked",
			   GTK_SIGNAL_FUNC(clicked_cb), NULL);
	gtk_box_pack_start(GTK_BOX(box), btn, TRUE, FALSE, 0);

	gtk_box_pack_start(GTK_BOX(box),
			   gtk_button_new_with_label("Test Me"),
			   TRUE, FALSE, 0);

	gtk_widget_show_all(top);

	gtk_main();

	return 0;
}




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