diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 8b97875464a..bee9ff736a5 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -287,7 +287,50 @@ void release_DataFormat(DataFormat * format) HeapFree(GetProcessHeap(), 0, format->dt); } -DataFormat *create_DataFormat(const DIDATAFORMAT *wine_format, LPCDIDATAFORMAT asked_format, int *offset) { +/* Make all instances sequential */ +static void calculate_ids(LPDIDATAFORMAT df) +{ + int i, axis = 0, pov = 0, button = 0; + int axis_base, pov_base, button_base; + DWORD type; + + /* Make two passes over the format. The first counts the number + * for each type and the second sets the id */ + for (i = 0; i < df->dwNumObjs; i++) + { + type = DIDFT_GETTYPE(df->rgodf[i].dwType); + if (type & DIDFT_AXIS) axis++; + else if (type & DIDFT_POV) pov++; + else if (type & DIDFT_BUTTON) button++; + } + + axis_base = 0; + pov_base = axis_base + axis; + button_base = pov_base + pov; + axis = pov = button = 0; + + for (i = 0; i < df->dwNumObjs; i++) + { + type = DIDFT_GETTYPE(df->rgodf[i].dwType); + if (type & DIDFT_AXIS) + { + type |= DIDFT_MAKEINSTANCE(axis_base + axis++); + TRACE("axis type = 0x%08x\n", type); + } else if (type & DIDFT_POV) + { + type |= DIDFT_MAKEINSTANCE(pov_base + pov++); + TRACE("POV type = 0x%08x\n", type); + } else if (type & DIDFT_BUTTON) + { + type |= DIDFT_MAKEINSTANCE(button_base + button++); + TRACE("button type = 0x%08x\n", type); + } + df->rgodf[i].dwType = type; + } +} + +DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, int *offset) +{ DataFormat *ret; DataTransform *dt; unsigned int i, j; @@ -404,7 +447,9 @@ DataFormat *create_DataFormat(const DIDATAFORMAT *wine_format, LPCDIDATAFORMAT a } HeapFree(GetProcessHeap(), 0, done); - + + /* Last step - reset all instances of the new format */ + calculate_ids(asked_format); return ret; } diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 4e63af4e9eb..84b6d02bdaf 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -60,7 +60,7 @@ typedef struct { DataTransform *dt; } DataFormat; extern void fill_DataFormat(void *out, const void *in, DataFormat *df) ; -extern DataFormat *create_DataFormat(const DIDATAFORMAT *wine_format, LPCDIDATAFORMAT asked_format, int *offset) ; +extern DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, int *offset); extern void release_DataFormat(DataFormat *df) ; extern void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq); diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c index 474678cc30c..0fb7e223677 100644 --- a/dlls/dinput/joystick_linux.c +++ b/dlls/dinput/joystick_linux.c @@ -393,57 +393,6 @@ static HRESULT setup_dinput_options(JoystickImpl * device) return DI_OK; } -static void calculate_ids(JoystickImpl* device) -{ - int i; - int axis = 0; - int button = 0; - int pov = 0; - int axis_base; - int pov_base; - int button_base; - - /* Make two passes over the format. The first counts the number - * for each type and the second sets the id */ - for (i = 0; i < device->user_df->dwNumObjs; i++) { - if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_AXIS) - axis++; - else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_POV) - pov++; - else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_BUTTON) - button++; - } - - axis_base = 0; - pov_base = axis; - button_base = axis + pov; - - axis = 0; - button = 0; - pov = 0; - - for (i = 0; i < device->user_df->dwNumObjs; i++) { - DWORD type = 0; - if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_AXIS) { - axis++; - type = DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) | - DIDFT_MAKEINSTANCE(axis + axis_base); - TRACE("axis type = 0x%08x\n", type); - } else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_POV) { - pov++; - type = DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) | - DIDFT_MAKEINSTANCE(pov + pov_base); - TRACE("POV type = 0x%08x\n", type); - } else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_BUTTON) { - button++; - type = DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) | - DIDFT_MAKEINSTANCE(button + button_base); - TRACE("button type = 0x%08x\n", type); - } - device->user_df->rgodf[i].dwType = type; - } -} - static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, LPDIRECTINPUTDEVICEA* pdev) { DWORD i; @@ -554,8 +503,6 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di /* create the default transform filter */ newDevice->transform = create_DataFormat(&c_dfDIJoystick2, newDevice->user_df, newDevice->offsets); - calculate_ids(newDevice); - IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput); newDevice->devcaps.dwSize = sizeof(newDevice->devcaps); @@ -765,8 +712,6 @@ static HRESULT WINAPI JoystickAImpl_SetDataFormat( } This->transform = create_DataFormat(&c_dfDIJoystick2, This->user_df, This->offsets); - calculate_ids(This); - return DI_OK; FAILED: diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c index 369c26dce69..2fe0b7cfe9b 100644 --- a/dlls/dinput/joystick_linuxinput.c +++ b/dlls/dinput/joystick_linuxinput.c @@ -152,7 +152,6 @@ static DWORD map_pov(int event_value, int is_x); static void find_joydevs(void); static int lxinput_to_user_offset(JoystickImpl *This, int ie_type, int ie_code); static int offset_to_object(JoystickImpl *This, int offset); -static void calculate_ids(LPDIDATAFORMAT df); /* This GUID is slightly different from the linux joystick one. Take note. */ static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */ @@ -414,7 +413,6 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm /* create the default transform filter */ newDevice->transform = create_DataFormat(&c_dfDIJoystick2, newDevice->df, newDevice->offsets); - calculate_ids(newDevice->df); return newDevice; @@ -577,7 +575,6 @@ static HRESULT WINAPI JoystickAImpl_SetDataFormat( memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize); This->transform = create_DataFormat(&c_dfDIJoystick2, This->df, This->offsets); - calculate_ids(This->df); return DI_OK; } @@ -798,57 +795,6 @@ static int offset_to_object(JoystickImpl *This, int offset) return -1; } -static void calculate_ids(LPDIDATAFORMAT df) -{ - int i; - int axis = 0; - int button = 0; - int pov = 0; - int axis_base; - int pov_base; - int button_base; - - /* Make two passes over the format. The first counts the number - * for each type and the second sets the id */ - for (i = 0; i < df->dwNumObjs; i++) { - if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS) - axis++; - else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_POV) - pov++; - else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_BUTTON) - button++; - } - - axis_base = 0; - pov_base = axis; - button_base = axis + pov; - - axis = 0; - button = 0; - pov = 0; - - for (i = 0; i < df->dwNumObjs; i++) { - DWORD type = 0; - if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS) { - axis++; - type = DIDFT_GETTYPE(df->rgodf[i].dwType) | - DIDFT_MAKEINSTANCE(axis + axis_base); - TRACE("axis type = 0x%08x\n", type); - } else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_POV) { - pov++; - type = DIDFT_GETTYPE(df->rgodf[i].dwType) | - DIDFT_MAKEINSTANCE(pov + pov_base); - TRACE("POV type = 0x%08x\n", type); - } else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_BUTTON) { - button++; - type = DIDFT_GETTYPE(df->rgodf[i].dwType) | - DIDFT_MAKEINSTANCE(button + button_base); - TRACE("button type = 0x%08x\n", type); - } - df->rgodf[i].dwType = type; - } -} - static void joy_polldev(JoystickImpl *This) { struct pollfd plfd; struct input_event ie; diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 0ede9cee155..bcb16faaa17 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -366,7 +366,7 @@ static HRESULT WINAPI SysMouseAImpl_SetDataFormat( memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize); /* Prepare all the data-conversion filters */ - This->wine_df = create_DataFormat(&(Wine_InternalMouseFormat), df, This->offset_array); + This->wine_df = create_DataFormat(&Wine_InternalMouseFormat, This->df, This->offset_array); return DI_OK; }