From 9587a60da451fe243dc46867ea19bb8e1c2d29ad Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 13 May 2016 19:57:51 +0200 Subject: [PATCH] clutter: Add clutter_input_device_[gs]et_mapping() This function call only applies to tablets, and thus will error out unless it's called with CLUTTER_TABLET_DEVICEs. This will allow setting absolute/relative mapping on those on the fly, as this is optional. --- .../clutter/clutter-device-manager-private.h | 2 + clutter/clutter/clutter-enums.h | 5 +++ clutter/clutter/clutter-input-device.c | 44 +++++++++++++++++++ clutter/clutter/clutter-input-device.h | 7 +++ 4 files changed, 58 insertions(+) diff --git a/clutter/clutter/clutter-device-manager-private.h b/clutter/clutter/clutter-device-manager-private.h index bafc02497..7efe76857 100644 --- a/clutter/clutter/clutter-device-manager-private.h +++ b/clutter/clutter/clutter-device-manager-private.h @@ -139,6 +139,8 @@ struct _ClutterInputDevice gint n_strips; gint n_mode_groups; + ClutterInputDeviceMapping mapping_mode; + guint has_cursor : 1; guint is_enabled : 1; }; diff --git a/clutter/clutter/clutter-enums.h b/clutter/clutter/clutter-enums.h index 6f779c5ec..03c0395db 100644 --- a/clutter/clutter/clutter-enums.h +++ b/clutter/clutter/clutter-enums.h @@ -1531,6 +1531,11 @@ typedef enum { CLUTTER_INPUT_DEVICE_PAD_SOURCE_FINGER, } ClutterInputDevicePadSource; +typedef enum { + CLUTTER_INPUT_DEVICE_MAPPING_ABSOLUTE, + CLUTTER_INPUT_DEVICE_MAPPING_RELATIVE, +} ClutterInputDeviceMapping; + G_END_DECLS #endif /* __CLUTTER_ENUMS_H__ */ diff --git a/clutter/clutter/clutter-input-device.c b/clutter/clutter/clutter-input-device.c index 6021c8e2f..2930e5625 100644 --- a/clutter/clutter/clutter-input-device.c +++ b/clutter/clutter/clutter-input-device.c @@ -74,6 +74,7 @@ enum PROP_N_RINGS, PROP_N_MODE_GROUPS, PROP_DEVICE_NODE, + PROP_MAPPING_MODE, PROP_LAST }; @@ -216,6 +217,10 @@ clutter_input_device_set_property (GObject *gobject, self->node_path = g_value_dup_string (value); break; + case PROP_MAPPING_MODE: + self->mapping_mode = g_value_get_enum (value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); break; @@ -292,6 +297,10 @@ clutter_input_device_get_property (GObject *gobject, g_value_set_string (value, self->node_path); break; + case PROP_MAPPING_MODE: + g_value_set_enum (value, self->mapping_mode); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); break; @@ -497,6 +506,14 @@ clutter_input_device_class_init (ClutterInputDeviceClass *klass) NULL, CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + obj_props[PROP_MAPPING_MODE] = + g_param_spec_enum ("mapping-mode", + P_("Device mapping mode"), + P_("Device mapping mode"), + CLUTTER_TYPE_INPUT_DEVICE_MAPPING, + CLUTTER_INPUT_DEVICE_MAPPING_ABSOLUTE, + CLUTTER_PARAM_READWRITE); + gobject_class->dispose = clutter_input_device_dispose; gobject_class->set_property = clutter_input_device_set_property; gobject_class->get_property = clutter_input_device_get_property; @@ -2165,3 +2182,30 @@ clutter_input_device_get_device_node (ClutterInputDevice *device) return device->node_path; } + +ClutterInputDeviceMapping +clutter_input_device_get_mapping_mode (ClutterInputDevice *device) +{ + g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), + CLUTTER_INPUT_DEVICE_MAPPING_ABSOLUTE); + g_return_val_if_fail (clutter_input_device_get_device_type (device) == + CLUTTER_TABLET_DEVICE, + CLUTTER_INPUT_DEVICE_MAPPING_ABSOLUTE); + + return device->mapping_mode; +} + +void +clutter_input_device_set_mapping_mode (ClutterInputDevice *device, + ClutterInputDeviceMapping mapping) +{ + g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device)); + g_return_if_fail (clutter_input_device_get_device_type (device) == + CLUTTER_TABLET_DEVICE); + + if (device->mapping_mode == mapping) + return; + + device->mapping_mode = mapping; + g_object_notify (G_OBJECT (device), "mapping-mode"); +} diff --git a/clutter/clutter/clutter-input-device.h b/clutter/clutter/clutter-input-device.h index 9b55d3529..66b2a58ba 100644 --- a/clutter/clutter/clutter-input-device.h +++ b/clutter/clutter/clutter-input-device.h @@ -150,6 +150,13 @@ gint clutter_input_device_get_n_mode_groups (ClutterInputDev CLUTTER_AVAILABLE_IN_ALL const gchar * clutter_input_device_get_device_node (ClutterInputDevice *device); +CLUTTER_AVAILABLE_IN_ALL +ClutterInputDeviceMapping clutter_input_device_get_mapping_mode (ClutterInputDevice *device); + +CLUTTER_AVAILABLE_IN_ALL +void clutter_input_device_set_mapping_mode (ClutterInputDevice *device, + ClutterInputDeviceMapping mapping); + G_END_DECLS #endif /* __CLUTTER_INPUT_DEVICE_H__ */