(w32_system_process_attributes) [_MSC_VER < 1300]: Alternative calculation
[emacs.git] / src / frame.c
blob7e482d6a5daf805de4095a4e35e4fa21b542159e
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) 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. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <ctype.h>
24 #include "lisp.h"
25 #include "character.h"
26 #ifdef HAVE_X_WINDOWS
27 #include "xterm.h"
28 #endif
29 #ifdef WINDOWSNT
30 #include "w32term.h"
31 #endif
32 #ifdef HAVE_NS
33 #include "nsterm.h"
34 #endif
35 #include "buffer.h"
36 /* These help us bind and responding to switch-frame events. */
37 #include "commands.h"
38 #include "keyboard.h"
39 #include "frame.h"
40 #include "blockinput.h"
41 #include "termchar.h"
42 #include "termhooks.h"
43 #include "dispextern.h"
44 #include "window.h"
45 #ifdef HAVE_WINDOW_SYSTEM
46 #include "font.h"
47 #include "fontset.h"
48 #endif
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 /* Lower limit value of the frame opacity (alpha transparency). */
68 Lisp_Object Vframe_alpha_lower_limit;
70 #endif
72 #ifdef HAVE_NS
73 Lisp_Object Qns_parse_geometry;
74 #endif
76 Lisp_Object Qframep, Qframe_live_p;
77 Lisp_Object Qicon, Qmodeline;
78 Lisp_Object Qonly;
79 Lisp_Object Qx, Qw32, Qmac, Qpc, Qns;
80 Lisp_Object Qvisible;
81 Lisp_Object Qdisplay_type;
82 Lisp_Object Qbackground_mode;
83 Lisp_Object Qnoelisp;
85 Lisp_Object Qx_frame_parameter;
86 Lisp_Object Qx_resource_name;
87 Lisp_Object Qterminal;
88 Lisp_Object Qterminal_live_p;
90 /* Frame parameters (set or reported). */
92 Lisp_Object Qauto_raise, Qauto_lower;
93 Lisp_Object Qborder_color, Qborder_width;
94 Lisp_Object Qcursor_color, Qcursor_type;
95 Lisp_Object Qgeometry; /* Not used */
96 Lisp_Object Qheight, Qwidth;
97 Lisp_Object Qleft, Qright;
98 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
99 Lisp_Object Qinternal_border_width;
100 Lisp_Object Qmouse_color;
101 Lisp_Object Qminibuffer;
102 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
103 Lisp_Object Qvisibility;
104 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
105 Lisp_Object Qscreen_gamma;
106 Lisp_Object Qline_spacing;
107 Lisp_Object Quser_position, Quser_size;
108 Lisp_Object Qwait_for_wm;
109 Lisp_Object Qwindow_id;
110 #ifdef HAVE_X_WINDOWS
111 Lisp_Object Qouter_window_id;
112 #endif
113 Lisp_Object Qparent_id;
114 Lisp_Object Qtitle, Qname;
115 Lisp_Object Qexplicit_name;
116 Lisp_Object Qunsplittable;
117 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
118 Lisp_Object Qleft_fringe, Qright_fringe;
119 Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list;
120 Lisp_Object Qtty_color_mode;
121 Lisp_Object Qtty, Qtty_type;
123 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
124 Lisp_Object Qfont_backend;
125 Lisp_Object Qalpha;
127 Lisp_Object Qface_set_after_frame_default;
129 Lisp_Object Vterminal_frame;
130 Lisp_Object Vdefault_frame_alist;
131 Lisp_Object Vdefault_frame_scroll_bars;
132 Lisp_Object Vmouse_position_function;
133 Lisp_Object Vmouse_highlight;
134 static Lisp_Object Vdelete_frame_functions, Qdelete_frame_functions;
136 int focus_follows_mouse;
138 static void
139 set_menu_bar_lines_1 (window, n)
140 Lisp_Object window;
141 int n;
143 struct window *w = XWINDOW (window);
145 XSETFASTINT (w->last_modified, 0);
146 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
147 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
149 if (INTEGERP (w->orig_top_line))
150 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
151 if (INTEGERP (w->orig_total_lines))
152 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
154 /* Handle just the top child in a vertical split. */
155 if (!NILP (w->vchild))
156 set_menu_bar_lines_1 (w->vchild, n);
158 /* Adjust all children in a horizontal split. */
159 for (window = w->hchild; !NILP (window); window = w->next)
161 w = XWINDOW (window);
162 set_menu_bar_lines_1 (window, n);
166 void
167 set_menu_bar_lines (f, value, oldval)
168 struct frame *f;
169 Lisp_Object value, oldval;
171 int nlines;
172 int olines = FRAME_MENU_BAR_LINES (f);
174 /* Right now, menu bars don't work properly in minibuf-only frames;
175 most of the commands try to apply themselves to the minibuffer
176 frame itself, and get an error because you can't switch buffers
177 in or split the minibuffer window. */
178 if (FRAME_MINIBUF_ONLY_P (f))
179 return;
181 if (INTEGERP (value))
182 nlines = XINT (value);
183 else
184 nlines = 0;
186 if (nlines != olines)
188 windows_or_buffers_changed++;
189 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
190 FRAME_MENU_BAR_LINES (f) = nlines;
191 set_menu_bar_lines_1 (f->root_window, nlines - olines);
192 adjust_glyphs (f);
196 Lisp_Object Vemacs_iconified;
197 Lisp_Object Vframe_list;
199 extern Lisp_Object Vminibuffer_list;
200 extern Lisp_Object get_minibuffer ();
201 extern Lisp_Object Fhandle_switch_frame ();
202 extern Lisp_Object Fredirect_frame_focus ();
203 extern Lisp_Object x_get_focus_frame ();
205 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
206 doc: /* Return non-nil if OBJECT is a frame.
207 Value is t for a termcap frame (a character-only terminal),
208 `x' for an Emacs frame that is really an X window,
209 `w32' for an Emacs frame that is a window on MS-Windows display,
210 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
211 `pc' for a direct-write MS-DOS frame.
212 See also `frame-live-p'. */)
213 (object)
214 Lisp_Object object;
216 if (!FRAMEP (object))
217 return Qnil;
218 switch (XFRAME (object)->output_method)
220 case output_initial: /* The initial frame is like a termcap frame. */
221 case output_termcap:
222 return Qt;
223 case output_x_window:
224 return Qx;
225 case output_w32:
226 return Qw32;
227 case output_msdos_raw:
228 return Qpc;
229 case output_mac:
230 return Qmac;
231 case output_ns:
232 return Qns;
233 default:
234 abort ();
238 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
239 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
240 Value is nil if OBJECT is not a live frame. If object is a live
241 frame, the return value indicates what sort of terminal device it is
242 displayed on. See the documentation of `framep' for possible
243 return values. */)
244 (object)
245 Lisp_Object object;
247 return ((FRAMEP (object)
248 && FRAME_LIVE_P (XFRAME (object)))
249 ? Fframep (object)
250 : Qnil);
253 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
254 doc: /* The name of the window system that FRAME is displaying through.
255 The value is a symbol---for instance, 'x' for X windows.
256 The value is nil if Emacs is using a text-only terminal.
258 FRAME defaults to the currently selected frame. */)
259 (frame)
260 Lisp_Object frame;
262 Lisp_Object type;
263 if (NILP (frame))
264 frame = selected_frame;
266 type = Fframep (frame);
268 if (NILP (type))
269 wrong_type_argument (Qframep, frame);
271 if (EQ (type, Qt))
272 return Qnil;
273 else
274 return type;
277 struct frame *
278 make_frame (mini_p)
279 int mini_p;
281 Lisp_Object frame;
282 register struct frame *f;
283 register Lisp_Object root_window;
284 register Lisp_Object mini_window;
286 f = allocate_frame ();
287 XSETFRAME (frame, f);
289 f->desired_matrix = 0;
290 f->current_matrix = 0;
291 f->desired_pool = 0;
292 f->current_pool = 0;
293 f->glyphs_initialized_p = 0;
294 f->decode_mode_spec_buffer = 0;
295 f->visible = 0;
296 f->async_visible = 0;
297 f->output_data.nothing = 0;
298 f->iconified = 0;
299 f->async_iconified = 0;
300 f->wants_modeline = 1;
301 f->auto_raise = 0;
302 f->auto_lower = 0;
303 f->no_split = 0;
304 f->garbaged = 1;
305 f->has_minibuffer = mini_p;
306 f->focus_frame = Qnil;
307 f->explicit_name = 0;
308 f->can_have_scroll_bars = 0;
309 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
310 f->param_alist = Qnil;
311 f->scroll_bars = Qnil;
312 f->condemned_scroll_bars = Qnil;
313 f->face_alist = Qnil;
314 f->face_cache = NULL;
315 f->menu_bar_items = Qnil;
316 f->menu_bar_vector = Qnil;
317 f->menu_bar_items_used = 0;
318 f->buffer_predicate = Qnil;
319 f->buffer_list = Qnil;
320 f->buried_buffer_list = Qnil;
321 f->namebuf = 0;
322 f->title = Qnil;
323 f->menu_bar_window = Qnil;
324 f->tool_bar_window = Qnil;
325 f->tool_bar_items = Qnil;
326 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
327 f->n_tool_bar_items = 0;
328 f->left_fringe_width = f->right_fringe_width = 0;
329 f->fringe_cols = 0;
330 f->scroll_bar_actual_width = 0;
331 f->border_width = 0;
332 f->internal_border_width = 0;
333 f->column_width = 1; /* !FRAME_WINDOW_P value */
334 f->line_height = 1; /* !FRAME_WINDOW_P value */
335 f->x_pixels_diff = f->y_pixels_diff = 0;
336 #ifdef HAVE_WINDOW_SYSTEM
337 f->want_fullscreen = FULLSCREEN_NONE;
338 #endif
339 f->size_hint_flags = 0;
340 f->win_gravity = 0;
341 f->font_driver_list = NULL;
342 f->font_data_list = NULL;
344 root_window = make_window ();
345 if (mini_p)
347 mini_window = make_window ();
348 XWINDOW (root_window)->next = mini_window;
349 XWINDOW (mini_window)->prev = root_window;
350 XWINDOW (mini_window)->mini_p = Qt;
351 XWINDOW (mini_window)->frame = frame;
352 f->minibuffer_window = mini_window;
354 else
356 mini_window = Qnil;
357 XWINDOW (root_window)->next = Qnil;
358 f->minibuffer_window = Qnil;
361 XWINDOW (root_window)->frame = frame;
363 /* 10 is arbitrary,
364 just so that there is "something there."
365 Correct size will be set up later with change_frame_size. */
367 SET_FRAME_COLS (f, 10);
368 FRAME_LINES (f) = 10;
370 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
371 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
373 if (mini_p)
375 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
376 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
377 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
380 /* Choose a buffer for the frame's root window. */
382 Lisp_Object buf;
384 XWINDOW (root_window)->buffer = Qt;
385 buf = Fcurrent_buffer ();
386 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
387 a space), try to find another one. */
388 if (SREF (Fbuffer_name (buf), 0) == ' ')
389 buf = Fother_buffer (buf, Qnil, Qnil);
391 /* Use set_window_buffer, not Fset_window_buffer, and don't let
392 hooks be run by it. The reason is that the whole frame/window
393 arrangement is not yet fully intialized at this point. Windows
394 don't have the right size, glyph matrices aren't initialized
395 etc. Running Lisp functions at this point surely ends in a
396 SEGV. */
397 set_window_buffer (root_window, buf, 0, 0);
398 f->buffer_list = Fcons (buf, Qnil);
401 if (mini_p)
403 XWINDOW (mini_window)->buffer = Qt;
404 set_window_buffer (mini_window,
405 (NILP (Vminibuffer_list)
406 ? get_minibuffer (0)
407 : Fcar (Vminibuffer_list)),
408 0, 0);
411 f->root_window = root_window;
412 f->selected_window = root_window;
413 /* Make sure this window seems more recently used than
414 a newly-created, never-selected window. */
415 ++window_select_count;
416 XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
418 f->default_face_done_p = 0;
420 return f;
423 #ifdef HAVE_WINDOW_SYSTEM
424 /* Make a frame using a separate minibuffer window on another frame.
425 MINI_WINDOW is the minibuffer window to use. nil means use the
426 default (the global minibuffer). */
428 struct frame *
429 make_frame_without_minibuffer (mini_window, kb, display)
430 register Lisp_Object mini_window;
431 KBOARD *kb;
432 Lisp_Object display;
434 register struct frame *f;
435 struct gcpro gcpro1;
437 if (!NILP (mini_window))
438 CHECK_LIVE_WINDOW (mini_window);
440 if (!NILP (mini_window)
441 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
442 error ("Frame and minibuffer must be on the same terminal");
444 /* Make a frame containing just a root window. */
445 f = make_frame (0);
447 if (NILP (mini_window))
449 /* Use default-minibuffer-frame if possible. */
450 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
451 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
453 Lisp_Object frame_dummy;
455 XSETFRAME (frame_dummy, f);
456 GCPRO1 (frame_dummy);
457 /* If there's no minibuffer frame to use, create one. */
458 kb->Vdefault_minibuffer_frame =
459 call1 (intern ("make-initial-minibuffer-frame"), display);
460 UNGCPRO;
463 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
466 f->minibuffer_window = mini_window;
468 /* Make the chosen minibuffer window display the proper minibuffer,
469 unless it is already showing a minibuffer. */
470 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
471 Fset_window_buffer (mini_window,
472 (NILP (Vminibuffer_list)
473 ? get_minibuffer (0)
474 : Fcar (Vminibuffer_list)), Qnil);
475 return f;
478 /* Make a frame containing only a minibuffer window. */
480 struct frame *
481 make_minibuffer_frame ()
483 /* First make a frame containing just a root window, no minibuffer. */
485 register struct frame *f = make_frame (0);
486 register Lisp_Object mini_window;
487 register Lisp_Object frame;
489 XSETFRAME (frame, f);
491 f->auto_raise = 0;
492 f->auto_lower = 0;
493 f->no_split = 1;
494 f->wants_modeline = 0;
495 f->has_minibuffer = 1;
497 /* Now label the root window as also being the minibuffer.
498 Avoid infinite looping on the window chain by marking next pointer
499 as nil. */
501 mini_window = f->minibuffer_window = f->root_window;
502 XWINDOW (mini_window)->mini_p = Qt;
503 XWINDOW (mini_window)->next = Qnil;
504 XWINDOW (mini_window)->prev = Qnil;
505 XWINDOW (mini_window)->frame = frame;
507 /* Put the proper buffer in that window. */
509 Fset_window_buffer (mini_window,
510 (NILP (Vminibuffer_list)
511 ? get_minibuffer (0)
512 : Fcar (Vminibuffer_list)), Qnil);
513 return f;
515 #endif /* HAVE_WINDOW_SYSTEM */
517 /* Construct a frame that refers to a terminal. */
519 static int tty_frame_count;
521 struct frame *
522 make_initial_frame (void)
524 struct frame *f;
525 struct terminal *terminal;
526 Lisp_Object frame;
528 eassert (initial_kboard);
530 /* The first call must initialize Vframe_list. */
531 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
532 Vframe_list = Qnil;
534 terminal = init_initial_terminal ();
536 f = make_frame (1);
537 XSETFRAME (frame, f);
539 Vframe_list = Fcons (frame, Vframe_list);
541 tty_frame_count = 1;
542 f->name = build_string ("F1");
544 f->visible = 1;
545 f->async_visible = 1;
547 f->output_method = terminal->type;
548 f->terminal = terminal;
549 f->terminal->reference_count++;
550 f->output_data.nothing = 0;
552 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
553 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
555 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
556 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
558 #ifdef CANNOT_DUMP
559 if (!noninteractive)
560 init_frame_faces (f);
561 #endif
563 return f;
567 struct frame *
568 make_terminal_frame (struct terminal *terminal)
570 register struct frame *f;
571 Lisp_Object frame;
572 char name[20];
574 if (!terminal->name)
575 error ("Terminal is not live, can't create new frames on it");
577 f = make_frame (1);
579 XSETFRAME (frame, f);
580 Vframe_list = Fcons (frame, Vframe_list);
582 tty_frame_count++;
583 sprintf (name, "F%d", tty_frame_count);
584 f->name = build_string (name);
586 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
587 f->async_visible = 1; /* Don't let visible be cleared later. */
588 #ifdef MSDOS
589 f->output_data.x = &the_only_x_display;
590 if (!inhibit_window_system
591 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
592 || XFRAME (selected_frame)->output_method == output_msdos_raw))
594 f->output_method = output_msdos_raw;
595 /* This initialization of foreground and background pixels is
596 only important for the initial frame created in temacs. If
597 we don't do that, we get black background and foreground in
598 the dumped Emacs because the_only_x_display is a static
599 variable, hence it is born all-zeroes, and zero is the code
600 for the black color. Other frames all inherit their pixels
601 from what's already in the_only_x_display. */
602 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
603 && FRAME_BACKGROUND_PIXEL (f) == 0
604 && FRAME_FOREGROUND_PIXEL (f) == 0)
606 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
607 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
610 else
611 f->output_method = output_termcap;
612 #else
614 f->output_method = output_termcap;
615 f->terminal = terminal;
616 f->terminal->reference_count++;
617 create_tty_output (f);
619 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
620 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
622 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
623 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
625 /* Set the top frame to the newly created frame. */
626 if (FRAMEP (FRAME_TTY (f)->top_frame)
627 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
628 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
630 FRAME_TTY (f)->top_frame = frame;
633 #ifdef CANNOT_DUMP
634 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
635 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
636 #endif
637 #endif /* MSDOS */
639 if (!noninteractive)
640 init_frame_faces (f);
642 return f;
645 /* Get a suitable value for frame parameter PARAMETER for a newly
646 created frame, based on (1) the user-supplied frame parameter
647 alist SUPPLIED_PARMS, (2) CURRENT_VALUE, and finally, if all else
648 fails, (3) Vdefault_frame_alist. */
650 static Lisp_Object
651 get_future_frame_param (Lisp_Object parameter,
652 Lisp_Object supplied_parms,
653 char *current_value)
655 Lisp_Object result;
657 result = Fassq (parameter, supplied_parms);
658 if (NILP (result))
659 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
660 if (NILP (result) && current_value != NULL)
661 result = build_string (current_value);
662 if (NILP (result))
663 result = Fassq (parameter, Vdefault_frame_alist);
664 if (!NILP (result) && !STRINGP (result))
665 result = XCDR (result);
666 if (NILP (result) || !STRINGP (result))
667 result = Qnil;
669 return result;
672 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
673 1, 1, 0,
674 doc: /* Create an additional terminal frame, possibly on another terminal.
675 This function takes one argument, an alist specifying frame parameters.
677 You can create multiple frames on a single text-only terminal, but
678 only one of them (the selected terminal frame) is actually displayed.
680 In practice, generally you don't need to specify any parameters,
681 except when you want to create a new frame on another terminal.
682 In that case, the `tty' parameter specifies the device file to open,
683 and the `tty-type' parameter specifies the terminal type. Example:
685 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
687 Note that changing the size of one terminal frame automatically
688 affects all frames on the same terminal device. */)
689 (parms)
690 Lisp_Object parms;
692 struct frame *f;
693 struct terminal *t = NULL;
694 Lisp_Object frame, tem;
695 struct frame *sf = SELECTED_FRAME ();
697 #ifdef MSDOS
698 if (sf->output_method != output_msdos_raw
699 && sf->output_method != output_termcap)
700 abort ();
701 #else /* not MSDOS */
703 #if 0 /* This should work now! */
704 if (sf->output_method != output_termcap)
705 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
706 #endif
707 #endif /* not MSDOS */
710 Lisp_Object terminal;
712 terminal = Fassq (Qterminal, parms);
713 if (!NILP (terminal))
715 terminal = XCDR (terminal);
716 t = get_terminal (terminal, 1);
720 if (!t)
722 char *name = 0, *type = 0;
723 Lisp_Object tty, tty_type;
725 tty = get_future_frame_param
726 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
727 ? FRAME_TTY (XFRAME (selected_frame))->name
728 : NULL));
729 if (!NILP (tty))
731 name = (char *) alloca (SBYTES (tty) + 1);
732 strncpy (name, SDATA (tty), SBYTES (tty));
733 name[SBYTES (tty)] = 0;
736 tty_type = get_future_frame_param
737 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
738 ? FRAME_TTY (XFRAME (selected_frame))->type
739 : NULL));
740 if (!NILP (tty_type))
742 type = (char *) alloca (SBYTES (tty_type) + 1);
743 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
744 type[SBYTES (tty_type)] = 0;
747 t = init_tty (name, type, 0); /* Errors are not fatal. */
750 f = make_terminal_frame (t);
753 int width, height;
754 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
755 change_frame_size (f, height, width, 0, 0, 0);
758 adjust_glyphs (f);
759 calculate_costs (f);
760 XSETFRAME (frame, f);
761 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
762 Fmodify_frame_parameters (frame, parms);
763 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
764 build_string (t->display_info.tty->type)),
765 Qnil));
766 if (t->display_info.tty->name != NULL)
767 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
768 build_string (t->display_info.tty->name)),
769 Qnil));
770 else
771 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
773 /* Make the frame face alist be frame-specific, so that each
774 frame could change its face definitions independently. */
775 f->face_alist = Fcopy_alist (sf->face_alist);
776 /* Simple Fcopy_alist isn't enough, because we need the contents of
777 the vectors which are the CDRs of associations in face_alist to
778 be copied as well. */
779 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
780 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
781 return frame;
785 /* Perform the switch to frame FRAME.
787 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
788 FRAME1 as frame.
790 If TRACK is non-zero and the frame that currently has the focus
791 redirects its focus to the selected frame, redirect that focused
792 frame's focus to FRAME instead.
794 FOR_DELETION non-zero means that the selected frame is being
795 deleted, which includes the possibility that the frame's terminal
796 is dead. */
798 Lisp_Object
799 do_switch_frame (frame, track, for_deletion)
800 Lisp_Object frame;
801 int track, for_deletion;
803 struct frame *sf = SELECTED_FRAME ();
805 /* If FRAME is a switch-frame event, extract the frame we should
806 switch to. */
807 if (CONSP (frame)
808 && EQ (XCAR (frame), Qswitch_frame)
809 && CONSP (XCDR (frame)))
810 frame = XCAR (XCDR (frame));
812 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
813 a switch-frame event to arrive after a frame is no longer live,
814 especially when deleting the initial frame during startup. */
815 CHECK_FRAME (frame);
816 if (! FRAME_LIVE_P (XFRAME (frame)))
817 return Qnil;
819 if (sf == XFRAME (frame))
820 return frame;
822 /* This is too greedy; it causes inappropriate focus redirection
823 that's hard to get rid of. */
824 #if 0
825 /* If a frame's focus has been redirected toward the currently
826 selected frame, we should change the redirection to point to the
827 newly selected frame. This means that if the focus is redirected
828 from a minibufferless frame to a surrogate minibuffer frame, we
829 can use `other-window' to switch between all the frames using
830 that minibuffer frame, and the focus redirection will follow us
831 around. */
832 if (track)
834 Lisp_Object tail;
836 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
838 Lisp_Object focus;
840 if (!FRAMEP (XCAR (tail)))
841 abort ();
843 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
845 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
846 Fredirect_frame_focus (XCAR (tail), frame);
849 #else /* ! 0 */
850 /* Instead, apply it only to the frame we're pointing to. */
851 #ifdef HAVE_WINDOW_SYSTEM
852 if (track && FRAME_WINDOW_P (XFRAME (frame)))
854 Lisp_Object focus, xfocus;
856 xfocus = x_get_focus_frame (XFRAME (frame));
857 if (FRAMEP (xfocus))
859 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
860 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
861 Fredirect_frame_focus (xfocus, frame);
864 #endif /* HAVE_X_WINDOWS */
865 #endif /* ! 0 */
867 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
868 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
870 if (FRAME_TERMCAP_P (XFRAME (frame)))
872 if (FRAMEP (FRAME_TTY (XFRAME (frame))->top_frame))
873 /* Mark previously displayed frame as now obscured. */
874 XFRAME (FRAME_TTY (XFRAME (frame))->top_frame)->async_visible = 2;
875 XFRAME (frame)->async_visible = 1;
876 FRAME_TTY (XFRAME (frame))->top_frame = frame;
879 selected_frame = frame;
880 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
881 last_nonminibuf_frame = XFRAME (selected_frame);
883 Fselect_window (XFRAME (frame)->selected_window, Qnil);
885 #ifdef NS_IMPL_COCOA
886 /* term gets no other notification of this */
887 if (for_deletion)
888 Fraise_frame(Qnil);
889 #endif
891 /* We want to make sure that the next event generates a frame-switch
892 event to the appropriate frame. This seems kludgy to me, but
893 before you take it out, make sure that evaluating something like
894 (select-window (frame-root-window (new-frame))) doesn't end up
895 with your typing being interpreted in the new frame instead of
896 the one you're actually typing in. */
897 internal_last_event_frame = Qnil;
899 return frame;
902 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 1, "e",
903 doc: /* Select the frame FRAME.
904 Subsequent editing commands apply to its selected window.
905 The selection of FRAME lasts until the next time the user does
906 something to select a different frame, or until the next time this
907 function is called. If you are using a window system, the previously
908 selected frame may be restored as the selected frame after return to
909 the command loop, because it still may have the window system's input
910 focus. On a text-only terminal, the next redisplay will display FRAME.
912 This function returns FRAME, or nil if FRAME has been deleted. */)
913 (frame)
914 Lisp_Object frame;
916 return do_switch_frame (frame, 1, 0);
920 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
921 doc: /* Handle a switch-frame event EVENT.
922 Switch-frame events are usually bound to this function.
923 A switch-frame event tells Emacs that the window manager has requested
924 that the user's events be directed to the frame mentioned in the event.
925 This function selects the selected window of the frame of EVENT.
927 If EVENT is frame object, handle it as if it were a switch-frame event
928 to that frame. */)
929 (event)
930 Lisp_Object event;
932 /* Preserve prefix arg that the command loop just cleared. */
933 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
934 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
935 return do_switch_frame (event, 0, 0);
938 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
939 doc: /* Return the frame that is now selected. */)
942 return selected_frame;
945 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
946 doc: /* Return the frame object that window WINDOW is on. */)
947 (window)
948 Lisp_Object window;
950 CHECK_LIVE_WINDOW (window);
951 return XWINDOW (window)->frame;
954 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
955 doc: /* Returns the topmost, leftmost window of FRAME.
956 If omitted, FRAME defaults to the currently selected frame. */)
957 (frame)
958 Lisp_Object frame;
960 Lisp_Object w;
962 if (NILP (frame))
963 w = SELECTED_FRAME ()->root_window;
964 else
966 CHECK_LIVE_FRAME (frame);
967 w = XFRAME (frame)->root_window;
969 while (NILP (XWINDOW (w)->buffer))
971 if (! NILP (XWINDOW (w)->hchild))
972 w = XWINDOW (w)->hchild;
973 else if (! NILP (XWINDOW (w)->vchild))
974 w = XWINDOW (w)->vchild;
975 else
976 abort ();
978 return w;
981 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
982 Sactive_minibuffer_window, 0, 0, 0,
983 doc: /* Return the currently active minibuffer window, or nil if none. */)
986 return minibuf_level ? minibuf_window : Qnil;
989 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
990 doc: /* Returns the root-window of FRAME.
991 If omitted, FRAME defaults to the currently selected frame. */)
992 (frame)
993 Lisp_Object frame;
995 Lisp_Object window;
997 if (NILP (frame))
998 window = SELECTED_FRAME ()->root_window;
999 else
1001 CHECK_LIVE_FRAME (frame);
1002 window = XFRAME (frame)->root_window;
1005 return window;
1008 DEFUN ("frame-selected-window", Fframe_selected_window,
1009 Sframe_selected_window, 0, 1, 0,
1010 doc: /* Return the selected window of frame object FRAME.
1011 If omitted, FRAME defaults to the currently selected frame. */)
1012 (frame)
1013 Lisp_Object frame;
1015 Lisp_Object window;
1017 if (NILP (frame))
1018 window = SELECTED_FRAME ()->selected_window;
1019 else
1021 CHECK_LIVE_FRAME (frame);
1022 window = XFRAME (frame)->selected_window;
1025 return window;
1028 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
1029 Sset_frame_selected_window, 2, 2, 0,
1030 doc: /* Set the selected window of frame object FRAME to WINDOW.
1031 Return WINDOW.
1032 If FRAME is nil, the selected frame is used.
1033 If FRAME is the selected frame, this makes WINDOW the selected window. */)
1034 (frame, window)
1035 Lisp_Object frame, window;
1037 if (NILP (frame))
1038 frame = selected_frame;
1040 CHECK_LIVE_FRAME (frame);
1041 CHECK_LIVE_WINDOW (window);
1043 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
1044 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
1046 if (EQ (frame, selected_frame))
1047 return Fselect_window (window, Qnil);
1049 return XFRAME (frame)->selected_window = window;
1053 DEFUN ("frame-list", Fframe_list, Sframe_list,
1054 0, 0, 0,
1055 doc: /* Return a list of all frames. */)
1058 Lisp_Object frames;
1059 frames = Fcopy_sequence (Vframe_list);
1060 #ifdef HAVE_WINDOW_SYSTEM
1061 if (FRAMEP (tip_frame))
1062 frames = Fdelq (tip_frame, frames);
1063 #endif
1064 return frames;
1067 /* Return the next frame in the frame list after FRAME.
1068 If MINIBUF is nil, exclude minibuffer-only frames.
1069 If MINIBUF is a window, include only its own frame
1070 and any frame now using that window as the minibuffer.
1071 If MINIBUF is `visible', include all visible frames.
1072 If MINIBUF is 0, include all visible and iconified frames.
1073 Otherwise, include all frames. */
1075 static Lisp_Object
1076 next_frame (frame, minibuf)
1077 Lisp_Object frame;
1078 Lisp_Object minibuf;
1080 Lisp_Object tail;
1081 int passed = 0;
1083 /* There must always be at least one frame in Vframe_list. */
1084 if (! CONSP (Vframe_list))
1085 abort ();
1087 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
1088 forever. Forestall that. */
1089 CHECK_LIVE_FRAME (frame);
1091 while (1)
1092 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1094 Lisp_Object f;
1096 f = XCAR (tail);
1098 if (passed
1099 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1100 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1101 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1102 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
1104 /* Decide whether this frame is eligible to be returned. */
1106 /* If we've looped all the way around without finding any
1107 eligible frames, return the original frame. */
1108 if (EQ (f, frame))
1109 return f;
1111 /* Let minibuf decide if this frame is acceptable. */
1112 if (NILP (minibuf))
1114 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1115 return f;
1117 else if (EQ (minibuf, Qvisible))
1119 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1120 if (FRAME_VISIBLE_P (XFRAME (f)))
1121 return f;
1123 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1125 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1126 if (FRAME_VISIBLE_P (XFRAME (f))
1127 || FRAME_ICONIFIED_P (XFRAME (f)))
1128 return f;
1130 else if (WINDOWP (minibuf))
1132 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1133 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1134 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1135 FRAME_FOCUS_FRAME (XFRAME (f))))
1136 return f;
1138 else
1139 return f;
1142 if (EQ (frame, f))
1143 passed++;
1147 /* Return the previous frame in the frame list before FRAME.
1148 If MINIBUF is nil, exclude minibuffer-only frames.
1149 If MINIBUF is a window, include only its own frame
1150 and any frame now using that window as the minibuffer.
1151 If MINIBUF is `visible', include all visible frames.
1152 If MINIBUF is 0, include all visible and iconified frames.
1153 Otherwise, include all frames. */
1155 static Lisp_Object
1156 prev_frame (frame, minibuf)
1157 Lisp_Object frame;
1158 Lisp_Object minibuf;
1160 Lisp_Object tail;
1161 Lisp_Object prev;
1163 /* There must always be at least one frame in Vframe_list. */
1164 if (! CONSP (Vframe_list))
1165 abort ();
1167 prev = Qnil;
1168 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1170 Lisp_Object f;
1172 f = XCAR (tail);
1173 if (!FRAMEP (f))
1174 abort ();
1176 if (EQ (frame, f) && !NILP (prev))
1177 return prev;
1179 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1180 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1181 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1182 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1184 /* Decide whether this frame is eligible to be returned,
1185 according to minibuf. */
1186 if (NILP (minibuf))
1188 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1189 prev = f;
1191 else if (WINDOWP (minibuf))
1193 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1194 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1195 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1196 FRAME_FOCUS_FRAME (XFRAME (f))))
1197 prev = f;
1199 else if (EQ (minibuf, Qvisible))
1201 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1202 if (FRAME_VISIBLE_P (XFRAME (f)))
1203 prev = f;
1205 else if (XFASTINT (minibuf) == 0)
1207 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1208 if (FRAME_VISIBLE_P (XFRAME (f))
1209 || FRAME_ICONIFIED_P (XFRAME (f)))
1210 prev = f;
1212 else
1213 prev = f;
1217 /* We've scanned the entire list. */
1218 if (NILP (prev))
1219 /* We went through the whole frame list without finding a single
1220 acceptable frame. Return the original frame. */
1221 return frame;
1222 else
1223 /* There were no acceptable frames in the list before FRAME; otherwise,
1224 we would have returned directly from the loop. Since PREV is the last
1225 acceptable frame in the list, return it. */
1226 return prev;
1230 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1231 doc: /* Return the next frame in the frame list after FRAME.
1232 It considers only frames on the same terminal as FRAME.
1233 By default, skip minibuffer-only frames.
1234 If omitted, FRAME defaults to the selected frame.
1235 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1236 If MINIFRAME is a window, include only its own frame
1237 and any frame now using that window as the minibuffer.
1238 If MINIFRAME is `visible', include all visible frames.
1239 If MINIFRAME is 0, include all visible and iconified frames.
1240 Otherwise, include all frames. */)
1241 (frame, miniframe)
1242 Lisp_Object frame, miniframe;
1244 if (NILP (frame))
1245 frame = selected_frame;
1247 CHECK_LIVE_FRAME (frame);
1248 return next_frame (frame, miniframe);
1251 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1252 doc: /* Return the previous frame in the frame list before FRAME.
1253 It considers only frames on the same terminal as FRAME.
1254 By default, skip minibuffer-only frames.
1255 If omitted, FRAME defaults to the selected frame.
1256 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1257 If MINIFRAME is a window, include only its own frame
1258 and any frame now using that window as the minibuffer.
1259 If MINIFRAME is `visible', include all visible frames.
1260 If MINIFRAME is 0, include all visible and iconified frames.
1261 Otherwise, include all frames. */)
1262 (frame, miniframe)
1263 Lisp_Object frame, miniframe;
1265 if (NILP (frame))
1266 frame = selected_frame;
1267 CHECK_LIVE_FRAME (frame);
1268 return prev_frame (frame, miniframe);
1271 /* Return 1 if it is ok to delete frame F;
1272 0 if all frames aside from F are invisible.
1273 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1276 other_visible_frames (f)
1277 FRAME_PTR f;
1279 /* We know the selected frame is visible,
1280 so if F is some other frame, it can't be the sole visible one. */
1281 if (f == SELECTED_FRAME ())
1283 Lisp_Object frames;
1284 int count = 0;
1286 for (frames = Vframe_list;
1287 CONSP (frames);
1288 frames = XCDR (frames))
1290 Lisp_Object this;
1292 this = XCAR (frames);
1293 /* Verify that the frame's window still exists
1294 and we can still talk to it. And note any recent change
1295 in visibility. */
1296 #ifdef HAVE_WINDOW_SYSTEM
1297 if (FRAME_WINDOW_P (XFRAME (this)))
1299 x_sync (XFRAME (this));
1300 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1302 #endif
1304 if (FRAME_VISIBLE_P (XFRAME (this))
1305 || FRAME_ICONIFIED_P (XFRAME (this))
1306 /* Allow deleting the terminal frame when at least
1307 one X frame exists! */
1308 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1309 count++;
1311 return count > 1;
1313 return 1;
1316 /* Error handler for `delete-frame-functions'. */
1317 static Lisp_Object
1318 delete_frame_handler (Lisp_Object arg)
1320 add_to_log ("Error during `delete-frame': %s", arg, Qnil);
1321 return Qnil;
1324 extern Lisp_Object Qrun_hook_with_args;
1326 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1327 doc: /* Delete FRAME, permanently eliminating it from use.
1328 If omitted, FRAME defaults to the selected frame.
1329 A frame may not be deleted if its minibuffer is used by other frames.
1330 Normally, you may not delete a frame if all other frames are invisible,
1331 but if the second optional argument FORCE is non-nil, you may do so.
1333 This function runs `delete-frame-functions' before actually deleting the
1334 frame, unless the frame is a tooltip.
1335 The functions are run with one arg, the frame to be deleted.
1336 But FORCE inhibits this too. */)
1337 /* FORCE is non-nil when handling a disconnected terminal. */
1338 (frame, force)
1339 Lisp_Object frame, force;
1341 struct frame *f;
1342 struct frame *sf = SELECTED_FRAME ();
1343 struct kboard *kb;
1345 int minibuffer_selected;
1347 if (EQ (frame, Qnil))
1349 f = sf;
1350 XSETFRAME (frame, f);
1352 else
1354 CHECK_FRAME (frame);
1355 f = XFRAME (frame);
1358 if (! FRAME_LIVE_P (f))
1359 return Qnil;
1361 if (NILP (force) && !other_visible_frames (f))
1362 error ("Attempt to delete the sole visible or iconified frame");
1364 #if 0
1365 /* This is a nice idea, but x_connection_closed needs to be able
1366 to delete the last frame, if it is gone. */
1367 if (NILP (XCDR (Vframe_list)))
1368 error ("Attempt to delete the only frame");
1369 #endif
1371 /* Does this frame have a minibuffer, and is it the surrogate
1372 minibuffer for any other frame? */
1373 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1375 Lisp_Object frames;
1377 for (frames = Vframe_list;
1378 CONSP (frames);
1379 frames = XCDR (frames))
1381 Lisp_Object this;
1382 this = XCAR (frames);
1384 if (! EQ (this, frame)
1385 && EQ (frame,
1386 WINDOW_FRAME (XWINDOW
1387 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1389 /* If we MUST delete this frame, delete the other first. */
1390 if (!NILP (force))
1391 Fdelete_frame (this, force);
1392 else
1393 error ("Attempt to delete a surrogate minibuffer frame");
1398 /* Run `delete-frame-functions'
1399 unless FORCE is `noelisp' or frame is a tooltip.
1400 FORCE is set to `noelisp' when handling a disconnect from the terminal,
1401 so we don't dare call Lisp code. */
1402 if (NILP (Vrun_hooks) || !NILP (Fframe_parameter (frame, intern ("tooltip"))))
1404 if (EQ (force, Qnoelisp))
1405 pending_funcalls
1406 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1407 pending_funcalls);
1408 else
1409 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1411 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1412 if (! FRAME_LIVE_P (f))
1413 return Qnil;
1415 /* At this point, we are committed to deleting the frame.
1416 There is no more chance for errors to prevent it. */
1418 minibuffer_selected = EQ (minibuf_window, selected_window);
1420 /* Don't let the frame remain selected. */
1421 if (f == sf)
1423 Lisp_Object tail, frame1;
1425 /* Look for another visible frame on the same terminal. */
1426 frame1 = next_frame (frame, Qvisible);
1428 /* If there is none, find *some* other frame. */
1429 if (NILP (frame1) || EQ (frame1, frame))
1431 FOR_EACH_FRAME (tail, frame1)
1433 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1434 break;
1438 do_switch_frame (frame1, 0, 1);
1439 sf = SELECTED_FRAME ();
1442 /* Don't allow minibuf_window to remain on a deleted frame. */
1443 if (EQ (f->minibuffer_window, minibuf_window))
1445 Fset_window_buffer (sf->minibuffer_window,
1446 XWINDOW (minibuf_window)->buffer, Qnil);
1447 minibuf_window = sf->minibuffer_window;
1449 /* If the dying minibuffer window was selected,
1450 select the new one. */
1451 if (minibuffer_selected)
1452 Fselect_window (minibuf_window, Qnil);
1455 /* Don't let echo_area_window to remain on a deleted frame. */
1456 if (EQ (f->minibuffer_window, echo_area_window))
1457 echo_area_window = sf->minibuffer_window;
1459 /* Clear any X selections for this frame. */
1460 #ifdef HAVE_X_WINDOWS
1461 if (FRAME_X_P (f))
1462 x_clear_frame_selections (f);
1463 #endif
1465 /* Free glyphs.
1466 This function must be called before the window tree of the
1467 frame is deleted because windows contain dynamically allocated
1468 memory. */
1469 free_glyphs (f);
1471 #ifdef HAVE_WINDOW_SYSTEM
1472 /* Give chance to each font driver to free a frame specific data. */
1473 font_update_drivers (f, Qnil);
1474 #endif
1476 /* Mark all the windows that used to be on FRAME as deleted, and then
1477 remove the reference to them. */
1478 delete_all_subwindows (XWINDOW (f->root_window));
1479 f->root_window = Qnil;
1481 Vframe_list = Fdelq (frame, Vframe_list);
1482 FRAME_SET_VISIBLE (f, 0);
1484 xfree (f->namebuf);
1485 xfree (f->decode_mode_spec_buffer);
1486 xfree (FRAME_INSERT_COST (f));
1487 xfree (FRAME_DELETEN_COST (f));
1488 xfree (FRAME_INSERTN_COST (f));
1489 xfree (FRAME_DELETE_COST (f));
1490 xfree (FRAME_MESSAGE_BUF (f));
1492 /* Since some events are handled at the interrupt level, we may get
1493 an event for f at any time; if we zero out the frame's terminal
1494 now, then we may trip up the event-handling code. Instead, we'll
1495 promise that the terminal of the frame must be valid until we
1496 have called the window-system-dependent frame destruction
1497 routine. */
1499 if (FRAME_TERMINAL (f)->delete_frame_hook)
1500 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1503 struct terminal *terminal = FRAME_TERMINAL (f);
1504 f->output_data.nothing = 0;
1505 f->terminal = 0; /* Now the frame is dead. */
1507 /* If needed, delete the terminal that this frame was on.
1508 (This must be done after the frame is killed.) */
1509 terminal->reference_count--;
1510 if (terminal->reference_count == 0)
1512 Lisp_Object tmp;
1513 XSETTERMINAL (tmp, terminal);
1515 kb = NULL;
1516 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1518 else
1519 kb = terminal->kboard;
1522 /* If we've deleted the last_nonminibuf_frame, then try to find
1523 another one. */
1524 if (f == last_nonminibuf_frame)
1526 Lisp_Object frames;
1528 last_nonminibuf_frame = 0;
1530 for (frames = Vframe_list;
1531 CONSP (frames);
1532 frames = XCDR (frames))
1534 f = XFRAME (XCAR (frames));
1535 if (!FRAME_MINIBUF_ONLY_P (f))
1537 last_nonminibuf_frame = f;
1538 break;
1543 /* If there's no other frame on the same kboard, get out of
1544 single-kboard state if we're in it for this kboard. */
1545 if (kb != NULL)
1547 Lisp_Object frames;
1548 /* Some frame we found on the same kboard, or nil if there are none. */
1549 Lisp_Object frame_on_same_kboard;
1551 frame_on_same_kboard = Qnil;
1553 for (frames = Vframe_list;
1554 CONSP (frames);
1555 frames = XCDR (frames))
1557 Lisp_Object this;
1558 struct frame *f1;
1560 this = XCAR (frames);
1561 if (!FRAMEP (this))
1562 abort ();
1563 f1 = XFRAME (this);
1565 if (kb == FRAME_KBOARD (f1))
1566 frame_on_same_kboard = this;
1569 if (NILP (frame_on_same_kboard))
1570 not_single_kboard_state (kb);
1574 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1575 find another one. Prefer minibuffer-only frames, but also notice
1576 frames with other windows. */
1577 if (kb != NULL && EQ (frame, kb->Vdefault_minibuffer_frame))
1579 Lisp_Object frames;
1581 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1582 Lisp_Object frame_with_minibuf;
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;
1587 frame_with_minibuf = Qnil;
1589 for (frames = Vframe_list;
1590 CONSP (frames);
1591 frames = XCDR (frames))
1593 Lisp_Object this;
1594 struct frame *f1;
1596 this = XCAR (frames);
1597 if (!FRAMEP (this))
1598 abort ();
1599 f1 = XFRAME (this);
1601 /* Consider only frames on the same kboard
1602 and only those with minibuffers. */
1603 if (kb == FRAME_KBOARD (f1)
1604 && FRAME_HAS_MINIBUF_P (f1))
1606 frame_with_minibuf = this;
1607 if (FRAME_MINIBUF_ONLY_P (f1))
1608 break;
1611 if (kb == FRAME_KBOARD (f1))
1612 frame_on_same_kboard = this;
1615 if (!NILP (frame_on_same_kboard))
1617 /* We know that there must be some frame with a minibuffer out
1618 there. If this were not true, all of the frames present
1619 would have to be minibufferless, which implies that at some
1620 point their minibuffer frames must have been deleted, but
1621 that is prohibited at the top; you can't delete surrogate
1622 minibuffer frames. */
1623 if (NILP (frame_with_minibuf))
1624 abort ();
1626 kb->Vdefault_minibuffer_frame = frame_with_minibuf;
1628 else
1629 /* No frames left on this kboard--say no minibuffer either. */
1630 kb->Vdefault_minibuffer_frame = Qnil;
1633 /* Cause frame titles to update--necessary if we now have just one frame. */
1634 update_mode_lines = 1;
1636 return Qnil;
1639 /* Return mouse position in character cell units. */
1641 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1642 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1643 The position is given in character cells, where (0, 0) is the
1644 upper-left corner of the frame, X is the horizontal offset, and Y is
1645 the vertical offset.
1646 If Emacs is running on a mouseless terminal or hasn't been programmed
1647 to read the mouse position, it returns the selected frame for FRAME
1648 and nil for X and Y.
1649 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1650 passing the normal return value to that function as an argument,
1651 and returns whatever that function returns. */)
1654 FRAME_PTR f;
1655 Lisp_Object lispy_dummy;
1656 enum scroll_bar_part party_dummy;
1657 Lisp_Object x, y, retval;
1658 int col, row;
1659 unsigned long long_dummy;
1660 struct gcpro gcpro1;
1662 f = SELECTED_FRAME ();
1663 x = y = Qnil;
1665 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1666 /* It's okay for the hook to refrain from storing anything. */
1667 if (FRAME_TERMINAL (f)->mouse_position_hook)
1668 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1669 &lispy_dummy, &party_dummy,
1670 &x, &y,
1671 &long_dummy);
1672 if (! NILP (x))
1674 col = XINT (x);
1675 row = XINT (y);
1676 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1677 XSETINT (x, col);
1678 XSETINT (y, row);
1680 #endif
1681 XSETFRAME (lispy_dummy, f);
1682 retval = Fcons (lispy_dummy, Fcons (x, y));
1683 GCPRO1 (retval);
1684 if (!NILP (Vmouse_position_function))
1685 retval = call1 (Vmouse_position_function, retval);
1686 RETURN_UNGCPRO (retval);
1689 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1690 Smouse_pixel_position, 0, 0, 0,
1691 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1692 The position is given in pixel units, where (0, 0) is the
1693 upper-left corner of the frame, X is the horizontal offset, and Y is
1694 the vertical offset.
1695 If Emacs is running on a mouseless terminal or hasn't been programmed
1696 to read the mouse position, it returns the selected frame for FRAME
1697 and nil for X and Y. */)
1700 FRAME_PTR f;
1701 Lisp_Object lispy_dummy;
1702 enum scroll_bar_part party_dummy;
1703 Lisp_Object x, y;
1704 unsigned long long_dummy;
1706 f = SELECTED_FRAME ();
1707 x = y = Qnil;
1709 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1710 /* It's okay for the hook to refrain from storing anything. */
1711 if (FRAME_TERMINAL (f)->mouse_position_hook)
1712 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1713 &lispy_dummy, &party_dummy,
1714 &x, &y,
1715 &long_dummy);
1716 #endif
1717 XSETFRAME (lispy_dummy, f);
1718 return Fcons (lispy_dummy, Fcons (x, y));
1721 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1722 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1723 Coordinates are relative to the frame, not a window,
1724 so the coordinates of the top left character in the frame
1725 may be nonzero due to left-hand scroll bars or the menu bar.
1727 The position is given in character cells, where (0, 0) is the
1728 upper-left corner of the frame, X is the horizontal offset, and Y is
1729 the vertical offset.
1731 This function is a no-op for an X frame that is not visible.
1732 If you have just created a frame, you must wait for it to become visible
1733 before calling this function on it, like this.
1734 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1735 (frame, x, y)
1736 Lisp_Object frame, x, y;
1738 CHECK_LIVE_FRAME (frame);
1739 CHECK_NUMBER (x);
1740 CHECK_NUMBER (y);
1742 /* I think this should be done with a hook. */
1743 #ifdef HAVE_WINDOW_SYSTEM
1744 if (FRAME_WINDOW_P (XFRAME (frame)))
1745 /* Warping the mouse will cause enternotify and focus events. */
1746 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1747 #else
1748 #if defined (MSDOS) && defined (HAVE_MOUSE)
1749 if (FRAME_MSDOS_P (XFRAME (frame)))
1751 Fselect_frame (frame);
1752 mouse_moveto (XINT (x), XINT (y));
1754 #else
1755 #ifdef HAVE_GPM
1757 Fselect_frame (frame);
1758 term_mouse_moveto (XINT (x), XINT (y));
1760 #endif
1761 #endif
1762 #endif
1764 return Qnil;
1767 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1768 Sset_mouse_pixel_position, 3, 3, 0,
1769 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1770 The position is given in pixels, where (0, 0) is the upper-left corner
1771 of the frame, X is the horizontal offset, and Y is the vertical offset.
1773 Note, this is a no-op for an X frame that is not visible.
1774 If you have just created a frame, you must wait for it to become visible
1775 before calling this function on it, like this.
1776 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1777 (frame, x, y)
1778 Lisp_Object frame, x, y;
1780 CHECK_LIVE_FRAME (frame);
1781 CHECK_NUMBER (x);
1782 CHECK_NUMBER (y);
1784 /* I think this should be done with a hook. */
1785 #ifdef HAVE_WINDOW_SYSTEM
1786 if (FRAME_WINDOW_P (XFRAME (frame)))
1787 /* Warping the mouse will cause enternotify and focus events. */
1788 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1789 #else
1790 #if defined (MSDOS) && defined (HAVE_MOUSE)
1791 if (FRAME_MSDOS_P (XFRAME (frame)))
1793 Fselect_frame (frame);
1794 mouse_moveto (XINT (x), XINT (y));
1796 #else
1797 #ifdef HAVE_GPM
1799 Fselect_frame (frame);
1800 term_mouse_moveto (XINT (x), XINT (y));
1802 #endif
1803 #endif
1804 #endif
1806 return Qnil;
1809 static void make_frame_visible_1 P_ ((Lisp_Object));
1811 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1812 0, 1, "",
1813 doc: /* Make the frame FRAME visible (assuming it is an X window).
1814 If omitted, FRAME defaults to the currently selected frame. */)
1815 (frame)
1816 Lisp_Object frame;
1818 if (NILP (frame))
1819 frame = selected_frame;
1821 CHECK_LIVE_FRAME (frame);
1823 /* I think this should be done with a hook. */
1824 #ifdef HAVE_WINDOW_SYSTEM
1825 if (FRAME_WINDOW_P (XFRAME (frame)))
1827 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1828 x_make_frame_visible (XFRAME (frame));
1830 #endif
1832 make_frame_visible_1 (XFRAME (frame)->root_window);
1834 /* Make menu bar update for the Buffers and Frames menus. */
1835 windows_or_buffers_changed++;
1837 return frame;
1840 /* Update the display_time slot of the buffers shown in WINDOW
1841 and all its descendents. */
1843 static void
1844 make_frame_visible_1 (window)
1845 Lisp_Object window;
1847 struct window *w;
1849 for (;!NILP (window); window = w->next)
1851 w = XWINDOW (window);
1853 if (!NILP (w->buffer))
1854 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1856 if (!NILP (w->vchild))
1857 make_frame_visible_1 (w->vchild);
1858 if (!NILP (w->hchild))
1859 make_frame_visible_1 (w->hchild);
1863 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1864 0, 2, "",
1865 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1866 If omitted, FRAME defaults to the currently selected frame.
1867 Normally you may not make FRAME invisible if all other frames are invisible,
1868 but if the second optional argument FORCE is non-nil, you may do so. */)
1869 (frame, force)
1870 Lisp_Object frame, force;
1872 if (NILP (frame))
1873 frame = selected_frame;
1875 CHECK_LIVE_FRAME (frame);
1877 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1878 error ("Attempt to make invisible the sole visible or iconified frame");
1880 #if 0 /* This isn't logically necessary, and it can do GC. */
1881 /* Don't let the frame remain selected. */
1882 if (EQ (frame, selected_frame))
1883 do_switch_frame (next_frame (frame, Qt), 0, 0)
1884 #endif
1886 /* Don't allow minibuf_window to remain on a deleted frame. */
1887 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1889 struct frame *sf = XFRAME (selected_frame);
1890 Fset_window_buffer (sf->minibuffer_window,
1891 XWINDOW (minibuf_window)->buffer, Qnil);
1892 minibuf_window = sf->minibuffer_window;
1895 /* I think this should be done with a hook. */
1896 #ifdef HAVE_WINDOW_SYSTEM
1897 if (FRAME_WINDOW_P (XFRAME (frame)))
1898 x_make_frame_invisible (XFRAME (frame));
1899 #endif
1901 /* Make menu bar update for the Buffers and Frames menus. */
1902 windows_or_buffers_changed++;
1904 return Qnil;
1907 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1908 0, 1, "",
1909 doc: /* Make the frame FRAME into an icon.
1910 If omitted, FRAME defaults to the currently selected frame. */)
1911 (frame)
1912 Lisp_Object frame;
1914 if (NILP (frame))
1915 frame = selected_frame;
1917 CHECK_LIVE_FRAME (frame);
1919 #if 0 /* This isn't logically necessary, and it can do GC. */
1920 /* Don't let the frame remain selected. */
1921 if (EQ (frame, selected_frame))
1922 Fhandle_switch_frame (next_frame (frame, Qt));
1923 #endif
1925 /* Don't allow minibuf_window to remain on a deleted frame. */
1926 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1928 struct frame *sf = XFRAME (selected_frame);
1929 Fset_window_buffer (sf->minibuffer_window,
1930 XWINDOW (minibuf_window)->buffer, Qnil);
1931 minibuf_window = sf->minibuffer_window;
1934 /* I think this should be done with a hook. */
1935 #ifdef HAVE_WINDOW_SYSTEM
1936 if (FRAME_WINDOW_P (XFRAME (frame)))
1937 x_iconify_frame (XFRAME (frame));
1938 #endif
1940 /* Make menu bar update for the Buffers and Frames menus. */
1941 windows_or_buffers_changed++;
1943 return Qnil;
1946 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1947 1, 1, 0,
1948 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1949 A frame that is not \"visible\" is not updated and, if it works through
1950 a window system, it may not show at all.
1951 Return the symbol `icon' if frame is visible only as an icon.
1953 On a text-only terminal, all frames are considered visible, whether
1954 they are currently being displayed or not, and this function returns t
1955 for all frames. */)
1956 (frame)
1957 Lisp_Object frame;
1959 CHECK_LIVE_FRAME (frame);
1961 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1963 if (FRAME_VISIBLE_P (XFRAME (frame)))
1964 return Qt;
1965 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1966 return Qicon;
1967 return Qnil;
1970 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1971 0, 0, 0,
1972 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1975 Lisp_Object tail, frame;
1976 struct frame *f;
1977 Lisp_Object value;
1979 value = Qnil;
1980 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1982 frame = XCAR (tail);
1983 if (!FRAMEP (frame))
1984 continue;
1985 f = XFRAME (frame);
1986 if (FRAME_VISIBLE_P (f))
1987 value = Fcons (frame, value);
1989 return value;
1993 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1994 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1995 If FRAME is invisible or iconified, make it visible.
1996 If you don't specify a frame, the selected frame is used.
1997 If Emacs is displaying on an ordinary terminal or some other device which
1998 doesn't support multiple overlapping frames, this function does nothing. */)
1999 (frame)
2000 Lisp_Object frame;
2002 struct frame *f;
2003 if (NILP (frame))
2004 frame = selected_frame;
2006 CHECK_LIVE_FRAME (frame);
2008 f = XFRAME (frame);
2010 /* Do like the documentation says. */
2011 Fmake_frame_visible (frame);
2013 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2014 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2016 return Qnil;
2019 /* Should we have a corresponding function called Flower_Power? */
2020 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2021 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2022 If you don't specify a frame, the selected frame is used.
2023 If Emacs is displaying on an ordinary terminal or some other device which
2024 doesn't support multiple overlapping frames, this function does nothing. */)
2025 (frame)
2026 Lisp_Object frame;
2028 struct frame *f;
2030 if (NILP (frame))
2031 frame = selected_frame;
2033 CHECK_LIVE_FRAME (frame);
2035 f = XFRAME (frame);
2037 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2038 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2040 return Qnil;
2044 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2045 1, 2, 0,
2046 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2047 In other words, switch-frame events caused by events in FRAME will
2048 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2049 FOCUS-FRAME after reading an event typed at FRAME.
2051 If FOCUS-FRAME is omitted or nil, any existing redirection is
2052 cancelled, and the frame again receives its own keystrokes.
2054 Focus redirection is useful for temporarily redirecting keystrokes to
2055 a surrogate minibuffer frame when a frame doesn't have its own
2056 minibuffer window.
2058 A frame's focus redirection can be changed by `select-frame'. If frame
2059 FOO is selected, and then a different frame BAR is selected, any
2060 frames redirecting their focus to FOO are shifted to redirect their
2061 focus to BAR. This allows focus redirection to work properly when the
2062 user switches from one frame to another using `select-window'.
2064 This means that a frame whose focus is redirected to itself is treated
2065 differently from a frame whose focus is redirected to nil; the former
2066 is affected by `select-frame', while the latter is not.
2068 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2069 (frame, focus_frame)
2070 Lisp_Object frame, focus_frame;
2072 struct frame *f;
2074 /* Note that we don't check for a live frame here. It's reasonable
2075 to redirect the focus of a frame you're about to delete, if you
2076 know what other frame should receive those keystrokes. */
2077 CHECK_FRAME (frame);
2079 if (! NILP (focus_frame))
2080 CHECK_LIVE_FRAME (focus_frame);
2082 f = XFRAME (frame);
2084 f->focus_frame = focus_frame;
2086 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2087 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2089 return Qnil;
2093 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
2094 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2095 This returns nil if FRAME's focus is not redirected.
2096 See `redirect-frame-focus'. */)
2097 (frame)
2098 Lisp_Object frame;
2100 CHECK_LIVE_FRAME (frame);
2102 return FRAME_FOCUS_FRAME (XFRAME (frame));
2107 /* Return the value of frame parameter PROP in frame FRAME. */
2109 Lisp_Object
2110 get_frame_param (frame, prop)
2111 register struct frame *frame;
2112 Lisp_Object prop;
2114 register Lisp_Object tem;
2116 tem = Fassq (prop, frame->param_alist);
2117 if (EQ (tem, Qnil))
2118 return tem;
2119 return Fcdr (tem);
2122 /* Return the buffer-predicate of the selected frame. */
2124 Lisp_Object
2125 frame_buffer_predicate (frame)
2126 Lisp_Object frame;
2128 return XFRAME (frame)->buffer_predicate;
2131 /* Return the buffer-list of the selected frame. */
2133 Lisp_Object
2134 frame_buffer_list (frame)
2135 Lisp_Object frame;
2137 return XFRAME (frame)->buffer_list;
2140 /* Set the buffer-list of the selected frame. */
2142 void
2143 set_frame_buffer_list (frame, list)
2144 Lisp_Object frame, list;
2146 XFRAME (frame)->buffer_list = list;
2149 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2151 void
2152 frames_discard_buffer (buffer)
2153 Lisp_Object buffer;
2155 Lisp_Object frame, tail;
2157 FOR_EACH_FRAME (tail, frame)
2159 XFRAME (frame)->buffer_list
2160 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2161 XFRAME (frame)->buried_buffer_list
2162 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
2166 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2167 If the alist already has an element for PROP, we change it. */
2169 void
2170 store_in_alist (alistptr, prop, val)
2171 Lisp_Object *alistptr, val;
2172 Lisp_Object prop;
2174 register Lisp_Object tem;
2176 tem = Fassq (prop, *alistptr);
2177 if (EQ (tem, Qnil))
2178 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2179 else
2180 Fsetcdr (tem, val);
2183 static int
2184 frame_name_fnn_p (str, len)
2185 char *str;
2186 EMACS_INT len;
2188 if (len > 1 && str[0] == 'F')
2190 char *end_ptr;
2192 strtol (str + 1, &end_ptr, 10);
2194 if (end_ptr == str + len)
2195 return 1;
2197 return 0;
2200 /* Set the name of the terminal frame. Also used by MSDOS frames.
2201 Modeled after x_set_name which is used for WINDOW frames. */
2203 static void
2204 set_term_frame_name (f, name)
2205 struct frame *f;
2206 Lisp_Object name;
2208 f->explicit_name = ! NILP (name);
2210 /* If NAME is nil, set the name to F<num>. */
2211 if (NILP (name))
2213 char namebuf[20];
2215 /* Check for no change needed in this very common case
2216 before we do any consing. */
2217 if (frame_name_fnn_p (SDATA (f->name),
2218 SBYTES (f->name)))
2219 return;
2221 tty_frame_count++;
2222 sprintf (namebuf, "F%d", tty_frame_count);
2223 name = build_string (namebuf);
2225 else
2227 CHECK_STRING (name);
2229 /* Don't change the name if it's already NAME. */
2230 if (! NILP (Fstring_equal (name, f->name)))
2231 return;
2233 /* Don't allow the user to set the frame name to F<num>, so it
2234 doesn't clash with the names we generate for terminal frames. */
2235 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2236 error ("Frame names of the form F<num> are usurped by Emacs");
2239 f->name = name;
2240 update_mode_lines = 1;
2243 void
2244 store_frame_param (f, prop, val)
2245 struct frame *f;
2246 Lisp_Object prop, val;
2248 register Lisp_Object old_alist_elt;
2250 /* The buffer-list parameters are stored in a special place and not
2251 in the alist. */
2252 if (EQ (prop, Qbuffer_list))
2254 f->buffer_list = val;
2255 return;
2257 if (EQ (prop, Qburied_buffer_list))
2259 f->buried_buffer_list = val;
2260 return;
2263 /* If PROP is a symbol which is supposed to have frame-local values,
2264 and it is set up based on this frame, switch to the global
2265 binding. That way, we can create or alter the frame-local binding
2266 without messing up the symbol's status. */
2267 if (SYMBOLP (prop))
2269 Lisp_Object valcontents;
2270 valcontents = SYMBOL_VALUE (prop);
2271 if ((BUFFER_LOCAL_VALUEP (valcontents))
2272 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2273 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame
2274 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2275 swap_in_global_binding (prop);
2278 #ifndef WINDOWSNT
2279 /* The tty color needed to be set before the frame's parameter
2280 alist was updated with the new value. This is not true any more,
2281 but we still do this test early on. */
2282 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2283 && f == FRAME_TTY (f)->previous_frame)
2284 /* Force redisplay of this tty. */
2285 FRAME_TTY (f)->previous_frame = NULL;
2286 #endif
2288 /* Update the frame parameter alist. */
2289 old_alist_elt = Fassq (prop, f->param_alist);
2290 if (EQ (old_alist_elt, Qnil))
2291 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2292 else
2293 Fsetcdr (old_alist_elt, val);
2295 /* Update some other special parameters in their special places
2296 in addition to the alist. */
2298 if (EQ (prop, Qbuffer_predicate))
2299 f->buffer_predicate = val;
2301 if (! FRAME_WINDOW_P (f))
2303 if (EQ (prop, Qmenu_bar_lines))
2304 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2305 else if (EQ (prop, Qname))
2306 set_term_frame_name (f, val);
2309 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2311 if (! MINI_WINDOW_P (XWINDOW (val)))
2312 error ("Surrogate minibuffer windows must be minibuffer windows");
2314 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2315 && !EQ (val, f->minibuffer_window))
2316 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2318 /* Install the chosen minibuffer window, with proper buffer. */
2319 f->minibuffer_window = val;
2323 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2324 doc: /* Return the parameters-alist of frame FRAME.
2325 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2326 The meaningful PARMs depend on the kind of frame.
2327 If FRAME is omitted, return information on the currently selected frame. */)
2328 (frame)
2329 Lisp_Object frame;
2331 Lisp_Object alist;
2332 FRAME_PTR f;
2333 int height, width;
2334 struct gcpro gcpro1;
2336 if (NILP (frame))
2337 frame = selected_frame;
2339 CHECK_FRAME (frame);
2340 f = XFRAME (frame);
2342 if (!FRAME_LIVE_P (f))
2343 return Qnil;
2345 alist = Fcopy_alist (f->param_alist);
2346 GCPRO1 (alist);
2348 if (!FRAME_WINDOW_P (f))
2350 int fg = FRAME_FOREGROUND_PIXEL (f);
2351 int bg = FRAME_BACKGROUND_PIXEL (f);
2352 Lisp_Object elt;
2354 /* If the frame's parameter alist says the colors are
2355 unspecified and reversed, take the frame's background pixel
2356 for foreground and vice versa. */
2357 elt = Fassq (Qforeground_color, alist);
2358 if (CONSP (elt) && STRINGP (XCDR (elt)))
2360 if (strncmp (SDATA (XCDR (elt)),
2361 unspecified_bg,
2362 SCHARS (XCDR (elt))) == 0)
2363 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2364 else if (strncmp (SDATA (XCDR (elt)),
2365 unspecified_fg,
2366 SCHARS (XCDR (elt))) == 0)
2367 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2369 else
2370 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2371 elt = Fassq (Qbackground_color, alist);
2372 if (CONSP (elt) && STRINGP (XCDR (elt)))
2374 if (strncmp (SDATA (XCDR (elt)),
2375 unspecified_fg,
2376 SCHARS (XCDR (elt))) == 0)
2377 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2378 else if (strncmp (SDATA (XCDR (elt)),
2379 unspecified_bg,
2380 SCHARS (XCDR (elt))) == 0)
2381 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2383 else
2384 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2385 store_in_alist (&alist, intern ("font"),
2386 build_string (FRAME_MSDOS_P (f)
2387 ? "ms-dos"
2388 : FRAME_W32_P (f) ? "w32term"
2389 :"tty"));
2391 store_in_alist (&alist, Qname, f->name);
2392 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2393 store_in_alist (&alist, Qheight, make_number (height));
2394 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2395 store_in_alist (&alist, Qwidth, make_number (width));
2396 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2397 store_in_alist (&alist, Qminibuffer,
2398 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2399 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2400 : FRAME_MINIBUF_WINDOW (f)));
2401 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2402 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2403 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2405 /* I think this should be done with a hook. */
2406 #ifdef HAVE_WINDOW_SYSTEM
2407 if (FRAME_WINDOW_P (f))
2408 x_report_frame_params (f, &alist);
2409 else
2410 #endif
2412 /* This ought to be correct in f->param_alist for an X frame. */
2413 Lisp_Object lines;
2414 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2415 store_in_alist (&alist, Qmenu_bar_lines, lines);
2418 UNGCPRO;
2419 return alist;
2423 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2424 doc: /* Return FRAME's value for parameter PARAMETER.
2425 If FRAME is nil, describe the currently selected frame. */)
2426 (frame, parameter)
2427 Lisp_Object frame, parameter;
2429 struct frame *f;
2430 Lisp_Object value;
2432 if (NILP (frame))
2433 frame = selected_frame;
2434 else
2435 CHECK_FRAME (frame);
2436 CHECK_SYMBOL (parameter);
2438 f = XFRAME (frame);
2439 value = Qnil;
2441 if (FRAME_LIVE_P (f))
2443 /* Avoid consing in frequent cases. */
2444 if (EQ (parameter, Qname))
2445 value = f->name;
2446 #ifdef HAVE_X_WINDOWS
2447 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2448 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2449 #endif /* HAVE_X_WINDOWS */
2450 else if (EQ (parameter, Qbackground_color)
2451 || EQ (parameter, Qforeground_color))
2453 value = Fassq (parameter, f->param_alist);
2454 if (CONSP (value))
2456 value = XCDR (value);
2457 /* Fframe_parameters puts the actual fg/bg color names,
2458 even if f->param_alist says otherwise. This is
2459 important when param_alist's notion of colors is
2460 "unspecified". We need to do the same here. */
2461 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2463 const char *color_name;
2464 EMACS_INT csz;
2466 if (EQ (parameter, Qbackground_color))
2468 color_name = SDATA (value);
2469 csz = SCHARS (value);
2470 if (strncmp (color_name, unspecified_bg, csz) == 0)
2471 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2472 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2473 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2475 else if (EQ (parameter, Qforeground_color))
2477 color_name = SDATA (value);
2478 csz = SCHARS (value);
2479 if (strncmp (color_name, unspecified_fg, csz) == 0)
2480 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2481 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2482 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2486 else
2487 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2489 else if (EQ (parameter, Qdisplay_type)
2490 || EQ (parameter, Qbackground_mode))
2491 value = Fcdr (Fassq (parameter, f->param_alist));
2492 else
2493 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2496 return value;
2500 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2501 Smodify_frame_parameters, 2, 2, 0,
2502 doc: /* Modify the parameters of frame FRAME according to ALIST.
2503 If FRAME is nil, it defaults to the selected frame.
2504 ALIST is an alist of parameters to change and their new values.
2505 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2506 The meaningful PARMs depend on the kind of frame.
2507 Undefined PARMs are ignored, but stored in the frame's parameter list
2508 so that `frame-parameters' will return them.
2510 The value of frame parameter FOO can also be accessed
2511 as a frame-local binding for the variable FOO, if you have
2512 enabled such bindings for that variable with `make-variable-frame-local'. */)
2513 (frame, alist)
2514 Lisp_Object frame, alist;
2516 FRAME_PTR f;
2517 register Lisp_Object tail, prop, val;
2519 if (EQ (frame, Qnil))
2520 frame = selected_frame;
2521 CHECK_LIVE_FRAME (frame);
2522 f = XFRAME (frame);
2524 /* I think this should be done with a hook. */
2525 #ifdef HAVE_WINDOW_SYSTEM
2526 if (FRAME_WINDOW_P (f))
2527 x_set_frame_parameters (f, alist);
2528 else
2529 #endif
2530 #ifdef MSDOS
2531 if (FRAME_MSDOS_P (f))
2532 IT_set_frame_parameters (f, alist);
2533 else
2534 #endif
2537 int length = XINT (Flength (alist));
2538 int i;
2539 Lisp_Object *parms
2540 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2541 Lisp_Object *values
2542 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2544 /* Extract parm names and values into those vectors. */
2546 i = 0;
2547 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2549 Lisp_Object elt;
2551 elt = XCAR (tail);
2552 parms[i] = Fcar (elt);
2553 values[i] = Fcdr (elt);
2554 i++;
2557 /* Now process them in reverse of specified order. */
2558 for (i--; i >= 0; i--)
2560 prop = parms[i];
2561 val = values[i];
2562 store_frame_param (f, prop, val);
2564 /* Changing the background color might change the background
2565 mode, so that we have to load new defface specs.
2566 Call frame-set-background-mode to do that. */
2567 if (EQ (prop, Qbackground_color))
2568 call1 (Qframe_set_background_mode, frame);
2571 return Qnil;
2574 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2575 0, 1, 0,
2576 doc: /* Height in pixels of a line in the font in frame FRAME.
2577 If FRAME is omitted, the selected frame is used.
2578 For a terminal frame, the value is always 1. */)
2579 (frame)
2580 Lisp_Object frame;
2582 struct frame *f;
2584 if (NILP (frame))
2585 frame = selected_frame;
2586 CHECK_FRAME (frame);
2587 f = XFRAME (frame);
2589 #ifdef HAVE_WINDOW_SYSTEM
2590 if (FRAME_WINDOW_P (f))
2591 return make_number (x_char_height (f));
2592 else
2593 #endif
2594 return make_number (1);
2598 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2599 0, 1, 0,
2600 doc: /* Width in pixels of characters in the font in frame FRAME.
2601 If FRAME is omitted, the selected frame is used.
2602 On a graphical screen, the width is the standard width of the default font.
2603 For a terminal screen, the value is always 1. */)
2604 (frame)
2605 Lisp_Object frame;
2607 struct frame *f;
2609 if (NILP (frame))
2610 frame = selected_frame;
2611 CHECK_FRAME (frame);
2612 f = XFRAME (frame);
2614 #ifdef HAVE_WINDOW_SYSTEM
2615 if (FRAME_WINDOW_P (f))
2616 return make_number (x_char_width (f));
2617 else
2618 #endif
2619 return make_number (1);
2622 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2623 Sframe_pixel_height, 0, 1, 0,
2624 doc: /* Return a FRAME's height in pixels.
2625 This counts only the height available for text lines,
2626 not menu bars on window-system Emacs frames.
2627 For a terminal frame, the result really gives the height in characters.
2628 If FRAME is omitted, the selected frame is used. */)
2629 (frame)
2630 Lisp_Object frame;
2632 struct frame *f;
2634 if (NILP (frame))
2635 frame = selected_frame;
2636 CHECK_FRAME (frame);
2637 f = XFRAME (frame);
2639 #ifdef HAVE_WINDOW_SYSTEM
2640 if (FRAME_WINDOW_P (f))
2641 return make_number (x_pixel_height (f));
2642 else
2643 #endif
2644 return make_number (FRAME_LINES (f));
2647 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2648 Sframe_pixel_width, 0, 1, 0,
2649 doc: /* Return FRAME's width in pixels.
2650 For a terminal frame, the result really gives the width in characters.
2651 If FRAME is omitted, the selected frame is used. */)
2652 (frame)
2653 Lisp_Object frame;
2655 struct frame *f;
2657 if (NILP (frame))
2658 frame = selected_frame;
2659 CHECK_FRAME (frame);
2660 f = XFRAME (frame);
2662 #ifdef HAVE_WINDOW_SYSTEM
2663 if (FRAME_WINDOW_P (f))
2664 return make_number (x_pixel_width (f));
2665 else
2666 #endif
2667 return make_number (FRAME_COLS (f));
2670 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2671 doc: /* Specify that the frame FRAME has LINES lines.
2672 Optional third arg non-nil means that redisplay should use LINES lines
2673 but that the idea of the actual height of the frame should not be changed. */)
2674 (frame, lines, pretend)
2675 Lisp_Object frame, lines, pretend;
2677 register struct frame *f;
2679 CHECK_NUMBER (lines);
2680 if (NILP (frame))
2681 frame = selected_frame;
2682 CHECK_LIVE_FRAME (frame);
2683 f = XFRAME (frame);
2685 /* I think this should be done with a hook. */
2686 #ifdef HAVE_WINDOW_SYSTEM
2687 if (FRAME_WINDOW_P (f))
2689 if (XINT (lines) != FRAME_LINES (f))
2690 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2691 do_pending_window_change (0);
2693 else
2694 #endif
2695 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2696 return Qnil;
2699 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2700 doc: /* Specify that the frame FRAME has COLS columns.
2701 Optional third arg non-nil means that redisplay should use COLS columns
2702 but that the idea of the actual width of the frame should not be changed. */)
2703 (frame, cols, pretend)
2704 Lisp_Object frame, cols, pretend;
2706 register struct frame *f;
2707 CHECK_NUMBER (cols);
2708 if (NILP (frame))
2709 frame = selected_frame;
2710 CHECK_LIVE_FRAME (frame);
2711 f = XFRAME (frame);
2713 /* I think this should be done with a hook. */
2714 #ifdef HAVE_WINDOW_SYSTEM
2715 if (FRAME_WINDOW_P (f))
2717 if (XINT (cols) != FRAME_COLS (f))
2718 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2719 do_pending_window_change (0);
2721 else
2722 #endif
2723 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2724 return Qnil;
2727 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2728 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2729 (frame, cols, rows)
2730 Lisp_Object frame, cols, rows;
2732 register struct frame *f;
2734 CHECK_LIVE_FRAME (frame);
2735 CHECK_NUMBER (cols);
2736 CHECK_NUMBER (rows);
2737 f = XFRAME (frame);
2739 /* I think this should be done with a hook. */
2740 #ifdef HAVE_WINDOW_SYSTEM
2741 if (FRAME_WINDOW_P (f))
2743 if (XINT (rows) != FRAME_LINES (f)
2744 || XINT (cols) != FRAME_COLS (f)
2745 || f->new_text_lines || f->new_text_cols)
2746 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2747 do_pending_window_change (0);
2749 else
2750 #endif
2751 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2753 return Qnil;
2756 DEFUN ("set-frame-position", Fset_frame_position,
2757 Sset_frame_position, 3, 3, 0,
2758 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2759 This is actually the position of the upper left corner of the frame.
2760 Negative values for XOFFSET or YOFFSET are interpreted relative to
2761 the rightmost or bottommost possible position (that stays within the screen). */)
2762 (frame, xoffset, yoffset)
2763 Lisp_Object frame, xoffset, yoffset;
2765 register struct frame *f;
2767 CHECK_LIVE_FRAME (frame);
2768 CHECK_NUMBER (xoffset);
2769 CHECK_NUMBER (yoffset);
2770 f = XFRAME (frame);
2772 /* I think this should be done with a hook. */
2773 #ifdef HAVE_WINDOW_SYSTEM
2774 if (FRAME_WINDOW_P (f))
2775 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2776 #endif
2778 return Qt;
2782 /***********************************************************************
2783 Frame Parameters
2784 ***********************************************************************/
2786 /* Connect the frame-parameter names for X frames
2787 to the ways of passing the parameter values to the window system.
2789 The name of a parameter, as a Lisp symbol,
2790 has an `x-frame-parameter' property which is an integer in Lisp
2791 that is an index in this table. */
2793 struct frame_parm_table {
2794 char *name;
2795 Lisp_Object *variable;
2798 static struct frame_parm_table frame_parms[] =
2800 {"auto-raise", &Qauto_raise},
2801 {"auto-lower", &Qauto_lower},
2802 {"background-color", 0},
2803 {"border-color", &Qborder_color},
2804 {"border-width", &Qborder_width},
2805 {"cursor-color", &Qcursor_color},
2806 {"cursor-type", &Qcursor_type},
2807 {"font", 0},
2808 {"foreground-color", 0},
2809 {"icon-name", &Qicon_name},
2810 {"icon-type", &Qicon_type},
2811 {"internal-border-width", &Qinternal_border_width},
2812 {"menu-bar-lines", &Qmenu_bar_lines},
2813 {"mouse-color", &Qmouse_color},
2814 {"name", &Qname},
2815 {"scroll-bar-width", &Qscroll_bar_width},
2816 {"title", &Qtitle},
2817 {"unsplittable", &Qunsplittable},
2818 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2819 {"visibility", &Qvisibility},
2820 {"tool-bar-lines", &Qtool_bar_lines},
2821 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2822 {"scroll-bar-background", &Qscroll_bar_background},
2823 {"screen-gamma", &Qscreen_gamma},
2824 {"line-spacing", &Qline_spacing},
2825 {"left-fringe", &Qleft_fringe},
2826 {"right-fringe", &Qright_fringe},
2827 {"wait-for-wm", &Qwait_for_wm},
2828 {"fullscreen", &Qfullscreen},
2829 {"font-backend", &Qfont_backend},
2830 {"alpha", &Qalpha}
2833 #ifdef HAVE_WINDOW_SYSTEM
2835 extern Lisp_Object Qbox;
2836 extern Lisp_Object Qtop;
2838 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2839 wanted positions of the WM window (not Emacs window).
2840 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2841 window (FRAME_X_WINDOW).
2844 void
2845 x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2846 struct frame *f;
2847 int *width;
2848 int *height;
2849 int *top_pos;
2850 int *left_pos;
2852 int newwidth = FRAME_COLS (f);
2853 int newheight = FRAME_LINES (f);
2855 *top_pos = f->top_pos;
2856 *left_pos = f->left_pos;
2858 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2860 int ph;
2862 ph = FRAME_X_DISPLAY_INFO (f)->height;
2863 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2864 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2865 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2866 *top_pos = 0;
2869 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2871 int pw;
2873 pw = FRAME_X_DISPLAY_INFO (f)->width;
2874 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2875 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2876 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2877 *left_pos = 0;
2880 *width = newwidth;
2881 *height = newheight;
2885 /* Change the parameters of frame F as specified by ALIST.
2886 If a parameter is not specially recognized, do nothing special;
2887 otherwise call the `x_set_...' function for that parameter.
2888 Except for certain geometry properties, always call store_frame_param
2889 to store the new value in the parameter alist. */
2891 void
2892 x_set_frame_parameters (f, alist)
2893 FRAME_PTR f;
2894 Lisp_Object alist;
2896 Lisp_Object tail;
2898 /* If both of these parameters are present, it's more efficient to
2899 set them both at once. So we wait until we've looked at the
2900 entire list before we set them. */
2901 int width, height;
2903 /* Same here. */
2904 Lisp_Object left, top;
2906 /* Same with these. */
2907 Lisp_Object icon_left, icon_top;
2909 /* Record in these vectors all the parms specified. */
2910 Lisp_Object *parms;
2911 Lisp_Object *values;
2912 int i, p;
2913 int left_no_change = 0, top_no_change = 0;
2914 int icon_left_no_change = 0, icon_top_no_change = 0;
2915 int fullscreen_is_being_set = 0;
2917 struct gcpro gcpro1, gcpro2;
2919 i = 0;
2920 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2921 i++;
2923 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2924 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2926 /* Extract parm names and values into those vectors. */
2928 i = 0;
2929 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2931 Lisp_Object elt;
2933 elt = XCAR (tail);
2934 parms[i] = Fcar (elt);
2935 values[i] = Fcdr (elt);
2936 i++;
2938 /* TAIL and ALIST are not used again below here. */
2939 alist = tail = Qnil;
2941 GCPRO2 (*parms, *values);
2942 gcpro1.nvars = i;
2943 gcpro2.nvars = i;
2945 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2946 because their values appear in VALUES and strings are not valid. */
2947 top = left = Qunbound;
2948 icon_left = icon_top = Qunbound;
2950 /* Provide default values for HEIGHT and WIDTH. */
2951 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2952 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2954 /* Process foreground_color and background_color before anything else.
2955 They are independent of other properties, but other properties (e.g.,
2956 cursor_color) are dependent upon them. */
2957 /* Process default font as well, since fringe widths depends on it. */
2958 /* Also, process fullscreen, width and height depend upon that */
2959 for (p = 0; p < i; p++)
2961 Lisp_Object prop, val;
2963 prop = parms[p];
2964 val = values[p];
2965 if (EQ (prop, Qforeground_color)
2966 || EQ (prop, Qbackground_color)
2967 || EQ (prop, Qfont)
2968 || EQ (prop, Qfullscreen))
2970 register Lisp_Object param_index, old_value;
2972 old_value = get_frame_param (f, prop);
2973 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
2974 if (NILP (Fequal (val, old_value)))
2976 store_frame_param (f, prop, val);
2978 param_index = Fget (prop, Qx_frame_parameter);
2979 if (NATNUMP (param_index)
2980 && (XFASTINT (param_index)
2981 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2982 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2983 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2988 /* Now process them in reverse of specified order. */
2989 for (i--; i >= 0; i--)
2991 Lisp_Object prop, val;
2993 prop = parms[i];
2994 val = values[i];
2996 if (EQ (prop, Qwidth) && NATNUMP (val))
2997 width = XFASTINT (val);
2998 else if (EQ (prop, Qheight) && NATNUMP (val))
2999 height = XFASTINT (val);
3000 else if (EQ (prop, Qtop))
3001 top = val;
3002 else if (EQ (prop, Qleft))
3003 left = val;
3004 else if (EQ (prop, Qicon_top))
3005 icon_top = val;
3006 else if (EQ (prop, Qicon_left))
3007 icon_left = val;
3008 else if (EQ (prop, Qforeground_color)
3009 || EQ (prop, Qbackground_color)
3010 || EQ (prop, Qfont)
3011 || EQ (prop, Qfullscreen))
3012 /* Processed above. */
3013 continue;
3014 else
3016 register Lisp_Object param_index, old_value;
3018 old_value = get_frame_param (f, prop);
3020 store_frame_param (f, prop, val);
3022 param_index = Fget (prop, Qx_frame_parameter);
3023 if (NATNUMP (param_index)
3024 && (XFASTINT (param_index)
3025 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3026 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3027 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3031 /* Don't die if just one of these was set. */
3032 if (EQ (left, Qunbound))
3034 left_no_change = 1;
3035 if (f->left_pos < 0)
3036 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
3037 else
3038 XSETINT (left, f->left_pos);
3040 if (EQ (top, Qunbound))
3042 top_no_change = 1;
3043 if (f->top_pos < 0)
3044 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
3045 else
3046 XSETINT (top, f->top_pos);
3049 /* If one of the icon positions was not set, preserve or default it. */
3050 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
3052 icon_left_no_change = 1;
3053 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3054 if (NILP (icon_left))
3055 XSETINT (icon_left, 0);
3057 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
3059 icon_top_no_change = 1;
3060 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3061 if (NILP (icon_top))
3062 XSETINT (icon_top, 0);
3065 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
3067 /* If the frame is visible already and the fullscreen parameter is
3068 being set, it is too late to set WM manager hints to specify
3069 size and position.
3070 Here we first get the width, height and position that applies to
3071 fullscreen. We then move the frame to the appropriate
3072 position. Resize of the frame is taken care of in the code after
3073 this if-statement. */
3074 int new_left, new_top;
3076 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
3077 if (new_top != f->top_pos || new_left != f->left_pos)
3078 x_set_offset (f, new_left, new_top, 1);
3081 /* Don't set these parameters unless they've been explicitly
3082 specified. The window might be mapped or resized while we're in
3083 this function, and we don't want to override that unless the lisp
3084 code has asked for it.
3086 Don't set these parameters unless they actually differ from the
3087 window's current parameters; the window may not actually exist
3088 yet. */
3090 Lisp_Object frame;
3092 check_frame_size (f, &height, &width);
3094 XSETFRAME (frame, f);
3096 if (width != FRAME_COLS (f)
3097 || height != FRAME_LINES (f)
3098 || f->new_text_lines || f->new_text_cols)
3099 Fset_frame_size (frame, make_number (width), make_number (height));
3101 if ((!NILP (left) || !NILP (top))
3102 && ! (left_no_change && top_no_change)
3103 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3104 && NUMBERP (top) && XINT (top) == f->top_pos))
3106 int leftpos = 0;
3107 int toppos = 0;
3109 /* Record the signs. */
3110 f->size_hint_flags &= ~ (XNegative | YNegative);
3111 if (EQ (left, Qminus))
3112 f->size_hint_flags |= XNegative;
3113 else if (INTEGERP (left))
3115 leftpos = XINT (left);
3116 if (leftpos < 0)
3117 f->size_hint_flags |= XNegative;
3119 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3120 && CONSP (XCDR (left))
3121 && INTEGERP (XCAR (XCDR (left))))
3123 leftpos = - XINT (XCAR (XCDR (left)));
3124 f->size_hint_flags |= XNegative;
3126 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3127 && CONSP (XCDR (left))
3128 && INTEGERP (XCAR (XCDR (left))))
3130 leftpos = XINT (XCAR (XCDR (left)));
3133 if (EQ (top, Qminus))
3134 f->size_hint_flags |= YNegative;
3135 else if (INTEGERP (top))
3137 toppos = XINT (top);
3138 if (toppos < 0)
3139 f->size_hint_flags |= YNegative;
3141 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3142 && CONSP (XCDR (top))
3143 && INTEGERP (XCAR (XCDR (top))))
3145 toppos = - XINT (XCAR (XCDR (top)));
3146 f->size_hint_flags |= YNegative;
3148 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3149 && CONSP (XCDR (top))
3150 && INTEGERP (XCAR (XCDR (top))))
3152 toppos = XINT (XCAR (XCDR (top)));
3156 /* Store the numeric value of the position. */
3157 f->top_pos = toppos;
3158 f->left_pos = leftpos;
3160 f->win_gravity = NorthWestGravity;
3162 /* Actually set that position, and convert to absolute. */
3163 x_set_offset (f, leftpos, toppos, -1);
3166 if ((!NILP (icon_left) || !NILP (icon_top))
3167 && ! (icon_left_no_change && icon_top_no_change))
3168 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3171 UNGCPRO;
3175 /* Insert a description of internally-recorded parameters of frame X
3176 into the parameter alist *ALISTPTR that is to be given to the user.
3177 Only parameters that are specific to the X window system
3178 and whose values are not correctly recorded in the frame's
3179 param_alist need to be considered here. */
3181 void
3182 x_report_frame_params (f, alistptr)
3183 struct frame *f;
3184 Lisp_Object *alistptr;
3186 char buf[16];
3187 Lisp_Object tem;
3189 /* Represent negative positions (off the top or left screen edge)
3190 in a way that Fmodify_frame_parameters will understand correctly. */
3191 XSETINT (tem, f->left_pos);
3192 if (f->left_pos >= 0)
3193 store_in_alist (alistptr, Qleft, tem);
3194 else
3195 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3197 XSETINT (tem, f->top_pos);
3198 if (f->top_pos >= 0)
3199 store_in_alist (alistptr, Qtop, tem);
3200 else
3201 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3203 store_in_alist (alistptr, Qborder_width,
3204 make_number (f->border_width));
3205 store_in_alist (alistptr, Qinternal_border_width,
3206 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3207 store_in_alist (alistptr, Qleft_fringe,
3208 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3209 store_in_alist (alistptr, Qright_fringe,
3210 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3211 store_in_alist (alistptr, Qscroll_bar_width,
3212 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3213 ? make_number (0)
3214 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3215 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3216 /* nil means "use default width"
3217 for non-toolkit scroll bar.
3218 ruler-mode.el depends on this. */
3219 : Qnil));
3220 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3221 store_in_alist (alistptr, Qwindow_id,
3222 build_string (buf));
3223 #ifdef HAVE_X_WINDOWS
3224 #ifdef USE_X_TOOLKIT
3225 /* Tooltip frame may not have this widget. */
3226 if (FRAME_X_OUTPUT (f)->widget)
3227 #endif
3228 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3229 store_in_alist (alistptr, Qouter_window_id,
3230 build_string (buf));
3231 #endif
3232 store_in_alist (alistptr, Qicon_name, f->icon_name);
3233 FRAME_SAMPLE_VISIBILITY (f);
3234 store_in_alist (alistptr, Qvisibility,
3235 (FRAME_VISIBLE_P (f) ? Qt
3236 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3237 store_in_alist (alistptr, Qdisplay,
3238 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3240 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3241 tem = Qnil;
3242 else
3243 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3244 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3245 store_in_alist (alistptr, Qparent_id, tem);
3249 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3250 the previous value of that parameter, NEW_VALUE is the new value. */
3252 void
3253 x_set_fullscreen (f, new_value, old_value)
3254 struct frame *f;
3255 Lisp_Object new_value, old_value;
3257 if (NILP (new_value))
3258 f->want_fullscreen = FULLSCREEN_NONE;
3259 else if (EQ (new_value, Qfullboth))
3260 f->want_fullscreen = FULLSCREEN_BOTH;
3261 else if (EQ (new_value, Qfullwidth))
3262 f->want_fullscreen = FULLSCREEN_WIDTH;
3263 else if (EQ (new_value, Qfullheight))
3264 f->want_fullscreen = FULLSCREEN_HEIGHT;
3266 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3267 FRAME_TERMINAL (f)->fullscreen_hook (f);
3271 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3272 the previous value of that parameter, NEW_VALUE is the new value. */
3274 void
3275 x_set_line_spacing (f, new_value, old_value)
3276 struct frame *f;
3277 Lisp_Object new_value, old_value;
3279 if (NILP (new_value))
3280 f->extra_line_spacing = 0;
3281 else if (NATNUMP (new_value))
3282 f->extra_line_spacing = XFASTINT (new_value);
3283 else
3284 signal_error ("Invalid line-spacing", new_value);
3285 if (FRAME_VISIBLE_P (f))
3286 redraw_frame (f);
3290 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3291 the previous value of that parameter, NEW_VALUE is the new value. */
3293 void
3294 x_set_screen_gamma (f, new_value, old_value)
3295 struct frame *f;
3296 Lisp_Object new_value, old_value;
3298 Lisp_Object bgcolor;
3300 if (NILP (new_value))
3301 f->gamma = 0;
3302 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3303 /* The value 0.4545 is the normal viewing gamma. */
3304 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3305 else
3306 signal_error ("Invalid screen-gamma", new_value);
3308 /* Apply the new gamma value to the frame background. */
3309 bgcolor = Fassq (Qbackground_color, f->param_alist);
3310 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3312 Lisp_Object index = Fget (Qbackground_color, Qx_frame_parameter);
3313 if (NATNUMP (index)
3314 && (XFASTINT (index)
3315 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3316 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3317 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3318 (f, bgcolor, Qnil);
3321 Fclear_face_cache (Qnil);
3325 void
3326 x_set_font (f, arg, oldval)
3327 struct frame *f;
3328 Lisp_Object arg, oldval;
3330 Lisp_Object frame;
3331 int fontset = -1;
3332 Lisp_Object font_object;
3334 /* Set the frame parameter back to the old value because we may
3335 fail to use ARG as the new parameter value. */
3336 store_frame_param (f, Qfont, oldval);
3338 /* ARG is a fontset name, a font name, or a font object.
3339 In the last case, this function never fail. */
3340 if (STRINGP (arg))
3342 fontset = fs_query_fontset (arg, 0);
3343 if (fontset < 0)
3345 font_object = font_open_by_name (f, SDATA (arg));
3346 if (NILP (font_object))
3347 error ("Font `%s' is not defined", SDATA (arg));
3348 arg = AREF (font_object, FONT_NAME_INDEX);
3350 else if (fontset > 0)
3352 Lisp_Object ascii_font = fontset_ascii (fontset);
3354 font_object = font_open_by_name (f, SDATA (ascii_font));
3355 if (NILP (font_object))
3356 error ("Font `%s' is not defined", SDATA (arg));
3357 arg = fontset_name (fontset);
3359 else
3360 error ("The default fontset can't be used for a frame font");
3362 else if (FONT_OBJECT_P (arg))
3364 font_object = arg;
3365 /* This is store the XLFD font name in the frame parameter for
3366 backward compatiblity. We should store the font-object
3367 itself in the future. */
3368 arg = AREF (font_object, FONT_NAME_INDEX);
3370 else
3371 signal_error ("Invalid font", arg);
3373 if (! NILP (Fequal (font_object, oldval)))
3374 return;
3375 x_new_font (f, font_object, fontset);
3376 store_frame_param (f, Qfont, arg);
3377 /* Recalculate toolbar height. */
3378 f->n_tool_bar_rows = 0;
3379 /* Ensure we redraw it. */
3380 clear_current_matrices (f);
3382 recompute_basic_faces (f);
3384 do_pending_window_change (0);
3386 /* We used to call face-set-after-frame-default here, but it leads to
3387 recursive calls (since that function can set the `default' face's
3388 font which in turns changes the frame's `font' parameter).
3389 Also I don't know what this call is meant to do, but it seems the
3390 wrong way to do it anyway (it does a lot more work than what seems
3391 reasonable in response to a change to `font'). */
3395 void
3396 x_set_font_backend (f, new_value, old_value)
3397 struct frame *f;
3398 Lisp_Object new_value, old_value;
3400 if (! NILP (new_value)
3401 && !CONSP (new_value))
3403 char *p0, *p1;
3405 CHECK_STRING (new_value);
3406 p0 = p1 = SDATA (new_value);
3407 new_value = Qnil;
3408 while (*p0)
3410 while (*p1 && ! isspace (*p1) && *p1 != ',') p1++;
3411 if (p0 < p1)
3412 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3413 new_value);
3414 if (*p1)
3416 int c;
3418 while ((c = *++p1) && isspace (c));
3420 p0 = p1;
3422 new_value = Fnreverse (new_value);
3425 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3426 return;
3428 if (FRAME_FONT (f))
3429 free_all_realized_faces (Qnil);
3431 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3432 if (NILP (new_value))
3434 if (NILP (old_value))
3435 error ("No font backend available");
3436 font_update_drivers (f, old_value);
3437 error ("None of specified font backends are available");
3439 store_frame_param (f, Qfont_backend, new_value);
3441 if (FRAME_FONT (f))
3443 Lisp_Object frame;
3445 XSETFRAME (frame, f);
3446 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3447 ++face_change_count;
3448 ++windows_or_buffers_changed;
3453 void
3454 x_set_fringe_width (f, new_value, old_value)
3455 struct frame *f;
3456 Lisp_Object new_value, old_value;
3458 compute_fringe_widths (f, 1);
3461 void
3462 x_set_border_width (f, arg, oldval)
3463 struct frame *f;
3464 Lisp_Object arg, oldval;
3466 CHECK_NUMBER (arg);
3468 if (XINT (arg) == f->border_width)
3469 return;
3471 if (FRAME_X_WINDOW (f) != 0)
3472 error ("Cannot change the border width of a frame");
3474 f->border_width = XINT (arg);
3477 void
3478 x_set_internal_border_width (f, arg, oldval)
3479 struct frame *f;
3480 Lisp_Object arg, oldval;
3482 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3484 CHECK_NUMBER (arg);
3485 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3486 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3487 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3489 #ifdef USE_X_TOOLKIT
3490 if (FRAME_X_OUTPUT (f)->edit_widget)
3491 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3492 #endif
3494 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3495 return;
3497 if (FRAME_X_WINDOW (f) != 0)
3499 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3500 SET_FRAME_GARBAGED (f);
3501 do_pending_window_change (0);
3503 else
3504 SET_FRAME_GARBAGED (f);
3507 void
3508 x_set_visibility (f, value, oldval)
3509 struct frame *f;
3510 Lisp_Object value, oldval;
3512 Lisp_Object frame;
3513 XSETFRAME (frame, f);
3515 if (NILP (value))
3516 Fmake_frame_invisible (frame, Qt);
3517 else if (EQ (value, Qicon))
3518 Ficonify_frame (frame);
3519 else
3520 Fmake_frame_visible (frame);
3523 void
3524 x_set_autoraise (f, arg, oldval)
3525 struct frame *f;
3526 Lisp_Object arg, oldval;
3528 f->auto_raise = !EQ (Qnil, arg);
3531 void
3532 x_set_autolower (f, arg, oldval)
3533 struct frame *f;
3534 Lisp_Object arg, oldval;
3536 f->auto_lower = !EQ (Qnil, arg);
3539 void
3540 x_set_unsplittable (f, arg, oldval)
3541 struct frame *f;
3542 Lisp_Object arg, oldval;
3544 f->no_split = !NILP (arg);
3547 void
3548 x_set_vertical_scroll_bars (f, arg, oldval)
3549 struct frame *f;
3550 Lisp_Object arg, oldval;
3552 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3553 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3554 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3555 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3557 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3558 = (NILP (arg)
3559 ? vertical_scroll_bar_none
3560 : EQ (Qleft, arg)
3561 ? vertical_scroll_bar_left
3562 : EQ (Qright, arg)
3563 ? vertical_scroll_bar_right
3564 : EQ (Qleft, Vdefault_frame_scroll_bars)
3565 ? vertical_scroll_bar_left
3566 : EQ (Qright, Vdefault_frame_scroll_bars)
3567 ? vertical_scroll_bar_right
3568 : vertical_scroll_bar_none);
3570 /* We set this parameter before creating the X window for the
3571 frame, so we can get the geometry right from the start.
3572 However, if the window hasn't been created yet, we shouldn't
3573 call x_set_window_size. */
3574 if (FRAME_X_WINDOW (f))
3575 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3576 do_pending_window_change (0);
3580 void
3581 x_set_scroll_bar_width (f, arg, oldval)
3582 struct frame *f;
3583 Lisp_Object arg, oldval;
3585 int wid = FRAME_COLUMN_WIDTH (f);
3587 if (NILP (arg))
3589 x_set_scroll_bar_default_width (f);
3591 if (FRAME_X_WINDOW (f))
3592 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3593 do_pending_window_change (0);
3595 else if (INTEGERP (arg) && XINT (arg) > 0
3596 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3598 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3599 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3601 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3602 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3603 if (FRAME_X_WINDOW (f))
3604 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3605 do_pending_window_change (0);
3608 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3609 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3610 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3615 /* Return non-nil if frame F wants a bitmap icon. */
3617 Lisp_Object
3618 x_icon_type (f)
3619 FRAME_PTR f;
3621 Lisp_Object tem;
3623 tem = assq_no_quit (Qicon_type, f->param_alist);
3624 if (CONSP (tem))
3625 return XCDR (tem);
3626 else
3627 return Qnil;
3630 void
3631 x_set_alpha (f, arg, oldval)
3632 struct frame *f;
3633 Lisp_Object arg, oldval;
3635 double alpha = 1.0;
3636 double newval[2];
3637 int i, ialpha;
3638 Lisp_Object item;
3640 for (i = 0; i < 2; i++)
3642 newval[i] = 1.0;
3643 if (CONSP (arg))
3645 item = CAR (arg);
3646 arg = CDR (arg);
3648 else
3649 item = arg;
3651 if (! NILP (item))
3653 if (FLOATP (item))
3655 alpha = XFLOAT_DATA (item);
3656 if (alpha < 0.0 || 1.0 < alpha)
3657 args_out_of_range (make_float (0.0), make_float (1.0));
3659 else if (INTEGERP (item))
3661 ialpha = XINT (item);
3662 if (ialpha < 0 || 100 < ialpha)
3663 args_out_of_range (make_number (0), make_number (100));
3664 else
3665 alpha = ialpha / 100.0;
3667 else
3668 wrong_type_argument (Qnumberp, item);
3670 newval[i] = alpha;
3673 for (i = 0; i < 2; i++)
3674 f->alpha[i] = newval[i];
3676 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
3677 BLOCK_INPUT;
3678 x_set_frame_alpha (f);
3679 UNBLOCK_INPUT;
3680 #endif
3682 return;
3686 /* Subroutines of creating an X frame. */
3688 /* Make sure that Vx_resource_name is set to a reasonable value.
3689 Fix it up, or set it to `emacs' if it is too hopeless. */
3691 void
3692 validate_x_resource_name ()
3694 int len = 0;
3695 /* Number of valid characters in the resource name. */
3696 int good_count = 0;
3697 /* Number of invalid characters in the resource name. */
3698 int bad_count = 0;
3699 Lisp_Object new;
3700 int i;
3702 if (!STRINGP (Vx_resource_class))
3703 Vx_resource_class = build_string (EMACS_CLASS);
3705 if (STRINGP (Vx_resource_name))
3707 unsigned char *p = SDATA (Vx_resource_name);
3708 int i;
3710 len = SBYTES (Vx_resource_name);
3712 /* Only letters, digits, - and _ are valid in resource names.
3713 Count the valid characters and count the invalid ones. */
3714 for (i = 0; i < len; i++)
3716 int c = p[i];
3717 if (! ((c >= 'a' && c <= 'z')
3718 || (c >= 'A' && c <= 'Z')
3719 || (c >= '0' && c <= '9')
3720 || c == '-' || c == '_'))
3721 bad_count++;
3722 else
3723 good_count++;
3726 else
3727 /* Not a string => completely invalid. */
3728 bad_count = 5, good_count = 0;
3730 /* If name is valid already, return. */
3731 if (bad_count == 0)
3732 return;
3734 /* If name is entirely invalid, or nearly so, use `emacs'. */
3735 if (good_count == 0
3736 || (good_count == 1 && bad_count > 0))
3738 Vx_resource_name = build_string ("emacs");
3739 return;
3742 /* Name is partly valid. Copy it and replace the invalid characters
3743 with underscores. */
3745 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3747 for (i = 0; i < len; i++)
3749 int c = SREF (new, i);
3750 if (! ((c >= 'a' && c <= 'z')
3751 || (c >= 'A' && c <= 'Z')
3752 || (c >= '0' && c <= '9')
3753 || c == '-' || c == '_'))
3754 SSET (new, i, '_');
3759 extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3760 extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3763 /* Get specified attribute from resource database RDB.
3764 See Fx_get_resource below for other parameters. */
3766 static Lisp_Object
3767 xrdb_get_resource (rdb, attribute, class, component, subclass)
3768 XrmDatabase rdb;
3769 Lisp_Object attribute, class, component, subclass;
3771 register char *value;
3772 char *name_key;
3773 char *class_key;
3775 CHECK_STRING (attribute);
3776 CHECK_STRING (class);
3778 if (!NILP (component))
3779 CHECK_STRING (component);
3780 if (!NILP (subclass))
3781 CHECK_STRING (subclass);
3782 if (NILP (component) != NILP (subclass))
3783 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3785 validate_x_resource_name ();
3787 /* Allocate space for the components, the dots which separate them,
3788 and the final '\0'. Make them big enough for the worst case. */
3789 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3790 + (STRINGP (component)
3791 ? SBYTES (component) : 0)
3792 + SBYTES (attribute)
3793 + 3);
3795 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3796 + SBYTES (class)
3797 + (STRINGP (subclass)
3798 ? SBYTES (subclass) : 0)
3799 + 3);
3801 /* Start with emacs.FRAMENAME for the name (the specific one)
3802 and with `Emacs' for the class key (the general one). */
3803 strcpy (name_key, SDATA (Vx_resource_name));
3804 strcpy (class_key, SDATA (Vx_resource_class));
3806 strcat (class_key, ".");
3807 strcat (class_key, SDATA (class));
3809 if (!NILP (component))
3811 strcat (class_key, ".");
3812 strcat (class_key, SDATA (subclass));
3814 strcat (name_key, ".");
3815 strcat (name_key, SDATA (component));
3818 strcat (name_key, ".");
3819 strcat (name_key, SDATA (attribute));
3821 value = x_get_string_resource (rdb, name_key, class_key);
3823 if (value != (char *) 0)
3824 return build_string (value);
3825 else
3826 return Qnil;
3830 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3831 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3832 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3833 class, where INSTANCE is the name under which Emacs was invoked, or
3834 the name specified by the `-name' or `-rn' command-line arguments.
3836 The optional arguments COMPONENT and SUBCLASS add to the key and the
3837 class, respectively. You must specify both of them or neither.
3838 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3839 and the class is `Emacs.CLASS.SUBCLASS'. */)
3840 (attribute, class, component, subclass)
3841 Lisp_Object attribute, class, component, subclass;
3843 #ifdef HAVE_X_WINDOWS
3844 check_x ();
3845 #endif
3847 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3848 attribute, class, component, subclass);
3851 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3853 Lisp_Object
3854 display_x_get_resource (dpyinfo, attribute, class, component, subclass)
3855 Display_Info *dpyinfo;
3856 Lisp_Object attribute, class, component, subclass;
3858 return xrdb_get_resource (dpyinfo->xrdb,
3859 attribute, class, component, subclass);
3862 /* Used when C code wants a resource value. */
3864 char *
3865 x_get_resource_string (attribute, class)
3866 char *attribute, *class;
3868 char *name_key;
3869 char *class_key;
3870 struct frame *sf = SELECTED_FRAME ();
3872 /* Allocate space for the components, the dots which separate them,
3873 and the final '\0'. */
3874 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3875 + strlen (attribute) + 2);
3876 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3877 + strlen (class) + 2);
3879 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3880 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3882 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3883 name_key, class_key);
3887 /* Return the value of parameter PARAM.
3889 First search ALIST, then Vdefault_frame_alist, then the X defaults
3890 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3892 Convert the resource to the type specified by desired_type.
3894 If no default is specified, return Qunbound. If you call
3895 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3896 and don't let it get stored in any Lisp-visible variables! */
3898 Lisp_Object
3899 x_get_arg (dpyinfo, alist, param, attribute, class, type)
3900 Display_Info *dpyinfo;
3901 Lisp_Object alist, param;
3902 char *attribute;
3903 char *class;
3904 enum resource_types type;
3906 register Lisp_Object tem;
3908 tem = Fassq (param, alist);
3910 if (!NILP (tem))
3912 /* If we find this parm in ALIST, clear it out
3913 so that it won't be "left over" at the end. */
3914 #ifndef WINDOWSNT /* w32fns.c has not yet been changed to cope with this. */
3915 Lisp_Object tail;
3916 XSETCAR (tem, Qnil);
3917 /* In case the parameter appears more than once in the alist,
3918 clear it out. */
3919 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3920 if (CONSP (XCAR (tail))
3921 && EQ (XCAR (XCAR (tail)), param))
3922 XSETCAR (XCAR (tail), Qnil);
3923 #endif
3925 else
3926 tem = Fassq (param, Vdefault_frame_alist);
3928 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3929 look in the X resources. */
3930 if (EQ (tem, Qnil))
3932 if (attribute)
3934 tem = display_x_get_resource (dpyinfo,
3935 build_string (attribute),
3936 build_string (class),
3937 Qnil, Qnil);
3939 if (NILP (tem))
3940 return Qunbound;
3942 switch (type)
3944 case RES_TYPE_NUMBER:
3945 return make_number (atoi (SDATA (tem)));
3947 case RES_TYPE_FLOAT:
3948 return make_float (atof (SDATA (tem)));
3950 case RES_TYPE_BOOLEAN:
3951 tem = Fdowncase (tem);
3952 if (!strcmp (SDATA (tem), "on")
3953 #ifdef HAVE_NS
3954 || !strcmp(SDATA(tem), "yes")
3955 #endif
3956 || !strcmp (SDATA (tem), "true"))
3957 return Qt;
3958 else
3959 return Qnil;
3961 case RES_TYPE_STRING:
3962 return tem;
3964 case RES_TYPE_SYMBOL:
3965 /* As a special case, we map the values `true' and `on'
3966 to Qt, and `false' and `off' to Qnil. */
3968 Lisp_Object lower;
3969 lower = Fdowncase (tem);
3970 if (!strcmp (SDATA (lower), "on")
3971 #ifdef HAVE_NS
3972 || !strcmp(SDATA(lower), "yes")
3973 #endif
3974 || !strcmp (SDATA (lower), "true"))
3975 return Qt;
3976 else if (!strcmp (SDATA (lower), "off")
3977 #ifdef HAVE_NS
3978 || !strcmp(SDATA(lower), "no")
3979 #endif
3980 || !strcmp (SDATA (lower), "false"))
3981 return Qnil;
3982 else
3983 return Fintern (tem, Qnil);
3986 default:
3987 abort ();
3990 else
3991 return Qunbound;
3993 return Fcdr (tem);
3996 Lisp_Object
3997 x_frame_get_arg (f, alist, param, attribute, class, type)
3998 struct frame *f;
3999 Lisp_Object alist, param;
4000 char *attribute;
4001 char *class;
4002 enum resource_types type;
4004 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
4005 alist, param, attribute, class, type);
4008 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4010 Lisp_Object
4011 x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
4012 struct frame *f;
4013 Lisp_Object alist, param;
4014 char *attribute;
4015 char *class;
4016 enum resource_types type;
4018 Lisp_Object value;
4020 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
4021 attribute, class, type);
4022 if (! NILP (value) && ! EQ (value, Qunbound))
4023 store_frame_param (f, param, value);
4025 return value;
4029 /* Record in frame F the specified or default value according to ALIST
4030 of the parameter named PROP (a Lisp symbol).
4031 If no value is specified for PROP, look for an X default for XPROP
4032 on the frame named NAME.
4033 If that is not found either, use the value DEFLT. */
4035 Lisp_Object
4036 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
4037 struct frame *f;
4038 Lisp_Object alist;
4039 Lisp_Object prop;
4040 Lisp_Object deflt;
4041 char *xprop;
4042 char *xclass;
4043 enum resource_types type;
4045 Lisp_Object tem;
4047 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4048 if (EQ (tem, Qunbound))
4049 tem = deflt;
4050 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
4051 return tem;
4057 #ifdef HAVE_NS
4059 /* We used to define x-parse-geometry directly in ns-win.el, but that
4060 confused make-docfile: the documentation string in ns-win.el was
4061 used for x-parse-geometry even in non-NS builds.. */
4063 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4064 doc: /* Parse a Nextstep-style geometry string STRING.
4065 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4066 The properties returned may include `top', `left', `height', and `width'.
4067 This works by calling `ns-parse-geometry'. */)
4068 (string)
4069 Lisp_Object string;
4071 call1 (Qns_parse_geometry, string);
4074 #else /* !HAVE_NS */
4076 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4077 doc: /* Parse an X-style geometry string STRING.
4078 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4079 The properties returned may include `top', `left', `height', and `width'.
4080 The value of `left' or `top' may be an integer,
4081 or a list (+ N) meaning N pixels relative to top/left corner,
4082 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
4083 (string)
4084 Lisp_Object string;
4086 int geometry, x, y;
4087 unsigned int width, height;
4088 Lisp_Object result;
4090 CHECK_STRING (string);
4092 geometry = XParseGeometry ((char *) SDATA (string),
4093 &x, &y, &width, &height);
4094 result = Qnil;
4095 if (geometry & XValue)
4097 Lisp_Object element;
4099 if (x >= 0 && (geometry & XNegative))
4100 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
4101 else if (x < 0 && ! (geometry & XNegative))
4102 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
4103 else
4104 element = Fcons (Qleft, make_number (x));
4105 result = Fcons (element, result);
4108 if (geometry & YValue)
4110 Lisp_Object element;
4112 if (y >= 0 && (geometry & YNegative))
4113 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
4114 else if (y < 0 && ! (geometry & YNegative))
4115 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
4116 else
4117 element = Fcons (Qtop, make_number (y));
4118 result = Fcons (element, result);
4121 if (geometry & WidthValue)
4122 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4123 if (geometry & HeightValue)
4124 result = Fcons (Fcons (Qheight, make_number (height)), result);
4126 return result;
4128 #endif /* HAVE_NS */
4131 /* Calculate the desired size and position of frame F.
4132 Return the flags saying which aspects were specified.
4134 Also set the win_gravity and size_hint_flags of F.
4136 Adjust height for toolbar if TOOLBAR_P is 1.
4138 This function does not make the coordinates positive. */
4140 #define DEFAULT_ROWS 40
4141 #define DEFAULT_COLS 80
4144 x_figure_window_size (f, parms, toolbar_p)
4145 struct frame *f;
4146 Lisp_Object parms;
4147 int toolbar_p;
4149 register Lisp_Object tem0, tem1, tem2;
4150 long window_prompting = 0;
4151 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
4153 /* Default values if we fall through.
4154 Actually, if that happens we should get
4155 window manager prompting. */
4156 SET_FRAME_COLS (f, DEFAULT_COLS);
4157 FRAME_LINES (f) = DEFAULT_ROWS;
4158 /* Window managers expect that if program-specified
4159 positions are not (0,0), they're intentional, not defaults. */
4160 f->top_pos = 0;
4161 f->left_pos = 0;
4163 /* Ensure that old new_text_cols and new_text_lines will not override the
4164 values set here. */
4165 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4166 f->new_text_cols = f->new_text_lines = 0;
4168 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4169 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4170 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4171 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4173 if (!EQ (tem0, Qunbound))
4175 CHECK_NUMBER (tem0);
4176 FRAME_LINES (f) = XINT (tem0);
4178 if (!EQ (tem1, Qunbound))
4180 CHECK_NUMBER (tem1);
4181 SET_FRAME_COLS (f, XINT (tem1));
4183 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4184 window_prompting |= USSize;
4185 else
4186 window_prompting |= PSize;
4189 f->scroll_bar_actual_width
4190 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4192 /* This used to be done _before_ calling x_figure_window_size, but
4193 since the height is reset here, this was really a no-op. I
4194 assume that moving it here does what Gerd intended (although he
4195 no longer can remember what that was... ++KFS, 2003-03-25. */
4197 /* Add the tool-bar height to the initial frame height so that the
4198 user gets a text display area of the size he specified with -g or
4199 via .Xdefaults. Later changes of the tool-bar height don't
4200 change the frame size. This is done so that users can create
4201 tall Emacs frames without having to guess how tall the tool-bar
4202 will get. */
4203 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4205 int margin, relief, bar_height;
4207 relief = (tool_bar_button_relief >= 0
4208 ? tool_bar_button_relief
4209 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4211 if (INTEGERP (Vtool_bar_button_margin)
4212 && XINT (Vtool_bar_button_margin) > 0)
4213 margin = XFASTINT (Vtool_bar_button_margin);
4214 else if (CONSP (Vtool_bar_button_margin)
4215 && INTEGERP (XCDR (Vtool_bar_button_margin))
4216 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
4217 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4218 else
4219 margin = 0;
4221 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4222 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4225 compute_fringe_widths (f, 0);
4227 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4228 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4230 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4231 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4232 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4233 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4235 if (EQ (tem0, Qminus))
4237 f->top_pos = 0;
4238 window_prompting |= YNegative;
4240 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4241 && CONSP (XCDR (tem0))
4242 && INTEGERP (XCAR (XCDR (tem0))))
4244 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4245 window_prompting |= YNegative;
4247 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4248 && CONSP (XCDR (tem0))
4249 && INTEGERP (XCAR (XCDR (tem0))))
4251 f->top_pos = XINT (XCAR (XCDR (tem0)));
4253 else if (EQ (tem0, Qunbound))
4254 f->top_pos = 0;
4255 else
4257 CHECK_NUMBER (tem0);
4258 f->top_pos = XINT (tem0);
4259 if (f->top_pos < 0)
4260 window_prompting |= YNegative;
4263 if (EQ (tem1, Qminus))
4265 f->left_pos = 0;
4266 window_prompting |= XNegative;
4268 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4269 && CONSP (XCDR (tem1))
4270 && INTEGERP (XCAR (XCDR (tem1))))
4272 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4273 window_prompting |= XNegative;
4275 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4276 && CONSP (XCDR (tem1))
4277 && INTEGERP (XCAR (XCDR (tem1))))
4279 f->left_pos = XINT (XCAR (XCDR (tem1)));
4281 else if (EQ (tem1, Qunbound))
4282 f->left_pos = 0;
4283 else
4285 CHECK_NUMBER (tem1);
4286 f->left_pos = XINT (tem1);
4287 if (f->left_pos < 0)
4288 window_prompting |= XNegative;
4291 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4292 window_prompting |= USPosition;
4293 else
4294 window_prompting |= PPosition;
4297 if (f->want_fullscreen != FULLSCREEN_NONE)
4299 int left, top;
4300 int width, height;
4302 /* It takes both for some WM:s to place it where we want */
4303 window_prompting |= USPosition | PPosition;
4304 x_fullscreen_adjust (f, &width, &height, &top, &left);
4305 FRAME_COLS (f) = width;
4306 FRAME_LINES (f) = height;
4307 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
4308 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
4309 f->left_pos = left;
4310 f->top_pos = top;
4313 if (window_prompting & XNegative)
4315 if (window_prompting & YNegative)
4316 f->win_gravity = SouthEastGravity;
4317 else
4318 f->win_gravity = NorthEastGravity;
4320 else
4322 if (window_prompting & YNegative)
4323 f->win_gravity = SouthWestGravity;
4324 else
4325 f->win_gravity = NorthWestGravity;
4328 f->size_hint_flags = window_prompting;
4330 return window_prompting;
4335 #endif /* HAVE_WINDOW_SYSTEM */
4339 /***********************************************************************
4340 Initialization
4341 ***********************************************************************/
4343 void
4344 syms_of_frame ()
4346 Qframep = intern ("framep");
4347 staticpro (&Qframep);
4348 Qframe_live_p = intern ("frame-live-p");
4349 staticpro (&Qframe_live_p);
4350 Qexplicit_name = intern ("explicit-name");
4351 staticpro (&Qexplicit_name);
4352 Qheight = intern ("height");
4353 staticpro (&Qheight);
4354 Qicon = intern ("icon");
4355 staticpro (&Qicon);
4356 Qminibuffer = intern ("minibuffer");
4357 staticpro (&Qminibuffer);
4358 Qmodeline = intern ("modeline");
4359 staticpro (&Qmodeline);
4360 Qonly = intern ("only");
4361 staticpro (&Qonly);
4362 Qwidth = intern ("width");
4363 staticpro (&Qwidth);
4364 Qgeometry = intern ("geometry");
4365 staticpro (&Qgeometry);
4366 Qicon_left = intern ("icon-left");
4367 staticpro (&Qicon_left);
4368 Qicon_top = intern ("icon-top");
4369 staticpro (&Qicon_top);
4370 Qleft = intern ("left");
4371 staticpro (&Qleft);
4372 Qright = intern ("right");
4373 staticpro (&Qright);
4374 Quser_position = intern ("user-position");
4375 staticpro (&Quser_position);
4376 Quser_size = intern ("user-size");
4377 staticpro (&Quser_size);
4378 Qwindow_id = intern ("window-id");
4379 staticpro (&Qwindow_id);
4380 #ifdef HAVE_X_WINDOWS
4381 Qouter_window_id = intern ("outer-window-id");
4382 staticpro (&Qouter_window_id);
4383 #endif
4384 Qparent_id = intern ("parent-id");
4385 staticpro (&Qparent_id);
4386 Qx = intern ("x");
4387 staticpro (&Qx);
4388 Qw32 = intern ("w32");
4389 staticpro (&Qw32);
4390 Qpc = intern ("pc");
4391 staticpro (&Qpc);
4392 Qmac = intern ("mac");
4393 staticpro (&Qmac);
4394 Qns = intern ("ns");
4395 staticpro (&Qns);
4396 Qvisible = intern ("visible");
4397 staticpro (&Qvisible);
4398 Qbuffer_predicate = intern ("buffer-predicate");
4399 staticpro (&Qbuffer_predicate);
4400 Qbuffer_list = intern ("buffer-list");
4401 staticpro (&Qbuffer_list);
4402 Qburied_buffer_list = intern ("buried-buffer-list");
4403 staticpro (&Qburied_buffer_list);
4404 Qdisplay_type = intern ("display-type");
4405 staticpro (&Qdisplay_type);
4406 Qbackground_mode = intern ("background-mode");
4407 staticpro (&Qbackground_mode);
4408 Qnoelisp = intern ("noelisp");
4409 staticpro (&Qnoelisp);
4410 Qtty_color_mode = intern ("tty-color-mode");
4411 staticpro (&Qtty_color_mode);
4412 Qtty = intern ("tty");
4413 staticpro (&Qtty);
4414 Qtty_type = intern ("tty-type");
4415 staticpro (&Qtty_type);
4417 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4418 staticpro (&Qface_set_after_frame_default);
4420 Qfullwidth = intern ("fullwidth");
4421 staticpro (&Qfullwidth);
4422 Qfullheight = intern ("fullheight");
4423 staticpro (&Qfullheight);
4424 Qfullboth = intern ("fullboth");
4425 staticpro (&Qfullboth);
4426 Qx_resource_name = intern ("x-resource-name");
4427 staticpro (&Qx_resource_name);
4429 Qx_frame_parameter = intern ("x-frame-parameter");
4430 staticpro (&Qx_frame_parameter);
4432 Qterminal = intern ("terminal");
4433 staticpro (&Qterminal);
4434 Qterminal_live_p = intern ("terminal-live-p");
4435 staticpro (&Qterminal_live_p);
4437 #ifdef HAVE_NS
4438 Qns_parse_geometry = intern ("ns-parse-geometry");
4439 staticpro (&Qns_parse_geometry);
4440 #endif
4443 int i;
4445 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4447 Lisp_Object v = intern (frame_parms[i].name);
4448 if (frame_parms[i].variable)
4450 *frame_parms[i].variable = v;
4451 staticpro (frame_parms[i].variable);
4453 Fput (v, Qx_frame_parameter, make_number (i));
4457 #ifdef HAVE_WINDOW_SYSTEM
4458 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4459 doc: /* The name Emacs uses to look up X resources.
4460 `x-get-resource' uses this as the first component of the instance name
4461 when requesting resource values.
4462 Emacs initially sets `x-resource-name' to the name under which Emacs
4463 was invoked, or to the value specified with the `-name' or `-rn'
4464 switches, if present.
4466 It may be useful to bind this variable locally around a call
4467 to `x-get-resource'. See also the variable `x-resource-class'. */);
4468 Vx_resource_name = Qnil;
4470 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4471 doc: /* The class Emacs uses to look up X resources.
4472 `x-get-resource' uses this as the first component of the instance class
4473 when requesting resource values.
4475 Emacs initially sets `x-resource-class' to "Emacs".
4477 Setting this variable permanently is not a reasonable thing to do,
4478 but binding this variable locally around a call to `x-get-resource'
4479 is a reasonable practice. See also the variable `x-resource-name'. */);
4480 Vx_resource_class = build_string (EMACS_CLASS);
4482 DEFVAR_LISP ("frame-alpha-lower-limit", &Vframe_alpha_lower_limit,
4483 doc: /* The lower limit of the frame opacity (alpha transparency).
4484 The value should range from 0 (invisible) to 100 (completely opaque).
4485 You can also use a floating number between 0.0 and 1.0.
4486 The default is 20. */);
4487 Vframe_alpha_lower_limit = make_number (20);
4488 #endif
4490 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4491 doc: /* Alist of default values for frame creation.
4492 These may be set in your init file, like this:
4493 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4494 These override values given in window system configuration data,
4495 including X Windows' defaults database.
4496 For values specific to the first Emacs frame, see `initial-frame-alist'.
4497 For window-system specific values, see `window-system-default-frame-alist'.
4498 For values specific to the separate minibuffer frame, see
4499 `minibuffer-frame-alist'.
4500 The `menu-bar-lines' element of the list controls whether new frames
4501 have menu bars; `menu-bar-mode' works by altering this element.
4502 Setting this variable does not affect existing frames, only new ones. */);
4503 Vdefault_frame_alist = Qnil;
4505 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4506 doc: /* Default position of scroll bars on this window-system. */);
4507 #ifdef HAVE_WINDOW_SYSTEM
4508 #if defined(HAVE_NTGUI) || defined(NS_IMPL_COCOA)
4509 /* MS-Windows and Mac OS X have scroll bars on the right by default. */
4510 Vdefault_frame_scroll_bars = Qright;
4511 #else
4512 Vdefault_frame_scroll_bars = Qleft;
4513 #endif
4514 #else
4515 Vdefault_frame_scroll_bars = Qnil;
4516 #endif
4518 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4519 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4521 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4522 doc: /* Non-nil if all of Emacs is iconified and frame updates are not needed. */);
4523 Vemacs_iconified = Qnil;
4525 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4526 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4527 `mouse-position' calls this function, passing its usual return value as
4528 argument, and returns whatever this function returns.
4529 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4530 which need to do mouse handling at the Lisp level. */);
4531 Vmouse_position_function = Qnil;
4533 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4534 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4535 If the value is an integer, highlighting is only shown after moving the
4536 mouse, while keyboard input turns off the highlight even when the mouse
4537 is over the clickable text. However, the mouse shape still indicates
4538 when the mouse is over clickable text. */);
4539 Vmouse_highlight = Qt;
4541 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4542 doc: /* Functions to be run before deleting a frame.
4543 The functions are run with one arg, the frame to be deleted.
4544 See `delete-frame'.
4546 Note that functions in this list may be called just before the frame is
4547 actually deleted, or some time later (or even both when an earlier function
4548 in `delete-frame-functions' (indirectly) calls `delete-frame'
4549 recursively). */);
4550 Vdelete_frame_functions = Qnil;
4551 Qdelete_frame_functions = intern ("delete-frame-functions");
4552 staticpro (&Qdelete_frame_functions);
4554 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4555 doc: /* Minibufferless frames use this frame's minibuffer.
4557 Emacs cannot create minibufferless frames unless this is set to an
4558 appropriate surrogate.
4560 Emacs consults this variable only when creating minibufferless
4561 frames; once the frame is created, it sticks with its assigned
4562 minibuffer, no matter what this variable is set to. This means that
4563 this variable doesn't necessarily say anything meaningful about the
4564 current set of frames, or where the minibuffer is currently being
4565 displayed.
4567 This variable is local to the current terminal and cannot be buffer-local. */);
4569 DEFVAR_BOOL ("focus-follows-mouse", &focus_follows_mouse,
4570 doc: /* Non-nil if window system changes focus when you move the mouse.
4571 You should set this variable to tell Emacs how your window manager
4572 handles focus, since there is no way in general for Emacs to find out
4573 automatically. */);
4574 #ifdef HAVE_WINDOW_SYSTEM
4575 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
4576 focus_follows_mouse = 0;
4577 #else
4578 focus_follows_mouse = 1;
4579 #endif
4580 #else
4581 focus_follows_mouse = 0;
4582 #endif
4584 staticpro (&Vframe_list);
4586 defsubr (&Sactive_minibuffer_window);
4587 defsubr (&Sframep);
4588 defsubr (&Sframe_live_p);
4589 defsubr (&Swindow_system);
4590 defsubr (&Smake_terminal_frame);
4591 defsubr (&Shandle_switch_frame);
4592 defsubr (&Sselect_frame);
4593 defsubr (&Sselected_frame);
4594 defsubr (&Swindow_frame);
4595 defsubr (&Sframe_root_window);
4596 defsubr (&Sframe_first_window);
4597 defsubr (&Sframe_selected_window);
4598 defsubr (&Sset_frame_selected_window);
4599 defsubr (&Sframe_list);
4600 defsubr (&Snext_frame);
4601 defsubr (&Sprevious_frame);
4602 defsubr (&Sdelete_frame);
4603 defsubr (&Smouse_position);
4604 defsubr (&Smouse_pixel_position);
4605 defsubr (&Sset_mouse_position);
4606 defsubr (&Sset_mouse_pixel_position);
4607 #if 0
4608 defsubr (&Sframe_configuration);
4609 defsubr (&Srestore_frame_configuration);
4610 #endif
4611 defsubr (&Smake_frame_visible);
4612 defsubr (&Smake_frame_invisible);
4613 defsubr (&Siconify_frame);
4614 defsubr (&Sframe_visible_p);
4615 defsubr (&Svisible_frame_list);
4616 defsubr (&Sraise_frame);
4617 defsubr (&Slower_frame);
4618 defsubr (&Sredirect_frame_focus);
4619 defsubr (&Sframe_focus);
4620 defsubr (&Sframe_parameters);
4621 defsubr (&Sframe_parameter);
4622 defsubr (&Smodify_frame_parameters);
4623 defsubr (&Sframe_char_height);
4624 defsubr (&Sframe_char_width);
4625 defsubr (&Sframe_pixel_height);
4626 defsubr (&Sframe_pixel_width);
4627 defsubr (&Sset_frame_height);
4628 defsubr (&Sset_frame_width);
4629 defsubr (&Sset_frame_size);
4630 defsubr (&Sset_frame_position);
4632 #ifdef HAVE_WINDOW_SYSTEM
4633 defsubr (&Sx_get_resource);
4634 defsubr (&Sx_parse_geometry);
4635 #endif
4639 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4640 (do not change this comment) */