[PATCH 5/9] Add ALT-XXX sequence insert support for keymaps

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


Note: this can insert up to 7[1] events to IKBD buffer before
emulation is continued.  In some situations (e.g. mouse movements done
at the same time) this might overflow the buffer so that events are
lost.

[1] Alt key press + up to 3 numpad digit key presses & releases.
---
 src/keymap.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/src/keymap.c b/src/keymap.c
index fc5eb964..6321d10d 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -61,8 +61,11 @@ static const struct
 	{"LSHIFT",  ST_LSHIFT,    0x02},
 	{"RSHIFT",  ST_RSHIFT,    0x04},
 	{"ALT",     ST_ALTERNATE, 0x08},
+	{"ALT_XXX", ST_ALTERNATE, 0x10},
 };
 
+#define ALT_XXX_BIT 0x10
+
 typedef struct
 {
 	uint8_t scancode;
@@ -609,6 +612,11 @@ static bool GuestSpecToKeymap(const char *spec, KeyMapping* mapping)
 			return false;
 		}
 	}
+	if ((mods & ALT_XXX_BIT) && (mods & ~ALT_XXX_BIT))
+	{
+		Log_Printf(LOG_ERROR, "'ALT_XXX' ST modifier specified with other modifier(s)\n");
+		return false;
+	}
 	mapping->st.scancode = scancode;
 	mapping->st.mods = mods;
 
@@ -829,6 +837,47 @@ 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.
+ */
+static bool InsertAltXXXDigits(ST_Key *stkey)
+{
+	/* map 0, 1-3, 5-6, 7-9 to corresponding numpad scancodes */
+	static const uint8_t keypad[] = {
+		112,
+		109, 110, 111,
+		106, 107, 108,
+		103, 104, 105
+	};
+	char buf[8], *xxx;
+
+	if (!(stkey->mods & ALT_XXX_BIT))
+		return false;
+
+	sprintf(buf, "%d", stkey->scancode);
+	for (xxx = buf; *xxx; xxx++)
+	{
+		uint8_t scancode;
+		int digit;
+
+		digit = *xxx - '0';
+		assert(digit >= 0 && digit <= 9);
+		scancode = keypad[digit];
+		/* press and release each keycode
+		 * without checking whether they
+		 * are already pressed
+		 */
+		IKBD_PressSTKey(scancode, true);
+		IKBD_PressSTKey(scancode, false);
+	}
+	return true;
+}
+
+
 /*-----------------------------------------------------------------------*/
 /**
  * User pressed a key down
@@ -863,6 +912,9 @@ void Keymap_KeyDown(const SDL_Keysym *sdlkey)
 	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 (!Keyboard.KeyStates[STScanCode])
 	{
 		/* Set down */
-- 
2.30.2


--------------7873925CF10FCA11A2667F70
Content-Type: text/x-patch; charset=UTF-8;
 name="0004-Support-for-specifying-ST-key-modifiers-in-the-mappi.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0004-Support-for-specifying-ST-key-modifiers-in-the-mappi.pa";
 filename*1="tch"



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