Skip to content

feat: add wallpaper fill style configuration - #4025

Open
Kakueeen wants to merge 1 commit into
linuxdeepin:masterfrom
Kakueeen:master
Open

feat: add wallpaper fill style configuration#4025
Kakueeen wants to merge 1 commit into
linuxdeepin:masterfrom
Kakueeen:master

Conversation

@Kakueeen

@Kakueeen Kakueeen commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Add support for configuring desktop wallpaper fill styles (Fill, Fit,
Stretch, Flatten, Center). This allows users to choose how the wallpaper
is displayed on the screen. A new DConfig key wallpaperFillStyle has
been added to org.deepin.dde.file-manager.desktop.json. The background
manager now listens for changes to this config, clears the pixmap cache,
and re-renders the wallpaper accordingly. The background bridge selects
the appropriate rendering strategy: for Fill style it uses the existing
WallpaperCache service or scaled cropping; for other styles it calls a
new processPixmap function that handles scaling, tiling, centering,
etc. A JSON parsing utility getValueFromJson extracts per-screen style
values from the config (expected format: {"screenName": styleNumber} ). Added a new overload of getPixmap to load original images without
scaling for non-Fill styles.

Log: Added wallpaper fill style configuration feature

Influence:

  1. Test setting each fill style (Fill, Fit, Stretch, Flatten, Center)
    via dconfig and verify wallpaper display
  2. Test changing style dynamically and ensure wallpaper updates
    immediately without restart
  3. Test with multi-monitor setups, verify per-screen style if config
    supports it
  4. Test with different image sizes and aspect ratios
  5. Test with corrupted or unsupported image formats (e.g., .png
    with .jpg content)
  6. Verify that the wallpaper cache is cleared when style changes
  7. Test default behavior when config value is empty or invalid
  8. Test performance with large images and screen resolutions

feat: 添加桌面壁纸填充方式配置

支持配置桌面壁纸的填充方式(填充、适应、拉伸、平铺、居中)。新增 DConfig
wallpaperFillStyleorg.deepin.dde.file-manager.desktop.json
背景管理器监听该配置变化,清除缓存并重新渲染壁纸。背景桥根据配置选
择渲染策略:填充模式使用原有的 WallpaperCache 服务或裁剪缩放;其他
模式调用新的 processPixmap 函数处理缩放、平铺、居中等操作。新增
getValueFromJson 工具函数从 JSON 格式的配置值解析每个屏幕的样式值(预
期格式:{"screenName": styleNumber})。新增 getPixmap 重载函数以加载
原始图片(不缩放)用于非填充模式。

Log: 新增桌面壁纸填充方式配置功能

Influence:

  1. 测试通过 dconfig 设置每种填充方式(填充/适应/拉伸/平铺/居中),验证壁
    纸显示效果
  2. 测试动态修改样式,确保壁纸立即更新,无需重启
  3. 测试多屏环境,如果配置支持按屏幕设置则验证每个屏幕的样式
  4. 测试不同尺寸和宽高比的图片
  5. 测试损坏或不支持的图片格式(如 .png 后缀但内容为 .jpg)
  6. 验证修改样式时壁纸缓存被清除
  7. 测试配置值为空或无效时的默认行为
  8. 测试大尺寸图片和高分辨率屏幕下的性能

TASK: https://pms.uniontech.com/task-view-393123.html
TASK: https://pms.uniontech.com/task-view-371829.html

Summary by Sourcery

Add configurable wallpaper fill styles and hook them into the desktop background rendering pipeline.

New Features:

  • Introduce a wallpaper fill style enum supporting Fill, Fit, Stretch, Flatten, and Center modes.
  • Add DConfig key wallpaperFillStyle in org.deepin.dde.file-manager.desktop to control wallpaper rendering per screen.

Enhancements:

  • Update background manager to listen for wallpaperFillStyle changes, clear pixmap cache, and re-render wallpapers immediately.
  • Extend background bridge image loading and processing logic to support style-specific scaling, tiling, centering, and aspect handling.

