From 592d028e5d9747c84dd846a166efc10e7363e98a Mon Sep 17 00:00:00 2001 From: tetektoza Date: Thu, 28 Sep 2023 14:57:29 +0200 Subject: [PATCH] Fix: Drawing using a keyboard key on X11 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. --- os/x11/window.cpp | 14 +++++++++++++- os/x11/window.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/os/x11/window.cpp b/os/x11/window.cpp index b08166b01..3de5fe430 100644 --- a/os/x11/window.cpp +++ b/os/x11/window.cpp @@ -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; diff --git a/os/x11/window.h b/os/x11/window.h index 1625d5d1a..5fd9d637b 100644 --- a/os/x11/window.h +++ b/os/x11/window.h @@ -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;