summaryrefslogtreecommitdiffhomepage
path: root/logic/shortcuts.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'logic/shortcuts.cpp')
-rw-r--r--logic/shortcuts.cpp88
1 files changed, 49 insertions, 39 deletions
diff --git a/logic/shortcuts.cpp b/logic/shortcuts.cpp
index 6d77c3e0..df21f7d2 100644
--- a/logic/shortcuts.cpp
+++ b/logic/shortcuts.cpp
@@ -29,9 +29,10 @@ void Shortcuts::free_binding(K& key)
#endif
}
-void Shortcuts::bind_shortcut(K &key, const key_opts& k, unused_on_unix(bool, held))
+void Shortcuts::bind_shortcut(K& key, const key_opts& k, bool held)
{
-#if !defined(_WIN32)
+#if !defined _WIN32
+ (void)held;
using sh = QxtGlobalShortcut;
if (key)
{
@@ -45,13 +46,18 @@ void Shortcuts::bind_shortcut(K &key, const key_opts& k, unused_on_unix(bool, he
key->setShortcut(QKeySequence::fromString(k.keycode, QKeySequence::PortableText));
key->setEnabled();
}
-}
#else
- key = K();
+ key = {};
int idx = 0;
- QKeySequence code;
+ QKeySequence code(QKeySequence::UnknownKey);
- if (k.guid != "")
+ if (k.guid == QStringLiteral("mouse"))
+ {
+ key.guid = k.guid;
+ key.keycode = k.button;
+ key.held = held;
+ }
+ if (!k.guid->isEmpty())
{
key.guid = k.guid;
key.keycode = k.button & ~Qt::KeyboardModifierMask;
@@ -62,48 +68,51 @@ void Shortcuts::bind_shortcut(K &key, const key_opts& k, unused_on_unix(bool, he
}
else
{
- if (k.keycode == "")
- code = QKeySequence(Qt::Key_unknown);
- else
+ if (!k.keycode->isEmpty())
code = QKeySequence::fromString(k.keycode, QKeySequence::PortableText);
Qt::KeyboardModifiers mods = Qt::NoModifier;
- if (code != Qt::Key_unknown)
- win_key::from_qt(code, idx, mods);
-
- key.guid = QStringLiteral("");
- key.keycode = idx;
- key.held = held;
- key.ctrl = !!(mods & Qt::ControlModifier);
- key.alt = !!(mods & Qt::AltModifier);
- key.shift = !!(mods & Qt::ShiftModifier);
+ if (!code.isEmpty() &&
+ code != QKeySequence{ QKeySequence::UnknownKey } &&
+ win_key::from_qt(code, idx, mods))
+ {
+ key.guid = QString{};
+ key.keycode = idx;
+ key.held = held;
+ key.ctrl = !!(mods & Qt::ControlModifier);
+ key.alt = !!(mods & Qt::AltModifier);
+ key.shift = !!(mods & Qt::ShiftModifier);
+ }
}
-}
#endif
+}
#ifdef _WIN32
-void Shortcuts::receiver(const Key& k)
+
+void Shortcuts::receiver(const Key& key)
{
const unsigned sz = keys.size();
for (unsigned i = 0; i < sz; i++)
{
- K& k_ = std::get<0>(keys[i]);
- if (k.guid != k_.guid)
+ auto& [k, f, held] = keys[i];
+ if (key.guid != k.guid)
continue;
- if (k.keycode != k_.keycode)
+ if (key.keycode != k.keycode)
continue;
- if (k_.held && !k.held) continue;
- if (k_.alt != k.alt) continue;
- if (k_.ctrl != k.ctrl) continue;
- if (k_.shift != k.shift) continue;
- if (!k_.should_process())
- continue;
-
- fun& f = std::get<1>(keys[i]);
- f(k.held);
+ if (k.held && !key.held) continue;
+ if (key.held)
+ {
+ if (k.alt != key.alt) continue;
+ if (k.ctrl != key.ctrl) continue;
+ if (k.shift != key.shift) continue;
+ if (!k.should_process())
+ continue;
+ }
+ f(key.held);
}
}
+
#endif
Shortcuts::~Shortcuts()
@@ -126,23 +135,24 @@ void Shortcuts::reload(const t_keys& keys_)
for (unsigned i = 0; i < sz; i++)
{
- const auto& kk = keys_[i];
- const key_opts& opts = std::get<0>(kk);
- const bool held = std::get<2>(kk);
- auto fun = std::get<1>(kk);
+ auto const&[opts, fun, held] = keys_[i];
#ifdef _WIN32
K k;
#else
K k(nullptr);
#endif
bind_shortcut(k, opts, held);
- keys.push_back(tt(k, [=](bool flag) { fun(flag); }, held));
+ keys.emplace_back(k, fun, held);
#ifndef _WIN32
const int idx = keys.size() - 1;
tt& kk_ = keys[idx];
- auto& fn = std::get<1>(kk_);
- connect(k, &QxtGlobalShortcut::activated, [=]() { fn(true); });
+ auto fn = std::get<1>(kk_);
+ bool held_ = held;
+ connect(k, &QxtGlobalShortcut::activated, [fn, held_](bool keydown) {
+ if (keydown || !held_)
+ fn(keydown);
+ });
#endif
}
}