From 88af339c0b9d249856a1732f48248674963f57be Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 15 Sep 2020 11:35:43 +0000 Subject: [PATCH] fix context creation on macos when gtk window is a nsview --- GLWidget/GLWidget.cs | 9 ++++++++- GLWidget/OpenTK/Platform/MacOS/CocoaWindowInfo.cs | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/GLWidget/GLWidget.cs b/GLWidget/GLWidget.cs index 4dac0ef..3cc1869 100644 --- a/GLWidget/GLWidget.cs +++ b/GLWidget/GLWidget.cs @@ -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); } diff --git a/GLWidget/OpenTK/Platform/MacOS/CocoaWindowInfo.cs b/GLWidget/OpenTK/Platform/MacOS/CocoaWindowInfo.cs index bfef467..feb3c52 100644 --- a/GLWidget/OpenTK/Platform/MacOS/CocoaWindowInfo.cs +++ b/GLWidget/OpenTK/Platform/MacOS/CocoaWindowInfo.cs @@ -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 /// A valid NSView reference. 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);