]> git.eshelyaron.com Git - emacs.git/commitdiff
Simplify XDND toplevel freeing code
authorPo Lu <luangruo@yahoo.com>
Wed, 8 Jun 2022 12:04:26 +0000 (20:04 +0800)
committerPo Lu <luangruo@yahoo.com>
Wed, 8 Jun 2022 12:05:06 +0000 (20:05 +0800)
* 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.

src/xterm.c

index 1f4d301e6a52d318a4146cc03e646d571d68f33a..00586d66a078e8cd64796d35b8b13a8674774167 100644 (file)
@@ -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))
     {