(IT_note_mouse_highlight): Return immediately if frame's
[bpt/emacs.git] / src / frame.c
... / ...
CommitLineData
1/* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000 Free Software Foundation.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, 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
45extern struct mac_output *NewMacWindow ();
46extern 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 &&&*/
83Lisp_Object Qframep;
84Lisp_Object Qframe_live_p;
85Lisp_Object Qheight;
86Lisp_Object Qicon;
87Lisp_Object Qminibuffer;
88Lisp_Object Qmodeline;
89Lisp_Object Qname;
90Lisp_Object Qonly;
91Lisp_Object Qunsplittable;
92Lisp_Object Qmenu_bar_lines;
93Lisp_Object Qtool_bar_lines;
94Lisp_Object Qwidth;
95Lisp_Object Qx;
96Lisp_Object Qw32;
97Lisp_Object Qpc;
98Lisp_Object Qmac;
99Lisp_Object Qvisible;
100Lisp_Object Qbuffer_predicate;
101Lisp_Object Qbuffer_list;
102Lisp_Object Qtitle;
103
104Lisp_Object Vterminal_frame;
105Lisp_Object Vdefault_frame_alist;
106Lisp_Object Vmouse_position_function;
107
108static void
109syms_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\
155These may be set in your init file, like this:\n\
156 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1))\n\
157These override values given in window system configuration data,\n\
158 including X Windows' defaults database.\n\
159For values specific to the first Emacs frame, see `initial-frame-alist'.\n\
160For values specific to the separate minibuffer frame, see\n\
161 `minibuffer-frame-alist'.\n\
162The `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
167static void
168set_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 /* Handle just the top child in a vertical split. */
179 if (!NILP (w->vchild))
180 set_menu_bar_lines_1 (w->vchild, n);
181
182 /* Adjust all children in a horizontal split. */
183 for (window = w->hchild; !NILP (window); window = w->next)
184 {
185 w = XWINDOW (window);
186 set_menu_bar_lines_1 (window, n);
187 }
188}
189
190void
191set_menu_bar_lines (f, value, oldval)
192 struct frame *f;
193 Lisp_Object value, oldval;
194{
195 int nlines;
196 int olines = FRAME_MENU_BAR_LINES (f);
197
198 /* Right now, menu bars don't work properly in minibuf-only frames;
199 most of the commands try to apply themselves to the minibuffer
200 frame itself, and get an error because you can't switch buffers
201 in or split the minibuffer window. */
202 if (FRAME_MINIBUF_ONLY_P (f))
203 return;
204
205 if (INTEGERP (value))
206 nlines = XINT (value);
207 else
208 nlines = 0;
209
210 if (nlines != olines)
211 {
212 windows_or_buffers_changed++;
213 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
214 FRAME_MENU_BAR_LINES (f) = nlines;
215 set_menu_bar_lines_1 (f->root_window, nlines - olines);
216 adjust_glyphs (f);
217 }
218}
219\f
220#include "buffer.h"
221
222/* These help us bind and responding to switch-frame events. */
223#include "commands.h"
224#include "keyboard.h"
225
226Lisp_Object Vemacs_iconified;
227Lisp_Object Vframe_list;
228
229struct x_output tty_display;
230
231extern Lisp_Object Vminibuffer_list;
232extern Lisp_Object get_minibuffer ();
233extern Lisp_Object Fhandle_switch_frame ();
234extern Lisp_Object Fredirect_frame_focus ();
235extern Lisp_Object x_get_focus_frame ();
236\f
237DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
238 "Return non-nil if OBJECT is a frame.\n\
239Value is t for a termcap frame (a character-only terminal),\n\
240`x' for an Emacs frame that is really an X window,\n\
241`w32' for an Emacs frame that is a window on MS-Windows display,\n\
242`mac' for an Emacs frame on a Macintosh display,\n\
243`pc' for a direct-write MS-DOS frame.\n\
244See also `frame-live-p'.")
245 (object)
246 Lisp_Object object;
247{
248 if (!FRAMEP (object))
249 return Qnil;
250 switch (XFRAME (object)->output_method)
251 {
252 case output_termcap:
253 return Qt;
254 case output_x_window:
255 return Qx;
256 case output_w32:
257 return Qw32;
258 case output_msdos_raw:
259 return Qpc;
260 case output_mac:
261 return Qmac;
262 default:
263 abort ();
264 }
265}
266
267DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
268 "Return non-nil if OBJECT is a frame which has not been deleted.\n\
269Value is nil if OBJECT is not a live frame. If object is a live\n\
270frame, the return value indicates what sort of output device it is\n\
271displayed on. Value is t for a termcap frame (a character-only\n\
272terminal), `x' for an Emacs frame being displayed in an X window.")
273 (object)
274 Lisp_Object object;
275{
276 return ((FRAMEP (object)
277 && FRAME_LIVE_P (XFRAME (object)))
278 ? Fframep (object)
279 : Qnil);
280}
281
282struct frame *
283make_frame (mini_p)
284 int mini_p;
285{
286 Lisp_Object frame;
287 register struct frame *f;
288 register Lisp_Object root_window;
289 register Lisp_Object mini_window;
290 register struct Lisp_Vector *vec;
291 int i;
292
293 vec = allocate_vectorlike ((EMACS_INT) VECSIZE (struct frame));
294 for (i = 0; i < VECSIZE (struct frame); i++)
295 XSETFASTINT (vec->contents[i], 0);
296 vec->size = VECSIZE (struct frame);
297 f = (struct frame *)vec;
298 XSETFRAME (frame, f);
299
300 f->desired_matrix = 0;
301 f->current_matrix = 0;
302 f->desired_pool = 0;
303 f->current_pool = 0;
304 f->glyphs_initialized_p = 0;
305 f->decode_mode_spec_buffer = 0;
306 f->visible = 0;
307 f->async_visible = 0;
308 f->output_data.nothing = 0;
309 f->iconified = 0;
310 f->async_iconified = 0;
311 f->wants_modeline = 1;
312 f->auto_raise = 0;
313 f->auto_lower = 0;
314 f->no_split = 0;
315 f->garbaged = 1;
316 f->has_minibuffer = mini_p;
317 f->focus_frame = Qnil;
318 f->explicit_name = 0;
319 f->can_have_scroll_bars = 0;
320 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
321 f->param_alist = Qnil;
322 f->scroll_bars = Qnil;
323 f->condemned_scroll_bars = Qnil;
324 f->face_alist = Qnil;
325 f->face_cache = NULL;
326 f->menu_bar_items = Qnil;
327 f->menu_bar_vector = Qnil;
328 f->menu_bar_items_used = 0;
329 f->buffer_predicate = Qnil;
330 f->buffer_list = Qnil;
331#ifdef MULTI_KBOARD
332 f->kboard = initial_kboard;
333#endif
334 f->namebuf = 0;
335 f->title = Qnil;
336 f->menu_bar_window = Qnil;
337 f->tool_bar_window = Qnil;
338 f->desired_tool_bar_items = f->current_tool_bar_items = Qnil;
339 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
340 f->n_desired_tool_bar_items = f->n_current_tool_bar_items = 0;
341
342 root_window = make_window ();
343 if (mini_p)
344 {
345 mini_window = make_window ();
346 XWINDOW (root_window)->next = mini_window;
347 XWINDOW (mini_window)->prev = root_window;
348 XWINDOW (mini_window)->mini_p = Qt;
349 XWINDOW (mini_window)->frame = frame;
350 f->minibuffer_window = mini_window;
351 }
352 else
353 {
354 mini_window = Qnil;
355 XWINDOW (root_window)->next = Qnil;
356 f->minibuffer_window = Qnil;
357 }
358
359 XWINDOW (root_window)->frame = frame;
360
361 /* 10 is arbitrary,
362 just so that there is "something there."
363 Correct size will be set up later with change_frame_size. */
364
365 SET_FRAME_WIDTH (f, 10);
366 f->height = 10;
367
368 XSETFASTINT (XWINDOW (root_window)->width, 10);
369 XSETFASTINT (XWINDOW (root_window)->height, (mini_p ? 9 : 10));
370
371 if (mini_p)
372 {
373 XSETFASTINT (XWINDOW (mini_window)->width, 10);
374 XSETFASTINT (XWINDOW (mini_window)->top, 9);
375 XSETFASTINT (XWINDOW (mini_window)->height, 1);
376 }
377
378 /* Choose a buffer for the frame's root window. */
379 {
380 Lisp_Object buf;
381
382 XWINDOW (root_window)->buffer = Qt;
383 buf = Fcurrent_buffer ();
384 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
385 a space), try to find another one. */
386 if (XSTRING (Fbuffer_name (buf))->data[0] == ' ')
387 buf = Fother_buffer (buf, Qnil, Qnil);
388
389 /* Use set_window_buffer, not Fset_window_buffer, and don't let
390 hooks be run by it. The reason is that the whole frame/window
391 arrangement is not yet fully intialized at this point. Windows
392 don't have the right size, glyph matrices aren't initialized
393 etc. Running Lisp functions at this point surely ends in a
394 SEGV. */
395 set_window_buffer (root_window, buf, 0);
396 f->buffer_list = Fcons (buf, Qnil);
397 }
398
399 if (mini_p)
400 {
401 XWINDOW (mini_window)->buffer = Qt;
402 set_window_buffer (mini_window,
403 (NILP (Vminibuffer_list)
404 ? get_minibuffer (0)
405 : Fcar (Vminibuffer_list)),
406 0);
407 }
408
409 f->root_window = root_window;
410 f->selected_window = root_window;
411 /* Make sure this window seems more recently used than
412 a newly-created, never-selected window. */
413 XSETFASTINT (XWINDOW (f->selected_window)->use_time, ++window_select_count);
414
415#ifdef HAVE_WINDOW_SYSTEM
416 f->fontset_data = alloc_fontset_data ();
417#endif
418
419 return f;
420}
421\f
422#ifdef HAVE_WINDOW_SYSTEM
423/* Make a frame using a separate minibuffer window on another frame.
424 MINI_WINDOW is the minibuffer window to use. nil means use the
425 default (the global minibuffer). */
426
427struct frame *
428make_frame_without_minibuffer (mini_window, kb, display)
429 register Lisp_Object mini_window;
430 KBOARD *kb;
431 Lisp_Object display;
432{
433 register struct frame *f;
434 struct gcpro gcpro1;
435
436 if (!NILP (mini_window))
437 CHECK_LIVE_WINDOW (mini_window, 0);
438
439#ifdef MULTI_KBOARD
440 if (!NILP (mini_window)
441 && XFRAME (XWINDOW (mini_window)->frame)->kboard != kb)
442 error ("frame and minibuffer must be on the same display");
443#endif
444
445 /* Make a frame containing just a root window. */
446 f = make_frame (0);
447
448 if (NILP (mini_window))
449 {
450 /* Use default-minibuffer-frame if possible. */
451 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
452 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
453 {
454 Lisp_Object frame_dummy;
455
456 XSETFRAME (frame_dummy, f);
457 GCPRO1 (frame_dummy);
458 /* If there's no minibuffer frame to use, create one. */
459 kb->Vdefault_minibuffer_frame =
460 call1 (intern ("make-initial-minibuffer-frame"), display);
461 UNGCPRO;
462 }
463
464 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
465 }
466
467 f->minibuffer_window = mini_window;
468
469 /* Make the chosen minibuffer window display the proper minibuffer,
470 unless it is already showing a minibuffer. */
471 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
472 Fset_window_buffer (mini_window,
473 (NILP (Vminibuffer_list)
474 ? get_minibuffer (0)
475 : Fcar (Vminibuffer_list)));
476 return f;
477}
478
479/* Make a frame containing only a minibuffer window. */
480
481struct frame *
482make_minibuffer_frame ()
483{
484 /* First make a frame containing just a root window, no minibuffer. */
485
486 register struct frame *f = make_frame (0);
487 register Lisp_Object mini_window;
488 register Lisp_Object frame;
489
490 XSETFRAME (frame, f);
491
492 f->auto_raise = 0;
493 f->auto_lower = 0;
494 f->no_split = 1;
495 f->wants_modeline = 0;
496 f->has_minibuffer = 1;
497
498 /* Now label the root window as also being the minibuffer.
499 Avoid infinite looping on the window chain by marking next pointer
500 as nil. */
501
502 mini_window = f->minibuffer_window = f->root_window;
503 XWINDOW (mini_window)->mini_p = Qt;
504 XWINDOW (mini_window)->next = Qnil;
505 XWINDOW (mini_window)->prev = Qnil;
506 XWINDOW (mini_window)->frame = frame;
507
508 /* Put the proper buffer in that window. */
509
510 Fset_window_buffer (mini_window,
511 (NILP (Vminibuffer_list)
512 ? get_minibuffer (0)
513 : Fcar (Vminibuffer_list)));
514 return f;
515}
516#endif /* HAVE_WINDOW_SYSTEM */
517\f
518/* Construct a frame that refers to the terminal (stdin and stdout). */
519
520static int terminal_frame_count;
521
522struct frame *
523make_terminal_frame ()
524{
525 register struct frame *f;
526 Lisp_Object frame;
527 char name[20];
528
529#ifdef MULTI_KBOARD
530 if (!initial_kboard)
531 {
532 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
533 init_kboard (initial_kboard);
534 initial_kboard->next_kboard = all_kboards;
535 all_kboards = initial_kboard;
536 }
537#endif
538
539 /* The first call must initialize Vframe_list. */
540 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
541 Vframe_list = Qnil;
542
543 f = make_frame (1);
544
545 XSETFRAME (frame, f);
546 Vframe_list = Fcons (frame, Vframe_list);
547
548 terminal_frame_count++;
549 sprintf (name, "F%d", terminal_frame_count);
550 f->name = build_string (name);
551
552 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
553 f->async_visible = 1; /* Don't let visible be cleared later. */
554#ifdef MSDOS
555 f->output_data.x = &the_only_x_display;
556 if (!inhibit_window_system
557 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
558 || XFRAME (selected_frame)->output_method == output_msdos_raw))
559 f->output_method = output_msdos_raw;
560 else
561 f->output_method = output_termcap;
562#else
563#ifdef macintosh
564 f->output_data.mac = NewMacWindow(f);
565 f->output_data.mac->background_pixel = 0xffffff;
566 f->output_data.mac->foreground_pixel = 0;
567 f->output_data.mac->n_param_faces = 0;
568 f->output_data.mac->n_computed_faces = 0;
569 f->output_data.mac->size_computed_faces = 0;
570 f->output_method = output_mac;
571 f->auto_raise = 1;
572 f->auto_lower = 1;
573 init_frame_faces (f);
574#else /* !macintosh */
575 f->output_data.x = &tty_display;
576#endif /* !macintosh */
577#endif /* MSDOS */
578
579#ifndef macintosh
580 if (!noninteractive)
581 init_frame_faces (f);
582#endif
583 return f;
584}
585
586DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
587 1, 1, 0, "Create an additional terminal frame.\n\
588You can create multiple frames on a text-only terminal in this way.\n\
589Only the selected terminal frame is actually displayed.\n\
590This function takes one argument, an alist specifying frame parameters.\n\
591In practice, generally you don't need to specify any parameters.\n\
592Note that changing the size of one terminal frame automatically affects all.")
593 (parms)
594 Lisp_Object parms;
595{
596 struct frame *f;
597 Lisp_Object frame, tem;
598 struct frame *sf = SELECTED_FRAME ();
599
600#ifdef MSDOS
601 if (sf->output_method != output_msdos_raw
602 && sf->output_method != output_termcap)
603 abort ();
604#else /* not MSDOS */
605
606#ifdef macintosh
607 if (sf->output_method != output_mac)
608 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
609#else
610 if (sf->output_method != output_termcap)
611 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
612#endif
613#endif /* not MSDOS */
614
615 f = make_terminal_frame ();
616
617 change_frame_size (f, FRAME_HEIGHT (sf),
618 FRAME_WIDTH (sf), 0, 0, 0);
619 adjust_glyphs (f);
620 calculate_costs (f);
621 XSETFRAME (frame, f);
622 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
623 Fmodify_frame_parameters (frame, parms);
624
625 /* Make the frame face alist be frame-specific, so that each
626 frame could change its face definitions independently. */
627 f->face_alist = Fcopy_alist (sf->face_alist);
628 /* Simple Fcopy_alist isn't enough, because we need the contents of
629 the vectors which are the CDRs of associations in face_alist to
630 be copied as well. */
631 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
632 XCDR (XCAR (tem)) = Fcopy_sequence (XCDR (XCAR (tem)));
633 return frame;
634}
635\f
636Lisp_Object
637do_switch_frame (frame, no_enter, track)
638 Lisp_Object frame, no_enter;
639 int track;
640{
641 struct frame *sf = SELECTED_FRAME ();
642
643 /* If FRAME is a switch-frame event, extract the frame we should
644 switch to. */
645 if (CONSP (frame)
646 && EQ (XCAR (frame), Qswitch_frame)
647 && CONSP (XCDR (frame)))
648 frame = XCAR (XCDR (frame));
649
650 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
651 a switch-frame event to arrive after a frame is no longer live,
652 especially when deleting the initial frame during startup. */
653 CHECK_FRAME (frame, 0);
654 if (! FRAME_LIVE_P (XFRAME (frame)))
655 return Qnil;
656
657 if (sf == XFRAME (frame))
658 return frame;
659
660 /* This is too greedy; it causes inappropriate focus redirection
661 that's hard to get rid of. */
662#if 0
663 /* If a frame's focus has been redirected toward the currently
664 selected frame, we should change the redirection to point to the
665 newly selected frame. This means that if the focus is redirected
666 from a minibufferless frame to a surrogate minibuffer frame, we
667 can use `other-window' to switch between all the frames using
668 that minibuffer frame, and the focus redirection will follow us
669 around. */
670 if (track)
671 {
672 Lisp_Object tail;
673
674 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
675 {
676 Lisp_Object focus;
677
678 if (!FRAMEP (XCAR (tail)))
679 abort ();
680
681 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
682
683 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
684 Fredirect_frame_focus (XCAR (tail), frame);
685 }
686 }
687#else /* ! 0 */
688 /* Instead, apply it only to the frame we're pointing to. */
689#ifdef HAVE_WINDOW_SYSTEM
690 if (track && (FRAME_WINDOW_P (XFRAME (frame))))
691 {
692 Lisp_Object focus, xfocus;
693
694 xfocus = x_get_focus_frame (XFRAME (frame));
695 if (FRAMEP (xfocus))
696 {
697 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
698 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
699 Fredirect_frame_focus (xfocus, frame);
700 }
701 }
702#endif /* HAVE_X_WINDOWS */
703#endif /* ! 0 */
704
705 selected_frame = frame;
706 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
707 last_nonminibuf_frame = XFRAME (selected_frame);
708
709 Fselect_window (XFRAME (frame)->selected_window);
710
711 /* We want to make sure that the next event generates a frame-switch
712 event to the appropriate frame. This seems kludgy to me, but
713 before you take it out, make sure that evaluating something like
714 (select-window (frame-root-window (new-frame))) doesn't end up
715 with your typing being interpreted in the new frame instead of
716 the one you're actually typing in. */
717 internal_last_event_frame = Qnil;
718
719 return frame;
720}
721
722DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
723 "Select the frame FRAME.\n\
724Subsequent editing commands apply to its selected window.\n\
725The selection of FRAME lasts until the next time the user does\n\
726something to select a different frame, or until the next time this\n\
727function is called.")
728 (frame, no_enter)
729 Lisp_Object frame, no_enter;
730{
731 return do_switch_frame (frame, no_enter, 1);
732}
733
734
735DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 2, "e",
736 "Handle a switch-frame event EVENT.\n\
737Switch-frame events are usually bound to this function.\n\
738A switch-frame event tells Emacs that the window manager has requested\n\
739that the user's events be directed to the frame mentioned in the event.\n\
740This function selects the selected window of the frame of EVENT.\n\
741\n\
742If EVENT is frame object, handle it as if it were a switch-frame event\n\
743to that frame.")
744 (event, no_enter)
745 Lisp_Object event, no_enter;
746{
747 /* Preserve prefix arg that the command loop just cleared. */
748 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
749 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
750 return do_switch_frame (event, no_enter, 0);
751}
752
753DEFUN ("ignore-event", Fignore_event, Signore_event, 0, 0, "",
754 "Do nothing, but preserve any prefix argument already specified.\n\
755This is a suitable binding for iconify-frame and make-frame-visible.")
756 ()
757{
758 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
759 return Qnil;
760}
761
762DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
763 "Return the frame that is now selected.")
764 ()
765{
766 return selected_frame;
767}
768\f
769DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
770 "Return the frame object that window WINDOW is on.")
771 (window)
772 Lisp_Object window;
773{
774 CHECK_LIVE_WINDOW (window, 0);
775 return XWINDOW (window)->frame;
776}
777
778DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
779 "Returns the topmost, leftmost window of FRAME.\n\
780If omitted, FRAME defaults to the currently selected frame.")
781 (frame)
782 Lisp_Object frame;
783{
784 Lisp_Object w;
785
786 if (NILP (frame))
787 w = SELECTED_FRAME ()->root_window;
788 else
789 {
790 CHECK_LIVE_FRAME (frame, 0);
791 w = XFRAME (frame)->root_window;
792 }
793 while (NILP (XWINDOW (w)->buffer))
794 {
795 if (! NILP (XWINDOW (w)->hchild))
796 w = XWINDOW (w)->hchild;
797 else if (! NILP (XWINDOW (w)->vchild))
798 w = XWINDOW (w)->vchild;
799 else
800 abort ();
801 }
802 return w;
803}
804
805DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
806 Sactive_minibuffer_window, 0, 0, 0,
807 "Return the currently active minibuffer window, or nil if none.")
808 ()
809{
810 return minibuf_level ? minibuf_window : Qnil;
811}
812
813DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
814 "Returns the root-window of FRAME.\n\
815If omitted, FRAME defaults to the currently selected frame.")
816 (frame)
817 Lisp_Object frame;
818{
819 Lisp_Object window;
820
821 if (NILP (frame))
822 window = SELECTED_FRAME ()->root_window;
823 else
824 {
825 CHECK_LIVE_FRAME (frame, 0);
826 window = XFRAME (frame)->root_window;
827 }
828
829 return window;
830}
831
832DEFUN ("frame-selected-window", Fframe_selected_window,
833 Sframe_selected_window, 0, 1, 0,
834 "Return the selected window of frame object FRAME.\n\
835If omitted, FRAME defaults to the currently selected frame.")
836 (frame)
837 Lisp_Object frame;
838{
839 Lisp_Object window;
840
841 if (NILP (frame))
842 window = SELECTED_FRAME ()->selected_window;
843 else
844 {
845 CHECK_LIVE_FRAME (frame, 0);
846 window = XFRAME (frame)->selected_window;
847 }
848
849 return window;
850}
851
852DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
853 Sset_frame_selected_window, 2, 2, 0,
854 "Set the selected window of frame object FRAME to WINDOW.\n\
855If FRAME is nil, the selected frame is used.\n\
856If FRAME is the selected frame, this makes WINDOW the selected window.")
857 (frame, window)
858 Lisp_Object frame, window;
859{
860 if (NILP (frame))
861 frame = selected_frame;
862
863 CHECK_LIVE_FRAME (frame, 0);
864 CHECK_LIVE_WINDOW (window, 1);
865
866 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
867 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
868
869 if (EQ (frame, selected_frame))
870 return Fselect_window (window);
871
872 return XFRAME (frame)->selected_window = window;
873}
874\f
875DEFUN ("frame-list", Fframe_list, Sframe_list,
876 0, 0, 0,
877 "Return a list of all frames.")
878 ()
879{
880 return Fcopy_sequence (Vframe_list);
881}
882
883/* Return the next frame in the frame list after FRAME.
884 If MINIBUF is nil, exclude minibuffer-only frames.
885 If MINIBUF is a window, include only its own frame
886 and any frame now using that window as the minibuffer.
887 If MINIBUF is `visible', include all visible frames.
888 If MINIBUF is 0, include all visible and iconified frames.
889 Otherwise, include all frames. */
890
891Lisp_Object
892next_frame (frame, minibuf)
893 Lisp_Object frame;
894 Lisp_Object minibuf;
895{
896 Lisp_Object tail;
897 int passed = 0;
898
899 /* There must always be at least one frame in Vframe_list. */
900 if (! CONSP (Vframe_list))
901 abort ();
902
903 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
904 forever. Forestall that. */
905 CHECK_LIVE_FRAME (frame, 0);
906
907 while (1)
908 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
909 {
910 Lisp_Object f;
911
912 f = XCAR (tail);
913
914 if (passed
915 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
916 {
917 /* Decide whether this frame is eligible to be returned. */
918
919 /* If we've looped all the way around without finding any
920 eligible frames, return the original frame. */
921 if (EQ (f, frame))
922 return f;
923
924 /* Let minibuf decide if this frame is acceptable. */
925 if (NILP (minibuf))
926 {
927 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
928 return f;
929 }
930 else if (EQ (minibuf, Qvisible))
931 {
932 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
933 if (FRAME_VISIBLE_P (XFRAME (f)))
934 return f;
935 }
936 else if (XFASTINT (minibuf) == 0)
937 {
938 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
939 if (FRAME_VISIBLE_P (XFRAME (f))
940 || FRAME_ICONIFIED_P (XFRAME (f)))
941 return f;
942 }
943 else if (WINDOWP (minibuf))
944 {
945 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
946 /* Check that F either is, or has forwarded its focus to,
947 MINIBUF's frame. */
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
970Lisp_Object
971prev_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 /* Check that F either is, or has forwarded its focus to,
1007 MINIBUF's frame. */
1008 && (EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1009 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1010 FRAME_FOCUS_FRAME (XFRAME (f)))))
1011 prev = f;
1012 }
1013 else if (EQ (minibuf, Qvisible))
1014 {
1015 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1016 if (FRAME_VISIBLE_P (XFRAME (f)))
1017 prev = f;
1018 }
1019 else if (XFASTINT (minibuf) == 0)
1020 {
1021 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1022 if (FRAME_VISIBLE_P (XFRAME (f))
1023 || FRAME_ICONIFIED_P (XFRAME (f)))
1024 prev = f;
1025 }
1026 else
1027 prev = f;
1028 }
1029 }
1030
1031 /* We've scanned the entire list. */
1032 if (NILP (prev))
1033 /* We went through the whole frame list without finding a single
1034 acceptable frame. Return the original frame. */
1035 return frame;
1036 else
1037 /* There were no acceptable frames in the list before FRAME; otherwise,
1038 we would have returned directly from the loop. Since PREV is the last
1039 acceptable frame in the list, return it. */
1040 return prev;
1041}
1042
1043
1044DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1045 "Return the next frame in the frame list after FRAME.\n\
1046It considers only frames on the same terminal as FRAME.\n\
1047By default, skip minibuffer-only frames.\n\
1048If omitted, FRAME defaults to the selected frame.\n\
1049If optional argument MINIFRAME is nil, exclude minibuffer-only frames.\n\
1050If MINIFRAME is a window, include only its own frame\n\
1051and any frame now using that window as the minibuffer.\n\
1052If MINIFRAME is `visible', include all visible frames.\n\
1053If MINIFRAME is 0, include all visible and iconified frames.\n\
1054Otherwise, include all frames.")
1055 (frame, miniframe)
1056 Lisp_Object frame, miniframe;
1057{
1058 if (NILP (frame))
1059 frame = selected_frame;
1060
1061 CHECK_LIVE_FRAME (frame, 0);
1062 return next_frame (frame, miniframe);
1063}
1064
1065DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1066 "Return the previous frame in the frame list before FRAME.\n\
1067It considers only frames on the same terminal as FRAME.\n\
1068By default, skip minibuffer-only frames.\n\
1069If omitted, FRAME defaults to the selected frame.\n\
1070If optional argument MINIFRAME is nil, exclude minibuffer-only frames.\n\
1071If MINIFRAME is a window, include only its own frame\n\
1072and any frame now using that window as the minibuffer.\n\
1073If MINIFRAME is `visible', include all visible frames.\n\
1074If MINIFRAME is 0, include all visible and iconified frames.\n\
1075Otherwise, include all frames.")
1076 (frame, miniframe)
1077 Lisp_Object frame, miniframe;
1078{
1079 if (NILP (frame))
1080 frame = selected_frame;
1081 CHECK_LIVE_FRAME (frame, 0);
1082 return prev_frame (frame, miniframe);
1083}
1084\f
1085/* Return 1 if it is ok to delete frame F;
1086 0 if all frames aside from F are invisible.
1087 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1088
1089int
1090other_visible_frames (f)
1091 FRAME_PTR f;
1092{
1093 /* We know the selected frame is visible,
1094 so if F is some other frame, it can't be the sole visible one. */
1095 if (f == SELECTED_FRAME ())
1096 {
1097 Lisp_Object frames;
1098 int count = 0;
1099
1100 for (frames = Vframe_list;
1101 CONSP (frames);
1102 frames = XCDR (frames))
1103 {
1104 Lisp_Object this;
1105
1106 this = XCAR (frames);
1107 /* Verify that the frame's window still exists
1108 and we can still talk to it. And note any recent change
1109 in visibility. */
1110#ifdef HAVE_WINDOW_SYSTEM
1111 if (FRAME_WINDOW_P (XFRAME (this)))
1112 {
1113 x_sync (XFRAME (this));
1114 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1115 }
1116#endif
1117
1118 if (FRAME_VISIBLE_P (XFRAME (this))
1119 || FRAME_ICONIFIED_P (XFRAME (this))
1120 /* Allow deleting the terminal frame when at least
1121 one X frame exists! */
1122 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1123 count++;
1124 }
1125 return count > 1;
1126 }
1127 return 1;
1128}
1129
1130DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1131 "Delete FRAME, permanently eliminating it from use.\n\
1132If omitted, FRAME defaults to the selected frame.\n\
1133A frame may not be deleted if its minibuffer is used by other frames.\n\
1134Normally, you may not delete a frame if all other frames are invisible,\n\
1135but if the second optional argument FORCE is non-nil, you may do so.")
1136 (frame, force)
1137 Lisp_Object frame, force;
1138{
1139 struct frame *f;
1140 struct frame *sf = SELECTED_FRAME ();
1141 int minibuffer_selected;
1142
1143 if (EQ (frame, Qnil))
1144 {
1145 f = sf;
1146 XSETFRAME (frame, f);
1147 }
1148 else
1149 {
1150 CHECK_FRAME (frame, 0);
1151 f = XFRAME (frame);
1152 }
1153
1154 if (! FRAME_LIVE_P (f))
1155 return Qnil;
1156
1157 if (NILP (force) && !other_visible_frames (f))
1158 error ("Attempt to delete the sole visible or iconified frame");
1159
1160#if 0
1161 /* This is a nice idea, but x_connection_closed needs to be able
1162 to delete the last frame, if it is gone. */
1163 if (NILP (XCDR (Vframe_list)))
1164 error ("Attempt to delete the only frame");
1165#endif
1166
1167 /* Does this frame have a minibuffer, and is it the surrogate
1168 minibuffer for any other frame? */
1169 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1170 {
1171 Lisp_Object frames;
1172
1173 for (frames = Vframe_list;
1174 CONSP (frames);
1175 frames = XCDR (frames))
1176 {
1177 Lisp_Object this;
1178 this = XCAR (frames);
1179
1180 if (! EQ (this, frame)
1181 && EQ (frame,
1182 WINDOW_FRAME (XWINDOW
1183 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1184 error ("Attempt to delete a surrogate minibuffer frame");
1185 }
1186 }
1187
1188 minibuffer_selected = EQ (minibuf_window, selected_window);
1189
1190 /* Don't let the frame remain selected. */
1191 if (f == sf)
1192 {
1193 Lisp_Object tail, frame1;
1194
1195 /* Look for another visible frame on the same terminal. */
1196 frame1 = next_frame (frame, Qvisible);
1197
1198 /* If there is none, find *some* other frame. */
1199 if (NILP (frame1) || EQ (frame1, frame))
1200 {
1201 FOR_EACH_FRAME (tail, frame1)
1202 {
1203 if (! EQ (frame, frame1))
1204 break;
1205 }
1206 }
1207
1208 do_switch_frame (frame1, Qnil, 0);
1209 sf = SELECTED_FRAME ();
1210 }
1211
1212 /* Don't allow minibuf_window to remain on a deleted frame. */
1213 if (EQ (f->minibuffer_window, minibuf_window))
1214 {
1215 Fset_window_buffer (sf->minibuffer_window,
1216 XWINDOW (minibuf_window)->buffer);
1217 minibuf_window = sf->minibuffer_window;
1218
1219 /* If the dying minibuffer window was selected,
1220 select the new one. */
1221 if (minibuffer_selected)
1222 Fselect_window (minibuf_window);
1223 }
1224
1225 /* Don't let echo_area_window to remain on a deleted frame. */
1226 if (EQ (f->minibuffer_window, echo_area_window))
1227 echo_area_window = sf->minibuffer_window;
1228
1229 /* Clear any X selections for this frame. */
1230#ifdef HAVE_X_WINDOWS
1231 if (FRAME_X_P (f))
1232 x_clear_frame_selections (f);
1233#endif
1234
1235 /* Free glyphs.
1236 This function must be called before the window tree of the
1237 frame is deleted because windows contain dynamically allocated
1238 memory. */
1239 free_glyphs (f);
1240
1241 /* Mark all the windows that used to be on FRAME as deleted, and then
1242 remove the reference to them. */
1243 delete_all_subwindows (XWINDOW (f->root_window));
1244 f->root_window = Qnil;
1245
1246 Vframe_list = Fdelq (frame, Vframe_list);
1247 FRAME_SET_VISIBLE (f, 0);
1248
1249 if (f->namebuf)
1250 xfree (f->namebuf);
1251 if (FRAME_INSERT_COST (f))
1252 xfree (FRAME_INSERT_COST (f));
1253 if (FRAME_DELETEN_COST (f))
1254 xfree (FRAME_DELETEN_COST (f));
1255 if (FRAME_INSERTN_COST (f))
1256 xfree (FRAME_INSERTN_COST (f));
1257 if (FRAME_DELETE_COST (f))
1258 xfree (FRAME_DELETE_COST (f));
1259 if (FRAME_MESSAGE_BUF (f))
1260 xfree (FRAME_MESSAGE_BUF (f));
1261
1262#ifdef HAVE_WINDOW_SYSTEM
1263 /* Free all fontset data. */
1264 free_fontset_data (FRAME_FONTSET_DATA (f));
1265#endif
1266
1267 /* Since some events are handled at the interrupt level, we may get
1268 an event for f at any time; if we zero out the frame's display
1269 now, then we may trip up the event-handling code. Instead, we'll
1270 promise that the display of the frame must be valid until we have
1271 called the window-system-dependent frame destruction routine. */
1272
1273 /* I think this should be done with a hook. */
1274#ifdef HAVE_WINDOW_SYSTEM
1275 if (FRAME_WINDOW_P (f))
1276 x_destroy_window (f);
1277#endif
1278
1279/* Done by x_destroy_window above already */
1280#if 0
1281#ifdef macintosh
1282 if (FRAME_MAC_P (f))
1283 DisposeMacWindow (f->output_data.mac);
1284#endif
1285#endif
1286
1287 f->output_data.nothing = 0;
1288
1289 /* If we've deleted the last_nonminibuf_frame, then try to find
1290 another one. */
1291 if (f == last_nonminibuf_frame)
1292 {
1293 Lisp_Object frames;
1294
1295 last_nonminibuf_frame = 0;
1296
1297 for (frames = Vframe_list;
1298 CONSP (frames);
1299 frames = XCDR (frames))
1300 {
1301 f = XFRAME (XCAR (frames));
1302 if (!FRAME_MINIBUF_ONLY_P (f))
1303 {
1304 last_nonminibuf_frame = f;
1305 break;
1306 }
1307 }
1308 }
1309
1310 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1311 find another one. Prefer minibuffer-only frames, but also notice
1312 frames with other windows. */
1313 if (EQ (frame, FRAME_KBOARD (f)->Vdefault_minibuffer_frame))
1314 {
1315 Lisp_Object frames;
1316
1317 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1318 Lisp_Object frame_with_minibuf;
1319 /* Some frame we found on the same kboard, or nil if there are none. */
1320 Lisp_Object frame_on_same_kboard;
1321
1322 frame_on_same_kboard = Qnil;
1323 frame_with_minibuf = Qnil;
1324
1325 for (frames = Vframe_list;
1326 CONSP (frames);
1327 frames = XCDR (frames))
1328 {
1329 Lisp_Object this;
1330 struct frame *f1;
1331
1332 this = XCAR (frames);
1333 if (!FRAMEP (this))
1334 abort ();
1335 f1 = XFRAME (this);
1336
1337 /* Consider only frames on the same kboard
1338 and only those with minibuffers. */
1339 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)
1340 && FRAME_HAS_MINIBUF_P (f1))
1341 {
1342 frame_with_minibuf = this;
1343 if (FRAME_MINIBUF_ONLY_P (f1))
1344 break;
1345 }
1346
1347 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1))
1348 frame_on_same_kboard = this;
1349 }
1350
1351 if (!NILP (frame_on_same_kboard))
1352 {
1353 /* We know that there must be some frame with a minibuffer out
1354 there. If this were not true, all of the frames present
1355 would have to be minibufferless, which implies that at some
1356 point their minibuffer frames must have been deleted, but
1357 that is prohibited at the top; you can't delete surrogate
1358 minibuffer frames. */
1359 if (NILP (frame_with_minibuf))
1360 abort ();
1361
1362 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = frame_with_minibuf;
1363 }
1364 else
1365 /* No frames left on this kboard--say no minibuffer either. */
1366 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = Qnil;
1367 }
1368
1369 /* Cause frame titles to update--necessary if we now have just one frame. */
1370 update_mode_lines = 1;
1371
1372 return Qnil;
1373}
1374\f
1375/* Return mouse position in character cell units. */
1376
1377DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1378 "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
1379The position is given in character cells, where (0, 0) is the\n\
1380upper-left corner.\n\
1381If Emacs is running on a mouseless terminal or hasn't been programmed\n\
1382to read the mouse position, it returns the selected frame for FRAME\n\
1383and nil for X and Y.\n\
1384Runs the abnormal hook `mouse-position-function' with the normal return\n\
1385value as argument.")
1386 ()
1387{
1388 FRAME_PTR f;
1389 Lisp_Object lispy_dummy;
1390 enum scroll_bar_part party_dummy;
1391 Lisp_Object x, y, retval;
1392 int col, row;
1393 unsigned long long_dummy;
1394 struct gcpro gcpro1;
1395
1396 f = SELECTED_FRAME ();
1397 x = y = Qnil;
1398
1399#ifdef HAVE_MOUSE
1400 /* It's okay for the hook to refrain from storing anything. */
1401 if (mouse_position_hook)
1402 (*mouse_position_hook) (&f, -1,
1403 &lispy_dummy, &party_dummy,
1404 &x, &y,
1405 &long_dummy);
1406 if (! NILP (x))
1407 {
1408 col = XINT (x);
1409 row = XINT (y);
1410 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1411 XSETINT (x, col);
1412 XSETINT (y, row);
1413 }
1414#endif
1415 XSETFRAME (lispy_dummy, f);
1416 retval = Fcons (lispy_dummy, Fcons (x, y));
1417 GCPRO1 (retval);
1418 if (!NILP (Vmouse_position_function))
1419 retval = call1 (Vmouse_position_function, retval);
1420 RETURN_UNGCPRO (retval);
1421}
1422
1423DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1424 Smouse_pixel_position, 0, 0, 0,
1425 "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
1426The position is given in pixel units, where (0, 0) is the\n\
1427upper-left corner.\n\
1428If Emacs is running on a mouseless terminal or hasn't been programmed\n\
1429to read the mouse position, it returns the selected frame for FRAME\n\
1430and nil for X and Y.")
1431 ()
1432{
1433 FRAME_PTR f;
1434 Lisp_Object lispy_dummy;
1435 enum scroll_bar_part party_dummy;
1436 Lisp_Object x, y;
1437 unsigned long long_dummy;
1438
1439 f = SELECTED_FRAME ();
1440 x = y = Qnil;
1441
1442#ifdef HAVE_MOUSE
1443 /* It's okay for the hook to refrain from storing anything. */
1444 if (mouse_position_hook)
1445 (*mouse_position_hook) (&f, -1,
1446 &lispy_dummy, &party_dummy,
1447 &x, &y,
1448 &long_dummy);
1449#endif
1450 XSETFRAME (lispy_dummy, f);
1451 return Fcons (lispy_dummy, Fcons (x, y));
1452}
1453
1454DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1455 "Move the mouse pointer to the center of character cell (X,Y) in FRAME.\n\
1456Coordinates are relative to the frame, not a window,\n\
1457so the coordinates of the top left character in the frame\n\
1458may be nonzero due to left-hand scroll bars or the menu bar.\n\
1459\n\
1460This function is a no-op for an X frame that is not visible.\n\
1461If you have just created a frame, you must wait for it to become visible\n\
1462before calling this function on it, like this.\n\
1463 (while (not (frame-visible-p frame)) (sleep-for .5))")
1464 (frame, x, y)
1465 Lisp_Object frame, x, y;
1466{
1467 CHECK_LIVE_FRAME (frame, 0);
1468 CHECK_NUMBER (x, 2);
1469 CHECK_NUMBER (y, 1);
1470
1471 /* I think this should be done with a hook. */
1472#ifdef HAVE_WINDOW_SYSTEM
1473 if (FRAME_WINDOW_P (XFRAME (frame)))
1474 /* Warping the mouse will cause enternotify and focus events. */
1475 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1476#else
1477#if defined (MSDOS) && defined (HAVE_MOUSE)
1478 if (FRAME_MSDOS_P (XFRAME (frame)))
1479 {
1480 Fselect_frame (frame, Qnil);
1481 mouse_moveto (XINT (x), XINT (y));
1482 }
1483#endif
1484#endif
1485
1486 return Qnil;
1487}
1488
1489DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1490 Sset_mouse_pixel_position, 3, 3, 0,
1491 "Move the mouse pointer to pixel position (X,Y) in FRAME.\n\
1492Note, this is a no-op for an X frame that is not visible.\n\
1493If you have just created a frame, you must wait for it to become visible\n\
1494before calling this function on it, like this.\n\
1495 (while (not (frame-visible-p frame)) (sleep-for .5))")
1496 (frame, x, y)
1497 Lisp_Object frame, x, y;
1498{
1499 CHECK_LIVE_FRAME (frame, 0);
1500 CHECK_NUMBER (x, 2);
1501 CHECK_NUMBER (y, 1);
1502
1503 /* I think this should be done with a hook. */
1504#ifdef HAVE_WINDOW_SYSTEM
1505 if (FRAME_WINDOW_P (XFRAME (frame)))
1506 /* Warping the mouse will cause enternotify and focus events. */
1507 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1508#else
1509#if defined (MSDOS) && defined (HAVE_MOUSE)
1510 if (FRAME_MSDOS_P (XFRAME (frame)))
1511 {
1512 Fselect_frame (frame, Qnil);
1513 mouse_moveto (XINT (x), XINT (y));
1514 }
1515#endif
1516#endif
1517
1518 return Qnil;
1519}
1520\f
1521static void make_frame_visible_1 P_ ((Lisp_Object));
1522
1523DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1524 0, 1, "",
1525 "Make the frame FRAME visible (assuming it is an X-window).\n\
1526If omitted, FRAME defaults to the currently selected frame.")
1527 (frame)
1528 Lisp_Object frame;
1529{
1530 if (NILP (frame))
1531 frame = selected_frame;
1532
1533 CHECK_LIVE_FRAME (frame, 0);
1534
1535 /* I think this should be done with a hook. */
1536#ifdef HAVE_WINDOW_SYSTEM
1537 if (FRAME_WINDOW_P (XFRAME (frame)))
1538 {
1539 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1540 x_make_frame_visible (XFRAME (frame));
1541 }
1542#endif
1543
1544 make_frame_visible_1 (XFRAME (frame)->root_window);
1545
1546 /* Make menu bar update for the Buffers and Frams menus. */
1547 windows_or_buffers_changed++;
1548
1549 return frame;
1550}
1551
1552/* Update the display_time slot of the buffers shown in WINDOW
1553 and all its descendents. */
1554
1555static void
1556make_frame_visible_1 (window)
1557 Lisp_Object window;
1558{
1559 struct window *w;
1560
1561 for (;!NILP (window); window = w->next)
1562 {
1563 w = XWINDOW (window);
1564
1565 if (!NILP (w->buffer))
1566 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1567
1568 if (!NILP (w->vchild))
1569 make_frame_visible_1 (w->vchild);
1570 if (!NILP (w->hchild))
1571 make_frame_visible_1 (w->hchild);
1572 }
1573}
1574
1575DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1576 0, 2, "",
1577 "Make the frame FRAME invisible (assuming it is an X-window).\n\
1578If omitted, FRAME defaults to the currently selected frame.\n\
1579Normally you may not make FRAME invisible if all other frames are invisible,\n\
1580but if the second optional argument FORCE is non-nil, you may do so.")
1581 (frame, force)
1582 Lisp_Object frame, force;
1583{
1584 if (NILP (frame))
1585 frame = selected_frame;
1586
1587 CHECK_LIVE_FRAME (frame, 0);
1588
1589 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1590 error ("Attempt to make invisible the sole visible or iconified frame");
1591
1592#if 0 /* This isn't logically necessary, and it can do GC. */
1593 /* Don't let the frame remain selected. */
1594 if (EQ (frame, selected_frame))
1595 do_switch_frame (next_frame (frame, Qt), Qnil, 0)
1596#endif
1597
1598 /* Don't allow minibuf_window to remain on a deleted frame. */
1599 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1600 {
1601 struct frame *sf = XFRAME (selected_frame);
1602 Fset_window_buffer (sf->minibuffer_window,
1603 XWINDOW (minibuf_window)->buffer);
1604 minibuf_window = sf->minibuffer_window;
1605 }
1606
1607 /* I think this should be done with a hook. */
1608#ifdef HAVE_WINDOW_SYSTEM
1609 if (FRAME_WINDOW_P (XFRAME (frame)))
1610 x_make_frame_invisible (XFRAME (frame));
1611#endif
1612
1613 /* Make menu bar update for the Buffers and Frams menus. */
1614 windows_or_buffers_changed++;
1615
1616 return Qnil;
1617}
1618
1619DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1620 0, 1, "",
1621 "Make the frame FRAME into an icon.\n\
1622If omitted, FRAME defaults to the currently selected frame.")
1623 (frame)
1624 Lisp_Object frame;
1625{
1626 if (NILP (frame))
1627 frame = selected_frame;
1628
1629 CHECK_LIVE_FRAME (frame, 0);
1630
1631#if 0 /* This isn't logically necessary, and it can do GC. */
1632 /* Don't let the frame remain selected. */
1633 if (EQ (frame, selected_frame))
1634 Fhandle_switch_frame (next_frame (frame, Qt), Qnil);
1635#endif
1636
1637 /* Don't allow minibuf_window to remain on a deleted frame. */
1638 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1639 {
1640 struct frame *sf = XFRAME (selected_frame);
1641 Fset_window_buffer (sf->minibuffer_window,
1642 XWINDOW (minibuf_window)->buffer);
1643 minibuf_window = sf->minibuffer_window;
1644 }
1645
1646 /* I think this should be done with a hook. */
1647#ifdef HAVE_WINDOW_SYSTEM
1648 if (FRAME_WINDOW_P (XFRAME (frame)))
1649 x_iconify_frame (XFRAME (frame));
1650#endif
1651
1652 /* Make menu bar update for the Buffers and Frams menus. */
1653 windows_or_buffers_changed++;
1654
1655 return Qnil;
1656}
1657
1658DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1659 1, 1, 0,
1660 "Return t if FRAME is now \"visible\" (actually in use for display).\n\
1661A frame that is not \"visible\" is not updated and, if it works through\n\
1662a window system, it may not show at all.\n\
1663Return the symbol `icon' if frame is visible only as an icon.")
1664 (frame)
1665 Lisp_Object frame;
1666{
1667 CHECK_LIVE_FRAME (frame, 0);
1668
1669 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1670
1671 if (FRAME_VISIBLE_P (XFRAME (frame)))
1672 return Qt;
1673 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1674 return Qicon;
1675 return Qnil;
1676}
1677
1678DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1679 0, 0, 0,
1680 "Return a list of all frames now \"visible\" (being updated).")
1681 ()
1682{
1683 Lisp_Object tail, frame;
1684 struct frame *f;
1685 Lisp_Object value;
1686
1687 value = Qnil;
1688 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1689 {
1690 frame = XCAR (tail);
1691 if (!FRAMEP (frame))
1692 continue;
1693 f = XFRAME (frame);
1694 if (FRAME_VISIBLE_P (f))
1695 value = Fcons (frame, value);
1696 }
1697 return value;
1698}
1699
1700
1701DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1702 "Bring FRAME to the front, so it occludes any frames it overlaps.\n\
1703If FRAME is invisible, make it visible.\n\
1704If you don't specify a frame, the selected frame is used.\n\
1705If Emacs is displaying on an ordinary terminal or some other device which\n\
1706doesn't support multiple overlapping frames, this function does nothing.")
1707 (frame)
1708 Lisp_Object frame;
1709{
1710 if (NILP (frame))
1711 frame = selected_frame;
1712
1713 CHECK_LIVE_FRAME (frame, 0);
1714
1715 /* Do like the documentation says. */
1716 Fmake_frame_visible (frame);
1717
1718 if (frame_raise_lower_hook)
1719 (*frame_raise_lower_hook) (XFRAME (frame), 1);
1720
1721 return Qnil;
1722}
1723
1724/* Should we have a corresponding function called Flower_Power? */
1725DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1726 "Send FRAME to the back, so it is occluded by any frames that overlap it.\n\
1727If you don't specify a frame, the selected frame is used.\n\
1728If Emacs is displaying on an ordinary terminal or some other device which\n\
1729doesn't support multiple overlapping frames, this function does nothing.")
1730 (frame)
1731 Lisp_Object frame;
1732{
1733 if (NILP (frame))
1734 frame = selected_frame;
1735
1736 CHECK_LIVE_FRAME (frame, 0);
1737
1738 if (frame_raise_lower_hook)
1739 (*frame_raise_lower_hook) (XFRAME (frame), 0);
1740
1741 return Qnil;
1742}
1743
1744\f
1745DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1746 1, 2, 0,
1747 "Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.\n\
1748In other words, switch-frame events caused by events in FRAME will\n\
1749request a switch to FOCUS-FRAME, and `last-event-frame' will be\n\
1750FOCUS-FRAME after reading an event typed at FRAME.\n\
1751\n\
1752If FOCUS-FRAME is omitted or nil, any existing redirection is\n\
1753cancelled, and the frame again receives its own keystrokes.\n\
1754\n\
1755Focus redirection is useful for temporarily redirecting keystrokes to\n\
1756a surrogate minibuffer frame when a frame doesn't have its own\n\
1757minibuffer window.\n\
1758\n\
1759A frame's focus redirection can be changed by select-frame. If frame\n\
1760FOO is selected, and then a different frame BAR is selected, any\n\
1761frames redirecting their focus to FOO are shifted to redirect their\n\
1762focus to BAR. This allows focus redirection to work properly when the\n\
1763user switches from one frame to another using `select-window'.\n\
1764\n\
1765This means that a frame whose focus is redirected to itself is treated\n\
1766differently from a frame whose focus is redirected to nil; the former\n\
1767is affected by select-frame, while the latter is not.\n\
1768\n\
1769The redirection lasts until `redirect-frame-focus' is called to change it.")
1770 (frame, focus_frame)
1771 Lisp_Object frame, focus_frame;
1772{
1773 /* Note that we don't check for a live frame here. It's reasonable
1774 to redirect the focus of a frame you're about to delete, if you
1775 know what other frame should receive those keystrokes. */
1776 CHECK_FRAME (frame, 0);
1777
1778 if (! NILP (focus_frame))
1779 CHECK_LIVE_FRAME (focus_frame, 1);
1780
1781 XFRAME (frame)->focus_frame = focus_frame;
1782
1783 if (frame_rehighlight_hook)
1784 (*frame_rehighlight_hook) (XFRAME (frame));
1785
1786 return Qnil;
1787}
1788
1789
1790DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1791 "Return the frame to which FRAME's keystrokes are currently being sent.\n\
1792This returns nil if FRAME's focus is not redirected.\n\
1793See `redirect-frame-focus'.")
1794 (frame)
1795 Lisp_Object frame;
1796{
1797 CHECK_LIVE_FRAME (frame, 0);
1798
1799 return FRAME_FOCUS_FRAME (XFRAME (frame));
1800}
1801
1802
1803\f
1804/* Return the value of frame parameter PROP in frame FRAME. */
1805
1806Lisp_Object
1807get_frame_param (frame, prop)
1808 register struct frame *frame;
1809 Lisp_Object prop;
1810{
1811 register Lisp_Object tem;
1812
1813 tem = Fassq (prop, frame->param_alist);
1814 if (EQ (tem, Qnil))
1815 return tem;
1816 return Fcdr (tem);
1817}
1818
1819/* Return the buffer-predicate of the selected frame. */
1820
1821Lisp_Object
1822frame_buffer_predicate (frame)
1823 Lisp_Object frame;
1824{
1825 return XFRAME (frame)->buffer_predicate;
1826}
1827
1828/* Return the buffer-list of the selected frame. */
1829
1830Lisp_Object
1831frame_buffer_list (frame)
1832 Lisp_Object frame;
1833{
1834 return XFRAME (frame)->buffer_list;
1835}
1836
1837/* Set the buffer-list of the selected frame. */
1838
1839void
1840set_frame_buffer_list (frame, list)
1841 Lisp_Object frame, list;
1842{
1843 XFRAME (frame)->buffer_list = list;
1844}
1845
1846/* Discard BUFFER from the buffer-list of each frame. */
1847
1848void
1849frames_discard_buffer (buffer)
1850 Lisp_Object buffer;
1851{
1852 Lisp_Object frame, tail;
1853
1854 FOR_EACH_FRAME (tail, frame)
1855 {
1856 XFRAME (frame)->buffer_list
1857 = Fdelq (buffer, XFRAME (frame)->buffer_list);
1858 }
1859}
1860
1861/* Move BUFFER to the end of the buffer-list of each frame. */
1862
1863void
1864frames_bury_buffer (buffer)
1865 Lisp_Object buffer;
1866{
1867 Lisp_Object frame, tail;
1868
1869 FOR_EACH_FRAME (tail, frame)
1870 {
1871 XFRAME (frame)->buffer_list
1872 = nconc2 (Fdelq (buffer, XFRAME (frame)->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
1880void
1881store_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
1894static int
1895frame_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
1914void
1915set_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
1954void
1955store_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
1998DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
1999 "Return the parameters-alist of frame FRAME.\n\
2000It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.\n\
2001The meaningful PARMs depend on the kind of frame.\n\
2002If 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
2068DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2069 Smodify_frame_parameters, 2, 2, 0,
2070 "Modify the parameters of frame FRAME according to ALIST.\n\
2071ALIST is an alist of parameters to change and their new values.\n\
2072Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.\n\
2073The meaningful PARMs depend on the kind of frame.\n\
2074Undefined PARMs are ignored, but stored in the frame's parameter list\n\
2075so 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
2137DEFUN ("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\
2140If FRAME is omitted, the selected frame is used.\n\
2141For 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
2161DEFUN ("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\
2164If FRAME is omitted, the selected frame is used.\n\
2165The width is the same for all characters, because\n\
2166currently Emacs supports only fixed-width fonts.\n\
2167For 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
2186DEFUN ("frame-pixel-height", Fframe_pixel_height,
2187 Sframe_pixel_height, 0, 1, 0,
2188 "Return a FRAME's height in pixels.\n\
2189This counts only the height available for text lines,\n\
2190not menu bars on window-system Emacs frames.\n\
2191For a terminal frame, the result really gives the height in characters.\n\
2192If 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
2211DEFUN ("frame-pixel-width", Fframe_pixel_width,
2212 Sframe_pixel_width, 0, 1, 0,
2213 "Return FRAME's width in pixels.\n\
2214For a terminal frame, the result really gives the width in characters.\n\
2215If 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
2234DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2235 "Specify that the frame FRAME has LINES lines.\n\
2236Optional third arg non-nil means that redisplay should use LINES lines\n\
2237but 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
2263DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2264 "Specify that the frame FRAME has COLS columns.\n\
2265Optional third arg non-nil means that redisplay should use COLS columns\n\
2266but 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
2291DEFUN ("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
2319DEFUN ("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\
2322This is actually the position of the upper left corner of the frame.\n\
2323Negative values for XOFFSET or YOFFSET are interpreted relative to\n\
2324the 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
2345void
2346syms_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\
2361This abnormal hook exists for the benefit of packages like XTerm-mouse\n\
2362which 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\
2368Emacs cannot create minibufferless frames unless this is set to an\n\
2369appropriate surrogate.\n\
2370\n\
2371Emacs consults this variable only when creating minibufferless\n\
2372frames; once the frame is created, it sticks with its assigned\n\
2373minibuffer, no matter what this variable is set to. This means that\n\
2374this variable doesn't necessarily say anything meaningful about the\n\
2375current set of frames, or where the minibuffer is currently being\n\
2376displayed.");
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
2424void
2425keys_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}