From: Po Lu Date: Wed, 8 Jun 2022 12:04:26 +0000 (+0800) Subject: Simplify XDND toplevel freeing code X-Git-Tag: emacs-29.0.90~1910^2~153 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b8e0f2e827744da8dc0454c4220c5c9de2ecd368;p=emacs.git Simplify XDND toplevel freeing code * src/xterm.c (x_free_dnd_toplevels): New function. (x_dnd_cleanup_drag_and_drop, x_dnd_begin_drag_and_drop): Record an unwind function to free DND toplevels instead of doing that manually everywhere. --- diff --git a/src/xterm.c b/src/xterm.c index 1f4d301e6a5..00586d66a07 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -4163,6 +4163,18 @@ x_free_dnd_targets (void) x_dnd_n_targets = 0; } +static void +x_free_dnd_toplevels (void) +{ + if (!x_dnd_use_toplevels || !x_dnd_toplevels) + return; + + /* If the display is deleted, x_dnd_toplevels will already be + NULL, so we can always assume the display is alive here. */ + + x_dnd_free_toplevels (true); +} + static void x_dnd_cleanup_drag_and_drop (void *frame) { @@ -4216,9 +4228,6 @@ x_dnd_cleanup_drag_and_drop (void *frame) x_dnd_waiting_for_finish = false; - if (x_dnd_use_toplevels) - x_dnd_free_toplevels (true); - FRAME_DISPLAY_INFO (f)->grabbed = 0; #ifdef USE_GTK current_hold_quit = NULL; @@ -10960,6 +10969,8 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction, x_dnd_free_toplevels (true); x_dnd_use_toplevels = false; } + else + record_unwind_protect_void (x_free_dnd_toplevels); } if (!NILP (return_frame)) @@ -11132,10 +11143,6 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction, } x_dnd_waiting_for_finish = false; - - if (x_dnd_use_toplevels) - x_dnd_free_toplevels (true); - x_dnd_return_frame_object = NULL; x_dnd_movement_frame = NULL; @@ -11223,10 +11230,6 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction, } x_dnd_waiting_for_finish = false; - - if (x_dnd_use_toplevels) - x_dnd_free_toplevels (true); - x_dnd_return_frame_object = NULL; x_dnd_movement_frame = NULL; @@ -11287,9 +11290,6 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction, FRAME_DISPLAY_INFO (f)->Xatom_XdndSelection); unblock_input (); - if (x_dnd_use_toplevels) - x_dnd_free_toplevels (true); - if (x_dnd_return_frame == 3 && FRAME_LIVE_P (x_dnd_return_frame_object)) {