[gtk+/touchscreens: 48/49] gtk, scrolledwindow: capture crossing events when dragging
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/touchscreens: 48/49] gtk, scrolledwindow: capture crossing events when dragging
- Date: Mon, 5 Dec 2011 01:19:00 +0000 (UTC)
commit b5e8204615562fab360af1fb3239b14e7062be55
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Dec 5 01:37:38 2011 +0100
gtk,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 | 128 +++++++++++++++++++---------------------------
1 files changed, 53 insertions(+), 75 deletions(-)
---
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 8e16e78..ab65596 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -158,9 +158,7 @@ struct _GtkScrolledWindowPrivate
GdkDevice *drag_device;
guint kinetic_scrolling_flags : 2;
guint in_drag : 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,10 @@ 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 GtkCapturedEventFlags
+ 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,
@@ -1154,9 +1154,9 @@ 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);
/* Hide the scrollbars */
@@ -1165,20 +1165,10 @@ gtk_scrolled_window_set_kinetic_scrolling (GtkScrolledWindow *scrolled_wi
}
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)
{
@@ -1250,20 +1240,10 @@ gtk_scrolled_window_destroy (GtkWidget *widget)
priv->vscrollbar = NULL;
}
- 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 (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)
{
@@ -2513,17 +2493,6 @@ gtk_scrolled_window_release_captured_events (GtkScrolledWindow *scrolled_window)
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)
- {
- g_signal_handler_disconnect (scrolled_window, priv->button_release_id);
- priv->button_release_id = 0;
- }
-
if (priv->kinetic_scrolling_flags & GTK_KINETIC_SCROLLING_CAPTURE_BUTTON_PRESS)
gtk_widget_release_captured_events (GTK_WIDGET (scrolled_window), TRUE);
@@ -2531,17 +2500,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 GTK_CAPTURED_EVENT_NONE;
-
event = (GdkEventButton *)_event;
if (event->button != 1)
@@ -2557,16 +2523,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);
@@ -2611,8 +2567,8 @@ gtk_scrolled_window_button_release_event (GtkWidget *widget,
}
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;
@@ -2624,9 +2580,6 @@ gtk_scrolled_window_motion_notify_event (GtkWidget *widget,
gdouble dx, dy;
GdkEventMotion *event;
- if (_event->type != GDK_MOTION_NOTIFY)
- return GTK_CAPTURED_EVENT_NONE;
-
event = (GdkEventMotion *)_event;
if (!(event->state & GDK_BUTTON1_MASK))
@@ -2721,9 +2674,9 @@ gtk_scrolled_window_motion_notify_event (GtkWidget *widget,
return GTK_CAPTURED_EVENT_HANDLED;
}
-static gboolean
-gtk_scrolled_window_button_press_event (GtkWidget *widget,
- GdkEvent *_event)
+static GtkCapturedEventFlags
+gtk_scrolled_window_captured_button_press (GtkWidget *widget,
+ GdkEvent *_event)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
@@ -2792,14 +2745,6 @@ gtk_scrolled_window_button_press_event (GtkWidget *widget,
"gtk-press-and-hold-timeout", &timeout,
NULL);
- 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 (timeout,
(GSourceFunc) gtk_scrolled_window_release_captured_events,
@@ -2836,6 +2781,39 @@ gtk_scrolled_window_button_press_event (GtkWidget *widget,
return GTK_CAPTURED_EVENT_NONE;
}
+static GtkCapturedEventFlags
+gtk_scrolled_window_captured_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ GtkCapturedEventFlags flags = GTK_CAPTURED_EVENT_NONE;
+ GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW (widget)->priv;
+
+ switch (event->type)
+ {
+ case GDK_BUTTON_PRESS:
+ flags = gtk_scrolled_window_captured_button_press (widget, event);
+ break;
+ case GDK_BUTTON_RELEASE:
+ if (priv->drag_device)
+ flags = gtk_scrolled_window_captured_button_release (widget, event);
+ break;
+ case GDK_MOTION_NOTIFY:
+ if (priv->drag_device)
+ flags = gtk_scrolled_window_captured_motion_notify (widget, event);
+ break;
+ case GDK_ENTER_NOTIFY:
+ case GDK_LEAVE_NOTIFY:
+ if (priv->in_drag)
+ flags = GTK_CAPTURED_EVENT_HANDLED;
+ break;
+ default:
+ break;
+ }
+
+ return flags;
+}
+
static gboolean
gtk_scrolled_window_focus (GtkWidget *widget,
GtkDirectionType direction)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]