From d167b227da94d4ee9ff8f36055bd0a34657c2c6c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 20 Sep 2019 19:35:05 +1000 Subject: [PATCH] Get 'quit' in dockbar to work for cocoa --- src/Window.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Window.c b/src/Window.c index 201aa1d4f..6bf77af6b 100644 --- a/src/Window.c +++ b/src/Window.c @@ -1649,6 +1649,18 @@ static void Window_CommonInit(void) { Display_BitsPerPixel = CGDisplayBitsPerPixel(display); } +static pascal OSErr HandleQuitMessage(const AppleEvent* ev, AppleEvent* reply, long handlerRefcon) { + Window_Close(); + return 0; +} + +static void Window_CommonCreate(void) { + Window_Exists = true; + /* for quit buttons in dock and menubar */ + AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, + NewAEEventHandlerUPP(HandleQuitMessage), 0, false); +} + /* Sourced from https://www.meandmark.com/keycodes.html */ static const cc_uint8 key_map[8 * 16] = { 'A', 'S', 'D', 'F', 'H', 'G', 'Z', 'X', 'C', 'V', 0, 'B', 'Q', 'W', 'E', 'R', @@ -1976,10 +1988,6 @@ static OSStatus Window_EventHandler(EventHandlerCallRef inCaller, EventRef inEve return eventNotHandledErr; } -static pascal OSErr HandleQuitMessage(const AppleEvent* ev, AppleEvent* reply, long handlerRefcon) { - Window_Close(); - return 0; -} typedef EventTargetRef (*GetMenuBarEventTarget_Func)(void); static void Window_ConnectEvents(void) { @@ -2017,9 +2025,6 @@ static void Window_ConnectEvents(void) { InstallEventHandler(target, NewEventHandlerUPP(Window_EventHandler), Array_Elems(appEventTypes), appEventTypes, NULL, NULL); - AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, - NewAEEventHandlerUPP(HandleQuitMessage), 0, false); - /* The code below is to get the menubar working. */ /* The documentation for 'RunApplicationEventLoop' states that it installs */ /* the standard application event handler which lets the menubar work. */ @@ -2066,7 +2071,7 @@ void Window_Create(int width, int height) { /* TODO: Use BringWindowToFront instead.. (look in the file which has RepositionWindow in it) !!!! */ Window_ConnectEvents(); - Window_Exists = true; + Window_CommonCreate(); Window_Handle = win_handle; } @@ -3726,8 +3731,8 @@ void Window_Create(int width, int height) { winHandle = objc_msgSend((id)objc_getClass("NSWindow"), sel_registerName("alloc")); objc_msgSend(winHandle, sel_registerName("initWithContentRect:styleMask:backing:defer:"), rect, (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask), 0, false); - Window_Exists = true; - + + Window_CommonCreate(); funcs = Window_MakeDelegate(); objc_msgSend(winHandle, sel_registerName("setDelegate:"), funcs);