Module: wine Branch: master Commit: aa7a6b8f4284bb654c657828271a0383f652801c URL: https://gitlab.winehq.org/wine/wine/-/commit/aa7a6b8f4284bb654c657828271a038...
Author: Rémi Bernon rbernon@codeweavers.com Date: Sat Feb 11 12:41:55 2023 +0100
dinput: Use rawinput interface for keyboard device.
---
dlls/dinput/dinput_main.c | 17 ++++++++++++++++- dlls/dinput/dinput_private.h | 2 ++ dlls/dinput/keyboard.c | 15 +++++++++++++++ dlls/dinput/tests/device8.c | 11 ----------- 4 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 15ab2fe3dce..42541b9084a 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -200,6 +200,7 @@ static LRESULT CALLBACK cbt_hook_proc( int code, WPARAM wparam, LPARAM lparam )
static void input_thread_update_device_list( struct input_thread_state *state ) { + RAWINPUTDEVICE rawinput_keyboard = {.usUsagePage = HID_USAGE_PAGE_GENERIC, .usUsage = HID_USAGE_GENERIC_KEYBOARD, .dwFlags = RIDEV_REMOVE}; RAWINPUTDEVICE rawinput_mouse = {.usUsagePage = HID_USAGE_PAGE_GENERIC, .usUsage = HID_USAGE_GENERIC_MOUSE, .dwFlags = RIDEV_REMOVE}; UINT count = 0, keyboard_ll_count = 0, mouse_ll_count = 0, foreground_count = 0; struct dinput_device *device; @@ -230,7 +231,9 @@ static void input_thread_update_device_list( struct input_thread_state *state ) break; case DIDEVTYPE_KEYBOARD: case DI8DEVTYPE_KEYBOARD: + if (device->dwCoopLevel & DISCL_EXCLUSIVE) rawinput_keyboard.dwFlags |= RIDEV_NOHOTKEYS; if (!device->use_raw_input) keyboard_ll_count++; + else rawinput_device = &rawinput_keyboard; break; }
@@ -274,8 +277,12 @@ static void input_thread_update_device_list( struct input_thread_state *state ) if (!rawinput_mouse.hwndTarget != !state->rawinput_devices[0].hwndTarget && !RegisterRawInputDevices( &rawinput_mouse, 1, sizeof(RAWINPUTDEVICE) )) WARN( "Failed to (un)register rawinput mouse device.\n" ); + if (!rawinput_keyboard.hwndTarget != !state->rawinput_devices[1].hwndTarget && + !RegisterRawInputDevices( &rawinput_keyboard, 1, sizeof(RAWINPUTDEVICE) )) + WARN( "Failed to (un)register rawinput mouse device.\n" );
state->rawinput_devices[0] = rawinput_mouse; + state->rawinput_devices[1] = rawinput_keyboard; }
static LRESULT WINAPI di_em_win_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) @@ -292,7 +299,9 @@ static LRESULT WINAPI di_em_win_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPAR size = GetRawInputData( (HRAWINPUT)lparam, RID_INPUT, &ri, &size, sizeof(RAWINPUTHEADER) ); if (size == (UINT)-1 || size < sizeof(RAWINPUTHEADER)) WARN( "Unable to read raw input data\n" ); - else if (ri.header.dwType == RIM_TYPEMOUSE) + else if (ri.header.dwType == RIM_TYPEHID) + WARN( "Unexpected HID rawinput message\n" ); + else { for (i = state->events_count; i < state->devices_count; ++i) { @@ -303,8 +312,14 @@ static LRESULT WINAPI di_em_win_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPAR { case DIDEVTYPE_MOUSE: case DI8DEVTYPE_MOUSE: + if (ri.header.dwType != RIM_TYPEMOUSE) break; dinput_mouse_rawinput_hook( &device->IDirectInputDevice8W_iface, wparam, lparam, &ri ); break; + case DIDEVTYPE_KEYBOARD: + case DI8DEVTYPE_KEYBOARD: + if (ri.header.dwType != RIM_TYPEKEYBOARD) break; + dinput_keyboard_rawinput_hook( &device->IDirectInputDevice8W_iface, wparam, lparam, &ri ); + break; default: break; } } diff --git a/dlls/dinput/dinput_private.h b/dlls/dinput/dinput_private.h index 6e7ffeb0841..944d12b860f 100644 --- a/dlls/dinput/dinput_private.h +++ b/dlls/dinput/dinput_private.h @@ -72,6 +72,8 @@ extern int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM extern int dinput_keyboard_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam ); extern void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam, RAWINPUT *raw ); +extern void dinput_keyboard_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam, + RAWINPUT *raw );
extern void check_dinput_events(void) DECLSPEC_HIDDEN;
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 6c24ddcf24b..c49796cfa2d 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -115,6 +115,18 @@ static void keyboard_handle_event( struct keyboard *impl, DWORD vkey, DWORD scan LeaveCriticalSection( &impl->base.crit ); }
+void dinput_keyboard_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam, RAWINPUT *ri ) +{ + struct keyboard *impl = impl_from_IDirectInputDevice8W( iface ); + DWORD scan_code; + + TRACE("(%p) wparam %Ix, lparam %Ix\n", iface, wparam, lparam); + + scan_code = ri->data.keyboard.MakeCode & 0xff; + if (ri->data.keyboard.Flags & RI_KEY_E0) scan_code |= 0x100; + keyboard_handle_event( impl, ri->data.keyboard.VKey, scan_code, ri->data.keyboard.Flags & RI_KEY_BREAK ); +} + int dinput_keyboard_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam ) { struct keyboard *impl = impl_from_IDirectInputDevice8W( iface ); @@ -189,6 +201,9 @@ HRESULT keyboard_create_device( struct dinput *dinput, const GUID *guid, IDirect impl->base.caps.dwFirmwareRevision = 100; impl->base.caps.dwHardwareRevision = 100;
+ if (dinput->dwVersion >= 0x0800) + impl->base.use_raw_input = TRUE; + *out = &impl->base.IDirectInputDevice8W_iface; return DI_OK; } diff --git a/dlls/dinput/tests/device8.c b/dlls/dinput/tests/device8.c index 449402621a7..1f29c9af519 100644 --- a/dlls/dinput/tests/device8.c +++ b/dlls/dinput/tests/device8.c @@ -1099,15 +1099,11 @@ static void test_mouse_keyboard(void) raw_devices_count = ARRAY_SIZE(raw_devices); memset(raw_devices, 0, sizeof(raw_devices)); hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE)); - todo_wine ok(hr == 1, "GetRegisteredRawInputDevices returned %ld, raw_devices_count: %d\n", hr, raw_devices_count); - todo_wine ok(raw_devices[0].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[0].usUsagePage); - todo_wine ok(raw_devices[0].usUsage == HID_USAGE_GENERIC_KEYBOARD, "got usUsage: %x\n", raw_devices[0].usUsage); todo_wine ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %#lx\n", raw_devices[0].dwFlags); - todo_wine ok(raw_devices[0].hwndTarget != NULL, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget); hr = IDirectInputDevice8_Unacquire(di_keyboard); ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %#lx\n", hr); @@ -1139,7 +1135,6 @@ static void test_mouse_keyboard(void) ok(raw_devices[0].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[0].usUsagePage); ok(raw_devices[0].usUsage == HID_USAGE_GENERIC_MOUSE, "got usUsage: %x\n", raw_devices[0].usUsage); ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %#lx\n", raw_devices[0].dwFlags); - todo_wine ok(raw_devices[0].hwndTarget == di_hwnd, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget); hr = IDirectInputDevice8_Unacquire(di_mouse); ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %#lx\n", hr); @@ -1185,9 +1180,6 @@ static void test_mouse_keyboard(void) ok(raw_devices[1].hwndTarget == hwnd, "Unexpected raw device target: %p\n", raw_devices[1].hwndTarget); ok(raw_devices[2].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[1].usUsagePage); ok(raw_devices[2].usUsage == HID_USAGE_GENERIC_KEYBOARD, "got usUsage: %x\n", raw_devices[1].usUsage); - todo_wine - ok(raw_devices[2].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %#lx\n", raw_devices[1].dwFlags); - todo_wine ok(raw_devices[2].hwndTarget == di_hwnd, "Unexpected raw device target: %p\n", raw_devices[1].hwndTarget); hr = IDirectInputDevice8_Unacquire(di_keyboard); ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %#lx\n", hr); @@ -1195,7 +1187,6 @@ static void test_mouse_keyboard(void) ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %#lx\n", hr); raw_devices_count = ARRAY_SIZE(raw_devices); GetRegisteredRawInputDevices(NULL, &raw_devices_count, sizeof(RAWINPUTDEVICE)); - todo_wine ok(raw_devices_count == 1, "Unexpected raw devices registered: %d\n", raw_devices_count);
IDirectInputDevice8_SetCooperativeLevel(di_mouse, hwnd, DISCL_FOREGROUND|DISCL_EXCLUSIVE); @@ -1210,7 +1201,6 @@ static void test_mouse_keyboard(void) hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE)); ok(hr == 3, "GetRegisteredRawInputDevices returned %ld, raw_devices_count: %d\n", hr, raw_devices_count); ok(raw_devices[0].dwFlags == (RIDEV_CAPTUREMOUSE|RIDEV_NOLEGACY), "Unexpected raw device flags: %#lx\n", raw_devices[0].dwFlags); - todo_wine ok(raw_devices[2].dwFlags == (RIDEV_NOHOTKEYS|RIDEV_NOLEGACY), "Unexpected raw device flags: %#lx\n", raw_devices[1].dwFlags); hr = IDirectInputDevice8_Unacquire(di_keyboard); ok(SUCCEEDED(hr), "IDirectInputDevice8_Acquire failed: %#lx\n", hr); @@ -1219,7 +1209,6 @@ static void test_mouse_keyboard(void)
raw_devices_count = ARRAY_SIZE(raw_devices); hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE)); - todo_wine ok(hr == 1, "GetRegisteredRawInputDevices returned %ld, raw_devices_count: %d\n", hr, raw_devices_count); ok(raw_devices[0].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[0].usUsagePage); ok(raw_devices[0].usUsage == HID_USAGE_GENERIC_GAMEPAD, "got usUsage: %x\n", raw_devices[0].usUsage);