fix: clipboard transparent issue on startup#264
Conversation
Reviewer's GuideSwitches 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/resizesequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The blur reinitialization logic in
showEventandresizeEventis duplicated and uses function-localstaticflags; consider consolidating this into a single helper with a member state flag so behavior is clearer and not shared across allMainWindowinstances. - The new XDG autostart desktop file is installed to
/etc/xdg/autostartvia 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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 pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff。本次修改主要涉及两个方面:一是将剪贴板应用的自启动方式从 以下是我对语法逻辑、代码质量、代码性能和代码安全方面的详细审查意见及改进建议: 1. 语法与逻辑1.1 重复且分散的 Workaround 逻辑
1.2 XDG Autostart 的
1.3
2. 代码质量2.1 魔法操作
2.2 静态变量控制单次执行的隐患
3. 代码性能3.1
4. 代码安全4.1 硬编码系统路径
4.2
改进后的代码建议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=dtkwidget3. 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();
}
}
// ... 其他代码 ...以上审查意见希望能帮助你提升代码的健壮性和可维护性。如果有任何疑问,欢迎继续交流! |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Log: Fixed clipboard window transparent display on first startup
Influence:
fix: 修复剪切板启动透明问题
Log: 修复剪切板首次启动窗口透明问题
Influence:
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:
Build:
Chores: