Trivial changes
[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
8303ba32
KL
1384 if (FRAME_TERMCAP_P (f))
1385 {
1386 /* See if the terminal needs to be closed. */
1387 Lisp_Object tail, frame1;
1388 int delete = 1;
1389
1390 FOR_EACH_FRAME (tail, frame1)
1391 {
1392 if (!FRAME_LIVE_P (XFRAME (frame1)) &&
1393 FRAME_TERMCAP_P (XFRAME (frame1)) &&
1394 FRAME_TTY (XFRAME (frame1)) == FRAME_TTY (f))
1395 {
1396 delete = 0;
1397 break;
1398 }
1399 }
1400 if (delete)
1401 delete_tty (FRAME_TTY (f));
1402 }
1403
7556890b 1404 f->output_data.nothing = 0;
8678b9cc 1405
ff11dfa1 1406 /* If we've deleted the last_nonminibuf_frame, then try to find
d5e7c279 1407 another one. */
ff11dfa1 1408 if (f == last_nonminibuf_frame)
d5e7c279 1409 {
ff11dfa1 1410 Lisp_Object frames;
1113d9db 1411
ff11dfa1 1412 last_nonminibuf_frame = 0;
d5e7c279 1413
ff11dfa1
JB
1414 for (frames = Vframe_list;
1415 CONSP (frames);
7539e11f 1416 frames = XCDR (frames))
d5e7c279 1417 {
7539e11f 1418 f = XFRAME (XCAR (frames));
ff11dfa1 1419 if (!FRAME_MINIBUF_ONLY_P (f))
d5e7c279 1420 {
ff11dfa1 1421 last_nonminibuf_frame = f;
d5e7c279
JB
1422 break;
1423 }
1424 }
1425 }
dc6f92b8 1426
c4c6d073
KH
1427 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1428 find another one. Prefer minibuffer-only frames, but also notice
1429 frames with other windows. */
c60f3a6a 1430 if (EQ (frame, FRAME_KBOARD (f)->Vdefault_minibuffer_frame))
1113d9db 1431 {
ff11dfa1 1432 Lisp_Object frames;
1113d9db 1433
ff11dfa1 1434 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
ab9f008d 1435 Lisp_Object frame_with_minibuf;
32fda9ba
RS
1436 /* Some frame we found on the same kboard, or nil if there are none. */
1437 Lisp_Object frame_on_same_kboard;
1113d9db 1438
32fda9ba 1439 frame_on_same_kboard = Qnil;
ab9f008d 1440 frame_with_minibuf = Qnil;
32fda9ba 1441
ff11dfa1
JB
1442 for (frames = Vframe_list;
1443 CONSP (frames);
7539e11f 1444 frames = XCDR (frames))
1113d9db 1445 {
ab9f008d 1446 Lisp_Object this;
c4c6d073 1447 struct frame *f1;
1113d9db 1448
7539e11f 1449 this = XCAR (frames);
e35d291d 1450 if (!FRAMEP (this))
1113d9db 1451 abort ();
c4c6d073 1452 f1 = XFRAME (this);
1113d9db 1453
c4c6d073
KH
1454 /* Consider only frames on the same kboard
1455 and only those with minibuffers. */
1456 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)
1457 && FRAME_HAS_MINIBUF_P (f1))
1113d9db 1458 {
ff11dfa1 1459 frame_with_minibuf = this;
c4c6d073 1460 if (FRAME_MINIBUF_ONLY_P (f1))
1113d9db
JB
1461 break;
1462 }
32fda9ba
RS
1463
1464 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1))
1465 frame_on_same_kboard = this;
1113d9db
JB
1466 }
1467
32fda9ba
RS
1468 if (!NILP (frame_on_same_kboard))
1469 {
1470 /* We know that there must be some frame with a minibuffer out
1471 there. If this were not true, all of the frames present
1472 would have to be minibufferless, which implies that at some
1473 point their minibuffer frames must have been deleted, but
1474 that is prohibited at the top; you can't delete surrogate
1475 minibuffer frames. */
1476 if (NILP (frame_with_minibuf))
1477 abort ();
1113d9db 1478
32fda9ba
RS
1479 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = frame_with_minibuf;
1480 }
1481 else
1482 /* No frames left on this kboard--say no minibuffer either. */
1483 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = Qnil;
1113d9db
JB
1484 }
1485
e681c92a
RS
1486 /* Cause frame titles to update--necessary if we now have just one frame. */
1487 update_mode_lines = 1;
1488
dc6f92b8
JB
1489 return Qnil;
1490}
1491\f
1492/* Return mouse position in character cell units. */
1493
f9898cc6 1494DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
14ff1ee0
PJ
1495 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1496The position is given in character cells, where (0, 0) is the
1497upper-left corner.
1498If Emacs is running on a mouseless terminal or hasn't been programmed
1499to read the mouse position, it returns the selected frame for FRAME
1500and nil for X and Y.
1501If `mouse-position-function' is non-nil, `mouse-position' calls it,
1502passing the normal return value to that function as an argument,
1503and returns whatever that function returns. */)
1504 ()
dc6f92b8 1505{
ff11dfa1 1506 FRAME_PTR f;
dbc4e1c1 1507 Lisp_Object lispy_dummy;
fd2777e0 1508 enum scroll_bar_part party_dummy;
beb0bc36 1509 Lisp_Object x, y, retval;
5384466a 1510 int col, row;
dbc4e1c1 1511 unsigned long long_dummy;
cb2255b3 1512 struct gcpro gcpro1;
dc6f92b8 1513
8d2666fe 1514 f = SELECTED_FRAME ();
c5074d8c
RS
1515 x = y = Qnil;
1516
f443c170 1517#ifdef HAVE_MOUSE
c5074d8c 1518 /* It's okay for the hook to refrain from storing anything. */
f9898cc6 1519 if (mouse_position_hook)
66e827dc 1520 (*mouse_position_hook) (&f, -1,
dbc4e1c1
JB
1521 &lispy_dummy, &party_dummy,
1522 &x, &y,
1523 &long_dummy);
76db7eb4
KH
1524 if (! NILP (x))
1525 {
1526 col = XINT (x);
1527 row = XINT (y);
8126c3b4 1528 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
76db7eb4
KH
1529 XSETINT (x, col);
1530 XSETINT (y, row);
1531 }
f443c170 1532#endif
2d80a27a 1533 XSETFRAME (lispy_dummy, f);
beb0bc36 1534 retval = Fcons (lispy_dummy, Fcons (x, y));
cb2255b3 1535 GCPRO1 (retval);
beb0bc36 1536 if (!NILP (Vmouse_position_function))
cb2255b3
GM
1537 retval = call1 (Vmouse_position_function, retval);
1538 RETURN_UNGCPRO (retval);
dc6f92b8
JB
1539}
1540
152e6c70
RS
1541DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1542 Smouse_pixel_position, 0, 0, 0,
14ff1ee0
PJ
1543 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1544The position is given in pixel units, where (0, 0) is the
1545upper-left corner.
1546If Emacs is running on a mouseless terminal or hasn't been programmed
1547to read the mouse position, it returns the selected frame for FRAME
1548and nil for X and Y. */)
1549 ()
152e6c70
RS
1550{
1551 FRAME_PTR f;
1552 Lisp_Object lispy_dummy;
1553 enum scroll_bar_part party_dummy;
1554 Lisp_Object x, y;
152e6c70
RS
1555 unsigned long long_dummy;
1556
8d2666fe 1557 f = SELECTED_FRAME ();
152e6c70
RS
1558 x = y = Qnil;
1559
0c5c1cf7 1560#ifdef HAVE_MOUSE
152e6c70
RS
1561 /* It's okay for the hook to refrain from storing anything. */
1562 if (mouse_position_hook)
66e827dc 1563 (*mouse_position_hook) (&f, -1,
152e6c70
RS
1564 &lispy_dummy, &party_dummy,
1565 &x, &y,
1566 &long_dummy);
0c5c1cf7 1567#endif
2d80a27a 1568 XSETFRAME (lispy_dummy, f);
152e6c70
RS
1569 return Fcons (lispy_dummy, Fcons (x, y));
1570}
1571
dc6f92b8 1572DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
14ff1ee0
PJ
1573 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1574Coordinates are relative to the frame, not a window,
1575so the coordinates of the top left character in the frame
1576may be nonzero due to left-hand scroll bars or the menu bar.
1577
1578This function is a no-op for an X frame that is not visible.
1579If you have just created a frame, you must wait for it to become visible
1580before calling this function on it, like this.
1581 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
ff11dfa1
JB
1582 (frame, x, y)
1583 Lisp_Object frame, x, y;
dc6f92b8 1584{
b7826503
PJ
1585 CHECK_LIVE_FRAME (frame);
1586 CHECK_NUMBER (x);
1587 CHECK_NUMBER (y);
dc6f92b8 1588
dbc4e1c1 1589 /* I think this should be done with a hook. */
032d78fe
GV
1590#ifdef HAVE_WINDOW_SYSTEM
1591 if (FRAME_WINDOW_P (XFRAME (frame)))
d19be8a9 1592 /* Warping the mouse will cause enternotify and focus events. */
d4d76014 1593 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
bb221971 1594#else
be625e00 1595#if defined (MSDOS) && defined (HAVE_MOUSE)
bb221971
RS
1596 if (FRAME_MSDOS_P (XFRAME (frame)))
1597 {
1598 Fselect_frame (frame, Qnil);
1599 mouse_moveto (XINT (x), XINT (y));
1600 }
1601#endif
dc6f92b8
JB
1602#endif
1603
1604 return Qnil;
1605}
152e6c70
RS
1606
1607DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1608 Sset_mouse_pixel_position, 3, 3, 0,
14ff1ee0
PJ
1609 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1610Note, this is a no-op for an X frame that is not visible.
1611If you have just created a frame, you must wait for it to become visible
1612before calling this function on it, like this.
1613 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
152e6c70
RS
1614 (frame, x, y)
1615 Lisp_Object frame, x, y;
1616{
b7826503
PJ
1617 CHECK_LIVE_FRAME (frame);
1618 CHECK_NUMBER (x);
1619 CHECK_NUMBER (y);
152e6c70
RS
1620
1621 /* I think this should be done with a hook. */
032d78fe
GV
1622#ifdef HAVE_WINDOW_SYSTEM
1623 if (FRAME_WINDOW_P (XFRAME (frame)))
d19be8a9 1624 /* Warping the mouse will cause enternotify and focus events. */
d4d76014 1625 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
bb221971 1626#else
be625e00 1627#if defined (MSDOS) && defined (HAVE_MOUSE)
bb221971
RS
1628 if (FRAME_MSDOS_P (XFRAME (frame)))
1629 {
1630 Fselect_frame (frame, Qnil);
1631 mouse_moveto (XINT (x), XINT (y));
1632 }
1633#endif
152e6c70
RS
1634#endif
1635
1636 return Qnil;
1637}
dc6f92b8 1638\f
98ce1622
RS
1639static void make_frame_visible_1 P_ ((Lisp_Object));
1640
ff11dfa1 1641DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
fc25d15d 1642 0, 1, "",
14ff1ee0
PJ
1643 doc: /* Make the frame FRAME visible (assuming it is an X window).
1644If omitted, FRAME defaults to the currently selected frame. */)
1645 (frame)
ff11dfa1 1646 Lisp_Object frame;
dc6f92b8 1647{
1aa66088 1648 if (NILP (frame))
8d2666fe 1649 frame = selected_frame;
1aa66088 1650
b7826503 1651 CHECK_LIVE_FRAME (frame);
dc6f92b8 1652
dbc4e1c1 1653 /* I think this should be done with a hook. */
032d78fe
GV
1654#ifdef HAVE_WINDOW_SYSTEM
1655 if (FRAME_WINDOW_P (XFRAME (frame)))
02ff9dd5
RS
1656 {
1657 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1658 x_make_frame_visible (XFRAME (frame));
1659 }
fd0c2bd1 1660#endif
dc6f92b8 1661
98ce1622
RS
1662 make_frame_visible_1 (XFRAME (frame)->root_window);
1663
d19be8a9 1664 /* Make menu bar update for the Buffers and Frames menus. */
565620a5
RS
1665 windows_or_buffers_changed++;
1666
ff11dfa1 1667 return frame;
dc6f92b8
JB
1668}
1669
98ce1622
RS
1670/* Update the display_time slot of the buffers shown in WINDOW
1671 and all its descendents. */
1672
1673static void
1674make_frame_visible_1 (window)
1675 Lisp_Object window;
1676{
1677 struct window *w;
1678
1679 for (;!NILP (window); window = w->next)
1680 {
1681 w = XWINDOW (window);
1682
1683 if (!NILP (w->buffer))
1684 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1685
1686 if (!NILP (w->vchild))
1687 make_frame_visible_1 (w->vchild);
1688 if (!NILP (w->hchild))
1689 make_frame_visible_1 (w->hchild);
1690 }
1691}
1692
ff11dfa1 1693DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
808c0f20 1694 0, 2, "",
14ff1ee0
PJ
1695 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1696If omitted, FRAME defaults to the currently selected frame.
1697Normally you may not make FRAME invisible if all other frames are invisible,
1698but if the second optional argument FORCE is non-nil, you may do so. */)
808c0f20
RS
1699 (frame, force)
1700 Lisp_Object frame, force;
dc6f92b8 1701{
1aa66088 1702 if (NILP (frame))
8d2666fe 1703 frame = selected_frame;
1aa66088 1704
b7826503 1705 CHECK_LIVE_FRAME (frame);
dc6f92b8 1706
808c0f20
RS
1707 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1708 error ("Attempt to make invisible the sole visible or iconified frame");
1709
3d378fdf 1710#if 0 /* This isn't logically necessary, and it can do GC. */
9c394f17 1711 /* Don't let the frame remain selected. */
8d2666fe 1712 if (EQ (frame, selected_frame))
1e8324d9 1713 do_switch_frame (next_frame (frame, Qt), 0, 0)
3d378fdf 1714#endif
9c394f17
RS
1715
1716 /* Don't allow minibuf_window to remain on a deleted frame. */
1717 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1718 {
8d2666fe
GM
1719 struct frame *sf = XFRAME (selected_frame);
1720 Fset_window_buffer (sf->minibuffer_window,
5af5757b 1721 XWINDOW (minibuf_window)->buffer, Qnil);
8d2666fe 1722 minibuf_window = sf->minibuffer_window;
9c394f17
RS
1723 }
1724
dbc4e1c1 1725 /* I think this should be done with a hook. */
032d78fe
GV
1726#ifdef HAVE_WINDOW_SYSTEM
1727 if (FRAME_WINDOW_P (XFRAME (frame)))
ff11dfa1 1728 x_make_frame_invisible (XFRAME (frame));
fd0c2bd1 1729#endif
dc6f92b8 1730
d19be8a9 1731 /* Make menu bar update for the Buffers and Frames menus. */
565620a5
RS
1732 windows_or_buffers_changed++;
1733
dc6f92b8
JB
1734 return Qnil;
1735}
1736
ff11dfa1 1737DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1aa66088 1738 0, 1, "",
14ff1ee0
PJ
1739 doc: /* Make the frame FRAME into an icon.
1740If omitted, FRAME defaults to the currently selected frame. */)
ff11dfa1
JB
1741 (frame)
1742 Lisp_Object frame;
dc6f92b8 1743{
1aa66088 1744 if (NILP (frame))
8d2666fe 1745 frame = selected_frame;
177c0ea7 1746
b7826503 1747 CHECK_LIVE_FRAME (frame);
dc6f92b8 1748
3d378fdf 1749#if 0 /* This isn't logically necessary, and it can do GC. */
9c394f17 1750 /* Don't let the frame remain selected. */
8d2666fe 1751 if (EQ (frame, selected_frame))
9c394f17 1752 Fhandle_switch_frame (next_frame (frame, Qt), Qnil);
3d378fdf 1753#endif
9c394f17
RS
1754
1755 /* Don't allow minibuf_window to remain on a deleted frame. */
1756 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1757 {
8d2666fe
GM
1758 struct frame *sf = XFRAME (selected_frame);
1759 Fset_window_buffer (sf->minibuffer_window,
5af5757b 1760 XWINDOW (minibuf_window)->buffer, Qnil);
8d2666fe 1761 minibuf_window = sf->minibuffer_window;
9c394f17
RS
1762 }
1763
dbc4e1c1 1764 /* I think this should be done with a hook. */
032d78fe
GV
1765#ifdef HAVE_WINDOW_SYSTEM
1766 if (FRAME_WINDOW_P (XFRAME (frame)))
ff11dfa1 1767 x_iconify_frame (XFRAME (frame));
fd0c2bd1 1768#endif
dc6f92b8 1769
d19be8a9 1770 /* Make menu bar update for the Buffers and Frames menus. */
565620a5
RS
1771 windows_or_buffers_changed++;
1772
dc6f92b8
JB
1773 return Qnil;
1774}
1775
ff11dfa1 1776DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
dc6f92b8 1777 1, 1, 0,
14ff1ee0
PJ
1778 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1779A frame that is not \"visible\" is not updated and, if it works through
1780a window system, it may not show at all.
1781Return the symbol `icon' if frame is visible only as an icon. */)
1782 (frame)
ff11dfa1 1783 Lisp_Object frame;
dc6f92b8 1784{
b7826503 1785 CHECK_LIVE_FRAME (frame);
dc6f92b8 1786
5c044f55
RS
1787 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1788
a42e9724 1789 if (FRAME_VISIBLE_P (XFRAME (frame)))
dc6f92b8 1790 return Qt;
a42e9724 1791 if (FRAME_ICONIFIED_P (XFRAME (frame)))
fd0c2bd1 1792 return Qicon;
dc6f92b8
JB
1793 return Qnil;
1794}
1795
ff11dfa1 1796DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
dc6f92b8 1797 0, 0, 0,
14ff1ee0 1798 doc: /* Return a list of all frames now \"visible\" (being updated). */)
dc6f92b8
JB
1799 ()
1800{
ff11dfa1
JB
1801 Lisp_Object tail, frame;
1802 struct frame *f;
dc6f92b8
JB
1803 Lisp_Object value;
1804
1805 value = Qnil;
7539e11f 1806 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
dc6f92b8 1807 {
7539e11f 1808 frame = XCAR (tail);
e35d291d 1809 if (!FRAMEP (frame))
dc6f92b8 1810 continue;
ff11dfa1 1811 f = XFRAME (frame);
a42e9724 1812 if (FRAME_VISIBLE_P (f))
ff11dfa1 1813 value = Fcons (frame, value);
dc6f92b8
JB
1814 }
1815 return value;
1816}
d5e7c279
JB
1817
1818
e518d5e1 1819DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
14ff1ee0
PJ
1820 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1821If FRAME is invisible, make it visible.
1822If you don't specify a frame, the selected frame is used.
1823If Emacs is displaying on an ordinary terminal or some other device which
1824doesn't support multiple overlapping frames, this function does nothing. */)
1825 (frame)
dbc4e1c1
JB
1826 Lisp_Object frame;
1827{
828ac693 1828 if (NILP (frame))
8d2666fe 1829 frame = selected_frame;
828ac693 1830
b7826503 1831 CHECK_LIVE_FRAME (frame);
8a981af5
RS
1832
1833 /* Do like the documentation says. */
1834 Fmake_frame_visible (frame);
1835
dbc4e1c1
JB
1836 if (frame_raise_lower_hook)
1837 (*frame_raise_lower_hook) (XFRAME (frame), 1);
1838
1839 return Qnil;
1840}
1841
b49f5578 1842/* Should we have a corresponding function called Flower_Power? */
e518d5e1 1843DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
14ff1ee0
PJ
1844 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1845If you don't specify a frame, the selected frame is used.
1846If Emacs is displaying on an ordinary terminal or some other device which
1847doesn't support multiple overlapping frames, this function does nothing. */)
1848 (frame)
dbc4e1c1
JB
1849 Lisp_Object frame;
1850{
828ac693 1851 if (NILP (frame))
8d2666fe 1852 frame = selected_frame;
828ac693 1853
b7826503 1854 CHECK_LIVE_FRAME (frame);
177c0ea7 1855
dbc4e1c1
JB
1856 if (frame_raise_lower_hook)
1857 (*frame_raise_lower_hook) (XFRAME (frame), 0);
1858
1859 return Qnil;
1860}
1861
d5e7c279 1862\f
ff11dfa1 1863DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
d5e7c279 1864 1, 2, 0,
14ff1ee0
PJ
1865 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1866In other words, switch-frame events caused by events in FRAME will
1867request a switch to FOCUS-FRAME, and `last-event-frame' will be
1868FOCUS-FRAME after reading an event typed at FRAME.
1869
1870If FOCUS-FRAME is omitted or nil, any existing redirection is
1871cancelled, and the frame again receives its own keystrokes.
1872
1873Focus redirection is useful for temporarily redirecting keystrokes to
1874a surrogate minibuffer frame when a frame doesn't have its own
1875minibuffer window.
1876
1877A frame's focus redirection can be changed by select-frame. If frame
1878FOO is selected, and then a different frame BAR is selected, any
1879frames redirecting their focus to FOO are shifted to redirect their
1880focus to BAR. This allows focus redirection to work properly when the
1881user switches from one frame to another using `select-window'.
1882
1883This means that a frame whose focus is redirected to itself is treated
1884differently from a frame whose focus is redirected to nil; the former
1885is affected by select-frame, while the latter is not.
1886
1887The redirection lasts until `redirect-frame-focus' is called to change it. */)
1888 (frame, focus_frame)
1889 Lisp_Object frame, focus_frame;
d5e7c279 1890{
13144095
JB
1891 /* Note that we don't check for a live frame here. It's reasonable
1892 to redirect the focus of a frame you're about to delete, if you
1893 know what other frame should receive those keystrokes. */
b7826503 1894 CHECK_FRAME (frame);
f9898cc6 1895
a42e9724 1896 if (! NILP (focus_frame))
b7826503 1897 CHECK_LIVE_FRAME (focus_frame);
d5e7c279 1898
ff11dfa1 1899 XFRAME (frame)->focus_frame = focus_frame;
d5e7c279 1900
ff11dfa1 1901 if (frame_rehighlight_hook)
dc0700f6 1902 (*frame_rehighlight_hook) (XFRAME (frame));
177c0ea7 1903
d5e7c279
JB
1904 return Qnil;
1905}
1906
1907
ff11dfa1 1908DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
14ff1ee0
PJ
1909 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1910This returns nil if FRAME's focus is not redirected.
1911See `redirect-frame-focus'. */)
1912 (frame)
1913 Lisp_Object frame;
d5e7c279 1914{
b7826503 1915 CHECK_LIVE_FRAME (frame);
a42e9724 1916
ff11dfa1 1917 return FRAME_FOCUS_FRAME (XFRAME (frame));
d5e7c279
JB
1918}
1919
1920
dc6f92b8 1921\f
329ca574
RS
1922/* Return the value of frame parameter PROP in frame FRAME. */
1923
dc6f92b8 1924Lisp_Object
ff11dfa1
JB
1925get_frame_param (frame, prop)
1926 register struct frame *frame;
dc6f92b8
JB
1927 Lisp_Object prop;
1928{
1929 register Lisp_Object tem;
1930
ff11dfa1 1931 tem = Fassq (prop, frame->param_alist);
dc6f92b8
JB
1932 if (EQ (tem, Qnil))
1933 return tem;
1934 return Fcdr (tem);
1935}
1936
329ca574
RS
1937/* Return the buffer-predicate of the selected frame. */
1938
1939Lisp_Object
98ce1622
RS
1940frame_buffer_predicate (frame)
1941 Lisp_Object frame;
329ca574 1942{
98ce1622 1943 return XFRAME (frame)->buffer_predicate;
329ca574
RS
1944}
1945
fa54c6ae
RS
1946/* Return the buffer-list of the selected frame. */
1947
1948Lisp_Object
98ce1622
RS
1949frame_buffer_list (frame)
1950 Lisp_Object frame;
fa54c6ae 1951{
98ce1622 1952 return XFRAME (frame)->buffer_list;
fa54c6ae
RS
1953}
1954
1955/* Set the buffer-list of the selected frame. */
1956
1957void
98ce1622
RS
1958set_frame_buffer_list (frame, list)
1959 Lisp_Object frame, list;
fa54c6ae 1960{
98ce1622 1961 XFRAME (frame)->buffer_list = list;
fa54c6ae
RS
1962}
1963
1964/* Discard BUFFER from the buffer-list of each frame. */
1965
1966void
1967frames_discard_buffer (buffer)
1968 Lisp_Object buffer;
1969{
1970 Lisp_Object frame, tail;
1971
1972 FOR_EACH_FRAME (tail, frame)
1973 {
1974 XFRAME (frame)->buffer_list
1975 = Fdelq (buffer, XFRAME (frame)->buffer_list);
1976 }
1977}
1978
329ca574
RS
1979/* Modify the alist in *ALISTPTR to associate PROP with VAL.
1980 If the alist already has an element for PROP, we change it. */
1981
dc6f92b8 1982void
fd0c2bd1 1983store_in_alist (alistptr, prop, val)
dc6f92b8 1984 Lisp_Object *alistptr, val;
fd0c2bd1 1985 Lisp_Object prop;
dc6f92b8
JB
1986{
1987 register Lisp_Object tem;
dc6f92b8 1988
dc6f92b8
JB
1989 tem = Fassq (prop, *alistptr);
1990 if (EQ (tem, Qnil))
1991 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1992 else
1993 Fsetcdr (tem, val);
1994}
1995
e5317d61
EZ
1996static int
1997frame_name_fnn_p (str, len)
1998 char *str;
1999 int len;
2000{
2001 if (len > 1 && str[0] == 'F')
2002 {
2003 char *end_ptr;
e5317d61 2004
48970f2f
EZ
2005 strtol (str + 1, &end_ptr, 10);
2006
e5317d61
EZ
2007 if (end_ptr == str + len)
2008 return 1;
2009 }
2010 return 0;
2011}
2012
2013/* Set the name of the terminal frame. Also used by MSDOS frames.
2014 Modeled after x_set_name which is used for WINDOW frames. */
2015
2016void
2017set_term_frame_name (f, name)
2018 struct frame *f;
2019 Lisp_Object name;
2020{
2021 f->explicit_name = ! NILP (name);
2022
2023 /* If NAME is nil, set the name to F<num>. */
2024 if (NILP (name))
2025 {
2026 char namebuf[20];
2027
2028 /* Check for no change needed in this very common case
2029 before we do any consing. */
d5db4077
KR
2030 if (frame_name_fnn_p (SDATA (f->name),
2031 SBYTES (f->name)))
e5317d61
EZ
2032 return;
2033
2034 terminal_frame_count++;
2035 sprintf (namebuf, "F%d", terminal_frame_count);
2036 name = build_string (namebuf);
2037 }
2038 else
2039 {
b7826503 2040 CHECK_STRING (name);
e5317d61
EZ
2041
2042 /* Don't change the name if it's already NAME. */
2043 if (! NILP (Fstring_equal (name, f->name)))
2044 return;
2045
2046 /* Don't allow the user to set the frame name to F<num>, so it
2047 doesn't clash with the names we generate for terminal frames. */
d5db4077 2048 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
e5317d61
EZ
2049 error ("Frame names of the form F<num> are usurped by Emacs");
2050 }
2051
2052 f->name = name;
2053 update_mode_lines = 1;
2054}
2055
dc6f92b8 2056void
ff11dfa1
JB
2057store_frame_param (f, prop, val)
2058 struct frame *f;
dc6f92b8
JB
2059 Lisp_Object prop, val;
2060{
7eb63b72 2061 register Lisp_Object old_alist_elt;
dc6f92b8 2062
7eb63b72
GM
2063 /* The buffer-alist parameter is stored in a special place and is
2064 not in the alist. */
fa54c6ae
RS
2065 if (EQ (prop, Qbuffer_list))
2066 {
2067 f->buffer_list = val;
2068 return;
2069 }
2070
7eb63b72
GM
2071 /* If PROP is a symbol which is supposed to have frame-local values,
2072 and it is set up based on this frame, switch to the global
2073 binding. That way, we can create or alter the frame-local binding
2074 without messing up the symbol's status. */
2075 if (SYMBOLP (prop))
2076 {
2077 Lisp_Object valcontents;
f5c1dd0d 2078 valcontents = SYMBOL_VALUE (prop);
7eb63b72
GM
2079 if ((BUFFER_LOCAL_VALUEP (valcontents)
2080 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
2081 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2082 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2083 swap_in_global_binding (prop);
2084 }
2085
94674d18
EZ
2086#ifndef WINDOWSNT
2087 /* The tty color mode needs to be set before the frame's parameter
2088 alist is updated with the new value, because set_tty_color_mode
2089 wants to look at the old mode. */
2090 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode))
2091 set_tty_color_mode (f, val);
2092#endif
2093
7eb63b72
GM
2094 /* Update the frame parameter alist. */
2095 old_alist_elt = Fassq (prop, f->param_alist);
2096 if (EQ (old_alist_elt, Qnil))
ff11dfa1 2097 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
dc6f92b8 2098 else
7eb63b72 2099 Fsetcdr (old_alist_elt, val);
bc93c097 2100
7eb63b72
GM
2101 /* Update some other special parameters in their special places
2102 in addition to the alist. */
177c0ea7 2103
329ca574
RS
2104 if (EQ (prop, Qbuffer_predicate))
2105 f->buffer_predicate = val;
2106
032d78fe 2107 if (! FRAME_WINDOW_P (f))
e5317d61
EZ
2108 {
2109 if (EQ (prop, Qmenu_bar_lines))
2110 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2111 else if (EQ (prop, Qname))
2112 set_term_frame_name (f, val);
2113 }
a249de79 2114
e35d291d 2115 if (EQ (prop, Qminibuffer) && WINDOWP (val))
bc93c097
JB
2116 {
2117 if (! MINI_WINDOW_P (XWINDOW (val)))
7c402969 2118 error ("Surrogate minibuffer windows must be minibuffer windows");
bc93c097 2119
213bac8a 2120 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
7af7ef38
KH
2121 && !EQ (val, f->minibuffer_window))
2122 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
bc93c097
JB
2123
2124 /* Install the chosen minibuffer window, with proper buffer. */
ff11dfa1 2125 f->minibuffer_window = val;
bc93c097 2126 }
dc6f92b8
JB
2127}
2128
ff11dfa1 2129DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
14ff1ee0
PJ
2130 doc: /* Return the parameters-alist of frame FRAME.
2131It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2132The meaningful PARMs depend on the kind of frame.
2133If FRAME is omitted, return information on the currently selected frame. */)
2134 (frame)
ff11dfa1 2135 Lisp_Object frame;
dc6f92b8
JB
2136{
2137 Lisp_Object alist;
f769f1b2 2138 FRAME_PTR f;
dd10ec4f 2139 int height, width;
57629833 2140 struct gcpro gcpro1;
dc6f92b8 2141
03390a72 2142 if (NILP (frame))
8d2666fe
GM
2143 frame = selected_frame;
2144
b7826503 2145 CHECK_FRAME (frame);
8d2666fe 2146 f = XFRAME (frame);
dc6f92b8 2147
f769f1b2 2148 if (!FRAME_LIVE_P (f))
dc6f92b8
JB
2149 return Qnil;
2150
ff11dfa1 2151 alist = Fcopy_alist (f->param_alist);
57629833 2152 GCPRO1 (alist);
177c0ea7 2153
2d764c78 2154 if (!FRAME_WINDOW_P (f))
bb221971 2155 {
4aec4b29
EZ
2156 int fg = FRAME_FOREGROUND_PIXEL (f);
2157 int bg = FRAME_BACKGROUND_PIXEL (f);
e1d0bbc9
EZ
2158 Lisp_Object elt;
2159
2160 /* If the frame's parameter alist says the colors are
2161 unspecified and reversed, take the frame's background pixel
2162 for foreground and vice versa. */
2163 elt = Fassq (Qforeground_color, alist);
70de9f06
EZ
2164 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2165 {
d5db4077 2166 if (strncmp (SDATA (XCDR (elt)),
70de9f06 2167 unspecified_bg,
d5db4077 2168 SCHARS (XCDR (elt))) == 0)
70de9f06 2169 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
d5db4077 2170 else if (strncmp (SDATA (XCDR (elt)),
70de9f06 2171 unspecified_fg,
d5db4077 2172 SCHARS (XCDR (elt))) == 0)
70de9f06
EZ
2173 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2174 }
e1d0bbc9
EZ
2175 else
2176 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2177 elt = Fassq (Qbackground_color, alist);
70de9f06
EZ
2178 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2179 {
d5db4077 2180 if (strncmp (SDATA (XCDR (elt)),
70de9f06 2181 unspecified_fg,
d5db4077 2182 SCHARS (XCDR (elt))) == 0)
70de9f06 2183 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
d5db4077 2184 else if (strncmp (SDATA (XCDR (elt)),
70de9f06 2185 unspecified_bg,
d5db4077 2186 SCHARS (XCDR (elt))) == 0)
70de9f06
EZ
2187 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2188 }
e1d0bbc9
EZ
2189 else
2190 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2d764c78
EZ
2191 store_in_alist (&alist, intern ("font"),
2192 build_string (FRAME_MSDOS_P (f)
2193 ? "ms-dos"
4ec0d3c1 2194 : FRAME_W32_P (f) ? "w32term"
4ec0d3c1 2195 :"tty"));
bb221971 2196 }
fd0c2bd1 2197 store_in_alist (&alist, Qname, f->name);
5af5757b 2198 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
dd10ec4f 2199 store_in_alist (&alist, Qheight, make_number (height));
5af5757b 2200 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
dd10ec4f 2201 store_in_alist (&alist, Qwidth, make_number (width));
f769f1b2 2202 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
fd0c2bd1 2203 store_in_alist (&alist, Qminibuffer,
39acc701 2204 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
f769f1b2
KH
2205 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2206 : FRAME_MINIBUF_WINDOW (f)));
2207 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
03390a72 2208 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
fd0c2bd1 2209
dbc4e1c1 2210 /* I think this should be done with a hook. */
032d78fe
GV
2211#ifdef HAVE_WINDOW_SYSTEM
2212 if (FRAME_WINDOW_P (f))
ff11dfa1 2213 x_report_frame_params (f, &alist);
b6dd20ed 2214 else
fd0c2bd1 2215#endif
16a3738c
KH
2216 {
2217 /* This ought to be correct in f->param_alist for an X frame. */
2218 Lisp_Object lines;
f4e93c40 2219 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
16a3738c
KH
2220 store_in_alist (&alist, Qmenu_bar_lines, lines);
2221 }
57629833
GM
2222
2223 UNGCPRO;
dc6f92b8
JB
2224 return alist;
2225}
2226
8b60f7bc
GM
2227
2228DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
14ff1ee0
PJ
2229 doc: /* Return FRAME's value for parameter PARAMETER.
2230If FRAME is nil, describe the currently selected frame. */)
2231 (frame, parameter)
2232 Lisp_Object frame, parameter;
8b60f7bc
GM
2233{
2234 struct frame *f;
2235 Lisp_Object value;
2236
2237 if (NILP (frame))
2238 frame = selected_frame;
2239 else
b7826503
PJ
2240 CHECK_FRAME (frame);
2241 CHECK_SYMBOL (parameter);
177c0ea7 2242
8b60f7bc
GM
2243 f = XFRAME (frame);
2244 value = Qnil;
177c0ea7 2245
8b60f7bc
GM
2246 if (FRAME_LIVE_P (f))
2247 {
5cd62b8c 2248 /* Avoid consing in frequent cases. */
67d853e6
GM
2249 if (EQ (parameter, Qname))
2250 value = f->name;
6345f6aa
GM
2251#ifdef HAVE_X_WINDOWS
2252 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2253 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2254#endif /* HAVE_X_WINDOWS */
75700ff2
GM
2255 else if (EQ (parameter, Qbackground_color)
2256 || EQ (parameter, Qforeground_color))
67d853e6
GM
2257 {
2258 value = Fassq (parameter, f->param_alist);
2259 if (CONSP (value))
5f65b39d 2260 {
5f65b39d
EZ
2261 value = XCDR (value);
2262 /* Fframe_parameters puts the actual fg/bg color names,
2263 even if f->param_alist says otherwise. This is
2264 important when param_alist's notion of colors is
2265 "unspecified". We need to do the same here. */
2266 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2267 {
c9b08ba8 2268 const char *color_name;
e1d0bbc9
EZ
2269 EMACS_INT csz;
2270
2271 if (EQ (parameter, Qbackground_color))
2272 {
d5db4077
KR
2273 color_name = SDATA (value);
2274 csz = SCHARS (value);
e1d0bbc9
EZ
2275 if (strncmp (color_name, unspecified_bg, csz) == 0)
2276 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2277 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2278 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2279 }
2280 else if (EQ (parameter, Qforeground_color))
2281 {
d5db4077
KR
2282 color_name = SDATA (value);
2283 csz = SCHARS (value);
e1d0bbc9
EZ
2284 if (strncmp (color_name, unspecified_fg, csz) == 0)
2285 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2286 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2287 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2288 }
5f65b39d
EZ
2289 }
2290 }
b23236fb
EZ
2291 else
2292 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
67d853e6 2293 }
75700ff2
GM
2294 else if (EQ (parameter, Qdisplay_type)
2295 || EQ (parameter, Qbackground_mode))
75700ff2
GM
2296 value = Fcdr (Fassq (parameter, f->param_alist));
2297 else
2298 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
8b60f7bc 2299 }
177c0ea7 2300
8b60f7bc
GM
2301 return value;
2302}
2303
2304
177c0ea7 2305DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
ff11dfa1 2306 Smodify_frame_parameters, 2, 2, 0,
14ff1ee0
PJ
2307 doc: /* Modify the parameters of frame FRAME according to ALIST.
2308If FRAME is nil, it defaults to the selected frame.
2309ALIST is an alist of parameters to change and their new values.
2310Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2311The meaningful PARMs depend on the kind of frame.
2312Undefined PARMs are ignored, but stored in the frame's parameter list
2313so that `frame-parameters' will return them.
2314
2315The value of frame parameter FOO can also be accessed
2316as a frame-local binding for the variable FOO, if you have
2317enabled such bindings for that variable with `make-variable-frame-local'. */)
2318 (frame, alist)
ff11dfa1 2319 Lisp_Object frame, alist;
dc6f92b8 2320{
fd0c2bd1 2321 FRAME_PTR f;
213bac8a 2322 register Lisp_Object tail, prop, val;
331379bf 2323 int count = SPECPDL_INDEX ();
3df1fda2
GM
2324
2325 /* Bind this to t to inhibit initialization of the default face from
2326 X resources in face-set-after-frame-default. If we don't inhibit
2327 this, modifying the `font' frame parameter, for example, while
2328 there is a `default.attributeFont' X resource, won't work,
2329 because `default's font is reset to the value of the X resource
2330 and that resets the `font' frame parameter. */
2331 specbind (Qinhibit_default_face_x_resources, Qt);
dc6f92b8 2332
ff11dfa1 2333 if (EQ (frame, Qnil))
8d2666fe 2334 frame = selected_frame;
b7826503 2335 CHECK_LIVE_FRAME (frame);
8d2666fe 2336 f = XFRAME (frame);
dc6f92b8 2337
dbc4e1c1 2338 /* I think this should be done with a hook. */
032d78fe
GV
2339#ifdef HAVE_WINDOW_SYSTEM
2340 if (FRAME_WINDOW_P (f))
fd0c2bd1 2341 x_set_frame_parameters (f, alist);
329ca574 2342 else
bb221971
RS
2343#endif
2344#ifdef MSDOS
2345 if (FRAME_MSDOS_P (f))
2346 IT_set_frame_parameters (f, alist);
2347 else
329ca574 2348#endif
574a1a90 2349
41d44f1f
RS
2350 {
2351 int length = XINT (Flength (alist));
2352 int i;
2353 Lisp_Object *parms
2354 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2355 Lisp_Object *values
2356 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2357
2358 /* Extract parm names and values into those vectors. */
2359
2360 i = 0;
2361 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2362 {
213bac8a 2363 Lisp_Object elt;
41d44f1f
RS
2364
2365 elt = Fcar (tail);
2366 parms[i] = Fcar (elt);
2367 values[i] = Fcdr (elt);
2368 i++;
2369 }
2370
2371 /* Now process them in reverse of specified order. */
2372 for (i--; i >= 0; i--)
2373 {
2374 prop = parms[i];
2375 val = values[i];
2376 store_frame_param (f, prop, val);
2377 }
2378 }
dc6f92b8 2379
3df1fda2 2380 return unbind_to (count, Qnil);
dc6f92b8
JB
2381}
2382\f
a26a1f95 2383DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
14ff1ee0
PJ
2384 0, 1, 0,
2385 doc: /* Height in pixels of a line in the font in frame FRAME.
2386If FRAME is omitted, the selected frame is used.
2387For a terminal frame, the value is always 1. */)
ff11dfa1
JB
2388 (frame)
2389 Lisp_Object frame;
dc6f92b8 2390{
a26a1f95 2391 struct frame *f;
dc6f92b8 2392
a26a1f95 2393 if (NILP (frame))
8d2666fe 2394 frame = selected_frame;
b7826503 2395 CHECK_FRAME (frame);
8d2666fe 2396 f = XFRAME (frame);
a26a1f95 2397
032d78fe
GV
2398#ifdef HAVE_WINDOW_SYSTEM
2399 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2400 return make_number (x_char_height (f));
2401 else
dc6d9681 2402#endif
a26a1f95
RS
2403 return make_number (1);
2404}
dc6d9681 2405
dc6f92b8 2406
a26a1f95 2407DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
14ff1ee0
PJ
2408 0, 1, 0,
2409 doc: /* Width in pixels of characters in the font in frame FRAME.
2410If FRAME is omitted, the selected frame is used.
2411The width is the same for all characters, because
2412currently Emacs supports only fixed-width fonts.
2413For a terminal screen, the value is always 1. */)
2414 (frame)
a26a1f95 2415 Lisp_Object frame;
dc6f92b8 2416{
a26a1f95
RS
2417 struct frame *f;
2418
2419 if (NILP (frame))
8d2666fe 2420 frame = selected_frame;
b7826503 2421 CHECK_FRAME (frame);
8d2666fe 2422 f = XFRAME (frame);
a26a1f95 2423
032d78fe
GV
2424#ifdef HAVE_WINDOW_SYSTEM
2425 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2426 return make_number (x_char_width (f));
2427 else
2428#endif
2429 return make_number (1);
dc6f92b8
JB
2430}
2431
177c0ea7 2432DEFUN ("frame-pixel-height", Fframe_pixel_height,
a26a1f95 2433 Sframe_pixel_height, 0, 1, 0,
14ff1ee0
PJ
2434 doc: /* Return a FRAME's height in pixels.
2435This counts only the height available for text lines,
2436not menu bars on window-system Emacs frames.
2437For a terminal frame, the result really gives the height in characters.
2438If FRAME is omitted, the selected frame is used. */)
2439 (frame)
a26a1f95 2440 Lisp_Object frame;
dc6f92b8 2441{
a26a1f95
RS
2442 struct frame *f;
2443
2444 if (NILP (frame))
8d2666fe 2445 frame = selected_frame;
b7826503 2446 CHECK_FRAME (frame);
8d2666fe 2447 f = XFRAME (frame);
a26a1f95 2448
032d78fe
GV
2449#ifdef HAVE_WINDOW_SYSTEM
2450 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2451 return make_number (x_pixel_height (f));
2452 else
dc6d9681 2453#endif
5af5757b 2454 return make_number (FRAME_LINES (f));
a26a1f95
RS
2455}
2456
177c0ea7 2457DEFUN ("frame-pixel-width", Fframe_pixel_width,
a26a1f95 2458 Sframe_pixel_width, 0, 1, 0,
14ff1ee0
PJ
2459 doc: /* Return FRAME's width in pixels.
2460For a terminal frame, the result really gives the width in characters.
2461If FRAME is omitted, the selected frame is used. */)
2462 (frame)
a26a1f95
RS
2463 Lisp_Object frame;
2464{
2465 struct frame *f;
2466
2467 if (NILP (frame))
8d2666fe 2468 frame = selected_frame;
b7826503 2469 CHECK_FRAME (frame);
8d2666fe 2470 f = XFRAME (frame);
dc6f92b8 2471
032d78fe
GV
2472#ifdef HAVE_WINDOW_SYSTEM
2473 if (FRAME_WINDOW_P (f))
a26a1f95
RS
2474 return make_number (x_pixel_width (f));
2475 else
2476#endif
5af5757b 2477 return make_number (FRAME_COLS (f));
a26a1f95
RS
2478}
2479\f
ff11dfa1 2480DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
14ff1ee0
PJ
2481 doc: /* Specify that the frame FRAME has LINES lines.
2482Optional third arg non-nil means that redisplay should use LINES lines
2483but that the idea of the actual height of the frame should not be changed. */)
2484 (frame, lines, pretend)
735eeca3 2485 Lisp_Object frame, lines, pretend;
dc6f92b8 2486{
ff11dfa1 2487 register struct frame *f;
dc6f92b8 2488
b7826503 2489 CHECK_NUMBER (lines);
ff11dfa1 2490 if (NILP (frame))
8d2666fe 2491 frame = selected_frame;
b7826503 2492 CHECK_LIVE_FRAME (frame);
8d2666fe 2493 f = XFRAME (frame);
dc6f92b8 2494
dbc4e1c1 2495 /* I think this should be done with a hook. */
032d78fe
GV
2496#ifdef HAVE_WINDOW_SYSTEM
2497 if (FRAME_WINDOW_P (f))
dc6f92b8 2498 {
5af5757b
KS
2499 if (XINT (lines) != FRAME_LINES (f))
2500 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
32347cf4 2501 do_pending_window_change (0);
dc6f92b8
JB
2502 }
2503 else
fd0c2bd1 2504#endif
32347cf4 2505 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
dc6f92b8
JB
2506 return Qnil;
2507}
2508
ff11dfa1 2509DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
14ff1ee0
PJ
2510 doc: /* Specify that the frame FRAME has COLS columns.
2511Optional third arg non-nil means that redisplay should use COLS columns
2512but that the idea of the actual width of the frame should not be changed. */)
2513 (frame, cols, pretend)
fd0c2bd1 2514 Lisp_Object frame, cols, pretend;
dc6f92b8 2515{
ff11dfa1 2516 register struct frame *f;
b7826503 2517 CHECK_NUMBER (cols);
ff11dfa1 2518 if (NILP (frame))
8d2666fe 2519 frame = selected_frame;
b7826503 2520 CHECK_LIVE_FRAME (frame);
8d2666fe 2521 f = XFRAME (frame);
dc6f92b8 2522
dbc4e1c1 2523 /* I think this should be done with a hook. */
032d78fe
GV
2524#ifdef HAVE_WINDOW_SYSTEM
2525 if (FRAME_WINDOW_P (f))
dc6f92b8 2526 {
5af5757b
KS
2527 if (XINT (cols) != FRAME_COLS (f))
2528 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
32347cf4 2529 do_pending_window_change (0);
dc6f92b8
JB
2530 }
2531 else
fd0c2bd1 2532#endif
32347cf4 2533 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
dc6f92b8
JB
2534 return Qnil;
2535}
2536
ff11dfa1 2537DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
14ff1ee0
PJ
2538 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2539 (frame, cols, rows)
ff11dfa1 2540 Lisp_Object frame, cols, rows;
dc6f92b8 2541{
ff11dfa1 2542 register struct frame *f;
dc6f92b8 2543
b7826503
PJ
2544 CHECK_LIVE_FRAME (frame);
2545 CHECK_NUMBER (cols);
2546 CHECK_NUMBER (rows);
ff11dfa1 2547 f = XFRAME (frame);
dc6f92b8 2548
dbc4e1c1 2549 /* I think this should be done with a hook. */
032d78fe
GV
2550#ifdef HAVE_WINDOW_SYSTEM
2551 if (FRAME_WINDOW_P (f))
dc6f92b8 2552 {
5af5757b
KS
2553 if (XINT (rows) != FRAME_LINES (f)
2554 || XINT (cols) != FRAME_COLS (f)
2555 || f->new_text_lines || f->new_text_cols)
808c0f20 2556 x_set_window_size (f, 1, XINT (cols), XINT (rows));
32347cf4 2557 do_pending_window_change (0);
dc6f92b8
JB
2558 }
2559 else
fd0c2bd1 2560#endif
32347cf4 2561 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
dc6f92b8
JB
2562
2563 return Qnil;
2564}
2565
177c0ea7 2566DEFUN ("set-frame-position", Fset_frame_position,
ff11dfa1 2567 Sset_frame_position, 3, 3, 0,
14ff1ee0
PJ
2568 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2569This is actually the position of the upper left corner of the frame.
2570Negative values for XOFFSET or YOFFSET are interpreted relative to
2571the rightmost or bottommost possible position (that stays within the screen). */)
2572 (frame, xoffset, yoffset)
ff11dfa1 2573 Lisp_Object frame, xoffset, yoffset;
dc6f92b8 2574{
ff11dfa1 2575 register struct frame *f;
dc6f92b8 2576
b7826503
PJ
2577 CHECK_LIVE_FRAME (frame);
2578 CHECK_NUMBER (xoffset);
2579 CHECK_NUMBER (yoffset);
ff11dfa1 2580 f = XFRAME (frame);
dc6f92b8 2581
dbc4e1c1 2582 /* I think this should be done with a hook. */
032d78fe
GV
2583#ifdef HAVE_WINDOW_SYSTEM
2584 if (FRAME_WINDOW_P (f))
c7c70761 2585 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
fd0c2bd1 2586#endif
dc6f92b8
JB
2587
2588 return Qt;
2589}
dc6d9681 2590
dc6f92b8 2591\f
972f4259
KS
2592/***********************************************************************
2593 Frame Parameters
2594 ***********************************************************************/
2595
2596/* Connect the frame-parameter names for X frames
2597 to the ways of passing the parameter values to the window system.
2598
2599 The name of a parameter, as a Lisp symbol,
2600 has an `x-frame-parameter' property which is an integer in Lisp
2601 that is an index in this table. */
2602
2603struct frame_parm_table {
2604 char *name;
2605 Lisp_Object *variable;
2606};
2607
2608static struct frame_parm_table frame_parms[] =
2609{
2610 {"auto-raise", &Qauto_raise},
2611 {"auto-lower", &Qauto_lower},
2612 {"background-color", 0},
2613 {"border-color", &Qborder_color},
2614 {"border-width", &Qborder_width},
2615 {"cursor-color", &Qcursor_color},
2616 {"cursor-type", &Qcursor_type},
2617 {"font", 0},
2618 {"foreground-color", 0},
2619 {"icon-name", &Qicon_name},
2620 {"icon-type", &Qicon_type},
2621 {"internal-border-width", &Qinternal_border_width},
2622 {"menu-bar-lines", &Qmenu_bar_lines},
2623 {"mouse-color", &Qmouse_color},
2624 {"name", &Qname},
2625 {"scroll-bar-width", &Qscroll_bar_width},
2626 {"title", &Qtitle},
2627 {"unsplittable", &Qunsplittable},
2628 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2629 {"visibility", &Qvisibility},
2630 {"tool-bar-lines", &Qtool_bar_lines},
2631 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2632 {"scroll-bar-background", &Qscroll_bar_background},
2633 {"screen-gamma", &Qscreen_gamma},
2634 {"line-spacing", &Qline_spacing},
2635 {"left-fringe", &Qleft_fringe},
2636 {"right-fringe", &Qright_fringe},
2637 {"wait-for-wm", &Qwait_for_wm},
2638 {"fullscreen", &Qfullscreen},
2639};
2640
2641#ifdef HAVE_WINDOW_SYSTEM
2642
2643extern Lisp_Object Qbox;
2644extern Lisp_Object Qtop;
2645
2646/* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2647 wanted positions of the WM window (not emacs window).
2648 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2649 window (FRAME_X_WINDOW).
2650 */
2651
dfcf069d 2652void
972f4259
KS
2653x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2654 struct frame *f;
2655 int *width;
2656 int *height;
2657 int *top_pos;
2658 int *left_pos;
dc6f92b8 2659{
5af5757b
KS
2660 int newwidth = FRAME_COLS (f);
2661 int newheight = FRAME_LINES (f);
dc6f92b8 2662
5af5757b
KS
2663 *top_pos = f->top_pos;
2664 *left_pos = f->left_pos;
3df1fda2 2665
5af5757b 2666 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
972f4259
KS
2667 {
2668 int ph;
2669
2670 ph = FRAME_X_DISPLAY_INFO (f)->height;
5af5757b
KS
2671 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2672 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2673 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
972f4259
KS
2674 *top_pos = 0;
2675 }
dc6f92b8 2676
5af5757b 2677 if (f->want_fullscreen & FULLSCREEN_WIDTH)
972f4259
KS
2678 {
2679 int pw;
2680
2681 pw = FRAME_X_DISPLAY_INFO (f)->width;
5af5757b
KS
2682 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2683 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2684 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
972f4259
KS
2685 *left_pos = 0;
2686 }
dc6f92b8 2687
972f4259
KS
2688 *width = newwidth;
2689 *height = newheight;
2690}
dc6f92b8 2691
beb0bc36 2692
972f4259
KS
2693/* Change the parameters of frame F as specified by ALIST.
2694 If a parameter is not specially recognized, do nothing special;
2695 otherwise call the `x_set_...' function for that parameter.
2696 Except for certain geometry properties, always call store_frame_param
2697 to store the new value in the parameter alist. */
14ff1ee0 2698
972f4259
KS
2699void
2700x_set_frame_parameters (f, alist)
2701 FRAME_PTR f;
2702 Lisp_Object alist;
2703{
2704 Lisp_Object tail;
dc6f92b8 2705
972f4259
KS
2706 /* If both of these parameters are present, it's more efficient to
2707 set them both at once. So we wait until we've looked at the
2708 entire list before we set them. */
2709 int width, height;
3df1fda2 2710
972f4259
KS
2711 /* Same here. */
2712 Lisp_Object left, top;
2713
2714 /* Same with these. */
2715 Lisp_Object icon_left, icon_top;
2716
2717 /* Record in these vectors all the parms specified. */
2718 Lisp_Object *parms;
2719 Lisp_Object *values;
2720 int i, p;
2721 int left_no_change = 0, top_no_change = 0;
2722 int icon_left_no_change = 0, icon_top_no_change = 0;
2723 int fullscreen_is_being_set = 0;
2724
2725 struct gcpro gcpro1, gcpro2;
2726
2727 i = 0;
2728 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2729 i++;
2730
2731 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2732 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2733
2734 /* Extract parm names and values into those vectors. */
2735
2736 i = 0;
2737 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2738 {
2739 Lisp_Object elt;
2740
2741 elt = Fcar (tail);
2742 parms[i] = Fcar (elt);
2743 values[i] = Fcdr (elt);
2744 i++;
2745 }
2746 /* TAIL and ALIST are not used again below here. */
2747 alist = tail = Qnil;
2748
2749 GCPRO2 (*parms, *values);
2750 gcpro1.nvars = i;
2751 gcpro2.nvars = i;
2752
2753 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2754 because their values appear in VALUES and strings are not valid. */
2755 top = left = Qunbound;
2756 icon_left = icon_top = Qunbound;
2757
2758 /* Provide default values for HEIGHT and WIDTH. */
5af5757b
KS
2759 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2760 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
972f4259
KS
2761
2762 /* Process foreground_color and background_color before anything else.
2763 They are independent of other properties, but other properties (e.g.,
2764 cursor_color) are dependent upon them. */
2765 /* Process default font as well, since fringe widths depends on it. */
2766 /* Also, process fullscreen, width and height depend upon that */
2767 for (p = 0; p < i; p++)
2768 {
2769 Lisp_Object prop, val;
2770
2771 prop = parms[p];
2772 val = values[p];
2773 if (EQ (prop, Qforeground_color)
2774 || EQ (prop, Qbackground_color)
2775 || EQ (prop, Qfont)
2776 || EQ (prop, Qfullscreen))
2777 {
2778 register Lisp_Object param_index, old_value;
2779
2780 old_value = get_frame_param (f, prop);
2781 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
2782
2783 if (NILP (Fequal (val, old_value)))
2784 {
2785 store_frame_param (f, prop, val);
2786
2787 param_index = Fget (prop, Qx_frame_parameter);
2788 if (NATNUMP (param_index)
2789 && (XFASTINT (param_index)
2790 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2791 && rif->frame_parm_handlers[XINT (param_index)])
2792 (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2793 }
2794 }
2795 }
2796
2797 /* Now process them in reverse of specified order. */
2798 for (i--; i >= 0; i--)
2799 {
2800 Lisp_Object prop, val;
2801
2802 prop = parms[i];
2803 val = values[i];
2804
2805 if (EQ (prop, Qwidth) && NUMBERP (val))
2806 width = XFASTINT (val);
2807 else if (EQ (prop, Qheight) && NUMBERP (val))
2808 height = XFASTINT (val);
2809 else if (EQ (prop, Qtop))
2810 top = val;
2811 else if (EQ (prop, Qleft))
2812 left = val;
2813 else if (EQ (prop, Qicon_top))
2814 icon_top = val;
2815 else if (EQ (prop, Qicon_left))
2816 icon_left = val;
2817 else if (EQ (prop, Qforeground_color)
2818 || EQ (prop, Qbackground_color)
2819 || EQ (prop, Qfont)
2820 || EQ (prop, Qfullscreen))
2821 /* Processed above. */
2822 continue;
2823 else
2824 {
2825 register Lisp_Object param_index, old_value;
2826
2827 old_value = get_frame_param (f, prop);
2828
2829 store_frame_param (f, prop, val);
2830
2831 param_index = Fget (prop, Qx_frame_parameter);
2832 if (NATNUMP (param_index)
2833 && (XFASTINT (param_index)
2834 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2835 && rif->frame_parm_handlers[XINT (param_index)])
2836 (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2837 }
2838 }
2839
2840 /* Don't die if just one of these was set. */
2841 if (EQ (left, Qunbound))
2842 {
2843 left_no_change = 1;
5af5757b
KS
2844 if (f->left_pos < 0)
2845 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
972f4259 2846 else
5af5757b 2847 XSETINT (left, f->left_pos);
972f4259
KS
2848 }
2849 if (EQ (top, Qunbound))
2850 {
2851 top_no_change = 1;
5af5757b
KS
2852 if (f->top_pos < 0)
2853 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
972f4259 2854 else
5af5757b 2855 XSETINT (top, f->top_pos);
972f4259
KS
2856 }
2857
2858 /* If one of the icon positions was not set, preserve or default it. */
2859 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
2860 {
2861 icon_left_no_change = 1;
2862 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2863 if (NILP (icon_left))
2864 XSETINT (icon_left, 0);
2865 }
2866 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
2867 {
2868 icon_top_no_change = 1;
2869 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2870 if (NILP (icon_top))
2871 XSETINT (icon_top, 0);
2872 }
2873
2874#ifndef HAVE_CARBON
2875 /* MAC_TODO: fullscreen */
2876 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
2877 {
2878 /* If the frame is visible already and the fullscreen parameter is
2879 being set, it is too late to set WM manager hints to specify
2880 size and position.
2881 Here we first get the width, height and position that applies to
2882 fullscreen. We then move the frame to the appropriate
2883 position. Resize of the frame is taken care of in the code after
2884 this if-statement. */
2885 int new_left, new_top;
2886
2887 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
068ae0fd
JD
2888 if (new_top != f->top_pos || new_left != f->left_pos)
2889 x_set_offset (f, new_left, new_top, 1);
972f4259 2890 }
dc6f92b8 2891#endif
972f4259
KS
2892
2893 /* Don't set these parameters unless they've been explicitly
2894 specified. The window might be mapped or resized while we're in
2895 this function, and we don't want to override that unless the lisp
2896 code has asked for it.
2897
2898 Don't set these parameters unless they actually differ from the
2899 window's current parameters; the window may not actually exist
2900 yet. */
2901 {
2902 Lisp_Object frame;
2903
2904 check_frame_size (f, &height, &width);
2905
2906 XSETFRAME (frame, f);
2907
5af5757b
KS
2908 if (width != FRAME_COLS (f)
2909 || height != FRAME_LINES (f)
2910 || f->new_text_lines || f->new_text_cols)
972f4259
KS
2911 Fset_frame_size (frame, make_number (width), make_number (height));
2912
2913 if ((!NILP (left) || !NILP (top))
2914 && ! (left_no_change && top_no_change)
5af5757b
KS
2915 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2916 && NUMBERP (top) && XINT (top) == f->top_pos))
972f4259
KS
2917 {
2918 int leftpos = 0;
2919 int toppos = 0;
2920
2921 /* Record the signs. */
5af5757b 2922 f->size_hint_flags &= ~ (XNegative | YNegative);
972f4259 2923 if (EQ (left, Qminus))
5af5757b 2924 f->size_hint_flags |= XNegative;
972f4259
KS
2925 else if (INTEGERP (left))
2926 {
2927 leftpos = XINT (left);
2928 if (leftpos < 0)
5af5757b 2929 f->size_hint_flags |= XNegative;
972f4259
KS
2930 }
2931 else if (CONSP (left) && EQ (XCAR (left), Qminus)
2932 && CONSP (XCDR (left))
2933 && INTEGERP (XCAR (XCDR (left))))
2934 {
2935 leftpos = - XINT (XCAR (XCDR (left)));
5af5757b 2936 f->size_hint_flags |= XNegative;
972f4259
KS
2937 }
2938 else if (CONSP (left) && EQ (XCAR (left), Qplus)
2939 && CONSP (XCDR (left))
2940 && INTEGERP (XCAR (XCDR (left))))
2941 {
2942 leftpos = XINT (XCAR (XCDR (left)));
2943 }
2944
2945 if (EQ (top, Qminus))
5af5757b 2946 f->size_hint_flags |= YNegative;
972f4259
KS
2947 else if (INTEGERP (top))
2948 {
2949 toppos = XINT (top);
2950 if (toppos < 0)
5af5757b 2951 f->size_hint_flags |= YNegative;
972f4259
KS
2952 }
2953 else if (CONSP (top) && EQ (XCAR (top), Qminus)
2954 && CONSP (XCDR (top))
2955 && INTEGERP (XCAR (XCDR (top))))
2956 {
2957 toppos = - XINT (XCAR (XCDR (top)));
5af5757b 2958 f->size_hint_flags |= YNegative;
972f4259
KS
2959 }
2960 else if (CONSP (top) && EQ (XCAR (top), Qplus)
2961 && CONSP (XCDR (top))
2962 && INTEGERP (XCAR (XCDR (top))))
2963 {
2964 toppos = XINT (XCAR (XCDR (top)));
2965 }
2966
2967
2968 /* Store the numeric value of the position. */
5af5757b
KS
2969 f->top_pos = toppos;
2970 f->left_pos = leftpos;
972f4259 2971
5af5757b 2972 f->win_gravity = NorthWestGravity;
972f4259
KS
2973
2974 /* Actually set that position, and convert to absolute. */
2975 x_set_offset (f, leftpos, toppos, -1);
2976 }
2977
2978 if ((!NILP (icon_left) || !NILP (icon_top))
2979 && ! (icon_left_no_change && icon_top_no_change))
2980 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
2981 }
2982
2983 UNGCPRO;
2984}
2985
2986
2987/* Insert a description of internally-recorded parameters of frame X
2988 into the parameter alist *ALISTPTR that is to be given to the user.
2989 Only parameters that are specific to the X window system
2990 and whose values are not correctly recorded in the frame's
2991 param_alist need to be considered here. */
2992
2993void
2994x_report_frame_params (f, alistptr)
2995 struct frame *f;
2996 Lisp_Object *alistptr;
2997{
2998 char buf[16];
2999 Lisp_Object tem;
3000
3001 /* Represent negative positions (off the top or left screen edge)
3002 in a way that Fmodify_frame_parameters will understand correctly. */
5af5757b
KS
3003 XSETINT (tem, f->left_pos);
3004 if (f->left_pos >= 0)
972f4259
KS
3005 store_in_alist (alistptr, Qleft, tem);
3006 else
3007 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3008
5af5757b
KS
3009 XSETINT (tem, f->top_pos);
3010 if (f->top_pos >= 0)
972f4259
KS
3011 store_in_alist (alistptr, Qtop, tem);
3012 else
3013 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3014
3015 store_in_alist (alistptr, Qborder_width,
5af5757b 3016 make_number (f->border_width));
972f4259 3017 store_in_alist (alistptr, Qinternal_border_width,
5af5757b 3018 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
972f4259 3019 store_in_alist (alistptr, Qleft_fringe,
5af5757b 3020 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
972f4259 3021 store_in_alist (alistptr, Qright_fringe,
5af5757b 3022 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
972f4259
KS
3023 store_in_alist (alistptr, Qscroll_bar_width,
3024 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3025 ? make_number (0)
5af5757b
KS
3026 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3027 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
972f4259
KS
3028 /* nil means "use default width"
3029 for non-toolkit scroll bar.
3030 ruler-mode.el depends on this. */
3031 : Qnil));
3032 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3033 store_in_alist (alistptr, Qwindow_id,
3034 build_string (buf));
3035#ifdef HAVE_X_WINDOWS
3036#ifdef USE_X_TOOLKIT
3037 /* Tooltip frame may not have this widget. */
3038 if (FRAME_X_OUTPUT (f)->widget)
3039#endif
3040 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3041 store_in_alist (alistptr, Qouter_window_id,
3042 build_string (buf));
3043#endif
3044 store_in_alist (alistptr, Qicon_name, f->icon_name);
3045 FRAME_SAMPLE_VISIBILITY (f);
3046 store_in_alist (alistptr, Qvisibility,
3047 (FRAME_VISIBLE_P (f) ? Qt
3048 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3049 store_in_alist (alistptr, Qdisplay,
3050 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3051
2f4b24c3
AC
3052#ifndef HAVE_CARBON
3053/* A Mac Window is identified by a struct, not an integer. */
972f4259
KS
3054 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3055 tem = Qnil;
3056 else
3057 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3058 store_in_alist (alistptr, Qparent_id, tem);
2f4b24c3 3059#endif
972f4259
KS
3060}
3061
3062
3063/* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3064 the previous value of that parameter, NEW_VALUE is the new value. */
3065
3066void
3067x_set_fullscreen (f, new_value, old_value)
3068 struct frame *f;
3069 Lisp_Object new_value, old_value;
3070{
3071#ifndef HAVE_CARBON
3072 if (NILP (new_value))
5af5757b 3073 f->want_fullscreen = FULLSCREEN_NONE;
972f4259 3074 else if (EQ (new_value, Qfullboth))
5af5757b 3075 f->want_fullscreen = FULLSCREEN_BOTH;
972f4259 3076 else if (EQ (new_value, Qfullwidth))
5af5757b 3077 f->want_fullscreen = FULLSCREEN_WIDTH;
972f4259 3078 else if (EQ (new_value, Qfullheight))
5af5757b 3079 f->want_fullscreen = FULLSCREEN_HEIGHT;
972f4259
KS
3080#endif
3081}
3082
3083
3084/* Change the `line-spacing' 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_line_spacing (f, new_value, old_value)
3089 struct frame *f;
3090 Lisp_Object new_value, old_value;
3091{
3092 if (NILP (new_value))
3093 f->extra_line_spacing = 0;
3094 else if (NATNUMP (new_value))
3095 f->extra_line_spacing = XFASTINT (new_value);
3096 else
3097 Fsignal (Qerror, Fcons (build_string ("Invalid line-spacing"),
3098 Fcons (new_value, Qnil)));
3099 if (FRAME_VISIBLE_P (f))
3100 redraw_frame (f);
3101}
3102
3103
3104/* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3105 the previous value of that parameter, NEW_VALUE is the new value. */
3106
3107void
3108x_set_screen_gamma (f, new_value, old_value)
3109 struct frame *f;
3110 Lisp_Object new_value, old_value;
3111{
3112 if (NILP (new_value))
3113 f->gamma = 0;
3114 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3115 /* The value 0.4545 is the normal viewing gamma. */
3116 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3117 else
3118 Fsignal (Qerror, Fcons (build_string ("Invalid screen-gamma"),
3119 Fcons (new_value, Qnil)));
3120
3121 clear_face_cache (0);
3122}
3123
3124
3125void
3126x_set_font (f, arg, oldval)
3127 struct frame *f;
3128 Lisp_Object arg, oldval;
3129{
3130 Lisp_Object result;
3131 Lisp_Object fontset_name;
3132 Lisp_Object frame;
3133 int old_fontset = FRAME_FONTSET(f);
3134
3135 CHECK_STRING (arg);
3136
3137 fontset_name = Fquery_fontset (arg, Qnil);
3138
3139 BLOCK_INPUT;
3140 result = (STRINGP (fontset_name)
3141 ? x_new_fontset (f, SDATA (fontset_name))
3142 : x_new_font (f, SDATA (arg)));
3143 UNBLOCK_INPUT;
3144
3145 if (EQ (result, Qnil))
3146 error ("Font `%s' is not defined", SDATA (arg));
3147 else if (EQ (result, Qt))
3148 error ("The characters of the given font have varying widths");
3149 else if (STRINGP (result))
3150 {
3151 if (STRINGP (fontset_name))
3152 {
3153 /* Fontset names are built from ASCII font names, so the
3154 names may be equal despite there was a change. */
3155 if (old_fontset == FRAME_FONTSET (f))
3156 return;
3157 }
3158 else if (!NILP (Fequal (result, oldval)))
3159 return;
3160
3161 store_frame_param (f, Qfont, result);
3162 recompute_basic_faces (f);
3163 }
3164 else
3165 abort ();
3166
3167 do_pending_window_change (0);
3168
3169 /* Don't call `face-set-after-frame-default' when faces haven't been
3170 initialized yet. This is the case when called from
3171 Fx_create_frame. In that case, the X widget or window doesn't
3172 exist either, and we can end up in x_report_frame_params with a
3173 null widget which gives a segfault. */
3174 if (FRAME_FACE_CACHE (f))
3175 {
3176 XSETFRAME (frame, f);
3177 call1 (Qface_set_after_frame_default, frame);
3178 }
3179}
3180
3181
3182void
3183x_set_fringe_width (f, new_value, old_value)
3184 struct frame *f;
3185 Lisp_Object new_value, old_value;
3186{
3187 compute_fringe_widths (f, 1);
3188}
3189
3190void
3191x_set_border_width (f, arg, oldval)
3192 struct frame *f;
3193 Lisp_Object arg, oldval;
3194{
3195 CHECK_NUMBER (arg);
3196
5af5757b 3197 if (XINT (arg) == f->border_width)
972f4259
KS
3198 return;
3199
3200#ifndef HAVE_CARBON
3201 if (FRAME_X_WINDOW (f) != 0)
3202 error ("Cannot change the border width of a window");
3203#endif /* MAC_TODO */
3204
5af5757b 3205 f->border_width = XINT (arg);
972f4259
KS
3206}
3207
3208void
3209x_set_internal_border_width (f, arg, oldval)
3210 struct frame *f;
3211 Lisp_Object arg, oldval;
3212{
5af5757b 3213 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
972f4259
KS
3214
3215 CHECK_NUMBER (arg);
5af5757b
KS
3216 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3217 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3218 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
972f4259
KS
3219
3220#ifdef USE_X_TOOLKIT
3221 if (FRAME_X_OUTPUT (f)->edit_widget)
3222 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3223#endif
3224
5af5757b 3225 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
972f4259
KS
3226 return;
3227
3228 if (FRAME_X_WINDOW (f) != 0)
3229 {
5af5757b 3230 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
972f4259
KS
3231 SET_FRAME_GARBAGED (f);
3232 do_pending_window_change (0);
3233 }
3234 else
3235 SET_FRAME_GARBAGED (f);
3236}
3237
3238void
3239x_set_visibility (f, value, oldval)
3240 struct frame *f;
3241 Lisp_Object value, oldval;
3242{
3243 Lisp_Object frame;
3244 XSETFRAME (frame, f);
3245
3246 if (NILP (value))
3247 Fmake_frame_invisible (frame, Qt);
3248 else if (EQ (value, Qicon))
3249 Ficonify_frame (frame);
3250 else
3251 Fmake_frame_visible (frame);
3252}
3253
3254void
3255x_set_autoraise (f, arg, oldval)
3256 struct frame *f;
3257 Lisp_Object arg, oldval;
3258{
3259 f->auto_raise = !EQ (Qnil, arg);
3260}
3261
3262void
3263x_set_autolower (f, arg, oldval)
3264 struct frame *f;
3265 Lisp_Object arg, oldval;
3266{
3267 f->auto_lower = !EQ (Qnil, arg);
3268}
3269
3270void
3271x_set_unsplittable (f, arg, oldval)
3272 struct frame *f;
3273 Lisp_Object arg, oldval;
3274{
3275 f->no_split = !NILP (arg);
3276}
3277
3278void
3279x_set_vertical_scroll_bars (f, arg, oldval)
3280 struct frame *f;
3281 Lisp_Object arg, oldval;
3282{
3283 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3284 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3285 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3286 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3287 {
3288 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3289 = (NILP (arg)
3290 ? vertical_scroll_bar_none
3291 : EQ (Qleft, arg)
3292 ? vertical_scroll_bar_left
3293 : EQ (Qright, arg)
3294 ? vertical_scroll_bar_right
a6e20602
KS
3295 : EQ (Qleft, Vdefault_frame_scroll_bars)
3296 ? vertical_scroll_bar_left
3297 : EQ (Qright, Vdefault_frame_scroll_bars)
3298 ? vertical_scroll_bar_right
3299 : vertical_scroll_bar_none);
972f4259
KS
3300
3301 /* We set this parameter before creating the X window for the
3302 frame, so we can get the geometry right from the start.
3303 However, if the window hasn't been created yet, we shouldn't
3304 call x_set_window_size. */
3305 if (FRAME_X_WINDOW (f))
5af5757b 3306 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
972f4259
KS
3307 do_pending_window_change (0);
3308 }
3309}
3310
3311void
3312x_set_scroll_bar_width (f, arg, oldval)
3313 struct frame *f;
3314 Lisp_Object arg, oldval;
3315{
5af5757b 3316 int wid = FRAME_COLUMN_WIDTH (f);
972f4259
KS
3317
3318 if (NILP (arg))
3319 {
3320 x_set_scroll_bar_default_width (f);
3321
3322 if (FRAME_X_WINDOW (f))
5af5757b 3323 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
972f4259
KS
3324 do_pending_window_change (0);
3325 }
3326 else if (INTEGERP (arg) && XINT (arg) > 0
5af5757b 3327 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
972f4259
KS
3328 {
3329 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3330 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3331
5af5757b
KS
3332 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3333 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
972f4259 3334 if (FRAME_X_WINDOW (f))
5af5757b 3335 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
972f4259
KS
3336 do_pending_window_change (0);
3337 }
3338
5af5757b 3339 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
972f4259
KS
3340 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3341 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3342}
3343
3344
3345
3346/* Return non-nil if frame F wants a bitmap icon. */
3347
3348Lisp_Object
3349x_icon_type (f)
3350 FRAME_PTR f;
3351{
3352 Lisp_Object tem;
3353
3354 tem = assq_no_quit (Qicon_type, f->param_alist);
3355 if (CONSP (tem))
3356 return XCDR (tem);
3357 else
3358 return Qnil;
3359}
3360
3361\f
3362/* Subroutines of creating an X frame. */
3363
3364/* Make sure that Vx_resource_name is set to a reasonable value.
3365 Fix it up, or set it to `emacs' if it is too hopeless. */
3366
3367void
3368validate_x_resource_name ()
3369{
3370 int len = 0;
3371 /* Number of valid characters in the resource name. */
3372 int good_count = 0;
3373 /* Number of invalid characters in the resource name. */
3374 int bad_count = 0;
3375 Lisp_Object new;
3376 int i;
3377
3378 if (!STRINGP (Vx_resource_class))
3379 Vx_resource_class = build_string (EMACS_CLASS);
3380
3381 if (STRINGP (Vx_resource_name))
3382 {
3383 unsigned char *p = SDATA (Vx_resource_name);
3384 int i;
3385
3386 len = SBYTES (Vx_resource_name);
3387
3388 /* Only letters, digits, - and _ are valid in resource names.
3389 Count the valid characters and count the invalid ones. */
3390 for (i = 0; i < len; i++)
3391 {
3392 int c = p[i];
3393 if (! ((c >= 'a' && c <= 'z')
3394 || (c >= 'A' && c <= 'Z')
3395 || (c >= '0' && c <= '9')
3396 || c == '-' || c == '_'))
3397 bad_count++;
3398 else
3399 good_count++;
3400 }
3401 }
3402 else
3403 /* Not a string => completely invalid. */
3404 bad_count = 5, good_count = 0;
3405
3406 /* If name is valid already, return. */
3407 if (bad_count == 0)
3408 return;
3409
3410 /* If name is entirely invalid, or nearly so, use `emacs'. */
3411 if (good_count == 0
3412 || (good_count == 1 && bad_count > 0))
3413 {
3414 Vx_resource_name = build_string ("emacs");
3415 return;
3416 }
3417
3418 /* Name is partly valid. Copy it and replace the invalid characters
3419 with underscores. */
3420
3421 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3422
3423 for (i = 0; i < len; i++)
3424 {
3425 int c = SREF (new, i);
3426 if (! ((c >= 'a' && c <= 'z')
3427 || (c >= 'A' && c <= 'Z')
3428 || (c >= '0' && c <= '9')
3429 || c == '-' || c == '_'))
3430 SSET (new, i, '_');
3431 }
3432}
3433
3434
3435extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3436extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3437
3438
3439/* Get specified attribute from resource database RDB.
3440 See Fx_get_resource below for other parameters. */
3441
3442static Lisp_Object
3443xrdb_get_resource (rdb, attribute, class, component, subclass)
3444 XrmDatabase rdb;
3445 Lisp_Object attribute, class, component, subclass;
3446{
3447 register char *value;
3448 char *name_key;
3449 char *class_key;
3450
3451 CHECK_STRING (attribute);
3452 CHECK_STRING (class);
3453
3454 if (!NILP (component))
3455 CHECK_STRING (component);
3456 if (!NILP (subclass))
3457 CHECK_STRING (subclass);
3458 if (NILP (component) != NILP (subclass))
3459 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3460
3461 validate_x_resource_name ();
3462
3463 /* Allocate space for the components, the dots which separate them,
3464 and the final '\0'. Make them big enough for the worst case. */
3465 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3466 + (STRINGP (component)
3467 ? SBYTES (component) : 0)
3468 + SBYTES (attribute)
3469 + 3);
3470
3471 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3472 + SBYTES (class)
3473 + (STRINGP (subclass)
3474 ? SBYTES (subclass) : 0)
3475 + 3);
3476
3477 /* Start with emacs.FRAMENAME for the name (the specific one)
3478 and with `Emacs' for the class key (the general one). */
3479 strcpy (name_key, SDATA (Vx_resource_name));
3480 strcpy (class_key, SDATA (Vx_resource_class));
3481
3482 strcat (class_key, ".");
3483 strcat (class_key, SDATA (class));
3484
3485 if (!NILP (component))
3486 {
3487 strcat (class_key, ".");
3488 strcat (class_key, SDATA (subclass));
3489
3490 strcat (name_key, ".");
3491 strcat (name_key, SDATA (component));
3492 }
3493
3494 strcat (name_key, ".");
3495 strcat (name_key, SDATA (attribute));
3496
3497 value = x_get_string_resource (rdb, name_key, class_key);
3498
3499 if (value != (char *) 0)
3500 return build_string (value);
3501 else
3502 return Qnil;
3503}
3504
3505
3506DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3507 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3508This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3509class, where INSTANCE is the name under which Emacs was invoked, or
3510the name specified by the `-name' or `-rn' command-line arguments.
3511
3512The optional arguments COMPONENT and SUBCLASS add to the key and the
3513class, respectively. You must specify both of them or neither.
3514If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3515and the class is `Emacs.CLASS.SUBCLASS'. */)
3516 (attribute, class, component, subclass)
3517 Lisp_Object attribute, class, component, subclass;
3518{
3519#ifdef HAVE_X_WINDOWS
3520 check_x ();
3521#endif
3522
3523 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3524 attribute, class, component, subclass);
3525}
3526
3527/* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3528
3529Lisp_Object
3530display_x_get_resource (dpyinfo, attribute, class, component, subclass)
a1702920 3531 Display_Info *dpyinfo;
972f4259
KS
3532 Lisp_Object attribute, class, component, subclass;
3533{
3534 return xrdb_get_resource (dpyinfo->xrdb,
3535 attribute, class, component, subclass);
3536}
3537
3538/* Used when C code wants a resource value. */
3539
3540char *
3541x_get_resource_string (attribute, class)
3542 char *attribute, *class;
3543{
3544 char *name_key;
3545 char *class_key;
3546 struct frame *sf = SELECTED_FRAME ();
3547
3548 /* Allocate space for the components, the dots which separate them,
3549 and the final '\0'. */
3550 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3551 + strlen (attribute) + 2);
3552 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3553 + strlen (class) + 2);
3554
3555 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3556 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3557
3558 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3559 name_key, class_key);
3560}
3561
3562
3563/* Return the value of parameter PARAM.
3564
3565 First search ALIST, then Vdefault_frame_alist, then the X defaults
3566 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3567
3568 Convert the resource to the type specified by desired_type.
3569
3570 If no default is specified, return Qunbound. If you call
3571 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3572 and don't let it get stored in any Lisp-visible variables! */
3573
3574Lisp_Object
3575x_get_arg (dpyinfo, alist, param, attribute, class, type)
3576 Display_Info *dpyinfo;
3577 Lisp_Object alist, param;
3578 char *attribute;
3579 char *class;
3580 enum resource_types type;
3581{
3582 register Lisp_Object tem;
3583
3584 tem = Fassq (param, alist);
3585 if (EQ (tem, Qnil))
3586 tem = Fassq (param, Vdefault_frame_alist);
3587 if (EQ (tem, Qnil))
3588 {
3589 if (attribute)
3590 {
3591 tem = display_x_get_resource (dpyinfo,
3592 build_string (attribute),
3593 build_string (class),
3594 Qnil, Qnil);
3595
3596 if (NILP (tem))
3597 return Qunbound;
3598
3599 switch (type)
3600 {
3601 case RES_TYPE_NUMBER:
3602 return make_number (atoi (SDATA (tem)));
3603
3604 case RES_TYPE_FLOAT:
3605 return make_float (atof (SDATA (tem)));
3606
3607 case RES_TYPE_BOOLEAN:
3608 tem = Fdowncase (tem);
3609 if (!strcmp (SDATA (tem), "on")
3610 || !strcmp (SDATA (tem), "true"))
3611 return Qt;
3612 else
3613 return Qnil;
3614
3615 case RES_TYPE_STRING:
3616 return tem;
3617
3618 case RES_TYPE_SYMBOL:
3619 /* As a special case, we map the values `true' and `on'
3620 to Qt, and `false' and `off' to Qnil. */
3621 {
3622 Lisp_Object lower;
3623 lower = Fdowncase (tem);
3624 if (!strcmp (SDATA (lower), "on")
3625 || !strcmp (SDATA (lower), "true"))
3626 return Qt;
3627 else if (!strcmp (SDATA (lower), "off")
3628 || !strcmp (SDATA (lower), "false"))
3629 return Qnil;
3630 else
3631 return Fintern (tem, Qnil);
3632 }
3633
3634 default:
3635 abort ();
3636 }
3637 }
3638 else
3639 return Qunbound;
3640 }
3641 return Fcdr (tem);
3642}
3643
3644Lisp_Object
3645x_frame_get_arg (f, alist, param, attribute, class, type)
3646 struct frame *f;
3647 Lisp_Object alist, param;
3648 char *attribute;
3649 char *class;
3650 enum resource_types type;
3651{
3652 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3653 alist, param, attribute, class, type);
3654}
3655
3656/* Like x_frame_get_arg, but also record the value in f->param_alist. */
3657
3658Lisp_Object
3659x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
3660 struct frame *f;
3661 Lisp_Object alist, param;
3662 char *attribute;
3663 char *class;
3664 enum resource_types type;
3665{
3666 Lisp_Object value;
3667
3668 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3669 attribute, class, type);
3670 if (! NILP (value))
3671 store_frame_param (f, param, value);
3672
3673 return value;
3674}
3675
3676
3677/* Record in frame F the specified or default value according to ALIST
3678 of the parameter named PROP (a Lisp symbol).
3679 If no value is specified for PROP, look for an X default for XPROP
3680 on the frame named NAME.
3681 If that is not found either, use the value DEFLT. */
3682
3683Lisp_Object
3684x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
3685 struct frame *f;
3686 Lisp_Object alist;
3687 Lisp_Object prop;
3688 Lisp_Object deflt;
3689 char *xprop;
3690 char *xclass;
3691 enum resource_types type;
3692{
3693 Lisp_Object tem;
3694
3695 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3696 if (EQ (tem, Qunbound))
3697 tem = deflt;
3698 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3699 return tem;
3700}
3701
3702
3703
3704\f
3705DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3706 doc: /* Parse an X-style geometry string STRING.
3707Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3708The properties returned may include `top', `left', `height', and `width'.
3709The value of `left' or `top' may be an integer,
3710or a list (+ N) meaning N pixels relative to top/left corner,
3711or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3712 (string)
3713 Lisp_Object string;
3714{
3715 int geometry, x, y;
3716 unsigned int width, height;
3717 Lisp_Object result;
3718
3719 CHECK_STRING (string);
3720
3721 geometry = XParseGeometry ((char *) SDATA (string),
3722 &x, &y, &width, &height);
3723
3724#if 0
3725 if (!!(geometry & XValue) != !!(geometry & YValue))
3726 error ("Must specify both x and y position, or neither");
3727#endif
3728
3729 result = Qnil;
3730 if (geometry & XValue)
3731 {
3732 Lisp_Object element;
3733
3734 if (x >= 0 && (geometry & XNegative))
3735 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3736 else if (x < 0 && ! (geometry & XNegative))
3737 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3738 else
3739 element = Fcons (Qleft, make_number (x));
3740 result = Fcons (element, result);
3741 }
3742
3743 if (geometry & YValue)
3744 {
3745 Lisp_Object element;
3746
3747 if (y >= 0 && (geometry & YNegative))
3748 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3749 else if (y < 0 && ! (geometry & YNegative))
3750 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3751 else
3752 element = Fcons (Qtop, make_number (y));
3753 result = Fcons (element, result);
3754 }
3755
3756 if (geometry & WidthValue)
3757 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3758 if (geometry & HeightValue)
3759 result = Fcons (Fcons (Qheight, make_number (height)), result);
3760
3761 return result;
3762}
3763
3764/* Calculate the desired size and position of frame F.
3765 Return the flags saying which aspects were specified.
3766
3767 Also set the win_gravity and size_hint_flags of F.
3768
3769 Adjust height for toolbar if TOOLBAR_P is 1.
3770
3771 This function does not make the coordinates positive. */
3772
3773#define DEFAULT_ROWS 40
3774#define DEFAULT_COLS 80
3775
3776int
3777x_figure_window_size (f, parms, toolbar_p)
3778 struct frame *f;
3779 Lisp_Object parms;
3780 int toolbar_p;
3781{
3782 register Lisp_Object tem0, tem1, tem2;
3783 long window_prompting = 0;
3784 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3785
3786 /* Default values if we fall through.
3787 Actually, if that happens we should get
3788 window manager prompting. */
5af5757b
KS
3789 SET_FRAME_COLS (f, DEFAULT_COLS);
3790 FRAME_LINES (f) = DEFAULT_ROWS;
972f4259
KS
3791 /* Window managers expect that if program-specified
3792 positions are not (0,0), they're intentional, not defaults. */
5af5757b
KS
3793 f->top_pos = 0;
3794 f->left_pos = 0;
972f4259 3795
5af5757b 3796 /* Ensure that old new_text_cols and new_text_lines will not override the
972f4259
KS
3797 values set here. */
3798 /* ++KFS: This was specific to W32, but seems ok for all platforms */
5af5757b 3799 f->new_text_cols = f->new_text_lines = 0;
972f4259
KS
3800
3801 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
3802 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
3803 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
3804 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3805 {
3806 if (!EQ (tem0, Qunbound))
3807 {
3808 CHECK_NUMBER (tem0);
5af5757b 3809 FRAME_LINES (f) = XINT (tem0);
972f4259
KS
3810 }
3811 if (!EQ (tem1, Qunbound))
3812 {
3813 CHECK_NUMBER (tem1);
5af5757b 3814 SET_FRAME_COLS (f, XINT (tem1));
972f4259
KS
3815 }
3816 if (!NILP (tem2) && !EQ (tem2, Qunbound))
3817 window_prompting |= USSize;
3818 else
3819 window_prompting |= PSize;
3820 }
3821
5af5757b
KS
3822 f->scroll_bar_actual_width
3823 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
972f4259
KS
3824
3825 /* This used to be done _before_ calling x_figure_window_size, but
3826 since the height is reset here, this was really a no-op. I
3827 assume that moving it here does what Gerd intended (although he
3828 no longer can remember what that was... ++KFS, 2003-03-25. */
3829
3830 /* Add the tool-bar height to the initial frame height so that the
3831 user gets a text display area of the size he specified with -g or
3832 via .Xdefaults. Later changes of the tool-bar height don't
3833 change the frame size. This is done so that users can create
3834 tall Emacs frames without having to guess how tall the tool-bar
3835 will get. */
3836 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
3837 {
3838 int margin, relief, bar_height;
3839
3840 relief = (tool_bar_button_relief >= 0
3841 ? tool_bar_button_relief
3842 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
3843
3844 if (INTEGERP (Vtool_bar_button_margin)
3845 && XINT (Vtool_bar_button_margin) > 0)
3846 margin = XFASTINT (Vtool_bar_button_margin);
3847 else if (CONSP (Vtool_bar_button_margin)
3848 && INTEGERP (XCDR (Vtool_bar_button_margin))
3849 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
3850 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
3851 else
3852 margin = 0;
3853
3854 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
5af5757b 3855 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
972f4259
KS
3856 }
3857
3858 compute_fringe_widths (f, 0);
3859
5af5757b
KS
3860 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
3861 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
972f4259
KS
3862
3863 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
3864 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
3865 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
3866 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3867 {
3868 if (EQ (tem0, Qminus))
3869 {
5af5757b 3870 f->top_pos = 0;
972f4259
KS
3871 window_prompting |= YNegative;
3872 }
3873 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
3874 && CONSP (XCDR (tem0))
3875 && INTEGERP (XCAR (XCDR (tem0))))
3876 {
5af5757b 3877 f->top_pos = - XINT (XCAR (XCDR (tem0)));
972f4259
KS
3878 window_prompting |= YNegative;
3879 }
3880 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
3881 && CONSP (XCDR (tem0))
3882 && INTEGERP (XCAR (XCDR (tem0))))
3883 {
5af5757b 3884 f->top_pos = XINT (XCAR (XCDR (tem0)));
972f4259
KS
3885 }
3886 else if (EQ (tem0, Qunbound))
5af5757b 3887 f->top_pos = 0;
972f4259
KS
3888 else
3889 {
3890 CHECK_NUMBER (tem0);
5af5757b
KS
3891 f->top_pos = XINT (tem0);
3892 if (f->top_pos < 0)
972f4259
KS
3893 window_prompting |= YNegative;
3894 }
3895
3896 if (EQ (tem1, Qminus))
3897 {
5af5757b 3898 f->left_pos = 0;
972f4259
KS
3899 window_prompting |= XNegative;
3900 }
3901 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
3902 && CONSP (XCDR (tem1))
3903 && INTEGERP (XCAR (XCDR (tem1))))
3904 {
5af5757b 3905 f->left_pos = - XINT (XCAR (XCDR (tem1)));
972f4259
KS
3906 window_prompting |= XNegative;
3907 }
3908 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
3909 && CONSP (XCDR (tem1))
3910 && INTEGERP (XCAR (XCDR (tem1))))
3911 {
5af5757b 3912 f->left_pos = XINT (XCAR (XCDR (tem1)));
972f4259
KS
3913 }
3914 else if (EQ (tem1, Qunbound))
5af5757b 3915 f->left_pos = 0;
972f4259
KS
3916 else
3917 {
3918 CHECK_NUMBER (tem1);
5af5757b
KS
3919 f->left_pos = XINT (tem1);
3920 if (f->left_pos < 0)
972f4259
KS
3921 window_prompting |= XNegative;
3922 }
3923
3924 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
3925 window_prompting |= USPosition;
3926 else
3927 window_prompting |= PPosition;
3928 }
3929
5af5757b 3930 if (f->want_fullscreen != FULLSCREEN_NONE)
972f4259
KS
3931 {
3932 int left, top;
3933 int width, height;
3934
3935 /* It takes both for some WM:s to place it where we want */
3936 window_prompting = USPosition | PPosition;
3937 x_fullscreen_adjust (f, &width, &height, &top, &left);
5af5757b
KS
3938 FRAME_COLS (f) = width;
3939 FRAME_LINES (f) = height;
3940 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
3941 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
3942 f->left_pos = left;
3943 f->top_pos = top;
972f4259
KS
3944 }
3945
3946 if (window_prompting & XNegative)
3947 {
3948 if (window_prompting & YNegative)
5af5757b 3949 f->win_gravity = SouthEastGravity;
972f4259 3950 else
5af5757b 3951 f->win_gravity = NorthEastGravity;
972f4259
KS
3952 }
3953 else
3954 {
3955 if (window_prompting & YNegative)
5af5757b 3956 f->win_gravity = SouthWestGravity;
972f4259 3957 else
5af5757b 3958 f->win_gravity = NorthWestGravity;
972f4259
KS
3959 }
3960
5af5757b 3961 f->size_hint_flags = window_prompting;
972f4259
KS
3962
3963 return window_prompting;
3964}
3965
3966
3967
3968#endif /* HAVE_WINDOW_SYSTEM */
3969
3970
3971\f
3972/***********************************************************************
3973 Initialization
3974 ***********************************************************************/
3975
3976void
3977syms_of_frame ()
3978{
3979 Qframep = intern ("framep");
3980 staticpro (&Qframep);
3981 Qframe_live_p = intern ("frame-live-p");
3982 staticpro (&Qframe_live_p);
3983 Qheight = intern ("height");
3984 staticpro (&Qheight);
3985 Qicon = intern ("icon");
3986 staticpro (&Qicon);
3987 Qminibuffer = intern ("minibuffer");
3988 staticpro (&Qminibuffer);
3989 Qmodeline = intern ("modeline");
3990 staticpro (&Qmodeline);
3991 Qonly = intern ("only");
3992 staticpro (&Qonly);
3993 Qwidth = intern ("width");
3994 staticpro (&Qwidth);
3995 Qgeometry = intern ("geometry");
3996 staticpro (&Qgeometry);
3997 Qicon_left = intern ("icon-left");
3998 staticpro (&Qicon_left);
3999 Qicon_top = intern ("icon-top");
4000 staticpro (&Qicon_top);
4001 Qleft = intern ("left");
4002 staticpro (&Qleft);
4003 Qright = intern ("right");
4004 staticpro (&Qright);
4005 Quser_position = intern ("user-position");
4006 staticpro (&Quser_position);
4007 Quser_size = intern ("user-size");
4008 staticpro (&Quser_size);
4009 Qwindow_id = intern ("window-id");
4010 staticpro (&Qwindow_id);
4011#ifdef HAVE_X_WINDOWS
4012 Qouter_window_id = intern ("outer-window-id");
4013 staticpro (&Qouter_window_id);
4014#endif
4015 Qparent_id = intern ("parent-id");
4016 staticpro (&Qparent_id);
4017 Qx = intern ("x");
4018 staticpro (&Qx);
4019 Qw32 = intern ("w32");
4020 staticpro (&Qw32);
4021 Qpc = intern ("pc");
4022 staticpro (&Qpc);
4023 Qmac = intern ("mac");
4024 staticpro (&Qmac);
4025 Qvisible = intern ("visible");
4026 staticpro (&Qvisible);
4027 Qbuffer_predicate = intern ("buffer-predicate");
4028 staticpro (&Qbuffer_predicate);
4029 Qbuffer_list = intern ("buffer-list");
4030 staticpro (&Qbuffer_list);
4031 Qdisplay_type = intern ("display-type");
4032 staticpro (&Qdisplay_type);
4033 Qbackground_mode = intern ("background-mode");
4034 staticpro (&Qbackground_mode);
4035 Qtty_color_mode = intern ("tty-color-mode");
4036 staticpro (&Qtty_color_mode);
28d440ab
KL
4037 Qtty = intern ("tty");
4038 staticpro (&Qtty);
4039 Qtty_type = intern ("tty-type");
4040 staticpro (&Qtty_type);
972f4259
KS
4041
4042 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4043 staticpro (&Qface_set_after_frame_default);
4044
4045 Qfullwidth = intern ("fullwidth");
4046 staticpro (&Qfullwidth);
4047 Qfullheight = intern ("fullheight");
4048 staticpro (&Qfullheight);
4049 Qfullboth = intern ("fullboth");
4050 staticpro (&Qfullboth);
4051 Qx_resource_name = intern ("x-resource-name");
4052 staticpro (&Qx_resource_name);
4053
4054 Qx_frame_parameter = intern ("x-frame-parameter");
4055 staticpro (&Qx_frame_parameter);
4056
4057 {
4058 int i;
4059
4060 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4061 {
4062 Lisp_Object v = intern (frame_parms[i].name);
4063 if (frame_parms[i].variable)
4064 {
4065 *frame_parms[i].variable = v;
4066 staticpro (frame_parms[i].variable);
4067 }
4068 Fput (v, Qx_frame_parameter, make_number (i));
4069 }
4070 }
4071
2731a0ad 4072#ifdef HAVE_WINDOW_SYSTEM
972f4259
KS
4073 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4074 doc: /* The name Emacs uses to look up X resources.
4075`x-get-resource' uses this as the first component of the instance name
4076when requesting resource values.
4077Emacs initially sets `x-resource-name' to the name under which Emacs
4078was invoked, or to the value specified with the `-name' or `-rn'
4079switches, if present.
4080
4081It may be useful to bind this variable locally around a call
4082to `x-get-resource'. See also the variable `x-resource-class'. */);
4083 Vx_resource_name = Qnil;
4084
4085 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4086 doc: /* The class Emacs uses to look up X resources.
4087`x-get-resource' uses this as the first component of the instance class
4088when requesting resource values.
4089
4090Emacs initially sets `x-resource-class' to "Emacs".
4091
4092Setting this variable permanently is not a reasonable thing to do,
4093but binding this variable locally around a call to `x-get-resource'
4094is a reasonable practice. See also the variable `x-resource-name'. */);
4095 Vx_resource_class = build_string (EMACS_CLASS);
2731a0ad 4096#endif
972f4259
KS
4097
4098 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4099 doc: /* Alist of default values for frame creation.
4100These may be set in your init file, like this:
4101 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1))
4102These override values given in window system configuration data,
4103 including X Windows' defaults database.
4104For values specific to the first Emacs frame, see `initial-frame-alist'.
4105For values specific to the separate minibuffer frame, see
4106 `minibuffer-frame-alist'.
4107The `menu-bar-lines' element of the list controls whether new frames
4108 have menu bars; `menu-bar-mode' works by altering this element.
4109Setting this variable does not affect existing frames, only new ones. */);
4110 Vdefault_frame_alist = Qnil;
4111
a6e20602
KS
4112 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4113 doc: /* Default position of scroll bars on this window-system. */);
4114#ifdef HAVE_WINDOW_SYSTEM
4115#if defined(HAVE_NTGUI) || defined(HAVE_CARBON)
4116 /* MS-Windows has scroll bars on the right by default. */
4117 Vdefault_frame_scroll_bars = Qright;
4118#else
4119 Vdefault_frame_scroll_bars = Qleft;
4120#endif
4121#else
4122 Vdefault_frame_scroll_bars = Qnil;
4123#endif
4124
972f4259
KS
4125 Qinhibit_default_face_x_resources
4126 = intern ("inhibit-default-face-x-resources");
4127 staticpro (&Qinhibit_default_face_x_resources);
4128
972f4259
KS
4129 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4130 doc: /* Non-nil if all of emacs is iconified and frame updates are not needed. */);
4131 Vemacs_iconified = Qnil;
4132
4133 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4134 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4135`mouse-position' calls this function, passing its usual return value as
4136argument, and returns whatever this function returns.
4137This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4138which need to do mouse handling at the Lisp level. */);
4139 Vmouse_position_function = Qnil;
4140
4141 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4142 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4143If the value is an integer, highlighting is only shown after moving the
4144mouse, while keyboard input turns off the highlight even when the mouse
4145is over the clickable text. However, the mouse shape still indicates
4146when the mouse is over clickable text. */);
4147 Vmouse_highlight = Qt;
4148
4149 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4150 doc: /* Functions to be run before deleting a frame.
4151The functions are run with one arg, the frame to be deleted.
4152See `delete-frame'. */);
4153 Vdelete_frame_functions = Qnil;
4154
4155 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4156 doc: /* Minibufferless frames use this frame's minibuffer.
4157
4158Emacs cannot create minibufferless frames unless this is set to an
4159appropriate surrogate.
4160
4161Emacs consults this variable only when creating minibufferless
4162frames; once the frame is created, it sticks with its assigned
4163minibuffer, no matter what this variable is set to. This means that
4164this variable doesn't necessarily say anything meaningful about the
4165current set of frames, or where the minibuffer is currently being
4166displayed.
4167
4168This variable is local to the current terminal and cannot be buffer-local. */);
4169
4170 staticpro (&Vframe_list);
4171
4172 defsubr (&Sactive_minibuffer_window);
4173 defsubr (&Sframep);
4174 defsubr (&Sframe_live_p);
4175 defsubr (&Smake_terminal_frame);
4176 defsubr (&Shandle_switch_frame);
4177 defsubr (&Signore_event);
4178 defsubr (&Sselect_frame);
4179 defsubr (&Sselected_frame);
4180 defsubr (&Swindow_frame);
4181 defsubr (&Sframe_root_window);
4182 defsubr (&Sframe_first_window);
4183 defsubr (&Sframe_selected_window);
4184 defsubr (&Sset_frame_selected_window);
4185 defsubr (&Sframe_list);
4186 defsubr (&Snext_frame);
4187 defsubr (&Sprevious_frame);
4188 defsubr (&Sdelete_frame);
4189 defsubr (&Smouse_position);
4190 defsubr (&Smouse_pixel_position);
4191 defsubr (&Sset_mouse_position);
4192 defsubr (&Sset_mouse_pixel_position);
4193#if 0
4194 defsubr (&Sframe_configuration);
4195 defsubr (&Srestore_frame_configuration);
4196#endif
4197 defsubr (&Smake_frame_visible);
4198 defsubr (&Smake_frame_invisible);
4199 defsubr (&Siconify_frame);
4200 defsubr (&Sframe_visible_p);
4201 defsubr (&Svisible_frame_list);
4202 defsubr (&Sraise_frame);
4203 defsubr (&Slower_frame);
4204 defsubr (&Sredirect_frame_focus);
4205 defsubr (&Sframe_focus);
4206 defsubr (&Sframe_parameters);
4207 defsubr (&Sframe_parameter);
4208 defsubr (&Smodify_frame_parameters);
4209 defsubr (&Sframe_char_height);
4210 defsubr (&Sframe_char_width);
4211 defsubr (&Sframe_pixel_height);
4212 defsubr (&Sframe_pixel_width);
4213 defsubr (&Sset_frame_height);
4214 defsubr (&Sset_frame_width);
4215 defsubr (&Sset_frame_size);
4216 defsubr (&Sset_frame_position);
4217
4218#ifdef HAVE_WINDOW_SYSTEM
4219 defsubr (&Sx_get_resource);
4220 defsubr (&Sx_parse_geometry);
4221#endif
4222
dc6f92b8 4223}
ab5796a9
MB
4224
4225/* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4226 (do not change this comment) */