@@ -23,6 +23,7 @@
2323
2424#include <unity/shell/application/ApplicationInfoInterface.h>
2525#include <unity/shell/application/MirSurfaceListInterface.h>
26+#include <unity/shell/application/MirSurfaceInterface.h>
2627
2728#include <QDesktopServices>
2829#include <QDebug>
@@ -540,15 +541,29 @@ void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
540541 m_list.append(item);
541542 endInsertRows();
542543 }
543− connect(app, &ApplicationInfoInterface::surfaceCountChanged, this, &LauncherModel::applicationSurfaceCountChanged);
544+ connect(app, &ApplicationInfoInterface::surfaceCountChanged, this, &LauncherModel::updateSurfaceList);
544545 m_asAdapter->syncItems(m_list);
545546 Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleRunning});
546547}
547548
548−void LauncherModel::applicationSurfaceCountChanged(int count)
549+void LauncherModel::updateSurfaceList()
549550{
550− Q_UNUSED(count)
551551 ApplicationInfoInterface *app = static_cast<ApplicationInfoInterface*>(sender());
552+ updateSurfaceListForApp(app);
553+}
554+
555+void LauncherModel::updateSurfaceListForSurface()
556+{
557+ MirSurfaceInterface *iface = static_cast<MirSurfaceInterface*>(sender());
558+ ApplicationInfoInterface* app = m_appManager->findApplication(iface->appId());
559+ if (!app) {
560+ return;
561+ }
562+ updateSurfaceListForApp(app);
563+}
564+
565+void LauncherModel::updateSurfaceListForApp(ApplicationInfoInterface* app)
566+{
552567 int idx = findApplication(app->appId());
553568 if (idx < 0) {
554569 qWarning() << "Received a surface count changed event from an app that's not in the Launcher model";
@@ -558,7 +573,14 @@ void LauncherModel::applicationSurfaceCountChanged(int count)
558573 QList<QPair<QString, QString> > surfaces;
559574 for (int i = 0; i < app->surfaceList()->count(); ++i) {
560575 MirSurfaceInterface* iface = app->surfaceList()->get(i);
561− surfaces.append({iface->persistentId(), iface->name()});
576+ // Avoid duplicate connections, so let's just disconnect first to be sure
577+ disconnect(iface, &MirSurfaceInterface::nameChanged, this, &LauncherModel::updateSurfaceListForSurface);
578+ connect(iface, &MirSurfaceInterface::nameChanged, this, &LauncherModel::updateSurfaceListForSurface);
579+ QString name = iface->name();
580+ if (name.isEmpty()) {
581+ name = app->name();
582+ }
583+ surfaces.append({iface->persistentId(), name});
562584 }
563585 item->setSurfaces(surfaces);
564586 Q_EMIT dataChanged(index(idx), index(idx), {RoleSurfaceCount});
@@ -582,7 +604,7 @@ void LauncherModel::applicationRemoved(const QModelIndex &parent, int row)
582604 return;
583605 }
584606
585− disconnect(app, &ApplicationInfoInterface::surfaceCountChanged, this, &LauncherModel::applicationSurfaceCountChanged);
607+ disconnect(app, &ApplicationInfoInterface::surfaceCountChanged, this, &LauncherModel::updateSurfaceList);
586608
587609 LauncherItem * item = m_list.at(appIndex);
588610