[PATCH 1/5] joy.cpl: Add a dedicated connected list for xinput devices.

Rémi Bernon rbernon at codeweavers.com
Fri Sep 24 01:57:08 CDT 2021


Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/joy.cpl/joy.h  | 25 +++++++++++++----------
 dlls/joy.cpl/joy.rc | 16 ++++++++-------
 dlls/joy.cpl/main.c | 50 +++++++++++++++++++++++++++++++++++++--------
 3 files changed, 64 insertions(+), 27 deletions(-)

diff --git a/dlls/joy.cpl/joy.h b/dlls/joy.cpl/joy.h
index ec7af4f7879..ffba9cd1220 100644
--- a/dlls/joy.cpl/joy.h
+++ b/dlls/joy.cpl/joy.h
@@ -41,6 +41,7 @@ struct Joystick {
     int num_buttons;
     int num_axes;
     BOOL forcefeedback;
+    BOOL is_xinput;
     int num_effects;
     int cur_effect;
     int chosen_effect;
@@ -82,17 +83,19 @@ struct JoystickData {
 #define IDD_FORCEFEEDBACK   1002
 
 #define IDC_JOYSTICKLIST    2000
-#define IDC_BUTTONDISABLE   2001
-#define IDC_BUTTONENABLE    2002
-#define IDC_DISABLEDLIST    2003
-#define IDC_TESTSELECTCOMBO 2004
-#define IDC_TESTGROUPXY     2005
-#define IDC_TESTGROUPRXRY   2006
-#define IDC_TESTGROUPZRZ    2007
-#define IDC_TESTGROUPPOV    2008
-
-#define IDC_FFSELECTCOMBO   2009
-#define IDC_FFEFFECTLIST    2010
+#define IDC_DISABLEDLIST    2001
+#define IDC_XINPUTLIST      2002
+#define IDC_BUTTONDISABLE   2010
+#define IDC_BUTTONENABLE    2011
+
+#define IDC_TESTSELECTCOMBO 2100
+#define IDC_TESTGROUPXY     2101
+#define IDC_TESTGROUPRXRY   2102
+#define IDC_TESTGROUPZRZ    2103
+#define IDC_TESTGROUPPOV    2104
+
+#define IDC_FFSELECTCOMBO   2200
+#define IDC_FFEFFECTLIST    2201
 
 #define ICO_MAIN            100
 
diff --git a/dlls/joy.cpl/joy.rc b/dlls/joy.cpl/joy.rc
index a4a780276bb..d425ea76440 100644
--- a/dlls/joy.cpl/joy.rc
+++ b/dlls/joy.cpl/joy.rc
@@ -31,21 +31,23 @@ BEGIN
     IDS_CPL_INFO        "Test and configure game controllers."
 END
 
-IDD_LIST DIALOG 0, 0, 320, 220
+IDD_LIST DIALOG 0, 0, 320, 300
 STYLE WS_CAPTION | WS_CHILD | WS_DISABLED
 CAPTION "Joysticks"
 FONT 8, "Ms Shell Dlg"
 {
     PUSHBUTTON      "&Disable", IDC_BUTTONDISABLE, 200, 20, 60, 15
-    PUSHBUTTON      "&Enable", IDC_BUTTONENABLE, 200, 105, 60, 15
+    PUSHBUTTON      "&Enable", IDC_BUTTONENABLE, 200, 190, 60, 15
     LTEXT           "Connected", IDC_STATIC, 10, 10, 100, 10
     LISTBOX         IDC_JOYSTICKLIST, 10, 20, 180, 70, WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY
-    LTEXT           "Disabled", IDC_STATIC, 10, 95, 100, 10
-    LISTBOX         IDC_DISABLEDLIST, 10, 105, 180, 70, WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY
-    LTEXT           "After disabling or enabling a device, the connected joysticks won't be updated here until you restart this applet.", IDC_STATIC, 10, 175, 200, 25
+    LTEXT           "Connected (xinput device)", IDC_STATIC, 10, 90, 100, 10
+    LISTBOX         IDC_XINPUTLIST, 10, 100, 180, 70, WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY
+    LTEXT           "Disabled", IDC_STATIC, 10, 180, 100, 10
+    LISTBOX         IDC_DISABLEDLIST, 10, 190, 180, 70, WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY
+    LTEXT           "After disabling or enabling a device, the connected joysticks won't be updated here until you restart this applet.", IDC_STATIC, 10, 270, 200, 25
 }
 
-IDD_TEST DIALOG 0, 0, 320, 220
+IDD_TEST DIALOG 0, 0, 320, 300
 STYLE WS_CAPTION | WS_CHILD | WS_DISABLED
 CAPTION "Test Joystick"
 FONT 8, "Ms Shell Dlg"
@@ -58,7 +60,7 @@ FONT 8, "Ms Shell Dlg"
     GROUPBOX        "", IDC_TESTGROUPPOV, 246, 30, 60, 60
 }
 
-IDD_FORCEFEEDBACK DIALOG 0, 0, 320, 220
+IDD_FORCEFEEDBACK DIALOG 0, 0, 320, 300
 STYLE WS_CAPTION | WS_CHILD | WS_DISABLED
 CAPTION "Test Force Feedback"
 FONT 8, "Ms Shell Dlg"
diff --git a/dlls/joy.cpl/main.c b/dlls/joy.cpl/main.c
index dbe84963c5d..91280f2c2c5 100644
--- a/dlls/joy.cpl/main.c
+++ b/dlls/joy.cpl/main.c
@@ -63,6 +63,15 @@ BOOL WINAPI DllMain(HINSTANCE hdll, DWORD reason, LPVOID reserved)
 static BOOL CALLBACK ff_effects_callback(const DIEFFECTINFOW *pdei, void *pvRef);
 static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *context)
 {
+    DIPROPGUIDANDPATH prop_guid_path =
+    {
+        .diph =
+        {
+            .dwSize = sizeof(DIPROPGUIDANDPATH),
+            .dwHeaderSize = sizeof(DIPROPHEADER),
+            .dwHow = DIPH_DEVICE,
+        },
+    };
     struct JoystickData *data = context;
     struct Joystick *joystick;
     DIPROPRANGE proprange;
@@ -90,6 +99,9 @@ static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *cont
     joystick->forcefeedback = caps.dwFlags & DIDC_FORCEFEEDBACK;
     joystick->num_effects = 0;
 
+    IDirectInputDevice8_GetProperty(joystick->device, DIPROP_GUIDANDPATH, &prop_guid_path.diph);
+    joystick->is_xinput = wcsstr(prop_guid_path.wszPath, L"&IG_") != NULL;
+
     if (joystick->forcefeedback) data->num_ff++;
 
     /* Set axis range to ease the GUI visualization */
@@ -233,9 +245,13 @@ static void refresh_joystick_list(HWND hwnd, struct JoystickData *data)
 
     SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_RESETCONTENT, 0, 0);
     SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_RESETCONTENT, 0, 0);
