wbar: drag to pin tray item

This commit is contained in:
end-4
2025-11-16 21:07:42 +01:00
parent 869f9529f6
commit 986461f590
6 changed files with 89 additions and 19 deletions
@@ -45,6 +45,14 @@ RowLayout {
extraVisibleCondition: overflowButton.shouldShowTooltip
text: qsTr("Show hidden icons")
}
DropArea {
id: pinDropArea
anchors.fill: parent
property bool willPin: false
onEntered: willPin = true
onExited: willPin = false
}
}
Repeater {
@@ -52,8 +60,47 @@ RowLayout {
values: TrayService.pinnedItems
}
delegate: TrayButton {
id: trayButton
required property var modelData
item: modelData
Drag.active: dragArea.drag.active
Drag.hotSpot.x: width / 2
Drag.hotSpot.y: height / 2
property real initialX
property real initialY
Behavior on x {
animation: Looks.transition.move.createObject(this)
}
MouseArea {
id: dragArea
anchors.fill: parent
drag.target: parent
drag.axis: Drag.XAxis
onPressed: (event) => {
trayButton.initialX = trayButton.x;
trayButton.initialY = trayButton.y;
trayButton.Drag.active = true;
}
onReleased: {
if (!dragArea.drag.active) {
trayButton.click();
} else {
if (pinDropArea.containsDrag && pinDropArea.willPin) {
// Quickshell would crash if we don't hide this item first. Took me fucking 3 hours to figure out...
trayButton.visible = false;
TrayService.togglePin(trayButton.item.id);
pinDropArea.willPin = false;
} else {
trayButton.x = trayButton.initialX;
trayButton.y = trayButton.initialY;
}
}
}
}
}
}
}
@@ -28,7 +28,9 @@ BarPopup {
rowSpacing: 0
Repeater {
model: TrayService.unpinnedItems
model: ScriptModel {
values: TrayService.unpinnedItems
}
delegate: TrayButton {
required property var modelData
item: modelData