diff options
| author | oldosfan | 2021-10-20 10:54:27 +0800 |
|---|---|---|
| committer | Po Lu | 2021-11-10 13:27:01 +0800 |
| commit | ff9cf991c1608cd2578a66cba41e654a2b5d9144 (patch) | |
| tree | f8a1078aa379dda2273e420fa5135064c4660164 /src | |
| parent | 7117bbc7aa905ae785fa564cb24c3fc75ef1d543 (diff) | |
| download | emacs-ff9cf991c1608cd2578a66cba41e654a2b5d9144.tar.gz emacs-ff9cf991c1608cd2578a66cba41e654a2b5d9144.zip | |
Support opening the toolkit menu bar on NS
* src/nsmenu.m (ns_activate_menubar, Fns_open_menubar): New functions.
* src/nsterm.m (ns_create_terminal): Add activate_menubar_hook.
* lisp/menu-bar.el (menu-bar-open): Use ns-menu-bar-open on Nextstep.
Diffstat (limited to 'src')
| -rw-r--r-- | src/nsmenu.m | 55 | ||||
| -rw-r--r-- | src/nsterm.m | 1 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/nsmenu.m b/src/nsmenu.m index 29201e69079..b93d3a79bdc 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m | |||
| @@ -439,6 +439,44 @@ set_frame_menubar (struct frame *f, bool deep_p) | |||
| 439 | ns_update_menubar (f, deep_p); | 439 | ns_update_menubar (f, deep_p); |
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | void | ||
| 443 | ns_activate_menubar (struct frame *frame) | ||
| 444 | { | ||
| 445 | if (frame != SELECTED_FRAME () | ||
| 446 | || !FRAME_EXTERNAL_MENU_BAR (frame)) | ||
| 447 | return; | ||
| 448 | |||
| 449 | block_input (); | ||
| 450 | NSApplication *app = [NSApplication sharedApplication]; | ||
| 451 | NSMenu *menu = [app mainMenu]; | ||
| 452 | for (NSMenuItem *item in [menu itemArray]) | ||
| 453 | { | ||
| 454 | if ([item hasSubmenu]) | ||
| 455 | { | ||
| 456 | #ifdef NS_IMPL_GNUSTEP | ||
| 457 | [[item submenu] display]; | ||
| 458 | #else | ||
| 459 | NSWindow *window = [FRAME_NS_VIEW (frame) window]; | ||
| 460 | NSScreen *screen = [window screen]; | ||
| 461 | |||
| 462 | NSRect screen_frame = [screen frame]; | ||
| 463 | [app postEvent: [NSEvent mouseEventWithType: NSLeftMouseDown | ||
| 464 | location: NSMakePoint (NSMinX (screen_frame), | ||
| 465 | NSMinY (screen_frame) + 10) | ||
| 466 | modifierFlags: 0 | ||
| 467 | timestamp: 0 | ||
| 468 | windowNumber: [window windowNumber] | ||
| 469 | context: [NSGraphicsContext currentContext] | ||
| 470 | eventNumber: 0 | ||
| 471 | clickCount: 1 | ||
| 472 | pressure: 1.0f] | ||
| 473 | atStart: YES]; | ||
| 474 | #endif | ||
| 475 | break; | ||
| 476 | } | ||
| 477 | } | ||
| 478 | unblock_input (); | ||
| 479 | } | ||
| 442 | 480 | ||
| 443 | /* ========================================================================== | 481 | /* ========================================================================== |
| 444 | 482 | ||
| @@ -1916,6 +1954,22 @@ DEFUN ("menu-or-popup-active-p", Fmenu_or_popup_active_p, Smenu_or_popup_active_ | |||
| 1916 | return popup_activated () ? Qt : Qnil; | 1954 | return popup_activated () ? Qt : Qnil; |
| 1917 | } | 1955 | } |
| 1918 | 1956 | ||
| 1957 | DEFUN ("ns-menu-bar-open", Fns_menu_bar_open, Sns_menu_bar_open, 0, 1, "i", | ||
| 1958 | doc: /* Start key navigation of the menu bar in FRAME. | ||
| 1959 | This initially opens the first menu bar item and you can then navigate with the | ||
| 1960 | arrow keys, select a menu entry with the return key or cancel with the | ||
| 1961 | escape key. If FRAME has no menu bar this function does nothing. | ||
| 1962 | |||
| 1963 | If FRAME is nil or not given, use the selected frame. */) | ||
| 1964 | (Lisp_Object frame) | ||
| 1965 | { | ||
| 1966 | struct frame *f = decode_window_system_frame (frame); | ||
| 1967 | |||
| 1968 | ns_activate_menubar (f); | ||
| 1969 | |||
| 1970 | return Qnil; | ||
| 1971 | } | ||
| 1972 | |||
| 1919 | /* ========================================================================== | 1973 | /* ========================================================================== |
| 1920 | 1974 | ||
| 1921 | Lisp interface declaration | 1975 | Lisp interface declaration |
| @@ -1927,6 +1981,7 @@ syms_of_nsmenu (void) | |||
| 1927 | { | 1981 | { |
| 1928 | defsubr (&Sns_reset_menu); | 1982 | defsubr (&Sns_reset_menu); |
| 1929 | defsubr (&Smenu_or_popup_active_p); | 1983 | defsubr (&Smenu_or_popup_active_p); |
| 1984 | defsubr (&Sns_menu_bar_open); | ||
| 1930 | 1985 | ||
| 1931 | DEFSYM (Qdebug_on_next_call, "debug-on-next-call"); | 1986 | DEFSYM (Qdebug_on_next_call, "debug-on-next-call"); |
| 1932 | } | 1987 | } |
diff --git a/src/nsterm.m b/src/nsterm.m index ed0e7a2aae8..4e84e130b89 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -5067,6 +5067,7 @@ ns_create_terminal (struct ns_display_info *dpyinfo) | |||
| 5067 | terminal->delete_frame_hook = ns_destroy_window; | 5067 | terminal->delete_frame_hook = ns_destroy_window; |
| 5068 | terminal->delete_terminal_hook = ns_delete_terminal; | 5068 | terminal->delete_terminal_hook = ns_delete_terminal; |
| 5069 | terminal->change_tab_bar_height_hook = ns_change_tab_bar_height; | 5069 | terminal->change_tab_bar_height_hook = ns_change_tab_bar_height; |
| 5070 | terminal->activate_menubar_hook = ns_activate_menubar; | ||
| 5070 | /* Other hooks are NULL by default. */ | 5071 | /* Other hooks are NULL by default. */ |
| 5071 | 5072 | ||
| 5072 | return terminal; | 5073 | return terminal; |