Skip to content

fix: clipboard transparent issue on startup#264

Merged
xionglinlin merged 1 commit into
linuxdeepin:masterfrom
xionglinlin:master
May 22, 2026
Merged

fix: clipboard transparent issue on startup#264
xionglinlin merged 1 commit into
linuxdeepin:masterfrom
xionglinlin:master

Conversation

@xionglinlin
Copy link
Copy Markdown
Contributor

@xionglinlin xionglinlin commented May 22, 2026

  1. Replace systemd want symlink with XDG autostart desktop file for more reliable clipboard service startup
  2. Add blur window re-init workaround in showEvent and resizeEvent to fix transparency issue on first display
  3. Remove old conffiles entry for dde-clipboard.desktop as it's now managed by XDG autostart

Log: Fixed clipboard window transparent display on first startup

Influence:

  1. Verify clipboard window appears correctly without transparency on startup
  2. Test clipboard window after resize to ensure no transparency issues
  3. Verify clipboard service starts automatically via XDG autostart
  4. Test clipboard functionality after system restart
  5. Check that clipboard window still works properly after manual launch

fix: 修复剪切板启动透明问题

  1. 将 systemd want 符号链接替换为 XDG autostart 桌面文件,使剪切板服务启 动更可靠
  2. 在 showEvent 和 resizeEvent 中添加模糊窗口重新初始化处理,修复首次显 示时的透明度问题
  3. 移除旧的 conffiles 中 dde-clipboard.desktop 条目,现在由 XDG autostart 管理

Log: 修复剪切板首次启动窗口透明问题

Influence:

  1. 验证剪切板窗口启动时无透明问题
  2. 测试调整窗口大小后无透明度异常
  3. 验证剪切板服务通过 XDG autostart 自动启动
  4. 测试系统重启后的剪切板功能
  5. 检查手动启动剪切板窗口是否能正常工作

PMS: BUG-362049
Change-Id: Ida2a9ef6aa4f301684810067832fd30771a483eb

Summary by Sourcery

Resolve clipboard window transparency on first display and switch clipboard autostart to XDG desktop entry instead of a systemd wants symlink.

Bug Fixes:

  • Ensure the clipboard window initializes its blur effect correctly on first show and after the first resize to avoid transparent display.

Build:

  • Install an XDG autostart desktop file for dde-clipboard and stop creating the systemd wants symlink, keeping the systemd user service only for D-Bus activation.

Chores:

  • Update packaging by removing the old conffiles entry for dde-clipboard.desktop now that it is managed via XDG autostart.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 22, 2026

Reviewer's Guide

Switches clipboard autostart from a systemd wants symlink to an XDG autostart desktop file and adds a blur re-init workaround on first show/resize to prevent the clipboard window from appearing transparent on first startup, while cleaning up obsolete Debian conffiles entries.

Sequence diagram for MainWindow blur re-init on first show/resize

sequenceDiagram
    participant MainWindow
    participant DBlurEffectWidget
    participant WindowHandle

    MainWindow->>DBlurEffectWidget: showEvent(event)
    alt [firstShow]
        MainWindow->>WindowHandle: setEnableBlurWindow(false)
        MainWindow->>WindowHandle: setEnableBlurWindow(true)
    end
    MainWindow->>MainWindow: activateWindow()

    MainWindow->>DBlurEffectWidget: resizeEvent(event)
    alt [firstResize]
        MainWindow->>WindowHandle: setEnableBlurWindow(false)
        MainWindow->>WindowHandle: setEnableBlurWindow(true)
    end
Loading

File-Level Changes

Change Details Files
Add blur effect re‑initialization on first show/resize to work around initial transparent window
  • Extend MainWindow to override resizeEvent and call base DBlurEffectWidget::resizeEvent
  • In showEvent, add a one-time guard and toggle m_windowHandle blur off/on on first show
  • In resizeEvent, add a one-time guard and toggle m_windowHandle blur off/on on first resize to ensure blur is properly applied
