1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-03-24 02:50:35 +03:00

fix #438,add wheel events

--by using wheel events the volume can
be increased/decreased
This commit is contained in:
Michail Vourlakos 2017-05-02 20:59:46 +03:00
parent d18d4eb037
commit c4171dff86
3 changed files with 36 additions and 2 deletions

View File

@ -65,10 +65,9 @@ Item {
border.color: root.minimizedDotColor
radius: width/2
opacity: mainItemContainer.playingAudio && !mainItemContainer.muted ? 1 : 0.5
opacity: mainItemContainer.playingAudio && !mainItemContainer.muted && mainItemContainer.volume>0 ? 1 : 0.5
}
Latte.IconItem{
id: audioStreamIcon
anchors.fill: parent
@ -87,7 +86,17 @@ Item {
MouseArea{
anchors.fill: parent
onClicked: mainItemContainer.toggleMuted();
onWheel: {
var angle = wheel.angleDelta.y / 8;
if (angle > 12)
mainItemContainer.increaseVolume();
else if (angle < 12)
mainItemContainer.decreaseVolume();
}
}
}
}

View File

@ -29,6 +29,14 @@ QtObject {
// It's a JS object so we can do key lookup and don't need to take care of filtering duplicates.
property var pidMatches: ({})
property int maxVolumePercent: 125
property int maxVolumeValue: Math.round(maxVolumePercent * PulseAudio.NormalVolume / 100.0)
property int volumeStep: Math.round(3 * PulseAudio.NormalVolume / 100.0)
function boundVolume(volume) {
return Math.max(PulseAudio.MinimalVolume, Math.min(volume, maxVolumeValue));
}
// TODO Evict cache at some point, preferably if all instances of an application closed.
function registerPidMatch(appName) {
if (!hasPidMatch(appName)) {
@ -88,6 +96,15 @@ QtObject {
Muted = false
}
function increaseVolume() {
var bVolume = pulseAudio.boundVolume(Volume + pulseAudio.volumeStep);
Volume = bVolume;
}
function decreaseVolume() {
var bVolume = pulseAudio.boundVolume(Volume - pulseAudio.volumeStep);
Volume = bVolume;
}
}
onObjectAdded: pulseAudio.streamsChanged()

View File

@ -1197,6 +1197,14 @@ MouseArea{
}
}
function increaseVolume() {
mainItemContainer.audioStreams.forEach(function (item) { item.increaseVolume(); });
}
function decreaseVolume() {
mainItemContainer.audioStreams.forEach(function (item) { item.decreaseVolume(); });
}
Connections {
target: pulseAudio.item
ignoreUnknownSignals: true // Plasma-PA might not be available