From bca68550844da7849ab33616345525918e82f3c8 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 26 Jan 2022 01:20:48 +0000 Subject: [PATCH] Make `haiku-menu-bar-open' faster * src/haikumenu.c (Fhaiku_menu_bar_open): Get draw lock before updating the menu bar. * src/haikuterm.c (haiku_read_socket): Don't update menu bar if b->no_lock. --- src/haikumenu.c | 13 ++++++++----- src/haikuterm.c | 28 +++++++++++++++++++--------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/haikumenu.c b/src/haikumenu.c index 3fee5831608..b73baf72e05 100644 --- a/src/haikumenu.c +++ b/src/haikumenu.c @@ -644,17 +644,20 @@ the position of the last non-menu event instead. */) struct frame *f = decode_window_system_frame (frame); if (FRAME_EXTERNAL_MENU_BAR (f)) - set_frame_menubar (f, 1); + { + block_input (); + BView_draw_lock (FRAME_HAIKU_VIEW (f)); + set_frame_menubar (f, 1); + BMenuBar_start_tracking (FRAME_HAIKU_MENU_BAR (f)); + BView_draw_unlock (FRAME_HAIKU_VIEW (f)); + unblock_input (); + } else { return call2 (Qpopup_menu, call0 (Qmouse_menu_bar_map), last_nonmenu_event); } - block_input (); - BMenuBar_start_tracking (FRAME_HAIKU_MENU_BAR (f)); - unblock_input (); - return Qnil; } diff --git a/src/haikuterm.c b/src/haikuterm.c index c8cc02a2988..e7d596cec3d 100644 --- a/src/haikuterm.c +++ b/src/haikuterm.c @@ -3178,15 +3178,25 @@ haiku_read_socket (struct terminal *terminal, struct input_event *hold_quit) if (type == MENU_BAR_OPEN) { - BView_draw_lock (FRAME_HAIKU_VIEW (f)); - /* This shouldn't be here, but nsmenu does it, so - it should probably be safe. */ - int was_waiting_for_input_p = waiting_for_input; - if (waiting_for_input) - waiting_for_input = 0; - set_frame_menubar (f, 1); - waiting_for_input = was_waiting_for_input_p; - BView_draw_unlock (FRAME_HAIKU_VIEW (f)); + /* b->no_lock means that MenusBeginning was called + from the main thread, which means tracking was + started manually, and we have already updated the + menu bar. */ + if (!b->no_lock) + { + BView_draw_lock (FRAME_HAIKU_VIEW (f)); + /* This shouldn't be here, but nsmenu does it, so + it should probably be safe. */ + int was_waiting_for_input_p = waiting_for_input; + if (waiting_for_input) + waiting_for_input = 0; + set_frame_menubar (f, 1); + waiting_for_input = was_waiting_for_input_p; + BView_draw_unlock (FRAME_HAIKU_VIEW (f)); + } + + /* But set the flag anyway, because the menu will end + from the window thread. */ FRAME_OUTPUT_DATA (f)->menu_bar_open_p = 1; popup_activated_p += 1; -- 2.39.2