At any time, one frame in Emacs is the selected frame. The selected window always resides on the selected frame.
The X server normally directs keyboard input to the X window that the mouse is in. Some window managers use mouse clicks or keyboard events to shift the focus to various X windows, overriding the normal behavior of the server.
Lisp programs can switch frames "temporarily" by calling
the function select-frame
. This does not override the window
manager; rather, it escapes from the window manager's control until
that control is somehow reasserted.
When using a text-only terminal, there is no window manager; therefore,
switch-frame
is the only way to switch frames, and the effect
lasts until overridden by a subsequent call to switch-frame
.
Only the selected terminal frame is actually displayed on the terminal.
Each terminal screen except for the initial one has a number, and the
number of the selected frame appears in the mode line after the word
`Emacs' (see section Variables Used in the Mode Line).
Emacs cooperates with the X server and the window managers by arranging
to select frames according to what the server and window manager ask
for. It does so by generating a special kind of input event, called a
focus event. The command loop handles a focus event by calling
handle-switch-frame
. See section Focus Events.
Focus events normally do their job by invoking this command. Don't call it for any other reason.
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
, when foo
had been selected, changes any redirections
pointing to foo
so that they point to bar
instead. This
allows focus redirection to work properly when the user switches from
one frame to another using select-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.
Go to the first, previous, next, last section, table of contents.