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