static void gtk_real_button_pressed (GtkButton *button) { if (button->activate_timeout) return; button->button_down = TRUE; gtk_button_update_state (button); }
static void gtk_real_button_released (GtkButton *button) { if (button->button_down) { button->button_down = FALSE; if (button->activate_timeout) return; if (button->in_button) gtk_button_clicked (button); gtk_button_update_state (button); } }
static gboolean gtk_button_leave_notify (GtkWidget *widget, GdkEventCrossing *event) { GtkButton *button = GTK_BUTTON (widget); GtkButtonPrivate *priv = button->priv; if ((event->window == button->priv->event_window) && (event->detail != GDK_NOTIFY_INFERIOR)) { priv->in_button = FALSE; gtk_button_update_state (button); } return FALSE; }
static void gtk_button_do_release (GtkButton *button, gboolean emit_clicked) { GtkButtonPrivate *priv = button->priv; if (priv->button_down) { priv->button_down = FALSE; if (priv->activate_timeout) return; if (emit_clicked) gtk_button_clicked (button); gtk_button_update_state (button); } }
static void gtk_button_finish_activate (GtkButton *button, gboolean do_it) { GtkWidget *widget = GTK_WIDGET (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 ()); gtk_grab_remove (widget); button->button_down = FALSE; gtk_button_update_state (button); gtk_widget_queue_draw (GTK_WIDGET (button)); if (do_it) gtk_button_clicked (button); }
static void gtk_real_button_activate (GtkButton *button) { GtkWidget *widget = GTK_WIDGET (button); if (GTK_WIDGET_REALIZED (button) && !button->activate_timeout) { if (gdk_keyboard_grab (button->event_window, TRUE, gtk_get_current_event_time ()) == 0) { 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)); } } }
static void gtk_button_screen_changed (GtkWidget *widget, GdkScreen *previous_screen) { GtkButton *button; GtkButtonPrivate *priv; if (!gtk_widget_has_screen (widget)) return; button = GTK_BUTTON (widget); priv = button->priv; /* If the button is being pressed while the screen changes the release might never occur, so we reset the state. */ if (priv->button_down) { priv->button_down = FALSE; gtk_button_update_state (button); } }
static void multipress_pressed_cb (GtkGestureMultiPress *gesture, guint n_press, gdouble x, gdouble y, GtkWidget *widget) { GtkButton *button = GTK_BUTTON (widget); GtkButtonPrivate *priv = button->priv; if (gtk_widget_get_focus_on_click (widget) && !gtk_widget_has_focus (widget)) gtk_widget_grab_focus (widget); priv->in_button = TRUE; if (!priv->activate_timeout) { priv->button_down = TRUE; gtk_button_update_state (button); } gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED); }
static void multipress_gesture_update_cb (GtkGesture *gesture, GdkEventSequence *sequence, GtkButton *button) { GtkButtonPrivate *priv = button->priv; GtkAllocation allocation; gboolean in_button; gdouble x, y; if (sequence != gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture))) return; gtk_widget_get_allocation (GTK_WIDGET (button), &allocation); gtk_gesture_get_point (gesture, sequence, &x, &y); in_button = (x >= 0 && y >= 0 && x < allocation.width && y < allocation.height); if (priv->in_button != in_button) { priv->in_button = in_button; gtk_button_update_state (button); } }
static void multipress_released_cb (GtkGestureMultiPress *gesture, guint n_press, gdouble x, gdouble y, GtkWidget *widget) { GtkButton *button = GTK_BUTTON (widget); GtkButtonPrivate *priv = button->priv; GdkEventSequence *sequence; gtk_button_do_release (button, gtk_widget_is_sensitive (GTK_WIDGET (button)) && (button->priv->in_button || touch_release_in_button (button))); sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture)); if (sequence) { priv->in_button = FALSE; gtk_button_update_state (button); } }
static void gtk_button_finish_activate (GtkButton *button, gboolean do_it) { GtkWidget *widget = GTK_WIDGET (button); GtkButtonPrivate *priv = button->priv; g_source_remove (priv->activate_timeout); priv->activate_timeout = 0; if (priv->grab_keyboard) { gdk_seat_ungrab (gdk_device_get_seat (priv->grab_keyboard)); gtk_device_grab_remove (widget, priv->grab_keyboard); priv->grab_keyboard = NULL; } priv->button_down = FALSE; gtk_button_update_state (button); if (do_it) gtk_button_clicked (button); }
static void gtk_real_button_activate (GtkButton *button) { GtkWidget *widget = GTK_WIDGET (button); GtkButtonPrivate *priv = button->priv; GdkDevice *device; device = gtk_get_current_event_device (); if (device && gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD) device = gdk_device_get_associated_device (device); if (gtk_widget_get_realized (widget) && !priv->activate_timeout) { /* bgo#626336 - Only grab if we have a device (from an event), not if we * were activated programmatically when no event is available. */ if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) { if (gdk_seat_grab (gdk_device_get_seat (device), priv->event_window, GDK_SEAT_CAPABILITY_KEYBOARD, TRUE, NULL, NULL, NULL, NULL) == GDK_GRAB_SUCCESS) { gtk_device_grab_add (widget, device, TRUE); priv->grab_keyboard = device; } } priv->activate_timeout = gdk_threads_add_timeout (ACTIVATE_TIMEOUT, button_activate_timeout, button); g_source_set_name_by_id (priv->activate_timeout, "[gtk+] button_activate_timeout"); priv->button_down = TRUE; gtk_button_update_state (button); } }