Function: mouse-autoselect-window-select

mouse-autoselect-window-select is a byte-compiled function defined in window.el.gz.

Signature

(mouse-autoselect-window-select)

Documentation

Select window with delayed window autoselection.

If the mouse position has stabilized in a non-selected window, select that window. The minibuffer window is selected only if the minibuffer is active. This function is run by mouse-autoselect-window-timer.

Source Code

;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun mouse-autoselect-window-select ()
  "Select window with delayed window autoselection.
If the mouse position has stabilized in a non-selected window, select
that window.  The minibuffer window is selected only if the minibuffer
is active.  This function is run by `mouse-autoselect-window-timer'."
  (let* ((mouse-position (mouse-position))
         (mouse-x (and (numberp (cadr mouse-position))
                       (cadr mouse-position)))
         (mouse-y (and (numberp (cddr mouse-position))
                       (cddr mouse-position)))
         (frame (and mouse-x mouse-y (car mouse-position)))
         (window (and frame (window-at mouse-x mouse-y frame))))
    (cond
      ((or (and (fboundp 'menu-or-popup-active-p) (menu-or-popup-active-p))
	   (and window
		(let ((coords (coordinates-in-window-p
			       (cdr mouse-position) window)))
		  (and (not (consp coords))
		       (not (memq coords '(left-margin right-margin)))))))
       ;; A menu / popup dialog is active or the mouse is not on the
       ;; text region of WINDOW: Suspend autoselection temporarily.
       (mouse-autoselect-window-start mouse-position nil t))
      ((or (eq mouse-autoselect-window-state 'suspend)
          ;; When the mouse is at its first recorded position, restart
          ;; delayed autoselection.  This works around a scenario with
          ;; two two-window frames with identical dimensions: select the
          ;; first window of the first frame, switch to the second
          ;; frame, move the mouse to its second window, minimize the
          ;; second frame.  Now the second window of the first frame
          ;; gets selected although the mouse never really "moved" into
          ;; that window.
          (and (numberp mouse-autoselect-window)
               (equal (mouse-position) mouse-autoselect-window-position-1)))
      ;; Delayed autoselection was temporarily suspended, reenable it.
      (mouse-autoselect-window-start mouse-position))
     ((and window
           (or (not (numberp mouse-autoselect-window))
               (and (>= mouse-autoselect-window 0)
                    ;; If `mouse-autoselect-window' is non-negative,
                    ;; select window if it's the same as before.
                    (eq window mouse-autoselect-window-window))
               ;; Otherwise select window iff the mouse is at the same
               ;; position as before.  Observe that the first test
               ;; after starting autoselection usually fails since the
               ;; value of `mouse-autoselect-window-position' recorded
               ;; there is the position where the mouse has entered the
               ;; new window and not necessarily where the mouse has
               ;; stopped moving.
               (equal mouse-position mouse-autoselect-window-position))
           ;; The minibuffer is a candidate window if it's active.
           (or (not (window-minibuffer-p window))
               (eq window (active-minibuffer-window))))
      ;; Mouse position has stabilized in non-selected window: Cancel
      ;; delayed autoselection and try to select that window.
      (mouse-autoselect-window-cancel t)
      ;; Use `unread-command-events' in order to execute pre- and
      ;; post-command hooks and trigger idle timers.  To avoid delaying
      ;; autoselection again, set `mouse-autoselect-window-state'."
      (setq mouse-autoselect-window-state 'select)
      (setq unread-command-events
            (cons (list 'select-window (list window))
                  unread-command-events)))
     ((or (not (numberp mouse-autoselect-window))
          (equal mouse-position mouse-autoselect-window-position))
      ;; Mouse position has stabilized at
      ;; `mouse-autoselect-window-position': Cancel delayed
      ;; autoselection.
     (mouse-autoselect-window-cancel t))
    (window
     ;; Mouse position has not stabilized yet, resume delayed
     ;; autoselection.
     (mouse-autoselect-window-start mouse-position window)))))