diff --git a/applets/mediacontroller/contents/ui/main.qml b/applets/mediacontroller/contents/ui/main.qml --- a/applets/mediacontroller/contents/ui/main.qml +++ b/applets/mediacontroller/contents/ui/main.qml @@ -147,6 +147,17 @@ anchors.fill: parent hoverEnabled: true acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.BackButton | Qt.ForwardButton + + onWheel: { // change volume + var volume = mpris2Source.currentData.Volume || 0.0 + volume += (wheel.angleDelta.y / 120) * 0.03 + if (volume < 0) volume = 0.0 + var service = mpris2Source.serviceForSource(mpris2Source.current) + var operation = service.operationDescription("SetVolume") + operation.level = volume + service.startOperationCall(operation) + } + onClicked: { switch (mouse.button) { case Qt.MiddleButton: diff --git a/dataengines/mpris2/multiplexedservice.cpp b/dataengines/mpris2/multiplexedservice.cpp --- a/dataengines/mpris2/multiplexedservice.cpp +++ b/dataengines/mpris2/multiplexedservice.cpp @@ -126,5 +126,29 @@ } } ); + + QAction *volumeupAction = m_actionCollection->addAction(QStringLiteral("mediavolumeup")); + volumeupAction->setText(i18n("Media volume up")); + KGlobalAccel::setGlobalShortcut(volumeupAction, QKeySequence()); + connect(volumeupAction, &QAction::triggered, this, + [this] { + if (m_control) { + double vol = m_control->playerInterface()->volume() + 0.05; + m_control->playerInterface()->setVolume(vol); + } + } + ); + + QAction *volumedownAction = m_actionCollection->addAction(QStringLiteral("mediavolumedown")); + volumedownAction->setText(i18n("Media volume down")); + KGlobalAccel::setGlobalShortcut(volumedownAction, QKeySequence()); + connect(volumedownAction, &QAction::triggered, this, + [this] { + if (m_control) { + double vol = m_control->playerInterface()->volume() - 0.05; + m_control->playerInterface()->setVolume(vol < 0.0 ? 0.0 : vol); + } + } + ); }