From a770e57193a8a55651773d12b8602c82d83f4a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Tue, 20 Nov 2007 17:14:05 +0000 Subject: [PATCH] * clutter/clutter-main.c: (event_click_count_generate): generalized click_count generation code. * tests/test-events.c: (input_cb): extended test to report click_count for release and scroll events as well as press events. --- ChangeLog | 7 ++++ clutter/clutter-main.c | 87 ++++++++++++++++++------------------------ tests/test-events.c | 9 +++-- 3 files changed, 50 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 047f8718a..5c9c87d8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-11-20 Øyvind Kolås + + * clutter/clutter-main.c: (event_click_count_generate): generalized + click_count generation code. + * tests/test-events.c: (input_cb): extended test to report click_count + for release and scroll events as well as press events. + 2007-11-20 Øyvind Kolås * clutter/clutter-main.c: (clutter_do_event): avoid computing source diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c index 15eb5829f..df2df37ec 100644 --- a/clutter/clutter-main.c +++ b/clutter/clutter-main.c @@ -1120,64 +1120,51 @@ static void event_click_count_generate (ClutterEvent *event) { /* multiple button click detection */ - static guint32 button_click_time[2] = { 0, 0 }; - static guint32 button_number[2] = { -1, -1 }; - static gint button_x[2] = { 0, 0 }; - static gint button_y[2] = { 0, 0 }; + static gint click_count = 0; + static gint previous_x = -1; + static gint previous_y = -1; + static guint32 previous_time = 0; + static gint previous_button_number = -1; - guint double_click_time, double_click_distance; - ClutterBackend *backend; - ClutterMainContext *context; - - context = clutter_context_get_default (); - backend = context->backend; + ClutterBackend *backend; + guint double_click_time; + guint double_click_distance; + backend = clutter_context_get_default ()->backend; double_click_distance = clutter_backend_get_double_click_distance (backend); double_click_time = clutter_backend_get_double_click_time (backend); - /* FIXME: below could be reduced in lines and handle >3 clicks */ - if ((event->button.time < (button_click_time[1] + 2 * double_click_time)) - && (event->button.button == button_number[1]) - && (ABS (event->button.x - button_x[1]) <= double_click_distance) - && (ABS (event->button.y - button_y[1]) <= double_click_distance)) + switch (event->type) { - event->button.click_count = 2; - - button_click_time[1] = 0; - button_click_time[0] = 0; - button_number[1] = -1; - button_number[0] = -1; - button_x[0] = button_x[1] = 0; - button_y[0] = button_y[1] = 0; - } - else if ((event->button.time < (button_click_time[0] + double_click_time)) && - (event->button.button == button_number[0]) && - (ABS (event->button.x - button_x[0]) <= double_click_distance) && - (ABS (event->button.y - button_y[0]) <= double_click_distance)) - { - event->button.click_count = 3; + case CLUTTER_BUTTON_PRESS: + case CLUTTER_SCROLL: + /* check if we are in time and within distance to increment an + * existing click count + */ + if (event->button.time < previous_time + double_click_time && + (ABS (event->button.x - previous_x) <= double_click_distance) && + (ABS (event->button.y - previous_y) <= double_click_distance) + && event->button.button == previous_button_number) + { + click_count ++; + } + else /* start a new click count*/ + { + click_count=1; + previous_button_number = event->button.button; + } - button_click_time[1] = button_click_time[0]; - button_click_time[0] = event->button.time; - button_number[1] = button_number[0]; - button_number[0] = event->button.button; - button_x[1] = button_x[0]; - button_x[0] = event->button.x; - button_y[1] = button_y[0]; - button_y[0] = event->button.y; - } - else - { - event->button.click_count = 1; + /* store time and position for this click for comparison with next event */ + previous_time = event->button.time; + previous_x = event->button.x; + previous_y = event->button.y; - button_click_time[1] = 0; - button_click_time[0] = event->button.time; - button_number[1] = -1; - button_number[0] = event->button.button; - button_x[1] = 0; - button_x[0] = event->button.x; - button_y[1] = 0; - button_y[0] = event->button.y; + /* fallthrough */ + case CLUTTER_BUTTON_RELEASE: + event->button.click_count=click_count; + break; + default: + g_assert (NULL); } } diff --git a/tests/test-events.c b/tests/test-events.c index 49abd48a9..a286ce545 100644 --- a/tests/test-events.c +++ b/tests/test-events.c @@ -116,15 +116,18 @@ input_cb (ClutterActor *actor, source, event->button.click_count); break; case CLUTTER_BUTTON_RELEASE: - printf("[%s] BUTTON RELEASE", source); + printf("[%s] BUTTON RELEASE (click count:%i)", + source, event->button.click_count); + if (clutter_event_get_source (event) == CLUTTER_ACTOR (stage)) clutter_stage_set_key_focus (stage, NULL); else if (clutter_event_get_source (event) == actor - && clutter_actor_get_parent (actor) == stage) + && clutter_actor_get_parent (actor) == CLUTTER_ACTOR (stage)) clutter_stage_set_key_focus (stage, actor); break; case CLUTTER_SCROLL: - printf("[%s] BUTTON SCROLL", source); + printf("[%s] BUTTON SCROLL (click count:%i)", + source, event->button.click_count); break; case CLUTTER_STAGE_STATE: printf("[%s] STAGE STATE", source);