forked from Shinonome/dots-hyprland
bars: refractor corner areas' scrolling behavior
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user