mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
adjust wheel events for touchpads
This commit is contained in:
@@ -55,39 +55,87 @@ Rectangle {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
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;
|
||||
if (windows.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
var currentIndex = -1;
|
||||
for (var i = 0; i < windows.length; i++) {
|
||||
if (windows[i].activated) {
|
||||
currentIndex = i;
|
||||
break;
|
||||
|
||||
if (isMouseWheel) {
|
||||
// Direct mouse wheel action
|
||||
var currentIndex = -1;
|
||||
for (var i = 0; i < windows.length; i++) {
|
||||
if (windows[i].activated) {
|
||||
currentIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var nextIndex;
|
||||
if (wheel.angleDelta.y < 0) {
|
||||
if (currentIndex === -1) {
|
||||
nextIndex = 0;
|
||||
var nextIndex;
|
||||
if (deltaY < 0) {
|
||||
if (currentIndex === -1) {
|
||||
nextIndex = 0;
|
||||
} else {
|
||||
nextIndex = (currentIndex + 1) % windows.length;
|
||||
}
|
||||
} 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 {
|
||||
if (currentIndex === -1) {
|
||||
nextIndex = windows.length - 1;
|
||||
} else {
|
||||
nextIndex = (currentIndex - 1 + windows.length) % windows.length;
|
||||
// Touchpad - accumulate small deltas
|
||||
scrollAccumulator += deltaY
|
||||
|
||||
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];
|
||||
if (nextWindow) {
|
||||
nextWindow.activate();
|
||||
}
|
||||
|
||||
wheel.accepted = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,41 +156,99 @@ Rectangle {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
acceptedButtons: Qt.NoButton
|
||||
onWheel: {
|
||||
if (CompositorService.isNiri) {
|
||||
var realWorkspaces = [];
|
||||
for (var i = 0; i < root.workspaceList.length; i++) {
|
||||
if (root.workspaceList[i] !== -1) {
|
||||
realWorkspaces.push(root.workspaceList[i]);
|
||||
|
||||
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
|
||||
|
||||
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;
|
||||
for (var i = 0; i < realWorkspaces.length; i++) {
|
||||
if (realWorkspaces[i] === root.currentWorkspace) {
|
||||
currentIndex = i;
|
||||
break;
|
||||
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 (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;
|
||||
|
||||
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");
|
||||
|
||||
scrollAccumulator = 0
|
||||
}
|
||||
}
|
||||
|
||||
wheel.accepted = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,6 +147,8 @@ Item {
|
||||
id: sliderMouseArea
|
||||
|
||||
property bool isDragging: false
|
||||
property real scrollAccumulator: 0
|
||||
property real touchpadThreshold: 20
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: -10
|
||||
@@ -156,23 +158,49 @@ Item {
|
||||
enabled: slider.enabled
|
||||
preventStealing: true
|
||||
acceptedButtons: Qt.LeftButton
|
||||
onWheel: function (wheelEvent) {
|
||||
onWheel: (wheelEvent) => {
|
||||
if (!slider.enabled || !slider.wheelEnabled) {
|
||||
wheelEvent.accepted = false
|
||||
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 step = Math.max(1, (slider.maximum - slider.minimum) / 20)
|
||||
let newValue
|
||||
if (delta > 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)
|
||||
|
||||
if (isMouseWheel) {
|
||||
// Direct mouse wheel action - 5% steps
|
||||
let step = Math.max(1, (slider.maximum - slider.minimum) / 20)
|
||||
let newValue
|
||||
if (deltaY > 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)
|
||||
}
|
||||
} 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user