Skip to content

feat: refactor wallpaper slideshow for multi-monitor support - #29

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
mhduiy:slider
Oct 21, 2025
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
mhduiy:slider

Conversation

@mhduiy

@mhduiy mhduiy commented Oct 20, 2025 •

Copy link
Copy Markdown
Contributor
  1. Added getCurrentWorkspaceBackgroundForMonitor method to retrieve wallpaper for specific monitor
  2. Refactored configuration storage to use monitor names directly instead of workspace-monitor combinations
  3. Implemented per-monitor wallpaper type tracking to handle different wallpaper types on different screens
  4. Added screen validation to ensure operations only affect valid monitors
  5. Updated configuration migration to convert old workspace-monitor format to monitor-only format
  6. Improved wallpaper change detection to handle multi-monitor scenarios

Log: Enhanced wallpaper slideshow to better support multi-monitor setups

Influence:

  1. Test wallpaper slideshow on single monitor setup
  2. Test wallpaper slideshow on multi-monitor setup with different wallpapers
  3. Verify configuration migration from old format to new format
  4. Test wallpaper change detection when switching between different wallpaper types
  5. Verify slideshow scheduling works correctly for each monitor independently
  6. Test with invalid monitor names to ensure proper error handling

feat: 重构壁纸轮播功能以支持多显示器

  1. 新增 getCurrentWorkspaceBackgroundForMonitor 方法用于获取特定显示器的 壁纸
  2. 重构配置存储,直接使用显示器名称而非工作区-显示器组合
  3. 实现按显示器跟踪壁纸类型,以处理不同屏幕上的不同壁纸类型
  4. 添加屏幕验证确保操作仅影响有效显示器
  5. 更新配置迁移以将旧的工作区-显示器格式转换为仅显示器格式
  6. 改进壁纸变更检测以处理多显示器场景

Log: 增强壁纸轮播功能以更好地支持多显示器设置

Influence:

  1. 在单显示器设置下测试壁纸轮播功能
  2. 在多显示器设置下测试壁纸轮播功能,使用不同壁纸
  3. 验证从旧格式到新格式的配置迁移
  4. 测试在不同壁纸类型之间切换时的壁纸变更检测
  5. 验证每个显示器的轮播调度独立正常工作
  6. 使用无效显示器名称测试以确保正确的错误处理

pms: BUG-333269
pms: BUG-333263

Summary by Sourcery

Refactor the wallpaper slideshow system to support multi-monitor setups by keying configurations and tracking per-monitor wallpaper state

New Features:

  • Add getCurrentWorkspaceBackgroundForMonitor DBus method to fetch wallpapers for individual monitors
  • Implement per-monitor wallpaper type tracking to handle different wallpaper types across screens

Enhancements:

  • Refactor configuration storage to use monitor names and migrate legacy workspace-monitor entries
  • Validate screen names to ensure operations only affect existing monitors
  • Enhance wallpaper change detection and scheduling to independently manage slideshows on each monitor

1. Added getCurrentWorkspaceBackgroundForMonitor method to retrieve
wallpaper for specific monitor
2. Refactored configuration storage to use monitor names directly
instead of workspace-monitor combinations
3. Implemented per-monitor wallpaper type tracking to handle different
wallpaper types on different screens
4. Added screen validation to ensure operations only affect valid
monitors
5. Updated configuration migration to convert old workspace-monitor
format to monitor-only format
6. Improved wallpaper change detection to handle multi-monitor scenarios

Log: Enhanced wallpaper slideshow to better support multi-monitor setups

Influence:
1. Test wallpaper slideshow on single monitor setup
2. Test wallpaper slideshow on multi-monitor setup with different
wallpapers
3. Verify configuration migration from old format to new format
4. Test wallpaper change detection when switching between different
wallpaper types
5. Verify slideshow scheduling works correctly for each monitor
independently
6. Test with invalid monitor names to ensure proper error handling

feat: 重构壁纸轮播功能以支持多显示器

