SDL: Add ability to suspend screensaver

This commit is contained in:
Jeffrey Pfau 2015-05-05 22:43:44 -07:00
parent 1b74517e8b
commit b079c3bd56
12 changed files with 430 additions and 319 deletions

View File

@ -14,6 +14,7 @@ Features:
- Remappable controls for tilt and gyroscope sensors - Remappable controls for tilt and gyroscope sensors
- Status messages for actions taken while a game is running (e.g. save/load state) - Status messages for actions taken while a game is running (e.g. save/load state)
- Memory inspector - Memory inspector
- Screensaver can now be suspended while a game is running
Bugfixes: Bugfixes:
- GBA: Fix timers not updating timing when writing to only the reload register - GBA: Fix timers not updating timing when writing to only the reload register
- All: Fix sanitize-deb script not cleaning up after itself - All: Fix sanitize-deb script not cleaning up after itself

View File

@ -204,6 +204,9 @@ void GBAConfigMap(const struct GBAConfig* config, struct GBAOptions* opts) {
if (_lookupIntValue(config, "resampleVideo", &fakeBool)) { if (_lookupIntValue(config, "resampleVideo", &fakeBool)) {
opts->resampleVideo = fakeBool; opts->resampleVideo = fakeBool;
} }
if (_lookupIntValue(config, "suspendScreensaver", &fakeBool)) {
opts->suspendScreensaver = fakeBool;
}
if (_lookupIntValue(config, "mute", &fakeBool)) { if (_lookupIntValue(config, "mute", &fakeBool)) {
opts->mute = fakeBool; opts->mute = fakeBool;
} }
@ -251,6 +254,7 @@ void GBAConfigLoadDefaults(struct GBAConfig* config, const struct GBAOptions* op
ConfigurationSetIntValue(&config->defaultsTable, 0, "mute", opts->mute); ConfigurationSetIntValue(&config->defaultsTable, 0, "mute", opts->mute);
ConfigurationSetIntValue(&config->defaultsTable, 0, "lockAspectRatio", opts->lockAspectRatio); ConfigurationSetIntValue(&config->defaultsTable, 0, "lockAspectRatio", opts->lockAspectRatio);
ConfigurationSetIntValue(&config->defaultsTable, 0, "resampleVideo", opts->resampleVideo); ConfigurationSetIntValue(&config->defaultsTable, 0, "resampleVideo", opts->resampleVideo);
ConfigurationSetIntValue(&config->defaultsTable, 0, "suspendScreensaver", opts->suspendScreensaver);
switch (opts->idleOptimization) { switch (opts->idleOptimization) {
case IDLE_LOOP_IGNORE: case IDLE_LOOP_IGNORE:

View File

@ -35,6 +35,7 @@ struct GBAOptions {
int height; int height;
bool lockAspectRatio; bool lockAspectRatio;
bool resampleVideo; bool resampleVideo;
bool suspendScreensaver;
int volume; int volume;
bool mute; bool mute;

View File

@ -114,6 +114,7 @@ ConfigController::ConfigController(QObject* parent)
m_opts.rewindBufferInterval = 0; m_opts.rewindBufferInterval = 0;
m_opts.rewindBufferCapacity = 0; m_opts.rewindBufferCapacity = 0;
m_opts.useBios = true; m_opts.useBios = true;
m_opts.suspendScreensaver = true;
GBAConfigLoadDefaults(&m_config, &m_opts); GBAConfigLoadDefaults(&m_config, &m_opts);
GBAConfigLoad(&m_config); GBAConfigLoad(&m_config);
GBAConfigMap(&m_config, &m_opts); GBAConfigMap(&m_config, &m_opts);

View File

@ -469,3 +469,17 @@ void InputController::clearPendingEvent(GBAKey key) {
bool InputController::hasPendingEvent(GBAKey key) const { bool InputController::hasPendingEvent(GBAKey key) const {
return m_pendingEvents.contains(key); return m_pendingEvents.contains(key);
} }
#if defined(BUILD_SDL) && SDL_VERSION_ATLEAST(2, 0, 0)
void InputController::suspendScreensaver() {
GBASDLSuspendScreensaver(&s_sdlEvents);
}
void InputController::resumeScreensaver() {
GBASDLResumeScreensaver(&s_sdlEvents);
}
void InputController::setScreensaverSuspendable(bool suspendable) {
GBASDLSetScreensaverSuspendable(&s_sdlEvents, suspendable);
}
#endif

View File

@ -80,6 +80,13 @@ public:
public slots: public slots:
void testGamepad(int type); void testGamepad(int type);
#if defined(BUILD_SDL) && SDL_VERSION_ATLEAST(2, 0, 0)
// TODO: Move these to somewhere that makes sense
void suspendScreensaver();
void resumeScreensaver();
void setScreensaverSuspendable(bool);
#endif
private: private:
void postPendingEvent(GBAKey); void postPendingEvent(GBAKey);
void clearPendingEvent(GBAKey); void clearPendingEvent(GBAKey);

View File

@ -34,6 +34,7 @@ SettingsView::SettingsView(ConfigController* controller, QWidget* parent)
loadSetting("rewindBufferCapacity", m_ui.rewindCapacity); loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
loadSetting("resampleVideo", m_ui.resampleVideo); loadSetting("resampleVideo", m_ui.resampleVideo);
loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections); loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
loadSetting("suspendScreensaver", m_ui.suspendScreensaver);
QString idleOptimization = loadSetting("idleOptimization"); QString idleOptimization = loadSetting("idleOptimization");
if (idleOptimization == "ignore") { if (idleOptimization == "ignore") {
@ -87,6 +88,7 @@ void SettingsView::updateConfig() {
saveSetting("rewindBufferCapacity", m_ui.rewindCapacity); saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);
saveSetting("resampleVideo", m_ui.resampleVideo); saveSetting("resampleVideo", m_ui.resampleVideo);
saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections); saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) { switch (m_ui.idleOptimization->currentIndex() + IDLE_LOOP_IGNORE) {
case IDLE_LOOP_IGNORE: case IDLE_LOOP_IGNORE:

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>374</width> <width>656</width>
<height>608</height> <height>366</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -21,21 +21,21 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QFormLayout" name="formLayout"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="fieldGrowthPolicy"> <item>
<enum>QFormLayout::ExpandingFieldsGrow</enum> <layout class="QFormLayout" name="formLayout">
</property> <property name="fieldGrowthPolicy">
<item row="0" column="0"> <enum>QFormLayout::ExpandingFieldsGrow</enum>
<widget class="QLabel" name="label">
<property name="text">
<string>BIOS file:</string>
</property> </property>
</widget> <item row="0" column="0">
</item> <widget class="QLabel" name="label_14">
<item row="0" column="1"> <property name="text">
<layout class="QHBoxLayout" name="horizontalLayout"> <string>Audio driver:</string>
<item> </property>
<widget class="QLineEdit" name="bios"> </widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="audioDriver">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -44,346 +44,371 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="1" column="0">
<widget class="QPushButton" name="biosBrowse"> <widget class="QLabel" name="audioBufferSizeLabel">
<property name="text"> <property name="text">
<string>Browse</string> <string>Audio buffer:</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> <item row="1" column="1">
</item> <layout class="QHBoxLayout" name="horizontalLayout_11">
<item row="1" column="1">
<widget class="QCheckBox" name="skipBios">
<property name="text">
<string>Skip BIOS intro</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="useBios">
<property name="text">
<string>Use BIOS file</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Audio driver:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="audioDriver">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="audioBufferSizeLabel">
<property name="text">
<string>Audio buffer:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QComboBox" name="audioBufferSize">
<property name="editable">
<bool>true</bool>
</property>
<property name="currentText">
<string>2048</string>
</property>
<property name="currentIndex">
<number>2</number>
</property>
<item> <item>
<property name="text"> <widget class="QComboBox" name="audioBufferSize">
<string>512</string> <property name="editable">
</property> <bool>true</bool>
</property>
<property name="currentText">
<string>2048</string>
</property>
<property name="currentIndex">
<number>2</number>
</property>
<item>
<property name="text">
<string>512</string>
</property>
</item>
<item>
<property name="text">
<string>1024</string>
</property>
</item>
<item>
<property name="text">
<string>2048</string>
</property>
</item>
<item>
<property name="text">
<string>4096</string>
</property>
</item>
</widget>
</item> </item>
<item> <item>
<property name="text"> <widget class="QLabel" name="label_16">
<string>1024</string> <property name="text">
</property> <string>samples</string>
</property>
</widget>
</item> </item>
<item> </layout>
<property name="text">
<string>2048</string>
</property>
</item>
<item>
<property name="text">
<string>4096</string>
</property>
</item>
</widget>
</item> </item>
<item> <item row="2" column="0">
<widget class="QLabel" name="label_10"> <widget class="QLabel" name="label_17">
<property name="text"> <property name="text">
<string>samples</string> <string>Volume:</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> <item row="2" column="1">
</item> <layout class="QHBoxLayout" name="horizontalLayout_6">
<item row="6" column="0"> <item>
<widget class="QLabel" name="label_16"> <widget class="QSlider" name="volume">
<property name="text"> <property name="maximum">
<string>Volume:</string> <number>256</number>
</property> </property>
</widget> <property name="pageStep">
</item> <number>16</number>
<item row="6" column="1"> </property>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <property name="value">
<item> <number>256</number>
<widget class="QSlider" name="volume"> </property>
<property name="maximum"> <property name="orientation">
<number>256</number> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="pageStep"> </widget>
<number>16</number> </item>
</property> <item>
<property name="value"> <widget class="QCheckBox" name="mute">
<number>256</number> <property name="text">
</property> <string>Mute</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="4" column="0">
<widget class="QCheckBox" name="mute"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Mute</string> <string>Sync:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QCheckBox" name="videoSync">
<property name="text">
<string>Video</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="audioSync">
<property name="text">
<string>Audio</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Frameskip:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Skip every</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="frameskip"/>
</item>
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>frames</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>FPS target:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSpinBox" name="fpsTarget">
<property name="maximum">
<number>240</number>
</property>
<property name="value">
<number>60</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>frames per second</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0" colspan="2">
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="lockAspectRatio">
<property name="text">
<string>Lock aspect ratio</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QCheckBox" name="resampleVideo">
<property name="text">
<string>Resample video</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QCheckBox" name="suspendScreensaver">
<property name="text">
<string>Suspend screensaver</string>
</property>
<property name="checked">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item row="7" column="0" colspan="2"> <item>
<widget class="Line" name="line"> <widget class="Line" name="line_5">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Vertical</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="0"> <item>
<widget class="QLabel" name="label_2"> <layout class="QFormLayout" name="formLayout_4">
<property name="text"> <item row="0" column="0">
<string>Sync:</string> <widget class="QLabel" name="label">
</property>
</widget>
</item>
<item row="8" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QCheckBox" name="videoSync">
<property name="text"> <property name="text">
<string>Video</string> <string>BIOS file:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="1">
<widget class="QCheckBox" name="audioSync"> <layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="bios">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="biosBrowse">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="skipBios">
<property name="text"> <property name="text">
<string>Audio</string> <string>Skip BIOS intro</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1">
<widget class="QCheckBox" name="useBios">
<property name="text">
<string>Use BIOS file</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="rewind">
<property name="text">
<string>Enable rewind</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Rewind interval:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Every</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="rewindInterval"/>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>frames</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Rewind length:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QSpinBox" name="rewindCapacity"/>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>intervals</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0" colspan="2">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="allowOpposingDirections">
<property name="text">
<string>Allow opposing input directions</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Idle loops</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QComboBox" name="idleOptimization">
<item>
<property name="text">
<string>Run all</string>
</property>
</item>
<item>
<property name="text">
<string>Remove known</string>
</property>
</item>
<item>
<property name="text">
<string>Detect and remove</string>
</property>
</item>
</widget>
</item>
</layout> </layout>
</item> </item>
<item row="9" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Frameskip:</string>
</property>
</widget>
</item>
<item row="9" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Skip every</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="frameskip"/>
</item>
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>frames</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>FPS target:</string>
</property>
</widget>
</item>
<item row="10" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSpinBox" name="fpsTarget">
<property name="maximum">
<number>240</number>
</property>
<property name="value">
<number>60</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>frames per second</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="11" column="1">
<widget class="QCheckBox" name="lockAspectRatio">
<property name="text">
<string>Lock aspect ratio</string>
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QCheckBox" name="resampleVideo">
<property name="text">
<string>Resample video</string>
</property>
</widget>
</item>
<item row="13" column="0" colspan="2">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="14" column="1">
<widget class="QCheckBox" name="rewind">
<property name="text">
<string>Enable rewind</string>
</property>
</widget>
</item>
<item row="15" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Rewind interval:</string>
</property>
</widget>
</item>
<item row="15" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Every</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="rewindInterval"/>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>frames</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="16" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Rewind length:</string>
</property>
</widget>
</item>
<item row="16" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QSpinBox" name="rewindCapacity"/>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>intervals</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="17" column="1">
<widget class="QCheckBox" name="allowOpposingDirections">
<property name="text">
<string>Allow opposing input directions</string>
</property>
</widget>
</item>
<item row="18" column="0" colspan="2">
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="19" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Idle loops</string>
</property>
</widget>
</item>
<item row="19" column="1">
<widget class="QComboBox" name="idleOptimization">
<item>
<property name="text">
<string>Run all</string>
</property>
</item>
<item>
<property name="text">
<string>Remove known</string>
</property>
</item>
<item>
<property name="text">
<string>Detect and remove</string>
</property>
</item>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>

View File

@ -89,8 +89,10 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
} }
connect(m_controller, SIGNAL(gameStarted(GBAThread*)), this, SLOT(gameStarted(GBAThread*))); connect(m_controller, SIGNAL(gameStarted(GBAThread*)), this, SLOT(gameStarted(GBAThread*)));
connect(m_controller, SIGNAL(gameStarted(GBAThread*)), &m_inputController, SLOT(suspendScreensaver()));
connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_display, SLOT(stopDrawing())); connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_display, SLOT(stopDrawing()));
connect(m_controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped())); connect(m_controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped()));
connect(m_controller, SIGNAL(gameStopped(GBAThread*)), &m_inputController, SLOT(resumeScreensaver()));
connect(m_controller, SIGNAL(stateLoaded(GBAThread*)), m_display, SLOT(forceDraw())); connect(m_controller, SIGNAL(stateLoaded(GBAThread*)), m_display, SLOT(forceDraw()));
connect(m_controller, SIGNAL(rewound(GBAThread*)), m_display, SLOT(forceDraw())); connect(m_controller, SIGNAL(rewound(GBAThread*)), m_display, SLOT(forceDraw()));
connect(m_controller, SIGNAL(gamePaused(GBAThread*)), m_display, SLOT(pauseDrawing())); connect(m_controller, SIGNAL(gamePaused(GBAThread*)), m_display, SLOT(pauseDrawing()));
@ -102,7 +104,9 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
} }
}); });
#endif #endif
connect(m_controller, SIGNAL(gamePaused(GBAThread*)), &m_inputController, SLOT(resumeScreensaver()));
connect(m_controller, SIGNAL(gameUnpaused(GBAThread*)), m_display, SLOT(unpauseDrawing())); connect(m_controller, SIGNAL(gameUnpaused(GBAThread*)), m_display, SLOT(unpauseDrawing()));
connect(m_controller, SIGNAL(gameUnpaused(GBAThread*)), &m_inputController, SLOT(suspendScreensaver()));
connect(m_controller, SIGNAL(postLog(int, const QString&)), m_logView, SLOT(postLog(int, const QString&))); connect(m_controller, SIGNAL(postLog(int, const QString&)), m_logView, SLOT(postLog(int, const QString&)));
connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(recordFrame())); connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(recordFrame()));
connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), m_display, SLOT(framePosted(const uint32_t*))); connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), m_display, SLOT(framePosted(const uint32_t*)));
@ -192,6 +196,8 @@ void Window::loadConfig() {
enterFullScreen(); enterFullScreen();
} }
m_inputController.setScreensaverSuspendable(opts->suspendScreensaver);
m_mruFiles = m_config->getMRU(); m_mruFiles = m_config->getMRU();
updateMRU(); updateMRU();

