mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-25 05:52:50 -05:00
Bar (mediaplayer): Mouse wheel options for media player widget (#1248)
* Add different options for scroll on media widget. * Nicer lookup code. * Remove some checks I didn't need. * Update the search tags. * EOF.
This commit is contained in:
@@ -54,38 +54,67 @@ BasePill {
|
||||
property real touchpadThreshold: 100
|
||||
|
||||
onWheel: function (wheelEvent) {
|
||||
if (!usePlayerVolume)
|
||||
return;
|
||||
if (!SettingsData.audioScrollEnabled)
|
||||
if (SettingsData.audioScrollMode === "nothing")
|
||||
return;
|
||||
|
||||
wheelEvent.accepted = true;
|
||||
if (SettingsData.audioScrollMode === "volume") {
|
||||
if (!usePlayerVolume)
|
||||
return;
|
||||
|
||||
const deltaY = wheelEvent.angleDelta.y;
|
||||
const isMouseWheelY = Math.abs(deltaY) >= 120 && (Math.abs(deltaY) % 120) === 0;
|
||||
wheelEvent.accepted = true;
|
||||
|
||||
const currentVolume = activePlayer.volume * 100;
|
||||
const deltaY = wheelEvent.angleDelta.y;
|
||||
const isMouseWheelY = Math.abs(deltaY) >= 120 && (Math.abs(deltaY) % 120) === 0;
|
||||
|
||||
let newVolume = currentVolume;
|
||||
if (isMouseWheelY) {
|
||||
if (deltaY > 0) {
|
||||
newVolume = Math.min(100, currentVolume + 5);
|
||||
} else if (deltaY < 0) {
|
||||
newVolume = Math.max(0, currentVolume - 5);
|
||||
}
|
||||
} else {
|
||||
scrollAccumulatorY += deltaY;
|
||||
if (Math.abs(scrollAccumulatorY) >= touchpadThreshold) {
|
||||
if (scrollAccumulatorY > 0) {
|
||||
newVolume = Math.min(100, currentVolume + 1);
|
||||
} else {
|
||||
newVolume = Math.max(0, currentVolume - 1);
|
||||
const currentVolume = activePlayer.volume * 100;
|
||||
|
||||
let newVolume = currentVolume;
|
||||
if (isMouseWheelY) {
|
||||
if (deltaY > 0) {
|
||||
newVolume = Math.min(100, currentVolume + 5);
|
||||
} else if (deltaY < 0) {
|
||||
newVolume = Math.max(0, currentVolume - 5);
|
||||
}
|
||||
} else {
|
||||
scrollAccumulatorY += deltaY;
|
||||
if (Math.abs(scrollAccumulatorY) >= touchpadThreshold) {
|
||||
if (scrollAccumulatorY > 0) {
|
||||
newVolume = Math.min(100, currentVolume + 1);
|
||||
} else {
|
||||
newVolume = Math.max(0, currentVolume - 1);
|
||||
}
|
||||
scrollAccumulatorY = 0;
|
||||
}
|
||||
}
|
||||
|
||||
activePlayer.volume = newVolume / 100;
|
||||
} else if (SettingsData.audioScrollMode === "song") {
|
||||
if (!activePlayer)
|
||||
return;
|
||||
|
||||
wheelEvent.accepted = true;
|
||||
|
||||
const deltaY = wheelEvent.angleDelta.y;
|
||||
const isMouseWheelY = Math.abs(deltaY) >= 120 && (Math.abs(deltaY) % 120) === 0;
|
||||
|
||||
if (isMouseWheelY) {
|
||||
if (deltaY > 0) {
|
||||
activePlayer.previous();
|
||||
} else {
|
||||
activePlayer.next();
|
||||
}
|
||||
} else {
|
||||
scrollAccumulatorY += deltaY;
|
||||
if (Math.abs(scrollAccumulatorY) >= touchpadThreshold) {
|
||||
if (scrollAccumulatorY > 0) {
|
||||
activePlayer.previous();
|
||||
} else {
|
||||
activePlayer.next();
|
||||
}
|
||||
scrollAccumulatorY = 0;
|
||||
}
|
||||
scrollAccumulatorY = 0;
|
||||
}
|
||||
}
|
||||
|
||||
activePlayer.volume = newVolume / 100;
|
||||
}
|
||||
|
||||
content: Component {
|
||||
|
||||
@@ -46,11 +46,24 @@ Item {
|
||||
onToggled: checked => SettingsData.set("audioVisualizerEnabled", checked)
|
||||
}
|
||||
|
||||
SettingsToggleRow {
|
||||
SettingsDropdownRow {
|
||||
property var scrollOpts: {
|
||||
"Change Volume": "volume",
|
||||
"Change Song": "song",
|
||||
"Nothing": "nothing"
|
||||
}
|
||||
|
||||
text: I18n.tr("Scroll Wheel")
|
||||
description: I18n.tr("Scroll on widget changes media volume")
|
||||
checked: SettingsData.audioScrollEnabled
|
||||
onToggled: checked => SettingsData.set("audioScrollEnabled", checked)
|
||||
description: I18n.tr("Scroll wheel behavior on media widget")
|
||||
settingKey: "audioScrollMode"
|
||||
tags: ["media", "music", "scroll"]
|
||||
options: Object.keys(scrollOpts).sort()
|
||||
currentValue: {
|
||||
Object.keys(scrollOpts).find(key => scrollOpts[key] === SettingsData.audioScrollMode) ?? "volume"
|
||||
}
|
||||
onValueChanged: value => {
|
||||
SettingsData.set("audioScrollMode", scrollOpts[value])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user