diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 1d691273..49b1c9d2 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -2552,7 +2552,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; } @@ -2562,7 +2562,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; } @@ -2581,7 +2581,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) { @@ -2601,8 +2601,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 bba1df8e..816560e2 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -252,6 +252,8 @@ void KeyPoll::Poll(void) touch::reset(); + pressed_android_back = false; + while (SDL_PollEvent(&evt)) { switch (evt.type) @@ -266,6 +268,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 @@ -605,9 +612,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 aaa939f4..dc4de326 100644 --- a/desktop_version/src/KeyPoll.h +++ b/desktop_version/src/KeyPoll.h @@ -73,6 +73,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 6da8aea4..6eeee1b6 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -567,6 +567,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!");