Skip to content

fix(focus): update focus policy handling for Wayland and clipboard in…#821

Merged
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
dengzhongyuan365-dev:bug-fix-error
Apr 15, 2026
Merged

fix(focus): update focus policy handling for Wayland and clipboard in…#821
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
dengzhongyuan365-dev:bug-fix-error

Conversation

@dengzhongyuan365-dev
Copy link
Copy Markdown
Contributor

…teractions

  • Improved focus policy logic for fullscreen windows in Wayland and Treeland modes, ensuring proper focus behavior for screenshot and recording functionalities.
  • Enhanced clipboard handling by checking for the presence of the clipboard daemon, allowing for better confirmation of data transfer to the clipboard.
  • Updated comments for clarity regarding focus policy changes and clipboard signal handling.

bug: https://pms.uniontech.com/bug-view-357249.html

…teractions

- Improved focus policy logic for fullscreen windows in Wayland and Treeland modes, ensuring proper focus behavior for screenshot and recording functionalities.
- Enhanced clipboard handling by checking for the presence of the clipboard daemon, allowing for better confirmation of data transfer to the clipboard.
- Updated comments for clarity regarding focus policy changes and clipboard signal handling.

bug: https://pms.uniontech.com/bug-view-357249.html
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengzhongyuan365-dev, lzwind

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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 15, 2026

CLA Assistant Lite bot:

如果你是以企业贡献者的身份进行提交,请联系我们签署企业贡献者许可协议
If you submit as corporate contributor, please contact us to sign our Corporate Contributor License Agreement

感谢您的提交,我们非常感谢。 像许多开源项目一样,在接受您的贡献之前,我们要求您签署我们的个人贡献者许可协议。 您只需发布与以下格式相同的评论即可签署个人贡献者许可协议
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Individual Contributor License Agreement before we can accept your contribution. You can sign the Individual Contributor License Agreement by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA.

You can retrigger this bot by commenting recheck in this Pull Request

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

代码审查报告

总体评价

这段代码主要针对不同系统版本(特别是1070版本和V25社区版)的窗口焦点策略和剪贴板行为进行了适配。代码逻辑基本正确,但存在一些可以改进的地方。

语法逻辑审查

  1. 变量定义位置

    • isNewFocusPolicyhasClipboardDaemon 变量定义在条件判断前,这是良好的做法,提高了代码可读性。
  2. 条件判断逻辑

    • isNewFocusPolicy 的判断逻辑合理,正确处理了1070+版本和社区版的情况。
    • hasClipboardDaemon 的判断逻辑也合理,与窗口焦点策略保持一致。

代码质量建议

  1. 魔法数字

    const int minor = DSysInfo::minorVersion().toInt();
    const bool isNewFocusPolicy = minor >= 1070
        || DSysInfo::uosEditionType() == DSysInfo::UosCommunity;

    建议将1070定义为常量,提高代码可维护性:

    constexpr int NEW_FOCUS_POLICY_VERSION = 1070;
    const int minor = DSysInfo::minorVersion().toInt();
    const bool isNewFocusPolicy = minor >= NEW_FOCUS_POLICY_VERSION
        || DSysInfo::uosEditionType() == DSysInfo::UosCommunity;
  2. 日志级别

    qCWarning(dsrApp) << "Received dataComing signal from clipboard daemon";

    这里使用qCWarning可能不太合适,因为这是一个正常的信号接收,建议改为qCInfoqCDebug

  3. 无限循环

    while (1) {
        // ...
    }

    建议使用更具描述性的条件:

    bool clipboardSaved = false;
    while (!clipboardSaved && time(nullptr) < endTime) {
        // ...
    }

代码性能建议

  1. 重复计算

    const int minor = DSysInfo::minorVersion().toInt();

    在多个地方重复调用DSysInfo::minorVersion().toInt(),建议在函数开始处计算一次并存储。

  2. 等待剪贴板数据

    int waitSeconds = getWaitTimeByImageSize(pix);
    time_t endTime = time(nullptr) + waitSeconds;

    这种基于图片大小的等待时间计算可能不够精确,考虑使用事件循环或QTimer替代忙等待。

代码安全建议

  1. 类型转换

    const int minor = DSysInfo::minorVersion().toInt();

    直接使用toInt()可能存在转换风险,建议添加错误检查:

    bool ok;
    const int minor = DSysInfo::minorVersion().toInt(&ok);
    if (!ok) {
        qCWarning(dsrApp) << "Failed to convert minor version to int";
        // 处理错误情况
    }
  2. 剪贴板数据验证

    qCDebug(dsrApp) << "Whether the data passed to the clipboard is empty? " << t_imageData->imageData().isNull();

    建议添加对剪贴板数据的验证,确保数据有效后再进行后续操作。

  3. 超时处理

    while (1) {
        // ...
    }

    虽然有超时机制,但建议添加明确的超时处理逻辑,确保程序不会无限等待。

其他建议

  1. 代码注释

    • 注释已经有所改进,但可以更详细地解释为什么不同版本需要不同的处理方式。
  2. 函数职责

    • save2Clipboard函数职责较多,考虑将部分逻辑提取为独立函数,提高代码可读性和可维护性。
  3. 信号槽连接

    const QString ClipboardSignal = QStringLiteral("dataComing");

    建议将信号名称定义为常量,避免硬编码。

总结

这段代码在语法逻辑上基本正确,但在代码质量、性能和安全性方面还有改进空间。主要建议包括:使用常量替代魔法数字、改进日志级别、优化等待机制、增强类型转换安全性等。这些改进将使代码更健壮、更易于维护。

@dengzhongyuan365-dev
Copy link
Copy Markdown
Contributor Author

/merge

@dengzhongyuan365-dev
Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot bot commented Apr 15, 2026

This pr cannot be merged! (status: unstable)

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot bot commented Apr 15, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit aa699ce into linuxdeepin:master Apr 15, 2026
7 of 10 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