src/joystick/darwin/SDL_sysjoystick.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 31 Aug 2014 11:21:10 -0400
changeset 9120 b186c0df3c18
parent 8986 1c81316ac642
child 9370 795d4866e4db
permissions -rw-r--r--
Mac: Don't add the same joystick twice if IOKit reports a duplicate device. Fixes Bugzilla #2704.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     7
  arising from the use of this software.
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    11
  freely, subject to the following restrictions:
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7947
diff changeset
    21
#include "../../SDL_internal.h"
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
1635
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1621
diff changeset
    23
#ifdef SDL_JOYSTICK_IOKIT
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1621
diff changeset
    24
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include <IOKit/hid/IOHIDLib.h>
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2295
diff changeset
    27
/* For force feedback testing. */
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2295
diff changeset
    28
#include <ForceFeedback/ForceFeedback.h>
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2295
diff changeset
    29
#include <ForceFeedback/ForceFeedbackConstants.h>
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2295
diff changeset
    30
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
#include "SDL_joystick.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    32
#include "../SDL_sysjoystick.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    33
#include "../SDL_joystick_c.h"
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2295
diff changeset
    34
#include "SDL_sysjoystick_c.h"
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    35
#include "SDL_events.h"
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
    36
#include "../../haptic/darwin/SDL_syshaptic_c.h"    /* For haptic hot plugging */
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    37
#if !SDL_EVENTS_DISABLED
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    38
#include "../../events/SDL_events_c.h"
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    39
#endif
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
8739
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
    41
#define SDL_JOYSTICK_RUNLOOP_MODE CFSTR("SDLJoystick")
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
    42
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    43
/* The base object of the HID Manager API */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    44
static IOHIDManagerRef hidman = NULL;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
/* Linked list of all available devices */
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
static recDevice *gpDeviceList = NULL;
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    48
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    49
/* if SDL_TRUE then a device was added since the last update call */
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
    50
static SDL_bool s_bDeviceAdded = SDL_FALSE;
7086
141ffce8bb59 - make sure to send a joy removed event even if the joystick wasn't opened under OSX
VALVE\alfred@alfredlinux.valvesoftware.com
parents: 7037
diff changeset
    51
static SDL_bool s_bDeviceRemoved = SDL_FALSE;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    53
/* static incrementing counter for new joystick devices seen on the system. Devices should start with index 0 */
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    54
static int s_joystick_instance_id = -1;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    56
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
    57
static void
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    58
FreeElementList(recElement *pElement)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
{
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    60
    while (pElement) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    61
        recElement *pElementNext = pElement->pNext;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    62
        SDL_free(pElement);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    63
        pElement = pElementNext;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    64
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    67
static recDevice *
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    68
FreeDevice(recDevice *removeDevice)
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    69
{
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    70
    recDevice *pDeviceNext = NULL;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    71
    if (removeDevice) {
8739
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
    72
        if (removeDevice->deviceRef) {
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
    73
            IOHIDDeviceUnscheduleFromRunLoop(removeDevice->deviceRef, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
    74
            removeDevice->deviceRef = NULL;
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
    75
        }
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
    76
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    77
        /* save next device prior to disposing of this device */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    78
        pDeviceNext = removeDevice->pNext;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    80
        if ( gpDeviceList == removeDevice ) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    81
            gpDeviceList = pDeviceNext;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    82
        } else {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    83
            recDevice *device = gpDeviceList;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    84
            while (device->pNext != removeDevice) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    85
                device = device->pNext;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    86
            }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    87
            device->pNext = pDeviceNext;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    88
        }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    89
        removeDevice->pNext = NULL;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    90
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    91
        /* free element lists */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    92
        FreeElementList(removeDevice->firstAxis);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    93
        FreeElementList(removeDevice->firstButton);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    94
        FreeElementList(removeDevice->firstHat);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    95
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    96
        SDL_free(removeDevice);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    97
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    98
    return pDeviceNext;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    99
}
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   101
static SInt32
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   102
GetHIDElementState(recDevice *pDevice, recElement *pElement)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
{
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   104
    SInt32 value = 0;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   106
    if (pDevice && pElement) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   107
        IOHIDValueRef valueRef;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   108
        if (IOHIDDeviceGetValue(pDevice->deviceRef, pElement->elementRef, &valueRef) == kIOReturnSuccess) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   109
            value = (SInt32) IOHIDValueGetIntegerValue(valueRef);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   110
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   111
            /* record min and max for auto calibration */
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   112
            if (value < pElement->minReport) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   113
                pElement->minReport = value;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   114
            }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   115
            if (value > pElement->maxReport) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   116
                pElement->maxReport = value;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   117
            }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   118
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   119
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   120
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   121
    return value;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   124
