1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-01 19:18:28 -04:00

dbar/notifications: fix right click context menu position and add middle

click to DnD

(cherry picked from commit 1f94c3cbd4)
This commit is contained in:
bbedward
2026-07-26 14:51:51 -04:00
parent a64bd80cc9
commit 6c27b92445
2 changed files with 33 additions and 35 deletions
@@ -35,44 +35,42 @@ BasePill {
} }
} }
onRightClicked: (rx, ry) => { onRightClicked: {
const screen = root.parentScreen || Screen; const screen = root.parentScreen || Screen;
if (!screen) if (!screen)
return; return;
const globalPos = root.visualContent.mapToItem(null, 0, 0);
const isVertical = root.axis?.isVertical ?? false; const isVertical = root.axis?.isVertical ?? false;
const edge = root.axis?.edge ?? "top"; const edge = root.axis?.edge ?? "top";
const gap = Math.max(Theme.spacingXS, root.barSpacing ?? Theme.spacingXS); const gap = Math.max(Theme.spacingXS, root.barSpacing ?? Theme.spacingXS);
const barOffset = root.barThickness + root.barSpacing + gap; const barOffset = root.barThickness + root.barSpacing + gap;
const localPos = root.visualContent.mapToItem(null, root.visualContent.width / 2, root.visualContent.height / 2);
let anchorX; let anchorX;
let anchorY; let anchorY;
let anchorEdge;
if (isVertical) { if (isVertical) {
anchorY = globalPos.y - (screen.y || 0) + root.visualContent.height / 2; anchorX = edge === "left" ? barOffset : screen.width - barOffset;
if (edge === "left") { anchorY = localPos.y;
anchorX = barOffset;
anchorEdge = "top";
} else {
anchorX = screen.width - barOffset;
anchorEdge = "top";
}
} else { } else {
anchorX = globalPos.x - (screen.x || 0) + root.visualContent.width / 2; anchorX = localPos.x;
if (edge === "bottom") { anchorY = edge === "bottom" ? screen.height - barOffset : barOffset;
anchorY = screen.height - barOffset;
anchorEdge = "bottom";
} else {
anchorY = barOffset;
anchorEdge = "top";
}
} }
dndPopupLoader.active = true; dndPopupLoader.active = true;
const popup = dndPopupLoader.item; const popup = dndPopupLoader.item;
if (!popup) if (!popup)
return; return;
popup.showAt(anchorX, anchorY, screen, anchorEdge);
popup.showAt(anchorX, anchorY, isVertical, edge, screen);
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.MiddleButton
onPressed: mouse => {
root.triggerRipple(this, mouse.x, mouse.y);
SessionData.setDoNotDisturb(!SessionData.doNotDisturb);
}
} }
Loader { Loader {
@@ -31,14 +31,16 @@ PanelWindow {
} }
property point anchorPos: Qt.point(0, 0) property point anchorPos: Qt.point(0, 0)
property string anchorEdge: "top" property bool isVertical: false
property string edge: "top"
visible: false visible: false
function showAt(x, y, targetScreen, edge) { function showAt(x, y, vertical, barEdge, targetScreen) {
if (targetScreen) if (targetScreen)
root.screen = targetScreen; root.screen = targetScreen;
anchorPos = Qt.point(x, y); anchorPos = Qt.point(x, y);
anchorEdge = edge || "top"; isVertical = vertical ?? false;
edge = barEdge ?? "top";
visible = true; visible = true;
} }
@@ -66,21 +68,19 @@ PanelWindow {
visible: root.visible visible: root.visible
x: { x: {
const left = 10; if (root.isVertical) {
const right = root.width - width - 10; if (root.edge === "left")
const want = root.anchorPos.x - width / 2; return Math.min(root.width - width - 10, root.anchorPos.x);
return Math.max(left, Math.min(right, want)); return Math.max(10, root.anchorPos.x - width);
}
return Math.max(10, Math.min(root.width - width - 10, root.anchorPos.x - width / 2));
} }
y: { y: {
switch (root.anchorEdge) { if (root.isVertical)
case "bottom":
return Math.max(10, root.anchorPos.y - height);
case "left":
case "right":
return Math.max(10, Math.min(root.height - height - 10, root.anchorPos.y - height / 2)); return Math.max(10, Math.min(root.height - height - 10, root.anchorPos.y - height / 2));
default: if (root.edge === "bottom")
return Math.min(root.height - height - 10, root.anchorPos.y); return Math.max(10, root.anchorPos.y - height);
} return Math.min(root.height - height - 10, root.anchorPos.y);
} }
onDismissed: root.closeMenu() onDismissed: root.closeMenu()