Variable: focus-follows-mouse

focus-follows-mouse is a customizable variable defined in frame.c.

Value

nil

Documentation

Non-nil if window system changes focus when you move the mouse.

You should set this variable to tell Emacs how your window manager handles focus, since there is no way in general for Emacs to find out automatically.

There are three meaningful values:

- The default nil should be used when your window manager follows a
  "click-to-focus" policy where you have to click the mouse inside of a
  frame in order for that frame to get focus.

- The value t should be used when your window manager has the focus
  automatically follow the position of the mouse pointer but a window
  that gains focus is not raised automatically.

- The value auto-raise should be used when your window manager has the
  focus automatically follow the position of the mouse pointer and a
  window that gains focus is raised automatically.

If this option is non-nil, Emacs moves the mouse pointer to the frame selected by select-frame-set-input-focus. This function is used by a number of commands like, for example, other-frame and pop-to-buffer. If this option is nil and your focus follows mouse window manager does not autonomously move the mouse pointer to the newly selected frame, the previously selected window manager window might get reselected instead immediately.

The distinction between the values t and auto-raise is not needed for
"normal" frames because the window manager takes care of raising them.
Setting this to auto-raise will, however, override the standard behavior of a window manager that does not automatically raise the frame that gets focus. Setting this to auto-raise is also necessary to automatically raise child frames which are usually left alone by the window manager.

Note that this option does not distinguish "sloppy" focus (where the frame that previously had focus retains focus as long as the mouse pointer does not move into another window manager window) from "strict" focus (where a frame immediately loses focus when it's left by the mouse pointer).

In order to extend a "focus follows mouse" policy to individual Emacs windows, customize the variable mouse-autoselect-window.

This variable was added, or its default value changed, in Emacs 26.1.

View in manual

Probably introduced at or before Emacs version 20.3.

Source Code

// Defined in /usr/src/emacs/src/frame.c
  DEFVAR_LISP ("focus-follows-mouse", focus_follows_mouse,
	       doc: /* Non-nil if window system changes focus when you move the mouse.
You should set this variable to tell Emacs how your window manager
handles focus, since there is no way in general for Emacs to find out
automatically.

There are three meaningful values:

- The default nil should be used when your window manager follows a
  "click-to-focus" policy where you have to click the mouse inside of a
  frame in order for that frame to get focus.

- The value t should be used when your window manager has the focus
  automatically follow the position of the mouse pointer but a window
  that gains focus is not raised automatically.

- The value `auto-raise' should be used when your window manager has the
  focus automatically follow the position of the mouse pointer and a
  window that gains focus is raised automatically.

If this option is non-nil, Emacs moves the mouse pointer to the frame
selected by `select-frame-set-input-focus'.  This function is used by a
number of commands like, for example, `other-frame' and `pop-to-buffer'.
If this option is nil and your focus follows mouse window manager does
not autonomously move the mouse pointer to the newly selected frame, the
previously selected window manager window might get reselected instead
immediately.

The distinction between the values t and `auto-raise' is not needed for
"normal" frames because the window manager takes care of raising them.
Setting this to `auto-raise' will, however, override the standard
behavior of a window manager that does not automatically raise the frame
that gets focus.  Setting this to `auto-raise' is also necessary to
automatically raise child frames which are usually left alone by the
window manager.

Note that this option does not distinguish "sloppy" focus (where the
frame that previously had focus retains focus as long as the mouse
pointer does not move into another window manager window) from "strict"
focus (where a frame immediately loses focus when it's left by the mouse
pointer).

In order to extend a "focus follows mouse" policy to individual Emacs
windows, customize the variable `mouse-autoselect-window'.  */);