* subr.el (unintern): Declare the obarray arg mandatory.
[emacs.git] / src / frame.c
bloba30d1e18175a1234c08da6920c39ad22ab1d8619
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 <setjmp.h>
25 #include "lisp.h"
26 #include "character.h"
27 #ifdef HAVE_X_WINDOWS
28 #include "xterm.h"
29 #endif
30 #ifdef WINDOWSNT
31 #include "w32term.h"
32 #endif
33 #ifdef HAVE_NS
34 #include "nsterm.h"
35 #endif
36 #include "buffer.h"
37 /* These help us bind and responding to switch-frame events. */
38 #include "commands.h"
39 #include "keyboard.h"
40 #include "frame.h"
41 #include "blockinput.h"
42 #include "termchar.h"
43 #include "termhooks.h"
44 #include "dispextern.h"
45 #include "window.h"
46 #include "font.h"
47 #ifdef HAVE_WINDOW_SYSTEM
48 #include "fontset.h"
49 #endif
50 #ifdef MSDOS
51 #include "msdos.h"
52 #include "dosfns.h"
53 #endif
56 /* If we shall make pointer invisible when typing or not. */
57 Lisp_Object Vmake_pointer_invisible;
59 #ifdef HAVE_WINDOW_SYSTEM
61 /* The name we're using in resource queries. Most often "emacs". */
63 Lisp_Object Vx_resource_name;
65 /* The application class we're using in resource queries.
66 Normally "Emacs". */
68 Lisp_Object Vx_resource_class;
70 /* Lower limit value of the frame opacity (alpha transparency). */
72 Lisp_Object Vframe_alpha_lower_limit;
74 #endif
76 #ifdef HAVE_NS
77 Lisp_Object Qns_parse_geometry;
78 #endif
80 Lisp_Object Qframep, Qframe_live_p;
81 Lisp_Object Qicon, Qmodeline;
82 Lisp_Object Qonly;
83 Lisp_Object Qx, Qw32, Qmac, Qpc, Qns;
84 Lisp_Object Qvisible;
85 Lisp_Object Qdisplay_type;
86 Lisp_Object Qbackground_mode;
87 Lisp_Object Qnoelisp;
89 Lisp_Object Qx_frame_parameter;
90 Lisp_Object Qx_resource_name;
91 Lisp_Object Qterminal;
92 Lisp_Object Qterminal_live_p;
94 /* Frame parameters (set or reported). */
96 Lisp_Object Qauto_raise, Qauto_lower;
97 Lisp_Object Qborder_color, Qborder_width;
98 Lisp_Object Qcursor_color, Qcursor_type;
99 Lisp_Object Qgeometry; /* Not used */
100 Lisp_Object Qheight, Qwidth;
101 Lisp_Object Qleft, Qright;
102 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
103 Lisp_Object Qtooltip;
104 Lisp_Object Qinternal_border_width;
105 Lisp_Object Qmouse_color;
106 Lisp_Object Qminibuffer;
107 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
108 Lisp_Object Qvisibility;
109 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
110 Lisp_Object Qscreen_gamma;
111 Lisp_Object Qline_spacing;
112 Lisp_Object Quser_position, Quser_size;
113 Lisp_Object Qwait_for_wm;
114 Lisp_Object Qwindow_id;
115 #ifdef HAVE_X_WINDOWS
116 Lisp_Object Qouter_window_id;
117 #endif
118 Lisp_Object Qparent_id;
119 Lisp_Object Qtitle, Qname;
120 Lisp_Object Qexplicit_name;
121 Lisp_Object Qunsplittable;
122 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
123 Lisp_Object Qleft_fringe, Qright_fringe;
124 Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list;
125 Lisp_Object Qtty_color_mode;
126 Lisp_Object Qtty, Qtty_type;
128 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth, Qmaximized;
129 Lisp_Object Qsticky;
130 Lisp_Object Qfont_backend;
131 Lisp_Object Qalpha;
133 Lisp_Object Qface_set_after_frame_default;
135 Lisp_Object Vterminal_frame;
136 Lisp_Object Vdefault_frame_alist;
137 Lisp_Object Vdefault_frame_scroll_bars;
138 Lisp_Object Vmouse_position_function;
139 Lisp_Object Vmouse_highlight;
140 static Lisp_Object Vdelete_frame_functions, Qdelete_frame_functions;
142 int focus_follows_mouse;
144 static void
145 set_menu_bar_lines_1 (window, n)
146 Lisp_Object window;
147 int n;
149 struct window *w = XWINDOW (window);
151 XSETFASTINT (w->last_modified, 0);
152 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
153 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
155 if (INTEGERP (w->orig_top_line))
156 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
157 if (INTEGERP (w->orig_total_lines))
158 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
160 /* Handle just the top child in a vertical split. */
161 if (!NILP (w->vchild))
162 set_menu_bar_lines_1 (w->vchild, n);
164 /* Adjust all children in a horizontal split. */
165 for (window = w->hchild; !NILP (window); window = w->next)
167 w = XWINDOW (window);
168 set_menu_bar_lines_1 (window, n);
172 void
173 set_menu_bar_lines (f, value, oldval)
174 struct frame *f;
175 Lisp_Object value, oldval;
177 int nlines;
178 int olines = FRAME_MENU_BAR_LINES (f);
180 /* Right now, menu bars don't work properly in minibuf-only frames;
181 most of the commands try to apply themselves to the minibuffer
182 frame itself, and get an error because you can't switch buffers
183 in or split the minibuffer window. */
184 if (FRAME_MINIBUF_ONLY_P (f))
185 return;
187 if (INTEGERP (value))
188 nlines = XINT (value);
189 else
190 nlines = 0;
192 if (nlines != olines)
194 windows_or_buffers_changed++;
195 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
196 FRAME_MENU_BAR_LINES (f) = nlines;
197 set_menu_bar_lines_1 (f->root_window, nlines - olines);
198 adjust_glyphs (f);
202 Lisp_Object Vframe_list;
204 extern Lisp_Object Vminibuffer_list;
205 extern Lisp_Object get_minibuffer ();
206 extern Lisp_Object Fhandle_switch_frame ();
207 extern Lisp_Object Fredirect_frame_focus ();
208 extern Lisp_Object x_get_focus_frame ();
209 extern Lisp_Object QCname, Qfont_param;
212 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
213 doc: /* Return non-nil if OBJECT is a frame.
214 Value is t for a termcap frame (a character-only terminal),
215 `x' for an Emacs frame that is really an X window,
216 `w32' for an Emacs frame that is a window on MS-Windows display,
217 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
218 `pc' for a direct-write MS-DOS frame.
219 See also `frame-live-p'. */)
220 (object)
221 Lisp_Object object;
223 if (!FRAMEP (object))
224 return Qnil;
225 switch (XFRAME (object)->output_method)
227 case output_initial: /* The initial frame is like a termcap frame. */
228 case output_termcap:
229 return Qt;
230 case output_x_window:
231 return Qx;
232 case output_w32:
233 return Qw32;
234 case output_msdos_raw:
235 return Qpc;
236 case output_mac:
237 return Qmac;
238 case output_ns:
239 return Qns;
240 default:
241 abort ();
245 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
246 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
247 Value is nil if OBJECT is not a live frame. If object is a live
248 frame, the return value indicates what sort of terminal device it is
249 displayed on. See the documentation of `framep' for possible
250 return values. */)
251 (object)
252 Lisp_Object object;
254 return ((FRAMEP (object)
255 && FRAME_LIVE_P (XFRAME (object)))
256 ? Fframep (object)
257 : Qnil);
260 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
261 doc: /* The name of the window system that FRAME is displaying through.
262 The value is a symbol---for instance, 'x' for X windows.
263 The value is nil if Emacs is using a text-only terminal.
265 FRAME defaults to the currently selected frame. */)
266 (frame)
267 Lisp_Object frame;
269 Lisp_Object type;
270 if (NILP (frame))
271 frame = selected_frame;
273 type = Fframep (frame);
275 if (NILP (type))
276 wrong_type_argument (Qframep, frame);
278 if (EQ (type, Qt))
279 return Qnil;
280 else
281 return type;
284 struct frame *
285 make_frame (mini_p)
286 int mini_p;
288 Lisp_Object frame;
289 register struct frame *f;
290 register Lisp_Object root_window;
291 register Lisp_Object mini_window;
293 f = allocate_frame ();
294 XSETFRAME (frame, f);
296 f->desired_matrix = 0;
297 f->current_matrix = 0;
298 f->desired_pool = 0;
299 f->current_pool = 0;
300 f->glyphs_initialized_p = 0;
301 f->decode_mode_spec_buffer = 0;
302 f->visible = 0;
303 f->async_visible = 0;
304 f->output_data.nothing = 0;
305 f->iconified = 0;
306 f->async_iconified = 0;
307 f->wants_modeline = 1;
308 f->auto_raise = 0;
309 f->auto_lower = 0;
310 f->no_split = 0;
311 f->garbaged = 1;
312 f->has_minibuffer = mini_p;
313 f->focus_frame = Qnil;
314 f->explicit_name = 0;
315 f->can_have_scroll_bars = 0;
316 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
317 f->param_alist = Qnil;
318 f->scroll_bars = Qnil;
319 f->condemned_scroll_bars = Qnil;
320 f->face_alist = Qnil;
321 f->face_cache = NULL;
322 f->menu_bar_items = Qnil;
323 f->menu_bar_vector = Qnil;
324 f->menu_bar_items_used = 0;
325 f->buffer_predicate = Qnil;
326 f->buffer_list = Qnil;
327 f->buried_buffer_list = Qnil;
328 f->namebuf = 0;
329 f->title = Qnil;
330 f->menu_bar_window = Qnil;
331 f->tool_bar_window = Qnil;
332 f->tool_bar_items = Qnil;
333 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
334 f->n_tool_bar_items = 0;
335 f->left_fringe_width = f->right_fringe_width = 0;
336 f->fringe_cols = 0;
337 f->scroll_bar_actual_width = 0;
338 f->border_width = 0;
339 f->internal_border_width = 0;
340 f->column_width = 1; /* !FRAME_WINDOW_P value */
341 f->line_height = 1; /* !FRAME_WINDOW_P value */
342 f->x_pixels_diff = f->y_pixels_diff = 0;
343 #ifdef HAVE_WINDOW_SYSTEM
344 f->want_fullscreen = FULLSCREEN_NONE;
345 #endif
346 f->size_hint_flags = 0;
347 f->win_gravity = 0;
348 f->font_driver_list = NULL;
349 f->font_data_list = NULL;
351 root_window = make_window ();
352 if (mini_p)
354 mini_window = make_window ();
355 XWINDOW (root_window)->next = mini_window;
356 XWINDOW (mini_window)->prev = root_window;
357 XWINDOW (mini_window)->mini_p = Qt;
358 XWINDOW (mini_window)->frame = frame;
359 f->minibuffer_window = mini_window;
361 else
363 mini_window = Qnil;
364 XWINDOW (root_window)->next = Qnil;
365 f->minibuffer_window = Qnil;
368 XWINDOW (root_window)->frame = frame;
370 /* 10 is arbitrary,
371 just so that there is "something there."
372 Correct size will be set up later with change_frame_size. */
374 SET_FRAME_COLS (f, 10);
375 FRAME_LINES (f) = 10;
377 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
378 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
380 if (mini_p)
382 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
383 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
384 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
387 /* Choose a buffer for the frame's root window. */
389 Lisp_Object buf;
391 XWINDOW (root_window)->buffer = Qt;
392 buf = Fcurrent_buffer ();
393 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
394 a space), try to find another one. */
395 if (SREF (Fbuffer_name (buf), 0) == ' ')
396 buf = Fother_buffer (buf, Qnil, Qnil);
398 /* Use set_window_buffer, not Fset_window_buffer, and don't let
399 hooks be run by it. The reason is that the whole frame/window
400 arrangement is not yet fully intialized at this point. Windows
401 don't have the right size, glyph matrices aren't initialized
402 etc. Running Lisp functions at this point surely ends in a
403 SEGV. */
404 set_window_buffer (root_window, buf, 0, 0);
405 f->buffer_list = Fcons (buf, Qnil);
408 if (mini_p)
410 XWINDOW (mini_window)->buffer = Qt;
411 set_window_buffer (mini_window,
412 (NILP (Vminibuffer_list)
413 ? get_minibuffer (0)
414 : Fcar (Vminibuffer_list)),
415 0, 0);
418 f->root_window = root_window;
419 f->selected_window = root_window;
420 /* Make sure this window seems more recently used than
421 a newly-created, never-selected window. */
422 ++window_select_count;
423 XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
425 f->default_face_done_p = 0;
427 return f;
430 #ifdef HAVE_WINDOW_SYSTEM
431 /* Make a frame using a separate minibuffer window on another frame.
432 MINI_WINDOW is the minibuffer window to use. nil means use the
433 default (the global minibuffer). */
435 struct frame *
436 make_frame_without_minibuffer (mini_window, kb, display)
437 register Lisp_Object mini_window;
438 KBOARD *kb;
439 Lisp_Object display;
441 register struct frame *f;
442 struct gcpro gcpro1;
444 if (!NILP (mini_window))
445 CHECK_LIVE_WINDOW (mini_window);
447 if (!NILP (mini_window)
448 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
449 error ("Frame and minibuffer must be on the same terminal");
451 /* Make a frame containing just a root window. */
452 f = make_frame (0);
454 if (NILP (mini_window))
456 /* Use default-minibuffer-frame if possible. */
457 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
458 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
460 Lisp_Object frame_dummy;
462 XSETFRAME (frame_dummy, f);
463 GCPRO1 (frame_dummy);
464 /* If there's no minibuffer frame to use, create one. */
465 kb->Vdefault_minibuffer_frame =
466 call1 (intern ("make-initial-minibuffer-frame"), display);
467 UNGCPRO;
470 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
473 f->minibuffer_window = mini_window;
475 /* Make the chosen minibuffer window display the proper minibuffer,
476 unless it is already showing a minibuffer. */
477 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
478 Fset_window_buffer (mini_window,
479 (NILP (Vminibuffer_list)
480 ? get_minibuffer (0)
481 : Fcar (Vminibuffer_list)), Qnil);
482 return f;
485 /* Make a frame containing only a minibuffer window. */
487 struct frame *
488 make_minibuffer_frame ()
490 /* First make a frame containing just a root window, no minibuffer. */
492 register struct frame *f = make_frame (0);
493 register Lisp_Object mini_window;
494 register Lisp_Object frame;
496 XSETFRAME (frame, f);
498 f->auto_raise = 0;
499 f->auto_lower = 0;
500 f->no_split = 1;
501 f->wants_modeline = 0;
502 f->has_minibuffer = 1;
504 /* Now label the root window as also being the minibuffer.
505 Avoid infinite looping on the window chain by marking next pointer
506 as nil. */
508 mini_window = f->minibuffer_window = f->root_window;
509 XWINDOW (mini_window)->mini_p = Qt;
510 XWINDOW (mini_window)->next = Qnil;
511 XWINDOW (mini_window)->prev = Qnil;
512 XWINDOW (mini_window)->frame = frame;
514 /* Put the proper buffer in that window. */
516 Fset_window_buffer (mini_window,
517 (NILP (Vminibuffer_list)
518 ? get_minibuffer (0)
519 : Fcar (Vminibuffer_list)), Qnil);
520 return f;
522 #endif /* HAVE_WINDOW_SYSTEM */
524 /* Construct a frame that refers to a terminal. */
526 static int tty_frame_count;
528 struct frame *
529 make_initial_frame (void)
531 struct frame *f;
532 struct terminal *terminal;
533 Lisp_Object frame;
535 eassert (initial_kboard);
537 /* The first call must initialize Vframe_list. */
538 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
539 Vframe_list = Qnil;
541 terminal = init_initial_terminal ();
543 f = make_frame (1);
544 XSETFRAME (frame, f);
546 Vframe_list = Fcons (frame, Vframe_list);
548 tty_frame_count = 1;
549 f->name = make_pure_c_string ("F1");
551 f->visible = 1;
552 f->async_visible = 1;
554 f->output_method = terminal->type;
555 f->terminal = terminal;
556 f->terminal->reference_count++;
557 f->output_data.nothing = 0;
559 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
560 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
562 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
563 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
565 #ifdef CANNOT_DUMP
566 if (!noninteractive)
567 init_frame_faces (f);
568 #endif
570 return f;
574 struct frame *
575 make_terminal_frame (struct terminal *terminal)
577 register struct frame *f;
578 Lisp_Object frame;
579 char name[20];
581 if (!terminal->name)
582 error ("Terminal is not live, can't create new frames on it");
584 f = make_frame (1);
586 XSETFRAME (frame, f);
587 Vframe_list = Fcons (frame, Vframe_list);
589 tty_frame_count++;
590 sprintf (name, "F%d", tty_frame_count);
591 f->name = build_string (name);
593 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
594 f->async_visible = 1; /* Don't let visible be cleared later. */
595 f->terminal = terminal;
596 f->terminal->reference_count++;
597 #ifdef MSDOS
598 f->output_data.tty->display_info = &the_only_display_info;
599 if (!inhibit_window_system
600 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
601 || XFRAME (selected_frame)->output_method == output_msdos_raw))
602 f->output_method = output_msdos_raw;
603 else
604 f->output_method = output_termcap;
605 #else /* not MSDOS */
606 f->output_method = output_termcap;
607 create_tty_output (f);
608 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
609 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
610 #endif /* not MSDOS */
612 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
613 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
615 /* Set the top frame to the newly created frame. */
616 if (FRAMEP (FRAME_TTY (f)->top_frame)
617 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
618 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
620 FRAME_TTY (f)->top_frame = frame;
622 if (!noninteractive)
623 init_frame_faces (f);
625 return f;
628 /* Get a suitable value for frame parameter PARAMETER for a newly
629 created frame, based on (1) the user-supplied frame parameter
630 alist SUPPLIED_PARMS, (2) CURRENT_VALUE, and finally, if all else
631 fails, (3) Vdefault_frame_alist. */
633 static Lisp_Object
634 get_future_frame_param (Lisp_Object parameter,
635 Lisp_Object supplied_parms,
636 char *current_value)
638 Lisp_Object result;
640 result = Fassq (parameter, supplied_parms);
641 if (NILP (result))
642 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
643 if (NILP (result) && current_value != NULL)
644 result = build_string (current_value);
645 if (NILP (result))
646 result = Fassq (parameter, Vdefault_frame_alist);
647 if (!NILP (result) && !STRINGP (result))
648 result = XCDR (result);
649 if (NILP (result) || !STRINGP (result))
650 result = Qnil;
652 return result;
655 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
656 1, 1, 0,
657 doc: /* Create an additional terminal frame, possibly on another terminal.
658 This function takes one argument, an alist specifying frame parameters.
660 You can create multiple frames on a single text-only terminal, but
661 only one of them (the selected terminal frame) is actually displayed.
663 In practice, generally you don't need to specify any parameters,
664 except when you want to create a new frame on another terminal.
665 In that case, the `tty' parameter specifies the device file to open,
666 and the `tty-type' parameter specifies the terminal type. Example:
668 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
670 Note that changing the size of one terminal frame automatically
671 affects all frames on the same terminal device. */)
672 (parms)
673 Lisp_Object parms;
675 struct frame *f;
676 struct terminal *t = NULL;
677 Lisp_Object frame, tem;
678 struct frame *sf = SELECTED_FRAME ();
680 #ifdef MSDOS
681 if (sf->output_method != output_msdos_raw
682 && sf->output_method != output_termcap)
683 abort ();
684 #else /* not MSDOS */
686 #ifdef WINDOWSNT /* This should work now! */
687 if (sf->output_method != output_termcap)
688 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
689 #endif
690 #endif /* not MSDOS */
693 Lisp_Object terminal;
695 terminal = Fassq (Qterminal, parms);
696 if (!NILP (terminal))
698 terminal = XCDR (terminal);
699 t = get_terminal (terminal, 1);
701 #ifdef MSDOS
702 if (t && t != the_only_display_info.terminal)
703 /* msdos.c assumes a single tty_display_info object. */
704 error ("Multiple terminals are not supported on this platform");
705 if (!t)
706 t = the_only_display_info.terminal;
707 #endif
710 if (!t)
712 char *name = 0, *type = 0;
713 Lisp_Object tty, tty_type;
715 tty = get_future_frame_param
716 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
717 ? FRAME_TTY (XFRAME (selected_frame))->name
718 : NULL));
719 if (!NILP (tty))
721 name = (char *) alloca (SBYTES (tty) + 1);
722 strncpy (name, SDATA (tty), SBYTES (tty));
723 name[SBYTES (tty)] = 0;
726 tty_type = get_future_frame_param
727 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
728 ? FRAME_TTY (XFRAME (selected_frame))->type
729 : NULL));
730 if (!NILP (tty_type))
732 type = (char *) alloca (SBYTES (tty_type) + 1);
733 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
734 type[SBYTES (tty_type)] = 0;
737 t = init_tty (name, type, 0); /* Errors are not fatal. */
740 f = make_terminal_frame (t);
743 int width, height;
744 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
745 change_frame_size (f, height, width, 0, 0, 0);
748 adjust_glyphs (f);
749 calculate_costs (f);
750 XSETFRAME (frame, f);
751 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
752 Fmodify_frame_parameters (frame, parms);
753 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
754 build_string (t->display_info.tty->type)),
755 Qnil));
756 if (t->display_info.tty->name != NULL)
757 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
758 build_string (t->display_info.tty->name)),
759 Qnil));
760 else
761 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
763 /* Make the frame face alist be frame-specific, so that each
764 frame could change its face definitions independently. */
765 f->face_alist = Fcopy_alist (sf->face_alist);
766 /* Simple Fcopy_alist isn't enough, because we need the contents of
767 the vectors which are the CDRs of associations in face_alist to
768 be copied as well. */
769 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
770 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
771 return frame;
775 /* Perform the switch to frame FRAME.
777 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
778 FRAME1 as frame.
780 If TRACK is non-zero and the frame that currently has the focus
781 redirects its focus to the selected frame, redirect that focused
782 frame's focus to FRAME instead.
784 FOR_DELETION non-zero means that the selected frame is being
785 deleted, which includes the possibility that the frame's terminal
786 is dead.
788 The value of NORECORD is passed as argument to Fselect_window. */
790 Lisp_Object
791 do_switch_frame (frame, track, for_deletion, norecord)
792 Lisp_Object frame, norecord;
793 int track, for_deletion;
795 struct frame *sf = SELECTED_FRAME ();
797 /* If FRAME is a switch-frame event, extract the frame we should
798 switch to. */
799 if (CONSP (frame)
800 && EQ (XCAR (frame), Qswitch_frame)
801 && CONSP (XCDR (frame)))
802 frame = XCAR (XCDR (frame));
804 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
805 a switch-frame event to arrive after a frame is no longer live,
806 especially when deleting the initial frame during startup. */
807 CHECK_FRAME (frame);
808 if (! FRAME_LIVE_P (XFRAME (frame)))
809 return Qnil;
811 if (sf == XFRAME (frame))
812 return frame;
814 /* This is too greedy; it causes inappropriate focus redirection
815 that's hard to get rid of. */
816 #if 0
817 /* If a frame's focus has been redirected toward the currently
818 selected frame, we should change the redirection to point to the
819 newly selected frame. This means that if the focus is redirected
820 from a minibufferless frame to a surrogate minibuffer frame, we
821 can use `other-window' to switch between all the frames using
822 that minibuffer frame, and the focus redirection will follow us
823 around. */
824 if (track)
826 Lisp_Object tail;
828 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
830 Lisp_Object focus;
832 if (!FRAMEP (XCAR (tail)))
833 abort ();
835 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
837 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
838 Fredirect_frame_focus (XCAR (tail), frame);
841 #else /* ! 0 */
842 /* Instead, apply it only to the frame we're pointing to. */
843 #ifdef HAVE_WINDOW_SYSTEM
844 if (track && FRAME_WINDOW_P (XFRAME (frame)))
846 Lisp_Object focus, xfocus;
848 xfocus = x_get_focus_frame (XFRAME (frame));
849 if (FRAMEP (xfocus))
851 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
852 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
853 Fredirect_frame_focus (xfocus, frame);
856 #endif /* HAVE_X_WINDOWS */
857 #endif /* ! 0 */
859 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
860 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
862 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
864 if (FRAMEP (FRAME_TTY (XFRAME (frame))->top_frame))
865 /* Mark previously displayed frame as now obscured. */
866 XFRAME (FRAME_TTY (XFRAME (frame))->top_frame)->async_visible = 2;
867 XFRAME (frame)->async_visible = 1;
868 FRAME_TTY (XFRAME (frame))->top_frame = frame;
871 selected_frame = frame;
872 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
873 last_nonminibuf_frame = XFRAME (selected_frame);
875 Fselect_window (XFRAME (frame)->selected_window, norecord);
877 /* We want to make sure that the next event generates a frame-switch
878 event to the appropriate frame. This seems kludgy to me, but
879 before you take it out, make sure that evaluating something like
880 (select-window (frame-root-window (new-frame))) doesn't end up
881 with your typing being interpreted in the new frame instead of
882 the one you're actually typing in. */
883 internal_last_event_frame = Qnil;
885 return frame;
888 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
889 doc: /* Select FRAME.
890 Subsequent editing commands apply to its selected window.
891 Optional argument NORECORD means to neither change the order of
892 recently selected windows nor the buffer list.
894 The selection of FRAME lasts until the next time the user does
895 something to select a different frame, or until the next time
896 this function is called. If you are using a window system, the
897 previously selected frame may be restored as the selected frame
898 when returning to the command loop, because it still may have
899 the window system's input focus. On a text-only terminal, the
900 next redisplay will display FRAME.
902 This function returns FRAME, or nil if FRAME has been deleted. */)
903 (frame, norecord)
904 Lisp_Object frame, norecord;
906 return do_switch_frame (frame, 1, 0, norecord);
910 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
911 doc: /* Handle a switch-frame event EVENT.
912 Switch-frame events are usually bound to this function.
913 A switch-frame event tells Emacs that the window manager has requested
914 that the user's events be directed to the frame mentioned in the event.
915 This function selects the selected window of the frame of EVENT.
917 If EVENT is frame object, handle it as if it were a switch-frame event
918 to that frame. */)
919 (event)
920 Lisp_Object event;
922 /* Preserve prefix arg that the command loop just cleared. */
923 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
924 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
925 return do_switch_frame (event, 0, 0, Qnil);
928 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
929 doc: /* Return the frame that is now selected. */)
932 return selected_frame;
935 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
936 doc: /* Return the frame object that window WINDOW is on. */)
937 (window)
938 Lisp_Object window;
940 CHECK_LIVE_WINDOW (window);
941 return XWINDOW (window)->frame;
944 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
945 doc: /* Returns the topmost, leftmost window of FRAME.
946 If omitted, FRAME defaults to the currently selected frame. */)
947 (frame)
948 Lisp_Object frame;
950 Lisp_Object w;
952 if (NILP (frame))
953 w = SELECTED_FRAME ()->root_window;
954 else
956 CHECK_LIVE_FRAME (frame);
957 w = XFRAME (frame)->root_window;
959 while (NILP (XWINDOW (w)->buffer))
961 if (! NILP (XWINDOW (w)->hchild))
962 w = XWINDOW (w)->hchild;
963 else if (! NILP (XWINDOW (w)->vchild))
964 w = XWINDOW (w)->vchild;
965 else
966 abort ();
968 return w;
971 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
972 Sactive_minibuffer_window, 0, 0, 0,
973 doc: /* Return the currently active minibuffer window, or nil if none. */)
976 return minibuf_level ? minibuf_window : Qnil;
979 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
980 doc: /* Returns the root-window of FRAME.
981 If omitted, FRAME defaults to the currently selected frame. */)
982 (frame)
983 Lisp_Object frame;
985 Lisp_Object window;
987 if (NILP (frame))
988 window = SELECTED_FRAME ()->root_window;
989 else
991 CHECK_LIVE_FRAME (frame);
992 window = XFRAME (frame)->root_window;
995 return window;
998 DEFUN ("frame-selected-window", Fframe_selected_window,
999 Sframe_selected_window, 0, 1, 0,
1000 doc: /* Return the selected window of FRAME.
1001 FRAME defaults to the currently selected frame. */)
1002 (frame)
1003 Lisp_Object frame;
1005 Lisp_Object window;
1007 if (NILP (frame))
1008 window = SELECTED_FRAME ()->selected_window;
1009 else
1011 CHECK_LIVE_FRAME (frame);
1012 window = XFRAME (frame)->selected_window;
1015 return window;
1018 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
1019 Sset_frame_selected_window, 2, 3, 0,
1020 doc: /* Set selected window of FRAME to WINDOW.
1021 If FRAME is nil, use the selected frame. If FRAME is the
1022 selected frame, this makes WINDOW the selected window.
1023 Optional argument NORECORD non-nil means to neither change the
1024 order of recently selected windows nor the buffer list.
1025 Return WINDOW. */)
1026 (frame, window, norecord)
1027 Lisp_Object frame, window, norecord;
1029 if (NILP (frame))
1030 frame = selected_frame;
1032 CHECK_LIVE_FRAME (frame);
1033 CHECK_LIVE_WINDOW (window);
1035 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
1036 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
1038 if (EQ (frame, selected_frame))
1039 return Fselect_window (window, norecord);
1041 return XFRAME (frame)->selected_window = window;
1045 DEFUN ("frame-list", Fframe_list, Sframe_list,
1046 0, 0, 0,
1047 doc: /* Return a list of all live frames. */)
1050 Lisp_Object frames;
1051 frames = Fcopy_sequence (Vframe_list);
1052 #ifdef HAVE_WINDOW_SYSTEM
1053 if (FRAMEP (tip_frame))
1054 frames = Fdelq (tip_frame, frames);
1055 #endif
1056 return frames;
1059 /* Return the next frame in the frame list after FRAME.
1060 If MINIBUF is nil, exclude minibuffer-only frames.
1061 If MINIBUF is a window, include only its own frame
1062 and any frame now using that window as the minibuffer.
1063 If MINIBUF is `visible', include all visible frames.
1064 If MINIBUF is 0, include all visible and iconified frames.
1065 Otherwise, include all frames. */
1067 static Lisp_Object
1068 next_frame (frame, minibuf)
1069 Lisp_Object frame;
1070 Lisp_Object minibuf;
1072 Lisp_Object tail;
1073 int passed = 0;
1075 /* There must always be at least one frame in Vframe_list. */
1076 if (! CONSP (Vframe_list))
1077 abort ();
1079 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
1080 forever. Forestall that. */
1081 CHECK_LIVE_FRAME (frame);
1083 while (1)
1084 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1086 Lisp_Object f;
1088 f = XCAR (tail);
1090 if (passed
1091 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1092 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1093 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1094 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
1096 /* Decide whether this frame is eligible to be returned. */
1098 /* If we've looped all the way around without finding any
1099 eligible frames, return the original frame. */
1100 if (EQ (f, frame))
1101 return f;
1103 /* Let minibuf decide if this frame is acceptable. */
1104 if (NILP (minibuf))
1106 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1107 return f;
1109 else if (EQ (minibuf, Qvisible))
1111 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1112 if (FRAME_VISIBLE_P (XFRAME (f)))
1113 return f;
1115 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1117 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1118 if (FRAME_VISIBLE_P (XFRAME (f))
1119 || FRAME_ICONIFIED_P (XFRAME (f)))
1120 return f;
1122 else if (WINDOWP (minibuf))
1124 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1125 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1126 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1127 FRAME_FOCUS_FRAME (XFRAME (f))))
1128 return f;
1130 else
1131 return f;
1134 if (EQ (frame, f))
1135 passed++;
1139 /* Return the previous frame in the frame list before FRAME.
1140 If MINIBUF is nil, exclude minibuffer-only frames.
1141 If MINIBUF is a window, include only its own frame
1142 and any frame now using that window as the minibuffer.
1143 If MINIBUF is `visible', include all visible frames.
1144 If MINIBUF is 0, include all visible and iconified frames.
1145 Otherwise, include all frames. */
1147 static Lisp_Object
1148 prev_frame (frame, minibuf)
1149 Lisp_Object frame;
1150 Lisp_Object minibuf;
1152 Lisp_Object tail;
1153 Lisp_Object prev;
1155 /* There must always be at least one frame in Vframe_list. */
1156 if (! CONSP (Vframe_list))
1157 abort ();
1159 prev = Qnil;
1160 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1162 Lisp_Object f;
1164 f = XCAR (tail);
1165 if (!FRAMEP (f))
1166 abort ();
1168 if (EQ (frame, f) && !NILP (prev))
1169 return prev;
1171 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1172 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1173 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1174 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1176 /* Decide whether this frame is eligible to be returned,
1177 according to minibuf. */
1178 if (NILP (minibuf))
1180 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1181 prev = f;
1183 else if (WINDOWP (minibuf))
1185 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1186 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1187 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1188 FRAME_FOCUS_FRAME (XFRAME (f))))
1189 prev = f;
1191 else if (EQ (minibuf, Qvisible))
1193 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1194 if (FRAME_VISIBLE_P (XFRAME (f)))
1195 prev = f;
1197 else if (XFASTINT (minibuf) == 0)
1199 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1200 if (FRAME_VISIBLE_P (XFRAME (f))
1201 || FRAME_ICONIFIED_P (XFRAME (f)))
1202 prev = f;
1204 else
1205 prev = f;
1209 /* We've scanned the entire list. */
1210 if (NILP (prev))
1211 /* We went through the whole frame list without finding a single
1212 acceptable frame. Return the original frame. */
1213 return frame;
1214 else
1215 /* There were no acceptable frames in the list before FRAME; otherwise,
1216 we would have returned directly from the loop. Since PREV is the last
1217 acceptable frame in the list, return it. */
1218 return prev;
1222 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1223 doc: /* Return the next frame in the frame list after FRAME.
1224 It considers only frames on the same terminal as FRAME.
1225 By default, skip minibuffer-only frames.
1226 If omitted, FRAME defaults to the selected frame.
1227 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1228 If MINIFRAME is a window, include only its own frame
1229 and any frame now using that window as the minibuffer.
1230 If MINIFRAME is `visible', include all visible frames.
1231 If MINIFRAME is 0, include all visible and iconified frames.
1232 Otherwise, include all frames. */)
1233 (frame, miniframe)
1234 Lisp_Object frame, miniframe;
1236 if (NILP (frame))
1237 frame = selected_frame;
1239 CHECK_LIVE_FRAME (frame);
1240 return next_frame (frame, miniframe);
1243 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1244 doc: /* Return the previous frame in the frame list before FRAME.
1245 It considers only frames on the same terminal as FRAME.
1246 By default, skip minibuffer-only frames.
1247 If omitted, FRAME defaults to the selected frame.
1248 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1249 If MINIFRAME is a window, include only its own frame
1250 and any frame now using that window as the minibuffer.
1251 If MINIFRAME is `visible', include all visible frames.
1252 If MINIFRAME is 0, include all visible and iconified frames.
1253 Otherwise, include all frames. */)
1254 (frame, miniframe)
1255 Lisp_Object frame, miniframe;
1257 if (NILP (frame))
1258 frame = selected_frame;
1259 CHECK_LIVE_FRAME (frame);
1260 return prev_frame (frame, miniframe);
1263 /* Return 1 if it is ok to delete frame F;
1264 0 if all frames aside from F are invisible.
1265 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1268 other_visible_frames (f)
1269 FRAME_PTR f;
1271 /* We know the selected frame is visible,
1272 so if F is some other frame, it can't be the sole visible one. */
1273 if (f == SELECTED_FRAME ())
1275 Lisp_Object frames;
1276 int count = 0;
1278 for (frames = Vframe_list;
1279 CONSP (frames);
1280 frames = XCDR (frames))
1282 Lisp_Object this;
1284 this = XCAR (frames);
1285 /* Verify that the frame's window still exists
1286 and we can still talk to it. And note any recent change
1287 in visibility. */
1288 #ifdef HAVE_WINDOW_SYSTEM
1289 if (FRAME_WINDOW_P (XFRAME (this)))
1291 x_sync (XFRAME (this));
1292 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1294 #endif
1296 if (FRAME_VISIBLE_P (XFRAME (this))
1297 || FRAME_ICONIFIED_P (XFRAME (this))
1298 /* Allow deleting the terminal frame when at least
1299 one X frame exists! */
1300 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1301 count++;
1303 return count > 1;
1305 return 1;
1308 /* Error handler for `delete-frame-functions'. */
1309 static Lisp_Object
1310 delete_frame_handler (Lisp_Object arg)
1312 add_to_log ("Error during `delete-frame': %s", arg, Qnil);
1313 return Qnil;
1316 extern Lisp_Object Qrun_hook_with_args;
1318 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1319 unconditionally. x_connection_closed and delete_terminal use
1320 this. Any other value of FORCE implements the semantics
1321 described for Fdelete_frame. */
1322 Lisp_Object
1323 delete_frame (frame, force)
1324 /* If we use `register' here, gcc-4.0.2 on amd64 using
1325 -DUSE_LISP_UNION_TYPE complains further down that we're getting the
1326 address of `force'. Go figure. */
1327 Lisp_Object frame, force;
1329 struct frame *f;
1330 struct frame *sf = SELECTED_FRAME ();
1331 struct kboard *kb;
1333 int minibuffer_selected, tooltip_frame;
1335 if (EQ (frame, Qnil))
1337 f = sf;
1338 XSETFRAME (frame, f);
1340 else
1342 CHECK_FRAME (frame);
1343 f = XFRAME (frame);
1346 if (! FRAME_LIVE_P (f))
1347 return Qnil;
1349 if (NILP (force) && !other_visible_frames (f))
1350 error ("Attempt to delete the sole visible or iconified frame");
1352 /* x_connection_closed must have set FORCE to `noelisp' in order
1353 to delete the last frame, if it is gone. */
1354 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1355 error ("Attempt to delete the only frame");
1357 /* Does this frame have a minibuffer, and is it the surrogate
1358 minibuffer for any other frame? */
1359 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1361 Lisp_Object frames;
1363 for (frames = Vframe_list;
1364 CONSP (frames);
1365 frames = XCDR (frames))
1367 Lisp_Object this;
1368 this = XCAR (frames);
1370 if (! EQ (this, frame)
1371 && EQ (frame,
1372 WINDOW_FRAME (XWINDOW
1373 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1375 /* If we MUST delete this frame, delete the other first.
1376 But do this only if FORCE equals `noelisp'. */
1377 if (EQ (force, Qnoelisp))
1378 delete_frame (this, Qnoelisp);
1379 else
1380 error ("Attempt to delete a surrogate minibuffer frame");
1385 tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1387 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1388 frame is a tooltip. FORCE is set to `noelisp' when handling
1389 a disconnect from the terminal, so we don't dare call Lisp
1390 code. */
1391 if (NILP (Vrun_hooks) || tooltip_frame)
1393 else if (EQ (force, Qnoelisp))
1394 pending_funcalls
1395 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1396 pending_funcalls);
1397 else
1398 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1400 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1401 if (! FRAME_LIVE_P (f))
1402 return Qnil;
1404 /* At this point, we are committed to deleting the frame.
1405 There is no more chance for errors to prevent it. */
1407 minibuffer_selected = EQ (minibuf_window, selected_window);
1409 /* Don't let the frame remain selected. */
1410 if (f == sf)
1412 Lisp_Object tail, frame1;
1414 /* Look for another visible frame on the same terminal. */
1415 frame1 = next_frame (frame, Qvisible);
1417 /* If there is none, find *some* other frame. */
1418 if (NILP (frame1) || EQ (frame1, frame))
1420 FOR_EACH_FRAME (tail, frame1)
1422 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1423 break;
1426 #ifdef NS_IMPL_COCOA
1427 else
1428 /* Under NS, there is no system mechanism for choosing a new
1429 window to get focus -- it is left to application code.
1430 So the portion of THIS application interfacing with NS
1431 needs to know about it. We call Fraise_frame, but the
1432 purpose is really to transfer focus. */
1433 Fraise_frame (frame1);
1434 #endif
1436 do_switch_frame (frame1, 0, 1, Qnil);
1437 sf = SELECTED_FRAME ();
1440 /* Don't allow minibuf_window to remain on a deleted frame. */
1441 if (EQ (f->minibuffer_window, minibuf_window))
1443 Fset_window_buffer (sf->minibuffer_window,
1444 XWINDOW (minibuf_window)->buffer, Qnil);
1445 minibuf_window = sf->minibuffer_window;
1447 /* If the dying minibuffer window was selected,
1448 select the new one. */
1449 if (minibuffer_selected)
1450 Fselect_window (minibuf_window, Qnil);
1453 /* Don't let echo_area_window to remain on a deleted frame. */
1454 if (EQ (f->minibuffer_window, echo_area_window))
1455 echo_area_window = sf->minibuffer_window;
1457 /* Clear any X selections for this frame. */
1458 #ifdef HAVE_X_WINDOWS
1459 if (FRAME_X_P (f))
1460 x_clear_frame_selections (f);
1461 #endif
1463 /* Free glyphs.
1464 This function must be called before the window tree of the
1465 frame is deleted because windows contain dynamically allocated
1466 memory. */
1467 free_glyphs (f);
1469 #ifdef HAVE_WINDOW_SYSTEM
1470 /* Give chance to each font driver to free a frame specific data. */
1471 font_update_drivers (f, Qnil);
1472 #endif
1474 /* Mark all the windows that used to be on FRAME as deleted, and then
1475 remove the reference to them. */
1476 delete_all_subwindows (XWINDOW (f->root_window));
1477 f->root_window = Qnil;
1479 Vframe_list = Fdelq (frame, Vframe_list);
1480 FRAME_SET_VISIBLE (f, 0);
1482 /* Allow the vector of menu bar contents to be freed in the next
1483 garbage collection. The frame object itself may not be garbage
1484 collected until much later, because recent_keys and other data
1485 structures can still refer to it. */
1486 f->menu_bar_vector = Qnil;
1488 free_font_driver_list (f);
1489 xfree (f->namebuf);
1490 xfree (f->decode_mode_spec_buffer);
1491 xfree (FRAME_INSERT_COST (f));
1492 xfree (FRAME_DELETEN_COST (f));
1493 xfree (FRAME_INSERTN_COST (f));
1494 xfree (FRAME_DELETE_COST (f));
1495 xfree (FRAME_MESSAGE_BUF (f));
1497 /* Since some events are handled at the interrupt level, we may get
1498 an event for f at any time; if we zero out the frame's terminal
1499 now, then we may trip up the event-handling code. Instead, we'll
1500 promise that the terminal of the frame must be valid until we
1501 have called the window-system-dependent frame destruction
1502 routine. */
1504 if (FRAME_TERMINAL (f)->delete_frame_hook)
1505 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1508 struct terminal *terminal = FRAME_TERMINAL (f);
1509 f->output_data.nothing = 0;
1510 f->terminal = 0; /* Now the frame is dead. */
1512 /* If needed, delete the terminal that this frame was on.
1513 (This must be done after the frame is killed.) */
1514 terminal->reference_count--;
1515 if (terminal->reference_count == 0)
1517 Lisp_Object tmp;
1518 XSETTERMINAL (tmp, terminal);
1520 kb = NULL;
1521 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1523 else
1524 kb = terminal->kboard;
1527 /* If we've deleted the last_nonminibuf_frame, then try to find
1528 another one. */
1529 if (f == last_nonminibuf_frame)
1531 Lisp_Object frames;
1533 last_nonminibuf_frame = 0;
1535 for (frames = Vframe_list;
1536 CONSP (frames);
1537 frames = XCDR (frames))
1539 f = XFRAME (XCAR (frames));
1540 if (!FRAME_MINIBUF_ONLY_P (f))
1542 last_nonminibuf_frame = f;
1543 break;
1548 /* If there's no other frame on the same kboard, get out of
1549 single-kboard state if we're in it for this kboard. */
1550 if (kb != NULL)
1552 Lisp_Object frames;
1553 /* Some frame we found on the same kboard, or nil if there are none. */
1554 Lisp_Object frame_on_same_kboard;
1556 frame_on_same_kboard = Qnil;
1558 for (frames = Vframe_list;
1559 CONSP (frames);
1560 frames = XCDR (frames))
1562 Lisp_Object this;
1563 struct frame *f1;
1565 this = XCAR (frames);
1566 if (!FRAMEP (this))
1567 abort ();
1568 f1 = XFRAME (this);
1570 if (kb == FRAME_KBOARD (f1))
1571 frame_on_same_kboard = this;
1574 if (NILP (frame_on_same_kboard))
1575 not_single_kboard_state (kb);
1579 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1580 find another one. Prefer minibuffer-only frames, but also notice
1581 frames with other windows. */
1582 if (kb != NULL && EQ (frame, kb->Vdefault_minibuffer_frame))
1584 Lisp_Object frames;
1586 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1587 Lisp_Object frame_with_minibuf;
1588 /* Some frame we found on the same kboard, or nil if there are none. */
1589 Lisp_Object frame_on_same_kboard;
1591 frame_on_same_kboard = Qnil;
1592 frame_with_minibuf = Qnil;
1594 for (frames = Vframe_list;
1595 CONSP (frames);
1596 frames = XCDR (frames))
1598 Lisp_Object this;
1599 struct frame *f1;
1601 this = XCAR (frames);
1602 if (!FRAMEP (this))
1603 abort ();
1604 f1 = XFRAME (this);
1606 /* Consider only frames on the same kboard
1607 and only those with minibuffers. */
1608 if (kb == FRAME_KBOARD (f1)
1609 && FRAME_HAS_MINIBUF_P (f1))
1611 frame_with_minibuf = this;
1612 if (FRAME_MINIBUF_ONLY_P (f1))
1613 break;
1616 if (kb == FRAME_KBOARD (f1))
1617 frame_on_same_kboard = this;
1620 if (!NILP (frame_on_same_kboard))
1622 /* We know that there must be some frame with a minibuffer out
1623 there. If this were not true, all of the frames present
1624 would have to be minibufferless, which implies that at some
1625 point their minibuffer frames must have been deleted, but
1626 that is prohibited at the top; you can't delete surrogate
1627 minibuffer frames. */
1628 if (NILP (frame_with_minibuf))
1629 abort ();
1631 kb->Vdefault_minibuffer_frame = frame_with_minibuf;
1633 else
1634 /* No frames left on this kboard--say no minibuffer either. */
1635 kb->Vdefault_minibuffer_frame = Qnil;
1638 /* Cause frame titles to update--necessary if we now have just one frame. */
1639 if (!tooltip_frame)
1640 update_mode_lines = 1;
1642 return Qnil;
1645 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1646 doc: /* Delete FRAME, permanently eliminating it from use.
1647 FRAME defaults to the selected frame.
1649 A frame may not be deleted if its minibuffer is used by other frames.
1650 Normally, you may not delete a frame if all other frames are invisible,
1651 but if the second optional argument FORCE is non-nil, you may do so.
1653 This function runs `delete-frame-functions' before actually
1654 deleting the frame, unless the frame is a tooltip.
1655 The functions are run with one argument, the frame to be deleted. */)
1656 (frame, force)
1657 Lisp_Object frame, force;
1659 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1663 /* Return mouse position in character cell units. */
1665 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1666 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1667 The position is given in character cells, where (0, 0) is the
1668 upper-left corner of the frame, X is the horizontal offset, and Y is
1669 the vertical offset.
1670 If Emacs is running on a mouseless terminal or hasn't been programmed
1671 to read the mouse position, it returns the selected frame for FRAME
1672 and nil for X and Y.
1673 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1674 passing the normal return value to that function as an argument,
1675 and returns whatever that function returns. */)
1678 FRAME_PTR f;
1679 Lisp_Object lispy_dummy;
1680 enum scroll_bar_part party_dummy;
1681 Lisp_Object x, y, retval;
1682 int col, row;
1683 unsigned long long_dummy;
1684 struct gcpro gcpro1;
1686 f = SELECTED_FRAME ();
1687 x = y = Qnil;
1689 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1690 /* It's okay for the hook to refrain from storing anything. */
1691 if (FRAME_TERMINAL (f)->mouse_position_hook)
1692 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1693 &lispy_dummy, &party_dummy,
1694 &x, &y,
1695 &long_dummy);
1696 if (! NILP (x))
1698 col = XINT (x);
1699 row = XINT (y);
1700 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1701 XSETINT (x, col);
1702 XSETINT (y, row);
1704 #endif
1705 XSETFRAME (lispy_dummy, f);
1706 retval = Fcons (lispy_dummy, Fcons (x, y));
1707 GCPRO1 (retval);
1708 if (!NILP (Vmouse_position_function))
1709 retval = call1 (Vmouse_position_function, retval);
1710 RETURN_UNGCPRO (retval);
1713 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1714 Smouse_pixel_position, 0, 0, 0,
1715 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1716 The position is given in pixel units, where (0, 0) is the
1717 upper-left corner of the frame, X is the horizontal offset, and Y is
1718 the vertical offset.
1719 If Emacs is running on a mouseless terminal or hasn't been programmed
1720 to read the mouse position, it returns the selected frame for FRAME
1721 and nil for X and Y. */)
1724 FRAME_PTR f;
1725 Lisp_Object lispy_dummy;
1726 enum scroll_bar_part party_dummy;
1727 Lisp_Object x, y;
1728 unsigned long long_dummy;
1730 f = SELECTED_FRAME ();
1731 x = y = Qnil;
1733 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1734 /* It's okay for the hook to refrain from storing anything. */
1735 if (FRAME_TERMINAL (f)->mouse_position_hook)
1736 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1737 &lispy_dummy, &party_dummy,
1738 &x, &y,
1739 &long_dummy);
1740 #endif
1741 XSETFRAME (lispy_dummy, f);
1742 return Fcons (lispy_dummy, Fcons (x, y));
1745 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1746 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1747 Coordinates are relative to the frame, not a window,
1748 so the coordinates of the top left character in the frame
1749 may be nonzero due to left-hand scroll bars or the menu bar.
1751 The position is given in character cells, where (0, 0) is the
1752 upper-left corner of the frame, X is the horizontal offset, and Y is
1753 the vertical offset.
1755 This function is a no-op for an X frame that is not visible.
1756 If you have just created a frame, you must wait for it to become visible
1757 before calling this function on it, like this.
1758 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1759 (frame, x, y)
1760 Lisp_Object frame, x, y;
1762 CHECK_LIVE_FRAME (frame);
1763 CHECK_NUMBER (x);
1764 CHECK_NUMBER (y);
1766 /* I think this should be done with a hook. */
1767 #ifdef HAVE_WINDOW_SYSTEM
1768 if (FRAME_WINDOW_P (XFRAME (frame)))
1769 /* Warping the mouse will cause enternotify and focus events. */
1770 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1771 #else
1772 #if defined (MSDOS) && defined (HAVE_MOUSE)
1773 if (FRAME_MSDOS_P (XFRAME (frame)))
1775 Fselect_frame (frame, Qnil);
1776 mouse_moveto (XINT (x), XINT (y));
1778 #else
1779 #ifdef HAVE_GPM
1781 Fselect_frame (frame, Qnil);
1782 term_mouse_moveto (XINT (x), XINT (y));
1784 #endif
1785 #endif
1786 #endif
1788 return Qnil;
1791 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1792 Sset_mouse_pixel_position, 3, 3, 0,
1793 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1794 The position is given in pixels, where (0, 0) is the upper-left corner
1795 of the frame, X is the horizontal offset, and Y is the vertical offset.
1797 Note, this is a no-op for an X frame that is not visible.
1798 If you have just created a frame, you must wait for it to become visible
1799 before calling this function on it, like this.
1800 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1801 (frame, x, y)
1802 Lisp_Object frame, x, y;
1804 CHECK_LIVE_FRAME (frame);
1805 CHECK_NUMBER (x);
1806 CHECK_NUMBER (y);
1808 /* I think this should be done with a hook. */
1809 #ifdef HAVE_WINDOW_SYSTEM
1810 if (FRAME_WINDOW_P (XFRAME (frame)))
1811 /* Warping the mouse will cause enternotify and focus events. */
1812 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1813 #else
1814 #if defined (MSDOS) && defined (HAVE_MOUSE)
1815 if (FRAME_MSDOS_P (XFRAME (frame)))
1817 Fselect_frame (frame, Qnil);
1818 mouse_moveto (XINT (x), XINT (y));
1820 #else
1821 #ifdef HAVE_GPM
1823 Fselect_frame (frame, Qnil);
1824 term_mouse_moveto (XINT (x), XINT (y));
1826 #endif
1827 #endif
1828 #endif
1830 return Qnil;
1833 static void make_frame_visible_1 P_ ((Lisp_Object));
1835 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1836 0, 1, "",
1837 doc: /* Make the frame FRAME visible (assuming it is an X window).
1838 If omitted, FRAME defaults to the currently selected frame. */)
1839 (frame)
1840 Lisp_Object frame;
1842 if (NILP (frame))
1843 frame = selected_frame;
1845 CHECK_LIVE_FRAME (frame);
1847 /* I think this should be done with a hook. */
1848 #ifdef HAVE_WINDOW_SYSTEM
1849 if (FRAME_WINDOW_P (XFRAME (frame)))
1851 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1852 x_make_frame_visible (XFRAME (frame));
1854 #endif
1856 make_frame_visible_1 (XFRAME (frame)->root_window);
1858 /* Make menu bar update for the Buffers and Frames menus. */
1859 windows_or_buffers_changed++;
1861 return frame;
1864 /* Update the display_time slot of the buffers shown in WINDOW
1865 and all its descendents. */
1867 static void
1868 make_frame_visible_1 (window)
1869 Lisp_Object window;
1871 struct window *w;
1873 for (;!NILP (window); window = w->next)
1875 w = XWINDOW (window);
1877 if (!NILP (w->buffer))
1878 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1880 if (!NILP (w->vchild))
1881 make_frame_visible_1 (w->vchild);
1882 if (!NILP (w->hchild))
1883 make_frame_visible_1 (w->hchild);
1887 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1888 0, 2, "",
1889 doc: /* Make the frame FRAME invisible.
1890 If omitted, FRAME defaults to the currently selected frame.
1891 On graphical displays, invisible frames are not updated and are
1892 usually not displayed at all, even in a window system's \"taskbar\".
1894 Normally you may not make FRAME invisible if all other frames are invisible,
1895 but if the second optional argument FORCE is non-nil, you may do so.
1897 This function has no effect on text-only terminal frames. Such frames
1898 are always considered visible, whether or not they are currently being
1899 displayed in the terminal. */)
1900 (frame, force)
1901 Lisp_Object frame, force;
1903 if (NILP (frame))
1904 frame = selected_frame;
1906 CHECK_LIVE_FRAME (frame);
1908 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1909 error ("Attempt to make invisible the sole visible or iconified frame");
1911 #if 0 /* This isn't logically necessary, and it can do GC. */
1912 /* Don't let the frame remain selected. */
1913 if (EQ (frame, selected_frame))
1914 do_switch_frame (next_frame (frame, Qt), 0, 0, Qnil)
1915 #endif
1917 /* Don't allow minibuf_window to remain on a deleted frame. */
1918 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1920 struct frame *sf = XFRAME (selected_frame);
1921 Fset_window_buffer (sf->minibuffer_window,
1922 XWINDOW (minibuf_window)->buffer, Qnil);
1923 minibuf_window = sf->minibuffer_window;
1926 /* I think this should be done with a hook. */
1927 #ifdef HAVE_WINDOW_SYSTEM
1928 if (FRAME_WINDOW_P (XFRAME (frame)))
1929 x_make_frame_invisible (XFRAME (frame));
1930 #endif
1932 /* Make menu bar update for the Buffers and Frames menus. */
1933 windows_or_buffers_changed++;
1935 return Qnil;
1938 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1939 0, 1, "",
1940 doc: /* Make the frame FRAME into an icon.
1941 If omitted, FRAME defaults to the currently selected frame. */)
1942 (frame)
1943 Lisp_Object frame;
1945 if (NILP (frame))
1946 frame = selected_frame;
1948 CHECK_LIVE_FRAME (frame);
1950 #if 0 /* This isn't logically necessary, and it can do GC. */
1951 /* Don't let the frame remain selected. */
1952 if (EQ (frame, selected_frame))
1953 Fhandle_switch_frame (next_frame (frame, Qt));
1954 #endif
1956 /* Don't allow minibuf_window to remain on a deleted frame. */
1957 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1959 struct frame *sf = XFRAME (selected_frame);
1960 Fset_window_buffer (sf->minibuffer_window,
1961 XWINDOW (minibuf_window)->buffer, Qnil);
1962 minibuf_window = sf->minibuffer_window;
1965 /* I think this should be done with a hook. */
1966 #ifdef HAVE_WINDOW_SYSTEM
1967 if (FRAME_WINDOW_P (XFRAME (frame)))
1968 x_iconify_frame (XFRAME (frame));
1969 #endif
1971 /* Make menu bar update for the Buffers and Frames menus. */
1972 windows_or_buffers_changed++;
1974 return Qnil;
1977 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1978 1, 1, 0,
1979 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1980 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1981 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1982 On graphical displays, invisible frames are not updated and are
1983 usually not displayed at all, even in a window system's \"taskbar\".
1985 If FRAME is a text-only terminal frame, this always returns t.
1986 Such frames are always considered visible, whether or not they are
1987 currently being displayed on the terminal. */)
1988 (frame)
1989 Lisp_Object frame;
1991 CHECK_LIVE_FRAME (frame);
1993 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1995 if (FRAME_VISIBLE_P (XFRAME (frame)))
1996 return Qt;
1997 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1998 return Qicon;
1999 return Qnil;
2002 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2003 0, 0, 0,
2004 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2007 Lisp_Object tail, frame;
2008 struct frame *f;
2009 Lisp_Object value;
2011 value = Qnil;
2012 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
2014 frame = XCAR (tail);
2015 if (!FRAMEP (frame))
2016 continue;
2017 f = XFRAME (frame);
2018 if (FRAME_VISIBLE_P (f))
2019 value = Fcons (frame, value);
2021 return value;
2025 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2026 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2027 If FRAME is invisible or iconified, make it visible.
2028 If you don't specify a frame, the selected frame is used.
2029 If Emacs is displaying on an ordinary terminal or some other device which
2030 doesn't support multiple overlapping frames, this function selects FRAME. */)
2031 (frame)
2032 Lisp_Object frame;
2034 struct frame *f;
2035 if (NILP (frame))
2036 frame = selected_frame;
2038 CHECK_LIVE_FRAME (frame);
2040 f = XFRAME (frame);
2042 if (FRAME_TERMCAP_P (f))
2043 /* On a text-only terminal select FRAME. */
2044 Fselect_frame (frame, Qnil);
2045 else
2046 /* Do like the documentation says. */
2047 Fmake_frame_visible (frame);
2049 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2050 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2052 return Qnil;
2055 /* Should we have a corresponding function called Flower_Power? */
2056 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2057 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2058 If you don't specify a frame, the selected frame is used.
2059 If Emacs is displaying on an ordinary terminal or some other device which
2060 doesn't support multiple overlapping frames, this function does nothing. */)
2061 (frame)
2062 Lisp_Object frame;
2064 struct frame *f;
2066 if (NILP (frame))
2067 frame = selected_frame;
2069 CHECK_LIVE_FRAME (frame);
2071 f = XFRAME (frame);
2073 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2074 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2076 return Qnil;
2080 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2081 1, 2, 0,
2082 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2083 In other words, switch-frame events caused by events in FRAME will
2084 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2085 FOCUS-FRAME after reading an event typed at FRAME.
2087 If FOCUS-FRAME is omitted or nil, any existing redirection is
2088 cancelled, and the frame again receives its own keystrokes.
2090 Focus redirection is useful for temporarily redirecting keystrokes to
2091 a surrogate minibuffer frame when a frame doesn't have its own
2092 minibuffer window.
2094 A frame's focus redirection can be changed by `select-frame'. If frame
2095 FOO is selected, and then a different frame BAR is selected, any
2096 frames redirecting their focus to FOO are shifted to redirect their
2097 focus to BAR. This allows focus redirection to work properly when the
2098 user switches from one frame to another using `select-window'.
2100 This means that a frame whose focus is redirected to itself is treated
2101 differently from a frame whose focus is redirected to nil; the former
2102 is affected by `select-frame', while the latter is not.
2104 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2105 (frame, focus_frame)
2106 Lisp_Object frame, focus_frame;
2108 struct frame *f;
2110 /* Note that we don't check for a live frame here. It's reasonable
2111 to redirect the focus of a frame you're about to delete, if you
2112 know what other frame should receive those keystrokes. */
2113 CHECK_FRAME (frame);
2115 if (! NILP (focus_frame))
2116 CHECK_LIVE_FRAME (focus_frame);
2118 f = XFRAME (frame);
2120 f->focus_frame = focus_frame;
2122 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2123 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2125 return Qnil;
2129 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
2130 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2131 This returns nil if FRAME's focus is not redirected.
2132 See `redirect-frame-focus'. */)
2133 (frame)
2134 Lisp_Object frame;
2136 CHECK_LIVE_FRAME (frame);
2138 return FRAME_FOCUS_FRAME (XFRAME (frame));
2143 /* Return the value of frame parameter PROP in frame FRAME. */
2145 Lisp_Object
2146 get_frame_param (frame, prop)
2147 register struct frame *frame;
2148 Lisp_Object prop;
2150 register Lisp_Object tem;
2152 tem = Fassq (prop, frame->param_alist);
2153 if (EQ (tem, Qnil))
2154 return tem;
2155 return Fcdr (tem);
2158 /* Return the buffer-predicate of the selected frame. */
2160 Lisp_Object
2161 frame_buffer_predicate (frame)
2162 Lisp_Object frame;
2164 return XFRAME (frame)->buffer_predicate;
2167 /* Return the buffer-list of the selected frame. */
2169 Lisp_Object
2170 frame_buffer_list (frame)
2171 Lisp_Object frame;
2173 return XFRAME (frame)->buffer_list;
2176 /* Set the buffer-list of the selected frame. */
2178 void
2179 set_frame_buffer_list (frame, list)
2180 Lisp_Object frame, list;
2182 XFRAME (frame)->buffer_list = list;
2185 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2187 void
2188 frames_discard_buffer (buffer)
2189 Lisp_Object buffer;
2191 Lisp_Object frame, tail;
2193 FOR_EACH_FRAME (tail, frame)
2195 XFRAME (frame)->buffer_list
2196 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2197 XFRAME (frame)->buried_buffer_list
2198 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
2202 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2203 If the alist already has an element for PROP, we change it. */
2205 void
2206 store_in_alist (alistptr, prop, val)
2207 Lisp_Object *alistptr, val;
2208 Lisp_Object prop;
2210 register Lisp_Object tem;
2212 tem = Fassq (prop, *alistptr);
2213 if (EQ (tem, Qnil))
2214 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2215 else
2216 Fsetcdr (tem, val);
2219 static int
2220 frame_name_fnn_p (str, len)
2221 char *str;
2222 EMACS_INT len;
2224 if (len > 1 && str[0] == 'F')
2226 char *end_ptr;
2228 strtol (str + 1, &end_ptr, 10);
2230 if (end_ptr == str + len)
2231 return 1;
2233 return 0;
2236 /* Set the name of the terminal frame. Also used by MSDOS frames.
2237 Modeled after x_set_name which is used for WINDOW frames. */
2239 static void
2240 set_term_frame_name (f, name)
2241 struct frame *f;
2242 Lisp_Object name;
2244 f->explicit_name = ! NILP (name);
2246 /* If NAME is nil, set the name to F<num>. */
2247 if (NILP (name))
2249 char namebuf[20];
2251 /* Check for no change needed in this very common case
2252 before we do any consing. */
2253 if (frame_name_fnn_p (SDATA (f->name),
2254 SBYTES (f->name)))
2255 return;
2257 tty_frame_count++;
2258 sprintf (namebuf, "F%d", tty_frame_count);
2259 name = build_string (namebuf);
2261 else
2263 CHECK_STRING (name);
2265 /* Don't change the name if it's already NAME. */
2266 if (! NILP (Fstring_equal (name, f->name)))
2267 return;
2269 /* Don't allow the user to set the frame name to F<num>, so it
2270 doesn't clash with the names we generate for terminal frames. */
2271 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2272 error ("Frame names of the form F<num> are usurped by Emacs");
2275 f->name = name;
2276 update_mode_lines = 1;
2279 void
2280 store_frame_param (f, prop, val)
2281 struct frame *f;
2282 Lisp_Object prop, val;
2284 register Lisp_Object old_alist_elt;
2286 /* The buffer-list parameters are stored in a special place and not
2287 in the alist. */
2288 if (EQ (prop, Qbuffer_list))
2290 f->buffer_list = val;
2291 return;
2293 if (EQ (prop, Qburied_buffer_list))
2295 f->buried_buffer_list = val;
2296 return;
2299 /* If PROP is a symbol which is supposed to have frame-local values,
2300 and it is set up based on this frame, switch to the global
2301 binding. That way, we can create or alter the frame-local binding
2302 without messing up the symbol's status. */
2303 if (SYMBOLP (prop))
2305 Lisp_Object valcontents;
2306 valcontents = SYMBOL_VALUE (prop);
2307 if ((BUFFER_LOCAL_VALUEP (valcontents))
2308 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2309 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame
2310 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2311 swap_in_global_binding (prop);
2314 /* The tty color needed to be set before the frame's parameter
2315 alist was updated with the new value. This is not true any more,
2316 but we still do this test early on. */
2317 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2318 && f == FRAME_TTY (f)->previous_frame)
2319 /* Force redisplay of this tty. */
2320 FRAME_TTY (f)->previous_frame = NULL;
2322 /* Update the frame parameter alist. */
2323 old_alist_elt = Fassq (prop, f->param_alist);
2324 if (EQ (old_alist_elt, Qnil))
2325 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2326 else
2327 Fsetcdr (old_alist_elt, val);
2329 /* Update some other special parameters in their special places
2330 in addition to the alist. */
2332 if (EQ (prop, Qbuffer_predicate))
2333 f->buffer_predicate = val;
2335 if (! FRAME_WINDOW_P (f))
2337 if (EQ (prop, Qmenu_bar_lines))
2338 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2339 else if (EQ (prop, Qname))
2340 set_term_frame_name (f, val);
2343 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2345 if (! MINI_WINDOW_P (XWINDOW (val)))
2346 error ("Surrogate minibuffer windows must be minibuffer windows");
2348 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2349 && !EQ (val, f->minibuffer_window))
2350 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2352 /* Install the chosen minibuffer window, with proper buffer. */
2353 f->minibuffer_window = val;
2357 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2358 doc: /* Return the parameters-alist of frame FRAME.
2359 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2360 The meaningful PARMs depend on the kind of frame.
2361 If FRAME is omitted, return information on the currently selected frame. */)
2362 (frame)
2363 Lisp_Object frame;
2365 Lisp_Object alist;
2366 FRAME_PTR f;
2367 int height, width;
2368 struct gcpro gcpro1;
2370 if (NILP (frame))
2371 frame = selected_frame;
2373 CHECK_FRAME (frame);
2374 f = XFRAME (frame);
2376 if (!FRAME_LIVE_P (f))
2377 return Qnil;
2379 alist = Fcopy_alist (f->param_alist);
2380 GCPRO1 (alist);
2382 if (!FRAME_WINDOW_P (f))
2384 int fg = FRAME_FOREGROUND_PIXEL (f);
2385 int bg = FRAME_BACKGROUND_PIXEL (f);
2386 Lisp_Object elt;
2388 /* If the frame's parameter alist says the colors are
2389 unspecified and reversed, take the frame's background pixel
2390 for foreground and vice versa. */
2391 elt = Fassq (Qforeground_color, alist);
2392 if (CONSP (elt) && STRINGP (XCDR (elt)))
2394 if (strncmp (SDATA (XCDR (elt)),
2395 unspecified_bg,
2396 SCHARS (XCDR (elt))) == 0)
2397 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2398 else if (strncmp (SDATA (XCDR (elt)),
2399 unspecified_fg,
2400 SCHARS (XCDR (elt))) == 0)
2401 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2403 else
2404 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2405 elt = Fassq (Qbackground_color, alist);
2406 if (CONSP (elt) && STRINGP (XCDR (elt)))
2408 if (strncmp (SDATA (XCDR (elt)),
2409 unspecified_fg,
2410 SCHARS (XCDR (elt))) == 0)
2411 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2412 else if (strncmp (SDATA (XCDR (elt)),
2413 unspecified_bg,
2414 SCHARS (XCDR (elt))) == 0)
2415 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2417 else
2418 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2419 store_in_alist (&alist, intern ("font"),
2420 build_string (FRAME_MSDOS_P (f)
2421 ? "ms-dos"
2422 : FRAME_W32_P (f) ? "w32term"
2423 :"tty"));
2425 store_in_alist (&alist, Qname, f->name);
2426 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2427 store_in_alist (&alist, Qheight, make_number (height));
2428 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2429 store_in_alist (&alist, Qwidth, make_number (width));
2430 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2431 store_in_alist (&alist, Qminibuffer,
2432 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2433 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2434 : FRAME_MINIBUF_WINDOW (f)));
2435 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2436 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2437 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2439 /* I think this should be done with a hook. */
2440 #ifdef HAVE_WINDOW_SYSTEM
2441 if (FRAME_WINDOW_P (f))
2442 x_report_frame_params (f, &alist);
2443 else
2444 #endif
2446 /* This ought to be correct in f->param_alist for an X frame. */
2447 Lisp_Object lines;
2448 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2449 store_in_alist (&alist, Qmenu_bar_lines, lines);
2452 UNGCPRO;
2453 return alist;
2457 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2458 doc: /* Return FRAME's value for parameter PARAMETER.
2459 If FRAME is nil, describe the currently selected frame. */)
2460 (frame, parameter)
2461 Lisp_Object frame, parameter;
2463 struct frame *f;
2464 Lisp_Object value;
2466 if (NILP (frame))
2467 frame = selected_frame;
2468 else
2469 CHECK_FRAME (frame);
2470 CHECK_SYMBOL (parameter);
2472 f = XFRAME (frame);
2473 value = Qnil;
2475 if (FRAME_LIVE_P (f))
2477 /* Avoid consing in frequent cases. */
2478 if (EQ (parameter, Qname))
2479 value = f->name;
2480 #ifdef HAVE_X_WINDOWS
2481 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2482 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2483 #endif /* HAVE_X_WINDOWS */
2484 else if (EQ (parameter, Qbackground_color)
2485 || EQ (parameter, Qforeground_color))
2487 value = Fassq (parameter, f->param_alist);
2488 if (CONSP (value))
2490 value = XCDR (value);
2491 /* Fframe_parameters puts the actual fg/bg color names,
2492 even if f->param_alist says otherwise. This is
2493 important when param_alist's notion of colors is
2494 "unspecified". We need to do the same here. */
2495 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2497 const char *color_name;
2498 EMACS_INT csz;
2500 if (EQ (parameter, Qbackground_color))
2502 color_name = SDATA (value);
2503 csz = SCHARS (value);
2504 if (strncmp (color_name, unspecified_bg, csz) == 0)
2505 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2506 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2507 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2509 else if (EQ (parameter, Qforeground_color))
2511 color_name = SDATA (value);
2512 csz = SCHARS (value);
2513 if (strncmp (color_name, unspecified_fg, csz) == 0)
2514 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2515 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2516 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2520 else
2521 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2523 else if (EQ (parameter, Qdisplay_type)
2524 || EQ (parameter, Qbackground_mode))
2525 value = Fcdr (Fassq (parameter, f->param_alist));
2526 else
2527 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2530 return value;
2534 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2535 Smodify_frame_parameters, 2, 2, 0,
2536 doc: /* Modify the parameters of frame FRAME according to ALIST.
2537 If FRAME is nil, it defaults to the selected frame.
2538 ALIST is an alist of parameters to change and their new values.
2539 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2540 The meaningful PARMs depend on the kind of frame.
2541 Undefined PARMs are ignored, but stored in the frame's parameter list
2542 so that `frame-parameters' will return them.
2544 The value of frame parameter FOO can also be accessed
2545 as a frame-local binding for the variable FOO, if you have
2546 enabled such bindings for that variable with `make-variable-frame-local'.
2547 Note that this functionality is obsolete as of Emacs 22.2, and its
2548 use is not recommended. Explicitly check for a frame-parameter instead. */)
2549 (frame, alist)
2550 Lisp_Object frame, alist;
2552 FRAME_PTR f;
2553 register Lisp_Object tail, prop, val;
2555 if (EQ (frame, Qnil))
2556 frame = selected_frame;
2557 CHECK_LIVE_FRAME (frame);
2558 f = XFRAME (frame);
2560 /* I think this should be done with a hook. */
2561 #ifdef HAVE_WINDOW_SYSTEM
2562 if (FRAME_WINDOW_P (f))
2563 x_set_frame_parameters (f, alist);
2564 else
2565 #endif
2566 #ifdef MSDOS
2567 if (FRAME_MSDOS_P (f))
2568 IT_set_frame_parameters (f, alist);
2569 else
2570 #endif
2573 int length = XINT (Flength (alist));
2574 int i;
2575 Lisp_Object *parms
2576 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2577 Lisp_Object *values
2578 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2580 /* Extract parm names and values into those vectors. */
2582 i = 0;
2583 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2585 Lisp_Object elt;
2587 elt = XCAR (tail);
2588 parms[i] = Fcar (elt);
2589 values[i] = Fcdr (elt);
2590 i++;
2593 /* Now process them in reverse of specified order. */
2594 for (i--; i >= 0; i--)
2596 prop = parms[i];
2597 val = values[i];
2598 store_frame_param (f, prop, val);
2600 /* Changing the background color might change the background
2601 mode, so that we have to load new defface specs.
2602 Call frame-set-background-mode to do that. */
2603 if (EQ (prop, Qbackground_color))
2604 call1 (Qframe_set_background_mode, frame);
2607 return Qnil;
2610 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2611 0, 1, 0,
2612 doc: /* Height in pixels of a line in the font in frame FRAME.
2613 If FRAME is omitted, the selected frame is used.
2614 For a terminal frame, the value is always 1. */)
2615 (frame)
2616 Lisp_Object frame;
2618 struct frame *f;
2620 if (NILP (frame))
2621 frame = selected_frame;
2622 CHECK_FRAME (frame);
2623 f = XFRAME (frame);
2625 #ifdef HAVE_WINDOW_SYSTEM
2626 if (FRAME_WINDOW_P (f))
2627 return make_number (x_char_height (f));
2628 else
2629 #endif
2630 return make_number (1);
2634 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2635 0, 1, 0,
2636 doc: /* Width in pixels of characters in the font in frame FRAME.
2637 If FRAME is omitted, the selected frame is used.
2638 On a graphical screen, the width is the standard width of the default font.
2639 For a terminal screen, the value is always 1. */)
2640 (frame)
2641 Lisp_Object frame;
2643 struct frame *f;
2645 if (NILP (frame))
2646 frame = selected_frame;
2647 CHECK_FRAME (frame);
2648 f = XFRAME (frame);
2650 #ifdef HAVE_WINDOW_SYSTEM
2651 if (FRAME_WINDOW_P (f))
2652 return make_number (x_char_width (f));
2653 else
2654 #endif
2655 return make_number (1);
2658 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2659 Sframe_pixel_height, 0, 1, 0,
2660 doc: /* Return a FRAME's height in pixels.
2661 If FRAME is omitted, the selected frame is used. The exact value
2662 of the result depends on the window-system and toolkit in use:
2664 In the Gtk+ version of Emacs, it includes only any window (including
2665 the minibuffer or eacho area), mode line, and header line. It does not
2666 include the tool bar or menu bar.
2668 With the Motif or Lucid toolkits, it also includes the tool bar (but
2669 not the menu bar).
2671 In a graphical version with no toolkit, it includes both the tool bar
2672 and menu bar.
2674 For a text-only terminal, it includes the menu bar. In this case, the
2675 result is really in characters rather than pixels (i.e., is identical
2676 to `frame-height'). */)
2677 (frame)
2678 Lisp_Object frame;
2680 struct frame *f;
2682 if (NILP (frame))
2683 frame = selected_frame;
2684 CHECK_FRAME (frame);
2685 f = XFRAME (frame);
2687 #ifdef HAVE_WINDOW_SYSTEM
2688 if (FRAME_WINDOW_P (f))
2689 return make_number (x_pixel_height (f));
2690 else
2691 #endif
2692 return make_number (FRAME_LINES (f));
2695 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2696 Sframe_pixel_width, 0, 1, 0,
2697 doc: /* Return FRAME's width in pixels.
2698 For a terminal frame, the result really gives the width in characters.
2699 If FRAME is omitted, the selected frame is used. */)
2700 (frame)
2701 Lisp_Object frame;
2703 struct frame *f;
2705 if (NILP (frame))
2706 frame = selected_frame;
2707 CHECK_FRAME (frame);
2708 f = XFRAME (frame);
2710 #ifdef HAVE_WINDOW_SYSTEM
2711 if (FRAME_WINDOW_P (f))
2712 return make_number (x_pixel_width (f));
2713 else
2714 #endif
2715 return make_number (FRAME_COLS (f));
2718 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2719 doc: /* Specify that the frame FRAME has LINES lines.
2720 Optional third arg non-nil means that redisplay should use LINES lines
2721 but that the idea of the actual height of the frame should not be changed. */)
2722 (frame, lines, pretend)
2723 Lisp_Object frame, lines, pretend;
2725 register struct frame *f;
2727 CHECK_NUMBER (lines);
2728 if (NILP (frame))
2729 frame = selected_frame;
2730 CHECK_LIVE_FRAME (frame);
2731 f = XFRAME (frame);
2733 /* I think this should be done with a hook. */
2734 #ifdef HAVE_WINDOW_SYSTEM
2735 if (FRAME_WINDOW_P (f))
2737 if (XINT (lines) != FRAME_LINES (f))
2738 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2739 do_pending_window_change (0);
2741 else
2742 #endif
2743 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2744 return Qnil;
2747 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2748 doc: /* Specify that the frame FRAME has COLS columns.
2749 Optional third arg non-nil means that redisplay should use COLS columns
2750 but that the idea of the actual width of the frame should not be changed. */)
2751 (frame, cols, pretend)
2752 Lisp_Object frame, cols, pretend;
2754 register struct frame *f;
2755 CHECK_NUMBER (cols);
2756 if (NILP (frame))
2757 frame = selected_frame;
2758 CHECK_LIVE_FRAME (frame);
2759 f = XFRAME (frame);
2761 /* I think this should be done with a hook. */
2762 #ifdef HAVE_WINDOW_SYSTEM
2763 if (FRAME_WINDOW_P (f))
2765 if (XINT (cols) != FRAME_COLS (f))
2766 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2767 do_pending_window_change (0);
2769 else
2770 #endif
2771 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2772 return Qnil;
2775 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2776 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2777 (frame, cols, rows)
2778 Lisp_Object frame, cols, rows;
2780 register struct frame *f;
2782 CHECK_LIVE_FRAME (frame);
2783 CHECK_NUMBER (cols);
2784 CHECK_NUMBER (rows);
2785 f = XFRAME (frame);
2787 /* I think this should be done with a hook. */
2788 #ifdef HAVE_WINDOW_SYSTEM
2789 if (FRAME_WINDOW_P (f))
2791 if (XINT (rows) != FRAME_LINES (f)
2792 || XINT (cols) != FRAME_COLS (f)
2793 || f->new_text_lines || f->new_text_cols)
2794 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2795 do_pending_window_change (0);
2797 else
2798 #endif
2799 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2801 return Qnil;
2804 DEFUN ("set-frame-position", Fset_frame_position,
2805 Sset_frame_position, 3, 3, 0,
2806 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2807 This is actually the position of the upper left corner of the frame.
2808 Negative values for XOFFSET or YOFFSET are interpreted relative to
2809 the rightmost or bottommost possible position (that stays within the screen). */)
2810 (frame, xoffset, yoffset)
2811 Lisp_Object frame, xoffset, yoffset;
2813 register struct frame *f;
2815 CHECK_LIVE_FRAME (frame);
2816 CHECK_NUMBER (xoffset);
2817 CHECK_NUMBER (yoffset);
2818 f = XFRAME (frame);
2820 /* I think this should be done with a hook. */
2821 #ifdef HAVE_WINDOW_SYSTEM
2822 if (FRAME_WINDOW_P (f))
2823 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2824 #endif
2826 return Qt;
2830 /***********************************************************************
2831 Frame Parameters
2832 ***********************************************************************/
2834 /* Connect the frame-parameter names for X frames
2835 to the ways of passing the parameter values to the window system.
2837 The name of a parameter, as a Lisp symbol,
2838 has an `x-frame-parameter' property which is an integer in Lisp
2839 that is an index in this table. */
2841 struct frame_parm_table {
2842 char *name;
2843 Lisp_Object *variable;
2846 static struct frame_parm_table frame_parms[] =
2848 {"auto-raise", &Qauto_raise},
2849 {"auto-lower", &Qauto_lower},
2850 {"background-color", 0},
2851 {"border-color", &Qborder_color},
2852 {"border-width", &Qborder_width},
2853 {"cursor-color", &Qcursor_color},
2854 {"cursor-type", &Qcursor_type},
2855 {"font", 0},
2856 {"foreground-color", 0},
2857 {"icon-name", &Qicon_name},
2858 {"icon-type", &Qicon_type},
2859 {"internal-border-width", &Qinternal_border_width},
2860 {"menu-bar-lines", &Qmenu_bar_lines},
2861 {"mouse-color", &Qmouse_color},
2862 {"name", &Qname},
2863 {"scroll-bar-width", &Qscroll_bar_width},
2864 {"title", &Qtitle},
2865 {"unsplittable", &Qunsplittable},
2866 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2867 {"visibility", &Qvisibility},
2868 {"tool-bar-lines", &Qtool_bar_lines},
2869 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2870 {"scroll-bar-background", &Qscroll_bar_background},
2871 {"screen-gamma", &Qscreen_gamma},
2872 {"line-spacing", &Qline_spacing},
2873 {"left-fringe", &Qleft_fringe},
2874 {"right-fringe", &Qright_fringe},
2875 {"wait-for-wm", &Qwait_for_wm},
2876 {"fullscreen", &Qfullscreen},
2877 {"font-backend", &Qfont_backend},
2878 {"alpha", &Qalpha},
2879 {"sticky", &Qsticky},
2882 #ifdef HAVE_WINDOW_SYSTEM
2884 extern Lisp_Object Qbox;
2885 extern Lisp_Object Qtop;
2887 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2888 wanted positions of the WM window (not Emacs window).
2889 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2890 window (FRAME_X_WINDOW).
2893 void
2894 x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2895 struct frame *f;
2896 int *width;
2897 int *height;
2898 int *top_pos;
2899 int *left_pos;
2901 int newwidth = FRAME_COLS (f);
2902 int newheight = FRAME_LINES (f);
2903 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2905 *top_pos = f->top_pos;
2906 *left_pos = f->left_pos;
2908 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2910 int ph;
2912 ph = x_display_pixel_height (dpyinfo);
2913 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2914 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2915 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2916 *top_pos = 0;
2919 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2921 int pw;
2923 pw = x_display_pixel_width (dpyinfo);
2924 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2925 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2926 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2927 *left_pos = 0;
2930 *width = newwidth;
2931 *height = newheight;
2935 /* Change the parameters of frame F as specified by ALIST.
2936 If a parameter is not specially recognized, do nothing special;
2937 otherwise call the `x_set_...' function for that parameter.
2938 Except for certain geometry properties, always call store_frame_param
2939 to store the new value in the parameter alist. */
2941 void
2942 x_set_frame_parameters (f, alist)
2943 FRAME_PTR f;
2944 Lisp_Object alist;
2946 Lisp_Object tail;
2948 /* If both of these parameters are present, it's more efficient to
2949 set them both at once. So we wait until we've looked at the
2950 entire list before we set them. */
2951 int width, height;
2953 /* Same here. */
2954 Lisp_Object left, top;
2956 /* Same with these. */
2957 Lisp_Object icon_left, icon_top;
2959 /* Record in these vectors all the parms specified. */
2960 Lisp_Object *parms;
2961 Lisp_Object *values;
2962 int i, p;
2963 int left_no_change = 0, top_no_change = 0;
2964 int icon_left_no_change = 0, icon_top_no_change = 0;
2965 int size_changed = 0;
2966 struct gcpro gcpro1, gcpro2;
2968 i = 0;
2969 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2970 i++;
2972 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2973 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2975 /* Extract parm names and values into those vectors. */
2977 i = 0;
2978 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2980 Lisp_Object elt;
2982 elt = XCAR (tail);
2983 parms[i] = Fcar (elt);
2984 values[i] = Fcdr (elt);
2985 i++;
2987 /* TAIL and ALIST are not used again below here. */
2988 alist = tail = Qnil;
2990 GCPRO2 (*parms, *values);
2991 gcpro1.nvars = i;
2992 gcpro2.nvars = i;
2994 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2995 because their values appear in VALUES and strings are not valid. */
2996 top = left = Qunbound;
2997 icon_left = icon_top = Qunbound;
2999 /* Provide default values for HEIGHT and WIDTH. */
3000 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
3001 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
3003 /* Process foreground_color and background_color before anything else.
3004 They are independent of other properties, but other properties (e.g.,
3005 cursor_color) are dependent upon them. */
3006 /* Process default font as well, since fringe widths depends on it. */
3007 for (p = 0; p < i; p++)
3009 Lisp_Object prop, val;
3011 prop = parms[p];
3012 val = values[p];
3013 if (EQ (prop, Qforeground_color)
3014 || EQ (prop, Qbackground_color)
3015 || EQ (prop, Qfont))
3017 register Lisp_Object param_index, old_value;
3019 old_value = get_frame_param (f, prop);
3020 if (NILP (Fequal (val, old_value)))
3022 store_frame_param (f, prop, val);
3024 param_index = Fget (prop, Qx_frame_parameter);
3025 if (NATNUMP (param_index)
3026 && (XFASTINT (param_index)
3027 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3028 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3029 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3034 /* Now process them in reverse of specified order. */
3035 for (i--; i >= 0; i--)
3037 Lisp_Object prop, val;
3039 prop = parms[i];
3040 val = values[i];
3042 if (EQ (prop, Qwidth) && NATNUMP (val))
3044 size_changed = 1;
3045 width = XFASTINT (val);
3047 else if (EQ (prop, Qheight) && NATNUMP (val))
3049 size_changed = 1;
3050 height = XFASTINT (val);
3052 else if (EQ (prop, Qtop))
3053 top = val;
3054 else if (EQ (prop, Qleft))
3055 left = val;
3056 else if (EQ (prop, Qicon_top))
3057 icon_top = val;
3058 else if (EQ (prop, Qicon_left))
3059 icon_left = val;
3060 else if (EQ (prop, Qforeground_color)
3061 || EQ (prop, Qbackground_color)
3062 || EQ (prop, Qfont))
3063 /* Processed above. */
3064 continue;
3065 else
3067 register Lisp_Object param_index, old_value;
3069 old_value = get_frame_param (f, prop);
3071 store_frame_param (f, prop, val);
3073 param_index = Fget (prop, Qx_frame_parameter);
3074 if (NATNUMP (param_index)
3075 && (XFASTINT (param_index)
3076 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3077 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3078 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3082 /* Don't die if just one of these was set. */
3083 if (EQ (left, Qunbound))
3085 left_no_change = 1;
3086 if (f->left_pos < 0)
3087 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
3088 else
3089 XSETINT (left, f->left_pos);
3091 if (EQ (top, Qunbound))
3093 top_no_change = 1;
3094 if (f->top_pos < 0)
3095 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
3096 else
3097 XSETINT (top, f->top_pos);
3100 /* If one of the icon positions was not set, preserve or default it. */
3101 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
3103 icon_left_no_change = 1;
3104 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3105 if (NILP (icon_left))
3106 XSETINT (icon_left, 0);
3108 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
3110 icon_top_no_change = 1;
3111 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3112 if (NILP (icon_top))
3113 XSETINT (icon_top, 0);
3116 /* Don't set these parameters unless they've been explicitly
3117 specified. The window might be mapped or resized while we're in
3118 this function, and we don't want to override that unless the lisp
3119 code has asked for it.
3121 Don't set these parameters unless they actually differ from the
3122 window's current parameters; the window may not actually exist
3123 yet. */
3125 Lisp_Object frame;
3127 check_frame_size (f, &height, &width);
3129 XSETFRAME (frame, f);
3131 if (size_changed
3132 && (width != FRAME_COLS (f)
3133 || height != FRAME_LINES (f)
3134 || f->new_text_lines || f->new_text_cols))
3135 Fset_frame_size (frame, make_number (width), make_number (height));
3137 if ((!NILP (left) || !NILP (top))
3138 && ! (left_no_change && top_no_change)
3139 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3140 && NUMBERP (top) && XINT (top) == f->top_pos))
3142 int leftpos = 0;
3143 int toppos = 0;
3145 /* Record the signs. */
3146 f->size_hint_flags &= ~ (XNegative | YNegative);
3147 if (EQ (left, Qminus))
3148 f->size_hint_flags |= XNegative;
3149 else if (INTEGERP (left))
3151 leftpos = XINT (left);
3152 if (leftpos < 0)
3153 f->size_hint_flags |= XNegative;
3155 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3156 && CONSP (XCDR (left))
3157 && INTEGERP (XCAR (XCDR (left))))
3159 leftpos = - XINT (XCAR (XCDR (left)));
3160 f->size_hint_flags |= XNegative;
3162 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3163 && CONSP (XCDR (left))
3164 && INTEGERP (XCAR (XCDR (left))))
3166 leftpos = XINT (XCAR (XCDR (left)));
3169 if (EQ (top, Qminus))
3170 f->size_hint_flags |= YNegative;
3171 else if (INTEGERP (top))
3173 toppos = XINT (top);
3174 if (toppos < 0)
3175 f->size_hint_flags |= YNegative;
3177 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3178 && CONSP (XCDR (top))
3179 && INTEGERP (XCAR (XCDR (top))))
3181 toppos = - XINT (XCAR (XCDR (top)));
3182 f->size_hint_flags |= YNegative;
3184 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3185 && CONSP (XCDR (top))
3186 && INTEGERP (XCAR (XCDR (top))))
3188 toppos = XINT (XCAR (XCDR (top)));
3192 /* Store the numeric value of the position. */
3193 f->top_pos = toppos;
3194 f->left_pos = leftpos;
3196 f->win_gravity = NorthWestGravity;
3198 /* Actually set that position, and convert to absolute. */
3199 x_set_offset (f, leftpos, toppos, -1);
3202 if ((!NILP (icon_left) || !NILP (icon_top))
3203 && ! (icon_left_no_change && icon_top_no_change))
3204 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3207 UNGCPRO;
3211 /* Insert a description of internally-recorded parameters of frame X
3212 into the parameter alist *ALISTPTR that is to be given to the user.
3213 Only parameters that are specific to the X window system
3214 and whose values are not correctly recorded in the frame's
3215 param_alist need to be considered here. */
3217 void
3218 x_report_frame_params (f, alistptr)
3219 struct frame *f;
3220 Lisp_Object *alistptr;
3222 char buf[16];
3223 Lisp_Object tem;
3225 /* Represent negative positions (off the top or left screen edge)
3226 in a way that Fmodify_frame_parameters will understand correctly. */
3227 XSETINT (tem, f->left_pos);
3228 if (f->left_pos >= 0)
3229 store_in_alist (alistptr, Qleft, tem);
3230 else
3231 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3233 XSETINT (tem, f->top_pos);
3234 if (f->top_pos >= 0)
3235 store_in_alist (alistptr, Qtop, tem);
3236 else
3237 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3239 store_in_alist (alistptr, Qborder_width,
3240 make_number (f->border_width));
3241 store_in_alist (alistptr, Qinternal_border_width,
3242 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3243 store_in_alist (alistptr, Qleft_fringe,
3244 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3245 store_in_alist (alistptr, Qright_fringe,
3246 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3247 store_in_alist (alistptr, Qscroll_bar_width,
3248 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3249 ? make_number (0)
3250 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3251 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3252 /* nil means "use default width"
3253 for non-toolkit scroll bar.
3254 ruler-mode.el depends on this. */
3255 : Qnil));
3256 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3257 store_in_alist (alistptr, Qwindow_id,
3258 build_string (buf));
3259 #ifdef HAVE_X_WINDOWS
3260 #ifdef USE_X_TOOLKIT
3261 /* Tooltip frame may not have this widget. */
3262 if (FRAME_X_OUTPUT (f)->widget)
3263 #endif
3264 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3265 store_in_alist (alistptr, Qouter_window_id,
3266 build_string (buf));
3267 #endif
3268 store_in_alist (alistptr, Qicon_name, f->icon_name);
3269 FRAME_SAMPLE_VISIBILITY (f);
3270 store_in_alist (alistptr, Qvisibility,
3271 (FRAME_VISIBLE_P (f) ? Qt
3272 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3273 store_in_alist (alistptr, Qdisplay,
3274 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3276 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3277 tem = Qnil;
3278 else
3279 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3280 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3281 store_in_alist (alistptr, Qparent_id, tem);
3285 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3286 the previous value of that parameter, NEW_VALUE is the new value. */
3288 void
3289 x_set_fullscreen (f, new_value, old_value)
3290 struct frame *f;
3291 Lisp_Object new_value, old_value;
3293 if (NILP (new_value))
3294 f->want_fullscreen = FULLSCREEN_NONE;
3295 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3296 f->want_fullscreen = FULLSCREEN_BOTH;
3297 else if (EQ (new_value, Qfullwidth))
3298 f->want_fullscreen = FULLSCREEN_WIDTH;
3299 else if (EQ (new_value, Qfullheight))
3300 f->want_fullscreen = FULLSCREEN_HEIGHT;
3301 else if (EQ (new_value, Qmaximized))
3302 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3304 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3305 FRAME_TERMINAL (f)->fullscreen_hook (f);
3309 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3310 the previous value of that parameter, NEW_VALUE is the new value. */
3312 void
3313 x_set_line_spacing (f, new_value, old_value)
3314 struct frame *f;
3315 Lisp_Object new_value, old_value;
3317 if (NILP (new_value))
3318 f->extra_line_spacing = 0;
3319 else if (NATNUMP (new_value))
3320 f->extra_line_spacing = XFASTINT (new_value);
3321 else
3322 signal_error ("Invalid line-spacing", new_value);
3323 if (FRAME_VISIBLE_P (f))
3324 redraw_frame (f);
3328 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3329 the previous value of that parameter, NEW_VALUE is the new value. */
3331 void
3332 x_set_screen_gamma (f, new_value, old_value)
3333 struct frame *f;
3334 Lisp_Object new_value, old_value;
3336 Lisp_Object bgcolor;
3338 if (NILP (new_value))
3339 f->gamma = 0;
3340 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3341 /* The value 0.4545 is the normal viewing gamma. */
3342 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3343 else
3344 signal_error ("Invalid screen-gamma", new_value);
3346 /* Apply the new gamma value to the frame background. */
3347 bgcolor = Fassq (Qbackground_color, f->param_alist);
3348 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3350 Lisp_Object index = Fget (Qbackground_color, Qx_frame_parameter);
3351 if (NATNUMP (index)
3352 && (XFASTINT (index)
3353 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3354 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3355 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3356 (f, bgcolor, Qnil);
3359 Fclear_face_cache (Qnil);
3363 void
3364 x_set_font (f, arg, oldval)
3365 struct frame *f;
3366 Lisp_Object arg, oldval;
3368 Lisp_Object frame, font_object, font_param = Qnil;
3369 int fontset = -1;
3371 /* Set the frame parameter back to the old value because we may
3372 fail to use ARG as the new parameter value. */
3373 store_frame_param (f, Qfont, oldval);
3375 /* ARG is a fontset name, a font name, a cons of fontset name and a
3376 font object, or a font object. In the last case, this function
3377 never fail. */
3378 if (STRINGP (arg))
3380 font_param = arg;
3381 fontset = fs_query_fontset (arg, 0);
3382 if (fontset < 0)
3384 font_object = font_open_by_name (f, SDATA (arg));
3385 if (NILP (font_object))
3386 error ("Font `%s' is not defined", SDATA (arg));
3387 arg = AREF (font_object, FONT_NAME_INDEX);
3389 else if (fontset > 0)
3391 Lisp_Object ascii_font = fontset_ascii (fontset);
3393 font_object = font_open_by_name (f, SDATA (ascii_font));
3394 if (NILP (font_object))
3395 error ("Font `%s' is not defined", SDATA (arg));
3396 arg = AREF (font_object, FONT_NAME_INDEX);
3398 else
3399 error ("The default fontset can't be used for a frame font");
3401 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3403 /* This is the case that the ASCII font of F's fontset XCAR
3404 (arg) is changed to the font XCDR (arg) by
3405 `set-fontset-font'. */
3406 fontset = fs_query_fontset (XCAR (arg), 0);
3407 if (fontset < 0)
3408 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3409 font_object = XCDR (arg);
3410 arg = AREF (font_object, FONT_NAME_INDEX);
3411 font_param = Ffont_get (font_object, QCname);
3413 else if (FONT_OBJECT_P (arg))
3415 font_object = arg;
3416 font_param = Ffont_get (font_object, QCname);
3417 /* This is to store the XLFD font name in the frame parameter for
3418 backward compatibility. We should store the font-object
3419 itself in the future. */
3420 arg = AREF (font_object, FONT_NAME_INDEX);
3421 fontset = FRAME_FONTSET (f);
3422 /* Check if we can use the current fontset. If not, set FONTSET
3423 to -1 to generate a new fontset from FONT-OBJECT. */
3424 if (fontset >= 0)
3426 Lisp_Object ascii_font = fontset_ascii (fontset);
3427 Lisp_Object spec = font_spec_from_name (ascii_font);
3429 if (! font_match_p (spec, font_object))
3430 fontset = -1;
3433 else
3434 signal_error ("Invalid font", arg);
3436 if (! NILP (Fequal (font_object, oldval)))
3437 return;
3439 x_new_font (f, font_object, fontset);
3440 store_frame_param (f, Qfont, arg);
3441 #ifdef HAVE_X_WINDOWS
3442 store_frame_param (f, Qfont_param, font_param);
3443 #endif
3444 /* Recalculate toolbar height. */
3445 f->n_tool_bar_rows = 0;
3446 /* Ensure we redraw it. */
3447 clear_current_matrices (f);
3449 recompute_basic_faces (f);
3451 do_pending_window_change (0);
3453 /* We used to call face-set-after-frame-default here, but it leads to
3454 recursive calls (since that function can set the `default' face's
3455 font which in turns changes the frame's `font' parameter).
3456 Also I don't know what this call is meant to do, but it seems the
3457 wrong way to do it anyway (it does a lot more work than what seems
3458 reasonable in response to a change to `font'). */
3462 void
3463 x_set_font_backend (f, new_value, old_value)
3464 struct frame *f;
3465 Lisp_Object new_value, old_value;
3467 if (! NILP (new_value)
3468 && !CONSP (new_value))
3470 char *p0, *p1;
3472 CHECK_STRING (new_value);
3473 p0 = p1 = SDATA (new_value);
3474 new_value = Qnil;
3475 while (*p0)
3477 while (*p1 && ! isspace (*p1) && *p1 != ',') p1++;
3478 if (p0 < p1)
3479 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3480 new_value);
3481 if (*p1)
3483 int c;
3485 while ((c = *++p1) && isspace (c));
3487 p0 = p1;
3489 new_value = Fnreverse (new_value);
3492 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3493 return;
3495 if (FRAME_FONT (f))
3496 free_all_realized_faces (Qnil);
3498 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3499 if (NILP (new_value))
3501 if (NILP (old_value))
3502 error ("No font backend available");
3503 font_update_drivers (f, old_value);
3504 error ("None of specified font backends are available");
3506 store_frame_param (f, Qfont_backend, new_value);
3508 if (FRAME_FONT (f))
3510 Lisp_Object frame;
3512 XSETFRAME (frame, f);
3513 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3514 ++face_change_count;
3515 ++windows_or_buffers_changed;
3520 void
3521 x_set_fringe_width (f, new_value, old_value)
3522 struct frame *f;
3523 Lisp_Object new_value, old_value;
3525 compute_fringe_widths (f, 1);
3528 void
3529 x_set_border_width (f, arg, oldval)
3530 struct frame *f;
3531 Lisp_Object arg, oldval;
3533 CHECK_NUMBER (arg);
3535 if (XINT (arg) == f->border_width)
3536 return;
3538 if (FRAME_X_WINDOW (f) != 0)
3539 error ("Cannot change the border width of a frame");
3541 f->border_width = XINT (arg);
3544 void
3545 x_set_internal_border_width (f, arg, oldval)
3546 struct frame *f;
3547 Lisp_Object arg, oldval;
3549 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3551 CHECK_NUMBER (arg);
3552 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3553 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3554 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3556 #ifdef USE_X_TOOLKIT
3557 if (FRAME_X_OUTPUT (f)->edit_widget)
3558 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3559 #endif
3561 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3562 return;
3564 if (FRAME_X_WINDOW (f) != 0)
3566 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3567 SET_FRAME_GARBAGED (f);
3568 do_pending_window_change (0);
3570 else
3571 SET_FRAME_GARBAGED (f);
3574 void
3575 x_set_visibility (f, value, oldval)
3576 struct frame *f;
3577 Lisp_Object value, oldval;
3579 Lisp_Object frame;
3580 XSETFRAME (frame, f);
3582 if (NILP (value))
3583 Fmake_frame_invisible (frame, Qt);
3584 else if (EQ (value, Qicon))
3585 Ficonify_frame (frame);
3586 else
3587 Fmake_frame_visible (frame);
3590 void
3591 x_set_autoraise (f, arg, oldval)
3592 struct frame *f;
3593 Lisp_Object arg, oldval;
3595 f->auto_raise = !EQ (Qnil, arg);
3598 void
3599 x_set_autolower (f, arg, oldval)
3600 struct frame *f;
3601 Lisp_Object arg, oldval;
3603 f->auto_lower = !EQ (Qnil, arg);
3606 void
3607 x_set_unsplittable (f, arg, oldval)
3608 struct frame *f;
3609 Lisp_Object arg, oldval;
3611 f->no_split = !NILP (arg);
3614 void
3615 x_set_vertical_scroll_bars (f, arg, oldval)
3616 struct frame *f;
3617 Lisp_Object arg, oldval;
3619 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3620 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3621 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3622 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3624 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3625 = (NILP (arg)
3626 ? vertical_scroll_bar_none
3627 : EQ (Qleft, arg)
3628 ? vertical_scroll_bar_left
3629 : EQ (Qright, arg)
3630 ? vertical_scroll_bar_right
3631 : EQ (Qleft, Vdefault_frame_scroll_bars)
3632 ? vertical_scroll_bar_left
3633 : EQ (Qright, Vdefault_frame_scroll_bars)
3634 ? vertical_scroll_bar_right
3635 : vertical_scroll_bar_none);
3637 /* We set this parameter before creating the X window for the
3638 frame, so we can get the geometry right from the start.
3639 However, if the window hasn't been created yet, we shouldn't
3640 call x_set_window_size. */
3641 if (FRAME_X_WINDOW (f))
3642 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3643 do_pending_window_change (0);
3647 void
3648 x_set_scroll_bar_width (f, arg, oldval)
3649 struct frame *f;
3650 Lisp_Object arg, oldval;
3652 int wid = FRAME_COLUMN_WIDTH (f);
3654 if (NILP (arg))
3656 x_set_scroll_bar_default_width (f);
3658 if (FRAME_X_WINDOW (f))
3659 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3660 do_pending_window_change (0);
3662 else if (INTEGERP (arg) && XINT (arg) > 0
3663 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3665 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3666 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3668 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3669 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3670 if (FRAME_X_WINDOW (f))
3671 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3672 do_pending_window_change (0);
3675 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3676 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3677 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3682 /* Return non-nil if frame F wants a bitmap icon. */
3684 Lisp_Object
3685 x_icon_type (f)
3686 FRAME_PTR f;
3688 Lisp_Object tem;
3690 tem = assq_no_quit (Qicon_type, f->param_alist);
3691 if (CONSP (tem))
3692 return XCDR (tem);
3693 else
3694 return Qnil;
3697 void
3698 x_set_alpha (f, arg, oldval)
3699 struct frame *f;
3700 Lisp_Object arg, oldval;
3702 double alpha = 1.0;
3703 double newval[2];
3704 int i, ialpha;
3705 Lisp_Object item;
3707 for (i = 0; i < 2; i++)
3709 newval[i] = 1.0;
3710 if (CONSP (arg))
3712 item = CAR (arg);
3713 arg = CDR (arg);
3715 else
3716 item = arg;
3718 if (NILP (item))
3719 alpha = - 1.0;
3720 else if (FLOATP (item))
3722 alpha = XFLOAT_DATA (item);
3723 if (alpha < 0.0 || 1.0 < alpha)
3724 args_out_of_range (make_float (0.0), make_float (1.0));
3726 else if (INTEGERP (item))
3728 ialpha = XINT (item);
3729 if (ialpha < 0 || 100 < ialpha)
3730 args_out_of_range (make_number (0), make_number (100));
3731 else
3732 alpha = ialpha / 100.0;
3734 else
3735 wrong_type_argument (Qnumberp, item);
3736 newval[i] = alpha;
3739 for (i = 0; i < 2; i++)
3740 f->alpha[i] = newval[i];
3742 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3743 BLOCK_INPUT;
3744 x_set_frame_alpha (f);
3745 UNBLOCK_INPUT;
3746 #endif
3748 return;
3752 /* Subroutines of creating an X frame. */
3754 /* Make sure that Vx_resource_name is set to a reasonable value.
3755 Fix it up, or set it to `emacs' if it is too hopeless. */
3757 void
3758 validate_x_resource_name ()
3760 int len = 0;
3761 /* Number of valid characters in the resource name. */
3762 int good_count = 0;
3763 /* Number of invalid characters in the resource name. */
3764 int bad_count = 0;
3765 Lisp_Object new;
3766 int i;
3768 if (!STRINGP (Vx_resource_class))
3769 Vx_resource_class = build_string (EMACS_CLASS);
3771 if (STRINGP (Vx_resource_name))
3773 unsigned char *p = SDATA (Vx_resource_name);
3774 int i;
3776 len = SBYTES (Vx_resource_name);
3778 /* Only letters, digits, - and _ are valid in resource names.
3779 Count the valid characters and count the invalid ones. */
3780 for (i = 0; i < len; i++)
3782 int c = p[i];
3783 if (! ((c >= 'a' && c <= 'z')
3784 || (c >= 'A' && c <= 'Z')
3785 || (c >= '0' && c <= '9')
3786 || c == '-' || c == '_'))
3787 bad_count++;
3788 else
3789 good_count++;
3792 else
3793 /* Not a string => completely invalid. */
3794 bad_count = 5, good_count = 0;
3796 /* If name is valid already, return. */
3797 if (bad_count == 0)
3798 return;
3800 /* If name is entirely invalid, or nearly so, use `emacs'. */
3801 if (good_count == 0
3802 || (good_count == 1 && bad_count > 0))
3804 Vx_resource_name = build_string ("emacs");
3805 return;
3808 /* Name is partly valid. Copy it and replace the invalid characters
3809 with underscores. */
3811 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3813 for (i = 0; i < len; i++)
3815 int c = SREF (new, i);
3816 if (! ((c >= 'a' && c <= 'z')
3817 || (c >= 'A' && c <= 'Z')
3818 || (c >= '0' && c <= '9')
3819 || c == '-' || c == '_'))
3820 SSET (new, i, '_');
3825 extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3826 extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3829 /* Get specified attribute from resource database RDB.
3830 See Fx_get_resource below for other parameters. */
3832 static Lisp_Object
3833 xrdb_get_resource (rdb, attribute, class, component, subclass)
3834 XrmDatabase rdb;
3835 Lisp_Object attribute, class, component, subclass;
3837 register char *value;
3838 char *name_key;
3839 char *class_key;
3841 CHECK_STRING (attribute);
3842 CHECK_STRING (class);
3844 if (!NILP (component))
3845 CHECK_STRING (component);
3846 if (!NILP (subclass))
3847 CHECK_STRING (subclass);
3848 if (NILP (component) != NILP (subclass))
3849 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3851 validate_x_resource_name ();
3853 /* Allocate space for the components, the dots which separate them,
3854 and the final '\0'. Make them big enough for the worst case. */
3855 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3856 + (STRINGP (component)
3857 ? SBYTES (component) : 0)
3858 + SBYTES (attribute)
3859 + 3);
3861 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3862 + SBYTES (class)
3863 + (STRINGP (subclass)
3864 ? SBYTES (subclass) : 0)
3865 + 3);
3867 /* Start with emacs.FRAMENAME for the name (the specific one)
3868 and with `Emacs' for the class key (the general one). */
3869 strcpy (name_key, SDATA (Vx_resource_name));
3870 strcpy (class_key, SDATA (Vx_resource_class));
3872 strcat (class_key, ".");
3873 strcat (class_key, SDATA (class));
3875 if (!NILP (component))
3877 strcat (class_key, ".");
3878 strcat (class_key, SDATA (subclass));
3880 strcat (name_key, ".");
3881 strcat (name_key, SDATA (component));
3884 strcat (name_key, ".");
3885 strcat (name_key, SDATA (attribute));
3887 value = x_get_string_resource (rdb, name_key, class_key);
3889 if (value != (char *) 0 && *value)
3890 return build_string (value);
3891 else
3892 return Qnil;
3896 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3897 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3898 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3899 class, where INSTANCE is the name under which Emacs was invoked, or
3900 the name specified by the `-name' or `-rn' command-line arguments.
3902 The optional arguments COMPONENT and SUBCLASS add to the key and the
3903 class, respectively. You must specify both of them or neither.
3904 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3905 and the class is `Emacs.CLASS.SUBCLASS'. */)
3906 (attribute, class, component, subclass)
3907 Lisp_Object attribute, class, component, subclass;
3909 #ifdef HAVE_X_WINDOWS
3910 check_x ();
3911 #endif
3913 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3914 attribute, class, component, subclass);
3917 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3919 Lisp_Object
3920 display_x_get_resource (dpyinfo, attribute, class, component, subclass)
3921 Display_Info *dpyinfo;
3922 Lisp_Object attribute, class, component, subclass;
3924 return xrdb_get_resource (dpyinfo->xrdb,
3925 attribute, class, component, subclass);
3928 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3929 /* Used when C code wants a resource value. */
3930 /* Called from oldXMenu/Create.c. */
3931 char *
3932 x_get_resource_string (attribute, class)
3933 char *attribute, *class;
3935 char *name_key;
3936 char *class_key;
3937 struct frame *sf = SELECTED_FRAME ();
3939 /* Allocate space for the components, the dots which separate them,
3940 and the final '\0'. */
3941 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3942 + strlen (attribute) + 2);
3943 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3944 + strlen (class) + 2);
3946 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3947 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3949 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3950 name_key, class_key);
3952 #endif
3954 /* Return the value of parameter PARAM.
3956 First search ALIST, then Vdefault_frame_alist, then the X defaults
3957 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3959 Convert the resource to the type specified by desired_type.
3961 If no default is specified, return Qunbound. If you call
3962 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3963 and don't let it get stored in any Lisp-visible variables! */
3965 Lisp_Object
3966 x_get_arg (dpyinfo, alist, param, attribute, class, type)
3967 Display_Info *dpyinfo;
3968 Lisp_Object alist, param;
3969 char *attribute;
3970 char *class;
3971 enum resource_types type;
3973 register Lisp_Object tem;
3975 tem = Fassq (param, alist);
3977 if (!NILP (tem))
3979 /* If we find this parm in ALIST, clear it out
3980 so that it won't be "left over" at the end. */
3981 Lisp_Object tail;
3982 XSETCAR (tem, Qnil);
3983 /* In case the parameter appears more than once in the alist,
3984 clear it out. */
3985 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3986 if (CONSP (XCAR (tail))
3987 && EQ (XCAR (XCAR (tail)), param))
3988 XSETCAR (XCAR (tail), Qnil);
3990 else
3991 tem = Fassq (param, Vdefault_frame_alist);
3993 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3994 look in the X resources. */
3995 if (EQ (tem, Qnil))
3997 if (attribute && dpyinfo)
3999 tem = display_x_get_resource (dpyinfo,
4000 build_string (attribute),
4001 build_string (class),
4002 Qnil, Qnil);
4004 if (NILP (tem))
4005 return Qunbound;
4007 switch (type)
4009 case RES_TYPE_NUMBER:
4010 return make_number (atoi (SDATA (tem)));
4012 case RES_TYPE_BOOLEAN_NUMBER:
4013 if (!strcmp (SDATA (tem), "on")
4014 || !strcmp (SDATA (tem), "true"))
4015 return make_number (1);
4016 return make_number (atoi (SDATA (tem)));
4017 break;
4019 case RES_TYPE_FLOAT:
4020 return make_float (atof (SDATA (tem)));
4022 case RES_TYPE_BOOLEAN:
4023 tem = Fdowncase (tem);
4024 if (!strcmp (SDATA (tem), "on")
4025 #ifdef HAVE_NS
4026 || !strcmp(SDATA(tem), "yes")
4027 #endif
4028 || !strcmp (SDATA (tem), "true"))
4029 return Qt;
4030 else
4031 return Qnil;
4033 case RES_TYPE_STRING:
4034 return tem;
4036 case RES_TYPE_SYMBOL:
4037 /* As a special case, we map the values `true' and `on'
4038 to Qt, and `false' and `off' to Qnil. */
4040 Lisp_Object lower;
4041 lower = Fdowncase (tem);
4042 if (!strcmp (SDATA (lower), "on")
4043 #ifdef HAVE_NS
4044 || !strcmp(SDATA(lower), "yes")
4045 #endif
4046 || !strcmp (SDATA (lower), "true"))
4047 return Qt;
4048 else if (!strcmp (SDATA (lower), "off")
4049 #ifdef HAVE_NS
4050 || !strcmp(SDATA(lower), "no")
4051 #endif
4052 || !strcmp (SDATA (lower), "false"))
4053 return Qnil;
4054 else
4055 return Fintern (tem, Qnil);
4058 default:
4059 abort ();
4062 else
4063 return Qunbound;
4065 return Fcdr (tem);
4068 Lisp_Object
4069 x_frame_get_arg (f, alist, param, attribute, class, type)
4070 struct frame *f;
4071 Lisp_Object alist, param;
4072 char *attribute;
4073 char *class;
4074 enum resource_types type;
4076 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
4077 alist, param, attribute, class, type);
4080 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4082 Lisp_Object
4083 x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
4084 struct frame *f;
4085 Lisp_Object alist, param;
4086 char *attribute;
4087 char *class;
4088 enum resource_types type;
4090 Lisp_Object value;
4092 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
4093 attribute, class, type);
4094 if (! NILP (value) && ! EQ (value, Qunbound))
4095 store_frame_param (f, param, value);
4097 return value;
4101 /* Record in frame F the specified or default value according to ALIST
4102 of the parameter named PROP (a Lisp symbol).
4103 If no value is specified for PROP, look for an X default for XPROP
4104 on the frame named NAME.
4105 If that is not found either, use the value DEFLT. */
4107 Lisp_Object
4108 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
4109 struct frame *f;
4110 Lisp_Object alist;
4111 Lisp_Object prop;
4112 Lisp_Object deflt;
4113 char *xprop;
4114 char *xclass;
4115 enum resource_types type;
4117 Lisp_Object tem;
4119 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4120 if (EQ (tem, Qunbound))
4121 tem = deflt;
4122 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
4123 return tem;
4129 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4130 make-docfile: the documentation string in ns-win.el was used for
4131 x-parse-geometry even in non-NS builds.
4133 With two definitions of x-parse-geometry in this file, various
4134 things still get confused (eg M-x apropos documentation), so that
4135 it is best if the two definitions just share the same doc-string.
4137 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4138 doc: /* Parse a display geometry string STRING.
4139 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4140 The properties returned may include `top', `left', `height', and `width'.
4141 For X, the value of `left' or `top' may be an integer,
4142 or a list (+ N) meaning N pixels relative to top/left corner,
4143 or a list (- N) meaning -N pixels relative to bottom/right corner.
4144 On Nextstep, this just calls `ns-parse-geometry'. */)
4145 (string)
4146 Lisp_Object string;
4148 #ifdef HAVE_NS
4149 call1 (Qns_parse_geometry, string);
4150 #else
4151 int geometry, x, y;
4152 unsigned int width, height;
4153 Lisp_Object result;
4155 CHECK_STRING (string);
4157 geometry = XParseGeometry ((char *) SDATA (string),
4158 &x, &y, &width, &height);
4159 result = Qnil;
4160 if (geometry & XValue)
4162 Lisp_Object element;
4164 if (x >= 0 && (geometry & XNegative))
4165 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
4166 else if (x < 0 && ! (geometry & XNegative))
4167 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
4168 else
4169 element = Fcons (Qleft, make_number (x));
4170 result = Fcons (element, result);
4173 if (geometry & YValue)
4175 Lisp_Object element;
4177 if (y >= 0 && (geometry & YNegative))
4178 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
4179 else if (y < 0 && ! (geometry & YNegative))
4180 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
4181 else
4182 element = Fcons (Qtop, make_number (y));
4183 result = Fcons (element, result);
4186 if (geometry & WidthValue)
4187 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4188 if (geometry & HeightValue)
4189 result = Fcons (Fcons (Qheight, make_number (height)), result);
4191 return result;
4192 #endif /* HAVE_NS */
4196 /* Calculate the desired size and position of frame F.
4197 Return the flags saying which aspects were specified.
4199 Also set the win_gravity and size_hint_flags of F.
4201 Adjust height for toolbar if TOOLBAR_P is 1.
4203 This function does not make the coordinates positive. */
4205 #define DEFAULT_ROWS 35
4206 #define DEFAULT_COLS 80
4209 x_figure_window_size (f, parms, toolbar_p)
4210 struct frame *f;
4211 Lisp_Object parms;
4212 int toolbar_p;
4214 register Lisp_Object tem0, tem1, tem2;
4215 long window_prompting = 0;
4216 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
4218 /* Default values if we fall through.
4219 Actually, if that happens we should get
4220 window manager prompting. */
4221 SET_FRAME_COLS (f, DEFAULT_COLS);
4222 FRAME_LINES (f) = DEFAULT_ROWS;
4223 /* Window managers expect that if program-specified
4224 positions are not (0,0), they're intentional, not defaults. */
4225 f->top_pos = 0;
4226 f->left_pos = 0;
4228 /* Ensure that old new_text_cols and new_text_lines will not override the
4229 values set here. */
4230 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4231 f->new_text_cols = f->new_text_lines = 0;
4233 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4234 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4235 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4236 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4238 if (!EQ (tem0, Qunbound))
4240 CHECK_NUMBER (tem0);
4241 FRAME_LINES (f) = XINT (tem0);
4243 if (!EQ (tem1, Qunbound))
4245 CHECK_NUMBER (tem1);
4246 SET_FRAME_COLS (f, XINT (tem1));
4248 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4249 window_prompting |= USSize;
4250 else
4251 window_prompting |= PSize;
4254 f->scroll_bar_actual_width
4255 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4257 /* This used to be done _before_ calling x_figure_window_size, but
4258 since the height is reset here, this was really a no-op. I
4259 assume that moving it here does what Gerd intended (although he
4260 no longer can remember what that was... ++KFS, 2003-03-25. */
4262 /* Add the tool-bar height to the initial frame height so that the
4263 user gets a text display area of the size he specified with -g or
4264 via .Xdefaults. Later changes of the tool-bar height don't
4265 change the frame size. This is done so that users can create
4266 tall Emacs frames without having to guess how tall the tool-bar
4267 will get. */
4268 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4270 int margin, relief, bar_height;
4272 relief = (tool_bar_button_relief >= 0
4273 ? tool_bar_button_relief
4274 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4276 if (INTEGERP (Vtool_bar_button_margin)
4277 && XINT (Vtool_bar_button_margin) > 0)
4278 margin = XFASTINT (Vtool_bar_button_margin);
4279 else if (CONSP (Vtool_bar_button_margin)
4280 && INTEGERP (XCDR (Vtool_bar_button_margin))
4281 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
4282 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4283 else
4284 margin = 0;
4286 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4287 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4290 compute_fringe_widths (f, 0);
4292 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4293 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4295 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4296 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4297 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4298 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4300 if (EQ (tem0, Qminus))
4302 f->top_pos = 0;
4303 window_prompting |= YNegative;
4305 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4306 && CONSP (XCDR (tem0))
4307 && INTEGERP (XCAR (XCDR (tem0))))
4309 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4310 window_prompting |= YNegative;
4312 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4313 && CONSP (XCDR (tem0))
4314 && INTEGERP (XCAR (XCDR (tem0))))
4316 f->top_pos = XINT (XCAR (XCDR (tem0)));
4318 else if (EQ (tem0, Qunbound))
4319 f->top_pos = 0;
4320 else
4322 CHECK_NUMBER (tem0);
4323 f->top_pos = XINT (tem0);
4324 if (f->top_pos < 0)
4325 window_prompting |= YNegative;
4328 if (EQ (tem1, Qminus))
4330 f->left_pos = 0;
4331 window_prompting |= XNegative;
4333 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4334 && CONSP (XCDR (tem1))
4335 && INTEGERP (XCAR (XCDR (tem1))))
4337 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4338 window_prompting |= XNegative;
4340 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4341 && CONSP (XCDR (tem1))
4342 && INTEGERP (XCAR (XCDR (tem1))))
4344 f->left_pos = XINT (XCAR (XCDR (tem1)));
4346 else if (EQ (tem1, Qunbound))
4347 f->left_pos = 0;
4348 else
4350 CHECK_NUMBER (tem1);
4351 f->left_pos = XINT (tem1);
4352 if (f->left_pos < 0)
4353 window_prompting |= XNegative;
4356 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4357 window_prompting |= USPosition;
4358 else
4359 window_prompting |= PPosition;
4362 if (window_prompting & XNegative)
4364 if (window_prompting & YNegative)
4365 f->win_gravity = SouthEastGravity;
4366 else
4367 f->win_gravity = NorthEastGravity;
4369 else
4371 if (window_prompting & YNegative)
4372 f->win_gravity = SouthWestGravity;
4373 else
4374 f->win_gravity = NorthWestGravity;
4377 f->size_hint_flags = window_prompting;
4379 return window_prompting;
4384 #endif /* HAVE_WINDOW_SYSTEM */
4386 void
4387 frame_make_pointer_invisible ()
4389 if (! NILP (Vmake_pointer_invisible))
4391 struct frame *f;
4392 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4393 return;
4395 f = SELECTED_FRAME ();
4396 if (f && !f->pointer_invisible
4397 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4399 f->mouse_moved = 0;
4400 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4401 f->pointer_invisible = 1;
4406 void
4407 frame_make_pointer_visible ()
4409 /* We don't check Vmake_pointer_invisible here in case the
4410 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4411 struct frame *f;
4413 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4414 return;
4416 f = SELECTED_FRAME ();
4417 if (f && f->pointer_invisible && f->mouse_moved
4418 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4420 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4421 f->pointer_invisible = 0;
4427 /***********************************************************************
4428 Initialization
4429 ***********************************************************************/
4431 void
4432 syms_of_frame ()
4434 Qframep = intern_c_string ("framep");
4435 staticpro (&Qframep);
4436 Qframe_live_p = intern_c_string ("frame-live-p");
4437 staticpro (&Qframe_live_p);
4438 Qexplicit_name = intern_c_string ("explicit-name");
4439 staticpro (&Qexplicit_name);
4440 Qheight = intern_c_string ("height");
4441 staticpro (&Qheight);
4442 Qicon = intern_c_string ("icon");
4443 staticpro (&Qicon);
4444 Qminibuffer = intern_c_string ("minibuffer");
4445 staticpro (&Qminibuffer);
4446 Qmodeline = intern_c_string ("modeline");
4447 staticpro (&Qmodeline);
4448 Qonly = intern_c_string ("only");
4449 staticpro (&Qonly);
4450 Qwidth = intern_c_string ("width");
4451 staticpro (&Qwidth);
4452 Qgeometry = intern_c_string ("geometry");
4453 staticpro (&Qgeometry);
4454 Qicon_left = intern_c_string ("icon-left");
4455 staticpro (&Qicon_left);
4456 Qicon_top = intern_c_string ("icon-top");
4457 staticpro (&Qicon_top);
4458 Qtooltip = intern_c_string ("tooltip");
4459 staticpro (&Qtooltip);
4460 Qleft = intern_c_string ("left");
4461 staticpro (&Qleft);
4462 Qright = intern_c_string ("right");
4463 staticpro (&Qright);
4464 Quser_position = intern_c_string ("user-position");
4465 staticpro (&Quser_position);
4466 Quser_size = intern_c_string ("user-size");
4467 staticpro (&Quser_size);
4468 Qwindow_id = intern_c_string ("window-id");
4469 staticpro (&Qwindow_id);
4470 #ifdef HAVE_X_WINDOWS
4471 Qouter_window_id = intern_c_string ("outer-window-id");
4472 staticpro (&Qouter_window_id);
4473 #endif
4474 Qparent_id = intern_c_string ("parent-id");
4475 staticpro (&Qparent_id);
4476 Qx = intern_c_string ("x");
4477 staticpro (&Qx);
4478 Qw32 = intern_c_string ("w32");
4479 staticpro (&Qw32);
4480 Qpc = intern_c_string ("pc");
4481 staticpro (&Qpc);
4482 Qmac = intern_c_string ("mac");
4483 staticpro (&Qmac);
4484 Qns = intern_c_string ("ns");
4485 staticpro (&Qns);
4486 Qvisible = intern_c_string ("visible");
4487 staticpro (&Qvisible);
4488 Qbuffer_predicate = intern_c_string ("buffer-predicate");
4489 staticpro (&Qbuffer_predicate);
4490 Qbuffer_list = intern_c_string ("buffer-list");
4491 staticpro (&Qbuffer_list);
4492 Qburied_buffer_list = intern_c_string ("buried-buffer-list");
4493 staticpro (&Qburied_buffer_list);
4494 Qdisplay_type = intern_c_string ("display-type");
4495 staticpro (&Qdisplay_type);
4496 Qbackground_mode = intern_c_string ("background-mode");
4497 staticpro (&Qbackground_mode);
4498 Qnoelisp = intern_c_string ("noelisp");
4499 staticpro (&Qnoelisp);
4500 Qtty_color_mode = intern_c_string ("tty-color-mode");
4501 staticpro (&Qtty_color_mode);
4502 Qtty = intern_c_string ("tty");
4503 staticpro (&Qtty);
4504 Qtty_type = intern_c_string ("tty-type");
4505 staticpro (&Qtty_type);
4507 Qface_set_after_frame_default = intern_c_string ("face-set-after-frame-default");
4508 staticpro (&Qface_set_after_frame_default);
4510 Qfullwidth = intern_c_string ("fullwidth");
4511 staticpro (&Qfullwidth);
4512 Qfullheight = intern_c_string ("fullheight");
4513 staticpro (&Qfullheight);
4514 Qfullboth = intern_c_string ("fullboth");
4515 staticpro (&Qfullboth);
4516 Qmaximized = intern_c_string ("maximized");
4517 staticpro (&Qmaximized);
4518 Qx_resource_name = intern_c_string ("x-resource-name");
4519 staticpro (&Qx_resource_name);
4521 Qx_frame_parameter = intern_c_string ("x-frame-parameter");
4522 staticpro (&Qx_frame_parameter);
4524 Qterminal = intern_c_string ("terminal");
4525 staticpro (&Qterminal);
4526 Qterminal_live_p = intern_c_string ("terminal-live-p");
4527 staticpro (&Qterminal_live_p);
4529 #ifdef HAVE_NS
4530 Qns_parse_geometry = intern_c_string ("ns-parse-geometry");
4531 staticpro (&Qns_parse_geometry);
4532 #endif
4535 int i;
4537 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4539 Lisp_Object v = intern_c_string (frame_parms[i].name);
4540 if (frame_parms[i].variable)
4542 *frame_parms[i].variable = v;
4543 staticpro (frame_parms[i].variable);
4545 Fput (v, Qx_frame_parameter, make_number (i));
4549 #ifdef HAVE_WINDOW_SYSTEM
4550 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4551 doc: /* The name Emacs uses to look up X resources.
4552 `x-get-resource' uses this as the first component of the instance name
4553 when requesting resource values.
4554 Emacs initially sets `x-resource-name' to the name under which Emacs
4555 was invoked, or to the value specified with the `-name' or `-rn'
4556 switches, if present.
4558 It may be useful to bind this variable locally around a call
4559 to `x-get-resource'. See also the variable `x-resource-class'. */);
4560 Vx_resource_name = Qnil;
4562 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4563 doc: /* The class Emacs uses to look up X resources.
4564 `x-get-resource' uses this as the first component of the instance class
4565 when requesting resource values.
4567 Emacs initially sets `x-resource-class' to "Emacs".
4569 Setting this variable permanently is not a reasonable thing to do,
4570 but binding this variable locally around a call to `x-get-resource'
4571 is a reasonable practice. See also the variable `x-resource-name'. */);
4572 Vx_resource_class = build_string (EMACS_CLASS);
4574 DEFVAR_LISP ("frame-alpha-lower-limit", &Vframe_alpha_lower_limit,
4575 doc: /* The lower limit of the frame opacity (alpha transparency).
4576 The value should range from 0 (invisible) to 100 (completely opaque).
4577 You can also use a floating number between 0.0 and 1.0.
4578 The default is 20. */);
4579 Vframe_alpha_lower_limit = make_number (20);
4580 #endif
4582 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4583 doc: /* Alist of default values for frame creation.
4584 These may be set in your init file, like this:
4585 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4586 These override values given in window system configuration data,
4587 including X Windows' defaults database.
4588 For values specific to the first Emacs frame, see `initial-frame-alist'.
4589 For window-system specific values, see `window-system-default-frame-alist'.
4590 For values specific to the separate minibuffer frame, see
4591 `minibuffer-frame-alist'.
4592 The `menu-bar-lines' element of the list controls whether new frames
4593 have menu bars; `menu-bar-mode' works by altering this element.
4594 Setting this variable does not affect existing frames, only new ones. */);
4595 Vdefault_frame_alist = Qnil;
4597 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4598 doc: /* Default position of scroll bars on this window-system. */);
4599 #ifdef HAVE_WINDOW_SYSTEM
4600 #if defined(HAVE_NTGUI) || defined(NS_IMPL_COCOA)
4601 /* MS-Windows and Mac OS X have scroll bars on the right by default. */
4602 Vdefault_frame_scroll_bars = Qright;
4603 #else
4604 Vdefault_frame_scroll_bars = Qleft;
4605 #endif
4606 #else
4607 Vdefault_frame_scroll_bars = Qnil;
4608 #endif
4610 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4611 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4613 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4614 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4615 `mouse-position' calls this function, passing its usual return value as
4616 argument, and returns whatever this function returns.
4617 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4618 which need to do mouse handling at the Lisp level. */);
4619 Vmouse_position_function = Qnil;
4621 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4622 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4623 If the value is an integer, highlighting is only shown after moving the
4624 mouse, while keyboard input turns off the highlight even when the mouse
4625 is over the clickable text. However, the mouse shape still indicates
4626 when the mouse is over clickable text. */);
4627 Vmouse_highlight = Qt;
4629 DEFVAR_LISP ("make-pointer-invisible", &Vmake_pointer_invisible,
4630 doc: /* If non-nil, make pointer invisible while typing.
4631 The pointer becomes visible again when the mouse is moved. */);
4632 Vmake_pointer_invisible = Qt;
4634 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4635 doc: /* Functions to be run before deleting a frame.
4636 The functions are run with one arg, the frame to be deleted.
4637 See `delete-frame'.
4639 Note that functions in this list may be called just before the frame is
4640 actually deleted, or some time later (or even both when an earlier function
4641 in `delete-frame-functions' (indirectly) calls `delete-frame'
4642 recursively). */);
4643 Vdelete_frame_functions = Qnil;
4644 Qdelete_frame_functions = intern_c_string ("delete-frame-functions");
4645 staticpro (&Qdelete_frame_functions);
4647 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4648 doc: /* Minibufferless frames use this frame's minibuffer.
4650 Emacs cannot create minibufferless frames unless this is set to an
4651 appropriate surrogate.
4653 Emacs consults this variable only when creating minibufferless
4654 frames; once the frame is created, it sticks with its assigned
4655 minibuffer, no matter what this variable is set to. This means that
4656 this variable doesn't necessarily say anything meaningful about the
4657 current set of frames, or where the minibuffer is currently being
4658 displayed.
4660 This variable is local to the current terminal and cannot be buffer-local. */);
4662 DEFVAR_BOOL ("focus-follows-mouse", &focus_follows_mouse,
4663 doc: /* Non-nil if window system changes focus when you move the mouse.
4664 You should set this variable to tell Emacs how your window manager
4665 handles focus, since there is no way in general for Emacs to find out
4666 automatically. See also `mouse-autoselect-window'. */);
4667 #ifdef HAVE_WINDOW_SYSTEM
4668 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
4669 focus_follows_mouse = 0;
4670 #else
4671 focus_follows_mouse = 1;
4672 #endif
4673 #else
4674 focus_follows_mouse = 0;
4675 #endif
4677 staticpro (&Vframe_list);
4679 defsubr (&Sactive_minibuffer_window);
4680 defsubr (&Sframep);
4681 defsubr (&Sframe_live_p);
4682 defsubr (&Swindow_system);
4683 defsubr (&Smake_terminal_frame);
4684 defsubr (&Shandle_switch_frame);
4685 defsubr (&Sselect_frame);
4686 defsubr (&Sselected_frame);
4687 defsubr (&Swindow_frame);
4688 defsubr (&Sframe_root_window);
4689 defsubr (&Sframe_first_window);
4690 defsubr (&Sframe_selected_window);
4691 defsubr (&Sset_frame_selected_window);
4692 defsubr (&Sframe_list);
4693 defsubr (&Snext_frame);
4694 defsubr (&Sprevious_frame);
4695 defsubr (&Sdelete_frame);
4696 defsubr (&Smouse_position);
4697 defsubr (&Smouse_pixel_position);
4698 defsubr (&Sset_mouse_position);
4699 defsubr (&Sset_mouse_pixel_position);
4700 #if 0
4701 defsubr (&Sframe_configuration);
4702 defsubr (&Srestore_frame_configuration);
4703 #endif
4704 defsubr (&Smake_frame_visible);
4705 defsubr (&Smake_frame_invisible);
4706 defsubr (&Siconify_frame);
4707 defsubr (&Sframe_visible_p);
4708 defsubr (&Svisible_frame_list);
4709 defsubr (&Sraise_frame);
4710 defsubr (&Slower_frame);
4711 defsubr (&Sredirect_frame_focus);
4712 defsubr (&Sframe_focus);
4713 defsubr (&Sframe_parameters);
4714 defsubr (&Sframe_parameter);
4715 defsubr (&Smodify_frame_parameters);
4716 defsubr (&Sframe_char_height);
4717 defsubr (&Sframe_char_width);
4718 defsubr (&Sframe_pixel_height);
4719 defsubr (&Sframe_pixel_width);
4720 defsubr (&Sset_frame_height);
4721 defsubr (&Sset_frame_width);
4722 defsubr (&Sset_frame_size);
4723 defsubr (&Sset_frame_position);
4725 #ifdef HAVE_WINDOW_SYSTEM
4726 defsubr (&Sx_get_resource);
4727 defsubr (&Sx_parse_geometry);
4728 #endif
4732 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4733 (do not change this comment) */