summaryrefslogtreecommitdiff
path: root/lisp/dnd.el
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-04-04 20:32:46 +0800
committerPo Lu <luangruo@yahoo.com>2022-04-04 20:32:46 +0800
commit84cf3be6f77f61dd361acdb3683ab9d71e76c995 (patch)
treeccf6ea1ff0d6ac533f3665991f311750af99f738 /lisp/dnd.el
parent3d2531c12c54f9ab923603655016077450c23ab2 (diff)
downloademacs-84cf3be6f77f61dd361acdb3683ab9d71e76c995.tar.gz
Handle mouse movement correctly during DND from one of our own frames
* lisp/dnd.el (dnd-handle-movement): Select the window specified in posn. * lisp/term/x-win.el (x-dnd-movement): New function. (x-dnd-movement-function): Set it as the default. * src/frame.c (delete_frame): Prevent deleting the drop source frame. * src/xterm.c (x_dnd_send_position): Set new mouse movement flags if the target window is one of our own frames. (x_dnd_begin_drag_and_drop): Call DND movement function whenever appropriate. (x_free_frame_resources): Remove useless code. (syms_of_xterm): New defvar `x-dnd-movement-function'. * src/xterm.h: Update prototypes.
Diffstat (limited to 'lisp/dnd.el')
-rw-r--r--lisp/dnd.el52
1 files changed, 27 insertions, 25 deletions
diff --git a/lisp/dnd.el b/lisp/dnd.el
index 8b11973eb41..4f71edf1aa1 100644
--- a/lisp/dnd.el
+++ b/lisp/dnd.el
@@ -107,31 +107,33 @@ program."
(defun dnd-handle-movement (posn)
"Handle mouse movement to POSN when receiving a drop from another program."
- (when dnd-scroll-margin
- (ignore-errors
- (let* ((row (cdr (posn-col-row posn)))
- (window (when (windowp (posn-window posn))
- (posn-window posn)))
- (text-height (window-text-height window))
- ;; Make sure it's possible to scroll both up
- ;; and down if the margin is too large for the
- ;; window.
- (margin (min (/ text-height 3) dnd-scroll-margin)))
- ;; At 2 lines, the window becomes too small for any
- ;; meaningful scrolling.
- (unless (<= text-height 2)
- (cond
- ;; Inside the bottom scroll margin, scroll up.
- ((> row (- text-height margin))
- (with-selected-window window
- (scroll-up 1)))
- ;; Inside the top scroll margin, scroll down.
- ((< row margin)
- (with-selected-window window
- (scroll-down 1))))))))
- (when dnd-indicate-insertion-point
- (ignore-errors
- (goto-char (posn-point posn)))))
+ (when (windowp (posn-window posn))
+ (with-selected-window (posn-window posn)
+ (when dnd-scroll-margin
+ (ignore-errors
+ (let* ((row (cdr (posn-col-row posn)))
+ (window (when (windowp (posn-window posn))
+ (posn-window posn)))
+ (text-height (window-text-height window))
+ ;; Make sure it's possible to scroll both up
+ ;; and down if the margin is too large for the
+ ;; window.
+ (margin (min (/ text-height 3) dnd-scroll-margin)))
+ ;; At 2 lines, the window becomes too small for any
+ ;; meaningful scrolling.
+ (unless (<= text-height 2)
+ (cond
+ ;; Inside the bottom scroll margin, scroll up.
+ ((> row (- text-height margin))
+ (with-selected-window window
+ (scroll-up 1)))
+ ;; Inside the top scroll margin, scroll down.
+ ((< row margin)
+ (with-selected-window window
+ (scroll-down 1))))))))
+ (when dnd-indicate-insertion-point
+ (ignore-errors
+ (goto-char (posn-point posn)))))))
(defun dnd-handle-one-url (window action url)
"Handle one dropped url by calling the appropriate handler.