From c25ad3f1936028590358558bbf87b80c33613261 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 22 Jul 2016 10:24:22 +0200 Subject: logic/work: move from header --- opentrack-logic/work.cpp | 32 +++++++++++++++++++++++++++++++ opentrack-logic/work.hpp | 50 +++++++++++++----------------------------------- 2 files changed, 45 insertions(+), 37 deletions(-) create mode 100644 opentrack-logic/work.cpp (limited to 'opentrack-logic') diff --git a/opentrack-logic/work.cpp b/opentrack-logic/work.cpp new file mode 100644 index 00000000..820112bf --- /dev/null +++ b/opentrack-logic/work.cpp @@ -0,0 +1,32 @@ +#include "work.hpp" + + +Work::Work(Mappings& m, SelectedLibraries& libs, WId handle) : + libs(libs), + tracker(std::make_shared(m, libs)), + sc(std::make_shared()), + handle(handle), + keys { + key_tuple(s.key_center, [&](bool) -> void { tracker->center(); }, true), + key_tuple(s.key_toggle, [&](bool) -> void { tracker->toggle_enabled(); }, true), + key_tuple(s.key_zero, [&](bool) -> void { tracker->zero(); }, true), + key_tuple(s.key_toggle_press, [&](bool x) -> void { tracker->set_toggle(!x); }, false), + key_tuple(s.key_zero_press, [&](bool x) -> void { tracker->set_zero(x); }, false), + } +{ + reload_shortcuts(); + tracker->start(); +} + +void Work::reload_shortcuts() +{ + sc->reload(keys); +} + +Work::~Work() +{ + sc = nullptr; + // order matters, otherwise use-after-free -sh + tracker = nullptr; + libs = SelectedLibraries(); +} diff --git a/opentrack-logic/work.hpp b/opentrack-logic/work.hpp index 37bc58bf..70322be2 100644 --- a/opentrack-logic/work.hpp +++ b/opentrack-logic/work.hpp @@ -12,52 +12,28 @@ #include "opentrack/plugin-support.hpp" #include "tracker.h" #include "shortcuts.h" +#include "export.hpp" #include #include #include #include -#include #include +#include -struct Work +struct OPENTRACK_LOGIC_EXPORT Work { - main_settings s; + using fn_t = std::function; + using key_tuple = std::tuple; + SelectedLibraries& libs; - mem tracker; - mem sc; + std::shared_ptr tracker; + std::shared_ptr sc; WId handle; - using fn = std::function; - using tt = std::tuple; - std::vector keys; - - Work(Mappings& m, SelectedLibraries& libs, WId handle) : - libs(libs), - tracker(std::make_shared(m, libs)), - sc(std::make_shared()), - handle(handle), - keys { - 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(); - } - - void reload_shortcuts() - { - sc->reload(keys); - } + std::vector keys; + main_settings s; - ~Work() - { - sc = nullptr; - // order matters, otherwise use-after-free -sh - tracker = nullptr; - libs = SelectedLibraries(); - } + Work(Mappings& m, SelectedLibraries& libs, WId handle); + ~Work(); + void reload_shortcuts(); }; -- cgit v1.2.3