mirror of https://github.com/PCSX2/pcsx2.git
Qt: Implement pause on focus loss
This commit is contained in:
parent
16936aa452
commit
590ca98463
|
@ -397,22 +397,6 @@ bool DisplayWidget::event(QEvent* event)
|
|||
return true;
|
||||
}
|
||||
|
||||
case QEvent::FocusIn:
|
||||
{
|
||||
QWidget::event(event);
|
||||
emit windowFocusEvent();
|
||||
return true;
|
||||
}
|
||||
|
||||
case QEvent::ActivationChange:
|
||||
{
|
||||
QWidget::event(event);
|
||||
if (isActiveWindow())
|
||||
emit windowFocusEvent();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
@ -477,19 +461,6 @@ bool DisplayContainer::event(QEvent* event)
|
|||
}
|
||||
break;
|
||||
|
||||
case QEvent::FocusIn:
|
||||
{
|
||||
emit m_display_widget->windowFocusEvent();
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::ActivationChange:
|
||||
{
|
||||
if (isActiveWindow())
|
||||
emit m_display_widget->windowFocusEvent();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ public:
|
|||
void updateCursor(bool master_enable);
|
||||
|
||||
Q_SIGNALS:
|
||||
void windowFocusEvent();
|
||||
void windowResizedEvent(int width, int height, float scale);
|
||||
void windowRestoredEvent();
|
||||
|
||||
|
|
|
@ -247,6 +247,7 @@ void EmuThread::run()
|
|||
reloadInputSources();
|
||||
createBackgroundControllerPollTimer();
|
||||
startBackgroundControllerPollTimer();
|
||||
connectSignals();
|
||||
|
||||
while (!m_shutdown_flag.load())
|
||||
{
|
||||
|
@ -277,6 +278,7 @@ void EmuThread::destroyVM()
|
|||
m_last_video_fps = 0.0f;
|
||||
m_last_internal_width = 0;
|
||||
m_last_internal_height = 0;
|
||||
m_was_paused_by_focus_loss = false;
|
||||
VMManager::Shutdown(m_save_state_on_shutdown);
|
||||
}
|
||||
|
||||
|
@ -436,6 +438,12 @@ void EmuThread::updateEmuFolders()
|
|||
void EmuThread::loadOurSettings()
|
||||
{
|
||||
m_verbose_status = Host::GetBaseBoolSettingValue("UI", "VerboseStatusBar", false);
|
||||
m_pause_on_focus_loss = Host::GetBaseBoolSettingValue("UI", "PauseOnFocusLoss", false);
|
||||
}
|
||||
|
||||
void EmuThread::connectSignals()
|
||||
{
|
||||
connect(qApp, &QGuiApplication::applicationStateChanged, this, &EmuThread::onApplicationStateChanged);
|
||||
}
|
||||
|
||||
void EmuThread::checkForSettingChanges()
|
||||
|
@ -605,9 +613,8 @@ void EmuThread::connectDisplaySignals(DisplayWidget* widget)
|
|||
{
|
||||
widget->disconnect(this);
|
||||
|
||||
connect(widget, &DisplayWidget::windowFocusEvent, this, &EmuThread::onDisplayWindowFocused);
|
||||
connect(widget, &DisplayWidget::windowResizedEvent, this, &EmuThread::onDisplayWindowResized);
|
||||
// connect(widget, &DisplayWidget::windowRestoredEvent, this, &EmuThread::redrawDisplayWindow);
|
||||
connect(widget, &DisplayWidget::windowRestoredEvent, this, &EmuThread::redrawDisplayWindow);
|
||||
}
|
||||
|
||||
void EmuThread::onDisplayWindowResized(int width, int height, float scale)
|
||||
|
@ -618,7 +625,31 @@ void EmuThread::onDisplayWindowResized(int width, int height, float scale)
|
|||
GetMTGS().ResizeDisplayWindow(width, height, scale);
|
||||
}
|
||||
|
||||
void EmuThread::onDisplayWindowFocused() {}
|
||||
void EmuThread::onApplicationStateChanged(Qt::ApplicationState state)
|
||||
{
|
||||
// NOTE: This is executed on the emu thread, not UI thread.
|
||||
if (!m_pause_on_focus_loss || !VMManager::HasValidVM())
|
||||
return;
|
||||
|
||||
const bool focus_loss = (state != Qt::ApplicationActive);
|
||||
if (focus_loss)
|
||||
{
|
||||
if (!m_was_paused_by_focus_loss && VMManager::GetState() == VMState::Running)
|
||||
{
|
||||
m_was_paused_by_focus_loss = true;
|
||||
VMManager::SetPaused(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_was_paused_by_focus_loss)
|
||||
{
|
||||
m_was_paused_by_focus_loss = false;
|
||||
if (VMManager::GetState() == VMState::Paused)
|
||||
VMManager::SetPaused(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EmuThread::redrawDisplayWindow()
|
||||
{
|
||||
|
|
|
@ -140,12 +140,13 @@ private:
|
|||
void createBackgroundControllerPollTimer();
|
||||
void destroyBackgroundControllerPollTimer();
|
||||
void loadOurSettings();
|
||||
void connectSignals();
|
||||
|
||||
private Q_SLOTS:
|
||||
void stopInThread();
|
||||
void doBackgroundControllerPoll();
|
||||
void onDisplayWindowResized(int width, int height, float scale);
|
||||
void onDisplayWindowFocused();
|
||||
void onApplicationStateChanged(Qt::ApplicationState state);
|
||||
void redrawDisplayWindow();
|
||||
|
||||
private:
|
||||
|
@ -161,6 +162,9 @@ private:
|
|||
bool m_is_fullscreen = false;
|
||||
bool m_is_surfaceless = false;
|
||||
bool m_save_state_on_shutdown = false;
|
||||
bool m_pause_on_focus_loss = false;
|
||||
|
||||
bool m_was_paused_by_focus_loss = false;
|
||||
|
||||
float m_last_speed = 0.0f;
|
||||
float m_last_game_fps = 0.0f;
|
||||
|
|
|
@ -117,7 +117,6 @@ InterfaceSettingsWidget::InterfaceSettingsWidget(SettingsDialog* dialog, QWidget
|
|||
tr("Hides the main window (with the game list) when a game is running, requires Render To Separate Window to be enabled."));
|
||||
|
||||
// Not yet used, disable the options
|
||||
m_ui.pauseOnFocusLoss->setDisabled(true);
|
||||
m_ui.language->setDisabled(true);
|
||||
|
||||
onRenderToSeparateWindowChanged();
|
||||
|
|
Loading…
Reference in New Issue