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