9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: underspecified <underspecified@gmail.com>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@9fans.net>
Subject: Re: [9fans] OSX Drawterm hangs on close
Date: Tue, 24 Jun 2008 17:29:58 +0900	[thread overview]
Message-ID: <ab4cf6420806240129q62ea1d6eu7959d4cc08518ce9@mail.gmail.com> (raw)
In-Reply-To: <467b878590eeb9c68a60ef6ae8af1b43@9netics.com>

[-- Attachment #1: Type: text/plain, Size: 1015 bytes --]

Greetings,

I came across this message while catching up on mailing lists.
This is a problem we were having that I recently fixed in Acme SAC for OS-X.
Basically, the problem was that there was no handler catching kEventAppQuit.

I am attaching a patch that creates a basic event handler and calls
exit(0) on any quit events.
This should prevent drawterm from hanging when being closed in any way
not using the menu
(system logouts, using the task switcher, etc.). My source for
drawterm might be a bit out of date,
so be careful when applying.

Take care,

--underspecified

On Wed, Apr 9, 2008 at 6:09 AM, Skip Tavakkolian <9nut@9netics.com> wrote:
> why do you feel compelled to state the obvious?
>
>> Also realize that Cocoa is written in Objective-C, not C, so you need
>> to learn a new language to get your hands on it. You CAN write a C
>> wrapper around the Objective-C (it was originally a C preprocessor),
>> but I don't think elite Mac programmers would recommend it.
>
>
>

[-- Attachment #2: quit_event.diff --]
[-- Type: application/octet-stream, Size: 2432 bytes --]

diff -ru drawterm.orig/gui-osx/screen.c drawterm.new/gui-osx/screen.c
--- drawterm.orig/gui-osx/screen.c	2007-10-26 02:31:32.000000000 +0900
+++ drawterm.new/gui-osx/screen.c	2008-06-24 17:22:16.000000000 +0900
@@ -138,6 +138,7 @@
 	ksleep(&rend, isready, 0);
 }
 
+static OSStatus ApplicationQuitEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
 static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
 static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
 
@@ -192,6 +193,9 @@
 	if(PasteboardCreate(kPasteboardClipboard, &appleclip) != noErr)
 		sysfatal("pasteboard create failed");
 
+	const EventTypeSpec quit_events[] = {
+		{ kEventClassApplication, kEventAppQuit }
+	};
 	const EventTypeSpec commands[] = {
 		{ kEventClassWindow, kEventWindowClosed },
 		{ kEventClassWindow, kEventWindowBoundsChanged },
@@ -208,6 +212,13 @@
 		{ kEventClassMouse, kEventMouseWheelMoved },
 	};
 
+	InstallApplicationEventHandler (
+								NewEventHandlerUPP (ApplicationQuitEventHandler),
+								GetEventTypeCount(quit_events),
+								quit_events,
+								NULL,
+								NULL);
+
  	InstallApplicationEventHandler (
  								NewEventHandlerUPP (MainWindowEventHandler),
 								GetEventTypeCount(events),
@@ -496,6 +507,13 @@
 	return result;
 }
 
+// catch quit events to handle quits from menu, Cmd+Q, applescript, and task switcher
+static OSStatus ApplicationQuitEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
+{
+	exit(0);
+//	QuitApplicationEventLoop();
+	return noErr;
+}
 
 //default window command handler (from menus)
 static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler,
@@ -543,11 +561,23 @@
 
 		switch (kind)
 		{
+			// send a quit carbon event instead of directly calling cleanexit 
+			// so that all quits are done in ApplicationQuitEventHandler
 			case kEventWindowClosed:
-				theWindow = NULL;
-				exit(0); // only one window
+				{
+				EventRef quitEvent;
+				CreateEvent(NULL,
+							kEventClassApplication,
+							kEventAppQuit,
+							0,
+							kEventAttributeNone,
+							&quitEvent);
+				EventTargetRef target;
+				target = GetApplicationEventTarget();
+				SendEventToEventTarget(quitEvent, target);
+				}
 				break;
-
+				
 			//resize window
 			case kEventWindowBoundsChanged:
 				window_resized();

  reply	other threads:[~2008-06-24  8:29 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-06  3:06 Michaelian Ennis
2008-04-06  3:15 ` andrey mirtchovski
2008-04-06  3:16   ` erik quanstrom
2008-04-06  3:44     ` andrey mirtchovski
2008-04-06 20:07       ` Michaelian Ennis
2008-04-06 20:52         ` andrey mirtchovski
2008-04-06 21:22           ` Skip Tavakkolian
2008-04-06 21:25             ` andrey mirtchovski
2008-04-08 13:34     ` Anant Narayanan
2008-04-08 14:32       ` Jeff Sickel
2008-04-08 20:27         ` Pietro Gagliardi
2008-04-08 21:09           ` Skip Tavakkolian
2008-06-24  8:29             ` underspecified [this message]
2008-06-24 12:51       ` Uriel
2008-06-24 13:17         ` Pietro Gagliardi
2008-06-24 13:23           ` Bruce Ellis
2008-06-24 13:24           ` sqweek
2008-06-24 13:36             ` erik quanstrom
2008-06-24 13:25           ` a
2008-06-24 13:28           ` Francisco J Ballesteros
2008-06-24 13:17         ` Bruce Ellis
2008-06-24 17:24         ` Russ Cox
2008-06-24 17:45         ` matt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ab4cf6420806240129q62ea1d6eu7959d4cc08518ce9@mail.gmail.com \
    --to=underspecified@gmail.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).