diff options
author | Kostadin Damyanov <maxmight@gmail.com> | 2015-07-12 00:52:47 +0300 |
---|---|---|
committer | Kostadin Damyanov <maxmight@gmail.com> | 2015-07-12 00:52:47 +0300 |
commit | 07e76a3f2ce85c996ddddce8e4e5180c7b948490 (patch) | |
tree | 69a8c87de6d498081b58070b94453fe0856e5f20 /platform/haiku | |
parent | 77e78cdb200b08a079b9d4047ea99227874ff3e1 (diff) |
Haiku: add keyboard support
Diffstat (limited to 'platform/haiku')
-rw-r--r-- | platform/haiku/SCsub | 3 | ||||
-rw-r--r-- | platform/haiku/haiku_direct_window.cpp | 84 | ||||
-rw-r--r-- | platform/haiku/haiku_direct_window.h | 2 | ||||
-rw-r--r-- | platform/haiku/key_mapping_haiku.cpp | 193 | ||||
-rw-r--r-- | platform/haiku/key_mapping_haiku.h | 13 |
5 files changed, 294 insertions, 1 deletions
diff --git a/platform/haiku/SCsub b/platform/haiku/SCsub index 18fa2e2b15..88c9b8b464 100644 --- a/platform/haiku/SCsub +++ b/platform/haiku/SCsub @@ -5,7 +5,8 @@ common_haiku = [ 'context_gl_haiku.cpp', 'haiku_application.cpp', 'haiku_direct_window.cpp', - 'haiku_gl_view.cpp' + 'haiku_gl_view.cpp', + 'key_mapping_haiku.cpp' ] env.Program( diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp index e400d70108..e7577602ca 100644 --- a/platform/haiku/haiku_direct_window.cpp +++ b/platform/haiku/haiku_direct_window.cpp @@ -1,5 +1,9 @@ +#include <UnicodeChar.h> + #include "main/main.h" +#include "os/keyboard.h" #include "haiku_direct_window.h" +#include "key_mapping_haiku.h" HaikuDirectWindow::HaikuDirectWindow(BRect p_frame) : BDirectWindow(p_frame, "Godot", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) @@ -79,6 +83,15 @@ void HaikuDirectWindow::DispatchMessage(BMessage* message, BHandler* handler) { HandleMouseWheelChanged(message); break; + case B_KEY_DOWN: + case B_KEY_UP: + HandleKeyboardEvent(message); + break; + + case B_MODIFIERS_CHANGED: + HandleKeyboardModifierEvent(message); + break; + case B_WINDOW_RESIZED: HandleWindowResized(message); //view->UnlockGL(); @@ -226,6 +239,77 @@ void HaikuDirectWindow::HandleMouseWheelChanged(BMessage* message) { input->parse_input_event(mouse_event); } +void HaikuDirectWindow::HandleKeyboardEvent(BMessage* message) { + message->PrintToStream(); + int32 raw_char = 0; + int32 key = 0; + int32 modifiers = 0; + + if (message->FindInt32("raw_char", &raw_char) != B_OK) { + return; + } + + if (message->FindInt32("key", &key) != B_OK) { + return; + } + + if (message->FindInt32("modifiers", &modifiers) != B_OK) { + return; + } + + InputEvent event; + event.ID = ++event_id; + event.type = InputEvent::KEY; + event.device = 0; + event.key.mod = GetKeyModifierState(modifiers); + event.key.pressed = (message->what == B_KEY_DOWN); + event.key.scancode = KeyMappingHaiku::get_keysym(raw_char, key); + event.key.echo = message->HasInt32("be:key_repeat"); + event.key.unicode = 0; + + const char* bytes = NULL; + if (message->FindString("bytes", &bytes) == B_OK) { + event.key.unicode = BUnicodeChar::FromUTF8(&bytes); + } + + //make it consistent accross platforms. + if (event.key.scancode==KEY_BACKTAB) { + event.key.scancode=KEY_TAB; + event.key.mod.shift=true; + } + + input->parse_input_event(event); +} + +void HaikuDirectWindow::HandleKeyboardModifierEvent(BMessage* message) { + message->PrintToStream(); + + int32 old_modifiers = 0; + int32 modifiers = 0; + + if (message->FindInt32("be:old_modifiers", &old_modifiers) != B_OK) { + return; + } + + if (message->FindInt32("modifiers", &modifiers) != B_OK) { + return; + } + + int32 key = old_modifiers ^ modifiers; + + InputEvent event; + event.ID = ++event_id; + event.type = InputEvent::KEY; + event.device = 0; + event.key.mod = GetKeyModifierState(modifiers); + event.key.pressed = ((modifiers & key) != 0); + event.key.scancode = KeyMappingHaiku::get_modifier_keysym(key); + event.key.echo = false; + event.key.unicode = 0; + + input->parse_input_event(event); +} + void HaikuDirectWindow::HandleWindowResized(BMessage* message) { int32 width = 0; int32 height = 0; diff --git a/platform/haiku/haiku_direct_window.h b/platform/haiku/haiku_direct_window.h index 3667eb24d1..7b1fd851fa 100644 --- a/platform/haiku/haiku_direct_window.h +++ b/platform/haiku/haiku_direct_window.h @@ -32,6 +32,8 @@ private: void HandleMouseMoved(BMessage* message); void HandleMouseWheelChanged(BMessage* message); void HandleWindowResized(BMessage* message); + void HandleKeyboardEvent(BMessage* message); + void HandleKeyboardModifierEvent(BMessage* message); inline InputModifierState GetKeyModifierState(uint32 p_state); inline int GetMouseButtonState(uint32 p_state); diff --git a/platform/haiku/key_mapping_haiku.cpp b/platform/haiku/key_mapping_haiku.cpp new file mode 100644 index 0000000000..d7bde9a727 --- /dev/null +++ b/platform/haiku/key_mapping_haiku.cpp @@ -0,0 +1,193 @@ +#include <InterfaceDefs.h> + +#include "key_mapping_haiku.h" +#include "os/keyboard.h" + +struct _HaikuTranslatePair { + unsigned int keysym; + int32 keycode; +}; + +static _HaikuTranslatePair _mod_to_keycode[] = { + { KEY_SHIFT, B_SHIFT_KEY }, + { KEY_ALT, B_COMMAND_KEY }, + { KEY_CONTROL, B_CONTROL_KEY }, + { KEY_CAPSLOCK, B_CAPS_LOCK }, + { KEY_SCROLLLOCK, B_SCROLL_LOCK }, + { KEY_NUMLOCK, B_NUM_LOCK }, + { KEY_SUPER_L, B_OPTION_KEY }, + { KEY_MENU, B_MENU_KEY }, + { KEY_SHIFT, B_LEFT_SHIFT_KEY }, + { KEY_SHIFT, B_RIGHT_SHIFT_KEY }, + { KEY_ALT, B_LEFT_COMMAND_KEY }, + { KEY_ALT, B_RIGHT_COMMAND_KEY }, + { KEY_CONTROL, B_LEFT_CONTROL_KEY }, + { KEY_CONTROL, B_RIGHT_CONTROL_KEY }, + { KEY_SUPER_L, B_LEFT_OPTION_KEY }, + { KEY_SUPER_R, B_RIGHT_OPTION_KEY }, + { KEY_UNKNOWN, 0 } +}; + +static _HaikuTranslatePair _fn_to_keycode[] = { + { KEY_F1, B_F1_KEY }, + { KEY_F2, B_F2_KEY }, + { KEY_F3, B_F3_KEY }, + { KEY_F4, B_F4_KEY }, + { KEY_F5, B_F5_KEY }, + { KEY_F6, B_F6_KEY }, + { KEY_F7, B_F7_KEY }, + { KEY_F8, B_F8_KEY }, + { KEY_F9, B_F9_KEY }, + { KEY_F10, B_F10_KEY }, + { KEY_F11, B_F11_KEY }, + { KEY_F12, B_F12_KEY }, + //{ KEY_F13, ? }, + //{ KEY_F14, ? }, + //{ KEY_F15, ? }, + //{ KEY_F16, ? }, + { KEY_PRINT, B_PRINT_KEY }, + { KEY_SCROLLLOCK, B_SCROLL_KEY }, + { KEY_PAUSE, B_PAUSE_KEY }, + { KEY_UNKNOWN, 0 } +}; + +static _HaikuTranslatePair _hb_to_keycode[] = { + { KEY_BACKSPACE, B_BACKSPACE }, + { KEY_TAB, B_TAB }, + { KEY_RETURN, B_RETURN }, + { KEY_CAPSLOCK, B_CAPS_LOCK }, + { KEY_ESCAPE, B_ESCAPE }, + { KEY_SPACE, B_SPACE }, + { KEY_PAGEUP, B_PAGE_UP }, + { KEY_PAGEDOWN, B_PAGE_DOWN }, + { KEY_END, B_END }, + { KEY_HOME, B_HOME }, + { KEY_LEFT, B_LEFT_ARROW }, + { KEY_UP, B_UP_ARROW }, + { KEY_RIGHT, B_RIGHT_ARROW }, + { KEY_DOWN, B_DOWN_ARROW }, + { KEY_PRINT, B_PRINT_KEY }, + { KEY_INSERT, B_INSERT }, + { KEY_DELETE, B_DELETE }, + // { KEY_HELP, ??? }, + + { KEY_0, (0x30) }, + { KEY_1, (0x31) }, + { KEY_2, (0x32) }, + { KEY_3, (0x33) }, + { KEY_4, (0x34) }, + { KEY_5, (0x35) }, + { KEY_6, (0x36) }, + { KEY_7, (0x37) }, + { KEY_8, (0x38) }, + { KEY_9, (0x39) }, + { KEY_A, (0x61) }, + { KEY_B, (0x62) }, + { KEY_C, (0x63) }, + { KEY_D, (0x64) }, + { KEY_E, (0x65) }, + { KEY_F, (0x66) }, + { KEY_G, (0x67) }, + { KEY_H, (0x68) }, + { KEY_I, (0x69) }, + { KEY_J, (0x6A) }, + { KEY_K, (0x6B) }, + { KEY_L, (0x6C) }, + { KEY_M, (0x6D) }, + { KEY_N, (0x6E) }, + { KEY_O, (0x6F) }, + { KEY_P, (0x70) }, + { KEY_Q, (0x71) }, + { KEY_R, (0x72) }, + { KEY_S, (0x73) }, + { KEY_T, (0x74) }, + { KEY_U, (0x75) }, + { KEY_V, (0x76) }, + { KEY_W, (0x77) }, + { KEY_X, (0x78) }, + { KEY_Y, (0x79) }, + { KEY_Z, (0x7A) }, + +/* +{ KEY_PLAY, VK_PLAY},// (0xFA) +{ KEY_STANDBY,VK_SLEEP },//(0x5F) +{ KEY_BACK,VK_BROWSER_BACK},// (0xA6) +{ KEY_FORWARD,VK_BROWSER_FORWARD},// (0xA7) +{ KEY_REFRESH,VK_BROWSER_REFRESH},// (0xA8) +{ KEY_STOP,VK_BROWSER_STOP},// (0xA9) +{ KEY_SEARCH,VK_BROWSER_SEARCH},// (0xAA) +{ KEY_FAVORITES, VK_BROWSER_FAVORITES},// (0xAB) +{ KEY_HOMEPAGE,VK_BROWSER_HOME},// (0xAC) +{ KEY_VOLUMEMUTE,VK_VOLUME_MUTE},// (0xAD) +{ KEY_VOLUMEDOWN,VK_VOLUME_DOWN},// (0xAE) +{ KEY_VOLUMEUP,VK_VOLUME_UP},// (0xAF) +{ KEY_MEDIANEXT,VK_MEDIA_NEXT_TRACK},// (0xB0) +{ KEY_MEDIAPREVIOUS,VK_MEDIA_PREV_TRACK},// (0xB1) +{ KEY_MEDIASTOP,VK_MEDIA_STOP},// (0xB2) +{ KEY_LAUNCHMAIL, VK_LAUNCH_MAIL},// (0xB4) +{ KEY_LAUNCHMEDIA,VK_LAUNCH_MEDIA_SELECT},// (0xB5) +{ KEY_LAUNCH0,VK_LAUNCH_APP1},// (0xB6) +{ KEY_LAUNCH1,VK_LAUNCH_APP2},// (0xB7) +*/ + + { KEY_SEMICOLON, 0x3B }, + { KEY_EQUAL, 0x3D }, + { KEY_COLON, 0x2C }, + { KEY_MINUS, 0x2D }, + { KEY_PERIOD, 0x2E }, + { KEY_SLASH, 0x2F }, + { KEY_KP_MULTIPLY, 0x2A }, + { KEY_KP_ADD, 0x2B }, + + { KEY_QUOTELEFT, 0x60 }, + { KEY_BRACKETLEFT, 0x5B }, + { KEY_BACKSLASH, 0x5C }, + { KEY_BRACKETRIGHT, 0x5D }, + { KEY_APOSTROPHE, 0x27 }, + + { KEY_UNKNOWN, 0 } +}; + +unsigned int KeyMappingHaiku::get_keysym(int32 raw_char, int32 key) { + if (raw_char == B_INSERT && key == 0x64) { return KEY_KP_0; } + if (raw_char == B_END && key == 0x58) { return KEY_KP_1; } + if (raw_char == B_DOWN_ARROW && key == 0x59) { return KEY_KP_2; } + if (raw_char == B_PAGE_DOWN && key == 0x5A) { return KEY_KP_3; } + if (raw_char == B_LEFT_ARROW && key == 0x48) { return KEY_KP_4; } + if (raw_char == 0x35 && key == 0x49) { return KEY_KP_5; } + if (raw_char == B_RIGHT_ARROW && key == 0x4A) { return KEY_KP_6; } + if (raw_char == B_HOME && key == 0x37) { return KEY_KP_7; } + if (raw_char == B_UP_ARROW && key == 0x38) { return KEY_KP_8; } + if (raw_char == B_PAGE_UP && key == 0x39) { return KEY_KP_9; } + if (raw_char == 0x2F && key == 0x23) { return KEY_KP_DIVIDE; } + if (raw_char == 0x2D && key == 0x25) { return KEY_KP_SUBSTRACT; } + if (raw_char == B_DELETE && key == 0x65) { return KEY_KP_PERIOD; } + + if (raw_char == 0x10) { + for(int i = 0; _fn_to_keycode[i].keysym != KEY_UNKNOWN; i++) { + if (_fn_to_keycode[i].keycode == key) { + return _fn_to_keycode[i].keysym; + } + } + + return KEY_UNKNOWN; + } + + for(int i = 0; _hb_to_keycode[i].keysym != KEY_UNKNOWN; i++) { + if (_hb_to_keycode[i].keycode == raw_char) { + return _hb_to_keycode[i].keysym; + } + } + + return KEY_UNKNOWN; +} + +unsigned int KeyMappingHaiku::get_modifier_keysym(int32 key) { + for(int i = 0; _mod_to_keycode[i].keysym != KEY_UNKNOWN; i++) { + if ((_mod_to_keycode[i].keycode & key) != 0) { + return _mod_to_keycode[i].keysym; + } + } + + return KEY_UNKNOWN; +} diff --git a/platform/haiku/key_mapping_haiku.h b/platform/haiku/key_mapping_haiku.h new file mode 100644 index 0000000000..e2864678a8 --- /dev/null +++ b/platform/haiku/key_mapping_haiku.h @@ -0,0 +1,13 @@ +#ifndef KEY_MAPPING_HAIKU_H +#define KEY_MAPPING_HAIKU_H + +class KeyMappingHaiku +{ + KeyMappingHaiku() {}; + +public: + static unsigned int get_keysym(int32 raw_char, int32 key); + static unsigned int get_modifier_keysym(int32 key); +}; + +#endif |