2008-11-07 19:32:28 +00:00
|
|
|
#include <gmodule.h>
|
2007-05-09 23:31:08 +00:00
|
|
|
#include <clutter/clutter.h>
|
2008-06-10 10:57:50 +00:00
|
|
|
#include <string.h>
|
2007-05-09 23:31:08 +00:00
|
|
|
|
2007-11-19 16:30:56 +00:00
|
|
|
gboolean IsFullScreen = FALSE, IsMotion = TRUE;
|
2007-08-13 20:48:01 +00:00
|
|
|
|
2007-08-24 15:12:52 +00:00
|
|
|
static void
|
|
|
|
stage_state_cb (ClutterStage *stage,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gchar *detail = (gchar*)data;
|
|
|
|
|
|
|
|
printf("[stage signal] %s\n", detail);
|
|
|
|
}
|
|
|
|
|
2007-10-02 14:03:36 +00:00
|
|
|
static gboolean
|
2007-08-24 15:12:52 +00:00
|
|
|
blue_button_cb (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
ClutterActor *stage;
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
|
|
|
|
if (IsFullScreen)
|
|
|
|
IsFullScreen = FALSE;
|
|
|
|
else
|
|
|
|
IsFullScreen = TRUE;
|
|
|
|
|
|
|
|
g_object_set (stage, "fullscreen", IsFullScreen, NULL);
|
2007-10-02 14:03:36 +00:00
|
|
|
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("*** Fullscreen %s ***\n",
|
|
|
|
IsFullScreen ? "enabled" : "disabled");
|
|
|
|
|
2007-10-02 14:03:36 +00:00
|
|
|
return FALSE;
|
2007-08-24 15:12:52 +00:00
|
|
|
}
|
2007-08-13 20:48:01 +00:00
|
|
|
|
2007-10-03 09:28:16 +00:00
|
|
|
static gboolean
|
|
|
|
red_button_cb (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (IsMotion)
|
|
|
|
IsMotion = FALSE;
|
|
|
|
else
|
|
|
|
IsMotion = TRUE;
|
|
|
|
|
2007-11-19 16:30:56 +00:00
|
|
|
clutter_set_motion_events_enabled (IsMotion);
|
2007-10-10 13:04:34 +00:00
|
|
|
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("*** Per actor motion events %s ***\n",
|
|
|
|
IsMotion ? "enabled" : "disabled");
|
|
|
|
|
2007-10-10 13:04:34 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2008-05-14 16:47:38 +00:00
|
|
|
capture_cb (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
gpointer data)
|
2007-10-10 13:04:34 +00:00
|
|
|
{
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("* captured event for type '%s' *\n",
|
|
|
|
G_OBJECT_TYPE_NAME (actor));
|
2007-10-10 13:04:34 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2007-10-03 09:28:16 +00:00
|
|
|
}
|
|
|
|
|
2007-10-02 14:03:36 +00:00
|
|
|
static void
|
2007-08-13 20:48:01 +00:00
|
|
|
key_focus_in_cb (ClutterActor *actor,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
ClutterActor *focus_box = CLUTTER_ACTOR(data);
|
|
|
|
|
|
|
|
if (actor == clutter_stage_get_default ())
|
2008-05-14 16:47:38 +00:00
|
|
|
clutter_actor_hide (focus_box);
|
2007-08-13 20:48:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
clutter_actor_set_position (focus_box,
|
|
|
|
clutter_actor_get_x (actor) - 5,
|
|
|
|
clutter_actor_get_y (actor) - 5);
|
|
|
|
|
|
|
|
clutter_actor_set_size (focus_box,
|
|
|
|
clutter_actor_get_width (actor) + 10,
|
|
|
|
clutter_actor_get_height (actor) + 10);
|
2007-10-02 14:03:36 +00:00
|
|
|
clutter_actor_show (focus_box);
|
2007-08-13 20:48:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-10 10:57:50 +00:00
|
|
|
static void
|
|
|
|
fill_keybuf (char *keybuf, ClutterKeyEvent *event)
|
|
|
|
{
|
|
|
|
char utf8[6];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* printable character, if any (ß, ∑) */
|
|
|
|
len = g_unichar_to_utf8 (event->unicode_value, utf8);
|
|
|
|
utf8[len] = '\0';
|
|
|
|
sprintf(keybuf, "'%s' ", utf8);
|
|
|
|
|
|
|
|
/* key combination (<Mod1>s, <Shift><Mod1>S, <Ctrl><Mod1>Delete) */
|
|
|
|
len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->keyval),
|
|
|
|
utf8);
|
|
|
|
utf8[len] = '\0';
|
|
|
|
|
|
|
|
if (event->modifier_state & CLUTTER_SHIFT_MASK)
|
|
|
|
strcat (keybuf, "<Shift>");
|
|
|
|
if (event->modifier_state & CLUTTER_LOCK_MASK)
|
|
|
|
strcat (keybuf, "<Lock>");
|
|
|
|
if (event->modifier_state & CLUTTER_CONTROL_MASK)
|
|
|
|
strcat (keybuf, "<Control>");
|
|
|
|
if (event->modifier_state & CLUTTER_MOD1_MASK)
|
|
|
|
strcat (keybuf, "<Mod1>");
|
|
|
|
if (event->modifier_state & CLUTTER_MOD2_MASK)
|
|
|
|
strcat (keybuf, "<Mod2>");
|
|
|
|
if (event->modifier_state & CLUTTER_MOD3_MASK)
|
|
|
|
strcat (keybuf, "<Mod3>");
|
|
|
|
if (event->modifier_state & CLUTTER_MOD4_MASK)
|
|
|
|
strcat (keybuf, "<Mod4>");
|
|
|
|
if (event->modifier_state & CLUTTER_MOD5_MASK)
|
|
|
|
strcat (keybuf, "<Mod5>");
|
|
|
|
strcat (keybuf, utf8);
|
|
|
|
}
|
|
|
|
|
2007-10-02 14:03:36 +00:00
|
|
|
static gboolean
|
2007-08-13 20:48:01 +00:00
|
|
|
input_cb (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
gpointer data)
|
2007-05-09 23:31:08 +00:00
|
|
|
{
|
2007-10-02 14:03:36 +00:00
|
|
|
ClutterStage *stage = CLUTTER_STAGE (clutter_stage_get_default ());
|
2008-06-10 10:57:50 +00:00
|
|
|
gchar keybuf[128], *source = (gchar*)data;
|
2007-06-18 09:15:00 +00:00
|
|
|
|
2007-05-09 23:31:08 +00:00
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case CLUTTER_KEY_PRESS:
|
2008-06-10 10:57:50 +00:00
|
|
|
fill_keybuf (keybuf, &event->key);
|
|
|
|
printf ("[%s] KEY PRESS %s", source, keybuf);
|
2007-05-09 23:31:08 +00:00
|
|
|
break;
|
|
|
|
case CLUTTER_KEY_RELEASE:
|
2008-06-10 10:57:50 +00:00
|
|
|
fill_keybuf (keybuf, &event->key);
|
|
|
|
printf ("[%s] KEY RELEASE %s", source, keybuf);
|
2007-05-09 23:31:08 +00:00
|
|
|
break;
|
|
|
|
case CLUTTER_MOTION:
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("[%s] MOTION", source);
|
2007-05-09 23:31:08 +00:00
|
|
|
break;
|
2007-10-03 09:28:16 +00:00
|
|
|
case CLUTTER_ENTER:
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("[%s] ENTER", source);
|
2007-05-09 23:31:08 +00:00
|
|
|
break;
|
2007-10-03 09:28:16 +00:00
|
|
|
case CLUTTER_LEAVE:
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("[%s] LEAVE", source);
|
2007-05-09 23:31:08 +00:00
|
|
|
break;
|
2007-10-03 09:28:16 +00:00
|
|
|
case CLUTTER_BUTTON_PRESS:
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("[%s] BUTTON PRESS (click count:%i)",
|
|
|
|
source, event->button.click_count);
|
2007-05-09 23:31:08 +00:00
|
|
|
break;
|
|
|
|
case CLUTTER_BUTTON_RELEASE:
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("[%s] BUTTON RELEASE (click count:%i)",
|
|
|
|
source, event->button.click_count);
|
2007-11-20 17:14:05 +00:00
|
|
|
|
2007-10-02 14:03:36 +00:00
|
|
|
if (clutter_event_get_source (event) == CLUTTER_ACTOR (stage))
|
|
|
|
clutter_stage_set_key_focus (stage, NULL);
|
2007-11-18 23:24:55 +00:00
|
|
|
else if (clutter_event_get_source (event) == actor
|
2007-11-20 17:14:05 +00:00
|
|
|
&& clutter_actor_get_parent (actor) == CLUTTER_ACTOR (stage))
|
2007-10-02 14:03:36 +00:00
|
|
|
clutter_stage_set_key_focus (stage, actor);
|
2007-05-09 23:31:08 +00:00
|
|
|
break;
|
|
|
|
case CLUTTER_SCROLL:
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("[%s] BUTTON SCROLL (click count:%i)",
|
|
|
|
source, event->button.click_count);
|
2007-05-09 23:31:08 +00:00
|
|
|
break;
|
|
|
|
case CLUTTER_STAGE_STATE:
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("[%s] STAGE STATE", source);
|
2007-05-09 23:31:08 +00:00
|
|
|
break;
|
|
|
|
case CLUTTER_DESTROY_NOTIFY:
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("[%s] DESTROY NOTIFY", source);
|
2007-05-09 23:31:08 +00:00
|
|
|
break;
|
|
|
|
case CLUTTER_CLIENT_MESSAGE:
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("[%s] CLIENT MESSAGE", source);
|
2007-05-09 23:31:08 +00:00
|
|
|
break;
|
|
|
|
case CLUTTER_DELETE:
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print ("[%s] DELETE", source);
|
2007-05-09 23:31:08 +00:00
|
|
|
break;
|
2007-07-26 11:04:04 +00:00
|
|
|
case CLUTTER_NOTHING:
|
2007-12-09 08:53:06 +00:00
|
|
|
return FALSE;
|
2007-05-09 23:31:08 +00:00
|
|
|
}
|
2007-08-13 20:48:01 +00:00
|
|
|
|
|
|
|
if (clutter_event_get_source (event) == actor)
|
2008-05-14 16:47:38 +00:00
|
|
|
g_print (" *source*");
|
2007-10-02 14:03:36 +00:00
|
|
|
|
2008-06-13 15:01:34 +00:00
|
|
|
g_print ("\n");
|
2007-08-13 20:48:01 +00:00
|
|
|
|
2007-10-02 14:03:36 +00:00
|
|
|
return FALSE;
|
2007-05-09 23:31:08 +00:00
|
|
|
}
|
|
|
|
|
2008-11-07 19:32:28 +00:00
|
|
|
G_MODULE_EXPORT int
|
|
|
|
test_events_main (int argc, char *argv[])
|
2007-05-09 23:31:08 +00:00
|
|
|
{
|
2007-11-18 23:24:55 +00:00
|
|
|
ClutterActor *stage, *actor, *focus_box, *group;
|
2007-08-13 20:48:01 +00:00
|
|
|
ClutterColor rcol = { 0xff, 0, 0, 0xff},
|
|
|
|
bcol = { 0, 0, 0xff, 0xff },
|
|
|
|
gcol = { 0, 0xff, 0, 0xff },
|
2007-11-18 23:24:55 +00:00
|
|
|
ycol = { 0xff, 0xff, 0, 0xff },
|
2007-08-13 20:48:01 +00:00
|
|
|
ncol = { 0, 0, 0, 0xff };
|
2007-05-09 23:31:08 +00:00
|
|
|
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
2007-10-03 09:28:16 +00:00
|
|
|
|
|
|
|
|
2007-05-09 23:31:08 +00:00
|
|
|
stage = clutter_stage_get_default ();
|
2007-08-13 20:48:01 +00:00
|
|
|
g_signal_connect (stage, "event", G_CALLBACK (input_cb), "stage");
|
2007-10-10 13:04:34 +00:00
|
|
|
|
2007-08-24 15:12:52 +00:00
|
|
|
g_signal_connect (stage, "fullscreen",
|
|
|
|
G_CALLBACK (stage_state_cb), "fullscreen");
|
|
|
|
g_signal_connect (stage, "unfullscreen",
|
|
|
|
G_CALLBACK (stage_state_cb), "unfullscreen");
|
|
|
|
g_signal_connect (stage, "activate",
|
|
|
|
G_CALLBACK (stage_state_cb), "activate");
|
|
|
|
g_signal_connect (stage, "deactivate",
|
|
|
|
G_CALLBACK (stage_state_cb), "deactivate");
|
2007-08-13 20:48:01 +00:00
|
|
|
|
2007-10-10 13:04:34 +00:00
|
|
|
g_signal_connect (stage, "captured-event", G_CALLBACK (capture_cb), NULL);
|
|
|
|
|
2007-08-13 20:48:01 +00:00
|
|
|
focus_box = clutter_rectangle_new_with_color (&ncol);
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER(stage), focus_box, NULL);
|
|
|
|
|
|
|
|
actor = clutter_rectangle_new_with_color (&rcol);
|
|
|
|
clutter_actor_set_size (actor, 100, 100);
|
|
|
|
clutter_actor_set_position (actor, 100, 100);
|
|
|
|
|
2007-11-15 17:35:47 +00:00
|
|
|
clutter_actor_set_reactive (actor, TRUE);
|
2007-08-13 20:48:01 +00:00
|
|
|
|
2007-10-02 14:03:36 +00:00
|
|
|
clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL);
|
2007-08-13 20:48:01 +00:00
|
|
|
|
|
|
|
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "red box");
|
2009-06-08 09:58:20 +00:00
|
|
|
g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb),
|
2007-08-13 20:48:01 +00:00
|
|
|
focus_box);
|
|
|
|
|
2007-10-03 09:28:16 +00:00
|
|
|
/* Toggle motion - enter/leave capture */
|
2008-05-14 16:47:38 +00:00
|
|
|
g_signal_connect (actor, "button-press-event",
|
|
|
|
G_CALLBACK (red_button_cb), NULL);
|
2007-10-03 09:28:16 +00:00
|
|
|
|
2007-09-28 11:03:21 +00:00
|
|
|
clutter_stage_set_key_focus (CLUTTER_STAGE (stage), actor);
|
2007-08-13 20:48:01 +00:00
|
|
|
|
|
|
|
actor = clutter_rectangle_new_with_color (&gcol);
|
|
|
|
clutter_actor_set_size (actor, 100, 100);
|
|
|
|
clutter_actor_set_position (actor, 250, 100);
|
|
|
|
|
2007-11-15 17:35:47 +00:00
|
|
|
clutter_actor_set_reactive (actor, TRUE);
|
2007-08-13 20:48:01 +00:00
|
|
|
|
2007-10-02 14:03:36 +00:00
|
|
|
clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL);
|
2007-08-13 20:48:01 +00:00
|
|
|
|
|
|
|
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "green box");
|
2009-06-08 09:58:20 +00:00
|
|
|
g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb),
|
2007-08-13 20:48:01 +00:00
|
|
|
focus_box);
|
|
|
|
|
2007-10-10 13:04:34 +00:00
|
|
|
g_signal_connect (actor, "captured-event", G_CALLBACK (capture_cb), NULL);
|
|
|
|
|
2007-08-13 20:48:01 +00:00
|
|
|
actor = clutter_rectangle_new_with_color (&bcol);
|
|
|
|
clutter_actor_set_size (actor, 100, 100);
|
|
|
|
clutter_actor_set_position (actor, 400, 100);
|
|
|
|
|
2007-11-15 17:35:47 +00:00
|
|
|
clutter_actor_set_reactive (actor, TRUE);
|
2007-08-13 20:48:01 +00:00
|
|
|
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER(stage), actor, NULL);
|
|
|
|
|
|
|
|
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "blue box");
|
2009-06-08 09:58:20 +00:00
|
|
|
g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb),
|
2007-08-13 20:48:01 +00:00
|
|
|
focus_box);
|
2007-10-03 09:28:16 +00:00
|
|
|
/* Fullscreen */
|
2008-05-14 16:47:38 +00:00
|
|
|
g_signal_connect (actor, "button-press-event",
|
|
|
|
G_CALLBACK (blue_button_cb), NULL);
|
2007-08-13 20:48:01 +00:00
|
|
|
|
2007-11-18 23:24:55 +00:00
|
|
|
/* non reactive */
|
2007-08-13 20:48:01 +00:00
|
|
|
actor = clutter_rectangle_new_with_color (&ncol);
|
|
|
|
clutter_actor_set_size (actor, 400, 50);
|
|
|
|
clutter_actor_set_position (actor, 100, 250);
|
|
|
|
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER(stage), actor, NULL);
|
|
|
|
|
|
|
|
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "blue box");
|
2009-06-08 09:58:20 +00:00
|
|
|
g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb),
|
2007-08-13 20:48:01 +00:00
|
|
|
focus_box);
|
|
|
|
|
2009-06-08 09:58:20 +00:00
|
|
|
g_signal_connect (stage, "key-focus-in", G_CALLBACK (key_focus_in_cb),
|
2007-08-13 20:48:01 +00:00
|
|
|
focus_box);
|
|
|
|
|
2007-11-18 23:24:55 +00:00
|
|
|
/* non reactive group, with reactive child */
|
|
|
|
actor = clutter_rectangle_new_with_color (&ycol);
|
|
|
|
clutter_actor_set_size (actor, 100, 100);
|
|
|
|
clutter_actor_set_reactive (actor, TRUE);
|
|
|
|
|
|
|
|
g_signal_connect (actor, "event", G_CALLBACK (input_cb), "yellow box");
|
|
|
|
|
|
|
|
/* note group not reactive */
|
|
|
|
group = clutter_group_new ();
|
2008-05-14 16:47:38 +00:00
|
|
|
clutter_container_add (CLUTTER_CONTAINER (group), actor, NULL);
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER (stage), group, NULL);
|
2007-11-18 23:24:55 +00:00
|
|
|
clutter_actor_set_position (group, 100, 350);
|
|
|
|
clutter_actor_show_all (group);
|
2007-08-13 20:48:01 +00:00
|
|
|
|
2007-05-09 23:31:08 +00:00
|
|
|
clutter_actor_show_all (CLUTTER_ACTOR (stage));
|
|
|
|
|
|
|
|
clutter_main();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|