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