From 0bcc2f33ebe382a1dafbe6edaf00f476f2584b74 Mon Sep 17 00:00:00 2001
From: rubenwardy <rw@rubenwardy.com>
Date: Sun, 10 Sep 2017 03:17:47 +0100
Subject: Add check to pause game on lost window focus

---
 src/defaultsettings.cpp | 1 +
 src/game.cpp            | 7 +++++++
 2 files changed, 8 insertions(+)

(limited to 'src')

diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index 3bd4f4ac6..130bb4a19 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -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");
diff --git a/src/game.cpp b/src/game.cpp
index f7d4164ae..ac50e9aba 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -1487,6 +1487,8 @@ private:
 	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;
@@ -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();
+		}
 	}
 }
 
@@ -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");
 }
 
 /****************************************************************************/
-- 
cgit v1.2.3