Skip to content

Commit 6529fa5

Browse files
pengfeixxdeepin-bot[bot]
authored andcommitted
fix: Fix the issue where the launcher fullscreen background doesn't change
Fix the issue where the launcher fullscreen background doesn't change Log: Fix the issue where the launcher fullscreen background doesn't change pms: BUG-343521
1 parent 17762bf commit 6529fa5

4 files changed

Lines changed: 66 additions & 15 deletions

File tree

launchercontroller.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,20 @@ void LauncherController::setCurrentFrame(const QString &frame)
156156
emit currentFrameChanged();
157157
}
158158

159+
QString LauncherController::currentScreen() const
160+
{
161+
return m_currentScreen;
162+
}
163+
164+
void LauncherController::setCurrentScreen(const QString &screen)
165+
{
166+
if (m_currentScreen == screen) return;
167+
168+
m_currentScreen = screen;
169+
qCInfo(logController) << "Current screen changed to:" << m_currentScreen;
170+
emit currentScreenChanged();
171+
}
172+
159173
// We need to hide the launcher when it lost focus, but clicking the launcher icon on the taskbar/dock will also trigger
160174
// `Toggle()`, which will show the launcher even if it just get hid caused by losting focus. Thus, we added a timer to
161175
// mark it as we just hide it, and check if the timer is running while calling `Toggle()`. This function will do nothing

launchercontroller.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class LauncherController : public QObject
1717

1818
Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
1919
Q_PROPERTY(QString currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY currentFrameChanged)
20+
Q_PROPERTY(QString currentScreen READ currentScreen WRITE setCurrentScreen NOTIFY currentScreenChanged)
2021

2122
QML_NAMED_ELEMENT(LauncherController)
2223
QML_SINGLETON
@@ -45,6 +46,8 @@ class LauncherController : public QObject
4546
bool isFullScreenFrame() const;
4647
QString currentFrame() const;
4748
void setCurrentFrame(const QString & frame);
49+
QString currentScreen() const;
50+
void setCurrentScreen(const QString & screen);
4851

4952
Q_INVOKABLE void hideWithTimer();
5053
Q_INVOKABLE void setAvoidHide(bool avoidHide);
@@ -57,6 +60,7 @@ class LauncherController : public QObject
5760

5861
signals:
5962
void currentFrameChanged();
63+
void currentScreenChanged();
6064
void visibleChanged(bool visible);
6165

6266
public:
@@ -83,6 +87,7 @@ class LauncherController : public QObject
8387
Launcher1Adaptor * m_launcher1Adaptor;
8488
bool m_visible;
8589
QString m_currentFrame;
90+
QString m_currentScreen;
8691
bool m_pendingHide = false;
8792
bool m_avoidHide = true;
8893
};

qml/Main.qml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ QtObject {
143143
windowedFrame.requestActivate()
144144
} else {
145145
fullscreenFrame.requestActivate()
146+
// Update current screen for wallpaper blur based on the screen where launcher is displayed
147+
var currentScreen = fullscreenFrame.screen
148+
if (currentScreen) {
149+
LauncherController.currentScreen = currentScreen.name
150+
}
146151
}
147152
}
148153

@@ -315,7 +320,14 @@ QtObject {
315320

316321
onVisibleChanged: {
317322
if (visible) {
318-
requestActivate()
323+
updateWindowVisibilityAndPosition()
324+
}
325+
}
326+
327+
onScreenChanged: {
328+
// Update current screen when the window moves to a different screen
329+
if (screen) {
330+
LauncherController.currentScreen = screen.name
319331
}
320332
}
321333

src/ddeintegration/appearance.cpp

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
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

1618
Q_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

152172
qreal Appearance::opacity() const

0 commit comments

Comments
 (0)