1 /* Generic frame functions.
2 Copyright (C) 1989, 1992, 1993 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
30 #include "termhooks.h"
32 /* These help us bind and responding to switch-frame events. */
36 Lisp_Object Vemacs_iconified
;
37 Lisp_Object Vframe_list
;
38 Lisp_Object Vterminal_frame
;
39 Lisp_Object Vdefault_minibuffer_frame
;
40 Lisp_Object Vdefault_frame_alist
;
42 /* Evaluate this expression to rebuild the section of syms_of_frame
43 that initializes and staticpros the symbols declared below. Note
44 that Emacs 18 has a bug that keeps C-x C-e from being able to
45 evaluate this expression.
48 ;; Accumulate a list of the symbols we want to initialize from the
49 ;; declarations at the top of the file.
50 (goto-char (point-min))
51 (search-forward "/\*&&& symbols declared here &&&*\/\n")
53 (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
55 (cons (buffer-substring (match-beginning 1) (match-end 1))
58 (setq symbol-list (nreverse symbol-list))
59 ;; Delete the section of syms_of_... where we initialize the symbols.
60 (search-forward "\n /\*&&& init symbols here &&&*\/\n")
61 (let ((start (point)))
62 (while (looking-at "^ Q")
64 (kill-region start (point)))
65 ;; Write a new symbol initialization section.
67 (insert (format " %s = intern (\"" (car symbol-list)))
68 (let ((start (point)))
69 (insert (substring (car symbol-list) 1))
70 (subst-char-in-region start (point) ?_ ?-))
71 (insert (format "\");\n staticpro (&%s);\n" (car symbol-list)))
72 (setq symbol-list (cdr symbol-list)))))
75 /*&&& symbols declared here &&&*/
77 Lisp_Object Qframe_live_p
;
80 Lisp_Object Qminibuffer
;
81 Lisp_Object Qmodeline
;
84 Lisp_Object Qunsplittable
;
88 extern Lisp_Object Vminibuffer_list
;
89 extern Lisp_Object
get_minibuffer ();
91 DEFUN ("framep", Fframep
, Sframep
, 1, 1, 0,
92 "Return non-nil if OBJECT is a frame.\n\
93 Value is t for a termcap frame (a character-only terminal),\n\
94 `x' for an Emacs frame that is really an X window.\n\
95 Also see `live-frame-p'.")
99 if (XTYPE (object
) != Lisp_Frame
)
101 switch (XFRAME (object
)->output_method
)
105 case output_x_window
:
112 DEFUN ("frame-live-p", Fframe_live_p
, Sframe_live_p
, 1, 1, 0,
113 "Return non-nil if OBJECT is a frame which has not been deleted.\n\
114 Value is nil if OBJECT is not a live frame. If object is a live\n\
115 frame, the return value indicates what sort of output device it is\n\
116 displayed on. Value is t for a termcap frame (a character-only\n\
117 terminal), `x' for an Emacs frame being displayed in an X window.")
121 return ((FRAMEP (object
)
122 && FRAME_LIVE_P (XFRAME (object
)))
132 register struct frame
*f
;
133 register Lisp_Object root_window
;
134 register Lisp_Object mini_window
;
136 frame
= Fmake_vector (((sizeof (struct frame
) - (sizeof (Lisp_Vector
)
137 - sizeof (Lisp_Object
)))
138 / sizeof (Lisp_Object
)),
140 XSETTYPE (frame
, Lisp_Frame
);
145 f
->current_glyphs
= 0;
146 f
->desired_glyphs
= 0;
148 f
->async_visible
= 0;
149 f
->display
.nothing
= 0;
151 f
->async_iconified
= 0;
152 f
->wants_modeline
= 1;
157 f
->has_minibuffer
= mini_p
;
158 f
->focus_frame
= Qnil
;
159 f
->explicit_name
= 0;
160 f
->can_have_scroll_bars
= 0;
161 f
->has_vertical_scroll_bars
= 0;
162 f
->param_alist
= Qnil
;
163 f
->scroll_bars
= Qnil
;
164 f
->condemned_scroll_bars
= Qnil
;
166 root_window
= make_window ();
169 mini_window
= make_window ();
170 XWINDOW (root_window
)->next
= mini_window
;
171 XWINDOW (mini_window
)->prev
= root_window
;
172 XWINDOW (mini_window
)->mini_p
= Qt
;
173 XWINDOW (mini_window
)->frame
= frame
;
174 f
->minibuffer_window
= mini_window
;
179 XWINDOW (root_window
)->next
= Qnil
;
180 f
->minibuffer_window
= Qnil
;
183 XWINDOW (root_window
)->frame
= frame
;
186 just so that there is "something there."
187 Correct size will be set up later with change_frame_size. */
192 XFASTINT (XWINDOW (root_window
)->width
) = 10;
193 XFASTINT (XWINDOW (root_window
)->height
) = (mini_p
? 9 : 10);
197 XFASTINT (XWINDOW (mini_window
)->width
) = 10;
198 XFASTINT (XWINDOW (mini_window
)->top
) = 9;
199 XFASTINT (XWINDOW (mini_window
)->height
) = 1;
202 /* Choose a buffer for the frame's root window. */
206 XWINDOW (root_window
)->buffer
= Qt
;
207 buf
= Fcurrent_buffer ();
208 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
209 a space), try to find another one. */
210 if (XSTRING (Fbuffer_name (buf
))->data
[0] == ' ')
211 buf
= Fother_buffer (buf
, Qnil
);
212 Fset_window_buffer (root_window
, buf
);
217 XWINDOW (mini_window
)->buffer
= Qt
;
218 Fset_window_buffer (mini_window
,
219 (NILP (Vminibuffer_list
)
221 : Fcar (Vminibuffer_list
)));
224 f
->root_window
= root_window
;
225 f
->selected_window
= root_window
;
226 /* Make sure this window seems more recently used than
227 a newly-created, never-selected window. */
228 XFASTINT (XWINDOW (f
->selected_window
)->use_time
) = ++window_select_count
;
230 Vframe_list
= Fcons (frame
, Vframe_list
);
235 /* Make a frame using a separate minibuffer window on another frame.
236 MINI_WINDOW is the minibuffer window to use. nil means use the
237 default (the global minibuffer). */
240 make_frame_without_minibuffer (mini_window
)
241 register Lisp_Object mini_window
;
243 register struct frame
*f
;
245 /* Choose the minibuffer window to use. */
246 if (NILP (mini_window
))
248 if (XTYPE (Vdefault_minibuffer_frame
) != Lisp_Frame
)
249 error ("default-minibuffer-frame must be set when creating minibufferless frames");
250 if (! FRAME_LIVE_P (XFRAME (Vdefault_minibuffer_frame
)))
251 error ("default-minibuffer-frame must be a live frame");
252 mini_window
= XFRAME (Vdefault_minibuffer_frame
)->minibuffer_window
;
256 CHECK_LIVE_WINDOW (mini_window
, 0);
259 /* Make a frame containing just a root window. */
262 /* Install the chosen minibuffer window, with proper buffer. */
263 f
->minibuffer_window
= mini_window
;
264 Fset_window_buffer (mini_window
,
265 (NILP (Vminibuffer_list
)
267 : Fcar (Vminibuffer_list
)));
271 /* Make a frame containing only a minibuffer window. */
274 make_minibuffer_frame ()
276 /* First make a frame containing just a root window, no minibuffer. */
278 register struct frame
*f
= make_frame (0);
279 register Lisp_Object mini_window
;
280 register Lisp_Object frame
;
282 XSET (frame
, Lisp_Frame
, f
);
287 f
->wants_modeline
= 0;
288 f
->has_minibuffer
= 1;
290 /* Now label the root window as also being the minibuffer.
291 Avoid infinite looping on the window chain by marking next pointer
294 mini_window
= f
->minibuffer_window
= f
->root_window
;
295 XWINDOW (mini_window
)->mini_p
= Qt
;
296 XWINDOW (mini_window
)->next
= Qnil
;
297 XWINDOW (mini_window
)->prev
= Qnil
;
298 XWINDOW (mini_window
)->frame
= frame
;
300 /* Put the proper buffer in that window. */
302 Fset_window_buffer (mini_window
,
303 (NILP (Vminibuffer_list
)
305 : Fcar (Vminibuffer_list
)));
309 /* Construct a frame that refers to the terminal (stdin and stdout). */
312 make_terminal_frame ()
314 register struct frame
*f
;
318 f
->name
= build_string ("terminal");
319 FRAME_SET_VISIBLE (f
, 1);
320 f
->display
.nothing
= 1; /* Nonzero means frame isn't deleted. */
321 XSET (Vterminal_frame
, Lisp_Frame
, f
);
325 DEFUN ("select-frame", Fselect_frame
, Sselect_frame
, 1, 2, "e",
326 "Select the frame FRAME. FRAME's selected window becomes \"the\"\n\
327 selected window. If the optional parameter NO-ENTER is non-nil, don't\n\
328 focus on that frame.\n\
330 This function is interactive, and may be bound to the ``switch-frame''\n\
331 event; when invoked this way, it switches to the frame named in the\n\
332 event. When called from lisp, FRAME may be a ``switch-frame'' event;\n\
333 if it is, select the frame named in the event.\n\
335 Changing the selected frame can change focus redirections. See\n\
336 `redirect-frame-focus' for details.")
338 Lisp_Object frame
, no_enter
;
340 /* If FRAME is a switch-frame event, extract the frame we should
343 && EQ (XCONS (frame
)->car
, Qswitch_frame
)
344 && CONSP (XCONS (frame
)->cdr
))
345 frame
= XCONS (XCONS (frame
)->cdr
)->car
;
347 CHECK_LIVE_FRAME (frame
, 0);
349 if (selected_frame
== XFRAME (frame
))
352 /* If a frame's focus has been redirected toward the currently
353 selected frame, we should change the redirection to point to the
354 newly selected frame. This means that if the focus is redirected
355 from a minibufferless frame to a surrogate minibuffer frame, we
356 can use `other-window' to switch between all the frames using
357 that minibuffer frame, and the focus redirection will follow us
362 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
366 if (XTYPE (XCONS (tail
)->car
) != Lisp_Frame
)
369 focus
= FRAME_FOCUS_FRAME (XFRAME (XCONS (tail
)->car
));
371 if (XTYPE (focus
) == Lisp_Frame
372 && XFRAME (focus
) == selected_frame
)
373 Fredirect_frame_focus (XCONS (tail
)->car
, frame
);
377 selected_frame
= XFRAME (frame
);
378 if (! FRAME_MINIBUF_ONLY_P (selected_frame
))
379 last_nonminibuf_frame
= selected_frame
;
381 Fselect_window (XFRAME (frame
)->selected_window
);
383 /* I think this should be done with a hook. */
384 #ifdef HAVE_X_WINDOWS
385 if (FRAME_X_P (XFRAME (frame
))
388 Ffocus_frame (frame
);
391 choose_minibuf_frame ();
393 /* We want to make sure that the next event generates a frame-switch
394 event to the appropriate frame. This seems kludgey to me, but
395 before you take it out, make sure that evaluating something like
396 (select-window (frame-root-window (new-frame))) doesn't end up
397 with your typing being interpreted in the new frame instead of
398 the one you're actually typing in. */
399 internal_last_event_frame
= Qnil
;
404 DEFUN ("selected-frame", Fselected_frame
, Sselected_frame
, 0, 0, 0,
405 "Return the frame that is now selected.")
409 XSET (tem
, Lisp_Frame
, selected_frame
);
413 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 1, 1, 0,
414 "Return the frame object that window WINDOW is on.")
418 CHECK_LIVE_WINDOW (window
, 0);
419 return XWINDOW (window
)->frame
;
422 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
423 "Returns the root-window of FRAME.\n\
424 If omitted, FRAME defaults to the currently selected frame.")
429 XSET (frame
, Lisp_Frame
, selected_frame
);
431 CHECK_LIVE_FRAME (frame
, 0);
433 return XFRAME (frame
)->root_window
;
436 DEFUN ("frame-selected-window", Fframe_selected_window
,
437 Sframe_selected_window
, 0, 1, 0,
438 "Return the selected window of frame object FRAME.\n\
439 If omitted, FRAME defaults to the currently selected frame.")
444 XSET (frame
, Lisp_Frame
, selected_frame
);
446 CHECK_LIVE_FRAME (frame
, 0);
448 return XFRAME (frame
)->selected_window
;
451 DEFUN ("frame-list", Fframe_list
, Sframe_list
,
453 "Return a list of all frames.")
456 return Fcopy_sequence (Vframe_list
);
459 /* Return the next frame in the frame list after FRAME.
460 If MINIBUF is nil, exclude minibuffer-only frames.
461 If MINIBUF is a window, include only frames using that window for
463 If MINIBUF is non-nil, and not a window, include all frames. */
465 next_frame (frame
, minibuf
)
472 /* There must always be at least one frame in Vframe_list. */
473 if (! CONSP (Vframe_list
))
476 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
477 forever. Forestall that. */
478 CHECK_LIVE_FRAME (frame
, 0);
481 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
483 Lisp_Object f
= XCONS (tail
)->car
;
487 /* Decide whether this frame is eligible to be returned. */
489 /* If we've looped all the way around without finding any
490 eligible frames, return the original frame. */
494 /* Let minibuf decide if this frame is acceptable. */
497 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f
)))
500 else if (XTYPE (minibuf
) == Lisp_Window
)
502 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f
)), minibuf
))
514 /* Return the previous frame in the frame list before FRAME.
515 If MINIBUF is nil, exclude minibuffer-only frames.
516 If MINIBUF is a window, include only frames using that window for
518 If MINIBUF is non-nil and not a window, include all frames. */
520 prev_frame (frame
, minibuf
)
527 /* There must always be at least one frame in Vframe_list. */
528 if (! CONSP (Vframe_list
))
532 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
534 Lisp_Object f
= XCONS (tail
)->car
;
536 if (XTYPE (f
) != Lisp_Frame
)
539 if (EQ (frame
, f
) && !NILP (prev
))
542 /* Decide whether this frame is eligible to be returned,
543 according to minibuf. */
546 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f
)))
549 else if (XTYPE (minibuf
) == Lisp_Window
)
551 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f
)), minibuf
))
558 /* We've scanned the entire list. */
560 /* We went through the whole frame list without finding a single
561 acceptable frame. Return the original frame. */
564 /* There were no acceptable frames in the list before FRAME; otherwise,
565 we would have returned directly from the loop. Since PREV is the last
566 acceptable frame in the list, return it. */
570 DEFUN ("next-frame", Fnext_frame
, Snext_frame
, 0, 2, 0,
571 "Return the next frame in the frame list after FRAME.\n\
572 By default, skip minibuffer-only frames.\n\
573 If omitted, FRAME defaults to the selected frame.\n\
574 If optional argument MINIFRAME is non-nil, include minibuffer-only frames.\n\
575 If MINIFRAME is a window, include only frames using that window for their\n\
577 If MINIFRAME is non-nil and not a window, include all frames.")
579 Lisp_Object frame
, miniframe
;
584 XSET (frame
, Lisp_Frame
, selected_frame
);
586 CHECK_LIVE_FRAME (frame
, 0);
588 return next_frame (frame
, miniframe
);
592 DEFUN ("delete-frame", Fdelete_frame
, Sdelete_frame
, 0, 1, "",
593 "Delete FRAME, permanently eliminating it from use.\n\
594 If omitted, FRAME defaults to the selected frame.\n\
595 A frame may not be deleted if its minibuffer is used by other frames.")
601 if (EQ (frame
, Qnil
))
604 XSET (frame
, Lisp_Frame
, f
);
608 CHECK_FRAME (frame
, 0);
612 if (! FRAME_LIVE_P (f
))
615 /* Are there any other frames besides this one? */
616 if (f
== selected_frame
&& EQ (next_frame (frame
, Qt
), frame
))
617 error ("Attempt to delete the only frame");
619 /* Does this frame have a minibuffer, and is it the surrogate
620 minibuffer for any other frame? */
621 if (FRAME_HAS_MINIBUF_P (XFRAME (frame
)))
625 for (frames
= Vframe_list
;
627 frames
= XCONS (frames
)->cdr
)
629 Lisp_Object
this = XCONS (frames
)->car
;
631 if (! EQ (this, frame
)
635 (FRAME_MINIBUF_WINDOW
637 error ("Attempt to delete a surrogate minibuffer frame");
641 /* Don't let the frame remain selected. */
642 if (f
== selected_frame
)
643 Fselect_frame (next_frame (frame
, Qt
), Qnil
);
645 /* Don't allow minibuf_window to remain on a deleted frame. */
646 if (EQ (f
->minibuffer_window
, minibuf_window
))
648 Fset_window_buffer (selected_frame
->minibuffer_window
,
649 XWINDOW (minibuf_window
)->buffer
);
650 minibuf_window
= selected_frame
->minibuffer_window
;
653 /* Mark all the windows that used to be on FRAME as deleted, and then
654 remove the reference to them. */
655 delete_all_subwindows (XWINDOW (f
->root_window
));
656 f
->root_window
= Qnil
;
658 Vframe_list
= Fdelq (frame
, Vframe_list
);
659 FRAME_SET_VISIBLE (f
, 0);
661 /* Since some events are handled at the interrupt level, we may get
662 an event for f at any time; if we zero out the frame's display
663 now, then we may trip up the event-handling code. Instead, we'll
664 promise that the display of the frame must be valid until we have
665 called the window-system-dependent frame destruction routine. */
667 /* I think this should be done with a hook. */
668 #ifdef HAVE_X_WINDOWS
670 x_destroy_window (f
);
673 f
->display
.nothing
= 0;
675 /* If we've deleted the last_nonminibuf_frame, then try to find
677 if (f
== last_nonminibuf_frame
)
681 last_nonminibuf_frame
= 0;
683 for (frames
= Vframe_list
;
685 frames
= XCONS (frames
)->cdr
)
687 f
= XFRAME (XCONS (frames
)->car
);
688 if (!FRAME_MINIBUF_ONLY_P (f
))
690 last_nonminibuf_frame
= f
;
696 /* If we've deleted Vdefault_minibuffer_frame, try to find another
697 one. Prefer minibuffer-only frames, but also notice frames
698 with other windows. */
699 if (EQ (frame
, Vdefault_minibuffer_frame
))
703 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
704 Lisp_Object frame_with_minibuf
= Qnil
;
706 for (frames
= Vframe_list
;
708 frames
= XCONS (frames
)->cdr
)
710 Lisp_Object
this = XCONS (frames
)->car
;
712 if (XTYPE (this) != Lisp_Frame
)
716 if (FRAME_HAS_MINIBUF_P (f
))
718 frame_with_minibuf
= this;
719 if (FRAME_MINIBUF_ONLY_P (f
))
724 /* We know that there must be some frame with a minibuffer out
725 there. If this were not true, all of the frames present
726 would have to be minibufferless, which implies that at some
727 point their minibuffer frames must have been deleted, but
728 that is prohibited at the top; you can't delete surrogate
729 minibuffer frames. */
730 if (NILP (frame_with_minibuf
))
733 Vdefault_minibuffer_frame
= frame_with_minibuf
;
739 /* Return mouse position in character cell units. */
741 DEFUN ("mouse-position", Fmouse_position
, Smouse_position
, 0, 0, 0,
742 "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
743 If Emacs is running on a mouseless terminal or hasn't been programmed\n\
744 to read the mouse position, it returns the selected frame for FRAME\n\
745 and nil for X and Y.")
749 Lisp_Object lispy_dummy
;
750 enum scroll_bar_part party_dummy
;
752 unsigned long long_dummy
;
754 if (mouse_position_hook
)
755 (*mouse_position_hook
) (&f
,
756 &lispy_dummy
, &party_dummy
,
765 XSET (lispy_dummy
, Lisp_Frame
, f
);
766 return Fcons (lispy_dummy
, Fcons (make_number (x
), make_number (y
)));
769 DEFUN ("set-mouse-position", Fset_mouse_position
, Sset_mouse_position
, 3, 3, 0,
770 "Move the mouse pointer to the center of cell (X,Y) in FRAME.\n\
771 WARNING: If you use this under X, you should do `unfocus-frame' afterwards.")
773 Lisp_Object frame
, x
, y
;
775 CHECK_LIVE_FRAME (frame
, 0);
779 /* I think this should be done with a hook. */
780 #ifdef HAVE_X_WINDOWS
781 if (FRAME_X_P (XFRAME (frame
)))
782 /* Warping the mouse will cause enternotify and focus events. */
783 x_set_mouse_position (XFRAME (frame
), x
, y
);
790 /* ??? Can this be replaced with a Lisp function?
791 It is used in minibuf.c. Can we get rid of that?
792 Yes. All uses in minibuf.c are gone, and parallels to these
793 functions have been defined in frame.el. */
795 DEFUN ("frame-configuration", Fframe_configuration
, Sframe_configuration
,
797 "Return object describing current frame configuration.\n\
798 The frame configuration is the current mouse position and selected frame.\n\
799 This object can be given to `restore-frame-configuration'\n\
800 to restore this frame configuration.")
805 c
= Fmake_vector (make_number(4), Qnil
);
806 XVECTOR (c
)->contents
[0] = Fselected_frame();
807 if (mouse_position_hook
)
808 (*mouse_position_hook
) (&XVECTOR (c
)->contents
[1]
809 &XVECTOR (c
)->contents
[2],
810 &XVECTOR (c
)->contents
[3],
815 DEFUN ("restore-frame-configuration", Frestore_frame_configuration
,
816 Srestore_frame_configuration
,
818 "Restores frame configuration CONFIGURATION.")
822 Lisp_Object x_pos
, y_pos
, frame
;
824 CHECK_VECTOR (config
, 0);
825 if (XVECTOR (config
)->size
!= 3)
827 error ("Wrong size vector passed to restore-frame-configuration");
829 frame
= XVECTOR (config
)->contents
[0];
830 CHECK_LIVE_FRAME (frame
, 0);
832 Fselect_frame (frame
, Qnil
);
835 /* This seems to interfere with the frame selection mechanism. jla */
836 x_pos
= XVECTOR (config
)->contents
[2];
837 y_pos
= XVECTOR (config
)->contents
[3];
838 set_mouse_position (frame
, XINT (x_pos
), XINT (y_pos
));
845 DEFUN ("make-frame-visible", Fmake_frame_visible
, Smake_frame_visible
,
847 "Make the frame FRAME visible (assuming it is an X-window).\n\
848 Also raises the frame so that nothing obscures it.\n\
849 If omitted, FRAME defaults to the currently selected frame.")
854 XSET (frame
, Lisp_Frame
, selected_frame
);
856 CHECK_LIVE_FRAME (frame
, 0);
858 /* I think this should be done with a hook. */
859 #ifdef HAVE_X_WINDOWS
860 if (FRAME_X_P (XFRAME (frame
)))
861 x_make_frame_visible (XFRAME (frame
));
867 DEFUN ("make-frame-invisible", Fmake_frame_invisible
, Smake_frame_invisible
,
869 "Make the frame FRAME invisible (assuming it is an X-window).\n\
870 If omitted, FRAME defaults to the currently selected frame.")
875 XSET (frame
, Lisp_Frame
, selected_frame
);
877 CHECK_LIVE_FRAME (frame
, 0);
879 /* I think this should be done with a hook. */
880 #ifdef HAVE_X_WINDOWS
881 if (FRAME_X_P (XFRAME (frame
)))
882 x_make_frame_invisible (XFRAME (frame
));
888 DEFUN ("iconify-frame", Ficonify_frame
, Siconify_frame
,
890 "Make the frame FRAME into an icon.\n\
891 If omitted, FRAME defaults to the currently selected frame.")
896 XSET (frame
, Lisp_Frame
, selected_frame
);
898 CHECK_LIVE_FRAME (frame
, 0);
900 /* I think this should be done with a hook. */
901 #ifdef HAVE_X_WINDOWS
902 if (FRAME_X_P (XFRAME (frame
)))
903 x_iconify_frame (XFRAME (frame
));
909 DEFUN ("frame-visible-p", Fframe_visible_p
, Sframe_visible_p
,
911 "Return t if FRAME is now \"visible\" (actually in use for display).\n\
912 A frame that is not \"visible\" is not updated and, if it works through\n\
913 a window system, it may not show at all.\n\
914 Return the symbol `icon' if frame is visible only as an icon.")
918 CHECK_LIVE_FRAME (frame
, 0);
920 if (FRAME_VISIBLE_P (XFRAME (frame
)))
922 if (FRAME_ICONIFIED_P (XFRAME (frame
)))
927 DEFUN ("visible-frame-list", Fvisible_frame_list
, Svisible_frame_list
,
929 "Return a list of all frames now \"visible\" (being updated).")
932 Lisp_Object tail
, frame
;
937 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
939 frame
= XCONS (tail
)->car
;
940 if (XTYPE (frame
) != Lisp_Frame
)
943 if (FRAME_VISIBLE_P (f
))
944 value
= Fcons (frame
, value
);
950 DEFUN ("frame-to-front", Fframe_to_front
, Sframe_to_front
, 1, 1, 0,
951 "Bring FRAME to the front, so it occludes any frames it overlaps.\n\
952 If FRAME is invisible, make it visible.\n\
953 If Emacs is displaying on an ordinary terminal or some other device which\n\
954 doesn't support multiple overlapping frames, this function does nothing.")
958 CHECK_LIVE_FRAME (frame
, 0);
960 if (frame_raise_lower_hook
)
961 (*frame_raise_lower_hook
) (XFRAME (frame
), 1);
966 DEFUN ("frame-to-back", Fframe_to_back
, Sframe_to_back
, 1, 1, 0,
967 "Send FRAME to the back, so it is occluded by any frames that overlap it.\n\
968 If Emacs is displaying on an ordinary terminal or some other device which\n\
969 doesn't support multiple overlapping frames, this function does nothing.")
973 CHECK_LIVE_FRAME (frame
, 0);
975 if (frame_raise_lower_hook
)
976 (*frame_raise_lower_hook
) (XFRAME (frame
), 0);
982 DEFUN ("redirect-frame-focus", Fredirect_frame_focus
, Sredirect_frame_focus
,
984 "Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.\n\
985 In other words, switch-frame events caused by events in FRAME will\n\
986 request a switch to FOCUS-FRAME, and `last-event-frame' will be\n\
987 FOCUS-FRAME after reading an event typed at FRAME.\n\
989 If FOCUS-FRAME is omitted or nil, any existing redirection is\n\
990 cancelled, and the frame again receives its own keystrokes.\n\
992 Focus redirection is useful for temporarily redirecting keystrokes to\n\
993 a surrogate minibuffer frame when a frame doesn't have its own\n\
994 minibuffer window.\n\
996 A frame's focus redirection can be changed by select-frame. If frame\n\
997 FOO is selected, and then a different frame BAR is selected, any\n\
998 frames redirecting their focus to FOO are shifted to redirect their\n\
999 focus to BAR. This allows focus redirection to work properly when the\n\
1000 user switches from one frame to another using `select-window'.\n\
1002 This means that a frame whose focus is redirected to itself is treated\n\
1003 differently from a frame whose focus is redirected to nil; the former\n\
1004 is affected by select-frame, while the latter is not.\n\
1006 The redirection lasts until `redirect-frame-focus' is called to change it.")
1007 (frame
, focus_frame
)
1008 Lisp_Object frame
, focus_frame
;
1010 CHECK_LIVE_FRAME (frame
, 0);
1012 if (! NILP (focus_frame
))
1013 CHECK_LIVE_FRAME (focus_frame
, 1);
1015 XFRAME (frame
)->focus_frame
= focus_frame
;
1017 if (frame_rehighlight_hook
)
1018 (*frame_rehighlight_hook
) ();
1024 DEFUN ("frame-focus", Fframe_focus
, Sframe_focus
, 1, 1, 0,
1025 "Return the frame to which FRAME's keystrokes are currently being sent.\n\
1026 This returns nil if FRAME's focus is not redirected.\n\
1027 See `redirect-frame-focus'.")
1031 CHECK_LIVE_FRAME (frame
, 0);
1033 return FRAME_FOCUS_FRAME (XFRAME (frame
));
1039 get_frame_param (frame
, prop
)
1040 register struct frame
*frame
;
1043 register Lisp_Object tem
;
1045 tem
= Fassq (prop
, frame
->param_alist
);
1052 store_in_alist (alistptr
, prop
, val
)
1053 Lisp_Object
*alistptr
, val
;
1056 register Lisp_Object tem
;
1058 tem
= Fassq (prop
, *alistptr
);
1060 *alistptr
= Fcons (Fcons (prop
, val
), *alistptr
);
1066 store_frame_param (f
, prop
, val
)
1068 Lisp_Object prop
, val
;
1070 register Lisp_Object tem
;
1072 tem
= Fassq (prop
, f
->param_alist
);
1074 f
->param_alist
= Fcons (Fcons (prop
, val
), f
->param_alist
);
1078 if (EQ (prop
, Qminibuffer
)
1079 && XTYPE (val
) == Lisp_Window
)
1081 if (! MINI_WINDOW_P (XWINDOW (val
)))
1082 error ("Surrogate minibuffer windows must be minibuffer windows.");
1084 if (FRAME_HAS_MINIBUF_P (f
) || FRAME_MINIBUF_ONLY_P (f
))
1085 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer.");
1087 /* Install the chosen minibuffer window, with proper buffer. */
1088 f
->minibuffer_window
= val
;
1092 DEFUN ("frame-parameters", Fframe_parameters
, Sframe_parameters
, 0, 1, 0,
1093 "Return the parameters-alist of frame FRAME.\n\
1094 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.\n\
1095 The meaningful PARMs depend on the kind of frame.\n\
1096 If FRAME is omitted, return information on the currently selected frame.")
1103 if (EQ (frame
, Qnil
))
1107 CHECK_FRAME (frame
, 0);
1111 if (f
->display
.nothing
== 0)
1114 alist
= Fcopy_alist (f
->param_alist
);
1115 store_in_alist (&alist
, Qname
, f
->name
);
1116 store_in_alist (&alist
, Qheight
, make_number (f
->height
));
1117 store_in_alist (&alist
, Qwidth
, make_number (f
->width
));
1118 store_in_alist (&alist
, Qmodeline
, (f
->wants_modeline
? Qt
: Qnil
));
1119 store_in_alist (&alist
, Qminibuffer
,
1120 (! FRAME_HAS_MINIBUF_P (f
) ? Qnil
1121 : (FRAME_MINIBUF_ONLY_P (f
) ? Qonly
1122 : FRAME_MINIBUF_WINDOW (f
))));
1123 store_in_alist (&alist
, Qunsplittable
, (f
->no_split
? Qt
: Qnil
));
1125 /* I think this should be done with a hook. */
1126 #ifdef HAVE_X_WINDOWS
1128 x_report_frame_params (f
, &alist
);
1133 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters
,
1134 Smodify_frame_parameters
, 2, 2, 0,
1135 "Modify the parameters of frame FRAME according to ALIST.\n\
1136 ALIST is an alist of parameters to change and their new values.\n\
1137 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.\n\
1138 The meaningful PARMs depend on the kind of frame; undefined PARMs are ignored.")
1140 Lisp_Object frame
, alist
;
1143 register Lisp_Object tail
, elt
, prop
, val
;
1145 if (EQ (frame
, Qnil
))
1149 CHECK_LIVE_FRAME (frame
, 0);
1153 /* I think this should be done with a hook. */
1154 #ifdef HAVE_X_WINDOWS
1157 x_set_frame_parameters (f
, alist
);
1159 for (tail
= alist
; !EQ (tail
, Qnil
); tail
= Fcdr (tail
))
1164 x_set_frame_param (f
, prop
, val
, get_frame_param (f
, prop
));
1165 store_frame_param (f
, prop
, val
);
1175 /* This function isn't useful enough by itself to include; we need to
1176 add functions to allow the user to find the size of a font before
1177 this is actually useful. */
1179 DEFUN ("frame-pixel-size", Fframe_pixel_size
,
1180 Sframe_pixel_size
, 1, 1, 0,
1181 "Return a cons (width . height) of FRAME's size in pixels.")
1185 register struct frame
*f
;
1188 CHECK_LIVE_FRAME (frame
, 0);
1191 return Fcons (make_number (x_pixel_width (f
)),
1192 make_number (x_pixel_height (f
)));
1197 /* These functions have no C callers, and can be written nicely in lisp. */
1199 DEFUN ("frame-height", Fframe_height
, Sframe_height
, 0, 0, 0,
1200 "Return number of lines available for display on selected frame.")
1203 return make_number (FRAME_HEIGHT (selected_frame
));
1206 DEFUN ("frame-width", Fframe_width
, Sframe_width
, 0, 0, 0,
1207 "Return number of columns available for display on selected frame.")
1210 return make_number (FRAME_WIDTH (selected_frame
));
1214 DEFUN ("set-frame-height", Fset_frame_height
, Sset_frame_height
, 2, 3, 0,
1215 "Specify that the frame FRAME has LINES lines.\n\
1216 Optional third arg non-nil means that redisplay should use LINES lines\n\
1217 but that the idea of the actual height of the frame should not be changed.")
1218 (frame
, rows
, pretend
)
1219 Lisp_Object frame
, rows
, pretend
;
1221 register struct frame
*f
;
1223 CHECK_NUMBER (rows
, 0);
1228 CHECK_LIVE_FRAME (frame
, 0);
1232 /* I think this should be done with a hook. */
1233 #ifdef HAVE_X_WINDOWS
1236 if (XINT (rows
) != f
->width
)
1237 x_set_window_size (f
, f
->width
, XINT (rows
));
1241 change_frame_size (f
, XINT (rows
), 0, !NILP (pretend
), 0);
1245 DEFUN ("set-frame-width", Fset_frame_width
, Sset_frame_width
, 2, 3, 0,
1246 "Specify that the frame FRAME has COLS columns.\n\
1247 Optional third arg non-nil means that redisplay should use COLS columns\n\
1248 but that the idea of the actual width of the frame should not be changed.")
1249 (frame
, cols
, pretend
)
1250 Lisp_Object frame
, cols
, pretend
;
1252 register struct frame
*f
;
1253 CHECK_NUMBER (cols
, 0);
1258 CHECK_LIVE_FRAME (frame
, 0);
1262 /* I think this should be done with a hook. */
1263 #ifdef HAVE_X_WINDOWS
1266 if (XINT (cols
) != f
->width
)
1267 x_set_window_size (f
, XINT (cols
), f
->height
);
1271 change_frame_size (f
, 0, XINT (cols
), !NILP (pretend
), 0);
1275 DEFUN ("set-frame-size", Fset_frame_size
, Sset_frame_size
, 3, 3, 0,
1276 "Sets size of FRAME to COLS by ROWS, measured in characters.")
1278 Lisp_Object frame
, cols
, rows
;
1280 register struct frame
*f
;
1283 CHECK_LIVE_FRAME (frame
, 0);
1284 CHECK_NUMBER (cols
, 2);
1285 CHECK_NUMBER (rows
, 1);
1288 /* I think this should be done with a hook. */
1289 #ifdef HAVE_X_WINDOWS
1292 if (XINT (rows
) != f
->height
|| XINT (cols
) != f
->width
)
1293 x_set_window_size (f
, XINT (cols
), XINT (rows
));
1297 change_frame_size (f
, XINT (rows
), XINT (cols
), 0, 0);
1302 DEFUN ("set-frame-position", Fset_frame_position
,
1303 Sset_frame_position
, 3, 3, 0,
1304 "Sets position of FRAME in pixels to XOFFSET by YOFFSET.\n\
1305 If XOFFSET or YOFFSET are negative, they are interpreted relative to\n\
1306 the leftmost or bottommost position FRAME could occupy without going\n\
1308 (frame
, xoffset
, yoffset
)
1309 Lisp_Object frame
, xoffset
, yoffset
;
1311 register struct frame
*f
;
1314 CHECK_LIVE_FRAME (frame
, 0);
1315 CHECK_NUMBER (xoffset
, 1);
1316 CHECK_NUMBER (yoffset
, 2);
1319 /* I think this should be done with a hook. */
1320 #ifdef HAVE_X_WINDOWS
1322 x_set_offset (f
, XINT (xoffset
), XINT (yoffset
));
1330 DEFUN ("rubber-band-rectangle", Frubber_band_rectangle
, Srubber_band_rectangle
,
1332 "Ask user to specify a window position and size on FRAME with the mouse.\n\
1333 Arguments are FRAME, NAME and GEO. NAME is a name to be displayed as\n\
1334 the purpose of this rectangle. GEO is an X-windows size spec that can\n\
1335 specify defaults for some sizes/positions. If GEO specifies everything,\n\
1336 the mouse is not used.\n\
1337 Returns a list of five values: (FRAME LEFT TOP WIDTH HEIGHT).")
1344 Lisp_Object nums
[4];
1347 CHECK_FRAME (frame
, 0);
1348 CHECK_STRING (name
, 1);
1349 CHECK_STRING (geo
, 2);
1351 switch (XFRAME (frame
)->output_method
)
1353 case output_x_window
:
1354 x_rubber_band (XFRAME (frame
), &vals
[0], &vals
[1], &vals
[2], &vals
[3],
1355 XSTRING (geo
)->data
, XSTRING (name
)->data
);
1362 for (i
= 0; i
< 4; i
++)
1363 XFASTINT (nums
[i
]) = vals
[i
];
1364 return Fcons (frame
, Flist (4, nums
));
1367 #endif /* not HAVE_X11 */
1369 choose_minibuf_frame ()
1371 /* For lowest-level minibuf, put it on currently selected frame
1372 if frame has a minibuffer. */
1374 if (minibuf_level
== 0
1375 && selected_frame
!= 0
1376 && !EQ (minibuf_window
, selected_frame
->minibuffer_window
))
1378 /* I don't think that any frames may validly have a null minibuffer
1380 if (NILP (selected_frame
->minibuffer_window
))
1383 Fset_window_buffer (selected_frame
->minibuffer_window
,
1384 XWINDOW (minibuf_window
)->buffer
);
1385 minibuf_window
= selected_frame
->minibuffer_window
;
1391 /*&&& init symbols here &&&*/
1392 Qframep
= intern ("framep");
1393 staticpro (&Qframep
);
1394 Qframe_live_p
= intern ("frame-live-p");
1395 staticpro (&Qframe_live_p
);
1396 Qheight
= intern ("height");
1397 staticpro (&Qheight
);
1398 Qicon
= intern ("icon");
1400 Qminibuffer
= intern ("minibuffer");
1401 staticpro (&Qminibuffer
);
1402 Qmodeline
= intern ("modeline");
1403 staticpro (&Qmodeline
);
1404 Qname
= intern ("name");
1406 Qonly
= intern ("only");
1408 Qunsplittable
= intern ("unsplittable");
1409 staticpro (&Qunsplittable
);
1410 Qwidth
= intern ("width");
1411 staticpro (&Qwidth
);
1415 staticpro (&Vframe_list
);
1417 DEFVAR_LISP ("terminal-frame", &Vterminal_frame
,
1418 "The initial frame-object, which represents Emacs's stdout.");
1420 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified
,
1421 "Non-nil if all of emacs is iconified and frame updates are not needed.");
1422 Vemacs_iconified
= Qnil
;
1424 DEFVAR_LISP ("default-minibuffer-frame", &Vdefault_minibuffer_frame
,
1425 "Minibufferless frames use this frame's minibuffer.\n\
1427 Emacs cannot create minibufferless frames unless this is set to an\n\
1428 appropriate surrogate.\n\
1430 Emacs consults this variable only when creating minibufferless\n\
1431 frames; once the frame is created, it sticks with its assigned\n\
1432 minibuffer, no matter what this variable is set to. This means that\n\
1433 this variable doesn't necessarily say anything meaningful about the\n\
1434 current set of frames, or where the minibuffer is currently being\n\
1436 Vdefault_minibuffer_frame
= Qnil
;
1438 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist
,
1439 "Alist of default values for frame creation.\n\
1440 These may be set in your init file, like this:\n\
1441 (setq default-frame-alist '((width . 80) (height . 55)))\n\
1442 These override values given in window system configuration data, like\n\
1443 X Windows' defaults database.\n\
1444 For values specific to the first Emacs frame, see `initial-frame-alist'.\n\
1445 For values specific to the separate minibuffer frame, see\n\
1446 `minibuffer-frame-alist'.");
1447 Vdefault_frame_alist
= Qnil
;
1450 defsubr (&Sframe_live_p
);
1451 defsubr (&Sselect_frame
);
1452 defsubr (&Sselected_frame
);
1453 defsubr (&Swindow_frame
);
1454 defsubr (&Sframe_root_window
);
1455 defsubr (&Sframe_selected_window
);
1456 defsubr (&Sframe_list
);
1457 defsubr (&Snext_frame
);
1458 defsubr (&Sdelete_frame
);
1459 defsubr (&Smouse_position
);
1460 defsubr (&Sset_mouse_position
);
1462 defsubr (&Sframe_configuration
);
1463 defsubr (&Srestore_frame_configuration
);
1465 defsubr (&Smake_frame_visible
);
1466 defsubr (&Smake_frame_invisible
);
1467 defsubr (&Siconify_frame
);
1468 defsubr (&Sframe_visible_p
);
1469 defsubr (&Svisible_frame_list
);
1470 defsubr (&Sframe_to_front
);
1471 defsubr (&Sframe_to_back
);
1472 defsubr (&Sredirect_frame_focus
);
1473 defsubr (&Sframe_focus
);
1474 defsubr (&Sframe_parameters
);
1475 defsubr (&Smodify_frame_parameters
);
1477 defsubr (&Sframe_pixel_size
);
1478 defsubr (&Sframe_height
);
1479 defsubr (&Sframe_width
);
1481 defsubr (&Sset_frame_height
);
1482 defsubr (&Sset_frame_width
);
1483 defsubr (&Sset_frame_size
);
1484 defsubr (&Sset_frame_position
);
1486 defsubr (&Srubber_band_rectangle
);
1487 #endif /* HAVE_X11 */
1492 initial_define_lispy_key (global_map
, "switch-frame", "select-frame");
1495 #else /* not MULTI_FRAME */
1497 /* If we're not using multi-frame stuff, we still need to provide some
1498 support functions. */
1500 /* Unless this function is defined, providing set-frame-height and
1501 set-frame-width doesn't help compatibility any, since they both
1502 want this as their first argument. */
1503 DEFUN ("selected-frame", Fselected_frame
, Sselected_frame
, 0, 0, 0,
1504 "Return the frame that is now selected.")
1512 DEFUN ("set-frame-height", Fset_frame_height
, Sset_frame_height
, 2, 3, 0,
1513 "Specify that the frame FRAME has LINES lines.\n\
1514 Optional third arg non-nil means that redisplay should use LINES lines\n\
1515 but that the idea of the actual height of the frame should not be changed.")
1516 (frame
, rows
, pretend
)
1517 Lisp_Object frame
, rows
, pretend
;
1519 CHECK_NUMBER (rows
, 0);
1521 change_frame_size (0, XINT (rows
), 0, !NILP (pretend
), 0);
1525 DEFUN ("set-frame-width", Fset_frame_width
, Sset_frame_width
, 2, 3, 0,
1526 "Specify that the frame FRAME has COLS columns.\n\
1527 Optional third arg non-nil means that redisplay should use COLS columns\n\
1528 but that the idea of the actual width of the frame should not be changed.")
1529 (frame
, cols
, pretend
)
1530 Lisp_Object frame
, cols
, pretend
;
1532 CHECK_NUMBER (cols
, 0);
1534 change_frame_size (0, 0, XINT (cols
), !NILP (pretend
), 0);
1538 DEFUN ("set-frame-size", Fset_frame_size
, Sset_frame_size
, 3, 3, 0,
1539 "Sets size of FRAME to COLS by ROWS, measured in characters.")
1541 Lisp_Object frame
, cols
, rows
;
1543 CHECK_NUMBER (cols
, 2);
1544 CHECK_NUMBER (rows
, 1);
1546 change_frame_size (0, XINT (rows
), XINT (cols
), 0, 0);
1551 DEFUN ("frame-height", Fframe_height
, Sframe_height
, 0, 0, 0,
1552 "Return number of lines available for display on selected frame.")
1555 return make_number (FRAME_HEIGHT (selected_frame
));
1558 DEFUN ("frame-width", Fframe_width
, Sframe_width
, 0, 0, 0,
1559 "Return number of columns available for display on selected frame.")
1562 return make_number (FRAME_WIDTH (selected_frame
));
1565 /* These are for backward compatibility with Emacs 18. */
1567 DEFUN ("set-screen-height", Fset_screen_height
, Sset_screen_height
, 1, 2, 0,
1568 "Tell redisplay that the screen has LINES lines.\n\
1569 Optional second arg non-nil means that redisplay should use LINES lines\n\
1570 but that the idea of the actual height of the screen should not be changed.")
1572 Lisp_Object lines
, pretend
;
1574 CHECK_NUMBER (lines
, 0);
1576 change_frame_size (0, XINT (lines
), 0, !NILP (pretend
), 0);
1580 DEFUN ("set-screen-width", Fset_screen_width
, Sset_screen_width
, 1, 2, 0,
1581 "Tell redisplay that the screen has COLS columns.\n\
1582 Optional second arg non-nil means that redisplay should use COLS columns\n\
1583 but that the idea of the actual width of the screen should not be changed.")
1585 Lisp_Object cols
, pretend
;
1587 CHECK_NUMBER (cols
, 0);
1589 change_frame_size (0, 0, XINT (cols
), !NILP (pretend
), 0);
1595 defsubr (&Sset_frame_height
);
1596 defsubr (&Sset_frame_width
);
1597 defsubr (&Sset_frame_size
);
1598 defsubr (&Sset_screen_height
);
1599 defsubr (&Sset_screen_width
);
1600 defsubr (&Sframe_height
);
1601 Ffset (intern ("screen-height"), intern ("frame-height"));
1602 defsubr (&Sframe_width
);
1603 Ffset (intern ("screen-width"), intern ("frame-width"));
1610 #endif /* not MULTI_FRAME */