High CPU usage due to interaction between tablet pen and pointer
This was first reported at https://github.com/swaywm/wlroots/issues/2471, but concluded to most likely be a gdk issue. The following is mostly copied from that issue, updated with some results from the discussion
Setup
- Arch, sway-git, wlroots-git, gtk 3.24.23
- Input devices: touchpad and Wacom Intuos tablet
Steps
- launch any GTK application (e.g. Xournal++, gtk3-demo)
- move the cursor over the window using the touchpad
- hover the stylus above the tablet (no touches/button presses necessary)
Sway will consume huge amounts of CPU (80% on one core in my case) while the stylus is in proximity of the tablet. The GTK client also has increased CPU usage, but nowhere near as extreme. CPU usage remains at that level even when the inputs are completely stationary (as verified with libinput debug-events).
Here is a (truncated) log of WAYLAND_DEBUG=1 gtk3-demo, where I made sure that the cursor was outside the new window on startup:
Everything is fine when moving the stylus to the application window. However, after briefly touching the touchpad such that the wl_pointer also enters the surface, havoc ensues: Somehow, the wl_pointer and zwp_tablet_tool_v2 interact in such a fashion that some surfaces (the pointer surfaces I think) constantly receive enter and leave events, which are followed by gdk setting new cursors. I captured a perf call graph in that situation, and sway indeed spends lots of time setting up (hardware) cursors.
wlr-gdk.zip (zipped svg flamegraph)
The bug also occurs when the touchpad and tablet are attached to different seats (such that there are two independent cursors).