From 9572e9189da786c79b1eb3c9a30fea680ece8aa5 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 9 Jun 2017 20:16:07 -0400 Subject: [PATCH] efl_input_device: add function for determining if a device has pointer caps this is useful when attempting to manage devices @feature --- src/lib/efl/interfaces/efl_common_internal.h | 1 + src/lib/efl/interfaces/efl_input_device.c | 32 +++++++++++++++++++- src/lib/efl/interfaces/efl_input_device.eo | 11 +++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/lib/efl/interfaces/efl_common_internal.h b/src/lib/efl/interfaces/efl_common_internal.h index 86884bf36b..0270782fd8 100644 --- a/src/lib/efl/interfaces/efl_common_internal.h +++ b/src/lib/efl/interfaces/efl_common_internal.h @@ -98,6 +98,7 @@ struct _Efl_Input_Device_Data unsigned int id; Efl_Input_Device_Class klass; Efl_Input_Device_Sub_Class subclass; + unsigned int pointer_count; }; struct _Efl_Input_Hold_Data diff --git a/src/lib/efl/interfaces/efl_input_device.c b/src/lib/efl/interfaces/efl_input_device.c index 7689fc211a..faee0dd6e3 100644 --- a/src/lib/efl/interfaces/efl_input_device.c +++ b/src/lib/efl/interfaces/efl_input_device.c @@ -19,6 +19,22 @@ struct _Child_Device_Iterator Eo *object; }; +static Eina_Bool +_is_pointer(Efl_Input_Device_Data *pd) +{ + return (pd->klass == EFL_INPUT_DEVICE_CLASS_MOUSE || + pd->klass == EFL_INPUT_DEVICE_CLASS_TOUCH || + pd->klass == EFL_INPUT_DEVICE_CLASS_PEN || + pd->klass == EFL_INPUT_DEVICE_CLASS_WAND); +} + +static void +_seat_pointers_update(Efl_Input_Device_Data *seat, Efl_Input_Device_Data *dev) +{ + if (seat && _is_pointer(dev)) + seat->pointer_count++; +} + EOLIAN static Efl_Object * _efl_input_device_efl_object_constructor(Eo *obj, Efl_Input_Device_Data *pd) { @@ -43,6 +59,8 @@ _efl_input_device_efl_object_destructor(Eo *obj, Efl_Input_Device_Data *pd) { Efl_Input_Device_Data *p = efl_data_scope_get(pd->parent, EFL_INPUT_DEVICE_CLASS); p->children = eina_list_remove(p->children, obj); + if (_is_pointer(pd)) + p->pointer_count--; } efl_unref(pd->source); @@ -52,7 +70,10 @@ _efl_input_device_efl_object_destructor(Eo *obj, Efl_Input_Device_Data *pd) EOLIAN static void _efl_input_device_device_type_set(Eo *obj EINA_UNUSED, Efl_Input_Device_Data *pd, Efl_Input_Device_Class klass) { - pd->klass= klass; + EINA_SAFETY_ON_TRUE_RETURN(pd->klass); + pd->klass = klass; + if (klass != EFL_INPUT_DEVICE_CLASS_SEAT) + _seat_pointers_update(efl_data_scope_get(pd->parent, EFL_INPUT_DEVICE_CLASS), pd); } EOLIAN static Efl_Input_Device_Class @@ -163,6 +184,7 @@ _efl_input_device_parent_set(Eo *obj, Efl_Input_Device_Data *pd, Efl_Input_Devic { Efl_Input_Device_Data *p = efl_data_scope_get(parent, EFL_INPUT_DEVICE_CLASS); p->children = eina_list_append(p->children, obj); + _seat_pointers_update(p, pd); } } @@ -212,4 +234,12 @@ _efl_input_device_children_iterate(Eo *obj, Efl_Input_Device_Data *pd) return &it->iterator; } +EOLIAN static unsigned int +_efl_input_device_has_pointer_caps(Eo *obj EINA_UNUSED, Efl_Input_Device_Data *pd) +{ + if (pd->klass == EFL_INPUT_DEVICE_CLASS_SEAT) + return pd->pointer_count; + return _is_pointer(pd); +} + #include "interfaces/efl_input_device.eo.c" diff --git a/src/lib/efl/interfaces/efl_input_device.eo b/src/lib/efl/interfaces/efl_input_device.eo index 2473164af8..6528db76ce 100644 --- a/src/lib/efl/interfaces/efl_input_device.eo +++ b/src/lib/efl/interfaces/efl_input_device.eo @@ -120,6 +120,17 @@ class Efl.Input.Device (Efl.Object) ]] return: own(free(iterator, eina_iterator_free)); } + has_pointer_caps { + [[Determine whether a device has pointer capabilities. + + Returns 1 for Mouse, Touch, Pen, Pointer, and Wand type devices. + + If a seat device is passed, returns the number of pointer devices in the seat. + + @since 1.20 + ]] + return: uint; + } } implements { Efl.Object.constructor;