EnterCriticalSection(&This->crit);
res = This->acquired ? S_FALSE : DI_OK;
This->acquired = 1;
- LeaveCriticalSection(&This->crit);
if (res == DI_OK)
- check_dinput_hooks(iface, TRUE);
+ check_dinput_hooks(iface);
+ LeaveCriticalSection(&This->crit);
return res;
}
EnterCriticalSection(&This->crit);
res = !This->acquired ? DI_NOEFFECT : DI_OK;
This->acquired = 0;
- LeaveCriticalSection(&This->crit);
if (res == DI_OK)
- check_dinput_hooks(iface, FALSE);
+ check_dinput_hooks(iface);
+ LeaveCriticalSection(&This->crit);
return res;
}
/* Force creation of the message queue */
PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE );
- SetEvent(param);
+ SetEvent(*(LPHANDLE)param);
while (GetMessageW( &msg, 0, 0, 0 ))
{
}
static DWORD hook_thread_id;
-static HANDLE hook_thread_event;
static CRITICAL_SECTION_DEBUG dinput_critsect_debug =
{
TRACE("IDirectInputs left: %d\n", list_count(&direct_input_list));
if (!list_empty(&direct_input_list) && !hook_thread)
{
- hook_thread_event = CreateEventW(NULL, FALSE, FALSE, NULL);
- hook_thread = CreateThread(NULL, 0, hook_thread_proc, hook_thread_event, 0, &hook_thread_id);
+ HANDLE event;
+
+ event = CreateEventW(NULL, FALSE, FALSE, NULL);
+ hook_thread = CreateThread(NULL, 0, hook_thread_proc, &event, 0, &hook_thread_id);
+ if (event && hook_thread)
+ {
+ HANDLE handles[2];
+ handles[0] = event;
+ handles[1] = hook_thread;
+ WaitForMultipleObjects(2, handles, FALSE, INFINITE);
+ }
LeaveCriticalSection(&dinput_hook_crit);
+ CloseHandle(event);
}
else if (list_empty(&direct_input_list) && hook_thread)
{
DWORD tid = hook_thread_id;
- if (hook_thread_event) /* if thread is not started yet */
- {
- WaitForSingleObject(hook_thread_event, INFINITE);
- CloseHandle(hook_thread_event);
- hook_thread_event = NULL;
- }
-
hook_thread_id = 0;
PostThreadMessageW(tid, WM_USER+0x10, 0, 0);
LeaveCriticalSection(&dinput_hook_crit);
return hook_thread_id != 0;
}
-void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface, BOOL acquired)
+void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface)
{
static HHOOK callwndproc_hook;
static ULONG foreground_cnt;
if (dev->dwCoopLevel & DISCL_FOREGROUND)
{
- if (acquired)
+ if (dev->acquired)
foreground_cnt++;
else
foreground_cnt--;
callwndproc_hook = NULL;
}
- if (hook_thread_event) /* if thread is not started yet */
- {
- WaitForSingleObject(hook_thread_event, INFINITE);
- CloseHandle(hook_thread_event);
- hook_thread_event = NULL;
- }
-
PostThreadMessageW( hook_thread_id, WM_USER+0x10, 1, 0 );
LeaveCriticalSection(&dinput_hook_crit);
{
IOHIDElementRef element = ( IOHIDElementRef ) CFArrayGetValueAtIndex( elements, idx );
int type = IOHIDElementGetType( element );
+ int usage_page = IOHIDElementGetUsagePage( element );
TRACE("element %s\n", debugstr_element(element));
+ if (usage_page >= kHIDPage_VendorDefinedStart)
+ {
+ /* vendor pages can repurpose type ids, resulting in incorrect case matches below (e.g. ds4 controllers) */
+ continue;
+ }
+
switch(type)
{
case kIOHIDElementTypeInput_Button:
{
- int usage_page = IOHIDElementGetUsagePage( element );
TRACE("kIOHIDElementTypeInput_Button usage_page %d\n", usage_page);
if (usage_page != kHIDPage_Button)
{