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
pull/4/head
Michail Vourlakos 6 years ago
parent 50dc45c61f
commit cf93b7516d

@ -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::Key>(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::Key>(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::Key>(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::Key>(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<QQuickItem *>()) {
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<QAction *>(sender());
QList<Latte::View *> 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;
}
}
}

@ -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();
}
}

@ -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<int> 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
//! <applet id, shortcut>

@ -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) {

@ -275,7 +275,7 @@
<choice name="Global"/>
</choices>
<default>0</default>
</entry>
</entry>
<entry name="showWindowActions" type="Bool">
<default>false</default>
</entry>
@ -304,7 +304,7 @@
</entry>
<entry name="showProgressBadge" type="Bool">
<default>true</default>
</entry>
</entry>
<entry name="showAudioBadge" type="Bool">
<default>true</default>
</entry>

@ -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")

@ -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

Loading…
Cancel
Save