1
0
forked from mirrors/0ad

Do not trigger "HotkeyPress" events when releasing a key.

Follows d0a42f2f00.
Because only the most specific hotkeys can be active at any time,
releasing a key may require re-activating less specific hotkeys.
There were two issues with this behaviour:
- It was buggy, as it only checked one active key, when any still active
key can trigger hotkeys.
- "HotkeyPress" and "HotkeyDown" events where sent, as if the hotkey was
pressed, which was unexpected for most code/users (it is unusual to have
a "Press" event on key release).

This fixes these issues by "silently" re-triggering the hotkeys in such
a case. It also makes it easier for JS code to use "hotkeyPress" instead
of "hotkeyDown" for non-continuous behaviour.

Accepted By: nani
Fixes #6123
Refs #6064 (fixes the problem, but not the code weirdness)

Differential Revision: https://code.wildfiregames.com/D3766
This was SVN commit r25169.
This commit is contained in:
wraitii
2021-03-31 15:50:25 +00:00
parent 457c538780
commit 4b46c09222
9 changed files with 277 additions and 136 deletions
@@ -48,8 +48,11 @@ template<> void ScriptInterface::ToJSVal<SDL_Event_>(const ScriptRequest& rq, JS
case SDL_MOUSEBUTTONDOWN: typeName = "mousebuttondown"; break;
case SDL_MOUSEBUTTONUP: typeName = "mousebuttonup"; break;
case SDL_QUIT: typeName = "quit"; break;
case SDL_HOTKEYPRESS: typeName = "hotkeypress"; break;
case SDL_HOTKEYDOWN: typeName = "hotkeydown"; break;
case SDL_HOTKEYUP: typeName = "hotkeyup"; break;
case SDL_HOTKEYPRESS_SILENT: typeName = "hotkeypresssilent"; break;
case SDL_HOTKEYUP_SILENT: typeName = "hotkeyupsilent"; break;
default: typeName = "(unknown)"; break;
}
@@ -111,8 +114,11 @@ template<> void ScriptInterface::ToJSVal<SDL_Event_>(const ScriptRequest& rq, JS
SET(obj, "clicks", (int)val.ev.button.clicks);
break;
}
case SDL_HOTKEYPRESS:
case SDL_HOTKEYDOWN:
case SDL_HOTKEYUP:
case SDL_HOTKEYPRESS_SILENT:
case SDL_HOTKEYUP_SILENT:
{
SET(obj, "hotkey", static_cast<const char*>(val.ev.user.data1));
break;