mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
volumeosd: Listen to osd service for opening the popup
Fixes: https://invent.kde.org/plasma/plasma-mobile/-/issues/423 We currently listen to when the volume changes, which wouldn't happen if the user reaches 0% or 100% and continues trying to press the volume button. Instead, listen to OSD events for determining when to open the popup.
This commit is contained in:
parent
c3e1bd607b
commit
447049d570
5 changed files with 80 additions and 12 deletions
|
|
@ -6,6 +6,7 @@ pragma Singleton
|
|||
import QtQuick
|
||||
|
||||
import org.kde.plasma.private.volume
|
||||
import org.kde.plasma.private.mobileshell as MobileShell
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
|
|
@ -100,21 +101,16 @@ QtObject {
|
|||
return icon;
|
||||
}
|
||||
|
||||
// emitted when the volume changed, but not due to sink switching
|
||||
signal volumeChanged()
|
||||
|
||||
property var updateVolume: Connections {
|
||||
target: root.paSinkModel ? (PreferredDevice.sink ? PreferredDevice.sink : null) : null
|
||||
enabled: target !== null
|
||||
|
||||
function onVolumeChanged() {
|
||||
root.volumeValue = root.volumePercent(PreferredDevice.sink.volume, root.maxVolumeValue);
|
||||
root.volumeChanged();
|
||||
}
|
||||
|
||||
function onMutedChanged() {
|
||||
root.volumeValue = PreferredDevice.sink.muted ? 0 : root.volumePercent(PreferredDevice.sink.volume, root.maxVolumeValue);
|
||||
root.volumeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,14 +19,14 @@ import org.kde.plasma.private.mobileshell as MobileShell
|
|||
QtObject {
|
||||
id: component
|
||||
|
||||
function showVolumeOverlay() {
|
||||
if (!osd.visible) {
|
||||
vcp.showOverlay();
|
||||
}
|
||||
}
|
||||
property var osdListener: Connections {
|
||||
target: MobileShellState.VolumeOSDListener
|
||||
|
||||
Component.onCompleted: {
|
||||
MobileShell.AudioInfo.volumeChanged.connect(showVolumeOverlay);
|
||||
function onShowOSD(icon, volume, maxVolume) {
|
||||
if (!osd.visible) {
|
||||
vcp.showOverlay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
property var apiListener: Connections {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ set(mobileshellstateplugin_SRCS
|
|||
lockscreendbusclient.cpp
|
||||
startupfeedbackmodel.cpp
|
||||
windowlistener.cpp
|
||||
volumeosdlistener.cpp
|
||||
)
|
||||
|
||||
qt_generate_dbus_interface(
|
||||
|
|
|
|||
45
components/mobileshellstate/volumeosdlistener.cpp
Normal file
45
components/mobileshellstate/volumeosdlistener.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// SPDX-FileCopyrightText: 2025 Devin Lin <devin@kde.org>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "volumeosdlistener.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QDBusServiceWatcher>
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
VolumeOSDListener::VolumeOSDListener(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
QDBusServiceWatcher *watcher =
|
||||
new QDBusServiceWatcher(QStringLiteral("org.kde.plasmashell"), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this);
|
||||
|
||||
connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, [this]() -> void {
|
||||
connectDBus();
|
||||
});
|
||||
|
||||
connectDBus();
|
||||
}
|
||||
|
||||
void VolumeOSDListener::connectDBus()
|
||||
{
|
||||
bool success = QDBusConnection::sessionBus().connect(QStringLiteral("org.kde.plasmashell"),
|
||||
QStringLiteral("/org/kde/osdService"),
|
||||
QStringLiteral("org.kde.osdService"),
|
||||
QStringLiteral("osdProgress"),
|
||||
this,
|
||||
SLOT(onOSDProgress(QString, int, int, QString)));
|
||||
}
|
||||
|
||||
void VolumeOSDListener::onOSDProgress(const QString &icon, int volume, int maxVolume, const QString &text)
|
||||
{
|
||||
Q_UNUSED(text)
|
||||
|
||||
if (icon == "audio-volume-muted"_L1 || icon == "audio-volume-low"_L1 || icon == "audio-volume-medium"_L1 || icon == "audio-volume-high"_L1) {
|
||||
Q_EMIT showOSD(icon, volume, maxVolume);
|
||||
}
|
||||
}
|
||||
26
components/mobileshellstate/volumeosdlistener.h
Normal file
26
components/mobileshellstate/volumeosdlistener.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// SPDX-FileCopyrightText: 2025 Devin Lin <devin@kde.org>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <qqmlregistration.h>
|
||||
|
||||
class VolumeOSDListener : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
QML_SINGLETON
|
||||
|
||||
public:
|
||||
VolumeOSDListener(QObject *parent = nullptr);
|
||||
|
||||
Q_SIGNALS:
|
||||
void showOSD(const QString &icon, int volume, int maxVolume);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onOSDProgress(const QString &icon, int volume, int maxVolume, const QString &text);
|
||||
|
||||
private:
|
||||
void connectDBus();
|
||||
};
|
||||
Loading…
Reference in a new issue