Skip to content

fix(wallpaperslideshow): skip DBus registration on Wayland, handled b…#71

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
mhduiy:treeland/fix/startdcc
May 28, 2026
Merged

fix(wallpaperslideshow): skip DBus registration on Wayland, handled b…#71
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
mhduiy:treeland/fix/startdcc

Conversation

@mhduiy

@mhduiy mhduiy commented May 28, 2026

Copy link
Copy Markdown
Contributor

…y Treeland

  1. Check XDG_SESSION_TYPE in DSMRegister and return early under Wayland
  2. Treeland compositor manages wallpaper slideshow on Wayland sessions
  3. Align with the same Wayland-guard pattern used in xsettings module

Log: Skip wallpaper slideshow DBus registration on Wayland, where Treeland handles it

fix(wallpaperslideshow): Wayland 下跳过壁纸轮播 DBus 注册,由 Treeland 处理

  1. 在 DSMRegister 中检查 XDG_SESSION_TYPE,Wayland 下提前返回
  2. Wayland 会话中壁纸轮播由 Treeland 合成器负责
  3. 与 xsettings 模块中已有的 Wayland 守卫模式保持一致

Log: Wayland 下壁纸轮播由 Treeland 负责,跳过 DBus 注册

…y Treeland

1. Check XDG_SESSION_TYPE in DSMRegister and return early under Wayland
2. Treeland compositor manages wallpaper slideshow on Wayland sessions
3. Align with the same Wayland-guard pattern used in xsettings module

Log: Skip wallpaper slideshow DBus registration on Wayland, where Treeland handles it

fix(wallpaperslideshow): Wayland 下跳过壁纸轮播 DBus 注册,由 Treeland 处理

1. 在 DSMRegister 中检查 XDG_SESSION_TYPE,Wayland 下提前返回
2. Wayland 会话中壁纸轮播由 Treeland 合成器负责
3. 与 xsettings 模块中已有的 Wayland 守卫模式保持一致

Log: Wayland 下壁纸轮播由 Treeland 负责,跳过 DBus 注册

@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 @mhduiy, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff,下面我将从语法逻辑、代码质量、代码性能和代码安全四个维度对该代码变更进行详细的审查,并提出改进意见。

总体评价

此次代码变更的主要目的是:在Wayland环境下阻止WallpaperSlideshow插件的注册与初始化。通过检查环境变量XDG_SESSION_TYPE,如果当前为Wayland会话,则直接返回0(成功状态)跳过后续逻辑。这是一个常见的平台兼容性处理手段,但实现细节上存在一些可以优化的空间。


一、 语法与逻辑

  1. 逻辑:返回值语义不够清晰

    • 问题:当检测到Wayland时,代码直接return 0;。在C/C++的main或注册函数中,0通常代表“成功”。但对于调用方来说,这可能意味着“插件注册成功”,而实际上插件并未注册。如果调用方依赖该返回值来判断插件是否可用,可能会引发逻辑错误。
    • 建议:如果调用方允许,建议返回一个非0的错误码(如1-1)表示“不支持的平台/跳过注册”;如果受限于框架设计必须返回0,强烈建议增加一行日志输出,表明这是主动跳过而非注册成功。
  2. 逻辑:资源泄漏风险(视上下文而定)

    • 问题:Diff中没有展示service变量的声明,但根据上下文推测,它可能是一个全局变量或类的静态成员。如果service在此之前已经被初始化或分配了内存,直接return 0可能会导致内存泄漏。
    • 建议:确保在return 0;之前,没有需要清理的资源。如果service是局部变量且遵循RAII,则无需担心;如果是裸指针,需确认逻辑安全性。

二、 代码质量

  1. 可读性:硬编码的字符串与缺乏注释
    • 问题:直接在代码中硬编码了"XDG_SESSION_TYPE""wayland",且没有注释说明为什么在Wayland下要直接返回。未来其他开发者看到这段代码可能会感到困惑(是Wayland不支持?还是有专门的Wayland实现?)。

    • 建议

      • 添加清晰的注释说明跳过的原因。
      • 考虑将判断逻辑提取为独立的内联函数或使用具名常量,增强可读性。

      改进示例:

      // Wayland does not support X11-based wallpaper slideshow, skip registration.
      const bool isWayland = qEnvironmentVariable("XDG_SESSION_TYPE") == QLatin1String("wayland");
      if (isWayland) {
          return 0; // or specific error code
      }

三、 代码性能

  1. 性能:QLatin1String的构造开销
    • 问题qEnvironmentVariable返回的是QString。每次调用时都构造一个QLatin1String("wayland")对象进行对比,虽然开销极小,但在平台检查这种大概率只执行一次的逻辑中,其实无需过度优化。不过,Qt提供了更优雅的字符串比较方式。
    • 建议:直接使用QString::compare或利用Qt的字符串字面量(如果使用C++11以上及Qt5/6),代码会更简洁。

四、 代码安全

  1. 安全性:环境变量可被篡改
    • 问题XDG_SESSION_TYPE是一个用户级环境变量,是可以被用户手动修改或篡改的(例如,在X11下强制设置XDG_SESSION_TYPE=wayland,或反之)。如果插件的崩溃或不加载会导致严重的安全问题或系统不稳定,依赖环境变量可能不够稳妥。
    • 建议:对于一般的桌面应用插件,依赖XDG_SESSION_TYPE是业界惯例,风险可控。但如果需要更严格的判断,可以通过Qt的QGuiApplication::platformName()(需要在QGuiApplication实例化之后)或者检查特定的Wayland显示协议(如qgetenv("WAYLAND_DISPLAY"))来做双重校验。

综合改进建议代码

结合以上分析,我为你提供一份优化后的代码参考:

// SPDX-FileCopyrightText: 2025 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <QDebug> // 确保包含日志头文件

extern "C" int DSMRegister(const char *name, void *data)
{
    Q_UNUSED(name)
    Q_UNUSED(data)

    // 优化1:添加注释说明原因
    // Note: WallpaperSlideshow relies on X11 specific features. 
    // Skip registration on Wayland to avoid conflicts or crashes.
    if (qEnvironmentVariable("XDG_SESSION_TYPE") == QStringLiteral("wayland")) {
        // 优化2:添加日志,使得排查问题时有迹可循
        qDebug() << "WallpaperSlideshow: Skipping registration on Wayland session.";
        // 优化3:如果框架允许,建议返回非0值表示未注册;若必须返回0,则保留0。
        return 0; 
    }

    service = new WallpaperSlideshow();
    new WallpaperSlideshowAdaptor(service);
    bool wallpaperSlideshowRegister = QDBusConnection::sessionBus().registerService(WALLPAPER_SLIDESHOW_SERVICE);
    
    // ... 后续逻辑
}

主要改动点说明:

  1. QLatin1String替换为QStringLiteral(或直接使用== "wayland"),在现代Qt版本中更符合惯用法,且语义清晰。
  2. 增加了qDebug()日志,这对于桌面环境的插件开发极其重要,可以避免在Wayland下插件静默不工作时耗费排查时间。
  3. 补充了清晰的注释,解释了“为什么”要在这行返回,提升代码的可维护性。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy, 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

@mhduiy

mhduiy commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

轮播壁纸后续在Treeland实现,这里屏蔽

@mhduiy

mhduiy commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented May 28, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 4d24b6e into linuxdeepin:master May 28, 2026
8 of 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