diff --git a/Changes.txt b/Changes.txt
index aa88d0d7b..76ce4b1e2 100644
--- a/Changes.txt
+++ b/Changes.txt
@@ -25,6 +25,8 @@
- Added option to show/hide file extensions.
- Extended context menu and shortcuts.
+ * Added option to automatically pause emulation when focus is lost.
+
* Added option to toggle autofire mode.
* Added another oddball TIA glitch option for score mode color.
diff --git a/docs/graphics/options_emulation.png b/docs/graphics/options_emulation.png
index b924a7bbc..032ce6446 100644
Binary files a/docs/graphics/options_emulation.png and b/docs/graphics/options_emulation.png differ
diff --git a/docs/index.html b/docs/index.html
index 0c57d061f..9f5e23ff8 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -2854,6 +2854,11 @@
indicating serious errors override this setting, and are always
shown.
+
+ -autopause <1|0> |
+ Enable or disable automatic pause/continue of emulation, when
+ Stella loses/gains focus. |
+
-pausedim <1|0> |
Enable or disable emulation dimming in pause mode. |
@@ -3966,6 +3971,10 @@
Multi-threading | Enable multi-threaded rendering | -threads |
Fast SuperCharger load | Skip progress loading bars for SuperCharger ROMs | -fastscbios |
Show UI messages | Overlay UI messages onscreen | -uimessages |
+
+ Automatic pause | Enable or disable automatic pause/continue of emulation,
+ when Stella loses/gains focus. | -autopause
+ |
Confirm exiting... | Display a popup when emulation is exited | -confirmexit |
When entering/exiting emulation: |
diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx
index b41ddaab4..3640e1c8c 100644
--- a/src/emucore/EventHandler.cxx
+++ b/src/emucore/EventHandler.cxx
@@ -376,6 +376,15 @@ void EventHandler::handleSystemEvent(SystemEvent e, int, int)
enterMenuMode(EventHandlerState::OPTIONSMENU);
break;
#endif
+ case SystemEvent::WINDOW_FOCUS_GAINED:
+ if(myOSystem.settings().getBool("autopause") && myState == EventHandlerState::PAUSE)
+ setState(EventHandlerState::EMULATION);
+ break;
+ case SystemEvent::WINDOW_FOCUS_LOST:
+ if(myOSystem.settings().getBool("autopause") && myState == EventHandlerState::EMULATION)
+ setState(EventHandlerState::PAUSE);
+ break;
+
default: // handle other events as testing requires
// cerr << "handleSystemEvent: " << e << endl;
break;
diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx
index ec74d98da..ecec07215 100644
--- a/src/emucore/Settings.cxx
+++ b/src/emucore/Settings.cxx
@@ -184,6 +184,8 @@ Settings::Settings()
setPermanent("dialogfont", "medium");
setPermanent("dialogpos", 0);
setPermanent("confirmexit", false);
+ setPermanent("autopause", false);
+
// Misc options
setPermanent("loglevel", int(Logger::Level::INFO));
@@ -624,6 +626,7 @@ void Settings::usage() const
<< " large16>\n"
<< " -dialogpos <0..4> Display all dialogs at given positions\n"
<< " -confirmexit <0|1> Display a confirm dialog when exiting emulation\n"
+ << " -autopause <0|1> Pause/continue emulation when focus is lost/gained\n"
<< " -listdelay Time to wait between keypresses in list widgets\n"
<< " (300-1000)\n"
<< " -mwheel Number of lines the mouse wheel will scroll in\n"
diff --git a/src/gui/EmulationDialog.cxx b/src/gui/EmulationDialog.cxx
index a04ceb6e0..fab449f07 100644
--- a/src/gui/EmulationDialog.cxx
+++ b/src/gui/EmulationDialog.cxx
@@ -81,7 +81,7 @@ EmulationDialog::EmulationDialog(OSystem& osystem, DialogContainer& parent,
// Set real dimensions
_w = 37 * fontWidth + HBORDER * 2 + CheckboxWidget::prefixSize(_font);
- _h = 12 * (lineHeight + VGAP) + VGAP * 7 + VBORDER * 3 + _th + buttonHeight;
+ _h = 13 * (lineHeight + VGAP) + VGAP * 7 + VBORDER * 3 + _th + buttonHeight;
xpos = HBORDER; ypos = VBORDER + _th;
@@ -122,8 +122,14 @@ EmulationDialog::EmulationDialog(OSystem& osystem, DialogContainer& parent,
wid.push_back(myUIMessages);
ypos += lineHeight + VGAP;
- // Confirm dialog when exiting emulation
+ // Automatically pause emulation when focus is lost
xpos = HBORDER; ypos += VGAP * 3;
+ myAutoPauseWidget = new CheckboxWidget(this, _font, xpos, ypos, "Automatic pause");
+ myAutoPauseWidget->setToolTip("Check for automatic pause/continue of\nemulation when Stella loses/gains focus.");
+ wid.push_back(myAutoPauseWidget);
+
+ // Confirm dialog when exiting emulation
+ ypos += lineHeight + VGAP;
myConfirmExitWidget = new CheckboxWidget(this, _font, xpos, ypos, "Confirm exiting emulation");
wid.push_back(myConfirmExitWidget);
@@ -186,6 +192,9 @@ void EmulationDialog::loadConfig()
// Multi-threaded rendering
myUseThreads->setState(settings.getBool("threads"));
+ // Automatically pause emulation when focus is lost
+ myAutoPauseWidget->setState(settings.getBool("autopause"));
+
// Confirm dialog when exiting emulation
myConfirmExitWidget->setState(settings.getBool("confirmexit"));
@@ -222,6 +231,9 @@ void EmulationDialog::saveConfig()
// Multi-threaded rendering
settings.setValue("threads", myUseThreads->getState());
+ // Automatically pause emulation when focus is lost
+ settings.setValue("autopause", myAutoPauseWidget->getState());
+
// Confirm dialog when exiting emulation
settings.setValue("confirmexit", myConfirmExitWidget->getState());
@@ -254,6 +266,7 @@ void EmulationDialog::setDefaults()
myUIMessages->setState(true);
myFastSCBios->setState(true);
myUseThreads->setState(false);
+ myAutoPauseWidget->setState(false);
myConfirmExitWidget->setState(false);
mySaveOnExitGroup->setSelected(0);
diff --git a/src/gui/EmulationDialog.hxx b/src/gui/EmulationDialog.hxx
index 13603c5d3..fb736fe44 100644
--- a/src/gui/EmulationDialog.hxx
+++ b/src/gui/EmulationDialog.hxx
@@ -43,6 +43,7 @@ class EmulationDialog : public Dialog
CheckboxWidget* myUIMessages{nullptr};
CheckboxWidget* myFastSCBios{nullptr};
CheckboxWidget* myUseThreads{nullptr};
+ CheckboxWidget* myAutoPauseWidget{nullptr};
CheckboxWidget* myConfirmExitWidget{nullptr};
RadioButtonGroup* mySaveOnExitGroup{nullptr};
CheckboxWidget* myAutoSlotWidget{nullptr};