1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-27 04:28:52 -05:00

Make Wayland and Mir backends use key LUTs

This commit is contained in:
Camilla Berglund 2015-11-12 15:06:46 +01:00
parent 994d8ae54d
commit 580c7da559
5 changed files with 265 additions and 241 deletions

View File

@ -30,6 +30,131 @@
#include <string.h> #include <string.h>
// Create key code translation tables
//
static void createKeyTables(void)
{
memset(_glfw.mir.publicKeys, -1, sizeof(_glfw.mir.publicKeys));
_glfw.mir.publicKeys[KEY_GRAVE] = GLFW_KEY_GRAVE_ACCENT;
_glfw.mir.publicKeys[KEY_1] = GLFW_KEY_1;
_glfw.mir.publicKeys[KEY_2] = GLFW_KEY_2;
_glfw.mir.publicKeys[KEY_3] = GLFW_KEY_3;
_glfw.mir.publicKeys[KEY_4] = GLFW_KEY_4;
_glfw.mir.publicKeys[KEY_5] = GLFW_KEY_5;
_glfw.mir.publicKeys[KEY_6] = GLFW_KEY_6;
_glfw.mir.publicKeys[KEY_7] = GLFW_KEY_7;
_glfw.mir.publicKeys[KEY_8] = GLFW_KEY_8;
_glfw.mir.publicKeys[KEY_9] = GLFW_KEY_9;
_glfw.mir.publicKeys[KEY_0] = GLFW_KEY_0;
_glfw.mir.publicKeys[KEY_MINUS] = GLFW_KEY_MINUS;
_glfw.mir.publicKeys[KEY_EQUAL] = GLFW_KEY_EQUAL;
_glfw.mir.publicKeys[KEY_Q] = GLFW_KEY_Q;
_glfw.mir.publicKeys[KEY_W] = GLFW_KEY_W;
_glfw.mir.publicKeys[KEY_E] = GLFW_KEY_E;
_glfw.mir.publicKeys[KEY_R] = GLFW_KEY_R;
_glfw.mir.publicKeys[KEY_T] = GLFW_KEY_T;
_glfw.mir.publicKeys[KEY_Y] = GLFW_KEY_Y;
_glfw.mir.publicKeys[KEY_U] = GLFW_KEY_U;
_glfw.mir.publicKeys[KEY_I] = GLFW_KEY_I;
_glfw.mir.publicKeys[KEY_O] = GLFW_KEY_O;
_glfw.mir.publicKeys[KEY_P] = GLFW_KEY_P;
_glfw.mir.publicKeys[KEY_LEFTBRACE] = GLFW_KEY_LEFT_BRACKET;
_glfw.mir.publicKeys[KEY_RIGHTBRACE] = GLFW_KEY_RIGHT_BRACKET;
_glfw.mir.publicKeys[KEY_A] = GLFW_KEY_A;
_glfw.mir.publicKeys[KEY_S] = GLFW_KEY_S;
_glfw.mir.publicKeys[KEY_D] = GLFW_KEY_D;
_glfw.mir.publicKeys[KEY_F] = GLFW_KEY_F;
_glfw.mir.publicKeys[KEY_G] = GLFW_KEY_G;
_glfw.mir.publicKeys[KEY_H] = GLFW_KEY_H;
_glfw.mir.publicKeys[KEY_J] = GLFW_KEY_J;
_glfw.mir.publicKeys[KEY_K] = GLFW_KEY_K;
_glfw.mir.publicKeys[KEY_L] = GLFW_KEY_L;
_glfw.mir.publicKeys[KEY_SEMICOLON] = GLFW_KEY_SEMICOLON;
_glfw.mir.publicKeys[KEY_APOSTROPHE] = GLFW_KEY_APOSTROPHE;
_glfw.mir.publicKeys[KEY_Z] = GLFW_KEY_Z;
_glfw.mir.publicKeys[KEY_X] = GLFW_KEY_X;
_glfw.mir.publicKeys[KEY_C] = GLFW_KEY_C;
_glfw.mir.publicKeys[KEY_V] = GLFW_KEY_V;
_glfw.mir.publicKeys[KEY_B] = GLFW_KEY_B;
_glfw.mir.publicKeys[KEY_N] = GLFW_KEY_N;
_glfw.mir.publicKeys[KEY_M] = GLFW_KEY_M;
_glfw.mir.publicKeys[KEY_COMMA] = GLFW_KEY_COMMA;
_glfw.mir.publicKeys[KEY_DOT] = GLFW_KEY_PERIOD;
_glfw.mir.publicKeys[KEY_SLASH] = GLFW_KEY_SLASH;
_glfw.mir.publicKeys[KEY_BACKSLASH] = GLFW_KEY_BACKSLASH;
_glfw.mir.publicKeys[KEY_ESC] = GLFW_KEY_ESCAPE;
_glfw.mir.publicKeys[KEY_TAB] = GLFW_KEY_TAB;
_glfw.mir.publicKeys[KEY_LEFTSHIFT] = GLFW_KEY_LEFT_SHIFT;
_glfw.mir.publicKeys[KEY_RIGHTSHIFT] = GLFW_KEY_RIGHT_SHIFT;
_glfw.mir.publicKeys[KEY_LEFTCTRL] = GLFW_KEY_LEFT_CONTROL;
_glfw.mir.publicKeys[KEY_RIGHTCTRL] = GLFW_KEY_RIGHT_CONTROL;
_glfw.mir.publicKeys[KEY_LEFTALT] = GLFW_KEY_LEFT_ALT;
_glfw.mir.publicKeys[KEY_RIGHTALT] = GLFW_KEY_RIGHT_ALT;
_glfw.mir.publicKeys[KEY_LEFTMETA] = GLFW_KEY_LEFT_SUPER;
_glfw.mir.publicKeys[KEY_RIGHTMETA] = GLFW_KEY_RIGHT_SUPER;
_glfw.mir.publicKeys[KEY_MENU] = GLFW_KEY_MENU;
_glfw.mir.publicKeys[KEY_NUMLOCK] = GLFW_KEY_NUM_LOCK;
_glfw.mir.publicKeys[KEY_CAPSLOCK] = GLFW_KEY_CAPS_LOCK;
_glfw.mir.publicKeys[KEY_PRINT] = GLFW_KEY_PRINT_SCREEN;
_glfw.mir.publicKeys[KEY_SCROLLLOCK] = GLFW_KEY_SCROLL_LOCK;
_glfw.mir.publicKeys[KEY_PAUSE] = GLFW_KEY_PAUSE;
_glfw.mir.publicKeys[KEY_DELETE] = GLFW_KEY_DELETE;
_glfw.mir.publicKeys[KEY_BACKSPACE] = GLFW_KEY_BACKSPACE;
_glfw.mir.publicKeys[KEY_ENTER] = GLFW_KEY_ENTER;
_glfw.mir.publicKeys[KEY_HOME] = GLFW_KEY_HOME;
_glfw.mir.publicKeys[KEY_END] = GLFW_KEY_END;
_glfw.mir.publicKeys[KEY_PAGEUP] = GLFW_KEY_PAGE_UP;
_glfw.mir.publicKeys[KEY_PAGEDOWN] = GLFW_KEY_PAGE_DOWN;
_glfw.mir.publicKeys[KEY_INSERT] = GLFW_KEY_INSERT;
_glfw.mir.publicKeys[KEY_LEFT] = GLFW_KEY_LEFT;
_glfw.mir.publicKeys[KEY_RIGHT] = GLFW_KEY_RIGHT;
_glfw.mir.publicKeys[KEY_DOWN] = GLFW_KEY_DOWN;
_glfw.mir.publicKeys[KEY_UP] = GLFW_KEY_UP;
_glfw.mir.publicKeys[KEY_F1] = GLFW_KEY_F1;
_glfw.mir.publicKeys[KEY_F2] = GLFW_KEY_F2;
_glfw.mir.publicKeys[KEY_F3] = GLFW_KEY_F3;
_glfw.mir.publicKeys[KEY_F4] = GLFW_KEY_F4;
_glfw.mir.publicKeys[KEY_F5] = GLFW_KEY_F5;
_glfw.mir.publicKeys[KEY_F6] = GLFW_KEY_F6;
_glfw.mir.publicKeys[KEY_F7] = GLFW_KEY_F7;
_glfw.mir.publicKeys[KEY_F8] = GLFW_KEY_F8;
_glfw.mir.publicKeys[KEY_F9] = GLFW_KEY_F9;
_glfw.mir.publicKeys[KEY_F10] = GLFW_KEY_F10;
_glfw.mir.publicKeys[KEY_F11] = GLFW_KEY_F11;
_glfw.mir.publicKeys[KEY_F12] = GLFW_KEY_F12;
_glfw.mir.publicKeys[KEY_F13] = GLFW_KEY_F13;
_glfw.mir.publicKeys[KEY_F14] = GLFW_KEY_F14;
_glfw.mir.publicKeys[KEY_F15] = GLFW_KEY_F15;
_glfw.mir.publicKeys[KEY_F16] = GLFW_KEY_F16;
_glfw.mir.publicKeys[KEY_F17] = GLFW_KEY_F17;
_glfw.mir.publicKeys[KEY_F18] = GLFW_KEY_F18;
_glfw.mir.publicKeys[KEY_F19] = GLFW_KEY_F19;
_glfw.mir.publicKeys[KEY_F20] = GLFW_KEY_F20;
_glfw.mir.publicKeys[KEY_F21] = GLFW_KEY_F21;
_glfw.mir.publicKeys[KEY_F22] = GLFW_KEY_F22;
_glfw.mir.publicKeys[KEY_F23] = GLFW_KEY_F23;
_glfw.mir.publicKeys[KEY_F24] = GLFW_KEY_F24;
_glfw.mir.publicKeys[KEY_KPSLASH] = GLFW_KEY_KP_DIVIDE;
_glfw.mir.publicKeys[KEY_KPDOT] = GLFW_KEY_KP_MULTIPLY;
_glfw.mir.publicKeys[KEY_KPMINUS] = GLFW_KEY_KP_SUBTRACT;
_glfw.mir.publicKeys[KEY_KPPLUS] = GLFW_KEY_KP_ADD;
_glfw.mir.publicKeys[KEY_KP0] = GLFW_KEY_KP_0;
_glfw.mir.publicKeys[KEY_KP1] = GLFW_KEY_KP_1;
_glfw.mir.publicKeys[KEY_KP2] = GLFW_KEY_KP_2;
_glfw.mir.publicKeys[KEY_KP3] = GLFW_KEY_KP_3;
_glfw.mir.publicKeys[KEY_KP4] = GLFW_KEY_KP_4;
_glfw.mir.publicKeys[KEY_KP5] = GLFW_KEY_KP_5;
_glfw.mir.publicKeys[KEY_KP6] = GLFW_KEY_KP_6;
_glfw.mir.publicKeys[KEY_KP7] = GLFW_KEY_KP_7;
_glfw.mir.publicKeys[KEY_KP8] = GLFW_KEY_KP_8;
_glfw.mir.publicKeys[KEY_KP9] = GLFW_KEY_KP_9;
_glfw.mir.publicKeys[KEY_KPCOMMA] = GLFW_KEY_KP_DECIMAL;
_glfw.mir.publicKeys[KEY_KPEQUAL] = GLFW_KEY_KP_EQUAL;
_glfw.mir.publicKeys[KEY_KPENTER] = GLFW_KEY_KP_ENTER;
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW internal API ////// ////// GLFW internal API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -52,6 +177,8 @@ int _glfwPlatformInit(void)
_glfw.mir.display = _glfw.mir.display =
mir_connection_get_egl_native_display(_glfw.mir.connection); mir_connection_get_egl_native_display(_glfw.mir.connection);
createKeyTables();
if (!_glfwInitContextAPI()) if (!_glfwInitContextAPI())
return GLFW_FALSE; return GLFW_FALSE;

View File

@ -92,6 +92,8 @@ typedef struct _GLFWlibraryMir
MirCursorConfiguration* default_conf; MirCursorConfiguration* default_conf;
EventQueue* event_queue; EventQueue* event_queue;
short int publicKeys[256];
pthread_mutex_t event_mutex; pthread_mutex_t event_mutex;
pthread_cond_t event_cond; pthread_cond_t event_cond;

View File

@ -130,129 +130,12 @@ static int mirModToGLFWMod(uint32_t mods)
return publicMods; return publicMods;
} }
// Taken from wl_init.c
static int toGLFWKeyCode(uint32_t key) static int toGLFWKeyCode(uint32_t key)
{ {
switch (key) if (key < sizeof(_glfw.mir.publicKeys) / sizeof(_glfw.mir.publicKeys[0]))
{ return _glfw.mir.publicKeys[key];
case KEY_GRAVE: return GLFW_KEY_GRAVE_ACCENT;
case KEY_1: return GLFW_KEY_1; return GLFW_KEY_UNKNOWN;
case KEY_2: return GLFW_KEY_2;
case KEY_3: return GLFW_KEY_3;
case KEY_4: return GLFW_KEY_4;
case KEY_5: return GLFW_KEY_5;
case KEY_6: return GLFW_KEY_6;
case KEY_7: return GLFW_KEY_7;
case KEY_8: return GLFW_KEY_8;
case KEY_9: return GLFW_KEY_9;
case KEY_0: return GLFW_KEY_0;
case KEY_MINUS: return GLFW_KEY_MINUS;
case KEY_EQUAL: return GLFW_KEY_EQUAL;
case KEY_Q: return GLFW_KEY_Q;
case KEY_W: return GLFW_KEY_W;
case KEY_E: return GLFW_KEY_E;
case KEY_R: return GLFW_KEY_R;
case KEY_T: return GLFW_KEY_T;
case KEY_Y: return GLFW_KEY_Y;
case KEY_U: return GLFW_KEY_U;
case KEY_I: return GLFW_KEY_I;
case KEY_O: return GLFW_KEY_O;
case KEY_P: return GLFW_KEY_P;
case KEY_LEFTBRACE: return GLFW_KEY_LEFT_BRACKET;
case KEY_RIGHTBRACE: return GLFW_KEY_RIGHT_BRACKET;
case KEY_A: return GLFW_KEY_A;
case KEY_S: return GLFW_KEY_S;
case KEY_D: return GLFW_KEY_D;
case KEY_F: return GLFW_KEY_F;
case KEY_G: return GLFW_KEY_G;
case KEY_H: return GLFW_KEY_H;
case KEY_J: return GLFW_KEY_J;
case KEY_K: return GLFW_KEY_K;
case KEY_L: return GLFW_KEY_L;
case KEY_SEMICOLON: return GLFW_KEY_SEMICOLON;
case KEY_APOSTROPHE: return GLFW_KEY_APOSTROPHE;
case KEY_Z: return GLFW_KEY_Z;
case KEY_X: return GLFW_KEY_X;
case KEY_C: return GLFW_KEY_C;
case KEY_V: return GLFW_KEY_V;
case KEY_B: return GLFW_KEY_B;
case KEY_N: return GLFW_KEY_N;
case KEY_M: return GLFW_KEY_M;
case KEY_COMMA: return GLFW_KEY_COMMA;
case KEY_DOT: return GLFW_KEY_PERIOD;
case KEY_SLASH: return GLFW_KEY_SLASH;
case KEY_BACKSLASH: return GLFW_KEY_BACKSLASH;
case KEY_ESC: return GLFW_KEY_ESCAPE;
case KEY_TAB: return GLFW_KEY_TAB;
case KEY_LEFTSHIFT: return GLFW_KEY_LEFT_SHIFT;
case KEY_RIGHTSHIFT: return GLFW_KEY_RIGHT_SHIFT;
case KEY_LEFTCTRL: return GLFW_KEY_LEFT_CONTROL;
case KEY_RIGHTCTRL: return GLFW_KEY_RIGHT_CONTROL;
case KEY_LEFTALT: return GLFW_KEY_LEFT_ALT;
case KEY_RIGHTALT: return GLFW_KEY_RIGHT_ALT;
case KEY_LEFTMETA: return GLFW_KEY_LEFT_SUPER;
case KEY_RIGHTMETA: return GLFW_KEY_RIGHT_SUPER;
case KEY_MENU: return GLFW_KEY_MENU;
case KEY_NUMLOCK: return GLFW_KEY_NUM_LOCK;
case KEY_CAPSLOCK: return GLFW_KEY_CAPS_LOCK;
case KEY_PRINT: return GLFW_KEY_PRINT_SCREEN;
case KEY_SCROLLLOCK: return GLFW_KEY_SCROLL_LOCK;
case KEY_PAUSE: return GLFW_KEY_PAUSE;
case KEY_DELETE: return GLFW_KEY_DELETE;
case KEY_BACKSPACE: return GLFW_KEY_BACKSPACE;
case KEY_ENTER: return GLFW_KEY_ENTER;
case KEY_HOME: return GLFW_KEY_HOME;
case KEY_END: return GLFW_KEY_END;
case KEY_PAGEUP: return GLFW_KEY_PAGE_UP;
case KEY_PAGEDOWN: return GLFW_KEY_PAGE_DOWN;
case KEY_INSERT: return GLFW_KEY_INSERT;
case KEY_LEFT: return GLFW_KEY_LEFT;
case KEY_RIGHT: return GLFW_KEY_RIGHT;
case KEY_DOWN: return GLFW_KEY_DOWN;
case KEY_UP: return GLFW_KEY_UP;
case KEY_F1: return GLFW_KEY_F1;
case KEY_F2: return GLFW_KEY_F2;
case KEY_F3: return GLFW_KEY_F3;
case KEY_F4: return GLFW_KEY_F4;
case KEY_F5: return GLFW_KEY_F5;
case KEY_F6: return GLFW_KEY_F6;
case KEY_F7: return GLFW_KEY_F7;
case KEY_F8: return GLFW_KEY_F8;
case KEY_F9: return GLFW_KEY_F9;
case KEY_F10: return GLFW_KEY_F10;
case KEY_F11: return GLFW_KEY_F11;
case KEY_F12: return GLFW_KEY_F12;
case KEY_F13: return GLFW_KEY_F13;
case KEY_F14: return GLFW_KEY_F14;
case KEY_F15: return GLFW_KEY_F15;
case KEY_F16: return GLFW_KEY_F16;
case KEY_F17: return GLFW_KEY_F17;
case KEY_F18: return GLFW_KEY_F18;
case KEY_F19: return GLFW_KEY_F19;
case KEY_F20: return GLFW_KEY_F20;
case KEY_F21: return GLFW_KEY_F21;
case KEY_F22: return GLFW_KEY_F22;
case KEY_F23: return GLFW_KEY_F23;
case KEY_F24: return GLFW_KEY_F24;
case KEY_KPSLASH: return GLFW_KEY_KP_DIVIDE;
case KEY_KPDOT: return GLFW_KEY_KP_MULTIPLY;
case KEY_KPMINUS: return GLFW_KEY_KP_SUBTRACT;
case KEY_KPPLUS: return GLFW_KEY_KP_ADD;
case KEY_KP0: return GLFW_KEY_KP_0;
case KEY_KP1: return GLFW_KEY_KP_1;
case KEY_KP2: return GLFW_KEY_KP_2;
case KEY_KP3: return GLFW_KEY_KP_3;
case KEY_KP4: return GLFW_KEY_KP_4;
case KEY_KP5: return GLFW_KEY_KP_5;
case KEY_KP6: return GLFW_KEY_KP_6;
case KEY_KP7: return GLFW_KEY_KP_7;
case KEY_KP8: return GLFW_KEY_KP_8;
case KEY_KP9: return GLFW_KEY_KP_9;
case KEY_KPCOMMA: return GLFW_KEY_KP_DECIMAL;
case KEY_KPEQUAL: return GLFW_KEY_KP_EQUAL;
case KEY_KPENTER: return GLFW_KEY_KP_ENTER;
default: return GLFW_KEY_UNKNOWN;
}
} }
static void handleKeyEvent(const MirKeyboardEvent* key_event, _GLFWwindow* window) static void handleKeyEvent(const MirKeyboardEvent* key_event, _GLFWwindow* window)

