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
111 ksleep(&rend, isready, 0);111 ksleep(&rend, isready, 0);
112}112}
113 113
114// No wonder Apple sells so many wide displays!
115static OSStatus ApplicationQuitEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
114static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);116static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
115static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);117static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
116 118
@@ -165,6 +167,9 @@ void winproc(void *a) · 48 unmodified lines
165 if(PasteboardCreate(kPasteboardClipboard, &appleclip) != noErr)167 if(PasteboardCreate(kPasteboardClipboard, &appleclip) != noErr)
166 sysfatal("pasteboard create failed");168 sysfatal("pasteboard create failed");
167 169
170 const EventTypeSpec quit_events[] = {
171 { kEventClassApplication, kEventAppQuit }
172 };
168 const EventTypeSpec commands[] = {173 const EventTypeSpec commands[] = {
169 { kEventClassWindow, kEventWindowClosed },174 { kEventClassWindow, kEventWindowClosed },
170 { kEventClassWindow, kEventWindowBoundsChanged },175 { kEventClassWindow, kEventWindowBoundsChanged },
@@ -181,6 +186,13 @@ void winproc(void *a) · 10 unmodified lines
181 { kEventClassMouse, kEventMouseWheelMoved },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 InstallApplicationEventHandler (196 InstallApplicationEventHandler (
185 NewEventHandlerUPP (MainWindowEventHandler),197 NewEventHandlerUPP (MainWindowEventHandler),
186 GetEventTypeCount(events),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
344static OSStatus ApplicationQuitEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
345{
346 exit(0);
347// QuitApplicationEventLoop();
348 return noErr;
349}
350
331static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)351static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
332{352{
333 OSStatus result = noErr;353 OSStatus result = noErr;
@@ -517,9 +537,21 @@ static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, · 183 unmodified lines
517 switch (kind)537 switch (kind)
518 {538 {
519 case kEventWindowClosed:539 case kEventWindowClosed:
520 theWindow = NULL;540 // send a quit carbon event instead of directly calling cleanexit
521 exit(0); // only one window541 // so that all quits are done in ApplicationQuitEventHandler
522 break;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 //resize window556 //resize window
525 case kEventWindowBoundsChanged:557 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