mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
BarWidgets: First pass on contextual widget menu accessible from right-click.
Testing on volume widget for now.
This commit is contained in:
@@ -244,4 +244,54 @@ Singleton {
|
||||
return "bottom";
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate context menu position based on bar position
|
||||
// Parameters:
|
||||
// anchorItem: The widget item to anchor the menu to
|
||||
// menuWidth: Width of the context menu (optional, defaults to 180)
|
||||
// menuHeight: Height of the context menu (optional, defaults to 100)
|
||||
// Returns: { x: number, y: number }
|
||||
// Note: Anchor position is top-left corner, so we calculate from center
|
||||
function getContextMenuPosition(anchorItem, menuWidth, menuHeight) {
|
||||
if (!anchorItem) {
|
||||
Logger.w("BarService", "getContextMenuPosition: anchorItem is null");
|
||||
return {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
};
|
||||
}
|
||||
|
||||
const mWidth = menuWidth || 180;
|
||||
const mHeight = menuHeight || 100;
|
||||
const barPosition = Settings.data.bar.position;
|
||||
let menuX = 0;
|
||||
let menuY = 0;
|
||||
|
||||
// Calculate center-based positioning for consistent spacing
|
||||
const anchorCenterX = anchorItem.width / 2;
|
||||
const anchorCenterY = anchorItem.height / 2;
|
||||
|
||||
if (barPosition === "left") {
|
||||
// For left bar: position menu to the right of anchor, vertically centered
|
||||
menuX = anchorItem.width + Style.marginM;
|
||||
menuY = anchorCenterY - (mHeight / 2);
|
||||
} else if (barPosition === "right") {
|
||||
// For right bar: position menu to the left of anchor, vertically centered
|
||||
menuX = -mWidth - Style.marginM;
|
||||
menuY = anchorCenterY - (mHeight / 2);
|
||||
} else if (barPosition === "top") {
|
||||
// For top bar: position menu below bar, horizontally centered
|
||||
menuX = anchorCenterX - (mWidth / 2);
|
||||
menuY = Style.barHeight;
|
||||
} else {
|
||||
// For bottom bar: position menu above, horizontally centered
|
||||
menuX = anchorCenterX - (mWidth / 2);
|
||||
menuY = -mHeight - Style.marginM;
|
||||
}
|
||||
|
||||
return {
|
||||
"x": menuX,
|
||||
"y": menuY
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user