@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 @Kakueeen, 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
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Kakueeen

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

@sourcery-ai

sourcery-ai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds configurable wallpaper fill styles via a new DConfig key and updates the background manager/bridge to interpret per-screen style values, load original images for non-Fill styles, and render wallpapers using different scaling/tiling strategies while clearing cache on configuration changes.

Sequence diagram for wallpaper style change and rendering

sequenceDiagram
    participant DConfigManager
    participant BackgroundManager
    participant BackgroundBridge
    participant WallpaperCache

    DConfigManager->>BackgroundManager: valueChanged(kConfName, KwallpaperFillStyle)
    BackgroundManager->>BackgroundManager: onConfigChanged(cfg, key)
    BackgroundManager->>BackgroundManager: QPixmapCache_clear()
    BackgroundManager->>BackgroundManager: onBackgroundChanged()
    BackgroundManager->>BackgroundBridge: runUpdate(self, reqs)

    loop per Requestion
        BackgroundBridge->>DConfigManager: value(kConfName, KwallpaperFillStyle, QString())
        BackgroundBridge->>BackgroundBridge: getValueFromJson(styleConfig, req.screen)
        alt WallpaperStyle_Fill
            BackgroundBridge->>WallpaperCache: getScaledPathFromCache(wallpaperPath, trueSize)
            opt pix_isNull
                BackgroundBridge->>BackgroundBridge: getPixmap(req.path, trueSize)
            end
        else Non_Fill_styles
            BackgroundBridge->>BackgroundBridge: getPixmap(req.path)
            BackgroundBridge->>BackgroundBridge: processPixmap(backgroundPixmap, wallpaperStyle, trueSize)
        end
    end

    BackgroundBridge-->>BackgroundManager: onFinished(pRecorder)
Loading

File-Level Changes

Change Details Files
Introduce configurable wallpaper fill styles and per-screen style parsing, and wire background manager to react to DConfig changes.
  • Include DConfigManager, QJsonDocument/QJsonObject, and QPainter dependencies in backgroundmanager.cpp.
  • Define desktop config name and wallpaperFillStyle key constants.
  • Connect BackgroundManager to DConfigManager::valueChanged and implement onConfigChanged to clear QPixmapCache and trigger background rebuild.
  • Implement getValueFromJson utility to parse a JSON style configuration string and return the style value for a given screen, handling extra quote characters.
src/plugins/desktop/ddplugin-background/backgroundmanager.cpp
src/plugins/desktop/ddplugin-background/backgroundmanager.h
src/plugins/desktop/ddplugin-background/backgroundmanager_p.h
assets/configs/org.deepin.dde.file-manager.desktop.json
Extend BackgroundBridge to support multiple wallpaper rendering styles and distinct pixmap loading paths for Fill vs non-Fill styles.
  • Add WallpaperStyle enum with Fill, Fit, Stretch, Flatten, Center in BackgroundBridge private header.
  • Add a new overload of BackgroundBridge::getPixmap that loads the original pixmap without scaling, including format-from-content fallback via QImageReader.
  • Update runUpdate to read wallpaperFillStyle from DConfig, derive WallpaperStyle per screen, handle Fill style with WallpaperCache or scaled cropping, and route non-Fill styles through processPixmap using the original image.
  • Implement processPixmap to apply different rendering strategies: aspect-ratio Fit with transparent padding, full-screen Stretch, tiling Flatten, centered placement, and Fill using KeepAspectRatioByExpanding plus cropping.
  • Extend logging in runUpdate to include the wallpaper style value.
src/plugins/desktop/ddplugin-background/backgroundmanager.cpp
src/plugins/desktop/ddplugin-background/backgroundmanager_p.h

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

@Johnson-zs Johnson-zs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit message的两个TASK换下行

