edemaine / cocreate

Cocreate Shared Whiteboard/Drawing
MIT License
209 stars 27 forks source link

Don't consider tool down on pointerenter with button pressed (fix #218) #219

Closed groszdaniel closed 1 year ago

groszdaniel commented 1 year ago

This is intended to fix https://github.com/edemaine/cocreate/issues/218, an issue when using stylus on Chromium on Linux/X11.

The issue is caused by a combination of Chromium's behavior on this platform, and Cocreate treating a pointerenter event with a button pressed as marking the current tool as "down" even in the absence of any pointerdown event.

This commit disables that.

As a (side-)effect, if this commit is applied, one can no longer start to draw by starting dragging the mouse (or finger or stylus) on a Cocreate toolbar and then dragging in into the drawing board. I wouldn't consider this a disimprovement. (Note that if the dragging starts outside the browser window, or even on the browser's toolbars, it wouldn't start drawing even before this commit.) But if you want I can limit the change by platform using the user agent string.

edemaine commented 1 year ago

Thanks for the PR! My one hesitation here is the following existing behavior:

This currently works and I believe your PR would disable it. That said, the current behavior in the above scenario is pretty much only good with the pen tool; with the rectangle tool, the current behavior starts a new rectangle when returning to the window, instead of editing the old one.

Perhaps a better behavior would be to detect that we're pointerentering with buttons down and those buttons match a pointerleave event. Then we'd like to continue the previous operation, though this might need to be tool-specific instead of the generic code you're touching here.

What do you think?

groszdaniel commented 1 year ago

I added a setPointerCapture in the pointerdown event handler. This way, the tool simply continues if the pointer leaves the window, and also if it returns.

This way the pen tool continues drawing even when the pointer is outside the board. Other whiteboard/drawing programs I tried work like this too. It can be considered good (the line is not interrupted if the cursor briefly moves outside the window) or bad (it might draw over stuff). If you prefer it to not work like this, I can try to make the pen tool work in a special way, approx. like you suggested.

I removed the code that marked the tool as "up" on pointerleave, because

edemaine commented 1 year ago

Oh wow, the setPointerCapture behavior is exactly what I wanted. What a nice improvement! (and code simplification) I've used setPointerCapture in other projects, but surprised I never added it to Cocreate. Thanks for this nice improvement in behavior, in addition to the bug fixes for X11.