diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 1ea54589..f4adf85f 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -2558,7 +2558,7 @@ void titleinput(void) //In the menu system, all keypresses are single taps rather than holds. Therefore this test has to be done for all presses if (!game.press_action && !game.press_left && !game.press_right && !key.isDown(27) && !key.isDown(game.controllerButton_esc) - && !touch::button_tapped(TOUCH_BUTTON_CANCEL)) + && !touch::button_tapped(TOUCH_BUTTON_CANCEL) && !key.pressed_android_back) { game.jumpheld = false; } @@ -2568,7 +2568,7 @@ void titleinput(void) if (!game.jumpheld && graphics.fademode == FADE_NONE) { if (game.press_action || game.press_left || game.press_right || game.press_map || key.isDown(27) || key.isDown(game.controllerButton_esc) - || touch::button_tapped(TOUCH_BUTTON_CANCEL)) + || touch::button_tapped(TOUCH_BUTTON_CANCEL) || key.pressed_android_back) { game.jumpheld = true; } @@ -2587,7 +2587,7 @@ void titleinput(void) if (game.menustart && game.menucountdown <= 0 - && (key.isDown(27) || key.isDown(game.controllerButton_esc) || touch::button_tapped(TOUCH_BUTTON_CANCEL))) + && (key.isDown(27) || key.isDown(game.controllerButton_esc) || touch::button_tapped(TOUCH_BUTTON_CANCEL) || key.pressed_android_back)) { if (game.currentmenuname == Menu::language && loc::pre_title_lang_menu) { @@ -2607,8 +2607,16 @@ void titleinput(void) } else if (game.currentmenuname == Menu::mainmenu) { - game.createmenu(Menu::youwannaquit); - map.nexttowercolour(); + if (key.pressed_android_back) + { + // Minimize the game!!! (Android only) + SDL_MinimizeWindow(gameScreen.m_window); + } + else + { + game.createmenu(Menu::youwannaquit); + map.nexttowercolour(); + } } else { diff --git a/desktop_version/src/KeyPoll.cpp b/desktop_version/src/KeyPoll.cpp index 2585697c..3a66b23b 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -261,6 +261,8 @@ void KeyPoll::Poll(void) touch::reset(); + pressed_android_back = false; + while (SDL_PollEvent(&evt)) { switch (evt.type) @@ -275,6 +277,11 @@ void KeyPoll::Poll(void) pressedbackspace = true; } + if (evt.key.keysym.sym == SDLK_AC_BACK) + { + pressed_android_back = true; + } + #ifdef __APPLE__ /* OSX prefers the command keys over the alt keys. -flibit */ altpressed = keymap[SDLK_LGUI] || keymap[SDLK_RGUI]; #else @@ -625,9 +632,9 @@ void KeyPoll::Poll(void) case SDL_KEYDOWN: if (evt.key.keysym.sym != SDLK_AC_BACK) { - // If we hit the back button on Android, this doesn't mean we're not using touch using_touch = false; } + if (evt.key.repeat == 0) { hidemouse = true; diff --git a/desktop_version/src/KeyPoll.h b/desktop_version/src/KeyPoll.h index 4f69b3cf..37b0e9af 100644 --- a/desktop_version/src/KeyPoll.h +++ b/desktop_version/src/KeyPoll.h @@ -76,6 +76,7 @@ public: bool linealreadyemptykludge; bool using_touch; + bool pressed_android_back; private: std::map controllers; diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 64daee90..4e6c86a5 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -609,6 +609,9 @@ int main(int argc, char *argv[]) /* We already do the button swapping in ButtonGlyphs, disable SDL's swapping */ SDL_SetHintWithPriority(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0", SDL_HINT_OVERRIDE); + /* We want to capture back inputs */ + SDL_SetHintWithPriority(SDL_HINT_ANDROID_TRAP_BACK_BUTTON, "1", SDL_HINT_OVERRIDE); + if(!FILESYSTEM_init(argv[0], baseDir, assetsPath, langDir, fontsDir)) { vlog_error("Unable to initialize filesystem!");