changeset 2776:caf3d5b2153f

Sort by HID usage, which makes more sense and is more cross-platform
author Sam Lantinga <slouken@libsdl.org>
date Sat, 08 Nov 2008 07:34:21 +0000
parents 6d7baec32718
children 6f260584df22
files src/joystick/darwin/SDL_sysjoystick.c src/joystick/darwin/SDL_sysjoystick_c.h
diffstat 2 files changed, 14 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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