* XI2Mouse.cs:
* X11Factory.cs: Detect whether XInput2 is not supported without throwing an exception.
This commit is contained in:
parent
eeefbd1a9c
commit
4d2759eb78
2 changed files with 35 additions and 23 deletions
|
@ -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
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace OpenTK.Platform.X11
|
|||
Dictionary<int, int> rawids = new Dictionary<int, int>(); // 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<MouseDevice> Mouse { get { throw new NotSupportedException(); } }
|
||||
|
||||
|
@ -105,6 +120,8 @@ namespace OpenTK.Platform.X11
|
|||
return new MouseState();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
void ProcessEvents()
|
||||
{
|
||||
while (true)
|
||||
|
|
Loading…
Reference in a new issue