Signed-off-by: Rémi Bernon rbernon@codeweavers.com ---
A bit of cleanup and improvements to joy.cpl to ultimately make it possible to override XInput / DInput HID device association with the registry DirectInput settings, and have it configurable through the control panel.
dlls/joy.cpl/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/dlls/joy.cpl/main.c b/dlls/joy.cpl/main.c index 3ea417843f4..226f36051a6 100644 --- a/dlls/joy.cpl/main.c +++ b/dlls/joy.cpl/main.c @@ -112,7 +112,7 @@ static void initialize_joysticks(struct JoystickData *data) data->num_joysticks = 0; data->cur_joystick = 0; IDirectInput8_EnumDevices(data->di, DI8DEVCLASS_GAMECTRL, enum_callback, data, DIEDFL_ATTACHEDONLY); - data->joysticks = HeapAlloc(GetProcessHeap(), 0, sizeof(struct Joystick) * data->num_joysticks); + data->joysticks = malloc(sizeof(struct Joystick) * data->num_joysticks);
/* Get all the joysticks */ IDirectInput8_EnumDevices(data->di, DI8DEVCLASS_GAMECTRL, enum_callback, data, DIEDFL_ATTACHEDONLY); @@ -134,14 +134,14 @@ static void destroy_joysticks(struct JoystickData *data) if (data->joysticks[i].effects[j].effect) IDirectInputEffect_Release(data->joysticks[i].effects[j].effect);
- HeapFree(GetProcessHeap(), 0, data->joysticks[i].effects); + free(data->joysticks[i].effects); }
IDirectInputDevice8_Unacquire(data->joysticks[i].device); IDirectInputDevice8_Release(data->joysticks[i].device); }
- HeapFree(GetProcessHeap(), 0, data->joysticks); + free(data->joysticks); }
static void initialize_joysticks_list(HWND hwnd, struct JoystickData *data) @@ -823,7 +823,7 @@ static INT_PTR CALLBACK ff_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp joy->num_effects = 0; joy->effects = NULL; IDirectInputDevice8_EnumEffects(joy->device, ff_effects_callback, (void *) joy, 0); - joy->effects = HeapAlloc(GetProcessHeap(), 0, sizeof(struct Effect) * joy->num_effects); + joy->effects = malloc(sizeof(struct Effect) * joy->num_effects);
joy->cur_effect = 0; IDirectInputDevice8_EnumEffects(joy->device, ff_effects_callback, (void*) joy, 0);
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/joy.cpl/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dlls/joy.cpl/main.c b/dlls/joy.cpl/main.c index 226f36051a6..43e124a0a33 100644 --- a/dlls/joy.cpl/main.c +++ b/dlls/joy.cpl/main.c @@ -212,7 +212,7 @@ static void enable_joystick(WCHAR *joy_name, BOOL enable) get_app_key(&hkey, &appkey);
if (!enable) - set_config_key(hkey, appkey, joy_name, L"disabled", lstrlenW(L"disabled")); + set_config_key(hkey, appkey, joy_name, L"disabled", wcslen(L"disabled")); else set_config_key(hkey, appkey, joy_name, NULL, 0);
@@ -240,7 +240,7 @@ static void initialize_disabled_joysticks_list(HWND hwnd)
status = RegEnumValueW(hkey, i, buf_name, &name_len, NULL, NULL, (BYTE*) buf_data, &data_len);
- if (status == ERROR_SUCCESS && !lstrcmpW(L"disabled", buf_data)) + if (status == ERROR_SUCCESS && !wcscmp(L"disabled", buf_data)) SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_ADDSTRING, 0, (LPARAM) buf_name); }
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/joy.cpl/main.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/dlls/joy.cpl/main.c b/dlls/joy.cpl/main.c index 43e124a0a33..ef905c65a93 100644 --- a/dlls/joy.cpl/main.c +++ b/dlls/joy.cpl/main.c @@ -60,6 +60,7 @@ BOOL WINAPI DllMain(HINSTANCE hdll, DWORD reason, LPVOID reserved) * First time it checks if space for the joysticks was already reserved * and if not, just counts how many there are. */ +static BOOL CALLBACK ff_effects_callback(const DIEFFECTINFOW *pdei, void *pvRef); static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *context) { struct JoystickData *data = context; @@ -101,6 +102,18 @@ static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *cont
IDirectInputDevice_SetProperty(joystick->device, DIPROP_RANGE, &proprange.diph);
+ if (!joystick->forcefeedback) return DIENUM_CONTINUE; + + /* Count device effects and then store them */ + joystick->num_effects = 0; + joystick->effects = NULL; + IDirectInputDevice8_EnumEffects(joystick->device, ff_effects_callback, (void *)joystick, 0); + joystick->effects = malloc(sizeof(struct Effect) * joystick->num_effects); + + joystick->cur_effect = 0; + IDirectInputDevice8_EnumEffects(joystick->device, ff_effects_callback, (void*)joystick, 0); + joystick->num_effects = joystick->cur_effect; + return DIENUM_CONTINUE; }
@@ -818,16 +831,6 @@ static INT_PTR CALLBACK ff_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp SendDlgItemMessageW(hwnd, IDC_FFSELECTCOMBO, CB_SETITEMDATA, cur, i);
cur++; - - /* Count device effects and then store them */ - joy->num_effects = 0; - joy->effects = NULL; - IDirectInputDevice8_EnumEffects(joy->device, ff_effects_callback, (void *) joy, 0); - joy->effects = malloc(sizeof(struct Effect) * joy->num_effects); - - joy->cur_effect = 0; - IDirectInputDevice8_EnumEffects(joy->device, ff_effects_callback, (void*) joy, 0); - joy->num_effects = joy->cur_effect; } }
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/joy.cpl/main.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/dlls/joy.cpl/main.c b/dlls/joy.cpl/main.c index ef905c65a93..3dee30a4b5b 100644 --- a/dlls/joy.cpl/main.c +++ b/dlls/joy.cpl/main.c @@ -533,6 +533,14 @@ static void draw_joystick_axes(HWND hwnd, struct JoystickData* data) * test_dlgproc [internal] * */ +static void refresh_test_joystick_list(HWND hwnd, struct JoystickData *data) +{ + struct Joystick *joy, *joy_end; + SendDlgItemMessageW(hwnd, IDC_TESTSELECTCOMBO, CB_RESETCONTENT, 0, 0); + for (joy = data->joysticks, joy_end = joy + data->num_joysticks; joy != joy_end; ++joy) + SendDlgItemMessageW(hwnd, IDC_TESTSELECTCOMBO, CB_ADDSTRING, 0, (LPARAM)joy->instance.tszInstanceName); +} + static INT_PTR CALLBACK test_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { static HANDLE thread; @@ -543,17 +551,9 @@ static INT_PTR CALLBACK test_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM { case WM_INITDIALOG: { - int i; - data = (struct JoystickData*) ((PROPSHEETPAGEW*)lparam)->lParam;
- /* Add enumerated joysticks to the combobox */ - for (i = 0; i < data->num_joysticks; i++) - { - struct Joystick *joy = &data->joysticks[i]; - SendDlgItemMessageW(hwnd, IDC_TESTSELECTCOMBO, CB_ADDSTRING, 0, (LPARAM) joy->instance.tszInstanceName); - } - + refresh_test_joystick_list(hwnd, data); draw_joystick_buttons(hwnd, data); draw_joystick_axes(hwnd, data);
@@ -576,6 +576,8 @@ static INT_PTR CALLBACK test_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM { DWORD tid;
+ refresh_test_joystick_list(hwnd, data); + /* Initialize input thread */ if (data->num_joysticks > 0) {
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/joy.cpl/main.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-)
diff --git a/dlls/joy.cpl/main.c b/dlls/joy.cpl/main.c index 3dee30a4b5b..d5272990df3 100644 --- a/dlls/joy.cpl/main.c +++ b/dlls/joy.cpl/main.c @@ -642,12 +642,9 @@ static void initialize_effects_list(HWND hwnd, struct Joystick* joy)
static void ff_handle_joychange(HWND hwnd, struct JoystickData *data) { - int sel; - if (data->num_ff == 0) return;
- sel = SendDlgItemMessageW(hwnd, IDC_FFSELECTCOMBO, CB_GETCURSEL, 0, 0); - data->chosen_joystick = SendDlgItemMessageW(hwnd, IDC_FFSELECTCOMBO, CB_GETITEMDATA, sel, 0); + data->chosen_joystick = SendDlgItemMessageW(hwnd, IDC_FFSELECTCOMBO, CB_GETCURSEL, 0, 0); initialize_effects_list(hwnd, &data->joysticks[data->chosen_joystick]); }
@@ -808,6 +805,14 @@ static BOOL CALLBACK ff_effects_callback(const DIEFFECTINFOW *pdei, void *pvRef) * ff_dlgproc [internal] * */ +static void refresh_ff_joystick_list(HWND hwnd, struct JoystickData *data) +{ + struct Joystick *joy, *joy_end; + SendDlgItemMessageW(hwnd, IDC_FFSELECTCOMBO, CB_RESETCONTENT, 0, 0); + for (joy = data->joysticks, joy_end = joy + data->num_joysticks; joy != joy_end; ++joy) + SendDlgItemMessageW(hwnd, IDC_FFSELECTCOMBO, CB_ADDSTRING, 0, (LPARAM)joy->instance.tszInstanceName); +} + static INT_PTR CALLBACK ff_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { static HANDLE thread; @@ -818,24 +823,9 @@ static INT_PTR CALLBACK ff_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp { case WM_INITDIALOG: { - int i, cur = 0; - data = (struct JoystickData*) ((PROPSHEETPAGEW*)lparam)->lParam;
- /* Add joysticks with FF support to the combobox and get the effects */ - for (i = 0; i < data->num_joysticks; i++) - { - struct Joystick *joy = &data->joysticks[i]; - - if (joy->forcefeedback) - { - SendDlgItemMessageW(hwnd, IDC_FFSELECTCOMBO, CB_ADDSTRING, 0, (LPARAM) joy->instance.tszInstanceName); - SendDlgItemMessageW(hwnd, IDC_FFSELECTCOMBO, CB_SETITEMDATA, cur, i); - - cur++; - } - } - + refresh_ff_joystick_list(hwnd, data); draw_ff_axis(hwnd, data);
return TRUE; @@ -861,6 +851,8 @@ static INT_PTR CALLBACK ff_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp switch(((LPNMHDR)lparam)->code) { case PSN_SETACTIVE: + refresh_ff_joystick_list(hwnd, data); + if (data->num_ff > 0) { DWORD tid;
This will not work for legacy dinput devices because of the internal enumeration logic, but it will dynamically update the list for HID joysticks.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/joy.cpl/main.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/dlls/joy.cpl/main.c b/dlls/joy.cpl/main.c index d5272990df3..dbe84963c5d 100644 --- a/dlls/joy.cpl/main.c +++ b/dlls/joy.cpl/main.c @@ -155,20 +155,7 @@ static void destroy_joysticks(struct JoystickData *data) }
free(data->joysticks); -} - -static void initialize_joysticks_list(HWND hwnd, struct JoystickData *data) -{ - int i; - - SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_RESETCONTENT, 0, 0); - - /* Add enumerated joysticks */ - for (i = 0; i < data->num_joysticks; i++) - { - struct Joystick *joy = &data->joysticks[i]; - SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_ADDSTRING, 0, (LPARAM) joy->instance.tszInstanceName); - } + data->joysticks = NULL; }
/****************************************************************************** @@ -233,15 +220,23 @@ static void enable_joystick(WCHAR *joy_name, BOOL enable) if (appkey) RegCloseKey(appkey); }
-static void initialize_disabled_joysticks_list(HWND hwnd) +static void refresh_joystick_list(HWND hwnd, struct JoystickData *data) { + struct Joystick *joy, *joy_end; HKEY hkey, appkey; DWORD values = 0; LSTATUS status; DWORD i;
+ destroy_joysticks(data); + initialize_joysticks(data); + + SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_RESETCONTENT, 0, 0); SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_RESETCONTENT, 0, 0);
+ for (joy = data->joysticks, joy_end = joy + data->num_joysticks; joy != joy_end; ++joy) + SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_ADDSTRING, 0, (LPARAM) joy->instance.tszInstanceName); + /* Search for disabled joysticks */ get_app_key(&hkey, &appkey); RegQueryInfoKeyW(hkey, NULL, NULL, NULL, NULL, NULL, NULL, &values, NULL, NULL, NULL, NULL); @@ -275,8 +270,7 @@ static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM { data = (struct JoystickData*) ((PROPSHEETPAGEW*)lparam)->lParam;
- initialize_joysticks_list(hwnd, data); - initialize_disabled_joysticks_list(hwnd); + refresh_joystick_list(hwnd, data);
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONENABLE), FALSE); EnableWindow(GetDlgItem(hwnd, IDC_BUTTONDISABLE), FALSE); @@ -298,7 +292,7 @@ static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM if (sel >= 0) { enable_joystick(data->joysticks[sel].instance.tszInstanceName, FALSE); - initialize_disabled_joysticks_list(hwnd); + refresh_joystick_list(hwnd, data); } } break; @@ -312,7 +306,7 @@ static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM WCHAR text[MAX_PATH]; SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_GETTEXT, sel, (LPARAM) text); enable_joystick(text, TRUE); - initialize_disabled_joysticks_list(hwnd); + refresh_joystick_list(hwnd, data); } } break;