1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 01:33:50 +03:00

support screen changes for offline containments

This commit is contained in:
Michail Vourlakos 2021-04-13 10:56:15 +03:00
parent 2b754dde97
commit 050b454b5a
5 changed files with 89 additions and 23 deletions

View File

@ -925,7 +925,6 @@ int Corona::screenForContainment(const Plasma::Containment *containment) const
// screen:0 and primaryScreen
//case in which this containment is child of an applet, hello systray :)
if (Plasma::Applet *parentApplet = qobject_cast<Plasma::Applet *>(containment->parent())) {
if (Plasma::Containment *cont = parentApplet->containment()) {
return screenForContainment(cont);
@ -935,29 +934,13 @@ int Corona::screenForContainment(const Plasma::Containment *containment) const
}
Plasma::Containment *c = const_cast<Plasma::Containment *>(containment);
Latte::View *view = m_layoutsManager->synchronizer()->viewForContainment(c);
int scrId = m_layoutsManager->synchronizer()->screenForContainment(c);
if (view && view->screen()) {
return m_screenPool->id(view->screen()->name());
if (scrId >= 0) {
return scrId;
}
//Failed? fallback on lastScreen()
//lastScreen() is the correct screen for panels
//It is also correct for desktops *that have the correct activity()*
//a containment with lastScreen() == 0 but another activity,
//won't be associated to a screen
// qDebug() << "ShellCorona screenForContainment: " << containment << " Last screen is " << containment->lastScreen();
for (auto screen : qGuiApp->screens()) {
// containment->lastScreen() == m_screenPool->id(screen->name()) to check if the lastScreen refers to a screen that exists/it's known
if (containment->lastScreen() == m_screenPool->id(screen->name()) &&
(containment->activity() == m_activitiesConsumer->currentActivity() ||
containment->containmentType() == Plasma::Types::PanelContainment || containment->containmentType() == Plasma::Types::CustomPanelContainment)) {
return containment->lastScreen();
}
}
return -1;
return containment->lastScreen();
}
void Corona::showAlternativesForApplet(Plasma::Applet *applet)

View File

@ -393,6 +393,45 @@ Plasma::Containment *GenericLayout::containmentForId(uint id) const
return nullptr;
}
bool GenericLayout::contains(Plasma::Containment *containment) const
{
return m_containments.contains(containment);
}
int GenericLayout::screenForContainment(Plasma::Containment *containment)
{
if (!containment) {
return -1;
}
//! there is a pending update
QString containmentid = QString::number(containment->id());
if (m_pendingContainmentUpdates.containsId(containmentid)) {
if (m_corona && m_pendingContainmentUpdates[containmentid].onPrimary) {
return m_corona->screenPool()->primaryScreenId();
} else {
return m_pendingContainmentUpdates[containmentid].screen;
}
}
//! there is a view present
Latte::View *view{nullptr};
if (m_latteViews.contains(containment)) {
view = m_latteViews[containment];
} else if (m_waitingLatteViews.contains(containment)) {
view = m_waitingLatteViews[containment];
}
if (view && view->screen()) {
return m_corona->screenPool()->id(view->screen()->name());
}
//! fallback scenario
return containment->lastScreen();
}
Latte::View *GenericLayout::viewForContainment(Plasma::Containment *containment) const
{
if (m_containments.contains(containment) && m_latteViews.contains(containment)) {
@ -1322,6 +1361,25 @@ void GenericLayout::syncLatteViewsToScreens(Layout::ViewsMap *occupiedMap)
qDebug() << "LAYOUT ::: " << name();
qDebug() << "screen count changed -+-+ " << qGuiApp->screens().size();
//! Clear up pendingContainmentUpdates when no-needed any more
QStringList clearpendings;
for(int i=0; i<m_pendingContainmentUpdates.rowCount(); ++i) {
auto viewdata = m_pendingContainmentUpdates[i];
auto containment = containmentForId(viewdata.id.toUInt());
if (containment) {
if ((viewdata.onPrimary && containment->lastScreen() == m_corona->screenPool()->primaryScreenId())
|| (!viewdata.onPrimary && containment->lastScreen() == viewdata.screen)) {
clearpendings << viewdata.id;
}
}
}
for(auto pendingid : clearpendings) {
m_pendingContainmentUpdates.remove(pendingid);
}
//! use valid views map based on active screens
Layout::ViewsMap viewsMap = validViewsMap(occupiedMap);
if (occupiedMap != nullptr) {
@ -1528,9 +1586,16 @@ void GenericLayout::updateView(const Latte::Data::View &viewData)
//! active -> inactiveinmemory [viewscenario]
auto containment = containmentForId(viewData.id.toUInt());
if (containment) {
qDebug() << " #$%#$%#%#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
Layouts::Storage::self()->updateView(containment->config(), viewData);
qDebug() << " #22222222222222222222222%%%%%2222222222222%%%%";
//! by using pendingContainmentUpdates we make sure that when containment->screen() will be
//! called though reactToScreenChange() the proper screen will be returned
if (!m_pendingContainmentUpdates.containsId(viewData.id)) {
m_pendingContainmentUpdates << viewData;
} else {
m_pendingContainmentUpdates[viewData.id] = viewData;
}
containment->reactToScreenChange();
}
//! complete update circle and inform the others about the changes

View File

@ -89,6 +89,9 @@ public:
virtual Types::ViewType latteViewType(uint containmentId) const;
const QList<Plasma::Containment *> *containments() const;
bool contains(Plasma::Containment *containment) const;
int screenForContainment(Plasma::Containment *containment);
Latte::View *highestPriorityView();
Latte::View *viewForContainment(uint id) const;
Latte::View *viewForContainment(Plasma::Containment *containment) const;
@ -207,6 +210,9 @@ private:
//! try to avoid crashes from recreating the same views all the time
QList<const Plasma::Containment *> m_viewsToRecreate;
//! Containments that are pending screen/state updates
Latte::Data::ViewsTable m_pendingContainmentUpdates;
friend class Latte::View;
};

View File

@ -377,6 +377,17 @@ Layout::GenericLayout *Synchronizer::layout(QString layoutname) const
return l;
}
int Synchronizer::screenForContainment(Plasma::Containment *containment)
{
for (auto layout : m_centralLayouts) {
if (layout->contains(containment)) {
return layout->screenForContainment(containment);
}
}
return -1;
}
Latte::View *Synchronizer::viewForContainment(uint id)
{
for (auto layout : m_centralLayouts) {

View File

@ -102,6 +102,7 @@ public:
QStringList freeRunningActivities(); //! These are activities that haven't been assigned to specific layout
QStringList validActivities(const QStringList &layoutActivities);
int screenForContainment(Plasma::Containment *containment);
Latte::View *viewForContainment(Plasma::Containment *containment);
Latte::View *viewForContainment(uint id);