From f08e57540d217e16d1d15e5638afafac17439c0d Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Tue, 8 Mar 2022 11:46:48 +0100 Subject: [PATCH] GUI: add ScreenWindowGrabbing capability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- src/gui/kernel/qplatformintegration.cpp | 7 ++++++- src/gui/kernel/qplatformintegration.h | 3 ++- tests/auto/gui/kernel/qscreen/tst_qscreen.cpp | 8 ++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp index 1427db5c614..c6382243b91 100644 --- a/src/gui/kernel/qplatformintegration.cpp +++ b/src/gui/kernel/qplatformintegration.cpp @@ -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. */ /*! @@ -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 diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h index 75b942f9988..d76aeee59e9 100644 --- a/src/gui/kernel/qplatformintegration.h +++ b/src/gui/kernel/qplatformintegration.h @@ -133,7 +133,8 @@ class Q_GUI_EXPORT QPlatformIntegration OpenGLOnRasterSurface, MaximizeUsingFullscreenGeometry, PaintEvents, - RhiBasedRendering + RhiBasedRendering, + ScreenWindowGrabbing // whether QScreen::grabWindow() is supported }; virtual ~QPlatformIntegration() { } diff --git a/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp index c29162ee67a..ea644e2e2b1 100644 --- a/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp +++ b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include @@ -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("screenIndex"); QTest::addColumn("screenName"); QTest::addColumn("grabWindow"); @@ -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);