1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
26 #ifdef HAVE_WINDOW_SYSTEM
30 #include "termhooks.h"
36 /* Evaluate this expression to rebuild the section of syms_of_frame
37 that initializes and staticpros the symbols declared below. Note
38 that Emacs 18 has a bug that keeps C-x C-e from being able to
39 evaluate this expression.
42 ;; Accumulate a list of the symbols we want to initialize from the
43 ;; declarations at the top of the file.
44 (goto-char (point-min))
45 (search-forward "/\*&&& symbols declared here &&&*\/\n")
47 (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
49 (cons (buffer-substring (match-beginning 1) (match-end 1))
52 (setq symbol-list (nreverse symbol-list))
53 ;; Delete the section of syms_of_... where we initialize the symbols.
54 (search-forward "\n /\*&&& init symbols here &&&*\/\n")
55 (let ((start (point)))
56 (while (looking-at "^ Q")
58 (kill-region start (point)))
59 ;; Write a new symbol initialization section.
61 (insert (format " %s = intern (\"" (car symbol-list)))
62 (let ((start (point)))
63 (insert (substring (car symbol-list) 1))
64 (subst-char-in-region start (point) ?_ ?-))
65 (insert (format "\");\n staticpro (&%s);\n" (car symbol-list)))
66 (setq symbol-list (cdr symbol-list)))))
69 /*&&& symbols declared here &&&*/
71 Lisp_Object Qframe_live_p
;
74 Lisp_Object Qminibuffer
;
75 Lisp_Object Qmodeline
;
78 Lisp_Object Qunsplittable
;
79 Lisp_Object Qmenu_bar_lines
;
85 Lisp_Object Qbuffer_predicate
;
86 Lisp_Object Qbuffer_list
;
89 Lisp_Object Vterminal_frame
;
90 Lisp_Object Vdefault_frame_alist
;
95 /*&&& init symbols here &&&*/
96 Qframep
= intern ("framep");
98 Qframe_live_p
= intern ("frame-live-p");
99 staticpro (&Qframe_live_p
);
100 Qheight
= intern ("height");
101 staticpro (&Qheight
);
102 Qicon
= intern ("icon");
104 Qminibuffer
= intern ("minibuffer");
105 staticpro (&Qminibuffer
);
106 Qmodeline
= intern ("modeline");
107 staticpro (&Qmodeline
);
108 Qname
= intern ("name");
110 Qonly
= intern ("only");
112 Qunsplittable
= intern ("unsplittable");
113 staticpro (&Qunsplittable
);
114 Qmenu_bar_lines
= intern ("menu-bar-lines");
115 staticpro (&Qmenu_bar_lines
);
116 Qwidth
= intern ("width");
120 Qw32
= intern ("w32");
124 Qvisible
= intern ("visible");
125 staticpro (&Qvisible
);
126 Qbuffer_predicate
= intern ("buffer-predicate");
127 staticpro (&Qbuffer_predicate
);
128 Qbuffer_list
= intern ("buffer-list");
129 staticpro (&Qbuffer_list
);
130 Qtitle
= intern ("title");
133 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist
,
134 "Alist of default values for frame creation.\n\
135 These may be set in your init file, like this:\n\
136 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1))\n\
137 These override values given in window system configuration data,\n\
138 including X Windows' defaults database.\n\
139 For values specific to the first Emacs frame, see `initial-frame-alist'.\n\
140 For values specific to the separate minibuffer frame, see\n\
141 `minibuffer-frame-alist'.\n\
142 The `menu-bar-lines' element of the list controls whether new frames\n\
143 have menu bars; `menu-bar-mode' works by altering this element.");
144 Vdefault_frame_alist
= Qnil
;
148 set_menu_bar_lines_1 (window
, n
)
152 struct window
*w
= XWINDOW (window
);
154 XSETFASTINT (w
->last_modified
, 0);
155 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
156 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
158 /* Handle just the top child in a vertical split. */
159 if (!NILP (w
->vchild
))
160 set_menu_bar_lines_1 (w
->vchild
, n
);
162 /* Adjust all children in a horizontal split. */
163 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
165 w
= XWINDOW (window
);
166 set_menu_bar_lines_1 (window
, n
);
171 set_menu_bar_lines (f
, value
, oldval
)
173 Lisp_Object value
, oldval
;
176 int olines
= FRAME_MENU_BAR_LINES (f
);
178 /* Right now, menu bars don't work properly in minibuf-only frames;
179 most of the commands try to apply themselves to the minibuffer
180 frame itself, and get an error because you can't switch buffers
181 in or split the minibuffer window. */
182 if (FRAME_MINIBUF_ONLY_P (f
))
185 if (INTEGERP (value
))
186 nlines
= XINT (value
);
190 if (nlines
!= olines
)
192 windows_or_buffers_changed
++;
193 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
194 FRAME_MENU_BAR_LINES (f
) = nlines
;
195 set_menu_bar_lines_1 (f
->root_window
, nlines
- olines
);
201 /* These help us bind and responding to switch-frame events. */
202 #include "commands.h"
203 #include "keyboard.h"
205 Lisp_Object Vemacs_iconified
;
206 Lisp_Object Vframe_list
;
208 extern Lisp_Object Vminibuffer_list
;
209 extern Lisp_Object
get_minibuffer ();
210 extern Lisp_Object
Fhandle_switch_frame ();
211 extern Lisp_Object
Fredirect_frame_focus ();
212 extern Lisp_Object
x_get_focus_frame ();
214 DEFUN ("framep", Fframep
, Sframep
, 1, 1, 0,
215 "Return non-nil if OBJECT is a frame.\n\
216 Value is t for a termcap frame (a character-only terminal),\n\
217 `x' for an Emacs frame that is really an X window,\n\
218 `pc' for a direct-write MS-DOS frame.\n\
219 See also `frame-live-p'.")
223 if (!FRAMEP (object
))
225 switch (XFRAME (object
)->output_method
)
229 case output_x_window
:
233 case output_msdos_raw
:
240 DEFUN ("frame-live-p", Fframe_live_p
, Sframe_live_p
, 1, 1, 0,
241 "Return non-nil if OBJECT is a frame which has not been deleted.\n\
242 Value is nil if OBJECT is not a live frame. If object is a live\n\
243 frame, the return value indicates what sort of output device it is\n\
244 displayed on. Value is t for a termcap frame (a character-only\n\
245 terminal), `x' for an Emacs frame being displayed in an X window.")
249 return ((FRAMEP (object
)
250 && FRAME_LIVE_P (XFRAME (object
)))
260 register struct frame
*f
;
261 register Lisp_Object root_window
;
262 register Lisp_Object mini_window
;
263 register struct Lisp_Vector
*vec
;
266 vec
= allocate_vectorlike ((EMACS_INT
) VECSIZE (struct frame
));
267 for (i
= 0; i
< VECSIZE (struct frame
); i
++)
268 XSETFASTINT (vec
->contents
[i
], 0);
269 vec
->size
= VECSIZE (struct frame
);
270 f
= (struct frame
*)vec
;
271 XSETFRAME (frame
, f
);
275 f
->current_glyphs
= 0;
276 f
->desired_glyphs
= 0;
278 f
->async_visible
= 0;
279 f
->output_data
.nothing
= 0;
281 f
->async_iconified
= 0;
282 f
->wants_modeline
= 1;
287 f
->has_minibuffer
= mini_p
;
288 f
->focus_frame
= Qnil
;
289 f
->explicit_name
= 0;
290 f
->can_have_scroll_bars
= 0;
291 f
->vertical_scroll_bar_type
= vertical_scroll_bar_none
;
292 f
->param_alist
= Qnil
;
293 f
->scroll_bars
= Qnil
;
294 f
->condemned_scroll_bars
= Qnil
;
295 f
->face_alist
= Qnil
;
296 f
->menu_bar_items
= Qnil
;
297 f
->menu_bar_vector
= Qnil
;
298 f
->menu_bar_items_used
= 0;
299 f
->buffer_predicate
= Qnil
;
300 f
->buffer_list
= Qnil
;
302 f
->kboard
= initial_kboard
;
307 root_window
= make_window ();
310 mini_window
= make_window ();
311 XWINDOW (root_window
)->next
= mini_window
;
312 XWINDOW (mini_window
)->prev
= root_window
;
313 XWINDOW (mini_window
)->mini_p
= Qt
;
314 XWINDOW (mini_window
)->frame
= frame
;
315 f
->minibuffer_window
= mini_window
;
320 XWINDOW (root_window
)->next
= Qnil
;
321 f
->minibuffer_window
= Qnil
;
324 XWINDOW (root_window
)->frame
= frame
;
327 just so that there is "something there."
328 Correct size will be set up later with change_frame_size. */
330 SET_FRAME_WIDTH (f
, 10);
333 XSETFASTINT (XWINDOW (root_window
)->width
, 10);
334 XSETFASTINT (XWINDOW (root_window
)->height
, (mini_p
? 9 : 10));
338 XSETFASTINT (XWINDOW (mini_window
)->width
, 10);
339 XSETFASTINT (XWINDOW (mini_window
)->top
, 9);
340 XSETFASTINT (XWINDOW (mini_window
)->height
, 1);
343 /* Choose a buffer for the frame's root window. */
347 XWINDOW (root_window
)->buffer
= Qt
;
348 buf
= Fcurrent_buffer ();
349 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
350 a space), try to find another one. */
351 if (XSTRING (Fbuffer_name (buf
))->data
[0] == ' ')
352 buf
= Fother_buffer (buf
, Qnil
);
353 Fset_window_buffer (root_window
, buf
);
355 f
->buffer_list
= Fcons (buf
, Qnil
);
360 XWINDOW (mini_window
)->buffer
= Qt
;
361 Fset_window_buffer (mini_window
,
362 (NILP (Vminibuffer_list
)
364 : Fcar (Vminibuffer_list
)));
367 f
->root_window
= root_window
;
368 f
->selected_window
= root_window
;
369 /* Make sure this window seems more recently used than
370 a newly-created, never-selected window. */
371 XSETFASTINT (XWINDOW (f
->selected_window
)->use_time
, ++window_select_count
);
373 #ifdef HAVE_WINDOW_SYSTEM
374 f
->fontset_data
= alloc_fontset_data ();
380 /* Make a frame using a separate minibuffer window on another frame.
381 MINI_WINDOW is the minibuffer window to use. nil means use the
382 default (the global minibuffer). */
385 make_frame_without_minibuffer (mini_window
, kb
, display
)
386 register Lisp_Object mini_window
;
390 register struct frame
*f
;
393 if (!NILP (mini_window
))
394 CHECK_LIVE_WINDOW (mini_window
, 0);
397 if (!NILP (mini_window
)
398 && XFRAME (XWINDOW (mini_window
)->frame
)->kboard
!= kb
)
399 error ("frame and minibuffer must be on the same display");
402 /* Make a frame containing just a root window. */
405 if (NILP (mini_window
))
407 /* Use default-minibuffer-frame if possible. */
408 if (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
409 || ! FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
)))
411 Lisp_Object frame_dummy
;
413 XSETFRAME (frame_dummy
, f
);
414 GCPRO1 (frame_dummy
);
415 /* If there's no minibuffer frame to use, create one. */
416 kb
->Vdefault_minibuffer_frame
=
417 call1 (intern ("make-initial-minibuffer-frame"), display
);
421 mini_window
= XFRAME (kb
->Vdefault_minibuffer_frame
)->minibuffer_window
;
424 f
->minibuffer_window
= mini_window
;
426 /* Make the chosen minibuffer window display the proper minibuffer,
427 unless it is already showing a minibuffer. */
428 if (NILP (Fmemq (XWINDOW (mini_window
)->buffer
, Vminibuffer_list
)))
429 Fset_window_buffer (mini_window
,
430 (NILP (Vminibuffer_list
)
432 : Fcar (Vminibuffer_list
)));
436 /* Make a frame containing only a minibuffer window. */
439 make_minibuffer_frame ()
441 /* First make a frame containing just a root window, no minibuffer. */
443 register struct frame
*f
= make_frame (0);
444 register Lisp_Object mini_window
;
445 register Lisp_Object frame
;
447 XSETFRAME (frame
, f
);
452 f
->wants_modeline
= 0;
453 f
->has_minibuffer
= 1;
455 /* Now label the root window as also being the minibuffer.
456 Avoid infinite looping on the window chain by marking next pointer
459 mini_window
= f
->minibuffer_window
= f
->root_window
;
460 XWINDOW (mini_window
)->mini_p
= Qt
;
461 XWINDOW (mini_window
)->next
= Qnil
;
462 XWINDOW (mini_window
)->prev
= Qnil
;
463 XWINDOW (mini_window
)->frame
= frame
;
465 /* Put the proper buffer in that window. */
467 Fset_window_buffer (mini_window
,
468 (NILP (Vminibuffer_list
)
470 : Fcar (Vminibuffer_list
)));
474 /* Construct a frame that refers to the terminal (stdin and stdout). */
476 static int terminal_frame_count
;
479 make_terminal_frame ()
481 register struct frame
*f
;
488 initial_kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
489 init_kboard (initial_kboard
);
490 initial_kboard
->next_kboard
= all_kboards
;
491 all_kboards
= initial_kboard
;
495 /* The first call must initialize Vframe_list. */
496 if (! (NILP (Vframe_list
) || CONSP (Vframe_list
)))
501 XSETFRAME (frame
, f
);
502 Vframe_list
= Fcons (frame
, Vframe_list
);
504 terminal_frame_count
++;
505 sprintf (name
, "F%d", terminal_frame_count
);
506 f
->name
= build_string (name
);
508 f
->visible
= 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
509 f
->async_visible
= 1; /* Don't let visible be cleared later. */
511 f
->output_data
.x
= &the_only_x_display
;
512 f
->output_method
= output_msdos_raw
;
513 init_frame_faces (f
);
514 #else /* not MSDOS */
515 f
->output_data
.nothing
= 1; /* Nonzero means frame isn't deleted. */
520 DEFUN ("make-terminal-frame", Fmake_terminal_frame
, Smake_terminal_frame
,
521 1, 1, 0, "Create an additional terminal frame.\n\
522 You can create multiple frames on a text-only terminal in this way.\n\
523 Only the selected terminal frame is actually displayed.\n\
524 This function takes one argument, an alist specifying frame parameters.\n\
525 In practice, generally you don't need to specify any parameters.\n\
526 Note that changing the size of one terminal frame automatically affects all.")
534 if (selected_frame
->output_method
!= output_msdos_raw
)
537 if (selected_frame
->output_method
!= output_termcap
)
538 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
541 f
= make_terminal_frame ();
542 change_frame_size (f
, FRAME_HEIGHT (selected_frame
),
543 FRAME_WIDTH (selected_frame
), 0, 0);
544 remake_frame_glyphs (f
);
546 XSETFRAME (frame
, f
);
547 Fmodify_frame_parameters (frame
, Vdefault_frame_alist
);
548 Fmodify_frame_parameters (frame
, parms
);
549 f
->face_alist
= selected_frame
->face_alist
;
554 do_switch_frame (frame
, no_enter
, track
)
555 Lisp_Object frame
, no_enter
;
558 /* If FRAME is a switch-frame event, extract the frame we should
561 && EQ (XCONS (frame
)->car
, Qswitch_frame
)
562 && CONSP (XCONS (frame
)->cdr
))
563 frame
= XCONS (XCONS (frame
)->cdr
)->car
;
565 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
566 a switch-frame event to arrive after a frame is no longer live,
567 especially when deleting the initial frame during startup. */
568 CHECK_FRAME (frame
, 0);
569 if (! FRAME_LIVE_P (XFRAME (frame
)))
572 if (selected_frame
== XFRAME (frame
))
575 /* This is too greedy; it causes inappropriate focus redirection
576 that's hard to get rid of. */
578 /* If a frame's focus has been redirected toward the currently
579 selected frame, we should change the redirection to point to the
580 newly selected frame. This means that if the focus is redirected
581 from a minibufferless frame to a surrogate minibuffer frame, we
582 can use `other-window' to switch between all the frames using
583 that minibuffer frame, and the focus redirection will follow us
589 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
593 if (!FRAMEP (XCONS (tail
)->car
))
596 focus
= FRAME_FOCUS_FRAME (XFRAME (XCONS (tail
)->car
));
598 if (FRAMEP (focus
) && XFRAME (focus
) == selected_frame
)
599 Fredirect_frame_focus (XCONS (tail
)->car
, frame
);
603 /* Instead, apply it only to the frame we're pointing to. */
604 #ifdef HAVE_WINDOW_SYSTEM
605 if (track
&& (FRAME_WINDOW_P (XFRAME (frame
))))
607 Lisp_Object focus
, xfocus
;
609 xfocus
= x_get_focus_frame (XFRAME (frame
));
612 focus
= FRAME_FOCUS_FRAME (XFRAME (xfocus
));
613 if (FRAMEP (focus
) && XFRAME (focus
) == selected_frame
)
614 Fredirect_frame_focus (xfocus
, frame
);
617 #endif /* HAVE_X_WINDOWS */
620 selected_frame
= XFRAME (frame
);
621 if (! FRAME_MINIBUF_ONLY_P (selected_frame
))
622 last_nonminibuf_frame
= selected_frame
;
624 Fselect_window (XFRAME (frame
)->selected_window
);
626 /* We want to make sure that the next event generates a frame-switch
627 event to the appropriate frame. This seems kludgy to me, but
628 before you take it out, make sure that evaluating something like
629 (select-window (frame-root-window (new-frame))) doesn't end up
630 with your typing being interpreted in the new frame instead of
631 the one you're actually typing in. */
632 internal_last_event_frame
= Qnil
;
637 DEFUN ("select-frame", Fselect_frame
, Sselect_frame
, 1, 2, "e",
638 "Select the frame FRAME.\n\
639 Subsequent editing commands apply to its selected window.\n\
640 The selection of FRAME lasts until the next time the user does\n\
641 something to select a different frame, or until the next time this\n\
642 function is called.")
644 Lisp_Object frame
, no_enter
;
646 return do_switch_frame (frame
, no_enter
, 1);
650 DEFUN ("handle-switch-frame", Fhandle_switch_frame
, Shandle_switch_frame
, 1, 2, "e",
651 "Handle a switch-frame event EVENT.\n\
652 Switch-frame events are usually bound to this function.\n\
653 A switch-frame event tells Emacs that the window manager has requested\n\
654 that the user's events be directed to the frame mentioned in the event.\n\
655 This function selects the selected window of the frame of EVENT.\n\
657 If EVENT is frame object, handle it as if it were a switch-frame event\n\
660 Lisp_Object event
, no_enter
;
662 /* Preserve prefix arg that the command loop just cleared. */
663 current_kboard
->Vprefix_arg
= Vcurrent_prefix_arg
;
664 call1 (Vrun_hooks
, Qmouse_leave_buffer_hook
);
665 return do_switch_frame (event
, no_enter
, 0);
668 DEFUN ("ignore-event", Fignore_event
, Signore_event
, 0, 0, "",
669 "Do nothing, but preserve any prefix argument already specified.\n\
670 This is a suitable binding for iconify-frame and make-frame-visible.")
673 current_kboard
->Vprefix_arg
= Vcurrent_prefix_arg
;
677 DEFUN ("selected-frame", Fselected_frame
, Sselected_frame
, 0, 0, 0,
678 "Return the frame that is now selected.")
682 XSETFRAME (tem
, selected_frame
);
686 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 1, 1, 0,
687 "Return the frame object that window WINDOW is on.")
691 CHECK_LIVE_WINDOW (window
, 0);
692 return XWINDOW (window
)->frame
;
695 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
696 "Returns the topmost, leftmost window of FRAME.\n\
697 If omitted, FRAME defaults to the currently selected frame.")
704 w
= selected_frame
->root_window
;
707 CHECK_LIVE_FRAME (frame
, 0);
708 w
= XFRAME (frame
)->root_window
;
710 while (NILP (XWINDOW (w
)->buffer
))
712 if (! NILP (XWINDOW (w
)->hchild
))
713 w
= XWINDOW (w
)->hchild
;
714 else if (! NILP (XWINDOW (w
)->vchild
))
715 w
= XWINDOW (w
)->vchild
;
722 DEFUN ("active-minibuffer-window", Factive_minibuffer_window
,
723 Sactive_minibuffer_window
, 0, 0, 0,
724 "Return the currently active minibuffer window, or nil if none.")
727 return minibuf_level
? minibuf_window
: Qnil
;
730 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
731 "Returns the root-window of FRAME.\n\
732 If omitted, FRAME defaults to the currently selected frame.")
737 XSETFRAME (frame
, selected_frame
);
739 CHECK_LIVE_FRAME (frame
, 0);
741 return XFRAME (frame
)->root_window
;
744 DEFUN ("frame-selected-window", Fframe_selected_window
,
745 Sframe_selected_window
, 0, 1, 0,
746 "Return the selected window of frame object FRAME.\n\
747 If omitted, FRAME defaults to the currently selected frame.")
752 XSETFRAME (frame
, selected_frame
);
754 CHECK_LIVE_FRAME (frame
, 0);
756 return XFRAME (frame
)->selected_window
;
759 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
760 Sset_frame_selected_window
, 2, 2, 0,
761 "Set the selected window of frame object FRAME to WINDOW.\n\
762 If FRAME is nil, the selected frame is used.\n\
763 If FRAME is the selected frame, this makes WINDOW the selected window.")
765 Lisp_Object frame
, window
;
768 XSETFRAME (frame
, selected_frame
);
770 CHECK_LIVE_FRAME (frame
, 0);
772 CHECK_LIVE_WINDOW (window
, 1);
774 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
775 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
777 if (XFRAME (frame
) == selected_frame
)
778 return Fselect_window (window
);
780 return XFRAME (frame
)->selected_window
= window
;
783 DEFUN ("frame-list", Fframe_list
, Sframe_list
,
785 "Return a list of all frames.")
788 return Fcopy_sequence (Vframe_list
);
791 /* Return the next frame in the frame list after FRAME.
792 If MINIBUF is nil, exclude minibuffer-only frames.
793 If MINIBUF is a window, include only its own frame
794 and any frame now using that window as the minibuffer.
795 If MINIBUF is `visible', include all visible frames.
796 If MINIBUF is 0, include all visible and iconified frames.
797 Otherwise, include all frames. */
800 next_frame (frame
, minibuf
)
807 /* There must always be at least one frame in Vframe_list. */
808 if (! CONSP (Vframe_list
))
811 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
812 forever. Forestall that. */
813 CHECK_LIVE_FRAME (frame
, 0);
816 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
820 f
= XCONS (tail
)->car
;
823 && FRAME_KBOARD (XFRAME (f
)) == FRAME_KBOARD (XFRAME (frame
)))
825 /* Decide whether this frame is eligible to be returned. */
827 /* If we've looped all the way around without finding any
828 eligible frames, return the original frame. */
832 /* Let minibuf decide if this frame is acceptable. */
835 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f
)))
838 else if (EQ (minibuf
, Qvisible
))
840 FRAME_SAMPLE_VISIBILITY (XFRAME (f
));
841 if (FRAME_VISIBLE_P (XFRAME (f
)))
844 else if (XFASTINT (minibuf
) == 0)
846 FRAME_SAMPLE_VISIBILITY (XFRAME (f
));
847 if (FRAME_VISIBLE_P (XFRAME (f
))
848 || FRAME_ICONIFIED_P (XFRAME (f
)))
851 else if (WINDOWP (minibuf
))
853 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f
)), minibuf
)
854 /* Check that F either is, or has forwarded its focus to,
856 && (EQ (WINDOW_FRAME (XWINDOW (minibuf
)), f
)
857 || EQ (WINDOW_FRAME (XWINDOW (minibuf
)),
858 FRAME_FOCUS_FRAME (XFRAME (f
)))))
870 /* Return the previous frame in the frame list before FRAME.
871 If MINIBUF is nil, exclude minibuffer-only frames.
872 If MINIBUF is a window, include only its own frame
873 and any frame now using that window as the minibuffer.
874 If MINIBUF is `visible', include all visible frames.
875 If MINIBUF is 0, include all visible and iconified frames.
876 Otherwise, include all frames. */
879 prev_frame (frame
, minibuf
)
886 /* There must always be at least one frame in Vframe_list. */
887 if (! CONSP (Vframe_list
))
891 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
895 f
= XCONS (tail
)->car
;
899 if (EQ (frame
, f
) && !NILP (prev
))
902 if (FRAME_KBOARD (XFRAME (f
)) == FRAME_KBOARD (XFRAME (frame
)))
904 /* Decide whether this frame is eligible to be returned,
905 according to minibuf. */
908 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f
)))
911 else if (WINDOWP (minibuf
))
913 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f
)), minibuf
)
914 /* Check that F either is, or has forwarded its focus to,
916 && (EQ (WINDOW_FRAME (XWINDOW (minibuf
)), f
)
917 || EQ (WINDOW_FRAME (XWINDOW (minibuf
)),
918 FRAME_FOCUS_FRAME (XFRAME (f
)))))
921 else if (EQ (minibuf
, Qvisible
))
923 FRAME_SAMPLE_VISIBILITY (XFRAME (f
));
924 if (FRAME_VISIBLE_P (XFRAME (f
)))
927 else if (XFASTINT (minibuf
) == 0)
929 FRAME_SAMPLE_VISIBILITY (XFRAME (f
));
930 if (FRAME_VISIBLE_P (XFRAME (f
))
931 || FRAME_ICONIFIED_P (XFRAME (f
)))
939 /* We've scanned the entire list. */
941 /* We went through the whole frame list without finding a single
942 acceptable frame. Return the original frame. */
945 /* There were no acceptable frames in the list before FRAME; otherwise,
946 we would have returned directly from the loop. Since PREV is the last
947 acceptable frame in the list, return it. */
952 DEFUN ("next-frame", Fnext_frame
, Snext_frame
, 0, 2, 0,
953 "Return the next frame in the frame list after FRAME.\n\
954 It considers only frames on the same terminal as FRAME.\n\
955 By default, skip minibuffer-only frames.\n\
956 If omitted, FRAME defaults to the selected frame.\n\
957 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.\n\
958 If MINIFRAME is a window, include only its own frame\n\
959 and any frame now using that window as the minibuffer.\n\
960 If MINIFRAME is `visible', include all visible frames.\n\
961 If MINIFRAME is 0, include all visible and iconified frames.\n\
962 Otherwise, include all frames.")
964 Lisp_Object frame
, miniframe
;
969 XSETFRAME (frame
, selected_frame
);
971 CHECK_LIVE_FRAME (frame
, 0);
973 return next_frame (frame
, miniframe
);
976 DEFUN ("previous-frame", Fprevious_frame
, Sprevious_frame
, 0, 2, 0,
977 "Return the previous frame in the frame list before FRAME.\n\
978 It considers only frames on the same terminal as FRAME.\n\
979 By default, skip minibuffer-only frames.\n\
980 If omitted, FRAME defaults to the selected frame.\n\
981 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.\n\
982 If MINIFRAME is a window, include only its own frame\n\
983 and any frame now using that window as the minibuffer.\n\
984 If MINIFRAME is `visible', include all visible frames.\n\
985 If MINIFRAME is 0, include all visible and iconified frames.\n\
986 Otherwise, include all frames.")
988 Lisp_Object frame
, miniframe
;
993 XSETFRAME (frame
, selected_frame
);
995 CHECK_LIVE_FRAME (frame
, 0);
997 return prev_frame (frame
, miniframe
);
1000 /* Return 1 if it is ok to delete frame F;
1001 0 if all frames aside from F are invisible.
1002 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1005 other_visible_frames (f
)
1008 /* We know the selected frame is visible,
1009 so if F is some other frame, it can't be the sole visible one. */
1010 if (f
== selected_frame
)
1015 for (frames
= Vframe_list
;
1017 frames
= XCONS (frames
)->cdr
)
1021 this = XCONS (frames
)->car
;
1022 /* Verify that the frame's window still exists
1023 and we can still talk to it. And note any recent change
1025 #ifdef HAVE_WINDOW_SYSTEM
1026 if (FRAME_WINDOW_P (XFRAME (this)))
1028 x_sync (XFRAME (this));
1029 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1033 if (FRAME_VISIBLE_P (XFRAME (this))
1034 || FRAME_ICONIFIED_P (XFRAME (this))
1035 /* Allow deleting the terminal frame when at least
1036 one X frame exists! */
1037 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f
)))
1045 DEFUN ("delete-frame", Fdelete_frame
, Sdelete_frame
, 0, 2, "",
1046 "Delete FRAME, permanently eliminating it from use.\n\
1047 If omitted, FRAME defaults to the selected frame.\n\
1048 A frame may not be deleted if its minibuffer is used by other frames.\n\
1049 Normally, you may not delete a frame if all other frames are invisible,\n\
1050 but if the second optional argument FORCE is non-nil, you may do so.")
1052 Lisp_Object frame
, force
;
1055 int minibuffer_selected
;
1057 if (EQ (frame
, Qnil
))
1060 XSETFRAME (frame
, f
);
1064 CHECK_FRAME (frame
, 0);
1068 if (! FRAME_LIVE_P (f
))
1071 if (NILP (force
) && !other_visible_frames (f
))
1072 error ("Attempt to delete the sole visible or iconified frame");
1074 /* Does this frame have a minibuffer, and is it the surrogate
1075 minibuffer for any other frame? */
1076 if (FRAME_HAS_MINIBUF_P (XFRAME (frame
)))
1080 for (frames
= Vframe_list
;
1082 frames
= XCONS (frames
)->cdr
)
1085 this = XCONS (frames
)->car
;
1087 if (! EQ (this, frame
)
1089 WINDOW_FRAME (XWINDOW
1090 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1091 error ("Attempt to delete a surrogate minibuffer frame");
1095 minibuffer_selected
= EQ (minibuf_window
, selected_window
);
1097 /* Don't let the frame remain selected. */
1098 if (f
== selected_frame
)
1100 Lisp_Object tail
, frame1
;
1102 /* Look for another visible frame on the same terminal. */
1103 frame1
= next_frame (frame
, Qvisible
);
1105 /* If there is none, find *some* other frame. */
1106 if (NILP (frame1
) || EQ (frame1
, frame
))
1108 FOR_EACH_FRAME (tail
, frame1
)
1110 if (! EQ (frame
, frame1
))
1115 do_switch_frame (frame1
, Qnil
, 0);
1118 /* Don't allow minibuf_window to remain on a deleted frame. */
1119 if (EQ (f
->minibuffer_window
, minibuf_window
))
1121 Fset_window_buffer (selected_frame
->minibuffer_window
,
1122 XWINDOW (minibuf_window
)->buffer
);
1123 minibuf_window
= selected_frame
->minibuffer_window
;
1125 /* If the dying minibuffer window was selected,
1126 select the new one. */
1127 if (minibuffer_selected
)
1128 Fselect_window (minibuf_window
);
1131 /* Clear any X selections for this frame. */
1132 #ifdef HAVE_X_WINDOWS
1134 x_clear_frame_selections (f
);
1137 /* Mark all the windows that used to be on FRAME as deleted, and then
1138 remove the reference to them. */
1139 delete_all_subwindows (XWINDOW (f
->root_window
));
1140 f
->root_window
= Qnil
;
1142 Vframe_list
= Fdelq (frame
, Vframe_list
);
1143 FRAME_SET_VISIBLE (f
, 0);
1145 if (echo_area_glyphs
== FRAME_MESSAGE_BUF (f
))
1147 echo_area_glyphs
= 0;
1148 previous_echo_glyphs
= 0;
1153 if (FRAME_CURRENT_GLYPHS (f
))
1154 free_frame_glyphs (f
, FRAME_CURRENT_GLYPHS (f
));
1155 if (FRAME_DESIRED_GLYPHS (f
))
1156 free_frame_glyphs (f
, FRAME_DESIRED_GLYPHS (f
));
1157 if (FRAME_TEMP_GLYPHS (f
))
1158 free_frame_glyphs (f
, FRAME_TEMP_GLYPHS (f
));
1159 if (FRAME_INSERT_COST (f
))
1160 free (FRAME_INSERT_COST (f
));
1161 if (FRAME_DELETEN_COST (f
))
1162 free (FRAME_DELETEN_COST (f
));
1163 if (FRAME_INSERTN_COST (f
))
1164 free (FRAME_INSERTN_COST (f
));
1165 if (FRAME_DELETE_COST (f
))
1166 free (FRAME_DELETE_COST (f
));
1167 if (FRAME_MESSAGE_BUF (f
))
1168 free (FRAME_MESSAGE_BUF (f
));
1170 #ifdef HAVE_WINDOW_SYSTEM
1171 /* Free all fontset data. */
1172 free_fontset_data (FRAME_FONTSET_DATA (f
));
1175 /* Since some events are handled at the interrupt level, we may get
1176 an event for f at any time; if we zero out the frame's display
1177 now, then we may trip up the event-handling code. Instead, we'll
1178 promise that the display of the frame must be valid until we have
1179 called the window-system-dependent frame destruction routine. */
1181 /* I think this should be done with a hook. */
1182 #ifdef HAVE_WINDOW_SYSTEM
1183 if (FRAME_WINDOW_P (f
))
1184 x_destroy_window (f
);
1187 f
->output_data
.nothing
= 0;
1189 /* If we've deleted the last_nonminibuf_frame, then try to find
1191 if (f
== last_nonminibuf_frame
)
1195 last_nonminibuf_frame
= 0;
1197 for (frames
= Vframe_list
;
1199 frames
= XCONS (frames
)->cdr
)
1201 f
= XFRAME (XCONS (frames
)->car
);
1202 if (!FRAME_MINIBUF_ONLY_P (f
))
1204 last_nonminibuf_frame
= f
;
1210 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1211 find another one. Prefer minibuffer-only frames, but also notice
1212 frames with other windows. */
1213 if (EQ (frame
, FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
))
1217 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1218 Lisp_Object frame_with_minibuf
;
1219 /* Some frame we found on the same kboard, or nil if there are none. */
1220 Lisp_Object frame_on_same_kboard
;
1222 frame_on_same_kboard
= Qnil
;
1223 frame_with_minibuf
= Qnil
;
1225 for (frames
= Vframe_list
;
1227 frames
= XCONS (frames
)->cdr
)
1232 this = XCONS (frames
)->car
;
1237 /* Consider only frames on the same kboard
1238 and only those with minibuffers. */
1239 if (FRAME_KBOARD (f
) == FRAME_KBOARD (f1
)
1240 && FRAME_HAS_MINIBUF_P (f1
))
1242 frame_with_minibuf
= this;
1243 if (FRAME_MINIBUF_ONLY_P (f1
))
1247 if (FRAME_KBOARD (f
) == FRAME_KBOARD (f1
))
1248 frame_on_same_kboard
= this;
1251 if (!NILP (frame_on_same_kboard
))
1253 /* We know that there must be some frame with a minibuffer out
1254 there. If this were not true, all of the frames present
1255 would have to be minibufferless, which implies that at some
1256 point their minibuffer frames must have been deleted, but
1257 that is prohibited at the top; you can't delete surrogate
1258 minibuffer frames. */
1259 if (NILP (frame_with_minibuf
))
1262 FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
= frame_with_minibuf
;
1265 /* No frames left on this kboard--say no minibuffer either. */
1266 FRAME_KBOARD (f
)->Vdefault_minibuffer_frame
= Qnil
;
1269 /* Cause frame titles to update--necessary if we now have just one frame. */
1270 update_mode_lines
= 1;
1275 /* Return mouse position in character cell units. */
1277 DEFUN ("mouse-position", Fmouse_position
, Smouse_position
, 0, 0, 0,
1278 "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
1279 The position is given in character cells, where (0, 0) is the\n\
1280 upper-left corner.\n\
1281 If Emacs is running on a mouseless terminal or hasn't been programmed\n\
1282 to read the mouse position, it returns the selected frame for FRAME\n\
1283 and nil for X and Y.")
1287 Lisp_Object lispy_dummy
;
1288 enum scroll_bar_part party_dummy
;
1291 unsigned long long_dummy
;
1297 /* It's okay for the hook to refrain from storing anything. */
1298 if (mouse_position_hook
)
1299 (*mouse_position_hook
) (&f
, 0,
1300 &lispy_dummy
, &party_dummy
,
1307 pixel_to_glyph_coords (f
, col
, row
, &col
, &row
, NULL
, 1);
1312 XSETFRAME (lispy_dummy
, f
);
1313 return Fcons (lispy_dummy
, Fcons (x
, y
));
1316 DEFUN ("mouse-pixel-position", Fmouse_pixel_position
,
1317 Smouse_pixel_position
, 0, 0, 0,
1318 "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
1319 The position is given in pixel units, where (0, 0) is the\n\
1320 upper-left corner.\n\
1321 If Emacs is running on a mouseless terminal or hasn't been programmed\n\
1322 to read the mouse position, it returns the selected frame for FRAME\n\
1323 and nil for X and Y.")
1327 Lisp_Object lispy_dummy
;
1328 enum scroll_bar_part party_dummy
;
1331 unsigned long long_dummy
;
1337 /* It's okay for the hook to refrain from storing anything. */
1338 if (mouse_position_hook
)
1339 (*mouse_position_hook
) (&f
, 0,
1340 &lispy_dummy
, &party_dummy
,
1344 XSETFRAME (lispy_dummy
, f
);
1345 return Fcons (lispy_dummy
, Fcons (x
, y
));
1348 DEFUN ("set-mouse-position", Fset_mouse_position
, Sset_mouse_position
, 3, 3, 0,
1349 "Move the mouse pointer to the center of character cell (X,Y) in FRAME.\n\
1350 Note, this is a no-op for an X frame that is not visible.\n\
1351 If you have just created a frame, you must wait for it to become visible\n\
1352 before calling this function on it, like this.\n\
1353 (while (not (frame-visible-p frame)) (sleep-for .5))")
1355 Lisp_Object frame
, x
, y
;
1357 CHECK_LIVE_FRAME (frame
, 0);
1358 CHECK_NUMBER (x
, 2);
1359 CHECK_NUMBER (y
, 1);
1361 /* I think this should be done with a hook. */
1362 #ifdef HAVE_WINDOW_SYSTEM
1363 if (FRAME_WINDOW_P (XFRAME (frame
)))
1364 /* Warping the mouse will cause enternotify and focus events. */
1365 x_set_mouse_position (XFRAME (frame
), x
, y
);
1367 #if defined (MSDOS) && defined (HAVE_MOUSE)
1368 if (FRAME_MSDOS_P (XFRAME (frame
)))
1370 Fselect_frame (frame
, Qnil
);
1371 mouse_moveto (XINT (x
), XINT (y
));
1379 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position
,
1380 Sset_mouse_pixel_position
, 3, 3, 0,
1381 "Move the mouse pointer to pixel position (X,Y) in FRAME.\n\
1382 Note, this is a no-op for an X frame that is not visible.\n\
1383 If you have just created a frame, you must wait for it to become visible\n\
1384 before calling this function on it, like this.\n\
1385 (while (not (frame-visible-p frame)) (sleep-for .5))")
1387 Lisp_Object frame
, x
, y
;
1389 CHECK_LIVE_FRAME (frame
, 0);
1390 CHECK_NUMBER (x
, 2);
1391 CHECK_NUMBER (y
, 1);
1393 /* I think this should be done with a hook. */
1394 #ifdef HAVE_WINDOW_SYSTEM
1395 if (FRAME_WINDOW_P (XFRAME (frame
)))
1396 /* Warping the mouse will cause enternotify and focus events. */
1397 x_set_mouse_pixel_position (XFRAME (frame
), x
, y
);
1399 #if defined (MSDOS) && defined (HAVE_MOUSE)
1400 if (FRAME_MSDOS_P (XFRAME (frame
)))
1402 Fselect_frame (frame
, Qnil
);
1403 mouse_moveto (XINT (x
), XINT (y
));
1411 DEFUN ("make-frame-visible", Fmake_frame_visible
, Smake_frame_visible
,
1413 "Make the frame FRAME visible (assuming it is an X-window).\n\
1414 If omitted, FRAME defaults to the currently selected frame.")
1419 XSETFRAME (frame
, selected_frame
);
1421 CHECK_LIVE_FRAME (frame
, 0);
1423 /* I think this should be done with a hook. */
1424 #ifdef HAVE_WINDOW_SYSTEM
1425 if (FRAME_WINDOW_P (XFRAME (frame
)))
1427 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1428 x_make_frame_visible (XFRAME (frame
));
1432 /* Make menu bar update for the Buffers and Frams menus. */
1433 windows_or_buffers_changed
++;
1438 DEFUN ("make-frame-invisible", Fmake_frame_invisible
, Smake_frame_invisible
,
1440 "Make the frame FRAME invisible (assuming it is an X-window).\n\
1441 If omitted, FRAME defaults to the currently selected frame.\n\
1442 Normally you may not make FRAME invisible if all other frames are invisible,\n\
1443 but if the second optional argument FORCE is non-nil, you may do so.")
1445 Lisp_Object frame
, force
;
1448 XSETFRAME (frame
, selected_frame
);
1450 CHECK_LIVE_FRAME (frame
, 0);
1452 if (NILP (force
) && !other_visible_frames (XFRAME (frame
)))
1453 error ("Attempt to make invisible the sole visible or iconified frame");
1455 #if 0 /* This isn't logically necessary, and it can do GC. */
1456 /* Don't let the frame remain selected. */
1457 if (XFRAME (frame
) == selected_frame
)
1458 do_switch_frame (next_frame (frame
, Qt
), Qnil
, 0)
1461 /* Don't allow minibuf_window to remain on a deleted frame. */
1462 if (EQ (XFRAME (frame
)->minibuffer_window
, minibuf_window
))
1464 Fset_window_buffer (selected_frame
->minibuffer_window
,
1465 XWINDOW (minibuf_window
)->buffer
);
1466 minibuf_window
= selected_frame
->minibuffer_window
;
1469 /* I think this should be done with a hook. */
1470 #ifdef HAVE_WINDOW_SYSTEM
1471 if (FRAME_WINDOW_P (XFRAME (frame
)))
1472 x_make_frame_invisible (XFRAME (frame
));
1475 /* Make menu bar update for the Buffers and Frams menus. */
1476 windows_or_buffers_changed
++;
1481 DEFUN ("iconify-frame", Ficonify_frame
, Siconify_frame
,
1483 "Make the frame FRAME into an icon.\n\
1484 If omitted, FRAME defaults to the currently selected frame.")
1489 XSETFRAME (frame
, selected_frame
);
1491 CHECK_LIVE_FRAME (frame
, 0);
1493 #if 0 /* This isn't logically necessary, and it can do GC. */
1494 /* Don't let the frame remain selected. */
1495 if (XFRAME (frame
) == selected_frame
)
1496 Fhandle_switch_frame (next_frame (frame
, Qt
), Qnil
);
1499 /* Don't allow minibuf_window to remain on a deleted frame. */
1500 if (EQ (XFRAME (frame
)->minibuffer_window
, minibuf_window
))
1502 Fset_window_buffer (selected_frame
->minibuffer_window
,
1503 XWINDOW (minibuf_window
)->buffer
);
1504 minibuf_window
= selected_frame
->minibuffer_window
;
1507 /* I think this should be done with a hook. */
1508 #ifdef HAVE_WINDOW_SYSTEM
1509 if (FRAME_WINDOW_P (XFRAME (frame
)))
1510 x_iconify_frame (XFRAME (frame
));
1513 /* Make menu bar update for the Buffers and Frams menus. */
1514 windows_or_buffers_changed
++;
1519 DEFUN ("frame-visible-p", Fframe_visible_p
, Sframe_visible_p
,
1521 "Return t if FRAME is now \"visible\" (actually in use for display).\n\
1522 A frame that is not \"visible\" is not updated and, if it works through\n\
1523 a window system, it may not show at all.\n\
1524 Return the symbol `icon' if frame is visible only as an icon.")
1528 CHECK_LIVE_FRAME (frame
, 0);
1530 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
1532 if (FRAME_VISIBLE_P (XFRAME (frame
)))
1534 if (FRAME_ICONIFIED_P (XFRAME (frame
)))
1539 DEFUN ("visible-frame-list", Fvisible_frame_list
, Svisible_frame_list
,
1541 "Return a list of all frames now \"visible\" (being updated).")
1544 Lisp_Object tail
, frame
;
1549 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1551 frame
= XCONS (tail
)->car
;
1552 if (!FRAMEP (frame
))
1555 if (FRAME_VISIBLE_P (f
))
1556 value
= Fcons (frame
, value
);
1562 DEFUN ("raise-frame", Fraise_frame
, Sraise_frame
, 0, 1, "",
1563 "Bring FRAME to the front, so it occludes any frames it overlaps.\n\
1564 If FRAME is invisible, make it visible.\n\
1565 If you don't specify a frame, the selected frame is used.\n\
1566 If Emacs is displaying on an ordinary terminal or some other device which\n\
1567 doesn't support multiple overlapping frames, this function does nothing.")
1572 XSETFRAME (frame
, selected_frame
);
1574 CHECK_LIVE_FRAME (frame
, 0);
1576 /* Do like the documentation says. */
1577 Fmake_frame_visible (frame
);
1579 if (frame_raise_lower_hook
)
1580 (*frame_raise_lower_hook
) (XFRAME (frame
), 1);
1585 /* Should we have a corresponding function called Flower_Power? */
1586 DEFUN ("lower-frame", Flower_frame
, Slower_frame
, 0, 1, "",
1587 "Send FRAME to the back, so it is occluded by any frames that overlap it.\n\
1588 If you don't specify a frame, the selected frame is used.\n\
1589 If Emacs is displaying on an ordinary terminal or some other device which\n\
1590 doesn't support multiple overlapping frames, this function does nothing.")
1595 XSETFRAME (frame
, selected_frame
);
1597 CHECK_LIVE_FRAME (frame
, 0);
1599 if (frame_raise_lower_hook
)
1600 (*frame_raise_lower_hook
) (XFRAME (frame
), 0);
1606 DEFUN ("redirect-frame-focus", Fredirect_frame_focus
, Sredirect_frame_focus
,
1608 "Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.\n\
1609 In other words, switch-frame events caused by events in FRAME will\n\
1610 request a switch to FOCUS-FRAME, and `last-event-frame' will be\n\
1611 FOCUS-FRAME after reading an event typed at FRAME.\n\
1613 If FOCUS-FRAME is omitted or nil, any existing redirection is\n\
1614 cancelled, and the frame again receives its own keystrokes.\n\
1616 Focus redirection is useful for temporarily redirecting keystrokes to\n\
1617 a surrogate minibuffer frame when a frame doesn't have its own\n\
1618 minibuffer window.\n\
1620 A frame's focus redirection can be changed by select-frame. If frame\n\
1621 FOO is selected, and then a different frame BAR is selected, any\n\
1622 frames redirecting their focus to FOO are shifted to redirect their\n\
1623 focus to BAR. This allows focus redirection to work properly when the\n\
1624 user switches from one frame to another using `select-window'.\n\
1626 This means that a frame whose focus is redirected to itself is treated\n\
1627 differently from a frame whose focus is redirected to nil; the former\n\
1628 is affected by select-frame, while the latter is not.\n\
1630 The redirection lasts until `redirect-frame-focus' is called to change it.")
1631 (frame
, focus_frame
)
1632 Lisp_Object frame
, focus_frame
;
1634 /* Note that we don't check for a live frame here. It's reasonable
1635 to redirect the focus of a frame you're about to delete, if you
1636 know what other frame should receive those keystrokes. */
1637 CHECK_FRAME (frame
, 0);
1639 if (! NILP (focus_frame
))
1640 CHECK_LIVE_FRAME (focus_frame
, 1);
1642 XFRAME (frame
)->focus_frame
= focus_frame
;
1644 if (frame_rehighlight_hook
)
1645 (*frame_rehighlight_hook
) (XFRAME (frame
));
1651 DEFUN ("frame-focus", Fframe_focus
, Sframe_focus
, 1, 1, 0,
1652 "Return the frame to which FRAME's keystrokes are currently being sent.\n\
1653 This returns nil if FRAME's focus is not redirected.\n\
1654 See `redirect-frame-focus'.")
1658 CHECK_LIVE_FRAME (frame
, 0);
1660 return FRAME_FOCUS_FRAME (XFRAME (frame
));
1665 /* Return the value of frame parameter PROP in frame FRAME. */
1668 get_frame_param (frame
, prop
)
1669 register struct frame
*frame
;
1672 register Lisp_Object tem
;
1674 tem
= Fassq (prop
, frame
->param_alist
);
1680 /* Return the buffer-predicate of the selected frame. */
1683 frame_buffer_predicate ()
1685 return selected_frame
->buffer_predicate
;
1688 /* Return the buffer-list of the selected frame. */
1691 frame_buffer_list ()
1693 return selected_frame
->buffer_list
;
1696 /* Set the buffer-list of the selected frame. */
1699 set_frame_buffer_list (list
)
1702 selected_frame
->buffer_list
= list
;
1705 /* Discard BUFFER from the buffer-list of each frame. */
1708 frames_discard_buffer (buffer
)
1711 Lisp_Object frame
, tail
;
1713 FOR_EACH_FRAME (tail
, frame
)
1715 XFRAME (frame
)->buffer_list
1716 = Fdelq (buffer
, XFRAME (frame
)->buffer_list
);
1720 /* Move BUFFER to the end of the buffer-list of each frame. */
1723 frames_bury_buffer (buffer
)
1726 Lisp_Object frame
, tail
;
1728 FOR_EACH_FRAME (tail
, frame
)
1730 XFRAME (frame
)->buffer_list
1731 = nconc2 (Fdelq (buffer
, XFRAME (frame
)->buffer_list
),
1732 Fcons (buffer
, Qnil
));
1736 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1737 If the alist already has an element for PROP, we change it. */
1740 store_in_alist (alistptr
, prop
, val
)
1741 Lisp_Object
*alistptr
, val
;
1744 register Lisp_Object tem
;
1746 tem
= Fassq (prop
, *alistptr
);
1748 *alistptr
= Fcons (Fcons (prop
, val
), *alistptr
);
1754 store_frame_param (f
, prop
, val
)
1756 Lisp_Object prop
, val
;
1758 register Lisp_Object tem
;
1760 if (EQ (prop
, Qbuffer_list
))
1762 f
->buffer_list
= val
;
1766 tem
= Fassq (prop
, f
->param_alist
);
1768 f
->param_alist
= Fcons (Fcons (prop
, val
), f
->param_alist
);
1772 if (EQ (prop
, Qbuffer_predicate
))
1773 f
->buffer_predicate
= val
;
1775 if (! FRAME_WINDOW_P (f
))
1776 if (EQ (prop
, Qmenu_bar_lines
))
1777 set_menu_bar_lines (f
, val
, make_number (FRAME_MENU_BAR_LINES (f
)));
1779 if (EQ (prop
, Qminibuffer
) && WINDOWP (val
))
1781 if (! MINI_WINDOW_P (XWINDOW (val
)))
1782 error ("Surrogate minibuffer windows must be minibuffer windows.");
1784 if (FRAME_HAS_MINIBUF_P (f
) || FRAME_MINIBUF_ONLY_P (f
)
1785 && !EQ (val
, f
->minibuffer_window
))
1786 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
1788 /* Install the chosen minibuffer window, with proper buffer. */
1789 f
->minibuffer_window
= val
;
1793 DEFUN ("frame-parameters", Fframe_parameters
, Sframe_parameters
, 0, 1, 0,
1794 "Return the parameters-alist of frame FRAME.\n\
1795 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.\n\
1796 The meaningful PARMs depend on the kind of frame.\n\
1797 If FRAME is omitted, return information on the currently selected frame.")
1805 if (EQ (frame
, Qnil
))
1809 CHECK_FRAME (frame
, 0);
1813 if (!FRAME_LIVE_P (f
))
1816 alist
= Fcopy_alist (f
->param_alist
);
1818 if (FRAME_MSDOS_P (f
))
1820 static char *colornames
[16] =
1822 "black", "blue", "green", "cyan", "red", "magenta", "brown",
1823 "lightgray", "darkgray", "lightblue", "lightgreen", "lightcyan",
1824 "lightred", "lightmagenta", "yellow", "white"
1826 store_in_alist (&alist
, intern ("foreground-color"),
1827 build_string (colornames
[FRAME_FOREGROUND_PIXEL (f
)]));
1828 store_in_alist (&alist
, intern ("background-color"),
1829 build_string (colornames
[FRAME_BACKGROUND_PIXEL (f
)]));
1831 store_in_alist (&alist
, intern ("font"), build_string ("default"));
1833 store_in_alist (&alist
, Qname
, f
->name
);
1834 height
= (FRAME_NEW_HEIGHT (f
) ? FRAME_NEW_HEIGHT (f
) : FRAME_HEIGHT (f
));
1835 store_in_alist (&alist
, Qheight
, make_number (height
));
1836 width
= (FRAME_NEW_WIDTH (f
) ? FRAME_NEW_WIDTH (f
) : FRAME_WIDTH (f
));
1837 store_in_alist (&alist
, Qwidth
, make_number (width
));
1838 store_in_alist (&alist
, Qmodeline
, (FRAME_WANTS_MODELINE_P (f
) ? Qt
: Qnil
));
1839 store_in_alist (&alist
, Qminibuffer
,
1840 (! FRAME_HAS_MINIBUF_P (f
) ? Qnil
1841 : FRAME_MINIBUF_ONLY_P (f
) ? Qonly
1842 : FRAME_MINIBUF_WINDOW (f
)));
1843 store_in_alist (&alist
, Qunsplittable
, (FRAME_NO_SPLIT_P (f
) ? Qt
: Qnil
));
1844 store_in_alist (&alist
, Qbuffer_list
, frame_buffer_list ());
1846 /* I think this should be done with a hook. */
1847 #ifdef HAVE_WINDOW_SYSTEM
1848 if (FRAME_WINDOW_P (f
))
1849 x_report_frame_params (f
, &alist
);
1853 /* This ought to be correct in f->param_alist for an X frame. */
1855 XSETFASTINT (lines
, FRAME_MENU_BAR_LINES (f
));
1856 store_in_alist (&alist
, Qmenu_bar_lines
, lines
);
1861 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters
,
1862 Smodify_frame_parameters
, 2, 2, 0,
1863 "Modify the parameters of frame FRAME according to ALIST.\n\
1864 ALIST is an alist of parameters to change and their new values.\n\
1865 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.\n\
1866 The meaningful PARMs depend on the kind of frame.\n\
1867 Undefined PARMs are ignored, but stored in the frame's parameter list\n\
1868 so that `frame-parameters' will return them.")
1870 Lisp_Object frame
, alist
;
1873 register Lisp_Object tail
, elt
, prop
, val
;
1875 if (EQ (frame
, Qnil
))
1879 CHECK_LIVE_FRAME (frame
, 0);
1883 /* I think this should be done with a hook. */
1884 #ifdef HAVE_WINDOW_SYSTEM
1885 if (FRAME_WINDOW_P (f
))
1886 x_set_frame_parameters (f
, alist
);
1890 if (FRAME_MSDOS_P (f
))
1891 IT_set_frame_parameters (f
, alist
);
1895 int length
= XINT (Flength (alist
));
1898 = (Lisp_Object
*) alloca (length
* sizeof (Lisp_Object
));
1900 = (Lisp_Object
*) alloca (length
* sizeof (Lisp_Object
));
1902 /* Extract parm names and values into those vectors. */
1905 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
1907 Lisp_Object elt
, prop
, val
;
1910 parms
[i
] = Fcar (elt
);
1911 values
[i
] = Fcdr (elt
);
1915 /* Now process them in reverse of specified order. */
1916 for (i
--; i
>= 0; i
--)
1920 store_frame_param (f
, prop
, val
);
1927 DEFUN ("frame-char-height", Fframe_char_height
, Sframe_char_height
,
1929 "Height in pixels of a line in the font in frame FRAME.\n\
1930 If FRAME is omitted, the selected frame is used.\n\
1931 For a terminal frame, the value is always 1.")
1941 CHECK_FRAME (frame
, 0);
1945 #ifdef HAVE_WINDOW_SYSTEM
1946 if (FRAME_WINDOW_P (f
))
1947 return make_number (x_char_height (f
));
1950 return make_number (1);
1954 DEFUN ("frame-char-width", Fframe_char_width
, Sframe_char_width
,
1956 "Width in pixels of characters in the font in frame FRAME.\n\
1957 If FRAME is omitted, the selected frame is used.\n\
1958 The width is the same for all characters, because\n\
1959 currently Emacs supports only fixed-width fonts.\n\
1960 For a terminal screen, the value is always 1.")
1970 CHECK_FRAME (frame
, 0);
1974 #ifdef HAVE_WINDOW_SYSTEM
1975 if (FRAME_WINDOW_P (f
))
1976 return make_number (x_char_width (f
));
1979 return make_number (1);
1982 DEFUN ("frame-pixel-height", Fframe_pixel_height
,
1983 Sframe_pixel_height
, 0, 1, 0,
1984 "Return a FRAME's height in pixels.\n\
1985 For a terminal frame, the result really gives the height in characters.\n\
1986 If FRAME is omitted, the selected frame is used.")
1996 CHECK_FRAME (frame
, 0);
2000 #ifdef HAVE_WINDOW_SYSTEM
2001 if (FRAME_WINDOW_P (f
))
2002 return make_number (x_pixel_height (f
));
2005 return make_number (FRAME_HEIGHT (f
));
2008 DEFUN ("frame-pixel-width", Fframe_pixel_width
,
2009 Sframe_pixel_width
, 0, 1, 0,
2010 "Return FRAME's width in pixels.\n\
2011 For a terminal frame, the result really gives the width in characters.\n\
2012 If FRAME is omitted, the selected frame is used.")
2022 CHECK_FRAME (frame
, 0);
2026 #ifdef HAVE_WINDOW_SYSTEM
2027 if (FRAME_WINDOW_P (f
))
2028 return make_number (x_pixel_width (f
));
2031 return make_number (FRAME_WIDTH (f
));
2034 DEFUN ("set-frame-height", Fset_frame_height
, Sset_frame_height
, 2, 3, 0,
2035 "Specify that the frame FRAME has LINES lines.\n\
2036 Optional third arg non-nil means that redisplay should use LINES lines\n\
2037 but that the idea of the actual height of the frame should not be changed.")
2038 (frame
, lines
, pretend
)
2039 Lisp_Object frame
, lines
, pretend
;
2041 register struct frame
*f
;
2043 CHECK_NUMBER (lines
, 0);
2048 CHECK_LIVE_FRAME (frame
, 0);
2052 /* I think this should be done with a hook. */
2053 #ifdef HAVE_WINDOW_SYSTEM
2054 if (FRAME_WINDOW_P (f
))
2056 if (XINT (lines
) != f
->height
)
2057 x_set_window_size (f
, 1, f
->width
, XINT (lines
));
2061 change_frame_size (f
, XINT (lines
), 0, !NILP (pretend
), 0);
2065 DEFUN ("set-frame-width", Fset_frame_width
, Sset_frame_width
, 2, 3, 0,
2066 "Specify that the frame FRAME has COLS columns.\n\
2067 Optional third arg non-nil means that redisplay should use COLS columns\n\
2068 but that the idea of the actual width of the frame should not be changed.")
2069 (frame
, cols
, pretend
)
2070 Lisp_Object frame
, cols
, pretend
;
2072 register struct frame
*f
;
2073 CHECK_NUMBER (cols
, 0);
2078 CHECK_LIVE_FRAME (frame
, 0);
2082 /* I think this should be done with a hook. */
2083 #ifdef HAVE_WINDOW_SYSTEM
2084 if (FRAME_WINDOW_P (f
))
2086 if (XINT (cols
) != f
->width
)
2087 x_set_window_size (f
, 1, XINT (cols
), f
->height
);
2091 change_frame_size (f
, 0, XINT (cols
), !NILP (pretend
), 0);
2095 DEFUN ("set-frame-size", Fset_frame_size
, Sset_frame_size
, 3, 3, 0,
2096 "Sets size of FRAME to COLS by ROWS, measured in characters.")
2098 Lisp_Object frame
, cols
, rows
;
2100 register struct frame
*f
;
2103 CHECK_LIVE_FRAME (frame
, 0);
2104 CHECK_NUMBER (cols
, 2);
2105 CHECK_NUMBER (rows
, 1);
2108 /* I think this should be done with a hook. */
2109 #ifdef HAVE_WINDOW_SYSTEM
2110 if (FRAME_WINDOW_P (f
))
2112 if (XINT (rows
) != f
->height
|| XINT (cols
) != f
->width
2113 || FRAME_NEW_HEIGHT (f
) || FRAME_NEW_WIDTH (f
))
2114 x_set_window_size (f
, 1, XINT (cols
), XINT (rows
));
2118 change_frame_size (f
, XINT (rows
), XINT (cols
), 0, 0);
2123 DEFUN ("set-frame-position", Fset_frame_position
,
2124 Sset_frame_position
, 3, 3, 0,
2125 "Sets position of FRAME in pixels to XOFFSET by YOFFSET.\n\
2126 This is actually the position of the upper left corner of the frame.\n\
2127 Negative values for XOFFSET or YOFFSET are interpreted relative to\n\
2128 the rightmost or bottommost possible position (that stays within the screen).")
2129 (frame
, xoffset
, yoffset
)
2130 Lisp_Object frame
, xoffset
, yoffset
;
2132 register struct frame
*f
;
2135 CHECK_LIVE_FRAME (frame
, 0);
2136 CHECK_NUMBER (xoffset
, 1);
2137 CHECK_NUMBER (yoffset
, 2);
2140 /* I think this should be done with a hook. */
2141 #ifdef HAVE_WINDOW_SYSTEM
2142 if (FRAME_WINDOW_P (f
))
2143 x_set_offset (f
, XINT (xoffset
), XINT (yoffset
), 1);
2154 staticpro (&Vframe_list
);
2156 DEFVAR_LISP ("terminal-frame", &Vterminal_frame
,
2157 "The initial frame-object, which represents Emacs's stdout.");
2159 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified
,
2160 "Non-nil if all of emacs is iconified and frame updates are not needed.");
2161 Vemacs_iconified
= Qnil
;
2163 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame
,
2164 "Minibufferless frames use this frame's minibuffer.\n\
2166 Emacs cannot create minibufferless frames unless this is set to an\n\
2167 appropriate surrogate.\n\
2169 Emacs consults this variable only when creating minibufferless\n\
2170 frames; once the frame is created, it sticks with its assigned\n\
2171 minibuffer, no matter what this variable is set to. This means that\n\
2172 this variable doesn't necessarily say anything meaningful about the\n\
2173 current set of frames, or where the minibuffer is currently being\n\
2176 defsubr (&Sactive_minibuffer_window
);
2178 defsubr (&Sframe_live_p
);
2179 defsubr (&Smake_terminal_frame
);
2180 defsubr (&Shandle_switch_frame
);
2181 defsubr (&Signore_event
);
2182 defsubr (&Sselect_frame
);
2183 defsubr (&Sselected_frame
);
2184 defsubr (&Swindow_frame
);
2185 defsubr (&Sframe_root_window
);
2186 defsubr (&Sframe_first_window
);
2187 defsubr (&Sframe_selected_window
);
2188 defsubr (&Sset_frame_selected_window
);
2189 defsubr (&Sframe_list
);
2190 defsubr (&Snext_frame
);
2191 defsubr (&Sprevious_frame
);
2192 defsubr (&Sdelete_frame
);
2193 defsubr (&Smouse_position
);
2194 defsubr (&Smouse_pixel_position
);
2195 defsubr (&Sset_mouse_position
);
2196 defsubr (&Sset_mouse_pixel_position
);
2198 defsubr (&Sframe_configuration
);
2199 defsubr (&Srestore_frame_configuration
);
2201 defsubr (&Smake_frame_visible
);
2202 defsubr (&Smake_frame_invisible
);
2203 defsubr (&Siconify_frame
);
2204 defsubr (&Sframe_visible_p
);
2205 defsubr (&Svisible_frame_list
);
2206 defsubr (&Sraise_frame
);
2207 defsubr (&Slower_frame
);
2208 defsubr (&Sredirect_frame_focus
);
2209 defsubr (&Sframe_focus
);
2210 defsubr (&Sframe_parameters
);
2211 defsubr (&Smodify_frame_parameters
);
2212 defsubr (&Sframe_char_height
);
2213 defsubr (&Sframe_char_width
);
2214 defsubr (&Sframe_pixel_height
);
2215 defsubr (&Sframe_pixel_width
);
2216 defsubr (&Sset_frame_height
);
2217 defsubr (&Sset_frame_width
);
2218 defsubr (&Sset_frame_size
);
2219 defsubr (&Sset_frame_position
);
2224 initial_define_lispy_key (global_map
, "switch-frame", "handle-switch-frame");
2225 initial_define_lispy_key (global_map
, "delete-frame", "handle-delete-frame");
2226 initial_define_lispy_key (global_map
, "iconify-frame", "ignore-event");
2227 initial_define_lispy_key (global_map
, "make-frame-visible", "ignore-event");