mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
fix: 声音插件滚轮调节音量
未考虑音量增强的情况,以及修复音量在1时无法继续减少,在99时无法继续增加的问题 Log: Influence: 将鼠标放在任务栏声音图标上,滚动滚轮,观察音量大小是否调节 Bug: https://pms.uniontech.com/bug-view-172417.html Change-Id: I07878e9c967152698f4c72323b98f1ed19c9c41d
This commit is contained in:
parent
cb620469e3
commit
9619df590c
@ -191,16 +191,24 @@ bool SoundPlugin::eventHandler(QEvent *event)
|
||||
QDBusReply<QVariant> volumePath = volumeCall.reply();
|
||||
double volume = volumePath.value().value<double>();
|
||||
|
||||
// 获取当前默认声音设备的最大音量
|
||||
DDBusSender audioDBus = DDBusSender().service("org.deepin.dde.Audio1")
|
||||
.path("/org/deepin/dde/Audio1").interface("org.deepin.dde.Audio1");
|
||||
QDBusPendingCall call = audioDBus.property("MaxUIVolume").get();
|
||||
call.waitForFinished();
|
||||
QDBusReply<QVariant> maxVolumeReply = call.reply();
|
||||
double maxVolume = maxVolumeReply.value().value<double>();
|
||||
|
||||
// 根据滚轮的动作来增加音量或者减小音量
|
||||
QWheelEvent *wheelEvent = static_cast<QWheelEvent *>(event);
|
||||
if (wheelEvent->angleDelta().y() > 0) {
|
||||
// 向上滚动,增大音量
|
||||
if (volume < 1)
|
||||
sinkDBus.method("SetVolume").arg(volume + 0.02).arg(true).call();
|
||||
if (volume < maxVolume)
|
||||
sinkDBus.method("SetVolume").arg(qMin(volume + 0.02, maxVolume)).arg(true).call();
|
||||
} else {
|
||||
// 向下滚动,调小音量
|
||||
if (volume > 0)
|
||||
sinkDBus.method("SetVolume").arg(volume - 0.02).arg(true).call();
|
||||
sinkDBus.method("SetVolume").arg(qMax(volume - 0.02, 0.0)).arg(true).call();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user