diff --git a/kded/CMakeLists.txt b/kded/CMakeLists.txt index 7beb186..5f20388 100644 --- a/kded/CMakeLists.txt +++ b/kded/CMakeLists.txt @@ -1,52 +1,53 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kscreen\") include_directories(${CMAKE_CURRENT_BINARY_DIR}/../ ${CMAKE_SOURCE_DIR}/kcm/src) set(kscreen_daemon_SRCS daemon.cpp serializer.cpp generator.cpp device.cpp osd.cpp osdmanager.cpp ${CMAKE_SOURCE_DIR}/kcm/src/utils.cpp ) ecm_qt_declare_logging_category(kscreen_daemon_SRCS HEADER kscreen_daemon_debug.h IDENTIFIER KSCREEN_KDED CATEGORY_NAME kscreen.kded) qt5_add_dbus_interface(kscreen_daemon_SRCS org.freedesktop.DBus.Properties.xml freedesktop_interface) qt5_add_dbus_adaptor(kscreen_daemon_SRCS org.kde.KScreen.xml daemon.h KScreenDaemon ) add_library(kscreen MODULE ${kscreen_daemon_SRCS}) target_link_libraries(kscreen Qt5::Widgets Qt5::DBus Qt5::Quick KF5::Declarative KF5::Screen KF5::DBusAddons KF5::I18n KF5::XmlGui KF5::GlobalAccel) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/kscreen.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kscreen.desktop @ONLY) kcoreaddons_desktop_to_json(kscreen ${CMAKE_CURRENT_BINARY_DIR}/kscreen.desktop) install(TARGETS kscreen DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kded) set(QML_FILES qml/Osd.qml qml/OsdItem.qml + qml/OsdSelector.qml qml/OutputIdentifier.qml ) install(FILES ${QML_FILES} DESTINATION ${DATA_INSTALL_DIR}/kded_kscreen/qml) diff --git a/kded/osd.cpp b/kded/osd.cpp index 1ee4c80..f1c3a32 100644 --- a/kded/osd.cpp +++ b/kded/osd.cpp @@ -1,142 +1,160 @@ /* * Copyright 2014 Martin Klapetek * Copyright 2016 Sebastian Kügler * * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "osd.h" #include "utils.h" #include "kscreen_daemon_debug.h" #include #include #include #include #include using namespace KScreen; Osd::Osd(const KScreen::OutputPtr output, QObject *parent) : QObject(parent) , m_output(output) , m_osdObject(new KDeclarative::QmlObject(this)) { 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; } m_osdObject->setSource(QUrl::fromLocalFile(osdPath)); if (m_osdObject->status() != QQmlComponent::Ready) { qCWarning(KSCREEN_KDED) << "Failed to load OSD QML file" << osdPath; return; } 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); } Osd::~Osd() { } void Osd::showGenericOsd(const QString &icon, const QString &text) { m_outputGeometry = m_output->geometry(); auto *rootObject = m_osdObject->rootObject(); rootObject->setProperty("itemSource", QStringLiteral("OsdItem.qml")); rootObject->setProperty("infoText", text); rootObject->setProperty("icon", icon); showOsd(); } void Osd::showOutputIdentifier(const KScreen::OutputPtr output) { m_outputGeometry = output->geometry(); auto *rootObject = m_osdObject->rootObject(); auto mode = output->currentMode(); QSize realSize = mode->size(); if (!output->isHorizontal()) { realSize.transpose(); } rootObject->setProperty("itemSource", QStringLiteral("OutputIdentifier.qml")); rootObject->setProperty("modeName", Utils::sizeToString(realSize)); rootObject->setProperty("outputName", Utils::outputName(output)); showOsd(); } +void Osd::showActionSelector() { + 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(QString)), + this, SLOT(onOsdActionSelected(QString))); + m_timeout = 0; // no timeout for this one + showOsd(); +} + +void Osd::onOsdActionSelected(const QString &action) { + Q_EMIT osdActionSelected(action); + hideOsd(); +} + void Osd::updatePosition() { if (!m_outputGeometry.isValid()) { return; } 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; rootObject->setProperty("x", pos_x); rootObject->setProperty("y", pos_y); } void Osd::showOsd() { m_osdTimer->stop(); auto *rootObject = m_osdObject->rootObject(); // only animate on X11, wayland plugin doesn't support this and // pukes loads of warnings into our logs if (qGuiApp->platformName() == QLatin1String("xcb")) { 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(); if (m_timeout > 0) { m_osdTimer->start(m_timeout); } } void Osd::hideOsd() { auto *rootObject = m_osdObject->rootObject(); if (!rootObject) { return; } rootObject->setProperty("visible", false); } diff --git a/kded/osd.h b/kded/osd.h index 93aeaf6..a5cce5f 100644 --- a/kded/osd.h +++ b/kded/osd.h @@ -1,63 +1,70 @@ /* * Copyright 2014 Martin Klapetek * Copyright 2016 Sebastian Kügler * * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KSCREEN_OSD_H #define KSCREEN_OSD_H #include #include #include #include namespace KDeclarative { class QmlObject; } class QTimer; namespace KScreen { class Osd : public QObject { Q_OBJECT public: Osd(const KScreen::OutputPtr output, QObject *parent = nullptr); ~Osd() override; void showGenericOsd(const QString &icon, const QString &text); void showOutputIdentifier(const KScreen::OutputPtr output); + void showActionSelector(); + +Q_SIGNALS: + void osdActionSelected(const QString &action); + +private Q_SLOTS: + void onOsdActionSelected(const QString &action); private: void hideOsd(); void showOsd(); void updatePosition(); KScreen::OutputPtr m_output; QRect m_outputGeometry; KDeclarative::QmlObject *m_osdObject = nullptr; QTimer *m_osdTimer = nullptr; int m_timeout = 0; }; } // ns #endif // KSCREEN_OSD_H diff --git a/kded/osdmanager.cpp b/kded/osdmanager.cpp index cead698..bcaedba 100644 --- a/kded/osdmanager.cpp +++ b/kded/osdmanager.cpp @@ -1,123 +1,194 @@ /* * Copyright 2016 Sebastian Kügler * * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "osdmanager.h" #include "osd.h" #include "kscreen_daemon_debug.h" #include #include #include #include namespace KScreen { OsdManager* OsdManager::s_instance = nullptr; OsdManager::OsdManager(QObject *parent) : QObject(parent) , m_cleanupTimer(new QTimer(this)) { // 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(); }); QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kscreen.osdService")); if (!QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/kde/kscreen/osdService"), this, QDBusConnection::ExportAllSlots)) { qCWarning(KSCREEN_KDED) << "Failed to registerObject"; } } OsdManager::~OsdManager() { } OsdManager* OsdManager::self() { if (!OsdManager::s_instance) { s_instance = new OsdManager(); } return s_instance; } void OsdManager::showOutputIdentifiers() { connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, &OsdManager::slotIdentifyOutputs); } void OsdManager::slotIdentifyOutputs(KScreen::ConfigOperation *op) { if (op->hasError()) { return; } const KScreen::ConfigPtr config = qobject_cast(op)->config(); Q_FOREACH (const KScreen::OutputPtr &output, config->outputs()) { 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 { osd = new KScreen::Osd(output, this); m_osds.insert(output->name(), osd); } osd->showOutputIdentifier(output); } m_cleanupTimer->start(); } void OsdManager::showOsd(const QString& icon, const QString& text) { qDeleteAll(m_osds); m_osds.clear(); connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, [this, icon, text] (KScreen::ConfigOperation *op) { if (op->hasError()) { return; } const KScreen::ConfigPtr config = qobject_cast(op)->config(); Q_FOREACH (const KScreen::OutputPtr &output, config->outputs()) { 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 { osd = new KScreen::Osd(output, this); m_osds.insert(output->name(), osd); } osd->showGenericOsd(icon, text); } m_cleanupTimer->start(); } ); } +void OsdManager::showActionSelector() +{ + qDeleteAll(m_osds); + m_osds.clear(); + connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, + this, [this](const KScreen::ConfigOperation *op) { + if (op->hasError()) { + qCWarning(KSCREEN_KDED) << op->errorString(); + return; + } + + auto config = op->config(); + const auto outputs = config->outputs(); + // If we have a primary output, show the selector on that screen + auto output = config->primaryOutput(); + if (!output) { + // no primary output, use the laptop output + auto it = std::find_if(outputs.cbegin(), outputs.cend(), + [](const OutputPtr &output) { + return output->type() == Output::Panel; + }); + if (it != outputs.cend() && (*it)->isConnected() && (*it)->isEnabled()) { + output = *it; + } + } + if (!output) { + // no primary or laptop output, use the biggest output + const auto end = outputs.cend(); + auto largestIt = end; + for (auto it = outputs.cbegin(); it != end; ++it) { + if (!(*it)->isConnected() || !(*it)->isEnabled() || !(*it)->currentMode()) { + continue; + } + if (largestIt == end) { + largestIt = it; + } else { + const auto itSize = (*it)->currentMode()->size(); + const auto largestSize = (*largestIt)->currentMode()->size(); + if (itSize.width() * itSize.height() > largestSize.width() * largestSize.height()) { + largestIt = it; + } + } + } + if (largestIt != end) { + output = *largestIt; + } + } + if (!output) { + // fallback to first active output + for (const auto &o : outputs) { + if (o->isConnected() && o->isEnabled()) { + output = o; + break; + } + } + } + if (!output) { + // no outputs? bail out... + qCDebug(KSCREEN_KDED) << "Found no usable outputs"; + return; + } + + auto osd = new KScreen::Osd(output, this); + connect(osd, &Osd::osdActionSelected, this, &OsdManager::osdActionSelected); + m_osds.insert(output->name(), osd); + osd->showActionSelector(); + m_cleanupTimer->start(); + } + ); +} + } diff --git a/kded/osdmanager.h b/kded/osdmanager.h index d75e3bf..b80de5e 100644 --- a/kded/osdmanager.h +++ b/kded/osdmanager.h @@ -1,57 +1,61 @@ /* * Copyright 2016 Sebastian Kügler * * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OSDM_H #define OSDM_H #include #include #include #include class QmlObject; namespace KScreen { class ConfigOperation; class Osd; class Output; class OsdManager : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kscreen.osdService") public: ~OsdManager() override; static OsdManager* self(); public Q_SLOTS: void showOutputIdentifiers(); void showOsd(const QString &icon, const QString &text); + void showActionSelector(); + +Q_SIGNALS: + void osdActionSelected(const QString &action); private: OsdManager(QObject *parent = nullptr); void slotIdentifyOutputs(KScreen::ConfigOperation *op); QMap m_osds; static OsdManager* s_instance; QTimer* m_cleanupTimer; }; } // ns #endif // OSDM_H diff --git a/kded/qml/Osd.qml b/kded/qml/Osd.qml index 2c5ad43..e04a1e0 100644 --- a/kded/qml/Osd.qml +++ b/kded/qml/Osd.qml @@ -1,62 +1,64 @@ /* * Copyright 2014 Martin Klapetek * Copyright 2016 Sebastian Kügler * * 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.0 import QtQuick.Window 2.2 import org.kde.plasma.core 2.0 as PlasmaCore PlasmaCore.Dialog { id: root location: PlasmaCore.Types.Floating type: PlasmaCore.Dialog.OnScreenDisplay outputOnly: true // OSD Timeout in msecs - how long it will stay on the screen property int timeout: 5000 // Icon name to display property string icon property string infoText property string outputName property string modeName property bool animateOpacity: false property string itemSource + property QtObject osdItem Behavior on opacity { SequentialAnimation { // prevent press and hold from flickering PauseAnimation { duration: root.timeout * 0.8 } NumberAnimation { duration: root.timeout * 0.2 easing.type: Easing.InQuad } } enabled: root.timeout > 0 && root.animateOpacity } mainItem: Loader { source: itemSource 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 index 0000000..6beac2c --- /dev/null +++ b/kded/qml/OsdSelector.qml @@ -0,0 +1,114 @@ +/* + * 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 + +Item { + id: root + property QtObject rootItem + + signal clicked(string 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.model.length * height) + ((actionRepeater.model.length - 1) * buttonRow.spacing); + + Repeater { + id: actionRepeater + model: [ + { + iconSource: "osd-shutd-screen", + label: qsTr("Switch to external screen"), + action: "external-only" + }, + { + iconSource: "osd-shutd-laptop", + label: qsTr("Switch to laptop screen"), + action: "internal-only" + }, + { + iconSource: "osd-duplicate", + label: qsTr("Duplicate outputs"), + action: "clone" + }, + { + iconSource: "osd-sbs-left", + label: qsTr("Extend to left"), + action: "extend-left" + }, + { + iconSource: "osd-sbs-sright", + label: qsTr("Extend to right"), + action: "extend-right" + }, + { + iconSource: "dialog-cancel", + label: qsTr("Do nothing"), + action: "cancel" + } + ] + 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/tests/osd/main.cpp b/tests/osd/main.cpp index 714c01e..4bbff93 100644 --- a/tests/osd/main.cpp +++ b/tests/osd/main.cpp @@ -1,60 +1,64 @@ /************************************************************************************* * Copyright 2014-2016 by Sebastian Kügler * * * * 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, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * *************************************************************************************/ #include "osdtest.h" #include #include int main(int argc, char **argv) { QGuiApplication app(argc, argv); QCommandLineOption dbus = QCommandLineOption(QStringList() << QStringLiteral("d") << "dbus", QStringLiteral("Call over dbus")); QCommandLineOption outputid = QCommandLineOption(QStringList() << QStringLiteral("o") << "outputidentifiers", QStringLiteral("Show output identifier")); QCommandLineOption icon = QCommandLineOption(QStringList() << QStringLiteral("i") << "icon", 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(); parser.addOption(dbus); parser.addOption(outputid); parser.addOption(icon); parser.addOption(message); + parser.addOption(selector); parser.process(app); if (parser.isSet(dbus)) { 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)); } if (parser.isSet(outputid)) { } return app.exec(); } diff --git a/tests/osd/osdtest.cpp b/tests/osd/osdtest.cpp index b54b05e..c84d746 100644 --- a/tests/osd/osdtest.cpp +++ b/tests/osd/osdtest.cpp @@ -1,79 +1,93 @@ /************************************************************************************* * Copyright 2016 Sebastian Kügler * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ #include "osdtest.h" #include "../../kded/osdmanager.h" #include #include #include #include #include Q_LOGGING_CATEGORY(KSCREEN_KDED, "kscreen.kded") namespace KScreen { OsdTest::OsdTest(QObject *parent) : QObject(parent) { } OsdTest::~OsdTest() { } void OsdTest::showOutputIdentifiers() { if (!m_useDBus) { QTimer::singleShot(5500, qApp, &QCoreApplication::quit); KScreen::OsdManager::self()->showOutputIdentifiers(); } else { QDBusMessage msg = QDBusMessage::createMethodCall( QLatin1Literal("org.kde.kscreen.osdService"), QLatin1Literal("/org/kde/kscreen/osdService"), QLatin1Literal("org.kde.kscreen.osdService"), QLatin1Literal("showOutputIdentifiers") ); //msg << icon << text; QDBusConnection::sessionBus().asyncCall(msg); qCWarning(KSCREEN_KDED) << "Sent dbus message."; QTimer::singleShot(500, qApp, &QCoreApplication::quit); } } void OsdTest::setUseDBus(bool yesno) { m_useDBus = yesno; } void OsdTest::showGenericOsd(const QString& icon, const QString& message) { if (!m_useDBus) { QTimer::singleShot(5500, qApp, &QCoreApplication::quit); KScreen::OsdManager::self()->showOsd(!icon.isEmpty() ? icon : QStringLiteral("preferences-desktop-display-randr"), !message.isEmpty() ? message : QStringLiteral("On-Screen-Display")); } else { qCWarning(KSCREEN_KDED) << "Implement me."; QTimer::singleShot(100, qApp, &QCoreApplication::quit); } } +void OsdTest::showActionSelector() +{ + if (!m_useDBus) { + connect(KScreen::OsdManager::self(), &KScreen::OsdManager::osdActionSelected, + [](const QString &action) { + qCDebug(KSCREEN_KDED) << "Action selected:" << action; + qApp->quit(); + }); + KScreen::OsdManager::self()->showActionSelector(); + } else { + qCWarning(KSCREEN_KDED) << "Implement me."; + QTimer::singleShot(100, qApp, &QCoreApplication::quit); + } +} } // ns diff --git a/tests/osd/osdtest.h b/tests/osd/osdtest.h index 279e443..3cf3c0a 100644 --- a/tests/osd/osdtest.h +++ b/tests/osd/osdtest.h @@ -1,47 +1,48 @@ /************************************************************************************* * Copyright 2016 Sebastian Kügler * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ #ifndef KSCREEN_OSDTEST_H #define KSCREEN_OSDTEST_H #include namespace KScreen { class OsdTest : public QObject { Q_OBJECT public: explicit OsdTest(QObject *parent = nullptr); virtual ~OsdTest(); void setUseDBus(bool yesno); void showGenericOsd(const QString &icon, const QString &message); void showOutputIdentifiers(); + void showActionSelector(); private: bool m_useDBus = false; }; } // namespace #endif // KSCREEN_OSDTEST_H