Skip to content

fix(shortcut): support brightness keys on Wayland#104

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix/wayland-brightness-shortcuts
Jul 16, 2026
Merged

fix(shortcut): support brightness keys on Wayland#104
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix/wayland-brightness-shortcuts

Conversation

@yixinshark

Copy link
Copy Markdown
Contributor

Summary

  • Adjust output brightness through the Treeland output-manager protocol on Wayland.
  • Serialize repeated shortcut processes to avoid lost read-modify-write updates.
  • Wait for compositor results before showing the OSD and preserve auto-brightness when adjustment fails.

Test plan

  • Build dde-shortcut-tool.
  • Verify brightness up/down keys change brightness repeatedly under Treeland.
  • Verify failed Wayland adjustments do not disable ambient auto-brightness.
  • Verify the X11 Display1 brightness path remains functional.

@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/wayland-brightness-shortcuts branch 2 times, most recently from 0b28a74 to 50651d7 Compare July 15, 2026 06:55
Use the Treeland output-manager protocol to read and adjust output brightness when Display1 is unavailable on Wayland. Serialize cross-process read-modify-write operations with a runtime lock so repeated shortcut processes do not lose updates, wait for compositor commit results before showing the OSD, and keep ambient auto-brightness enabled when an adjustment fails. Preserve the existing Display1 path on X11.

在 Wayland 下 Display1 不可用时,通过 Treeland output-manager 协议读取并调整输出亮度。使用运行时进程锁串行化跨进程的读取、修改和写入操作,避免快捷键重复触发时丢失亮度更新;等待合成器提交结果后再显示 OSD,并在调节失败时保持环境光自动亮度设置不变。X11 下继续使用原有 Display1 路径。

Log: support brightness keys on Wayland
Change-Id: Ib70f62de7fbcb7f93f23bf3c550fbacf7eb2e4ea
@yixinshark
yixinshark force-pushed the fix/wayland-brightness-shortcuts branch from 50651d7 to edd656f Compare July 16, 2026 07:16
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码实现了Wayland环境下的屏幕亮度控制,逻辑严谨且资源管理规范
逻辑正确且引入了跨进程锁与超时机制,因部分异步处理细节可优化扣5分

■ 【详细分析】

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

DisplayController::changeBrightness 中将 Wayland 分支委托给 TreelandBrightnessController,条件判断修改正确,避免了在 Wayland 下访问无效的 m_displayInterfaceWaylandBrightnessSession::changeBrightness 中的异步事件循环和结果统计逻辑完整,正确处理了多输出设备的亮度调节请求。
潜在问题:在 DisplayController::changeBrightness 中,环境光自动调节的禁用逻辑从“调节前禁用”改为了“调节成功后禁用”,这可能导致在自动调节开启时,手动调节的瞬间亮度被自动调节逻辑覆盖。
建议:考虑在调用亮度调节接口前禁用环境光自动调节,或者在调节成功后重置自动调节状态以避免冲突。

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

代码结构清晰,TreelandBrightnessPrivate 命名空间封装了实现细节。Wayland 资源的生命周期管理规范,WaylandBrightnessSession 析构函数正确释放了 wl_outputwl_registry 及相关控制对象。使用 std::unique_ptr 管理 TreelandColorControlTreelandOutputManager 避免了内存泄漏。
潜在问题:WaylandBrightnessSession::handleGlobalRemove 中在遍历查找并 erase 元素时,如果在事件处理过程中有其他逻辑持有该 output 的引用,可能存在悬挂引用风险,但当前代码中未发现此类使用。
建议:保持当前实现,注意后续扩展时不要在事件回调期间缓存 output 迭代器。

  • 3.代码性能(良好)✓

使用了 QEventLoop 配合 QTimer 处理异步 Wayland 事件,设置了 1000ms 的超时时间,避免了无限期阻塞。两次 wl_display_roundtrip 确保了协议对象的初始化和当前亮度值的获取,设计合理。
潜在问题:无
建议:无

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码使用了 QStandardPaths::RuntimeLocation 获取运行时目录,并通过 QLockFile 进行跨进程同步,未发现命令注入、路径遍历或内存破坏等安全风险。对 Wayland 协议返回的指针进行了空指针检查。

  • 建议:无

■ 【改进建议代码示例】

// displaycontroller.cpp
bool DisplayController::changeBrightness(bool raised)
{
    if (!m_isWayland && (!m_displayInterface || !m_displayInterface->isValid())) {
        qWarning() << "Display interface not available";
        return false;
    }

    auto *powerConfig = DConfig::create("org.deepin.dde.daemon", "org.deepin.dde.daemon.power", "", this);
    if (!powerConfig->isValid()) {
        qWarning() << "daemon power config is not valid";
        powerConfig->deleteLater();
        return false;
    }

    const bool autoAdjustEnabled =
            powerConfig->value("ambientLightAdjustBrightness").toBool();

    // 在调节亮度前禁用环境光自动调节,避免调节被覆盖
    if (autoAdjustEnabled) {
        powerConfig->setValue("ambientLightAdjustBrightness", false);
        qDebug() << "Disabled ambient light auto brightness adjustment";
    }

    bool success = false;
    if (m_isWayland) {
        TreelandBrightnessController controller;
        success = controller.changeBrightness(raised);
    } else {
        QDBusReply<void> reply = m_displayInterface->call("ChangeBrightness", raised);
        if (!reply.isValid()) {
            qWarning() << "Failed to change brightness:" << reply.error().message();
        } else {
            success = true;
        }
    }

    if (!success) {
        // 如果失败,恢复之前的自动调节状态
        if (autoAdjustEnabled) {
            powerConfig->setValue("ambientLightAdjustBrightness", true);
        }
        powerConfig->deleteLater();
        return false;
    }

    powerConfig->deleteLater();

    qDebug() << "Changed brightness:" << (raised ? "up" : "down");
    showOSD(raised ? "BrightnessUp" : "BrightnessDown");
    return true;
}

@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

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit b39428c into linuxdeepin:master Jul 16, 2026
9 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