forked from enlightenment/efl
elput: Add event which can be raised when devices get added or removed
Signed-off-by: Chris Michael <cpmichael@osg.samsung.com>
This commit is contained in:
parent
6a7589bf78
commit
6c85fe7514
|
@ -74,10 +74,24 @@ typedef struct _Elput_Event_Modifiers_Send
|
|||
unsigned int group;
|
||||
} Elput_Event_Modifiers_Send;
|
||||
|
||||
typedef enum _Elput_Device_Change_Type
|
||||
{
|
||||
ELPUT_DEVICE_ADDED,
|
||||
ELPUT_DEVICE_REMOVED,
|
||||
} Elput_Device_Change_Type;
|
||||
|
||||
/* structure to represent event for device being added or removed */
|
||||
typedef struct _Elput_Event_Device_Change
|
||||
{
|
||||
Elput_Device *device;
|
||||
Elput_Device_Change_Type type;
|
||||
} Elput_Event_Device_Change;
|
||||
|
||||
EAPI extern int ELPUT_EVENT_SEAT_CAPS;
|
||||
EAPI extern int ELPUT_EVENT_SEAT_FRAME;
|
||||
EAPI extern int ELPUT_EVENT_KEYMAP_SEND;
|
||||
EAPI extern int ELPUT_EVENT_MODIFIERS_SEND;
|
||||
EAPI extern int ELPUT_EVENT_DEVICE_CHANGE;
|
||||
|
||||
/**
|
||||
* @file
|
||||
|
|
|
@ -10,6 +10,7 @@ EAPI int ELPUT_EVENT_SEAT_CAPS = -1;
|
|||
EAPI int ELPUT_EVENT_SEAT_FRAME = -1;
|
||||
EAPI int ELPUT_EVENT_KEYMAP_SEND = -1;
|
||||
EAPI int ELPUT_EVENT_MODIFIERS_SEND = -1;
|
||||
EAPI int ELPUT_EVENT_DEVICE_CHANGE = -1;
|
||||
|
||||
EAPI int
|
||||
elput_init(void)
|
||||
|
@ -32,6 +33,7 @@ elput_init(void)
|
|||
ELPUT_EVENT_SEAT_FRAME = ecore_event_type_new();
|
||||
ELPUT_EVENT_KEYMAP_SEND = ecore_event_type_new();
|
||||
ELPUT_EVENT_MODIFIERS_SEND = ecore_event_type_new();
|
||||
ELPUT_EVENT_DEVICE_CHANGE = ecore_event_type_new();
|
||||
|
||||
return _elput_init_count;
|
||||
|
||||
|
@ -57,6 +59,7 @@ elput_shutdown(void)
|
|||
ELPUT_EVENT_SEAT_FRAME = -1;
|
||||
ELPUT_EVENT_KEYMAP_SEND = -1;
|
||||
ELPUT_EVENT_MODIFIERS_SEND = -1;
|
||||
ELPUT_EVENT_DEVICE_CHANGE = -1;
|
||||
|
||||
eina_log_domain_unregister(_elput_log_dom);
|
||||
_elput_log_dom = -1;
|
||||
|
|
|
@ -78,6 +78,41 @@ _udev_seat_get(Elput_Manager *em, struct libinput_device *device)
|
|||
return _udev_seat_named_get(em, name);
|
||||
}
|
||||
|
||||
static void
|
||||
_device_event_cb_free(void *data EINA_UNUSED, void *event)
|
||||
{
|
||||
Elput_Event_Device_Change *ev;
|
||||
|
||||
ev = event;
|
||||
|
||||
if (ev->type == ELPUT_DEVICE_REMOVED)
|
||||
{
|
||||
Elput_Seat *seat;
|
||||
|
||||
seat = ev->device->seat;
|
||||
if (seat)
|
||||
seat->devices = eina_list_remove(seat->devices, ev->device);
|
||||
|
||||
_evdev_device_destroy(ev->device);
|
||||
}
|
||||
|
||||
free(ev);
|
||||
}
|
||||
|
||||
static void
|
||||
_device_event_send(Elput_Device *edev, Elput_Device_Change_Type type)
|
||||
{
|
||||
Elput_Event_Device_Change *ev;
|
||||
|
||||
ev = calloc(1, sizeof(Elput_Event_Device_Change));
|
||||
if (!ev) return;
|
||||
|
||||
ev->device = edev;
|
||||
ev->type = type;
|
||||
|
||||
ecore_event_add(ELPUT_EVENT_DEVICE_CHANGE, ev, _device_event_cb_free, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
_device_add(Elput_Manager *em, struct libinput_device *dev)
|
||||
{
|
||||
|
@ -95,22 +130,25 @@ _device_add(Elput_Manager *em, struct libinput_device *dev)
|
|||
eina_stringshare_replace(&edev->output_name, oname);
|
||||
|
||||
eseat->devices = eina_list_append(eseat->devices, edev);
|
||||
|
||||
_device_event_send(edev, ELPUT_DEVICE_ADDED);
|
||||
}
|
||||
|
||||
static void
|
||||
_device_remove(Elput_Manager *em, struct libinput_device *device)
|
||||
_device_remove(Elput_Manager *em EINA_UNUSED, struct libinput_device *device)
|
||||
{
|
||||
Elput_Seat *eseat;
|
||||
/* Elput_Seat *eseat; */
|
||||
Elput_Device *edev;
|
||||
|
||||
edev = libinput_device_get_user_data(device);
|
||||
if (!edev) return;
|
||||
|
||||
eseat = _udev_seat_get(em, device);
|
||||
if (eseat)
|
||||
eseat->devices = eina_list_remove(eseat->devices, edev);
|
||||
/* eseat = _udev_seat_get(em, device); */
|
||||
/* if (eseat) */
|
||||
/* eseat->devices = eina_list_remove(eseat->devices, edev); */
|
||||
|
||||
_evdev_device_destroy(edev);
|
||||
_device_event_send(edev, ELPUT_DEVICE_REMOVED);
|
||||
/* _evdev_device_destroy(edev); */
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
Loading…
Reference in New Issue