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 {
|
sourceComponent: SysTrayMenu {
|
||||||
Component.onCompleted: this.open();
|
Component.onCompleted: this.open();
|
||||||
trayItemMenuHandle: root.item.menu
|
trayItemMenuHandle: root.item.menu
|
||||||
|
trayItemId: root.item.id
|
||||||
anchor {
|
anchor {
|
||||||
window: root.QsWindow.window
|
window: root.QsWindow.window
|
||||||
item: root
|
item: root
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import Quickshell
|
|||||||
PopupWindow {
|
PopupWindow {
|
||||||
id: root
|
id: root
|
||||||
required property QsMenuHandle trayItemMenuHandle
|
required property QsMenuHandle trayItemMenuHandle
|
||||||
|
property string trayItemId: ""
|
||||||
property real popupBackgroundMargin: 0
|
property real popupBackgroundMargin: 0
|
||||||
|
|
||||||
signal menuClosed
|
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 {
|
Repeater {
|
||||||
id: menuEntriesRepeater
|
id: menuEntriesRepeater
|
||||||
|
|||||||
@@ -33,12 +33,25 @@ Singleton {
|
|||||||
function unpin(itemId) {
|
function unpin(itemId) {
|
||||||
Config.options.tray.pinnedItems = Config.options.tray.pinnedItems.filter(id => id !== 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) {
|
function togglePin(itemId) {
|
||||||
var pins = Config.options.tray.pinnedItems;
|
if (root.isPinned(itemId)) {
|
||||||
if (pins.includes(itemId)) {
|
if (!root.invertPins)
|
||||||
unpin(itemId)
|
unpin(itemId);
|
||||||
|
else
|
||||||
|
pin(itemId);
|
||||||
} else {
|
} else {
|
||||||
pin(itemId)
|
if (!root.invertPins)
|
||||||
|
pin(itemId);
|
||||||
|
else
|
||||||
|
unpin(itemId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user