Skip to content

Commit

Permalink
GUI: add ScreenWindowGrabbing capability
Browse files Browse the repository at this point in the history
On Wayland, there is no protocol to do it yet.

Task-number: QTBUG-100792
Task-number: QTBUG-101145
Change-Id: Id72625a8161359111a2d0f43f3215e787778ba6b
Reviewed-by: Tor Arne Vestbø <[email protected]>
  • Loading branch information
liangqi committed Mar 17, 2022
1 parent 9619cec commit f08e575
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/gui/kernel/qplatformintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ QPlatformServices *QPlatformIntegration::services() const
where there is an alternative, such as Qt Quick with its \c software backend, an
automatic fallback to that alternative may occur, if applicable. The default
implementation of hasCapability() returns \c true.
\value ScreenWindowGrabbing The platform supports grabbing window on screen.
On Wayland, this capability can be reported as \c false. The default implementation
of hasCapability() returns \c true.
*/

/*!
Expand All @@ -284,7 +288,8 @@ QPlatformServices *QPlatformIntegration::services() const
bool QPlatformIntegration::hasCapability(Capability cap) const
{
return cap == NonFullScreenWindows || cap == NativeWidgets || cap == WindowManagement
|| cap == TopStackedNativeChildWindows || cap == WindowActivation || cap == RhiBasedRendering;
|| cap == TopStackedNativeChildWindows || cap == WindowActivation
|| cap == RhiBasedRendering || cap == ScreenWindowGrabbing;
}

QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
Expand Down
3 changes: 2 additions & 1 deletion src/gui/kernel/qplatformintegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ class Q_GUI_EXPORT QPlatformIntegration
OpenGLOnRasterSurface,
MaximizeUsingFullscreenGeometry,
PaintEvents,
RhiBasedRendering
RhiBasedRendering,
ScreenWindowGrabbing // whether QScreen::grabWindow() is supported
};

virtual ~QPlatformIntegration() { }
Expand Down
8 changes: 6 additions & 2 deletions tests/auto/gui/kernel/qscreen/tst_qscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <qrasterwindow.h>
#include <qscreen.h>
#include <qpa/qwindowsysteminterface.h>
#include <qpa/qplatformintegration.h>
#include <private/qguiapplication_p.h>

#include <QTest>
#include <QSignalSpy>
Expand Down Expand Up @@ -205,6 +207,10 @@ void tst_QScreen::orientationChange()

void tst_QScreen::grabWindow_data()
{
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(
QPlatformIntegration::ScreenWindowGrabbing)) {
QSKIP("This platform does not support grabbing windows on screen.");
}
QTest::addColumn<int>("screenIndex");
QTest::addColumn<QByteArray>("screenName");
QTest::addColumn<bool>("grabWindow");
Expand Down Expand Up @@ -302,8 +308,6 @@ void tst_QScreen::grabWindow()

QImage grabbedImage = pixmap.toImage();
const QSize grabbedSize = grabbedImage.size();
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
QEXPECT_FAIL("", "Wayland: Screen grabbing not implemented, See QTBUG-100792.", Abort);
QCOMPARE(grabbedSize, expectedGrabSize);

QPoint pixelOffset = QPoint(0, 0);
Expand Down

0 comments on commit f08e575

Please sign in to comment.