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