summaryrefslogtreecommitdiffhomepage
path: root/opentrack-logic/work.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-06-16 12:34:31 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-06-16 12:35:51 +0200
commit0760fe011114fa440275b487eaf766b015f40e5b (patch)
treea0141fb291b7dc1e38d16dd0eb2c767ec93b310a /opentrack-logic/work.hpp
parent60460f56cabe0155996adf8ba5e9f6730ef0b203 (diff)
all: split "api" into "api" and "logic"
Here, the "logic" module has all the stuff for building one's own graphical user interface. The "api" module has stuff used by other trackers. While at it, each of "api", "logic", and "compat" need their own export headers. This is because of preprocessor symbol clashes. This is all because a change in the "gui"-only dependency required a relink of all the trackers, protocols, and flters. It takes too long when building in the release configuration. With the split, only the "gui" module gets rebuilt. Since it has close to no static dependencies, it's fast enough.
Diffstat (limited to 'opentrack-logic/work.hpp')
-rw-r--r--opentrack-logic/work.hpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/opentrack-logic/work.hpp b/opentrack-logic/work.hpp
new file mode 100644
index 00000000..2377be5a
--- /dev/null
+++ b/opentrack-logic/work.hpp
@@ -0,0 +1,63 @@
+/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>
+
+ * Permission to use, copy, modify, and/or distribute this
+ * software for any purpose with or without fee is hereby granted,
+ * provided that the above copyright notice and this permission
+ * notice appear in all copies.
+ */
+
+#pragma once
+
+#include "main-settings.hpp"
+#include "opentrack/plugin-support.hpp"
+#include "tracker.h"
+#include "shortcuts.h"
+
+#include <QObject>
+#include <QFrame>
+#include <memory>
+#include <vector>
+#include <functional>
+#include <tuple>
+
+struct Work
+{
+ main_settings& s;
+ SelectedLibraries& libs;
+ mem<Tracker> tracker;
+ mem<Shortcuts> sc;
+ WId handle;
+ 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),
+ tracker(std::make_shared<Tracker>(s, m, libs)),
+ sc(std::make_shared<Shortcuts>()),
+ 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);
+ }
+
+ ~Work()
+ {
+ sc = nullptr;
+ // order matters, otherwise use-after-free -sh
+ tracker = nullptr;
+ libs = SelectedLibraries();
+ }
+};