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