mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 01:04:06 +00:00
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:
@@ -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
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user