dde-clipboard/mainwindow.cpp
dde-clipboard/mainwindow.h
Change clipboard autostart mechanism from systemd wants symlink to XDG autostart desktop entry
  • Comment out install_symlink of dde-clipboard.service into dde-session-initialized.target.wants, keeping the user service only for D-Bus activation
  • Configure misc/dde-clipboard.desktop.in into dde-clipboard.desktop via CMake configure_file
  • Install the generated dde-clipboard.desktop into /etc/xdg/autostart so the clipboard service starts via XDG autostart
CMakeLists.txt
misc/dde-clipboard.desktop.in
Clean up obsolete Debian conffiles entry for the old desktop file path
  • Remove dde-clipboard.desktop entry from debian/dde-clipboard.conffiles since the desktop file is now managed via XDG autostart installation
debian/dde-clipboard.conffiles

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The blur reinitialization logic in showEvent and resizeEvent is duplicated and uses function-local static flags; consider consolidating this into a single helper with a member state flag so behavior is clearer and not shared across all MainWindow instances.
  • The new XDG autostart desktop file is installed to /etc/xdg/autostart via a hardcoded path; consider using a configurable CMake variable or standard XDG/CMake install directory macro to avoid embedding the absolute path.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The blur reinitialization logic in `showEvent` and `resizeEvent` is duplicated and uses function-local `static` flags; consider consolidating this into a single helper with a member state flag so behavior is clearer and not shared across all `MainWindow` instances.
- The new XDG autostart desktop file is installed to `/etc/xdg/autostart` via a hardcoded path; consider using a configurable CMake variable or standard XDG/CMake install directory macro to avoid embedding the absolute path.

## Individual Comments

### Comment 1
<location path="dde-clipboard/mainwindow.cpp" line_range="667" />
<code_context>
     Q_EMIT clipboardVisibleChanged(true);
     DBlurEffectWidget::showEvent(event);
