fix notif popup anims

This commit is contained in:
end-4
2025-05-22 14:24:52 +02:00
parent 382a75e4c6
commit b66f1b7e93
2 changed files with 69 additions and 59 deletions
@@ -33,76 +33,80 @@ Scope {
} }
mask: Region { mask: Region {
item: columnLayout item: listview.contentItem
} }
color: "transparent" color: "transparent"
implicitWidth: Appearance.sizes.notificationPopupWidth implicitWidth: Appearance.sizes.notificationPopupWidth
// Signal handlers to add/remove notifications ListView { // Scrollable window
Connections { id: listview
target: Notifications anchors.top: parent.top
function onNotify(notification) { anchors.bottom: parent.bottom
if (GlobalStates.sidebarRightOpen) { anchors.horizontalCenter: parent.horizontalCente
return implicitWidth: parent.width - Appearance.sizes.elevationMargin * 2
}
// notificationRepeater.model = [notification, ...notificationRepeater.model]
const notif = root.notifComponent.createObject(columnLayout, {
notificationObject: notification,
popup: true
});
notificationWidgetList.unshift(notif)
// Remove stuff from t he column, add back add: Transition {
for (let i = 0; i < notificationWidgetList.length; i++) { animations: [
if (notificationWidgetList[i].parent === columnLayout) { Appearance.animation.elementMove.numberAnimation.createObject(this, {
notificationWidgetList[i].parent = null; properties: "opacity,scale",
} from: 0,
} to: 1,
}),
]
}
// Add notification widgets to the column addDisplaced: Transition {
for (let i = 0; i < notificationWidgetList.length; i++) { animations: [
if (notificationWidgetList[i].parent === null) { Appearance.animation.elementMove.numberAnimation.createObject(this, {
notificationWidgetList[i].parent = columnLayout; property: "y",
} }),
} Appearance.animation.elementMove.numberAnimation.createObject(this, {
properties: "opacity,scale",
to: 1,
}),
]
} }
function onDiscard(id) {
for (let i = notificationWidgetList.length - 1; i >= 0; i--) {
const widget = notificationWidgetList[i];
if (widget && widget.notificationObject && widget.notificationObject.id === id) {
widget.destroyWithAnimation();
notificationWidgetList.splice(i, 1);
}
}
}
function onTimeout(id) {
for (let i = notificationWidgetList.length - 1; i >= 0; i--) {
const widget = notificationWidgetList[i];
if (widget && widget.notificationObject && widget.notificationObject.id === id) {
widget.destroyWithAnimation();
notificationWidgetList.splice(i, 1);
}
}
}
function onDiscardAll() {
for (let i = notificationWidgetList.length - 1; i >= 0; i--) {
const widget = notificationWidgetList[i];
if (widget && widget.notificationObject) {
widget.destroyWithAnimation();
}
}
notificationWidgetList = [];
}
}
ColumnLayout { // Scrollable window content displaced: Transition {
id: columnLayout animations: [
anchors.horizontalCenter: parent.horizontalCenter Appearance.animation.elementMove.numberAnimation.createObject(this, {
width: parent.width - Appearance.sizes.elevationMargin * 2 property: "y",
spacing: 0 // The widgets themselves have margins for spacing }),
]
}
move: Transition {
animations: [
Appearance.animation.elementMove.numberAnimation.createObject(this, {
property: "y",
}),
]
}
// Notifications are added by the above signal handlers remove: Transition {
animations: [
Appearance.animation.elementMove.numberAnimation.createObject(this, {
property: "x",
to: listview.width,
}),
Appearance.animation.elementMove.numberAnimation.createObject(this, {
property: "opacity",
to: 0,
})
]
}
model: ScriptModel {
values: Notifications.popupList.slice().reverse()
}
delegate: NotificationWidget {
required property var modelData
id: notificationWidget
popup: true
anchors.left: parent?.left
anchors.right: parent?.right
notificationObject: modelData
}
} }
} }
@@ -12,6 +12,7 @@ Singleton {
id: root id: root
property var filePath: `${XdgDirectories.cache}/notifications/notifications.json` property var filePath: `${XdgDirectories.cache}/notifications/notifications.json`
property var list: [] property var list: []
property var popupList: []
// Quickshell's notification IDs starts at 1 on each run, while saved notifications // Quickshell's notification IDs starts at 1 on each run, while saved notifications
// can already contain higher IDs. This is for avoiding id collisions // can already contain higher IDs. This is for avoiding id collisions
property int idOffset property int idOffset
@@ -53,6 +54,7 @@ Singleton {
"urgency": notification.urgency.toString(), "urgency": notification.urgency.toString(),
} }
root.list = [...root.list, newNotifObject]; root.list = [...root.list, newNotifObject];
root.popupList = [...root.popupList, newNotifObject];
root.notify(newNotifObject); root.notify(newNotifObject);
notifFileView.setText(JSON.stringify(root.list, null, 2)) notifFileView.setText(JSON.stringify(root.list, null, 2))
} }
@@ -69,6 +71,7 @@ Singleton {
if (notifServerIndex !== -1) { if (notifServerIndex !== -1) {
notifServer.trackedNotifications.values[notifServerIndex].dismiss() notifServer.trackedNotifications.values[notifServerIndex].dismiss()
} }
root.popupList = root.popupList.filter((notif) => notif.id !== id);
root.discard(id); root.discard(id);
} }
@@ -83,6 +86,8 @@ Singleton {
} }
function timeoutNotification(id) { function timeoutNotification(id) {
const index = root.list.findIndex((notif) => notif.id === id);
root.popupList = root.popupList.filter((notif) => notif.id !== id);
root.timeout(id); root.timeout(id);
} }
@@ -90,6 +95,7 @@ Singleton {
root.list.forEach((notif) => { root.list.forEach((notif) => {
root.timeout(notif.id); root.timeout(notif.id);
}) })
root.popupList = []
} }
function attemptInvokeAction(id, notifIdentifier) { function attemptInvokeAction(id, notifIdentifier) {
@@ -100,7 +106,7 @@ Singleton {
action.invoke() action.invoke()
} }
// else console.log("Notification not found in server: " + id) // else console.log("Notification not found in server: " + id)
root.discard(id); // root.discard(id);
} }
function triggerListChange() { function triggerListChange() {