summaryrefslogtreecommitdiffhomepage
path: root/opentrack/shortcuts.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-07-25 02:50:52 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-07-25 02:51:44 +0200
commit95114eccc774bbb0fbeade8904aafa4f9b6d143d (patch)
treee80f681b8374a91579ebd0fbfff9ecd48402e136 /opentrack/shortcuts.cpp
parent7d0c58540103e9182ba584b440b91068df03a49c (diff)
initial impl of arbitrary keybindings
Issue: #118 Linux and OSX likely broken for now.
Diffstat (limited to 'opentrack/shortcuts.cpp')
-rw-r--r--opentrack/shortcuts.cpp44
1 files changed, 16 insertions, 28 deletions
diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp
index ed1701c7..190c4003 100644
--- a/opentrack/shortcuts.cpp
+++ b/opentrack/shortcuts.cpp
@@ -7,6 +7,7 @@
*/
#include "shortcuts.h"
+#include "global-shortcuts.h"
#include <QMutexLocker>
#if defined(_WIN32)
@@ -124,38 +125,25 @@ void KeybindingWorker::run() {
void Shortcuts::bind_keyboard_shortcut(K &key, key_opts& k)
{
#if !defined(_WIN32)
- const int idx = k.key_index;
- if (!key)
- key = std::make_shared<QxtGlobalShortcut>();
- else {
- key->setEnabled(false);
- key->setShortcut(QKeySequence::UnknownKey);
- }
- if (idx > 0)
+ key->setEnabled(false);
+ key->setShortcut(QKeySequence::UnknownKey);
+
+ if (k.keycode)
{
- QString seq(global_key_sequences.value(idx, ""));
- if (!seq.isEmpty())
- {
- if (k.shift)
- seq = "Shift+" + seq;
- if (k.alt)
- seq = "Alt+" + seq;
- if (k.ctrl)
- seq = "Ctrl+" + seq;
- key->setShortcut(QKeySequence::fromString(seq, QKeySequence::PortableText));
- key->setEnabled();
- }
+ key->setShortcut(Qt::KeySequence(k.keycode));
+ key->setEnabled();
}
+}
#else
key = K();
- int idx = k.key_index;
- key.keycode = 0;
- key.shift = key.alt = key.ctrl = 0;
- if (idx > 0 && idx < global_windows_key_sequences.size())
- key.keycode = global_windows_key_sequences[idx];
- key.shift = k.shift;
- key.alt = k.alt;
- key.ctrl = k.ctrl;
+ int idx = 0;
+ Qt::KeyboardModifiers mods = Qt::NoModifier;
+ if (k.keycode != Qt::Key_unknown)
+ win_key::from_qt(QKeySequence(k.keycode), idx, mods);
+ key.shift = !!(mods & Qt::ShiftModifier);
+ key.alt = !!(mods & Qt::AltModifier);
+ key.ctrl = !!(mods & Qt::ControlModifier);
+ key.keycode = idx;
#endif
}