aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2025-03-03 23:28:36 +0100
committerdec05eba <dec05eba@protonmail.com>2025-03-03 23:28:36 +0100
commit06166b3c9e5ad140d286d4bf6e491556ce4c8bea (patch)
treeb9391675c25ff75d77f4f3b80689130b9ecf2b3a /src
parentfc30899a2dcd3af167a4785cec5bb6c17374e30c (diff)
Support more keys: insert, printscreen, pause, numpad numbers and numpad enterHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/window/key.c290
-rw-r--r--src/window/window.c88
2 files changed, 199 insertions, 179 deletions
diff --git a/src/window/key.c b/src/window/key.c
index 8cdce24..27b7d4b 100644
--- a/src/window/key.c
+++ b/src/window/key.c
@@ -3,111 +3,113 @@
const char* mgl_key_to_string(mgl_key key) {
switch(key) {
- case MGL_KEY_UNKNOWN: return 0;
- case MGL_KEY_A: return "A";
- case MGL_KEY_B: return "B";
- case MGL_KEY_C: return "C";
- case MGL_KEY_D: return "D";
- case MGL_KEY_E: return "E";
- case MGL_KEY_F: return "F";
- case MGL_KEY_G: return "G";
- case MGL_KEY_H: return "H";
- case MGL_KEY_I: return "I";
- case MGL_KEY_J: return "J";
- case MGL_KEY_K: return "K";
- case MGL_KEY_L: return "L";
- case MGL_KEY_M: return "M";
- case MGL_KEY_N: return "N";
- case MGL_KEY_O: return "O";
- case MGL_KEY_P: return "P";
- case MGL_KEY_Q: return "Q";
- case MGL_KEY_R: return "R";
- case MGL_KEY_S: return "S";
- case MGL_KEY_T: return "T";
- case MGL_KEY_U: return "U";
- case MGL_KEY_V: return "V";
- case MGL_KEY_W: return "W";
- case MGL_KEY_X: return "X";
- case MGL_KEY_Y: return "Y";
- case MGL_KEY_Z: return "Z";
- case MGL_KEY_NUM0: return "0";
- case MGL_KEY_NUM1: return "1";
- case MGL_KEY_NUM2: return "2";
- case MGL_KEY_NUM3: return "3";
- case MGL_KEY_NUM4: return "4";
- case MGL_KEY_NUM5: return "5";
- case MGL_KEY_NUM6: return "6";
- case MGL_KEY_NUM7: return "7";
- case MGL_KEY_NUM8: return "8";
- case MGL_KEY_NUM9: return "9";
- case MGL_KEY_ESCAPE: return "Escape";
- case MGL_KEY_LCONTROL: return "Left Ctrl";
- case MGL_KEY_LSHIFT: return "Left Shift";
- case MGL_KEY_LALT: return "Left Alt";
- case MGL_KEY_LSYSTEM: return "Left System";
- case MGL_KEY_RCONTROL: return "Right Ctrl";
- case MGL_KEY_RSHIFT: return "Right Shift";
- case MGL_KEY_RALT: return "Right Alt";
- case MGL_KEY_RSYSTEM: return "Right System";
- case MGL_KEY_MENU: return "Menu";
- case MGL_KEY_LBRACKET: return "[";
- case MGL_KEY_RBRACKET: return "]";
- case MGL_KEY_SEMICOLON: return ";";
- case MGL_KEY_COMMA: return ",";
- case MGL_KEY_PERIOD: return ".";
- case MGL_KEY_QUOTE: return "'";
- case MGL_KEY_SLASH: return "/";
- case MGL_KEY_BACKSLASH: return "\\";
- case MGL_KEY_TILDE: return "~";
- case MGL_KEY_EQUAL: return "=";
- case MGL_KEY_HYPHEN: return "-";
- case MGL_KEY_SPACE: return "Space";
- case MGL_KEY_ENTER: return "Enter";
- case MGL_KEY_BACKSPACE: return "Backspace";
- case MGL_KEY_TAB: return "Tab";
- case MGL_KEY_PAGEUP: return "PageUp";
- case MGL_KEY_PAGEDOWN: return "PageDown";
- case MGL_KEY_END: return "End";
- case MGL_KEY_HOME: return "Home";
- case MGL_KEY_INSERT: return "Insert";
- case MGL_KEY_DELETE: return "Delete";
- case MGL_KEY_ADD: return "Add";
- case MGL_KEY_SUBTRACT: return "Subtract";
- case MGL_KEY_MULTIPLY: return "Multiply";
- case MGL_KEY_DIVIDE: return "Divide";
- case MGL_KEY_LEFT: return "Left";
- case MGL_KEY_RIGHT: return "Right";
- case MGL_KEY_UP: return "Up";
- case MGL_KEY_DOWN: return "Down";
- case MGL_KEY_NUMPAD0: return "Numpad0";
- case MGL_KEY_NUMPAD1: return "Numpad1";
- case MGL_KEY_NUMPAD2: return "Numpad2";
- case MGL_KEY_NUMPAD3: return "Numpad3";
- case MGL_KEY_NUMPAD4: return "Numpad4";
- case MGL_KEY_NUMPAD5: return "Numpad5";
- case MGL_KEY_NUMPAD6: return "Numpad6";
- case MGL_KEY_NUMPAD7: return "Numpad7";
- case MGL_KEY_NUMPAD8: return "Numpad8";
- case MGL_KEY_NUMPAD9: return "Numpad9";
- case MGL_KEY_F1: return "F1";
- case MGL_KEY_F2: return "F2";
- case MGL_KEY_F3: return "F3";
- case MGL_KEY_F4: return "F4";
- case MGL_KEY_F5: return "F5";
- case MGL_KEY_F6: return "F6";
- case MGL_KEY_F7: return "F7";
- case MGL_KEY_F8: return "F8";
- case MGL_KEY_F9: return "F9";
- case MGL_KEY_F10: return "F10";
- case MGL_KEY_F11: return "F11";
- case MGL_KEY_F12: return "F12";
- case MGL_KEY_F13: return "F13";
- case MGL_KEY_F14: return "F14";
- case MGL_KEY_F15: return "F15";
- case MGL_KEY_PAUSE: return "Pause";
- case __MGL_NUM_KEYS__: return 0;
+ case MGL_KEY_UNKNOWN: return "";
+ case MGL_KEY_A: return "A";
+ case MGL_KEY_B: return "B";
+ case MGL_KEY_C: return "C";
+ case MGL_KEY_D: return "D";
+ case MGL_KEY_E: return "E";
+ case MGL_KEY_F: return "F";
+ case MGL_KEY_G: return "G";
+ case MGL_KEY_H: return "H";
+ case MGL_KEY_I: return "I";
+ case MGL_KEY_J: return "J";
+ case MGL_KEY_K: return "K";
+ case MGL_KEY_L: return "L";
+ case MGL_KEY_M: return "M";
+ case MGL_KEY_N: return "N";
+ case MGL_KEY_O: return "O";
+ case MGL_KEY_P: return "P";
+ case MGL_KEY_Q: return "Q";
+ case MGL_KEY_R: return "R";
+ case MGL_KEY_S: return "S";
+ case MGL_KEY_T: return "T";
+ case MGL_KEY_U: return "U";
+ case MGL_KEY_V: return "V";
+ case MGL_KEY_W: return "W";
+ case MGL_KEY_X: return "X";
+ case MGL_KEY_Y: return "Y";
+ case MGL_KEY_Z: return "Z";
+ case MGL_KEY_NUM0: return "0";
+ case MGL_KEY_NUM1: return "1";
+ case MGL_KEY_NUM2: return "2";
+ case MGL_KEY_NUM3: return "3";
+ case MGL_KEY_NUM4: return "4";
+ case MGL_KEY_NUM5: return "5";
+ case MGL_KEY_NUM6: return "6";
+ case MGL_KEY_NUM7: return "7";
+ case MGL_KEY_NUM8: return "8";
+ case MGL_KEY_NUM9: return "9";
+ case MGL_KEY_ESCAPE: return "Escape";
+ case MGL_KEY_LCONTROL: return "Left Ctrl";
+ case MGL_KEY_LSHIFT: return "Left Shift";
+ case MGL_KEY_LALT: return "Left Alt";
+ case MGL_KEY_LSYSTEM: return "Left System";
+ case MGL_KEY_RCONTROL: return "Right Ctrl";
+ case MGL_KEY_RSHIFT: return "Right Shift";
+ case MGL_KEY_RALT: return "Right Alt";
+ case MGL_KEY_RSYSTEM: return "Right System";
+ case MGL_KEY_MENU: return "Menu";
+ case MGL_KEY_LBRACKET: return "[";
+ case MGL_KEY_RBRACKET: return "]";
+ case MGL_KEY_SEMICOLON: return ";";
+ case MGL_KEY_COMMA: return ",";
+ case MGL_KEY_PERIOD: return ".";
+ case MGL_KEY_QUOTE: return "'";
+ case MGL_KEY_SLASH: return "/";
+ case MGL_KEY_BACKSLASH: return "\\";
+ case MGL_KEY_TILDE: return "~";
+ case MGL_KEY_EQUAL: return "=";
+ case MGL_KEY_HYPHEN: return "-";
+ case MGL_KEY_SPACE: return "Space";
+ case MGL_KEY_ENTER: return "Enter";
+ case MGL_KEY_BACKSPACE: return "Backspace";
+ case MGL_KEY_TAB: return "Tab";
+ case MGL_KEY_PAGEUP: return "PageUp";
+ case MGL_KEY_PAGEDOWN: return "PageDown";
+ case MGL_KEY_END: return "End";
+ case MGL_KEY_HOME: return "Home";
+ case MGL_KEY_INSERT: return "Insert";
+ case MGL_KEY_DELETE: return "Delete";
+ case MGL_KEY_ADD: return "Add";
+ case MGL_KEY_SUBTRACT: return "Subtract";
+ case MGL_KEY_MULTIPLY: return "Multiply";
+ case MGL_KEY_DIVIDE: return "Divide";
+ case MGL_KEY_LEFT: return "Left";
+ case MGL_KEY_RIGHT: return "Right";
+ case MGL_KEY_UP: return "Up";
+ case MGL_KEY_DOWN: return "Down";
+ case MGL_KEY_NUMPAD0: return "Numpad0";
+ case MGL_KEY_NUMPAD1: return "Numpad1";
+ case MGL_KEY_NUMPAD2: return "Numpad2";
+ case MGL_KEY_NUMPAD3: return "Numpad3";
+ case MGL_KEY_NUMPAD4: return "Numpad4";
+ case MGL_KEY_NUMPAD5: return "Numpad5";
+ case MGL_KEY_NUMPAD6: return "Numpad6";
+ case MGL_KEY_NUMPAD7: return "Numpad7";
+ case MGL_KEY_NUMPAD8: return "Numpad8";
+ case MGL_KEY_NUMPAD9: return "Numpad9";
+ case MGL_KEY_NUMPAD_ENTER: return "Numpad enter";
+ case MGL_KEY_F1: return "F1";
+ case MGL_KEY_F2: return "F2";
+ case MGL_KEY_F3: return "F3";
+ case MGL_KEY_F4: return "F4";
+ case MGL_KEY_F5: return "F5";
+ case MGL_KEY_F6: return "F6";
+ case MGL_KEY_F7: return "F7";
+ case MGL_KEY_F8: return "F8";
+ case MGL_KEY_F9: return "F9";
+ case MGL_KEY_F10: return "F10";
+ case MGL_KEY_F11: return "F11";
+ case MGL_KEY_F12: return "F12";
+ case MGL_KEY_F13: return "F13";
+ case MGL_KEY_F14: return "F14";
+ case MGL_KEY_F15: return "F15";
+ case MGL_KEY_PAUSE: return "Pause";
+ case MGL_KEY_PRINTSCREEN: return "Pause";
+ case __MGL_NUM_KEYS__: return "";
}
- return 0;
+ return "";
}
bool mgl_key_is_modifier(mgl_key key) {
@@ -124,44 +126,48 @@ uint64_t mgl_key_to_x11_keysym(mgl_key key) {
/* TODO: Fill in the rest */
switch(key) {
- case MGL_KEY_SPACE: return XK_space;
- case MGL_KEY_BACKSPACE: return XK_BackSpace;
- case MGL_KEY_TAB: return XK_Tab;
- case MGL_KEY_ENTER: return XK_Return;
- case MGL_KEY_ESCAPE: return XK_Escape;
- case MGL_KEY_LCONTROL: return XK_Control_L;
- case MGL_KEY_LSHIFT: return XK_Shift_L;
- case MGL_KEY_LALT: return XK_Alt_L;
- case MGL_KEY_LSYSTEM: return XK_Super_L;
- case MGL_KEY_RCONTROL: return XK_Control_R;
- case MGL_KEY_RSHIFT: return XK_Shift_R;
- case MGL_KEY_RALT: return XK_Alt_R;
- case MGL_KEY_RSYSTEM: return XK_Super_R;
- case MGL_KEY_DELETE: return XK_Delete;
- case MGL_KEY_HOME: return XK_Home;
- case MGL_KEY_LEFT: return XK_Left;
- case MGL_KEY_UP: return XK_Up;
- case MGL_KEY_RIGHT: return XK_Right;
- case MGL_KEY_DOWN: return XK_Down;
- case MGL_KEY_PAGEUP: return XK_Page_Up;
- case MGL_KEY_PAGEDOWN: return XK_Page_Down;
- case MGL_KEY_END: return XK_End;
- case MGL_KEY_F1: return XK_F1;
- case MGL_KEY_F2: return XK_F2;
- case MGL_KEY_F3: return XK_F3;
- case MGL_KEY_F4: return XK_F4;
- case MGL_KEY_F5: return XK_F5;
- case MGL_KEY_F6: return XK_F6;
- case MGL_KEY_F7: return XK_F7;
- case MGL_KEY_F8: return XK_F8;
- case MGL_KEY_F9: return XK_F9;
- case MGL_KEY_F10: return XK_F10;
- case MGL_KEY_F11: return XK_F11;
- case MGL_KEY_F12: return XK_F12;
- case MGL_KEY_F13: return XK_F13;
- case MGL_KEY_F14: return XK_F14;
- case MGL_KEY_F15: return XK_F15;
- default: return XK_VoidSymbol;
+ case MGL_KEY_SPACE: return XK_space;
+ case MGL_KEY_BACKSPACE: return XK_BackSpace;
+ case MGL_KEY_TAB: return XK_Tab;
+ case MGL_KEY_ENTER: return XK_Return;
+ case MGL_KEY_ESCAPE: return XK_Escape;
+ case MGL_KEY_LCONTROL: return XK_Control_L;
+ case MGL_KEY_LSHIFT: return XK_Shift_L;
+ case MGL_KEY_LALT: return XK_Alt_L;
+ case MGL_KEY_LSYSTEM: return XK_Super_L;
+ case MGL_KEY_RCONTROL: return XK_Control_R;
+ case MGL_KEY_RSHIFT: return XK_Shift_R;
+ case MGL_KEY_RALT: return XK_Alt_R;
+ case MGL_KEY_RSYSTEM: return XK_Super_R;
+ case MGL_KEY_DELETE: return XK_Delete;
+ case MGL_KEY_HOME: return XK_Home;
+ case MGL_KEY_LEFT: return XK_Left;
+ case MGL_KEY_UP: return XK_Up;
+ case MGL_KEY_RIGHT: return XK_Right;
+ case MGL_KEY_DOWN: return XK_Down;
+ case MGL_KEY_PAGEUP: return XK_Page_Up;
+ case MGL_KEY_PAGEDOWN: return XK_Page_Down;
+ case MGL_KEY_END: return XK_End;
+ case MGL_KEY_F1: return XK_F1;
+ case MGL_KEY_F2: return XK_F2;
+ case MGL_KEY_F3: return XK_F3;
+ case MGL_KEY_F4: return XK_F4;
+ case MGL_KEY_F5: return XK_F5;
+ case MGL_KEY_F6: return XK_F6;
+ case MGL_KEY_F7: return XK_F7;
+ case MGL_KEY_F8: return XK_F8;
+ case MGL_KEY_F9: return XK_F9;
+ case MGL_KEY_F10: return XK_F10;
+ case MGL_KEY_F11: return XK_F11;
+ case MGL_KEY_F12: return XK_F12;
+ case MGL_KEY_F13: return XK_F13;
+ case MGL_KEY_F14: return XK_F14;
+ case MGL_KEY_F15: return XK_F15;
+ case MGL_KEY_INSERT: return XK_Insert;
+ case MGL_KEY_PAUSE: return XK_Pause;
+ case MGL_KEY_PRINTSCREEN: return XK_Print;
+ case MGL_KEY_NUMPAD_ENTER: return XK_KP_Enter;
+ default: return XK_VoidSymbol;
}
return XK_VoidSymbol;
}
diff --git a/src/window/window.c b/src/window/window.c
index 2c7077d..cde69e1 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -1099,43 +1099,57 @@ static mgl_key x11_keysym_to_mgl_key(KeySym key_sym) {
/* TODO: Fill in the rest */
switch(key_sym) {
- case XK_space: return MGL_KEY_SPACE;
- case XK_BackSpace: return MGL_KEY_BACKSPACE;
- case XK_Tab: return MGL_KEY_TAB;
- case XK_Return: return MGL_KEY_ENTER;
- case XK_Escape: return MGL_KEY_ESCAPE;
- case XK_Control_L: return MGL_KEY_LCONTROL;
- case XK_Shift_L: return MGL_KEY_LSHIFT;
- case XK_Alt_L: return MGL_KEY_LALT;
- case XK_Super_L: return MGL_KEY_LSYSTEM;
- case XK_Control_R: return MGL_KEY_RCONTROL;
- case XK_Shift_R: return MGL_KEY_RSHIFT;
- case XK_Alt_R: return MGL_KEY_RALT;
- case XK_Super_R: return MGL_KEY_RSYSTEM;
- case XK_Delete: return MGL_KEY_DELETE;
- case XK_Home: return MGL_KEY_HOME;
- case XK_Left: return MGL_KEY_LEFT;
- case XK_Up: return MGL_KEY_UP;
- case XK_Right: return MGL_KEY_RIGHT;
- case XK_Down: return MGL_KEY_DOWN;
- case XK_Page_Up: return MGL_KEY_PAGEUP;
- case XK_Page_Down: return MGL_KEY_PAGEDOWN;
- case XK_End: return MGL_KEY_END;
- case XK_F1: return MGL_KEY_F1;
- case XK_F2: return MGL_KEY_F2;
- case XK_F3: return MGL_KEY_F3;
- case XK_F4: return MGL_KEY_F4;
- case XK_F5: return MGL_KEY_F5;
- case XK_F6: return MGL_KEY_F6;
- case XK_F7: return MGL_KEY_F7;
- case XK_F8: return MGL_KEY_F8;
- case XK_F9: return MGL_KEY_F9;
- case XK_F10: return MGL_KEY_F10;
- case XK_F11: return MGL_KEY_F11;
- case XK_F12: return MGL_KEY_F12;
- case XK_F13: return MGL_KEY_F13;
- case XK_F14: return MGL_KEY_F14;
- case XK_F15: return MGL_KEY_F15;
+ case XK_space: return MGL_KEY_SPACE;
+ case XK_BackSpace: return MGL_KEY_BACKSPACE;
+ case XK_Tab: return MGL_KEY_TAB;
+ case XK_Return: return MGL_KEY_ENTER;
+ case XK_Escape: return MGL_KEY_ESCAPE;
+ case XK_Control_L: return MGL_KEY_LCONTROL;
+ case XK_Shift_L: return MGL_KEY_LSHIFT;
+ case XK_Alt_L: return MGL_KEY_LALT;
+ case XK_Super_L: return MGL_KEY_LSYSTEM;
+ case XK_Control_R: return MGL_KEY_RCONTROL;
+ case XK_Shift_R: return MGL_KEY_RSHIFT;
+ case XK_Alt_R: return MGL_KEY_RALT;
+ case XK_Super_R: return MGL_KEY_RSYSTEM;
+ case XK_Delete: return MGL_KEY_DELETE;
+ case XK_Home: return MGL_KEY_HOME;
+ case XK_Left: return MGL_KEY_LEFT;
+ case XK_Up: return MGL_KEY_UP;
+ case XK_Right: return MGL_KEY_RIGHT;
+ case XK_Down: return MGL_KEY_DOWN;
+ case XK_Page_Up: return MGL_KEY_PAGEUP;
+ case XK_Page_Down: return MGL_KEY_PAGEDOWN;
+ case XK_End: return MGL_KEY_END;
+ case XK_F1: return MGL_KEY_F1;
+ case XK_F2: return MGL_KEY_F2;
+ case XK_F3: return MGL_KEY_F3;
+ case XK_F4: return MGL_KEY_F4;
+ case XK_F5: return MGL_KEY_F5;
+ case XK_F6: return MGL_KEY_F6;
+ case XK_F7: return MGL_KEY_F7;
+ case XK_F8: return MGL_KEY_F8;
+ case XK_F9: return MGL_KEY_F9;
+ case XK_F10: return MGL_KEY_F10;
+ case XK_F11: return MGL_KEY_F11;
+ case XK_F12: return MGL_KEY_F12;
+ case XK_F13: return MGL_KEY_F13;
+ case XK_F14: return MGL_KEY_F14;
+ case XK_F15: return MGL_KEY_F15;
+ case XK_Insert: return MGL_KEY_INSERT;
+ case XK_Pause: return MGL_KEY_PAUSE;
+ case XK_Print: return MGL_KEY_PRINTSCREEN;
+ case XK_KP_Insert: return MGL_KEY_NUMPAD0;
+ case XK_KP_End: return MGL_KEY_NUMPAD1;
+ case XK_KP_Down: return MGL_KEY_NUMPAD2;
+ case XK_KP_Page_Down: return MGL_KEY_NUMPAD3;
+ case XK_KP_Left: return MGL_KEY_NUMPAD4;
+ case XK_KP_Begin: return MGL_KEY_NUMPAD5;
+ case XK_KP_Right: return MGL_KEY_NUMPAD6;
+ case XK_KP_Home: return MGL_KEY_NUMPAD7;
+ case XK_KP_Up: return MGL_KEY_NUMPAD8;
+ case XK_KP_Page_Up: return MGL_KEY_NUMPAD9;
+ case XK_KP_Enter: return MGL_KEY_NUMPAD_ENTER;
}
return MGL_KEY_UNKNOWN;
}