static SInt32
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   125
GetHIDScaledCalibratedState(recDevice * pDevice, recElement * pElement, SInt32 min, SInt32 max)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
{
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   127
    const float deviceScale = max - min;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   128
    const float readScale = pElement->maxReport - pElement->minReport;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   129
    const SInt32 value = GetHIDElementState(pDevice, pElement);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   130
    if (readScale == 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   131
        return value;           /* no scaling at all */
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   132
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   133
    return ((value - pElement->minReport) * deviceScale / readScale) + min;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
858
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   136
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   137
static void
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   138
JoystickDeviceWasRemovedCallback(void *ctx, IOReturn result, void *sender)
858
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   139
{
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   140
    recDevice *device = (recDevice *) ctx;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   141
    device->removed = 1;
8858
a13c7a84c57f - fixed crash if you removed a device twice, the deviceRef is invalid if removed from the removed device callback (added in http://hg.libsdl.org/SDL/rev/153077041e4b ).
Alfred Reynolds <alfred@valvesoftware.com>
parents: 8739
diff changeset
   142
    device->deviceRef = NULL; // deviceRef was invalidated due to the remove
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   143
#if SDL_HAPTIC_IOKIT
8176
9efac2fd6ed6 Cleanup some vi footer comments, rename new PRIVATE_* funcs to MacHaptic_*.
Ryan C. Gordon <icculus@icculus.org>
parents: 8173
diff changeset
   144
    MacHaptic_MaybeRemoveDevice(device->ffservice);
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   145
#endif
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   146
    s_bDeviceRemoved = SDL_TRUE;
858
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   147
}
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   148
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   149
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   150
static void AddHIDElement(const void *value, void *parameter);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   151
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   152
/* Call AddHIDElement() on all elements in an array of IOHIDElementRefs */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   153
static void
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   154
AddHIDElements(CFArrayRef array, recDevice *pDevice)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
{
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   156
    const CFRange range = { 0, CFArrayGetCount(array) };
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   157
    CFArrayApplyFunction(array, range, AddHIDElement, pDevice);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   158
}
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   160
static SDL_bool
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   161
ElementAlreadyAdded(const IOHIDElementCookie cookie, const recElement *listitem) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   162
    while (listitem) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   163
        if (listitem->cookie == cookie) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   164
            return SDL_TRUE;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   165
        }
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   166
        listitem = listitem->pNext;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   167
    }
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   168
    return SDL_FALSE;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   169
}
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   170
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   171
/* See if we care about this HID element, and if so, note it in our recDevice. */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   172
static void
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   173
AddHIDElement(const void *value, void *parameter)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
{
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   175
    recDevice *pDevice = (recDevice *) parameter;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   176
    IOHIDElementRef refElement = (IOHIDElementRef) value;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   177
    const CFTypeID elementTypeID = refElement ? CFGetTypeID(refElement) : 0;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   179
    if (refElement && (elementTypeID == IOHIDElementGetTypeID())) {
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   180
        const IOHIDElementCookie cookie = IOHIDElementGetCookie(refElement);
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   181
        const uint32_t usagePage = IOHIDElementGetUsagePage(refElement);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   182
        const uint32_t usage = IOHIDElementGetUsage(refElement);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   183
        recElement *element = NULL;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   184
        recElement **headElement = NULL;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   185
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   186
        /* look at types of interest */
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   187
        switch (IOHIDElementGetType(refElement)) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   188
            case kIOHIDElementTypeInput_Misc:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   189
            case kIOHIDElementTypeInput_Button:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   190
            case kIOHIDElementTypeInput_Axis: {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   191
                switch (usagePage) {    /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   192
                    case kHIDPage_GenericDesktop:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   193
                        switch (usage) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   194
                            case kHIDUsage_GD_X:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   195
                            case kHIDUsage_GD_Y:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   196
                            case kHIDUsage_GD_Z:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   197
                            case kHIDUsage_GD_Rx:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   198
                            case kHIDUsage_GD_Ry:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   199
                            case kHIDUsage_GD_Rz:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   200
                            case kHIDUsage_GD_Slider:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   201
                            case kHIDUsage_GD_Dial:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   202
                            case kHIDUsage_GD_Wheel:
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   203
                                if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   204
                                    element = (recElement *) SDL_calloc(1, sizeof (recElement));
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   205
                                    if (element) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   206
                                        pDevice->axes++;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   207
                                        headElement = &(pDevice->firstAxis);
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   208
                                    }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   209
                                }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   210
                                break;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   211
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   212
                            case kHIDUsage_GD_Hatswitch:
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   213
                                if (!ElementAlreadyAdded(cookie, pDevice->firstHat)) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   214
                                    element = (recElement *) SDL_calloc(1, sizeof (recElement));
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   215
                                    if (element) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   216
                                        pDevice->hats++;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   217
                                        headElement = &(pDevice->firstHat);
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   218
                                    }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   219
                                }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   220
                                break;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   221
                        }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   222
                        break;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   223
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   224
                    case kHIDPage_Simulation:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   225
                        switch (usage) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   226
                            case kHIDUsage_Sim_Rudder:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   227
                            case kHIDUsage_Sim_Throttle:
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   228
                                if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   229
                                    element = (recElement *) SDL_calloc(1, sizeof (recElement));
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   230
                                    if (element) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   231
                                        pDevice->axes++;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   232
                                        headElement = &(pDevice->firstAxis);
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   233
                                    }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   234
                                }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   235
                                break;
