2009-06-19 08:07:20 -04:00
|
|
|
#include <stdlib.h>
|
2008-11-07 14:32:28 -05:00
|
|
|
#include <gmodule.h>
|
2008-06-23 05:55:42 -04:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <clutter/x11/clutter-x11.h>
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
|
|
|
GHashTable *devices;
|
|
|
|
|
|
|
|
} TestDevicesApp;
|
|
|
|
|
2010-01-15 07:24:21 -05:00
|
|
|
static const gchar *
|
|
|
|
device_type_name (ClutterInputDevice *device)
|
|
|
|
{
|
|
|
|
ClutterInputDeviceType d_type;
|
|
|
|
|
|
|
|
d_type = clutter_input_device_get_device_type (device);
|
|
|
|
switch (d_type)
|
|
|
|
{
|
|
|
|
case CLUTTER_POINTER_DEVICE:
|
|
|
|
return "Pointer";
|
|
|
|
|
|
|
|
case CLUTTER_KEYBOARD_DEVICE:
|
|
|
|
return "Keyboard";
|
|
|
|
|
|
|
|
case CLUTTER_EXTENSION_DEVICE:
|
|
|
|
return "Extension";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
g_warn_if_reached ();
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-23 05:55:42 -04:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
stage_motion_event_cb (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
gpointer userdata)
|
|
|
|
{
|
|
|
|
TestDevicesApp *app = (TestDevicesApp *)userdata;
|
2009-06-19 08:07:20 -04:00
|
|
|
ClutterInputDevice *device;
|
2008-06-23 05:55:42 -04:00
|
|
|
ClutterActor *hand = NULL;
|
|
|
|
|
2009-06-19 08:07:20 -04:00
|
|
|
device = clutter_event_get_device (event);
|
|
|
|
|
|
|
|
hand = g_hash_table_lookup (app->devices, device);
|
|
|
|
|
2010-01-15 07:24:21 -05:00
|
|
|
g_print ("Device: '%s' (id:%d, type:%s)\n",
|
|
|
|
clutter_input_device_get_device_name (device),
|
|
|
|
clutter_input_device_get_device_id (device),
|
|
|
|
device_type_name (device));
|
|
|
|
|
2009-06-19 08:07:20 -04:00
|
|
|
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 12:43:49 -04:00
|
|
|
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 07:32:04 -05:00
|
|
|
if (event->motion.axes != NULL)
|
|
|
|
{
|
|
|
|
guint n_axes = clutter_input_device_get_n_axes (event->motion.device);
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < n_axes; i++)
|
|
|
|
{
|
|
|
|
g_print ("Axis[%02d].value: %.2f\n",
|
|
|
|
i,
|
|
|
|
event->motion.axes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-23 12:43:49 -04:00
|
|
|
return FALSE;
|
2008-06-23 05:55:42 -04:00
|
|
|
}
|
|
|
|
|
2008-11-07 14:32:28 -05:00
|
|
|
G_MODULE_EXPORT int
|
|
|
|
test_devices_main (int argc, char **argv)
|
2008-06-23 05:55:42 -04:00
|
|
|
{
|
2009-06-19 08:07:20 -04:00
|
|
|
ClutterActor *stage;
|
|
|
|
TestDevicesApp *app;
|
2008-06-23 05:55:42 -04:00
|
|
|
ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff };
|
2009-11-20 11:37:58 -05:00
|
|
|
ClutterDeviceManager *manager;
|
2009-06-19 08:07:20 -04:00
|
|
|
const GSList *stage_devices, *l;
|
2008-06-23 05:55:42 -04:00
|
|
|
|
2009-06-19 09:20:50 -04:00
|
|
|
/* force enabling X11 support */
|
2008-07-01 09:41:23 -04:00
|
|
|
clutter_x11_enable_xinput ();
|
2009-06-19 09:20:50 -04:00
|
|
|
|
2008-06-23 05:55:42 -04: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 08:07:20 -04:00
|
|
|
"motion-event", G_CALLBACK(stage_motion_event_cb),
|
2008-06-23 05:55:42 -04:00
|
|
|
app);
|
2009-06-19 08:07:20 -04:00
|
|
|
|
2008-06-23 05:55:42 -04:00
|
|
|
clutter_actor_show_all (stage);
|
|
|
|
|
2009-11-20 11:37:58 -05:00
|
|
|
manager = clutter_device_manager_get_default ();
|
|
|
|
stage_devices = clutter_device_manager_peek_devices (manager);
|
2008-06-23 05:55:42 -04:00
|
|
|
|
2008-07-01 09:41:23 -04:00
|
|
|
if (stage_devices == NULL)
|
2009-11-20 11:37:58 -05:00
|
|
|
g_error ("No input devices found.");
|
2008-07-01 09:41:23 -04:00
|
|
|
|
2009-06-19 08:07:20 -04:00
|
|
|
for (l = stage_devices; l != NULL; l = l->next)
|
2008-06-23 05:55:42 -04:00
|
|
|
{
|
2009-06-19 08:07:20 -04:00
|
|
|
ClutterInputDevice *device = l->data;
|
|
|
|
ClutterInputDeviceType device_type;
|
|
|
|
ClutterActor *hand = NULL;
|
2008-06-23 05:55:42 -04:00
|
|
|
|
2010-01-20 14:40:58 -05:00
|
|
|
g_print ("got a %s device '%s' with id %d...\n",
|
|
|
|
device_type_name (device),
|
|
|
|
clutter_input_device_get_device_name (device),
|
|
|
|
clutter_input_device_get_device_id (device));
|
|
|
|
|
2009-06-19 08:07:20 -04:00
|
|
|
device_type = clutter_input_device_get_device_type (device);
|
2010-01-20 14:40:58 -05:00
|
|
|
if (device_type == CLUTTER_POINTER_DEVICE ||
|
|
|
|
device_type == CLUTTER_EXTENSION_DEVICE)
|
2009-06-19 08:07:20 -04:00
|
|
|
{
|
2009-11-05 12:30:33 -05:00
|
|
|
hand = clutter_texture_new_from_file (TESTS_DATADIR
|
|
|
|
G_DIR_SEPARATOR_S
|
|
|
|
"redhand.png",
|
|
|
|
NULL);
|
2009-06-19 08:07:20 -04:00
|
|
|
g_hash_table_insert (app->devices, device, hand);
|
2008-06-23 05:55:42 -04:00
|
|
|
|
2009-06-19 08:07:20 -04:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), hand);
|
2008-06-23 05:55:42 -04:00
|
|
|
}
|
2009-06-19 08:07:20 -04:00
|
|
|
}
|
2008-06-23 05:55:42 -04:00
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
2009-06-19 08:07:20 -04:00
|
|
|
return EXIT_SUCCESS;
|
2008-06-23 05:55:42 -04:00
|
|
|
}
|