Qt: Make ALT+F4 while fullscreen exit DuckStation

This commit is contained in:
Stenzek 2023-11-24 14:30:31 +10:00
parent a705884342
commit cca901c4c6
No known key found for this signature in database
2 changed files with 12 additions and 2 deletions

View file

@ -135,7 +135,9 @@ void DisplayWidget::handleCloseEvent(QCloseEvent* event)
{
// Closing the separate widget will either cancel the close, or trigger shutdown.
// In the latter case, it's going to destroy us, so don't let Qt do it first.
if (QtHost::IsSystemValid())
// Treat a close event while fullscreen as an exit, that way ALT+F4 closes DuckStation,
// rather than just the game.
if (QtHost::IsSystemValid() && !isActuallyFullscreen())
{
QMetaObject::invokeMethod(g_main_window, "requestShutdown", Q_ARG(bool, true), Q_ARG(bool, true),
Q_ARG(bool, false));
@ -156,12 +158,19 @@ void DisplayWidget::destroy()
// See Qt documentation, entire application is in full screen state, and the main
// window will get reopened fullscreen instead of windowed if we don't close the
// fullscreen window first.
if (isFullScreen())
if (isActuallyFullscreen())
close();
#endif
deleteLater();
}
bool DisplayWidget::isActuallyFullscreen() const
{
// I hate you QtWayland... have to check the parent, not ourselves.
QWidget* container = qobject_cast<QWidget*>(parent());
return container ? container->isFullScreen() : isFullScreen();
}
void DisplayWidget::updateCenterPos()
{
#ifdef _WIN32

View file

@ -46,6 +46,7 @@ protected:
bool event(QEvent* event) override;
private:
bool isActuallyFullscreen() const;
void updateCenterPos();
QPoint m_relative_mouse_start_pos{};