diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,11 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) find_package(Qt5 REQUIRED COMPONENTS QuickWidgets Test) -find_package(KF5 REQUIRED COMPONENTS DBusAddons Config ConfigWidgets I18n XmlGui GlobalAccel WidgetsAddons) +find_package(KF5 REQUIRED COMPONENTS DBusAddons Config ConfigWidgets I18n XmlGui GlobalAccel WidgetsAddons + Declarative IconThemes Plasma +) +# WARNING PlasmaQuick provides unversioned CMake config +find_package(KF5 REQUIRED COMPONENTS PlasmaQuick) set(MIN_LIBKSCREEN_VERSION "5.2.91") find_package(KF5Screen ${MIN_LIBKSCREEN_VERSION} REQUIRED) diff --git a/kded/CMakeLists.txt b/kded/CMakeLists.txt --- a/kded/CMakeLists.txt +++ b/kded/CMakeLists.txt @@ -1,13 +1,16 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kscreen\") -include_directories(${CMAKE_CURRENT_BINARY_DIR}/../) +include_directories(${CMAKE_CURRENT_BINARY_DIR}/../ ${CMAKE_SOURCE_DIR}/kcm/src) set(kscreen_daemon_SRCS debug.cpp daemon.cpp serializer.cpp generator.cpp device.cpp + osd.cpp + osdmanager.cpp + ${CMAKE_SOURCE_DIR}/kcm/src/utils.cpp ) qt5_add_dbus_interface(kscreen_daemon_SRCS @@ -21,12 +24,28 @@ add_library(kscreen MODULE ${kscreen_daemon_SRCS}) -target_link_libraries(kscreen Qt5::Widgets Qt5::DBus KF5::Screen KF5::DBusAddons KF5::I18n KF5::XmlGui KF5::GlobalAccel) +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/OutputIdentifier.qml +) + +install(FILES ${QML_FILES} DESTINATION ${DATA_INSTALL_DIR}/kded_kscreen/qml) diff --git a/kded/daemon.h b/kded/daemon.h --- a/kded/daemon.h +++ b/kded/daemon.h @@ -60,6 +60,7 @@ void lidClosedTimeout(); void setMonitorForChanges(bool enabled); void outputConnectedChanged(); + void showOutputIdentifier(); 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 @@ -22,6 +22,7 @@ #include "generator.h" #include "device.h" #include "kscreenadaptor.h" +#include "osdmanager.h" #include "debug.h" #include @@ -240,15 +241,19 @@ QDBusConnection::sessionBus().asyncCall(msg); } +void KScreenDaemon::showOutputIdentifier() +{ + KScreen::OsdManager::self()->showOutputIdentifiers(); +} + void KScreenDaemon::displayButton() { qCDebug(KSCREEN_KDED) << "displayBtn triggered"; QString message = i18nc("OSD text after XF86Display button press", "No External Display"); if (m_monitoredConfig && m_monitoredConfig->connectedOutputs().count() > 1) { message = i18nc("OSD text after XF86Display button press", "Changing Screen Layout"); } - showOsd(QStringLiteral("preferences-desktop-display-randr"), message); if (m_buttonTimer->isActive()) { qCDebug(KSCREEN_KDED) << "Too fast, cowboy"; @@ -273,6 +278,23 @@ m_iteration = Generator::DisplaySwitchAction(static_cast(m_iteration) + 1); qCDebug(KSCREEN_KDED) << "displayButton: " << m_iteration; + static QHash actionMessages({ + {Generator::DisplaySwitchAction::None, i18nc("osd when displaybutton is pressed", "No Action")}, + {Generator::DisplaySwitchAction::Clone, i18nc("osd when displaybutton is pressed", "Cloned Display")}, + {Generator::DisplaySwitchAction::ExtendToLeft, i18nc("osd when displaybutton is pressed", "Extend Left")}, + {Generator::DisplaySwitchAction::TurnOffEmbedded, i18nc("osd when displaybutton is pressed", "External Only")}, + {Generator::DisplaySwitchAction::TurnOffExternal, i18nc("osd when displaybutton is pressed", "Internal Only")}, + {Generator::DisplaySwitchAction::ExtendToRight, i18nc("osd when displaybutton is pressed", "Extended Right")} + }); + const QString &message = actionMessages.value(m_iteration); + + // We delay the OSD for two seconds and hope that X and hardware are done setting everything up. + QTimer::singleShot(2000, + [message]() { + KScreen::OsdManager::self()->showOsd(QStringLiteral("preferences-desktop-display-randr"), message); + } + ); + doApplyConfig(Generator::self()->displaySwitch(m_iteration)); } @@ -430,5 +452,4 @@ } - #include "daemon.moc" diff --git a/kded/osd.h b/kded/osd.h new file mode 100644 --- /dev/null +++ b/kded/osd.h @@ -0,0 +1,63 @@ +/* + * 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); + +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/osd.cpp b/kded/osd.cpp new file mode 100644 --- /dev/null +++ b/kded/osd.cpp @@ -0,0 +1,137 @@ +/* + * 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 "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::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")) { + 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); + } + updatePosition(); + m_osdTimer->start(m_timeout); +} + +void Osd::hideOsd() +{ + auto *rootObject = m_osdObject->rootObject(); + if (!rootObject) { + return; + } + rootObject->setProperty("visible", false); +} + diff --git a/kded/osdmanager.h b/kded/osdmanager.h new file mode 100644 --- /dev/null +++ b/kded/osdmanager.h @@ -0,0 +1,57 @@ +/* + * 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); + +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/osdmanager.cpp b/kded/osdmanager.cpp new file mode 100644 --- /dev/null +++ b/kded/osdmanager.cpp @@ -0,0 +1,124 @@ +/* + * 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 "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() +{ + qDebug() << "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(); + } + ); +} + + +} diff --git a/kded/qml/Osd.qml b/kded/qml/Osd.qml new file mode 100644 --- /dev/null +++ b/kded/qml/Osd.qml @@ -0,0 +1,62 @@ +/* + * 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 + + 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.animateOpacity + } + + mainItem: Loader { + source: itemSource + onItemChanged: { + if (item != undefined) { + item.rootItem = root; + } + } + + } +} diff --git a/kded/qml/OsdItem.qml b/kded/qml/OsdItem.qml new file mode 100644 --- /dev/null +++ b/kded/qml/OsdItem.qml @@ -0,0 +1,56 @@ +/* + * 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.5 +import QtQuick.Window 2.2 + +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.extras 2.0 as PlasmaExtras + +Item { + property QtObject rootItem + + height: Math.min(units.gridUnit * 15, Screen.desktopAvailableHeight / 5) + width: height + + PlasmaCore.IconItem { + id: icon + height: parent.height - label.height - ((units.smallSpacing/2) * 3) + width: parent.width + source: rootItem.icon + } + + 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("osditem loaded..." + root.infoText); +} diff --git a/kded/qml/OutputIdentifier.qml b/kded/qml/OutputIdentifier.qml new file mode 100644 --- /dev/null +++ b/kded/qml/OutputIdentifier.qml @@ -0,0 +1,57 @@ +/* + * 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.5 +import QtQuick.Layouts 1.3 +import QtQuick.Window 2.2 + +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents + +ColumnLayout { + + property QtObject rootItem + + property string outputName: rootItem ? rootItem.outputName : "" + property string modeName: rootItem ? rootItem.modeName : "" + + PlasmaComponents.Label { + id: displayName + + Layout.maximumWidth: Screen.width * 0.8 + Layout.maximumHeight: Screen.height * 0.8 + Layout.margins: units.largeSpacing + Layout.bottomMargin: units.smallSpacing + + text: root.outputName + font.pointSize: theme.defaultFont.pointSize * 3 + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WordWrap + maximumLineCount: 2 + elide: Text.ElideLeft + } + + PlasmaComponents.Label { + id: modeLabel; + + Layout.fillWidth: true + Layout.bottomMargin: units.largeSpacing + + text: root.modeName; + horizontalAlignment: Text.AlignHCenter; + } +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1 +1,2 @@ -add_subdirectory(kded) \ No newline at end of file +add_subdirectory(kded) +add_subdirectory(osd) diff --git a/tests/osd/CMakeLists.txt b/tests/osd/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/tests/osd/CMakeLists.txt @@ -0,0 +1,20 @@ +include_directories(${CMAKE_SOURCE_DIR}/kcm/src) + +add_executable(osdtest main.cpp + osdtest.cpp + ../../kded/osd.cpp + ../../kded/osdmanager.cpp + ../../kcm/src/utils.cpp +) + +target_link_libraries(osdtest Qt5::Core + Qt5::DBus + Qt5::Quick + Qt5::Qml + KF5::Screen + KF5::I18n + KF5::Declarative +) + +add_test(kscreen-kded-osdtest osdtest) +ecm_mark_as_test(osdtest) diff --git a/tests/osd/main.cpp b/tests/osd/main.cpp new file mode 100644 --- /dev/null +++ b/tests/osd/main.cpp @@ -0,0 +1,60 @@ +/************************************************************************************* + * 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")); + KScreen::OsdTest osdtest; + QCommandLineParser parser; + parser.addHelpOption(); + parser.addOption(dbus); + parser.addOption(outputid); + parser.addOption(icon); + parser.addOption(message); + parser.process(app); + + + + if (parser.isSet(dbus)) { + osdtest.setUseDBus(true); + } + if (parser.isSet(outputid)) { + + osdtest.showOutputIdentifiers(); + } else { + osdtest.showGenericOsd(parser.value(icon), parser.value(message)); + } + if (parser.isSet(outputid)) { + } + + return app.exec(); +} diff --git a/tests/osd/osdtest.h b/tests/osd/osdtest.h new file mode 100644 --- /dev/null +++ b/tests/osd/osdtest.h @@ -0,0 +1,47 @@ +/************************************************************************************* + * 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(); + +private: + bool m_useDBus = false; +}; + +} // namespace + +#endif // KSCREEN_OSDTEST_H diff --git a/tests/osd/osdtest.cpp b/tests/osd/osdtest.cpp new file mode 100644 --- /dev/null +++ b/tests/osd/osdtest.cpp @@ -0,0 +1,79 @@ +/************************************************************************************* + * 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); + } +} + + +} // ns