feat: refactor NotificationHistory.qml to improve hover tracking and auto-closing behavior

This commit is contained in:
Hannes
2026-09-02 00:34:14 +02:00
parent aea40a3e42
commit 510cbb0cec
+12 -55
View File
@@ -65,23 +65,13 @@ PanelWindow {
} }
function closeNHistory() { function closeNHistory() {
// Centralized close via singleton signal fixes previous ReferenceError
// where this file tried to access notifificationHistoryLoader.id directly
// (that id lives in NotificationHistoryLoader.qml and is not in scope here).
console.log("[NotificationHistory] closeNHistory() requested") console.log("[NotificationHistory] closeNHistory() requested")
NotificationS.historyHovered = false NotificationS.historyHovered = false
NotificationS.closeHistoryRequested() NotificationS.closeHistoryRequested()
} }
// ── Hover tracking via NotificationServer ──
// History reports its hover state via background HoverHandler (non-exclusive)
// so hovering over inner buttons (closeArea, clearGroupArea, NotificationBody)
// does NOT clear historyHovered. Timer auto-closes when neither history nor
// bar button is hovered for historyAutoCloseDelay ms.
property bool _allowAutoClose: false property bool _allowAutoClose: false
// Grace timer: don't allow auto-close immediately after opening,
// giving keyboard users time to move mouse to history.
Timer { Timer {
id: graceTimer id: graceTimer
interval: 500 interval: 500
@@ -93,7 +83,6 @@ PanelWindow {
Timer { Timer {
id: hoverCloseTimer id: hoverCloseTimer
interval: NotificationS.historyAutoCloseDelay interval: NotificationS.historyAutoCloseDelay
// Only run when panel is visible, grace passed, and neither element is hovered
running: root.visible && _allowAutoClose && !NotificationS.historyHovered && !NotificationS.buttonHovered running: root.visible && _allowAutoClose && !NotificationS.historyHovered && !NotificationS.buttonHovered
repeat: false repeat: false
onTriggered: { onTriggered: {
@@ -104,7 +93,6 @@ PanelWindow {
} }
} }
// Ensure hover state is cleared when window hides/destroys
onVisibleChanged: { onVisibleChanged: {
if (!visible) { if (!visible) {
NotificationS.historyHovered = false NotificationS.historyHovered = false
@@ -124,12 +112,6 @@ PanelWindow {
root.closeNHistory() root.closeNHistory()
} }
} }
Rectangle {
anchors.fill: parent
color: "lightblue"
visible: false // debug helper, keep hidden in normal use
}
} }
Rectangle { Rectangle {
@@ -141,13 +123,7 @@ PanelWindow {
border.color: textColor border.color: textColor
radius: Config.screen_big_radius_fun(screen.height) radius: Config.screen_big_radius_fun(screen.height)
// HoverHandler on background (parent of all history UI) stays hovered
// when pointer is over any descendant (topBar buttons, NotificationBody etc.)
// because HoverHandler is non-blocking PointerHandler and tracks parent
// bounds rather than exclusive MouseArea containsMouse. This fixes bug
// where hovering over inner buttons made historyHovered false and triggered
// auto-close. Using CanTakeOverFromAnything ensures it isn't blocked by
// child MouseAreas.
HoverHandler { HoverHandler {
id: backgroundHoverHandler id: backgroundHoverHandler
blocking: false blocking: false
@@ -158,15 +134,6 @@ PanelWindow {
} }
} }
// Component.onCompleted: {
// for (var notification in NotificationS.trackedNotifications.values) {
// console.log("[NotificationHistory]: " + notification.appName + " Notifications")
// }
// for (var i =0; i < NotificationS.notificationNum; i++) {
// console.log("[NotificationHistory]: " + NotificationS.trackedNotifications.values[i].appName + " Notifications")
// }
// }
Column{ Column{
id: bgColumn id: bgColumn
anchors.fill: parent anchors.fill: parent
@@ -197,12 +164,6 @@ PanelWindow {
} }
} }
// Row{
// id: backgroundCenter
// anchors.centerIn: parent
// spacing: Config.screen_small_bar_spacing_fun(screen.height)
// }
Row{ Row{
id: backgroundRight id: backgroundRight
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@@ -224,6 +185,15 @@ PanelWindow {
implicitHeight: topBar.height*0.75 implicitHeight: topBar.height*0.75
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
checked: NotificationS.notificationPopupEnabled checked: NotificationS.notificationPopupEnabled
hoverEnabled: true
HoverHandler {
id: switchHoverHandler
cursorShape: Qt.PointingHandCursor
blocking: false
grabPermissions: PointerHandler.CanTakeOverFromAnything
onHoveredChanged: if (hovered) NotificationS.historyHovered = true
}
indicator: Rectangle { indicator: Rectangle {
implicitWidth: notificationVolumeSwitch.width implicitWidth: notificationVolumeSwitch.width
@@ -272,8 +242,7 @@ PanelWindow {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
// Safety: hovering over button should keep history considered hovered
// even if background HoverHandler is blocked (exclusive hover)
onContainsMouseChanged: if (containsMouse) NotificationS.historyHovered = true onContainsMouseChanged: if (containsMouse) NotificationS.historyHovered = true
Rectangle{ Rectangle{
anchors.fill: parent anchors.fill: parent
@@ -291,7 +260,6 @@ PanelWindow {
} }
onClicked: { onClicked: {
root.clearAll() root.clearAll()
// closeNHistory()
} }
} }
} }
@@ -299,7 +267,7 @@ PanelWindow {
Rectangle { Rectangle {
width: parent.width width: parent.width
height: parent.height - topBar.height - bgColumn.spacing //- bgColumn.anchors.margins*2 height: parent.height - topBar.height - bgColumn.spacing
color: textBGColor color: textBGColor
radius: Config.screen_big_radius_fun(screen.height) radius: Config.screen_big_radius_fun(screen.height)
border.width: Config.border_width border.width: Config.border_width
@@ -330,12 +298,6 @@ PanelWindow {
width: flick.width width: flick.width
spacing: Config.spacing spacing: Config.spacing
// ── Grouped view (only groups with >1 notification are grouped) ──
// Uses root.grouped (sorted by appName). Each app group with
// more than one notification is rendered as a collapsible
// card with a header (appName + count + expand/collapse +
// clear-group). Singletons are rendered directly as a
// NotificationBody without a header.
Repeater { Repeater {
id: groupedRepeater id: groupedRepeater
model: root.grouped model: root.grouped
@@ -348,19 +310,15 @@ PanelWindow {
property bool isExpanded: root.expandedGroups[group.appName] === true property bool isExpanded: root.expandedGroups[group.appName] === true
width: contentColumn.width width: contentColumn.width
// height adapts to which component is visible
implicitHeight: isGrouped ? groupedCard.implicitHeight : singleBody.implicitHeight implicitHeight: isGrouped ? groupedCard.implicitHeight : singleBody.implicitHeight
height: implicitHeight height: implicitHeight
// Keep history hovered when pointer is over this delegate
// (covers NotificationBody and its inner buttons).
HoverHandler { HoverHandler {
blocking: false blocking: false
grabPermissions: PointerHandler.CanTakeOverFromAnything grabPermissions: PointerHandler.CanTakeOverFromAnything
onHoveredChanged: if (hovered) NotificationS.historyHovered = true onHoveredChanged: if (hovered) NotificationS.historyHovered = true
} }
// ── Singleton: plain NotificationBody ──
NotificationBody { NotificationBody {
id: singleBody id: singleBody
visible: !delegateRoot.isGrouped visible: !delegateRoot.isGrouped
@@ -374,7 +332,6 @@ PanelWindow {
} }
} }
// ── Grouped card (count > 1) ──
Rectangle { Rectangle {
id: groupedCard id: groupedCard
visible: delegateRoot.isGrouped visible: delegateRoot.isGrouped