From eb0b9dc85dce34e8ec57b5d198d175a1ef69ec93 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 8 Nov 2008 07:34:21 +0000 Subject: [PATCH] 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 --- src/joystick/darwin/SDL_sysjoystick.c | 26 +++++++++++++------------ src/joystick/darwin/SDL_sysjoystick_c.h | 1 + 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index 5ead47779..cc1ea8d8c 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -331,20 +331,22 @@ HIDAddElement(CFTypeRef refElement, recDevice * pDevice) } 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 e78c4b689..ff3ec67af 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