* Input/Mouse.cs:

* Platform/X11/X11Mouse.cs:
* Platform/X11/XI2Mouse.cs: Added internal list of mouse devices in
  preparation for multi-mouse support.
This commit is contained in:
the_fiddler 2010-10-21 14:53:10 +00:00
parent 6276057c65
commit d49b315ced
3 changed files with 28 additions and 11 deletions

View file

@ -61,6 +61,8 @@ namespace OpenTK.Input
/// <returns>A <see cref="OpenTK.Input.MouseState"/> structure containing the state of the mouse device.</returns>
public static MouseState GetState(int index)
{
if (index < 0)
throw new ArgumentOutOfRangeException("index");
return driver.GetState(index);
}

View file

@ -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)

View file

@ -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<MouseState> mice = new List<MouseState>();
Dictionary<int, int> rawids = new Dictionary<int, int>(); // 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);
}