From cf93b7516d9ceaa84d3744e08194211967a098a3 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 3 Feb 2019 09:53:49 +0200 Subject: [PATCH] improve global shortcuts options --the user can disable "global shortcuts based on position" by disabling the global shortcuts for the first two latte items --improve texts readability BUG: 403880 --- app/shortcuts/globalshortcuts.cpp | 40 +++++++++++-------- app/shortcuts/shortcutstracker.cpp | 14 ++++++- app/shortcuts/shortcutstracker.h | 7 +++- app/view/settings/primaryconfigview.cpp | 3 ++ containment/package/contents/config/main.xml | 4 +- .../configuration/pages/BehaviorConfig.qml | 25 ++++++------ .../configuration/pages/TasksConfig.qml | 6 +-- 7 files changed, 63 insertions(+), 36 deletions(-) diff --git a/app/shortcuts/globalshortcuts.cpp b/app/shortcuts/globalshortcuts.cpp index 6519c31b4..eb1274254 100644 --- a/app/shortcuts/globalshortcuts.cpp +++ b/app/shortcuts/globalshortcuts.cpp @@ -143,6 +143,7 @@ void GlobalShortcuts::init() KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + key)); connect(action, &QAction::triggered, this, [this, i] { // qDebug() << "meta action..."; + m_modifierTracker->cancelMetaPressed(); activateEntry(i, static_cast(Qt::META)); }); } @@ -157,6 +158,7 @@ void GlobalShortcuts::init() action->setShortcut(QKeySequence(Qt::META + keysAboveTen[i - 10])); KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + keysAboveTen[i - 10])); connect(action, &QAction::triggered, this, [this, i] { + m_modifierTracker->cancelMetaPressed(); activateEntry(i, static_cast(Qt::META)); }); } @@ -171,6 +173,7 @@ void GlobalShortcuts::init() KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + Qt::CTRL + key)); connect(action, &QAction::triggered, this, [this, i] { // qDebug() << "meta + ctrl + action..."; + m_modifierTracker->cancelMetaPressed(); activateEntry(i, static_cast(Qt::CTRL)); }); } @@ -181,6 +184,7 @@ void GlobalShortcuts::init() action->setText(i18n("New Instance for Entry %1", i)); KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + Qt::CTRL + keysAboveTen[i - 10])); connect(action, &QAction::triggered, this, [this, i] { + m_modifierTracker->cancelMetaPressed(); activateEntry(i, static_cast(Qt::CTRL)); }); } @@ -306,8 +310,6 @@ bool GlobalShortcuts::activatePlasmaTaskManagerEntryAtContainment(const Plasma:: bool GlobalShortcuts::activateLatteEntryAtContainment(const Latte::View *view, int index, Qt::Key modifier) { - m_modifierTracker->cancelMetaPressed(); - if (QQuickItem *containmentInterface = view->containment()->property("_plasma_graphicObject").value()) { const auto &childItems = containmentInterface->childItems(); @@ -366,24 +368,24 @@ bool GlobalShortcuts::activateLatteEntryAtContainment(const Latte::View *view, i //! Activate task manager entry void GlobalShortcuts::activateEntry(int index, Qt::Key modifier) { - m_modifierTracker->cancelMetaPressed(); - m_lastInvokedAction = dynamic_cast(sender()); QList sortedViews = sortedViewsList(m_corona->layoutManager()->currentLatteViews()); - foreach (auto view, sortedViews) { - if ((!view->latteTasksPresent() && view->tasksPresent() && - activatePlasmaTaskManagerEntryAtContainment(view->containment(), index, modifier)) - || (view->isPreferredForShortcuts() && activateLatteEntryAtContainment(view, index, modifier))) { + if (m_shortcutsTracker->basedOnPositionEnabled()){ + foreach (auto view, sortedViews) { + if ((!view->latteTasksPresent() && view->tasksPresent() && + activatePlasmaTaskManagerEntryAtContainment(view->containment(), index, modifier)) + || activateLatteEntryAtContainment(view, index, modifier)) { - if (!m_hideViews.contains(view)) { - m_hideViews.append(view); - } + if (!m_hideViews.contains(view)) { + m_hideViews.append(view); + } - view->visibility()->setBlockHiding(true); - m_hideViewsTimer.start(); - return; + view->visibility()->setBlockHiding(true); + m_hideViewsTimer.start(); + return; + } } } } @@ -591,9 +593,12 @@ void GlobalShortcuts::showViews() Latte::View *viewWithTasks{nullptr}; Latte::View *viewWithMeta{nullptr}; - foreach (auto view, sortedViews) { - if (!viewWithTasks && view->isPreferredForShortcuts() && isCapableToShowShortcutBadges(view)) { - viewWithTasks = view; + if (m_shortcutsTracker->basedOnPositionEnabled()) { + foreach (auto view, sortedViews) { + if (!viewWithTasks && isCapableToShowShortcutBadges(view)) { + viewWithTasks = view; + break; + } } } @@ -602,6 +607,7 @@ void GlobalShortcuts::showViews() foreach (auto view, sortedViews) { if (!viewWithMeta && m_corona->universalSettings()->metaForwardedToLatte() && applicationLauncherId(view->containment()) > -1) { viewWithMeta = view; + break; } } } diff --git a/app/shortcuts/shortcutstracker.cpp b/app/shortcuts/shortcutstracker.cpp index 74481ca25..75445b80a 100644 --- a/app/shortcuts/shortcutstracker.cpp +++ b/app/shortcuts/shortcutstracker.cpp @@ -52,6 +52,10 @@ ShortcutsTracker::~ShortcutsTracker() void ShortcutsTracker::initGlobalShortcutsWatcher() { + for (int i=1; i<=19; ++i) { + m_badgesForActivate << QString(); + } + const QString globalShortcutsFilePath = QDir::homePath() + "/.config/" + GLOBALSHORTCUTSCONFIG; m_shortcutsConfigPtr = KSharedConfig::openConfig(globalShortcutsFilePath); @@ -61,6 +65,11 @@ void ShortcutsTracker::initGlobalShortcutsWatcher() connect(KDirWatch::self(), &KDirWatch::created, this, &ShortcutsTracker::shortcutsFileChanged, Qt::QueuedConnection); } +bool ShortcutsTracker::basedOnPositionEnabled() const +{ + return m_basedOnPositionEnabled; +} + QStringList ShortcutsTracker::badgesForActivate() const { return m_badgesForActivate; @@ -145,6 +154,8 @@ void ShortcutsTracker::parseGlobalShortcuts() m_badgesForActivate << shortcutToBadge(records); } + m_basedOnPositionEnabled = (!m_badgesForActivate[0].isEmpty() && !m_badgesForActivate[1].isEmpty()); + foreach(auto key, latteGroup.keyList()) { if (key.startsWith(APPLETSHORTCUTKEY)) { QStringList records = latteGroup.readEntry(key, QStringList()); @@ -154,9 +165,10 @@ void ShortcutsTracker::parseGlobalShortcuts() } } - emit badgesForActivateChanged(); qDebug() << "badges updated to :: " << m_badgesForActivate; qDebug() << "applet shortcuts updated to :: " << m_appletShortcuts; + + emit badgesForActivateChanged(); } } diff --git a/app/shortcuts/shortcutstracker.h b/app/shortcuts/shortcutstracker.h index ceafddd66..78c0b3aa5 100644 --- a/app/shortcuts/shortcutstracker.h +++ b/app/shortcuts/shortcutstracker.h @@ -31,6 +31,7 @@ namespace ShortcutsPart { class ShortcutsTracker: public QObject { Q_OBJECT + Q_PROPERTY(bool basedOnPositionEnabled READ basedOnPositionEnabled NOTIFY badgesForActivateChanged) Q_PROPERTY(QStringList badgesForActivate READ badgesForActivate NOTIFY badgesForActivateChanged) public: @@ -39,6 +40,8 @@ public: void clearAllAppletShortcuts(); + bool basedOnPositionEnabled() const; + QStringList badgesForActivate() const; QList appletsWithPlasmaShortcuts(); @@ -60,7 +63,9 @@ private: QString shortcutToBadge(QStringList shortcutRecords); private: - QStringList m_badgesForActivate{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "z", "x", "c", "v", "b", "n", "m", ",", "."}; + bool m_basedOnPositionEnabled{false}; + + QStringList m_badgesForActivate; //! shortcuts assigned to applets through plasma infrastructure //! diff --git a/app/view/settings/primaryconfigview.cpp b/app/view/settings/primaryconfigview.cpp index 55785a890..1304b1ff9 100644 --- a/app/view/settings/primaryconfigview.cpp +++ b/app/view/settings/primaryconfigview.cpp @@ -27,6 +27,8 @@ #include "../../lattecorona.h" #include "../../layoutmanager.h" #include "../../settings/universalsettings.h" +#include "../../shortcuts/globalshortcuts.h" +#include "../../shortcuts/shortcutstracker.h" #include "../../wm/abstractwindowinterface.h" // Qt @@ -123,6 +125,7 @@ void PrimaryConfigView::init() setColor(Qt::transparent); PanelShadows::self()->addWindow(this); rootContext()->setContextProperty(QStringLiteral("latteView"), m_latteView); + rootContext()->setContextProperty(QStringLiteral("shortcutsEngine"), m_corona->globalShortcuts()->shortcutsTracker()); rootContext()->setContextProperty(QStringLiteral("viewConfig"), this); if (m_corona) { diff --git a/containment/package/contents/config/main.xml b/containment/package/contents/config/main.xml index a482f1d83..6d7546649 100644 --- a/containment/package/contents/config/main.xml +++ b/containment/package/contents/config/main.xml @@ -275,7 +275,7 @@ 0 - + false @@ -304,7 +304,7 @@ true - + true diff --git a/shell/package/contents/configuration/pages/BehaviorConfig.qml b/shell/package/contents/configuration/pages/BehaviorConfig.qml index e8dba8577..9b123877a 100644 --- a/shell/package/contents/configuration/pages/BehaviorConfig.qml +++ b/shell/package/contents/configuration/pages/BehaviorConfig.qml @@ -541,18 +541,6 @@ PlasmaComponents.Page { } } - PlasmaComponents.CheckBox { - Layout.leftMargin: units.smallSpacing * 2 - text: i18n("Activate based on position through global shortcuts") - checked: latteView.isPreferredForShortcuts - - tooltip: i18n("This view activates its items based on their position through global shortcuts. Take note that only one view can have that option enabled for each layout") - - onClicked: { - latteView.isPreferredForShortcuts = checked - } - } - PlasmaComponents.CheckBox { Layout.leftMargin: units.smallSpacing * 2 text: i18n("Decrease size automatically when needed") @@ -588,6 +576,19 @@ PlasmaComponents.Page { } } + PlasmaComponents.CheckBox { + Layout.leftMargin: units.smallSpacing * 2 + text: i18n("Prefer for based on position global shortcuts") + checked: latteView.isPreferredForShortcuts + enabled: shortcutsEngine.basedOnPositionEnabled + + tooltip: i18n("This view is preferred to use the based on position global shortcuts. Take note that only one view can have that option enabled for each layout") + + onClicked: { + latteView.isPreferredForShortcuts = checked + } + } + PlasmaComponents.CheckBox { Layout.leftMargin: units.smallSpacing * 2 text: i18n("Can be above fullscreen windows") diff --git a/shell/package/contents/configuration/pages/TasksConfig.qml b/shell/package/contents/configuration/pages/TasksConfig.qml index 890b1abc7..5c9b329b1 100644 --- a/shell/package/contents/configuration/pages/TasksConfig.qml +++ b/shell/package/contents/configuration/pages/TasksConfig.qml @@ -168,11 +168,11 @@ PlasmaComponents.Page { PlasmaComponents.CheckBox { id: unifyGlobalShortcutsChk Layout.leftMargin: units.smallSpacing * 2 - text: i18n("Activate based on position shortcuts only for tasks") + text: i18n("Based on position shortcuts apply only for tasks") checked: !plasmoid.configuration.unifiedGlobalShortcuts - tooltip: i18n("Based on position global shortcuts are enabled for tasks but are disabled for applets") + tooltip: i18n("Based on position global shortcuts are enabled only for tasks and not for applets") visible: dialog.highLevel - enabled: latteView.isPreferredForShortcuts + enabled: shortcutsEngine.basedOnPositionEnabled onClicked: { plasmoid.configuration.unifiedGlobalShortcuts = !checked