Initial git import
[sxemacs] / info / lispref / frames.texi
1 @c -*-texinfo-*-
2 @c This is part of the SXEmacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4 @c Copyright (C) 1995, 1996 Ben Wing.
5 @c Copyright (C) 2005 Sebastian Freundt <hroptatyr@sxemacs.org>
6 @c See the file lispref.texi for copying conditions.
7 @setfilename ../../info/frames.info
8
9 @node Frames, Consoles and Devices, Windows, Top
10 @chapter Frames
11 @cindex frame
12
13   A @var{frame} is a rectangle on the screen that contains one or more
14 SXEmacs windows (@pxref{Windows}).  A frame initially contains a single
15 main window (plus perhaps an echo area), which you can subdivide
16 vertically or horizontally into smaller windows.  Each window is
17 associated with a modeline (@pxref{Modeline Format}), and optionally two
18 scrollbars (@pxref{Scrollbars}).  By default the vertical scrollbar is
19 on, the horizontal scrollbar is off.
20
21   The frame may also contain menubars (@pxref{Menubar}), toolbars
22 (@pxref{Toolbar Intro}), and gutters (@pxref{Gutter Intro}).  By default
23 there is one of each at the top of the frame, with menubar topmost,
24 toolbar next, and gutter lowest, immediately above the windows.
25
26
27 @cindex terminal frame
28 @cindex X window frame
29   When SXEmacs runs on a text-only terminal, it starts with one
30 @dfn{TTY frame}.  If you create additional ones, SXEmacs displays
31 one and only one at any given time---on the terminal screen, of course.
32
33   When SXEmacs communicates directly with an X server, it does not have a
34 TTY frame; instead, it starts with a single @dfn{X window frame}.
35 It can display multiple X window frames at the same time, each in its
36 own X window.
37
38 @defun framep object
39 This predicate returns @code{t} if @var{object} is a frame, and
40 @code{nil} otherwise.
41 @end defun
42
43 @menu
44 * Creating Frames::             Creating additional frames.
45 * Frame Properties::            Controlling frame size, position, font, etc.
46 * Frame Titles::                Automatic updating of frame titles.
47 * Deleting Frames::             Frames last until explicitly deleted.
48 * Finding All Frames::          How to examine all existing frames.
49 * Frames and Windows::          A frame contains windows;
50                                   display of text always works through windows.
51 * Minibuffers and Frames::      How a frame finds the minibuffer to use.
52 * Input Focus::                 Specifying the selected frame.
53 * Visibility of Frames::        Frames may be visible or invisible, or icons.
54 * Raising and Lowering::        Raising a frame makes it hide other X windows;
55                                   lowering it makes the others hide them.
56 * Frame Configurations::        Saving the state of all frames.
57 * Frame Hooks::                 Hooks for customizing frame behavior.
58 @end menu
59
60   @xref{Display}, for related information.
61
62
63 @node Creating Frames
64 @section Creating Frames
65
66 To create a new frame, call the function @code{make-frame}.
67
68 @deffn Command make-frame &optional props device
69 This function creates a new frame on @var{device}, if @var{device}
70 permits creation of frames.  (An X server does; an ordinary terminal
71 does not (yet).)  @var{device} defaults to the selected device if omitted.
72 @xref{Consoles and Devices}.
73
74 The argument @var{props} is a property list (a list of alternating
75 keyword-value specifications) of properties for the new frame. (An alist
76 is accepted for backward compatibility but should not be passed in.) Any
77 properties not mentioned in @var{props} default according to the value
78 of the variable @code{default-frame-plist}.
79
80 For X devices, properties not specified in @code{default-frame-plist}
81 default in turn from @code{default-x-frame-plist} and, if not specified
82 there, from the X resources.  For TTY devices,
83 @code{default-tty-frame-plist} is consulted as well as
84 @code{default-frame-plist}.
85
86 The set of possible properties depends in principle on what kind of
87 window system SXEmacs uses to display its frames.  @xref{X Frame
88 Properties}, for documentation of individual properties you can specify
89 when creating an X window frame.
90 @end deffn
91
92
93 @node Frame Properties
94 @section Frame Properties
95
96 A frame has many properties that control its appearance and behavior.
97 Just what properties a frame has depends on which display mechanism it
98 uses.
99
100 Frame properties exist for the sake of window systems.  A terminal frame
101 has few properties, mostly for compatibility's sake; only the height,
102 width and @code{buffer-predicate} properties really do something.
103
104 @menu
105 * Property Access::     How to change a frame's properties.
106 * Initial Properties::  Specifying frame properties when you make a frame.
107 * X Frame Properties::  List of frame properties.
108 * Size and Position::   Changing the size and position of a frame.
109 * Frame Name::          The name of a frame (as opposed to its title).
110 @end menu
111
112
113 @node Property Access
114 @subsection Access to Frame Properties
115
116 These functions let you read and change the properties of a frame.
117
118 @defun frame-properties &optional frame
119 This function returns a plist listing all the properties of @var{frame}
120 and their values.
121 @end defun
122
123 @defun frame-property frame property &optional default
124 This function returns @var{frame}'s value for the property
125 @var{property}, or @var{default} if there is no such property.
126 @end defun
127
128 @defun set-frame-properties frame plist
129 This function alters the properties of frame @var{frame} based on the
130 elements of property list @var{plist}.  If you don't mention a property
131 in @var{plist}, its value doesn't change.
132 @end defun
133
134 @defun set-frame-property frame property value
135 This function sets the property @var{property} of frame @var{frame} to the
136 value @var{value}.
137 @end defun
138
139
140 @node Initial Properties
141 @subsection Initial Frame Properties
142
143 You can specify the properties for the initial startup frame by setting
144 @code{initial-frame-plist} in your @file{.emacs} file.
145
146 @defvar initial-frame-plist
147 This variable's value is a plist of alternating property-value pairs
148 used when creating the initial X window frame.
149
150 SXEmacs creates the initial frame before it reads your @file{~/.emacs}
151 file.  After reading that file, SXEmacs checks @code{initial-frame-plist},
152 and applies the property settings in the altered value to the already
153 created initial frame.
154
155 If these settings affect the frame geometry and appearance, you'll see
156 the frame appear with the wrong ones and then change to the specified
157 ones.  If that bothers you, you can specify the same geometry and
158 appearance with X resources; those do take affect before the frame is
159 created.  @xref{Resources X,, X Resources, sxemacs, The SXEmacs User's Manual}.
160
161 X resource settings typically apply to all frames.  If you want to
162 specify some X resources solely for the sake of the initial frame, and
163 you don't want them to apply to subsequent frames, here's how to achieve
164 this: specify properties in @code{default-frame-plist} to override the X
165 resources for subsequent frames; then, to prevent these from affecting
166 the initial frame, specify the same properties in
167 @code{initial-frame-plist} with values that match the X resources.
168 @end defvar
169
170 If these properties specify a separate minibuffer-only frame via a
171 @code{minibuffer} property of @code{nil}, and you have not yet created
172 one, SXEmacs creates one for you.
173
174 @defvar minibuffer-frame-plist
175 This variable's value is a plist of properties used when creating an
176 initial minibuffer-only frame---if such a frame is needed, according to
177 the properties for the main initial frame.
178 @end defvar
179
180 @defvar default-frame-plist
181 This is a plist specifying default values of frame properties for
182 subsequent SXEmacs frames (not the initial ones).
183 @end defvar
184
185 See also @code{special-display-frame-plist}, in @ref{Choosing Window}.
186
187 If you use options that specify window appearance when you invoke SXEmacs,
188 they take effect by adding elements to @code{default-frame-plist}.  One
189 exception is @samp{-geometry}, which adds the specified position to
190 @code{initial-frame-plist} instead.  @xref{Command Arguments,,, sxemacs,
191 The SXEmacs User's Manual}.
192
193
194 @node X Frame Properties
195 @subsection X Window Frame Properties
196
197 Just what properties a frame has depends on what display mechanism it
198 uses.  Here is a table of the properties of an X window frame; of these,
199 @code{name}, @code{height}, @code{width}, and @code{buffer-predicate}
200 provide meaningful information in non-X frames.
201
202 @table @code
203 @item name
204 The name of the frame.  Most window managers display the frame's name in
205 the frame's border, at the top of the frame.  If you don't specify a
206 name, and you have more than one frame, SXEmacs sets the frame name based
207 on the buffer displayed in the frame's selected window.
208
209 If you specify the frame name explicitly when you create the frame, the
210 name is also used (instead of the name of the SXEmacs executable) when
211 looking up X resources for the frame.
212
213 @item display
214 The display on which to open this frame.  It should be a string of the
215 form @code{"@var{host}:@var{dpy}.@var{screen}"}, just like the
216 @code{DISPLAY} environment variable.
217
218 @item left
219 The screen position of the left edge, in pixels, with respect to the
220 left edge of the screen.  The value may be a positive number @var{pos},
221 or a list of the form @code{(+ @var{pos})} which permits specifying a
222 negative @var{pos} value.
223
224 A negative number @minus{}@var{pos}, or a list of the form @code{(-
225 @var{pos})}, actually specifies the position of the right edge of the
226 window with respect to the right edge of the screen.  A positive value
227 of @var{pos} counts toward the left.  If the property is a negative
228 integer @minus{}@var{pos} then @var{pos} is positive!
229
230 @item top
231 The screen position of the top edge, in pixels, with respect to the
232 top edge of the screen.  The value may be a positive number @var{pos},
233 or a list of the form @code{(+ @var{pos})} which permits specifying a
234 negative @var{pos} value.
235
236 A negative number @minus{}@var{pos}, or a list of the form @code{(-
237 @var{pos})}, actually specifies the position of the bottom edge of the
238 window with respect to the bottom edge of the screen.  A positive value
239 of @var{pos} counts toward the top.  If the property is a negative
240 integer @minus{}@var{pos} then @var{pos} is positive!
241
242 @item icon-left
243 The screen position of the left edge @emph{of the frame's icon}, in
244 pixels, counting from the left edge of the screen.  This takes effect if
245 and when the frame is iconified.
246
247 @item icon-top
248 The screen position of the top edge @emph{of the frame's icon}, in
249 pixels, counting from the top edge of the screen.  This takes effect if
250 and when the frame is iconified.
251
252 @item user-position
253 Non-@code{nil} if the screen position of the frame was explicitly
254 requested by the user (for example, with the @samp{-geometry} option).
255 Nothing automatically makes this property non-@code{nil}; it is up to
256 Lisp programs that call @code{make-frame} to specify this property as
257 well as specifying the @code{left} and @code{top} properties.
258
259 @item height
260 The height of the frame contents, in characters.  (To get the height in
261 pixels, call @code{frame-pixel-height}; see @ref{Size and Position}.)
262
263 @item width
264 The width of the frame contents, in characters.  (To get the height in
265 pixels, call @code{frame-pixel-width}; see @ref{Size and Position}.)
266
267 @item window-id
268 The number of the X window for the frame.
269
270 @item minibuffer
271 Whether this frame has its own minibuffer.  The value @code{t} means
272 yes, @code{nil} means no, @code{only} means this frame is just a
273 minibuffer.  If the value is a minibuffer window (in some other frame),
274 the new frame uses that minibuffer.
275
276 Note: Minibuffer-only and minibuffer-less frames are not yet implemented
277 in SXEmacs.
278
279 @item buffer-predicate
280 The buffer-predicate function for this frame.  The function
281 @code{other-buffer} uses this predicate (from the selected frame) to
282 decide which buffers it should consider, if the predicate is not
283 @code{nil}.  It calls the predicate with one arg, a buffer, once for
284 each buffer; if the predicate returns a non-@code{nil} value, it
285 considers that buffer.
286
287 @item scroll-bar-width
288 The width of the vertical scroll bar, in pixels.
289
290 @ignore Not in SXEmacs
291 @item icon-type
292 The type of icon to use for this frame when it is iconified.  If the
293 value is a string, that specifies a file containing a bitmap to use.
294 Any other non-@code{nil} value specifies the default bitmap icon (a
295 picture of a gnu); @code{nil} specifies a text icon.
296
297 @item icon-name
298 The name to use in the icon for this frame, when and if the icon
299 appears.  If this is @code{nil}, the frame's title is used.
300 @end ignore
301
302 @item cursor-color
303 The color for the cursor that shows point.
304
305 @item border-color
306 The color for the border of the frame.
307
308 @ignore Not in SXEmacs
309 @item cursor-type
310 The way to display the cursor.  The legitimate values are @code{bar},
311 @code{box}, and @code{(bar . @var{width})}.  The symbol @code{box}
312 specifies an ordinary black box overlaying the character after point;
313 that is the default.  The symbol @code{bar} specifies a vertical bar
314 between characters as the cursor.  @code{(bar . @var{width})} specifies
315 a bar @var{width} pixels wide.
316 @end ignore
317
318 @item border-width
319 The width in pixels of the window border.
320
321 @item internal-border-width
322 The distance in pixels between text and border.
323
324 @item unsplittable
325 If non-@code{nil}, this frame's window is never split automatically.
326
327 @item inter-line-space
328 The space in pixels between adjacent lines of text. (Not currently
329 implemented.)
330
331 @item modeline
332 Whether the frame has a modeline.
333 @end table
334
335
336 @node Size and Position
337 @subsection Frame Size And Position
338 @cindex size of frame
339 @cindex frame size
340 @cindex display lines
341 @cindex display columns
342 @cindex resize redisplay
343 @cindex frame position
344 @cindex position of frame
345
346   You can read or change the size and position of a frame using the
347 frame properties @code{left}, @code{top}, @code{height}, and
348 @code{width}.  Whatever geometry properties you don't specify are chosen
349 by the window manager in its usual fashion.
350
351   Here are some special features for working with sizes and positions:
352
353 @defun set-frame-position frame left top
354 This function sets the position of the top left corner of @var{frame} to
355 @var{left} and @var{top}.  These arguments are measured in pixels, and
356 count from the top left corner of the screen.  Negative property values
357 count up or rightward from the top left corner of the screen.
358 @end defun
359
360 @defun frame-height &optional frame
361 @defunx frame-width &optional frame
362 These functions return the height and width of @var{frame}, measured in
363 lines and columns.  If you don't supply @var{frame}, they use the selected
364 frame.
365 @end defun
366
367 @defun frame-pixel-height &optional frame
368 @defunx frame-pixel-width &optional frame
369 These functions return the height and width of @var{frame}, measured in
370 pixels.  If you don't supply @var{frame}, they use the selected frame.
371 @end defun
372
373 @defun set-frame-size frame cols rows &optional pretend
374 This function sets the size of @var{frame}, measured in characters;
375 @var{cols} and @var{rows} specify the new width and height.  (If
376 @var{pretend} is non-@code{nil}, it means that redisplay should act as if
377 the frame's size is @var{cols} by @var{rows}, but the actual size
378 of the frame should not be changed.  You should not normally use
379 this option.)
380 @end defun
381
382   You can also use the functions @code{set-frame-height} and
383 @code{set-frame-width} to set the height and width individually.
384 The frame is the first argument and the size (in rows or columns)
385 is the second. (There is an optional third argument, @var{pretend},
386 which has the same purpose as the corresponding argument in
387 @code{set-frame-size}.)
388
389 @ignore  @c Not in SXEmacs
390 @defun x-parse-geometry geom
391 @cindex geometry specification
392 The function @code{x-parse-geometry} converts a standard X windows
393 geometry string to a plist that you can use as part of the argument to
394 @code{make-frame}.
395
396 The plist describes which properties were specified in @var{geom}, and
397 gives the values specified for them.  Each element looks like
398 @code{(@var{property} . @var{value})}.  The possible @var{property}
399 values are @code{left}, @code{top}, @code{width}, and @code{height}.
400
401 For the size properties, the value must be an integer.  The position
402 property names @code{left} and @code{top} are not totally accurate,
403 because some values indicate the position of the right or bottom edges
404 instead.  These are the @var{value} possibilities for the position
405 properties:
406
407 @table @asis
408 @item an integer
409 A positive integer relates the left edge or top edge of the window to
410 the left or top edge of the screen.  A negative integer relates the
411 right or bottom edge of the window to the right or bottom edge of the
412 screen.
413
414 @item @code{(+ @var{position})}
415 This specifies the position of the left or top edge of the window
416 relative to the left or top edge of the screen.  The integer
417 @var{position} may be positive or negative; a negative value specifies a
418 position outside the screen.
419
420 @item @code{(- @var{position})}
421 This specifies the position of the right or bottom edge of the window
422 relative to the right or bottom edge of the screen.  The integer
423 @var{position} may be positive or negative; a negative value specifies a
424 position outside the screen.
425 @end table
426
427 Here is an example:
428
429 @example
430 (x-parse-geometry "35x70+0-0")
431      @result{} ((width . 35) (height . 70)
432          (left . 0) (top - 0))
433 @end example
434 @end defun
435 @end ignore
436
437
438 @node Frame Name
439 @subsection The Name of a Frame (As Opposed to Its Title)
440 @cindex frame name
441
442 Under X, every frame has a name, which is not the same as the title of
443 the frame.  A frame's name is used to look up its resources and does
444 not normally change over the lifetime of a frame.  It is perfectly
445 allowable, and quite common, for multiple frames to have the same
446 name.
447
448 @defun frame-name &optional frame
449 This function returns the name of @var{frame}, which defaults to the
450 selected frame if not specified.  The name of a frame can also be
451 obtained from the frame's properties.  @xref{Frame Properties}.
452 @end defun
453
454 @defvar default-frame-name
455 This variable holds the default name to assign to newly-created frames.
456 This can be overridden by arguments to @code{make-frame}.  This
457 must be a string.
458 @end defvar
459
460
461 @node Frame Titles
462 @section Frame Titles
463
464 Every frame has a title; most window managers display the frame title at
465 the top of the frame.  You can specify an explicit title with the
466 @code{name} frame property.  But normally you don't specify this
467 explicitly, and SXEmacs computes the title automatically.
468
469 SXEmacs computes the frame title based on a template stored in the
470 variable @code{frame-title-format}.
471
472 @defvar frame-title-format
473 This variable specifies how to compute a title for a frame
474 when you have not explicitly specified one.
475
476 The variable's value is actually a modeline construct, just like
477 @code{modeline-format}.  @xref{Modeline Data}.
478 @end defvar
479
480 @defvar frame-icon-title-format
481 This variable specifies how to compute the title for an iconified frame,
482 when you have not explicitly specified the frame title.  This title
483 appears in the icon itself.
484 @end defvar
485
486 @defun x-set-frame-icon-pixmap frame pixmap &optional mask
487 This function sets the icon of the given frame to the given image
488 instance, which should be an image instance object (as returned by
489 @code{make-image-instance}), a glyph object (as returned by
490 @code{make-glyph}), or @code{nil}.  If a glyph object is given, the
491 glyph will be instantiated on the frame to produce an image instance
492 object.
493
494 If the given image instance has a mask, that will be used as the icon mask;
495 however, not all window managers support this.
496
497 The window manager is also not required to support color pixmaps,
498 only bitmaps (one plane deep).
499
500 If the image instance does not have a mask, then the optional
501 third argument may be the image instance to use as the mask (it must be
502 one plane deep).
503 @xref{Glyphs}.
504 @end defun
505
506
507 @node Deleting Frames
508 @section Deleting Frames
509 @cindex deletion of frames
510
511 Frames remain potentially visible until you explicitly @dfn{delete}
512 them.  A deleted frame cannot appear on the screen, but continues to
513 exist as a Lisp object until there are no references to it.
514
515 @deffn Command delete-frame &optional frame force
516 This function deletes the frame @var{frame}.  By default, @var{frame} is
517 the selected frame.
518
519 A frame may not be deleted if its minibuffer is used by other frames.
520 Normally, you cannot delete the last non-minibuffer-only frame (you must
521 use @code{save-buffers-kill-emacs} or @code{kill-emacs}).  However, if
522 optional second argument @var{force} is non-@code{nil}, you can delete
523 the last frame. (This will automatically call
524 @code{save-buffers-kill-emacs}.)
525 @end deffn
526
527 @defun frame-live-p frame
528 The function @code{frame-live-p} returns non-@code{nil} if the frame
529 @var{frame} has not been deleted.
530 @end defun
531
532 @ignore Not in SXEmacs currently
533   Some window managers provide a command to delete a window.  These work
534 by sending a special message to the program that operates the window.
535 When SXEmacs gets one of these commands, it generates a
536 @code{delete-frame} event, whose normal definition is a command that
537 calls the function @code{delete-frame}.  @xref{Misc Events}.
538 @end ignore
539
540
541 @node Finding All Frames
542 @section Finding All Frames
543
544 @defun frame-list
545 The function @code{frame-list} returns a list of all the frames that
546 have not been deleted.  It is analogous to @code{buffer-list} for
547 buffers.  The list that you get is newly created, so modifying the list
548 doesn't have any effect on the internals of SXEmacs.
549 @end defun
550
551 @defun device-frame-list &optional device
552 This function returns a list of all frames on @var{device}.  If
553 @var{device} is @code{nil}, the selected device will be used.
554 @end defun
555
556 @defun visible-frame-list &optional device
557 This function returns a list of just the currently visible frames.
558 If @var{device} is specified only frames on that device will be returned.
559 @xref{Visibility of Frames}.  (TTY frames always count as
560 ``visible'', even though only the selected one is actually displayed.)
561 @end defun
562
563 @defun next-frame &optional frame which-frames which-devices
564 The function @code{next-frame} lets you cycle conveniently through all
565 the frames from an arbitrary starting point.  It returns the ``next''
566 frame after @var{frame} in the cycle.  If @var{frame} defaults to the
567 selected frame.
568
569 The second argument, @var{which-frames}, says which frames to consider:
570
571 @table @asis
572 @item @code{visible}
573 Consider only frames that are visible.
574
575 @item @code{iconic}
576 Consider only frames that are iconic.
577
578 @item @code{invisible}
579 Consider only frames that are invisible (this is different from iconic).
580
581 @item @code{visible-iconic}
582 Consider frames that are visible or iconic.
583
584 @item @code{invisible-iconic}
585 Consider frames that are invisible or iconic.
586
587 @item @code{nomini}
588 Consider all frames except minibuffer-only ones.
589
590 @item @code{visible-nomini}
591 Like @code{visible} but omits minibuffer-only frames.
592
593 @item @code{iconic-nomini}
594 Like @code{iconic} but omits minibuffer-only frames.
595
596 @item @code{invisible-nomini}
597 Like @code{invisible} but omits minibuffer-only frames.
598
599 @item @code{visible-iconic-nomini}
600 Like @code{visible-iconic} but omits minibuffer-only frames.
601
602 @item @code{invisible-iconic-nomini}
603 Like @code{invisible-iconic} but omits minibuffer-only frames.
604
605 @item @code{nil}
606 Identical to @code{nomini}.
607
608 @item @var{window}
609 Consider only the window @var{window}'s frame and any frame now using
610 @var{window} as the minibuffer.
611
612 @item any other value
613 Consider all frames.
614 @end table
615
616 The optional argument @var{which-devices} further clarifies on which
617 devices to search for frames as specified by @var{which-frames}.
618
619 @table @asis
620 @item @code{nil}
621 Consider all devices on the selected console.
622
623 @item @var{device}
624 Consider only the one device @var{device}.
625
626 @item @var{console}
627 Consider all devices on @var{console}.
628
629 @item @var{device-type}
630 Consider all devices with device type @var{device-type}.
631
632 @item @code{window-system}
633 Consider all devices on window system consoles.
634
635 @item anything else
636 Consider all devices without restriction.
637 @end table
638 @end defun
639
640 @defun previous-frame &optional frame which-frames which-devices
641 Like @code{next-frame}, but cycles through all frames in the opposite
642 direction.
643 @end defun
644
645   See also @code{next-window} and @code{previous-window}, in @ref{Cyclic
646 Window Ordering}.
647
648
649 @node Frames and Windows
650 @section Frames and Windows
651
652   Each window is part of one and only one frame; you can get the frame
653 with @code{window-frame}.
654
655 @defun frame-root-window &optional frame
656 This returns the root window of frame @var{frame}.  @var{frame}
657 defaults to the selected frame if not specified.
658 @end defun
659
660 @defun window-frame &optional window
661 This function returns the frame that @var{window} is on.  @var{window}
662 defaults to the selected window if omitted.
663 @end defun
664
665   All the non-minibuffer windows in a frame are arranged in a cyclic
666 order.  The order runs from the frame's top window, which is at the
667 upper left corner, down and to the right, until it reaches the window at
668 the lower right corner (always the minibuffer window, if the frame has
669 one), and then it moves back to the top.
670
671 @defun frame-highest-window &optional frame position
672 This function returns the topmost, leftmost window of frame @var{frame}
673 at position @var{position}.
674
675 If omitted, @var{frame} defaults to the currently selected frame.
676
677 @var{position} is used to distinguish between multiple windows that abut
678 the top of the frame: 0 means the leftmost window abutting the top of
679 the frame, 1 the next-leftmost, etc.  @var{position} can also be less
680 than zero: -1 means the rightmost window abutting the top of the frame,
681 -2 the next-rightmost, etc.  If omitted, @var{position} defaults to 0,
682 i.e. the leftmost highest window.  If there is no window at the given
683 @var{position}, @code{nil} is returned.
684 @end defun
685
686 The following three functions work similarly.
687
688 @defun frame-lowest-window &optional frame position
689 This function returns the lowest window on @var{frame} which is at
690 @var{position}.
691 @end defun
692
693 @defun frame-leftmost-window &optional frame position
694 This function returns the leftmost window on @var{frame} which is at
695 @var{position}.
696 @end defun
697
698 @defun frame-rightmost-window &optional frame position
699 This function returns the rightmost window on @var{frame} which is at
700 @var{position}.
701 @end defun
702
703
704 At any time, exactly one window on any frame is @dfn{selected within the
705 frame}.  The significance of this designation is that selecting the
706 frame also selects this window.  You can get the frame's current
707 selected window with @code{frame-selected-window}.
708
709 @defun frame-selected-window &optional frame
710 This function returns the window on @var{frame} that is selected within
711 @var{frame}.  @var{frame} defaults to the selected frame if not
712 specified.
713 @end defun
714
715 Conversely, selecting a window for XEmacs with @code{select-window} also
716 makes that window selected within its frame.  @xref{Selecting Windows}.
717
718 Another function that (usually) returns one of the windows in a frame is
719 @code{minibuffer-window}.  @xref{Minibuffer Misc}.
720
721
722 @node Minibuffers and Frames
723 @section Minibuffers and Frames
724
725 Normally, each frame has its own minibuffer window at the bottom, which
726 is used whenever that frame is selected.  If the frame has a minibuffer,
727 you can get it with @code{minibuffer-window} (@pxref{Minibuffer Misc}).
728
729 However, you can also create a frame with no minibuffer.  Such a frame
730 must use the minibuffer window of some other frame.  When you create the
731 frame, you can specify explicitly the minibuffer window to use (in some
732 other frame).  If you don't, then the minibuffer is found in the frame
733 which is the value of the variable @code{default-minibuffer-frame}.  Its
734 value should be a frame which does have a minibuffer.
735
736 @ignore Not yet in SXEmacs
737 If you use a minibuffer-only frame, you might want that frame to raise
738 when you enter the minibuffer.  If so, set the variable
739 @code{minibuffer-auto-raise} to @code{t}.  @xref{Raising and Lowering}.
740 @end ignore
741
742 @defvar default-minibuffer-frame
743 This variable specifies the frame to use for the minibuffer window, by
744 default.
745 @end defvar
746
747
748 @node Input Focus
749 @section Input Focus
750 @cindex input focus
751 @cindex selected frame
752
753 At any time, one frame in SXEmacs is the @dfn{selected frame}.  The
754 selected window always resides on the selected frame.  As the focus
755 moves from device to device, the selected frame on each device is
756 remembered and restored when the focus moves back to that device.
757
758 @defun selected-frame &optional device
759 This function returns the selected frame on @var{device}.  If
760 @var{device} is not specified, the selected device will be used.  If no
761 frames exist on the device, @code{nil} is returned.
762 @end defun
763
764 The X server normally directs keyboard input to the X window that the
765 mouse is in.  Some window managers use mouse clicks or keyboard events
766 to @dfn{shift the focus} to various X windows, overriding the normal
767 behavior of the server.
768
769 Lisp programs can switch frames ``temporarily'' by calling
770 the function @code{select-frame}.  This does not override the window
771 manager; rather, it escapes from the window manager's control until
772 that control is somehow reasserted.
773
774 When using a text-only terminal, there is no window manager; therefore,
775 @code{select-frame} is the only way to switch frames, and the effect
776 lasts until overridden by a subsequent call to @code{select-frame}.
777 Only the selected terminal frame is actually displayed on the terminal.
778 Each terminal screen except for the initial one has a number, and the
779 number of the selected frame appears in the mode line after the word
780 @samp{XEmacs} (@pxref{Modeline Variables}).
781 @c hm, btw, why is there `XEmacs' and not `SXEmacs' in the modeline?
782
783 @defun select-frame frame
784 This function selects frame @var{frame}, temporarily disregarding the
785 focus of the X server if any.  The selection of @var{frame} lasts until
786 the next time the user does something to select a different frame, or
787 until the next time this function is called.
788
789 Note that @code{select-frame} does not actually cause the window-system
790 focus to be set to this frame, or the @code{select-frame-hook} or
791 @code{deselect-frame-hook} to be run, until the next time that XEmacs is
792 waiting for an event.
793
794 Also note that when the variable @code{focus-follows-mouse} is
795 non-@code{nil}, the frame selection is temporary and is reverted when
796 the current command terminates, much like the buffer selected by
797 @code{set-buffer}.  In order to effect a permanent focus change use
798 @code{focus-frame}.
799 @end defun
800
801 @defun focus-frame frame
802 This function selects @var{frame} and gives it the window system focus.
803 The operation of @code{focus-frame} is not affected by the value of
804 @code{focus-follows-mouse}.
805 @end defun
806
807 @defspec save-selected-frame forms@dots{}
808 This special form records the selected frame, executes @var{forms} in
809 sequence, then restores the earlier selected frame.  The value returned
810 is the value of the last form.
811 @end defspec
812
813 @defspec with-selected-frame frame forms@dots{}
814 This special form records the selected frame, then selects @var{frame}
815 and executes @var{forms} in sequence.  After the last form is finished,
816 the earlier selected frame is restored.  The value returned is the value
817 of the last form.
818 @end defspec
819
820 @ignore (FSF Emacs, continued from defun select-frame)
821 SXEmacs cooperates with the X server and the window managers by arranging
822 to select frames according to what the server and window manager ask
823 for.  It does so by generating a special kind of input event, called a
824 @dfn{focus} event.  The command loop handles a focus event by calling
825 @code{handle-select-frame}.  @xref{Focus Events}.
826
827 @deffn Command handle-switch-frame frame
828 This function handles a focus event by selecting frame @var{frame}.
829
830 Focus events normally do their job by invoking this command.
831 Don't call it for any other reason.
832 @end deffn
833
834 @defun redirect-frame-focus frame focus-frame
835 This function redirects focus from @var{frame} to @var{focus-frame}.
836 This means that @var{focus-frame} will receive subsequent keystrokes
837 intended for @var{frame}.  After such an event, the value of
838 @code{last-event-frame} will be @var{focus-frame}.  Also, switch-frame
839 events specifying @var{frame} will instead select @var{focus-frame}.
840
841 If @var{focus-frame} is @code{nil}, that cancels any existing
842 redirection for @var{frame}, which therefore once again receives its own
843 events.
844
845 One use of focus redirection is for frames that don't have minibuffers.
846 These frames use minibuffers on other frames.  Activating a minibuffer
847 on another frame redirects focus to that frame.  This puts the focus on
848 the minibuffer's frame, where it belongs, even though the mouse remains
849 in the frame that activated the minibuffer.
850
851 Selecting a frame can also change focus redirections.  Selecting frame
852 @code{bar}, when @code{foo} had been selected, changes any redirections
853 pointing to @code{foo} so that they point to @code{bar} instead.  This
854 allows focus redirection to work properly when the user switches from
855 one frame to another using @code{select-window}.
856
857 This means that a frame whose focus is redirected to itself is treated
858 differently from a frame whose focus is not redirected.
859 @code{select-frame} affects the former but not the latter.
860
861 The redirection lasts until @code{redirect-frame-focus} is called to
862 change it.
863 @end defun
864 @end ignore
865
866
867 @node Visibility of Frames
868 @section Visibility of Frames
869 @cindex visible frame
870 @cindex invisible frame
871 @cindex iconified frame
872 @cindex frame visibility
873
874 An frame on a window system may be @dfn{visible}, @dfn{invisible}, or
875 @dfn{iconified}.  If it is visible, you can see its contents.  If it is
876 iconified, the frame's contents do not appear on the screen, but an icon
877 does.  If the frame is invisible, it doesn't show on the screen, not
878 even as an icon.
879
880 Visibility is meaningless for TTY frames, since only the selected
881 one is actually displayed in any case.
882
883 @defun make-frame-visible &optional frame
884 This function makes frame @var{frame} visible.  If you omit @var{frame},
885 it makes the selected frame visible.
886 @end defun
887
888 @defun make-frame-invisible &optional frame force
889 This function makes frame @var{frame} invisible.
890 @end defun
891
892 @deffn Command iconify-frame &optional frame
893 This function iconifies frame @var{frame}.
894 @end deffn
895
896 @defun Command deiconify-frame &optional frame
897 This function de-iconifies frame @var{frame}.  Under a window system,
898 this is equivalent to @code{make-frame-visible}.
899 @end defun
900
901 @defun frame-visible-p &optional frame
902 This returns whether @var{frame} is currently ``visible'' (actually in
903 use for display).  A frame that is not visible is not updated, and, if
904 it works through a window system, may not show at all.
905 @end defun
906
907 @defun frame-iconified-p &optional frame
908 This returns whether @var{frame} is iconified.  Not all window managers
909 use icons; some merely unmap the window, so this function is not the
910 inverse of @code{frame-visible-p}.  It is possible for a frame to not
911 be visible and not be iconified either.  However, if the frame is
912 iconified, it will not be visible.  (Under FSF Emacs, the functionality
913 of this function is obtained through @code{frame-visible-p}.)
914 @end defun
915
916 @defun frame-totally-visible-p &optional frame
917 This returns whether @var{frame} is not obscured by any other X
918 windows.  On TTY frames, this is the same as @code{frame-visible-p}.
919 @end defun
920
921 @ignore  @c Not in SXEmacs.
922   The visibility status of a frame is also available as a frame
923 property.  You can read or change it as such.  @xref{X Frame
924 Properties}.
925
926 The user can iconify and deiconify frames with the window manager.  This
927 happens below the level at which SXEmacs can exert any control, but SXEmacs
928 does provide events that you can use to keep track of such changes.
929 @xref{Misc Events}.
930 @end ignore
931
932
933 @node Raising and Lowering
934 @section Raising and Lowering Frames
935
936 The X Window System uses a desktop metaphor.  Part of this metaphor is
937 the idea that windows are stacked in a notional third dimension
938 perpendicular to the screen surface, and thus ordered from ``highest''
939 to ``lowest''.  Where two windows overlap, the one higher up covers the
940 one underneath.  Even a window at the bottom of the stack can be seen if
941 no other window overlaps it.
942
943 @cindex raising a frame
944 @cindex lowering a frame
945 A window's place in this ordering is not fixed; in fact, users tend to
946 change the order frequently.  @dfn{Raising} a window means moving it
947 ``up'', to the top of the stack.  @dfn{Lowering} a window means moving
948 it to the bottom of the stack.  This motion is in the notional third
949 dimension only, and does not change the position of the window on the
950 screen.
951
952 You can raise and lower SXEmacs's X windows with these functions:
953
954 @deffn Command raise-frame &optional frame
955 This function raises frame @var{frame}.
956 @end deffn
957
958 @deffn Command lower-frame &optional frame
959 This function lowers frame @var{frame}.
960 @end deffn
961
962 You can also specify auto-raise (raising automatically when a frame is
963 selected) or auto-lower (lowering automatically when it is deselected).
964 Under X, most ICCCM-compliant window managers will have an option to do
965 this for you, but the following variables are provided in case you're
966 using a broken WM.
967
968 Note: Under FSF Emacs, the same functionality is provided through the
969 @code{auto-raise} and @code{auto-lower} frame properties.
970
971 @defvar auto-raise-frame
972 This variable's value is @code{t} if frames will be raised to the top
973 when selected.
974 @end defvar
975
976 @ignore Not in SXEmacs
977 @defopt minibuffer-auto-raise
978 If this is non-@code{nil}, activation of the minibuffer raises the frame
979 that the minibuffer window is in.
980 @end defopt
981 @end ignore
982
983 @defvar auto-lower-frame
984 This variable's value is @code{t} if frames will be lowered to the bottom
985 when no longer selected.
986 @end defvar
987
988 Auto-raising and auto-lowering is implemented through functions attached
989 to @code{select-frame-hook} and @code{deselect-frame-hook}
990 (@pxref{Frame Hooks}).  Under normal circumstances, you should not call
991 these functions directly.
992
993 @defun default-select-frame-hook
994 This hook function implements the @code{auto-raise-frame} variable; it is
995 for use as the value of @code{select-frame-hook}.
996 @end defun
997
998 @defun default-deselect-frame-hook
999 This hook function implements the @code{auto-lower-frame} variable; it is
1000 for use as the value of @code{deselect-frame-hook}.
1001 @end defun
1002
1003
1004 @node Frame Configurations
1005 @section Frame Configurations
1006 @cindex frame configuration
1007
1008   A @dfn{frame configuration} records the current arrangement of frames,
1009 all their properties, and the window configuration of each one.
1010
1011 @defun current-frame-configuration
1012 This function returns a frame configuration list that describes
1013 the current arrangement of frames and their contents.
1014 @end defun
1015
1016 @defun set-frame-configuration configuration &optional nodelete
1017 This function restores the state of frames described by
1018 @var{configuration}, which should be the return value from a previous
1019 call to @code{current-frame-configuration}.
1020
1021 Each frame listed in @var{configuration} has its position, size, window
1022 configuration, and other properties set as specified in
1023 @var{configuration}.
1024
1025 Ordinarily, this function deletes all existing frames not listed in
1026 @var{configuration}.  But if optional second argument @var{nodelete} is
1027 non-@code{nil}, the unwanted frames are iconified instead.
1028 @end defun
1029
1030
1031 @node Frame Hooks
1032 @section Hooks for Customizing Frame Behavior
1033 @cindex frame hooks
1034
1035 SXEmacs provides many hooks that are called at various times during a
1036 frame's lifetime.  @xref{Hooks}.
1037
1038 @defvar create-frame-hook
1039 This hook is called each time a frame is created.  The functions are called
1040 with one argument, the newly-created frame.
1041 @end defvar
1042
1043 @defvar delete-frame-hook
1044 This hook is called each time a frame is deleted.  The functions are called
1045 with one argument, the about-to-be-deleted frame.
1046 @end defvar
1047
1048 @defvar select-frame-hook
1049 This is a normal hook that is run just after a frame is selected.  The
1050 function @code{default-select-frame-hook}, which implements auto-raising
1051 (@pxref{Raising and Lowering}), is normally attached to this hook.
1052
1053 Note that calling @code{select-frame} does not necessarily set the
1054 focus: The actual window-system focus will not be changed until the next
1055 time that SXEmacs is waiting for an event, and even then, the window
1056 manager may refuse the focus-change request.
1057 @end defvar
1058
1059 @defvar deselect-frame-hook
1060 This is a normal hook that is run just before a frame is deselected
1061 (and another frame is selected).  The function
1062 @code{default-deselect-frame-hook}, which implements auto-lowering
1063 (@pxref{Raising and Lowering}), is normally attached to this hook.
1064 @end defvar
1065
1066 @defvar map-frame-hook
1067 This hook is called each time a frame is mapped (i.e. made visible).
1068 The functions are called with one argument, the newly mapped frame.
1069 @end defvar
1070
1071 @defvar unmap-frame-hook
1072 This hook is called each time a frame is unmapped (i.e. made invisible
1073 or iconified).  The functions are called with one argument, the
1074 newly unmapped frame.
1075 @end defvar