[PATCH 6/9] Add trace output for ST key modifiers

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


TODO: Because there are multiple ways for modifiers to end up in
pressed state with keymaps, some modifier key events may actually not
insert anything to IKBD.

Should there be e.g. separate trace events depending on whether key
event was inserted to IKBD or not, like in Vincent's patch?
---
 src/keymap.c | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/src/keymap.c b/src/keymap.c
index 6321d10d..0f67cbd2 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -801,19 +801,27 @@ static bool IsKeyTranslatable(SDL_Keycode symkey)
 /**
  * Set modifiers keys indicated by bits in 'mods' up or down
  * based on 'down'.
+ *
+ * Return true if modifiers were present and trace output
+ * requires newline, false otherwise.
  */
-static void InsertModifiers(uint8_t mods, bool down)
+static bool InsertModifiers(uint8_t mods, bool down)
 {
+	const char *separator;
 	uint8_t i, scancode;
 	if (!mods)
-		return;
+		return false;
 
+	separator = "key mod(s):";
 	for (i = 0; i < ARRAY_SIZE(ST_Modifiers); i++)
 	{
 		if (!(mods & ST_Modifiers[i].mod))
 			continue;
 
 		scancode = ST_Modifiers[i].scancode;
+		LOG_TRACE(TRACE_KEYMAP, "%s %s (0x%02x)",
+			  separator, ST_Modifiers[i].name, scancode);
+		separator = " |";
 
 		if (down)
 		{
@@ -834,6 +842,7 @@ static void InsertModifiers(uint8_t mods, bool down)
 		}
 		IKBD_PressSTKey(scancode, down);
 	}
+	return true;
 }
 
 
@@ -842,7 +851,8 @@ static void InsertModifiers(uint8_t mods, bool down)
  * Insert key presses and releases for ALT_XXX digits
  * when relevant modifier bit is set.
  *
- * Return true if scancode should be ignored, false otherwise.
+ * Return true if scancode should be ignored and trace output
+ * requires newline, false otherwise.
  */
 static bool InsertAltXXXDigits(ST_Key *stkey)
 {
@@ -867,6 +877,9 @@ static bool InsertAltXXXDigits(ST_Key *stkey)
 		digit = *xxx - '0';
 		assert(digit >= 0 && digit <= 9);
 		scancode = keypad[digit];
+		LOG_TRACE(TRACE_KEYMAP, " + '%d' (0x%02x)",
+			  digit, scancode);
+
 		/* press and release each keycode
 		 * without checking whether they
 		 * are already pressed
@@ -911,10 +924,13 @@ void Keymap_KeyDown(const SDL_Keysym *sdlkey)
 	STScanCode = stkey->scancode;
 	LOG_TRACE(TRACE_KEYMAP, "key map: sym=0x%x to ST-scan=0x%02x\n", symkey, STScanCode);
 
-	InsertModifiers(stkey->mods, true);
-	if (InsertAltXXXDigits(stkey))
-		return;
-
+	if (InsertModifiers(stkey->mods, true))
+	{
+		bool done = InsertAltXXXDigits(stkey);
+		LOG_TRACE(TRACE_KEYMAP, "\n");
+		if (done)
+			return;
+	}
 	if (!Keyboard.KeyStates[STScanCode])
 	{
 		/* Set down */
@@ -966,7 +982,10 @@ void Keymap_KeyUp(const SDL_Keysym *sdlkey)
 		IKBD_PressSTKey(STScanCode, false);
 		Keyboard.KeyStates[STScanCode]--;
 	}
-	InsertModifiers(stkey->mods, false);
+	if (InsertModifiers(stkey->mods, false))
+	{
+		LOG_TRACE(TRACE_KEYMAP, "\n");
+	}
 }
 
 /*-----------------------------------------------------------------------*/
-- 
2.30.2


--------------7873925CF10FCA11A2667F70
Content-Type: text/x-patch; charset=UTF-8;
 name="0005-Add-ALT-XXX-sequence-insert-support-for-keymaps.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0005-Add-ALT-XXX-sequence-insert-support-for-keymaps.patch"



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/