From f10526284f2b9ea6cfa62395bc3831a2c597e73b Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Sat, 22 Feb 2025 20:59:48 +0100 Subject: [PATCH] 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 --- source/ps/Hotkey.cpp | 3 +-- source/ps/Hotkey.h | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/ps/Hotkey.cpp b/source/ps/Hotkey.cpp index 633e61d9ba..55203ecdbd 100644 --- a/source/ps/Hotkey.cpp +++ b/source/ps/Hotkey.cpp @@ -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::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. diff --git a/source/ps/Hotkey.h b/source/ps/Hotkey.h index 5bcfaa19ad..46596afc47 100644 --- a/source/ps/Hotkey.h +++ b/source/ps/Hotkey.h @@ -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 {