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