Sort by HID usage, which makes more sense and is more cross-platform
authorSam Lantinga <slouken@libsdl.org>
Sat, 08 Nov 2008 07:34:21 +0000
changeset 2776 caf3d5b2153f
parent 2775 6d7baec32718
child 2777 6f260584df22
Sort by HID usage, which makes more sense and is more cross-platform
src/joystick/darwin/SDL_sysjoystick.c
src/joystick/darwin/SDL_sysjoystick_c.h
--- 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++;
     }
 }
 
--- a/src/joystick/darwin/SDL_sysjoystick_c.h	Wed Oct 29 05:56:23 2008 +0000
+++ b/src/joystick/darwin/SDL_sysjoystick_c.h	Sat Nov 08 07:34:21 2008 +0000
@@ -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