1. 新增 getCurrentWorkspaceBackgroundForMonitor 方法用于获取特定显示器的
壁纸
2. 重构配置存储,直接使用显示器名称而非工作区-显示器组合
3. 实现按显示器跟踪壁纸类型,以处理不同屏幕上的不同壁纸类型
4. 添加屏幕验证确保操作仅影响有效显示器
5. 更新配置迁移以将旧的工作区-显示器格式转换为仅显示器格式
6. 改进壁纸变更检测以处理多显示器场景

Log: 增强壁纸轮播功能以更好地支持多显示器设置

Influence:
1. 在单显示器设置下测试壁纸轮播功能
2. 在多显示器设置下测试壁纸轮播功能,使用不同壁纸
3. 验证从旧格式到新格式的配置迁移
4. 测试在不同壁纸类型之间切换时的壁纸变更检测
5. 验证每个显示器的轮播调度独立正常工作
6. 使用无效显示器名称测试以确保正确的错误处理

pms: BUG-333269
pms: BUG-333263
@mhduiy
mhduiy requested a review from 18202781743 October 20, 2025 09:35
@sourcery-ai

sourcery-ai Bot commented Oct 20, 2025

Copy link
Copy Markdown

Reviewer's Guide

Refactors the wallpaper slideshow manager to fully support multi-monitor setups by switching configuration keys to per-monitor, migrating legacy workspace-monitor settings, validating monitors before operations, and tracking wallpaper types and scheduling independently for each screen.

Sequence diagram for per-monitor wallpaper change detection and update

sequenceDiagram
    participant "SlideshowManager"
    participant "QApplication"
    participant "QScreen"
    participant "AppearanceDBusProxy"
    participant "Backgrounds"
    "SlideshowManager"->>"QApplication": get screens()
    loop for each screen
        "SlideshowManager"->>"QScreen": get name()
        "SlideshowManager"->>"AppearanceDBusProxy": getCurrentWorkspaceBackgroundForMonitor(screenName)
        "SlideshowManager"->>"Backgrounds": getBackgroundType(wallpaper)
        alt wallpaper type changed
            "SlideshowManager"->>"Backgrounds": update type for screen
        end
    end
    alt any wallpaper type changed
        "SlideshowManager"->>"SlideshowManager": updateWSPolicy()
        "SlideshowManager"->>"WallpaperLoop": updateLoopList()
    end
Loading

Entity relationship diagram for wallpaper slideshow configuration migration

erDiagram
    CONFIG_OLD {
        STRING key
        STRING value
    }
    CONFIG_NEW {
        STRING monitorName
        STRING value
    }
    CONFIG_OLD ||--o| CONFIG_NEW : "migrates to"
Loading

Class diagram for updated SlideshowManager and AppearanceDBusProxy

classDiagram
class SlideshowManager {
    +bool doSetWallpaperSlideShow(monitorName, wallpaperSlideShow)
    +QString doGetWallpaperSlideShow(monitorName)
    +void updateWSPolicy(policy)
    +void loadWSConfig()
    +void autoChangeBg(monitorSpace, date)
    +void init()
    +void loadConfig()
    +void handlePrepareForSleep(sleep)
    +void onWallpaperChanged()
    +bool isValidScreen(screenName)
    -QMap<QString, QSharedPointer<WallpaperLoop>> m_wsLoopMap
    -QSharedPointer<AppearanceDBusProxy> m_dbusProxy
    -QString m_wallpaperSlideShow
    -QMap<QString, Backgrounds::BackgroundType> m_wallpaperType
}
class AppearanceDBusProxy {
    +QString getCurrentWorkspaceBackground()
    +QString getCurrentWorkspaceBackgroundForMonitor(monitor)
    +void SetCurrentWorkspaceBackgroundForMonitor(url, screenName)
    +void SetGreeterBackground(url)
}
SlideshowManager --> AppearanceDBusProxy : uses
Loading

File-Level Changes

