aboutsummaryrefslogtreecommitdiffstats
path: root/src/nsmenu.m
diff options
context:
space:
mode:
authorJan Djärv2011-12-18 15:50:19 +0100
committerJan Djärv2011-12-18 15:50:19 +0100
commit5fecd5fce0bac31f1d39d84caa9d2c444c8e7e01 (patch)
tree884906787db3c2cb7af26ca28e9e25f3f0e5a58a /src/nsmenu.m
parentc803b2b767f8ed06beb28106a03f23bc577cfdae (diff)
downloademacs-5fecd5fce0bac31f1d39d84caa9d2c444c8e7e01.tar.gz
emacs-5fecd5fce0bac31f1d39d84caa9d2c444c8e7e01.zip
Adapt code from AquaEmacs to handle occasional blank menus.
* nsmenu.m (trackingMenu): New variable. (NSMenuDidBeginTrackingNotification): Declare if OSX < 10.5 and NS_IMPL_COCOA. (trackingNotification): New method (from AquaEmacs). (menuNeedsUpdate): Expand comment and return if trackingMenu is 0, from AquaEmacs. (syms_of_nsmenu): Set trackingMenu to 1 if not NS_IMPL_COCOA. * nsterm.m (ns_term_init): Subscribe for notifications NSMenuDidBeginTrackingNotification and NSMenuDidEndTrackingNotification to method trackingNotification in EmacsMenu. Fixes: debbugs:7030
Diffstat (limited to 'src/nsmenu.m')
-rw-r--r--src/nsmenu.m44
1 files changed, 38 insertions, 6 deletions
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 951282910ac..d599cdb6ce5 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -74,6 +74,10 @@ EmacsMenu *mainMenu, *svcsMenu, *dockMenu;
74static int popup_activated_flag; 74static int popup_activated_flag;
75static NSModalSession popupSession; 75static NSModalSession popupSession;
76 76
77/* Nonzero means we are tracking and updating menus. */
78static int trackingMenu;
79
80
77/* NOTE: toolbar implementation is at end, 81/* NOTE: toolbar implementation is at end,
78 following complete menu implementation. */ 82 following complete menu implementation. */
79 83
@@ -543,21 +547,44 @@ set_frame_menubar (struct frame *f, int first_time, int deep_p)
543 frame = f; 547 frame = f;
544} 548}
545 549
550#ifdef NS_IMPL_COCOA
551#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
552extern NSString *NSMenuDidBeginTrackingNotification;
553#endif
554#endif
555
556#ifdef NS_IMPL_COCOA
557-(void)trackingNotification:(NSNotification *)notification
558{
559 /* Update menu in menuNeedsUpdate only while tracking menus. */
560 trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification
561 ? 1 : 0);
562}
563#endif
546 564
547/* delegate method called when a submenu is being opened: run a 'deep' call 565/* delegate method called when a submenu is being opened: run a 'deep' call
548 to set_frame_menubar */ 566 to set_frame_menubar */
549- (void)menuNeedsUpdate: (NSMenu *)menu 567- (void)menuNeedsUpdate: (NSMenu *)menu
550{ 568{
551 NSEvent *event;
552 if (!FRAME_LIVE_P (frame)) 569 if (!FRAME_LIVE_P (frame))
553 return; 570 return;
554 event = [[FRAME_NS_VIEW (frame) window] currentEvent]; 571
555 /* HACK: Cocoa/Carbon will request update on every keystroke 572 /* Cocoa/Carbon will request update on every keystroke
556 via IsMenuKeyEvent -> CheckMenusForKeyEvent. These are not needed 573 via IsMenuKeyEvent -> CheckMenusForKeyEvent. These are not needed
557 since key equivalents are handled through emacs. 574 since key equivalents are handled through emacs.
558 On Leopard, even keystroke events generate SystemDefined events, but 575 On Leopard, even keystroke events generate SystemDefined event.
559 their subtype is 8. */ 576 Third-party applications that enhance mouse / trackpad
560 if ([event type] != NSSystemDefined || [event subtype] == 8 577 interaction, or also VNC/Remote Desktop will send events
578 of type AppDefined rather than SysDefined.
579 Menus will fail to show up if they haven't been initialized.
580 AppDefined events may lack timing data.
581
582 Thus, we rely on the didBeginTrackingNotification notification
583 as above to indicate the need for updates.
584 From 10.6 on, we could also use -[NSMenu propertiesToUpdate]: In the
585 key press case, NSMenuPropertyItemImage (e.g.) won't be set.
586 */
587 if (trackingMenu == 0
561 /* Also, don't try this if from an event picked up asynchronously, 588 /* Also, don't try this if from an event picked up asynchronously,
562 as lots of lisp evaluation happens in ns_update_menubar. */ 589 as lots of lisp evaluation happens in ns_update_menubar. */
563 || handling_signal != 0) 590 || handling_signal != 0)
@@ -1795,6 +1822,11 @@ DEFUN ("menu-or-popup-active-p", Fmenu_or_popup_active_p, Smenu_or_popup_active_
1795void 1822void
1796syms_of_nsmenu (void) 1823syms_of_nsmenu (void)
1797{ 1824{
1825#ifndef NS_IMPL_COCOA
1826 /* Don't know how to keep track of this in Next/Open/Gnustep. Always
1827 update menus there. */
1828 trackingMenu = 1;
1829#endif
1798 defsubr (&Sx_popup_dialog); 1830 defsubr (&Sx_popup_dialog);
1799 defsubr (&Sns_reset_menu); 1831 defsubr (&Sns_reset_menu);
1800 defsubr (&Smenu_or_popup_active_p); 1832 defsubr (&Smenu_or_popup_active_p);