author | Sam Lantinga <slouken@libsdl.org> |
Fri, 26 Aug 2016 12:18:08 -0700 | |
changeset 10281 | cb13d22b7f09 |
parent 9998 | f67cf37e9cd4 |
permissions | -rw-r--r-- |
0 | 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 |
9998
f67cf37e9cd4
Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents:
9916
diff
changeset
|
3 |
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> |
0 | 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. |
0 | 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: |
0 | 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. |
0 | 20 |
*/ |
8093
b43765095a6f
Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents:
7922
diff
changeset
|
21 |
#include "../SDL_internal.h" |
0 | 22 |
|
23 |
/* This is the joystick API for Simple DirectMedia Layer */ |
|
24 |
||
7337
5ba1fafc6a94
Only check for keyboard focus if the video subsystem was initialized.
Sam Lantinga <slouken@libsdl.org>
parents:
7307
diff
changeset
|
25 |
#include "SDL.h" |
0 | 26 |
#include "SDL_events.h" |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
27 |
#include "SDL_sysjoystick.h" |
5861 | 28 |
#include "SDL_assert.h" |
7279
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
29 |
#include "SDL_hints.h" |
5861 | 30 |
|
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
31 |
#if !SDL_EVENTS_DISABLED |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
32 |
#include "../events/SDL_events_c.h" |
0 | 33 |
#endif |
34 |
||
7337
5ba1fafc6a94
Only check for keyboard focus if the video subsystem was initialized.
Sam Lantinga <slouken@libsdl.org>
parents:
7307
diff
changeset
|
35 |
static SDL_bool SDL_joystick_allows_background_events = SDL_FALSE; |
6712
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
36 |
static SDL_Joystick *SDL_joysticks = NULL; |
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
37 |
static SDL_Joystick *SDL_updating_joystick = NULL; |
0 | 38 |
|
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
39 |
static void |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
40 |
SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint) |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
41 |
{ |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
42 |
if (hint && *hint == '1') { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
43 |
SDL_joystick_allows_background_events = SDL_TRUE; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
44 |
} else { |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
45 |
SDL_joystick_allows_background_events = SDL_FALSE; |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
46 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
47 |
} |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
48 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
49 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
50 |
SDL_JoystickInit(void) |
0 | 51 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
52 |
int status; |
7500
6b484ff38f86
Corrected internal documentation in source.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7432
diff
changeset
|
53 |
|
7432
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
54 |
/* See if we should allow joystick events while in the background */ |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
55 |
SDL_AddHintCallback(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, |
58908b180ebd
Added a hint to control the Windows timer resolution: SDL_HINT_TIMER_RESOLUTION
Sam Lantinga <slouken@libsdl.org>
parents:
7360
diff
changeset
|
56 |
SDL_JoystickAllowBackgroundEventsChanged, NULL); |
0 | 57 |
|
7360
b86947ea2749
Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents:
7337
diff
changeset
|
58 |
#if !SDL_EVENTS_DISABLED |
b86947ea2749
Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents:
7337
diff
changeset
|
59 |
if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) { |
b86947ea2749
Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents:
7337
diff
changeset
|
60 |
return -1; |
b86947ea2749
Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents:
7337
diff
changeset
|
61 |
} |
b86947ea2749
Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents:
7337
diff
changeset
|
62 |
#endif /* !SDL_EVENTS_DISABLED */ |
b86947ea2749
Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents:
7337
diff
changeset
|
63 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
64 |
status = SDL_SYS_JoystickInit(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
65 |
if (status >= 0) { |
7337
5ba1fafc6a94
Only check for keyboard focus if the video subsystem was initialized.
Sam Lantinga <slouken@libsdl.org>
parents:
7307
diff
changeset
|
66 |
status = 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:
1612
diff
changeset
|
67 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
68 |
return (status); |
0 | 69 |
} |
70 |
||
71 |
/* |
|
72 |
* Count the number of joysticks attached to the system |
|
73 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
74 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
75 |
SDL_NumJoysticks(void) |
0 | 76 |
{ |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
77 |
return SDL_SYS_NumJoysticks(); |
0 | 78 |
} |
79 |
||
80 |
/* |
|
81 |
* Get the implementation dependent name of a joystick |
|
82 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
83 |
const char * |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
84 |
SDL_JoystickNameForIndex(int device_index) |
0 | 85 |
{ |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
86 |
if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) { |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
87 |
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks()); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
88 |
return (NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
89 |
} |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6693
diff
changeset
|
90 |
return (SDL_SYS_JoystickNameForDeviceIndex(device_index)); |
0 | 91 |
} |
92 |
||
93 |
/* |
|
94 |
* Open a joystick for use - the index passed as an argument refers to |
|
95 |
* the N'th joystick on the system. This index is the value which will |
|
96 |
* identify this joystick in future joystick events. |
|
97 |
* |
|
98 |
* This function returns a joystick identifier, or NULL if an error occurred. |
|
99 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
100 |
SDL_Joystick * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
101 |
SDL_JoystickOpen(int device_index) |
0 | 102 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
103 |
SDL_Joystick *joystick; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
104 |
SDL_Joystick *joysticklist; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
105 |
const char *joystickname = NULL; |
0 | 106 |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
107 |
if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) { |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
108 |
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks()); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
109 |
return (NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
110 |
} |
0 | 111 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
112 |
joysticklist = SDL_joysticks; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
113 |
/* If the joystick is already open, return it |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
114 |
* it is important that we have a single joystick * for each instance id |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
115 |
*/ |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
116 |
while (joysticklist) { |
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
117 |
if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == joysticklist->instance_id) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
118 |
joystick = joysticklist; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
119 |
++joystick->ref_count; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
120 |
return (joystick); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
121 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
122 |
joysticklist = joysticklist->next; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
123 |
} |
0 | 124 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
125 |
/* Create and initialize the joystick */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
126 |
joystick = (SDL_Joystick *) SDL_malloc((sizeof *joystick)); |
3608
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
127 |
if (joystick == NULL) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
128 |
SDL_OutOfMemory(); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
129 |
return NULL; |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
130 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
131 |
|
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
132 |
SDL_memset(joystick, 0, (sizeof *joystick)); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
133 |
if (SDL_SYS_JoystickOpen(joystick, device_index) < 0) { |
3608
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
134 |
SDL_free(joystick); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
135 |
return NULL; |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
136 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
137 |
|
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
138 |
joystickname = SDL_SYS_JoystickNameForDeviceIndex(device_index); |
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
139 |
if (joystickname) |
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
140 |
joystick->name = SDL_strdup(joystickname); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
141 |
else |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
142 |
joystick->name = NULL; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
143 |
|
3608
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
144 |
if (joystick->naxes > 0) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
145 |
joystick->axes = (Sint16 *) SDL_malloc |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
146 |
(joystick->naxes * sizeof(Sint16)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
147 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
148 |
if (joystick->nhats > 0) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
149 |
joystick->hats = (Uint8 *) SDL_malloc |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
150 |
(joystick->nhats * sizeof(Uint8)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
151 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
152 |
if (joystick->nballs > 0) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
153 |
joystick->balls = (struct balldelta *) SDL_malloc |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
154 |
(joystick->nballs * sizeof(*joystick->balls)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
155 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
156 |
if (joystick->nbuttons > 0) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
157 |
joystick->buttons = (Uint8 *) SDL_malloc |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
158 |
(joystick->nbuttons * sizeof(Uint8)); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
159 |
} |
3608
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
160 |
if (((joystick->naxes > 0) && !joystick->axes) |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
161 |
|| ((joystick->nhats > 0) && !joystick->hats) |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
162 |
|| ((joystick->nballs > 0) && !joystick->balls) |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
163 |
|| ((joystick->nbuttons > 0) && !joystick->buttons)) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
164 |
SDL_OutOfMemory(); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
165 |
SDL_JoystickClose(joystick); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
166 |
return NULL; |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
167 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
168 |
if (joystick->axes) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
169 |
SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
170 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
171 |
if (joystick->hats) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
172 |
SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8)); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
173 |
} |
3608
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
174 |
if (joystick->balls) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
175 |
SDL_memset(joystick->balls, 0, |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
176 |
joystick->nballs * sizeof(*joystick->balls)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
177 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
178 |
if (joystick->buttons) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
179 |
SDL_memset(joystick->buttons, 0, joystick->nbuttons * sizeof(Uint8)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
180 |
} |
9884
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
181 |
joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN; |
3608
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
182 |
|
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
183 |
/* Add joystick to list */ |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
184 |
++joystick->ref_count; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
185 |
/* Link the joystick in the list */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
186 |
joystick->next = SDL_joysticks; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
187 |
SDL_joysticks = joystick; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
188 |
|
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
189 |
SDL_SYS_JoystickUpdate(joystick); |
3608
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
190 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
191 |
return (joystick); |
0 | 192 |
} |
193 |
||
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
194 |
|
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
195 |
/* |
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
196 |
* Checks to make sure the joystick is valid. |
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
197 |
*/ |
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
198 |
int |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
199 |
SDL_PrivateJoystickValid(SDL_Joystick * joystick) |
0 | 200 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
201 |
int valid; |
0 | 202 |
|
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
203 |
if (joystick == 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:
1612
diff
changeset
|
204 |
SDL_SetError("Joystick hasn't been opened yet"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
205 |
valid = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
206 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
207 |
valid = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
208 |
} |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
209 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
210 |
return valid; |
0 | 211 |
} |
212 |
||
213 |
/* |
|
214 |
* Get the number of multi-dimensional axis controls on a joystick |
|
215 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
216 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
217 |
SDL_JoystickNumAxes(SDL_Joystick * joystick) |
0 | 218 |
{ |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
219 |
if (!SDL_PrivateJoystickValid(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:
1612
diff
changeset
|
220 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
221 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
222 |
return (joystick->naxes); |
0 | 223 |
} |
224 |
||
225 |
/* |
|
226 |
* Get the number of hats on a joystick |
|
227 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
228 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
229 |
SDL_JoystickNumHats(SDL_Joystick * joystick) |
0 | 230 |
{ |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
231 |
if (!SDL_PrivateJoystickValid(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:
1612
diff
changeset
|
232 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
233 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
234 |
return (joystick->nhats); |
0 | 235 |
} |
236 |
||
237 |
/* |
|
238 |
* Get the number of trackballs on a joystick |
|
239 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
240 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
241 |
SDL_JoystickNumBalls(SDL_Joystick * joystick) |
0 | 242 |
{ |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
243 |
if (!SDL_PrivateJoystickValid(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:
1612
diff
changeset
|
244 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
245 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
246 |
return (joystick->nballs); |
0 | 247 |
} |
248 |
||
249 |
/* |
|
250 |
* Get the number of buttons on a joystick |
|
251 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
252 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
253 |
SDL_JoystickNumButtons(SDL_Joystick * joystick) |
0 | 254 |
{ |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
255 |
if (!SDL_PrivateJoystickValid(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:
1612
diff
changeset
|
256 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
257 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
258 |
return (joystick->nbuttons); |
0 | 259 |
} |
260 |
||
261 |
/* |
|
262 |
* Get the current state of an axis control on a joystick |
|
263 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
264 |
Sint16 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
265 |
SDL_JoystickGetAxis(SDL_Joystick * joystick, int axis) |
0 | 266 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
267 |
Sint16 state; |
0 | 268 |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
269 |
if (!SDL_PrivateJoystickValid(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:
1612
diff
changeset
|
270 |
return (0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
271 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
272 |
if (axis < joystick->naxes) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
273 |
state = joystick->axes[axis]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
274 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
275 |
SDL_SetError("Joystick only has %d axes", joystick->naxes); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
276 |
state = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
277 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
278 |
return (state); |
0 | 279 |
} |
280 |
||
281 |
/* |
|
282 |
* Get the current state of a hat on a joystick |
|
283 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
284 |
Uint8 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
285 |
SDL_JoystickGetHat(SDL_Joystick * joystick, int hat) |
0 | 286 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
287 |
Uint8 state; |
0 | 288 |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
289 |
if (!SDL_PrivateJoystickValid(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:
1612
diff
changeset
|
290 |
return (0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
291 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
292 |
if (hat < joystick->nhats) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
293 |
state = joystick->hats[hat]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
294 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
295 |
SDL_SetError("Joystick only has %d hats", joystick->nhats); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
296 |
state = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
297 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
298 |
return (state); |
0 | 299 |
} |
300 |
||
301 |
/* |
|
302 |
* Get the ball axis change since the last poll |
|
303 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
304 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
305 |
SDL_JoystickGetBall(SDL_Joystick * joystick, int ball, int *dx, int *dy) |
0 | 306 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
307 |
int retval; |
0 | 308 |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
309 |
if (!SDL_PrivateJoystickValid(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:
1612
diff
changeset
|
310 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
311 |
} |
0 | 312 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
313 |
retval = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
314 |
if (ball < joystick->nballs) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
315 |
if (dx) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
316 |
*dx = joystick->balls[ball].dx; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
317 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
318 |
if (dy) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
319 |
*dy = joystick->balls[ball].dy; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
320 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
321 |
joystick->balls[ball].dx = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
322 |
joystick->balls[ball].dy = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
323 |
} else { |
7037
3fedf1f25b94
Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents:
6885
diff
changeset
|
324 |
return SDL_SetError("Joystick only has %d balls", joystick->nballs); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
325 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
326 |
return (retval); |
0 | 327 |
} |
328 |
||
329 |
/* |
|
330 |
* Get the current state of a button on a joystick |
|
331 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
332 |
Uint8 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
333 |
SDL_JoystickGetButton(SDL_Joystick * joystick, int button) |
0 | 334 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
335 |
Uint8 state; |
0 | 336 |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
337 |
if (!SDL_PrivateJoystickValid(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:
1612
diff
changeset
|
338 |
return (0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
339 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
340 |
if (button < joystick->nbuttons) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
341 |
state = joystick->buttons[button]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
342 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
343 |
SDL_SetError("Joystick only has %d buttons", joystick->nbuttons); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
344 |
state = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
345 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
346 |
return (state); |
0 | 347 |
} |
348 |
||
349 |
/* |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
350 |
* Return if the joystick in question is currently attached to the system, |
7500
6b484ff38f86
Corrected internal documentation in source.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7432
diff
changeset
|
351 |
* \return SDL_FALSE if not plugged in, SDL_TRUE if still present. |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
352 |
*/ |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6693
diff
changeset
|
353 |
SDL_bool |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6693
diff
changeset
|
354 |
SDL_JoystickGetAttached(SDL_Joystick * joystick) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
355 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
356 |
if (!SDL_PrivateJoystickValid(joystick)) { |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6693
diff
changeset
|
357 |
return SDL_FALSE; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
358 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
359 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
360 |
return SDL_SYS_JoystickAttached(joystick); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
361 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
362 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
363 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
364 |
* Get the instance id for this opened joystick |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
365 |
*/ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
366 |
SDL_JoystickID |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6693
diff
changeset
|
367 |
SDL_JoystickInstanceID(SDL_Joystick * joystick) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
368 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
369 |
if (!SDL_PrivateJoystickValid(joystick)) { |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
370 |
return (-1); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
371 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
372 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
373 |
return (joystick->instance_id); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
374 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
375 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
376 |
/* |
9916
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
377 |
* Find the SDL_Joystick that owns this instance id |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
378 |
*/ |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
379 |
SDL_Joystick * |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
380 |
SDL_JoystickFromInstanceID(SDL_JoystickID joyid) |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
381 |
{ |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
382 |
SDL_Joystick *joystick = SDL_joysticks; |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
383 |
while (joystick) { |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
384 |
if (joystick->instance_id == joyid) { |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
385 |
return joystick; |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
386 |
} |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
387 |
joystick = joystick->next; |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
388 |
} |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
389 |
|
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
390 |
return NULL; |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
391 |
} |
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
392 |
|
9429bc102632
Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Ryan C. Gordon <icculus@icculus.org>
parents:
9884
diff
changeset
|
393 |
/* |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
394 |
* Get the friendly name of this joystick |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
395 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
396 |
const char * |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
397 |
SDL_JoystickName(SDL_Joystick * joystick) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
398 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
399 |
if (!SDL_PrivateJoystickValid(joystick)) { |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
400 |
return (NULL); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
401 |
} |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
402 |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
403 |
return (joystick->name); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
404 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
405 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
406 |
/* |
0 | 407 |
* Close a joystick previously opened with SDL_JoystickOpen() |
408 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
409 |
void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
410 |
SDL_JoystickClose(SDL_Joystick * joystick) |
0 | 411 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
412 |
SDL_Joystick *joysticklist; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
413 |
SDL_Joystick *joysticklistprev; |
0 | 414 |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
415 |
if (!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:
1612
diff
changeset
|
416 |
return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
417 |
} |
0 | 418 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
419 |
/* First decrement ref count */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
420 |
if (--joystick->ref_count > 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
421 |
return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
422 |
} |
0 | 423 |
|
6712
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
424 |
if (joystick == SDL_updating_joystick) { |
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
425 |
return; |
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
426 |
} |
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
427 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
428 |
SDL_SYS_JoystickClose(joystick); |
9433
bd062398b648
Cleanups in the joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
8920
diff
changeset
|
429 |
joystick->hwdata = NULL; |
0 | 430 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
431 |
joysticklist = SDL_joysticks; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
432 |
joysticklistprev = NULL; |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
433 |
while (joysticklist) { |
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
434 |
if (joystick == joysticklist) { |
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
435 |
if (joysticklistprev) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
436 |
/* unlink this entry */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
437 |
joysticklistprev->next = joysticklist->next; |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
438 |
} else { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
439 |
SDL_joysticks = joystick->next; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
440 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
441 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
442 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
443 |
joysticklistprev = joysticklist; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
444 |
joysticklist = joysticklist->next; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
445 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
446 |
|
7719
31b5f9ff36ca
Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents:
7677
diff
changeset
|
447 |
SDL_free(joystick->name); |
0 | 448 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
449 |
/* Free the data associated with this joystick */ |
7719
31b5f9ff36ca
Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents:
7677
diff
changeset
|
450 |
SDL_free(joystick->axes); |
31b5f9ff36ca
Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents:
7677
diff
changeset
|
451 |
SDL_free(joystick->hats); |
31b5f9ff36ca
Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents:
7677
diff
changeset
|
452 |
SDL_free(joystick->balls); |
31b5f9ff36ca
Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents:
7677
diff
changeset
|
453 |
SDL_free(joystick->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:
1612
diff
changeset
|
454 |
SDL_free(joystick); |
0 | 455 |
} |
456 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
457 |
void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
458 |
SDL_JoystickQuit(void) |
0 | 459 |
{ |
6712
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
460 |
/* Make sure we're not getting called in the middle of updating joysticks */ |
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
461 |
SDL_assert(!SDL_updating_joystick); |
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
462 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
463 |
/* Stop the event polling */ |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
464 |
while (SDL_joysticks) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
465 |
SDL_joysticks->ref_count = 1; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
466 |
SDL_JoystickClose(SDL_joysticks); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
467 |
} |
5856
173d28fd4be4
Clean up any opened joysticks during SDL_JoystickQuit().
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
468 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
469 |
/* Quit the joystick setup */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
470 |
SDL_SYS_JoystickQuit(); |
7360
b86947ea2749
Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents:
7337
diff
changeset
|
471 |
|
b86947ea2749
Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents:
7337
diff
changeset
|
472 |
#if !SDL_EVENTS_DISABLED |
b86947ea2749
Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents:
7337
diff
changeset
|
473 |
SDL_QuitSubSystem(SDL_INIT_EVENTS); |
b86947ea2749
Make it possible to use SDL events separately from the video subsystem.
Sam Lantinga <slouken@libsdl.org>
parents:
7337
diff
changeset
|
474 |
#endif |
0 | 475 |
} |
476 |
||
477 |
||
7279
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
478 |
static SDL_bool |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
479 |
SDL_PrivateJoystickShouldIgnoreEvent() |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
480 |
{ |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
481 |
if (SDL_joystick_allows_background_events) { |
7279
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
482 |
return SDL_FALSE; |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
483 |
} |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
484 |
|
7337
5ba1fafc6a94
Only check for keyboard focus if the video subsystem was initialized.
Sam Lantinga <slouken@libsdl.org>
parents:
7307
diff
changeset
|
485 |
if (SDL_WasInit(SDL_INIT_VIDEO)) { |
5ba1fafc6a94
Only check for keyboard focus if the video subsystem was initialized.
Sam Lantinga <slouken@libsdl.org>
parents:
7307
diff
changeset
|
486 |
if (SDL_GetKeyboardFocus() == NULL) { |
7677
871d43c6968a
OCD fixes: Adds a space before */
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7662
diff
changeset
|
487 |
/* Video is initialized and we don't have focus, ignore the event. */ |
7337
5ba1fafc6a94
Only check for keyboard focus if the video subsystem was initialized.
Sam Lantinga <slouken@libsdl.org>
parents:
7307
diff
changeset
|
488 |
return SDL_TRUE; |
5ba1fafc6a94
Only check for keyboard focus if the video subsystem was initialized.
Sam Lantinga <slouken@libsdl.org>
parents:
7307
diff
changeset
|
489 |
} else { |
5ba1fafc6a94
Only check for keyboard focus if the video subsystem was initialized.
Sam Lantinga <slouken@libsdl.org>
parents:
7307
diff
changeset
|
490 |
return SDL_FALSE; |
5ba1fafc6a94
Only check for keyboard focus if the video subsystem was initialized.
Sam Lantinga <slouken@libsdl.org>
parents:
7307
diff
changeset
|
491 |
} |
7279
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
492 |
} |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
493 |
|
7677
871d43c6968a
OCD fixes: Adds a space before */
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7662
diff
changeset
|
494 |
/* Video subsystem wasn't initialized, always allow the event */ |
7337
5ba1fafc6a94
Only check for keyboard focus if the video subsystem was initialized.
Sam Lantinga <slouken@libsdl.org>
parents:
7307
diff
changeset
|
495 |
return SDL_FALSE; |
7279
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
496 |
} |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
497 |
|
0 | 498 |
/* These are global for SDL_sysjoystick.c and SDL_events.c */ |
499 |
||
10281
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
500 |
void SDL_PrivateJoystickAdded(int device_index) |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
501 |
{ |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
502 |
#if !SDL_EVENTS_DISABLED |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
503 |
SDL_Event event; |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
504 |
|
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
505 |
event.type = SDL_JOYDEVICEADDED; |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
506 |
|
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
507 |
if (SDL_GetEventState(event.type) == SDL_ENABLE) { |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
508 |
event.jdevice.which = device_index; |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
509 |
if ( (SDL_EventOK == NULL) || |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
510 |
(*SDL_EventOK) (SDL_EventOKParam, &event) ) { |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
511 |
SDL_PushEvent(&event); |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
512 |
} |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
513 |
} |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
514 |
#endif /* !SDL_EVENTS_DISABLED */ |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
515 |
} |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
516 |
|
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
517 |
/* |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
518 |
* If there is an existing add event in the queue, it needs to be modified |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
519 |
* to have the right value for which, because the number of controllers in |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
520 |
* the system is now one less. |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
521 |
*/ |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
522 |
static void UpdateEventsForDeviceRemoval() |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
523 |
{ |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
524 |
int i, num_events; |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
525 |
SDL_Event *events; |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
526 |
|
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
527 |
num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED); |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
528 |
if (num_events <= 0) { |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
529 |
return; |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
530 |
} |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
531 |
|
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
532 |
events = SDL_stack_alloc(SDL_Event, num_events); |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
533 |
if (!events) { |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
534 |
return; |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
535 |
} |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
536 |
|
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
537 |
num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED); |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
538 |
for (i = 0; i < num_events; ++i) { |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
539 |
--events[i].jdevice.which; |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
540 |
} |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
541 |
SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0); |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
542 |
|
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
543 |
SDL_stack_free(events); |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
544 |
} |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
545 |
|
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
546 |
void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance) |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
547 |
{ |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
548 |
#if !SDL_EVENTS_DISABLED |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
549 |
SDL_Event event; |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
550 |
|
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
551 |
event.type = SDL_JOYDEVICEREMOVED; |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
552 |
|
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
553 |
if (SDL_GetEventState(event.type) == SDL_ENABLE) { |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
554 |
event.jdevice.which = device_instance; |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
555 |
if ( (SDL_EventOK == NULL) || |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
556 |
(*SDL_EventOK) (SDL_EventOKParam, &event) ) { |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
557 |
SDL_PushEvent(&event); |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
558 |
} |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
559 |
} |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
560 |
|
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
561 |
UpdateEventsForDeviceRemoval(); |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
562 |
#endif /* !SDL_EVENTS_DISABLED */ |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
563 |
} |
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
564 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
565 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
566 |
SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value) |
0 | 567 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
568 |
int posted; |
0 | 569 |
|
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
570 |
/* Make sure we're not getting garbage or duplicate events */ |
6145
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
571 |
if (axis >= joystick->naxes) { |
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
572 |
return 0; |
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
573 |
} |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
574 |
if (value == joystick->axes[axis]) { |
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
575 |
return 0; |
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
576 |
} |
6145
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
577 |
|
8903
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
578 |
/* We ignore events if we don't have keyboard focus, except for centering |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
579 |
* events. |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
580 |
*/ |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
581 |
if (SDL_PrivateJoystickShouldIgnoreEvent()) { |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
582 |
if ((value > 0 && value >= joystick->axes[axis]) || |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
583 |
(value < 0 && value <= joystick->axes[axis])) { |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
584 |
return 0; |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
585 |
} |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
586 |
} |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
587 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
588 |
/* Update internal joystick state */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
589 |
joystick->axes[axis] = value; |
0 | 590 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
591 |
/* Post the event, if desired */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
592 |
posted = 0; |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
593 |
#if !SDL_EVENTS_DISABLED |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
594 |
if (SDL_GetEventState(SDL_JOYAXISMOTION) == SDL_ENABLE) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
595 |
SDL_Event event; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
596 |
event.type = SDL_JOYAXISMOTION; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
597 |
event.jaxis.which = joystick->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:
1612
diff
changeset
|
598 |
event.jaxis.axis = axis; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
599 |
event.jaxis.value = value; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
600 |
posted = SDL_PushEvent(&event) == 1; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
601 |
} |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
602 |
#endif /* !SDL_EVENTS_DISABLED */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
603 |
return (posted); |
0 | 604 |
} |
605 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
606 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
607 |
SDL_PrivateJoystickHat(SDL_Joystick * joystick, Uint8 hat, Uint8 value) |
0 | 608 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
609 |
int posted; |
0 | 610 |
|
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
611 |
/* Make sure we're not getting garbage or duplicate events */ |
6145
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
612 |
if (hat >= joystick->nhats) { |
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
613 |
return 0; |
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
614 |
} |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
615 |
if (value == joystick->hats[hat]) { |
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
616 |
return 0; |
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
617 |
} |
6145
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
618 |
|
7279
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
619 |
/* We ignore events if we don't have keyboard focus, except for centering |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
620 |
* events. |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
621 |
*/ |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
622 |
if (SDL_PrivateJoystickShouldIgnoreEvent()) { |
8903
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
623 |
if (value != SDL_HAT_CENTERED) { |
7279
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
624 |
return 0; |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
625 |
} |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
626 |
} |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
627 |
|
8903
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
628 |
/* Update internal joystick state */ |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
629 |
joystick->hats[hat] = value; |
7279
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
630 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
631 |
/* Post the event, if desired */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
632 |
posted = 0; |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
633 |
#if !SDL_EVENTS_DISABLED |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
634 |
if (SDL_GetEventState(SDL_JOYHATMOTION) == SDL_ENABLE) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
635 |
SDL_Event event; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
636 |
event.jhat.type = SDL_JOYHATMOTION; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
637 |
event.jhat.which = joystick->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:
1612
diff
changeset
|
638 |
event.jhat.hat = hat; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
639 |
event.jhat.value = value; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
640 |
posted = SDL_PushEvent(&event) == 1; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
641 |
} |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
642 |
#endif /* !SDL_EVENTS_DISABLED */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
643 |
return (posted); |
0 | 644 |
} |
645 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
646 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
647 |
SDL_PrivateJoystickBall(SDL_Joystick * joystick, Uint8 ball, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
648 |
Sint16 xrel, Sint16 yrel) |
0 | 649 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
650 |
int posted; |
0 | 651 |
|
6145
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
652 |
/* Make sure we're not getting garbage events */ |
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
653 |
if (ball >= joystick->nballs) { |
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
654 |
return 0; |
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
655 |
} |
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
656 |
|
7279
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
657 |
/* We ignore events if we don't have keyboard focus. */ |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
658 |
if (SDL_PrivateJoystickShouldIgnoreEvent()) { |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
659 |
return 0; |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
660 |
} |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
661 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
662 |
/* Update internal mouse state */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
663 |
joystick->balls[ball].dx += xrel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
664 |
joystick->balls[ball].dy += yrel; |
0 | 665 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
666 |
/* Post the event, if desired */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
667 |
posted = 0; |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
668 |
#if !SDL_EVENTS_DISABLED |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
669 |
if (SDL_GetEventState(SDL_JOYBALLMOTION) == SDL_ENABLE) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
670 |
SDL_Event event; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
671 |
event.jball.type = SDL_JOYBALLMOTION; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
672 |
event.jball.which = joystick->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:
1612
diff
changeset
|
673 |
event.jball.ball = ball; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
674 |
event.jball.xrel = xrel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
675 |
event.jball.yrel = yrel; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
676 |
posted = SDL_PushEvent(&event) == 1; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
677 |
} |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
678 |
#endif /* !SDL_EVENTS_DISABLED */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
679 |
return (posted); |
0 | 680 |
} |
681 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
682 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
683 |
SDL_PrivateJoystickButton(SDL_Joystick * joystick, Uint8 button, Uint8 state) |
0 | 684 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
685 |
int posted; |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
686 |
#if !SDL_EVENTS_DISABLED |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
687 |
SDL_Event event; |
0 | 688 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
689 |
switch (state) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
690 |
case SDL_PRESSED: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
691 |
event.type = SDL_JOYBUTTONDOWN; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
692 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
693 |
case SDL_RELEASED: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
694 |
event.type = SDL_JOYBUTTONUP; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
695 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
696 |
default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
697 |
/* Invalid state -- bail */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
698 |
return (0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
699 |
} |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
700 |
#endif /* !SDL_EVENTS_DISABLED */ |
0 | 701 |
|
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
702 |
/* Make sure we're not getting garbage or duplicate events */ |
6145
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
703 |
if (button >= joystick->nbuttons) { |
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
704 |
return 0; |
9884
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
705 |
} |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
706 |
if (state == joystick->buttons[button]) { |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
707 |
return 0; |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
708 |
} |
6145
964d13f789e2
Fixed bug 1337 - joystick crash due to heap corruption with btnx
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
709 |
|
7279
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
710 |
/* We ignore events if we don't have keyboard focus, except for button |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
711 |
* release. */ |
8903
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
712 |
if (SDL_PrivateJoystickShouldIgnoreEvent()) { |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
713 |
if (state == SDL_PRESSED) { |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
714 |
return 0; |
8e09eceea61e
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
715 |
} |
7279
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
716 |
} |
f7805b13b485
Joystick: Only send joy events when focused.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7191
diff
changeset
|
717 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
718 |
/* Update internal joystick state */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
719 |
joystick->buttons[button] = state; |
0 | 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:
1612
diff
changeset
|
721 |
/* Post the event, if desired */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
722 |
posted = 0; |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
723 |
#if !SDL_EVENTS_DISABLED |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
724 |
if (SDL_GetEventState(event.type) == SDL_ENABLE) { |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
725 |
event.jbutton.which = joystick->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:
1612
diff
changeset
|
726 |
event.jbutton.button = button; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
727 |
event.jbutton.state = state; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
728 |
posted = SDL_PushEvent(&event) == 1; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
729 |
} |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
730 |
#endif /* !SDL_EVENTS_DISABLED */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
731 |
return (posted); |
0 | 732 |
} |
733 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
734 |
void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
735 |
SDL_JoystickUpdate(void) |
0 | 736 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
737 |
SDL_Joystick *joystick; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
738 |
|
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
739 |
joystick = SDL_joysticks; |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
740 |
while (joystick) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
741 |
SDL_Joystick *joysticknext; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
742 |
/* save off the next pointer, the Update call may cause a joystick removed event |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
743 |
* and cause our joystick pointer to be freed |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
744 |
*/ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
745 |
joysticknext = joystick->next; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
746 |
|
6712
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
747 |
SDL_updating_joystick = joystick; |
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
748 |
|
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
749 |
SDL_SYS_JoystickUpdate(joystick); |
0 | 750 |
|
9433
bd062398b648
Cleanups in the joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
8920
diff
changeset
|
751 |
if (joystick->force_recentering) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
752 |
int i; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
753 |
|
6712
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
754 |
/* Tell the app that everything is centered/unpressed... */ |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
755 |
for (i = 0; i < joystick->naxes; i++) { |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
756 |
SDL_PrivateJoystickAxis(joystick, i, 0); |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
757 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
758 |
|
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
759 |
for (i = 0; i < joystick->nbuttons; i++) { |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
760 |
SDL_PrivateJoystickButton(joystick, i, 0); |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
761 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
762 |
|
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
763 |
for (i = 0; i < joystick->nhats; i++) { |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
764 |
SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED); |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
765 |
} |
6712
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
766 |
|
9433
bd062398b648
Cleanups in the joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
8920
diff
changeset
|
767 |
joystick->force_recentering = SDL_FALSE; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
768 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
769 |
|
6712
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
770 |
SDL_updating_joystick = NULL; |
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
771 |
|
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
772 |
/* If the joystick was closed while updating, free it here */ |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
773 |
if (joystick->ref_count <= 0) { |
6712
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
774 |
SDL_JoystickClose(joystick); |
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
775 |
} |
05f046f5886b
Fixed crashes in new joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
776 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
777 |
joystick = joysticknext; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
778 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
779 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
780 |
/* this needs to happen AFTER walking the joystick list above, so that any |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
781 |
dangling hardware data from removed devices can be free'd |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
782 |
*/ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
783 |
SDL_SYS_JoystickDetect(); |
0 | 784 |
} |
785 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
786 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
787 |
SDL_JoystickEventState(int state) |
0 | 788 |
{ |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
789 |
#if SDL_EVENTS_DISABLED |
6753
332c36fd0fd7
Only check SDL_SYS_JoystickNeedsPolling() if we know we don't need to poll for other reasons. This avoids a select() syscall on Linux if it isn't necessary.
Sam Lantinga <slouken@libsdl.org>
parents:
6748
diff
changeset
|
790 |
return SDL_DISABLE; |
0 | 791 |
#else |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
792 |
const Uint32 event_list[] = { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
793 |
SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION, |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
794 |
SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
795 |
}; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
796 |
unsigned int i; |
0 | 797 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
798 |
switch (state) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
799 |
case SDL_QUERY: |
6753
332c36fd0fd7
Only check SDL_SYS_JoystickNeedsPolling() if we know we don't need to poll for other reasons. This avoids a select() syscall on Linux if it isn't necessary.
Sam Lantinga <slouken@libsdl.org>
parents:
6748
diff
changeset
|
800 |
state = SDL_DISABLE; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
801 |
for (i = 0; i < SDL_arraysize(event_list); ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
802 |
state = SDL_EventState(event_list[i], SDL_QUERY); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
803 |
if (state == SDL_ENABLE) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
804 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
805 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
806 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
807 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
808 |
default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
809 |
for (i = 0; i < SDL_arraysize(event_list); ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
810 |
SDL_EventState(event_list[i], state); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
811 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
812 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
813 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
814 |
return (state); |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
815 |
#endif /* SDL_EVENTS_DISABLED */ |
0 | 816 |
} |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
817 |
|
6693
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6690
diff
changeset
|
818 |
/* return the guid for this index */ |
6738 | 819 |
SDL_JoystickGUID SDL_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:
6145
diff
changeset
|
820 |
{ |
7294
0923de98a63a
Fixed crash trying to get the GUID of an invalid joystick index
Sam Lantinga <slouken@libsdl.org>
parents:
7279
diff
changeset
|
821 |
if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) { |
0923de98a63a
Fixed crash trying to get the GUID of an invalid joystick index
Sam Lantinga <slouken@libsdl.org>
parents:
7279
diff
changeset
|
822 |
SDL_JoystickGUID emptyGUID; |
0923de98a63a
Fixed crash trying to get the GUID of an invalid joystick index
Sam Lantinga <slouken@libsdl.org>
parents:
7279
diff
changeset
|
823 |
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks()); |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
824 |
SDL_zero(emptyGUID); |
7294
0923de98a63a
Fixed crash trying to get the GUID of an invalid joystick index
Sam Lantinga <slouken@libsdl.org>
parents:
7279
diff
changeset
|
825 |
return emptyGUID; |
0923de98a63a
Fixed crash trying to get the GUID of an invalid joystick index
Sam Lantinga <slouken@libsdl.org>
parents:
7279
diff
changeset
|
826 |
} |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
827 |
return SDL_SYS_JoystickGetDeviceGUID(device_index); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
828 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
829 |
|
6693
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6690
diff
changeset
|
830 |
/* return the guid for this opened device */ |
6738 | 831 |
SDL_JoystickGUID SDL_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:
6145
diff
changeset
|
832 |
{ |
7789
a18c12b02b69
Check for NULL joystick in SDL_JoystickGetGUID()
Sam Lantinga <slouken@libsdl.org>
parents:
7731
diff
changeset
|
833 |
if (!SDL_PrivateJoystickValid(joystick)) { |
a18c12b02b69
Check for NULL joystick in SDL_JoystickGetGUID()
Sam Lantinga <slouken@libsdl.org>
parents:
7731
diff
changeset
|
834 |
SDL_JoystickGUID emptyGUID; |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
835 |
SDL_zero(emptyGUID); |
7789
a18c12b02b69
Check for NULL joystick in SDL_JoystickGetGUID()
Sam Lantinga <slouken@libsdl.org>
parents:
7731
diff
changeset
|
836 |
return emptyGUID; |
a18c12b02b69
Check for NULL joystick in SDL_JoystickGetGUID()
Sam Lantinga <slouken@libsdl.org>
parents:
7731
diff
changeset
|
837 |
} |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
838 |
return SDL_SYS_JoystickGetGUID(joystick); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
839 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
840 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
841 |
/* convert the guid to a printable string */ |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
842 |
void SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
843 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
844 |
static const char k_rgchHexToASCII[] = "0123456789abcdef"; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
845 |
int i; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
846 |
|
6748
80a6aac67ad9
Minor sanity checking and tweaks in SDL_JoystickGetGUIDString().
Ryan C. Gordon <icculus@icculus.org>
parents:
6738
diff
changeset
|
847 |
if ((pszGUID == NULL) || (cbGUID <= 0)) { |
80a6aac67ad9
Minor sanity checking and tweaks in SDL_JoystickGetGUIDString().
Ryan C. Gordon <icculus@icculus.org>
parents:
6738
diff
changeset
|
848 |
return; |
80a6aac67ad9
Minor sanity checking and tweaks in SDL_JoystickGetGUIDString().
Ryan C. Gordon <icculus@icculus.org>
parents:
6738
diff
changeset
|
849 |
} |
80a6aac67ad9
Minor sanity checking and tweaks in SDL_JoystickGetGUIDString().
Ryan C. Gordon <icculus@icculus.org>
parents:
6738
diff
changeset
|
850 |
|
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
851 |
for (i = 0; i < sizeof(guid.data) && i < (cbGUID-1)/2; i++) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
852 |
/* each input byte writes 2 ascii chars, and might write a null byte. */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
853 |
/* If we don't have room for next input byte, stop */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
854 |
unsigned char c = guid.data[i]; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
855 |
|
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
856 |
*pszGUID++ = k_rgchHexToASCII[c >> 4]; |
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
857 |
*pszGUID++ = k_rgchHexToASCII[c & 0x0F]; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
858 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
859 |
*pszGUID = '\0'; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
860 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
861 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
862 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
863 |
/*----------------------------------------------------------------------------- |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
864 |
* Purpose: Returns the 4 bit nibble for a hex character |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
865 |
* Input : c - |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
866 |
* Output : unsigned char |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
867 |
*-----------------------------------------------------------------------------*/ |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
868 |
static unsigned char nibble(char c) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
869 |
{ |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
870 |
if ((c >= '0') && (c <= '9')) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
871 |
return (unsigned char)(c - '0'); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
872 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
873 |
|
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
874 |
if ((c >= 'A') && (c <= 'F')) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
875 |
return (unsigned char)(c - 'A' + 0x0a); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
876 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
877 |
|
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
878 |
if ((c >= 'a') && (c <= 'f')) { |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
879 |
return (unsigned char)(c - 'a' + 0x0a); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
880 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
881 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
882 |
/* received an invalid character, and no real way to return an error */ |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
883 |
/* AssertMsg1(false, "Q_nibble invalid hex character '%c' ", c); */ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
884 |
return 0; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
885 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
886 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
887 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
888 |
/* convert the string version of a joystick guid to the struct */ |
6738 | 889 |
SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
890 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
891 |
SDL_JoystickGUID guid; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
892 |
int maxoutputbytes= sizeof(guid); |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
893 |
size_t len = SDL_strlen(pchGUID); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
894 |
Uint8 *p; |
7922
6ebd3a9aee8c
Fixed signed/unsigned warning
Sam Lantinga <slouken@libsdl.org>
parents:
7870
diff
changeset
|
895 |
size_t i; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
896 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
897 |
/* Make sure it's even */ |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
898 |
len = (len) & ~0x1; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
899 |
|
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
900 |
SDL_memset(&guid, 0x00, sizeof(guid)); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
901 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
902 |
p = (Uint8 *)&guid; |
8920
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
903 |
for (i = 0; (i < len) && ((p - (Uint8 *)&guid) < maxoutputbytes); i+=2, p++) { |
21ccd40c778a
Fixed bug 2553 - Add support to all XInput devices
Sam Lantinga <slouken@libsdl.org>
parents:
8903
diff
changeset
|
904 |
*p = (nibble(pchGUID[i]) << 4) | nibble(pchGUID[i+1]); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
905 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
906 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7086
diff
changeset
|
907 |
return guid; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
908 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
909 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6145
diff
changeset
|
910 |
|
9884
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
911 |
/* update the power level for this joystick */ |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
912 |
void SDL_PrivateJoystickBatteryLevel(SDL_Joystick * joystick, SDL_JoystickPowerLevel ePowerLevel) |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
913 |
{ |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
914 |
joystick->epowerlevel = ePowerLevel; |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
915 |
} |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
916 |
|
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
917 |
|
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
918 |
/* return its power level */ |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
919 |
SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick) |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
920 |
{ |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
921 |
if (!SDL_PrivateJoystickValid(joystick)) { |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
922 |
return (SDL_JOYSTICK_POWER_UNKNOWN); |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
923 |
} |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
924 |
return joystick->epowerlevel; |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
925 |
} |
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
926 |
|
26b595dea221
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.
Sam Lantinga <slouken@libsdl.org>
parents:
9876
diff
changeset
|
927 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
928 |
/* vi: set ts=4 sw=4 expandtab: */ |