* 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.
This commit is contained in:
Øyvind Kolås 2007-11-20 17:14:05 +00:00
parent 08f841304a
commit a770e57193
3 changed files with 50 additions and 53 deletions

View File

@ -1,3 +1,10 @@
2007-11-20 Øyvind Kolås <pippin@o-hand.com>
* 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 <pippin@o-hand.com> 2007-11-20 Øyvind Kolås <pippin@o-hand.com>
* clutter/clutter-main.c: (clutter_do_event): avoid computing source * clutter/clutter-main.c: (clutter_do_event): avoid computing source

View File

@ -1120,64 +1120,51 @@ static void
event_click_count_generate (ClutterEvent *event) event_click_count_generate (ClutterEvent *event)
{ {
/* multiple button click detection */ /* multiple button click detection */
static guint32 button_click_time[2] = { 0, 0 }; static gint click_count = 0;
static guint32 button_number[2] = { -1, -1 }; static gint previous_x = -1;
static gint button_x[2] = { 0, 0 }; static gint previous_y = -1;
static gint button_y[2] = { 0, 0 }; static guint32 previous_time = 0;
static gint previous_button_number = -1;
guint double_click_time, double_click_distance; ClutterBackend *backend;
ClutterBackend *backend; guint double_click_time;
ClutterMainContext *context; guint double_click_distance;
context = clutter_context_get_default ();
backend = context->backend;
backend = clutter_context_get_default ()->backend;
double_click_distance = clutter_backend_get_double_click_distance (backend); double_click_distance = clutter_backend_get_double_click_distance (backend);
double_click_time = clutter_backend_get_double_click_time (backend); double_click_time = clutter_backend_get_double_click_time (backend);
/* FIXME: below could be reduced in lines and handle >3 clicks */ switch (event->type)
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))
{ {
event->button.click_count = 2; case CLUTTER_BUTTON_PRESS:
case CLUTTER_SCROLL:
button_click_time[1] = 0; /* check if we are in time and within distance to increment an
button_click_time[0] = 0; * existing click count
button_number[1] = -1; */
button_number[0] = -1; if (event->button.time < previous_time + double_click_time &&
button_x[0] = button_x[1] = 0; (ABS (event->button.x - previous_x) <= double_click_distance) &&
button_y[0] = button_y[1] = 0; (ABS (event->button.y - previous_y) <= double_click_distance)
} && event->button.button == previous_button_number)
else if ((event->button.time < (button_click_time[0] + double_click_time)) && {
(event->button.button == button_number[0]) && click_count ++;
(ABS (event->button.x - button_x[0]) <= double_click_distance) && }
(ABS (event->button.y - button_y[0]) <= double_click_distance)) else /* start a new click count*/
{ {
event->button.click_count = 3; click_count=1;
previous_button_number = event->button.button;
}
button_click_time[1] = button_click_time[0]; /* store time and position for this click for comparison with next event */
button_click_time[0] = event->button.time; previous_time = event->button.time;
button_number[1] = button_number[0]; previous_x = event->button.x;
button_number[0] = event->button.button; previous_y = event->button.y;
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;
button_click_time[1] = 0; /* fallthrough */
button_click_time[0] = event->button.time; case CLUTTER_BUTTON_RELEASE:
button_number[1] = -1; event->button.click_count=click_count;
button_number[0] = event->button.button; break;
button_x[1] = 0; default:
button_x[0] = event->button.x; g_assert (NULL);
button_y[1] = 0;
button_y[0] = event->button.y;
} }
} }

View File

@ -116,15 +116,18 @@ input_cb (ClutterActor *actor,
source, event->button.click_count); source, event->button.click_count);
break; break;
case CLUTTER_BUTTON_RELEASE: 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)) if (clutter_event_get_source (event) == CLUTTER_ACTOR (stage))
clutter_stage_set_key_focus (stage, NULL); clutter_stage_set_key_focus (stage, NULL);
else if (clutter_event_get_source (event) == actor 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); clutter_stage_set_key_focus (stage, actor);
break; break;
case CLUTTER_SCROLL: case CLUTTER_SCROLL:
printf("[%s] BUTTON SCROLL", source); printf("[%s] BUTTON SCROLL (click count:%i)",
source, event->button.click_count);
break; break;
case CLUTTER_STAGE_STATE: case CLUTTER_STAGE_STATE:
printf("[%s] STAGE STATE", source); printf("[%s] STAGE STATE", source);