1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-29 07:52:50 -05:00

adjust wheel events for touchpads

This commit is contained in:
bbedward
2025-09-01 15:14:16 -04:00
parent 26e27e2686
commit 53698040ab
3 changed files with 196 additions and 62 deletions

View File

@@ -55,39 +55,87 @@ Rectangle {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
acceptedButtons: Qt.NoButton acceptedButtons: Qt.NoButton
onWheel: {
property real scrollAccumulator: 0
property real touchpadThreshold: 500
onWheel: (wheel) => {
const deltaY = wheel.angleDelta.y
const isMouseWheel = Math.abs(deltaY) >= 120
&& (Math.abs(deltaY) % 120) === 0
var windows = root.sortedToplevels; var windows = root.sortedToplevels;
if (windows.length < 2) { if (windows.length < 2) {
return; return;
} }
var currentIndex = -1; if (isMouseWheel) {
for (var i = 0; i < windows.length; i++) { // Direct mouse wheel action
if (windows[i].activated) { var currentIndex = -1;
currentIndex = i; for (var i = 0; i < windows.length; i++) {
break; if (windows[i].activated) {
currentIndex = i;
break;
}
} }
}
var nextIndex; var nextIndex;
if (wheel.angleDelta.y < 0) { if (deltaY < 0) {
if (currentIndex === -1) { if (currentIndex === -1) {
nextIndex = 0; nextIndex = 0;
} else {
nextIndex = (currentIndex + 1) % windows.length;
}
} else { } else {
nextIndex = (currentIndex + 1) % windows.length; if (currentIndex === -1) {
nextIndex = windows.length - 1;
} else {
nextIndex = (currentIndex - 1 + windows.length) % windows.length;
}
}
var nextWindow = windows[nextIndex];
if (nextWindow) {
nextWindow.activate();
} }
} else { } else {
if (currentIndex === -1) { // Touchpad - accumulate small deltas
nextIndex = windows.length - 1; scrollAccumulator += deltaY
} else {
nextIndex = (currentIndex - 1 + windows.length) % windows.length; if (Math.abs(scrollAccumulator) >= touchpadThreshold) {
var currentIndex = -1;
for (var i = 0; i < windows.length; i++) {
if (windows[i].activated) {
currentIndex = i;
break;
}
}
var nextIndex;
if (scrollAccumulator < 0) {
if (currentIndex === -1) {
nextIndex = 0;
} else {
nextIndex = (currentIndex + 1) % windows.length;
}
} else {
if (currentIndex === -1) {
nextIndex = windows.length - 1;
} else {
nextIndex = (currentIndex - 1 + windows.length) % windows.length;
}
}
var nextWindow = windows[nextIndex];
if (nextWindow) {
nextWindow.activate();
}
scrollAccumulator = 0
} }
} }
var nextWindow = windows[nextIndex]; wheel.accepted = true
if (nextWindow) {
nextWindow.activate();
}
} }
} }

View File

