Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1609433

Re: [PATCH v3] Documentation: Input: Add uinput documentation

From Marcos Paulo de Souza <marcos.souza.org@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH v3] Documentation: Input: Add uinput documentation
Date 2017-03-27 04:50 +0200
Message-ID <tpsTf-133-1@gated-at.bofh.it> (permalink)
References <tpjGi-2B4-13@gated-at.bofh.it> <tpjGi-2B4-11@gated-at.bofh.it> <tprkt-8oO-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, Mar 27, 2017 at 11:06:11AM +1000, Peter Hutterer wrote:
> On Sun, Mar 26, 2017 at 01:48:12PM -0300, Marcos Paulo de Souza wrote:
> > Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
> > ---
> >  v2 -> v3:
> >  Changes in libevdev's description (suggested by Peter)
> >  Added uinput version check when using the old interface (suggested by Peter)
> >  Removed section numbers from sections, sphinx creates these indexes
> >  	(suggestion by Jon)
> > 
> >  v1 -> v2:
> >  Changes all over the place, including better descriptions (suggested by Peter)
> >  Added comments about the need of a sleep call (suggested by Peter)
> >  
> 
> 
> [...]
> 
> tested mouse/keyboard - works as expected, thanks. I found it slightly
> confusing though that the mouse example wasn't wrapped in main() but still had a
> return 0 at the bottom. This code will never change once it's in the doc, so
> I'm not sure skipping things is really that useful here.

True, I'll "complete" the code in the next submission.

> 
> > +uinput old interface
> > +--------------------
> > +
> > +Before uinput version 5, there wasn't a proper ioctl to setup a virtual device.
> > +In this case, the user neesa to fill a different struct and call write o the
> > +uinput file descriptor to configure the new uinput device.
> > +
> > +.. code-block:: c
> > +
> > +    #include <linux/uinput.h>
> > +
> > +    /* emit function is identical to of the first example */
> > +
> > +    struct uinput_user_dev uud;
> > +    int version;
> > +
> > +    fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
> > +    ioctl(fd, UI_GET_VERSION, &version);
> > +
> > +    if (version < 5) {
> 
> this won't work on all kernels. UI_GET_VERSION was added in version 4, on
> kernels before you get rc == -1 and errno EINVAL. You can only check
> for >= 4. Please make sure the example compiles and works on an older
> kernel, otherwise there's no point shipping it.

OK, noting here.

> 
> Cheers,
>    Peter
> 
> > +        /*
> > +         * the ioctls below enables the to be created device to key
> > +         * events, in this case the space key
> > +         */
> > +        ioctl(fd, UI_SET_EVBIT, EV_KEY);
> > +        ioctl(fd, UI_SET_KEYBIT, KEY_SPACE);
> > +
> > +        memset(&uud, 0, sizeof(uud));
> > +        snprintf(uud.name, UINPUT_MAX_NAME_SIZE, "uinput old interface");
> > +        write(fd, &uud, sizeof(uud));
> > +
> > +        ioctl(fd, UI_DEV_CREATE);
> > +
> > +        /*
> > +         * On UI_DEV_CREATE the kernel creates the device nodes for this device.
> > +         * Insert a pause so that userspace has time to detect, initialize the
> > +         * new device, and can start to listen to events from this device
> > +         */
> > +        sleep(1);
> > +
> > +        /* key press, report the event, send key release, and report again */
> > +        emit(EV_KEY, KEY_SPACE, 1);
> > +        emit(EV_SYN, SYN_REPORT, 0);
> > +        emit(EV_KEY, KEY_SPACE, 0);
> > +        emit(EV_SYN, SYN_REPORT, 0);
> > +
> > +        ioctl(fd, UI_DEV_DESTROY);
> > +    }
> > +
> > +    close(fd);
> > +
> > +    return 0;
> > +
> > -- 
> > 2.9.3
> > 

-- 
Thanks,
	Marcos

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH v3] Adding uinput documentation Marcos Paulo de Souza <marcos.souza.org@gmail.com> - 2017-03-26 19:00 +0200
  [PATCH v3] Documentation: Input: Add uinput documentation Marcos Paulo de Souza <marcos.souza.org@gmail.com> - 2017-03-26 19:00 +0200
    Re: [PATCH v3] Documentation: Input: Add uinput documentation Peter Hutterer <peter.hutterer@who-t.net> - 2017-03-27 03:10 +0200
      Re: [PATCH v3] Documentation: Input: Add uinput documentation Marcos Paulo de Souza <marcos.souza.org@gmail.com> - 2017-03-27 04:50 +0200

csiph-web