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