mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-30 13:20:03 +00:00 
			
		
		
		
	Merge pull request #4930 from vitor-k/pause-on-unfocus
Pause when in background
This commit is contained in:
		
						commit
						377abfa3e6
					
				
					 6 changed files with 39 additions and 0 deletions
				
			
		|  | @ -388,6 +388,8 @@ void Config::ReadValues() { | |||
|     UISettings::values.first_start = ReadSetting("firstStart", true).toBool(); | ||||
|     UISettings::values.callout_flags = ReadSetting("calloutFlags", 0).toUInt(); | ||||
|     UISettings::values.show_console = ReadSetting("showConsole", false).toBool(); | ||||
|     UISettings::values.pause_when_in_background = | ||||
|         ReadSetting("pauseWhenInBackground", false).toBool(); | ||||
| 
 | ||||
|     qt_config->beginGroup("Multiplayer"); | ||||
|     UISettings::values.nickname = ReadSetting("nickname", "").toString(); | ||||
|  | @ -640,6 +642,7 @@ void Config::SaveValues() { | |||
|     WriteSetting("firstStart", UISettings::values.first_start, true); | ||||
|     WriteSetting("calloutFlags", UISettings::values.callout_flags, 0); | ||||
|     WriteSetting("showConsole", UISettings::values.show_console, false); | ||||
|     WriteSetting("pauseWhenInBackground", UISettings::values.pause_when_in_background, false); | ||||
| 
 | ||||
|     qt_config->beginGroup("Multiplayer"); | ||||
|     WriteSetting("nickname", UISettings::values.nickname, ""); | ||||
|  |  | |||
|  | @ -26,6 +26,7 @@ ConfigureGeneral::~ConfigureGeneral() = default; | |||
| 
 | ||||
| void ConfigureGeneral::SetConfiguration() { | ||||
|     ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing); | ||||
|     ui->toggle_background_pause->setChecked(UISettings::values.pause_when_in_background); | ||||
| 
 | ||||
|     ui->toggle_update_check->setChecked(UISettings::values.check_for_update_on_start); | ||||
|     ui->toggle_auto_update->setChecked(UISettings::values.update_on_close); | ||||
|  | @ -53,6 +54,7 @@ void ConfigureGeneral::ResetDefaults() { | |||
| 
 | ||||
| void ConfigureGeneral::ApplyConfiguration() { | ||||
|     UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); | ||||
|     UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked(); | ||||
| 
 | ||||
|     UISettings::values.check_for_update_on_start = ui->toggle_update_check->isChecked(); | ||||
|     UISettings::values.update_on_close = ui->toggle_auto_update->isChecked(); | ||||
|  |  | |||
|  | @ -29,6 +29,13 @@ | |||
|           </property> | ||||
|          </widget> | ||||
|         </item> | ||||
|         <item> | ||||
|          <widget class="QCheckBox" name="toggle_background_pause"> | ||||
|           <property name="text"> | ||||
|            <string>Pause emulation when in background</string> | ||||
|           </property> | ||||
|          </widget> | ||||
|         </item> | ||||
|        </layout> | ||||
|       </widget> | ||||
|      </item> | ||||
|  |  | |||
|  | @ -499,6 +499,24 @@ void GMainWindow::RestoreUIState() { | |||
|     statusBar()->setVisible(ui.action_Show_Status_Bar->isChecked()); | ||||
| } | ||||
| 
 | ||||
| void GMainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) { | ||||
|     if (!UISettings::values.pause_when_in_background) { | ||||
|         return; | ||||
|     } | ||||
|     if (state != Qt::ApplicationHidden && state != Qt::ApplicationInactive && | ||||
|         state != Qt::ApplicationActive) { | ||||
|         LOG_DEBUG(Frontend, "ApplicationState unusual flag: {} ", state); | ||||
|     } | ||||
|     if (ui.action_Pause->isEnabled() && | ||||
|         (state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) { | ||||
|         auto_paused = true; | ||||
|         OnPauseGame(); | ||||
|     } else if (ui.action_Start->isEnabled() && auto_paused && state == Qt::ApplicationActive) { | ||||
|         auto_paused = false; | ||||
|         OnStartGame(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void GMainWindow::ConnectWidgetEvents() { | ||||
|     connect(game_list, &GameList::GameChosen, this, &GMainWindow::OnGameListLoadFile); | ||||
|     connect(game_list, &GameList::OpenDirectory, this, &GMainWindow::OnGameListOpenDirectory); | ||||
|  | @ -2013,6 +2031,10 @@ int main(int argc, char* argv[]) { | |||
|     Core::System::GetInstance().RegisterSoftwareKeyboard(std::make_shared<QtKeyboard>(main_window)); | ||||
| 
 | ||||
|     main_window.show(); | ||||
| 
 | ||||
|     QObject::connect(&app, &QGuiApplication::applicationStateChanged, &main_window, | ||||
|                      &GMainWindow::OnAppFocusStateChanged); | ||||
| 
 | ||||
|     int result = app.exec(); | ||||
|     detached_tasks.WaitForAllTasks(); | ||||
|     return result; | ||||
|  |  | |||
|  | @ -68,6 +68,8 @@ public: | |||
|     GameList* game_list; | ||||
|     std::unique_ptr<DiscordRPC::DiscordInterface> discord_rpc; | ||||
| 
 | ||||
| public slots: | ||||
|     void OnAppFocusStateChanged(Qt::ApplicationState state); | ||||
| signals: | ||||
| 
 | ||||
|     /**
 | ||||
|  | @ -231,6 +233,8 @@ private: | |||
|     // The path to the game currently running
 | ||||
|     QString game_path; | ||||
| 
 | ||||
|     bool auto_paused = false; | ||||
| 
 | ||||
|     // Movie
 | ||||
|     bool movie_record_on_start = false; | ||||
|     QString movie_record_path; | ||||
|  |  | |||
|  | @ -74,6 +74,7 @@ struct Values { | |||
| 
 | ||||
|     bool confirm_before_closing; | ||||
|     bool first_start; | ||||
|     bool pause_when_in_background; | ||||
| 
 | ||||
|     bool updater_found; | ||||
|     bool update_on_close; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue