Rémi Bernon : joy.cpl: Refresh the joystick device list when modified.

Alexandre Julliard julliard at winehq.org
Thu Sep 23 15:35:05 CDT 2021


Module: wine
Branch: master
Commit: c496a7b3f984fa0eb4931757da77eeecd6a7ab38
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=c496a7b3f984fa0eb4931757da77eeecd6a7ab38

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Thu Sep 23 14:01:55 2021 +0200

joy.cpl: Refresh the joystick device list when modified.

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 at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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;




More information about the wine-cvs mailing list