To create a new child frame or to convert a normal frame into a child
frame, set that frame’s parent-frame parameter (see Frame Interaction Parameters) to that of an already existing frame. The
frame specified by that parameter will then be the frame’s parent frame
as long as the parameter is not changed or reset. Technically, on a GUI
this makes the child frame’s window-system window a child window of the
parent frame’s window-system window. On a text terminal, this makes the
frame usually appear on the same terminal as its parent frame, obscuring
some part of it.
The parent-frame parameter can be changed at any time. Setting
it to another frame reparents the child frame. Setting it to
another child frame makes the frame a nested child frame. Setting
it to nil restores the frame’s status as a top-level frame—a
frame whose window-system window is a child of its display’s root
window.25 On text terminals,
top-level frames are called root frames (see below).
Since child frames can be arbitrarily nested, a frame can be both a child and a parent frame. Also, the relative roles of child and parent frame may be reversed at any time (though it’s usually a good idea to keep the size of a child frame sufficiently smaller than that of its parent). An error will be signaled for the attempt to make a frame an ancestor of itself.
When a parent frame is about to be deleted (see Deleting Frames), its child frames are recursively deleted before it. There is one exception to this rule: When the child frame serves as a surrogate minibuffer frame (see Minibuffers and Frames) for another frame, it is retained until the parent frame has been deleted. If, at this time, no remaining frame uses the child frame as its minibuffer frame, Emacs will try to delete the child frame too. If that deletion fails for whatever reason, the child frame is made a top-level frame. Since on text terminals no such conversion is possible, deleting a frame may throw an error if a surrogate minibuffer frame to be deleted is used by a frame that will not be deleted too.
The following three functions help to understand how parent and child frames related to each other.
This function returns the parent frame of frame. It returns
nil if frame has no parent frame.
This functions returns non-nil if ancestor is an ancestor
of descendant. ancestor is an ancestor of descendant
when it is either descendant’s parent frame or it is an ancestor
of descendant’s parent frame. Both, ancestor and
descendant must specify live frames.
This function returns the root frame of the specified frame. frame must be a live frame and defaults to the selected one. The root frame of frame is the frame obtained by following the chain of parent frames starting with frame until a frame is reached that has no parent. If frame has no parent, its root frame is frame itself.
On a text terminal, a root frame is always positioned at the top left edge of its terminal and always occupies the full size of its terminal.
On Haiku, child frames are only visible when a parent frame is active, owing to a limitation of the Haiku windowing system. Owing to the same limitation, child frames are only guaranteed to appear above their top-level parent; that is to say, the top-most frame in the hierarchy, which does not have a parent frame.