Skip to content

Commit

Permalink
Don't enable relative mouse mode if in touchscreen mode (#14118)
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp authored Jan 13, 2024
1 parent 59abf1b commit b12be04
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
14 changes: 7 additions & 7 deletions src/client/clientlauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 16 additions & 16 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

}
}

Expand Down

0 comments on commit b12be04

Please sign in to comment.