diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2019-02-09 12:11:49 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2019-02-09 12:13:39 +0100 |
commit | 14a976e4729d38f86d336fa6054279b33905b63c (patch) | |
tree | 41e5a48f3e75520800fe3937691af0755c565d64 /dinput/dinput.cpp | |
parent | 6073e15f2871f2699f3e821dc927b3c49187cfb9 (diff) |
dinput: fix api usage
Issue: #871
- don't sleep with a lock held
- fix Acquire() return value check
- remove needless Unacquire() calls
- always use Poll(), even for keyboard
- fix HRESULT debug output
Diffstat (limited to 'dinput/dinput.cpp')
-rw-r--r-- | dinput/dinput.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/dinput/dinput.cpp b/dinput/dinput.cpp index e896f5f1..575922d9 100644 --- a/dinput/dinput.cpp +++ b/dinput/dinput.cpp @@ -1,4 +1,6 @@ #include "dinput.hpp" +#include "compat/macros.hpp" + #include <QDebug> int di_t::refcnt{0}; @@ -58,3 +60,32 @@ di_t::~di_t() unref_di(); } +bool di_t::poll_device(LPDIRECTINPUTDEVICE8 dev) +{ + HRESULT hr; + + switch (dev->Poll()) + { + case DI_OK: + case DI_NOEFFECT: + return true; + default: + break; + } + + switch (hr = dev->Acquire()) + { + case DI_OK: + case S_FALSE: + switch (hr = dev->Poll()) + { + case DI_OK: + case DI_NOEFFECT: + return true; + default: + eval_once(qDebug() << "dinput: device poll failed:" << (void*)hr); + } + } + + return false; +} |