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