View File

@ -117,6 +117,11 @@ int main(int argc, char** argv) {
GBASDLPlayerLoadConfig(&renderer.player, GBAConfigGetInput(&config)); GBASDLPlayerLoadConfig(&renderer.player, GBAConfigGetInput(&config));
context.overrides = GBAConfigGetOverrides(&config); context.overrides = GBAConfigGetOverrides(&config);
#if SDL_VERSION_ATLEAST(2, 0, 0)
GBASDLSetScreensaverSuspendable(&renderer.events, opts.suspendScreensaver);
GBASDLSuspendScreensaver(&renderer.events);
#endif
int didFail = 0; int didFail = 0;
if (GBAThreadStart(&context)) { if (GBAThreadStart(&context)) {
renderer.runloop(&context, &renderer); renderer.runloop(&context, &renderer);
@ -126,6 +131,11 @@ int main(int argc, char** argv) {
printf("Could not run game. Are you sure the file exists and is a Game Boy Advance game?\n"); printf("Could not run game. Are you sure the file exists and is a Game Boy Advance game?\n");
} }
#if SDL_VERSION_ATLEAST(2, 0, 0)
GBASDLResumeScreensaver(&renderer.events);
GBASDLSetScreensaverSuspendable(&renderer.events, false);
#endif
if (GBAThreadHasCrashed(&context)) { if (GBAThreadHasCrashed(&context)) {
didFail = 1; didFail = 1;
printf("The game crashed!\n"); printf("The game crashed!\n");

View File

@ -32,7 +32,7 @@ static void _GBASDLRotationSample(struct GBARotationSource* source);
bool GBASDLInitEvents(struct GBASDLEvents* context) { bool GBASDLInitEvents(struct GBASDLEvents* context) {
int subsystem = SDL_INIT_JOYSTICK; int subsystem = SDL_INIT_JOYSTICK;
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
subsystem |= SDL_INIT_HAPTIC; subsystem |= SDL_INIT_HAPTIC | SDL_INIT_VIDEO;
#endif #endif
if (SDL_InitSubSystem(subsystem) < 0) { if (SDL_InitSubSystem(subsystem) < 0) {
return false; return false;
@ -68,6 +68,8 @@ bool GBASDLInitEvents(struct GBASDLEvents* context) {
#if !SDL_VERSION_ATLEAST(2, 0, 0) #if !SDL_VERSION_ATLEAST(2, 0, 0)
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
#else
context->screensaverSuspendDepth = 0;
#endif #endif
return true; return true;
} }
@ -582,3 +584,33 @@ static void _GBASDLRotationSample(struct GBARotationSource* source) {
CircleBufferWrite32(&rotation->zHistory, theta.i); CircleBufferWrite32(&rotation->zHistory, theta.i);
rotation->zDelta += theta.f - oldZ; rotation->zDelta += theta.f - oldZ;
} }
#if SDL_VERSION_ATLEAST(2, 0, 0)
void GBASDLSuspendScreensaver(struct GBASDLEvents* events) {
if (events->screensaverSuspendDepth == 0 && events->screensaverSuspendable) {
SDL_DisableScreenSaver();
}
++events->screensaverSuspendDepth;
}
void GBASDLResumeScreensaver(struct GBASDLEvents* events) {
--events->screensaverSuspendDepth;
if (events->screensaverSuspendDepth == 0 && events->screensaverSuspendable) {
SDL_EnableScreenSaver();
}
}
void GBASDLSetScreensaverSuspendable(struct GBASDLEvents* events, bool suspendable) {
bool wasSuspendable = events->screensaverSuspendable;
events->screensaverSuspendable = suspendable;
if (events->screensaverSuspendDepth > 0) {
if (suspendable && !wasSuspendable) {
SDL_DisableScreenSaver();
} else if (!suspendable && wasSuspendable) {
SDL_EnableScreenSaver();
}
} else {
SDL_EnableScreenSaver();
}
}
#endif

View File

@ -29,6 +29,8 @@ struct GBASDLEvents {
size_t joysticksClaimed[MAX_PLAYERS]; size_t joysticksClaimed[MAX_PLAYERS];
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Haptic** haptic; SDL_Haptic** haptic;
int screensaverSuspendDepth;
bool screensaverSuspendable;
#endif #endif
}; };
@ -82,4 +84,10 @@ void GBASDLPlayerSaveConfig(const struct GBASDLPlayer*, struct Configuration*);
void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const union SDL_Event* event); void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLPlayer* sdlContext, const union SDL_Event* event);
#if SDL_VERSION_ATLEAST(2, 0, 0)
void GBASDLSuspendScreensaver(struct GBASDLEvents*);
void GBASDLResumeScreensaver(struct GBASDLEvents*);
void GBASDLSetScreensaverSuspendable(struct GBASDLEvents*, bool suspendable);
#endif
#endif #endif