[1/3] dinput: Disable linuxinput or linux joysticks based on registry key

Lucas Zawacki lfzawacki at gmail.com
Mon Aug 20 01:47:04 CDT 2012


From: Lucas Fialho Zawacki <lfzawacki at gmail.com>

In the form of "Disable Controllername"="driver"

Examples:
   Disable "Usb Controller"="js"             disable linux js driver
   Disable "OtherController"="event,js"      disable linux js and event drivers

This can help the users with bugs #26810 and #30690
---
 dlls/dinput/joystick.c            |   50 +++++++++++++++++++++++++++++++++++++
 dlls/dinput/joystick_linux.c      |    3 +++
 dlls/dinput/joystick_linuxinput.c |    8 +++---
 dlls/dinput/joystick_private.h    |    2 ++
 4 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/dlls/dinput/joystick.c b/dlls/dinput/joystick.c
index dfcaeb7..a73cb58 100644
--- a/dlls/dinput/joystick.c
+++ b/dlls/dinput/joystick.c
@@ -49,6 +49,56 @@ static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(JoystickGener
     return &This->base.IDirectInputDevice8W_iface;
 }
 
+BOOL device_disabled_registry(const char* name, const char* driver)
+{
+    static const char disable_str[] = "Disable ";
+
+    char buffer[MAX_PATH];
+    HKEY hkey, appkey;
+    BOOL do_disable = FALSE;
+    char *disable_name;
+
+    int str_size = strlen(name) + strlen(disable_str) + 1;
+    disable_name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, str_size);
+
+    if (!disable_name) return FALSE;
+
+    strcat(disable_name, disable_str);
+    strcat(disable_name, name);
+
+    get_app_key(&hkey, &appkey);
+
+    /* Look for the "Disable controllername"="drivername" key 
+       More than one driver can be specified delimited by a ','.
+
+       Examples:
+         Disable "Usb Controller"="js"             disable linux js driver
+         Disable "OtherController"="event,js"      disable linux js and event drivers
+    */
+    if (!get_config_key(hkey, appkey, disable_name, buffer, sizeof(buffer)))
+    {
+        static const char *delim = ",";
+        char *ptr;
+
+        if ((ptr = strtok(buffer, delim)) != NULL)
+            do
+            {
+                if (!strncmp(ptr, driver, sizeof(ptr)))
+                {
+                    TRACE("Disabling joystick '%s (%s)' based on registry key.\n", name, driver);
+                    do_disable = TRUE;
+                }
+            } while ((ptr = strtok(NULL, delim)) != NULL && !do_disable);
+    }
+
+    HeapFree(GetProcessHeap(), 0, disable_name);
+
+    if (appkey) RegCloseKey(appkey);
+    if (hkey)   RegCloseKey(hkey);
+
+    return do_disable;
+}
+
 /******************************************************************************
   *     SetProperty : change input device properties
   */
diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index 5afd07c..a1ad818 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -153,6 +153,9 @@ static INT find_joystick_devices(void)
         if (ioctl(fd, JSIOCGNAME(sizeof(joydev.name)), joydev.name) < 0)
             WARN("ioctl(%s,JSIOCGNAME) failed: %s\n", joydev.device, strerror(errno));
 #endif
+
+        if (device_disabled_registry(joydev.name, "js")) continue;
+
 #ifdef JSIOCGAXES
         if (ioctl(fd, JSIOCGAXES, &joydev.axis_count) < 0)
         {
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index 3cab015..54f9fdd 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -246,10 +246,12 @@ static void find_joydevs(void)
         else
             joydev.name = joydev.device;
 
-	joydev.guid = DInput_Wine_Joystick_Base_GUID;
-	joydev.guid.Data3 += have_joydevs;
+        if (device_disabled_registry(joydev.name, "event")) continue;
 
-        TRACE("Found a joystick on %s: %s (%s)\n", 
+        joydev.guid = DInput_Wine_Joystick_Base_GUID;
+        joydev.guid.Data3 += have_joydevs;
+
+        TRACE("Found a joystick on %s: %s (%s)\n",
             joydev.device, joydev.name, 
             debugstr_guid(&joydev.guid)
             );
diff --git a/dlls/dinput/joystick_private.h b/dlls/dinput/joystick_private.h
index 71d91f1..97becc7 100644
--- a/dlls/dinput/joystick_private.h
+++ b/dlls/dinput/joystick_private.h
@@ -57,6 +57,8 @@ HRESULT setup_dinput_options(JoystickGenericImpl *This, const int *default_axis_
 
 DWORD joystick_map_pov(const POINTL *p) DECLSPEC_HIDDEN;
 
+BOOL device_disabled_registry(const char* name, const char* driver) DECLSPEC_HIDDEN;
+
 HRESULT WINAPI JoystickWGenericImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
         LPDIDEVICEOBJECTINSTANCEW pdidoi, DWORD dwObj, DWORD dwHow) DECLSPEC_HIDDEN;
 
-- 
1.7.9.5




More information about the wine-patches mailing list