Change Details Files
Switch slideshow configuration to monitor-only keys and migrate legacy workspace-monitor format
  • doSetWallpaperSlideShow and doGetWallpaperSlideShow store and retrieve entries by monitorName only
  • Introduce WS_CONFIG_PATH and update loadWSConfig to use it
  • Implement loadConfig migration to strip "&&" suffix and rewrite settings in new format
commondefine.h
slideshowmanager.cpp
Remove workspace context from scheduling and apply per-monitor scheduling directly
  • Eliminate m_curMonitorSpace and composite key parsing in autoChangeBg, init, updateWSPolicy
  • Simplify autoChangeBg to call setMonitorBackground with monitorName only
slideshowmanager.cpp
slideshowmanager.h
Implement per-monitor wallpaper retrieval and type tracking
  • Add getCurrentWorkspaceBackgroundForMonitor DBus proxy method
  • Convert m_wallpaperType to a QMap and update onWallpaperChanged to iterate qApp->screens()
  • Initialize WallpaperLoop instances with per-monitor background type
appearancedbusproxy.cpp
slideshowmanager.cpp
slideshowmanager.h
Add screen validation to guard slideshow operations on valid monitors
  • Add SlideshowManager::isValidScreen to check qApp->screens()
  • Validate monitorName in doSetWallpaperSlideShow and skip empty/invalid screen entries in loops
slideshowmanager.cpp
slideshowmanager.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

@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 there - I've reviewed your changes - here's some feedback:

  • doSetWallpaperSlideShow currently swallows JSON parse errors and proceeds with an empty object, so consider logging parse failures or aborting to avoid unintentionally wiping existing keys.
  • loadConfig always rewrites the migrated JSON back to DConfig on every startup, which could be optimized by applying the migration only once to reduce repeated writes.
  • Relying on QScreen::name() for monitor identity may be fragile across reboots or hardware changes—consider using a more stable identifier like screen serial number or index.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- doSetWallpaperSlideShow currently swallows JSON parse errors and proceeds with an empty object, so consider logging parse failures or aborting to avoid unintentionally wiping existing keys.
- loadConfig always rewrites the migrated JSON back to DConfig on every startup, which could be optimized by applying the migration only once to reduce repeated writes.
- Relying on QScreen::name() for monitor identity may be fragile across reboots or hardware changes—consider using a more stable identifier like screen serial number or index.

## Individual Comments

### Comment 1
<location> `src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp:41-45` </location>
<code_context>
+        qWarning() << "monitor can not found: " << monitorName;
+        return false;
+    }
+    QByteArray jsonData = m_wallpaperSlideShow.toUtf8();
+    QJsonParseError err;
+    QJsonDocument doc = QJsonDocument::fromJson(jsonData, &err);

