Change libevdev_grab to take an enum

Enum values fo 3 and 4 to avoid callers using true/false values for grabbing
and ungrabbing. If the evdev mute ioctl is merged, we can extend this
without having to worry about breaking callers.

[1] http://lwn.net/Articles/476830/

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2013-05-31 14:48:43 +10:00
parent cfcfa4c159
commit 27528b9668
2 changed files with 14 additions and 2 deletions

View file

@ -847,9 +847,15 @@ libevdev_grab(struct libevdev *dev, int grab)
{
int rc = 0;
if (grab && !dev->grabbed)
if (grab != LIBEVDEV_GRAB && grab != LIBEVDEV_UNGRAB)
return -EINVAL;
if (grab == dev->grabbed)
return 0;
if (grab == LIBEVDEV_GRAB)
rc = ioctl(dev->fd, EVIOCGRAB, (void *)1);
else if (!grab && dev->grabbed)
else if (grab == LIBEVDEV_UNGRAB)
rc = ioctl(dev->fd, EVIOCGRAB, (void *)0);
if (rc == 0)

View file

@ -83,6 +83,12 @@ typedef void (*libevdev_log_func_t)(const char *format, va_list args);
*/
void libevdev_set_log_handler(struct libevdev *dev, libevdev_log_func_t logfunc);
enum EvdevGrabModes {
LIBEVDEV_GRAB = 3,
LIBEVDEV_UNGRAB = 4,
};
/**
* Grab or ungrab the device through a kernel EVIOCGRAB. This prevents other
* clients (including kernel-internal ones such as rfkill) from receiving