Bug regarding evdev input and compositor focus

Ran Benita ran234 at gmail.com
Tue Dec 13 09:30:04 PST 2011


Hello,

I was writing some input handling code for a separate program, when I
stumbled into an issue and eventually decided to look at how wayland
does it for inspiration. Unfortunately, wayland has a similar issue ;(

The bug can be reproduced easily:
- Start compositor-drm on some VT.
- Switch to another VT.
- Watch the CPU utilization go to 100%.

In order to stop receiving input events when we VT switch out of wayland
(i.e compositor->focus = false), the function evdev_input_device_data
has a simple check:

        ec = device->master->base.compositor;
        if (!ec->focus)
                return 1;

This check goes *before* the read(), the device fd always has data in
it, the event loop keeps dispatching it, and we get into an endless
loop until we get focus again.

I guess there are a few ways to solve it:
- Move the check after the read (not very nice).
- Remove the fd from event loop when losing focus.
- Close the fd altogether and re-open() when we get focus again.
The latter is how X does it (see hw/xfree86/common/xf86Events.c,
xf86VTSwitch()).

Thanks,
Ran


More information about the wayland-devel mailing list