7626
36e493277423 Fixed bug 2024 - Update OSX Joystick code to fully support Saitek p2500 gamepad
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   236
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   237
                            default:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   238
                                break;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   239
                        }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   240
                        break;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   241
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   242
                    case kHIDPage_Button:
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   243
                        if (!ElementAlreadyAdded(cookie, pDevice->firstButton)) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   244
                            element = (recElement *) SDL_calloc(1, sizeof (recElement));
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   245
                            if (element) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   246
                                pDevice->buttons++;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   247
                                headElement = &(pDevice->firstButton);
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   248
                            }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   249
                        }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   250
                        break;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   251
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   252
                    default:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   253
                        break;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   254
                }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   255
            }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   256
            break;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   258
            case kIOHIDElementTypeCollection: {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   259
                CFArrayRef array = IOHIDElementGetChildren(refElement);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   260
                if (array) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   261
                    AddHIDElements(array, pDevice);
7026
bc089599bd82 Added GUIDs for Bluetooth devices, using the same algorithm as the Linux code.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   262
                }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   263
            }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   264
            break;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   266
            default:
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   267
                break;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   268
        }
7026
bc089599bd82 Added GUIDs for Bluetooth devices, using the same algorithm as the Linux code.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   269
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   270
        if (element && headElement) {       /* add to list */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   271
            recElement *elementPrevious = NULL;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   272
            recElement *elementCurrent = *headElement;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   273
            while (elementCurrent && usage >= elementCurrent->usage) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   274
                elementPrevious = elementCurrent;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   275
                elementCurrent = elementCurrent->pNext;
7026
bc089599bd82 Added GUIDs for Bluetooth devices, using the same algorithm as the Linux code.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   276
            }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   277
            if (elementPrevious) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   278
                elementPrevious->pNext = element;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   279
            } else {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   280
                *headElement = element;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   281
            }
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   282
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   283
            element->elementRef = refElement;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   284
            element->usagePage = usagePage;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   285
            element->usage = usage;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   286
            element->pNext = elementCurrent;
7026
bc089599bd82 Added GUIDs for Bluetooth devices, using the same algorithm as the Linux code.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   287
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   288
            element->minReport = element->min = (SInt32) IOHIDElementGetLogicalMin(refElement);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   289
            element->maxReport = element->max = (SInt32) IOHIDElementGetLogicalMax(refElement);
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   290
            element->cookie = IOHIDElementGetCookie(refElement);
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   292
            pDevice->elements++;
