Help writing a virtual touchpad

Peter Hutterer peter.hutterer at
Tue May 11 21:30:19 UTC 2021

On Tue, May 11, 2021 at 10:15:39AM +0200, Andrea Somaini wrote:
> Thanks a lot for your detailed response, that blog post was amazing and it made some things much more clearer.
> At the end, I managed to write a kernel driver that receives input through
> a character device and sends raw input events, without ever knowing the
> existence of evdev. It still need a lot of tweaking regarding resolution
> and which events I should send and which not. (e.g. should I communicate
> the pressure if my data does not contain information about it? What about
> tool_width/major-axis and such?)

The only thing pressure is used for atm is for palm and thumb detection.
Given you're writing a virtual touchpad, you shouldn't need either.
Same for major/minor. Tool width is unused in libinput so I wouldn't bother
with it either.
> Anyway, with some trial and error the driver kinda works and I got to see
> 1:1 multitouch gesture on GNOME 40 :)
> Regarding performance: I use a userspace process to write to a character
> device which talks to my kernelspace code, maybe using evdev directly
> avoids some layers of abstraction? And in this way I don’t have to write
> any kernelspace code right?

correct, uinput is a module supported everywhere and would not
require a custom kernel module. Using it removes one moving part, you only
need the userspace process because everything else is already there (and
well-tested :)


> Repo with my code:
> Thank you so much,
> Andrea
> Il 11 mag 2021, 03:09 +0200, Peter Hutterer <peter.hutterer at>, ha scritto:
> > On Sat, May 08, 2021 at 12:45:24PM +0200, Andrea Somaini wrote:
> > > Hello,
> > > I was thinking about creating a virtual touchpad device for Linux
> > > I never worked on such low level software, so I feel kinda lost
> > > Can someone please point me where should I start?
> >
> > The best option you have at this point is to emulate an evdev node that
> > behaves like a touchpad. That's both straightforward and complicated at the
> > same time. The code itself is trivial (use python-libevdev, check the
> > examples directory) but getting touchpads right in evdev can be a bit
> > tricky - you really need to know the details of the evdev protocol.
> >
> > If you look at the libinput test devices (e.g.
> > test/litest-device-synaptics-rmi4.c) you get a **rough** idea of the events
> > you need to send for a finger down event and a finger move event.
> > You still need to handle BTN_TOOL_DOUBLETAP, etc.
> > What I recommend is: use libinput record to record 1, 2, 3... finger
> > interactions on your normal touchpad to get the set of data sent, then
> > emulate that device. Axis ranges and coordinates can generally be changed
> > at-will, but the set of events within each frame has to be correct (or
> > correct enough) to be processed as expected.
> >
> > has some
> > explanations too.
> >
> > Cheers,
> > Peter
> >

More information about the wayland-devel mailing list