@@ -23,6 +23,7 @@
24#include <unity/shell/application/ApplicationInfoInterface.h>
24#include <unity/shell/application/ApplicationInfoInterface.h>
25#include <unity/shell/application/MirSurfaceListInterface.h>
25#include <unity/shell/application/MirSurfaceListInterface.h>
26+#include <unity/shell/application/MirSurfaceInterface.h>
27#include <QDesktopServices>
28#include <QDesktopServices>
28#include <QDebug>
29#include <QDebug>
@@ -540,15 +541,29 @@ void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
540 m_list.append(item);
541 m_list.append(item);
541 endInsertRows();
542 endInsertRows();
543− connect(app, &ApplicationInfoInterface::surfaceCountChanged, this, &LauncherModel::applicationSurfaceCountChanged);
544+ connect(app, &ApplicationInfoInterface::surfaceCountChanged, this, &LauncherModel::updateSurfaceList);
544 m_asAdapter->syncItems(m_list);
545 m_asAdapter->syncItems(m_list);
545 Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleRunning});
546 Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleRunning});
548−void LauncherModel::applicationSurfaceCountChanged(int count)
549+void LauncherModel::updateSurfaceList()
551 ApplicationInfoInterface *app = static_cast<ApplicationInfoInterface*>(sender());
551 ApplicationInfoInterface *app = static_cast<ApplicationInfoInterface*>(sender());
552+ updateSurfaceListForApp(app);
555+void LauncherModel::updateSurfaceListForSurface()
557+ MirSurfaceInterface *iface = static_cast<MirSurfaceInterface*>(sender());
558+ ApplicationInfoInterface* app = m_appManager->findApplication(iface->appId());
562+ updateSurfaceListForApp(app);
565+void LauncherModel::updateSurfaceListForApp(ApplicationInfoInterface* app)
552 int idx = findApplication(app->appId());
567 int idx = findApplication(app->appId());
553 if (idx < 0) {
568 if (idx < 0) {
554 qWarning() << "Received a surface count changed event from an app that's not in the Launcher model";
569 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)
558 QList<QPair<QString, QString> > surfaces;
573 QList<QPair<QString, QString> > surfaces;
559 for (int i = 0; i < app->surfaceList()->count(); ++i) {
574 for (int i = 0; i < app->surfaceList()->count(); ++i) {
560 MirSurfaceInterface* iface = app->surfaceList()->get(i);
575 MirSurfaceInterface* iface = app->surfaceList()->get(i);
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()) {
561− surfaces.append({iface->persistentId(), iface->name()});
583+ surfaces.append({iface->persistentId(), name});
563 item->setSurfaces(surfaces);
585 item->setSurfaces(surfaces);
564 Q_EMIT dataChanged(index(idx), index(idx), {RoleSurfaceCount});
586 Q_EMIT dataChanged(index(idx), index(idx), {RoleSurfaceCount});
@@ -582,7 +604,7 @@ void LauncherModel::applicationRemoved(const QModelIndex &parent, int row)
585− disconnect(app, &ApplicationInfoInterface::surfaceCountChanged, this, &LauncherModel::applicationSurfaceCountChanged);
607+ disconnect(app, &ApplicationInfoInterface::surfaceCountChanged, this, &LauncherModel::updateSurfaceList);
587 LauncherItem * item = m_list.at(appIndex);
609 LauncherItem * item = m_list.at(appIndex);