mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
BarWidgets: All the right click contextual menus. Fix #541
This commit is contained in:
@@ -3,6 +3,7 @@ import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Modules.Bar.Extras
|
||||
import qs.Services.Media
|
||||
import qs.Services.UI
|
||||
import qs.Widgets
|
||||
@@ -162,6 +163,58 @@ Item {
|
||||
pointSize: Style.fontSizeS * scaling
|
||||
}
|
||||
|
||||
NPopupContextMenu {
|
||||
id: contextMenu
|
||||
|
||||
model: {
|
||||
var items = [];
|
||||
if (hasActivePlayer && MediaService.canPlay) {
|
||||
items.push({
|
||||
"label": MediaService.isPlaying ? I18n.tr("context-menu.pause") : I18n.tr("context-menu.play"),
|
||||
"action": "play-pause",
|
||||
"icon": MediaService.isPlaying ? "media-pause" : "media-play"
|
||||
});
|
||||
}
|
||||
if (hasActivePlayer && MediaService.canGoPrevious) {
|
||||
items.push({
|
||||
"label": I18n.tr("context-menu.previous"),
|
||||
"action": "previous",
|
||||
"icon": "media-prev"
|
||||
});
|
||||
}
|
||||
if (hasActivePlayer && MediaService.canGoNext) {
|
||||
items.push({
|
||||
"label": I18n.tr("context-menu.next"),
|
||||
"action": "next",
|
||||
"icon": "media-next"
|
||||
});
|
||||
}
|
||||
items.push({
|
||||
"label": I18n.tr("context-menu.widget-settings"),
|
||||
"action": "widget-settings",
|
||||
"icon": "settings"
|
||||
});
|
||||
return items;
|
||||
}
|
||||
|
||||
onTriggered: action => {
|
||||
var popupMenuWindow = PanelService.getPopupMenuWindow(screen);
|
||||
if (popupMenuWindow) {
|
||||
popupMenuWindow.close();
|
||||
}
|
||||
|
||||
if (action === "play-pause") {
|
||||
MediaService.playPause();
|
||||
} else if (action === "previous") {
|
||||
MediaService.previous();
|
||||
} else if (action === "next") {
|
||||
MediaService.next();
|
||||
} else if (action === "widget-settings") {
|
||||
BarService.openWidgetSettings(screen, section, sectionWidgetIndex, widgetId, widgetSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: mediaMini
|
||||
visible: root.visible
|
||||
@@ -466,18 +519,24 @@ Item {
|
||||
cursorShape: hasActivePlayer ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
|
||||
onClicked: mouse => {
|
||||
if (!hasActivePlayer || !MediaService.currentPlayer || !MediaService.canPlay) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mouse.button === Qt.LeftButton) {
|
||||
if (!hasActivePlayer || !MediaService.currentPlayer || !MediaService.canPlay) {
|
||||
return;
|
||||
}
|
||||
MediaService.playPause();
|
||||
} else if (mouse.button == Qt.RightButton) {
|
||||
MediaService.next();
|
||||
TooltipService.hide();
|
||||
} else if (mouse.button == Qt.MiddleButton) {
|
||||
MediaService.previous();
|
||||
} else if (mouse.button === Qt.RightButton) {
|
||||
TooltipService.hide();
|
||||
var popupMenuWindow = PanelService.getPopupMenuWindow(screen);
|
||||
if (popupMenuWindow) {
|
||||
const pos = BarService.getContextMenuPosition(mediaMini, contextMenu.implicitWidth, contextMenu.implicitHeight);
|
||||
contextMenu.openAtItem(mediaMini, pos.x, pos.y);
|
||||
popupMenuWindow.showContextMenu(contextMenu);
|
||||
}
|
||||
} else if (mouse.button === Qt.MiddleButton) {
|
||||
if (hasActivePlayer && MediaService.canGoPrevious) {
|
||||
MediaService.previous();
|
||||
TooltipService.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user