diff --git a/Source/OpenTK/Input/Mouse.cs b/Source/OpenTK/Input/Mouse.cs index faecb812..e8239e97 100644 --- a/Source/OpenTK/Input/Mouse.cs +++ b/Source/OpenTK/Input/Mouse.cs @@ -61,6 +61,8 @@ namespace OpenTK.Input /// A structure containing the state of the mouse device. public static MouseState GetState(int index) { + if (index < 0) + throw new ArgumentOutOfRangeException("index"); return driver.GetState(index); } diff --git a/Source/OpenTK/Platform/X11/X11Mouse.cs b/Source/OpenTK/Platform/X11/X11Mouse.cs index 4b636a99..5a57364b 100644 --- a/Source/OpenTK/Platform/X11/X11Mouse.cs +++ b/Source/OpenTK/Platform/X11/X11Mouse.cs @@ -77,13 +77,12 @@ namespace OpenTK.Platform.X11 public MouseState GetState(int index) { - - // X11Mouse supports a single mouse only - if (index < 0 || index > 1) - throw new ArgumentOutOfRangeException("index"); - ProcessEvents(); - return mouse; + // X11Mouse supports only one device + if (index == 0) + return mouse; + else + return new MouseState(); } void WriteBit(MouseButton offset, int enabled) diff --git a/Source/OpenTK/Platform/X11/XI2Mouse.cs b/Source/OpenTK/Platform/X11/XI2Mouse.cs index 0451aa27..b4026905 100644 --- a/Source/OpenTK/Platform/X11/XI2Mouse.cs +++ b/Source/OpenTK/Platform/X11/XI2Mouse.cs @@ -37,8 +37,10 @@ namespace OpenTK.Platform.X11 // This should be easy: just read the device id and route the data to the correct device. sealed class XI2Mouse : IMouseDriver { - MouseState state = new MouseState(); - X11WindowInfo window; + List mice = new List(); + Dictionary rawids = new Dictionary(); // maps raw ids to mouse ids + int first_mouse; + readonly X11WindowInfo window; readonly int XIOpCode; static readonly Functions.EventPredicate PredicateImpl = IsEventValid; @@ -88,13 +90,19 @@ namespace OpenTK.Platform.X11 public MouseState GetState() { ProcessEvents(); - return state; + if (mice.Count > 0) + return mice[0]; + else + return new MouseState(); } public MouseState GetState(int index) { ProcessEvents(); - return state; + if (mice.Count > index) + return mice[index]; + else + return new MouseState(); } void ProcessEvents() @@ -114,7 +122,14 @@ namespace OpenTK.Platform.X11 { XIRawEvent raw = (XIRawEvent) Marshal.PtrToStructure(cookie.data, typeof(XIRawEvent)); - + + if (!rawids.ContainsKey(raw.deviceid)) + { + mice.Add(new MouseState()); + rawids.Add(raw.deviceid, mice.Count - 1); + } + MouseState state = mice[rawids[raw.deviceid]]; + switch (raw.evtype) { case XIEventType.RawMotion: @@ -162,6 +177,7 @@ namespace OpenTK.Platform.X11 } break; } + mice[rawids[raw.deviceid]] = state; } Functions.XFreeEventData(window.Display, ref cookie); }