Repository navigation
fix: center dialog on parent screen - #252
wangrong1069 wants to merge 1 commit into
Conversation
1. Root cause: DTK6 DAbstractDialog::getParentGeometry() uses parentWidget()->window()->geometry() which returns position (0,0) on Wayland, causing dialogs to center on primary screen 2. Fix: override showEvent in DDBase to use parentWidget()->screen()->geometry() for centering, which returns correct screen geometry on both X11 and Wayland 3. Impact: all DDBase-derived dialogs now center on the screen where the parent window resides Log: fix dialog appearing on primary screen in multi-monitor setup Influence: 1. Test dialog positioning in dual-monitor Wayland session 2. Test dialog positioning in single-monitor session for regression 3. Verify all DDBase-derived dialogs appear on correct screen fix: 修复双屏环境下弹窗显示在主屏的问题 1. 根因:DTK6 DAbstractDialog::getParentGeometry() 使用 parentWidget()->window()->geometry(),在 Wayland 下返回 (0,0), 导致弹窗居中到主屏而非父窗口所在屏幕 2. 方案:在 DDBase 中覆盖 showEvent,使用 parentWidget()->screen()->geometry() 计算居中位置, 该接口在 X11 和 Wayland 下均返回屏幕物理几何 3. 影响:所有继承 DDBase 的弹窗将在父窗口所在屏幕居中显示 Log: 修复双屏环境下磁盘管理器弹窗显示在主屏的问题 Influence: 1. 测试双屏 Wayland 环境下弹窗定位 2. 测试单屏环境下弹窗定位(无回归) 3. 验证所有 DDBase 派生弹窗显示在正确屏幕 PMS: BUG-333047
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes dialog placement on multi-monitor Wayland by replacing DTK6’s window-geometry-based centering with parent-screen geometry, while preserving single-monitor behavior and existing keyboard handling. Sequence diagram for centering DDBase dialogs on the parent screensequenceDiagram
participant ParentWindow
participant DDBase
participant DDialog
participant Screen
ParentWindow->>DDBase: showEvent(event)
DDBase->>ParentWindow: screen()
ParentWindow-->>DDBase: Screen
DDBase->>Screen: geometry()
Screen-->>DDBase: screen geometry
DDBase->>DDBase: move(x, y)
DDBase->>DDialog: showEvent(event)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: wangrong1069 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 |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ❌评价: 存在逻辑缺陷 ❌ 不通过 潜在问题: 建议: ['将 move(x, y) 移至 DDialog::showEvent(event) 之后调用,确保自定义居中位置为最终生效位置', '考虑使用 QWindow::setScreen() 设置目标屏幕,或通过 transient parent 关系让 Wayland compositor 将对话框放置在父窗口所在屏幕'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['可考虑增加平台判断逻辑,在 Wayland 下使用 QWindow::setScreen() 替代 move()'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例#include <QShowEvent>
#include <QScreen>
#include <QWindow>
void DDBase::showEvent(QShowEvent *event)
{
DDialog::showEvent(event);
if (parentWidget() && parentWidget()->screen()) {
QScreen *targetScreen = parentWidget()->screen();
// Wayland 兼容:通过 setScreen 请求 compositor 将窗口放置在目标屏幕
if (windowHandle()) {
windowHandle()->setScreen(targetScreen);
}
QRect screenGeom = targetScreen->geometry();
QRect dialogGeom = geometry();
int x = screenGeom.x() + (screenGeom.width() - dialogGeom.width()) / 2;
int y = screenGeom.y() + (screenGeom.height() - dialogGeom.height()) / 2;
// 在基类 showEvent 之后调用 move,确保自定义位置为最终生效位置
move(x, y);
}
}本报告由 AI 代码审查工具自动生成 |
|
TAG Bot New tag: 6.0.29 |
|
TAG Bot New tag: 6.0.30 |
Root Cause Analysis
DTK6
DAbstractDialog::getParentGeometry()usesparentWidget()->window()->geometry()to determine the centering reference geometry. On Wayland,QWidget::geometry()returns position(0,0)because the Wayland protocol does not expose client-side absolute window coordinates. This causesmoveToCenter()to center the dialog on the primary screen (origin) rather than the screen where the parent window resides. The bug manifests in multi-monitor setups when disk manager is opened on a secondary screen and anyDDBase-derived dialog (e.g., Create Partition Table) appears on the primary screen instead.Fix Approach
Override
showEventinDDBase(ddbase.cpp/h) to compute centering usingparentWidget()->screen()->geometry()instead of the DTK6 defaultparentWidget()->window()->geometry(). Thescreen()->geometry()API returns the physical screen geometry on both X11 and Wayland, ensuring the dialog centers on the correct screen. AllDDBase-derived dialogs inherit this override automatically.Change Safety Assessment
Code Safety
protectedvirtual function override (showEvent) and one include (<QShowEvent>); no existing function signatures, public members, or code lines are modified.showEventwas never implemented inDDBasebefore (pickaxe confirmed). The existingkeyPressEventoverride (BUG-126825 ESC key fix) is untouched and independent.Business Impact Scope
All
DDBase-derived dialogs are affected: Create Partition Table, Format, Resize, Mount/Unmount, Decrypt, Password Input, and others. In multi-monitor setups, these dialogs will now appear on the screen where the parent window resides instead of the primary screen. Single-monitor behavior is unchanged (dialog centers on the only screen).Verification Suggestion
Test in a dual-monitor Wayland session: open disk manager on the secondary screen, trigger each dialog (new partition table, format, resize), and verify the dialog appears on the secondary screen. Also test single-monitor sessions for no regression.
根因分析
DTK6
DAbstractDialog::getParentGeometry()使用parentWidget()->window()->geometry()获取居中参考几何。Wayland 协议不暴露客户端窗口绝对坐标,QWidget::geometry()返回 position(0,0),导致moveToCenter()将弹窗居中到主屏原点而非父窗口所在屏幕。双屏环境下在副屏打开磁盘管理器时,所有DDBase派生弹窗(如新建分区表)显示在主屏。修复方案
在
DDBase(ddbase.cpp/h)中覆盖showEvent,使用parentWidget()->screen()->geometry()替代 DTK6 默认的parentWidget()->window()->geometry()计算居中位置。screen()->geometry()在 X11 和 Wayland 下均返回屏幕物理几何,确保弹窗在正确屏幕居中。所有继承DDBase的弹窗自动继承此覆盖。改动安全评估
代码安全评估
protected虚函数覆盖(showEvent)和一个 include(<QShowEvent>),不修改任何已有函数签名、公开成员或代码行。showEvent此前从未在DDBase中实现(pickaxe 确认)。已有的keyPressEvent覆盖(BUG-126825 ESC 键修复)不受影响且完全独立。业务影响范围
所有
DDBase派生弹窗均受影响:新建分区表、格式化、调整大小、挂载/卸载、解密、密码输入等。双屏环境下这些弹窗将显示在父窗口所在屏幕而非主屏。单屏环境行为不变(弹窗居中于唯一屏幕)。验证建议
在双屏 Wayland 环境下测试:副屏打开磁盘管理器,触发各弹窗(新建分区表、格式化、调整大小),验证弹窗显示在副屏。同时测试单屏环境确认无回归。
Summary by Sourcery
Bug Fixes: