diff --git a/Source/OpenTK/Platform/SDL2/Sdl2.cs b/Source/OpenTK/Platform/SDL2/Sdl2.cs index 4690e7d9..b41abb47 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2.cs @@ -331,6 +331,10 @@ namespace OpenTK.Platform.SDL2 [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickGetGUID", ExactSpelling = true)] 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] [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickName", ExactSpelling = true)] static extern IntPtr JoystickNameInternal(IntPtr joystick); diff --git a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs index 7623bf53..396c336b 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs @@ -42,6 +42,7 @@ namespace OpenTK.Platform.SDL2 { public IntPtr Handle { get; set; } public Guid Guid { get; set; } + public int InstanceId { get; set; } public int PacketNumber { get; set; } public int HatCount { get; set; } public int BallCount { get; set; } @@ -51,7 +52,6 @@ namespace OpenTK.Platform.SDL2 } // For IJoystickDriver2 implementation - int last_joystick_instance = 0; readonly List joysticks = new List(4); readonly Dictionary sdl_instanceid_to_joysticks = new Dictionary(); @@ -98,6 +98,7 @@ namespace OpenTK.Platform.SDL2 joystick = new JoystickDevice(id, num_axes, num_buttons); joystick.Description = SDL.JoystickName(handle); joystick.Details.Handle = handle; + joystick.Details.InstanceId = SDL.JoystickInstanceID(handle); joystick.Details.Guid = SDL.JoystickGetGUID(handle).ToGuid(); joystick.Details.HatCount = num_hats; joystick.Details.BallCount = num_balls; @@ -315,11 +316,12 @@ namespace OpenTK.Platform.SDL2 { IntPtr handle = SDL.JoystickOpen(id); if (handle != IntPtr.Zero) - { - int device_id = id; - int instance_id = last_joystick_instance++; - + { JoystickDevice joystick = OpenJoystick(id); + + int instance_id = joystick.Details.InstanceId; + int device_id = id; + if (joystick != null) { joystick.Details.IsConnected = true;