1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 21:42:51 -05:00

dankbar: add scroll wheel behavior configuration

This commit is contained in:
bbedward
2025-12-13 20:12:21 -05:00
parent fbf79e62e9
commit 30dad46c94
4 changed files with 159 additions and 16 deletions

View File

@@ -594,7 +594,8 @@ PanelWindow {
propagateComposedEvents: true
z: -1
property real scrollAccumulator: 0
property real scrollAccumulatorY: 0
property real scrollAccumulatorX: 0
property real touchpadThreshold: 500
property bool actionInProgress: false
@@ -604,7 +605,30 @@ PanelWindow {
onTriggered: parent.actionInProgress = false
}
function handleScrollAction(behavior, direction) {
switch (behavior) {
case "workspace":
topBarContent.switchWorkspace(direction);
return true;
case "column":
if (!CompositorService.isNiri)
return false;
if (direction > 0)
NiriService.moveColumnRight();
else
NiriService.moveColumnLeft();
return true;
default:
return false;
}
}
onWheel: wheel => {
if (!(barConfig?.scrollEnabled ?? true)) {
wheel.accepted = false;
return;
}
if (actionInProgress) {
wheel.accepted = false;
return;
@@ -612,9 +636,34 @@ PanelWindow {
const deltaY = wheel.angleDelta.y;
const deltaX = wheel.angleDelta.x;
const xBehavior = barConfig?.scrollXBehavior ?? "column";
const yBehavior = barConfig?.scrollYBehavior ?? "workspace";
if (CompositorService.isNiri && Math.abs(deltaX) > Math.abs(deltaY)) {
topBarContent.switchApp(deltaX);
if (CompositorService.isNiri && xBehavior !== "none" && Math.abs(deltaX) > Math.abs(deltaY)) {
const isMouseWheel = Math.abs(deltaX) >= 120 && (Math.abs(deltaX) % 120) === 0;
const direction = deltaX < 0 ? 1 : -1;
if (isMouseWheel) {
if (handleScrollAction(xBehavior, direction)) {
actionInProgress = true;
cooldownTimer.restart();
}
} else {
scrollAccumulatorX += deltaX;
if (Math.abs(scrollAccumulatorX) >= touchpadThreshold) {
const touchDirection = scrollAccumulatorX < 0 ? 1 : -1;
if (handleScrollAction(xBehavior, touchDirection)) {
actionInProgress = true;
cooldownTimer.restart();
}
scrollAccumulatorX = 0;
}
}
wheel.accepted = false;
return;
}
if (yBehavior === "none") {
wheel.accepted = false;
return;
}
@@ -623,19 +672,20 @@ PanelWindow {
const direction = deltaY < 0 ? 1 : -1;
if (isMouseWheel) {
topBarContent.switchWorkspace(direction);
actionInProgress = true;
cooldownTimer.restart();
} else {
scrollAccumulator += deltaY;
if (Math.abs(scrollAccumulator) >= touchpadThreshold) {
const touchDirection = scrollAccumulator < 0 ? 1 : -1;
topBarContent.switchWorkspace(touchDirection);
scrollAccumulator = 0;
if (handleScrollAction(yBehavior, direction)) {
actionInProgress = true;
cooldownTimer.restart();
}
} else {
scrollAccumulatorY += deltaY;
if (Math.abs(scrollAccumulatorY) >= touchpadThreshold) {
const touchDirection = scrollAccumulatorY < 0 ? 1 : -1;
if (handleScrollAction(yBehavior, touchDirection)) {
actionInProgress = true;
cooldownTimer.restart();
}
scrollAccumulatorY = 0;
}
}
wheel.accepted = false;

View File

@@ -237,7 +237,10 @@ Item {
visible: defaultBar.visible ?? true,
popupGapsAuto: defaultBar.popupGapsAuto ?? true,
popupGapsManual: defaultBar.popupGapsManual ?? 4,
maximizeDetection: defaultBar.maximizeDetection ?? true
maximizeDetection: defaultBar.maximizeDetection ?? true,
scrollEnabled: defaultBar.scrollEnabled ?? true,
scrollXBehavior: defaultBar.scrollXBehavior ?? "column",
scrollYBehavior: defaultBar.scrollYBehavior ?? "workspace"
};
SettingsData.addBarConfig(newBar);
selectedBarId = newId;
@@ -751,6 +754,90 @@ Item {
})
}
SettingsToggleCard {
iconName: "mouse"
title: I18n.tr("Scroll Wheel")
description: I18n.tr("Control workspaces and columns by scrolling on the bar")
visible: selectedBarConfig?.enabled
checked: selectedBarConfig?.scrollEnabled ?? true
onToggled: checked => SettingsData.updateBarConfig(selectedBarId, {
scrollEnabled: checked
})
SettingsButtonGroupRow {
text: I18n.tr("Y Axis")
model: CompositorService.isNiri ? [I18n.tr("None"), I18n.tr("Workspace"), I18n.tr("Column")] : [I18n.tr("None"), I18n.tr("Workspace")]
currentIndex: {
switch (selectedBarConfig?.scrollYBehavior || "workspace") {
case "none":
return 0;
case "workspace":
return 1;
case "column":
return 2;
default:
return 1;
}
}
onSelectionChanged: (index, selected) => {
if (!selected)
return;
let behavior = "workspace";
switch (index) {
case 0:
behavior = "none";
break;
case 1:
behavior = "workspace";
break;
case 2:
behavior = "column";
break;
}
SettingsData.updateBarConfig(selectedBarId, {
scrollYBehavior: behavior
});
}
}
SettingsButtonGroupRow {
text: I18n.tr("X Axis")
visible: CompositorService.isNiri
model: [I18n.tr("None"), I18n.tr("Workspace"), I18n.tr("Column")]
currentIndex: {
switch (selectedBarConfig?.scrollXBehavior || "column") {
case "none":
return 0;
case "workspace":
return 1;
case "column":
return 2;
default:
return 2;
}
}
onSelectionChanged: (index, selected) => {
if (!selected)
return;
let behavior = "column";
switch (index) {
case 0:
behavior = "none";
break;
case 1:
behavior = "workspace";
break;
case 2:
behavior = "column";
break;
}
SettingsData.updateBarConfig(selectedBarId, {
scrollXBehavior: behavior
});
}
}
}
SettingsCard {
iconName: "space_bar"
title: I18n.tr("Spacing")