Skip to content

sync: from linuxdeepin/dde-session-shell#505

Merged
yixinshark merged 1 commit into
masterfrom
sync-pr-67-nosync
May 14, 2026
Merged

sync: from linuxdeepin/dde-session-shell#505
yixinshark merged 1 commit into
masterfrom
sync-pr-67-nosync

Conversation

@deepin-ci-robot
Copy link
Copy Markdown
Contributor

@deepin-ci-robot deepin-ci-robot commented May 13, 2026

Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#67

Summary by Sourcery

Update greeter-display-setting build and scaling behavior and unify greeter installation targets.

Enhancements:

  • Always build and install greeter-display-setting alongside greeter binaries, regardless of DISABLE_DSS_SNIPE configuration.
  • Modernize greeter-display-setting CMake linkage by switching to the Dtk Core target and centralizing binary installation rules.
  • Adjust greeter-display-setting scaling logic to use different QT_SCALE_FACTOR behavior when ENABLE_DSS_SNIPE is defined.

Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#67
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 13, 2026

Reviewer's Guide

Synchronizes the greeter-display-setting utility and related build/install logic with upstream, adjusting how it is built, linked, installed, and how it computes Qt scale factors depending on whether the DSS SNIPE variant is enabled.

Flow diagram for Qt scale factor selection in greeter-display-setting

flowchart TD
    main[main] --> cond_env{ENABLE_DSS_SNIPE}

    cond_env -->|true and !IsWayland| call_set1[setQtScaleFactorEnv]
    cond_env -->|true and IsWayland| end_main1[exit]

    cond_env -->|false and IsWayland| call_set2[setQtScaleFactorEnv]
    cond_env -->|false and !IsWayland| end_main2[exit]

    subgraph setQtScaleFactorEnv
        setQtScaleFactorEnv --> cond_scale{ENABLE_DSS_SNIPE}
        cond_scale -->|true| sf1[getScaleFactor]
        cond_scale -->|false and IsWayland| sf2[getScaleFormConfig]
        cond_scale -->|false and !IsWayland| sf3[getScaleFactor]
        sf1 --> log[print QT_SCALE_FACTOR if > 0]
        sf2 --> log
        sf3 --> log
    end
Loading

File-Level Changes

Change Details Files
Always build and install greeter-display-setting and update its link dependencies to modern Dtk targets.
  • Remove DISABLE_DSS_SNIPE guard from the greeter-display-setting executable so it is built unconditionally.
  • Change greeter-display-setting target_link_libraries to use Dtk${DTK_VERSION_MAJOR}::Core instead of legacy DtkCore/Qt5-specific variables.
  • Unify installation so dde-lock, lightdm-deepin-greeter, and greeter-display-setting are always installed together via a single install(TARGETS ...) call, instead of being conditional on DISABLE_DSS_SNIPE.
CMakeLists.txt
Adjust greeter-display-setting scaling behavior based on ENABLE_DSS_SNIPE and update copyright years.
  • Extend SPDX-FileCopyrightText year range to 2015–2026.
  • In setQtScaleFactorEnv, choose scaleFactor using getScaleFactor() unconditionally when ENABLE_DSS_SNIPE is defined, otherwise keep the Wayland vs X11 conditional logic.
  • In main, when ENABLE_DSS_SNIPE is defined, call setQtScaleFactorEnv only on non-Wayland (X11) to avoid double scaling; when not defined, retain the behavior of only calling it on Wayland.
src/app/greeter-display-setting.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
Contributor Author

deepin pr auto review

你好!我是CodeGeeX,你的智能编程助手。我已仔细审查了你提供的 Git Diff 输入。本次修改主要涉及 CMake 构建逻辑调整、Shell 脚本调用变更以及 C++ 代码的条件编译逻辑修改。

以下是我从语法逻辑、代码质量、代码性能和代码安全四个维度提出的审查意见和改进建议:

