From e1a46976e63a9ab8d5478867bd37c9182321191b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sun, 2 Apr 2017 18:22:44 +0200 Subject: [PATCH] Support new touch screen edge swipe callbacks in TabBox Summary: Last but not least the TabBox gets adjusted for the new touch callbacks. Reviewers: #kwin, #plasma Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D5281 --- tabbox/tabbox.cpp | 37 +++++++++++++++++++++++++++++++++---- tabbox/tabbox.h | 4 ++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/tabbox/tabbox.cpp b/tabbox/tabbox.cpp index 41df699255..014c09b7b1 100644 --- a/tabbox/tabbox.cpp +++ b/tabbox/tabbox.cpp @@ -815,6 +815,29 @@ void TabBox::reconfigure() borders = &m_borderAlternativeActivate; borderConfig = QStringLiteral("BorderAlternativeActivate"); } + + auto touchConfig = [this, config] (const QString &key, QHash &actions, TabBoxMode mode) { + // fist erase old config + for (auto it = actions.begin(); it != actions.end(); ) { + delete it.value(); + it = actions.erase(it); + } + // now new config + const QStringList list = config.readEntry(key, QStringList()); + for (const auto &s : list) { + bool ok; + const int i = s.toInt(&ok); + if (!ok) { + continue; + } + QAction *a = new QAction(this); + connect(a, &QAction::triggered, this, std::bind(&TabBox::toggleMode, this, mode)); + ScreenEdges::self()->reserveTouch(ElectricBorder(i), a); + actions.insert(ElectricBorder(i), a); + } + }; + touchConfig(QStringLiteral("TouchBorderActivate"), m_touchActivate, TabBoxWindowsMode); + touchConfig(QStringLiteral("TouchBorderAlternativeActivate"), m_touchAlternativeActivate, TabBoxWindowsAlternativeMode); } void TabBox::loadConfig(const KConfigGroup& config, TabBoxConfig& tabBoxConfig) @@ -1220,6 +1243,15 @@ void TabBox::shadeActivate(AbstractClient *c) } bool TabBox::toggle(ElectricBorder eb) +{ + if (m_borderAlternativeActivate.contains(eb)) { + return toggleMode(TabBoxWindowsAlternativeMode); + } else { + return toggleMode(TabBoxWindowsMode); + } +} + +bool TabBox::toggleMode(TabBoxMode mode) { if (!options->focusPolicyIsReasonable()) return false; // not supported. @@ -1230,10 +1262,7 @@ bool TabBox::toggle(ElectricBorder eb) if (!establishTabBoxGrab()) return false; m_noModifierGrab = m_tabGrab = true; - if (m_borderAlternativeActivate.contains(eb)) - setMode(TabBoxWindowsAlternativeMode); - else - setMode(TabBoxWindowsMode); + setMode(mode); reset(); show(); return true; diff --git a/tabbox/tabbox.h b/tabbox/tabbox.h index fb9c093937..bdc02a6fcc 100644 --- a/tabbox/tabbox.h +++ b/tabbox/tabbox.h @@ -241,6 +241,8 @@ private: void shadeActivate(AbstractClient *c); + bool toggleMode(TabBoxMode mode); + private Q_SLOTS: void reconfigure(); void globalShortcutChanged(QAction *action, const QKeySequence &seq); @@ -276,6 +278,8 @@ private: bool m_forcedGlobalMouseGrab; bool m_ready; // indicates whether the config is completely loaded QList m_borderActivate, m_borderAlternativeActivate; + QHash m_touchActivate; + QHash m_touchAlternativeActivate; static TabBox *s_self; };