aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorPo Lu2022-07-15 16:19:41 +0800
committerPo Lu2022-07-15 16:19:52 +0800
commit200938b95d1b73d03ce758e69a69d4fb198be4e8 (patch)
tree16d187bd8747d8bed5dd84c58cef71c7b2d35498 /lisp
parentffe4a5dac0dbc9fd85064200ed7b46b4ab3b910a (diff)
downloademacs-200938b95d1b73d03ce758e69a69d4fb198be4e8.tar.gz
emacs-200938b95d1b73d03ce758e69a69d4fb198be4e8.zip
Fix generated drag-and-drop mouse rectangles
* lisp/x-dnd.el (x-dnd-get-drop-width-height): Handle window width and height correctly. Remove unused parameter. (x-dnd-after-move-frame): New function. (move-frame-functions): Add new hook. (x-dnd-compute-root-window-position): New function. (x-dnd-get-drop-x-y): Use that instead of `left' and `top' parameters, which include the title bar. (x-dnd-handle-xdnd): Update accordingly. * src/xfns.c (Fx_translate_coordinates): New function. (syms_of_xfns): New defsym.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/x-dnd.el48
1 files changed, 34 insertions, 14 deletions
diff --git a/lisp/x-dnd.el b/lisp/x-dnd.el
index 92899e7a0c6..b25d2ea3d9d 100644
--- a/lisp/x-dnd.el
+++ b/lisp/x-dnd.el
@@ -588,6 +588,7 @@ message (format 32) that caused EVENT to be generated."
588 588
589(declare-function x-change-window-property "xfns.c" 589(declare-function x-change-window-property "xfns.c"
590 (prop value &optional frame type format outer-P window-id)) 590 (prop value &optional frame type format outer-P window-id))
591(declare-function x-translate-coordinates "xfns.c")
591 592
592(defun x-dnd-init-xdnd-for-frame (frame) 593(defun x-dnd-init-xdnd-for-frame (frame)
593 "Set the XdndAware property for FRAME to indicate that we do XDND." 594 "Set the XdndAware property for FRAME to indicate that we do XDND."
@@ -595,33 +596,53 @@ message (format 32) that caused EVENT to be generated."
595 '(5) ;; The version of XDND we support. 596 '(5) ;; The version of XDND we support.
596 frame "ATOM" 32 t)) 597 frame "ATOM" 32 t))
597 598
598(defun x-dnd-get-drop-width-height (frame w accept) 599(defun x-dnd-get-drop-width-height (w accept)
599 "Return the width/height to be sent in a XdndStatus message. 600 "Return the width/height to be sent in a XdndStatus message.
600FRAME is the frame and W is the window where the drop happened. 601W is the window where the drop happened.
601If ACCEPT is nil return 0 (empty rectangle), 602If ACCEPT is nil return 0 (empty rectangle),
602otherwise if W is a window, return its width/height, 603otherwise if W is a window, return its width/height,
603otherwise return the frame width/height." 604otherwise return the frame width/height."
604 (if accept 605 (if accept
605 (if (windowp w) ;; w is not a window if dropping on the menu bar, 606 (if (windowp w) ;; w is not a window if dropping on the menu bar,
606 ;; scroll bar or tool bar. 607 ;; scroll bar or tool bar.
607 (let ((edges (window-inside-pixel-edges w))) 608 (cons (window-pixel-width)
608 (cons 609 (window-pixel-height))
609 (- (nth 2 edges) (nth 0 edges)) ;; right - left 610 ;; Don't confine to mouse rect if w is not a window.
610 (- (nth 3 edges) (nth 1 edges)))) ;; bottom - top 611 ;; Otherwise, we won't get position events once the mouse does
611 (cons (frame-pixel-width frame) 612 ;; move into a window.
612 (frame-pixel-height frame))) 613 0)
613 0)) 614 0))
614 615
616(defun x-dnd-after-move-frame (frame)
617 "Handle FRAME moving to a different position.
618Clear any cached root window position."
619 (set-frame-parameter frame 'dnd-root-window-position
620 nil))
621
622(add-hook 'move-frame-functions #'x-dnd-after-move-frame)
623
624(defun x-dnd-compute-root-window-position (frame)
625 "Return the position of FRAME's edit widget relative to the root window.
626The value is a cons of (X . Y), describing the position of
627FRAME's edit widget (inner window) relative to the root window of
628its screen."
629 (or (frame-parameter frame 'dnd-root-window-position)
630 (let* ((result (x-translate-coordinates frame))
631 (param (cons (car result) (cadr result))))
632 (unless result
633 (error "Frame isn't on the same screen as its root window"))
634 (prog1 param
635 (set-frame-parameter frame 'dnd-root-window-position param)))))
636
615(defun x-dnd-get-drop-x-y (frame w) 637(defun x-dnd-get-drop-x-y (frame w)
616 "Return the x/y coordinates to be sent in a XdndStatus message. 638 "Return the x/y coordinates to be sent in a XdndStatus message.
617Coordinates are required to be absolute. 639Coordinates are required to be absolute.
618FRAME is the frame and W is the window where the drop happened. 640FRAME is the frame and W is the window where the drop happened.
619If W is a window, return its absolute coordinates, 641If W is a window, return its absolute coordinates,
620otherwise return the frame coordinates." 642otherwise return the frame coordinates."
621 (let* ((frame-left (or (car-safe (cdr-safe (frame-parameter frame 'left))) 643 (let* ((position (x-dnd-compute-root-window-position frame))
622 (frame-parameter frame 'left))) 644 (frame-left (car position))
623 (frame-top (or (car-safe (cdr-safe (frame-parameter frame 'top))) 645 (frame-top (cdr position)))
624 (frame-parameter frame 'top))))
625 (if (windowp w) 646 (if (windowp w)
626 (let ((edges (window-inside-pixel-edges w))) 647 (let ((edges (window-inside-pixel-edges w)))
627 (cons 648 (cons
@@ -700,8 +721,7 @@ FORMAT is 32 (not used). MESSAGE is the data part of an XClientMessageEvent."
700 ;; widget bounds". 721 ;; widget bounds".
701 (+ (if dnd-indicate-insertion-point 2 0) accept) 722 (+ (if dnd-indicate-insertion-point 2 0) accept)
702 (x-dnd-get-drop-x-y frame window) 723 (x-dnd-get-drop-x-y frame window)
703 (x-dnd-get-drop-width-height 724 (x-dnd-get-drop-width-height window (eq accept 1))
704 frame window (eq accept 1))
705 ;; The no-toolkit Emacs build can actually 725 ;; The no-toolkit Emacs build can actually
706 ;; receive drops from programs that speak 726 ;; receive drops from programs that speak
707 ;; versions of XDND earlier than 3 (such as 727 ;; versions of XDND earlier than 3 (such as