From 227b96247baeec7a3f44cf82c4560f2aca282c16 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 21 Jan 2025 22:37:23 +0100 Subject: Expose mgl_key_to_x11_keysym --- src/window/key.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/window/window.c | 53 ----------------------------------------------------- 2 files changed, 53 insertions(+), 53 deletions(-) (limited to 'src/window') diff --git a/src/window/key.c b/src/window/key.c index 0ac0be6..ecddf0e 100644 --- a/src/window/key.c +++ b/src/window/key.c @@ -1,4 +1,5 @@ #include "../../include/mgl/window/key.h" +#include const char* mgl_key_to_string(mgl_key key) { switch(key) { @@ -112,3 +113,55 @@ const char* mgl_key_to_string(mgl_key key) { bool mgl_key_is_modifier(mgl_key key) { return key >= MGL_KEY_LCONTROL && key <= MGL_KEY_RSYSTEM; } + +uint64_t mgl_key_to_x11_keysym(mgl_key key) { + if(key >= MGL_KEY_A && key <= MGL_KEY_Z) + return XK_A + (key - MGL_KEY_A); + if(key >= MGL_KEY_NUM0 && key <= MGL_KEY_NUM9) + return XK_0 + (key - MGL_KEY_NUM0); + if(key >= MGL_KEY_NUMPAD0 && key <= MGL_KEY_NUMPAD9) + return XK_KP_0 + (key - MGL_KEY_NUMPAD0); + + /* 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; + } + return XK_VoidSymbol; +} diff --git a/src/window/window.c b/src/window/window.c index a70e0d9..9280e32 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -1140,59 +1140,6 @@ static mgl_key x11_keysym_to_mgl_key(KeySym key_sym) { return MGL_KEY_UNKNOWN; } -/* Returns XK_VoidSymbol on no match */ -static KeySym mgl_key_to_x11_keysym(mgl_key key) { - if(key >= MGL_KEY_A && key <= MGL_KEY_Z) - return XK_A + (key - MGL_KEY_A); - if(key >= MGL_KEY_NUM0 && key <= MGL_KEY_NUM9) - return XK_0 + (key - MGL_KEY_NUM0); - if(key >= MGL_KEY_NUMPAD0 && key <= MGL_KEY_NUMPAD9) - return XK_KP_0 + (key - MGL_KEY_NUMPAD0); - - /* 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; - } - return XK_VoidSymbol; -} - static mgl_mouse_button x11_button_to_mgl_button(unsigned int button) { switch(button) { case Button1: return MGL_BUTTON_LEFT; -- cgit v1.2.3