summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-11-22 15:07:23 +0100
committerStanislaw Halik <sthalik@misaki.pl>2015-11-22 15:55:40 +0100
commitbf5931532f91107747cc45befffb5cc189777c89 (patch)
treea1c5d99a971e04ad5a9e89f158941fcb711c7ff2
parenta9860e951757bf454b83b13ce7eff865f0b6644e (diff)
work: use the centralized keypress worker
-rw-r--r--gui/keyboard.h10
-rw-r--r--opentrack/shortcuts.cpp10
-rw-r--r--opentrack/shortcuts.h11
-rw-r--r--opentrack/work.hpp3
4 files changed, 12 insertions, 22 deletions
diff --git a/gui/keyboard.h b/gui/keyboard.h
index 75226aa3..696df605 100644
--- a/gui/keyboard.h
+++ b/gui/keyboard.h
@@ -13,13 +13,12 @@ class KeyboardListener : public QLabel
Q_OBJECT
Ui_keyboard_listener ui;
#ifdef _WIN32
- KeybindingWorker w;
+ KeybindingWorker::Token token;
#endif
public:
KeyboardListener(QWidget* parent = nullptr) : QLabel(parent)
#ifdef _WIN32
- , w([&](Key& k)
- {
+ , token([&](const Key& k) {
if(k.guid != "")
{
int mods = 0;
@@ -35,14 +34,11 @@ public:
if (win_key::to_qt(k, k_, m))
key_pressed(static_cast<QVariant>(k_).toInt() | m);
}
- }, this->winId())
+ })
#endif
{
ui.setupUi(this);
setFocusPolicy(Qt::StrongFocus);
-#ifdef _WIN32
- w.start();
-#endif
}
#ifndef _WIN32
void keyPressEvent(QKeyEvent* event) override
diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp
index 059febdb..b961294f 100644
--- a/opentrack/shortcuts.cpp
+++ b/opentrack/shortcuts.cpp
@@ -61,7 +61,7 @@ void Shortcuts::bind_keyboard_shortcut(K &key, key_opts& k)
#endif
#ifdef _WIN32
-void Shortcuts::receiver(Key &k)
+void Shortcuts::receiver(const Key& k)
{
std::vector<K*> ks { &keyCenter, &keyToggle, &keyZero };
for (K* k_ : ks)
@@ -92,12 +92,4 @@ void Shortcuts::reload() {
bind_keyboard_shortcut(keyCenter, s.center);
bind_keyboard_shortcut(keyToggle, s.toggle);
bind_keyboard_shortcut(keyZero, s.zero);
-#ifdef _WIN32
- bool is_new = keybindingWorker == nullptr;
- if (is_new)
- {
- keybindingWorker = std::make_shared<KeybindingWorker>([&](Key& k) { receiver(k); }, handle);
- keybindingWorker->start();
- }
-#endif
}
diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h
index 1643485e..930952e8 100644
--- a/opentrack/shortcuts.h
+++ b/opentrack/shortcuts.h
@@ -40,10 +40,8 @@ public:
K keyCenter;
K keyToggle;
K keyZero;
-
- WId handle;
#ifdef _WIN32
- mem<KeybindingWorker> keybindingWorker;
+ KeybindingWorker::Token key_token;
#endif
struct key_opts {
@@ -68,13 +66,16 @@ public:
{}
} s;
- Shortcuts(WId handle) : handle(handle) { reload(); }
+ Shortcuts() : key_token(KeybindingWorker::add_receiver([&](const Key& k) { receiver(k); }))
+ {
+ reload();
+ }
void reload();
private:
void bind_keyboard_shortcut(K &key, key_opts& k);
#ifdef _WIN32
- void receiver(Key& k);
+ void receiver(const Key& k);
#endif
signals:
void center();
diff --git a/opentrack/work.hpp b/opentrack/work.hpp
index 5d1f6b54..e338e9f4 100644
--- a/opentrack/work.hpp
+++ b/opentrack/work.hpp
@@ -28,7 +28,7 @@ struct Work
Work(main_settings& s, Mappings& m, SelectedLibraries& libs, QObject* recv, WId handle) :
s(s), libs(libs),
tracker(std::make_shared<Tracker>(s, m, libs)),
- sc(std::make_shared<Shortcuts>(handle)),
+ sc(std::make_shared<Shortcuts>()),
handle(handle)
{
#ifndef _WIN32
@@ -50,6 +50,7 @@ struct Work
~Work()
{
+ sc = nullptr;
// order matters, otherwise use-after-free -sh
tracker = nullptr;
libs = SelectedLibraries();