diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-01-13 14:14:20 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-01-13 14:24:05 +0100 |
commit | e0f0353dd5314d7836a7d3030e4895865f2e62ff (patch) | |
tree | 66a53ed743f36c1840c035841c80c42e55534f7f /dinput | |
parent | c6cdf9cfc701b5c9f02f37178b8364abd0bf4d93 (diff) |
dinput: don't include <windows.h> in headers
Issue: #583
Diffstat (limited to 'dinput')
-rw-r--r-- | dinput/dinput.cpp | 3 | ||||
-rw-r--r-- | dinput/dinput.hpp | 16 | ||||
-rw-r--r-- | dinput/keybinding-worker.cpp | 4 | ||||
-rw-r--r-- | dinput/keybinding-worker.hpp | 1 | ||||
-rw-r--r-- | dinput/win32-joystick.cpp | 10 | ||||
-rw-r--r-- | dinput/win32-joystick.hpp | 17 |
6 files changed, 32 insertions, 19 deletions
diff --git a/dinput/dinput.cpp b/dinput/dinput.cpp index 31de40e7..7a0e9cab 100644 --- a/dinput/dinput.cpp +++ b/dinput/dinput.cpp @@ -5,6 +5,7 @@ #include <cassert> #include <cstdlib> +#include <dinput.h> #include <QDebug> @@ -60,7 +61,7 @@ diptr di_t::init_di_() di_t::di_t() = default; -bool di_t::poll_device(LPDIRECTINPUTDEVICE8 dev) +bool di_t::poll_device(IDirectInputDevice8A* dev) { HRESULT hr; assert(handle); diff --git a/dinput/dinput.hpp b/dinput/dinput.hpp index e9908a94..09c9a30b 100644 --- a/dinput/dinput.hpp +++ b/dinput/dinput.hpp @@ -15,7 +15,19 @@ #undef DIRECTINPUT_VERSION #define DIRECTINPUT_VERSION 0x800 -#include <dinput.h> +struct IDirectInputDevice8A; +typedef struct IDirectInputDevice8A IDirectInputDevice8A; +struct IDirectInput8A; +typedef struct IDirectInput8A IDirectInput8A; +struct _GUID; +typedef struct _GUID GUID; +struct _DIDATAFORMAT; +typedef struct _DIDATAFORMAT DIDATAFORMAT; +typedef int BOOL; +struct DIDEVICEINSTANCEA; +typedef struct DIDEVICEINSTANCEA DIDEVICEINSTANCEA; +struct DIDEVICEOBJECTINSTANCEA; +typedef struct DIDEVICEOBJECTINSTANCEA DIDEVICEOBJECTINSTANCEA; // XXX TODO -sh 20190209 // keybinding_worker and joystick context are badly named @@ -39,5 +51,5 @@ public: operator bool() const; operator diptr() const; - static bool poll_device(LPDIRECTINPUTDEVICE8 dev); + static bool poll_device(IDirectInputDevice8A* dev); }; diff --git a/dinput/keybinding-worker.cpp b/dinput/keybinding-worker.cpp index 91b02428..fc30bcd3 100644 --- a/dinput/keybinding-worker.cpp +++ b/dinput/keybinding-worker.cpp @@ -15,7 +15,7 @@ #include <QDebug> #include <QMutexLocker> -#include <windows.h> +#include <dinput.h> Key::Key() = default; @@ -153,6 +153,8 @@ bool KeybindingWorker::run_keyboard_nolock() if (!di_t::poll_device(dinkeyboard)) eval_once(qDebug() << "dinput: keyboard poll failed"); + DIDEVICEOBJECTDATA keyboard_states[num_keyboard_states] = {}; + DWORD sz = num_keyboard_states; HRESULT hr = dinkeyboard->GetDeviceData(sizeof(*keyboard_states), keyboard_states, &sz, 0); diff --git a/dinput/keybinding-worker.hpp b/dinput/keybinding-worker.hpp index 335a5c11..6b21bd01 100644 --- a/dinput/keybinding-worker.hpp +++ b/dinput/keybinding-worker.hpp @@ -67,7 +67,6 @@ private: ~KeybindingWorker() override; static constexpr int num_keyboard_states = 64; - DIDEVICEOBJECTDATA keyboard_states[num_keyboard_states] {}; public: class Token { diff --git a/dinput/win32-joystick.cpp b/dinput/win32-joystick.cpp index 3b83a7f1..5a372710 100644 --- a/dinput/win32-joystick.cpp +++ b/dinput/win32-joystick.cpp @@ -11,13 +11,13 @@ #include <QWidget> #include <QDebug> +#include <dinput.h> #include <objbase.h> namespace win32_joy_impl { QMutex win32_joy_ctx::enum_state::mtx; win32_joy_ctx::enum_state win32_joy_ctx::enumerator; -DIDEVICEOBJECTDATA win32_joy_ctx::joy::keystate_buffers[num_buffers] = {}; void win32_joy_ctx::poll(fn const& f) { @@ -142,6 +142,8 @@ bool win32_joy_ctx::joy::poll(fn const& f) return false; } + DIDEVICEOBJECTDATA keystate_buffers[num_buffers] = {}; + DWORD sz = num_buffers; if (FAILED(hr = joy_handle->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), keystate_buffers, &sz, 0))) { @@ -273,7 +275,7 @@ BOOL CALLBACK win32_joy_ctx::enum_state::EnumJoysticksCallback(const DIDEVICEINS { HRESULT hr; - LPDIRECTINPUTDEVICE8 h; + IDirectInputDevice8A* h; if (FAILED(hr = state.di->CreateDevice(pdidInstance->guidInstance, &h, nullptr))) { qDebug() << "dinput: failed joystick CreateDevice" << guid << (void*)hr; @@ -339,7 +341,7 @@ BOOL CALLBACK win32_joy_ctx::enum_state::EnumObjectsCallback(const DIDEVICEOBJEC HRESULT hr; - if (FAILED(hr = reinterpret_cast<LPDIRECTINPUTDEVICE8>(ctx)->SetProperty(DIPROP_RANGE, &diprg.diph))) + if (FAILED(hr = reinterpret_cast<IDirectInputDevice8A*>(ctx)->SetProperty(DIPROP_RANGE, &diprg.diph))) { qDebug() << "dinput: failed joystick DIPROP_RANGE" << (void*)hr; return DIENUM_STOP; @@ -349,7 +351,7 @@ BOOL CALLBACK win32_joy_ctx::enum_state::EnumObjectsCallback(const DIDEVICEOBJEC return DIENUM_CONTINUE; } -win32_joy_ctx::joy::joy(LPDIRECTINPUTDEVICE8 handle, const QString& guid, const QString &name) +win32_joy_ctx::joy::joy(IDirectInputDevice8A* handle, const QString& guid, const QString &name) : joy_handle(handle), guid(guid), name(name) { //qDebug() << "make joy" << guid << name << joy_handle; diff --git a/dinput/win32-joystick.hpp b/dinput/win32-joystick.hpp index ff52ad1d..8e5344d6 100644 --- a/dinput/win32-joystick.hpp +++ b/dinput/win32-joystick.hpp @@ -10,6 +10,7 @@ #include "dinput.hpp" #include "compat/timer.hpp" #include "export.hpp" +#include "compat/qhash.hpp" #include <memory> #include <vector> @@ -17,15 +18,13 @@ #include <unordered_map> #include <iterator> -#include "compat/qhash.hpp" #include <QString> #include <QMutex> namespace win32_joy_impl { -static constexpr unsigned max_buttons = std::size(DIJOYSTATE2().rgbButtons); -static constexpr unsigned max_pov_hats = std::size(DIJOYSTATE2().rgdwPOV); - +static constexpr unsigned max_buttons = 128; +static constexpr unsigned max_pov_hats = 4; static constexpr unsigned pov_hat_directions = 8; // cf. https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee416628(v=vs.85) @@ -48,13 +47,11 @@ struct OTR_DINPUT_EXPORT win32_joy_ctx final struct joy final { - LPDIRECTINPUTDEVICE8 joy_handle; + IDirectInputDevice8A* joy_handle; QString guid, name; bool last_state[max_buttons_and_pov_hats] {}; - static DIDEVICEOBJECTDATA keystate_buffers[num_buffers]; - - joy(LPDIRECTINPUTDEVICE8 handle, const QString& guid, const QString& name); + joy(IDirectInputDevice8A* handle, const QString& guid, const QString& name); ~joy(); void release(); @@ -89,8 +86,8 @@ private: joys_t joys; di_t di; - static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, VOID* pContext); - static BOOL CALLBACK EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* ctx); + static BOOL __stdcall EnumJoysticksCallback(const DIDEVICEINSTANCEA* pdidInstance, void* pContext); + static BOOL __stdcall EnumObjectsCallback(const DIDEVICEOBJECTINSTANCEA* pdidoi, void* ctx); public: static QMutex mtx; |