Skip to content

Commit a49534d

Browse files
committed
feat(Bar/Widgets/MediaMini): change volume on scroll
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
1 parent a50c921 commit a49534d

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

Modules/Bar/Widgets/MediaMini.qml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Item {
6464
readonly property bool shouldHideEmpty: !hasPlayer && hideMode === "hidden"
6565
readonly property bool isHidden: shouldHideIdle || shouldHideEmpty
6666

67+
// Volume scroll
68+
property int wheelAccumulator: 0
69+
6770
// Title
6871
readonly property string title: {
6972
if (!hasPlayer)
@@ -392,6 +395,27 @@ Item {
392395
cursorShape: Qt.PointingHandCursor
393396
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton | Qt.ForwardButton | Qt.BackButton
394397

398+
onWheel: function (ev) {
399+
// Hide tooltip as soon as the user starts scrolling to adjust volume
400+
TooltipService.hide();
401+
402+
ev.accepted = true;
403+
404+
var delta = ev.pixelDelta.y;
405+
406+
if (ev.inverted)
407+
delta *= -1;
408+
409+
wheelAccumulator += delta;
410+
if (wheelAccumulator >= 120) {
411+
wheelAccumulator = 0;
412+
MediaService.increaseVolume();
413+
} else if (wheelAccumulator <= -120) {
414+
wheelAccumulator = 0;
415+
MediaService.decreaseVolume();
416+
}
417+
}
418+
395419
onClicked: mouse => {
396420
TooltipService.hide();
397421
if (mouse.button === Qt.LeftButton) {

Services/Control/IPCService.qml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,14 @@ Singleton {
814814
}
815815
MediaService.seekByRatio(positionVal);
816816
}
817+
818+
function increase() {
819+
MediaService.increaseVolume();
820+
}
821+
822+
function decrease() {
823+
MediaService.decreaseVolume();
824+
}
817825
}
818826

819827
IpcHandler {

Services/Media/MediaService.qml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Singleton {
4545
property string lengthString: formatTime(trackLength)
4646
property real infiniteTrackLength: 922337203685
4747

48+
readonly property real stepVolume: Settings.data.audio.volumeStep / 100.0
49+
4850
Component.onCompleted: {
4951
updateCurrentPlayer();
5052
}
@@ -292,6 +294,20 @@ Singleton {
292294
}
293295
}
294296

297+
function increaseVolume() {
298+
let target = currentPlayer ? (currentPlayer._controlTarget || currentPlayer) : null;
299+
if (target && target.canControl && target.volumeSupported) {
300+
target.volume = Math.min(1.0, target.volume + stepVolume);
301+
}
302+
}
303+
304+
function decreaseVolume() {
305+
let target = currentPlayer ? (currentPlayer._controlTarget || currentPlayer) : null;
306+
if (target && target.canControl && target.volumeSupported) {
307+
target.volume = Math.max(0.0, target.volume - stepVolume);
308+
}
309+
}
310+
295311
// Update progress bar every second while playing
296312
Timer {
297313
id: positionTimer

0 commit comments

Comments
 (0)