7026
bc089599bd82 Added GUIDs for Bluetooth devices, using the same algorithm as the Linux code.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   293
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   294
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   297
static SDL_bool
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   298
GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
{
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   300
    Uint32 *guid32 = NULL;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   301
    CFTypeRef refCF = NULL;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   302
    CFArrayRef array = NULL;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   303
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   304
    /* get usage page and usage */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   305
    refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDPrimaryUsagePageKey));
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   306
    if (refCF) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   307
        CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->usagePage);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   308
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   309
    if (pDevice->usagePage != kHIDPage_GenericDesktop) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   310
        return SDL_FALSE; /* Filter device list to non-keyboard/mouse stuff */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   311
    }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   312
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   313
    refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDPrimaryUsageKey));
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   314
    if (refCF) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   315
        CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->usage);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   316
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   318
    if ((pDevice->usage != kHIDUsage_GD_Joystick &&
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   319
         pDevice->usage != kHIDUsage_GD_GamePad &&
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   320
         pDevice->usage != kHIDUsage_GD_MultiAxisController)) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   321
        return SDL_FALSE; /* Filter device list to non-keyboard/mouse stuff */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   322
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   323
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   324
    pDevice->deviceRef = hidDevice;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   326
    /* get device name */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   327
    refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductKey));
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   328
    if (!refCF) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   329
        /* Maybe we can't get "AwesomeJoystick2000", but we can get "Logitech"? */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   330
        refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   331
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   332
    if ((!refCF) || (!CFStringGetCString(refCF, pDevice->product, sizeof (pDevice->product), kCFStringEncodingUTF8))) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   333
        SDL_strlcpy(pDevice->product, "Unidentified joystick", sizeof (pDevice->product));
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   334
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   335
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   336
    refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVendorIDKey));
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   337
    if (refCF) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   338
        CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->guid.data[0]);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   339
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   340
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   341
    refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductIDKey));
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   342
    if (refCF) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   343
        CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->guid.data[8]);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   344
    }
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2295
diff changeset
   345
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   346
    /* Check to make sure we have a vendor and product ID
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   347
       If we don't, use the same algorithm as the Linux code for Bluetooth devices */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   348
    guid32 = (Uint32*)pDevice->guid.data;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   349
    if (!guid32[0] && !guid32[1]) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   350
        /* If we don't have a vendor and product ID this is probably a Bluetooth device */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   351
        const Uint16 BUS_BLUETOOTH = 0x05;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   352
        Uint16 *guid16 = (Uint16 *)guid32;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   353
        *guid16++ = BUS_BLUETOOTH;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   354
        *guid16++ = 0;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   355
        SDL_strlcpy((char*)guid16, pDevice->product, sizeof(pDevice->guid.data) - 4);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   356
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   357
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   358
    array = IOHIDDeviceCopyMatchingElements(hidDevice, NULL, kIOHIDOptionsTypeNone);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   359
    if (array) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   360
        AddHIDElements(array, pDevice);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   361
        CFRelease(array);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   362
    }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   363
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   364
    return SDL_TRUE;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   365
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   366
9120
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   367
static SDL_bool
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   368
JoystickAlreadyKnown(IOHIDDeviceRef ioHIDDeviceObject)
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   369
{
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   370
    recDevice *i;
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   371
    for (i = gpDeviceList; i != NULL; i = i->pNext) {
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   372
        if (i->deviceRef == ioHIDDeviceObject) {
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   373
            return SDL_TRUE;
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   374
        }
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   375
    }
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   376
    return SDL_FALSE;
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   377
}
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   378
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   379
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   380
static void
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   381
JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject)
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   382
{
9120
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   383
    recDevice *device;
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   384
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   385
    if (res != kIOReturnSuccess) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   386
        return;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   387
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   388
9120
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   389
    if (JoystickAlreadyKnown(ioHIDDeviceObject)) {
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   390
        return;  /* IOKit sent us a duplicate. */
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   391
    }
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   392
b186c0df3c18 Mac: Don't add the same joystick twice if IOKit reports a duplicate device.
Ryan C. Gordon <icculus@icculus.org>
parents: 8986
diff changeset
   393
    device = (recDevice *) SDL_calloc(1, sizeof(recDevice));
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   394
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   395
    if (!device) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   396
        SDL_OutOfMemory();
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   397
        return;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   398
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   399
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   400
    if (!GetDeviceInfo(ioHIDDeviceObject, device)) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   401
        SDL_free(device);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   402
        return;   /* not a device we care about, probably. */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   403
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   404
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   405
    /* Get notified when this device is disconnected. */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   406
    IOHIDDeviceRegisterRemovalCallback(ioHIDDeviceObject, JoystickDeviceWasRemovedCallback, device);
8739
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
   407
    IOHIDDeviceScheduleWithRunLoop(ioHIDDeviceObject, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   408
7791
d9f0067a5421 Only allocate a joystick instance ID once we know it's a joystick.
Sam Lantinga <slouken@libsdl.org>
parents: 7681
diff changeset
   409
    /* Allocate an instance ID for this device */
d9f0067a5421 Only allocate a joystick instance ID once we know it's a joystick.
Sam Lantinga <slouken@libsdl.org>
parents: 7681
diff changeset
   410
    device->instance_id = ++s_joystick_instance_id;
d9f0067a5421 Only allocate a joystick instance ID once we know it's a joystick.
Sam Lantinga <slouken@libsdl.org>
parents: 7681
diff changeset
   411
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   412
    /* We have to do some storage of the io_service_t for SDL_HapticOpenFromJoystick */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   413
    if (IOHIDDeviceGetService != NULL) {  /* weak reference: available in 10.6 and later. */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   414
        const io_service_t ioservice = IOHIDDeviceGetService(ioHIDDeviceObject);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   415
        if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK)) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   416
            device->ffservice = ioservice;
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   417
#if SDL_HAPTIC_IOKIT
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   418
            MacHaptic_MaybeAddDevice(ioservice);
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   419
#endif
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   420
        }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   421
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   422
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   423
    device->send_open_event = 1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   424
    s_bDeviceAdded = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   425
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   426
    /* Add device to the end of the list */
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8860
diff changeset
   427
    if ( !gpDeviceList ) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   428
        gpDeviceList = device;
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8860
diff changeset
   429
    } else {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   430
        recDevice *curdevice;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   431
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   432
        curdevice = gpDeviceList;
8986
1c81316ac642 Fixed bug 2631 - Mac: minor code cleanup
Sam Lantinga <slouken@libsdl.org>
parents: 8860
diff changeset
   433
        while ( curdevice->pNext ) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   434
            curdevice = curdevice->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   435
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   436
        curdevice->pNext = device;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   437
    }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   438
}
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   439
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   440
static SDL_bool
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   441
ConfigHIDManager(CFArrayRef matchingArray)
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   442
{
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   443
    CFRunLoopRef runloop = CFRunLoopGetCurrent();
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   444
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   445
    if (IOHIDManagerOpen(hidman, kIOHIDOptionsTypeNone) != kIOReturnSuccess) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   446
        return SDL_FALSE;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   447
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   448
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   449
    IOHIDManagerRegisterDeviceMatchingCallback(hidman, JoystickDeviceWasAddedCallback, NULL);
8739
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
   450
    IOHIDManagerScheduleWithRunLoop(hidman, runloop, SDL_JOYSTICK_RUNLOOP_MODE);
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   451
    IOHIDManagerSetDeviceMatchingMultiple(hidman, matchingArray);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   452
8739
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
   453
    while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   454
        /* no-op. Callback fires once per existing device. */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   455
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   456
8739
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
   457
    /* future hotplug events will come through SDL_JOYSTICK_RUNLOOP_MODE now. */
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   458
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   459
    return SDL_TRUE;  /* good to go. */
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   460
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   461
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   462
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   463
static CFDictionaryRef
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   464
CreateHIDDeviceMatchDictionary(const UInt32 page, const UInt32 usage, int *okay)
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   465
{
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   466
    CFDictionaryRef retval = NULL;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   467
    CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   468
    CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   469
    const void *keys[2] = { (void *) CFSTR(kIOHIDDeviceUsagePageKey), (void *) CFSTR(kIOHIDDeviceUsageKey) };
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   470
    const void *vals[2] = { (void *) pageNumRef, (void *) usageNumRef };
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   471
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   472
    if (pageNumRef && usageNumRef) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   473
        retval = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   474
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   475
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   476
    if (pageNumRef) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   477
        CFRelease(pageNumRef);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   478
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   479
    if (usageNumRef) {
8245
2c63c27c4d1d Free the correct variable.
Ryan C. Gordon <icculus@icculus.org>
parents: 8242
diff changeset
   480
        CFRelease(usageNumRef);
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   481
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   482
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   483
    if (!retval) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   484
        *okay = 0;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   485
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   486
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   487
    return retval;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   488
}
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   489
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   490
static SDL_bool
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   491
CreateHIDManager(void)
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   492
{
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   493
    SDL_bool retval = SDL_FALSE;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   494
    int okay = 1;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   495
    const void *vals[] = {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   496
        (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick, &okay),
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   497
        (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad, &okay),
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   498
        (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController, &okay),
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   499
    };
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   500
    const size_t numElements = SDL_arraysize(vals);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   501
    CFArrayRef array = okay ? CFArrayCreate(kCFAllocatorDefault, vals, numElements, &kCFTypeArrayCallBacks) : NULL;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   502
    size_t i;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   503
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   504
    for (i = 0; i < numElements; i++) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   505
        if (vals[i]) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   506
            CFRelease((CFTypeRef) vals[i]);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   507
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   508
    }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   509
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   510
    if (array) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   511
        hidman = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   512
        if (hidman != NULL) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   513
            retval = ConfigHIDManager(array);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   514
        }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   515
        CFRelease(array);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   516
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   517
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   518
    return retval;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   519
}
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   520
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   521
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   522
/* Function to scan the system for joysticks.
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   523
 * Joystick 0 should be the system default joystick.
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   524
 * This function should return the number of available joysticks, or -1
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   525
 * on an unrecoverable fatal error.
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   526
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   527
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   528
SDL_SYS_JoystickInit(void)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   529
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   530
    if (gpDeviceList) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7026
diff changeset
   531
        return SDL_SetError("Joystick: Device list already inited.");
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   532
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   533
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   534
    if (!CreateHIDManager()) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   535
        return SDL_SetError("Joystick: Couldn't initialize HID Manager");
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   536
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   537
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   538
    return SDL_SYS_NumJoysticks();
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   539
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   540
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   541
/* Function to return the number of joystick devices plugged in right now */
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   542
int
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   543
SDL_SYS_NumJoysticks()
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   544
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   545
    recDevice *device = gpDeviceList;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   546
    int nJoySticks = 0;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   547
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   548
    while (device) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   549
        if (!device->removed) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   550
            nJoySticks++;
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   551
        }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   552
        device = device->pNext;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   553
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   554
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   555
    return nJoySticks;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   556
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   557
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   558
/* Function to cause any queued joystick insertions to be processed
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   559
 */
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   560
void
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   561
SDL_SYS_JoystickDetect()
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   562
{
8739
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
   563
    while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
   564
        /* no-op. Pending callbacks will fire in CFRunLoopRunInMode(). */
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
   565
    }
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
   566
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   567
    if (s_bDeviceAdded || s_bDeviceRemoved) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   568
        recDevice *device = gpDeviceList;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   569
        s_bDeviceAdded = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   570
        s_bDeviceRemoved = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   571
        int device_index = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   572
        /* send notifications */
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   573
        while (device) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   574
            if (device->send_open_event) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   575
                device->send_open_event = 0;
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   576
/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceAdded()? */
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   577
#if !SDL_EVENTS_DISABLED
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   578
                SDL_Event event;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   579
                event.type = SDL_JOYDEVICEADDED;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   580
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   581
                if (SDL_GetEventState(event.type) == SDL_ENABLE) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   582
                    event.jdevice.which = device_index;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   583
                    if ((SDL_EventOK == NULL)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   584
                        || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   585
                        SDL_PushEvent(&event);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   586
                    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   587
                }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   588
