bars: refractor corner areas' scrolling behavior

This commit is contained in:
end-4
2025-08-17 15:39:58 +07:00
parent a50b673e07
commit 8b77aa151b
3 changed files with 116 additions and 175 deletions
@@ -0,0 +1,63 @@
import QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Services.UPower
import qs
import qs.services
import qs.modules.common
import qs.modules.common.widgets
import qs.modules.common.functions
MouseArea { // Right side | scroll to change volume
id: root
signal scrollUp(delta: int)
signal scrollDown(delta: int)
signal movedAway()
property bool hovered: false
property real lastScrollX: 0
property real lastScrollY: 0
property bool trackingScroll: false
acceptedButtons: Qt.LeftButton
hoverEnabled: true
onEntered: {
root.hovered = true;
}
onExited: {
root.hovered = false;
root.trackingScroll = false;
}
onWheel: event => {
if (event.angleDelta.y < 0)
root.scrollDown(event.angleDelta.y);
else if (event.angleDelta.y > 0)
root.scrollUp(event.angleDelta.y);
// Store the mouse position and start tracking
root.lastScrollX = event.x;
root.lastScrollY = event.y;
root.trackingScroll = true;
}
onPositionChanged: mouse => {
if (root.trackingScroll) {
const dx = mouse.x - root.lastScrollX;
const dy = mouse.y - root.lastScrollY;
if (Math.sqrt(dx * dx + dy * dy) > osdHideMouseMoveThreshold) {
root.movedAway();
root.trackingScroll = false;
}
}
}
onContainsMouseChanged: {
if (!root.containsMouse && root.trackingScroll) {
root.movedAway();
root.trackingScroll = false;
}
}
}