Unified · Split
| @@ -111,6 +111,8 @@ void screeninit(void) · 110 unmodified lines | ||
| 111 | 111 | ksleep(&rend, isready, 0); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | +// No wonder Apple sells so many wide displays! | |
| 115 | +static OSStatus ApplicationQuitEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData); | |
| 114 | 116 | static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData); |
| 115 | 117 | static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData); |
| 116 | 118 | |
| @@ -165,6 +167,9 @@ void winproc(void *a) · 48 unmodified lines | ||
| 165 | 167 | if(PasteboardCreate(kPasteboardClipboard, &appleclip) != noErr) |
| 166 | 168 | sysfatal("pasteboard create failed"); |
| 167 | 169 | |
| 170 | + const EventTypeSpec quit_events[] = { | |
| 171 | + { kEventClassApplication, kEventAppQuit } | |
| 172 | + }; | |
| 168 | 173 | const EventTypeSpec commands[] = { |
| 169 | 174 | { kEventClassWindow, kEventWindowClosed }, |
| 170 | 175 | { kEventClassWindow, kEventWindowBoundsChanged }, |
| @@ -181,6 +186,13 @@ void winproc(void *a) · 10 unmodified lines | ||
| 181 | 186 | { kEventClassMouse, kEventMouseWheelMoved }, |
| 182 | 187 | }; |
| 183 | 188 | |
| 189 | + InstallApplicationEventHandler ( | |
| 190 | + NewEventHandlerUPP (ApplicationQuitEventHandler), | |
| 191 | + GetEventTypeCount(quit_events), | |
| 192 | + quit_events, | |
| 193 | + NULL, | |
| 194 | + NULL); | |
| 195 | + | |
| 184 | 196 | InstallApplicationEventHandler ( |
| 185 | 197 | NewEventHandlerUPP (MainWindowEventHandler), |
| 186 | 198 | GetEventTypeCount(events), |
| @@ -328,6 +340,14 @@ full_screen() · 141 unmodified lines | ||
| 328 | 340 | } |
| 329 | 341 | } |
| 330 | 342 | |
| 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 | + | |
| 331 | 351 | static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) |
| 332 | 352 | { |
| 333 | 353 | OSStatus result = noErr; |
| @@ -517,9 +537,21 @@ static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, · 183 unmodified lines | ||
| 517 | 537 | switch (kind) |
| 518 | 538 | { |
| 519 | 539 | 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; | |
| 523 | 555 | |
| 524 | 556 | //resize window |
| 525 | 557 | case kEventWindowBoundsChanged: |