From a0c44f48272d94d6b62a0759ffa2ce49e69a393d Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 19 Jun 2024 10:57:07 +0800 Subject: [PATCH] Avoid races between the tooltip and compositor on X and Android * java/org/gnu/emacs/EmacsView.java (onLayout): Don't send exposure events when the window is still to be attached. * src/androidfns.c (Fx_show_tip): * src/xfns.c (Fx_show_tip): Block async input around initial frame update. (cherry picked from commit 5fceb53856583384e7adeab52494d1afc6eae666) --- java/org/gnu/emacs/EmacsView.java | 2 +- src/androidfns.c | 7 +++++++ src/xfns.c | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/java/org/gnu/emacs/EmacsView.java b/java/org/gnu/emacs/EmacsView.java index 2ea54217837..82792c3fcca 100644 --- a/java/org/gnu/emacs/EmacsView.java +++ b/java/org/gnu/emacs/EmacsView.java @@ -425,7 +425,7 @@ public final class EmacsView extends ViewGroup window.viewLayout (left, top, right, bottom); } - if (needExpose) + if (needExpose && isAttachedToWindow) EmacsNative.sendExpose (this.window.handle, 0, 0, right - left, bottom - top); } diff --git a/src/androidfns.c b/src/androidfns.c index 4246f6d2be4..84558350dc0 100644 --- a/src/androidfns.c +++ b/src/androidfns.c @@ -2564,9 +2564,16 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0, /* Garbage the tip frame too. */ SET_FRAME_GARBAGED (tip_f); + /* Block input around `update_single_window' and `flush_frame', lest a + ConfigureNotify and Expose event arrive during the update, and set + flags, e.g. garbaged_p, that are cleared once the update completes, + leaving the requested exposure or configuration outstanding. */ + block_input (); w->must_be_updated_p = true; update_single_window (w); flush_frame (tip_f); + unblock_input (); + set_buffer_internal_1 (old_buffer); unbind_to (count_1, Qnil); windows_or_buffers_changed = old_windows_or_buffers_changed; diff --git a/src/xfns.c b/src/xfns.c index c48fa24b6be..4fdcf07e8fb 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -9299,9 +9299,19 @@ Text larger than the specified size is clipped. */) x_cr_update_surface_desired_size (tip_f, width, height); #endif /* USE_CAIRO */ + /* Garbage the tip frame too. */ + SET_FRAME_GARBAGED (tip_f); + + /* Block input around `update_single_window' and `flush_frame', lest a + ConfigureNotify and Expose event arrive during the update, and set + flags, e.g. garbaged_p, that are cleared once the update completes, + leaving the requested exposure or configuration outstanding. */ + block_input (); w->must_be_updated_p = true; update_single_window (w); flush_frame (tip_f); + unblock_input (); + set_buffer_internal_1 (old_buffer); unbind_to (count_1, Qnil); windows_or_buffers_changed = old_windows_or_buffers_changed; -- 2.39.2