Sort by HID usage, which makes more sense and is more cross-platform

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403236
diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c
index 5ead477..cc1ea8d 100644
--- a/src/joystick/darwin/SDL_sysjoystick.c
+++ b/src/joystick/darwin/SDL_sysjoystick.c
@@ -331,20 +331,22 @@
     }
 
     if (element && headElement) {       /* add to list */
-        pDevice->elements++;
-        if (NULL == *headElement)
-            *headElement = element;
-        else {
-            recElement *elementPrevious, *elementCurrent;
-            elementCurrent = *headElement;
-            while (elementCurrent) {
-                elementPrevious = elementCurrent;
-                elementCurrent = elementPrevious->pNext;
-            }
-            elementPrevious->pNext = element;
+        recElement *elementPrevious = NULL;
+        recElement *elementCurrent = *headElement;
+        while (elementCurrent && usage >= elementCurrent->usage) {
+            elementPrevious = elementCurrent;
+            elementCurrent = elementCurrent->pNext;
         }
-        element->pNext = NULL;
+        if (elementPrevious) {
+            elementPrevious->pNext = element;
+        } else {
+            *headElement = element;
+        }
+        element->usagePage = usagePage;
+        element->usage = usage;
+        element->pNext = elementCurrent;
         HIDGetElementInfo(refElement, element);
+        pDevice->elements++;
     }
 }
 
diff --git a/src/joystick/darwin/SDL_sysjoystick_c.h b/src/joystick/darwin/SDL_sysjoystick_c.h
index e78c4b6..ff3ec67 100644
--- a/src/joystick/darwin/SDL_sysjoystick_c.h
+++ b/src/joystick/darwin/SDL_sysjoystick_c.h
@@ -35,6 +35,7 @@
 struct recElement
 {
     IOHIDElementCookie cookie;  /* unique value which identifies element, will NOT change */
+    long usagePage, usage;      /* HID usage */
     long min;                   /* reported min value possible */
     long max;                   /* reported max value possible */
 #if 0