File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ - (IBAction)menuCallback:(id)sender {
4040static NSStatusBar *statusBar;
4141static NSStatusItem *statusItem;
4242
43+ #define QUIT_EVENT_SUBTYPE 0x0DED // /< NSEvent subtype used to signal exit.
44+
4345static NSMenu *_tray_menu (struct tray_menu *m) {
4446 NSMenu *menu = [[NSMenu alloc ] init ];
4547 [menu setAutoenablesItems: FALSE ];
@@ -82,6 +84,10 @@ int tray_loop(int blocking) {
8284 inMode: [NSString stringWithUTF8String: " kCFRunLoopDefaultMode" ]
8385 dequeue: TRUE ];
8486 if (event) {
87+ if (event.type == NSEventTypeApplicationDefined && event.subtype == QUIT_EVENT_SUBTYPE ) {
88+ return -1 ;
89+ }
90+
8591 [app sendEvent: event];
8692 }
8793 return 0 ;
@@ -96,5 +102,14 @@ void tray_update(struct tray *tray) {
96102}
97103
98104void tray_exit (void ) {
99- [app terminate: app];
105+ NSEvent *event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
106+ location: NSMakePoint (0 , 0 )
107+ modifierFlags: 0
108+ timestamp: 0
109+ windowNumber: 0
110+ context: nil
111+ subtype: QUIT_EVENT_SUBTYPE
112+ data1: 0
113+ data2: 0 ];
114+ [app postEvent: event atStart: FALSE ];
100115}
Original file line number Diff line number Diff line change @@ -317,10 +317,10 @@ void tray_update(struct tray *tray) {
317317
318318void tray_exit (void ) {
319319 Shell_NotifyIconW (NIM_DELETE , & nid );
320+ SendMessage (hwnd , WM_CLOSE , 0 , 0 );
320321 _destroy_icon_cache ();
321322 if (hmenu != 0 ) {
322323 DestroyMenu (hmenu );
323324 }
324- PostQuitMessage (0 );
325325 UnregisterClass (WC_TRAY_CLASS_NAME , GetModuleHandle (NULL ));
326326}
You can’t perform that action at this time.
0 commit comments