device: Allow enabling/disabling non-master devices

Slave and floating devices should always be disabled, and not deliver
events to the scene. It is up to the user to enable non-master devices
and handle events coming from them.

ClutterInputDevice gets a new :enabled property, defaulting to FALSE;
when a device manager creates a new device it has to set it to TRUE if
the :device-mode property is set to CLUTTER_INPUT_MODE_MASTER.

The main event queue entry point, _clutter_event_push(), will
automatically discard events coming from disabled devices.
This commit is contained in:
Emmanuele Bassi
2011-01-19 16:23:45 +00:00
parent 137f7d42a8
commit 73cf6bd52c
7 changed files with 100 additions and 4 deletions

View File

@ -59,6 +59,7 @@ enum
PROP_DEVICE_MODE,
PROP_HAS_CURSOR,
PROP_ENABLED,
PROP_N_AXES,
@ -139,6 +140,10 @@ clutter_input_device_set_property (GObject *gobject,
self->has_cursor = g_value_get_boolean (value);
break;
case PROP_ENABLED:
self->is_enabled = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@ -190,6 +195,10 @@ clutter_input_device_get_property (GObject *gobject,
g_value_set_uint (value, 0);
break;
case PROP_ENABLED:
g_value_set_boolean (value, self->is_enabled);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@ -270,6 +279,13 @@ clutter_input_device_class_init (ClutterInputDeviceClass *klass)
FALSE,
CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
obj_props[PROP_ENABLED] =
g_param_spec_boolean ("enabled",
P_("Enabled"),
P_("Whether the device is enabled"),
FALSE,
CLUTTER_PARAM_READWRITE);
obj_props[PROP_N_AXES] =
g_param_spec_uint ("n-axes",
P_("Number of Axes"),
@ -587,6 +603,56 @@ clutter_input_device_get_device_id (ClutterInputDevice *device)
return device->id;
}
/**
* clutter_input_device_set_enabled:
* @device: a #ClutterInputDevice
* @enabled: %TRUE to enable the @device
*
* Enables or disables a #ClutterInputDevice.
*
* Only devices with a #ClutterInputDevice:device-mode property set
* to %CLUTTER_INPUT_MODE_SLAVE or %CLUTTER_INPUT_MODE_FLOATING can
* be disabled.
*
* Since: 1.6
*/
void
clutter_input_device_set_enabled (ClutterInputDevice *device,
gboolean enabled)
{
g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
enabled = !!enabled;
if (!enabled && device->device_mode == CLUTTER_INPUT_MODE_MASTER)
return;
if (device->is_enabled == enabled)
return;
device->is_enabled = enabled;
g_object_notify_by_pspec (G_OBJECT (device), obj_props[PROP_ENABLED]);
}
/**
* clutter_input_device_get_enabled:
* @device: a #ClutterInputDevice
*
* Retrieves whether @device is enabled.
*
* Return value: %TRUE if the device is enabled
*
* Since: 1.6
*/
gboolean
clutter_input_device_get_enabled (ClutterInputDevice *device)
{
g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE);
return device->is_enabled;
}
/**
* clutter_input_device_get_device_coords:
* @device: a #ClutterInputDevice of type %CLUTTER_POINTER_DEVICE