mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 02:23:23 +00:00
Tray: refactoring - back to dropdown menu while keeping the drawer for unpinned.
This commit is contained in:
@@ -7,17 +7,38 @@ import qs.Widgets
|
||||
|
||||
PopupWindow {
|
||||
id: root
|
||||
property QsMenuHandle menu
|
||||
property var trayItem: null
|
||||
property var anchorItem: null
|
||||
property real anchorX
|
||||
property real anchorY
|
||||
property bool isSubMenu: false
|
||||
property bool isHovered: rootMouseArea.containsMouse
|
||||
property ShellScreen screen
|
||||
property var trayItem: null
|
||||
property string widgetSection: ""
|
||||
property int widgetIndex: -1
|
||||
|
||||
// Derive menu from trayItem (only used for non-submenus)
|
||||
readonly property QsMenuHandle menu: isSubMenu ? null : (trayItem ? trayItem.menu : null)
|
||||
|
||||
// Compute if current tray item is pinned
|
||||
readonly property bool isPinned: {
|
||||
if (!trayItem || widgetSection === "" || widgetIndex < 0)
|
||||
return false
|
||||
var widgets = Settings.data.bar.widgets[widgetSection]
|
||||
if (!widgets || widgetIndex >= widgets.length)
|
||||
return false
|
||||
var widgetSettings = widgets[widgetIndex]
|
||||
if (!widgetSettings || widgetSettings.id !== "Tray")
|
||||
return false
|
||||
var pinnedList = widgetSettings.pinned || []
|
||||
const itemName = trayItem.tooltipTitle || trayItem.name || trayItem.id || ""
|
||||
for (var i = 0; i < pinnedList.length; i++) {
|
||||
if (pinnedList[i] === itemName)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
readonly property int menuWidth: 180
|
||||
|
||||
implicitWidth: menuWidth
|
||||
@@ -283,9 +304,9 @@ PopupWindow {
|
||||
Rectangle {
|
||||
Layout.preferredWidth: parent.width
|
||||
Layout.preferredHeight: 28
|
||||
color: addToFavoriteMouseArea.containsMouse ? Qt.alpha(Color.mPrimary, 0.2) : Qt.alpha(Color.mPrimary, 0.08)
|
||||
color: pinUnpinMouseArea.containsMouse ? Qt.alpha(Color.mPrimary, 0.2) : Qt.alpha(Color.mPrimary, 0.08)
|
||||
radius: Style.radiusS
|
||||
border.color: Qt.alpha(Color.mPrimary, addToFavoriteMouseArea.containsMouse ? 0.4 : 0.2)
|
||||
border.color: Qt.alpha(Color.mPrimary, pinUnpinMouseArea.containsMouse ? 0.4 : 0.2)
|
||||
border.width: Style.borderS
|
||||
|
||||
RowLayout {
|
||||
@@ -295,7 +316,7 @@ PopupWindow {
|
||||
spacing: Style.marginS
|
||||
|
||||
NIcon {
|
||||
icon: "pin" //addToFavoriteEntry.isFavorite ? "unpin" : "pin"
|
||||
icon: root.isPinned ? "unpin" : "pin"
|
||||
pointSize: Style.fontSizeS
|
||||
applyUiScale: false
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
@@ -305,7 +326,7 @@ PopupWindow {
|
||||
NText {
|
||||
Layout.fillWidth: true
|
||||
color: Color.mPrimary
|
||||
text: addToFavoriteEntry.isFavorite ? I18n.tr("settings.bar.tray.unpin-application") : I18n.tr("settings.bar.tray.pin-application")
|
||||
text: root.isPinned ? I18n.tr("settings.bar.tray.unpin-application") : I18n.tr("settings.bar.tray.pin-application")
|
||||
pointSize: Style.fontSizeS
|
||||
font.weight: Font.Medium
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
@@ -314,87 +335,81 @@ PopupWindow {
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: addToFavoriteMouseArea
|
||||
id: pinUnpinMouseArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
|
||||
onClicked: {
|
||||
if (addToFavoriteEntry.isFavorite) {
|
||||
root.removeFromFavorites()
|
||||
if (root.isPinned) {
|
||||
root.removeFromPinned()
|
||||
} else {
|
||||
root.addToFavorites()
|
||||
root.addToPinned()
|
||||
}
|
||||
root.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addToFavorites() {
|
||||
function addToPinned() {
|
||||
if (!trayItem || widgetSection === "" || widgetIndex < 0) {
|
||||
Logger.w("TrayMenu", "Cannot add as favorite: missing tray item or widget info")
|
||||
Logger.w("TrayMenu", "Cannot pin: missing tray item or widget info")
|
||||
return
|
||||
}
|
||||
const itemName = trayItem.tooltipTitle || trayItem.name || trayItem.id || ""
|
||||
if (!itemName) {
|
||||
Logger.w("TrayMenu", "Cannot add as favorite: tray item has no name")
|
||||
Logger.w("TrayMenu", "Cannot pin: tray item has no name")
|
||||
return
|
||||
}
|
||||
var widgets = Settings.data.bar.widgets[widgetSection]
|
||||
if (!widgets || widgetIndex >= widgets.length) {
|
||||
Logger.w("TrayMenu", "Cannot add as favorite: invalid widget index")
|
||||
Logger.w("TrayMenu", "Cannot pin: invalid widget index")
|
||||
return
|
||||
}
|
||||
var widgetSettings = widgets[widgetIndex]
|
||||
if (!widgetSettings || widgetSettings.id !== "Tray") {
|
||||
Logger.w("TrayMenu", "Cannot add as favorite: widget is not a Tray widget")
|
||||
Logger.w("TrayMenu", "Cannot pin: widget is not a Tray widget")
|
||||
return
|
||||
}
|
||||
var favorites = widgetSettings.favorites || []
|
||||
var newFavorites = favorites.slice()
|
||||
newFavorites.push(itemName)
|
||||
var pinnedList = widgetSettings.pinned || []
|
||||
var newPinned = pinnedList.slice()
|
||||
newPinned.push(itemName)
|
||||
var newSettings = Object.assign({}, widgetSettings)
|
||||
newSettings.favorites = newFavorites
|
||||
newSettings.pinned = newPinned
|
||||
widgets[widgetIndex] = newSettings
|
||||
Settings.data.bar.widgets[widgetSection] = widgets
|
||||
Settings.saveImmediate()
|
||||
if (root.screen) {
|
||||
const panel = PanelService.getPanel("trayDrawerPanel", root.screen)
|
||||
if (panel)
|
||||
panel.close()
|
||||
}
|
||||
}
|
||||
|
||||
function removeFromFavorites() {
|
||||
function removeFromPinned() {
|
||||
if (!trayItem || widgetSection === "" || widgetIndex < 0) {
|
||||
Logger.w("TrayMenu", "Cannot remove from favorites: missing tray item or widget info")
|
||||
Logger.w("TrayMenu", "Cannot unpin: missing tray item or widget info")
|
||||
return
|
||||
}
|
||||
const itemName = trayItem.tooltipTitle || trayItem.name || trayItem.id || ""
|
||||
if (!itemName) {
|
||||
Logger.w("TrayMenu", "Cannot remove from favorites: tray item has no name")
|
||||
Logger.w("TrayMenu", "Cannot unpin: tray item has no name")
|
||||
return
|
||||
}
|
||||
var widgets = Settings.data.bar.widgets[widgetSection]
|
||||
if (!widgets || widgetIndex >= widgets.length) {
|
||||
Logger.w("TrayMenu", "Cannot remove from favorites: invalid widget index")
|
||||
Logger.w("TrayMenu", "Cannot unpin: invalid widget index")
|
||||
return
|
||||
}
|
||||
var widgetSettings = widgets[widgetIndex]
|
||||
if (!widgetSettings || widgetSettings.id !== "Tray") {
|
||||
Logger.w("TrayMenu", "Cannot remove from favorites: widget is not a Tray widget")
|
||||
Logger.w("TrayMenu", "Cannot unpin: widget is not a Tray widget")
|
||||
return
|
||||
}
|
||||
var favorites = widgetSettings.favorites || []
|
||||
var newFavorites = []
|
||||
for (var i = 0; i < favorites.length; i++) {
|
||||
if (favorites[i] !== itemName) {
|
||||
newFavorites.push(favorites[i])
|
||||
var pinnedList = widgetSettings.pinned || []
|
||||
var newPinned = []
|
||||
for (var i = 0; i < pinnedList.length; i++) {
|
||||
if (pinnedList[i] !== itemName) {
|
||||
newPinned.push(pinnedList[i])
|
||||
}
|
||||
}
|
||||
var newSettings = Object.assign({}, widgetSettings)
|
||||
newSettings.favorites = newFavorites
|
||||
newSettings.pinned = newPinned
|
||||
widgets[widgetIndex] = newSettings
|
||||
Settings.data.bar.widgets[widgetSection] = widgets
|
||||
Settings.saveImmediate()
|
||||
|
||||
@@ -15,6 +15,18 @@ Rectangle {
|
||||
|
||||
property ShellScreen screen
|
||||
|
||||
// Get shared tray menu window from MainScreen (via screen's parent MainScreen)
|
||||
readonly property var trayMenuWindow: {
|
||||
// Access via PanelService to get the MainScreen that contains the trayMenuWindow
|
||||
if (!screen)
|
||||
return null
|
||||
// Get any panel from this screen to access its parent MainScreen
|
||||
const drawerPanel = PanelService.getPanel("trayDrawerPanel", screen)
|
||||
return drawerPanel?.trayMenuWindow || null
|
||||
}
|
||||
|
||||
readonly property var trayMenu: trayMenuWindow ? trayMenuWindow.trayMenuLoader : null
|
||||
|
||||
// Widget properties passed from Bar.qml for per-instance settings
|
||||
property string widgetId: ""
|
||||
property string section: ""
|
||||
@@ -38,10 +50,10 @@ Rectangle {
|
||||
readonly property real iconSize: Math.round(Style.capsuleHeight * 0.65)
|
||||
|
||||
property list<string> blacklist: widgetSettings.blacklist || widgetMetadata.blacklist || [] // Read from settings
|
||||
property list<string> favorites: widgetSettings.favorites || widgetMetadata.favorites || [] // Pinned items (shown inline)
|
||||
property list<string> pinned: widgetSettings.pinned || widgetMetadata.pinned || [] // Pinned items (shown inline)
|
||||
property bool drawerEnabled: widgetSettings.drawerEnabled !== undefined ? widgetSettings.drawerEnabled : (widgetMetadata.drawerEnabled !== undefined ? widgetMetadata.drawerEnabled : true) // Enable drawer panel
|
||||
property var filteredItems: [] // Items to show inline (pinned/favorites)
|
||||
property var dropdownItems: [] // Items to show in drawer (unpinned/non-favorites)
|
||||
property var filteredItems: [] // Items to show inline (pinned)
|
||||
property var dropdownItems: [] // Items to show in drawer (unpinned)
|
||||
|
||||
// Debounce timer for updateFilteredItems to prevent excessive calls
|
||||
// when multiple events (e.g., SystemTray changes, settings saves)
|
||||
@@ -89,41 +101,41 @@ Rectangle {
|
||||
filteredItems = newItems
|
||||
dropdownItems = []
|
||||
} else {
|
||||
// Build inline (pinned/favorites) and drawer (unpinned/non-favorites) lists
|
||||
// If favorites list is empty, all items go to drawer (none inline)
|
||||
// If favorites list has items, favorites are inline, rest go to drawer
|
||||
if (favorites && favorites.length > 0) {
|
||||
let fav = []
|
||||
// Build inline (pinned) and drawer (unpinned) lists
|
||||
// If pinned list is empty, all items go to drawer (none inline)
|
||||
// If pinned list has items, pinned items are inline, rest go to drawer
|
||||
if (pinned && pinned.length > 0) {
|
||||
let pinnedItems = []
|
||||
for (var k = 0; k < newItems.length; k++) {
|
||||
const item2 = newItems[k]
|
||||
const title2 = item2.tooltipTitle || item2.name || item2.id || ""
|
||||
for (var m = 0; m < favorites.length; m++) {
|
||||
const rule2 = favorites[m]
|
||||
for (var m = 0; m < pinned.length; m++) {
|
||||
const rule2 = pinned[m]
|
||||
if (wildCardMatch(title2, rule2)) {
|
||||
fav.push(item2)
|
||||
pinnedItems.push(item2)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
filteredItems = fav
|
||||
filteredItems = pinnedItems
|
||||
|
||||
// Non-favorites (unpinned) go to drawer
|
||||
let nonFav = []
|
||||
// Unpinned items go to drawer
|
||||
let unpinnedItems = []
|
||||
for (var v = 0; v < newItems.length; v++) {
|
||||
const cand = newItems[v]
|
||||
let isFavorite = false
|
||||
let isPinned = false
|
||||
for (var f = 0; f < filteredItems.length; f++) {
|
||||
if (filteredItems[f] === cand) {
|
||||
isFavorite = true
|
||||
isPinned = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!isFavorite)
|
||||
nonFav.push(cand)
|
||||
if (!isPinned)
|
||||
unpinnedItems.push(cand)
|
||||
}
|
||||
dropdownItems = nonFav
|
||||
dropdownItems = unpinnedItems
|
||||
} else {
|
||||
// No favorites (pinned): all items go to drawer (none inline)
|
||||
// No pinned items: all items go to drawer (none inline)
|
||||
filteredItems = []
|
||||
dropdownItems = newItems
|
||||
}
|
||||
@@ -171,7 +183,7 @@ Rectangle {
|
||||
|
||||
function onLoaded() {
|
||||
// When the widget is fully initialized with its props set the screen for the trayMenu
|
||||
if (trayMenu.item) {
|
||||
if (trayMenu && trayMenu.item) {
|
||||
trayMenu.item.screen = screen
|
||||
}
|
||||
}
|
||||
@@ -331,7 +343,6 @@ Rectangle {
|
||||
menuX = (width / 2) - (trayMenu.item.width / 2)
|
||||
menuY = Style.barHeight
|
||||
}
|
||||
trayMenu.item.menu = modelData.menu
|
||||
trayMenu.item.trayItem = modelData
|
||||
trayMenu.item.widgetSection = root.section
|
||||
trayMenu.item.widgetIndex = root.sectionWidgetIndex
|
||||
@@ -381,38 +392,4 @@ Rectangle {
|
||||
onRightClicked: toggleDrawer(this)
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
PanelWindow {
|
||||
id: trayMenuWindow
|
||||
anchors.top: true
|
||||
anchors.left: true
|
||||
anchors.right: true
|
||||
anchors.bottom: true
|
||||
visible: false
|
||||
color: Color.transparent
|
||||
screen: screen
|
||||
|
||||
function open() {
|
||||
visible = true
|
||||
}
|
||||
|
||||
function close() {
|
||||
visible = false
|
||||
if (trayMenu.item) {
|
||||
trayMenu.item.hideMenu()
|
||||
}
|
||||
}
|
||||
|
||||
// Clicking outside of the rectangle to close
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: trayMenuWindow.close()
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: trayMenu
|
||||
source: "../Extras/TrayMenu.qml"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user