bdilly pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=ed48b8d93ee28d7e577c1bf200591db75afca317

commit ed48b8d93ee28d7e577c1bf200591db75afca317
Author: Bruno Dilly <[email protected]>
Date:   Tue Nov 8 19:12:28 2016 -0200

    efl: add getter for input device's seat
    
    Since this code will be required in many use cases
    of the multiseat feature, including examples.
    
    Reviewers: iscaro, barbieri, cedric
    
    Subscribers: jpeg
    
    Differential Revision: https://phab.enlightenment.org/D4385
---
 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 228c173..abed803 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 081a0fc..db73889 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 <Ecore_Evas.h>
 #include <Ecore_Input.h>
 
-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 1c79e5b..bb59fc6 100644
--- a/src/lib/efl/interfaces/efl_input_device.c
+++ b/src/lib/efl/interfaces/efl_input_device.c
@@ -98,6 +98,23 @@ _efl_input_device_description_get(Eo *obj EINA_UNUSED, 
Efl_Input_Device_Data *pd
 }
 
 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)
 {
    return pd->parent;
diff --git a/src/lib/efl/interfaces/efl_input_device.eo 
b/src/lib/efl/interfaces/efl_input_device.eo
index 8e8dd04..45056c4 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 @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; [[The seat this device belongs to.]]
+         }
+      }
    }
    implements {
       Efl.Object.constructor;

-- 


Reply via email to