diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-12-06 00:43:58 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-12-06 00:43:58 +0100 |
commit | 52b75a02aeeaf2c23f5af32fededf4e5fb24bade (patch) | |
tree | 158d9a60763ce6a149ee12f78bc746a0dc8670fc /opentrack | |
parent | 0f577dbe8adb8f7e210241c6bee0be73349f8d45 (diff) |
api, main: implement global shortcuts for controlling tracking
Issue: #252
That involves moving stuff around to get rid of circular dependencies.
You need to bind keys to shortcuts again this once.
Diffstat (limited to 'opentrack')
-rw-r--r-- | opentrack/main-settings.hpp | 26 | ||||
-rw-r--r-- | opentrack/shortcuts.h | 27 | ||||
-rw-r--r-- | opentrack/work.hpp | 7 |
3 files changed, 27 insertions, 33 deletions
diff --git a/opentrack/main-settings.hpp b/opentrack/main-settings.hpp index b7b086ad..793c52f7 100644 --- a/opentrack/main-settings.hpp +++ b/opentrack/main-settings.hpp @@ -32,7 +32,18 @@ private: } }; -struct main_settings : opts { +struct key_opts { + value<QString> keycode, guid; + value<int> button; + + key_opts(pbundle b, const QString& name) : + keycode(b, QString("keycode-%1").arg(name), ""), + guid(b, QString("guid-%1").arg(name), ""), + button(b, QString("button-%1").arg(name), -1) + {} +}; + +struct main_settings : opts { value<QString> tracker_dll, filter_dll, protocol_dll; axis_opts a_x, a_y, a_z, a_yaw, a_pitch, a_roll; value<bool> tcomp_p, tcomp_tz; @@ -40,6 +51,8 @@ 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_center, key_toggle, key_zero; main_settings() : opts("opentrack-ui"), tracker_dll(b, "tracker-dll", ""), @@ -58,6 +71,13 @@ struct main_settings : opts { camera_pitch(b, "camera-pitch", 0), camera_roll(b, "camera-roll", 0), center_at_startup(b, "center-at-startup", true), - center_method(b, "centering-method", true) - {} + center_method(b, "centering-method", true), + key_start_tracking(b, "start-tracking"), + key_stop_tracking(b, "stop-tracking"), + key_toggle_tracking(b, "toggle-tracking"), + key_center(b, "center"), + key_toggle(b, "toggle"), + key_zero(b, "zero") + { + } }; diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h index 4dec7c2c..f8343ad8 100644 --- a/opentrack/shortcuts.h +++ b/opentrack/shortcuts.h @@ -46,31 +46,6 @@ public: #ifdef _WIN32 KeybindingWorker::Token key_token; #endif - - struct key_opts { - value<QString> keycode, guid; - value<int> button; - - key_opts(pbundle b, const QString& name) : - keycode(b, QString("keycode-%1").arg(name), ""), - guid(b, QString("guid-%1").arg(name), ""), - button(b, QString("button-%1").arg(name), -1) - {} - }; - - struct settings : opts { - key_opts center, toggle, zero, start_tracking, stop_tracking, toggle_tracking; - main_settings s_main; - settings() : - opts("keyboard-shortcuts"), - center(b, "center"), - toggle(b, "toggle"), - zero(b, "zero"), - start_tracking(b, "start-tracking"), - stop_tracking(b, "stop-tracking"), - toggle_tracking(b, "toggle-tracking") - {} - } s; Shortcuts() : #ifdef _WIN32 @@ -78,7 +53,7 @@ public: #endif {} - void reload(const std::vector<std::tuple<Shortcuts::key_opts &, Shortcuts::fun> > &keys); + void reload(const std::vector<std::tuple<key_opts &, fun> > &keys); private: void bind_keyboard_shortcut(K &key, const key_opts& k); #ifdef _WIN32 diff --git a/opentrack/work.hpp b/opentrack/work.hpp index a3c0e014..4188b937 100644 --- a/opentrack/work.hpp +++ b/opentrack/work.hpp @@ -28,7 +28,6 @@ struct Work mem<Shortcuts> sc; WId handle; using fn = std::function<void(void)>; - using key_opts = Shortcuts::key_opts; using tt = std::tuple<key_opts&, fn>; std::vector<std::tuple<key_opts&, fn>> keys; @@ -38,9 +37,9 @@ struct Work sc(std::make_shared<Shortcuts>()), handle(handle), keys { - tt(sc->s.center, [&]() -> void { tracker->center(); }), - tt(sc->s.toggle, [&]() -> void { tracker->toggle_enabled(); }), - tt(sc->s.zero, [&]() -> void { tracker->zero(); }), + tt(s.key_center, [&]() -> void { tracker->center(); }), + tt(s.key_toggle, [&]() -> void { tracker->toggle_enabled(); }), + tt(s.key_zero, [&]() -> void { tracker->zero(); }), } { reload_shortcuts(); |