From 29bf6e64fdad648642a79915d63fe543fdeaff8b Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 18 Apr 2022 00:50:15 +0000 Subject: [PATCH] Fix Haiku menu bars when redisplay happens immediately after activation * src/haiku_support.cc (MessageReceived): Make `REPLAY_MENU_BAR' messages synchronous. (be_replay_menu_bar_event): Return whether or not the menu bar really opened. * src/haiku_support.h: Update prototypes. * src/haikumenu.c (haiku_activate_menubar): Immediately activate menu bar after replaying event. --- src/haiku_support.cc | 22 ++++++++++++++++++---- src/haiku_support.h | 2 +- src/haikumenu.c | 10 ++++++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 673ae02ac9c..1feea6c4502 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -1335,7 +1335,7 @@ public: window->menus_begun = &menus_begun; set_mouse_position (pt.x, pt.y); - MouseDown (l); + BMenuBar::MouseDown (l); window->menus_begun = NULL; if (!menus_begun) @@ -1345,8 +1345,19 @@ public: } else if (msg->what == REPLAY_MENU_BAR) { + window = (EmacsWindow *) Window (); + menus_begun = false; + window->menus_begun = &menus_begun; + if (msg->FindPoint ("emacs:point", &pt) == B_OK) BMenuBar::MouseDown (pt); + + window->menus_begun = NULL; + + if (!menus_begun) + msg->SendReply (msg); + else + msg->SendReply (BE_MENU_BAR_OPEN); } else BMenuBar::MessageReceived (msg); @@ -4261,14 +4272,17 @@ be_drag_and_drop_in_progress (void) return drag_and_drop_in_progress; } -void +/* Replay the menu bar click event EVENT. Return whether or not the + menu bar actually opened. */ +bool be_replay_menu_bar_event (void *menu_bar, struct haiku_menu_bar_click_event *event) { BMenuBar *m = (BMenuBar *) menu_bar; BMessenger messenger (m); - BMessage msg (REPLAY_MENU_BAR); + BMessage reply, msg (REPLAY_MENU_BAR); msg.AddPoint ("emacs:point", BPoint (event->x, event->y)); - messenger.SendMessage (&msg); + messenger.SendMessage (&msg, &reply); + return reply.what == BE_MENU_BAR_OPEN; } diff --git a/src/haiku_support.h b/src/haiku_support.h index 6b285cf3e0a..4718be4f84a 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h @@ -636,7 +636,7 @@ extern bool be_drag_message (void *, void *, bool, void (*) (void), bool (*) (void)); extern bool be_drag_and_drop_in_progress (void); -extern void be_replay_menu_bar_event (void *, struct haiku_menu_bar_click_event *); +extern bool be_replay_menu_bar_event (void *, struct haiku_menu_bar_click_event *); #ifdef __cplusplus extern void *find_appropriate_view_for_draw (void *); diff --git a/src/haikumenu.c b/src/haikumenu.c index 46dde6496bb..54ee3f160f6 100644 --- a/src/haikumenu.c +++ b/src/haikumenu.c @@ -783,11 +783,17 @@ haiku_activate_menubar (struct frame *f) if (FRAME_OUTPUT_DATA (f)->saved_menu_event) { block_input (); - be_replay_menu_bar_event (FRAME_HAIKU_MENU_BAR (f), - FRAME_OUTPUT_DATA (f)->saved_menu_event); + rc = be_replay_menu_bar_event (FRAME_HAIKU_MENU_BAR (f), + FRAME_OUTPUT_DATA (f)->saved_menu_event); xfree (FRAME_OUTPUT_DATA (f)->saved_menu_event); FRAME_OUTPUT_DATA (f)->saved_menu_event = NULL; unblock_input (); + + if (!rc) + return; + + FRAME_OUTPUT_DATA (f)->menu_bar_open_p = 1; + popup_activated_p += 1; } else { -- 2.39.2