diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-04-29 09:21:10 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-04-29 09:21:23 +0200 |
commit | 3a7011ff73cce39ecacb4c5651c1a2dbda8eb10e (patch) | |
tree | 84d21d48998aaacbad9cb27b7e5edf29b0dd1396 /opentrack | |
parent | 69cc802722c8264c0fd8b138a298d4820c11f1d8 (diff) |
api, main: implement new keybindings
The following keybindings are now implemented:
- restart tracking. if not started, starts.
- toggle (keep position) while key held
- zero (keep zero) while key held
The latter two options only work for Windows as libqxt doesn't support
them.
Closes #291
Diffstat (limited to 'opentrack')
-rwxr-xr-x[-rw-r--r--] | opentrack/keybinding-worker.cpp | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | opentrack/main-settings.hpp | 8 | ||||
-rwxr-xr-x[-rw-r--r--] | opentrack/shortcuts.cpp | 19 | ||||
-rwxr-xr-x[-rw-r--r--] | opentrack/shortcuts.h | 14 | ||||
-rwxr-xr-x[-rw-r--r--] | opentrack/tracker.h | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | opentrack/work.hpp | 16 |
6 files changed, 40 insertions, 23 deletions
diff --git a/opentrack/keybinding-worker.cpp b/opentrack/keybinding-worker.cpp index 39693a7c..2d133c2f 100644..100755 --- a/opentrack/keybinding-worker.cpp +++ b/opentrack/keybinding-worker.cpp @@ -126,8 +126,9 @@ void KeybindingWorker::run() { for (int i = 0; i < 256; i++) { Key k; - if (old_keystate[i] != keystate[i] && keystate[i] & 0x80) + if (old_keystate[i] != keystate[i]) { + const bool held = keystate[i] & 0x80; switch (i) { case DIK_LCONTROL: @@ -142,6 +143,7 @@ void KeybindingWorker::run() { k.alt = !!(keystate[DIK_LALT] & 0x80) || !!(keystate[DIK_RALT] & 0x80); k.ctrl = !!(keystate[DIK_LCONTROL] & 0x80) || !!(keystate[DIK_RCONTROL] & 0x80); k.keycode = i; + k.held = held; for (auto& r : receivers) r->operator()(k); diff --git a/opentrack/main-settings.hpp b/opentrack/main-settings.hpp index 793c52f7..7c04fd6d 100644..100755 --- a/opentrack/main-settings.hpp +++ b/opentrack/main-settings.hpp @@ -51,8 +51,9 @@ struct main_settings : opts { value<int> camera_yaw, camera_pitch, camera_roll; value<bool> center_at_startup; value<int> center_method; - key_opts key_start_tracking, key_stop_tracking, key_toggle_tracking; + key_opts key_start_tracking, key_stop_tracking, key_toggle_tracking, key_restart_tracking; key_opts key_center, key_toggle, key_zero; + key_opts key_toggle_press, key_zero_press; main_settings() : opts("opentrack-ui"), tracker_dll(b, "tracker-dll", ""), @@ -75,9 +76,12 @@ struct main_settings : opts { key_start_tracking(b, "start-tracking"), key_stop_tracking(b, "stop-tracking"), key_toggle_tracking(b, "toggle-tracking"), + key_restart_tracking(b, "restart-tracking"), key_center(b, "center"), key_toggle(b, "toggle"), - key_zero(b, "zero") + key_zero(b, "zero"), + key_toggle_press(b, "toggle-press"), + key_zero_press(b, "zero-press") { } }; diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp index bab1283a..aa1006c4 100644..100755 --- a/opentrack/shortcuts.cpp +++ b/opentrack/shortcuts.cpp @@ -9,7 +9,7 @@ #include "shortcuts.h" #include "win32-shortcuts.h" -void Shortcuts::bind_keyboard_shortcut(K &key, const key_opts& k) +void Shortcuts::bind_keyboard_shortcut(K &key, const key_opts& k, unused(bool, held)) { #if !defined(_WIN32) using sh = QxtGlobalShortcut; @@ -56,6 +56,7 @@ void Shortcuts::bind_keyboard_shortcut(K &key, const key_opts& k) key.alt = !!(mods & Qt::AltModifier); key.ctrl = !!(mods & Qt::ControlModifier); key.keycode = idx; + key.held = held; } } #endif @@ -72,20 +73,19 @@ void Shortcuts::receiver(const Key& k) continue; if (k.keycode != k_.keycode) continue; - if (!k.held) - continue; - if (!k_.should_process()) - continue; + if (k_.held && !k.held) continue; if (k_.alt && !k.alt) continue; if (k_.ctrl && !k.ctrl) continue; if (k_.shift && !k.shift) continue; + if (!k_.should_process()) + continue; - fun(); + fun(k.held); } } #endif -void Shortcuts::reload(const std::vector<std::tuple<key_opts&, fun> > &keys_) +void Shortcuts::reload(const std::vector<std::tuple<key_opts&, fun, bool>> &keys_) { const int sz = keys_.size(); keys = std::vector<tt>(); @@ -94,10 +94,11 @@ void Shortcuts::reload(const std::vector<std::tuple<key_opts&, fun> > &keys_) { const auto& kk = keys_[i]; const key_opts& opts = std::get<0>(kk); + const bool held = std::get<2>(kk); auto& fun = std::get<1>(kk); K k; - bind_keyboard_shortcut(k, opts); - keys.push_back(std::tuple<K, Shortcuts::fun>(k, fun)); + bind_keyboard_shortcut(k, opts, held); + keys.push_back(tt(k, fun, held)); #ifndef _WIN32 connect(k.get(), &QxtGlobalShortcut::activated, fun); #endif diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h index 38037923..40d41957 100644..100755 --- a/opentrack/shortcuts.h +++ b/opentrack/shortcuts.h @@ -26,6 +26,12 @@ # include "keybinding-worker.hpp" #endif +#ifdef __GNUC__ +# define unused(t, i) t __attribute__((unused)) i +#else +# define unused(t, i) t i +#endif + using namespace options; struct OPENTRACK_EXPORT Shortcuts : public QObject { @@ -40,8 +46,8 @@ public: #endif ; - using fun = std::function<void(void)>; - using tt = std::tuple<K, fun>; + using fun = std::function<void(bool)>; + using tt = std::tuple<K, fun, bool>; std::vector<tt> keys; #ifdef _WIN32 KeybindingWorker::Token key_token; @@ -53,9 +59,9 @@ public: #endif {} - void reload(const std::vector<std::tuple<key_opts &, fun> > &keys); + void reload(const std::vector<std::tuple<key_opts &, fun, bool>> &keys); private: - void bind_keyboard_shortcut(K &key, const key_opts& k); + void bind_keyboard_shortcut(K &key, const key_opts& k, bool held); #ifdef _WIN32 void receiver(const Key& k); #endif diff --git a/opentrack/tracker.h b/opentrack/tracker.h index 36b5cad4..079ce473 100644..100755 --- a/opentrack/tracker.h +++ b/opentrack/tracker.h @@ -81,6 +81,8 @@ public: void get_raw_and_mapped_poses(double* mapped, double* raw) const; void start() { QThread::start(); } void toggle_enabled() { qDebug() << "toggle enabled"; enabledp = !enabledp; } + void set_toggle(bool value) { qDebug() << "enabled" << value; enabledp = value; } + void set_zero(bool value) { qDebug() << "zero" << value; zero_ = value; } void center() { qDebug() << "toggle center"; centerp = !centerp; } void zero() { qDebug() << "toggle zero"; zero_ = !zero_; } }; diff --git a/opentrack/work.hpp b/opentrack/work.hpp index 4188b937..3b65ba52 100644..100755 --- a/opentrack/work.hpp +++ b/opentrack/work.hpp @@ -27,9 +27,9 @@ struct Work mem<Tracker> tracker; mem<Shortcuts> sc; WId handle; - using fn = std::function<void(void)>; - using tt = std::tuple<key_opts&, fn>; - std::vector<std::tuple<key_opts&, fn>> keys; + using fn = std::function<void(bool)>; + using tt = std::tuple<key_opts&, fn, bool>; + std::vector<tt> keys; Work(main_settings& s, Mappings& m, SelectedLibraries& libs, WId handle) : s(s), libs(libs), @@ -37,13 +37,15 @@ struct Work sc(std::make_shared<Shortcuts>()), handle(handle), keys { - tt(s.key_center, [&]() -> void { tracker->center(); }), - tt(s.key_toggle, [&]() -> void { tracker->toggle_enabled(); }), - tt(s.key_zero, [&]() -> void { tracker->zero(); }), + tt(s.key_center, [&](bool) -> void { tracker->center(); }, true), + tt(s.key_toggle, [&](bool) -> void { tracker->toggle_enabled(); }, true), + tt(s.key_zero, [&](bool) -> void { tracker->zero(); }, true), + tt(s.key_toggle_press, [&](bool x) -> void { tracker->set_toggle(!x); }, false), + tt(s.key_zero_press, [&](bool x) -> void { tracker->set_zero(x); }, false), } { reload_shortcuts(); - tracker->start(); + tracker->start(); } void reload_shortcuts() |