]> git.eshelyaron.com Git - emacs.git/commitdiff
Minor fixes to DND support
authorPo Lu <luangruo@yahoo.com>
Fri, 18 Mar 2022 00:22:50 +0000 (08:22 +0800)
committerPo Lu <luangruo@yahoo.com>
Fri, 18 Mar 2022 00:22:50 +0000 (08:22 +0800)
* src/xterm.c (x_dnd_begin_drag_and_drop): Free targets
afterwards.
(handle_one_xevent): Only calculate dnd_grab if DND is in
progress.

src/xterm.c

index 6485374e2ae63931b7bdc81d7331ff85a6e7e41b..eb2ecf7d65a284cf7d47e1612db517216f2301b9 100644 (file)
@@ -1157,6 +1157,7 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction,
 
              x_dnd_in_progress = false;
              x_dnd_frame = NULL;
+             x_set_dnd_targets (NULL, 0);
            }
 
          FRAME_DISPLAY_INFO (f)->grabbed = 0;
@@ -1167,6 +1168,8 @@ x_dnd_begin_drag_and_drop (struct frame *f, Time time, Atom xaction,
        }
     }
 
+  x_set_dnd_targets (NULL, 0);
+
 #ifdef USE_GTK
   current_hold_quit = NULL;
 #endif
@@ -12077,30 +12080,31 @@ handle_one_xevent (struct x_display_info *dpyinfo,
         bool tool_bar_p = false;
        bool dnd_grab = false;
 
-       for (int i = 1; i < 8; ++i)
-         {
-           if (i != event->xbutton.button
-               && event->xbutton.state & (Button1Mask << (i - 1)))
-             dnd_grab = true;
-         }
-
        if (x_dnd_in_progress
-           && dpyinfo == FRAME_DISPLAY_INFO (x_dnd_frame)
-           && !dnd_grab
-           && event->xbutton.type == ButtonRelease)
+           && dpyinfo == FRAME_DISPLAY_INFO (x_dnd_frame))
          {
-           x_dnd_in_progress = false;
+           for (int i = 1; i < 8; ++i)
+             {
+               if (i != event->xbutton.button
+                   && event->xbutton.state & (Button1Mask << (i - 1)))
+                 dnd_grab = true;
+             }
 
-           if (x_dnd_last_seen_window != None
-               && x_dnd_last_protocol_version != -1)
-             x_dnd_send_drop (x_dnd_frame, x_dnd_last_seen_window,
-                              x_dnd_selection_timestamp,
-                              x_dnd_last_protocol_version);
+           if (dnd_grab && event->xbutton.type == ButtonRelease)
+             {
+               x_dnd_in_progress = false;
+
+               if (x_dnd_last_seen_window != None
+                   && x_dnd_last_protocol_version != -1)
+                 x_dnd_send_drop (x_dnd_frame, x_dnd_last_seen_window,
+                                  x_dnd_selection_timestamp,
+                                  x_dnd_last_protocol_version);
 
-           x_dnd_last_protocol_version = -1;
-           x_dnd_last_seen_window = None;
-           x_dnd_frame = NULL;
-           x_set_dnd_targets (NULL, 0);
+               x_dnd_last_protocol_version = -1;
+               x_dnd_last_seen_window = None;
+               x_dnd_frame = NULL;
+               x_set_dnd_targets (NULL, 0);
+             }
 
            goto OTHER;
          }
@@ -13053,31 +13057,33 @@ handle_one_xevent (struct x_display_info *dpyinfo,
              XButtonEvent bv;
              bool dnd_grab = false;
 
-             for (int i = 0; i < xev->buttons.mask_len * 8; ++i)
-               {
-                 if (i != xev->detail && XIMaskIsSet (xev->buttons.mask, i))
-                   dnd_grab = true;
-               }
-
              if (x_dnd_in_progress
-                 && dpyinfo == FRAME_DISPLAY_INFO (x_dnd_frame)
-                 && !dnd_grab
-                 && xev->evtype == XI_ButtonRelease)
+                 && dpyinfo == FRAME_DISPLAY_INFO (x_dnd_frame))
                {
-                 x_dnd_in_progress = false;
+                 for (int i = 0; i < xev->buttons.mask_len * 8; ++i)
+                   {
+                     if (i != xev->detail && XIMaskIsSet (xev->buttons.mask, i))
+                       dnd_grab = true;
+                   }
 
-                 if (x_dnd_last_seen_window != None
-                     && x_dnd_last_protocol_version != -1)
-                   x_dnd_send_drop (x_dnd_frame, x_dnd_last_seen_window,
-                                    x_dnd_selection_timestamp,
-                                    x_dnd_last_protocol_version);
+                 if (!dnd_grab
+                     && xev->evtype == XI_ButtonRelease)
+                   {
+                     x_dnd_in_progress = false;
 
-                 x_dnd_last_protocol_version = -1;
-                 x_dnd_last_seen_window = None;
-                 x_dnd_frame = NULL;
-                 x_set_dnd_targets (NULL, 0);
+                     if (x_dnd_last_seen_window != None
+                         && x_dnd_last_protocol_version != -1)
+                       x_dnd_send_drop (x_dnd_frame, x_dnd_last_seen_window,
+                                        x_dnd_selection_timestamp,
+                                        x_dnd_last_protocol_version);
 
-                 goto XI_OTHER;
+                     x_dnd_last_protocol_version = -1;
+                     x_dnd_last_seen_window = None;
+                     x_dnd_frame = NULL;
+                     x_set_dnd_targets (NULL, 0);
+
+                     goto XI_OTHER;
+                   }
                }
 
              if (x_dnd_in_progress)