Next: , Previous: Window Frame Parameters, Up: Frame Parameters

29.3.4 Frame Size And Position

You can read or change the size and position of a frame using the frame parameters left, top, height, and width. Whatever geometry parameters you don't specify are chosen by the window manager in its usual fashion.

Here are some special features for working with sizes and positions. (For the precise meaning of “selected frame” used by these functions, see Input Focus.)

— Function: set-frame-position frame left top

This function sets the position of the top left corner of frame to left and top. These arguments are measured in pixels, and normally count from the top left corner of the screen.

Negative parameter values position the bottom edge of the window up from the bottom edge of the screen, or the right window edge to the left of the right edge of the screen. It would probably be better if the values were always counted from the left and top, so that negative arguments would position the frame partly off the top or left edge of the screen, but it seems inadvisable to change that now.

— Function: frame-height &optional frame
— Function: frame-width &optional frame

These functions return the height and width of frame, measured in lines and columns. If you don't supply frame, they use the selected frame.

— Function: frame-pixel-height &optional frame
— Function: frame-pixel-width &optional frame

These functions return the height and width of the main display area of frame, measured in pixels. If you don't supply frame, they use the selected frame. For a text terminal, the results are in characters rather than pixels.

These values include the internal borders, and windows' scroll bars and fringes (which belong to individual windows, not to the frame itself). The exact value of the heights depends on the window-system and toolkit in use. With GTK+, the height does not include any tool bar or menu bar. With the Motif or Lucid toolkits, it includes the tool bar but not the menu bar. In a graphical version with no toolkit, it includes both the tool bar and menu bar. For a text terminal, the result includes the menu bar.

— Function: frame-char-height &optional frame
— Function: frame-char-width &optional frame

These functions return the height and width of a character in frame, measured in pixels. The values depend on the choice of font. If you don't supply frame, these functions use the selected frame.

— Function: set-frame-size frame cols rows

This function sets the size of frame, measured in characters; cols and rows specify the new width and height.

To set the size based on values measured in pixels, use frame-char-height and frame-char-width to convert them to units of characters.

— Function: set-frame-height frame lines &optional pretend

This function resizes frame to a height of lines lines. The sizes of existing windows in frame are altered proportionally to fit.

If pretend is non-nil, then Emacs displays lines lines of output in frame, but does not change its value for the actual height of the frame. This is only useful on text terminals. Using a smaller height than the terminal actually implements may be useful to reproduce behavior observed on a smaller screen, or if the terminal malfunctions when using its whole screen. Setting the frame height “for real” does not always work, because knowing the correct actual size may be necessary for correct cursor positioning on text terminals.

— Function: set-frame-width frame width &optional pretend

This function sets the width of frame, measured in characters. The argument pretend has the same meaning as in set-frame-height.

— Command: fit-frame-to-buffer &optional frame max-height min-height

This command adjusts the height of frame (the default is the selected frame) to fit its contents. The optional arguments max-height and min-height specify the maximum and minimum new frame heights, respectively.

The default minimum height corresponds to window-min-height. The default maximum height is the screen height below the current top position of the frame, minus any margin specified by the option fit-frame-to-buffer-bottom-margin.