Skip to content

fix(window): prevent window re-centering on image switch#285

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master
Apr 23, 2026
Merged

fix(window): prevent window re-centering on image switch#285
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master

Conversation

@wyu71
Copy link
Copy Markdown
Contributor

@wyu71 wyu71 commented Apr 23, 2026

Only center window when opening new files via setImageFiles(), not on every currentSourceChanged during browsing.

仅在通过setImageFiles()打开新文件时居中窗口,
而非每次切换图片浏览时都重新居中。

Log: 修复切换图片时窗口位置重置到居中的问题
PMS: BUG-358647
Influence: 移动窗口后切换图片不再跳回屏幕居中,仅在首次打开图片文件时居中。

Copy link
Copy Markdown
Contributor

@lzwind lzwind left a comment

Choose a reason for hiding this comment

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

处理下license

lzwind
lzwind previously approved these changes Apr 23, 2026
Remove window centering from onCurrentSourceChanged to keep window
position during image browsing. Center only once on startup.

移除 onCurrentSourceChanged 中的窗口居中逻辑,仅在程序首次
启动时居中窗口,切换和打开图片时保持用户摆放的位置。

Log: 修复切换图片时窗口位置重置到居中的问题
PMS: BUG-358647
Influence: 移动窗口后切换或打开图片不再跳回屏幕居中,仅在首次启动时居中。
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码的修改主要是对 src/qml/main.qml 文件中的版权年份更新以及移除了一段窗口位置调整的逻辑。以下是从语法逻辑、代码质量、代码性能和代码安全四个方面的详细审查和改进意见:

1. 语法逻辑

  • 版权年份更新:将 SPDX-FileCopyrightText 中的年份从 2023 - 2024 更新为 2023 - 2026。这是合法的语法修改,用于延长版权声明的时间范围。逻辑上没有问题。
  • 移除窗口居中逻辑:移除了 onCurrentSourceChanged 信号处理函数中关于窗口位置重置的代码块:
    if (window.visibility !== Window.FullScreen && window.visibility !== Window.Maximized) {
        setX(IV.FileControl.getPrimaryScreenCenterX(width));
        setY(IV.FileControl.getPrimaryScreenCenterY(height));
    }
    逻辑影响分析:原代码的逻辑是:当当前源(currentSource)发生变化时,如果窗口不是全屏或最大化状态,则将窗口移动到主屏幕的中心。
    移除这段代码后,当用户切换文件(currentSource 改变)时,如果窗口处于普通状态,窗口将不再自动跳回屏幕中心
    • 潜在问题:这可能是为了修复一个 Bug(例如用户拖动窗口后切换文件,窗口突然跳回中心),但也可能引入新的问题(例如,如果窗口位置在之前的操作中变得不可见,用户可能无法找回窗口)。
    • 建议:确认移除此逻辑的意图。如果是为了防止窗口在切换文件时位置重置带来的体验不佳,这是一个好的改动。但需要确保有其他机制(如初始化时)保证窗口首次出现时位置合理。

2. 代码质量

  • 版权维护:版权年份的更新是常规维护,符合开源项目规范。
  • 代码简洁性:移除不必要的逻辑使得 onCurrentSourceChanged 回调函数更加简洁,只专注于更新窗口标题,符合单一职责原则。
  • 可读性:代码变更后的逻辑非常清晰,没有可读性问题。

3. 代码性能

  • 性能提升:移除的代码涉及调用 C++ 后端方法 IV.FileControl.getPrimaryScreenCenterXIV.FileControl.getPrimaryScreenCenterY,以及调用 QML 的 setXsetY。在 currentSource 频繁变化(例如快速切换图片或文件)的场景下,移除这些跨线程/边界的调用和几何属性变更可以减少不必要的计算和 UI 刷新开销,对性能有微小的正面影响。

4. 代码安全

  • 安全性:此 diff 不涉及安全漏洞的引入或修复。
  • 许可证:保留了 SPDX-License-Identifier: GPL-3.0-or-later,符合合规要求。

总结与改进建议

这段改动主要是移除了切换文件时的自动窗口居中行为

改进建议:

  1. 验证窗口初始化逻辑:由于移除了切换文件时的居中逻辑,请务必确保在应用启动或窗口首次创建时,有明确的逻辑将窗口置于屏幕可见区域(通常是中心),防止窗口出现在屏幕外。

    • 例如,检查 Component.onCompleted 或窗口的初始化代码中是否有类似 setX(IV.FileControl.getPrimaryScreenCenterX(width)) 的调用。
  2. 用户体验 (UX) 测试

    • 测试场景:拖动窗口到屏幕边缘 -> 切换文件。
    • 预期结果:窗口应保持在拖动后的位置,不应跳回中心(这是移除代码后的预期行为)。
    • 测试场景:多显示器环境,窗口在副屏 -> 切换文件。
    • 预期结果:窗口应保留在副屏,不应跳回主屏中心。
  3. 代码注释(可选):如果这个改动是为了修复特定的 Issue 或 Ticket,建议在代码提交信息中注明,或者在代码中添加简短注释说明为何不需要居中,方便后续维护者理解。

    • 例如:// 用户切换文件时保持窗口当前位置,避免跳动干扰体验

结论:该改动在语法和逻辑上是正确的,有助于提升用户体验(防止窗口跳动)和微小的性能提升。只要确保窗口初始化位置正确,这是一个合理的优化。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, wyu71

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

@wyu71 wyu71 merged commit e1c1023 into linuxdeepin:master Apr 23, 2026
19 of 21 checks passed
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.

3 participants