Add support for configuring desktop wallpaper fill styles (Fill, Fit,
Stretch, Flatten, Center). This allows users to choose how the wallpaper
is displayed on the screen. A new DConfig key `wallpaperFillStyle` has
been added to `org.deepin.dde.file-manager.desktop.json`. The background
manager now listens for changes to this config, clears the pixmap cache,
and re-renders the wallpaper accordingly. The background bridge selects
the appropriate rendering strategy: for Fill style it uses the existing
WallpaperCache service or scaled cropping; for other styles it calls a
new `processPixmap` function that handles scaling, tiling, centering,
etc. A JSON parsing utility `getValueFromJson` extracts per-screen style
values from the config (expected format: `{"screenName": styleNumber}
`). Added a new overload of `getPixmap` to load original images without
scaling for non-Fill styles.

Log: Added wallpaper fill style configuration feature

Influence:
1. Test setting each fill style (Fill, Fit, Stretch, Flatten, Center)
via dconfig and verify wallpaper display
2. Test changing style dynamically and ensure wallpaper updates
immediately without restart
3. Test with multi-monitor setups, verify per-screen style if config
supports it
4. Test with different image sizes and aspect ratios
5. Test with corrupted or unsupported image formats (e.g., .png
with .jpg content)
6. Verify that the wallpaper cache is cleared when style changes
7. Test default behavior when config value is empty or invalid
8. Test performance with large images and screen resolutions

feat: 添加桌面壁纸填充方式配置

支持配置桌面壁纸的填充方式(填充、适应、拉伸、平铺、居中)。新增 DConfig
键 `wallpaperFillStyle` 到 `org.deepin.dde.file-manager.desktop.json`。
背景管理器监听该配置变化,清除缓存并重新渲染壁纸。背景桥根据配置选
择渲染策略:填充模式使用原有的 WallpaperCache 服务或裁剪缩放;其他
模式调用新的 `processPixmap` 函数处理缩放、平铺、居中等操作。新增
`getValueFromJson` 工具函数从 JSON 格式的配置值解析每个屏幕的样式值(预
期格式:`{"screenName": styleNumber}`)。新增 `getPixmap` 重载函数以加载
原始图片(不缩放)用于非填充模式。

Log: 新增桌面壁纸填充方式配置功能

Influence:
1. 测试通过 dconfig 设置每种填充方式(填充/适应/拉伸/平铺/居中),验证壁
纸显示效果
2. 测试动态修改样式,确保壁纸立即更新,无需重启
3. 测试多屏环境,如果配置支持按屏幕设置则验证每个屏幕的样式
4. 测试不同尺寸和宽高比的图片
5. 测试损坏或不支持的图片格式(如 .png 后缀但内容为 .jpg)
6. 验证修改样式时壁纸缓存被清除
7. 测试配置值为空或无效时的默认行为
8. 测试大尺寸图片和高分辨率屏幕下的性能

TASK: https://pms.uniontech.com/task-view-393123.html
TASK: https://pms.uniontech.com/task-view-371829.html
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

★ 总体评分:85分

■ 【总体评价】

代码实现了桌面壁纸多种填充方式的配置与渲染,逻辑基本清晰,但存在未初始化Pixmap的瑕疵。
逻辑正确但因部分细节处理不当和命名规范问题扣15分。

■ 【详细分析】

  • 1.语法逻辑(存在错误)✕

BackgroundBridge::processPixmapWallpaperStyle::Flatten 分支中,创建了 QPixmap flattenPixmap(targetSize); 但未调用 fill() 方法初始化背景。对比 FitCenter 分支均调用了 fill(Qt::transparent),此处可能导致平铺边缘出现未定义的垃圾像素。
潜在问题:平铺模式下背景可能出现随机噪点或黑边。
建议:在 Flatten 分支中添加 flattenPixmap.fill(Qt::transparent); 或根据需求填充特定颜色。

  • 2.代码质量(良好)✓

代码结构清晰,新增的 processPixmap 函数职责单一,枚举定义明确。但静态常量 KwallpaperFillStyle 命名不符合常见的驼峰命名规范(首字母大写K),应为 kWallpaperFillStyle
潜在问题:命名不一致可能影响代码可读性和团队规范统一。
建议:将 KwallpaperFillStyle 重命名为 kWallpaperFillStyle

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

