(make_temp_name): New function, extracted from
[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 {
1867 XFRAME (frame)->buffer_list
1868 = nconc2 (Fdelq (buffer, XFRAME (frame)->buffer_list),
1869 Fcons (buffer, Qnil));
1870 }
1871}
1872
329ca574
RS
1873/* Modify the alist in *ALISTPTR to associate PROP with VAL.
1874 If the alist already has an element for PROP, we change it. */
1875
dc6f92b8 1876void
fd0c2bd1 1877store_in_alist (alistptr, prop, val)
dc6f92b8 1878 Lisp_Object *alistptr, val;
fd0c2bd1 1879 Lisp_Object prop;
dc6f92b8
JB
1880{
1881 register Lisp_Object tem;
dc6f92b8 1882
dc6f92b8
JB
1883 tem = Fassq (prop, *alistptr);
1884 if (EQ (tem, Qnil))
1885 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1886 else
1887 Fsetcdr (tem, val);
1888}
1889
e5317d61
EZ
1890static int
1891frame_name_fnn_p (str, len)
1892 char *str;
1893 int len;
1894{
1895 if (len > 1 && str[0] == 'F')
1896 {
1897 char *end_ptr;
e5317d61 1898
48970f2f
EZ
1899 strtol (str + 1, &end_ptr, 10);
1900
e5317d61
EZ
1901 if (end_ptr == str + len)
1902 return 1;
1903 }
1904 return 0;
1905}
1906
1907/* Set the name of the terminal frame. Also used by MSDOS frames.
1908 Modeled after x_set_name which is used for WINDOW frames. */
1909
1910void
1911set_term_frame_name (f, name)
1912 struct frame *f;
1913 Lisp_Object name;
1914{
1915 f->explicit_name = ! NILP (name);
1916
1917 /* If NAME is nil, set the name to F<num>. */
1918 if (NILP (name))
1919 {
1920 char namebuf[20];
1921
1922 /* Check for no change needed in this very common case
1923 before we do any consing. */
e34c5c7d 1924 if (frame_name_fnn_p (XSTRING (f->name)->data,
fc932ac6 1925 STRING_BYTES (XSTRING (f->name))))
e5317d61
EZ
1926 return;
1927
1928 terminal_frame_count++;
1929 sprintf (namebuf, "F%d", terminal_frame_count);
1930 name = build_string (namebuf);
1931 }
1932 else
1933 {
1934 CHECK_STRING (name, 0);
1935
1936 /* Don't change the name if it's already NAME. */
1937 if (! NILP (Fstring_equal (name, f->name)))
1938 return;
1939
1940 /* Don't allow the user to set the frame name to F<num>, so it
1941 doesn't clash with the names we generate for terminal frames. */
fc932ac6 1942 if (frame_name_fnn_p (XSTRING (name)->data, STRING_BYTES (XSTRING (name))))
e5317d61
EZ
1943 error ("Frame names of the form F<num> are usurped by Emacs");
1944 }
1945
1946 f->name = name;
1947 update_mode_lines = 1;
1948}
1949
dc6f92b8 1950void
ff11dfa1
JB
1951store_frame_param (f, prop, val)
1952 struct frame *f;
dc6f92b8
JB
1953 Lisp_Object prop, val;
1954{
1955 register Lisp_Object tem;
1956
fa54c6ae
RS
1957 if (EQ (prop, Qbuffer_list))
1958 {
1959 f->buffer_list = val;
1960 return;
1961 }
1962
ff11dfa1 1963 tem = Fassq (prop, f->param_alist);
dc6f92b8 1964 if (EQ (tem, Qnil))
ff11dfa1 1965 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
dc6f92b8
JB
1966 else
1967 Fsetcdr (tem, val);
bc93c097 1968
329ca574
RS
1969 if (EQ (prop, Qbuffer_predicate))
1970 f->buffer_predicate = val;
1971
032d78fe 1972 if (! FRAME_WINDOW_P (f))
e5317d61
EZ
1973 {
1974 if (EQ (prop, Qmenu_bar_lines))
1975 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
1976 else if (EQ (prop, Qname))
1977 set_term_frame_name (f, val);
1978 }
a249de79 1979
e35d291d 1980 if (EQ (prop, Qminibuffer) && WINDOWP (val))
bc93c097
JB
1981 {
1982 if (! MINI_WINDOW_P (XWINDOW (val)))
1983 error ("Surrogate minibuffer windows must be minibuffer windows.");
1984
213bac8a 1985 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
7af7ef38
KH
1986 && !EQ (val, f->minibuffer_window))
1987 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
bc93c097
JB
1988
1989 /* Install the chosen minibuffer window, with proper buffer. */
ff11dfa1 1990 f->minibuffer_window = val;
bc93c097 1991 }
dc6f92b8
JB
1992}
1993
ff11dfa1
JB
1994DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
1995 "Return the parameters-alist of frame FRAME.\n\
dc6f92b8 1996It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.\n\
dc6d9681
JB
1997The meaningful PARMs depend on the kind of frame.\n\
1998If FRAME is omitted, return information on the currently selected frame.")
ff11dfa1
JB
1999 (frame)
2000 Lisp_Object frame;
dc6f92b8
JB
2001{
2002 Lisp_Object alist;
f769f1b2 2003 FRAME_PTR f;
dd10ec4f 2004 int height, width;
57629833 2005 struct gcpro gcpro1;
dc6f92b8 2006
ff11dfa1 2007 if (EQ (frame, Qnil))
8d2666fe
GM
2008 frame = selected_frame;
2009
2010 CHECK_FRAME (frame, 0);
2011 f = XFRAME (frame);
dc6f92b8 2012
f769f1b2 2013 if (!FRAME_LIVE_P (f))
dc6f92b8
JB
2014 return Qnil;
2015
ff11dfa1 2016 alist = Fcopy_alist (f->param_alist);
57629833
GM
2017 GCPRO1 (alist);
2018
2d764c78 2019 if (!FRAME_WINDOW_P (f))
bb221971 2020 {
4aec4b29
EZ
2021 int fg = FRAME_FOREGROUND_PIXEL (f);
2022 int bg = FRAME_BACKGROUND_PIXEL (f);
2023
bb221971 2024 store_in_alist (&alist, intern ("foreground-color"),
2d764c78 2025 tty_color_name (f, fg));
bb221971 2026 store_in_alist (&alist, intern ("background-color"),
2d764c78
EZ
2027 tty_color_name (f, bg));
2028 store_in_alist (&alist, intern ("font"),
2029 build_string (FRAME_MSDOS_P (f)
2030 ? "ms-dos"
2031 : FRAME_W32_P (f) ? "w32term" : "tty"));
bb221971 2032 }
fd0c2bd1 2033 store_in_alist (&alist, Qname, f->name);
dd10ec4f
RS
2034 height = (FRAME_NEW_HEIGHT (f) ? FRAME_NEW_HEIGHT (f) : FRAME_HEIGHT (f));
2035 store_in_alist (&alist, Qheight, make_number (height));
2036 width = (FRAME_NEW_WIDTH (f) ? FRAME_NEW_WIDTH (f) : FRAME_WIDTH (f));
2037 store_in_alist (&alist, Qwidth, make_number (width));
f769f1b2 2038 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
fd0c2bd1 2039 store_in_alist (&alist, Qminibuffer,
39acc701 2040 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
f769f1b2
KH
2041 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2042 : FRAME_MINIBUF_WINDOW (f)));
2043 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
98ce1622 2044 store_in_alist (&alist, Qbuffer_list,
8d2666fe 2045 frame_buffer_list (selected_frame));
fd0c2bd1 2046
dbc4e1c1 2047 /* I think this should be done with a hook. */
032d78fe
GV
2048#ifdef HAVE_WINDOW_SYSTEM
2049 if (FRAME_WINDOW_P (f))
ff11dfa1 2050 x_report_frame_params (f, &alist);
b6dd20ed 2051 else
fd0c2bd1 2052#endif
16a3738c
KH
2053 {
2054 /* This ought to be correct in f->param_alist for an X frame. */
2055 Lisp_Object lines;
f4e93c40 2056 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
16a3738c
KH
2057 store_in_alist (&alist, Qmenu_bar_lines, lines);
2058 }
57629833
GM
2059
2060 UNGCPRO;
dc6f92b8
JB
2061 return alist;
2062}
2063
ff11dfa1
JB
2064DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2065 Smodify_frame_parameters, 2, 2, 0,
2066 "Modify the parameters of frame FRAME according to ALIST.\n\
dc6f92b8
JB
2067ALIST is an alist of parameters to change and their new values.\n\
2068Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.\n\
e80f3932
RS
2069The meaningful PARMs depend on the kind of frame.\n\
2070Undefined PARMs are ignored, but stored in the frame's parameter list\n\
2071so that `frame-parameters' will return them.")
ff11dfa1
JB
2072 (frame, alist)
2073 Lisp_Object frame, alist;
dc6f92b8 2074{
fd0c2bd1 2075 FRAME_PTR f;
213bac8a 2076 register Lisp_Object tail, prop, val;
dc6f92b8 2077
ff11dfa1 2078 if (EQ (frame, Qnil))
8d2666fe
GM
2079 frame = selected_frame;
2080 CHECK_LIVE_FRAME (frame, 0);
2081 f = XFRAME (frame);
dc6f92b8 2082
dbc4e1c1 2083 /* I think this should be done with a hook. */
032d78fe
GV
2084#ifdef HAVE_WINDOW_SYSTEM
2085 if (FRAME_WINDOW_P (f))
fd0c2bd1 2086 x_set_frame_parameters (f, alist);
329ca574 2087 else
bb221971
RS
2088#endif
2089#ifdef MSDOS
2090 if (FRAME_MSDOS_P (f))
2091 IT_set_frame_parameters (f, alist);
2092 else
329ca574 2093#endif
574a1a90
RS
2094#ifdef macintosh
2095 if (FRAME_MAC_P (f))
2096 mac_set_frame_parameters (f, alist);
2097 else
2098#endif
2099
41d44f1f
RS
2100 {
2101 int length = XINT (Flength (alist));
2102 int i;
2103 Lisp_Object *parms
2104 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2105 Lisp_Object *values
2106 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2107
2108 /* Extract parm names and values into those vectors. */
2109
2110 i = 0;
2111 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2112 {
213bac8a 2113 Lisp_Object elt;
41d44f1f
RS
2114
2115 elt = Fcar (tail);
2116 parms[i] = Fcar (elt);
2117 values[i] = Fcdr (elt);
2118 i++;
2119 }
2120
2121 /* Now process them in reverse of specified order. */
2122 for (i--; i >= 0; i--)
2123 {
2124 prop = parms[i];
2125 val = values[i];
2126 store_frame_param (f, prop, val);
2127 }
2128 }
dc6f92b8
JB
2129
2130 return Qnil;
2131}
2132\f
a26a1f95
RS
2133DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2134 0, 1, 0,
2135 "Height in pixels of a line in the font in frame FRAME.\n\
2136If FRAME is omitted, the selected frame is used.\n\
2137For a terminal frame, the value is always 1.")
ff11dfa1
JB
2138 (frame)
2139 Lisp_Object frame;
dc6f92b8 2140{
a26a1f95 2141 struct frame *f;
dc6f92b8 2142
a26a1f95 2143 if (NILP (frame))
8d2666fe
GM
2144 frame = selected_frame;
2145 CHECK_FRAME (frame, 0);
2146 f = XFRAME (frame);
a26a1f95 2147
032d78fe
GV
2148#ifdef HAVE_WINDOW_SYSTEM
2149 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2150 return make_number (x_char_height (f));
2151 else
dc6d9681 2152#endif
a26a1f95
RS
2153 return make_number (1);
2154}
dc6d9681 2155
dc6f92b8 2156
a26a1f95
RS
2157DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2158 0, 1, 0,
2159 "Width in pixels of characters in the font in frame FRAME.\n\
2160If FRAME is omitted, the selected frame is used.\n\
2161The width is the same for all characters, because\n\
2162currently Emacs supports only fixed-width fonts.\n\
2163For a terminal screen, the value is always 1.")
2164 (frame)
2165 Lisp_Object frame;
dc6f92b8 2166{
a26a1f95
RS
2167 struct frame *f;
2168
2169 if (NILP (frame))
8d2666fe
GM
2170 frame = selected_frame;
2171 CHECK_FRAME (frame, 0);
2172 f = XFRAME (frame);
a26a1f95 2173
032d78fe
GV
2174#ifdef HAVE_WINDOW_SYSTEM
2175 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2176 return make_number (x_char_width (f));
2177 else
2178#endif
2179 return make_number (1);
dc6f92b8
JB
2180}
2181
a26a1f95
RS
2182DEFUN ("frame-pixel-height", Fframe_pixel_height,
2183 Sframe_pixel_height, 0, 1, 0,
164a14ef 2184 "Return a FRAME's height in pixels.\n\
07822795
RS
2185This counts only the height available for text lines,\n\
2186not menu bars on window-system Emacs frames.\n\
164a14ef 2187For a terminal frame, the result really gives the height in characters.\n\
a26a1f95
RS
2188If FRAME is omitted, the selected frame is used.")
2189 (frame)
2190 Lisp_Object frame;
dc6f92b8 2191{
a26a1f95
RS
2192 struct frame *f;
2193
2194 if (NILP (frame))
8d2666fe
GM
2195 frame = selected_frame;
2196 CHECK_FRAME (frame, 0);
2197 f = XFRAME (frame);
a26a1f95 2198
032d78fe
GV
2199#ifdef HAVE_WINDOW_SYSTEM
2200 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2201 return make_number (x_pixel_height (f));
2202 else
dc6d9681 2203#endif
a26a1f95
RS
2204 return make_number (FRAME_HEIGHT (f));
2205}
2206
2207DEFUN ("frame-pixel-width", Fframe_pixel_width,
2208 Sframe_pixel_width, 0, 1, 0,
2209 "Return FRAME's width in pixels.\n\
164a14ef 2210For a terminal frame, the result really gives the width in characters.\n\
a26a1f95
RS
2211If FRAME is omitted, the selected frame is used.")
2212 (frame)
2213 Lisp_Object frame;
2214{
2215 struct frame *f;
2216
2217 if (NILP (frame))
8d2666fe
GM
2218 frame = selected_frame;
2219 CHECK_FRAME (frame, 0);
2220 f = XFRAME (frame);
dc6f92b8 2221
032d78fe
GV
2222#ifdef HAVE_WINDOW_SYSTEM
2223 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2224 return make_number (x_pixel_width (f));
2225 else
2226#endif
2227 return make_number (FRAME_WIDTH (f));
2228}
2229\f
ff11dfa1
JB
2230DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2231 "Specify that the frame FRAME has LINES lines.\n\
dc6f92b8 2232Optional third arg non-nil means that redisplay should use LINES lines\n\
ff11dfa1 2233but that the idea of the actual height of the frame should not be changed.")
735eeca3
EN
2234 (frame, lines, pretend)
2235 Lisp_Object frame, lines, pretend;
dc6f92b8 2236{
ff11dfa1 2237 register struct frame *f;
dc6f92b8 2238
735eeca3 2239 CHECK_NUMBER (lines, 0);
ff11dfa1 2240 if (NILP (frame))
8d2666fe
GM
2241 frame = selected_frame;
2242 CHECK_LIVE_FRAME (frame, 0);
2243 f = XFRAME (frame);
dc6f92b8 2244
dbc4e1c1 2245 /* I think this should be done with a hook. */
032d78fe
GV
2246#ifdef HAVE_WINDOW_SYSTEM
2247 if (FRAME_WINDOW_P (f))
dc6f92b8 2248 {
735eeca3
EN
2249 if (XINT (lines) != f->height)
2250 x_set_window_size (f, 1, f->width, XINT (lines));
32347cf4 2251 do_pending_window_change (0);
dc6f92b8
JB
2252 }
2253 else
fd0c2bd1 2254#endif
32347cf4 2255 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
dc6f92b8
JB
2256 return Qnil;
2257}
2258
ff11dfa1
JB
2259DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2260 "Specify that the frame FRAME has COLS columns.\n\
dc6f92b8 2261Optional third arg non-nil means that redisplay should use COLS columns\n\
ff11dfa1
JB
2262but that the idea of the actual width of the frame should not be changed.")
2263 (frame, cols, pretend)
fd0c2bd1 2264 Lisp_Object frame, cols, pretend;
dc6f92b8 2265{
ff11dfa1 2266 register struct frame *f;
dc6f92b8 2267 CHECK_NUMBER (cols, 0);
ff11dfa1 2268 if (NILP (frame))
8d2666fe
GM
2269 frame = selected_frame;
2270 CHECK_LIVE_FRAME (frame, 0);
2271 f = XFRAME (frame);
dc6f92b8 2272
dbc4e1c1 2273 /* I think this should be done with a hook. */
032d78fe
GV
2274#ifdef HAVE_WINDOW_SYSTEM
2275 if (FRAME_WINDOW_P (f))
dc6f92b8 2276 {
ff11dfa1 2277 if (XINT (cols) != f->width)
808c0f20 2278 x_set_window_size (f, 1, XINT (cols), f->height);
32347cf4 2279 do_pending_window_change (0);
dc6f92b8
JB
2280 }
2281 else
fd0c2bd1 2282#endif
32347cf4 2283 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
dc6f92b8
JB
2284 return Qnil;
2285}
2286
ff11dfa1
JB
2287DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2288 "Sets size of FRAME to COLS by ROWS, measured in characters.")
2289 (frame, cols, rows)
2290 Lisp_Object frame, cols, rows;
dc6f92b8 2291{
ff11dfa1 2292 register struct frame *f;
dc6f92b8 2293
ff11dfa1 2294 CHECK_LIVE_FRAME (frame, 0);
dc6f92b8
JB
2295 CHECK_NUMBER (cols, 2);
2296 CHECK_NUMBER (rows, 1);
ff11dfa1 2297 f = XFRAME (frame);
dc6f92b8 2298
dbc4e1c1 2299 /* I think this should be done with a hook. */
032d78fe
GV
2300#ifdef HAVE_WINDOW_SYSTEM
2301 if (FRAME_WINDOW_P (f))
dc6f92b8 2302 {
29824ce2
RS
2303 if (XINT (rows) != f->height || XINT (cols) != f->width
2304 || FRAME_NEW_HEIGHT (f) || FRAME_NEW_WIDTH (f))
808c0f20 2305 x_set_window_size (f, 1, XINT (cols), XINT (rows));
32347cf4 2306 do_pending_window_change (0);
dc6f92b8
JB
2307 }
2308 else
fd0c2bd1 2309#endif
32347cf4 2310 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
dc6f92b8
JB
2311
2312 return Qnil;
2313}
2314
ff11dfa1
JB
2315DEFUN ("set-frame-position", Fset_frame_position,
2316 Sset_frame_position, 3, 3, 0,
2317 "Sets position of FRAME in pixels to XOFFSET by YOFFSET.\n\
60bf8ee4
RS
2318This is actually the position of the upper left corner of the frame.\n\
2319Negative values for XOFFSET or YOFFSET are interpreted relative to\n\
4524cb1c 2320the rightmost or bottommost possible position (that stays within the screen).")
ff11dfa1
JB
2321 (frame, xoffset, yoffset)
2322 Lisp_Object frame, xoffset, yoffset;
dc6f92b8 2323{
ff11dfa1 2324 register struct frame *f;
dc6f92b8 2325
ff11dfa1 2326 CHECK_LIVE_FRAME (frame, 0);
dc6f92b8
JB
2327 CHECK_NUMBER (xoffset, 1);
2328 CHECK_NUMBER (yoffset, 2);
ff11dfa1 2329 f = XFRAME (frame);
dc6f92b8 2330
dbc4e1c1 2331 /* I think this should be done with a hook. */
032d78fe
GV
2332#ifdef HAVE_WINDOW_SYSTEM
2333 if (FRAME_WINDOW_P (f))
c7c70761 2334 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
fd0c2bd1 2335#endif
dc6f92b8
JB
2336
2337 return Qt;
2338}
dc6d9681 2339
dc6f92b8 2340\f
dfcf069d 2341void
ff11dfa1 2342syms_of_frame ()
dc6f92b8 2343{
a249de79 2344 syms_of_frame_1 ();
dc6f92b8 2345
ff11dfa1 2346 staticpro (&Vframe_list);
dc6f92b8 2347
ff11dfa1
JB
2348 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
2349 "The initial frame-object, which represents Emacs's stdout.");
dc6f92b8
JB
2350
2351 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
ff11dfa1 2352 "Non-nil if all of emacs is iconified and frame updates are not needed.");
dc6f92b8
JB
2353 Vemacs_iconified = Qnil;
2354
beb0bc36
DL
2355 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
2356 "If non-nil, function applied to the normal result of `mouse-position'.\n\
2357This abnormal hook exists for the benefit of packages like XTerm-mouse\n\
2358which need to do mouse handling at the Lisp level.");
2359 Vmouse_position_function = Qnil;
2360
c60f3a6a 2361 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
ff11dfa1 2362 "Minibufferless frames use this frame's minibuffer.\n\
f9898cc6 2363\n\
ff11dfa1 2364Emacs cannot create minibufferless frames unless this is set to an\n\
f9898cc6
JB
2365appropriate surrogate.\n\
2366\n\
2367Emacs consults this variable only when creating minibufferless\n\
ff11dfa1 2368frames; once the frame is created, it sticks with its assigned\n\
f9898cc6
JB
2369minibuffer, no matter what this variable is set to. This means that\n\
2370this variable doesn't necessarily say anything meaningful about the\n\
ff11dfa1 2371current set of frames, or where the minibuffer is currently being\n\
f9898cc6 2372displayed.");
dc6f92b8 2373
5add3885 2374 defsubr (&Sactive_minibuffer_window);
ff11dfa1 2375 defsubr (&Sframep);
dbc4e1c1 2376 defsubr (&Sframe_live_p);
bb1513c9 2377 defsubr (&Smake_terminal_frame);
0f85737c 2378 defsubr (&Shandle_switch_frame);
1c212787 2379 defsubr (&Signore_event);
ff11dfa1
JB
2380 defsubr (&Sselect_frame);
2381 defsubr (&Sselected_frame);
2382 defsubr (&Swindow_frame);
2383 defsubr (&Sframe_root_window);
d446a856 2384 defsubr (&Sframe_first_window);
ff11dfa1 2385 defsubr (&Sframe_selected_window);
4a7cfafc 2386 defsubr (&Sset_frame_selected_window);
ff11dfa1
JB
2387 defsubr (&Sframe_list);
2388 defsubr (&Snext_frame);
ef2c57ac 2389 defsubr (&Sprevious_frame);
ff11dfa1 2390 defsubr (&Sdelete_frame);
f9898cc6 2391 defsubr (&Smouse_position);
152e6c70 2392 defsubr (&Smouse_pixel_position);
dc6f92b8 2393 defsubr (&Sset_mouse_position);
152e6c70 2394 defsubr (&Sset_mouse_pixel_position);
dc6f92b8 2395#if 0
ff11dfa1
JB
2396 defsubr (&Sframe_configuration);
2397 defsubr (&Srestore_frame_configuration);
dc6f92b8 2398#endif
ff11dfa1
JB
2399 defsubr (&Smake_frame_visible);
2400 defsubr (&Smake_frame_invisible);
2401 defsubr (&Siconify_frame);
2402 defsubr (&Sframe_visible_p);
2403 defsubr (&Svisible_frame_list);
b49f5578
JB
2404 defsubr (&Sraise_frame);
2405 defsubr (&Slower_frame);
ff11dfa1
JB
2406 defsubr (&Sredirect_frame_focus);
2407 defsubr (&Sframe_focus);
2408 defsubr (&Sframe_parameters);
2409 defsubr (&Smodify_frame_parameters);
a26a1f95
RS
2410 defsubr (&Sframe_char_height);
2411 defsubr (&Sframe_char_width);
2412 defsubr (&Sframe_pixel_height);
2413 defsubr (&Sframe_pixel_width);
ff11dfa1
JB
2414 defsubr (&Sset_frame_height);
2415 defsubr (&Sset_frame_width);
2416 defsubr (&Sset_frame_size);
2417 defsubr (&Sset_frame_position);
dc6f92b8 2418}
e5d77022 2419
dfcf069d 2420void
2f0b07e0
JB
2421keys_of_frame ()
2422{
0f85737c 2423 initial_define_lispy_key (global_map, "switch-frame", "handle-switch-frame");
d134b17b 2424 initial_define_lispy_key (global_map, "delete-frame", "handle-delete-frame");
1c212787
KH
2425 initial_define_lispy_key (global_map, "iconify-frame", "ignore-event");
2426 initial_define_lispy_key (global_map, "make-frame-visible", "ignore-event");
2f0b07e0 2427}