Skip to content

Commit

Permalink
Fix: Previous key state for repeat count in X11
Browse files Browse the repository at this point in the history
Currently, as we've spoken in #69
@dcap has correctly pointed out that my patch has some problems with
shift key modifier - and he was correct, I've skipped an important thing
looking into this problem.

So if we hold a key and the next event that will come will be different than
the current one - it will reset repeat count. If it's shift for example,
holding a trigger left mouse button on keyboard will correctly set the
repeat count to 1, but as soon as we press shift during that for
example, then it will bring the repeat count for the key to 0, since the new
m_pressedKeySym will be equal to the shift button.

Solution for that is to simply keep a map of states of the current
keyboard - it will remember last state of the button that got pressed.
So even if we will press Shift, and after that comes another event with
the key that got mapped to left mouse button - we will check the last
state of the mapped key, not shift for example.
  • Loading branch information
tetektoza committed Oct 3, 2023
1 parent 58709a0 commit 4e4a0cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 7 additions & 7 deletions os/x11/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,18 +1042,18 @@ void WindowX11::processX11Event(XEvent& event)
KEY_TRACE("Xutf8LookupString %s\n", &buf[0]);
}


// 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.
// and if yes - check what's the previous state
// of the key symbol - if it was previously pressed
// set repeat count of 1, if it wasn't pressed previously
// it will set repeat count to 0
if (event.type == KeyPress) {
if (keysym == m_pressedKeySym)
if (map_keys[keysym])
ev.setRepeat(1);
m_pressedKeySym = keysym;
}
else
m_pressedKeySym = 0;

map_keys[keysym] = event.type == KeyPress ? true : false;
// Key event used by the input method (e.g. when the users
// presses a dead key).
if (XFilterEvent(&event, m_window))
Expand Down
5 changes: 2 additions & 3 deletions os/x11/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

#include <map>
#include <cstring>
#include <string>

Expand Down Expand Up @@ -128,8 +128,7 @@ class WindowX11 : public Window {
bool m_resizable = false;
bool m_transparent = false;

KeySym m_pressedKeySym = 0;

std::map<KeySym, bool> map_keys;
// Double-click info
Event::MouseButton m_doubleClickButton;
base::tick_t m_doubleClickTick;
Expand Down

0 comments on commit 4e4a0cb

Please sign in to comment.