Repository navigation
fix(osd): speed up Super+P display-mode checkmarks #1914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,65 @@ | ||
| // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
| // SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #include "audioapplet.h" | ||
|
|
||
| #include "pluginfactory.h" | ||
|
|
||
| #include <QDBusConnection> | ||
| #include <QDBusMessage> | ||
| #include <QDBusPendingCall> | ||
| #include <QDBusReply> | ||
|
|
||
| #include <DDBusSender> | ||
|
|
||
| namespace osd { | ||
|
|
||
| const QString audioService = QStringLiteral("org.deepin.dde.Audio1"); | ||
| const QString audioPath = QStringLiteral("/org/deepin/dde/Audio1"); | ||
| const QString audioSinkInterface = QStringLiteral("org.deepin.dde.Audio1.Sink"); | ||
|
|
||
| static DDBusSender audioInter() | ||
| { | ||
| return DDBusSender().service("org.deepin.dde.Audio1") | ||
| .path("/org/deepin/dde/Audio1") | ||
| .interface("org.deepin.dde.Audio1"); | ||
| return DDBusSender().service(audioService) | ||
| .path(audioPath) | ||
| .interface(audioService); | ||
| } | ||
|
|
||
| static DDBusSender audioSinkInter() | ||
| static DDBusSender audioSinkInter(const QString &sinkPath) | ||
| { | ||
| return DDBusSender().service(audioService) | ||
| .path(sinkPath) | ||
| .interface(audioSinkInterface); | ||
| } | ||
|
|
||
| static std::optional<QString> fetchDefaultSinkPath() | ||
| { | ||
| QDBusReply<QVariant> defaultSink = audioInter().property("DefaultSink").get(); | ||
| if (!defaultSink.isValid()) { | ||
| qWarning() << "Failed to fetch DefaultSink" << defaultSink.error(); | ||
| return DDBusSender(); | ||
| return std::nullopt; | ||
| } | ||
| const auto path = qdbus_cast<QDBusObjectPath>(defaultSink); | ||
| return DDBusSender().service("org.deepin.dde.Audio1") | ||
| .path(path.path()) | ||
| .interface("org.deepin.dde.Audio1.Sink"); | ||
| return qdbus_cast<QDBusObjectPath>(defaultSink).path(); | ||
| } | ||
|
|
||
| AudioApplet::AudioApplet(QObject *parent) | ||
| : DApplet(parent) | ||
| { | ||
| } | ||
|
|
||
| bool AudioApplet::load() | ||
| { | ||
| if (!DApplet::load()) | ||
| return false; | ||
|
|
||
| // Subscribe before reading the initial state so changes during sync are delivered as well. | ||
| QDBusConnection::sessionBus().connect( | ||
| audioService, QString(), | ||
| QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged"), | ||
| this, SLOT(onAudioPropertiesChanged(QString,QVariantMap,QStringList,QDBusMessage))); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| bool AudioApplet::increaseVolume() const | ||
|
|
@@ -55,21 +77,85 @@ | |
|
|
||
| void AudioApplet::sync() | ||
| { | ||
| setVolumeValue(fetchVolume()); | ||
| if (const auto sinkPath = fetchDefaultSinkPath()) | ||
| updateDefaultSink(*sinkPath); | ||
| } | ||
|
|
||
| void AudioApplet::updateDefaultSink(const QString &sinkPath) | ||
| { | ||
| m_sinkPath = sinkPath; | ||
| readSinkState(true, true); | ||
| setIncreaseVolume(fetchIncreaseVolume()); | ||
| setIconName(fetchIconName()); | ||
| } | ||
|
|
||
| void AudioApplet::readSinkState(bool readVolume, bool readMute) | ||
| { | ||
| if (!readVolume && !readMute) | ||
| return; | ||
|
|
||
| if (m_sinkPath.isEmpty() || m_sinkPath == QStringLiteral("/")) { | ||
| m_muted.reset(); | ||
| setVolumeValue(0.0); | ||
| return; | ||
| } | ||
|
|
||
| auto sink = audioSinkInter(m_sinkPath); | ||
| if (readMute) { | ||
| const QDBusReply<QVariant> reply = sink.property("Mute").get(); | ||
| if (reply.isValid()) { | ||
| m_muted = qdbus_cast<bool>(reply); | ||
| } else { | ||
| qWarning() << "Failed to fetch Mute" << reply.error(); | ||
| m_muted.reset(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Transient reads corrupt audio OSD When an invalidated Mute or Volume property is re-read while the audio service returns a D-Bus error, Keep the cached property value when its refresh fails, and update the OSD only with successfully read values. Also at Prompt for AI agentsIn `panels/notification/osd/audio/audioapplet.cpp` at line 110:
**Transient reads corrupt audio OSD**
When an invalidated Mute or Volume property is re-read while the audio service returns a D-Bus error, `readSinkState` clears `m_muted` or stores `fetchVolume`’s `0.0` fallback instead of retaining the last valid value, so the visible OSD loses its icon or reports zero volume.
Keep the cached property value when its refresh fails, and update the OSD only with successfully read values.
Also at `panels/notification/osd/audio/audioapplet.cpp:114`. |
||
| } | ||
| } | ||
| if (readVolume) | ||
| setVolumeValue(fetchVolume(sink)); | ||
| } | ||
|
|
||
| void AudioApplet::onAudioPropertiesChanged(const QString &interface, const QVariantMap &changed, | ||
| const QStringList &invalidated, const QDBusMessage &message) | ||
| { | ||
| if (interface == audioService && message.path() == audioPath) { | ||
| const auto defaultSink = changed.constFind(QStringLiteral("DefaultSink")); | ||
| if (defaultSink != changed.cend()) { | ||
| updateDefaultSink(qdbus_cast<QDBusObjectPath>(*defaultSink).path()); | ||
| } else if (invalidated.contains(QStringLiteral("DefaultSink"))) { | ||
| sync(); | ||
| } | ||
| return; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Progress scale stays outdated When the audio service changes Handle Also at Prompt for AI agentsIn `panels/notification/osd/audio/audioapplet.cpp` at line 128:
**Progress scale stays outdated**
When the audio service changes `IncreaseVolume` while the default sink stays the same, `onAudioPropertiesChanged()` returns without refreshing `m_increaseVolume`, so the visible OSD uses the old progress-bar scale and boost marks.
Handle `IncreaseVolume` changes in `onAudioPropertiesChanged()` even when the default sink does not change.
Also at `panels/notification/osd/audio/audioapplet.cpp:127`. |
||
|
|
||
| if (interface != audioSinkInterface || message.path() != m_sinkPath) | ||
| return; | ||
|
|
||
| const auto volume = changed.constFind(QStringLiteral("Volume")); | ||
| const auto mute = changed.constFind(QStringLiteral("Mute")); | ||
| const bool hasVolume = volume != changed.cend(); | ||
| const bool hasMute = mute != changed.cend(); | ||
| const bool readVolume = !hasVolume && invalidated.contains(QStringLiteral("Volume")); | ||
| const bool readMute = !hasMute && invalidated.contains(QStringLiteral("Mute")); | ||
| if (!hasVolume && !hasMute && !readVolume && !readMute) | ||
| return; | ||
|
|
||
| if (hasMute) | ||
| m_muted = mute->toBool(); | ||
|
|
||
| if (hasVolume) | ||
| setVolumeValue(volume->toDouble()); | ||
|
|
||
| readSinkState(readVolume, readMute); | ||
| setIconName(fetchIconName()); | ||
| } | ||
|
|
||
| QString AudioApplet::fetchIconName() const | ||
| { | ||
| QDBusReply<QVariant> muteReply = audioSinkInter().property("Mute").get(); | ||
| if (!muteReply.isValid()) { | ||
| qWarning() << "Failed to fetch Mute" << muteReply.error(); | ||
| return QString(); | ||
| if (!m_muted.has_value()) { | ||
| return {}; | ||
| } | ||
| if (qdbus_cast<bool>(muteReply)) { | ||
|
|
||
| if (*m_muted) { | ||
| return "osd_volume_mute"; | ||
| } | ||
|
|
||
|
|
@@ -88,11 +174,11 @@ | |
| return QString("osd_volume_%1").arg(level); | ||
| } | ||
|
|
||
| double AudioApplet::fetchVolume() const | ||
| double AudioApplet::fetchVolume(DDBusSender &sink) const | ||
| { | ||
| QDBusReply<QVariant> volumeReply = audioSinkInter().property("Volume").get(); | ||
| QDBusReply<QVariant> volumeReply = sink.property("Volume").get(); | ||
| if (!volumeReply.isValid()) { | ||
| qWarning() << "Failed to Volume Volume" << volumeReply.error(); | ||
| qWarning() << "Failed to fetch Volume" << volumeReply.error(); | ||
| return 0.0; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · OSD shows stale output state
When the DefaultSink read fails during an output switch or while an audio OSD request is being synced,
AudioApplet::sync()leavesm_sinkPathand the displayed state unchanged; after an output switch, notifications from the new sink are ignored because their path does not matchm_sinkPath, so the OSD shows stale output data.Handle a failed
DefaultSinkread so the cached sink and displayed state cannot remain stale.Also at
panels/notification/osd/audio/audioapplet.cpp:125.Prompt for AI agents