[retro-gtk] keyboard-key: Add key_to_val_converter()
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk] keyboard-key: Add key_to_val_converter()
- Date: Sat, 9 Feb 2019 13:17:18 +0000 (UTC)
commit 2f46c815827462011d7dd2eb4aee9587c55ed316
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Wed Nov 14 19:12:29 2018 +0500
keyboard-key: Add key_to_val_converter()
Add a function that allows to convert RetroKeyboardKey to GDK keyval,
effectively an inverse of retro_keyboard_key_converter()
retro-gtk/retro-keyboard-key.c | 137 +++++++++++++++++++++++++++++++++++++++++
retro-gtk/retro-keyboard-key.h | 1 +
2 files changed, 138 insertions(+)
---
diff --git a/retro-gtk/retro-keyboard-key.c b/retro-gtk/retro-keyboard-key.c
index e43056b..d78c936 100644
--- a/retro-gtk/retro-keyboard-key.c
+++ b/retro-gtk/retro-keyboard-key.c
@@ -166,3 +166,140 @@ retro_keyboard_key_converter (guint keyval)
return RETRO_KEYBOARD_KEY_UNKNOWN;
}
}
+
+guint
+retro_keyboard_key_to_val_converter (RetroKeyboardKey key)
+{
+ /*
+ * US-ASCII codes
+ *
+ * Both GDK_KEY_* and RETRO_KEYBOARD_KEY_* start with the US-ASCII codes,
+ * implementing common letters, digits and symbols.
+ */
+ if (key >= 0x20 && key < 0x80)
+ return key;
+
+ /*
+ * Function keys
+ *
+ * Both GDK_KEY_F* and RETRO_KEYBOARD_KEY_F* implement function keys 1—15 in a
+ * consecutive manner. GDK_KEY_F* actually implements more function keys but
+ * RETRO_KEYBOARD_KEY_F* doesn't.
+ */
+ if (key >= RETRO_KEYBOARD_KEY_F1 && key <= RETRO_KEYBOARD_KEY_F15)
+ return GDK_KEY_F1 + (key - RETRO_KEYBOARD_KEY_F1);
+
+ /*
+ * Keypad digits
+ *
+ * Both GDK_KEY_KP_* and RETRO_KEYBOARD_KEY_KP* implement keypad digits 0–9 in
+ * a consecutive manner.
+ */
+ if (key >= RETRO_KEYBOARD_KEY_KP0 && key <= RETRO_KEYBOARD_KEY_KP9)
+ return GDK_KEY_KP_0 + (key - RETRO_KEYBOARD_KEY_KP0);
+
+ /*
+ * Various keys
+ *
+ * FIXME: The following keys are unimplemented because I couldn't find the
+ * right GDK_KEY_* equivalent:
+ * - RETRO_KEYBOARD_KEY_MODE
+ * - RETRO_KEYBOARD_KEY_COMPOSE
+ * - RETRO_KEYBOARD_KEY_POWER
+ */
+ switch (key) {
+ case RETRO_KEYBOARD_KEY_BACKSPACE:
+ return GDK_KEY_BackSpace;
+ case RETRO_KEYBOARD_KEY_TAB:
+ return GDK_KEY_Tab;
+ case RETRO_KEYBOARD_KEY_CLEAR:
+ return GDK_KEY_Clear;
+ case RETRO_KEYBOARD_KEY_RETURN:
+ return GDK_KEY_Return;
+ case RETRO_KEYBOARD_KEY_PAUSE:
+ return GDK_KEY_Pause;
+ case RETRO_KEYBOARD_KEY_ESCAPE:
+ return GDK_KEY_Escape;
+ case RETRO_KEYBOARD_KEY_DELETE:
+ return GDK_KEY_Delete;
+
+ case RETRO_KEYBOARD_KEY_UP:
+ return GDK_KEY_Up;
+ case RETRO_KEYBOARD_KEY_DOWN:
+ return GDK_KEY_Down;
+ case RETRO_KEYBOARD_KEY_LEFT:
+ return GDK_KEY_Left;
+ case RETRO_KEYBOARD_KEY_RIGHT:
+ return GDK_KEY_Right;
+ case RETRO_KEYBOARD_KEY_INSERT:
+ return GDK_KEY_Insert;
+ case RETRO_KEYBOARD_KEY_HOME:
+ return GDK_KEY_Home;
+ case RETRO_KEYBOARD_KEY_END:
+ return GDK_KEY_End;
+ case RETRO_KEYBOARD_KEY_PAGEUP:
+ return GDK_KEY_Page_Up;
+ case RETRO_KEYBOARD_KEY_PAGEDOWN:
+ return GDK_KEY_Page_Down;
+
+ case RETRO_KEYBOARD_KEY_KP_PERIOD:
+ return GDK_KEY_KP_Decimal;
+ case RETRO_KEYBOARD_KEY_KP_DIVIDE:
+ return GDK_KEY_KP_Divide;
+ case RETRO_KEYBOARD_KEY_KP_MULTIPLY:
+ return GDK_KEY_KP_Multiply;
+ case RETRO_KEYBOARD_KEY_KP_MINUS:
+ return GDK_KEY_KP_Subtract;
+ case RETRO_KEYBOARD_KEY_KP_PLUS:
+ return GDK_KEY_KP_Add;
+ case RETRO_KEYBOARD_KEY_KP_ENTER:
+ return GDK_KEY_KP_Enter;
+ case RETRO_KEYBOARD_KEY_KP_EQUALS:
+ return GDK_KEY_KP_Equal;
+
+ case RETRO_KEYBOARD_KEY_NUMLOCK:
+ return GDK_KEY_Num_Lock;
+ case RETRO_KEYBOARD_KEY_CAPSLOCK:
+ return GDK_KEY_Caps_Lock;
+ case RETRO_KEYBOARD_KEY_SCROLLOCK:
+ return GDK_KEY_Scroll_Lock;
+ case RETRO_KEYBOARD_KEY_RSHIFT:
+ return GDK_KEY_Shift_R;
+ case RETRO_KEYBOARD_KEY_LSHIFT:
+ return GDK_KEY_Shift_L;
+ case RETRO_KEYBOARD_KEY_RCTRL:
+ return GDK_KEY_Control_R;
+ case RETRO_KEYBOARD_KEY_LCTRL:
+ return GDK_KEY_Control_L;
+ case RETRO_KEYBOARD_KEY_RALT:
+ return GDK_KEY_Alt_R;
+ case RETRO_KEYBOARD_KEY_LALT:
+ return GDK_KEY_Alt_L;
+ case RETRO_KEYBOARD_KEY_RMETA:
+ return GDK_KEY_Meta_R;
+ case RETRO_KEYBOARD_KEY_LMETA:
+ return GDK_KEY_Meta_L;
+ case RETRO_KEYBOARD_KEY_RSUPER:
+ return GDK_KEY_Super_R;
+ case RETRO_KEYBOARD_KEY_LSUPER:
+ return GDK_KEY_Super_L;
+
+ case RETRO_KEYBOARD_KEY_HELP:
+ return GDK_KEY_Help;
+ case RETRO_KEYBOARD_KEY_PRINT:
+ return GDK_KEY_Print;
+ case RETRO_KEYBOARD_KEY_SYSREQ:
+ return GDK_KEY_Sys_Req;
+ case RETRO_KEYBOARD_KEY_BREAK:
+ return GDK_KEY_Break;
+ case RETRO_KEYBOARD_KEY_MENU:
+ return GDK_KEY_Menu;
+ case RETRO_KEYBOARD_KEY_EURO:
+ return GDK_KEY_EuroSign;
+ case RETRO_KEYBOARD_KEY_UNDO:
+ return GDK_KEY_Undo;
+
+ default:
+ return GDK_KEY_VoidSymbol;
+ }
+}
diff --git a/retro-gtk/retro-keyboard-key.h b/retro-gtk/retro-keyboard-key.h
index f9ce061..115a1a2 100644
--- a/retro-gtk/retro-keyboard-key.h
+++ b/retro-gtk/retro-keyboard-key.h
@@ -170,6 +170,7 @@ typedef enum {
RetroKeyboardModifierKey retro_keyboard_modifier_key_converter (guint keyval,
GdkModifierType modifiers);
RetroKeyboardKey retro_keyboard_key_converter (guint keyval);
+guint retro_keyboard_key_to_val_converter (RetroKeyboardKey key);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]