Added support for higher mouse buttons under X11.
Use XCheckWindowEvent instead of XNextEvent.
This commit is contained in:
parent
ef3e344d68
commit
7473fe500e
9 changed files with 72 additions and 50 deletions
|
@ -32,7 +32,7 @@ namespace OpenTK.Build
|
|||
|
||||
static string PrebuildXml = Path.Combine(ToolPath, "Prebuild.xml");
|
||||
|
||||
static Regex DataFiles = new Regex(@"(\.jpg|\.txt|\.glsl)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
static Regex DataFiles = new Regex(@"^.*\.(jpg|txt|glsl)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
enum BuildMode
|
||||
{
|
||||
|
|
|
@ -108,14 +108,20 @@ namespace Examples.Tests
|
|||
ControlLogMouseKey ControlLogMouseKeyDown =
|
||||
delegate(GameWindow input_window, S04_Input_Logger control, MouseDevice sender, MouseButton button)
|
||||
{
|
||||
if (sender.DeviceID == input_window.Mouse.DeviceID)
|
||||
control.MouseButtonsBox.Items.Add(button);
|
||||
if (sender.DeviceID == input_window.Mouse.DeviceID)
|
||||
{
|
||||
control.MouseButtonsBox.Items.Add(button);
|
||||
System.Diagnostics.Debug.Print("Button down: {0}", button);
|
||||
}
|
||||
};
|
||||
ControlLogMouseKey ControlLogMouseKeyUp =
|
||||
delegate(GameWindow input_window, S04_Input_Logger control, MouseDevice sender, MouseButton button)
|
||||
{
|
||||
if (sender.DeviceID == input_window.Mouse.DeviceID)
|
||||
control.MouseButtonsBox.Items.Remove(button);
|
||||
if (sender.DeviceID == input_window.Mouse.DeviceID)
|
||||
{
|
||||
control.MouseButtonsBox.Items.Remove(button);
|
||||
System.Diagnostics.Debug.Print("Button up: {0}", button);
|
||||
}
|
||||
};
|
||||
|
||||
delegate void ControlLogMousePosition(GameWindow input_window, S04_Input_Logger control);
|
||||
|
@ -174,7 +180,7 @@ namespace Examples.Tests
|
|||
|
||||
private void ChooseMouse_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
MouseButtonsBox.Items.Clear();
|
||||
MouseButtonsBox.Items.Clear();
|
||||
}
|
||||
|
||||
#region public static void Main()
|
||||
|
@ -196,4 +202,4 @@ namespace Examples.Tests
|
|||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ namespace OpenTK.Input
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the absolute x position of the pointer, in screen pixel coordinates.
|
||||
/// Gets an integer representing the absolute x position of the pointer, in window pixel coordinates.
|
||||
/// </summary>
|
||||
public int X
|
||||
{
|
||||
|
@ -113,7 +113,7 @@ namespace OpenTK.Input
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the absolute y position of the pointer, in screen pixel coordinates.
|
||||
/// Gets an integer representing the absolute y position of the pointer, in window pixel coordinates.
|
||||
/// </summary>
|
||||
public int Y
|
||||
{
|
||||
|
@ -154,7 +154,7 @@ namespace OpenTK.Input
|
|||
#region public Point Position
|
||||
|
||||
/// <summary>
|
||||
/// Gets a System.Drawing.Point representing the absolute position of the pointer, in screen pixel coordinates.
|
||||
/// Gets a System.Drawing.Point representing the absolute position of the pointer, in window pixel coordinates.
|
||||
/// </summary>
|
||||
public Point Position
|
||||
{
|
||||
|
@ -191,14 +191,11 @@ namespace OpenTK.Input
|
|||
internal set
|
||||
{
|
||||
if (ButtonDown != null && value && !button[(int)b])
|
||||
{
|
||||
ButtonDown(this, b);
|
||||
}
|
||||
else if (ButtonUp != null && !value && button[(int)b])
|
||||
{
|
||||
ButtonUp(this, b);
|
||||
}
|
||||
button[(int)b] = value;
|
||||
|
||||
//System.Diagnostics.Debug.Print("Mouse button {0} {1}", b, value ? "down" : "up");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace OpenTK.Platform.X11
|
|||
{
|
||||
AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
|
||||
|
||||
//using (System.Windows.Forms.Control c = new System.Windows.Forms.Control()) { }
|
||||
// Bad idea - Windows.Forms will steal our events!
|
||||
//Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
||||
//defaultDisplay = (IntPtr)xplatui.GetField("DisplayHandle", System.Reflection.BindingFlags.Static |
|
||||
// System.Reflection.BindingFlags.NonPublic).GetValue(null);
|
||||
|
@ -1237,7 +1237,10 @@ XF86VidModeGetGammaRampSize(
|
|||
Button2Mask = (1 << 9),
|
||||
Button3Mask = (1 << 10),
|
||||
Button4Mask = (1 << 11),
|
||||
Button5Mask = (1 << 12),
|
||||
Button5Mask = (1 << 12),
|
||||
Button6Mask = (1 << 13),
|
||||
Button7Mask = (1 << 14),
|
||||
Button8Mask = (1 << 15),
|
||||
ShiftMask = (1 << 0),
|
||||
LockMask = (1 << 1),
|
||||
ControlMask = (1 << 2),
|
||||
|
@ -1250,19 +1253,6 @@ XF86VidModeGetGammaRampSize(
|
|||
|
||||
#endregion
|
||||
|
||||
#region public enum MouseButton
|
||||
|
||||
public enum MouseButton
|
||||
{
|
||||
Button1 = 1,
|
||||
Button2 = 2,
|
||||
Button3 = 3,
|
||||
Button4 = 4,
|
||||
Button5 = 5,
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
internal static partial class Functions
|
||||
|
|
|
@ -73,8 +73,16 @@ namespace OpenTK.Platform.X11
|
|||
public extern static int XUnmapSubwindows(IntPtr display, IntPtr window);
|
||||
[DllImport("libX11", EntryPoint = "XRootWindow")]
|
||||
public extern static IntPtr XRootWindow(IntPtr display, int screen_number);
|
||||
|
||||
[DllImport("libX11", EntryPoint = "XNextEvent")]
|
||||
public extern static IntPtr XNextEvent(IntPtr display, ref XEvent xevent);
|
||||
[DllImport("libX11")]
|
||||
public extern static Bool XWindowEvent(Display display, Window w, EventMask event_mask, ref XEvent event_return);
|
||||
[DllImport("libX11")]
|
||||
public extern static Bool XCheckWindowEvent(Display display, Window w, EventMask event_mask, ref XEvent event_return);
|
||||
[DllImport("libX11")]
|
||||
public extern static Bool XCheckTypedWindowEvent(Display display, Window w, XEventName event_type, ref XEvent event_return);
|
||||
|
||||
[DllImport("libX11")]
|
||||
public extern static int XConnectionNumber(IntPtr diplay);
|
||||
[DllImport("libX11")]
|
||||
|
|
|
@ -863,7 +863,7 @@ namespace OpenTK.Platform.X11
|
|||
PropertyChangeMask = 1 << 22,
|
||||
ColormapChangeMask = 1 << 23,
|
||||
OwnerGrabButtonMask = 1 << 24
|
||||
}
|
||||
}
|
||||
|
||||
public enum GrabMode
|
||||
{
|
||||
|
|
|
@ -228,15 +228,17 @@ namespace OpenTK.Platform.X11
|
|||
public void ProcessEvents()
|
||||
{
|
||||
// Process all pending events
|
||||
while (true)
|
||||
{
|
||||
//while (true)
|
||||
while (Functions.XCheckWindowEvent(window.Display, window.WindowHandle, window.EventMask, ref e) ||
|
||||
Functions.XCheckTypedWindowEvent(window.Display, window.WindowHandle, XEventName.ClientMessage, ref e))
|
||||
{
|
||||
//pending = Functions.XPending(window.Display);
|
||||
pending = API.Pending(window.Display);
|
||||
//pending = API.Pending(window.Display);
|
||||
|
||||
if (pending == 0)
|
||||
return;
|
||||
//if (pending == 0)
|
||||
// return;
|
||||
|
||||
Functions.XNextEvent(window.Display, ref e);
|
||||
//Functions.XNextEvent(window.Display, ref e);
|
||||
|
||||
//Debug.Print("Event: {0} ({1} pending)", e.type, pending);
|
||||
|
||||
|
|
|
@ -132,10 +132,10 @@ namespace OpenTK.Platform.X11
|
|||
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null);
|
||||
|
||||
|
||||
xplatui.GetField("CustomVisual", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
|
||||
.SetValue(null, visual);
|
||||
xplatui.GetField("CustomColormap", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
|
||||
.SetValue(null, Functions.XCreateColormap(display, root, visual, 0));
|
||||
//xplatui.GetField("CustomVisual", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
|
||||
// .SetValue(null, visual);
|
||||
//xplatui.GetField("CustomColormap", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
|
||||
// .SetValue(null, Functions.XCreateColormap(display, root, visual, 0));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -155,19 +155,38 @@ namespace OpenTK.Platform.X11
|
|||
break;
|
||||
|
||||
case XEventName.ButtonPress:
|
||||
if (e.ButtonEvent.button == (int)MouseButton.Button1) mouse[OpenTK.Input.MouseButton.Left] = true;
|
||||
else if (e.ButtonEvent.button == (int)MouseButton.Button2) mouse[OpenTK.Input.MouseButton.Middle] = true;
|
||||
else if (e.ButtonEvent.button == (int)MouseButton.Button3) mouse[OpenTK.Input.MouseButton.Right] = true;
|
||||
else if (e.ButtonEvent.button == (int)MouseButton.Button4) mouse.Wheel++;
|
||||
else if (e.ButtonEvent.button == (int)MouseButton.Button5) mouse.Wheel--;
|
||||
if (e.ButtonEvent.button == 1) mouse[OpenTK.Input.MouseButton.Left] = true;
|
||||
else if (e.ButtonEvent.button == 2) mouse[OpenTK.Input.MouseButton.Middle] = true;
|
||||
else if (e.ButtonEvent.button == 3) mouse[OpenTK.Input.MouseButton.Right] = true;
|
||||
else if (e.ButtonEvent.button == 4) mouse.Wheel++;
|
||||
else if (e.ButtonEvent.button == 5) mouse.Wheel--;
|
||||
else if (e.ButtonEvent.button == 6) mouse[OpenTK.Input.MouseButton.Button1] = true;
|
||||
else if (e.ButtonEvent.button == 7) mouse[OpenTK.Input.MouseButton.Button2] = true;
|
||||
else if (e.ButtonEvent.button == 8) mouse[OpenTK.Input.MouseButton.Button3] = true;
|
||||
else if (e.ButtonEvent.button == 9) mouse[OpenTK.Input.MouseButton.Button4] = true;
|
||||
else if (e.ButtonEvent.button == 10) mouse[OpenTK.Input.MouseButton.Button5] = true;
|
||||
else if (e.ButtonEvent.button == 11) mouse[OpenTK.Input.MouseButton.Button6] = true;
|
||||
else if (e.ButtonEvent.button == 12) mouse[OpenTK.Input.MouseButton.Button7] = true;
|
||||
else if (e.ButtonEvent.button == 13) mouse[OpenTK.Input.MouseButton.Button8] = true;
|
||||
else if (e.ButtonEvent.button == 14) mouse[OpenTK.Input.MouseButton.Button9] = true;
|
||||
//if ((e.state & (int)X11.MouseMask.Button4Mask) != 0) m.Wheel++;
|
||||
//if ((e.state & (int)X11.MouseMask.Button5Mask) != 0) m.Wheel--;
|
||||
//if ((e.state & (int)X11.MouseMask.Button5Mask) != 0) m.Wheel--;
|
||||
//Debug.Print("Button pressed: {0}", e.ButtonEvent.button);
|
||||
break;
|
||||
|
||||
case XEventName.ButtonRelease:
|
||||
if (e.ButtonEvent.button == (int)MouseButton.Button1) mouse[OpenTK.Input.MouseButton.Left] = false;
|
||||
else if (e.ButtonEvent.button == (int)MouseButton.Button2) mouse[OpenTK.Input.MouseButton.Middle] = false;
|
||||
else if (e.ButtonEvent.button == (int)MouseButton.Button3) mouse[OpenTK.Input.MouseButton.Right] = false;
|
||||
case XEventName.ButtonRelease:
|
||||
if (e.ButtonEvent.button == 1) mouse[OpenTK.Input.MouseButton.Left] = false;
|
||||
else if (e.ButtonEvent.button == 2) mouse[OpenTK.Input.MouseButton.Middle] = false;
|
||||
else if (e.ButtonEvent.button == 3) mouse[OpenTK.Input.MouseButton.Right] = false;
|
||||
else if (e.ButtonEvent.button == 6) mouse[OpenTK.Input.MouseButton.Button1] = false;
|
||||
else if (e.ButtonEvent.button == 7) mouse[OpenTK.Input.MouseButton.Button2] = false;
|
||||
else if (e.ButtonEvent.button == 8) mouse[OpenTK.Input.MouseButton.Button3] = false;
|
||||
else if (e.ButtonEvent.button == 9) mouse[OpenTK.Input.MouseButton.Button4] = false;
|
||||
else if (e.ButtonEvent.button == 10) mouse[OpenTK.Input.MouseButton.Button5] = false;
|
||||
else if (e.ButtonEvent.button == 11) mouse[OpenTK.Input.MouseButton.Button6] = false;
|
||||
else if (e.ButtonEvent.button == 12) mouse[OpenTK.Input.MouseButton.Button7] = false;
|
||||
else if (e.ButtonEvent.button == 13) mouse[OpenTK.Input.MouseButton.Button8] = false;
|
||||
else if (e.ButtonEvent.button == 14) mouse[OpenTK.Input.MouseButton.Button9] = false;
|
||||
break;
|
||||
|
||||
case XEventName.MotionNotify:
|
||||
|
|
Loading…
Reference in a new issue