diff --git a/src/lib/ecore_drm/ecore_drm.c b/src/lib/ecore_drm/ecore_drm.c --- a/src/lib/ecore_drm/ecore_drm.c +++ b/src/lib/ecore_drm/ecore_drm.c @@ -87,6 +87,8 @@ /* try to init eeze */ if (!eeze_init()) goto eeze_err; + _ecore_drm_inputs_init(); + ECORE_DRM_EVENT_ACTIVATE = ecore_event_type_new(); ECORE_DRM_EVENT_OUTPUT = ecore_event_type_new(); ECORE_DRM_EVENT_SEAT_ADD = ecore_event_type_new(); @@ -141,6 +143,8 @@ /* shutdown eina */ eina_shutdown(); + _ecore_drm_inputs_shutdown(); + /* return init count */ return _ecore_drm_init_count; } diff --git a/src/lib/ecore_drm/ecore_drm_inputs.c b/src/lib/ecore_drm/ecore_drm_inputs.c --- a/src/lib/ecore_drm/ecore_drm_inputs.c +++ b/src/lib/ecore_drm/ecore_drm_inputs.c @@ -5,15 +5,13 @@ #include "ecore_drm_private.h" EAPI int ECORE_DRM_EVENT_SEAT_ADD = -1; +static Eina_Hash *_fd_hash = NULL; /* local functions */ static int _cb_open_restricted(const char *path, int flags, void *data) { Ecore_Drm_Input *input; - Ecore_Drm_Seat *seat; - Ecore_Drm_Evdev *edev; - Eina_List *l, *ll; int fd = -1; if (!(input = data)) return -1; @@ -21,18 +19,8 @@ /* try to open the device */ fd = _ecore_drm_launcher_device_open_no_pending(path, flags); if (fd < 0) ERR("Could not open device"); - - EINA_LIST_FOREACH(input->dev->seats, l, seat) - { - EINA_LIST_FOREACH(seat->devices, ll, edev) - { - if (strstr(path, edev->path)) - { - edev->fd = fd; - return fd; - } - } - } + if (_fd_hash) + eina_hash_add(_fd_hash, path, (void *)(intptr_t)fd); return fd; } @@ -54,6 +42,9 @@ if (edev->fd == fd) { _ecore_drm_launcher_device_close(edev->path, fd); + + /* re-initialize fd after closing */ + edev->fd = -1; return; } } @@ -118,6 +109,8 @@ return; } + edev->fd = (int)(intptr_t)eina_hash_find(_fd_hash, edev->path); + /* append this device to the seat */ seat->devices = eina_list_append(seat->devices, edev); } @@ -134,6 +127,9 @@ /* remove this evdev from the seat's list of devices */ edev->seat->devices = eina_list_remove(edev->seat->devices, edev); + if (_fd_hash) + eina_hash_del_by_key(_fd_hash, edev->path); + /* tell launcher to release device */ _ecore_drm_launcher_device_close(edev->path, edev->fd); @@ -345,3 +341,16 @@ input->suspended = EINA_TRUE; } + +void +_ecore_drm_inputs_init(void) +{ + _fd_hash = eina_hash_string_superfast_new(NULL); +} + +void +_ecore_drm_inputs_shutdown(void) +{ + eina_hash_free(_fd_hash); + _fd_hash = NULL; +} diff --git a/src/lib/ecore_drm/ecore_drm_launcher.c b/src/lib/ecore_drm/ecore_drm_launcher.c --- a/src/lib/ecore_drm/ecore_drm_launcher.c +++ b/src/lib/ecore_drm/ecore_drm_launcher.c @@ -167,5 +167,6 @@ { if ((logind) && (device)) _ecore_drm_logind_device_close(device); + if (fd < 0) return; close(fd); } diff --git a/src/lib/ecore_drm/ecore_drm_private.h b/src/lib/ecore_drm/ecore_drm_private.h --- a/src/lib/ecore_drm/ecore_drm_private.h +++ b/src/lib/ecore_drm/ecore_drm_private.h @@ -289,4 +289,6 @@ Eina_Bool _ecore_drm_dbus_session_take(void); Eina_Bool _ecore_drm_dbus_session_release(void); +void _ecore_drm_inputs_init(void); +void _ecore_drm_inputs_shutdown(void); #endif