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