buttonrebinds: Allow binding mouse button actions
Makes it possible to assign a pointer button event as the trigger to a button rebind. This would make it possible to make a mouse click the outcome of such actions.
This commit is contained in:
parent
d257da0a00
commit
d0da1cf751
2 changed files with 30 additions and 4 deletions
|
@ -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<Qt::MouseButton>(mouseButtonEnum.keyToValue(buttonName));
|
||||
const auto button = static_cast<quint32>(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<QKeySequence>(&action))
|
||||
return sendKeySequence(*seq, pressed, timestamp);
|
||||
else if (const auto mb = std::get_if<quint32>(&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;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "plugin.h"
|
||||
#include <variant>
|
||||
|
||||
#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<Trigger, QKeySequence> m_actions[LastType];
|
||||
QHash<Trigger, std::variant<QKeySequence, quint32>> m_actions[LastType];
|
||||
KConfigWatcher::Ptr m_configWatcher;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue