[2/3] joy.cpl: Using joystick name suffixed with driver when in Linux

Lucas Zawacki lfzawacki at gmail.com
Mon Aug 20 01:47:05 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 |   58 ++++++++++++++++++++++++++++++++++++++++++---------
 3 files changed, 51 insertions(+), 12 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 354dfd7..ab38638 100644
--- a/dlls/joy.cpl/main.c
+++ b/dlls/joy.cpl/main.c
@@ -38,6 +38,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(joycpl);
 
 DECLSPEC_HIDDEN HMODULE hcpl;
 
+/* 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'} };
+
 /*********************************************************************
  *  DllMain
  */
@@ -68,6 +77,10 @@ static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *cont
     struct JoystickData *data = context;
     struct Joystick *joystick;
     DIPROPRANGE proprange;
+    const WCHAR *device_name = NULL;
+    int name_size;
+    int i;
+
     DIDEVCAPS caps;
 
     if (data->joysticks == NULL)
@@ -103,6 +116,20 @@ static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *cont
 
     IDirectInputDevice_SetProperty(joystick->device, DIPROP_RANGE, &proprange.diph);
 
+    /* Store joystick name + driver name */
+    for (i=0; i < sizeof(wine_guids)/sizeof(wine_guids[0]); i++)
+        if (IsEqualGUID(wine_guids[i], &instance->guidProduct))
+            device_name = wine_device_names[i];
+
+    name_size = lstrlenW(instance->tszInstanceName) + 1;
+
+    if (device_name) name_size += lstrlenW(device_name);
+
+    joystick->name = HeapAlloc(GetProcessHeap(), 0, name_size * sizeof(WCHAR));
+    lstrcpynW(joystick->name, instance->tszInstanceName, lstrlenW(instance->tszInstanceName) + 1);
+
+    if (device_name) lstrcatW(joystick->name, device_name);
+
     return DIENUM_CONTINUE;
 }
 
@@ -138,6 +165,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);
     }
@@ -145,26 +173,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;
@@ -184,7 +222,6 @@ static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
                     FIXME("Re-Enable selected joystick\n");
                     break;
             }
-
             return TRUE;
 
         case WM_NOTIFY:
@@ -200,6 +237,7 @@ static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
  * Joystick testing functions
  *
  */
+
 static void dump_joy_state(DIJOYSTATE* st, int num_buttons)
 {
     int i;
@@ -413,7 +451,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