-    QJsonDocument doc = QJsonDocument::fromJson(wallpaperSlideShow.toLatin1());
-    QJsonObject cfgObj = doc.object();
+    QJsonObject cfgObj;
+    if (err.error == QJsonParseError::NoError && doc.isObject()) {
+        cfgObj = doc.object();
</code_context>

<issue_to_address>
**issue (bug_risk):** Potential confusion between input and member variable usage for wallpaperSlideShow.

The method uses 'm_wallpaperSlideShow' for JSON parsing instead of the 'wallpaperSlideShow' parameter, which may not reflect the intended behavior. Please verify if the correct variable is being used.
</issue_to_address>

### Comment 2
<location> `src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp:82` </location>
<code_context>
-
-    if (tempMap.count(key) == 1) {
-        return tempMap[key].toString();
+    if (tempMap.count(monitorName) == 1) {
+        return tempMap[monitorName].toString();
     }
</code_context>

<issue_to_address>
**nitpick:** Using count() == 1 for key existence is less idiomatic than contains().

Consider replacing count(monitorName) == 1 with contains(monitorName) for improved readability and idiomatic usage.
</issue_to_address>

### Comment 3
<location> `src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp:116-119` </location>
<code_context>
         }

         if (m_wsLoopMap.count(iter.first) == 0) {
-            m_wsLoopMap[iter.first] = QSharedPointer<WallpaperLoop>(new WallpaperLoop(m_wallpaperType));
+            m_wsLoopMap[iter.first] = QSharedPointer<WallpaperLoop>(new WallpaperLoop(m_wallpaperType[screenName]));
         }
-        m_wsLoopMap[iter.first]->updateWallpaperType(m_wallpaperType);
+        m_wsLoopMap[iter.first]->updateWallpaperType(m_wallpaperType[screenName]);

-        if (m_curMonitorSpace == iter.first && WallpaperLoopConfigManger::isValidWSPolicy(iter.second.toString())) {
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Assumes m_wallpaperType[screenName] is always valid; may cause issues if missing.

Accessing m_wallpaperType[screenName] without validation may lead to default or unintended values. Please ensure m_wallpaperType is properly initialized for all relevant screens before use.

```suggestion
        if (!m_wallpaperType.contains(screenName)) {
            qWarning() << "Wallpaper type not initialized for screen:" << screenName;
            continue;
        }
        if (m_wsLoopMap.count(iter.first) == 0) {
            m_wsLoopMap[iter.first] = QSharedPointer<WallpaperLoop>(new WallpaperLoop(m_wallpaperType[screenName]));
        }
        m_wsLoopMap[iter.first]->updateWallpaperType(m_wallpaperType[screenName]);
```
</issue_to_address>

### Comment 4
<location> `src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp:255` </location>
<code_context>
 void SlideshowManager::loadConfig()
 {
-    m_wallpaperSlideShow = m_settingDconfig->value(GSKEYWALLPAPERSLIDESHOW).toString();
+    QFile::remove(WS_CONFIG_PATH);
+
+    const QString wallpaperSlideShow = m_settingDconfig->value(GSKEYWALLPAPERSLIDESHOW).toString();
</code_context>

<issue_to_address>
**issue (bug_risk):** Unconditionally removing WS_CONFIG_PATH may cause data loss.

If removing the config file is required, implement a backup or recovery process to prevent data loss in case of failure.
</issue_to_address>

### Comment 5
<location> `src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp:270-274` </location>
<code_context>
+    QJsonObject newObject;
+
+    // 兼容老配置,去掉&&
+    for (auto it = rootObject.begin(); it != rootObject.end(); ++it) {
+        QString key = it.key();
+        QJsonValue value = it.value();
+
+        if (key.contains("&&")) {
+            QString newKey = key.split("&&").first();
+            newObject[newKey] = value;
</code_context>

<issue_to_address>
**issue (bug_risk):** Key migration logic may not handle duplicate keys after splitting.

Splitting keys with '&&' may overwrite values if multiple original keys produce the same newKey. Please add logic to detect and handle such duplicates to prevent data loss.
</issue_to_address>

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.

Comment thread src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp
@18202781743
18202781743 requested a review from Copilot October 21, 2025 02:41

Copilot AI 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.

Pull Request Overview

This PR refactors the wallpaper slideshow feature to properly support multi-monitor configurations by tracking wallpaper state per-monitor instead of per-workspace-monitor combination.

Key Changes:

  • Migrated configuration storage from workspace&&monitor format to monitor-only keys
  • Changed wallpaper type tracking from single value to per-monitor map
  • Added per-monitor wallpaper retrieval and validation

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
slideshowmanager.h Changed m_wallpaperType from single value to per-monitor map; added screen validation method
slideshowmanager.cpp Implemented monitor-based configuration storage, added config migration logic, and per-monitor wallpaper change detection
commondefine.h Added WS_CONFIG_PATH constant to centralize config file path
appearancedbusproxy.h Added getCurrentWorkspaceBackgroundForMonitor method declaration
appearancedbusproxy.cpp Implemented monitor-specific wallpaper retrieval method

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp
Comment thread src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp
Comment thread src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp
Comment thread src/plugin-qt/wallpaperslideshow/slideshowmanager.cpp
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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 Oct 21, 2025

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Oct 21, 2025

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 8afca8d into linuxdeepin:master Oct 21, 2025
5 of 7 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.

4 participants