* src/fileio.c (Fwrite_region): Delay the defaulting to beg&z to after
[emacs.git] / src / frame.c
blob20812878c10e4ff3f53ab03e53f71cca2be8af87
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include "lisp.h"
24 #include "character.h"
25 #ifdef HAVE_X_WINDOWS
26 #include "xterm.h"
27 #endif
28 #ifdef WINDOWSNT
29 #include "w32term.h"
30 #endif
31 #ifdef MAC_OS
32 #include "macterm.h"
33 #endif
34 #include "buffer.h"
35 /* These help us bind and responding to switch-frame events. */
36 #include "commands.h"
37 #include "keyboard.h"
38 #include "frame.h"
39 #include "blockinput.h"
40 #include "termchar.h"
41 #include "termhooks.h"
42 #include "dispextern.h"
43 #include "window.h"
44 #ifdef HAVE_WINDOW_SYSTEM
45 #include "font.h"
46 #include "fontset.h"
47 #endif
48 #ifdef MSDOS
49 #include "msdos.h"
50 #include "dosfns.h"
51 #endif
54 #ifdef HAVE_WINDOW_SYSTEM
56 /* The name we're using in resource queries. Most often "emacs". */
58 Lisp_Object Vx_resource_name;
60 /* The application class we're using in resource queries.
61 Normally "Emacs". */
63 Lisp_Object Vx_resource_class;
65 /* Lower limit value of the frame opacity (alpha transparency). */
67 Lisp_Object Vframe_alpha_lower_limit;
69 #endif
71 Lisp_Object Qframep, Qframe_live_p;
72 Lisp_Object Qicon, Qmodeline;
73 Lisp_Object Qonly;
74 Lisp_Object Qx, Qw32, Qmac, Qpc;
75 Lisp_Object Qvisible;
76 Lisp_Object Qdisplay_type;
77 Lisp_Object Qbackground_mode;
78 Lisp_Object Qnoelisp;
80 Lisp_Object Qx_frame_parameter;
81 Lisp_Object Qx_resource_name;
82 Lisp_Object Qterminal;
83 Lisp_Object Qterminal_live_p;
85 /* Frame parameters (set or reported). */
87 Lisp_Object Qauto_raise, Qauto_lower;
88 Lisp_Object Qborder_color, Qborder_width;
89 Lisp_Object Qcursor_color, Qcursor_type;
90 Lisp_Object Qgeometry; /* Not used */
91 Lisp_Object Qheight, Qwidth;
92 Lisp_Object Qleft, Qright;
93 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
94 Lisp_Object Qinternal_border_width;
95 Lisp_Object Qmouse_color;
96 Lisp_Object Qminibuffer;
97 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
98 Lisp_Object Qvisibility;
99 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
100 Lisp_Object Qscreen_gamma;
101 Lisp_Object Qline_spacing;
102 Lisp_Object Quser_position, Quser_size;
103 Lisp_Object Qwait_for_wm;
104 Lisp_Object Qwindow_id;
105 #ifdef HAVE_X_WINDOWS
106 Lisp_Object Qouter_window_id;
107 #endif
108 Lisp_Object Qparent_id;
109 Lisp_Object Qtitle, Qname;
110 Lisp_Object Qexplicit_name;
111 Lisp_Object Qunsplittable;
112 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
113 Lisp_Object Qleft_fringe, Qright_fringe;
114 Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list;
115 Lisp_Object Qtty_color_mode;
116 Lisp_Object Qtty, Qtty_type;
118 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
119 Lisp_Object Qfont_backend;
120 Lisp_Object Qalpha;
122 Lisp_Object Qinhibit_face_set_after_frame_default;
123 Lisp_Object Qface_set_after_frame_default;
125 Lisp_Object Vterminal_frame;
126 Lisp_Object Vdefault_frame_alist;
127 Lisp_Object Vdefault_frame_scroll_bars;
128 Lisp_Object Vmouse_position_function;
129 Lisp_Object Vmouse_highlight;
130 static Lisp_Object Vdelete_frame_functions, Qdelete_frame_functions;
132 int focus_follows_mouse;
134 static void
135 set_menu_bar_lines_1 (window, n)
136 Lisp_Object window;
137 int n;
139 struct window *w = XWINDOW (window);
141 XSETFASTINT (w->last_modified, 0);
142 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
143 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
145 if (INTEGERP (w->orig_top_line))
146 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
147 if (INTEGERP (w->orig_total_lines))
148 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
150 /* Handle just the top child in a vertical split. */
151 if (!NILP (w->vchild))
152 set_menu_bar_lines_1 (w->vchild, n);
154 /* Adjust all children in a horizontal split. */
155 for (window = w->hchild; !NILP (window); window = w->next)
157 w = XWINDOW (window);
158 set_menu_bar_lines_1 (window, n);
162 void
163 set_menu_bar_lines (f, value, oldval)
164 struct frame *f;
165 Lisp_Object value, oldval;
167 int nlines;
168 int olines = FRAME_MENU_BAR_LINES (f);
170 /* Right now, menu bars don't work properly in minibuf-only frames;
171 most of the commands try to apply themselves to the minibuffer
172 frame itself, and get an error because you can't switch buffers
173 in or split the minibuffer window. */
174 if (FRAME_MINIBUF_ONLY_P (f))
175 return;
177 if (INTEGERP (value))
178 nlines = XINT (value);
179 else
180 nlines = 0;
182 if (nlines != olines)
184 windows_or_buffers_changed++;
185 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
186 FRAME_MENU_BAR_LINES (f) = nlines;
187 set_menu_bar_lines_1 (f->root_window, nlines - olines);
188 adjust_glyphs (f);
192 Lisp_Object Vemacs_iconified;
193 Lisp_Object Vframe_list;
195 extern Lisp_Object Vminibuffer_list;
196 extern Lisp_Object get_minibuffer ();
197 extern Lisp_Object Fhandle_switch_frame ();
198 extern Lisp_Object Fredirect_frame_focus ();
199 extern Lisp_Object x_get_focus_frame ();
201 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
202 doc: /* Return non-nil if OBJECT is a frame.
203 Value is t for a termcap frame (a character-only terminal),
204 `x' for an Emacs frame that is really an X window,
205 `w32' for an Emacs frame that is a window on MS-Windows display,
206 `mac' for an Emacs frame on a Macintosh display,
207 `pc' for a direct-write MS-DOS frame.
208 See also `frame-live-p'. */)
209 (object)
210 Lisp_Object object;
212 if (!FRAMEP (object))
213 return Qnil;
214 switch (XFRAME (object)->output_method)
216 case output_initial: /* The initial frame is like a termcap frame. */
217 case output_termcap:
218 return Qt;
219 case output_x_window:
220 return Qx;
221 case output_w32:
222 return Qw32;
223 case output_msdos_raw:
224 return Qpc;
225 case output_mac:
226 return Qmac;
227 default:
228 abort ();
232 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
233 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
234 Value is nil if OBJECT is not a live frame. If object is a live
235 frame, the return value indicates what sort of terminal device it is
236 displayed on. See the documentation of `framep' for possible
237 return values. */)
238 (object)
239 Lisp_Object object;
241 return ((FRAMEP (object)
242 && FRAME_LIVE_P (XFRAME (object)))
243 ? Fframep (object)
244 : Qnil);
247 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
248 doc: /* The name of the window system that FRAME is displaying through.
249 The value is a symbol---for instance, 'x' for X windows.
250 The value is nil if Emacs is using a text-only terminal.
252 FRAME defaults to the currently selected frame. */)
253 (frame)
254 Lisp_Object frame;
256 Lisp_Object type;
257 if (NILP (frame))
258 frame = selected_frame;
260 type = Fframep (frame);
262 if (NILP (type))
263 wrong_type_argument (Qframep, frame);
265 if (EQ (type, Qt))
266 return Qnil;
267 else
268 return type;
271 struct frame *
272 make_frame (mini_p)
273 int mini_p;
275 Lisp_Object frame;
276 register struct frame *f;
277 register Lisp_Object root_window;
278 register Lisp_Object mini_window;
280 f = allocate_frame ();
281 XSETFRAME (frame, f);
283 f->desired_matrix = 0;
284 f->current_matrix = 0;
285 f->desired_pool = 0;
286 f->current_pool = 0;
287 f->glyphs_initialized_p = 0;
288 f->decode_mode_spec_buffer = 0;
289 f->visible = 0;
290 f->async_visible = 0;
291 f->output_data.nothing = 0;
292 f->iconified = 0;
293 f->async_iconified = 0;
294 f->wants_modeline = 1;
295 f->auto_raise = 0;
296 f->auto_lower = 0;
297 f->no_split = 0;
298 f->garbaged = 1;
299 f->has_minibuffer = mini_p;
300 f->focus_frame = Qnil;
301 f->explicit_name = 0;
302 f->can_have_scroll_bars = 0;
303 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
304 f->param_alist = Qnil;
305 f->scroll_bars = Qnil;
306 f->condemned_scroll_bars = Qnil;
307 f->face_alist = Qnil;
308 f->face_cache = NULL;
309 f->menu_bar_items = Qnil;
310 f->menu_bar_vector = Qnil;
311 f->menu_bar_items_used = 0;
312 f->buffer_predicate = Qnil;
313 f->buffer_list = Qnil;
314 f->buried_buffer_list = Qnil;
315 f->namebuf = 0;
316 f->title = Qnil;
317 f->menu_bar_window = Qnil;
318 f->tool_bar_window = Qnil;
319 f->tool_bar_items = Qnil;
320 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
321 f->n_tool_bar_items = 0;
322 f->left_fringe_width = f->right_fringe_width = 0;
323 f->fringe_cols = 0;
324 f->scroll_bar_actual_width = 0;
325 f->border_width = 0;
326 f->internal_border_width = 0;
327 f->column_width = 1; /* !FRAME_WINDOW_P value */
328 f->line_height = 1; /* !FRAME_WINDOW_P value */
329 f->x_pixels_diff = f->y_pixels_diff = 0;
330 #ifdef HAVE_WINDOW_SYSTEM
331 f->want_fullscreen = FULLSCREEN_NONE;
332 #endif
333 f->size_hint_flags = 0;
334 f->win_gravity = 0;
335 f->font_driver_list = NULL;
336 f->font_data_list = NULL;
338 root_window = make_window ();
339 if (mini_p)
341 mini_window = make_window ();
342 XWINDOW (root_window)->next = mini_window;
343 XWINDOW (mini_window)->prev = root_window;
344 XWINDOW (mini_window)->mini_p = Qt;
345 XWINDOW (mini_window)->frame = frame;
346 f->minibuffer_window = mini_window;
348 else
350 mini_window = Qnil;
351 XWINDOW (root_window)->next = Qnil;
352 f->minibuffer_window = Qnil;
355 XWINDOW (root_window)->frame = frame;
357 /* 10 is arbitrary,
358 just so that there is "something there."
359 Correct size will be set up later with change_frame_size. */
361 SET_FRAME_COLS (f, 10);
362 FRAME_LINES (f) = 10;
364 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
365 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
367 if (mini_p)
369 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
370 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
371 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
374 /* Choose a buffer for the frame's root window. */
376 Lisp_Object buf;
378 XWINDOW (root_window)->buffer = Qt;
379 buf = Fcurrent_buffer ();
380 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
381 a space), try to find another one. */
382 if (SREF (Fbuffer_name (buf), 0) == ' ')
383 buf = Fother_buffer (buf, Qnil, Qnil);
385 /* Use set_window_buffer, not Fset_window_buffer, and don't let
386 hooks be run by it. The reason is that the whole frame/window
387 arrangement is not yet fully intialized at this point. Windows
388 don't have the right size, glyph matrices aren't initialized
389 etc. Running Lisp functions at this point surely ends in a
390 SEGV. */
391 set_window_buffer (root_window, buf, 0, 0);
392 f->buffer_list = Fcons (buf, Qnil);
395 if (mini_p)
397 XWINDOW (mini_window)->buffer = Qt;
398 set_window_buffer (mini_window,
399 (NILP (Vminibuffer_list)
400 ? get_minibuffer (0)
401 : Fcar (Vminibuffer_list)),
402 0, 0);
405 f->root_window = root_window;
406 f->selected_window = root_window;
407 /* Make sure this window seems more recently used than
408 a newly-created, never-selected window. */
409 ++window_select_count;
410 XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
412 f->default_face_done_p = 0;
414 return f;
417 #ifdef HAVE_WINDOW_SYSTEM
418 /* Make a frame using a separate minibuffer window on another frame.
419 MINI_WINDOW is the minibuffer window to use. nil means use the
420 default (the global minibuffer). */
422 struct frame *
423 make_frame_without_minibuffer (mini_window, kb, display)
424 register Lisp_Object mini_window;
425 KBOARD *kb;
426 Lisp_Object display;
428 register struct frame *f;
429 struct gcpro gcpro1;
431 if (!NILP (mini_window))
432 CHECK_LIVE_WINDOW (mini_window);
434 #ifdef MULTI_KBOARD
435 if (!NILP (mini_window)
436 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
437 error ("Frame and minibuffer must be on the same terminal");
438 #endif
440 /* Make a frame containing just a root window. */
441 f = make_frame (0);
443 if (NILP (mini_window))
445 /* Use default-minibuffer-frame if possible. */
446 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
447 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
449 Lisp_Object frame_dummy;
451 XSETFRAME (frame_dummy, f);
452 GCPRO1 (frame_dummy);
453 /* If there's no minibuffer frame to use, create one. */
454 kb->Vdefault_minibuffer_frame =
455 call1 (intern ("make-initial-minibuffer-frame"), display);
456 UNGCPRO;
459 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
462 f->minibuffer_window = mini_window;
464 /* Make the chosen minibuffer window display the proper minibuffer,
465 unless it is already showing a minibuffer. */
466 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
467 Fset_window_buffer (mini_window,
468 (NILP (Vminibuffer_list)
469 ? get_minibuffer (0)
470 : Fcar (Vminibuffer_list)), Qnil);
471 return f;
474 /* Make a frame containing only a minibuffer window. */
476 struct frame *
477 make_minibuffer_frame ()
479 /* First make a frame containing just a root window, no minibuffer. */
481 register struct frame *f = make_frame (0);
482 register Lisp_Object mini_window;
483 register Lisp_Object frame;
485 XSETFRAME (frame, f);
487 f->auto_raise = 0;
488 f->auto_lower = 0;
489 f->no_split = 1;
490 f->wants_modeline = 0;
491 f->has_minibuffer = 1;
493 /* Now label the root window as also being the minibuffer.
494 Avoid infinite looping on the window chain by marking next pointer
495 as nil. */
497 mini_window = f->minibuffer_window = f->root_window;
498 XWINDOW (mini_window)->mini_p = Qt;
499 XWINDOW (mini_window)->next = Qnil;
500 XWINDOW (mini_window)->prev = Qnil;
501 XWINDOW (mini_window)->frame = frame;
503 /* Put the proper buffer in that window. */
505 Fset_window_buffer (mini_window,
506 (NILP (Vminibuffer_list)
507 ? get_minibuffer (0)
508 : Fcar (Vminibuffer_list)), Qnil);
509 return f;
511 #endif /* HAVE_WINDOW_SYSTEM */
513 /* Construct a frame that refers to a terminal. */
515 static int tty_frame_count;
517 struct frame *
518 make_initial_frame (void)
520 struct frame *f;
521 struct terminal *terminal;
522 Lisp_Object frame;
524 eassert (initial_kboard);
526 /* The first call must initialize Vframe_list. */
527 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
528 Vframe_list = Qnil;
530 terminal = init_initial_terminal ();
532 f = make_frame (1);
533 XSETFRAME (frame, f);
535 Vframe_list = Fcons (frame, Vframe_list);
537 tty_frame_count = 1;
538 f->name = build_string ("F1");
540 f->visible = 1;
541 f->async_visible = 1;
543 f->output_method = terminal->type;
544 f->terminal = terminal;
545 f->terminal->reference_count++;
546 f->output_data.nothing = 0;
548 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
549 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
551 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
552 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
554 return f;
558 struct frame *
559 make_terminal_frame (struct terminal *terminal)
561 register struct frame *f;
562 Lisp_Object frame;
563 char name[20];
565 if (!terminal->name)
566 error ("Terminal is not live, can't create new frames on it");
568 f = make_frame (1);
570 XSETFRAME (frame, f);
571 Vframe_list = Fcons (frame, Vframe_list);
573 tty_frame_count++;
574 sprintf (name, "F%d", tty_frame_count);
575 f->name = build_string (name);
577 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
578 f->async_visible = 1; /* Don't let visible be cleared later. */
579 #ifdef MSDOS
580 f->output_data.x = &the_only_x_display;
581 if (!inhibit_window_system
582 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
583 || XFRAME (selected_frame)->output_method == output_msdos_raw))
585 f->output_method = output_msdos_raw;
586 /* This initialization of foreground and background pixels is
587 only important for the initial frame created in temacs. If
588 we don't do that, we get black background and foreground in
589 the dumped Emacs because the_only_x_display is a static
590 variable, hence it is born all-zeroes, and zero is the code
591 for the black color. Other frames all inherit their pixels
592 from what's already in the_only_x_display. */
593 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
594 && FRAME_BACKGROUND_PIXEL (f) == 0
595 && FRAME_FOREGROUND_PIXEL (f) == 0)
597 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
598 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
601 else
602 f->output_method = output_termcap;
603 #else
605 f->output_method = output_termcap;
606 f->terminal = terminal;
607 f->terminal->reference_count++;
608 create_tty_output (f);
610 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
611 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
613 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
614 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
616 /* Set the top frame to the newly created frame. */
617 if (FRAMEP (FRAME_TTY (f)->top_frame)
618 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
619 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
621 FRAME_TTY (f)->top_frame = frame;
624 #ifdef CANNOT_DUMP
625 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
626 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
627 #endif
628 #endif /* MSDOS */
630 if (!noninteractive)
631 init_frame_faces (f);
633 return f;
636 /* Get a suitable value for frame parameter PARAMETER for a newly
637 created frame, based on (1) the user-supplied frame parameter
638 alist SUPPLIED_PARMS, (2) CURRENT_VALUE, and finally, if all else
639 fails, (3) Vdefault_frame_alist. */
641 static Lisp_Object
642 get_future_frame_param (Lisp_Object parameter,
643 Lisp_Object supplied_parms,
644 char *current_value)
646 Lisp_Object result;
648 result = Fassq (parameter, supplied_parms);
649 if (NILP (result))
650 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
651 if (NILP (result) && current_value != NULL)
652 result = build_string (current_value);
653 if (NILP (result))
654 result = Fassq (parameter, Vdefault_frame_alist);
655 if (!NILP (result) && !STRINGP (result))
656 result = XCDR (result);
657 if (NILP (result) || !STRINGP (result))
658 result = Qnil;
660 return result;
663 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
664 1, 1, 0,
665 doc: /* Create an additional terminal frame, possibly on another terminal.
666 This function takes one argument, an alist specifying frame parameters.
668 You can create multiple frames on a single text-only terminal, but
669 only one of them (the selected terminal frame) is actually displayed.
671 In practice, generally you don't need to specify any parameters,
672 except when you want to create a new frame on another terminal.
673 In that case, the `tty' parameter specifies the device file to open,
674 and the `tty-type' parameter specifies the terminal type. Example:
676 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
678 Note that changing the size of one terminal frame automatically
679 affects all frames on the same terminal device. */)
680 (parms)
681 Lisp_Object parms;
683 struct frame *f;
684 struct terminal *t = NULL;
685 Lisp_Object frame, tem;
686 struct frame *sf = SELECTED_FRAME ();
688 #ifdef MSDOS
689 if (sf->output_method != output_msdos_raw
690 && sf->output_method != output_termcap)
691 abort ();
692 #else /* not MSDOS */
694 #if 0
695 /* This can happen for multi-tty when using both terminal frames and
696 Carbon frames. */
697 if (sf->output_method != output_mac)
698 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
699 #else
700 #if 0 /* This should work now! */
701 if (sf->output_method != output_termcap)
702 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
703 #endif
704 #endif
705 #endif /* not MSDOS */
708 Lisp_Object terminal;
710 terminal = Fassq (Qterminal, parms);
711 if (!NILP (terminal))
713 terminal = XCDR (terminal);
714 t = get_terminal (terminal, 1);
718 if (!t)
720 char *name = 0, *type = 0;
721 Lisp_Object tty, tty_type;
723 tty = get_future_frame_param
724 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
725 ? FRAME_TTY (XFRAME (selected_frame))->name
726 : NULL));
727 if (!NILP (tty))
729 name = (char *) alloca (SBYTES (tty) + 1);
730 strncpy (name, SDATA (tty), SBYTES (tty));
731 name[SBYTES (tty)] = 0;
734 tty_type = get_future_frame_param
735 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
736 ? FRAME_TTY (XFRAME (selected_frame))->type
737 : NULL));
738 if (!NILP (tty_type))
740 type = (char *) alloca (SBYTES (tty_type) + 1);
741 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
742 type[SBYTES (tty_type)] = 0;
745 t = init_tty (name, type, 0); /* Errors are not fatal. */
748 f = make_terminal_frame (t);
751 int width, height;
752 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
753 change_frame_size (f, height, width, 0, 0, 0);
756 adjust_glyphs (f);
757 calculate_costs (f);
758 XSETFRAME (frame, f);
759 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
760 Fmodify_frame_parameters (frame, parms);
761 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
762 build_string (t->display_info.tty->type)),
763 Qnil));
764 if (t->display_info.tty->name != NULL)
765 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
766 build_string (t->display_info.tty->name)),
767 Qnil));
768 else
769 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
771 /* Make the frame face alist be frame-specific, so that each
772 frame could change its face definitions independently. */
773 f->face_alist = Fcopy_alist (sf->face_alist);
774 /* Simple Fcopy_alist isn't enough, because we need the contents of
775 the vectors which are the CDRs of associations in face_alist to
776 be copied as well. */
777 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
778 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
779 return frame;
783 /* Perform the switch to frame FRAME.
785 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
786 FRAME1 as frame.
788 If TRACK is non-zero and the frame that currently has the focus
789 redirects its focus to the selected frame, redirect that focused
790 frame's focus to FRAME instead.
792 FOR_DELETION non-zero means that the selected frame is being
793 deleted, which includes the possibility that the frame's terminal
794 is dead. */
796 Lisp_Object
797 do_switch_frame (frame, track, for_deletion)
798 Lisp_Object frame;
799 int track, for_deletion;
801 struct frame *sf = SELECTED_FRAME ();
803 /* If FRAME is a switch-frame event, extract the frame we should
804 switch to. */
805 if (CONSP (frame)
806 && EQ (XCAR (frame), Qswitch_frame)
807 && CONSP (XCDR (frame)))
808 frame = XCAR (XCDR (frame));
810 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
811 a switch-frame event to arrive after a frame is no longer live,
812 especially when deleting the initial frame during startup. */
813 CHECK_FRAME (frame);
814 if (! FRAME_LIVE_P (XFRAME (frame)))
815 return Qnil;
817 if (sf == XFRAME (frame))
818 return frame;
820 /* This is too greedy; it causes inappropriate focus redirection
821 that's hard to get rid of. */
822 #if 0
823 /* If a frame's focus has been redirected toward the currently
824 selected frame, we should change the redirection to point to the
825 newly selected frame. This means that if the focus is redirected
826 from a minibufferless frame to a surrogate minibuffer frame, we
827 can use `other-window' to switch between all the frames using
828 that minibuffer frame, and the focus redirection will follow us
829 around. */
830 if (track)
832 Lisp_Object tail;
834 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
836 Lisp_Object focus;
838 if (!FRAMEP (XCAR (tail)))
839 abort ();
841 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
843 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
844 Fredirect_frame_focus (XCAR (tail), frame);
847 #else /* ! 0 */
848 /* Instead, apply it only to the frame we're pointing to. */
849 #ifdef HAVE_WINDOW_SYSTEM
850 if (track && FRAME_WINDOW_P (XFRAME (frame)))
852 Lisp_Object focus, xfocus;
854 xfocus = x_get_focus_frame (XFRAME (frame));
855 if (FRAMEP (xfocus))
857 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
858 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
859 Fredirect_frame_focus (xfocus, frame);
862 #endif /* HAVE_X_WINDOWS */
863 #endif /* ! 0 */
865 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
866 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
868 if (FRAME_TERMCAP_P (XFRAME (frame)))
870 if (FRAMEP (FRAME_TTY (XFRAME (frame))->top_frame))
871 /* Mark previously displayed frame as now obscured. */
872 XFRAME (FRAME_TTY (XFRAME (frame))->top_frame)->async_visible = 2;
873 XFRAME (frame)->async_visible = 1;
874 FRAME_TTY (XFRAME (frame))->top_frame = frame;
877 selected_frame = frame;
878 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
879 last_nonminibuf_frame = XFRAME (selected_frame);
881 Fselect_window (XFRAME (frame)->selected_window, Qnil);
883 /* We want to make sure that the next event generates a frame-switch
884 event to the appropriate frame. This seems kludgy to me, but
885 before you take it out, make sure that evaluating something like
886 (select-window (frame-root-window (new-frame))) doesn't end up
887 with your typing being interpreted in the new frame instead of
888 the one you're actually typing in. */
889 internal_last_event_frame = Qnil;
891 return frame;
894 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 1, "e",
895 doc: /* Select the frame FRAME.
896 Subsequent editing commands apply to its selected window.
897 The selection of FRAME lasts until the next time the user does
898 something to select a different frame, or until the next time this
899 function is called. If you are using a window system, the previously
900 selected frame may be restored as the selected frame after return to
901 the command loop, because it still may have the window system's input
902 focus. On a text-only terminal, the next redisplay will display FRAME.
904 This function returns FRAME, or nil if FRAME has been deleted. */)
905 (frame)
906 Lisp_Object frame;
908 return do_switch_frame (frame, 1, 0);
912 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
913 doc: /* Handle a switch-frame event EVENT.
914 Switch-frame events are usually bound to this function.
915 A switch-frame event tells Emacs that the window manager has requested
916 that the user's events be directed to the frame mentioned in the event.
917 This function selects the selected window of the frame of EVENT.
919 If EVENT is frame object, handle it as if it were a switch-frame event
920 to that frame. */)
921 (event)
922 Lisp_Object event;
924 /* Preserve prefix arg that the command loop just cleared. */
925 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
926 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
927 return do_switch_frame (event, 0, 0);
930 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
931 doc: /* Return the frame that is now selected. */)
934 return selected_frame;
937 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
938 doc: /* Return the frame object that window WINDOW is on. */)
939 (window)
940 Lisp_Object window;
942 CHECK_LIVE_WINDOW (window);
943 return XWINDOW (window)->frame;
946 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
947 doc: /* Returns the topmost, leftmost window of FRAME.
948 If omitted, FRAME defaults to the currently selected frame. */)
949 (frame)
950 Lisp_Object frame;
952 Lisp_Object w;
954 if (NILP (frame))
955 w = SELECTED_FRAME ()->root_window;
956 else
958 CHECK_LIVE_FRAME (frame);
959 w = XFRAME (frame)->root_window;
961 while (NILP (XWINDOW (w)->buffer))
963 if (! NILP (XWINDOW (w)->hchild))
964 w = XWINDOW (w)->hchild;
965 else if (! NILP (XWINDOW (w)->vchild))
966 w = XWINDOW (w)->vchild;
967 else
968 abort ();
970 return w;
973 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
974 Sactive_minibuffer_window, 0, 0, 0,
975 doc: /* Return the currently active minibuffer window, or nil if none. */)
978 return minibuf_level ? minibuf_window : Qnil;
981 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
982 doc: /* Returns the root-window of FRAME.
983 If omitted, FRAME defaults to the currently selected frame. */)
984 (frame)
985 Lisp_Object frame;
987 Lisp_Object window;
989 if (NILP (frame))
990 window = SELECTED_FRAME ()->root_window;
991 else
993 CHECK_LIVE_FRAME (frame);
994 window = XFRAME (frame)->root_window;
997 return window;
1000 DEFUN ("frame-selected-window", Fframe_selected_window,
1001 Sframe_selected_window, 0, 1, 0,
1002 doc: /* Return the selected window of frame object FRAME.
1003 If omitted, FRAME defaults to the currently selected frame. */)
1004 (frame)
1005 Lisp_Object frame;
1007 Lisp_Object window;
1009 if (NILP (frame))
1010 window = SELECTED_FRAME ()->selected_window;
1011 else
1013 CHECK_LIVE_FRAME (frame);
1014 window = XFRAME (frame)->selected_window;
1017 return window;
1020 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
1021 Sset_frame_selected_window, 2, 2, 0,
1022 doc: /* Set the selected window of frame object FRAME to WINDOW.
1023 Return WINDOW.
1024 If FRAME is nil, the selected frame is used.
1025 If FRAME is the selected frame, this makes WINDOW the selected window. */)
1026 (frame, window)
1027 Lisp_Object frame, window;
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, Qnil);
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 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 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1319 doc: /* Delete FRAME, permanently eliminating it from use.
1320 If omitted, FRAME defaults to the selected frame.
1321 A frame may not be deleted if its minibuffer is used by other frames.
1322 Normally, you may not delete a frame if all other frames are invisible,
1323 but if the second optional argument FORCE is non-nil, you may do so.
1325 This function runs `delete-frame-functions' before actually deleting the
1326 frame, unless the frame is a tooltip.
1327 The functions are run with one arg, the frame to be deleted.
1328 But FORCE inhibits this too. */)
1329 /* FORCE is non-nil when handling a disconnected terminal. */
1330 (frame, force)
1331 Lisp_Object frame, force;
1333 struct frame *f;
1334 struct frame *sf = SELECTED_FRAME ();
1335 struct kboard *kb;
1337 int minibuffer_selected;
1339 if (EQ (frame, Qnil))
1341 f = sf;
1342 XSETFRAME (frame, f);
1344 else
1346 CHECK_FRAME (frame);
1347 f = XFRAME (frame);
1350 if (! FRAME_LIVE_P (f))
1351 return Qnil;
1353 if (NILP (force) && !other_visible_frames (f))
1354 error ("Attempt to delete the sole visible or iconified frame");
1356 #if 0
1357 /* This is a nice idea, but x_connection_closed needs to be able
1358 to delete the last frame, if it is gone. */
1359 if (NILP (XCDR (Vframe_list)))
1360 error ("Attempt to delete the only frame");
1361 #endif
1363 /* Does this frame have a minibuffer, and is it the surrogate
1364 minibuffer for any other frame? */
1365 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1367 Lisp_Object frames;
1369 for (frames = Vframe_list;
1370 CONSP (frames);
1371 frames = XCDR (frames))
1373 Lisp_Object this;
1374 this = XCAR (frames);
1376 if (! EQ (this, frame)
1377 && EQ (frame,
1378 WINDOW_FRAME (XWINDOW
1379 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1381 /* If we MUST delete this frame, delete the other first. */
1382 if (!NILP (force))
1383 Fdelete_frame (this, force);
1384 else
1385 error ("Attempt to delete a surrogate minibuffer frame");
1390 /* Run `delete-frame-functions'
1391 unless FORCE is `noelisp' or frame is a tooltip.
1392 FORCE is set to `noelisp' when handling a disconnect from the terminal,
1393 so we don't dare call Lisp code. */
1394 if (NILP (Vrun_hooks) || !NILP (Fframe_parameter (frame, intern ("tooltip"))))
1396 if (EQ (force, Qnoelisp))
1397 pending_funcalls
1398 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1399 pending_funcalls);
1400 else
1401 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1403 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1404 if (! FRAME_LIVE_P (f))
1405 return Qnil;
1407 /* At this point, we are committed to deleting the frame.
1408 There is no more chance for errors to prevent it. */
1410 minibuffer_selected = EQ (minibuf_window, selected_window);
1412 /* Don't let the frame remain selected. */
1413 if (f == sf)
1415 Lisp_Object tail, frame1;
1417 /* Look for another visible frame on the same terminal. */
1418 frame1 = next_frame (frame, Qvisible);
1420 /* If there is none, find *some* other frame. */
1421 if (NILP (frame1) || EQ (frame1, frame))
1423 FOR_EACH_FRAME (tail, frame1)
1425 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1426 break;
1430 do_switch_frame (frame1, 0, 1);
1431 sf = SELECTED_FRAME ();
1434 /* Don't allow minibuf_window to remain on a deleted frame. */
1435 if (EQ (f->minibuffer_window, minibuf_window))
1437 Fset_window_buffer (sf->minibuffer_window,
1438 XWINDOW (minibuf_window)->buffer, Qnil);
1439 minibuf_window = sf->minibuffer_window;
1441 /* If the dying minibuffer window was selected,
1442 select the new one. */
1443 if (minibuffer_selected)
1444 Fselect_window (minibuf_window, Qnil);
1447 /* Don't let echo_area_window to remain on a deleted frame. */
1448 if (EQ (f->minibuffer_window, echo_area_window))
1449 echo_area_window = sf->minibuffer_window;
1451 /* Clear any X selections for this frame. */
1452 #ifdef HAVE_X_WINDOWS
1453 if (FRAME_X_P (f))
1454 x_clear_frame_selections (f);
1455 #endif
1456 #ifdef MAC_OS
1457 if (FRAME_MAC_P (f))
1458 x_clear_frame_selections (f);
1459 #endif
1461 /* Free glyphs.
1462 This function must be called before the window tree of the
1463 frame is deleted because windows contain dynamically allocated
1464 memory. */
1465 free_glyphs (f);
1467 #ifdef HAVE_WINDOW_SYSTEM
1468 /* Give chance to each font driver to free a frame specific data. */
1469 font_update_drivers (f, Qnil);
1470 #endif
1472 /* Mark all the windows that used to be on FRAME as deleted, and then
1473 remove the reference to them. */
1474 delete_all_subwindows (XWINDOW (f->root_window));
1475 f->root_window = Qnil;
1477 Vframe_list = Fdelq (frame, Vframe_list);
1478 FRAME_SET_VISIBLE (f, 0);
1480 if (f->namebuf)
1481 xfree (f->namebuf);
1482 if (f->decode_mode_spec_buffer)
1483 xfree (f->decode_mode_spec_buffer);
1484 if (FRAME_INSERT_COST (f))
1485 xfree (FRAME_INSERT_COST (f));
1486 if (FRAME_DELETEN_COST (f))
1487 xfree (FRAME_DELETEN_COST (f));
1488 if (FRAME_INSERTN_COST (f))
1489 xfree (FRAME_INSERTN_COST (f));
1490 if (FRAME_DELETE_COST (f))
1491 xfree (FRAME_DELETE_COST (f));
1492 if (FRAME_MESSAGE_BUF (f))
1493 xfree (FRAME_MESSAGE_BUF (f));
1495 /* Since some events are handled at the interrupt level, we may get
1496 an event for f at any time; if we zero out the frame's terminal
1497 now, then we may trip up the event-handling code. Instead, we'll
1498 promise that the terminal of the frame must be valid until we
1499 have called the window-system-dependent frame destruction
1500 routine. */
1502 if (FRAME_TERMINAL (f)->delete_frame_hook)
1503 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1506 struct terminal *terminal = FRAME_TERMINAL (f);
1507 f->output_data.nothing = 0;
1508 f->terminal = 0; /* Now the frame is dead. */
1510 /* If needed, delete the terminal that this frame was on.
1511 (This must be done after the frame is killed.) */
1512 terminal->reference_count--;
1513 if (terminal->reference_count == 0)
1515 Lisp_Object tmp;
1516 XSETTERMINAL (tmp, terminal);
1518 kb = NULL;
1519 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1521 #ifdef MULTI_KBOARD
1522 else
1523 kb = terminal->kboard;
1524 #endif
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 update_mode_lines = 1;
1641 return Qnil;
1644 /* Return mouse position in character cell units. */
1646 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1647 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1648 The position is given in character cells, where (0, 0) is the
1649 upper-left corner of the frame, X is the horizontal offset, and Y is
1650 the vertical offset.
1651 If Emacs is running on a mouseless terminal or hasn't been programmed
1652 to read the mouse position, it returns the selected frame for FRAME
1653 and nil for X and Y.
1654 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1655 passing the normal return value to that function as an argument,
1656 and returns whatever that function returns. */)
1659 FRAME_PTR f;
1660 Lisp_Object lispy_dummy;
1661 enum scroll_bar_part party_dummy;
1662 Lisp_Object x, y, retval;
1663 int col, row;
1664 unsigned long long_dummy;
1665 struct gcpro gcpro1;
1667 f = SELECTED_FRAME ();
1668 x = y = Qnil;
1670 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1671 /* It's okay for the hook to refrain from storing anything. */
1672 if (FRAME_TERMINAL (f)->mouse_position_hook)
1673 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1674 &lispy_dummy, &party_dummy,
1675 &x, &y,
1676 &long_dummy);
1677 if (! NILP (x))
1679 col = XINT (x);
1680 row = XINT (y);
1681 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1682 XSETINT (x, col);
1683 XSETINT (y, row);
1685 #endif
1686 XSETFRAME (lispy_dummy, f);
1687 retval = Fcons (lispy_dummy, Fcons (x, y));
1688 GCPRO1 (retval);
1689 if (!NILP (Vmouse_position_function))
1690 retval = call1 (Vmouse_position_function, retval);
1691 RETURN_UNGCPRO (retval);
1694 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1695 Smouse_pixel_position, 0, 0, 0,
1696 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1697 The position is given in pixel units, where (0, 0) is the
1698 upper-left corner of the frame, X is the horizontal offset, and Y is
1699 the vertical offset.
1700 If Emacs is running on a mouseless terminal or hasn't been programmed
1701 to read the mouse position, it returns the selected frame for FRAME
1702 and nil for X and Y. */)
1705 FRAME_PTR f;
1706 Lisp_Object lispy_dummy;
1707 enum scroll_bar_part party_dummy;
1708 Lisp_Object x, y;
1709 unsigned long long_dummy;
1711 f = SELECTED_FRAME ();
1712 x = y = Qnil;
1714 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1715 /* It's okay for the hook to refrain from storing anything. */
1716 if (FRAME_TERMINAL (f)->mouse_position_hook)
1717 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1718 &lispy_dummy, &party_dummy,
1719 &x, &y,
1720 &long_dummy);
1721 #endif
1722 XSETFRAME (lispy_dummy, f);
1723 return Fcons (lispy_dummy, Fcons (x, y));
1726 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1727 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1728 Coordinates are relative to the frame, not a window,
1729 so the coordinates of the top left character in the frame
1730 may be nonzero due to left-hand scroll bars or the menu bar.
1732 The position is given in character cells, where (0, 0) is the
1733 upper-left corner of the frame, X is the horizontal offset, and Y is
1734 the vertical offset.
1736 This function is a no-op for an X frame that is not visible.
1737 If you have just created a frame, you must wait for it to become visible
1738 before calling this function on it, like this.
1739 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1740 (frame, x, y)
1741 Lisp_Object frame, x, y;
1743 CHECK_LIVE_FRAME (frame);
1744 CHECK_NUMBER (x);
1745 CHECK_NUMBER (y);
1747 /* I think this should be done with a hook. */
1748 #ifdef HAVE_WINDOW_SYSTEM
1749 if (FRAME_WINDOW_P (XFRAME (frame)))
1750 /* Warping the mouse will cause enternotify and focus events. */
1751 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1752 #else
1753 #if defined (MSDOS) && defined (HAVE_MOUSE)
1754 if (FRAME_MSDOS_P (XFRAME (frame)))
1756 Fselect_frame (frame);
1757 mouse_moveto (XINT (x), XINT (y));
1759 #else
1760 #ifdef HAVE_GPM
1762 Fselect_frame (frame);
1763 term_mouse_moveto (XINT (x), XINT (y));
1765 #endif
1766 #endif
1767 #endif
1769 return Qnil;
1772 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1773 Sset_mouse_pixel_position, 3, 3, 0,
1774 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1775 The position is given in pixels, where (0, 0) is the upper-left corner
1776 of the frame, X is the horizontal offset, and Y is the vertical offset.
1778 Note, this is a no-op for an X frame that is not visible.
1779 If you have just created a frame, you must wait for it to become visible
1780 before calling this function on it, like this.
1781 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1782 (frame, x, y)
1783 Lisp_Object frame, x, y;
1785 CHECK_LIVE_FRAME (frame);
1786 CHECK_NUMBER (x);
1787 CHECK_NUMBER (y);
1789 /* I think this should be done with a hook. */
1790 #ifdef HAVE_WINDOW_SYSTEM
1791 if (FRAME_WINDOW_P (XFRAME (frame)))
1792 /* Warping the mouse will cause enternotify and focus events. */
1793 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1794 #else
1795 #if defined (MSDOS) && defined (HAVE_MOUSE)
1796 if (FRAME_MSDOS_P (XFRAME (frame)))
1798 Fselect_frame (frame);
1799 mouse_moveto (XINT (x), XINT (y));
1801 #else
1802 #ifdef HAVE_GPM
1804 Fselect_frame (frame);
1805 term_mouse_moveto (XINT (x), XINT (y));
1807 #endif
1808 #endif
1809 #endif
1811 return Qnil;
1814 static void make_frame_visible_1 P_ ((Lisp_Object));
1816 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1817 0, 1, "",
1818 doc: /* Make the frame FRAME visible (assuming it is an X window).
1819 If omitted, FRAME defaults to the currently selected frame. */)
1820 (frame)
1821 Lisp_Object frame;
1823 if (NILP (frame))
1824 frame = selected_frame;
1826 CHECK_LIVE_FRAME (frame);
1828 /* I think this should be done with a hook. */
1829 #ifdef HAVE_WINDOW_SYSTEM
1830 if (FRAME_WINDOW_P (XFRAME (frame)))
1832 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1833 x_make_frame_visible (XFRAME (frame));
1835 #endif
1837 make_frame_visible_1 (XFRAME (frame)->root_window);
1839 /* Make menu bar update for the Buffers and Frames menus. */
1840 windows_or_buffers_changed++;
1842 return frame;
1845 /* Update the display_time slot of the buffers shown in WINDOW
1846 and all its descendents. */
1848 static void
1849 make_frame_visible_1 (window)
1850 Lisp_Object window;
1852 struct window *w;
1854 for (;!NILP (window); window = w->next)
1856 w = XWINDOW (window);
1858 if (!NILP (w->buffer))
1859 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1861 if (!NILP (w->vchild))
1862 make_frame_visible_1 (w->vchild);
1863 if (!NILP (w->hchild))
1864 make_frame_visible_1 (w->hchild);
1868 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1869 0, 2, "",
1870 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1871 If omitted, FRAME defaults to the currently selected frame.
1872 Normally you may not make FRAME invisible if all other frames are invisible,
1873 but if the second optional argument FORCE is non-nil, you may do so. */)
1874 (frame, force)
1875 Lisp_Object frame, force;
1877 if (NILP (frame))
1878 frame = selected_frame;
1880 CHECK_LIVE_FRAME (frame);
1882 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1883 error ("Attempt to make invisible the sole visible or iconified frame");
1885 #if 0 /* This isn't logically necessary, and it can do GC. */
1886 /* Don't let the frame remain selected. */
1887 if (EQ (frame, selected_frame))
1888 do_switch_frame (next_frame (frame, Qt), 0, 0)
1889 #endif
1891 /* Don't allow minibuf_window to remain on a deleted frame. */
1892 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1894 struct frame *sf = XFRAME (selected_frame);
1895 Fset_window_buffer (sf->minibuffer_window,
1896 XWINDOW (minibuf_window)->buffer, Qnil);
1897 minibuf_window = sf->minibuffer_window;
1900 /* I think this should be done with a hook. */
1901 #ifdef HAVE_WINDOW_SYSTEM
1902 if (FRAME_WINDOW_P (XFRAME (frame)))
1903 x_make_frame_invisible (XFRAME (frame));
1904 #endif
1906 /* Make menu bar update for the Buffers and Frames menus. */
1907 windows_or_buffers_changed++;
1909 return Qnil;
1912 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1913 0, 1, "",
1914 doc: /* Make the frame FRAME into an icon.
1915 If omitted, FRAME defaults to the currently selected frame. */)
1916 (frame)
1917 Lisp_Object frame;
1919 if (NILP (frame))
1920 frame = selected_frame;
1922 CHECK_LIVE_FRAME (frame);
1924 #if 0 /* This isn't logically necessary, and it can do GC. */
1925 /* Don't let the frame remain selected. */
1926 if (EQ (frame, selected_frame))
1927 Fhandle_switch_frame (next_frame (frame, Qt));
1928 #endif
1930 /* Don't allow minibuf_window to remain on a deleted frame. */
1931 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1933 struct frame *sf = XFRAME (selected_frame);
1934 Fset_window_buffer (sf->minibuffer_window,
1935 XWINDOW (minibuf_window)->buffer, Qnil);
1936 minibuf_window = sf->minibuffer_window;
1939 /* I think this should be done with a hook. */
1940 #ifdef HAVE_WINDOW_SYSTEM
1941 if (FRAME_WINDOW_P (XFRAME (frame)))
1942 x_iconify_frame (XFRAME (frame));
1943 #endif
1945 /* Make menu bar update for the Buffers and Frames menus. */
1946 windows_or_buffers_changed++;
1948 return Qnil;
1951 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1952 1, 1, 0,
1953 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1954 A frame that is not \"visible\" is not updated and, if it works through
1955 a window system, it may not show at all.
1956 Return the symbol `icon' if frame is visible only as an icon.
1958 On a text-only terminal, all frames are considered visible, whether
1959 they are currently being displayed or not, and this function returns t
1960 for all frames. */)
1961 (frame)
1962 Lisp_Object frame;
1964 CHECK_LIVE_FRAME (frame);
1966 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1968 if (FRAME_VISIBLE_P (XFRAME (frame)))
1969 return Qt;
1970 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1971 return Qicon;
1972 return Qnil;
1975 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1976 0, 0, 0,
1977 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1980 Lisp_Object tail, frame;
1981 struct frame *f;
1982 Lisp_Object value;
1984 value = Qnil;
1985 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1987 frame = XCAR (tail);
1988 if (!FRAMEP (frame))
1989 continue;
1990 f = XFRAME (frame);
1991 if (FRAME_VISIBLE_P (f))
1992 value = Fcons (frame, value);
1994 return value;
1998 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1999 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2000 If FRAME is invisible or iconified, make it visible.
2001 If you don't specify a frame, the selected frame is used.
2002 If Emacs is displaying on an ordinary terminal or some other device which
2003 doesn't support multiple overlapping frames, this function does nothing. */)
2004 (frame)
2005 Lisp_Object frame;
2007 struct frame *f;
2008 if (NILP (frame))
2009 frame = selected_frame;
2011 CHECK_LIVE_FRAME (frame);
2013 f = XFRAME (frame);
2015 /* Do like the documentation says. */
2016 Fmake_frame_visible (frame);
2018 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2019 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2021 return Qnil;
2024 /* Should we have a corresponding function called Flower_Power? */
2025 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2026 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2027 If you don't specify a frame, the selected frame is used.
2028 If Emacs is displaying on an ordinary terminal or some other device which
2029 doesn't support multiple overlapping frames, this function does nothing. */)
2030 (frame)
2031 Lisp_Object frame;
2033 struct frame *f;
2035 if (NILP (frame))
2036 frame = selected_frame;
2038 CHECK_LIVE_FRAME (frame);
2040 f = XFRAME (frame);
2042 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2043 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2045 return Qnil;
2049 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2050 1, 2, 0,
2051 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2052 In other words, switch-frame events caused by events in FRAME will
2053 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2054 FOCUS-FRAME after reading an event typed at FRAME.
2056 If FOCUS-FRAME is omitted or nil, any existing redirection is
2057 cancelled, and the frame again receives its own keystrokes.
2059 Focus redirection is useful for temporarily redirecting keystrokes to
2060 a surrogate minibuffer frame when a frame doesn't have its own
2061 minibuffer window.
2063 A frame's focus redirection can be changed by `select-frame'. If frame
2064 FOO is selected, and then a different frame BAR is selected, any
2065 frames redirecting their focus to FOO are shifted to redirect their
2066 focus to BAR. This allows focus redirection to work properly when the
2067 user switches from one frame to another using `select-window'.
2069 This means that a frame whose focus is redirected to itself is treated
2070 differently from a frame whose focus is redirected to nil; the former
2071 is affected by `select-frame', while the latter is not.
2073 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2074 (frame, focus_frame)
2075 Lisp_Object frame, focus_frame;
2077 struct frame *f;
2079 /* Note that we don't check for a live frame here. It's reasonable
2080 to redirect the focus of a frame you're about to delete, if you
2081 know what other frame should receive those keystrokes. */
2082 CHECK_FRAME (frame);
2084 if (! NILP (focus_frame))
2085 CHECK_LIVE_FRAME (focus_frame);
2087 f = XFRAME (frame);
2089 f->focus_frame = focus_frame;
2091 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2092 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2094 return Qnil;
2098 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
2099 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2100 This returns nil if FRAME's focus is not redirected.
2101 See `redirect-frame-focus'. */)
2102 (frame)
2103 Lisp_Object frame;
2105 CHECK_LIVE_FRAME (frame);
2107 return FRAME_FOCUS_FRAME (XFRAME (frame));
2112 /* Return the value of frame parameter PROP in frame FRAME. */
2114 Lisp_Object
2115 get_frame_param (frame, prop)
2116 register struct frame *frame;
2117 Lisp_Object prop;
2119 register Lisp_Object tem;
2121 tem = Fassq (prop, frame->param_alist);
2122 if (EQ (tem, Qnil))
2123 return tem;
2124 return Fcdr (tem);
2127 /* Return the buffer-predicate of the selected frame. */
2129 Lisp_Object
2130 frame_buffer_predicate (frame)
2131 Lisp_Object frame;
2133 return XFRAME (frame)->buffer_predicate;
2136 /* Return the buffer-list of the selected frame. */
2138 Lisp_Object
2139 frame_buffer_list (frame)
2140 Lisp_Object frame;
2142 return XFRAME (frame)->buffer_list;
2145 /* Set the buffer-list of the selected frame. */
2147 void
2148 set_frame_buffer_list (frame, list)
2149 Lisp_Object frame, list;
2151 XFRAME (frame)->buffer_list = list;
2154 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2156 void
2157 frames_discard_buffer (buffer)
2158 Lisp_Object buffer;
2160 Lisp_Object frame, tail;
2162 FOR_EACH_FRAME (tail, frame)
2164 XFRAME (frame)->buffer_list
2165 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2166 XFRAME (frame)->buried_buffer_list
2167 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
2171 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2172 If the alist already has an element for PROP, we change it. */
2174 void
2175 store_in_alist (alistptr, prop, val)
2176 Lisp_Object *alistptr, val;
2177 Lisp_Object prop;
2179 register Lisp_Object tem;
2181 tem = Fassq (prop, *alistptr);
2182 if (EQ (tem, Qnil))
2183 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2184 else
2185 Fsetcdr (tem, val);
2188 static int
2189 frame_name_fnn_p (str, len)
2190 char *str;
2191 EMACS_INT len;
2193 if (len > 1 && str[0] == 'F')
2195 char *end_ptr;
2197 strtol (str + 1, &end_ptr, 10);
2199 if (end_ptr == str + len)
2200 return 1;
2202 return 0;
2205 /* Set the name of the terminal frame. Also used by MSDOS frames.
2206 Modeled after x_set_name which is used for WINDOW frames. */
2208 static void
2209 set_term_frame_name (f, name)
2210 struct frame *f;
2211 Lisp_Object name;
2213 f->explicit_name = ! NILP (name);
2215 /* If NAME is nil, set the name to F<num>. */
2216 if (NILP (name))
2218 char namebuf[20];
2220 /* Check for no change needed in this very common case
2221 before we do any consing. */
2222 if (frame_name_fnn_p (SDATA (f->name),
2223 SBYTES (f->name)))
2224 return;
2226 tty_frame_count++;
2227 sprintf (namebuf, "F%d", tty_frame_count);
2228 name = build_string (namebuf);
2230 else
2232 CHECK_STRING (name);
2234 /* Don't change the name if it's already NAME. */
2235 if (! NILP (Fstring_equal (name, f->name)))
2236 return;
2238 /* Don't allow the user to set the frame name to F<num>, so it
2239 doesn't clash with the names we generate for terminal frames. */
2240 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2241 error ("Frame names of the form F<num> are usurped by Emacs");
2244 f->name = name;
2245 update_mode_lines = 1;
2248 void
2249 store_frame_param (f, prop, val)
2250 struct frame *f;
2251 Lisp_Object prop, val;
2253 register Lisp_Object old_alist_elt;
2255 /* The buffer-list parameters are stored in a special place and not
2256 in the alist. */
2257 if (EQ (prop, Qbuffer_list))
2259 f->buffer_list = val;
2260 return;
2262 if (EQ (prop, Qburied_buffer_list))
2264 f->buried_buffer_list = val;
2265 return;
2268 /* If PROP is a symbol which is supposed to have frame-local values,
2269 and it is set up based on this frame, switch to the global
2270 binding. That way, we can create or alter the frame-local binding
2271 without messing up the symbol's status. */
2272 if (SYMBOLP (prop))
2274 Lisp_Object valcontents;
2275 valcontents = SYMBOL_VALUE (prop);
2276 if ((BUFFER_LOCAL_VALUEP (valcontents))
2277 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2278 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame
2279 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2280 swap_in_global_binding (prop);
2283 #ifndef WINDOWSNT
2284 /* The tty color needed to be set before the frame's parameter
2285 alist was updated with the new value. This is not true any more,
2286 but we still do this test early on. */
2287 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2288 && f == FRAME_TTY (f)->previous_frame)
2289 /* Force redisplay of this tty. */
2290 FRAME_TTY (f)->previous_frame = NULL;
2291 #endif
2293 /* Update the frame parameter alist. */
2294 old_alist_elt = Fassq (prop, f->param_alist);
2295 if (EQ (old_alist_elt, Qnil))
2296 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2297 else
2298 Fsetcdr (old_alist_elt, val);
2300 /* Update some other special parameters in their special places
2301 in addition to the alist. */
2303 if (EQ (prop, Qbuffer_predicate))
2304 f->buffer_predicate = val;
2306 if (! FRAME_WINDOW_P (f))
2308 if (EQ (prop, Qmenu_bar_lines))
2309 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2310 else if (EQ (prop, Qname))
2311 set_term_frame_name (f, val);
2314 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2316 if (! MINI_WINDOW_P (XWINDOW (val)))
2317 error ("Surrogate minibuffer windows must be minibuffer windows");
2319 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2320 && !EQ (val, f->minibuffer_window))
2321 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2323 /* Install the chosen minibuffer window, with proper buffer. */
2324 f->minibuffer_window = val;
2328 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2329 doc: /* Return the parameters-alist of frame FRAME.
2330 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2331 The meaningful PARMs depend on the kind of frame.
2332 If FRAME is omitted, return information on the currently selected frame. */)
2333 (frame)
2334 Lisp_Object frame;
2336 Lisp_Object alist;
2337 FRAME_PTR f;
2338 int height, width;
2339 struct gcpro gcpro1;
2341 if (NILP (frame))
2342 frame = selected_frame;
2344 CHECK_FRAME (frame);
2345 f = XFRAME (frame);
2347 if (!FRAME_LIVE_P (f))
2348 return Qnil;
2350 alist = Fcopy_alist (f->param_alist);
2351 GCPRO1 (alist);
2353 if (!FRAME_WINDOW_P (f))
2355 int fg = FRAME_FOREGROUND_PIXEL (f);
2356 int bg = FRAME_BACKGROUND_PIXEL (f);
2357 Lisp_Object elt;
2359 /* If the frame's parameter alist says the colors are
2360 unspecified and reversed, take the frame's background pixel
2361 for foreground and vice versa. */
2362 elt = Fassq (Qforeground_color, alist);
2363 if (CONSP (elt) && STRINGP (XCDR (elt)))
2365 if (strncmp (SDATA (XCDR (elt)),
2366 unspecified_bg,
2367 SCHARS (XCDR (elt))) == 0)
2368 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2369 else if (strncmp (SDATA (XCDR (elt)),
2370 unspecified_fg,
2371 SCHARS (XCDR (elt))) == 0)
2372 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2374 else
2375 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2376 elt = Fassq (Qbackground_color, alist);
2377 if (CONSP (elt) && STRINGP (XCDR (elt)))
2379 if (strncmp (SDATA (XCDR (elt)),
2380 unspecified_fg,
2381 SCHARS (XCDR (elt))) == 0)
2382 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2383 else if (strncmp (SDATA (XCDR (elt)),
2384 unspecified_bg,
2385 SCHARS (XCDR (elt))) == 0)
2386 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2388 else
2389 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2390 store_in_alist (&alist, intern ("font"),
2391 build_string (FRAME_MSDOS_P (f)
2392 ? "ms-dos"
2393 : FRAME_W32_P (f) ? "w32term"
2394 :"tty"));
2396 store_in_alist (&alist, Qname, f->name);
2397 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2398 store_in_alist (&alist, Qheight, make_number (height));
2399 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2400 store_in_alist (&alist, Qwidth, make_number (width));
2401 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2402 store_in_alist (&alist, Qminibuffer,
2403 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2404 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2405 : FRAME_MINIBUF_WINDOW (f)));
2406 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2407 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2408 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2410 /* I think this should be done with a hook. */
2411 #ifdef HAVE_WINDOW_SYSTEM
2412 if (FRAME_WINDOW_P (f))
2413 x_report_frame_params (f, &alist);
2414 else
2415 #endif
2417 /* This ought to be correct in f->param_alist for an X frame. */
2418 Lisp_Object lines;
2419 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2420 store_in_alist (&alist, Qmenu_bar_lines, lines);
2423 UNGCPRO;
2424 return alist;
2428 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2429 doc: /* Return FRAME's value for parameter PARAMETER.
2430 If FRAME is nil, describe the currently selected frame. */)
2431 (frame, parameter)
2432 Lisp_Object frame, parameter;
2434 struct frame *f;
2435 Lisp_Object value;
2437 if (NILP (frame))
2438 frame = selected_frame;
2439 else
2440 CHECK_FRAME (frame);
2441 CHECK_SYMBOL (parameter);
2443 f = XFRAME (frame);
2444 value = Qnil;
2446 if (FRAME_LIVE_P (f))
2448 /* Avoid consing in frequent cases. */
2449 if (EQ (parameter, Qname))
2450 value = f->name;
2451 #ifdef HAVE_X_WINDOWS
2452 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2453 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2454 #endif /* HAVE_X_WINDOWS */
2455 else if (EQ (parameter, Qbackground_color)
2456 || EQ (parameter, Qforeground_color))
2458 value = Fassq (parameter, f->param_alist);
2459 if (CONSP (value))
2461 value = XCDR (value);
2462 /* Fframe_parameters puts the actual fg/bg color names,
2463 even if f->param_alist says otherwise. This is
2464 important when param_alist's notion of colors is
2465 "unspecified". We need to do the same here. */
2466 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2468 const char *color_name;
2469 EMACS_INT csz;
2471 if (EQ (parameter, Qbackground_color))
2473 color_name = SDATA (value);
2474 csz = SCHARS (value);
2475 if (strncmp (color_name, unspecified_bg, csz) == 0)
2476 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2477 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2478 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2480 else if (EQ (parameter, Qforeground_color))
2482 color_name = SDATA (value);
2483 csz = SCHARS (value);
2484 if (strncmp (color_name, unspecified_fg, csz) == 0)
2485 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2486 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2487 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2491 else
2492 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2494 else if (EQ (parameter, Qdisplay_type)
2495 || EQ (parameter, Qbackground_mode))
2496 value = Fcdr (Fassq (parameter, f->param_alist));
2497 else
2498 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2501 return value;
2505 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2506 Smodify_frame_parameters, 2, 2, 0,
2507 doc: /* Modify the parameters of frame FRAME according to ALIST.
2508 If FRAME is nil, it defaults to the selected frame.
2509 ALIST is an alist of parameters to change and their new values.
2510 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2511 The meaningful PARMs depend on the kind of frame.
2512 Undefined PARMs are ignored, but stored in the frame's parameter list
2513 so that `frame-parameters' will return them.
2515 The value of frame parameter FOO can also be accessed
2516 as a frame-local binding for the variable FOO, if you have
2517 enabled such bindings for that variable with `make-variable-frame-local'. */)
2518 (frame, alist)
2519 Lisp_Object frame, alist;
2521 FRAME_PTR f;
2522 register Lisp_Object tail, prop, val;
2524 if (EQ (frame, Qnil))
2525 frame = selected_frame;
2526 CHECK_LIVE_FRAME (frame);
2527 f = XFRAME (frame);
2529 /* I think this should be done with a hook. */
2530 #ifdef HAVE_WINDOW_SYSTEM
2531 if (FRAME_WINDOW_P (f))
2532 x_set_frame_parameters (f, alist);
2533 else
2534 #endif
2535 #ifdef MSDOS
2536 if (FRAME_MSDOS_P (f))
2537 IT_set_frame_parameters (f, alist);
2538 else
2539 #endif
2542 int length = XINT (Flength (alist));
2543 int i;
2544 Lisp_Object *parms
2545 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2546 Lisp_Object *values
2547 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2549 /* Extract parm names and values into those vectors. */
2551 i = 0;
2552 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2554 Lisp_Object elt;
2556 elt = XCAR (tail);
2557 parms[i] = Fcar (elt);
2558 values[i] = Fcdr (elt);
2559 i++;
2562 /* Now process them in reverse of specified order. */
2563 for (i--; i >= 0; i--)
2565 prop = parms[i];
2566 val = values[i];
2567 store_frame_param (f, prop, val);
2569 /* Changing the background color might change the background
2570 mode, so that we have to load new defface specs.
2571 Call frame-set-background-mode to do that. */
2572 if (EQ (prop, Qbackground_color))
2573 call1 (Qframe_set_background_mode, frame);
2576 return Qnil;
2579 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2580 0, 1, 0,
2581 doc: /* Height in pixels of a line in the font in frame FRAME.
2582 If FRAME is omitted, the selected frame is used.
2583 For a terminal frame, the value is always 1. */)
2584 (frame)
2585 Lisp_Object frame;
2587 struct frame *f;
2589 if (NILP (frame))
2590 frame = selected_frame;
2591 CHECK_FRAME (frame);
2592 f = XFRAME (frame);
2594 #ifdef HAVE_WINDOW_SYSTEM
2595 if (FRAME_WINDOW_P (f))
2596 return make_number (x_char_height (f));
2597 else
2598 #endif
2599 return make_number (1);
2603 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2604 0, 1, 0,
2605 doc: /* Width in pixels of characters in the font in frame FRAME.
2606 If FRAME is omitted, the selected frame is used.
2607 On a graphical screen, the width is the standard width of the default font.
2608 For a terminal screen, the value is always 1. */)
2609 (frame)
2610 Lisp_Object frame;
2612 struct frame *f;
2614 if (NILP (frame))
2615 frame = selected_frame;
2616 CHECK_FRAME (frame);
2617 f = XFRAME (frame);
2619 #ifdef HAVE_WINDOW_SYSTEM
2620 if (FRAME_WINDOW_P (f))
2621 return make_number (x_char_width (f));
2622 else
2623 #endif
2624 return make_number (1);
2627 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2628 Sframe_pixel_height, 0, 1, 0,
2629 doc: /* Return a FRAME's height in pixels.
2630 This counts only the height available for text lines,
2631 not menu bars on window-system Emacs frames.
2632 For a terminal frame, the result really gives the height in characters.
2633 If FRAME is omitted, the selected frame is used. */)
2634 (frame)
2635 Lisp_Object frame;
2637 struct frame *f;
2639 if (NILP (frame))
2640 frame = selected_frame;
2641 CHECK_FRAME (frame);
2642 f = XFRAME (frame);
2644 #ifdef HAVE_WINDOW_SYSTEM
2645 if (FRAME_WINDOW_P (f))
2646 return make_number (x_pixel_height (f));
2647 else
2648 #endif
2649 return make_number (FRAME_LINES (f));
2652 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2653 Sframe_pixel_width, 0, 1, 0,
2654 doc: /* Return FRAME's width in pixels.
2655 For a terminal frame, the result really gives the width in characters.
2656 If FRAME is omitted, the selected frame is used. */)
2657 (frame)
2658 Lisp_Object frame;
2660 struct frame *f;
2662 if (NILP (frame))
2663 frame = selected_frame;
2664 CHECK_FRAME (frame);
2665 f = XFRAME (frame);
2667 #ifdef HAVE_WINDOW_SYSTEM
2668 if (FRAME_WINDOW_P (f))
2669 return make_number (x_pixel_width (f));
2670 else
2671 #endif
2672 return make_number (FRAME_COLS (f));
2675 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2676 doc: /* Specify that the frame FRAME has LINES lines.
2677 Optional third arg non-nil means that redisplay should use LINES lines
2678 but that the idea of the actual height of the frame should not be changed. */)
2679 (frame, lines, pretend)
2680 Lisp_Object frame, lines, pretend;
2682 register struct frame *f;
2684 CHECK_NUMBER (lines);
2685 if (NILP (frame))
2686 frame = selected_frame;
2687 CHECK_LIVE_FRAME (frame);
2688 f = XFRAME (frame);
2690 /* I think this should be done with a hook. */
2691 #ifdef HAVE_WINDOW_SYSTEM
2692 if (FRAME_WINDOW_P (f))
2694 if (XINT (lines) != FRAME_LINES (f))
2695 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2696 do_pending_window_change (0);
2698 else
2699 #endif
2700 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2701 return Qnil;
2704 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2705 doc: /* Specify that the frame FRAME has COLS columns.
2706 Optional third arg non-nil means that redisplay should use COLS columns
2707 but that the idea of the actual width of the frame should not be changed. */)
2708 (frame, cols, pretend)
2709 Lisp_Object frame, cols, pretend;
2711 register struct frame *f;
2712 CHECK_NUMBER (cols);
2713 if (NILP (frame))
2714 frame = selected_frame;
2715 CHECK_LIVE_FRAME (frame);
2716 f = XFRAME (frame);
2718 /* I think this should be done with a hook. */
2719 #ifdef HAVE_WINDOW_SYSTEM
2720 if (FRAME_WINDOW_P (f))
2722 if (XINT (cols) != FRAME_COLS (f))
2723 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2724 do_pending_window_change (0);
2726 else
2727 #endif
2728 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2729 return Qnil;
2732 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2733 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2734 (frame, cols, rows)
2735 Lisp_Object frame, cols, rows;
2737 register struct frame *f;
2739 CHECK_LIVE_FRAME (frame);
2740 CHECK_NUMBER (cols);
2741 CHECK_NUMBER (rows);
2742 f = XFRAME (frame);
2744 /* I think this should be done with a hook. */
2745 #ifdef HAVE_WINDOW_SYSTEM
2746 if (FRAME_WINDOW_P (f))
2748 if (XINT (rows) != FRAME_LINES (f)
2749 || XINT (cols) != FRAME_COLS (f)
2750 || f->new_text_lines || f->new_text_cols)
2751 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2752 do_pending_window_change (0);
2754 else
2755 #endif
2756 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2758 return Qnil;
2761 DEFUN ("set-frame-position", Fset_frame_position,
2762 Sset_frame_position, 3, 3, 0,
2763 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2764 This is actually the position of the upper left corner of the frame.
2765 Negative values for XOFFSET or YOFFSET are interpreted relative to
2766 the rightmost or bottommost possible position (that stays within the screen). */)
2767 (frame, xoffset, yoffset)
2768 Lisp_Object frame, xoffset, yoffset;
2770 register struct frame *f;
2772 CHECK_LIVE_FRAME (frame);
2773 CHECK_NUMBER (xoffset);
2774 CHECK_NUMBER (yoffset);
2775 f = XFRAME (frame);
2777 /* I think this should be done with a hook. */
2778 #ifdef HAVE_WINDOW_SYSTEM
2779 if (FRAME_WINDOW_P (f))
2780 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2781 #endif
2783 return Qt;
2787 /***********************************************************************
2788 Frame Parameters
2789 ***********************************************************************/
2791 /* Connect the frame-parameter names for X frames
2792 to the ways of passing the parameter values to the window system.
2794 The name of a parameter, as a Lisp symbol,
2795 has an `x-frame-parameter' property which is an integer in Lisp
2796 that is an index in this table. */
2798 struct frame_parm_table {
2799 char *name;
2800 Lisp_Object *variable;
2803 static struct frame_parm_table frame_parms[] =
2805 {"auto-raise", &Qauto_raise},
2806 {"auto-lower", &Qauto_lower},
2807 {"background-color", 0},
2808 {"border-color", &Qborder_color},
2809 {"border-width", &Qborder_width},
2810 {"cursor-color", &Qcursor_color},
2811 {"cursor-type", &Qcursor_type},
2812 {"font", 0},
2813 {"foreground-color", 0},
2814 {"icon-name", &Qicon_name},
2815 {"icon-type", &Qicon_type},
2816 {"internal-border-width", &Qinternal_border_width},
2817 {"menu-bar-lines", &Qmenu_bar_lines},
2818 {"mouse-color", &Qmouse_color},
2819 {"name", &Qname},
2820 {"scroll-bar-width", &Qscroll_bar_width},
2821 {"title", &Qtitle},
2822 {"unsplittable", &Qunsplittable},
2823 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2824 {"visibility", &Qvisibility},
2825 {"tool-bar-lines", &Qtool_bar_lines},
2826 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2827 {"scroll-bar-background", &Qscroll_bar_background},
2828 {"screen-gamma", &Qscreen_gamma},
2829 {"line-spacing", &Qline_spacing},
2830 {"left-fringe", &Qleft_fringe},
2831 {"right-fringe", &Qright_fringe},
2832 {"wait-for-wm", &Qwait_for_wm},
2833 {"fullscreen", &Qfullscreen},
2834 {"font-backend", &Qfont_backend},
2835 {"alpha", &Qalpha}
2838 #ifdef HAVE_WINDOW_SYSTEM
2840 extern Lisp_Object Qbox;
2841 extern Lisp_Object Qtop;
2843 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2844 wanted positions of the WM window (not Emacs window).
2845 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2846 window (FRAME_X_WINDOW).
2849 void
2850 x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2851 struct frame *f;
2852 int *width;
2853 int *height;
2854 int *top_pos;
2855 int *left_pos;
2857 int newwidth = FRAME_COLS (f);
2858 int newheight = FRAME_LINES (f);
2860 *top_pos = f->top_pos;
2861 *left_pos = f->left_pos;
2863 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2865 int ph;
2867 ph = FRAME_X_DISPLAY_INFO (f)->height;
2868 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2869 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2870 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2871 *top_pos = 0;
2874 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2876 int pw;
2878 pw = FRAME_X_DISPLAY_INFO (f)->width;
2879 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2880 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2881 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2882 *left_pos = 0;
2885 *width = newwidth;
2886 *height = newheight;
2890 /* Change the parameters of frame F as specified by ALIST.
2891 If a parameter is not specially recognized, do nothing special;
2892 otherwise call the `x_set_...' function for that parameter.
2893 Except for certain geometry properties, always call store_frame_param
2894 to store the new value in the parameter alist. */
2896 void
2897 x_set_frame_parameters (f, alist)
2898 FRAME_PTR f;
2899 Lisp_Object alist;
2901 Lisp_Object tail;
2903 /* If both of these parameters are present, it's more efficient to
2904 set them both at once. So we wait until we've looked at the
2905 entire list before we set them. */
2906 int width, height;
2908 /* Same here. */
2909 Lisp_Object left, top;
2911 /* Same with these. */
2912 Lisp_Object icon_left, icon_top;
2914 /* Record in these vectors all the parms specified. */
2915 Lisp_Object *parms;
2916 Lisp_Object *values;
2917 int i, p;
2918 int left_no_change = 0, top_no_change = 0;
2919 int icon_left_no_change = 0, icon_top_no_change = 0;
2920 int fullscreen_is_being_set = 0;
2922 struct gcpro gcpro1, gcpro2;
2924 i = 0;
2925 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2926 i++;
2928 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2929 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2931 /* Extract parm names and values into those vectors. */
2933 i = 0;
2934 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2936 Lisp_Object elt;
2938 elt = XCAR (tail);
2939 parms[i] = Fcar (elt);
2940 values[i] = Fcdr (elt);
2941 i++;
2943 /* TAIL and ALIST are not used again below here. */
2944 alist = tail = Qnil;
2946 GCPRO2 (*parms, *values);
2947 gcpro1.nvars = i;
2948 gcpro2.nvars = i;
2950 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2951 because their values appear in VALUES and strings are not valid. */
2952 top = left = Qunbound;
2953 icon_left = icon_top = Qunbound;
2955 /* Provide default values for HEIGHT and WIDTH. */
2956 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2957 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2959 /* Process foreground_color and background_color before anything else.
2960 They are independent of other properties, but other properties (e.g.,
2961 cursor_color) are dependent upon them. */
2962 /* Process default font as well, since fringe widths depends on it. */
2963 /* Also, process fullscreen, width and height depend upon that */
2964 for (p = 0; p < i; p++)
2966 Lisp_Object prop, val;
2968 prop = parms[p];
2969 val = values[p];
2970 if (EQ (prop, Qforeground_color)
2971 || EQ (prop, Qbackground_color)
2972 || EQ (prop, Qfont)
2973 || EQ (prop, Qfullscreen))
2975 register Lisp_Object param_index, old_value;
2976 int count = SPECPDL_INDEX ();
2978 old_value = get_frame_param (f, prop);
2979 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
2981 if (NILP (Fequal (val, old_value)))
2983 /* For :font attributes, the frame_parm_handler
2984 x_set_font calls `face-set-after-frame-default'.
2985 Unless we bind inhibit-face-set-after-frame-default
2986 here, this would reset the :font attribute that we
2987 just applied to the default value for new faces. */
2988 specbind (Qinhibit_face_set_after_frame_default, Qt);
2990 store_frame_param (f, prop, val);
2992 param_index = Fget (prop, Qx_frame_parameter);
2993 if (NATNUMP (param_index)
2994 && (XFASTINT (param_index)
2995 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2996 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2997 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2998 unbind_to (count, Qnil);
3003 /* Now process them in reverse of specified order. */
3004 for (i--; i >= 0; i--)
3006 Lisp_Object prop, val;
3008 prop = parms[i];
3009 val = values[i];
3011 if (EQ (prop, Qwidth) && NATNUMP (val))
3012 width = XFASTINT (val);
3013 else if (EQ (prop, Qheight) && NATNUMP (val))
3014 height = XFASTINT (val);
3015 else if (EQ (prop, Qtop))
3016 top = val;
3017 else if (EQ (prop, Qleft))
3018 left = val;
3019 else if (EQ (prop, Qicon_top))
3020 icon_top = val;
3021 else if (EQ (prop, Qicon_left))
3022 icon_left = val;
3023 else if (EQ (prop, Qforeground_color)
3024 || EQ (prop, Qbackground_color)
3025 || EQ (prop, Qfont)
3026 || EQ (prop, Qfullscreen))
3027 /* Processed above. */
3028 continue;
3029 else
3031 register Lisp_Object param_index, old_value;
3033 old_value = get_frame_param (f, prop);
3035 store_frame_param (f, prop, val);
3037 param_index = Fget (prop, Qx_frame_parameter);
3038 if (NATNUMP (param_index)
3039 && (XFASTINT (param_index)
3040 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3041 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3042 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3046 /* Don't die if just one of these was set. */
3047 if (EQ (left, Qunbound))
3049 left_no_change = 1;
3050 if (f->left_pos < 0)
3051 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
3052 else
3053 XSETINT (left, f->left_pos);
3055 if (EQ (top, Qunbound))
3057 top_no_change = 1;
3058 if (f->top_pos < 0)
3059 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
3060 else
3061 XSETINT (top, f->top_pos);
3064 /* If one of the icon positions was not set, preserve or default it. */
3065 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
3067 icon_left_no_change = 1;
3068 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3069 if (NILP (icon_left))
3070 XSETINT (icon_left, 0);
3072 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
3074 icon_top_no_change = 1;
3075 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3076 if (NILP (icon_top))
3077 XSETINT (icon_top, 0);
3080 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
3082 /* If the frame is visible already and the fullscreen parameter is
3083 being set, it is too late to set WM manager hints to specify
3084 size and position.
3085 Here we first get the width, height and position that applies to
3086 fullscreen. We then move the frame to the appropriate
3087 position. Resize of the frame is taken care of in the code after
3088 this if-statement. */
3089 int new_left, new_top;
3091 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
3092 if (new_top != f->top_pos || new_left != f->left_pos)
3093 x_set_offset (f, new_left, new_top, 1);
3096 /* Don't set these parameters unless they've been explicitly
3097 specified. The window might be mapped or resized while we're in
3098 this function, and we don't want to override that unless the lisp
3099 code has asked for it.
3101 Don't set these parameters unless they actually differ from the
3102 window's current parameters; the window may not actually exist
3103 yet. */
3105 Lisp_Object frame;
3107 check_frame_size (f, &height, &width);
3109 XSETFRAME (frame, f);
3111 if (width != FRAME_COLS (f)
3112 || height != FRAME_LINES (f)
3113 || f->new_text_lines || f->new_text_cols)
3114 Fset_frame_size (frame, make_number (width), make_number (height));
3116 if ((!NILP (left) || !NILP (top))
3117 && ! (left_no_change && top_no_change)
3118 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3119 && NUMBERP (top) && XINT (top) == f->top_pos))
3121 int leftpos = 0;
3122 int toppos = 0;
3124 /* Record the signs. */
3125 f->size_hint_flags &= ~ (XNegative | YNegative);
3126 if (EQ (left, Qminus))
3127 f->size_hint_flags |= XNegative;
3128 else if (INTEGERP (left))
3130 leftpos = XINT (left);
3131 if (leftpos < 0)
3132 f->size_hint_flags |= XNegative;
3134 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3135 && CONSP (XCDR (left))
3136 && INTEGERP (XCAR (XCDR (left))))
3138 leftpos = - XINT (XCAR (XCDR (left)));
3139 f->size_hint_flags |= XNegative;
3141 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3142 && CONSP (XCDR (left))
3143 && INTEGERP (XCAR (XCDR (left))))
3145 leftpos = XINT (XCAR (XCDR (left)));
3148 if (EQ (top, Qminus))
3149 f->size_hint_flags |= YNegative;
3150 else if (INTEGERP (top))
3152 toppos = XINT (top);
3153 if (toppos < 0)
3154 f->size_hint_flags |= YNegative;
3156 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3157 && CONSP (XCDR (top))
3158 && INTEGERP (XCAR (XCDR (top))))
3160 toppos = - XINT (XCAR (XCDR (top)));
3161 f->size_hint_flags |= YNegative;
3163 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3164 && CONSP (XCDR (top))
3165 && INTEGERP (XCAR (XCDR (top))))
3167 toppos = XINT (XCAR (XCDR (top)));
3171 /* Store the numeric value of the position. */
3172 f->top_pos = toppos;
3173 f->left_pos = leftpos;
3175 f->win_gravity = NorthWestGravity;
3177 /* Actually set that position, and convert to absolute. */
3178 x_set_offset (f, leftpos, toppos, -1);
3181 if ((!NILP (icon_left) || !NILP (icon_top))
3182 && ! (icon_left_no_change && icon_top_no_change))
3183 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3186 UNGCPRO;
3190 /* Insert a description of internally-recorded parameters of frame X
3191 into the parameter alist *ALISTPTR that is to be given to the user.
3192 Only parameters that are specific to the X window system
3193 and whose values are not correctly recorded in the frame's
3194 param_alist need to be considered here. */
3196 void
3197 x_report_frame_params (f, alistptr)
3198 struct frame *f;
3199 Lisp_Object *alistptr;
3201 char buf[16];
3202 Lisp_Object tem;
3204 /* Represent negative positions (off the top or left screen edge)
3205 in a way that Fmodify_frame_parameters will understand correctly. */
3206 XSETINT (tem, f->left_pos);
3207 if (f->left_pos >= 0)
3208 store_in_alist (alistptr, Qleft, tem);
3209 else
3210 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3212 XSETINT (tem, f->top_pos);
3213 if (f->top_pos >= 0)
3214 store_in_alist (alistptr, Qtop, tem);
3215 else
3216 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3218 store_in_alist (alistptr, Qborder_width,
3219 make_number (f->border_width));
3220 store_in_alist (alistptr, Qinternal_border_width,
3221 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3222 store_in_alist (alistptr, Qleft_fringe,
3223 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3224 store_in_alist (alistptr, Qright_fringe,
3225 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3226 store_in_alist (alistptr, Qscroll_bar_width,
3227 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3228 ? make_number (0)
3229 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3230 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3231 /* nil means "use default width"
3232 for non-toolkit scroll bar.
3233 ruler-mode.el depends on this. */
3234 : Qnil));
3235 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3236 store_in_alist (alistptr, Qwindow_id,
3237 build_string (buf));
3238 #ifdef HAVE_X_WINDOWS
3239 #ifdef USE_X_TOOLKIT
3240 /* Tooltip frame may not have this widget. */
3241 if (FRAME_X_OUTPUT (f)->widget)
3242 #endif
3243 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3244 store_in_alist (alistptr, Qouter_window_id,
3245 build_string (buf));
3246 #endif
3247 store_in_alist (alistptr, Qicon_name, f->icon_name);
3248 FRAME_SAMPLE_VISIBILITY (f);
3249 store_in_alist (alistptr, Qvisibility,
3250 (FRAME_VISIBLE_P (f) ? Qt
3251 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3252 store_in_alist (alistptr, Qdisplay,
3253 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3255 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3256 tem = Qnil;
3257 else
3258 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3259 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3260 store_in_alist (alistptr, Qparent_id, tem);
3264 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3265 the previous value of that parameter, NEW_VALUE is the new value. */
3267 void
3268 x_set_fullscreen (f, new_value, old_value)
3269 struct frame *f;
3270 Lisp_Object new_value, old_value;
3272 if (NILP (new_value))
3273 f->want_fullscreen = FULLSCREEN_NONE;
3274 else if (EQ (new_value, Qfullboth))
3275 f->want_fullscreen = FULLSCREEN_BOTH;
3276 else if (EQ (new_value, Qfullwidth))
3277 f->want_fullscreen = FULLSCREEN_WIDTH;
3278 else if (EQ (new_value, Qfullheight))
3279 f->want_fullscreen = FULLSCREEN_HEIGHT;
3281 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3282 FRAME_TERMINAL (f)->fullscreen_hook (f);
3286 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3287 the previous value of that parameter, NEW_VALUE is the new value. */
3289 void
3290 x_set_line_spacing (f, new_value, old_value)
3291 struct frame *f;
3292 Lisp_Object new_value, old_value;
3294 if (NILP (new_value))
3295 f->extra_line_spacing = 0;
3296 else if (NATNUMP (new_value))
3297 f->extra_line_spacing = XFASTINT (new_value);
3298 else
3299 signal_error ("Invalid line-spacing", new_value);
3300 if (FRAME_VISIBLE_P (f))
3301 redraw_frame (f);
3305 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3306 the previous value of that parameter, NEW_VALUE is the new value. */
3308 void
3309 x_set_screen_gamma (f, new_value, old_value)
3310 struct frame *f;
3311 Lisp_Object new_value, old_value;
3313 Lisp_Object bgcolor;
3315 if (NILP (new_value))
3316 f->gamma = 0;
3317 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3318 /* The value 0.4545 is the normal viewing gamma. */
3319 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3320 else
3321 signal_error ("Invalid screen-gamma", new_value);
3323 /* Apply the new gamma value to the frame background. */
3324 bgcolor = Fassq (Qbackground_color, f->param_alist);
3325 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3327 Lisp_Object index = Fget (Qbackground_color, Qx_frame_parameter);
3328 if (NATNUMP (index)
3329 && (XFASTINT (index)
3330 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3331 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3332 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3333 (f, bgcolor, Qnil);
3336 Fclear_face_cache (Qnil);
3340 void
3341 x_set_font (f, arg, oldval)
3342 struct frame *f;
3343 Lisp_Object arg, oldval;
3345 Lisp_Object frame;
3346 int fontset = -1;
3347 Lisp_Object font_object;
3349 /* Set the frame parameter back to the old value because we mail
3350 fail to use ARG as the new parameter value. */
3351 store_frame_param (f, Qfont, oldval);
3353 /* ARG is a fontset name, a font name, or a font object.
3354 In the last case, this function never fail. */
3355 if (STRINGP (arg))
3357 fontset = fs_query_fontset (arg, 0);
3358 if (fontset < 0)
3360 font_object = font_open_by_name (f, SDATA (arg));
3361 if (NILP (font_object))
3362 error ("Font `%s' is not defined", SDATA (arg));
3363 arg = AREF (font_object, FONT_NAME_INDEX);
3365 else if (fontset > 0)
3367 Lisp_Object ascii_font = fontset_ascii (fontset);
3369 font_object = font_open_by_name (f, SDATA (ascii_font));
3370 if (NILP (font_object))
3371 error ("Font `%s' is not defined", SDATA (arg));
3372 arg = fontset_name (fontset);
3374 else
3375 error ("The default fontset can't be used for a frame font");
3377 else if (FONT_OBJECT_P (arg))
3379 font_object = arg;
3380 /* This is store the XLFD font name in the frame parameter for
3381 backward compatiblity. We should store the font-object
3382 itself in the future. */
3383 arg = AREF (font_object, FONT_NAME_INDEX);
3385 else
3386 signal_error ("Invalid font", arg);
3388 if (! NILP (Fequal (font_object, oldval)))
3389 return;
3390 x_new_font (f, font_object, fontset);
3391 store_frame_param (f, Qfont, arg);
3392 /* Recalculate toolbar height. */
3393 f->n_tool_bar_rows = 0;
3394 /* Ensure we redraw it. */
3395 clear_current_matrices (f);
3397 recompute_basic_faces (f);
3399 do_pending_window_change (0);
3401 /* Don't call `face-set-after-frame-default' when faces haven't been
3402 initialized yet. This is the case when called from
3403 Fx_create_frame. In that case, the X widget or window doesn't
3404 exist either, and we can end up in x_report_frame_params with a
3405 null widget which gives a segfault. */
3406 if (FRAME_FACE_CACHE (f))
3408 XSETFRAME (frame, f);
3409 call1 (Qface_set_after_frame_default, frame);
3414 void
3415 x_set_font_backend (f, new_value, old_value)
3416 struct frame *f;
3417 Lisp_Object new_value, old_value;
3419 if (! NILP (new_value)
3420 && !CONSP (new_value))
3422 char *p0, *p1;
3424 CHECK_STRING (new_value);
3425 p0 = p1 = SDATA (new_value);
3426 new_value = Qnil;
3427 while (*p0)
3429 while (*p1 && *p1 != ',') p1++;
3430 if (p0 < p1)
3431 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3432 new_value);
3433 if (*p1)
3434 p1++;
3435 p0 = p1;
3437 new_value = Fnreverse (new_value);
3440 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3441 return;
3443 if (FRAME_FONT (f))
3444 free_all_realized_faces (Qnil);
3446 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3447 if (NILP (new_value))
3449 if (NILP (old_value))
3450 error ("No font backend available");
3451 font_update_drivers (f, old_value);
3452 error ("None of specified font backends are available");
3454 store_frame_param (f, Qfont_backend, new_value);
3456 if (FRAME_FONT (f))
3458 Lisp_Object frame;
3460 XSETFRAME (frame, f);
3461 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3462 ++face_change_count;
3463 ++windows_or_buffers_changed;
3468 void
3469 x_set_fringe_width (f, new_value, old_value)
3470 struct frame *f;
3471 Lisp_Object new_value, old_value;
3473 compute_fringe_widths (f, 1);
3476 void
3477 x_set_border_width (f, arg, oldval)
3478 struct frame *f;
3479 Lisp_Object arg, oldval;
3481 CHECK_NUMBER (arg);
3483 if (XINT (arg) == f->border_width)
3484 return;
3486 if (FRAME_X_WINDOW (f) != 0)
3487 error ("Cannot change the border width of a frame");
3489 f->border_width = XINT (arg);
3492 void
3493 x_set_internal_border_width (f, arg, oldval)
3494 struct frame *f;
3495 Lisp_Object arg, oldval;
3497 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3499 CHECK_NUMBER (arg);
3500 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3501 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3502 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3504 #ifdef USE_X_TOOLKIT
3505 if (FRAME_X_OUTPUT (f)->edit_widget)
3506 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3507 #endif
3509 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3510 return;
3512 if (FRAME_X_WINDOW (f) != 0)
3514 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3515 SET_FRAME_GARBAGED (f);
3516 do_pending_window_change (0);
3518 else
3519 SET_FRAME_GARBAGED (f);
3522 void
3523 x_set_visibility (f, value, oldval)
3524 struct frame *f;
3525 Lisp_Object value, oldval;
3527 Lisp_Object frame;
3528 XSETFRAME (frame, f);
3530 if (NILP (value))
3531 Fmake_frame_invisible (frame, Qt);
3532 else if (EQ (value, Qicon))
3533 Ficonify_frame (frame);
3534 else
3535 Fmake_frame_visible (frame);
3538 void
3539 x_set_autoraise (f, arg, oldval)
3540 struct frame *f;
3541 Lisp_Object arg, oldval;
3543 f->auto_raise = !EQ (Qnil, arg);
3546 void
3547 x_set_autolower (f, arg, oldval)
3548 struct frame *f;
3549 Lisp_Object arg, oldval;
3551 f->auto_lower = !EQ (Qnil, arg);
3554 void
3555 x_set_unsplittable (f, arg, oldval)
3556 struct frame *f;
3557 Lisp_Object arg, oldval;
3559 f->no_split = !NILP (arg);
3562 void
3563 x_set_vertical_scroll_bars (f, arg, oldval)
3564 struct frame *f;
3565 Lisp_Object arg, oldval;
3567 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3568 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3569 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3570 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3572 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3573 = (NILP (arg)
3574 ? vertical_scroll_bar_none
3575 : EQ (Qleft, arg)
3576 ? vertical_scroll_bar_left
3577 : EQ (Qright, arg)
3578 ? vertical_scroll_bar_right
3579 : EQ (Qleft, Vdefault_frame_scroll_bars)
3580 ? vertical_scroll_bar_left
3581 : EQ (Qright, Vdefault_frame_scroll_bars)
3582 ? vertical_scroll_bar_right
3583 : vertical_scroll_bar_none);
3585 /* We set this parameter before creating the X window for the
3586 frame, so we can get the geometry right from the start.
3587 However, if the window hasn't been created yet, we shouldn't
3588 call x_set_window_size. */
3589 if (FRAME_X_WINDOW (f))
3590 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3591 do_pending_window_change (0);
3595 void
3596 x_set_scroll_bar_width (f, arg, oldval)
3597 struct frame *f;
3598 Lisp_Object arg, oldval;
3600 int wid = FRAME_COLUMN_WIDTH (f);
3602 if (NILP (arg))
3604 x_set_scroll_bar_default_width (f);
3606 if (FRAME_X_WINDOW (f))
3607 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3608 do_pending_window_change (0);
3610 else if (INTEGERP (arg) && XINT (arg) > 0
3611 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3613 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3614 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3616 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3617 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3618 if (FRAME_X_WINDOW (f))
3619 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3620 do_pending_window_change (0);
3623 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3624 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3625 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3630 /* Return non-nil if frame F wants a bitmap icon. */
3632 Lisp_Object
3633 x_icon_type (f)
3634 FRAME_PTR f;
3636 Lisp_Object tem;
3638 tem = assq_no_quit (Qicon_type, f->param_alist);
3639 if (CONSP (tem))
3640 return XCDR (tem);
3641 else
3642 return Qnil;
3645 void
3646 x_set_alpha (f, arg, oldval)
3647 struct frame *f;
3648 Lisp_Object arg, oldval;
3650 double alpha = 1.0;
3651 double newval[2];
3652 int i, ialpha;
3653 Lisp_Object item;
3655 for (i = 0; i < 2; i++)
3657 newval[i] = 1.0;
3658 if (CONSP (arg))
3660 item = CAR (arg);
3661 arg = CDR (arg);
3663 else
3664 item=arg;
3666 if (! NILP (item))
3668 if (FLOATP (item))
3670 alpha = XFLOAT_DATA (item);
3671 if (alpha < 0.0 || 1.0 < alpha)
3672 args_out_of_range (make_float (0.0), make_float (1.0));
3674 else if (INTEGERP (item))
3676 ialpha = XINT (item);
3677 if (ialpha < 0 || 100 < ialpha)
3678 args_out_of_range (make_number (0), make_number (100));
3679 else
3680 alpha = ialpha / 100.0;
3682 else
3683 wrong_type_argument (Qnumberp, item);
3685 newval[i] = alpha;
3688 for (i = 0; i < 2; i++)
3689 f->alpha[i] = newval[i];
3691 #ifdef HAVE_X_WINDOWS
3692 BLOCK_INPUT;
3693 x_set_frame_alpha (f);
3694 UNBLOCK_INPUT;
3695 #endif
3697 return;
3701 /* Subroutines of creating an X frame. */
3703 /* Make sure that Vx_resource_name is set to a reasonable value.
3704 Fix it up, or set it to `emacs' if it is too hopeless. */
3706 void
3707 validate_x_resource_name ()
3709 int len = 0;
3710 /* Number of valid characters in the resource name. */
3711 int good_count = 0;
3712 /* Number of invalid characters in the resource name. */
3713 int bad_count = 0;
3714 Lisp_Object new;
3715 int i;
3717 if (!STRINGP (Vx_resource_class))
3718 Vx_resource_class = build_string (EMACS_CLASS);
3720 if (STRINGP (Vx_resource_name))
3722 unsigned char *p = SDATA (Vx_resource_name);
3723 int i;
3725 len = SBYTES (Vx_resource_name);
3727 /* Only letters, digits, - and _ are valid in resource names.
3728 Count the valid characters and count the invalid ones. */
3729 for (i = 0; i < len; i++)
3731 int c = p[i];
3732 if (! ((c >= 'a' && c <= 'z')
3733 || (c >= 'A' && c <= 'Z')
3734 || (c >= '0' && c <= '9')
3735 || c == '-' || c == '_'))
3736 bad_count++;
3737 else
3738 good_count++;
3741 else
3742 /* Not a string => completely invalid. */
3743 bad_count = 5, good_count = 0;
3745 /* If name is valid already, return. */
3746 if (bad_count == 0)
3747 return;
3749 /* If name is entirely invalid, or nearly so, use `emacs'. */
3750 if (good_count == 0
3751 || (good_count == 1 && bad_count > 0))
3753 Vx_resource_name = build_string ("emacs");
3754 return;
3757 /* Name is partly valid. Copy it and replace the invalid characters
3758 with underscores. */
3760 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3762 for (i = 0; i < len; i++)
3764 int c = SREF (new, i);
3765 if (! ((c >= 'a' && c <= 'z')
3766 || (c >= 'A' && c <= 'Z')
3767 || (c >= '0' && c <= '9')
3768 || c == '-' || c == '_'))
3769 SSET (new, i, '_');
3774 extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3775 extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3778 /* Get specified attribute from resource database RDB.
3779 See Fx_get_resource below for other parameters. */
3781 static Lisp_Object
3782 xrdb_get_resource (rdb, attribute, class, component, subclass)
3783 XrmDatabase rdb;
3784 Lisp_Object attribute, class, component, subclass;
3786 register char *value;
3787 char *name_key;
3788 char *class_key;
3790 CHECK_STRING (attribute);
3791 CHECK_STRING (class);
3793 if (!NILP (component))
3794 CHECK_STRING (component);
3795 if (!NILP (subclass))
3796 CHECK_STRING (subclass);
3797 if (NILP (component) != NILP (subclass))
3798 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3800 validate_x_resource_name ();
3802 /* Allocate space for the components, the dots which separate them,
3803 and the final '\0'. Make them big enough for the worst case. */
3804 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3805 + (STRINGP (component)
3806 ? SBYTES (component) : 0)
3807 + SBYTES (attribute)
3808 + 3);
3810 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3811 + SBYTES (class)
3812 + (STRINGP (subclass)
3813 ? SBYTES (subclass) : 0)
3814 + 3);
3816 /* Start with emacs.FRAMENAME for the name (the specific one)
3817 and with `Emacs' for the class key (the general one). */
3818 strcpy (name_key, SDATA (Vx_resource_name));
3819 strcpy (class_key, SDATA (Vx_resource_class));
3821 strcat (class_key, ".");
3822 strcat (class_key, SDATA (class));
3824 if (!NILP (component))
3826 strcat (class_key, ".");
3827 strcat (class_key, SDATA (subclass));
3829 strcat (name_key, ".");
3830 strcat (name_key, SDATA (component));
3833 strcat (name_key, ".");
3834 strcat (name_key, SDATA (attribute));
3836 value = x_get_string_resource (rdb, name_key, class_key);
3838 if (value != (char *) 0)
3839 return build_string (value);
3840 else
3841 return Qnil;
3845 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3846 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3847 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3848 class, where INSTANCE is the name under which Emacs was invoked, or
3849 the name specified by the `-name' or `-rn' command-line arguments.
3851 The optional arguments COMPONENT and SUBCLASS add to the key and the
3852 class, respectively. You must specify both of them or neither.
3853 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3854 and the class is `Emacs.CLASS.SUBCLASS'. */)
3855 (attribute, class, component, subclass)
3856 Lisp_Object attribute, class, component, subclass;
3858 #ifdef HAVE_X_WINDOWS
3859 check_x ();
3860 #endif
3862 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3863 attribute, class, component, subclass);
3866 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3868 Lisp_Object
3869 display_x_get_resource (dpyinfo, attribute, class, component, subclass)
3870 Display_Info *dpyinfo;
3871 Lisp_Object attribute, class, component, subclass;
3873 return xrdb_get_resource (dpyinfo->xrdb,
3874 attribute, class, component, subclass);
3877 /* Used when C code wants a resource value. */
3879 char *
3880 x_get_resource_string (attribute, class)
3881 char *attribute, *class;
3883 char *name_key;
3884 char *class_key;
3885 struct frame *sf = SELECTED_FRAME ();
3887 /* Allocate space for the components, the dots which separate them,
3888 and the final '\0'. */
3889 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3890 + strlen (attribute) + 2);
3891 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3892 + strlen (class) + 2);
3894 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3895 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3897 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3898 name_key, class_key);
3902 /* Return the value of parameter PARAM.
3904 First search ALIST, then Vdefault_frame_alist, then the X defaults
3905 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3907 Convert the resource to the type specified by desired_type.
3909 If no default is specified, return Qunbound. If you call
3910 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3911 and don't let it get stored in any Lisp-visible variables! */
3913 Lisp_Object
3914 x_get_arg (dpyinfo, alist, param, attribute, class, type)
3915 Display_Info *dpyinfo;
3916 Lisp_Object alist, param;
3917 char *attribute;
3918 char *class;
3919 enum resource_types type;
3921 register Lisp_Object tem;
3923 tem = Fassq (param, alist);
3925 if (!NILP (tem))
3927 /* If we find this parm in ALIST, clear it out
3928 so that it won't be "left over" at the end. */
3929 #ifndef WINDOWSNT /* w32fns.c has not yet been changed to cope with this. */
3930 Lisp_Object tail;
3931 XSETCAR (tem, Qnil);
3932 /* In case the parameter appears more than once in the alist,
3933 clear it out. */
3934 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3935 if (CONSP (XCAR (tail))
3936 && EQ (XCAR (XCAR (tail)), param))
3937 XSETCAR (XCAR (tail), Qnil);
3938 #endif
3940 else
3941 tem = Fassq (param, Vdefault_frame_alist);
3943 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3944 look in the X resources. */
3945 if (EQ (tem, Qnil))
3947 if (attribute)
3949 tem = display_x_get_resource (dpyinfo,
3950 build_string (attribute),
3951 build_string (class),
3952 Qnil, Qnil);
3954 if (NILP (tem))
3955 return Qunbound;
3957 switch (type)
3959 case RES_TYPE_NUMBER:
3960 return make_number (atoi (SDATA (tem)));
3962 case RES_TYPE_FLOAT:
3963 return make_float (atof (SDATA (tem)));
3965 case RES_TYPE_BOOLEAN:
3966 tem = Fdowncase (tem);
3967 if (!strcmp (SDATA (tem), "on")
3968 || !strcmp (SDATA (tem), "true"))
3969 return Qt;
3970 else
3971 return Qnil;
3973 case RES_TYPE_STRING:
3974 return tem;
3976 case RES_TYPE_SYMBOL:
3977 /* As a special case, we map the values `true' and `on'
3978 to Qt, and `false' and `off' to Qnil. */
3980 Lisp_Object lower;
3981 lower = Fdowncase (tem);
3982 if (!strcmp (SDATA (lower), "on")
3983 || !strcmp (SDATA (lower), "true"))
3984 return Qt;
3985 else if (!strcmp (SDATA (lower), "off")
3986 || !strcmp (SDATA (lower), "false"))
3987 return Qnil;
3988 else
3989 return Fintern (tem, Qnil);
3992 default:
3993 abort ();
3996 else
3997 return Qunbound;
3999 return Fcdr (tem);
4002 Lisp_Object
4003 x_frame_get_arg (f, alist, param, attribute, class, type)
4004 struct frame *f;
4005 Lisp_Object alist, param;
4006 char *attribute;
4007 char *class;
4008 enum resource_types type;
4010 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
4011 alist, param, attribute, class, type);
4014 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4016 Lisp_Object
4017 x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
4018 struct frame *f;
4019 Lisp_Object alist, param;
4020 char *attribute;
4021 char *class;
4022 enum resource_types type;
4024 Lisp_Object value;
4026 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
4027 attribute, class, type);
4028 if (! NILP (value) && ! EQ (value, Qunbound))
4029 store_frame_param (f, param, value);
4031 return value;
4035 /* Record in frame F the specified or default value according to ALIST
4036 of the parameter named PROP (a Lisp symbol).
4037 If no value is specified for PROP, look for an X default for XPROP
4038 on the frame named NAME.
4039 If that is not found either, use the value DEFLT. */
4041 Lisp_Object
4042 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
4043 struct frame *f;
4044 Lisp_Object alist;
4045 Lisp_Object prop;
4046 Lisp_Object deflt;
4047 char *xprop;
4048 char *xclass;
4049 enum resource_types type;
4051 Lisp_Object tem;
4053 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4054 if (EQ (tem, Qunbound))
4055 tem = deflt;
4056 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
4057 return tem;
4063 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4064 doc: /* Parse an X-style geometry string STRING.
4065 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4066 The properties returned may include `top', `left', `height', and `width'.
4067 The value of `left' or `top' may be an integer,
4068 or a list (+ N) meaning N pixels relative to top/left corner,
4069 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
4070 (string)
4071 Lisp_Object string;
4073 int geometry, x, y;
4074 unsigned int width, height;
4075 Lisp_Object result;
4077 CHECK_STRING (string);
4079 geometry = XParseGeometry ((char *) SDATA (string),
4080 &x, &y, &width, &height);
4082 #if 0
4083 if (!!(geometry & XValue) != !!(geometry & YValue))
4084 error ("Must specify both x and y position, or neither");
4085 #endif
4087 result = Qnil;
4088 if (geometry & XValue)
4090 Lisp_Object element;
4092 if (x >= 0 && (geometry & XNegative))
4093 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
4094 else if (x < 0 && ! (geometry & XNegative))
4095 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
4096 else
4097 element = Fcons (Qleft, make_number (x));
4098 result = Fcons (element, result);
4101 if (geometry & YValue)
4103 Lisp_Object element;
4105 if (y >= 0 && (geometry & YNegative))
4106 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
4107 else if (y < 0 && ! (geometry & YNegative))
4108 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
4109 else
4110 element = Fcons (Qtop, make_number (y));
4111 result = Fcons (element, result);
4114 if (geometry & WidthValue)
4115 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4116 if (geometry & HeightValue)
4117 result = Fcons (Fcons (Qheight, make_number (height)), result);
4119 return result;
4122 /* Calculate the desired size and position of frame F.
4123 Return the flags saying which aspects were specified.
4125 Also set the win_gravity and size_hint_flags of F.
4127 Adjust height for toolbar if TOOLBAR_P is 1.
4129 This function does not make the coordinates positive. */
4131 #define DEFAULT_ROWS 40
4132 #define DEFAULT_COLS 80
4135 x_figure_window_size (f, parms, toolbar_p)
4136 struct frame *f;
4137 Lisp_Object parms;
4138 int toolbar_p;
4140 register Lisp_Object tem0, tem1, tem2;
4141 long window_prompting = 0;
4142 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
4144 /* Default values if we fall through.
4145 Actually, if that happens we should get
4146 window manager prompting. */
4147 SET_FRAME_COLS (f, DEFAULT_COLS);
4148 FRAME_LINES (f) = DEFAULT_ROWS;
4149 /* Window managers expect that if program-specified
4150 positions are not (0,0), they're intentional, not defaults. */
4151 f->top_pos = 0;
4152 f->left_pos = 0;
4154 /* Ensure that old new_text_cols and new_text_lines will not override the
4155 values set here. */
4156 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4157 f->new_text_cols = f->new_text_lines = 0;
4159 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4160 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4161 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4162 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4164 if (!EQ (tem0, Qunbound))
4166 CHECK_NUMBER (tem0);
4167 FRAME_LINES (f) = XINT (tem0);
4169 if (!EQ (tem1, Qunbound))
4171 CHECK_NUMBER (tem1);
4172 SET_FRAME_COLS (f, XINT (tem1));
4174 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4175 window_prompting |= USSize;
4176 else
4177 window_prompting |= PSize;
4180 f->scroll_bar_actual_width
4181 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4183 /* This used to be done _before_ calling x_figure_window_size, but
4184 since the height is reset here, this was really a no-op. I
4185 assume that moving it here does what Gerd intended (although he
4186 no longer can remember what that was... ++KFS, 2003-03-25. */
4188 /* Add the tool-bar height to the initial frame height so that the
4189 user gets a text display area of the size he specified with -g or
4190 via .Xdefaults. Later changes of the tool-bar height don't
4191 change the frame size. This is done so that users can create
4192 tall Emacs frames without having to guess how tall the tool-bar
4193 will get. */
4194 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4196 int margin, relief, bar_height;
4198 relief = (tool_bar_button_relief >= 0
4199 ? tool_bar_button_relief
4200 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4202 if (INTEGERP (Vtool_bar_button_margin)
4203 && XINT (Vtool_bar_button_margin) > 0)
4204 margin = XFASTINT (Vtool_bar_button_margin);
4205 else if (CONSP (Vtool_bar_button_margin)
4206 && INTEGERP (XCDR (Vtool_bar_button_margin))
4207 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
4208 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4209 else
4210 margin = 0;
4212 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4213 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4216 compute_fringe_widths (f, 0);
4218 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4219 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4221 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4222 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4223 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4224 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4226 if (EQ (tem0, Qminus))
4228 f->top_pos = 0;
4229 window_prompting |= YNegative;
4231 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4232 && CONSP (XCDR (tem0))
4233 && INTEGERP (XCAR (XCDR (tem0))))
4235 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4236 window_prompting |= YNegative;
4238 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4239 && CONSP (XCDR (tem0))
4240 && INTEGERP (XCAR (XCDR (tem0))))
4242 f->top_pos = XINT (XCAR (XCDR (tem0)));
4244 else if (EQ (tem0, Qunbound))
4245 f->top_pos = 0;
4246 else
4248 CHECK_NUMBER (tem0);
4249 f->top_pos = XINT (tem0);
4250 if (f->top_pos < 0)
4251 window_prompting |= YNegative;
4254 if (EQ (tem1, Qminus))
4256 f->left_pos = 0;
4257 window_prompting |= XNegative;
4259 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4260 && CONSP (XCDR (tem1))
4261 && INTEGERP (XCAR (XCDR (tem1))))
4263 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4264 window_prompting |= XNegative;
4266 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4267 && CONSP (XCDR (tem1))
4268 && INTEGERP (XCAR (XCDR (tem1))))
4270 f->left_pos = XINT (XCAR (XCDR (tem1)));
4272 else if (EQ (tem1, Qunbound))
4273 f->left_pos = 0;
4274 else
4276 CHECK_NUMBER (tem1);
4277 f->left_pos = XINT (tem1);
4278 if (f->left_pos < 0)
4279 window_prompting |= XNegative;
4282 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4283 window_prompting |= USPosition;
4284 else
4285 window_prompting |= PPosition;
4288 if (f->want_fullscreen != FULLSCREEN_NONE)
4290 int left, top;
4291 int width, height;
4293 /* It takes both for some WM:s to place it where we want */
4294 window_prompting |= USPosition | PPosition;
4295 x_fullscreen_adjust (f, &width, &height, &top, &left);
4296 FRAME_COLS (f) = width;
4297 FRAME_LINES (f) = height;
4298 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
4299 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
4300 f->left_pos = left;
4301 f->top_pos = top;
4304 if (window_prompting & XNegative)
4306 if (window_prompting & YNegative)
4307 f->win_gravity = SouthEastGravity;
4308 else
4309 f->win_gravity = NorthEastGravity;
4311 else
4313 if (window_prompting & YNegative)
4314 f->win_gravity = SouthWestGravity;
4315 else
4316 f->win_gravity = NorthWestGravity;
4319 f->size_hint_flags = window_prompting;
4321 return window_prompting;
4326 #endif /* HAVE_WINDOW_SYSTEM */
4330 /***********************************************************************
4331 Initialization
4332 ***********************************************************************/
4334 void
4335 syms_of_frame ()
4337 Qframep = intern ("framep");
4338 staticpro (&Qframep);
4339 Qframe_live_p = intern ("frame-live-p");
4340 staticpro (&Qframe_live_p);
4341 Qexplicit_name = intern ("explicit-name");
4342 staticpro (&Qexplicit_name);
4343 Qheight = intern ("height");
4344 staticpro (&Qheight);
4345 Qicon = intern ("icon");
4346 staticpro (&Qicon);
4347 Qminibuffer = intern ("minibuffer");
4348 staticpro (&Qminibuffer);
4349 Qmodeline = intern ("modeline");
4350 staticpro (&Qmodeline);
4351 Qonly = intern ("only");
4352 staticpro (&Qonly);
4353 Qwidth = intern ("width");
4354 staticpro (&Qwidth);
4355 Qgeometry = intern ("geometry");
4356 staticpro (&Qgeometry);
4357 Qicon_left = intern ("icon-left");
4358 staticpro (&Qicon_left);
4359 Qicon_top = intern ("icon-top");
4360 staticpro (&Qicon_top);
4361 Qleft = intern ("left");
4362 staticpro (&Qleft);
4363 Qright = intern ("right");
4364 staticpro (&Qright);
4365 Quser_position = intern ("user-position");
4366 staticpro (&Quser_position);
4367 Quser_size = intern ("user-size");
4368 staticpro (&Quser_size);
4369 Qwindow_id = intern ("window-id");
4370 staticpro (&Qwindow_id);
4371 #ifdef HAVE_X_WINDOWS
4372 Qouter_window_id = intern ("outer-window-id");
4373 staticpro (&Qouter_window_id);
4374 #endif
4375 Qparent_id = intern ("parent-id");
4376 staticpro (&Qparent_id);
4377 Qx = intern ("x");
4378 staticpro (&Qx);
4379 Qw32 = intern ("w32");
4380 staticpro (&Qw32);
4381 Qpc = intern ("pc");
4382 staticpro (&Qpc);
4383 Qmac = intern ("mac");
4384 staticpro (&Qmac);
4385 Qvisible = intern ("visible");
4386 staticpro (&Qvisible);
4387 Qbuffer_predicate = intern ("buffer-predicate");
4388 staticpro (&Qbuffer_predicate);
4389 Qbuffer_list = intern ("buffer-list");
4390 staticpro (&Qbuffer_list);
4391 Qburied_buffer_list = intern ("buried-buffer-list");
4392 staticpro (&Qburied_buffer_list);
4393 Qdisplay_type = intern ("display-type");
4394 staticpro (&Qdisplay_type);
4395 Qbackground_mode = intern ("background-mode");
4396 staticpro (&Qbackground_mode);
4397 Qnoelisp = intern ("noelisp");
4398 staticpro (&Qnoelisp);
4399 Qtty_color_mode = intern ("tty-color-mode");
4400 staticpro (&Qtty_color_mode);
4401 Qtty = intern ("tty");
4402 staticpro (&Qtty);
4403 Qtty_type = intern ("tty-type");
4404 staticpro (&Qtty_type);
4406 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4407 staticpro (&Qface_set_after_frame_default);
4409 Qinhibit_face_set_after_frame_default
4410 = intern ("inhibit-face-set-after-frame-default");
4411 staticpro (&Qinhibit_face_set_after_frame_default);
4413 Qfullwidth = intern ("fullwidth");
4414 staticpro (&Qfullwidth);
4415 Qfullheight = intern ("fullheight");
4416 staticpro (&Qfullheight);
4417 Qfullboth = intern ("fullboth");
4418 staticpro (&Qfullboth);
4419 Qx_resource_name = intern ("x-resource-name");
4420 staticpro (&Qx_resource_name);
4422 Qx_frame_parameter = intern ("x-frame-parameter");
4423 staticpro (&Qx_frame_parameter);
4425 Qterminal = intern ("terminal");
4426 staticpro (&Qterminal);
4427 Qterminal_live_p = intern ("terminal-live-p");
4428 staticpro (&Qterminal_live_p);
4431 int i;
4433 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4435 Lisp_Object v = intern (frame_parms[i].name);
4436 if (frame_parms[i].variable)
4438 *frame_parms[i].variable = v;
4439 staticpro (frame_parms[i].variable);
4441 Fput (v, Qx_frame_parameter, make_number (i));
4445 #ifdef HAVE_WINDOW_SYSTEM
4446 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4447 doc: /* The name Emacs uses to look up X resources.
4448 `x-get-resource' uses this as the first component of the instance name
4449 when requesting resource values.
4450 Emacs initially sets `x-resource-name' to the name under which Emacs
4451 was invoked, or to the value specified with the `-name' or `-rn'
4452 switches, if present.
4454 It may be useful to bind this variable locally around a call
4455 to `x-get-resource'. See also the variable `x-resource-class'. */);
4456 Vx_resource_name = Qnil;
4458 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4459 doc: /* The class Emacs uses to look up X resources.
4460 `x-get-resource' uses this as the first component of the instance class
4461 when requesting resource values.
4463 Emacs initially sets `x-resource-class' to "Emacs".
4465 Setting this variable permanently is not a reasonable thing to do,
4466 but binding this variable locally around a call to `x-get-resource'
4467 is a reasonable practice. See also the variable `x-resource-name'. */);
4468 Vx_resource_class = build_string (EMACS_CLASS);
4470 DEFVAR_LISP ("frame-alpha-lower-limit", &Vframe_alpha_lower_limit,
4471 doc: /* The lower limit of the frame opacity (alpha transparency).
4472 The value should range from 0 (invisible) to 100 (completely opaque).
4473 You can also use a floating number between 0.0 and 1.0.
4474 The default is 20. */);
4475 Vframe_alpha_lower_limit = make_number (20);
4476 #endif
4478 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4479 doc: /* Alist of default values for frame creation.
4480 These may be set in your init file, like this:
4481 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4482 These override values given in window system configuration data,
4483 including X Windows' defaults database.
4484 For values specific to the first Emacs frame, see `initial-frame-alist'.
4485 For window-system specific values, see `window-system-default-frame-alist'.
4486 For values specific to the separate minibuffer frame, see
4487 `minibuffer-frame-alist'.
4488 The `menu-bar-lines' element of the list controls whether new frames
4489 have menu bars; `menu-bar-mode' works by altering this element.
4490 Setting this variable does not affect existing frames, only new ones. */);
4491 Vdefault_frame_alist = Qnil;
4493 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4494 doc: /* Default position of scroll bars on this window-system. */);
4495 #ifdef HAVE_WINDOW_SYSTEM
4496 #if defined(HAVE_NTGUI) || defined(MAC_OS)
4497 /* MS-Windows has scroll bars on the right by default. */
4498 Vdefault_frame_scroll_bars = Qright;
4499 #else
4500 Vdefault_frame_scroll_bars = Qleft;
4501 #endif
4502 #else
4503 Vdefault_frame_scroll_bars = Qnil;
4504 #endif
4506 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4507 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4509 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4510 doc: /* Non-nil if all of Emacs is iconified and frame updates are not needed. */);
4511 Vemacs_iconified = Qnil;
4513 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4514 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4515 `mouse-position' calls this function, passing its usual return value as
4516 argument, and returns whatever this function returns.
4517 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4518 which need to do mouse handling at the Lisp level. */);
4519 Vmouse_position_function = Qnil;
4521 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4522 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4523 If the value is an integer, highlighting is only shown after moving the
4524 mouse, while keyboard input turns off the highlight even when the mouse
4525 is over the clickable text. However, the mouse shape still indicates
4526 when the mouse is over clickable text. */);
4527 Vmouse_highlight = Qt;
4529 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4530 doc: /* Functions to be run before deleting a frame.
4531 The functions are run with one arg, the frame to be deleted.
4532 See `delete-frame'.
4534 Note that functions in this list may be called just before the frame is
4535 actually deleted, or some time later (or even both when an earlier function
4536 in `delete-frame-functions' (indirectly) calls `delete-frame'
4537 recursively). */);
4538 Vdelete_frame_functions = Qnil;
4539 Qdelete_frame_functions = intern ("delete-frame-functions");
4540 staticpro (&Qdelete_frame_functions);
4542 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4543 doc: /* Minibufferless frames use this frame's minibuffer.
4545 Emacs cannot create minibufferless frames unless this is set to an
4546 appropriate surrogate.
4548 Emacs consults this variable only when creating minibufferless
4549 frames; once the frame is created, it sticks with its assigned
4550 minibuffer, no matter what this variable is set to. This means that
4551 this variable doesn't necessarily say anything meaningful about the
4552 current set of frames, or where the minibuffer is currently being
4553 displayed.
4555 This variable is local to the current terminal and cannot be buffer-local. */);
4557 DEFVAR_BOOL ("focus-follows-mouse", &focus_follows_mouse,
4558 doc: /* Non-nil if window system changes focus when you move the mouse.
4559 You should set this variable to tell Emacs how your window manager
4560 handles focus, since there is no way in general for Emacs to find out
4561 automatically. */);
4562 #ifdef HAVE_WINDOW_SYSTEM
4563 #if defined(HAVE_NTGUI) || defined(MAC_OS)
4564 focus_follows_mouse = 0;
4565 #else
4566 focus_follows_mouse = 1;
4567 #endif
4568 #else
4569 focus_follows_mouse = 0;
4570 #endif
4572 staticpro (&Vframe_list);
4574 defsubr (&Sactive_minibuffer_window);
4575 defsubr (&Sframep);
4576 defsubr (&Sframe_live_p);
4577 defsubr (&Swindow_system);
4578 defsubr (&Smake_terminal_frame);
4579 defsubr (&Shandle_switch_frame);
4580 defsubr (&Sselect_frame);
4581 defsubr (&Sselected_frame);
4582 defsubr (&Swindow_frame);
4583 defsubr (&Sframe_root_window);
4584 defsubr (&Sframe_first_window);
4585 defsubr (&Sframe_selected_window);
4586 defsubr (&Sset_frame_selected_window);
4587 defsubr (&Sframe_list);
4588 defsubr (&Snext_frame);
4589 defsubr (&Sprevious_frame);
4590 defsubr (&Sdelete_frame);
4591 defsubr (&Smouse_position);
4592 defsubr (&Smouse_pixel_position);
4593 defsubr (&Sset_mouse_position);
4594 defsubr (&Sset_mouse_pixel_position);
4595 #if 0
4596 defsubr (&Sframe_configuration);
4597 defsubr (&Srestore_frame_configuration);
4598 #endif
4599 defsubr (&Smake_frame_visible);
4600 defsubr (&Smake_frame_invisible);
4601 defsubr (&Siconify_frame);
4602 defsubr (&Sframe_visible_p);
4603 defsubr (&Svisible_frame_list);
4604 defsubr (&Sraise_frame);
4605 defsubr (&Slower_frame);
4606 defsubr (&Sredirect_frame_focus);
4607 defsubr (&Sframe_focus);
4608 defsubr (&Sframe_parameters);
4609 defsubr (&Sframe_parameter);
4610 defsubr (&Smodify_frame_parameters);
4611 defsubr (&Sframe_char_height);
4612 defsubr (&Sframe_char_width);
4613 defsubr (&Sframe_pixel_height);
4614 defsubr (&Sframe_pixel_width);
4615 defsubr (&Sset_frame_height);
4616 defsubr (&Sset_frame_width);
4617 defsubr (&Sset_frame_size);
4618 defsubr (&Sset_frame_position);
4620 #ifdef HAVE_WINDOW_SYSTEM
4621 defsubr (&Sx_get_resource);
4622 defsubr (&Sx_parse_geometry);
4623 #endif
4627 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4628 (do not change this comment) */