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