Skip to content

Commit

Permalink
Qt: Fix returning from fullscreen on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Sep 14, 2023
1 parent 8dd866a commit b384a2f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
20 changes: 18 additions & 2 deletions pcsx2-qt/DisplayWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ void DisplayWidget::updateRelativeMode(bool enabled)
QCursor::setPos(m_relative_mouse_start_pos);
releaseMouse();
}

}

void DisplayWidget::updateCursor(bool hidden)
Expand Down Expand Up @@ -163,6 +162,20 @@ void DisplayWidget::handleCloseEvent(QCloseEvent* event)
event->ignore();
}

void DisplayWidget::destroy()
{
m_destroying = true;

#ifdef __APPLE__
// 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())
close();
#endif
deleteLater();
}

void DisplayWidget::updateCenterPos()
{
#ifdef _WIN32
Expand Down Expand Up @@ -206,7 +219,7 @@ bool DisplayWidget::event(QEvent* event)
case QEvent::KeyRelease:
{
const QKeyEvent* key_event = static_cast<QKeyEvent*>(event);

// Forward text input to imgui.
if (ImGuiManager::WantsTextInput() && key_event->type() == QEvent::KeyPress)
{
Expand Down Expand Up @@ -369,6 +382,9 @@ bool DisplayWidget::event(QEvent* event)

case QEvent::Close:
{
if (m_destroying)
return QWidget::event(event);

handleCloseEvent(static_cast<QCloseEvent*>(event));
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions pcsx2-qt/DisplayWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class DisplayWidget final : public QWidget
void updateCursor(bool hidden);

void handleCloseEvent(QCloseEvent* event);
void destroy();

Q_SIGNALS:
void windowResizedEvent(int width, int height, float scale);
Expand All @@ -59,6 +60,7 @@ class DisplayWidget final : public QWidget
bool m_clip_mouse_enabled = false;
#endif
bool m_cursor_hidden = false;
bool m_destroying = false;

std::vector<int> m_keys_pressed_with_modifiers;

Expand Down
7 changes: 2 additions & 5 deletions pcsx2-qt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1991,9 +1991,6 @@ std::optional<WindowInfo> MainWindow::acquireRenderWindow(bool recreate_window,

createDisplayWidget(fullscreen, render_to_main);

// we need the surface visible.. this might be able to be replaced with something else
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);

std::optional<WindowInfo> wi = m_display_widget->getWindowInfo();
if (!wi.has_value())
{
Expand Down Expand Up @@ -2165,7 +2162,7 @@ void MainWindow::destroyDisplayWidget(bool show_game_list)

if (m_display_widget)
{
m_display_widget->deleteLater();
m_display_widget->destroy();
m_display_widget = nullptr;
}

Expand Down Expand Up @@ -2247,7 +2244,7 @@ SettingsDialog* MainWindow::getSettingsDialog()
updateLanguage();
// If you doSettings now, on macOS, the window will somehow end up underneath the main window that was created above
// Delay it slightly...
QtHost::RunOnUIThread([]{
QtHost::RunOnUIThread([] {
g_main_window->doSettings("Interface");
});
});
Expand Down

0 comments on commit b384a2f

Please sign in to comment.