summaryrefslogtreecommitdiffhomepage
path: root/opentrack-logic/keybinding-worker.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-07-07 14:15:18 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-07-07 14:15:18 +0200
commit5f5ca66c58ad30d0c218b2da904aa3f722e18ebe (patch)
tree8e8d5bae3ca7edf6c96c7f0e0da87f347486b045 /opentrack-logic/keybinding-worker.cpp
parentc418644838e99416fb168066bacc28a4cbc36a04 (diff)
logic/dinput: only ever use a single handle to DIRECTINPUT8 COM object
Diffstat (limited to 'opentrack-logic/keybinding-worker.cpp')
-rw-r--r--opentrack-logic/keybinding-worker.cpp28
1 files changed, 10 insertions, 18 deletions
diff --git a/opentrack-logic/keybinding-worker.cpp b/opentrack-logic/keybinding-worker.cpp
index eba026a5..a009d399 100644
--- a/opentrack-logic/keybinding-worker.cpp
+++ b/opentrack-logic/keybinding-worker.cpp
@@ -23,56 +23,47 @@ bool Key::should_process()
return ret;
}
-KeybindingWorker::~KeybindingWorker() {
+KeybindingWorker::~KeybindingWorker()
+{
should_quit = true;
wait();
if (dinkeyboard) {
dinkeyboard->Unacquire();
dinkeyboard->Release();
}
- if (din)
- din->Release();
}
-KeybindingWorker::KeybindingWorker() :
- should_quit(true)
+KeybindingWorker::KeybindingWorker() : should_quit(true)
{
- if (DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&din, NULL) != DI_OK) {
- qDebug() << "setup DirectInput8 Creation failed!" << GetLastError();
- return;
- }
+ LPDIRECTINPUT8 din = dinput_handle::make_di();
+
if (din->CreateDevice(GUID_SysKeyboard, &dinkeyboard, NULL) != DI_OK) {
- din->Release();
- din = 0;
qDebug() << "setup CreateDevice function failed!" << GetLastError();
return;
}
+
if (dinkeyboard->SetDataFormat(&c_dfDIKeyboard) != DI_OK) {
qDebug() << "setup SetDataFormat function failed!" << GetLastError();
dinkeyboard->Release();
dinkeyboard = 0;
- din->Release();
- din = 0;
return;
}
if (dinkeyboard->SetCooperativeLevel((HWND) fake_main_window.winId(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND) != DI_OK) {
dinkeyboard->Release();
- din->Release();
- din = 0;
dinkeyboard = 0;
qDebug() << "setup SetCooperativeLevel function failed!" << GetLastError();
return;
}
+
if (dinkeyboard->Acquire() != DI_OK)
{
dinkeyboard->Release();
- din->Release();
- din = 0;
dinkeyboard = 0;
qDebug() << "setup dinkeyboard Acquire failed!" << GetLastError();
return;
}
+
should_quit = false;
start();
}
@@ -83,7 +74,8 @@ KeybindingWorker& KeybindingWorker::make()
return k;
}
-void KeybindingWorker::run() {
+void KeybindingWorker::run()
+{
BYTE keystate[256] = {0};
BYTE old_keystate[256] = {0};