Skip to content

Commit 8be860b

Browse files
committed
Qt: Don't contain display surface when entering fullscreen/separate on Windows
1 parent 74db386 commit 8be860b

File tree

6 files changed

+238
-55
lines changed

6 files changed

+238
-55
lines changed

pcsx2-qt/DisplayWidget.cpp

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void DisplaySurface::handleCloseEvent(QCloseEvent* event)
128128
// In the latter case, it's going to destroy us, so don't let Qt do it first.
129129
// Treat a close event while fullscreen as an exit, that way ALT+F4 closes PCSX2,
130130
// rather than just the game.
131-
if (QtHost::IsVMValid() && !isActuallyFullscreen())
131+
if (QtHost::IsVMValid() && !isFullScreen())
132132
{
133133
QMetaObject::invokeMethod(g_main_window, "requestShutdown", Q_ARG(bool, true),
134134
Q_ARG(bool, true), Q_ARG(bool, false));
@@ -142,10 +142,44 @@ void DisplaySurface::handleCloseEvent(QCloseEvent* event)
142142
event->ignore();
143143
}
144144

145-
bool DisplaySurface::isActuallyFullscreen() const
145+
bool DisplaySurface::isFullScreen() const
146146
{
147-
// DisplaySurface is always in a container, so we need to check parent window
148-
return parent()->windowState() & Qt::WindowFullScreen;
147+
// DisplaySurface may be in a container
148+
return (parent() ? parent()->windowState() : windowState()) & Qt::WindowFullScreen;
149+
}
150+
151+
void DisplaySurface::setFocus()
152+
{
153+
if (m_container)
154+
m_container->setFocus();
155+
else
156+
requestActivate();
157+
}
158+
159+
QByteArray DisplaySurface::saveGeometry() const
160+
{
161+
if (m_container)
162+
return m_container->saveGeometry();
163+
else
164+
{
165+
// QWindow lacks saveGeometry, so create a dummy widget and copy geometry across.
166+
QWidget dummy = QWidget();
167+
dummy.setGeometry(geometry());
168+
return dummy.saveGeometry();
169+
}
170+
}
171+
172+
void DisplaySurface::restoreGeometry(const QByteArray& geometry)
173+
{
174+
if (m_container)
175+
m_container->restoreGeometry(geometry);
176+
else
177+
{
178+
// QWindow lacks restoreGeometry, so create a dummy widget and copy geometry across.
179+
QWidget dummy = QWidget();
180+
dummy.restoreGeometry(geometry);
181+
setGeometry(dummy.geometry());
182+
}
149183
}
150184

151185
void DisplaySurface::updateCenterPos()
@@ -376,10 +410,18 @@ bool DisplaySurface::event(QEvent* event)
376410
return event->isAccepted();
377411

378412
case QEvent::Move:
379-
{
380413
updateCenterPos();
381414
return true;
382-
}
415+
416+
// These events only work on the top level control.
417+
// Which is this container when render to seperate or fullscreen is active (Windows).
418+
case QEvent::Close:
419+
handleCloseEvent(static_cast<QCloseEvent*>(event));
420+
return true;
421+
case QEvent::WindowStateChange:
422+
if (static_cast<QWindowStateChangeEvent*>(event)->oldState() & Qt::WindowMinimized)
423+
emit windowRestoredEvent();
424+
return false;
383425

384426
default:
385427
return QWindow::event(event);
@@ -401,7 +443,7 @@ bool DisplaySurface::eventFilter(QObject* object, QEvent* event)
401443
return true;
402444

403445
// These events only work on the top level control.
404-
// Which is this container when render to seperate or fullscreen is active.
446+
// Which is this container when render to seperate or fullscreen is active (Non-Windows).
405447
case QEvent::Close:
406448
handleCloseEvent(static_cast<QCloseEvent*>(event));
407449
return true;
@@ -410,8 +452,8 @@ bool DisplaySurface::eventFilter(QObject* object, QEvent* event)
410452
emit windowRestoredEvent();
411453
return false;
412454

413-
case QEvent::ChildRemoved:
414-
if (static_cast<QChildEvent*>(event)->child() == m_container)
455+
case QEvent::ChildWindowRemoved:
456+
if (static_cast<QChildWindowEvent*>(event)->child() == this)
415457
{
416458
object->removeEventFilter(this);
417459
m_container = nullptr;

pcsx2-qt/DisplayWidget.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class DisplaySurface final : public QWindow
2929
void updateRelativeMode(bool enabled);
3030
void updateCursor(bool hidden);
3131

32+
bool isFullScreen() const;
33+
void setFocus();
34+
35+
QByteArray saveGeometry() const;
36+
void restoreGeometry(const QByteArray& geometry);
37+
3238
Q_SIGNALS:
3339
void windowResizedEvent(int width, int height, float scale);
3440
void windowRestoredEvent();
@@ -43,7 +49,6 @@ class DisplaySurface final : public QWindow
4349
bool eventFilter(QObject* object, QEvent* event) override;
4450

4551
private:
46-
bool isActuallyFullscreen() const;
4752
void updateCenterPos();
4853

4954
QPoint m_relative_mouse_start_pos{};

0 commit comments

Comments
 (0)