mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 10:00:45 -05:00
* 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:
parent
08f841304a
commit
a770e57193
@ -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>
|
||||
|
||||
* clutter/clutter-main.c: (clutter_do_event): avoid computing source
|
||||
|
@ -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;
|
||||
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;
|
||||
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 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))
|
||||
else /* start a new click count*/
|
||||
{
|
||||
event->button.click_count = 3;
|
||||
|
||||
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;
|
||||
click_count=1;
|
||||
previous_button_number = event->button.button;
|
||||
}
|
||||
else
|
||||
{
|
||||
event->button.click_count = 1;
|
||||
|
||||
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;
|
||||
/* 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;
|
||||
|
||||
/* fallthrough */
|
||||
case CLUTTER_BUTTON_RELEASE:
|
||||
event->button.click_count=click_count;
|
||||
break;
|
||||
default:
|
||||
g_assert (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user