summaryrefslogtreecommitdiffhomepage
path: root/dinput/keybinding-worker.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'dinput/keybinding-worker.hpp')
-rw-r--r--dinput/keybinding-worker.hpp35
1 files changed, 21 insertions, 14 deletions
diff --git a/dinput/keybinding-worker.hpp b/dinput/keybinding-worker.hpp
index 407b0107..1c22ca17 100644
--- a/dinput/keybinding-worker.hpp
+++ b/dinput/keybinding-worker.hpp
@@ -24,13 +24,13 @@
struct OTR_DINPUT_EXPORT Key
{
QString guid;
+ Timer timer;
int keycode = 0;
bool shift = false;
bool ctrl = false;
bool alt = false;
bool held = true;
bool enabled = true;
- Timer timer;
public:
Key();
@@ -41,45 +41,52 @@ struct OTR_DINPUT_EXPORT KeybindingWorker : private QThread
{
using fun = std::function<void(const Key&)>;
+ KeybindingWorker(const KeybindingWorker&) = delete;
+ KeybindingWorker& operator=(KeybindingWorker&) = delete;
+
private:
- LPDIRECTINPUTDEVICE8 dinkeyboard;
+ static constexpr int num_keyboard_states = 64;
+ static constexpr int num_mouse_buttons = 8;
+ static constexpr int first_mouse_button = 3;
+
+ IDirectInputDevice8A* dinkeyboard = nullptr, *dinmouse = nullptr;
win32_joy_ctx joy_ctx;
std::vector<std::unique_ptr<fun>> receivers;
QMutex mtx;
QMainWindow fake_main_window;
- dinput_handle::di_t din;
+ di_t din;
bool keystate[256] {};
- bool old_keystate[256] {};
+ bool mouse_state[num_mouse_buttons - first_mouse_button] = {};
void run() override;
+ bool run_keyboard_nolock();
+ bool run_joystick_nolock();
+ bool run_mouse_nolock();
+
bool init();
+ bool init_(IDirectInputDevice8A*& dev, const char* name, const GUID& guid, const DIDATAFORMAT& fmt);
KeybindingWorker();
static KeybindingWorker& make();
- fun* _add_receiver(fun &receiver);
+ fun* add_receiver(fun& receiver);
void remove_receiver(fun* pos);
- ~KeybindingWorker();
-
- static constexpr int num_keyboard_states = 128;
- DIDEVICEOBJECTDATA keyboard_states[num_keyboard_states];
-
- KeybindingWorker(const KeybindingWorker&) = delete;
- KeybindingWorker& operator=(KeybindingWorker&) = delete;
+ ~KeybindingWorker() override;
public:
class Token
{
fun* pos;
+ public:
Token(const Token&) = delete;
Token& operator=(Token&) = delete;
- public:
+
~Token()
{
make().remove_receiver(pos);
}
Token(fun receiver)
{
- pos = make()._add_receiver(receiver);
+ pos = make().add_receiver(receiver);
}
};
};