Skip to content

fix: center dialog on parent screen - #252

Draft
wangrong1069 wants to merge 1 commit into
linuxdeepin:masterfrom
wangrong1069:agent/agent/b61c7733f912
Draft

wangrong1069 wants to merge 1 commit into
linuxdeepin:masterfrom
wangrong1069:agent/agent/b61c7733f912

Conversation

@wangrong1069

@wangrong1069 wangrong1069 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

DTK6 DAbstractDialog::getParentGeometry() uses parentWidget()->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 causes moveToCenter() 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 any DDBase-derived dialog (e.g., Create Partition Table) appears on the primary screen instead.

Fix Approach

Override showEvent in DDBase (ddbase.cpp/h) to compute centering using parentWidget()->screen()->geometry() instead of the DTK6 default parentWidget()->window()->geometry(). The screen()->geometry() API returns the physical screen geometry on both X11 and Wayland, ensuring the dialog centers on the correct screen. All DDBase-derived dialogs inherit this override automatically.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • The change adds a new protected virtual function override (showEvent) and one include (<QShowEvent>); no existing function signatures, public members, or code lines are modified.
  • Historical insight: showEvent was never implemented in DDBase before (pickaxe confirmed). The existing keyPressEvent override (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:

  • Ensure DDBase-derived dialogs are centered on the screen containing their parent window, including multi-monitor Wayland setups.

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
@wangrong1069
wangrong1069 marked this pull request as draft November 6, 2026 11:20
@sourcery-ai

sourcery-ai Bot commented Nov 6, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes 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 screen

sequenceDiagram
    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)
Loading

File-Level Changes

Change Details Files
Override dialog display positioning to center DDBase dialogs on the parent window’s screen.
  • Add a QShowEvent include and protected showEvent override.
  • Calculate the screen-relative center from parentWidget()->screen()->geometry().
  • Move the dialog before delegating to the base-class show event.
  • Automatically apply the behavior to all DDBase-derived dialogs.
application/widgets/customcontrol/ddbase.cpp
application/widgets/customcontrol/ddbase.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 90 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 DDBase 对话框添加 showEvent 覆盖,实现对话框在父窗口所在屏幕居中显示。 代码语法正确、结构清晰、注释完整、无安全漏洞。但存在一个逻辑缺陷:move() 调用在 DDialog::showEvent(event) 之前,DTK6 基类 showEvent 内部的 moveToCenter() 会覆盖自定义位置, 导致修复可能无效;同时在 Wayland 平台上 move() 对顶层窗口无效,需配合 QWindow::setScreen() 使用。 综合四维度评分 90 分,审查通过但建议修复上述问题。

🔍 详细分析

1. 语法逻辑 ❌

评价: 存在逻辑缺陷 ❌ 不通过

潜在问题:
✅ 未发现明显问题

建议: ['将 move(x, y) 移至 DDialog::showEvent(event) 之后调用,确保自定义居中位置为最终生效位置', '考虑使用 QWindow::setScreen() 设置目标屏幕,或通过 transient parent 关系让 Wayland compositor 将对话框放置在父窗口所在屏幕']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['可考虑增加平台判断逻辑,在 Wayland 下使用 QWindow::setScreen() 替代 move()']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 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 代码审查工具自动生成

@deepin-bot

deepin-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.29
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #259

@deepin-bot

deepin-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.30
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #261

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants