From 09e9f45933174d5b2ccb75e492d4ef4663e33fac Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Fri, 8 Apr 2022 11:37:40 +0200 Subject: [PATCH] xcb: get geometry correctly for rotation with RAndR 1.5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit xcb_randr_get_crtc_info() returns already rotated size. Pick-to: 6.3 Change-Id: I33eacf988b44cea77411ad79ae24fef7e8e1564e Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/xcb/qxcbscreen.cpp | 3 - .../qscreen_xrandr/tst_qscreen_xrandr.cpp | 60 +++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index 65fd9139e18..a3390b08dc1 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -695,9 +695,6 @@ void QXcbScreen::setMonitor(xcb_randr_monitor_info_t *monitorInfo, xcb_timestamp m_singlescreen = (monitorGeometry == (QRect(crtc->x, crtc->y, crtc->width, crtc->height))); if (m_singlescreen) { if (crtc->mode) { - if (crtc->rotation == XCB_RANDR_ROTATION_ROTATE_90 || - crtc->rotation == XCB_RANDR_ROTATION_ROTATE_270) - std::swap(crtc->width, crtc->height); updateGeometry(QRect(crtc->x, crtc->y, crtc->width, crtc->height), crtc->rotation); if (mode() != crtc->mode) updateRefreshRate(crtc->mode); diff --git a/tests/manual/qscreen_xrandr/tst_qscreen_xrandr.cpp b/tests/manual/qscreen_xrandr/tst_qscreen_xrandr.cpp index ed084253869..331bb103e7f 100644 --- a/tests/manual/qscreen_xrandr/tst_qscreen_xrandr.cpp +++ b/tests/manual/qscreen_xrandr/tst_qscreen_xrandr.cpp @@ -43,6 +43,7 @@ private slots: void xrandr_15_scale(); void xrandr_15_off_and_on(); void xrandr_15_primary(); + void xrandr_15_rotate(); private: void xrandr_process(const QStringList &arguments = {}); @@ -232,6 +233,65 @@ void tst_QScreen_Xrandr::xrandr_15_primary() } } +void tst_QScreen_Xrandr::xrandr_15_rotate() +{ + QList screens = QGuiApplication::screens(); + int ss = screens.size(); + if (ss < 1) + QSKIP("This test requires at least one screen."); + + QScreen *screen1 = screens.at(0); + QString name1 = screen1->name(); + int height1 = screen1->size().height(); + int width1 = screen1->size().width(); + qDebug() << "screen " << name1 << ": height=" << height1 << ", width=" << width1; + + int expectedHeight = width1; + int expectedWidth = height1; + + QSignalSpy geometryChangedSpy1(screen1, &QScreen::geometryChanged); + + // "xrandr --output name1 --rotate left" + QStringList args; + args << "--output" << name1 << "--rotate" << "left"; + xrandr_process(args); + QTRY_COMPARE(geometryChangedSpy1.count(), 1); + + QList screens2 = QGuiApplication::screens(); + QVERIFY(screens2.size() >= 1); + QScreen *screen2 = nullptr; + for (QScreen *s : screens2) { + if (s->name() == name1) + screen2 = s; + } + int height2 = screen2->size().height(); + int width2 = screen2->size().width(); + qDebug() << "screen " << name1 << ": height=" << height2 << ", width=" << width2; + QVERIFY(height2 == expectedHeight); + QVERIFY(width2 == expectedWidth); + + QSignalSpy geometryChangedSpy2(screen2, &QScreen::geometryChanged); + + // "xrandr --output name1 --rotate normal" + args.clear(); + args << "--output" << name1 << "--rotate" << "normal"; + xrandr_process(args); + QTRY_COMPARE(geometryChangedSpy2.count(), 1); + + QList screens3 = QGuiApplication::screens(); + QVERIFY(screens3.size() >= 1); + QScreen *screen3 = nullptr; + for (QScreen *s : screens3) { + if (s->name() == name1) + screen3 = s; + } + int height3 = screen3->size().height(); + int width3 = screen3->size().width(); + qDebug() << "screen " << name1 << ": height=" << height3 << ", width=" << width3; + QVERIFY(height3 == height1); + QVERIFY(width3 == width1); +} + void tst_QScreen_Xrandr::xrandr_process(const QStringList &args) { QString prog = "xrandr";