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