2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4 @c See the file elisp.texi for copying conditions.
5 @setfilename ../info/frames
6 @node Frames, Positions, Windows, Top
10 A @dfn{frame} is a rectangle on the screen that contains one or more
11 Emacs windows. A frame initially contains a single main window (plus
12 perhaps a minibuffer window), which you can subdivide vertically or
13 horizontally into smaller windows.
15 @cindex terminal frame
16 @cindex X window frame
17 When Emacs runs on a text-only terminal, it starts with one
18 @dfn{terminal frame}. If you create additional ones, Emacs displays
19 one and only one at any given time---on the terminal screen, of course.
21 When Emacs communicates directly with an X server, it does not have a
22 terminal frame; instead, it starts with a single @dfn{X window frame}.
23 It can display multiple X window frames at the same time, each in its
27 This predicate returns @code{t} if @var{object} is a frame, and
32 * Creating Frames:: Creating additional frames.
33 * Multiple Displays:: Creating frames on other X displays.
34 * Frame Parameters:: Controlling frame size, position, font, etc.
35 * Frame Titles:: Automatic updating of frame titles.
36 * Deleting Frames:: Frames last until explicitly deleted.
37 * Finding All Frames:: How to examine all existing frames.
38 * Frames and Windows:: A frame contains windows;
39 display of text always works through windows.
40 * Minibuffers and Frames:: How a frame finds the minibuffer to use.
41 * Input Focus:: Specifying the selected frame.
42 * Visibility of Frames:: Frames may be visible or invisible, or icons.
43 * Raising and Lowering:: Raising a frame makes it hide other X windows;
44 lowering it makes the others hide them.
45 * Frame Configurations:: Saving the state of all frames.
46 * Mouse Tracking:: Getting events that say when the mouse moves.
47 * Mouse Position:: Asking where the mouse is, or moving it.
48 * Pop-Up Menus:: Displaying a menu for the user to select from.
49 * Dialog Boxes:: Displaying a box to ask yes or no.
50 * Pointer Shapes:: Specifying the shape of the mouse pointer.
51 * X Selections:: Transferring text to and from other X clients.
52 * Color Names:: Getting the definitions of color names.
53 * Resources:: Getting resource values from the server.
54 * Server Data:: Getting info about the X server.
57 @xref{Display}, for related information.
60 @section Creating Frames
62 To create a new frame, call the function @code{make-frame}.
64 @defun make-frame &optional alist
65 This function creates a new frame. If you are using X, it makes
66 an X window frame; otherwise, it makes a terminal frame.
68 The argument is an alist specifying frame parameters. Any parameters
69 not mentioned in @var{alist} default according to the value of the
70 variable @code{default-frame-alist}; parameters not specified even there
71 default from the standard X defaults file and X resources.
73 The set of possible parameters depends in principle on what kind of
74 window system Emacs uses to display its frames. @xref{X Frame
75 Parameters}, for documentation of individual parameters you can specify.
78 @defvar before-make-frame-hook
79 A normal hook run by @code{make-frame} before it actually creates the
83 @defvar after-make-frame-hook
84 A normal hook run by @code{make-frame} after it creates the frame.
87 @node Multiple Displays
88 @section Multiple Displays
89 @cindex multiple displays
90 @cindex multiple X terminals
91 @cindex displays, multiple
93 A single Emacs can talk to more than one X Windows display.
94 Initially, Emacs uses just one display---the one chosen with the
95 @code{DISPLAY} environment variable or with the @samp{--display} option
96 (@pxref{Initial Options,,, emacs, The GNU Emacs Manual}). To connect to
97 another display, use the command @code{make-frame-on-display} or specify
98 the @code{display} frame parameter when you create the frame.
100 Emacs treats each X server as a separate terminal, giving each one its
101 own selected frame and its own minibuffer windows. A few Lisp variables
102 have values local to the current terminal (that is, the terminal
103 corresponding to the currently selected frame): these are
104 @code{default-minibuffer-frame}, @code{defining-kbd-macro},
105 @code{last-kbd-macro}, and @code{system-key-alist}. These variables are
106 always terminal-local and can never be buffer-local.
108 A single X server can handle more than one screen. A display name
109 @samp{@var{host}.@var{server}.@var{screen}} has three parts; the last
110 part specifies the screen number for a given server. When you use two
111 screens belonging to one server, Emacs knows by the similarity in their
112 names that they share a single keyboard, and it treats them as a single
115 @deffn Command make-frame-on-display display &optional parameters
116 This creates a new frame on display @var{display}, taking the other
117 frame parameters from @var{parameters}. Aside from the @var{display}
118 argument, it is like @code{make-frame} (@pxref{Creating Frames}).
121 @defun x-display-list
122 This returns a list that indicates which X displays Emacs has a
123 connection to. The elements of the list are strings, and each one is
127 @defun x-open-connection display &optional xrm-string
128 This function opens a connection to the X display @var{display}. It
129 does not create a frame on that display, but it permits you to check
130 that communication can be established with that display.
132 The optional argument @var{resource-string}, if not @code{nil}, is a
133 string of resource names and values, in the same format used in the
134 @file{.Xresources} file. The values you specify override the resource
135 values recorded in the X server itself; they apply to all Emacs frames
136 created on this display. Here's an example of what this string might
140 "*BorderWidth: 3\n*InternalBorder: 2\n"
146 @defun x-close-connection display
147 This function closes the connection to display @var{display}. Before
148 you can do this, you must first delete all the frames that were open on
149 that display (@pxref{Deleting Frames}).
152 @node Frame Parameters
153 @section Frame Parameters
155 A frame has many parameters that control its appearance and behavior.
156 Just what parameters a frame has depends on what display mechanism it
159 Frame parameters exist for the sake of window systems. A terminal frame
160 has a few parameters, mostly for compatibility's sake; only the height,
161 width and @code{buffer-predicate} parameters really do something.
164 * Parameter Access:: How to change a frame's parameters.
165 * Initial Parameters:: Specifying frame parameters when you make a frame.
166 * X Frame Parameters:: List of frame parameters.
167 * Size and Position:: Changing the size and position of a frame.
170 @node Parameter Access
171 @subsection Access to Frame Parameters
173 These functions let you read and change the parameter values of a
176 @defun frame-parameters frame
177 The function @code{frame-parameters} returns an alist listing all the
178 parameters of @var{frame} and their values.
181 @defun modify-frame-parameters frame alist
182 This function alters the parameters of frame @var{frame} based on the
183 elements of @var{alist}. Each element of @var{alist} has the form
184 @code{(@var{parm} . @var{value})}, where @var{parm} is a symbol naming a
185 parameter. If you don't mention a parameter in @var{alist}, its value
189 @node Initial Parameters
190 @subsection Initial Frame Parameters
192 You can specify the parameters for the initial startup frame
193 by setting @code{initial-frame-alist} in your @file{.emacs} file.
195 @defvar initial-frame-alist
196 This variable's value is an alist of parameter values used when creating
197 the initial X window frame. Each element has the form:
200 (@var{parameter} . @var{value})
203 Emacs creates the initial frame before it reads your @file{~/.emacs}
204 file. After reading that file, Emacs checks @code{initial-frame-alist},
205 and applies the parameter settings in the altered value to the already
206 created initial frame.
208 If these settings affect the frame geometry and appearance, you'll see
209 the frame appear with the wrong ones and then change to the specified
210 ones. If that bothers you, you can specify the same geometry and
211 appearance with X resources; those do take affect before the frame is
212 created. @xref{Resources X,, X Resources, emacs, The GNU Emacs Manual}.
214 X resource settings typically apply to all frames. If you want to
215 specify some X resources solely for the sake of the initial frame, and
216 you don't want them to apply to subsequent frames, here's how to achieve
217 this. Specify parameters in @code{default-frame-alist} to override the
218 X resources for subsequent frames; then, to prevent these from affecting
219 the initial frame, specify the same parameters in
220 @code{initial-frame-alist} with values that match the X resources.
223 If these parameters specify a separate minibuffer-only frame with
224 @code{(minibuffer . nil)}, and you have not created one, Emacs creates
227 @defvar minibuffer-frame-alist
228 This variable's value is an alist of parameter values used when creating
229 an initial minibuffer-only frame---if such a frame is needed, according
230 to the parameters for the main initial frame.
233 @defvar default-frame-alist
234 This is an alist specifying default values of frame parameters for
235 subsequent Emacs frames (not the initial ones).
238 See also @code{special-display-frame-alist}, in @ref{Choosing Window}.
240 If you use options that specify window appearance when you invoke Emacs,
241 they take effect by adding elements to @code{default-frame-alist}. One
242 exception is @samp{-geometry}, which adds the specified position to
243 @code{initial-frame-alist} instead. @xref{Command Arguments,,, emacs,
244 The GNU Emacs Manual}.
246 @node X Frame Parameters
247 @subsection X Window Frame Parameters
249 Just what parameters a frame has depends on what display mechanism it
250 uses. Here is a table of the parameters of an X window frame; of these,
251 @code{name}, @code{height}, @code{width}, and @code{buffer-predicate}
252 provide meaningful information in non-X frames.
256 The name of the frame. Most window managers display the frame's name in
257 the frame's border, at the top of the frame. If you don't specify a
258 name, and you have more than one frame, Emacs sets the frame name based
259 on the buffer displayed in the frame's selected window.
261 If you specify the frame name explicitly when you create the frame, the
262 name is also used (instead of the name of the Emacs executable) when
263 looking up X resources for the frame.
266 The display on which to open this frame. It should be a string of the
267 form @code{"@var{host}:@var{dpy}.@var{screen}"}, just like the
268 @code{DISPLAY} environment variable.
271 The screen position of the left edge, in pixels, with respect to the
272 left edge of the screen. The value may be a positive number @var{pos},
273 or a list of the form @code{(+ @var{pos})} which permits specifying a
274 negative @var{pos} value.
276 A negative number @minus{}@var{pos}, or a list of the form @code{(-
277 @var{pos})}, actually specifies the position of the right edge of the
278 window with respect to the right edge of the screen. A positive value
279 of @var{pos} counts toward the left. If the parameter is a negative
280 integer @minus{}@var{pos} then @var{pos} is positive!
282 Some window managers ignore program-specified positions. If you want to
283 be sure the position you specify is not ignored, specify a
284 non-@code{nil} value for the @code{user-position} parameter as well.
287 The screen position of the top edge, in pixels, with respect to the
288 top edge of the screen. The value may be a positive number @var{pos},
289 or a list of the form @code{(+ @var{pos})} which permits specifying a
290 negative @var{pos} value.
292 A negative number @minus{}@var{pos}, or a list of the form @code{(-
293 @var{pos})}, actually specifies the position of the bottom edge of the
294 window with respect to the bottom edge of the screen. A positive value
295 of @var{pos} counts toward the top. If the parameter is a negative
296 integer @minus{}@var{pos} then @var{pos} is positive!
298 Some window managers ignore program-specified positions. If you want to
299 be sure the position you specify is not ignored, specify a
300 non-@code{nil} value for the @code{user-position} parameter as well.
303 The screen position of the left edge @emph{of the frame's icon}, in
304 pixels, counting from the left edge of the screen. This takes effect if
305 and when the frame is iconified.
308 The screen position of the top edge @emph{of the frame's icon}, in
309 pixels, counting from the top edge of the screen. This takes effect if
310 and when the frame is iconified.
313 Non-@code{nil} if the screen position of the frame was explicitly
314 requested by the user (for example, with the @samp{-geometry} option).
315 Nothing automatically makes this parameter non-@code{nil}; it is up to
316 Lisp programs that call @code{make-frame} to specify this parameter to
317 indicate that the values of the @code{left} and @code{top} parameters
318 are user-specified positions.
321 The height of the frame contents, in characters. (To get the height in
322 pixels, call @code{frame-pixel-height}; see @ref{Size and Position}.)
325 The width of the frame contents, in characters. (To get the height in
326 pixels, call @code{frame-pixel-width}; see @ref{Size and Position}.)
329 The number of the X window for the frame.
332 Whether this frame has its own minibuffer. The value @code{t} means
333 yes, @code{nil} means no, @code{only} means this frame is just a
334 minibuffer. If the value is a minibuffer window (in some other frame),
335 the new frame uses that minibuffer.
337 @item buffer-predicate
338 The buffer-predicate function for this frame. The function
339 @code{other-buffer} uses this predicate (from the selected frame) to
340 decide which buffers it should consider, if the predicate is not
341 @code{nil}. It calls the predicate with one arg, a buffer, once for
342 each buffer; if the predicate returns a non-@code{nil} value, it
343 considers that buffer.
346 The name of the font for displaying text in the frame. This is a
350 Whether selecting the frame raises it (non-@code{nil} means yes).
353 Whether deselecting the frame lowers it (non-@code{nil} means yes).
355 @item vertical-scroll-bars
356 Whether the frame has scroll bars for vertical scrolling
357 (non-@code{nil} means yes).
359 @item horizontal-scroll-bars
360 Whether the frame has scroll bars for horizontal scrolling
361 (non-@code{nil} means yes). (Horizontal scroll bars are not currently
364 @item scroll-bar-width
365 The width of the vertical scroll bar, in pixels.
368 The type of icon to use for this frame when it is iconified. If the
369 value is a string, that specifies a file containing a bitmap to use.
370 Any other non-@code{nil} value specifies the default bitmap icon (a
371 picture of a gnu); @code{nil} specifies a text icon.
374 The name to use in the icon for this frame, when and if the icon
375 appears. If this is @code{nil}, the frame's title is used.
377 @item foreground-color
378 The color to use for the image of a character. This is a string; the X
379 server defines the meaningful color names.
381 @item background-color
382 The color to use for the background of characters.
385 The color for the mouse pointer.
388 The color for the cursor that shows point.
391 The color for the border of the frame.
394 The way to display the cursor. The legitimate values are @code{bar},
395 @code{box}, and @code{(bar . @var{width})}. The symbol @code{box}
396 specifies an ordinary black box overlaying the character after point;
397 that is the default. The symbol @code{bar} specifies a vertical bar
398 between characters as the cursor. @code{(bar . @var{width})} specifies
399 a bar @var{width} pixels wide.
402 The width in pixels of the window border.
404 @item internal-border-width
405 The distance in pixels between text and border.
408 If non-@code{nil}, this frame's window is never split automatically.
411 The state of visibility of the frame. There are three possibilities:
412 @code{nil} for invisible, @code{t} for visible, and @code{icon} for
413 iconified. @xref{Visibility of Frames}.
416 The number of lines to allocate at the top of the frame for a menu bar.
417 The default is 1. @xref{Menu Bar}. (In Emacs versions that use the X
418 toolkit, there is only one menu bar line; all that matters about the
419 number you specify is whether it is greater than zero.)
422 @c ??? Not yet working.
423 The X window number of the window that should be the parent of this one.
424 Specifying this lets you create an Emacs window inside some other
425 application's window. (It is not certain this will be implemented; try
426 it and see if it works.)
429 @node Size and Position
430 @subsection Frame Size And Position
432 You can read or change the size and position of a frame using the
433 frame parameters @code{left}, @code{top}, @code{height}, and
434 @code{width}. Whatever geometry parameters you don't specify are chosen
435 by the window manager in its usual fashion.
437 Here are some special features for working with sizes and positions:
439 @defun set-frame-position frame left top
440 This function sets the position of the top left corner of @var{frame} to
441 @var{left} and @var{top}. These arguments are measured in pixels, and
442 count from the top left corner of the screen. Negative parameter values
443 count up or rightward from the top left corner of the screen.
446 @defun frame-height &optional frame
447 @defunx frame-width &optional frame
448 These functions return the height and width of @var{frame}, measured in
449 characters. If you don't supply @var{frame}, they use the selected
453 @defun frame-pixel-height &optional frame
454 @defunx frame-pixel-width &optional frame
455 These functions return the height and width of @var{frame}, measured in
456 pixels. If you don't supply @var{frame}, they use the selected frame.
459 @defun frame-char-height &optional frame
460 @defunx frame-char-width &optional frame
461 These functions return the height and width of a character in
462 @var{frame}, measured in pixels. The values depend on the choice of
463 font. If you don't supply @var{frame}, these functions use the selected
467 @defun set-frame-size frame cols rows
468 This function sets the size of @var{frame}, measured in characters;
469 @var{cols} and @var{rows} specify the new width and height.
471 To set the size based on values measured in pixels, use
472 @code{frame-char-height} and @code{frame-char-width} to convert
473 them to units of characters.
476 The old-fashioned functions @code{set-screen-height} and
477 @code{set-screen-width}, which were used to specify the height and width
478 of the screen in Emacs versions that did not support multiple frames,
479 are still usable. They apply to the selected frame. @xref{Screen
482 @defun x-parse-geometry geom
483 @cindex geometry specification
484 The function @code{x-parse-geometry} converts a standard X windows
485 geometry string to an alist that you can use as part of the argument to
488 The alist describes which parameters were specified in @var{geom}, and
489 gives the values specified for them. Each element looks like
490 @code{(@var{parameter} . @var{value})}. The possible @var{parameter}
491 values are @code{left}, @code{top}, @code{width}, and @code{height}.
493 For the size parameters, the value must be an integer. The position
494 parameter names @code{left} and @code{top} are not totally accurate,
495 because some values indicate the position of the right or bottom edges
496 instead. These are the @var{value} possibilities for the position
501 A positive integer relates the left edge or top edge of the window to
502 the left or top edge of the screen. A negative integer relates the
503 right or bottom edge of the window to the right or bottom edge of the
506 @item @code{(+ @var{position})}
507 This specifies the position of the left or top edge of the window
508 relative to the left or top edge of the screen. The integer
509 @var{position} may be positive or negative; a negative value specifies a
510 position outside the screen.
512 @item @code{(- @var{position})}
513 This specifies the position of the right or bottom edge of the window
514 relative to the right or bottom edge of the screen. The integer
515 @var{position} may be positive or negative; a negative value specifies a
516 position outside the screen.
522 (x-parse-geometry "35x70+0-0")
523 @result{} ((width . 35) (height . 70)
524 (left . 0) (top - 0))
529 New functions @code{set-frame-height} and @code{set-frame-width} set the
530 size of a specified frame. The frame is the first argument; the size is
535 @section Frame Titles
537 Every frame has a title; most window managers display the frame title at
538 the top of the frame. You can specify an explicit title with the
539 @code{name} frame property. But normally you don't specify this
540 explicitly, and Emacs computes the title automatically.
542 Emacs computes the frame title based on a template stored in the
543 variable @code{frame-title-format}.
545 @defvar frame-title-format
546 This variable specifies how to compute a title for a frame
547 when you have not explicitly specified one.
549 The variable's value is actually a mode line construct, just like
550 @code{mode-line-format}. @xref{Mode Line Data}.
553 @defvar icon-title-format
554 This variable specifies how to compute the title for an iconified frame,
555 when you have not explicitly specified the frame title. This title
556 appears in the icon itself.
559 @defvar multiple-frames
560 This variable is set automatically by Emacs. Its value is @code{t} when
561 there are two or more frames (not counting minibuffer-only frames or
562 invisible frames). The default value of @code{frame-title-format} uses
563 @code{multiple-frames} so as to put the buffer name in the frame title
564 only when there is more than one frame.
567 @node Deleting Frames
568 @section Deleting Frames
569 @cindex deletion of frames
571 Frames remain potentially visible until you explicitly @dfn{delete}
572 them. A deleted frame cannot appear on the screen, but continues to
573 exist as a Lisp object until there are no references to it. There is no
574 way to cancel the deletion of a frame aside from restoring a saved frame
575 configuration (@pxref{Frame Configurations}); this is similar to the
578 @deffn Command delete-frame &optional frame
579 This function deletes the frame @var{frame}. By default, @var{frame} is
583 @defun frame-live-p frame
584 The function @code{frame-live-p} returns non-@code{nil} if the frame
585 @var{frame} has not been deleted.
588 Some window managers provide a command to delete a window. These work
589 by sending a special message to the program that operates the window.
590 When Emacs gets one of these commands, it generates a
591 @code{delete-frame} event, whose normal definition is a command that
592 calls the function @code{delete-frame}. @xref{Misc Events}.
594 @node Finding All Frames
595 @section Finding All Frames
598 The function @code{frame-list} returns a list of all the frames that
599 have not been deleted. It is analogous to @code{buffer-list} for
600 buffers. The list that you get is newly created, so modifying the list
601 doesn't have any effect on the internals of Emacs.
604 @defun visible-frame-list
605 This function returns a list of just the currently visible frames.
606 @xref{Visibility of Frames}. (Terminal frames always count as
607 ``visible'', even though only the selected one is actually displayed.)
610 @defun next-frame &optional frame minibuf
611 The function @code{next-frame} lets you cycle conveniently through all
612 the frames from an arbitrary starting point. It returns the ``next''
613 frame after @var{frame} in the cycle. If @var{frame} is omitted or
614 @code{nil}, it defaults to the selected frame.
616 The second argument, @var{minibuf}, says which frames to consider:
620 Exclude minibuffer-only frames.
622 Consider all visible frames.
624 Consider all visible or iconified frames.
626 Consider only the frames using that particular window as their
633 @defun previous-frame &optional frame minibuf
634 Like @code{next-frame}, but cycles through all frames in the opposite
638 See also @code{next-window} and @code{previous-window}, in @ref{Cyclic
641 @node Frames and Windows
642 @section Frames and Windows
644 Each window is part of one and only one frame; you can get the frame
645 with @code{window-frame}.
647 @defun window-frame window
648 This function returns the frame that @var{window} is on.
651 All the non-minibuffer windows in a frame are arranged in a cyclic
652 order. The order runs from the frame's top window, which is at the
653 upper left corner, down and to the right, until it reaches the window at
654 the lower right corner (always the minibuffer window, if the frame has
655 one), and then it moves back to the top.
657 @defun frame-top-window frame
658 This returns the topmost, leftmost window of frame @var{frame}.
661 At any time, exactly one window on any frame is @dfn{selected within the
662 frame}. The significance of this designation is that selecting the
663 frame also selects this window. You can get the frame's current
664 selected window with @code{frame-selected-window}.
666 @defun frame-selected-window frame
667 This function returns the window on @var{frame} that is selected within
671 Conversely, selecting a window for Emacs with @code{select-window} also
672 makes that window selected within its frame. @xref{Selecting Windows}.
674 Another function that (usually) returns one of the windows in a frame is
675 @code{minibuffer-window}. @xref{Minibuffer Misc}.
677 @node Minibuffers and Frames
678 @section Minibuffers and Frames
680 Normally, each frame has its own minibuffer window at the bottom, which
681 is used whenever that frame is selected. If the frame has a minibuffer,
682 you can get it with @code{minibuffer-window} (@pxref{Minibuffer Misc}).
684 However, you can also create a frame with no minibuffer. Such a frame
685 must use the minibuffer window of some other frame. When you create the
686 frame, you can specify explicitly the minibuffer window to use (in some
687 other frame). If you don't, then the minibuffer is found in the frame
688 which is the value of the variable @code{default-minibuffer-frame}. Its
689 value should be a frame that does have a minibuffer.
691 If you use a minibuffer-only frame, you might want that frame to raise
692 when you enter the minibuffer. If so, set the variable
693 @code{minibuffer-auto-raise} to @code{t}. @xref{Raising and Lowering}.
695 @defvar default-minibuffer-frame
696 This variable specifies the frame to use for the minibuffer window, by
697 default. It is always local to the current terminal and cannot be
698 buffer-local. @xref{Multiple Displays}.
704 @cindex selected frame
706 At any time, one frame in Emacs is the @dfn{selected frame}. The selected
707 window always resides on the selected frame.
709 @defun selected-frame
710 This function returns the selected frame.
713 The X server normally directs keyboard input to the X window that the
714 mouse is in. Some window managers use mouse clicks or keyboard events
715 to @dfn{shift the focus} to various X windows, overriding the normal
716 behavior of the server.
718 Lisp programs can switch frames ``temporarily'' by calling
719 the function @code{select-frame}. This does not override the window
720 manager; rather, it escapes from the window manager's control until
721 that control is somehow reasserted.
723 When using a text-only terminal, there is no window manager; therefore,
724 @code{switch-frame} is the only way to switch frames, and the effect
725 lasts until overridden by a subsequent call to @code{switch-frame}.
726 Only the selected terminal frame is actually displayed on the terminal.
727 Each terminal screen except for the initial one has a number, and the
728 number of the selected frame appears in the mode line after the word
729 @samp{Emacs} (@pxref{Mode Line Variables}).
731 @c ??? This is not yet implemented properly.
732 @defun select-frame frame
733 This function selects frame @var{frame}, temporarily disregarding the
734 focus of the X server if any. The selection of @var{frame} lasts until
735 the next time the user does something to select a different frame, or
736 until the next time this function is called.
739 Emacs cooperates with the X server and the window managers by arranging
740 to select frames according to what the server and window manager ask
741 for. It does so by generating a special kind of input event, called a
742 @dfn{focus} event. The command loop handles a focus event by calling
743 @code{handle-switch-frame}. @xref{Focus Events}.
745 @deffn Command handle-switch-frame frame
746 This function handles a focus event by selecting frame @var{frame}.
748 Focus events normally do their job by invoking this command.
749 Don't call it for any other reason.
752 @defun redirect-frame-focus frame focus-frame
753 This function redirects focus from @var{frame} to @var{focus-frame}.
754 This means that @var{focus-frame} will receive subsequent keystrokes
755 intended for @var{frame}. After such an event, the value of
756 @code{last-event-frame} will be @var{focus-frame}. Also, switch-frame
757 events specifying @var{frame} will instead select @var{focus-frame}.
759 If @var{focus-frame} is @code{nil}, that cancels any existing
760 redirection for @var{frame}, which therefore once again receives its own
763 One use of focus redirection is for frames that don't have minibuffers.
764 These frames use minibuffers on other frames. Activating a minibuffer
765 on another frame redirects focus to that frame. This puts the focus on
766 the minibuffer's frame, where it belongs, even though the mouse remains
767 in the frame that activated the minibuffer.
769 Selecting a frame can also change focus redirections. Selecting frame
770 @code{bar}, when @code{foo} had been selected, changes any redirections
771 pointing to @code{foo} so that they point to @code{bar} instead. This
772 allows focus redirection to work properly when the user switches from
773 one frame to another using @code{select-window}.
775 This means that a frame whose focus is redirected to itself is treated
776 differently from a frame whose focus is not redirected.
777 @code{select-frame} affects the former but not the latter.
779 The redirection lasts until @code{redirect-frame-focus} is called to
783 @node Visibility of Frames
784 @section Visibility of Frames
785 @cindex visible frame
786 @cindex invisible frame
787 @cindex iconified frame
788 @cindex frame visibility
790 An X window frame may be @dfn{visible}, @dfn{invisible}, or
791 @dfn{iconified}. If it is visible, you can see its contents. If it is
792 iconified, the frame's contents do not appear on the screen, but an icon
793 does. If the frame is invisible, it doesn't show on the screen, not
796 Visibility is meaningless for terminal frames, since only the selected
797 one is actually displayed in any case.
799 @deffn Command make-frame-visible &optional frame
800 This function makes frame @var{frame} visible. If you omit @var{frame},
801 it makes the selected frame visible.
804 @deffn Command make-frame-invisible &optional frame
805 This function makes frame @var{frame} invisible. If you omit
806 @var{frame}, it makes the selected frame invisible.
809 @deffn Command iconify-frame &optional frame
810 This function iconifies frame @var{frame}. If you omit @var{frame}, it
811 iconifies the selected frame.
814 @defun frame-visible-p frame
815 This returns the visibility status of frame @var{frame}. The value is
816 @code{t} if @var{frame} is visible, @code{nil} if it is invisible, and
817 @code{icon} if it is iconified.
820 The visibility status of a frame is also available as a frame
821 parameter. You can read or change it as such. @xref{X Frame
824 The user can iconify and deiconify frames with the window manager.
825 This happens below the level at which Emacs can exert any control, but
826 Emacs does provide events that you can use to keep track of such
827 changes. @xref{Misc Events}.
829 @node Raising and Lowering
830 @section Raising and Lowering Frames
832 The X Window System uses a desktop metaphor. Part of this metaphor is
833 the idea that windows are stacked in a notional third dimension
834 perpendicular to the screen surface, and thus ordered from ``highest''
835 to ``lowest''. Where two windows overlap, the one higher up covers the
836 one underneath. Even a window at the bottom of the stack can be seen if
837 no other window overlaps it.
839 @cindex raising a frame
840 @cindex lowering a frame
841 A window's place in this ordering is not fixed; in fact, users tend to
842 change the order frequently. @dfn{Raising} a window means moving it
843 ``up'', to the top of the stack. @dfn{Lowering} a window means moving
844 it to the bottom of the stack. This motion is in the notional third
845 dimension only, and does not change the position of the window on the
848 You can raise and lower Emacs's X windows with these functions:
850 @deffn Command raise-frame frame
851 This function raises frame @var{frame}.
854 @deffn Command lower-frame frame
855 This function lowers frame @var{frame}.
858 @defopt minibuffer-auto-raise
859 If this is non-@code{nil}, activation of the minibuffer raises the frame
860 that the minibuffer window is in.
863 You can also enable auto-raise (raising automatically when a frame is
864 selected) or auto-lower (lowering automatically when it is deselected)
865 for any frame using frame parameters. @xref{X Frame Parameters}.
867 @node Frame Configurations
868 @section Frame Configurations
869 @cindex frame configuration
871 A @dfn{frame configuration} records the current arrangement of frames,
872 all their properties, and the window configuration of each one.
874 @defun current-frame-configuration
875 This function returns a frame configuration list that describes
876 the current arrangement of frames and their contents.
879 @defun set-frame-configuration configuration
880 This function restores the state of frames described in
885 @section Mouse Tracking
886 @cindex mouse tracking
887 @cindex tracking the mouse
889 Sometimes it is useful to @dfn{track} the mouse, which means to display
890 something to indicate where the mouse is and move the indicator as the
891 mouse moves. For efficient mouse tracking, you need a way to wait until
892 the mouse actually moves.
894 The convenient way to track the mouse is to ask for events to represent
895 mouse motion. Then you can wait for motion by waiting for an event. In
896 addition, you can easily handle any other sorts of events that may
897 occur. That is useful, because normally you don't want to track the
898 mouse forever---only until some other event, such as the release of a
901 @defspec track-mouse body@dots{}
902 Execute @var{body}, meanwhile generating input events for mouse motion.
903 The code in @var{body} can read these events with @code{read-event} or
904 @code{read-key-sequence}. @xref{Motion Events}, for the format of mouse
907 The value of @code{track-mouse} is that of the last form in @var{body}.
910 The usual purpose of tracking mouse motion is to indicate on the screen
911 the consequences of pushing or releasing a button at the current
914 In many cases, you can avoid the need to track the mouse by using
915 the @code{mouse-face} text property (@pxref{Special Properties}).
916 That works at a much lower level and runs more smoothly than
917 Lisp-level mouse tracking.
920 @c These are not implemented yet.
922 These functions change the screen appearance instantaneously. The
923 effect is transient, only until the next ordinary Emacs redisplay. That
924 is ok for mouse tracking, since it doesn't make sense for mouse tracking
925 to change the text, and the body of @code{track-mouse} normally reads
926 the events itself and does not do redisplay.
928 @defun x-contour-region window beg end
929 This function draws lines to make a box around the text from @var{beg}
930 to @var{end}, in window @var{window}.
933 @defun x-uncontour-region window beg end
934 This function erases the lines that would make a box around the text
935 from @var{beg} to @var{end}, in window @var{window}. Use it to remove
936 a contour that you previously made by calling @code{x-contour-region}.
939 @defun x-draw-rectangle frame left top right bottom
940 This function draws a hollow rectangle on frame @var{frame} with the
941 specified edge coordinates, all measured in pixels from the inside top
942 left corner. It uses the cursor color, the one used for indicating the
946 @defun x-erase-rectangle frame left top right bottom
947 This function erases a hollow rectangle on frame @var{frame} with the
948 specified edge coordinates, all measured in pixels from the inside top
949 left corner. Erasure means redrawing the text and background that
950 normally belong in the specified rectangle.
955 @section Mouse Position
956 @cindex mouse position
957 @cindex position of mouse
959 The functions @code{mouse-position} and @code{set-mouse-position}
960 give access to the current position of the mouse.
962 @defun mouse-position
963 This function returns a description of the position of the mouse. The
964 value looks like @code{(@var{frame} @var{x} . @var{y})}, where @var{x}
965 and @var{y} are integers giving the position in characters relative to
966 the top left corner of the inside of @var{frame}.
969 @defun set-mouse-position frame x y
970 This function @dfn{warps the mouse} to position @var{x}, @var{y} in
971 frame @var{frame}. The arguments @var{x} and @var{y} are integers,
972 giving the position in characters relative to the top left corner of the
973 inside of @var{frame}.
976 @defun mouse-pixel-position
977 This function is like @code{mouse-position} except that it returns
978 coordinates in units of pixels rather than units of characters.
981 @defun set-mouse-pixel-position frame x y
982 This function warps the mouse like @code{set-mouse-position} except that
983 @var{x} and @var{y} are in units of pixels rather than units of
984 characters. These coordinates are not required to be within the frame.
990 @section Pop-Up Menus
992 When using X windows, a Lisp program can pop up a menu which the
993 user can choose from with the mouse.
995 @defun x-popup-menu position menu
996 This function displays a pop-up menu and returns an indication of
997 what selection the user makes.
999 The argument @var{position} specifies where on the screen to put the
1000 menu. It can be either a mouse button event (which says to put the menu
1001 where the user actuated the button) or a list of this form:
1004 ((@var{xoffset} @var{yoffset}) @var{window})
1008 where @var{xoffset} and @var{yoffset} are coordinates, measured in
1009 pixels, counting from the top left corner of @var{window}'s frame.
1011 If @var{position} is @code{t}, it means to use the current mouse
1012 position. If @var{position} is @code{nil}, it means to precompute the
1013 key binding equivalents for the keymaps specified in @var{menu},
1014 without actually displaying or popping up the menu.
1016 The argument @var{menu} says what to display in the menu. It can be a
1017 keymap or a list of keymaps (@pxref{Menu Keymaps}). Alternatively, it
1018 can have the following form:
1021 (@var{title} @var{pane1} @var{pane2}...)
1025 where each pane is a list of form
1028 (@var{title} (@var{line} . @var{item})...)
1031 Each @var{line} should be a string, and each @var{item} should be the
1032 value to return if that @var{line} is chosen.
1035 @strong{Usage note:} Don't use @code{x-popup-menu} to display a menu if
1036 a prefix key with a menu keymap would do the job. If you use a menu
1037 keymap to implement a menu, @kbd{C-h c} and @kbd{C-h a} can see the
1038 individual items in that menu and provide help for them. If instead you
1039 implement the menu by defining a command that calls @code{x-popup-menu},
1040 the help facilities cannot know what happens inside that command, so
1041 they cannot give any help for the menu's items.
1043 The menu bar mechanism, which lets you switch between submenus by
1044 moving the mouse, cannot look within the definition of a command to see
1045 that it calls @code{x-popup-menu}. Therefore, if you try to implement a
1046 submenu using @code{x-popup-menu}, it cannot work with the menu bar in
1047 an integrated fashion. This is why all menu bar submenus are
1048 implemented with menu keymaps within the parent menu, and never with
1049 @code{x-popup-menu}. @xref{Menu Bar},
1051 If you want a menu bar submenu to have contents that vary, you should
1052 still use a menu keymap to implement it. To make the contents vary, add
1053 a hook function to @code{menu-bar-update-hook} to update the contents of
1054 the menu keymap as necessary.
1057 @section Dialog Boxes
1058 @cindex dialog boxes
1060 A dialog box is a variant of a pop-up menu. It looks a little
1061 different (if Emacs uses an X toolkit), it always appears in the center
1062 of a frame, and it has just one level and one pane. The main use of
1063 dialog boxes is for asking questions that the user can answer with
1064 ``yes'', ``no'', and a few other alternatives. The functions
1065 @code{y-or-n-p} and @code{yes-or-no-p} use dialog boxes instead of the
1066 keyboard, when called from commands invoked by mouse clicks.
1068 @defun x-popup-dialog position contents
1069 This function displays a pop-up dialog box and returns an indication of
1070 what selection the user makes. The argument @var{contents} specifies
1071 the alternatives to offer; it has this format:
1074 (@var{title} (@var{string} . @var{value})@dots{})
1078 which looks like the list that specifies a single pane for
1079 @code{x-popup-menu}.
1081 The return value is @var{value} from the chosen alternative.
1083 An element of the list may be just a string instead of a cons cell
1084 @code{(@var{string} . @var{value})}. That makes a box that cannot
1087 If @code{nil} appears in the list, it separates the left-hand items from
1088 the right-hand items; items that precede the @code{nil} appear on the
1089 left, and items that follow the @code{nil} appear on the right. If you
1090 don't include a @code{nil} in the list, then approximately half the
1091 items appear on each side.
1093 Dialog boxes always appear in the center of a frame; the argument
1094 @var{position} specifies which frame. The possible values are as in
1095 @code{x-popup-menu}, but the precise coordinates don't matter; only the
1098 If your Emacs executable does not use an X toolkit, then it cannot
1099 display a real dialog box; so instead it displays the same items in a
1100 pop-up menu in the center of the frame.
1103 @node Pointer Shapes
1104 @section Pointer Shapes
1105 @cindex pointer shape
1106 @cindex mouse pointer shape
1108 These variables specify which shape to use for the mouse pointer in
1112 @item x-pointer-shape
1113 @vindex x-pointer-shape
1114 This variable specifies the pointer shape to use ordinarily in the Emacs
1117 @item x-sensitive-text-pointer-shape
1118 @vindex x-sensitive-text-pointer-shape
1119 This variable specifies the pointer shape to use when the mouse
1120 is over mouse-sensitive text.
1123 These variables affect newly created frames. They do not normally
1124 affect existing frames; however, if you set the mouse color of a frame,
1125 that also updates its pointer shapes based on the current values of
1126 these variables. @xref{X Frame Parameters}.
1128 The values you can use, to specify either of these pointer shapes, are
1129 defined in the file @file{lisp/x-win.el}. Use @kbd{M-x apropos
1130 @key{RET} x-pointer @key{RET}} to see a list of them.
1133 @section X Selections
1134 @cindex selection (for X windows)
1136 The X server records a set of @dfn{selections} which permit transfer of
1137 data between application programs. The various selections are
1138 distinguished by @dfn{selection types}, represented in Emacs by
1139 symbols. X clients including Emacs can read or set the selection for
1142 @defun x-set-selection type data
1143 This function sets a ``selection'' in the X server. It takes two
1144 arguments: a selection type @var{type}, and the value to assign to it,
1145 @var{data}. If @var{data} is @code{nil}, it means to clear out the
1146 selection. Otherwise, @var{data} may be a string, a symbol, an integer
1147 (or a cons of two integers or list of two integers), an overlay, or a
1148 cons of two markers pointing to the same buffer. An overlay or a pair
1149 of markers stands for text in the overlay or between the markers.
1151 The data may also be a vector of valid non-vector selection values.
1153 Each possible @var{type} has its own selection value, which changes
1154 independently. The usual values of @var{type} are @code{PRIMARY} and
1155 @code{SECONDARY}; these are symbols with upper-case names, in accord
1156 with X Window System conventions. The default is @code{PRIMARY}.
1159 @defun x-get-selection &optional type data-type
1160 This function accesses selections set up by Emacs or by other X
1161 clients. It takes two optional arguments, @var{type} and
1162 @var{data-type}. The default for @var{type}, the selection type, is
1165 The @var{data-type} argument specifies the form of data conversion to
1166 use, to convert the raw data obtained from another X client into Lisp
1167 data. Meaningful values include @code{TEXT}, @code{STRING},
1168 @code{TARGETS}, @code{LENGTH}, @code{DELETE}, @code{FILE_NAME},
1169 @code{CHARACTER_POSITION}, @code{LINE_NUMBER}, @code{COLUMN_NUMBER},
1170 @code{OWNER_OS}, @code{HOST_NAME}, @code{USER}, @code{CLASS},
1171 @code{NAME}, @code{ATOM}, and @code{INTEGER}. (These are symbols with
1172 upper-case names in accord with X conventions.) The default for
1173 @var{data-type} is @code{STRING}.
1177 The X server also has a set of numbered @dfn{cut buffers} which can
1178 store text or other data being moved between applications. Cut buffers
1179 are considered obsolete, but Emacs supports them for the sake of X
1180 clients that still use them.
1182 @defun x-get-cut-buffer n
1183 This function returns the contents of cut buffer number @var{n}.
1186 @defun x-set-cut-buffer string
1187 This function stores @var{string} into the first cut buffer (cut buffer
1188 0), moving the other values down through the series of cut buffers, much
1189 like the way successive kills in Emacs move down the kill ring.
1193 @section Color Names
1195 @defun x-color-defined-p color &optional frame
1196 This function reports whether a color name is meaningful. It returns
1197 @code{t} if so; otherwise, @code{nil}. The argument @var{frame} says
1198 which frame's display to ask about; if @var{frame} is omitted or
1199 @code{nil}, the selected frame is used.
1201 Note that this does not tell you whether the display you are using
1202 really supports that color. You can ask for any defined color on any
1203 kind of display, and you will get some result---that is how the X server
1204 works. Here's an approximate way to test whether your display supports
1205 the color @var{color}:
1208 (defun x-color-supported-p (color &optional frame)
1209 (and (x-color-defined-p color frame)
1210 (or (x-display-color-p frame)
1211 (member color '("black" "white"))
1212 (and (> (x-display-planes frame) 1)
1213 (equal color "gray")))))
1217 @defun x-color-values color &optional frame
1218 This function returns a value that describes what @var{color} should
1219 ideally look like. If @var{color} is defined, the value is a list of
1220 three integers, which give the amount of red, the amount of green, and
1221 the amount of blue. Each integer ranges in principle from 0 to 65535,
1222 but in practice no value seems to be above 65280. If @var{color} is not
1223 defined, the value is @code{nil}.
1226 (x-color-values "black")
1228 (x-color-values "white")
1229 @result{} (65280 65280 65280)
1230 (x-color-values "red")
1231 @result{} (65280 0 0)
1232 (x-color-values "pink")
1233 @result{} (65280 49152 51968)
1234 (x-color-values "hungry")
1238 The color values are returned for @var{frame}'s display. If @var{frame}
1239 is omitted or @code{nil}, the information is return for the selected
1244 @section X Resources
1246 @defun x-get-resource attribute class &optional component subclass
1247 The function @code{x-get-resource} retrieves a resource value from the X
1248 Windows defaults database.
1250 Resources are indexed by a combination of a @dfn{key} and a @dfn{class}.
1251 This function searches using a key of the form
1252 @samp{@var{instance}.@var{attribute}} (where @var{instance} is the name
1253 under which Emacs was invoked), and using @samp{Emacs.@var{class}} as
1256 The optional arguments @var{component} and @var{subclass} add to the key
1257 and the class, respectively. You must specify both of them or neither.
1258 If you specify them, the key is
1259 @samp{@var{instance}.@var{component}.@var{attribute}}, and the class is
1260 @samp{Emacs.@var{class}.@var{subclass}}.
1263 @xref{Resources X,, X Resources, emacs, The GNU Emacs Manual}.
1266 @section Data about the X Server
1268 This section describes functions you can use to get information about
1269 the capabilities and origin of an X display that Emacs is using. Each
1270 of these functions lets you specify the display you are interested in:
1271 the @var{display} argument can be either a display name, or a frame
1272 (meaning use the display that frame is on). If you omit the
1273 @var{display} argument, or specify @code{nil}, that means to use the
1274 selected frame's display.
1276 @defun x-display-screens &optional display
1277 This function returns the number of screens associated with the display.
1280 @defun x-server-version &optional display
1281 This function returns the list of version numbers of the X server
1282 running the display.
1285 @defun x-server-vendor &optional display
1286 This function returns the vendor that provided the X server software.
1289 @defun x-display-pixel-height &optional display
1290 This function returns the height of the screen in pixels.
1293 @defun x-display-mm-height &optional display
1294 This function returns the height of the screen in millimeters.
1297 @defun x-display-pixel-width &optional display
1298 This function returns the width of the screen in pixels.
1301 @defun x-display-mm-width &optional display
1302 This function returns the width of the screen in millimeters.
1305 @defun x-display-backing-store &optional display
1306 This function returns the backing store capability of the screen.
1307 Values can be the symbols @code{always}, @code{when-mapped}, or
1311 @defun x-display-save-under &optional display
1312 This function returns non-@code{nil} if the display supports the
1316 @defun x-display-planes &optional display
1317 This function returns the number of planes the display supports.
1320 @defun x-display-visual-class &optional display
1321 This function returns the visual class for the screen. The value is one
1322 of the symbols @code{static-gray}, @code{gray-scale},
1323 @code{static-color}, @code{pseudo-color}, @code{true-color}, and
1324 @code{direct-color}.
1327 @defun x-display-grayscale-p &optional display
1328 This function returns @code{t} if the screen can display shades of gray.
1331 @defun x-display-color-p &optional display
1332 This function returns @code{t} if the screen is a color screen.
1335 @defun x-display-color-cells &optional display
1336 This function returns the number of color cells the screen supports.
1340 @defvar x-no-window-manager
1341 This variable's value is is @code{t} if no X window manager is in use.
1347 The functions @code{x-pixel-width} and @code{x-pixel-height} return the
1348 width and height of an X Window frame, measured in pixels.