Skip to content

Commit

Permalink
Fix: Drawing using a keyboard key on X11
Browse files Browse the repository at this point in the history
As spoken in aseprite/aseprite#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.
  • Loading branch information
tetektoza committed Oct 1, 2023
1 parent cbb157c commit 592d028
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion os/x11/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,19 @@ void WindowX11::processX11Event(XEvent& event)
KEY_TRACE("Xutf8LookupString %s\n", &buf[0]);
}

// Key event used by the input method (e.g. when the user
// Check if the key has been pressed,
// and if yes - check if it's the same one key
// as in the previous event. If it's the same one
// - it means key is being held, so set repeat to 1.
if (event.type == KeyPress) {
if (keysym == m_pressedKeySym)
ev.setRepeat(1);
m_pressedKeySym = keysym;
}
else
m_pressedKeySym = 0;

// Key event used by the input method (e.g. when the users
// presses a dead key).
if (XFilterEvent(&event, m_window))
break;
Expand Down
2 changes: 2 additions & 0 deletions os/x11/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class WindowX11 : public Window {
bool m_resizable = false;
bool m_transparent = false;

KeySym m_pressedKeySym = 0;

// Double-click info
Event::MouseButton m_doubleClickButton;
base::tick_t m_doubleClickTick;
Expand Down

0 comments on commit 592d028

Please sign in to comment.