wine-staging/patches/dinput-scancode/0002-dinput-Enumerate-lower-keyboard-scancodes-values-fir.patch
2023-07-08 15:20:31 +10:00

65 lines
2.9 KiB
Diff

From bdf952bf0711a7cf22fee840197234bd413ae611 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Bernon?= <rbernon@codeweavers.com>
Date: Fri, 7 Jul 2023 12:45:04 +0200
Subject: [PATCH] dinput: Enumerate lower keyboard scancodes values first.
Windows usually doesn't have scancodes higher than 0x7f, or extended
scancodes higher than 0x17f, but X11 does for several XF86 keys.
We want to enumerate the basic keys first including in the extended
scancode range, so they appear before the XF86 keys in the dinput
device object list.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55205
---
dlls/dinput/keyboard.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index 3fd75bb10e6..1f1db883b80 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -256,6 +256,7 @@ static BOOL try_enum_object( struct dinput_device *impl, const DIPROPHEADER *fil
static HRESULT keyboard_enum_objects( IDirectInputDevice8W *iface, const DIPROPHEADER *filter,
DWORD flags, enum_object_callback callback, void *context )
{
+ static const UINT vsc_base[] = {0, 0x100, 0x80, 0x180};
struct keyboard *impl = impl_from_IDirectInputDevice8W( iface );
BYTE subtype = GET_DIDEVICE_SUBTYPE( impl->base.instance.dwDevType );
DIDEVICEOBJECTINSTANCEW instance =
@@ -266,18 +267,21 @@ static HRESULT keyboard_enum_objects( IDirectInputDevice8W *iface, const DIPROPH
.dwType = DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE( DIK_ESCAPE ),
};
BOOL ret, mapped[0x100] = {0};
- DWORD index, i, dik;
+ DWORD index, i, dik, vsc;
- for (i = 0, index = 0; i < 512; ++i)
+ for (i = 0, index = 0; i < ARRAY_SIZE(vsc_base); ++i)
{
- if (!GetKeyNameTextW( i << 16, instance.tszName, ARRAY_SIZE(instance.tszName) )) continue;
- if (!(dik = map_dik_code( i, 0, subtype, impl->base.dinput->dwVersion ))) continue;
- if (mapped[dik]) continue;
- mapped[dik] = TRUE;
- instance.dwOfs = dik;
- instance.dwType = DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE( dik );
- ret = try_enum_object( &impl->base, filter, flags, callback, index++, &instance, context );
- if (ret != DIENUM_CONTINUE) return DIENUM_STOP;
+ for (vsc = vsc_base[i]; vsc < vsc_base[i] + 0x80; vsc++)
+ {
+ if (!GetKeyNameTextW( vsc << 16, instance.tszName, ARRAY_SIZE(instance.tszName) )) continue;
+ if (!(dik = map_dik_code( vsc, 0, subtype, impl->base.dinput->dwVersion ))) continue;
+ if (mapped[dik]) continue;
+ mapped[dik] = TRUE;
+ instance.dwOfs = dik;
+ instance.dwType = DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE( dik );
+ ret = try_enum_object( &impl->base, filter, flags, callback, index++, &instance, context );
+ if (ret != DIENUM_CONTINUE) return DIENUM_STOP;
+ }
}
return DIENUM_CONTINUE;
--
2.40.1