Function: window-at-x-y

window-at-x-y is a byte-compiled function defined in window.el.gz.

Signature

(window-at-x-y X Y &optional FRAME NO-OTHER)

Documentation

Return live window at coordinates X, Y on specified FRAME.

X and Y are FRAME-relative pixel coordinates. A coordinate on an edge shared by two windows is attributed to the window on the right (or below). Return nil if no such window can be found.

Tool-bar and tab-bar pseudo-windows are ignored by this function: if the specified coordinates are in any of these two windows, this function returns nil.

Optional argument FRAME must specify a live frame and defaults to the selected one. Optional argument NO-OTHER non-nil means to return nil if window-no-other-p returns non-nil for the window located at the specified coordinates.

Source Code

;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun window-at-x-y (x y &optional frame no-other)
  "Return live window at coordinates X, Y on specified FRAME.
X and Y are FRAME-relative pixel coordinates.  A coordinate on an
edge shared by two windows is attributed to the window on the
right (or below).  Return nil if no such window can be found.

Tool-bar and tab-bar pseudo-windows are ignored by this function:
if the specified coordinates are in any of these two windows, this
function returns nil.

Optional argument FRAME must specify a live frame and defaults to the
selected one.  Optional argument NO-OTHER non-nil means to return nil if
`window-no-other-p' returns non-nil for the window located at the
specified coordinates."
  (setq frame (window-normalize-frame frame))
  (let* ((root-edges (window-edges (frame-root-window frame) nil nil t))
         (root-left (nth 2 root-edges))
         (root-bottom (nth 3 root-edges)))
    (catch 'window
      (walk-window-tree
       (lambda (window)
         (let ((edges (window-edges window nil nil t)))
	   (when (and (>= x (nth 0 edges))
                      (or (< x (nth 2 edges)) (= x root-left))
		      (>= y (nth 1 edges))
                      (or (< y (nth 3 edges)) (= y root-bottom)))
             (if (and no-other (window-no-other-p window))
                 (throw 'window nil)
	       (throw 'window window)))))
       frame))))