forked from Shinonome/dots-hyprland
wbar: drag to pin tray item
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user