diff --git a/Source/OpenTK/Platform/X11/X11Factory.cs b/Source/OpenTK/Platform/X11/X11Factory.cs index 96dd6162..a5a82c08 100644 --- a/Source/OpenTK/Platform/X11/X11Factory.cs +++ b/Source/OpenTK/Platform/X11/X11Factory.cs @@ -85,15 +85,10 @@ namespace OpenTK.Platform.X11 public virtual OpenTK.Input.IMouseDriver CreateMouseDriver() { - try - { - // Only supported on xorg 1.7 or higher. - return new XI2Mouse(null); - } - catch (NotSupportedException) { } - - // Should always be supported. - return new X11Mouse(null); + if (XI2Mouse.IsSupported(IntPtr.Zero)) + return new XI2Mouse(null); // Requires xorg 1.7 or higher. + else + return new X11Mouse(null); // Always supported. } #endregion diff --git a/Source/OpenTK/Platform/X11/XI2Mouse.cs b/Source/OpenTK/Platform/X11/XI2Mouse.cs index b4026905..c92984fd 100644 --- a/Source/OpenTK/Platform/X11/XI2Mouse.cs +++ b/Source/OpenTK/Platform/X11/XI2Mouse.cs @@ -41,7 +41,7 @@ namespace OpenTK.Platform.X11 Dictionary rawids = new Dictionary(); // maps raw ids to mouse ids int first_mouse; readonly X11WindowInfo window; - readonly int XIOpCode; + static int XIOpCode; static readonly Functions.EventPredicate PredicateImpl = IsEventValid; readonly IntPtr Predicate = Marshal.GetFunctionPointerForDelegate(PredicateImpl); @@ -65,25 +65,40 @@ namespace OpenTK.Platform.X11 } } - using (new XLock(window.Display)) - { - int major, ev, error; - if (Functions.XQueryExtension(window.Display, "XInputExtension", out major, out ev, out error) == 0) - { - Debug.WriteLine("XInput2 not supported."); - throw new NotSupportedException(); - } - XIOpCode = major; + if (!IsSupported(window.Display)) + throw new NotSupportedException("XInput2 not supported."); - using (XIEventMask mask = new XIEventMask(1, XIEventMasks.RawButtonPressMask | + using (XIEventMask mask = new XIEventMask(1, XIEventMasks.RawButtonPressMask | XIEventMasks.RawButtonReleaseMask | XIEventMasks.RawMotionMask)) - { - Functions.XISelectEvents(window.Display, window.WindowHandle, mask); - } + { + Functions.XISelectEvents(window.Display, window.WindowHandle, mask); } + Debug.WriteLine("Using XI2Mouse."); } + // Checks whether XInput2 is supported on the specified display. + // If a display is not specified, the default display is used. + internal static bool IsSupported(IntPtr display) + { + if (display == IntPtr.Zero) + display = API.DefaultDisplay; + + using (new XLock(display)) + { + int major, ev, error; + if (Functions.XQueryExtension(display, "XInputExtension", out major, out ev, out error) == 0) + { + return false; + } + XIOpCode = major; + } + + return true; + } + + #region IMouseDriver Members + // Todo: remove this public IList Mouse { get { throw new NotSupportedException(); } } @@ -105,6 +120,8 @@ namespace OpenTK.Platform.X11 return new MouseState(); } + #endregion + void ProcessEvents() { while (true)