2009-06-19 12:07:20 +00:00
|
|
|
#include <stdlib.h>
|
2008-11-07 19:32:28 +00:00
|
|
|
#include <gmodule.h>
|
2008-06-23 09:55:42 +00:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <clutter/x11/clutter-x11.h>
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
|
|
|
GHashTable *devices;
|
|
|
|
|
|
|
|
} TestDevicesApp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
stage_motion_event_cb (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
gpointer userdata)
|
|
|
|
{
|
|
|
|
TestDevicesApp *app = (TestDevicesApp *)userdata;
|
2009-06-19 12:07:20 +00:00
|
|
|
ClutterInputDevice *device;
|
2008-06-23 09:55:42 +00:00
|
|
|
ClutterActor *hand = NULL;
|
|
|
|
|
2009-06-19 12:07:20 +00:00
|
|
|
device = clutter_event_get_device (event);
|
|
|
|
|
|
|
|
hand = g_hash_table_lookup (app->devices, device);
|
|
|
|
|
|
|
|
if (hand != NULL)
|
|
|
|
{
|
|
|
|
gfloat event_x, event_y;
|
|
|
|
|
|
|
|
clutter_event_get_coords (event, &event_x, &event_y);
|
|
|
|
clutter_actor_set_position (hand, event_x, event_y);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-06-23 16:43:49 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2008-06-23 09:55:42 +00:00
|
|
|
}
|
|
|
|
|
2008-11-07 19:32:28 +00:00
|
|
|
G_MODULE_EXPORT int
|
|
|
|
test_devices_main (int argc, char **argv)
|
2008-06-23 09:55:42 +00:00
|
|
|
{
|
2009-06-19 12:07:20 +00:00
|
|
|
ClutterActor *stage;
|
|
|
|
TestDevicesApp *app;
|
2008-06-23 09:55:42 +00:00
|
|
|
ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff };
|
2009-06-19 12:07:20 +00:00
|
|
|
const GSList *stage_devices, *l;
|
2008-06-23 09:55:42 +00:00
|
|
|
|
2009-06-19 13:20:50 +00:00
|
|
|
/* force enabling X11 support */
|
2008-07-01 13:41:23 +00:00
|
|
|
clutter_x11_enable_xinput ();
|
2009-06-19 13:20:50 +00:00
|
|
|
|
2008-06-23 09:55:42 +00:00
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
|
|
|
app = g_new0 (TestDevicesApp, 1);
|
|
|
|
app->devices = g_hash_table_new (g_direct_hash, g_direct_equal) ;
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
|
|
|
|
//clutter_stage_fullscreen (CLUTTER_STAGE (stage));
|
|
|
|
|
|
|
|
g_signal_connect (stage,
|
2009-06-19 12:07:20 +00:00
|
|
|
"motion-event", G_CALLBACK(stage_motion_event_cb),
|
2008-06-23 09:55:42 +00:00
|
|
|
app);
|
2009-06-19 12:07:20 +00:00
|
|
|
|
2008-06-23 09:55:42 +00:00
|
|
|
clutter_actor_show_all (stage);
|
|
|
|
|
|
|
|
stage_devices = clutter_x11_get_input_devices ();
|
|
|
|
|
2008-07-01 13:41:23 +00:00
|
|
|
if (stage_devices == NULL)
|
|
|
|
g_error ("No extended input devices found.");
|
|
|
|
|
2009-06-19 12:07:20 +00:00
|
|
|
for (l = stage_devices; l != NULL; l = l->next)
|
2008-06-23 09:55:42 +00:00
|
|
|
{
|
2009-06-19 12:07:20 +00:00
|
|
|
ClutterInputDevice *device = l->data;
|
|
|
|
ClutterInputDeviceType device_type;
|
|
|
|
ClutterActor *hand = NULL;
|
2008-06-23 09:55:42 +00:00
|
|
|
|
2009-06-19 12:07:20 +00:00
|
|
|
device_type = clutter_input_device_get_device_type (device);
|
|
|
|
if (device_type == CLUTTER_POINTER_DEVICE)
|
|
|
|
{
|
|
|
|
g_print ("got a pointer device with id %d...\n",
|
|
|
|
clutter_input_device_get_device_id (device));
|
2008-06-23 09:55:42 +00:00
|
|
|
|
2009-11-05 17:30:33 +00:00
|
|
|
hand = clutter_texture_new_from_file (TESTS_DATADIR
|
|
|
|
G_DIR_SEPARATOR_S
|
|
|
|
"redhand.png",
|
|
|
|
NULL);
|
2009-06-19 12:07:20 +00:00
|
|
|
g_hash_table_insert (app->devices, device, hand);
|
2008-06-23 09:55:42 +00:00
|
|
|
|
2009-06-19 12:07:20 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), hand);
|
2008-06-23 09:55:42 +00:00
|
|
|
}
|
2009-06-19 12:07:20 +00:00
|
|
|
}
|
2008-06-23 09:55:42 +00:00
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
2009-06-19 12:07:20 +00:00
|
|
|
return EXIT_SUCCESS;
|
2008-06-23 09:55:42 +00:00
|
|
|
}
|