Search code examples
javascriptlinuxpointer-eventsstylus-pen

Pen pointer events in Linux Chrome and Firefox not working as intended


I'm writing a cross-platform JavaScript-based drawing tool and run into severe problems on Linux.

First, Google Chrome's pointer events do not distinguish between the regular tip and the eraser end.

Second, in Firefox pointer events always are mouse events, never pen events.

In Chrome, the Eraser is reported as Contact. In Firefox, the pen pointer type is reported as mouse pointer type. I am aware of there having been some incantations in Firefox's configuration such as dom.w3c_pointer_events.enabled true and dom.w3c_pointer_events.dispatch_by_pointer_messages true, but they don't seem to help (anymore?).

In Xournal++, the eraser end of the pen does erase. With PySide6, the eraser end of the stylus is recognized as such (pointerType).

This is a minimal demonstration:

function print(e) {
  const theButtons = {
    "-1": "-",
    0: "Contact",
    1: "Middle",
    2: "Barrel",
    5: "Eraser"
  };
  log.innerText += ` ${e.pointerType}:${theButtons[e.button]}`;
}
area.addEventListener('contextmenu', e => e.preventDefault());
['pointerdown', 'pointerup', 'pointermove', 'pointerover'].forEach(e => area.addEventListener(e, print));
<div id="area" style="height:100px;background-color:aqua;"><span>Use stylus here</span></div>
<p id="log"></p>

Versions and equipment: Chrome 122.0.6261.94, Firefox 122.0.1, Wacom Cintiq 27QHDT, openSUSE Tumbleweed 2024-02-26, KDE PLasma 5.115.0-1.1, /sys/module/wacom*/version says v2.00


Solution

  • Welcome to the world of stuff that isn't fully implemented yet! Stuff that requires special hardware and thus only a few developers are able to test. You faced multiple bugs, let me try to make some sense out of the current status:

    Test pages

    Chrome

    Chrome/Chromium/Blink support is the best so far, but not perfect. The behavior you found is known bug: Chromium can't differentiate between pen tip and eraser input on Linux

    Otherwise, most stuff seems to be working just fine.

    Firefox

    Firefox support is incomplete, but gradually improving.


    Good luck! I wish this answer to be obsoleted "soon enough", but I understand it will take some time until we get there.