Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
/*
|
2011-04-08 13:03:26 -07:00
|
|
|
Simple DirectMedia Layer
|
2018-01-03 10:03:25 -08:00
|
|
|
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2011-04-08 13:03:26 -07:00
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2011-04-08 13:03:26 -07:00
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2011-04-08 13:03:26 -07:00
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
*/
|
2013-11-24 23:56:17 -05:00
|
|
|
#include "../../SDL_internal.h"
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2006-04-14 04:46:47 +00:00
|
|
|
#ifdef SDL_JOYSTICK_IOKIT
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
#include "SDL_events.h"
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
#include "SDL_joystick.h"
|
2006-02-16 10:11:48 +00:00
|
|
|
#include "../SDL_sysjoystick.h"
|
|
|
|
#include "../SDL_joystick_c.h"
|
2008-08-25 09:55:03 +00:00
|
|
|
#include "SDL_sysjoystick_c.h"
|
2018-08-09 16:00:17 -07:00
|
|
|
#include "../hidapi/SDL_hidapijoystick_c.h"
|
2014-02-04 18:17:16 -05:00
|
|
|
#include "../../haptic/darwin/SDL_syshaptic_c.h" /* For haptic hot plugging */
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
|
2014-04-24 23:24:48 -04:00
|
|
|
#define SDL_JOYSTICK_RUNLOOP_MODE CFSTR("SDLJoystick")
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
#define CONVERT_MAGNITUDE(x) (((x)*10000) / 0x7FFF)
|
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
/* The base object of the HID Manager API */
|
|
|
|
static IOHIDManagerRef hidman = NULL;
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
|
|
|
/* Linked list of all available devices */
|
|
|
|
static recDevice *gpDeviceList = NULL;
|
2014-02-22 00:55:28 -05:00
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
void FreeRumbleEffectData(FFEFFECT *effect)
|
|
|
|
{
|
|
|
|
if (!effect) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SDL_free(effect->rgdwAxes);
|
|
|
|
SDL_free(effect->rglDirection);
|
|
|
|
SDL_free(effect->lpvTypeSpecificParams);
|
|
|
|
SDL_free(effect);
|
|
|
|
}
|
|
|
|
|
|
|
|
FFEFFECT *CreateRumbleEffectData(Sint16 magnitude, Uint32 duration_ms)
|
|
|
|
{
|
|
|
|
FFEFFECT *effect;
|
|
|
|
FFPERIODIC *periodic;
|
|
|
|
|
|
|
|
/* Create the effect */
|
|
|
|
effect = (FFEFFECT *)SDL_calloc(1, sizeof(*effect));
|
|
|
|
if (!effect) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
effect->dwSize = sizeof(*effect);
|
|
|
|
effect->dwGain = 10000;
|
|
|
|
effect->dwFlags = FFEFF_OBJECTOFFSETS;
|
|
|
|
effect->dwDuration = duration_ms * 1000; /* In microseconds. */
|
|
|
|
effect->dwTriggerButton = FFEB_NOTRIGGER;
|
|
|
|
|
|
|
|
effect->cAxes = 2;
|
|
|
|
effect->rgdwAxes = (DWORD *)SDL_calloc(effect->cAxes, sizeof(DWORD));
|
|
|
|
if (!effect->rgdwAxes) {
|
|
|
|
FreeRumbleEffectData(effect);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
effect->rglDirection = (LONG *)SDL_calloc(effect->cAxes, sizeof(LONG));
|
|
|
|
if (!effect->rglDirection) {
|
|
|
|
FreeRumbleEffectData(effect);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
effect->dwFlags |= FFEFF_CARTESIAN;
|
|
|
|
|
|
|
|
periodic = (FFPERIODIC *)SDL_calloc(1, sizeof(*periodic));
|
|
|
|
if (!periodic) {
|
|
|
|
FreeRumbleEffectData(effect);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
periodic->dwMagnitude = CONVERT_MAGNITUDE(magnitude);
|
|
|
|
periodic->dwPeriod = 1000000;
|
|
|
|
|
|
|
|
effect->cbTypeSpecificParams = sizeof(*periodic);
|
|
|
|
effect->lpvTypeSpecificParams = periodic;
|
|
|
|
|
|
|
|
return effect;
|
|
|
|
}
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2015-05-26 08:52:02 -07:00
|
|
|
static recDevice *GetDeviceForIndex(int device_index)
|
|
|
|
{
|
|
|
|
recDevice *device = gpDeviceList;
|
|
|
|
while (device) {
|
|
|
|
if (!device->removed) {
|
|
|
|
if (device_index == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
--device_index;
|
|
|
|
}
|
|
|
|
device = device->pNext;
|
|
|
|
}
|
|
|
|
return device;
|
|
|
|
}
|
2014-02-22 00:55:28 -05:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static void
|
2014-02-22 00:55:28 -05:00
|
|
|
FreeElementList(recElement *pElement)
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
{
|
2014-02-22 00:55:28 -05:00
|
|
|
while (pElement) {
|
|
|
|
recElement *pElementNext = pElement->pNext;
|
|
|
|
SDL_free(pElement);
|
|
|
|
pElement = pElementNext;
|
|
|
|
}
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
static recDevice *
|
|
|
|
FreeDevice(recDevice *removeDevice)
|
|
|
|
{
|
|
|
|
recDevice *pDeviceNext = NULL;
|
|
|
|
if (removeDevice) {
|
2014-04-24 23:24:48 -04:00
|
|
|
if (removeDevice->deviceRef) {
|
|
|
|
IOHIDDeviceUnscheduleFromRunLoop(removeDevice->deviceRef, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
|
|
|
|
removeDevice->deviceRef = NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
/* save next device prior to disposing of this device */
|
|
|
|
pDeviceNext = removeDevice->pNext;
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
if ( gpDeviceList == removeDevice ) {
|
|
|
|
gpDeviceList = pDeviceNext;
|
|
|
|
} else {
|
|
|
|
recDevice *device = gpDeviceList;
|
|
|
|
while (device->pNext != removeDevice) {
|
|
|
|
device = device->pNext;
|
|
|
|
}
|
|
|
|
device->pNext = pDeviceNext;
|
|
|
|
}
|
|
|
|
removeDevice->pNext = NULL;
|
|
|
|
|
|
|
|
/* free element lists */
|
|
|
|
FreeElementList(removeDevice->firstAxis);
|
|
|
|
FreeElementList(removeDevice->firstButton);
|
|
|
|
FreeElementList(removeDevice->firstHat);
|
|
|
|
|
|
|
|
SDL_free(removeDevice);
|
|
|
|
}
|
|
|
|
return pDeviceNext;
|
|
|
|
}
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2018-02-05 11:40:39 -08:00
|
|
|
static SDL_bool
|
|
|
|
GetHIDElementState(recDevice *pDevice, recElement *pElement, SInt32 *pValue)
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
{
|
2014-02-22 00:55:28 -05:00
|
|
|
SInt32 value = 0;
|
2018-02-05 11:40:39 -08:00
|
|
|
int returnValue = SDL_FALSE;
|
2014-02-22 00:55:28 -05:00
|
|
|
|
|
|
|
if (pDevice && pElement) {
|
|
|
|
IOHIDValueRef valueRef;
|
|
|
|
if (IOHIDDeviceGetValue(pDevice->deviceRef, pElement->elementRef, &valueRef) == kIOReturnSuccess) {
|
|
|
|
value = (SInt32) IOHIDValueGetIntegerValue(valueRef);
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* record min and max for auto calibration */
|
2014-02-22 00:55:28 -05:00
|
|
|
if (value < pElement->minReport) {
|
|
|
|
pElement->minReport = value;
|
|
|
|
}
|
|
|
|
if (value > pElement->maxReport) {
|
|
|
|
pElement->maxReport = value;
|
|
|
|
}
|
2018-02-05 11:40:39 -08:00
|
|
|
*pValue = value;
|
|
|
|
|
|
|
|
returnValue = SDL_TRUE;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-05 11:40:39 -08:00
|
|
|
return returnValue;
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-02-05 11:40:39 -08:00
|
|
|
static SDL_bool
|
|
|
|
GetHIDScaledCalibratedState(recDevice * pDevice, recElement * pElement, SInt32 min, SInt32 max, SInt32 *pValue)
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
{
|
2014-02-22 00:55:28 -05:00
|
|
|
const float deviceScale = max - min;
|
|
|
|
const float readScale = pElement->maxReport - pElement->minReport;
|
2018-02-05 11:40:39 -08:00
|
|
|
int returnValue = SDL_FALSE;
|
|
|
|
if (GetHIDElementState(pDevice, pElement, pValue))
|
|
|
|
{
|
|
|
|
if (readScale == 0) {
|
|
|
|
returnValue = SDL_TRUE; /* no scaling at all */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pValue = ((*pValue - pElement->minReport) * deviceScale / readScale) + min;
|
|
|
|
returnValue = SDL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnValue;
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static void
|
2014-02-22 00:55:28 -05:00
|
|
|
JoystickDeviceWasRemovedCallback(void *ctx, IOReturn result, void *sender)
|
2004-02-26 13:45:22 +00:00
|
|
|
{
|
2014-02-22 00:55:28 -05:00
|
|
|
recDevice *device = (recDevice *) ctx;
|
2015-03-24 13:52:01 -04:00
|
|
|
device->removed = SDL_TRUE;
|
2014-06-13 10:50:24 -07:00
|
|
|
device->deviceRef = NULL; // deviceRef was invalidated due to the remove
|
2018-08-09 16:00:17 -07:00
|
|
|
if (device->ffeffect_ref) {
|
|
|
|
FFDeviceReleaseEffect(device->ffdevice, device->ffeffect_ref);
|
|
|
|
device->ffeffect_ref = NULL;
|
|
|
|
}
|
|
|
|
if (device->ffeffect) {
|
|
|
|
FreeRumbleEffectData(device->ffeffect);
|
|
|
|
device->ffeffect = NULL;
|
|
|
|
}
|
|
|
|
if (device->ffdevice) {
|
|
|
|
FFReleaseDevice(device->ffdevice);
|
|
|
|
device->ffdevice = NULL;
|
|
|
|
device->ff_initialized = SDL_FALSE;
|
|
|
|
}
|
2014-02-04 18:17:16 -05:00
|
|
|
#if SDL_HAPTIC_IOKIT
|
2014-02-05 01:02:09 -05:00
|
|
|
MacHaptic_MaybeRemoveDevice(device->ffservice);
|
2014-02-04 18:17:16 -05:00
|
|
|
#endif
|
2015-05-26 08:52:02 -07:00
|
|
|
|
2016-08-26 12:18:08 -07:00
|
|
|
SDL_PrivateJoystickRemoved(device->instance_id);
|
2004-02-26 13:45:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
static void AddHIDElement(const void *value, void *parameter);
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
/* Call AddHIDElement() on all elements in an array of IOHIDElementRefs */
|
|
|
|
static void
|
|
|
|
AddHIDElements(CFArrayRef array, recDevice *pDevice)
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
{
|
2014-02-22 00:55:28 -05:00
|
|
|
const CFRange range = { 0, CFArrayGetCount(array) };
|
|
|
|
CFArrayApplyFunction(array, range, AddHIDElement, pDevice);
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:15:34 -05:00
|
|
|
static SDL_bool
|
|
|
|
ElementAlreadyAdded(const IOHIDElementCookie cookie, const recElement *listitem) {
|
|
|
|
while (listitem) {
|
|
|
|
if (listitem->cookie == cookie) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
listitem = listitem->pNext;
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
/* See if we care about this HID element, and if so, note it in our recDevice. */
|
2006-07-10 21:04:37 +00:00
|
|
|
static void
|
2014-02-22 00:55:28 -05:00
|
|
|
AddHIDElement(const void *value, void *parameter)
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
{
|
2014-02-22 00:55:28 -05:00
|
|
|
recDevice *pDevice = (recDevice *) parameter;
|
|
|
|
IOHIDElementRef refElement = (IOHIDElementRef) value;
|
|
|
|
const CFTypeID elementTypeID = refElement ? CFGetTypeID(refElement) : 0;
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
if (refElement && (elementTypeID == IOHIDElementGetTypeID())) {
|
2014-02-22 21:15:34 -05:00
|
|
|
const IOHIDElementCookie cookie = IOHIDElementGetCookie(refElement);
|
2014-02-22 00:55:28 -05:00
|
|
|
const uint32_t usagePage = IOHIDElementGetUsagePage(refElement);
|
|
|
|
const uint32_t usage = IOHIDElementGetUsage(refElement);
|
|
|
|
recElement *element = NULL;
|
|
|
|
recElement **headElement = NULL;
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* look at types of interest */
|
2014-02-22 00:55:28 -05:00
|
|
|
switch (IOHIDElementGetType(refElement)) {
|
|
|
|
case kIOHIDElementTypeInput_Misc:
|
|
|
|
case kIOHIDElementTypeInput_Button:
|
|
|
|
case kIOHIDElementTypeInput_Axis: {
|
2006-07-10 21:04:37 +00:00
|
|
|
switch (usagePage) { /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
|
2014-02-22 00:55:28 -05:00
|
|
|
case kHIDPage_GenericDesktop:
|
|
|
|
switch (usage) {
|
|
|
|
case kHIDUsage_GD_X:
|
|
|
|
case kHIDUsage_GD_Y:
|
|
|
|
case kHIDUsage_GD_Z:
|
|
|
|
case kHIDUsage_GD_Rx:
|
|
|
|
case kHIDUsage_GD_Ry:
|
|
|
|
case kHIDUsage_GD_Rz:
|
|
|
|
case kHIDUsage_GD_Slider:
|
|
|
|
case kHIDUsage_GD_Dial:
|
|
|
|
case kHIDUsage_GD_Wheel:
|
2014-02-22 21:15:34 -05:00
|
|
|
if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
|
|
|
|
element = (recElement *) SDL_calloc(1, sizeof (recElement));
|
|
|
|
if (element) {
|
|
|
|
pDevice->axes++;
|
|
|
|
headElement = &(pDevice->firstAxis);
|
|
|
|
}
|
2014-02-22 00:55:28 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kHIDUsage_GD_Hatswitch:
|
2014-02-22 21:15:34 -05:00
|
|
|
if (!ElementAlreadyAdded(cookie, pDevice->firstHat)) {
|
|
|
|
element = (recElement *) SDL_calloc(1, sizeof (recElement));
|
|
|
|
if (element) {
|
|
|
|
pDevice->hats++;
|
|
|
|
headElement = &(pDevice->firstHat);
|
|
|
|
}
|
2014-02-22 00:55:28 -05:00
|
|
|
}
|
|
|
|
break;
|
2015-11-12 22:44:32 -04:00
|
|
|
case kHIDUsage_GD_DPadUp:
|
|
|
|
case kHIDUsage_GD_DPadDown:
|
|
|
|
case kHIDUsage_GD_DPadRight:
|
|
|
|
case kHIDUsage_GD_DPadLeft:
|
2015-12-28 15:44:09 -04:00
|
|
|
case kHIDUsage_GD_Start:
|
|
|
|
case kHIDUsage_GD_Select:
|
2016-08-08 12:17:53 -07:00
|
|
|
case kHIDUsage_GD_SystemMainMenu:
|
2015-11-12 22:44:32 -04:00
|
|
|
if (!ElementAlreadyAdded(cookie, pDevice->firstButton)) {
|
|
|
|
element = (recElement *) SDL_calloc(1, sizeof (recElement));
|
|
|
|
if (element) {
|
|
|
|
pDevice->buttons++;
|
|
|
|
headElement = &(pDevice->firstButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2014-02-22 00:55:28 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kHIDPage_Simulation:
|
|
|
|
switch (usage) {
|
|
|
|
case kHIDUsage_Sim_Rudder:
|
|
|
|
case kHIDUsage_Sim_Throttle:
|
2017-01-25 22:22:05 -08:00
|
|
|
case kHIDUsage_Sim_Accelerator:
|
|
|
|
case kHIDUsage_Sim_Brake:
|
2014-02-22 21:15:34 -05:00
|
|
|
if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
|
|
|
|
element = (recElement *) SDL_calloc(1, sizeof (recElement));
|
|
|
|
if (element) {
|
|
|
|
pDevice->axes++;
|
|
|
|
headElement = &(pDevice->firstAxis);
|
|
|
|
}
|
2014-02-22 00:55:28 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kHIDPage_Button:
|
2015-11-12 22:44:32 -04:00
|
|
|
case kHIDPage_Consumer: /* e.g. 'pause' button on Steelseries MFi gamepads. */
|
2014-02-22 21:15:34 -05:00
|
|
|
if (!ElementAlreadyAdded(cookie, pDevice->firstButton)) {
|
|
|
|
element = (recElement *) SDL_calloc(1, sizeof (recElement));
|
|
|
|
if (element) {
|
|
|
|
pDevice->buttons++;
|
|
|
|
headElement = &(pDevice->firstButton);
|
|
|
|
}
|
2014-02-22 00:55:28 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-22 00:55:28 -05:00
|
|
|
break;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
case kIOHIDElementTypeCollection: {
|
|
|
|
CFArrayRef array = IOHIDElementGetChildren(refElement);
|
|
|
|
if (array) {
|
|
|
|
AddHIDElements(array, pDevice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
if (element && headElement) { /* add to list */
|
|
|
|
recElement *elementPrevious = NULL;
|
|
|
|
recElement *elementCurrent = *headElement;
|
|
|
|
while (elementCurrent && usage >= elementCurrent->usage) {
|
|
|
|
elementPrevious = elementCurrent;
|
|
|
|
elementCurrent = elementCurrent->pNext;
|
|
|
|
}
|
|
|
|
if (elementPrevious) {
|
|
|
|
elementPrevious->pNext = element;
|
|
|
|
} else {
|
|
|
|
*headElement = element;
|
|
|
|
}
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
element->elementRef = refElement;
|
|
|
|
element->usagePage = usagePage;
|
|
|
|
element->usage = usage;
|
|
|
|
element->pNext = elementCurrent;
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
element->minReport = element->min = (SInt32) IOHIDElementGetLogicalMin(refElement);
|
|
|
|
element->maxReport = element->max = (SInt32) IOHIDElementGetLogicalMax(refElement);
|
2014-02-22 21:15:34 -05:00
|
|
|
element->cookie = IOHIDElementGetCookie(refElement);
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
pDevice->elements++;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
static SDL_bool
|
|
|
|
GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
{
|
2016-11-10 17:19:34 -08:00
|
|
|
Sint32 vendor = 0;
|
|
|
|
Sint32 product = 0;
|
|
|
|
Sint32 version = 0;
|
2014-02-22 00:55:28 -05:00
|
|
|
CFTypeRef refCF = NULL;
|
|
|
|
CFArrayRef array = NULL;
|
2016-11-11 04:06:00 -07:00
|
|
|
Uint16 *guid16 = (Uint16 *)pDevice->guid.data;
|
2013-03-25 11:38:30 -07:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
/* get usage page and usage */
|
|
|
|
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDPrimaryUsagePageKey));
|
|
|
|
if (refCF) {
|
|
|
|
CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->usagePage);
|
|
|
|
}
|
|
|
|
if (pDevice->usagePage != kHIDPage_GenericDesktop) {
|
|
|
|
return SDL_FALSE; /* Filter device list to non-keyboard/mouse stuff */
|
|
|
|
}
|
2013-03-25 11:38:30 -07:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDPrimaryUsageKey));
|
|
|
|
if (refCF) {
|
|
|
|
CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->usage);
|
|
|
|
}
|
2012-11-26 16:37:54 -08:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
if ((pDevice->usage != kHIDUsage_GD_Joystick &&
|
|
|
|
pDevice->usage != kHIDUsage_GD_GamePad &&
|
|
|
|
pDevice->usage != kHIDUsage_GD_MultiAxisController)) {
|
|
|
|
return SDL_FALSE; /* Filter device list to non-keyboard/mouse stuff */
|
|
|
|
}
|
2013-03-25 11:38:30 -07:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
pDevice->deviceRef = hidDevice;
|
2013-03-25 11:38:30 -07:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
/* get device name */
|
|
|
|
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductKey));
|
|
|
|
if (!refCF) {
|
|
|
|
/* Maybe we can't get "AwesomeJoystick2000", but we can get "Logitech"? */
|
|
|
|
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
|
|
|
|
}
|
|
|
|
if ((!refCF) || (!CFStringGetCString(refCF, pDevice->product, sizeof (pDevice->product), kCFStringEncodingUTF8))) {
|
|
|
|
SDL_strlcpy(pDevice->product, "Unidentified joystick", sizeof (pDevice->product));
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVendorIDKey));
|
|
|
|
if (refCF) {
|
2016-11-10 17:19:34 -08:00
|
|
|
CFNumberGetValue(refCF, kCFNumberSInt32Type, &vendor);
|
2014-02-22 00:55:28 -05:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductIDKey));
|
|
|
|
if (refCF) {
|
2016-11-10 17:19:34 -08:00
|
|
|
CFNumberGetValue(refCF, kCFNumberSInt32Type, &product);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2016-11-10 17:19:34 -08:00
|
|
|
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVersionNumberKey));
|
|
|
|
if (refCF) {
|
|
|
|
CFNumberGetValue(refCF, kCFNumberSInt32Type, &version);
|
|
|
|
}
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
#ifdef SDL_JOYSTICK_HIDAPI
|
|
|
|
if (HIDAPI_IsDevicePresent(vendor, product)) {
|
|
|
|
/* The HIDAPI driver is taking care of this device */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-11 04:06:00 -07:00
|
|
|
SDL_memset(pDevice->guid.data, 0, sizeof(pDevice->guid.data));
|
2016-11-10 17:19:34 -08:00
|
|
|
|
|
|
|
if (vendor && product) {
|
2018-08-09 16:00:17 -07:00
|
|
|
*guid16++ = SDL_SwapLE16(SDL_HARDWARE_BUS_USB);
|
2016-11-10 17:19:34 -08:00
|
|
|
*guid16++ = 0;
|
|
|
|
*guid16++ = SDL_SwapLE16((Uint16)vendor);
|
|
|
|
*guid16++ = 0;
|
|
|
|
*guid16++ = SDL_SwapLE16((Uint16)product);
|
|
|
|
*guid16++ = 0;
|
|
|
|
*guid16++ = SDL_SwapLE16((Uint16)version);
|
|
|
|
*guid16++ = 0;
|
|
|
|
} else {
|
2018-08-09 16:00:17 -07:00
|
|
|
*guid16++ = SDL_SwapLE16(SDL_HARDWARE_BUS_BLUETOOTH);
|
2014-02-22 00:55:28 -05:00
|
|
|
*guid16++ = 0;
|
|
|
|
SDL_strlcpy((char*)guid16, pDevice->product, sizeof(pDevice->guid.data) - 4);
|
|
|
|
}
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
array = IOHIDDeviceCopyMatchingElements(hidDevice, NULL, kIOHIDOptionsTypeNone);
|
|
|
|
if (array) {
|
|
|
|
AddHIDElements(array, pDevice);
|
|
|
|
CFRelease(array);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2014-02-22 00:55:28 -05:00
|
|
|
|
|
|
|
return SDL_TRUE;
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-31 11:21:10 -04:00
|
|
|
static SDL_bool
|
|
|
|
JoystickAlreadyKnown(IOHIDDeviceRef ioHIDDeviceObject)
|
|
|
|
{
|
|
|
|
recDevice *i;
|
|
|
|
for (i = gpDeviceList; i != NULL; i = i->pNext) {
|
|
|
|
if (i->deviceRef == ioHIDDeviceObject) {
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static void
|
2014-02-22 00:55:28 -05:00
|
|
|
JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject)
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
{
|
2014-08-31 11:21:10 -04:00
|
|
|
recDevice *device;
|
2015-05-26 08:52:02 -07:00
|
|
|
int device_index = 0;
|
2016-05-21 00:20:52 -03:00
|
|
|
io_service_t ioservice;
|
2014-08-31 11:21:10 -04:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
if (res != kIOReturnSuccess) {
|
|
|
|
return;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2014-08-31 11:21:10 -04:00
|
|
|
if (JoystickAlreadyKnown(ioHIDDeviceObject)) {
|
|
|
|
return; /* IOKit sent us a duplicate. */
|
|
|
|
}
|
|
|
|
|
|
|
|
device = (recDevice *) SDL_calloc(1, sizeof(recDevice));
|
2014-02-22 00:55:28 -05:00
|
|
|
if (!device) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
if (!GetDeviceInfo(ioHIDDeviceObject, device)) {
|
|
|
|
SDL_free(device);
|
|
|
|
return; /* not a device we care about, probably. */
|
2013-05-18 14:17:52 -07:00
|
|
|
}
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
if (SDL_ShouldIgnoreJoystick(device->product, device->guid)) {
|
2017-08-09 11:59:29 -07:00
|
|
|
SDL_free(device);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
/* Get notified when this device is disconnected. */
|
|
|
|
IOHIDDeviceRegisterRemovalCallback(ioHIDDeviceObject, JoystickDeviceWasRemovedCallback, device);
|
2014-04-24 23:24:48 -04:00
|
|
|
IOHIDDeviceScheduleWithRunLoop(ioHIDDeviceObject, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
|
2014-02-22 00:55:28 -05:00
|
|
|
|
2013-10-06 20:39:23 -07:00
|
|
|
/* Allocate an instance ID for this device */
|
2018-08-09 16:00:17 -07:00
|
|
|
device->instance_id = SDL_GetNextJoystickInstanceID();
|
2013-10-06 20:39:23 -07:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
/* We have to do some storage of the io_service_t for SDL_HapticOpenFromJoystick */
|
2016-05-21 00:20:52 -03:00
|
|
|
ioservice = IOHIDDeviceGetService(ioHIDDeviceObject);
|
|
|
|
if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK)) {
|
|
|
|
device->ffservice = ioservice;
|
2018-08-09 16:00:17 -07:00
|
|
|
#if SDL_HAPTIC_IOKIT
|
2016-05-21 00:20:52 -03:00
|
|
|
MacHaptic_MaybeAddDevice(ioservice);
|
2015-05-26 12:52:28 -04:00
|
|
|
#endif
|
2018-08-09 16:00:17 -07:00
|
|
|
}
|
2013-05-18 14:17:52 -07:00
|
|
|
|
|
|
|
/* Add device to the end of the list */
|
2014-07-07 12:48:25 -07:00
|
|
|
if ( !gpDeviceList ) {
|
2013-05-18 14:17:52 -07:00
|
|
|
gpDeviceList = device;
|
2014-07-07 12:48:25 -07:00
|
|
|
} else {
|
2013-05-18 14:17:52 -07:00
|
|
|
recDevice *curdevice;
|
|
|
|
|
|
|
|
curdevice = gpDeviceList;
|
2014-07-07 12:48:25 -07:00
|
|
|
while ( curdevice->pNext ) {
|
2015-05-26 08:52:02 -07:00
|
|
|
++device_index;
|
2013-05-18 14:17:52 -07:00
|
|
|
curdevice = curdevice->pNext;
|
|
|
|
}
|
|
|
|
curdevice->pNext = device;
|
2015-09-13 11:29:45 -04:00
|
|
|
++device_index; /* bump by one since we counted by pNext. */
|
2013-05-18 14:17:52 -07:00
|
|
|
}
|
2015-05-26 08:52:02 -07:00
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
SDL_PrivateJoystickAdded(device->instance_id);
|
2014-02-22 00:55:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static SDL_bool
|
|
|
|
ConfigHIDManager(CFArrayRef matchingArray)
|
|
|
|
{
|
|
|
|
CFRunLoopRef runloop = CFRunLoopGetCurrent();
|
|
|
|
|
|
|
|
if (IOHIDManagerOpen(hidman, kIOHIDOptionsTypeNone) != kIOReturnSuccess) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
2015-02-19 23:52:10 -05:00
|
|
|
IOHIDManagerSetDeviceMatchingMultiple(hidman, matchingArray);
|
2014-02-22 00:55:28 -05:00
|
|
|
IOHIDManagerRegisterDeviceMatchingCallback(hidman, JoystickDeviceWasAddedCallback, NULL);
|
2014-04-24 23:24:48 -04:00
|
|
|
IOHIDManagerScheduleWithRunLoop(hidman, runloop, SDL_JOYSTICK_RUNLOOP_MODE);
|
2014-02-22 00:55:28 -05:00
|
|
|
|
2014-04-24 23:24:48 -04:00
|
|
|
while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
|
2014-02-22 00:55:28 -05:00
|
|
|
/* no-op. Callback fires once per existing device. */
|
|
|
|
}
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2014-04-24 23:24:48 -04:00
|
|
|
/* future hotplug events will come through SDL_JOYSTICK_RUNLOOP_MODE now. */
|
2014-02-22 00:55:28 -05:00
|
|
|
|
|
|
|
return SDL_TRUE; /* good to go. */
|
2012-11-26 16:37:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
static CFDictionaryRef
|
|
|
|
CreateHIDDeviceMatchDictionary(const UInt32 page, const UInt32 usage, int *okay)
|
2012-11-26 16:37:54 -08:00
|
|
|
{
|
2014-02-22 00:55:28 -05:00
|
|
|
CFDictionaryRef retval = NULL;
|
|
|
|
CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
|
|
|
|
CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
|
|
|
|
const void *keys[2] = { (void *) CFSTR(kIOHIDDeviceUsagePageKey), (void *) CFSTR(kIOHIDDeviceUsageKey) };
|
|
|
|
const void *vals[2] = { (void *) pageNumRef, (void *) usageNumRef };
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
if (pageNumRef && usageNumRef) {
|
|
|
|
retval = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pageNumRef) {
|
|
|
|
CFRelease(pageNumRef);
|
|
|
|
}
|
|
|
|
if (usageNumRef) {
|
2014-02-23 01:24:46 -05:00
|
|
|
CFRelease(usageNumRef);
|
2014-02-22 00:55:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!retval) {
|
|
|
|
*okay = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SDL_bool
|
|
|
|
CreateHIDManager(void)
|
|
|
|
{
|
|
|
|
SDL_bool retval = SDL_FALSE;
|
|
|
|
int okay = 1;
|
|
|
|
const void *vals[] = {
|
|
|
|
(void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick, &okay),
|
|
|
|
(void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad, &okay),
|
|
|
|
(void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController, &okay),
|
|
|
|
};
|
|
|
|
const size_t numElements = SDL_arraysize(vals);
|
|
|
|
CFArrayRef array = okay ? CFArrayCreate(kCFAllocatorDefault, vals, numElements, &kCFTypeArrayCallBacks) : NULL;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < numElements; i++) {
|
|
|
|
if (vals[i]) {
|
|
|
|
CFRelease((CFTypeRef) vals[i]);
|
2013-05-18 14:17:52 -07:00
|
|
|
}
|
|
|
|
}
|
2014-02-22 00:55:28 -05:00
|
|
|
|
|
|
|
if (array) {
|
|
|
|
hidman = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
|
|
|
|
if (hidman != NULL) {
|
|
|
|
retval = ConfigHIDManager(array);
|
|
|
|
}
|
|
|
|
CFRelease(array);
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
2012-11-26 16:37:54 -08:00
|
|
|
}
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2012-11-26 16:37:54 -08:00
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
static int
|
|
|
|
DARWIN_JoystickInit(void)
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
if (gpDeviceList) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("Joystick: Device list already inited.");
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
if (!CreateHIDManager()) {
|
|
|
|
return SDL_SetError("Joystick: Couldn't initialize HID Manager");
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2012-11-26 16:37:54 -08:00
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
return 0;
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
static int
|
|
|
|
DARWIN_JoystickGetCount(void)
|
2012-11-27 00:58:12 -08:00
|
|
|
{
|
2013-05-18 14:17:52 -07:00
|
|
|
recDevice *device = gpDeviceList;
|
2012-11-27 00:58:12 -08:00
|
|
|
int nJoySticks = 0;
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
while (device) {
|
|
|
|
if (!device->removed) {
|
2013-05-18 14:17:52 -07:00
|
|
|
nJoySticks++;
|
2014-02-22 00:55:28 -05:00
|
|
|
}
|
2012-11-27 00:58:12 -08:00
|
|
|
device = device->pNext;
|
2013-05-18 14:17:52 -07:00
|
|
|
}
|
2012-11-27 00:58:12 -08:00
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
return nJoySticks;
|
2012-11-27 00:58:12 -08:00
|
|
|
}
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
static void
|
|
|
|
DARWIN_JoystickDetect(void)
|
2012-11-27 00:58:12 -08:00
|
|
|
{
|
2015-05-26 08:52:02 -07:00
|
|
|
recDevice *device = gpDeviceList;
|
|
|
|
while (device) {
|
|
|
|
if (device->removed) {
|
|
|
|
device = FreeDevice(device);
|
|
|
|
} else {
|
|
|
|
device = device->pNext;
|
2013-05-18 14:17:52 -07:00
|
|
|
}
|
|
|
|
}
|
2015-03-02 11:43:24 -08:00
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
/* run this after the checks above so we don't set device->removed and delete the device before
|
|
|
|
DARWIN_JoystickUpdate can run to clean up the SDL_Joystick object that owns this device */
|
|
|
|
while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
|
|
|
|
/* no-op. Pending callbacks will fire in CFRunLoopRunInMode(). */
|
|
|
|
}
|
2012-11-27 00:58:12 -08:00
|
|
|
}
|
|
|
|
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
/* Function to get the device-dependent name of a joystick */
|
2006-07-10 21:04:37 +00:00
|
|
|
const char *
|
2018-08-09 16:00:17 -07:00
|
|
|
DARWIN_JoystickGetDeviceName(int device_index)
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
{
|
2015-05-26 08:52:02 -07:00
|
|
|
recDevice *device = GetDeviceForIndex(device_index);
|
|
|
|
return device ? device->product : "UNKNOWN";
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
static SDL_JoystickGUID
|
|
|
|
DARWIN_JoystickGetDeviceGUID( int device_index )
|
|
|
|
{
|
|
|
|
recDevice *device = GetDeviceForIndex(device_index);
|
|
|
|
SDL_JoystickGUID guid;
|
|
|
|
if (device) {
|
|
|
|
guid = device->guid;
|
|
|
|
} else {
|
|
|
|
SDL_zero(guid);
|
|
|
|
}
|
|
|
|
return guid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SDL_JoystickID
|
|
|
|
DARWIN_JoystickGetDeviceInstanceID(int device_index)
|
2012-11-27 00:58:12 -08:00
|
|
|
{
|
2015-05-26 08:52:02 -07:00
|
|
|
recDevice *device = GetDeviceForIndex(device_index);
|
|
|
|
return device ? device->instance_id : 0;
|
2012-11-27 00:58:12 -08:00
|
|
|
}
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
static int
|
|
|
|
DARWIN_JoystickOpen(SDL_Joystick * joystick, int device_index)
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
{
|
2015-05-26 08:52:02 -07:00
|
|
|
recDevice *device = GetDeviceForIndex(device_index);
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
joystick->instance_id = device->instance_id;
|
2012-11-26 22:27:49 -08:00
|
|
|
joystick->hwdata = device;
|
2013-05-18 14:17:52 -07:00
|
|
|
joystick->name = device->product;
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
joystick->naxes = device->axes;
|
|
|
|
joystick->nhats = device->hats;
|
|
|
|
joystick->nballs = 0;
|
|
|
|
joystick->nbuttons = device->buttons;
|
2006-07-10 21:04:37 +00:00
|
|
|
return 0;
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
static SDL_bool
|
|
|
|
DARWIN_JoystickIsAttached(SDL_Joystick * joystick)
|
2012-11-26 16:37:54 -08:00
|
|
|
{
|
2015-03-24 13:52:01 -04:00
|
|
|
return joystick->hwdata != NULL;
|
2012-11-26 16:37:54 -08:00
|
|
|
}
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
/*
|
|
|
|
* Like strerror but for force feedback errors.
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
*/
|
2018-08-09 16:00:17 -07:00
|
|
|
static const char *
|
|
|
|
FFStrError(unsigned int err)
|
|
|
|
{
|
|
|
|
switch (err) {
|
|
|
|
case FFERR_DEVICEFULL:
|
|
|
|
return "device full";
|
|
|
|
/* This should be valid, but for some reason isn't defined... */
|
|
|
|
/* case FFERR_DEVICENOTREG:
|
|
|
|
return "device not registered"; */
|
|
|
|
case FFERR_DEVICEPAUSED:
|
|
|
|
return "device paused";
|
|
|
|
case FFERR_DEVICERELEASED:
|
|
|
|
return "device released";
|
|
|
|
case FFERR_EFFECTPLAYING:
|
|
|
|
return "effect playing";
|
|
|
|
case FFERR_EFFECTTYPEMISMATCH:
|
|
|
|
return "effect type mismatch";
|
|
|
|
case FFERR_EFFECTTYPENOTSUPPORTED:
|
|
|
|
return "effect type not supported";
|
|
|
|
case FFERR_GENERIC:
|
|
|
|
return "undetermined error";
|
|
|
|
case FFERR_HASEFFECTS:
|
|
|
|
return "device has effects";
|
|
|
|
case FFERR_INCOMPLETEEFFECT:
|
|
|
|
return "incomplete effect";
|
|
|
|
case FFERR_INTERNAL:
|
|
|
|
return "internal fault";
|
|
|
|
case FFERR_INVALIDDOWNLOADID:
|
|
|
|
return "invalid download id";
|
|
|
|
case FFERR_INVALIDPARAM:
|
|
|
|
return "invalid parameter";
|
|
|
|
case FFERR_MOREDATA:
|
|
|
|
return "more data";
|
|
|
|
case FFERR_NOINTERFACE:
|
|
|
|
return "interface not supported";
|
|
|
|
case FFERR_NOTDOWNLOADED:
|
|
|
|
return "effect is not downloaded";
|
|
|
|
case FFERR_NOTINITIALIZED:
|
|
|
|
return "object has not been initialized";
|
|
|
|
case FFERR_OUTOFMEMORY:
|
|
|
|
return "out of memory";
|
|
|
|
case FFERR_UNPLUGGED:
|
|
|
|
return "device is unplugged";
|
|
|
|
case FFERR_UNSUPPORTED:
|
|
|
|
return "function call unsupported";
|
|
|
|
case FFERR_UNSUPPORTEDAXIS:
|
|
|
|
return "axis unsupported";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "unknown error";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
DARWIN_JoystickInitRumble(recDevice *device, Sint16 magnitude, Uint32 duration_ms)
|
|
|
|
{
|
|
|
|
HRESULT result;
|
|
|
|
|
|
|
|
if (!device->ffdevice) {
|
|
|
|
result = FFCreateDevice(device->ffservice, &device->ffdevice);
|
|
|
|
if (result != FF_OK) {
|
|
|
|
return SDL_SetError("Unable to create force feedback device from service: %s", FFStrError(result));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset and then enable actuators */
|
|
|
|
result = FFDeviceSendForceFeedbackCommand(device->ffdevice, FFSFFC_RESET);
|
|
|
|
if (result != FF_OK) {
|
|
|
|
return SDL_SetError("Unable to reset force feedback device: %s", FFStrError(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
result = FFDeviceSendForceFeedbackCommand(device->ffdevice, FFSFFC_SETACTUATORSON);
|
|
|
|
if (result != FF_OK) {
|
|
|
|
return SDL_SetError("Unable to enable force feedback actuators: %s", FFStrError(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the effect */
|
|
|
|
device->ffeffect = CreateRumbleEffectData(magnitude, duration_ms);
|
|
|
|
if (!device->ffeffect) {
|
|
|
|
return SDL_OutOfMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
result = FFDeviceCreateEffect(device->ffdevice, kFFEffectType_Sine_ID,
|
|
|
|
device->ffeffect, &device->ffeffect_ref);
|
|
|
|
if (result != FF_OK) {
|
|
|
|
return SDL_SetError("Haptic: Unable to create effect: %s", FFStrError(result));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
DARWIN_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
|
|
|
|
{
|
|
|
|
HRESULT result;
|
|
|
|
recDevice *device = joystick->hwdata;
|
|
|
|
|
|
|
|
/* Scale and average the two rumble strengths */
|
|
|
|
Sint16 magnitude = (Sint16)(((low_frequency_rumble / 2) + (high_frequency_rumble / 2)) / 2);
|
|
|
|
|
|
|
|
if (!device->ffservice) {
|
|
|
|
return SDL_Unsupported();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device->ff_initialized) {
|
|
|
|
FFPERIODIC *periodic = ((FFPERIODIC *)device->ffeffect->lpvTypeSpecificParams);
|
|
|
|
device->ffeffect->dwDuration = duration_ms * 1000; /* In microseconds. */
|
|
|
|
periodic->dwMagnitude = CONVERT_MAGNITUDE(magnitude);
|
|
|
|
|
|
|
|
result = FFEffectSetParameters(device->ffeffect_ref, device->ffeffect,
|
|
|
|
(FFEP_DURATION | FFEP_TYPESPECIFICPARAMS));
|
|
|
|
if (result != FF_OK) {
|
|
|
|
return SDL_SetError("Unable to update rumble effect: %s", FFStrError(result));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (DARWIN_JoystickInitRumble(device, magnitude, duration_ms) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
device->ff_initialized = SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = FFEffectStart(device->ffeffect_ref, 1, 0);
|
|
|
|
if (result != FF_OK) {
|
|
|
|
return SDL_SetError("Unable to run the rumble effect: %s", FFStrError(result));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DARWIN_JoystickUpdate(SDL_Joystick * joystick)
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
{
|
2013-05-18 14:17:52 -07:00
|
|
|
recDevice *device = joystick->hwdata;
|
2006-07-10 21:04:37 +00:00
|
|
|
recElement *element;
|
2007-12-29 19:45:09 +00:00
|
|
|
SInt32 value, range;
|
2006-07-10 21:04:37 +00:00
|
|
|
int i;
|
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
if (!device) {
|
2013-05-18 14:17:52 -07:00
|
|
|
return;
|
2014-02-22 00:55:28 -05:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2012-11-26 16:37:54 -08:00
|
|
|
if (device->removed) { /* device was unplugged; ignore it. */
|
2015-03-24 13:52:01 -04:00
|
|
|
if (joystick->hwdata) {
|
|
|
|
joystick->force_recentering = SDL_TRUE;
|
|
|
|
joystick->hwdata = NULL;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
element = device->firstAxis;
|
|
|
|
i = 0;
|
2018-02-05 11:40:39 -08:00
|
|
|
|
|
|
|
int goodRead = SDL_FALSE;
|
2006-07-10 21:04:37 +00:00
|
|
|
while (element) {
|
2018-02-05 11:40:39 -08:00
|
|
|
goodRead = GetHIDScaledCalibratedState(device, element, -32768, 32767, &value);
|
|
|
|
if (goodRead) {
|
|
|
|
SDL_PrivateJoystickAxis(joystick, i, value);
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
element = element->pNext;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
element = device->firstButton;
|
|
|
|
i = 0;
|
|
|
|
while (element) {
|
2018-02-05 11:40:39 -08:00
|
|
|
goodRead = GetHIDElementState(device, element, &value);
|
|
|
|
if (goodRead) {
|
|
|
|
if (value > 1) { /* handle pressure-sensitive buttons */
|
|
|
|
value = 1;
|
|
|
|
}
|
|
|
|
SDL_PrivateJoystickButton(joystick, i, value);
|
2014-02-22 00:55:28 -05:00
|
|
|
}
|
2018-02-05 11:40:39 -08:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
element = element->pNext;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
element = device->firstHat;
|
|
|
|
i = 0;
|
2018-02-05 11:40:39 -08:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
while (element) {
|
|
|
|
Uint8 pos = 0;
|
|
|
|
|
2007-12-29 19:45:09 +00:00
|
|
|
range = (element->max - element->min + 1);
|
2018-02-05 11:40:39 -08:00
|
|
|
goodRead = GetHIDElementState(device, element, &value);
|
|
|
|
if (goodRead) {
|
|
|
|
value -= element->min;
|
|
|
|
if (range == 4) { /* 4 position hatswitch - scale up value */
|
|
|
|
value *= 2;
|
|
|
|
} else if (range != 8) { /* Neither a 4 nor 8 positions - fall back to default position (centered) */
|
|
|
|
value = -1;
|
|
|
|
}
|
|
|
|
switch (value) {
|
|
|
|
case 0:
|
|
|
|
pos = SDL_HAT_UP;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pos = SDL_HAT_RIGHTUP;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pos = SDL_HAT_RIGHT;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pos = SDL_HAT_RIGHTDOWN;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
pos = SDL_HAT_DOWN;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
pos = SDL_HAT_LEFTDOWN;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
pos = SDL_HAT_LEFT;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
pos = SDL_HAT_LEFTUP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Every other value is mapped to center. We do that because some
|
|
|
|
* joysticks use 8 and some 15 for this value, and apparently
|
|
|
|
* there are even more variants out there - so we try to be generous.
|
|
|
|
*/
|
|
|
|
pos = SDL_HAT_CENTERED;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-22 00:55:28 -05:00
|
|
|
|
2018-02-05 11:40:39 -08:00
|
|
|
SDL_PrivateJoystickHat(joystick, i, pos);
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
element = element->pNext;
|
|
|
|
++i;
|
|
|
|
}
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
static void
|
|
|
|
DARWIN_JoystickClose(SDL_Joystick * joystick)
|
2013-05-18 14:17:52 -07:00
|
|
|
{
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
static void
|
|
|
|
DARWIN_JoystickQuit(void)
|
Date: Sat, 8 Sep 2001 04:42:23 +0200
From: Max Horn <max@quendi.de>
Subject: SDL/OSX: Joystick; Better key handling
I just finished implementing improved keyhandling for OS X (in fact
the code should be easily ported to the "normal" MacOS part of SDL, I
just had no chance yet). Works like this:
First init the mapping table statically like before. Them, it queries
the OS for the "official" key table, then iterates over all 127
scancode and gets the associates ascii code. It ignores everythng
below 32 (has to, as it would lead to many problems if we did not...
e.g. both ESC and NUM LOCk produce an ascii code 27 on my keyboard),
and all stuff above 127 is mapped to SDLK_WORLD_* simply in the order
it is encountered.
In addition, caps lock is now working, too.
The code work flawless for me, but since I only have one keyboard, I
may have not encountered some serious problem... but I am pretty
confident that it is better than the old code in most cases.
The joystick driver works fine for me, too. I think it can be added
to CVS already. It would simply be helpful if more people would test
it. Hm, I wonder if Maelstrom or GLTron has Joystick support? That
would be a wonderful test application :)
I also took the liberty of modifying some text files like BUGS,
README.CVS, README.MacOSX (which now contains the OS X docs I long
promised)
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40173
2001-09-11 19:00:18 +00:00
|
|
|
{
|
2014-02-22 00:55:28 -05:00
|
|
|
while (FreeDevice(gpDeviceList)) {
|
|
|
|
/* spin */
|
|
|
|
}
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2014-02-22 00:55:28 -05:00
|
|
|
if (hidman) {
|
2014-04-24 23:24:48 -04:00
|
|
|
IOHIDManagerUnscheduleFromRunLoop(hidman, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
|
2014-02-22 00:55:28 -05:00
|
|
|
IOHIDManagerClose(hidman, kIOHIDOptionsTypeNone);
|
|
|
|
CFRelease(hidman);
|
|
|
|
hidman = NULL;
|
2013-05-18 14:17:52 -07:00
|
|
|
}
|
2012-11-26 16:37:54 -08:00
|
|
|
}
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
SDL_JoystickDriver SDL_DARWIN_JoystickDriver =
|
2012-11-26 16:37:54 -08:00
|
|
|
{
|
2018-08-09 16:00:17 -07:00
|
|
|
DARWIN_JoystickInit,
|
|
|
|
DARWIN_JoystickGetCount,
|
|
|
|
DARWIN_JoystickDetect,
|
|
|
|
DARWIN_JoystickGetDeviceName,
|
|
|
|
DARWIN_JoystickGetDeviceGUID,
|
|
|
|
DARWIN_JoystickGetDeviceInstanceID,
|
|
|
|
DARWIN_JoystickOpen,
|
|
|
|
DARWIN_JoystickIsAttached,
|
|
|
|
DARWIN_JoystickRumble,
|
|
|
|
DARWIN_JoystickUpdate,
|
|
|
|
DARWIN_JoystickClose,
|
|
|
|
DARWIN_JoystickQuit,
|
|
|
|
};
|
2006-04-14 04:46:47 +00:00
|
|
|
|
|
|
|
#endif /* SDL_JOYSTICK_IOKIT */
|
2013-03-25 11:38:30 -07:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|