devilhorns pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=6c85fe751488c344f1c0cff8e9f3dd013bf5f66d
commit 6c85fe751488c344f1c0cff8e9f3dd013bf5f66d Author: Chris Michael <cpmich...@osg.samsung.com> Date: Thu Apr 7 09:00:18 2016 -0400 elput: Add event which can be raised when devices get added or removed Signed-off-by: Chris Michael <cpmich...@osg.samsung.com> --- src/lib/elput/Elput.h | 14 +++++++++++++ src/lib/elput/elput.c | 3 +++ src/lib/elput/elput_input.c | 50 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/lib/elput/Elput.h b/src/lib/elput/Elput.h index f8808ce..385ea4e 100644 --- a/src/lib/elput/Elput.h +++ b/src/lib/elput/Elput.h @@ -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 diff --git a/src/lib/elput/elput.c b/src/lib/elput/elput.c index f65da98..2e54b3e 100644 --- a/src/lib/elput/elput.c +++ b/src/lib/elput/elput.c @@ -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; diff --git a/src/lib/elput/elput_input.c b/src/lib/elput/elput_input.c index 499efcf..6c43f2f 100644 --- a/src/lib/elput/elput_input.c +++ b/src/lib/elput/elput_input.c @@ -79,6 +79,41 @@ _udev_seat_get(Elput_Manager *em, struct libinput_device *device) } 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) { Elput_Seat *eseat; @@ -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 --