[gtk+/xi2: 776/1239] Store double/triple click info per-device.
- From: Carlos Garnacho <carlosg src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtk+/xi2: 776/1239] Store double/triple click info per-device.
- Date: Tue, 29 Sep 2009 10:50:51 +0000 (UTC)
commit 1843eeb48a756450ba2f2a4863df80605013e830
Author: Carlos Garnacho <carlos lanedo com>
Date: Sun Aug 16 19:34:58 2009 +0200
Store double/triple click info per-device.
gdk/gdkdisplay.c | 14 +++++---
gdk/gdkdisplay.h | 15 ++++++---
gdk/gdkevents.c | 93 ++++++++++++++++++++++++++++++-----------------------
3 files changed, 71 insertions(+), 51 deletions(-)
---
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index 734e164..fabdd2e 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -138,12 +138,6 @@ gdk_display_init (GdkDisplay *display)
{
_gdk_displays = g_slist_prepend (_gdk_displays, display);
- display->button_click_time[0] = display->button_click_time[1] = 0;
- display->button_window[0] = display->button_window[1] = NULL;
- display->button_number[0] = display->button_number[1] = -1;
- display->button_x[0] = display->button_x[1] = 0;
- display->button_y[0] = display->button_y[1] = 0;
-
display->double_click_time = 250;
display->double_click_distance = 5;
@@ -151,6 +145,9 @@ gdk_display_init (GdkDisplay *display)
display->pointers_info = g_hash_table_new_full (NULL, NULL, NULL,
(GDestroyNotify) free_pointer_info);
+
+ display->multiple_click_info = g_hash_table_new_full (NULL, NULL, NULL,
+ (GDestroyNotify) g_free);
}
static void
@@ -181,6 +178,11 @@ gdk_display_dispose (GObject *object)
static void
gdk_display_finalize (GObject *object)
{
+ GdkDisplay *display;
+
+ g_hash_table_destroy (display->pointers_info);
+ g_hash_table_destroy (display->multiple_click_info);
+
G_OBJECT_CLASS (gdk_display_parent_class)->finalize (object);
}
diff --git a/gdk/gdkdisplay.h b/gdk/gdkdisplay.h
index b3a3a42..e81df53 100644
--- a/gdk/gdkdisplay.h
+++ b/gdk/gdkdisplay.h
@@ -70,6 +70,15 @@ typedef struct
gulong motion_hint_serial; /* 0 == didn't deliver hinted motion event */
} GdkPointerWindowInfo;
+typedef struct
+{
+ guint32 button_click_time[2]; /* The last 2 button click times. */
+ GdkWindow *button_window[2]; /* The last 2 windows to receive button presses. */
+ gint button_number[2]; /* The last 2 buttons to be pressed. */
+ gint button_x[2]; /* The last 2 button click positions. */
+ gint button_y[2];
+} GdkMultipleClickInfo;
+
struct _GdkDisplay
{
GObject parent_instance;
@@ -81,9 +90,7 @@ struct _GdkDisplay
/* Information for determining if the latest button click
* is part of a double-click or triple-click
*/
- guint32 button_click_time[2]; /* The last 2 button click times. */
- GdkWindow *button_window[2]; /* The last 2 windows to receive button presses. */
- gint button_number[2]; /* The last 2 buttons to be pressed. */
+ GHashTable *multiple_click_info;
guint double_click_time; /* Maximum time between clicks in msecs */
GdkDevice *core_pointer; /* Core pointer device */
@@ -94,8 +101,6 @@ struct _GdkDisplay
guint ignore_core_events : 1; /* Don't send core motion and button event */
guint double_click_distance; /* Maximum distance between clicks in pixels */
- gint button_x[2]; /* The last 2 button click positions. */
- gint button_y[2];
GList *pointer_grabs;
GdkKeyboardGrabInfo keyboard_grab;
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index b7fc9f2..2e6846c 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -1296,54 +1296,67 @@ void
_gdk_event_button_generate (GdkDisplay *display,
GdkEvent *event)
{
- if ((event->button.time < (display->button_click_time[1] + 2*display->double_click_time)) &&
- (event->button.window == display->button_window[1]) &&
- (event->button.button == display->button_number[1]) &&
- (ABS (event->button.x - display->button_x[1]) <= display->double_click_distance) &&
- (ABS (event->button.y - display->button_y[1]) <= display->double_click_distance))
-{
+ GdkMultipleClickInfo *info;
+
+ info = g_hash_table_lookup (display->multiple_click_info, event->button.device);
+
+ if (G_UNLIKELY (!info))
+ {
+ info = g_new0 (GdkMultipleClickInfo, 1);
+ info->button_number[0] = info->button_number[1] = -1;
+
+ g_hash_table_insert (display->multiple_click_info,
+ event->button.device, info);
+ }
+
+ if ((event->button.time < (info->button_click_time[1] + 2 * display->double_click_time)) &&
+ (event->button.window == info->button_window[1]) &&
+ (event->button.button == info->button_number[1]) &&
+ (ABS (event->button.x - info->button_x[1]) <= display->double_click_distance) &&
+ (ABS (event->button.y - info->button_y[1]) <= display->double_click_distance))
+ {
gdk_synthesize_click (display, event, 3);
-
- display->button_click_time[1] = 0;
- display->button_click_time[0] = 0;
- display->button_window[1] = NULL;
- display->button_window[0] = NULL;
- display->button_number[1] = -1;
- display->button_number[0] = -1;
- display->button_x[0] = display->button_x[1] = 0;
- display->button_y[0] = display->button_y[1] = 0;
+
+ info->button_click_time[1] = 0;
+ info->button_click_time[0] = 0;
+ info->button_window[1] = NULL;
+ info->button_window[0] = NULL;
+ info->button_number[1] = -1;
+ info->button_number[0] = -1;
+ info->button_x[0] = info->button_x[1] = 0;
+ info->button_y[0] = info->button_y[1] = 0;
}
- else if ((event->button.time < (display->button_click_time[0] + display->double_click_time)) &&
- (event->button.window == display->button_window[0]) &&
- (event->button.button == display->button_number[0]) &&
- (ABS (event->button.x - display->button_x[0]) <= display->double_click_distance) &&
- (ABS (event->button.y - display->button_y[0]) <= display->double_click_distance))
+ else if ((event->button.time < (info->button_click_time[0] + display->double_click_time)) &&
+ (event->button.window == info->button_window[0]) &&
+ (event->button.button == info->button_number[0]) &&
+ (ABS (event->button.x - info->button_x[0]) <= display->double_click_distance) &&
+ (ABS (event->button.y - info->button_y[0]) <= display->double_click_distance))
{
gdk_synthesize_click (display, event, 2);
- display->button_click_time[1] = display->button_click_time[0];
- display->button_click_time[0] = event->button.time;
- display->button_window[1] = display->button_window[0];
- display->button_window[0] = event->button.window;
- display->button_number[1] = display->button_number[0];
- display->button_number[0] = event->button.button;
- display->button_x[1] = display->button_x[0];
- display->button_x[0] = event->button.x;
- display->button_y[1] = display->button_y[0];
- display->button_y[0] = event->button.y;
+ info->button_click_time[1] = info->button_click_time[0];
+ info->button_click_time[0] = event->button.time;
+ info->button_window[1] = info->button_window[0];
+ info->button_window[0] = event->button.window;
+ info->button_number[1] = info->button_number[0];
+ info->button_number[0] = event->button.button;
+ info->button_x[1] = info->button_x[0];
+ info->button_x[0] = event->button.x;
+ info->button_y[1] = info->button_y[0];
+ info->button_y[0] = event->button.y;
}
else
{
- display->button_click_time[1] = 0;
- display->button_click_time[0] = event->button.time;
- display->button_window[1] = NULL;
- display->button_window[0] = event->button.window;
- display->button_number[1] = -1;
- display->button_number[0] = event->button.button;
- display->button_x[1] = 0;
- display->button_x[0] = event->button.x;
- display->button_y[1] = 0;
- display->button_y[0] = event->button.y;
+ info->button_click_time[1] = 0;
+ info->button_click_time[0] = event->button.time;
+ info->button_window[1] = NULL;
+ info->button_window[0] = event->button.window;
+ info->button_number[1] = -1;
+ info->button_number[0] = event->button.button;
+ info->button_x[1] = 0;
+ info->button_x[0] = event->button.x;
+ info->button_y[1] = 0;
+ info->button_y[0] = event->button.y;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]