* XI2Mouse.cs:

* X11Factory.cs: Detect whether XInput2 is not supported without
  throwing an exception.
This commit is contained in:
the_fiddler 2010-10-22 07:41:56 +00:00
parent d49b315ced
commit bb01babfbd
2 changed files with 35 additions and 23 deletions

View file

@ -85,15 +85,10 @@ namespace OpenTK.Platform.X11
public virtual OpenTK.Input.IMouseDriver CreateMouseDriver() public virtual OpenTK.Input.IMouseDriver CreateMouseDriver()
{ {
try if (XI2Mouse.IsSupported(IntPtr.Zero))
{ return new XI2Mouse(null); // Requires xorg 1.7 or higher.
// Only supported on xorg 1.7 or higher. else
return new XI2Mouse(null); return new X11Mouse(null); // Always supported.
}
catch (NotSupportedException) { }
// Should always be supported.
return new X11Mouse(null);
} }
#endregion #endregion

View file

@ -41,7 +41,7 @@ namespace OpenTK.Platform.X11
Dictionary<int, int> rawids = new Dictionary<int, int>(); // maps raw ids to mouse ids Dictionary<int, int> rawids = new Dictionary<int, int>(); // maps raw ids to mouse ids
int first_mouse; int first_mouse;
readonly X11WindowInfo window; readonly X11WindowInfo window;
readonly int XIOpCode; static int XIOpCode;
static readonly Functions.EventPredicate PredicateImpl = IsEventValid; static readonly Functions.EventPredicate PredicateImpl = IsEventValid;
readonly IntPtr Predicate = Marshal.GetFunctionPointerForDelegate(PredicateImpl); readonly IntPtr Predicate = Marshal.GetFunctionPointerForDelegate(PredicateImpl);
@ -65,25 +65,40 @@ namespace OpenTK.Platform.X11
} }
} }
using (new XLock(window.Display)) if (!IsSupported(window.Display))
{ throw new NotSupportedException("XInput2 not supported.");
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;
using (XIEventMask mask = new XIEventMask(1, XIEventMasks.RawButtonPressMask | using (XIEventMask mask = new XIEventMask(1, XIEventMasks.RawButtonPressMask |
XIEventMasks.RawButtonReleaseMask | XIEventMasks.RawMotionMask)) XIEventMasks.RawButtonReleaseMask | XIEventMasks.RawMotionMask))
{ {
Functions.XISelectEvents(window.Display, window.WindowHandle, mask); Functions.XISelectEvents(window.Display, window.WindowHandle, mask);
}
} }
Debug.WriteLine("Using XI2Mouse."); 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 // Todo: remove this
public IList<MouseDevice> Mouse { get { throw new NotSupportedException(); } } public IList<MouseDevice> Mouse { get { throw new NotSupportedException(); } }
@ -105,6 +120,8 @@ namespace OpenTK.Platform.X11
return new MouseState(); return new MouseState();
} }
#endregion
void ProcessEvents() void ProcessEvents()
{ {
while (true) while (true)