History

better handling of quit events (underspecified@gmail)

Russ Cox committed 18 years ago

Commit 347c54d1 parent 6c519f31 file · +35 −3Browse files

Unified · Split

gui-osx/screen.c+35−3
@@ -111,6 +111,8 @@ void screeninit(void) · 110 unmodified lines
111111 ksleep(&rend, isready, 0);
112112 }
113113
114+// No wonder Apple sells so many wide displays!
115+static OSStatus ApplicationQuitEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
114116 static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
115117 static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
116118
@@ -165,6 +167,9 @@ void winproc(void *a) · 48 unmodified lines
165167 if(PasteboardCreate(kPasteboardClipboard, &appleclip) != noErr)
166168 sysfatal("pasteboard create failed");
167169
170+ const EventTypeSpec quit_events[] = {
171+ { kEventClassApplication, kEventAppQuit }
172+ };
168173 const EventTypeSpec commands[] = {
169174 { kEventClassWindow, kEventWindowClosed },
170175 { kEventClassWindow, kEventWindowBoundsChanged },
@@ -181,6 +186,13 @@ void winproc(void *a) · 10 unmodified lines
181186 { kEventClassMouse, kEventMouseWheelMoved },
182187 };
183188
189+ InstallApplicationEventHandler (
190+ NewEventHandlerUPP (ApplicationQuitEventHandler),
191+ GetEventTypeCount(quit_events),
192+ quit_events,
193+ NULL,
194+ NULL);
195+
184196 InstallApplicationEventHandler (
185197 NewEventHandlerUPP (MainWindowEventHandler),
186198 GetEventTypeCount(events),
@@ -328,6 +340,14 @@ full_screen() · 141 unmodified lines
328340 }
329341 }
330342
343+// catch quit events to handle quits from menu, Cmd+Q, applescript, and task switcher
344+static OSStatus ApplicationQuitEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
345+{
346+ exit(0);
347+// QuitApplicationEventLoop();
348+ return noErr;
349+}
350+
331351 static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
332352 {
333353 OSStatus result = noErr;
@@ -517,9 +537,21 @@ static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, · 183 unmodified lines
517537 switch (kind)
518538 {
519539 case kEventWindowClosed:
520− theWindow = NULL;
521− exit(0); // only one window
522− break;
540+ // send a quit carbon event instead of directly calling cleanexit
541+ // so that all quits are done in ApplicationQuitEventHandler
542+ {
543+ EventRef quitEvent;
544+ CreateEvent(NULL,
545+ kEventClassApplication,
546+ kEventAppQuit,
547+ 0,
548+ kEventAttributeNone,
549+ &quitEvent);
550+ EventTargetRef target;
551+ target = GetApplicationEventTarget();
552+ SendEventToEventTarget(quitEvent, target);
553+ }
554+ break;
523555
524556 //resize window
525557 case kEventWindowBoundsChanged:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t