Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions src/ddeintegration/appearance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,35 @@
return;
}

// Use the current screen where the launcher is displayed
// Priority: 1. LauncherController.currentScreen, 2. Dock position, 3. Cursor position, 4. Primary screen
QString screenName = LauncherController::instance().currentScreen();
if (screenName.isEmpty()) {
// Try to get screen from dock position (launcher opens on the same screen as dock)
QRect dockGeometry = DesktopIntegration::instance().dockGeometry();
if (dockGeometry.isValid() && dockGeometry.x() >= 0) {
QPoint dockCenter = dockGeometry.center();
QScreen *screenAtDock = qApp->screenAt(dockCenter);
if (screenAtDock) {
screenName = screenAtDock->name();
}
// TODO: LauncherController.currentScreen is sometimes empty when read here (QML sets it from dock later),
// so we fallback to dock geometry / cursor / primary. In practice we always hit dockGeometry; currentScreen
// and dock are the same logical source. Could simplify to use only dock geometry first if desired.
auto screenByName = [](const QString &name) -> QScreen * {
if (name.isEmpty())
return nullptr;
for (QScreen *s : qApp->screens()) {
if (s && s->name() == name)

Check warning on line 75 in src/ddeintegration/appearance.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Consider using std::find_if algorithm instead of a raw loop.
return s;
}
return nullptr;
};
QString requestedScreenName = LauncherController::instance().currentScreen();
QScreen *targetScreen = screenByName(requestedScreenName);
if (!targetScreen) {
QRect dockGeometry = DesktopIntegration::instance().dockGeometry();
if (dockGeometry.isValid() && dockGeometry.width() > 0 && dockGeometry.height() > 0)
targetScreen = qApp->screenAt(dockGeometry.center());
}
if (!targetScreen)
targetScreen = qApp->screenAt(QCursor::pos());
if (!targetScreen)
targetScreen = QGuiApplication::primaryScreen();
Comment on lines +71 to +90
Copy link
Member

@BLumia BLumia Feb 2, 2026

Choose a reason for hiding this comment

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

看这里写了反复多次检查,看上去意思是之前 LauncherController::instance().currentScreen() 返回的结果可能是个无效的屏幕名称?如果是的话,是不是应该看为什么 LauncherController::instance().currentScreen() 会返回无效的名称?

可以问问 @pengfeixx

QString screenName = targetScreen ? targetScreen->name() : QString();
if (screenName.isEmpty() || !m_dbusAppearanceIface->isValid())
return;
qCDebug(logDdeIntegration) << "Getting wallpaper for screen:" << screenName;
QDBusPendingReply<QString> async = m_dbusAppearanceIface->GetCurrentWorkspaceBackgroundForMonitor(screenName);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this);

Check warning on line 96 in src/ddeintegration/appearance.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'watcher' can be declared as pointer to const
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher* call){
QDBusPendingReply<QString> reply = *call;
if (reply.isError()) {
Expand Down