src/joystick/darwin/SDL_sysjoystick.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 23 Feb 2014 01:24:46 -0500
changeset 8245 2c63c27c4d1d
parent 8242 f6a2b1a6932b
child 8739 153077041e4b
permissions -rw-r--r--
Free the correct variable.
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
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
    41
/* 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
    42
static IOHIDManagerRef hidman = NULL;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
/* Linked list of all available devices */
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
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
    46
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
    47
/* 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
    48
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
    49
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
    50
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    51
/* 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
    52
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
    53
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
    54
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
    55
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
    56
FreeElementList(recElement *pElement)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
{
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
    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
    59
        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
    60
        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
    61
        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
    62
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
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
    65
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
    66
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
    67
{
1c185bacf915 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
    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
    69
    if (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
    70
        /* 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
    71
        pDeviceNext = removeDevice->pNext;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
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
    73
        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
    74
            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
    75
        } 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
    76
            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
    77
            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
    78
                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
    79
            }
1c185bacf915 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
            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
    81
        }
1c185bacf915 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
        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
    83
1c185bacf915 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
        /* 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
    85
        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
    86
        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
    87
        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
    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
        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
    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
    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
    92
}
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
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
    94
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
    95
GetHIDElementState(recDevice *pDevice, recElement *pElement)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
{
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
    97
    SInt32 value = 0;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
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
    99
    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
   100
        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
   101
        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
   102
            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
   103
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
   104
            /* 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
   105
            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
   106
                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
   107
            }
1c185bacf915 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 (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
   109
                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
   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
        }
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
   112
    }
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
   113
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
   114
    return value;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
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
   117
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
   118
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
   119
{
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
   120
    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
   121
    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
   122
    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
   123
    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
   124
        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
   125
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   126
    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
   127
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
858
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   129
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
   130
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
   131
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
   132
{
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
   133
    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
   134
    device->removed = 1;
8173
23919d993046 Implement new backend methods for haptic and hot plugging on OS X
Edward Rudd <urkle@outoforder.cc>
parents: 8149
diff changeset
   135
#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
   136
    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
   137
#endif
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   138
    s_bDeviceRemoved = SDL_TRUE;
858
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   139
}
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   140
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   141
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
   142
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
   143
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
   144
/* 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
   145
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
   146
AddHIDElements(CFArrayRef array, recDevice *pDevice)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
{
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
   148
    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
   149
    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
   150
}
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   152
static SDL_bool
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   153
ElementAlreadyAdded(const IOHIDElementCookie cookie, const recElement *listitem) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   154
    while (listitem) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   155
        if (listitem->cookie == cookie) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   156
            return SDL_TRUE;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   157
        }
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   158
        listitem = listitem->pNext;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   159
    }
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   160
    return SDL_FALSE;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   161
}
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   162
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
   163
/* 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
   164
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
   165
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
   166
{
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
   167
    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
   168
    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
   169
    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
   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
    if (refElement && (elementTypeID == IOHIDElementGetTypeID())) {
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   172
        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
   173
        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
   174
        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
   175
        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
   176
        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
   177
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
   178
        /* 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
   179
        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
   180
            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
   181
            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
   182
            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
   183
                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
   184
                    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
   185
                        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
   186
                            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
   187
                            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
   188
                            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
   189
                            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
   190
                            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
   191
                            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
   192
                            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
   193
                            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
   194
                            case kHIDUsage_GD_Wheel:
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   195
                                if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   196
                                    element = (recElement *) SDL_calloc(1, sizeof (recElement));
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   197
                                    if (element) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   198
                                        pDevice->axes++;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   199
                                        headElement = &(pDevice->firstAxis);
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   200
                                    }
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
   201
                                }
1c185bacf915 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
                                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
   203
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   204
                            case kHIDUsage_GD_Hatswitch:
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   205
                                if (!ElementAlreadyAdded(cookie, pDevice->firstHat)) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   206
                                    element = (recElement *) SDL_calloc(1, sizeof (recElement));
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   207
                                    if (element) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   208
                                        pDevice->hats++;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   209
                                        headElement = &(pDevice->firstHat);
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   210
                                    }
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
   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
                                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
   213
                        }
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
   214
                        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
   215
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   216
                    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
   217
                        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
   218
                            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
   219
                            case kHIDUsage_Sim_Throttle:
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   220
                                if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   221
                                    element = (recElement *) SDL_calloc(1, sizeof (recElement));
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   222
                                    if (element) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   223
                                        pDevice->axes++;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   224
                                        headElement = &(pDevice->firstAxis);
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   225
                                    }
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
   226
                                }
1c185bacf915 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
                                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
   228
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
   229
                            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
   230
                                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
   231
                        }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   232
                        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
   233
1c185bacf915 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
                    case kHIDPage_Button:
8242
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   235
                        if (!ElementAlreadyAdded(cookie, pDevice->firstButton)) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   236
                            element = (recElement *) SDL_calloc(1, sizeof (recElement));
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   237
                            if (element) {
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   238
                                pDevice->buttons++;
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   239
                                headElement = &(pDevice->firstButton);
f6a2b1a6932b Mac joystick: ignore duplicate HID elements.
Ryan C. Gordon <icculus@icculus.org>
parents: 8230
diff changeset
   240
                            }
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
   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
                        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
   243
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   244
                    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
   245
                        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
   246
                }
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
   247
            }
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
   248
            break;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
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
   250
            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
   251
                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
   252
                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
   253
                    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
   254
                }
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
   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
            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
   259
                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
   260
        }
7026
bc089599bd82 Added GUIDs for Bluetooth devices, using the same algorithm as the Linux code.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   261
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
   262
        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
   263
            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
   264
            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
   265
            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
   266
                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
   267
                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
   268
            }
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
   269
            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
   270
                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
   271
            } 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
   272
                *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
   273
            }
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   274
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
   275
            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
   276
            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
   277
            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
   278
            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
   279
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
   280
            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
   281
            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
   282
            element->cookie = IOHIDElementGetCookie(refElement);
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
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
   284
            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
   285
        }
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
   286
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
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
   289
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
   290
GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
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
    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
   293
    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
   294
    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
   295
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   296
    /* 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
   297
    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
   298
    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
   299
        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
   300
    }
1c185bacf915 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
    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
   302
        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
   303
    }
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
   304
1c185bacf915 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(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
   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->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
   308
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
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
   310
    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
   311
         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
   312
         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
   313
        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
   314
    }
1c185bacf915 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
1c185bacf915 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
    pDevice->deviceRef = hidDevice;
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
    /* 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
   319
    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
   320
    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
   321
        /* 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
   322
        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
   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
    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
   325
        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
   326
    }
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
   327
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
   328
    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
   329
    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
   330
        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
   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
1c185bacf915 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
    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
   334
    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
   335
        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
   336
    }
2713
0906692aa6a4 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2295
diff changeset
   337
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
   338
    /* 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
   339
       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
   340
    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
   341
    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
   342
        /* 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
   343
        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
   344
        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
   345
        *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
   346
        *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
   347
        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
   348
    }
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
   349
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
   350
    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
   351
    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
   352
        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
   353
        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
   354
    }
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
   355
1c185bacf915 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
    return SDL_TRUE;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
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
   360
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
   361
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
   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
    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
   364
        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
   365
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   366
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
   367
    recDevice *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
   368
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
   369
    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
   370
        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
   371
        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
   372
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   373
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
   374
    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
   375
        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
   376
        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
   377
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   378
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
   379
    /* 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
   380
    IOHIDDeviceRegisterRemovalCallback(ioHIDDeviceObject, JoystickDeviceWasRemovedCallback, 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
   381
    IOHIDDeviceScheduleWithRunLoop(ioHIDDeviceObject, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   382
7791
d9f0067a5421 Only allocate a joystick instance ID once we know it's a joystick.
Sam Lantinga <slouken@libsdl.org>
parents: 7681
diff changeset
   383
    /* 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
   384
    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
   385
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
   386
    /* 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
   387
    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
   388
        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
   389
        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
   390
            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
   391
#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
   392
            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
   393
#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
   394
        }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   395
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   396
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   397
    device->send_open_event = 1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   398
    s_bDeviceAdded = SDL_TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   399
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   400
    /* Add device to the end of the list */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   401
    if ( !gpDeviceList )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   402
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   403
        gpDeviceList = device;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   404
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   405
    else
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   406
    {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   407
        recDevice *curdevice;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   408
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   409
        curdevice = gpDeviceList;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   410
        while ( curdevice->pNext )
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   411
        {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   412
            curdevice = curdevice->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   413
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   414
        curdevice->pNext = device;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   415
    }
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
   416
}
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   417
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
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
   419
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
   420
{
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   421
    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
   422
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   423
    /* Run in a custom RunLoop mode just while initializing,
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   424
       so we can detect sticks without messing with everything 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
   425
    CFStringRef tempRunLoopMode = CFSTR("SDLJoystickInit");
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   426
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   427
    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
   428
        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
   429
    }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   430
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   431
    IOHIDManagerRegisterDeviceMatchingCallback(hidman, JoystickDeviceWasAddedCallback, 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
   432
    IOHIDManagerScheduleWithRunLoop(hidman, runloop, tempRunLoopMode);
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   433
    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
   434
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   435
    while (CFRunLoopRunInMode(tempRunLoopMode,0,TRUE)==kCFRunLoopRunHandledSource) {
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   436
        /* 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
   437
    }
1c185bacf915 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
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   439
    /* Put this in the normal RunLoop mode now, for future hotplug events. */
1c185bacf915 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
    IOHIDManagerUnscheduleFromRunLoop(hidman, runloop, tempRunLoopMode);
1c185bacf915 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
    IOHIDManagerScheduleWithRunLoop(hidman, runloop, kCFRunLoopDefaultMode);
1c185bacf915 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
    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
   444
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   445
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   446
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
   447
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
   448
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
   449
{
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
   450
    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
   451
    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
   452
    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
   453
    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
   454
    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
   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
    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
   457
        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
   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
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   460
    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
   461
        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
   462
    }
1c185bacf915 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
    if (usageNumRef) {
8245
2c63c27c4d1d Free the correct variable.
Ryan C. Gordon <icculus@icculus.org>
parents: 8242
diff changeset
   464
        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
   465
    }
1c185bacf915 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
1c185bacf915 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
    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
   468
        *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
   469
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   470
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
   471
    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
   472
}
1c185bacf915 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
1c185bacf915 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
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
   475
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
   476
{
1c185bacf915 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
    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
   478
    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
   479
    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
   480
        (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
   481
        (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
   482
        (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
   483
    };
1c185bacf915 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
    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
   485
    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
   486
    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
   487
1c185bacf915 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
    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
   489
        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
   490
            CFRelease((CFTypeRef) vals[i]);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   491
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   492
    }
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
   493
1c185bacf915 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
    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
   495
        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
   496
        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
   497
            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
   498
        }
1c185bacf915 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
        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
   500
    }
