*** empty log message ***
[bpt/emacs.git] / src / frame.c
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000 Free Software Foundation.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include <config.h>
22
23 #include <stdio.h>
24 #include "lisp.h"
25 #include "charset.h"
26 #ifdef HAVE_X_WINDOWS
27 #include "xterm.h"
28 #endif
29 #ifdef WINDOWSNT
30 #include "w32term.h"
31 #endif
32 #include "buffer.h"
33 /* These help us bind and responding to switch-frame events. */
34 #include "commands.h"
35 #include "keyboard.h"
36 #include "frame.h"
37 #ifdef HAVE_WINDOW_SYSTEM
38 #include "fontset.h"
39 #endif
40 #include "termhooks.h"
41 #include "dispextern.h"
42 #include "window.h"
43 #ifdef MSDOS
44 #include "msdos.h"
45 #include "dosfns.h"
46 #endif
47
48 #ifdef macintosh
49 extern struct mac_output *NewMacWindow ();
50 extern void DisposeMacWindow (struct mac_output *);
51 #endif
52
53 /* Evaluate this expression to rebuild the section of syms_of_frame
54 that initializes and staticpros the symbols declared below. Note
55 that Emacs 18 has a bug that keeps C-x C-e from being able to
56 evaluate this expression.
57
58 (progn
59 ;; Accumulate a list of the symbols we want to initialize from the
60 ;; declarations at the top of the file.
61 (goto-char (point-min))
62 (search-forward "/\*&&& symbols declared here &&&*\/\n")
63 (let (symbol-list)
64 (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
65 (setq symbol-list
66 (cons (buffer-substring (match-beginning 1) (match-end 1))
67 symbol-list))
68 (forward-line 1))
69 (setq symbol-list (nreverse symbol-list))
70 ;; Delete the section of syms_of_... where we initialize the symbols.
71 (search-forward "\n /\*&&& init symbols here &&&*\/\n")
72 (let ((start (point)))
73 (while (looking-at "^ Q")
74 (forward-line 2))
75 (kill-region start (point)))
76 ;; Write a new symbol initialization section.
77 (while symbol-list
78 (insert (format " %s = intern (\"" (car symbol-list)))
79 (let ((start (point)))
80 (insert (substring (car symbol-list) 1))
81 (subst-char-in-region start (point) ?_ ?-))
82 (insert (format "\");\n staticpro (&%s);\n" (car symbol-list)))
83 (setq symbol-list (cdr symbol-list)))))
84 */
85
86 /*&&& symbols declared here &&&*/
87 Lisp_Object Qframep;
88 Lisp_Object Qframe_live_p;
89 Lisp_Object Qheight;
90 Lisp_Object Qicon;
91 Lisp_Object Qminibuffer;
92 Lisp_Object Qmodeline;
93 Lisp_Object Qname;
94 Lisp_Object Qonly;
95 Lisp_Object Qunsplittable;
96 Lisp_Object Qmenu_bar_lines;
97 Lisp_Object Qtool_bar_lines;
98 Lisp_Object Qwidth;
99 Lisp_Object Qx;
100 Lisp_Object Qw32;
101 Lisp_Object Qpc;
102 Lisp_Object Qmac;
103 Lisp_Object Qvisible;
104 Lisp_Object Qbuffer_predicate;
105 Lisp_Object Qbuffer_list;
106 Lisp_Object Qtitle;
107 Lisp_Object Qdisplay_type;
108 Lisp_Object Qbackground_mode;
109
110 Lisp_Object Vterminal_frame;
111 Lisp_Object Vdefault_frame_alist;
112 Lisp_Object Vmouse_position_function;
113
114 static void
115 syms_of_frame_1 ()
116 {
117 /*&&& init symbols here &&&*/
118 Qframep = intern ("framep");
119 staticpro (&Qframep);
120 Qframe_live_p = intern ("frame-live-p");
121 staticpro (&Qframe_live_p);
122 Qheight = intern ("height");
123 staticpro (&Qheight);
124 Qicon = intern ("icon");
125 staticpro (&Qicon);
126 Qminibuffer = intern ("minibuffer");
127 staticpro (&Qminibuffer);
128 Qmodeline = intern ("modeline");
129 staticpro (&Qmodeline);
130 Qname = intern ("name");
131 staticpro (&Qname);
132 Qonly = intern ("only");
133 staticpro (&Qonly);
134 Qunsplittable = intern ("unsplittable");
135 staticpro (&Qunsplittable);
136 Qmenu_bar_lines = intern ("menu-bar-lines");
137 staticpro (&Qmenu_bar_lines);
138 Qtool_bar_lines = intern ("tool-bar-lines");
139 staticpro (&Qtool_bar_lines);
140 Qwidth = intern ("width");
141 staticpro (&Qwidth);
142 Qx = intern ("x");
143 staticpro (&Qx);
144 Qw32 = intern ("w32");
145 staticpro (&Qw32);
146 Qpc = intern ("pc");
147 staticpro (&Qpc);
148 Qmac = intern ("mac");
149 staticpro (&Qmac);
150 Qvisible = intern ("visible");
151 staticpro (&Qvisible);
152 Qbuffer_predicate = intern ("buffer-predicate");
153 staticpro (&Qbuffer_predicate);
154 Qbuffer_list = intern ("buffer-list");
155 staticpro (&Qbuffer_list);
156 Qtitle = intern ("title");
157 staticpro (&Qtitle);
158 Qdisplay_type = intern ("display-type");
159 staticpro (&Qdisplay_type);
160 Qbackground_mode = intern ("background-mode");
161 staticpro (&Qbackground_mode);
162
163 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
164 "Alist of default values for frame creation.\n\
165 These may be set in your init file, like this:\n\
166 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1))\n\
167 These override values given in window system configuration data,\n\
168 including X Windows' defaults database.\n\
169 For values specific to the first Emacs frame, see `initial-frame-alist'.\n\
170 For values specific to the separate minibuffer frame, see\n\
171 `minibuffer-frame-alist'.\n\
172 The `menu-bar-lines' element of the list controls whether new frames\n\
173 have menu bars; `menu-bar-mode' works by altering this element.");
174 Vdefault_frame_alist = Qnil;
175 }
176 \f
177 static void
178 set_menu_bar_lines_1 (window, n)
179 Lisp_Object window;
180 int n;
181 {
182 struct window *w = XWINDOW (window);
183
184 XSETFASTINT (w->last_modified, 0);
185 XSETFASTINT (w->top, XFASTINT (w->top) + n);
186 XSETFASTINT (w->height, XFASTINT (w->height) - n);
187
188 if (INTEGERP (w->orig_top))
189 XSETFASTINT (w->orig_top, XFASTINT (w->orig_top) + n);
190 if (INTEGERP (w->orig_height))
191 XSETFASTINT (w->orig_height, XFASTINT (w->orig_height) - n);
192
193 /* Handle just the top child in a vertical split. */
194 if (!NILP (w->vchild))
195 set_menu_bar_lines_1 (w->vchild, n);
196
197 /* Adjust all children in a horizontal split. */
198 for (window = w->hchild; !NILP (window); window = w->next)
199 {
200 w = XWINDOW (window);
201 set_menu_bar_lines_1 (window, n);
202 }
203 }
204
205 void
206 set_menu_bar_lines (f, value, oldval)
207 struct frame *f;
208 Lisp_Object value, oldval;
209 {
210 int nlines;
211 int olines = FRAME_MENU_BAR_LINES (f);
212
213 /* Right now, menu bars don't work properly in minibuf-only frames;
214 most of the commands try to apply themselves to the minibuffer
215 frame itself, and get an error because you can't switch buffers
216 in or split the minibuffer window. */
217 if (FRAME_MINIBUF_ONLY_P (f))
218 return;
219
220 if (INTEGERP (value))
221 nlines = XINT (value);
222 else
223 nlines = 0;
224
225 if (nlines != olines)
226 {
227 windows_or_buffers_changed++;
228 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
229 FRAME_MENU_BAR_LINES (f) = nlines;
230 set_menu_bar_lines_1 (f->root_window, nlines - olines);
231 adjust_glyphs (f);
232 }
233 }
234 \f
235 Lisp_Object Vemacs_iconified;
236 Lisp_Object Vframe_list;
237
238 struct x_output tty_display;
239
240 extern Lisp_Object Vminibuffer_list;
241 extern Lisp_Object get_minibuffer ();
242 extern Lisp_Object Fhandle_switch_frame ();
243 extern Lisp_Object Fredirect_frame_focus ();
244 extern Lisp_Object x_get_focus_frame ();
245 \f
246 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
247 "Return non-nil if OBJECT is a frame.\n\
248 Value is t for a termcap frame (a character-only terminal),\n\
249 `x' for an Emacs frame that is really an X window,\n\
250 `w32' for an Emacs frame that is a window on MS-Windows display,\n\
251 `mac' for an Emacs frame on a Macintosh display,\n\
252 `pc' for a direct-write MS-DOS frame.\n\
253 See also `frame-live-p'.")
254 (object)
255 Lisp_Object object;
256 {
257 if (!FRAMEP (object))
258 return Qnil;
259 switch (XFRAME (object)->output_method)
260 {
261 case output_termcap:
262 return Qt;
263 case output_x_window:
264 return Qx;
265 case output_w32:
266 return Qw32;
267 case output_msdos_raw:
268 return Qpc;
269 case output_mac:
270 return Qmac;
271 default:
272 abort ();
273 }
274 }
275
276 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
277 "Return non-nil if OBJECT is a frame which has not been deleted.\n\
278 Value is nil if OBJECT is not a live frame. If object is a live\n\
279 frame, the return value indicates what sort of output device it is\n\
280 displayed on. Value is t for a termcap frame (a character-only\n\
281 terminal), `x' for an Emacs frame being displayed in an X window.")
282 (object)
283 Lisp_Object object;
284 {
285 return ((FRAMEP (object)
286 && FRAME_LIVE_P (XFRAME (object)))
287 ? Fframep (object)
288 : Qnil);
289 }
290
291 struct frame *
292 make_frame (mini_p)
293 int mini_p;
294 {
295 Lisp_Object frame;
296 register struct frame *f;
297 register Lisp_Object root_window;
298 register Lisp_Object mini_window;
299 register struct Lisp_Vector *vec;
300 int i;
301
302 vec = allocate_vectorlike ((EMACS_INT) VECSIZE (struct frame));
303 for (i = 0; i < VECSIZE (struct frame); i++)
304 XSETFASTINT (vec->contents[i], 0);
305 vec->size = VECSIZE (struct frame);
306 f = (struct frame *)vec;
307 XSETFRAME (frame, f);
308
309 f->desired_matrix = 0;
310 f->current_matrix = 0;
311 f->desired_pool = 0;
312 f->current_pool = 0;
313 f->glyphs_initialized_p = 0;
314 f->decode_mode_spec_buffer = 0;
315 f->visible = 0;
316 f->async_visible = 0;
317 f->output_data.nothing = 0;
318 f->iconified = 0;
319 f->async_iconified = 0;
320 f->wants_modeline = 1;
321 f->auto_raise = 0;
322 f->auto_lower = 0;
323 f->no_split = 0;
324 f->garbaged = 1;
325 f->has_minibuffer = mini_p;
326 f->focus_frame = Qnil;
327 f->explicit_name = 0;
328 f->can_have_scroll_bars = 0;
329 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
330 f->param_alist = Qnil;
331 f->scroll_bars = Qnil;
332 f->condemned_scroll_bars = Qnil;
333 f->face_alist = Qnil;
334 f->face_cache = NULL;
335 f->menu_bar_items = Qnil;
336 f->menu_bar_vector = Qnil;
337 f->menu_bar_items_used = 0;
338 f->buffer_predicate = Qnil;
339 f->buffer_list = Qnil;
340 #ifdef MULTI_KBOARD
341 f->kboard = initial_kboard;
342 #endif
343 f->namebuf = 0;
344 f->title = Qnil;
345 f->menu_bar_window = Qnil;
346 f->tool_bar_window = Qnil;
347 f->desired_tool_bar_items = f->current_tool_bar_items = Qnil;
348 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
349 f->n_desired_tool_bar_items = f->n_current_tool_bar_items = 0;
350
351 root_window = make_window ();
352 if (mini_p)
353 {
354 mini_window = make_window ();
355 XWINDOW (root_window)->next = mini_window;
356 XWINDOW (mini_window)->prev = root_window;
357 XWINDOW (mini_window)->mini_p = Qt;
358 XWINDOW (mini_window)->frame = frame;
359 f->minibuffer_window = mini_window;
360 }
361 else
362 {
363 mini_window = Qnil;
364 XWINDOW (root_window)->next = Qnil;
365 f->minibuffer_window = Qnil;
366 }
367
368 XWINDOW (root_window)->frame = frame;
369
370 /* 10 is arbitrary,
371 just so that there is "something there."
372 Correct size will be set up later with change_frame_size. */
373
374 SET_FRAME_WIDTH (f, 10);
375 f->height = 10;
376
377 XSETFASTINT (XWINDOW (root_window)->width, 10);
378 XSETFASTINT (XWINDOW (root_window)->height, (mini_p ? 9 : 10));
379
380 if (mini_p)
381 {
382 XSETFASTINT (XWINDOW (mini_window)->width, 10);
383 XSETFASTINT (XWINDOW (mini_window)->top, 9);
384 XSETFASTINT (XWINDOW (mini_window)->height, 1);
385 }
386
387 /* Choose a buffer for the frame's root window. */
388 {
389 Lisp_Object buf;
390
391 XWINDOW (root_window)->buffer = Qt;
392 buf = Fcurrent_buffer ();
393 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
394 a space), try to find another one. */
395 if (XSTRING (Fbuffer_name (buf))->data[0] == ' ')
396 buf = Fother_buffer (buf, Qnil, Qnil);
397
398 /* Use set_window_buffer, not Fset_window_buffer, and don't let
399 hooks be run by it. The reason is that the whole frame/window
400 arrangement is not yet fully intialized at this point. Windows
401 don't have the right size, glyph matrices aren't initialized
402 etc. Running Lisp functions at this point surely ends in a
403 SEGV. */
404 set_window_buffer (root_window, buf, 0);
405 f->buffer_list = Fcons (buf, Qnil);
406 }
407
408 if (mini_p)
409 {
410 XWINDOW (mini_window)->buffer = Qt;
411 set_window_buffer (mini_window,
412 (NILP (Vminibuffer_list)
413 ? get_minibuffer (0)
414 : Fcar (Vminibuffer_list)),
415 0);
416 }
417
418 f->root_window = root_window;
419 f->selected_window = root_window;
420 /* Make sure this window seems more recently used than
421 a newly-created, never-selected window. */
422 XSETFASTINT (XWINDOW (f->selected_window)->use_time, ++window_select_count);
423
424 return f;
425 }
426 \f
427 #ifdef HAVE_WINDOW_SYSTEM
428 /* Make a frame using a separate minibuffer window on another frame.
429 MINI_WINDOW is the minibuffer window to use. nil means use the
430 default (the global minibuffer). */
431
432 struct frame *
433 make_frame_without_minibuffer (mini_window, kb, display)
434 register Lisp_Object mini_window;
435 KBOARD *kb;
436 Lisp_Object display;
437 {
438 register struct frame *f;
439 struct gcpro gcpro1;
440
441 if (!NILP (mini_window))
442 CHECK_LIVE_WINDOW (mini_window, 0);
443
444 #ifdef MULTI_KBOARD
445 if (!NILP (mini_window)
446 && XFRAME (XWINDOW (mini_window)->frame)->kboard != kb)
447 error ("frame and minibuffer must be on the same display");
448 #endif
449
450 /* Make a frame containing just a root window. */
451 f = make_frame (0);
452
453 if (NILP (mini_window))
454 {
455 /* Use default-minibuffer-frame if possible. */
456 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
457 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
458 {
459 Lisp_Object frame_dummy;
460
461 XSETFRAME (frame_dummy, f);
462 GCPRO1 (frame_dummy);
463 /* If there's no minibuffer frame to use, create one. */
464 kb->Vdefault_minibuffer_frame =
465 call1 (intern ("make-initial-minibuffer-frame"), display);
466 UNGCPRO;
467 }
468
469 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
470 }
471
472 f->minibuffer_window = mini_window;
473
474 /* Make the chosen minibuffer window display the proper minibuffer,
475 unless it is already showing a minibuffer. */
476 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
477 Fset_window_buffer (mini_window,
478 (NILP (Vminibuffer_list)
479 ? get_minibuffer (0)
480 : Fcar (Vminibuffer_list)));
481 return f;
482 }
483
484 /* Make a frame containing only a minibuffer window. */
485
486 struct frame *
487 make_minibuffer_frame ()
488 {
489 /* First make a frame containing just a root window, no minibuffer. */
490
491 register struct frame *f = make_frame (0);
492 register Lisp_Object mini_window;
493 register Lisp_Object frame;
494
495 XSETFRAME (frame, f);
496
497 f->auto_raise = 0;
498 f->auto_lower = 0;
499 f->no_split = 1;
500 f->wants_modeline = 0;
501 f->has_minibuffer = 1;
502
503 /* Now label the root window as also being the minibuffer.
504 Avoid infinite looping on the window chain by marking next pointer
505 as nil. */
506
507 mini_window = f->minibuffer_window = f->root_window;
508 XWINDOW (mini_window)->mini_p = Qt;
509 XWINDOW (mini_window)->next = Qnil;
510 XWINDOW (mini_window)->prev = Qnil;
511 XWINDOW (mini_window)->frame = frame;
512
513 /* Put the proper buffer in that window. */
514
515 Fset_window_buffer (mini_window,
516 (NILP (Vminibuffer_list)
517 ? get_minibuffer (0)
518 : Fcar (Vminibuffer_list)));
519 return f;
520 }
521 #endif /* HAVE_WINDOW_SYSTEM */
522 \f
523 /* Construct a frame that refers to the terminal (stdin and stdout). */
524
525 static int terminal_frame_count;
526
527 struct frame *
528 make_terminal_frame ()
529 {
530 register struct frame *f;
531 Lisp_Object frame;
532 char name[20];
533
534 #ifdef MULTI_KBOARD
535 if (!initial_kboard)
536 {
537 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
538 init_kboard (initial_kboard);
539 initial_kboard->next_kboard = all_kboards;
540 all_kboards = initial_kboard;
541 }
542 #endif
543
544 /* The first call must initialize Vframe_list. */
545 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
546 Vframe_list = Qnil;
547
548 f = make_frame (1);
549
550 XSETFRAME (frame, f);
551 Vframe_list = Fcons (frame, Vframe_list);
552
553 terminal_frame_count++;
554 sprintf (name, "F%d", terminal_frame_count);
555 f->name = build_string (name);
556
557 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
558 f->async_visible = 1; /* Don't let visible be cleared later. */
559 #ifdef MSDOS
560 f->output_data.x = &the_only_x_display;
561 if (!inhibit_window_system
562 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
563 || XFRAME (selected_frame)->output_method == output_msdos_raw))
564 {
565 f->output_method = output_msdos_raw;
566 /* This initialization of foreground and background pixels is
567 only important for the initial frame created in temacs. If
568 we don't do that, we get black background and foreground in
569 the dumped Emacs because the_only_x_display is a static
570 variable, hence it is born all-zeroes, and zero is the code
571 for the black color. Other frames all inherit their pixels
572 from what's already in the_only_x_display. */
573 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
574 && f->output_data.x->background_pixel == 0
575 && f->output_data.x->foreground_pixel == 0)
576 {
577 f->output_data.x->background_pixel = FACE_TTY_DEFAULT_BG_COLOR;
578 f->output_data.x->foreground_pixel = FACE_TTY_DEFAULT_FG_COLOR;
579 }
580 }
581 else
582 f->output_method = output_termcap;
583 #else
584 #ifdef macintosh
585 f->output_data.mac = NewMacWindow(f);
586 f->output_data.mac->background_pixel = 0xffffff;
587 f->output_data.mac->foreground_pixel = 0;
588 f->output_data.mac->n_param_faces = 0;
589 f->output_data.mac->n_computed_faces = 0;
590 f->output_data.mac->size_computed_faces = 0;
591 f->output_method = output_mac;
592 f->auto_raise = 1;
593 f->auto_lower = 1;
594 init_frame_faces (f);
595 #else /* !macintosh */
596 f->output_data.x = &tty_display;
597 #endif /* !macintosh */
598 #endif /* MSDOS */
599
600 #ifndef macintosh
601 if (!noninteractive)
602 init_frame_faces (f);
603 #endif
604 return f;
605 }
606
607 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
608 1, 1, 0, "Create an additional terminal frame.\n\
609 You can create multiple frames on a text-only terminal in this way.\n\
610 Only the selected terminal frame is actually displayed.\n\
611 This function takes one argument, an alist specifying frame parameters.\n\
612 In practice, generally you don't need to specify any parameters.\n\
613 Note that changing the size of one terminal frame automatically affects all.")
614 (parms)
615 Lisp_Object parms;
616 {
617 struct frame *f;
618 Lisp_Object frame, tem;
619 struct frame *sf = SELECTED_FRAME ();
620
621 #ifdef MSDOS
622 if (sf->output_method != output_msdos_raw
623 && sf->output_method != output_termcap)
624 abort ();
625 #else /* not MSDOS */
626
627 #ifdef macintosh
628 if (sf->output_method != output_mac)
629 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
630 #else
631 if (sf->output_method != output_termcap)
632 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
633 #endif
634 #endif /* not MSDOS */
635
636 f = make_terminal_frame ();
637
638 change_frame_size (f, FRAME_HEIGHT (sf),
639 FRAME_WIDTH (sf), 0, 0, 0);
640 adjust_glyphs (f);
641 calculate_costs (f);
642 XSETFRAME (frame, f);
643 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
644 Fmodify_frame_parameters (frame, parms);
645
646 /* Make the frame face alist be frame-specific, so that each
647 frame could change its face definitions independently. */
648 f->face_alist = Fcopy_alist (sf->face_alist);
649 /* Simple Fcopy_alist isn't enough, because we need the contents of
650 the vectors which are the CDRs of associations in face_alist to
651 be copied as well. */
652 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
653 XCDR (XCAR (tem)) = Fcopy_sequence (XCDR (XCAR (tem)));
654 return frame;
655 }
656 \f
657 Lisp_Object
658 do_switch_frame (frame, no_enter, track)
659 Lisp_Object frame, no_enter;
660 int track;
661 {
662 struct frame *sf = SELECTED_FRAME ();
663
664 /* If FRAME is a switch-frame event, extract the frame we should
665 switch to. */
666 if (CONSP (frame)
667 && EQ (XCAR (frame), Qswitch_frame)
668 && CONSP (XCDR (frame)))
669 frame = XCAR (XCDR (frame));
670
671 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
672 a switch-frame event to arrive after a frame is no longer live,
673 especially when deleting the initial frame during startup. */
674 CHECK_FRAME (frame, 0);
675 if (! FRAME_LIVE_P (XFRAME (frame)))
676 return Qnil;
677
678 if (sf == XFRAME (frame))
679 return frame;
680
681 /* This is too greedy; it causes inappropriate focus redirection
682 that's hard to get rid of. */
683 #if 0
684 /* If a frame's focus has been redirected toward the currently
685 selected frame, we should change the redirection to point to the
686 newly selected frame. This means that if the focus is redirected
687 from a minibufferless frame to a surrogate minibuffer frame, we
688 can use `other-window' to switch between all the frames using
689 that minibuffer frame, and the focus redirection will follow us
690 around. */
691 if (track)
692 {
693 Lisp_Object tail;
694
695 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
696 {
697 Lisp_Object focus;
698
699 if (!FRAMEP (XCAR (tail)))
700 abort ();
701
702 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
703
704 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
705 Fredirect_frame_focus (XCAR (tail), frame);
706 }
707 }
708 #else /* ! 0 */
709 /* Instead, apply it only to the frame we're pointing to. */
710 #ifdef HAVE_WINDOW_SYSTEM
711 if (track && (FRAME_WINDOW_P (XFRAME (frame))))
712 {
713 Lisp_Object focus, xfocus;
714
715 xfocus = x_get_focus_frame (XFRAME (frame));
716 if (FRAMEP (xfocus))
717 {
718 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
719 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
720 Fredirect_frame_focus (xfocus, frame);
721 }
722 }
723 #endif /* HAVE_X_WINDOWS */
724 #endif /* ! 0 */
725
726 selected_frame = frame;
727 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
728 last_nonminibuf_frame = XFRAME (selected_frame);
729
730 Fselect_window (XFRAME (frame)->selected_window);
731
732 /* We want to make sure that the next event generates a frame-switch
733 event to the appropriate frame. This seems kludgy to me, but
734 before you take it out, make sure that evaluating something like
735 (select-window (frame-root-window (new-frame))) doesn't end up
736 with your typing being interpreted in the new frame instead of
737 the one you're actually typing in. */
738 internal_last_event_frame = Qnil;
739
740 return frame;
741 }
742
743 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
744 "Select the frame FRAME.\n\
745 Subsequent editing commands apply to its selected window.\n\
746 The selection of FRAME lasts until the next time the user does\n\
747 something to select a different frame, or until the next time this\n\
748 function is called.")
749 (frame, no_enter)
750 Lisp_Object frame, no_enter;
751 {
752 return do_switch_frame (frame, no_enter, 1);
753 }
754
755
756 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 2, "e",
757 "Handle a switch-frame event EVENT.\n\
758 Switch-frame events are usually bound to this function.\n\
759 A switch-frame event tells Emacs that the window manager has requested\n\
760 that the user's events be directed to the frame mentioned in the event.\n\
761 This function selects the selected window of the frame of EVENT.\n\
762 \n\
763 If EVENT is frame object, handle it as if it were a switch-frame event\n\
764 to that frame.")
765 (event, no_enter)
766 Lisp_Object event, no_enter;
767 {
768 /* Preserve prefix arg that the command loop just cleared. */
769 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
770 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
771 return do_switch_frame (event, no_enter, 0);
772 }
773
774 DEFUN ("ignore-event", Fignore_event, Signore_event, 0, 0, "",
775 "Do nothing, but preserve any prefix argument already specified.\n\
776 This is a suitable binding for iconify-frame and make-frame-visible.")
777 ()
778 {
779 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
780 return Qnil;
781 }
782
783 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
784 "Return the frame that is now selected.")
785 ()
786 {
787 return selected_frame;
788 }
789 \f
790 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
791 "Return the frame object that window WINDOW is on.")
792 (window)
793 Lisp_Object window;
794 {
795 CHECK_LIVE_WINDOW (window, 0);
796 return XWINDOW (window)->frame;
797 }
798
799 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
800 "Returns the topmost, leftmost window of FRAME.\n\
801 If omitted, FRAME defaults to the currently selected frame.")
802 (frame)
803 Lisp_Object frame;
804 {
805 Lisp_Object w;
806
807 if (NILP (frame))
808 w = SELECTED_FRAME ()->root_window;
809 else
810 {
811 CHECK_LIVE_FRAME (frame, 0);
812 w = XFRAME (frame)->root_window;
813 }
814 while (NILP (XWINDOW (w)->buffer))
815 {
816 if (! NILP (XWINDOW (w)->hchild))
817 w = XWINDOW (w)->hchild;
818 else if (! NILP (XWINDOW (w)->vchild))
819 w = XWINDOW (w)->vchild;
820 else
821 abort ();
822 }
823 return w;
824 }
825
826 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
827 Sactive_minibuffer_window, 0, 0, 0,
828 "Return the currently active minibuffer window, or nil if none.")
829 ()
830 {
831 return minibuf_level ? minibuf_window : Qnil;
832 }
833
834 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
835 "Returns the root-window of FRAME.\n\
836 If omitted, FRAME defaults to the currently selected frame.")
837 (frame)
838 Lisp_Object frame;
839 {
840 Lisp_Object window;
841
842 if (NILP (frame))
843 window = SELECTED_FRAME ()->root_window;
844 else
845 {
846 CHECK_LIVE_FRAME (frame, 0);
847 window = XFRAME (frame)->root_window;
848 }
849
850 return window;
851 }
852
853 DEFUN ("frame-selected-window", Fframe_selected_window,
854 Sframe_selected_window, 0, 1, 0,
855 "Return the selected window of frame object FRAME.\n\
856 If omitted, FRAME defaults to the currently selected frame.")
857 (frame)
858 Lisp_Object frame;
859 {
860 Lisp_Object window;
861
862 if (NILP (frame))
863 window = SELECTED_FRAME ()->selected_window;
864 else
865 {
866 CHECK_LIVE_FRAME (frame, 0);
867 window = XFRAME (frame)->selected_window;
868 }
869
870 return window;
871 }
872
873 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
874 Sset_frame_selected_window, 2, 2, 0,
875 "Set the selected window of frame object FRAME to WINDOW.\n\
876 If FRAME is nil, the selected frame is used.\n\
877 If FRAME is the selected frame, this makes WINDOW the selected window.")
878 (frame, window)
879 Lisp_Object frame, window;
880 {
881 if (NILP (frame))
882 frame = selected_frame;
883
884 CHECK_LIVE_FRAME (frame, 0);
885 CHECK_LIVE_WINDOW (window, 1);
886
887 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
888 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
889
890 if (EQ (frame, selected_frame))
891 return Fselect_window (window);
892
893 return XFRAME (frame)->selected_window = window;
894 }
895 \f
896 DEFUN ("frame-list", Fframe_list, Sframe_list,
897 0, 0, 0,
898 "Return a list of all frames.")
899 ()
900 {
901 return Fcopy_sequence (Vframe_list);
902 }
903
904 /* Return the next frame in the frame list after FRAME.
905 If MINIBUF is nil, exclude minibuffer-only frames.
906 If MINIBUF is a window, include only its own frame
907 and any frame now using that window as the minibuffer.
908 If MINIBUF is `visible', include all visible frames.
909 If MINIBUF is 0, include all visible and iconified frames.
910 Otherwise, include all frames. */
911
912 Lisp_Object
913 next_frame (frame, minibuf)
914 Lisp_Object frame;
915 Lisp_Object minibuf;
916 {
917 Lisp_Object tail;
918 int passed = 0;
919
920 /* There must always be at least one frame in Vframe_list. */
921 if (! CONSP (Vframe_list))
922 abort ();
923
924 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
925 forever. Forestall that. */
926 CHECK_LIVE_FRAME (frame, 0);
927
928 while (1)
929 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
930 {
931 Lisp_Object f;
932
933 f = XCAR (tail);
934
935 if (passed
936 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
937 {
938 /* Decide whether this frame is eligible to be returned. */
939
940 /* If we've looped all the way around without finding any
941 eligible frames, return the original frame. */
942 if (EQ (f, frame))
943 return f;
944
945 /* Let minibuf decide if this frame is acceptable. */
946 if (NILP (minibuf))
947 {
948 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
949 return f;
950 }
951 else if (EQ (minibuf, Qvisible))
952 {
953 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
954 if (FRAME_VISIBLE_P (XFRAME (f)))
955 return f;
956 }
957 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
958 {
959 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
960 if (FRAME_VISIBLE_P (XFRAME (f))
961 || FRAME_ICONIFIED_P (XFRAME (f)))
962 return f;
963 }
964 else if (WINDOWP (minibuf))
965 {
966 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
967 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
968 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
969 FRAME_FOCUS_FRAME (XFRAME (f))))
970 return f;
971 }
972 else
973 return f;
974 }
975
976 if (EQ (frame, f))
977 passed++;
978 }
979 }
980
981 /* Return the previous frame in the frame list before FRAME.
982 If MINIBUF is nil, exclude minibuffer-only frames.
983 If MINIBUF is a window, include only its own frame
984 and any frame now using that window as the minibuffer.
985 If MINIBUF is `visible', include all visible frames.
986 If MINIBUF is 0, include all visible and iconified frames.
987 Otherwise, include all frames. */
988
989 Lisp_Object
990 prev_frame (frame, minibuf)
991 Lisp_Object frame;
992 Lisp_Object minibuf;
993 {
994 Lisp_Object tail;
995 Lisp_Object prev;
996
997 /* There must always be at least one frame in Vframe_list. */
998 if (! CONSP (Vframe_list))
999 abort ();
1000
1001 prev = Qnil;
1002 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1003 {
1004 Lisp_Object f;
1005
1006 f = XCAR (tail);
1007 if (!FRAMEP (f))
1008 abort ();
1009
1010 if (EQ (frame, f) && !NILP (prev))
1011 return prev;
1012
1013 if (FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1014 {
1015 /* Decide whether this frame is eligible to be returned,
1016 according to minibuf. */
1017 if (NILP (minibuf))
1018 {
1019 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1020 prev = f;
1021 }
1022 else if (WINDOWP (minibuf))
1023 {
1024 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1025 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1026 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1027 FRAME_FOCUS_FRAME (XFRAME (f))))
1028 prev = f;
1029 }
1030 else if (EQ (minibuf, Qvisible))
1031 {
1032 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1033 if (FRAME_VISIBLE_P (XFRAME (f)))
1034 prev = f;
1035 }
1036 else if (XFASTINT (minibuf) == 0)
1037 {
1038 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1039 if (FRAME_VISIBLE_P (XFRAME (f))
1040 || FRAME_ICONIFIED_P (XFRAME (f)))
1041 prev = f;
1042 }
1043 else
1044 prev = f;
1045 }
1046 }
1047
1048 /* We've scanned the entire list. */
1049 if (NILP (prev))
1050 /* We went through the whole frame list without finding a single
1051 acceptable frame. Return the original frame. */
1052 return frame;
1053 else
1054 /* There were no acceptable frames in the list before FRAME; otherwise,
1055 we would have returned directly from the loop. Since PREV is the last
1056 acceptable frame in the list, return it. */
1057 return prev;
1058 }
1059
1060
1061 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1062 "Return the next frame in the frame list after FRAME.\n\
1063 It considers only frames on the same terminal as FRAME.\n\
1064 By default, skip minibuffer-only frames.\n\
1065 If omitted, FRAME defaults to the selected frame.\n\
1066 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.\n\
1067 If MINIFRAME is a window, include only its own frame\n\
1068 and any frame now using that window as the minibuffer.\n\
1069 If MINIFRAME is `visible', include all visible frames.\n\
1070 If MINIFRAME is 0, include all visible and iconified frames.\n\
1071 Otherwise, include all frames.")
1072 (frame, miniframe)
1073 Lisp_Object frame, miniframe;
1074 {
1075 if (NILP (frame))
1076 frame = selected_frame;
1077
1078 CHECK_LIVE_FRAME (frame, 0);
1079 return next_frame (frame, miniframe);
1080 }
1081
1082 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1083 "Return the previous frame in the frame list before FRAME.\n\
1084 It considers only frames on the same terminal as FRAME.\n\
1085 By default, skip minibuffer-only frames.\n\
1086 If omitted, FRAME defaults to the selected frame.\n\
1087 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.\n\
1088 If MINIFRAME is a window, include only its own frame\n\
1089 and any frame now using that window as the minibuffer.\n\
1090 If MINIFRAME is `visible', include all visible frames.\n\
1091 If MINIFRAME is 0, include all visible and iconified frames.\n\
1092 Otherwise, include all frames.")
1093 (frame, miniframe)
1094 Lisp_Object frame, miniframe;
1095 {
1096 if (NILP (frame))
1097 frame = selected_frame;
1098 CHECK_LIVE_FRAME (frame, 0);
1099 return prev_frame (frame, miniframe);
1100 }
1101 \f
1102 /* Return 1 if it is ok to delete frame F;
1103 0 if all frames aside from F are invisible.
1104 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1105
1106 int
1107 other_visible_frames (f)
1108 FRAME_PTR f;
1109 {
1110 /* We know the selected frame is visible,
1111 so if F is some other frame, it can't be the sole visible one. */
1112 if (f == SELECTED_FRAME ())
1113 {
1114 Lisp_Object frames;
1115 int count = 0;
1116
1117 for (frames = Vframe_list;
1118 CONSP (frames);
1119 frames = XCDR (frames))
1120 {
1121 Lisp_Object this;
1122
1123 this = XCAR (frames);
1124 /* Verify that the frame's window still exists
1125 and we can still talk to it. And note any recent change
1126 in visibility. */
1127 #ifdef HAVE_WINDOW_SYSTEM
1128 if (FRAME_WINDOW_P (XFRAME (this)))
1129 {
1130 x_sync (XFRAME (this));
1131 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1132 }
1133 #endif
1134
1135 if (FRAME_VISIBLE_P (XFRAME (this))
1136 || FRAME_ICONIFIED_P (XFRAME (this))
1137 /* Allow deleting the terminal frame when at least
1138 one X frame exists! */
1139 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1140 count++;
1141 }
1142 return count > 1;
1143 }
1144 return 1;
1145 }
1146
1147 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1148 "Delete FRAME, permanently eliminating it from use.\n\
1149 If omitted, FRAME defaults to the selected frame.\n\
1150 A frame may not be deleted if its minibuffer is used by other frames.\n\
1151 Normally, you may not delete a frame if all other frames are invisible,\n\
1152 but if the second optional argument FORCE is non-nil, you may do so.")
1153 (frame, force)
1154 Lisp_Object frame, force;
1155 {
1156 struct frame *f;
1157 struct frame *sf = SELECTED_FRAME ();
1158 int minibuffer_selected;
1159
1160 if (EQ (frame, Qnil))
1161 {
1162 f = sf;
1163 XSETFRAME (frame, f);
1164 }
1165 else
1166 {
1167 CHECK_FRAME (frame, 0);
1168 f = XFRAME (frame);
1169 }
1170
1171 if (! FRAME_LIVE_P (f))
1172 return Qnil;
1173
1174 if (NILP (force) && !other_visible_frames (f))
1175 error ("Attempt to delete the sole visible or iconified frame");
1176
1177 #if 0
1178 /* This is a nice idea, but x_connection_closed needs to be able
1179 to delete the last frame, if it is gone. */
1180 if (NILP (XCDR (Vframe_list)))
1181 error ("Attempt to delete the only frame");
1182 #endif
1183
1184 /* Does this frame have a minibuffer, and is it the surrogate
1185 minibuffer for any other frame? */
1186 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1187 {
1188 Lisp_Object frames;
1189
1190 for (frames = Vframe_list;
1191 CONSP (frames);
1192 frames = XCDR (frames))
1193 {
1194 Lisp_Object this;
1195 this = XCAR (frames);
1196
1197 if (! EQ (this, frame)
1198 && EQ (frame,
1199 WINDOW_FRAME (XWINDOW
1200 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1201 error ("Attempt to delete a surrogate minibuffer frame");
1202 }
1203 }
1204
1205 minibuffer_selected = EQ (minibuf_window, selected_window);
1206
1207 /* Don't let the frame remain selected. */
1208 if (f == sf)
1209 {
1210 Lisp_Object tail, frame1;
1211
1212 /* Look for another visible frame on the same terminal. */
1213 frame1 = next_frame (frame, Qvisible);
1214
1215 /* If there is none, find *some* other frame. */
1216 if (NILP (frame1) || EQ (frame1, frame))
1217 {
1218 FOR_EACH_FRAME (tail, frame1)
1219 {
1220 if (! EQ (frame, frame1))
1221 break;
1222 }
1223 }
1224
1225 do_switch_frame (frame1, Qnil, 0);
1226 sf = SELECTED_FRAME ();
1227 }
1228
1229 /* Don't allow minibuf_window to remain on a deleted frame. */
1230 if (EQ (f->minibuffer_window, minibuf_window))
1231 {
1232 Fset_window_buffer (sf->minibuffer_window,
1233 XWINDOW (minibuf_window)->buffer);
1234 minibuf_window = sf->minibuffer_window;
1235
1236 /* If the dying minibuffer window was selected,
1237 select the new one. */
1238 if (minibuffer_selected)
1239 Fselect_window (minibuf_window);
1240 }
1241
1242 /* Don't let echo_area_window to remain on a deleted frame. */
1243 if (EQ (f->minibuffer_window, echo_area_window))
1244 echo_area_window = sf->minibuffer_window;
1245
1246 /* Clear any X selections for this frame. */
1247 #ifdef HAVE_X_WINDOWS
1248 if (FRAME_X_P (f))
1249 x_clear_frame_selections (f);
1250 #endif
1251
1252 /* Free glyphs.
1253 This function must be called before the window tree of the
1254 frame is deleted because windows contain dynamically allocated
1255 memory. */
1256 free_glyphs (f);
1257
1258 /* Mark all the windows that used to be on FRAME as deleted, and then
1259 remove the reference to them. */
1260 delete_all_subwindows (XWINDOW (f->root_window));
1261 f->root_window = Qnil;
1262
1263 Vframe_list = Fdelq (frame, Vframe_list);
1264 FRAME_SET_VISIBLE (f, 0);
1265
1266 if (f->namebuf)
1267 xfree (f->namebuf);
1268 if (FRAME_INSERT_COST (f))
1269 xfree (FRAME_INSERT_COST (f));
1270 if (FRAME_DELETEN_COST (f))
1271 xfree (FRAME_DELETEN_COST (f));
1272 if (FRAME_INSERTN_COST (f))
1273 xfree (FRAME_INSERTN_COST (f));
1274 if (FRAME_DELETE_COST (f))
1275 xfree (FRAME_DELETE_COST (f));
1276 if (FRAME_MESSAGE_BUF (f))
1277 xfree (FRAME_MESSAGE_BUF (f));
1278
1279 /* Since some events are handled at the interrupt level, we may get
1280 an event for f at any time; if we zero out the frame's display
1281 now, then we may trip up the event-handling code. Instead, we'll
1282 promise that the display of the frame must be valid until we have
1283 called the window-system-dependent frame destruction routine. */
1284
1285 /* I think this should be done with a hook. */
1286 #ifdef HAVE_WINDOW_SYSTEM
1287 if (FRAME_WINDOW_P (f))
1288 x_destroy_window (f);
1289 #endif
1290
1291 /* Done by x_destroy_window above already */
1292 #if 0
1293 #ifdef macintosh
1294 if (FRAME_MAC_P (f))
1295 DisposeMacWindow (f->output_data.mac);
1296 #endif
1297 #endif
1298
1299 f->output_data.nothing = 0;
1300
1301 /* If we've deleted the last_nonminibuf_frame, then try to find
1302 another one. */
1303 if (f == last_nonminibuf_frame)
1304 {
1305 Lisp_Object frames;
1306
1307 last_nonminibuf_frame = 0;
1308
1309 for (frames = Vframe_list;
1310 CONSP (frames);
1311 frames = XCDR (frames))
1312 {
1313 f = XFRAME (XCAR (frames));
1314 if (!FRAME_MINIBUF_ONLY_P (f))
1315 {
1316 last_nonminibuf_frame = f;
1317 break;
1318 }
1319 }
1320 }
1321
1322 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1323 find another one. Prefer minibuffer-only frames, but also notice
1324 frames with other windows. */
1325 if (EQ (frame, FRAME_KBOARD (f)->Vdefault_minibuffer_frame))
1326 {
1327 Lisp_Object frames;
1328
1329 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1330 Lisp_Object frame_with_minibuf;
1331 /* Some frame we found on the same kboard, or nil if there are none. */
1332 Lisp_Object frame_on_same_kboard;
1333
1334 frame_on_same_kboard = Qnil;
1335 frame_with_minibuf = Qnil;
1336
1337 for (frames = Vframe_list;
1338 CONSP (frames);
1339 frames = XCDR (frames))
1340 {
1341 Lisp_Object this;
1342 struct frame *f1;
1343
1344 this = XCAR (frames);
1345 if (!FRAMEP (this))
1346 abort ();
1347 f1 = XFRAME (this);
1348
1349 /* Consider only frames on the same kboard
1350 and only those with minibuffers. */
1351 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)
1352 && FRAME_HAS_MINIBUF_P (f1))
1353 {
1354 frame_with_minibuf = this;
1355 if (FRAME_MINIBUF_ONLY_P (f1))
1356 break;
1357 }
1358
1359 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1))
1360 frame_on_same_kboard = this;
1361 }
1362
1363 if (!NILP (frame_on_same_kboard))
1364 {
1365 /* We know that there must be some frame with a minibuffer out
1366 there. If this were not true, all of the frames present
1367 would have to be minibufferless, which implies that at some
1368 point their minibuffer frames must have been deleted, but
1369 that is prohibited at the top; you can't delete surrogate
1370 minibuffer frames. */
1371 if (NILP (frame_with_minibuf))
1372 abort ();
1373
1374 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = frame_with_minibuf;
1375 }
1376 else
1377 /* No frames left on this kboard--say no minibuffer either. */
1378 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = Qnil;
1379 }
1380
1381 /* Cause frame titles to update--necessary if we now have just one frame. */
1382 update_mode_lines = 1;
1383
1384 return Qnil;
1385 }
1386 \f
1387 /* Return mouse position in character cell units. */
1388
1389 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1390 "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
1391 The position is given in character cells, where (0, 0) is the\n\
1392 upper-left corner.\n\
1393 If Emacs is running on a mouseless terminal or hasn't been programmed\n\
1394 to read the mouse position, it returns the selected frame for FRAME\n\
1395 and nil for X and Y.\n\
1396 Runs the abnormal hook `mouse-position-function' with the normal return\n\
1397 value as argument.")
1398 ()
1399 {
1400 FRAME_PTR f;
1401 Lisp_Object lispy_dummy;
1402 enum scroll_bar_part party_dummy;
1403 Lisp_Object x, y, retval;
1404 int col, row;
1405 unsigned long long_dummy;
1406 struct gcpro gcpro1;
1407
1408 f = SELECTED_FRAME ();
1409 x = y = Qnil;
1410
1411 #ifdef HAVE_MOUSE
1412 /* It's okay for the hook to refrain from storing anything. */
1413 if (mouse_position_hook)
1414 (*mouse_position_hook) (&f, -1,
1415 &lispy_dummy, &party_dummy,
1416 &x, &y,
1417 &long_dummy);
1418 if (! NILP (x))
1419 {
1420 col = XINT (x);
1421 row = XINT (y);
1422 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1423 XSETINT (x, col);
1424 XSETINT (y, row);
1425 }
1426 #endif
1427 XSETFRAME (lispy_dummy, f);
1428 retval = Fcons (lispy_dummy, Fcons (x, y));
1429 GCPRO1 (retval);
1430 if (!NILP (Vmouse_position_function))
1431 retval = call1 (Vmouse_position_function, retval);
1432 RETURN_UNGCPRO (retval);
1433 }
1434
1435 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1436 Smouse_pixel_position, 0, 0, 0,
1437 "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
1438 The position is given in pixel units, where (0, 0) is the\n\
1439 upper-left corner.\n\
1440 If Emacs is running on a mouseless terminal or hasn't been programmed\n\
1441 to read the mouse position, it returns the selected frame for FRAME\n\
1442 and nil for X and Y.")
1443 ()
1444 {
1445 FRAME_PTR f;
1446 Lisp_Object lispy_dummy;
1447 enum scroll_bar_part party_dummy;
1448 Lisp_Object x, y;
1449 unsigned long long_dummy;
1450
1451 f = SELECTED_FRAME ();
1452 x = y = Qnil;
1453
1454 #ifdef HAVE_MOUSE
1455 /* It's okay for the hook to refrain from storing anything. */
1456 if (mouse_position_hook)
1457 (*mouse_position_hook) (&f, -1,
1458 &lispy_dummy, &party_dummy,
1459 &x, &y,
1460 &long_dummy);
1461 #endif
1462 XSETFRAME (lispy_dummy, f);
1463 return Fcons (lispy_dummy, Fcons (x, y));
1464 }
1465
1466 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1467 "Move the mouse pointer to the center of character cell (X,Y) in FRAME.\n\
1468 Coordinates are relative to the frame, not a window,\n\
1469 so the coordinates of the top left character in the frame\n\
1470 may be nonzero due to left-hand scroll bars or the menu bar.\n\
1471 \n\
1472 This function is a no-op for an X frame that is not visible.\n\
1473 If you have just created a frame, you must wait for it to become visible\n\
1474 before calling this function on it, like this.\n\
1475 (while (not (frame-visible-p frame)) (sleep-for .5))")
1476 (frame, x, y)
1477 Lisp_Object frame, x, y;
1478 {
1479 CHECK_LIVE_FRAME (frame, 0);
1480 CHECK_NUMBER (x, 2);
1481 CHECK_NUMBER (y, 1);
1482
1483 /* I think this should be done with a hook. */
1484 #ifdef HAVE_WINDOW_SYSTEM
1485 if (FRAME_WINDOW_P (XFRAME (frame)))
1486 /* Warping the mouse will cause enternotify and focus events. */
1487 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1488 #else
1489 #if defined (MSDOS) && defined (HAVE_MOUSE)
1490 if (FRAME_MSDOS_P (XFRAME (frame)))
1491 {
1492 Fselect_frame (frame, Qnil);
1493 mouse_moveto (XINT (x), XINT (y));
1494 }
1495 #endif
1496 #endif
1497
1498 return Qnil;
1499 }
1500
1501 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1502 Sset_mouse_pixel_position, 3, 3, 0,
1503 "Move the mouse pointer to pixel position (X,Y) in FRAME.\n\
1504 Note, this is a no-op for an X frame that is not visible.\n\
1505 If you have just created a frame, you must wait for it to become visible\n\
1506 before calling this function on it, like this.\n\
1507 (while (not (frame-visible-p frame)) (sleep-for .5))")
1508 (frame, x, y)
1509 Lisp_Object frame, x, y;
1510 {
1511 CHECK_LIVE_FRAME (frame, 0);
1512 CHECK_NUMBER (x, 2);
1513 CHECK_NUMBER (y, 1);
1514
1515 /* I think this should be done with a hook. */
1516 #ifdef HAVE_WINDOW_SYSTEM
1517 if (FRAME_WINDOW_P (XFRAME (frame)))
1518 /* Warping the mouse will cause enternotify and focus events. */
1519 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1520 #else
1521 #if defined (MSDOS) && defined (HAVE_MOUSE)
1522 if (FRAME_MSDOS_P (XFRAME (frame)))
1523 {
1524 Fselect_frame (frame, Qnil);
1525 mouse_moveto (XINT (x), XINT (y));
1526 }
1527 #endif
1528 #endif
1529
1530 return Qnil;
1531 }
1532 \f
1533 static void make_frame_visible_1 P_ ((Lisp_Object));
1534
1535 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1536 0, 1, "",
1537 "Make the frame FRAME visible (assuming it is an X-window).\n\
1538 If omitted, FRAME defaults to the currently selected frame.")
1539 (frame)
1540 Lisp_Object frame;
1541 {
1542 if (NILP (frame))
1543 frame = selected_frame;
1544
1545 CHECK_LIVE_FRAME (frame, 0);
1546
1547 /* I think this should be done with a hook. */
1548 #ifdef HAVE_WINDOW_SYSTEM
1549 if (FRAME_WINDOW_P (XFRAME (frame)))
1550 {
1551 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1552 x_make_frame_visible (XFRAME (frame));
1553 }
1554 #endif
1555
1556 make_frame_visible_1 (XFRAME (frame)->root_window);
1557
1558 /* Make menu bar update for the Buffers and Frams menus. */
1559 windows_or_buffers_changed++;
1560
1561 return frame;
1562 }
1563
1564 /* Update the display_time slot of the buffers shown in WINDOW
1565 and all its descendents. */
1566
1567 static void
1568 make_frame_visible_1 (window)
1569 Lisp_Object window;
1570 {
1571 struct window *w;
1572
1573 for (;!NILP (window); window = w->next)
1574 {
1575 w = XWINDOW (window);
1576
1577 if (!NILP (w->buffer))
1578 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1579
1580 if (!NILP (w->vchild))
1581 make_frame_visible_1 (w->vchild);
1582 if (!NILP (w->hchild))
1583 make_frame_visible_1 (w->hchild);
1584 }
1585 }
1586
1587 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1588 0, 2, "",
1589 "Make the frame FRAME invisible (assuming it is an X-window).\n\
1590 If omitted, FRAME defaults to the currently selected frame.\n\
1591 Normally you may not make FRAME invisible if all other frames are invisible,\n\
1592 but if the second optional argument FORCE is non-nil, you may do so.")
1593 (frame, force)
1594 Lisp_Object frame, force;
1595 {
1596 if (NILP (frame))
1597 frame = selected_frame;
1598
1599 CHECK_LIVE_FRAME (frame, 0);
1600
1601 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1602 error ("Attempt to make invisible the sole visible or iconified frame");
1603
1604 #if 0 /* This isn't logically necessary, and it can do GC. */
1605 /* Don't let the frame remain selected. */
1606 if (EQ (frame, selected_frame))
1607 do_switch_frame (next_frame (frame, Qt), Qnil, 0)
1608 #endif
1609
1610 /* Don't allow minibuf_window to remain on a deleted frame. */
1611 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1612 {
1613 struct frame *sf = XFRAME (selected_frame);
1614 Fset_window_buffer (sf->minibuffer_window,
1615 XWINDOW (minibuf_window)->buffer);
1616 minibuf_window = sf->minibuffer_window;
1617 }
1618
1619 /* I think this should be done with a hook. */
1620 #ifdef HAVE_WINDOW_SYSTEM
1621 if (FRAME_WINDOW_P (XFRAME (frame)))
1622 x_make_frame_invisible (XFRAME (frame));
1623 #endif
1624
1625 /* Make menu bar update for the Buffers and Frams menus. */
1626 windows_or_buffers_changed++;
1627
1628 return Qnil;
1629 }
1630
1631 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1632 0, 1, "",
1633 "Make the frame FRAME into an icon.\n\
1634 If omitted, FRAME defaults to the currently selected frame.")
1635 (frame)
1636 Lisp_Object frame;
1637 {
1638 if (NILP (frame))
1639 frame = selected_frame;
1640
1641 CHECK_LIVE_FRAME (frame, 0);
1642
1643 #if 0 /* This isn't logically necessary, and it can do GC. */
1644 /* Don't let the frame remain selected. */
1645 if (EQ (frame, selected_frame))
1646 Fhandle_switch_frame (next_frame (frame, Qt), Qnil);
1647 #endif
1648
1649 /* Don't allow minibuf_window to remain on a deleted frame. */
1650 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1651 {
1652 struct frame *sf = XFRAME (selected_frame);
1653 Fset_window_buffer (sf->minibuffer_window,
1654 XWINDOW (minibuf_window)->buffer);
1655 minibuf_window = sf->minibuffer_window;
1656 }
1657
1658 /* I think this should be done with a hook. */
1659 #ifdef HAVE_WINDOW_SYSTEM
1660 if (FRAME_WINDOW_P (XFRAME (frame)))
1661 x_iconify_frame (XFRAME (frame));
1662 #endif
1663
1664 /* Make menu bar update for the Buffers and Frams menus. */
1665 windows_or_buffers_changed++;
1666
1667 return Qnil;
1668 }
1669
1670 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1671 1, 1, 0,
1672 "Return t if FRAME is now \"visible\" (actually in use for display).\n\
1673 A frame that is not \"visible\" is not updated and, if it works through\n\
1674 a window system, it may not show at all.\n\
1675 Return the symbol `icon' if frame is visible only as an icon.")
1676 (frame)
1677 Lisp_Object frame;
1678 {
1679 CHECK_LIVE_FRAME (frame, 0);
1680
1681 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1682
1683 if (FRAME_VISIBLE_P (XFRAME (frame)))
1684 return Qt;
1685 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1686 return Qicon;
1687 return Qnil;
1688 }
1689
1690 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1691 0, 0, 0,
1692 "Return a list of all frames now \"visible\" (being updated).")
1693 ()
1694 {
1695 Lisp_Object tail, frame;
1696 struct frame *f;
1697 Lisp_Object value;
1698
1699 value = Qnil;
1700 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1701 {
1702 frame = XCAR (tail);
1703 if (!FRAMEP (frame))
1704 continue;
1705 f = XFRAME (frame);
1706 if (FRAME_VISIBLE_P (f))
1707 value = Fcons (frame, value);
1708 }
1709 return value;
1710 }
1711
1712
1713 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1714 "Bring FRAME to the front, so it occludes any frames it overlaps.\n\
1715 If FRAME is invisible, make it visible.\n\
1716 If you don't specify a frame, the selected frame is used.\n\
1717 If Emacs is displaying on an ordinary terminal or some other device which\n\
1718 doesn't support multiple overlapping frames, this function does nothing.")
1719 (frame)
1720 Lisp_Object frame;
1721 {
1722 if (NILP (frame))
1723 frame = selected_frame;
1724
1725 CHECK_LIVE_FRAME (frame, 0);
1726
1727 /* Do like the documentation says. */
1728 Fmake_frame_visible (frame);
1729
1730 if (frame_raise_lower_hook)
1731 (*frame_raise_lower_hook) (XFRAME (frame), 1);
1732
1733 return Qnil;
1734 }
1735
1736 /* Should we have a corresponding function called Flower_Power? */
1737 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1738 "Send FRAME to the back, so it is occluded by any frames that overlap it.\n\
1739 If you don't specify a frame, the selected frame is used.\n\
1740 If Emacs is displaying on an ordinary terminal or some other device which\n\
1741 doesn't support multiple overlapping frames, this function does nothing.")
1742 (frame)
1743 Lisp_Object frame;
1744 {
1745 if (NILP (frame))
1746 frame = selected_frame;
1747
1748 CHECK_LIVE_FRAME (frame, 0);
1749
1750 if (frame_raise_lower_hook)
1751 (*frame_raise_lower_hook) (XFRAME (frame), 0);
1752
1753 return Qnil;
1754 }
1755
1756 \f
1757 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1758 1, 2, 0,
1759 "Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.\n\
1760 In other words, switch-frame events caused by events in FRAME will\n\
1761 request a switch to FOCUS-FRAME, and `last-event-frame' will be\n\
1762 FOCUS-FRAME after reading an event typed at FRAME.\n\
1763 \n\
1764 If FOCUS-FRAME is omitted or nil, any existing redirection is\n\
1765 cancelled, and the frame again receives its own keystrokes.\n\
1766 \n\
1767 Focus redirection is useful for temporarily redirecting keystrokes to\n\
1768 a surrogate minibuffer frame when a frame doesn't have its own\n\
1769 minibuffer window.\n\
1770 \n\
1771 A frame's focus redirection can be changed by select-frame. If frame\n\
1772 FOO is selected, and then a different frame BAR is selected, any\n\
1773 frames redirecting their focus to FOO are shifted to redirect their\n\
1774 focus to BAR. This allows focus redirection to work properly when the\n\
1775 user switches from one frame to another using `select-window'.\n\
1776 \n\
1777 This means that a frame whose focus is redirected to itself is treated\n\
1778 differently from a frame whose focus is redirected to nil; the former\n\
1779 is affected by select-frame, while the latter is not.\n\
1780 \n\
1781 The redirection lasts until `redirect-frame-focus' is called to change it.")
1782 (frame, focus_frame)
1783 Lisp_Object frame, focus_frame;
1784 {
1785 /* Note that we don't check for a live frame here. It's reasonable
1786 to redirect the focus of a frame you're about to delete, if you
1787 know what other frame should receive those keystrokes. */
1788 CHECK_FRAME (frame, 0);
1789
1790 if (! NILP (focus_frame))
1791 CHECK_LIVE_FRAME (focus_frame, 1);
1792
1793 XFRAME (frame)->focus_frame = focus_frame;
1794
1795 if (frame_rehighlight_hook)
1796 (*frame_rehighlight_hook) (XFRAME (frame));
1797
1798 return Qnil;
1799 }
1800
1801
1802 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1803 "Return the frame to which FRAME's keystrokes are currently being sent.\n\
1804 This returns nil if FRAME's focus is not redirected.\n\
1805 See `redirect-frame-focus'.")
1806 (frame)
1807 Lisp_Object frame;
1808 {
1809 CHECK_LIVE_FRAME (frame, 0);
1810
1811 return FRAME_FOCUS_FRAME (XFRAME (frame));
1812 }
1813
1814
1815 \f
1816 /* Return the value of frame parameter PROP in frame FRAME. */
1817
1818 Lisp_Object
1819 get_frame_param (frame, prop)
1820 register struct frame *frame;
1821 Lisp_Object prop;
1822 {
1823 register Lisp_Object tem;
1824
1825 tem = Fassq (prop, frame->param_alist);
1826 if (EQ (tem, Qnil))
1827 return tem;
1828 return Fcdr (tem);
1829 }
1830
1831 /* Return the buffer-predicate of the selected frame. */
1832
1833 Lisp_Object
1834 frame_buffer_predicate (frame)
1835 Lisp_Object frame;
1836 {
1837 return XFRAME (frame)->buffer_predicate;
1838 }
1839
1840 /* Return the buffer-list of the selected frame. */
1841
1842 Lisp_Object
1843 frame_buffer_list (frame)
1844 Lisp_Object frame;
1845 {
1846 return XFRAME (frame)->buffer_list;
1847 }
1848
1849 /* Set the buffer-list of the selected frame. */
1850
1851 void
1852 set_frame_buffer_list (frame, list)
1853 Lisp_Object frame, list;
1854 {
1855 XFRAME (frame)->buffer_list = list;
1856 }
1857
1858 /* Discard BUFFER from the buffer-list of each frame. */
1859
1860 void
1861 frames_discard_buffer (buffer)
1862 Lisp_Object buffer;
1863 {
1864 Lisp_Object frame, tail;
1865
1866 FOR_EACH_FRAME (tail, frame)
1867 {
1868 XFRAME (frame)->buffer_list
1869 = Fdelq (buffer, XFRAME (frame)->buffer_list);
1870 }
1871 }
1872
1873 /* Move BUFFER to the end of the buffer-list of each frame. */
1874
1875 void
1876 frames_bury_buffer (buffer)
1877 Lisp_Object buffer;
1878 {
1879 Lisp_Object frame, tail;
1880
1881 FOR_EACH_FRAME (tail, frame)
1882 {
1883 struct frame *f = XFRAME (frame);
1884 Lisp_Object found;
1885
1886 found = Fmemq (buffer, f->buffer_list);
1887 if (!NILP (found))
1888 f->buffer_list = nconc2 (Fdelq (buffer, f->buffer_list),
1889 Fcons (buffer, Qnil));
1890 }
1891 }
1892
1893 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1894 If the alist already has an element for PROP, we change it. */
1895
1896 void
1897 store_in_alist (alistptr, prop, val)
1898 Lisp_Object *alistptr, val;
1899 Lisp_Object prop;
1900 {
1901 register Lisp_Object tem;
1902
1903 tem = Fassq (prop, *alistptr);
1904 if (EQ (tem, Qnil))
1905 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1906 else
1907 Fsetcdr (tem, val);
1908 }
1909
1910 static int
1911 frame_name_fnn_p (str, len)
1912 char *str;
1913 int len;
1914 {
1915 if (len > 1 && str[0] == 'F')
1916 {
1917 char *end_ptr;
1918
1919 strtol (str + 1, &end_ptr, 10);
1920
1921 if (end_ptr == str + len)
1922 return 1;
1923 }
1924 return 0;
1925 }
1926
1927 /* Set the name of the terminal frame. Also used by MSDOS frames.
1928 Modeled after x_set_name which is used for WINDOW frames. */
1929
1930 void
1931 set_term_frame_name (f, name)
1932 struct frame *f;
1933 Lisp_Object name;
1934 {
1935 f->explicit_name = ! NILP (name);
1936
1937 /* If NAME is nil, set the name to F<num>. */
1938 if (NILP (name))
1939 {
1940 char namebuf[20];
1941
1942 /* Check for no change needed in this very common case
1943 before we do any consing. */
1944 if (frame_name_fnn_p (XSTRING (f->name)->data,
1945 STRING_BYTES (XSTRING (f->name))))
1946 return;
1947
1948 terminal_frame_count++;
1949 sprintf (namebuf, "F%d", terminal_frame_count);
1950 name = build_string (namebuf);
1951 }
1952 else
1953 {
1954 CHECK_STRING (name, 0);
1955
1956 /* Don't change the name if it's already NAME. */
1957 if (! NILP (Fstring_equal (name, f->name)))
1958 return;
1959
1960 /* Don't allow the user to set the frame name to F<num>, so it
1961 doesn't clash with the names we generate for terminal frames. */
1962 if (frame_name_fnn_p (XSTRING (name)->data, STRING_BYTES (XSTRING (name))))
1963 error ("Frame names of the form F<num> are usurped by Emacs");
1964 }
1965
1966 f->name = name;
1967 update_mode_lines = 1;
1968 }
1969
1970 void
1971 store_frame_param (f, prop, val)
1972 struct frame *f;
1973 Lisp_Object prop, val;
1974 {
1975 register Lisp_Object old_alist_elt;
1976
1977 /* The buffer-alist parameter is stored in a special place and is
1978 not in the alist. */
1979 if (EQ (prop, Qbuffer_list))
1980 {
1981 f->buffer_list = val;
1982 return;
1983 }
1984
1985 /* If PROP is a symbol which is supposed to have frame-local values,
1986 and it is set up based on this frame, switch to the global
1987 binding. That way, we can create or alter the frame-local binding
1988 without messing up the symbol's status. */
1989 if (SYMBOLP (prop))
1990 {
1991 Lisp_Object valcontents;
1992 valcontents = XSYMBOL (prop)->value;
1993 if ((BUFFER_LOCAL_VALUEP (valcontents)
1994 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1995 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
1996 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
1997 swap_in_global_binding (prop);
1998 }
1999
2000 /* Update the frame parameter alist. */
2001 old_alist_elt = Fassq (prop, f->param_alist);
2002 if (EQ (old_alist_elt, Qnil))
2003 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2004 else
2005 Fsetcdr (old_alist_elt, val);
2006
2007 /* Update some other special parameters in their special places
2008 in addition to the alist. */
2009
2010 if (EQ (prop, Qbuffer_predicate))
2011 f->buffer_predicate = val;
2012
2013 if (! FRAME_WINDOW_P (f))
2014 {
2015 if (EQ (prop, Qmenu_bar_lines))
2016 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2017 else if (EQ (prop, Qname))
2018 set_term_frame_name (f, val);
2019 }
2020
2021 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2022 {
2023 if (! MINI_WINDOW_P (XWINDOW (val)))
2024 error ("Surrogate minibuffer windows must be minibuffer windows.");
2025
2026 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2027 && !EQ (val, f->minibuffer_window))
2028 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2029
2030 /* Install the chosen minibuffer window, with proper buffer. */
2031 f->minibuffer_window = val;
2032 }
2033 }
2034
2035 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2036 "Return the parameters-alist of frame FRAME.\n\
2037 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.\n\
2038 The meaningful PARMs depend on the kind of frame.\n\
2039 If FRAME is omitted, return information on the currently selected frame.")
2040 (frame)
2041 Lisp_Object frame;
2042 {
2043 Lisp_Object alist;
2044 FRAME_PTR f;
2045 int height, width;
2046 struct gcpro gcpro1;
2047
2048 if (EQ (frame, Qnil))
2049 frame = selected_frame;
2050
2051 CHECK_FRAME (frame, 0);
2052 f = XFRAME (frame);
2053
2054 if (!FRAME_LIVE_P (f))
2055 return Qnil;
2056
2057 alist = Fcopy_alist (f->param_alist);
2058 GCPRO1 (alist);
2059
2060 if (!FRAME_WINDOW_P (f))
2061 {
2062 int fg = FRAME_FOREGROUND_PIXEL (f);
2063 int bg = FRAME_BACKGROUND_PIXEL (f);
2064
2065 store_in_alist (&alist, intern ("foreground-color"),
2066 tty_color_name (f, fg));
2067 store_in_alist (&alist, intern ("background-color"),
2068 tty_color_name (f, bg));
2069 store_in_alist (&alist, intern ("font"),
2070 build_string (FRAME_MSDOS_P (f)
2071 ? "ms-dos"
2072 : FRAME_W32_P (f) ? "w32term" : "tty"));
2073 }
2074 store_in_alist (&alist, Qname, f->name);
2075 height = (FRAME_NEW_HEIGHT (f) ? FRAME_NEW_HEIGHT (f) : FRAME_HEIGHT (f));
2076 store_in_alist (&alist, Qheight, make_number (height));
2077 width = (FRAME_NEW_WIDTH (f) ? FRAME_NEW_WIDTH (f) : FRAME_WIDTH (f));
2078 store_in_alist (&alist, Qwidth, make_number (width));
2079 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2080 store_in_alist (&alist, Qminibuffer,
2081 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2082 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2083 : FRAME_MINIBUF_WINDOW (f)));
2084 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2085 store_in_alist (&alist, Qbuffer_list,
2086 frame_buffer_list (selected_frame));
2087
2088 /* I think this should be done with a hook. */
2089 #ifdef HAVE_WINDOW_SYSTEM
2090 if (FRAME_WINDOW_P (f))
2091 x_report_frame_params (f, &alist);
2092 else
2093 #endif
2094 {
2095 /* This ought to be correct in f->param_alist for an X frame. */
2096 Lisp_Object lines;
2097 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2098 store_in_alist (&alist, Qmenu_bar_lines, lines);
2099 }
2100
2101 UNGCPRO;
2102 return alist;
2103 }
2104
2105
2106 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2107 "Return FRAME's value for parameter PARAMETER.\n\
2108 If FRAME is nil, describe the currently selected frame.")
2109 (frame, parameter)
2110 Lisp_Object frame, parameter;
2111 {
2112 struct frame *f;
2113 Lisp_Object value;
2114
2115 if (NILP (frame))
2116 frame = selected_frame;
2117 else
2118 CHECK_FRAME (frame, 0);
2119 CHECK_SYMBOL (parameter, 1);
2120
2121 f = XFRAME (frame);
2122 value = Qnil;
2123
2124 if (FRAME_LIVE_P (f))
2125 {
2126 if (EQ (parameter, Qname))
2127 value = f->name;
2128 #ifdef HAVE_X_WINDOWS
2129 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2130 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2131 #endif /* HAVE_X_WINDOWS */
2132 else
2133 {
2134 value = Fassq (parameter, f->param_alist);
2135 if (CONSP (value))
2136 value = XCDR (value);
2137 else if (EQ (parameter, Qdisplay_type)
2138 || EQ (parameter, Qbackground_mode))
2139 /* Avoid consing in frequent cases. */
2140 value = Qnil;
2141 else
2142 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2143 }
2144 }
2145
2146 return value;
2147 }
2148
2149
2150 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2151 Smodify_frame_parameters, 2, 2, 0,
2152 "Modify the parameters of frame FRAME according to ALIST.\n\
2153 ALIST is an alist of parameters to change and their new values.\n\
2154 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.\n\
2155 The meaningful PARMs depend on the kind of frame.\n\
2156 Undefined PARMs are ignored, but stored in the frame's parameter list\n\
2157 so that `frame-parameters' will return them.\n\
2158 \n\
2159 The value of frame parameter FOO can also be accessed\n\
2160 as a frame-local binding for the variable FOO, if you have\n\
2161 enabled such bindings for that variable with `make-variable-frame-local'.")
2162 (frame, alist)
2163 Lisp_Object frame, alist;
2164 {
2165 FRAME_PTR f;
2166 register Lisp_Object tail, prop, val;
2167
2168 if (EQ (frame, Qnil))
2169 frame = selected_frame;
2170 CHECK_LIVE_FRAME (frame, 0);
2171 f = XFRAME (frame);
2172
2173 /* I think this should be done with a hook. */
2174 #ifdef HAVE_WINDOW_SYSTEM
2175 if (FRAME_WINDOW_P (f))
2176 x_set_frame_parameters (f, alist);
2177 else
2178 #endif
2179 #ifdef MSDOS
2180 if (FRAME_MSDOS_P (f))
2181 IT_set_frame_parameters (f, alist);
2182 else
2183 #endif
2184 #ifdef macintosh
2185 if (FRAME_MAC_P (f))
2186 mac_set_frame_parameters (f, alist);
2187 else
2188 #endif
2189
2190 {
2191 int length = XINT (Flength (alist));
2192 int i;
2193 Lisp_Object *parms
2194 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2195 Lisp_Object *values
2196 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2197
2198 /* Extract parm names and values into those vectors. */
2199
2200 i = 0;
2201 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2202 {
2203 Lisp_Object elt;
2204
2205 elt = Fcar (tail);
2206 parms[i] = Fcar (elt);
2207 values[i] = Fcdr (elt);
2208 i++;
2209 }
2210
2211 /* Now process them in reverse of specified order. */
2212 for (i--; i >= 0; i--)
2213 {
2214 prop = parms[i];
2215 val = values[i];
2216 store_frame_param (f, prop, val);
2217 }
2218 }
2219
2220 return Qnil;
2221 }
2222 \f
2223 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2224 0, 1, 0,
2225 "Height in pixels of a line in the font in frame FRAME.\n\
2226 If FRAME is omitted, the selected frame is used.\n\
2227 For a terminal frame, the value is always 1.")
2228 (frame)
2229 Lisp_Object frame;
2230 {
2231 struct frame *f;
2232
2233 if (NILP (frame))
2234 frame = selected_frame;
2235 CHECK_FRAME (frame, 0);
2236 f = XFRAME (frame);
2237
2238 #ifdef HAVE_WINDOW_SYSTEM
2239 if (FRAME_WINDOW_P (f))
2240 return make_number (x_char_height (f));
2241 else
2242 #endif
2243 return make_number (1);
2244 }
2245
2246
2247 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2248 0, 1, 0,
2249 "Width in pixels of characters in the font in frame FRAME.\n\
2250 If FRAME is omitted, the selected frame is used.\n\
2251 The width is the same for all characters, because\n\
2252 currently Emacs supports only fixed-width fonts.\n\
2253 For a terminal screen, the value is always 1.")
2254 (frame)
2255 Lisp_Object frame;
2256 {
2257 struct frame *f;
2258
2259 if (NILP (frame))
2260 frame = selected_frame;
2261 CHECK_FRAME (frame, 0);
2262 f = XFRAME (frame);
2263
2264 #ifdef HAVE_WINDOW_SYSTEM
2265 if (FRAME_WINDOW_P (f))
2266 return make_number (x_char_width (f));
2267 else
2268 #endif
2269 return make_number (1);
2270 }
2271
2272 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2273 Sframe_pixel_height, 0, 1, 0,
2274 "Return a FRAME's height in pixels.\n\
2275 This counts only the height available for text lines,\n\
2276 not menu bars on window-system Emacs frames.\n\
2277 For a terminal frame, the result really gives the height in characters.\n\
2278 If FRAME is omitted, the selected frame is used.")
2279 (frame)
2280 Lisp_Object frame;
2281 {
2282 struct frame *f;
2283
2284 if (NILP (frame))
2285 frame = selected_frame;
2286 CHECK_FRAME (frame, 0);
2287 f = XFRAME (frame);
2288
2289 #ifdef HAVE_WINDOW_SYSTEM
2290 if (FRAME_WINDOW_P (f))
2291 return make_number (x_pixel_height (f));
2292 else
2293 #endif
2294 return make_number (FRAME_HEIGHT (f));
2295 }
2296
2297 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2298 Sframe_pixel_width, 0, 1, 0,
2299 "Return FRAME's width in pixels.\n\
2300 For a terminal frame, the result really gives the width in characters.\n\
2301 If FRAME is omitted, the selected frame is used.")
2302 (frame)
2303 Lisp_Object frame;
2304 {
2305 struct frame *f;
2306
2307 if (NILP (frame))
2308 frame = selected_frame;
2309 CHECK_FRAME (frame, 0);
2310 f = XFRAME (frame);
2311
2312 #ifdef HAVE_WINDOW_SYSTEM
2313 if (FRAME_WINDOW_P (f))
2314 return make_number (x_pixel_width (f));
2315 else
2316 #endif
2317 return make_number (FRAME_WIDTH (f));
2318 }
2319 \f
2320 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2321 "Specify that the frame FRAME has LINES lines.\n\
2322 Optional third arg non-nil means that redisplay should use LINES lines\n\
2323 but that the idea of the actual height of the frame should not be changed.")
2324 (frame, lines, pretend)
2325 Lisp_Object frame, lines, pretend;
2326 {
2327 register struct frame *f;
2328
2329 CHECK_NUMBER (lines, 0);
2330 if (NILP (frame))
2331 frame = selected_frame;
2332 CHECK_LIVE_FRAME (frame, 0);
2333 f = XFRAME (frame);
2334
2335 /* I think this should be done with a hook. */
2336 #ifdef HAVE_WINDOW_SYSTEM
2337 if (FRAME_WINDOW_P (f))
2338 {
2339 if (XINT (lines) != f->height)
2340 x_set_window_size (f, 1, f->width, XINT (lines));
2341 do_pending_window_change (0);
2342 }
2343 else
2344 #endif
2345 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2346 return Qnil;
2347 }
2348
2349 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2350 "Specify that the frame FRAME has COLS columns.\n\
2351 Optional third arg non-nil means that redisplay should use COLS columns\n\
2352 but that the idea of the actual width of the frame should not be changed.")
2353 (frame, cols, pretend)
2354 Lisp_Object frame, cols, pretend;
2355 {
2356 register struct frame *f;
2357 CHECK_NUMBER (cols, 0);
2358 if (NILP (frame))
2359 frame = selected_frame;
2360 CHECK_LIVE_FRAME (frame, 0);
2361 f = XFRAME (frame);
2362
2363 /* I think this should be done with a hook. */
2364 #ifdef HAVE_WINDOW_SYSTEM
2365 if (FRAME_WINDOW_P (f))
2366 {
2367 if (XINT (cols) != f->width)
2368 x_set_window_size (f, 1, XINT (cols), f->height);
2369 do_pending_window_change (0);
2370 }
2371 else
2372 #endif
2373 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2374 return Qnil;
2375 }
2376
2377 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2378 "Sets size of FRAME to COLS by ROWS, measured in characters.")
2379 (frame, cols, rows)
2380 Lisp_Object frame, cols, rows;
2381 {
2382 register struct frame *f;
2383
2384 CHECK_LIVE_FRAME (frame, 0);
2385 CHECK_NUMBER (cols, 2);
2386 CHECK_NUMBER (rows, 1);
2387 f = XFRAME (frame);
2388
2389 /* I think this should be done with a hook. */
2390 #ifdef HAVE_WINDOW_SYSTEM
2391 if (FRAME_WINDOW_P (f))
2392 {
2393 if (XINT (rows) != f->height || XINT (cols) != f->width
2394 || FRAME_NEW_HEIGHT (f) || FRAME_NEW_WIDTH (f))
2395 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2396 do_pending_window_change (0);
2397 }
2398 else
2399 #endif
2400 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2401
2402 return Qnil;
2403 }
2404
2405 DEFUN ("set-frame-position", Fset_frame_position,
2406 Sset_frame_position, 3, 3, 0,
2407 "Sets position of FRAME in pixels to XOFFSET by YOFFSET.\n\
2408 This is actually the position of the upper left corner of the frame.\n\
2409 Negative values for XOFFSET or YOFFSET are interpreted relative to\n\
2410 the rightmost or bottommost possible position (that stays within the screen).")
2411 (frame, xoffset, yoffset)
2412 Lisp_Object frame, xoffset, yoffset;
2413 {
2414 register struct frame *f;
2415
2416 CHECK_LIVE_FRAME (frame, 0);
2417 CHECK_NUMBER (xoffset, 1);
2418 CHECK_NUMBER (yoffset, 2);
2419 f = XFRAME (frame);
2420
2421 /* I think this should be done with a hook. */
2422 #ifdef HAVE_WINDOW_SYSTEM
2423 if (FRAME_WINDOW_P (f))
2424 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2425 #endif
2426
2427 return Qt;
2428 }
2429
2430 \f
2431 void
2432 syms_of_frame ()
2433 {
2434 syms_of_frame_1 ();
2435
2436 staticpro (&Vframe_list);
2437
2438 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
2439 "The initial frame-object, which represents Emacs's stdout.");
2440
2441 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
2442 "Non-nil if all of emacs is iconified and frame updates are not needed.");
2443 Vemacs_iconified = Qnil;
2444
2445 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
2446 "If non-nil, function applied to the normal result of `mouse-position'.\n\
2447 This abnormal hook exists for the benefit of packages like XTerm-mouse\n\
2448 which need to do mouse handling at the Lisp level.");
2449 Vmouse_position_function = Qnil;
2450
2451 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
2452 "Minibufferless frames use this frame's minibuffer.\n\
2453 \n\
2454 Emacs cannot create minibufferless frames unless this is set to an\n\
2455 appropriate surrogate.\n\
2456 \n\
2457 Emacs consults this variable only when creating minibufferless\n\
2458 frames; once the frame is created, it sticks with its assigned\n\
2459 minibuffer, no matter what this variable is set to. This means that\n\
2460 this variable doesn't necessarily say anything meaningful about the\n\
2461 current set of frames, or where the minibuffer is currently being\n\
2462 displayed.");
2463
2464 defsubr (&Sactive_minibuffer_window);
2465 defsubr (&Sframep);
2466 defsubr (&Sframe_live_p);
2467 defsubr (&Smake_terminal_frame);
2468 defsubr (&Shandle_switch_frame);
2469 defsubr (&Signore_event);
2470 defsubr (&Sselect_frame);
2471 defsubr (&Sselected_frame);
2472 defsubr (&Swindow_frame);
2473 defsubr (&Sframe_root_window);
2474 defsubr (&Sframe_first_window);
2475 defsubr (&Sframe_selected_window);
2476 defsubr (&Sset_frame_selected_window);
2477 defsubr (&Sframe_list);
2478 defsubr (&Snext_frame);
2479 defsubr (&Sprevious_frame);
2480 defsubr (&Sdelete_frame);
2481 defsubr (&Smouse_position);
2482 defsubr (&Smouse_pixel_position);
2483 defsubr (&Sset_mouse_position);
2484 defsubr (&Sset_mouse_pixel_position);
2485 #if 0
2486 defsubr (&Sframe_configuration);
2487 defsubr (&Srestore_frame_configuration);
2488 #endif
2489 defsubr (&Smake_frame_visible);
2490 defsubr (&Smake_frame_invisible);
2491 defsubr (&Siconify_frame);
2492 defsubr (&Sframe_visible_p);
2493 defsubr (&Svisible_frame_list);
2494 defsubr (&Sraise_frame);
2495 defsubr (&Slower_frame);
2496 defsubr (&Sredirect_frame_focus);
2497 defsubr (&Sframe_focus);
2498 defsubr (&Sframe_parameters);
2499 defsubr (&Sframe_parameter);
2500 defsubr (&Smodify_frame_parameters);
2501 defsubr (&Sframe_char_height);
2502 defsubr (&Sframe_char_width);
2503 defsubr (&Sframe_pixel_height);
2504 defsubr (&Sframe_pixel_width);
2505 defsubr (&Sset_frame_height);
2506 defsubr (&Sset_frame_width);
2507 defsubr (&Sset_frame_size);
2508 defsubr (&Sset_frame_position);
2509 }
2510
2511 void
2512 keys_of_frame ()
2513 {
2514 initial_define_lispy_key (global_map, "switch-frame", "handle-switch-frame");
2515 initial_define_lispy_key (global_map, "delete-frame", "handle-delete-frame");
2516 initial_define_lispy_key (global_map, "iconify-frame", "ignore-event");
2517 initial_define_lispy_key (global_map, "make-frame-visible", "ignore-event");
2518 }