Fix segfault by `C-x 5 2' on the controlling tty. (Reported by Suresh Madhu.)
[emacs.git] / src / frame.c
blobac7fc5912e84c6b7396ea19a18a7a1ce24cacbc6
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #include <config.h>
24 #include <stdio.h>
25 #include "lisp.h"
26 #include "charset.h"
27 #ifdef HAVE_X_WINDOWS
28 #include "xterm.h"
29 #endif
30 #ifdef WINDOWSNT
31 #include "w32term.h"
32 #endif
33 #ifdef MAC_OS
34 #include "macterm.h"
35 #endif
36 #include "buffer.h"
37 /* These help us bind and responding to switch-frame events. */
38 #include "commands.h"
39 #include "keyboard.h"
40 #include "frame.h"
41 #ifdef HAVE_WINDOW_SYSTEM
42 #include "fontset.h"
43 #endif
44 #include "blockinput.h"
45 #include "termchar.h"
46 #include "termhooks.h"
47 #include "dispextern.h"
48 #include "window.h"
49 #ifdef MSDOS
50 #include "msdos.h"
51 #include "dosfns.h"
52 #endif
55 #ifdef HAVE_WINDOW_SYSTEM
57 /* The name we're using in resource queries. Most often "emacs". */
59 Lisp_Object Vx_resource_name;
61 /* The application class we're using in resource queries.
62 Normally "Emacs". */
64 Lisp_Object Vx_resource_class;
66 #endif
68 Lisp_Object Qframep, Qframe_live_p;
69 Lisp_Object Qicon, Qmodeline;
70 Lisp_Object Qonly;
71 Lisp_Object Qx, Qw32, Qmac, Qpc;
72 Lisp_Object Qvisible;
73 Lisp_Object Qdisplay_type;
74 Lisp_Object Qbackground_mode;
75 Lisp_Object Qinhibit_default_face_x_resources;
77 Lisp_Object Qx_frame_parameter;
78 Lisp_Object Qx_resource_name;
79 Lisp_Object Qterminal;
80 Lisp_Object Qterminal_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, Qburied_buffer_list;
111 Lisp_Object Qtty_color_mode;
112 Lisp_Object Qtty, Qtty_type;
113 Lisp_Object Qwindow_system;
114 Lisp_Object Qenvironment;
116 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
118 Lisp_Object Qface_set_after_frame_default;
120 Lisp_Object Vterminal_frame;
121 Lisp_Object Vdefault_frame_alist;
122 Lisp_Object Vdefault_frame_scroll_bars;
123 Lisp_Object Vmouse_position_function;
124 Lisp_Object Vmouse_highlight;
125 Lisp_Object Vdelete_frame_functions;
127 static void
128 set_menu_bar_lines_1 (window, n)
129 Lisp_Object window;
130 int n;
132 struct window *w = XWINDOW (window);
134 XSETFASTINT (w->last_modified, 0);
135 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
136 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
138 if (INTEGERP (w->orig_top_line))
139 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
140 if (INTEGERP (w->orig_total_lines))
141 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
143 /* Handle just the top child in a vertical split. */
144 if (!NILP (w->vchild))
145 set_menu_bar_lines_1 (w->vchild, n);
147 /* Adjust all children in a horizontal split. */
148 for (window = w->hchild; !NILP (window); window = w->next)
150 w = XWINDOW (window);
151 set_menu_bar_lines_1 (window, n);
155 void
156 set_menu_bar_lines (f, value, oldval)
157 struct frame *f;
158 Lisp_Object value, oldval;
160 int nlines;
161 int olines = FRAME_MENU_BAR_LINES (f);
163 /* Right now, menu bars don't work properly in minibuf-only frames;
164 most of the commands try to apply themselves to the minibuffer
165 frame itself, and get an error because you can't switch buffers
166 in or split the minibuffer window. */
167 if (FRAME_MINIBUF_ONLY_P (f))
168 return;
170 if (INTEGERP (value))
171 nlines = XINT (value);
172 else
173 nlines = 0;
175 if (nlines != olines)
177 windows_or_buffers_changed++;
178 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
179 FRAME_MENU_BAR_LINES (f) = nlines;
180 set_menu_bar_lines_1 (f->root_window, nlines - olines);
181 adjust_glyphs (f);
185 Lisp_Object Vemacs_iconified;
186 Lisp_Object Vframe_list;
188 extern Lisp_Object Vminibuffer_list;
189 extern Lisp_Object get_minibuffer ();
190 extern Lisp_Object Fhandle_switch_frame ();
191 extern Lisp_Object Fredirect_frame_focus ();
192 extern Lisp_Object x_get_focus_frame ();
194 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
195 doc: /* Return non-nil if OBJECT is a frame.
196 Value is t for a termcap frame (a character-only terminal),
197 `x' for an Emacs frame that is really an X window,
198 `w32' for an Emacs frame that is a window on MS-Windows display,
199 `mac' for an Emacs frame on a Macintosh display,
200 `pc' for a direct-write MS-DOS frame.
201 See also `frame-live-p'. */)
202 (object)
203 Lisp_Object object;
205 if (!FRAMEP (object))
206 return Qnil;
207 switch (XFRAME (object)->output_method)
209 case output_initial: /* The initial frame is like a termcap frame. */
210 case output_termcap:
211 return Qt;
212 case output_x_window:
213 return Qx;
214 case output_w32:
215 return Qw32;
216 case output_msdos_raw:
217 return Qpc;
218 case output_mac:
219 return Qmac;
220 default:
221 abort ();
225 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
226 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
227 Value is nil if OBJECT is not a live frame. If object is a live
228 frame, the return value indicates what sort of terminal device it is
229 displayed on. See the documentation of `framep' for possible
230 return values. */)
231 (object)
232 Lisp_Object object;
234 return ((FRAMEP (object)
235 && FRAME_LIVE_P (XFRAME (object)))
236 ? Fframep (object)
237 : Qnil);
240 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
241 doc: /* The name of the window system that FRAME is displaying through.
242 The value is a symbol---for instance, 'x' for X windows.
243 The value is nil if Emacs is using a text-only terminal.
245 FRAME defaults to the currently selected frame. */)
246 (frame)
247 Lisp_Object frame;
249 Lisp_Object type;
250 if (NILP (frame))
251 frame = selected_frame;
253 type = Fframep (frame);
255 if (NILP (type))
256 wrong_type_argument (Qframep, frame);
258 if (EQ (type, Qt))
259 return Qnil;
260 else
261 return type;
264 struct frame *
265 make_frame (mini_p)
266 int mini_p;
268 Lisp_Object frame;
269 register struct frame *f;
270 register Lisp_Object root_window;
271 register Lisp_Object mini_window;
273 f = allocate_frame ();
274 XSETFRAME (frame, f);
276 f->desired_matrix = 0;
277 f->current_matrix = 0;
278 f->desired_pool = 0;
279 f->current_pool = 0;
280 f->glyphs_initialized_p = 0;
281 f->decode_mode_spec_buffer = 0;
282 f->visible = 0;
283 f->async_visible = 0;
284 f->output_data.nothing = 0;
285 f->iconified = 0;
286 f->async_iconified = 0;
287 f->wants_modeline = 1;
288 f->auto_raise = 0;
289 f->auto_lower = 0;
290 f->no_split = 0;
291 f->garbaged = 1;
292 f->has_minibuffer = mini_p;
293 f->focus_frame = Qnil;
294 f->explicit_name = 0;
295 f->can_have_scroll_bars = 0;
296 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
297 f->param_alist = Qnil;
298 f->scroll_bars = Qnil;
299 f->condemned_scroll_bars = Qnil;
300 f->face_alist = Qnil;
301 f->face_cache = NULL;
302 f->menu_bar_items = Qnil;
303 f->menu_bar_vector = Qnil;
304 f->menu_bar_items_used = 0;
305 f->buffer_predicate = Qnil;
306 f->buffer_list = Qnil;
307 f->buried_buffer_list = Qnil;
308 f->namebuf = 0;
309 f->title = Qnil;
310 f->menu_bar_window = Qnil;
311 f->tool_bar_window = Qnil;
312 f->tool_bar_items = Qnil;
313 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
314 f->n_tool_bar_items = 0;
315 f->left_fringe_width = f->right_fringe_width = 0;
316 f->fringe_cols = 0;
317 f->scroll_bar_actual_width = 0;
318 f->border_width = 0;
319 f->internal_border_width = 0;
320 f->column_width = 1; /* !FRAME_WINDOW_P value */
321 f->line_height = 1; /* !FRAME_WINDOW_P value */
322 f->x_pixels_diff = f->y_pixels_diff = 0;
323 #ifdef HAVE_WINDOW_SYSTEM
324 f->want_fullscreen = FULLSCREEN_NONE;
325 #endif
326 f->size_hint_flags = 0;
327 f->win_gravity = 0;
329 root_window = make_window ();
330 if (mini_p)
332 mini_window = make_window ();
333 XWINDOW (root_window)->next = mini_window;
334 XWINDOW (mini_window)->prev = root_window;
335 XWINDOW (mini_window)->mini_p = Qt;
336 XWINDOW (mini_window)->frame = frame;
337 f->minibuffer_window = mini_window;
339 else
341 mini_window = Qnil;
342 XWINDOW (root_window)->next = Qnil;
343 f->minibuffer_window = Qnil;
346 XWINDOW (root_window)->frame = frame;
348 /* 10 is arbitrary,
349 just so that there is "something there."
350 Correct size will be set up later with change_frame_size. */
352 SET_FRAME_COLS (f, 10);
353 FRAME_LINES (f) = 10;
355 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
356 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
358 if (mini_p)
360 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
361 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
362 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
365 /* Choose a buffer for the frame's root window. */
367 Lisp_Object buf;
369 XWINDOW (root_window)->buffer = Qt;
370 buf = Fcurrent_buffer ();
371 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
372 a space), try to find another one. */
373 if (SREF (Fbuffer_name (buf), 0) == ' ')
374 buf = Fother_buffer (buf, Qnil, Qnil);
376 /* Use set_window_buffer, not Fset_window_buffer, and don't let
377 hooks be run by it. The reason is that the whole frame/window
378 arrangement is not yet fully intialized at this point. Windows
379 don't have the right size, glyph matrices aren't initialized
380 etc. Running Lisp functions at this point surely ends in a
381 SEGV. */
382 set_window_buffer (root_window, buf, 0, 0);
383 f->buffer_list = Fcons (buf, Qnil);
386 if (mini_p)
388 XWINDOW (mini_window)->buffer = Qt;
389 set_window_buffer (mini_window,
390 (NILP (Vminibuffer_list)
391 ? get_minibuffer (0)
392 : Fcar (Vminibuffer_list)),
393 0, 0);
396 f->root_window = root_window;
397 f->selected_window = root_window;
398 /* Make sure this window seems more recently used than
399 a newly-created, never-selected window. */
400 ++window_select_count;
401 XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
403 f->default_face_done_p = 0;
405 return f;
408 #ifdef HAVE_WINDOW_SYSTEM
409 /* Make a frame using a separate minibuffer window on another frame.
410 MINI_WINDOW is the minibuffer window to use. nil means use the
411 default (the global minibuffer). */
413 struct frame *
414 make_frame_without_minibuffer (mini_window, kb, display)
415 register Lisp_Object mini_window;
416 KBOARD *kb;
417 Lisp_Object display;
419 register struct frame *f;
420 struct gcpro gcpro1;
422 if (!NILP (mini_window))
423 CHECK_LIVE_WINDOW (mini_window);
425 #ifdef MULTI_KBOARD
426 if (!NILP (mini_window)
427 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
428 error ("Frame and minibuffer must be on the same terminal");
429 #endif
431 /* Make a frame containing just a root window. */
432 f = make_frame (0);
434 if (NILP (mini_window))
436 /* Use default-minibuffer-frame if possible. */
437 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
438 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
440 Lisp_Object frame_dummy;
442 XSETFRAME (frame_dummy, f);
443 GCPRO1 (frame_dummy);
444 /* If there's no minibuffer frame to use, create one. */
445 kb->Vdefault_minibuffer_frame =
446 call1 (intern ("make-initial-minibuffer-frame"), display);
447 UNGCPRO;
450 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
453 f->minibuffer_window = mini_window;
455 /* Make the chosen minibuffer window display the proper minibuffer,
456 unless it is already showing a minibuffer. */
457 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
458 Fset_window_buffer (mini_window,
459 (NILP (Vminibuffer_list)
460 ? get_minibuffer (0)
461 : Fcar (Vminibuffer_list)), Qnil);
462 return f;
465 /* Make a frame containing only a minibuffer window. */
467 struct frame *
468 make_minibuffer_frame ()
470 /* First make a frame containing just a root window, no minibuffer. */
472 register struct frame *f = make_frame (0);
473 register Lisp_Object mini_window;
474 register Lisp_Object frame;
476 XSETFRAME (frame, f);
478 f->auto_raise = 0;
479 f->auto_lower = 0;
480 f->no_split = 1;
481 f->wants_modeline = 0;
482 f->has_minibuffer = 1;
484 /* Now label the root window as also being the minibuffer.
485 Avoid infinite looping on the window chain by marking next pointer
486 as nil. */
488 mini_window = f->minibuffer_window = f->root_window;
489 XWINDOW (mini_window)->mini_p = Qt;
490 XWINDOW (mini_window)->next = Qnil;
491 XWINDOW (mini_window)->prev = Qnil;
492 XWINDOW (mini_window)->frame = frame;
494 /* Put the proper buffer in that window. */
496 Fset_window_buffer (mini_window,
497 (NILP (Vminibuffer_list)
498 ? get_minibuffer (0)
499 : Fcar (Vminibuffer_list)), Qnil);
500 return f;
502 #endif /* HAVE_WINDOW_SYSTEM */
504 /* Construct a frame that refers to a terminal. */
506 static int tty_frame_count;
508 struct frame *
509 make_initial_frame (void)
511 struct frame *f;
512 struct terminal *terminal;
513 Lisp_Object frame;
515 #ifdef MULTI_KBOARD
516 /* Create the initial keyboard. */
517 if (!initial_kboard)
519 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
520 init_kboard (initial_kboard);
521 initial_kboard->next_kboard = all_kboards;
522 all_kboards = initial_kboard;
524 #endif
526 /* The first call must initialize Vframe_list. */
527 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
528 Vframe_list = Qnil;
530 terminal = init_initial_terminal ();
532 f = make_frame (1);
533 XSETFRAME (frame, f);
535 Vframe_list = Fcons (frame, Vframe_list);
537 tty_frame_count = 1;
538 f->name = build_string ("F1");
540 f->visible = 1;
541 f->async_visible = 1;
543 f->output_method = terminal->type;
544 f->terminal = terminal;
545 f->terminal->reference_count++;
546 f->output_data.nothing = 0;
548 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
549 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
551 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
552 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
554 return f;
558 struct frame *
559 make_terminal_frame (struct terminal *terminal)
561 register struct frame *f;
562 Lisp_Object frame;
563 char name[20];
565 f = make_frame (1);
567 XSETFRAME (frame, f);
568 Vframe_list = Fcons (frame, Vframe_list);
570 tty_frame_count++;
571 sprintf (name, "F%d", tty_frame_count);
572 f->name = build_string (name);
574 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
575 f->async_visible = 1; /* Don't let visible be cleared later. */
576 #ifdef MSDOS
577 f->output_data.x = &the_only_x_display;
578 if (!inhibit_window_system
579 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
580 || XFRAME (selected_frame)->output_method == output_msdos_raw))
582 f->output_method = output_msdos_raw;
583 /* This initialization of foreground and background pixels is
584 only important for the initial frame created in temacs. If
585 we don't do that, we get black background and foreground in
586 the dumped Emacs because the_only_x_display is a static
587 variable, hence it is born all-zeroes, and zero is the code
588 for the black color. Other frames all inherit their pixels
589 from what's already in the_only_x_display. */
590 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
591 && f->output_data.x->background_pixel == 0
592 && f->output_data.x->foreground_pixel == 0)
594 f->output_data.x->background_pixel = FACE_TTY_DEFAULT_BG_COLOR;
595 f->output_data.x->foreground_pixel = FACE_TTY_DEFAULT_FG_COLOR;
598 else
599 f->output_method = output_termcap;
600 #else
601 #ifdef WINDOWSNT
602 f->output_method = output_termcap;
603 f->output_data.x = &tty_display; /* XXX ??? */
604 #else
605 #ifdef MAC_OS8
606 make_mac_terminal_frame (f);
607 #else
609 f->output_method = output_termcap;
610 f->terminal = terminal;
611 f->terminal->reference_count++;
612 create_tty_output (f);
614 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
615 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
617 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
618 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
620 /* Set the top frame to the newly created frame. */
621 if (FRAME_TTY (f)->top_frame
622 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
623 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
625 FRAME_TTY (f)->top_frame = frame;
628 #ifdef CANNOT_DUMP
629 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
630 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
631 #endif
632 #endif /* MAC_OS8 */
633 #endif /* WINDOWSNT */
634 #endif /* MSDOS */
636 if (!noninteractive)
637 init_frame_faces (f);
639 return f;
642 /* Get a suitable value for frame parameter PARAMETER for a newly
643 created frame, based on (1) the user-supplied frame parameter
644 alist SUPPLIED_PARMS, (2) CURRENT_VALUE, and finally, if all else
645 fails, (3) Vdefault_frame_alist. */
647 static Lisp_Object
648 get_future_frame_param (Lisp_Object parameter,
649 Lisp_Object supplied_parms,
650 char *current_value)
652 Lisp_Object result;
654 result = Fassq (parameter, supplied_parms);
655 if (NILP (result))
656 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
657 if (NILP (result) && current_value != NULL)
658 result = build_string (current_value);
659 if (NILP (result))
660 result = Fassq (parameter, Vdefault_frame_alist);
661 if (!NILP (result) && !STRINGP (result))
662 result = XCDR (result);
663 if (NILP (result) || !STRINGP (result))
664 result = Qnil;
666 return result;
669 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
670 1, 1, 0,
671 doc: /* Create an additional terminal frame, possibly on another terminal.
672 This function takes one argument, an alist specifying frame parameters.
674 You can create multiple frames on a single text-only terminal, but
675 only one of them (the selected terminal frame) is actually displayed.
677 In practice, generally you don't need to specify any parameters,
678 except when you want to create a new frame on another terminal.
679 In that case, the `tty' parameter specifies the device file to open,
680 and the `tty-type' parameter specifies the terminal type. Example:
682 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
684 Note that changing the size of one terminal frame automatically
685 affects all frames on the same terminal device. */)
686 (parms)
687 Lisp_Object parms;
689 struct frame *f;
690 struct terminal *t = NULL;
691 Lisp_Object frame, tem;
692 struct frame *sf = SELECTED_FRAME ();
694 #ifdef MSDOS
695 if (sf->output_method != output_msdos_raw
696 && sf->output_method != output_termcap)
697 abort ();
698 #else /* not MSDOS */
700 #ifdef MAC_OS
701 if (sf->output_method != output_mac)
702 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
703 #else
704 #if 0 /* This should work now! */
705 if (sf->output_method != output_termcap)
706 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
707 #endif
708 #endif
709 #endif /* not MSDOS */
712 Lisp_Object terminal;
714 terminal = Fassq (Qterminal, parms);
715 if (!NILP (terminal))
717 terminal = XCDR (terminal);
718 t = get_terminal (terminal, 1);
722 if (!t)
724 char *name = 0, *type = 0;
725 Lisp_Object tty, tty_type;
727 tty = get_future_frame_param
728 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
729 ? FRAME_TTY (XFRAME (selected_frame))->name
730 : NULL));
731 if (!NILP (tty))
733 name = (char *) alloca (SBYTES (tty) + 1);
734 strncpy (name, SDATA (tty), SBYTES (tty));
735 name[SBYTES (tty)] = 0;
738 tty_type = get_future_frame_param
739 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
740 ? FRAME_TTY (XFRAME (selected_frame))->type
741 : NULL));
742 if (!NILP (tty_type))
744 type = (char *) alloca (SBYTES (tty_type) + 1);
745 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
746 type[SBYTES (tty_type)] = 0;
749 t = init_tty (name, type, 0); /* Errors are not fatal. */
752 f = make_terminal_frame (t);
755 int width, height;
756 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
757 change_frame_size (f, height, width, 0, 0, 0);
760 adjust_glyphs (f);
761 calculate_costs (f);
762 XSETFRAME (frame, f);
763 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
764 Fmodify_frame_parameters (frame, parms);
765 Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qnil), Qnil));
766 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
767 build_string (t->display_info.tty->type)),
768 Qnil));
769 if (t->display_info.tty->name != NULL)
770 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
771 build_string (t->display_info.tty->name)),
772 Qnil));
773 else
774 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
776 /* Make the frame face alist be frame-specific, so that each
777 frame could change its face definitions independently. */
778 f->face_alist = Fcopy_alist (sf->face_alist);
779 /* Simple Fcopy_alist isn't enough, because we need the contents of
780 the vectors which are the CDRs of associations in face_alist to
781 be copied as well. */
782 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
783 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
784 return frame;
788 /* Perform the switch to frame FRAME.
790 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
791 FRAME1 as frame.
793 If TRACK is non-zero and the frame that currently has the focus
794 redirects its focus to the selected frame, redirect that focused
795 frame's focus to FRAME instead.
797 FOR_DELETION non-zero means that the selected frame is being
798 deleted, which includes the possibility that the frame's terminal
799 is dead. */
801 Lisp_Object
802 do_switch_frame (frame, track, for_deletion)
803 Lisp_Object frame;
804 int track, for_deletion;
806 struct frame *sf = SELECTED_FRAME ();
808 /* If FRAME is a switch-frame event, extract the frame we should
809 switch to. */
810 if (CONSP (frame)
811 && EQ (XCAR (frame), Qswitch_frame)
812 && CONSP (XCDR (frame)))
813 frame = XCAR (XCDR (frame));
815 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
816 a switch-frame event to arrive after a frame is no longer live,
817 especially when deleting the initial frame during startup. */
818 CHECK_FRAME (frame);
819 if (! FRAME_LIVE_P (XFRAME (frame)))
820 return Qnil;
822 if (sf == XFRAME (frame))
823 return frame;
825 /* This is too greedy; it causes inappropriate focus redirection
826 that's hard to get rid of. */
827 #if 0
828 /* If a frame's focus has been redirected toward the currently
829 selected frame, we should change the redirection to point to the
830 newly selected frame. This means that if the focus is redirected
831 from a minibufferless frame to a surrogate minibuffer frame, we
832 can use `other-window' to switch between all the frames using
833 that minibuffer frame, and the focus redirection will follow us
834 around. */
835 if (track)
837 Lisp_Object tail;
839 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
841 Lisp_Object focus;
843 if (!FRAMEP (XCAR (tail)))
844 abort ();
846 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
848 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
849 Fredirect_frame_focus (XCAR (tail), frame);
852 #else /* ! 0 */
853 /* Instead, apply it only to the frame we're pointing to. */
854 #ifdef HAVE_WINDOW_SYSTEM
855 if (track && FRAME_WINDOW_P (XFRAME (frame)))
857 Lisp_Object focus, xfocus;
859 xfocus = x_get_focus_frame (XFRAME (frame));
860 if (FRAMEP (xfocus))
862 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
863 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
864 Fredirect_frame_focus (xfocus, frame);
867 #endif /* HAVE_X_WINDOWS */
868 #endif /* ! 0 */
870 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
871 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
873 if (FRAME_TERMCAP_P (XFRAME (selected_frame))
874 && FRAME_TERMCAP_P (XFRAME (frame))
875 && FRAME_TTY (XFRAME (selected_frame)) == FRAME_TTY (XFRAME (frame)))
877 XFRAME (selected_frame)->async_visible = 2; /* obscured */
878 XFRAME (frame)->async_visible = 1;
879 FRAME_TTY (XFRAME (frame))->top_frame = frame;
882 selected_frame = frame;
883 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
884 last_nonminibuf_frame = XFRAME (selected_frame);
886 Fselect_window (XFRAME (frame)->selected_window, Qnil);
888 #ifndef WINDOWSNT
889 /* Make sure to switch the tty color mode to that of the newly
890 selected frame. */
891 sf = SELECTED_FRAME ();
892 if (FRAME_TERMCAP_P (sf))
894 Lisp_Object color_mode_spec, color_mode;
896 color_mode_spec = assq_no_quit (Qtty_color_mode, sf->param_alist);
897 if (CONSP (color_mode_spec))
898 color_mode = XCDR (color_mode_spec);
899 else
900 color_mode = make_number (0);
901 set_tty_color_mode (sf, color_mode);
903 #endif /* !WINDOWSNT */
905 /* We want to make sure that the next event generates a frame-switch
906 event to the appropriate frame. This seems kludgy to me, but
907 before you take it out, make sure that evaluating something like
908 (select-window (frame-root-window (new-frame))) doesn't end up
909 with your typing being interpreted in the new frame instead of
910 the one you're actually typing in. */
911 internal_last_event_frame = Qnil;
913 return frame;
916 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 1, "e",
917 doc: /* Select the frame FRAME.
918 Subsequent editing commands apply to its selected window.
919 The selection of FRAME lasts until the next time the user does
920 something to select a different frame, or until the next time this
921 function is called. If you are using a window system, the previously
922 selected frame may be restored as the selected frame after return to
923 the command loop, because it still may have the window system's input
924 focus. On a text-only terminal, the next redisplay will display FRAME.
926 This function returns FRAME, or nil if FRAME has been deleted. */)
927 (frame)
928 Lisp_Object frame;
930 return do_switch_frame (frame, 1, 0);
934 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
935 doc: /* Handle a switch-frame event EVENT.
936 Switch-frame events are usually bound to this function.
937 A switch-frame event tells Emacs that the window manager has requested
938 that the user's events be directed to the frame mentioned in the event.
939 This function selects the selected window of the frame of EVENT.
941 If EVENT is frame object, handle it as if it were a switch-frame event
942 to that frame. */)
943 (event)
944 Lisp_Object event;
946 /* Preserve prefix arg that the command loop just cleared. */
947 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
948 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
949 return do_switch_frame (event, 0, 0);
952 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
953 doc: /* Return the frame that is now selected. */)
956 return selected_frame;
959 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
960 doc: /* Return the frame object that window WINDOW is on. */)
961 (window)
962 Lisp_Object window;
964 CHECK_LIVE_WINDOW (window);
965 return XWINDOW (window)->frame;
968 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
969 doc: /* Returns the topmost, leftmost window of FRAME.
970 If omitted, FRAME defaults to the currently selected frame. */)
971 (frame)
972 Lisp_Object frame;
974 Lisp_Object w;
976 if (NILP (frame))
977 w = SELECTED_FRAME ()->root_window;
978 else
980 CHECK_LIVE_FRAME (frame);
981 w = XFRAME (frame)->root_window;
983 while (NILP (XWINDOW (w)->buffer))
985 if (! NILP (XWINDOW (w)->hchild))
986 w = XWINDOW (w)->hchild;
987 else if (! NILP (XWINDOW (w)->vchild))
988 w = XWINDOW (w)->vchild;
989 else
990 abort ();
992 return w;
995 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
996 Sactive_minibuffer_window, 0, 0, 0,
997 doc: /* Return the currently active minibuffer window, or nil if none. */)
1000 return minibuf_level ? minibuf_window : Qnil;
1003 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
1004 doc: /* Returns the root-window of FRAME.
1005 If omitted, FRAME defaults to the currently selected frame. */)
1006 (frame)
1007 Lisp_Object frame;
1009 Lisp_Object window;
1011 if (NILP (frame))
1012 window = SELECTED_FRAME ()->root_window;
1013 else
1015 CHECK_LIVE_FRAME (frame);
1016 window = XFRAME (frame)->root_window;
1019 return window;
1022 DEFUN ("frame-selected-window", Fframe_selected_window,
1023 Sframe_selected_window, 0, 1, 0,
1024 doc: /* Return the selected window of frame object FRAME.
1025 If omitted, FRAME defaults to the currently selected frame. */)
1026 (frame)
1027 Lisp_Object frame;
1029 Lisp_Object window;
1031 if (NILP (frame))
1032 window = SELECTED_FRAME ()->selected_window;
1033 else
1035 CHECK_LIVE_FRAME (frame);
1036 window = XFRAME (frame)->selected_window;
1039 return window;
1042 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
1043 Sset_frame_selected_window, 2, 2, 0,
1044 doc: /* Set the selected window of frame object FRAME to WINDOW.
1045 Return WINDOW.
1046 If FRAME is nil, the selected frame is used.
1047 If FRAME is the selected frame, this makes WINDOW the selected window. */)
1048 (frame, window)
1049 Lisp_Object frame, window;
1051 if (NILP (frame))
1052 frame = selected_frame;
1054 CHECK_LIVE_FRAME (frame);
1055 CHECK_LIVE_WINDOW (window);
1057 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
1058 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
1060 if (EQ (frame, selected_frame))
1061 return Fselect_window (window, Qnil);
1063 return XFRAME (frame)->selected_window = window;
1067 DEFUN ("frame-list", Fframe_list, Sframe_list,
1068 0, 0, 0,
1069 doc: /* Return a list of all frames. */)
1072 Lisp_Object frames;
1073 frames = Fcopy_sequence (Vframe_list);
1074 #ifdef HAVE_WINDOW_SYSTEM
1075 if (FRAMEP (tip_frame))
1076 frames = Fdelq (tip_frame, frames);
1077 #endif
1078 return frames;
1081 /* Return the next frame in the frame list after FRAME.
1082 If MINIBUF is nil, exclude minibuffer-only frames.
1083 If MINIBUF is a window, include only its own frame
1084 and any frame now using that window as the minibuffer.
1085 If MINIBUF is `visible', include all visible frames.
1086 If MINIBUF is 0, include all visible and iconified frames.
1087 Otherwise, include all frames. */
1089 static Lisp_Object
1090 next_frame (frame, minibuf)
1091 Lisp_Object frame;
1092 Lisp_Object minibuf;
1094 Lisp_Object tail;
1095 int passed = 0;
1097 /* There must always be at least one frame in Vframe_list. */
1098 if (! CONSP (Vframe_list))
1099 abort ();
1101 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
1102 forever. Forestall that. */
1103 CHECK_LIVE_FRAME (frame);
1105 while (1)
1106 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1108 Lisp_Object f;
1110 f = XCAR (tail);
1112 if (passed
1113 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1114 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1115 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1116 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
1118 /* Decide whether this frame is eligible to be returned. */
1120 /* If we've looped all the way around without finding any
1121 eligible frames, return the original frame. */
1122 if (EQ (f, frame))
1123 return f;
1125 /* Let minibuf decide if this frame is acceptable. */
1126 if (NILP (minibuf))
1128 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1129 return f;
1131 else if (EQ (minibuf, Qvisible))
1133 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1134 if (FRAME_VISIBLE_P (XFRAME (f)))
1135 return f;
1137 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1139 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1140 if (FRAME_VISIBLE_P (XFRAME (f))
1141 || FRAME_ICONIFIED_P (XFRAME (f)))
1142 return f;
1144 else if (WINDOWP (minibuf))
1146 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1147 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1148 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1149 FRAME_FOCUS_FRAME (XFRAME (f))))
1150 return f;
1152 else
1153 return f;
1156 if (EQ (frame, f))
1157 passed++;
1161 /* Return the previous frame in the frame list before FRAME.
1162 If MINIBUF is nil, exclude minibuffer-only frames.
1163 If MINIBUF is a window, include only its own frame
1164 and any frame now using that window as the minibuffer.
1165 If MINIBUF is `visible', include all visible frames.
1166 If MINIBUF is 0, include all visible and iconified frames.
1167 Otherwise, include all frames. */
1169 static Lisp_Object
1170 prev_frame (frame, minibuf)
1171 Lisp_Object frame;
1172 Lisp_Object minibuf;
1174 Lisp_Object tail;
1175 Lisp_Object prev;
1177 /* There must always be at least one frame in Vframe_list. */
1178 if (! CONSP (Vframe_list))
1179 abort ();
1181 prev = Qnil;
1182 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1184 Lisp_Object f;
1186 f = XCAR (tail);
1187 if (!FRAMEP (f))
1188 abort ();
1190 if (EQ (frame, f) && !NILP (prev))
1191 return prev;
1193 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1194 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1195 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1196 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1198 /* Decide whether this frame is eligible to be returned,
1199 according to minibuf. */
1200 if (NILP (minibuf))
1202 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1203 prev = f;
1205 else if (WINDOWP (minibuf))
1207 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1208 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1209 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1210 FRAME_FOCUS_FRAME (XFRAME (f))))
1211 prev = f;
1213 else if (EQ (minibuf, Qvisible))
1215 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1216 if (FRAME_VISIBLE_P (XFRAME (f)))
1217 prev = f;
1219 else if (XFASTINT (minibuf) == 0)
1221 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1222 if (FRAME_VISIBLE_P (XFRAME (f))
1223 || FRAME_ICONIFIED_P (XFRAME (f)))
1224 prev = f;
1226 else
1227 prev = f;
1231 /* We've scanned the entire list. */
1232 if (NILP (prev))
1233 /* We went through the whole frame list without finding a single
1234 acceptable frame. Return the original frame. */
1235 return frame;
1236 else
1237 /* There were no acceptable frames in the list before FRAME; otherwise,
1238 we would have returned directly from the loop. Since PREV is the last
1239 acceptable frame in the list, return it. */
1240 return prev;
1244 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1245 doc: /* Return the next frame in the frame list after FRAME.
1246 It considers only frames on the same terminal as FRAME.
1247 By default, skip minibuffer-only frames.
1248 If omitted, FRAME defaults to the selected frame.
1249 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1250 If MINIFRAME is a window, include only its own frame
1251 and any frame now using that window as the minibuffer.
1252 If MINIFRAME is `visible', include all visible frames.
1253 If MINIFRAME is 0, include all visible and iconified frames.
1254 Otherwise, include all frames. */)
1255 (frame, miniframe)
1256 Lisp_Object frame, miniframe;
1258 if (NILP (frame))
1259 frame = selected_frame;
1261 CHECK_LIVE_FRAME (frame);
1262 return next_frame (frame, miniframe);
1265 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1266 doc: /* Return the previous frame in the frame list before FRAME.
1267 It considers only frames on the same terminal as FRAME.
1268 By default, skip minibuffer-only frames.
1269 If omitted, FRAME defaults to the selected frame.
1270 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1271 If MINIFRAME is a window, include only its own frame
1272 and any frame now using that window as the minibuffer.
1273 If MINIFRAME is `visible', include all visible frames.
1274 If MINIFRAME is 0, include all visible and iconified frames.
1275 Otherwise, include all frames. */)
1276 (frame, miniframe)
1277 Lisp_Object frame, miniframe;
1279 if (NILP (frame))
1280 frame = selected_frame;
1281 CHECK_LIVE_FRAME (frame);
1282 return prev_frame (frame, miniframe);
1285 /* Return 1 if it is ok to delete frame F;
1286 0 if all frames aside from F are invisible.
1287 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1290 other_visible_frames (f)
1291 FRAME_PTR f;
1293 /* We know the selected frame is visible,
1294 so if F is some other frame, it can't be the sole visible one. */
1295 if (f == SELECTED_FRAME ())
1297 Lisp_Object frames;
1298 int count = 0;
1300 for (frames = Vframe_list;
1301 CONSP (frames);
1302 frames = XCDR (frames))
1304 Lisp_Object this;
1306 this = XCAR (frames);
1307 /* Verify that the frame's window still exists
1308 and we can still talk to it. And note any recent change
1309 in visibility. */
1310 #ifdef HAVE_WINDOW_SYSTEM
1311 if (FRAME_WINDOW_P (XFRAME (this)))
1313 x_sync (XFRAME (this));
1314 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1316 #endif
1318 if (FRAME_VISIBLE_P (XFRAME (this))
1319 || FRAME_ICONIFIED_P (XFRAME (this))
1320 /* Allow deleting the terminal frame when at least
1321 one X frame exists! */
1322 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1323 count++;
1325 return count > 1;
1327 return 1;
1330 /* Error handler for `delete-frame-functions'. */
1331 static Lisp_Object
1332 delete_frame_handler (Lisp_Object arg)
1334 add_to_log ("Error during `delete-frame': %s", arg, Qnil);
1335 return Qnil;
1338 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1339 doc: /* Delete FRAME, permanently eliminating it from use.
1340 If omitted, FRAME defaults to the selected frame.
1341 A frame may not be deleted if its minibuffer is used by other frames.
1342 Normally, you may not delete a frame if all other frames are invisible,
1343 but if the second optional argument FORCE is non-nil, you may do so.
1345 This function runs `delete-frame-functions' before actually deleting the
1346 frame, unless the frame is a tooltip.
1347 The functions are run with one arg, the frame to be deleted. */)
1348 (frame, force)
1349 Lisp_Object frame, force;
1351 struct frame *f;
1352 struct frame *sf = SELECTED_FRAME ();
1353 struct kboard *kb;
1355 int minibuffer_selected;
1357 if (EQ (frame, Qnil))
1359 f = sf;
1360 XSETFRAME (frame, f);
1362 else
1364 CHECK_FRAME (frame);
1365 f = XFRAME (frame);
1368 if (! FRAME_LIVE_P (f))
1369 return Qnil;
1371 if (NILP (force) && !other_visible_frames (f)
1372 #ifdef MAC_OS8
1373 /* Terminal frame deleted before any other visible frames are
1374 created. */
1375 && strcmp (SDATA (f->name), "F1") != 0
1376 #endif
1378 error ("Attempt to delete the sole visible or iconified frame");
1380 #if 0
1381 /* This is a nice idea, but x_connection_closed needs to be able
1382 to delete the last frame, if it is gone. */
1383 if (NILP (XCDR (Vframe_list)))
1384 error ("Attempt to delete the only frame");
1385 #endif
1387 /* Does this frame have a minibuffer, and is it the surrogate
1388 minibuffer for any other frame? */
1389 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1391 Lisp_Object frames;
1393 for (frames = Vframe_list;
1394 CONSP (frames);
1395 frames = XCDR (frames))
1397 Lisp_Object this;
1398 this = XCAR (frames);
1400 if (! EQ (this, frame)
1401 && EQ (frame,
1402 WINDOW_FRAME (XWINDOW
1403 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1404 error ("Attempt to delete a surrogate minibuffer frame");
1408 /* Run `delete-frame-functions' unless frame is a tooltip. */
1409 if (!NILP (Vrun_hooks)
1410 && NILP (Fframe_parameter (frame, intern ("tooltip"))))
1412 Lisp_Object args[2];
1413 struct gcpro gcpro1, gcpro2;
1415 /* Don't let a rogue function in `delete-frame-functions'
1416 prevent the frame deletion. */
1417 GCPRO2 (args[0], args[1]);
1418 args[0] = intern ("delete-frame-functions");
1419 args[1] = frame;
1420 internal_condition_case_2 (Frun_hook_with_args, 2, args,
1421 Qt, delete_frame_handler);
1422 UNGCPRO;
1425 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1426 if (! FRAME_LIVE_P (f))
1427 return Qnil;
1429 minibuffer_selected = EQ (minibuf_window, selected_window);
1431 /* Don't let the frame remain selected. */
1432 if (f == sf)
1434 Lisp_Object tail, frame1;
1436 /* Look for another visible frame on the same terminal. */
1437 frame1 = next_frame (frame, Qvisible);
1439 /* If there is none, find *some* other frame. */
1440 if (NILP (frame1) || EQ (frame1, frame))
1442 FOR_EACH_FRAME (tail, frame1)
1444 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1445 break;
1449 do_switch_frame (frame1, 0, 1);
1450 sf = SELECTED_FRAME ();
1453 /* Don't allow minibuf_window to remain on a deleted frame. */
1454 if (EQ (f->minibuffer_window, minibuf_window))
1456 Fset_window_buffer (sf->minibuffer_window,
1457 XWINDOW (minibuf_window)->buffer, Qnil);
1458 minibuf_window = sf->minibuffer_window;
1460 /* If the dying minibuffer window was selected,
1461 select the new one. */
1462 if (minibuffer_selected)
1463 Fselect_window (minibuf_window, Qnil);
1466 /* Don't let echo_area_window to remain on a deleted frame. */
1467 if (EQ (f->minibuffer_window, echo_area_window))
1468 echo_area_window = sf->minibuffer_window;
1470 /* Don't allow other frames to refer to a deleted frame in their
1471 'environment parameter. */
1473 Lisp_Object tail, frame1;
1474 Lisp_Object env = get_frame_param (XFRAME (frame), Qenvironment);
1475 FOR_EACH_FRAME (tail, frame1)
1477 if (EQ (frame, frame1) || !FRAME_LIVE_P (XFRAME (frame1)))
1478 continue;
1479 if (EQ (frame, get_frame_param (XFRAME (frame1), Qenvironment)))
1481 store_frame_param (XFRAME (frame1), Qenvironment, env);
1482 if (!FRAMEP (env))
1483 env = frame1;
1488 /* Clear any X selections for this frame. */
1489 #ifdef HAVE_X_WINDOWS
1490 if (FRAME_X_P (f))
1491 x_clear_frame_selections (f);
1492 #endif
1493 #ifdef MAC_OS
1494 if (FRAME_MAC_P (f))
1495 x_clear_frame_selections (f);
1496 #endif
1498 /* Free glyphs.
1499 This function must be called before the window tree of the
1500 frame is deleted because windows contain dynamically allocated
1501 memory. */
1502 free_glyphs (f);
1504 /* Mark all the windows that used to be on FRAME as deleted, and then
1505 remove the reference to them. */
1506 delete_all_subwindows (XWINDOW (f->root_window));
1507 f->root_window = Qnil;
1509 Vframe_list = Fdelq (frame, Vframe_list);
1510 FRAME_SET_VISIBLE (f, 0);
1512 if (f->namebuf)
1513 xfree (f->namebuf);
1514 if (f->decode_mode_spec_buffer)
1515 xfree (f->decode_mode_spec_buffer);
1516 if (FRAME_INSERT_COST (f))
1517 xfree (FRAME_INSERT_COST (f));
1518 if (FRAME_DELETEN_COST (f))
1519 xfree (FRAME_DELETEN_COST (f));
1520 if (FRAME_INSERTN_COST (f))
1521 xfree (FRAME_INSERTN_COST (f));
1522 if (FRAME_DELETE_COST (f))
1523 xfree (FRAME_DELETE_COST (f));
1524 if (FRAME_MESSAGE_BUF (f))
1525 xfree (FRAME_MESSAGE_BUF (f));
1527 /* Since some events are handled at the interrupt level, we may get
1528 an event for f at any time; if we zero out the frame's terminal
1529 now, then we may trip up the event-handling code. Instead, we'll
1530 promise that the terminal of the frame must be valid until we
1531 have called the window-system-dependent frame destruction
1532 routine. */
1534 if (FRAME_TERMINAL (f)->delete_frame_hook)
1535 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1538 struct terminal *terminal = FRAME_TERMINAL (f);
1539 f->output_data.nothing = 0;
1540 f->terminal = 0; /* Now the frame is dead. */
1542 /* If needed, delete the terminal that this frame was on.
1543 (This must be done after the frame is killed.) */
1544 terminal->reference_count--;
1545 if (terminal->reference_count == 0)
1547 kb = NULL;
1548 if (terminal->delete_terminal_hook)
1549 (*terminal->delete_terminal_hook) (terminal);
1550 else
1551 delete_terminal (terminal);
1553 else
1554 kb = terminal->kboard;
1557 /* If we've deleted the last_nonminibuf_frame, then try to find
1558 another one. */
1559 if (f == last_nonminibuf_frame)
1561 Lisp_Object frames;
1563 last_nonminibuf_frame = 0;
1565 for (frames = Vframe_list;
1566 CONSP (frames);
1567 frames = XCDR (frames))
1569 f = XFRAME (XCAR (frames));
1570 if (!FRAME_MINIBUF_ONLY_P (f))
1572 last_nonminibuf_frame = f;
1573 break;
1578 /* If there's no other frame on the same kboard, get out of
1579 single-kboard state if we're in it for this kboard. */
1580 if (kb != NULL)
1582 Lisp_Object frames;
1583 /* Some frame we found on the same kboard, or nil if there are none. */
1584 Lisp_Object frame_on_same_kboard;
1586 frame_on_same_kboard = Qnil;
1588 for (frames = Vframe_list;
1589 CONSP (frames);
1590 frames = XCDR (frames))
1592 Lisp_Object this;
1593 struct frame *f1;
1595 this = XCAR (frames);
1596 if (!FRAMEP (this))
1597 abort ();
1598 f1 = XFRAME (this);
1600 if (kb == FRAME_KBOARD (f1))
1601 frame_on_same_kboard = this;
1604 if (NILP (frame_on_same_kboard))
1605 not_single_kboard_state (kb);
1609 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1610 find another one. Prefer minibuffer-only frames, but also notice
1611 frames with other windows. */
1612 if (kb != NULL && EQ (frame, kb->Vdefault_minibuffer_frame))
1614 Lisp_Object frames;
1616 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1617 Lisp_Object frame_with_minibuf;
1618 /* Some frame we found on the same kboard, or nil if there are none. */
1619 Lisp_Object frame_on_same_kboard;
1621 frame_on_same_kboard = Qnil;
1622 frame_with_minibuf = Qnil;
1624 for (frames = Vframe_list;
1625 CONSP (frames);
1626 frames = XCDR (frames))
1628 Lisp_Object this;
1629 struct frame *f1;
1631 this = XCAR (frames);
1632 if (!FRAMEP (this))
1633 abort ();
1634 f1 = XFRAME (this);
1636 /* Consider only frames on the same kboard
1637 and only those with minibuffers. */
1638 if (kb == FRAME_KBOARD (f1)
1639 && FRAME_HAS_MINIBUF_P (f1))
1641 frame_with_minibuf = this;
1642 if (FRAME_MINIBUF_ONLY_P (f1))
1643 break;
1646 if (kb == FRAME_KBOARD (f1))
1647 frame_on_same_kboard = this;
1650 if (!NILP (frame_on_same_kboard))
1652 /* We know that there must be some frame with a minibuffer out
1653 there. If this were not true, all of the frames present
1654 would have to be minibufferless, which implies that at some
1655 point their minibuffer frames must have been deleted, but
1656 that is prohibited at the top; you can't delete surrogate
1657 minibuffer frames. */
1658 if (NILP (frame_with_minibuf))
1659 abort ();
1661 kb->Vdefault_minibuffer_frame = frame_with_minibuf;
1663 else
1664 /* No frames left on this kboard--say no minibuffer either. */
1665 kb->Vdefault_minibuffer_frame = Qnil;
1668 /* Cause frame titles to update--necessary if we now have just one frame. */
1669 update_mode_lines = 1;
1671 return Qnil;
1674 /* Return mouse position in character cell units. */
1676 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1677 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1678 The position is given in character cells, where (0, 0) is the
1679 upper-left corner.
1680 If Emacs is running on a mouseless terminal or hasn't been programmed
1681 to read the mouse position, it returns the selected frame for FRAME
1682 and nil for X and Y.
1683 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1684 passing the normal return value to that function as an argument,
1685 and returns whatever that function returns. */)
1688 FRAME_PTR f;
1689 Lisp_Object lispy_dummy;
1690 enum scroll_bar_part party_dummy;
1691 Lisp_Object x, y, retval;
1692 int col, row;
1693 unsigned long long_dummy;
1694 struct gcpro gcpro1;
1696 f = SELECTED_FRAME ();
1697 x = y = Qnil;
1699 #ifdef HAVE_MOUSE
1700 /* It's okay for the hook to refrain from storing anything. */
1701 if (FRAME_TERMINAL (f)->mouse_position_hook)
1702 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1703 &lispy_dummy, &party_dummy,
1704 &x, &y,
1705 &long_dummy);
1706 if (! NILP (x))
1708 col = XINT (x);
1709 row = XINT (y);
1710 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1711 XSETINT (x, col);
1712 XSETINT (y, row);
1714 #endif
1715 XSETFRAME (lispy_dummy, f);
1716 retval = Fcons (lispy_dummy, Fcons (x, y));
1717 GCPRO1 (retval);
1718 if (!NILP (Vmouse_position_function))
1719 retval = call1 (Vmouse_position_function, retval);
1720 RETURN_UNGCPRO (retval);
1723 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1724 Smouse_pixel_position, 0, 0, 0,
1725 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1726 The position is given in pixel units, where (0, 0) is the
1727 upper-left corner.
1728 If Emacs is running on a mouseless terminal or hasn't been programmed
1729 to read the mouse position, it returns the selected frame for FRAME
1730 and nil for X and Y. */)
1733 FRAME_PTR f;
1734 Lisp_Object lispy_dummy;
1735 enum scroll_bar_part party_dummy;
1736 Lisp_Object x, y;
1737 unsigned long long_dummy;
1739 f = SELECTED_FRAME ();
1740 x = y = Qnil;
1742 #ifdef HAVE_MOUSE
1743 /* It's okay for the hook to refrain from storing anything. */
1744 if (FRAME_TERMINAL (f)->mouse_position_hook)
1745 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1746 &lispy_dummy, &party_dummy,
1747 &x, &y,
1748 &long_dummy);
1749 #endif
1750 XSETFRAME (lispy_dummy, f);
1751 return Fcons (lispy_dummy, Fcons (x, y));
1754 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1755 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1756 Coordinates are relative to the frame, not a window,
1757 so the coordinates of the top left character in the frame
1758 may be nonzero due to left-hand scroll bars or the menu bar.
1760 This function is a no-op for an X frame that is not visible.
1761 If you have just created a frame, you must wait for it to become visible
1762 before calling this function on it, like this.
1763 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1764 (frame, x, y)
1765 Lisp_Object frame, x, y;
1767 CHECK_LIVE_FRAME (frame);
1768 CHECK_NUMBER (x);
1769 CHECK_NUMBER (y);
1771 /* I think this should be done with a hook. */
1772 #ifdef HAVE_WINDOW_SYSTEM
1773 if (FRAME_WINDOW_P (XFRAME (frame)))
1774 /* Warping the mouse will cause enternotify and focus events. */
1775 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1776 #else
1777 #if defined (MSDOS) && defined (HAVE_MOUSE)
1778 if (FRAME_MSDOS_P (XFRAME (frame)))
1780 Fselect_frame (frame);
1781 mouse_moveto (XINT (x), XINT (y));
1783 #endif
1784 #endif
1786 return Qnil;
1789 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1790 Sset_mouse_pixel_position, 3, 3, 0,
1791 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1792 Note, this is a no-op for an X frame that is not visible.
1793 If you have just created a frame, you must wait for it to become visible
1794 before calling this function on it, like this.
1795 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1796 (frame, x, y)
1797 Lisp_Object frame, x, y;
1799 CHECK_LIVE_FRAME (frame);
1800 CHECK_NUMBER (x);
1801 CHECK_NUMBER (y);
1803 /* I think this should be done with a hook. */
1804 #ifdef HAVE_WINDOW_SYSTEM
1805 if (FRAME_WINDOW_P (XFRAME (frame)))
1806 /* Warping the mouse will cause enternotify and focus events. */
1807 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1808 #else
1809 #if defined (MSDOS) && defined (HAVE_MOUSE)
1810 if (FRAME_MSDOS_P (XFRAME (frame)))
1812 Fselect_frame (frame);
1813 mouse_moveto (XINT (x), XINT (y));
1815 #endif
1816 #endif
1818 return Qnil;
1821 static void make_frame_visible_1 P_ ((Lisp_Object));
1823 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1824 0, 1, "",
1825 doc: /* Make the frame FRAME visible (assuming it is an X window).
1826 If omitted, FRAME defaults to the currently selected frame. */)
1827 (frame)
1828 Lisp_Object frame;
1830 if (NILP (frame))
1831 frame = selected_frame;
1833 CHECK_LIVE_FRAME (frame);
1835 /* I think this should be done with a hook. */
1836 #ifdef HAVE_WINDOW_SYSTEM
1837 if (FRAME_WINDOW_P (XFRAME (frame)))
1839 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1840 x_make_frame_visible (XFRAME (frame));
1842 #endif
1844 make_frame_visible_1 (XFRAME (frame)->root_window);
1846 /* Make menu bar update for the Buffers and Frames menus. */
1847 windows_or_buffers_changed++;
1849 return frame;
1852 /* Update the display_time slot of the buffers shown in WINDOW
1853 and all its descendents. */
1855 static void
1856 make_frame_visible_1 (window)
1857 Lisp_Object window;
1859 struct window *w;
1861 for (;!NILP (window); window = w->next)
1863 w = XWINDOW (window);
1865 if (!NILP (w->buffer))
1866 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1868 if (!NILP (w->vchild))
1869 make_frame_visible_1 (w->vchild);
1870 if (!NILP (w->hchild))
1871 make_frame_visible_1 (w->hchild);
1875 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1876 0, 2, "",
1877 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1878 If omitted, FRAME defaults to the currently selected frame.
1879 Normally you may not make FRAME invisible if all other frames are invisible,
1880 but if the second optional argument FORCE is non-nil, you may do so. */)
1881 (frame, force)
1882 Lisp_Object frame, force;
1884 if (NILP (frame))
1885 frame = selected_frame;
1887 CHECK_LIVE_FRAME (frame);
1889 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1890 error ("Attempt to make invisible the sole visible or iconified frame");
1892 #if 0 /* This isn't logically necessary, and it can do GC. */
1893 /* Don't let the frame remain selected. */
1894 if (EQ (frame, selected_frame))
1895 do_switch_frame (next_frame (frame, Qt), 0, 0)
1896 #endif
1898 /* Don't allow minibuf_window to remain on a deleted frame. */
1899 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1901 struct frame *sf = XFRAME (selected_frame);
1902 Fset_window_buffer (sf->minibuffer_window,
1903 XWINDOW (minibuf_window)->buffer, Qnil);
1904 minibuf_window = sf->minibuffer_window;
1907 /* I think this should be done with a hook. */
1908 #ifdef HAVE_WINDOW_SYSTEM
1909 if (FRAME_WINDOW_P (XFRAME (frame)))
1910 x_make_frame_invisible (XFRAME (frame));
1911 #endif
1913 /* Make menu bar update for the Buffers and Frames menus. */
1914 windows_or_buffers_changed++;
1916 return Qnil;
1919 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1920 0, 1, "",
1921 doc: /* Make the frame FRAME into an icon.
1922 If omitted, FRAME defaults to the currently selected frame. */)
1923 (frame)
1924 Lisp_Object frame;
1926 if (NILP (frame))
1927 frame = selected_frame;
1929 CHECK_LIVE_FRAME (frame);
1931 #if 0 /* This isn't logically necessary, and it can do GC. */
1932 /* Don't let the frame remain selected. */
1933 if (EQ (frame, selected_frame))
1934 Fhandle_switch_frame (next_frame (frame, Qt));
1935 #endif
1937 /* Don't allow minibuf_window to remain on a deleted frame. */
1938 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1940 struct frame *sf = XFRAME (selected_frame);
1941 Fset_window_buffer (sf->minibuffer_window,
1942 XWINDOW (minibuf_window)->buffer, Qnil);
1943 minibuf_window = sf->minibuffer_window;
1946 /* I think this should be done with a hook. */
1947 #ifdef HAVE_WINDOW_SYSTEM
1948 if (FRAME_WINDOW_P (XFRAME (frame)))
1949 x_iconify_frame (XFRAME (frame));
1950 #endif
1952 /* Make menu bar update for the Buffers and Frames menus. */
1953 windows_or_buffers_changed++;
1955 return Qnil;
1958 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1959 1, 1, 0,
1960 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1961 A frame that is not \"visible\" is not updated and, if it works through
1962 a window system, it may not show at all.
1963 Return the symbol `icon' if frame is visible only as an icon.
1965 On a text-only terminal, all frames are considered visible, whether
1966 they are currently being displayed or not, and this function returns t
1967 for all frames. */)
1968 (frame)
1969 Lisp_Object frame;
1971 CHECK_LIVE_FRAME (frame);
1973 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1975 if (FRAME_VISIBLE_P (XFRAME (frame)))
1976 return Qt;
1977 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1978 return Qicon;
1979 return Qnil;
1982 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1983 0, 0, 0,
1984 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1987 Lisp_Object tail, frame;
1988 struct frame *f;
1989 Lisp_Object value;
1991 value = Qnil;
1992 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1994 frame = XCAR (tail);
1995 if (!FRAMEP (frame))
1996 continue;
1997 f = XFRAME (frame);
1998 if (FRAME_VISIBLE_P (f))
1999 value = Fcons (frame, value);
2001 return value;
2005 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2006 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2007 If FRAME is invisible or iconified, make it visible.
2008 If you don't specify a frame, the selected frame is used.
2009 If Emacs is displaying on an ordinary terminal or some other device which
2010 doesn't support multiple overlapping frames, this function does nothing. */)
2011 (frame)
2012 Lisp_Object frame;
2014 struct frame *f;
2015 if (NILP (frame))
2016 frame = selected_frame;
2018 CHECK_LIVE_FRAME (frame);
2020 f = XFRAME (frame);
2022 /* Do like the documentation says. */
2023 Fmake_frame_visible (frame);
2025 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2026 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2028 return Qnil;
2031 /* Should we have a corresponding function called Flower_Power? */
2032 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2033 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2034 If you don't specify a frame, the selected frame is used.
2035 If Emacs is displaying on an ordinary terminal or some other device which
2036 doesn't support multiple overlapping frames, this function does nothing. */)
2037 (frame)
2038 Lisp_Object frame;
2040 struct frame *f;
2042 if (NILP (frame))
2043 frame = selected_frame;
2045 CHECK_LIVE_FRAME (frame);
2047 f = XFRAME (frame);
2049 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2050 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2052 return Qnil;
2056 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2057 1, 2, 0,
2058 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2059 In other words, switch-frame events caused by events in FRAME will
2060 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2061 FOCUS-FRAME after reading an event typed at FRAME.
2063 If FOCUS-FRAME is omitted or nil, any existing redirection is
2064 cancelled, and the frame again receives its own keystrokes.
2066 Focus redirection is useful for temporarily redirecting keystrokes to
2067 a surrogate minibuffer frame when a frame doesn't have its own
2068 minibuffer window.
2070 A frame's focus redirection can be changed by `select-frame'. If frame
2071 FOO is selected, and then a different frame BAR is selected, any
2072 frames redirecting their focus to FOO are shifted to redirect their
2073 focus to BAR. This allows focus redirection to work properly when the
2074 user switches from one frame to another using `select-window'.
2076 This means that a frame whose focus is redirected to itself is treated
2077 differently from a frame whose focus is redirected to nil; the former
2078 is affected by `select-frame', while the latter is not.
2080 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2081 (frame, focus_frame)
2082 Lisp_Object frame, focus_frame;
2084 struct frame *f;
2086 /* Note that we don't check for a live frame here. It's reasonable
2087 to redirect the focus of a frame you're about to delete, if you
2088 know what other frame should receive those keystrokes. */
2089 CHECK_FRAME (frame);
2091 if (! NILP (focus_frame))
2092 CHECK_LIVE_FRAME (focus_frame);
2094 f = XFRAME (frame);
2096 f->focus_frame = focus_frame;
2098 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2099 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2101 return Qnil;
2105 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
2106 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2107 This returns nil if FRAME's focus is not redirected.
2108 See `redirect-frame-focus'. */)
2109 (frame)
2110 Lisp_Object frame;
2112 CHECK_LIVE_FRAME (frame);
2114 return FRAME_FOCUS_FRAME (XFRAME (frame));
2119 /* Return the value of frame parameter PROP in frame FRAME. */
2121 Lisp_Object
2122 get_frame_param (frame, prop)
2123 register struct frame *frame;
2124 Lisp_Object prop;
2126 register Lisp_Object tem;
2128 tem = Fassq (prop, frame->param_alist);
2129 if (EQ (tem, Qnil))
2130 return tem;
2131 return Fcdr (tem);
2134 /* Return the buffer-predicate of the selected frame. */
2136 Lisp_Object
2137 frame_buffer_predicate (frame)
2138 Lisp_Object frame;
2140 return XFRAME (frame)->buffer_predicate;
2143 /* Return the buffer-list of the selected frame. */
2145 Lisp_Object
2146 frame_buffer_list (frame)
2147 Lisp_Object frame;
2149 return XFRAME (frame)->buffer_list;
2152 /* Set the buffer-list of the selected frame. */
2154 void
2155 set_frame_buffer_list (frame, list)
2156 Lisp_Object frame, list;
2158 XFRAME (frame)->buffer_list = list;
2161 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2163 void
2164 frames_discard_buffer (buffer)
2165 Lisp_Object buffer;
2167 Lisp_Object frame, tail;
2169 FOR_EACH_FRAME (tail, frame)
2171 XFRAME (frame)->buffer_list
2172 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2173 XFRAME (frame)->buried_buffer_list
2174 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
2178 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2179 If the alist already has an element for PROP, we change it. */
2181 void
2182 store_in_alist (alistptr, prop, val)
2183 Lisp_Object *alistptr, val;
2184 Lisp_Object prop;
2186 register Lisp_Object tem;
2188 tem = Fassq (prop, *alistptr);
2189 if (EQ (tem, Qnil))
2190 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2191 else
2192 Fsetcdr (tem, val);
2195 static int
2196 frame_name_fnn_p (str, len)
2197 char *str;
2198 int len;
2200 if (len > 1 && str[0] == 'F')
2202 char *end_ptr;
2204 strtol (str + 1, &end_ptr, 10);
2206 if (end_ptr == str + len)
2207 return 1;
2209 return 0;
2212 /* Set the name of the terminal frame. Also used by MSDOS frames.
2213 Modeled after x_set_name which is used for WINDOW frames. */
2215 static void
2216 set_term_frame_name (f, name)
2217 struct frame *f;
2218 Lisp_Object name;
2220 f->explicit_name = ! NILP (name);
2222 /* If NAME is nil, set the name to F<num>. */
2223 if (NILP (name))
2225 char namebuf[20];
2227 /* Check for no change needed in this very common case
2228 before we do any consing. */
2229 if (frame_name_fnn_p (SDATA (f->name),
2230 SBYTES (f->name)))
2231 return;
2233 tty_frame_count++;
2234 sprintf (namebuf, "F%d", tty_frame_count);
2235 name = build_string (namebuf);
2237 else
2239 CHECK_STRING (name);
2241 /* Don't change the name if it's already NAME. */
2242 if (! NILP (Fstring_equal (name, f->name)))
2243 return;
2245 /* Don't allow the user to set the frame name to F<num>, so it
2246 doesn't clash with the names we generate for terminal frames. */
2247 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2248 error ("Frame names of the form F<num> are usurped by Emacs");
2251 f->name = name;
2252 update_mode_lines = 1;
2255 void
2256 store_frame_param (f, prop, val)
2257 struct frame *f;
2258 Lisp_Object prop, val;
2260 register Lisp_Object old_alist_elt;
2262 /* The buffer-list parameters are stored in a special place and not
2263 in the alist. */
2264 if (EQ (prop, Qbuffer_list))
2266 f->buffer_list = val;
2267 return;
2269 if (EQ (prop, Qburied_buffer_list))
2271 f->buried_buffer_list = val;
2272 return;
2275 /* If PROP is a symbol which is supposed to have frame-local values,
2276 and it is set up based on this frame, switch to the global
2277 binding. That way, we can create or alter the frame-local binding
2278 without messing up the symbol's status. */
2279 if (SYMBOLP (prop))
2281 Lisp_Object valcontents;
2282 valcontents = SYMBOL_VALUE (prop);
2283 if ((BUFFER_LOCAL_VALUEP (valcontents)
2284 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
2285 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2286 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame
2287 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2288 swap_in_global_binding (prop);
2291 #ifndef WINDOWSNT
2292 /* The tty color mode needs to be set before the frame's parameter
2293 alist is updated with the new value, because set_tty_color_mode
2294 wants to look at the old mode. */
2295 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode))
2296 set_tty_color_mode (f, val);
2297 #endif
2299 /* Update the frame parameter alist. */
2300 old_alist_elt = Fassq (prop, f->param_alist);
2301 if (EQ (old_alist_elt, Qnil))
2302 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2303 else
2304 Fsetcdr (old_alist_elt, val);
2306 /* Update some other special parameters in their special places
2307 in addition to the alist. */
2309 if (EQ (prop, Qbuffer_predicate))
2310 f->buffer_predicate = val;
2312 if (! FRAME_WINDOW_P (f))
2314 if (EQ (prop, Qmenu_bar_lines))
2315 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2316 else if (EQ (prop, Qname))
2317 set_term_frame_name (f, val);
2320 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2322 if (! MINI_WINDOW_P (XWINDOW (val)))
2323 error ("Surrogate minibuffer windows must be minibuffer windows");
2325 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2326 && !EQ (val, f->minibuffer_window))
2327 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2329 /* Install the chosen minibuffer window, with proper buffer. */
2330 f->minibuffer_window = val;
2334 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2335 doc: /* Return the parameters-alist of frame FRAME.
2336 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2337 The meaningful PARMs depend on the kind of frame.
2338 If FRAME is omitted, return information on the currently selected frame. */)
2339 (frame)
2340 Lisp_Object frame;
2342 Lisp_Object alist;
2343 FRAME_PTR f;
2344 int height, width;
2345 struct gcpro gcpro1;
2347 if (NILP (frame))
2348 frame = selected_frame;
2350 CHECK_FRAME (frame);
2351 f = XFRAME (frame);
2353 if (!FRAME_LIVE_P (f))
2354 return Qnil;
2356 alist = Fcopy_alist (f->param_alist);
2357 GCPRO1 (alist);
2359 if (!FRAME_WINDOW_P (f))
2361 int fg = FRAME_FOREGROUND_PIXEL (f);
2362 int bg = FRAME_BACKGROUND_PIXEL (f);
2363 Lisp_Object elt;
2365 /* If the frame's parameter alist says the colors are
2366 unspecified and reversed, take the frame's background pixel
2367 for foreground and vice versa. */
2368 elt = Fassq (Qforeground_color, alist);
2369 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2371 if (strncmp (SDATA (XCDR (elt)),
2372 unspecified_bg,
2373 SCHARS (XCDR (elt))) == 0)
2374 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2375 else if (strncmp (SDATA (XCDR (elt)),
2376 unspecified_fg,
2377 SCHARS (XCDR (elt))) == 0)
2378 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2380 else
2381 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2382 elt = Fassq (Qbackground_color, alist);
2383 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2385 if (strncmp (SDATA (XCDR (elt)),
2386 unspecified_fg,
2387 SCHARS (XCDR (elt))) == 0)
2388 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2389 else if (strncmp (SDATA (XCDR (elt)),
2390 unspecified_bg,
2391 SCHARS (XCDR (elt))) == 0)
2392 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2394 else
2395 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2396 store_in_alist (&alist, intern ("font"),
2397 build_string (FRAME_MSDOS_P (f)
2398 ? "ms-dos"
2399 : FRAME_W32_P (f) ? "w32term"
2400 :"tty"));
2402 store_in_alist (&alist, Qname, f->name);
2403 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2404 store_in_alist (&alist, Qheight, make_number (height));
2405 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2406 store_in_alist (&alist, Qwidth, make_number (width));
2407 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2408 store_in_alist (&alist, Qminibuffer,
2409 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2410 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2411 : FRAME_MINIBUF_WINDOW (f)));
2412 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2413 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2414 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2416 /* I think this should be done with a hook. */
2417 #ifdef HAVE_WINDOW_SYSTEM
2418 if (FRAME_WINDOW_P (f))
2419 x_report_frame_params (f, &alist);
2420 else
2421 #endif
2423 /* This ought to be correct in f->param_alist for an X frame. */
2424 Lisp_Object lines;
2425 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2426 store_in_alist (&alist, Qmenu_bar_lines, lines);
2429 UNGCPRO;
2430 return alist;
2434 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2435 doc: /* Return FRAME's value for parameter PARAMETER.
2436 If FRAME is nil, describe the currently selected frame. */)
2437 (frame, parameter)
2438 Lisp_Object frame, parameter;
2440 struct frame *f;
2441 Lisp_Object value;
2443 if (NILP (frame))
2444 frame = selected_frame;
2445 else
2446 CHECK_FRAME (frame);
2447 CHECK_SYMBOL (parameter);
2449 f = XFRAME (frame);
2450 value = Qnil;
2452 if (FRAME_LIVE_P (f))
2454 /* Avoid consing in frequent cases. */
2455 if (EQ (parameter, Qname))
2456 value = f->name;
2457 #ifdef HAVE_X_WINDOWS
2458 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2459 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2460 #endif /* HAVE_X_WINDOWS */
2461 else if (EQ (parameter, Qbackground_color)
2462 || EQ (parameter, Qforeground_color))
2464 value = Fassq (parameter, f->param_alist);
2465 if (CONSP (value))
2467 value = XCDR (value);
2468 /* Fframe_parameters puts the actual fg/bg color names,
2469 even if f->param_alist says otherwise. This is
2470 important when param_alist's notion of colors is
2471 "unspecified". We need to do the same here. */
2472 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2474 const char *color_name;
2475 EMACS_INT csz;
2477 if (EQ (parameter, Qbackground_color))
2479 color_name = SDATA (value);
2480 csz = SCHARS (value);
2481 if (strncmp (color_name, unspecified_bg, csz) == 0)
2482 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2483 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2484 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2486 else if (EQ (parameter, Qforeground_color))
2488 color_name = SDATA (value);
2489 csz = SCHARS (value);
2490 if (strncmp (color_name, unspecified_fg, csz) == 0)
2491 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2492 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2493 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2497 else
2498 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2500 else if (EQ (parameter, Qdisplay_type)
2501 || EQ (parameter, Qbackground_mode))
2502 value = Fcdr (Fassq (parameter, f->param_alist));
2503 else
2504 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2507 return value;
2511 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2512 Smodify_frame_parameters, 2, 2, 0,
2513 doc: /* Modify the parameters of frame FRAME according to ALIST.
2514 If FRAME is nil, it defaults to the selected frame.
2515 ALIST is an alist of parameters to change and their new values.
2516 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2517 The meaningful PARMs depend on the kind of frame.
2518 Undefined PARMs are ignored, but stored in the frame's parameter list
2519 so that `frame-parameters' will return them.
2521 The value of frame parameter FOO can also be accessed
2522 as a frame-local binding for the variable FOO, if you have
2523 enabled such bindings for that variable with `make-variable-frame-local'. */)
2524 (frame, alist)
2525 Lisp_Object frame, alist;
2527 FRAME_PTR f;
2528 register Lisp_Object tail, prop, val;
2529 int count = SPECPDL_INDEX ();
2531 /* Bind this to t to inhibit initialization of the default face from
2532 X resources in face-set-after-frame-default. If we don't inhibit
2533 this, modifying the `font' frame parameter, for example, while
2534 there is a `default.attributeFont' X resource, won't work,
2535 because `default's font is reset to the value of the X resource
2536 and that resets the `font' frame parameter. */
2537 specbind (Qinhibit_default_face_x_resources, Qt);
2539 if (EQ (frame, Qnil))
2540 frame = selected_frame;
2541 CHECK_LIVE_FRAME (frame);
2542 f = XFRAME (frame);
2544 /* I think this should be done with a hook. */
2545 #ifdef HAVE_WINDOW_SYSTEM
2546 if (FRAME_WINDOW_P (f))
2547 x_set_frame_parameters (f, alist);
2548 else
2549 #endif
2550 #ifdef MSDOS
2551 if (FRAME_MSDOS_P (f))
2552 IT_set_frame_parameters (f, alist);
2553 else
2554 #endif
2557 int length = XINT (Flength (alist));
2558 int i;
2559 Lisp_Object *parms
2560 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2561 Lisp_Object *values
2562 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2564 /* Extract parm names and values into those vectors. */
2566 i = 0;
2567 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2569 Lisp_Object elt;
2571 elt = Fcar (tail);
2572 parms[i] = Fcar (elt);
2573 values[i] = Fcdr (elt);
2574 i++;
2577 /* Now process them in reverse of specified order. */
2578 for (i--; i >= 0; i--)
2580 prop = parms[i];
2581 val = values[i];
2582 store_frame_param (f, prop, val);
2584 /* Changing the background color might change the background
2585 mode, so that we have to load new defface specs.
2586 Call frame-set-background-mode to do that. */
2587 if (EQ (prop, Qbackground_color))
2588 call1 (Qframe_set_background_mode, frame);
2592 return unbind_to (count, Qnil);
2595 DEFUN ("frame-with-environment", Fframe_with_environment, Sframe_with_environment, 0, 1, 0,
2596 doc: /* Return the frame that has the environment variable list for FRAME.
2598 The frame-local environment variable list is normally shared between
2599 frames that were created in the same Emacsclient session. The
2600 environment list is stored in a single frame's 'environment parameter;
2601 the other frames' 'environment parameter is set to this frame. This
2602 function follows the chain of 'environment references to reach the
2603 frame that stores the actual local environment list, and returns that
2604 frame. */)
2605 (frame)
2606 Lisp_Object frame;
2608 Lisp_Object hare, tortoise;
2610 if (NILP (frame))
2611 frame = selected_frame;
2612 CHECK_FRAME (frame);
2614 hare = tortoise = get_frame_param (XFRAME (frame), Qenvironment);
2615 while (!NILP (hare) && FRAMEP (hare))
2617 frame = hare;
2618 hare = get_frame_param (XFRAME (hare), Qenvironment);
2619 if (NILP (hare) || !FRAMEP (hare))
2620 break;
2621 frame = hare;
2622 hare = get_frame_param (XFRAME (hare), Qenvironment);
2623 tortoise = get_frame_param (XFRAME (tortoise), Qenvironment);
2624 if (EQ (hare, tortoise))
2625 error ("Cyclic frame-local environment indirection");
2628 return frame;
2632 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2633 0, 1, 0,
2634 doc: /* Height in pixels of a line in the font in frame FRAME.
2635 If FRAME is omitted, the selected frame is used.
2636 For a terminal frame, the value is always 1. */)
2637 (frame)
2638 Lisp_Object frame;
2640 struct frame *f;
2642 if (NILP (frame))
2643 frame = selected_frame;
2644 CHECK_FRAME (frame);
2645 f = XFRAME (frame);
2647 #ifdef HAVE_WINDOW_SYSTEM
2648 if (FRAME_WINDOW_P (f))
2649 return make_number (x_char_height (f));
2650 else
2651 #endif
2652 return make_number (1);
2656 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2657 0, 1, 0,
2658 doc: /* Width in pixels of characters in the font in frame FRAME.
2659 If FRAME is omitted, the selected frame is used.
2660 On a graphical screen, the width is the standard width of the default font.
2661 For a terminal screen, the value is always 1. */)
2662 (frame)
2663 Lisp_Object frame;
2665 struct frame *f;
2667 if (NILP (frame))
2668 frame = selected_frame;
2669 CHECK_FRAME (frame);
2670 f = XFRAME (frame);
2672 #ifdef HAVE_WINDOW_SYSTEM
2673 if (FRAME_WINDOW_P (f))
2674 return make_number (x_char_width (f));
2675 else
2676 #endif
2677 return make_number (1);
2680 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2681 Sframe_pixel_height, 0, 1, 0,
2682 doc: /* Return a FRAME's height in pixels.
2683 This counts only the height available for text lines,
2684 not menu bars on window-system Emacs frames.
2685 For a terminal frame, the result really gives the height in characters.
2686 If FRAME is omitted, the selected frame is used. */)
2687 (frame)
2688 Lisp_Object frame;
2690 struct frame *f;
2692 if (NILP (frame))
2693 frame = selected_frame;
2694 CHECK_FRAME (frame);
2695 f = XFRAME (frame);
2697 #ifdef HAVE_WINDOW_SYSTEM
2698 if (FRAME_WINDOW_P (f))
2699 return make_number (x_pixel_height (f));
2700 else
2701 #endif
2702 return make_number (FRAME_LINES (f));
2705 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2706 Sframe_pixel_width, 0, 1, 0,
2707 doc: /* Return FRAME's width in pixels.
2708 For a terminal frame, the result really gives the width in characters.
2709 If FRAME is omitted, the selected frame is used. */)
2710 (frame)
2711 Lisp_Object frame;
2713 struct frame *f;
2715 if (NILP (frame))
2716 frame = selected_frame;
2717 CHECK_FRAME (frame);
2718 f = XFRAME (frame);
2720 #ifdef HAVE_WINDOW_SYSTEM
2721 if (FRAME_WINDOW_P (f))
2722 return make_number (x_pixel_width (f));
2723 else
2724 #endif
2725 return make_number (FRAME_COLS (f));
2728 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2729 doc: /* Specify that the frame FRAME has LINES lines.
2730 Optional third arg non-nil means that redisplay should use LINES lines
2731 but that the idea of the actual height of the frame should not be changed. */)
2732 (frame, lines, pretend)
2733 Lisp_Object frame, lines, pretend;
2735 register struct frame *f;
2737 CHECK_NUMBER (lines);
2738 if (NILP (frame))
2739 frame = selected_frame;
2740 CHECK_LIVE_FRAME (frame);
2741 f = XFRAME (frame);
2743 /* I think this should be done with a hook. */
2744 #ifdef HAVE_WINDOW_SYSTEM
2745 if (FRAME_WINDOW_P (f))
2747 if (XINT (lines) != FRAME_LINES (f))
2748 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2749 do_pending_window_change (0);
2751 else
2752 #endif
2753 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2754 return Qnil;
2757 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2758 doc: /* Specify that the frame FRAME has COLS columns.
2759 Optional third arg non-nil means that redisplay should use COLS columns
2760 but that the idea of the actual width of the frame should not be changed. */)
2761 (frame, cols, pretend)
2762 Lisp_Object frame, cols, pretend;
2764 register struct frame *f;
2765 CHECK_NUMBER (cols);
2766 if (NILP (frame))
2767 frame = selected_frame;
2768 CHECK_LIVE_FRAME (frame);
2769 f = XFRAME (frame);
2771 /* I think this should be done with a hook. */
2772 #ifdef HAVE_WINDOW_SYSTEM
2773 if (FRAME_WINDOW_P (f))
2775 if (XINT (cols) != FRAME_COLS (f))
2776 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2777 do_pending_window_change (0);
2779 else
2780 #endif
2781 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2782 return Qnil;
2785 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2786 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2787 (frame, cols, rows)
2788 Lisp_Object frame, cols, rows;
2790 register struct frame *f;
2792 CHECK_LIVE_FRAME (frame);
2793 CHECK_NUMBER (cols);
2794 CHECK_NUMBER (rows);
2795 f = XFRAME (frame);
2797 /* I think this should be done with a hook. */
2798 #ifdef HAVE_WINDOW_SYSTEM
2799 if (FRAME_WINDOW_P (f))
2801 if (XINT (rows) != FRAME_LINES (f)
2802 || XINT (cols) != FRAME_COLS (f)
2803 || f->new_text_lines || f->new_text_cols)
2804 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2805 do_pending_window_change (0);
2807 else
2808 #endif
2809 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2811 return Qnil;
2814 DEFUN ("set-frame-position", Fset_frame_position,
2815 Sset_frame_position, 3, 3, 0,
2816 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2817 This is actually the position of the upper left corner of the frame.
2818 Negative values for XOFFSET or YOFFSET are interpreted relative to
2819 the rightmost or bottommost possible position (that stays within the screen). */)
2820 (frame, xoffset, yoffset)
2821 Lisp_Object frame, xoffset, yoffset;
2823 register struct frame *f;
2825 CHECK_LIVE_FRAME (frame);
2826 CHECK_NUMBER (xoffset);
2827 CHECK_NUMBER (yoffset);
2828 f = XFRAME (frame);
2830 /* I think this should be done with a hook. */
2831 #ifdef HAVE_WINDOW_SYSTEM
2832 if (FRAME_WINDOW_P (f))
2833 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2834 #endif
2836 return Qt;
2840 /***********************************************************************
2841 Frame Parameters
2842 ***********************************************************************/
2844 /* Connect the frame-parameter names for X frames
2845 to the ways of passing the parameter values to the window system.
2847 The name of a parameter, as a Lisp symbol,
2848 has an `x-frame-parameter' property which is an integer in Lisp
2849 that is an index in this table. */
2851 struct frame_parm_table {
2852 char *name;
2853 Lisp_Object *variable;
2856 static struct frame_parm_table frame_parms[] =
2858 {"auto-raise", &Qauto_raise},
2859 {"auto-lower", &Qauto_lower},
2860 {"background-color", 0},
2861 {"border-color", &Qborder_color},
2862 {"border-width", &Qborder_width},
2863 {"cursor-color", &Qcursor_color},
2864 {"cursor-type", &Qcursor_type},
2865 {"font", 0},
2866 {"foreground-color", 0},
2867 {"icon-name", &Qicon_name},
2868 {"icon-type", &Qicon_type},
2869 {"internal-border-width", &Qinternal_border_width},
2870 {"menu-bar-lines", &Qmenu_bar_lines},
2871 {"mouse-color", &Qmouse_color},
2872 {"name", &Qname},
2873 {"scroll-bar-width", &Qscroll_bar_width},
2874 {"title", &Qtitle},
2875 {"unsplittable", &Qunsplittable},
2876 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2877 {"visibility", &Qvisibility},
2878 {"tool-bar-lines", &Qtool_bar_lines},
2879 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2880 {"scroll-bar-background", &Qscroll_bar_background},
2881 {"screen-gamma", &Qscreen_gamma},
2882 {"line-spacing", &Qline_spacing},
2883 {"left-fringe", &Qleft_fringe},
2884 {"right-fringe", &Qright_fringe},
2885 {"wait-for-wm", &Qwait_for_wm},
2886 {"fullscreen", &Qfullscreen},
2889 #ifdef HAVE_WINDOW_SYSTEM
2891 extern Lisp_Object Qbox;
2892 extern Lisp_Object Qtop;
2894 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2895 wanted positions of the WM window (not emacs window).
2896 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2897 window (FRAME_X_WINDOW).
2900 void
2901 x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2902 struct frame *f;
2903 int *width;
2904 int *height;
2905 int *top_pos;
2906 int *left_pos;
2908 int newwidth = FRAME_COLS (f);
2909 int newheight = FRAME_LINES (f);
2911 *top_pos = f->top_pos;
2912 *left_pos = f->left_pos;
2914 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2916 int ph;
2918 ph = FRAME_X_DISPLAY_INFO (f)->height;
2919 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2920 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2921 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2922 *top_pos = 0;
2925 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2927 int pw;
2929 pw = FRAME_X_DISPLAY_INFO (f)->width;
2930 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2931 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2932 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2933 *left_pos = 0;
2936 *width = newwidth;
2937 *height = newheight;
2941 /* Change the parameters of frame F as specified by ALIST.
2942 If a parameter is not specially recognized, do nothing special;
2943 otherwise call the `x_set_...' function for that parameter.
2944 Except for certain geometry properties, always call store_frame_param
2945 to store the new value in the parameter alist. */
2947 void
2948 x_set_frame_parameters (f, alist)
2949 FRAME_PTR f;
2950 Lisp_Object alist;
2952 Lisp_Object tail;
2954 /* If both of these parameters are present, it's more efficient to
2955 set them both at once. So we wait until we've looked at the
2956 entire list before we set them. */
2957 int width, height;
2959 /* Same here. */
2960 Lisp_Object left, top;
2962 /* Same with these. */
2963 Lisp_Object icon_left, icon_top;
2965 /* Record in these vectors all the parms specified. */
2966 Lisp_Object *parms;
2967 Lisp_Object *values;
2968 int i, p;
2969 int left_no_change = 0, top_no_change = 0;
2970 int icon_left_no_change = 0, icon_top_no_change = 0;
2971 int fullscreen_is_being_set = 0;
2973 struct gcpro gcpro1, gcpro2;
2975 i = 0;
2976 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2977 i++;
2979 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2980 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2982 /* Extract parm names and values into those vectors. */
2984 i = 0;
2985 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2987 Lisp_Object elt;
2989 elt = Fcar (tail);
2990 parms[i] = Fcar (elt);
2991 values[i] = Fcdr (elt);
2992 i++;
2994 /* TAIL and ALIST are not used again below here. */
2995 alist = tail = Qnil;
2997 GCPRO2 (*parms, *values);
2998 gcpro1.nvars = i;
2999 gcpro2.nvars = i;
3001 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
3002 because their values appear in VALUES and strings are not valid. */
3003 top = left = Qunbound;
3004 icon_left = icon_top = Qunbound;
3006 /* Provide default values for HEIGHT and WIDTH. */
3007 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
3008 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
3010 /* Process foreground_color and background_color before anything else.
3011 They are independent of other properties, but other properties (e.g.,
3012 cursor_color) are dependent upon them. */
3013 /* Process default font as well, since fringe widths depends on it. */
3014 /* Also, process fullscreen, width and height depend upon that */
3015 for (p = 0; p < i; p++)
3017 Lisp_Object prop, val;
3019 prop = parms[p];
3020 val = values[p];
3021 if (EQ (prop, Qforeground_color)
3022 || EQ (prop, Qbackground_color)
3023 || EQ (prop, Qfont)
3024 || EQ (prop, Qfullscreen))
3026 register Lisp_Object param_index, old_value;
3028 old_value = get_frame_param (f, prop);
3029 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
3031 if (NILP (Fequal (val, old_value)))
3033 store_frame_param (f, prop, val);
3035 param_index = Fget (prop, Qx_frame_parameter);
3036 if (NATNUMP (param_index)
3037 && (XFASTINT (param_index)
3038 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3039 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3040 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3045 /* Now process them in reverse of specified order. */
3046 for (i--; i >= 0; i--)
3048 Lisp_Object prop, val;
3050 prop = parms[i];
3051 val = values[i];
3053 if (EQ (prop, Qwidth) && NUMBERP (val))
3054 width = XFASTINT (val);
3055 else if (EQ (prop, Qheight) && NUMBERP (val))
3056 height = XFASTINT (val);
3057 else if (EQ (prop, Qtop))
3058 top = val;
3059 else if (EQ (prop, Qleft))
3060 left = val;
3061 else if (EQ (prop, Qicon_top))
3062 icon_top = val;
3063 else if (EQ (prop, Qicon_left))
3064 icon_left = val;
3065 else if (EQ (prop, Qforeground_color)
3066 || EQ (prop, Qbackground_color)
3067 || EQ (prop, Qfont)
3068 || EQ (prop, Qfullscreen))
3069 /* Processed above. */
3070 continue;
3071 else
3073 register Lisp_Object param_index, old_value;
3075 old_value = get_frame_param (f, prop);
3077 store_frame_param (f, prop, val);
3079 param_index = Fget (prop, Qx_frame_parameter);
3080 if (NATNUMP (param_index)
3081 && (XFASTINT (param_index)
3082 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3083 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3084 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3088 /* Don't die if just one of these was set. */
3089 if (EQ (left, Qunbound))
3091 left_no_change = 1;
3092 if (f->left_pos < 0)
3093 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
3094 else
3095 XSETINT (left, f->left_pos);
3097 if (EQ (top, Qunbound))
3099 top_no_change = 1;
3100 if (f->top_pos < 0)
3101 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
3102 else
3103 XSETINT (top, f->top_pos);
3106 /* If one of the icon positions was not set, preserve or default it. */
3107 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
3109 icon_left_no_change = 1;
3110 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3111 if (NILP (icon_left))
3112 XSETINT (icon_left, 0);
3114 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
3116 icon_top_no_change = 1;
3117 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3118 if (NILP (icon_top))
3119 XSETINT (icon_top, 0);
3122 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
3124 /* If the frame is visible already and the fullscreen parameter is
3125 being set, it is too late to set WM manager hints to specify
3126 size and position.
3127 Here we first get the width, height and position that applies to
3128 fullscreen. We then move the frame to the appropriate
3129 position. Resize of the frame is taken care of in the code after
3130 this if-statement. */
3131 int new_left, new_top;
3133 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
3134 if (new_top != f->top_pos || new_left != f->left_pos)
3135 x_set_offset (f, new_left, new_top, 1);
3138 /* Don't set these parameters unless they've been explicitly
3139 specified. The window might be mapped or resized while we're in
3140 this function, and we don't want to override that unless the lisp
3141 code has asked for it.
3143 Don't set these parameters unless they actually differ from the
3144 window's current parameters; the window may not actually exist
3145 yet. */
3147 Lisp_Object frame;
3149 check_frame_size (f, &height, &width);
3151 XSETFRAME (frame, f);
3153 if (width != FRAME_COLS (f)
3154 || height != FRAME_LINES (f)
3155 || f->new_text_lines || f->new_text_cols)
3156 Fset_frame_size (frame, make_number (width), make_number (height));
3158 if ((!NILP (left) || !NILP (top))
3159 && ! (left_no_change && top_no_change)
3160 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3161 && NUMBERP (top) && XINT (top) == f->top_pos))
3163 int leftpos = 0;
3164 int toppos = 0;
3166 /* Record the signs. */
3167 f->size_hint_flags &= ~ (XNegative | YNegative);
3168 if (EQ (left, Qminus))
3169 f->size_hint_flags |= XNegative;
3170 else if (INTEGERP (left))
3172 leftpos = XINT (left);
3173 if (leftpos < 0)
3174 f->size_hint_flags |= XNegative;
3176 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3177 && CONSP (XCDR (left))
3178 && INTEGERP (XCAR (XCDR (left))))
3180 leftpos = - XINT (XCAR (XCDR (left)));
3181 f->size_hint_flags |= XNegative;
3183 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3184 && CONSP (XCDR (left))
3185 && INTEGERP (XCAR (XCDR (left))))
3187 leftpos = XINT (XCAR (XCDR (left)));
3190 if (EQ (top, Qminus))
3191 f->size_hint_flags |= YNegative;
3192 else if (INTEGERP (top))
3194 toppos = XINT (top);
3195 if (toppos < 0)
3196 f->size_hint_flags |= YNegative;
3198 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3199 && CONSP (XCDR (top))
3200 && INTEGERP (XCAR (XCDR (top))))
3202 toppos = - XINT (XCAR (XCDR (top)));
3203 f->size_hint_flags |= YNegative;
3205 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3206 && CONSP (XCDR (top))
3207 && INTEGERP (XCAR (XCDR (top))))
3209 toppos = XINT (XCAR (XCDR (top)));
3213 /* Store the numeric value of the position. */
3214 f->top_pos = toppos;
3215 f->left_pos = leftpos;
3217 f->win_gravity = NorthWestGravity;
3219 /* Actually set that position, and convert to absolute. */
3220 x_set_offset (f, leftpos, toppos, -1);
3223 if ((!NILP (icon_left) || !NILP (icon_top))
3224 && ! (icon_left_no_change && icon_top_no_change))
3225 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3228 UNGCPRO;
3232 /* Insert a description of internally-recorded parameters of frame X
3233 into the parameter alist *ALISTPTR that is to be given to the user.
3234 Only parameters that are specific to the X window system
3235 and whose values are not correctly recorded in the frame's
3236 param_alist need to be considered here. */
3238 void
3239 x_report_frame_params (f, alistptr)
3240 struct frame *f;
3241 Lisp_Object *alistptr;
3243 char buf[16];
3244 Lisp_Object tem;
3246 /* Represent negative positions (off the top or left screen edge)
3247 in a way that Fmodify_frame_parameters will understand correctly. */
3248 XSETINT (tem, f->left_pos);
3249 if (f->left_pos >= 0)
3250 store_in_alist (alistptr, Qleft, tem);
3251 else
3252 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3254 XSETINT (tem, f->top_pos);
3255 if (f->top_pos >= 0)
3256 store_in_alist (alistptr, Qtop, tem);
3257 else
3258 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3260 store_in_alist (alistptr, Qborder_width,
3261 make_number (f->border_width));
3262 store_in_alist (alistptr, Qinternal_border_width,
3263 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3264 store_in_alist (alistptr, Qleft_fringe,
3265 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3266 store_in_alist (alistptr, Qright_fringe,
3267 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3268 store_in_alist (alistptr, Qscroll_bar_width,
3269 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3270 ? make_number (0)
3271 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3272 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3273 /* nil means "use default width"
3274 for non-toolkit scroll bar.
3275 ruler-mode.el depends on this. */
3276 : Qnil));
3277 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3278 store_in_alist (alistptr, Qwindow_id,
3279 build_string (buf));
3280 #ifdef HAVE_X_WINDOWS
3281 #ifdef USE_X_TOOLKIT
3282 /* Tooltip frame may not have this widget. */
3283 if (FRAME_X_OUTPUT (f)->widget)
3284 #endif
3285 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3286 store_in_alist (alistptr, Qouter_window_id,
3287 build_string (buf));
3288 #endif
3289 store_in_alist (alistptr, Qicon_name, f->icon_name);
3290 FRAME_SAMPLE_VISIBILITY (f);
3291 store_in_alist (alistptr, Qvisibility,
3292 (FRAME_VISIBLE_P (f) ? Qt
3293 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3294 store_in_alist (alistptr, Qdisplay,
3295 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3297 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3298 tem = Qnil;
3299 else
3300 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3301 store_in_alist (alistptr, Qparent_id, tem);
3305 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3306 the previous value of that parameter, NEW_VALUE is the new value. */
3308 void
3309 x_set_fullscreen (f, new_value, old_value)
3310 struct frame *f;
3311 Lisp_Object new_value, old_value;
3313 if (NILP (new_value))
3314 f->want_fullscreen = FULLSCREEN_NONE;
3315 else if (EQ (new_value, Qfullboth))
3316 f->want_fullscreen = FULLSCREEN_BOTH;
3317 else if (EQ (new_value, Qfullwidth))
3318 f->want_fullscreen = FULLSCREEN_WIDTH;
3319 else if (EQ (new_value, Qfullheight))
3320 f->want_fullscreen = FULLSCREEN_HEIGHT;
3324 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3325 the previous value of that parameter, NEW_VALUE is the new value. */
3327 void
3328 x_set_line_spacing (f, new_value, old_value)
3329 struct frame *f;
3330 Lisp_Object new_value, old_value;
3332 if (NILP (new_value))
3333 f->extra_line_spacing = 0;
3334 else if (NATNUMP (new_value))
3335 f->extra_line_spacing = XFASTINT (new_value);
3336 else
3337 Fsignal (Qerror, Fcons (build_string ("Invalid line-spacing"),
3338 Fcons (new_value, Qnil)));
3339 if (FRAME_VISIBLE_P (f))
3340 redraw_frame (f);
3344 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3345 the previous value of that parameter, NEW_VALUE is the new value. */
3347 void
3348 x_set_screen_gamma (f, new_value, old_value)
3349 struct frame *f;
3350 Lisp_Object new_value, old_value;
3352 if (NILP (new_value))
3353 f->gamma = 0;
3354 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3355 /* The value 0.4545 is the normal viewing gamma. */
3356 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3357 else
3358 Fsignal (Qerror, Fcons (build_string ("Invalid screen-gamma"),
3359 Fcons (new_value, Qnil)));
3361 clear_face_cache (0);
3365 void
3366 x_set_font (f, arg, oldval)
3367 struct frame *f;
3368 Lisp_Object arg, oldval;
3370 Lisp_Object result;
3371 Lisp_Object fontset_name;
3372 Lisp_Object frame;
3373 int old_fontset = FRAME_FONTSET(f);
3375 CHECK_STRING (arg);
3377 fontset_name = Fquery_fontset (arg, Qnil);
3379 BLOCK_INPUT;
3380 result = (STRINGP (fontset_name)
3381 ? x_new_fontset (f, SDATA (fontset_name))
3382 : x_new_font (f, SDATA (arg)));
3383 UNBLOCK_INPUT;
3385 if (EQ (result, Qnil))
3386 error ("Font `%s' is not defined", SDATA (arg));
3387 else if (EQ (result, Qt))
3388 error ("The characters of the given font have varying widths");
3389 else if (STRINGP (result))
3391 set_default_ascii_font (result);
3392 if (STRINGP (fontset_name))
3394 /* Fontset names are built from ASCII font names, so the
3395 names may be equal despite there was a change. */
3396 if (old_fontset == FRAME_FONTSET (f))
3397 return;
3399 else if (!NILP (Fequal (result, oldval)))
3400 return;
3402 store_frame_param (f, Qfont, result);
3403 recompute_basic_faces (f);
3405 else
3406 abort ();
3408 do_pending_window_change (0);
3410 /* Don't call `face-set-after-frame-default' when faces haven't been
3411 initialized yet. This is the case when called from
3412 Fx_create_frame. In that case, the X widget or window doesn't
3413 exist either, and we can end up in x_report_frame_params with a
3414 null widget which gives a segfault. */
3415 if (FRAME_FACE_CACHE (f))
3417 XSETFRAME (frame, f);
3418 call1 (Qface_set_after_frame_default, frame);
3423 void
3424 x_set_fringe_width (f, new_value, old_value)
3425 struct frame *f;
3426 Lisp_Object new_value, old_value;
3428 compute_fringe_widths (f, 1);
3431 void
3432 x_set_border_width (f, arg, oldval)
3433 struct frame *f;
3434 Lisp_Object arg, oldval;
3436 CHECK_NUMBER (arg);
3438 if (XINT (arg) == f->border_width)
3439 return;
3441 #ifndef MAC_OS
3442 if (FRAME_X_WINDOW (f) != 0)
3443 error ("Cannot change the border width of a window");
3444 #endif /* MAC_TODO */
3446 f->border_width = XINT (arg);
3449 void
3450 x_set_internal_border_width (f, arg, oldval)
3451 struct frame *f;
3452 Lisp_Object arg, oldval;
3454 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3456 CHECK_NUMBER (arg);
3457 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3458 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3459 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3461 #ifdef USE_X_TOOLKIT
3462 if (FRAME_X_OUTPUT (f)->edit_widget)
3463 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3464 #endif
3466 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3467 return;
3469 if (FRAME_X_WINDOW (f) != 0)
3471 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3472 SET_FRAME_GARBAGED (f);
3473 do_pending_window_change (0);
3475 else
3476 SET_FRAME_GARBAGED (f);
3479 void
3480 x_set_visibility (f, value, oldval)
3481 struct frame *f;
3482 Lisp_Object value, oldval;
3484 Lisp_Object frame;
3485 XSETFRAME (frame, f);
3487 if (NILP (value))
3488 Fmake_frame_invisible (frame, Qt);
3489 else if (EQ (value, Qicon))
3490 Ficonify_frame (frame);
3491 else
3492 Fmake_frame_visible (frame);
3495 void
3496 x_set_autoraise (f, arg, oldval)
3497 struct frame *f;
3498 Lisp_Object arg, oldval;
3500 f->auto_raise = !EQ (Qnil, arg);
3503 void
3504 x_set_autolower (f, arg, oldval)
3505 struct frame *f;
3506 Lisp_Object arg, oldval;
3508 f->auto_lower = !EQ (Qnil, arg);
3511 void
3512 x_set_unsplittable (f, arg, oldval)
3513 struct frame *f;
3514 Lisp_Object arg, oldval;
3516 f->no_split = !NILP (arg);
3519 void
3520 x_set_vertical_scroll_bars (f, arg, oldval)
3521 struct frame *f;
3522 Lisp_Object arg, oldval;
3524 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3525 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3526 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3527 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3529 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3530 = (NILP (arg)
3531 ? vertical_scroll_bar_none
3532 : EQ (Qleft, arg)
3533 ? vertical_scroll_bar_left
3534 : EQ (Qright, arg)
3535 ? vertical_scroll_bar_right
3536 : EQ (Qleft, Vdefault_frame_scroll_bars)
3537 ? vertical_scroll_bar_left
3538 : EQ (Qright, Vdefault_frame_scroll_bars)
3539 ? vertical_scroll_bar_right
3540 : vertical_scroll_bar_none);
3542 /* We set this parameter before creating the X window for the
3543 frame, so we can get the geometry right from the start.
3544 However, if the window hasn't been created yet, we shouldn't
3545 call x_set_window_size. */
3546 if (FRAME_X_WINDOW (f))
3547 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3548 do_pending_window_change (0);
3552 void
3553 x_set_scroll_bar_width (f, arg, oldval)
3554 struct frame *f;
3555 Lisp_Object arg, oldval;
3557 int wid = FRAME_COLUMN_WIDTH (f);
3559 if (NILP (arg))
3561 x_set_scroll_bar_default_width (f);
3563 if (FRAME_X_WINDOW (f))
3564 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3565 do_pending_window_change (0);
3567 else if (INTEGERP (arg) && XINT (arg) > 0
3568 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3570 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3571 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3573 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3574 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3575 if (FRAME_X_WINDOW (f))
3576 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3577 do_pending_window_change (0);
3580 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3581 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3582 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3587 /* Return non-nil if frame F wants a bitmap icon. */
3589 Lisp_Object
3590 x_icon_type (f)
3591 FRAME_PTR f;
3593 Lisp_Object tem;
3595 tem = assq_no_quit (Qicon_type, f->param_alist);
3596 if (CONSP (tem))
3597 return XCDR (tem);
3598 else
3599 return Qnil;
3603 /* Subroutines of creating an X frame. */
3605 /* Make sure that Vx_resource_name is set to a reasonable value.
3606 Fix it up, or set it to `emacs' if it is too hopeless. */
3608 void
3609 validate_x_resource_name ()
3611 int len = 0;
3612 /* Number of valid characters in the resource name. */
3613 int good_count = 0;
3614 /* Number of invalid characters in the resource name. */
3615 int bad_count = 0;
3616 Lisp_Object new;
3617 int i;
3619 if (!STRINGP (Vx_resource_class))
3620 Vx_resource_class = build_string (EMACS_CLASS);
3622 if (STRINGP (Vx_resource_name))
3624 unsigned char *p = SDATA (Vx_resource_name);
3625 int i;
3627 len = SBYTES (Vx_resource_name);
3629 /* Only letters, digits, - and _ are valid in resource names.
3630 Count the valid characters and count the invalid ones. */
3631 for (i = 0; i < len; i++)
3633 int c = p[i];
3634 if (! ((c >= 'a' && c <= 'z')
3635 || (c >= 'A' && c <= 'Z')
3636 || (c >= '0' && c <= '9')
3637 || c == '-' || c == '_'))
3638 bad_count++;
3639 else
3640 good_count++;
3643 else
3644 /* Not a string => completely invalid. */
3645 bad_count = 5, good_count = 0;
3647 /* If name is valid already, return. */
3648 if (bad_count == 0)
3649 return;
3651 /* If name is entirely invalid, or nearly so, use `emacs'. */
3652 if (good_count == 0
3653 || (good_count == 1 && bad_count > 0))
3655 Vx_resource_name = build_string ("emacs");
3656 return;
3659 /* Name is partly valid. Copy it and replace the invalid characters
3660 with underscores. */
3662 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3664 for (i = 0; i < len; i++)
3666 int c = SREF (new, i);
3667 if (! ((c >= 'a' && c <= 'z')
3668 || (c >= 'A' && c <= 'Z')
3669 || (c >= '0' && c <= '9')
3670 || c == '-' || c == '_'))
3671 SSET (new, i, '_');
3676 extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3677 extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3680 /* Get specified attribute from resource database RDB.
3681 See Fx_get_resource below for other parameters. */
3683 static Lisp_Object
3684 xrdb_get_resource (rdb, attribute, class, component, subclass)
3685 XrmDatabase rdb;
3686 Lisp_Object attribute, class, component, subclass;
3688 register char *value;
3689 char *name_key;
3690 char *class_key;
3692 CHECK_STRING (attribute);
3693 CHECK_STRING (class);
3695 if (!NILP (component))
3696 CHECK_STRING (component);
3697 if (!NILP (subclass))
3698 CHECK_STRING (subclass);
3699 if (NILP (component) != NILP (subclass))
3700 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3702 validate_x_resource_name ();
3704 /* Allocate space for the components, the dots which separate them,
3705 and the final '\0'. Make them big enough for the worst case. */
3706 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3707 + (STRINGP (component)
3708 ? SBYTES (component) : 0)
3709 + SBYTES (attribute)
3710 + 3);
3712 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3713 + SBYTES (class)
3714 + (STRINGP (subclass)
3715 ? SBYTES (subclass) : 0)
3716 + 3);
3718 /* Start with emacs.FRAMENAME for the name (the specific one)
3719 and with `Emacs' for the class key (the general one). */
3720 strcpy (name_key, SDATA (Vx_resource_name));
3721 strcpy (class_key, SDATA (Vx_resource_class));
3723 strcat (class_key, ".");
3724 strcat (class_key, SDATA (class));
3726 if (!NILP (component))
3728 strcat (class_key, ".");
3729 strcat (class_key, SDATA (subclass));
3731 strcat (name_key, ".");
3732 strcat (name_key, SDATA (component));
3735 strcat (name_key, ".");
3736 strcat (name_key, SDATA (attribute));
3738 value = x_get_string_resource (rdb, name_key, class_key);
3740 if (value != (char *) 0)
3741 return build_string (value);
3742 else
3743 return Qnil;
3747 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3748 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3749 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3750 class, where INSTANCE is the name under which Emacs was invoked, or
3751 the name specified by the `-name' or `-rn' command-line arguments.
3753 The optional arguments COMPONENT and SUBCLASS add to the key and the
3754 class, respectively. You must specify both of them or neither.
3755 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3756 and the class is `Emacs.CLASS.SUBCLASS'. */)
3757 (attribute, class, component, subclass)
3758 Lisp_Object attribute, class, component, subclass;
3760 #ifdef HAVE_X_WINDOWS
3761 check_x ();
3762 #endif
3764 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3765 attribute, class, component, subclass);
3768 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3770 Lisp_Object
3771 display_x_get_resource (dpyinfo, attribute, class, component, subclass)
3772 Display_Info *dpyinfo;
3773 Lisp_Object attribute, class, component, subclass;
3775 return xrdb_get_resource (dpyinfo->xrdb,
3776 attribute, class, component, subclass);
3779 /* Used when C code wants a resource value. */
3781 char *
3782 x_get_resource_string (attribute, class)
3783 char *attribute, *class;
3785 char *name_key;
3786 char *class_key;
3787 struct frame *sf = SELECTED_FRAME ();
3789 /* Allocate space for the components, the dots which separate them,
3790 and the final '\0'. */
3791 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3792 + strlen (attribute) + 2);
3793 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3794 + strlen (class) + 2);
3796 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3797 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3799 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3800 name_key, class_key);
3804 /* Return the value of parameter PARAM.
3806 First search ALIST, then Vdefault_frame_alist, then the X defaults
3807 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3809 Convert the resource to the type specified by desired_type.
3811 If no default is specified, return Qunbound. If you call
3812 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3813 and don't let it get stored in any Lisp-visible variables! */
3815 Lisp_Object
3816 x_get_arg (dpyinfo, alist, param, attribute, class, type)
3817 Display_Info *dpyinfo;
3818 Lisp_Object alist, param;
3819 char *attribute;
3820 char *class;
3821 enum resource_types type;
3823 register Lisp_Object tem;
3825 tem = Fassq (param, alist);
3827 if (!NILP (tem))
3829 /* If we find this parm in ALIST, clear it out
3830 so that it won't be "left over" at the end. */
3831 #ifndef WINDOWSNT /* w32fns.c has not yet been changed to cope with this. */
3832 Lisp_Object tail;
3833 XSETCAR (tem, Qnil);
3834 /* In case the parameter appears more than once in the alist,
3835 clear it out. */
3836 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3837 if (CONSP (XCAR (tail))
3838 && EQ (XCAR (XCAR (tail)), param))
3839 XSETCAR (XCAR (tail), Qnil);
3840 #endif
3842 else
3843 tem = Fassq (param, Vdefault_frame_alist);
3845 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3846 look in the X resources. */
3847 if (EQ (tem, Qnil))
3849 if (attribute)
3851 tem = display_x_get_resource (dpyinfo,
3852 build_string (attribute),
3853 build_string (class),
3854 Qnil, Qnil);
3856 if (NILP (tem))
3857 return Qunbound;
3859 switch (type)
3861 case RES_TYPE_NUMBER:
3862 return make_number (atoi (SDATA (tem)));
3864 case RES_TYPE_FLOAT:
3865 return make_float (atof (SDATA (tem)));
3867 case RES_TYPE_BOOLEAN:
3868 tem = Fdowncase (tem);
3869 if (!strcmp (SDATA (tem), "on")
3870 || !strcmp (SDATA (tem), "true"))
3871 return Qt;
3872 else
3873 return Qnil;
3875 case RES_TYPE_STRING:
3876 return tem;
3878 case RES_TYPE_SYMBOL:
3879 /* As a special case, we map the values `true' and `on'
3880 to Qt, and `false' and `off' to Qnil. */
3882 Lisp_Object lower;
3883 lower = Fdowncase (tem);
3884 if (!strcmp (SDATA (lower), "on")
3885 || !strcmp (SDATA (lower), "true"))
3886 return Qt;
3887 else if (!strcmp (SDATA (lower), "off")
3888 || !strcmp (SDATA (lower), "false"))
3889 return Qnil;
3890 else
3891 return Fintern (tem, Qnil);
3894 default:
3895 abort ();
3898 else
3899 return Qunbound;
3901 return Fcdr (tem);
3904 Lisp_Object
3905 x_frame_get_arg (f, alist, param, attribute, class, type)
3906 struct frame *f;
3907 Lisp_Object alist, param;
3908 char *attribute;
3909 char *class;
3910 enum resource_types type;
3912 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3913 alist, param, attribute, class, type);
3916 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3918 Lisp_Object
3919 x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
3920 struct frame *f;
3921 Lisp_Object alist, param;
3922 char *attribute;
3923 char *class;
3924 enum resource_types type;
3926 Lisp_Object value;
3928 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3929 attribute, class, type);
3930 if (! NILP (value) && ! EQ (value, Qunbound))
3931 store_frame_param (f, param, value);
3933 return value;
3937 /* Record in frame F the specified or default value according to ALIST
3938 of the parameter named PROP (a Lisp symbol).
3939 If no value is specified for PROP, look for an X default for XPROP
3940 on the frame named NAME.
3941 If that is not found either, use the value DEFLT. */
3943 Lisp_Object
3944 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
3945 struct frame *f;
3946 Lisp_Object alist;
3947 Lisp_Object prop;
3948 Lisp_Object deflt;
3949 char *xprop;
3950 char *xclass;
3951 enum resource_types type;
3953 Lisp_Object tem;
3955 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3956 if (EQ (tem, Qunbound))
3957 tem = deflt;
3958 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3959 return tem;
3965 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3966 doc: /* Parse an X-style geometry string STRING.
3967 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3968 The properties returned may include `top', `left', `height', and `width'.
3969 The value of `left' or `top' may be an integer,
3970 or a list (+ N) meaning N pixels relative to top/left corner,
3971 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3972 (string)
3973 Lisp_Object string;
3975 int geometry, x, y;
3976 unsigned int width, height;
3977 Lisp_Object result;
3979 CHECK_STRING (string);
3981 geometry = XParseGeometry ((char *) SDATA (string),
3982 &x, &y, &width, &height);
3984 #if 0
3985 if (!!(geometry & XValue) != !!(geometry & YValue))
3986 error ("Must specify both x and y position, or neither");
3987 #endif
3989 result = Qnil;
3990 if (geometry & XValue)
3992 Lisp_Object element;
3994 if (x >= 0 && (geometry & XNegative))
3995 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3996 else if (x < 0 && ! (geometry & XNegative))
3997 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3998 else
3999 element = Fcons (Qleft, make_number (x));
4000 result = Fcons (element, result);
4003 if (geometry & YValue)
4005 Lisp_Object element;
4007 if (y >= 0 && (geometry & YNegative))
4008 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
4009 else if (y < 0 && ! (geometry & YNegative))
4010 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
4011 else
4012 element = Fcons (Qtop, make_number (y));
4013 result = Fcons (element, result);
4016 if (geometry & WidthValue)
4017 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4018 if (geometry & HeightValue)
4019 result = Fcons (Fcons (Qheight, make_number (height)), result);
4021 return result;
4024 /* Calculate the desired size and position of frame F.
4025 Return the flags saying which aspects were specified.
4027 Also set the win_gravity and size_hint_flags of F.
4029 Adjust height for toolbar if TOOLBAR_P is 1.
4031 This function does not make the coordinates positive. */
4033 #define DEFAULT_ROWS 40
4034 #define DEFAULT_COLS 80
4037 x_figure_window_size (f, parms, toolbar_p)
4038 struct frame *f;
4039 Lisp_Object parms;
4040 int toolbar_p;
4042 register Lisp_Object tem0, tem1, tem2;
4043 long window_prompting = 0;
4044 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
4046 /* Default values if we fall through.
4047 Actually, if that happens we should get
4048 window manager prompting. */
4049 SET_FRAME_COLS (f, DEFAULT_COLS);
4050 FRAME_LINES (f) = DEFAULT_ROWS;
4051 /* Window managers expect that if program-specified
4052 positions are not (0,0), they're intentional, not defaults. */
4053 f->top_pos = 0;
4054 f->left_pos = 0;
4056 /* Ensure that old new_text_cols and new_text_lines will not override the
4057 values set here. */
4058 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4059 f->new_text_cols = f->new_text_lines = 0;
4061 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4062 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4063 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4064 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4066 if (!EQ (tem0, Qunbound))
4068 CHECK_NUMBER (tem0);
4069 FRAME_LINES (f) = XINT (tem0);
4071 if (!EQ (tem1, Qunbound))
4073 CHECK_NUMBER (tem1);
4074 SET_FRAME_COLS (f, XINT (tem1));
4076 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4077 window_prompting |= USSize;
4078 else
4079 window_prompting |= PSize;
4082 f->scroll_bar_actual_width
4083 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4085 /* This used to be done _before_ calling x_figure_window_size, but
4086 since the height is reset here, this was really a no-op. I
4087 assume that moving it here does what Gerd intended (although he
4088 no longer can remember what that was... ++KFS, 2003-03-25. */
4090 /* Add the tool-bar height to the initial frame height so that the
4091 user gets a text display area of the size he specified with -g or
4092 via .Xdefaults. Later changes of the tool-bar height don't
4093 change the frame size. This is done so that users can create
4094 tall Emacs frames without having to guess how tall the tool-bar
4095 will get. */
4096 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4098 int margin, relief, bar_height;
4100 relief = (tool_bar_button_relief >= 0
4101 ? tool_bar_button_relief
4102 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4104 if (INTEGERP (Vtool_bar_button_margin)
4105 && XINT (Vtool_bar_button_margin) > 0)
4106 margin = XFASTINT (Vtool_bar_button_margin);
4107 else if (CONSP (Vtool_bar_button_margin)
4108 && INTEGERP (XCDR (Vtool_bar_button_margin))
4109 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
4110 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4111 else
4112 margin = 0;
4114 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4115 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4118 compute_fringe_widths (f, 0);
4120 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4121 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4123 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4124 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4125 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4126 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4128 if (EQ (tem0, Qminus))
4130 f->top_pos = 0;
4131 window_prompting |= YNegative;
4133 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4134 && CONSP (XCDR (tem0))
4135 && INTEGERP (XCAR (XCDR (tem0))))
4137 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4138 window_prompting |= YNegative;
4140 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4141 && CONSP (XCDR (tem0))
4142 && INTEGERP (XCAR (XCDR (tem0))))
4144 f->top_pos = XINT (XCAR (XCDR (tem0)));
4146 else if (EQ (tem0, Qunbound))
4147 f->top_pos = 0;
4148 else
4150 CHECK_NUMBER (tem0);
4151 f->top_pos = XINT (tem0);
4152 if (f->top_pos < 0)
4153 window_prompting |= YNegative;
4156 if (EQ (tem1, Qminus))
4158 f->left_pos = 0;
4159 window_prompting |= XNegative;
4161 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4162 && CONSP (XCDR (tem1))
4163 && INTEGERP (XCAR (XCDR (tem1))))
4165 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4166 window_prompting |= XNegative;
4168 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4169 && CONSP (XCDR (tem1))
4170 && INTEGERP (XCAR (XCDR (tem1))))
4172 f->left_pos = XINT (XCAR (XCDR (tem1)));
4174 else if (EQ (tem1, Qunbound))
4175 f->left_pos = 0;
4176 else
4178 CHECK_NUMBER (tem1);
4179 f->left_pos = XINT (tem1);
4180 if (f->left_pos < 0)
4181 window_prompting |= XNegative;
4184 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4185 window_prompting |= USPosition;
4186 else
4187 window_prompting |= PPosition;
4190 if (f->want_fullscreen != FULLSCREEN_NONE)
4192 int left, top;
4193 int width, height;
4195 /* It takes both for some WM:s to place it where we want */
4196 window_prompting = USPosition | PPosition;
4197 x_fullscreen_adjust (f, &width, &height, &top, &left);
4198 FRAME_COLS (f) = width;
4199 FRAME_LINES (f) = height;
4200 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
4201 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
4202 f->left_pos = left;
4203 f->top_pos = top;
4206 if (window_prompting & XNegative)
4208 if (window_prompting & YNegative)
4209 f->win_gravity = SouthEastGravity;
4210 else
4211 f->win_gravity = NorthEastGravity;
4213 else
4215 if (window_prompting & YNegative)
4216 f->win_gravity = SouthWestGravity;
4217 else
4218 f->win_gravity = NorthWestGravity;
4221 f->size_hint_flags = window_prompting;
4223 return window_prompting;
4228 #endif /* HAVE_WINDOW_SYSTEM */
4232 /***********************************************************************
4233 Initialization
4234 ***********************************************************************/
4236 void
4237 syms_of_frame ()
4239 Qframep = intern ("framep");
4240 staticpro (&Qframep);
4241 Qframe_live_p = intern ("frame-live-p");
4242 staticpro (&Qframe_live_p);
4243 Qheight = intern ("height");
4244 staticpro (&Qheight);
4245 Qicon = intern ("icon");
4246 staticpro (&Qicon);
4247 Qminibuffer = intern ("minibuffer");
4248 staticpro (&Qminibuffer);
4249 Qmodeline = intern ("modeline");
4250 staticpro (&Qmodeline);
4251 Qonly = intern ("only");
4252 staticpro (&Qonly);
4253 Qwidth = intern ("width");
4254 staticpro (&Qwidth);
4255 Qgeometry = intern ("geometry");
4256 staticpro (&Qgeometry);
4257 Qicon_left = intern ("icon-left");
4258 staticpro (&Qicon_left);
4259 Qicon_top = intern ("icon-top");
4260 staticpro (&Qicon_top);
4261 Qleft = intern ("left");
4262 staticpro (&Qleft);
4263 Qright = intern ("right");
4264 staticpro (&Qright);
4265 Quser_position = intern ("user-position");
4266 staticpro (&Quser_position);
4267 Quser_size = intern ("user-size");
4268 staticpro (&Quser_size);
4269 Qwindow_id = intern ("window-id");
4270 staticpro (&Qwindow_id);
4271 #ifdef HAVE_X_WINDOWS
4272 Qouter_window_id = intern ("outer-window-id");
4273 staticpro (&Qouter_window_id);
4274 #endif
4275 Qparent_id = intern ("parent-id");
4276 staticpro (&Qparent_id);
4277 Qx = intern ("x");
4278 staticpro (&Qx);
4279 Qw32 = intern ("w32");
4280 staticpro (&Qw32);
4281 Qpc = intern ("pc");
4282 staticpro (&Qpc);
4283 Qmac = intern ("mac");
4284 staticpro (&Qmac);
4285 Qvisible = intern ("visible");
4286 staticpro (&Qvisible);
4287 Qbuffer_predicate = intern ("buffer-predicate");
4288 staticpro (&Qbuffer_predicate);
4289 Qbuffer_list = intern ("buffer-list");
4290 staticpro (&Qbuffer_list);
4291 Qburied_buffer_list = intern ("buried-buffer-list");
4292 staticpro (&Qburied_buffer_list);
4293 Qdisplay_type = intern ("display-type");
4294 staticpro (&Qdisplay_type);
4295 Qbackground_mode = intern ("background-mode");
4296 staticpro (&Qbackground_mode);
4297 Qtty_color_mode = intern ("tty-color-mode");
4298 staticpro (&Qtty_color_mode);
4299 Qtty = intern ("tty");
4300 staticpro (&Qtty);
4301 Qtty_type = intern ("tty-type");
4302 staticpro (&Qtty_type);
4303 Qwindow_system = intern ("window-system");
4304 staticpro (&Qwindow_system);
4305 Qenvironment = intern ("environment");
4306 staticpro (&Qenvironment);
4308 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4309 staticpro (&Qface_set_after_frame_default);
4311 Qfullwidth = intern ("fullwidth");
4312 staticpro (&Qfullwidth);
4313 Qfullheight = intern ("fullheight");
4314 staticpro (&Qfullheight);
4315 Qfullboth = intern ("fullboth");
4316 staticpro (&Qfullboth);
4317 Qx_resource_name = intern ("x-resource-name");
4318 staticpro (&Qx_resource_name);
4320 Qx_frame_parameter = intern ("x-frame-parameter");
4321 staticpro (&Qx_frame_parameter);
4323 Qterminal = intern ("terminal");
4324 staticpro (&Qterminal);
4325 Qterminal_live_p = intern ("terminal-live-p");
4326 staticpro (&Qterminal_live_p);
4329 int i;
4331 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4333 Lisp_Object v = intern (frame_parms[i].name);
4334 if (frame_parms[i].variable)
4336 *frame_parms[i].variable = v;
4337 staticpro (frame_parms[i].variable);
4339 Fput (v, Qx_frame_parameter, make_number (i));
4343 #ifdef HAVE_WINDOW_SYSTEM
4344 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4345 doc: /* The name Emacs uses to look up X resources.
4346 `x-get-resource' uses this as the first component of the instance name
4347 when requesting resource values.
4348 Emacs initially sets `x-resource-name' to the name under which Emacs
4349 was invoked, or to the value specified with the `-name' or `-rn'
4350 switches, if present.
4352 It may be useful to bind this variable locally around a call
4353 to `x-get-resource'. See also the variable `x-resource-class'. */);
4354 Vx_resource_name = Qnil;
4356 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4357 doc: /* The class Emacs uses to look up X resources.
4358 `x-get-resource' uses this as the first component of the instance class
4359 when requesting resource values.
4361 Emacs initially sets `x-resource-class' to "Emacs".
4363 Setting this variable permanently is not a reasonable thing to do,
4364 but binding this variable locally around a call to `x-get-resource'
4365 is a reasonable practice. See also the variable `x-resource-name'. */);
4366 Vx_resource_class = build_string (EMACS_CLASS);
4367 #endif
4369 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4370 doc: /* Alist of default values for frame creation.
4371 These may be set in your init file, like this:
4372 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4373 These override values given in window system configuration data,
4374 including X Windows' defaults database.
4375 For values specific to the first Emacs frame, see `initial-frame-alist'.
4376 For values specific to the separate minibuffer frame, see
4377 `minibuffer-frame-alist'.
4378 The `menu-bar-lines' element of the list controls whether new frames
4379 have menu bars; `menu-bar-mode' works by altering this element.
4380 Setting this variable does not affect existing frames, only new ones. */);
4381 Vdefault_frame_alist = Qnil;
4383 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4384 doc: /* Default position of scroll bars on this window-system. */);
4385 #ifdef HAVE_WINDOW_SYSTEM
4386 #if defined(HAVE_NTGUI) || defined(MAC_OS)
4387 /* MS-Windows has scroll bars on the right by default. */
4388 Vdefault_frame_scroll_bars = Qright;
4389 #else
4390 Vdefault_frame_scroll_bars = Qleft;
4391 #endif
4392 #else
4393 Vdefault_frame_scroll_bars = Qnil;
4394 #endif
4396 Qinhibit_default_face_x_resources
4397 = intern ("inhibit-default-face-x-resources");
4398 staticpro (&Qinhibit_default_face_x_resources);
4400 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4401 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4403 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4404 doc: /* Non-nil if all of emacs is iconified and frame updates are not needed. */);
4405 Vemacs_iconified = Qnil;
4407 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4408 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4409 `mouse-position' calls this function, passing its usual return value as
4410 argument, and returns whatever this function returns.
4411 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4412 which need to do mouse handling at the Lisp level. */);
4413 Vmouse_position_function = Qnil;
4415 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4416 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4417 If the value is an integer, highlighting is only shown after moving the
4418 mouse, while keyboard input turns off the highlight even when the mouse
4419 is over the clickable text. However, the mouse shape still indicates
4420 when the mouse is over clickable text. */);
4421 Vmouse_highlight = Qt;
4423 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4424 doc: /* Functions to be run before deleting a frame.
4425 The functions are run with one arg, the frame to be deleted.
4426 See `delete-frame'.
4428 Note that functions in this list may be called twice on the same
4429 frame. In the second invocation, the frame is already deleted, and
4430 the function should do nothing. (You can use `frame-live-p' to check
4431 for this.) This wrinkle happens when an earlier function in
4432 `delete-frame-functions' (indirectly) calls delete-frame
4433 recursively. */);
4434 Vdelete_frame_functions = Qnil;
4436 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4437 doc: /* Minibufferless frames use this frame's minibuffer.
4439 Emacs cannot create minibufferless frames unless this is set to an
4440 appropriate surrogate.
4442 Emacs consults this variable only when creating minibufferless
4443 frames; once the frame is created, it sticks with its assigned
4444 minibuffer, no matter what this variable is set to. This means that
4445 this variable doesn't necessarily say anything meaningful about the
4446 current set of frames, or where the minibuffer is currently being
4447 displayed.
4449 This variable is local to the current terminal and cannot be buffer-local. */);
4451 staticpro (&Vframe_list);
4453 defsubr (&Sactive_minibuffer_window);
4454 defsubr (&Sframep);
4455 defsubr (&Sframe_live_p);
4456 defsubr (&Swindow_system);
4457 defsubr (&Smake_terminal_frame);
4458 defsubr (&Shandle_switch_frame);
4459 defsubr (&Sselect_frame);
4460 defsubr (&Sselected_frame);
4461 defsubr (&Swindow_frame);
4462 defsubr (&Sframe_root_window);
4463 defsubr (&Sframe_first_window);
4464 defsubr (&Sframe_selected_window);
4465 defsubr (&Sset_frame_selected_window);
4466 defsubr (&Sframe_list);
4467 defsubr (&Snext_frame);
4468 defsubr (&Sprevious_frame);
4469 defsubr (&Sdelete_frame);
4470 defsubr (&Smouse_position);
4471 defsubr (&Smouse_pixel_position);
4472 defsubr (&Sset_mouse_position);
4473 defsubr (&Sset_mouse_pixel_position);
4474 #if 0
4475 defsubr (&Sframe_configuration);
4476 defsubr (&Srestore_frame_configuration);
4477 #endif
4478 defsubr (&Smake_frame_visible);
4479 defsubr (&Smake_frame_invisible);
4480 defsubr (&Siconify_frame);
4481 defsubr (&Sframe_visible_p);
4482 defsubr (&Svisible_frame_list);
4483 defsubr (&Sraise_frame);
4484 defsubr (&Slower_frame);
4485 defsubr (&Sredirect_frame_focus);
4486 defsubr (&Sframe_focus);
4487 defsubr (&Sframe_parameters);
4488 defsubr (&Sframe_parameter);
4489 defsubr (&Smodify_frame_parameters);
4490 defsubr (&Sframe_with_environment);
4491 defsubr (&Sframe_char_height);
4492 defsubr (&Sframe_char_width);
4493 defsubr (&Sframe_pixel_height);
4494 defsubr (&Sframe_pixel_width);
4495 defsubr (&Sset_frame_height);
4496 defsubr (&Sset_frame_width);
4497 defsubr (&Sset_frame_size);
4498 defsubr (&Sset_frame_position);
4500 #ifdef HAVE_WINDOW_SYSTEM
4501 defsubr (&Sx_get_resource);
4502 defsubr (&Sx_parse_geometry);
4503 #endif
4507 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4508 (do not change this comment) */