Merged from miles@gnu.org--gnu-2005 (patch 441-446)
[emacs.git] / src / frame.c
blob6a54e26121feabcda4ce93c3778431778656a9ba
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2003, 2004, 2005
3 Free Software Foundation.
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 2, 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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, 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;
75 Lisp_Object Qinhibit_default_face_x_resources;
77 Lisp_Object Qx_frame_parameter;
78 Lisp_Object Qx_resource_name;
79 Lisp_Object Qdisplay_id;
80 Lisp_Object Qdisplay_live_p;
82 /* Frame parameters (set or reported). */
84 Lisp_Object Qauto_raise, Qauto_lower;
85 Lisp_Object Qborder_color, Qborder_width;
86 Lisp_Object Qcursor_color, Qcursor_type;
87 Lisp_Object Qgeometry; /* Not used */
88 Lisp_Object Qheight, Qwidth;
89 Lisp_Object Qleft, Qright;
90 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
91 Lisp_Object Qinternal_border_width;
92 Lisp_Object Qmouse_color;
93 Lisp_Object Qminibuffer;
94 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
95 Lisp_Object Qvisibility;
96 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
97 Lisp_Object Qscreen_gamma;
98 Lisp_Object Qline_spacing;
99 Lisp_Object Quser_position, Quser_size;
100 Lisp_Object Qwait_for_wm;
101 Lisp_Object Qwindow_id;
102 #ifdef HAVE_X_WINDOWS
103 Lisp_Object Qouter_window_id;
104 #endif
105 Lisp_Object Qparent_id;
106 Lisp_Object Qtitle, Qname;
107 Lisp_Object Qunsplittable;
108 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
109 Lisp_Object Qleft_fringe, Qright_fringe;
110 Lisp_Object Qbuffer_predicate, Qbuffer_list;
111 Lisp_Object Qtty_color_mode;
112 Lisp_Object Qtty, Qtty_type;
113 Lisp_Object Qwindow_system;
115 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
117 Lisp_Object Qface_set_after_frame_default;
119 Lisp_Object Vterminal_frame;
120 Lisp_Object Vdefault_frame_alist;
121 Lisp_Object Vdefault_frame_scroll_bars;
122 Lisp_Object Vmouse_position_function;
123 Lisp_Object Vmouse_highlight;
124 Lisp_Object Vdelete_frame_functions;
126 static void
127 set_menu_bar_lines_1 (window, n)
128 Lisp_Object window;
129 int n;
131 struct window *w = XWINDOW (window);
133 XSETFASTINT (w->last_modified, 0);
134 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
135 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
137 if (INTEGERP (w->orig_top_line))
138 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
139 if (INTEGERP (w->orig_total_lines))
140 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
142 /* Handle just the top child in a vertical split. */
143 if (!NILP (w->vchild))
144 set_menu_bar_lines_1 (w->vchild, n);
146 /* Adjust all children in a horizontal split. */
147 for (window = w->hchild; !NILP (window); window = w->next)
149 w = XWINDOW (window);
150 set_menu_bar_lines_1 (window, n);
154 void
155 set_menu_bar_lines (f, value, oldval)
156 struct frame *f;
157 Lisp_Object value, oldval;
159 int nlines;
160 int olines = FRAME_MENU_BAR_LINES (f);
162 /* Right now, menu bars don't work properly in minibuf-only frames;
163 most of the commands try to apply themselves to the minibuffer
164 frame itself, and get an error because you can't switch buffers
165 in or split the minibuffer window. */
166 if (FRAME_MINIBUF_ONLY_P (f))
167 return;
169 if (INTEGERP (value))
170 nlines = XINT (value);
171 else
172 nlines = 0;
174 if (nlines != olines)
176 windows_or_buffers_changed++;
177 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
178 FRAME_MENU_BAR_LINES (f) = nlines;
179 set_menu_bar_lines_1 (f->root_window, nlines - olines);
180 adjust_glyphs (f);
184 Lisp_Object Vemacs_iconified;
185 Lisp_Object Vframe_list;
187 extern Lisp_Object Vminibuffer_list;
188 extern Lisp_Object get_minibuffer ();
189 extern Lisp_Object Fhandle_switch_frame ();
190 extern Lisp_Object Fredirect_frame_focus ();
191 extern Lisp_Object x_get_focus_frame ();
193 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
194 doc: /* Return non-nil if OBJECT is a frame.
195 Value is t for a termcap frame (a character-only terminal),
196 `x' for an Emacs frame that is really an X window,
197 `w32' for an Emacs frame that is a window on MS-Windows display,
198 `mac' for an Emacs frame on a Macintosh display,
199 `pc' for a direct-write MS-DOS frame.
200 See also `frame-live-p'. */)
201 (object)
202 Lisp_Object object;
204 if (!FRAMEP (object))
205 return Qnil;
206 switch (XFRAME (object)->output_method)
208 case output_initial: /* The initial frame is like a termcap frame. */
209 case output_termcap:
210 return Qt;
211 case output_x_window:
212 return Qx;
213 case output_w32:
214 return Qw32;
215 case output_msdos_raw:
216 return Qpc;
217 case output_mac:
218 return Qmac;
219 default:
220 abort ();
224 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
225 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
226 Value is nil if OBJECT is not a live frame. If object is a live
227 frame, the return value indicates what sort of output device it is
228 displayed on. See the documentation of `framep' for possible
229 return values. */)
230 (object)
231 Lisp_Object object;
233 return ((FRAMEP (object)
234 && FRAME_LIVE_P (XFRAME (object)))
235 ? Fframep (object)
236 : Qnil);
239 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
240 doc: /* The name of the window system that FRAME is displaying through.
241 The value is a symbol---for instance, 'x' for X windows.
242 The value is nil if Emacs is using a text-only terminal.
244 FRAME defaults to the currently selected frame. */)
245 (frame)
246 Lisp_Object frame;
248 Lisp_Object type;
249 if (NILP (frame))
250 frame = selected_frame;
252 type = Fframep (frame);
254 if (NILP (type))
255 wrong_type_argument (Qframep, frame);
257 if (EQ (type, Qt))
258 return Qnil;
259 else
260 return type;
263 struct frame *
264 make_frame (mini_p)
265 int mini_p;
267 Lisp_Object frame;
268 register struct frame *f;
269 register Lisp_Object root_window;
270 register Lisp_Object mini_window;
272 f = allocate_frame ();
273 XSETFRAME (frame, f);
275 f->desired_matrix = 0;
276 f->current_matrix = 0;
277 f->desired_pool = 0;
278 f->current_pool = 0;
279 f->glyphs_initialized_p = 0;
280 f->decode_mode_spec_buffer = 0;
281 f->visible = 0;
282 f->async_visible = 0;
283 f->output_data.nothing = 0;
284 f->iconified = 0;
285 f->async_iconified = 0;
286 f->wants_modeline = 1;
287 f->auto_raise = 0;
288 f->auto_lower = 0;
289 f->no_split = 0;
290 f->garbaged = 1;
291 f->has_minibuffer = mini_p;
292 f->focus_frame = Qnil;
293 f->explicit_name = 0;
294 f->can_have_scroll_bars = 0;
295 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
296 f->param_alist = Qnil;
297 f->scroll_bars = Qnil;
298 f->condemned_scroll_bars = Qnil;
299 f->face_alist = Qnil;
300 f->face_cache = NULL;
301 f->menu_bar_items = Qnil;
302 f->menu_bar_vector = Qnil;
303 f->menu_bar_items_used = 0;
304 f->buffer_predicate = Qnil;
305 f->buffer_list = Qnil;
306 #ifdef MULTI_KBOARD
307 f->kboard = initial_kboard;
308 #endif
309 f->namebuf = 0;
310 f->title = Qnil;
311 f->menu_bar_window = Qnil;
312 f->tool_bar_window = Qnil;
313 f->tool_bar_items = Qnil;
314 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
315 f->n_tool_bar_items = 0;
316 f->left_fringe_width = f->right_fringe_width = 0;
317 f->fringe_cols = 0;
318 f->scroll_bar_actual_width = 0;
319 f->border_width = 0;
320 f->internal_border_width = 0;
321 f->column_width = 1; /* !FRAME_WINDOW_P value */
322 f->line_height = 1; /* !FRAME_WINDOW_P value */
323 f->x_pixels_diff = f->y_pixels_diff = 0;
324 #ifdef HAVE_WINDOW_SYSTEM
325 f->want_fullscreen = FULLSCREEN_NONE;
326 #endif
327 f->size_hint_flags = 0;
328 f->win_gravity = 0;
330 root_window = make_window ();
331 if (mini_p)
333 mini_window = make_window ();
334 XWINDOW (root_window)->next = mini_window;
335 XWINDOW (mini_window)->prev = root_window;
336 XWINDOW (mini_window)->mini_p = Qt;
337 XWINDOW (mini_window)->frame = frame;
338 f->minibuffer_window = mini_window;
340 else
342 mini_window = Qnil;
343 XWINDOW (root_window)->next = Qnil;
344 f->minibuffer_window = Qnil;
347 XWINDOW (root_window)->frame = frame;
349 /* 10 is arbitrary,
350 just so that there is "something there."
351 Correct size will be set up later with change_frame_size. */
353 SET_FRAME_COLS (f, 10);
354 FRAME_LINES (f) = 10;
356 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
357 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
359 if (mini_p)
361 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
362 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
363 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
366 /* Choose a buffer for the frame's root window. */
368 Lisp_Object buf;
370 XWINDOW (root_window)->buffer = Qt;
371 buf = Fcurrent_buffer ();
372 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
373 a space), try to find another one. */
374 if (SREF (Fbuffer_name (buf), 0) == ' ')
375 buf = Fother_buffer (buf, Qnil, Qnil);
377 /* Use set_window_buffer, not Fset_window_buffer, and don't let
378 hooks be run by it. The reason is that the whole frame/window
379 arrangement is not yet fully intialized at this point. Windows
380 don't have the right size, glyph matrices aren't initialized
381 etc. Running Lisp functions at this point surely ends in a
382 SEGV. */
383 set_window_buffer (root_window, buf, 0, 0);
384 f->buffer_list = Fcons (buf, Qnil);
387 if (mini_p)
389 XWINDOW (mini_window)->buffer = Qt;
390 set_window_buffer (mini_window,
391 (NILP (Vminibuffer_list)
392 ? get_minibuffer (0)
393 : Fcar (Vminibuffer_list)),
394 0, 0);
397 f->root_window = root_window;
398 f->selected_window = root_window;
399 /* Make sure this window seems more recently used than
400 a newly-created, never-selected window. */
401 ++window_select_count;
402 XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
404 f->default_face_done_p = 0;
406 return f;
409 #ifdef HAVE_WINDOW_SYSTEM
410 /* Make a frame using a separate minibuffer window on another frame.
411 MINI_WINDOW is the minibuffer window to use. nil means use the
412 default (the global minibuffer). */
414 struct frame *
415 make_frame_without_minibuffer (mini_window, kb, display)
416 register Lisp_Object mini_window;
417 KBOARD *kb;
418 Lisp_Object display;
420 register struct frame *f;
421 struct gcpro gcpro1;
423 if (!NILP (mini_window))
424 CHECK_LIVE_WINDOW (mini_window);
426 #ifdef MULTI_KBOARD
427 if (!NILP (mini_window)
428 && XFRAME (XWINDOW (mini_window)->frame)->kboard != kb)
429 error ("Frame and minibuffer must be on the same display");
430 #endif
432 /* Make a frame containing just a root window. */
433 f = make_frame (0);
435 if (NILP (mini_window))
437 /* Use default-minibuffer-frame if possible. */
438 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
439 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
441 Lisp_Object frame_dummy;
443 XSETFRAME (frame_dummy, f);
444 GCPRO1 (frame_dummy);
445 /* If there's no minibuffer frame to use, create one. */
446 kb->Vdefault_minibuffer_frame =
447 call1 (intern ("make-initial-minibuffer-frame"), display);
448 UNGCPRO;
451 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
454 f->minibuffer_window = mini_window;
456 /* Make the chosen minibuffer window display the proper minibuffer,
457 unless it is already showing a minibuffer. */
458 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
459 Fset_window_buffer (mini_window,
460 (NILP (Vminibuffer_list)
461 ? get_minibuffer (0)
462 : Fcar (Vminibuffer_list)), Qnil);
463 return f;
466 /* Make a frame containing only a minibuffer window. */
468 struct frame *
469 make_minibuffer_frame ()
471 /* First make a frame containing just a root window, no minibuffer. */
473 register struct frame *f = make_frame (0);
474 register Lisp_Object mini_window;
475 register Lisp_Object frame;
477 XSETFRAME (frame, f);
479 f->auto_raise = 0;
480 f->auto_lower = 0;
481 f->no_split = 1;
482 f->wants_modeline = 0;
483 f->has_minibuffer = 1;
485 /* Now label the root window as also being the minibuffer.
486 Avoid infinite looping on the window chain by marking next pointer
487 as nil. */
489 mini_window = f->minibuffer_window = f->root_window;
490 XWINDOW (mini_window)->mini_p = Qt;
491 XWINDOW (mini_window)->next = Qnil;
492 XWINDOW (mini_window)->prev = Qnil;
493 XWINDOW (mini_window)->frame = frame;
495 /* Put the proper buffer in that window. */
497 Fset_window_buffer (mini_window,
498 (NILP (Vminibuffer_list)
499 ? get_minibuffer (0)
500 : Fcar (Vminibuffer_list)), Qnil);
501 return f;
503 #endif /* HAVE_WINDOW_SYSTEM */
505 /* Construct a frame that refers to a terminal. */
507 static int terminal_frame_count;
509 struct frame *
510 make_initial_frame (void)
512 struct frame *f;
513 struct display *display;
514 Lisp_Object frame;
516 #ifdef MULTI_KBOARD
517 /* Create the initial keyboard. */
518 if (!initial_kboard)
520 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
521 init_kboard (initial_kboard);
522 initial_kboard->next_kboard = all_kboards;
523 all_kboards = initial_kboard;
525 #endif
527 /* The first call must initialize Vframe_list. */
528 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
529 Vframe_list = Qnil;
531 display = init_initial_display ();
533 f = make_frame (1);
534 XSETFRAME (frame, f);
536 Vframe_list = Fcons (frame, Vframe_list);
538 terminal_frame_count = 1;
539 f->name = build_string ("F1");
541 f->visible = 1;
542 f->async_visible = 1;
544 f->output_method = display->type;
545 f->display = display;
546 f->display->reference_count++;
547 f->output_data.nothing = 0;
549 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
550 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
552 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
553 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
555 #ifdef MULTI_KBOARD
556 f->kboard = initial_kboard;
557 #endif
559 return f;
563 struct frame *
564 make_terminal_frame (struct display *display)
566 register struct frame *f;
567 Lisp_Object frame;
568 char name[20];
570 f = make_frame (1);
572 XSETFRAME (frame, f);
573 Vframe_list = Fcons (frame, Vframe_list);
575 terminal_frame_count++;
576 sprintf (name, "F%d", terminal_frame_count);
577 f->name = build_string (name);
579 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
580 f->async_visible = 1; /* Don't let visible be cleared later. */
581 #ifdef MSDOS
582 f->output_data.x = &the_only_x_display;
583 if (!inhibit_window_system
584 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
585 || XFRAME (selected_frame)->output_method == output_msdos_raw))
587 f->output_method = output_msdos_raw;
588 /* This initialization of foreground and background pixels is
589 only important for the initial frame created in temacs. If
590 we don't do that, we get black background and foreground in
591 the dumped Emacs because the_only_x_display is a static
592 variable, hence it is born all-zeroes, and zero is the code
593 for the black color. Other frames all inherit their pixels
594 from what's already in the_only_x_display. */
595 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
596 && f->output_data.x->background_pixel == 0
597 && f->output_data.x->foreground_pixel == 0)
599 f->output_data.x->background_pixel = FACE_TTY_DEFAULT_BG_COLOR;
600 f->output_data.x->foreground_pixel = FACE_TTY_DEFAULT_FG_COLOR;
603 else
604 f->output_method = output_termcap;
605 #else
606 #ifdef WINDOWSNT
607 f->output_method = output_termcap;
608 f->output_data.x = &tty_display; /* XXX ??? */
609 #else
610 #ifdef MAC_OS8
611 make_mac_terminal_frame (f);
612 #else
614 f->output_method = output_termcap;
615 f->display = display;
616 f->display->reference_count++;
617 create_tty_output (f);
619 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
620 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
622 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
623 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
625 #ifdef MULTI_KBOARD
626 f->kboard = FRAME_TTY (f)->kboard;
627 #endif
629 /* Set the top frame to the newly created frame. */
630 if (FRAME_TTY (f)->top_frame
631 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
632 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
634 FRAME_TTY (f)->top_frame = frame;
637 #ifdef CANNOT_DUMP
638 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
639 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
640 #endif
641 #endif /* MAC_OS8 */
642 #endif /* WINDOWSNT */
643 #endif /* MSDOS */
645 if (!noninteractive)
646 init_frame_faces (f);
648 return f;
651 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
652 1, 1, 0,
653 doc: /* Create an additional terminal frame, possibly on another terminal.
654 This function takes one argument, an alist specifying frame parameters.
656 You can create multiple frames on a single text-only terminal, but
657 only one of them (the selected terminal frame) is actually displayed.
659 In practice, generally you don't need to specify any parameters,
660 except when you want to create a new frame on another terminal.
661 In that case, the `tty' parameter specifies the device file to open,
662 and the `tty-type' parameter specifies the terminal type. Example:
664 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
666 Note that changing the size of one terminal frame automatically
667 affects all frames on the same terminal device. */)
668 (parms)
669 Lisp_Object parms;
671 struct frame *f;
672 struct display *d = NULL;
673 Lisp_Object frame, tem;
674 struct frame *sf = SELECTED_FRAME ();
676 #ifdef MSDOS
677 if (sf->output_method != output_msdos_raw
678 && sf->output_method != output_termcap)
679 abort ();
680 #else /* not MSDOS */
682 #ifdef MAC_OS
683 if (sf->output_method != output_mac)
684 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
685 #else
686 #if 0 /* This should work now! */
687 if (sf->output_method != output_termcap)
688 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
689 #endif
690 #endif
691 #endif /* not MSDOS */
694 Lisp_Object display_device;
696 display_device = Fassq (Qdisplay_id, parms);
697 if (!NILP (display_device))
699 display_device = XCDR (display_device);
700 CHECK_NUMBER (display_device);
701 d = get_display (XINT (display_device), 1);
705 if (!d)
707 Lisp_Object tty, tty_type;
708 char *name = 0, *type = 0;
710 tty = Fassq (Qtty, parms);
711 if (EQ (tty, Qnil))
712 tty = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
713 if (EQ (tty, Qnil) && FRAME_TERMCAP_P (XFRAME (selected_frame))
714 && FRAME_TTY (XFRAME (selected_frame))->name)
715 tty = build_string (FRAME_TTY (XFRAME (selected_frame))->name);
716 if (EQ (tty, Qnil))
717 tty = Fassq (Qtty, Vdefault_frame_alist);
718 if (! EQ (tty, Qnil) && ! STRINGP (tty))
719 tty = XCDR (tty);
720 if (EQ (tty, Qnil) || !STRINGP (tty))
721 tty = Qnil;
723 tty_type = Fassq (Qtty_type, parms);
724 if (EQ (tty_type, Qnil))
725 tty_type = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
726 if (EQ (tty_type, Qnil) && FRAME_TERMCAP_P (XFRAME (selected_frame))
727 && FRAME_TTY (XFRAME (selected_frame))->type)
728 tty_type = build_string (FRAME_TTY (XFRAME (selected_frame))->type);
729 if (EQ (tty_type, Qnil))
730 tty_type = Fassq (Qtty_type, Vdefault_frame_alist);
731 if (! EQ (tty_type, Qnil) && ! STRINGP (tty_type))
732 tty_type = XCDR (tty_type);
733 if (EQ (tty_type, Qnil) || !STRINGP (tty_type))
734 tty_type = Qnil;
736 if (! EQ (tty, Qnil))
738 name = (char *) alloca (SBYTES (tty) + 1);
739 strncpy (name, SDATA (tty), SBYTES (tty));
740 name[SBYTES (tty)] = 0;
743 if (! EQ (tty_type, Qnil))
745 type = (char *) alloca (SBYTES (tty_type) + 1);
746 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
747 type[SBYTES (tty_type)] = 0;
750 d = term_init (name, type, 0); /* Errors are not fatal. */
753 f = make_terminal_frame (d);
756 int width, height;
757 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
758 change_frame_size (f, height, width, 0, 0, 0);
761 adjust_glyphs (f);
762 calculate_costs (f);
763 XSETFRAME (frame, f);
764 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
765 Fmodify_frame_parameters (frame, parms);
766 Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qnil), Qnil));
768 /* Make the frame face alist be frame-specific, so that each
769 frame could change its face definitions independently. */
770 f->face_alist = Fcopy_alist (sf->face_alist);
771 /* Simple Fcopy_alist isn't enough, because we need the contents of
772 the vectors which are the CDRs of associations in face_alist to
773 be copied as well. */
774 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
775 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
776 return frame;
780 /* Perform the switch to frame FRAME.
782 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
783 FRAME1 as frame.
785 If TRACK is non-zero and the frame that currently has the focus
786 redirects its focus to the selected frame, redirect that focused
787 frame's focus to FRAME instead.
789 FOR_DELETION non-zero means that the selected frame is being
790 deleted, which includes the possibility that the frame's display
791 is dead. */
793 Lisp_Object
794 do_switch_frame (frame, track, for_deletion)
795 Lisp_Object frame;
796 int track, for_deletion;
798 struct frame *sf = SELECTED_FRAME ();
800 /* If FRAME is a switch-frame event, extract the frame we should
801 switch to. */
802 if (CONSP (frame)
803 && EQ (XCAR (frame), Qswitch_frame)
804 && CONSP (XCDR (frame)))
805 frame = XCAR (XCDR (frame));
807 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
808 a switch-frame event to arrive after a frame is no longer live,
809 especially when deleting the initial frame during startup. */
810 CHECK_FRAME (frame);
811 if (! FRAME_LIVE_P (XFRAME (frame)))
812 return Qnil;
814 if (sf == XFRAME (frame))
815 return frame;
817 /* This is too greedy; it causes inappropriate focus redirection
818 that's hard to get rid of. */
819 #if 0
820 /* If a frame's focus has been redirected toward the currently
821 selected frame, we should change the redirection to point to the
822 newly selected frame. This means that if the focus is redirected
823 from a minibufferless frame to a surrogate minibuffer frame, we
824 can use `other-window' to switch between all the frames using
825 that minibuffer frame, and the focus redirection will follow us
826 around. */
827 if (track)
829 Lisp_Object tail;
831 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
833 Lisp_Object focus;
835 if (!FRAMEP (XCAR (tail)))
836 abort ();
838 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
840 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
841 Fredirect_frame_focus (XCAR (tail), frame);
844 #else /* ! 0 */
845 /* Instead, apply it only to the frame we're pointing to. */
846 #ifdef HAVE_WINDOW_SYSTEM
847 if (track && FRAME_WINDOW_P (XFRAME (frame)))
849 Lisp_Object focus, xfocus;
851 xfocus = x_get_focus_frame (XFRAME (frame));
852 if (FRAMEP (xfocus))
854 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
855 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
856 Fredirect_frame_focus (xfocus, frame);
859 #endif /* HAVE_X_WINDOWS */
860 #endif /* ! 0 */
862 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
863 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
865 if (FRAME_TERMCAP_P (XFRAME (selected_frame))
866 && FRAME_TERMCAP_P (XFRAME (frame))
867 && FRAME_TTY (XFRAME (selected_frame)) == FRAME_TTY (XFRAME (frame)))
869 XFRAME (selected_frame)->async_visible = 2; /* obscured */
870 XFRAME (frame)->async_visible = 1;
871 FRAME_TTY (XFRAME (frame))->top_frame = frame;
874 selected_frame = frame;
875 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
876 last_nonminibuf_frame = XFRAME (selected_frame);
878 Fselect_window (XFRAME (frame)->selected_window, Qnil);
880 #ifndef WINDOWSNT
881 /* Make sure to switch the tty color mode to that of the newly
882 selected frame. */
883 sf = SELECTED_FRAME ();
884 if (FRAME_TERMCAP_P (sf))
886 Lisp_Object color_mode_spec, color_mode;
888 color_mode_spec = assq_no_quit (Qtty_color_mode, sf->param_alist);
889 if (CONSP (color_mode_spec))
890 color_mode = XCDR (color_mode_spec);
891 else
892 color_mode = make_number (0);
893 set_tty_color_mode (sf, color_mode);
895 #endif /* !WINDOWSNT */
897 /* We want to make sure that the next event generates a frame-switch
898 event to the appropriate frame. This seems kludgy to me, but
899 before you take it out, make sure that evaluating something like
900 (select-window (frame-root-window (new-frame))) doesn't end up
901 with your typing being interpreted in the new frame instead of
902 the one you're actually typing in. */
903 internal_last_event_frame = Qnil;
905 return frame;
908 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 1, "e",
909 doc: /* Select the frame FRAME.
910 Subsequent editing commands apply to its selected window.
911 The selection of FRAME lasts until the next time the user does
912 something to select a different frame, or until the next time this
913 function is called. If you are using a window system, the previously
914 selected frame may be restored as the selected frame after return to
915 the command loop, because it still may have the window system's input
916 focus. On a text-only terminal, the next redisplay will display FRAME.
918 This function returns FRAME, or nil if FRAME has been deleted. */)
919 (frame)
920 Lisp_Object frame;
922 return do_switch_frame (frame, 1, 0);
926 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
927 doc: /* Handle a switch-frame event EVENT.
928 Switch-frame events are usually bound to this function.
929 A switch-frame event tells Emacs that the window manager has requested
930 that the user's events be directed to the frame mentioned in the event.
931 This function selects the selected window of the frame of EVENT.
933 If EVENT is frame object, handle it as if it were a switch-frame event
934 to that frame. */)
935 (event)
936 Lisp_Object event;
938 /* Preserve prefix arg that the command loop just cleared. */
939 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
940 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
941 return do_switch_frame (event, 0, 0);
944 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
945 doc: /* Return the frame that is now selected. */)
948 return selected_frame;
951 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
952 doc: /* Return the frame object that window WINDOW is on. */)
953 (window)
954 Lisp_Object window;
956 CHECK_LIVE_WINDOW (window);
957 return XWINDOW (window)->frame;
960 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
961 doc: /* Returns the topmost, leftmost window of FRAME.
962 If omitted, FRAME defaults to the currently selected frame. */)
963 (frame)
964 Lisp_Object frame;
966 Lisp_Object w;
968 if (NILP (frame))
969 w = SELECTED_FRAME ()->root_window;
970 else
972 CHECK_LIVE_FRAME (frame);
973 w = XFRAME (frame)->root_window;
975 while (NILP (XWINDOW (w)->buffer))
977 if (! NILP (XWINDOW (w)->hchild))
978 w = XWINDOW (w)->hchild;
979 else if (! NILP (XWINDOW (w)->vchild))
980 w = XWINDOW (w)->vchild;
981 else
982 abort ();
984 return w;
987 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
988 Sactive_minibuffer_window, 0, 0, 0,
989 doc: /* Return the currently active minibuffer window, or nil if none. */)
992 return minibuf_level ? minibuf_window : Qnil;
995 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
996 doc: /* Returns the root-window of FRAME.
997 If omitted, FRAME defaults to the currently selected frame. */)
998 (frame)
999 Lisp_Object frame;
1001 Lisp_Object window;
1003 if (NILP (frame))
1004 window = SELECTED_FRAME ()->root_window;
1005 else
1007 CHECK_LIVE_FRAME (frame);
1008 window = XFRAME (frame)->root_window;
1011 return window;
1014 DEFUN ("frame-selected-window", Fframe_selected_window,
1015 Sframe_selected_window, 0, 1, 0,
1016 doc: /* Return the selected window of frame object FRAME.
1017 If omitted, FRAME defaults to the currently selected frame. */)
1018 (frame)
1019 Lisp_Object frame;
1021 Lisp_Object window;
1023 if (NILP (frame))
1024 window = SELECTED_FRAME ()->selected_window;
1025 else
1027 CHECK_LIVE_FRAME (frame);
1028 window = XFRAME (frame)->selected_window;
1031 return window;
1034 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
1035 Sset_frame_selected_window, 2, 2, 0,
1036 doc: /* Set the selected window of frame object FRAME to WINDOW.
1037 Return WINDOW.
1038 If FRAME is nil, the selected frame is used.
1039 If FRAME is the selected frame, this makes WINDOW the selected window. */)
1040 (frame, window)
1041 Lisp_Object frame, window;
1043 if (NILP (frame))
1044 frame = selected_frame;
1046 CHECK_LIVE_FRAME (frame);
1047 CHECK_LIVE_WINDOW (window);
1049 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
1050 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
1052 if (EQ (frame, selected_frame))
1053 return Fselect_window (window, Qnil);
1055 return XFRAME (frame)->selected_window = window;
1059 DEFUN ("frame-display", Fframe_display, Sframe_display, 0, 1, 0,
1060 doc: /* Return the display device that FRAME is displayed on.
1061 If FRAME is nil, the selected frame is used.
1063 The display device is represented by its integer identifier. */)
1064 (frame)
1065 Lisp_Object frame;
1067 struct display *d;
1069 if (NILP (frame))
1070 frame = selected_frame;
1072 CHECK_LIVE_FRAME (frame);
1074 d = get_display (frame, 0);
1076 if (!d)
1077 return Qnil;
1078 else
1079 return make_number (d->id);
1083 DEFUN ("frame-list", Fframe_list, Sframe_list,
1084 0, 0, 0,
1085 doc: /* Return a list of all frames. */)
1088 Lisp_Object frames;
1089 frames = Fcopy_sequence (Vframe_list);
1090 #ifdef HAVE_WINDOW_SYSTEM
1091 if (FRAMEP (tip_frame))
1092 frames = Fdelq (tip_frame, frames);
1093 #endif
1094 return frames;
1097 /* Return the next frame in the frame list after FRAME.
1098 If MINIBUF is nil, exclude minibuffer-only frames.
1099 If MINIBUF is a window, include only its own frame
1100 and any frame now using that window as the minibuffer.
1101 If MINIBUF is `visible', include all visible frames.
1102 If MINIBUF is 0, include all visible and iconified frames.
1103 Otherwise, include all frames. */
1105 Lisp_Object
1106 next_frame (frame, minibuf)
1107 Lisp_Object frame;
1108 Lisp_Object minibuf;
1110 Lisp_Object tail;
1111 int passed = 0;
1113 /* There must always be at least one frame in Vframe_list. */
1114 if (! CONSP (Vframe_list))
1115 abort ();
1117 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
1118 forever. Forestall that. */
1119 CHECK_LIVE_FRAME (frame);
1121 while (1)
1122 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1124 Lisp_Object f;
1126 f = XCAR (tail);
1128 if (passed
1129 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1130 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1131 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1132 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
1134 /* Decide whether this frame is eligible to be returned. */
1136 /* If we've looped all the way around without finding any
1137 eligible frames, return the original frame. */
1138 if (EQ (f, frame))
1139 return f;
1141 /* Let minibuf decide if this frame is acceptable. */
1142 if (NILP (minibuf))
1144 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1145 return f;
1147 else if (EQ (minibuf, Qvisible))
1149 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1150 if (FRAME_VISIBLE_P (XFRAME (f)))
1151 return f;
1153 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1155 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1156 if (FRAME_VISIBLE_P (XFRAME (f))
1157 || FRAME_ICONIFIED_P (XFRAME (f)))
1158 return f;
1160 else if (WINDOWP (minibuf))
1162 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1163 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1164 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1165 FRAME_FOCUS_FRAME (XFRAME (f))))
1166 return f;
1168 else
1169 return f;
1172 if (EQ (frame, f))
1173 passed++;
1177 /* Return the previous frame in the frame list before FRAME.
1178 If MINIBUF is nil, exclude minibuffer-only frames.
1179 If MINIBUF is a window, include only its own frame
1180 and any frame now using that window as the minibuffer.
1181 If MINIBUF is `visible', include all visible frames.
1182 If MINIBUF is 0, include all visible and iconified frames.
1183 Otherwise, include all frames. */
1185 Lisp_Object
1186 prev_frame (frame, minibuf)
1187 Lisp_Object frame;
1188 Lisp_Object minibuf;
1190 Lisp_Object tail;
1191 Lisp_Object prev;
1193 /* There must always be at least one frame in Vframe_list. */
1194 if (! CONSP (Vframe_list))
1195 abort ();
1197 prev = Qnil;
1198 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1200 Lisp_Object f;
1202 f = XCAR (tail);
1203 if (!FRAMEP (f))
1204 abort ();
1206 if (EQ (frame, f) && !NILP (prev))
1207 return prev;
1209 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1210 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1211 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1212 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1214 /* Decide whether this frame is eligible to be returned,
1215 according to minibuf. */
1216 if (NILP (minibuf))
1218 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1219 prev = f;
1221 else if (WINDOWP (minibuf))
1223 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1224 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1225 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1226 FRAME_FOCUS_FRAME (XFRAME (f))))
1227 prev = f;
1229 else if (EQ (minibuf, Qvisible))
1231 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1232 if (FRAME_VISIBLE_P (XFRAME (f)))
1233 prev = f;
1235 else if (XFASTINT (minibuf) == 0)
1237 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1238 if (FRAME_VISIBLE_P (XFRAME (f))
1239 || FRAME_ICONIFIED_P (XFRAME (f)))
1240 prev = f;
1242 else
1243 prev = f;
1247 /* We've scanned the entire list. */
1248 if (NILP (prev))
1249 /* We went through the whole frame list without finding a single
1250 acceptable frame. Return the original frame. */
1251 return frame;
1252 else
1253 /* There were no acceptable frames in the list before FRAME; otherwise,
1254 we would have returned directly from the loop. Since PREV is the last
1255 acceptable frame in the list, return it. */
1256 return prev;
1260 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1261 doc: /* Return the next frame in the frame list after FRAME.
1262 It considers only frames on the same terminal as FRAME.
1263 By default, skip minibuffer-only frames.
1264 If omitted, FRAME defaults to the selected frame.
1265 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1266 If MINIFRAME is a window, include only its own frame
1267 and any frame now using that window as the minibuffer.
1268 If MINIFRAME is `visible', include all visible frames.
1269 If MINIFRAME is 0, include all visible and iconified frames.
1270 Otherwise, include all frames. */)
1271 (frame, miniframe)
1272 Lisp_Object frame, miniframe;
1274 if (NILP (frame))
1275 frame = selected_frame;
1277 CHECK_LIVE_FRAME (frame);
1278 return next_frame (frame, miniframe);
1281 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1282 doc: /* Return the previous frame in the frame list before FRAME.
1283 It considers only frames on the same terminal as FRAME.
1284 By default, skip minibuffer-only frames.
1285 If omitted, FRAME defaults to the selected frame.
1286 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1287 If MINIFRAME is a window, include only its own frame
1288 and any frame now using that window as the minibuffer.
1289 If MINIFRAME is `visible', include all visible frames.
1290 If MINIFRAME is 0, include all visible and iconified frames.
1291 Otherwise, include all frames. */)
1292 (frame, miniframe)
1293 Lisp_Object frame, miniframe;
1295 if (NILP (frame))
1296 frame = selected_frame;
1297 CHECK_LIVE_FRAME (frame);
1298 return prev_frame (frame, miniframe);
1301 /* Return 1 if it is ok to delete frame F;
1302 0 if all frames aside from F are invisible.
1303 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1306 other_visible_frames (f)
1307 FRAME_PTR f;
1309 /* We know the selected frame is visible,
1310 so if F is some other frame, it can't be the sole visible one. */
1311 if (f == SELECTED_FRAME ())
1313 Lisp_Object frames;
1314 int count = 0;
1316 for (frames = Vframe_list;
1317 CONSP (frames);
1318 frames = XCDR (frames))
1320 Lisp_Object this;
1322 this = XCAR (frames);
1323 /* Verify that the frame's window still exists
1324 and we can still talk to it. And note any recent change
1325 in visibility. */
1326 #ifdef HAVE_WINDOW_SYSTEM
1327 if (FRAME_WINDOW_P (XFRAME (this)))
1329 x_sync (XFRAME (this));
1330 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1332 #endif
1334 if (FRAME_VISIBLE_P (XFRAME (this))
1335 || FRAME_ICONIFIED_P (XFRAME (this))
1336 /* Allow deleting the terminal frame when at least
1337 one X frame exists! */
1338 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1339 count++;
1341 return count > 1;
1343 return 1;
1346 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1347 doc: /* Delete FRAME, permanently eliminating it from use.
1348 If omitted, FRAME defaults to the selected frame.
1349 A frame may not be deleted if its minibuffer is used by other frames.
1350 Normally, you may not delete a frame if all other frames are invisible,
1351 but if the second optional argument FORCE is non-nil, you may do so.
1353 This function runs `delete-frame-functions' before actually deleting the
1354 frame, unless the frame is a tooltip.
1355 The functions are run with one arg, the frame to be deleted. */)
1356 (frame, force)
1357 Lisp_Object frame, force;
1359 struct frame *f;
1360 struct frame *sf = SELECTED_FRAME ();
1361 int minibuffer_selected;
1363 if (EQ (frame, Qnil))
1365 f = sf;
1366 XSETFRAME (frame, f);
1368 else
1370 CHECK_FRAME (frame);
1371 f = XFRAME (frame);
1374 if (! FRAME_LIVE_P (f))
1375 return Qnil;
1377 if (NILP (force) && !other_visible_frames (f)
1378 #ifdef MAC_OS8
1379 /* Terminal frame deleted before any other visible frames are
1380 created. */
1381 && strcmp (SDATA (f->name), "F1") != 0
1382 #endif
1384 error ("Attempt to delete the sole visible or iconified frame");
1386 #if 0
1387 /* This is a nice idea, but x_connection_closed needs to be able
1388 to delete the last frame, if it is gone. */
1389 if (NILP (XCDR (Vframe_list)))
1390 error ("Attempt to delete the only frame");
1391 #endif
1393 /* Does this frame have a minibuffer, and is it the surrogate
1394 minibuffer for any other frame? */
1395 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1397 Lisp_Object frames;
1399 for (frames = Vframe_list;
1400 CONSP (frames);
1401 frames = XCDR (frames))
1403 Lisp_Object this;
1404 this = XCAR (frames);
1406 if (! EQ (this, frame)
1407 && EQ (frame,
1408 WINDOW_FRAME (XWINDOW
1409 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1410 error ("Attempt to delete a surrogate minibuffer frame");
1414 /* Run `delete-frame-functions' unless frame is a tooltip. */
1415 if (!NILP (Vrun_hooks)
1416 && NILP (Fframe_parameter (frame, intern ("tooltip"))))
1418 Lisp_Object args[2];
1419 args[0] = intern ("delete-frame-functions");
1420 args[1] = frame;
1421 Frun_hook_with_args (2, args);
1424 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1425 if (! FRAME_LIVE_P (f))
1426 return Qnil;
1428 minibuffer_selected = EQ (minibuf_window, selected_window);
1430 /* Don't let the frame remain selected. */
1431 if (f == sf)
1433 Lisp_Object tail, frame1;
1435 /* Look for another visible frame on the same terminal. */
1436 frame1 = next_frame (frame, Qvisible);
1438 /* If there is none, find *some* other frame. */
1439 if (NILP (frame1) || EQ (frame1, frame))
1441 FOR_EACH_FRAME (tail, frame1)
1443 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1444 break;
1448 do_switch_frame (frame1, 0, 1);
1449 sf = SELECTED_FRAME ();
1452 /* Don't allow minibuf_window to remain on a deleted frame. */
1453 if (EQ (f->minibuffer_window, minibuf_window))
1455 Fset_window_buffer (sf->minibuffer_window,
1456 XWINDOW (minibuf_window)->buffer, Qnil);
1457 minibuf_window = sf->minibuffer_window;
1459 /* If the dying minibuffer window was selected,
1460 select the new one. */
1461 if (minibuffer_selected)
1462 Fselect_window (minibuf_window, Qnil);
1465 /* Don't let echo_area_window to remain on a deleted frame. */
1466 if (EQ (f->minibuffer_window, echo_area_window))
1467 echo_area_window = sf->minibuffer_window;
1469 /* Clear any X selections for this frame. */
1470 #ifdef HAVE_X_WINDOWS
1471 if (FRAME_X_P (f))
1472 x_clear_frame_selections (f);
1473 #endif
1474 #ifdef MAC_OS
1475 if (FRAME_MAC_P (f))
1476 x_clear_frame_selections (f);
1477 #endif
1479 /* Free glyphs.
1480 This function must be called before the window tree of the
1481 frame is deleted because windows contain dynamically allocated
1482 memory. */
1483 free_glyphs (f);
1485 /* Mark all the windows that used to be on FRAME as deleted, and then
1486 remove the reference to them. */
1487 delete_all_subwindows (XWINDOW (f->root_window));
1488 f->root_window = Qnil;
1490 Vframe_list = Fdelq (frame, Vframe_list);
1491 FRAME_SET_VISIBLE (f, 0);
1493 if (f->namebuf)
1494 xfree (f->namebuf);
1495 if (f->decode_mode_spec_buffer)
1496 xfree (f->decode_mode_spec_buffer);
1497 if (FRAME_INSERT_COST (f))
1498 xfree (FRAME_INSERT_COST (f));
1499 if (FRAME_DELETEN_COST (f))
1500 xfree (FRAME_DELETEN_COST (f));
1501 if (FRAME_INSERTN_COST (f))
1502 xfree (FRAME_INSERTN_COST (f));
1503 if (FRAME_DELETE_COST (f))
1504 xfree (FRAME_DELETE_COST (f));
1505 if (FRAME_MESSAGE_BUF (f))
1506 xfree (FRAME_MESSAGE_BUF (f));
1508 /* Since some events are handled at the interrupt level, we may get
1509 an event for f at any time; if we zero out the frame's display
1510 now, then we may trip up the event-handling code. Instead, we'll
1511 promise that the display of the frame must be valid until we have
1512 called the window-system-dependent frame destruction routine. */
1514 if (FRAME_DISPLAY (f)->delete_frame_hook)
1515 (*FRAME_DISPLAY (f)->delete_frame_hook) (f);
1518 struct display *display = FRAME_DISPLAY (f);
1520 f->output_data.nothing = 0;
1521 f->display = 0; /* Now the frame is dead. */
1523 /* If needed, delete the device that this frame was on.
1524 (This must be done after the frame is killed.) */
1525 display->reference_count--;
1526 if (display->reference_count == 0)
1528 if (display->delete_display_hook)
1529 (*display->delete_display_hook) (display);
1530 else
1531 delete_display (display);
1535 /* If we've deleted the last_nonminibuf_frame, then try to find
1536 another one. */
1537 if (f == last_nonminibuf_frame)
1539 Lisp_Object frames;
1541 last_nonminibuf_frame = 0;
1543 for (frames = Vframe_list;
1544 CONSP (frames);
1545 frames = XCDR (frames))
1547 f = XFRAME (XCAR (frames));
1548 if (!FRAME_MINIBUF_ONLY_P (f))
1550 last_nonminibuf_frame = f;
1551 break;
1556 /* If there's no other frame on the same kboard, get out of
1557 single-kboard state if we're in it for this kboard. */
1559 Lisp_Object frames;
1560 /* Some frame we found on the same kboard, or nil if there are none. */
1561 Lisp_Object frame_on_same_kboard;
1563 frame_on_same_kboard = Qnil;
1565 for (frames = Vframe_list;
1566 CONSP (frames);
1567 frames = XCDR (frames))
1569 Lisp_Object this;
1570 struct frame *f1;
1572 this = XCAR (frames);
1573 if (!FRAMEP (this))
1574 abort ();
1575 f1 = XFRAME (this);
1577 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1))
1578 frame_on_same_kboard = this;
1581 if (NILP (frame_on_same_kboard))
1582 not_single_kboard_state (FRAME_KBOARD (f));
1586 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1587 find another one. Prefer minibuffer-only frames, but also notice
1588 frames with other windows. */
1589 if (EQ (frame, FRAME_KBOARD (f)->Vdefault_minibuffer_frame))
1591 Lisp_Object frames;
1593 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1594 Lisp_Object frame_with_minibuf;
1595 /* Some frame we found on the same kboard, or nil if there are none. */
1596 Lisp_Object frame_on_same_kboard;
1598 frame_on_same_kboard = Qnil;
1599 frame_with_minibuf = Qnil;
1601 for (frames = Vframe_list;
1602 CONSP (frames);
1603 frames = XCDR (frames))
1605 Lisp_Object this;
1606 struct frame *f1;
1608 this = XCAR (frames);
1609 if (!FRAMEP (this))
1610 abort ();
1611 f1 = XFRAME (this);
1613 /* Consider only frames on the same kboard
1614 and only those with minibuffers. */
1615 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)
1616 && FRAME_HAS_MINIBUF_P (f1))
1618 frame_with_minibuf = this;
1619 if (FRAME_MINIBUF_ONLY_P (f1))
1620 break;
1623 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1))
1624 frame_on_same_kboard = this;
1627 if (!NILP (frame_on_same_kboard))
1629 /* We know that there must be some frame with a minibuffer out
1630 there. If this were not true, all of the frames present
1631 would have to be minibufferless, which implies that at some
1632 point their minibuffer frames must have been deleted, but
1633 that is prohibited at the top; you can't delete surrogate
1634 minibuffer frames. */
1635 if (NILP (frame_with_minibuf))
1636 abort ();
1638 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = frame_with_minibuf;
1640 else
1641 /* No frames left on this kboard--say no minibuffer either. */
1642 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = Qnil;
1645 /* Cause frame titles to update--necessary if we now have just one frame. */
1646 update_mode_lines = 1;
1648 return Qnil;
1651 /* Return mouse position in character cell units. */
1653 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1654 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1655 The position is given in character cells, where (0, 0) is the
1656 upper-left corner.
1657 If Emacs is running on a mouseless terminal or hasn't been programmed
1658 to read the mouse position, it returns the selected frame for FRAME
1659 and nil for X and Y.
1660 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1661 passing the normal return value to that function as an argument,
1662 and returns whatever that function returns. */)
1665 FRAME_PTR f;
1666 Lisp_Object lispy_dummy;
1667 enum scroll_bar_part party_dummy;
1668 Lisp_Object x, y, retval;
1669 int col, row;
1670 unsigned long long_dummy;
1671 struct gcpro gcpro1;
1673 f = SELECTED_FRAME ();
1674 x = y = Qnil;
1676 #ifdef HAVE_MOUSE
1677 /* It's okay for the hook to refrain from storing anything. */
1678 if (FRAME_DISPLAY (f)->mouse_position_hook)
1679 (*FRAME_DISPLAY (f)->mouse_position_hook) (&f, -1,
1680 &lispy_dummy, &party_dummy,
1681 &x, &y,
1682 &long_dummy);
1683 if (! NILP (x))
1685 col = XINT (x);
1686 row = XINT (y);
1687 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1688 XSETINT (x, col);
1689 XSETINT (y, row);
1691 #endif
1692 XSETFRAME (lispy_dummy, f);
1693 retval = Fcons (lispy_dummy, Fcons (x, y));
1694 GCPRO1 (retval);
1695 if (!NILP (Vmouse_position_function))
1696 retval = call1 (Vmouse_position_function, retval);
1697 RETURN_UNGCPRO (retval);
1700 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1701 Smouse_pixel_position, 0, 0, 0,
1702 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1703 The position is given in pixel units, where (0, 0) is the
1704 upper-left corner.
1705 If Emacs is running on a mouseless terminal or hasn't been programmed
1706 to read the mouse position, it returns the selected frame for FRAME
1707 and nil for X and Y. */)
1710 FRAME_PTR f;
1711 Lisp_Object lispy_dummy;
1712 enum scroll_bar_part party_dummy;
1713 Lisp_Object x, y;
1714 unsigned long long_dummy;
1716 f = SELECTED_FRAME ();
1717 x = y = Qnil;
1719 #ifdef HAVE_MOUSE
1720 /* It's okay for the hook to refrain from storing anything. */
1721 if (FRAME_DISPLAY (f)->mouse_position_hook)
1722 (*FRAME_DISPLAY (f)->mouse_position_hook) (&f, -1,
1723 &lispy_dummy, &party_dummy,
1724 &x, &y,
1725 &long_dummy);
1726 #endif
1727 XSETFRAME (lispy_dummy, f);
1728 return Fcons (lispy_dummy, Fcons (x, y));
1731 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1732 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1733 Coordinates are relative to the frame, not a window,
1734 so the coordinates of the top left character in the frame
1735 may be nonzero due to left-hand scroll bars or the menu bar.
1737 This function is a no-op for an X frame that is not visible.
1738 If you have just created a frame, you must wait for it to become visible
1739 before calling this function on it, like this.
1740 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1741 (frame, x, y)
1742 Lisp_Object frame, x, y;
1744 CHECK_LIVE_FRAME (frame);
1745 CHECK_NUMBER (x);
1746 CHECK_NUMBER (y);
1748 /* I think this should be done with a hook. */
1749 #ifdef HAVE_WINDOW_SYSTEM
1750 if (FRAME_WINDOW_P (XFRAME (frame)))
1751 /* Warping the mouse will cause enternotify and focus events. */
1752 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1753 #else
1754 #if defined (MSDOS) && defined (HAVE_MOUSE)
1755 if (FRAME_MSDOS_P (XFRAME (frame)))
1757 Fselect_frame (frame);
1758 mouse_moveto (XINT (x), XINT (y));
1760 #endif
1761 #endif
1763 return Qnil;
1766 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1767 Sset_mouse_pixel_position, 3, 3, 0,
1768 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1769 Note, this is a no-op for an X frame that is not visible.
1770 If you have just created a frame, you must wait for it to become visible
1771 before calling this function on it, like this.
1772 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1773 (frame, x, y)
1774 Lisp_Object frame, x, y;
1776 CHECK_LIVE_FRAME (frame);
1777 CHECK_NUMBER (x);
1778 CHECK_NUMBER (y);
1780 /* I think this should be done with a hook. */
1781 #ifdef HAVE_WINDOW_SYSTEM
1782 if (FRAME_WINDOW_P (XFRAME (frame)))
1783 /* Warping the mouse will cause enternotify and focus events. */
1784 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1785 #else
1786 #if defined (MSDOS) && defined (HAVE_MOUSE)
1787 if (FRAME_MSDOS_P (XFRAME (frame)))
1789 Fselect_frame (frame);
1790 mouse_moveto (XINT (x), XINT (y));
1792 #endif
1793 #endif
1795 return Qnil;
1798 static void make_frame_visible_1 P_ ((Lisp_Object));
1800 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1801 0, 1, "",
1802 doc: /* Make the frame FRAME visible (assuming it is an X window).
1803 If omitted, FRAME defaults to the currently selected frame. */)
1804 (frame)
1805 Lisp_Object frame;
1807 if (NILP (frame))
1808 frame = selected_frame;
1810 CHECK_LIVE_FRAME (frame);
1812 /* I think this should be done with a hook. */
1813 #ifdef HAVE_WINDOW_SYSTEM
1814 if (FRAME_WINDOW_P (XFRAME (frame)))
1816 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1817 x_make_frame_visible (XFRAME (frame));
1819 #endif
1821 make_frame_visible_1 (XFRAME (frame)->root_window);
1823 /* Make menu bar update for the Buffers and Frames menus. */
1824 windows_or_buffers_changed++;
1826 return frame;
1829 /* Update the display_time slot of the buffers shown in WINDOW
1830 and all its descendents. */
1832 static void
1833 make_frame_visible_1 (window)
1834 Lisp_Object window;
1836 struct window *w;
1838 for (;!NILP (window); window = w->next)
1840 w = XWINDOW (window);
1842 if (!NILP (w->buffer))
1843 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1845 if (!NILP (w->vchild))
1846 make_frame_visible_1 (w->vchild);
1847 if (!NILP (w->hchild))
1848 make_frame_visible_1 (w->hchild);
1852 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1853 0, 2, "",
1854 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1855 If omitted, FRAME defaults to the currently selected frame.
1856 Normally you may not make FRAME invisible if all other frames are invisible,
1857 but if the second optional argument FORCE is non-nil, you may do so. */)
1858 (frame, force)
1859 Lisp_Object frame, force;
1861 if (NILP (frame))
1862 frame = selected_frame;
1864 CHECK_LIVE_FRAME (frame);
1866 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1867 error ("Attempt to make invisible the sole visible or iconified frame");
1869 #if 0 /* This isn't logically necessary, and it can do GC. */
1870 /* Don't let the frame remain selected. */
1871 if (EQ (frame, selected_frame))
1872 do_switch_frame (next_frame (frame, Qt), 0, 0)
1873 #endif
1875 /* Don't allow minibuf_window to remain on a deleted frame. */
1876 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1878 struct frame *sf = XFRAME (selected_frame);
1879 Fset_window_buffer (sf->minibuffer_window,
1880 XWINDOW (minibuf_window)->buffer, Qnil);
1881 minibuf_window = sf->minibuffer_window;
1884 /* I think this should be done with a hook. */
1885 #ifdef HAVE_WINDOW_SYSTEM
1886 if (FRAME_WINDOW_P (XFRAME (frame)))
1887 x_make_frame_invisible (XFRAME (frame));
1888 #endif
1890 /* Make menu bar update for the Buffers and Frames menus. */
1891 windows_or_buffers_changed++;
1893 return Qnil;
1896 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1897 0, 1, "",
1898 doc: /* Make the frame FRAME into an icon.
1899 If omitted, FRAME defaults to the currently selected frame. */)
1900 (frame)
1901 Lisp_Object frame;
1903 if (NILP (frame))
1904 frame = selected_frame;
1906 CHECK_LIVE_FRAME (frame);
1908 #if 0 /* This isn't logically necessary, and it can do GC. */
1909 /* Don't let the frame remain selected. */
1910 if (EQ (frame, selected_frame))
1911 Fhandle_switch_frame (next_frame (frame, Qt));
1912 #endif
1914 /* Don't allow minibuf_window to remain on a deleted frame. */
1915 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1917 struct frame *sf = XFRAME (selected_frame);
1918 Fset_window_buffer (sf->minibuffer_window,
1919 XWINDOW (minibuf_window)->buffer, Qnil);
1920 minibuf_window = sf->minibuffer_window;
1923 /* I think this should be done with a hook. */
1924 #ifdef HAVE_WINDOW_SYSTEM
1925 if (FRAME_WINDOW_P (XFRAME (frame)))
1926 x_iconify_frame (XFRAME (frame));
1927 #endif
1929 /* Make menu bar update for the Buffers and Frames menus. */
1930 windows_or_buffers_changed++;
1932 return Qnil;
1935 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1936 1, 1, 0,
1937 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1938 A frame that is not \"visible\" is not updated and, if it works through
1939 a window system, it may not show at all.
1940 Return the symbol `icon' if frame is visible only as an icon.
1942 On a text-only terminal, all frames are considered visible, whether
1943 they are currently being displayed or not, and this function returns t
1944 for all frames. */)
1945 (frame)
1946 Lisp_Object frame;
1948 CHECK_LIVE_FRAME (frame);
1950 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1952 if (FRAME_VISIBLE_P (XFRAME (frame)))
1953 return Qt;
1954 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1955 return Qicon;
1956 return Qnil;
1959 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1960 0, 0, 0,
1961 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1964 Lisp_Object tail, frame;
1965 struct frame *f;
1966 Lisp_Object value;
1968 value = Qnil;
1969 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1971 frame = XCAR (tail);
1972 if (!FRAMEP (frame))
1973 continue;
1974 f = XFRAME (frame);
1975 if (FRAME_VISIBLE_P (f))
1976 value = Fcons (frame, value);
1978 return value;
1982 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1983 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1984 If FRAME is invisible or iconified, make it visible.
1985 If you don't specify a frame, the selected frame is used.
1986 If Emacs is displaying on an ordinary terminal or some other device which
1987 doesn't support multiple overlapping frames, this function does nothing. */)
1988 (frame)
1989 Lisp_Object frame;
1991 struct frame *f;
1992 if (NILP (frame))
1993 frame = selected_frame;
1995 CHECK_LIVE_FRAME (frame);
1997 f = XFRAME (frame);
1999 /* Do like the documentation says. */
2000 Fmake_frame_visible (frame);
2002 if (FRAME_DISPLAY (f)->frame_raise_lower_hook)
2003 (*FRAME_DISPLAY (f)->frame_raise_lower_hook) (f, 1);
2005 return Qnil;
2008 /* Should we have a corresponding function called Flower_Power? */
2009 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2010 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2011 If you don't specify a frame, the selected frame is used.
2012 If Emacs is displaying on an ordinary terminal or some other device which
2013 doesn't support multiple overlapping frames, this function does nothing. */)
2014 (frame)
2015 Lisp_Object frame;
2017 struct frame *f;
2019 if (NILP (frame))
2020 frame = selected_frame;
2022 CHECK_LIVE_FRAME (frame);
2024 f = XFRAME (frame);
2026 if (FRAME_DISPLAY (f)->frame_raise_lower_hook)
2027 (*FRAME_DISPLAY (f)->frame_raise_lower_hook) (f, 0);
2029 return Qnil;
2033 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2034 1, 2, 0,
2035 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2036 In other words, switch-frame events caused by events in FRAME will
2037 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2038 FOCUS-FRAME after reading an event typed at FRAME.
2040 If FOCUS-FRAME is omitted or nil, any existing redirection is
2041 cancelled, and the frame again receives its own keystrokes.
2043 Focus redirection is useful for temporarily redirecting keystrokes to
2044 a surrogate minibuffer frame when a frame doesn't have its own
2045 minibuffer window.
2047 A frame's focus redirection can be changed by select-frame. If frame
2048 FOO is selected, and then a different frame BAR is selected, any
2049 frames redirecting their focus to FOO are shifted to redirect their
2050 focus to BAR. This allows focus redirection to work properly when the
2051 user switches from one frame to another using `select-window'.
2053 This means that a frame whose focus is redirected to itself is treated
2054 differently from a frame whose focus is redirected to nil; the former
2055 is affected by select-frame, while the latter is not.
2057 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2058 (frame, focus_frame)
2059 Lisp_Object frame, focus_frame;
2061 struct frame *f;
2063 /* Note that we don't check for a live frame here. It's reasonable
2064 to redirect the focus of a frame you're about to delete, if you
2065 know what other frame should receive those keystrokes. */
2066 CHECK_FRAME (frame);
2068 if (! NILP (focus_frame))
2069 CHECK_LIVE_FRAME (focus_frame);
2071 f = XFRAME (frame);
2073 f->focus_frame = focus_frame;
2075 if (FRAME_DISPLAY (f)->frame_rehighlight_hook)
2076 (*FRAME_DISPLAY (f)->frame_rehighlight_hook) (f);
2078 return Qnil;
2082 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
2083 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2084 This returns nil if FRAME's focus is not redirected.
2085 See `redirect-frame-focus'. */)
2086 (frame)
2087 Lisp_Object frame;
2089 CHECK_LIVE_FRAME (frame);
2091 return FRAME_FOCUS_FRAME (XFRAME (frame));
2096 /* Return the value of frame parameter PROP in frame FRAME. */
2098 Lisp_Object
2099 get_frame_param (frame, prop)
2100 register struct frame *frame;
2101 Lisp_Object prop;
2103 register Lisp_Object tem;
2105 tem = Fassq (prop, frame->param_alist);
2106 if (EQ (tem, Qnil))
2107 return tem;
2108 return Fcdr (tem);
2111 /* Return the buffer-predicate of the selected frame. */
2113 Lisp_Object
2114 frame_buffer_predicate (frame)
2115 Lisp_Object frame;
2117 return XFRAME (frame)->buffer_predicate;
2120 /* Return the buffer-list of the selected frame. */
2122 Lisp_Object
2123 frame_buffer_list (frame)
2124 Lisp_Object frame;
2126 return XFRAME (frame)->buffer_list;
2129 /* Set the buffer-list of the selected frame. */
2131 void
2132 set_frame_buffer_list (frame, list)
2133 Lisp_Object frame, list;
2135 XFRAME (frame)->buffer_list = list;
2138 /* Discard BUFFER from the buffer-list of each frame. */
2140 void
2141 frames_discard_buffer (buffer)
2142 Lisp_Object buffer;
2144 Lisp_Object frame, tail;
2146 FOR_EACH_FRAME (tail, frame)
2148 XFRAME (frame)->buffer_list
2149 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2153 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2154 If the alist already has an element for PROP, we change it. */
2156 void
2157 store_in_alist (alistptr, prop, val)
2158 Lisp_Object *alistptr, val;
2159 Lisp_Object prop;
2161 register Lisp_Object tem;
2163 tem = Fassq (prop, *alistptr);
2164 if (EQ (tem, Qnil))
2165 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2166 else
2167 Fsetcdr (tem, val);
2170 static int
2171 frame_name_fnn_p (str, len)
2172 char *str;
2173 int len;
2175 if (len > 1 && str[0] == 'F')
2177 char *end_ptr;
2179 strtol (str + 1, &end_ptr, 10);
2181 if (end_ptr == str + len)
2182 return 1;
2184 return 0;
2187 /* Set the name of the terminal frame. Also used by MSDOS frames.
2188 Modeled after x_set_name which is used for WINDOW frames. */
2190 void
2191 set_term_frame_name (f, name)
2192 struct frame *f;
2193 Lisp_Object name;
2195 f->explicit_name = ! NILP (name);
2197 /* If NAME is nil, set the name to F<num>. */
2198 if (NILP (name))
2200 char namebuf[20];
2202 /* Check for no change needed in this very common case
2203 before we do any consing. */
2204 if (frame_name_fnn_p (SDATA (f->name),
2205 SBYTES (f->name)))
2206 return;
2208 terminal_frame_count++;
2209 sprintf (namebuf, "F%d", terminal_frame_count);
2210 name = build_string (namebuf);
2212 else
2214 CHECK_STRING (name);
2216 /* Don't change the name if it's already NAME. */
2217 if (! NILP (Fstring_equal (name, f->name)))
2218 return;
2220 /* Don't allow the user to set the frame name to F<num>, so it
2221 doesn't clash with the names we generate for terminal frames. */
2222 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2223 error ("Frame names of the form F<num> are usurped by Emacs");
2226 f->name = name;
2227 update_mode_lines = 1;
2230 void
2231 store_frame_param (f, prop, val)
2232 struct frame *f;
2233 Lisp_Object prop, val;
2235 register Lisp_Object old_alist_elt;
2237 /* The buffer-alist parameter is stored in a special place and is
2238 not in the alist. */
2239 if (EQ (prop, Qbuffer_list))
2241 f->buffer_list = val;
2242 return;
2245 /* If PROP is a symbol which is supposed to have frame-local values,
2246 and it is set up based on this frame, switch to the global
2247 binding. That way, we can create or alter the frame-local binding
2248 without messing up the symbol's status. */
2249 if (SYMBOLP (prop))
2251 Lisp_Object valcontents;
2252 valcontents = SYMBOL_VALUE (prop);
2253 if ((BUFFER_LOCAL_VALUEP (valcontents)
2254 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
2255 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2256 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2257 swap_in_global_binding (prop);
2260 #ifndef WINDOWSNT
2261 /* The tty color mode needs to be set before the frame's parameter
2262 alist is updated with the new value, because set_tty_color_mode
2263 wants to look at the old mode. */
2264 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode))
2265 set_tty_color_mode (f, val);
2266 #endif
2268 /* Update the frame parameter alist. */
2269 old_alist_elt = Fassq (prop, f->param_alist);
2270 if (EQ (old_alist_elt, Qnil))
2271 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2272 else
2273 Fsetcdr (old_alist_elt, val);
2275 /* Update some other special parameters in their special places
2276 in addition to the alist. */
2278 if (EQ (prop, Qbuffer_predicate))
2279 f->buffer_predicate = val;
2281 if (! FRAME_WINDOW_P (f))
2283 if (EQ (prop, Qmenu_bar_lines))
2284 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2285 else if (EQ (prop, Qname))
2286 set_term_frame_name (f, val);
2289 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2291 if (! MINI_WINDOW_P (XWINDOW (val)))
2292 error ("Surrogate minibuffer windows must be minibuffer windows");
2294 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2295 && !EQ (val, f->minibuffer_window))
2296 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2298 /* Install the chosen minibuffer window, with proper buffer. */
2299 f->minibuffer_window = val;
2303 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2304 doc: /* Return the parameters-alist of frame FRAME.
2305 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2306 The meaningful PARMs depend on the kind of frame.
2307 If FRAME is omitted, return information on the currently selected frame. */)
2308 (frame)
2309 Lisp_Object frame;
2311 Lisp_Object alist;
2312 FRAME_PTR f;
2313 int height, width;
2314 struct gcpro gcpro1;
2316 if (NILP (frame))
2317 frame = selected_frame;
2319 CHECK_FRAME (frame);
2320 f = XFRAME (frame);
2322 if (!FRAME_LIVE_P (f))
2323 return Qnil;
2325 alist = Fcopy_alist (f->param_alist);
2326 GCPRO1 (alist);
2328 if (!FRAME_WINDOW_P (f))
2330 int fg = FRAME_FOREGROUND_PIXEL (f);
2331 int bg = FRAME_BACKGROUND_PIXEL (f);
2332 Lisp_Object elt;
2334 /* If the frame's parameter alist says the colors are
2335 unspecified and reversed, take the frame's background pixel
2336 for foreground and vice versa. */
2337 elt = Fassq (Qforeground_color, alist);
2338 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2340 if (strncmp (SDATA (XCDR (elt)),
2341 unspecified_bg,
2342 SCHARS (XCDR (elt))) == 0)
2343 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2344 else if (strncmp (SDATA (XCDR (elt)),
2345 unspecified_fg,
2346 SCHARS (XCDR (elt))) == 0)
2347 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2349 else
2350 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2351 elt = Fassq (Qbackground_color, alist);
2352 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2354 if (strncmp (SDATA (XCDR (elt)),
2355 unspecified_fg,
2356 SCHARS (XCDR (elt))) == 0)
2357 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2358 else if (strncmp (SDATA (XCDR (elt)),
2359 unspecified_bg,
2360 SCHARS (XCDR (elt))) == 0)
2361 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2363 else
2364 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2365 store_in_alist (&alist, intern ("font"),
2366 build_string (FRAME_MSDOS_P (f)
2367 ? "ms-dos"
2368 : FRAME_W32_P (f) ? "w32term"
2369 :"tty"));
2371 store_in_alist (&alist, Qname, f->name);
2372 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2373 store_in_alist (&alist, Qheight, make_number (height));
2374 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2375 store_in_alist (&alist, Qwidth, make_number (width));
2376 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2377 store_in_alist (&alist, Qminibuffer,
2378 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2379 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2380 : FRAME_MINIBUF_WINDOW (f)));
2381 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2382 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2384 /* I think this should be done with a hook. */
2385 #ifdef HAVE_WINDOW_SYSTEM
2386 if (FRAME_WINDOW_P (f))
2387 x_report_frame_params (f, &alist);
2388 else
2389 #endif
2391 /* This ought to be correct in f->param_alist for an X frame. */
2392 Lisp_Object lines;
2393 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2394 store_in_alist (&alist, Qmenu_bar_lines, lines);
2397 UNGCPRO;
2398 return alist;
2402 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2403 doc: /* Return FRAME's value for parameter PARAMETER.
2404 If FRAME is nil, describe the currently selected frame. */)
2405 (frame, parameter)
2406 Lisp_Object frame, parameter;
2408 struct frame *f;
2409 Lisp_Object value;
2411 if (NILP (frame))
2412 frame = selected_frame;
2413 else
2414 CHECK_FRAME (frame);
2415 CHECK_SYMBOL (parameter);
2417 f = XFRAME (frame);
2418 value = Qnil;
2420 if (FRAME_LIVE_P (f))
2422 /* Avoid consing in frequent cases. */
2423 if (EQ (parameter, Qname))
2424 value = f->name;
2425 #ifdef HAVE_X_WINDOWS
2426 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2427 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2428 #endif /* HAVE_X_WINDOWS */
2429 else if (EQ (parameter, Qbackground_color)
2430 || EQ (parameter, Qforeground_color))
2432 value = Fassq (parameter, f->param_alist);
2433 if (CONSP (value))
2435 value = XCDR (value);
2436 /* Fframe_parameters puts the actual fg/bg color names,
2437 even if f->param_alist says otherwise. This is
2438 important when param_alist's notion of colors is
2439 "unspecified". We need to do the same here. */
2440 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2442 const char *color_name;
2443 EMACS_INT csz;
2445 if (EQ (parameter, Qbackground_color))
2447 color_name = SDATA (value);
2448 csz = SCHARS (value);
2449 if (strncmp (color_name, unspecified_bg, csz) == 0)
2450 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2451 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2452 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2454 else if (EQ (parameter, Qforeground_color))
2456 color_name = SDATA (value);
2457 csz = SCHARS (value);
2458 if (strncmp (color_name, unspecified_fg, csz) == 0)
2459 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2460 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2461 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2465 else
2466 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2468 else if (EQ (parameter, Qdisplay_type)
2469 || EQ (parameter, Qbackground_mode))
2470 value = Fcdr (Fassq (parameter, f->param_alist));
2471 else
2472 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2475 return value;
2479 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2480 Smodify_frame_parameters, 2, 2, 0,
2481 doc: /* Modify the parameters of frame FRAME according to ALIST.
2482 If FRAME is nil, it defaults to the selected frame.
2483 ALIST is an alist of parameters to change and their new values.
2484 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2485 The meaningful PARMs depend on the kind of frame.
2486 Undefined PARMs are ignored, but stored in the frame's parameter list
2487 so that `frame-parameters' will return them.
2489 The value of frame parameter FOO can also be accessed
2490 as a frame-local binding for the variable FOO, if you have
2491 enabled such bindings for that variable with `make-variable-frame-local'. */)
2492 (frame, alist)
2493 Lisp_Object frame, alist;
2495 FRAME_PTR f;
2496 register Lisp_Object tail, prop, val;
2497 int count = SPECPDL_INDEX ();
2499 /* Bind this to t to inhibit initialization of the default face from
2500 X resources in face-set-after-frame-default. If we don't inhibit
2501 this, modifying the `font' frame parameter, for example, while
2502 there is a `default.attributeFont' X resource, won't work,
2503 because `default's font is reset to the value of the X resource
2504 and that resets the `font' frame parameter. */
2505 specbind (Qinhibit_default_face_x_resources, Qt);
2507 if (EQ (frame, Qnil))
2508 frame = selected_frame;
2509 CHECK_LIVE_FRAME (frame);
2510 f = XFRAME (frame);
2512 /* I think this should be done with a hook. */
2513 #ifdef HAVE_WINDOW_SYSTEM
2514 if (FRAME_WINDOW_P (f))
2515 x_set_frame_parameters (f, alist);
2516 else
2517 #endif
2518 #ifdef MSDOS
2519 if (FRAME_MSDOS_P (f))
2520 IT_set_frame_parameters (f, alist);
2521 else
2522 #endif
2525 int length = XINT (Flength (alist));
2526 int i;
2527 Lisp_Object *parms
2528 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2529 Lisp_Object *values
2530 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2532 /* Extract parm names and values into those vectors. */
2534 i = 0;
2535 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2537 Lisp_Object elt;
2539 elt = Fcar (tail);
2540 parms[i] = Fcar (elt);
2541 values[i] = Fcdr (elt);
2542 i++;
2545 /* Now process them in reverse of specified order. */
2546 for (i--; i >= 0; i--)
2548 prop = parms[i];
2549 val = values[i];
2550 store_frame_param (f, prop, val);
2552 /* Changing the background color might change the background
2553 mode, so that we have to load new defface specs.
2554 Call frame-set-background-mode to do that. */
2555 if (EQ (prop, Qbackground_color))
2556 call1 (Qframe_set_background_mode, frame);
2560 return unbind_to (count, Qnil);
2563 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2564 0, 1, 0,
2565 doc: /* Height in pixels of a line in the font in frame FRAME.
2566 If FRAME is omitted, the selected frame is used.
2567 For a terminal frame, the value is always 1. */)
2568 (frame)
2569 Lisp_Object frame;
2571 struct frame *f;
2573 if (NILP (frame))
2574 frame = selected_frame;
2575 CHECK_FRAME (frame);
2576 f = XFRAME (frame);
2578 #ifdef HAVE_WINDOW_SYSTEM
2579 if (FRAME_WINDOW_P (f))
2580 return make_number (x_char_height (f));
2581 else
2582 #endif
2583 return make_number (1);
2587 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2588 0, 1, 0,
2589 doc: /* Width in pixels of characters in the font in frame FRAME.
2590 If FRAME is omitted, the selected frame is used.
2591 The width is the same for all characters, because
2592 currently Emacs supports only fixed-width fonts.
2593 For a terminal screen, the value is always 1. */)
2594 (frame)
2595 Lisp_Object frame;
2597 struct frame *f;
2599 if (NILP (frame))
2600 frame = selected_frame;
2601 CHECK_FRAME (frame);
2602 f = XFRAME (frame);
2604 #ifdef HAVE_WINDOW_SYSTEM
2605 if (FRAME_WINDOW_P (f))
2606 return make_number (x_char_width (f));
2607 else
2608 #endif
2609 return make_number (1);
2612 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2613 Sframe_pixel_height, 0, 1, 0,
2614 doc: /* Return a FRAME's height in pixels.
2615 This counts only the height available for text lines,
2616 not menu bars on window-system Emacs frames.
2617 For a terminal frame, the result really gives the height in characters.
2618 If FRAME is omitted, the selected frame is used. */)
2619 (frame)
2620 Lisp_Object frame;
2622 struct frame *f;
2624 if (NILP (frame))
2625 frame = selected_frame;
2626 CHECK_FRAME (frame);
2627 f = XFRAME (frame);
2629 #ifdef HAVE_WINDOW_SYSTEM
2630 if (FRAME_WINDOW_P (f))
2631 return make_number (x_pixel_height (f));
2632 else
2633 #endif
2634 return make_number (FRAME_LINES (f));
2637 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2638 Sframe_pixel_width, 0, 1, 0,
2639 doc: /* Return FRAME's width in pixels.
2640 For a terminal frame, the result really gives the width in characters.
2641 If FRAME is omitted, the selected frame is used. */)
2642 (frame)
2643 Lisp_Object frame;
2645 struct frame *f;
2647 if (NILP (frame))
2648 frame = selected_frame;
2649 CHECK_FRAME (frame);
2650 f = XFRAME (frame);
2652 #ifdef HAVE_WINDOW_SYSTEM
2653 if (FRAME_WINDOW_P (f))
2654 return make_number (x_pixel_width (f));
2655 else
2656 #endif
2657 return make_number (FRAME_COLS (f));
2660 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2661 doc: /* Specify that the frame FRAME has LINES lines.
2662 Optional third arg non-nil means that redisplay should use LINES lines
2663 but that the idea of the actual height of the frame should not be changed. */)
2664 (frame, lines, pretend)
2665 Lisp_Object frame, lines, pretend;
2667 register struct frame *f;
2669 CHECK_NUMBER (lines);
2670 if (NILP (frame))
2671 frame = selected_frame;
2672 CHECK_LIVE_FRAME (frame);
2673 f = XFRAME (frame);
2675 /* I think this should be done with a hook. */
2676 #ifdef HAVE_WINDOW_SYSTEM
2677 if (FRAME_WINDOW_P (f))
2679 if (XINT (lines) != FRAME_LINES (f))
2680 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2681 do_pending_window_change (0);
2683 else
2684 #endif
2685 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2686 return Qnil;
2689 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2690 doc: /* Specify that the frame FRAME has COLS columns.
2691 Optional third arg non-nil means that redisplay should use COLS columns
2692 but that the idea of the actual width of the frame should not be changed. */)
2693 (frame, cols, pretend)
2694 Lisp_Object frame, cols, pretend;
2696 register struct frame *f;
2697 CHECK_NUMBER (cols);
2698 if (NILP (frame))
2699 frame = selected_frame;
2700 CHECK_LIVE_FRAME (frame);
2701 f = XFRAME (frame);
2703 /* I think this should be done with a hook. */
2704 #ifdef HAVE_WINDOW_SYSTEM
2705 if (FRAME_WINDOW_P (f))
2707 if (XINT (cols) != FRAME_COLS (f))
2708 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2709 do_pending_window_change (0);
2711 else
2712 #endif
2713 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2714 return Qnil;
2717 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2718 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2719 (frame, cols, rows)
2720 Lisp_Object frame, cols, rows;
2722 register struct frame *f;
2724 CHECK_LIVE_FRAME (frame);
2725 CHECK_NUMBER (cols);
2726 CHECK_NUMBER (rows);
2727 f = XFRAME (frame);
2729 /* I think this should be done with a hook. */
2730 #ifdef HAVE_WINDOW_SYSTEM
2731 if (FRAME_WINDOW_P (f))
2733 if (XINT (rows) != FRAME_LINES (f)
2734 || XINT (cols) != FRAME_COLS (f)
2735 || f->new_text_lines || f->new_text_cols)
2736 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2737 do_pending_window_change (0);
2739 else
2740 #endif
2741 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2743 return Qnil;
2746 DEFUN ("set-frame-position", Fset_frame_position,
2747 Sset_frame_position, 3, 3, 0,
2748 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2749 This is actually the position of the upper left corner of the frame.
2750 Negative values for XOFFSET or YOFFSET are interpreted relative to
2751 the rightmost or bottommost possible position (that stays within the screen). */)
2752 (frame, xoffset, yoffset)
2753 Lisp_Object frame, xoffset, yoffset;
2755 register struct frame *f;
2757 CHECK_LIVE_FRAME (frame);
2758 CHECK_NUMBER (xoffset);
2759 CHECK_NUMBER (yoffset);
2760 f = XFRAME (frame);
2762 /* I think this should be done with a hook. */
2763 #ifdef HAVE_WINDOW_SYSTEM
2764 if (FRAME_WINDOW_P (f))
2765 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2766 #endif
2768 return Qt;
2772 /***********************************************************************
2773 Frame Parameters
2774 ***********************************************************************/
2776 /* Connect the frame-parameter names for X frames
2777 to the ways of passing the parameter values to the window system.
2779 The name of a parameter, as a Lisp symbol,
2780 has an `x-frame-parameter' property which is an integer in Lisp
2781 that is an index in this table. */
2783 struct frame_parm_table {
2784 char *name;
2785 Lisp_Object *variable;
2788 static struct frame_parm_table frame_parms[] =
2790 {"auto-raise", &Qauto_raise},
2791 {"auto-lower", &Qauto_lower},
2792 {"background-color", 0},
2793 {"border-color", &Qborder_color},
2794 {"border-width", &Qborder_width},
2795 {"cursor-color", &Qcursor_color},
2796 {"cursor-type", &Qcursor_type},
2797 {"font", 0},
2798 {"foreground-color", 0},
2799 {"icon-name", &Qicon_name},
2800 {"icon-type", &Qicon_type},
2801 {"internal-border-width", &Qinternal_border_width},
2802 {"menu-bar-lines", &Qmenu_bar_lines},
2803 {"mouse-color", &Qmouse_color},
2804 {"name", &Qname},
2805 {"scroll-bar-width", &Qscroll_bar_width},
2806 {"title", &Qtitle},
2807 {"unsplittable", &Qunsplittable},
2808 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2809 {"visibility", &Qvisibility},
2810 {"tool-bar-lines", &Qtool_bar_lines},
2811 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2812 {"scroll-bar-background", &Qscroll_bar_background},
2813 {"screen-gamma", &Qscreen_gamma},
2814 {"line-spacing", &Qline_spacing},
2815 {"left-fringe", &Qleft_fringe},
2816 {"right-fringe", &Qright_fringe},
2817 {"wait-for-wm", &Qwait_for_wm},
2818 {"fullscreen", &Qfullscreen},
2821 #ifdef HAVE_WINDOW_SYSTEM
2823 extern Lisp_Object Qbox;
2824 extern Lisp_Object Qtop;
2826 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2827 wanted positions of the WM window (not emacs window).
2828 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2829 window (FRAME_X_WINDOW).
2832 void
2833 x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2834 struct frame *f;
2835 int *width;
2836 int *height;
2837 int *top_pos;
2838 int *left_pos;
2840 int newwidth = FRAME_COLS (f);
2841 int newheight = FRAME_LINES (f);
2843 *top_pos = f->top_pos;
2844 *left_pos = f->left_pos;
2846 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2848 int ph;
2850 ph = FRAME_X_DISPLAY_INFO (f)->height;
2851 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2852 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2853 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2854 *top_pos = 0;
2857 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2859 int pw;
2861 pw = FRAME_X_DISPLAY_INFO (f)->width;
2862 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2863 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2864 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2865 *left_pos = 0;
2868 *width = newwidth;
2869 *height = newheight;
2873 /* Change the parameters of frame F as specified by ALIST.
2874 If a parameter is not specially recognized, do nothing special;
2875 otherwise call the `x_set_...' function for that parameter.
2876 Except for certain geometry properties, always call store_frame_param
2877 to store the new value in the parameter alist. */
2879 void
2880 x_set_frame_parameters (f, alist)
2881 FRAME_PTR f;
2882 Lisp_Object alist;
2884 Lisp_Object tail;
2886 /* If both of these parameters are present, it's more efficient to
2887 set them both at once. So we wait until we've looked at the
2888 entire list before we set them. */
2889 int width, height;
2891 /* Same here. */
2892 Lisp_Object left, top;
2894 /* Same with these. */
2895 Lisp_Object icon_left, icon_top;
2897 /* Record in these vectors all the parms specified. */
2898 Lisp_Object *parms;
2899 Lisp_Object *values;
2900 int i, p;
2901 int left_no_change = 0, top_no_change = 0;
2902 int icon_left_no_change = 0, icon_top_no_change = 0;
2903 int fullscreen_is_being_set = 0;
2905 struct gcpro gcpro1, gcpro2;
2907 i = 0;
2908 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2909 i++;
2911 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2912 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2914 /* Extract parm names and values into those vectors. */
2916 i = 0;
2917 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2919 Lisp_Object elt;
2921 elt = Fcar (tail);
2922 parms[i] = Fcar (elt);
2923 values[i] = Fcdr (elt);
2924 i++;
2926 /* TAIL and ALIST are not used again below here. */
2927 alist = tail = Qnil;
2929 GCPRO2 (*parms, *values);
2930 gcpro1.nvars = i;
2931 gcpro2.nvars = i;
2933 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2934 because their values appear in VALUES and strings are not valid. */
2935 top = left = Qunbound;
2936 icon_left = icon_top = Qunbound;
2938 /* Provide default values for HEIGHT and WIDTH. */
2939 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2940 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2942 /* Process foreground_color and background_color before anything else.
2943 They are independent of other properties, but other properties (e.g.,
2944 cursor_color) are dependent upon them. */
2945 /* Process default font as well, since fringe widths depends on it. */
2946 /* Also, process fullscreen, width and height depend upon that */
2947 for (p = 0; p < i; p++)
2949 Lisp_Object prop, val;
2951 prop = parms[p];
2952 val = values[p];
2953 if (EQ (prop, Qforeground_color)
2954 || EQ (prop, Qbackground_color)
2955 || EQ (prop, Qfont)
2956 || EQ (prop, Qfullscreen))
2958 register Lisp_Object param_index, old_value;
2960 old_value = get_frame_param (f, prop);
2961 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
2963 if (NILP (Fequal (val, old_value)))
2965 store_frame_param (f, prop, val);
2967 param_index = Fget (prop, Qx_frame_parameter);
2968 if (NATNUMP (param_index)
2969 && (XFASTINT (param_index)
2970 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2971 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2972 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2977 /* Now process them in reverse of specified order. */
2978 for (i--; i >= 0; i--)
2980 Lisp_Object prop, val;
2982 prop = parms[i];
2983 val = values[i];
2985 if (EQ (prop, Qwidth) && NUMBERP (val))
2986 width = XFASTINT (val);
2987 else if (EQ (prop, Qheight) && NUMBERP (val))
2988 height = XFASTINT (val);
2989 else if (EQ (prop, Qtop))
2990 top = val;
2991 else if (EQ (prop, Qleft))
2992 left = val;
2993 else if (EQ (prop, Qicon_top))
2994 icon_top = val;
2995 else if (EQ (prop, Qicon_left))
2996 icon_left = val;
2997 else if (EQ (prop, Qforeground_color)
2998 || EQ (prop, Qbackground_color)
2999 || EQ (prop, Qfont)
3000 || EQ (prop, Qfullscreen))
3001 /* Processed above. */
3002 continue;
3003 else
3005 register Lisp_Object param_index, old_value;
3007 old_value = get_frame_param (f, prop);
3009 store_frame_param (f, prop, val);
3011 param_index = Fget (prop, Qx_frame_parameter);
3012 if (NATNUMP (param_index)
3013 && (XFASTINT (param_index)
3014 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3015 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3016 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3020 /* Don't die if just one of these was set. */
3021 if (EQ (left, Qunbound))
3023 left_no_change = 1;
3024 if (f->left_pos < 0)
3025 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
3026 else
3027 XSETINT (left, f->left_pos);
3029 if (EQ (top, Qunbound))
3031 top_no_change = 1;
3032 if (f->top_pos < 0)
3033 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
3034 else
3035 XSETINT (top, f->top_pos);
3038 /* If one of the icon positions was not set, preserve or default it. */
3039 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
3041 icon_left_no_change = 1;
3042 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3043 if (NILP (icon_left))
3044 XSETINT (icon_left, 0);
3046 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
3048 icon_top_no_change = 1;
3049 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3050 if (NILP (icon_top))
3051 XSETINT (icon_top, 0);
3054 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
3056 /* If the frame is visible already and the fullscreen parameter is
3057 being set, it is too late to set WM manager hints to specify
3058 size and position.
3059 Here we first get the width, height and position that applies to
3060 fullscreen. We then move the frame to the appropriate
3061 position. Resize of the frame is taken care of in the code after
3062 this if-statement. */
3063 int new_left, new_top;
3065 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
3066 if (new_top != f->top_pos || new_left != f->left_pos)
3067 x_set_offset (f, new_left, new_top, 1);
3070 /* Don't set these parameters unless they've been explicitly
3071 specified. The window might be mapped or resized while we're in
3072 this function, and we don't want to override that unless the lisp
3073 code has asked for it.
3075 Don't set these parameters unless they actually differ from the
3076 window's current parameters; the window may not actually exist
3077 yet. */
3079 Lisp_Object frame;
3081 check_frame_size (f, &height, &width);
3083 XSETFRAME (frame, f);
3085 if (width != FRAME_COLS (f)
3086 || height != FRAME_LINES (f)
3087 || f->new_text_lines || f->new_text_cols)
3088 Fset_frame_size (frame, make_number (width), make_number (height));
3090 if ((!NILP (left) || !NILP (top))
3091 && ! (left_no_change && top_no_change)
3092 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3093 && NUMBERP (top) && XINT (top) == f->top_pos))
3095 int leftpos = 0;
3096 int toppos = 0;
3098 /* Record the signs. */
3099 f->size_hint_flags &= ~ (XNegative | YNegative);
3100 if (EQ (left, Qminus))
3101 f->size_hint_flags |= XNegative;
3102 else if (INTEGERP (left))
3104 leftpos = XINT (left);
3105 if (leftpos < 0)
3106 f->size_hint_flags |= XNegative;
3108 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3109 && CONSP (XCDR (left))
3110 && INTEGERP (XCAR (XCDR (left))))
3112 leftpos = - XINT (XCAR (XCDR (left)));
3113 f->size_hint_flags |= XNegative;
3115 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3116 && CONSP (XCDR (left))
3117 && INTEGERP (XCAR (XCDR (left))))
3119 leftpos = XINT (XCAR (XCDR (left)));
3122 if (EQ (top, Qminus))
3123 f->size_hint_flags |= YNegative;
3124 else if (INTEGERP (top))
3126 toppos = XINT (top);
3127 if (toppos < 0)
3128 f->size_hint_flags |= YNegative;
3130 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3131 && CONSP (XCDR (top))
3132 && INTEGERP (XCAR (XCDR (top))))
3134 toppos = - XINT (XCAR (XCDR (top)));
3135 f->size_hint_flags |= YNegative;
3137 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3138 && CONSP (XCDR (top))
3139 && INTEGERP (XCAR (XCDR (top))))
3141 toppos = XINT (XCAR (XCDR (top)));
3145 /* Store the numeric value of the position. */
3146 f->top_pos = toppos;
3147 f->left_pos = leftpos;
3149 f->win_gravity = NorthWestGravity;
3151 /* Actually set that position, and convert to absolute. */
3152 x_set_offset (f, leftpos, toppos, -1);
3155 if ((!NILP (icon_left) || !NILP (icon_top))
3156 && ! (icon_left_no_change && icon_top_no_change))
3157 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3160 UNGCPRO;
3164 /* Insert a description of internally-recorded parameters of frame X
3165 into the parameter alist *ALISTPTR that is to be given to the user.
3166 Only parameters that are specific to the X window system
3167 and whose values are not correctly recorded in the frame's
3168 param_alist need to be considered here. */
3170 void
3171 x_report_frame_params (f, alistptr)
3172 struct frame *f;
3173 Lisp_Object *alistptr;
3175 char buf[16];
3176 Lisp_Object tem;
3178 /* Represent negative positions (off the top or left screen edge)
3179 in a way that Fmodify_frame_parameters will understand correctly. */
3180 XSETINT (tem, f->left_pos);
3181 if (f->left_pos >= 0)
3182 store_in_alist (alistptr, Qleft, tem);
3183 else
3184 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3186 XSETINT (tem, f->top_pos);
3187 if (f->top_pos >= 0)
3188 store_in_alist (alistptr, Qtop, tem);
3189 else
3190 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3192 store_in_alist (alistptr, Qborder_width,
3193 make_number (f->border_width));
3194 store_in_alist (alistptr, Qinternal_border_width,
3195 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3196 store_in_alist (alistptr, Qleft_fringe,
3197 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3198 store_in_alist (alistptr, Qright_fringe,
3199 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3200 store_in_alist (alistptr, Qscroll_bar_width,
3201 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3202 ? make_number (0)
3203 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3204 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3205 /* nil means "use default width"
3206 for non-toolkit scroll bar.
3207 ruler-mode.el depends on this. */
3208 : Qnil));
3209 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3210 store_in_alist (alistptr, Qwindow_id,
3211 build_string (buf));
3212 #ifdef HAVE_X_WINDOWS
3213 #ifdef USE_X_TOOLKIT
3214 /* Tooltip frame may not have this widget. */
3215 if (FRAME_X_OUTPUT (f)->widget)
3216 #endif
3217 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3218 store_in_alist (alistptr, Qouter_window_id,
3219 build_string (buf));
3220 #endif
3221 store_in_alist (alistptr, Qicon_name, f->icon_name);
3222 FRAME_SAMPLE_VISIBILITY (f);
3223 store_in_alist (alistptr, Qvisibility,
3224 (FRAME_VISIBLE_P (f) ? Qt
3225 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3226 store_in_alist (alistptr, Qdisplay,
3227 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3229 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3230 tem = Qnil;
3231 else
3232 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3233 store_in_alist (alistptr, Qparent_id, tem);
3237 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3238 the previous value of that parameter, NEW_VALUE is the new value. */
3240 void
3241 x_set_fullscreen (f, new_value, old_value)
3242 struct frame *f;
3243 Lisp_Object new_value, old_value;
3245 if (NILP (new_value))
3246 f->want_fullscreen = FULLSCREEN_NONE;
3247 else if (EQ (new_value, Qfullboth))
3248 f->want_fullscreen = FULLSCREEN_BOTH;
3249 else if (EQ (new_value, Qfullwidth))
3250 f->want_fullscreen = FULLSCREEN_WIDTH;
3251 else if (EQ (new_value, Qfullheight))
3252 f->want_fullscreen = FULLSCREEN_HEIGHT;
3256 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3257 the previous value of that parameter, NEW_VALUE is the new value. */
3259 void
3260 x_set_line_spacing (f, new_value, old_value)
3261 struct frame *f;
3262 Lisp_Object new_value, old_value;
3264 if (NILP (new_value))
3265 f->extra_line_spacing = 0;
3266 else if (NATNUMP (new_value))
3267 f->extra_line_spacing = XFASTINT (new_value);
3268 else
3269 Fsignal (Qerror, Fcons (build_string ("Invalid line-spacing"),
3270 Fcons (new_value, Qnil)));
3271 if (FRAME_VISIBLE_P (f))
3272 redraw_frame (f);
3276 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3277 the previous value of that parameter, NEW_VALUE is the new value. */
3279 void
3280 x_set_screen_gamma (f, new_value, old_value)
3281 struct frame *f;
3282 Lisp_Object new_value, old_value;
3284 if (NILP (new_value))
3285 f->gamma = 0;
3286 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3287 /* The value 0.4545 is the normal viewing gamma. */
3288 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3289 else
3290 Fsignal (Qerror, Fcons (build_string ("Invalid screen-gamma"),
3291 Fcons (new_value, Qnil)));
3293 clear_face_cache (0);
3297 void
3298 x_set_font (f, arg, oldval)
3299 struct frame *f;
3300 Lisp_Object arg, oldval;
3302 Lisp_Object result;
3303 Lisp_Object fontset_name;
3304 Lisp_Object frame;
3305 int old_fontset = FRAME_FONTSET(f);
3307 CHECK_STRING (arg);
3309 fontset_name = Fquery_fontset (arg, Qnil);
3311 BLOCK_INPUT;
3312 result = (STRINGP (fontset_name)
3313 ? x_new_fontset (f, SDATA (fontset_name))
3314 : x_new_font (f, SDATA (arg)));
3315 UNBLOCK_INPUT;
3317 if (EQ (result, Qnil))
3318 error ("Font `%s' is not defined", SDATA (arg));
3319 else if (EQ (result, Qt))
3320 error ("The characters of the given font have varying widths");
3321 else if (STRINGP (result))
3323 set_default_ascii_font (result);
3324 if (STRINGP (fontset_name))
3326 /* Fontset names are built from ASCII font names, so the
3327 names may be equal despite there was a change. */
3328 if (old_fontset == FRAME_FONTSET (f))
3329 return;
3331 else if (!NILP (Fequal (result, oldval)))
3332 return;
3334 store_frame_param (f, Qfont, result);
3335 recompute_basic_faces (f);
3337 else
3338 abort ();
3340 do_pending_window_change (0);
3342 /* Don't call `face-set-after-frame-default' when faces haven't been
3343 initialized yet. This is the case when called from
3344 Fx_create_frame. In that case, the X widget or window doesn't
3345 exist either, and we can end up in x_report_frame_params with a
3346 null widget which gives a segfault. */
3347 if (FRAME_FACE_CACHE (f))
3349 XSETFRAME (frame, f);
3350 call1 (Qface_set_after_frame_default, frame);
3355 void
3356 x_set_fringe_width (f, new_value, old_value)
3357 struct frame *f;
3358 Lisp_Object new_value, old_value;
3360 compute_fringe_widths (f, 1);
3363 void
3364 x_set_border_width (f, arg, oldval)
3365 struct frame *f;
3366 Lisp_Object arg, oldval;
3368 CHECK_NUMBER (arg);
3370 if (XINT (arg) == f->border_width)
3371 return;
3373 #ifndef MAC_OS
3374 if (FRAME_X_WINDOW (f) != 0)
3375 error ("Cannot change the border width of a window");
3376 #endif /* MAC_TODO */
3378 f->border_width = XINT (arg);
3381 void
3382 x_set_internal_border_width (f, arg, oldval)
3383 struct frame *f;
3384 Lisp_Object arg, oldval;
3386 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3388 CHECK_NUMBER (arg);
3389 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3390 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3391 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3393 #ifdef USE_X_TOOLKIT
3394 if (FRAME_X_OUTPUT (f)->edit_widget)
3395 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3396 #endif
3398 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3399 return;
3401 if (FRAME_X_WINDOW (f) != 0)
3403 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3404 SET_FRAME_GARBAGED (f);
3405 do_pending_window_change (0);
3407 else
3408 SET_FRAME_GARBAGED (f);
3411 void
3412 x_set_visibility (f, value, oldval)
3413 struct frame *f;
3414 Lisp_Object value, oldval;
3416 Lisp_Object frame;
3417 XSETFRAME (frame, f);
3419 if (NILP (value))
3420 Fmake_frame_invisible (frame, Qt);
3421 else if (EQ (value, Qicon))
3422 Ficonify_frame (frame);
3423 else
3424 Fmake_frame_visible (frame);
3427 void
3428 x_set_autoraise (f, arg, oldval)
3429 struct frame *f;
3430 Lisp_Object arg, oldval;
3432 f->auto_raise = !EQ (Qnil, arg);
3435 void
3436 x_set_autolower (f, arg, oldval)
3437 struct frame *f;
3438 Lisp_Object arg, oldval;
3440 f->auto_lower = !EQ (Qnil, arg);
3443 void
3444 x_set_unsplittable (f, arg, oldval)
3445 struct frame *f;
3446 Lisp_Object arg, oldval;
3448 f->no_split = !NILP (arg);
3451 void
3452 x_set_vertical_scroll_bars (f, arg, oldval)
3453 struct frame *f;
3454 Lisp_Object arg, oldval;
3456 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3457 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3458 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3459 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3461 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3462 = (NILP (arg)
3463 ? vertical_scroll_bar_none
3464 : EQ (Qleft, arg)
3465 ? vertical_scroll_bar_left
3466 : EQ (Qright, arg)
3467 ? vertical_scroll_bar_right
3468 : EQ (Qleft, Vdefault_frame_scroll_bars)
3469 ? vertical_scroll_bar_left
3470 : EQ (Qright, Vdefault_frame_scroll_bars)
3471 ? vertical_scroll_bar_right
3472 : vertical_scroll_bar_none);
3474 /* We set this parameter before creating the X window for the
3475 frame, so we can get the geometry right from the start.
3476 However, if the window hasn't been created yet, we shouldn't
3477 call x_set_window_size. */
3478 if (FRAME_X_WINDOW (f))
3479 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3480 do_pending_window_change (0);
3484 void
3485 x_set_scroll_bar_width (f, arg, oldval)
3486 struct frame *f;
3487 Lisp_Object arg, oldval;
3489 int wid = FRAME_COLUMN_WIDTH (f);
3491 if (NILP (arg))
3493 x_set_scroll_bar_default_width (f);
3495 if (FRAME_X_WINDOW (f))
3496 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3497 do_pending_window_change (0);
3499 else if (INTEGERP (arg) && XINT (arg) > 0
3500 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3502 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3503 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3505 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3506 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3507 if (FRAME_X_WINDOW (f))
3508 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3509 do_pending_window_change (0);
3512 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3513 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3514 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3519 /* Return non-nil if frame F wants a bitmap icon. */
3521 Lisp_Object
3522 x_icon_type (f)
3523 FRAME_PTR f;
3525 Lisp_Object tem;
3527 tem = assq_no_quit (Qicon_type, f->param_alist);
3528 if (CONSP (tem))
3529 return XCDR (tem);
3530 else
3531 return Qnil;
3535 /* Subroutines of creating an X frame. */
3537 /* Make sure that Vx_resource_name is set to a reasonable value.
3538 Fix it up, or set it to `emacs' if it is too hopeless. */
3540 void
3541 validate_x_resource_name ()
3543 int len = 0;
3544 /* Number of valid characters in the resource name. */
3545 int good_count = 0;
3546 /* Number of invalid characters in the resource name. */
3547 int bad_count = 0;
3548 Lisp_Object new;
3549 int i;
3551 if (!STRINGP (Vx_resource_class))
3552 Vx_resource_class = build_string (EMACS_CLASS);
3554 if (STRINGP (Vx_resource_name))
3556 unsigned char *p = SDATA (Vx_resource_name);
3557 int i;
3559 len = SBYTES (Vx_resource_name);
3561 /* Only letters, digits, - and _ are valid in resource names.
3562 Count the valid characters and count the invalid ones. */
3563 for (i = 0; i < len; i++)
3565 int c = p[i];
3566 if (! ((c >= 'a' && c <= 'z')
3567 || (c >= 'A' && c <= 'Z')
3568 || (c >= '0' && c <= '9')
3569 || c == '-' || c == '_'))
3570 bad_count++;
3571 else
3572 good_count++;
3575 else
3576 /* Not a string => completely invalid. */
3577 bad_count = 5, good_count = 0;
3579 /* If name is valid already, return. */
3580 if (bad_count == 0)
3581 return;
3583 /* If name is entirely invalid, or nearly so, use `emacs'. */
3584 if (good_count == 0
3585 || (good_count == 1 && bad_count > 0))
3587 Vx_resource_name = build_string ("emacs");
3588 return;
3591 /* Name is partly valid. Copy it and replace the invalid characters
3592 with underscores. */
3594 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3596 for (i = 0; i < len; i++)
3598 int c = SREF (new, i);
3599 if (! ((c >= 'a' && c <= 'z')
3600 || (c >= 'A' && c <= 'Z')
3601 || (c >= '0' && c <= '9')
3602 || c == '-' || c == '_'))
3603 SSET (new, i, '_');
3608 extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3609 extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3612 /* Get specified attribute from resource database RDB.
3613 See Fx_get_resource below for other parameters. */
3615 static Lisp_Object
3616 xrdb_get_resource (rdb, attribute, class, component, subclass)
3617 XrmDatabase rdb;
3618 Lisp_Object attribute, class, component, subclass;
3620 register char *value;
3621 char *name_key;
3622 char *class_key;
3624 CHECK_STRING (attribute);
3625 CHECK_STRING (class);
3627 if (!NILP (component))
3628 CHECK_STRING (component);
3629 if (!NILP (subclass))
3630 CHECK_STRING (subclass);
3631 if (NILP (component) != NILP (subclass))
3632 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3634 validate_x_resource_name ();
3636 /* Allocate space for the components, the dots which separate them,
3637 and the final '\0'. Make them big enough for the worst case. */
3638 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3639 + (STRINGP (component)
3640 ? SBYTES (component) : 0)
3641 + SBYTES (attribute)
3642 + 3);
3644 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3645 + SBYTES (class)
3646 + (STRINGP (subclass)
3647 ? SBYTES (subclass) : 0)
3648 + 3);
3650 /* Start with emacs.FRAMENAME for the name (the specific one)
3651 and with `Emacs' for the class key (the general one). */
3652 strcpy (name_key, SDATA (Vx_resource_name));
3653 strcpy (class_key, SDATA (Vx_resource_class));
3655 strcat (class_key, ".");
3656 strcat (class_key, SDATA (class));
3658 if (!NILP (component))
3660 strcat (class_key, ".");
3661 strcat (class_key, SDATA (subclass));
3663 strcat (name_key, ".");
3664 strcat (name_key, SDATA (component));
3667 strcat (name_key, ".");
3668 strcat (name_key, SDATA (attribute));
3670 value = x_get_string_resource (rdb, name_key, class_key);
3672 if (value != (char *) 0)
3673 return build_string (value);
3674 else
3675 return Qnil;
3679 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3680 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3681 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3682 class, where INSTANCE is the name under which Emacs was invoked, or
3683 the name specified by the `-name' or `-rn' command-line arguments.
3685 The optional arguments COMPONENT and SUBCLASS add to the key and the
3686 class, respectively. You must specify both of them or neither.
3687 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3688 and the class is `Emacs.CLASS.SUBCLASS'. */)
3689 (attribute, class, component, subclass)
3690 Lisp_Object attribute, class, component, subclass;
3692 #ifdef HAVE_X_WINDOWS
3693 check_x ();
3694 #endif
3696 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3697 attribute, class, component, subclass);
3700 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3702 Lisp_Object
3703 display_x_get_resource (dpyinfo, attribute, class, component, subclass)
3704 Display_Info *dpyinfo;
3705 Lisp_Object attribute, class, component, subclass;
3707 return xrdb_get_resource (dpyinfo->xrdb,
3708 attribute, class, component, subclass);
3711 /* Used when C code wants a resource value. */
3713 char *
3714 x_get_resource_string (attribute, class)
3715 char *attribute, *class;
3717 char *name_key;
3718 char *class_key;
3719 struct frame *sf = SELECTED_FRAME ();
3721 /* Allocate space for the components, the dots which separate them,
3722 and the final '\0'. */
3723 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3724 + strlen (attribute) + 2);
3725 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3726 + strlen (class) + 2);
3728 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3729 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3731 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3732 name_key, class_key);
3736 /* Return the value of parameter PARAM.
3738 First search ALIST, then Vdefault_frame_alist, then the X defaults
3739 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3741 Convert the resource to the type specified by desired_type.
3743 If no default is specified, return Qunbound. If you call
3744 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3745 and don't let it get stored in any Lisp-visible variables! */
3747 Lisp_Object
3748 x_get_arg (dpyinfo, alist, param, attribute, class, type)
3749 Display_Info *dpyinfo;
3750 Lisp_Object alist, param;
3751 char *attribute;
3752 char *class;
3753 enum resource_types type;
3755 register Lisp_Object tem;
3757 tem = Fassq (param, alist);
3758 if (EQ (tem, Qnil))
3759 tem = Fassq (param, Vdefault_frame_alist);
3760 if (EQ (tem, Qnil))
3762 if (attribute)
3764 tem = display_x_get_resource (dpyinfo,
3765 build_string (attribute),
3766 build_string (class),
3767 Qnil, Qnil);
3769 if (NILP (tem))
3770 return Qunbound;
3772 switch (type)
3774 case RES_TYPE_NUMBER:
3775 return make_number (atoi (SDATA (tem)));
3777 case RES_TYPE_FLOAT:
3778 return make_float (atof (SDATA (tem)));
3780 case RES_TYPE_BOOLEAN:
3781 tem = Fdowncase (tem);
3782 if (!strcmp (SDATA (tem), "on")
3783 || !strcmp (SDATA (tem), "true"))
3784 return Qt;
3785 else
3786 return Qnil;
3788 case RES_TYPE_STRING:
3789 return tem;
3791 case RES_TYPE_SYMBOL:
3792 /* As a special case, we map the values `true' and `on'
3793 to Qt, and `false' and `off' to Qnil. */
3795 Lisp_Object lower;
3796 lower = Fdowncase (tem);
3797 if (!strcmp (SDATA (lower), "on")
3798 || !strcmp (SDATA (lower), "true"))
3799 return Qt;
3800 else if (!strcmp (SDATA (lower), "off")
3801 || !strcmp (SDATA (lower), "false"))
3802 return Qnil;
3803 else
3804 return Fintern (tem, Qnil);
3807 default:
3808 abort ();
3811 else
3812 return Qunbound;
3814 return Fcdr (tem);
3817 Lisp_Object
3818 x_frame_get_arg (f, alist, param, attribute, class, type)
3819 struct frame *f;
3820 Lisp_Object alist, param;
3821 char *attribute;
3822 char *class;
3823 enum resource_types type;
3825 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3826 alist, param, attribute, class, type);
3829 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3831 Lisp_Object
3832 x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
3833 struct frame *f;
3834 Lisp_Object alist, param;
3835 char *attribute;
3836 char *class;
3837 enum resource_types type;
3839 Lisp_Object value;
3841 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3842 attribute, class, type);
3843 if (! NILP (value))
3844 store_frame_param (f, param, value);
3846 return value;
3850 /* Record in frame F the specified or default value according to ALIST
3851 of the parameter named PROP (a Lisp symbol).
3852 If no value is specified for PROP, look for an X default for XPROP
3853 on the frame named NAME.
3854 If that is not found either, use the value DEFLT. */
3856 Lisp_Object
3857 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
3858 struct frame *f;
3859 Lisp_Object alist;
3860 Lisp_Object prop;
3861 Lisp_Object deflt;
3862 char *xprop;
3863 char *xclass;
3864 enum resource_types type;
3866 Lisp_Object tem;
3868 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3869 if (EQ (tem, Qunbound))
3870 tem = deflt;
3871 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3872 return tem;
3878 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3879 doc: /* Parse an X-style geometry string STRING.
3880 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3881 The properties returned may include `top', `left', `height', and `width'.
3882 The value of `left' or `top' may be an integer,
3883 or a list (+ N) meaning N pixels relative to top/left corner,
3884 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3885 (string)
3886 Lisp_Object string;
3888 int geometry, x, y;
3889 unsigned int width, height;
3890 Lisp_Object result;
3892 CHECK_STRING (string);
3894 geometry = XParseGeometry ((char *) SDATA (string),
3895 &x, &y, &width, &height);
3897 #if 0
3898 if (!!(geometry & XValue) != !!(geometry & YValue))
3899 error ("Must specify both x and y position, or neither");
3900 #endif
3902 result = Qnil;
3903 if (geometry & XValue)
3905 Lisp_Object element;
3907 if (x >= 0 && (geometry & XNegative))
3908 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3909 else if (x < 0 && ! (geometry & XNegative))
3910 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3911 else
3912 element = Fcons (Qleft, make_number (x));
3913 result = Fcons (element, result);
3916 if (geometry & YValue)
3918 Lisp_Object element;
3920 if (y >= 0 && (geometry & YNegative))
3921 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3922 else if (y < 0 && ! (geometry & YNegative))
3923 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3924 else
3925 element = Fcons (Qtop, make_number (y));
3926 result = Fcons (element, result);
3929 if (geometry & WidthValue)
3930 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3931 if (geometry & HeightValue)
3932 result = Fcons (Fcons (Qheight, make_number (height)), result);
3934 return result;
3937 /* Calculate the desired size and position of frame F.
3938 Return the flags saying which aspects were specified.
3940 Also set the win_gravity and size_hint_flags of F.
3942 Adjust height for toolbar if TOOLBAR_P is 1.
3944 This function does not make the coordinates positive. */
3946 #define DEFAULT_ROWS 40
3947 #define DEFAULT_COLS 80
3950 x_figure_window_size (f, parms, toolbar_p)
3951 struct frame *f;
3952 Lisp_Object parms;
3953 int toolbar_p;
3955 register Lisp_Object tem0, tem1, tem2;
3956 long window_prompting = 0;
3957 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3959 /* Default values if we fall through.
3960 Actually, if that happens we should get
3961 window manager prompting. */
3962 SET_FRAME_COLS (f, DEFAULT_COLS);
3963 FRAME_LINES (f) = DEFAULT_ROWS;
3964 /* Window managers expect that if program-specified
3965 positions are not (0,0), they're intentional, not defaults. */
3966 f->top_pos = 0;
3967 f->left_pos = 0;
3969 /* Ensure that old new_text_cols and new_text_lines will not override the
3970 values set here. */
3971 /* ++KFS: This was specific to W32, but seems ok for all platforms */
3972 f->new_text_cols = f->new_text_lines = 0;
3974 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
3975 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
3976 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
3977 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3979 if (!EQ (tem0, Qunbound))
3981 CHECK_NUMBER (tem0);
3982 FRAME_LINES (f) = XINT (tem0);
3984 if (!EQ (tem1, Qunbound))
3986 CHECK_NUMBER (tem1);
3987 SET_FRAME_COLS (f, XINT (tem1));
3989 if (!NILP (tem2) && !EQ (tem2, Qunbound))
3990 window_prompting |= USSize;
3991 else
3992 window_prompting |= PSize;
3995 f->scroll_bar_actual_width
3996 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
3998 /* This used to be done _before_ calling x_figure_window_size, but
3999 since the height is reset here, this was really a no-op. I
4000 assume that moving it here does what Gerd intended (although he
4001 no longer can remember what that was... ++KFS, 2003-03-25. */
4003 /* Add the tool-bar height to the initial frame height so that the
4004 user gets a text display area of the size he specified with -g or
4005 via .Xdefaults. Later changes of the tool-bar height don't
4006 change the frame size. This is done so that users can create
4007 tall Emacs frames without having to guess how tall the tool-bar
4008 will get. */
4009 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4011 int margin, relief, bar_height;
4013 relief = (tool_bar_button_relief >= 0
4014 ? tool_bar_button_relief
4015 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4017 if (INTEGERP (Vtool_bar_button_margin)
4018 && XINT (Vtool_bar_button_margin) > 0)
4019 margin = XFASTINT (Vtool_bar_button_margin);
4020 else if (CONSP (Vtool_bar_button_margin)
4021 && INTEGERP (XCDR (Vtool_bar_button_margin))
4022 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
4023 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4024 else
4025 margin = 0;
4027 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4028 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4031 compute_fringe_widths (f, 0);
4033 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4034 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4036 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4037 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4038 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4039 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4041 if (EQ (tem0, Qminus))
4043 f->top_pos = 0;
4044 window_prompting |= YNegative;
4046 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4047 && CONSP (XCDR (tem0))
4048 && INTEGERP (XCAR (XCDR (tem0))))
4050 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4051 window_prompting |= YNegative;
4053 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4054 && CONSP (XCDR (tem0))
4055 && INTEGERP (XCAR (XCDR (tem0))))
4057 f->top_pos = XINT (XCAR (XCDR (tem0)));
4059 else if (EQ (tem0, Qunbound))
4060 f->top_pos = 0;
4061 else
4063 CHECK_NUMBER (tem0);
4064 f->top_pos = XINT (tem0);
4065 if (f->top_pos < 0)
4066 window_prompting |= YNegative;
4069 if (EQ (tem1, Qminus))
4071 f->left_pos = 0;
4072 window_prompting |= XNegative;
4074 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4075 && CONSP (XCDR (tem1))
4076 && INTEGERP (XCAR (XCDR (tem1))))
4078 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4079 window_prompting |= XNegative;
4081 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4082 && CONSP (XCDR (tem1))
4083 && INTEGERP (XCAR (XCDR (tem1))))
4085 f->left_pos = XINT (XCAR (XCDR (tem1)));
4087 else if (EQ (tem1, Qunbound))
4088 f->left_pos = 0;
4089 else
4091 CHECK_NUMBER (tem1);
4092 f->left_pos = XINT (tem1);
4093 if (f->left_pos < 0)
4094 window_prompting |= XNegative;
4097 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4098 window_prompting |= USPosition;
4099 else
4100 window_prompting |= PPosition;
4103 if (f->want_fullscreen != FULLSCREEN_NONE)
4105 int left, top;
4106 int width, height;
4108 /* It takes both for some WM:s to place it where we want */
4109 window_prompting = USPosition | PPosition;
4110 x_fullscreen_adjust (f, &width, &height, &top, &left);
4111 FRAME_COLS (f) = width;
4112 FRAME_LINES (f) = height;
4113 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
4114 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
4115 f->left_pos = left;
4116 f->top_pos = top;
4119 if (window_prompting & XNegative)
4121 if (window_prompting & YNegative)
4122 f->win_gravity = SouthEastGravity;
4123 else
4124 f->win_gravity = NorthEastGravity;
4126 else
4128 if (window_prompting & YNegative)
4129 f->win_gravity = SouthWestGravity;
4130 else
4131 f->win_gravity = NorthWestGravity;
4134 f->size_hint_flags = window_prompting;
4136 return window_prompting;
4141 #endif /* HAVE_WINDOW_SYSTEM */
4145 /***********************************************************************
4146 Initialization
4147 ***********************************************************************/
4149 void
4150 syms_of_frame ()
4152 Qframep = intern ("framep");
4153 staticpro (&Qframep);
4154 Qframe_live_p = intern ("frame-live-p");
4155 staticpro (&Qframe_live_p);
4156 Qheight = intern ("height");
4157 staticpro (&Qheight);
4158 Qicon = intern ("icon");
4159 staticpro (&Qicon);
4160 Qminibuffer = intern ("minibuffer");
4161 staticpro (&Qminibuffer);
4162 Qmodeline = intern ("modeline");
4163 staticpro (&Qmodeline);
4164 Qonly = intern ("only");
4165 staticpro (&Qonly);
4166 Qwidth = intern ("width");
4167 staticpro (&Qwidth);
4168 Qgeometry = intern ("geometry");
4169 staticpro (&Qgeometry);
4170 Qicon_left = intern ("icon-left");
4171 staticpro (&Qicon_left);
4172 Qicon_top = intern ("icon-top");
4173 staticpro (&Qicon_top);
4174 Qleft = intern ("left");
4175 staticpro (&Qleft);
4176 Qright = intern ("right");
4177 staticpro (&Qright);
4178 Quser_position = intern ("user-position");
4179 staticpro (&Quser_position);
4180 Quser_size = intern ("user-size");
4181 staticpro (&Quser_size);
4182 Qwindow_id = intern ("window-id");
4183 staticpro (&Qwindow_id);
4184 #ifdef HAVE_X_WINDOWS
4185 Qouter_window_id = intern ("outer-window-id");
4186 staticpro (&Qouter_window_id);
4187 #endif
4188 Qparent_id = intern ("parent-id");
4189 staticpro (&Qparent_id);
4190 Qx = intern ("x");
4191 staticpro (&Qx);
4192 Qw32 = intern ("w32");
4193 staticpro (&Qw32);
4194 Qpc = intern ("pc");
4195 staticpro (&Qpc);
4196 Qmac = intern ("mac");
4197 staticpro (&Qmac);
4198 Qvisible = intern ("visible");
4199 staticpro (&Qvisible);
4200 Qbuffer_predicate = intern ("buffer-predicate");
4201 staticpro (&Qbuffer_predicate);
4202 Qbuffer_list = intern ("buffer-list");
4203 staticpro (&Qbuffer_list);
4204 Qdisplay_type = intern ("display-type");
4205 staticpro (&Qdisplay_type);
4206 Qbackground_mode = intern ("background-mode");
4207 staticpro (&Qbackground_mode);
4208 Qtty_color_mode = intern ("tty-color-mode");
4209 staticpro (&Qtty_color_mode);
4210 Qtty = intern ("tty");
4211 staticpro (&Qtty);
4212 Qtty_type = intern ("tty-type");
4213 staticpro (&Qtty_type);
4214 Qwindow_system = intern ("window-system");
4215 staticpro (&Qwindow_system);
4217 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4218 staticpro (&Qface_set_after_frame_default);
4220 Qfullwidth = intern ("fullwidth");
4221 staticpro (&Qfullwidth);
4222 Qfullheight = intern ("fullheight");
4223 staticpro (&Qfullheight);
4224 Qfullboth = intern ("fullboth");
4225 staticpro (&Qfullboth);
4226 Qx_resource_name = intern ("x-resource-name");
4227 staticpro (&Qx_resource_name);
4229 Qx_frame_parameter = intern ("x-frame-parameter");
4230 staticpro (&Qx_frame_parameter);
4232 Qdisplay_id = intern ("display-id");
4233 staticpro (&Qdisplay_id);
4234 Qdisplay_live_p = intern ("display-live-p");
4235 staticpro (&Qdisplay_live_p);
4238 int i;
4240 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4242 Lisp_Object v = intern (frame_parms[i].name);
4243 if (frame_parms[i].variable)
4245 *frame_parms[i].variable = v;
4246 staticpro (frame_parms[i].variable);
4248 Fput (v, Qx_frame_parameter, make_number (i));
4252 #ifdef HAVE_WINDOW_SYSTEM
4253 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4254 doc: /* The name Emacs uses to look up X resources.
4255 `x-get-resource' uses this as the first component of the instance name
4256 when requesting resource values.
4257 Emacs initially sets `x-resource-name' to the name under which Emacs
4258 was invoked, or to the value specified with the `-name' or `-rn'
4259 switches, if present.
4261 It may be useful to bind this variable locally around a call
4262 to `x-get-resource'. See also the variable `x-resource-class'. */);
4263 Vx_resource_name = Qnil;
4265 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4266 doc: /* The class Emacs uses to look up X resources.
4267 `x-get-resource' uses this as the first component of the instance class
4268 when requesting resource values.
4270 Emacs initially sets `x-resource-class' to "Emacs".
4272 Setting this variable permanently is not a reasonable thing to do,
4273 but binding this variable locally around a call to `x-get-resource'
4274 is a reasonable practice. See also the variable `x-resource-name'. */);
4275 Vx_resource_class = build_string (EMACS_CLASS);
4276 #endif
4278 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4279 doc: /* Alist of default values for frame creation.
4280 These may be set in your init file, like this:
4281 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4282 These override values given in window system configuration data,
4283 including X Windows' defaults database.
4284 For values specific to the first Emacs frame, see `initial-frame-alist'.
4285 For values specific to the separate minibuffer frame, see
4286 `minibuffer-frame-alist'.
4287 The `menu-bar-lines' element of the list controls whether new frames
4288 have menu bars; `menu-bar-mode' works by altering this element.
4289 Setting this variable does not affect existing frames, only new ones. */);
4290 Vdefault_frame_alist = Qnil;
4292 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4293 doc: /* Default position of scroll bars on this window-system. */);
4294 #ifdef HAVE_WINDOW_SYSTEM
4295 #if defined(HAVE_NTGUI) || defined(MAC_OS)
4296 /* MS-Windows has scroll bars on the right by default. */
4297 Vdefault_frame_scroll_bars = Qright;
4298 #else
4299 Vdefault_frame_scroll_bars = Qleft;
4300 #endif
4301 #else
4302 Vdefault_frame_scroll_bars = Qnil;
4303 #endif
4305 Qinhibit_default_face_x_resources
4306 = intern ("inhibit-default-face-x-resources");
4307 staticpro (&Qinhibit_default_face_x_resources);
4309 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4310 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4312 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4313 doc: /* Non-nil if all of emacs is iconified and frame updates are not needed. */);
4314 Vemacs_iconified = Qnil;
4316 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4317 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4318 `mouse-position' calls this function, passing its usual return value as
4319 argument, and returns whatever this function returns.
4320 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4321 which need to do mouse handling at the Lisp level. */);
4322 Vmouse_position_function = Qnil;
4324 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4325 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4326 If the value is an integer, highlighting is only shown after moving the
4327 mouse, while keyboard input turns off the highlight even when the mouse
4328 is over the clickable text. However, the mouse shape still indicates
4329 when the mouse is over clickable text. */);
4330 Vmouse_highlight = Qt;
4332 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4333 doc: /* Functions to be run before deleting a frame.
4334 The functions are run with one arg, the frame to be deleted.
4335 See `delete-frame'. */);
4336 Vdelete_frame_functions = Qnil;
4338 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4339 doc: /* Minibufferless frames use this frame's minibuffer.
4341 Emacs cannot create minibufferless frames unless this is set to an
4342 appropriate surrogate.
4344 Emacs consults this variable only when creating minibufferless
4345 frames; once the frame is created, it sticks with its assigned
4346 minibuffer, no matter what this variable is set to. This means that
4347 this variable doesn't necessarily say anything meaningful about the
4348 current set of frames, or where the minibuffer is currently being
4349 displayed.
4351 This variable is local to the current terminal and cannot be buffer-local. */);
4353 staticpro (&Vframe_list);
4355 defsubr (&Sactive_minibuffer_window);
4356 defsubr (&Sframep);
4357 defsubr (&Sframe_live_p);
4358 defsubr (&Swindow_system);
4359 defsubr (&Smake_terminal_frame);
4360 defsubr (&Shandle_switch_frame);
4361 defsubr (&Sselect_frame);
4362 defsubr (&Sselected_frame);
4363 defsubr (&Swindow_frame);
4364 defsubr (&Sframe_root_window);
4365 defsubr (&Sframe_first_window);
4366 defsubr (&Sframe_selected_window);
4367 defsubr (&Sset_frame_selected_window);
4368 defsubr (&Sframe_display);
4369 defsubr (&Sframe_list);
4370 defsubr (&Snext_frame);
4371 defsubr (&Sprevious_frame);
4372 defsubr (&Sdelete_frame);
4373 defsubr (&Smouse_position);
4374 defsubr (&Smouse_pixel_position);
4375 defsubr (&Sset_mouse_position);
4376 defsubr (&Sset_mouse_pixel_position);
4377 #if 0
4378 defsubr (&Sframe_configuration);
4379 defsubr (&Srestore_frame_configuration);
4380 #endif
4381 defsubr (&Smake_frame_visible);
4382 defsubr (&Smake_frame_invisible);
4383 defsubr (&Siconify_frame);
4384 defsubr (&Sframe_visible_p);
4385 defsubr (&Svisible_frame_list);
4386 defsubr (&Sraise_frame);
4387 defsubr (&Slower_frame);
4388 defsubr (&Sredirect_frame_focus);
4389 defsubr (&Sframe_focus);
4390 defsubr (&Sframe_parameters);
4391 defsubr (&Sframe_parameter);
4392 defsubr (&Smodify_frame_parameters);
4393 defsubr (&Sframe_char_height);
4394 defsubr (&Sframe_char_width);
4395 defsubr (&Sframe_pixel_height);
4396 defsubr (&Sframe_pixel_width);
4397 defsubr (&Sset_frame_height);
4398 defsubr (&Sset_frame_width);
4399 defsubr (&Sset_frame_size);
4400 defsubr (&Sset_frame_position);
4402 #ifdef HAVE_WINDOW_SYSTEM
4403 defsubr (&Sx_get_resource);
4404 defsubr (&Sx_parse_geometry);
4405 #endif
4409 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4410 (do not change this comment) */