mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-06-02 10:37:50 +00:00
TaskBar: added right click contextual menu
This commit is contained in:
@@ -40,6 +40,50 @@ Rectangle {
|
||||
readonly property bool onlySameOutput: (widgetSettings.onlySameOutput !== undefined) ? widgetSettings.onlySameOutput : widgetMetadata.onlySameOutput
|
||||
readonly property bool onlyActiveWorkspaces: (widgetSettings.onlyActiveWorkspaces !== undefined) ? widgetSettings.onlyActiveWorkspaces : widgetMetadata.onlyActiveWorkspaces
|
||||
|
||||
// Context menu state
|
||||
property var selectedWindow: null
|
||||
property string selectedAppName: ""
|
||||
|
||||
NPopupContextMenu {
|
||||
id: contextMenu
|
||||
model: {
|
||||
var items = [];
|
||||
if (selectedWindow) {
|
||||
items.push({
|
||||
"label": I18n.tr("context-menu.activate-app", {
|
||||
"app": selectedAppName
|
||||
}),
|
||||
"action": "activate",
|
||||
"icon": "focus"
|
||||
});
|
||||
items.push({
|
||||
"label": I18n.tr("context-menu.close-app", {
|
||||
"app": selectedAppName
|
||||
}),
|
||||
"action": "close",
|
||||
"icon": "x"
|
||||
});
|
||||
}
|
||||
items.push({
|
||||
"label": I18n.tr("context-menu.widget-settings"),
|
||||
"action": "widget-settings",
|
||||
"icon": "settings"
|
||||
});
|
||||
return items;
|
||||
}
|
||||
onTriggered: action => {
|
||||
if (action === "activate" && selectedWindow) {
|
||||
CompositorService.focusWindow(selectedWindow);
|
||||
} else if (action === "close" && selectedWindow) {
|
||||
CompositorService.closeWindow(selectedWindow);
|
||||
} else if (action === "widget-settings") {
|
||||
BarService.openWidgetSettings(screen, section, sectionWidgetIndex, widgetId, widgetSettings);
|
||||
}
|
||||
selectedWindow = null;
|
||||
selectedAppName = "";
|
||||
}
|
||||
}
|
||||
|
||||
function updateHasWindow() {
|
||||
try {
|
||||
var total = CompositorService.windows.count || 0;
|
||||
@@ -170,10 +214,14 @@ Rectangle {
|
||||
Logger.e("Taskbar", "Failed to activate toplevel: " + error);
|
||||
}
|
||||
} else if (mouse.button === Qt.RightButton) {
|
||||
try {
|
||||
CompositorService.closeWindow(taskbarItem.modelData);
|
||||
} catch (error) {
|
||||
Logger.e("Taskbar", "Failed to close toplevel: " + error);
|
||||
TooltipService.hide();
|
||||
root.selectedWindow = taskbarItem.modelData;
|
||||
root.selectedAppName = CompositorService.getCleanAppName(taskbarItem.modelData.appId, taskbarItem.modelData.title);
|
||||
var popupMenuWindow = PanelService.getPopupMenuWindow(screen);
|
||||
if (popupMenuWindow) {
|
||||
const pos = BarService.getContextMenuPosition(taskbarItem, contextMenu.implicitWidth, contextMenu.implicitHeight);
|
||||
contextMenu.openAtItem(taskbarItem, pos.x, pos.y);
|
||||
popupMenuWindow.showContextMenu(contextMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user