TaskBar+Grouped: improved popup menu positionning and factorized code.

This commit is contained in:
ItsLemmy
2025-11-24 14:59:42 -05:00
parent 38721a1a80
commit 3cf4e1f95b
2 changed files with 64 additions and 120 deletions
+12 -13
View File
@@ -20,7 +20,8 @@ Rectangle {
property int sectionWidgetIndex: -1
property int sectionWidgetsCount: 0
readonly property bool isVerticalBar: Settings.data.bar.position === "left" || Settings.data.bar.position === "right"
readonly property string barPosition: Settings.data.bar.position
readonly property bool isVerticalBar: barPosition === "left" || barPosition === "right"
readonly property string density: Settings.data.bar.density
readonly property real itemSize: (density === "compact") ? Style.capsuleHeight * 0.9 : Style.capsuleHeight * 0.8
@@ -164,7 +165,7 @@ Rectangle {
required property var modelData
property ShellScreen screen: root.screen
visible: (!onlySameOutput || modelData.output == screen.name) && (!onlyActiveWorkspaces || CompositorService.getActiveWorkspaces().map(function (ws) {
visible: (!onlySameOutput || modelData.output === screen?.name) && (!onlyActiveWorkspaces || CompositorService.getActiveWorkspaces().map(function (ws) {
return ws.id;
}).includes(modelData.workspaceId))
@@ -287,23 +288,21 @@ Rectangle {
if (popupMenuWindow) {
popupMenuWindow.open();
// Calculate menu position relative to the clicked item with consistent spacing
const barPosition = Settings.data.bar.position;
const spacing = Style.barHeight * 0.5;
// Calculate menu position
let menuX, menuY;
if (barPosition === "top") {
if (root.barPosition === "top") {
menuX = globalX + (itemWidth / 2) - (contextMenu.implicitWidth / 2);
menuY = globalY + itemHeight + spacing;
} else if (barPosition === "bottom") {
menuY = Style.barHeight + Style.marginS;
} else if (root.barPosition === "bottom") {
const menuHeight = 12 + contextMenu.model.length * contextMenu.itemHeight;
menuX = globalX + (itemWidth / 2) - (contextMenu.implicitWidth / 2);
menuY = globalY - contextMenu.implicitHeight - (Style.barHeight * 2);
} else if (barPosition === "left") {
menuX = globalX + itemWidth + spacing;
menuY = -menuHeight - Style.marginS;
} else if (root.barPosition === "left") {
menuX = Style.barHeight + Style.marginS;
menuY = globalY + (itemHeight / 2) - (contextMenu.implicitHeight / 2);
} else {
// right
menuX = globalX - contextMenu.implicitWidth - spacing;
menuX = -contextMenu.implicitWidth - Style.marginS;
menuY = globalY + (itemHeight / 2) - (contextMenu.implicitHeight / 2);
}
+52 -107
View File
@@ -21,7 +21,8 @@ Item {
property int sectionWidgetIndex: -1
property int sectionWidgetsCount: 0
readonly property bool isVerticalBar: Settings.data.bar.position === "left" || Settings.data.bar.position === "right"
readonly property string barPosition: Settings.data.bar.position
readonly property bool isVerticalBar: barPosition === "left" || barPosition === "right"
readonly property string density: Settings.data.bar.density
readonly property real itemSize: (density === "compact") ? Style.capsuleHeight * 0.9 : Style.capsuleHeight * 0.8
property var widgetMetadata: BarWidgetRegistry.widgetMetadata[widgetId]
@@ -565,63 +566,7 @@ Item {
property real globalY: 0
property real itemWidth: 0
property real itemHeight: 0
onTriggered: {
// Directly build and set model as a new array (bypass binding issues)
var items = [];
if (root.selectedWindow) {
items.push({
"label": I18n.tr("context-menu.activate-app", {
"app": root.selectedAppName
}),
"action": "activate",
"icon": "focus"
});
items.push({
"label": I18n.tr("context-menu.close-app", {
"app": root.selectedAppName
}),
"action": "close",
"icon": "x"
});
}
items.push({
"label": I18n.tr("context-menu.widget-settings"),
"action": "widget-settings",
"icon": "settings"
});
// Set the model directly
contextMenu.model = items;
var popupMenuWindow = PanelService.getPopupMenuWindow(screen);
if (popupMenuWindow) {
popupMenuWindow.open();
// Calculate menu position relative to the clicked item with consistent spacing
const barPosition = Settings.data.bar.position;
const spacing = Style.barHeight * 0.5;
let menuX, menuY;
if (barPosition === "top") {
menuX = globalX + (itemWidth / 2) - (contextMenu.implicitWidth / 2);
menuY = globalY + itemHeight + spacing;
} else if (barPosition === "bottom") {
menuX = globalX + (itemWidth / 2) - (contextMenu.implicitWidth / 2);
menuY = globalY - contextMenu.implicitHeight - (Style.barHeight * 2);
} else if (barPosition === "left") {
menuX = globalX + itemWidth + spacing;
menuY = globalY + (itemHeight / 2) - (contextMenu.implicitHeight / 2);
} else {
// right
menuX = globalX - contextMenu.implicitWidth - spacing;
menuY = globalY + (itemHeight / 2) - (contextMenu.implicitHeight / 2);
}
contextMenu.openAtItem(root, menuX, menuY);
popupMenuWindow.contentItem = contextMenu;
}
}
onTriggered: openContextMenu(globalX, globalY, itemWidth, itemHeight)
}
Timer {
@@ -632,62 +577,62 @@ Item {
property real globalY: 0
property real itemWidth: 0
property real itemHeight: 0
onTriggered: openContextMenu(globalX, globalY, itemWidth, itemHeight)
}
onTriggered: {
// Directly build and set model as a new array (bypass binding issues)
var items = [];
if (root.selectedWindow) {
items.push({
"label": I18n.tr("context-menu.activate-app", {
"app": root.selectedAppName
}),
"action": "activate",
"icon": "focus"
});
items.push({
"label": I18n.tr("context-menu.close-app", {
"app": root.selectedAppName
}),
"action": "close",
"icon": "x"
});
}
// --------------------------------------------------
function openContextMenu(globalX, globalY, itemWidth, itemHeight) {
// Directly build and set model as a new array (bypass binding issues)
var items = [];
if (root.selectedWindow) {
items.push({
"label": I18n.tr("context-menu.widget-settings"),
"action": "widget-settings",
"icon": "settings"
"label": I18n.tr("context-menu.activate-app", {
"app": root.selectedAppName
}),
"action": "activate",
"icon": "focus"
});
items.push({
"label": I18n.tr("context-menu.close-app", {
"app": root.selectedAppName
}),
"action": "close",
"icon": "x"
});
}
items.push({
"label": I18n.tr("context-menu.widget-settings"),
"action": "widget-settings",
"icon": "settings"
});
// Set the model directly
contextMenu.model = items;
// Set the model directly
contextMenu.model = items;
var popupMenuWindow = PanelService.getPopupMenuWindow(screen);
if (popupMenuWindow) {
popupMenuWindow.open();
var popupMenuWindow = PanelService.getPopupMenuWindow(screen);
if (popupMenuWindow) {
popupMenuWindow.open();
// Calculate menu position relative to the clicked item with consistent spacing
const barPosition = Settings.data.bar.position;
const spacing = Style.barHeight * 0.5;
let menuX, menuY;
if (barPosition === "top") {
menuX = globalX + (itemWidth / 2) - (contextMenu.implicitWidth / 2);
menuY = globalY + itemHeight + spacing;
} else if (barPosition === "bottom") {
menuX = globalX + (itemWidth / 2) - (contextMenu.implicitWidth / 2);
menuY = globalY - contextMenu.implicitHeight - (Style.barHeight * 2);
} else if (barPosition === "left") {
menuX = globalX + itemWidth + spacing;
menuY = globalY + (itemHeight / 2) - (contextMenu.implicitHeight / 2);
} else {
// right
menuX = globalX - contextMenu.implicitWidth - spacing;
menuY = globalY + (itemHeight / 2) - (contextMenu.implicitHeight / 2);
}
contextMenu.openAtItem(root, menuX, menuY);
popupMenuWindow.contentItem = contextMenu;
// Calculate menu position
let menuX, menuY;
if (root.barPosition === "top") {
menuX = globalX + (itemWidth / 2) - (contextMenu.implicitWidth / 2);
menuY = Style.barHeight + Style.marginS;
} else if (root.barPosition === "bottom") {
const menuHeight = 12 + contextMenu.model.length * contextMenu.itemHeight;
menuX = globalX + (itemWidth / 2) - (contextMenu.implicitWidth / 2);
menuY = -menuHeight - Style.marginS;
} else if (root.barPosition === "left") {
menuX = Style.barHeight + Style.marginS;
menuY = globalY + (itemHeight / 2) - (contextMenu.implicitHeight / 2);
} else {
// right
menuX = -contextMenu.implicitWidth - Style.marginS;
menuY = globalY + (itemHeight / 2) - (contextMenu.implicitHeight / 2);
}
contextMenu.openAtItem(root, menuX, menuY);
popupMenuWindow.contentItem = contextMenu;
}
}
}