diff --git a/src/plugins/buttonrebinds/buttonrebindsfilter.cpp b/src/plugins/buttonrebinds/buttonrebindsfilter.cpp index c505373401..1f977f32b8 100644 --- a/src/plugins/buttonrebinds/buttonrebindsfilter.cpp +++ b/src/plugins/buttonrebinds/buttonrebindsfilter.cpp @@ -129,7 +129,7 @@ void ButtonRebindsFilter::loadConfig(const KConfigGroup &group) const QByteArray buttonName = QByteArray("ExtraButton") + QByteArray::number(i); if (mouseGroup.hasKey(buttonName.constData())) { const auto entry = mouseGroup.readEntry(buttonName.constData(), QStringList()); - const auto button = static_cast(mouseButtonEnum.keyToValue(buttonName)); + const auto button = static_cast(mouseButtonEnum.keyToValue(buttonName)); insert(Pointer, {QString(), button}, entry); foundActions = true; } @@ -172,11 +172,23 @@ bool ButtonRebindsFilter::tabletPadButtonEvent(uint button, bool pressed, const void ButtonRebindsFilter::insert(TriggerType type, const Trigger &trigger, const QStringList &entry) { - if (entry.size() == 2 && entry.first() == QLatin1String("Key")) { + if (entry.size() != 2) { + qCWarning(KWIN_BUTTONREBINDS) << "Failed to rebind to" << entry; + return; + } + if (entry.first() == QLatin1String("Key")) { const auto keys = QKeySequence::fromString(entry.at(1), QKeySequence::PortableText); if (!keys.isEmpty()) { m_actions[type].insert(trigger, keys); } + } else if (entry.first() == QLatin1String("MouseButton")) { + bool ok; + const auto mb = quint32(entry.last().toInt(&ok)); + if (ok) { + m_actions[type].insert(trigger, mb); + } else { + qCWarning(KWIN_BUTTONREBINDS) << "Could not convert" << entry << "into a mouse button"; + } } } @@ -186,7 +198,13 @@ bool ButtonRebindsFilter::send(TriggerType type, const Trigger &trigger, bool pr if (typeActions.isEmpty()) { return false; } - return sendKeySequence(typeActions[trigger], pressed, timestamp); + + const auto &action = typeActions[trigger]; + if (const QKeySequence *seq = std::get_if(&action)) + return sendKeySequence(*seq, pressed, timestamp); + else if (const auto mb = std::get_if(&action)) + return sendMouseButton(*mb, pressed, timestamp); + return false; } bool ButtonRebindsFilter::sendKeySequence(const QKeySequence &keys, bool pressed, uint time) @@ -229,3 +247,9 @@ bool ButtonRebindsFilter::sendKeySequence(const QKeySequence &keys, bool pressed sendKey(keyCode.value()); return true; } + +bool ButtonRebindsFilter::sendMouseButton(quint32 button, bool pressed, uint time) +{ + Q_EMIT m_inputDevice.pointerButtonChanged(button, KWin::InputRedirection::PointerButtonState(pressed), time, &m_inputDevice); + return true; +} diff --git a/src/plugins/buttonrebinds/buttonrebindsfilter.h b/src/plugins/buttonrebinds/buttonrebindsfilter.h index ba95735b18..dfc335ec08 100644 --- a/src/plugins/buttonrebinds/buttonrebindsfilter.h +++ b/src/plugins/buttonrebinds/buttonrebindsfilter.h @@ -7,6 +7,7 @@ #pragma once #include "plugin.h" +#include #include "core/inputdevice.h" #include "input.h" @@ -65,8 +66,9 @@ private: void insert(TriggerType type, const Trigger &trigger, const QStringList &action); bool send(TriggerType type, const Trigger &trigger, bool pressed, uint timestamp); bool sendKeySequence(const QKeySequence &sequence, bool pressed, uint time); + bool sendMouseButton(quint32 button, bool pressed, uint time); InputDevice m_inputDevice; - QHash m_actions[LastType]; + QHash> m_actions[LastType]; KConfigWatcher::Ptr m_configWatcher; };