Skip to content

fix: cache appearance opacity in the shell#1665

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix/cache-appearance-opacity
Jul 15, 2026
Merged

fix: cache appearance opacity in the shell#1665
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix/cache-appearance-opacity

Conversation

@yixinshark

Copy link
Copy Markdown
Contributor

Cache the Appearance1 opacity after proxy initialization and update it from OpacityChanged instead of issuing a D-Bus property request for every QML read. Only access the cached property when the task manager uses the X11 window monitor, avoiding unnecessary work on Wayland.

在代理初始化后缓存 Appearance1 透明度,并通过 OpacityChanged 更新,避免每次 QML 读取都发起 D-Bus 属性请求。任务管理器仅在使用 X11 窗口监视器时访问该缓存属性,避免 Wayland 下的无效操作。

Log: cache appearance opacity in the shell

@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

@yixinshark yixinshark force-pushed the fix/cache-appearance-opacity branch from 26c9c26 to e3b4c9a Compare July 15, 2026 03:32
18202781743
18202781743 previously approved these changes Jul 15, 2026
Cache the Appearance1 opacity after proxy initialization and update it from OpacityChanged instead of issuing a D-Bus property request for every QML read. Only access the cached property when the task manager uses the X11 window monitor, avoiding unnecessary work on Wayland.

在代理初始化后缓存 Appearance1 透明度,并通过 OpacityChanged 更新,避免每次 QML 读取都发起 D-Bus 属性请求。任务管理器仅在使用 X11 窗口监视器时访问该缓存属性,避免 Wayland 下的无效操作。

Log: cache appearance opacity in the shell
@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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码通过引入缓存机制重构了透明度管理逻辑,消除了对DBus接口的运行时依赖并优化了属性访问时机
逻辑正确,性能大幅提升,无安全漏洞,代码质量优秀

■ 【详细分析】

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

AppearanceApplet::opacity()改为返回缓存值m_opacityinitDBusProxy()中正确处理了接口无效和有效时的初始化逻辑,updateOpacity方法集中管理了透明度约束和去重逻辑。TaskManager::modifyOpacityChanged()将属性读取移入条件块内,逻辑严谨。
潜在问题:无
建议:无

  • 2.代码质量优秀✓

引入m_opacity成员变量作为本地缓存,新增updateOpacity方法集中管理状态变更,符合单一职责原则。注释清晰,命名规范,消除了重复的信号发射逻辑。
潜在问题:无
建议:无

  • 3.代码性能高效✓

修复前每次调用opacity()都会触发DBus调用,修复后仅返回本地缓存值,大幅降低了进程间通信开销。TaskManager中避免了非X11环境下的无效属性访问,减少了不必要的开销。
潜在问题:无
建议:无

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码未引入外部输入处理,不存在命令注入、缓冲区溢出等风险,空指针访问已通过逻辑分支避免。

  • 建议:无

■ 【改进建议代码示例】

// 当前修复代码已非常完善,以下为修复后的完整关键函数实现,供参考编译
qreal AppearanceApplet::opacity() const
{
    return m_opacity;
}

void AppearanceApplet::initDBusProxy()
{
    // ... 前置初始化代码 ...
    if (!m_interface->isValid()) {
        qWarning() << "Failed to proxy Appearance, error:" << m_interface->lastError();
        m_interface.reset();
        updateOpacity(-1);
        return;
    }

    QObject::connect(m_interface.data(), &org::deepin::dde::Appearance1::OpacityChanged,
                     this, &AppearanceApplet::updateOpacity);
    updateOpacity(m_interface->opacity());
}

void AppearanceApplet::updateOpacity(qreal opacity)
{
    if (opacity >= 0) {
        // The minimum opacity is 0.2
        opacity = std::max(0.2, opacity);
    }
    if (qFuzzyCompare(m_opacity, opacity))
        return;

    m_opacity = opacity;
    Q_EMIT opacityChanged();
}

// taskmanager.cpp
void TaskManager::modifyOpacityChanged()
{
    DS_NAMESPACE::DAppletBridge appearanceBridge("org.deepin.ds.dde-appearance");
    auto appearanceApplet = appearanceBridge.applet();
    if (appearanceApplet) {
        if (auto x11Monitor = qobject_cast<X11WindowMonitor*>(m_windowMonitor.data())) {
            double opacity = appearanceApplet->property("opacity").toReal();
            x11Monitor->setPreviewOpacity(opacity);
        }
    } else {
        // ... 其他逻辑 ...
    }
}

@yixinshark

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 20dd915 into linuxdeepin:master Jul 15, 2026
10 of 13 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