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.hpp46
1 files changed, 29 insertions, 17 deletions
diff --git a/dinput/keybinding-worker.hpp b/dinput/keybinding-worker.hpp
index 553a314c..1c22ca17 100644
--- a/dinput/keybinding-worker.hpp
+++ b/dinput/keybinding-worker.hpp
@@ -24,15 +24,15 @@
struct OTR_DINPUT_EXPORT Key
{
QString guid;
- int keycode;
- bool shift;
- bool ctrl;
- bool alt;
- bool held;
- bool enabled;
Timer timer;
+ int keycode = 0;
+ bool shift = false;
+ bool ctrl = false;
+ bool alt = false;
+ bool held = true;
+ bool enabled = true;
public:
- Key() : keycode(0), shift(false), ctrl(false), alt(false), held(true), enabled(true) {}
+ Key();
bool should_process();
};
@@ -41,40 +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;
- volatile bool should_quit;
+ di_t din;
+
+ bool 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();
-
- 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);
}
};
};