#endif /* !SDL_EVENTS_DISABLED */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   589
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   590
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   591
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   592
            if (device->removed) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   593
                const int instance_id = device->instance_id;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   594
                device = FreeDevice(device);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   595
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   596
/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceRemoved()? */
7086
141ffce8bb59 - make sure to send a joy removed event even if the joystick wasn't opened under OSX
VALVE\alfred@alfredlinux.valvesoftware.com
parents: 7037
diff changeset
   597
#if !SDL_EVENTS_DISABLED
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   598
                SDL_Event event;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   599
                event.type = SDL_JOYDEVICEREMOVED;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   600
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   601
                if (SDL_GetEventState(event.type) == SDL_ENABLE) {
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   602
                    event.jdevice.which = instance_id;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   603
                    if ((SDL_EventOK == NULL)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   604
                        || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   605
                        SDL_PushEvent(&event);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   606
                    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   607
                }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   608
#endif /* !SDL_EVENTS_DISABLED */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   609
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   610
            } else {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   611
                device = device->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   612
                device_index++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   613
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   614
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   615
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   616
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   617
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   618
/* Function to get the device-dependent name of a joystick */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   619
const char *
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   620
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   621
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   622
    recDevice *device = gpDeviceList;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   623
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   624
    while (device_index-- > 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   625
        device = device->pNext;
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   626
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   627
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   628
    return device->product;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   629
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   630
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   631
/* Function to return the instance id of the joystick at device_index
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   632
 */
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   633
SDL_JoystickID
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   634
SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   635
{
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   636
    recDevice *device = gpDeviceList;
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   637
    int index;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   638
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   639
    for (index = device_index; index > 0; index--) {
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   640
        device = device->pNext;
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   641
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   642
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   643
    return device->instance_id;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   644
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   645
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   646
/* Function to open a joystick for use.
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   647
 * The joystick to open is specified by the index field of the joystick.
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   648
 * This should fill the nbuttons and naxes fields of the joystick structure.
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   649
 * It returns 0, or -1 if there is an error.
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   650
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   651
int
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   652
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   653
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   654
    recDevice *device = gpDeviceList;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   655
    int index;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   656
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   657
    for (index = device_index; index > 0; index--) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   658
        device = device->pNext;
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   659
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   660
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   661
    joystick->instance_id = device->instance_id;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   662
    joystick->hwdata = device;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   663
    joystick->name = device->product;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   664
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   665
    joystick->naxes = device->axes;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   666
    joystick->nhats = device->hats;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   667
    joystick->nballs = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   668
    joystick->nbuttons = device->buttons;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   669
    return 0;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   670
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   671
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   672
/* Function to query if the joystick is currently attached
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   673
 *   It returns 1 if attached, 0 otherwise.
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   674
 */
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   675
SDL_bool
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   676
SDL_SYS_JoystickAttached(SDL_Joystick * joystick)
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   677
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   678
    recDevice *device = gpDeviceList;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   679
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   680
    while (device) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   681
        if (joystick->instance_id == device->instance_id) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   682
            return SDL_TRUE;
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   683
        }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   684
        device = device->pNext;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   685
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   686
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   687
    return SDL_FALSE;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   688
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   689
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   690
/* Function to update the state of a joystick - called as a device poll.
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   691
 * This function shouldn't update the joystick structure directly,
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   692
 * but instead should call SDL_PrivateJoystick*() to deliver events
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   693
 * and update joystick device state.
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   694
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   695
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   696
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   697
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   698
    recDevice *device = joystick->hwdata;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   699
    recElement *element;
2287
15a242fca6c4 Fixed bug #478
Sam Lantinga <slouken@libsdl.org>
parents: 2120
diff changeset
   700
    SInt32 value, range;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   701
    int i;
858
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   702
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   703
    if (!device) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   704
        return;
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   705
    }
858
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   706
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   707
    if (device->removed) {      /* device was unplugged; ignore it. */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   708
        joystick->closed = 1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   709
        joystick->uncentered = 1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   710
        joystick->hwdata = NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   711
        return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   712
    }
858
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   713
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   714
    element = device->firstAxis;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   715
    i = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   716
    while (element) {
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   717
        value = GetHIDScaledCalibratedState(device, element, -32768, 32767);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   718
        if (value != joystick->axes[i]) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   719
            SDL_PrivateJoystickAxis(joystick, i, value);
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   720
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   721
        element = element->pNext;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   722
        ++i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   723
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   724
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   725
    element = device->firstButton;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   726
    i = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   727
    while (element) {
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   728
        value = GetHIDElementState(device, element);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   729
        if (value > 1) {          /* handle pressure-sensitive buttons */
629
3fa401bb4bb5 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 623
diff changeset
   730
            value = 1;
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   731
        }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   732
        if (value != joystick->buttons[i]) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   733
            SDL_PrivateJoystickButton(joystick, i, value);
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   734
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   735
        element = element->pNext;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   736
        ++i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   737
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   738
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   739
    element = device->firstHat;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   740
    i = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   741
    while (element) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   742
        Uint8 pos = 0;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   743
2287
15a242fca6c4 Fixed bug #478
Sam Lantinga <slouken@libsdl.org>
parents: 2120
diff changeset
   744
        range = (element->max - element->min + 1);
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   745
        value = GetHIDElementState(device, element) - element->min;
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   746
        if (range == 4) {         /* 4 position hatswitch - scale up value */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   747
            value *= 2;
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   748
        } else if (range != 8) {    /* Neither a 4 nor 8 positions - fall back to default position (centered) */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   749
            value = -1;
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   750
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   751
        switch (value) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   752
        case 0:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   753
            pos = SDL_HAT_UP;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   754
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   755
        case 1:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   756
            pos = SDL_HAT_RIGHTUP;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   757
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   758
        case 2:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   759
            pos = SDL_HAT_RIGHT;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   760
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   761
        case 3:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   762
            pos = SDL_HAT_RIGHTDOWN;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   763
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   764
        case 4:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   765
            pos = SDL_HAT_DOWN;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   766
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   767
        case 5:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   768
            pos = SDL_HAT_LEFTDOWN;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   769
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   770
        case 6:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   771
            pos = SDL_HAT_LEFT;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   772
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   773
        case 7:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   774
            pos = SDL_HAT_LEFTUP;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   775
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   776
        default:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   777
            /* Every other value is mapped to center. We do that because some
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   778
             * joysticks use 8 and some 15 for this value, and apparently
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   779
             * there are even more variants out there - so we try to be generous.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   780
             */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   781
            pos = SDL_HAT_CENTERED;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   782
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   783
        }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   784
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   785
        if (pos != joystick->hats[i]) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   786
            SDL_PrivateJoystickHat(joystick, i, pos);
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   787
        }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   788
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   789
        element = element->pNext;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   790
        ++i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   791
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   792
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   793
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   794
/* Function to close a joystick after use */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   795
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   796
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   797
{
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   798
    joystick->closed = 1;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   799
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   800
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   801
/* Function to perform any system-specific joystick related cleanup */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   802
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   803
SDL_SYS_JoystickQuit(void)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   804
{
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   805
    while (FreeDevice(gpDeviceList)) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   806
        /* spin */
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   807
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   808
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   809
    if (hidman) {
8739
153077041e4b Mac OS X: Look for joystick hotplug in its own CFRunLoop.
Ryan C. Gordon <icculus@icculus.org>
parents: 8245
diff changeset
   810
        IOHIDManagerUnscheduleFromRunLoop(hidman, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   811
        IOHIDManagerClose(hidman, kIOHIDOptionsTypeNone);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   812
        CFRelease(hidman);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   813
        hidman = NULL;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   814
    }
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   815
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   816
    s_bDeviceAdded = s_bDeviceRemoved = SDL_FALSE;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   817
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   818
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   819
6738
b408d5a406a3 Changes from Alfred:
Sam Lantinga <slouken@libsdl.org>
parents: 6718
diff changeset
   820
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   821
{
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   822
    recDevice *device = gpDeviceList;
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   823
    int index;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   824
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   825
    for (index = device_index; index > 0; index--) {
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   826
        device = device->pNext;
8230
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   827
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   828
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   829
    return device->guid;
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   830
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   831
6738
b408d5a406a3 Changes from Alfred:
Sam Lantinga <slouken@libsdl.org>
parents: 6718
diff changeset
   832
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   833
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   834
    return joystick->hwdata->guid;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   835
}
1635
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1621
diff changeset
   836
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1621
diff changeset
   837
#endif /* SDL_JOYSTICK_IOKIT */
7026
bc089599bd82 Added GUIDs for Bluetooth devices, using the same algorithm as the Linux code.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   838
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
   839
/* vi: set ts=4 sw=4 expandtab: */