Qt: Handle fullscreen cases on MacOS

If the user exits fullscreen with the window button, restore
render to main.
This commit is contained in:
Stenzek 2025-07-19 01:04:22 +10:00
parent b545671d67
commit 24a16db437
No known key found for this signature in database
3 changed files with 24 additions and 7 deletions

View File

@ -400,9 +400,16 @@ bool DisplayWidget::event(QEvent* event)
{
QWidget::event(event);
if (static_cast<QWindowStateChangeEvent*>(event)->oldState() & Qt::WindowMinimized)
const QWindowStateChangeEvent* ws_event = static_cast<const QWindowStateChangeEvent*>(event);
if (ws_event->oldState() & Qt::WindowMinimized)
emit windowRestoredEvent();
#ifdef __APPLE__
// On MacOS, the user can "cancel" fullscreen by unmaximizing the window.
if (ws_event->oldState() & Qt::WindowFullScreen && !(windowState() & Qt::WindowFullScreen))
g_emu_thread->setFullscreen(false);
#endif
return true;
}

View File

@ -421,6 +421,16 @@ void MainWindow::createDisplayWidget(bool fullscreen, bool render_to_main)
m_display_widget->setFocus();
}
void MainWindow::exitFullscreen(bool wait_for_completion)
{
if (!m_display_widget || !isRenderingFullscreen())
return;
g_emu_thread->setFullscreen(false);
if (wait_for_completion)
QtUtils::ProcessEventsWithSleep(QEventLoop::ExcludeUserInputEvents, [this]() { return isRenderingFullscreen(); });
}
void MainWindow::displayResizeRequested(qint32 width, qint32 height)
{
if (!m_display_widget)
@ -2179,6 +2189,9 @@ bool MainWindow::shouldHideMainWindow() const
void MainWindow::switchToGameListView()
{
// Normally, we'd never end up here. But on MacOS, the global menu is accessible while fullscreen.
exitFullscreen(true);
if (!isShowingGameList())
{
if (wantsDisplayWidget())
@ -3026,13 +3039,9 @@ void MainWindow::onToolsMemoryCardEditorTriggered()
void MainWindow::onToolsCoverDownloaderTriggered()
{
// This can be invoked via big picture, so exit fullscreen.
// Wait for the fullscreen request to actually go through, otherwise the downloader appears behind the main window.
if (isRenderingFullscreen())
{
g_emu_thread->setFullscreen(false);
// wait for the fullscreen request to actually go through, otherwise the downloader appears behind the main window.
QtUtils::ProcessEventsWithSleep(QEventLoop::ExcludeUserInputEvents, [this]() { return isRenderingFullscreen(); });
}
exitFullscreen(true);
if (!m_cover_download_window)
{

View File

@ -272,6 +272,7 @@ private:
void destroyDisplayWidget(bool show_game_list);
void updateDisplayWidgetCursor();
void updateDisplayRelatedActions(bool has_surface, bool fullscreen);
void exitFullscreen(bool wait_for_completion);
void doSettings(const char* category = nullptr);
void openGamePropertiesForCurrentGame(const char* category = nullptr);