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