diff --git a/app/layout/layout.h b/app/layout/layout.h --- a/app/layout/layout.h +++ b/app/layout/layout.h @@ -67,6 +67,8 @@ Q_PROPERTY(QStringList launchers READ launchers WRITE setLaunchers NOTIFY launchersChanged) Q_PROPERTY(QStringList activities READ activities WRITE setActivities NOTIFY activitiesChanged) + Q_PROPERTY(bool preferredForShortcutsTouched READ preferredForShortcutsTouched WRITE setPreferredForShortcutsTouched NOTIFY preferredForShortcutsTouchedChanged) + public: Layout(QObject *parent, QString layoutFile, QString layoutName = QString()); ~Layout() override; @@ -164,6 +166,9 @@ int viewsCount(QScreen *screen) const; int viewsCount() const; + bool preferredForShortcutsTouched() const; + void setPreferredForShortcutsTouched(bool touched); + public slots: Q_INVOKABLE int viewsWithTasks() const; @@ -189,6 +194,7 @@ //! used from LatteView(s) in order to exist only one each time that has the highest priority //! to use the global shortcuts activations void preferredViewForShortcutsChanged(Latte::View *view); + void preferredForShortcutsTouchedChanged(); private slots: void loadConfig(); @@ -245,6 +251,7 @@ QString m_textColor; QStringList m_activities; QStringList m_launchers; + bool m_preferredForShortcutsTouched{false}; QStringList m_unloadedContainmentsIds; diff --git a/app/layout/layout.cpp b/app/layout/layout.cpp --- a/app/layout/layout.cpp +++ b/app/layout/layout.cpp @@ -184,6 +184,7 @@ connect(this, &Layout::textColorChanged, this, &Layout::saveConfig); connect(this, &Layout::launchersChanged, this, &Layout::saveConfig); connect(this, &Layout::lastUsedActivityChanged, this, &Layout::saveConfig); + connect(this, &Layout::preferredForShortcutsTouchedChanged, this, &Layout::saveConfig); } void Layout::initToCorona(Latte::Corona *corona) @@ -550,6 +551,21 @@ emit activitiesChanged(); } +bool Layout::preferredForShortcutsTouched() const +{ + return m_preferredForShortcutsTouched; +} + +void Layout::setPreferredForShortcutsTouched(bool touched) +{ + if (m_preferredForShortcutsTouched == touched) { + return; + } + + m_preferredForShortcutsTouched = touched; + emit preferredForShortcutsTouchedChanged(); +} + QStringList Layout::unloadedContainmentsIds() { return m_unloadedContainmentsIds; @@ -730,6 +746,7 @@ m_activities = m_layoutGroup.readEntry("activities", QStringList()); m_launchers = m_layoutGroup.readEntry("launchers", QStringList()); m_lastUsedActivity = m_layoutGroup.readEntry("lastUsedActivity", QString()); + m_preferredForShortcutsTouched = m_layoutGroup.readEntry("preferredForShortcutsTouched", false); QString back = m_layoutGroup.readEntry("background", ""); @@ -756,6 +773,7 @@ m_layoutGroup.writeEntry("activities", m_activities); m_layoutGroup.writeEntry("lastUsedActivity", m_lastUsedActivity); m_layoutGroup.writeEntry("textColor", m_textColor); + m_layoutGroup.writeEntry("preferredForShortcutsTouched", m_preferredForShortcutsTouched); m_layoutGroup.sync(); } diff --git a/app/shortcuts/globalshortcuts.h b/app/shortcuts/globalshortcuts.h --- a/app/shortcuts/globalshortcuts.h +++ b/app/shortcuts/globalshortcuts.h @@ -61,6 +61,8 @@ ShortcutsPart::ShortcutsTracker *shortcutsTracker() const; + Latte::View *highestPriorityView(); + signals: void modifiersChanged(); @@ -82,7 +84,6 @@ bool isCapableToShowShortcutBadges(Latte::View *view); int applicationLauncherId(const Plasma::Containment *c); - QList sortedViewsList(QHash *views); private: diff --git a/app/shortcuts/globalshortcuts.cpp b/app/shortcuts/globalshortcuts.cpp --- a/app/shortcuts/globalshortcuts.cpp +++ b/app/shortcuts/globalshortcuts.cpp @@ -373,7 +373,7 @@ QList sortedViews = sortedViewsList(m_corona->layoutManager()->currentLatteViews()); foreach (auto view, sortedViews) { - if (!view->isPreferredForShortcuts()) { + if (view->managedLayout()->preferredForShortcutsTouched() && !view->isPreferredForShortcuts()) { continue; } @@ -597,7 +597,7 @@ Latte::View *viewWithMeta{nullptr}; foreach (auto view, sortedViews) { - if (!viewWithTasks && view->isPreferredForShortcuts() && isCapableToShowShortcutBadges(view)) { + if (!viewWithTasks && (!view->managedLayout()->preferredForShortcutsTouched() || view->isPreferredForShortcuts()) && isCapableToShowShortcutBadges(view)) { viewWithTasks = view; break; } @@ -805,6 +805,16 @@ return sortedViews; } +Latte::View *GlobalShortcuts::highestPriorityView() +{ + QList views = sortedViewsList(m_corona->layoutManager()->currentLatteViews()); + + if (views.count() > 0) { + return views[0]; + } + return nullptr; +} + void GlobalShortcuts::showSettings() { QList views = sortedViewsList(m_corona->layoutManager()->currentLatteViews()); diff --git a/app/view/view.h b/app/view/view.h --- a/app/view/view.h +++ b/app/view/view.h @@ -26,6 +26,7 @@ #include "positioner.h" #include "visibilitymanager.h" #include "settings/primaryconfigview.h" +#include "../shortcuts/globalshortcuts.h" #include "../layout/layout.h" #include "../plasma/quick/containmentview.h" #include "../plasma/quick/configview.h" @@ -191,6 +192,8 @@ Q_INVOKABLE void disableGrabItemBehavior(); Q_INVOKABLE void restoreGrabItemBehavior(); + Q_INVOKABLE bool isHighestPriorityView(); + protected slots: void showConfigurationInterface(Plasma::Applet *applet) override; diff --git a/app/view/view.cpp b/app/view/view.cpp --- a/app/view/view.cpp +++ b/app/view/view.cpp @@ -1030,6 +1030,15 @@ } } +bool View::isHighestPriorityView() { + auto *latteCorona = qobject_cast(this->corona()); + + if (latteCorona) { + return this == latteCorona->globalShortcuts()->highestPriorityView(); + } + return false; +} + //!BEGIN overriding context menus behavior void View::mousePressEvent(QMouseEvent *event) { diff --git a/shell/package/contents/configuration/pages/BehaviorConfig.qml b/shell/package/contents/configuration/pages/BehaviorConfig.qml --- a/shell/package/contents/configuration/pages/BehaviorConfig.qml +++ b/shell/package/contents/configuration/pages/BehaviorConfig.qml @@ -544,13 +544,16 @@ PlasmaComponents.CheckBox { Layout.leftMargin: units.smallSpacing * 2 text: i18n("Activate based on position through global shortcuts") - checked: latteView.isPreferredForShortcuts + checked: latteView.isPreferredForShortcuts || (!latteView.managedLayout.preferredForShortcutsTouched && latteView.isHighestPriorityView()) //enabled: shortcutsEngine.basedOnPositionEnabled tooltip: i18n("This view is used for based on position global shortcuts. Take note that only one view can have that option enabled for each layout") onClicked: { latteView.isPreferredForShortcuts = checked + if (!latteView.managedLayout.preferredForShortcutsTouched) { + latteView.managedLayout.preferredForShortcutsTouched = true + } } } diff --git a/shell/package/contents/configuration/pages/TasksConfig.qml b/shell/package/contents/configuration/pages/TasksConfig.qml --- a/shell/package/contents/configuration/pages/TasksConfig.qml +++ b/shell/package/contents/configuration/pages/TasksConfig.qml @@ -172,7 +172,7 @@ checked: !plasmoid.configuration.unifiedGlobalShortcuts tooltip: i18n("Based on position global shortcuts are enabled only for tasks and not for applets") visible: dialog.highLevel - enabled: latteView.isPreferredForShortcuts + enabled: latteView.isPreferredForShortcuts || (!latteView.managedLayout.preferredForShortcutsTouched && latteView.isHighestPriorityView()) onClicked: { plasmoid.configuration.unifiedGlobalShortcuts = !checked