forked from Shinonome/dots-hyprland
feat(SysTray): add pinning functionality to system tray items
This commit is contained in:
@@ -48,6 +48,7 @@ MouseArea {
|
||||
sourceComponent: SysTrayMenu {
|
||||
Component.onCompleted: this.open();
|
||||
trayItemMenuHandle: root.item.menu
|
||||
trayItemId: root.item.id
|
||||
anchor {
|
||||
window: root.QsWindow.window
|
||||
item: root
|
||||
|
||||
@@ -9,6 +9,7 @@ import Quickshell
|
||||
PopupWindow {
|
||||
id: root
|
||||
required property QsMenuHandle trayItemMenuHandle
|
||||
property string trayItemId: ""
|
||||
property real popupBackgroundMargin: 0
|
||||
|
||||
signal menuClosed
|
||||
@@ -173,6 +174,52 @@ PopupWindow {
|
||||
}
|
||||
}
|
||||
}
|
||||
RippleButton {
|
||||
id: pinEntry
|
||||
buttonRadius: popupBackground.radius - popupBackground.padding
|
||||
horizontalPadding: 12
|
||||
implicitWidth: contentItem.implicitWidth + horizontalPadding * 2
|
||||
implicitHeight: 36
|
||||
Layout.topMargin: 0
|
||||
Layout.bottomMargin: 0
|
||||
Layout.fillWidth: true
|
||||
|
||||
visible: root.trayItemId !== undefined && root.trayItemId.length > 0
|
||||
|
||||
releaseAction: () => {
|
||||
TrayService.togglePin(root.trayItemId);
|
||||
root.close();
|
||||
}
|
||||
|
||||
contentItem: RowLayout {
|
||||
anchors {
|
||||
verticalCenter: parent.verticalCenter
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
leftMargin: pinEntry.horizontalPadding
|
||||
rightMargin: pinEntry.horizontalPadding
|
||||
}
|
||||
spacing: 8
|
||||
|
||||
MaterialSymbol {
|
||||
iconSize: 18
|
||||
text: "push_pin"
|
||||
}
|
||||
|
||||
StyledText {
|
||||
Layout.fillWidth: true
|
||||
text: TrayService.isPinned(root.trayItemId) ? Translation.tr("Unpin") : Translation.tr("Pin")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: 1
|
||||
color: Appearance.colors.colSubtext
|
||||
Layout.topMargin: 4
|
||||
Layout.bottomMargin: 4
|
||||
}
|
||||
|
||||
Repeater {
|
||||
id: menuEntriesRepeater
|
||||
|
||||
@@ -33,12 +33,25 @@ Singleton {
|
||||
function unpin(itemId) {
|
||||
Config.options.tray.pinnedItems = Config.options.tray.pinnedItems.filter(id => id !== itemId);
|
||||
}
|
||||
function isPinned(itemId) {
|
||||
for (var i = 0; i < root.pinnedItems.length; i++) {
|
||||
if (root.pinnedItems[i].id === itemId)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function togglePin(itemId) {
|
||||
var pins = Config.options.tray.pinnedItems;
|
||||
if (pins.includes(itemId)) {
|
||||
unpin(itemId)
|
||||
if (root.isPinned(itemId)) {
|
||||
if (!root.invertPins)
|
||||
unpin(itemId);
|
||||
else
|
||||
pin(itemId);
|
||||
} else {
|
||||
pin(itemId)
|
||||
if (!root.invertPins)
|
||||
pin(itemId);
|
||||
else
|
||||
unpin(itemId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user