diff --git a/abstract_wayland_output.cpp b/abstract_wayland_output.cpp index 8aa4bec840..11174f3a2d 100644 --- a/abstract_wayland_output.cpp +++ b/abstract_wayland_output.cpp @@ -113,6 +113,44 @@ void AbstractWaylandOutput::setScale(qreal scale) } } +using DeviceInterface = KWayland::Server::OutputDeviceInterface; + +KWayland::Server::OutputInterface::Transform toOutputTransform(DeviceInterface::Transform transform) +{ + using Transform = DeviceInterface::Transform; + using OutputTransform = KWayland::Server::OutputInterface::Transform; + + switch (transform) { + case Transform::Rotated90: + return OutputTransform::Rotated90; + case Transform::Rotated180: + return OutputTransform::Rotated180; + case Transform::Rotated270: + return OutputTransform::Rotated270; + case Transform::Flipped: + return OutputTransform::Flipped; + case Transform::Flipped90: + return OutputTransform::Flipped90; + case Transform::Flipped180: + return OutputTransform::Flipped180; + case Transform::Flipped270: + return OutputTransform::Flipped270; + default: + return OutputTransform::Normal; + } +} + +void AbstractWaylandOutput::setTransform(DeviceInterface::Transform transform) +{ + m_waylandOutputDevice->setTransform(transform); + + if (isEnabled()) { + m_waylandOutput->setTransform(toOutputTransform(transform)); + m_xdgOutput->setLogicalSize(pixelSize() / scale()); + m_xdgOutput->done(); + } +} + void AbstractWaylandOutput::applyChanges(const KWayland::Server::OutputChangeSet *changeSet) { qCDebug(KWIN_CORE) << "Apply changes to the Wayland output."; @@ -128,6 +166,7 @@ void AbstractWaylandOutput::applyChanges(const KWayland::Server::OutputChangeSet if (changeSet->transformChanged()) { qCDebug(KWIN_CORE) << "Server setting transform: " << (int)(changeSet->transform()); transform(changeSet->transform()); + setTransform(changeSet->transform()); emitModeChanged = true; } if (changeSet->positionChanged()) { @@ -146,8 +185,6 @@ void AbstractWaylandOutput::applyChanges(const KWayland::Server::OutputChangeSet } } -using DeviceInterface = KWayland::Server::OutputDeviceInterface; - bool AbstractWaylandOutput::isEnabled() const { return m_waylandOutputDevice->enabled() == DeviceInterface::Enablement::Enabled; @@ -262,7 +299,10 @@ void AbstractWaylandOutput::initInterfaces(const QString &model, const QString & QSize AbstractWaylandOutput::orientateSize(const QSize &size) const { - if (m_orientation == Qt::PortraitOrientation || m_orientation == Qt::InvertedPortraitOrientation) { + using Transform = DeviceInterface::Transform; + const Transform transform = m_waylandOutputDevice->transform(); + if (transform == Transform::Rotated90 || transform == Transform::Rotated270 || + transform == Transform::Flipped90 || transform == Transform::Flipped270) { return size.transposed(); } return size; diff --git a/abstract_wayland_output.h b/abstract_wayland_output.h index 88ae3bb3fa..4848bf1e23 100644 --- a/abstract_wayland_output.h +++ b/abstract_wayland_output.h @@ -70,9 +70,6 @@ public: */ QRect geometry() const override; QSize physicalSize() const override; - Qt::ScreenOrientation orientation() const override { - return m_orientation; - } /** * Current refresh rate in 1/ms. @@ -119,9 +116,6 @@ protected: QPoint globalPos() const; - void setOrientation(Qt::ScreenOrientation set) { - m_orientation = set; - } bool internal() const { return m_internal; } @@ -147,6 +141,7 @@ protected: void setWaylandMode(const QSize &size, int refreshRate); + void setTransform(KWayland::Server::OutputDeviceInterface::Transform transform); QSize orientateSize(const QSize &size) const; private: @@ -159,7 +154,6 @@ private: KWayland::Server::OutputInterface::DpmsMode m_dpms = KWayland::Server::OutputInterface::DpmsMode::On; - Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation; bool m_internal = false; bool m_supportsDpms = false; }; diff --git a/plugins/platforms/drm/drm_output.cpp b/plugins/platforms/drm/drm_output.cpp index 5ae2859d80..df6b9ff01f 100644 --- a/plugins/platforms/drm/drm_output.cpp +++ b/plugins/platforms/drm/drm_output.cpp @@ -640,83 +640,49 @@ bool DrmOutput::dpmsLegacyApply() // TODO: Rotation is currently broken in the DRM backend for 90° and 270°. Disable all rotation for // now to not break user setups until it is possible again. -#if 0 +#if 1 void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform transform) { - waylandOutputDevice()->setTransform(transform); using KWayland::Server::OutputDeviceInterface; - using KWayland::Server::OutputInterface; - auto wlOutput = waylandOutput(); switch (transform) { case OutputDeviceInterface::Transform::Normal: if (m_primaryPlane) { m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate0); } - if (wlOutput) { - wlOutput->setTransform(OutputInterface::Transform::Normal); - } - setOrientation(Qt::PrimaryOrientation); break; case OutputDeviceInterface::Transform::Rotated90: if (m_primaryPlane) { m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate90); } - if (wlOutput) { - wlOutput->setTransform(OutputInterface::Transform::Rotated90); - } - setOrientation(Qt::PortraitOrientation); break; case OutputDeviceInterface::Transform::Rotated180: if (m_primaryPlane) { m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate180); } - if (wlOutput) { - wlOutput->setTransform(OutputInterface::Transform::Rotated180); - } - setOrientation(Qt::InvertedLandscapeOrientation); break; case OutputDeviceInterface::Transform::Rotated270: if (m_primaryPlane) { m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate270); } - if (wlOutput) { - wlOutput->setTransform(OutputInterface::Transform::Rotated270); - } - setOrientation(Qt::InvertedPortraitOrientation); break; case OutputDeviceInterface::Transform::Flipped: // TODO: what is this exactly? - if (wlOutput) { - wlOutput->setTransform(OutputInterface::Transform::Flipped); - } break; case OutputDeviceInterface::Transform::Flipped90: // TODO: what is this exactly? - if (wlOutput) { - wlOutput->setTransform(OutputInterface::Transform::Flipped90); - } break; case OutputDeviceInterface::Transform::Flipped180: // TODO: what is this exactly? - if (wlOutput) { - wlOutput->setTransform(OutputInterface::Transform::Flipped180); - } break; case OutputDeviceInterface::Transform::Flipped270: // TODO: what is this exactly? - if (wlOutput) { - wlOutput->setTransform(OutputInterface::Transform::Flipped270); - } break; } m_modesetRequested = true; // the cursor might need to get rotated updateCursor(); showCursor(); - - // TODO: are these calls not enough in updateMode already? - setWaylandMode(); } #else void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform transform) @@ -872,7 +838,10 @@ bool DrmOutput::presentAtomically(DrmBuffer *buffer) // go back to previous state if (m_lastWorkingState.valid) { m_mode = m_lastWorkingState.mode; - setOrientation(m_lastWorkingState.orientation); + + // TODO: Add API back to set orientation from backend +// setOrientation(m_lastWorkingState.orientation); + setGlobalPos(m_lastWorkingState.globalPos); if (m_primaryPlane) { m_primaryPlane->setTransformation(m_lastWorkingState.planeTransformations);