Skip to content

Commit

Permalink
Add check to pause game on lost window focus
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy authored and paramat committed Dec 26, 2017
1 parent 2153965 commit 0bcc2f3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions builtin/settingtypes.txt
Expand Up @@ -536,6 +536,9 @@ fps_max (Maximum FPS) int 60
# Maximum FPS when game is paused.
pause_fps_max (FPS in pause menu) int 20

# Open the pause menu when the window's focus is lost. Does not pause if a formspec is open.
pause_on_lost_focus (Pause on lost window focus) bool false

# View distance in nodes.
viewing_range (Viewing range) int 100 20 4000

Expand Down
4 changes: 4 additions & 0 deletions minetest.conf.example
Expand Up @@ -994,6 +994,10 @@
# type: int
# max_out_chat_queue_size = 20

# Open the pause menu when the window's focus is lost. Does not pause if a formspec is open.
# type: bool
# pause_on_lost_focus = false

## Advanced

# Timeout for client to remove unused map data from memory.
Expand Down
1 change: 1 addition & 0 deletions src/defaultsettings.cpp
Expand Up @@ -58,6 +58,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("enable_remote_media_server", "true");
settings->setDefault("enable_client_modding", "false");
settings->setDefault("max_out_chat_queue_size", "20");
settings->setDefault("pause_on_lost_focus", "false");

// Keymap
settings->setDefault("remote_port", "30000");
Expand Down
7 changes: 7 additions & 0 deletions src/game.cpp
Expand Up @@ -1487,6 +1487,8 @@ class Game {
bool m_first_loop_after_window_activation = false;
bool m_camera_offset_changed = false;

bool m_does_lost_focus_pause_game = false;

#ifdef __ANDROID__
bool m_cache_hold_aux1;
bool m_android_chat_open;
Expand Down Expand Up @@ -1741,6 +1743,10 @@ void Game::run()

// Update if minimap has been disabled by the server
flags.show_minimap &= client->shouldShowMinimap();

if (m_does_lost_focus_pause_game && !device->isWindowFocused() && !isMenuActive()) {
showPauseMenu();
}
}
}

Expand Down Expand Up @@ -4638,6 +4644,7 @@ void Game::readSettings()
m_cache_cam_smoothing = rangelim(m_cache_cam_smoothing, 0.01f, 1.0f);
m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);

m_does_lost_focus_pause_game = g_settings->getBool("pause_on_lost_focus");
}

/****************************************************************************/
Expand Down

0 comments on commit 0bcc2f3

Please sign in to comment.