Skip to content

Commit 0bcc2f3

Browse files
rubenwardyparamat
authored andcommittedDec 26, 2017
Add check to pause game on lost window focus
1 parent 2153965 commit 0bcc2f3

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed
 

Diff for: ‎builtin/settingtypes.txt

+3
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@ fps_max (Maximum FPS) int 60
536536
# Maximum FPS when game is paused.
537537
pause_fps_max (FPS in pause menu) int 20
538538

539+
# Open the pause menu when the window's focus is lost. Does not pause if a formspec is open.
540+
pause_on_lost_focus (Pause on lost window focus) bool false
541+
539542
# View distance in nodes.
540543
viewing_range (Viewing range) int 100 20 4000
541544

Diff for: ‎minetest.conf.example

+4
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,10 @@
994994
# type: int
995995
# max_out_chat_queue_size = 20
996996

997+
# Open the pause menu when the window's focus is lost. Does not pause if a formspec is open.
998+
# type: bool
999+
# pause_on_lost_focus = false
1000+
9971001
## Advanced
9981002

9991003
# Timeout for client to remove unused map data from memory.

Diff for: ‎src/defaultsettings.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void set_default_settings(Settings *settings)
5858
settings->setDefault("enable_remote_media_server", "true");
5959
settings->setDefault("enable_client_modding", "false");
6060
settings->setDefault("max_out_chat_queue_size", "20");
61+
settings->setDefault("pause_on_lost_focus", "false");
6162

6263
// Keymap
6364
settings->setDefault("remote_port", "30000");

Diff for: ‎src/game.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,8 @@ class Game {
14871487
bool m_first_loop_after_window_activation = false;
14881488
bool m_camera_offset_changed = false;
14891489

1490+
bool m_does_lost_focus_pause_game = false;
1491+
14901492
#ifdef __ANDROID__
14911493
bool m_cache_hold_aux1;
14921494
bool m_android_chat_open;
@@ -1741,6 +1743,10 @@ void Game::run()
17411743

17421744
// Update if minimap has been disabled by the server
17431745
flags.show_minimap &= client->shouldShowMinimap();
1746+
1747+
if (m_does_lost_focus_pause_game && !device->isWindowFocused() && !isMenuActive()) {
1748+
showPauseMenu();
1749+
}
17441750
}
17451751
}
17461752

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

4647+
m_does_lost_focus_pause_game = g_settings->getBool("pause_on_lost_focus");
46414648
}
46424649

46434650
/****************************************************************************/

0 commit comments

Comments
 (0)