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