tests: Clean up test-events

The output of test-events is a bit of a mess; this patch should clean
it up a little bit - at least enough for it to be useful again during
visual inspection.
This commit is contained in:
Emmanuele Bassi 2009-11-24 16:31:14 +00:00
parent a056ae7164
commit 75f05646fa

View File

@ -27,6 +27,12 @@ get_event_type_name (const ClutterEvent *event)
case CLUTTER_LEAVE: case CLUTTER_LEAVE:
return "LEAVE"; return "LEAVE";
case CLUTTER_MOTION:
return "MOTION";
case CLUTTER_DELETE:
return "DELETE";
default: default:
return "EVENT"; return "EVENT";
} }
@ -124,94 +130,116 @@ fill_keybuf (char *keybuf, ClutterKeyEvent *event)
/* printable character, if any (ß, ∑) */ /* printable character, if any (ß, ∑) */
len = g_unichar_to_utf8 (event->unicode_value, utf8); len = g_unichar_to_utf8 (event->unicode_value, utf8);
utf8[len] = '\0'; utf8[len] = '\0';
sprintf(keybuf, "'%s' ", utf8); sprintf (keybuf, "'%s' ", utf8);
/* key combination (<Mod1>s, <Shift><Mod1>S, <Ctrl><Mod1>Delete) */ /* key combination (<Mod1>s, <Shift><Mod1>S, <Ctrl><Mod1>Delete) */
len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->keyval), len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->keyval), utf8);
utf8);
utf8[len] = '\0'; utf8[len] = '\0';
if (event->modifier_state & CLUTTER_SHIFT_MASK) if (event->modifier_state & CLUTTER_SHIFT_MASK)
strcat (keybuf, "<Shift>"); strcat (keybuf, "<Shift>");
if (event->modifier_state & CLUTTER_LOCK_MASK) if (event->modifier_state & CLUTTER_LOCK_MASK)
strcat (keybuf, "<Lock>"); strcat (keybuf, "<Lock>");
if (event->modifier_state & CLUTTER_CONTROL_MASK) if (event->modifier_state & CLUTTER_CONTROL_MASK)
strcat (keybuf, "<Control>"); strcat (keybuf, "<Control>");
if (event->modifier_state & CLUTTER_MOD1_MASK) if (event->modifier_state & CLUTTER_MOD1_MASK)
strcat (keybuf, "<Mod1>"); strcat (keybuf, "<Mod1>");
if (event->modifier_state & CLUTTER_MOD2_MASK) if (event->modifier_state & CLUTTER_MOD2_MASK)
strcat (keybuf, "<Mod2>"); strcat (keybuf, "<Mod2>");
if (event->modifier_state & CLUTTER_MOD3_MASK) if (event->modifier_state & CLUTTER_MOD3_MASK)
strcat (keybuf, "<Mod3>"); strcat (keybuf, "<Mod3>");
if (event->modifier_state & CLUTTER_MOD4_MASK) if (event->modifier_state & CLUTTER_MOD4_MASK)
strcat (keybuf, "<Mod4>"); strcat (keybuf, "<Mod4>");
if (event->modifier_state & CLUTTER_MOD5_MASK) if (event->modifier_state & CLUTTER_MOD5_MASK)
strcat (keybuf, "<Mod5>"); strcat (keybuf, "<Mod5>");
strcat (keybuf, utf8); strcat (keybuf, utf8);
} }
static gboolean static gboolean
input_cb (ClutterActor *actor, input_cb (ClutterActor *actor,
ClutterEvent *event, ClutterEvent *event,
gpointer data) gpointer data)
{ {
ClutterStage *stage = CLUTTER_STAGE (clutter_stage_get_default ()); ClutterStage *stage = CLUTTER_STAGE (clutter_stage_get_default ());
gchar keybuf[128], *source = (gchar*)data; ClutterActor *source_actor = clutter_event_get_source (event);
gchar keybuf[128];
switch (event->type) switch (event->type)
{ {
case CLUTTER_KEY_PRESS: case CLUTTER_KEY_PRESS:
fill_keybuf (keybuf, &event->key); fill_keybuf (keybuf, &event->key);
printf ("[%s] KEY PRESS %s", source, keybuf); printf ("[%s] KEY PRESS %s",
clutter_actor_get_name (source_actor),
keybuf);
break; break;
case CLUTTER_KEY_RELEASE: case CLUTTER_KEY_RELEASE:
fill_keybuf (keybuf, &event->key); fill_keybuf (keybuf, &event->key);
printf ("[%s] KEY RELEASE %s", source, keybuf); printf ("[%s] KEY RELEASE %s",
clutter_actor_get_name (source_actor),
keybuf);
break; break;
case CLUTTER_MOTION: case CLUTTER_MOTION:
g_print ("[%s] MOTION", source); g_print ("[%s] MOTION",
clutter_actor_get_name (source_actor));
break; break;
case CLUTTER_ENTER: case CLUTTER_ENTER:
g_print ("[%s] ENTER", source); g_print ("[%s] ENTER (from:%s)",
clutter_actor_get_name (source_actor),
clutter_actor_get_name (clutter_event_get_related (event)));
break; break;
case CLUTTER_LEAVE: case CLUTTER_LEAVE:
g_print ("[%s] LEAVE", source); g_print ("[%s] LEAVE (to:%s)",
clutter_actor_get_name (source_actor),
clutter_actor_get_name (clutter_event_get_related (event)));
break; break;
case CLUTTER_BUTTON_PRESS: case CLUTTER_BUTTON_PRESS:
g_print ("[%s] BUTTON PRESS (click count:%i)", g_print ("[%s] BUTTON PRESS (click count:%i)",
source, event->button.click_count); clutter_actor_get_name (source_actor),
clutter_event_get_click_count (event));
break; break;
case CLUTTER_BUTTON_RELEASE: case CLUTTER_BUTTON_RELEASE:
g_print ("[%s] BUTTON RELEASE (click count:%i)", g_print ("[%s] BUTTON RELEASE (click count:%i)",
source, event->button.click_count); clutter_actor_get_name (source_actor),
clutter_event_get_button (event));
if (clutter_event_get_source (event) == CLUTTER_ACTOR (stage)) if (source_actor == 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 (source_actor == actor &&
&& clutter_actor_get_parent (actor) == CLUTTER_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:
g_print ("[%s] BUTTON SCROLL (click count:%i)", g_print ("[%s] BUTTON SCROLL (direction:%s)",
source, event->button.click_count); clutter_actor_get_name (source_actor),
clutter_event_get_scroll_direction (event) == CLUTTER_SCROLL_UP
? "up"
: "down");
break; break;
case CLUTTER_STAGE_STATE: case CLUTTER_STAGE_STATE:
g_print ("[%s] STAGE STATE", source); g_print ("[%s] STAGE STATE", clutter_actor_get_name (source_actor));
break; break;
case CLUTTER_DESTROY_NOTIFY: case CLUTTER_DESTROY_NOTIFY:
g_print ("[%s] DESTROY NOTIFY", source); g_print ("[%s] DESTROY NOTIFY", clutter_actor_get_name (source_actor));
break; break;
case CLUTTER_CLIENT_MESSAGE: case CLUTTER_CLIENT_MESSAGE:
g_print ("[%s] CLIENT MESSAGE", source); g_print ("[%s] CLIENT MESSAGE", clutter_actor_get_name (source_actor));
break; break;
case CLUTTER_DELETE: case CLUTTER_DELETE:
g_print ("[%s] DELETE", source); g_print ("[%s] DELETE", clutter_actor_get_name (source_actor));
break; break;
case CLUTTER_NOTHING: case CLUTTER_NOTHING:
return FALSE; return FALSE;
} }
if (clutter_event_get_source (event) == actor) if (source_actor == actor)
g_print (" *source*"); g_print (" *source*");
g_print ("\n"); g_print ("\n");
@ -234,8 +262,8 @@ test_events_main (int argc, char *argv[])
stage = clutter_stage_get_default (); stage = clutter_stage_get_default ();
clutter_actor_set_name (stage, "Stage");
g_signal_connect (stage, "event", G_CALLBACK (input_cb), "stage"); g_signal_connect (stage, "event", G_CALLBACK (input_cb), "stage");
g_signal_connect (stage, "fullscreen", g_signal_connect (stage, "fullscreen",
G_CALLBACK (stage_state_cb), "fullscreen"); G_CALLBACK (stage_state_cb), "fullscreen");
g_signal_connect (stage, "unfullscreen", g_signal_connect (stage, "unfullscreen",
@ -244,24 +272,21 @@ test_events_main (int argc, char *argv[])
G_CALLBACK (stage_state_cb), "activate"); G_CALLBACK (stage_state_cb), "activate");
g_signal_connect (stage, "deactivate", g_signal_connect (stage, "deactivate",
G_CALLBACK (stage_state_cb), "deactivate"); G_CALLBACK (stage_state_cb), "deactivate");
/*g_signal_connect (stage, "captured-event", G_CALLBACK (capture_cb), NULL);*/
g_signal_connect (stage, "captured-event", G_CALLBACK (capture_cb), NULL);
focus_box = clutter_rectangle_new_with_color (&ncol); focus_box = clutter_rectangle_new_with_color (&ncol);
clutter_actor_set_name (focus_box, "Focus Box");
clutter_container_add (CLUTTER_CONTAINER(stage), focus_box, NULL); clutter_container_add (CLUTTER_CONTAINER(stage), focus_box, NULL);
actor = clutter_rectangle_new_with_color (&rcol); actor = clutter_rectangle_new_with_color (&rcol);
clutter_actor_set_name (actor, "Red Box");
clutter_actor_set_size (actor, 100, 100); clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_position (actor, 100, 100); clutter_actor_set_position (actor, 100, 100);
clutter_actor_set_reactive (actor, TRUE); clutter_actor_set_reactive (actor, TRUE);
clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL); clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL);
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "red box"); g_signal_connect (actor, "event", G_CALLBACK (input_cb), "red box");
g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb), g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb),
focus_box); focus_box);
/* Toggle motion - enter/leave capture */ /* Toggle motion - enter/leave capture */
g_signal_connect (actor, "button-press-event", g_signal_connect (actor, "button-press-event",
G_CALLBACK (red_button_cb), NULL); G_CALLBACK (red_button_cb), NULL);
@ -269,27 +294,22 @@ test_events_main (int argc, char *argv[])
clutter_stage_set_key_focus (CLUTTER_STAGE (stage), actor); clutter_stage_set_key_focus (CLUTTER_STAGE (stage), actor);
actor = clutter_rectangle_new_with_color (&gcol); actor = clutter_rectangle_new_with_color (&gcol);
clutter_actor_set_name (actor, "Green Box");
clutter_actor_set_size (actor, 100, 100); clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_position (actor, 250, 100); clutter_actor_set_position (actor, 250, 100);
clutter_actor_set_reactive (actor, TRUE); clutter_actor_set_reactive (actor, TRUE);
clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL); clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL);
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "green box"); g_signal_connect (actor, "event", G_CALLBACK (input_cb), "green box");
g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb), g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb),
focus_box); focus_box);
g_signal_connect (actor, "captured-event", G_CALLBACK (capture_cb), NULL); g_signal_connect (actor, "captured-event", G_CALLBACK (capture_cb), NULL);
actor = clutter_rectangle_new_with_color (&bcol); actor = clutter_rectangle_new_with_color (&bcol);
clutter_actor_set_name (actor, "Blue Box");
clutter_actor_set_size (actor, 100, 100); clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_position (actor, 400, 100); clutter_actor_set_position (actor, 400, 100);
clutter_actor_set_reactive (actor, TRUE); clutter_actor_set_reactive (actor, TRUE);
clutter_container_add (CLUTTER_CONTAINER(stage), actor, NULL); clutter_container_add (CLUTTER_CONTAINER(stage), actor, NULL);
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "blue box"); g_signal_connect (actor, "event", G_CALLBACK (input_cb), "blue box");
g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb), g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb),
focus_box); focus_box);
@ -299,20 +319,19 @@ test_events_main (int argc, char *argv[])
/* non reactive */ /* non reactive */
actor = clutter_rectangle_new_with_color (&ncol); actor = clutter_rectangle_new_with_color (&ncol);
clutter_actor_set_name (actor, "Black Box");
clutter_actor_set_size (actor, 400, 50); clutter_actor_set_size (actor, 400, 50);
clutter_actor_set_position (actor, 100, 250); clutter_actor_set_position (actor, 100, 250);
clutter_container_add (CLUTTER_CONTAINER(stage), actor, NULL); clutter_container_add (CLUTTER_CONTAINER(stage), actor, NULL);
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "blue box"); g_signal_connect (actor, "event", G_CALLBACK (input_cb), "blue box");
g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb), g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb),
focus_box); focus_box);
g_signal_connect (stage, "key-focus-in", G_CALLBACK (key_focus_in_cb), g_signal_connect (stage, "key-focus-in", G_CALLBACK (key_focus_in_cb),
focus_box); focus_box);
/* non reactive group, with reactive child */ /* non reactive group, with reactive child */
actor = clutter_rectangle_new_with_color (&ycol); actor = clutter_rectangle_new_with_color (&ycol);
clutter_actor_set_name (actor, "Yellow Box");
clutter_actor_set_size (actor, 100, 100); clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_reactive (actor, TRUE); clutter_actor_set_reactive (actor, TRUE);