Skip to content

fix: clamp Treeland brightness at 10 percent - #115

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
robertkill:fix-371285-brightness-lower-bound
Jul 28, 2026
Merged

fix: clamp Treeland brightness at 10 percent#115
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
robertkill:fix-371285-brightness-lower-bound

Conversation

@robertkill

@robertkill robertkill commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

fix: clamp Treeland brightness at 10 percent

  1. Centralize the brightness step and [10, 100] bounds
  2. Apply the shared policy to Treeland brightness changes
  3. Add QtTest coverage for lower and upper boundaries

Influence:

  1. Prevent brightness-down from producing values below Treeland's supported minimum
  2. Preserve 5-point increments and the 100 percent upper bound
  3. Verify the policy with unit tests and debug-machine runtime validation

fix: 将 Treeland 亮度下限限制为 10%

  1. 统一亮度步长及 [10, 100] 边界
  2. 在 Treeland 亮度调整中使用统一策略
  3. 增加亮度上下限 QtTest 覆盖

Influence:

  1. 防止亮度降低快捷键产生低于 Treeland 支持下限的值
  2. 保持 5% 步进和 100% 上限
  3. 已通过单测及调试机运行时验证

PMS: BUG-371285

Summary by Sourcery

Enforce a shared brightness policy with clamped bounds and apply it to Treeland brightness control.

Bug Fixes:

  • Prevent Treeland brightness from being reduced below its supported 10% minimum via keyboard shortcuts.

Enhancements:

  • Introduce a centralized brightness policy with fixed 5% steps and [10%, 100%] bounds for reuse across shortcut tooling.

Tests:

  • Add QtTest-based unit tests to verify brightness clamping at lower and upper bounds and correct stepping within the valid range.

1. Centralize the brightness step and [10, 100] bounds
2. Apply the shared policy to Treeland brightness changes
3. Add QtTest coverage for lower and upper boundaries

Influence:
1. Prevent brightness-down from producing values below Treeland's supported minimum
2. Preserve 5-point increments and the 100 percent upper bound
3. Verify the policy with unit tests and debug-machine runtime validation

fix: 将 Treeland 亮度下限限制为 10%

1. 统一亮度步长及 [10, 100] 边界
2. 在 Treeland 亮度调整中使用统一策略
3. 增加亮度上下限 QtTest 覆盖

Influence:
1. 防止亮度降低快捷键产生低于 Treeland 支持下限的值
2. 保持 5% 步进和 100% 上限
3. 已通过单测及调试机运行时验证

PMS: BUG-371285
@sourcery-ai

sourcery-ai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Reviewer's Guide

Centralizes brightness step and [10, 100] bounds into a shared Brightness policy utility, updates the Treeland brightness controller to use it, and adds QtTest coverage plus CMake wiring for the new brightness policy tests.

File-Level Changes

Change Details Files
Introduce a centralized Brightness policy with shared step and clamped range logic.
  • Add Brightness namespace constants for step, minimum, and maximum brightness
  • Implement adjustedValue helper that applies the step up/down and clamps to [10, 100]
  • Expose the shared policy via constant.h for reuse by controllers and tests
src/plugin-qt/shortcut/tools/dde-shortcut-tool/constant.h
Apply the shared Brightness policy to Treeland brightness control behavior.
  • Include the shared constants header in the Treeland brightness controller implementation
  • Remove the local BrightnessStep constant and manual std::clamp usage
  • Use Brightness::adjustedValue to compute the target brightness before committing
src/plugin-qt/shortcut/tools/dde-shortcut-tool/treelandbrightnesscontroller.cpp
Add unit tests and CMake wiring to validate the brightness policy boundaries.
  • Register a new tst-brightnesspolicy QtTest target in CMake and hook it into ctest
  • Add BrightnessPolicyTest that verifies clamping at the 10% lower bound and 100% upper bound
  • Test that in-range brightness changes respect the 5% step without unnecessary clamping
src/plugin-qt/shortcut/tests/CMakeLists.txt
src/plugin-qt/shortcut/tests/tst_brightnesspolicy.cpp

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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码重构提取了亮度调节逻辑并增加了单元测试,结构清晰且逻辑正确
逻辑正确且无安全漏洞,代码质量与性能均表现优秀

■ 【详细分析】

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

constant.h 中新增的 Brightness::adjustedValue 函数逻辑严密,能正确处理增减步进及边界钳制(10.0至100.0)。treelandbrightnesscontroller.cpp 中的 changeBrightness 函数正确调用了新逻辑,替换了原有的硬编码计算,保持了原有功能的一致性。单元测试覆盖了下限、上限及正常范围内的各种情况。
潜在问题:无
建议:无

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

将魔法数字和重复逻辑提取到 Brightness 命名空间中,提高了代码的可读性和可维护性。使用 constexpr 定义常量,并在头文件中使用 inline 函数,避免了多重定义问题。新增的单元测试结构规范,遵循了 Qt 测试框架的最佳实践。
潜在问题:无
建议:无

  • 3.代码性能(无性能问题)✓

adjustedValue 作为 inline 函数定义在头文件中,编译器可进行内联优化,消除了函数调用开销。计算逻辑仅包含简单的加减法和比较,时间复杂度为 O(1)。
潜在问题:无
建议:无

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改仅涉及内部数值计算和边界限制,不涉及外部输入解析、文件操作或网络通信,不存在可利用的安全风险。输入参数类型安全(doublebool),且输出被严格限制在安全范围内。

  • 建议:无需额外安全修复

■ 【改进建议代码示例】

// 当前代码已足够优秀,无需进一步修改。
// 若未来需要支持动态步长或边界,可考虑扩展 adjustedValue 的参数,例如:
/*
namespace Brightness {

constexpr double Step = 5.0;
constexpr double Minimum = 10.0;
constexpr double Maximum = 100.0;

inline double adjustedValue(double current, bool raised, double step = Step, double min = Minimum, double max = Maximum)
{
    const double value = current + (raised ? step : -step);
    if (value < min) {
        return min;
    }
    if (value > max) {
        return max;
    }
    return value;
}

} // namespace Brightness
*/

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

Hey - I've left some high level feedback:

  • Consider marking Brightness::adjustedValue as constexpr since it only performs arithmetic and comparisons, which would better express its pure, compile-time-friendly nature and keep it consistent with the other Brightness constants.
  • In tst_brightnesspolicy.cpp, using Brightness::Minimum and Brightness::Maximum instead of hardcoded 10.0 and 100.0 would avoid magic numbers and keep the tests aligned with future changes to the brightness policy.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider marking `Brightness::adjustedValue` as `constexpr` since it only performs arithmetic and comparisons, which would better express its pure, compile-time-friendly nature and keep it consistent with the other `Brightness` constants.
- In `tst_brightnesspolicy.cpp`, using `Brightness::Minimum` and `Brightness::Maximum` instead of hardcoded `10.0` and `100.0` would avoid magic numbers and keep the tests aligned with future changes to the brightness policy.

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.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@robertkill

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

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