bitbof / klecks

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

Pressure isn't working on Firefox on Linux #129

Open denilsonsa opened 1 week ago

denilsonsa commented 1 week 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 1 week 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 1 week 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 1 week 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 1 week 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.