Merge pull request #352 from mrhelmut/SDL2GamePadInstanceId
Fix SDL2 instance enumeration and mapping
This commit is contained in:
commit
f2d1bd1db5
2 changed files with 11 additions and 5 deletions
|
@ -335,6 +335,10 @@ namespace OpenTK.Platform.SDL2
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickGetGUID", ExactSpelling = true)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickGetGUID", ExactSpelling = true)]
|
||||||
public static extern JoystickGuid JoystickGetGUID(IntPtr joystick);
|
public static extern JoystickGuid JoystickGetGUID(IntPtr joystick);
|
||||||
|
|
||||||
|
[SuppressUnmanagedCodeSecurity]
|
||||||
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickInstanceID", ExactSpelling = true)]
|
||||||
|
public static extern int JoystickInstanceID(IntPtr joystick);
|
||||||
|
|
||||||
[SuppressUnmanagedCodeSecurity]
|
[SuppressUnmanagedCodeSecurity]
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickName", ExactSpelling = true)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickName", ExactSpelling = true)]
|
||||||
static extern IntPtr JoystickNameInternal(IntPtr joystick);
|
static extern IntPtr JoystickNameInternal(IntPtr joystick);
|
||||||
|
|
|
@ -42,6 +42,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
{
|
{
|
||||||
public IntPtr Handle { get; set; }
|
public IntPtr Handle { get; set; }
|
||||||
public Guid Guid { get; set; }
|
public Guid Guid { get; set; }
|
||||||
|
public int InstanceId { get; set; }
|
||||||
public int PacketNumber { get; set; }
|
public int PacketNumber { get; set; }
|
||||||
public int HatCount { get; set; }
|
public int HatCount { get; set; }
|
||||||
public int BallCount { get; set; }
|
public int BallCount { get; set; }
|
||||||
|
@ -51,7 +52,6 @@ namespace OpenTK.Platform.SDL2
|
||||||
}
|
}
|
||||||
|
|
||||||
// For IJoystickDriver2 implementation
|
// For IJoystickDriver2 implementation
|
||||||
int last_joystick_instance = 0;
|
|
||||||
readonly List<JoystickDevice> joysticks = new List<JoystickDevice>(4);
|
readonly List<JoystickDevice> joysticks = new List<JoystickDevice>(4);
|
||||||
readonly Dictionary<int, int> sdl_instanceid_to_joysticks = new Dictionary<int, int>();
|
readonly Dictionary<int, int> sdl_instanceid_to_joysticks = new Dictionary<int, int>();
|
||||||
|
|
||||||
|
@ -98,6 +98,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
joystick = new JoystickDevice<Sdl2JoystickDetails>(id, num_axes, num_buttons);
|
joystick = new JoystickDevice<Sdl2JoystickDetails>(id, num_axes, num_buttons);
|
||||||
joystick.Description = SDL.JoystickName(handle);
|
joystick.Description = SDL.JoystickName(handle);
|
||||||
joystick.Details.Handle = handle;
|
joystick.Details.Handle = handle;
|
||||||
|
joystick.Details.InstanceId = SDL.JoystickInstanceID(handle);
|
||||||
joystick.Details.Guid = SDL.JoystickGetGUID(handle).ToGuid();
|
joystick.Details.Guid = SDL.JoystickGetGUID(handle).ToGuid();
|
||||||
joystick.Details.HatCount = num_hats;
|
joystick.Details.HatCount = num_hats;
|
||||||
joystick.Details.BallCount = num_balls;
|
joystick.Details.BallCount = num_balls;
|
||||||
|
@ -316,10 +317,11 @@ namespace OpenTK.Platform.SDL2
|
||||||
IntPtr handle = SDL.JoystickOpen(id);
|
IntPtr handle = SDL.JoystickOpen(id);
|
||||||
if (handle != IntPtr.Zero)
|
if (handle != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
int device_id = id;
|
|
||||||
int instance_id = last_joystick_instance++;
|
|
||||||
|
|
||||||
JoystickDevice<Sdl2JoystickDetails> joystick = OpenJoystick(id);
|
JoystickDevice<Sdl2JoystickDetails> joystick = OpenJoystick(id);
|
||||||
|
|
||||||
|
int instance_id = joystick.Details.InstanceId;
|
||||||
|
int device_id = id;
|
||||||
|
|
||||||
if (joystick != null)
|
if (joystick != null)
|
||||||
{
|
{
|
||||||
joystick.Details.IsConnected = true;
|
joystick.Details.IsConnected = true;
|
||||||
|
|
Loading…
Reference in a new issue