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