unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Alan Third <alan@idiocy.org>
Cc: Robert Pluim <rpluim@gmail.com>, sds@gnu.org, 19120@debbugs.gnu.org
Subject: bug#19120: 25.0.50; macosx: f10 does NOT go to the menu bar
Date: Mon, 25 Oct 2021 19:47:42 +0800	[thread overview]
Message-ID: <87tuh5wckh.fsf@yahoo.com> (raw)
In-Reply-To: <YXZ0DmqbYLb8bd5C@idiocy.org> (Alan Third's message of "Mon, 25 Oct 2021 10:08:30 +0100")

[-- Attachment #1: Type: text/plain, Size: 182 bytes --]

Alan Third <alan@idiocy.org> writes:

> Perhaps we'd be better sticking with NSApplication's
> 'postEvent:atStart:'? I don't know if it can do the same thing.

Thanks, please test.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Support-opening-the-toolkit-menu-bar-on-NS.patch --]
[-- Type: text/x-patch, Size: 4523 bytes --]

From 24c019196c865268a2ad3aedf5706b54b80e4e2c Mon Sep 17 00:00:00 2001
From: Po Lu <luangruo@yahoo.com>
Date: Wed, 20 Oct 2021 10:54:27 +0800
Subject: [PATCH] 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.
---
 lisp/menu-bar.el |  8 ++++---
 src/nsmenu.m     | 55 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/nsterm.m     |  1 +
 3 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el
index fafc99eb95..b66f620276 100644
--- a/lisp/menu-bar.el
+++ b/lisp/menu-bar.el
@@ -2659,9 +2659,10 @@ menu-bar-open
 this is the numeric argument to the command.
 This function decides which method to use to access the menu
 depending on FRAME's terminal device.  On X displays, it calls
-`x-menu-bar-open'; on Windows, `w32-menu-bar-open'; otherwise it
-calls either `popup-menu' or `tmm-menubar' depending on whether
-`tty-menu-open-use-tmm' is nil or not.
+`x-menu-bar-open'; on Windows, `w32-menu-bar-open';
+on NS, `ns-menu-bar-open'; otherwise it calls either `popup-menu'
+or `tmm-menubar' depending on whether `tty-menu-open-use-tmm'
+is nil or not.
 
 If FRAME is nil or not given, use the selected frame."
   (interactive
@@ -2670,6 +2671,7 @@ menu-bar-open
     (cond
      ((eq type 'x) (x-menu-bar-open frame))
      ((eq type 'w32) (w32-menu-bar-open frame))
+     ((eq type 'ns) (ns-menu-bar-open frame))
      ((and (null tty-menu-open-use-tmm)
 	   (not (zerop (or (frame-parameter nil 'menu-bar-lines) 0))))
       ;; Make sure the menu bar is up to date.  One situation where
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 29201e6907..b93d3a79bd 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -439,6 +439,44 @@
   ns_update_menubar (f, deep_p);
 }
 
+void
+ns_activate_menubar (struct frame *frame)
+{
+  if (frame != SELECTED_FRAME ()
+      || !FRAME_EXTERNAL_MENU_BAR (frame))
+    return;
+
+  block_input ();
+  NSApplication *app = [NSApplication sharedApplication];
+  NSMenu *menu = [app mainMenu];
+  for (NSMenuItem *item in [menu itemArray])
+    {
+      if ([item hasSubmenu])
+	{
+#ifdef NS_IMPL_GNUSTEP
+	  [[item submenu] display];
+#else
+	  NSWindow *window = [FRAME_NS_VIEW (frame) window];
+	  NSScreen *screen = [window screen];
+
+	  NSRect screen_frame = [screen frame];
+	  [app postEvent: [NSEvent mouseEventWithType: NSLeftMouseDown
+					     location: NSMakePoint (NSMinX (screen_frame),
+								    NSMinY (screen_frame) + 10)
+					modifierFlags: 0
+					    timestamp: 0
+					 windowNumber: [window windowNumber]
+					      context: [NSGraphicsContext currentContext]
+					  eventNumber: 0
+					   clickCount: 1
+					     pressure: 1.0f]
+		 atStart: YES];
+#endif
+	  break;
+	}
+    }
+  unblock_input ();
+}
 
 /* ==========================================================================
 
@@ -1916,6 +1954,22 @@ - (Lisp_Object)runDialogAt: (NSPoint)p
   return popup_activated () ? Qt : Qnil;
 }
 
+DEFUN ("ns-menu-bar-open", Fns_menu_bar_open, Sns_menu_bar_open, 0, 1, "i",
+       doc: /* Start key navigation of the menu bar in FRAME.
+This initially opens the first menu bar item and you can then navigate with the
+arrow keys, select a menu entry with the return key or cancel with the
+escape key.  If FRAME has no menu bar this function does nothing.
+
+If FRAME is nil or not given, use the selected frame.  */)
+  (Lisp_Object frame)
+{
+  struct frame *f = decode_window_system_frame (frame);
+
+  ns_activate_menubar (f);
+
+  return Qnil;
+}
+
 /* ==========================================================================
 
     Lisp interface declaration
@@ -1927,6 +1981,7 @@ - (Lisp_Object)runDialogAt: (NSPoint)p
 {
   defsubr (&Sns_reset_menu);
   defsubr (&Smenu_or_popup_active_p);
+  defsubr (&Sns_menu_bar_open);
 
   DEFSYM (Qdebug_on_next_call, "debug-on-next-call");
 }
diff --git a/src/nsterm.m b/src/nsterm.m
index c10b6feca1..d9c28cb191 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -5078,6 +5078,7 @@ static Lisp_Object ns_new_font (struct frame *f, Lisp_Object font_object,
   terminal->delete_frame_hook = ns_destroy_window;
   terminal->delete_terminal_hook = ns_delete_terminal;
   terminal->change_tab_bar_height_hook = ns_change_tab_bar_height;
+  terminal->activate_menubar_hook = ns_activate_menubar;
   /* Other hooks are NULL by default.  */
 
   return terminal;
-- 
2.31.1


  reply	other threads:[~2021-10-25 11:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-20 16:27 bug#19120: 25.0.50; macosx: f10 does NOT go to the menu bar Sam Steingold
2015-04-11  9:15 ` Jan D.
2015-04-12  7:29   ` Sam Steingold
2015-04-12  8:04     ` Jan D.
2015-04-14 20:41       ` Sam Steingold
2015-04-19  7:44         ` Jan D.
2021-10-20  2:59           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-20  9:53             ` Robert Pluim
2021-10-20 10:26               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-20 12:36                 ` Robert Pluim
2021-10-20 20:47                   ` Alan Third
2021-10-21  0:21                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-23 10:18                       ` Alan Third
2021-10-24  7:14                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-24  7:15                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-24  9:36                           ` Alan Third
2021-10-24  9:49                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-25  9:08                               ` Alan Third
2021-10-25 11:47                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-11-24 22:54                                   ` Alan Third
2021-11-25  0:43                                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tuh5wckh.fsf@yahoo.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=19120@debbugs.gnu.org \
    --cc=alan@idiocy.org \
    --cc=luangruo@yahoo.com \
    --cc=rpluim@gmail.com \
    --cc=sds@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).