Commit 98390b63 authored by David Redondo's avatar David Redondo 🏎
Browse files

WidgetExplorer: Only count applets in visible Containments

Currently the applet count is filtered by activity. But for every activity all
applets in all known screens/containments are counted. If a user switches
screens regularly they will see for example that there are 7 instances of the
clock applet even though they have less screens and only one instance in their
current panel(s). This information is not useful to the user because they cannot
interact with the not visible  applets in any way.
parent 44607de8
......@@ -80,9 +80,12 @@ public:
void initFilters();
void initRunningApplets();
void screenAdded(int screen);
void screenRemoved(int screen);
void containmentDestroyed();
void addContainment(Containment *containment);
void removeContainment(Containment *containment);
/**
* Tracks a new running applet
......@@ -255,24 +258,49 @@ void WidgetExplorerPrivate::initRunningApplets()
qWarning() << "WidgetExplorer failed to find corona";
return;
}
appletNames.clear();
runningApplets.clear();
QObject::connect(c, &Plasma::Corona::screenAdded, q, [this] (int screen) {screenAdded(screen);});
QObject::connect(c, &Plasma::Corona::screenRemoved, q, [this] (int screen) {screenRemoved(screen);});
const QList<Containment*> containments = c->containments();
for (Containment *containment : containments) {
if (containment->containmentType() == Plasma::Types::DesktopContainment
&& containment->activity() != activitiesConsumer->currentActivity()) {
continue;
}
addContainment(containment);
if (containment->screen() != -1) {
addContainment(containment);
}
}
//qDebug() << runningApplets;
itemModel.setRunningApplets(runningApplets);
}
void WidgetExplorerPrivate::screenAdded(int screen)
{
const QList<Containment*> containments = containment->corona()->containments();
for (auto c : containments) {
if (c->screen() == screen) {
addContainment(c);
}
}
itemModel.setRunningApplets(runningApplets);
}
void WidgetExplorerPrivate::screenRemoved(int screen)
{
const QList<Containment*> containments = containment->corona()->containments();
for (auto c : containments) {
if (c->lastScreen() == screen) {
removeContainment(c);
}
}
itemModel.setRunningApplets(runningApplets);
}
void WidgetExplorerPrivate::addContainment(Containment *containment)
{
QObject::connect(containment, SIGNAL(appletAdded(Plasma::Applet*)), q, SLOT(appletAdded(Plasma::Applet*)));
......@@ -291,6 +319,22 @@ void WidgetExplorerPrivate::addContainment(Containment *containment)
}
}
void WidgetExplorerPrivate::removeContainment(Plasma::Containment *containment)
{
containment->disconnect(q);
const QList<Applet*> applets = containment->applets();
for (auto applet : applets) {
if (applet->pluginMetaData().isValid()) {
Containment *childContainment = applet->property("containment").value<Containment*>();
if (childContainment) {
removeContainment(childContainment);
}
runningApplets[applet->pluginMetaData().pluginId()]--;
}
}
}
void WidgetExplorerPrivate::containmentDestroyed()
{
containment = nullptr;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment