aseprite / laf

A C++ library to create desktop applications
https://aseprite.github.io/laf/
MIT License
274 stars 58 forks source link

Fix: Drawing using a keyboard key on X11 #69

Closed tetektoza closed 10 months ago

tetektoza commented 10 months ago

As spoken in https://github.com/aseprite/aseprite/pull/4063 - currently, if we try to bind a key to mouse trigger button and we will try to draw with it - after a longer period of holding the key, drawing will stop and will try to draw continously with short breaks.

This is caused because we never set repeat count inside the event that we generate from the event that comes from X Window System.

Repeat count is being properly checked in doc_view.cpp:onProcessMessage method, although it always equals 0 - thus allowing for the key event to be converted to mouse event, and at the same time interpreting (and queueing) it as a mouse event.

Solution for that is to simply check if the previous key event that came was KeyPress, and if it is currently pressed. If yes - it means that user never pushed the key down, thus set repeat count to 1. Otherwise, if the previous key event is KeyRelease for example - it means user has pushed the key down, thus repeat count on the current event can be set to 0.

I agree that my contributions are licensed under the MIT License. You can find a copy of this license at https://opensource.org/licenses/MIT

tetektoza commented 10 months ago

Maybe we could also change repeat variable to be of type bool, but I'd have to check in places where it's used so it would not cause a regression.

dacap commented 10 months ago

Thanks @tetektoza, I'll merge this as it works better than the current version. Anyway there are still problems when we use Shift modifier to keep a square ratio, etc on line/circle/rectangle tools.

As a side note, the idea of the "repeat" field was as a counter of "how many times the key was autopressed by the OS", but I'll make a comment about this in #70 where it makes more sense.