Don't map unknown scancodes to hotkeys

Users may generate key presses that don't map to a distinct SDL scancode
and will be mapped SDL_SCANCODE_UNKNOWN instead. Using the same ID for
unmapped hotkeys means any such key press will execute unset hotkeys. As
luck would have it in #7644 this leads to calling "Custom exit to
desktop" if the hotkey is unbound as is the default.

So simply use a code for unused hotkeys that doesn't map to any SDL
scancodes.

Fixes: #7644
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser
2025-02-22 20:59:48 +01:00
parent 75f414c665
commit f10526284f
2 changed files with 4 additions and 4 deletions
+1 -2
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2023 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -71,7 +71,6 @@ namespace {
static_assert(std::is_integral<std::underlying_type<SDL_Scancode>::type>::value, "SDL_Scancode is not an integral enum.");
static_assert(SDL_USEREVENT_ == SDL_USEREVENT, "SDL_USEREVENT_ is not the same type as the real SDL_USEREVENT");
static_assert(UNUSED_HOTKEY_CODE == SDL_SCANCODE_UNKNOWN);
// Look up each key binding in the config file and set the mappings for
// all key combinations that trigger it.
+3 -2
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2023 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -49,7 +49,8 @@ const uint SDL_HOTKEYUP = SDL_USEREVENT_ + 2;
const uint SDL_HOTKEYPRESS_SILENT = SDL_USEREVENT_ + 3;
const uint SDL_HOTKEYUP_SILENT = SDL_USEREVENT_ + 4;
constexpr SDL_Scancode_ UNUSED_HOTKEY_CODE = 0; // == SDL_SCANCODE_UNKNOWN
// Value not mapping to any valid SDL_SCANCODE_*
constexpr SDL_Scancode_ UNUSED_HOTKEY_CODE{-1};
struct SKey
{