From 9c41ec461e619f6236537a4d36b7d795f5c6ddb7 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Tue, 10 May 2022 13:09:08 +0200 Subject: [PATCH] kcm/edges: Draw the ratio of the monitor we are on At the moment it's showing whatever is QGuiApplication::primaryScreen(), which on Wayland is random. --- src/kcmkwin/kwinscreenedges/monitor.cpp | 13 +++++++++++-- src/kcmkwin/kwinscreenedges/monitor.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/kcmkwin/kwinscreenedges/monitor.cpp b/src/kcmkwin/kwinscreenedges/monitor.cpp index baf13c883c..eda4aafa58 100644 --- a/src/kcmkwin/kwinscreenedges/monitor.cpp +++ b/src/kcmkwin/kwinscreenedges/monitor.cpp @@ -53,8 +53,6 @@ static QScreen *screenFromWidget(const QWidget *widget) Monitor::Monitor(QWidget *parent) : ScreenPreviewWidget(parent) { - QRect avail = screenFromWidget(this)->geometry(); - setRatio((qreal)avail.width() / (qreal)avail.height()); for (int i = 0; i < 8; ++i) { @@ -97,6 +95,17 @@ void Monitor::resizeEvent(QResizeEvent *e) checkSize(); } +bool Monitor::event(QEvent *event) +{ + const bool r = ScreenPreviewWidget::event(event); + if (event->type() == QEvent::ScreenChangeInternal) { + QRect avail = screenFromWidget(this)->geometry(); + setRatio((qreal)avail.width() / (qreal)avail.height()); + checkSize(); + } + return r; +} + void Monitor::checkSize() { QRect contentsRect = previewRect(); diff --git a/src/kcmkwin/kwinscreenedges/monitor.h b/src/kcmkwin/kwinscreenedges/monitor.h index cdebc585f9..3dc7ee8d44 100644 --- a/src/kcmkwin/kwinscreenedges/monitor.h +++ b/src/kcmkwin/kwinscreenedges/monitor.h @@ -65,6 +65,7 @@ Q_SIGNALS: protected: void resizeEvent(QResizeEvent *e) override; + bool event(QEvent *event) override; private: class Corner;