diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-12-05 23:30:43 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-12-05 23:30:43 +0100 |
commit | 578749c5b7f245aac08c4e514d2767dba059c4db (patch) | |
tree | b3706f7342372d1efb2bd646b28b74abe371701b /opentrack/keybinding-worker.hpp | |
parent | f9a6946d26dca681a14a5aacf523414dbc6bdfb3 (diff) |
api/keys: fix multiple shortcut receivers
We can't depend on std::vector's address of array subscript to remain
constant, duh.
Diffstat (limited to 'opentrack/keybinding-worker.hpp')
-rw-r--r-- | opentrack/keybinding-worker.hpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/opentrack/keybinding-worker.hpp b/opentrack/keybinding-worker.hpp index 5b669331..c8d8e009 100644 --- a/opentrack/keybinding-worker.hpp +++ b/opentrack/keybinding-worker.hpp @@ -47,8 +47,8 @@ private: LPDIRECTINPUTDEVICE8 dinkeyboard; win32_joy_ctx& joy_ctx; volatile bool should_quit; - using fun = std::function<void(Key&)>; - std::vector<fun> receivers; + using fun = std::function<void(const Key&)>; + std::vector<std::unique_ptr<fun>> receivers; QMutex mtx; void run() override; @@ -57,27 +57,23 @@ private: KeybindingWorker(const KeybindingWorker&) = delete; KeybindingWorker& operator=(KeybindingWorker&) = delete; static KeybindingWorker& make(); - fun* _add_receiver(fun receiver); + fun* _add_receiver(fun &receiver); void remove_receiver(fun* pos); ~KeybindingWorker(); public: class Token { fun* pos; - //Token(const Token&) = delete; + Token(const Token&) = delete; Token& operator=(Token&) = delete; public: - Token(fun receiver) - { - pos = make()._add_receiver(receiver); - } ~Token() { make().remove_receiver(pos); } + Token(fun receiver) + { + pos = make()._add_receiver(receiver); + } }; - static Token add_receiver(fun receiver) - { - return Token(receiver); - } }; |