Next: Visibility of Frames, Previous: Minibuffers and Frames, Up: Frames
At any time, one frame in Emacs is the selected frame. The selected window always resides on the selected frame.
When Emacs displays its frames on several terminals (see Multiple Displays), each terminal has its own selected frame. But only one of these is “the selected frame”: it's the frame that belongs to the terminal from which the most recent input came. That is, when Emacs runs a command that came from a certain terminal, the selected frame is the one of that terminal. Since Emacs runs only a single command at any given time, it needs to consider only one selected frame at a time; this frame is what we call the selected frame in this manual. The display on which the selected frame is displayed is the selected frame's display.
Some window systems and window managers direct keyboard input to the window object that the mouse is in; others require explicit clicks or commands to shift the focus to various window objects. Either way, Emacs automatically keeps track of which frame has the focus.
Lisp programs can also switch frames “temporarily” by calling the
function select-frame
. This does not alter the window system's
concept of focus; rather, it escapes from the window manager's control
until that control is somehow reasserted.
When using a text-only terminal, only the selected terminal frame is
actually displayed on the terminal. switch-frame
is the only way
to switch frames, and the change lasts until overridden by a subsequent
call to switch-frame
. Each terminal screen except for the
initial one has a number, and the number of the selected frame appears
in the mode line before the buffer name (see Mode Line Variables).
This function selects frame frame, temporarily disregarding the focus of the X server if any. The selection of frame lasts until the next time the user does something to select a different frame, or until the next time this function is called. The specified frame becomes the selected frame, as explained above, and the terminal that frame is on becomes the selected terminal.
In general, you should never use
select-frame
in a way that could switch to a different terminal without switching back when you're done.
Emacs cooperates with the window system by arranging to select frames as
the server and window manager request. It does so by generating a
special kind of input event, called a focus event, when
appropriate. The command loop handles a focus event by calling
handle-switch-frame
. See Focus Events.
This function handles a focus event by selecting frame frame.
Focus events normally do their job by invoking this command. Don't call it for any other reason.
This function redirects focus from frame to focus-frame. This means that focus-frame will receive subsequent keystrokes and events intended for frame. After such an event, the value of
last-event-frame
will be focus-frame. Also, switch-frame events specifying frame will instead select focus-frame.If focus-frame is
nil
, that cancels any existing redirection for frame, which therefore once again receives its own events.One use of focus redirection is for frames that don't have minibuffers. These frames use minibuffers on other frames. Activating a minibuffer on another frame redirects focus to that frame. This puts the focus on the minibuffer's frame, where it belongs, even though the mouse remains in the frame that activated the minibuffer.
Selecting a frame can also change focus redirections. Selecting frame
bar
, whenfoo
had been selected, changes any redirections pointing tofoo
so that they point tobar
instead. This allows focus redirection to work properly when the user switches from one frame to another usingselect-window
.This means that a frame whose focus is redirected to itself is treated differently from a frame whose focus is not redirected.
select-frame
affects the former but not the latter.The redirection lasts until
redirect-frame-focus
is called to change it.