From af729b1dfd235de400f6a0998a968222417596bf Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sun, 2 Jan 2022 00:43:54 +0000 Subject: [PATCH] Make quitting actually work in Haiku file dialogs * src/haiku_support.h: (be_popup_file_dialog) * src/haiku_support.cc (be_popup_file_dialog): New parameter `maybe_quit_function'. * src/haikufns.c (Fhaiku_read_file_name): Pass `maybe_quit' as the maybe_quit_function. --- src/haiku_support.cc | 14 +++++++++++--- src/haiku_support.h | 3 ++- src/haikufns.c | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 211d37b8e1a..8bd7c04ee89 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -2624,7 +2624,8 @@ char * be_popup_file_dialog (int open_p, const char *default_dir, int must_match_p, int dir_only_p, void *window, const char *save_text, const char *prompt, void (*block_input_function) (void), - void (*unblock_input_function) (void)) + void (*unblock_input_function) (void), + void (*maybe_quit_function) (void)) { ptrdiff_t idx = c_specpdl_idx_from_cxx (); /* setjmp/longjmp is UB with automatic objects. */ @@ -2635,7 +2636,6 @@ be_popup_file_dialog (int open_p, const char *default_dir, int must_match_p, int BMessage *msg = new BMessage ('FPSE'); BFilePanel *panel = new BFilePanel (open_p ? B_OPEN_PANEL : B_SAVE_PANEL, NULL, NULL, mode); - unblock_input_function (); struct popup_file_dialog_data dat; dat.entry = path; @@ -2660,6 +2660,7 @@ be_popup_file_dialog (int open_p, const char *default_dir, int must_match_p, int panel->Show (); panel->Window ()->Show (); + unblock_input_function (); void *buf = alloca (200); while (1) @@ -2669,19 +2670,26 @@ be_popup_file_dialog (int open_p, const char *default_dir, int must_match_p, int if (!haiku_read_with_timeout (&type, buf, 200, 100000)) { + block_input_function (); if (type != FILE_PANEL_EVENT) haiku_write (type, buf); else if (!ptr) ptr = (char *) ((struct haiku_file_panel_event *) buf)->ptr; + unblock_input_function (); + + maybe_quit_function (); } ssize_t b_s; + block_input_function (); haiku_read_size (&b_s); - if (!b_s || b_s == -1 || ptr || panel->Window ()->IsHidden ()) + if (!b_s || ptr || panel->Window ()->IsHidden ()) { c_unbind_to_nil_from_cxx (idx); + unblock_input_function (); return ptr; } + unblock_input_function (); } } diff --git a/src/haiku_support.h b/src/haiku_support.h index 0377376a02c..dd5e168d140 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h @@ -740,7 +740,8 @@ extern "C" int dir_only_p, void *window, const char *save_text, const char *prompt, void (*block_input_function) (void), - void (*unblock_input_function) (void)); + void (*unblock_input_function) (void), + void (*maybe_quit_function) (void)); extern void record_c_unwind_protect_from_cxx (void (*) (void *), void *); diff --git a/src/haikufns.c b/src/haikufns.c index bf0bf8e5253..743ecf1aef5 100644 --- a/src/haikufns.c +++ b/src/haikufns.c @@ -2236,7 +2236,7 @@ Optional arg SAVE_TEXT, if non-nil, specifies some text to show in the entry fie FRAME_HAIKU_WINDOW (f), !NILP (save_text) ? SSDATA (ENCODE_UTF_8 (save_text)) : NULL, SSDATA (ENCODE_UTF_8 (prompt)), - block_input, unblock_input); + block_input, unblock_input, maybe_quit); unbind_to (idx, Qnil); -- 2.39.5