fix context creation on macos when gtk window is a nsview

This commit is contained in:
Emmanuel 2020-09-15 11:35:43 +00:00
parent c35e98f984
commit 88af339c0b
2 changed files with 14 additions and 1 deletions

View file

@ -365,7 +365,14 @@ namespace OpenTK
IWindowInfo InitializeOSX()
{
IntPtr windowHandle = gdk_quartz_window_get_nswindow(this.Window.Handle);
//IntPtr viewHandle = gdk_quartz_window_get_nsview(this.GdkWindow.Handle);
if (windowHandle == IntPtr.Zero)
{
IntPtr viewHandle = gdk_quartz_window_get_nsview(this.Window.Handle);
return Utilities.CreateMacOSWindowInfo(windowHandle, viewHandle);
}
return Utilities.CreateMacOSWindowInfo(windowHandle);
}

View file

@ -37,6 +37,7 @@ namespace OpenTK.Platform.MacOS
internal sealed class CocoaWindowInfo : IWindowInfo
{
private static readonly IntPtr selContentView = Selector.Get("contentView");
private static readonly IntPtr selWindow = Selector.Get("window");
private bool disposed = false;
@ -57,6 +58,11 @@ namespace OpenTK.Platform.MacOS
/// <param name="nsViewRef">A valid NSView reference.</param>
public CocoaWindowInfo(IntPtr nsWindowRef, IntPtr nsViewRef)
{
if (nsWindowRef == IntPtr.Zero)
{
nsWindowRef = Cocoa.SendIntPtr(nsViewRef, selWindow);
}
this.Handle = nsWindowRef;
this.ViewHandle = nsViewRef;
Cocoa.SendVoid(nsWindowRef, Selector.Retain);