Overhaul and simplify single_kboard API. Allow calls to `recursive-edit' in process...
[bpt/emacs.git] / src / frame.c
CommitLineData
ff11dfa1 1/* Generic frame functions.
0b5538bd
TTN
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005 Free Software Foundation, Inc.
dc6f92b8
JB
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
1113d9db 9the Free Software Foundation; either version 2, or (at your option)
dc6f92b8
JB
10any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
4fc5845f
LK
19the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20Boston, MA 02110-1301, USA. */
dc6f92b8 21
18160b98 22#include <config.h>
565620a5
RS
23
24#include <stdio.h>
cc38027b 25#include "lisp.h"
71025e5e 26#include "charset.h"
6d55d620 27#ifdef HAVE_X_WINDOWS
dfcf069d 28#include "xterm.h"
71025e5e 29#endif
8f23f280
AI
30#ifdef WINDOWSNT
31#include "w32term.h"
32#endif
e0f712ba 33#ifdef MAC_OS
1a578e9b
AC
34#include "macterm.h"
35#endif
2538fae4
AI
36#include "buffer.h"
37/* These help us bind and responding to switch-frame events. */
38#include "commands.h"
39#include "keyboard.h"
cc38027b 40#include "frame.h"
a1dfb88a
KH
41#ifdef HAVE_WINDOW_SYSTEM
42#include "fontset.h"
43#endif
972f4259 44#include "blockinput.h"
28d440ab 45#include "termchar.h"
bc1ed486 46#include "termhooks.h"
dfcf069d 47#include "dispextern.h"
f769f1b2 48#include "window.h"
87485d6f
MW
49#ifdef MSDOS
50#include "msdos.h"
4aec4b29 51#include "dosfns.h"
87485d6f 52#endif
e5d77022 53
972f4259 54
2731a0ad
KS
55#ifdef HAVE_WINDOW_SYSTEM
56
972f4259
KS
57/* The name we're using in resource queries. Most often "emacs". */
58
59Lisp_Object Vx_resource_name;
60
61/* The application class we're using in resource queries.
62 Normally "Emacs". */
63
64Lisp_Object Vx_resource_class;
65
2731a0ad 66#endif
972f4259
KS
67
68Lisp_Object Qframep, Qframe_live_p;
69Lisp_Object Qicon, Qmodeline;
fd0c2bd1 70Lisp_Object Qonly;
972f4259 71Lisp_Object Qx, Qw32, Qmac, Qpc;
f7af3f7b 72Lisp_Object Qvisible;
8b60f7bc 73Lisp_Object Qdisplay_type;
6345f6aa 74Lisp_Object Qbackground_mode;
3df1fda2 75Lisp_Object Qinhibit_default_face_x_resources;
972f4259
KS
76
77Lisp_Object Qx_frame_parameter;
78Lisp_Object Qx_resource_name;
6ed8eeff
KL
79Lisp_Object Qterminal;
80Lisp_Object Qterminal_live_p;
972f4259
KS
81
82/* Frame parameters (set or reported). */
83
84Lisp_Object Qauto_raise, Qauto_lower;
85Lisp_Object Qborder_color, Qborder_width;
86Lisp_Object Qcursor_color, Qcursor_type;
87Lisp_Object Qgeometry; /* Not used */
88Lisp_Object Qheight, Qwidth;
89Lisp_Object Qleft, Qright;
90Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
91Lisp_Object Qinternal_border_width;
92Lisp_Object Qmouse_color;
93Lisp_Object Qminibuffer;
94Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
95Lisp_Object Qvisibility;
96Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
97Lisp_Object Qscreen_gamma;
98Lisp_Object Qline_spacing;
99Lisp_Object Quser_position, Quser_size;
100Lisp_Object Qwait_for_wm;
101Lisp_Object Qwindow_id;
102#ifdef HAVE_X_WINDOWS
103Lisp_Object Qouter_window_id;
104#endif
105Lisp_Object Qparent_id;
106Lisp_Object Qtitle, Qname;
107Lisp_Object Qunsplittable;
108Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
109Lisp_Object Qleft_fringe, Qright_fringe;
a18b8cb5 110Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list;
94674d18 111Lisp_Object Qtty_color_mode;
28d440ab 112Lisp_Object Qtty, Qtty_type;
7f19e125 113Lisp_Object Qwindow_system;
da8e8fc1 114Lisp_Object Qenvironment;
dc6f92b8 115
972f4259
KS
116Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
117
118Lisp_Object Qface_set_after_frame_default;
119
daf01701 120Lisp_Object Vterminal_frame;
a1aaa23f 121Lisp_Object Vdefault_frame_alist;
a6e20602 122Lisp_Object Vdefault_frame_scroll_bars;
beb0bc36 123Lisp_Object Vmouse_position_function;
6018080f 124Lisp_Object Vmouse_highlight;
cd1d850f 125Lisp_Object Vdelete_frame_functions;
a249de79
RS
126\f
127static void
128set_menu_bar_lines_1 (window, n)
daf01701
KL
129 Lisp_Object window;
130 int n;
a249de79
RS
131{
132 struct window *w = XWINDOW (window);
133
57aeea1e 134 XSETFASTINT (w->last_modified, 0);
5af5757b
KS
135 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
136 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
177c0ea7 137
5af5757b
KS
138 if (INTEGERP (w->orig_top_line))
139 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
140 if (INTEGERP (w->orig_total_lines))
141 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
a249de79
RS
142
143 /* Handle just the top child in a vertical split. */
144 if (!NILP (w->vchild))
145 set_menu_bar_lines_1 (w->vchild, n);
146
147 /* Adjust all children in a horizontal split. */
148 for (window = w->hchild; !NILP (window); window = w->next)
149 {
150 w = XWINDOW (window);
151 set_menu_bar_lines_1 (window, n);
152 }
153}
154
e48f782c 155void
a249de79
RS
156set_menu_bar_lines (f, value, oldval)
157 struct frame *f;
158 Lisp_Object value, oldval;
159{
160 int nlines;
161 int olines = FRAME_MENU_BAR_LINES (f);
162
163 /* Right now, menu bars don't work properly in minibuf-only frames;
164 most of the commands try to apply themselves to the minibuffer
e3678b64 165 frame itself, and get an error because you can't switch buffers
a249de79
RS
166 in or split the minibuffer window. */
167 if (FRAME_MINIBUF_ONLY_P (f))
168 return;
169
170 if (INTEGERP (value))
171 nlines = XINT (value);
172 else
173 nlines = 0;
174
57aeea1e
RS
175 if (nlines != olines)
176 {
177 windows_or_buffers_changed++;
178 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
179 FRAME_MENU_BAR_LINES (f) = nlines;
180 set_menu_bar_lines_1 (f->root_window, nlines - olines);
18082e2d 181 adjust_glyphs (f);
57aeea1e 182 }
a249de79
RS
183}
184\f
a249de79
RS
185Lisp_Object Vemacs_iconified;
186Lisp_Object Vframe_list;
a249de79 187
dc6f92b8
JB
188extern Lisp_Object Vminibuffer_list;
189extern Lisp_Object get_minibuffer ();
84386599
RS
190extern Lisp_Object Fhandle_switch_frame ();
191extern Lisp_Object Fredirect_frame_focus ();
a54d3a73 192extern Lisp_Object x_get_focus_frame ();
dc6f92b8 193\f
ff11dfa1 194DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
14ff1ee0
PJ
195 doc: /* Return non-nil if OBJECT is a frame.
196Value is t for a termcap frame (a character-only terminal),
197`x' for an Emacs frame that is really an X window,
198`w32' for an Emacs frame that is a window on MS-Windows display,
199`mac' for an Emacs frame on a Macintosh display,
200`pc' for a direct-write MS-DOS frame.
201See also `frame-live-p'. */)
202 (object)
f9898cc6 203 Lisp_Object object;
dc6f92b8 204{
e35d291d 205 if (!FRAMEP (object))
dc6f92b8 206 return Qnil;
ff11dfa1 207 switch (XFRAME (object)->output_method)
dc6f92b8 208 {
3224dac1 209 case output_initial: /* The initial frame is like a termcap frame. */
dc6f92b8
JB
210 case output_termcap:
211 return Qt;
212 case output_x_window:
fd0c2bd1 213 return Qx;
fbd6baed
GV
214 case output_w32:
215 return Qw32;
bb221971
RS
216 case output_msdos_raw:
217 return Qpc;
574a1a90
RS
218 case output_mac:
219 return Qmac;
dc6f92b8
JB
220 default:
221 abort ();
222 }
223}
224
dbc4e1c1 225DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
14ff1ee0
PJ
226 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
227Value is nil if OBJECT is not a live frame. If object is a live
6ed8eeff 228frame, the return value indicates what sort of terminal device it is
f6fa0866 229displayed on. See the documentation of `framep' for possible
4e10df59 230return values. */)
14ff1ee0 231 (object)
f9898cc6
JB
232 Lisp_Object object;
233{
ff11dfa1
JB
234 return ((FRAMEP (object)
235 && FRAME_LIVE_P (XFRAME (object)))
236 ? Fframep (object)
f9898cc6
JB
237 : Qnil);
238}
239
428a555e
KL
240DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
241 doc: /* The name of the window system that FRAME is displaying through.
242The value is a symbol---for instance, 'x' for X windows.
243The value is nil if Emacs is using a text-only terminal.
244
245FRAME defaults to the currently selected frame. */)
246 (frame)
247 Lisp_Object frame;
248{
249 Lisp_Object type;
250 if (NILP (frame))
251 frame = selected_frame;
252
253 type = Fframep (frame);
254
255 if (NILP (type))
256 wrong_type_argument (Qframep, frame);
257
258 if (EQ (type, Qt))
259 return Qnil;
260 else
261 return type;
262}
263
ff11dfa1
JB
264struct frame *
265make_frame (mini_p)
dc6f92b8
JB
266 int mini_p;
267{
ff11dfa1
JB
268 Lisp_Object frame;
269 register struct frame *f;
dc6f92b8
JB
270 register Lisp_Object root_window;
271 register Lisp_Object mini_window;
e9c96c62
GM
272
273 f = allocate_frame ();
36af7d69 274 XSETFRAME (frame, f);
ff11dfa1 275
18082e2d
GM
276 f->desired_matrix = 0;
277 f->current_matrix = 0;
278 f->desired_pool = 0;
279 f->current_pool = 0;
280 f->glyphs_initialized_p = 0;
281 f->decode_mode_spec_buffer = 0;
ff11dfa1 282 f->visible = 0;
323405de 283 f->async_visible = 0;
7556890b 284 f->output_data.nothing = 0;
ff11dfa1 285 f->iconified = 0;
323405de 286 f->async_iconified = 0;
ff11dfa1
JB
287 f->wants_modeline = 1;
288 f->auto_raise = 0;
289 f->auto_lower = 0;
290 f->no_split = 0;
10689a01 291 f->garbaged = 1;
ff11dfa1 292 f->has_minibuffer = mini_p;
a42e9724 293 f->focus_frame = Qnil;
804518aa 294 f->explicit_name = 0;
fd2777e0 295 f->can_have_scroll_bars = 0;
3a43d2dd 296 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
ff11dfa1 297 f->param_alist = Qnil;
fd2777e0
JB
298 f->scroll_bars = Qnil;
299 f->condemned_scroll_bars = Qnil;
306cc902 300 f->face_alist = Qnil;
18082e2d 301 f->face_cache = NULL;
9dd935ee 302 f->menu_bar_items = Qnil;
c8b8e7e3
RS
303 f->menu_bar_vector = Qnil;
304 f->menu_bar_items_used = 0;
329ca574 305 f->buffer_predicate = Qnil;
fa54c6ae 306 f->buffer_list = Qnil;
a18b8cb5 307 f->buried_buffer_list = Qnil;
aec6e486 308 f->namebuf = 0;
2b1c9cfb 309 f->title = Qnil;
18082e2d 310 f->menu_bar_window = Qnil;
9ea173e8 311 f->tool_bar_window = Qnil;
61752261 312 f->tool_bar_items = Qnil;
9ea173e8 313 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
61752261 314 f->n_tool_bar_items = 0;
5af5757b
KS
315 f->left_fringe_width = f->right_fringe_width = 0;
316 f->fringe_cols = 0;
317 f->scroll_bar_actual_width = 0;
318 f->border_width = 0;
319 f->internal_border_width = 0;
320 f->column_width = 1; /* !FRAME_WINDOW_P value */
321 f->line_height = 1; /* !FRAME_WINDOW_P value */
322 f->x_pixels_diff = f->y_pixels_diff = 0;
93421a1f 323#ifdef HAVE_WINDOW_SYSTEM
5af5757b 324 f->want_fullscreen = FULLSCREEN_NONE;
93421a1f 325#endif
5af5757b
KS
326 f->size_hint_flags = 0;
327 f->win_gravity = 0;
dc6f92b8 328
cc38027b 329 root_window = make_window ();
dc6f92b8
JB
330 if (mini_p)
331 {
cc38027b 332 mini_window = make_window ();
dc6f92b8
JB
333 XWINDOW (root_window)->next = mini_window;
334 XWINDOW (mini_window)->prev = root_window;
335 XWINDOW (mini_window)->mini_p = Qt;
ff11dfa1
JB
336 XWINDOW (mini_window)->frame = frame;
337 f->minibuffer_window = mini_window;
dc6f92b8
JB
338 }
339 else
340 {
341 mini_window = Qnil;
342 XWINDOW (root_window)->next = Qnil;
ff11dfa1 343 f->minibuffer_window = Qnil;
dc6f92b8
JB
344 }
345
ff11dfa1 346 XWINDOW (root_window)->frame = frame;
dc6f92b8
JB
347
348 /* 10 is arbitrary,
349 just so that there is "something there."
ff11dfa1 350 Correct size will be set up later with change_frame_size. */
dc6f92b8 351
5af5757b
KS
352 SET_FRAME_COLS (f, 10);
353 FRAME_LINES (f) = 10;
dc6f92b8 354
5af5757b
KS
355 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
356 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
dc6f92b8
JB
357
358 if (mini_p)
359 {
5af5757b
KS
360 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
361 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
362 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
dc6f92b8
JB
363 }
364
ff11dfa1 365 /* Choose a buffer for the frame's root window. */
5bce042c
JB
366 {
367 Lisp_Object buf;
368
369 XWINDOW (root_window)->buffer = Qt;
370 buf = Fcurrent_buffer ();
371 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
372 a space), try to find another one. */
d5db4077 373 if (SREF (Fbuffer_name (buf), 0) == ' ')
98ce1622 374 buf = Fother_buffer (buf, Qnil, Qnil);
fa54c6ae 375
18082e2d
GM
376 /* Use set_window_buffer, not Fset_window_buffer, and don't let
377 hooks be run by it. The reason is that the whole frame/window
378 arrangement is not yet fully intialized at this point. Windows
379 don't have the right size, glyph matrices aren't initialized
380 etc. Running Lisp functions at this point surely ends in a
381 SEGV. */
5af5757b 382 set_window_buffer (root_window, buf, 0, 0);
fa54c6ae 383 f->buffer_list = Fcons (buf, Qnil);
5bce042c
JB
384 }
385
dc6f92b8
JB
386 if (mini_p)
387 {
388 XWINDOW (mini_window)->buffer = Qt;
18082e2d
GM
389 set_window_buffer (mini_window,
390 (NILP (Vminibuffer_list)
391 ? get_minibuffer (0)
392 : Fcar (Vminibuffer_list)),
5af5757b 393 0, 0);
dc6f92b8
JB
394 }
395
ff11dfa1
JB
396 f->root_window = root_window;
397 f->selected_window = root_window;
d5e7c279
JB
398 /* Make sure this window seems more recently used than
399 a newly-created, never-selected window. */
2a1893f4
SM
400 ++window_select_count;
401 XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
dc6f92b8 402
a5f696ac
JD
403 f->default_face_done_p = 0;
404
ff11dfa1 405 return f;
dc6f92b8
JB
406}
407\f
bba88bb1 408#ifdef HAVE_WINDOW_SYSTEM
ff11dfa1 409/* Make a frame using a separate minibuffer window on another frame.
dc6f92b8
JB
410 MINI_WINDOW is the minibuffer window to use. nil means use the
411 default (the global minibuffer). */
412
ff11dfa1 413struct frame *
b0660239 414make_frame_without_minibuffer (mini_window, kb, display)
dc6f92b8 415 register Lisp_Object mini_window;
662ac59a 416 KBOARD *kb;
b0660239 417 Lisp_Object display;
dc6f92b8 418{
ff11dfa1 419 register struct frame *f;
363b873b 420 struct gcpro gcpro1;
dc6f92b8 421
b0660239 422 if (!NILP (mini_window))
b7826503 423 CHECK_LIVE_WINDOW (mini_window);
dc6f92b8 424
662ac59a 425#ifdef MULTI_KBOARD
b0660239 426 if (!NILP (mini_window)
6ed8eeff
KL
427 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
428 error ("Frame and minibuffer must be on the same terminal");
662ac59a
KH
429#endif
430
ff11dfa1
JB
431 /* Make a frame containing just a root window. */
432 f = make_frame (0);
dc6f92b8 433
b0660239
KH
434 if (NILP (mini_window))
435 {
436 /* Use default-minibuffer-frame if possible. */
437 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
438 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
439 {
363b873b
RS
440 Lisp_Object frame_dummy;
441
442 XSETFRAME (frame_dummy, f);
443 GCPRO1 (frame_dummy);
b0660239 444 /* If there's no minibuffer frame to use, create one. */
363b873b
RS
445 kb->Vdefault_minibuffer_frame =
446 call1 (intern ("make-initial-minibuffer-frame"), display);
447 UNGCPRO;
b0660239 448 }
177c0ea7 449
b0660239
KH
450 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
451 }
a2812a26 452
ff11dfa1 453 f->minibuffer_window = mini_window;
a2812a26
RS
454
455 /* Make the chosen minibuffer window display the proper minibuffer,
456 unless it is already showing a minibuffer. */
457 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
458 Fset_window_buffer (mini_window,
459 (NILP (Vminibuffer_list)
460 ? get_minibuffer (0)
5af5757b 461 : Fcar (Vminibuffer_list)), Qnil);
ff11dfa1 462 return f;
dc6f92b8
JB
463}
464
ff11dfa1 465/* Make a frame containing only a minibuffer window. */
dc6f92b8 466
ff11dfa1
JB
467struct frame *
468make_minibuffer_frame ()
dc6f92b8 469{
ff11dfa1 470 /* First make a frame containing just a root window, no minibuffer. */
dc6f92b8 471
ff11dfa1 472 register struct frame *f = make_frame (0);
dc6f92b8 473 register Lisp_Object mini_window;
ff11dfa1 474 register Lisp_Object frame;
dc6f92b8 475
2d80a27a 476 XSETFRAME (frame, f);
dc6f92b8 477
804518aa 478 f->auto_raise = 0;
ff11dfa1
JB
479 f->auto_lower = 0;
480 f->no_split = 1;
481 f->wants_modeline = 0;
482 f->has_minibuffer = 1;
dc6f92b8
JB
483
484 /* Now label the root window as also being the minibuffer.
485 Avoid infinite looping on the window chain by marking next pointer
486 as nil. */
487
ff11dfa1 488 mini_window = f->minibuffer_window = f->root_window;
dc6f92b8
JB
489 XWINDOW (mini_window)->mini_p = Qt;
490 XWINDOW (mini_window)->next = Qnil;
804518aa 491 XWINDOW (mini_window)->prev = Qnil;
ff11dfa1 492 XWINDOW (mini_window)->frame = frame;
dc6f92b8
JB
493
494 /* Put the proper buffer in that window. */
495
496 Fset_window_buffer (mini_window,
265a9e55 497 (NILP (Vminibuffer_list)
dc6f92b8 498 ? get_minibuffer (0)
5af5757b 499 : Fcar (Vminibuffer_list)), Qnil);
ff11dfa1 500 return f;
dc6f92b8 501}
bba88bb1 502#endif /* HAVE_WINDOW_SYSTEM */
dc6f92b8 503\f
28d440ab 504/* Construct a frame that refers to a terminal. */
dc6f92b8 505
6ed8eeff 506static int tty_frame_count;
bb1513c9 507
ff11dfa1 508struct frame *
3224dac1 509make_initial_frame (void)
dc6f92b8 510{
3224dac1 511 struct frame *f;
6ed8eeff 512 struct terminal *terminal;
d063751a 513 Lisp_Object frame;
3224dac1 514
b4f0ee5d 515#ifdef MULTI_KBOARD
7b00d185 516 /* Create the initial keyboard. */
b4f0ee5d
KH
517 if (!initial_kboard)
518 {
519 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
520 init_kboard (initial_kboard);
a1b658dd
KH
521 initial_kboard->next_kboard = all_kboards;
522 all_kboards = initial_kboard;
b4f0ee5d
KH
523 }
524#endif
525
bb1513c9
RS
526 /* The first call must initialize Vframe_list. */
527 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
528 Vframe_list = Qnil;
ff11dfa1 529
6ed8eeff 530 terminal = init_initial_terminal ();
3224dac1
KL
531
532 f = make_frame (1);
533 XSETFRAME (frame, f);
534
535 Vframe_list = Fcons (frame, Vframe_list);
536
6ed8eeff 537 tty_frame_count = 1;
3224dac1
KL
538 f->name = build_string ("F1");
539
540 f->visible = 1;
541 f->async_visible = 1;
542
6ed8eeff
KL
543 f->output_method = terminal->type;
544 f->terminal = terminal;
545 f->terminal->reference_count++;
3224dac1
KL
546 f->output_data.nothing = 0;
547
548 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
549 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
550
551 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
552 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
553
3224dac1
KL
554 return f;
555}
556
557
558struct frame *
6ed8eeff 559make_terminal_frame (struct terminal *terminal)
3224dac1
KL
560{
561 register struct frame *f;
3224dac1
KL
562 Lisp_Object frame;
563 char name[20];
564
ff11dfa1 565 f = make_frame (1);
d063751a 566
2d80a27a 567 XSETFRAME (frame, f);
d063751a
RS
568 Vframe_list = Fcons (frame, Vframe_list);
569
6ed8eeff
KL
570 tty_frame_count++;
571 sprintf (name, "F%d", tty_frame_count);
0303e8da 572 f->name = build_string (name);
bb1513c9 573
bb1513c9
RS
574 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
575 f->async_visible = 1; /* Don't let visible be cleared later. */
bb221971
RS
576#ifdef MSDOS
577 f->output_data.x = &the_only_x_display;
2d764c78
EZ
578 if (!inhibit_window_system
579 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
580 || XFRAME (selected_frame)->output_method == output_msdos_raw))
65606f5e
EZ
581 {
582 f->output_method = output_msdos_raw;
583 /* This initialization of foreground and background pixels is
584 only important for the initial frame created in temacs. If
585 we don't do that, we get black background and foreground in
586 the dumped Emacs because the_only_x_display is a static
587 variable, hence it is born all-zeroes, and zero is the code
588 for the black color. Other frames all inherit their pixels
589 from what's already in the_only_x_display. */
590 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
591 && f->output_data.x->background_pixel == 0
592 && f->output_data.x->foreground_pixel == 0)
593 {
594 f->output_data.x->background_pixel = FACE_TTY_DEFAULT_BG_COLOR;
595 f->output_data.x->foreground_pixel = FACE_TTY_DEFAULT_FG_COLOR;
596 }
597 }
2d764c78
EZ
598 else
599 f->output_method = output_termcap;
600#else
4ec0d3c1 601#ifdef WINDOWSNT
ff8d4bf4 602 f->output_method = output_termcap;
428a555e 603 f->output_data.x = &tty_display; /* XXX ??? */
4ec0d3c1 604#else
e0f712ba 605#ifdef MAC_OS8
1a578e9b
AC
606 make_mac_terminal_frame (f);
607#else
0a125897 608 {
0a125897 609 f->output_method = output_termcap;
6ed8eeff
KL
610 f->terminal = terminal;
611 f->terminal->reference_count++;
428a555e
KL
612 create_tty_output (f);
613
28d7d09f
KL
614 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
615 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
0a125897 616
428a555e
KL
617 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
618 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
619
428a555e 620 /* Set the top frame to the newly created frame. */
114a8b8c
KL
621 if (FRAME_TTY (f)->top_frame
622 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
623 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
624
428a555e 625 FRAME_TTY (f)->top_frame = frame;
0a125897
KL
626 }
627
58bd8318
KS
628#ifdef CANNOT_DUMP
629 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
630 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
631#endif
e0f712ba 632#endif /* MAC_OS8 */
4ec0d3c1 633#endif /* WINDOWSNT */
2d764c78 634#endif /* MSDOS */
574a1a90 635
1a6d3623
EZ
636 if (!noninteractive)
637 init_frame_faces (f);
1a578e9b 638
ff11dfa1 639 return f;
dc6f92b8 640}
bb1513c9 641
ed8dad6b
KL
642/* Get a suitable value for frame parameter PARAMETER for a newly
643 created frame, based on (1) the user-supplied frame parameter
644 alist SUPPLIED_PARMS, (2) CURRENT_VALUE, and finally, if all else
645 fails, (3) Vdefault_frame_alist. */
646
647static Lisp_Object
648get_future_frame_param (Lisp_Object parameter,
649 Lisp_Object supplied_parms,
650 char *current_value)
651{
652 Lisp_Object result;
653
654 result = Fassq (parameter, supplied_parms);
655 if (NILP (result))
656 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
657 if (NILP (result) && current_value != NULL)
658 result = build_string (current_value);
659 if (NILP (result))
660 result = Fassq (parameter, Vdefault_frame_alist);
661 if (!NILP (result) && !STRINGP (result))
662 result = XCDR (result);
663 if (NILP (result) || !STRINGP (result))
664 result = Qnil;
665
666 return result;
667}
668
bb1513c9 669DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
14ff1ee0 670 1, 1, 0,
28d440ab 671 doc: /* Create an additional terminal frame, possibly on another terminal.
14ff1ee0 672This function takes one argument, an alist specifying frame parameters.
28d440ab
KL
673
674You can create multiple frames on a single text-only terminal, but
675only one of them (the selected terminal frame) is actually displayed.
676
677In practice, generally you don't need to specify any parameters,
678except when you want to create a new frame on another terminal.
679In that case, the `tty' parameter specifies the device file to open,
680and the `tty-type' parameter specifies the terminal type. Example:
681
682 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
683
0b0d3e0b
KL
684Note that changing the size of one terminal frame automatically
685affects all frames on the same terminal device. */)
14ff1ee0 686 (parms)
bb1513c9
RS
687 Lisp_Object parms;
688{
689 struct frame *f;
6ed8eeff 690 struct terminal *t = NULL;
574a1a90 691 Lisp_Object frame, tem;
8d2666fe 692 struct frame *sf = SELECTED_FRAME ();
bb1513c9 693
541580aa 694#ifdef MSDOS
2d764c78
EZ
695 if (sf->output_method != output_msdos_raw
696 && sf->output_method != output_termcap)
bb221971 697 abort ();
574a1a90
RS
698#else /* not MSDOS */
699
e0f712ba 700#ifdef MAC_OS
8d2666fe 701 if (sf->output_method != output_mac)
574a1a90 702 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
bb221971 703#else
daf01701 704#if 0 /* This should work now! */
8d2666fe 705 if (sf->output_method != output_termcap)
bb1513c9 706 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
bb221971 707#endif
daf01701 708#endif
574a1a90 709#endif /* not MSDOS */
b6660415
KL
710
711 {
6ed8eeff 712 Lisp_Object terminal;
bb1513c9 713
6ed8eeff
KL
714 terminal = Fassq (Qterminal, parms);
715 if (!NILP (terminal))
28d440ab 716 {
6ed8eeff
KL
717 terminal = XCDR (terminal);
718 t = get_terminal (terminal, 1);
28d440ab 719 }
28d440ab 720 }
b6660415 721
6ed8eeff 722 if (!t)
b6660415 723 {
b6660415 724 char *name = 0, *type = 0;
ed8dad6b 725 Lisp_Object tty, tty_type;
b6660415 726
ed8dad6b
KL
727 tty = get_future_frame_param
728 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
729 ? FRAME_TTY (XFRAME (selected_frame))->name
730 : NULL));
731 if (!NILP (tty))
b6660415
KL
732 {
733 name = (char *) alloca (SBYTES (tty) + 1);
734 strncpy (name, SDATA (tty), SBYTES (tty));
735 name[SBYTES (tty)] = 0;
736 }
737
ed8dad6b
KL
738 tty_type = get_future_frame_param
739 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
740 ? FRAME_TTY (XFRAME (selected_frame))->type
741 : NULL));
742 if (!NILP (tty_type))
b6660415
KL
743 {
744 type = (char *) alloca (SBYTES (tty_type) + 1);
745 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
746 type[SBYTES (tty_type)] = 0;
747 }
748
6ed8eeff 749 t = init_tty (name, type, 0); /* Errors are not fatal. */
b6660415
KL
750 }
751
6ed8eeff 752 f = make_terminal_frame (t);
574a1a90 753
9628b887
KL
754 {
755 int width, height;
0b0d3e0b 756 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
9628b887
KL
757 change_frame_size (f, height, width, 0, 0, 0);
758 }
759
18082e2d 760 adjust_glyphs (f);
bb1513c9
RS
761 calculate_costs (f);
762 XSETFRAME (frame, f);
8adfc1ec 763 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
bb1513c9 764 Fmodify_frame_parameters (frame, parms);
7f19e125 765 Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qnil), Qnil));
ed8dad6b 766 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
6ed8eeff 767 build_string (t->display_info.tty->type)),
ed8dad6b
KL
768 Qnil));
769 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
6ed8eeff 770 build_string (t->display_info.tty->name)),
ed8dad6b 771 Qnil));
5b65d888 772
87f1940e
EZ
773 /* Make the frame face alist be frame-specific, so that each
774 frame could change its face definitions independently. */
8d2666fe 775 f->face_alist = Fcopy_alist (sf->face_alist);
87f1940e
EZ
776 /* Simple Fcopy_alist isn't enough, because we need the contents of
777 the vectors which are the CDRs of associations in face_alist to
778 be copied as well. */
779 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
f3fbd155 780 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
bb1513c9
RS
781 return frame;
782}
1e8324d9 783
dc6f92b8 784\f
1e8324d9
GM
785/* Perform the switch to frame FRAME.
786
787 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
788 FRAME1 as frame.
789
790 If TRACK is non-zero and the frame that currently has the focus
791 redirects its focus to the selected frame, redirect that focused
792 frame's focus to FRAME instead.
793
794 FOR_DELETION non-zero means that the selected frame is being
6ed8eeff 795 deleted, which includes the possibility that the frame's terminal
1e8324d9
GM
796 is dead. */
797
61f94483 798Lisp_Object
1e8324d9
GM
799do_switch_frame (frame, track, for_deletion)
800 Lisp_Object frame;
801 int track, for_deletion;
dc6f92b8 802{
8d2666fe 803 struct frame *sf = SELECTED_FRAME ();
177c0ea7 804
2f0b07e0
JB
805 /* If FRAME is a switch-frame event, extract the frame we should
806 switch to. */
807 if (CONSP (frame)
7539e11f
KR
808 && EQ (XCAR (frame), Qswitch_frame)
809 && CONSP (XCDR (frame)))
810 frame = XCAR (XCDR (frame));
2f0b07e0 811
09907c3a
KH
812 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
813 a switch-frame event to arrive after a frame is no longer live,
814 especially when deleting the initial frame during startup. */
b7826503 815 CHECK_FRAME (frame);
09907c3a
KH
816 if (! FRAME_LIVE_P (XFRAME (frame)))
817 return Qnil;
dc6f92b8 818
8d2666fe 819 if (sf == XFRAME (frame))
ff11dfa1 820 return frame;
dc6f92b8 821
0aed85f4
KH
822 /* This is too greedy; it causes inappropriate focus redirection
823 that's hard to get rid of. */
824#if 0
a42e9724
JB
825 /* If a frame's focus has been redirected toward the currently
826 selected frame, we should change the redirection to point to the
827 newly selected frame. This means that if the focus is redirected
828 from a minibufferless frame to a surrogate minibuffer frame, we
829 can use `other-window' to switch between all the frames using
830 that minibuffer frame, and the focus redirection will follow us
831 around. */
0aed85f4
KH
832 if (track)
833 {
834 Lisp_Object tail;
a42e9724 835
7539e11f 836 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
0aed85f4
KH
837 {
838 Lisp_Object focus;
a42e9724 839
7539e11f 840 if (!FRAMEP (XCAR (tail)))
0aed85f4 841 abort ();
a42e9724 842
7539e11f 843 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
a42e9724 844
8d2666fe 845 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
7539e11f 846 Fredirect_frame_focus (XCAR (tail), frame);
0aed85f4
KH
847 }
848 }
849#else /* ! 0 */
850 /* Instead, apply it only to the frame we're pointing to. */
032d78fe 851#ifdef HAVE_WINDOW_SYSTEM
1e8324d9 852 if (track && FRAME_WINDOW_P (XFRAME (frame)))
0aed85f4
KH
853 {
854 Lisp_Object focus, xfocus;
855
d7266360 856 xfocus = x_get_focus_frame (XFRAME (frame));
0aed85f4
KH
857 if (FRAMEP (xfocus))
858 {
859 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
8d2666fe 860 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
0aed85f4
KH
861 Fredirect_frame_focus (xfocus, frame);
862 }
863 }
864#endif /* HAVE_X_WINDOWS */
865#endif /* ! 0 */
a42e9724 866
1e8324d9 867 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
550f0e6a
GM
868 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
869
9628b887
KL
870 if (FRAME_TERMCAP_P (XFRAME (selected_frame))
871 && FRAME_TERMCAP_P (XFRAME (frame))
872 && FRAME_TTY (XFRAME (selected_frame)) == FRAME_TTY (XFRAME (frame)))
873 {
6548cf00 874 XFRAME (selected_frame)->async_visible = 2; /* obscured */
9628b887
KL
875 XFRAME (frame)->async_visible = 1;
876 FRAME_TTY (XFRAME (frame))->top_frame = frame;
877 }
878
8d2666fe
GM
879 selected_frame = frame;
880 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
881 last_nonminibuf_frame = XFRAME (selected_frame);
d5e7c279 882
f1321dc3 883 Fselect_window (XFRAME (frame)->selected_window, Qnil);
dc6f92b8 884
94674d18
EZ
885#ifndef WINDOWSNT
886 /* Make sure to switch the tty color mode to that of the newly
887 selected frame. */
888 sf = SELECTED_FRAME ();
889 if (FRAME_TERMCAP_P (sf))
890 {
891 Lisp_Object color_mode_spec, color_mode;
892
893 color_mode_spec = assq_no_quit (Qtty_color_mode, sf->param_alist);
894 if (CONSP (color_mode_spec))
895 color_mode = XCDR (color_mode_spec);
896 else
897 color_mode = make_number (0);
898 set_tty_color_mode (sf, color_mode);
899 }
900#endif /* !WINDOWSNT */
901
074577b8 902 /* We want to make sure that the next event generates a frame-switch
eb8c3be9 903 event to the appropriate frame. This seems kludgy to me, but
074577b8
JB
904 before you take it out, make sure that evaluating something like
905 (select-window (frame-root-window (new-frame))) doesn't end up
906 with your typing being interpreted in the new frame instead of
907 the one you're actually typing in. */
ef352596 908 internal_last_event_frame = Qnil;
074577b8 909
ff11dfa1 910 return frame;
dc6f92b8
JB
911}
912
20dc6fbb 913DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 1, "e",
14ff1ee0
PJ
914 doc: /* Select the frame FRAME.
915Subsequent editing commands apply to its selected window.
916The selection of FRAME lasts until the next time the user does
917something to select a different frame, or until the next time this
e4ed805e
LT
918function is called. If you are using a window system, the previously
919selected frame may be restored as the selected frame after return to
920the command loop, because it still may have the window system's input
921focus. On a text-only terminal, the next redisplay will display FRAME.
922
923This function returns FRAME, or nil if FRAME has been deleted. */)
20dc6fbb
LT
924 (frame)
925 Lisp_Object frame;
0aed85f4 926{
1e8324d9 927 return do_switch_frame (frame, 1, 0);
0aed85f4
KH
928}
929
930
20dc6fbb 931DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
14ff1ee0
PJ
932 doc: /* Handle a switch-frame event EVENT.
933Switch-frame events are usually bound to this function.
934A switch-frame event tells Emacs that the window manager has requested
935that the user's events be directed to the frame mentioned in the event.
936This function selects the selected window of the frame of EVENT.
937
938If EVENT is frame object, handle it as if it were a switch-frame event
939to that frame. */)
20dc6fbb
LT
940 (event)
941 Lisp_Object event;
0aed85f4 942{
6951cd71
KH
943 /* Preserve prefix arg that the command loop just cleared. */
944 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
e05169e2 945 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
1e8324d9 946 return do_switch_frame (event, 0, 0);
0aed85f4
KH
947}
948
ff11dfa1 949DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
14ff1ee0
PJ
950 doc: /* Return the frame that is now selected. */)
951 ()
dc6f92b8 952{
8d2666fe 953 return selected_frame;
dc6f92b8 954}
4a7cfafc 955\f
ff11dfa1 956DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
14ff1ee0
PJ
957 doc: /* Return the frame object that window WINDOW is on. */)
958 (window)
dc6f92b8
JB
959 Lisp_Object window;
960{
b7826503 961 CHECK_LIVE_WINDOW (window);
ff11dfa1 962 return XWINDOW (window)->frame;
dc6f92b8
JB
963}
964
ba32f2db 965DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
14ff1ee0
PJ
966 doc: /* Returns the topmost, leftmost window of FRAME.
967If omitted, FRAME defaults to the currently selected frame. */)
968 (frame)
ba32f2db
KH
969 Lisp_Object frame;
970{
971 Lisp_Object w;
972
973 if (NILP (frame))
8d2666fe 974 w = SELECTED_FRAME ()->root_window;
ba32f2db
KH
975 else
976 {
b7826503 977 CHECK_LIVE_FRAME (frame);
ba32f2db
KH
978 w = XFRAME (frame)->root_window;
979 }
980 while (NILP (XWINDOW (w)->buffer))
981 {
982 if (! NILP (XWINDOW (w)->hchild))
983 w = XWINDOW (w)->hchild;
984 else if (! NILP (XWINDOW (w)->vchild))
985 w = XWINDOW (w)->vchild;
986 else
987 abort ();
988 }
989 return w;
990}
991
5add3885
RS
992DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
993 Sactive_minibuffer_window, 0, 0, 0,
14ff1ee0
PJ
994 doc: /* Return the currently active minibuffer window, or nil if none. */)
995 ()
5add3885
RS
996{
997 return minibuf_level ? minibuf_window : Qnil;
998}
999
ff11dfa1 1000DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
14ff1ee0
PJ
1001 doc: /* Returns the root-window of FRAME.
1002If omitted, FRAME defaults to the currently selected frame. */)
1003 (frame)
ff11dfa1 1004 Lisp_Object frame;
dc6f92b8 1005{
8d2666fe 1006 Lisp_Object window;
177c0ea7 1007
ff11dfa1 1008 if (NILP (frame))
8d2666fe 1009 window = SELECTED_FRAME ()->root_window;
f9898cc6 1010 else
8d2666fe 1011 {
b7826503 1012 CHECK_LIVE_FRAME (frame);
8d2666fe
GM
1013 window = XFRAME (frame)->root_window;
1014 }
177c0ea7 1015
8d2666fe 1016 return window;
dc6f92b8
JB
1017}
1018
ff11dfa1
JB
1019DEFUN ("frame-selected-window", Fframe_selected_window,
1020 Sframe_selected_window, 0, 1, 0,
14ff1ee0
PJ
1021 doc: /* Return the selected window of frame object FRAME.
1022If omitted, FRAME defaults to the currently selected frame. */)
1023 (frame)
ff11dfa1 1024 Lisp_Object frame;
dc6f92b8 1025{
8d2666fe 1026 Lisp_Object window;
177c0ea7 1027
ff11dfa1 1028 if (NILP (frame))
8d2666fe 1029 window = SELECTED_FRAME ()->selected_window;
f9898cc6 1030 else
8d2666fe 1031 {
b7826503 1032 CHECK_LIVE_FRAME (frame);
8d2666fe
GM
1033 window = XFRAME (frame)->selected_window;
1034 }
dc6f92b8 1035
8d2666fe 1036 return window;
dc6f92b8
JB
1037}
1038
4a7cfafc
RS
1039DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
1040 Sset_frame_selected_window, 2, 2, 0,
14ff1ee0 1041 doc: /* Set the selected window of frame object FRAME to WINDOW.
e4ed805e 1042Return WINDOW.
14ff1ee0
PJ
1043If FRAME is nil, the selected frame is used.
1044If FRAME is the selected frame, this makes WINDOW the selected window. */)
1045 (frame, window)
4a7cfafc
RS
1046 Lisp_Object frame, window;
1047{
1048 if (NILP (frame))
8d2666fe 1049 frame = selected_frame;
177c0ea7 1050
b7826503
PJ
1051 CHECK_LIVE_FRAME (frame);
1052 CHECK_LIVE_WINDOW (window);
4a7cfafc
RS
1053
1054 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
1055 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
1056
8d2666fe 1057 if (EQ (frame, selected_frame))
f1321dc3 1058 return Fselect_window (window, Qnil);
4a7cfafc
RS
1059
1060 return XFRAME (frame)->selected_window = window;
1061}
b6660415
KL
1062
1063\f
ff11dfa1 1064DEFUN ("frame-list", Fframe_list, Sframe_list,
dc6f92b8 1065 0, 0, 0,
14ff1ee0
PJ
1066 doc: /* Return a list of all frames. */)
1067 ()
dc6f92b8 1068{
d74c1900
GM
1069 Lisp_Object frames;
1070 frames = Fcopy_sequence (Vframe_list);
6a65b1b5 1071#ifdef HAVE_WINDOW_SYSTEM
d74c1900
GM
1072 if (FRAMEP (tip_frame))
1073 frames = Fdelq (tip_frame, frames);
6a65b1b5 1074#endif
d74c1900 1075 return frames;
dc6f92b8
JB
1076}
1077
ff11dfa1 1078/* Return the next frame in the frame list after FRAME.
ff11dfa1 1079 If MINIBUF is nil, exclude minibuffer-only frames.
a9986780
RS
1080 If MINIBUF is a window, include only its own frame
1081 and any frame now using that window as the minibuffer.
f7af3f7b 1082 If MINIBUF is `visible', include all visible frames.
a9986780 1083 If MINIBUF is 0, include all visible and iconified frames.
f7af3f7b
RS
1084 Otherwise, include all frames. */
1085
66a9dbbe 1086static Lisp_Object
ff11dfa1
JB
1087next_frame (frame, minibuf)
1088 Lisp_Object frame;
f9898cc6 1089 Lisp_Object minibuf;
dc6f92b8
JB
1090{
1091 Lisp_Object tail;
1092 int passed = 0;
1093
ff11dfa1
JB
1094 /* There must always be at least one frame in Vframe_list. */
1095 if (! CONSP (Vframe_list))
f9898cc6
JB
1096 abort ();
1097
dbc4e1c1
JB
1098 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
1099 forever. Forestall that. */
b7826503 1100 CHECK_LIVE_FRAME (frame);
dbc4e1c1 1101
dc6f92b8 1102 while (1)
7539e11f 1103 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
dc6f92b8 1104 {
ab9f008d 1105 Lisp_Object f;
d06a8a56 1106
7539e11f 1107 f = XCAR (tail);
06537cc8
RS
1108
1109 if (passed
9628b887
KL
1110 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1111 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1112 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1113 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
d5e7c279 1114 {
d06a8a56
JB
1115 /* Decide whether this frame is eligible to be returned. */
1116
1117 /* If we've looped all the way around without finding any
1118 eligible frames, return the original frame. */
1119 if (EQ (f, frame))
1120 return f;
1121
1122 /* Let minibuf decide if this frame is acceptable. */
1123 if (NILP (minibuf))
1124 {
1125 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1126 return f;
1127 }
f7af3f7b
RS
1128 else if (EQ (minibuf, Qvisible))
1129 {
1130 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1131 if (FRAME_VISIBLE_P (XFRAME (f)))
1132 return f;
1133 }
3780bc22 1134 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
a9986780
RS
1135 {
1136 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1137 if (FRAME_VISIBLE_P (XFRAME (f))
1138 || FRAME_ICONIFIED_P (XFRAME (f)))
1139 return f;
1140 }
f7af3f7b 1141 else if (WINDOWP (minibuf))
d06a8a56 1142 {
a9986780 1143 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
551645f8
GM
1144 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1145 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1146 FRAME_FOCUS_FRAME (XFRAME (f))))
d06a8a56
JB
1147 return f;
1148 }
1149 else
ff11dfa1 1150 return f;
d5e7c279 1151 }
dc6f92b8 1152
d06a8a56 1153 if (EQ (frame, f))
dc6f92b8
JB
1154 passed++;
1155 }
1156}
1157
ff11dfa1 1158/* Return the previous frame in the frame list before FRAME.
ff11dfa1 1159 If MINIBUF is nil, exclude minibuffer-only frames.
a9986780
RS
1160 If MINIBUF is a window, include only its own frame
1161 and any frame now using that window as the minibuffer.
f7af3f7b 1162 If MINIBUF is `visible', include all visible frames.
a9986780 1163 If MINIBUF is 0, include all visible and iconified frames.
f7af3f7b
RS
1164 Otherwise, include all frames. */
1165
66a9dbbe 1166static Lisp_Object
ff11dfa1
JB
1167prev_frame (frame, minibuf)
1168 Lisp_Object frame;
f9898cc6 1169 Lisp_Object minibuf;
dc6f92b8
JB
1170{
1171 Lisp_Object tail;
1172 Lisp_Object prev;
1173
ff11dfa1
JB
1174 /* There must always be at least one frame in Vframe_list. */
1175 if (! CONSP (Vframe_list))
f9898cc6
JB
1176 abort ();
1177
dc6f92b8 1178 prev = Qnil;
7539e11f 1179 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
f9898cc6 1180 {
ab9f008d 1181 Lisp_Object f;
f9898cc6 1182
7539e11f 1183 f = XCAR (tail);
e35d291d 1184 if (!FRAMEP (f))
d06a8a56 1185 abort ();
f9898cc6 1186
d06a8a56
JB
1187 if (EQ (frame, f) && !NILP (prev))
1188 return prev;
f9898cc6 1189
9628b887
KL
1190 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1191 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1192 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1193 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
f7af3f7b 1194 {
06537cc8
RS
1195 /* Decide whether this frame is eligible to be returned,
1196 according to minibuf. */
1197 if (NILP (minibuf))
1198 {
1199 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1200 prev = f;
1201 }
1202 else if (WINDOWP (minibuf))
1203 {
1204 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
551645f8
GM
1205 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1206 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1207 FRAME_FOCUS_FRAME (XFRAME (f))))
06537cc8
RS
1208 prev = f;
1209 }
1210 else if (EQ (minibuf, Qvisible))
1211 {
1212 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1213 if (FRAME_VISIBLE_P (XFRAME (f)))
1214 prev = f;
1215 }
1216 else if (XFASTINT (minibuf) == 0)
1217 {
1218 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1219 if (FRAME_VISIBLE_P (XFRAME (f))
1220 || FRAME_ICONIFIED_P (XFRAME (f)))
1221 prev = f;
1222 }
1223 else
a9986780
RS
1224 prev = f;
1225 }
f9898cc6 1226 }
d06a8a56
JB
1227
1228 /* We've scanned the entire list. */
1229 if (NILP (prev))
1230 /* We went through the whole frame list without finding a single
1231 acceptable frame. Return the original frame. */
1232 return frame;
1233 else
1234 /* There were no acceptable frames in the list before FRAME; otherwise,
1235 we would have returned directly from the loop. Since PREV is the last
1236 acceptable frame in the list, return it. */
1237 return prev;
dc6f92b8
JB
1238}
1239
ef2c57ac 1240
ff11dfa1 1241DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
14ff1ee0
PJ
1242 doc: /* Return the next frame in the frame list after FRAME.
1243It considers only frames on the same terminal as FRAME.
1244By default, skip minibuffer-only frames.
1245If omitted, FRAME defaults to the selected frame.
1246If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1247If MINIFRAME is a window, include only its own frame
1248and any frame now using that window as the minibuffer.
1249If MINIFRAME is `visible', include all visible frames.
1250If MINIFRAME is 0, include all visible and iconified frames.
1251Otherwise, include all frames. */)
1252 (frame, miniframe)
8693ca83 1253 Lisp_Object frame, miniframe;
dc6f92b8 1254{
ff11dfa1 1255 if (NILP (frame))
8d2666fe 1256 frame = selected_frame;
177c0ea7 1257
b7826503 1258 CHECK_LIVE_FRAME (frame);
ff11dfa1 1259 return next_frame (frame, miniframe);
dc6f92b8 1260}
dbc4e1c1 1261
ef2c57ac 1262DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
14ff1ee0
PJ
1263 doc: /* Return the previous frame in the frame list before FRAME.
1264It considers only frames on the same terminal as FRAME.
1265By default, skip minibuffer-only frames.
1266If omitted, FRAME defaults to the selected frame.
1267If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1268If MINIFRAME is a window, include only its own frame
1269and any frame now using that window as the minibuffer.
1270If MINIFRAME is `visible', include all visible frames.
1271If MINIFRAME is 0, include all visible and iconified frames.
1272Otherwise, include all frames. */)
1273 (frame, miniframe)
ef2c57ac
RM
1274 Lisp_Object frame, miniframe;
1275{
ef2c57ac 1276 if (NILP (frame))
8d2666fe 1277 frame = selected_frame;
b7826503 1278 CHECK_LIVE_FRAME (frame);
ef2c57ac
RM
1279 return prev_frame (frame, miniframe);
1280}
dc6f92b8 1281\f
808c0f20
RS
1282/* Return 1 if it is ok to delete frame F;
1283 0 if all frames aside from F are invisible.
1284 (Exception: if F is the terminal frame, and we are using X, return 1.) */
dc6f92b8 1285
d56b45eb 1286int
808c0f20
RS
1287other_visible_frames (f)
1288 FRAME_PTR f;
1289{
1290 /* We know the selected frame is visible,
1291 so if F is some other frame, it can't be the sole visible one. */
8d2666fe 1292 if (f == SELECTED_FRAME ())
c08c95c7
RS
1293 {
1294 Lisp_Object frames;
1295 int count = 0;
1296
1297 for (frames = Vframe_list;
1298 CONSP (frames);
7539e11f 1299 frames = XCDR (frames))
c08c95c7 1300 {
ab9f008d 1301 Lisp_Object this;
c08c95c7 1302
7539e11f 1303 this = XCAR (frames);
808c0f20
RS
1304 /* Verify that the frame's window still exists
1305 and we can still talk to it. And note any recent change
1306 in visibility. */
032d78fe
GV
1307#ifdef HAVE_WINDOW_SYSTEM
1308 if (FRAME_WINDOW_P (XFRAME (this)))
5e7b7c5b 1309 {
b0509a40 1310 x_sync (XFRAME (this));
5e7b7c5b
RS
1311 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1312 }
1313#endif
1314
c08c95c7
RS
1315 if (FRAME_VISIBLE_P (XFRAME (this))
1316 || FRAME_ICONIFIED_P (XFRAME (this))
1317 /* Allow deleting the terminal frame when at least
1318 one X frame exists! */
032d78fe 1319 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
c08c95c7
RS
1320 count++;
1321 }
808c0f20 1322 return count > 1;
c08c95c7 1323 }
808c0f20
RS
1324 return 1;
1325}
1326
ea161626
KL
1327/* Error handler for `delete-frame-functions'. */
1328static Lisp_Object
1329delete_frame_handler (Lisp_Object arg)
1330{
1331 add_to_log ("Error during `delete-frame': %s", arg, Qnil);
1332 return Qnil;
1333}
1334
808c0f20 1335DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
14ff1ee0
PJ
1336 doc: /* Delete FRAME, permanently eliminating it from use.
1337If omitted, FRAME defaults to the selected frame.
1338A frame may not be deleted if its minibuffer is used by other frames.
1339Normally, you may not delete a frame if all other frames are invisible,
1340but if the second optional argument FORCE is non-nil, you may do so.
1341
cd1d850f
JPW
1342This function runs `delete-frame-functions' before actually deleting the
1343frame, unless the frame is a tooltip.
1344The functions are run with one arg, the frame to be deleted. */)
14ff1ee0 1345 (frame, force)
808c0f20
RS
1346 Lisp_Object frame, force;
1347{
1348 struct frame *f;
8d2666fe 1349 struct frame *sf = SELECTED_FRAME ();
bedb9c0e
KL
1350 struct kboard *kb;
1351
99b92e64 1352 int minibuffer_selected;
808c0f20
RS
1353
1354 if (EQ (frame, Qnil))
1355 {
8d2666fe 1356 f = sf;
2d80a27a 1357 XSETFRAME (frame, f);
808c0f20
RS
1358 }
1359 else
1360 {
b7826503 1361 CHECK_FRAME (frame);
808c0f20
RS
1362 f = XFRAME (frame);
1363 }
1364
1365 if (! FRAME_LIVE_P (f))
1366 return Qnil;
1367
83a96b4d 1368 if (NILP (force) && !other_visible_frames (f)
e0f712ba 1369#ifdef MAC_OS8
83a96b4d
AC
1370 /* Terminal frame deleted before any other visible frames are
1371 created. */
d5db4077 1372 && strcmp (SDATA (f->name), "F1") != 0
83a96b4d
AC
1373#endif
1374 )
808c0f20 1375 error ("Attempt to delete the sole visible or iconified frame");
d5e7c279 1376
00c5fd51
RS
1377#if 0
1378 /* This is a nice idea, but x_connection_closed needs to be able
1379 to delete the last frame, if it is gone. */
7539e11f 1380 if (NILP (XCDR (Vframe_list)))
e9687ee8 1381 error ("Attempt to delete the only frame");
00c5fd51 1382#endif
e9687ee8 1383
ff11dfa1
JB
1384 /* Does this frame have a minibuffer, and is it the surrogate
1385 minibuffer for any other frame? */
fd0c2bd1 1386 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
dc6f92b8 1387 {
ff11dfa1 1388 Lisp_Object frames;
1113d9db 1389
ff11dfa1
JB
1390 for (frames = Vframe_list;
1391 CONSP (frames);
7539e11f 1392 frames = XCDR (frames))
1113d9db 1393 {
7a8cc307 1394 Lisp_Object this;
7539e11f 1395 this = XCAR (frames);
1113d9db 1396
ff11dfa1
JB
1397 if (! EQ (this, frame)
1398 && EQ (frame,
7a8cc307
RS
1399 WINDOW_FRAME (XWINDOW
1400 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
ff11dfa1 1401 error ("Attempt to delete a surrogate minibuffer frame");
1113d9db 1402 }
dc6f92b8
JB
1403 }
1404
cd1d850f
JPW
1405 /* Run `delete-frame-functions' unless frame is a tooltip. */
1406 if (!NILP (Vrun_hooks)
1407 && NILP (Fframe_parameter (frame, intern ("tooltip"))))
0e662342
GM
1408 {
1409 Lisp_Object args[2];
ea161626
KL
1410 struct gcpro gcpro1, gcpro2;
1411
1412 /* Don't let a rogue function in `delete-frame-functions'
1413 prevent the frame deletion. */
1414 GCPRO2 (args[0], args[1]);
cd1d850f 1415 args[0] = intern ("delete-frame-functions");
0e662342 1416 args[1] = frame;
ea161626
KL
1417 internal_condition_case_2 (Frun_hook_with_args, 2, args,
1418 Qt, delete_frame_handler);
1419 UNGCPRO;
0e662342
GM
1420 }
1421
b6660415
KL
1422 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1423 if (! FRAME_LIVE_P (f))
1424 return Qnil;
1425
99b92e64
RS
1426 minibuffer_selected = EQ (minibuf_window, selected_window);
1427
ff11dfa1 1428 /* Don't let the frame remain selected. */
8d2666fe 1429 if (f == sf)
06537cc8
RS
1430 {
1431 Lisp_Object tail, frame1;
1432
1433 /* Look for another visible frame on the same terminal. */
1434 frame1 = next_frame (frame, Qvisible);
1435
1436 /* If there is none, find *some* other frame. */
1437 if (NILP (frame1) || EQ (frame1, frame))
1438 {
1439 FOR_EACH_FRAME (tail, frame1)
1440 {
fca177d4 1441 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
06537cc8
RS
1442 break;
1443 }
1444 }
1445
1e8324d9 1446 do_switch_frame (frame1, 0, 1);
79a65b7f 1447 sf = SELECTED_FRAME ();
06537cc8 1448 }
dc6f92b8 1449
ff11dfa1
JB
1450 /* Don't allow minibuf_window to remain on a deleted frame. */
1451 if (EQ (f->minibuffer_window, minibuf_window))
dc6f92b8 1452 {
8d2666fe 1453 Fset_window_buffer (sf->minibuffer_window,
5af5757b 1454 XWINDOW (minibuf_window)->buffer, Qnil);
8d2666fe 1455 minibuf_window = sf->minibuffer_window;
99b92e64
RS
1456
1457 /* If the dying minibuffer window was selected,
1458 select the new one. */
1459 if (minibuffer_selected)
f1321dc3 1460 Fselect_window (minibuf_window, Qnil);
dc6f92b8
JB
1461 }
1462
130adcb7
EZ
1463 /* Don't let echo_area_window to remain on a deleted frame. */
1464 if (EQ (f->minibuffer_window, echo_area_window))
1465 echo_area_window = sf->minibuffer_window;
1466
da8e8fc1
KL
1467 /* Don't allow other frames to refer to a deleted frame in their
1468 'environment parameter. */
1469 {
1470 Lisp_Object tail, frame1;
1471 Lisp_Object env = get_frame_param (XFRAME (frame), Qenvironment);
1472 FOR_EACH_FRAME (tail, frame1)
1473 {
1474 if (EQ (frame, frame1) || !FRAME_LIVE_P (XFRAME (frame1)))
1475 continue;
1476 if (EQ (frame, get_frame_param (XFRAME (frame1), Qenvironment)))
1477 {
1478 store_frame_param (XFRAME (frame1), Qenvironment, env);
1479 if (!FRAMEP (env))
1480 env = frame1;
1481 }
1482 }
1483 }
1484
bb2a0a65
RS
1485 /* Clear any X selections for this frame. */
1486#ifdef HAVE_X_WINDOWS
1487 if (FRAME_X_P (f))
1488 x_clear_frame_selections (f);
1489#endif
f706a7b2
YM
1490#ifdef MAC_OS
1491 if (FRAME_MAC_P (f))
1492 x_clear_frame_selections (f);
1493#endif
bb2a0a65 1494
177c0ea7
JB
1495 /* Free glyphs.
1496 This function must be called before the window tree of the
18082e2d
GM
1497 frame is deleted because windows contain dynamically allocated
1498 memory. */
1499 free_glyphs (f);
1500
4a88b3b0
JB
1501 /* Mark all the windows that used to be on FRAME as deleted, and then
1502 remove the reference to them. */
1503 delete_all_subwindows (XWINDOW (f->root_window));
1504 f->root_window = Qnil;
1505
ff11dfa1 1506 Vframe_list = Fdelq (frame, Vframe_list);
a42e9724 1507 FRAME_SET_VISIBLE (f, 0);
dc6f92b8 1508
60a8823e 1509 if (f->namebuf)
18082e2d 1510 xfree (f->namebuf);
96f09305
JD
1511 if (f->decode_mode_spec_buffer)
1512 xfree (f->decode_mode_spec_buffer);
d2bee99e 1513 if (FRAME_INSERT_COST (f))
18082e2d 1514 xfree (FRAME_INSERT_COST (f));
d2bee99e 1515 if (FRAME_DELETEN_COST (f))
18082e2d 1516 xfree (FRAME_DELETEN_COST (f));
d2bee99e 1517 if (FRAME_INSERTN_COST (f))
18082e2d 1518 xfree (FRAME_INSERTN_COST (f));
d2bee99e 1519 if (FRAME_DELETE_COST (f))
18082e2d 1520 xfree (FRAME_DELETE_COST (f));
25734faf 1521 if (FRAME_MESSAGE_BUF (f))
18082e2d 1522 xfree (FRAME_MESSAGE_BUF (f));
d2bee99e 1523
8678b9cc 1524 /* Since some events are handled at the interrupt level, we may get
6ed8eeff 1525 an event for f at any time; if we zero out the frame's terminal
8678b9cc 1526 now, then we may trip up the event-handling code. Instead, we'll
6ed8eeff
KL
1527 promise that the terminal of the frame must be valid until we
1528 have called the window-system-dependent frame destruction
1529 routine. */
dbc4e1c1 1530
6ed8eeff
KL
1531 if (FRAME_TERMINAL (f)->delete_frame_hook)
1532 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
bedb9c0e 1533
428a555e 1534 {
6ed8eeff 1535 struct terminal *terminal = FRAME_TERMINAL (f);
428a555e 1536 f->output_data.nothing = 0;
6ed8eeff 1537 f->terminal = 0; /* Now the frame is dead. */
428a555e 1538
6ed8eeff 1539 /* If needed, delete the terminal that this frame was on.
bedb9c0e 1540 (This must be done after the frame is killed.) */
6ed8eeff
KL
1541 terminal->reference_count--;
1542 if (terminal->reference_count == 0)
bedb9c0e
KL
1543 {
1544 kb = NULL;
6ed8eeff
KL
1545 if (terminal->delete_terminal_hook)
1546 (*terminal->delete_terminal_hook) (terminal);
bedb9c0e 1547 else
6ed8eeff 1548 delete_terminal (terminal);
bedb9c0e
KL
1549 }
1550 else
6ed8eeff 1551 kb = terminal->kboard;
428a555e 1552 }
8678b9cc 1553
ff11dfa1 1554 /* If we've deleted the last_nonminibuf_frame, then try to find
d5e7c279 1555 another one. */
ff11dfa1 1556 if (f == last_nonminibuf_frame)
d5e7c279 1557 {
ff11dfa1 1558 Lisp_Object frames;
1113d9db 1559
ff11dfa1 1560 last_nonminibuf_frame = 0;
d5e7c279 1561
ff11dfa1
JB
1562 for (frames = Vframe_list;
1563 CONSP (frames);
7539e11f 1564 frames = XCDR (frames))
d5e7c279 1565 {
7539e11f 1566 f = XFRAME (XCAR (frames));
ff11dfa1 1567 if (!FRAME_MINIBUF_ONLY_P (f))
d5e7c279 1568 {
ff11dfa1 1569 last_nonminibuf_frame = f;
d5e7c279
JB
1570 break;
1571 }
1572 }
1573 }
dc6f92b8 1574
8ceb7434
RS
1575 /* If there's no other frame on the same kboard, get out of
1576 single-kboard state if we're in it for this kboard. */
bedb9c0e
KL
1577 if (kb != NULL)
1578 {
1579 Lisp_Object frames;
1580 /* Some frame we found on the same kboard, or nil if there are none. */
1581 Lisp_Object frame_on_same_kboard;
8ceb7434 1582
bedb9c0e 1583 frame_on_same_kboard = Qnil;
8ceb7434 1584
bedb9c0e
KL
1585 for (frames = Vframe_list;
1586 CONSP (frames);
1587 frames = XCDR (frames))
1588 {
1589 Lisp_Object this;
1590 struct frame *f1;
8ceb7434 1591
bedb9c0e
KL
1592 this = XCAR (frames);
1593 if (!FRAMEP (this))
1594 abort ();
1595 f1 = XFRAME (this);
8ceb7434 1596
bedb9c0e
KL
1597 if (kb == FRAME_KBOARD (f1))
1598 frame_on_same_kboard = this;
1599 }
8ceb7434 1600
bedb9c0e
KL
1601 if (NILP (frame_on_same_kboard))
1602 not_single_kboard_state (kb);
1603 }
8ceb7434
RS
1604
1605
c4c6d073
KH
1606 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1607 find another one. Prefer minibuffer-only frames, but also notice
1608 frames with other windows. */
bedb9c0e 1609 if (kb != NULL && EQ (frame, kb->Vdefault_minibuffer_frame))
1113d9db 1610 {
ff11dfa1 1611 Lisp_Object frames;
1113d9db 1612
ff11dfa1 1613 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
ab9f008d 1614 Lisp_Object frame_with_minibuf;
32fda9ba
RS
1615 /* Some frame we found on the same kboard, or nil if there are none. */
1616 Lisp_Object frame_on_same_kboard;
1113d9db 1617
32fda9ba 1618 frame_on_same_kboard = Qnil;
ab9f008d 1619 frame_with_minibuf = Qnil;
32fda9ba 1620
ff11dfa1
JB
1621 for (frames = Vframe_list;
1622 CONSP (frames);
7539e11f 1623 frames = XCDR (frames))
1113d9db 1624 {
ab9f008d 1625 Lisp_Object this;
c4c6d073 1626 struct frame *f1;
1113d9db 1627
7539e11f 1628 this = XCAR (frames);
e35d291d 1629 if (!FRAMEP (this))
1113d9db 1630 abort ();
c4c6d073 1631 f1 = XFRAME (this);
1113d9db 1632
c4c6d073
KH
1633 /* Consider only frames on the same kboard
1634 and only those with minibuffers. */
bedb9c0e 1635 if (kb == FRAME_KBOARD (f1)
c4c6d073 1636 && FRAME_HAS_MINIBUF_P (f1))
1113d9db 1637 {
ff11dfa1 1638 frame_with_minibuf = this;
c4c6d073 1639 if (FRAME_MINIBUF_ONLY_P (f1))
1113d9db
JB
1640 break;
1641 }
32fda9ba 1642
bedb9c0e 1643 if (kb == FRAME_KBOARD (f1))
32fda9ba 1644 frame_on_same_kboard = this;
1113d9db
JB
1645 }
1646
32fda9ba
RS
1647 if (!NILP (frame_on_same_kboard))
1648 {
1649 /* We know that there must be some frame with a minibuffer out
1650 there. If this were not true, all of the frames present
1651 would have to be minibufferless, which implies that at some
1652 point their minibuffer frames must have been deleted, but
1653 that is prohibited at the top; you can't delete surrogate
1654 minibuffer frames. */
1655 if (NILP (frame_with_minibuf))
1656 abort ();
1113d9db 1657
bedb9c0e 1658 kb->Vdefault_minibuffer_frame = frame_with_minibuf;
32fda9ba
RS
1659 }
1660 else
1661 /* No frames left on this kboard--say no minibuffer either. */
bedb9c0e 1662 kb->Vdefault_minibuffer_frame = Qnil;
1113d9db
JB
1663 }
1664
e681c92a
RS
1665 /* Cause frame titles to update--necessary if we now have just one frame. */
1666 update_mode_lines = 1;
1667
dc6f92b8
JB
1668 return Qnil;
1669}
1670\f
1671/* Return mouse position in character cell units. */
1672
f9898cc6 1673DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
14ff1ee0
PJ
1674 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1675The position is given in character cells, where (0, 0) is the
1676upper-left corner.
1677If Emacs is running on a mouseless terminal or hasn't been programmed
1678to read the mouse position, it returns the selected frame for FRAME
1679and nil for X and Y.
1680If `mouse-position-function' is non-nil, `mouse-position' calls it,
1681passing the normal return value to that function as an argument,
1682and returns whatever that function returns. */)
1683 ()
dc6f92b8 1684{
ff11dfa1 1685 FRAME_PTR f;
dbc4e1c1 1686 Lisp_Object lispy_dummy;
fd2777e0 1687 enum scroll_bar_part party_dummy;
beb0bc36 1688 Lisp_Object x, y, retval;
5384466a 1689 int col, row;
dbc4e1c1 1690 unsigned long long_dummy;
cb2255b3 1691 struct gcpro gcpro1;
dc6f92b8 1692
8d2666fe 1693 f = SELECTED_FRAME ();
c5074d8c
RS
1694 x = y = Qnil;
1695
f443c170 1696#ifdef HAVE_MOUSE
c5074d8c 1697 /* It's okay for the hook to refrain from storing anything. */
6ed8eeff
KL
1698 if (FRAME_TERMINAL (f)->mouse_position_hook)
1699 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1700 &lispy_dummy, &party_dummy,
1701 &x, &y,
1702 &long_dummy);
76db7eb4
KH
1703 if (! NILP (x))
1704 {
1705 col = XINT (x);
1706 row = XINT (y);
8126c3b4 1707 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
76db7eb4
KH
1708 XSETINT (x, col);
1709 XSETINT (y, row);
1710 }
f443c170 1711#endif
2d80a27a 1712 XSETFRAME (lispy_dummy, f);
beb0bc36 1713 retval = Fcons (lispy_dummy, Fcons (x, y));
cb2255b3 1714 GCPRO1 (retval);
beb0bc36 1715 if (!NILP (Vmouse_position_function))
cb2255b3
GM
1716 retval = call1 (Vmouse_position_function, retval);
1717 RETURN_UNGCPRO (retval);
dc6f92b8
JB
1718}
1719
152e6c70
RS
1720DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1721 Smouse_pixel_position, 0, 0, 0,
14ff1ee0
PJ
1722 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1723The position is given in pixel units, where (0, 0) is the
1724upper-left corner.
1725If Emacs is running on a mouseless terminal or hasn't been programmed
1726to read the mouse position, it returns the selected frame for FRAME
1727and nil for X and Y. */)
1728 ()
152e6c70
RS
1729{
1730 FRAME_PTR f;
1731 Lisp_Object lispy_dummy;
1732 enum scroll_bar_part party_dummy;
1733 Lisp_Object x, y;
152e6c70
RS
1734 unsigned long long_dummy;
1735
8d2666fe 1736 f = SELECTED_FRAME ();
152e6c70
RS
1737 x = y = Qnil;
1738
0c5c1cf7 1739#ifdef HAVE_MOUSE
152e6c70 1740 /* It's okay for the hook to refrain from storing anything. */
6ed8eeff
KL
1741 if (FRAME_TERMINAL (f)->mouse_position_hook)
1742 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1743 &lispy_dummy, &party_dummy,
1744 &x, &y,
1745 &long_dummy);
0c5c1cf7 1746#endif
2d80a27a 1747 XSETFRAME (lispy_dummy, f);
152e6c70
RS
1748 return Fcons (lispy_dummy, Fcons (x, y));
1749}
1750
dc6f92b8 1751DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
14ff1ee0
PJ
1752 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1753Coordinates are relative to the frame, not a window,
1754so the coordinates of the top left character in the frame
1755may be nonzero due to left-hand scroll bars or the menu bar.
1756
1757This function is a no-op for an X frame that is not visible.
1758If you have just created a frame, you must wait for it to become visible
1759before calling this function on it, like this.
1760 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
ff11dfa1
JB
1761 (frame, x, y)
1762 Lisp_Object frame, x, y;
dc6f92b8 1763{
b7826503
PJ
1764 CHECK_LIVE_FRAME (frame);
1765 CHECK_NUMBER (x);
1766 CHECK_NUMBER (y);
dc6f92b8 1767
dbc4e1c1 1768 /* I think this should be done with a hook. */
032d78fe
GV
1769#ifdef HAVE_WINDOW_SYSTEM
1770 if (FRAME_WINDOW_P (XFRAME (frame)))
d19be8a9 1771 /* Warping the mouse will cause enternotify and focus events. */
d4d76014 1772 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
bb221971 1773#else
be625e00 1774#if defined (MSDOS) && defined (HAVE_MOUSE)
bb221971
RS
1775 if (FRAME_MSDOS_P (XFRAME (frame)))
1776 {
20dc6fbb 1777 Fselect_frame (frame);
bb221971
RS
1778 mouse_moveto (XINT (x), XINT (y));
1779 }
1780#endif
dc6f92b8
JB
1781#endif
1782
1783 return Qnil;
1784}
152e6c70
RS
1785
1786DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1787 Sset_mouse_pixel_position, 3, 3, 0,
14ff1ee0
PJ
1788 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1789Note, this is a no-op for an X frame that is not visible.
1790If you have just created a frame, you must wait for it to become visible
1791before calling this function on it, like this.
1792 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
152e6c70
RS
1793 (frame, x, y)
1794 Lisp_Object frame, x, y;
1795{
b7826503
PJ
1796 CHECK_LIVE_FRAME (frame);
1797 CHECK_NUMBER (x);
1798 CHECK_NUMBER (y);
152e6c70
RS
1799
1800 /* I think this should be done with a hook. */
032d78fe
GV
1801#ifdef HAVE_WINDOW_SYSTEM
1802 if (FRAME_WINDOW_P (XFRAME (frame)))
d19be8a9 1803 /* Warping the mouse will cause enternotify and focus events. */
d4d76014 1804 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
bb221971 1805#else
be625e00 1806#if defined (MSDOS) && defined (HAVE_MOUSE)
bb221971
RS
1807 if (FRAME_MSDOS_P (XFRAME (frame)))
1808 {
20dc6fbb 1809 Fselect_frame (frame);
bb221971
RS
1810 mouse_moveto (XINT (x), XINT (y));
1811 }
1812#endif
152e6c70
RS
1813#endif
1814
1815 return Qnil;
1816}
dc6f92b8 1817\f
98ce1622
RS
1818static void make_frame_visible_1 P_ ((Lisp_Object));
1819
ff11dfa1 1820DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
fc25d15d 1821 0, 1, "",
14ff1ee0
PJ
1822 doc: /* Make the frame FRAME visible (assuming it is an X window).
1823If omitted, FRAME defaults to the currently selected frame. */)
1824 (frame)
ff11dfa1 1825 Lisp_Object frame;
dc6f92b8 1826{
1aa66088 1827 if (NILP (frame))
8d2666fe 1828 frame = selected_frame;
1aa66088 1829
b7826503 1830 CHECK_LIVE_FRAME (frame);
dc6f92b8 1831
dbc4e1c1 1832 /* I think this should be done with a hook. */
032d78fe
GV
1833#ifdef HAVE_WINDOW_SYSTEM
1834 if (FRAME_WINDOW_P (XFRAME (frame)))
02ff9dd5
RS
1835 {
1836 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1837 x_make_frame_visible (XFRAME (frame));
1838 }
fd0c2bd1 1839#endif
dc6f92b8 1840
98ce1622
RS
1841 make_frame_visible_1 (XFRAME (frame)->root_window);
1842
d19be8a9 1843 /* Make menu bar update for the Buffers and Frames menus. */
565620a5
RS
1844 windows_or_buffers_changed++;
1845
ff11dfa1 1846 return frame;
dc6f92b8
JB
1847}
1848
98ce1622
RS
1849/* Update the display_time slot of the buffers shown in WINDOW
1850 and all its descendents. */
1851
1852static void
1853make_frame_visible_1 (window)
1854 Lisp_Object window;
1855{
1856 struct window *w;
1857
1858 for (;!NILP (window); window = w->next)
1859 {
1860 w = XWINDOW (window);
1861
1862 if (!NILP (w->buffer))
1863 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1864
1865 if (!NILP (w->vchild))
1866 make_frame_visible_1 (w->vchild);
1867 if (!NILP (w->hchild))
1868 make_frame_visible_1 (w->hchild);
1869 }
1870}
1871
ff11dfa1 1872DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
808c0f20 1873 0, 2, "",
14ff1ee0
PJ
1874 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1875If omitted, FRAME defaults to the currently selected frame.
1876Normally you may not make FRAME invisible if all other frames are invisible,
1877but if the second optional argument FORCE is non-nil, you may do so. */)
808c0f20
RS
1878 (frame, force)
1879 Lisp_Object frame, force;
dc6f92b8 1880{
1aa66088 1881 if (NILP (frame))
8d2666fe 1882 frame = selected_frame;
1aa66088 1883
b7826503 1884 CHECK_LIVE_FRAME (frame);
dc6f92b8 1885
808c0f20
RS
1886 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1887 error ("Attempt to make invisible the sole visible or iconified frame");
1888
3d378fdf 1889#if 0 /* This isn't logically necessary, and it can do GC. */
9c394f17 1890 /* Don't let the frame remain selected. */
8d2666fe 1891 if (EQ (frame, selected_frame))
1e8324d9 1892 do_switch_frame (next_frame (frame, Qt), 0, 0)
3d378fdf 1893#endif
9c394f17
RS
1894
1895 /* Don't allow minibuf_window to remain on a deleted frame. */
1896 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1897 {
8d2666fe
GM
1898 struct frame *sf = XFRAME (selected_frame);
1899 Fset_window_buffer (sf->minibuffer_window,
5af5757b 1900 XWINDOW (minibuf_window)->buffer, Qnil);
8d2666fe 1901 minibuf_window = sf->minibuffer_window;
9c394f17
RS
1902 }
1903
dbc4e1c1 1904 /* I think this should be done with a hook. */
032d78fe
GV
1905#ifdef HAVE_WINDOW_SYSTEM
1906 if (FRAME_WINDOW_P (XFRAME (frame)))
ff11dfa1 1907 x_make_frame_invisible (XFRAME (frame));
fd0c2bd1 1908#endif
dc6f92b8 1909
d19be8a9 1910 /* Make menu bar update for the Buffers and Frames menus. */
565620a5
RS
1911 windows_or_buffers_changed++;
1912
dc6f92b8
JB
1913 return Qnil;
1914}
1915
ff11dfa1 1916DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1aa66088 1917 0, 1, "",
14ff1ee0
PJ
1918 doc: /* Make the frame FRAME into an icon.
1919If omitted, FRAME defaults to the currently selected frame. */)
ff11dfa1
JB
1920 (frame)
1921 Lisp_Object frame;
dc6f92b8 1922{
1aa66088 1923 if (NILP (frame))
8d2666fe 1924 frame = selected_frame;
177c0ea7 1925
b7826503 1926 CHECK_LIVE_FRAME (frame);
dc6f92b8 1927
3d378fdf 1928#if 0 /* This isn't logically necessary, and it can do GC. */
9c394f17 1929 /* Don't let the frame remain selected. */
8d2666fe 1930 if (EQ (frame, selected_frame))
20dc6fbb 1931 Fhandle_switch_frame (next_frame (frame, Qt));
3d378fdf 1932#endif
9c394f17
RS
1933
1934 /* Don't allow minibuf_window to remain on a deleted frame. */
1935 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1936 {
8d2666fe
GM
1937 struct frame *sf = XFRAME (selected_frame);
1938 Fset_window_buffer (sf->minibuffer_window,
5af5757b 1939 XWINDOW (minibuf_window)->buffer, Qnil);
8d2666fe 1940 minibuf_window = sf->minibuffer_window;
9c394f17
RS
1941 }
1942
dbc4e1c1 1943 /* I think this should be done with a hook. */
032d78fe
GV
1944#ifdef HAVE_WINDOW_SYSTEM
1945 if (FRAME_WINDOW_P (XFRAME (frame)))
ff11dfa1 1946 x_iconify_frame (XFRAME (frame));
fd0c2bd1 1947#endif
dc6f92b8 1948
d19be8a9 1949 /* Make menu bar update for the Buffers and Frames menus. */
565620a5
RS
1950 windows_or_buffers_changed++;
1951
dc6f92b8
JB
1952 return Qnil;
1953}
1954
ff11dfa1 1955DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
dc6f92b8 1956 1, 1, 0,
14ff1ee0
PJ
1957 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1958A frame that is not \"visible\" is not updated and, if it works through
1959a window system, it may not show at all.
e4ed805e
LT
1960Return the symbol `icon' if frame is visible only as an icon.
1961
1962On a text-only terminal, all frames are considered visible, whether
1963they are currently being displayed or not, and this function returns t
1964for all frames. */)
14ff1ee0 1965 (frame)
ff11dfa1 1966 Lisp_Object frame;
dc6f92b8 1967{
b7826503 1968 CHECK_LIVE_FRAME (frame);
dc6f92b8 1969
5c044f55
RS
1970 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1971
a42e9724 1972 if (FRAME_VISIBLE_P (XFRAME (frame)))
dc6f92b8 1973 return Qt;
a42e9724 1974 if (FRAME_ICONIFIED_P (XFRAME (frame)))
fd0c2bd1 1975 return Qicon;
dc6f92b8
JB
1976 return Qnil;
1977}
1978
ff11dfa1 1979DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
dc6f92b8 1980 0, 0, 0,
14ff1ee0 1981 doc: /* Return a list of all frames now \"visible\" (being updated). */)
dc6f92b8
JB
1982 ()
1983{
ff11dfa1
JB
1984 Lisp_Object tail, frame;
1985 struct frame *f;
dc6f92b8
JB
1986 Lisp_Object value;
1987
1988 value = Qnil;
7539e11f 1989 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
dc6f92b8 1990 {
7539e11f 1991 frame = XCAR (tail);
e35d291d 1992 if (!FRAMEP (frame))
dc6f92b8 1993 continue;
ff11dfa1 1994 f = XFRAME (frame);
a42e9724 1995 if (FRAME_VISIBLE_P (f))
ff11dfa1 1996 value = Fcons (frame, value);
dc6f92b8
JB
1997 }
1998 return value;
1999}
d5e7c279
JB
2000
2001
e518d5e1 2002DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
14ff1ee0 2003 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
e4ed805e 2004If FRAME is invisible or iconified, make it visible.
14ff1ee0
PJ
2005If you don't specify a frame, the selected frame is used.
2006If Emacs is displaying on an ordinary terminal or some other device which
2007doesn't support multiple overlapping frames, this function does nothing. */)
2008 (frame)
dbc4e1c1
JB
2009 Lisp_Object frame;
2010{
428a555e 2011 struct frame *f;
828ac693 2012 if (NILP (frame))
8d2666fe 2013 frame = selected_frame;
828ac693 2014
b7826503 2015 CHECK_LIVE_FRAME (frame);
8a981af5 2016
428a555e
KL
2017 f = XFRAME (frame);
2018
8a981af5
RS
2019 /* Do like the documentation says. */
2020 Fmake_frame_visible (frame);
2021
6ed8eeff
KL
2022 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2023 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
dbc4e1c1
JB
2024
2025 return Qnil;
2026}
2027
b49f5578 2028/* Should we have a corresponding function called Flower_Power? */
e518d5e1 2029DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
14ff1ee0
PJ
2030 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2031If you don't specify a frame, the selected frame is used.
2032If Emacs is displaying on an ordinary terminal or some other device which
2033doesn't support multiple overlapping frames, this function does nothing. */)
2034 (frame)
dbc4e1c1
JB
2035 Lisp_Object frame;
2036{
428a555e
KL
2037 struct frame *f;
2038
828ac693 2039 if (NILP (frame))
8d2666fe 2040 frame = selected_frame;
828ac693 2041
b7826503 2042 CHECK_LIVE_FRAME (frame);
177c0ea7 2043
428a555e
KL
2044 f = XFRAME (frame);
2045
6ed8eeff
KL
2046 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2047 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
dbc4e1c1
JB
2048
2049 return Qnil;
2050}
2051
d5e7c279 2052\f
ff11dfa1 2053DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
d5e7c279 2054 1, 2, 0,
14ff1ee0
PJ
2055 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2056In other words, switch-frame events caused by events in FRAME will
2057request a switch to FOCUS-FRAME, and `last-event-frame' will be
2058FOCUS-FRAME after reading an event typed at FRAME.
2059
2060If FOCUS-FRAME is omitted or nil, any existing redirection is
2061cancelled, and the frame again receives its own keystrokes.
2062
2063Focus redirection is useful for temporarily redirecting keystrokes to
2064a surrogate minibuffer frame when a frame doesn't have its own
2065minibuffer window.
2066
66a9dbbe 2067A frame's focus redirection can be changed by `select-frame'. If frame
14ff1ee0
PJ
2068FOO is selected, and then a different frame BAR is selected, any
2069frames redirecting their focus to FOO are shifted to redirect their
2070focus to BAR. This allows focus redirection to work properly when the
2071user switches from one frame to another using `select-window'.
2072
2073This means that a frame whose focus is redirected to itself is treated
2074differently from a frame whose focus is redirected to nil; the former
66a9dbbe 2075is affected by `select-frame', while the latter is not.
14ff1ee0
PJ
2076
2077The redirection lasts until `redirect-frame-focus' is called to change it. */)
2078 (frame, focus_frame)
2079 Lisp_Object frame, focus_frame;
d5e7c279 2080{
428a555e
KL
2081 struct frame *f;
2082
13144095
JB
2083 /* Note that we don't check for a live frame here. It's reasonable
2084 to redirect the focus of a frame you're about to delete, if you
2085 know what other frame should receive those keystrokes. */
b7826503 2086 CHECK_FRAME (frame);
f9898cc6 2087
a42e9724 2088 if (! NILP (focus_frame))
b7826503 2089 CHECK_LIVE_FRAME (focus_frame);
d5e7c279 2090
428a555e
KL
2091 f = XFRAME (frame);
2092
2093 f->focus_frame = focus_frame;
d5e7c279 2094
6ed8eeff
KL
2095 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2096 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
177c0ea7 2097
d5e7c279
JB
2098 return Qnil;
2099}
2100
2101
ff11dfa1 2102DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
14ff1ee0
PJ
2103 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2104This returns nil if FRAME's focus is not redirected.
2105See `redirect-frame-focus'. */)
2106 (frame)
2107 Lisp_Object frame;
d5e7c279 2108{
b7826503 2109 CHECK_LIVE_FRAME (frame);
a42e9724 2110
ff11dfa1 2111 return FRAME_FOCUS_FRAME (XFRAME (frame));
d5e7c279
JB
2112}
2113
2114
dc6f92b8 2115\f
329ca574
RS
2116/* Return the value of frame parameter PROP in frame FRAME. */
2117
dc6f92b8 2118Lisp_Object
ff11dfa1
JB
2119get_frame_param (frame, prop)
2120 register struct frame *frame;
dc6f92b8
JB
2121 Lisp_Object prop;
2122{
2123 register Lisp_Object tem;
2124
ff11dfa1 2125 tem = Fassq (prop, frame->param_alist);
dc6f92b8
JB
2126 if (EQ (tem, Qnil))
2127 return tem;
2128 return Fcdr (tem);
2129}
2130
329ca574
RS
2131/* Return the buffer-predicate of the selected frame. */
2132
2133Lisp_Object
98ce1622
RS
2134frame_buffer_predicate (frame)
2135 Lisp_Object frame;
329ca574 2136{
98ce1622 2137 return XFRAME (frame)->buffer_predicate;
329ca574
RS
2138}
2139
fa54c6ae
RS
2140/* Return the buffer-list of the selected frame. */
2141
2142Lisp_Object
98ce1622
RS
2143frame_buffer_list (frame)
2144 Lisp_Object frame;
fa54c6ae 2145{
98ce1622 2146 return XFRAME (frame)->buffer_list;
fa54c6ae
RS
2147}
2148
2149/* Set the buffer-list of the selected frame. */
2150
2151void
98ce1622
RS
2152set_frame_buffer_list (frame, list)
2153 Lisp_Object frame, list;
fa54c6ae 2154{
98ce1622 2155 XFRAME (frame)->buffer_list = list;
fa54c6ae
RS
2156}
2157
a18b8cb5 2158/* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
fa54c6ae
RS
2159
2160void
2161frames_discard_buffer (buffer)
2162 Lisp_Object buffer;
2163{
2164 Lisp_Object frame, tail;
2165
2166 FOR_EACH_FRAME (tail, frame)
2167 {
2168 XFRAME (frame)->buffer_list
2169 = Fdelq (buffer, XFRAME (frame)->buffer_list);
a18b8cb5
KL
2170 XFRAME (frame)->buried_buffer_list
2171 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
fa54c6ae
RS
2172 }
2173}
2174
329ca574
RS
2175/* Modify the alist in *ALISTPTR to associate PROP with VAL.
2176 If the alist already has an element for PROP, we change it. */
2177
dc6f92b8 2178void
fd0c2bd1 2179store_in_alist (alistptr, prop, val)
dc6f92b8 2180 Lisp_Object *alistptr, val;
fd0c2bd1 2181 Lisp_Object prop;
dc6f92b8
JB
2182{
2183 register Lisp_Object tem;
dc6f92b8 2184
dc6f92b8
JB
2185 tem = Fassq (prop, *alistptr);
2186 if (EQ (tem, Qnil))
2187 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2188 else
2189 Fsetcdr (tem, val);
2190}
2191
e5317d61
EZ
2192static int
2193frame_name_fnn_p (str, len)
2194 char *str;
2195 int len;
2196{
2197 if (len > 1 && str[0] == 'F')
2198 {
2199 char *end_ptr;
e5317d61 2200
48970f2f
EZ
2201 strtol (str + 1, &end_ptr, 10);
2202
e5317d61
EZ
2203 if (end_ptr == str + len)
2204 return 1;
2205 }
2206 return 0;
2207}
2208
2209/* Set the name of the terminal frame. Also used by MSDOS frames.
2210 Modeled after x_set_name which is used for WINDOW frames. */
2211
66a9dbbe 2212static void
e5317d61
EZ
2213set_term_frame_name (f, name)
2214 struct frame *f;
2215 Lisp_Object name;
2216{
2217 f->explicit_name = ! NILP (name);
2218
2219 /* If NAME is nil, set the name to F<num>. */
2220 if (NILP (name))
2221 {
2222 char namebuf[20];
2223
2224 /* Check for no change needed in this very common case
2225 before we do any consing. */
d5db4077
KR
2226 if (frame_name_fnn_p (SDATA (f->name),
2227 SBYTES (f->name)))
e5317d61
EZ
2228 return;
2229
6ed8eeff
KL
2230 tty_frame_count++;
2231 sprintf (namebuf, "F%d", tty_frame_count);
e5317d61
EZ
2232 name = build_string (namebuf);
2233 }
2234 else
2235 {
b7826503 2236 CHECK_STRING (name);
e5317d61
EZ
2237
2238 /* Don't change the name if it's already NAME. */
2239 if (! NILP (Fstring_equal (name, f->name)))
2240 return;
2241
2242 /* Don't allow the user to set the frame name to F<num>, so it
2243 doesn't clash with the names we generate for terminal frames. */
d5db4077 2244 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
e5317d61
EZ
2245 error ("Frame names of the form F<num> are usurped by Emacs");
2246 }
2247
2248 f->name = name;
2249 update_mode_lines = 1;
2250}
2251
dc6f92b8 2252void
ff11dfa1
JB
2253store_frame_param (f, prop, val)
2254 struct frame *f;
dc6f92b8
JB
2255 Lisp_Object prop, val;
2256{
7eb63b72 2257 register Lisp_Object old_alist_elt;
dc6f92b8 2258
a18b8cb5
KL
2259 /* The buffer-list parameters are stored in a special place and not
2260 in the alist. */
fa54c6ae
RS
2261 if (EQ (prop, Qbuffer_list))
2262 {
2263 f->buffer_list = val;
2264 return;
2265 }
a18b8cb5
KL
2266 if (EQ (prop, Qburied_buffer_list))
2267 {
2268 f->buried_buffer_list = val;
2269 return;
2270 }
fa54c6ae 2271
7eb63b72
GM
2272 /* If PROP is a symbol which is supposed to have frame-local values,
2273 and it is set up based on this frame, switch to the global
2274 binding. That way, we can create or alter the frame-local binding
2275 without messing up the symbol's status. */
2276 if (SYMBOLP (prop))
2277 {
2278 Lisp_Object valcontents;
f5c1dd0d 2279 valcontents = SYMBOL_VALUE (prop);
7eb63b72
GM
2280 if ((BUFFER_LOCAL_VALUEP (valcontents)
2281 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
2282 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2283 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2284 swap_in_global_binding (prop);
2285 }
2286
94674d18
EZ
2287#ifndef WINDOWSNT
2288 /* The tty color mode needs to be set before the frame's parameter
2289 alist is updated with the new value, because set_tty_color_mode
2290 wants to look at the old mode. */
2291 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode))
2292 set_tty_color_mode (f, val);
2293#endif
2294
7eb63b72
GM
2295 /* Update the frame parameter alist. */
2296 old_alist_elt = Fassq (prop, f->param_alist);
2297 if (EQ (old_alist_elt, Qnil))
ff11dfa1 2298 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
dc6f92b8 2299 else
7eb63b72 2300 Fsetcdr (old_alist_elt, val);
bc93c097 2301
7eb63b72
GM
2302 /* Update some other special parameters in their special places
2303 in addition to the alist. */
177c0ea7 2304
329ca574
RS
2305 if (EQ (prop, Qbuffer_predicate))
2306 f->buffer_predicate = val;
2307
032d78fe 2308 if (! FRAME_WINDOW_P (f))
e5317d61
EZ
2309 {
2310 if (EQ (prop, Qmenu_bar_lines))
2311 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2312 else if (EQ (prop, Qname))
2313 set_term_frame_name (f, val);
2314 }
a249de79 2315
e35d291d 2316 if (EQ (prop, Qminibuffer) && WINDOWP (val))
bc93c097
JB
2317 {
2318 if (! MINI_WINDOW_P (XWINDOW (val)))
7c402969 2319 error ("Surrogate minibuffer windows must be minibuffer windows");
bc93c097 2320
213bac8a 2321 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
7af7ef38
KH
2322 && !EQ (val, f->minibuffer_window))
2323 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
bc93c097
JB
2324
2325 /* Install the chosen minibuffer window, with proper buffer. */
ff11dfa1 2326 f->minibuffer_window = val;
bc93c097 2327 }
dc6f92b8
JB
2328}
2329
ff11dfa1 2330DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
14ff1ee0
PJ
2331 doc: /* Return the parameters-alist of frame FRAME.
2332It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2333The meaningful PARMs depend on the kind of frame.
2334If FRAME is omitted, return information on the currently selected frame. */)
2335 (frame)
ff11dfa1 2336 Lisp_Object frame;
dc6f92b8
JB
2337{
2338 Lisp_Object alist;
f769f1b2 2339 FRAME_PTR f;
dd10ec4f 2340 int height, width;
57629833 2341 struct gcpro gcpro1;
dc6f92b8 2342
03390a72 2343 if (NILP (frame))
8d2666fe
GM
2344 frame = selected_frame;
2345
b7826503 2346 CHECK_FRAME (frame);
8d2666fe 2347 f = XFRAME (frame);
dc6f92b8 2348
f769f1b2 2349 if (!FRAME_LIVE_P (f))
dc6f92b8
JB
2350 return Qnil;
2351
ff11dfa1 2352 alist = Fcopy_alist (f->param_alist);
57629833 2353 GCPRO1 (alist);
177c0ea7 2354
2d764c78 2355 if (!FRAME_WINDOW_P (f))
bb221971 2356 {
4aec4b29
EZ
2357 int fg = FRAME_FOREGROUND_PIXEL (f);
2358 int bg = FRAME_BACKGROUND_PIXEL (f);
e1d0bbc9
EZ
2359 Lisp_Object elt;
2360
2361 /* If the frame's parameter alist says the colors are
2362 unspecified and reversed, take the frame's background pixel
2363 for foreground and vice versa. */
2364 elt = Fassq (Qforeground_color, alist);
70de9f06
EZ
2365 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2366 {
d5db4077 2367 if (strncmp (SDATA (XCDR (elt)),
70de9f06 2368 unspecified_bg,
d5db4077 2369 SCHARS (XCDR (elt))) == 0)
70de9f06 2370 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
d5db4077 2371 else if (strncmp (SDATA (XCDR (elt)),
70de9f06 2372 unspecified_fg,
d5db4077 2373 SCHARS (XCDR (elt))) == 0)
70de9f06
EZ
2374 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2375 }
e1d0bbc9
EZ
2376 else
2377 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2378 elt = Fassq (Qbackground_color, alist);
70de9f06
EZ
2379 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2380 {
d5db4077 2381 if (strncmp (SDATA (XCDR (elt)),
70de9f06 2382 unspecified_fg,
d5db4077 2383 SCHARS (XCDR (elt))) == 0)
70de9f06 2384 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
d5db4077 2385 else if (strncmp (SDATA (XCDR (elt)),
70de9f06 2386 unspecified_bg,
d5db4077 2387 SCHARS (XCDR (elt))) == 0)
70de9f06
EZ
2388 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2389 }
e1d0bbc9
EZ
2390 else
2391 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2d764c78
EZ
2392 store_in_alist (&alist, intern ("font"),
2393 build_string (FRAME_MSDOS_P (f)
2394 ? "ms-dos"
4ec0d3c1 2395 : FRAME_W32_P (f) ? "w32term"
4ec0d3c1 2396 :"tty"));
bb221971 2397 }
fd0c2bd1 2398 store_in_alist (&alist, Qname, f->name);
5af5757b 2399 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
dd10ec4f 2400 store_in_alist (&alist, Qheight, make_number (height));
5af5757b 2401 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
dd10ec4f 2402 store_in_alist (&alist, Qwidth, make_number (width));
f769f1b2 2403 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
fd0c2bd1 2404 store_in_alist (&alist, Qminibuffer,
39acc701 2405 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
f769f1b2
KH
2406 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2407 : FRAME_MINIBUF_WINDOW (f)));
2408 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
03390a72 2409 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
a18b8cb5 2410 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
fd0c2bd1 2411
dbc4e1c1 2412 /* I think this should be done with a hook. */
032d78fe
GV
2413#ifdef HAVE_WINDOW_SYSTEM
2414 if (FRAME_WINDOW_P (f))
ff11dfa1 2415 x_report_frame_params (f, &alist);
b6dd20ed 2416 else
fd0c2bd1 2417#endif
16a3738c
KH
2418 {
2419 /* This ought to be correct in f->param_alist for an X frame. */
2420 Lisp_Object lines;
f4e93c40 2421 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
16a3738c
KH
2422 store_in_alist (&alist, Qmenu_bar_lines, lines);
2423 }
57629833
GM
2424
2425 UNGCPRO;
dc6f92b8
JB
2426 return alist;
2427}
2428
8b60f7bc
GM
2429
2430DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
14ff1ee0
PJ
2431 doc: /* Return FRAME's value for parameter PARAMETER.
2432If FRAME is nil, describe the currently selected frame. */)
2433 (frame, parameter)
2434 Lisp_Object frame, parameter;
8b60f7bc
GM
2435{
2436 struct frame *f;
2437 Lisp_Object value;
2438
2439 if (NILP (frame))
2440 frame = selected_frame;
2441 else
b7826503
PJ
2442 CHECK_FRAME (frame);
2443 CHECK_SYMBOL (parameter);
177c0ea7 2444
8b60f7bc
GM
2445 f = XFRAME (frame);
2446 value = Qnil;
177c0ea7 2447
8b60f7bc
GM
2448 if (FRAME_LIVE_P (f))
2449 {
5cd62b8c 2450 /* Avoid consing in frequent cases. */
67d853e6
GM
2451 if (EQ (parameter, Qname))
2452 value = f->name;
6345f6aa
GM
2453#ifdef HAVE_X_WINDOWS
2454 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2455 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2456#endif /* HAVE_X_WINDOWS */
75700ff2
GM
2457 else if (EQ (parameter, Qbackground_color)
2458 || EQ (parameter, Qforeground_color))
67d853e6
GM
2459 {
2460 value = Fassq (parameter, f->param_alist);
2461 if (CONSP (value))
5f65b39d 2462 {
5f65b39d
EZ
2463 value = XCDR (value);
2464 /* Fframe_parameters puts the actual fg/bg color names,
2465 even if f->param_alist says otherwise. This is
2466 important when param_alist's notion of colors is
2467 "unspecified". We need to do the same here. */
2468 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2469 {
c9b08ba8 2470 const char *color_name;
e1d0bbc9
EZ
2471 EMACS_INT csz;
2472
2473 if (EQ (parameter, Qbackground_color))
2474 {
d5db4077
KR
2475 color_name = SDATA (value);
2476 csz = SCHARS (value);
e1d0bbc9
EZ
2477 if (strncmp (color_name, unspecified_bg, csz) == 0)
2478 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2479 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2480 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2481 }
2482 else if (EQ (parameter, Qforeground_color))
2483 {
d5db4077
KR
2484 color_name = SDATA (value);
2485 csz = SCHARS (value);
e1d0bbc9
EZ
2486 if (strncmp (color_name, unspecified_fg, csz) == 0)
2487 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2488 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2489 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2490 }
5f65b39d
EZ
2491 }
2492 }
b23236fb
EZ
2493 else
2494 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
67d853e6 2495 }
75700ff2
GM
2496 else if (EQ (parameter, Qdisplay_type)
2497 || EQ (parameter, Qbackground_mode))
75700ff2
GM
2498 value = Fcdr (Fassq (parameter, f->param_alist));
2499 else
2500 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
8b60f7bc 2501 }
177c0ea7 2502
8b60f7bc
GM
2503 return value;
2504}
2505
2506
177c0ea7 2507DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
ff11dfa1 2508 Smodify_frame_parameters, 2, 2, 0,
14ff1ee0
PJ
2509 doc: /* Modify the parameters of frame FRAME according to ALIST.
2510If FRAME is nil, it defaults to the selected frame.
2511ALIST is an alist of parameters to change and their new values.
2512Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2513The meaningful PARMs depend on the kind of frame.
2514Undefined PARMs are ignored, but stored in the frame's parameter list
2515so that `frame-parameters' will return them.
2516
2517The value of frame parameter FOO can also be accessed
2518as a frame-local binding for the variable FOO, if you have
2519enabled such bindings for that variable with `make-variable-frame-local'. */)
2520 (frame, alist)
ff11dfa1 2521 Lisp_Object frame, alist;
dc6f92b8 2522{
fd0c2bd1 2523 FRAME_PTR f;
213bac8a 2524 register Lisp_Object tail, prop, val;
331379bf 2525 int count = SPECPDL_INDEX ();
3df1fda2
GM
2526
2527 /* Bind this to t to inhibit initialization of the default face from
2528 X resources in face-set-after-frame-default. If we don't inhibit
2529 this, modifying the `font' frame parameter, for example, while
2530 there is a `default.attributeFont' X resource, won't work,
2531 because `default's font is reset to the value of the X resource
2532 and that resets the `font' frame parameter. */
2533 specbind (Qinhibit_default_face_x_resources, Qt);
dc6f92b8 2534
ff11dfa1 2535 if (EQ (frame, Qnil))
8d2666fe 2536 frame = selected_frame;
b7826503 2537 CHECK_LIVE_FRAME (frame);
8d2666fe 2538 f = XFRAME (frame);
dc6f92b8 2539
dbc4e1c1 2540 /* I think this should be done with a hook. */
032d78fe
GV
2541#ifdef HAVE_WINDOW_SYSTEM
2542 if (FRAME_WINDOW_P (f))
fd0c2bd1 2543 x_set_frame_parameters (f, alist);
329ca574 2544 else
bb221971
RS
2545#endif
2546#ifdef MSDOS
2547 if (FRAME_MSDOS_P (f))
2548 IT_set_frame_parameters (f, alist);
2549 else
329ca574 2550#endif
574a1a90 2551
41d44f1f
RS
2552 {
2553 int length = XINT (Flength (alist));
2554 int i;
2555 Lisp_Object *parms
2556 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2557 Lisp_Object *values
2558 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2559
2560 /* Extract parm names and values into those vectors. */
2561
2562 i = 0;
2563 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2564 {
213bac8a 2565 Lisp_Object elt;
41d44f1f
RS
2566
2567 elt = Fcar (tail);
2568 parms[i] = Fcar (elt);
2569 values[i] = Fcdr (elt);
2570 i++;
2571 }
2572
2573 /* Now process them in reverse of specified order. */
2574 for (i--; i >= 0; i--)
2575 {
2576 prop = parms[i];
2577 val = values[i];
2578 store_frame_param (f, prop, val);
33d537f0
JL
2579
2580 /* Changing the background color might change the background
2581 mode, so that we have to load new defface specs.
2582 Call frame-set-background-mode to do that. */
2583 if (EQ (prop, Qbackground_color))
2584 call1 (Qframe_set_background_mode, frame);
41d44f1f
RS
2585 }
2586 }
dc6f92b8 2587
3df1fda2 2588 return unbind_to (count, Qnil);
dc6f92b8 2589}
da8e8fc1
KL
2590
2591DEFUN ("frame-with-environment", Fframe_with_environment, Sframe_with_environment, 0, 1, 0,
2592 doc: /* Return the frame that has the environment variable list for FRAME.
2593
2594The frame-local environment variable list is normally shared between
2595frames that were created in the same Emacsclient session. The
2596environment list is stored in a single frame's 'environment parameter;
2597the other frames' 'environment parameter is set to this frame. This
6d8299f6 2598function follows the chain of 'environment references to reach the
da8e8fc1
KL
2599frame that stores the actual local environment list, and returns that
2600frame. */)
2601 (frame)
2602 Lisp_Object frame;
2603{
2604 Lisp_Object hare, tortoise;
2605
2606 if (NILP (frame))
2607 frame = selected_frame;
2608 CHECK_FRAME (frame);
2609
2610 hare = tortoise = get_frame_param (XFRAME (frame), Qenvironment);
2611 while (!NILP (hare) && FRAMEP (hare))
2612 {
2613 frame = hare;
2614 hare = get_frame_param (XFRAME (hare), Qenvironment);
2615 if (NILP (hare) || !FRAMEP (hare))
2616 break;
2617 frame = hare;
2618 hare = get_frame_param (XFRAME (hare), Qenvironment);
2619 tortoise = get_frame_param (XFRAME (tortoise), Qenvironment);
2620 if (EQ (hare, tortoise))
2621 error ("Cyclic frame-local environment indirection");
2622 }
2623
2624 return frame;
2625}
2626
dc6f92b8 2627\f
a26a1f95 2628DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
14ff1ee0
PJ
2629 0, 1, 0,
2630 doc: /* Height in pixels of a line in the font in frame FRAME.
2631If FRAME is omitted, the selected frame is used.
2632For a terminal frame, the value is always 1. */)
ff11dfa1
JB
2633 (frame)
2634 Lisp_Object frame;
dc6f92b8 2635{
a26a1f95 2636 struct frame *f;
dc6f92b8 2637
a26a1f95 2638 if (NILP (frame))
8d2666fe 2639 frame = selected_frame;
b7826503 2640 CHECK_FRAME (frame);
8d2666fe 2641 f = XFRAME (frame);
a26a1f95 2642
032d78fe
GV
2643#ifdef HAVE_WINDOW_SYSTEM
2644 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2645 return make_number (x_char_height (f));
2646 else
dc6d9681 2647#endif
a26a1f95
RS
2648 return make_number (1);
2649}
dc6d9681 2650
dc6f92b8 2651
a26a1f95 2652DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
14ff1ee0
PJ
2653 0, 1, 0,
2654 doc: /* Width in pixels of characters in the font in frame FRAME.
2655If FRAME is omitted, the selected frame is used.
31b7cc74 2656On a graphical screen, the width is the standard width of the default font.
14ff1ee0
PJ
2657For a terminal screen, the value is always 1. */)
2658 (frame)
a26a1f95 2659 Lisp_Object frame;
dc6f92b8 2660{
a26a1f95
RS
2661 struct frame *f;
2662
2663 if (NILP (frame))
8d2666fe 2664 frame = selected_frame;
b7826503 2665 CHECK_FRAME (frame);
8d2666fe 2666 f = XFRAME (frame);
a26a1f95 2667
032d78fe
GV
2668#ifdef HAVE_WINDOW_SYSTEM
2669 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2670 return make_number (x_char_width (f));
2671 else
2672#endif
2673 return make_number (1);
dc6f92b8
JB
2674}
2675
177c0ea7 2676DEFUN ("frame-pixel-height", Fframe_pixel_height,
a26a1f95 2677 Sframe_pixel_height, 0, 1, 0,
14ff1ee0
PJ
2678 doc: /* Return a FRAME's height in pixels.
2679This counts only the height available for text lines,
2680not menu bars on window-system Emacs frames.
2681For a terminal frame, the result really gives the height in characters.
2682If FRAME is omitted, the selected frame is used. */)
2683 (frame)
a26a1f95 2684 Lisp_Object frame;
dc6f92b8 2685{
a26a1f95
RS
2686 struct frame *f;
2687
2688 if (NILP (frame))
8d2666fe 2689 frame = selected_frame;
b7826503 2690 CHECK_FRAME (frame);
8d2666fe 2691 f = XFRAME (frame);
a26a1f95 2692
032d78fe
GV
2693#ifdef HAVE_WINDOW_SYSTEM
2694 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2695 return make_number (x_pixel_height (f));
2696 else
dc6d9681 2697#endif
5af5757b 2698 return make_number (FRAME_LINES (f));
a26a1f95
RS
2699}
2700
177c0ea7 2701DEFUN ("frame-pixel-width", Fframe_pixel_width,
a26a1f95 2702 Sframe_pixel_width, 0, 1, 0,
14ff1ee0
PJ
2703 doc: /* Return FRAME's width in pixels.
2704For a terminal frame, the result really gives the width in characters.
2705If FRAME is omitted, the selected frame is used. */)
2706 (frame)
a26a1f95
RS
2707 Lisp_Object frame;
2708{
2709 struct frame *f;
2710
2711 if (NILP (frame))
8d2666fe 2712 frame = selected_frame;
b7826503 2713 CHECK_FRAME (frame);
8d2666fe 2714 f = XFRAME (frame);
dc6f92b8 2715
032d78fe
GV
2716#ifdef HAVE_WINDOW_SYSTEM
2717 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2718 return make_number (x_pixel_width (f));
2719 else
2720#endif
5af5757b 2721 return make_number (FRAME_COLS (f));
a26a1f95
RS
2722}
2723\f
ff11dfa1 2724DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
14ff1ee0
PJ
2725 doc: /* Specify that the frame FRAME has LINES lines.
2726Optional third arg non-nil means that redisplay should use LINES lines
2727but that the idea of the actual height of the frame should not be changed. */)
2728 (frame, lines, pretend)
735eeca3 2729 Lisp_Object frame, lines, pretend;
dc6f92b8 2730{
ff11dfa1 2731 register struct frame *f;
dc6f92b8 2732
b7826503 2733 CHECK_NUMBER (lines);
ff11dfa1 2734 if (NILP (frame))
8d2666fe 2735 frame = selected_frame;
b7826503 2736 CHECK_LIVE_FRAME (frame);
8d2666fe 2737 f = XFRAME (frame);
dc6f92b8 2738
dbc4e1c1 2739 /* I think this should be done with a hook. */
032d78fe
GV
2740#ifdef HAVE_WINDOW_SYSTEM
2741 if (FRAME_WINDOW_P (f))
dc6f92b8 2742 {
5af5757b
KS
2743 if (XINT (lines) != FRAME_LINES (f))
2744 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
32347cf4 2745 do_pending_window_change (0);
dc6f92b8
JB
2746 }
2747 else
fd0c2bd1 2748#endif
32347cf4 2749 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
dc6f92b8
JB
2750 return Qnil;
2751}
2752
ff11dfa1 2753DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
14ff1ee0
PJ
2754 doc: /* Specify that the frame FRAME has COLS columns.
2755Optional third arg non-nil means that redisplay should use COLS columns
2756but that the idea of the actual width of the frame should not be changed. */)
2757 (frame, cols, pretend)
fd0c2bd1 2758 Lisp_Object frame, cols, pretend;
dc6f92b8 2759{
ff11dfa1 2760 register struct frame *f;
b7826503 2761 CHECK_NUMBER (cols);
ff11dfa1 2762 if (NILP (frame))
8d2666fe 2763 frame = selected_frame;
b7826503 2764 CHECK_LIVE_FRAME (frame);
8d2666fe 2765 f = XFRAME (frame);
dc6f92b8 2766
dbc4e1c1 2767 /* I think this should be done with a hook. */
032d78fe
GV
2768#ifdef HAVE_WINDOW_SYSTEM
2769 if (FRAME_WINDOW_P (f))
dc6f92b8 2770 {
5af5757b
KS
2771 if (XINT (cols) != FRAME_COLS (f))
2772 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
32347cf4 2773 do_pending_window_change (0);
dc6f92b8
JB
2774 }
2775 else
fd0c2bd1 2776#endif
32347cf4 2777 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
dc6f92b8
JB
2778 return Qnil;
2779}
2780
ff11dfa1 2781DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
14ff1ee0
PJ
2782 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2783 (frame, cols, rows)
ff11dfa1 2784 Lisp_Object frame, cols, rows;
dc6f92b8 2785{
ff11dfa1 2786 register struct frame *f;
dc6f92b8 2787
b7826503
PJ
2788 CHECK_LIVE_FRAME (frame);
2789 CHECK_NUMBER (cols);
2790 CHECK_NUMBER (rows);
ff11dfa1 2791 f = XFRAME (frame);
dc6f92b8 2792
dbc4e1c1 2793 /* I think this should be done with a hook. */
032d78fe
GV
2794#ifdef HAVE_WINDOW_SYSTEM
2795 if (FRAME_WINDOW_P (f))
dc6f92b8 2796 {
5af5757b
KS
2797 if (XINT (rows) != FRAME_LINES (f)
2798 || XINT (cols) != FRAME_COLS (f)
2799 || f->new_text_lines || f->new_text_cols)
808c0f20 2800 x_set_window_size (f, 1, XINT (cols), XINT (rows));
32347cf4 2801 do_pending_window_change (0);
dc6f92b8
JB
2802 }
2803 else
fd0c2bd1 2804#endif
32347cf4 2805 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
dc6f92b8
JB
2806
2807 return Qnil;
2808}
2809
177c0ea7 2810DEFUN ("set-frame-position", Fset_frame_position,
ff11dfa1 2811 Sset_frame_position, 3, 3, 0,
14ff1ee0
PJ
2812 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2813This is actually the position of the upper left corner of the frame.
2814Negative values for XOFFSET or YOFFSET are interpreted relative to
2815the rightmost or bottommost possible position (that stays within the screen). */)
2816 (frame, xoffset, yoffset)
ff11dfa1 2817 Lisp_Object frame, xoffset, yoffset;
dc6f92b8 2818{
ff11dfa1 2819 register struct frame *f;
dc6f92b8 2820
b7826503
PJ
2821 CHECK_LIVE_FRAME (frame);
2822 CHECK_NUMBER (xoffset);
2823 CHECK_NUMBER (yoffset);
ff11dfa1 2824 f = XFRAME (frame);
dc6f92b8 2825
dbc4e1c1 2826 /* I think this should be done with a hook. */
032d78fe
GV
2827#ifdef HAVE_WINDOW_SYSTEM
2828 if (FRAME_WINDOW_P (f))
c7c70761 2829 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
fd0c2bd1 2830#endif
dc6f92b8
JB
2831
2832 return Qt;
2833}
dc6d9681 2834
dc6f92b8 2835\f
972f4259
KS
2836/***********************************************************************
2837 Frame Parameters
2838 ***********************************************************************/
2839
2840/* Connect the frame-parameter names for X frames
2841 to the ways of passing the parameter values to the window system.
2842
2843 The name of a parameter, as a Lisp symbol,
2844 has an `x-frame-parameter' property which is an integer in Lisp
2845 that is an index in this table. */
2846
2847struct frame_parm_table {
2848 char *name;
2849 Lisp_Object *variable;
2850};
2851
2852static struct frame_parm_table frame_parms[] =
2853{
2854 {"auto-raise", &Qauto_raise},
2855 {"auto-lower", &Qauto_lower},
2856 {"background-color", 0},
2857 {"border-color", &Qborder_color},
2858 {"border-width", &Qborder_width},
2859 {"cursor-color", &Qcursor_color},
2860 {"cursor-type", &Qcursor_type},
2861 {"font", 0},
2862 {"foreground-color", 0},
2863 {"icon-name", &Qicon_name},
2864 {"icon-type", &Qicon_type},
2865 {"internal-border-width", &Qinternal_border_width},
2866 {"menu-bar-lines", &Qmenu_bar_lines},
2867 {"mouse-color", &Qmouse_color},
2868 {"name", &Qname},
2869 {"scroll-bar-width", &Qscroll_bar_width},
2870 {"title", &Qtitle},
2871 {"unsplittable", &Qunsplittable},
2872 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2873 {"visibility", &Qvisibility},
2874 {"tool-bar-lines", &Qtool_bar_lines},
2875 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2876 {"scroll-bar-background", &Qscroll_bar_background},
2877 {"screen-gamma", &Qscreen_gamma},
2878 {"line-spacing", &Qline_spacing},
2879 {"left-fringe", &Qleft_fringe},
2880 {"right-fringe", &Qright_fringe},
2881 {"wait-for-wm", &Qwait_for_wm},
2882 {"fullscreen", &Qfullscreen},
2883};
2884
2885#ifdef HAVE_WINDOW_SYSTEM
2886
2887extern Lisp_Object Qbox;
2888extern Lisp_Object Qtop;
2889
2890/* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2891 wanted positions of the WM window (not emacs window).
2892 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2893 window (FRAME_X_WINDOW).
2894 */
2895
dfcf069d 2896void
972f4259
KS
2897x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2898 struct frame *f;
2899 int *width;
2900 int *height;
2901 int *top_pos;
2902 int *left_pos;
dc6f92b8 2903{
5af5757b
KS
2904 int newwidth = FRAME_COLS (f);
2905 int newheight = FRAME_LINES (f);
dc6f92b8 2906
5af5757b
KS
2907 *top_pos = f->top_pos;
2908 *left_pos = f->left_pos;
3df1fda2 2909
5af5757b 2910 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
972f4259
KS
2911 {
2912 int ph;
2913
2914 ph = FRAME_X_DISPLAY_INFO (f)->height;
5af5757b
KS
2915 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2916 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2917 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
972f4259
KS
2918 *top_pos = 0;
2919 }
dc6f92b8 2920
5af5757b 2921 if (f->want_fullscreen & FULLSCREEN_WIDTH)
972f4259
KS
2922 {
2923 int pw;
2924
2925 pw = FRAME_X_DISPLAY_INFO (f)->width;
5af5757b
KS
2926 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2927 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2928 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
972f4259
KS
2929 *left_pos = 0;
2930 }
dc6f92b8 2931
972f4259
KS
2932 *width = newwidth;
2933 *height = newheight;
2934}
dc6f92b8 2935
beb0bc36 2936
972f4259
KS
2937/* Change the parameters of frame F as specified by ALIST.
2938 If a parameter is not specially recognized, do nothing special;
2939 otherwise call the `x_set_...' function for that parameter.
2940 Except for certain geometry properties, always call store_frame_param
2941 to store the new value in the parameter alist. */
14ff1ee0 2942
972f4259
KS
2943void
2944x_set_frame_parameters (f, alist)
2945 FRAME_PTR f;
2946 Lisp_Object alist;
2947{
2948 Lisp_Object tail;
dc6f92b8 2949
972f4259
KS
2950 /* If both of these parameters are present, it's more efficient to
2951 set them both at once. So we wait until we've looked at the
2952 entire list before we set them. */
2953 int width, height;
3df1fda2 2954
972f4259
KS
2955 /* Same here. */
2956 Lisp_Object left, top;
2957
2958 /* Same with these. */
2959 Lisp_Object icon_left, icon_top;
2960
2961 /* Record in these vectors all the parms specified. */
2962 Lisp_Object *parms;
2963 Lisp_Object *values;
2964 int i, p;
2965 int left_no_change = 0, top_no_change = 0;
2966 int icon_left_no_change = 0, icon_top_no_change = 0;
2967 int fullscreen_is_being_set = 0;
2968
2969 struct gcpro gcpro1, gcpro2;
2970
2971 i = 0;
2972 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2973 i++;
2974
2975 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2976 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2977
2978 /* Extract parm names and values into those vectors. */
2979
2980 i = 0;
2981 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2982 {
2983 Lisp_Object elt;
2984
2985 elt = Fcar (tail);
2986 parms[i] = Fcar (elt);
2987 values[i] = Fcdr (elt);
2988 i++;
2989 }
2990 /* TAIL and ALIST are not used again below here. */
2991 alist = tail = Qnil;
2992
2993 GCPRO2 (*parms, *values);
2994 gcpro1.nvars = i;
2995 gcpro2.nvars = i;
2996
2997 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2998 because their values appear in VALUES and strings are not valid. */
2999 top = left = Qunbound;
3000 icon_left = icon_top = Qunbound;
3001
3002 /* Provide default values for HEIGHT and WIDTH. */
5af5757b
KS
3003 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
3004 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
972f4259
KS
3005
3006 /* Process foreground_color and background_color before anything else.
3007 They are independent of other properties, but other properties (e.g.,
3008 cursor_color) are dependent upon them. */
3009 /* Process default font as well, since fringe widths depends on it. */
3010 /* Also, process fullscreen, width and height depend upon that */
3011 for (p = 0; p < i; p++)
3012 {
3013 Lisp_Object prop, val;
3014
3015 prop = parms[p];
3016 val = values[p];
3017 if (EQ (prop, Qforeground_color)
3018 || EQ (prop, Qbackground_color)
3019 || EQ (prop, Qfont)
3020 || EQ (prop, Qfullscreen))
3021 {
3022 register Lisp_Object param_index, old_value;
3023
3024 old_value = get_frame_param (f, prop);
3025 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
3026
3027 if (NILP (Fequal (val, old_value)))
3028 {
3029 store_frame_param (f, prop, val);
3030
3031 param_index = Fget (prop, Qx_frame_parameter);
3032 if (NATNUMP (param_index)
3033 && (XFASTINT (param_index)
3034 < sizeof (frame_parms)/sizeof (frame_parms[0]))
fa971ac3
KL
3035 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3036 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
972f4259
KS
3037 }
3038 }
3039 }
3040
3041 /* Now process them in reverse of specified order. */
3042 for (i--; i >= 0; i--)
3043 {
3044 Lisp_Object prop, val;
3045
3046 prop = parms[i];
3047 val = values[i];
3048
3049 if (EQ (prop, Qwidth) && NUMBERP (val))
3050 width = XFASTINT (val);
3051 else if (EQ (prop, Qheight) && NUMBERP (val))
3052 height = XFASTINT (val);
3053 else if (EQ (prop, Qtop))
3054 top = val;
3055 else if (EQ (prop, Qleft))
3056 left = val;
3057 else if (EQ (prop, Qicon_top))
3058 icon_top = val;
3059 else if (EQ (prop, Qicon_left))
3060 icon_left = val;
3061 else if (EQ (prop, Qforeground_color)
3062 || EQ (prop, Qbackground_color)
3063 || EQ (prop, Qfont)
3064 || EQ (prop, Qfullscreen))
3065 /* Processed above. */
3066 continue;
3067 else
3068 {
3069 register Lisp_Object param_index, old_value;
3070
3071 old_value = get_frame_param (f, prop);
3072
3073 store_frame_param (f, prop, val);
3074
3075 param_index = Fget (prop, Qx_frame_parameter);
3076 if (NATNUMP (param_index)
3077 && (XFASTINT (param_index)
3078 < sizeof (frame_parms)/sizeof (frame_parms[0]))
fa971ac3
KL
3079 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3080 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
972f4259
KS
3081 }
3082 }
3083
3084 /* Don't die if just one of these was set. */
3085 if (EQ (left, Qunbound))
3086 {
3087 left_no_change = 1;
5af5757b
KS
3088 if (f->left_pos < 0)
3089 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
972f4259 3090 else
5af5757b 3091 XSETINT (left, f->left_pos);
972f4259
KS
3092 }
3093 if (EQ (top, Qunbound))
3094 {
3095 top_no_change = 1;
5af5757b
KS
3096 if (f->top_pos < 0)
3097 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
972f4259 3098 else
5af5757b 3099 XSETINT (top, f->top_pos);
972f4259
KS
3100 }
3101
3102 /* If one of the icon positions was not set, preserve or default it. */
3103 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
3104 {
3105 icon_left_no_change = 1;
3106 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3107 if (NILP (icon_left))
3108 XSETINT (icon_left, 0);
3109 }
3110 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
3111 {
3112 icon_top_no_change = 1;
3113 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3114 if (NILP (icon_top))
3115 XSETINT (icon_top, 0);
3116 }
3117
972f4259
KS
3118 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
3119 {
3120 /* If the frame is visible already and the fullscreen parameter is
3121 being set, it is too late to set WM manager hints to specify
3122 size and position.
3123 Here we first get the width, height and position that applies to
3124 fullscreen. We then move the frame to the appropriate
3125 position. Resize of the frame is taken care of in the code after
3126 this if-statement. */
3127 int new_left, new_top;
3128
3129 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
068ae0fd
JD
3130 if (new_top != f->top_pos || new_left != f->left_pos)
3131 x_set_offset (f, new_left, new_top, 1);
972f4259 3132 }
972f4259
KS
3133
3134 /* Don't set these parameters unless they've been explicitly
3135 specified. The window might be mapped or resized while we're in
3136 this function, and we don't want to override that unless the lisp
3137 code has asked for it.
3138
3139 Don't set these parameters unless they actually differ from the
3140 window's current parameters; the window may not actually exist
3141 yet. */
3142 {
3143 Lisp_Object frame;
3144
3145 check_frame_size (f, &height, &width);
3146
3147 XSETFRAME (frame, f);
3148
5af5757b
KS
3149 if (width != FRAME_COLS (f)
3150 || height != FRAME_LINES (f)
3151 || f->new_text_lines || f->new_text_cols)
972f4259
KS
3152 Fset_frame_size (frame, make_number (width), make_number (height));
3153
3154 if ((!NILP (left) || !NILP (top))
3155 && ! (left_no_change && top_no_change)
5af5757b
KS
3156 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3157 && NUMBERP (top) && XINT (top) == f->top_pos))
972f4259
KS
3158 {
3159 int leftpos = 0;
3160 int toppos = 0;
3161
3162 /* Record the signs. */
5af5757b 3163 f->size_hint_flags &= ~ (XNegative | YNegative);
972f4259 3164 if (EQ (left, Qminus))
5af5757b 3165 f->size_hint_flags |= XNegative;
972f4259
KS
3166 else if (INTEGERP (left))
3167 {
3168 leftpos = XINT (left);
3169 if (leftpos < 0)
5af5757b 3170 f->size_hint_flags |= XNegative;
972f4259
KS
3171 }
3172 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3173 && CONSP (XCDR (left))
3174 && INTEGERP (XCAR (XCDR (left))))
3175 {
3176 leftpos = - XINT (XCAR (XCDR (left)));
5af5757b 3177 f->size_hint_flags |= XNegative;
972f4259
KS
3178 }
3179 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3180 && CONSP (XCDR (left))
3181 && INTEGERP (XCAR (XCDR (left))))
3182 {
3183 leftpos = XINT (XCAR (XCDR (left)));
3184 }
3185
3186 if (EQ (top, Qminus))
5af5757b 3187 f->size_hint_flags |= YNegative;
972f4259
KS
3188 else if (INTEGERP (top))
3189 {
3190 toppos = XINT (top);
3191 if (toppos < 0)
5af5757b 3192 f->size_hint_flags |= YNegative;
972f4259
KS
3193 }
3194 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3195 && CONSP (XCDR (top))
3196 && INTEGERP (XCAR (XCDR (top))))
3197 {
3198 toppos = - XINT (XCAR (XCDR (top)));
5af5757b 3199 f->size_hint_flags |= YNegative;
972f4259
KS
3200 }
3201 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3202 && CONSP (XCDR (top))
3203 && INTEGERP (XCAR (XCDR (top))))
3204 {
3205 toppos = XINT (XCAR (XCDR (top)));
3206 }
3207
3208
3209 /* Store the numeric value of the position. */
5af5757b
KS
3210 f->top_pos = toppos;
3211 f->left_pos = leftpos;
972f4259 3212
5af5757b 3213 f->win_gravity = NorthWestGravity;
972f4259
KS
3214
3215 /* Actually set that position, and convert to absolute. */
3216 x_set_offset (f, leftpos, toppos, -1);
3217 }
3218
3219 if ((!NILP (icon_left) || !NILP (icon_top))
3220 && ! (icon_left_no_change && icon_top_no_change))
3221 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3222 }
3223
3224 UNGCPRO;
3225}
3226
3227
3228/* Insert a description of internally-recorded parameters of frame X
3229 into the parameter alist *ALISTPTR that is to be given to the user.
3230 Only parameters that are specific to the X window system
3231 and whose values are not correctly recorded in the frame's
3232 param_alist need to be considered here. */
3233
3234void
3235x_report_frame_params (f, alistptr)
3236 struct frame *f;
3237 Lisp_Object *alistptr;
3238{
3239 char buf[16];
3240 Lisp_Object tem;
3241
3242 /* Represent negative positions (off the top or left screen edge)
3243 in a way that Fmodify_frame_parameters will understand correctly. */
5af5757b
KS
3244 XSETINT (tem, f->left_pos);
3245 if (f->left_pos >= 0)
972f4259
KS
3246 store_in_alist (alistptr, Qleft, tem);
3247 else
3248 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3249
5af5757b
KS
3250 XSETINT (tem, f->top_pos);
3251 if (f->top_pos >= 0)
972f4259
KS
3252 store_in_alist (alistptr, Qtop, tem);
3253 else
3254 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3255
3256 store_in_alist (alistptr, Qborder_width,
5af5757b 3257 make_number (f->border_width));
972f4259 3258 store_in_alist (alistptr, Qinternal_border_width,
5af5757b 3259 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
972f4259 3260 store_in_alist (alistptr, Qleft_fringe,
5af5757b 3261 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
972f4259 3262 store_in_alist (alistptr, Qright_fringe,
5af5757b 3263 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
972f4259
KS
3264 store_in_alist (alistptr, Qscroll_bar_width,
3265 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3266 ? make_number (0)
5af5757b
KS
3267 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3268 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
972f4259
KS
3269 /* nil means "use default width"
3270 for non-toolkit scroll bar.
3271 ruler-mode.el depends on this. */
3272 : Qnil));
3273 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3274 store_in_alist (alistptr, Qwindow_id,
3275 build_string (buf));
3276#ifdef HAVE_X_WINDOWS
3277#ifdef USE_X_TOOLKIT
3278 /* Tooltip frame may not have this widget. */
3279 if (FRAME_X_OUTPUT (f)->widget)
3280#endif
3281 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3282 store_in_alist (alistptr, Qouter_window_id,
3283 build_string (buf));
3284#endif
3285 store_in_alist (alistptr, Qicon_name, f->icon_name);
3286 FRAME_SAMPLE_VISIBILITY (f);
3287 store_in_alist (alistptr, Qvisibility,
3288 (FRAME_VISIBLE_P (f) ? Qt
3289 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3290 store_in_alist (alistptr, Qdisplay,
3291 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3292
3293 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3294 tem = Qnil;
3295 else
3296 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3297 store_in_alist (alistptr, Qparent_id, tem);
3298}
3299
3300
3301/* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3302 the previous value of that parameter, NEW_VALUE is the new value. */
3303
3304void
3305x_set_fullscreen (f, new_value, old_value)
3306 struct frame *f;
3307 Lisp_Object new_value, old_value;
3308{
972f4259 3309 if (NILP (new_value))
5af5757b 3310 f->want_fullscreen = FULLSCREEN_NONE;
972f4259 3311 else if (EQ (new_value, Qfullboth))
5af5757b 3312 f->want_fullscreen = FULLSCREEN_BOTH;
972f4259 3313 else if (EQ (new_value, Qfullwidth))
5af5757b 3314 f->want_fullscreen = FULLSCREEN_WIDTH;
972f4259 3315 else if (EQ (new_value, Qfullheight))
5af5757b 3316 f->want_fullscreen = FULLSCREEN_HEIGHT;
972f4259
KS
3317}
3318
3319
3320/* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3321 the previous value of that parameter, NEW_VALUE is the new value. */
3322
3323void
3324x_set_line_spacing (f, new_value, old_value)
3325 struct frame *f;
3326 Lisp_Object new_value, old_value;
3327{
3328 if (NILP (new_value))
3329 f->extra_line_spacing = 0;
3330 else if (NATNUMP (new_value))
3331 f->extra_line_spacing = XFASTINT (new_value);
3332 else
3333 Fsignal (Qerror, Fcons (build_string ("Invalid line-spacing"),
3334 Fcons (new_value, Qnil)));
3335 if (FRAME_VISIBLE_P (f))
3336 redraw_frame (f);
3337}
3338
3339
3340/* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3341 the previous value of that parameter, NEW_VALUE is the new value. */
3342
3343void
3344x_set_screen_gamma (f, new_value, old_value)
3345 struct frame *f;
3346 Lisp_Object new_value, old_value;
3347{
3348 if (NILP (new_value))
3349 f->gamma = 0;
3350 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3351 /* The value 0.4545 is the normal viewing gamma. */
3352 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3353 else
3354 Fsignal (Qerror, Fcons (build_string ("Invalid screen-gamma"),
3355 Fcons (new_value, Qnil)));
3356
3357 clear_face_cache (0);
3358}
3359
3360
3361void
3362x_set_font (f, arg, oldval)
3363 struct frame *f;
3364 Lisp_Object arg, oldval;
3365{
3366 Lisp_Object result;
3367 Lisp_Object fontset_name;
3368 Lisp_Object frame;
3369 int old_fontset = FRAME_FONTSET(f);
3370
3371 CHECK_STRING (arg);
3372
3373 fontset_name = Fquery_fontset (arg, Qnil);
3374
3375 BLOCK_INPUT;
3376 result = (STRINGP (fontset_name)
3377 ? x_new_fontset (f, SDATA (fontset_name))
3378 : x_new_font (f, SDATA (arg)));
3379 UNBLOCK_INPUT;
3380
3381 if (EQ (result, Qnil))
3382 error ("Font `%s' is not defined", SDATA (arg));
3383 else if (EQ (result, Qt))
3384 error ("The characters of the given font have varying widths");
3385 else if (STRINGP (result))
3386 {
ee5d57b0 3387 set_default_ascii_font (result);
972f4259
KS
3388 if (STRINGP (fontset_name))
3389 {
3390 /* Fontset names are built from ASCII font names, so the
3391 names may be equal despite there was a change. */
3392 if (old_fontset == FRAME_FONTSET (f))
3393 return;
3394 }
3395 else if (!NILP (Fequal (result, oldval)))
3396 return;
3397
3398 store_frame_param (f, Qfont, result);
3399 recompute_basic_faces (f);
3400 }
3401 else
3402 abort ();
3403
3404 do_pending_window_change (0);
3405
3406 /* Don't call `face-set-after-frame-default' when faces haven't been
3407 initialized yet. This is the case when called from
3408 Fx_create_frame. In that case, the X widget or window doesn't
3409 exist either, and we can end up in x_report_frame_params with a
3410 null widget which gives a segfault. */
3411 if (FRAME_FACE_CACHE (f))
3412 {
3413 XSETFRAME (frame, f);
3414 call1 (Qface_set_after_frame_default, frame);
3415 }
3416}
3417
3418
3419void
3420x_set_fringe_width (f, new_value, old_value)
3421 struct frame *f;
3422 Lisp_Object new_value, old_value;
3423{
3424 compute_fringe_widths (f, 1);
3425}
3426
3427void
3428x_set_border_width (f, arg, oldval)
3429 struct frame *f;
3430 Lisp_Object arg, oldval;
3431{
3432 CHECK_NUMBER (arg);
3433
5af5757b 3434 if (XINT (arg) == f->border_width)
972f4259
KS
3435 return;
3436
b15325b2 3437#ifndef MAC_OS
972f4259
KS
3438 if (FRAME_X_WINDOW (f) != 0)
3439 error ("Cannot change the border width of a window");
3440#endif /* MAC_TODO */
3441
5af5757b 3442 f->border_width = XINT (arg);
972f4259
KS
3443}
3444
3445void
3446x_set_internal_border_width (f, arg, oldval)
3447 struct frame *f;
3448 Lisp_Object arg, oldval;
3449{
5af5757b 3450 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
972f4259
KS
3451
3452 CHECK_NUMBER (arg);
5af5757b
KS
3453 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3454 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3455 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
972f4259
KS
3456
3457#ifdef USE_X_TOOLKIT
3458 if (FRAME_X_OUTPUT (f)->edit_widget)
3459 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3460#endif
3461
5af5757b 3462 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
972f4259
KS
3463 return;
3464
3465 if (FRAME_X_WINDOW (f) != 0)
3466 {
5af5757b 3467 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
972f4259
KS
3468 SET_FRAME_GARBAGED (f);
3469 do_pending_window_change (0);
3470 }
3471 else
3472 SET_FRAME_GARBAGED (f);
3473}
3474
3475void
3476x_set_visibility (f, value, oldval)
3477 struct frame *f;
3478 Lisp_Object value, oldval;
3479{
3480 Lisp_Object frame;
3481 XSETFRAME (frame, f);
3482
3483 if (NILP (value))
3484 Fmake_frame_invisible (frame, Qt);
3485 else if (EQ (value, Qicon))
3486 Ficonify_frame (frame);
3487 else
3488 Fmake_frame_visible (frame);
3489}
3490
3491void
3492x_set_autoraise (f, arg, oldval)
3493 struct frame *f;
3494 Lisp_Object arg, oldval;
3495{
3496 f->auto_raise = !EQ (Qnil, arg);
3497}
3498
3499void
3500x_set_autolower (f, arg, oldval)
3501 struct frame *f;
3502 Lisp_Object arg, oldval;
3503{
3504 f->auto_lower = !EQ (Qnil, arg);
3505}
3506
3507void
3508x_set_unsplittable (f, arg, oldval)
3509 struct frame *f;
3510 Lisp_Object arg, oldval;
3511{
3512 f->no_split = !NILP (arg);
3513}
3514
3515void
3516x_set_vertical_scroll_bars (f, arg, oldval)
3517 struct frame *f;
3518 Lisp_Object arg, oldval;
3519{
3520 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3521 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3522 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3523 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3524 {
3525 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3526 = (NILP (arg)
3527 ? vertical_scroll_bar_none
3528 : EQ (Qleft, arg)
3529 ? vertical_scroll_bar_left
3530 : EQ (Qright, arg)
3531 ? vertical_scroll_bar_right
a6e20602
KS
3532 : EQ (Qleft, Vdefault_frame_scroll_bars)
3533 ? vertical_scroll_bar_left
3534 : EQ (Qright, Vdefault_frame_scroll_bars)
3535 ? vertical_scroll_bar_right
3536 : vertical_scroll_bar_none);
972f4259
KS
3537
3538 /* We set this parameter before creating the X window for the
3539 frame, so we can get the geometry right from the start.
3540 However, if the window hasn't been created yet, we shouldn't
3541 call x_set_window_size. */
3542 if (FRAME_X_WINDOW (f))
5af5757b 3543 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
972f4259
KS
3544 do_pending_window_change (0);
3545 }
3546}
3547
3548void
3549x_set_scroll_bar_width (f, arg, oldval)
3550 struct frame *f;
3551 Lisp_Object arg, oldval;
3552{
5af5757b 3553 int wid = FRAME_COLUMN_WIDTH (f);
972f4259
KS
3554
3555 if (NILP (arg))
3556 {
3557 x_set_scroll_bar_default_width (f);
3558
3559 if (FRAME_X_WINDOW (f))
5af5757b 3560 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
972f4259
KS
3561 do_pending_window_change (0);
3562 }
3563 else if (INTEGERP (arg) && XINT (arg) > 0
5af5757b 3564 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
972f4259
KS
3565 {
3566 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3567 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3568
5af5757b
KS
3569 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3570 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
972f4259 3571 if (FRAME_X_WINDOW (f))
5af5757b 3572 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
972f4259
KS
3573 do_pending_window_change (0);
3574 }
3575
5af5757b 3576 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
972f4259
KS
3577 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3578 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3579}
3580
3581
3582
3583/* Return non-nil if frame F wants a bitmap icon. */
3584
3585Lisp_Object
3586x_icon_type (f)
3587 FRAME_PTR f;
3588{
3589 Lisp_Object tem;
3590
3591 tem = assq_no_quit (Qicon_type, f->param_alist);
3592 if (CONSP (tem))
3593 return XCDR (tem);
3594 else
3595 return Qnil;
3596}
3597
3598\f
3599/* Subroutines of creating an X frame. */
3600
3601/* Make sure that Vx_resource_name is set to a reasonable value.
3602 Fix it up, or set it to `emacs' if it is too hopeless. */
3603
3604void
3605validate_x_resource_name ()
3606{
3607 int len = 0;
3608 /* Number of valid characters in the resource name. */
3609 int good_count = 0;
3610 /* Number of invalid characters in the resource name. */
3611 int bad_count = 0;
3612 Lisp_Object new;
3613 int i;
3614
3615 if (!STRINGP (Vx_resource_class))
3616 Vx_resource_class = build_string (EMACS_CLASS);
3617
3618 if (STRINGP (Vx_resource_name))
3619 {
3620 unsigned char *p = SDATA (Vx_resource_name);
3621 int i;
3622
3623 len = SBYTES (Vx_resource_name);
3624
3625 /* Only letters, digits, - and _ are valid in resource names.
3626 Count the valid characters and count the invalid ones. */
3627 for (i = 0; i < len; i++)
3628 {
3629 int c = p[i];
3630 if (! ((c >= 'a' && c <= 'z')
3631 || (c >= 'A' && c <= 'Z')
3632 || (c >= '0' && c <= '9')
3633 || c == '-' || c == '_'))
3634 bad_count++;
3635 else
3636 good_count++;
3637 }
3638 }
3639 else
3640 /* Not a string => completely invalid. */
3641 bad_count = 5, good_count = 0;
3642
3643 /* If name is valid already, return. */
3644 if (bad_count == 0)
3645 return;
3646
3647 /* If name is entirely invalid, or nearly so, use `emacs'. */
3648 if (good_count == 0
3649 || (good_count == 1 && bad_count > 0))
3650 {
3651 Vx_resource_name = build_string ("emacs");
3652 return;
3653 }
3654
3655 /* Name is partly valid. Copy it and replace the invalid characters
3656 with underscores. */
3657
3658 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3659
3660 for (i = 0; i < len; i++)
3661 {
3662 int c = SREF (new, i);
3663 if (! ((c >= 'a' && c <= 'z')
3664 || (c >= 'A' && c <= 'Z')
3665 || (c >= '0' && c <= '9')
3666 || c == '-' || c == '_'))
3667 SSET (new, i, '_');
3668 }
3669}
3670
3671
3672extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3673extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3674
3675
b5251fe7 3676/* Get specified attribute from resource database RDB.
972f4259
KS
3677 See Fx_get_resource below for other parameters. */
3678
3679static Lisp_Object
3680xrdb_get_resource (rdb, attribute, class, component, subclass)
3681 XrmDatabase rdb;
3682 Lisp_Object attribute, class, component, subclass;
3683{
3684 register char *value;
3685 char *name_key;
3686 char *class_key;
3687
3688 CHECK_STRING (attribute);
3689 CHECK_STRING (class);
3690
3691 if (!NILP (component))
3692 CHECK_STRING (component);
3693 if (!NILP (subclass))
3694 CHECK_STRING (subclass);
3695 if (NILP (component) != NILP (subclass))
3696 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3697
3698 validate_x_resource_name ();
3699
3700 /* Allocate space for the components, the dots which separate them,
3701 and the final '\0'. Make them big enough for the worst case. */
3702 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3703 + (STRINGP (component)
3704 ? SBYTES (component) : 0)
3705 + SBYTES (attribute)
3706 + 3);
3707
3708 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3709 + SBYTES (class)
3710 + (STRINGP (subclass)
3711 ? SBYTES (subclass) : 0)
3712 + 3);
3713
3714 /* Start with emacs.FRAMENAME for the name (the specific one)
3715 and with `Emacs' for the class key (the general one). */
3716 strcpy (name_key, SDATA (Vx_resource_name));
3717 strcpy (class_key, SDATA (Vx_resource_class));
3718
3719 strcat (class_key, ".");
3720 strcat (class_key, SDATA (class));
3721
3722 if (!NILP (component))
3723 {
3724 strcat (class_key, ".");
3725 strcat (class_key, SDATA (subclass));
3726
3727 strcat (name_key, ".");
3728 strcat (name_key, SDATA (component));
3729 }
3730
3731 strcat (name_key, ".");
3732 strcat (name_key, SDATA (attribute));
3733
3734 value = x_get_string_resource (rdb, name_key, class_key);
3735
3736 if (value != (char *) 0)
3737 return build_string (value);
3738 else
3739 return Qnil;
3740}
3741
3742
3743DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3744 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3745This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3746class, where INSTANCE is the name under which Emacs was invoked, or
3747the name specified by the `-name' or `-rn' command-line arguments.
3748
3749The optional arguments COMPONENT and SUBCLASS add to the key and the
3750class, respectively. You must specify both of them or neither.
3751If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3752and the class is `Emacs.CLASS.SUBCLASS'. */)
3753 (attribute, class, component, subclass)
3754 Lisp_Object attribute, class, component, subclass;
3755{
3756#ifdef HAVE_X_WINDOWS
3757 check_x ();
3758#endif
3759
3760 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3761 attribute, class, component, subclass);
3762}
3763
3764/* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3765
3766Lisp_Object
3767display_x_get_resource (dpyinfo, attribute, class, component, subclass)
a1702920 3768 Display_Info *dpyinfo;
972f4259
KS
3769 Lisp_Object attribute, class, component, subclass;
3770{
3771 return xrdb_get_resource (dpyinfo->xrdb,
3772 attribute, class, component, subclass);
3773}
3774
3775/* Used when C code wants a resource value. */
3776
3777char *
3778x_get_resource_string (attribute, class)
3779 char *attribute, *class;
3780{
3781 char *name_key;
3782 char *class_key;
3783 struct frame *sf = SELECTED_FRAME ();
3784
3785 /* Allocate space for the components, the dots which separate them,
3786 and the final '\0'. */
3787 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3788 + strlen (attribute) + 2);
3789 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3790 + strlen (class) + 2);
3791
3792 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3793 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3794
3795 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3796 name_key, class_key);
3797}
3798
3799
3800/* Return the value of parameter PARAM.
3801
3802 First search ALIST, then Vdefault_frame_alist, then the X defaults
3803 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3804
3805 Convert the resource to the type specified by desired_type.
3806
3807 If no default is specified, return Qunbound. If you call
3808 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3809 and don't let it get stored in any Lisp-visible variables! */
3810
3811Lisp_Object
3812x_get_arg (dpyinfo, alist, param, attribute, class, type)
b5251fe7 3813 Display_Info *dpyinfo;
972f4259
KS
3814 Lisp_Object alist, param;
3815 char *attribute;
3816 char *class;
3817 enum resource_types type;
3818{
3819 register Lisp_Object tem;
3820
3821 tem = Fassq (param, alist);
3822 if (EQ (tem, Qnil))
3823 tem = Fassq (param, Vdefault_frame_alist);
3824 if (EQ (tem, Qnil))
3825 {
3826 if (attribute)
3827 {
3828 tem = display_x_get_resource (dpyinfo,
3829 build_string (attribute),
3830 build_string (class),
3831 Qnil, Qnil);
3832
3833 if (NILP (tem))
3834 return Qunbound;
3835
3836 switch (type)
3837 {
3838 case RES_TYPE_NUMBER:
3839 return make_number (atoi (SDATA (tem)));
3840
3841 case RES_TYPE_FLOAT:
3842 return make_float (atof (SDATA (tem)));
3843
3844 case RES_TYPE_BOOLEAN:
3845 tem = Fdowncase (tem);
3846 if (!strcmp (SDATA (tem), "on")
3847 || !strcmp (SDATA (tem), "true"))
3848 return Qt;
3849 else
3850 return Qnil;
3851
3852 case RES_TYPE_STRING:
3853 return tem;
3854
3855 case RES_TYPE_SYMBOL:
3856 /* As a special case, we map the values `true' and `on'
3857 to Qt, and `false' and `off' to Qnil. */
3858 {
3859 Lisp_Object lower;
3860 lower = Fdowncase (tem);
3861 if (!strcmp (SDATA (lower), "on")
3862 || !strcmp (SDATA (lower), "true"))
3863 return Qt;
3864 else if (!strcmp (SDATA (lower), "off")
3865 || !strcmp (SDATA (lower), "false"))
3866 return Qnil;
3867 else
3868 return Fintern (tem, Qnil);
3869 }
3870
3871 default:
3872 abort ();
3873 }
3874 }
3875 else
3876 return Qunbound;
3877 }
3878 return Fcdr (tem);
3879}
3880
3881Lisp_Object
3882x_frame_get_arg (f, alist, param, attribute, class, type)
3883 struct frame *f;
3884 Lisp_Object alist, param;
3885 char *attribute;
3886 char *class;
3887 enum resource_types type;
3888{
3889 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3890 alist, param, attribute, class, type);
3891}
3892
3893/* Like x_frame_get_arg, but also record the value in f->param_alist. */
3894
3895Lisp_Object
3896x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
3897 struct frame *f;
3898 Lisp_Object alist, param;
3899 char *attribute;
3900 char *class;
3901 enum resource_types type;
3902{
3903 Lisp_Object value;
3904
3905 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3906 attribute, class, type);
3907 if (! NILP (value))
3908 store_frame_param (f, param, value);
3909
3910 return value;
3911}
3912
3913
3914/* Record in frame F the specified or default value according to ALIST
3915 of the parameter named PROP (a Lisp symbol).
3916 If no value is specified for PROP, look for an X default for XPROP
3917 on the frame named NAME.
3918 If that is not found either, use the value DEFLT. */
3919
3920Lisp_Object
3921x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
3922 struct frame *f;
3923 Lisp_Object alist;
3924 Lisp_Object prop;
3925 Lisp_Object deflt;
3926 char *xprop;
3927 char *xclass;
3928 enum resource_types type;
3929{
3930 Lisp_Object tem;
3931
3932 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3933 if (EQ (tem, Qunbound))
3934 tem = deflt;
3935 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3936 return tem;
3937}
3938
3939
3940
3941\f
3942DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3943 doc: /* Parse an X-style geometry string STRING.
3944Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3945The properties returned may include `top', `left', `height', and `width'.
3946The value of `left' or `top' may be an integer,
3947or a list (+ N) meaning N pixels relative to top/left corner,
3948or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3949 (string)
3950 Lisp_Object string;
3951{
3952 int geometry, x, y;
3953 unsigned int width, height;
3954 Lisp_Object result;
3955
3956 CHECK_STRING (string);
3957
3958 geometry = XParseGeometry ((char *) SDATA (string),
3959 &x, &y, &width, &height);
3960
3961#if 0
3962 if (!!(geometry & XValue) != !!(geometry & YValue))
3963 error ("Must specify both x and y position, or neither");
3964#endif
3965
3966 result = Qnil;
3967 if (geometry & XValue)
3968 {
3969 Lisp_Object element;
3970
3971 if (x >= 0 && (geometry & XNegative))
3972 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3973 else if (x < 0 && ! (geometry & XNegative))
3974 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3975 else
3976 element = Fcons (Qleft, make_number (x));
3977 result = Fcons (element, result);
3978 }
3979
3980 if (geometry & YValue)
3981 {
3982 Lisp_Object element;
3983
3984 if (y >= 0 && (geometry & YNegative))
3985 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3986 else if (y < 0 && ! (geometry & YNegative))
3987 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3988 else
3989 element = Fcons (Qtop, make_number (y));
3990 result = Fcons (element, result);
3991 }
3992
3993 if (geometry & WidthValue)
3994 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3995 if (geometry & HeightValue)
3996 result = Fcons (Fcons (Qheight, make_number (height)), result);
3997
3998 return result;
3999}
4000
4001/* Calculate the desired size and position of frame F.
4002 Return the flags saying which aspects were specified.
4003
4004 Also set the win_gravity and size_hint_flags of F.
4005
4006 Adjust height for toolbar if TOOLBAR_P is 1.
4007
4008 This function does not make the coordinates positive. */
4009
4010#define DEFAULT_ROWS 40
4011#define DEFAULT_COLS 80
4012
4013int
4014x_figure_window_size (f, parms, toolbar_p)
4015 struct frame *f;
4016 Lisp_Object parms;
4017 int toolbar_p;
4018{
4019 register Lisp_Object tem0, tem1, tem2;
4020 long window_prompting = 0;
4021 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
4022
4023 /* Default values if we fall through.
4024 Actually, if that happens we should get
4025 window manager prompting. */
5af5757b
KS
4026 SET_FRAME_COLS (f, DEFAULT_COLS);
4027 FRAME_LINES (f) = DEFAULT_ROWS;
972f4259
KS
4028 /* Window managers expect that if program-specified
4029 positions are not (0,0), they're intentional, not defaults. */
5af5757b
KS
4030 f->top_pos = 0;
4031 f->left_pos = 0;
972f4259 4032
5af5757b 4033 /* Ensure that old new_text_cols and new_text_lines will not override the
972f4259
KS
4034 values set here. */
4035 /* ++KFS: This was specific to W32, but seems ok for all platforms */
5af5757b 4036 f->new_text_cols = f->new_text_lines = 0;
972f4259
KS
4037
4038 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4039 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4040 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4041 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4042 {
4043 if (!EQ (tem0, Qunbound))
4044 {
4045 CHECK_NUMBER (tem0);
5af5757b 4046 FRAME_LINES (f) = XINT (tem0);
972f4259
KS
4047 }
4048 if (!EQ (tem1, Qunbound))
4049 {
4050 CHECK_NUMBER (tem1);
5af5757b 4051 SET_FRAME_COLS (f, XINT (tem1));
972f4259
KS
4052 }
4053 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4054 window_prompting |= USSize;
4055 else
4056 window_prompting |= PSize;
4057 }
4058
5af5757b
KS
4059 f->scroll_bar_actual_width
4060 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
972f4259
KS
4061
4062 /* This used to be done _before_ calling x_figure_window_size, but
4063 since the height is reset here, this was really a no-op. I
4064 assume that moving it here does what Gerd intended (although he
4065 no longer can remember what that was... ++KFS, 2003-03-25. */
4066
4067 /* Add the tool-bar height to the initial frame height so that the
4068 user gets a text display area of the size he specified with -g or
4069 via .Xdefaults. Later changes of the tool-bar height don't
4070 change the frame size. This is done so that users can create
4071 tall Emacs frames without having to guess how tall the tool-bar
4072 will get. */
4073 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4074 {
4075 int margin, relief, bar_height;
4076
4077 relief = (tool_bar_button_relief >= 0
4078 ? tool_bar_button_relief
4079 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4080
4081 if (INTEGERP (Vtool_bar_button_margin)
4082 && XINT (Vtool_bar_button_margin) > 0)
4083 margin = XFASTINT (Vtool_bar_button_margin);
4084 else if (CONSP (Vtool_bar_button_margin)
4085 && INTEGERP (XCDR (Vtool_bar_button_margin))
4086 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
4087 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4088 else
4089 margin = 0;
4090
4091 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
5af5757b 4092 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
972f4259
KS
4093 }
4094
4095 compute_fringe_widths (f, 0);
4096
5af5757b
KS
4097 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4098 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
972f4259
KS
4099
4100 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4101 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4102 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4103 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4104 {
4105 if (EQ (tem0, Qminus))
4106 {
5af5757b 4107 f->top_pos = 0;
972f4259
KS
4108 window_prompting |= YNegative;
4109 }
4110 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4111 && CONSP (XCDR (tem0))
4112 && INTEGERP (XCAR (XCDR (tem0))))
4113 {
5af5757b 4114 f->top_pos = - XINT (XCAR (XCDR (tem0)));
972f4259
KS
4115 window_prompting |= YNegative;
4116 }
4117 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4118 && CONSP (XCDR (tem0))
4119 && INTEGERP (XCAR (XCDR (tem0))))
4120 {
5af5757b 4121 f->top_pos = XINT (XCAR (XCDR (tem0)));
972f4259
KS
4122 }
4123 else if (EQ (tem0, Qunbound))
5af5757b 4124 f->top_pos = 0;
972f4259
KS
4125 else
4126 {
4127 CHECK_NUMBER (tem0);
5af5757b
KS
4128 f->top_pos = XINT (tem0);
4129 if (f->top_pos < 0)
972f4259
KS
4130 window_prompting |= YNegative;
4131 }
4132
4133 if (EQ (tem1, Qminus))
4134 {
5af5757b 4135 f->left_pos = 0;
972f4259
KS
4136 window_prompting |= XNegative;
4137 }
4138 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4139 && CONSP (XCDR (tem1))
4140 && INTEGERP (XCAR (XCDR (tem1))))
4141 {
5af5757b 4142 f->left_pos = - XINT (XCAR (XCDR (tem1)));
972f4259
KS
4143 window_prompting |= XNegative;
4144 }
4145 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4146 && CONSP (XCDR (tem1))
4147 && INTEGERP (XCAR (XCDR (tem1))))
4148 {
5af5757b 4149 f->left_pos = XINT (XCAR (XCDR (tem1)));
972f4259
KS
4150 }
4151 else if (EQ (tem1, Qunbound))
5af5757b 4152 f->left_pos = 0;
972f4259
KS
4153 else
4154 {
4155 CHECK_NUMBER (tem1);
5af5757b
KS
4156 f->left_pos = XINT (tem1);
4157 if (f->left_pos < 0)
972f4259
KS
4158 window_prompting |= XNegative;
4159 }
4160
4161 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4162 window_prompting |= USPosition;
4163 else
4164 window_prompting |= PPosition;
4165 }
4166
5af5757b 4167 if (f->want_fullscreen != FULLSCREEN_NONE)
972f4259
KS
4168 {
4169 int left, top;
4170 int width, height;
4171
4172 /* It takes both for some WM:s to place it where we want */
4173 window_prompting = USPosition | PPosition;
4174 x_fullscreen_adjust (f, &width, &height, &top, &left);
5af5757b
KS
4175 FRAME_COLS (f) = width;
4176 FRAME_LINES (f) = height;
4177 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
4178 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
4179 f->left_pos = left;
4180 f->top_pos = top;
972f4259
KS
4181 }
4182
4183 if (window_prompting & XNegative)
4184 {
4185 if (window_prompting & YNegative)
5af5757b 4186 f->win_gravity = SouthEastGravity;
972f4259 4187 else
5af5757b 4188 f->win_gravity = NorthEastGravity;
972f4259
KS
4189 }
4190 else
4191 {
4192 if (window_prompting & YNegative)
5af5757b 4193 f->win_gravity = SouthWestGravity;
972f4259 4194 else
5af5757b 4195 f->win_gravity = NorthWestGravity;
972f4259
KS
4196 }
4197
5af5757b 4198 f->size_hint_flags = window_prompting;
972f4259
KS
4199
4200 return window_prompting;
4201}
4202
4203
4204
4205#endif /* HAVE_WINDOW_SYSTEM */
4206
4207
4208\f
4209/***********************************************************************
4210 Initialization
4211 ***********************************************************************/
4212
4213void
4214syms_of_frame ()
4215{
4216 Qframep = intern ("framep");
4217 staticpro (&Qframep);
4218 Qframe_live_p = intern ("frame-live-p");
4219 staticpro (&Qframe_live_p);
4220 Qheight = intern ("height");
4221 staticpro (&Qheight);
4222 Qicon = intern ("icon");
4223 staticpro (&Qicon);
4224 Qminibuffer = intern ("minibuffer");
4225 staticpro (&Qminibuffer);
4226 Qmodeline = intern ("modeline");
4227 staticpro (&Qmodeline);
4228 Qonly = intern ("only");
4229 staticpro (&Qonly);
4230 Qwidth = intern ("width");
4231 staticpro (&Qwidth);
4232 Qgeometry = intern ("geometry");
4233 staticpro (&Qgeometry);
4234 Qicon_left = intern ("icon-left");
4235 staticpro (&Qicon_left);
4236 Qicon_top = intern ("icon-top");
4237 staticpro (&Qicon_top);
4238 Qleft = intern ("left");
4239 staticpro (&Qleft);
4240 Qright = intern ("right");
4241 staticpro (&Qright);
4242 Quser_position = intern ("user-position");
4243 staticpro (&Quser_position);
4244 Quser_size = intern ("user-size");
4245 staticpro (&Quser_size);
4246 Qwindow_id = intern ("window-id");
4247 staticpro (&Qwindow_id);
4248#ifdef HAVE_X_WINDOWS
4249 Qouter_window_id = intern ("outer-window-id");
4250 staticpro (&Qouter_window_id);
4251#endif
4252 Qparent_id = intern ("parent-id");
4253 staticpro (&Qparent_id);
4254 Qx = intern ("x");
4255 staticpro (&Qx);
4256 Qw32 = intern ("w32");
4257 staticpro (&Qw32);
4258 Qpc = intern ("pc");
4259 staticpro (&Qpc);
4260 Qmac = intern ("mac");
4261 staticpro (&Qmac);
4262 Qvisible = intern ("visible");
4263 staticpro (&Qvisible);
4264 Qbuffer_predicate = intern ("buffer-predicate");
4265 staticpro (&Qbuffer_predicate);
4266 Qbuffer_list = intern ("buffer-list");
4267 staticpro (&Qbuffer_list);
a18b8cb5
KL
4268 Qburied_buffer_list = intern ("buried-buffer-list");
4269 staticpro (&Qburied_buffer_list);
972f4259
KS
4270 Qdisplay_type = intern ("display-type");
4271 staticpro (&Qdisplay_type);
4272 Qbackground_mode = intern ("background-mode");
4273 staticpro (&Qbackground_mode);
4274 Qtty_color_mode = intern ("tty-color-mode");
4275 staticpro (&Qtty_color_mode);
28d440ab
KL
4276 Qtty = intern ("tty");
4277 staticpro (&Qtty);
4278 Qtty_type = intern ("tty-type");
4279 staticpro (&Qtty_type);
7f19e125
KL
4280 Qwindow_system = intern ("window-system");
4281 staticpro (&Qwindow_system);
da8e8fc1
KL
4282 Qenvironment = intern ("environment");
4283 staticpro (&Qenvironment);
7f19e125 4284
972f4259
KS
4285 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4286 staticpro (&Qface_set_after_frame_default);
4287
4288 Qfullwidth = intern ("fullwidth");
4289 staticpro (&Qfullwidth);
4290 Qfullheight = intern ("fullheight");
4291 staticpro (&Qfullheight);
4292 Qfullboth = intern ("fullboth");
4293 staticpro (&Qfullboth);
4294 Qx_resource_name = intern ("x-resource-name");
4295 staticpro (&Qx_resource_name);
4296
4297 Qx_frame_parameter = intern ("x-frame-parameter");
4298 staticpro (&Qx_frame_parameter);
4299
6ed8eeff
KL
4300 Qterminal = intern ("terminal");
4301 staticpro (&Qterminal);
4302 Qterminal_live_p = intern ("terminal-live-p");
4303 staticpro (&Qterminal_live_p);
b6660415 4304
972f4259
KS
4305 {
4306 int i;
4307
4308 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4309 {
4310 Lisp_Object v = intern (frame_parms[i].name);
4311 if (frame_parms[i].variable)
4312 {
4313 *frame_parms[i].variable = v;
4314 staticpro (frame_parms[i].variable);
4315 }
4316 Fput (v, Qx_frame_parameter, make_number (i));
4317 }
4318 }
4319
2731a0ad 4320#ifdef HAVE_WINDOW_SYSTEM
972f4259
KS
4321 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4322 doc: /* The name Emacs uses to look up X resources.
4323`x-get-resource' uses this as the first component of the instance name
4324when requesting resource values.
4325Emacs initially sets `x-resource-name' to the name under which Emacs
4326was invoked, or to the value specified with the `-name' or `-rn'
4327switches, if present.
4328
4329It may be useful to bind this variable locally around a call
4330to `x-get-resource'. See also the variable `x-resource-class'. */);
4331 Vx_resource_name = Qnil;
4332
4333 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4334 doc: /* The class Emacs uses to look up X resources.
4335`x-get-resource' uses this as the first component of the instance class
4336when requesting resource values.
4337
4338Emacs initially sets `x-resource-class' to "Emacs".
4339
4340Setting this variable permanently is not a reasonable thing to do,
4341but binding this variable locally around a call to `x-get-resource'
4342is a reasonable practice. See also the variable `x-resource-name'. */);
4343 Vx_resource_class = build_string (EMACS_CLASS);
2731a0ad 4344#endif
972f4259
KS
4345
4346 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4347 doc: /* Alist of default values for frame creation.
4348These may be set in your init file, like this:
5ff00c42 4349 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
972f4259
KS
4350These override values given in window system configuration data,
4351 including X Windows' defaults database.
4352For values specific to the first Emacs frame, see `initial-frame-alist'.
4353For values specific to the separate minibuffer frame, see
4354 `minibuffer-frame-alist'.
4355The `menu-bar-lines' element of the list controls whether new frames
4356 have menu bars; `menu-bar-mode' works by altering this element.
4357Setting this variable does not affect existing frames, only new ones. */);
4358 Vdefault_frame_alist = Qnil;
4359
a6e20602
KS
4360 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4361 doc: /* Default position of scroll bars on this window-system. */);
4362#ifdef HAVE_WINDOW_SYSTEM
b15325b2 4363#if defined(HAVE_NTGUI) || defined(MAC_OS)
a6e20602
KS
4364 /* MS-Windows has scroll bars on the right by default. */
4365 Vdefault_frame_scroll_bars = Qright;
4366#else
4367 Vdefault_frame_scroll_bars = Qleft;
4368#endif
4369#else
4370 Vdefault_frame_scroll_bars = Qnil;
4371#endif
4372
972f4259
KS
4373 Qinhibit_default_face_x_resources
4374 = intern ("inhibit-default-face-x-resources");
4375 staticpro (&Qinhibit_default_face_x_resources);
4376
daf01701
KL
4377 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4378 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4379
972f4259
KS
4380 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4381 doc: /* Non-nil if all of emacs is iconified and frame updates are not needed. */);
4382 Vemacs_iconified = Qnil;
4383
4384 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4385 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4386`mouse-position' calls this function, passing its usual return value as
4387argument, and returns whatever this function returns.
4388This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4389which need to do mouse handling at the Lisp level. */);
4390 Vmouse_position_function = Qnil;
4391
4392 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4393 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4394If the value is an integer, highlighting is only shown after moving the
4395mouse, while keyboard input turns off the highlight even when the mouse
4396is over the clickable text. However, the mouse shape still indicates
4397when the mouse is over clickable text. */);
4398 Vmouse_highlight = Qt;
4399
4400 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4401 doc: /* Functions to be run before deleting a frame.
4402The functions are run with one arg, the frame to be deleted.
e519a50b
KL
4403See `delete-frame'.
4404
4405Note that functions in this list may be called twice on the same
4406frame. In the second invocation, the frame is already deleted, and
4407the function should do nothing. (You can use `frame-live-p' to check
4408for this.) This wrinkle happens when an earlier function in
4409`delete-frame-functions' (indirectly) calls delete-frame
4410recursively. */);
972f4259
KS
4411 Vdelete_frame_functions = Qnil;
4412
4413 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4414 doc: /* Minibufferless frames use this frame's minibuffer.
4415
4416Emacs cannot create minibufferless frames unless this is set to an
4417appropriate surrogate.
4418
4419Emacs consults this variable only when creating minibufferless
4420frames; once the frame is created, it sticks with its assigned
4421minibuffer, no matter what this variable is set to. This means that
4422this variable doesn't necessarily say anything meaningful about the
4423current set of frames, or where the minibuffer is currently being
4424displayed.
4425
4426This variable is local to the current terminal and cannot be buffer-local. */);
4427
4428 staticpro (&Vframe_list);
4429
4430 defsubr (&Sactive_minibuffer_window);
4431 defsubr (&Sframep);
4432 defsubr (&Sframe_live_p);
428a555e 4433 defsubr (&Swindow_system);
972f4259
KS
4434 defsubr (&Smake_terminal_frame);
4435 defsubr (&Shandle_switch_frame);
972f4259
KS
4436 defsubr (&Sselect_frame);
4437 defsubr (&Sselected_frame);
4438 defsubr (&Swindow_frame);
4439 defsubr (&Sframe_root_window);
4440 defsubr (&Sframe_first_window);
4441 defsubr (&Sframe_selected_window);
4442 defsubr (&Sset_frame_selected_window);
4443 defsubr (&Sframe_list);
4444 defsubr (&Snext_frame);
4445 defsubr (&Sprevious_frame);
4446 defsubr (&Sdelete_frame);
4447 defsubr (&Smouse_position);
4448 defsubr (&Smouse_pixel_position);
4449 defsubr (&Sset_mouse_position);
4450 defsubr (&Sset_mouse_pixel_position);
4451#if 0
4452 defsubr (&Sframe_configuration);
4453 defsubr (&Srestore_frame_configuration);
4454#endif
4455 defsubr (&Smake_frame_visible);
4456 defsubr (&Smake_frame_invisible);
4457 defsubr (&Siconify_frame);
4458 defsubr (&Sframe_visible_p);
4459 defsubr (&Svisible_frame_list);
4460 defsubr (&Sraise_frame);
4461 defsubr (&Slower_frame);
4462 defsubr (&Sredirect_frame_focus);
4463 defsubr (&Sframe_focus);
4464 defsubr (&Sframe_parameters);
4465 defsubr (&Sframe_parameter);
4466 defsubr (&Smodify_frame_parameters);
da8e8fc1 4467 defsubr (&Sframe_with_environment);
972f4259
KS
4468 defsubr (&Sframe_char_height);
4469 defsubr (&Sframe_char_width);
4470 defsubr (&Sframe_pixel_height);
4471 defsubr (&Sframe_pixel_width);
4472 defsubr (&Sset_frame_height);
4473 defsubr (&Sset_frame_width);
4474 defsubr (&Sset_frame_size);
4475 defsubr (&Sset_frame_position);
4476
4477#ifdef HAVE_WINDOW_SYSTEM
4478 defsubr (&Sx_get_resource);
4479 defsubr (&Sx_parse_geometry);
4480#endif
4481
dc6f92b8 4482}
ab5796a9
MB
4483
4484/* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4485 (do not change this comment) */