diff options
Diffstat (limited to 'gui')
-rw-r--r-- | gui/keyboard.cpp | 50 | ||||
-rw-r--r-- | gui/keyboard.h | 10 |
2 files changed, 34 insertions, 26 deletions
diff --git a/gui/keyboard.cpp b/gui/keyboard.cpp index dbc3ab3a..90849bab 100644 --- a/gui/keyboard.cpp +++ b/gui/keyboard.cpp @@ -1,39 +1,43 @@ +#undef NDEBUG +#include <cassert> + #include "keyboard.h" #include <QDebug> #ifdef _WIN32 -auto keyboard_listener::make_token() + +void keyboard_listener::receive_key(const Key& k) { - return [this](const Key& k) { - if(!k.guid.isEmpty()) - { - int mods = 0; - if (k.alt) mods |= Qt::AltModifier; - if (k.shift) mods |= Qt::ShiftModifier; - if (k.ctrl) mods |= Qt::ControlModifier; - emit joystick_button_pressed(k.guid, k.keycode | mods, k.held); - } - else - { - Qt::KeyboardModifiers m; - QKeySequence k_; - if (win_key::to_qt(k, k_, m)) - emit key_pressed({ int(m) | int(k_) }); - } - }; + if(!k.guid.isEmpty()) + { + int mods = 0; + if (k.alt) mods |= Qt::AltModifier; + if (k.shift) mods |= Qt::ShiftModifier; + if (k.ctrl) mods |= Qt::ControlModifier; + + emit joystick_button_pressed(k.guid, k.keycode | mods, k.held); + } + else + { + Qt::KeyboardModifiers m; + QKeySequence k_; + + if (win_key::to_qt(k, k_, m)) + for (unsigned i = 0; i < (unsigned)k_.count(); i++) + emit key_pressed(QKeySequence(int(m) | k_[i])); + } } #endif -keyboard_listener::keyboard_listener(QWidget* parent) : - QDialog(parent) -#ifdef _WIN32 - , token(make_token()) -#endif +keyboard_listener::keyboard_listener(QWidget* parent) : QDialog(parent) { ui.setupUi(this); setFocusPolicy(Qt::StrongFocus); +#ifdef _WIN32 + (void)token; +#endif } #if !defined _WIN32 diff --git a/gui/keyboard.h b/gui/keyboard.h index 0a06a3af..ea35d372 100644 --- a/gui/keyboard.h +++ b/gui/keyboard.h @@ -22,13 +22,17 @@ class OTR_GUI_EXPORT keyboard_listener : public QDialog { Q_OBJECT - Ui_keyboard_listener ui; + #ifdef _WIN32 - auto make_token(); - KeybindingWorker::Token token; + void receive_key(const Key& k); + + KeybindingWorker::Token token{[this](const Key& k) {receive_key(k);}}; #else void keyPressEvent(QKeyEvent* event) override; #endif + + Ui_keyboard_listener ui; + public: keyboard_listener(QWidget* parent = nullptr); signals: |