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