Repository navigation
daemon: debounce rubber and button flags to avoid spurious stylus lifts - #233
06FallingLight90 wants to merge 2 commits into
Conversation
Some third-party MPP styli (see linux-surface#195) constantly flicker the eraser and side button phase detection: the sign of the phase correlation computed in handle_button() flips several times per second while writing. Since StylusDevice::update() lifts the pen for one frame on every tool flip, each flicker is emitted as a full BTN_TOOL_PEN 0 -> 1 cycle, which is perceived as constant disconnects while inking (measured ~3 lift cycles per second, with a stable 0.030s lift-to-retouch interval). Debounce both flags: a flip only becomes visible once it has been seen in 2 consecutive updates (~30ms at the typical DFT rate, imperceptible for real tool switches and button presses, while single-frame flickers are dropped entirely). On an affected Surface Pro 7+ this reduces stylus disconnects from 123 per 40s writing session to 0, without affecting real eraser usage.
|
This fix doesn't work on my machine. Interestingly, the diagnosis is correct - I verified the issue is caused by the eraser button triggering. I will investigate why the fix isn't working. Edit: It looks like my issue is caused by the MPP2 based button detection mechanism instead of the phase sign one, so this PR wouldn't be expected to help. |
Some third-party MPP pens constantly produce spurious eraser / button events through the MPP v2 binary frame detection. Document the two independent detection paths and how to disable the MPP v2 button detection for affected pens, complementing the StylusDevice debounce added for the phase based path (linux-surface#195).
|
Thanks — this matches what we see and adds an important piece: there are two independent detection paths that can each produce spurious eraser / button events:
Both paths feed the same choke point: a flipped I just ran the discrimination experiment on my setup (third-party MPP 2.0 pen, phase-sign case): setting
I've documented your workaround in the example config (second commit in this PR) so affected users can find it. Making the debounce depth configurable might be a sensible follow-up for pens that emit longer bursts. |
Problem
Third-party MPP styli can produce constant "disconnects" while writing: the pen is repeatedly lifted and put back down several times per second. This is the symptom reported in #195.
Instrumenting an affected setup (Surface Pro 7+, iptsd 3.1.1) shows that the stylus data stream itself is healthy: the pen reports
proximity = 1continuously and DFT position windows arrive at a constant ~66 Hz. What actually happens is:handle_button()derives the eraser / side button state from the sign of a phase correlation (val). With some pensvalhovers near zero while writing, sodata.rubber/data.buttonflip back and forth several times per second (measured: 424 flips within 10 minutes of normal writing).StylusDevice::update()lifts the pen for one frame on every tool flip ("Switching tools within one frame causes issues, lift the stylus for one frame"). Every single-frame flicker is therefore emitted as a fullBTN_TOOL_PEN 1 -> 0 -> 1cycle — perceived as a disconnect (~3/s, with a stable 0.030 s lift-to-retouch interval = 2 frames at the DFT rate).This also explains the
wevobservations in #195: each spurious lift makes libinput leave and re-enter tool proximity, which shows up downstream as duplicated coordinates followed by zero-timestamped motion events.Fix
Debounce both flags in
StylusDevice::update(): a flip only becomes visible after it has been seen in 2 consecutive updates (~30 ms at the typical DFT rate — imperceptible for real tool switches and button presses), while single-frame flickers are dropped entirely.BTN_STYLUSis debounced with the same scheme, since flapping it is interpreted as clicks by some applications.Validation
On an affected Surface Pro 7+ with a third-party MPP 2.0 pen:
BTN_TOOL_PENdrops while writing): 123 per 40 s session → 0Krita, Xournal, Okular and LibreOffice Draw all write continuously after the fix.
References #195 (assuming the reporter's pen flickers the same way; a quick discriminator is writing while holding the side button, which stops the disconnects completely on the pen tested here).