summaryrefslogtreecommitdiffhomepage
path: root/opentrack/win32-joystick-shortcuts.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-11-22 15:11:31 +0100
committerStanislaw Halik <sthalik@misaki.pl>2015-11-22 15:55:41 +0100
commit38a7253d20f7e29760e536e7e172a43d413a9372 (patch)
tree0b09a536be4e41dded13d754cdc0c622cc5fde46 /opentrack/win32-joystick-shortcuts.cpp
parentbf5931532f91107747cc45befffb5cc189777c89 (diff)
api/joy: implement a central joystick worker
- Make the dinput handle a singleton also across module boundaries. - Provide axis values per connected stick. - Robustify in case of sudden unplug.
Diffstat (limited to 'opentrack/win32-joystick-shortcuts.cpp')
-rw-r--r--opentrack/win32-joystick-shortcuts.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/opentrack/win32-joystick-shortcuts.cpp b/opentrack/win32-joystick-shortcuts.cpp
new file mode 100644
index 00000000..44659b7e
--- /dev/null
+++ b/opentrack/win32-joystick-shortcuts.cpp
@@ -0,0 +1,24 @@
+#include "win32-joystick-shortcuts.hpp"
+
+LPDIRECTINPUT8& win32_joy_ctx::dinput_handle()
+{
+ (void) CoInitialize(nullptr);
+
+ static LPDIRECTINPUT8 dinput_handle_ = nullptr;
+
+ if (dinput_handle_ == nullptr)
+ (void) DirectInput8Create(GetModuleHandle(nullptr),
+ DIRECTINPUT_VERSION,
+ IID_IDirectInput8,
+ (void**) &dinput_handle_,
+ nullptr);
+
+ return dinput_handle_;
+}
+
+std::unordered_map<QString, std::shared_ptr<win32_joy_ctx::joy>>& win32_joy_ctx::joys()
+{
+ static std::unordered_map<QString, std::shared_ptr<joy>> js;
+
+ return js;
+}