test-devices: Clean up and show axes data
This commit is contained in:
parent
d078fe0930
commit
f54044f7e4
@ -26,6 +26,15 @@ device_type_name (ClutterInputDevice *device)
|
|||||||
case CLUTTER_EXTENSION_DEVICE:
|
case CLUTTER_EXTENSION_DEVICE:
|
||||||
return "Extension";
|
return "Extension";
|
||||||
|
|
||||||
|
case CLUTTER_PEN_DEVICE:
|
||||||
|
return "Pen";
|
||||||
|
|
||||||
|
case CLUTTER_ERASER_DEVICE:
|
||||||
|
return "Eraser";
|
||||||
|
|
||||||
|
case CLUTTER_CURSOR_DEVICE:
|
||||||
|
return "Cursor";
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
@ -35,6 +44,89 @@ device_type_name (ClutterInputDevice *device)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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";
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
g_warn_if_reached ();
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
stage_button_event_cb (ClutterActor *actor,
|
||||||
|
ClutterEvent *event,
|
||||||
|
gpointer userdata)
|
||||||
|
{
|
||||||
|
TestDevicesApp *app = (TestDevicesApp *)userdata;
|
||||||
|
ClutterInputDevice *device;
|
||||||
|
ClutterInputDevice *source_device;
|
||||||
|
ClutterActor *hand = NULL;
|
||||||
|
|
||||||
|
device = clutter_event_get_device (event);
|
||||||
|
source_device = clutter_event_get_source_device (event);
|
||||||
|
|
||||||
|
hand = g_hash_table_lookup (app->devices, device);
|
||||||
|
|
||||||
|
g_print ("Device: '%s' (id:%d, type: %s, source: '%s')\n",
|
||||||
|
clutter_input_device_get_device_name (device),
|
||||||
|
clutter_input_device_get_device_id (device),
|
||||||
|
device_type_name (device),
|
||||||
|
source_device != device
|
||||||
|
? clutter_input_device_get_device_name (source_device)
|
||||||
|
: "<same>");
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->motion.axes != NULL)
|
||||||
|
{
|
||||||
|
gdouble *axes;
|
||||||
|
guint n_axes, i;
|
||||||
|
|
||||||
|
axes = clutter_event_get_axes (event, &n_axes);
|
||||||
|
for (i = 0; i < n_axes; i++)
|
||||||
|
{
|
||||||
|
g_print ("Axis[%02d][%s].value: %.2f\n",
|
||||||
|
i,
|
||||||
|
axis_type_name (clutter_input_device_get_axis (device, i)),
|
||||||
|
axes[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
stage_motion_event_cb (ClutterActor *actor,
|
stage_motion_event_cb (ClutterActor *actor,
|
||||||
ClutterEvent *event,
|
ClutterEvent *event,
|
||||||
@ -47,12 +139,6 @@ stage_motion_event_cb (ClutterActor *actor,
|
|||||||
device = clutter_event_get_device (event);
|
device = clutter_event_get_device (event);
|
||||||
|
|
||||||
hand = g_hash_table_lookup (app->devices, device);
|
hand = g_hash_table_lookup (app->devices, device);
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
if (hand != NULL)
|
if (hand != NULL)
|
||||||
{
|
{
|
||||||
gfloat event_x, event_y;
|
gfloat event_x, event_y;
|
||||||
@ -63,19 +149,6 @@ stage_motion_event_cb (ClutterActor *actor,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +157,6 @@ test_devices_main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
ClutterActor *stage;
|
ClutterActor *stage;
|
||||||
TestDevicesApp *app;
|
TestDevicesApp *app;
|
||||||
ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff };
|
|
||||||
ClutterDeviceManager *manager;
|
ClutterDeviceManager *manager;
|
||||||
const GSList *stage_devices, *l;
|
const GSList *stage_devices, *l;
|
||||||
|
|
||||||
@ -96,13 +168,19 @@ test_devices_main (int argc, char **argv)
|
|||||||
app = g_new0 (TestDevicesApp, 1);
|
app = g_new0 (TestDevicesApp, 1);
|
||||||
app->devices = g_hash_table_new (g_direct_hash, g_direct_equal) ;
|
app->devices = g_hash_table_new (g_direct_hash, g_direct_equal) ;
|
||||||
|
|
||||||
stage = clutter_stage_get_default ();
|
stage = clutter_stage_new ();
|
||||||
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
|
clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_LightSkyBlue);
|
||||||
//clutter_stage_fullscreen (CLUTTER_STAGE (stage));
|
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);
|
||||||
g_signal_connect (stage,
|
g_signal_connect (stage,
|
||||||
"motion-event", G_CALLBACK (stage_motion_event_cb),
|
"motion-event", G_CALLBACK (stage_motion_event_cb),
|
||||||
app);
|
app);
|
||||||
|
g_signal_connect (stage,
|
||||||
|
"button-press-event", G_CALLBACK (stage_button_event_cb),
|
||||||
|
app);
|
||||||
|
|
||||||
clutter_actor_show_all (stage);
|
clutter_actor_show_all (stage);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user