1. 语法与逻辑

  • C++ 条件编译逻辑反转疑似错误
    src/app/greeter-display-setting.cppmain 函数中,你通过宏 ENABLE_DSS_SNIPE 对执行逻辑进行了反转。

    • 非 Snipe 模式:if (IsWayland) 才设置环境变量(符合注释:Wayland 下需要手动设置)。
    • Snipe 模式:if (!IsWayland) 才设置环境变量(与注释完全矛盾:X11 下平台插件会处理缩放,主动设置会导致缩放相乘错误)。
      建议:请确认 Snipe 模式下的逻辑是否真的需要反转。如果 Snipe 模式同样遵循“Wayland 需手动设置,X11 不需要”的原则,那么这里的 !IsWayland 是一个严重的逻辑 Bug,应改为 if (IsWayland)。如果确实需要反转,请更新注释以免误导后续维护者。
  • CMake 中 greeter-display-setting 的构建脱离条件控制
    CMakeLists.txt 中,add_executable(greeter-display-setting ...)target_link_libraries(...) 被移出了 if (DISABLE_DSS_SNIPE) 块,这意味着无论何种模式都会编译该目标。但在 Shell 脚本中,调用该程序的逻辑仅存在于 files/snipe/scripts/lightdm-deepin-greeter(属于 Snipe 分支)。如果非 Snipe 模式不需要此可执行文件,将其移出条件编译会导致不必要的编译开销。
    建议:如果该程序在两种模式下都需要,则当前修改合理;如果仅 Snipe 模式需要,建议将其放回条件编译块内,或使用 ENABLE_DSS_SNIPE 宏进行控制。

  • CMake 安装目标的潜在逻辑冲突
    install(TARGETS dde-lock lightdm-deepin-greeter greeter-display-setting ...) 被移到了最外层。这意味着 greeter-display-setting 会在所有模式下都被安装。需确认在非 Snipe 模式下安装此文件是否会引起包冲突或功能异常。

2. 代码质量

  • Shell 脚本中未加引号的变量
    files/snipe/scripts/lightdm-deepin-greeter 中,export $scale_env 存在词法分割和通配符扩展的风险。如果 greeter-display-setting 的输出包含空格或特殊字符,export 会将其拆分为多个参数,导致执行错误甚至崩溃。
    建议:应使用 export "$scale_env",确保其作为单个字符串被 export。
    修改前export $scale_env
    修改后export "$scale_env"

  • C++ 代码中的硬编码字符串与冗余转换
    setQtScaleFactorEnv() 中:

    std::cout << QString("QT_SCALE_FACTOR="+QByteArray::number(scaleFactor)).toStdString().c_str() << std::endl;

    这行代码存在多个质量问题:

    1. + 拼接字符串时,左侧是 QString,右侧是 QByteArray,隐式转换路径不清晰。
    2. QString::number()QByteArray::number() 更适合与 QString 拼接。
    3. 为了输出到 std::cout,经历了 QString -> std::string -> const char* 的冗余转换。
      建议:直接使用 QString 拼接,并使用更简洁的输出方式:
    std::cout << QString("QT_SCALE_FACTOR=%1").arg(scaleFactor).toStdString() << std::endl;
    // 或者使用 QTextStream
    QTextStream out(stdout);
    out << "QT_SCALE_FACTOR=" << scaleFactor << "\n";
    out.flush();
  • 版权年份修改不合理
    SPDX-FileCopyrightText: 2015 - 2026,结束年份修改为了 2026(未来时间)。通常版权结束年份应为文件最近一次修改的年份(如 2023 或 2024),除非有特殊法务要求,否则不建议写未来年份。
    建议:将 2026 改回当前实际年份。

3. 代码性能

  • Shell 脚本中的冗余变量赋值与进程调用
    greeter_display_setting_path="/usr/bin/greeter-display-setting"
    if [ -f $greeter_display_setting_path ]; then
        scale_env=$(/usr/bin/greeter-display-setting | tail -1)
    1. 检查文件是否存在(-f)后立即执行该文件,在并发或权限变更场景下存在 TOCTOU(检查时间与使用时间不一致)问题,且增加了一次磁盘 IO 判断。
    2. 使用管道 | tail -1 额外启动了一个 tail 进程,增加了系统开销。
      建议:直接执行命令并获取结果,通过判断命令执行是否成功来决定是否 export。C++ 代码中已经只在最后一行输出需要的环境变量,可以直接捕获:
    if scale_env=$(/usr/bin/greeter-display-setting 2>/dev/null); then
        export "$scale_env"
    fi