+
+    static bool firstShow = true;
+    if (firstShow) {
+        firstShow = false;
</code_context>
<issue_to_address>
**issue (complexity):** Consider extracting the one-time blur toggle logic into a shared helper that uses member flags instead of per-function static variables to avoid duplication and clarify the workaround’s intent.

You can reduce duplication and make the intent clearer by extracting the workaround into a helper and using member flags instead of two separate `static` locals. This preserves current behavior (runs once on first show and once on first resize) while centralizing the blur toggle.

```cpp
// mainwindow.h
class MainWindow : public DBlurEffectWidget
{
    Q_OBJECT
    // ...
private:
    bool m_blurInitializedOnShow = false;
    bool m_blurInitializedOnResize = false;

    void initBlurWorkaroundOnce(bool &initializedFlag);
};
```

```cpp
// mainwindow.cpp
void MainWindow::initBlurWorkaroundOnce(bool &initializedFlag)
{
    if (initializedFlag)
        return;

    initializedFlag = true;
    m_windowHandle->setEnableBlurWindow(false);
    m_windowHandle->setEnableBlurWindow(true);
}

void MainWindow::showEvent(QShowEvent *event)
{
    Q_EMIT clipboardVisibleChanged(true);
    DBlurEffectWidget::showEvent(event);

    initBlurWorkaroundOnce(m_blurInitializedOnShow);

    activateWindow();
}

void MainWindow::resizeEvent(QResizeEvent *event)
{
    DBlurEffectWidget::resizeEvent(event);

    initBlurWorkaroundOnce(m_blurInitializedOnResize);
}
```

This keeps all current behavior but removes copy‑pasted logic, makes the workaround self‑documenting, and makes it obvious that show/resize each perform their own one-time initialization.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread dde-clipboard/mainwindow.cpp
1. Replace systemd want symlink with XDG autostart desktop file for more
reliable clipboard service startup
2. Add blur window re-init workaround in showEvent and resizeEvent to
fix transparency issue on first display
3. Remove old conffiles entry for dde-clipboard.desktop as it's now
managed by XDG autostart

Log: Fixed clipboard window transparent display on first startup

Influence:
1. Verify clipboard window appears correctly without transparency on
startup
2. Test clipboard window after resize to ensure no transparency issues
3. Verify clipboard service starts automatically via XDG autostart
4. Test clipboard functionality after system restart
5. Check that clipboard window still works properly after manual launch

fix: 修复剪切板启动透明问题

1. 将 systemd want 符号链接替换为 XDG autostart 桌面文件,使剪切板服务启
动更可靠
2. 在 showEvent 和 resizeEvent 中添加模糊窗口重新初始化处理,修复首次显
示时的透明度问题
3. 移除旧的 conffiles 中 dde-clipboard.desktop 条目,现在由 XDG
autostart 管理

Log: 修复剪切板首次启动窗口透明问题

Influence:
1. 验证剪切板窗口启动时无透明问题
2. 测试调整窗口大小后无透明度异常
3. 验证剪切板服务通过 XDG autostart 自动启动
4. 测试系统重启后的剪切板功能
5. 检查手动启动剪切板窗口是否能正常工作

PMS: BUG-362049
Change-Id: Ida2a9ef6aa4f301684810067832fd30771a483eb
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff。本次修改主要涉及两个方面:一是将剪贴板应用的自启动方式从 systemd symlink 切换为 XDG autostart;二是为了解决窗口模糊特效问题,引入了在首次显示和首次调整大小时重置模糊状态的Workaround(变通方案)。

以下是我对语法逻辑、代码质量、代码性能和代码安全方面的详细审查意见及改进建议:

1. 语法与逻辑

1.1 重复且分散的 Workaround 逻辑

  • 问题:在 showEventresizeEvent 中,使用了完全相同的静态变量和重置逻辑来触发模糊窗口的刷新。这种重复代码不仅违反了 DRY(Don't Repeat Yourself)原则,而且逻辑分散,未来如果DTK修复了该Bug,需要多处修改。
  • 改进:建议将重置模糊状态的逻辑提取为一个独立的私有方法,例如 ensureBlurEffect()

1.2 XDG Autostart 的 Hidden 逻辑冲突

  • 问题:在 debian/dde-clipboard.conffiles 中移除了 remove-on-upgrade /etc/xdg/autostart/dde-clipboard.desktop,这意味着该文件将重新由包管理器管理。但是,如果用户在系统设置中手动禁用了该自启动项,XDG规范会在 ~/.config/autostart/ 下生成一个同名文件,并添加 Hidden=true。由于你在此处使用了 configure_file 硬编码安装到 /etc/xdg/autostart/,且没有在 .desktop.in 中显式声明 Hidden=false,在某些边缘场景下可能会与用户的自定义配置产生逻辑冲突。
  • 改进:虽然对于 DDE 内部组件影响不大,但建议在 misc/dde-clipboard.desktop.in 中显式加上 Hidden=false 以明确意图。

1.3 X-Deepin-TurboType 的值

  • 问题X-Deepin-TurboType=dtkwidget 是一个Deepin特有的加速启动配置。请确认该值是否正确,通常如果是QT程序可能会写 qt,或者是具体的模块名。如果这是你们项目组约定的值则无妨,否则请确认 DDE 的 TurboType 支持的具体枚举。

2. 代码质量

2.1 魔法操作

  • 问题setEnableBlurWindow(false); setEnableBlurWindow(true); 这种强行通过开关来刷新状态的方式属于典型的 Workaround。代码中没有注释说明为什么要这么做,未来维护者(或者你自己)很可能会误以为这是无用代码而将其删除。
  • 改进:必须添加详细的注释,说明这是为了绕过 DTK 或 WM 的哪个 Bug(例如:首次显示时模糊特效失效的Bug),并附上相关的 Bug Tracker 链接(如果有的话)。

2.2 静态变量控制单次执行的隐患

  • 问题:使用 static bool firstShow = true; 只能在程序生命周期内执行一次。如果模糊特效在窗口隐藏后再次显示时(例如从最小化恢复,或者跨越不同虚拟桌面)依然存在渲染Bug,这个逻辑将无法修复后续的Bug。
  • 改进:如果仅是首次启动问题,静态变量可以接受;但如果是为了解决每次显隐时的渲染Bug,应考虑去掉 static 控制或在特定的显隐逻辑中触发。

3. 代码性能

3.1 resizeEvent 中的高频触发风险

  • 问题resizeEvent 在窗口拖拽调整大小时会以极高的频率触发。虽然目前有 static bool firstResize 保护,仅执行一次,但这种将逻辑挂在 resizeEvent 内部的做法容易引发性能隐患。如果未来有人在 if 块外部添加了其他逻辑,极易导致性能骤降。
  • 改进:如果这个模糊刷新必须在 resize 时触发,建议使用定时器防抖,或者只在首次 resize 结束后触发。但鉴于当前有 firstResize 保护,性能损耗仅限于一次布尔判断,目前可以接受,但需注意后续维护。

4. 代码安全

4.1 硬编码系统路径

  • 问题install(FILES ... DESTINATION /etc/xdg/autostart) 硬编码了绝对路径。在交叉编译或某些特殊发行版中,/etc 可能不在预期位置,或者用户使用了 DESTDIR 进行沙盒安装时,该路径可能会直接写入宿主机系统,存在破坏宿主机环境的隐患。
  • 改进:CMake 提供了 CMAKE_INSTALL_SYSCONFDIR 变量来表示 /etc。应使用该变量代替硬编码,以确保 DESTDIR 和前缀生效。

4.2 .desktop 文件执行权限与路径安全

  • 问题Exec=@CMAKE_INSTALL_FULL_BINDIR@/dde-clipboard 使用了绝对路径,这是安全的做法,避免了 PATH 劫持。但请确保 dde-clipboard 二进制文件在安装时没有被赋予不必要的高权限(如 SUID 等)。

改进后的代码建议

1. CMakeLists.txt (修改安装路径,避免硬编码)

# XDG autostart 替代 systemd wants 自动启动,保留 systemd service 作为 D-Bus 激活
# install_symlink(dde-clipboard.service dde-session-initialized.target.wants)

configure_file(
    misc/dde-clipboard.desktop.in
    dde-clipboard.desktop
    @ONLY
)

# 安全改进:使用 CMAKE_INSTALL_SYSCONFDIR 替代硬编码的 /etc
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dde-clipboard.desktop DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/xdg/autostart)

2. misc/dde-clipboard.desktop.in (增加 Hidden=false 明确意图)

[Desktop Entry]
Name=Deepin Clipboard
Comment=Deepin Clipboard
Exec=@CMAKE_INSTALL_FULL_BINDIR@/dde-clipboard
NoDisplay=true
OnlyShowIn=DDE
Type=Application
Hidden=false
X-Deepin-Vendor=user-custom
X-Deepin-TurboType=dtkwidget

3. dde-clipboard/mainwindow.h (提取公共方法)

// ... 在 private 区域添加:
private:
    void ensureBlurEffect();

4. dde-clipboard/mainwindow.cpp (重构逻辑,增加详细注释)

// ... 其他代码 ...

void MainWindow::ensureBlurEffect()
{
    // WORKAROUND: 解决窗口首次显示/调整大小时,模糊特效未正确渲染的问题。
    // 相关Bug追踪: [请在此处填入DTK或Window Manager的Bug链接,若无则简要描述现象]
    // 通过强制关闭再开启模糊状态,触发底层重绘。
    m_windowHandle->setEnableBlurWindow(false);
    m_windowHandle->setEnableBlurWindow(true);
}

void MainWindow::showEvent(QShowEvent *event)
{
    Q_EMIT clipboardVisibleChanged(true);
    DBlurEffectWidget::showEvent(event);

    static bool firstShow = true;
    if (firstShow) {
        firstShow = false;
        ensureBlurEffect();
    }

    activateWindow();
}

void MainWindow::resizeEvent(QResizeEvent *event)
{
    DBlurEffectWidget::resizeEvent(event);

    static bool firstResize = true;
    if (firstResize) {
        firstResize = false;
        ensureBlurEffect();
    }
}

// ... 其他代码 ...

以上审查意见希望能帮助你提升代码的健壮性和可维护性。如果有任何疑问,欢迎继续交流!

Comment thread CMakeLists.txt
Comment thread CMakeLists.txt
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: xionglinlin, 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

@xionglinlin xionglinlin merged commit 1613e28 into linuxdeepin:master May 22, 2026
16 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