mutter/tests/interactive/test-devices.c
Emmanuele Bassi 184df2a5fa [input] Rework input device API
The input device API is split halfway thorugh the backends in a very
weird way. The data structures are private, as they should, but most
of the information should be available in the main API since it's
generic enough.

The device type enumeration, for instance, should be common across
every backend; the accessors for device type and id should live in the
core API. The internal API should always use ClutterInputDevice and
not the private X11 implementation when dealing with public structures
like ClutterEvent.

By adding accessors for the device type and id, and by moving the
device type enumeration into the core API we can cut down the amount
of symbols private and/or visible only to the X11 backends; this way
when other backends start implementing multi-pointer support we can
share the same API across the code.
2009-06-19 13:12:05 +01:00

94 lines
2.2 KiB
C

#include <stdlib.h>
#include <gmodule.h>
#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;
ClutterInputDevice *device;
ClutterActor *hand = NULL;
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;
}
return FALSE;
}
G_MODULE_EXPORT int
test_devices_main (int argc, char **argv)
{
ClutterActor *stage;
TestDevicesApp *app;
ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff };
const GSList *stage_devices, *l;
g_type_init();
clutter_x11_enable_xinput ();
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,
"motion-event", G_CALLBACK(stage_motion_event_cb),
app);
clutter_actor_show_all (stage);
stage_devices = clutter_x11_get_input_devices ();
if (stage_devices == NULL)
g_error ("No extended input devices found.");
for (l = stage_devices; l != NULL; l = l->next)
{
ClutterInputDevice *device = l->data;
ClutterInputDeviceType device_type;
ClutterActor *hand = NULL;
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));
hand = clutter_texture_new_from_file ("redhand.png", NULL);
g_hash_table_insert (app->devices, device, hand);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), hand);
}
}
clutter_main ();
return EXIT_SUCCESS;
}