src/joystick/darwin/SDL_sysjoystick.c
changeset 2776 caf3d5b2153f
parent 2735 204be4fc2726
child 2859 99210400e8b9
--- a/src/joystick/darwin/SDL_sysjoystick.c	Wed Oct 29 05:56:23 2008 +0000
+++ b/src/joystick/darwin/SDL_sysjoystick.c	Sat Nov 08 07:34:21 2008 +0000
@@ -331,20 +331,22 @@
     }
 
     if (element && headElement) {       /* add to list */
-        pDevice->elements++;
-        if (NULL == *headElement)
+        recElement *elementPrevious = NULL;
+        recElement *elementCurrent = *headElement;
+        while (elementCurrent && usage >= elementCurrent->usage) {
+            elementPrevious = elementCurrent;
+            elementCurrent = elementCurrent->pNext;
+        }
+        if (elementPrevious) {
+            elementPrevious->pNext = element;
+        } else {
             *headElement = element;
-        else {
-            recElement *elementPrevious, *elementCurrent;
-            elementCurrent = *headElement;
-            while (elementCurrent) {
-                elementPrevious = elementCurrent;
-                elementCurrent = elementPrevious->pNext;
-            }
-            elementPrevious->pNext = element;
         }
-        element->pNext = NULL;
+        element->usagePage = usagePage;
+        element->usage = usage;
+        element->pNext = elementCurrent;
         HIDGetElementInfo(refElement, element);
+        pDevice->elements++;
     }
 }