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