diff --git a/app/shortcuts/globalshortcuts.cpp b/app/shortcuts/globalshortcuts.cpp index e3f5b4dc3..256df1d05 100644 --- a/app/shortcuts/globalshortcuts.cpp +++ b/app/shortcuts/globalshortcuts.cpp @@ -207,6 +207,33 @@ ShortcutsPart::ShortcutsTracker *GlobalShortcuts::shortcutsTracker() const return m_shortcutsTracker; } +Latte::View *GlobalShortcuts::highestApplicationLauncherView(const QList &views) const +{ + if (views.isEmpty()) { + return nullptr; + } + + Latte::View *highestPriorityView{nullptr}; + + for (const auto view : views) { + if (view->interface()->applicationLauncherHasGlobalShortcut()) { + highestPriorityView = view; + break; + } + } + + if (!highestPriorityView) { + for (const auto view : views) { + if (view->interface()->containsApplicationLauncher()) { + highestPriorityView = view; + break; + } + } + } + + return highestPriorityView; +} + //! Activate launcher menu through dbus interface void GlobalShortcuts::activateLauncherMenu() { @@ -221,28 +248,26 @@ void GlobalShortcuts::activateLauncherMenu() sortedViews = currentLayout->sortedLatteViews(); } - for (const auto view : sortedViews) { - if (view->interface()->containsApplicationLauncher()) { - if (view->visibility()->isHidden() && view->interface()->applicationLauncherInPopup()) { - if (!m_hideViews.contains(view)) { - m_hideViews.append(view); - } + Latte::View *highestPriorityView = highestApplicationLauncherView(sortedViews); - m_lastInvokedAction = m_singleMetaAction; + if (highestPriorityView) { + if (highestPriorityView->visibility()->isHidden() && highestPriorityView->interface()->applicationLauncherInPopup()) { + if (!m_hideViews.contains(highestPriorityView)) { + m_hideViews.append(highestPriorityView); + } - view->visibility()->setBlockHiding(true); + m_lastInvokedAction = m_singleMetaAction; - //! delay the execution in order to show first the view - QTimer::singleShot(APPLETEXECUTIONDELAY, [this, view]() { - view->toggleAppletExpanded(view->interface()->applicationLauncherId()); - }); + highestPriorityView->visibility()->setBlockHiding(true); - m_hideViewsTimer.start(); - } else { - view->toggleAppletExpanded(view->interface()->applicationLauncherId()); - } + //! delay the execution in order to show first the view + QTimer::singleShot(APPLETEXECUTIONDELAY, [this, highestPriorityView]() { + highestPriorityView->toggleAppletExpanded(highestPriorityView->interface()->applicationLauncherId()); + }); - return; + m_hideViewsTimer.start(); + } else { + highestPriorityView->toggleAppletExpanded(highestPriorityView->interface()->applicationLauncherId()); } } } @@ -382,14 +407,8 @@ void GlobalShortcuts::showViews() } } - //! show Meta if it is not already shown for Tasks Latte View - if (!viewWithTasks || !viewWithTasks->interface()->containsApplicationLauncher()) { - for(const auto view : sortedViews) { - if (!viewWithMeta && m_corona->universalSettings()->kwin_metaForwardedToLatte() && view->interface()->containsApplicationLauncher()) { - viewWithMeta = view; - break; - } - } + if (m_corona->universalSettings()->kwin_metaForwardedToLatte()) { + viewWithMeta = highestApplicationLauncherView(sortedViews); } bool viewFound{false}; @@ -399,9 +418,13 @@ void GlobalShortcuts::showViews() } //! show view that contains tasks plasmoid - if (viewWithTasks && viewWithTasks->interface()->showShortcutBadges(true, true)) { + if (viewWithTasks) { viewFound = true; + bool showMeta = (viewWithMeta && (viewWithMeta == viewWithTasks)); + + viewWithTasks->interface()->showShortcutBadges(true, showMeta); + if (!m_hideViewsTimer.isActive()) { m_hideViews.append(viewWithTasks); viewWithTasks->visibility()->setBlockHiding(true); @@ -510,7 +533,7 @@ void GlobalShortcuts::hideViewsTimerSlot() for(const auto latteView : m_hideViews) { latteView->visibility()->setBlockHiding(false); latteView->interface()->hideShortcutBadges(); - } + } } m_hideViews.clear(); diff --git a/app/shortcuts/globalshortcuts.h b/app/shortcuts/globalshortcuts.h index a9c7abab7..8376799bc 100644 --- a/app/shortcuts/globalshortcuts.h +++ b/app/shortcuts/globalshortcuts.h @@ -79,6 +79,9 @@ private: bool viewAtLowerScreenPriority(Latte::View *test, Latte::View *base); bool viewsToHideAreValid(); + //! highest priority application launcher view + Latte::View *highestApplicationLauncherView(const QList &views) const; + QList sortedViewsList(QHash *views); private: diff --git a/app/view/containmentinterface.cpp b/app/view/containmentinterface.cpp index 6af5626d2..8480387e4 100644 --- a/app/view/containmentinterface.cpp +++ b/app/view/containmentinterface.cpp @@ -81,6 +81,25 @@ void ContainmentInterface::identifyMethods() m_showShortcutsMethod = m_mainItem->metaObject()->method(sbIndex); } +bool ContainmentInterface::applicationLauncherHasGlobalShortcut() const +{ + if (!containsApplicationLauncher()) { + return false; + } + + int launcherAppletId = applicationLauncherId(); + + const auto applets = m_view->containment()->applets(); + + for (auto applet : applets) { + if (applet->id() == launcherAppletId) { + return !applet->globalShortcut().isEmpty(); + } + } + + return false; +} + bool ContainmentInterface::applicationLauncherInPopup() const { if (!containsApplicationLauncher()) { @@ -103,11 +122,13 @@ bool ContainmentInterface::applicationLauncherInPopup() const bool ContainmentInterface::containsApplicationLauncher() const { - return applicationLauncherId() == -1 ? false : true; + return (applicationLauncherId() >= 0); } -bool ContainmentInterface::isCapableToShowShortcutBadges() const +bool ContainmentInterface::isCapableToShowShortcutBadges() { + identifyMainItem(); + if (!m_view->latteTasksArePresent() && m_view->tasksPresent()) { return false; } @@ -119,15 +140,21 @@ int ContainmentInterface::applicationLauncherId() const { const auto applets = m_view->containment()->applets(); + auto launcherId{-1}; + for (auto applet : applets) { const auto provides = applet->kPackage().metadata().value(QStringLiteral("X-Plasma-Provides")); if (provides.contains(QLatin1String("org.kde.plasma.launchermenu"))) { - return applet->id(); + if (!applet->globalShortcut().isEmpty()) { + return applet->id(); + } else if (launcherId == -1) { + launcherId = applet->id(); + } } } - return -1; + return launcherId; } bool ContainmentInterface::updateBadgeForLatteTask(const QString identifier, const QString value) diff --git a/app/view/containmentinterface.h b/app/view/containmentinterface.h index 06039c526..f53625e25 100644 --- a/app/view/containmentinterface.h +++ b/app/view/containmentinterface.h @@ -43,8 +43,9 @@ public: virtual ~ContainmentInterface(); bool applicationLauncherInPopup() const; + bool applicationLauncherHasGlobalShortcut() const; bool containsApplicationLauncher() const; - bool isCapableToShowShortcutBadges() const; + bool isCapableToShowShortcutBadges(); bool activateEntry(const int index); bool newInstanceForEntry(const int index); diff --git a/containment/package/contents/ui/applet/ShortcutBadge.qml b/containment/package/contents/ui/applet/ShortcutBadge.qml index 236ae9191..7d969f03d 100644 --- a/containment/package/contents/ui/applet/ShortcutBadge.qml +++ b/containment/package/contents/ui/applet/ShortcutBadge.qml @@ -62,6 +62,10 @@ Loader{ return; } + if (root.showMetaBadge && applet && applet.id === applicationLauncherId) { + return '\u2318'; + } + if (root.showAppletShortcutBadges) { var plasmaShortcut = applet ? shortcutsEngine.appletShortcutBadge(applet.id) : ""; @@ -70,9 +74,7 @@ Loader{ } } - if (root.showMetaBadge && applet && applet.id === applicationLauncherId) { - return '\u2318'; - } else if (appletNumberLoader.fixedIndex>=1 && appletNumberLoader.fixedIndex<20) { + if (appletNumberLoader.fixedIndex>=1 && appletNumberLoader.fixedIndex<20) { return root.badgesForActivate[appletNumberLoader.fixedIndex-1]; } else { return "";