diff --git a/kded/osd.cpp b/kded/osd.cpp index 3c716f1..c6f07c0 100644 --- a/kded/osd.cpp +++ b/kded/osd.cpp @@ -1,137 +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 "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::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.cpp b/kded/osdmanager.cpp index 08a7772..cead698 100644 --- a/kded/osdmanager.cpp +++ b/kded/osdmanager.cpp @@ -1,124 +1,123 @@ /* * 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 "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() { - 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/tests/osd/CMakeLists.txt b/tests/osd/CMakeLists.txt index b7c5e9e..a98ed36 100644 --- a/tests/osd/CMakeLists.txt +++ b/tests/osd/CMakeLists.txt @@ -1,20 +1,23 @@ -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 ../../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)