From 09003d03bc34ba25991a8de26d7a396d43787568 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 11 Jul 2024 15:30:39 -0400 Subject: [PATCH] ButtonRebindsFilter: Support disabled buttons It's sometimes wanted that you disable certain buttons on the device, such as an annoyingly place side button on a drawing tablet. This now makes it possible to do so by putting "Disabled" in the config. The rebind filter will then ensure the events are stopped and none are emitted. --- .../buttonrebinds/buttonrebindsfilter.cpp | 24 ++++++++++++++++++- .../buttonrebinds/buttonrebindsfilter.h | 5 +++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/plugins/buttonrebinds/buttonrebindsfilter.cpp b/src/plugins/buttonrebinds/buttonrebindsfilter.cpp index 5f87c97d97..7d81479d6c 100644 --- a/src/plugins/buttonrebinds/buttonrebindsfilter.cpp +++ b/src/plugins/buttonrebinds/buttonrebindsfilter.cpp @@ -224,16 +224,26 @@ bool ButtonRebindsFilter::tabletToolButtonEvent(uint button, bool pressed, const void ButtonRebindsFilter::insert(TriggerType type, const Trigger &trigger, const QStringList &entry) { - if (entry.size() != 2) { + if (entry.empty()) { qCWarning(KWIN_BUTTONREBINDS) << "Failed to rebind to" << entry; return; } if (entry.first() == QLatin1String("Key")) { + if (entry.size() != 2) { + qCWarning(KWIN_BUTTONREBINDS) << "Invalid key" << entry; + return; + } + const auto keys = QKeySequence::fromString(entry.at(1), QKeySequence::PortableText); if (!keys.isEmpty()) { m_actions.at(type).insert(trigger, keys); } } else if (entry.first() == QLatin1String("MouseButton")) { + if (entry.size() != 2) { + qCWarning(KWIN_BUTTONREBINDS) << "Invalid mouse button" << entry; + return; + } + bool ok = false; const MouseButton mb{entry.last().toUInt(&ok)}; if (ok) { @@ -242,6 +252,12 @@ void ButtonRebindsFilter::insert(TriggerType type, const Trigger &trigger, const qCWarning(KWIN_BUTTONREBINDS) << "Could not convert" << entry << "into a mouse button"; } } else if (entry.first() == QLatin1String("TabletToolButton")) { + if (entry.size() != 2) { + qCWarning(KWIN_BUTTONREBINDS) + << "Invalid tablet tool button" << entry; + return; + } + bool ok = false; const TabletToolButton tb{entry.last().toUInt(&ok)}; if (ok) { @@ -249,6 +265,8 @@ void ButtonRebindsFilter::insert(TriggerType type, const Trigger &trigger, const } else { qCWarning(KWIN_BUTTONREBINDS) << "Could not convert" << entry << "into a mouse button"; } + } else if (entry.first() == QLatin1String("Disabled")) { + m_actions.at(type).insert(trigger, DisabledButton{}); } } @@ -269,6 +287,10 @@ bool ButtonRebindsFilter::send(TriggerType type, const Trigger &trigger, bool pr if (const auto tb = std::get_if(&action)) { return sendTabletToolButton(tb->button, pressed, timestamp); } + if (std::get_if(&action)) { + // Intentional, we don't want to anything to anybody + return true; + } return false; } diff --git a/src/plugins/buttonrebinds/buttonrebindsfilter.h b/src/plugins/buttonrebinds/buttonrebindsfilter.h index b8faafcfa8..9950e3e67c 100644 --- a/src/plugins/buttonrebinds/buttonrebindsfilter.h +++ b/src/plugins/buttonrebinds/buttonrebindsfilter.h @@ -68,6 +68,9 @@ public: { quint32 button; }; + struct DisabledButton + { + }; explicit ButtonRebindsFilter(); bool pointerEvent(KWin::MouseEvent *event, quint32 nativeButton) override; @@ -83,7 +86,7 @@ private: bool sendTabletToolButton(quint32 button, bool pressed, std::chrono::microseconds time); InputDevice m_inputDevice; - std::array>, LastType> m_actions; + std::array>, LastType> m_actions; KConfigWatcher::Ptr m_configWatcher; std::optional m_tabletTool; };