From 6d0b42d814d81f4c7bff91560df51f62dabf639e Mon Sep 17 00:00:00 2001 From: Bruno Dilly Date: Tue, 8 Nov 2016 19:12:28 -0200 Subject: efl: add getter for input device's seat Since this code will be required in many use cases of the multiseat feature, including examples. --- src/examples/ecore/ecore_evas_vnc_example.c | 22 ++++------------------ .../ecore/ecore_evas_wayland_multiseat_example.c | 21 ++++----------------- src/lib/efl/interfaces/efl_input_device.c | 17 +++++++++++++++++ src/lib/efl/interfaces/efl_input_device.eo | 16 ++++++++++++++++ 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/examples/ecore/ecore_evas_vnc_example.c b/src/examples/ecore/ecore_evas_vnc_example.c index 228c173398..abed8037a2 100644 --- a/src/examples/ecore/ecore_evas_vnc_example.c +++ b/src/examples/ecore/ecore_evas_vnc_example.c @@ -58,20 +58,6 @@ _disc_cb(void *data EINA_UNUSED, Ecore_Evas *ee EINA_UNUSED, const char *client_ printf("Client %s disconnected\n", client_host); } -static Efl_Input_Device * -_get_seat(Efl_Input_Device *dev) -{ - if (!dev) - return NULL; - - while ((dev = efl_input_device_parent_get(dev))) - { - if (efl_input_device_type_get(dev) == EFL_INPUT_DEVICE_CLASS_SEAT) - return dev; - } - return NULL; -} - static Eina_Bool _keyboard_event(void *data EINA_UNUSED, int type, void *event) { @@ -79,7 +65,7 @@ _keyboard_event(void *data EINA_UNUSED, int type, void *event) Efl_Input_Device *seat = NULL; if (e->dev) - seat = _get_seat(e->dev); + seat = efl_input_device_seat_get(e->dev); printf("The keyboard on seat '%s' %s the key '%s'\n", seat ? efl_input_device_name_get(seat) : "default", @@ -96,7 +82,7 @@ _mouse_move(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) Efl_Input_Device *seat = NULL; if (e->dev) - seat = _get_seat(e->dev); + seat = efl_input_device_seat_get(e->dev); printf("The mouse on seat '%s' is at X: %d Y:%d\n", seat ? efl_input_device_name_get(seat) : "default", e->x, e->y); @@ -110,7 +96,7 @@ _mouse_button(void *data EINA_UNUSED, int type, void *event) Efl_Input_Device *seat = NULL; if (e->dev) - seat = _get_seat(e->dev); + seat = efl_input_device_seat_get(e->dev); printf("The mouse on seat '%s' %s the following button '%d'\n", seat ? efl_input_device_name_get(seat) : "default", @@ -126,7 +112,7 @@ _mouse_wheel(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) Efl_Input_Device *seat = NULL; if (e->dev) - seat = _get_seat(e->dev); + seat = efl_input_device_seat_get(e->dev); printf("The mouse on seat '%s' moved the wheel '%s'\n", seat ? efl_input_device_name_get(seat) : "default", diff --git a/src/examples/ecore/ecore_evas_wayland_multiseat_example.c b/src/examples/ecore/ecore_evas_wayland_multiseat_example.c index 081a0fc48a..db73889cbd 100644 --- a/src/examples/ecore/ecore_evas_wayland_multiseat_example.c +++ b/src/examples/ecore/ecore_evas_wayland_multiseat_example.c @@ -9,19 +9,6 @@ #include #include -static Efl_Input_Device * -_get_seat(Efl_Input_Device *dev) -{ - if (!dev) return NULL; - - while ((dev = efl_input_device_parent_get(dev))) - { - if (efl_input_device_type_get(dev) == EFL_INPUT_DEVICE_CLASS_SEAT) - return dev; - } - return NULL; -} - static Eina_Bool _keyboard_event(void *data EINA_UNUSED, int type, void *event) { @@ -29,7 +16,7 @@ _keyboard_event(void *data EINA_UNUSED, int type, void *event) Efl_Input_Device *seat = NULL; if (e->dev) - seat = _get_seat(e->dev); + seat = efl_input_device_seat_get(e->dev); printf("The keyboard on seat '%s' %s the key '%s'\n", seat ? efl_input_device_name_get(seat) : "unknown", @@ -46,7 +33,7 @@ _mouse_move(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) Efl_Input_Device *seat = NULL; if (e->dev) - seat = _get_seat(e->dev); + seat = efl_input_device_seat_get(e->dev); printf("The mouse on seat '%s' is at X: %d Y:%d\n", seat ? efl_input_device_name_get(seat) : "unknown", e->x, e->y); @@ -60,7 +47,7 @@ _mouse_button(void *data EINA_UNUSED, int type, void *event) Efl_Input_Device *seat = NULL; if (e->dev) - seat = _get_seat(e->dev); + seat = efl_input_device_seat_get(e->dev); printf("The mouse on seat '%s' %s the following button '%d'\n", seat ? efl_input_device_name_get(seat) : "unknown", @@ -76,7 +63,7 @@ _mouse_wheel(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) Efl_Input_Device *seat = NULL; if (e->dev) - seat = _get_seat(e->dev); + seat = efl_input_device_seat_get(e->dev); printf("The mouse on seat '%s' moved the wheel '%s'\n", seat ? efl_input_device_name_get(seat) : "unknown", diff --git a/src/lib/efl/interfaces/efl_input_device.c b/src/lib/efl/interfaces/efl_input_device.c index 1c79e5bee6..bb59fc6447 100644 --- a/src/lib/efl/interfaces/efl_input_device.c +++ b/src/lib/efl/interfaces/efl_input_device.c @@ -97,6 +97,23 @@ _efl_input_device_description_get(Eo *obj EINA_UNUSED, Efl_Input_Device_Data *pd return pd->desc; } +EOLIAN static Efl_Input_Device * +_efl_input_device_seat_get(Eo *obj EINA_UNUSED, Efl_Input_Device_Data *pd) +{ + while (1) + { + if (pd->klass == EFL_INPUT_DEVICE_CLASS_SEAT) + return pd->eo; + + if (!pd->parent) + break; + + pd = efl_data_scope_get(pd->parent, EFL_INPUT_DEVICE_CLASS); + } + + return NULL; +} + EOLIAN static Efl_Input_Device * _efl_input_device_parent_get(Eo *obj EINA_UNUSED, Efl_Input_Device_Data *pd) { diff --git a/src/lib/efl/interfaces/efl_input_device.eo b/src/lib/efl/interfaces/efl_input_device.eo index 8e8dd04fd6..3e7fbfc1db 100644 --- a/src/lib/efl/interfaces/efl_input_device.eo +++ b/src/lib/efl/interfaces/efl_input_device.eo @@ -81,6 +81,22 @@ class Efl.Input.Device (Efl.Object) parent: Efl.Input.Device; [[Parent input device]] } } + @property seat { + [[Get the @Efl.Input.Device that represents a seat. + + This method will find the seat the device belongs to. + + For this, it walk through device's parents looking for a device + with \@ref EFL_INPUT_DEVICE_CLASS_SEAT. It may be + the device itself. + + In case no seat is found, $NULL is returned. + ]] + get {} + values { + seat: Efl.Input.Device; [[Input device's seat, if any]] + } + } } implements { Efl.Object.constructor; -- cgit v1.2.1