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