@@ -156,41 +156,99 @@ Rectangle {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
acceptedButtons: Qt.NoButton acceptedButtons: Qt.NoButton
onWheel: {
if (CompositorService.isNiri) { property real scrollAccumulator: 0
var realWorkspaces = []; property real touchpadThreshold: 500
for (var i = 0; i < root.workspaceList.length; i++) {
if (root.workspaceList[i] !== -1) { onWheel: (wheel) => {
realWorkspaces.push(root.workspaceList[i]); const deltaY = wheel.angleDelta.y
const isMouseWheel = Math.abs(deltaY) >= 120
&& (Math.abs(deltaY) % 120) === 0
if (isMouseWheel) {
// Direct mouse wheel action
if (CompositorService.isNiri) {
var realWorkspaces = [];
for (var i = 0; i < root.workspaceList.length; i++) {
if (root.workspaceList[i] !== -1) {
realWorkspaces.push(root.workspaceList[i]);
}
}
if (realWorkspaces.length < 2) return;
var currentIndex = -1;
for (var i = 0; i < realWorkspaces.length; i++) {
if (realWorkspaces[i] === root.currentWorkspace) {
currentIndex = i;
break;
}
}
if (currentIndex === -1) currentIndex = 0;
var nextIndex;
if (deltaY < 0) {
nextIndex = (currentIndex + 1) % realWorkspaces.length;
} else {
nextIndex = (currentIndex - 1 + realWorkspaces.length) % realWorkspaces.length;
}
NiriService.switchToWorkspace(realWorkspaces[nextIndex] - 1);
} else if (CompositorService.isHyprland) {
if (deltaY < 0) {
Hyprland.dispatch("workspace r+1");
} else {
Hyprland.dispatch("workspace r-1");
} }
} }
} else {
// Touchpad - accumulate small deltas
scrollAccumulator += deltaY
if (Math.abs(scrollAccumulator) >= touchpadThreshold) {
if (CompositorService.isNiri) {
var realWorkspaces = [];
for (var i = 0; i < root.workspaceList.length; i++) {
if (root.workspaceList[i] !== -1) {
realWorkspaces.push(root.workspaceList[i]);
}
}
if (realWorkspaces.length < 2) return; if (realWorkspaces.length < 2) {
scrollAccumulator = 0;
return;
}
var currentIndex = -1; var currentIndex = -1;
for (var i = 0; i < realWorkspaces.length; i++) { for (var i = 0; i < realWorkspaces.length; i++) {
if (realWorkspaces[i] === root.currentWorkspace) { if (realWorkspaces[i] === root.currentWorkspace) {
currentIndex = i; currentIndex = i;
break; break;
}
}
if (currentIndex === -1) currentIndex = 0;
var nextIndex;
if (scrollAccumulator < 0) {
nextIndex = (currentIndex + 1) % realWorkspaces.length;
} else {
nextIndex = (currentIndex - 1 + realWorkspaces.length) % realWorkspaces.length;
}
NiriService.switchToWorkspace(realWorkspaces[nextIndex] - 1);
} else if (CompositorService.isHyprland) {
if (scrollAccumulator < 0) {
Hyprland.dispatch("workspace r+1");
} else {
Hyprland.dispatch("workspace r-1");
}
} }
}
if (currentIndex === -1) currentIndex = 0; scrollAccumulator = 0
var nextIndex;
if (wheel.angleDelta.y < 0) {
nextIndex = (currentIndex + 1) % realWorkspaces.length;
} else {
nextIndex = (currentIndex - 1 + realWorkspaces.length) % realWorkspaces.length;
}
NiriService.switchToWorkspace(realWorkspaces[nextIndex] - 1);
} else if (CompositorService.isHyprland) {
if (wheel.angleDelta.y < 0) {
Hyprland.dispatch("workspace r+1");
} else {
Hyprland.dispatch("workspace r-1");
} }
} }
wheel.accepted = true
} }
} }

View File

@@ -147,6 +147,8 @@ Item {
id: sliderMouseArea id: sliderMouseArea
property bool isDragging: false property bool isDragging: false
property real scrollAccumulator: 0
property real touchpadThreshold: 20
anchors.fill: parent anchors.fill: parent
anchors.topMargin: -10 anchors.topMargin: -10
@@ -156,23 +158,49 @@ Item {
enabled: slider.enabled enabled: slider.enabled
preventStealing: true preventStealing: true
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
onWheel: function (wheelEvent) { onWheel: (wheelEvent) => {
if (!slider.enabled || !slider.wheelEnabled) { if (!slider.enabled || !slider.wheelEnabled) {
wheelEvent.accepted = false wheelEvent.accepted = false
return return
} }
let delta = wheelEvent.angleDelta.y
const deltaY = wheelEvent.angleDelta.y
const isMouseWheel = Math.abs(deltaY) >= 120
&& (Math.abs(deltaY) % 120) === 0
let currentValue = slider.value let currentValue = slider.value
let step = Math.max(1, (slider.maximum - slider.minimum) / 20)
let newValue if (isMouseWheel) {
if (delta > 0) // Direct mouse wheel action - 5% steps
newValue = Math.min(slider.maximum, currentValue + step) let step = Math.max(1, (slider.maximum - slider.minimum) / 20)
else let newValue
newValue = Math.max(slider.minimum, currentValue - step) if (deltaY > 0)
newValue = Math.round(newValue) newValue = Math.min(slider.maximum, currentValue + step)
if (newValue !== slider.value) { else
slider.value = newValue newValue = Math.max(slider.minimum, currentValue - step)
slider.sliderValueChanged(newValue) newValue = Math.round(newValue)
if (newValue !== slider.value) {
slider.value = newValue
slider.sliderValueChanged(newValue)
}
} else {
// Touchpad - accumulate then apply 1% steps
scrollAccumulator += deltaY
if (Math.abs(scrollAccumulator) >= touchpadThreshold) {
let step = Math.max(0.5, (slider.maximum - slider.minimum) / 100)
let newValue
if (scrollAccumulator > 0)
newValue = Math.min(slider.maximum, currentValue + step)
else
newValue = Math.max(slider.minimum, currentValue - step)
newValue = Math.round(newValue)
if (newValue !== slider.value) {
slider.value = newValue
slider.sliderValueChanged(newValue)
}
scrollAccumulator = 0
}
} }
wheelEvent.accepted = true wheelEvent.accepted = true
} }