Commit 9f2b9729 authored by Sebastian Kügler's avatar Sebastian Kügler Committed by Daniel Vrátil
Browse files

implement generic osd

The generic osd shows an icon and a text in an osd on all screens.

- doesn't work yet, but I need sleep
parent 38a30f92
......@@ -31,8 +31,9 @@
namespace KScreen {
Osd::Osd(QObject *parent)
Osd::Osd(const KScreen::OutputPtr output, QObject *parent)
: QObject(parent)
, m_output(output)
, m_osdPath(QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation, QStringLiteral("kded_kscreen/qml/Osd.qml")))
, m_osdObject(new KDeclarative::QmlObject(this))
{
......@@ -60,6 +61,18 @@ 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);
qCDebug(KSCREEN_KDED) << "icon / text:" << icon << text;
showOsd();
}
void Osd::showOutputIdentifier(const KScreen::OutputPtr output)
{
m_outputGeometry = output->geometry();
......@@ -75,7 +88,7 @@ void Osd::showOutputIdentifier(const KScreen::OutputPtr output)
rootObject->setProperty("itemSource", QStringLiteral("OutputIdentifier.qml"));
rootObject->setProperty("modeName", Utils::sizeToString(realSize));
rootObject->setProperty("outputName", Utils::outputName(output));
rootObject->setProperty("icon", QStringLiteral("preferences-desktop-display-randr"));
//rootObject->setProperty("icon", QStringLiteral("preferences-desktop-display-randr"));
showOsd();
}
......@@ -96,6 +109,8 @@ void Osd::updatePosition()
rootObject->setProperty("x", pos_x);
rootObject->setProperty("y", pos_y);
qCDebug(KSCREEN_KDED) << "pos:" << QPoint(pos_x, pos_y);
}
void Osd::showOsd()
......@@ -107,6 +122,7 @@ void Osd::showOsd()
// only animate on X11, wayland plugin doesn't support this and
// pukes loads of warnings into our logs
if (qGuiApp->platformName() == QStringLiteral("xcb")) {
qCDebug(KSCREEN_KDED) << "vibsible";
rootObject->setProperty("animateOpacity", false);
rootObject->setProperty("opacity", 1);
rootObject->setProperty("visible", true);
......@@ -126,8 +142,6 @@ void Osd::hideOsd()
return;
}
rootObject->setProperty("visible", false);
// this is needed to prevent fading from "old" values when the OSD shows up
rootObject->setProperty("osdValue", 0);
}
} // ns
......@@ -39,11 +39,13 @@ class Osd : public QObject {
Q_OBJECT
public:
Osd(QObject *parent = nullptr);
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 Q_SLOTS:
void hideOsd();
......@@ -51,6 +53,7 @@ private:
void showOsd();
void updatePosition();
KScreen::OutputPtr m_output;
QString m_osdPath;
QRect m_outputGeometry;
KDeclarative::QmlObject *m_osdObject = nullptr;
......
......@@ -18,6 +18,7 @@
#include "osdmanager.h"
#include "osd.h"
#include "debug.h"
#include <KScreen/Config>
#include <KScreen/GetConfigOperation>
......@@ -79,7 +80,7 @@ void OsdManager::slotIdentifyOutputs(KScreen::ConfigOperation *op)
if (m_osds.keys().contains(output->name())) {
osd = m_osds.value(output->name());
} else {
osd = new KScreen::Osd(this);
osd = new KScreen::Osd(output, this);
m_osds.insert(output->name(), osd);
}
osd->showOutputIdentifier(output);
......@@ -87,5 +88,33 @@ void OsdManager::slotIdentifyOutputs(KScreen::ConfigOperation *op)
m_cleanupTimer->start();
}
void OsdManager::showOsd(const QString& icon, const QString& text)
{
connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished,
this, [this, icon, text] (KScreen::ConfigOperation *op) {
qCDebug(KSCREEN_KDED) << "whoooooopwhoooooopwhoooooop";
if (op->hasError()) {
return;
}
const KScreen::ConfigPtr config = qobject_cast<KScreen::GetConfigOperation*>(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();
});
}
}
......@@ -42,6 +42,7 @@ public:
public Q_SLOTS:
void showOutputIdentifiers();
void showOsd(const QString &icon, const QString &text);
private:
OsdManager(QObject *parent = nullptr);
......
......@@ -31,6 +31,7 @@ PlasmaCore.Dialog {
// Icon name to display
property string icon
property string infoText
property string outputName
property string modeName
property bool animateOpacity: false
......
......@@ -41,7 +41,7 @@ Item {
margins: Math.floor(units.smallSpacing / 2)
}
text: outputName
text: rootItem.infoText
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
maximumLineCount: 2
......@@ -49,4 +49,5 @@ Item {
minimumPointSize: theme.defaultFont.pointSize
fontSizeMode: Text.HorizontalFit
}
Component.onCompleted: print("osditem loaded..." + root.infoText);
}
......@@ -37,7 +37,8 @@ OsdTest::~OsdTest()
void OsdTest::start()
{
QTimer::singleShot(5500, qApp, &QCoreApplication::quit);
KScreen::OsdManager::self()->showOutputIdentifiers();
// KScreen::OsdManager::self()->showOutputIdentifiers();
KScreen::OsdManager::self()->showOsd(QStringLiteral("preferences-desktop-display-randr"), QStringLiteral("OSD Showing Up"));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment