From 3654b76ec20dbc5731fc78a089dabee9bd16f432 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 2 Oct 2023 15:36:20 +0200 Subject: [PATCH] split output rotation setting from rotation applied because of auto rotation --- src/backends/drm/drm_output.cpp | 1 + src/core/output.cpp | 5 +++++ src/core/output.h | 6 ++++++ src/core/outputconfiguration.h | 1 + src/outputconfigurationstore.cpp | 29 ++++++++++++++++++----------- src/outputconfigurationstore.h | 1 + src/wayland/outputmanagement_v2.cpp | 3 ++- 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/backends/drm/drm_output.cpp b/src/backends/drm/drm_output.cpp index d3bb310d7c..4be4ffdef4 100644 --- a/src/backends/drm/drm_output.cpp +++ b/src/backends/drm/drm_output.cpp @@ -333,6 +333,7 @@ void DrmOutput::applyQueuedChanges(const std::shared_ptr &props next.position = props->pos.value_or(m_state.position); next.scale = props->scale.value_or(m_state.scale); next.transform = props->transform.value_or(m_state.transform); + next.manualTransform = props->manualTransform.value_or(m_state.manualTransform); next.currentMode = m_pipeline->mode(); next.overscan = m_pipeline->overscan(); next.rgbRange = m_pipeline->rgbRange(); diff --git a/src/core/output.cpp b/src/core/output.cpp index 5b693e03a4..798a05c48e 100644 --- a/src/core/output.cpp +++ b/src/core/output.cpp @@ -193,6 +193,11 @@ OutputTransform Output::transform() const return m_state.transform; } +OutputTransform Output::manualTransform() const +{ + return m_state.manualTransform; +} + QString Output::eisaId() const { return m_information.eisaId; diff --git a/src/core/output.h b/src/core/output.h index 8ddba48256..bd5c21cc4e 100644 --- a/src/core/output.h +++ b/src/core/output.h @@ -274,6 +274,11 @@ public: static std::chrono::milliseconds dimAnimationTime(); OutputTransform transform() const; + /** + * The transform that the user has configured, and which doesn't get changed + * by automatic rotation + */ + OutputTransform manualTransform() const; QSize orientateSize(const QSize &size) const; void applyChanges(const OutputConfiguration &config); @@ -395,6 +400,7 @@ protected: QPoint position; qreal scale = 1; OutputTransform transform = OutputTransform::Normal; + OutputTransform manualTransform = OutputTransform::Normal; QList> modes; std::shared_ptr currentMode; DpmsMode dpmsMode = DpmsMode::On; diff --git a/src/core/outputconfiguration.h b/src/core/outputconfiguration.h index 329f5c96fb..d4b87a5923 100644 --- a/src/core/outputconfiguration.h +++ b/src/core/outputconfiguration.h @@ -26,6 +26,7 @@ public: std::optional pos; std::optional scale; std::optional transform; + std::optional manualTransform; std::optional overscan; std::optional rgbRange; std::optional vrrPolicy; diff --git a/src/outputconfigurationstore.cpp b/src/outputconfigurationstore.cpp index 23b482de97..8c38e606fd 100644 --- a/src/outputconfigurationstore.cpp +++ b/src/outputconfigurationstore.cpp @@ -65,9 +65,6 @@ std::optional, OutputConfigura void OutputConfigurationStore::applyOrientationReading(OutputConfiguration &config, const QVector &outputs, QOrientationReading *orientation, bool isTabletMode) { - if (!isAutoRotateActive(outputs, isTabletMode) || !orientation || orientation->orientation() == QOrientationReading::Orientation::Undefined) { - return; - } const auto output = std::find_if(outputs.begin(), outputs.end(), [&config](Output *output) { return output->isInternal() && config.changeSet(output)->enabled.value_or(output->isEnabled()); }); @@ -76,6 +73,10 @@ void OutputConfigurationStore::applyOrientationReading(OutputConfiguration &conf } // TODO move other outputs to matching positions const auto changeset = config.changeSet(*output); + if (!isAutoRotateActive(outputs, isTabletMode)) { + changeset->transform = changeset->manualTransform; + return; + } switch (orientation->orientation()) { case QOrientationReading::Orientation::TopUp: changeset->transform = OutputTransform::Kind::Normal; @@ -91,7 +92,9 @@ void OutputConfigurationStore::applyOrientationReading(OutputConfiguration &conf return; case QOrientationReading::Orientation::FaceUp: case QOrientationReading::Orientation::FaceDown: + return; case QOrientationReading::Orientation::Undefined: + changeset->transform = changeset->manualTransform; return; } } @@ -184,6 +187,7 @@ void OutputConfigurationStore::storeConfig(const QVector &allOutputs, }, .scale = changeSet->scale.value_or(output->scale()), .transform = changeSet->transform.value_or(output->transform()), + .manualTransform = changeSet->manualTransform.value_or(output->manualTransform()), .overscan = changeSet->overscan.value_or(output->overscan()), .rgbRange = changeSet->rgbRange.value_or(output->rgbRange()), .vrrPolicy = changeSet->vrrPolicy.value_or(output->vrrPolicy()), @@ -209,6 +213,7 @@ void OutputConfigurationStore::storeConfig(const QVector &allOutputs, }, .scale = output->scale(), .transform = output->transform(), + .manualTransform = output->manualTransform(), .overscan = output->overscan(), .rgbRange = output->rgbRange(), .vrrPolicy = output->vrrPolicy(), @@ -249,6 +254,7 @@ std::pair> OutputConfigurationStore::setu .pos = setupState.position, .scale = state.scale, .transform = state.transform, + .manualTransform = state.manualTransform, .overscan = state.overscan, .rgbRange = state.rgbRange, .vrrPolicy = state.vrrPolicy, @@ -362,6 +368,7 @@ std::pair> OutputConfigurationStore::gene .pos = pos, .scale = existingData.scale.value_or(chooseScale(output, mode.get())), .transform = existingData.transform.value_or(output->panelOrientation()), + .manualTransform = existingData.manualTransform.value_or(output->panelOrientation()), .overscan = existingData.overscan.value_or(0), .rgbRange = existingData.rgbRange.value_or(Output::RgbRange::Automatic), .vrrPolicy = existingData.vrrPolicy.value_or(RenderLoop::VrrPolicy::Automatic), @@ -545,13 +552,13 @@ void OutputConfigurationStore::load() if (const auto it = data.find("transform"); it != data.end()) { const auto str = it->toString(); if (str == "Normal") { - state.transform = OutputTransform::Kind::Normal; + state.transform = state.manualTransform = OutputTransform::Kind::Normal; } else if (str == "Rotated90") { - state.transform = OutputTransform::Kind::Rotated90; + state.transform = state.manualTransform = OutputTransform::Kind::Rotated90; } else if (str == "Rotated180") { - state.transform = OutputTransform::Kind::Rotated180; + state.transform = state.manualTransform = OutputTransform::Kind::Rotated180; } else if (str == "Rotated270") { - state.transform = OutputTransform::Kind::Rotated270; + state.transform = state.manualTransform = OutputTransform::Kind::Rotated270; } } if (const auto it = data.find("overscan"); it != data.end()) { @@ -729,13 +736,13 @@ void OutputConfigurationStore::save() if (output.scale) { o["scale"] = *output.scale; } - if (output.transform == OutputTransform::Kind::Normal) { + if (output.manualTransform == OutputTransform::Kind::Normal) { o["transform"] = "Normal"; - } else if (output.transform == OutputTransform::Kind::Rotated90) { + } else if (output.manualTransform == OutputTransform::Kind::Rotated90) { o["transform"] = "Rotated90"; - } else if (output.transform == OutputTransform::Kind::Rotated180) { + } else if (output.manualTransform == OutputTransform::Kind::Rotated180) { o["transform"] = "Rotated180"; - } else if (output.transform == OutputTransform::Kind::Rotated270) { + } else if (output.manualTransform == OutputTransform::Kind::Rotated270) { o["transform"] = "Rotated270"; } if (output.overscan) { diff --git a/src/outputconfigurationstore.h b/src/outputconfigurationstore.h index 19638db146..1e641fef6d 100644 --- a/src/outputconfigurationstore.h +++ b/src/outputconfigurationstore.h @@ -65,6 +65,7 @@ private: std::optional mode; std::optional scale; std::optional transform; + std::optional manualTransform; std::optional overscan; std::optional rgbRange; std::optional vrrPolicy; diff --git a/src/wayland/outputmanagement_v2.cpp b/src/wayland/outputmanagement_v2.cpp index fd3f2046d7..154020b8f3 100644 --- a/src/wayland/outputmanagement_v2.cpp +++ b/src/wayland/outputmanagement_v2.cpp @@ -150,7 +150,8 @@ void OutputConfigurationV2Interface::kde_output_configuration_v2_transform(Resou }; auto _transform = toTransform(); if (OutputDeviceV2Interface *output = OutputDeviceV2Interface::get(outputdevice)) { - config.changeSet(output->handle())->transform = _transform; + const auto changeset = config.changeSet(output->handle()); + changeset->transform = changeset->manualTransform = _transform; } }