fix: Main interface does not gray out when losing focus#3013
fix: Main interface does not gray out when losing focus#3013JWWTSL wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: JWWTSL The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures the Create Account dialog correctly sets and resolves its transient parent and activates itself when shown so that Qt.WindowModal properly grays out the main window on focus loss, aligning behavior with other modal dialogs. Sequence diagram for CreateAccountDialog transient parent resolution and activationsequenceDiagram
actor User
participant MainWindow as DccAppMainWindow
participant CreateAccountDialog
participant QtApplication
User->>MainWindow: OpenCreateAccountDialog
MainWindow->>CreateAccountDialog: create and show
activate CreateAccountDialog
CreateAccountDialog->>CreateAccountDialog: Component.onCompleted
CreateAccountDialog->>CreateAccountDialog: resolveTransientParent
CreateAccountDialog->>DccAppMainWindow: DccApp.mainWindow()
alt DccApp.mainWindow available
DccAppMainWindow-->>CreateAccountDialog: mainWindow reference
else DccApp.mainWindow not available
CreateAccountDialog->>QtApplication: Qt.application.activeWindow
QtApplication-->>CreateAccountDialog: activeWindow reference
end
CreateAccountDialog->>CreateAccountDialog: transientParentWindow = resolved window
CreateAccountDialog->>CreateAccountDialog: transientParent bound to transientParentWindow
CreateAccountDialog->>CreateAccountDialog: visible = true
CreateAccountDialog->>CreateAccountDialog: onVisibleChanged
alt transientParentWindow null or self
CreateAccountDialog->>CreateAccountDialog: transientParentWindow = resolveTransientParent
end
CreateAccountDialog->>QtApplication: Qt.callLater(dialog.requestActivate)
QtApplication-->>CreateAccountDialog: requestActivate invoked
CreateAccountDialog->>DccAppMainWindow: enforce Qt.WindowModal
DccAppMainWindow->>DccAppMainWindow: enter grayed_out state
deactivate CreateAccountDialog
Class diagram for updated CreateAccountDialog QML componentclassDiagram
class DialogWindow
class CreateAccountDialog {
+var transientParentWindow
+int width
+int minimumWidth
+int minimumHeight
+int maximumWidth
+int maximumHeight
+string icon
+var transientParent
+var modality
+string title
+signal accepted()
+var visible
+var id
+var mainLayout
+function resolveTransientParent()
+handler Component_onCompleted()
+handler onVisibleChanged()
}
CreateAccountDialog --|> DialogWindow
class DccApp {
+function mainWindow()
}
class QtApplication {
+var activeWindow
+function callLater(callback)
}
CreateAccountDialog ..> DccApp : uses
CreateAccountDialog ..> QtApplication : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
resolveTransientParent(), you should avoid returningdialogitself (e.g., whenQt.application.activeWindowis the dialog andDccApp.mainWindowis unavailable), otherwisetransientParentends up pointing to the dialog, defeating the purpose of having a real parent window. - Consider deferring the first call to
resolveTransientParent()until the dialog is actually becoming visible (and possibly after a shortQt.callLater) instead of running it inComponent.onCompleted, to reduce the chance of racing with initialization ofDccApp.mainWindow.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `resolveTransientParent()`, you should avoid returning `dialog` itself (e.g., when `Qt.application.activeWindow` is the dialog and `DccApp.mainWindow` is unavailable), otherwise `transientParent` ends up pointing to the dialog, defeating the purpose of having a real parent window.
- Consider deferring the first call to `resolveTransientParent()` until the dialog is actually becoming visible (and possibly after a short `Qt.callLater`) instead of running it in `Component.onCompleted`, to reduce the chance of racing with initialization of `DccApp.mainWindow`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
log: When the “New User” dialog is a top-level DialogWindow, it fails to reliably bind to the main window's transient parent/fail to reliably activate as the active window. This prevents Qt.WindowModal from triggering the main window to enter a grayed-out state upon losing focus in certain environments. The fix involves prioritizing the setting of transientParent with DccApp.mainWindow() in CreateAccountDialog.qml and calling requestActivate() when the dialog appears. This ensures the main interface grayscale behavior aligns with other modal dialogs. pms: bug-336201 Translated with DeepL.com (free version)
deepin pr auto review这段代码主要是在 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
综合改进建议代码D.DialogWindow {
id: dialog
// 建议明确类型,如果 DTK 或 Qt 模块提供了 QWindow 的 QML 封装类型
// property var transientParentWindow: null
// 或者保持 var,但添加注释说明
width: 460
minimumWidth: width
minimumHeight: height
maximumWidth: minimumWidth
maximumHeight: minimumHeight
icon: "preferences-system"
// 初始设为 null,由 onVisibleChanged 统一管理
transientParent: transientParentWindow
modality: Qt.WindowModal
title: qsTr("Create a new account")
signal accepted()
// 移除 Component.onCompleted,避免过早获取 activeWindow 可能导致的不确定性
onVisibleChanged: {
if (!visible) {
return;
}
// 更新 transientParent
// 只有当当前父窗口无效,或者当前父窗口是自身时才更新
// (自身作为父窗口是无效状态,需要修正)
if (!transientParentWindow || transientParentWindow === dialog) {
var candidate = Qt.application.activeWindow;
// 确保获取到的窗口不是对话框自身,且不是 null
if (candidate && candidate !== dialog) {
transientParentWindow = candidate;
}
}
// 延迟激活,确保窗口状态稳定
Qt.callLater(function () {
dialog.raise();
dialog.requestActivate();
});
}
ColumnLayout {
id: mainLayout
width: dialog.width - 20
// ...
}
}总结这段代码的主要目的是为了解决对话框在某些情况下无法获得焦点或显示层级不正确的问题。目前的实现基本可行,但在初始化时机和边缘情况处理上可以更严谨一些。建议移除 |
log: When the “New User” dialog is a top-level DialogWindow, it fails to reliably bind to the main window's transient parent/fail to reliably activate as the active window. This prevents Qt.WindowModal from triggering the main window to enter a grayed-out state upon losing focus in certain environments. The fix involves prioritizing the setting of transientParent with DccApp.mainWindow() in CreateAccountDialog.qml and calling requestActivate() when the dialog appears. This ensures the main interface grayscale behavior aligns with other modal dialogs.
pms: bug-336201
Translated with DeepL.com (free version)
Summary by Sourcery
Bug Fixes: