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