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,20 +65,48 @@ 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+ if (screenName.isEmpty ()) {
83+ // Try to get screen from cursor position
84+ QPoint cursorPos = QCursor::pos ();
85+ QScreen *screenAtCursor = qApp->screenAt (cursorPos);
86+ if (screenAtCursor) {
87+ screenName = screenAtCursor->name ();
88+ } else {
89+ screenName = qApp->primaryScreen ()->name ();
90+ }
91+ }
92+ qCDebug (logDdeIntegration) << " Getting wallpaper for screen:" << screenName;
6493 QDBusPendingReply<QString> async = m_dbusAppearanceIface->GetCurrentWorkspaceBackgroundForMonitor (screenName);
6594 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher (async, this );
6695 connect (watcher, &QDBusPendingCallWatcher::finished, this , [this ](QDBusPendingCallWatcher* call){
6796 QDBusPendingReply<QString> reply = *call;
97+ call->deleteLater ();
6898 if (reply.isError ()) {
6999 qCWarning (logDdeIntegration) << " Cannot get wallpaper from dbus:" << reply.error ();
70100 } else {
71101 QUrl wallpaperUrl (reply.value ());
72102 qCDebug (logDdeIntegration) << " Got wallpaper URL from dbus:" << wallpaperUrl;
73103
74104 if (m_wallpaperBlurMap.contains (wallpaperUrl)) {
75- m_wallpaperBlurhash = m_wallpaperBlurMap.value (wallpaperUrl);
76- emit wallpaperBlurhashChanged ();
105+ QString newBlurhash = m_wallpaperBlurMap.value (wallpaperUrl);
106+ if (m_wallpaperBlurhash != newBlurhash) {
107+ m_wallpaperBlurhash = newBlurhash;
108+ emit wallpaperBlurhashChanged ();
109+ }
77110 } else {
78111 qCDebug (logDdeIntegration) << " No cached blurhash found, updating all wallpapers" ;
79112 // try update new workspace background image
@@ -97,18 +130,15 @@ void Appearance::updateAllWallpaper()
97130 qCWarning (logDdeIntegration) << " Wallpaper document is not a JSON object" ;
98131 return ;
99132 }
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
108133
134+ QJsonObject jsonObj = doc.object ();
135+
136+ // Iterate through all keys in the JSON object to get wallpapers for all screens
137+ // Keys are in format "ScreenName&&WorkspaceIndex" (e.g., "eDP-1&&1", "HDMI-1&&1")
138+ for (auto it = jsonObj.begin (); it != jsonObj.end (); ++it) {
139+ QJsonValue v = it.value ();
109140 if (!v.isString ()) {
110- qCDebug (logDdeIntegration) << " No more wallpapers found at key:" << k;
111- break ;
141+ continue ;
112142 }
113143
114144 QUrl wallpaperUrl (v.toString ());
@@ -146,7 +176,7 @@ void Appearance::updateAllWallpaper()
146176 });
147177
148178 m_blurhashWatchers << watcher;
149- } while ( 1 );
179+ }
150180}
151181
152182qreal Appearance::opacity () const
0 commit comments