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