Skip to content

Commit

Permalink
Handle mod key edge-cases in tiling WMs
Browse files Browse the repository at this point in the history
This commit ignores keypresses when the mod key is held.

The reasoning is that an odd interaction happens between SDL applications and
tiling window managers. Tiling window managers like Xmonad and i3 usually use
the mod ("windows") key and a number to change workspaces. When changing
workspaces, however, the WMs still send the number key through instead of
"eating" it. It's not clear why, exactly, but it seems universal.

Mod+1 -> Goes to workspace OpenRCT2#1
Mod+2 -> Goes to workspace OpenRCT2#2
 ...
Mod+9 -> Goes to workspace OpenRCT2#9

Most applications don't even see the number key being sent, so if you move to
workspace 1, Firefox won't type "1" into the browser bar, Vim won't type "1"
into your file, etc. But SDL applications, for whatever reason, DO see this
keydown. Of course, they'll handle it like a regular key press. So if you move
to workspace 1, which contains OpenRCT, it inadvertently toggles x-ray mode.

I first found this bug in another SDL game, The Powder Toy. After some
discussion with the devs, they fixed it like this, by ignoring keydown events
when the mod key is pressed, since the mod key is reserved for the window
manager anyway. It works well and should be in the next release.

The-Powder-Toy/The-Powder-Toy@c761938...93b920a

I did the same thing here.
  • Loading branch information
rendello committed Apr 2, 2021
1 parent 7344b7f commit 0ffe573
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/openrct2-ui/UiContext.cpp
Expand Up @@ -526,6 +526,12 @@ class UiContext final : public IUiContext
#endif
case SDL_KEYDOWN:
{
// Ignore keydowns when mod is held. Handles edge cases
// where window managers don't eat the keypresses.
if (SDL_GetModState() & KMOD_GUI)
{
break;
}
_textComposition.HandleMessage(&e);
auto ie = GetInputEventFromSDLEvent(e);
ie.State = InputEventState::Down;
Expand Down

0 comments on commit 0ffe573

Please sign in to comment.