From cf0921f3fbde31cb94b9ccddcaba36da3a488483 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A9ven=20Car?= <meven29@gmail.com>
Date: Thu, 2 Dec 2021 16:04:20 +0000
Subject: [PATCH] Under X11 ignore per-screen scale to compute logicalSize
---
src/config.cpp | 32 ++++++++++++++++++++++++++++++++
src/config.h | 4 ++++
src/output.cpp | 39 +++++++++------------------------------
src/output.h | 18 ++++--------------
4 files changed, 49 insertions(+), 44 deletions(-)
mode change 100644 => 100755 src/output.h
diff --git a/src/config.cpp b/src/config.cpp
index 37e1038..41abf70 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -325,6 +325,7 @@ void Config::setPrimaryOutput(const OutputPtr &newPrimary)
void Config::addOutput(const OutputPtr &output)
{
d->outputs.insert(output->id(), output);
+ output->setExplicitLogicalSize(logicalSizeForOutput(*output));
connect(output.data(), &KScreen::Output::isPrimaryChanged, d, &KScreen::Config::Private::onPrimaryOutputChanged);
Q_EMIT outputAdded(output);
@@ -391,6 +392,37 @@ void Config::apply(const ConfigPtr &other)
setValid(other->isValid());
}
+QRect Config::outputGeometryForOutput(const KScreen::Output &output) const
+{
+ QSize size = logicalSizeForOutput(output).toSize();
+ if (!size.isValid()) {
+ return QRect();
+ }
+
+ return QRect(output.pos(), size);
+}
+
+QSizeF Config::logicalSizeForOutput(const KScreen::Output &output) const
+{
+ QSizeF size = output.enforcedModeSize();
+ if (!size.isValid()) {
+ return QSizeF();
+ }
+ // ignore scale where scaling is not per-output
+ if (supportedFeatures().testFlag(Feature::PerOutputScaling)) {
+ size = size / output.scale();
+ }
+
+ // We can't use output.size(), because it does not reflect the actual rotation() set by caller.
+ // It is only updated when we get update from KScreen, but not when user changes mode or
+ // rotation manually.
+
+ if (!output.isHorizontal()) {
+ size = size.transposed();
+ }
+ return size;
+}
+
QDebug operator<<(QDebug dbg, const KScreen::ConfigPtr &config)
{
if (config) {
diff --git a/src/config.h b/src/config.h
index 551d7d0..4629dab 100644
--- a/src/config.h
+++ b/src/config.h
@@ -190,6 +190,10 @@ public:
*/
void setTabletModeEngaged(bool engaged);
+ QRect outputGeometryForOutput(const KScreen::Output &output) const;
+
+ QSizeF logicalSizeForOutput(const KScreen::Output &output) const;
+
Q_SIGNALS:
void outputAdded(const KScreen::OutputPtr &output);
void outputRemoved(int outputId);
diff --git a/src/output.cpp b/src/output.cpp
index c7f5949..a0fae28 100644
--- a/src/output.cpp
+++ b/src/output.cpp
@@ -13,6 +13,7 @@
#include "mode.h"
#include <QCryptographicHash>
+#include <QGuiApplication>
#include <QRect>
#include <QScopedPointer>
#include <QStringList>
@@ -28,7 +29,7 @@ public:
, replicationSource(0)
, rotation(None)
, scale(1.0)
- , logicalSize(QSizeF())
+ , explicitLogicalSize(QSizeF())
, connected(false)
, enabled(false)
, primary(false)
@@ -87,7 +88,7 @@ public:
QSize size;
Rotation rotation;
qreal scale;
- QSizeF logicalSize;
+ QSizeF explicitLogicalSize;
bool connected;
bool enabled;
bool primary;
@@ -459,40 +460,18 @@ void Output::setScale(qreal factor)
Q_EMIT scaleChanged();
}
-QSizeF Output::logicalSize() const
-{
- if (d->logicalSize.isValid()) {
- return d->logicalSize;
- }
-
- QSizeF size = enforcedModeSize();
- if (!size.isValid()) {
- return QSizeF();
- }
- size = size / d->scale;
-
- // We can't use d->size, because d->size does not reflect the actual rotation() set by caller.
- // It is only updated when we get update from KScreen, but not when user changes mode or
- // rotation manually.
-
- if (!isHorizontal()) {
- size = size.transposed();
- }
- return size;
-}
-
QSizeF Output::explicitLogicalSize() const
{
- return d->logicalSize;
+ return d->explicitLogicalSize;
}
-void Output::setLogicalSize(const QSizeF &size)
+void Output::setExplicitLogicalSize(const QSizeF &size)
{
- if (qFuzzyCompare(d->logicalSize.width(), size.width()) && qFuzzyCompare(d->logicalSize.height(), size.height())) {
+ if (qFuzzyCompare(d->explicitLogicalSize.width(), size.width()) && qFuzzyCompare(d->explicitLogicalSize.height(), size.height())) {
return;
}
- d->logicalSize = size;
- Q_EMIT logicalSizeChanged();
+ d->explicitLogicalSize = size;
+ Q_EMIT explicitLogicalSizeChanged();
}
bool Output::isConnected() const
@@ -628,7 +607,7 @@ QSize Output::enforcedModeSize() const
QRect Output::geometry() const
{
- QSize size = logicalSize().toSize();
+ QSize size = explicitLogicalSize().toSize();
if (!size.isValid()) {
return QRect();
}
diff --git a/src/output.h b/src/output.h
old mode 100644
new mode 100755
index 2b23ac4..7edb74c
--- a/src/output.h
+++ b/src/output.h
@@ -47,7 +47,7 @@ public:
Q_PROPERTY(QSize sizeMm READ sizeMm CONSTANT)
Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
Q_PROPERTY(bool followPreferredMode READ followPreferredMode WRITE setFollowPreferredMode NOTIFY followPreferredModeChanged)
- Q_PROPERTY(QSizeF logicalSize READ logicalSize WRITE setLogicalSize NOTIFY logicalSizeChanged)
+ Q_PROPERTY(QSizeF explicitLogicalSize READ explicitLogicalSize WRITE setExplicitLogicalSize NOTIFY explicitLogicalSizeChanged)
Q_PROPERTY(Capabilities capabilities READ capabilities NOTIFY capabilitiesChanged)
Q_PROPERTY(uint32_t overscan READ overscan WRITE setOverscan NOTIFY overscanChanged)
Q_PROPERTY(VrrPolicy vrrPolicy READ vrrPolicy WRITE setVrrPolicy NOTIFY vrrPolicyChanged)
@@ -311,16 +311,6 @@ public:
*/
void setScale(qreal factor);
- /**
- * The logical size is the output's representation internal to the display server and its
- * overall screen geometry.
- *
- * returns the logical size of this output
- *
- * @since 5.18
- */
- QSizeF logicalSize() const;
-
/**
* The logical size is the output's representation internal to the display server and its
* overall screen geometry.
@@ -338,9 +328,9 @@ public:
*
* @param size of this output in logical space
*
- * @since 5.18
+ * @since 5.24
*/
- void setLogicalSize(const QSizeF &size);
+ void setExplicitLogicalSize(const QSizeF &size);
/**
* @returns whether the mode should be changed to the new preferred mode
@@ -421,7 +411,7 @@ Q_SIGNALS:
void clonesChanged();
void replicationSourceChanged();
void scaleChanged();
- void logicalSizeChanged();
+ void explicitLogicalSizeChanged();
void followPreferredModeChanged(bool followPreferredMode);
void capabilitiesChanged();
void overscanChanged();
--
GitLab