[Scummvm-git-logs] scummvm master -> e302590cab4d70f7106824b1981d0941ccb1fa70

criezy noreply at scummvm.org
Sun Mar 13 21:34:54 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
e302590cab SDL: Improve AmigaOS workaround for numpad


Commit: e302590cab4d70f7106824b1981d0941ccb1fa70
    https://github.com/scummvm/scummvm/commit/e302590cab4d70f7106824b1981d0941ccb1fa70
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2022-03-13T21:33:39Z

Commit Message:
SDL: Improve AmigaOS workaround for numpad

The previous workaround was introduced to fix fighting using the keypad
in Indy 3. It enforced genering a number on KEYCODE_KP# events even
when KBD_NUM is not set. The issue on AmigaOS is that SDL never reports
KBD_NUM as being set. Instead we get different keycodes depending if
numlock is on or off (e.g. KEYCODE_KP3 and KEYCODE_PAGEDOWN).

The new workaround is to set the KBD_NUM modifier whenever we receive
a KEYCODE_KP# event from SDL. This way we also generate a number, but
in addition this is consistent with the modifier and works with code
that checks the KDB_NUM modifier (such as the GUI code or the AGI
engine).

Changed paths:
    backends/events/sdl/sdl-events.cpp


diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index 57abf788713..b7d0005e259 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -144,14 +144,8 @@ int SdlEventSource::mapKey(SDL_Keycode sdlKey, SDL_Keymod mod, Uint16 unicode) {
 	if (key >= Common::KEYCODE_F1 && key <= Common::KEYCODE_F9) {
 		return key - Common::KEYCODE_F1 + Common::ASCII_F1;
 	} else if (key >= Common::KEYCODE_KP0 && key <= Common::KEYCODE_KP9) {
-		// WORKAROUND:  Disable this change for AmigaOS as it's breaking numpad usage ("fighting") on that platform.
-		// This fixes bug #10558.
-		// The actual issue here is that the SCUMM engine uses ASCII codes instead of keycodes for input.
-		// See also the relevant FIXME in SCUMM's input.cpp.
-		#ifndef __amigaos4__
-			if ((mod & KMOD_NUM) == 0)
-				return 0; // In case Num-Lock is NOT enabled, return 0 for ascii, so that directional keys on numpad work
-		#endif
+		if ((mod & KMOD_NUM) == 0)
+			return 0; // In case Num-Lock is NOT enabled, return 0 for ascii, so that directional keys on numpad work
 		return key - Common::KEYCODE_KP0 + '0';
 	} else if (key >= Common::KEYCODE_UP && key <= Common::KEYCODE_PAGEDOWN) {
 		return key;
@@ -635,7 +629,17 @@ bool SdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) {
 
 	event.type = Common::EVENT_KEYDOWN;
 	event.kbd.keycode = key;
-	event.kbd.ascii = mapKey(sdlKeycode, (SDL_Keymod)ev.key.keysym.mod, obtainUnicode(ev.key.keysym));
+
+	SDL_Keymod mod = (SDL_Keymod)ev.key.keysym.mod;
+#if defined(__amigaos4__)
+	// On AmigaOS SDL always report numlock as off. However we get KEYCODE_KP# only when
+	// it is on, and get different keycodes (for example KEYCODE_PAGEDONW) when it is off.
+	if (event.kbd.keycode >= Common::KEYCODE_KP0 && event.kbd.keycode <= Common::KEYCODE_KP9) {
+		event.kbd.flags |= Common::KBD_NUM;
+		mod = SDL_Keymod(mod | KMOD_NUM);
+	}
+#endif
+	event.kbd.ascii = mapKey(sdlKeycode, mod, obtainUnicode(ev.key.keysym));
 
 #if SDL_VERSION_ATLEAST(2, 0, 0)
 	event.kbdRepeat = ev.key.repeat;
@@ -648,19 +652,28 @@ bool SdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) {
 	if (remapKey(ev, event))
 		return true;
 
-	SDL_Keycode sdlKeycode = obtainKeycode(ev.key.keysym);
-	SDL_Keymod mod = SDL_GetModState();
-
-	event.type = Common::EVENT_KEYUP;
-	event.kbd.keycode = SDLToOSystemKeycode(sdlKeycode);
-	event.kbd.ascii = mapKey(sdlKeycode, (SDL_Keymod)ev.key.keysym.mod, 0);
+	SDLModToOSystemKeyFlags(SDL_GetModState(), event);
 
-	SDLModToOSystemKeyFlags(mod, event);
+	SDL_Keycode sdlKeycode = obtainKeycode(ev.key.keysym);
 
 	// Set the scroll lock sticky flag
 	if (_scrollLock)
 		event.kbd.flags |= Common::KBD_SCRL;
 
+	event.type = Common::EVENT_KEYUP;
+	event.kbd.keycode = SDLToOSystemKeycode(sdlKeycode);
+
+	SDL_Keymod mod = (SDL_Keymod)ev.key.keysym.mod;
+#if defined(__amigaos4__)
+	// On AmigaOS SDL always report numlock as off. However we get KEYCODE_KP# only when
+	// it is on, and get different keycodes (for example KEYCODE_PAGEDONW) when it is off.
+	if (event.kbd.keycode >= Common::KEYCODE_KP0 && event.kbd.keycode <= Common::KEYCODE_KP9) {
+		event.kbd.flags |= Common::KBD_NUM;
+		mod = SDL_Keymod(mod | KMOD_NUM);
+	}
+#endif
+	event.kbd.ascii = mapKey(sdlKeycode, mod, 0);
+
 	return true;
 }
 




More information about the Scummvm-git-logs mailing list