Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanups.

  • Loading branch information...
commit ed87814a7f59fe1aa6b4d51d102e8d9a351cfec7 1 parent 3798d26
@Ollhax Ollhax authored thefiddler committed
View
8 Source/OpenTK/Platform/MacOS/Cocoa/NSApplication.cs
@@ -7,12 +7,12 @@ namespace OpenTK.Platform.MacOS
static class NSApplication
{
internal static IntPtr Handle;
+ internal static IntPtr AutoreleasePool;
internal static void Initialize()
{
// Create the NSAutoreleasePool
- Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSAutoreleasePool"), Selector.Alloc),
- Selector.Init);
+ AutoreleasePool = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSAutoreleasePool"), Selector.Alloc), Selector.Init);
// Fetch the application handle
Handle = Cocoa.SendIntPtr(Class.Get("NSApplication"), Selector.Get("sharedApplication"));
@@ -20,7 +20,6 @@ internal static void Initialize()
// Setup the application
Cocoa.SendBool(Handle, Selector.Get("setActivationPolicy:"), (int)NSApplicationActivationPolicy.Regular);
Cocoa.SendVoid(Handle, Selector.Get("activateIgnoringOtherApps:"), true);
- Cocoa.SendVoid(Handle, Selector.Get("finishLaunching"));
// Create the menu bar
var menubar = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSMenu"), Selector.Alloc),
@@ -32,6 +31,9 @@ internal static void Initialize()
// Add menu item to bar, and bar to application
Cocoa.SendIntPtr(menubar, Selector.Get("addItem:"), menuItem);
Cocoa.SendIntPtr(Handle, Selector.Get("setMainMenu:"), menubar);
+
+ // Tell cocoa we're ready to run the application (usually called by [NSApp run]).
+ Cocoa.SendVoid(Handle, Selector.Get("finishLaunching"));
}
}
}
View
205 Source/OpenTK/Platform/MacOS/CocoaNativeWindow.cs
@@ -266,6 +266,7 @@ private void ResetTrackingArea()
if (trackingArea != IntPtr.Zero)
{
Cocoa.SendVoid(owner, selRemoveTrackingArea, trackingArea);
+ Cocoa.SendVoid(trackingArea, Selector.Release);
}
var ownerBounds = Cocoa.SendRect(owner, selBounds);
@@ -329,132 +330,138 @@ private MouseButton GetMouseButton(int cocoaButtonIndex)
public void ProcessEvents()
{
- var e = Cocoa.SendIntPtr(NSApplication.Handle, selNextEventMatchingMask, uint.MaxValue, IntPtr.Zero, NSDefaultRunLoopMode, true);
-
- if (e == IntPtr.Zero)
- return;
-
- var type = (NSEventType)Cocoa.SendInt(e, selType);
- switch (type)
+ while (true)
{
- case NSEventType.KeyDown:
- {
- var keyCode = Cocoa.SendUshort(e, selKeyCode);
- var modifierFlags = (NSEventModifierMask)Cocoa.SendUint(e, selModifierFlags);
- var isARepeat = Cocoa.SendBool(e, selIsARepeat);
- GetKey(keyCode, modifierFlags, keyArgs);
- InputDriver.Keyboard[0].SetKey(keyArgs.Key, keyArgs.ScanCode, true);
+ var e = Cocoa.SendIntPtr(NSApplication.Handle, selNextEventMatchingMask, uint.MaxValue, IntPtr.Zero, NSDefaultRunLoopMode, true);
- if (!isARepeat || InputDriver.Keyboard[0].KeyRepeat)
- {
- KeyDown(this, keyArgs);
- }
+ if (e == IntPtr.Zero)
+ break;
- var s = Cocoa.FromNSString(Cocoa.SendIntPtr(e, selCharactersIgnoringModifiers));
- foreach (var c in s)
+ var type = (NSEventType)Cocoa.SendInt(e, selType);
+ switch (type)
+ {
+ case NSEventType.KeyDown:
{
- int intVal = (int)c;
- if (!Char.IsControl(c) && (intVal < 63232 || intVal > 63235))
+ var keyCode = Cocoa.SendUshort(e, selKeyCode);
+ var modifierFlags = (NSEventModifierMask)Cocoa.SendUint(e, selModifierFlags);
+ var isARepeat = Cocoa.SendBool(e, selIsARepeat);
+ GetKey(keyCode, modifierFlags, keyArgs);
+ InputDriver.Keyboard[0].SetKey(keyArgs.Key, keyArgs.ScanCode, true);
+
+ if (!isARepeat || InputDriver.Keyboard[0].KeyRepeat)
{
- // For some reason, arrow keys (mapped 63232-63235) are seen as non-control characters, so get rid of those.
+ KeyDown(this, keyArgs);
+ }
- keyPressArgs.KeyChar = c;
- KeyPress(this, keyPressArgs);
+ var s = Cocoa.FromNSString(Cocoa.SendIntPtr(e, selCharactersIgnoringModifiers));
+ foreach (var c in s)
+ {
+ int intVal = (int)c;
+ if (!Char.IsControl(c) && (intVal < 63232 || intVal > 63235))
+ {
+ // For some reason, arrow keys (mapped 63232-63235) are seen as non-control characters, so get rid of those.
+
+ keyPressArgs.KeyChar = c;
+ KeyPress(this, keyPressArgs);
+ }
}
- }
- // Steal all keydown events to avoid the annoying "bleep" sound.
- return;
- }
+ // Steal all keydown events to avoid the annoying "bleep" sound.
+ return;
+ }
- case NSEventType.KeyUp:
- {
- var keyCode = Cocoa.SendUshort(e, selKeyCode);
- var modifierFlags = (NSEventModifierMask)Cocoa.SendUint(e, selModifierFlags);
+ case NSEventType.KeyUp:
+ {
+ var keyCode = Cocoa.SendUshort(e, selKeyCode);
+ var modifierFlags = (NSEventModifierMask)Cocoa.SendUint(e, selModifierFlags);
- GetKey(keyCode, modifierFlags, keyArgs);
- InputDriver.Keyboard[0].SetKey(keyArgs.Key, keyArgs.ScanCode, false);
+ GetKey(keyCode, modifierFlags, keyArgs);
+ InputDriver.Keyboard[0].SetKey(keyArgs.Key, keyArgs.ScanCode, false);
- KeyUp(this, keyArgs);
- }
- break;
+ KeyUp(this, keyArgs);
+ }
+ break;
- case NSEventType.MouseEntered:
- {
- var eventTrackingArea = Cocoa.SendIntPtr(e, selTrackingArea);
- var trackingAreaOwner = Cocoa.SendIntPtr(eventTrackingArea, selOwner);
- if (trackingAreaOwner == windowInfo.ViewHandle)
+ case NSEventType.MouseEntered:
{
- if (!cursorVisible)
+ var eventTrackingArea = Cocoa.SendIntPtr(e, selTrackingArea);
+ var trackingAreaOwner = Cocoa.SendIntPtr(eventTrackingArea, selOwner);
+ if (trackingAreaOwner == windowInfo.ViewHandle)
{
- SetCursorVisible(false);
- }
+ if (!cursorVisible)
+ {
+ SetCursorVisible(false);
+ }
- MouseEnter(this, EventArgs.Empty);
+ MouseEnter(this, EventArgs.Empty);
+ }
}
- }
- break;
+ break;
- case NSEventType.MouseExited:
- {
- var eventTrackingArea = Cocoa.SendIntPtr(e, selTrackingArea);
- var trackingAreaOwner = Cocoa.SendIntPtr(eventTrackingArea, selOwner);
- if (trackingAreaOwner == windowInfo.ViewHandle)
+ case NSEventType.MouseExited:
{
- if (!cursorVisible)
+ var eventTrackingArea = Cocoa.SendIntPtr(e, selTrackingArea);
+ var trackingAreaOwner = Cocoa.SendIntPtr(eventTrackingArea, selOwner);
+ if (trackingAreaOwner == windowInfo.ViewHandle)
{
- SetCursorVisible(true);
- }
+ if (!cursorVisible)
+ {
+ SetCursorVisible(true);
+ }
- MouseLeave(this, EventArgs.Empty);
+ MouseLeave(this, EventArgs.Empty);
+ }
}
- }
- break;
+ break;
- case NSEventType.MouseMoved:
- {
- var pf = Cocoa.SendPoint(e, selLocationInWindowOwner);
- var p = new Point((int)pf.X, (int)pf.Y);
-
- var s = ClientSize;
- if (p.X < 0) p.X = 0;
- if (p.Y < 0) p.Y = 0;
- if (p.X > s.Width) p.X = s.Width;
- if (p.Y > s.Height) p.Y = s.Height;
- p.Y = s.Height - p.Y;
+ case NSEventType.MouseMoved:
+ {
+ var pf = Cocoa.SendPoint(e, selLocationInWindowOwner);
+ var p = new Point((int)pf.X, (int)pf.Y);
+
+ var s = ClientSize;
+ if (p.X < 0)
+ p.X = 0;
+ if (p.Y < 0)
+ p.Y = 0;
+ if (p.X > s.Width)
+ p.X = s.Width;
+ if (p.Y > s.Height)
+ p.Y = s.Height;
+ p.Y = s.Height - p.Y;
+
+ InputDriver.Mouse[0].Position = p;
+ }
+ break;
- InputDriver.Mouse[0].Position = p;
- }
- break;
+ case NSEventType.ScrollWheel:
+ {
+ var scrollingDelta = Cocoa.SendFloat(e, selScrollingDeltaY);
+ InputDriver.Mouse[0].WheelPrecise += scrollingDelta;
+ }
+ break;
- case NSEventType.ScrollWheel:
- {
- var scrollingDelta = Cocoa.SendFloat(e, selScrollingDeltaY);
- InputDriver.Mouse[0].WheelPrecise += scrollingDelta;
- }
- break;
+ case NSEventType.LeftMouseDown:
+ case NSEventType.RightMouseDown:
+ case NSEventType.OtherMouseDown:
+ {
+ var buttonNumber = Cocoa.SendInt(e, selButtonNumber);
+ InputDriver.Mouse[0][GetMouseButton(buttonNumber)] = true;
+ }
+ break;
- case NSEventType.LeftMouseDown:
- case NSEventType.RightMouseDown:
- case NSEventType.OtherMouseDown:
- {
- var buttonNumber = Cocoa.SendInt(e, selButtonNumber);
- InputDriver.Mouse[0][GetMouseButton(buttonNumber)] = true;
- }
- break;
+ case NSEventType.LeftMouseUp:
+ case NSEventType.RightMouseUp:
+ case NSEventType.OtherMouseUp:
+ {
+ var buttonNumber = Cocoa.SendInt(e, selButtonNumber);
+ InputDriver.Mouse[0][GetMouseButton(buttonNumber)] = false;
+ }
+ break;
+ }
- case NSEventType.LeftMouseUp:
- case NSEventType.RightMouseUp:
- case NSEventType.OtherMouseUp:
- {
- var buttonNumber = Cocoa.SendInt(e, selButtonNumber);
- InputDriver.Mouse[0][GetMouseButton(buttonNumber)] = false;
- }
- break;
+ Cocoa.SendVoid(NSApplication.Handle, selSendEvent, e);
}
-
- Cocoa.SendVoid(NSApplication.Handle, selSendEvent, e);
- Cocoa.SendVoid(NSApplication.Handle, selUpdateWindows);
}
public System.Drawing.Point PointToClient(System.Drawing.Point point)
Please sign in to comment.
Something went wrong with that request. Please try again.