devilhorns pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=a0395b07c5b51fff61ec4b2e62bbe12fd2badd8f
commit a0395b07c5b51fff61ec4b2e62bbe12fd2badd8f Author: Chris Michael <[email protected]> Date: Tue Sep 23 15:11:43 2014 -0400 ecore-drm: Port ecore_drm_inputs code to use Eeze instead of udev Summary: This changes all of our internal ecore-drm input code to use Eeze library instead of udev directly. @feature Signed-off-by: Chris Michael <[email protected]> --- src/lib/ecore_drm/ecore_drm_inputs.c | 202 ++++++++++++++--------------------- 1 file changed, 82 insertions(+), 120 deletions(-) diff --git a/src/lib/ecore_drm/ecore_drm_inputs.c b/src/lib/ecore_drm/ecore_drm_inputs.c index 0774b8f..cec6913 100644 --- a/src/lib/ecore_drm/ecore_drm_inputs.c +++ b/src/lib/ecore_drm/ecore_drm_inputs.c @@ -87,7 +87,7 @@ _cb_device_opened(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending if (!(d = data)) return; - DBG("Device Opened: %s", d->node); + /* DBG("Input Device Opened: %s", d->node); */ /* DBUS_TYPE_UNIX_FD == 'h' */ if (!eldbus_message_arguments_get(msg, "hb", &fd, &b)) @@ -142,37 +142,43 @@ _seat_get(Ecore_Drm_Input *input, const char *seat) } static Eina_Bool -_device_add(Ecore_Drm_Input *input, struct udev_device *device) +_device_add(Ecore_Drm_Input *input, const char *device) { - Ecore_Drm_Device_Open_Data *data; Ecore_Drm_Seat *seat; - const char *dev_seat, *wl_seat; - const char *node; - char n[PATH_MAX]; + Ecore_Drm_Device_Open_Data *data; + const char *devseat, *wlseat; - if (!(dev_seat = udev_device_get_property_value(device, "ID_SEAT"))) - dev_seat = "seat0"; + DBG("Add Input Device: %s", device); - if (strcmp(dev_seat, input->seat)) return EINA_FALSE; + if (!(devseat = eeze_udev_syspath_get_property(device, "ID_SEAT"))) + devseat = eina_stringshare_add("seat0"); - if (!(wl_seat = udev_device_get_property_value(device, "WL_SEAT"))) - wl_seat = "seat0"; + if (strcmp(devseat, input->seat)) goto seat_err; - if (!(seat = _seat_get(input, wl_seat))) - return EINA_FALSE; + if (!(wlseat = eeze_udev_syspath_get_property(device, "WL_SEAT"))) + wlseat = eina_stringshare_add("seat0"); - node = udev_device_get_devnode(device); - strcpy(n, node); + if (!(seat = _seat_get(input, wlseat))) + { + ERR("\tCould not get matching seat"); + goto seat_get_err; + } if (!(data = calloc(1, sizeof(Ecore_Drm_Device_Open_Data)))) - return EINA_FALSE; + goto seat_get_err; data->seat = seat; - data->node = eina_stringshare_add(n); + data->node = eeze_udev_syspath_get_devpath(device); - _ecore_drm_dbus_device_open(n, _cb_device_opened, data); + _ecore_drm_dbus_device_open(data->node, _cb_device_opened, data); return EINA_TRUE; + +seat_get_err: + eina_stringshare_del(wlseat); +seat_err: + eina_stringshare_del(devseat); + return EINA_FALSE; } static void @@ -200,79 +206,61 @@ _device_remove(Ecore_Drm_Input *input, const char *device) } } -static Eina_Bool -_cb_input_event(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED) +static void +_cb_input_event(const char *device, Eeze_Udev_Event event, void *data, Eeze_Udev_Watch *watch EINA_UNUSED) { Ecore_Drm_Input *input; - struct udev_device *udevice; - const char *act; - - if (!(input = data)) return EINA_FALSE; - - if (!(udevice = udev_monitor_receive_device(input->monitor))) - return EINA_TRUE; - - if (!(act = udev_device_get_action(udevice))) return EINA_TRUE; - if (strncmp("event", udev_device_get_sysname(udevice), 5) != 0) - goto err; + if (!(input = data)) return; - if (!strcmp(act, "add")) - _device_add(input, udevice); - else if (!strcmp(act, "remove")) + switch (event) { - const char *node; - - node = udev_device_get_devnode(udevice); + case EEZE_UDEV_EVENT_ADD: + _device_add(input, device); + break; + case EEZE_UDEV_EVENT_REMOVE: + { + const char *node; - _device_remove(input, node); + node = eeze_udev_syspath_get_devpath(device); + _device_remove(input, node); + eina_stringshare_del(node); + } + break; + default: + break; } - - return EINA_TRUE; - -err: - if (udevice) udev_device_unref(udevice); - return EINA_TRUE; } static Eina_Bool _devices_add(Ecore_Drm_Input *input) { - struct udev_enumerate *uenum; - struct udev_list_entry *uentry; - struct udev_device *udevice; - const char *path, *name; + Eina_List *devices; Eina_Bool found = EINA_FALSE; - - uenum = udev_enumerate_new(udev); - udev_enumerate_add_match_subsystem(uenum, "input"); - udev_enumerate_scan_devices(uenum); - - udev_list_entry_foreach(uentry, udev_enumerate_get_list_entry(uenum)) + const char *device; + + /* NB: This really sucks !! We cannot 'OR' diferent device types + * together for eeze_udev_find_by_type + * + * For now, just find by 'NONE" and we'll filter for input devices by + * running tests */ + devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NONE, NULL); + EINA_LIST_FREE(devices, device) { - path = udev_list_entry_get_name(uentry); - udevice = udev_device_new_from_syspath(udev, path); - name = udev_device_get_sysname(udevice); - - if (strncmp("event", name, 5) != 0) - { - udev_device_unref(udevice); - continue; - } - - if (!_device_add(input, udevice)) + if ((eeze_udev_syspath_is_mouse(device)) || + (eeze_udev_syspath_is_kbd(device)) || + (eeze_udev_syspath_is_touchpad(device)) || + (eeze_udev_syspath_is_joystick(device))) { - udev_device_unref(udevice); - continue; + if (!_device_add(input, device)) + ERR("\tFailed to add device"); + else + found = EINA_TRUE; } - found = EINA_TRUE; - - udev_device_unref(udevice); + eina_stringshare_del(device); } - udev_enumerate_unref(uenum); - if (!found) { ERR("No Input Devices Found"); @@ -289,7 +277,7 @@ ecore_drm_inputs_create(Ecore_Drm_Device *dev) Ecore_Drm_Input *input; /* check for valid device */ - if ((!dev) || (!udev)) return EINA_FALSE; + if (!dev) return EINA_FALSE; /* try to allocate space for input structure */ if (!(input = calloc(1, sizeof(Ecore_Drm_Input)))) @@ -340,55 +328,31 @@ ecore_drm_inputs_enable(Ecore_Drm_Input *input) /* check for valid input */ if (!input) return EINA_FALSE; - if (!input->monitor) - input->monitor = udev_monitor_new_from_netlink(udev, "udev"); - - if (!input->monitor) - { - ERR("Could not create udev monitor: %m"); - return EINA_FALSE; - } - - /* setup input filter */ - udev_monitor_filter_add_match_subsystem_devtype(input->monitor, - "input", NULL); - - /* try to enable receiving udev events */ - if (udev_monitor_enable_receiving(input->monitor)) - { - ERR("Could not bind udev monitor: %m"); - udev_monitor_unref(input->monitor); - return EINA_FALSE; - } - - /* save the fd */ - if ((input->fd = udev_monitor_get_fd(input->monitor)) < 0) + if (!input->watch) { - ERR("Input monitor has no fd: %m"); - udev_monitor_unref(input->monitor); - return EINA_FALSE; - } - - /* create fd handler */ - if (!input->hdlr) - { - input->hdlr = - ecore_main_fd_handler_add(input->fd, ECORE_FD_READ, - _cb_input_event, input, NULL, NULL); - } - - if (!input->hdlr) - { - ERR("Failed to setup input fd handler: %m"); - udev_monitor_unref(input->monitor); - return EINA_FALSE; + int events = 0; + + events = (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE); + /* NB: This really sucks !! We cannot 'OR' diferent device types + * together for eeze_udev_watch_add :( + * + * For now, just put a 'watch' on mouse type as this (in effect) does + * what we need by internally by adding a subsystem match for 'input' */ + if (!(input->watch = + eeze_udev_watch_add(EEZE_UDEV_TYPE_MOUSE, events, + _cb_input_event, input))) + { + ERR("Could not create Eeze_Udev_Watch for input"); + return EINA_FALSE; + } } /* try to add devices */ if (!_devices_add(input)) { ERR("Could not add input devices"); - udev_monitor_unref(input->monitor); + eeze_udev_watch_del(input->watch); + input->watch = NULL; return EINA_FALSE; } @@ -403,13 +367,11 @@ ecore_drm_inputs_disable(Ecore_Drm_Input *input) { if (!input) return; - if (input->monitor) udev_monitor_unref(input->monitor); - input->monitor = NULL; - - if (input->hdlr) ecore_main_fd_handler_del(input->hdlr); - input->hdlr = NULL; + if (input->watch) eeze_udev_watch_del(input->watch); + input->watch = NULL; input->enabled = EINA_FALSE; input->suspended = EINA_TRUE; + ecore_drm_inputs_destroy(input->dev); } --
