From 4a714b09cc9c355536450bd0196f10cb6a33e651 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 --- src/joystick/darwin/SDL_sysjoystick.c | 24 +++++++++++++----------- src/joystick/darwin/SDL_sysjoystick_c.h | 1 + 2 files changed, 14 insertions(+), 11 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; - } + recElement *elementPrevious = NULL; + recElement *elementCurrent = *headElement; + while (elementCurrent && usage >= elementCurrent->usage) { + elementPrevious = elementCurrent; + elementCurrent = elementCurrent->pNext; + } + if (elementPrevious) { elementPrevious->pNext = element; + } else { + *headElement = element; } - element->pNext = NULL; + 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