From 6bfa931f2b1d9787e75c4be4e44611d51ba835c3 Mon Sep 17 00:00:00 2001 From: Roman Gilg Date: Sun, 24 Nov 2019 12:26:18 +0100 Subject: [PATCH] Associate output transforms and orientations Summary: We use internally Qt:ScreenOrientation for representing output transforms. This is not ideal since the values do not map directly to Wayland transform values, but we can make it work by using OR combinations of Qt:ScreenOrientations. Do this for now and see if we should not better introduce an internal enum mapped directly. Additionally the OR combinations need to be handled in the drm backend at various places accordingly as well (see TODOs). Test Plan: Compiles Reviewers: #kwin Subscribers: kwin Tags: #kwin Maniphest Tasks: T11670 Differential Revision: https://phabricator.kde.org/D25505 --- abstract_output.cpp | 5 ----- abstract_output.h | 7 ------- abstract_wayland_output.cpp | 25 +++++++++++++++++++++++++ abstract_wayland_output.h | 11 +++++++++++ outputscreens.cpp | 8 -------- outputscreens.h | 1 - plugins/platforms/drm/drm_output.cpp | 5 ++++- plugins/platforms/drm/drm_output.h | 2 +- 8 files changed, 41 insertions(+), 23 deletions(-) diff --git a/abstract_output.cpp b/abstract_output.cpp index 161f95f3bd..1f29302ad1 100644 --- a/abstract_output.cpp +++ b/abstract_output.cpp @@ -103,11 +103,6 @@ QSize AbstractOutput::physicalSize() const return QSize(); } -Qt::ScreenOrientation AbstractOutput::orientation() const -{ - return Qt::PrimaryOrientation; -} - int AbstractOutput::gammaRampSize() const { return 0; diff --git a/abstract_output.h b/abstract_output.h index d96c288e5b..16aaa90e9e 100644 --- a/abstract_output.h +++ b/abstract_output.h @@ -161,13 +161,6 @@ public: */ virtual QSize physicalSize() const; - /** - * Returns the orientation of this output. - * - * Default implementation returns Qt::PrimaryOrientation. - */ - virtual Qt::ScreenOrientation orientation() const; - /** * Returns the size of the gamma lookup table. * diff --git a/abstract_wayland_output.cpp b/abstract_wayland_output.cpp index 11174f3a2d..52917e9ab4 100644 --- a/abstract_wayland_output.cpp +++ b/abstract_wayland_output.cpp @@ -308,4 +308,29 @@ QSize AbstractWaylandOutput::orientateSize(const QSize &size) const return size; } +Qt::ScreenOrientations AbstractWaylandOutput::orientation() const +{ + const DeviceInterface::Transform transform = m_waylandOutputDevice->transform(); + + switch (transform) { + case DeviceInterface::Transform::Rotated90: + return Qt::PortraitOrientation; + case DeviceInterface::Transform::Rotated180: + return Qt::InvertedLandscapeOrientation; + case DeviceInterface::Transform::Rotated270: + return Qt::InvertedPortraitOrientation; + case DeviceInterface::Transform::Flipped: + return Qt::LandscapeOrientation | Qt::InvertedPortraitOrientation; + case DeviceInterface::Transform::Flipped90: + return Qt::PortraitOrientation | Qt::InvertedLandscapeOrientation; + case DeviceInterface::Transform::Flipped180: + return Qt::InvertedLandscapeOrientation | Qt::InvertedPortraitOrientation; + case DeviceInterface::Transform::Flipped270: + return Qt::PortraitOrientation | Qt::InvertedLandscapeOrientation | + Qt::InvertedPortraitOrientation; + default: + return Qt::LandscapeOrientation; + } +} + } diff --git a/abstract_wayland_output.h b/abstract_wayland_output.h index 4848bf1e23..a73ef6d243 100644 --- a/abstract_wayland_output.h +++ b/abstract_wayland_output.h @@ -144,6 +144,17 @@ protected: void setTransform(KWayland::Server::OutputDeviceInterface::Transform transform); QSize orientateSize(const QSize &size) const; + /** + * Returns the orientation of this output. + * + * - Flipped along the vertical axis is landscape + inv. portrait. + * - Rotated 90° and flipped along the horizontal axis is portrait + inv. landscape + * - Rotated 180° and flipped along the vertical axis is inv. landscape + inv. portrait + * - Rotated 270° and flipped along the horizontal axis is inv. portrait + inv. landscape + + * portrait + */ + Qt::ScreenOrientations orientation() const; + private: void createWaylandOutput(); void createXdgOutput(); diff --git a/outputscreens.cpp b/outputscreens.cpp index 4ac6a31fc4..7f7a188512 100644 --- a/outputscreens.cpp +++ b/outputscreens.cpp @@ -95,14 +95,6 @@ float OutputScreens::refreshRate(int screen) const return 60.0; } -Qt::ScreenOrientation OutputScreens::orientation(int screen) const -{ - if (AbstractOutput *output = findOutput(screen)) { - return output->orientation(); - } - return Qt::PrimaryOrientation; -} - void OutputScreens::updateCount() { setCount(m_platform->enabledOutputs().size()); diff --git a/outputscreens.h b/outputscreens.h index 3bc8ba26b4..3f3e466dbb 100644 --- a/outputscreens.h +++ b/outputscreens.h @@ -45,7 +45,6 @@ public: QSize size(int screen) const override; qreal scale(int screen) const override; float refreshRate(int screen) const override; - Qt::ScreenOrientation orientation(int screen) const override; void updateCount() override; int number(const QPoint &pos) const override; diff --git a/plugins/platforms/drm/drm_output.cpp b/plugins/platforms/drm/drm_output.cpp index df6b9ff01f..4485d10824 100644 --- a/plugins/platforms/drm/drm_output.cpp +++ b/plugins/platforms/drm/drm_output.cpp @@ -128,7 +128,8 @@ bool DrmOutput::showCursor() return ret; } -int orientationToRotation(Qt::ScreenOrientation orientation) +// TODO: Respect OR combinations of values +int orientationToRotation(Qt::ScreenOrientations orientation) { switch (orientation) { case Qt::PrimaryOrientation: @@ -182,6 +183,8 @@ void DrmOutput::moveCursor(const QPoint &globalPos) const QMatrix4x4 hotspotMatrix = matrixDisplay(m_backend->softwareCursor().size()); QPoint p = globalPos - AbstractWaylandOutput::globalPos(); + + // TODO: Respect OR combinations of values switch (orientation()) { case Qt::PrimaryOrientation: case Qt::LandscapeOrientation: diff --git a/plugins/platforms/drm/drm_output.h b/plugins/platforms/drm/drm_output.h index a8ec22e54e..9f20943b66 100644 --- a/plugins/platforms/drm/drm_output.h +++ b/plugins/platforms/drm/drm_output.h @@ -150,7 +150,7 @@ private: bool m_modesetRequested = true; struct { - Qt::ScreenOrientation orientation; + Qt::ScreenOrientations orientation; drmModeModeInfo mode; DrmPlane::Transformations planeTransformations; QPoint globalPos;