From 6e7af85c52e994fada7f989f4af2a6e793dedac9 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 10 Aug 2016 12:02:00 +0200 Subject: dinput: split from logic module For use in the joystick module. --- opentrack-dinput/keybinding-worker.hpp | 82 ++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 opentrack-dinput/keybinding-worker.hpp (limited to 'opentrack-dinput/keybinding-worker.hpp') diff --git a/opentrack-dinput/keybinding-worker.hpp b/opentrack-dinput/keybinding-worker.hpp new file mode 100644 index 00000000..439d2066 --- /dev/null +++ b/opentrack-dinput/keybinding-worker.hpp @@ -0,0 +1,82 @@ +/* Copyright (c) 2014-2015, Stanislaw Halik + + * 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 "dinput.hpp" +#include +#include +#include +#include +#include +#include + +#undef DIRECTINPUT_VERSION +#define DIRECTINPUT_VERSION 0x0800 +#include +#include + +struct OPENTRACK_DINPUT_EXPORT 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_DINPUT_EXPORT KeybindingWorker : private QThread +{ + using fun = std::function; + +private: + LPDIRECTINPUTDEVICE8 dinkeyboard; + win32_joy_ctx joy_ctx; + std::vector> receivers; + QMutex mtx; + QMainWindow fake_main_window; + volatile bool should_quit; + + void run() override; + KeybindingWorker(); + + static KeybindingWorker& make(); + fun* _add_receiver(fun &receiver); + void remove_receiver(fun* pos); + ~KeybindingWorker(); + + KeybindingWorker(const KeybindingWorker&) = delete; + KeybindingWorker& operator=(KeybindingWorker&) = delete; +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); + } + }; +}; -- cgit v1.2.3