1c185bacf915 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
1c185bacf915 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
    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
   503
}
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   504
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   505
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   506
/* 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
   507
 * 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
   508
 * 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
   509
 * on an unrecoverable fatal error.
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   510
 */
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
   511
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
   512
SDL_SYS_JoystickInit(void)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   513
{
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
   514
    if (gpDeviceList) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 7026
diff changeset
   515
        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
   516
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
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
   518
    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
   519
        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
   520
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   521
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   522
    return SDL_SYS_NumJoysticks();
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   523
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   524
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   525
/* 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
   526
int
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   527
SDL_SYS_NumJoysticks()
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   528
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   529
    recDevice *device = gpDeviceList;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   530
    int nJoySticks = 0;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   531
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
   532
    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
   533
        if (!device->removed) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   534
            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
   535
        }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   536
        device = device->pNext;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   537
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   538
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   539
    return nJoySticks;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   540
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   541
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   542
/* 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
   543
 */
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   544
void
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   545
SDL_SYS_JoystickDetect()
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   546
{
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
   547
    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
   548
        recDevice *device = gpDeviceList;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   549
        s_bDeviceAdded = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   550
        s_bDeviceRemoved = SDL_FALSE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   551
        int device_index = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   552
        /* 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
   553
        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
   554
            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
   555
                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
   556
/* !!! 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
   557
#if !SDL_EVENTS_DISABLED
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   558
                SDL_Event event;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   559
                event.type = SDL_JOYDEVICEADDED;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   560
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   561
                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
   562
                    event.jdevice.which = device_index;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   563
                    if ((SDL_EventOK == NULL)
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   564
                        || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   565
                        SDL_PushEvent(&event);
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   566
                    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   567
                }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   568
#endif /* !SDL_EVENTS_DISABLED */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   569
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   570
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   571
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
   572
            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
   573
                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
   574
                device = FreeDevice(device);
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   575
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_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
   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_JOYDEVICEREMOVED;
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) {
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
   582
                    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
   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
                }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   588
#endif /* !SDL_EVENTS_DISABLED */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   589
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
   590
            } else {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   591
                device = device->pNext;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   592
                device_index++;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   593
            }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   594
        }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   595
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   596
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   597
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   598
SDL_bool
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   599
SDL_SYS_JoystickNeedsPolling()
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   600
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   601
    return s_bDeviceAdded || s_bDeviceRemoved;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   602
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   603
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   604
/* 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
   605
const char *
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   606
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
   607
{
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
   608
    recDevice *device = gpDeviceList;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
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
    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
   611
        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
   612
    }
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
   613
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   614
    return device->product;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   615
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   616
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   617
/* 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
   618
 */
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   619
SDL_JoystickID
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   620
SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   621
{
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   622
    recDevice *device = gpDeviceList;
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   623
    int index;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   624
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
   625
    for (index = device_index; index > 0; index--) {
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   626
        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
   627
    }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   628
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   629
    return device->instance_id;
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   630
}
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   631
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   632
/* 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
   633
 * 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
   634
 * 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
   635
 * 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
   636
 */
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
   637
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
   638
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
   639
{
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
   640
    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
   641
    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
   642
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
   643
    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
   644
        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
   645
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   646
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   647
    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
   648
    joystick->hwdata = device;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   649
    joystick->name = device->product;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   650
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   651
    joystick->naxes = device->axes;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   652
    joystick->nhats = device->hats;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   653
    joystick->nballs = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   654
    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
   655
    return 0;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   656
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   657
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   658
/* 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
   659
 *   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
   660
 */
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   661
SDL_bool
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   662
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
   663
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   664
    recDevice *device = gpDeviceList;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   665
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
   666
    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
   667
        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
   668
            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
   669
        }
