[PATCH 6/8] Add ALT-XXX sequence insert support for keymaps |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- Subject: [PATCH 6/8] Add ALT-XXX sequence insert support for keymaps
- From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
- Date: Wed, 27 Oct 2021 02:13:20 +0300
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 71a6d0dd..9833bb39 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;
@@ -619,6 +622,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;
@@ -837,6 +845,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
@@ -872,6 +921,9 @@ void Keymap_KeyDown(const SDL_Keysym *sdlkey)
assert(Keyboard.KeyStates[scancode] == 0);
InsertModifiers(stkey->mods, true);
+ if (InsertAltXXXDigits(stkey))
+ return;
+
if (!Keyboard.KeyStates[STScanCode])
{
/* Set down */
--
2.30.2
--------------F1FA3BEB0519731AA569A677
Content-Type: text/x-patch; charset=UTF-8;
name="0005-Support-for-specifying-ST-key-modifiers-in-the-mappi.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename*0="0005-Support-for-specifying-ST-key-modifiers-in-the-mappi.pa";
filename*1="tch"