4. 代码安全

  • Shell 脚本中的命令注入风险
    export $scale_env(即使加了引号 export "$scale_env")将外部程序的输出直接作为环境变量导出。如果 greeter-display-setting 被恶意替换,或者其输出被劫持(例如输出 QT_SCALE_FACTOR=1.0; rm -rf /),虽然 export 不会直接执行嵌入的命令,但某些不安全的 Shell 脚本后续如果直接 eval 该环境变量,就会导致命令注入。
    建议

    1. 确保 greeter-display-setting 二进制文件的权限严格受控(只读、属主为 root),防止被篡改。
    2. 在 C++ 程序中增加对 scaleFactor 范围的严格校验,防止输出超出预期格式的字符串:
    // 在 C++ 代码 setQtScaleFactorEnv() 中增加校验
    if (scaleFactor > 0.0 && scaleFactor <= 10.0) { // 假设10倍是最大合理缩放比
        std::cout << QString("QT_SCALE_FACTOR=%1").arg(scaleFactor).toStdString() << std::endl;
    }
  • C++ 代码中未使用宏导致逻辑分支不可达
    C++ 中使用了 #ifdef ENABLE_DSS_SNIPE,但在 CMakeLists.txt 中,并没有看到针对 greeter-display-setting 目标定义 ENABLE_DSS_SNIPE 宏的代码(如 target_compile_definitions(greeter-display-setting PRIVATE ENABLE_DSS_SNIPE))。如果该宏未定义,Snipe 相关的代码将永远不会被编译。
    建议:检查 CMakeLists.txt,确保在 Snipe 构建模式下,正确地为目标传递了宏定义:

    if (NOT DISABLE_DSS_SNIPE) # 或者对应的 Snipe 判断条件
        target_compile_definitions(greeter-display-setting PRIVATE ENABLE_DSS_SNIPE)
    endif()

综合修改建议代码

C++ (src/app/greeter-display-setting.cpp):

// SPDX-FileCopyrightText: 2015 - 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
// ... 前置代码 ...

static void setQtScaleFactorEnv() {
    double scaleFactor = 0.0;
    // 建议:如果逻辑不是刻意反转,这里应该统一为 IsWayland
#ifdef ENABLE_DSS_SNIPE
    scaleFactor = getScaleFactor(); // 请确认:Snipe模式下 X11 真的需要设置吗?
#else
    scaleFactor = IsWayland ? getScaleFormConfig() : getScaleFactor();
#endif
    qDebug() << "Final scale factor: " << scaleFactor;
    // 增加安全边界校验,防止异常值输出
    if (scaleFactor > 0.0 && scaleFactor <= 10.0) {
        std::cout << QString("QT_SCALE_FACTOR=%1").arg(scaleFactor).toStdString() << std::endl;
    }
}

int main(int argc, char* argv[])
{
    // 建议:如果 Snipe 模式下也是 Wayland 需要设置,请将 #ifdef 逻辑统一
#ifdef ENABLE_DSS_SNIPE
    // 此处逻辑与注释相悖,如果是刻意为之,请加详尽注释;否则应改为 if (IsWayland)
    if (!IsWayland) { 
        setQtScaleFactorEnv();
    }
#else
    if (IsWayland) {
        setQtScaleFactorEnv();
    }
#endif

    return 0;
}

Shell (files/snipe/scripts/lightdm-deepin-greeter):

xsettingsd_conf="/etc/lightdm/deepin/xsettingsd.conf"
if [ -e "$xsettingsd_conf" ]; then
    xsettingsd -c "$xsettingsd_conf" &
else
    # 直接执行并捕获输出,避免 TOCTOU 漏洞和多余的 tail 进程
    if scale_env=$(/usr/bin/greeter-display-setting 2>/dev/null); then
        # 务必加上双引号,防止词法分割
        export "$scale_env"
    fi
fi

CMake (CMakeLists.txt):
请确保在对应分支添加宏定义(如果原先没有的话):

# 在 snipe 分支或全局配置中确保宏生效
if (NOT DISABLE_DSS_SNIPE)
    target_compile_definitions(greeter-display-setting PRIVATE ENABLE_DSS_SNIPE)
endif()

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 left some high level feedback:

  • The ENABLE_DSS_SNIPE/IsWayland branching for scale-factor handling is split between setQtScaleFactorEnv() and main(), which makes the control flow harder to reason about; consider centralizing the condition in one place (e.g., compute the desired scaleFactor in main() and pass it in) so the behavior for each build configuration is clearer and less error-prone to change.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `ENABLE_DSS_SNIPE`/`IsWayland` branching for scale-factor handling is split between `setQtScaleFactorEnv()` and `main()`, which makes the control flow harder to reason about; consider centralizing the condition in one place (e.g., compute the desired scaleFactor in `main()` and pass it in) so the behavior for each build configuration is clearer and less error-prone to change.

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
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-ci-robot, 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 yixinshark merged commit 3af9176 into master May 14, 2026
26 of 29 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.

2 participants