88#include < QScreen>
99#include < QImage>
1010#include < QLoggingCategory>
11+ #include < QCursor>
1112
1213#include " Appearance1.h"
1314#include " blurhash.hpp"
1415#include " ../launchercontroller.h"
16+ #include " ../desktopintegration.h"
1517
1618Q_LOGGING_CATEGORY (logDdeIntegration, " org.deepin.dde.launchpad.integration" )
1719
@@ -31,8 +33,11 @@ Appearance::Appearance(QObject *parent)
3133
3234 connect (&(LauncherController::instance ()), &LauncherController::currentFrameChanged,
3335 this , &Appearance::updateCurrentWallpaperBlurhash);
36+ // Use a delayed call to wait for screen info to be ready after visible changes
3437 connect (&(LauncherController::instance ()), &LauncherController::visibleChanged,
3538 this , &Appearance::updateCurrentWallpaperBlurhash);
39+ connect (&(LauncherController::instance ()), &LauncherController::currentScreenChanged,
40+ this , &Appearance::updateCurrentWallpaperBlurhash);
3641
3742 if (m_dbusAppearanceIface->isValid ()) {
3843 connect (m_dbusAppearanceIface, &Appearance1::OpacityChanged, this , [this ](double value) {
@@ -60,7 +65,21 @@ void Appearance::updateCurrentWallpaperBlurhash()
6065 return ;
6166 }
6267
63- const QString screenName = qApp->primaryScreen ()->name ();
68+ // Use the current screen where the launcher is displayed
69+ // Priority: 1. LauncherController.currentScreen, 2. Dock position, 3. Cursor position, 4. Primary screen
70+ QString screenName = LauncherController::instance ().currentScreen ();
71+ if (screenName.isEmpty ()) {
72+ // Try to get screen from dock position (launcher opens on the same screen as dock)
73+ QRect dockGeometry = DesktopIntegration::instance ().dockGeometry ();
74+ if (dockGeometry.isValid () && dockGeometry.x () >= 0 ) {
75+ QPoint dockCenter = dockGeometry.center ();
76+ QScreen *screenAtDock = qApp->screenAt (dockCenter);
77+ if (screenAtDock) {
78+ screenName = screenAtDock->name ();
79+ }
80+ }
81+ }
82+ qCDebug (logDdeIntegration) << " Getting wallpaper for screen:" << screenName;
6483 QDBusPendingReply<QString> async = m_dbusAppearanceIface->GetCurrentWorkspaceBackgroundForMonitor (screenName);
6584 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher (async, this );
6685 connect (watcher, &QDBusPendingCallWatcher::finished, this , [this ](QDBusPendingCallWatcher* call){
@@ -72,14 +91,18 @@ void Appearance::updateCurrentWallpaperBlurhash()
7291 qCDebug (logDdeIntegration) << " Got wallpaper URL from dbus:" << wallpaperUrl;
7392
7493 if (m_wallpaperBlurMap.contains (wallpaperUrl)) {
75- m_wallpaperBlurhash = m_wallpaperBlurMap.value (wallpaperUrl);
76- emit wallpaperBlurhashChanged ();
94+ QString newBlurhash = m_wallpaperBlurMap.value (wallpaperUrl);
95+ if (m_wallpaperBlurhash != newBlurhash) {
96+ m_wallpaperBlurhash = newBlurhash;
97+ emit wallpaperBlurhashChanged ();
98+ }
7799 } else {
78100 qCDebug (logDdeIntegration) << " No cached blurhash found, updating all wallpapers" ;
79101 // try update new workspace background image
80102 updateAllWallpaper ();
81103 }
82104 }
105+ call->deleteLater ();
83106 });
84107}
85108
@@ -97,18 +120,15 @@ void Appearance::updateAllWallpaper()
97120 qCWarning (logDdeIntegration) << " Wallpaper document is not a JSON object" ;
98121 return ;
99122 }
100- int i = 1 ;
101- do {
102- const QString k = QString (" Primary&&%1" ).arg (i++);
103- QJsonValue v = doc[k];
104-
105- #ifdef QT_DEBUG
106- qDebug () << k << " :" << v;
107- #endif
108123
124+ QJsonObject jsonObj = doc.object ();
125+
126+ // Iterate through all keys in the JSON object to get wallpapers for all screens
127+ // Keys are in format "ScreenName&&WorkspaceIndex" (e.g., "eDP-1&&1", "HDMI-1&&1")
128+ for (auto it = jsonObj.begin (); it != jsonObj.end (); ++it) {
129+ QJsonValue v = it.value ();
109130 if (!v.isString ()) {
110- qCDebug (logDdeIntegration) << " No more wallpapers found at key:" << k;
111- break ;
131+ continue ;
112132 }
113133
114134 QUrl wallpaperUrl (v.toString ());
@@ -146,7 +166,7 @@ void Appearance::updateAllWallpaper()
146166 });
147167
148168 m_blurhashWatchers << watcher;
149- } while ( 1 );
169+ }
150170}
151171
152172qreal Appearance::opacity () const
0 commit comments