diff --git a/kcm/CMakeLists.txt b/kcm/CMakeLists.txt --- a/kcm/CMakeLists.txt +++ b/kcm/CMakeLists.txt @@ -26,7 +26,9 @@ Qt5::Sensors KF5::ConfigCore KF5::CoreAddons + KF5::Declarative KF5::I18n + KF5::PlasmaQuick KF5::QuickAddons KF5::Screen ) diff --git a/kcm/output_identifier.h b/kcm/output_identifier.h --- a/kcm/output_identifier.h +++ b/kcm/output_identifier.h @@ -21,7 +21,10 @@ #include #include -class QQuickView; +namespace PlasmaQuick +{ + class Dialog; +} class OutputIdentifier : public QObject { @@ -38,6 +41,6 @@ bool eventFilter(QObject *object, QEvent *event) override; private: - QVector m_views; + QVector m_views; QTimer m_timer; }; diff --git a/kcm/output_identifier.cpp b/kcm/output_identifier.cpp --- a/kcm/output_identifier.cpp +++ b/kcm/output_identifier.cpp @@ -23,7 +23,9 @@ #include #include #include -#include + +#include +#include #define QML_PATH "kpackage/kcms/kcm_kscreen/contents/ui/" @@ -42,16 +44,21 @@ } const KScreen::ModePtr mode = output->currentMode(); + auto *view = new PlasmaQuick::Dialog(); + + auto qmlObject = new KDeclarative::QmlObject(view); + qmlObject->setSource(QUrl::fromLocalFile(qmlPath)); + qmlObject->completeInitialization(); - auto *view = new QQuickView(); + auto rootObj = qobject_cast(qmlObject->rootObject()); + view->setMainItem(rootObj); view->setFlags(Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); - view->setResizeMode(QQuickView::SizeViewToRootObject); - view->setSource(QUrl::fromLocalFile(qmlPath)); + view->setBackgroundHints(PlasmaQuick::Dialog::NoBackground); view->installEventFilter(this); - QQuickItem *rootObj = view->rootObject(); if (!rootObj) { + delete view; continue; } @@ -62,12 +69,11 @@ deviceSize = QSize(mode->size().height(), mode->size().width()); } if (config->supportedFeatures() & KScreen::Config::Feature::PerOutputScaling) { - // no scale adjustment needed on Wayland - logicalSize = deviceSize; + // Scale adjustment is not needed on Wayland, we use logical size. + logicalSize = output->logicalSize().toSize(); } else { logicalSize = deviceSize / view->effectiveDevicePixelRatio(); } - rootObj->setProperty("outputName", Utils::outputName(output)); rootObj->setProperty("modeName", Utils::sizeToString(deviceSize)); view->setProperty("screenSize", QRect(output->pos(), logicalSize)); @@ -88,12 +94,12 @@ bool OutputIdentifier::eventFilter(QObject* object, QEvent* event) { if (event->type() == QEvent::Resize) { - if (m_views.contains(qobject_cast(object))) { + if (m_views.contains(qobject_cast(object))) { QResizeEvent *e = static_cast(event); const QRect screenSize = object->property("screenSize").toRect(); QRect geometry(QPoint(0, 0), e->size()); geometry.moveCenter(screenSize.center()); - static_cast(object)->setGeometry(geometry); + static_cast(object)->setGeometry(geometry); } } return QObject::eventFilter(object, event);