Skip to content

Commit 22ae9e8

Browse files
authored
Handle mod key edge-cases in tiling WMs (OpenRCT2#14426)
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 #1 Mod+2 -> Goes to workspace #2 ... Mod+9 -> Goes to workspace #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.
2 parents 6b96507 + 86cf0dc commit 22ae9e8

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

contributors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ The following people are not part of the development team, but have been contrib
178178
* (ocalhoun6)
179179
* Sean Payne (seanmajorpayne)
180180
* Soham Roy (sohamroy19)
181+
* Gaven Rendell (Rendello)
181182

182183
## Toolchain
183184
* (Balletie) - macOS

src/openrct2-ui/UiContext.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,15 @@ class UiContext final : public IUiContext
523523
#endif
524524
case SDL_KEYDOWN:
525525
{
526+
#ifndef __MACOSX__
527+
// Ignore winkey keydowns. Handles edge case where tiling
528+
// window managers don't eat the keypresses when changing
529+
// workspaces.
530+
if (SDL_GetModState() & KMOD_GUI)
531+
{
532+
break;
533+
}
534+
#endif
526535
_textComposition.HandleMessage(&e);
527536
auto ie = GetInputEventFromSDLEvent(e);
528537
ie.State = InputEventState::Down;

0 commit comments

Comments
 (0)