[PATCH 2/3] joy.cpl: Using joystick name suffixed with driver when in Linux (try 2)
Lucas Zawacki
lfzawacki at gmail.com
Wed Aug 22 16:55:34 CDT 2012
From: Lucas Zawacki <lfzawacki at gmail.com>
Made the comboboxes holding joystick names bigger so that the user
can read their entirety and the driver name.
---
dlls/joy.cpl/joy.h | 1 +
dlls/joy.cpl/joy.rc | 4 ++--
dlls/joy.cpl/main.c | 60 +++++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 54 insertions(+), 11 deletions(-)
diff --git a/dlls/joy.cpl/joy.h b/dlls/joy.cpl/joy.h
index 16d7a0b..5fa1e72 100644
--- a/dlls/joy.cpl/joy.h
+++ b/dlls/joy.cpl/joy.h
@@ -38,6 +38,7 @@ struct Effect {
struct Joystick {
IDirectInputDevice8W *device;
DIDEVICEINSTANCEW instance;
+ WCHAR *name;
int num_buttons;
int num_axes;
BOOL forcefeedback;
diff --git a/dlls/joy.cpl/joy.rc b/dlls/joy.cpl/joy.rc
index f407aa6..0b07e15 100644
--- a/dlls/joy.cpl/joy.rc
+++ b/dlls/joy.cpl/joy.rc
@@ -46,7 +46,7 @@ STYLE WS_CAPTION | WS_CHILD | WS_DISABLED
CAPTION "Test Joystick"
FONT 8, "Ms Shell Dlg"
{
- COMBOBOX IDC_TESTSELECTCOMBO, 5, 5, 100, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS
+ COMBOBOX IDC_TESTSELECTCOMBO, 5, 5, 200, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS
GROUPBOX "Buttons", IDC_STATIC, 0, 110, 250, 110
GROUPBOX "", IDC_TESTGROUPXY, 15, 30, 60, 60
GROUPBOX "", IDC_TESTGROUPRXRY, 92, 30, 60, 60
@@ -59,7 +59,7 @@ STYLE WS_CAPTION | WS_CHILD | WS_DISABLED
CAPTION "Test Force Feedback"
FONT 8, "Ms Shell Dlg"
{
- COMBOBOX IDC_FFSELECTCOMBO, 5, 5, 100, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS
+ COMBOBOX IDC_FFSELECTCOMBO, 5, 5, 200, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS
LTEXT "Available Effects", IDC_STATIC, 10, 30, 100, 10
LISTBOX IDC_FFEFFECTLIST, 10, 40, 180, 70, WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY
LTEXT "Press any button in the controller to activate the chosen effect. The effect direction can be changed with the controller axis.",
diff --git a/dlls/joy.cpl/main.c b/dlls/joy.cpl/main.c
index 0631466..b5bac6a 100644
--- a/dlls/joy.cpl/main.c
+++ b/dlls/joy.cpl/main.c
@@ -57,6 +57,34 @@ BOOL WINAPI DllMain(HINSTANCE hdll, DWORD reason, LPVOID reserved)
return TRUE;
}
+static void get_joystick_name(struct Joystick *joy)
+{
+ /* Base product guids as Wine defines them in DirectInput */
+ /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
+ static const GUID linux_guid = { 0x9e573ed9, 0x7734, 0x11d2, {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7} };
+ /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
+ static const GUID linuxinput_guid = { 0x9e573eda, 0x7734, 0x11d2, {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7} };
+ static REFGUID wine_guids[] = { &linux_guid, &linuxinput_guid };
+ static const WCHAR wine_device_names[2][9] = { {'(','j','s',')','\0'}, {'(','e','v','e','n','t',')','\0'} };
+
+ const WCHAR *device_name = NULL;
+ int name_size, i;
+
+ /* Joystick name + driver name */
+ for (i=0; i < sizeof(wine_guids)/sizeof(wine_guids[0]); i++)
+ if (IsEqualGUID(wine_guids[i], &joy->instance.guidProduct))
+ device_name = wine_device_names[i];
+
+ name_size = lstrlenW(joy->instance.tszInstanceName) + 1;
+
+ if (device_name) name_size += lstrlenW(device_name);
+
+ joy->name = HeapAlloc(GetProcessHeap(), 0, name_size * sizeof(WCHAR));
+ lstrcpynW(joy->name, joy->instance.tszInstanceName, lstrlenW(joy->instance.tszInstanceName) + 1);
+
+ if (device_name) lstrcatW(joy->name, device_name);
+}
+
/***********************************************************************
* enum_callback [internal]
* Enumerates, creates and sets the common data format for all the joystick devices.
@@ -68,6 +96,7 @@ static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *cont
struct JoystickData *data = context;
struct Joystick *joystick;
DIPROPRANGE proprange;
+
DIDEVCAPS caps;
if (data->joysticks == NULL)
@@ -104,6 +133,8 @@ static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *cont
IDirectInputDevice_SetProperty(joystick->device, DIPROP_RANGE, &proprange.diph);
+ get_joystick_name(joystick);
+
return DIENUM_CONTINUE;
}
@@ -139,6 +170,7 @@ static void destroy_joysticks(struct JoystickData *data)
HeapFree(GetProcessHeap(), 0, data->joysticks[i].effects);
}
+ HeapFree(GetProcessHeap(), 0, data->joysticks[i].name);
IDirectInputDevice8_Unacquire(data->joysticks[i].device);
IDirectInputDevice8_Release(data->joysticks[i].device);
}
@@ -146,26 +178,36 @@ static void destroy_joysticks(struct JoystickData *data)
HeapFree(GetProcessHeap(), 0, 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->name);
+ }
+}
+
+
/*********************************************************************
* list_dlgproc [internal]
*
*/
static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
+ static struct JoystickData *data;
TRACE("(%p, 0x%08x/%d, 0x%lx)\n", hwnd, msg, msg, lparam);
switch (msg)
{
case WM_INITDIALOG:
{
- int i;
- struct JoystickData *data = (struct JoystickData*) ((PROPSHEETPAGEW*)lparam)->lParam;
+ data = (struct JoystickData*) ((PROPSHEETPAGEW*)lparam)->lParam;
- /* Set dialog information */
- 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);
- }
+ initialize_joysticks_list(hwnd, data);
/* Store the hwnd to be used with MapDialogRect for unit conversions */
data->graphics.hwnd = hwnd;
@@ -415,7 +457,7 @@ static INT_PTR CALLBACK test_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
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);
+ SendDlgItemMessageW(hwnd, IDC_TESTSELECTCOMBO, CB_ADDSTRING, 0, (LPARAM) joy->name);
}
draw_joystick_buttons(hwnd, data);
--
1.7.9.5
More information about the wine-patches
mailing list