mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
Tray: refactoring - back to dropdown menu while keeping the drawer for unpinned.
This commit is contained in:
@@ -12,6 +12,9 @@ import qs.Modules.MainScreen
|
||||
SmartPanel {
|
||||
id: root
|
||||
|
||||
// Shared tray menu window (set by MainScreen)
|
||||
property var trayMenuWindow: null
|
||||
|
||||
// Widget info for menu functionality
|
||||
property string widgetSection: ""
|
||||
property int widgetIndex: -1
|
||||
@@ -34,8 +37,8 @@ SmartPanel {
|
||||
return settings
|
||||
}
|
||||
|
||||
// Read favorites directly from settings for reactivity
|
||||
readonly property var favoritesList: widgetSettings.favorites || []
|
||||
// Read pinned list directly from settings for reactivity
|
||||
readonly property var pinnedList: widgetSettings.pinned || []
|
||||
|
||||
function wildCardMatch(str, rule) {
|
||||
if (!str || !rule)
|
||||
@@ -49,22 +52,22 @@ SmartPanel {
|
||||
}
|
||||
}
|
||||
|
||||
function isFavorite(item) {
|
||||
if (!favoritesList || favoritesList.length === 0)
|
||||
function isPinned(item) {
|
||||
if (!pinnedList || pinnedList.length === 0)
|
||||
return false
|
||||
const title = item?.tooltipTitle || item?.name || item?.id || ""
|
||||
for (var i = 0; i < favoritesList.length; i++) {
|
||||
if (wildCardMatch(title, favoritesList[i]))
|
||||
for (var i = 0; i < pinnedList.length; i++) {
|
||||
if (wildCardMatch(title, pinnedList[i]))
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Dynamic sizing based on item count
|
||||
// Show items that are NOT favorites (unpinned items go to drawer)
|
||||
// Show items that are NOT pinned (unpinned items go to drawer)
|
||||
readonly property var trayValuesAll: (SystemTray.items && SystemTray.items.values) ? SystemTray.items.values : []
|
||||
readonly property var trayValues: trayValuesAll.filter(function (it) {
|
||||
return !root.isFavorite(it)
|
||||
return !root.isPinned(it)
|
||||
})
|
||||
readonly property int itemCount: trayValues.length
|
||||
readonly property int maxColumns: 8
|
||||
@@ -84,11 +87,21 @@ SmartPanel {
|
||||
Connections {
|
||||
target: Settings
|
||||
function onSettingsSaved() {
|
||||
// Force refresh by incrementing settingsVersion, which triggers recalculation of favoritesList
|
||||
// Force refresh by incrementing settingsVersion, which triggers recalculation of pinnedList
|
||||
root.settingsVersion++
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-close drawer when all items are pinned (drawer becomes empty)
|
||||
onTrayValuesChanged: {
|
||||
if (visible && trayValues.length === 0) {
|
||||
close()
|
||||
}
|
||||
}
|
||||
|
||||
// Get the trayMenu Loader from the shared window
|
||||
readonly property var trayMenu: trayMenuWindow ? trayMenuWindow.trayMenuLoader : null
|
||||
|
||||
panelContent: Item {
|
||||
id: content
|
||||
|
||||
@@ -144,22 +157,49 @@ SmartPanel {
|
||||
onClicked: mouse => {
|
||||
if (!modelData)
|
||||
return
|
||||
if (mouse.button === Qt.RightButton && modelData.hasMenu && modelData.menu) {
|
||||
const panel = PanelService.getPanel("trayMenuPanel", root.screen)
|
||||
if (panel) {
|
||||
panel.menu = modelData.menu
|
||||
panel.trayItem = modelData
|
||||
panel.widgetSection = root.widgetSection
|
||||
panel.widgetIndex = root.widgetIndex
|
||||
panel.openAt(trayIcon)
|
||||
|
||||
if (mouse.button === Qt.LeftButton) {
|
||||
// Left click: activate tray item
|
||||
if (!modelData.onlyMenu) {
|
||||
modelData.activate()
|
||||
}
|
||||
} else if (mouse.button === Qt.LeftButton) {
|
||||
modelData.activate()
|
||||
// Close the drawer after activation
|
||||
PanelService.getPanel("trayDrawerPanel", root.screen)?.close()
|
||||
} else if (mouse.button === Qt.MiddleButton) {
|
||||
modelData.secondaryActivate()
|
||||
PanelService.getPanel("trayDrawerPanel", root.screen)?.close()
|
||||
// Middle click: activate with middle button
|
||||
modelData.activate(1)
|
||||
} else if (mouse.button === Qt.RightButton) {
|
||||
// Right click: open context menu
|
||||
TooltipService.hideImmediately()
|
||||
|
||||
// Close menu if already visible
|
||||
if (trayMenuWindow && trayMenuWindow.visible) {
|
||||
trayMenuWindow.close()
|
||||
return
|
||||
}
|
||||
|
||||
if (modelData.hasMenu && modelData.menu && trayMenu.item) {
|
||||
trayMenuWindow.open()
|
||||
|
||||
// Position menu at the tray icon
|
||||
const barPosition = Settings.data.bar.position
|
||||
let menuX, menuY
|
||||
|
||||
if (barPosition === "left") {
|
||||
menuX = trayIcon.width + Style.marginM
|
||||
menuY = 0
|
||||
} else if (barPosition === "right") {
|
||||
menuX = -trayMenu.item.width - Style.marginM
|
||||
menuY = 0
|
||||
} else {
|
||||
// Horizontal bars
|
||||
menuX = (trayIcon.width / 2) - (trayMenu.item.width / 2)
|
||||
menuY = trayIcon.height + Style.marginS
|
||||
}
|
||||
|
||||
trayMenu.item.trayItem = modelData
|
||||
trayMenu.item.widgetSection = root.widgetSection
|
||||
trayMenu.item.widgetIndex = root.widgetIndex
|
||||
trayMenu.item.showAt(trayIcon, menuX, menuY)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +210,10 @@ SmartPanel {
|
||||
modelData?.scrollDown()
|
||||
}
|
||||
|
||||
onEntered: TooltipService.show(Screen, trayIcon, modelData.tooltipTitle || modelData.name || modelData.id || "Tray Item", BarService.getTooltipDirection())
|
||||
onEntered: {
|
||||
trayMenuWindow.close()
|
||||
TooltipService.show(Screen, trayIcon, modelData.tooltipTitle || modelData.name || modelData.id || "Tray Item", BarService.getTooltipDirection())
|
||||
}
|
||||
onExited: TooltipService.hide()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user