bitbof / klecks

Community funded painting tool powering Kleki.com
https://klecks.org
MIT License
232 stars 74 forks source link

Pressure isn't working on Firefox on Linux #129

Closed denilsonsa closed 4 months ago

denilsonsa commented 4 months ago

https://github.com/bitbof/klecks/assets/121676/980fb675-f4e9-42e1-a45d-969d8f9a5291

My system:

Related:

Further testing:

https://github.com/bitbof/klecks/assets/121676/7431a914-0cb4-4a5c-b212-12c4146e2f9c

denilsonsa commented 4 months ago

Related code: https://github.com/bitbof/klecks/blob/5aa871e55755ca6c72dddcddcb807c6c48c5fade/src/app/script/bb/input/pointer-listener.ts#L166-L180

The check that tries to correct the pressure for the "mouse" type is probably breaking the pressure-sensitive mouse that Firefox is reporting.

I'm sure the Firefox behavior isn't correct (it should report as a pen), so feel free to add a comment in that Mozilla bug, if you think that's relevant. After all, it's a bug that is affecting a web application and forcing developers to write workarounds for specific browsers on specific systems.

bitbof commented 4 months ago

Thanks for the detailed report and even finding the relevant section in code.

I gave it a try on Ubuntu with a Wacom One tablet. As you said the pressure works on Chrome, but not on Firefox. I disabled resetting pressure to 1 in the code section, but then the pressure was just 0.5, always. Firefox does the same when I use a mouse. (btw on Windows and Mac it works fine)

Also on other websites I got no pressure, or only 0.5. This is in line with the bug report which you've linked. Pen input is registered as type=mouse with pressure=0.5.

As it stands I see no workaround. And 0.5 pressure is not desirable. If a user with a mouse sets 10 as the brush size, but then the line has a thickness of 5, that is probably not what they want.

If the bug is resolved by Firefox I think it should automatically work in Kleki/Klecks.

bitbof commented 4 months ago

It is interesting that you seem to get proper pressure in your second video, but indeed, it's complicated by mouse input also having 0.5 pressure.

0.5 pressure for mouse input is in line with the spec: https://w3c.github.io/pointerevents/#dom-pointerevent-pressure

For hardware and platforms that do not support pressure, the value MUST be 0.5 when in the [active buttons state] and 0 otherwise.

I'll think if there is a workaround.

denilsonsa commented 4 months ago

Oh, pressure requires MOZ_USE_XINPUT2=1 environment variable on Firefox. (bug 1207700)

I can think about two workarounds:

  1. Pre-multiply the brush thickness by 2.
    • If the user wants a 12px brush, display 12px, but internally store it as 24px. Then, the 0.5 pressure will automatically reduce it back to 12px.
    • This will change the behavior for pressure-sensitive inputs, as they now can get up to twice the width of the displayed value. Probably not good.
  2. Only replace the value of 0.5 with 1.0.
    • If the current input reports a value different than 0.5, leave it as is.
    • It probably needs some memory to avoid a sudden jump to 1.0 when the user is drawing with a pressure between 0.4 and 0.6.

But both sound like a lot of work for a workaround, and they may fail at some corner-cases.

The alternative could be just wait and hope for bug 1501744 to be fixed and the patch to be applied.

bitbof commented 4 months ago

I implemented option 2. Did it without memory because it seems very unlikely for a floating point to hit exactly 0.5. If you observe jumps I'll fix that.

denilsonsa commented 4 months ago

Meanwhile, folks have fixed the Firefox bug in the latest nightly. I don't know how long until it hits stable.

bitbof commented 4 months ago

That's great news!

ncmprhnsbl commented 3 months ago

small update: as of firefox-129.0, though it's now correctly identifying the stylus, it still requires MOZ_USE_XINPUT2=1 environment variable in X11 sessions. in wayland sessions it's working out of the box.

denilsonsa commented 3 months ago

it still requires MOZ_USE_XINPUT2=1 environment variable in X11 sessions.

That is being tracked in https://bugzilla.mozilla.org/show_bug.cgi?id=1207700

See also this summary of the current state of pen input among the two major browsers: https://stackoverflow.com/a/78764151