From 6e9bf7b88a055247c01d4c25bfe172748aace9a6 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Mon, 27 Apr 2020 11:36:29 +0200 Subject: switch: send gui escape/cancel event on keyboard dismiss switch: add README-SWITCH.md --- README-SWITCH.md | 28 ++++++++++++++++++++++++++++ src/gui/sdlinput.cpp | 18 ++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 README-SWITCH.md diff --git a/README-SWITCH.md b/README-SWITCH.md new file mode 100644 index 000000000..35d732bf8 --- /dev/null +++ b/README-SWITCH.md @@ -0,0 +1,28 @@ +Switch button mapping: + +``` +KEY_A JButton1 +KEY_B JButton2 +KEY_X JButton3 +KEY_Y JButton4 +KEY_LSTICK JButton5 +KEY_RSTICK JButton6 +KEY_L JButton7 +KEY_R JButton8 +KEY_ZL JButton9 +KEY_ZR JButton10 +KEY_PLUS JButton11 +KEY_MINUS JButton12 +KEY_DLEFT JButton13 +KEY_DUP JButton14 +KEY_DRIGHT JButton15 +KEY_DDOWN JButton16 +KEY_LSTICK_LEFT JButton17 +KEY_LSTICK_UP JButton18 +KEY_LSTICK_RIGHT JButton19 +KEY_LSTICK_DOWN JButton20 +KEY_RSTICK_LEFT JButton21 +KEY_RSTICK_UP JButton22 +KEY_RSTICK_RIGHT JButton23 +KEY_RSTICK_DOWN JButton24 +``` \ No newline at end of file diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index 97ac0ac5e..b6fabd8a5 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -91,6 +91,10 @@ PRAGMA48(GCC diagnostic pop) #include "debug.h" +#ifdef __SWITCH__ +bool keyboardClosed = false; +#endif + extern volatile time_t cur_time; SDLInput *guiInput = nullptr; @@ -134,6 +138,20 @@ void SDLInput::pushInput(const SDL_Event &event) KeyInput keyInput; MouseInput mouseInput; +#ifdef __SWITCH__ + // send an escape/cancel key on keyboard dismiss event + bool visible = SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE; + if(visible) + { + keyboardClosed = false; + } + else if(!keyboardClosed) + { + simulateKey(KeyValue::ESCAPE, InputAction::GUI_CANCEL); + keyboardClosed = true; + } +#endif + switch (event.type) { case SDL_KEYDOWN: -- cgit v1.2.3-60-g2f50