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