wbar: unpin and stuff

i realized i mixed up pinning and unpinning, but whatever
This commit is contained in:
end-4
2025-11-16 21:59:42 +01:00
parent 986461f590
commit 28bf94904f
6 changed files with 141 additions and 50 deletions
@@ -1,3 +1,4 @@
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
@@ -15,46 +16,108 @@ BarPopup {
closeOnFocusLost: false
onFocusCleared: {
const hasMenuOpen = contentItem.children.some(c => (c.menuOpen));
if (!hasMenuOpen) root.close();
else root.grabFocus();
if (!hasMenuOpen)
root.close();
else
root.grabFocus();
}
contentItem: GridLayout {
contentItem: Item {
id: contentItem
anchors.centerIn: parent
rows: Math.floor(Math.sqrt(TrayService.unpinnedItems.length))
columns: Math.ceil(TrayService.unpinnedItems.length / rows)
columnSpacing: 0
rowSpacing: 0
implicitWidth: contentGrid.implicitWidth
implicitHeight: contentGrid.implicitHeight
GridLayout {
id: contentGrid
anchors.centerIn: parent
rows: Math.floor(Math.sqrt(TrayService.unpinnedItems.length))
columns: Math.ceil(TrayService.unpinnedItems.length / rows)
columnSpacing: 0
rowSpacing: 0
Repeater {
model: ScriptModel {
values: TrayService.unpinnedItems
}
delegate: TrayButton {
required property var modelData
item: modelData
Repeater {
model: ScriptModel {
values: TrayService.unpinnedItems
onValuesChanged: {
if (values.length === 0) {
root.close();
}
}
}
delegate: TrayButton {
id: trayButton
required property var modelData
item: modelData
topInset: 0
bottomInset: 0
implicitWidth: 40
implicitHeight: 40
topInset: 0
bottomInset: 0
implicitWidth: 40
implicitHeight: 40
colBackground: ColorUtils.transparentize(Looks.colors.bg2)
colBackgroundHover: Looks.colors.bg2Hover
colBackgroundActive: Looks.colors.bg2Active
colBackground: ColorUtils.transparentize(Looks.colors.bg2)
colBackgroundHover: Looks.colors.bg2Hover
colBackgroundActive: Looks.colors.bg2Active
onMenuOpenChanged: {
// The overflow menu should only be closed when the user clicks outside
// However the focus grab refuses to reactivate, so we can't have that
// But most of the time the user dismisses the menu by clicking outside anyway,
// so this is acceptable.
if (!menuOpen) {
root.close();
onMenuOpenChanged: {
// The overflow menu should only be closed when the user clicks outside
// However the focus grab refuses to reactivate, so we can't have that
// But most of the time the user dismisses the menu by clicking outside anyway,
// so this is acceptable.
if (!menuOpen) {
root.close();
}
}
property real initialX
property real initialY
Behavior on x {
animation: Looks.transition.move.createObject(this)
}
Behavior on y {
animation: Looks.transition.move.createObject(this)
}
MouseArea {
id: dragArea
anchors.fill: parent
drag.target: parent
drag.threshold: 2
onPressed: event => {
trayButton.Drag.hotSpot.x = event.x;
trayButton.Drag.hotSpot.y = event.y;
trayButton.initialX = trayButton.x;
trayButton.initialY = trayButton.y;
trayButton.Drag.active = true;
}
onReleased: {
if (!dragArea.drag.active) {
trayButton.click();
} else {
if (!unpinDropArea.containsDrag && unpinDropArea.willUnpin) {
// 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);
unpinDropArea.willUnpin = false;
} else {
trayButton.x = trayButton.initialX;
trayButton.y = trayButton.initialY;
}
}
trayButton.Drag.active = false;
}
}
}
}
}
DropArea {
id: unpinDropArea
anchors.fill: parent
property bool willUnpin: false
onEntered: willUnpin = false
onExited: willUnpin = true
}
}
}