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