2012-06-05 17:01:37 +02:00
|
|
|
/*
|
|
|
|
* Joystick testing control panel applet
|
|
|
|
*
|
|
|
|
* Copyright 2012 Lucas Fialho Zawacki
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define COBJMACROS
|
|
|
|
#define CONST_VTABLE
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <winuser.h>
|
|
|
|
#include <commctrl.h>
|
|
|
|
#include <cpl.h>
|
|
|
|
#include "ole2.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "joy.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(joycpl);
|
|
|
|
|
|
|
|
DECLSPEC_HIDDEN HMODULE hcpl;
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* DllMain
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE hdll, DWORD reason, LPVOID reserved)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %p)\n", hdll, reason, reserved);
|
|
|
|
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
DisableThreadLibraryCalls(hdll);
|
|
|
|
hcpl = hdll;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-05 17:01:38 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* enum_callback [internal]
|
|
|
|
* Enumerates, creates and sets the common data format for all the joystick devices.
|
|
|
|
* First time it checks if space for the joysticks was already reserved
|
|
|
|
* and if not, just counts how many there are.
|
|
|
|
*/
|
2021-09-23 14:01:52 +02:00
|
|
|
static BOOL CALLBACK ff_effects_callback(const DIEFFECTINFOW *pdei, void *pvRef);
|
2012-06-05 17:01:38 +02:00
|
|
|
static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *context)
|
|
|
|
{
|
2021-09-24 10:10:32 +02:00
|
|
|
DIPROPGUIDANDPATH prop_guid_path =
|
|
|
|
{
|
|
|
|
.diph =
|
|
|
|
{
|
|
|
|
.dwSize = sizeof(DIPROPGUIDANDPATH),
|
|
|
|
.dwHeaderSize = sizeof(DIPROPHEADER),
|
|
|
|
.dwHow = DIPH_DEVICE,
|
|
|
|
},
|
|
|
|
};
|
2012-06-05 17:01:38 +02:00
|
|
|
struct JoystickData *data = context;
|
|
|
|
struct Joystick *joystick;
|
2012-07-17 03:37:12 +02:00
|
|
|
DIPROPRANGE proprange;
|
2012-06-07 19:44:12 +02:00
|
|
|
DIDEVCAPS caps;
|
2012-06-05 17:01:38 +02:00
|
|
|
|
|
|
|
if (data->joysticks == NULL)
|
|
|
|
{
|
|
|
|
data->num_joysticks += 1;
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
joystick = &data->joysticks[data->cur_joystick];
|
|
|
|
data->cur_joystick += 1;
|
|
|
|
|
|
|
|
IDirectInput8_CreateDevice(data->di, &instance->guidInstance, &joystick->device, NULL);
|
|
|
|
IDirectInputDevice8_SetDataFormat(joystick->device, &c_dfDIJoystick);
|
|
|
|
|
|
|
|
joystick->instance = *instance;
|
|
|
|
|
2012-06-07 19:44:12 +02:00
|
|
|
caps.dwSize = sizeof(caps);
|
|
|
|
IDirectInputDevice8_GetCapabilities(joystick->device, &caps);
|
|
|
|
|
|
|
|
joystick->num_buttons = caps.dwButtons;
|
|
|
|
joystick->num_axes = caps.dwAxes;
|
2012-07-17 03:35:23 +02:00
|
|
|
joystick->forcefeedback = caps.dwFlags & DIDC_FORCEFEEDBACK;
|
2012-08-20 08:39:07 +02:00
|
|
|
joystick->num_effects = 0;
|
2012-07-17 03:35:23 +02:00
|
|
|
|
2021-09-24 10:10:32 +02:00
|
|
|
IDirectInputDevice8_GetProperty(joystick->device, DIPROP_GUIDANDPATH, &prop_guid_path.diph);
|
2021-12-23 15:33:09 +01:00
|
|
|
joystick->is_xinput = wcsstr(prop_guid_path.wszPath, L"&ig_") != NULL;
|
2021-09-24 10:10:32 +02:00
|
|
|
|
2012-07-17 03:35:23 +02:00
|
|
|
if (joystick->forcefeedback) data->num_ff++;
|
2012-06-07 19:44:12 +02:00
|
|
|
|
2012-07-17 03:37:12 +02:00
|
|
|
/* Set axis range to ease the GUI visualization */
|
|
|
|
proprange.diph.dwSize = sizeof(DIPROPRANGE);
|
|
|
|
proprange.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
|
|
|
proprange.diph.dwHow = DIPH_DEVICE;
|
|
|
|
proprange.diph.dwObj = 0;
|
|
|
|
proprange.lMin = TEST_AXIS_MIN;
|
|
|
|
proprange.lMax = TEST_AXIS_MAX;
|
|
|
|
|
|
|
|
IDirectInputDevice_SetProperty(joystick->device, DIPROP_RANGE, &proprange.diph);
|
|
|
|
|
2021-09-23 14:01:52 +02:00
|
|
|
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;
|
|
|
|
|
2012-06-05 17:01:38 +02:00
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* initialize_joysticks [internal]
|
|
|
|
*/
|
|
|
|
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);
|
2021-09-23 14:01:50 +02:00
|
|
|
data->joysticks = malloc(sizeof(struct Joystick) * data->num_joysticks);
|
2012-06-05 17:01:38 +02:00
|
|
|
|
|
|
|
/* Get all the joysticks */
|
|
|
|
IDirectInput8_EnumDevices(data->di, DI8DEVCLASS_GAMECTRL, enum_callback, data, DIEDFL_ATTACHEDONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* destroy_joysticks [internal]
|
|
|
|
*/
|
|
|
|
static void destroy_joysticks(struct JoystickData *data)
|
|
|
|
{
|
2012-07-17 03:35:23 +02:00
|
|
|
int i, j;
|
2012-06-05 17:01:38 +02:00
|
|
|
|
|
|
|
for (i = 0; i < data->num_joysticks; i++)
|
|
|
|
{
|
2012-07-17 03:35:23 +02:00
|
|
|
|
2012-08-20 08:39:07 +02:00
|
|
|
if (data->joysticks[i].forcefeedback && data->joysticks[i].num_effects > 0)
|
2012-07-17 03:35:23 +02:00
|
|
|
{
|
|
|
|
for (j = 0; j < data->joysticks[i].num_effects; j++)
|
2019-05-18 21:02:58 +02:00
|
|
|
if (data->joysticks[i].effects[j].effect)
|
|
|
|
IDirectInputEffect_Release(data->joysticks[i].effects[j].effect);
|
2012-07-17 03:35:23 +02:00
|
|
|
|
2021-09-23 14:01:50 +02:00
|
|
|
free(data->joysticks[i].effects);
|
2012-07-17 03:35:23 +02:00
|
|
|
}
|
|
|
|
|
2012-06-05 17:01:38 +02:00
|
|
|
IDirectInputDevice8_Unacquire(data->joysticks[i].device);
|
|
|
|
IDirectInputDevice8_Release(data->joysticks[i].device);
|
|
|
|
}
|
|
|
|
|
2021-09-23 14:01:50 +02:00
|
|
|
free(data->joysticks);
|
2021-09-23 14:01:55 +02:00
|
|
|
data->joysticks = NULL;
|
2012-08-24 09:55:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* get_app_key [internal]
|
|
|
|
* Get the default DirectInput key and the selected app config key.
|
|
|
|
*/
|
|
|
|
static BOOL get_app_key(HKEY *defkey, HKEY *appkey)
|
|
|
|
{
|
|
|
|
*appkey = 0;
|
|
|
|
|
|
|
|
/* Registry key can be found in HKCU\Software\Wine\DirectInput */
|
2020-10-07 00:52:02 +02:00
|
|
|
if (RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\Wine\\DirectInput\\Joysticks", 0, NULL, 0,
|
|
|
|
KEY_SET_VALUE | KEY_READ, NULL, defkey, NULL))
|
2012-08-24 09:55:08 +02:00
|
|
|
*defkey = 0;
|
|
|
|
|
|
|
|
return *defkey || *appkey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* set_config_key [internal]
|
|
|
|
* Writes a string value to a registry key, deletes the key if value == NULL
|
|
|
|
*/
|
|
|
|
static DWORD set_config_key(HKEY defkey, HKEY appkey, const WCHAR *name, const WCHAR *value, DWORD size)
|
|
|
|
{
|
|
|
|
if (value == NULL)
|
|
|
|
{
|
|
|
|
if (appkey && !RegDeleteValueW(appkey, name))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (defkey && !RegDeleteValueW(defkey, name))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (appkey && !RegSetValueExW(appkey, name, 0, REG_SZ, (const BYTE*) value, (size + 1)*sizeof(WCHAR)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (defkey && !RegSetValueExW(defkey, name, 0, REG_SZ, (const BYTE*) value, (size + 1)*sizeof(WCHAR)))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* enable_joystick [internal]
|
|
|
|
* Writes to the DirectInput registry key that enables/disables a joystick
|
|
|
|
* from being enumerated.
|
|
|
|
*/
|
|
|
|
static void enable_joystick(WCHAR *joy_name, BOOL enable)
|
|
|
|
{
|
|
|
|
HKEY hkey, appkey;
|
|
|
|
|
|
|
|
get_app_key(&hkey, &appkey);
|
|
|
|
|
|
|
|
if (!enable)
|
2021-09-23 14:01:51 +02:00
|
|
|
set_config_key(hkey, appkey, joy_name, L"disabled", wcslen(L"disabled"));
|
2012-08-24 09:55:08 +02:00
|
|
|
else
|
|
|
|
set_config_key(hkey, appkey, joy_name, NULL, 0);
|
|
|
|
|
|
|
|
if (hkey) RegCloseKey(hkey);
|
|
|
|
if (appkey) RegCloseKey(appkey);
|
|
|
|
}
|
|
|
|
|
2021-09-23 14:01:55 +02:00
|
|
|
static void refresh_joystick_list(HWND hwnd, struct JoystickData *data)
|
2012-08-24 09:55:08 +02:00
|
|
|
{
|
2021-09-23 14:01:55 +02:00
|
|
|
struct Joystick *joy, *joy_end;
|
2012-08-24 09:55:08 +02:00
|
|
|
HKEY hkey, appkey;
|
|
|
|
DWORD values = 0;
|
2016-09-13 09:03:17 +02:00
|
|
|
LSTATUS status;
|
2013-03-09 22:48:51 +01:00
|
|
|
DWORD i;
|
2012-08-24 09:55:08 +02:00
|
|
|
|
2021-09-23 14:01:55 +02:00
|
|
|
destroy_joysticks(data);
|
|
|
|
initialize_joysticks(data);
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_RESETCONTENT, 0, 0);
|
2012-08-24 09:55:08 +02:00
|
|
|
SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_RESETCONTENT, 0, 0);
|
2021-09-24 10:10:32 +02:00
|
|
|
SendDlgItemMessageW(hwnd, IDC_XINPUTLIST, LB_RESETCONTENT, 0, 0);
|
2012-08-24 09:55:08 +02:00
|
|
|
|
2021-09-23 14:01:55 +02:00
|
|
|
for (joy = data->joysticks, joy_end = joy + data->num_joysticks; joy != joy_end; ++joy)
|
2021-09-24 10:10:32 +02:00
|
|
|
{
|
|
|
|
if (joy->is_xinput) SendDlgItemMessageW(hwnd, IDC_XINPUTLIST, LB_ADDSTRING, 0, (LPARAM) joy->instance.tszInstanceName);
|
|
|
|
else SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_ADDSTRING, 0, (LPARAM) joy->instance.tszInstanceName);
|
|
|
|
}
|
2021-09-23 14:01:55 +02:00
|
|
|
|
2012-08-24 09:55:08 +02:00
|
|
|
/* Search for disabled joysticks */
|
|
|
|
get_app_key(&hkey, &appkey);
|
|
|
|
RegQueryInfoKeyW(hkey, NULL, NULL, NULL, NULL, NULL, NULL, &values, NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
for (i=0; i < values; i++)
|
|
|
|
{
|
|
|
|
DWORD name_len = MAX_PATH, data_len = MAX_PATH;
|
|
|
|
WCHAR buf_name[MAX_PATH + 9], buf_data[MAX_PATH];
|
|
|
|
|
2016-09-13 09:03:17 +02:00
|
|
|
status = RegEnumValueW(hkey, i, buf_name, &name_len, NULL, NULL, (BYTE*) buf_data, &data_len);
|
2012-08-24 09:55:08 +02:00
|
|
|
|
2021-09-23 14:01:51 +02:00
|
|
|
if (status == ERROR_SUCCESS && !wcscmp(L"disabled", buf_data))
|
2012-08-24 09:55:08 +02:00
|
|
|
SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_ADDSTRING, 0, (LPARAM) buf_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hkey) RegCloseKey(hkey);
|
|
|
|
if (appkey) RegCloseKey(appkey);
|
|
|
|
}
|
|
|
|
|
2021-09-24 10:10:36 +02:00
|
|
|
static void override_joystick(WCHAR *joy_name, BOOL override)
|
|
|
|
{
|
|
|
|
HKEY hkey, appkey;
|
|
|
|
|
|
|
|
get_app_key(&hkey, &appkey);
|
|
|
|
|
|
|
|
if (override)
|
|
|
|
set_config_key(hkey, appkey, joy_name, L"override", wcslen(L"override"));
|
|
|
|
else
|
|
|
|
set_config_key(hkey, appkey, joy_name, NULL, 0);
|
|
|
|
|
|
|
|
if (hkey) RegCloseKey(hkey);
|
|
|
|
if (appkey) RegCloseKey(appkey);
|
|
|
|
}
|
|
|
|
|
2012-06-05 17:01:38 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* list_dlgproc [internal]
|
|
|
|
*
|
|
|
|
*/
|
2012-06-12 10:25:27 +02:00
|
|
|
static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
2012-06-05 17:01:38 +02:00
|
|
|
{
|
2021-09-24 10:10:32 +02:00
|
|
|
WCHAR instance_name[MAX_PATH] = {0};
|
2012-08-24 09:55:08 +02:00
|
|
|
static struct JoystickData *data;
|
2021-09-24 10:10:32 +02:00
|
|
|
int sel;
|
|
|
|
|
2012-06-05 17:01:38 +02:00
|
|
|
TRACE("(%p, 0x%08x/%d, 0x%lx)\n", hwnd, msg, msg, lparam);
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
2012-08-24 09:55:08 +02:00
|
|
|
data = (struct JoystickData*) ((PROPSHEETPAGEW*)lparam)->lParam;
|
2012-06-05 17:01:38 +02:00
|
|
|
|
2021-09-23 14:01:55 +02:00
|
|
|
refresh_joystick_list(hwnd, data);
|
2012-08-24 09:55:08 +02:00
|
|
|
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONENABLE), FALSE);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONDISABLE), FALSE);
|
2021-09-24 10:10:36 +02:00
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONRESET), FALSE);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONOVERRIDE), FALSE);
|
2012-06-05 17:01:38 +02:00
|
|
|
|
2012-08-14 01:36:54 +02:00
|
|
|
/* Store the hwnd to be used with MapDialogRect for unit conversions */
|
|
|
|
data->graphics.hwnd = hwnd;
|
|
|
|
|
2012-06-05 17:01:38 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
|
|
|
|
switch (LOWORD(wparam))
|
|
|
|
{
|
|
|
|
case IDC_BUTTONDISABLE:
|
2012-08-24 09:55:08 +02:00
|
|
|
{
|
2021-09-24 10:10:32 +02:00
|
|
|
if ((sel = SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_GETCURSEL, 0, 0)) >= 0)
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_GETTEXT, sel, (LPARAM)instance_name);
|
|
|
|
if ((sel = SendDlgItemMessageW(hwnd, IDC_XINPUTLIST, LB_GETCURSEL, 0, 0)) >= 0)
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_XINPUTLIST, LB_GETTEXT, sel, (LPARAM)instance_name);
|
2012-08-24 09:55:08 +02:00
|
|
|
|
2021-09-24 10:10:32 +02:00
|
|
|
if (instance_name[0])
|
2012-08-24 09:55:08 +02:00
|
|
|
{
|
2021-09-24 10:10:32 +02:00
|
|
|
enable_joystick(instance_name, FALSE);
|
2021-09-23 14:01:55 +02:00
|
|
|
refresh_joystick_list(hwnd, data);
|
2012-08-24 09:55:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-06-05 17:01:38 +02:00
|
|
|
|
|
|
|
case IDC_BUTTONENABLE:
|
2012-08-24 09:55:08 +02:00
|
|
|
{
|
2021-09-24 10:10:32 +02:00
|
|
|
if ((sel = SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_GETCURSEL, 0, 0)) >= 0)
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_GETTEXT, sel, (LPARAM)instance_name);
|
2012-08-24 09:55:08 +02:00
|
|
|
|
2021-09-24 10:10:32 +02:00
|
|
|
if (instance_name[0])
|
2012-08-24 09:55:08 +02:00
|
|
|
{
|
2021-09-24 10:10:32 +02:00
|
|
|
enable_joystick(instance_name, TRUE);
|
2021-09-23 14:01:55 +02:00
|
|
|
refresh_joystick_list(hwnd, data);
|
2012-08-24 09:55:08 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-03 19:23:07 +02:00
|
|
|
break;
|
2012-08-24 09:55:08 +02:00
|
|
|
|
2021-09-24 10:10:36 +02:00
|
|
|
case IDC_BUTTONRESET:
|
|
|
|
{
|
|
|
|
if ((sel = SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_GETCURSEL, 0, 0)) >= 0)
|
|
|
|
{
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_GETTEXT, sel, (LPARAM)instance_name);
|
|
|
|
override_joystick(instance_name, FALSE);
|
|
|
|
refresh_joystick_list(hwnd, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_BUTTONOVERRIDE:
|
|
|
|
{
|
|
|
|
if ((sel = SendDlgItemMessageW(hwnd, IDC_XINPUTLIST, LB_GETCURSEL, 0, 0)) >= 0)
|
|
|
|
{
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_XINPUTLIST, LB_GETTEXT, sel, (LPARAM)instance_name);
|
|
|
|
override_joystick(instance_name, TRUE);
|
|
|
|
refresh_joystick_list(hwnd, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-08-24 09:55:08 +02:00
|
|
|
case IDC_JOYSTICKLIST:
|
2021-09-24 10:10:32 +02:00
|
|
|
SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_SETCURSEL, -1, 0);
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_XINPUTLIST, LB_SETCURSEL, -1, 0);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONENABLE), FALSE);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONDISABLE), TRUE);
|
2021-09-24 10:10:36 +02:00
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONOVERRIDE), FALSE);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONRESET), TRUE);
|
2021-09-24 10:10:32 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_XINPUTLIST:
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_SETCURSEL, -1, 0);
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_SETCURSEL, -1, 0);
|
2012-08-24 09:55:08 +02:00
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONENABLE), FALSE);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONDISABLE), TRUE);
|
2021-09-24 10:10:36 +02:00
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONOVERRIDE), TRUE);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONRESET), FALSE);
|
2012-08-24 09:55:08 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_DISABLEDLIST:
|
2021-09-24 10:10:32 +02:00
|
|
|
SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_SETCURSEL, -1, 0);
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_XINPUTLIST, LB_SETCURSEL, -1, 0);
|
2012-08-24 09:55:08 +02:00
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONENABLE), TRUE);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONDISABLE), FALSE);
|
2021-09-24 10:10:36 +02:00
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONOVERRIDE), FALSE);
|
|
|
|
EnableWindow(GetDlgItem(hwnd, IDC_BUTTONRESET), FALSE);
|
2012-08-24 09:55:08 +02:00
|
|
|
break;
|
2012-06-05 17:01:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_NOTIFY:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-07 19:44:12 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* Joystick testing functions
|
|
|
|
*
|
|
|
|
*/
|
2021-10-14 09:39:54 +02:00
|
|
|
static void dump_joy_state(DIJOYSTATE* st)
|
2012-06-07 19:44:14 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
TRACE("Ax (% 5d,% 5d,% 5d)\n", st->lX,st->lY, st->lZ);
|
|
|
|
TRACE("RAx (% 5d,% 5d,% 5d)\n", st->lRx, st->lRy, st->lRz);
|
|
|
|
TRACE("Slider (% 5d,% 5d)\n", st->rglSlider[0], st->rglSlider[1]);
|
|
|
|
TRACE("Pov (% 5d,% 5d,% 5d,% 5d)\n", st->rgdwPOV[0], st->rgdwPOV[1], st->rgdwPOV[2], st->rgdwPOV[3]);
|
|
|
|
|
|
|
|
TRACE("Buttons ");
|
2021-10-14 09:39:54 +02:00
|
|
|
for(i=0; i < TEST_MAX_BUTTONS; i++)
|
2012-06-07 19:44:14 +02:00
|
|
|
TRACE(" %c",st->rgbButtons[i] ? 'x' : 'o');
|
|
|
|
TRACE("\n");
|
|
|
|
}
|
|
|
|
|
2012-06-07 19:44:12 +02:00
|
|
|
static void poll_input(const struct Joystick *joy, DIJOYSTATE *state)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_Poll(joy->device);
|
|
|
|
|
|
|
|
/* If it failed, try to acquire the joystick */
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice8_Acquire(joy->device);
|
|
|
|
while (hr == DIERR_INPUTLOST) hr = IDirectInputDevice8_Acquire(joy->device);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hr == DIERR_OTHERAPPHASPRIO) return;
|
|
|
|
|
|
|
|
IDirectInputDevice8_GetDeviceState(joy->device, sizeof(DIJOYSTATE), state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI input_thread(void *param)
|
|
|
|
{
|
2012-06-07 19:44:13 +02:00
|
|
|
int axes_pos[TEST_MAX_AXES][2];
|
2012-06-07 19:44:12 +02:00
|
|
|
DIJOYSTATE state;
|
|
|
|
struct JoystickData *data = param;
|
|
|
|
|
2012-06-27 05:09:51 +02:00
|
|
|
/* Setup POV as clock positions
|
|
|
|
* 0
|
|
|
|
* 31500 4500
|
|
|
|
* 27000 -1 9000
|
|
|
|
* 22500 13500
|
|
|
|
* 18000
|
|
|
|
*/
|
|
|
|
int ma = TEST_AXIS_MAX;
|
|
|
|
int pov_val[9] = {0, 4500, 9000, 13500,
|
|
|
|
18000, 22500, 27000, 31500, -1};
|
|
|
|
int pov_pos[9][2] = { {0, -ma}, {ma/2, -ma/2}, {ma, 0}, {ma/2, ma/2},
|
|
|
|
{0, ma}, {-ma/2, ma/2}, {-ma, 0}, {-ma/2, -ma/2}, {0, 0} };
|
|
|
|
|
2012-06-07 19:44:12 +02:00
|
|
|
ZeroMemory(&state, sizeof(state));
|
|
|
|
|
|
|
|
while (!data->stop)
|
|
|
|
{
|
|
|
|
int i;
|
2013-03-09 22:48:51 +01:00
|
|
|
unsigned int j;
|
|
|
|
|
2012-06-07 19:44:12 +02:00
|
|
|
poll_input(&data->joysticks[data->chosen_joystick], &state);
|
|
|
|
|
2021-10-14 09:39:54 +02:00
|
|
|
dump_joy_state(&state);
|
2012-06-07 19:44:14 +02:00
|
|
|
|
2012-06-07 19:44:12 +02:00
|
|
|
/* Indicate pressed buttons */
|
2021-10-14 09:39:54 +02:00
|
|
|
for (i = 0; i < TEST_MAX_BUTTONS; i++)
|
2020-06-05 18:37:30 +02:00
|
|
|
SendMessageW(data->graphics.buttons[i], BM_SETSTATE, !!state.rgbButtons[i], 0);
|
2012-06-07 19:44:12 +02:00
|
|
|
|
2012-06-07 19:44:13 +02:00
|
|
|
/* Indicate axis positions, axes showing are hardcoded for now */
|
|
|
|
axes_pos[0][0] = state.lX;
|
|
|
|
axes_pos[0][1] = state.lY;
|
|
|
|
axes_pos[1][0] = state.lRx;
|
|
|
|
axes_pos[1][1] = state.lRy;
|
|
|
|
axes_pos[2][0] = state.lZ;
|
|
|
|
axes_pos[2][1] = state.lRz;
|
|
|
|
|
2012-06-27 05:09:51 +02:00
|
|
|
/* Set pov values */
|
2018-08-08 11:30:07 +02:00
|
|
|
for (j = 0; j < ARRAY_SIZE(pov_val); j++)
|
2012-06-27 05:09:51 +02:00
|
|
|
{
|
2013-03-09 22:48:51 +01:00
|
|
|
if (state.rgdwPOV[0] == pov_val[j])
|
2012-06-27 05:09:51 +02:00
|
|
|
{
|
2013-03-09 22:48:51 +01:00
|
|
|
axes_pos[3][0] = pov_pos[j][0];
|
|
|
|
axes_pos[3][1] = pov_pos[j][1];
|
2012-06-27 05:09:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 19:44:13 +02:00
|
|
|
for (i = 0; i < TEST_MAX_AXES; i++)
|
2012-08-14 01:36:54 +02:00
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
|
|
|
|
r.left = (TEST_AXIS_X + TEST_NEXT_AXIS_X*i + axes_pos[i][0]);
|
|
|
|
r.top = (TEST_AXIS_Y + axes_pos[i][1]);
|
2012-08-18 11:51:24 +02:00
|
|
|
r.bottom = r.right = 0; /* unused */
|
2012-08-14 01:36:54 +02:00
|
|
|
MapDialogRect(data->graphics.hwnd, &r);
|
|
|
|
|
|
|
|
SetWindowPos(data->graphics.axes[i], 0, r.left, r.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
|
|
|
|
}
|
2012-06-07 19:44:13 +02:00
|
|
|
|
2012-06-07 19:44:12 +02:00
|
|
|
Sleep(TEST_POLL_TIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_handle_joychange(HWND hwnd, struct JoystickData *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (data->num_joysticks == 0) return;
|
|
|
|
|
|
|
|
data->chosen_joystick = SendDlgItemMessageW(hwnd, IDC_TESTSELECTCOMBO, CB_GETCURSEL, 0, 0);
|
|
|
|
|
|
|
|
/* Enable only buttons present in the device */
|
|
|
|
for (i = 0; i < TEST_MAX_BUTTONS; i++)
|
2016-07-23 02:50:33 +02:00
|
|
|
ShowWindow(data->graphics.buttons[i], i < data->joysticks[data->chosen_joystick].num_buttons);
|
2012-06-07 19:44:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* button_number_to_wchar [internal]
|
|
|
|
* Transforms an integer in the interval [0,99] into a 2 character WCHAR string
|
|
|
|
*/
|
|
|
|
static void button_number_to_wchar(int n, WCHAR str[3])
|
|
|
|
{
|
|
|
|
str[1] = n % 10 + '0';
|
|
|
|
n /= 10;
|
|
|
|
str[0] = n % 10 + '0';
|
|
|
|
str[2] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_joystick_buttons(HWND hwnd, struct JoystickData* data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int row = 0, col = 0;
|
|
|
|
WCHAR button_label[3];
|
|
|
|
HINSTANCE hinst = (HINSTANCE) GetWindowLongPtrW(hwnd, GWLP_HINSTANCE);
|
|
|
|
|
|
|
|
for (i = 0; i < TEST_MAX_BUTTONS; i++)
|
|
|
|
{
|
2012-08-14 01:36:54 +02:00
|
|
|
RECT r;
|
|
|
|
|
2012-06-07 19:44:12 +02:00
|
|
|
if ((i % TEST_BUTTON_COL_MAX) == 0 && i != 0)
|
|
|
|
{
|
|
|
|
row += 1;
|
|
|
|
col = 0;
|
|
|
|
}
|
|
|
|
|
2012-08-14 01:36:54 +02:00
|
|
|
r.left = (TEST_BUTTON_X + TEST_NEXT_BUTTON_X*col);
|
|
|
|
r.top = (TEST_BUTTON_Y + TEST_NEXT_BUTTON_Y*row);
|
|
|
|
r.right = r.left + TEST_BUTTON_SIZE_X;
|
|
|
|
r.bottom = r.top + TEST_BUTTON_SIZE_Y;
|
|
|
|
MapDialogRect(hwnd, &r);
|
|
|
|
|
2012-06-07 19:44:12 +02:00
|
|
|
button_number_to_wchar(i + 1, button_label);
|
|
|
|
|
2020-10-07 00:52:02 +02:00
|
|
|
data->graphics.buttons[i] = CreateWindowW(L"Button", button_label, WS_CHILD,
|
2012-08-14 01:36:54 +02:00
|
|
|
r.left, r.top, r.right - r.left, r.bottom - r.top,
|
2012-06-07 19:44:12 +02:00
|
|
|
hwnd, NULL, NULL, hinst);
|
|
|
|
|
|
|
|
col += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 19:44:13 +02:00
|
|
|
static void draw_joystick_axes(HWND hwnd, struct JoystickData* data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
HINSTANCE hinst = (HINSTANCE) GetWindowLongPtrW(hwnd, GWLP_HINSTANCE);
|
2020-10-07 00:52:02 +02:00
|
|
|
static const WCHAR axes_names[TEST_MAX_AXES][7] = { L"X,Y", L"Rx,Ry", L"Z,Rz", L"POV"};
|
2012-06-27 05:09:51 +02:00
|
|
|
static const DWORD axes_idc[TEST_MAX_AXES] = { IDC_TESTGROUPXY, IDC_TESTGROUPRXRY,
|
|
|
|
IDC_TESTGROUPZRZ, IDC_TESTGROUPPOV };
|
2012-06-07 19:44:13 +02:00
|
|
|
|
|
|
|
for (i = 0; i < TEST_MAX_AXES; i++)
|
|
|
|
{
|
2012-08-14 01:36:54 +02:00
|
|
|
RECT r;
|
2012-06-19 16:42:08 +02:00
|
|
|
/* Set axis box name */
|
|
|
|
SetWindowTextW(GetDlgItem(hwnd, axes_idc[i]), axes_names[i]);
|
|
|
|
|
2012-08-14 01:36:54 +02:00
|
|
|
r.left = (TEST_AXIS_X + TEST_NEXT_AXIS_X*i);
|
|
|
|
r.top = TEST_AXIS_Y;
|
|
|
|
r.right = r.left + TEST_AXIS_SIZE_X;
|
|
|
|
r.bottom = r.top + TEST_AXIS_SIZE_Y;
|
|
|
|
MapDialogRect(hwnd, &r);
|
|
|
|
|
2020-10-07 00:52:02 +02:00
|
|
|
data->graphics.axes[i] = CreateWindowW(L"Button", NULL, WS_CHILD | WS_VISIBLE,
|
2012-08-14 01:36:54 +02:00
|
|
|
r.left, r.top, r.right - r.left, r.bottom - r.top,
|
|
|
|
hwnd, NULL, NULL, hinst);
|
2012-06-07 19:44:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 19:44:12 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* test_dlgproc [internal]
|
|
|
|
*
|
|
|
|
*/
|
2021-09-23 14:01:53 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-06-07 19:44:12 +02:00
|
|
|
static INT_PTR CALLBACK test_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
|
|
|
static HANDLE thread;
|
|
|
|
static struct JoystickData *data;
|
|
|
|
TRACE("(%p, 0x%08x/%d, 0x%lx)\n", hwnd, msg, msg, lparam);
|
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
data = (struct JoystickData*) ((PROPSHEETPAGEW*)lparam)->lParam;
|
|
|
|
|
2021-09-23 14:01:53 +02:00
|
|
|
refresh_test_joystick_list(hwnd, data);
|
2012-06-07 19:44:12 +02:00
|
|
|
draw_joystick_buttons(hwnd, data);
|
2012-06-07 19:44:13 +02:00
|
|
|
draw_joystick_axes(hwnd, data);
|
2012-06-07 19:44:12 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch(wparam)
|
|
|
|
{
|
|
|
|
case MAKEWPARAM(IDC_TESTSELECTCOMBO, CBN_SELCHANGE):
|
|
|
|
test_handle_joychange(hwnd, data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_NOTIFY:
|
|
|
|
switch(((LPNMHDR)lparam)->code)
|
|
|
|
{
|
|
|
|
case PSN_SETACTIVE:
|
|
|
|
{
|
|
|
|
DWORD tid;
|
|
|
|
|
2021-09-23 14:01:53 +02:00
|
|
|
refresh_test_joystick_list(hwnd, data);
|
|
|
|
|
2012-06-07 19:44:12 +02:00
|
|
|
/* Initialize input thread */
|
|
|
|
if (data->num_joysticks > 0)
|
|
|
|
{
|
|
|
|
data->stop = FALSE;
|
|
|
|
|
|
|
|
/* Set the first joystick as default */
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_TESTSELECTCOMBO, CB_SETCURSEL, 0, 0);
|
|
|
|
test_handle_joychange(hwnd, data);
|
|
|
|
|
|
|
|
thread = CreateThread(NULL, 0, input_thread, (void*) data, 0, &tid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-07-16 19:05:39 +02:00
|
|
|
case PSN_RESET: /* intentional fall-through */
|
|
|
|
case PSN_KILLACTIVE:
|
2012-06-07 19:44:12 +02:00
|
|
|
/* Stop input thread */
|
|
|
|
data->stop = TRUE;
|
2012-07-16 19:05:39 +02:00
|
|
|
MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, 0);
|
2012-06-07 19:44:12 +02:00
|
|
|
CloseHandle(thread);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-07-17 03:35:23 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* Joystick force feedback testing functions
|
|
|
|
*
|
|
|
|
*/
|
2012-07-17 03:37:12 +02:00
|
|
|
static void draw_ff_axis(HWND hwnd, struct JoystickData *data)
|
|
|
|
{
|
|
|
|
HINSTANCE hinst = (HINSTANCE) GetWindowLongPtrW(hwnd, GWLP_HINSTANCE);
|
2012-08-14 01:36:54 +02:00
|
|
|
RECT r;
|
|
|
|
|
|
|
|
r.left = FF_AXIS_X;
|
|
|
|
r.top = FF_AXIS_Y;
|
|
|
|
r.right = r.left + FF_AXIS_SIZE_X;
|
|
|
|
r.bottom = r.top + FF_AXIS_SIZE_Y;
|
|
|
|
MapDialogRect(hwnd, &r);
|
2012-07-17 03:37:12 +02:00
|
|
|
|
|
|
|
/* Draw direction axis */
|
2020-10-07 00:52:02 +02:00
|
|
|
data->graphics.ff_axis = CreateWindowW(L"Button", NULL, WS_CHILD | WS_VISIBLE,
|
2012-08-14 01:36:54 +02:00
|
|
|
r.left, r.top, r.right - r.left, r.bottom - r.top,
|
|
|
|
hwnd, NULL, NULL, hinst);
|
2012-07-17 03:37:12 +02:00
|
|
|
}
|
2012-07-17 03:35:23 +02:00
|
|
|
|
|
|
|
static void initialize_effects_list(HWND hwnd, struct Joystick* joy)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_FFEFFECTLIST, LB_RESETCONTENT, 0, 0);
|
|
|
|
|
|
|
|
for (i=0; i < joy->num_effects; i++)
|
|
|
|
{
|
|
|
|
/* Effect names start with GUID_, so we'll skip this part */
|
|
|
|
WCHAR *name = joy->effects[i].info.tszName + 5;
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_FFEFFECTLIST, LB_ADDSTRING, 0, (LPARAM) name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ff_handle_joychange(HWND hwnd, struct JoystickData *data)
|
|
|
|
{
|
|
|
|
if (data->num_ff == 0) return;
|
|
|
|
|
2021-09-23 14:01:54 +02:00
|
|
|
data->chosen_joystick = SendDlgItemMessageW(hwnd, IDC_FFSELECTCOMBO, CB_GETCURSEL, 0, 0);
|
2012-07-17 03:35:23 +02:00
|
|
|
initialize_effects_list(hwnd, &data->joysticks[data->chosen_joystick]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ff_handle_effectchange(HWND hwnd, struct Joystick *joy)
|
|
|
|
{
|
|
|
|
int sel = SendDlgItemMessageW(hwnd, IDC_FFEFFECTLIST, LB_GETCURSEL, 0, 0);
|
|
|
|
|
|
|
|
if (sel < 0) return;
|
|
|
|
|
|
|
|
joy->chosen_effect = sel;
|
2021-10-06 10:26:41 +02:00
|
|
|
IDirectInputDevice8_Unacquire(joy->device);
|
|
|
|
IDirectInputDevice8_SetCooperativeLevel(joy->device, GetAncestor(hwnd, GA_ROOT), DISCL_BACKGROUND|DISCL_EXCLUSIVE);
|
|
|
|
IDirectInputDevice8_Acquire(joy->device);
|
2012-07-17 03:35:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI ff_input_thread(void *param)
|
|
|
|
{
|
|
|
|
struct JoystickData *data = param;
|
|
|
|
DIJOYSTATE state;
|
|
|
|
|
|
|
|
ZeroMemory(&state, sizeof(state));
|
|
|
|
|
|
|
|
while (!data->stop)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct Joystick *joy = &data->joysticks[data->chosen_joystick];
|
|
|
|
int chosen_effect = joy->chosen_effect;
|
2012-07-17 03:37:12 +02:00
|
|
|
DIEFFECT *dieffect;
|
|
|
|
DWORD flags = DIEP_AXES | DIEP_DIRECTION | DIEP_NORESTART;
|
2012-08-14 01:36:54 +02:00
|
|
|
RECT r;
|
2012-07-17 03:35:23 +02:00
|
|
|
|
2019-05-19 00:43:17 +02:00
|
|
|
Sleep(TEST_POLL_TIME);
|
|
|
|
|
2012-07-17 03:35:23 +02:00
|
|
|
/* Skip this if we have no effects */
|
|
|
|
if (joy->num_effects == 0 || chosen_effect < 0) continue;
|
|
|
|
|
|
|
|
poll_input(joy, &state);
|
|
|
|
|
2012-07-17 03:37:12 +02:00
|
|
|
/* Set ff parameters and draw the axis */
|
|
|
|
dieffect = &joy->effects[chosen_effect].params;
|
|
|
|
dieffect->rgdwAxes[0] = state.lX;
|
|
|
|
dieffect->rgdwAxes[1] = state.lY;
|
|
|
|
|
2012-08-14 01:36:54 +02:00
|
|
|
r.left = FF_AXIS_X + state.lX;
|
|
|
|
r.top = FF_AXIS_Y + state.lY;
|
2012-08-18 11:51:24 +02:00
|
|
|
r.right = r.bottom = 0; /* unused */
|
2012-08-14 01:36:54 +02:00
|
|
|
MapDialogRect(data->graphics.hwnd, &r);
|
|
|
|
|
|
|
|
SetWindowPos(data->graphics.ff_axis, 0, r.left, r.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
|
2012-07-17 03:37:12 +02:00
|
|
|
|
2021-10-14 09:39:54 +02:00
|
|
|
for (i=0; i < TEST_MAX_BUTTONS; i++)
|
2012-07-17 03:35:23 +02:00
|
|
|
if (state.rgbButtons[i])
|
|
|
|
{
|
2012-07-17 03:37:12 +02:00
|
|
|
IDirectInputEffect_SetParameters(joy->effects[chosen_effect].effect, dieffect, flags);
|
2012-07-17 03:35:23 +02:00
|
|
|
IDirectInputEffect_Start(joy->effects[chosen_effect].effect, 1, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ff_effects_callback [internal]
|
|
|
|
* Enumerates, creates, sets the some parameters and stores all ff effects
|
|
|
|
* supported by the joystick. Works like enum_callback, counting the effects
|
|
|
|
* first and then storing them.
|
|
|
|
*/
|
|
|
|
static BOOL CALLBACK ff_effects_callback(const DIEFFECTINFOW *pdei, void *pvRef)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DIEFFECT dieffect;
|
|
|
|
DWORD axes[2] = {DIJOFS_X, DIJOFS_Y};
|
|
|
|
int direction[2] = {0, 0};
|
2021-11-19 09:39:42 +01:00
|
|
|
int num_axes = 2;
|
2012-07-17 03:35:23 +02:00
|
|
|
struct Joystick *joystick = pvRef;
|
2014-12-04 11:00:43 +01:00
|
|
|
DIRAMPFORCE rforce;
|
|
|
|
DICONSTANTFORCE cforce;
|
|
|
|
DIPERIODIC pforce;
|
2018-01-18 20:56:23 +01:00
|
|
|
DICONDITION cdforce;
|
2012-07-17 03:35:23 +02:00
|
|
|
|
|
|
|
if (joystick->effects == NULL)
|
|
|
|
{
|
|
|
|
joystick->num_effects += 1;
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDirectInputDevice8_Acquire(joystick->device);
|
|
|
|
|
|
|
|
if (FAILED(hr)) return DIENUM_CONTINUE;
|
|
|
|
|
|
|
|
ZeroMemory(&dieffect, sizeof(dieffect));
|
|
|
|
|
|
|
|
dieffect.dwSize = sizeof(dieffect);
|
2021-10-06 10:26:42 +02:00
|
|
|
dieffect.dwFlags = DIEFF_CARTESIAN|DIEFF_OBJECTOFFSETS;
|
2012-07-17 03:35:23 +02:00
|
|
|
dieffect.dwDuration = FF_PLAY_TIME;
|
2021-11-19 09:39:42 +01:00
|
|
|
dieffect.dwGain = DI_FFNOMINALMAX;
|
2012-07-17 03:35:23 +02:00
|
|
|
|
|
|
|
dieffect.rgdwAxes = axes;
|
|
|
|
dieffect.rglDirection = direction;
|
|
|
|
|
|
|
|
if (IsEqualGUID(&pdei->guid, &GUID_RampForce))
|
|
|
|
{
|
|
|
|
rforce.lStart = 0;
|
|
|
|
rforce.lEnd = DI_FFNOMINALMAX;
|
|
|
|
|
|
|
|
dieffect.cbTypeSpecificParams = sizeof(rforce);
|
|
|
|
dieffect.lpvTypeSpecificParams = &rforce;
|
|
|
|
dieffect.dwFlags |= DIEP_TYPESPECIFICPARAMS;
|
|
|
|
}
|
|
|
|
else if (IsEqualGUID(&pdei->guid, &GUID_ConstantForce))
|
|
|
|
{
|
|
|
|
cforce.lMagnitude = DI_FFNOMINALMAX;
|
|
|
|
|
|
|
|
dieffect.cbTypeSpecificParams = sizeof(cforce);
|
|
|
|
dieffect.lpvTypeSpecificParams = &cforce;
|
|
|
|
dieffect.dwFlags |= DIEP_TYPESPECIFICPARAMS;
|
|
|
|
}
|
|
|
|
else if (IsEqualGUID(&pdei->guid, &GUID_Sine) ||
|
|
|
|
IsEqualGUID(&pdei->guid, &GUID_Square) ||
|
|
|
|
IsEqualGUID(&pdei->guid, &GUID_Triangle) ||
|
|
|
|
IsEqualGUID(&pdei->guid, &GUID_SawtoothUp) ||
|
|
|
|
IsEqualGUID(&pdei->guid, &GUID_SawtoothDown))
|
|
|
|
{
|
|
|
|
pforce.dwMagnitude = DI_FFNOMINALMAX;
|
|
|
|
pforce.lOffset = 0;
|
|
|
|
pforce.dwPhase = 0;
|
|
|
|
pforce.dwPeriod = FF_PERIOD_TIME;
|
|
|
|
|
|
|
|
dieffect.cbTypeSpecificParams = sizeof(pforce);
|
|
|
|
dieffect.lpvTypeSpecificParams = &pforce;
|
|
|
|
dieffect.dwFlags |= DIEP_TYPESPECIFICPARAMS;
|
|
|
|
}
|
2018-01-18 20:56:23 +01:00
|
|
|
else if (IsEqualGUID(&pdei->guid, &GUID_Spring) ||
|
|
|
|
IsEqualGUID(&pdei->guid, &GUID_Damper) ||
|
|
|
|
IsEqualGUID(&pdei->guid, &GUID_Inertia) ||
|
|
|
|
IsEqualGUID(&pdei->guid, &GUID_Friction))
|
|
|
|
{
|
|
|
|
cdforce.dwPositiveSaturation = 10000;
|
|
|
|
cdforce.dwNegativeSaturation = 10000;
|
|
|
|
cdforce.lPositiveCoefficient = 10000;
|
|
|
|
cdforce.lNegativeCoefficient = 10000;
|
|
|
|
cdforce.lDeadBand = 0;
|
|
|
|
cdforce.lOffset = 0;
|
|
|
|
|
|
|
|
dieffect.cbTypeSpecificParams = sizeof(cdforce);
|
|
|
|
dieffect.lpvTypeSpecificParams = &cdforce;
|
|
|
|
dieffect.dwFlags |= DIEP_TYPESPECIFICPARAMS;
|
|
|
|
}
|
2012-07-17 03:35:23 +02:00
|
|
|
|
2021-11-19 09:39:42 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
dieffect.cAxes = num_axes--;
|
|
|
|
hr = IDirectInputDevice2_CreateEffect(
|
|
|
|
joystick->device, &pdei->guid, &dieffect, &joystick->effects[joystick->cur_effect].effect, NULL);
|
|
|
|
}
|
|
|
|
while (FAILED(hr) && num_axes);
|
|
|
|
|
2021-10-14 09:39:55 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
FIXME("Failed to create effect with type %s, hr %#x\n", debugstr_guid(&pdei->guid), hr);
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
2012-07-17 03:35:23 +02:00
|
|
|
|
|
|
|
joystick->effects[joystick->cur_effect].params = dieffect;
|
|
|
|
joystick->effects[joystick->cur_effect].info = *pdei;
|
|
|
|
joystick->cur_effect += 1;
|
|
|
|
|
|
|
|
return DIENUM_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* ff_dlgproc [internal]
|
|
|
|
*
|
|
|
|
*/
|
2021-09-23 14:01:54 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-07-17 03:35:23 +02:00
|
|
|
static INT_PTR CALLBACK ff_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
|
|
|
static HANDLE thread;
|
|
|
|
static struct JoystickData *data;
|
|
|
|
TRACE("(%p, 0x%08x/%d, 0x%lx)\n", hwnd, msg, msg, lparam);
|
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
data = (struct JoystickData*) ((PROPSHEETPAGEW*)lparam)->lParam;
|
|
|
|
|
2021-09-23 14:01:54 +02:00
|
|
|
refresh_ff_joystick_list(hwnd, data);
|
2012-07-17 03:37:12 +02:00
|
|
|
draw_ff_axis(hwnd, data);
|
|
|
|
|
2012-07-17 03:35:23 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch(wparam)
|
|
|
|
{
|
|
|
|
case MAKEWPARAM(IDC_FFSELECTCOMBO, CBN_SELCHANGE):
|
|
|
|
ff_handle_joychange(hwnd, data);
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_FFEFFECTLIST, LB_SETCURSEL, 0, 0);
|
|
|
|
ff_handle_effectchange(hwnd, &data->joysticks[data->chosen_joystick]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAKEWPARAM(IDC_FFEFFECTLIST, LBN_SELCHANGE):
|
|
|
|
ff_handle_effectchange(hwnd, &data->joysticks[data->chosen_joystick]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_NOTIFY:
|
|
|
|
switch(((LPNMHDR)lparam)->code)
|
|
|
|
{
|
|
|
|
case PSN_SETACTIVE:
|
2021-09-23 14:01:54 +02:00
|
|
|
refresh_ff_joystick_list(hwnd, data);
|
|
|
|
|
2012-07-17 03:35:23 +02:00
|
|
|
if (data->num_ff > 0)
|
|
|
|
{
|
|
|
|
DWORD tid;
|
|
|
|
|
|
|
|
data->stop = FALSE;
|
|
|
|
/* Set the first joystick as default */
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_FFSELECTCOMBO, CB_SETCURSEL, 0, 0);
|
|
|
|
ff_handle_joychange(hwnd, data);
|
|
|
|
|
|
|
|
SendDlgItemMessageW(hwnd, IDC_FFEFFECTLIST, LB_SETCURSEL, 0, 0);
|
|
|
|
ff_handle_effectchange(hwnd, &data->joysticks[data->chosen_joystick]);
|
|
|
|
|
|
|
|
thread = CreateThread(NULL, 0, ff_input_thread, (void*) data, 0, &tid);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSN_RESET: /* intentional fall-through */
|
|
|
|
case PSN_KILLACTIVE:
|
|
|
|
/* Stop ff thread */
|
|
|
|
data->stop = TRUE;
|
|
|
|
MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, 0);
|
|
|
|
CloseHandle(thread);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-05 17:01:37 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* propsheet_callback [internal]
|
|
|
|
*/
|
|
|
|
static int CALLBACK propsheet_callback(HWND hwnd, UINT msg, LPARAM lparam)
|
|
|
|
{
|
|
|
|
TRACE("(%p, 0x%08x/%d, 0x%lx)\n", hwnd, msg, msg, lparam);
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case PSCB_INITIALIZED:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* display_cpl_sheets [internal]
|
|
|
|
*
|
|
|
|
* Build and display the dialog with all control panel propertysheets
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void display_cpl_sheets(HWND parent, struct JoystickData *data)
|
|
|
|
{
|
|
|
|
INITCOMMONCONTROLSEX icex;
|
|
|
|
PROPSHEETPAGEW psp[NUM_PROPERTY_PAGES];
|
|
|
|
PROPSHEETHEADERW psh;
|
|
|
|
DWORD id = 0;
|
|
|
|
|
|
|
|
OleInitialize(NULL);
|
|
|
|
/* Initialize common controls */
|
|
|
|
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
|
|
|
icex.dwICC = ICC_LISTVIEW_CLASSES | ICC_BAR_CLASSES;
|
|
|
|
InitCommonControlsEx(&icex);
|
|
|
|
|
|
|
|
ZeroMemory(&psh, sizeof(psh));
|
|
|
|
ZeroMemory(psp, sizeof(psp));
|
|
|
|
|
|
|
|
/* Fill out all PROPSHEETPAGE */
|
|
|
|
psp[id].dwSize = sizeof (PROPSHEETPAGEW);
|
|
|
|
psp[id].hInstance = hcpl;
|
|
|
|
psp[id].u.pszTemplate = MAKEINTRESOURCEW(IDD_LIST);
|
2012-06-05 17:01:38 +02:00
|
|
|
psp[id].pfnDlgProc = list_dlgproc;
|
2012-06-05 17:01:37 +02:00
|
|
|
psp[id].lParam = (INT_PTR) data;
|
|
|
|
id++;
|
|
|
|
|
|
|
|
psp[id].dwSize = sizeof (PROPSHEETPAGEW);
|
|
|
|
psp[id].hInstance = hcpl;
|
|
|
|
psp[id].u.pszTemplate = MAKEINTRESOURCEW(IDD_TEST);
|
2012-06-07 19:44:12 +02:00
|
|
|
psp[id].pfnDlgProc = test_dlgproc;
|
2012-06-05 17:01:37 +02:00
|
|
|
psp[id].lParam = (INT_PTR) data;
|
|
|
|
id++;
|
|
|
|
|
|
|
|
psp[id].dwSize = sizeof (PROPSHEETPAGEW);
|
|
|
|
psp[id].hInstance = hcpl;
|
|
|
|
psp[id].u.pszTemplate = MAKEINTRESOURCEW(IDD_FORCEFEEDBACK);
|
2012-07-17 03:35:23 +02:00
|
|
|
psp[id].pfnDlgProc = ff_dlgproc;
|
2012-06-05 17:01:37 +02:00
|
|
|
psp[id].lParam = (INT_PTR) data;
|
|
|
|
id++;
|
|
|
|
|
|
|
|
/* Fill out the PROPSHEETHEADER */
|
|
|
|
psh.dwSize = sizeof (PROPSHEETHEADERW);
|
|
|
|
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
|
|
|
|
psh.hwndParent = parent;
|
|
|
|
psh.hInstance = hcpl;
|
|
|
|
psh.pszCaption = MAKEINTRESOURCEW(IDS_CPL_NAME);
|
|
|
|
psh.nPages = id;
|
|
|
|
psh.u3.ppsp = psp;
|
|
|
|
psh.pfnCallback = propsheet_callback;
|
|
|
|
|
|
|
|
/* display the dialog */
|
|
|
|
PropertySheetW(&psh);
|
|
|
|
|
|
|
|
OleUninitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* CPlApplet (joy.cpl.@)
|
|
|
|
*
|
|
|
|
* Control Panel entry point
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hWnd [I] Handle for the Control Panel Window
|
|
|
|
* command [I] CPL_* Command
|
|
|
|
* lParam1 [I] first extra Parameter
|
|
|
|
* lParam2 [I] second extra Parameter
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Depends on the command
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
LONG CALLBACK CPlApplet(HWND hwnd, UINT command, LPARAM lParam1, LPARAM lParam2)
|
|
|
|
{
|
|
|
|
static struct JoystickData data;
|
|
|
|
TRACE("(%p, %u, 0x%lx, 0x%lx)\n", hwnd, command, lParam1, lParam2);
|
|
|
|
|
|
|
|
switch (command)
|
|
|
|
{
|
|
|
|
case CPL_INIT:
|
2012-06-05 17:01:38 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* Initialize dinput */
|
|
|
|
hr = DirectInput8Create(GetModuleHandleW(NULL), DIRECTINPUT_VERSION, &IID_IDirectInput8W, (void**)&data.di, NULL);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Failed to initialize DirectInput: 0x%08x\n", hr);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then get all the connected joysticks */
|
|
|
|
initialize_joysticks(&data);
|
2012-06-05 17:01:37 +02:00
|
|
|
|
2012-06-05 17:01:38 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2012-06-05 17:01:37 +02:00
|
|
|
case CPL_GETCOUNT:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case CPL_INQUIRE:
|
|
|
|
{
|
|
|
|
CPLINFO *appletInfo = (CPLINFO *) lParam2;
|
|
|
|
|
2013-06-06 11:33:10 +02:00
|
|
|
appletInfo->idIcon = ICO_MAIN;
|
2012-06-05 17:01:37 +02:00
|
|
|
appletInfo->idName = IDS_CPL_NAME;
|
|
|
|
appletInfo->idInfo = IDS_CPL_INFO;
|
|
|
|
appletInfo->lData = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CPL_DBLCLK:
|
|
|
|
display_cpl_sheets(hwnd, &data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CPL_STOP:
|
2012-06-05 17:01:38 +02:00
|
|
|
destroy_joysticks(&data);
|
|
|
|
|
|
|
|
/* And destroy dinput too */
|
|
|
|
IDirectInput8_Release(data.di);
|
2012-06-05 17:01:37 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|