Skip to content

Commit

Permalink
Closing should occur in ProcessEvents.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ollhax authored and thefiddler committed Apr 24, 2014
1 parent ed87814 commit 46856dc
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions Source/OpenTK/Platform/MacOS/CocoaNativeWindow.cs
Expand Up @@ -100,11 +100,12 @@ static CocoaNativeWindow()
private MacOSKeyMap keyMap = new MacOSKeyMap();
private OpenTK.Input.KeyboardKeyEventArgs keyArgs = new OpenTK.Input.KeyboardKeyEventArgs();
private KeyPressEventArgs keyPressArgs = new KeyPressEventArgs((char)0);
string title;
RectangleF normalBounds;
int normalLevel;
private string title;
private RectangleF normalBounds;
private int normalLevel;
private bool shouldClose;

const bool exclusiveFullscreen = true;
private const bool exclusiveFullscreen = false;

public CocoaNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
{
Expand Down Expand Up @@ -280,19 +281,7 @@ private void ResetTrackingArea()

public void Close()
{
// PerformClose is equivalent to pressing the close-button, which
// does not work in a borderless window. Handle this special case.
if (GetStyleMask() == NSWindowStyle.Borderless)
{
if (WindowShouldClose(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero))
{
Cocoa.SendVoid(windowInfo.Handle, selClose);
}
}
else
{
Cocoa.SendVoid(windowInfo.Handle, selPerformClose, windowInfo.Handle);
}
shouldClose = true;
}

private KeyModifiers GetModifiers(NSEventModifierMask mask)
Expand Down Expand Up @@ -462,6 +451,26 @@ public void ProcessEvents()

Cocoa.SendVoid(NSApplication.Handle, selSendEvent, e);
}

// Handle closing
if (shouldClose)
{
shouldClose = false;

// PerformClose is equivalent to pressing the close-button, which
// does not work in a borderless window. Handle this special case.
if (GetStyleMask() == NSWindowStyle.Borderless)
{
if (WindowShouldClose(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero))
{
Cocoa.SendVoid(windowInfo.Handle, selClose);
}
}
else
{
Cocoa.SendVoid(windowInfo.Handle, selPerformClose, windowInfo.Handle);
}
}
}

public System.Drawing.Point PointToClient(System.Drawing.Point point)
Expand Down

0 comments on commit 46856dc

Please sign in to comment.