Skip to content

fix: restore Wayland clipboard image replay#272

Merged
yixinshark merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix-wayland-clipboard-image-paste
Jul 6, 2026
Merged

fix: restore Wayland clipboard image replay#272
yixinshark merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix-wayland-clipboard-image-paste

Conversation

@yixinshark

Copy link
Copy Markdown
Contributor

Summary

  • Move Wayland clipboard MIME reads to bounded async pipe reads with stale-result cancellation.
  • Restore historical image replay by re-offering supported image MIME types and notifying local Wayland replay changes.
  • Add diagnostics for Wayland offer/read/takeover/send flow and ignore daemon-owned private MIME data.

Test plan

  • cmake --build build --target dde-clipboard dde-clipboard-daemon
  • Manually tested Wayland screenshot copy logs and daemon self-offer filtering.

Fix Wayland clipboard image replay and ownership handling.
- Move Wayland MIME pipe reads off the event path and read them with a bounded poll loop.
- Track active read task ids so stale async read results cannot overwrite newer clipboard data.
- Re-publish saved clipboard data with supported image offers and ignore self-produced Wayland offers.
- Emit clipboard change notifications for local Wayland replay so history items are reinserted at the top.
- Add diagnostic logs for Wayland offer, read, takeover, and send-request flow.

修复 Wayland 剪贴板图片历史回放和 owner 接管处理。
- 将 Wayland MIME pipe 读取移出事件路径,使用带超时和大小限制的 poll 循环读取。
- 通过当前读任务 ID 丢弃过期异步读取结果,避免旧数据覆盖新的剪贴板内容。
- 使用支持的图片格式重新发布历史剪贴板数据,并忽略 daemon 自己发布的 Wayland offer。
- 本地 Wayland 历史回放后发出剪贴板变更通知,使历史项可以重新插入列表顶部。
- 增加 Wayland offer、读取、接管和数据请求流程的诊断日志。

Log: restore Wayland clipboard image replay
Change-Id: Ia7f1058c20d640a9503aee02f2f7a3d523aa21e8

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

Sorry @yixinshark, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码彻底重构了Wayland剪贴板读取流程,完美解决了死锁与递归问题
逻辑严密、性能优异且无安全漏洞,属于高质量的重构代码

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

重构后的异步poll多路复用逻辑严谨,超时、取消、错误处理完备。getByteArray函数修复了图片格式大小写不匹配的bug,reborn函数修复了首项数据无法恢复的逻辑遗漏。FdGuard增加了fd有效性检查,onNewSelection提前声明offerGuard防止了提前返回时的内存泄漏。
潜在问题:FdGuard类未禁用拷贝构造函数,存在被意外拷贝导致double-free的隐患;m_activeReadTaskId在多线程环境下理论上存在数据竞争。
建议:为FdGuard删除拷贝构造并实现移动语义;将m_activeReadTaskId类型改为std::atomic以增强线程安全性。

  • 2.代码质量(优秀)✓

代码结构清晰,引入了PipeReadRequest、PipeReadState等结构体使状态管理更加明确。日志输出详尽且分级合理,常量定义规范。optimizedReadMimeTypes函数有效减少了冗余的图片格式读取,canStorePayload对图片数据进行了有效性校验,体现了良好的防御性编程思想。
潜在问题:无
建议:无

  • 3.代码性能(高效)✓

使用poll替代原先的forceRoundTrip和同步阻塞read,彻底消除了主线程死锁风险。通过独立读写线程池避免了占用Qt全局线程池。限制单次仅读取优先级最高的一种图片格式,大幅降低了剪贴板数据传输时的I/O开销和内存占用。
潜在问题:无
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码引入了64MB的MaxMimePayloadSize限制防止OOM攻击,所有管道文件描述符均通过RAII机制或显式调用确保关闭,并正确设置了FD_CLOEXEC防止子进程继承泄露,未发现安全漏洞。

  • 建议:保持当前的安全编码标准。

■ 【改进建议代码示例】

class FdGuard {
public:
    explicit FdGuard(int fd) : m_fd(fd) {}
    ~FdGuard()
    {
        if (m_fd >= 0)
            close(m_fd);
    }
    
    // 禁用拷贝构造和拷贝赋值,防止双重释放
    FdGuard(const FdGuard&) = delete;
    FdGuard& operator=(const FdGuard&) = delete;
    
    // 支持移动语义,允许资源所有权转移
    FdGuard(FdGuard&& other) noexcept : m_fd(other.m_fd) {
        other.m_fd = -1;
    }
    
    FdGuard& operator=(FdGuard&& other) noexcept {
        if (this != &other) {
            if (m_fd >= 0) {
                close(m_fd);
            }
            m_fd = other.m_fd;
            other.m_fd = -1;
        }
        return *this;
    }
private:
    int m_fd;
};

@deepin-bot

deepin-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.1.31
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #273

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, yixinshark

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

@yixinshark
yixinshark merged commit 218ecfb into linuxdeepin:master Jul 6, 2026
19 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