diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-12 18:00:49 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-12 18:00:49 +0200 |
commit | 9040b187a1c4fa380f8a12207b9dd6d04b3a10ac (patch) | |
tree | 115e1351571d690c1261a9d512e6d44e717f3051 /dinput/keybinding-worker.hpp | |
parent | 13a18b149764509a3f460be86590250cdcf690fb (diff) |
all: rename modules s#^opentrack-##. and opentrack -> api
Adjust usages.
Diffstat (limited to 'dinput/keybinding-worker.hpp')
-rw-r--r-- | dinput/keybinding-worker.hpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/dinput/keybinding-worker.hpp b/dinput/keybinding-worker.hpp new file mode 100644 index 00000000..39b850e0 --- /dev/null +++ b/dinput/keybinding-worker.hpp @@ -0,0 +1,80 @@ +/* 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 "compat/timer.hpp" +#include "win32-joystick.hpp" +#include "dinput.hpp" +#include <QThread> +#include <QMutex> +#include <QWidget> +#include <QMainWindow> +#include <QDebug> +#include <functional> +#include <vector> + +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<void(const Key&)>; + +private: + LPDIRECTINPUTDEVICE8 dinkeyboard; + win32_joy_ctx joy_ctx; + std::vector<std::unique_ptr<fun>> receivers; + QMutex mtx; + QMainWindow fake_main_window; + dinput_handle::di_t din; + volatile bool should_quit; + + void run() override; + void init(); + 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); + } + }; +}; |