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