@@ -25,6 +25,7 @@
2525#include "asadapter.h"
2626
2727#include <unity/shell/application/ApplicationInfoInterface.h>
28+#include <unity/shell/application/MirSurfaceListInterface.h>
2829
2930#include <QDesktopServices>
3031#include <QDebug>
@@ -88,6 +89,8 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
8889 return item->alerting();
8990 case RoleRunning:
9091 return item->running();
92+ case RoleSurfaceCount:
93+ return item->surfaceCount();
9194 default:
9295 qWarning() << Q_FUNC_INFO << "missing role, implement me";
9396 return QVariant();
@@ -96,18 +99,6 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
9699 return QVariant();
97100}
98101
99−void LauncherModel::setAlerting(const QString &appId, bool alerting) {
100− int index = findApplication(appId);
101− if (index >= 0) {
102− QModelIndex modelIndex = this->index(index);
103− LauncherItem *item = m_list.at(index);
104− if (!item->focused()) {
105− item->setAlerting(alerting);
106− Q_EMIT dataChanged(modelIndex, modelIndex, {RoleAlerting});
107− }
108− }
109−}
110−
111102unity::shell::launcher::LauncherItemInterface *LauncherModel::get(int index) const
112103{
113104 if (index < 0 || index >= m_list.count()) {
@@ -358,11 +349,13 @@ void LauncherModel::countChanged(const QString &appId, int count)
358349 if (idx >= 0) {
359350 LauncherItem *item = m_list.at(idx);
360351 item->setCount(count);
361− if (item->countVisible()) {
362− setAlerting(item->appId(), true);
352+ QVector<int> changedRoles = {RoleCount};
353+ if (item->countVisible() && !item->alerting() && !item->focused()) {
354+ changedRoles << RoleAlerting;
355+ item->setAlerting(true);
363356 }
364357 m_asAdapter->syncItems(m_list);
365− Q_EMIT dataChanged(index(idx), index(idx), {RoleCount});
358+ Q_EMIT dataChanged(index(idx), index(idx), changedRoles);
366359 }
367360}
368361
@@ -372,10 +365,12 @@ void LauncherModel::countVisibleChanged(const QString &appId, bool countVisible)
372365 if (idx >= 0) {
373366 LauncherItem *item = m_list.at(idx);
374367 item->setCountVisible(countVisible);
375− if (countVisible) {
376− setAlerting(item->appId(), true);
368+ QVector<int> changedRoles = {RoleCount};
369+ if (countVisible && !item->alerting() && !item->focused()) {
370+ changedRoles << RoleAlerting;
371+ item->setAlerting(true);
377372 }
378− Q_EMIT dataChanged(index(idx), index(idx), {RoleCountVisible});
373+ Q_EMIT dataChanged(index(idx), index(idx), changedRoles);
379374
380375 // If countVisible goes to false, and the item is neither pinned nor recent we can drop it
381376 if (!countVisible && !item->pinned() && !item->recent()) {
@@ -498,8 +493,10 @@ void LauncherModel::alert(const QString &appId)
498493 int idx = findApplication(appId);
499494 if (idx >= 0) {
500495 LauncherItem *item = m_list.at(idx);
501− setAlerting(item->appId(), true);
502− Q_EMIT dataChanged(index(idx), index(idx), {RoleAlerting});
496+ if (!item->focused() && !item->alerting()) {
497+ item->setAlerting(true);
498+ Q_EMIT dataChanged(index(idx), index(idx), {RoleAlerting});
499+ }
503500 }
504501}
505502
@@ -525,28 +522,50 @@ void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
525522 item->setRecent(true);
526523 Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleRecent});
527524 }
525+ if (item->surfaceCount() != app->surfaceCount()) {
526+ item->setSurfaceCount(app->surfaceCount());
527+ Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleSurfaceCount});
528+ }
529+
528530 item->setRunning(true);
529531 } else {
530532 LauncherItem *item = new LauncherItem(app->appId(), app->name(), app->icon().toString(), this);
531533 item->setRecent(true);
532534 item->setRunning(true);
533535 item->setFocused(app->focused());
534−
536+ item->setSurfaceCount(app->surfaceCount());
535537 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
536538 m_list.append(item);
537539 endInsertRows();
538540 }
541+ connect(app, &ApplicationInfoInterface::surfaceCountChanged, this, &LauncherModel::applicationSurfaceCountChanged);
539542 m_asAdapter->syncItems(m_list);
540543 Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleRunning});
541544}
542545
546+void LauncherModel::applicationSurfaceCountChanged(int count)
547+{
548+ ApplicationInfoInterface *app = static_cast<ApplicationInfoInterface*>(sender());
549+ int idx = findApplication(app->appId());
550+ if (idx < 0) {
551+ qWarning() << "Received a surface count changed event from an app that's not in the Launcher model";
552+ return;
553+ }
554+ LauncherItem *item = m_list.at(idx);
555+ if (item->surfaceCount() != count) {
556+ item->setSurfaceCount(count);
557+ Q_EMIT dataChanged(index(idx), index(idx), {RoleSurfaceCount});
558+ }
559+}
560+
543561void LauncherModel::applicationRemoved(const QModelIndex &parent, int row)
544562{
545563 Q_UNUSED(parent)
546564
565+ ApplicationInfoInterface *app = m_appManager->get(row);
547566 int appIndex = -1;
548567 for (int i = 0; i < m_list.count(); ++i) {
549− if (m_list.at(i)->appId() == m_appManager->get(row)->appId()) {
568+ if (m_list.at(i)->appId() == app->appId()) {
550569 appIndex = i;
551570 break;
552571 }
@@ -557,17 +576,24 @@ void LauncherModel::applicationRemoved(const QModelIndex &parent, int row)
557576 return;
558577 }
559578
579+ disconnect(app, &ApplicationInfoInterface::surfaceCountChanged, this, &LauncherModel::applicationSurfaceCountChanged);
580+
560581 LauncherItem * item = m_list.at(appIndex);
561− item->setRunning(false);
562582
563583 if (!item->pinned()) {
564584 beginRemoveRows(QModelIndex(), appIndex, appIndex);
565585 m_list.takeAt(appIndex)->deleteLater();
566586 endRemoveRows();
567587 m_asAdapter->syncItems(m_list);
568− Q_EMIT dataChanged(index(appIndex), index(appIndex), {RolePinned});
588+ } else {
589+ QVector<int> changedRoles = {RoleRunning};
590+ item->setRunning(false);
591+ if (item->focused()) {
592+ changedRoles << RoleFocused;
593+ item->setFocused(false);
594+ }
595+ Q_EMIT dataChanged(index(appIndex), index(appIndex), changedRoles);
569596 }
570− Q_EMIT dataChanged(index(appIndex), index(appIndex), {RoleRunning});
571597}
572598
573599void LauncherModel::focusedAppIdChanged()
@@ -576,8 +602,14 @@ void LauncherModel::focusedAppIdChanged()
576602 for (int i = 0; i < m_list.count(); ++i) {
577603 LauncherItem *item = m_list.at(i);
578604 if (!item->focused() && item->appId() == appId) {
605+ QVector<int> changedRoles;
606+ changedRoles << RoleFocused;
579607 item->setFocused(true);
580− Q_EMIT dataChanged(index(i), index(i), {RoleFocused});
608+ if (item->alerting()) {
609+ changedRoles << RoleAlerting;
610+ item->setAlerting(false);
611+ }
612+ Q_EMIT dataChanged(index(i), index(i), changedRoles);
581613 } else if (item->focused() && item->appId() != appId) {
582614 item->setFocused(false);
583615 Q_EMIT dataChanged(index(i), index(i), {RoleFocused});