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