[PATCH xf86-input-evdev] evdev: Add support for server managed fds
Peter Hutterer
peter.hutterer at who-t.net
Sun Mar 9 23:16:08 PDT 2014
On Sat, Mar 08, 2014 at 10:28:00AM +0100, Hans de Goede wrote:
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
pushed, thanks
Cheers,
Peter
> ---
> src/evdev.c | 49 ++++++++++++++++++++++++++++---------------------
> 1 file changed, 28 insertions(+), 21 deletions(-)
>
> diff --git a/src/evdev.c b/src/evdev.c
> index d1ed9ee..ed84f0f 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -97,6 +97,10 @@
> #define ABS_MT_TRACKING_ID 0x39
> #endif
>
> +#ifndef XI86_SERVER_FD
> +#define XI86_SERVER_FD 0x20
> +#endif
> +
> static const char *evdevDefaults[] = {
> "XkbRules", "evdev",
> "XkbModel", "pc104", /* the right model for 'us' */
> @@ -2478,32 +2482,32 @@ EvdevOpenDevice(InputInfoPtr pInfo)
> xf86IDrvMsg(pInfo, X_CONFIG, "Device: \"%s\"\n", device);
> }
>
> - if (pInfo->fd < 0)
> + if (!(pInfo->flags & XI86_SERVER_FD) && pInfo->fd < 0)
> {
> do {
> pInfo->fd = open(device, O_RDWR | O_NONBLOCK, 0);
> } while (pInfo->fd < 0 && errno == EINTR);
> + }
>
> - if (pInfo->fd < 0) {
> - xf86IDrvMsg(pInfo, X_ERROR, "Unable to open evdev device \"%s\".\n", device);
> - return BadValue;
> - }
> + if (pInfo->fd < 0) {
> + xf86IDrvMsg(pInfo, X_ERROR, "Unable to open evdev device \"%s\".\n", device);
> + return BadValue;
> + }
>
> - if (libevdev_get_fd(pEvdev->dev) != -1) {
> - struct input_event ev;
> + if (libevdev_get_fd(pEvdev->dev) != -1) {
> + struct input_event ev;
>
> - libevdev_change_fd(pEvdev->dev, pInfo->fd);
> - /* re-sync libevdev's view of the device, but
> - we don't care about the actual events here */
> - libevdev_next_event(pEvdev->dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev);
> - while (libevdev_next_event(pEvdev->dev, LIBEVDEV_READ_FLAG_SYNC, &ev) == LIBEVDEV_READ_STATUS_SYNC)
> - ;
> - } else {
> - int rc = libevdev_set_fd(pEvdev->dev, pInfo->fd);
> - if (rc < 0) {
> - xf86IDrvMsg(pInfo, X_ERROR, "Unable to query fd: %s\n", strerror(-rc));
> - return BadValue;
> - }
> + libevdev_change_fd(pEvdev->dev, pInfo->fd);
> + /* re-sync libevdev's view of the device, but
> + we don't care about the actual events here */
> + libevdev_next_event(pEvdev->dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev);
> + while (libevdev_next_event(pEvdev->dev, LIBEVDEV_READ_FLAG_SYNC, &ev) == LIBEVDEV_READ_STATUS_SYNC)
> + ;
> + } else {
> + int rc = libevdev_set_fd(pEvdev->dev, pInfo->fd);
> + if (rc < 0) {
> + xf86IDrvMsg(pInfo, X_ERROR, "Unable to query fd: %s\n", strerror(-rc));
> + return BadValue;
> }
> }
>
> @@ -2531,7 +2535,7 @@ static void
> EvdevCloseDevice(InputInfoPtr pInfo)
> {
> EvdevPtr pEvdev = pInfo->private;
> - if (pInfo->fd >= 0)
> + if (!(pInfo->flags & XI86_SERVER_FD) && pInfo->fd >= 0)
> {
> close(pInfo->fd);
> pInfo->fd = -1;
> @@ -2679,7 +2683,10 @@ _X_EXPORT InputDriverRec EVDEV = {
> EvdevPreInit,
> EvdevUnInit,
> NULL,
> - evdevDefaults
> + evdevDefaults,
> +#ifdef XI86_DRV_CAP_SERVER_FD
> + XI86_DRV_CAP_SERVER_FD
> +#endif
> };
>
> static void
> --
> 1.8.4.2
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>
More information about the xorg-devel
mailing list