summaryrefslogtreecommitdiffhomepage
path: root/opentrack/keybinding-worker.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-12-05 23:30:43 +0100
committerStanislaw Halik <sthalik@misaki.pl>2015-12-05 23:30:43 +0100
commit578749c5b7f245aac08c4e514d2767dba059c4db (patch)
treeb3706f7342372d1efb2bd646b28b74abe371701b /opentrack/keybinding-worker.cpp
parentf9a6946d26dca681a14a5aacf523414dbc6bdfb3 (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.cpp')
-rw-r--r--opentrack/keybinding-worker.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/opentrack/keybinding-worker.cpp b/opentrack/keybinding-worker.cpp
index 3c801cf2..9ff825a0 100644
--- a/opentrack/keybinding-worker.cpp
+++ b/opentrack/keybinding-worker.cpp
@@ -119,7 +119,7 @@ void KeybindingWorker::run() {
k.held = held;
for (auto& r : receivers)
- r(k);
+ r->operator()(k);
};
joy_ctx.poll(f);
@@ -147,7 +147,7 @@ void KeybindingWorker::run() {
k.keycode = i;
for (auto& r : receivers)
- r(k);
+ r->operator()(k);
break;
}
}
@@ -160,12 +160,13 @@ void KeybindingWorker::run() {
}
}
-KeybindingWorker::fun* KeybindingWorker::_add_receiver(KeybindingWorker::fun receiver)
+KeybindingWorker::fun* KeybindingWorker::_add_receiver(fun& receiver)
{
QMutexLocker l(&mtx);
- receivers.push_back(receiver);
- qDebug() << "add receiver" << (long) &receivers[receivers.size()-1];
- return &receivers[receivers.size()-1];
+ receivers.push_back(std::unique_ptr<fun>(new fun(receiver)));
+ fun* f = receivers[receivers.size() - 1].get();
+ qDebug() << "add receiver" << (long) f;
+ return f;
}
void KeybindingWorker::remove_receiver(KeybindingWorker::fun* pos)
@@ -175,7 +176,7 @@ void KeybindingWorker::remove_receiver(KeybindingWorker::fun* pos)
for (int i = receivers.size() - 1; i >= 0; i--)
{
- if (&receivers[i] == pos)
+ if (receivers[i].get() == pos)
{
ok = true;
qDebug() << "remove receiver" << (long) pos;