summaryrefslogtreecommitdiffhomepage
path: root/opentrack-logic/keybinding-worker.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/keybinding-worker.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/keybinding-worker.hpp')
-rw-r--r--opentrack-logic/keybinding-worker.hpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/opentrack-logic/keybinding-worker.hpp b/opentrack-logic/keybinding-worker.hpp
new file mode 100644
index 00000000..12237ab0
--- /dev/null
+++ b/opentrack-logic/keybinding-worker.hpp
@@ -0,0 +1,78 @@
+/* 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 "export.hpp"
+
+#include "opentrack-compat/timer.hpp"
+#include "win32-joystick.hpp"
+#include <QThread>
+#include <QMutex>
+#include <QWidget>
+#include <QMainWindow>
+#include <functional>
+#include <vector>
+
+#undef DIRECTINPUT_VERSION
+#define DIRECTINPUT_VERSION 0x0800
+#include <windows.h>
+#include <dinput.h>
+struct Key {
+ BYTE keycode;
+ QString guid;
+ bool shift;
+ bool ctrl;
+ bool alt;
+ bool held;
+ bool enabled;
+ Timer timer;
+public:
+ Key() : keycode(0), shift(false), ctrl(false), alt(false), held(true), enabled(true) {}
+
+ bool should_process();
+};
+
+struct OPENTRACK_LOGIC_EXPORT KeybindingWorker : private QThread
+{
+private:
+ LPDIRECTINPUT8 din;
+ LPDIRECTINPUTDEVICE8 dinkeyboard;
+ win32_joy_ctx joy_ctx;
+ volatile bool should_quit;
+ using fun = std::function<void(const Key&)>;
+ std::vector<std::unique_ptr<fun>> receivers;
+ QMutex mtx;
+ QMainWindow fake_main_window;
+
+ void run() override;
+ KeybindingWorker();
+
+ KeybindingWorker(const KeybindingWorker&) = delete;
+ KeybindingWorker& operator=(KeybindingWorker&) = delete;
+ static KeybindingWorker& make();
+ fun* _add_receiver(fun &receiver);
+ void remove_receiver(fun* pos);
+ ~KeybindingWorker();
+public:
+ class Token
+ {
+ fun* pos;
+ Token(const Token&) = delete;
+ Token& operator=(Token&) = delete;
+ public:
+ ~Token()
+ {
+ make().remove_receiver(pos);
+ }
+ Token(fun receiver)
+ {
+ pos = make()._add_receiver(receiver);
+ }
+ };
+};