View File

@ -252,126 +252,10 @@ static void keyboardHandleLeave(void* data,
static int toGLFWKeyCode(uint32_t key) static int toGLFWKeyCode(uint32_t key)
{ {
switch (key) if (key < sizeof(_glfw.wl.publicKeys) / sizeof(_glfw.wl.publicKeys[0]))
{ return _glfw.wl.publicKeys[key];
case KEY_GRAVE: return GLFW_KEY_GRAVE_ACCENT;
case KEY_1: return GLFW_KEY_1; return GLFW_KEY_UNKNOWN;
case KEY_2: return GLFW_KEY_2;
case KEY_3: return GLFW_KEY_3;
case KEY_4: return GLFW_KEY_4;
case KEY_5: return GLFW_KEY_5;
case KEY_6: return GLFW_KEY_6;
case KEY_7: return GLFW_KEY_7;
case KEY_8: return GLFW_KEY_8;
case KEY_9: return GLFW_KEY_9;
case KEY_0: return GLFW_KEY_0;
case KEY_MINUS: return GLFW_KEY_MINUS;
case KEY_EQUAL: return GLFW_KEY_EQUAL;
case KEY_Q: return GLFW_KEY_Q;
case KEY_W: return GLFW_KEY_W;
case KEY_E: return GLFW_KEY_E;
case KEY_R: return GLFW_KEY_R;
case KEY_T: return GLFW_KEY_T;
case KEY_Y: return GLFW_KEY_Y;
case KEY_U: return GLFW_KEY_U;
case KEY_I: return GLFW_KEY_I;
case KEY_O: return GLFW_KEY_O;
case KEY_P: return GLFW_KEY_P;
case KEY_LEFTBRACE: return GLFW_KEY_LEFT_BRACKET;
case KEY_RIGHTBRACE: return GLFW_KEY_RIGHT_BRACKET;
case KEY_A: return GLFW_KEY_A;
case KEY_S: return GLFW_KEY_S;
case KEY_D: return GLFW_KEY_D;
case KEY_F: return GLFW_KEY_F;
case KEY_G: return GLFW_KEY_G;
case KEY_H: return GLFW_KEY_H;
case KEY_J: return GLFW_KEY_J;
case KEY_K: return GLFW_KEY_K;
case KEY_L: return GLFW_KEY_L;
case KEY_SEMICOLON: return GLFW_KEY_SEMICOLON;
case KEY_APOSTROPHE: return GLFW_KEY_APOSTROPHE;
case KEY_Z: return GLFW_KEY_Z;
case KEY_X: return GLFW_KEY_X;
case KEY_C: return GLFW_KEY_C;
case KEY_V: return GLFW_KEY_V;
case KEY_B: return GLFW_KEY_B;
case KEY_N: return GLFW_KEY_N;
case KEY_M: return GLFW_KEY_M;
case KEY_COMMA: return GLFW_KEY_COMMA;
case KEY_DOT: return GLFW_KEY_PERIOD;
case KEY_SLASH: return GLFW_KEY_SLASH;
case KEY_BACKSLASH: return GLFW_KEY_BACKSLASH;
case KEY_ESC: return GLFW_KEY_ESCAPE;
case KEY_TAB: return GLFW_KEY_TAB;
case KEY_LEFTSHIFT: return GLFW_KEY_LEFT_SHIFT;
case KEY_RIGHTSHIFT: return GLFW_KEY_RIGHT_SHIFT;
case KEY_LEFTCTRL: return GLFW_KEY_LEFT_CONTROL;
case KEY_RIGHTCTRL: return GLFW_KEY_RIGHT_CONTROL;
case KEY_LEFTALT: return GLFW_KEY_LEFT_ALT;
case KEY_RIGHTALT: return GLFW_KEY_RIGHT_ALT;
case KEY_LEFTMETA: return GLFW_KEY_LEFT_SUPER;
case KEY_RIGHTMETA: return GLFW_KEY_RIGHT_SUPER;
case KEY_MENU: return GLFW_KEY_MENU;
case KEY_NUMLOCK: return GLFW_KEY_NUM_LOCK;
case KEY_CAPSLOCK: return GLFW_KEY_CAPS_LOCK;
case KEY_PRINT: return GLFW_KEY_PRINT_SCREEN;
case KEY_SCROLLLOCK: return GLFW_KEY_SCROLL_LOCK;
case KEY_PAUSE: return GLFW_KEY_PAUSE;
case KEY_DELETE: return GLFW_KEY_DELETE;
case KEY_BACKSPACE: return GLFW_KEY_BACKSPACE;
case KEY_ENTER: return GLFW_KEY_ENTER;
case KEY_HOME: return GLFW_KEY_HOME;
case KEY_END: return GLFW_KEY_END;
case KEY_PAGEUP: return GLFW_KEY_PAGE_UP;
case KEY_PAGEDOWN: return GLFW_KEY_PAGE_DOWN;
case KEY_INSERT: return GLFW_KEY_INSERT;
case KEY_LEFT: return GLFW_KEY_LEFT;
case KEY_RIGHT: return GLFW_KEY_RIGHT;
case KEY_DOWN: return GLFW_KEY_DOWN;
case KEY_UP: return GLFW_KEY_UP;
case KEY_F1: return GLFW_KEY_F1;
case KEY_F2: return GLFW_KEY_F2;
case KEY_F3: return GLFW_KEY_F3;
case KEY_F4: return GLFW_KEY_F4;
case KEY_F5: return GLFW_KEY_F5;
case KEY_F6: return GLFW_KEY_F6;
case KEY_F7: return GLFW_KEY_F7;
case KEY_F8: return GLFW_KEY_F8;
case KEY_F9: return GLFW_KEY_F9;
case KEY_F10: return GLFW_KEY_F10;
case KEY_F11: return GLFW_KEY_F11;
case KEY_F12: return GLFW_KEY_F12;
case KEY_F13: return GLFW_KEY_F13;
case KEY_F14: return GLFW_KEY_F14;
case KEY_F15: return GLFW_KEY_F15;
case KEY_F16: return GLFW_KEY_F16;
case KEY_F17: return GLFW_KEY_F17;
case KEY_F18: return GLFW_KEY_F18;
case KEY_F19: return GLFW_KEY_F19;
case KEY_F20: return GLFW_KEY_F20;
case KEY_F21: return GLFW_KEY_F21;
case KEY_F22: return GLFW_KEY_F22;
case KEY_F23: return GLFW_KEY_F23;
case KEY_F24: return GLFW_KEY_F24;
case KEY_KPSLASH: return GLFW_KEY_KP_DIVIDE;
case KEY_KPDOT: return GLFW_KEY_KP_MULTIPLY;
case KEY_KPMINUS: return GLFW_KEY_KP_SUBTRACT;
case KEY_KPPLUS: return GLFW_KEY_KP_ADD;
case KEY_KP0: return GLFW_KEY_KP_0;
case KEY_KP1: return GLFW_KEY_KP_1;
case KEY_KP2: return GLFW_KEY_KP_2;
case KEY_KP3: return GLFW_KEY_KP_3;
case KEY_KP4: return GLFW_KEY_KP_4;
case KEY_KP5: return GLFW_KEY_KP_5;
case KEY_KP6: return GLFW_KEY_KP_6;
case KEY_KP7: return GLFW_KEY_KP_7;
case KEY_KP8: return GLFW_KEY_KP_8;
case KEY_KP9: return GLFW_KEY_KP_9;
case KEY_KPCOMMA: return GLFW_KEY_KP_DECIMAL;
case KEY_KPEQUAL: return GLFW_KEY_KP_EQUAL;
case KEY_KPENTER: return GLFW_KEY_KP_ENTER;
default: return GLFW_KEY_UNKNOWN;
}
} }
static void keyboardHandleKey(void* data, static void keyboardHandleKey(void* data,
@ -536,6 +420,130 @@ static const struct wl_registry_listener registryListener = {
registryHandleGlobalRemove registryHandleGlobalRemove
}; };
// Create key code translation tables
//
static void createKeyTables(void)
{
memset(_glfw.wl.publicKeys, -1, sizeof(_glfw.wl.publicKeys));
_glfw.wl.publicKeys[KEY_GRAVE] = GLFW_KEY_GRAVE_ACCENT;
_glfw.wl.publicKeys[KEY_1] = GLFW_KEY_1;
_glfw.wl.publicKeys[KEY_2] = GLFW_KEY_2;
_glfw.wl.publicKeys[KEY_3] = GLFW_KEY_3;
_glfw.wl.publicKeys[KEY_4] = GLFW_KEY_4;
_glfw.wl.publicKeys[KEY_5] = GLFW_KEY_5;
_glfw.wl.publicKeys[KEY_6] = GLFW_KEY_6;
_glfw.wl.publicKeys[KEY_7] = GLFW_KEY_7;
_glfw.wl.publicKeys[KEY_8] = GLFW_KEY_8;
_glfw.wl.publicKeys[KEY_9] = GLFW_KEY_9;
_glfw.wl.publicKeys[KEY_0] = GLFW_KEY_0;
_glfw.wl.publicKeys[KEY_MINUS] = GLFW_KEY_MINUS;
_glfw.wl.publicKeys[KEY_EQUAL] = GLFW_KEY_EQUAL;
_glfw.wl.publicKeys[KEY_Q] = GLFW_KEY_Q;
_glfw.wl.publicKeys[KEY_W] = GLFW_KEY_W;
_glfw.wl.publicKeys[KEY_E] = GLFW_KEY_E;
_glfw.wl.publicKeys[KEY_R] = GLFW_KEY_R;
_glfw.wl.publicKeys[KEY_T] = GLFW_KEY_T;
_glfw.wl.publicKeys[KEY_Y] = GLFW_KEY_Y;
_glfw.wl.publicKeys[KEY_U] = GLFW_KEY_U;
_glfw.wl.publicKeys[KEY_I] = GLFW_KEY_I;
_glfw.wl.publicKeys[KEY_O] = GLFW_KEY_O;
_glfw.wl.publicKeys[KEY_P] = GLFW_KEY_P;
_glfw.wl.publicKeys[KEY_LEFTBRACE] = GLFW_KEY_LEFT_BRACKET;
_glfw.wl.publicKeys[KEY_RIGHTBRACE] = GLFW_KEY_RIGHT_BRACKET;
_glfw.wl.publicKeys[KEY_A] = GLFW_KEY_A;
_glfw.wl.publicKeys[KEY_S] = GLFW_KEY_S;
_glfw.wl.publicKeys[KEY_D] = GLFW_KEY_D;
_glfw.wl.publicKeys[KEY_F] = GLFW_KEY_F;
_glfw.wl.publicKeys[KEY_G] = GLFW_KEY_G;
_glfw.wl.publicKeys[KEY_H] = GLFW_KEY_H;
_glfw.wl.publicKeys[KEY_J] = GLFW_KEY_J;
_glfw.wl.publicKeys[KEY_K] = GLFW_KEY_K;
_glfw.wl.publicKeys[KEY_L] = GLFW_KEY_L;
_glfw.wl.publicKeys[KEY_SEMICOLON] = GLFW_KEY_SEMICOLON;
_glfw.wl.publicKeys[KEY_APOSTROPHE] = GLFW_KEY_APOSTROPHE;
_glfw.wl.publicKeys[KEY_Z] = GLFW_KEY_Z;
_glfw.wl.publicKeys[KEY_X] = GLFW_KEY_X;
_glfw.wl.publicKeys[KEY_C] = GLFW_KEY_C;
_glfw.wl.publicKeys[KEY_V] = GLFW_KEY_V;
_glfw.wl.publicKeys[KEY_B] = GLFW_KEY_B;
_glfw.wl.publicKeys[KEY_N] = GLFW_KEY_N;
_glfw.wl.publicKeys[KEY_M] = GLFW_KEY_M;
_glfw.wl.publicKeys[KEY_COMMA] = GLFW_KEY_COMMA;
_glfw.wl.publicKeys[KEY_DOT] = GLFW_KEY_PERIOD;
_glfw.wl.publicKeys[KEY_SLASH] = GLFW_KEY_SLASH;
_glfw.wl.publicKeys[KEY_BACKSLASH] = GLFW_KEY_BACKSLASH;
_glfw.wl.publicKeys[KEY_ESC] = GLFW_KEY_ESCAPE;
_glfw.wl.publicKeys[KEY_TAB] = GLFW_KEY_TAB;
_glfw.wl.publicKeys[KEY_LEFTSHIFT] = GLFW_KEY_LEFT_SHIFT;
_glfw.wl.publicKeys[KEY_RIGHTSHIFT] = GLFW_KEY_RIGHT_SHIFT;
_glfw.wl.publicKeys[KEY_LEFTCTRL] = GLFW_KEY_LEFT_CONTROL;
_glfw.wl.publicKeys[KEY_RIGHTCTRL] = GLFW_KEY_RIGHT_CONTROL;
_glfw.wl.publicKeys[KEY_LEFTALT] = GLFW_KEY_LEFT_ALT;
_glfw.wl.publicKeys[KEY_RIGHTALT] = GLFW_KEY_RIGHT_ALT;
_glfw.wl.publicKeys[KEY_LEFTMETA] = GLFW_KEY_LEFT_SUPER;
_glfw.wl.publicKeys[KEY_RIGHTMETA] = GLFW_KEY_RIGHT_SUPER;
_glfw.wl.publicKeys[KEY_MENU] = GLFW_KEY_MENU;
_glfw.wl.publicKeys[KEY_NUMLOCK] = GLFW_KEY_NUM_LOCK;
_glfw.wl.publicKeys[KEY_CAPSLOCK] = GLFW_KEY_CAPS_LOCK;
_glfw.wl.publicKeys[KEY_PRINT] = GLFW_KEY_PRINT_SCREEN;
_glfw.wl.publicKeys[KEY_SCROLLLOCK] = GLFW_KEY_SCROLL_LOCK;
_glfw.wl.publicKeys[KEY_PAUSE] = GLFW_KEY_PAUSE;
_glfw.wl.publicKeys[KEY_DELETE] = GLFW_KEY_DELETE;
_glfw.wl.publicKeys[KEY_BACKSPACE] = GLFW_KEY_BACKSPACE;
_glfw.wl.publicKeys[KEY_ENTER] = GLFW_KEY_ENTER;
_glfw.wl.publicKeys[KEY_HOME] = GLFW_KEY_HOME;
_glfw.wl.publicKeys[KEY_END] = GLFW_KEY_END;
_glfw.wl.publicKeys[KEY_PAGEUP] = GLFW_KEY_PAGE_UP;
_glfw.wl.publicKeys[KEY_PAGEDOWN] = GLFW_KEY_PAGE_DOWN;
_glfw.wl.publicKeys[KEY_INSERT] = GLFW_KEY_INSERT;
_glfw.wl.publicKeys[KEY_LEFT] = GLFW_KEY_LEFT;
_glfw.wl.publicKeys[KEY_RIGHT] = GLFW_KEY_RIGHT;
_glfw.wl.publicKeys[KEY_DOWN] = GLFW_KEY_DOWN;
_glfw.wl.publicKeys[KEY_UP] = GLFW_KEY_UP;
_glfw.wl.publicKeys[KEY_F1] = GLFW_KEY_F1;
_glfw.wl.publicKeys[KEY_F2] = GLFW_KEY_F2;
_glfw.wl.publicKeys[KEY_F3] = GLFW_KEY_F3;
_glfw.wl.publicKeys[KEY_F4] = GLFW_KEY_F4;
_glfw.wl.publicKeys[KEY_F5] = GLFW_KEY_F5;
_glfw.wl.publicKeys[KEY_F6] = GLFW_KEY_F6;
_glfw.wl.publicKeys[KEY_F7] = GLFW_KEY_F7;
_glfw.wl.publicKeys[KEY_F8] = GLFW_KEY_F8;
_glfw.wl.publicKeys[KEY_F9] = GLFW_KEY_F9;
_glfw.wl.publicKeys[KEY_F10] = GLFW_KEY_F10;
_glfw.wl.publicKeys[KEY_F11] = GLFW_KEY_F11;
_glfw.wl.publicKeys[KEY_F12] = GLFW_KEY_F12;
_glfw.wl.publicKeys[KEY_F13] = GLFW_KEY_F13;
_glfw.wl.publicKeys[KEY_F14] = GLFW_KEY_F14;
_glfw.wl.publicKeys[KEY_F15] = GLFW_KEY_F15;
_glfw.wl.publicKeys[KEY_F16] = GLFW_KEY_F16;
_glfw.wl.publicKeys[KEY_F17] = GLFW_KEY_F17;
_glfw.wl.publicKeys[KEY_F18] = GLFW_KEY_F18;
_glfw.wl.publicKeys[KEY_F19] = GLFW_KEY_F19;
_glfw.wl.publicKeys[KEY_F20] = GLFW_KEY_F20;
_glfw.wl.publicKeys[KEY_F21] = GLFW_KEY_F21;
_glfw.wl.publicKeys[KEY_F22] = GLFW_KEY_F22;
_glfw.wl.publicKeys[KEY_F23] = GLFW_KEY_F23;
_glfw.wl.publicKeys[KEY_F24] = GLFW_KEY_F24;
_glfw.wl.publicKeys[KEY_KPSLASH] = GLFW_KEY_KP_DIVIDE;
_glfw.wl.publicKeys[KEY_KPDOT] = GLFW_KEY_KP_MULTIPLY;
_glfw.wl.publicKeys[KEY_KPMINUS] = GLFW_KEY_KP_SUBTRACT;
_glfw.wl.publicKeys[KEY_KPPLUS] = GLFW_KEY_KP_ADD;
_glfw.wl.publicKeys[KEY_KP0] = GLFW_KEY_KP_0;
_glfw.wl.publicKeys[KEY_KP1] = GLFW_KEY_KP_1;
_glfw.wl.publicKeys[KEY_KP2] = GLFW_KEY_KP_2;
_glfw.wl.publicKeys[KEY_KP3] = GLFW_KEY_KP_3;
_glfw.wl.publicKeys[KEY_KP4] = GLFW_KEY_KP_4;
_glfw.wl.publicKeys[KEY_KP5] = GLFW_KEY_KP_5;
_glfw.wl.publicKeys[KEY_KP6] = GLFW_KEY_KP_6;
_glfw.wl.publicKeys[KEY_KP7] = GLFW_KEY_KP_7;
_glfw.wl.publicKeys[KEY_KP8] = GLFW_KEY_KP_8;
_glfw.wl.publicKeys[KEY_KP9] = GLFW_KEY_KP_9;
_glfw.wl.publicKeys[KEY_KPCOMMA] = GLFW_KEY_KP_DECIMAL;
_glfw.wl.publicKeys[KEY_KPEQUAL] = GLFW_KEY_KP_EQUAL;
_glfw.wl.publicKeys[KEY_KPENTER] = GLFW_KEY_KP_ENTER;
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW platform API ////// ////// GLFW platform API //////
@ -557,6 +565,8 @@ int _glfwPlatformInit(void)
_glfw.wl.monitors = calloc(4, sizeof(_GLFWmonitor*)); _glfw.wl.monitors = calloc(4, sizeof(_GLFWmonitor*));
_glfw.wl.monitorsSize = 4; _glfw.wl.monitorsSize = 4;
createKeyTables();
_glfw.wl.xkb.context = xkb_context_new(0); _glfw.wl.xkb.context = xkb_context_new(0);
if (!_glfw.wl.xkb.context) if (!_glfw.wl.xkb.context)
{ {

View File

@ -91,6 +91,8 @@ typedef struct _GLFWlibraryWayland
int monitorsCount; int monitorsCount;
int monitorsSize; int monitorsSize;
short int publicKeys[256];
struct { struct {
struct xkb_context* context; struct xkb_context* context;
struct xkb_keymap* keymap; struct xkb_keymap* keymap;