Push key events to ImGui.

This commit is contained in:
Bartosz Taudul 2022-12-22 17:39:30 +01:00
parent dff2a6d6c2
commit 797d5df850
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -28,6 +28,137 @@
#include "Backend.hpp"
#include "RunQueue.hpp"
constexpr ImGuiKey s_keyTable[] = {
/* 0 */ ImGuiKey_None,
/* 1 */ ImGuiKey_Escape,
/* 2 */ ImGuiKey_1,
/* 3 */ ImGuiKey_2,
/* 4 */ ImGuiKey_3,
/* 5 */ ImGuiKey_4,
/* 6 */ ImGuiKey_5,
/* 7 */ ImGuiKey_6,
/* 8 */ ImGuiKey_7,
/* 9 */ ImGuiKey_8,
/* 10 */ ImGuiKey_9,
/* 11 */ ImGuiKey_0,
/* 12 */ ImGuiKey_Minus,
/* 13 */ ImGuiKey_Equal,
/* 14 */ ImGuiKey_Backspace,
/* 15 */ ImGuiKey_Tab,
/* 16 */ ImGuiKey_Q,
/* 17 */ ImGuiKey_W,
/* 18 */ ImGuiKey_E,
/* 19 */ ImGuiKey_R,
/* 20 */ ImGuiKey_T,
/* 21 */ ImGuiKey_Y,
/* 22 */ ImGuiKey_U,
/* 23 */ ImGuiKey_I,
/* 24 */ ImGuiKey_O,
/* 25 */ ImGuiKey_P,
/* 26 */ ImGuiKey_LeftBracket,
/* 27 */ ImGuiKey_RightBracket,
/* 28 */ ImGuiKey_Enter,
/* 29 */ ImGuiKey_LeftCtrl,
/* 30 */ ImGuiKey_A,
/* 31 */ ImGuiKey_S,
/* 32 */ ImGuiKey_D,
/* 33 */ ImGuiKey_F,
/* 34 */ ImGuiKey_G,
/* 35 */ ImGuiKey_H,
/* 36 */ ImGuiKey_J,
/* 37 */ ImGuiKey_K,
/* 38 */ ImGuiKey_L,
/* 39 */ ImGuiKey_Semicolon,
/* 40 */ ImGuiKey_Apostrophe,
/* 41 */ ImGuiKey_GraveAccent,
/* 42 */ ImGuiKey_LeftShift,
/* 43 */ ImGuiKey_Backslash,
/* 44 */ ImGuiKey_Z,
/* 45 */ ImGuiKey_X,
/* 46 */ ImGuiKey_C,
/* 47 */ ImGuiKey_V,
/* 48 */ ImGuiKey_B,
/* 49 */ ImGuiKey_N,
/* 50 */ ImGuiKey_M,
/* 51 */ ImGuiKey_Comma,
/* 52 */ ImGuiKey_Period,
/* 53 */ ImGuiKey_Slash,
/* 54 */ ImGuiKey_RightShift,
/* 55 */ ImGuiKey_KeypadMultiply,
/* 56 */ ImGuiKey_LeftAlt,
/* 57 */ ImGuiKey_Space,
/* 58 */ ImGuiKey_CapsLock,
/* 59 */ ImGuiKey_F1,
/* 60 */ ImGuiKey_F2,
/* 61 */ ImGuiKey_F3,
/* 62 */ ImGuiKey_F4,
/* 63 */ ImGuiKey_F5,
/* 64 */ ImGuiKey_F6,
/* 65 */ ImGuiKey_F7,
/* 66 */ ImGuiKey_F8,
/* 67 */ ImGuiKey_F9,
/* 68 */ ImGuiKey_F10,
/* 69 */ ImGuiKey_NumLock,
/* 70 */ ImGuiKey_ScrollLock,
/* 71 */ ImGuiKey_Keypad7,
/* 72 */ ImGuiKey_Keypad8,
/* 73 */ ImGuiKey_Keypad9,
/* 74 */ ImGuiKey_KeypadSubtract,
/* 75 */ ImGuiKey_Keypad4,
/* 76 */ ImGuiKey_Keypad5,
/* 77 */ ImGuiKey_Keypad6,
/* 78 */ ImGuiKey_KeypadAdd,
/* 79 */ ImGuiKey_Keypad1,
/* 80 */ ImGuiKey_Keypad2,
/* 81 */ ImGuiKey_Keypad3,
/* 82 */ ImGuiKey_Keypad0,
/* 83 */ ImGuiKey_KeypadDecimal,
/* 84 */ ImGuiKey_RightAlt,
/* 85 */ ImGuiKey_None,
/* 86 */ ImGuiKey_Backslash,
/* 87 */ ImGuiKey_F11,
/* 88 */ ImGuiKey_F12,
/* 89 */ ImGuiKey_None,
/* 90 */ ImGuiKey_None,
/* 91 */ ImGuiKey_None,
/* 92 */ ImGuiKey_None,
/* 93 */ ImGuiKey_None,
/* 94 */ ImGuiKey_None,
/* 95 */ ImGuiKey_None,
/* 96 */ ImGuiKey_KeypadEnter,
/* 97 */ ImGuiKey_RightCtrl,
/* 98 */ ImGuiKey_KeypadDivide,
/* 99 */ ImGuiKey_PrintScreen,
/* 100 */ ImGuiKey_RightAlt,
/* 101 */ ImGuiKey_None,
/* 102 */ ImGuiKey_Home,
/* 103 */ ImGuiKey_UpArrow,
/* 104 */ ImGuiKey_PageUp,
/* 105 */ ImGuiKey_LeftArrow,
/* 106 */ ImGuiKey_RightArrow,
/* 107 */ ImGuiKey_End,
/* 108 */ ImGuiKey_DownArrow,
/* 109 */ ImGuiKey_PageDown,
/* 110 */ ImGuiKey_Insert,
/* 111 */ ImGuiKey_Delete,
/* 112 */ ImGuiKey_None,
/* 113 */ ImGuiKey_None,
/* 114 */ ImGuiKey_None,
/* 115 */ ImGuiKey_None,
/* 116 */ ImGuiKey_None,
/* 117 */ ImGuiKey_KeypadEqual,
/* 118 */ ImGuiKey_None,
/* 119 */ ImGuiKey_Pause,
/* 120 */ ImGuiKey_None,
/* 121 */ ImGuiKey_KeypadDecimal,
/* 122 */ ImGuiKey_None,
/* 123 */ ImGuiKey_None,
/* 124 */ ImGuiKey_None,
/* 125 */ ImGuiKey_LeftSuper,
/* 126 */ ImGuiKey_RightSuper,
/* 127 */ ImGuiKey_Menu,
};
static std::function<void()> s_redraw;
static RunQueue* s_mainThreadTasks;
@ -229,6 +360,12 @@ static xkb_keysym_t Compose( const xkb_keysym_t sym )
static void KeyboardKey( void*, struct wl_keyboard* kbd, uint32_t serial, uint32_t time, uint32_t key, uint32_t state )
{
auto& io = ImGui::GetIO();
if( key < ( sizeof( s_keyTable ) / sizeof( *s_keyTable ) ) )
{
io.AddKeyEvent( s_keyTable[key], state == WL_KEYBOARD_KEY_STATE_PRESSED );
}
if( state == WL_KEYBOARD_KEY_STATE_PRESSED )
{
const xkb_keysym_t* keysyms;