From 9bd06cf09ed3b1afaf084f4885e0406b9eaeff1b Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Mon, 24 Sep 2007 20:56:50 +0000 Subject: [PATCH] Added X11Mouse driver. --- Source/OpenTK/Platform/X11/API.cs | 31 +++++++++++++++++ Source/OpenTK/Platform/X11/X11Input.cs | 8 +++++ Source/OpenTK/Platform/X11/X11Mouse.cs | 46 ++++++++++++++++++++++---- 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/Source/OpenTK/Platform/X11/API.cs b/Source/OpenTK/Platform/X11/API.cs index 4fd02576..49211509 100644 --- a/Source/OpenTK/Platform/X11/API.cs +++ b/Source/OpenTK/Platform/X11/API.cs @@ -1065,4 +1065,35 @@ XF86VidModeGetGammaRampSize( #endregion + + public enum MouseMask + { + Button1MotionMask = (1 << 8), + Button2MotionMask = (1 << 9), + Button3MotionMask = (1 << 10), + Button4MotionMask = (1 << 11), + Button5MotionMask = (1 << 12), + Button1Mask = (1 << 8), + Button2Mask = (1 << 9), + Button3Mask = (1 << 10), + Button4Mask = (1 << 11), + Button5Mask = (1 << 12), + ShiftMask = (1 << 0), + LockMask = (1 << 1), + ControlMask = (1 << 2), + Mod1Mask = (1 << 3), + Mod2Mask = (1 << 4), + Mod3Mask = (1 << 5), + Mod4Mask = (1 << 6), + Mod5Mask = (1 << 7), + } + + public enum MouseButton + { + Button1 = 1, + Button2 = 2, + Button3 = 3, + Button4 = 4, + Button5 = 5, + } } diff --git a/Source/OpenTK/Platform/X11/X11Input.cs b/Source/OpenTK/Platform/X11/X11Input.cs index b5646fae..f7500bb5 100644 --- a/Source/OpenTK/Platform/X11/X11Input.cs +++ b/Source/OpenTK/Platform/X11/X11Input.cs @@ -135,6 +135,14 @@ namespace OpenTK.Platform.X11 { keyboardDriver.ProcessKeyboardEvent(e.KeyEvent); } + while (API.CheckMaskEvent(window.Display, EventMask.ButtonPressMask | EventMask.ButtonPressMask, ref e)) + { + mouseDriver.ProcessButton(e.ButtonEvent); + } + while (API.CheckMaskEvent(window.Display, EventMask.PointerMotionMask | EventMask.PointerMotionHintMask, ref e)) + { + mouseDriver.ProcessMotion(e.MotionEvent); + } /* if (API.Pending(window.Display) > 0) { diff --git a/Source/OpenTK/Platform/X11/X11Mouse.cs b/Source/OpenTK/Platform/X11/X11Mouse.cs index e52ff963..17ff547d 100644 --- a/Source/OpenTK/Platform/X11/X11Mouse.cs +++ b/Source/OpenTK/Platform/X11/X11Mouse.cs @@ -25,6 +25,15 @@ namespace OpenTK.Platform.X11 public X11Mouse(WindowInfo window) { this.window = window; + + // Just create one mouse now. + // TODO: support for multiple devices through evdev. + Mouse m = new Mouse(); + m.Description = "Default X11 mouse"; + m.DeviceID = IntPtr.Zero; + m.NumberOfButtons = 5; + m.NumberOfWheels = 1; + mice.Add(m); } #endregion @@ -33,14 +42,39 @@ namespace OpenTK.Platform.X11 public IList Mouse { - get { } - } - - public int RegisterDevices() - { - throw new Exception("The method or operation is not implemented."); + get { return mice; } } #endregion + + /// + /// Processes XButtonEvents. + /// + /// The X11.XButtonEvent to process. + /// True if the event was processed, false otherwise. + internal bool ProcessButton(X11.XButtonEvent e) + { + Mouse m = mice[0]; + bool pressed = e.type == XEventName.ButtonPress; + if ((e.state & (int)X11.MouseMask.Button1Mask) != 0) m[OpenTK.Input.MouseButton.Button1] = pressed; + if ((e.state & (int)X11.MouseMask.Button2Mask) != 0) m[OpenTK.Input.MouseButton.Button2] = pressed; + if ((e.state & (int)X11.MouseMask.Button3Mask) != 0) m[OpenTK.Input.MouseButton.Button3] = pressed; + if ((e.state & (int)X11.MouseMask.Button4Mask) != 0) m[OpenTK.Input.MouseButton.Button4] = pressed; + if ((e.state & (int)X11.MouseMask.Button5Mask) != 0) m[OpenTK.Input.MouseButton.Button5] = pressed; + return true; + } + + /// + /// Processes XMotionEvents. + /// + /// The X11.XMotionEvent to process. + /// True if the event was processed, false otherwise. + internal bool ProcessMotion(X11.XMotionEvent e) + { + Mouse m = mice[0]; + m.X = e.x; + m.Y = e.y; + return true; + } } }