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>
|
2011-10-17 15:06:15 +00:00
|
|
|
|
|
|
|
#ifdef CLUTTER_WINDOWING_X11
|
2008-06-23 09:55:42 +00:00
|
|
|
#include <clutter/x11/clutter-x11.h>
|
2011-10-17 15:06:15 +00:00
|
|
|
#endif
|
2008-06-23 09:55:42 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2011-01-21 11:41:36 +00:00
|
|
|
ClutterActor *stage;
|
2008-06-23 09:55:42 +00:00
|
|
|
|
|
|
|
GHashTable *devices;
|
|
|
|
} TestDevicesApp;
|
|
|
|
|
2010-01-15 12:24:21 +00: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";
|
|
|
|
|
2011-01-19 13:52:33 +00:00
|
|
|
case CLUTTER_PEN_DEVICE:
|
|
|
|
return "Pen";
|
|
|
|
|
|
|
|
case CLUTTER_ERASER_DEVICE:
|
|
|
|
return "Eraser";
|
|
|
|
|
|
|
|
case CLUTTER_CURSOR_DEVICE:
|
|
|
|
return "Cursor";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
axis_type_name (ClutterInputAxis axis)
|
|
|
|
{
|
|
|
|
switch (axis)
|
|
|
|
{
|
|
|
|
case CLUTTER_INPUT_AXIS_X:
|
|
|
|
return "Absolute X";
|
|
|
|
|
|
|
|
case CLUTTER_INPUT_AXIS_Y:
|
|
|
|
return "Absolute Y";
|
|
|
|
|
|
|
|
case CLUTTER_INPUT_AXIS_PRESSURE:
|
|
|
|
return "Pressure";
|
|
|
|
|
|
|
|
case CLUTTER_INPUT_AXIS_XTILT:
|
|
|
|
return "X Tilt";
|
|
|
|
|
|
|
|
case CLUTTER_INPUT_AXIS_YTILT:
|
|
|
|
return "Y Tilt";
|
|
|
|
|
|
|
|
case CLUTTER_INPUT_AXIS_WHEEL:
|
|
|
|
return "Wheel";
|
|
|
|
|
2010-01-15 12:24:21 +00:00
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
2008-06-23 09:55:42 +00:00
|
|
|
|
|
|
|
static gboolean
|
2011-01-21 11:41:36 +00:00
|
|
|
stage_button_event_cb (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
TestDevicesApp *app)
|
2008-06-23 09:55:42 +00:00
|
|
|
{
|
2009-06-19 12:07:20 +00:00
|
|
|
ClutterInputDevice *device;
|
2011-01-19 13:52:33 +00:00
|
|
|
ClutterInputDevice *source_device;
|
2008-06-23 09:55:42 +00:00
|
|
|
ClutterActor *hand = NULL;
|
2011-01-21 15:27:56 +00:00
|
|
|
gdouble *axes;
|
|
|
|
guint n_axes, i;
|
2008-06-23 09:55:42 +00:00
|
|
|
|
2009-06-19 12:07:20 +00:00
|
|
|
device = clutter_event_get_device (event);
|
2011-01-19 13:52:33 +00:00
|
|
|
source_device = clutter_event_get_source_device (event);
|
2009-06-19 12:07:20 +00:00
|
|
|
|
|
|
|
hand = g_hash_table_lookup (app->devices, device);
|
|
|
|
|
2011-01-21 15:27:56 +00:00
|
|
|
g_print ("Device: '%s' (id:%d, type: %s, source: '%s', axes: %d)\n",
|
2010-01-15 12:24:21 +00:00
|
|
|
clutter_input_device_get_device_name (device),
|
|
|
|
clutter_input_device_get_device_id (device),
|
2011-01-19 13:52:33 +00:00
|
|
|
device_type_name (device),
|
|
|
|
source_device != device
|
|
|
|
? clutter_input_device_get_device_name (source_device)
|
2011-01-21 15:27:56 +00:00
|
|
|
: "<same>",
|
|
|
|
clutter_input_device_get_n_axes (device));
|
2010-01-15 12:24:21 +00:00
|
|
|
|
2009-06-19 12:07:20 +00: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);
|
|
|
|
}
|
2008-06-23 16:43:49 +00:00
|
|
|
|
2011-01-21 15:27:56 +00:00
|
|
|
axes = clutter_event_get_axes (event, &n_axes);
|
|
|
|
for (i = 0; i < n_axes; i++)
|
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 12:32:04 +00:00
|
|
|
{
|
2011-01-21 15:27:56 +00:00
|
|
|
ClutterInputAxis axis;
|
|
|
|
|
|
|
|
axis = clutter_input_device_get_axis (device, i);
|
|
|
|
if (axis == CLUTTER_INPUT_AXIS_IGNORE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_print ("\tAxis[%2d][%s].value: %.2f\n",
|
|
|
|
i,
|
|
|
|
axis_type_name (axis),
|
|
|
|
axes[i]);
|
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 12:32:04 +00:00
|
|
|
}
|
|
|
|
|
2008-06-23 16:43:49 +00:00
|
|
|
return FALSE;
|
2008-06-23 09:55:42 +00:00
|
|
|
}
|
|
|
|
|
2011-01-19 13:52:33 +00:00
|
|
|
static gboolean
|
2011-01-21 11:41:36 +00:00
|
|
|
stage_motion_event_cb (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
TestDevicesApp *app)
|
2011-01-19 13:52:33 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-01-21 11:41:36 +00:00
|
|
|
static void
|
|
|
|
manager_device_added_cb (ClutterDeviceManager *manager,
|
|
|
|
ClutterInputDevice *device,
|
|
|
|
TestDevicesApp *app)
|
|
|
|
{
|
|
|
|
ClutterInputDeviceType device_type;
|
|
|
|
ClutterActor *hand = NULL;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
device_type = clutter_input_device_get_device_type (device);
|
|
|
|
if (device_type == CLUTTER_POINTER_DEVICE ||
|
|
|
|
device_type == CLUTTER_PEN_DEVICE ||
|
|
|
|
device_type == CLUTTER_POINTER_DEVICE)
|
|
|
|
{
|
|
|
|
g_print ("*** enabling device '%s' ***\n",
|
|
|
|
clutter_input_device_get_device_name (device));
|
|
|
|
|
|
|
|
clutter_input_device_set_enabled (device, TRUE);
|
|
|
|
|
|
|
|
hand = clutter_texture_new_from_file (TESTS_DATADIR
|
|
|
|
G_DIR_SEPARATOR_S
|
|
|
|
"redhand.png",
|
|
|
|
NULL);
|
|
|
|
g_hash_table_insert (app->devices, device, hand);
|
|
|
|
|
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (app->stage), hand);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
manager_device_removed_cb (ClutterDeviceManager *manager,
|
|
|
|
ClutterInputDevice *device,
|
|
|
|
TestDevicesApp *app)
|
|
|
|
{
|
|
|
|
ClutterInputDeviceType device_type;
|
|
|
|
ClutterActor *hand = NULL;
|
|
|
|
|
|
|
|
g_print ("removed 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));
|
|
|
|
|
|
|
|
device_type = clutter_input_device_get_device_type (device);
|
|
|
|
if (device_type == CLUTTER_POINTER_DEVICE ||
|
|
|
|
device_type == CLUTTER_PEN_DEVICE ||
|
|
|
|
device_type == CLUTTER_POINTER_DEVICE)
|
|
|
|
{
|
|
|
|
hand = g_hash_table_lookup (app->devices, device);
|
|
|
|
if (hand != NULL)
|
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (app->stage), hand);
|
|
|
|
|
|
|
|
g_hash_table_remove (app->devices, device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2009-11-20 16:37:58 +00:00
|
|
|
ClutterDeviceManager *manager;
|
2009-06-19 12:07:20 +00:00
|
|
|
const GSList *stage_devices, *l;
|
2008-06-23 09:55:42 +00:00
|
|
|
|
2011-02-22 00:19:35 +00:00
|
|
|
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return 1;
|
2008-06-23 09:55:42 +00:00
|
|
|
|
|
|
|
app = g_new0 (TestDevicesApp, 1);
|
|
|
|
app->devices = g_hash_table_new (g_direct_hash, g_direct_equal) ;
|
|
|
|
|
2011-01-19 13:52:33 +00:00
|
|
|
stage = clutter_stage_new ();
|
2012-02-13 16:47:17 +00:00
|
|
|
clutter_actor_set_background_color (stage, CLUTTER_COLOR_LightSkyBlue);
|
2011-01-19 13:52:33 +00:00
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Devices");
|
|
|
|
clutter_stage_hide_cursor (CLUTTER_STAGE (stage));
|
|
|
|
g_signal_connect (stage,
|
|
|
|
"destroy", G_CALLBACK (clutter_main_quit),
|
|
|
|
NULL);
|
2008-06-23 09:55:42 +00:00
|
|
|
g_signal_connect (stage,
|
2011-01-19 13:52:33 +00:00
|
|
|
"motion-event", G_CALLBACK (stage_motion_event_cb),
|
|
|
|
app);
|
|
|
|
g_signal_connect (stage,
|
|
|
|
"button-press-event", G_CALLBACK (stage_button_event_cb),
|
2008-06-23 09:55:42 +00:00
|
|
|
app);
|
2011-01-21 11:41:36 +00:00
|
|
|
app->stage = stage;
|
2009-06-19 12:07:20 +00:00
|
|
|
|
2008-06-23 09:55:42 +00:00
|
|
|
clutter_actor_show_all (stage);
|
|
|
|
|
2009-11-20 16:37:58 +00:00
|
|
|
manager = clutter_device_manager_get_default ();
|
2011-01-21 11:41:36 +00:00
|
|
|
g_signal_connect (manager,
|
|
|
|
"device-added", G_CALLBACK (manager_device_added_cb),
|
|
|
|
app);
|
|
|
|
g_signal_connect (manager,
|
|
|
|
"device-removed", G_CALLBACK (manager_device_removed_cb),
|
|
|
|
app);
|
|
|
|
|
2009-11-20 16:37:58 +00:00
|
|
|
stage_devices = clutter_device_manager_peek_devices (manager);
|
2008-06-23 09:55:42 +00:00
|
|
|
|
2008-07-01 13:41:23 +00:00
|
|
|
if (stage_devices == NULL)
|
2009-11-20 16:37:58 +00:00
|
|
|
g_error ("No input devices found.");
|
2008-07-01 13:41:23 +00:00
|
|
|
|
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
|
|
|
|
2011-01-19 16:23:45 +00:00
|
|
|
g_print ("got a %s device '%s' with id %d\n",
|
2010-01-20 19:40:58 +00:00
|
|
|
device_type_name (device),
|
|
|
|
clutter_input_device_get_device_name (device),
|
|
|
|
clutter_input_device_get_device_id (device));
|
|
|
|
|
2009-06-19 12:07:20 +00:00
|
|
|
device_type = clutter_input_device_get_device_type (device);
|
2010-01-20 19:40:58 +00:00
|
|
|
if (device_type == CLUTTER_POINTER_DEVICE ||
|
2011-01-19 16:23:45 +00:00
|
|
|
device_type == CLUTTER_PEN_DEVICE ||
|
|
|
|
device_type == CLUTTER_POINTER_DEVICE)
|
2009-06-19 12:07:20 +00:00
|
|
|
{
|
2011-01-19 16:23:45 +00:00
|
|
|
g_print ("*** enabling device '%s' ***\n",
|
|
|
|
clutter_input_device_get_device_name (device));
|
|
|
|
|
|
|
|
clutter_input_device_set_enabled (device, TRUE);
|
|
|
|
|
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
|
|
|
}
|