]> git.eshelyaron.com Git - emacs.git/commitdiff
Make DND target list lifecycle a little clearer
authorPo Lu <luangruo@yahoo.com>
Sun, 29 May 2022 04:55:54 +0000 (12:55 +0800)
committerPo Lu <luangruo@yahoo.com>
Sun, 29 May 2022 04:56:37 +0000 (12:56 +0800)
* src/xfns.c (Fx_begin_drag): Pass target atoms and ntargets to
x_dnd_begin_drag_and_drop instead.
* src/xterm.c (x_set_dnd_targets): Make static.
(x_clear_dnd_targets): Delete function.
(x_dnd_begin_drag_and_drop): Adjust to set targets here instead.
* src/xterm.h: Update prototypes.

src/xfns.c
src/xterm.c
src/xterm.h

index 9f218d2b7fe038726a18bcfc37104eebe54d993b..401ad816955a25cccc49697f21ba8f5ce6f82bc4 100644 (file)
@@ -6933,11 +6933,11 @@ that mouse buttons are being held down, such as immediately after a
                ntargets, False, target_atoms);
   unblock_input ();
 
-  x_set_dnd_targets (target_atoms, ntargets);
   lval = x_dnd_begin_drag_and_drop (f, FRAME_DISPLAY_INFO (f)->last_user_time,
                                    xaction, return_frame, action_list,
                                    (const char **) &name_list, nnames,
-                                   !NILP (allow_current_frame));
+                                   !NILP (allow_current_frame), target_atoms,
+                                   ntargets);
 
   SAFE_FREE ();
   return lval;
index 3e5aaf5d4a4a9d4bf6497c0128b7c2fd1b5e1270..65d3eaf83f2e4c04a2100de5b5e94940d0ca9675 100644 (file)
@@ -3901,7 +3901,7 @@ x_dnd_send_drop (struct frame *f, Window target, Time timestamp,
   return true;
 }
 
-void
+static void
 x_set_dnd_targets (Atom *targets, int ntargets)
 {
   if (x_dnd_targets)
@@ -10292,13 +10292,6 @@ x_next_event_from_any_display (XEvent *event)
 
 #endif /* USE_X_TOOLKIT || USE_GTK */
 
-static void
-x_clear_dnd_targets (void)
-{
-  if (x_dnd_unwind_flag)
-    x_set_dnd_targets (NULL, 0);
-}
-
 /* This function is defined far away from the rest of the XDND code so
    it can utilize `x_any_window_to_frame'.  */
 
@@ -10306,7 +10299,8 @@ Lisp_Object
 x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction,
                           Lisp_Object return_frame, Atom *ask_action_list,
                           const char **ask_action_names, size_t n_ask_actions,
-                          bool allow_current_frame)
+                          bool allow_current_frame, Atom *target_atoms,
+                          int ntargets)
 {
 #ifndef USE_GTK
   XEvent next_event;
@@ -10394,43 +10388,25 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction,
     }
 
   if (!FRAME_VISIBLE_P (f))
-    {
-      x_set_dnd_targets (NULL, 0);
-      error ("Frame is invisible");
-    }
+    error ("Frame must be visible");
 
   XSETFRAME (frame, f);
   local_value = assq_no_quit (QXdndSelection,
                              FRAME_TERMINAL (f)->Vselection_alist);
 
   if (x_dnd_in_progress || x_dnd_waiting_for_finish)
-    {
-      x_set_dnd_targets (NULL, 0);
-      error ("A drag-and-drop session is already in progress");
-    }
+    error ("A drag-and-drop session is already in progress");
 
   if (CONSP (local_value))
-    {
-      ref = SPECPDL_INDEX ();
-
-      record_unwind_protect_void (x_clear_dnd_targets);
-      x_dnd_unwind_flag = true;
-      x_own_selection (QXdndSelection,
-                      Fnth (make_fixnum (1), local_value), frame);
-      x_dnd_unwind_flag = false;
-      unbind_to (ref, Qnil);
-    }
+    x_own_selection (QXdndSelection,
+                    Fnth (make_fixnum (1), local_value), frame);
   else
-    {
-      x_set_dnd_targets (NULL, 0);
-      error ("No local value for XdndSelection");
-    }
+    error ("No local value for XdndSelection");
 
   if (popup_activated ())
-    {
-      x_set_dnd_targets (NULL, 0);
-      error ("Trying to drag-and-drop from within a menu-entry");
-    }
+    error ("Trying to drag-and-drop from within a menu-entry");
+
+  x_set_dnd_targets (target_atoms, ntargets);
 
   ltimestamp = x_timestamp_for_selection (FRAME_DISPLAY_INFO (f),
                                          QXdndSelection);
index 6c798ea246d0476a514031490714ec1fb59eb8ff..bc2e138aa994b0a44d48a78042bf5fbec8643464 100644 (file)
@@ -1451,11 +1451,10 @@ extern void x_scroll_bar_configure (GdkEvent *);
 
 extern Lisp_Object x_dnd_begin_drag_and_drop (struct frame *, Time, Atom,
                                              Lisp_Object, Atom *, const char **,
-                                             size_t, bool);
+                                             size_t, bool, Atom *, int);
 extern void x_dnd_do_unsupported_drop (struct x_display_info *, Lisp_Object,
                                       Lisp_Object, Lisp_Object, Window, int,
                                       int, Time);
-extern void x_set_dnd_targets (Atom *, int);
 
 extern int x_display_pixel_height (struct x_display_info *);
 extern int x_display_pixel_width (struct x_display_info *);