+    SendDlgItemMessageW(hwnd, IDC_XINPUTLIST, 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);
+    {
+        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);
+    }
 
     /* Search for disabled joysticks */
     get_app_key(&hkey, &appkey);
@@ -262,7 +278,10 @@ static void refresh_joystick_list(HWND hwnd, struct JoystickData *data)
  */
 static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
 {
+    WCHAR instance_name[MAX_PATH] = {0};
     static struct JoystickData *data;
+    int sel;
+
     TRACE("(%p, 0x%08x/%d, 0x%lx)\n", hwnd, msg, msg, lparam);
     switch (msg)
     {
@@ -287,11 +306,14 @@ static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
             {
                 case IDC_BUTTONDISABLE:
                 {
-                    int sel = SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_GETCURSEL, 0, 0);
+                    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);
 
-                    if (sel >= 0)
+                    if (instance_name[0])
                     {
-                        enable_joystick(data->joysticks[sel].instance.tszInstanceName, FALSE);
+                        enable_joystick(instance_name, FALSE);
                         refresh_joystick_list(hwnd, data);
                     }
                 }
@@ -299,24 +321,34 @@ static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
 
                 case IDC_BUTTONENABLE:
                 {
-                    int sel = SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_GETCURSEL, 0, 0);
+                    if ((sel = SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_GETCURSEL, 0, 0)) >= 0)
+                        SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_GETTEXT, sel, (LPARAM)instance_name);
 
-                    if (sel >= 0)
+                    if (instance_name[0])
                     {
-                        WCHAR text[MAX_PATH];
-                        SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_GETTEXT, sel, (LPARAM) text);
-                        enable_joystick(text, TRUE);
+                        enable_joystick(instance_name, TRUE);
                         refresh_joystick_list(hwnd, data);
                     }
                 }
                 break;
 
                 case IDC_JOYSTICKLIST:
+                    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);
+                break;
+
+                case IDC_XINPUTLIST:
+                    SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_SETCURSEL, -1, 0);
+                    SendDlgItemMessageW(hwnd, IDC_DISABLEDLIST, LB_SETCURSEL, -1, 0);
                     EnableWindow(GetDlgItem(hwnd, IDC_BUTTONENABLE), FALSE);
                     EnableWindow(GetDlgItem(hwnd, IDC_BUTTONDISABLE), TRUE);
                 break;
 
                 case IDC_DISABLEDLIST:
+                    SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_SETCURSEL, -1, 0);
+                    SendDlgItemMessageW(hwnd, IDC_XINPUTLIST, LB_SETCURSEL, -1, 0);
                     EnableWindow(GetDlgItem(hwnd, IDC_BUTTONENABLE), TRUE);
                     EnableWindow(GetDlgItem(hwnd, IDC_BUTTONDISABLE), FALSE);
                 break;
-- 
2.33.0




More information about the wine-devel mailing list