forked from Shinonome/dots-hyprland
waffles: notif center: drag to dismiss
This commit is contained in:
+49
-10
@@ -1,3 +1,4 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
@@ -18,10 +19,44 @@ MouseArea {
|
||||
implicitWidth: contentLayout.implicitWidth
|
||||
implicitHeight: contentLayout.implicitHeight
|
||||
|
||||
function dismissAll() {
|
||||
root.notifications.forEach(notif => {
|
||||
Qt.callLater(() => {
|
||||
Notifications.discardNotification(notif.notificationId);
|
||||
});
|
||||
});
|
||||
removeAnimation.start();
|
||||
}
|
||||
|
||||
WNotificationDismissAnim {
|
||||
id: removeAnimation
|
||||
target: root
|
||||
}
|
||||
|
||||
property real dragDismissThreshold: 100
|
||||
drag {
|
||||
axis: Drag.XAxis
|
||||
target: contentLayout
|
||||
minimumX: 0
|
||||
onActiveChanged: {
|
||||
if (drag.active)
|
||||
return;
|
||||
if (contentLayout.x > root.dragDismissThreshold) {
|
||||
root.dismissAll();
|
||||
} else {
|
||||
contentLayout.x = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: contentLayout
|
||||
anchors.fill: parent
|
||||
spacing: 4
|
||||
width: root.width
|
||||
|
||||
Behavior on x {
|
||||
animation: Looks.transition.enter.createObject(this)
|
||||
}
|
||||
|
||||
GroupHeader {
|
||||
id: notifHeader
|
||||
@@ -29,7 +64,9 @@ MouseArea {
|
||||
Layout.margins: 11
|
||||
}
|
||||
|
||||
ListView {
|
||||
WListView {
|
||||
Layout.leftMargin: -Math.min(35, contentLayout.x)
|
||||
Layout.rightMargin: -Layout.leftMargin
|
||||
Layout.fillWidth: true
|
||||
implicitWidth: notifHeader.implicitWidth
|
||||
implicitHeight: contentHeight
|
||||
@@ -40,14 +77,20 @@ MouseArea {
|
||||
objectProp: "notificationId"
|
||||
}
|
||||
delegate: WSingleNotification {
|
||||
id: singleNotif
|
||||
required property int index
|
||||
required property var modelData
|
||||
|
||||
width: ListView.view.width
|
||||
notification: modelData
|
||||
|
||||
groupExpandControlMessage: {
|
||||
if (root.notifications.length <= 1) return "";
|
||||
if (!root.expanded) return Translation.tr("+%1 notifications").arg(root.notifications.length - 1);
|
||||
if (index === root.notifications.length - 1) return Translation.tr("See fewer");
|
||||
if (root.notifications.length <= 1)
|
||||
return "";
|
||||
if (!root.expanded)
|
||||
return Translation.tr("+%1 notifications").arg(root.notifications.length - 1);
|
||||
if (index === root.notifications.length - 1)
|
||||
return Translation.tr("See fewer");
|
||||
return "";
|
||||
}
|
||||
onGroupExpandToggle: {
|
||||
@@ -94,11 +137,7 @@ MouseArea {
|
||||
Layout.rightMargin: 3
|
||||
icon.name: "dismiss"
|
||||
onClicked: {
|
||||
root.notifications.forEach(notif => {
|
||||
Qt.callLater(() => {
|
||||
Notifications.discardNotification(notif.notificationId);
|
||||
});
|
||||
});
|
||||
root.dismissAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user