diff --git a/.reviewboardrc b/.reviewboardrc deleted file mode 100644 --- a/.reviewboardrc +++ /dev/null @@ -1,2 +0,0 @@ -REVIEWBOARD_URL = 'https://git.reviewboard.kde.org' -REPOSITORY = 'git://anongit.kde.org/kscreen' diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ project(KScreen) -set(PROJECT_VERSION "5.11.90") +set(PROJECT_VERSION "5.12.80") cmake_minimum_required(VERSION 2.8.12) diff --git a/kcm/kcm_kscreen.desktop.cmake b/kcm/kcm_kscreen.desktop.cmake --- a/kcm/kcm_kscreen.desktop.cmake +++ b/kcm/kcm_kscreen.desktop.cmake @@ -67,7 +67,7 @@ Comment[he]=נהל את הגדרות המסכים והתצוגות שלך Comment[hu]=Monitorok és kijelzők kezelése és beállítása Comment[ia]=Gere e configura monitors e monstratores -Comment[id]=Kelola dan atur monitor dan display +Comment[id]=Kelola dan konfigurasi monitor dan display Comment[it]=Gestisci e configura monitor e schermi Comment[ko]=모니터와 디스플레이 설정 및 관리 Comment[lt]=Tvarkyti ir konfigūruoti monitorius ir ekranus diff --git a/kded/CMakeLists.txt b/kded/CMakeLists.txt --- a/kded/CMakeLists.txt +++ b/kded/CMakeLists.txt @@ -46,6 +46,7 @@ set(QML_FILES qml/Osd.qml qml/OsdItem.qml + qml/OsdSelector.qml qml/OutputIdentifier.qml ) diff --git a/kded/daemon.h b/kded/daemon.h --- a/kded/daemon.h +++ b/kded/daemon.h @@ -26,6 +26,7 @@ #include #include "generator.h" +#include "osdmanager.h" class QTimer; @@ -61,6 +62,7 @@ void setMonitorForChanges(bool enabled); void outputConnectedChanged(); void showOutputIdentifier(); + void applyOsdAction(KScreen::OsdAction::Action action); Q_SIGNALS: void outputConnected(const QString &outputName); diff --git a/kded/daemon.cpp b/kded/daemon.cpp --- a/kded/daemon.cpp +++ b/kded/daemon.cpp @@ -96,6 +96,8 @@ connect(action, &QAction::triggered, [&](bool) { displayButton(); }); new KScreenAdaptor(this); + // Initialize OSD manager to register its dbus interface + KScreen::OsdManager::self(); m_buttonTimer->setInterval(300); m_buttonTimer->setSingleShot(true); @@ -181,10 +183,49 @@ doApplyConfig(config); } +void KScreenDaemon::applyOsdAction(KScreen::OsdAction::Action action) +{ + switch (action) { + case KScreen::OsdAction::NoAction: + qCDebug(KSCREEN_KDED) << "OSD: no action"; + return; + case KScreen::OsdAction::SwitchToInternal: + qCDebug(KSCREEN_KDED) << "OSD: switch to internal"; + doApplyConfig(Generator::self()->displaySwitch(Generator::TurnOffExternal)); + return; + case KScreen::OsdAction::SwitchToExternal: + qCDebug(KSCREEN_KDED) << "OSD: switch to external"; + doApplyConfig(Generator::self()->displaySwitch(Generator::TurnOffEmbedded)); + return; + case KScreen::OsdAction::ExtendLeft: + qCDebug(KSCREEN_KDED) << "OSD: extend left"; + doApplyConfig(Generator::self()->displaySwitch(Generator::ExtendToLeft)); + return; + case KScreen::OsdAction::ExtendRight: + qCDebug(KSCREEN_KDED) << "OSD: extend right"; + doApplyConfig(Generator::self()->displaySwitch(Generator::ExtendToRight)); + return; + case KScreen::OsdAction::Clone: + qCDebug(KSCREEN_KDED) << "OSD: clone"; + doApplyConfig(Generator::self()->displaySwitch(Generator::Clone)); + return; + } + + Q_UNREACHABLE(); +} + void KScreenDaemon::applyIdealConfig() { - qCDebug(KSCREEN_KDED) << "Applying ideal config"; - doApplyConfig(Generator::self()->idealConfig(m_monitoredConfig)); + + if (m_monitoredConfig->connectedOutputs().count() < 2) { + KScreen::OsdManager::self()->hideOsd(); + doApplyConfig(Generator::self()->idealConfig(m_monitoredConfig)); + } else { + qCDebug(KSCREEN_KDED) << "Getting ideal config from user via OSD..."; + auto action = KScreen::OsdManager::self()->showActionSelector(); + connect(action, &KScreen::OsdAction::selected, + this, &KScreenDaemon::applyOsdAction); + } } void logConfig(const KScreen::ConfigPtr &config) { @@ -401,6 +442,9 @@ Qt::UniqueConnection); }, Qt::UniqueConnection ); + connect(m_monitoredConfig.data(), &KScreen::Config::outputRemoved, + this, &KScreenDaemon::applyConfig, + static_cast(Qt::QueuedConnection | Qt::UniqueConnection)); } void KScreenDaemon::setMonitorForChanges(bool enabled) diff --git a/kded/osd.h b/kded/osd.h --- a/kded/osd.h +++ b/kded/osd.h @@ -26,6 +26,8 @@ #include +#include "osdmanager.h" + namespace KDeclarative { class QmlObject; } @@ -44,9 +46,18 @@ void showGenericOsd(const QString &icon, const QString &text); void showOutputIdentifier(const KScreen::OutputPtr output); + void showActionSelector(); + void hideOsd(); + +Q_SIGNALS: + void osdActionSelected(OsdAction::Action action); + +private Q_SLOTS: + void onOsdActionSelected(int action); + void onOutputAvailabilityChanged(); private: - void hideOsd(); + bool initOsd(); void showOsd(); void updatePosition(); diff --git a/kded/osd.cpp b/kded/osd.cpp --- a/kded/osd.cpp +++ b/kded/osd.cpp @@ -19,7 +19,7 @@ #include "osd.h" #include "utils.h" -#include "debug.h" +#include "kscreen_daemon_debug.h" #include @@ -34,33 +34,57 @@ Osd::Osd(const KScreen::OutputPtr output, QObject *parent) : QObject(parent) , m_output(output) - , m_osdObject(new KDeclarative::QmlObject(this)) { + connect(output.data(), &KScreen::Output::isConnectedChanged, + this, &Osd::onOutputAvailabilityChanged); + connect(output.data(), &KScreen::Output::isEnabledChanged, + this, &Osd::onOutputAvailabilityChanged); + connect(output.data(), &KScreen::Output::currentModeIdChanged, + this, &Osd::updatePosition); + connect(output.data(), &KScreen::Output::destroyed, + this, &Osd::hideOsd); +} + +Osd::~Osd() +{ +} + +bool Osd::initOsd() +{ + if (m_osdObject) { + return true; + } + const QString &osdPath = QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation, QStringLiteral("kded_kscreen/qml/Osd.qml")); if (osdPath.isEmpty()) { qCWarning(KSCREEN_KDED) << "Failed to find OSD QML file" << osdPath; + return false; } + m_osdObject = new KDeclarative::QmlObject(this); m_osdObject->setSource(QUrl::fromLocalFile(osdPath)); if (m_osdObject->status() != QQmlComponent::Ready) { qCWarning(KSCREEN_KDED) << "Failed to load OSD QML file" << osdPath; - return; + delete m_osdObject; + m_osdObject = nullptr; + return false; } m_timeout = m_osdObject->rootObject()->property("timeout").toInt(); - m_osdTimer = new QTimer(this); m_osdTimer->setSingleShot(true); connect(m_osdTimer, &QTimer::timeout, this, &Osd::hideOsd); -} + return true; -Osd::~Osd() -{ } void Osd::showGenericOsd(const QString &icon, const QString &text) { + if (!initOsd()) { + return; + } + m_outputGeometry = m_output->geometry(); auto *rootObject = m_osdObject->rootObject(); rootObject->setProperty("itemSource", QStringLiteral("OsdItem.qml")); @@ -72,6 +96,10 @@ void Osd::showOutputIdentifier(const KScreen::OutputPtr output) { + if (!initOsd()) { + return; + } + m_outputGeometry = output->geometry(); auto *rootObject = m_osdObject->rootObject(); @@ -86,20 +114,57 @@ showOsd(); } +void Osd::showActionSelector() +{ + if (!initOsd()) { + return; + } + + m_outputGeometry = m_output->geometry(); + auto *rootObject = m_osdObject->rootObject(); + rootObject->setProperty("itemSource", QStringLiteral("OsdSelector.qml")); + rootObject->setProperty("timeout", 0); + rootObject->setProperty("outputOnly", false); + auto osdItem = rootObject->property("osdItem").value(); + connect(osdItem, SIGNAL(clicked(int)), + this, SLOT(onOsdActionSelected(int))); + m_timeout = 0; // no timeout for this one + + showOsd(); +} + +void Osd::onOsdActionSelected(int action) +{ + Q_EMIT osdActionSelected(static_cast(action)); + hideOsd(); +} + +void Osd::onOutputAvailabilityChanged() +{ + if (!m_output || !m_output->isConnected() || !m_output->isEnabled() || !m_output->currentMode()) { + hideOsd(); + } +} + void Osd::updatePosition() { - if (!m_outputGeometry.isValid()) { + if (!initOsd()) { return; } + const auto geometry = m_output->geometry(); + if (!geometry.isValid()) { + hideOsd(); + } + auto *rootObject = m_osdObject->rootObject(); const int dialogWidth = rootObject->property("width").toInt(); const int dialogHeight = rootObject->property("height").toInt(); - const int relx = m_outputGeometry.x(); - const int rely = m_outputGeometry.y(); - const int pos_x = relx + (m_outputGeometry.width() - dialogWidth) / 2; - const int pos_y = rely + (m_outputGeometry.height() - dialogHeight) / 2; + const int relx = geometry.x(); + const int rely = geometry.y(); + const int pos_x = relx + (geometry.width() - dialogWidth) / 2; + const int pos_y = rely + (geometry.height() - dialogHeight) / 2; rootObject->setProperty("x", pos_x); rootObject->setProperty("y", pos_y); @@ -114,20 +179,30 @@ // only animate on X11, wayland plugin doesn't support this and // pukes loads of warnings into our logs if (qGuiApp->platformName() == QLatin1String("xcb")) { - rootObject->setProperty("animateOpacity", false); - rootObject->setProperty("opacity", 1); - rootObject->setProperty("visible", true); - rootObject->setProperty("animateOpacity", true); - rootObject->setProperty("opacity", 0); + if (rootObject->property("timeout").toInt() > 0) { + rootObject->setProperty("animateOpacity", false); + rootObject->setProperty("opacity", 1); + rootObject->setProperty("visible", true); + rootObject->setProperty("animateOpacity", true); + rootObject->setProperty("opacity", 0); + } else { + rootObject->setProperty("visible", true); + } } else { rootObject->setProperty("visible", true); } - updatePosition(); - m_osdTimer->start(m_timeout); + QTimer::singleShot(0, this, &Osd::updatePosition); + if (m_timeout > 0) { + m_osdTimer->start(m_timeout); + } } void Osd::hideOsd() { + if (!initOsd()) { + return; + } + auto *rootObject = m_osdObject->rootObject(); if (!rootObject) { return; diff --git a/kded/osdmanager.h b/kded/osdmanager.h --- a/kded/osdmanager.h +++ b/kded/osdmanager.h @@ -32,6 +32,28 @@ class Osd; class Output; +class OsdAction : public QObject +{ + Q_OBJECT +public: + enum Action { + NoAction, + SwitchToExternal, + SwitchToInternal, + Clone, + ExtendLeft, + ExtendRight + }; + Q_ENUM(Action) + +Q_SIGNALS: + void selected(Action action); + +protected: + explicit OsdAction(QObject *parent = nullptr); +}; + + class OsdManager : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kscreen.osdService") @@ -43,6 +65,8 @@ public Q_SLOTS: void showOutputIdentifiers(); void showOsd(const QString &icon, const QString &text); + void hideOsd(); + OsdAction *showActionSelector(); private: OsdManager(QObject *parent = nullptr); diff --git a/kded/osdmanager.cpp b/kded/osdmanager.cpp --- a/kded/osdmanager.cpp +++ b/kded/osdmanager.cpp @@ -18,7 +18,7 @@ #include "osdmanager.h" #include "osd.h" -#include "debug.h" +#include "kscreen_daemon_debug.h" #include #include @@ -26,20 +26,45 @@ #include +#include + namespace KScreen { OsdManager* OsdManager::s_instance = nullptr; +OsdAction::OsdAction(QObject *parent) + : QObject(parent) +{ +} + +class OsdActionImpl : public OsdAction +{ + Q_OBJECT +public: + OsdActionImpl(QObject *parent = nullptr) + : OsdAction(parent) + {} + + void setOsd(Osd *osd) { + connect(osd, &Osd::osdActionSelected, + this, [this](Action action) { + Q_EMIT selected(action); + deleteLater(); + }); + } +}; + OsdManager::OsdManager(QObject *parent) : QObject(parent) , m_cleanupTimer(new QTimer(this)) { + qmlRegisterUncreatableType("org.kde.KScreen", 1, 0, "OsdAction", "You cannot create OsdAction"); + // free up memory when the osd hasn't been used for more than 1 minute m_cleanupTimer->setInterval(60000); m_cleanupTimer->setSingleShot(true); connect(m_cleanupTimer, &QTimer::timeout, this, [this]() { - qDeleteAll(m_osds); - m_osds.clear(); + hideOsd(); }); QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kscreen.osdService")); if (!QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/kde/kscreen/osdService"), this, QDBusConnection::ExportAllSlots)) { @@ -47,6 +72,12 @@ } } +void OsdManager::hideOsd() +{ + qDeleteAll(m_osds); + m_osds.clear(); +} + OsdManager::~OsdManager() { } @@ -61,7 +92,6 @@ void OsdManager::showOutputIdentifiers() { - qDebug() << "SHOWOUTPUTIDENTIFIERS"; connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, &OsdManager::slotIdentifyOutputs); } @@ -78,10 +108,8 @@ if (!output->isConnected() || !output->isEnabled() || !output->currentMode()) { continue; } - KScreen::Osd* osd = nullptr; - if (m_osds.keys().contains(output->name())) { - osd = m_osds.value(output->name()); - } else { + auto osd = m_osds.value(output->name()); + if (!osd) { osd = new KScreen::Osd(output, this); m_osds.insert(output->name(), osd); } @@ -106,10 +134,8 @@ if (!output->isConnected() || !output->isEnabled() || !output->currentMode()) { continue; } - KScreen::Osd* osd = nullptr; - if (m_osds.keys().contains(output->name())) { - osd = m_osds.value(output->name()); - } else { + auto osd = m_osds.value(output->name()); + if (!osd) { osd = new KScreen::Osd(output, this); m_osds.insert(output->name(), osd); } @@ -120,5 +146,76 @@ ); } +OsdAction *OsdManager::showActionSelector() +{ + hideOsd(); + + OsdActionImpl *action = new OsdActionImpl(this); + connect(action, &OsdActionImpl::selected, + this, [this]() { + for (auto osd : qAsConst(m_osds)) { + osd->hideOsd(); + } + }); + connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, + this, [this, action](const KScreen::ConfigOperation *op) { + if (op->hasError()) { + qCWarning(KSCREEN_KDED) << op->errorString(); + return; + } + + // Show selector on alll enabled screens + const auto outputs = op->config()->outputs(); + KScreen::OutputPtr osdOutput; + for (const auto &output : outputs) { + if (!output->isConnected() || !output->isEnabled() || !output->currentMode()) { + continue; + } + + // Prefer laptop screen + if (output->type() == KScreen::Output::Panel) { + osdOutput = output; + break; + } + + // Fallback to primary + if (output->isPrimary()) { + osdOutput = output; + break; + } + } + // no laptop or primary screen, just take the first usable one + if (!osdOutput) { + for (const auto &output : outputs) { + if (output->isConnected() && output->isEnabled() && output->currentMode()) { + osdOutput = output; + break; + } + } + } + + if (!osdOutput) { + // huh!? + return; + } + + KScreen::Osd* osd = nullptr; + if (m_osds.contains(osdOutput->name())) { + osd = m_osds.value(osdOutput->name()); + } else { + osd = new KScreen::Osd(osdOutput, this); + m_osds.insert(osdOutput->name(), osd); + } + action->setOsd(osd); + osd->showActionSelector(); + m_cleanupTimer->start(); + } + ); + + return action; +} + } + +#include "osdmanager.moc" diff --git a/kded/qml/Osd.qml b/kded/qml/Osd.qml --- a/kded/qml/Osd.qml +++ b/kded/qml/Osd.qml @@ -36,6 +36,7 @@ property string modeName property bool animateOpacity: false property string itemSource + property QtObject osdItem Behavior on opacity { SequentialAnimation { @@ -47,7 +48,7 @@ easing.type: Easing.InQuad } } - enabled: root.animateOpacity + enabled: root.timeout > 0 && root.animateOpacity } mainItem: Loader { @@ -55,6 +56,7 @@ onItemChanged: { if (item != undefined) { item.rootItem = root; + root.osdItem = item } } diff --git a/kded/qml/OsdSelector.qml b/kded/qml/OsdSelector.qml new file mode 100644 --- /dev/null +++ b/kded/qml/OsdSelector.qml @@ -0,0 +1,116 @@ +/* + * Copyright 2017 Daniel Vrátil + * + * 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 . + */ + +import QtQuick 2.5 +import QtQuick.Window 2.2 + +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.extras 2.0 as PlasmaExtras + +import org.kde.KScreen 1.0 + +Item { + id: root + property QtObject rootItem + + signal clicked(int actionId) + + height: Math.min(units.gridUnit * 15, Screen.desktopAvailableHeight / 5) + width: buttonRow.width + + PlasmaComponents.ButtonRow { + id: buttonRow + + exclusive: false + + height: parent.height - label.height - ((units.smallSpacing/2) * 3) + width: (actionRepeater.count * height) + ((actionRepeater.count - 1) * buttonRow.spacing); + + Repeater { + id: actionRepeater + model: [ + { + iconSource: "osd-shutd-laptop", + label: i18n("Switch to external screen"), + action: OsdAction.SwitchToExternal + }, + { + iconSource: "osd-shutd-screen", + label: i18n("Switch to laptop screen"), + action: OsdAction.SwitchToInternal + }, + { + iconSource: "osd-duplicate", + label: i18n("Unify outputs"), + action: OsdAction.Clonse + }, + { + iconSource: "osd-sbs-left", + label: i18n("Extend to left"), + action: OsdAction.ExtendLeft + }, + { + iconSource: "osd-sbs-sright", + label: i18n("Extend to right"), + action: OsdAction.ExtendRight + }, + { + iconSource: "dialog-cancel", + label: i18n("Leave unchanged"), + action: OsdAction.NoAction + } + ] + delegate: PlasmaComponents.Button { + PlasmaCore.IconItem { + source: modelData.iconSource + height: buttonRow.height - ((units.smallSpacing / 2) * 3) + width: height + anchors.centerIn: parent + } + height: parent.height + width: height + + onHoveredChanged: rootItem.infoText = (hovered ? modelData.label : "") + + onClicked: root.clicked(modelData.action) + } + } + } + + // TODO: keep? remove? + PlasmaExtras.Heading { + id: label + anchors { + bottom: parent.bottom + left: parent.left + right: parent.right + margins: Math.floor(units.smallSpacing / 2) + } + + text: rootItem.infoText + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WordWrap + maximumLineCount: 2 + elide: Text.ElideLeft + minimumPointSize: theme.defaultFont.pointSize + fontSizeMode: Text.HorizontalFit + } + + Component.onCompleted: print("OsdSelector loaded..."); +} + diff --git a/kded/serializer.cpp b/kded/serializer.cpp --- a/kded/serializer.cpp +++ b/kded/serializer.cpp @@ -256,6 +256,7 @@ output->setPrimary(info[QStringLiteral("primary")].toBool()); output->setEnabled(info[QStringLiteral("enabled")].toBool()); output->setRotation(static_cast(info[QStringLiteral("rotation")].toInt())); + output->setScale(info.value(QStringLiteral("scale"), 1).toInt()); const QVariantMap modeInfo = info[QStringLiteral("mode")].toMap(); const QVariantMap modeSize = modeInfo[QStringLiteral("size")].toMap(); diff --git a/tests/osd/CMakeLists.txt b/tests/osd/CMakeLists.txt --- a/tests/osd/CMakeLists.txt +++ b/tests/osd/CMakeLists.txt @@ -1,4 +1,7 @@ -include_directories(${CMAKE_SOURCE_DIR}/kcm/src) +include_directories( + ${CMAKE_SOURCE_DIR}/kcm/src + ${CMAKE_BINARY_DIR}/kded +) add_executable(osdtest main.cpp osdtest.cpp diff --git a/tests/osd/main.cpp b/tests/osd/main.cpp --- a/tests/osd/main.cpp +++ b/tests/osd/main.cpp @@ -33,6 +33,8 @@ QStringLiteral("Icon to use for OSD"), QStringLiteral("preferences-desktop-display-randr")); QCommandLineOption message = QCommandLineOption(QStringList() << QStringLiteral("m") << "message", QStringLiteral("Icon to use for OSD"), QStringLiteral("OSD Test")); + QCommandLineOption selector = QCommandLineOption({ QStringLiteral("s"), QStringLiteral("selector") }, + QStringLiteral("Show new screen action selector")); KScreen::OsdTest osdtest; QCommandLineParser parser; parser.addHelpOption(); @@ -40,6 +42,7 @@ parser.addOption(outputid); parser.addOption(icon); parser.addOption(message); + parser.addOption(selector); parser.process(app); @@ -48,8 +51,9 @@ osdtest.setUseDBus(true); } if (parser.isSet(outputid)) { - osdtest.showOutputIdentifiers(); + } else if (parser.isSet(selector)) { + osdtest.showActionSelector(); } else { osdtest.showGenericOsd(parser.value(icon), parser.value(message)); } diff --git a/tests/osd/osdtest.h b/tests/osd/osdtest.h --- a/tests/osd/osdtest.h +++ b/tests/osd/osdtest.h @@ -37,6 +37,7 @@ void showGenericOsd(const QString &icon, const QString &message); void showOutputIdentifiers(); + void showActionSelector(); private: bool m_useDBus = false; diff --git a/tests/osd/osdtest.cpp b/tests/osd/osdtest.cpp --- a/tests/osd/osdtest.cpp +++ b/tests/osd/osdtest.cpp @@ -75,5 +75,19 @@ } } +void OsdTest::showActionSelector() +{ + if (!m_useDBus) { + auto action = KScreen::OsdManager::self()->showActionSelector(); + connect(action, &KScreen::OsdAction::selected, + [](KScreen::OsdAction::Action action) { + qCDebug(KSCREEN_KDED) << "Selected action:" << action; + qApp->quit(); + }); + } else { + qCWarning(KSCREEN_KDED) << "Implement me."; + QTimer::singleShot(100, qApp, &QCoreApplication::quit); + } +} } // ns