fix: Main interface does not gray out when losing focus#570
fix: Main interface does not gray out when losing focus#570JWWTSL wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
log: In the DialogWindow, when set to WindowModal, the transientParent is automatically set to Qt.application.activeWindow. Upon display, raise() and requestActivate() are called to ensure the main window correctly enters a grayed-out state. pms: bug-336201
Reviewer's GuideEnsures WindowModal DialogWindow instances correctly set and maintain their transient parent and, when shown, raise and activate themselves so the main window enters the expected grayed-out (modal) state. Sequence diagram for WindowModal DialogWindow activation and main window grayingsequenceDiagram
actor User
participant MainWindow
participant DialogWindow
participant QtApplication
User->>MainWindow: openDialog()
MainWindow->>DialogWindow: create DialogWindow (modality = Qt.WindowModal)
DialogWindow->>DialogWindow: Component.onCompleted
alt modality is WindowModal and transientParentWindow is null
DialogWindow->>QtApplication: get activeWindow
QtApplication-->>DialogWindow: activeWindow
DialogWindow->>DialogWindow: set transientParentWindow
DialogWindow->>DialogWindow: bind transientParent to transientParentWindow
end
User->>DialogWindow: set visible = true
DialogWindow->>DialogWindow: onVisibleChanged (visible = true)
alt modality is WindowModal
alt transientParentWindow is null or equals control
DialogWindow->>QtApplication: get activeWindow
QtApplication-->>DialogWindow: activeWindow
DialogWindow->>DialogWindow: set transientParentWindow
end
DialogWindow->>DialogWindow: Qt.callLater
DialogWindow->>DialogWindow: raise()
DialogWindow->>DialogWindow: requestActivate()
DialogWindow->>MainWindow: enforce modal relationship (main window grayed)
end
Updated class diagram for DialogWindow QML componentclassDiagram
class DialogWindow {
<<Window>>
+real leftPadding
+real rightPadding
+var transientParentWindow
+Window transientParent
+onCompleted()
+onVisibleChanged(visible)
+onClosing(close)
}
class QtApplication {
+Window activeWindow
+callLater(callback)
}
class Window {
+bool visible
+int modality
+void raise()
+void requestActivate()
}
DialogWindow --|> Window
DialogWindow --> QtApplication : uses
QtApplication --> Window : returns activeWindow
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:
- When the dialog becomes visible,
Qt.application.activeWindowmay already be the dialog itself, so thetransientParentWindow === controlguard and re-read ofactiveWindowwill still not yield the main window; consider capturing the previously active window before showing or using a more reliable source for the parent. - Overwriting
transientParentWindowinonVisibleChangedcan break any external binding or explicit assignment to this property; if it is meant to be user-configurable, consider only setting a default once (e.g., via a binding or when the property is stillnull) rather than reassigning on every visibility change.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When the dialog becomes visible, `Qt.application.activeWindow` may already be the dialog itself, so the `transientParentWindow === control` guard and re-read of `activeWindow` will still not yield the main window; consider capturing the previously active window before showing or using a more reliable source for the parent.
- Overwriting `transientParentWindow` in `onVisibleChanged` can break any external binding or explicit assignment to this property; if it is meant to be user-configurable, consider only setting a default once (e.g., via a binding or when the property is still `null`) rather than reassigning on every visibility change.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Pull request overview
This PR fixes a focus/modality behavior issue where DialogWindow instances shown as Qt.WindowModal don’t correctly gray out the main window by ensuring a transient parent is set and activating the dialog when it becomes visible.
Changes:
- Introduce a
transientParentWindowproperty and bindtransientParentto it. - Auto-assign
transientParentWindowtoQt.application.activeWindowforQt.WindowModaldialogs. - On show, raise and request activation for window-modal dialogs to trigger expected grayed-out behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Component.onCompleted: { | ||
| if (control.modality === Qt.WindowModal && !transientParentWindow) | ||
| transientParentWindow = Qt.application.activeWindow | ||
| } | ||
|
|
||
| onVisibleChanged: { | ||
| if (!control.visible) | ||
| return | ||
| if (control.modality !== Qt.WindowModal) | ||
| return | ||
| if (!transientParentWindow || transientParentWindow === control) | ||
| transientParentWindow = Qt.application.activeWindow | ||
| Qt.callLater(function () { | ||
| control.raise() | ||
| control.requestActivate() | ||
| }) |
There was a problem hiding this comment.
transientParentWindow is only set when it is null (or equals control). Once it has been auto-assigned the first time, it will not update on subsequent shows. If a DialogWindow instance is reused across multiple top-level windows, the dialog can remain transient for the original window, causing the wrong window to gray out (or none) when shown from another active window. Consider recalculating the transient parent each time the dialog becomes visible (or clearing the auto-assigned parent when the dialog is hidden), while still respecting an explicitly provided transient parent when callers set one.
log: In the DialogWindow, when set to WindowModal, the transientParent is automatically set to Qt.application.activeWindow. Upon display, raise() and requestActivate() are called to ensure the main window correctly enters a grayed-out state.
pms: bug-336201
Summary by Sourcery
Bug Fixes: