From 9cf69e1171d0621cf464794b4a6adcb766c99b54 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 9 Mar 2022 03:21:36 +0000 Subject: [PATCH] Improve handling of tooltips inside menus on Haiku * src/haiku_support.cc (BMenu_run): Make `process_pending_signals_function' return a struct timespec. * src/haiku_support.h: Update prototypes. * src/haikumenu.c (haiku_process_pending_signals_for_menu): Return result of `timer_run'. * src/haikuterm.c (haiku_flush): Flip buffers if frame is dirty. --- src/haiku_support.cc | 23 ++++++++++++++++++----- src/haiku_support.h | 2 +- src/haikumenu.c | 5 ++--- src/haikuterm.c | 7 ++++++- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 057464c9088..2f2adfd8f8a 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -2697,7 +2697,7 @@ BMenu_run (void *menu, int x, int y, void (*run_help_callback) (void *, void *), void (*block_input_function) (void), void (*unblock_input_function) (void), - void (*process_pending_signals_function) (void), + struct timespec (*process_pending_signals_function) (void), void *run_help_callback_data) { BPopUpMenu *mn = (BPopUpMenu *) menu; @@ -2705,10 +2705,12 @@ BMenu_run (void *menu, int x, int y, void *buf; void *ptr = NULL; struct be_popup_menu_data data; - struct object_wait_info infos[2]; + struct object_wait_info infos[3]; struct haiku_menu_bar_help_event *event; BMessage *msg; ssize_t stat; + struct timespec next_time; + bigtime_t timeout; block_input_function (); port_popup_menu_to_emacs = create_port (1800, "popup menu port"); @@ -2733,6 +2735,10 @@ BMenu_run (void *menu, int x, int y, (void *) &data); infos[1].type = B_OBJECT_TYPE_THREAD; infos[1].events = B_EVENT_INVALID; + + infos[2].object = port_application_to_emacs; + infos[2].type = B_OBJECT_TYPE_PORT; + infos[2].events = B_EVENT_READ; unblock_input_function (); if (infos[1].object < B_OK) @@ -2749,10 +2755,16 @@ BMenu_run (void *menu, int x, int y, while (true) { - process_pending_signals_function (); + next_time = process_pending_signals_function (); + + if (next_time.tv_nsec < 0) + timeout = 100000; + else + timeout = (next_time.tv_sec * 1000000 + + next_time.tv_nsec / 1000); - if ((stat = wait_for_objects_etc ((object_wait_info *) &infos, 2, - B_RELATIVE_TIMEOUT, 10000)) < B_OK) + if ((stat = wait_for_objects_etc ((object_wait_info *) &infos, 3, + B_RELATIVE_TIMEOUT, timeout)) < B_OK) { if (stat == B_INTERRUPTED || stat == B_TIMED_OUT) continue; @@ -2792,6 +2804,7 @@ BMenu_run (void *menu, int x, int y, infos[0].events = B_EVENT_READ; infos[1].events = B_EVENT_INVALID; + infos[2].events = B_EVENT_READ; } } diff --git a/src/haiku_support.h b/src/haiku_support.h index 04079edbbc5..fb86372c4ff 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h @@ -744,7 +744,7 @@ extern "C" void (*run_help_callback) (void *, void *), void (*block_input_function) (void), void (*unblock_input_function) (void), - void (*process_pending_signals_function) (void), + struct timespec (*process_pending_signals_function) (void), void *run_help_callback_data); extern void diff --git a/src/haikumenu.c b/src/haikumenu.c index 74328086d6f..2f75a5dd03e 100644 --- a/src/haikumenu.c +++ b/src/haikumenu.c @@ -340,13 +340,12 @@ haiku_menu_show_help (void *help, void *data) show_help_echo (Qnil, Qnil, Qnil, Qnil); } -static void +static struct timespec haiku_process_pending_signals_for_menu (void) { process_pending_signals (); - input_pending = false; - detect_input_pending_run_timers (true); + return timer_check (); } Lisp_Object diff --git a/src/haikuterm.c b/src/haikuterm.c index 633e87fd435..3950e45fe9b 100644 --- a/src/haikuterm.c +++ b/src/haikuterm.c @@ -2513,7 +2513,12 @@ haiku_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, static void haiku_flush (struct frame *f) { - if (FRAME_VISIBLE_P (f)) + /* This is needed for tooltip frames to work properly with double + buffering. */ + if (FRAME_DIRTY_P (f)) + haiku_flip_buffers (f); + + if (FRAME_VISIBLE_P (f) && !FRAME_TOOLTIP_P (f)) BWindow_Flush (FRAME_HAIKU_WINDOW (f)); } -- 2.39.2