aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2022-07-09 16:18:35 +0800
committerPo Lu2022-07-09 16:18:35 +0800
commitbab449f034f44657ff3ed1bf533be6a27f4dafd6 (patch)
tree107dfc478b04d3ba772f8ef36a4670846b2bebd9
parentedabfe4ff66090b3b2c433962df4cfe1a68259fd (diff)
downloademacs-bab449f034f44657ff3ed1bf533be6a27f4dafd6.tar.gz
emacs-bab449f034f44657ff3ed1bf533be6a27f4dafd6.zip
Improve drag-and-drop emulation time handling
* src/xselect.c (x_handle_selection_request): Use display-specific pending DND time. (x_set_pending_dnd_time): Delete function. * src/xterm.c (x_dnd_do_unsupported_drop, handle_one_xevent): Set dpyinfo->pending_dnd_time instead. * src/xterm.h (struct x_display_info): New field `pending_dnd_time'. Make handling pending drops display-specific to avoid interference when there are multiple displays.
-rw-r--r--src/xselect.c17
-rw-r--r--src/xterm.c59
-rw-r--r--src/xterm.h5
3 files changed, 32 insertions, 49 deletions
diff --git a/src/xselect.c b/src/xselect.c
index d1b6d454abd..80db0d1fe2a 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -40,8 +40,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
40 40
41#include <X11/Xproto.h> 41#include <X11/Xproto.h>
42 42
43static Time pending_dnd_time;
44
45struct prop_location; 43struct prop_location;
46struct selection_data; 44struct selection_data;
47 45
@@ -265,7 +263,7 @@ x_atom_to_symbol (struct x_display_info *dpyinfo, Atom atom)
265 TIMESTAMP should be the timestamp where selection ownership will be 263 TIMESTAMP should be the timestamp where selection ownership will be
266 assumed. 264 assumed.
267 DND_DATA is the local value that will be used for selection requests 265 DND_DATA is the local value that will be used for selection requests
268 with `pending_dnd_time'. 266 with `dpyinfo->pending_dnd_time'.
269 Update the Vselection_alist so that we can reply to later requests for 267 Update the Vselection_alist so that we can reply to later requests for
270 our selection. */ 268 our selection. */
271 269
@@ -855,8 +853,11 @@ x_handle_selection_request (struct selection_input_event *event)
855 853
856 /* This is how the XDND protocol recommends dropping text onto a 854 /* This is how the XDND protocol recommends dropping text onto a
857 target that doesn't support XDND. */ 855 target that doesn't support XDND. */
858 if (SELECTION_EVENT_TIME (event) == pending_dnd_time + 1 856 if (dpyinfo->pending_dnd_time
859 || SELECTION_EVENT_TIME (event) == pending_dnd_time + 2) 857 && ((SELECTION_EVENT_TIME (event)
858 == dpyinfo->pending_dnd_time + 1)
859 || (SELECTION_EVENT_TIME (event)
860 == dpyinfo->pending_dnd_time + 2)))
860 use_alternate = true; 861 use_alternate = true;
861 862
862 block_input (); 863 block_input ();
@@ -2884,12 +2885,6 @@ x_timestamp_for_selection (struct x_display_info *dpyinfo,
2884 return value; 2885 return value;
2885} 2886}
2886 2887
2887void
2888x_set_pending_dnd_time (Time time)
2889{
2890 pending_dnd_time = time;
2891}
2892
2893static void syms_of_xselect_for_pdumper (void); 2888static void syms_of_xselect_for_pdumper (void);
2894 2889
2895void 2890void
diff --git a/src/xterm.c b/src/xterm.c
index 1afb8adcfee..d9485980fea 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -3873,8 +3873,10 @@ x_dnd_do_unsupported_drop (struct x_display_info *dpyinfo,
3873 && child_return != None) 3873 && child_return != None)
3874 child = child_return; 3874 child = child_return;
3875 3875
3876 x_uncatch_errors ();
3877
3876 if (!CONSP (value)) 3878 if (!CONSP (value))
3877 goto cancel; 3879 return;
3878 3880
3879 current_value = assq_no_quit (QPRIMARY, 3881 current_value = assq_no_quit (QPRIMARY,
3880 dpyinfo->terminal->Vselection_alist); 3882 dpyinfo->terminal->Vselection_alist);
@@ -3891,9 +3893,7 @@ x_dnd_do_unsupported_drop (struct x_display_info *dpyinfo,
3891 from generating events that will insert something else. */ 3893 from generating events that will insert something else. */
3892 3894
3893 if (owner != FRAME_X_WINDOW (f)) 3895 if (owner != FRAME_X_WINDOW (f))
3894 goto cancel; 3896 return;
3895
3896 x_uncatch_errors ();
3897 3897
3898 event.xbutton.window = child; 3898 event.xbutton.window = child;
3899 event.xbutton.subwindow = None; 3899 event.xbutton.subwindow = None;
@@ -3903,7 +3903,7 @@ x_dnd_do_unsupported_drop (struct x_display_info *dpyinfo,
3903 event.xbutton.button = 2; 3903 event.xbutton.button = 2;
3904 event.xbutton.same_screen = True; 3904 event.xbutton.same_screen = True;
3905 3905
3906 x_set_pending_dnd_time (before); 3906 dpyinfo->pending_dnd_time = before;
3907 3907
3908 event.xbutton.type = ButtonPress; 3908 event.xbutton.type = ButtonPress;
3909 event.xbutton.time = before + 1; 3909 event.xbutton.time = before + 1;
@@ -3924,9 +3924,6 @@ x_dnd_do_unsupported_drop (struct x_display_info *dpyinfo,
3924 x_dnd_action_symbol = QXdndActionPrivate; 3924 x_dnd_action_symbol = QXdndActionPrivate;
3925 3925
3926 return; 3926 return;
3927
3928 cancel:
3929 x_uncatch_errors ();
3930} 3927}
3931 3928
3932static void 3929static void
@@ -18934,23 +18931,17 @@ handle_one_xevent (struct x_display_info *dpyinfo,
18934 } 18931 }
18935 } 18932 }
18936 else 18933 else
18937 { 18934 x_dnd_send_unsupported_drop (dpyinfo, (x_dnd_last_seen_toplevel != None
18938 x_set_pending_dnd_time (event->xbutton.time); 18935 ? x_dnd_last_seen_toplevel
18939 x_dnd_send_unsupported_drop (dpyinfo, (x_dnd_last_seen_toplevel != None 18936 : x_dnd_last_seen_window),
18940 ? x_dnd_last_seen_toplevel 18937 event->xbutton.x_root, event->xbutton.y_root,
18941 : x_dnd_last_seen_window), 18938 event->xbutton.time);
18942 event->xbutton.x_root, event->xbutton.y_root,
18943 event->xbutton.time);
18944 }
18945 } 18939 }
18946 else if (x_dnd_last_seen_toplevel != None) 18940 else if (x_dnd_last_seen_toplevel != None)
18947 { 18941 x_dnd_send_unsupported_drop (dpyinfo, x_dnd_last_seen_toplevel,
18948 x_set_pending_dnd_time (event->xbutton.time); 18942 event->xbutton.x_root,
18949 x_dnd_send_unsupported_drop (dpyinfo, x_dnd_last_seen_toplevel, 18943 event->xbutton.y_root,
18950 event->xbutton.x_root, 18944 event->xbutton.time);
18951 event->xbutton.y_root,
18952 event->xbutton.time);
18953 }
18954 18945
18955 18946
18956 x_dnd_last_protocol_version = -1; 18947 x_dnd_last_protocol_version = -1;
@@ -20352,22 +20343,16 @@ handle_one_xevent (struct x_display_info *dpyinfo,
20352 } 20343 }
20353 } 20344 }
20354 else 20345 else
20355 { 20346 x_dnd_send_unsupported_drop (dpyinfo, (x_dnd_last_seen_toplevel != None
20356 x_set_pending_dnd_time (xev->time); 20347 ? x_dnd_last_seen_toplevel
20357 x_dnd_send_unsupported_drop (dpyinfo, (x_dnd_last_seen_toplevel != None 20348 : x_dnd_last_seen_window),
20358 ? x_dnd_last_seen_toplevel 20349 xev->root_x, xev->root_y, xev->time);
20359 : x_dnd_last_seen_window),
20360 xev->root_x, xev->root_y, xev->time);
20361 }
20362 } 20350 }
20363 else if (x_dnd_last_seen_toplevel != None) 20351 else if (x_dnd_last_seen_toplevel != None)
20364 { 20352 x_dnd_send_unsupported_drop (dpyinfo,
20365 x_set_pending_dnd_time (xev->time); 20353 x_dnd_last_seen_toplevel,
20366 x_dnd_send_unsupported_drop (dpyinfo, 20354 xev->root_x, xev->root_y,
20367 x_dnd_last_seen_toplevel, 20355 xev->time);
20368 xev->root_x, xev->root_y,
20369 xev->time);
20370 }
20371 20356
20372 x_dnd_last_protocol_version = -1; 20357 x_dnd_last_protocol_version = -1;
20373 x_dnd_last_motif_style = XM_DRAG_STYLE_NONE; 20358 x_dnd_last_motif_style = XM_DRAG_STYLE_NONE;
diff --git a/src/xterm.h b/src/xterm.h
index 6684d7839f3..92e88bb50fa 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -765,6 +765,10 @@ struct x_display_info
765 765
766 /* Pointer to the next request in `failable_requests'. */ 766 /* Pointer to the next request in `failable_requests'. */
767 struct x_failable_request *next_failable_request; 767 struct x_failable_request *next_failable_request;
768
769 /* The pending drag-and-drop time for middle-click based
770 drag-and-drop emulation. */
771 Time pending_dnd_time;
768}; 772};
769 773
770#ifdef HAVE_X_I18N 774#ifdef HAVE_X_I18N
@@ -1617,7 +1621,6 @@ extern void x_clipboard_manager_save_all (void);
1617 1621
1618extern Lisp_Object x_timestamp_for_selection (struct x_display_info *, 1622extern Lisp_Object x_timestamp_for_selection (struct x_display_info *,
1619 Lisp_Object); 1623 Lisp_Object);
1620extern void x_set_pending_dnd_time (Time);
1621extern void x_own_selection (Lisp_Object, Lisp_Object, Lisp_Object, 1624extern void x_own_selection (Lisp_Object, Lisp_Object, Lisp_Object,
1622 Lisp_Object, Time); 1625 Lisp_Object, Time);
1623extern Atom x_intern_cached_atom (struct x_display_info *, const char *, 1626extern Atom x_intern_cached_atom (struct x_display_info *, const char *,