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