[gtk+/touch-for-3.4: 19/65] scrolledwindow: Capture crossing events when dragging
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/touch-for-3.4: 19/65] scrolledwindow: Capture crossing events when dragging
- Date: Fri, 24 Feb 2012 15:26:26 +0000 (UTC)
commit 523fd1fafad78ee59edde3585e358f037365d66d
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Dec 5 01:37:38 2011 +0100
scrolledwindow: Capture crossing events when dragging
Also, instead of connecting 2 more times to ::captured-event,
have it all go through a single handler.
gtk/gtkscrolledwindow.c | 175 +++++++++++++++++++++--------------------------
1 files changed, 77 insertions(+), 98 deletions(-)
---
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 53b61e7..27a22ca 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -158,9 +158,7 @@ struct _GtkScrolledWindowPrivate
guint kinetic_scrolling_flags : 2;
guint in_drag : 1;
guint last_button_event_valid : 1;
- guint button_press_id;
- guint motion_notify_id;
- guint button_release_id;
+ guint captured_event_id;
guint release_timeout_id;
guint deceleration_id;
@@ -230,8 +228,9 @@ static void gtk_scrolled_window_size_allocate (GtkWidget *widge
GtkAllocation *allocation);
static gboolean gtk_scrolled_window_scroll_event (GtkWidget *widget,
GdkEventScroll *event);
-static gboolean gtk_scrolled_window_button_press_event (GtkWidget *widget,
- GdkEvent *event);
+static gboolean gtk_scrolled_window_captured_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data);
static gboolean gtk_scrolled_window_focus (GtkWidget *widget,
GtkDirectionType direction);
static void gtk_scrolled_window_add (GtkContainer *container,
@@ -1134,27 +1133,17 @@ gtk_scrolled_window_set_kinetic_scrolling (GtkScrolledWindow *scrolled_wi
priv->kinetic_scrolling_flags = flags;
if (priv->kinetic_scrolling_flags & GTK_KINETIC_SCROLLING_ENABLED)
{
- priv->button_press_id =
+ priv->captured_event_id =
g_signal_connect (scrolled_window, "captured-event",
- G_CALLBACK (gtk_scrolled_window_button_press_event),
+ G_CALLBACK (gtk_scrolled_window_captured_event),
NULL);
}
else
{
- if (priv->button_press_id > 0)
+ if (priv->captured_event_id > 0)
{
- g_signal_handler_disconnect (scrolled_window, priv->button_press_id);
- priv->button_press_id = 0;
- }
- if (priv->motion_notify_id > 0)
- {
- g_signal_handler_disconnect (scrolled_window, priv->motion_notify_id);
- priv->motion_notify_id = 0;
- }
- if (priv->button_release_id > 0)
- {
- g_signal_handler_disconnect (scrolled_window, priv->button_release_id);
- priv->button_release_id = 0;
+ g_signal_handler_disconnect (scrolled_window, priv->captured_event_id);
+ priv->captured_event_id = 0;
}
if (priv->release_timeout_id)
{
@@ -1219,20 +1208,10 @@ gtk_scrolled_window_destroy (GtkWidget *widget)
priv->vscrollbar = NULL;
}
- if (priv->button_press_id > 0)
- {
- g_signal_handler_disconnect (scrolled_window, priv->button_press_id);
- priv->button_press_id = 0;
- }
- if (priv->motion_notify_id > 0)
+ if (priv->captured_event_id > 0)
{
- g_signal_handler_disconnect (widget, priv->motion_notify_id);
- priv->motion_notify_id = 0;
- }
- if (priv->button_release_id > 0)
- {
- g_signal_handler_disconnect (widget, priv->button_release_id);
- priv->button_release_id = 0;
+ g_signal_handler_disconnect (scrolled_window, priv->captured_event_id);
+ priv->captured_event_id = 0;
}
if (priv->release_timeout_id)
{
@@ -2436,7 +2415,7 @@ gtk_scrolled_window_start_deceleration (GtkScrolledWindow *scrolled_window)
}
static gboolean
-gtk_scrolled_window_release_captured_events (GtkScrolledWindow *scrolled_window)
+gtk_scrolled_window_release_captured_event (GtkScrolledWindow *scrolled_window)
{
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
@@ -2446,32 +2425,23 @@ gtk_scrolled_window_release_captured_events (GtkScrolledWindow *scrolled_window)
if (!priv->button_press_event)
return FALSE;
- gtk_device_grab_remove (GTK_WIDGET (scrolled_window), priv->drag_device);
- priv->drag_device = NULL;
-
- if (priv->motion_notify_id > 0)
- {
- g_signal_handler_disconnect (scrolled_window, priv->motion_notify_id);
- priv->motion_notify_id = 0;
- }
- if (priv->button_release_id > 0)
+ if (priv->drag_device)
{
- g_signal_handler_disconnect (scrolled_window, priv->button_release_id);
- priv->button_release_id = 0;
+ gtk_device_grab_remove (GTK_WIDGET (scrolled_window), priv->drag_device);
+ priv->drag_device = NULL;
}
if (priv->kinetic_scrolling_flags & GTK_KINETIC_SCROLLING_CAPTURE_BUTTON_PRESS)
{
- /* We are going to synthesize the button press event so that
- * it can be handled by child widget, but we don't want to
- * handle it, so block both button-press and and press-and-hold
- * during this button press
- */
- g_signal_handler_block (scrolled_window, priv->button_press_id);
+ GtkWidget *event_widget;
+
+ event_widget = gtk_get_event_widget (priv->button_press_event);
- gtk_main_do_event (priv->button_press_event);
+ if (!_gtk_propagate_captured_event (event_widget,
+ priv->button_press_event,
+ gtk_bin_get_child (GTK_BIN (scrolled_window))))
+ gtk_propagate_event (event_widget, priv->button_press_event);
- g_signal_handler_unblock (scrolled_window, priv->button_press_id);
gdk_event_free (priv->button_press_event);
priv->button_press_event = NULL;
}
@@ -2480,17 +2450,14 @@ gtk_scrolled_window_release_captured_events (GtkScrolledWindow *scrolled_window)
}
static gboolean
-gtk_scrolled_window_button_release_event (GtkWidget *widget,
- GdkEvent *_event)
+gtk_scrolled_window_captured_button_release (GtkWidget *widget,
+ GdkEvent *_event)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
GtkWidget *child;
GdkEventButton *event;
- if (_event->type != GDK_BUTTON_RELEASE)
- return FALSE;
-
event = (GdkEventButton *)_event;
if (event->button != 1)
@@ -2503,16 +2470,6 @@ gtk_scrolled_window_button_release_event (GtkWidget *widget,
gtk_device_grab_remove (widget, priv->drag_device);
priv->drag_device = NULL;
- if (priv->motion_notify_id > 0)
- {
- g_signal_handler_disconnect (widget, priv->motion_notify_id);
- priv->motion_notify_id = 0;
- }
- if (priv->button_release_id > 0)
- {
- g_signal_handler_disconnect (widget, priv->button_release_id);
- priv->button_release_id = 0;
- }
if (priv->release_timeout_id)
{
g_source_remove (priv->release_timeout_id);
@@ -2524,17 +2481,9 @@ gtk_scrolled_window_button_release_event (GtkWidget *widget,
else
{
/* There hasn't been scrolling at all, so just let the
- * child widget handle the events normally
+ * child widget handle the button press normally
*/
- if (priv->button_press_event &&
- priv->kinetic_scrolling_flags & GTK_KINETIC_SCROLLING_CAPTURE_BUTTON_PRESS)
- {
- g_signal_handler_block (widget, priv->button_press_id);
- gtk_main_do_event (priv->button_press_event);
- g_signal_handler_unblock (widget, priv->button_press_id);
- gdk_event_free (priv->button_press_event);
- priv->button_press_event = NULL;
- }
+ gtk_scrolled_window_release_captured_event (scrolled_window);
return FALSE;
}
@@ -2566,12 +2515,15 @@ gtk_scrolled_window_button_release_event (GtkWidget *widget,
priv->last_button_event_valid = TRUE;
}
- return TRUE;
+ if (priv->kinetic_scrolling_flags & GTK_KINETIC_SCROLLING_CAPTURE_BUTTON_PRESS)
+ return TRUE;
+ else
+ return FALSE;
}
static gboolean
-gtk_scrolled_window_motion_notify_event (GtkWidget *widget,
- GdkEvent *_event)
+gtk_scrolled_window_captured_motion_notify (GtkWidget *widget,
+ GdkEvent *_event)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
@@ -2583,9 +2535,6 @@ gtk_scrolled_window_motion_notify_event (GtkWidget *widget,
gdouble dx, dy;
GdkEventMotion *event;
- if (_event->type != GDK_MOTION_NOTIFY)
- return FALSE;
-
event = (GdkEventMotion *)_event;
if (!(event->state & GDK_BUTTON1_MASK))
@@ -2686,8 +2635,8 @@ gtk_scrolled_window_motion_notify_event (GtkWidget *widget,
}
static gboolean
-gtk_scrolled_window_button_press_event (GtkWidget *widget,
- GdkEvent *_event)
+gtk_scrolled_window_captured_button_press (GtkWidget *widget,
+ GdkEvent *_event)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
@@ -2751,18 +2700,12 @@ gtk_scrolled_window_button_press_event (GtkWidget *widget,
gtk_scrolled_window_cancel_deceleration (scrolled_window);
- priv->motion_notify_id =
- g_signal_connect (widget, "captured-event",
- G_CALLBACK (gtk_scrolled_window_motion_notify_event),
- NULL);
- priv->button_release_id =
- g_signal_connect (widget, "captured-event",
- G_CALLBACK (gtk_scrolled_window_button_release_event),
- NULL);
- priv->release_timeout_id =
- gdk_threads_add_timeout (RELEASE_EVENT_TIMEOUT,
- (GSourceFunc) gtk_scrolled_window_release_captured_events,
- scrolled_window);
+ /* Only set the timeout if we're going to store an event */
+ if (priv->kinetic_scrolling_flags & GTK_KINETIC_SCROLLING_CAPTURE_BUTTON_PRESS)
+ priv->release_timeout_id =
+ gdk_threads_add_timeout (RELEASE_EVENT_TIMEOUT,
+ (GSourceFunc) gtk_scrolled_window_release_captured_event,
+ scrolled_window);
priv->in_drag = FALSE;
@@ -2779,6 +2722,42 @@ gtk_scrolled_window_button_press_event (GtkWidget *widget,
}
static gboolean
+gtk_scrolled_window_captured_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ gboolean retval = FALSE;
+ GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW (widget)->priv;
+
+ switch (event->type)
+ {
+ case GDK_BUTTON_PRESS:
+ retval = gtk_scrolled_window_captured_button_press (widget, event);
+ break;
+ case GDK_BUTTON_RELEASE:
+ if (priv->drag_device)
+ retval = gtk_scrolled_window_captured_button_release (widget, event);
+ else
+ priv->last_button_event_valid = FALSE;
+ break;
+ case GDK_MOTION_NOTIFY:
+ if (priv->drag_device)
+ retval = gtk_scrolled_window_captured_motion_notify (widget, event);
+ break;
+ case GDK_LEAVE_NOTIFY:
+ case GDK_ENTER_NOTIFY:
+ if (priv->in_drag &&
+ event->crossing.mode != GDK_CROSSING_GRAB)
+ retval = TRUE;
+ break;
+ default:
+ break;
+ }
+
+ return retval;
+}
+
+static gboolean
gtk_scrolled_window_focus (GtkWidget *widget,
GtkDirectionType direction)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]