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
This commit is contained in:
Bruno Dilly 2016-11-08 19:12:28 -02:00
parent f2295d2fef
commit ed48b8d93e
4 changed files with 41 additions and 35 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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)
{

View File

@ -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;