*** empty log message ***
[bpt/emacs.git] / src / frame.c
CommitLineData
ff11dfa1 1/* Generic frame functions.
beb0bc36 2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000 Free Software Foundation.
dc6f92b8
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
1113d9db 8the Free Software Foundation; either version 2, or (at your option)
dc6f92b8
JB
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
dc6f92b8 20
18160b98 21#include <config.h>
565620a5
RS
22
23#include <stdio.h>
cc38027b 24#include "lisp.h"
71025e5e 25#include "charset.h"
6d55d620 26#ifdef HAVE_X_WINDOWS
dfcf069d 27#include "xterm.h"
71025e5e 28#endif
8f23f280
AI
29#ifdef WINDOWSNT
30#include "w32term.h"
31#endif
cc38027b 32#include "frame.h"
a1dfb88a
KH
33#ifdef HAVE_WINDOW_SYSTEM
34#include "fontset.h"
35#endif
bc1ed486 36#include "termhooks.h"
dfcf069d 37#include "dispextern.h"
f769f1b2 38#include "window.h"
87485d6f
MW
39#ifdef MSDOS
40#include "msdos.h"
4aec4b29 41#include "dosfns.h"
87485d6f 42#endif
e5d77022 43
574a1a90
RS
44#ifdef macintosh
45extern struct mac_output *NewMacWindow ();
46extern void DisposeMacWindow (struct mac_output *);
47#endif
48
fd0c2bd1
JB
49/* Evaluate this expression to rebuild the section of syms_of_frame
50 that initializes and staticpros the symbols declared below. Note
51 that Emacs 18 has a bug that keeps C-x C-e from being able to
52 evaluate this expression.
53
54(progn
55 ;; Accumulate a list of the symbols we want to initialize from the
56 ;; declarations at the top of the file.
57 (goto-char (point-min))
58 (search-forward "/\*&&& symbols declared here &&&*\/\n")
59 (let (symbol-list)
60 (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
61 (setq symbol-list
62 (cons (buffer-substring (match-beginning 1) (match-end 1))
63 symbol-list))
64 (forward-line 1))
65 (setq symbol-list (nreverse symbol-list))
66 ;; Delete the section of syms_of_... where we initialize the symbols.
67 (search-forward "\n /\*&&& init symbols here &&&*\/\n")
68 (let ((start (point)))
69 (while (looking-at "^ Q")
70 (forward-line 2))
71 (kill-region start (point)))
72 ;; Write a new symbol initialization section.
73 (while symbol-list
74 (insert (format " %s = intern (\"" (car symbol-list)))
75 (let ((start (point)))
76 (insert (substring (car symbol-list) 1))
77 (subst-char-in-region start (point) ?_ ?-))
78 (insert (format "\");\n staticpro (&%s);\n" (car symbol-list)))
79 (setq symbol-list (cdr symbol-list)))))
80 */
81
82/*&&& symbols declared here &&&*/
83Lisp_Object Qframep;
dbc4e1c1 84Lisp_Object Qframe_live_p;
fd0c2bd1
JB
85Lisp_Object Qheight;
86Lisp_Object Qicon;
bc93c097 87Lisp_Object Qminibuffer;
fd0c2bd1
JB
88Lisp_Object Qmodeline;
89Lisp_Object Qname;
fd0c2bd1
JB
90Lisp_Object Qonly;
91Lisp_Object Qunsplittable;
fa8fdbf9 92Lisp_Object Qmenu_bar_lines;
9ea173e8 93Lisp_Object Qtool_bar_lines;
fd0c2bd1
JB
94Lisp_Object Qwidth;
95Lisp_Object Qx;
fbd6baed 96Lisp_Object Qw32;
bb221971 97Lisp_Object Qpc;
574a1a90 98Lisp_Object Qmac;
f7af3f7b 99Lisp_Object Qvisible;
329ca574 100Lisp_Object Qbuffer_predicate;
fa54c6ae 101Lisp_Object Qbuffer_list;
61eaa912 102Lisp_Object Qtitle;
dc6f92b8 103
a249de79 104Lisp_Object Vterminal_frame;
a1aaa23f 105Lisp_Object Vdefault_frame_alist;
beb0bc36 106Lisp_Object Vmouse_position_function;
a249de79
RS
107
108static void
109syms_of_frame_1 ()
110{
111 /*&&& init symbols here &&&*/
112 Qframep = intern ("framep");
113 staticpro (&Qframep);
114 Qframe_live_p = intern ("frame-live-p");
115 staticpro (&Qframe_live_p);
116 Qheight = intern ("height");
117 staticpro (&Qheight);
118 Qicon = intern ("icon");
119 staticpro (&Qicon);
120 Qminibuffer = intern ("minibuffer");
121 staticpro (&Qminibuffer);
122 Qmodeline = intern ("modeline");
123 staticpro (&Qmodeline);
124 Qname = intern ("name");
125 staticpro (&Qname);
126 Qonly = intern ("only");
127 staticpro (&Qonly);
128 Qunsplittable = intern ("unsplittable");
129 staticpro (&Qunsplittable);
130 Qmenu_bar_lines = intern ("menu-bar-lines");
131 staticpro (&Qmenu_bar_lines);
9ea173e8
GM
132 Qtool_bar_lines = intern ("tool-bar-lines");
133 staticpro (&Qtool_bar_lines);
a249de79
RS
134 Qwidth = intern ("width");
135 staticpro (&Qwidth);
136 Qx = intern ("x");
137 staticpro (&Qx);
fbd6baed
GV
138 Qw32 = intern ("w32");
139 staticpro (&Qw32);
bb221971
RS
140 Qpc = intern ("pc");
141 staticpro (&Qpc);
574a1a90
RS
142 Qmac = intern ("mac");
143 staticpro (&Qmac);
a249de79
RS
144 Qvisible = intern ("visible");
145 staticpro (&Qvisible);
146 Qbuffer_predicate = intern ("buffer-predicate");
147 staticpro (&Qbuffer_predicate);
fa54c6ae
RS
148 Qbuffer_list = intern ("buffer-list");
149 staticpro (&Qbuffer_list);
61eaa912
RS
150 Qtitle = intern ("title");
151 staticpro (&Qtitle);
e05169e2 152
a1aaa23f
RS
153 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
154 "Alist of default values for frame creation.\n\
155These may be set in your init file, like this:\n\
156 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1))\n\
157These override values given in window system configuration data,\n\
158 including X Windows' defaults database.\n\
159For values specific to the first Emacs frame, see `initial-frame-alist'.\n\
160For values specific to the separate minibuffer frame, see\n\
161 `minibuffer-frame-alist'.\n\
162The `menu-bar-lines' element of the list controls whether new frames\n\
163 have menu bars; `menu-bar-mode' works by altering this element.");
164 Vdefault_frame_alist = Qnil;
a249de79
RS
165}
166\f
167static void
168set_menu_bar_lines_1 (window, n)
169 Lisp_Object window;
170 int n;
171{
172 struct window *w = XWINDOW (window);
173
57aeea1e 174 XSETFASTINT (w->last_modified, 0);
a249de79
RS
175 XSETFASTINT (w->top, XFASTINT (w->top) + n);
176 XSETFASTINT (w->height, XFASTINT (w->height) - n);
4336c705
GM
177
178 if (INTEGERP (w->orig_top))
179 XSETFASTINT (w->orig_top, XFASTINT (w->orig_top) + n);
180 if (INTEGERP (w->orig_height))
181 XSETFASTINT (w->orig_height, XFASTINT (w->orig_height) - n);
a249de79
RS
182
183 /* Handle just the top child in a vertical split. */
184 if (!NILP (w->vchild))
185 set_menu_bar_lines_1 (w->vchild, n);
186
187 /* Adjust all children in a horizontal split. */
188 for (window = w->hchild; !NILP (window); window = w->next)
189 {
190 w = XWINDOW (window);
191 set_menu_bar_lines_1 (window, n);
192 }
193}
194
e48f782c 195void
a249de79
RS
196set_menu_bar_lines (f, value, oldval)
197 struct frame *f;
198 Lisp_Object value, oldval;
199{
200 int nlines;
201 int olines = FRAME_MENU_BAR_LINES (f);
202
203 /* Right now, menu bars don't work properly in minibuf-only frames;
204 most of the commands try to apply themselves to the minibuffer
e3678b64 205 frame itself, and get an error because you can't switch buffers
a249de79
RS
206 in or split the minibuffer window. */
207 if (FRAME_MINIBUF_ONLY_P (f))
208 return;
209
210 if (INTEGERP (value))
211 nlines = XINT (value);
212 else
213 nlines = 0;
214
57aeea1e
RS
215 if (nlines != olines)
216 {
217 windows_or_buffers_changed++;
218 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
219 FRAME_MENU_BAR_LINES (f) = nlines;
220 set_menu_bar_lines_1 (f->root_window, nlines - olines);
18082e2d 221 adjust_glyphs (f);
57aeea1e 222 }
a249de79
RS
223}
224\f
a249de79
RS
225#include "buffer.h"
226
227/* These help us bind and responding to switch-frame events. */
228#include "commands.h"
229#include "keyboard.h"
230
231Lisp_Object Vemacs_iconified;
232Lisp_Object Vframe_list;
a249de79 233
2d764c78
EZ
234struct x_output tty_display;
235
dc6f92b8
JB
236extern Lisp_Object Vminibuffer_list;
237extern Lisp_Object get_minibuffer ();
84386599
RS
238extern Lisp_Object Fhandle_switch_frame ();
239extern Lisp_Object Fredirect_frame_focus ();
a54d3a73 240extern Lisp_Object x_get_focus_frame ();
dc6f92b8 241\f
ff11dfa1
JB
242DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
243 "Return non-nil if OBJECT is a frame.\n\
244Value is t for a termcap frame (a character-only terminal),\n\
87485d6f 245`x' for an Emacs frame that is really an X window,\n\
2d764c78
EZ
246`w32' for an Emacs frame that is a window on MS-Windows display,\n\
247`mac' for an Emacs frame on a Macintosh display,\n\
87485d6f 248`pc' for a direct-write MS-DOS frame.\n\
e6b27a8f 249See also `frame-live-p'.")
f9898cc6
JB
250 (object)
251 Lisp_Object object;
dc6f92b8 252{
e35d291d 253 if (!FRAMEP (object))
dc6f92b8 254 return Qnil;
ff11dfa1 255 switch (XFRAME (object)->output_method)
dc6f92b8
JB
256 {
257 case output_termcap:
258 return Qt;
259 case output_x_window:
fd0c2bd1 260 return Qx;
fbd6baed
GV
261 case output_w32:
262 return Qw32;
bb221971
RS
263 case output_msdos_raw:
264 return Qpc;
574a1a90
RS
265 case output_mac:
266 return Qmac;
dc6f92b8
JB
267 default:
268 abort ();
269 }
270}
271
dbc4e1c1 272DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
ff11dfa1
JB
273 "Return non-nil if OBJECT is a frame which has not been deleted.\n\
274Value is nil if OBJECT is not a live frame. If object is a live\n\
275frame, the return value indicates what sort of output device it is\n\
276displayed on. Value is t for a termcap frame (a character-only\n\
277terminal), `x' for an Emacs frame being displayed in an X window.")
f9898cc6
JB
278 (object)
279 Lisp_Object object;
280{
ff11dfa1
JB
281 return ((FRAMEP (object)
282 && FRAME_LIVE_P (XFRAME (object)))
283 ? Fframep (object)
f9898cc6
JB
284 : Qnil);
285}
286
ff11dfa1
JB
287struct frame *
288make_frame (mini_p)
dc6f92b8
JB
289 int mini_p;
290{
ff11dfa1
JB
291 Lisp_Object frame;
292 register struct frame *f;
dc6f92b8
JB
293 register Lisp_Object root_window;
294 register Lisp_Object mini_window;
36af7d69
KH
295 register struct Lisp_Vector *vec;
296 int i;
297
298 vec = allocate_vectorlike ((EMACS_INT) VECSIZE (struct frame));
299 for (i = 0; i < VECSIZE (struct frame); i++)
300 XSETFASTINT (vec->contents[i], 0);
301 vec->size = VECSIZE (struct frame);
302 f = (struct frame *)vec;
303 XSETFRAME (frame, f);
ff11dfa1 304
18082e2d
GM
305 f->desired_matrix = 0;
306 f->current_matrix = 0;
307 f->desired_pool = 0;
308 f->current_pool = 0;
309 f->glyphs_initialized_p = 0;
310 f->decode_mode_spec_buffer = 0;
ff11dfa1 311 f->visible = 0;
323405de 312 f->async_visible = 0;
7556890b 313 f->output_data.nothing = 0;
ff11dfa1 314 f->iconified = 0;
323405de 315 f->async_iconified = 0;
ff11dfa1
JB
316 f->wants_modeline = 1;
317 f->auto_raise = 0;
318 f->auto_lower = 0;
319 f->no_split = 0;
10689a01 320 f->garbaged = 1;
ff11dfa1 321 f->has_minibuffer = mini_p;
a42e9724 322 f->focus_frame = Qnil;
804518aa 323 f->explicit_name = 0;
fd2777e0 324 f->can_have_scroll_bars = 0;
3a43d2dd 325 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
ff11dfa1 326 f->param_alist = Qnil;
fd2777e0
JB
327 f->scroll_bars = Qnil;
328 f->condemned_scroll_bars = Qnil;
306cc902 329 f->face_alist = Qnil;
18082e2d 330 f->face_cache = NULL;
9dd935ee 331 f->menu_bar_items = Qnil;
c8b8e7e3
RS
332 f->menu_bar_vector = Qnil;
333 f->menu_bar_items_used = 0;
329ca574 334 f->buffer_predicate = Qnil;
fa54c6ae 335 f->buffer_list = Qnil;
b4f0ee5d
KH
336#ifdef MULTI_KBOARD
337 f->kboard = initial_kboard;
338#endif
aec6e486 339 f->namebuf = 0;
2b1c9cfb 340 f->title = Qnil;
18082e2d 341 f->menu_bar_window = Qnil;
9ea173e8
GM
342 f->tool_bar_window = Qnil;
343 f->desired_tool_bar_items = f->current_tool_bar_items = Qnil;
344 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
345 f->n_desired_tool_bar_items = f->n_current_tool_bar_items = 0;
dc6f92b8 346
cc38027b 347 root_window = make_window ();
dc6f92b8
JB
348 if (mini_p)
349 {
cc38027b 350 mini_window = make_window ();
dc6f92b8
JB
351 XWINDOW (root_window)->next = mini_window;
352 XWINDOW (mini_window)->prev = root_window;
353 XWINDOW (mini_window)->mini_p = Qt;
ff11dfa1
JB
354 XWINDOW (mini_window)->frame = frame;
355 f->minibuffer_window = mini_window;
dc6f92b8
JB
356 }
357 else
358 {
359 mini_window = Qnil;
360 XWINDOW (root_window)->next = Qnil;
ff11dfa1 361 f->minibuffer_window = Qnil;
dc6f92b8
JB
362 }
363
ff11dfa1 364 XWINDOW (root_window)->frame = frame;
dc6f92b8
JB
365
366 /* 10 is arbitrary,
367 just so that there is "something there."
ff11dfa1 368 Correct size will be set up later with change_frame_size. */
dc6f92b8 369
3a43d2dd 370 SET_FRAME_WIDTH (f, 10);
ff11dfa1 371 f->height = 10;
dc6f92b8 372
f4e93c40
KH
373 XSETFASTINT (XWINDOW (root_window)->width, 10);
374 XSETFASTINT (XWINDOW (root_window)->height, (mini_p ? 9 : 10));
dc6f92b8
JB
375
376 if (mini_p)
377 {
f4e93c40
KH
378 XSETFASTINT (XWINDOW (mini_window)->width, 10);
379 XSETFASTINT (XWINDOW (mini_window)->top, 9);
380 XSETFASTINT (XWINDOW (mini_window)->height, 1);
dc6f92b8
JB
381 }
382
ff11dfa1 383 /* Choose a buffer for the frame's root window. */
5bce042c
JB
384 {
385 Lisp_Object buf;
386
387 XWINDOW (root_window)->buffer = Qt;
388 buf = Fcurrent_buffer ();
389 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
390 a space), try to find another one. */
391 if (XSTRING (Fbuffer_name (buf))->data[0] == ' ')
98ce1622 392 buf = Fother_buffer (buf, Qnil, Qnil);
fa54c6ae 393
18082e2d
GM
394 /* Use set_window_buffer, not Fset_window_buffer, and don't let
395 hooks be run by it. The reason is that the whole frame/window
396 arrangement is not yet fully intialized at this point. Windows
397 don't have the right size, glyph matrices aren't initialized
398 etc. Running Lisp functions at this point surely ends in a
399 SEGV. */
400 set_window_buffer (root_window, buf, 0);
fa54c6ae 401 f->buffer_list = Fcons (buf, Qnil);
5bce042c
JB
402 }
403
dc6f92b8
JB
404 if (mini_p)
405 {
406 XWINDOW (mini_window)->buffer = Qt;
18082e2d
GM
407 set_window_buffer (mini_window,
408 (NILP (Vminibuffer_list)
409 ? get_minibuffer (0)
410 : Fcar (Vminibuffer_list)),
411 0);
dc6f92b8
JB
412 }
413
ff11dfa1
JB
414 f->root_window = root_window;
415 f->selected_window = root_window;
d5e7c279
JB
416 /* Make sure this window seems more recently used than
417 a newly-created, never-selected window. */
f4e93c40 418 XSETFASTINT (XWINDOW (f->selected_window)->use_time, ++window_select_count);
dc6f92b8 419
ff11dfa1 420 return f;
dc6f92b8
JB
421}
422\f
bba88bb1 423#ifdef HAVE_WINDOW_SYSTEM
ff11dfa1 424/* Make a frame using a separate minibuffer window on another frame.
dc6f92b8
JB
425 MINI_WINDOW is the minibuffer window to use. nil means use the
426 default (the global minibuffer). */
427
ff11dfa1 428struct frame *
b0660239 429make_frame_without_minibuffer (mini_window, kb, display)
dc6f92b8 430 register Lisp_Object mini_window;
662ac59a 431 KBOARD *kb;
b0660239 432 Lisp_Object display;
dc6f92b8 433{
ff11dfa1 434 register struct frame *f;
363b873b 435 struct gcpro gcpro1;
dc6f92b8 436
b0660239
KH
437 if (!NILP (mini_window))
438 CHECK_LIVE_WINDOW (mini_window, 0);
dc6f92b8 439
662ac59a 440#ifdef MULTI_KBOARD
b0660239
KH
441 if (!NILP (mini_window)
442 && XFRAME (XWINDOW (mini_window)->frame)->kboard != kb)
662ac59a
KH
443 error ("frame and minibuffer must be on the same display");
444#endif
445
ff11dfa1
JB
446 /* Make a frame containing just a root window. */
447 f = make_frame (0);
dc6f92b8 448
b0660239
KH
449 if (NILP (mini_window))
450 {
451 /* Use default-minibuffer-frame if possible. */
452 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
453 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
454 {
363b873b
RS
455 Lisp_Object frame_dummy;
456
457 XSETFRAME (frame_dummy, f);
458 GCPRO1 (frame_dummy);
b0660239 459 /* If there's no minibuffer frame to use, create one. */
363b873b
RS
460 kb->Vdefault_minibuffer_frame =
461 call1 (intern ("make-initial-minibuffer-frame"), display);
462 UNGCPRO;
b0660239 463 }
363b873b 464
b0660239
KH
465 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
466 }
a2812a26 467
ff11dfa1 468 f->minibuffer_window = mini_window;
a2812a26
RS
469
470 /* Make the chosen minibuffer window display the proper minibuffer,
471 unless it is already showing a minibuffer. */
472 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
473 Fset_window_buffer (mini_window,
474 (NILP (Vminibuffer_list)
475 ? get_minibuffer (0)
476 : Fcar (Vminibuffer_list)));
ff11dfa1 477 return f;
dc6f92b8
JB
478}
479
ff11dfa1 480/* Make a frame containing only a minibuffer window. */
dc6f92b8 481
ff11dfa1
JB
482struct frame *
483make_minibuffer_frame ()
dc6f92b8 484{
ff11dfa1 485 /* First make a frame containing just a root window, no minibuffer. */
dc6f92b8 486
ff11dfa1 487 register struct frame *f = make_frame (0);
dc6f92b8 488 register Lisp_Object mini_window;
ff11dfa1 489 register Lisp_Object frame;
dc6f92b8 490
2d80a27a 491 XSETFRAME (frame, f);
dc6f92b8 492
804518aa 493 f->auto_raise = 0;
ff11dfa1
JB
494 f->auto_lower = 0;
495 f->no_split = 1;
496 f->wants_modeline = 0;
497 f->has_minibuffer = 1;
dc6f92b8
JB
498
499 /* Now label the root window as also being the minibuffer.
500 Avoid infinite looping on the window chain by marking next pointer
501 as nil. */
502
ff11dfa1 503 mini_window = f->minibuffer_window = f->root_window;
dc6f92b8
JB
504 XWINDOW (mini_window)->mini_p = Qt;
505 XWINDOW (mini_window)->next = Qnil;
804518aa 506 XWINDOW (mini_window)->prev = Qnil;
ff11dfa1 507 XWINDOW (mini_window)->frame = frame;
dc6f92b8
JB
508
509 /* Put the proper buffer in that window. */
510
511 Fset_window_buffer (mini_window,
265a9e55 512 (NILP (Vminibuffer_list)
dc6f92b8
JB
513 ? get_minibuffer (0)
514 : Fcar (Vminibuffer_list)));
ff11dfa1 515 return f;
dc6f92b8 516}
bba88bb1 517#endif /* HAVE_WINDOW_SYSTEM */
dc6f92b8 518\f
ff11dfa1 519/* Construct a frame that refers to the terminal (stdin and stdout). */
dc6f92b8 520
bb1513c9
RS
521static int terminal_frame_count;
522
ff11dfa1
JB
523struct frame *
524make_terminal_frame ()
dc6f92b8 525{
ff11dfa1 526 register struct frame *f;
d063751a 527 Lisp_Object frame;
bb1513c9
RS
528 char name[20];
529
b4f0ee5d
KH
530#ifdef MULTI_KBOARD
531 if (!initial_kboard)
532 {
533 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
534 init_kboard (initial_kboard);
a1b658dd
KH
535 initial_kboard->next_kboard = all_kboards;
536 all_kboards = initial_kboard;
b4f0ee5d
KH
537 }
538#endif
539
bb1513c9
RS
540 /* The first call must initialize Vframe_list. */
541 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
542 Vframe_list = Qnil;
ff11dfa1 543
ff11dfa1 544 f = make_frame (1);
d063751a 545
2d80a27a 546 XSETFRAME (frame, f);
d063751a
RS
547 Vframe_list = Fcons (frame, Vframe_list);
548
bb1513c9 549 terminal_frame_count++;
0303e8da
RS
550 sprintf (name, "F%d", terminal_frame_count);
551 f->name = build_string (name);
bb1513c9 552
bb1513c9
RS
553 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
554 f->async_visible = 1; /* Don't let visible be cleared later. */
bb221971
RS
555#ifdef MSDOS
556 f->output_data.x = &the_only_x_display;
2d764c78
EZ
557 if (!inhibit_window_system
558 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
559 || XFRAME (selected_frame)->output_method == output_msdos_raw))
560 f->output_method = output_msdos_raw;
561 else
562 f->output_method = output_termcap;
563#else
574a1a90
RS
564#ifdef macintosh
565 f->output_data.mac = NewMacWindow(f);
566 f->output_data.mac->background_pixel = 0xffffff;
567 f->output_data.mac->foreground_pixel = 0;
568 f->output_data.mac->n_param_faces = 0;
569 f->output_data.mac->n_computed_faces = 0;
570 f->output_data.mac->size_computed_faces = 0;
571 f->output_method = output_mac;
572 f->auto_raise = 1;
573 f->auto_lower = 1;
574 init_frame_faces (f);
2d764c78
EZ
575#else /* !macintosh */
576 f->output_data.x = &tty_display;
577#endif /* !macintosh */
578#endif /* MSDOS */
574a1a90 579
574a1a90 580#ifndef macintosh
1a6d3623
EZ
581 if (!noninteractive)
582 init_frame_faces (f);
2d764c78 583#endif
ff11dfa1 584 return f;
dc6f92b8 585}
bb1513c9
RS
586
587DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
4bc7e3ad
RS
588 1, 1, 0, "Create an additional terminal frame.\n\
589You can create multiple frames on a text-only terminal in this way.\n\
590Only the selected terminal frame is actually displayed.\n\
591This function takes one argument, an alist specifying frame parameters.\n\
592In practice, generally you don't need to specify any parameters.\n\
593Note that changing the size of one terminal frame automatically affects all.")
bb1513c9
RS
594 (parms)
595 Lisp_Object parms;
596{
597 struct frame *f;
574a1a90 598 Lisp_Object frame, tem;
8d2666fe 599 struct frame *sf = SELECTED_FRAME ();
bb1513c9 600
541580aa 601#ifdef MSDOS
2d764c78
EZ
602 if (sf->output_method != output_msdos_raw
603 && sf->output_method != output_termcap)
bb221971 604 abort ();
574a1a90
RS
605#else /* not MSDOS */
606
607#ifdef macintosh
8d2666fe 608 if (sf->output_method != output_mac)
574a1a90 609 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
bb221971 610#else
8d2666fe 611 if (sf->output_method != output_termcap)
bb1513c9 612 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
bb221971 613#endif
574a1a90 614#endif /* not MSDOS */
bb1513c9
RS
615
616 f = make_terminal_frame ();
574a1a90 617
8d2666fe
GM
618 change_frame_size (f, FRAME_HEIGHT (sf),
619 FRAME_WIDTH (sf), 0, 0, 0);
18082e2d 620 adjust_glyphs (f);
bb1513c9
RS
621 calculate_costs (f);
622 XSETFRAME (frame, f);
8adfc1ec 623 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
bb1513c9 624 Fmodify_frame_parameters (frame, parms);
87f1940e
EZ
625
626 /* Make the frame face alist be frame-specific, so that each
627 frame could change its face definitions independently. */
8d2666fe 628 f->face_alist = Fcopy_alist (sf->face_alist);
87f1940e
EZ
629 /* Simple Fcopy_alist isn't enough, because we need the contents of
630 the vectors which are the CDRs of associations in face_alist to
631 be copied as well. */
632 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
633 XCDR (XCAR (tem)) = Fcopy_sequence (XCDR (XCAR (tem)));
bb1513c9
RS
634 return frame;
635}
dc6f92b8 636\f
61f94483 637Lisp_Object
0aed85f4 638do_switch_frame (frame, no_enter, track)
ff11dfa1 639 Lisp_Object frame, no_enter;
0aed85f4 640 int track;
dc6f92b8 641{
8d2666fe
GM
642 struct frame *sf = SELECTED_FRAME ();
643
2f0b07e0
JB
644 /* If FRAME is a switch-frame event, extract the frame we should
645 switch to. */
646 if (CONSP (frame)
7539e11f
KR
647 && EQ (XCAR (frame), Qswitch_frame)
648 && CONSP (XCDR (frame)))
649 frame = XCAR (XCDR (frame));
2f0b07e0 650
09907c3a
KH
651 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
652 a switch-frame event to arrive after a frame is no longer live,
653 especially when deleting the initial frame during startup. */
654 CHECK_FRAME (frame, 0);
655 if (! FRAME_LIVE_P (XFRAME (frame)))
656 return Qnil;
dc6f92b8 657
8d2666fe 658 if (sf == XFRAME (frame))
ff11dfa1 659 return frame;
dc6f92b8 660
0aed85f4
KH
661 /* This is too greedy; it causes inappropriate focus redirection
662 that's hard to get rid of. */
663#if 0
a42e9724
JB
664 /* If a frame's focus has been redirected toward the currently
665 selected frame, we should change the redirection to point to the
666 newly selected frame. This means that if the focus is redirected
667 from a minibufferless frame to a surrogate minibuffer frame, we
668 can use `other-window' to switch between all the frames using
669 that minibuffer frame, and the focus redirection will follow us
670 around. */
0aed85f4
KH
671 if (track)
672 {
673 Lisp_Object tail;
a42e9724 674
7539e11f 675 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
0aed85f4
KH
676 {
677 Lisp_Object focus;
a42e9724 678
7539e11f 679 if (!FRAMEP (XCAR (tail)))
0aed85f4 680 abort ();
a42e9724 681
7539e11f 682 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
a42e9724 683
8d2666fe 684 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
7539e11f 685 Fredirect_frame_focus (XCAR (tail), frame);
0aed85f4
KH
686 }
687 }
688#else /* ! 0 */
689 /* Instead, apply it only to the frame we're pointing to. */
032d78fe
GV
690#ifdef HAVE_WINDOW_SYSTEM
691 if (track && (FRAME_WINDOW_P (XFRAME (frame))))
0aed85f4
KH
692 {
693 Lisp_Object focus, xfocus;
694
d7266360 695 xfocus = x_get_focus_frame (XFRAME (frame));
0aed85f4
KH
696 if (FRAMEP (xfocus))
697 {
698 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
8d2666fe 699 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
0aed85f4
KH
700 Fredirect_frame_focus (xfocus, frame);
701 }
702 }
703#endif /* HAVE_X_WINDOWS */
704#endif /* ! 0 */
a42e9724 705
8d2666fe
GM
706 selected_frame = frame;
707 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
708 last_nonminibuf_frame = XFRAME (selected_frame);
d5e7c279 709
ff11dfa1 710 Fselect_window (XFRAME (frame)->selected_window);
dc6f92b8 711
074577b8 712 /* We want to make sure that the next event generates a frame-switch
eb8c3be9 713 event to the appropriate frame. This seems kludgy to me, but
074577b8
JB
714 before you take it out, make sure that evaluating something like
715 (select-window (frame-root-window (new-frame))) doesn't end up
716 with your typing being interpreted in the new frame instead of
717 the one you're actually typing in. */
ef352596 718 internal_last_event_frame = Qnil;
074577b8 719
ff11dfa1 720 return frame;
dc6f92b8
JB
721}
722
0aed85f4
KH
723DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
724 "Select the frame FRAME.\n\
725Subsequent editing commands apply to its selected window.\n\
726The selection of FRAME lasts until the next time the user does\n\
727something to select a different frame, or until the next time this\n\
728function is called.")
729 (frame, no_enter)
730 Lisp_Object frame, no_enter;
731{
732 return do_switch_frame (frame, no_enter, 1);
733}
734
735
736DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 2, "e",
737 "Handle a switch-frame event EVENT.\n\
738Switch-frame events are usually bound to this function.\n\
739A switch-frame event tells Emacs that the window manager has requested\n\
740that the user's events be directed to the frame mentioned in the event.\n\
741This function selects the selected window of the frame of EVENT.\n\
742\n\
743If EVENT is frame object, handle it as if it were a switch-frame event\n\
744to that frame.")
735eeca3
EN
745 (event, no_enter)
746 Lisp_Object event, no_enter;
0aed85f4 747{
6951cd71
KH
748 /* Preserve prefix arg that the command loop just cleared. */
749 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
e05169e2 750 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
735eeca3 751 return do_switch_frame (event, no_enter, 0);
0aed85f4
KH
752}
753
1c212787
KH
754DEFUN ("ignore-event", Fignore_event, Signore_event, 0, 0, "",
755 "Do nothing, but preserve any prefix argument already specified.\n\
756This is a suitable binding for iconify-frame and make-frame-visible.")
757 ()
758{
759 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
760 return Qnil;
761}
0aed85f4 762
ff11dfa1
JB
763DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
764 "Return the frame that is now selected.")
dc6f92b8
JB
765 ()
766{
8d2666fe 767 return selected_frame;
dc6f92b8 768}
4a7cfafc 769\f
ff11dfa1
JB
770DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
771 "Return the frame object that window WINDOW is on.")
dc6f92b8
JB
772 (window)
773 Lisp_Object window;
774{
774910eb 775 CHECK_LIVE_WINDOW (window, 0);
ff11dfa1 776 return XWINDOW (window)->frame;
dc6f92b8
JB
777}
778
ba32f2db
KH
779DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
780 "Returns the topmost, leftmost window of FRAME.\n\
781If omitted, FRAME defaults to the currently selected frame.")
782 (frame)
783 Lisp_Object frame;
784{
785 Lisp_Object w;
786
787 if (NILP (frame))
8d2666fe 788 w = SELECTED_FRAME ()->root_window;
ba32f2db
KH
789 else
790 {
791 CHECK_LIVE_FRAME (frame, 0);
792 w = XFRAME (frame)->root_window;
793 }
794 while (NILP (XWINDOW (w)->buffer))
795 {
796 if (! NILP (XWINDOW (w)->hchild))
797 w = XWINDOW (w)->hchild;
798 else if (! NILP (XWINDOW (w)->vchild))
799 w = XWINDOW (w)->vchild;
800 else
801 abort ();
802 }
803 return w;
804}
805
5add3885
RS
806DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
807 Sactive_minibuffer_window, 0, 0, 0,
808 "Return the currently active minibuffer window, or nil if none.")
809 ()
810{
811 return minibuf_level ? minibuf_window : Qnil;
812}
813
ff11dfa1 814DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
8693ca83
JB
815 "Returns the root-window of FRAME.\n\
816If omitted, FRAME defaults to the currently selected frame.")
ff11dfa1
JB
817 (frame)
818 Lisp_Object frame;
dc6f92b8 819{
8d2666fe
GM
820 Lisp_Object window;
821
ff11dfa1 822 if (NILP (frame))
8d2666fe 823 window = SELECTED_FRAME ()->root_window;
f9898cc6 824 else
8d2666fe
GM
825 {
826 CHECK_LIVE_FRAME (frame, 0);
827 window = XFRAME (frame)->root_window;
828 }
829
830 return window;
dc6f92b8
JB
831}
832
ff11dfa1
JB
833DEFUN ("frame-selected-window", Fframe_selected_window,
834 Sframe_selected_window, 0, 1, 0,
8693ca83
JB
835 "Return the selected window of frame object FRAME.\n\
836If omitted, FRAME defaults to the currently selected frame.")
ff11dfa1
JB
837 (frame)
838 Lisp_Object frame;
dc6f92b8 839{
8d2666fe
GM
840 Lisp_Object window;
841
ff11dfa1 842 if (NILP (frame))
8d2666fe 843 window = SELECTED_FRAME ()->selected_window;
f9898cc6 844 else
8d2666fe
GM
845 {
846 CHECK_LIVE_FRAME (frame, 0);
847 window = XFRAME (frame)->selected_window;
848 }
dc6f92b8 849
8d2666fe 850 return window;
dc6f92b8
JB
851}
852
4a7cfafc
RS
853DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
854 Sset_frame_selected_window, 2, 2, 0,
855 "Set the selected window of frame object FRAME to WINDOW.\n\
856If FRAME is nil, the selected frame is used.\n\
857If FRAME is the selected frame, this makes WINDOW the selected window.")
858 (frame, window)
859 Lisp_Object frame, window;
860{
861 if (NILP (frame))
8d2666fe
GM
862 frame = selected_frame;
863
864 CHECK_LIVE_FRAME (frame, 0);
4a7cfafc
RS
865 CHECK_LIVE_WINDOW (window, 1);
866
867 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
868 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
869
8d2666fe 870 if (EQ (frame, selected_frame))
4a7cfafc
RS
871 return Fselect_window (window);
872
873 return XFRAME (frame)->selected_window = window;
874}
875\f
ff11dfa1 876DEFUN ("frame-list", Fframe_list, Sframe_list,
dc6f92b8 877 0, 0, 0,
ff11dfa1 878 "Return a list of all frames.")
dc6f92b8
JB
879 ()
880{
ff11dfa1 881 return Fcopy_sequence (Vframe_list);
dc6f92b8
JB
882}
883
ff11dfa1 884/* Return the next frame in the frame list after FRAME.
ff11dfa1 885 If MINIBUF is nil, exclude minibuffer-only frames.
a9986780
RS
886 If MINIBUF is a window, include only its own frame
887 and any frame now using that window as the minibuffer.
f7af3f7b 888 If MINIBUF is `visible', include all visible frames.
a9986780 889 If MINIBUF is 0, include all visible and iconified frames.
f7af3f7b
RS
890 Otherwise, include all frames. */
891
dc6f92b8 892Lisp_Object
ff11dfa1
JB
893next_frame (frame, minibuf)
894 Lisp_Object frame;
f9898cc6 895 Lisp_Object minibuf;
dc6f92b8
JB
896{
897 Lisp_Object tail;
898 int passed = 0;
899
ff11dfa1
JB
900 /* There must always be at least one frame in Vframe_list. */
901 if (! CONSP (Vframe_list))
f9898cc6
JB
902 abort ();
903
dbc4e1c1
JB
904 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
905 forever. Forestall that. */
906 CHECK_LIVE_FRAME (frame, 0);
907
dc6f92b8 908 while (1)
7539e11f 909 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
dc6f92b8 910 {
ab9f008d 911 Lisp_Object f;
d06a8a56 912
7539e11f 913 f = XCAR (tail);
06537cc8
RS
914
915 if (passed
916 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
d5e7c279 917 {
d06a8a56
JB
918 /* Decide whether this frame is eligible to be returned. */
919
920 /* If we've looped all the way around without finding any
921 eligible frames, return the original frame. */
922 if (EQ (f, frame))
923 return f;
924
925 /* Let minibuf decide if this frame is acceptable. */
926 if (NILP (minibuf))
927 {
928 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
929 return f;
930 }
f7af3f7b
RS
931 else if (EQ (minibuf, Qvisible))
932 {
933 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
934 if (FRAME_VISIBLE_P (XFRAME (f)))
935 return f;
936 }
a9986780
RS
937 else if (XFASTINT (minibuf) == 0)
938 {
939 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
940 if (FRAME_VISIBLE_P (XFRAME (f))
941 || FRAME_ICONIFIED_P (XFRAME (f)))
942 return f;
943 }
f7af3f7b 944 else if (WINDOWP (minibuf))
d06a8a56 945 {
a9986780
RS
946 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
947 /* Check that F either is, or has forwarded its focus to,
948 MINIBUF's frame. */
949 && (EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
950 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
951 FRAME_FOCUS_FRAME (XFRAME (f)))))
d06a8a56
JB
952 return f;
953 }
954 else
ff11dfa1 955 return f;
d5e7c279 956 }
dc6f92b8 957
d06a8a56 958 if (EQ (frame, f))
dc6f92b8
JB
959 passed++;
960 }
961}
962
ff11dfa1 963/* Return the previous frame in the frame list before FRAME.
ff11dfa1 964 If MINIBUF is nil, exclude minibuffer-only frames.
a9986780
RS
965 If MINIBUF is a window, include only its own frame
966 and any frame now using that window as the minibuffer.
f7af3f7b 967 If MINIBUF is `visible', include all visible frames.
a9986780 968 If MINIBUF is 0, include all visible and iconified frames.
f7af3f7b
RS
969 Otherwise, include all frames. */
970
dc6f92b8 971Lisp_Object
ff11dfa1
JB
972prev_frame (frame, minibuf)
973 Lisp_Object frame;
f9898cc6 974 Lisp_Object minibuf;
dc6f92b8
JB
975{
976 Lisp_Object tail;
977 Lisp_Object prev;
978
ff11dfa1
JB
979 /* There must always be at least one frame in Vframe_list. */
980 if (! CONSP (Vframe_list))
f9898cc6
JB
981 abort ();
982
dc6f92b8 983 prev = Qnil;
7539e11f 984 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
f9898cc6 985 {
ab9f008d 986 Lisp_Object f;
f9898cc6 987
7539e11f 988 f = XCAR (tail);
e35d291d 989 if (!FRAMEP (f))
d06a8a56 990 abort ();
f9898cc6 991
d06a8a56
JB
992 if (EQ (frame, f) && !NILP (prev))
993 return prev;
f9898cc6 994
06537cc8 995 if (FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
f7af3f7b 996 {
06537cc8
RS
997 /* Decide whether this frame is eligible to be returned,
998 according to minibuf. */
999 if (NILP (minibuf))
1000 {
1001 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1002 prev = f;
1003 }
1004 else if (WINDOWP (minibuf))
1005 {
1006 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1007 /* Check that F either is, or has forwarded its focus to,
1008 MINIBUF's frame. */
1009 && (EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1010 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1011 FRAME_FOCUS_FRAME (XFRAME (f)))))
1012 prev = f;
1013 }
1014 else if (EQ (minibuf, Qvisible))
1015 {
1016 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1017 if (FRAME_VISIBLE_P (XFRAME (f)))
1018 prev = f;
1019 }
1020 else if (XFASTINT (minibuf) == 0)
1021 {
1022 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1023 if (FRAME_VISIBLE_P (XFRAME (f))
1024 || FRAME_ICONIFIED_P (XFRAME (f)))
1025 prev = f;
1026 }
1027 else
a9986780
RS
1028 prev = f;
1029 }
f9898cc6 1030 }
d06a8a56
JB
1031
1032 /* We've scanned the entire list. */
1033 if (NILP (prev))
1034 /* We went through the whole frame list without finding a single
1035 acceptable frame. Return the original frame. */
1036 return frame;
1037 else
1038 /* There were no acceptable frames in the list before FRAME; otherwise,
1039 we would have returned directly from the loop. Since PREV is the last
1040 acceptable frame in the list, return it. */
1041 return prev;
dc6f92b8
JB
1042}
1043
ef2c57ac 1044
ff11dfa1
JB
1045DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1046 "Return the next frame in the frame list after FRAME.\n\
06537cc8 1047It considers only frames on the same terminal as FRAME.\n\
a42e9724 1048By default, skip minibuffer-only frames.\n\
d06a8a56 1049If omitted, FRAME defaults to the selected frame.\n\
c08c95c7 1050If optional argument MINIFRAME is nil, exclude minibuffer-only frames.\n\
06537cc8 1051If MINIFRAME is a window, include only its own frame\n\
a9986780 1052and any frame now using that window as the minibuffer.\n\
f7af3f7b 1053If MINIFRAME is `visible', include all visible frames.\n\
06537cc8 1054If MINIFRAME is 0, include all visible and iconified frames.\n\
f7af3f7b 1055Otherwise, include all frames.")
ff11dfa1 1056 (frame, miniframe)
8693ca83 1057 Lisp_Object frame, miniframe;
dc6f92b8 1058{
ff11dfa1 1059 if (NILP (frame))
8d2666fe
GM
1060 frame = selected_frame;
1061
1062 CHECK_LIVE_FRAME (frame, 0);
ff11dfa1 1063 return next_frame (frame, miniframe);
dc6f92b8 1064}
dbc4e1c1 1065
ef2c57ac
RM
1066DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1067 "Return the previous frame in the frame list before FRAME.\n\
06537cc8 1068It considers only frames on the same terminal as FRAME.\n\
ef2c57ac
RM
1069By default, skip minibuffer-only frames.\n\
1070If omitted, FRAME defaults to the selected frame.\n\
1071If optional argument MINIFRAME is nil, exclude minibuffer-only frames.\n\
06537cc8 1072If MINIFRAME is a window, include only its own frame\n\
a9986780 1073and any frame now using that window as the minibuffer.\n\
f7af3f7b 1074If MINIFRAME is `visible', include all visible frames.\n\
06537cc8 1075If MINIFRAME is 0, include all visible and iconified frames.\n\
f7af3f7b 1076Otherwise, include all frames.")
ef2c57ac
RM
1077 (frame, miniframe)
1078 Lisp_Object frame, miniframe;
1079{
ef2c57ac 1080 if (NILP (frame))
8d2666fe
GM
1081 frame = selected_frame;
1082 CHECK_LIVE_FRAME (frame, 0);
ef2c57ac
RM
1083 return prev_frame (frame, miniframe);
1084}
dc6f92b8 1085\f
808c0f20
RS
1086/* Return 1 if it is ok to delete frame F;
1087 0 if all frames aside from F are invisible.
1088 (Exception: if F is the terminal frame, and we are using X, return 1.) */
dc6f92b8 1089
d56b45eb 1090int
808c0f20
RS
1091other_visible_frames (f)
1092 FRAME_PTR f;
1093{
1094 /* We know the selected frame is visible,
1095 so if F is some other frame, it can't be the sole visible one. */
8d2666fe 1096 if (f == SELECTED_FRAME ())
c08c95c7
RS
1097 {
1098 Lisp_Object frames;
1099 int count = 0;
1100
1101 for (frames = Vframe_list;
1102 CONSP (frames);
7539e11f 1103 frames = XCDR (frames))
c08c95c7 1104 {
ab9f008d 1105 Lisp_Object this;
c08c95c7 1106
7539e11f 1107 this = XCAR (frames);
808c0f20
RS
1108 /* Verify that the frame's window still exists
1109 and we can still talk to it. And note any recent change
1110 in visibility. */
032d78fe
GV
1111#ifdef HAVE_WINDOW_SYSTEM
1112 if (FRAME_WINDOW_P (XFRAME (this)))
5e7b7c5b 1113 {
b0509a40 1114 x_sync (XFRAME (this));
5e7b7c5b
RS
1115 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1116 }
1117#endif
1118
c08c95c7
RS
1119 if (FRAME_VISIBLE_P (XFRAME (this))
1120 || FRAME_ICONIFIED_P (XFRAME (this))
1121 /* Allow deleting the terminal frame when at least
1122 one X frame exists! */
032d78fe 1123 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
c08c95c7
RS
1124 count++;
1125 }
808c0f20 1126 return count > 1;
c08c95c7 1127 }
808c0f20
RS
1128 return 1;
1129}
1130
1131DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1132 "Delete FRAME, permanently eliminating it from use.\n\
1133If omitted, FRAME defaults to the selected frame.\n\
1134A frame may not be deleted if its minibuffer is used by other frames.\n\
1135Normally, you may not delete a frame if all other frames are invisible,\n\
1136but if the second optional argument FORCE is non-nil, you may do so.")
1137 (frame, force)
1138 Lisp_Object frame, force;
1139{
1140 struct frame *f;
8d2666fe 1141 struct frame *sf = SELECTED_FRAME ();
99b92e64 1142 int minibuffer_selected;
808c0f20
RS
1143
1144 if (EQ (frame, Qnil))
1145 {
8d2666fe 1146 f = sf;
2d80a27a 1147 XSETFRAME (frame, f);
808c0f20
RS
1148 }
1149 else
1150 {
1151 CHECK_FRAME (frame, 0);
1152 f = XFRAME (frame);
1153 }
1154
1155 if (! FRAME_LIVE_P (f))
1156 return Qnil;
1157
1158 if (NILP (force) && !other_visible_frames (f))
1159 error ("Attempt to delete the sole visible or iconified frame");
d5e7c279 1160
00c5fd51
RS
1161#if 0
1162 /* This is a nice idea, but x_connection_closed needs to be able
1163 to delete the last frame, if it is gone. */
7539e11f 1164 if (NILP (XCDR (Vframe_list)))
e9687ee8 1165 error ("Attempt to delete the only frame");
00c5fd51 1166#endif
e9687ee8 1167
ff11dfa1
JB
1168 /* Does this frame have a minibuffer, and is it the surrogate
1169 minibuffer for any other frame? */
fd0c2bd1 1170 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
dc6f92b8 1171 {
ff11dfa1 1172 Lisp_Object frames;
1113d9db 1173
ff11dfa1
JB
1174 for (frames = Vframe_list;
1175 CONSP (frames);
7539e11f 1176 frames = XCDR (frames))
1113d9db 1177 {
7a8cc307 1178 Lisp_Object this;
7539e11f 1179 this = XCAR (frames);
1113d9db 1180
ff11dfa1
JB
1181 if (! EQ (this, frame)
1182 && EQ (frame,
7a8cc307
RS
1183 WINDOW_FRAME (XWINDOW
1184 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
ff11dfa1 1185 error ("Attempt to delete a surrogate minibuffer frame");
1113d9db 1186 }
dc6f92b8
JB
1187 }
1188
99b92e64
RS
1189 minibuffer_selected = EQ (minibuf_window, selected_window);
1190
ff11dfa1 1191 /* Don't let the frame remain selected. */
8d2666fe 1192 if (f == sf)
06537cc8
RS
1193 {
1194 Lisp_Object tail, frame1;
1195
1196 /* Look for another visible frame on the same terminal. */
1197 frame1 = next_frame (frame, Qvisible);
1198
1199 /* If there is none, find *some* other frame. */
1200 if (NILP (frame1) || EQ (frame1, frame))
1201 {
1202 FOR_EACH_FRAME (tail, frame1)
1203 {
1204 if (! EQ (frame, frame1))
1205 break;
1206 }
1207 }
1208
1209 do_switch_frame (frame1, Qnil, 0);
79a65b7f 1210 sf = SELECTED_FRAME ();
06537cc8 1211 }
dc6f92b8 1212
ff11dfa1
JB
1213 /* Don't allow minibuf_window to remain on a deleted frame. */
1214 if (EQ (f->minibuffer_window, minibuf_window))
dc6f92b8 1215 {
8d2666fe 1216 Fset_window_buffer (sf->minibuffer_window,
dc6f92b8 1217 XWINDOW (minibuf_window)->buffer);
8d2666fe 1218 minibuf_window = sf->minibuffer_window;
99b92e64
RS
1219
1220 /* If the dying minibuffer window was selected,
1221 select the new one. */
1222 if (minibuffer_selected)
1223 Fselect_window (minibuf_window);
dc6f92b8
JB
1224 }
1225
130adcb7
EZ
1226 /* Don't let echo_area_window to remain on a deleted frame. */
1227 if (EQ (f->minibuffer_window, echo_area_window))
1228 echo_area_window = sf->minibuffer_window;
1229
bb2a0a65
RS
1230 /* Clear any X selections for this frame. */
1231#ifdef HAVE_X_WINDOWS
1232 if (FRAME_X_P (f))
1233 x_clear_frame_selections (f);
1234#endif
1235
18082e2d
GM
1236 /* Free glyphs.
1237 This function must be called before the window tree of the
1238 frame is deleted because windows contain dynamically allocated
1239 memory. */
1240 free_glyphs (f);
1241
4a88b3b0
JB
1242 /* Mark all the windows that used to be on FRAME as deleted, and then
1243 remove the reference to them. */
1244 delete_all_subwindows (XWINDOW (f->root_window));
1245 f->root_window = Qnil;
1246
ff11dfa1 1247 Vframe_list = Fdelq (frame, Vframe_list);
a42e9724 1248 FRAME_SET_VISIBLE (f, 0);
dc6f92b8 1249
60a8823e 1250 if (f->namebuf)
18082e2d 1251 xfree (f->namebuf);
d2bee99e 1252 if (FRAME_INSERT_COST (f))
18082e2d 1253 xfree (FRAME_INSERT_COST (f));
d2bee99e 1254 if (FRAME_DELETEN_COST (f))
18082e2d 1255 xfree (FRAME_DELETEN_COST (f));
d2bee99e 1256 if (FRAME_INSERTN_COST (f))
18082e2d 1257 xfree (FRAME_INSERTN_COST (f));
d2bee99e 1258 if (FRAME_DELETE_COST (f))
18082e2d 1259 xfree (FRAME_DELETE_COST (f));
25734faf 1260 if (FRAME_MESSAGE_BUF (f))
18082e2d 1261 xfree (FRAME_MESSAGE_BUF (f));
d2bee99e 1262
8678b9cc
JB
1263 /* Since some events are handled at the interrupt level, we may get
1264 an event for f at any time; if we zero out the frame's display
1265 now, then we may trip up the event-handling code. Instead, we'll
1266 promise that the display of the frame must be valid until we have
1267 called the window-system-dependent frame destruction routine. */
dbc4e1c1
JB
1268
1269 /* I think this should be done with a hook. */
032d78fe
GV
1270#ifdef HAVE_WINDOW_SYSTEM
1271 if (FRAME_WINDOW_P (f))
8678b9cc 1272 x_destroy_window (f);
d5e7c279
JB
1273#endif
1274
574a1a90
RS
1275/* Done by x_destroy_window above already */
1276#if 0
1277#ifdef macintosh
1278 if (FRAME_MAC_P (f))
1279 DisposeMacWindow (f->output_data.mac);
1280#endif
1281#endif
1282
7556890b 1283 f->output_data.nothing = 0;
8678b9cc 1284
ff11dfa1 1285 /* If we've deleted the last_nonminibuf_frame, then try to find
d5e7c279 1286 another one. */
ff11dfa1 1287 if (f == last_nonminibuf_frame)
d5e7c279 1288 {
ff11dfa1 1289 Lisp_Object frames;
1113d9db 1290
ff11dfa1 1291 last_nonminibuf_frame = 0;
d5e7c279 1292
ff11dfa1
JB
1293 for (frames = Vframe_list;
1294 CONSP (frames);
7539e11f 1295 frames = XCDR (frames))
d5e7c279 1296 {
7539e11f 1297 f = XFRAME (XCAR (frames));
ff11dfa1 1298 if (!FRAME_MINIBUF_ONLY_P (f))
d5e7c279 1299 {
ff11dfa1 1300 last_nonminibuf_frame = f;
d5e7c279
JB
1301 break;
1302 }
1303 }
1304 }
dc6f92b8 1305
c4c6d073
KH
1306 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1307 find another one. Prefer minibuffer-only frames, but also notice
1308 frames with other windows. */
c60f3a6a 1309 if (EQ (frame, FRAME_KBOARD (f)->Vdefault_minibuffer_frame))
1113d9db 1310 {
ff11dfa1 1311 Lisp_Object frames;
1113d9db 1312
ff11dfa1 1313 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
ab9f008d 1314 Lisp_Object frame_with_minibuf;
32fda9ba
RS
1315 /* Some frame we found on the same kboard, or nil if there are none. */
1316 Lisp_Object frame_on_same_kboard;
1113d9db 1317
32fda9ba 1318 frame_on_same_kboard = Qnil;
ab9f008d 1319 frame_with_minibuf = Qnil;
32fda9ba 1320
ff11dfa1
JB
1321 for (frames = Vframe_list;
1322 CONSP (frames);
7539e11f 1323 frames = XCDR (frames))
1113d9db 1324 {
ab9f008d 1325 Lisp_Object this;
c4c6d073 1326 struct frame *f1;
1113d9db 1327
7539e11f 1328 this = XCAR (frames);
e35d291d 1329 if (!FRAMEP (this))
1113d9db 1330 abort ();
c4c6d073 1331 f1 = XFRAME (this);
1113d9db 1332
c4c6d073
KH
1333 /* Consider only frames on the same kboard
1334 and only those with minibuffers. */
1335 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)
1336 && FRAME_HAS_MINIBUF_P (f1))
1113d9db 1337 {
ff11dfa1 1338 frame_with_minibuf = this;
c4c6d073 1339 if (FRAME_MINIBUF_ONLY_P (f1))
1113d9db
JB
1340 break;
1341 }
32fda9ba
RS
1342
1343 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1))
1344 frame_on_same_kboard = this;
1113d9db
JB
1345 }
1346
32fda9ba
RS
1347 if (!NILP (frame_on_same_kboard))
1348 {
1349 /* We know that there must be some frame with a minibuffer out
1350 there. If this were not true, all of the frames present
1351 would have to be minibufferless, which implies that at some
1352 point their minibuffer frames must have been deleted, but
1353 that is prohibited at the top; you can't delete surrogate
1354 minibuffer frames. */
1355 if (NILP (frame_with_minibuf))
1356 abort ();
1113d9db 1357
32fda9ba
RS
1358 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = frame_with_minibuf;
1359 }
1360 else
1361 /* No frames left on this kboard--say no minibuffer either. */
1362 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = Qnil;
1113d9db
JB
1363 }
1364
e681c92a
RS
1365 /* Cause frame titles to update--necessary if we now have just one frame. */
1366 update_mode_lines = 1;
1367
dc6f92b8
JB
1368 return Qnil;
1369}
1370\f
1371/* Return mouse position in character cell units. */
1372
f9898cc6 1373DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
ff11dfa1 1374 "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
4f90516b
JB
1375The position is given in character cells, where (0, 0) is the\n\
1376upper-left corner.\n\
f9898cc6 1377If Emacs is running on a mouseless terminal or hasn't been programmed\n\
ff11dfa1 1378to read the mouse position, it returns the selected frame for FRAME\n\
beb0bc36
DL
1379and nil for X and Y.\n\
1380Runs the abnormal hook `mouse-position-function' with the normal return\n\
1381value as argument.")
f9898cc6 1382 ()
dc6f92b8 1383{
ff11dfa1 1384 FRAME_PTR f;
dbc4e1c1 1385 Lisp_Object lispy_dummy;
fd2777e0 1386 enum scroll_bar_part party_dummy;
beb0bc36 1387 Lisp_Object x, y, retval;
5384466a 1388 int col, row;
dbc4e1c1 1389 unsigned long long_dummy;
cb2255b3 1390 struct gcpro gcpro1;
dc6f92b8 1391
8d2666fe 1392 f = SELECTED_FRAME ();
c5074d8c
RS
1393 x = y = Qnil;
1394
f443c170 1395#ifdef HAVE_MOUSE
c5074d8c 1396 /* It's okay for the hook to refrain from storing anything. */
f9898cc6 1397 if (mouse_position_hook)
66e827dc 1398 (*mouse_position_hook) (&f, -1,
dbc4e1c1
JB
1399 &lispy_dummy, &party_dummy,
1400 &x, &y,
1401 &long_dummy);
76db7eb4
KH
1402 if (! NILP (x))
1403 {
1404 col = XINT (x);
1405 row = XINT (y);
8126c3b4 1406 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
76db7eb4
KH
1407 XSETINT (x, col);
1408 XSETINT (y, row);
1409 }
f443c170 1410#endif
2d80a27a 1411 XSETFRAME (lispy_dummy, f);
beb0bc36 1412 retval = Fcons (lispy_dummy, Fcons (x, y));
cb2255b3 1413 GCPRO1 (retval);
beb0bc36 1414 if (!NILP (Vmouse_position_function))
cb2255b3
GM
1415 retval = call1 (Vmouse_position_function, retval);
1416 RETURN_UNGCPRO (retval);
dc6f92b8
JB
1417}
1418
152e6c70
RS
1419DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1420 Smouse_pixel_position, 0, 0, 0,
1421 "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
1422The position is given in pixel units, where (0, 0) is the\n\
1423upper-left corner.\n\
1424If Emacs is running on a mouseless terminal or hasn't been programmed\n\
1425to read the mouse position, it returns the selected frame for FRAME\n\
1426and nil for X and Y.")
1427 ()
1428{
1429 FRAME_PTR f;
1430 Lisp_Object lispy_dummy;
1431 enum scroll_bar_part party_dummy;
1432 Lisp_Object x, y;
152e6c70
RS
1433 unsigned long long_dummy;
1434
8d2666fe 1435 f = SELECTED_FRAME ();
152e6c70
RS
1436 x = y = Qnil;
1437
0c5c1cf7 1438#ifdef HAVE_MOUSE
152e6c70
RS
1439 /* It's okay for the hook to refrain from storing anything. */
1440 if (mouse_position_hook)
66e827dc 1441 (*mouse_position_hook) (&f, -1,
152e6c70
RS
1442 &lispy_dummy, &party_dummy,
1443 &x, &y,
1444 &long_dummy);
0c5c1cf7 1445#endif
2d80a27a 1446 XSETFRAME (lispy_dummy, f);
152e6c70
RS
1447 return Fcons (lispy_dummy, Fcons (x, y));
1448}
1449
dc6f92b8 1450DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1d7cc616 1451 "Move the mouse pointer to the center of character cell (X,Y) in FRAME.\n\
e84ffeec
RS
1452Coordinates are relative to the frame, not a window,\n\
1453so the coordinates of the top left character in the frame\n\
1454may be nonzero due to left-hand scroll bars or the menu bar.\n\
1455\n\
1456This function is a no-op for an X frame that is not visible.\n\
efb57f43
RS
1457If you have just created a frame, you must wait for it to become visible\n\
1458before calling this function on it, like this.\n\
1459 (while (not (frame-visible-p frame)) (sleep-for .5))")
ff11dfa1
JB
1460 (frame, x, y)
1461 Lisp_Object frame, x, y;
dc6f92b8 1462{
ff11dfa1 1463 CHECK_LIVE_FRAME (frame, 0);
dc6f92b8
JB
1464 CHECK_NUMBER (x, 2);
1465 CHECK_NUMBER (y, 1);
1466
dbc4e1c1 1467 /* I think this should be done with a hook. */
032d78fe
GV
1468#ifdef HAVE_WINDOW_SYSTEM
1469 if (FRAME_WINDOW_P (XFRAME (frame)))
dc6f92b8 1470 /* Warping the mouse will cause enternotify and focus events. */
d4d76014 1471 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
bb221971 1472#else
be625e00 1473#if defined (MSDOS) && defined (HAVE_MOUSE)
bb221971
RS
1474 if (FRAME_MSDOS_P (XFRAME (frame)))
1475 {
1476 Fselect_frame (frame, Qnil);
1477 mouse_moveto (XINT (x), XINT (y));
1478 }
1479#endif
dc6f92b8
JB
1480#endif
1481
1482 return Qnil;
1483}
152e6c70
RS
1484
1485DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1486 Sset_mouse_pixel_position, 3, 3, 0,
1487 "Move the mouse pointer to pixel position (X,Y) in FRAME.\n\
efb57f43
RS
1488Note, this is a no-op for an X frame that is not visible.\n\
1489If you have just created a frame, you must wait for it to become visible\n\
1490before calling this function on it, like this.\n\
1491 (while (not (frame-visible-p frame)) (sleep-for .5))")
152e6c70
RS
1492 (frame, x, y)
1493 Lisp_Object frame, x, y;
1494{
1495 CHECK_LIVE_FRAME (frame, 0);
1496 CHECK_NUMBER (x, 2);
1497 CHECK_NUMBER (y, 1);
1498
1499 /* I think this should be done with a hook. */
032d78fe
GV
1500#ifdef HAVE_WINDOW_SYSTEM
1501 if (FRAME_WINDOW_P (XFRAME (frame)))
152e6c70 1502 /* Warping the mouse will cause enternotify and focus events. */
d4d76014 1503 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
bb221971 1504#else
be625e00 1505#if defined (MSDOS) && defined (HAVE_MOUSE)
bb221971
RS
1506 if (FRAME_MSDOS_P (XFRAME (frame)))
1507 {
1508 Fselect_frame (frame, Qnil);
1509 mouse_moveto (XINT (x), XINT (y));
1510 }
1511#endif
152e6c70
RS
1512#endif
1513
1514 return Qnil;
1515}
dc6f92b8 1516\f
98ce1622
RS
1517static void make_frame_visible_1 P_ ((Lisp_Object));
1518
ff11dfa1 1519DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
fc25d15d 1520 0, 1, "",
ff11dfa1 1521 "Make the frame FRAME visible (assuming it is an X-window).\n\
8693ca83 1522If omitted, FRAME defaults to the currently selected frame.")
ff11dfa1
JB
1523 (frame)
1524 Lisp_Object frame;
dc6f92b8 1525{
1aa66088 1526 if (NILP (frame))
8d2666fe 1527 frame = selected_frame;
1aa66088 1528
ff11dfa1 1529 CHECK_LIVE_FRAME (frame, 0);
dc6f92b8 1530
dbc4e1c1 1531 /* I think this should be done with a hook. */
032d78fe
GV
1532#ifdef HAVE_WINDOW_SYSTEM
1533 if (FRAME_WINDOW_P (XFRAME (frame)))
02ff9dd5
RS
1534 {
1535 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1536 x_make_frame_visible (XFRAME (frame));
1537 }
fd0c2bd1 1538#endif
dc6f92b8 1539
98ce1622
RS
1540 make_frame_visible_1 (XFRAME (frame)->root_window);
1541
565620a5
RS
1542 /* Make menu bar update for the Buffers and Frams menus. */
1543 windows_or_buffers_changed++;
1544
ff11dfa1 1545 return frame;
dc6f92b8
JB
1546}
1547
98ce1622
RS
1548/* Update the display_time slot of the buffers shown in WINDOW
1549 and all its descendents. */
1550
1551static void
1552make_frame_visible_1 (window)
1553 Lisp_Object window;
1554{
1555 struct window *w;
1556
1557 for (;!NILP (window); window = w->next)
1558 {
1559 w = XWINDOW (window);
1560
1561 if (!NILP (w->buffer))
1562 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1563
1564 if (!NILP (w->vchild))
1565 make_frame_visible_1 (w->vchild);
1566 if (!NILP (w->hchild))
1567 make_frame_visible_1 (w->hchild);
1568 }
1569}
1570
ff11dfa1 1571DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
808c0f20 1572 0, 2, "",
8693ca83 1573 "Make the frame FRAME invisible (assuming it is an X-window).\n\
808c0f20
RS
1574If omitted, FRAME defaults to the currently selected frame.\n\
1575Normally you may not make FRAME invisible if all other frames are invisible,\n\
1576but if the second optional argument FORCE is non-nil, you may do so.")
1577 (frame, force)
1578 Lisp_Object frame, force;
dc6f92b8 1579{
1aa66088 1580 if (NILP (frame))
8d2666fe 1581 frame = selected_frame;
1aa66088 1582
ff11dfa1 1583 CHECK_LIVE_FRAME (frame, 0);
dc6f92b8 1584
808c0f20
RS
1585 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1586 error ("Attempt to make invisible the sole visible or iconified frame");
1587
3d378fdf 1588#if 0 /* This isn't logically necessary, and it can do GC. */
9c394f17 1589 /* Don't let the frame remain selected. */
8d2666fe 1590 if (EQ (frame, selected_frame))
61f94483 1591 do_switch_frame (next_frame (frame, Qt), Qnil, 0)
3d378fdf 1592#endif
9c394f17
RS
1593
1594 /* Don't allow minibuf_window to remain on a deleted frame. */
1595 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1596 {
8d2666fe
GM
1597 struct frame *sf = XFRAME (selected_frame);
1598 Fset_window_buffer (sf->minibuffer_window,
9c394f17 1599 XWINDOW (minibuf_window)->buffer);
8d2666fe 1600 minibuf_window = sf->minibuffer_window;
9c394f17
RS
1601 }
1602
dbc4e1c1 1603 /* I think this should be done with a hook. */
032d78fe
GV
1604#ifdef HAVE_WINDOW_SYSTEM
1605 if (FRAME_WINDOW_P (XFRAME (frame)))
ff11dfa1 1606 x_make_frame_invisible (XFRAME (frame));
fd0c2bd1 1607#endif
dc6f92b8 1608
565620a5
RS
1609 /* Make menu bar update for the Buffers and Frams menus. */
1610 windows_or_buffers_changed++;
1611
dc6f92b8
JB
1612 return Qnil;
1613}
1614
ff11dfa1 1615DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1aa66088 1616 0, 1, "",
8693ca83
JB
1617 "Make the frame FRAME into an icon.\n\
1618If omitted, FRAME defaults to the currently selected frame.")
ff11dfa1
JB
1619 (frame)
1620 Lisp_Object frame;
dc6f92b8 1621{
1aa66088 1622 if (NILP (frame))
8d2666fe 1623 frame = selected_frame;
1aa66088 1624
ff11dfa1 1625 CHECK_LIVE_FRAME (frame, 0);
dc6f92b8 1626
3d378fdf 1627#if 0 /* This isn't logically necessary, and it can do GC. */
9c394f17 1628 /* Don't let the frame remain selected. */
8d2666fe 1629 if (EQ (frame, selected_frame))
9c394f17 1630 Fhandle_switch_frame (next_frame (frame, Qt), Qnil);
3d378fdf 1631#endif
9c394f17
RS
1632
1633 /* Don't allow minibuf_window to remain on a deleted frame. */
1634 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1635 {
8d2666fe
GM
1636 struct frame *sf = XFRAME (selected_frame);
1637 Fset_window_buffer (sf->minibuffer_window,
9c394f17 1638 XWINDOW (minibuf_window)->buffer);
8d2666fe 1639 minibuf_window = sf->minibuffer_window;
9c394f17
RS
1640 }
1641
dbc4e1c1 1642 /* I think this should be done with a hook. */
032d78fe
GV
1643#ifdef HAVE_WINDOW_SYSTEM
1644 if (FRAME_WINDOW_P (XFRAME (frame)))
ff11dfa1 1645 x_iconify_frame (XFRAME (frame));
fd0c2bd1 1646#endif
dc6f92b8 1647
565620a5
RS
1648 /* Make menu bar update for the Buffers and Frams menus. */
1649 windows_or_buffers_changed++;
1650
dc6f92b8
JB
1651 return Qnil;
1652}
1653
ff11dfa1 1654DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
dc6f92b8 1655 1, 1, 0,
ff11dfa1
JB
1656 "Return t if FRAME is now \"visible\" (actually in use for display).\n\
1657A frame that is not \"visible\" is not updated and, if it works through\n\
dc6f92b8 1658a window system, it may not show at all.\n\
fd0c2bd1 1659Return the symbol `icon' if frame is visible only as an icon.")
ff11dfa1
JB
1660 (frame)
1661 Lisp_Object frame;
dc6f92b8 1662{
ff11dfa1 1663 CHECK_LIVE_FRAME (frame, 0);
dc6f92b8 1664
5c044f55
RS
1665 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1666
a42e9724 1667 if (FRAME_VISIBLE_P (XFRAME (frame)))
dc6f92b8 1668 return Qt;
a42e9724 1669 if (FRAME_ICONIFIED_P (XFRAME (frame)))
fd0c2bd1 1670 return Qicon;
dc6f92b8
JB
1671 return Qnil;
1672}
1673
ff11dfa1 1674DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
dc6f92b8 1675 0, 0, 0,
ff11dfa1 1676 "Return a list of all frames now \"visible\" (being updated).")
dc6f92b8
JB
1677 ()
1678{
ff11dfa1
JB
1679 Lisp_Object tail, frame;
1680 struct frame *f;
dc6f92b8
JB
1681 Lisp_Object value;
1682
1683 value = Qnil;
7539e11f 1684 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
dc6f92b8 1685 {
7539e11f 1686 frame = XCAR (tail);
e35d291d 1687 if (!FRAMEP (frame))
dc6f92b8 1688 continue;
ff11dfa1 1689 f = XFRAME (frame);
a42e9724 1690 if (FRAME_VISIBLE_P (f))
ff11dfa1 1691 value = Fcons (frame, value);
dc6f92b8
JB
1692 }
1693 return value;
1694}
d5e7c279
JB
1695
1696
e518d5e1 1697DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
dbc4e1c1
JB
1698 "Bring FRAME to the front, so it occludes any frames it overlaps.\n\
1699If FRAME is invisible, make it visible.\n\
828ac693 1700If you don't specify a frame, the selected frame is used.\n\
dbc4e1c1
JB
1701If Emacs is displaying on an ordinary terminal or some other device which\n\
1702doesn't support multiple overlapping frames, this function does nothing.")
1703 (frame)
1704 Lisp_Object frame;
1705{
828ac693 1706 if (NILP (frame))
8d2666fe 1707 frame = selected_frame;
828ac693 1708
dbc4e1c1 1709 CHECK_LIVE_FRAME (frame, 0);
8a981af5
RS
1710
1711 /* Do like the documentation says. */
1712 Fmake_frame_visible (frame);
1713
dbc4e1c1
JB
1714 if (frame_raise_lower_hook)
1715 (*frame_raise_lower_hook) (XFRAME (frame), 1);
1716
1717 return Qnil;
1718}
1719
b49f5578 1720/* Should we have a corresponding function called Flower_Power? */
e518d5e1 1721DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
dbc4e1c1 1722 "Send FRAME to the back, so it is occluded by any frames that overlap it.\n\
828ac693 1723If you don't specify a frame, the selected frame is used.\n\
dbc4e1c1
JB
1724If Emacs is displaying on an ordinary terminal or some other device which\n\
1725doesn't support multiple overlapping frames, this function does nothing.")
1726 (frame)
1727 Lisp_Object frame;
1728{
828ac693 1729 if (NILP (frame))
8d2666fe 1730 frame = selected_frame;
828ac693 1731
dbc4e1c1
JB
1732 CHECK_LIVE_FRAME (frame, 0);
1733
1734 if (frame_raise_lower_hook)
1735 (*frame_raise_lower_hook) (XFRAME (frame), 0);
1736
1737 return Qnil;
1738}
1739
d5e7c279 1740\f
ff11dfa1 1741DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
d5e7c279 1742 1, 2, 0,
ff11dfa1 1743 "Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.\n\
a42e9724
JB
1744In other words, switch-frame events caused by events in FRAME will\n\
1745request a switch to FOCUS-FRAME, and `last-event-frame' will be\n\
1746FOCUS-FRAME after reading an event typed at FRAME.\n\
d5e7c279 1747\n\
a42e9724 1748If FOCUS-FRAME is omitted or nil, any existing redirection is\n\
ff11dfa1 1749cancelled, and the frame again receives its own keystrokes.\n\
d5e7c279 1750\n\
a42e9724
JB
1751Focus redirection is useful for temporarily redirecting keystrokes to\n\
1752a surrogate minibuffer frame when a frame doesn't have its own\n\
1753minibuffer window.\n\
d5e7c279 1754\n\
a42e9724
JB
1755A frame's focus redirection can be changed by select-frame. If frame\n\
1756FOO is selected, and then a different frame BAR is selected, any\n\
1757frames redirecting their focus to FOO are shifted to redirect their\n\
1758focus to BAR. This allows focus redirection to work properly when the\n\
1759user switches from one frame to another using `select-window'.\n\
1760\n\
1761This means that a frame whose focus is redirected to itself is treated\n\
1762differently from a frame whose focus is redirected to nil; the former\n\
1763is affected by select-frame, while the latter is not.\n\
1764\n\
1765The redirection lasts until `redirect-frame-focus' is called to change it.")
ff11dfa1
JB
1766 (frame, focus_frame)
1767 Lisp_Object frame, focus_frame;
d5e7c279 1768{
13144095
JB
1769 /* Note that we don't check for a live frame here. It's reasonable
1770 to redirect the focus of a frame you're about to delete, if you
1771 know what other frame should receive those keystrokes. */
1772 CHECK_FRAME (frame, 0);
f9898cc6 1773
a42e9724 1774 if (! NILP (focus_frame))
ff11dfa1 1775 CHECK_LIVE_FRAME (focus_frame, 1);
d5e7c279 1776
ff11dfa1 1777 XFRAME (frame)->focus_frame = focus_frame;
d5e7c279 1778
ff11dfa1 1779 if (frame_rehighlight_hook)
dc0700f6 1780 (*frame_rehighlight_hook) (XFRAME (frame));
d5e7c279
JB
1781
1782 return Qnil;
1783}
1784
1785
ff11dfa1
JB
1786DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1787 "Return the frame to which FRAME's keystrokes are currently being sent.\n\
a42e9724 1788This returns nil if FRAME's focus is not redirected.\n\
ff11dfa1
JB
1789See `redirect-frame-focus'.")
1790 (frame)
1791 Lisp_Object frame;
d5e7c279 1792{
ff11dfa1 1793 CHECK_LIVE_FRAME (frame, 0);
a42e9724 1794
ff11dfa1 1795 return FRAME_FOCUS_FRAME (XFRAME (frame));
d5e7c279
JB
1796}
1797
1798
dc6f92b8 1799\f
329ca574
RS
1800/* Return the value of frame parameter PROP in frame FRAME. */
1801
dc6f92b8 1802Lisp_Object
ff11dfa1
JB
1803get_frame_param (frame, prop)
1804 register struct frame *frame;
dc6f92b8
JB
1805 Lisp_Object prop;
1806{
1807 register Lisp_Object tem;
1808
ff11dfa1 1809 tem = Fassq (prop, frame->param_alist);
dc6f92b8
JB
1810 if (EQ (tem, Qnil))
1811 return tem;
1812 return Fcdr (tem);
1813}
1814
329ca574
RS
1815/* Return the buffer-predicate of the selected frame. */
1816
1817Lisp_Object
98ce1622
RS
1818frame_buffer_predicate (frame)
1819 Lisp_Object frame;
329ca574 1820{
98ce1622 1821 return XFRAME (frame)->buffer_predicate;
329ca574
RS
1822}
1823
fa54c6ae
RS
1824/* Return the buffer-list of the selected frame. */
1825
1826Lisp_Object
98ce1622
RS
1827frame_buffer_list (frame)
1828 Lisp_Object frame;
fa54c6ae 1829{
98ce1622 1830 return XFRAME (frame)->buffer_list;
fa54c6ae
RS
1831}
1832
1833/* Set the buffer-list of the selected frame. */
1834
1835void
98ce1622
RS
1836set_frame_buffer_list (frame, list)
1837 Lisp_Object frame, list;
fa54c6ae 1838{
98ce1622 1839 XFRAME (frame)->buffer_list = list;
fa54c6ae
RS
1840}
1841
1842/* Discard BUFFER from the buffer-list of each frame. */
1843
1844void
1845frames_discard_buffer (buffer)
1846 Lisp_Object buffer;
1847{
1848 Lisp_Object frame, tail;
1849
1850 FOR_EACH_FRAME (tail, frame)
1851 {
1852 XFRAME (frame)->buffer_list
1853 = Fdelq (buffer, XFRAME (frame)->buffer_list);
1854 }
1855}
1856
214b3216
RS
1857/* Move BUFFER to the end of the buffer-list of each frame. */
1858
1859void
1860frames_bury_buffer (buffer)
1861 Lisp_Object buffer;
1862{
1863 Lisp_Object frame, tail;
1864
1865 FOR_EACH_FRAME (tail, frame)
1866 {
835c1b36
GM
1867 struct frame *f = XFRAME (frame);
1868 Lisp_Object found;
1869
1870 found = Fmemq (buffer, f->buffer_list);
1871 if (!NILP (found))
1872 f->buffer_list = nconc2 (Fdelq (buffer, f->buffer_list),
1873 Fcons (buffer, Qnil));
214b3216
RS
1874 }
1875}
1876
329ca574
RS
1877/* Modify the alist in *ALISTPTR to associate PROP with VAL.
1878 If the alist already has an element for PROP, we change it. */
1879
dc6f92b8 1880void
fd0c2bd1 1881store_in_alist (alistptr, prop, val)
dc6f92b8 1882 Lisp_Object *alistptr, val;
fd0c2bd1 1883 Lisp_Object prop;
dc6f92b8
JB
1884{
1885 register Lisp_Object tem;
dc6f92b8 1886
dc6f92b8
JB
1887 tem = Fassq (prop, *alistptr);
1888 if (EQ (tem, Qnil))
1889 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1890 else
1891 Fsetcdr (tem, val);
1892}
1893
e5317d61
EZ
1894static int
1895frame_name_fnn_p (str, len)
1896 char *str;
1897 int len;
1898{
1899 if (len > 1 && str[0] == 'F')
1900 {
1901 char *end_ptr;
e5317d61 1902
48970f2f
EZ
1903 strtol (str + 1, &end_ptr, 10);
1904
e5317d61
EZ
1905 if (end_ptr == str + len)
1906 return 1;
1907 }
1908 return 0;
1909}
1910
1911/* Set the name of the terminal frame. Also used by MSDOS frames.
1912 Modeled after x_set_name which is used for WINDOW frames. */
1913
1914void
1915set_term_frame_name (f, name)
1916 struct frame *f;
1917 Lisp_Object name;
1918{
1919 f->explicit_name = ! NILP (name);
1920
1921 /* If NAME is nil, set the name to F<num>. */
1922 if (NILP (name))
1923 {
1924 char namebuf[20];
1925
1926 /* Check for no change needed in this very common case
1927 before we do any consing. */
e34c5c7d 1928 if (frame_name_fnn_p (XSTRING (f->name)->data,
fc932ac6 1929 STRING_BYTES (XSTRING (f->name))))
e5317d61
EZ
1930 return;
1931
1932 terminal_frame_count++;
1933 sprintf (namebuf, "F%d", terminal_frame_count);
1934 name = build_string (namebuf);
1935 }
1936 else
1937 {
1938 CHECK_STRING (name, 0);
1939
1940 /* Don't change the name if it's already NAME. */
1941 if (! NILP (Fstring_equal (name, f->name)))
1942 return;
1943
1944 /* Don't allow the user to set the frame name to F<num>, so it
1945 doesn't clash with the names we generate for terminal frames. */
fc932ac6 1946 if (frame_name_fnn_p (XSTRING (name)->data, STRING_BYTES (XSTRING (name))))
e5317d61
EZ
1947 error ("Frame names of the form F<num> are usurped by Emacs");
1948 }
1949
1950 f->name = name;
1951 update_mode_lines = 1;
1952}
1953
dc6f92b8 1954void
ff11dfa1
JB
1955store_frame_param (f, prop, val)
1956 struct frame *f;
dc6f92b8
JB
1957 Lisp_Object prop, val;
1958{
7eb63b72 1959 register Lisp_Object old_alist_elt;
dc6f92b8 1960
7eb63b72
GM
1961 /* The buffer-alist parameter is stored in a special place and is
1962 not in the alist. */
fa54c6ae
RS
1963 if (EQ (prop, Qbuffer_list))
1964 {
1965 f->buffer_list = val;
1966 return;
1967 }
1968
7eb63b72
GM
1969 /* If PROP is a symbol which is supposed to have frame-local values,
1970 and it is set up based on this frame, switch to the global
1971 binding. That way, we can create or alter the frame-local binding
1972 without messing up the symbol's status. */
1973 if (SYMBOLP (prop))
1974 {
1975 Lisp_Object valcontents;
1976 valcontents = XSYMBOL (prop)->value;
1977 if ((BUFFER_LOCAL_VALUEP (valcontents)
1978 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1979 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
1980 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
1981 swap_in_global_binding (prop);
1982 }
1983
1984 /* Update the frame parameter alist. */
1985 old_alist_elt = Fassq (prop, f->param_alist);
1986 if (EQ (old_alist_elt, Qnil))
ff11dfa1 1987 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
dc6f92b8 1988 else
7eb63b72 1989 Fsetcdr (old_alist_elt, val);
bc93c097 1990
7eb63b72
GM
1991 /* Update some other special parameters in their special places
1992 in addition to the alist. */
1993
329ca574
RS
1994 if (EQ (prop, Qbuffer_predicate))
1995 f->buffer_predicate = val;
1996
032d78fe 1997 if (! FRAME_WINDOW_P (f))
e5317d61
EZ
1998 {
1999 if (EQ (prop, Qmenu_bar_lines))
2000 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2001 else if (EQ (prop, Qname))
2002 set_term_frame_name (f, val);
2003 }
a249de79 2004
e35d291d 2005 if (EQ (prop, Qminibuffer) && WINDOWP (val))
bc93c097
JB
2006 {
2007 if (! MINI_WINDOW_P (XWINDOW (val)))
2008 error ("Surrogate minibuffer windows must be minibuffer windows.");
2009
213bac8a 2010 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
7af7ef38
KH
2011 && !EQ (val, f->minibuffer_window))
2012 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
bc93c097
JB
2013
2014 /* Install the chosen minibuffer window, with proper buffer. */
ff11dfa1 2015 f->minibuffer_window = val;
bc93c097 2016 }
dc6f92b8
JB
2017}
2018
ff11dfa1
JB
2019DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2020 "Return the parameters-alist of frame FRAME.\n\
dc6f92b8 2021It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.\n\
dc6d9681
JB
2022The meaningful PARMs depend on the kind of frame.\n\
2023If FRAME is omitted, return information on the currently selected frame.")
ff11dfa1
JB
2024 (frame)
2025 Lisp_Object frame;
dc6f92b8
JB
2026{
2027 Lisp_Object alist;
f769f1b2 2028 FRAME_PTR f;
dd10ec4f 2029 int height, width;
57629833 2030 struct gcpro gcpro1;
dc6f92b8 2031
ff11dfa1 2032 if (EQ (frame, Qnil))
8d2666fe
GM
2033 frame = selected_frame;
2034
2035 CHECK_FRAME (frame, 0);
2036 f = XFRAME (frame);
dc6f92b8 2037
f769f1b2 2038 if (!FRAME_LIVE_P (f))
dc6f92b8
JB
2039 return Qnil;
2040
ff11dfa1 2041 alist = Fcopy_alist (f->param_alist);
57629833
GM
2042 GCPRO1 (alist);
2043
2d764c78 2044 if (!FRAME_WINDOW_P (f))
bb221971 2045 {
4aec4b29
EZ
2046 int fg = FRAME_FOREGROUND_PIXEL (f);
2047 int bg = FRAME_BACKGROUND_PIXEL (f);
2048
bb221971 2049 store_in_alist (&alist, intern ("foreground-color"),
2d764c78 2050 tty_color_name (f, fg));
bb221971 2051 store_in_alist (&alist, intern ("background-color"),
2d764c78
EZ
2052 tty_color_name (f, bg));
2053 store_in_alist (&alist, intern ("font"),
2054 build_string (FRAME_MSDOS_P (f)
2055 ? "ms-dos"
2056 : FRAME_W32_P (f) ? "w32term" : "tty"));
bb221971 2057 }
fd0c2bd1 2058 store_in_alist (&alist, Qname, f->name);
dd10ec4f
RS
2059 height = (FRAME_NEW_HEIGHT (f) ? FRAME_NEW_HEIGHT (f) : FRAME_HEIGHT (f));
2060 store_in_alist (&alist, Qheight, make_number (height));
2061 width = (FRAME_NEW_WIDTH (f) ? FRAME_NEW_WIDTH (f) : FRAME_WIDTH (f));
2062 store_in_alist (&alist, Qwidth, make_number (width));
f769f1b2 2063 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
fd0c2bd1 2064 store_in_alist (&alist, Qminibuffer,
39acc701 2065 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
f769f1b2
KH
2066 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2067 : FRAME_MINIBUF_WINDOW (f)));
2068 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
98ce1622 2069 store_in_alist (&alist, Qbuffer_list,
8d2666fe 2070 frame_buffer_list (selected_frame));
fd0c2bd1 2071
dbc4e1c1 2072 /* I think this should be done with a hook. */
032d78fe
GV
2073#ifdef HAVE_WINDOW_SYSTEM
2074 if (FRAME_WINDOW_P (f))
ff11dfa1 2075 x_report_frame_params (f, &alist);
b6dd20ed 2076 else
fd0c2bd1 2077#endif
16a3738c
KH
2078 {
2079 /* This ought to be correct in f->param_alist for an X frame. */
2080 Lisp_Object lines;
f4e93c40 2081 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
16a3738c
KH
2082 store_in_alist (&alist, Qmenu_bar_lines, lines);
2083 }
57629833
GM
2084
2085 UNGCPRO;
dc6f92b8
JB
2086 return alist;
2087}
2088
ff11dfa1
JB
2089DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2090 Smodify_frame_parameters, 2, 2, 0,
2091 "Modify the parameters of frame FRAME according to ALIST.\n\
dc6f92b8
JB
2092ALIST is an alist of parameters to change and their new values.\n\
2093Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.\n\
e80f3932
RS
2094The meaningful PARMs depend on the kind of frame.\n\
2095Undefined PARMs are ignored, but stored in the frame's parameter list\n\
7eb63b72
GM
2096so that `frame-parameters' will return them.\n\
2097\n\
2098The value of frame parameter FOO can also be accessed\n\
2099as a frame-local binding for the variable FOO, if you have\n\
2100enabled such bindings for that variable with `make-variable-frame-local'.")
ff11dfa1
JB
2101 (frame, alist)
2102 Lisp_Object frame, alist;
dc6f92b8 2103{
fd0c2bd1 2104 FRAME_PTR f;
213bac8a 2105 register Lisp_Object tail, prop, val;
dc6f92b8 2106
ff11dfa1 2107 if (EQ (frame, Qnil))
8d2666fe
GM
2108 frame = selected_frame;
2109 CHECK_LIVE_FRAME (frame, 0);
2110 f = XFRAME (frame);
dc6f92b8 2111
dbc4e1c1 2112 /* I think this should be done with a hook. */
032d78fe
GV
2113#ifdef HAVE_WINDOW_SYSTEM
2114 if (FRAME_WINDOW_P (f))
fd0c2bd1 2115 x_set_frame_parameters (f, alist);
329ca574 2116 else
bb221971
RS
2117#endif
2118#ifdef MSDOS
2119 if (FRAME_MSDOS_P (f))
2120 IT_set_frame_parameters (f, alist);
2121 else
329ca574 2122#endif
574a1a90
RS
2123#ifdef macintosh
2124 if (FRAME_MAC_P (f))
2125 mac_set_frame_parameters (f, alist);
2126 else
2127#endif
2128
41d44f1f
RS
2129 {
2130 int length = XINT (Flength (alist));
2131 int i;
2132 Lisp_Object *parms
2133 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2134 Lisp_Object *values
2135 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2136
2137 /* Extract parm names and values into those vectors. */
2138
2139 i = 0;
2140 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2141 {
213bac8a 2142 Lisp_Object elt;
41d44f1f
RS
2143
2144 elt = Fcar (tail);
2145 parms[i] = Fcar (elt);
2146 values[i] = Fcdr (elt);
2147 i++;
2148 }
2149
2150 /* Now process them in reverse of specified order. */
2151 for (i--; i >= 0; i--)
2152 {
2153 prop = parms[i];
2154 val = values[i];
2155 store_frame_param (f, prop, val);
2156 }
2157 }
dc6f92b8
JB
2158
2159 return Qnil;
2160}
2161\f
a26a1f95
RS
2162DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2163 0, 1, 0,
2164 "Height in pixels of a line in the font in frame FRAME.\n\
2165If FRAME is omitted, the selected frame is used.\n\
2166For a terminal frame, the value is always 1.")
ff11dfa1
JB
2167 (frame)
2168 Lisp_Object frame;
dc6f92b8 2169{
a26a1f95 2170 struct frame *f;
dc6f92b8 2171
a26a1f95 2172 if (NILP (frame))
8d2666fe
GM
2173 frame = selected_frame;
2174 CHECK_FRAME (frame, 0);
2175 f = XFRAME (frame);
a26a1f95 2176
032d78fe
GV
2177#ifdef HAVE_WINDOW_SYSTEM
2178 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2179 return make_number (x_char_height (f));
2180 else
dc6d9681 2181#endif
a26a1f95
RS
2182 return make_number (1);
2183}
dc6d9681 2184
dc6f92b8 2185
a26a1f95
RS
2186DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2187 0, 1, 0,
2188 "Width in pixels of characters in the font in frame FRAME.\n\
2189If FRAME is omitted, the selected frame is used.\n\
2190The width is the same for all characters, because\n\
2191currently Emacs supports only fixed-width fonts.\n\
2192For a terminal screen, the value is always 1.")
2193 (frame)
2194 Lisp_Object frame;
dc6f92b8 2195{
a26a1f95
RS
2196 struct frame *f;
2197
2198 if (NILP (frame))
8d2666fe
GM
2199 frame = selected_frame;
2200 CHECK_FRAME (frame, 0);
2201 f = XFRAME (frame);
a26a1f95 2202
032d78fe
GV
2203#ifdef HAVE_WINDOW_SYSTEM
2204 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2205 return make_number (x_char_width (f));
2206 else
2207#endif
2208 return make_number (1);
dc6f92b8
JB
2209}
2210
a26a1f95
RS
2211DEFUN ("frame-pixel-height", Fframe_pixel_height,
2212 Sframe_pixel_height, 0, 1, 0,
164a14ef 2213 "Return a FRAME's height in pixels.\n\
07822795
RS
2214This counts only the height available for text lines,\n\
2215not menu bars on window-system Emacs frames.\n\
164a14ef 2216For a terminal frame, the result really gives the height in characters.\n\
a26a1f95
RS
2217If FRAME is omitted, the selected frame is used.")
2218 (frame)
2219 Lisp_Object frame;
dc6f92b8 2220{
a26a1f95
RS
2221 struct frame *f;
2222
2223 if (NILP (frame))
8d2666fe
GM
2224 frame = selected_frame;
2225 CHECK_FRAME (frame, 0);
2226 f = XFRAME (frame);
a26a1f95 2227
032d78fe
GV
2228#ifdef HAVE_WINDOW_SYSTEM
2229 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2230 return make_number (x_pixel_height (f));
2231 else
dc6d9681 2232#endif
a26a1f95
RS
2233 return make_number (FRAME_HEIGHT (f));
2234}
2235
2236DEFUN ("frame-pixel-width", Fframe_pixel_width,
2237 Sframe_pixel_width, 0, 1, 0,
2238 "Return FRAME's width in pixels.\n\
164a14ef 2239For a terminal frame, the result really gives the width in characters.\n\
a26a1f95
RS
2240If FRAME is omitted, the selected frame is used.")
2241 (frame)
2242 Lisp_Object frame;
2243{
2244 struct frame *f;
2245
2246 if (NILP (frame))
8d2666fe
GM
2247 frame = selected_frame;
2248 CHECK_FRAME (frame, 0);
2249 f = XFRAME (frame);
dc6f92b8 2250
032d78fe
GV
2251#ifdef HAVE_WINDOW_SYSTEM
2252 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2253 return make_number (x_pixel_width (f));
2254 else
2255#endif
2256 return make_number (FRAME_WIDTH (f));
2257}
2258\f
ff11dfa1
JB
2259DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2260 "Specify that the frame FRAME has LINES lines.\n\
dc6f92b8 2261Optional third arg non-nil means that redisplay should use LINES lines\n\
ff11dfa1 2262but that the idea of the actual height of the frame should not be changed.")
735eeca3
EN
2263 (frame, lines, pretend)
2264 Lisp_Object frame, lines, pretend;
dc6f92b8 2265{
ff11dfa1 2266 register struct frame *f;
dc6f92b8 2267
735eeca3 2268 CHECK_NUMBER (lines, 0);
ff11dfa1 2269 if (NILP (frame))
8d2666fe
GM
2270 frame = selected_frame;
2271 CHECK_LIVE_FRAME (frame, 0);
2272 f = XFRAME (frame);
dc6f92b8 2273
dbc4e1c1 2274 /* I think this should be done with a hook. */
032d78fe
GV
2275#ifdef HAVE_WINDOW_SYSTEM
2276 if (FRAME_WINDOW_P (f))
dc6f92b8 2277 {
735eeca3
EN
2278 if (XINT (lines) != f->height)
2279 x_set_window_size (f, 1, f->width, XINT (lines));
32347cf4 2280 do_pending_window_change (0);
dc6f92b8
JB
2281 }
2282 else
fd0c2bd1 2283#endif
32347cf4 2284 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
dc6f92b8
JB
2285 return Qnil;
2286}
2287
ff11dfa1
JB
2288DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2289 "Specify that the frame FRAME has COLS columns.\n\
dc6f92b8 2290Optional third arg non-nil means that redisplay should use COLS columns\n\
ff11dfa1
JB
2291but that the idea of the actual width of the frame should not be changed.")
2292 (frame, cols, pretend)
fd0c2bd1 2293 Lisp_Object frame, cols, pretend;
dc6f92b8 2294{
ff11dfa1 2295 register struct frame *f;
dc6f92b8 2296 CHECK_NUMBER (cols, 0);
ff11dfa1 2297 if (NILP (frame))
8d2666fe
GM
2298 frame = selected_frame;
2299 CHECK_LIVE_FRAME (frame, 0);
2300 f = XFRAME (frame);
dc6f92b8 2301
dbc4e1c1 2302 /* I think this should be done with a hook. */
032d78fe
GV
2303#ifdef HAVE_WINDOW_SYSTEM
2304 if (FRAME_WINDOW_P (f))
dc6f92b8 2305 {
ff11dfa1 2306 if (XINT (cols) != f->width)
808c0f20 2307 x_set_window_size (f, 1, XINT (cols), f->height);
32347cf4 2308 do_pending_window_change (0);
dc6f92b8
JB
2309 }
2310 else
fd0c2bd1 2311#endif
32347cf4 2312 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
dc6f92b8
JB
2313 return Qnil;
2314}
2315
ff11dfa1
JB
2316DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2317 "Sets size of FRAME to COLS by ROWS, measured in characters.")
2318 (frame, cols, rows)
2319 Lisp_Object frame, cols, rows;
dc6f92b8 2320{
ff11dfa1 2321 register struct frame *f;
dc6f92b8 2322
ff11dfa1 2323 CHECK_LIVE_FRAME (frame, 0);
dc6f92b8
JB
2324 CHECK_NUMBER (cols, 2);
2325 CHECK_NUMBER (rows, 1);
ff11dfa1 2326 f = XFRAME (frame);
dc6f92b8 2327
dbc4e1c1 2328 /* I think this should be done with a hook. */
032d78fe
GV
2329#ifdef HAVE_WINDOW_SYSTEM
2330 if (FRAME_WINDOW_P (f))
dc6f92b8 2331 {
29824ce2
RS
2332 if (XINT (rows) != f->height || XINT (cols) != f->width
2333 || FRAME_NEW_HEIGHT (f) || FRAME_NEW_WIDTH (f))
808c0f20 2334 x_set_window_size (f, 1, XINT (cols), XINT (rows));
32347cf4 2335 do_pending_window_change (0);
dc6f92b8
JB
2336 }
2337 else
fd0c2bd1 2338#endif
32347cf4 2339 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
dc6f92b8
JB
2340
2341 return Qnil;
2342}
2343
ff11dfa1
JB
2344DEFUN ("set-frame-position", Fset_frame_position,
2345 Sset_frame_position, 3, 3, 0,
2346 "Sets position of FRAME in pixels to XOFFSET by YOFFSET.\n\
60bf8ee4
RS
2347This is actually the position of the upper left corner of the frame.\n\
2348Negative values for XOFFSET or YOFFSET are interpreted relative to\n\
4524cb1c 2349the rightmost or bottommost possible position (that stays within the screen).")
ff11dfa1
JB
2350 (frame, xoffset, yoffset)
2351 Lisp_Object frame, xoffset, yoffset;
dc6f92b8 2352{
ff11dfa1 2353 register struct frame *f;
dc6f92b8 2354
ff11dfa1 2355 CHECK_LIVE_FRAME (frame, 0);
dc6f92b8
JB
2356 CHECK_NUMBER (xoffset, 1);
2357 CHECK_NUMBER (yoffset, 2);
ff11dfa1 2358 f = XFRAME (frame);
dc6f92b8 2359
dbc4e1c1 2360 /* I think this should be done with a hook. */
032d78fe
GV
2361#ifdef HAVE_WINDOW_SYSTEM
2362 if (FRAME_WINDOW_P (f))
c7c70761 2363 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
fd0c2bd1 2364#endif
dc6f92b8
JB
2365
2366 return Qt;
2367}
dc6d9681 2368
dc6f92b8 2369\f
dfcf069d 2370void
ff11dfa1 2371syms_of_frame ()
dc6f92b8 2372{
a249de79 2373 syms_of_frame_1 ();
dc6f92b8 2374
ff11dfa1 2375 staticpro (&Vframe_list);
dc6f92b8 2376
ff11dfa1
JB
2377 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
2378 "The initial frame-object, which represents Emacs's stdout.");
dc6f92b8
JB
2379
2380 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
ff11dfa1 2381 "Non-nil if all of emacs is iconified and frame updates are not needed.");
dc6f92b8
JB
2382 Vemacs_iconified = Qnil;
2383
beb0bc36
DL
2384 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
2385 "If non-nil, function applied to the normal result of `mouse-position'.\n\
2386This abnormal hook exists for the benefit of packages like XTerm-mouse\n\
2387which need to do mouse handling at the Lisp level.");
2388 Vmouse_position_function = Qnil;
2389
c60f3a6a 2390 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
ff11dfa1 2391 "Minibufferless frames use this frame's minibuffer.\n\
f9898cc6 2392\n\
ff11dfa1 2393Emacs cannot create minibufferless frames unless this is set to an\n\
f9898cc6
JB
2394appropriate surrogate.\n\
2395\n\
2396Emacs consults this variable only when creating minibufferless\n\
ff11dfa1 2397frames; once the frame is created, it sticks with its assigned\n\
f9898cc6
JB
2398minibuffer, no matter what this variable is set to. This means that\n\
2399this variable doesn't necessarily say anything meaningful about the\n\
ff11dfa1 2400current set of frames, or where the minibuffer is currently being\n\
f9898cc6 2401displayed.");
dc6f92b8 2402
5add3885 2403 defsubr (&Sactive_minibuffer_window);
ff11dfa1 2404 defsubr (&Sframep);
dbc4e1c1 2405 defsubr (&Sframe_live_p);
bb1513c9 2406 defsubr (&Smake_terminal_frame);
0f85737c 2407 defsubr (&Shandle_switch_frame);
1c212787 2408 defsubr (&Signore_event);
ff11dfa1
JB
2409 defsubr (&Sselect_frame);
2410 defsubr (&Sselected_frame);
2411 defsubr (&Swindow_frame);
2412 defsubr (&Sframe_root_window);
d446a856 2413 defsubr (&Sframe_first_window);
ff11dfa1 2414 defsubr (&Sframe_selected_window);
4a7cfafc 2415 defsubr (&Sset_frame_selected_window);
ff11dfa1
JB
2416 defsubr (&Sframe_list);
2417 defsubr (&Snext_frame);
ef2c57ac 2418 defsubr (&Sprevious_frame);
ff11dfa1 2419 defsubr (&Sdelete_frame);
f9898cc6 2420 defsubr (&Smouse_position);
152e6c70 2421 defsubr (&Smouse_pixel_position);
dc6f92b8 2422 defsubr (&Sset_mouse_position);
152e6c70 2423 defsubr (&Sset_mouse_pixel_position);
dc6f92b8 2424#if 0
ff11dfa1
JB
2425 defsubr (&Sframe_configuration);
2426 defsubr (&Srestore_frame_configuration);
dc6f92b8 2427#endif
ff11dfa1
JB
2428 defsubr (&Smake_frame_visible);
2429 defsubr (&Smake_frame_invisible);
2430 defsubr (&Siconify_frame);
2431 defsubr (&Sframe_visible_p);
2432 defsubr (&Svisible_frame_list);
b49f5578
JB
2433 defsubr (&Sraise_frame);
2434 defsubr (&Slower_frame);
ff11dfa1
JB
2435 defsubr (&Sredirect_frame_focus);
2436 defsubr (&Sframe_focus);
2437 defsubr (&Sframe_parameters);
2438 defsubr (&Smodify_frame_parameters);
a26a1f95
RS
2439 defsubr (&Sframe_char_height);
2440 defsubr (&Sframe_char_width);
2441 defsubr (&Sframe_pixel_height);
2442 defsubr (&Sframe_pixel_width);
ff11dfa1
JB
2443 defsubr (&Sset_frame_height);
2444 defsubr (&Sset_frame_width);
2445 defsubr (&Sset_frame_size);
2446 defsubr (&Sset_frame_position);
dc6f92b8 2447}
e5d77022 2448
dfcf069d 2449void
2f0b07e0
JB
2450keys_of_frame ()
2451{
0f85737c 2452 initial_define_lispy_key (global_map, "switch-frame", "handle-switch-frame");
d134b17b 2453 initial_define_lispy_key (global_map, "delete-frame", "handle-delete-frame");
1c212787
KH
2454 initial_define_lispy_key (global_map, "iconify-frame", "ignore-event");
2455 initial_define_lispy_key (global_map, "make-frame-visible", "ignore-event");
2f0b07e0 2456}