diff --git a/kcm/CMakeLists.txt b/kcm/CMakeLists.txt index f54797c..14593f6 100644 --- a/kcm/CMakeLists.txt +++ b/kcm/CMakeLists.txt @@ -1,41 +1,43 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kcm_kscreen\") set(kcm_kscreen_SRCS config_handler.cpp kcm.cpp output_identifier.cpp output_model.cpp ${CMAKE_SOURCE_DIR}/common/utils.cpp ${CMAKE_SOURCE_DIR}/common/control.cpp ${CMAKE_SOURCE_DIR}/common/globals.cpp ${CMAKE_SOURCE_DIR}/common/orientation_sensor.cpp ) ecm_qt_declare_logging_category(kcm_kscreen_SRCS HEADER kcm_screen_debug.h IDENTIFIER KSCREEN_KCM CATEGORY_NAME kscreen.kcm ) add_library(kcm_kscreen MODULE ${kcm_kscreen_SRCS}) target_link_libraries(kcm_kscreen Qt5::Sensors KF5::ConfigCore KF5::CoreAddons + KF5::Declarative KF5::I18n + KF5::PlasmaQuick KF5::QuickAddons KF5::Screen ) kcoreaddons_desktop_to_json(kcm_kscreen "kcm_kscreen.desktop" SERVICE_TYPES kcmodule.desktop) #this desktop file is installed only for retrocompatibility with sycoca install(FILES kcm_kscreen.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) install(TARGETS kcm_kscreen DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms) kpackage_install_package(package kcm_kscreen kcms) diff --git a/kcm/output_identifier.cpp b/kcm/output_identifier.cpp index 17bb306..8412d10 100644 --- a/kcm/output_identifier.cpp +++ b/kcm/output_identifier.cpp @@ -1,100 +1,106 @@ /******************************************************************** Copyright © 2019 Roman Gilg This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "output_identifier.h" #include "../common/utils.h" #include #include #include #include -#include + +#include +#include #define QML_PATH "kpackage/kcms/kcm_kscreen/contents/ui/" OutputIdentifier::OutputIdentifier(KScreen::ConfigPtr config, QObject *parent) : QObject(parent) { const QString qmlPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral(QML_PATH "OutputIdentifier.qml")); for (const auto &output : config->connectedOutputs()) { if (!output->currentMode()) { continue; } 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; } QSize deviceSize, logicalSize; if (output->isHorizontal()) { deviceSize = mode->size(); } else { 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)); m_views << view; } for (auto *view : m_views) { view->show(); } QTimer::singleShot(2500, this, &OutputIdentifier::identifiersFinished); } OutputIdentifier::~OutputIdentifier() { qDeleteAll(m_views); } 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); } diff --git a/kcm/output_identifier.h b/kcm/output_identifier.h index b4dd539..740b646 100644 --- a/kcm/output_identifier.h +++ b/kcm/output_identifier.h @@ -1,43 +1,46 @@ /******************************************************************** Copyright © 2019 Roman Gilg This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #pragma once #include #include #include -class QQuickView; +namespace PlasmaQuick +{ + class Dialog; +} class OutputIdentifier : public QObject { Q_OBJECT public: explicit OutputIdentifier (KScreen::ConfigPtr config, QObject *parent = nullptr); ~OutputIdentifier() override; Q_SIGNALS: void identifiersFinished(); protected: bool eventFilter(QObject *object, QEvent *event) override; private: - QVector m_views; + QVector m_views; QTimer m_timer; };