summaryrefslogtreecommitdiffhomepage
path: root/dinput
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-12-06 08:05:57 +0100
committerStanislaw Halik <sthalik@misaki.pl>2018-12-06 08:11:01 +0100
commit3fd39cf892250545b4510065fe16e39d494faa44 (patch)
tree7f52c9a4a5257778cdd8cb3c46e038a368eb2768 /dinput
parent94600f2c5f234dddf826c9d6d9db91952832220a (diff)
cruft only
Diffstat (limited to 'dinput')
-rw-r--r--dinput/keybinding-worker.cpp14
-rw-r--r--dinput/keybinding-worker.hpp2
-rw-r--r--dinput/win32-joystick.cpp47
3 files changed, 26 insertions, 37 deletions
diff --git a/dinput/keybinding-worker.cpp b/dinput/keybinding-worker.cpp
index a3331323..aa8faca8 100644
--- a/dinput/keybinding-worker.cpp
+++ b/dinput/keybinding-worker.cpp
@@ -48,12 +48,12 @@ bool KeybindingWorker::init()
}
if (din->CreateDevice(GUID_SysKeyboard, &dinkeyboard, nullptr) != DI_OK) {
- qDebug() << "setup CreateDevice function failed!" << GetLastError();
+ qDebug() << "dinput: create keyboard failed" << GetLastError();
return false;
}
if (dinkeyboard->SetDataFormat(&c_dfDIKeyboard) != DI_OK) {
- qDebug() << "setup SetDataFormat function failed!" << GetLastError();
+ qDebug() << "dinput: keyboard SetDataFormat" << GetLastError();
dinkeyboard->Release();
dinkeyboard = nullptr;
return false;
@@ -62,20 +62,20 @@ bool KeybindingWorker::init()
if (dinkeyboard->SetCooperativeLevel((HWND) fake_main_window.winId(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND) != DI_OK) {
dinkeyboard->Release();
dinkeyboard = nullptr;
- qDebug() << "setup SetCooperativeLevel function failed!" << GetLastError();
+ qDebug() << "dinput: keyboard SetCooperativeLevel" << GetLastError();
return false;
}
{
DIPROPDWORD dipdw;
- dipdw.dwData = 128;
+ dipdw.dwData = num_keyboard_states;
dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.diph.dwObj = 0;
dipdw.diph.dwSize = sizeof(dipdw);
if ( dinkeyboard->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph) != DI_OK)
{
- qDebug() << "setup keyboard buffer mode failed!";
+ qDebug() << "dinput: DIPROP_BUFFERSIZE";
dinkeyboard->Release();
dinkeyboard = nullptr;
return false;
@@ -86,7 +86,7 @@ bool KeybindingWorker::init()
{
dinkeyboard->Release();
dinkeyboard = nullptr;
- qDebug() << "setup dinkeyboard Acquire failed!" << GetLastError();
+ qDebug() << "dinput: acquire keyboard failed" << GetLastError();
return false;
}
@@ -147,7 +147,7 @@ bool KeybindingWorker::run_keyboard_nolock()
if (hr != DI_OK)
{
- eval_once(qDebug() << "dinput: keyboard GetDeviceData failed" << hr);
+ eval_once(qDebug() << "dinput: keyboard GetDeviceData" << hr);
return false;
}
diff --git a/dinput/keybinding-worker.hpp b/dinput/keybinding-worker.hpp
index fad9ec7e..ec403c15 100644
--- a/dinput/keybinding-worker.hpp
+++ b/dinput/keybinding-worker.hpp
@@ -64,7 +64,7 @@ private:
void remove_receiver(fun* pos);
~KeybindingWorker();
- static constexpr int num_keyboard_states = 16;
+ static constexpr int num_keyboard_states = 64;
DIDEVICEOBJECTDATA keyboard_states[num_keyboard_states] {};
KeybindingWorker(const KeybindingWorker&) = delete;
diff --git a/dinput/win32-joystick.cpp b/dinput/win32-joystick.cpp
index 4da5c57d..71c93543 100644
--- a/dinput/win32-joystick.cpp
+++ b/dinput/win32-joystick.cpp
@@ -3,19 +3,11 @@
#include "win32-joystick.hpp"
#include "compat/macros.hpp"
-// doesn't play well with Qt Creator clang code model
-#if defined Q_CREATOR_RUN && defined _MSC_VER
-# undef offsetof
-# define offsetof(type, member) __builtin_offsetof(type, member)
-#else
-# include <cstddef>
-#endif
-
+#include <cstddef>
#include <algorithm>
#include <cmath>
#include <QWidget>
-
#include <QDebug>
#include <objbase.h>
@@ -59,19 +51,15 @@ bool win32_joy_ctx::poll_axis(const QString &guid, int* axes)
bool ok = false;
HRESULT hr;
- if (!FAILED(hr = joy_handle->Poll()))
+ if (SUCCEEDED(hr = joy_handle->Poll()))
+ ok = true;
+ else if (SUCCEEDED(hr = joy_handle->Acquire()) && SUCCEEDED(hr = joy_handle->Poll()))
ok = true;
-
- if (!ok && FAILED(hr = joy_handle->Acquire()))
- {
- (void)0;
- //qDebug() << "joy acquire failed" << hr;
- }
if (!ok)
{
(void)joy_handle->Unacquire();
- Sleep(100);
+ Sleep(0);
continue;
}
@@ -80,7 +68,7 @@ bool win32_joy_ctx::poll_axis(const QString &guid, int* axes)
if (FAILED(hr = joy_handle->GetDeviceState(sizeof(js), &js)))
{
//qDebug() << "joy get state failed" << guid << hr;
- Sleep(500);
+ Sleep(0);
continue;
}
@@ -133,11 +121,12 @@ void win32_joy_ctx::refresh()
QString win32_joy_ctx::guid_to_string(const GUID& guid)
{
- char buf[40] = {0};
- wchar_t szGuidW[40] = {0};
+ char buf[40] = {};
+ wchar_t szGuidW[40] = {};
- StringFromGUID2(guid, szGuidW, 40);
- WideCharToMultiByte(0, 0, szGuidW, -1, buf, 40, nullptr, nullptr);
+ StringFromGUID2(guid, szGuidW, sizeof(buf));
+ WideCharToMultiByte(0, 0, szGuidW, -1, buf, sizeof(buf), nullptr, nullptr);
+ buf[sizeof(buf)-1] = 0;
return QString(buf);
}
@@ -254,7 +243,7 @@ void win32_joy_ctx::enum_state::refresh()
if (!di)
{
- qDebug() << "can't create dinput";
+ qDebug() << "dinput: can't create dinput";
return;
}
@@ -265,7 +254,7 @@ void win32_joy_ctx::enum_state::refresh()
this,
DIEDFL_ATTACHEDONLY)))
{
- eval_once(qDebug() << "failed enum joysticks" << hr);
+ eval_once(qDebug() << "dinput: failed enum joysticks" << hr);
return;
}
@@ -298,12 +287,12 @@ BOOL CALLBACK win32_joy_ctx::enum_state::EnumJoysticksCallback(const DIDEVICEINS
LPDIRECTINPUTDEVICE8 h;
if (FAILED(hr = state.di->CreateDevice(pdidInstance->guidInstance, &h, nullptr)))
{
- qDebug() << "createdevice" << guid << hr;
+ qDebug() << "dinput: joystick CreateDevice" << guid << hr;
goto end;
}
if (FAILED(h->SetDataFormat(&c_dfDIJoystick2)))
{
- qDebug() << "format";
+ qDebug() << "dinput: joystick SetDataFormat";
h->Release();
goto end;
}
@@ -328,7 +317,7 @@ BOOL CALLBACK win32_joy_ctx::enum_state::EnumJoysticksCallback(const DIDEVICEINS
if (h->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph) != DI_OK)
{
- qDebug() << "setup joystick buffer mode failed!";
+ qDebug() << "dinput: joystick DIPROP_BUFFERSIZE";
h->Release();
goto end;
}
@@ -336,7 +325,7 @@ BOOL CALLBACK win32_joy_ctx::enum_state::EnumJoysticksCallback(const DIDEVICEINS
if (FAILED(hr = h->EnumObjects(EnumObjectsCallback, h, DIDFT_ALL)))
{
- qDebug() << "enum-objects";
+ qDebug() << "dinput: joystick EnumObjects";
h->Release();
goto end;
}
@@ -363,7 +352,7 @@ BOOL CALLBACK win32_joy_ctx::enum_state::EnumObjectsCallback(const DIDEVICEOBJEC
if (FAILED(hr = reinterpret_cast<LPDIRECTINPUTDEVICE8>(ctx)->SetProperty(DIPROP_RANGE, &diprg.diph)))
{
- qDebug() << "DIPROP_RANGE" << hr;
+ qDebug() << "dinput: joystick DIPROP_RANGE" << hr;
return DIENUM_STOP;
}
}