Don't enable relative mouse mode if in touchscreen mode (#14118)

This commit is contained in:
grorp 2024-01-13 20:01:10 +01:00 committed by GitHub
parent 59abf1bb42
commit b12be0498e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 23 deletions

@ -542,13 +542,13 @@ void ClientLauncher::main_menu(MainMenuData *menudata)
} }
infostream << "Waited for other menus" << std::endl; infostream << "Waited for other menus" << std::endl;
#ifndef ANDROID auto *cur_control = m_rendering_engine->get_raw_device()->getCursorControl();
if (cur_control) {
// Cursor can be non-visible when coming from the game // Cursor can be non-visible when coming from the game
m_rendering_engine->get_raw_device()->getCursorControl()->setVisible(true); cur_control->setVisible(true);
// Set absolute mouse mode // Set absolute mouse mode
m_rendering_engine->get_raw_device()->getCursorControl()->setRelativeMode(false); cur_control->setRelativeMode(false);
#endif }
/* show main menu */ /* show main menu */
GUIEngine mymenu(&input->joystick, guiroot, m_rendering_engine, &g_menumgr, menudata, *kill); GUIEngine mymenu(&input->joystick, guiroot, m_rendering_engine, &g_menumgr, menudata, *kill);

@ -2613,23 +2613,27 @@ void Game::checkZoomEnabled()
void Game::updateCameraDirection(CameraOrientation *cam, float dtime) void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
{ {
#ifndef __ANDROID__ auto *cur_control = device->getCursorControl();
if (isMenuActive())
device->getCursorControl()->setRelativeMode(false); /* With CIrrDeviceSDL on Linux and Windows, enabling relative mouse mode
else somehow results in simulated mouse events being generated from touch events,
device->getCursorControl()->setRelativeMode(true); 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 #endif
if ((device->isWindowActive() && device->isWindowFocused() if ((device->isWindowActive() && device->isWindowFocused()
&& !isMenuActive()) || input->isRandom()) { && !isMenuActive()) || input->isRandom()) {
#ifndef __ANDROID__ if (cur_control && !input->isRandom()) {
if (!input->isRandom()) {
// Mac OSX gets upset if this is set every frame // Mac OSX gets upset if this is set every frame
if (device->getCursorControl()->isVisible()) if (cur_control->isVisible())
device->getCursorControl()->setVisible(false); cur_control->setVisible(false);
} }
#endif
if (m_first_loop_after_window_activation) { if (m_first_loop_after_window_activation) {
m_first_loop_after_window_activation = false; m_first_loop_after_window_activation = false;
@ -2641,15 +2645,11 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
} }
} else { } else {
#ifndef ANDROID
// Mac OSX gets upset if this is set every frame // Mac OSX gets upset if this is set every frame
if (!device->getCursorControl()->isVisible()) if (cur_control && !cur_control->isVisible())
device->getCursorControl()->setVisible(true); cur_control->setVisible(true);
#endif
m_first_loop_after_window_activation = true; m_first_loop_after_window_activation = true;
} }
} }