Function: window-main-window

window-main-window is a byte-compiled function defined in window.el.gz.

Signature

(window-main-window &optional FRAME)

Documentation

Return the main window of specified FRAME.

The optional argument FRAME must be a live frame and defaults to the selected one.

If FRAME has no side windows, return FRAME's root window. Otherwise, return either an internal non-side window such that all other non-side windows on FRAME descend from it, or the single live non-side window of FRAME.

View in manual

Source Code

;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun window-main-window (&optional frame)
  "Return the main window of specified FRAME.
The optional argument FRAME must be a live frame and defaults to
the selected one.

If FRAME has no side windows, return FRAME's root window.
Otherwise, return either an internal non-side window such that
all other non-side windows on FRAME descend from it, or the
single live non-side window of FRAME."
  (let ((frame (window-normalize-frame frame))
	main sibling)
    ;; Set main to the _last_ window found by `walk-window-tree' that
    ;; is not a side window but has a side window as its sibling.
    (walk-window-tree
     (lambda (window)
       (and (not (window-parameter window 'window-side))
	    (or (and (setq sibling (window-prev-sibling window))
		     (window-parameter sibling 'window-side))
		(and (setq sibling (window-next-sibling window))
		     (window-parameter sibling 'window-side)))
	    (setq main window)))
     frame t 'nomini)
    (or main (frame-root-window frame))))