(te-pass-through): Don't presume internal bit layout of non-ASCII keys.
[emacs.git] / lispref / frames.texi
blob9511319c1bd24b9c84f0e342233ad16218e24897
1 @c -*-texinfo-*-
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
7 @chapter Frames
8 @cindex frame
10   A @var{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 has just one frame, a
18 @dfn{terminal frame}.  There is no way to create another terminal frame
19 after startup.  If Emacs has an X display, it does not have a terminal
20 frame; instead, it starts with a single @dfn{X window frame}.  You can
21 create more; see @ref{Creating Frames}.
23 @defun framep object
24 This predicate returns @code{t} if @var{object} is a frame, and
25 @code{nil} otherwise.
26 @end defun
28 @menu
29 * Creating Frames::             Creating additional X Window frames.
30 * Frame Parameters::            Controlling frame size, position, font, etc.
31 * Deleting Frames::             Frames last until explicitly deleted.
32 * Finding All Frames::          How to examine all existing frames.
33 * Frames and Windows::          A frame contains windows;
34                                   display of text always works through windows.
35 * Minibuffers and Frames::      How a frame finds the minibuffer to use.
36 * Input Focus::                 Specifying the selected frame.
37 * Visibility of Frames::        Frames may be visible or invisible, or icons.
38 * Raising and Lowering::        Raising a frame makes it hide other X windows;
39                                   lowering it makes the others hide them.
40 * Frame Configurations::        Saving the state of all frames.
41 * Mouse Tracking::              Getting events that say when the mouse moves.
42 * Mouse Position::              Asking where the mouse is, or moving it.
43 * Pop-Up Menus::                Displaying a menu for the user to select from.
44 * Dialog Boxes::                Displaying a box to ask yes or no.
45 * Pointer Shapes::              Specifying the shape of the mouse pointer.
46 * X Selections::                Transferring text to and from other X clients.
47 * X Connections::               Opening and closing the X server connection.
48 * Resources::                   Getting resource values from the server.
49 * Server Data::                 Getting info about the X server.
50 @end menu
52   @xref{Display}, for related information.
54 @node Creating Frames
55 @section Creating Frames
57 To create a new frame, call the function @code{make-frame}.
59 @defun make-frame alist
60 This function creates a new frame, if the display mechanism permits
61 creation of frames.  (An X server does; an ordinary terminal does not.)
63 The argument is an alist specifying frame parameters.  Any parameters
64 not mentioned in @var{alist} default according to the value of the
65 variable @code{default-frame-alist}; parameters not specified there
66 either default from the standard X defaults file and X resources.
68 The set of possible parameters depends in principle on what kind of
69 window system Emacs uses to display its frames.  @xref{X Frame
70 Parameters}, for documentation of individual parameters you can specify
71 when creating an X window frame.
72 @end defun
74 @defvar before-make-frame-hook
75 A normal hook run by @code{make-frame} before it actually creates the
76 frame.
77 @end defvar
79 @defvar after-make-frame-hook
80 A normal hook run by @code{make-frame} after it creates the frame.
81 @end defvar
83 @node Frame Parameters
84 @section Frame Parameters
86 A frame has many parameters that control its appearance and behavior.
87 Just what parameters a frame has depends on what display mechanism it
88 uses.
90 Frame parameters exist for the sake of window systems.  A terminal frame
91 has a few parameters, for compatibility's sake only.  You can't change
92 these parameters directly; the only ones that ever change are the height
93 and width.
95 @menu
96 * Parameter Access::       How to change a frame's parameters.
97 * Initial Parameters::     Specifying frame parameters when you make a frame.
98 * X Frame Parameters::     Individual parameters documented.
99 * Size and Position::      Changing the size and position of a frame.
100 @end menu
102 @node Parameter Access
103 @subsection Access to Frame Parameters
105 These functions let you read and change the parameter values of a
106 frame.
108 @defun frame-parameters frame
109 The function @code{frame-parameters} returns an alist listing all the
110 parameters of @var{frame} and their values.
111 @end defun
113 @defun modify-frame-parameters frame alist
114 This function alters the parameters of frame @var{frame} based on the
115 elements of @var{alist}.  Each element of @var{alist} has the form
116 @code{(@var{parm} . @var{value})}, where @var{parm} is a symbol naming a
117 parameter.  If you don't mention a parameter in @var{alist}, its value
118 doesn't change.
119 @end defun
121 @node Initial Parameters
122 @subsection Initial Frame Parameters
124 You can specify the parameters for the initial startup frame
125 by setting @code{initial-frame-alist} in your @file{.emacs} file.
127 @defvar initial-frame-alist
128 This variable's value is an alist of parameter values used when creating
129 the initial X window frame.  Each element has the form:
131 @example
132 (@var{parameter} . @var{value})
133 @end example
135 Emacs creates the initial frame before it reads your @file{~/.emacs}
136 file.  After reading that file, Emacs checks @code{initial-frame-alist},
137 and applies the parameter settings in the altered value to the already
138 created initial frame.
140 If these settings affect the frame geometry, you'll see the frame appear
141 with the wrong geometry and then change to the specified one.  If you
142 like, you can specify the same geometry with X resources; those do take
143 affect before the frame is created.  @xref{Resources X,, X Resources,
144 emacs, The GNU Emacs Manual}.
146 X resource settings typically apply to all frames.  If you want to
147 specify some X resources solely for the sake of the initial frame, and
148 you don't want them to apply to subsequent frames, here's how to achieve
149 this.  Specify parameters in @code{default-frame-alist} to override the
150 X resources for subsequent frames; then, to prevent these from affecting
151 the initial frame, specify the same parameters in
152 @code{initial-frame-alist} with values that match the X resources.
153 @end defvar
155 If these parameters specify a separate minibuffer-only frame,
156 and you have not created one, Emacs creates one for you.
158 @defvar minibuffer-frame-alist
159 This variable's value is an alist of parameter values used when creating
160 an initial minibuffer-only frame---if such a frame is needed, according
161 to the parameters for the main initial frame.
162 @end defvar
164 @defvar special-display-frame-alist
165 The variable @code{special-display-frame-alist} specifies the frame
166 parameters for special display frames.
167 @end defvar
169 @defvar default-frame-alist
170 This is an alist specifying default values of frame parameters for
171 subsequent Emacs frames (not the initial ones).
172 @end defvar
174 If you use options that specify window appearance when you invoke Emacs,
175 they take effect by adding elements to @code{default-frame-alist}.  One
176 exception is @samp{-geometry}, which adds to @code{initial-frame-alist}
177 instead.  @xref{Command Arguments,,, emacs, The GNU Emacs Manual}.
179 @node X Frame Parameters
180 @subsection X Window Frame Parameters
182 Just what parameters a frame has depends on what display mechanism it
183 uses.  Here is a table of the parameters of an X window frame:
185 @table @code
186 @item name
187 The name of the frame.  Most window managers display the frame's name in
188 the frame's border, at the top of the frame.  If you don't specify a
189 name, and you have more than one frame, Emacs sets the frame name based
190 on the buffer displayed in the frame's selected window.
192 If you specify the frame name explicitly when you create the frame, the
193 name is also used (instead of the name of the Emacs executable) when
194 looking up X resources for the frame.
196 @item left
197 The screen position of the left edge, in pixels.  The value may be
198 @code{-} instead of a number; that represents @samp{-0} in a geometry
199 specification.
201 @item top
202 The screen position of the top edge, in pixels.  The value may be
203 @code{-} instead of a number; that represents @samp{-0} in a geometry
204 specification.
206 @item icon-left
207 The screen position of the left edge @emph{of the frame's icon}, in
208 pixels, counting from the left edge of the screen.  This takes effect if
209 and when the frame is iconified.
211 @item icon-top
212 The screen position of the top edge @emph{of the frame's icon}, in
213 pixels, counting from the top edge of the screen.  This takes effect if
214 and when the frame is iconified.
216 @item user-position
217 Non-@code{nil} if the screen position of the frame was explicitly
218 requested by the user (for example, with the @samp{-geometry} option).
219 Nothing automatically makes this parameter non-@code{nil}; it is up to
220 Lisp programs that call @code{make-frame} to specify this parameter as
221 well as specifying the @code{left} and @code{top} parameters.
223 @item height
224 The height of the frame contents, in characters.  (To get the height in
225 pixels, call @code{frame-pixel-height}; see @ref{Size and Position}.)
227 @item width
228 The width of the frame contents, in characters.  (To get the height in
229 pixels, call @code{frame-pixel-width}; see @ref{Size and Position}.)
231 @item window-id
232 The number of the X window for the frame.
234 @item minibuffer
235 Whether this frame has its own minibuffer.  The value @code{t} means
236 yes, @code{nil} means no, @code{only} means this frame is just a
237 minibuffer, a minibuffer window (in some other frame) means the new
238 frame uses that minibuffer.
240 @item font
241 The name of the font for displaying text in the frame.  This is a
242 string.
244 @item auto-raise
245 Whether selecting the frame raises it (non-@code{nil} means yes).
247 @item auto-lower
248 Whether deselecting the frame lowers it (non-@code{nil} means yes).
250 @item vertical-scroll-bars
251 Whether the frame has scroll bars for vertical scrolling
252 (non-@code{nil} means yes).
254 @item horizontal-scroll-bars
255 Whether the frame has scroll bars for horizontal scrolling
256 (non-@code{nil} means yes).  (Horizontal scroll bars are not currently
257 implemented.)
259 @item icon-type
260 The type of icon to use for this frame when it is iconified.
261 Non-@code{nil} specifies a bitmap icon, @code{nil} a text icon.
263 @item foreground-color
264 The color to use for the image of a character.  This is a string; the X
265 server defines the meaningful color names.
267 @item background-color
268 The color to use for the background of characters.
270 @item mouse-color
271 The color for the mouse pointer.
273 @item cursor-color
274 The color for the cursor that shows point.
276 @item border-color
277 The color for the border of the frame.
279 @item cursor-type
280 The way to display the cursor.  There are two legitimate values:
281 @code{bar} and @code{box}.  The symbol @code{bar} specifies a vertical
282 bar between characters as the cursor.  The symbol @code{box} specifies
283 an ordinary black box overlaying the character after point; that is the
284 default.
286 @item border-width
287 The width in pixels of the window border.
289 @item internal-border-width
290 The distance in pixels between text and border.
292 @item unsplittable
293 If non-@code{nil}, this frame's window is never split automatically.
295 @item visibility
296 The state of visibility of the frame.  There are three possibilities:
297 @code{nil} for invisible, @code{t} for visible, and @code{icon} for
298 iconified.  @xref{Visibility of Frames}.
300 @item menu-bar-lines
301 The number of lines to allocate at the top of the frame for a menu bar.
302 The default is 1.  @xref{Menu Bar}.  (In Emacs versions that use the X
303 toolkit, there is only one menu bar line; all that matters about the
304 number you specify is whether it is greater than zero.)
306 @item parent-id
307 @c ??? Not yet working.
308 The X window number of the window that should be the parent of this one.
309 Specifying this lets you create an Emacs window inside some other
310 application's window.  (It is not certain this will be implemented; try
311 it and see if it works.)
312 @end table
314 @node Size and Position
315 @subsection Frame Size And Position
317   You can read or change the size and position of a frame using the
318 frame parameters @code{left}, @code{top}, @code{height}, and
319 @code{width}.  Whatever geometry parameters you don't specify are chosen
320 by the window manager in its usual fashion.
322   Here are some special features for working with sizes and positions:
324 @defun set-frame-position frame left top
325 This function sets the position of the top left corner of
326 @var{frame} to @var{left} and @var{top}.  These arguments are measured
327 in pixels, counting from the top left corner of the screen.
328 @end defun
330 @defun frame-height &optional frame
331 @defunx frame-width &optional frame
332 These functions return the height and width of @var{frame}, measured in
333 characters.  If you don't supply @var{frame}, they use the selected
334 frame.
335 @end defun
337 @defun frame-pixel-height &optional frame
338 @defunx frame-pixel-width &optional frame
339 These functions return the height and width of @var{frame}, measured in
340 pixels.  If you don't supply @var{frame}, they use the selected frame.
341 @end defun
343 @defun frame-char-height &optional frame
344 @defunx frame-char-width &optional frame
345 These functions return the height and width of a character in
346 @var{frame}, measured in pixels.  The values depend on the choice of
347 font.  If you don't supply @var{frame}, these functions use the selected
348 frame.
349 @end defun
351 @defun set-frame-size frame cols rows
352 This function sets the size of @var{frame}, measured in characters;
353 @var{cols} and @var{rows} specify the new width and height.
355 To set the size based on values measured in pixels, use
356 @code{frame-char-height} and @code{frame-char-width} to convert
357 them to units of characters.
358 @end defun
360   The old-fashioned functions @code{set-screen-height} and
361 @code{set-screen-width}, which were used to specify the height and width
362 of the screen in Emacs versions that did not support multiple frames,
363 are still usable.  They apply to the selected frame.  @xref{Screen
364 Size}.
366 @defun x-parse-geometry geom
367 @cindex geometry specification
368 The function @code{x-parse-geometry} converts a standard X windows
369 geometry string to an alist that you can use as part of the argument to
370 @code{make-frame}.
372 The alist describes which parameters were specified in @var{geom}, and
373 gives the values specified for them.  Each element looks like
374 @code{(@var{parameter} . @var{value})}.  The possible @var{parameter}
375 values are @code{left}, @code{top}, @code{width}, and @code{height}.
377 @smallexample
378 (x-parse-geometry "35x70+0-0")
379      @result{} ((width . 35) (height . 70) (left . 0) (top . -1))
380 @end smallexample
381 @end defun
383 @ignore
384 New functions @code{set-frame-height} and @code{set-frame-width} set the
385 size of a specified frame.  The frame is the first argument; the size is
386 the second.
387 @end ignore
389 @node Deleting Frames
390 @section Deleting Frames
391 @cindex deletion of frames
393 Frames remain potentially visible until you explicitly @dfn{delete}
394 them.  A deleted frame cannot appear on the screen, but continues to
395 exist as a Lisp object until there are no references to it.  There is no
396 way to cancel the deletion of a frame aside from restoring a saved frame
397 configuration (@pxref{Frame Configurations}); this is similar to the
398 way windows behave.
400 @deffn Command delete-frame &optional frame
401 This function deletes the frame @var{frame}.  By default, @var{frame} is
402 the selected frame.
403 @end deffn
405 @defun frame-live-p frame
406 The function @code{frame-live-p} returns non-@code{nil} if the frame
407 @var{frame} has not been deleted.
408 @end defun
410 @node Finding All Frames
411 @section Finding All Frames
413 @defun frame-list
414 The function @code{frame-list} returns a list of all the frames that
415 have not been deleted.  It is analogous to @code{buffer-list} for
416 buffers.  The list that you get is newly created, so modifying the list
417 doesn't have any effect on the internals of Emacs.
418 @end defun
420 @defun visible-frame-list
421 This function returns a list of just the currently visible frames.
422 @xref{Visibility of Frames}.
423 @end defun
425 @defun next-frame &optional frame minibuf
426 The function @code{next-frame} lets you cycle conveniently through all
427 the frames from an arbitrary starting point.  It returns the ``next''
428 frame after @var{frame} in the cycle.  If @var{frame} is omitted or
429 @code{nil}, it defaults to the selected frame.
431 The second argument, @var{minibuf}, says which frames to consider:
433 @table @asis
434 @item @code{nil}
435 Exclude minibuffer-only frames.
436 @item @code{visible}
437 Consider all visible frames.
438 @item a window
439 Consider only the frames using that particular window as their
440 minibuffer.
441 @item anything else
442 Consider all frames.
443 @end table
444 @end defun
446 @defun previous-frame &optional frame minibuf
447 Like @code{next-frame}, but cycles through all frames in the opposite
448 direction.
449 @end defun
451 @node Frames and Windows
452 @section Frames and Windows
454   Each window is part of one and only one frame; you can get the frame
455 with @code{window-frame}.
457 @defun window-frame window
458 This function returns the frame that @var{window} is on.
459 @end defun
461   All the non-minibuffer windows in a frame are arranged in a cyclic
462 order.  The order runs from the frame's top window, which is at the
463 upper left corner, down and to the right, until it reaches the window at
464 the lower right corner (always the minibuffer window, if the frame has
465 one), and then it moves back to the top.
467 @defun frame-top-window frame
468 This returns the topmost, leftmost window of frame @var{frame}.
469 @end defun
471 At any time, exactly one window on any frame is @dfn{selected within the
472 frame}.  The significance of this designation is that selecting the
473 frame also selects this window.  You can get the frame's current
474 selected window with @code{frame-selected-window}.
476 @defun frame-selected-window frame
477 This function returns the window on @var{frame} that is selected within
478 @var{frame}.
479 @end defun
481 Conversely, selecting a window for Emacs with @code{select-window} also
482 makes that window selected within its frame.  @xref{Selecting Windows}.
484 @node Minibuffers and Frames
485 @section Minibuffers and Frames
487 Normally, each frame has its own minibuffer window at the bottom, which
488 is used whenever that frame is selected.  If the frame has a minibuffer,
489 you can get it with @code{minibuffer-window} (@pxref{Minibuffer Misc}).
491 However, you can also create a frame with no minibuffer.  Such a frame
492 must use the minibuffer window of some other frame.  When you create the
493 frame, you can specify explicitly the frame on which to find the
494 minibuffer to use.  If you don't, then the minibuffer is found in the
495 frame which is the value of the variable
496 @code{default-minibuffer-frame}.  Its value should be a frame that does
497 have a minibuffer.
499 If you use a minibuffer-only frame, you might want that frame to raise
500 when you enter the minibuffer.  If so, set the variable
501 @code{minibuffer-auto-raise} to @code{t}.  @xref{Raising and Lowering}.
503 @node Input Focus
504 @section Input Focus
505 @cindex input focus
506 @cindex selected frame
508 At any time, one frame in Emacs is the @dfn{selected frame}.  The selected
509 window always resides on the selected frame.
511 @defun selected-frame
512 This function returns the selected frame.
513 @end defun
515 The X server normally directs keyboard input to the X window that the
516 mouse is in.  Some window managers use mouse clicks or keyboard events
517 to @dfn{shift the focus} to various X windows, overriding the normal
518 behavior of the server.
520 Lisp programs can switch frames ``temporarily'' by calling
521 the function @code{select-frame}.  This does not override the window
522 manager; rather, it escapes from the window manager's control until
523 that control is somehow reasserted.
525 @c ??? This is not yet implemented properly.
526 @defun select-frame frame
527 This function selects frame @var{frame}, temporarily disregarding the
528 focus of the X server.  The selection of @var{frame} lasts until the
529 next time the user does something to select a different frame, or until
530 the next time this function is called.
531 @end defun
533 Emacs cooperates with the X server and the window managers by arranging
534 to select frames according to what the server and window manager ask
535 for.  It does so by generating a special kind of input event, called a
536 @dfn{focus} event.  The command loop handles a focus event by calling
537 @code{handle-select-frame}.  @xref{Focus Events}.
539 @deffn Command handle-switch-frame frame
540 This function handles a focus event by selecting frame @var{frame}.
542 Focus events normally do their job by invoking this command.
543 Don't call it for any other reason.
544 @end deffn
546 @defun redirect-frame-focus frame focus-frame
547 This function redirects focus from @var{frame} to @var{focus-frame}.
548 This means that @var{focus-frame} will receive subsequent keystrokes
549 intended for @var{frame}.  After such an event, the value of
550 @code{last-event-frame} will be @var{focus-frame}.  Also, switch-frame
551 events specifying @var{frame} will instead select @var{focus-frame}.
553 If @var{focus-frame} is @code{nil}, that cancels any existing
554 redirection for @var{frame}, which therefore once again receives its own
555 events.
557 One use of focus redirection is for frames that don't have minibuffers.
558 These frames use minibuffers on other frames.  Activating a minibuffer
559 on another frame redirects focus to that frame.  This puts the focus on
560 the minibuffer's frame, where it belongs, even though the mouse remains
561 in the frame that activated the minibuffer.
563 Selecting a frame can also change focus redirections.  Selecting frame
564 @code{bar}, when @code{foo} had been selected, changes any redirections
565 pointing to @code{foo} so that they point to @code{bar} instead.  This
566 allows focus redirection to work properly when the user switches from
567 one frame to another using @code{select-window}.
569 This means that a frame whose focus is redirected to itself is treated
570 differently from a frame whose focus is not redirected.
571 @code{select-frame} affects the former but not the latter.
573 The redirection lasts until @code{redirect-frame-focus} is called to
574 change it.
575 @end defun
577 @node Visibility of Frames
578 @section Visibility of Frames
579 @cindex visible frame
580 @cindex invisible frame
581 @cindex iconified frame
582 @cindex frame visibility
584 A frame may be @dfn{visible}, @dfn{invisible}, or @dfn{iconified}.  If
585 it is visible, you can see its contents.  If it is iconified, the
586 frame's contents do not appear on the screen, but an icon does.  If the
587 frame is invisible, it doesn't show on the screen, not even as an icon.
589 @deffn Command make-frame-visible &optional frame
590 This function makes frame @var{frame} visible.  If you omit @var{frame},
591 it makes the selected frame visible.
592 @end deffn
594 @deffn Command make-frame-invisible &optional frame
595 This function makes frame @var{frame} invisible.  If you omit
596 @var{frame}, it makes the selected frame invisible.
597 @end deffn
599 @deffn Command iconify-frame &optional frame
600 This function iconifies frame @var{frame}.  If you omit @var{frame}, it
601 iconifies the selected frame.
602 @end deffn
604 @defun frame-visible-p frame
605 This returns the visibility status of frame @var{frame}.  The value is
606 @code{t} if @var{frame} is visible, @code{nil} if it is invisible, and
607 @code{icon} if it is iconified.
608 @end defun
610   The visibility status of a frame is also available as a frame
611 parameter.  You can read or change it as such.  @xref{X Frame
612 Parameters}.
614 @node Raising and Lowering
615 @section Raising and Lowering Frames
617 The X Window System uses a desktop metaphor.  Part of this metaphor is
618 the idea that windows are stacked in a notional third dimension
619 perpendicular to the screen surface, and thus ordered from ``highest''
620 to ``lowest''.  Where two windows overlap, the one higher up covers the
621 one underneath.  Even a window at the bottom of the stack can be seen if
622 no other window overlaps it.
624 @cindex raising a frame
625 @cindex lowering a frame
626 A window's place in this ordering is not fixed; in fact, users tend to
627 change the order frequently.  @dfn{Raising} a window means moving it
628 ``up'', to the top of the stack.  @dfn{Lowering} a window means moving
629 it to the bottom of the stack.  This motion is in the notional third
630 dimension only, and does not change the position of the window on the
631 screen.
633 You can raise and lower Emacs's X windows with these functions:
635 @defun raise-frame frame
636 This function raises frame @var{frame}.
637 @end defun
639 @defun lower-frame frame
640 This function lowers frame @var{frame}.
641 @end defun
643 @defopt minibuffer-auto-raise
644 If this is non-@code{nil}, activation of the minibuffer raises the frame
645 that the minibuffer window is in.
646 @end defopt
648 You can also enable auto-raise (raising automatically when a frame is
649 selected) or auto-lower (lowering automatically when it is deselected)
650 for any frame using frame parameters.  @xref{X Frame Parameters}.
652 @node Frame Configurations
653 @section Frame Configurations
654 @cindex frame configuration
656   A @dfn{frame configuration} records the current arrangement of frames,
657 all their properties, and the window configuration of each one.
659 @defun current-frame-configuration
660 This function returns a frame configuration list that describes
661 the current arrangement of frames and their contents.
662 @end defun
664 @defun set-frame-configuration configuration
665 This function restores the state of frames described in
666 @var{configuration}.
667 @end defun
669 @node Mouse Tracking
670 @section Mouse Tracking
671 @cindex mouse tracking
672 @cindex tracking the mouse
674 Sometimes it is useful to @dfn{track} the mouse, which means to display
675 something to indicate where the mouse is and move the indicator as the
676 mouse moves.  For efficient mouse tracking, you need a way to wait until
677 the mouse actually moves.
679 The convenient way to track the mouse is to ask for events to represent
680 mouse motion.  Then you can wait for motion by waiting for an event.  In
681 addition, you can easily handle any other sorts of events that may
682 occur.  That is useful, because normally you don't want to track the
683 mouse forever---only until some other event, such as the release of a
684 button.
686 @defspec track-mouse body@dots{}
687 Execute @var{body}, meanwhile generating input events for mouse motion.
688 The code in @var{body} can read these events with @code{read-event} or
689 @code{read-key-sequence}.  @xref{Motion Events}, for the format of mouse
690 motion events.
692 The value of @code{track-mouse} is that of the last form in @var{body}.
693 @end defspec
695 The usual purpose of tracking mouse motion is to indicate on the screen
696 the consequences of pushing or releasing a button at the current
697 position.
699 @ignore
700 @c These are not implemented yet.
702 These functions change the screen appearance instantaneously.  The
703 effect is transient, only until the next ordinary Emacs redisplay.  That
704 is ok for mouse tracking, since it doesn't make sense for mouse tracking
705 to change the text, and the body of @code{track-mouse} normally reads
706 the events itself and does not do redisplay.
708 @defun x-contour-region window beg end
709 This function draws lines to make a box around the text from @var{beg}
710 to @var{end}, in window @var{window}.
711 @end defun
713 @defun x-uncontour-region window beg end
714 This function erases the lines that would make a box around the text
715 from @var{beg} to @var{end}, in window @var{window}.  Use it to remove
716 a contour that you previously made by calling @code{x-contour-region}.
717 @end defun
719 @defun x-draw-rectangle frame left top right bottom
720 This function draws a hollow rectangle on frame @var{frame} with the
721 specified edge coordinates, all measured in pixels from the inside top
722 left corner.  It uses the cursor color, the one used for indicating the
723 location of point.
724 @end defun
726 @defun x-erase-rectangle frame left top right bottom
727 This function erases a hollow rectangle on frame @var{frame} with the
728 specified edge coordinates, all measured in pixels from the inside top
729 left corner.  Erasure means redrawing the text and background that
730 normally belong in the specified rectangle.
731 @end defun
732 @end ignore
734 @node Mouse Position
735 @section Mouse Position
736 @cindex mouse position
737 @cindex position of mouse
739   The functions @code{mouse-position} and @code{set-mouse-position}
740 give access to the current position of the mouse.
742 @defun mouse-position
743 This function returns a description of the position of the mouse.  The
744 value looks like @code{(@var{frame} @var{x} . @var{y})}, where @var{x}
745 and @var{y} are integers giving the position in characters relative to
746 the top left corner of the inside of @var{frame}.
747 @end defun
749 @defun set-mouse-position frame x y
750 This function @dfn{warps the mouse} to position @var{x}, @var{y} in
751 frame @var{frame}.  The arguments @var{x} and @var{y} are integers,
752 giving the position in characters relative to the top left corner of the
753 inside of @var{frame}.
754 @end defun
756 @defun mouse-pixel-position
757 This function is like @code{mouse-position} except that it returns
758 coordinates in units of pixels rather than units of characters.
759 @end defun
761 @defun set-mouse-pixel-position frame x y
762 This function warps the mouse like @code{set-mouse-position} except that
763 @var{x} and @var{y} are in units of pixels rather than units of
764 characters.  These coordinates are not required to be within the frame.
765 @end defun
767 @need 3000
769 @node Pop-Up Menus
770 @section Pop-Up Menus
772 @defun x-popup-menu position menu
773 This function displays a pop-up menu and returns an indication of
774 what selection the user makes.
776 The argument @var{position} specifies where on the screen to put the
777 menu.  It can be either a mouse button event (which says to put the menu
778 where the user actuated the button) or a list of this form:
780 @example
781 ((@var{xoffset} @var{yoffset}) @var{window})
782 @end example
784 @noindent
785 where @var{xoffset} and @var{yoffset} are coordinates, measured in
786 pixels, counting from the top left corner of @var{window}'s frame.
788 If @var{position} is @code{t}, it means to use the current mouse
789 position.  If @var{position} is @code{nil}, it means to precompute the
790 key binding equivalents for the keymaps specified in @var{menu},
791 without actually displaying or popping up the menu.
793 The argument @var{menu} says what to display in the menu.  It can be a
794 keymap or a list of keymaps (@pxref{Menu Keymaps}).  Alternatively, it
795 can have the following form:
797 @example
798 (@var{title} @var{pane1} @var{pane2}...)
799 @end example
801 @noindent
802 where each pane is a list of form
804 @example
805 (@var{title} (@var{line} @var{item})...)
806 @end example
808 Each @var{line} should be a string, and each @var{item} should be the
809 value to return if that @var{line} is chosen.
810 @end defun
812 @strong{Usage note:} Don't use @code{x-popup-menu} to display a menu if
813 a prefix key with a menu keymap would do the job.  If you use a menu
814 keymap to implement a menu, @kbd{C-h c} and @kbd{C-h a} can see the
815 individual items in that menu and provide help for them.  If instead you
816 implement the menu by defining a command that calls @code{x-popup-menu},
817 the help facilities cannot know what happens inside that command, so
818 they cannot give any help for the menu's items.  This is the reason why
819 all the menu bar items except @samp{Buffers} are implemented with menu
820 keymaps (@pxref{Menu Keymaps}).
822 @node Dialog Boxes
823 @section Dialog Boxes
824 @cindex dialog boxes
826   A dialog box is a variant of a pop-up menu.  It looks a little
827 different (if Emacs uses an X toolkit), it always appears in the center
828 of a frame, and it has just one level and one pane.  The main use of
829 dialog boxes is for asking questions that the user can answer with
830 ``yes'', ``no'', and a few other alternatives.  The functions
831 @code{y-or-n-p} and @code{yes-or-no-p} use dialog boxes instead of the
832 keyboard, when called from commands invoked by mouse clicks.
834 @defun x-popup-dialog position contents
835 This function displays a pop-up dialog box and returns an indication of
836 what selection the user makes.  The argument @var{contents} specifies
837 the alternatives to offer; it has this format:
839 @example
840 (@var{title} (@var{string} . @var{value})@dots{})
841 @end example
843 @noindent
844 which looks like the list that specifies a single pane for
845 @code{x-popup-menu}.
847 The return value is @var{value} from the chosen alternative.
849 An element of the list may be just a string instead of a cons cell
850 @code{(@var{string} . @var{value})}.  That makes a box that cannot
851 be selected.
853 If @code{nil} appears in the list, it separates the left-hand items from
854 the right-hand items; items that precede the @code{nil} appear on the
855 left, and items that follow the @code{nil} appear on the right.  If you
856 don't include a @code{nil} in the list, then approximately half the
857 items appear on each side.
859 Dialog boxes always appear in the center of a frame; the argument
860 @var{position} specifies which frame.  The possible values are as in
861 @code{x-popup-menu}, but the precise coordinates don't matter; only the
862 frame matters.
864 If your Emacs executable does not use an X toolkit, then it cannot
865 display a real dialog box; so instead it displays the same items in a
866 pop-up menu in the center of the frame.
867 @end defun
869 @node Pointer Shapes
870 @section Pointer Shapes
871 @cindex pointer shape
872 @cindex mouse pointer shape
874   These variables specify which mouse pointer shape to use in various
875 situations:
877 @table @code
878 @item x-pointer-shape
879 @vindex x-pointer-shape
880 This variable specifies the pointer shape to use ordinarily in the Emacs
881 frame.
883 @item x-sensitive-text-pointer-shape
884 @vindex x-sensitive-text-pointer-shape
885 This variable specifies the pointer shape to use when the mouse
886 is over mouse-sensitive text.
887 @end table
889   These variables affect newly created frames.  They do not normally
890 affect existing frames; however, if you set the mouse color of a frame,
891 that also updates its pointer shapes based on the current values of
892 these variables.  @xref{X Frame Parameters}.
894   The values you can use, to specify either of these pointer shapes, are
895 defined in the file @file{lisp/x-win.el}.  Use @kbd{M-x apropos
896 @key{RET} x-pointer @key{RET}} to see a list of them.
898 @node X Selections
899 @section X Selections
900 @cindex selection (for X windows)
902 The X server records a set of @dfn{selections} which permit transfer of
903 data between application programs.  The various selections are
904 distinguished by @dfn{selection types}, represented in Emacs by
905 symbols.  X clients including Emacs can read or set the selection for
906 any given type.
908 @defun x-set-selection type data
909 This function sets a ``selection'' in the X server.  It takes two
910 arguments: a selection type @var{type}, and the value to assign to it,
911 @var{data}.  If @var{data} is @code{nil}, it means to clear out the
912 selection.  Otherwise, @var{data} may be a string, a symbol, an integer
913 (or a cons of two integers or list of two integers), an overlay, or a
914 cons of two markers pointing to the same buffer.  An overlay or a pair
915 of markers stands for text in the overlay or between the markers.
917 The data may also be a vector of valid non-vector selection values.
919 Each possible @var{type} has its own selection value, which changes
920 independently.  The usual values of @var{type} are @code{PRIMARY} and
921 @code{SECONDARY}; these are symbols with upper-case names, in accord
922 with X Window System conventions.  The default is @code{PRIMARY}.
923 @end defun
925 @defun x-get-selection &optional type data-type
926 This function accesses selections set up by Emacs or by other X
927 clients.  It takes two optional arguments, @var{type} and
928 @var{data-type}.  The default for @var{type}, the selection type, is
929 @code{PRIMARY}.
931 The @var{data-type} argument specifies the form of data conversion to
932 use, to convert the raw data obtained from another X client into Lisp
933 data.  Meaningful values include @code{TEXT}, @code{STRING},
934 @code{TARGETS}, @code{LENGTH}, @code{DELETE}, @code{FILE_NAME},
935 @code{CHARACTER_POSITION}, @code{LINE_NUMBER}, @code{COLUMN_NUMBER},
936 @code{OWNER_OS}, @code{HOST_NAME}, @code{USER}, @code{CLASS},
937 @code{NAME}, @code{ATOM}, and @code{INTEGER}.  (These are symbols with
938 upper-case names in accord with X conventions.)  The default for
939 @var{data-type} is @code{STRING}.
940 @end defun
942 @cindex cut buffer
943 The X server also has a set of numbered @dfn{cut buffers} which can
944 store text or other data being moved between applications.  Cut buffers
945 are considered obsolete, but Emacs supports them for the sake of X
946 clients that still use them.
948 @defun x-get-cut-buffer n
949 This function returns the contents of cut buffer number @var{n}.
950 @end defun
952 @defun x-set-cut-buffer string
953 This function stores @var{string} into the first cut buffer (cut buffer
954 0), moving the other values down through the series of cut buffers, much
955 like the way successive kills in Emacs move down the kill ring.
956 @end defun
958 @node X Connections
959 @section X Connections
961 You can close the connection with the X server with the function
962 @code{x-close-current-connection}, and open a new one with
963 @code{x-open-connection} (perhaps with a different server and display).
965 @defun x-close-current-connection
966 This function closes the connection to the X server.  It deletes all
967 frames, making Emacs effectively inaccessible to the user; therefore, a
968 Lisp program that closes the connection should open another one.
969 @end defun
971 @defun x-open-connection display &optional resource-string
972 This function opens a connection to an X server, for use of display
973 @var{display}.
975 The optional argument @var{resource-string} is a string of resource
976 names and values, in the same format used in the @file{.Xresources}
977 file.  The values you specify override the resource values recorded in
978 the X server itself.  Here's an example of what this string might look
979 like:
981 @example
982 "*BorderWidth: 3\n*InternalBorder: 2\n"
983 @end example
985 @xref{Resources}.
986 @end defun
988 @defun x-display-color-p
989 This returns @code{t} if the connected X display has color, and
990 @code{nil} otherwise.
991 @end defun
993 @defun x-color-defined-p color
994 This function reports whether a color name is meaningful.  It returns
995 @code{t} if so; otherwise, @code{nil}.
997 Note that this does not tell you whether the display you are using
998 really supports that color.  You can ask for any defined color on any
999 kind of display, and you will get some result---that is how the X server
1000 works.  Here's an approximate way to test whether your display supports
1001 the color @var{color}:
1003 @example
1004 (defun x-color-supported-p (color)
1005   (and (x-color-defined-p color)
1006        (or (x-display-color-p)
1007            (member color '("black" "white"))
1008            (and (> (x-display-planes) 1)
1009                 (equal color "gray")))))
1010 @end example
1011 @end defun
1013 @defun x-color-values color
1014 This function returns a value that describes what @var{color} should
1015 ideally look like.  If @var{color} is defined, the value is a list of
1016 three integers, which give the amount of red, the amount of green, and
1017 the amount of blue.  Each integer ranges in principle from 0 to 65535,
1018 but in practice no value seems to be above 65280.  If @var{color} is not
1019 defined, the value is @code{nil}.
1021 @example
1022 (x-color-values "black")
1023      @result{} (0 0 0)
1024 (x-color-values "white")
1025      @result{} (65280 65280 65280)
1026 (x-color-values "red")
1027      @result{} (65280 0 0)
1028 (x-color-values "pink")
1029      @result{} (65280 49152 51968)
1030 (x-color-values "hungry")
1031      @result{} nil
1032 @end example
1033 @end defun
1035 @defun x-synchronize flag
1036 The function @code{x-synchronize} enables or disables synchronous
1037 communication with the X server.  It enables synchronous communication
1038 if @var{flag} is non-@code{nil}, and disables it if @var{flag} is
1039 @code{nil}.
1041 In synchronous mode, Emacs waits for a response to each X protocol
1042 command before doing anything else.  This is useful for debugging Emacs,
1043 because protocol errors are reported right away, which helps you find
1044 the erroneous command.  Synchronous mode is not the default because it
1045 is much slower.
1046 @end defun
1048 @node Resources
1049 @section X Resources
1051 @defun x-get-resource attribute &optional component subclass
1052 The function @code{x-get-resource} retrieves a resource value from the X
1053 Windows defaults database.
1055 Resources are indexed by a combination of a @dfn{key} and a @dfn{class}.
1056 This function searches using a key of the form
1057 @samp{@var{instance}.@var{attribute}} (where @var{instance} is the name
1058 under which Emacs was invoked), and using @samp{Emacs} as the class.
1060 The optional arguments @var{component} and @var{subclass} add to the key
1061 and the class, respectively.  You must specify both of them or neither.
1062 If you specify them, the key is
1063 @samp{@var{instance}.@var{component}.@var{attribute}}, and the class is
1064 @samp{Emacs.@var{subclass}}.
1065 @end defun
1067   @xref{Resources X, X Resources,, emacs, The GNU Emacs Manual}.
1069 @node Server Data
1070 @section Data about the X Server
1072   This section describes functions and a variable that you can use to
1073 get information about the capabilities and origin of the X server that
1074 Emacs is displaying its frames on.
1076 @defun x-display-screens
1077 This function returns the number of screens associated with the current
1078 display.
1079 @end defun
1081 @defun x-server-version
1082 This function returns the list of version numbers of the X server in
1083 use.
1084 @end defun
1086 @defun x-server-vendor
1087 This function returns the vendor supporting the X server in use.
1088 @end defun
1090 @defun x-display-pixel-height
1091 This function returns the height of this X screen in pixels.
1092 @end defun
1094 @defun x-display-mm-height
1095 This function returns the height of this X screen in millimeters.
1096 @end defun
1098 @defun x-display-pixel-width
1099 This function returns the width of this X screen in pixels.
1100 @end defun
1102 @defun x-display-mm-width
1103 This function returns the width of this X screen in millimeters.
1104 @end defun
1106 @defun x-display-backing-store
1107 This function returns the backing store capability of this screen.
1108 Values can be the symbols @code{always}, @code{when-mapped}, or
1109 @code{not-useful}.
1110 @end defun
1112 @defun x-display-save-under
1113 This function returns non-@code{nil} if this X screen supports the
1114 SaveUnder feature.
1115 @end defun
1117 @defun x-display-planes
1118 This function returns the number of planes this display supports.
1119 @end defun
1121 @defun x-display-visual-class
1122 This function returns the visual class for this X screen.  The value is
1123 one of the symbols @code{static-gray}, @code{gray-scale},
1124 @code{static-color}, @code{pseudo-color}, @code{true-color}, and
1125 @code{direct-color}.
1126 @end defun
1128 @defun x-display-color-p
1129 This function returns @code{t} if the X screen in use is a color
1130 screen.
1131 @end defun
1133 @defun x-display-color-cells
1134 This function returns the number of color cells this X screen supports.
1135 @end defun
1137 @ignore
1138 @defvar x-no-window-manager
1139 This variable's value is is @code{t} if no X window manager is in use.
1140 @end defvar
1141 @end ignore
1143 @ignore
1144 @item
1145 The functions @code{x-pixel-width} and @code{x-pixel-height} return the
1146 width and height of an X Window frame, measured in pixels.
1147 @end ignore