Make QPlatformPlaceholderScreen a sibling of other screens

This is how the fake screen currently behaves in the xcb plugin. So if we are
to deduplicate, it's probably best to match current behavior first.

I still left an option for not being a virtual sibling in case other platforms
don't support showing a window on a placeholder screen.

Task-number: QTBUG-79711
Change-Id: I4e8b44d892efb85fdb003f1d473d0867442d7e4e
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
This commit is contained in:
Johan Klokkhammer Helsing 2019-11-07 12:18:22 +01:00
parent c17a5cec19
commit f0a43a9def
2 changed files with 28 additions and 3 deletions

View File

@ -616,4 +616,18 @@ int QPlatformScreen::preferredMode() const
return 0; return 0;
} }
QList<QPlatformScreen *> QPlatformPlaceholderScreen::virtualSiblings() const
{
QList<QPlatformScreen *> siblings;
if (!m_virtualSibling)
return siblings;
for (QScreen *screen : QGuiApplication::screens()) {
if (screen->handle() && screen->handle() != this)
siblings << screen->handle();
}
return siblings;
}
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -105,7 +105,7 @@ public:
QPlatformScreen(); QPlatformScreen();
virtual ~QPlatformScreen(); virtual ~QPlatformScreen();
virtual bool isPlaceholder() const { return false; }; virtual bool isPlaceholder() const { return false; }
virtual QPixmap grabWindow(WId window, int x, int y, int width, int height) const; virtual QPixmap grabWindow(WId window, int x, int y, int width, int height) const;
@ -176,12 +176,23 @@ private:
// Qt doesn't currently support running with no platform screen // Qt doesn't currently support running with no platform screen
// QPA plugins can use this class to create a fake screen // QPA plugins can use this class to create a fake screen
class QPlatformPlaceholderScreen : public QPlatformScreen { class Q_GUI_EXPORT QPlatformPlaceholderScreen : public QPlatformScreen {
bool isPlaceholder() const override { return true; }; public:
// virtualSibling can be passed in to make the placeholder a sibling with other screens during
// the transitioning phase when the real screen is about to be removed, or the first real screen
// is about to be added. This is useful because Qt will currently recreate (but now show!)
// windows when they are moved from one virtual desktop to another, so if the last monitor is
// unplugged, then plugged in again, windows will be hidden unless the placeholder belongs to
// the same virtual desktop as the other screens.
QPlatformPlaceholderScreen(bool virtualSibling = true) : m_virtualSibling(virtualSibling) {}
bool isPlaceholder() const override { return true; }
QRect geometry() const override { return QRect(); } QRect geometry() const override { return QRect(); }
QRect availableGeometry() const override { return QRect(); } QRect availableGeometry() const override { return QRect(); }
int depth() const override { return 32; } int depth() const override { return 32; }
QImage::Format format() const override { return QImage::Format::Format_RGB32; } QImage::Format format() const override { return QImage::Format::Format_RGB32; }
QList<QPlatformScreen *> virtualSiblings() const override;
private:
bool m_virtualSibling = true;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE