improvements for global shortcuts

Summary: BUG: 403880

Reviewers: mvourlakos

Reviewed By: mvourlakos

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D18717
pull/4/head
Tranter Madi 6 years ago committed by Michail Vourlakos
parent 499ae015c1
commit fede9feb2d

@ -184,6 +184,7 @@ void Layout::init()
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 @@ void Layout::setActivities(QStringList activities)
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 @@ void Layout::loadConfig()
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 @@ void Layout::saveConfig()
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();
}

@ -67,6 +67,8 @@ class Layout : public QObject
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 @@ public:
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 @@ signals:
//! 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 @@ private:
QString m_textColor;
QStringList m_activities;
QStringList m_launchers;
bool m_preferredForShortcutsTouched{false};
QStringList m_unloadedContainmentsIds;

@ -373,7 +373,7 @@ void GlobalShortcuts::activateEntry(int index, Qt::Key modifier)
QList<Latte::View *> sortedViews = sortedViewsList(m_corona->layoutManager()->currentLatteViews());
foreach (auto view, sortedViews) {
if (!view->isPreferredForShortcuts()) {
if (view->managedLayout()->preferredForShortcutsTouched() && !view->isPreferredForShortcuts()) {
continue;
}
@ -597,7 +597,7 @@ void GlobalShortcuts::showViews()
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 @@ QList<Latte::View *> GlobalShortcuts::sortedViewsList(QHash<const Plasma::Contai
return sortedViews;
}
Latte::View *GlobalShortcuts::highestPriorityView()
{
QList<Latte::View *> views = sortedViewsList(m_corona->layoutManager()->currentLatteViews());
if (views.count() > 0) {
return views[0];
}
return nullptr;
}
void GlobalShortcuts::showSettings()
{
QList<Latte::View *> views = sortedViewsList(m_corona->layoutManager()->currentLatteViews());

@ -61,6 +61,8 @@ public:
ShortcutsPart::ShortcutsTracker *shortcutsTracker() const;
Latte::View *highestPriorityView();
signals:
void modifiersChanged();
@ -82,7 +84,6 @@ private:
bool isCapableToShowShortcutBadges(Latte::View *view);
int applicationLauncherId(const Plasma::Containment *c);
QList<Latte::View *> sortedViewsList(QHash<const Plasma::Containment *, Latte::View *> *views);
private:

@ -1030,6 +1030,15 @@ void View::restoreGrabItemBehavior()
}
}
bool View::isHighestPriorityView() {
auto *latteCorona = qobject_cast<Latte::Corona *>(this->corona());
if (latteCorona) {
return this == latteCorona->globalShortcuts()->highestPriorityView();
}
return false;
}
//!BEGIN overriding context menus behavior
void View::mousePressEvent(QMouseEvent *event)
{

@ -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 @@ public slots:
Q_INVOKABLE void disableGrabItemBehavior();
Q_INVOKABLE void restoreGrabItemBehavior();
Q_INVOKABLE bool isHighestPriorityView();
protected slots:
void showConfigurationInterface(Plasma::Applet *applet) override;

@ -544,13 +544,16 @@ PlasmaComponents.Page {
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
}
}
}

@ -172,7 +172,7 @@ PlasmaComponents.Page {
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

Loading…
Cancel
Save