Skip to content

Commit bb6de1b

Browse files
committed
fix: fix warning with closebtn and binding loop.
更新了 closebtn的未定义问题,修复了hover通知,循环依赖问题。 更新通知焦点循环一次后,第二次循环无法经过overlapnotify,从而无法给到焦点到后面其他的通知上。 以及修复 shift+tab 保证跟tab的逻辑一致,能够正常响应焦点处理。 还需修复: 带有action的通知焦点处理。
1 parent b87de4e commit bb6de1b

7 files changed

Lines changed: 24 additions & 38 deletions

File tree

panels/notification/center/GroupNotify.qml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -111,7 +111,6 @@ NotifyItem {
111111
icon.name: "clean-group"
112112
text: qsTr("Clear All")
113113
Keys.onTabPressed: function(event) {
114-
groupClearBtn.focus = false // Clear focus before signal to prevent focus state residue
115114
root.gotoNextItem()
116115
event.accepted = true
117116
}

panels/notification/center/NormalNotify.qml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -13,7 +13,6 @@ NotifyItem {
1313
id: root
1414
implicitWidth: impl.implicitWidth
1515
implicitHeight: impl.implicitHeight
16-
property bool shouldShowClose: false // True when item gets focus from keyboard navigation
1716

1817
signal gotoNextItem()
1918
signal gotoPrevItem()
@@ -32,19 +31,16 @@ NotifyItem {
3231
focus: true
3332

3433
Keys.onTabPressed: function(event) {
35-
// Mark that this item got focus from Tab navigation
36-
root.shouldShowClose = true
37-
if (notifyContent.focusFirstButton()) {
38-
event.accepted = true
39-
} else {
34+
if (!notifyContent.focusFirstButton()) {
4035
root.gotoNextItem()
41-
event.accepted = true
4236
}
37+
event.accepted = true
4338
}
4439

4540
Keys.onBacktabPressed: function(event) {
46-
root.shouldShowClose = true
47-
root.gotoPrevItem()
41+
if (!notifyContent.focusLastButton()) {
42+
root.gotoPrevItem()
43+
}
4844
event.accepted = true
4945
}
5046

@@ -59,7 +55,7 @@ NotifyItem {
5955
actions: root.actions
6056
defaultAction: root.defaultAction
6157
// Show close button when: mouse hovers, or item has focus from keyboard navigation
62-
parentHovered: impl.hovered || (root.activeFocus && root.shouldShowClose)
58+
parentHovered: impl.hovered || root.activeFocus
6359
strongInteractive: root.strongInteractive
6460
contentIcon: root.contentIcon
6561
contentRowCount: root.contentRowCount

panels/notification/center/NotifyHeader.qml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ FocusScope {
150150
text: qsTr("Clear All")
151151
Layout.alignment: Qt.AlignRight
152152
Keys.onTabPressed: function(event) {
153-
clearAllBtn.focus = false // Clear focus before signal to prevent focus state residue
154153
root.gotoFirstNotify()
155154
event.accepted = true
156155
}

panels/notification/center/NotifyView.qml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ Control {
3838
function tryFocus(retries) {
3939
let item = view.itemAtIndex(idx)
4040
if (item && item.enabled) {
41-
item.forceActiveFocus()
41+
if (!item.focusFirstButton()) {
42+
item.forceActiveFocus()
43+
}
4244
} else if (retries > 0) {
4345
Qt.callLater(function() { tryFocus(retries - 1) })
4446
}

panels/notification/center/NotifyViewDelegate.qml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ DelegateChooser {
2626
Qt.callLater(function() {
2727
let nextItem = view.itemAtIndex(currentIndex + 1)
2828
if (nextItem && nextItem.enabled) {
29-
// Focus on the item itself first, not directly to buttons
3029
nextItem.forceActiveFocus()
3130
}
3231
})
@@ -43,7 +42,6 @@ DelegateChooser {
4342
Qt.callLater(function() {
4443
let prevItem = view.itemAtIndex(currentIndex - 1)
4544
if (prevItem && prevItem.enabled) {
46-
// Focus on the item itself first, not directly to buttons
4745
prevItem.forceActiveFocus()
4846
}
4947
})
@@ -177,8 +175,8 @@ DelegateChooser {
177175
activeFocusOnTab: false
178176
focusBorderVisible: activeFocus
179177
Keys.onTabPressed: function(event) {
180-
// Try to focus first action button
181-
if (overlapNotify.focusFirstButton()) {
178+
// Try to focus first action button (skip clear button to avoid loop)
179+
if (notifyContent.focusFirstActionOnly()) {
182180
event.accepted = true
183181
return
184182
}
@@ -196,11 +194,6 @@ DelegateChooser {
196194
}
197195
}
198196

199-
Component.onCompleted: {
200-
// Pass clear button reference to OverlapNotify
201-
overlapNotify.clearButton = clearBtn
202-
}
203-
204197
TapHandler {
205198
acceptedButtons: Qt.RightButton
206199
onPressedChanged: function () {

panels/notification/center/OverlapNotify.qml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -17,15 +17,14 @@ NotifyItem {
1717
property int count: 1
1818
readonly property int overlapItemRadius: 12
1919
property bool enableDismissed: true
20-
property bool shouldShowClose: false // True when item gets focus from keyboard navigation
2120
property var removedCallback
2221
property alias notifyContent: notifyContent
2322

2423
signal expand()
2524
signal gotoNextItem()
2625
signal gotoPrevItem()
2726

28-
property var clearButton: null // Reference to the externally defined clear button
27+
property var clearButton: notifyContent.clearButtonItem
2928

3029
function focusFirstButton() {
3130
// Focus clear button first, then action buttons
@@ -77,18 +76,16 @@ NotifyItem {
7776
focus: true
7877

7978
Keys.onTabPressed: function(event) {
80-
root.shouldShowClose = true
81-
if (notifyContent.focusFirstButton()) {
82-
event.accepted = true
83-
} else {
79+
if (!notifyContent.focusFirstButton()) {
8480
root.gotoNextItem()
85-
event.accepted = true
8681
}
82+
event.accepted = true
8783
}
8884

8985
Keys.onBacktabPressed: function(event) {
90-
root.shouldShowClose = true
91-
root.gotoPrevItem()
86+
if (!notifyContent.focusLastButton()) {
87+
root.gotoPrevItem()
88+
}
9289
event.accepted = true
9390
}
9491

@@ -106,7 +103,7 @@ NotifyItem {
106103
actions: root.actions
107104
defaultAction: root.defaultAction
108105
// Show close button when: mouse hovers, or item has focus from keyboard navigation
109-
parentHovered: impl.hovered || (root.activeFocus && root.shouldShowClose)
106+
parentHovered: impl.hovered || root.activeFocus
110107
strongInteractive: root.strongInteractive
111108
contentIcon: root.contentIcon
112109
contentRowCount: root.contentRowCount

panels/notification/plugin/NotifyItemContent.qml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ NotifyItem {
1616
// Maximum retry attempts for focus operations when loader content is pending
1717
readonly property int maxFocusRetries: 5
1818
property bool parentHovered: false // External hover state from parent component
19-
property bool closeVisible: activeFocus || impl.hovered || parentHovered || (clearLoader.item && clearLoader.item.activeFocus)
19+
property bool closeVisible: activeFocus || impl.hovered || parentHovered
2020
property int miniContentHeight: NotifyStyle.contentItem.miniHeight
2121
property bool enableDismissed: true
2222
property alias clearButton: clearLoader.sourceComponent
23+
readonly property alias clearButtonItem: clearLoader.item
2324

2425
signal gotoNextItem() // Signal to navigate to next notify item
2526
signal gotoPrevItem() // Signal to navigate to previous notify item
@@ -111,8 +112,7 @@ NotifyItem {
111112
id: clearLoader
112113
anchors.right: parent.right
113114
// Show when mouse hovers or notification item has focus
114-
// Keep active when button itself has focus to prevent unloading during Tab navigation
115-
active: !(root.strongInteractive && root.actions.length > 0) && (root.closeVisible || closePlaceHolder.hovered || (clearLoader.item && clearLoader.item.activeFocus))
115+
active: !(root.strongInteractive && root.actions.length > 0) && (root.closeVisible || closePlaceHolder.hovered)
116116
sourceComponent: SettingActionButton {
117117
id: closeBtn
118118
objectName: "closeNotify-" + root.appName

0 commit comments

Comments
 (0)