BackgroundBridge::runUpdatefor 循环内部,每次迭代都调用 DConfigManager::instance()->value(kConfName, KwallpaperFillStyle, QString()) 读取配置字符串。虽然后续的 getValueFromJson 需要针对不同屏幕解析,但配置字符串本身的读取可以移至循环外。
潜在问题:无
建议:将 DConfig 字符串读取逻辑移至 for 循环之前,避免重复读取。

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码变更主要涉及配置读取、JSON解析和Qt图像处理,未引入外部输入的直接执行或内存越界操作,不存在安全风险。

  • 建议:无

■ 【改进建议代码示例】

// 1. 修复 Flatten 模式下 Pixmap 未初始化问题
// 2. 优化 runUpdate 中的配置读取位置
// 3. 修复命名规范

diff --git a/src/plugins/desktop/ddplugin-background/backgroundmanager.cpp b/src/plugins/desktop/ddplugin-background/backgroundmanager.cpp
index 9a5335695d..e1daa4d17a 100644
--- a/src/plugins/desktop/ddplugin-background/backgroundmanager.cpp
+++ b/src/plugins/desktop/ddplugin-background/backgroundmanager.cpp
@@ -29,7 +29,7 @@ DDP_BACKGROUND_USE_NAMESPACE
 #define CanvasCoreUnsubscribe(topic, func) \
     dpfSignalDispatcher->unsubscribe("ddplugin_core", QT_STRINGIFY2(topic), this, func);
 
-static constexpr char kConfName[] { "org.deepin.dde.file-manager.desktop" };
-static constexpr char KwallpaperFillStyle[] { "wallpaperFillStyle" };
+static constexpr char kWallpaperFillStyle[] { "wallpaperFillStyle" };
 
 // Generate cache key for wallpaper: wallpaper:path@widthxheight
 static QString generateCacheKey(const QString &path, const QSize &size)
@@ -640,8 +640,11 @@ void BackgroundBridge::runUpdate(BackgroundBridge *self, QList<Requestion> reqs)
         QSize trueSize = req.size;
         QString wallpaperPath = req.path.startsWith("file:") ? QUrl(req.path).toLocalFile() : req.path;
 
-        // Read wallpaper fill style from dconfig
-        QString styleConfig = DConfigManager::instance()->value(kConfName, KwallpaperFillStyle, QString()).toString();
-        int style = getValueFromJson(styleConfig, req.screen);
-        auto wallpaperStyle = static_cast<WallpaperStyle>(style);
+        // Read wallpaper fill style from dconfig outside the loop (if not already)
+        // Note: Assuming this block is inside the loop, we should move it out.
+        // For the sake of diff, showing the concept:
+        // QString styleConfig = DConfigManager::instance()->value(kConfName, kWallpaperFillStyle, QString()).toString();
+        // int style = getValueFromJson(styleConfig, req.screen);
+        // auto wallpaperStyle = static_cast<WallpaperStyle>(style);
 
         QPixmap pix;
@@ -730,6 +733,7 @@ QPixmap BackgroundBridge::processPixmap(const QPixmap &originalPixmap, Wallpaper
     case WallpaperStyle::Flatten: {
         QPixmap flattenPixmap(targetSize);
+        flattenPixmap.fill(Qt::transparent); // 添加初始化填充
         QPainter painter(&flattenPixmap);
         int tileWidth = originalPixmap.width();
         int tileHeight = originalPixmap.height();
@@ -766,7 +770,7 @@ int BackgroundBridge::getValueFromJson(QString json, const QString &screenName)
 {
     // The string in dconfig contains extra characters
     if (json.startsWith('"')) {
         json.remove(0, 1);
     }
     if (json.endsWith('"')) {
         json.chop(1);
     }
     QJsonDocument jsonDoc = QJsonDocument::fromJson(json.toUtf8());
 
     if (!jsonDoc.isObject())
         return 0;
 
     QJsonObject jsonObj = jsonDoc.object();
 
     if (jsonObj.contains(screenName))
         return jsonObj[screenName].toInt();
 
     return 0;
 }

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