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

fixes for corona available areas calcs

This commit is contained in:
Michail Vourlakos 2020-08-25 19:30:33 +03:00
parent 951668fff9
commit 9026f931fd
9 changed files with 134 additions and 89 deletions

View File

@ -507,14 +507,8 @@ CentralLayout *Corona::centralLayout(QString name) const
{
CentralLayout *result{nullptr};
if (name.isEmpty()) {
result = m_layoutsManager->currentLayout();
} else {
CentralLayout *tempCentral = m_layoutsManager->synchronizer()->centralLayout(name);
if (tempCentral) {
result = tempCentral;
}
if (!name.isEmpty()) {
result = m_layoutsManager->synchronizer()->centralLayout(name);
}
return result;
@ -524,14 +518,8 @@ Layout::GenericLayout *Corona::layout(QString name) const
{
Layout::GenericLayout *result{nullptr};
if (name.isEmpty()) {
result = m_layoutsManager->currentLayout();
} else {
if (!name.isEmpty()) {
result = m_layoutsManager->synchronizer()->layout(name);
if (!result) {
result = m_layoutsManager->currentLayout();
}
}
return result;
@ -543,14 +531,14 @@ QRegion Corona::availableScreenRegion(int id) const
}
QRegion Corona::availableScreenRegionWithCriteria(int id,
QString forLayout,
QString layoutName,
QList<Types::Visibility> ignoreModes,
QList<Plasma::Types::Location> ignoreEdges,
bool ignoreExternalPanels,
bool desktopUse) const
{
const QScreen *screen = m_screenPool->screenForId(id);
CentralLayout *layout = centralLayout(forLayout);
bool inCurrentLayouts{layoutName.isEmpty()};
if (!screen) {
return {};
@ -558,7 +546,7 @@ QRegion Corona::availableScreenRegionWithCriteria(int id,
QRegion available = ignoreExternalPanels ? screen->geometry() : screen->availableGeometry();
if (!layout) {
if (!centralLayout(layoutName) && !inCurrentLayouts) {
return available;
}
@ -572,7 +560,14 @@ QRegion Corona::availableScreenRegionWithCriteria(int id,
}
bool allEdges = ignoreEdges.isEmpty();
QList<Latte::View *> views = layout->latteViews();
QList<Latte::View *> views;
if (inCurrentLayouts) {
views = m_layoutsManager->synchronizer()->currentViews();
} else {
CentralLayout *central = centralLayout(layoutName);
views = central->latteViews();
}
for (const auto *view : views) {
if (view && view->containment() && view->screen() == screen
@ -730,14 +725,14 @@ QRect Corona::availableScreenRect(int id) const
}
QRect Corona::availableScreenRectWithCriteria(int id,
QString forLayout,
QString layoutName,
QList<Types::Visibility> ignoreModes,
QList<Plasma::Types::Location> ignoreEdges,
bool ignoreExternalPanels,
bool desktopUse) const
{
const QScreen *screen = m_screenPool->screenForId(id);
CentralLayout *layout = centralLayout(forLayout);
bool inCurrentLayouts{layoutName.isEmpty()};
if (!screen) {
return {};
@ -745,7 +740,7 @@ QRect Corona::availableScreenRectWithCriteria(int id,
QRect available = ignoreExternalPanels ? screen->geometry() : screen->availableGeometry();
if (!layout) {
if (!centralLayout(layoutName) && !inCurrentLayouts) {
return available;
}
@ -759,7 +754,14 @@ QRect Corona::availableScreenRectWithCriteria(int id,
}
bool allEdges = ignoreEdges.isEmpty();
QList<Latte::View *> views = layout->latteViews();
QList<Latte::View *> views;
if (inCurrentLayouts) {
views = m_layoutsManager->synchronizer()->currentViews();
} else {
CentralLayout *central = centralLayout(layoutName);
views = central->latteViews();
}
for (const auto *view : views) {
if (view && view->containment() && view->screen() == screen
@ -1194,11 +1196,10 @@ QStringList Corona::contextMenuData()
{
QStringList data;
Types::ViewType viewType{Types::DockView};
auto view = m_layoutsManager->synchronizer()->viewForContainment(m_contextMenuViewId);
Latte::CentralLayout *currentLayout = m_layoutsManager->currentLayout();
if (currentLayout) {
viewType = currentLayout->latteViewType(m_contextMenuViewId);
if (view) {
viewType = view->type();
}
data << QString::number((int)m_layoutsManager->memoryUsage());
@ -1234,10 +1235,16 @@ void Corona::setBroadcastedBackgroundsEnabled(QString activity, QString screenNa
void Corona::toggleHiddenState(QString layoutName, QString screenName, int screenEdge)
{
Layout::GenericLayout *gLayout = layout(layoutName);
if (layoutName.isEmpty()) {
for(auto layout : m_layoutsManager->currentLayouts()) {
layout->toggleHiddenState(screenName, (Plasma::Types::Location)screenEdge);
}
} else {
Layout::GenericLayout *gLayout = layout(layoutName);
if (gLayout) {
gLayout->toggleHiddenState(screenName, (Plasma::Types::Location)screenEdge);
if (gLayout) {
gLayout->toggleHiddenState(screenName, (Plasma::Types::Location)screenEdge);
}
}
}

View File

@ -117,14 +117,14 @@ public:
//! arguments mean that all choices are accepted in calculations. ignoreExternalPanels means that
//! external panels should be not considered in the calculations
QRect availableScreenRectWithCriteria(int id,
QString forLayout = QString(),
QString layoutName = QString(),
QList<Types::Visibility> ignoreModes = QList<Types::Visibility>(),
QList<Plasma::Types::Location> ignoreEdges = QList<Plasma::Types::Location>(),
bool ignoreExternalPanels = true,
bool desktopUse = false) const;
QRegion availableScreenRegionWithCriteria(int id,
QString forLayout = QString(),
QString layoutName = QString(),
QList<Types::Visibility> ignoreModes = QList<Types::Visibility>(),
QList<Plasma::Types::Location> ignoreEdges = QList<Plasma::Types::Location>(),
bool ignoreExternalPanels = true,

View File

@ -370,6 +370,17 @@ void GenericLayout::setLastConfigViewFor(Latte::View *view)
emit lastConfigViewForChanged(view);
}
Latte::View *GenericLayout::viewForContainment(uint id) const
{
for(auto view : m_latteViews) {
if (view && view->containment()->id() == id) {
return view;
}
}
return nullptr;
}
Latte::View *GenericLayout::viewForContainment(Plasma::Containment *containment) const
{
if (m_containments.contains(containment) && m_latteViews.contains(containment)) {
@ -384,9 +395,14 @@ QList<Latte::View *> GenericLayout::latteViews()
return m_latteViews.values();
}
QList<Latte::View *> GenericLayout::sortedLatteViews()
{
return sortedLatteViews(latteViews());
}
QList<Latte::View *> GenericLayout::sortedLatteViews(QList<Latte::View *> views)
{
QList<Latte::View *> sortedViews = views.isEmpty() ? latteViews() : views;
QList<Latte::View *> sortedViews = views;
qDebug() << " -------- ";

View File

@ -98,8 +98,14 @@ public:
const QList<Plasma::Containment *> *containments() const;
Latte::View *highestPriorityView();
Latte::View *viewForContainment(uint id) const;
Latte::View *viewForContainment(Plasma::Containment *containment) const;
virtual QList<Latte::View *> sortedLatteViews(QList<Latte::View *> views = QList<Latte::View *>());
static bool viewAtLowerScreenPriority(Latte::View *test, Latte::View *base);
static bool viewAtLowerEdgePriority(Latte::View *test, Latte::View *base);
static QList<Latte::View *> sortedLatteViews(QList<Latte::View *> views);
QList<Latte::View *> sortedLatteViews();
virtual QList<Latte::View *> viewsWithPlasmaShortcuts();
virtual QList<Latte::View *> latteViews();
ViewsMap validViewsMap(ViewsMap *occupiedMap = nullptr);
@ -184,9 +190,6 @@ private:
bool explicitDockOccupyEdge(int screen, Plasma::Types::Location location) const;
bool primaryDockOccupyEdge(Plasma::Types::Location location) const;
bool viewAtLowerScreenPriority(Latte::View *test, Latte::View *base);
bool viewAtLowerEdgePriority(Latte::View *test, Latte::View *base);
bool viewDataAtLowerEdgePriority(const ViewData &test, const ViewData &base) const;
bool viewDataAtLowerScreenPriority(const ViewData &test, const ViewData &base) const;
bool viewDataAtLowerStatePriority(const ViewData &test, const ViewData &base) const;

View File

@ -178,9 +178,9 @@ QStringList Manager::centralLayoutsNames()
return m_synchronizer->centralLayoutsNames();
}
CentralLayout *Manager::currentLayout() const
QList<CentralLayout *> Manager::currentLayouts() const
{
return m_synchronizer->currentLayout();
return m_synchronizer->currentLayouts();
}
bool Manager::switchToLayout(QString layoutName, int previousMemoryUsage)

View File

@ -98,7 +98,7 @@ public:
void setMemoryUsage(MemoryUsage::LayoutsMemory memoryUsage);
//! returns the current and central layout based on activities and user preferences
CentralLayout *currentLayout() const;
QList<CentralLayout *>currentLayouts() const;
LaunchersSignals *launchersSignals() const;
Synchronizer *synchronizer() const;

View File

@ -241,25 +241,49 @@ CentralLayout *Synchronizer::centralLayout(QString id) const
return nullptr;
}
CentralLayout *Synchronizer::currentLayout() const
QList<CentralLayout *> Synchronizer::currentLayouts() const
{
QList<CentralLayout *> layouts;
if (m_manager->memoryUsage() == MemoryUsage::SingleLayout) {
return m_centralLayouts.at(0);
layouts << m_centralLayouts.at(0);
} else {
for (auto layout : m_centralLayouts) {
if (layout->activities().contains(m_manager->corona()->activitiesConsumer()->currentActivity())) {
return layout;
}
}
for (auto layout : m_centralLayouts) {
if (layout->activities().isEmpty()) {
return layout;
if (layout->isOnAllActivities() || layout->appliedActivities().contains(m_manager->corona()->activitiesConsumer()->currentActivity())) {
layouts << layout;
}
}
}
return nullptr;
return layouts;
}
QList<Latte::View *> Synchronizer::currentViews() const
{
QList<Latte::View *> views;
for(auto layout : currentLayouts()) {
views << layout->latteViews();
}
return views;
}
QList<Latte::View *> Synchronizer::currentViewsWithPlasmaShortcuts() const
{
QList<Latte::View *> views;
for(auto layout : currentLayouts()) {
views << layout->viewsWithPlasmaShortcuts();
}
return views;
}
QList<Latte::View *> Synchronizer::sortedCurrentViews() const
{
QList<Latte::View *> views = currentViews();
return Layout::GenericLayout::sortedLatteViews(views);
}
Layout::GenericLayout *Synchronizer::layout(QString id) const
@ -269,6 +293,19 @@ Layout::GenericLayout *Synchronizer::layout(QString id) const
return l;
}
Latte::View *Synchronizer::viewForContainment(uint id)
{
for (auto layout : m_centralLayouts) {
Latte::View *view = layout->viewForContainment(id);
if (view) {
return view;
}
}
return nullptr;
}
Latte::View *Synchronizer::viewForContainment(Plasma::Containment *containment)
{
for (auto layout : m_centralLayouts) {

View File

@ -99,8 +99,13 @@ public:
QStringList freeActivities(); //! These are activities that haven't been assigned to specific layout
Latte::View *viewForContainment(Plasma::Containment *containment);
Latte::View *viewForContainment(uint id);
QList<CentralLayout *> currentLayouts() const;
QList<Latte::View *> currentViews() const;
QList<Latte::View *> currentViewsWithPlasmaShortcuts() const;
QList<Latte::View *> sortedCurrentViews() const;
CentralLayout *currentLayout() const;
CentralLayout *centralLayout(QString id) const;
Layout::GenericLayout *layout(QString id) const;

View File

@ -244,12 +244,7 @@ void GlobalShortcuts::activateLauncherMenu()
return;
}
QList<Latte::View *> sortedViews;
CentralLayout *currentLayout = m_corona->layoutsManager()->currentLayout();
if (currentLayout) {
sortedViews = currentLayout->sortedLatteViews();
}
QList<Latte::View *> sortedViews = m_corona->layoutsManager()->synchronizer()->sortedCurrentViews();
Latte::View *highestPriorityView = highestApplicationLauncherView(sortedViews);
@ -356,12 +351,7 @@ void GlobalShortcuts::activateEntry(int index, Qt::Key modifier)
{
m_lastInvokedAction = dynamic_cast<QAction *>(sender());
QList<Latte::View *> sortedViews;
CentralLayout *currentLayout = m_corona->layoutsManager()->currentLayout();
if (currentLayout) {
sortedViews = currentLayout->sortedLatteViews();
}
QList<Latte::View *> sortedViews = m_corona->layoutsManager()->synchronizer()->sortedCurrentViews();
Latte::View *highest{nullptr};
@ -386,12 +376,7 @@ void GlobalShortcuts::activateEntry(int index, Qt::Key modifier)
//! update badge for specific view item
void GlobalShortcuts::updateViewItemBadge(QString identifier, QString value)
{
CentralLayout *currentLayout = m_corona->layoutsManager()->currentLayout();
QList<Latte::View *> views;
if (currentLayout) {
views = currentLayout->latteViews();
}
QList<Latte::View *> views = m_corona->layoutsManager()->synchronizer()->currentViews();
// update badges in all Latte Tasks plasmoids
for (const auto &view : views) {
@ -407,12 +392,7 @@ void GlobalShortcuts::showViews()
m_lastInvokedAction = m_singleMetaAction;
}
QList<Latte::View *> sortedViews;
CentralLayout *currentLayout = m_corona->layoutsManager()->currentLayout();
if (currentLayout) {
sortedViews = currentLayout->sortedLatteViews();
}
QList<Latte::View *> sortedViews = m_corona->layoutsManager()->synchronizer()->sortedCurrentViews();
Latte::View *viewWithTasks{nullptr};
Latte::View *viewWithMeta{nullptr};
@ -469,11 +449,7 @@ void GlobalShortcuts::showViews()
}
//! show all the rest views that contain plasma shortcuts
QList<Latte::View *> viewsWithShortcuts;
if (currentLayout) {
viewsWithShortcuts = currentLayout->viewsWithPlasmaShortcuts();
}
QList<Latte::View *> viewsWithShortcuts = m_corona->layoutsManager()->synchronizer()->currentViewsWithPlasmaShortcuts();
if (viewsWithShortcuts.count() > 0) {
viewFound = true;
@ -514,12 +490,7 @@ bool GlobalShortcuts::viewsToHideAreValid()
void GlobalShortcuts::showSettings()
{
QList<Latte::View *> sortedViews;
CentralLayout *currentLayout = m_corona->layoutsManager()->currentLayout();
if (currentLayout) {
sortedViews = currentLayout->sortedLatteViews();
}
QList<Latte::View *> sortedViews = m_corona->layoutsManager()->synchronizer()->sortedCurrentViews();
//! find which is the next view to show its settings
if (sortedViews.count() > 0) {
@ -527,8 +498,14 @@ void GlobalShortcuts::showSettings()
//! find last view that showed its config view
for (int i = 0; i < sortedViews.size(); ++i) {
if (sortedViews[i] == currentLayout->lastConfigViewFor()) {
openSettings = i;
for (auto currentLayout : m_corona->layoutsManager()->currentLayouts()) {
if (sortedViews[i] == currentLayout->lastConfigViewFor()) {
openSettings = i;
break;
}
}
if (openSettings >= 0) {
break;
}
}