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