From fc0ca5631fe8d514f5db186ca7d01bf907d09a15 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 8 Mar 2009 20:03:33 +0000 Subject: [PATCH] Relaxed checks to allow input devices that do not contain any axes and/or buttons (e.g. tablets or keyboard extensions). --- Source/OpenTK/Input/JoystickDevice.cs | 8 ++++---- Source/OpenTK/Platform/Windows/WinMMJoystick.cs | 8 ++------ Source/OpenTK/Platform/X11/X11Joystick.cs | 5 +---- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Source/OpenTK/Input/JoystickDevice.cs b/Source/OpenTK/Input/JoystickDevice.cs index da6c8523..273dc2de 100644 --- a/Source/OpenTK/Input/JoystickDevice.cs +++ b/Source/OpenTK/Input/JoystickDevice.cs @@ -50,10 +50,10 @@ namespace OpenTK.Input internal JoystickDevice(int id, int axes, int buttons) { - if (axes <= 0) + if (axes < 0) throw new ArgumentOutOfRangeException("axes"); - if (buttons <= 0) + if (buttons < 0) throw new ArgumentOutOfRangeException("buttons"); Id = id; @@ -331,7 +331,7 @@ namespace OpenTK.Input internal JoystickButtonCollection(int numButtons) { - if (numButtons <= 0) + if (numButtons < 0) throw new ArgumentOutOfRangeException("numButtons"); button_state = new bool[numButtons]; @@ -424,7 +424,7 @@ namespace OpenTK.Input internal JoystickAxisCollection(int numAxes) { - if (numAxes <= 0) + if (numAxes < 0) throw new ArgumentOutOfRangeException("numAxes"); axis_state = new float[numAxes]; diff --git a/Source/OpenTK/Platform/Windows/WinMMJoystick.cs b/Source/OpenTK/Platform/Windows/WinMMJoystick.cs index 95b03139..1fc3bddd 100644 --- a/Source/OpenTK/Platform/Windows/WinMMJoystick.cs +++ b/Source/OpenTK/Platform/Windows/WinMMJoystick.cs @@ -86,12 +86,6 @@ namespace OpenTK.Platform.Windows if ((caps.Capabilities & JoystCapsFlags.HasPov) != 0) num_axes += 2; - if (num_axes == 0) - { - Debug.Print("WinMM device {0} has 0 axes. Device will not be used."); - return null; - } - stick = new JoystickDevice(number, num_axes, caps.NumButtons); stick.Details = new WinMMJoyDetails(num_axes); @@ -131,6 +125,8 @@ namespace OpenTK.Platform.Windows key.Close(); } + if (stick != null) + Debug.Print("Found joystick on device number {0}", number); return stick; } diff --git a/Source/OpenTK/Platform/X11/X11Joystick.cs b/Source/OpenTK/Platform/X11/X11Joystick.cs index 01d5079f..c073ef19 100644 --- a/Source/OpenTK/Platform/X11/X11Joystick.cs +++ b/Source/OpenTK/Platform/X11/X11Joystick.cs @@ -131,8 +131,6 @@ namespace OpenTK.Platform.X11 string path = base_path + number.ToString(); JoystickDevice stick = null; - Debug.Write(String.Format("Attempting to open joystick {0}... ", path)); - int fd = -1; try { @@ -155,13 +153,12 @@ namespace OpenTK.Platform.X11 UnsafeNativeMethods.ioctl(fd, JoystickIoctlCode.Buttons, ref buttons); stick = new JoystickDevice(fd, axes, buttons); + Debug.Print("Found joystick on path {0}", path); } finally { if (stick == null && fd != -1) UnsafeNativeMethods.close(fd); - - Debug.Print(stick != null ? "success!" : "failed."); } return stick;