(Fget_buffer_create, init_buffer_once): Use XSETPVECTYPE.
[emacs.git] / src / frame.c
blob702596e2b98e87857e91f054a41751218e367f0b
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #include <config.h>
24 #include <stdio.h>
25 #include "lisp.h"
26 #include "charset.h"
27 #ifdef HAVE_X_WINDOWS
28 #include "xterm.h"
29 #endif
30 #ifdef WINDOWSNT
31 #include "w32term.h"
32 #endif
33 #ifdef MAC_OS
34 #include "macterm.h"
35 #endif
36 #include "buffer.h"
37 /* These help us bind and responding to switch-frame events. */
38 #include "commands.h"
39 #include "keyboard.h"
40 #include "frame.h"
41 #ifdef HAVE_WINDOW_SYSTEM
42 #include "fontset.h"
43 #endif
44 #include "blockinput.h"
45 #include "termchar.h"
46 #include "termhooks.h"
47 #include "dispextern.h"
48 #include "window.h"
49 #ifdef MSDOS
50 #include "msdos.h"
51 #include "dosfns.h"
52 #endif
55 #ifdef HAVE_WINDOW_SYSTEM
57 /* The name we're using in resource queries. Most often "emacs". */
59 Lisp_Object Vx_resource_name;
61 /* The application class we're using in resource queries.
62 Normally "Emacs". */
64 Lisp_Object Vx_resource_class;
66 #endif
68 Lisp_Object Qframep, Qframe_live_p;
69 Lisp_Object Qicon, Qmodeline;
70 Lisp_Object Qonly;
71 Lisp_Object Qx, Qw32, Qmac, Qpc;
72 Lisp_Object Qvisible;
73 Lisp_Object Qdisplay_type;
74 Lisp_Object Qbackground_mode;
76 Lisp_Object Qx_frame_parameter;
77 Lisp_Object Qx_resource_name;
78 Lisp_Object Qterminal;
79 Lisp_Object Qterminal_live_p;
81 /* Frame parameters (set or reported). */
83 Lisp_Object Qauto_raise, Qauto_lower;
84 Lisp_Object Qborder_color, Qborder_width;
85 Lisp_Object Qcursor_color, Qcursor_type;
86 Lisp_Object Qgeometry; /* Not used */
87 Lisp_Object Qheight, Qwidth;
88 Lisp_Object Qleft, Qright;
89 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
90 Lisp_Object Qinternal_border_width;
91 Lisp_Object Qmouse_color;
92 Lisp_Object Qminibuffer;
93 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
94 Lisp_Object Qvisibility;
95 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
96 Lisp_Object Qscreen_gamma;
97 Lisp_Object Qline_spacing;
98 Lisp_Object Quser_position, Quser_size;
99 Lisp_Object Qwait_for_wm;
100 Lisp_Object Qwindow_id;
101 #ifdef HAVE_X_WINDOWS
102 Lisp_Object Qouter_window_id;
103 #endif
104 Lisp_Object Qparent_id;
105 Lisp_Object Qtitle, Qname;
106 Lisp_Object Qunsplittable;
107 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
108 Lisp_Object Qleft_fringe, Qright_fringe;
109 Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list;
110 Lisp_Object Qtty_color_mode;
111 Lisp_Object Qtty, Qtty_type;
112 Lisp_Object Qwindow_system;
113 Lisp_Object Qenvironment;
115 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
117 Lisp_Object Qinhibit_face_set_after_frame_default;
118 Lisp_Object Qface_set_after_frame_default;
120 Lisp_Object Vterminal_frame;
121 Lisp_Object Vdefault_frame_alist;
122 Lisp_Object Vdefault_frame_scroll_bars;
123 Lisp_Object Vmouse_position_function;
124 Lisp_Object Vmouse_highlight;
125 Lisp_Object Vdelete_frame_functions;
127 static void
128 set_menu_bar_lines_1 (window, n)
129 Lisp_Object window;
130 int n;
132 struct window *w = XWINDOW (window);
134 XSETFASTINT (w->last_modified, 0);
135 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
136 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
138 if (INTEGERP (w->orig_top_line))
139 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
140 if (INTEGERP (w->orig_total_lines))
141 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
143 /* Handle just the top child in a vertical split. */
144 if (!NILP (w->vchild))
145 set_menu_bar_lines_1 (w->vchild, n);
147 /* Adjust all children in a horizontal split. */
148 for (window = w->hchild; !NILP (window); window = w->next)
150 w = XWINDOW (window);
151 set_menu_bar_lines_1 (window, n);
155 void
156 set_menu_bar_lines (f, value, oldval)
157 struct frame *f;
158 Lisp_Object value, oldval;
160 int nlines;
161 int olines = FRAME_MENU_BAR_LINES (f);
163 /* Right now, menu bars don't work properly in minibuf-only frames;
164 most of the commands try to apply themselves to the minibuffer
165 frame itself, and get an error because you can't switch buffers
166 in or split the minibuffer window. */
167 if (FRAME_MINIBUF_ONLY_P (f))
168 return;
170 if (INTEGERP (value))
171 nlines = XINT (value);
172 else
173 nlines = 0;
175 if (nlines != olines)
177 windows_or_buffers_changed++;
178 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
179 FRAME_MENU_BAR_LINES (f) = nlines;
180 set_menu_bar_lines_1 (f->root_window, nlines - olines);
181 adjust_glyphs (f);
185 Lisp_Object Vemacs_iconified;
186 Lisp_Object Vframe_list;
188 extern Lisp_Object Vminibuffer_list;
189 extern Lisp_Object get_minibuffer ();
190 extern Lisp_Object Fhandle_switch_frame ();
191 extern Lisp_Object Fredirect_frame_focus ();
192 extern Lisp_Object x_get_focus_frame ();
194 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
195 doc: /* Return non-nil if OBJECT is a frame.
196 Value is t for a termcap frame (a character-only terminal),
197 `x' for an Emacs frame that is really an X window,
198 `w32' for an Emacs frame that is a window on MS-Windows display,
199 `mac' for an Emacs frame on a Macintosh display,
200 `pc' for a direct-write MS-DOS frame.
201 See also `frame-live-p'. */)
202 (object)
203 Lisp_Object object;
205 if (!FRAMEP (object))
206 return Qnil;
207 switch (XFRAME (object)->output_method)
209 case output_initial: /* The initial frame is like a termcap frame. */
210 case output_termcap:
211 return Qt;
212 case output_x_window:
213 return Qx;
214 case output_w32:
215 return Qw32;
216 case output_msdos_raw:
217 return Qpc;
218 case output_mac:
219 return Qmac;
220 default:
221 abort ();
225 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
226 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
227 Value is nil if OBJECT is not a live frame. If object is a live
228 frame, the return value indicates what sort of terminal device it is
229 displayed on. See the documentation of `framep' for possible
230 return values. */)
231 (object)
232 Lisp_Object object;
234 return ((FRAMEP (object)
235 && FRAME_LIVE_P (XFRAME (object)))
236 ? Fframep (object)
237 : Qnil);
240 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
241 doc: /* The name of the window system that FRAME is displaying through.
242 The value is a symbol---for instance, 'x' for X windows.
243 The value is nil if Emacs is using a text-only terminal.
245 FRAME defaults to the currently selected frame. */)
246 (frame)
247 Lisp_Object frame;
249 Lisp_Object type;
250 if (NILP (frame))
251 frame = selected_frame;
253 type = Fframep (frame);
255 if (NILP (type))
256 wrong_type_argument (Qframep, frame);
258 if (EQ (type, Qt))
259 return Qnil;
260 else
261 return type;
264 struct frame *
265 make_frame (mini_p)
266 int mini_p;
268 Lisp_Object frame;
269 register struct frame *f;
270 register Lisp_Object root_window;
271 register Lisp_Object mini_window;
273 f = allocate_frame ();
274 XSETFRAME (frame, f);
276 f->desired_matrix = 0;
277 f->current_matrix = 0;
278 f->desired_pool = 0;
279 f->current_pool = 0;
280 f->glyphs_initialized_p = 0;
281 f->decode_mode_spec_buffer = 0;
282 f->visible = 0;
283 f->async_visible = 0;
284 f->output_data.nothing = 0;
285 f->iconified = 0;
286 f->async_iconified = 0;
287 f->wants_modeline = 1;
288 f->auto_raise = 0;
289 f->auto_lower = 0;
290 f->no_split = 0;
291 f->garbaged = 1;
292 f->has_minibuffer = mini_p;
293 f->focus_frame = Qnil;
294 f->explicit_name = 0;
295 f->can_have_scroll_bars = 0;
296 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
297 f->param_alist = Qnil;
298 f->scroll_bars = Qnil;
299 f->condemned_scroll_bars = Qnil;
300 f->face_alist = Qnil;
301 f->face_cache = NULL;
302 f->menu_bar_items = Qnil;
303 f->menu_bar_vector = Qnil;
304 f->menu_bar_items_used = 0;
305 f->buffer_predicate = Qnil;
306 f->buffer_list = Qnil;
307 f->buried_buffer_list = Qnil;
308 f->namebuf = 0;
309 f->title = Qnil;
310 f->menu_bar_window = Qnil;
311 f->tool_bar_window = Qnil;
312 f->tool_bar_items = Qnil;
313 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
314 f->n_tool_bar_items = 0;
315 f->left_fringe_width = f->right_fringe_width = 0;
316 f->fringe_cols = 0;
317 f->scroll_bar_actual_width = 0;
318 f->border_width = 0;
319 f->internal_border_width = 0;
320 f->column_width = 1; /* !FRAME_WINDOW_P value */
321 f->line_height = 1; /* !FRAME_WINDOW_P value */
322 f->x_pixels_diff = f->y_pixels_diff = 0;
323 #ifdef HAVE_WINDOW_SYSTEM
324 f->want_fullscreen = FULLSCREEN_NONE;
325 #endif
326 f->size_hint_flags = 0;
327 f->win_gravity = 0;
329 root_window = make_window ();
330 if (mini_p)
332 mini_window = make_window ();
333 XWINDOW (root_window)->next = mini_window;
334 XWINDOW (mini_window)->prev = root_window;
335 XWINDOW (mini_window)->mini_p = Qt;
336 XWINDOW (mini_window)->frame = frame;
337 f->minibuffer_window = mini_window;
339 else
341 mini_window = Qnil;
342 XWINDOW (root_window)->next = Qnil;
343 f->minibuffer_window = Qnil;
346 XWINDOW (root_window)->frame = frame;
348 /* 10 is arbitrary,
349 just so that there is "something there."
350 Correct size will be set up later with change_frame_size. */
352 SET_FRAME_COLS (f, 10);
353 FRAME_LINES (f) = 10;
355 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
356 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
358 if (mini_p)
360 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
361 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
362 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
365 /* Choose a buffer for the frame's root window. */
367 Lisp_Object buf;
369 XWINDOW (root_window)->buffer = Qt;
370 buf = Fcurrent_buffer ();
371 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
372 a space), try to find another one. */
373 if (SREF (Fbuffer_name (buf), 0) == ' ')
374 buf = Fother_buffer (buf, Qnil, Qnil);
376 /* Use set_window_buffer, not Fset_window_buffer, and don't let
377 hooks be run by it. The reason is that the whole frame/window
378 arrangement is not yet fully intialized at this point. Windows
379 don't have the right size, glyph matrices aren't initialized
380 etc. Running Lisp functions at this point surely ends in a
381 SEGV. */
382 set_window_buffer (root_window, buf, 0, 0);
383 f->buffer_list = Fcons (buf, Qnil);
386 if (mini_p)
388 XWINDOW (mini_window)->buffer = Qt;
389 set_window_buffer (mini_window,
390 (NILP (Vminibuffer_list)
391 ? get_minibuffer (0)
392 : Fcar (Vminibuffer_list)),
393 0, 0);
396 f->root_window = root_window;
397 f->selected_window = root_window;
398 /* Make sure this window seems more recently used than
399 a newly-created, never-selected window. */
400 ++window_select_count;
401 XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
403 f->default_face_done_p = 0;
405 return f;
408 #ifdef HAVE_WINDOW_SYSTEM
409 /* Make a frame using a separate minibuffer window on another frame.
410 MINI_WINDOW is the minibuffer window to use. nil means use the
411 default (the global minibuffer). */
413 struct frame *
414 make_frame_without_minibuffer (mini_window, kb, display)
415 register Lisp_Object mini_window;
416 KBOARD *kb;
417 Lisp_Object display;
419 register struct frame *f;
420 struct gcpro gcpro1;
422 if (!NILP (mini_window))
423 CHECK_LIVE_WINDOW (mini_window);
425 #ifdef MULTI_KBOARD
426 if (!NILP (mini_window)
427 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
428 error ("Frame and minibuffer must be on the same terminal");
429 #endif
431 /* Make a frame containing just a root window. */
432 f = make_frame (0);
434 if (NILP (mini_window))
436 /* Use default-minibuffer-frame if possible. */
437 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
438 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
440 Lisp_Object frame_dummy;
442 XSETFRAME (frame_dummy, f);
443 GCPRO1 (frame_dummy);
444 /* If there's no minibuffer frame to use, create one. */
445 kb->Vdefault_minibuffer_frame =
446 call1 (intern ("make-initial-minibuffer-frame"), display);
447 UNGCPRO;
450 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
453 f->minibuffer_window = mini_window;
455 /* Make the chosen minibuffer window display the proper minibuffer,
456 unless it is already showing a minibuffer. */
457 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
458 Fset_window_buffer (mini_window,
459 (NILP (Vminibuffer_list)
460 ? get_minibuffer (0)
461 : Fcar (Vminibuffer_list)), Qnil);
462 return f;
465 /* Make a frame containing only a minibuffer window. */
467 struct frame *
468 make_minibuffer_frame ()
470 /* First make a frame containing just a root window, no minibuffer. */
472 register struct frame *f = make_frame (0);
473 register Lisp_Object mini_window;
474 register Lisp_Object frame;
476 XSETFRAME (frame, f);
478 f->auto_raise = 0;
479 f->auto_lower = 0;
480 f->no_split = 1;
481 f->wants_modeline = 0;
482 f->has_minibuffer = 1;
484 /* Now label the root window as also being the minibuffer.
485 Avoid infinite looping on the window chain by marking next pointer
486 as nil. */
488 mini_window = f->minibuffer_window = f->root_window;
489 XWINDOW (mini_window)->mini_p = Qt;
490 XWINDOW (mini_window)->next = Qnil;
491 XWINDOW (mini_window)->prev = Qnil;
492 XWINDOW (mini_window)->frame = frame;
494 /* Put the proper buffer in that window. */
496 Fset_window_buffer (mini_window,
497 (NILP (Vminibuffer_list)
498 ? get_minibuffer (0)
499 : Fcar (Vminibuffer_list)), Qnil);
500 return f;
502 #endif /* HAVE_WINDOW_SYSTEM */
504 /* Construct a frame that refers to a terminal. */
506 static int tty_frame_count;
508 struct frame *
509 make_initial_frame (void)
511 struct frame *f;
512 struct terminal *terminal;
513 Lisp_Object frame;
515 #ifdef MULTI_KBOARD
516 /* Create the initial keyboard. */
517 if (!initial_kboard)
519 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
520 init_kboard (initial_kboard);
521 initial_kboard->next_kboard = all_kboards;
522 all_kboards = initial_kboard;
524 #endif
526 /* The first call must initialize Vframe_list. */
527 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
528 Vframe_list = Qnil;
530 terminal = init_initial_terminal ();
532 f = make_frame (1);
533 XSETFRAME (frame, f);
535 Vframe_list = Fcons (frame, Vframe_list);
537 tty_frame_count = 1;
538 f->name = build_string ("F1");
540 f->visible = 1;
541 f->async_visible = 1;
543 f->output_method = terminal->type;
544 f->terminal = terminal;
545 f->terminal->reference_count++;
546 f->output_data.nothing = 0;
548 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
549 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
551 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
552 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
554 return f;
558 struct frame *
559 make_terminal_frame (struct terminal *terminal)
561 register struct frame *f;
562 Lisp_Object frame;
563 char name[20];
565 if (!terminal->name)
566 error ("Terminal is not live, can't create new frames on it");
568 f = make_frame (1);
570 XSETFRAME (frame, f);
571 Vframe_list = Fcons (frame, Vframe_list);
573 tty_frame_count++;
574 sprintf (name, "F%d", tty_frame_count);
575 f->name = build_string (name);
577 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
578 f->async_visible = 1; /* Don't let visible be cleared later. */
579 #ifdef MSDOS
580 f->output_data.x = &the_only_x_display;
581 if (!inhibit_window_system
582 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
583 || XFRAME (selected_frame)->output_method == output_msdos_raw))
585 f->output_method = output_msdos_raw;
586 /* This initialization of foreground and background pixels is
587 only important for the initial frame created in temacs. If
588 we don't do that, we get black background and foreground in
589 the dumped Emacs because the_only_x_display is a static
590 variable, hence it is born all-zeroes, and zero is the code
591 for the black color. Other frames all inherit their pixels
592 from what's already in the_only_x_display. */
593 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
594 && FRAME_BACKGROUND_PIXEL (f) == 0
595 && FRAME_FOREGROUND_PIXEL (f) == 0)
597 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
598 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
601 else
602 f->output_method = output_termcap;
603 #else
604 #ifdef MAC_OS8
605 make_mac_terminal_frame (f);
606 #else
608 f->output_method = output_termcap;
609 f->terminal = terminal;
610 f->terminal->reference_count++;
611 create_tty_output (f);
613 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
614 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
616 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
617 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
619 /* Set the top frame to the newly created frame. */
620 if (FRAMEP (FRAME_TTY (f)->top_frame)
621 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
622 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
624 FRAME_TTY (f)->top_frame = frame;
627 #ifdef CANNOT_DUMP
628 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
629 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
630 #endif
631 #endif /* MAC_OS8 */
632 #endif /* MSDOS */
634 if (!noninteractive)
635 init_frame_faces (f);
637 return f;
640 /* Get a suitable value for frame parameter PARAMETER for a newly
641 created frame, based on (1) the user-supplied frame parameter
642 alist SUPPLIED_PARMS, (2) CURRENT_VALUE, and finally, if all else
643 fails, (3) Vdefault_frame_alist. */
645 static Lisp_Object
646 get_future_frame_param (Lisp_Object parameter,
647 Lisp_Object supplied_parms,
648 char *current_value)
650 Lisp_Object result;
652 result = Fassq (parameter, supplied_parms);
653 if (NILP (result))
654 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
655 if (NILP (result) && current_value != NULL)
656 result = build_string (current_value);
657 if (NILP (result))
658 result = Fassq (parameter, Vdefault_frame_alist);
659 if (!NILP (result) && !STRINGP (result))
660 result = XCDR (result);
661 if (NILP (result) || !STRINGP (result))
662 result = Qnil;
664 return result;
667 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
668 1, 1, 0,
669 doc: /* Create an additional terminal frame, possibly on another terminal.
670 This function takes one argument, an alist specifying frame parameters.
672 You can create multiple frames on a single text-only terminal, but
673 only one of them (the selected terminal frame) is actually displayed.
675 In practice, generally you don't need to specify any parameters,
676 except when you want to create a new frame on another terminal.
677 In that case, the `tty' parameter specifies the device file to open,
678 and the `tty-type' parameter specifies the terminal type. Example:
680 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
682 Note that changing the size of one terminal frame automatically
683 affects all frames on the same terminal device. */)
684 (parms)
685 Lisp_Object parms;
687 struct frame *f;
688 struct terminal *t = NULL;
689 Lisp_Object frame, tem;
690 struct frame *sf = SELECTED_FRAME ();
692 #ifdef MSDOS
693 if (sf->output_method != output_msdos_raw
694 && sf->output_method != output_termcap)
695 abort ();
696 #else /* not MSDOS */
698 #if 0 /* #ifdef MAC_OS */
699 /* This can happen for multi-tty when using both terminal frames and
700 Carbon frames. */
701 if (sf->output_method != output_mac)
702 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
703 #else
704 #if 0 /* This should work now! */
705 if (sf->output_method != output_termcap)
706 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
707 #endif
708 #endif
709 #endif /* not MSDOS */
712 Lisp_Object terminal;
714 terminal = Fassq (Qterminal, parms);
715 if (!NILP (terminal))
717 terminal = XCDR (terminal);
718 t = get_terminal (terminal, 1);
722 if (!t)
724 char *name = 0, *type = 0;
725 Lisp_Object tty, tty_type;
727 tty = get_future_frame_param
728 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
729 ? FRAME_TTY (XFRAME (selected_frame))->name
730 : NULL));
731 if (!NILP (tty))
733 name = (char *) alloca (SBYTES (tty) + 1);
734 strncpy (name, SDATA (tty), SBYTES (tty));
735 name[SBYTES (tty)] = 0;
738 tty_type = get_future_frame_param
739 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
740 ? FRAME_TTY (XFRAME (selected_frame))->type
741 : NULL));
742 if (!NILP (tty_type))
744 type = (char *) alloca (SBYTES (tty_type) + 1);
745 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
746 type[SBYTES (tty_type)] = 0;
749 t = init_tty (name, type, 0); /* Errors are not fatal. */
752 f = make_terminal_frame (t);
755 int width, height;
756 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
757 change_frame_size (f, height, width, 0, 0, 0);
760 adjust_glyphs (f);
761 calculate_costs (f);
762 XSETFRAME (frame, f);
763 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
764 Fmodify_frame_parameters (frame, parms);
765 Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qnil), Qnil));
766 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
767 build_string (t->display_info.tty->type)),
768 Qnil));
769 if (t->display_info.tty->name != NULL)
770 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
771 build_string (t->display_info.tty->name)),
772 Qnil));
773 else
774 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
776 /* Make the frame face alist be frame-specific, so that each
777 frame could change its face definitions independently. */
778 f->face_alist = Fcopy_alist (sf->face_alist);
779 /* Simple Fcopy_alist isn't enough, because we need the contents of
780 the vectors which are the CDRs of associations in face_alist to
781 be copied as well. */
782 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
783 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
784 return frame;
788 /* Perform the switch to frame FRAME.
790 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
791 FRAME1 as frame.
793 If TRACK is non-zero and the frame that currently has the focus
794 redirects its focus to the selected frame, redirect that focused
795 frame's focus to FRAME instead.
797 FOR_DELETION non-zero means that the selected frame is being
798 deleted, which includes the possibility that the frame's terminal
799 is dead. */
801 Lisp_Object
802 do_switch_frame (frame, track, for_deletion)
803 Lisp_Object frame;
804 int track, for_deletion;
806 struct frame *sf = SELECTED_FRAME ();
808 /* If FRAME is a switch-frame event, extract the frame we should
809 switch to. */
810 if (CONSP (frame)
811 && EQ (XCAR (frame), Qswitch_frame)
812 && CONSP (XCDR (frame)))
813 frame = XCAR (XCDR (frame));
815 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
816 a switch-frame event to arrive after a frame is no longer live,
817 especially when deleting the initial frame during startup. */
818 CHECK_FRAME (frame);
819 if (! FRAME_LIVE_P (XFRAME (frame)))
820 return Qnil;
822 if (sf == XFRAME (frame))
823 return frame;
825 /* This is too greedy; it causes inappropriate focus redirection
826 that's hard to get rid of. */
827 #if 0
828 /* If a frame's focus has been redirected toward the currently
829 selected frame, we should change the redirection to point to the
830 newly selected frame. This means that if the focus is redirected
831 from a minibufferless frame to a surrogate minibuffer frame, we
832 can use `other-window' to switch between all the frames using
833 that minibuffer frame, and the focus redirection will follow us
834 around. */
835 if (track)
837 Lisp_Object tail;
839 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
841 Lisp_Object focus;
843 if (!FRAMEP (XCAR (tail)))
844 abort ();
846 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
848 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
849 Fredirect_frame_focus (XCAR (tail), frame);
852 #else /* ! 0 */
853 /* Instead, apply it only to the frame we're pointing to. */
854 #ifdef HAVE_WINDOW_SYSTEM
855 if (track && FRAME_WINDOW_P (XFRAME (frame)))
857 Lisp_Object focus, xfocus;
859 xfocus = x_get_focus_frame (XFRAME (frame));
860 if (FRAMEP (xfocus))
862 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
863 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
864 Fredirect_frame_focus (xfocus, frame);
867 #endif /* HAVE_X_WINDOWS */
868 #endif /* ! 0 */
870 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
871 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
873 if (FRAME_TERMCAP_P (XFRAME (selected_frame))
874 && FRAME_TERMCAP_P (XFRAME (frame))
875 && FRAME_TTY (XFRAME (selected_frame)) == FRAME_TTY (XFRAME (frame)))
877 XFRAME (selected_frame)->async_visible = 2; /* obscured */
878 XFRAME (frame)->async_visible = 1;
879 FRAME_TTY (XFRAME (frame))->top_frame = frame;
882 selected_frame = frame;
883 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
884 last_nonminibuf_frame = XFRAME (selected_frame);
886 Fselect_window (XFRAME (frame)->selected_window, Qnil);
888 #ifndef WINDOWSNT
889 /* Make sure to switch the tty color mode to that of the newly
890 selected frame. */
891 sf = SELECTED_FRAME ();
892 if (FRAME_TERMCAP_P (sf))
894 Lisp_Object color_mode_spec, color_mode;
896 color_mode_spec = assq_no_quit (Qtty_color_mode, sf->param_alist);
897 if (CONSP (color_mode_spec))
898 color_mode = XCDR (color_mode_spec);
899 else
900 color_mode = make_number (0);
901 set_tty_color_mode (sf, color_mode);
903 #endif /* !WINDOWSNT */
905 /* We want to make sure that the next event generates a frame-switch
906 event to the appropriate frame. This seems kludgy to me, but
907 before you take it out, make sure that evaluating something like
908 (select-window (frame-root-window (new-frame))) doesn't end up
909 with your typing being interpreted in the new frame instead of
910 the one you're actually typing in. */
911 internal_last_event_frame = Qnil;
913 return frame;
916 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 1, "e",
917 doc: /* Select the frame FRAME.
918 Subsequent editing commands apply to its selected window.
919 The selection of FRAME lasts until the next time the user does
920 something to select a different frame, or until the next time this
921 function is called. If you are using a window system, the previously
922 selected frame may be restored as the selected frame after return to
923 the command loop, because it still may have the window system's input
924 focus. On a text-only terminal, the next redisplay will display FRAME.
926 This function returns FRAME, or nil if FRAME has been deleted. */)
927 (frame)
928 Lisp_Object frame;
930 return do_switch_frame (frame, 1, 0);
934 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
935 doc: /* Handle a switch-frame event EVENT.
936 Switch-frame events are usually bound to this function.
937 A switch-frame event tells Emacs that the window manager has requested
938 that the user's events be directed to the frame mentioned in the event.
939 This function selects the selected window of the frame of EVENT.
941 If EVENT is frame object, handle it as if it were a switch-frame event
942 to that frame. */)
943 (event)
944 Lisp_Object event;
946 /* Preserve prefix arg that the command loop just cleared. */
947 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
948 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
949 return do_switch_frame (event, 0, 0);
952 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
953 doc: /* Return the frame that is now selected. */)
956 return selected_frame;
959 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
960 doc: /* Return the frame object that window WINDOW is on. */)
961 (window)
962 Lisp_Object window;
964 CHECK_LIVE_WINDOW (window);
965 return XWINDOW (window)->frame;
968 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
969 doc: /* Returns the topmost, leftmost window of FRAME.
970 If omitted, FRAME defaults to the currently selected frame. */)
971 (frame)
972 Lisp_Object frame;
974 Lisp_Object w;
976 if (NILP (frame))
977 w = SELECTED_FRAME ()->root_window;
978 else
980 CHECK_LIVE_FRAME (frame);
981 w = XFRAME (frame)->root_window;
983 while (NILP (XWINDOW (w)->buffer))
985 if (! NILP (XWINDOW (w)->hchild))
986 w = XWINDOW (w)->hchild;
987 else if (! NILP (XWINDOW (w)->vchild))
988 w = XWINDOW (w)->vchild;
989 else
990 abort ();
992 return w;
995 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
996 Sactive_minibuffer_window, 0, 0, 0,
997 doc: /* Return the currently active minibuffer window, or nil if none. */)
1000 return minibuf_level ? minibuf_window : Qnil;
1003 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
1004 doc: /* Returns the root-window of FRAME.
1005 If omitted, FRAME defaults to the currently selected frame. */)
1006 (frame)
1007 Lisp_Object frame;
1009 Lisp_Object window;
1011 if (NILP (frame))
1012 window = SELECTED_FRAME ()->root_window;
1013 else
1015 CHECK_LIVE_FRAME (frame);
1016 window = XFRAME (frame)->root_window;
1019 return window;
1022 DEFUN ("frame-selected-window", Fframe_selected_window,
1023 Sframe_selected_window, 0, 1, 0,
1024 doc: /* Return the selected window of frame object FRAME.
1025 If omitted, FRAME defaults to the currently selected frame. */)
1026 (frame)
1027 Lisp_Object frame;
1029 Lisp_Object window;
1031 if (NILP (frame))
1032 window = SELECTED_FRAME ()->selected_window;
1033 else
1035 CHECK_LIVE_FRAME (frame);
1036 window = XFRAME (frame)->selected_window;
1039 return window;
1042 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
1043 Sset_frame_selected_window, 2, 2, 0,
1044 doc: /* Set the selected window of frame object FRAME to WINDOW.
1045 Return WINDOW.
1046 If FRAME is nil, the selected frame is used.
1047 If FRAME is the selected frame, this makes WINDOW the selected window. */)
1048 (frame, window)
1049 Lisp_Object frame, window;
1051 if (NILP (frame))
1052 frame = selected_frame;
1054 CHECK_LIVE_FRAME (frame);
1055 CHECK_LIVE_WINDOW (window);
1057 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
1058 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
1060 if (EQ (frame, selected_frame))
1061 return Fselect_window (window, Qnil);
1063 return XFRAME (frame)->selected_window = window;
1067 DEFUN ("frame-list", Fframe_list, Sframe_list,
1068 0, 0, 0,
1069 doc: /* Return a list of all frames. */)
1072 Lisp_Object frames;
1073 frames = Fcopy_sequence (Vframe_list);
1074 #ifdef HAVE_WINDOW_SYSTEM
1075 if (FRAMEP (tip_frame))
1076 frames = Fdelq (tip_frame, frames);
1077 #endif
1078 return frames;
1081 /* Return the next frame in the frame list after FRAME.
1082 If MINIBUF is nil, exclude minibuffer-only frames.
1083 If MINIBUF is a window, include only its own frame
1084 and any frame now using that window as the minibuffer.
1085 If MINIBUF is `visible', include all visible frames.
1086 If MINIBUF is 0, include all visible and iconified frames.
1087 Otherwise, include all frames. */
1089 static Lisp_Object
1090 next_frame (frame, minibuf)
1091 Lisp_Object frame;
1092 Lisp_Object minibuf;
1094 Lisp_Object tail;
1095 int passed = 0;
1097 /* There must always be at least one frame in Vframe_list. */
1098 if (! CONSP (Vframe_list))
1099 abort ();
1101 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
1102 forever. Forestall that. */
1103 CHECK_LIVE_FRAME (frame);
1105 while (1)
1106 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1108 Lisp_Object f;
1110 f = XCAR (tail);
1112 if (passed
1113 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1114 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1115 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1116 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
1118 /* Decide whether this frame is eligible to be returned. */
1120 /* If we've looped all the way around without finding any
1121 eligible frames, return the original frame. */
1122 if (EQ (f, frame))
1123 return f;
1125 /* Let minibuf decide if this frame is acceptable. */
1126 if (NILP (minibuf))
1128 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1129 return f;
1131 else if (EQ (minibuf, Qvisible))
1133 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1134 if (FRAME_VISIBLE_P (XFRAME (f)))
1135 return f;
1137 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1139 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1140 if (FRAME_VISIBLE_P (XFRAME (f))
1141 || FRAME_ICONIFIED_P (XFRAME (f)))
1142 return f;
1144 else if (WINDOWP (minibuf))
1146 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1147 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1148 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1149 FRAME_FOCUS_FRAME (XFRAME (f))))
1150 return f;
1152 else
1153 return f;
1156 if (EQ (frame, f))
1157 passed++;
1161 /* Return the previous frame in the frame list before FRAME.
1162 If MINIBUF is nil, exclude minibuffer-only frames.
1163 If MINIBUF is a window, include only its own frame
1164 and any frame now using that window as the minibuffer.
1165 If MINIBUF is `visible', include all visible frames.
1166 If MINIBUF is 0, include all visible and iconified frames.
1167 Otherwise, include all frames. */
1169 static Lisp_Object
1170 prev_frame (frame, minibuf)
1171 Lisp_Object frame;
1172 Lisp_Object minibuf;
1174 Lisp_Object tail;
1175 Lisp_Object prev;
1177 /* There must always be at least one frame in Vframe_list. */
1178 if (! CONSP (Vframe_list))
1179 abort ();
1181 prev = Qnil;
1182 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1184 Lisp_Object f;
1186 f = XCAR (tail);
1187 if (!FRAMEP (f))
1188 abort ();
1190 if (EQ (frame, f) && !NILP (prev))
1191 return prev;
1193 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1194 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1195 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1196 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1198 /* Decide whether this frame is eligible to be returned,
1199 according to minibuf. */
1200 if (NILP (minibuf))
1202 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1203 prev = f;
1205 else if (WINDOWP (minibuf))
1207 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1208 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1209 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1210 FRAME_FOCUS_FRAME (XFRAME (f))))
1211 prev = f;
1213 else if (EQ (minibuf, Qvisible))
1215 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1216 if (FRAME_VISIBLE_P (XFRAME (f)))
1217 prev = f;
1219 else if (XFASTINT (minibuf) == 0)
1221 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1222 if (FRAME_VISIBLE_P (XFRAME (f))
1223 || FRAME_ICONIFIED_P (XFRAME (f)))
1224 prev = f;
1226 else
1227 prev = f;
1231 /* We've scanned the entire list. */
1232 if (NILP (prev))
1233 /* We went through the whole frame list without finding a single
1234 acceptable frame. Return the original frame. */
1235 return frame;
1236 else
1237 /* There were no acceptable frames in the list before FRAME; otherwise,
1238 we would have returned directly from the loop. Since PREV is the last
1239 acceptable frame in the list, return it. */
1240 return prev;
1244 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1245 doc: /* Return the next frame in the frame list after FRAME.
1246 It considers only frames on the same terminal as FRAME.
1247 By default, skip minibuffer-only frames.
1248 If omitted, FRAME defaults to the selected frame.
1249 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1250 If MINIFRAME is a window, include only its own frame
1251 and any frame now using that window as the minibuffer.
1252 If MINIFRAME is `visible', include all visible frames.
1253 If MINIFRAME is 0, include all visible and iconified frames.
1254 Otherwise, include all frames. */)
1255 (frame, miniframe)
1256 Lisp_Object frame, miniframe;
1258 if (NILP (frame))
1259 frame = selected_frame;
1261 CHECK_LIVE_FRAME (frame);
1262 return next_frame (frame, miniframe);
1265 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1266 doc: /* Return the previous frame in the frame list before FRAME.
1267 It considers only frames on the same terminal as FRAME.
1268 By default, skip minibuffer-only frames.
1269 If omitted, FRAME defaults to the selected frame.
1270 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1271 If MINIFRAME is a window, include only its own frame
1272 and any frame now using that window as the minibuffer.
1273 If MINIFRAME is `visible', include all visible frames.
1274 If MINIFRAME is 0, include all visible and iconified frames.
1275 Otherwise, include all frames. */)
1276 (frame, miniframe)
1277 Lisp_Object frame, miniframe;
1279 if (NILP (frame))
1280 frame = selected_frame;
1281 CHECK_LIVE_FRAME (frame);
1282 return prev_frame (frame, miniframe);
1285 /* Return 1 if it is ok to delete frame F;
1286 0 if all frames aside from F are invisible.
1287 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1290 other_visible_frames (f)
1291 FRAME_PTR f;
1293 /* We know the selected frame is visible,
1294 so if F is some other frame, it can't be the sole visible one. */
1295 if (f == SELECTED_FRAME ())
1297 Lisp_Object frames;
1298 int count = 0;
1300 for (frames = Vframe_list;
1301 CONSP (frames);
1302 frames = XCDR (frames))
1304 Lisp_Object this;
1306 this = XCAR (frames);
1307 /* Verify that the frame's window still exists
1308 and we can still talk to it. And note any recent change
1309 in visibility. */
1310 #ifdef HAVE_WINDOW_SYSTEM
1311 if (FRAME_WINDOW_P (XFRAME (this)))
1313 x_sync (XFRAME (this));
1314 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1316 #endif
1318 if (FRAME_VISIBLE_P (XFRAME (this))
1319 || FRAME_ICONIFIED_P (XFRAME (this))
1320 /* Allow deleting the terminal frame when at least
1321 one X frame exists! */
1322 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1323 count++;
1325 return count > 1;
1327 return 1;
1330 /* Error handler for `delete-frame-functions'. */
1331 static Lisp_Object
1332 delete_frame_handler (Lisp_Object arg)
1334 add_to_log ("Error during `delete-frame': %s", arg, Qnil);
1335 return Qnil;
1338 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1339 doc: /* Delete FRAME, permanently eliminating it from use.
1340 If omitted, FRAME defaults to the selected frame.
1341 A frame may not be deleted if its minibuffer is used by other frames.
1342 Normally, you may not delete a frame if all other frames are invisible,
1343 but if the second optional argument FORCE is non-nil, you may do so.
1345 This function runs `delete-frame-functions' before actually deleting the
1346 frame, unless the frame is a tooltip.
1347 The functions are run with one arg, the frame to be deleted. */)
1348 (frame, force)
1349 Lisp_Object frame, force;
1351 struct frame *f;
1352 struct frame *sf = SELECTED_FRAME ();
1353 struct kboard *kb;
1355 int minibuffer_selected;
1357 if (EQ (frame, Qnil))
1359 f = sf;
1360 XSETFRAME (frame, f);
1362 else
1364 CHECK_FRAME (frame);
1365 f = XFRAME (frame);
1368 if (! FRAME_LIVE_P (f))
1369 return Qnil;
1371 if (NILP (force) && !other_visible_frames (f)
1372 #ifdef MAC_OS8
1373 /* Terminal frame deleted before any other visible frames are
1374 created. */
1375 && strcmp (SDATA (f->name), "F1") != 0
1376 #endif
1378 error ("Attempt to delete the sole visible or iconified frame");
1380 #if 0
1381 /* This is a nice idea, but x_connection_closed needs to be able
1382 to delete the last frame, if it is gone. */
1383 if (NILP (XCDR (Vframe_list)))
1384 error ("Attempt to delete the only frame");
1385 #endif
1387 /* Does this frame have a minibuffer, and is it the surrogate
1388 minibuffer for any other frame? */
1389 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1391 Lisp_Object frames;
1393 for (frames = Vframe_list;
1394 CONSP (frames);
1395 frames = XCDR (frames))
1397 Lisp_Object this;
1398 this = XCAR (frames);
1400 if (! EQ (this, frame)
1401 && EQ (frame,
1402 WINDOW_FRAME (XWINDOW
1403 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1404 error ("Attempt to delete a surrogate minibuffer frame");
1408 /* Run `delete-frame-functions' unless frame is a tooltip. */
1409 if (!NILP (Vrun_hooks)
1410 && NILP (Fframe_parameter (frame, intern ("tooltip"))))
1412 Lisp_Object args[2];
1413 struct gcpro gcpro1, gcpro2;
1415 /* Don't let a rogue function in `delete-frame-functions'
1416 prevent the frame deletion. */
1417 GCPRO2 (args[0], args[1]);
1418 args[0] = intern ("delete-frame-functions");
1419 args[1] = frame;
1420 internal_condition_case_2 (Frun_hook_with_args, 2, args,
1421 Qt, delete_frame_handler);
1422 UNGCPRO;
1425 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1426 if (! FRAME_LIVE_P (f))
1427 return Qnil;
1429 minibuffer_selected = EQ (minibuf_window, selected_window);
1431 /* Don't let the frame remain selected. */
1432 if (f == sf)
1434 Lisp_Object tail, frame1;
1436 /* Look for another visible frame on the same terminal. */
1437 frame1 = next_frame (frame, Qvisible);
1439 /* If there is none, find *some* other frame. */
1440 if (NILP (frame1) || EQ (frame1, frame))
1442 FOR_EACH_FRAME (tail, frame1)
1444 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1445 break;
1449 do_switch_frame (frame1, 0, 1);
1450 sf = SELECTED_FRAME ();
1453 /* Don't allow minibuf_window to remain on a deleted frame. */
1454 if (EQ (f->minibuffer_window, minibuf_window))
1456 Fset_window_buffer (sf->minibuffer_window,
1457 XWINDOW (minibuf_window)->buffer, Qnil);
1458 minibuf_window = sf->minibuffer_window;
1460 /* If the dying minibuffer window was selected,
1461 select the new one. */
1462 if (minibuffer_selected)
1463 Fselect_window (minibuf_window, Qnil);
1466 /* Don't let echo_area_window to remain on a deleted frame. */
1467 if (EQ (f->minibuffer_window, echo_area_window))
1468 echo_area_window = sf->minibuffer_window;
1470 /* Don't allow other frames to refer to a deleted frame in their
1471 'environment parameter. */
1473 Lisp_Object tail, frame1;
1474 Lisp_Object env = get_frame_param (XFRAME (frame), Qenvironment);
1475 FOR_EACH_FRAME (tail, frame1)
1477 if (EQ (frame, frame1) || !FRAME_LIVE_P (XFRAME (frame1)))
1478 continue;
1479 if (EQ (frame, get_frame_param (XFRAME (frame1), Qenvironment)))
1481 store_frame_param (XFRAME (frame1), Qenvironment, env);
1482 if (!FRAMEP (env))
1483 env = frame1;
1488 /* Clear any X selections for this frame. */
1489 #ifdef HAVE_X_WINDOWS
1490 if (FRAME_X_P (f))
1491 x_clear_frame_selections (f);
1492 #endif
1493 #ifdef MAC_OS
1494 if (FRAME_MAC_P (f))
1495 x_clear_frame_selections (f);
1496 #endif
1498 /* Free glyphs.
1499 This function must be called before the window tree of the
1500 frame is deleted because windows contain dynamically allocated
1501 memory. */
1502 free_glyphs (f);
1504 /* Mark all the windows that used to be on FRAME as deleted, and then
1505 remove the reference to them. */
1506 delete_all_subwindows (XWINDOW (f->root_window));
1507 f->root_window = Qnil;
1509 Vframe_list = Fdelq (frame, Vframe_list);
1510 FRAME_SET_VISIBLE (f, 0);
1512 if (f->namebuf)
1513 xfree (f->namebuf);
1514 if (f->decode_mode_spec_buffer)
1515 xfree (f->decode_mode_spec_buffer);
1516 if (FRAME_INSERT_COST (f))
1517 xfree (FRAME_INSERT_COST (f));
1518 if (FRAME_DELETEN_COST (f))
1519 xfree (FRAME_DELETEN_COST (f));
1520 if (FRAME_INSERTN_COST (f))
1521 xfree (FRAME_INSERTN_COST (f));
1522 if (FRAME_DELETE_COST (f))
1523 xfree (FRAME_DELETE_COST (f));
1524 if (FRAME_MESSAGE_BUF (f))
1525 xfree (FRAME_MESSAGE_BUF (f));
1527 /* Since some events are handled at the interrupt level, we may get
1528 an event for f at any time; if we zero out the frame's terminal
1529 now, then we may trip up the event-handling code. Instead, we'll
1530 promise that the terminal of the frame must be valid until we
1531 have called the window-system-dependent frame destruction
1532 routine. */
1534 if (FRAME_TERMINAL (f)->delete_frame_hook)
1535 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1538 struct terminal *terminal = FRAME_TERMINAL (f);
1539 f->output_data.nothing = 0;
1540 f->terminal = 0; /* Now the frame is dead. */
1542 /* If needed, delete the terminal that this frame was on.
1543 (This must be done after the frame is killed.) */
1544 terminal->reference_count--;
1545 if (terminal->reference_count == 0)
1547 kb = NULL;
1548 if (terminal->delete_terminal_hook)
1549 (*terminal->delete_terminal_hook) (terminal);
1550 else
1551 delete_terminal (terminal);
1553 #ifdef MULTI_KBOARD
1554 else
1555 kb = terminal->kboard;
1556 #endif
1559 /* If we've deleted the last_nonminibuf_frame, then try to find
1560 another one. */
1561 if (f == last_nonminibuf_frame)
1563 Lisp_Object frames;
1565 last_nonminibuf_frame = 0;
1567 for (frames = Vframe_list;
1568 CONSP (frames);
1569 frames = XCDR (frames))
1571 f = XFRAME (XCAR (frames));
1572 if (!FRAME_MINIBUF_ONLY_P (f))
1574 last_nonminibuf_frame = f;
1575 break;
1580 /* If there's no other frame on the same kboard, get out of
1581 single-kboard state if we're in it for this kboard. */
1582 if (kb != NULL)
1584 Lisp_Object frames;
1585 /* Some frame we found on the same kboard, or nil if there are none. */
1586 Lisp_Object frame_on_same_kboard;
1588 frame_on_same_kboard = Qnil;
1590 for (frames = Vframe_list;
1591 CONSP (frames);
1592 frames = XCDR (frames))
1594 Lisp_Object this;
1595 struct frame *f1;
1597 this = XCAR (frames);
1598 if (!FRAMEP (this))
1599 abort ();
1600 f1 = XFRAME (this);
1602 if (kb == FRAME_KBOARD (f1))
1603 frame_on_same_kboard = this;
1606 if (NILP (frame_on_same_kboard))
1607 not_single_kboard_state (kb);
1611 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1612 find another one. Prefer minibuffer-only frames, but also notice
1613 frames with other windows. */
1614 if (kb != NULL && EQ (frame, kb->Vdefault_minibuffer_frame))
1616 Lisp_Object frames;
1618 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1619 Lisp_Object frame_with_minibuf;
1620 /* Some frame we found on the same kboard, or nil if there are none. */
1621 Lisp_Object frame_on_same_kboard;
1623 frame_on_same_kboard = Qnil;
1624 frame_with_minibuf = Qnil;
1626 for (frames = Vframe_list;
1627 CONSP (frames);
1628 frames = XCDR (frames))
1630 Lisp_Object this;
1631 struct frame *f1;
1633 this = XCAR (frames);
1634 if (!FRAMEP (this))
1635 abort ();
1636 f1 = XFRAME (this);
1638 /* Consider only frames on the same kboard
1639 and only those with minibuffers. */
1640 if (kb == FRAME_KBOARD (f1)
1641 && FRAME_HAS_MINIBUF_P (f1))
1643 frame_with_minibuf = this;
1644 if (FRAME_MINIBUF_ONLY_P (f1))
1645 break;
1648 if (kb == FRAME_KBOARD (f1))
1649 frame_on_same_kboard = this;
1652 if (!NILP (frame_on_same_kboard))
1654 /* We know that there must be some frame with a minibuffer out
1655 there. If this were not true, all of the frames present
1656 would have to be minibufferless, which implies that at some
1657 point their minibuffer frames must have been deleted, but
1658 that is prohibited at the top; you can't delete surrogate
1659 minibuffer frames. */
1660 if (NILP (frame_with_minibuf))
1661 abort ();
1663 kb->Vdefault_minibuffer_frame = frame_with_minibuf;
1665 else
1666 /* No frames left on this kboard--say no minibuffer either. */
1667 kb->Vdefault_minibuffer_frame = Qnil;
1670 /* Cause frame titles to update--necessary if we now have just one frame. */
1671 update_mode_lines = 1;
1673 return Qnil;
1676 /* Return mouse position in character cell units. */
1678 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1679 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1680 The position is given in character cells, where (0, 0) is the
1681 upper-left corner of the frame, X is the horizontal offset, and Y is
1682 the vertical offset.
1683 If Emacs is running on a mouseless terminal or hasn't been programmed
1684 to read the mouse position, it returns the selected frame for FRAME
1685 and nil for X and Y.
1686 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1687 passing the normal return value to that function as an argument,
1688 and returns whatever that function returns. */)
1691 FRAME_PTR f;
1692 Lisp_Object lispy_dummy;
1693 enum scroll_bar_part party_dummy;
1694 Lisp_Object x, y, retval;
1695 int col, row;
1696 unsigned long long_dummy;
1697 struct gcpro gcpro1;
1699 f = SELECTED_FRAME ();
1700 x = y = Qnil;
1702 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1703 /* It's okay for the hook to refrain from storing anything. */
1704 if (FRAME_TERMINAL (f)->mouse_position_hook)
1705 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1706 &lispy_dummy, &party_dummy,
1707 &x, &y,
1708 &long_dummy);
1709 if (! NILP (x))
1711 col = XINT (x);
1712 row = XINT (y);
1713 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1714 XSETINT (x, col);
1715 XSETINT (y, row);
1717 #endif
1718 XSETFRAME (lispy_dummy, f);
1719 retval = Fcons (lispy_dummy, Fcons (x, y));
1720 GCPRO1 (retval);
1721 if (!NILP (Vmouse_position_function))
1722 retval = call1 (Vmouse_position_function, retval);
1723 RETURN_UNGCPRO (retval);
1726 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1727 Smouse_pixel_position, 0, 0, 0,
1728 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1729 The position is given in pixel units, where (0, 0) is the
1730 upper-left corner of the frame, X is the horizontal offset, and Y is
1731 the vertical offset.
1732 If Emacs is running on a mouseless terminal or hasn't been programmed
1733 to read the mouse position, it returns the selected frame for FRAME
1734 and nil for X and Y. */)
1737 FRAME_PTR f;
1738 Lisp_Object lispy_dummy;
1739 enum scroll_bar_part party_dummy;
1740 Lisp_Object x, y;
1741 unsigned long long_dummy;
1743 f = SELECTED_FRAME ();
1744 x = y = Qnil;
1746 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1747 /* It's okay for the hook to refrain from storing anything. */
1748 if (FRAME_TERMINAL (f)->mouse_position_hook)
1749 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1750 &lispy_dummy, &party_dummy,
1751 &x, &y,
1752 &long_dummy);
1753 #endif
1754 XSETFRAME (lispy_dummy, f);
1755 return Fcons (lispy_dummy, Fcons (x, y));
1758 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1759 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1760 Coordinates are relative to the frame, not a window,
1761 so the coordinates of the top left character in the frame
1762 may be nonzero due to left-hand scroll bars or the menu bar.
1764 The position is given in character cells, where (0, 0) is the
1765 upper-left corner of the frame, X is the horizontal offset, and Y is
1766 the vertical offset.
1768 This function is a no-op for an X frame that is not visible.
1769 If you have just created a frame, you must wait for it to become visible
1770 before calling this function on it, like this.
1771 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1772 (frame, x, y)
1773 Lisp_Object frame, x, y;
1775 CHECK_LIVE_FRAME (frame);
1776 CHECK_NUMBER (x);
1777 CHECK_NUMBER (y);
1779 /* I think this should be done with a hook. */
1780 #ifdef HAVE_WINDOW_SYSTEM
1781 if (FRAME_WINDOW_P (XFRAME (frame)))
1782 /* Warping the mouse will cause enternotify and focus events. */
1783 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1784 #else
1785 #if defined (MSDOS) && defined (HAVE_MOUSE)
1786 if (FRAME_MSDOS_P (XFRAME (frame)))
1788 Fselect_frame (frame);
1789 mouse_moveto (XINT (x), XINT (y));
1791 #else
1792 #ifdef HAVE_GPM
1794 Fselect_frame (frame);
1795 term_mouse_moveto (XINT (x), XINT (y));
1797 #endif
1798 #endif
1799 #endif
1801 return Qnil;
1804 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1805 Sset_mouse_pixel_position, 3, 3, 0,
1806 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1807 The position is given in pixels, where (0, 0) is the upper-left corner
1808 of the frame, X is the horizontal offset, and Y is the vertical offset.
1810 Note, this is a no-op for an X frame that is not visible.
1811 If you have just created a frame, you must wait for it to become visible
1812 before calling this function on it, like this.
1813 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1814 (frame, x, y)
1815 Lisp_Object frame, x, y;
1817 CHECK_LIVE_FRAME (frame);
1818 CHECK_NUMBER (x);
1819 CHECK_NUMBER (y);
1821 /* I think this should be done with a hook. */
1822 #ifdef HAVE_WINDOW_SYSTEM
1823 if (FRAME_WINDOW_P (XFRAME (frame)))
1824 /* Warping the mouse will cause enternotify and focus events. */
1825 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1826 #else
1827 #if defined (MSDOS) && defined (HAVE_MOUSE)
1828 if (FRAME_MSDOS_P (XFRAME (frame)))
1830 Fselect_frame (frame);
1831 mouse_moveto (XINT (x), XINT (y));
1833 #else
1834 #ifdef HAVE_GPM
1836 Fselect_frame (frame);
1837 term_mouse_moveto (XINT (x), XINT (y));
1839 #endif
1840 #endif
1841 #endif
1843 return Qnil;
1846 static void make_frame_visible_1 P_ ((Lisp_Object));
1848 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1849 0, 1, "",
1850 doc: /* Make the frame FRAME visible (assuming it is an X window).
1851 If omitted, FRAME defaults to the currently selected frame. */)
1852 (frame)
1853 Lisp_Object frame;
1855 if (NILP (frame))
1856 frame = selected_frame;
1858 CHECK_LIVE_FRAME (frame);
1860 /* I think this should be done with a hook. */
1861 #ifdef HAVE_WINDOW_SYSTEM
1862 if (FRAME_WINDOW_P (XFRAME (frame)))
1864 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1865 x_make_frame_visible (XFRAME (frame));
1867 #endif
1869 make_frame_visible_1 (XFRAME (frame)->root_window);
1871 /* Make menu bar update for the Buffers and Frames menus. */
1872 windows_or_buffers_changed++;
1874 return frame;
1877 /* Update the display_time slot of the buffers shown in WINDOW
1878 and all its descendents. */
1880 static void
1881 make_frame_visible_1 (window)
1882 Lisp_Object window;
1884 struct window *w;
1886 for (;!NILP (window); window = w->next)
1888 w = XWINDOW (window);
1890 if (!NILP (w->buffer))
1891 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1893 if (!NILP (w->vchild))
1894 make_frame_visible_1 (w->vchild);
1895 if (!NILP (w->hchild))
1896 make_frame_visible_1 (w->hchild);
1900 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1901 0, 2, "",
1902 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1903 If omitted, FRAME defaults to the currently selected frame.
1904 Normally you may not make FRAME invisible if all other frames are invisible,
1905 but if the second optional argument FORCE is non-nil, you may do so. */)
1906 (frame, force)
1907 Lisp_Object frame, force;
1909 if (NILP (frame))
1910 frame = selected_frame;
1912 CHECK_LIVE_FRAME (frame);
1914 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1915 error ("Attempt to make invisible the sole visible or iconified frame");
1917 #if 0 /* This isn't logically necessary, and it can do GC. */
1918 /* Don't let the frame remain selected. */
1919 if (EQ (frame, selected_frame))
1920 do_switch_frame (next_frame (frame, Qt), 0, 0)
1921 #endif
1923 /* Don't allow minibuf_window to remain on a deleted frame. */
1924 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1926 struct frame *sf = XFRAME (selected_frame);
1927 Fset_window_buffer (sf->minibuffer_window,
1928 XWINDOW (minibuf_window)->buffer, Qnil);
1929 minibuf_window = sf->minibuffer_window;
1932 /* I think this should be done with a hook. */
1933 #ifdef HAVE_WINDOW_SYSTEM
1934 if (FRAME_WINDOW_P (XFRAME (frame)))
1935 x_make_frame_invisible (XFRAME (frame));
1936 #endif
1938 /* Make menu bar update for the Buffers and Frames menus. */
1939 windows_or_buffers_changed++;
1941 return Qnil;
1944 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1945 0, 1, "",
1946 doc: /* Make the frame FRAME into an icon.
1947 If omitted, FRAME defaults to the currently selected frame. */)
1948 (frame)
1949 Lisp_Object frame;
1951 if (NILP (frame))
1952 frame = selected_frame;
1954 CHECK_LIVE_FRAME (frame);
1956 #if 0 /* This isn't logically necessary, and it can do GC. */
1957 /* Don't let the frame remain selected. */
1958 if (EQ (frame, selected_frame))
1959 Fhandle_switch_frame (next_frame (frame, Qt));
1960 #endif
1962 /* Don't allow minibuf_window to remain on a deleted frame. */
1963 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1965 struct frame *sf = XFRAME (selected_frame);
1966 Fset_window_buffer (sf->minibuffer_window,
1967 XWINDOW (minibuf_window)->buffer, Qnil);
1968 minibuf_window = sf->minibuffer_window;
1971 /* I think this should be done with a hook. */
1972 #ifdef HAVE_WINDOW_SYSTEM
1973 if (FRAME_WINDOW_P (XFRAME (frame)))
1974 x_iconify_frame (XFRAME (frame));
1975 #endif
1977 /* Make menu bar update for the Buffers and Frames menus. */
1978 windows_or_buffers_changed++;
1980 return Qnil;
1983 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1984 1, 1, 0,
1985 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1986 A frame that is not \"visible\" is not updated and, if it works through
1987 a window system, it may not show at all.
1988 Return the symbol `icon' if frame is visible only as an icon.
1990 On a text-only terminal, all frames are considered visible, whether
1991 they are currently being displayed or not, and this function returns t
1992 for all frames. */)
1993 (frame)
1994 Lisp_Object frame;
1996 CHECK_LIVE_FRAME (frame);
1998 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
2000 if (FRAME_VISIBLE_P (XFRAME (frame)))
2001 return Qt;
2002 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2003 return Qicon;
2004 return Qnil;
2007 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2008 0, 0, 0,
2009 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2012 Lisp_Object tail, frame;
2013 struct frame *f;
2014 Lisp_Object value;
2016 value = Qnil;
2017 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
2019 frame = XCAR (tail);
2020 if (!FRAMEP (frame))
2021 continue;
2022 f = XFRAME (frame);
2023 if (FRAME_VISIBLE_P (f))
2024 value = Fcons (frame, value);
2026 return value;
2030 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2031 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2032 If FRAME is invisible or iconified, make it visible.
2033 If you don't specify a frame, the selected frame is used.
2034 If Emacs is displaying on an ordinary terminal or some other device which
2035 doesn't support multiple overlapping frames, this function does nothing. */)
2036 (frame)
2037 Lisp_Object frame;
2039 struct frame *f;
2040 if (NILP (frame))
2041 frame = selected_frame;
2043 CHECK_LIVE_FRAME (frame);
2045 f = XFRAME (frame);
2047 /* Do like the documentation says. */
2048 Fmake_frame_visible (frame);
2050 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2051 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2053 return Qnil;
2056 /* Should we have a corresponding function called Flower_Power? */
2057 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2058 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2059 If you don't specify a frame, the selected frame is used.
2060 If Emacs is displaying on an ordinary terminal or some other device which
2061 doesn't support multiple overlapping frames, this function does nothing. */)
2062 (frame)
2063 Lisp_Object frame;
2065 struct frame *f;
2067 if (NILP (frame))
2068 frame = selected_frame;
2070 CHECK_LIVE_FRAME (frame);
2072 f = XFRAME (frame);
2074 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2075 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2077 return Qnil;
2081 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2082 1, 2, 0,
2083 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2084 In other words, switch-frame events caused by events in FRAME will
2085 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2086 FOCUS-FRAME after reading an event typed at FRAME.
2088 If FOCUS-FRAME is omitted or nil, any existing redirection is
2089 cancelled, and the frame again receives its own keystrokes.
2091 Focus redirection is useful for temporarily redirecting keystrokes to
2092 a surrogate minibuffer frame when a frame doesn't have its own
2093 minibuffer window.
2095 A frame's focus redirection can be changed by `select-frame'. If frame
2096 FOO is selected, and then a different frame BAR is selected, any
2097 frames redirecting their focus to FOO are shifted to redirect their
2098 focus to BAR. This allows focus redirection to work properly when the
2099 user switches from one frame to another using `select-window'.
2101 This means that a frame whose focus is redirected to itself is treated
2102 differently from a frame whose focus is redirected to nil; the former
2103 is affected by `select-frame', while the latter is not.
2105 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2106 (frame, focus_frame)
2107 Lisp_Object frame, focus_frame;
2109 struct frame *f;
2111 /* Note that we don't check for a live frame here. It's reasonable
2112 to redirect the focus of a frame you're about to delete, if you
2113 know what other frame should receive those keystrokes. */
2114 CHECK_FRAME (frame);
2116 if (! NILP (focus_frame))
2117 CHECK_LIVE_FRAME (focus_frame);
2119 f = XFRAME (frame);
2121 f->focus_frame = focus_frame;
2123 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2124 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2126 return Qnil;
2130 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
2131 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2132 This returns nil if FRAME's focus is not redirected.
2133 See `redirect-frame-focus'. */)
2134 (frame)
2135 Lisp_Object frame;
2137 CHECK_LIVE_FRAME (frame);
2139 return FRAME_FOCUS_FRAME (XFRAME (frame));
2144 /* Return the value of frame parameter PROP in frame FRAME. */
2146 Lisp_Object
2147 get_frame_param (frame, prop)
2148 register struct frame *frame;
2149 Lisp_Object prop;
2151 register Lisp_Object tem;
2153 tem = Fassq (prop, frame->param_alist);
2154 if (EQ (tem, Qnil))
2155 return tem;
2156 return Fcdr (tem);
2159 /* Return the buffer-predicate of the selected frame. */
2161 Lisp_Object
2162 frame_buffer_predicate (frame)
2163 Lisp_Object frame;
2165 return XFRAME (frame)->buffer_predicate;
2168 /* Return the buffer-list of the selected frame. */
2170 Lisp_Object
2171 frame_buffer_list (frame)
2172 Lisp_Object frame;
2174 return XFRAME (frame)->buffer_list;
2177 /* Set the buffer-list of the selected frame. */
2179 void
2180 set_frame_buffer_list (frame, list)
2181 Lisp_Object frame, list;
2183 XFRAME (frame)->buffer_list = list;
2186 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2188 void
2189 frames_discard_buffer (buffer)
2190 Lisp_Object buffer;
2192 Lisp_Object frame, tail;
2194 FOR_EACH_FRAME (tail, frame)
2196 XFRAME (frame)->buffer_list
2197 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2198 XFRAME (frame)->buried_buffer_list
2199 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
2203 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2204 If the alist already has an element for PROP, we change it. */
2206 void
2207 store_in_alist (alistptr, prop, val)
2208 Lisp_Object *alistptr, val;
2209 Lisp_Object prop;
2211 register Lisp_Object tem;
2213 tem = Fassq (prop, *alistptr);
2214 if (EQ (tem, Qnil))
2215 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2216 else
2217 Fsetcdr (tem, val);
2220 static int
2221 frame_name_fnn_p (str, len)
2222 char *str;
2223 int len;
2225 if (len > 1 && str[0] == 'F')
2227 char *end_ptr;
2229 strtol (str + 1, &end_ptr, 10);
2231 if (end_ptr == str + len)
2232 return 1;
2234 return 0;
2237 /* Set the name of the terminal frame. Also used by MSDOS frames.
2238 Modeled after x_set_name which is used for WINDOW frames. */
2240 static void
2241 set_term_frame_name (f, name)
2242 struct frame *f;
2243 Lisp_Object name;
2245 f->explicit_name = ! NILP (name);
2247 /* If NAME is nil, set the name to F<num>. */
2248 if (NILP (name))
2250 char namebuf[20];
2252 /* Check for no change needed in this very common case
2253 before we do any consing. */
2254 if (frame_name_fnn_p (SDATA (f->name),
2255 SBYTES (f->name)))
2256 return;
2258 tty_frame_count++;
2259 sprintf (namebuf, "F%d", tty_frame_count);
2260 name = build_string (namebuf);
2262 else
2264 CHECK_STRING (name);
2266 /* Don't change the name if it's already NAME. */
2267 if (! NILP (Fstring_equal (name, f->name)))
2268 return;
2270 /* Don't allow the user to set the frame name to F<num>, so it
2271 doesn't clash with the names we generate for terminal frames. */
2272 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2273 error ("Frame names of the form F<num> are usurped by Emacs");
2276 f->name = name;
2277 update_mode_lines = 1;
2280 void
2281 store_frame_param (f, prop, val)
2282 struct frame *f;
2283 Lisp_Object prop, val;
2285 register Lisp_Object old_alist_elt;
2287 /* The buffer-list parameters are stored in a special place and not
2288 in the alist. */
2289 if (EQ (prop, Qbuffer_list))
2291 f->buffer_list = val;
2292 return;
2294 if (EQ (prop, Qburied_buffer_list))
2296 f->buried_buffer_list = val;
2297 return;
2300 /* If PROP is a symbol which is supposed to have frame-local values,
2301 and it is set up based on this frame, switch to the global
2302 binding. That way, we can create or alter the frame-local binding
2303 without messing up the symbol's status. */
2304 if (SYMBOLP (prop))
2306 Lisp_Object valcontents;
2307 valcontents = SYMBOL_VALUE (prop);
2308 if ((BUFFER_LOCAL_VALUEP (valcontents)
2309 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
2310 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2311 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame
2312 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2313 swap_in_global_binding (prop);
2316 #ifndef WINDOWSNT
2317 /* The tty color mode needs to be set before the frame's parameter
2318 alist is updated with the new value, because set_tty_color_mode
2319 wants to look at the old mode. */
2320 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode))
2321 set_tty_color_mode (f, val);
2322 #endif
2324 /* Update the frame parameter alist. */
2325 old_alist_elt = Fassq (prop, f->param_alist);
2326 if (EQ (old_alist_elt, Qnil))
2327 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2328 else
2329 Fsetcdr (old_alist_elt, val);
2331 /* Update some other special parameters in their special places
2332 in addition to the alist. */
2334 if (EQ (prop, Qbuffer_predicate))
2335 f->buffer_predicate = val;
2337 if (! FRAME_WINDOW_P (f))
2339 if (EQ (prop, Qmenu_bar_lines))
2340 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2341 else if (EQ (prop, Qname))
2342 set_term_frame_name (f, val);
2345 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2347 if (! MINI_WINDOW_P (XWINDOW (val)))
2348 error ("Surrogate minibuffer windows must be minibuffer windows");
2350 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2351 && !EQ (val, f->minibuffer_window))
2352 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2354 /* Install the chosen minibuffer window, with proper buffer. */
2355 f->minibuffer_window = val;
2359 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2360 doc: /* Return the parameters-alist of frame FRAME.
2361 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2362 The meaningful PARMs depend on the kind of frame.
2363 If FRAME is omitted, return information on the currently selected frame. */)
2364 (frame)
2365 Lisp_Object frame;
2367 Lisp_Object alist;
2368 FRAME_PTR f;
2369 int height, width;
2370 struct gcpro gcpro1;
2372 if (NILP (frame))
2373 frame = selected_frame;
2375 CHECK_FRAME (frame);
2376 f = XFRAME (frame);
2378 if (!FRAME_LIVE_P (f))
2379 return Qnil;
2381 alist = Fcopy_alist (f->param_alist);
2382 GCPRO1 (alist);
2384 if (!FRAME_WINDOW_P (f))
2386 int fg = FRAME_FOREGROUND_PIXEL (f);
2387 int bg = FRAME_BACKGROUND_PIXEL (f);
2388 Lisp_Object elt;
2390 /* If the frame's parameter alist says the colors are
2391 unspecified and reversed, take the frame's background pixel
2392 for foreground and vice versa. */
2393 elt = Fassq (Qforeground_color, alist);
2394 if (CONSP (elt) && STRINGP (XCDR (elt)))
2396 if (strncmp (SDATA (XCDR (elt)),
2397 unspecified_bg,
2398 SCHARS (XCDR (elt))) == 0)
2399 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2400 else if (strncmp (SDATA (XCDR (elt)),
2401 unspecified_fg,
2402 SCHARS (XCDR (elt))) == 0)
2403 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2405 else
2406 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2407 elt = Fassq (Qbackground_color, alist);
2408 if (CONSP (elt) && STRINGP (XCDR (elt)))
2410 if (strncmp (SDATA (XCDR (elt)),
2411 unspecified_fg,
2412 SCHARS (XCDR (elt))) == 0)
2413 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2414 else if (strncmp (SDATA (XCDR (elt)),
2415 unspecified_bg,
2416 SCHARS (XCDR (elt))) == 0)
2417 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2419 else
2420 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2421 store_in_alist (&alist, intern ("font"),
2422 build_string (FRAME_MSDOS_P (f)
2423 ? "ms-dos"
2424 : FRAME_W32_P (f) ? "w32term"
2425 :"tty"));
2427 store_in_alist (&alist, Qname, f->name);
2428 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2429 store_in_alist (&alist, Qheight, make_number (height));
2430 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2431 store_in_alist (&alist, Qwidth, make_number (width));
2432 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2433 store_in_alist (&alist, Qminibuffer,
2434 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2435 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2436 : FRAME_MINIBUF_WINDOW (f)));
2437 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2438 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2439 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2441 /* I think this should be done with a hook. */
2442 #ifdef HAVE_WINDOW_SYSTEM
2443 if (FRAME_WINDOW_P (f))
2444 x_report_frame_params (f, &alist);
2445 else
2446 #endif
2448 /* This ought to be correct in f->param_alist for an X frame. */
2449 Lisp_Object lines;
2450 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2451 store_in_alist (&alist, Qmenu_bar_lines, lines);
2454 UNGCPRO;
2455 return alist;
2459 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2460 doc: /* Return FRAME's value for parameter PARAMETER.
2461 If FRAME is nil, describe the currently selected frame. */)
2462 (frame, parameter)
2463 Lisp_Object frame, parameter;
2465 struct frame *f;
2466 Lisp_Object value;
2468 if (NILP (frame))
2469 frame = selected_frame;
2470 else
2471 CHECK_FRAME (frame);
2472 CHECK_SYMBOL (parameter);
2474 f = XFRAME (frame);
2475 value = Qnil;
2477 if (FRAME_LIVE_P (f))
2479 /* Avoid consing in frequent cases. */
2480 if (EQ (parameter, Qname))
2481 value = f->name;
2482 #ifdef HAVE_X_WINDOWS
2483 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2484 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2485 #endif /* HAVE_X_WINDOWS */
2486 else if (EQ (parameter, Qbackground_color)
2487 || EQ (parameter, Qforeground_color))
2489 value = Fassq (parameter, f->param_alist);
2490 if (CONSP (value))
2492 value = XCDR (value);
2493 /* Fframe_parameters puts the actual fg/bg color names,
2494 even if f->param_alist says otherwise. This is
2495 important when param_alist's notion of colors is
2496 "unspecified". We need to do the same here. */
2497 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2499 const char *color_name;
2500 EMACS_INT csz;
2502 if (EQ (parameter, Qbackground_color))
2504 color_name = SDATA (value);
2505 csz = SCHARS (value);
2506 if (strncmp (color_name, unspecified_bg, csz) == 0)
2507 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2508 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2509 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2511 else if (EQ (parameter, Qforeground_color))
2513 color_name = SDATA (value);
2514 csz = SCHARS (value);
2515 if (strncmp (color_name, unspecified_fg, csz) == 0)
2516 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2517 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2518 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2522 else
2523 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2525 else if (EQ (parameter, Qdisplay_type)
2526 || EQ (parameter, Qbackground_mode))
2527 value = Fcdr (Fassq (parameter, f->param_alist));
2528 else
2529 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2532 return value;
2536 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2537 Smodify_frame_parameters, 2, 2, 0,
2538 doc: /* Modify the parameters of frame FRAME according to ALIST.
2539 If FRAME is nil, it defaults to the selected frame.
2540 ALIST is an alist of parameters to change and their new values.
2541 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2542 The meaningful PARMs depend on the kind of frame.
2543 Undefined PARMs are ignored, but stored in the frame's parameter list
2544 so that `frame-parameters' will return them.
2546 The value of frame parameter FOO can also be accessed
2547 as a frame-local binding for the variable FOO, if you have
2548 enabled such bindings for that variable with `make-variable-frame-local'. */)
2549 (frame, alist)
2550 Lisp_Object frame, alist;
2552 FRAME_PTR f;
2553 register Lisp_Object tail, prop, val;
2555 if (EQ (frame, Qnil))
2556 frame = selected_frame;
2557 CHECK_LIVE_FRAME (frame);
2558 f = XFRAME (frame);
2560 /* I think this should be done with a hook. */
2561 #ifdef HAVE_WINDOW_SYSTEM
2562 if (FRAME_WINDOW_P (f))
2563 x_set_frame_parameters (f, alist);
2564 else
2565 #endif
2566 #ifdef MSDOS
2567 if (FRAME_MSDOS_P (f))
2568 IT_set_frame_parameters (f, alist);
2569 else
2570 #endif
2573 int length = XINT (Flength (alist));
2574 int i;
2575 Lisp_Object *parms
2576 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2577 Lisp_Object *values
2578 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2580 /* Extract parm names and values into those vectors. */
2582 i = 0;
2583 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2585 Lisp_Object elt;
2587 elt = Fcar (tail);
2588 parms[i] = Fcar (elt);
2589 values[i] = Fcdr (elt);
2590 i++;
2593 /* Now process them in reverse of specified order. */
2594 for (i--; i >= 0; i--)
2596 prop = parms[i];
2597 val = values[i];
2598 store_frame_param (f, prop, val);
2600 /* Changing the background color might change the background
2601 mode, so that we have to load new defface specs.
2602 Call frame-set-background-mode to do that. */
2603 if (EQ (prop, Qbackground_color))
2604 call1 (Qframe_set_background_mode, frame);
2607 return Qnil;
2610 DEFUN ("frame-with-environment", Fframe_with_environment, Sframe_with_environment, 0, 1, 0,
2611 doc: /* Return the frame that has the environment variable list for FRAME.
2613 The frame-local environment variable list is normally shared between
2614 frames that were created in the same Emacsclient session. The
2615 environment list is stored in a single frame's 'environment parameter;
2616 the other frames' 'environment parameter is set to this frame. This
2617 function follows the chain of 'environment references to reach the
2618 frame that stores the actual local environment list, and returns that
2619 frame. */)
2620 (frame)
2621 Lisp_Object frame;
2623 Lisp_Object hare, tortoise;
2625 if (NILP (frame))
2626 frame = selected_frame;
2627 CHECK_FRAME (frame);
2629 hare = tortoise = get_frame_param (XFRAME (frame), Qenvironment);
2630 while (!NILP (hare) && FRAMEP (hare))
2632 frame = hare;
2633 hare = get_frame_param (XFRAME (hare), Qenvironment);
2634 if (NILP (hare) || !FRAMEP (hare))
2635 break;
2636 frame = hare;
2637 hare = get_frame_param (XFRAME (hare), Qenvironment);
2638 tortoise = get_frame_param (XFRAME (tortoise), Qenvironment);
2639 if (EQ (hare, tortoise))
2640 error ("Cyclic frame-local environment indirection");
2643 return frame;
2647 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2648 0, 1, 0,
2649 doc: /* Height in pixels of a line in the font in frame FRAME.
2650 If FRAME is omitted, the selected frame is used.
2651 For a terminal frame, the value is always 1. */)
2652 (frame)
2653 Lisp_Object frame;
2655 struct frame *f;
2657 if (NILP (frame))
2658 frame = selected_frame;
2659 CHECK_FRAME (frame);
2660 f = XFRAME (frame);
2662 #ifdef HAVE_WINDOW_SYSTEM
2663 if (FRAME_WINDOW_P (f))
2664 return make_number (x_char_height (f));
2665 else
2666 #endif
2667 return make_number (1);
2671 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2672 0, 1, 0,
2673 doc: /* Width in pixels of characters in the font in frame FRAME.
2674 If FRAME is omitted, the selected frame is used.
2675 On a graphical screen, the width is the standard width of the default font.
2676 For a terminal screen, the value is always 1. */)
2677 (frame)
2678 Lisp_Object frame;
2680 struct frame *f;
2682 if (NILP (frame))
2683 frame = selected_frame;
2684 CHECK_FRAME (frame);
2685 f = XFRAME (frame);
2687 #ifdef HAVE_WINDOW_SYSTEM
2688 if (FRAME_WINDOW_P (f))
2689 return make_number (x_char_width (f));
2690 else
2691 #endif
2692 return make_number (1);
2695 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2696 Sframe_pixel_height, 0, 1, 0,
2697 doc: /* Return a FRAME's height in pixels.
2698 This counts only the height available for text lines,
2699 not menu bars on window-system Emacs frames.
2700 For a terminal frame, the result really gives the height in characters.
2701 If FRAME is omitted, the selected frame is used. */)
2702 (frame)
2703 Lisp_Object frame;
2705 struct frame *f;
2707 if (NILP (frame))
2708 frame = selected_frame;
2709 CHECK_FRAME (frame);
2710 f = XFRAME (frame);
2712 #ifdef HAVE_WINDOW_SYSTEM
2713 if (FRAME_WINDOW_P (f))
2714 return make_number (x_pixel_height (f));
2715 else
2716 #endif
2717 return make_number (FRAME_LINES (f));
2720 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2721 Sframe_pixel_width, 0, 1, 0,
2722 doc: /* Return FRAME's width in pixels.
2723 For a terminal frame, the result really gives the width in characters.
2724 If FRAME is omitted, the selected frame is used. */)
2725 (frame)
2726 Lisp_Object frame;
2728 struct frame *f;
2730 if (NILP (frame))
2731 frame = selected_frame;
2732 CHECK_FRAME (frame);
2733 f = XFRAME (frame);
2735 #ifdef HAVE_WINDOW_SYSTEM
2736 if (FRAME_WINDOW_P (f))
2737 return make_number (x_pixel_width (f));
2738 else
2739 #endif
2740 return make_number (FRAME_COLS (f));
2743 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2744 doc: /* Specify that the frame FRAME has LINES lines.
2745 Optional third arg non-nil means that redisplay should use LINES lines
2746 but that the idea of the actual height of the frame should not be changed. */)
2747 (frame, lines, pretend)
2748 Lisp_Object frame, lines, pretend;
2750 register struct frame *f;
2752 CHECK_NUMBER (lines);
2753 if (NILP (frame))
2754 frame = selected_frame;
2755 CHECK_LIVE_FRAME (frame);
2756 f = XFRAME (frame);
2758 /* I think this should be done with a hook. */
2759 #ifdef HAVE_WINDOW_SYSTEM
2760 if (FRAME_WINDOW_P (f))
2762 if (XINT (lines) != FRAME_LINES (f))
2763 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2764 do_pending_window_change (0);
2766 else
2767 #endif
2768 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2769 return Qnil;
2772 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2773 doc: /* Specify that the frame FRAME has COLS columns.
2774 Optional third arg non-nil means that redisplay should use COLS columns
2775 but that the idea of the actual width of the frame should not be changed. */)
2776 (frame, cols, pretend)
2777 Lisp_Object frame, cols, pretend;
2779 register struct frame *f;
2780 CHECK_NUMBER (cols);
2781 if (NILP (frame))
2782 frame = selected_frame;
2783 CHECK_LIVE_FRAME (frame);
2784 f = XFRAME (frame);
2786 /* I think this should be done with a hook. */
2787 #ifdef HAVE_WINDOW_SYSTEM
2788 if (FRAME_WINDOW_P (f))
2790 if (XINT (cols) != FRAME_COLS (f))
2791 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2792 do_pending_window_change (0);
2794 else
2795 #endif
2796 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2797 return Qnil;
2800 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2801 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2802 (frame, cols, rows)
2803 Lisp_Object frame, cols, rows;
2805 register struct frame *f;
2807 CHECK_LIVE_FRAME (frame);
2808 CHECK_NUMBER (cols);
2809 CHECK_NUMBER (rows);
2810 f = XFRAME (frame);
2812 /* I think this should be done with a hook. */
2813 #ifdef HAVE_WINDOW_SYSTEM
2814 if (FRAME_WINDOW_P (f))
2816 if (XINT (rows) != FRAME_LINES (f)
2817 || XINT (cols) != FRAME_COLS (f)
2818 || f->new_text_lines || f->new_text_cols)
2819 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2820 do_pending_window_change (0);
2822 else
2823 #endif
2824 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2826 return Qnil;
2829 DEFUN ("set-frame-position", Fset_frame_position,
2830 Sset_frame_position, 3, 3, 0,
2831 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2832 This is actually the position of the upper left corner of the frame.
2833 Negative values for XOFFSET or YOFFSET are interpreted relative to
2834 the rightmost or bottommost possible position (that stays within the screen). */)
2835 (frame, xoffset, yoffset)
2836 Lisp_Object frame, xoffset, yoffset;
2838 register struct frame *f;
2840 CHECK_LIVE_FRAME (frame);
2841 CHECK_NUMBER (xoffset);
2842 CHECK_NUMBER (yoffset);
2843 f = XFRAME (frame);
2845 /* I think this should be done with a hook. */
2846 #ifdef HAVE_WINDOW_SYSTEM
2847 if (FRAME_WINDOW_P (f))
2848 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2849 #endif
2851 return Qt;
2855 /***********************************************************************
2856 Frame Parameters
2857 ***********************************************************************/
2859 /* Connect the frame-parameter names for X frames
2860 to the ways of passing the parameter values to the window system.
2862 The name of a parameter, as a Lisp symbol,
2863 has an `x-frame-parameter' property which is an integer in Lisp
2864 that is an index in this table. */
2866 struct frame_parm_table {
2867 char *name;
2868 Lisp_Object *variable;
2871 static struct frame_parm_table frame_parms[] =
2873 {"auto-raise", &Qauto_raise},
2874 {"auto-lower", &Qauto_lower},
2875 {"background-color", 0},
2876 {"border-color", &Qborder_color},
2877 {"border-width", &Qborder_width},
2878 {"cursor-color", &Qcursor_color},
2879 {"cursor-type", &Qcursor_type},
2880 {"font", 0},
2881 {"foreground-color", 0},
2882 {"icon-name", &Qicon_name},
2883 {"icon-type", &Qicon_type},
2884 {"internal-border-width", &Qinternal_border_width},
2885 {"menu-bar-lines", &Qmenu_bar_lines},
2886 {"mouse-color", &Qmouse_color},
2887 {"name", &Qname},
2888 {"scroll-bar-width", &Qscroll_bar_width},
2889 {"title", &Qtitle},
2890 {"unsplittable", &Qunsplittable},
2891 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2892 {"visibility", &Qvisibility},
2893 {"tool-bar-lines", &Qtool_bar_lines},
2894 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2895 {"scroll-bar-background", &Qscroll_bar_background},
2896 {"screen-gamma", &Qscreen_gamma},
2897 {"line-spacing", &Qline_spacing},
2898 {"left-fringe", &Qleft_fringe},
2899 {"right-fringe", &Qright_fringe},
2900 {"wait-for-wm", &Qwait_for_wm},
2901 {"fullscreen", &Qfullscreen},
2904 #ifdef HAVE_WINDOW_SYSTEM
2906 extern Lisp_Object Qbox;
2907 extern Lisp_Object Qtop;
2909 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2910 wanted positions of the WM window (not Emacs window).
2911 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2912 window (FRAME_X_WINDOW).
2915 void
2916 x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2917 struct frame *f;
2918 int *width;
2919 int *height;
2920 int *top_pos;
2921 int *left_pos;
2923 int newwidth = FRAME_COLS (f);
2924 int newheight = FRAME_LINES (f);
2926 *top_pos = f->top_pos;
2927 *left_pos = f->left_pos;
2929 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2931 int ph;
2933 ph = FRAME_X_DISPLAY_INFO (f)->height;
2934 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2935 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2936 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2937 *top_pos = 0;
2940 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2942 int pw;
2944 pw = FRAME_X_DISPLAY_INFO (f)->width;
2945 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2946 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2947 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2948 *left_pos = 0;
2951 *width = newwidth;
2952 *height = newheight;
2956 /* Change the parameters of frame F as specified by ALIST.
2957 If a parameter is not specially recognized, do nothing special;
2958 otherwise call the `x_set_...' function for that parameter.
2959 Except for certain geometry properties, always call store_frame_param
2960 to store the new value in the parameter alist. */
2962 void
2963 x_set_frame_parameters (f, alist)
2964 FRAME_PTR f;
2965 Lisp_Object alist;
2967 Lisp_Object tail;
2969 /* If both of these parameters are present, it's more efficient to
2970 set them both at once. So we wait until we've looked at the
2971 entire list before we set them. */
2972 int width, height;
2974 /* Same here. */
2975 Lisp_Object left, top;
2977 /* Same with these. */
2978 Lisp_Object icon_left, icon_top;
2980 /* Record in these vectors all the parms specified. */
2981 Lisp_Object *parms;
2982 Lisp_Object *values;
2983 int i, p;
2984 int left_no_change = 0, top_no_change = 0;
2985 int icon_left_no_change = 0, icon_top_no_change = 0;
2986 int fullscreen_is_being_set = 0;
2988 struct gcpro gcpro1, gcpro2;
2990 i = 0;
2991 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2992 i++;
2994 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2995 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2997 /* Extract parm names and values into those vectors. */
2999 i = 0;
3000 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
3002 Lisp_Object elt;
3004 elt = Fcar (tail);
3005 parms[i] = Fcar (elt);
3006 values[i] = Fcdr (elt);
3007 i++;
3009 /* TAIL and ALIST are not used again below here. */
3010 alist = tail = Qnil;
3012 GCPRO2 (*parms, *values);
3013 gcpro1.nvars = i;
3014 gcpro2.nvars = i;
3016 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
3017 because their values appear in VALUES and strings are not valid. */
3018 top = left = Qunbound;
3019 icon_left = icon_top = Qunbound;
3021 /* Provide default values for HEIGHT and WIDTH. */
3022 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
3023 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
3025 /* Process foreground_color and background_color before anything else.
3026 They are independent of other properties, but other properties (e.g.,
3027 cursor_color) are dependent upon them. */
3028 /* Process default font as well, since fringe widths depends on it. */
3029 /* Also, process fullscreen, width and height depend upon that */
3030 for (p = 0; p < i; p++)
3032 Lisp_Object prop, val;
3034 prop = parms[p];
3035 val = values[p];
3036 if (EQ (prop, Qforeground_color)
3037 || EQ (prop, Qbackground_color)
3038 || EQ (prop, Qfont)
3039 || EQ (prop, Qfullscreen))
3041 register Lisp_Object param_index, old_value;
3042 int count = SPECPDL_INDEX ();
3044 old_value = get_frame_param (f, prop);
3045 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
3047 if (NILP (Fequal (val, old_value)))
3049 /* For :font attributes, the frame_parm_handler
3050 x_set_font calls `face-set-after-frame-default'.
3051 Unless we bind inhibit-face-set-after-frame-default
3052 here, this would reset the :font attribute that we
3053 just applied to the default value for new faces. */
3054 specbind (Qinhibit_face_set_after_frame_default, Qt);
3056 store_frame_param (f, prop, val);
3058 param_index = Fget (prop, Qx_frame_parameter);
3059 if (NATNUMP (param_index)
3060 && (XFASTINT (param_index)
3061 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3062 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3063 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3064 unbind_to (count, Qnil);
3069 /* Now process them in reverse of specified order. */
3070 for (i--; i >= 0; i--)
3072 Lisp_Object prop, val;
3074 prop = parms[i];
3075 val = values[i];
3077 if (EQ (prop, Qwidth) && NATNUMP (val))
3078 width = XFASTINT (val);
3079 else if (EQ (prop, Qheight) && NATNUMP (val))
3080 height = XFASTINT (val);
3081 else if (EQ (prop, Qtop))
3082 top = val;
3083 else if (EQ (prop, Qleft))
3084 left = val;
3085 else if (EQ (prop, Qicon_top))
3086 icon_top = val;
3087 else if (EQ (prop, Qicon_left))
3088 icon_left = val;
3089 else if (EQ (prop, Qforeground_color)
3090 || EQ (prop, Qbackground_color)
3091 || EQ (prop, Qfont)
3092 || EQ (prop, Qfullscreen))
3093 /* Processed above. */
3094 continue;
3095 else
3097 register Lisp_Object param_index, old_value;
3099 old_value = get_frame_param (f, prop);
3101 store_frame_param (f, prop, val);
3103 param_index = Fget (prop, Qx_frame_parameter);
3104 if (NATNUMP (param_index)
3105 && (XFASTINT (param_index)
3106 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3107 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3108 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3112 /* Don't die if just one of these was set. */
3113 if (EQ (left, Qunbound))
3115 left_no_change = 1;
3116 if (f->left_pos < 0)
3117 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
3118 else
3119 XSETINT (left, f->left_pos);
3121 if (EQ (top, Qunbound))
3123 top_no_change = 1;
3124 if (f->top_pos < 0)
3125 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
3126 else
3127 XSETINT (top, f->top_pos);
3130 /* If one of the icon positions was not set, preserve or default it. */
3131 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
3133 icon_left_no_change = 1;
3134 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3135 if (NILP (icon_left))
3136 XSETINT (icon_left, 0);
3138 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
3140 icon_top_no_change = 1;
3141 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3142 if (NILP (icon_top))
3143 XSETINT (icon_top, 0);
3146 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
3148 /* If the frame is visible already and the fullscreen parameter is
3149 being set, it is too late to set WM manager hints to specify
3150 size and position.
3151 Here we first get the width, height and position that applies to
3152 fullscreen. We then move the frame to the appropriate
3153 position. Resize of the frame is taken care of in the code after
3154 this if-statement. */
3155 int new_left, new_top;
3157 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
3158 if (new_top != f->top_pos || new_left != f->left_pos)
3159 x_set_offset (f, new_left, new_top, 1);
3162 /* Don't set these parameters unless they've been explicitly
3163 specified. The window might be mapped or resized while we're in
3164 this function, and we don't want to override that unless the lisp
3165 code has asked for it.
3167 Don't set these parameters unless they actually differ from the
3168 window's current parameters; the window may not actually exist
3169 yet. */
3171 Lisp_Object frame;
3173 check_frame_size (f, &height, &width);
3175 XSETFRAME (frame, f);
3177 if (width != FRAME_COLS (f)
3178 || height != FRAME_LINES (f)
3179 || f->new_text_lines || f->new_text_cols)
3180 Fset_frame_size (frame, make_number (width), make_number (height));
3182 if ((!NILP (left) || !NILP (top))
3183 && ! (left_no_change && top_no_change)
3184 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3185 && NUMBERP (top) && XINT (top) == f->top_pos))
3187 int leftpos = 0;
3188 int toppos = 0;
3190 /* Record the signs. */
3191 f->size_hint_flags &= ~ (XNegative | YNegative);
3192 if (EQ (left, Qminus))
3193 f->size_hint_flags |= XNegative;
3194 else if (INTEGERP (left))
3196 leftpos = XINT (left);
3197 if (leftpos < 0)
3198 f->size_hint_flags |= XNegative;
3200 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3201 && CONSP (XCDR (left))
3202 && INTEGERP (XCAR (XCDR (left))))
3204 leftpos = - XINT (XCAR (XCDR (left)));
3205 f->size_hint_flags |= XNegative;
3207 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3208 && CONSP (XCDR (left))
3209 && INTEGERP (XCAR (XCDR (left))))
3211 leftpos = XINT (XCAR (XCDR (left)));
3214 if (EQ (top, Qminus))
3215 f->size_hint_flags |= YNegative;
3216 else if (INTEGERP (top))
3218 toppos = XINT (top);
3219 if (toppos < 0)
3220 f->size_hint_flags |= YNegative;
3222 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3223 && CONSP (XCDR (top))
3224 && INTEGERP (XCAR (XCDR (top))))
3226 toppos = - XINT (XCAR (XCDR (top)));
3227 f->size_hint_flags |= YNegative;
3229 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3230 && CONSP (XCDR (top))
3231 && INTEGERP (XCAR (XCDR (top))))
3233 toppos = XINT (XCAR (XCDR (top)));
3237 /* Store the numeric value of the position. */
3238 f->top_pos = toppos;
3239 f->left_pos = leftpos;
3241 f->win_gravity = NorthWestGravity;
3243 /* Actually set that position, and convert to absolute. */
3244 x_set_offset (f, leftpos, toppos, -1);
3247 if ((!NILP (icon_left) || !NILP (icon_top))
3248 && ! (icon_left_no_change && icon_top_no_change))
3249 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3252 UNGCPRO;
3256 /* Insert a description of internally-recorded parameters of frame X
3257 into the parameter alist *ALISTPTR that is to be given to the user.
3258 Only parameters that are specific to the X window system
3259 and whose values are not correctly recorded in the frame's
3260 param_alist need to be considered here. */
3262 void
3263 x_report_frame_params (f, alistptr)
3264 struct frame *f;
3265 Lisp_Object *alistptr;
3267 char buf[16];
3268 Lisp_Object tem;
3270 /* Represent negative positions (off the top or left screen edge)
3271 in a way that Fmodify_frame_parameters will understand correctly. */
3272 XSETINT (tem, f->left_pos);
3273 if (f->left_pos >= 0)
3274 store_in_alist (alistptr, Qleft, tem);
3275 else
3276 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3278 XSETINT (tem, f->top_pos);
3279 if (f->top_pos >= 0)
3280 store_in_alist (alistptr, Qtop, tem);
3281 else
3282 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3284 store_in_alist (alistptr, Qborder_width,
3285 make_number (f->border_width));
3286 store_in_alist (alistptr, Qinternal_border_width,
3287 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3288 store_in_alist (alistptr, Qleft_fringe,
3289 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3290 store_in_alist (alistptr, Qright_fringe,
3291 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3292 store_in_alist (alistptr, Qscroll_bar_width,
3293 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3294 ? make_number (0)
3295 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3296 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3297 /* nil means "use default width"
3298 for non-toolkit scroll bar.
3299 ruler-mode.el depends on this. */
3300 : Qnil));
3301 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3302 store_in_alist (alistptr, Qwindow_id,
3303 build_string (buf));
3304 #ifdef HAVE_X_WINDOWS
3305 #ifdef USE_X_TOOLKIT
3306 /* Tooltip frame may not have this widget. */
3307 if (FRAME_X_OUTPUT (f)->widget)
3308 #endif
3309 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3310 store_in_alist (alistptr, Qouter_window_id,
3311 build_string (buf));
3312 #endif
3313 store_in_alist (alistptr, Qicon_name, f->icon_name);
3314 FRAME_SAMPLE_VISIBILITY (f);
3315 store_in_alist (alistptr, Qvisibility,
3316 (FRAME_VISIBLE_P (f) ? Qt
3317 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3318 store_in_alist (alistptr, Qdisplay,
3319 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3321 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3322 tem = Qnil;
3323 else
3324 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3325 store_in_alist (alistptr, Qparent_id, tem);
3329 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3330 the previous value of that parameter, NEW_VALUE is the new value. */
3332 void
3333 x_set_fullscreen (f, new_value, old_value)
3334 struct frame *f;
3335 Lisp_Object new_value, old_value;
3337 if (NILP (new_value))
3338 f->want_fullscreen = FULLSCREEN_NONE;
3339 else if (EQ (new_value, Qfullboth))
3340 f->want_fullscreen = FULLSCREEN_BOTH;
3341 else if (EQ (new_value, Qfullwidth))
3342 f->want_fullscreen = FULLSCREEN_WIDTH;
3343 else if (EQ (new_value, Qfullheight))
3344 f->want_fullscreen = FULLSCREEN_HEIGHT;
3346 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3347 FRAME_TERMINAL (f)->fullscreen_hook (f);
3351 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3352 the previous value of that parameter, NEW_VALUE is the new value. */
3354 void
3355 x_set_line_spacing (f, new_value, old_value)
3356 struct frame *f;
3357 Lisp_Object new_value, old_value;
3359 if (NILP (new_value))
3360 f->extra_line_spacing = 0;
3361 else if (NATNUMP (new_value))
3362 f->extra_line_spacing = XFASTINT (new_value);
3363 else
3364 signal_error ("Invalid line-spacing", new_value);
3365 if (FRAME_VISIBLE_P (f))
3366 redraw_frame (f);
3370 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3371 the previous value of that parameter, NEW_VALUE is the new value. */
3373 void
3374 x_set_screen_gamma (f, new_value, old_value)
3375 struct frame *f;
3376 Lisp_Object new_value, old_value;
3378 Lisp_Object bgcolor;
3380 if (NILP (new_value))
3381 f->gamma = 0;
3382 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3383 /* The value 0.4545 is the normal viewing gamma. */
3384 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3385 else
3386 signal_error ("Invalid screen-gamma", new_value);
3388 /* Apply the new gamma value to the frame background. */
3389 bgcolor = Fassq (Qbackground_color, f->param_alist);
3390 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3392 Lisp_Object index = Fget (Qbackground_color, Qx_frame_parameter);
3393 if (NATNUMP (index)
3394 && (XFASTINT (index)
3395 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3396 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3397 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3398 (f, bgcolor, Qnil);
3401 Fclear_face_cache (Qnil);
3405 void
3406 x_set_font (f, arg, oldval)
3407 struct frame *f;
3408 Lisp_Object arg, oldval;
3410 Lisp_Object result;
3411 Lisp_Object fontset_name;
3412 Lisp_Object frame;
3413 int old_fontset = FRAME_FONTSET(f);
3415 CHECK_STRING (arg);
3417 fontset_name = Fquery_fontset (arg, Qnil);
3419 BLOCK_INPUT;
3420 result = (STRINGP (fontset_name)
3421 ? x_new_fontset (f, SDATA (fontset_name))
3422 : x_new_font (f, SDATA (arg)));
3423 UNBLOCK_INPUT;
3425 if (EQ (result, Qnil))
3426 error ("Font `%s' is not defined", SDATA (arg));
3427 else if (EQ (result, Qt))
3428 error ("The characters of the given font have varying widths");
3429 else if (STRINGP (result))
3431 set_default_ascii_font (result);
3432 if (STRINGP (fontset_name))
3434 /* Fontset names are built from ASCII font names, so the
3435 names may be equal despite there was a change. */
3436 if (old_fontset == FRAME_FONTSET (f))
3437 return;
3439 else if (!NILP (Fequal (result, oldval)))
3440 return;
3442 /* Recalculate toolbar height. */
3443 f->n_tool_bar_rows = 0;
3444 /* Ensure we redraw it. */
3445 clear_current_matrices (f);
3447 store_frame_param (f, Qfont, result);
3448 recompute_basic_faces (f);
3450 else
3451 abort ();
3453 do_pending_window_change (0);
3455 /* Don't call `face-set-after-frame-default' when faces haven't been
3456 initialized yet. This is the case when called from
3457 Fx_create_frame. In that case, the X widget or window doesn't
3458 exist either, and we can end up in x_report_frame_params with a
3459 null widget which gives a segfault. */
3460 if (FRAME_FACE_CACHE (f))
3462 XSETFRAME (frame, f);
3463 call1 (Qface_set_after_frame_default, frame);
3468 void
3469 x_set_fringe_width (f, new_value, old_value)
3470 struct frame *f;
3471 Lisp_Object new_value, old_value;
3473 compute_fringe_widths (f, 1);
3476 void
3477 x_set_border_width (f, arg, oldval)
3478 struct frame *f;
3479 Lisp_Object arg, oldval;
3481 CHECK_NUMBER (arg);
3483 if (XINT (arg) == f->border_width)
3484 return;
3486 if (FRAME_X_WINDOW (f) != 0)
3487 error ("Cannot change the border width of a frame");
3489 f->border_width = XINT (arg);
3492 void
3493 x_set_internal_border_width (f, arg, oldval)
3494 struct frame *f;
3495 Lisp_Object arg, oldval;
3497 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3499 CHECK_NUMBER (arg);
3500 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3501 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3502 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3504 #ifdef USE_X_TOOLKIT
3505 if (FRAME_X_OUTPUT (f)->edit_widget)
3506 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3507 #endif
3509 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3510 return;
3512 if (FRAME_X_WINDOW (f) != 0)
3514 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3515 SET_FRAME_GARBAGED (f);
3516 do_pending_window_change (0);
3518 else
3519 SET_FRAME_GARBAGED (f);
3522 void
3523 x_set_visibility (f, value, oldval)
3524 struct frame *f;
3525 Lisp_Object value, oldval;
3527 Lisp_Object frame;
3528 XSETFRAME (frame, f);
3530 if (NILP (value))
3531 Fmake_frame_invisible (frame, Qt);
3532 else if (EQ (value, Qicon))
3533 Ficonify_frame (frame);
3534 else
3535 Fmake_frame_visible (frame);
3538 void
3539 x_set_autoraise (f, arg, oldval)
3540 struct frame *f;
3541 Lisp_Object arg, oldval;
3543 f->auto_raise = !EQ (Qnil, arg);
3546 void
3547 x_set_autolower (f, arg, oldval)
3548 struct frame *f;
3549 Lisp_Object arg, oldval;
3551 f->auto_lower = !EQ (Qnil, arg);
3554 void
3555 x_set_unsplittable (f, arg, oldval)
3556 struct frame *f;
3557 Lisp_Object arg, oldval;
3559 f->no_split = !NILP (arg);
3562 void
3563 x_set_vertical_scroll_bars (f, arg, oldval)
3564 struct frame *f;
3565 Lisp_Object arg, oldval;
3567 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3568 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3569 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3570 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3572 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3573 = (NILP (arg)
3574 ? vertical_scroll_bar_none
3575 : EQ (Qleft, arg)
3576 ? vertical_scroll_bar_left
3577 : EQ (Qright, arg)
3578 ? vertical_scroll_bar_right
3579 : EQ (Qleft, Vdefault_frame_scroll_bars)
3580 ? vertical_scroll_bar_left
3581 : EQ (Qright, Vdefault_frame_scroll_bars)
3582 ? vertical_scroll_bar_right
3583 : vertical_scroll_bar_none);
3585 /* We set this parameter before creating the X window for the
3586 frame, so we can get the geometry right from the start.
3587 However, if the window hasn't been created yet, we shouldn't
3588 call x_set_window_size. */
3589 if (FRAME_X_WINDOW (f))
3590 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3591 do_pending_window_change (0);
3595 void
3596 x_set_scroll_bar_width (f, arg, oldval)
3597 struct frame *f;
3598 Lisp_Object arg, oldval;
3600 int wid = FRAME_COLUMN_WIDTH (f);
3602 if (NILP (arg))
3604 x_set_scroll_bar_default_width (f);
3606 if (FRAME_X_WINDOW (f))
3607 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3608 do_pending_window_change (0);
3610 else if (INTEGERP (arg) && XINT (arg) > 0
3611 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3613 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3614 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3616 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3617 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3618 if (FRAME_X_WINDOW (f))
3619 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3620 do_pending_window_change (0);
3623 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3624 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3625 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3630 /* Return non-nil if frame F wants a bitmap icon. */
3632 Lisp_Object
3633 x_icon_type (f)
3634 FRAME_PTR f;
3636 Lisp_Object tem;
3638 tem = assq_no_quit (Qicon_type, f->param_alist);
3639 if (CONSP (tem))
3640 return XCDR (tem);
3641 else
3642 return Qnil;
3646 /* Subroutines of creating an X frame. */
3648 /* Make sure that Vx_resource_name is set to a reasonable value.
3649 Fix it up, or set it to `emacs' if it is too hopeless. */
3651 void
3652 validate_x_resource_name ()
3654 int len = 0;
3655 /* Number of valid characters in the resource name. */
3656 int good_count = 0;
3657 /* Number of invalid characters in the resource name. */
3658 int bad_count = 0;
3659 Lisp_Object new;
3660 int i;
3662 if (!STRINGP (Vx_resource_class))
3663 Vx_resource_class = build_string (EMACS_CLASS);
3665 if (STRINGP (Vx_resource_name))
3667 unsigned char *p = SDATA (Vx_resource_name);
3668 int i;
3670 len = SBYTES (Vx_resource_name);
3672 /* Only letters, digits, - and _ are valid in resource names.
3673 Count the valid characters and count the invalid ones. */
3674 for (i = 0; i < len; i++)
3676 int c = p[i];
3677 if (! ((c >= 'a' && c <= 'z')
3678 || (c >= 'A' && c <= 'Z')
3679 || (c >= '0' && c <= '9')
3680 || c == '-' || c == '_'))
3681 bad_count++;
3682 else
3683 good_count++;
3686 else
3687 /* Not a string => completely invalid. */
3688 bad_count = 5, good_count = 0;
3690 /* If name is valid already, return. */
3691 if (bad_count == 0)
3692 return;
3694 /* If name is entirely invalid, or nearly so, use `emacs'. */
3695 if (good_count == 0
3696 || (good_count == 1 && bad_count > 0))
3698 Vx_resource_name = build_string ("emacs");
3699 return;
3702 /* Name is partly valid. Copy it and replace the invalid characters
3703 with underscores. */
3705 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3707 for (i = 0; i < len; i++)
3709 int c = SREF (new, i);
3710 if (! ((c >= 'a' && c <= 'z')
3711 || (c >= 'A' && c <= 'Z')
3712 || (c >= '0' && c <= '9')
3713 || c == '-' || c == '_'))
3714 SSET (new, i, '_');
3719 extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3720 extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3723 /* Get specified attribute from resource database RDB.
3724 See Fx_get_resource below for other parameters. */
3726 static Lisp_Object
3727 xrdb_get_resource (rdb, attribute, class, component, subclass)
3728 XrmDatabase rdb;
3729 Lisp_Object attribute, class, component, subclass;
3731 register char *value;
3732 char *name_key;
3733 char *class_key;
3735 CHECK_STRING (attribute);
3736 CHECK_STRING (class);
3738 if (!NILP (component))
3739 CHECK_STRING (component);
3740 if (!NILP (subclass))
3741 CHECK_STRING (subclass);
3742 if (NILP (component) != NILP (subclass))
3743 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3745 validate_x_resource_name ();
3747 /* Allocate space for the components, the dots which separate them,
3748 and the final '\0'. Make them big enough for the worst case. */
3749 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3750 + (STRINGP (component)
3751 ? SBYTES (component) : 0)
3752 + SBYTES (attribute)
3753 + 3);
3755 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3756 + SBYTES (class)
3757 + (STRINGP (subclass)
3758 ? SBYTES (subclass) : 0)
3759 + 3);
3761 /* Start with emacs.FRAMENAME for the name (the specific one)
3762 and with `Emacs' for the class key (the general one). */
3763 strcpy (name_key, SDATA (Vx_resource_name));
3764 strcpy (class_key, SDATA (Vx_resource_class));
3766 strcat (class_key, ".");
3767 strcat (class_key, SDATA (class));
3769 if (!NILP (component))
3771 strcat (class_key, ".");
3772 strcat (class_key, SDATA (subclass));
3774 strcat (name_key, ".");
3775 strcat (name_key, SDATA (component));
3778 strcat (name_key, ".");
3779 strcat (name_key, SDATA (attribute));
3781 value = x_get_string_resource (rdb, name_key, class_key);
3783 if (value != (char *) 0)
3784 return build_string (value);
3785 else
3786 return Qnil;
3790 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3791 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3792 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3793 class, where INSTANCE is the name under which Emacs was invoked, or
3794 the name specified by the `-name' or `-rn' command-line arguments.
3796 The optional arguments COMPONENT and SUBCLASS add to the key and the
3797 class, respectively. You must specify both of them or neither.
3798 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3799 and the class is `Emacs.CLASS.SUBCLASS'. */)
3800 (attribute, class, component, subclass)
3801 Lisp_Object attribute, class, component, subclass;
3803 #ifdef HAVE_X_WINDOWS
3804 check_x ();
3805 #endif
3807 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3808 attribute, class, component, subclass);
3811 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3813 Lisp_Object
3814 display_x_get_resource (dpyinfo, attribute, class, component, subclass)
3815 Display_Info *dpyinfo;
3816 Lisp_Object attribute, class, component, subclass;
3818 return xrdb_get_resource (dpyinfo->xrdb,
3819 attribute, class, component, subclass);
3822 /* Used when C code wants a resource value. */
3824 char *
3825 x_get_resource_string (attribute, class)
3826 char *attribute, *class;
3828 char *name_key;
3829 char *class_key;
3830 struct frame *sf = SELECTED_FRAME ();
3832 /* Allocate space for the components, the dots which separate them,
3833 and the final '\0'. */
3834 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3835 + strlen (attribute) + 2);
3836 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3837 + strlen (class) + 2);
3839 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3840 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3842 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3843 name_key, class_key);
3847 /* Return the value of parameter PARAM.
3849 First search ALIST, then Vdefault_frame_alist, then the X defaults
3850 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3852 Convert the resource to the type specified by desired_type.
3854 If no default is specified, return Qunbound. If you call
3855 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3856 and don't let it get stored in any Lisp-visible variables! */
3858 Lisp_Object
3859 x_get_arg (dpyinfo, alist, param, attribute, class, type)
3860 Display_Info *dpyinfo;
3861 Lisp_Object alist, param;
3862 char *attribute;
3863 char *class;
3864 enum resource_types type;
3866 register Lisp_Object tem;
3868 tem = Fassq (param, alist);
3870 if (!NILP (tem))
3872 /* If we find this parm in ALIST, clear it out
3873 so that it won't be "left over" at the end. */
3874 #ifndef WINDOWSNT /* w32fns.c has not yet been changed to cope with this. */
3875 Lisp_Object tail;
3876 XSETCAR (tem, Qnil);
3877 /* In case the parameter appears more than once in the alist,
3878 clear it out. */
3879 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3880 if (CONSP (XCAR (tail))
3881 && EQ (XCAR (XCAR (tail)), param))
3882 XSETCAR (XCAR (tail), Qnil);
3883 #endif
3885 else
3886 tem = Fassq (param, Vdefault_frame_alist);
3888 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3889 look in the X resources. */
3890 if (EQ (tem, Qnil))
3892 if (attribute)
3894 tem = display_x_get_resource (dpyinfo,
3895 build_string (attribute),
3896 build_string (class),
3897 Qnil, Qnil);
3899 if (NILP (tem))
3900 return Qunbound;
3902 switch (type)
3904 case RES_TYPE_NUMBER:
3905 return make_number (atoi (SDATA (tem)));
3907 case RES_TYPE_FLOAT:
3908 return make_float (atof (SDATA (tem)));
3910 case RES_TYPE_BOOLEAN:
3911 tem = Fdowncase (tem);
3912 if (!strcmp (SDATA (tem), "on")
3913 || !strcmp (SDATA (tem), "true"))
3914 return Qt;
3915 else
3916 return Qnil;
3918 case RES_TYPE_STRING:
3919 return tem;
3921 case RES_TYPE_SYMBOL:
3922 /* As a special case, we map the values `true' and `on'
3923 to Qt, and `false' and `off' to Qnil. */
3925 Lisp_Object lower;
3926 lower = Fdowncase (tem);
3927 if (!strcmp (SDATA (lower), "on")
3928 || !strcmp (SDATA (lower), "true"))
3929 return Qt;
3930 else if (!strcmp (SDATA (lower), "off")
3931 || !strcmp (SDATA (lower), "false"))
3932 return Qnil;
3933 else
3934 return Fintern (tem, Qnil);
3937 default:
3938 abort ();
3941 else
3942 return Qunbound;
3944 return Fcdr (tem);
3947 Lisp_Object
3948 x_frame_get_arg (f, alist, param, attribute, class, type)
3949 struct frame *f;
3950 Lisp_Object alist, param;
3951 char *attribute;
3952 char *class;
3953 enum resource_types type;
3955 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3956 alist, param, attribute, class, type);
3959 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3961 Lisp_Object
3962 x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
3963 struct frame *f;
3964 Lisp_Object alist, param;
3965 char *attribute;
3966 char *class;
3967 enum resource_types type;
3969 Lisp_Object value;
3971 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3972 attribute, class, type);
3973 if (! NILP (value) && ! EQ (value, Qunbound))
3974 store_frame_param (f, param, value);
3976 return value;
3980 /* Record in frame F the specified or default value according to ALIST
3981 of the parameter named PROP (a Lisp symbol).
3982 If no value is specified for PROP, look for an X default for XPROP
3983 on the frame named NAME.
3984 If that is not found either, use the value DEFLT. */
3986 Lisp_Object
3987 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
3988 struct frame *f;
3989 Lisp_Object alist;
3990 Lisp_Object prop;
3991 Lisp_Object deflt;
3992 char *xprop;
3993 char *xclass;
3994 enum resource_types type;
3996 Lisp_Object tem;
3998 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3999 if (EQ (tem, Qunbound))
4000 tem = deflt;
4001 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
4002 return tem;
4008 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4009 doc: /* Parse an X-style geometry string STRING.
4010 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4011 The properties returned may include `top', `left', `height', and `width'.
4012 The value of `left' or `top' may be an integer,
4013 or a list (+ N) meaning N pixels relative to top/left corner,
4014 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
4015 (string)
4016 Lisp_Object string;
4018 int geometry, x, y;
4019 unsigned int width, height;
4020 Lisp_Object result;
4022 CHECK_STRING (string);
4024 geometry = XParseGeometry ((char *) SDATA (string),
4025 &x, &y, &width, &height);
4027 #if 0
4028 if (!!(geometry & XValue) != !!(geometry & YValue))
4029 error ("Must specify both x and y position, or neither");
4030 #endif
4032 result = Qnil;
4033 if (geometry & XValue)
4035 Lisp_Object element;
4037 if (x >= 0 && (geometry & XNegative))
4038 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
4039 else if (x < 0 && ! (geometry & XNegative))
4040 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
4041 else
4042 element = Fcons (Qleft, make_number (x));
4043 result = Fcons (element, result);
4046 if (geometry & YValue)
4048 Lisp_Object element;
4050 if (y >= 0 && (geometry & YNegative))
4051 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
4052 else if (y < 0 && ! (geometry & YNegative))
4053 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
4054 else
4055 element = Fcons (Qtop, make_number (y));
4056 result = Fcons (element, result);
4059 if (geometry & WidthValue)
4060 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4061 if (geometry & HeightValue)
4062 result = Fcons (Fcons (Qheight, make_number (height)), result);
4064 return result;
4067 /* Calculate the desired size and position of frame F.
4068 Return the flags saying which aspects were specified.
4070 Also set the win_gravity and size_hint_flags of F.
4072 Adjust height for toolbar if TOOLBAR_P is 1.
4074 This function does not make the coordinates positive. */
4076 #define DEFAULT_ROWS 40
4077 #define DEFAULT_COLS 80
4080 x_figure_window_size (f, parms, toolbar_p)
4081 struct frame *f;
4082 Lisp_Object parms;
4083 int toolbar_p;
4085 register Lisp_Object tem0, tem1, tem2;
4086 long window_prompting = 0;
4087 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
4089 /* Default values if we fall through.
4090 Actually, if that happens we should get
4091 window manager prompting. */
4092 SET_FRAME_COLS (f, DEFAULT_COLS);
4093 FRAME_LINES (f) = DEFAULT_ROWS;
4094 /* Window managers expect that if program-specified
4095 positions are not (0,0), they're intentional, not defaults. */
4096 f->top_pos = 0;
4097 f->left_pos = 0;
4099 /* Ensure that old new_text_cols and new_text_lines will not override the
4100 values set here. */
4101 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4102 f->new_text_cols = f->new_text_lines = 0;
4104 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4105 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4106 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4107 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4109 if (!EQ (tem0, Qunbound))
4111 CHECK_NUMBER (tem0);
4112 FRAME_LINES (f) = XINT (tem0);
4114 if (!EQ (tem1, Qunbound))
4116 CHECK_NUMBER (tem1);
4117 SET_FRAME_COLS (f, XINT (tem1));
4119 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4120 window_prompting |= USSize;
4121 else
4122 window_prompting |= PSize;
4125 f->scroll_bar_actual_width
4126 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4128 /* This used to be done _before_ calling x_figure_window_size, but
4129 since the height is reset here, this was really a no-op. I
4130 assume that moving it here does what Gerd intended (although he
4131 no longer can remember what that was... ++KFS, 2003-03-25. */
4133 /* Add the tool-bar height to the initial frame height so that the
4134 user gets a text display area of the size he specified with -g or
4135 via .Xdefaults. Later changes of the tool-bar height don't
4136 change the frame size. This is done so that users can create
4137 tall Emacs frames without having to guess how tall the tool-bar
4138 will get. */
4139 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4141 int margin, relief, bar_height;
4143 relief = (tool_bar_button_relief >= 0
4144 ? tool_bar_button_relief
4145 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4147 if (INTEGERP (Vtool_bar_button_margin)
4148 && XINT (Vtool_bar_button_margin) > 0)
4149 margin = XFASTINT (Vtool_bar_button_margin);
4150 else if (CONSP (Vtool_bar_button_margin)
4151 && INTEGERP (XCDR (Vtool_bar_button_margin))
4152 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
4153 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4154 else
4155 margin = 0;
4157 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4158 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4161 compute_fringe_widths (f, 0);
4163 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4164 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4166 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4167 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4168 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4169 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4171 if (EQ (tem0, Qminus))
4173 f->top_pos = 0;
4174 window_prompting |= YNegative;
4176 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4177 && CONSP (XCDR (tem0))
4178 && INTEGERP (XCAR (XCDR (tem0))))
4180 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4181 window_prompting |= YNegative;
4183 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4184 && CONSP (XCDR (tem0))
4185 && INTEGERP (XCAR (XCDR (tem0))))
4187 f->top_pos = XINT (XCAR (XCDR (tem0)));
4189 else if (EQ (tem0, Qunbound))
4190 f->top_pos = 0;
4191 else
4193 CHECK_NUMBER (tem0);
4194 f->top_pos = XINT (tem0);
4195 if (f->top_pos < 0)
4196 window_prompting |= YNegative;
4199 if (EQ (tem1, Qminus))
4201 f->left_pos = 0;
4202 window_prompting |= XNegative;
4204 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4205 && CONSP (XCDR (tem1))
4206 && INTEGERP (XCAR (XCDR (tem1))))
4208 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4209 window_prompting |= XNegative;
4211 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4212 && CONSP (XCDR (tem1))
4213 && INTEGERP (XCAR (XCDR (tem1))))
4215 f->left_pos = XINT (XCAR (XCDR (tem1)));
4217 else if (EQ (tem1, Qunbound))
4218 f->left_pos = 0;
4219 else
4221 CHECK_NUMBER (tem1);
4222 f->left_pos = XINT (tem1);
4223 if (f->left_pos < 0)
4224 window_prompting |= XNegative;
4227 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4228 window_prompting |= USPosition;
4229 else
4230 window_prompting |= PPosition;
4233 if (f->want_fullscreen != FULLSCREEN_NONE)
4235 int left, top;
4236 int width, height;
4238 /* It takes both for some WM:s to place it where we want */
4239 window_prompting = USPosition | PPosition;
4240 x_fullscreen_adjust (f, &width, &height, &top, &left);
4241 FRAME_COLS (f) = width;
4242 FRAME_LINES (f) = height;
4243 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
4244 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
4245 f->left_pos = left;
4246 f->top_pos = top;
4249 if (window_prompting & XNegative)
4251 if (window_prompting & YNegative)
4252 f->win_gravity = SouthEastGravity;
4253 else
4254 f->win_gravity = NorthEastGravity;
4256 else
4258 if (window_prompting & YNegative)
4259 f->win_gravity = SouthWestGravity;
4260 else
4261 f->win_gravity = NorthWestGravity;
4264 f->size_hint_flags = window_prompting;
4266 return window_prompting;
4271 #endif /* HAVE_WINDOW_SYSTEM */
4275 /***********************************************************************
4276 Initialization
4277 ***********************************************************************/
4279 void
4280 syms_of_frame ()
4282 Qframep = intern ("framep");
4283 staticpro (&Qframep);
4284 Qframe_live_p = intern ("frame-live-p");
4285 staticpro (&Qframe_live_p);
4286 Qheight = intern ("height");
4287 staticpro (&Qheight);
4288 Qicon = intern ("icon");
4289 staticpro (&Qicon);
4290 Qminibuffer = intern ("minibuffer");
4291 staticpro (&Qminibuffer);
4292 Qmodeline = intern ("modeline");
4293 staticpro (&Qmodeline);
4294 Qonly = intern ("only");
4295 staticpro (&Qonly);
4296 Qwidth = intern ("width");
4297 staticpro (&Qwidth);
4298 Qgeometry = intern ("geometry");
4299 staticpro (&Qgeometry);
4300 Qicon_left = intern ("icon-left");
4301 staticpro (&Qicon_left);
4302 Qicon_top = intern ("icon-top");
4303 staticpro (&Qicon_top);
4304 Qleft = intern ("left");
4305 staticpro (&Qleft);
4306 Qright = intern ("right");
4307 staticpro (&Qright);
4308 Quser_position = intern ("user-position");
4309 staticpro (&Quser_position);
4310 Quser_size = intern ("user-size");
4311 staticpro (&Quser_size);
4312 Qwindow_id = intern ("window-id");
4313 staticpro (&Qwindow_id);
4314 #ifdef HAVE_X_WINDOWS
4315 Qouter_window_id = intern ("outer-window-id");
4316 staticpro (&Qouter_window_id);
4317 #endif
4318 Qparent_id = intern ("parent-id");
4319 staticpro (&Qparent_id);
4320 Qx = intern ("x");
4321 staticpro (&Qx);
4322 Qw32 = intern ("w32");
4323 staticpro (&Qw32);
4324 Qpc = intern ("pc");
4325 staticpro (&Qpc);
4326 Qmac = intern ("mac");
4327 staticpro (&Qmac);
4328 Qvisible = intern ("visible");
4329 staticpro (&Qvisible);
4330 Qbuffer_predicate = intern ("buffer-predicate");
4331 staticpro (&Qbuffer_predicate);
4332 Qbuffer_list = intern ("buffer-list");
4333 staticpro (&Qbuffer_list);
4334 Qburied_buffer_list = intern ("buried-buffer-list");
4335 staticpro (&Qburied_buffer_list);
4336 Qdisplay_type = intern ("display-type");
4337 staticpro (&Qdisplay_type);
4338 Qbackground_mode = intern ("background-mode");
4339 staticpro (&Qbackground_mode);
4340 Qtty_color_mode = intern ("tty-color-mode");
4341 staticpro (&Qtty_color_mode);
4342 Qtty = intern ("tty");
4343 staticpro (&Qtty);
4344 Qtty_type = intern ("tty-type");
4345 staticpro (&Qtty_type);
4346 Qwindow_system = intern ("window-system");
4347 staticpro (&Qwindow_system);
4348 Qenvironment = intern ("environment");
4349 staticpro (&Qenvironment);
4351 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4352 staticpro (&Qface_set_after_frame_default);
4354 Qinhibit_face_set_after_frame_default
4355 = intern ("inhibit-face-set-after-frame-default");
4356 staticpro (&Qinhibit_face_set_after_frame_default);
4358 Qfullwidth = intern ("fullwidth");
4359 staticpro (&Qfullwidth);
4360 Qfullheight = intern ("fullheight");
4361 staticpro (&Qfullheight);
4362 Qfullboth = intern ("fullboth");
4363 staticpro (&Qfullboth);
4364 Qx_resource_name = intern ("x-resource-name");
4365 staticpro (&Qx_resource_name);
4367 Qx_frame_parameter = intern ("x-frame-parameter");
4368 staticpro (&Qx_frame_parameter);
4370 Qterminal = intern ("terminal");
4371 staticpro (&Qterminal);
4372 Qterminal_live_p = intern ("terminal-live-p");
4373 staticpro (&Qterminal_live_p);
4376 int i;
4378 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4380 Lisp_Object v = intern (frame_parms[i].name);
4381 if (frame_parms[i].variable)
4383 *frame_parms[i].variable = v;
4384 staticpro (frame_parms[i].variable);
4386 Fput (v, Qx_frame_parameter, make_number (i));
4390 #ifdef HAVE_WINDOW_SYSTEM
4391 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4392 doc: /* The name Emacs uses to look up X resources.
4393 `x-get-resource' uses this as the first component of the instance name
4394 when requesting resource values.
4395 Emacs initially sets `x-resource-name' to the name under which Emacs
4396 was invoked, or to the value specified with the `-name' or `-rn'
4397 switches, if present.
4399 It may be useful to bind this variable locally around a call
4400 to `x-get-resource'. See also the variable `x-resource-class'. */);
4401 Vx_resource_name = Qnil;
4403 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4404 doc: /* The class Emacs uses to look up X resources.
4405 `x-get-resource' uses this as the first component of the instance class
4406 when requesting resource values.
4408 Emacs initially sets `x-resource-class' to "Emacs".
4410 Setting this variable permanently is not a reasonable thing to do,
4411 but binding this variable locally around a call to `x-get-resource'
4412 is a reasonable practice. See also the variable `x-resource-name'. */);
4413 Vx_resource_class = build_string (EMACS_CLASS);
4414 #endif
4416 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4417 doc: /* Alist of default values for frame creation.
4418 These may be set in your init file, like this:
4419 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4420 These override values given in window system configuration data,
4421 including X Windows' defaults database.
4422 For values specific to the first Emacs frame, see `initial-frame-alist'.
4423 For window-system specific values, see `window-system-default-frame-alist'.
4424 For values specific to the separate minibuffer frame, see
4425 `minibuffer-frame-alist'.
4426 The `menu-bar-lines' element of the list controls whether new frames
4427 have menu bars; `menu-bar-mode' works by altering this element.
4428 Setting this variable does not affect existing frames, only new ones. */);
4429 Vdefault_frame_alist = Qnil;
4431 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4432 doc: /* Default position of scroll bars on this window-system. */);
4433 #ifdef HAVE_WINDOW_SYSTEM
4434 #if defined(HAVE_NTGUI) || defined(MAC_OS)
4435 /* MS-Windows has scroll bars on the right by default. */
4436 Vdefault_frame_scroll_bars = Qright;
4437 #else
4438 Vdefault_frame_scroll_bars = Qleft;
4439 #endif
4440 #else
4441 Vdefault_frame_scroll_bars = Qnil;
4442 #endif
4444 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4445 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4447 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4448 doc: /* Non-nil if all of Emacs is iconified and frame updates are not needed. */);
4449 Vemacs_iconified = Qnil;
4451 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4452 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4453 `mouse-position' calls this function, passing its usual return value as
4454 argument, and returns whatever this function returns.
4455 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4456 which need to do mouse handling at the Lisp level. */);
4457 Vmouse_position_function = Qnil;
4459 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4460 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4461 If the value is an integer, highlighting is only shown after moving the
4462 mouse, while keyboard input turns off the highlight even when the mouse
4463 is over the clickable text. However, the mouse shape still indicates
4464 when the mouse is over clickable text. */);
4465 Vmouse_highlight = Qt;
4467 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4468 doc: /* Functions to be run before deleting a frame.
4469 The functions are run with one arg, the frame to be deleted.
4470 See `delete-frame'.
4472 Note that functions in this list may be called twice on the same
4473 frame. In the second invocation, the frame is already deleted, and
4474 the function should do nothing. (You can use `frame-live-p' to check
4475 for this.) This wrinkle happens when an earlier function in
4476 `delete-frame-functions' (indirectly) calls delete-frame
4477 recursively. */);
4478 Vdelete_frame_functions = Qnil;
4480 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4481 doc: /* Minibufferless frames use this frame's minibuffer.
4483 Emacs cannot create minibufferless frames unless this is set to an
4484 appropriate surrogate.
4486 Emacs consults this variable only when creating minibufferless
4487 frames; once the frame is created, it sticks with its assigned
4488 minibuffer, no matter what this variable is set to. This means that
4489 this variable doesn't necessarily say anything meaningful about the
4490 current set of frames, or where the minibuffer is currently being
4491 displayed.
4493 This variable is local to the current terminal and cannot be buffer-local. */);
4495 staticpro (&Vframe_list);
4497 defsubr (&Sactive_minibuffer_window);
4498 defsubr (&Sframep);
4499 defsubr (&Sframe_live_p);
4500 defsubr (&Swindow_system);
4501 defsubr (&Smake_terminal_frame);
4502 defsubr (&Shandle_switch_frame);
4503 defsubr (&Sselect_frame);
4504 defsubr (&Sselected_frame);
4505 defsubr (&Swindow_frame);
4506 defsubr (&Sframe_root_window);
4507 defsubr (&Sframe_first_window);
4508 defsubr (&Sframe_selected_window);
4509 defsubr (&Sset_frame_selected_window);
4510 defsubr (&Sframe_list);
4511 defsubr (&Snext_frame);
4512 defsubr (&Sprevious_frame);
4513 defsubr (&Sdelete_frame);
4514 defsubr (&Smouse_position);
4515 defsubr (&Smouse_pixel_position);
4516 defsubr (&Sset_mouse_position);
4517 defsubr (&Sset_mouse_pixel_position);
4518 #if 0
4519 defsubr (&Sframe_configuration);
4520 defsubr (&Srestore_frame_configuration);
4521 #endif
4522 defsubr (&Smake_frame_visible);
4523 defsubr (&Smake_frame_invisible);
4524 defsubr (&Siconify_frame);
4525 defsubr (&Sframe_visible_p);
4526 defsubr (&Svisible_frame_list);
4527 defsubr (&Sraise_frame);
4528 defsubr (&Slower_frame);
4529 defsubr (&Sredirect_frame_focus);
4530 defsubr (&Sframe_focus);
4531 defsubr (&Sframe_parameters);
4532 defsubr (&Sframe_parameter);
4533 defsubr (&Smodify_frame_parameters);
4534 defsubr (&Sframe_with_environment);
4535 defsubr (&Sframe_char_height);
4536 defsubr (&Sframe_char_width);
4537 defsubr (&Sframe_pixel_height);
4538 defsubr (&Sframe_pixel_width);
4539 defsubr (&Sset_frame_height);
4540 defsubr (&Sset_frame_width);
4541 defsubr (&Sset_frame_size);
4542 defsubr (&Sset_frame_position);
4544 #ifdef HAVE_WINDOW_SYSTEM
4545 defsubr (&Sx_get_resource);
4546 defsubr (&Sx_parse_geometry);
4547 #endif
4551 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4552 (do not change this comment) */