diff --git a/ChangeLog b/ChangeLog index c1352b7385..d37854800d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2005-06-27 Matthias Clasen + * gtk/gtkbutton.c (gtk_real_button_activate): Continue + to activate even if we can't grab the keyboard. + (gtk_button_finish_activate): Only ungrab when we have + a keyboard grab. (#172998, William Jon McCann) + * modules/input/gtkimcontextxim.c (gtk_im_context_xim_finalize): Avoid a segfault. (#309054) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index c1352b7385..d37854800d 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,10 @@ 2005-06-27 Matthias Clasen + * gtk/gtkbutton.c (gtk_real_button_activate): Continue + to activate even if we can't grab the keyboard. + (gtk_button_finish_activate): Only ungrab when we have + a keyboard grab. (#172998, William Jon McCann) + * modules/input/gtkimcontextxim.c (gtk_im_context_xim_finalize): Avoid a segfault. (#309054) diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index c1352b7385..d37854800d 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,5 +1,10 @@ 2005-06-27 Matthias Clasen + * gtk/gtkbutton.c (gtk_real_button_activate): Continue + to activate even if we can't grab the keyboard. + (gtk_button_finish_activate): Only ungrab when we have + a keyboard grab. (#172998, William Jon McCann) + * modules/input/gtkimcontextxim.c (gtk_im_context_xim_finalize): Avoid a segfault. (#309054) diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index 8190ad8fa2..984d99adca 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -81,6 +81,8 @@ struct _GtkButtonPrivate GtkWidget *image; guint align_set : 1; guint image_is_stock : 1; + guint has_grab : 1; + guint32 grab_time; }; static void gtk_button_class_init (GtkButtonClass *klass); @@ -1360,21 +1362,29 @@ static void gtk_real_button_activate (GtkButton *button) { GtkWidget *widget = GTK_WIDGET (button); - + GtkButtonPrivate *priv; + guint32 time; + + priv = GTK_BUTTON_GET_PRIVATE (button); + if (GTK_WIDGET_REALIZED (button) && !button->activate_timeout) { - if (gdk_keyboard_grab (button->event_window, TRUE, - gtk_get_current_event_time ()) == 0) + time = gtk_get_current_event_time (); + if (gdk_keyboard_grab (button->event_window, TRUE, time) == + GDK_GRAB_SUCCESS) { - gtk_grab_add (widget); - - button->activate_timeout = g_timeout_add (ACTIVATE_TIMEOUT, - button_activate_timeout, - button); - button->button_down = TRUE; - gtk_button_update_state (button); - gtk_widget_queue_draw (GTK_WIDGET (button)); + priv->has_grab = TRUE; + priv->grab_time = time; } + + gtk_grab_add (widget); + + button->activate_timeout = g_timeout_add (ACTIVATE_TIMEOUT, + button_activate_timeout, + button); + button->button_down = TRUE; + gtk_button_update_state (button); + gtk_widget_queue_draw (GTK_WIDGET (button)); } } @@ -1383,12 +1393,18 @@ gtk_button_finish_activate (GtkButton *button, gboolean do_it) { GtkWidget *widget = GTK_WIDGET (button); + GtkButtonPrivate *priv; + priv = GTK_BUTTON_GET_PRIVATE (button); + g_source_remove (button->activate_timeout); button->activate_timeout = 0; - gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), - gtk_get_current_event_time ()); + if (priv->has_grab) + { + gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), + priv->grab_time); + } gtk_grab_remove (widget); button->button_down = FALSE;