Make menu bar key navigation work on Haiku

* src/haiku_support.cc (menu_bar_active_p): New variable.
(DispatchMessage): Pass through key events if the menu bar is
active.
(MenusBeginning, MenusEnd): Set `menu_bar_active_p' according
to the state of the menu bar.
(BMenuBar_delete): Clear `menu_bar_active_p'.

* src/haikufns.c (haiku_free_frame_resources): Block input only
after checking that F is a window system frame.
* src/haikumenu.c (Fhaiku_menu_bar_open): Update doc string.
This commit is contained in:
Po Lu 2022-01-04 06:48:08 +00:00
parent 693815e90f
commit cbbe235a90
3 changed files with 33 additions and 7 deletions

View file

@ -266,6 +266,7 @@ class EmacsWindow : public BWindow
int zoomed_p = 0;
int shown_flag = 0;
volatile int was_shown_p = 0;
bool menu_bar_active_p = false;
EmacsWindow () : BWindow (BRect (0, 0, 0, 0), "", B_TITLED_WINDOW_LOOK,
B_NORMAL_WINDOW_FEEL, B_NO_SERVER_SIDE_WINDOW_MODIFIERS)
@ -563,6 +564,15 @@ class EmacsWindow : public BWindow
if (msg->what == B_KEY_DOWN || msg->what == B_KEY_UP)
{
struct haiku_key_event rq;
/* Pass through key events to the regular dispatch mechanism
if the menu bar active, so that key navigation can work. */
if (menu_bar_active_p)
{
BWindow::DispatchMessage (msg, handler);
return;
}
rq.window = this;
int32_t code = msg->GetInt32 ("raw_char", 0);
@ -635,6 +645,7 @@ class EmacsWindow : public BWindow
rq.window = this;
haiku_write (MENU_BAR_OPEN, &rq);
menu_bar_active_p = true;
}
void
@ -644,6 +655,7 @@ class EmacsWindow : public BWindow
rq.window = this;
haiku_write (MENU_BAR_CLOSE, &rq);
menu_bar_active_p = false;
}
void
@ -908,6 +920,14 @@ class EmacsMenuBar : public BMenuBar
{
}
void
AttachedToWindow (void)
{
BWindow *window = Window ();
window->SetKeyMenuBar (this);
}
void
FrameResized (float newWidth, float newHeight)
{
@ -2274,8 +2294,14 @@ BMenuBar_delete (void *menubar)
{
BView *vw = (BView *) menubar;
BView *p = vw->Parent ();
EmacsWindow *window = (EmacsWindow *) p->Window ();
if (!p->LockLooper ())
gui_abort ("Failed to lock menu bar parent while removing menubar");
window->SetKeyMenuBar (NULL);
/* MenusEnded isn't called if the menu bar is destroyed
before it closes. */
window->menu_bar_active_p = false;
vw->RemoveSelf ();
p->UnlockLooper ();
delete vw;

View file

@ -1291,8 +1291,8 @@ haiku_free_frame_resources (struct frame *f)
Lisp_Object bar;
struct scroll_bar *b;
block_input ();
check_window_system (f);
block_input ();
hlinfo = MOUSE_HL_INFO (f);
window = FRAME_HAIKU_WINDOW (f);

View file

@ -630,12 +630,12 @@ DEFUN ("menu-or-popup-active-p", Fmenu_or_popup_active_p, Smenu_or_popup_active_
}
DEFUN ("haiku-menu-bar-open", Fhaiku_menu_bar_open, Shaiku_menu_bar_open, 0, 1, "i",
doc: /* Show the menu bar in FRAME.
Move the mouse pointer onto the first element of FRAME's menu bar, and
cause it to be opened. If FRAME is nil or not given, use the selected
frame. If FRAME has no menu bar, a pop-up is displayed at the position
of the last non-menu event instead. */)
doc: /* Show and 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 is nil or not given, use the
selected frame. If FRAME has no menu bar, a pop-up is displayed at
the position of the last non-menu event instead. */)
(Lisp_Object frame)
{
struct frame *f = decode_window_system_frame (frame);