6707
70eeb7e3ec2f Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents: 6698
diff changeset
   670
        device = device->pNext;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   671
    }
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   672
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   673
    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
   674
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   675
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   676
/* 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
   677
 * 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
   678
 * 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
   679
 * and update joystick device state.
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   680
 */
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
   681
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
   682
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
   683
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   684
    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
   685
    recElement *element;
2287
15a242fca6c4 Fixed bug #478
Sam Lantinga <slouken@libsdl.org>
parents: 2120
diff changeset
   686
    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
   687
    int i;
858
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   688
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
   689
    if (!device) {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   690
        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
   691
    }
858
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   692
6690
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   693
    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
   694
        joystick->closed = 1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   695
        joystick->uncentered = 1;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   696
        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
   697
        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
   698
    }
858
5db50aa5bf08 Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
   699
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
   700
    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
   701
    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
   702
    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
   703
        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
   704
        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
   705
            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
   706
        }
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
   707
        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
   708
        ++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
   709
    }
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
   710
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
    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
   712
    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
   713
    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
   714
        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
   715
        if (value > 1) {          /* handle pressure-sensitive buttons */
629
3fa401bb4bb5 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 623
diff changeset
   716
            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
   717
        }
1c185bacf915 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->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
   719
            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
   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->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
   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) {
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
   728
        Uint8 pos = 0;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   729
2287
15a242fca6c4 Fixed bug #478
Sam Lantinga <slouken@libsdl.org>
parents: 2120
diff changeset
   730
        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
   731
        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
   732
        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
   733
            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
   734
        } 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
   735
            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
   736
        }
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
   737
        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
   738
        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
   739
            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
   740
            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
   741
        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
   742
            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
   743
            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
   744
        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
   745
            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
   746
            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
   747
        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
   748
            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
   749
            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
   750
        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
   751
            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
   752
            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
   753
        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
   754
            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
   755
            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
   756
        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
   757
            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
   758
            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
   759
        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
   760
            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
   761
            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
   762
        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
   763
            /* 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
   764
             * 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
   765
             * 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
   766
             */
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
            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
   768
            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
   769
        }
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
   770
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   771
        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
   772
            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
   773
        }
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   774
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
   775
        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
   776
        ++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
   777
    }
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   778
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   779
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   780
/* 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
   781
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
   782
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
   783
{
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   784
    joystick->closed = 1;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   785
}
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   786
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   787
/* 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
   788
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
   789
SDL_SYS_JoystickQuit(void)
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   790
{
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
   791
    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
   792
        /* 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
   793
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   794
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
   795
    if (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
   796
        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
   797
        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
   798
        hidman = NULL;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   799
    }
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
   800
1c185bacf915 Reworked Mac OS X joystick code to use the 10.5+ HID Manager API.
Ryan C. Gordon <icculus@icculus.org>
parents: 8176
diff changeset
   801
    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
   802
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   803
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   804
6738
b408d5a406a3 Changes from Alfred:
Sam Lantinga <slouken@libsdl.org>
parents: 6718
diff changeset
   805
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
   806
{
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   807
    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
   808
    int index;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   809
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
   810
    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
   811
        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
   812
    }
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   813
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   814
    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
   815
}
9548c8a58103 Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   816
6738
b408d5a406a3 Changes from Alfred:
Sam Lantinga <slouken@libsdl.org>
parents: 6718
diff changeset
   817
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
   818
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7133
diff changeset
   819
    return joystick->hwdata->guid;
172
37e3ca9254c7 Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   820
}
1635
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1621
diff changeset
   821
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1621
diff changeset
   822
#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
   823
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
   824
/* vi: set ts=4 sw=4 expandtab: */