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