From b12be0498e8a2386dd3cb616a9afac802be2ad5f Mon Sep 17 00:00:00 2001 From: grorp Date: Sat, 13 Jan 2024 20:01:10 +0100 Subject: [PATCH] Don't enable relative mouse mode if in touchscreen mode (#14118) --- src/client/clientlauncher.cpp | 14 +++++++------- src/client/game.cpp | 32 ++++++++++++++++---------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 80381dc6e..047338fef 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -542,13 +542,13 @@ void ClientLauncher::main_menu(MainMenuData *menudata) } infostream << "Waited for other menus" << std::endl; -#ifndef ANDROID - // Cursor can be non-visible when coming from the game - m_rendering_engine->get_raw_device()->getCursorControl()->setVisible(true); - - // Set absolute mouse mode - m_rendering_engine->get_raw_device()->getCursorControl()->setRelativeMode(false); -#endif + auto *cur_control = m_rendering_engine->get_raw_device()->getCursorControl(); + if (cur_control) { + // Cursor can be non-visible when coming from the game + cur_control->setVisible(true); + // Set absolute mouse mode + cur_control->setRelativeMode(false); + } /* show main menu */ GUIEngine mymenu(&input->joystick, guiroot, m_rendering_engine, &g_menumgr, menudata, *kill); diff --git a/src/client/game.cpp b/src/client/game.cpp index 0e9516dcb..1c06aab47 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2613,23 +2613,27 @@ void Game::checkZoomEnabled() void Game::updateCameraDirection(CameraOrientation *cam, float dtime) { -#ifndef __ANDROID__ - if (isMenuActive()) - device->getCursorControl()->setRelativeMode(false); - else - device->getCursorControl()->setRelativeMode(true); + auto *cur_control = device->getCursorControl(); + + /* With CIrrDeviceSDL on Linux and Windows, enabling relative mouse mode + somehow results in simulated mouse events being generated from touch events, + although SDL_HINT_MOUSE_TOUCH_EVENTS and SDL_HINT_TOUCH_MOUSE_EVENTS are set to 0. + Since Minetest has its own code to synthesize mouse events from touch events, + this results in duplicated input. To avoid that, we don't enable relative + mouse mode if we're in touchscreen mode. */ +#ifndef HAVE_TOUCHSCREENGUI + if (cur_control) + cur_control->setRelativeMode(!isMenuActive()); #endif if ((device->isWindowActive() && device->isWindowFocused() && !isMenuActive()) || input->isRandom()) { -#ifndef __ANDROID__ - if (!input->isRandom()) { + if (cur_control && !input->isRandom()) { // Mac OSX gets upset if this is set every frame - if (device->getCursorControl()->isVisible()) - device->getCursorControl()->setVisible(false); + if (cur_control->isVisible()) + cur_control->setVisible(false); } -#endif if (m_first_loop_after_window_activation) { m_first_loop_after_window_activation = false; @@ -2641,15 +2645,11 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime) } } else { - -#ifndef ANDROID // Mac OSX gets upset if this is set every frame - if (!device->getCursorControl()->isVisible()) - device->getCursorControl()->setVisible(true); -#endif + if (cur_control && !cur_control->isVisible()) + cur_control->setVisible(true); m_first_loop_after_window_activation = true; - } }