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