diff --git a/kded/osd.cpp b/kded/osd.cpp index c1b207b..051c515 100644 --- a/kded/osd.cpp +++ b/kded/osd.cpp @@ -1,133 +1,133 @@ /* * 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 namespace KScreen { Osd::Osd(QObject *parent) : QObject(parent) , m_osdPath(QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation, QStringLiteral("kded_kscreen/qml/Osd.qml"))) , m_osdObject(new KDeclarative::QmlObject(this)) { if (m_osdPath.isEmpty()) { qCWarning(KSCREEN_KDED) << "Failed to find OSD QML file" << m_osdPath; } m_osdObject->setSource(QUrl::fromLocalFile(m_osdPath)); if (m_osdObject->status() != QQmlComponent::Ready) { qCWarning(KSCREEN_KDED) << "Failed to load OSD QML file" << m_osdPath; return; } m_timeout = m_osdObject->rootObject()->property("timeout").toInt(); if (!m_osdTimer) { m_osdTimer = new QTimer(this); m_osdTimer->setSingleShot(true); connect(m_osdTimer, &QTimer::timeout, this, &Osd::hideOsd); } } Osd::~Osd() { } void Osd::showOutputIdentifier(const KScreen::OutputPtr output) { m_outputGeometry = output->geometry(); auto *rootObject = m_osdObject->rootObject(); auto mode = output->currentMode(); QSize realSize; if (output->isHorizontal()) { realSize = mode->size(); } else { realSize = QSize(mode->size().height(), mode->size().width()); } 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")); 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(); - // if our OSD understands animating the opacity, do it; - // otherwise just show it to not break existing lnf packages - if (rootObject->property("animateOpacity").isValid()) { + // only animate on X11, wayland plugin doesn't support this and + // pukes loads of warnings into our logs + if (qGuiApp->platformName() == QStringLiteral("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); // this is needed to prevent fading from "old" values when the OSD shows up rootObject->setProperty("osdValue", 0); } } // ns diff --git a/kded/qml/Osd.qml b/kded/qml/Osd.qml index 69f35d2..65db294 100644 --- a/kded/qml/Osd.qml +++ b/kded/qml/Osd.qml @@ -1,51 +1,61 @@ /* * 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 outputName + property string modeName property bool animateOpacity: false - property string itemSource - property string outputName - property string modeName + 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; } } } }