Got rid of the rif (window-based redisplay interface) global variable.
[emacs.git] / src / frame.c
blob3b8ce346cad0c4d038817b83a07ac422d66283c2
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2003
3 Free Software Foundation.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include <config.h>
24 #include <stdio.h>
25 #include "lisp.h"
26 #include "charset.h"
27 #ifdef HAVE_X_WINDOWS
28 #include "xterm.h"
29 #endif
30 #ifdef WINDOWSNT
31 #include "w32term.h"
32 #endif
33 #ifdef MAC_OS
34 #include "macterm.h"
35 #endif
36 #include "buffer.h"
37 /* These help us bind and responding to switch-frame events. */
38 #include "commands.h"
39 #include "keyboard.h"
40 #include "frame.h"
41 #ifdef HAVE_WINDOW_SYSTEM
42 #include "fontset.h"
43 #endif
44 #include "blockinput.h"
45 #include "systty.h" /* For emacs_tty in termchar.h */
46 #include "termchar.h"
47 #include "termhooks.h"
48 #include "dispextern.h"
49 #include "window.h"
50 #ifdef MSDOS
51 #include "msdos.h"
52 #include "dosfns.h"
53 #endif
56 #ifdef HAVE_WINDOW_SYSTEM
58 /* The name we're using in resource queries. Most often "emacs". */
60 Lisp_Object Vx_resource_name;
62 /* The application class we're using in resource queries.
63 Normally "Emacs". */
65 Lisp_Object Vx_resource_class;
67 #endif
69 Lisp_Object Qframep, Qframe_live_p;
70 Lisp_Object Qicon, Qmodeline;
71 Lisp_Object Qonly;
72 Lisp_Object Qx, Qw32, Qmac, Qpc;
73 Lisp_Object Qvisible;
74 Lisp_Object Qdisplay_type;
75 Lisp_Object Qbackground_mode;
76 Lisp_Object Qinhibit_default_face_x_resources;
78 Lisp_Object Qx_frame_parameter;
79 Lisp_Object Qx_resource_name;
81 /* Frame parameters (set or reported). */
83 Lisp_Object Qauto_raise, Qauto_lower;
84 Lisp_Object Qborder_color, Qborder_width;
85 Lisp_Object Qcursor_color, Qcursor_type;
86 Lisp_Object Qgeometry; /* Not used */
87 Lisp_Object Qheight, Qwidth;
88 Lisp_Object Qleft, Qright;
89 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
90 Lisp_Object Qinternal_border_width;
91 Lisp_Object Qmouse_color;
92 Lisp_Object Qminibuffer;
93 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
94 Lisp_Object Qvisibility;
95 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
96 Lisp_Object Qscreen_gamma;
97 Lisp_Object Qline_spacing;
98 Lisp_Object Quser_position, Quser_size;
99 Lisp_Object Qwait_for_wm;
100 Lisp_Object Qwindow_id;
101 #ifdef HAVE_X_WINDOWS
102 Lisp_Object Qouter_window_id;
103 #endif
104 Lisp_Object Qparent_id;
105 Lisp_Object Qtitle, Qname;
106 Lisp_Object Qunsplittable;
107 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
108 Lisp_Object Qleft_fringe, Qright_fringe;
109 Lisp_Object Qbuffer_predicate, Qbuffer_list;
110 Lisp_Object Qtty_color_mode;
111 Lisp_Object Qtty, Qtty_type;
113 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
115 Lisp_Object Qface_set_after_frame_default;
117 Lisp_Object Vterminal_frame;
118 Lisp_Object Vdefault_frame_alist;
119 Lisp_Object Vdefault_frame_scroll_bars;
120 Lisp_Object Vmouse_position_function;
121 Lisp_Object Vmouse_highlight;
122 Lisp_Object Vdelete_frame_functions;
124 static void
125 set_menu_bar_lines_1 (window, n)
126 Lisp_Object window;
127 int n;
129 struct window *w = XWINDOW (window);
131 XSETFASTINT (w->last_modified, 0);
132 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
133 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
135 if (INTEGERP (w->orig_top_line))
136 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
137 if (INTEGERP (w->orig_total_lines))
138 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
140 /* Handle just the top child in a vertical split. */
141 if (!NILP (w->vchild))
142 set_menu_bar_lines_1 (w->vchild, n);
144 /* Adjust all children in a horizontal split. */
145 for (window = w->hchild; !NILP (window); window = w->next)
147 w = XWINDOW (window);
148 set_menu_bar_lines_1 (window, n);
152 void
153 set_menu_bar_lines (f, value, oldval)
154 struct frame *f;
155 Lisp_Object value, oldval;
157 int nlines;
158 int olines = FRAME_MENU_BAR_LINES (f);
160 /* Right now, menu bars don't work properly in minibuf-only frames;
161 most of the commands try to apply themselves to the minibuffer
162 frame itself, and get an error because you can't switch buffers
163 in or split the minibuffer window. */
164 if (FRAME_MINIBUF_ONLY_P (f))
165 return;
167 if (INTEGERP (value))
168 nlines = XINT (value);
169 else
170 nlines = 0;
172 if (nlines != olines)
174 windows_or_buffers_changed++;
175 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
176 FRAME_MENU_BAR_LINES (f) = nlines;
177 set_menu_bar_lines_1 (f->root_window, nlines - olines);
178 adjust_glyphs (f);
182 Lisp_Object Vemacs_iconified;
183 Lisp_Object Vframe_list;
185 extern Lisp_Object Vminibuffer_list;
186 extern Lisp_Object get_minibuffer ();
187 extern Lisp_Object Fhandle_switch_frame ();
188 extern Lisp_Object Fredirect_frame_focus ();
189 extern Lisp_Object x_get_focus_frame ();
191 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
192 doc: /* Return non-nil if OBJECT is a frame.
193 Value is t for a termcap frame (a character-only terminal),
194 `x' for an Emacs frame that is really an X window,
195 `w32' for an Emacs frame that is a window on MS-Windows display,
196 `mac' for an Emacs frame on a Macintosh display,
197 `pc' for a direct-write MS-DOS frame.
198 See also `frame-live-p'. */)
199 (object)
200 Lisp_Object object;
202 if (!FRAMEP (object))
203 return Qnil;
204 switch (XFRAME (object)->output_method)
206 case output_termcap:
207 return Qt;
208 case output_x_window:
209 return Qx;
210 case output_w32:
211 return Qw32;
212 case output_msdos_raw:
213 return Qpc;
214 case output_mac:
215 return Qmac;
216 default:
217 abort ();
221 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
222 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
223 Value is nil if OBJECT is not a live frame. If object is a live
224 frame, the return value indicates what sort of output device it is
225 displayed on. See the documentation of `framep' for possible
226 return values. */)
227 (object)
228 Lisp_Object object;
230 return ((FRAMEP (object)
231 && FRAME_LIVE_P (XFRAME (object)))
232 ? Fframep (object)
233 : Qnil);
236 struct frame *
237 make_frame (mini_p)
238 int mini_p;
240 Lisp_Object frame;
241 register struct frame *f;
242 register Lisp_Object root_window;
243 register Lisp_Object mini_window;
245 f = allocate_frame ();
246 XSETFRAME (frame, f);
248 f->desired_matrix = 0;
249 f->current_matrix = 0;
250 f->desired_pool = 0;
251 f->current_pool = 0;
252 f->glyphs_initialized_p = 0;
253 f->decode_mode_spec_buffer = 0;
254 f->visible = 0;
255 f->async_visible = 0;
256 f->output_data.nothing = 0;
257 f->iconified = 0;
258 f->async_iconified = 0;
259 f->wants_modeline = 1;
260 f->auto_raise = 0;
261 f->auto_lower = 0;
262 f->no_split = 0;
263 f->garbaged = 1;
264 f->has_minibuffer = mini_p;
265 f->focus_frame = Qnil;
266 f->explicit_name = 0;
267 f->can_have_scroll_bars = 0;
268 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
269 f->param_alist = Qnil;
270 f->scroll_bars = Qnil;
271 f->condemned_scroll_bars = Qnil;
272 f->face_alist = Qnil;
273 f->face_cache = NULL;
274 f->menu_bar_items = Qnil;
275 f->menu_bar_vector = Qnil;
276 f->menu_bar_items_used = 0;
277 f->buffer_predicate = Qnil;
278 f->buffer_list = Qnil;
279 #ifdef MULTI_KBOARD
280 f->kboard = initial_kboard;
281 #endif
282 f->namebuf = 0;
283 f->title = Qnil;
284 f->menu_bar_window = Qnil;
285 f->tool_bar_window = Qnil;
286 f->tool_bar_items = Qnil;
287 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
288 f->n_tool_bar_items = 0;
289 f->left_fringe_width = f->right_fringe_width = 0;
290 f->fringe_cols = 0;
291 f->scroll_bar_actual_width = 0;
292 f->border_width = 0;
293 f->internal_border_width = 0;
294 f->column_width = 1; /* !FRAME_WINDOW_P value */
295 f->line_height = 1; /* !FRAME_WINDOW_P value */
296 f->x_pixels_diff = f->y_pixels_diff = 0;
297 #ifdef HAVE_WINDOW_SYSTEM
298 f->want_fullscreen = FULLSCREEN_NONE;
299 #endif
300 f->size_hint_flags = 0;
301 f->win_gravity = 0;
303 root_window = make_window ();
304 if (mini_p)
306 mini_window = make_window ();
307 XWINDOW (root_window)->next = mini_window;
308 XWINDOW (mini_window)->prev = root_window;
309 XWINDOW (mini_window)->mini_p = Qt;
310 XWINDOW (mini_window)->frame = frame;
311 f->minibuffer_window = mini_window;
313 else
315 mini_window = Qnil;
316 XWINDOW (root_window)->next = Qnil;
317 f->minibuffer_window = Qnil;
320 XWINDOW (root_window)->frame = frame;
322 /* 10 is arbitrary,
323 just so that there is "something there."
324 Correct size will be set up later with change_frame_size. */
326 SET_FRAME_COLS (f, 10);
327 FRAME_LINES (f) = 10;
329 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
330 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
332 if (mini_p)
334 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
335 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
336 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
339 /* Choose a buffer for the frame's root window. */
341 Lisp_Object buf;
343 XWINDOW (root_window)->buffer = Qt;
344 buf = Fcurrent_buffer ();
345 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
346 a space), try to find another one. */
347 if (SREF (Fbuffer_name (buf), 0) == ' ')
348 buf = Fother_buffer (buf, Qnil, Qnil);
350 /* Use set_window_buffer, not Fset_window_buffer, and don't let
351 hooks be run by it. The reason is that the whole frame/window
352 arrangement is not yet fully intialized at this point. Windows
353 don't have the right size, glyph matrices aren't initialized
354 etc. Running Lisp functions at this point surely ends in a
355 SEGV. */
356 set_window_buffer (root_window, buf, 0, 0);
357 f->buffer_list = Fcons (buf, Qnil);
360 if (mini_p)
362 XWINDOW (mini_window)->buffer = Qt;
363 set_window_buffer (mini_window,
364 (NILP (Vminibuffer_list)
365 ? get_minibuffer (0)
366 : Fcar (Vminibuffer_list)),
367 0, 0);
370 f->root_window = root_window;
371 f->selected_window = root_window;
372 /* Make sure this window seems more recently used than
373 a newly-created, never-selected window. */
374 XSETFASTINT (XWINDOW (f->selected_window)->use_time, ++window_select_count);
376 f->default_face_done_p = 0;
378 return f;
381 #ifdef HAVE_WINDOW_SYSTEM
382 /* Make a frame using a separate minibuffer window on another frame.
383 MINI_WINDOW is the minibuffer window to use. nil means use the
384 default (the global minibuffer). */
386 struct frame *
387 make_frame_without_minibuffer (mini_window, kb, display)
388 register Lisp_Object mini_window;
389 KBOARD *kb;
390 Lisp_Object display;
392 register struct frame *f;
393 struct gcpro gcpro1;
395 if (!NILP (mini_window))
396 CHECK_LIVE_WINDOW (mini_window);
398 #ifdef MULTI_KBOARD
399 if (!NILP (mini_window)
400 && XFRAME (XWINDOW (mini_window)->frame)->kboard != kb)
401 error ("frame and minibuffer must be on the same display");
402 #endif
404 /* Make a frame containing just a root window. */
405 f = make_frame (0);
407 if (NILP (mini_window))
409 /* Use default-minibuffer-frame if possible. */
410 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
411 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
413 Lisp_Object frame_dummy;
415 XSETFRAME (frame_dummy, f);
416 GCPRO1 (frame_dummy);
417 /* If there's no minibuffer frame to use, create one. */
418 kb->Vdefault_minibuffer_frame =
419 call1 (intern ("make-initial-minibuffer-frame"), display);
420 UNGCPRO;
423 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
426 f->minibuffer_window = mini_window;
428 /* Make the chosen minibuffer window display the proper minibuffer,
429 unless it is already showing a minibuffer. */
430 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
431 Fset_window_buffer (mini_window,
432 (NILP (Vminibuffer_list)
433 ? get_minibuffer (0)
434 : Fcar (Vminibuffer_list)), Qnil);
435 return f;
438 /* Make a frame containing only a minibuffer window. */
440 struct frame *
441 make_minibuffer_frame ()
443 /* First make a frame containing just a root window, no minibuffer. */
445 register struct frame *f = make_frame (0);
446 register Lisp_Object mini_window;
447 register Lisp_Object frame;
449 XSETFRAME (frame, f);
451 f->auto_raise = 0;
452 f->auto_lower = 0;
453 f->no_split = 1;
454 f->wants_modeline = 0;
455 f->has_minibuffer = 1;
457 /* Now label the root window as also being the minibuffer.
458 Avoid infinite looping on the window chain by marking next pointer
459 as nil. */
461 mini_window = f->minibuffer_window = f->root_window;
462 XWINDOW (mini_window)->mini_p = Qt;
463 XWINDOW (mini_window)->next = Qnil;
464 XWINDOW (mini_window)->prev = Qnil;
465 XWINDOW (mini_window)->frame = frame;
467 /* Put the proper buffer in that window. */
469 Fset_window_buffer (mini_window,
470 (NILP (Vminibuffer_list)
471 ? get_minibuffer (0)
472 : Fcar (Vminibuffer_list)), Qnil);
473 return f;
475 #endif /* HAVE_WINDOW_SYSTEM */
477 /* Construct a frame that refers to a terminal. */
479 static int terminal_frame_count;
481 struct frame *
482 make_terminal_frame (tty_name, tty_type)
483 char *tty_name;
484 char *tty_type;
486 register struct frame *f;
487 Lisp_Object frame;
488 char name[20];
490 #ifdef MULTI_KBOARD
491 /* Create the initial keyboard. */
492 if (!initial_kboard)
494 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
495 init_kboard (initial_kboard);
496 initial_kboard->next_kboard = all_kboards;
497 all_kboards = initial_kboard;
499 #endif
501 /* The first call must initialize Vframe_list. */
502 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
503 Vframe_list = Qnil;
505 f = make_frame (1);
507 XSETFRAME (frame, f);
508 Vframe_list = Fcons (frame, Vframe_list);
510 terminal_frame_count++;
511 sprintf (name, "F%d", terminal_frame_count);
512 f->name = build_string (name);
514 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
515 f->async_visible = 1; /* Don't let visible be cleared later. */
516 #ifdef MSDOS
517 f->output_data.x = &the_only_x_display;
518 if (!inhibit_window_system
519 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
520 || XFRAME (selected_frame)->output_method == output_msdos_raw))
522 f->output_method = output_msdos_raw;
523 /* This initialization of foreground and background pixels is
524 only important for the initial frame created in temacs. If
525 we don't do that, we get black background and foreground in
526 the dumped Emacs because the_only_x_display is a static
527 variable, hence it is born all-zeroes, and zero is the code
528 for the black color. Other frames all inherit their pixels
529 from what's already in the_only_x_display. */
530 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
531 && f->output_data.x->background_pixel == 0
532 && f->output_data.x->foreground_pixel == 0)
534 f->output_data.x->background_pixel = FACE_TTY_DEFAULT_BG_COLOR;
535 f->output_data.x->foreground_pixel = FACE_TTY_DEFAULT_FG_COLOR;
538 else
539 f->output_method = output_termcap;
540 #else
541 #ifdef WINDOWSNT
542 f->output_method = output_termcap;
543 f->output_data.x = &tty_display; /* XXX */
544 #else
545 #ifdef MAC_OS8
546 make_mac_terminal_frame (f);
547 #else
549 struct tty_display_info *tty;
550 f->output_method = output_termcap;
552 f->output_data.tty = (struct tty_output *) xmalloc (sizeof (struct tty_output));
553 bzero (f->output_data.tty, sizeof (struct tty_output));
555 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
556 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
558 if (initialized)
560 /* Note that term_init may signal an error, but then it is its
561 responsibility to make sure this frame is deleted. */
562 f->output_data.tty->display_info = term_init (frame, tty_name, tty_type);
564 else
566 /* init_display() will reinitialize the terminal with correct values after dump. */
567 f->output_data.tty->display_info = term_dummy_init ();
569 FRAME_TTY (f)->reference_count++;
570 f->display_method = FRAME_TTY (f)->display_method;
571 #ifdef MULTI_KBOARD
572 f->kboard = FRAME_TTY (f)->kboard;
573 #endif
576 #ifdef CANNOT_DUMP
577 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
578 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
579 #endif
580 #endif /* MAC_OS8 */
581 #endif /* WINDOWSNT */
582 #endif /* MSDOS */
584 if (!noninteractive)
585 init_frame_faces (f);
587 return f;
590 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
591 1, 1, 0,
592 doc: /* Create an additional terminal frame, possibly on another terminal.
593 This function takes one argument, an alist specifying frame parameters.
595 You can create multiple frames on a single text-only terminal, but
596 only one of them (the selected terminal frame) is actually displayed.
598 In practice, generally you don't need to specify any parameters,
599 except when you want to create a new frame on another terminal.
600 In that case, the `tty' parameter specifies the device file to open,
601 and the `tty-type' parameter specifies the terminal type. Example:
603 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
605 Note that changing the size of one terminal frame automatically affects all. */)
606 (parms)
607 Lisp_Object parms;
609 struct frame *f;
610 Lisp_Object frame, tem;
611 struct frame *sf = SELECTED_FRAME ();
613 #ifdef MSDOS
614 if (sf->output_method != output_msdos_raw
615 && sf->output_method != output_termcap)
616 abort ();
617 #else /* not MSDOS */
619 #ifdef MAC_OS
620 if (sf->output_method != output_mac)
621 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
622 #else
623 #if 0 /* This should work now! */
624 if (sf->output_method != output_termcap)
625 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
626 #endif
627 #endif
628 #endif /* not MSDOS */
631 Lisp_Object tty, tty_type;
632 char *name = 0, *type = 0;
634 /* XXX Ugh, there must be a better way to do this. */
635 tty = Fassq (Qtty, parms);
636 if (EQ (tty, Qnil))
637 tty = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
638 if (EQ (tty, Qnil))
639 tty = Fassq (Qtty, Vdefault_frame_alist);
640 if (! EQ (tty, Qnil))
641 tty = XCDR (tty);
642 if (EQ (tty, Qnil) || !STRINGP (tty))
643 tty = Qnil;
645 tty_type = Fassq (Qtty_type, parms);
646 if (EQ (tty_type, Qnil))
647 tty_type = Fassq (Qtty_type, Vdefault_frame_alist);
648 if (EQ (tty_type, Qnil))
649 tty_type = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
650 if (! EQ (tty_type, Qnil))
651 tty_type = XCDR (tty_type);
652 if (EQ (tty_type, Qnil) || !STRINGP (tty_type))
653 tty_type = Qnil;
655 if (! EQ (tty, Qnil))
657 name = (char *) alloca (SBYTES (tty) + 1);
658 strncpy (name, SDATA (tty), SBYTES (tty));
659 name[SBYTES (tty)] = 0;
662 if (! EQ (tty_type, Qnil))
664 type = (char *) alloca (SBYTES (tty_type) + 1);
665 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
666 type[SBYTES (tty_type)] = 0;
669 f = make_terminal_frame (name, type);
673 int width, height;
674 get_tty_size (fileno (TTY_INPUT (FRAME_TTY (f))), &width, &height);
675 change_frame_size (f, height, width, 0, 0, 0);
678 adjust_glyphs (f);
679 calculate_costs (f);
680 XSETFRAME (frame, f);
681 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
682 Fmodify_frame_parameters (frame, parms);
684 /* Make the frame face alist be frame-specific, so that each
685 frame could change its face definitions independently. */
686 f->face_alist = Fcopy_alist (sf->face_alist);
687 /* Simple Fcopy_alist isn't enough, because we need the contents of
688 the vectors which are the CDRs of associations in face_alist to
689 be copied as well. */
690 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
691 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
692 return frame;
696 /* Perform the switch to frame FRAME.
698 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
699 FRAME1 as frame.
701 If TRACK is non-zero and the frame that currently has the focus
702 redirects its focus to the selected frame, redirect that focused
703 frame's focus to FRAME instead.
705 FOR_DELETION non-zero means that the selected frame is being
706 deleted, which includes the possibility that the frame's display
707 is dead. */
709 Lisp_Object
710 do_switch_frame (frame, track, for_deletion)
711 Lisp_Object frame;
712 int track, for_deletion;
714 struct frame *sf = SELECTED_FRAME ();
716 /* If FRAME is a switch-frame event, extract the frame we should
717 switch to. */
718 if (CONSP (frame)
719 && EQ (XCAR (frame), Qswitch_frame)
720 && CONSP (XCDR (frame)))
721 frame = XCAR (XCDR (frame));
723 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
724 a switch-frame event to arrive after a frame is no longer live,
725 especially when deleting the initial frame during startup. */
726 CHECK_FRAME (frame);
727 if (! FRAME_LIVE_P (XFRAME (frame)))
728 return Qnil;
730 if (sf == XFRAME (frame))
731 return frame;
733 /* This is too greedy; it causes inappropriate focus redirection
734 that's hard to get rid of. */
735 #if 0
736 /* If a frame's focus has been redirected toward the currently
737 selected frame, we should change the redirection to point to the
738 newly selected frame. This means that if the focus is redirected
739 from a minibufferless frame to a surrogate minibuffer frame, we
740 can use `other-window' to switch between all the frames using
741 that minibuffer frame, and the focus redirection will follow us
742 around. */
743 if (track)
745 Lisp_Object tail;
747 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
749 Lisp_Object focus;
751 if (!FRAMEP (XCAR (tail)))
752 abort ();
754 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
756 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
757 Fredirect_frame_focus (XCAR (tail), frame);
760 #else /* ! 0 */
761 /* Instead, apply it only to the frame we're pointing to. */
762 #ifdef HAVE_WINDOW_SYSTEM
763 if (track && FRAME_WINDOW_P (XFRAME (frame)))
765 Lisp_Object focus, xfocus;
767 xfocus = x_get_focus_frame (XFRAME (frame));
768 if (FRAMEP (xfocus))
770 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
771 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
772 Fredirect_frame_focus (xfocus, frame);
775 #endif /* HAVE_X_WINDOWS */
776 #endif /* ! 0 */
778 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
779 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
781 if (FRAME_TERMCAP_P (XFRAME (selected_frame))
782 && FRAME_TERMCAP_P (XFRAME (frame))
783 && FRAME_TTY (XFRAME (selected_frame)) == FRAME_TTY (XFRAME (frame)))
785 XFRAME (selected_frame)->async_visible = 2; /* obscured */
786 XFRAME (frame)->async_visible = 1;
787 FRAME_TTY (XFRAME (frame))->top_frame = frame;
790 selected_frame = frame;
791 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
792 last_nonminibuf_frame = XFRAME (selected_frame);
794 Fselect_window (XFRAME (frame)->selected_window, Qnil);
796 #ifndef WINDOWSNT
797 /* Make sure to switch the tty color mode to that of the newly
798 selected frame. */
799 sf = SELECTED_FRAME ();
800 if (FRAME_TERMCAP_P (sf))
802 Lisp_Object color_mode_spec, color_mode;
804 color_mode_spec = assq_no_quit (Qtty_color_mode, sf->param_alist);
805 if (CONSP (color_mode_spec))
806 color_mode = XCDR (color_mode_spec);
807 else
808 color_mode = make_number (0);
809 set_tty_color_mode (sf, color_mode);
811 #endif /* !WINDOWSNT */
813 /* We want to make sure that the next event generates a frame-switch
814 event to the appropriate frame. This seems kludgy to me, but
815 before you take it out, make sure that evaluating something like
816 (select-window (frame-root-window (new-frame))) doesn't end up
817 with your typing being interpreted in the new frame instead of
818 the one you're actually typing in. */
819 internal_last_event_frame = Qnil;
821 return frame;
824 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
825 doc: /* Select the frame FRAME.
826 Subsequent editing commands apply to its selected window.
827 The selection of FRAME lasts until the next time the user does
828 something to select a different frame, or until the next time this
829 function is called. */)
830 (frame, no_enter)
831 Lisp_Object frame, no_enter;
833 return do_switch_frame (frame, 1, 0);
837 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 2, "e",
838 doc: /* Handle a switch-frame event EVENT.
839 Switch-frame events are usually bound to this function.
840 A switch-frame event tells Emacs that the window manager has requested
841 that the user's events be directed to the frame mentioned in the event.
842 This function selects the selected window of the frame of EVENT.
844 If EVENT is frame object, handle it as if it were a switch-frame event
845 to that frame. */)
846 (event, no_enter)
847 Lisp_Object event, no_enter;
849 /* Preserve prefix arg that the command loop just cleared. */
850 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
851 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
852 return do_switch_frame (event, 0, 0);
855 DEFUN ("ignore-event", Fignore_event, Signore_event, 0, 0, "",
856 doc: /* Do nothing, but preserve any prefix argument already specified.
857 This is a suitable binding for `iconify-frame' and `make-frame-visible'. */)
860 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
861 return Qnil;
864 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
865 doc: /* Return the frame that is now selected. */)
868 return selected_frame;
871 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
872 doc: /* Return the frame object that window WINDOW is on. */)
873 (window)
874 Lisp_Object window;
876 CHECK_LIVE_WINDOW (window);
877 return XWINDOW (window)->frame;
880 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
881 doc: /* Returns the topmost, leftmost window of FRAME.
882 If omitted, FRAME defaults to the currently selected frame. */)
883 (frame)
884 Lisp_Object frame;
886 Lisp_Object w;
888 if (NILP (frame))
889 w = SELECTED_FRAME ()->root_window;
890 else
892 CHECK_LIVE_FRAME (frame);
893 w = XFRAME (frame)->root_window;
895 while (NILP (XWINDOW (w)->buffer))
897 if (! NILP (XWINDOW (w)->hchild))
898 w = XWINDOW (w)->hchild;
899 else if (! NILP (XWINDOW (w)->vchild))
900 w = XWINDOW (w)->vchild;
901 else
902 abort ();
904 return w;
907 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
908 Sactive_minibuffer_window, 0, 0, 0,
909 doc: /* Return the currently active minibuffer window, or nil if none. */)
912 return minibuf_level ? minibuf_window : Qnil;
915 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
916 doc: /* Returns the root-window of FRAME.
917 If omitted, FRAME defaults to the currently selected frame. */)
918 (frame)
919 Lisp_Object frame;
921 Lisp_Object window;
923 if (NILP (frame))
924 window = SELECTED_FRAME ()->root_window;
925 else
927 CHECK_LIVE_FRAME (frame);
928 window = XFRAME (frame)->root_window;
931 return window;
934 DEFUN ("frame-selected-window", Fframe_selected_window,
935 Sframe_selected_window, 0, 1, 0,
936 doc: /* Return the selected window of frame object FRAME.
937 If omitted, FRAME defaults to the currently selected frame. */)
938 (frame)
939 Lisp_Object frame;
941 Lisp_Object window;
943 if (NILP (frame))
944 window = SELECTED_FRAME ()->selected_window;
945 else
947 CHECK_LIVE_FRAME (frame);
948 window = XFRAME (frame)->selected_window;
951 return window;
954 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
955 Sset_frame_selected_window, 2, 2, 0,
956 doc: /* Set the selected window of frame object FRAME to WINDOW.
957 If FRAME is nil, the selected frame is used.
958 If FRAME is the selected frame, this makes WINDOW the selected window. */)
959 (frame, window)
960 Lisp_Object frame, window;
962 if (NILP (frame))
963 frame = selected_frame;
965 CHECK_LIVE_FRAME (frame);
966 CHECK_LIVE_WINDOW (window);
968 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
969 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
971 if (EQ (frame, selected_frame))
972 return Fselect_window (window, Qnil);
974 return XFRAME (frame)->selected_window = window;
977 DEFUN ("frame-list", Fframe_list, Sframe_list,
978 0, 0, 0,
979 doc: /* Return a list of all frames. */)
982 Lisp_Object frames;
983 frames = Fcopy_sequence (Vframe_list);
984 #ifdef HAVE_WINDOW_SYSTEM
985 if (FRAMEP (tip_frame))
986 frames = Fdelq (tip_frame, frames);
987 #endif
988 return frames;
991 /* Return the next frame in the frame list after FRAME.
992 If MINIBUF is nil, exclude minibuffer-only frames.
993 If MINIBUF is a window, include only its own frame
994 and any frame now using that window as the minibuffer.
995 If MINIBUF is `visible', include all visible frames.
996 If MINIBUF is 0, include all visible and iconified frames.
997 Otherwise, include all frames. */
999 Lisp_Object
1000 next_frame (frame, minibuf)
1001 Lisp_Object frame;
1002 Lisp_Object minibuf;
1004 Lisp_Object tail;
1005 int passed = 0;
1007 /* There must always be at least one frame in Vframe_list. */
1008 if (! CONSP (Vframe_list))
1009 abort ();
1011 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
1012 forever. Forestall that. */
1013 CHECK_LIVE_FRAME (frame);
1015 while (1)
1016 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1018 Lisp_Object f;
1020 f = XCAR (tail);
1022 if (passed
1023 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1024 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1025 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1026 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
1028 /* Decide whether this frame is eligible to be returned. */
1030 /* If we've looped all the way around without finding any
1031 eligible frames, return the original frame. */
1032 if (EQ (f, frame))
1033 return f;
1035 /* Let minibuf decide if this frame is acceptable. */
1036 if (NILP (minibuf))
1038 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1039 return f;
1041 else if (EQ (minibuf, Qvisible))
1043 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1044 if (FRAME_VISIBLE_P (XFRAME (f)))
1045 return f;
1047 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1049 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1050 if (FRAME_VISIBLE_P (XFRAME (f))
1051 || FRAME_ICONIFIED_P (XFRAME (f)))
1052 return f;
1054 else if (WINDOWP (minibuf))
1056 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1057 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1058 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1059 FRAME_FOCUS_FRAME (XFRAME (f))))
1060 return f;
1062 else
1063 return f;
1066 if (EQ (frame, f))
1067 passed++;
1071 /* Return the previous frame in the frame list before FRAME.
1072 If MINIBUF is nil, exclude minibuffer-only frames.
1073 If MINIBUF is a window, include only its own frame
1074 and any frame now using that window as the minibuffer.
1075 If MINIBUF is `visible', include all visible frames.
1076 If MINIBUF is 0, include all visible and iconified frames.
1077 Otherwise, include all frames. */
1079 Lisp_Object
1080 prev_frame (frame, minibuf)
1081 Lisp_Object frame;
1082 Lisp_Object minibuf;
1084 Lisp_Object tail;
1085 Lisp_Object prev;
1087 /* There must always be at least one frame in Vframe_list. */
1088 if (! CONSP (Vframe_list))
1089 abort ();
1091 prev = Qnil;
1092 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1094 Lisp_Object f;
1096 f = XCAR (tail);
1097 if (!FRAMEP (f))
1098 abort ();
1100 if (EQ (frame, f) && !NILP (prev))
1101 return prev;
1103 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1104 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1105 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1106 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1108 /* Decide whether this frame is eligible to be returned,
1109 according to minibuf. */
1110 if (NILP (minibuf))
1112 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1113 prev = f;
1115 else if (WINDOWP (minibuf))
1117 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1118 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1119 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1120 FRAME_FOCUS_FRAME (XFRAME (f))))
1121 prev = f;
1123 else if (EQ (minibuf, Qvisible))
1125 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1126 if (FRAME_VISIBLE_P (XFRAME (f)))
1127 prev = f;
1129 else if (XFASTINT (minibuf) == 0)
1131 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1132 if (FRAME_VISIBLE_P (XFRAME (f))
1133 || FRAME_ICONIFIED_P (XFRAME (f)))
1134 prev = f;
1136 else
1137 prev = f;
1141 /* We've scanned the entire list. */
1142 if (NILP (prev))
1143 /* We went through the whole frame list without finding a single
1144 acceptable frame. Return the original frame. */
1145 return frame;
1146 else
1147 /* There were no acceptable frames in the list before FRAME; otherwise,
1148 we would have returned directly from the loop. Since PREV is the last
1149 acceptable frame in the list, return it. */
1150 return prev;
1154 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1155 doc: /* Return the next frame in the frame list after FRAME.
1156 It considers only frames on the same terminal as FRAME.
1157 By default, skip minibuffer-only frames.
1158 If omitted, FRAME defaults to the selected frame.
1159 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1160 If MINIFRAME is a window, include only its own frame
1161 and any frame now using that window as the minibuffer.
1162 If MINIFRAME is `visible', include all visible frames.
1163 If MINIFRAME is 0, include all visible and iconified frames.
1164 Otherwise, include all frames. */)
1165 (frame, miniframe)
1166 Lisp_Object frame, miniframe;
1168 if (NILP (frame))
1169 frame = selected_frame;
1171 CHECK_LIVE_FRAME (frame);
1172 return next_frame (frame, miniframe);
1175 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1176 doc: /* Return the previous frame in the frame list before FRAME.
1177 It considers only frames on the same terminal as FRAME.
1178 By default, skip minibuffer-only frames.
1179 If omitted, FRAME defaults to the selected frame.
1180 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1181 If MINIFRAME is a window, include only its own frame
1182 and any frame now using that window as the minibuffer.
1183 If MINIFRAME is `visible', include all visible frames.
1184 If MINIFRAME is 0, include all visible and iconified frames.
1185 Otherwise, include all frames. */)
1186 (frame, miniframe)
1187 Lisp_Object frame, miniframe;
1189 if (NILP (frame))
1190 frame = selected_frame;
1191 CHECK_LIVE_FRAME (frame);
1192 return prev_frame (frame, miniframe);
1195 /* Return 1 if it is ok to delete frame F;
1196 0 if all frames aside from F are invisible.
1197 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1200 other_visible_frames (f)
1201 FRAME_PTR f;
1203 /* We know the selected frame is visible,
1204 so if F is some other frame, it can't be the sole visible one. */
1205 if (f == SELECTED_FRAME ())
1207 Lisp_Object frames;
1208 int count = 0;
1210 for (frames = Vframe_list;
1211 CONSP (frames);
1212 frames = XCDR (frames))
1214 Lisp_Object this;
1216 this = XCAR (frames);
1217 /* Verify that the frame's window still exists
1218 and we can still talk to it. And note any recent change
1219 in visibility. */
1220 #ifdef HAVE_WINDOW_SYSTEM
1221 if (FRAME_WINDOW_P (XFRAME (this)))
1223 x_sync (XFRAME (this));
1224 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1226 #endif
1228 if (FRAME_VISIBLE_P (XFRAME (this))
1229 || FRAME_ICONIFIED_P (XFRAME (this))
1230 /* Allow deleting the terminal frame when at least
1231 one X frame exists! */
1232 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1233 count++;
1235 return count > 1;
1237 return 1;
1240 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1241 doc: /* Delete FRAME, permanently eliminating it from use.
1242 If omitted, FRAME defaults to the selected frame.
1243 A frame may not be deleted if its minibuffer is used by other frames.
1244 Normally, you may not delete a frame if all other frames are invisible,
1245 but if the second optional argument FORCE is non-nil, you may do so.
1247 This function runs `delete-frame-functions' before actually deleting the
1248 frame, unless the frame is a tooltip.
1249 The functions are run with one arg, the frame to be deleted. */)
1250 (frame, force)
1251 Lisp_Object frame, force;
1253 struct frame *f;
1254 struct frame *sf = SELECTED_FRAME ();
1255 int minibuffer_selected;
1257 if (EQ (frame, Qnil))
1259 f = sf;
1260 XSETFRAME (frame, f);
1262 else
1264 CHECK_FRAME (frame);
1265 f = XFRAME (frame);
1268 if (! FRAME_LIVE_P (f))
1269 return Qnil;
1271 if (NILP (force) && !other_visible_frames (f)
1272 #ifdef MAC_OS8
1273 /* Terminal frame deleted before any other visible frames are
1274 created. */
1275 && strcmp (SDATA (f->name), "F1") != 0
1276 #endif
1278 error ("Attempt to delete the sole visible or iconified frame");
1280 #if 0
1281 /* This is a nice idea, but x_connection_closed needs to be able
1282 to delete the last frame, if it is gone. */
1283 if (NILP (XCDR (Vframe_list)))
1284 error ("Attempt to delete the only frame");
1285 #endif
1287 /* Does this frame have a minibuffer, and is it the surrogate
1288 minibuffer for any other frame? */
1289 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1291 Lisp_Object frames;
1293 for (frames = Vframe_list;
1294 CONSP (frames);
1295 frames = XCDR (frames))
1297 Lisp_Object this;
1298 this = XCAR (frames);
1300 if (! EQ (this, frame)
1301 && EQ (frame,
1302 WINDOW_FRAME (XWINDOW
1303 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1304 error ("Attempt to delete a surrogate minibuffer frame");
1308 /* Run `delete-frame-functions' unless frame is a tooltip. */
1309 if (!NILP (Vrun_hooks)
1310 && NILP (Fframe_parameter (frame, intern ("tooltip"))))
1312 Lisp_Object args[2];
1313 args[0] = intern ("delete-frame-functions");
1314 args[1] = frame;
1315 Frun_hook_with_args (2, args);
1318 minibuffer_selected = EQ (minibuf_window, selected_window);
1320 /* Don't let the frame remain selected. */
1321 if (f == sf)
1323 Lisp_Object tail, frame1;
1325 /* Look for another visible frame on the same terminal. */
1326 frame1 = next_frame (frame, Qvisible);
1328 /* If there is none, find *some* other frame. */
1329 if (NILP (frame1) || EQ (frame1, frame))
1331 FOR_EACH_FRAME (tail, frame1)
1333 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1334 break;
1338 do_switch_frame (frame1, 0, 1);
1339 sf = SELECTED_FRAME ();
1342 /* Don't allow minibuf_window to remain on a deleted frame. */
1343 if (EQ (f->minibuffer_window, minibuf_window))
1345 Fset_window_buffer (sf->minibuffer_window,
1346 XWINDOW (minibuf_window)->buffer, Qnil);
1347 minibuf_window = sf->minibuffer_window;
1349 /* If the dying minibuffer window was selected,
1350 select the new one. */
1351 if (minibuffer_selected)
1352 Fselect_window (minibuf_window, Qnil);
1355 /* Don't let echo_area_window to remain on a deleted frame. */
1356 if (EQ (f->minibuffer_window, echo_area_window))
1357 echo_area_window = sf->minibuffer_window;
1359 /* Clear any X selections for this frame. */
1360 #ifdef HAVE_X_WINDOWS
1361 if (FRAME_X_P (f))
1362 x_clear_frame_selections (f);
1363 #endif
1365 /* Free glyphs.
1366 This function must be called before the window tree of the
1367 frame is deleted because windows contain dynamically allocated
1368 memory. */
1369 free_glyphs (f);
1371 /* Mark all the windows that used to be on FRAME as deleted, and then
1372 remove the reference to them. */
1373 delete_all_subwindows (XWINDOW (f->root_window));
1374 f->root_window = Qnil;
1376 Vframe_list = Fdelq (frame, Vframe_list);
1377 FRAME_SET_VISIBLE (f, 0);
1379 if (f->namebuf)
1380 xfree (f->namebuf);
1381 if (f->decode_mode_spec_buffer)
1382 xfree (f->decode_mode_spec_buffer);
1383 if (FRAME_INSERT_COST (f))
1384 xfree (FRAME_INSERT_COST (f));
1385 if (FRAME_DELETEN_COST (f))
1386 xfree (FRAME_DELETEN_COST (f));
1387 if (FRAME_INSERTN_COST (f))
1388 xfree (FRAME_INSERTN_COST (f));
1389 if (FRAME_DELETE_COST (f))
1390 xfree (FRAME_DELETE_COST (f));
1391 if (FRAME_MESSAGE_BUF (f))
1392 xfree (FRAME_MESSAGE_BUF (f));
1394 /* Since some events are handled at the interrupt level, we may get
1395 an event for f at any time; if we zero out the frame's display
1396 now, then we may trip up the event-handling code. Instead, we'll
1397 promise that the display of the frame must be valid until we have
1398 called the window-system-dependent frame destruction routine. */
1400 /* I think this should be done with a hook. */
1401 #ifdef HAVE_WINDOW_SYSTEM
1402 if (FRAME_WINDOW_P (f))
1403 x_destroy_window (f);
1404 #endif
1406 if (FRAME_TERMCAP_P (f))
1408 int delete = 1;
1409 struct tty_display_info *tty = FRAME_TTY (f);
1411 if (! --tty->reference_count)
1413 /* delete_tty would call us recursively if we don't kill the
1414 frame now. */
1415 xfree (f->output_data.tty);
1416 f->output_data.nothing = 0;
1417 delete_tty (tty);
1420 else
1422 f->output_data.nothing = 0;
1425 /* If we've deleted the last_nonminibuf_frame, then try to find
1426 another one. */
1427 if (f == last_nonminibuf_frame)
1429 Lisp_Object frames;
1431 last_nonminibuf_frame = 0;
1433 for (frames = Vframe_list;
1434 CONSP (frames);
1435 frames = XCDR (frames))
1437 f = XFRAME (XCAR (frames));
1438 if (!FRAME_MINIBUF_ONLY_P (f))
1440 last_nonminibuf_frame = f;
1441 break;
1446 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1447 find another one. Prefer minibuffer-only frames, but also notice
1448 frames with other windows. */
1449 if (EQ (frame, FRAME_KBOARD (f)->Vdefault_minibuffer_frame))
1451 Lisp_Object frames;
1453 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1454 Lisp_Object frame_with_minibuf;
1455 /* Some frame we found on the same kboard, or nil if there are none. */
1456 Lisp_Object frame_on_same_kboard;
1458 frame_on_same_kboard = Qnil;
1459 frame_with_minibuf = Qnil;
1461 for (frames = Vframe_list;
1462 CONSP (frames);
1463 frames = XCDR (frames))
1465 Lisp_Object this;
1466 struct frame *f1;
1468 this = XCAR (frames);
1469 if (!FRAMEP (this))
1470 abort ();
1471 f1 = XFRAME (this);
1473 /* Consider only frames on the same kboard
1474 and only those with minibuffers. */
1475 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)
1476 && FRAME_HAS_MINIBUF_P (f1))
1478 frame_with_minibuf = this;
1479 if (FRAME_MINIBUF_ONLY_P (f1))
1480 break;
1483 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1))
1484 frame_on_same_kboard = this;
1487 if (!NILP (frame_on_same_kboard))
1489 /* We know that there must be some frame with a minibuffer out
1490 there. If this were not true, all of the frames present
1491 would have to be minibufferless, which implies that at some
1492 point their minibuffer frames must have been deleted, but
1493 that is prohibited at the top; you can't delete surrogate
1494 minibuffer frames. */
1495 if (NILP (frame_with_minibuf))
1496 abort ();
1498 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = frame_with_minibuf;
1500 else
1501 /* No frames left on this kboard--say no minibuffer either. */
1502 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = Qnil;
1505 /* Cause frame titles to update--necessary if we now have just one frame. */
1506 update_mode_lines = 1;
1508 return Qnil;
1511 /* Return mouse position in character cell units. */
1513 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1514 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1515 The position is given in character cells, where (0, 0) is the
1516 upper-left corner.
1517 If Emacs is running on a mouseless terminal or hasn't been programmed
1518 to read the mouse position, it returns the selected frame for FRAME
1519 and nil for X and Y.
1520 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1521 passing the normal return value to that function as an argument,
1522 and returns whatever that function returns. */)
1525 FRAME_PTR f;
1526 Lisp_Object lispy_dummy;
1527 enum scroll_bar_part party_dummy;
1528 Lisp_Object x, y, retval;
1529 int col, row;
1530 unsigned long long_dummy;
1531 struct gcpro gcpro1;
1533 f = SELECTED_FRAME ();
1534 x = y = Qnil;
1536 #ifdef HAVE_MOUSE
1537 /* It's okay for the hook to refrain from storing anything. */
1538 if (mouse_position_hook)
1539 (*mouse_position_hook) (&f, -1,
1540 &lispy_dummy, &party_dummy,
1541 &x, &y,
1542 &long_dummy);
1543 if (! NILP (x))
1545 col = XINT (x);
1546 row = XINT (y);
1547 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1548 XSETINT (x, col);
1549 XSETINT (y, row);
1551 #endif
1552 XSETFRAME (lispy_dummy, f);
1553 retval = Fcons (lispy_dummy, Fcons (x, y));
1554 GCPRO1 (retval);
1555 if (!NILP (Vmouse_position_function))
1556 retval = call1 (Vmouse_position_function, retval);
1557 RETURN_UNGCPRO (retval);
1560 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1561 Smouse_pixel_position, 0, 0, 0,
1562 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1563 The position is given in pixel units, where (0, 0) is the
1564 upper-left corner.
1565 If Emacs is running on a mouseless terminal or hasn't been programmed
1566 to read the mouse position, it returns the selected frame for FRAME
1567 and nil for X and Y. */)
1570 FRAME_PTR f;
1571 Lisp_Object lispy_dummy;
1572 enum scroll_bar_part party_dummy;
1573 Lisp_Object x, y;
1574 unsigned long long_dummy;
1576 f = SELECTED_FRAME ();
1577 x = y = Qnil;
1579 #ifdef HAVE_MOUSE
1580 /* It's okay for the hook to refrain from storing anything. */
1581 if (mouse_position_hook)
1582 (*mouse_position_hook) (&f, -1,
1583 &lispy_dummy, &party_dummy,
1584 &x, &y,
1585 &long_dummy);
1586 #endif
1587 XSETFRAME (lispy_dummy, f);
1588 return Fcons (lispy_dummy, Fcons (x, y));
1591 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1592 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1593 Coordinates are relative to the frame, not a window,
1594 so the coordinates of the top left character in the frame
1595 may be nonzero due to left-hand scroll bars or the menu bar.
1597 This function is a no-op for an X frame that is not visible.
1598 If you have just created a frame, you must wait for it to become visible
1599 before calling this function on it, like this.
1600 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1601 (frame, x, y)
1602 Lisp_Object frame, x, y;
1604 CHECK_LIVE_FRAME (frame);
1605 CHECK_NUMBER (x);
1606 CHECK_NUMBER (y);
1608 /* I think this should be done with a hook. */
1609 #ifdef HAVE_WINDOW_SYSTEM
1610 if (FRAME_WINDOW_P (XFRAME (frame)))
1611 /* Warping the mouse will cause enternotify and focus events. */
1612 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1613 #else
1614 #if defined (MSDOS) && defined (HAVE_MOUSE)
1615 if (FRAME_MSDOS_P (XFRAME (frame)))
1617 Fselect_frame (frame, Qnil);
1618 mouse_moveto (XINT (x), XINT (y));
1620 #endif
1621 #endif
1623 return Qnil;
1626 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1627 Sset_mouse_pixel_position, 3, 3, 0,
1628 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1629 Note, this is a no-op for an X frame that is not visible.
1630 If you have just created a frame, you must wait for it to become visible
1631 before calling this function on it, like this.
1632 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1633 (frame, x, y)
1634 Lisp_Object frame, x, y;
1636 CHECK_LIVE_FRAME (frame);
1637 CHECK_NUMBER (x);
1638 CHECK_NUMBER (y);
1640 /* I think this should be done with a hook. */
1641 #ifdef HAVE_WINDOW_SYSTEM
1642 if (FRAME_WINDOW_P (XFRAME (frame)))
1643 /* Warping the mouse will cause enternotify and focus events. */
1644 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1645 #else
1646 #if defined (MSDOS) && defined (HAVE_MOUSE)
1647 if (FRAME_MSDOS_P (XFRAME (frame)))
1649 Fselect_frame (frame, Qnil);
1650 mouse_moveto (XINT (x), XINT (y));
1652 #endif
1653 #endif
1655 return Qnil;
1658 static void make_frame_visible_1 P_ ((Lisp_Object));
1660 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1661 0, 1, "",
1662 doc: /* Make the frame FRAME visible (assuming it is an X window).
1663 If omitted, FRAME defaults to the currently selected frame. */)
1664 (frame)
1665 Lisp_Object frame;
1667 if (NILP (frame))
1668 frame = selected_frame;
1670 CHECK_LIVE_FRAME (frame);
1672 /* I think this should be done with a hook. */
1673 #ifdef HAVE_WINDOW_SYSTEM
1674 if (FRAME_WINDOW_P (XFRAME (frame)))
1676 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1677 x_make_frame_visible (XFRAME (frame));
1679 #endif
1681 make_frame_visible_1 (XFRAME (frame)->root_window);
1683 /* Make menu bar update for the Buffers and Frames menus. */
1684 windows_or_buffers_changed++;
1686 return frame;
1689 /* Update the display_time slot of the buffers shown in WINDOW
1690 and all its descendents. */
1692 static void
1693 make_frame_visible_1 (window)
1694 Lisp_Object window;
1696 struct window *w;
1698 for (;!NILP (window); window = w->next)
1700 w = XWINDOW (window);
1702 if (!NILP (w->buffer))
1703 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1705 if (!NILP (w->vchild))
1706 make_frame_visible_1 (w->vchild);
1707 if (!NILP (w->hchild))
1708 make_frame_visible_1 (w->hchild);
1712 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1713 0, 2, "",
1714 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1715 If omitted, FRAME defaults to the currently selected frame.
1716 Normally you may not make FRAME invisible if all other frames are invisible,
1717 but if the second optional argument FORCE is non-nil, you may do so. */)
1718 (frame, force)
1719 Lisp_Object frame, force;
1721 if (NILP (frame))
1722 frame = selected_frame;
1724 CHECK_LIVE_FRAME (frame);
1726 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1727 error ("Attempt to make invisible the sole visible or iconified frame");
1729 #if 0 /* This isn't logically necessary, and it can do GC. */
1730 /* Don't let the frame remain selected. */
1731 if (EQ (frame, selected_frame))
1732 do_switch_frame (next_frame (frame, Qt), 0, 0)
1733 #endif
1735 /* Don't allow minibuf_window to remain on a deleted frame. */
1736 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1738 struct frame *sf = XFRAME (selected_frame);
1739 Fset_window_buffer (sf->minibuffer_window,
1740 XWINDOW (minibuf_window)->buffer, Qnil);
1741 minibuf_window = sf->minibuffer_window;
1744 /* I think this should be done with a hook. */
1745 #ifdef HAVE_WINDOW_SYSTEM
1746 if (FRAME_WINDOW_P (XFRAME (frame)))
1747 x_make_frame_invisible (XFRAME (frame));
1748 #endif
1750 /* Make menu bar update for the Buffers and Frames menus. */
1751 windows_or_buffers_changed++;
1753 return Qnil;
1756 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1757 0, 1, "",
1758 doc: /* Make the frame FRAME into an icon.
1759 If omitted, FRAME defaults to the currently selected frame. */)
1760 (frame)
1761 Lisp_Object frame;
1763 if (NILP (frame))
1764 frame = selected_frame;
1766 CHECK_LIVE_FRAME (frame);
1768 #if 0 /* This isn't logically necessary, and it can do GC. */
1769 /* Don't let the frame remain selected. */
1770 if (EQ (frame, selected_frame))
1771 Fhandle_switch_frame (next_frame (frame, Qt), Qnil);
1772 #endif
1774 /* Don't allow minibuf_window to remain on a deleted frame. */
1775 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1777 struct frame *sf = XFRAME (selected_frame);
1778 Fset_window_buffer (sf->minibuffer_window,
1779 XWINDOW (minibuf_window)->buffer, Qnil);
1780 minibuf_window = sf->minibuffer_window;
1783 /* I think this should be done with a hook. */
1784 #ifdef HAVE_WINDOW_SYSTEM
1785 if (FRAME_WINDOW_P (XFRAME (frame)))
1786 x_iconify_frame (XFRAME (frame));
1787 #endif
1789 /* Make menu bar update for the Buffers and Frames menus. */
1790 windows_or_buffers_changed++;
1792 return Qnil;
1795 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1796 1, 1, 0,
1797 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1798 A frame that is not \"visible\" is not updated and, if it works through
1799 a window system, it may not show at all.
1800 Return the symbol `icon' if frame is visible only as an icon. */)
1801 (frame)
1802 Lisp_Object frame;
1804 CHECK_LIVE_FRAME (frame);
1806 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1808 if (FRAME_VISIBLE_P (XFRAME (frame)))
1809 return Qt;
1810 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1811 return Qicon;
1812 return Qnil;
1815 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1816 0, 0, 0,
1817 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1820 Lisp_Object tail, frame;
1821 struct frame *f;
1822 Lisp_Object value;
1824 value = Qnil;
1825 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1827 frame = XCAR (tail);
1828 if (!FRAMEP (frame))
1829 continue;
1830 f = XFRAME (frame);
1831 if (FRAME_VISIBLE_P (f))
1832 value = Fcons (frame, value);
1834 return value;
1838 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1839 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1840 If FRAME is invisible, make it visible.
1841 If you don't specify a frame, the selected frame is used.
1842 If Emacs is displaying on an ordinary terminal or some other device which
1843 doesn't support multiple overlapping frames, this function does nothing. */)
1844 (frame)
1845 Lisp_Object frame;
1847 if (NILP (frame))
1848 frame = selected_frame;
1850 CHECK_LIVE_FRAME (frame);
1852 /* Do like the documentation says. */
1853 Fmake_frame_visible (frame);
1855 if (frame_raise_lower_hook)
1856 (*frame_raise_lower_hook) (XFRAME (frame), 1);
1858 return Qnil;
1861 /* Should we have a corresponding function called Flower_Power? */
1862 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1863 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1864 If you don't specify a frame, the selected frame is used.
1865 If Emacs is displaying on an ordinary terminal or some other device which
1866 doesn't support multiple overlapping frames, this function does nothing. */)
1867 (frame)
1868 Lisp_Object frame;
1870 if (NILP (frame))
1871 frame = selected_frame;
1873 CHECK_LIVE_FRAME (frame);
1875 if (frame_raise_lower_hook)
1876 (*frame_raise_lower_hook) (XFRAME (frame), 0);
1878 return Qnil;
1882 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1883 1, 2, 0,
1884 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1885 In other words, switch-frame events caused by events in FRAME will
1886 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1887 FOCUS-FRAME after reading an event typed at FRAME.
1889 If FOCUS-FRAME is omitted or nil, any existing redirection is
1890 cancelled, and the frame again receives its own keystrokes.
1892 Focus redirection is useful for temporarily redirecting keystrokes to
1893 a surrogate minibuffer frame when a frame doesn't have its own
1894 minibuffer window.
1896 A frame's focus redirection can be changed by select-frame. If frame
1897 FOO is selected, and then a different frame BAR is selected, any
1898 frames redirecting their focus to FOO are shifted to redirect their
1899 focus to BAR. This allows focus redirection to work properly when the
1900 user switches from one frame to another using `select-window'.
1902 This means that a frame whose focus is redirected to itself is treated
1903 differently from a frame whose focus is redirected to nil; the former
1904 is affected by select-frame, while the latter is not.
1906 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1907 (frame, focus_frame)
1908 Lisp_Object frame, focus_frame;
1910 /* Note that we don't check for a live frame here. It's reasonable
1911 to redirect the focus of a frame you're about to delete, if you
1912 know what other frame should receive those keystrokes. */
1913 CHECK_FRAME (frame);
1915 if (! NILP (focus_frame))
1916 CHECK_LIVE_FRAME (focus_frame);
1918 XFRAME (frame)->focus_frame = focus_frame;
1920 if (!FRAME_TERMCAP_P (XFRAME (frame)) && frame_rehighlight_hook)
1921 (*frame_rehighlight_hook) (XFRAME (frame));
1923 return Qnil;
1927 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1928 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1929 This returns nil if FRAME's focus is not redirected.
1930 See `redirect-frame-focus'. */)
1931 (frame)
1932 Lisp_Object frame;
1934 CHECK_LIVE_FRAME (frame);
1936 return FRAME_FOCUS_FRAME (XFRAME (frame));
1941 /* Return the value of frame parameter PROP in frame FRAME. */
1943 Lisp_Object
1944 get_frame_param (frame, prop)
1945 register struct frame *frame;
1946 Lisp_Object prop;
1948 register Lisp_Object tem;
1950 tem = Fassq (prop, frame->param_alist);
1951 if (EQ (tem, Qnil))
1952 return tem;
1953 return Fcdr (tem);
1956 /* Return the buffer-predicate of the selected frame. */
1958 Lisp_Object
1959 frame_buffer_predicate (frame)
1960 Lisp_Object frame;
1962 return XFRAME (frame)->buffer_predicate;
1965 /* Return the buffer-list of the selected frame. */
1967 Lisp_Object
1968 frame_buffer_list (frame)
1969 Lisp_Object frame;
1971 return XFRAME (frame)->buffer_list;
1974 /* Set the buffer-list of the selected frame. */
1976 void
1977 set_frame_buffer_list (frame, list)
1978 Lisp_Object frame, list;
1980 XFRAME (frame)->buffer_list = list;
1983 /* Discard BUFFER from the buffer-list of each frame. */
1985 void
1986 frames_discard_buffer (buffer)
1987 Lisp_Object buffer;
1989 Lisp_Object frame, tail;
1991 FOR_EACH_FRAME (tail, frame)
1993 XFRAME (frame)->buffer_list
1994 = Fdelq (buffer, XFRAME (frame)->buffer_list);
1998 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1999 If the alist already has an element for PROP, we change it. */
2001 void
2002 store_in_alist (alistptr, prop, val)
2003 Lisp_Object *alistptr, val;
2004 Lisp_Object prop;
2006 register Lisp_Object tem;
2008 tem = Fassq (prop, *alistptr);
2009 if (EQ (tem, Qnil))
2010 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2011 else
2012 Fsetcdr (tem, val);
2015 static int
2016 frame_name_fnn_p (str, len)
2017 char *str;
2018 int len;
2020 if (len > 1 && str[0] == 'F')
2022 char *end_ptr;
2024 strtol (str + 1, &end_ptr, 10);
2026 if (end_ptr == str + len)
2027 return 1;
2029 return 0;
2032 /* Set the name of the terminal frame. Also used by MSDOS frames.
2033 Modeled after x_set_name which is used for WINDOW frames. */
2035 void
2036 set_term_frame_name (f, name)
2037 struct frame *f;
2038 Lisp_Object name;
2040 f->explicit_name = ! NILP (name);
2042 /* If NAME is nil, set the name to F<num>. */
2043 if (NILP (name))
2045 char namebuf[20];
2047 /* Check for no change needed in this very common case
2048 before we do any consing. */
2049 if (frame_name_fnn_p (SDATA (f->name),
2050 SBYTES (f->name)))
2051 return;
2053 terminal_frame_count++;
2054 sprintf (namebuf, "F%d", terminal_frame_count);
2055 name = build_string (namebuf);
2057 else
2059 CHECK_STRING (name);
2061 /* Don't change the name if it's already NAME. */
2062 if (! NILP (Fstring_equal (name, f->name)))
2063 return;
2065 /* Don't allow the user to set the frame name to F<num>, so it
2066 doesn't clash with the names we generate for terminal frames. */
2067 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2068 error ("Frame names of the form F<num> are usurped by Emacs");
2071 f->name = name;
2072 update_mode_lines = 1;
2075 void
2076 store_frame_param (f, prop, val)
2077 struct frame *f;
2078 Lisp_Object prop, val;
2080 register Lisp_Object old_alist_elt;
2082 /* The buffer-alist parameter is stored in a special place and is
2083 not in the alist. */
2084 if (EQ (prop, Qbuffer_list))
2086 f->buffer_list = val;
2087 return;
2090 /* If PROP is a symbol which is supposed to have frame-local values,
2091 and it is set up based on this frame, switch to the global
2092 binding. That way, we can create or alter the frame-local binding
2093 without messing up the symbol's status. */
2094 if (SYMBOLP (prop))
2096 Lisp_Object valcontents;
2097 valcontents = SYMBOL_VALUE (prop);
2098 if ((BUFFER_LOCAL_VALUEP (valcontents)
2099 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
2100 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2101 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2102 swap_in_global_binding (prop);
2105 #ifndef WINDOWSNT
2106 /* The tty color mode needs to be set before the frame's parameter
2107 alist is updated with the new value, because set_tty_color_mode
2108 wants to look at the old mode. */
2109 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode))
2110 set_tty_color_mode (f, val);
2111 #endif
2113 /* Update the frame parameter alist. */
2114 old_alist_elt = Fassq (prop, f->param_alist);
2115 if (EQ (old_alist_elt, Qnil))
2116 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2117 else
2118 Fsetcdr (old_alist_elt, val);
2120 /* Update some other special parameters in their special places
2121 in addition to the alist. */
2123 if (EQ (prop, Qbuffer_predicate))
2124 f->buffer_predicate = val;
2126 if (! FRAME_WINDOW_P (f))
2128 if (EQ (prop, Qmenu_bar_lines))
2129 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2130 else if (EQ (prop, Qname))
2131 set_term_frame_name (f, val);
2134 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2136 if (! MINI_WINDOW_P (XWINDOW (val)))
2137 error ("Surrogate minibuffer windows must be minibuffer windows");
2139 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2140 && !EQ (val, f->minibuffer_window))
2141 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2143 /* Install the chosen minibuffer window, with proper buffer. */
2144 f->minibuffer_window = val;
2148 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2149 doc: /* Return the parameters-alist of frame FRAME.
2150 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2151 The meaningful PARMs depend on the kind of frame.
2152 If FRAME is omitted, return information on the currently selected frame. */)
2153 (frame)
2154 Lisp_Object frame;
2156 Lisp_Object alist;
2157 FRAME_PTR f;
2158 int height, width;
2159 struct gcpro gcpro1;
2161 if (NILP (frame))
2162 frame = selected_frame;
2164 CHECK_FRAME (frame);
2165 f = XFRAME (frame);
2167 if (!FRAME_LIVE_P (f))
2168 return Qnil;
2170 alist = Fcopy_alist (f->param_alist);
2171 GCPRO1 (alist);
2173 if (!FRAME_WINDOW_P (f))
2175 int fg = FRAME_FOREGROUND_PIXEL (f);
2176 int bg = FRAME_BACKGROUND_PIXEL (f);
2177 Lisp_Object elt;
2179 /* If the frame's parameter alist says the colors are
2180 unspecified and reversed, take the frame's background pixel
2181 for foreground and vice versa. */
2182 elt = Fassq (Qforeground_color, alist);
2183 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2185 if (strncmp (SDATA (XCDR (elt)),
2186 unspecified_bg,
2187 SCHARS (XCDR (elt))) == 0)
2188 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2189 else if (strncmp (SDATA (XCDR (elt)),
2190 unspecified_fg,
2191 SCHARS (XCDR (elt))) == 0)
2192 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2194 else
2195 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2196 elt = Fassq (Qbackground_color, alist);
2197 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2199 if (strncmp (SDATA (XCDR (elt)),
2200 unspecified_fg,
2201 SCHARS (XCDR (elt))) == 0)
2202 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2203 else if (strncmp (SDATA (XCDR (elt)),
2204 unspecified_bg,
2205 SCHARS (XCDR (elt))) == 0)
2206 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2208 else
2209 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2210 store_in_alist (&alist, intern ("font"),
2211 build_string (FRAME_MSDOS_P (f)
2212 ? "ms-dos"
2213 : FRAME_W32_P (f) ? "w32term"
2214 :"tty"));
2216 store_in_alist (&alist, Qname, f->name);
2217 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2218 store_in_alist (&alist, Qheight, make_number (height));
2219 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2220 store_in_alist (&alist, Qwidth, make_number (width));
2221 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2222 store_in_alist (&alist, Qminibuffer,
2223 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2224 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2225 : FRAME_MINIBUF_WINDOW (f)));
2226 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2227 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2229 /* I think this should be done with a hook. */
2230 #ifdef HAVE_WINDOW_SYSTEM
2231 if (FRAME_WINDOW_P (f))
2232 x_report_frame_params (f, &alist);
2233 else
2234 #endif
2236 /* This ought to be correct in f->param_alist for an X frame. */
2237 Lisp_Object lines;
2238 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2239 store_in_alist (&alist, Qmenu_bar_lines, lines);
2242 UNGCPRO;
2243 return alist;
2247 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2248 doc: /* Return FRAME's value for parameter PARAMETER.
2249 If FRAME is nil, describe the currently selected frame. */)
2250 (frame, parameter)
2251 Lisp_Object frame, parameter;
2253 struct frame *f;
2254 Lisp_Object value;
2256 if (NILP (frame))
2257 frame = selected_frame;
2258 else
2259 CHECK_FRAME (frame);
2260 CHECK_SYMBOL (parameter);
2262 f = XFRAME (frame);
2263 value = Qnil;
2265 if (FRAME_LIVE_P (f))
2267 /* Avoid consing in frequent cases. */
2268 if (EQ (parameter, Qname))
2269 value = f->name;
2270 #ifdef HAVE_X_WINDOWS
2271 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2272 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2273 #endif /* HAVE_X_WINDOWS */
2274 else if (EQ (parameter, Qbackground_color)
2275 || EQ (parameter, Qforeground_color))
2277 value = Fassq (parameter, f->param_alist);
2278 if (CONSP (value))
2280 value = XCDR (value);
2281 /* Fframe_parameters puts the actual fg/bg color names,
2282 even if f->param_alist says otherwise. This is
2283 important when param_alist's notion of colors is
2284 "unspecified". We need to do the same here. */
2285 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2287 const char *color_name;
2288 EMACS_INT csz;
2290 if (EQ (parameter, Qbackground_color))
2292 color_name = SDATA (value);
2293 csz = SCHARS (value);
2294 if (strncmp (color_name, unspecified_bg, csz) == 0)
2295 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2296 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2297 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2299 else if (EQ (parameter, Qforeground_color))
2301 color_name = SDATA (value);
2302 csz = SCHARS (value);
2303 if (strncmp (color_name, unspecified_fg, csz) == 0)
2304 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2305 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2306 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2310 else
2311 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2313 else if (EQ (parameter, Qdisplay_type)
2314 || EQ (parameter, Qbackground_mode))
2315 value = Fcdr (Fassq (parameter, f->param_alist));
2316 else
2317 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2320 return value;
2324 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2325 Smodify_frame_parameters, 2, 2, 0,
2326 doc: /* Modify the parameters of frame FRAME according to ALIST.
2327 If FRAME is nil, it defaults to the selected frame.
2328 ALIST is an alist of parameters to change and their new values.
2329 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2330 The meaningful PARMs depend on the kind of frame.
2331 Undefined PARMs are ignored, but stored in the frame's parameter list
2332 so that `frame-parameters' will return them.
2334 The value of frame parameter FOO can also be accessed
2335 as a frame-local binding for the variable FOO, if you have
2336 enabled such bindings for that variable with `make-variable-frame-local'. */)
2337 (frame, alist)
2338 Lisp_Object frame, alist;
2340 FRAME_PTR f;
2341 register Lisp_Object tail, prop, val;
2342 int count = SPECPDL_INDEX ();
2344 /* Bind this to t to inhibit initialization of the default face from
2345 X resources in face-set-after-frame-default. If we don't inhibit
2346 this, modifying the `font' frame parameter, for example, while
2347 there is a `default.attributeFont' X resource, won't work,
2348 because `default's font is reset to the value of the X resource
2349 and that resets the `font' frame parameter. */
2350 specbind (Qinhibit_default_face_x_resources, Qt);
2352 if (EQ (frame, Qnil))
2353 frame = selected_frame;
2354 CHECK_LIVE_FRAME (frame);
2355 f = XFRAME (frame);
2357 /* I think this should be done with a hook. */
2358 #ifdef HAVE_WINDOW_SYSTEM
2359 if (FRAME_WINDOW_P (f))
2360 x_set_frame_parameters (f, alist);
2361 else
2362 #endif
2363 #ifdef MSDOS
2364 if (FRAME_MSDOS_P (f))
2365 IT_set_frame_parameters (f, alist);
2366 else
2367 #endif
2370 int length = XINT (Flength (alist));
2371 int i;
2372 Lisp_Object *parms
2373 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2374 Lisp_Object *values
2375 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2377 /* Extract parm names and values into those vectors. */
2379 i = 0;
2380 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2382 Lisp_Object elt;
2384 elt = Fcar (tail);
2385 parms[i] = Fcar (elt);
2386 values[i] = Fcdr (elt);
2387 i++;
2390 /* Now process them in reverse of specified order. */
2391 for (i--; i >= 0; i--)
2393 prop = parms[i];
2394 val = values[i];
2395 store_frame_param (f, prop, val);
2399 return unbind_to (count, Qnil);
2402 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2403 0, 1, 0,
2404 doc: /* Height in pixels of a line in the font in frame FRAME.
2405 If FRAME is omitted, the selected frame is used.
2406 For a terminal frame, the value is always 1. */)
2407 (frame)
2408 Lisp_Object frame;
2410 struct frame *f;
2412 if (NILP (frame))
2413 frame = selected_frame;
2414 CHECK_FRAME (frame);
2415 f = XFRAME (frame);
2417 #ifdef HAVE_WINDOW_SYSTEM
2418 if (FRAME_WINDOW_P (f))
2419 return make_number (x_char_height (f));
2420 else
2421 #endif
2422 return make_number (1);
2426 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2427 0, 1, 0,
2428 doc: /* Width in pixels of characters in the font in frame FRAME.
2429 If FRAME is omitted, the selected frame is used.
2430 The width is the same for all characters, because
2431 currently Emacs supports only fixed-width fonts.
2432 For a terminal screen, the value is always 1. */)
2433 (frame)
2434 Lisp_Object frame;
2436 struct frame *f;
2438 if (NILP (frame))
2439 frame = selected_frame;
2440 CHECK_FRAME (frame);
2441 f = XFRAME (frame);
2443 #ifdef HAVE_WINDOW_SYSTEM
2444 if (FRAME_WINDOW_P (f))
2445 return make_number (x_char_width (f));
2446 else
2447 #endif
2448 return make_number (1);
2451 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2452 Sframe_pixel_height, 0, 1, 0,
2453 doc: /* Return a FRAME's height in pixels.
2454 This counts only the height available for text lines,
2455 not menu bars on window-system Emacs frames.
2456 For a terminal frame, the result really gives the height in characters.
2457 If FRAME is omitted, the selected frame is used. */)
2458 (frame)
2459 Lisp_Object frame;
2461 struct frame *f;
2463 if (NILP (frame))
2464 frame = selected_frame;
2465 CHECK_FRAME (frame);
2466 f = XFRAME (frame);
2468 #ifdef HAVE_WINDOW_SYSTEM
2469 if (FRAME_WINDOW_P (f))
2470 return make_number (x_pixel_height (f));
2471 else
2472 #endif
2473 return make_number (FRAME_LINES (f));
2476 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2477 Sframe_pixel_width, 0, 1, 0,
2478 doc: /* Return FRAME's width in pixels.
2479 For a terminal frame, the result really gives the width in characters.
2480 If FRAME is omitted, the selected frame is used. */)
2481 (frame)
2482 Lisp_Object frame;
2484 struct frame *f;
2486 if (NILP (frame))
2487 frame = selected_frame;
2488 CHECK_FRAME (frame);
2489 f = XFRAME (frame);
2491 #ifdef HAVE_WINDOW_SYSTEM
2492 if (FRAME_WINDOW_P (f))
2493 return make_number (x_pixel_width (f));
2494 else
2495 #endif
2496 return make_number (FRAME_COLS (f));
2499 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2500 doc: /* Specify that the frame FRAME has LINES lines.
2501 Optional third arg non-nil means that redisplay should use LINES lines
2502 but that the idea of the actual height of the frame should not be changed. */)
2503 (frame, lines, pretend)
2504 Lisp_Object frame, lines, pretend;
2506 register struct frame *f;
2508 CHECK_NUMBER (lines);
2509 if (NILP (frame))
2510 frame = selected_frame;
2511 CHECK_LIVE_FRAME (frame);
2512 f = XFRAME (frame);
2514 /* I think this should be done with a hook. */
2515 #ifdef HAVE_WINDOW_SYSTEM
2516 if (FRAME_WINDOW_P (f))
2518 if (XINT (lines) != FRAME_LINES (f))
2519 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2520 do_pending_window_change (0);
2522 else
2523 #endif
2524 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2525 return Qnil;
2528 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2529 doc: /* Specify that the frame FRAME has COLS columns.
2530 Optional third arg non-nil means that redisplay should use COLS columns
2531 but that the idea of the actual width of the frame should not be changed. */)
2532 (frame, cols, pretend)
2533 Lisp_Object frame, cols, pretend;
2535 register struct frame *f;
2536 CHECK_NUMBER (cols);
2537 if (NILP (frame))
2538 frame = selected_frame;
2539 CHECK_LIVE_FRAME (frame);
2540 f = XFRAME (frame);
2542 /* I think this should be done with a hook. */
2543 #ifdef HAVE_WINDOW_SYSTEM
2544 if (FRAME_WINDOW_P (f))
2546 if (XINT (cols) != FRAME_COLS (f))
2547 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2548 do_pending_window_change (0);
2550 else
2551 #endif
2552 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2553 return Qnil;
2556 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2557 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2558 (frame, cols, rows)
2559 Lisp_Object frame, cols, rows;
2561 register struct frame *f;
2563 CHECK_LIVE_FRAME (frame);
2564 CHECK_NUMBER (cols);
2565 CHECK_NUMBER (rows);
2566 f = XFRAME (frame);
2568 /* I think this should be done with a hook. */
2569 #ifdef HAVE_WINDOW_SYSTEM
2570 if (FRAME_WINDOW_P (f))
2572 if (XINT (rows) != FRAME_LINES (f)
2573 || XINT (cols) != FRAME_COLS (f)
2574 || f->new_text_lines || f->new_text_cols)
2575 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2576 do_pending_window_change (0);
2578 else
2579 #endif
2580 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2582 return Qnil;
2585 DEFUN ("set-frame-position", Fset_frame_position,
2586 Sset_frame_position, 3, 3, 0,
2587 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2588 This is actually the position of the upper left corner of the frame.
2589 Negative values for XOFFSET or YOFFSET are interpreted relative to
2590 the rightmost or bottommost possible position (that stays within the screen). */)
2591 (frame, xoffset, yoffset)
2592 Lisp_Object frame, xoffset, yoffset;
2594 register struct frame *f;
2596 CHECK_LIVE_FRAME (frame);
2597 CHECK_NUMBER (xoffset);
2598 CHECK_NUMBER (yoffset);
2599 f = XFRAME (frame);
2601 /* I think this should be done with a hook. */
2602 #ifdef HAVE_WINDOW_SYSTEM
2603 if (FRAME_WINDOW_P (f))
2604 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2605 #endif
2607 return Qt;
2611 /***********************************************************************
2612 Frame Parameters
2613 ***********************************************************************/
2615 /* Connect the frame-parameter names for X frames
2616 to the ways of passing the parameter values to the window system.
2618 The name of a parameter, as a Lisp symbol,
2619 has an `x-frame-parameter' property which is an integer in Lisp
2620 that is an index in this table. */
2622 struct frame_parm_table {
2623 char *name;
2624 Lisp_Object *variable;
2627 static struct frame_parm_table frame_parms[] =
2629 {"auto-raise", &Qauto_raise},
2630 {"auto-lower", &Qauto_lower},
2631 {"background-color", 0},
2632 {"border-color", &Qborder_color},
2633 {"border-width", &Qborder_width},
2634 {"cursor-color", &Qcursor_color},
2635 {"cursor-type", &Qcursor_type},
2636 {"font", 0},
2637 {"foreground-color", 0},
2638 {"icon-name", &Qicon_name},
2639 {"icon-type", &Qicon_type},
2640 {"internal-border-width", &Qinternal_border_width},
2641 {"menu-bar-lines", &Qmenu_bar_lines},
2642 {"mouse-color", &Qmouse_color},
2643 {"name", &Qname},
2644 {"scroll-bar-width", &Qscroll_bar_width},
2645 {"title", &Qtitle},
2646 {"unsplittable", &Qunsplittable},
2647 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2648 {"visibility", &Qvisibility},
2649 {"tool-bar-lines", &Qtool_bar_lines},
2650 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2651 {"scroll-bar-background", &Qscroll_bar_background},
2652 {"screen-gamma", &Qscreen_gamma},
2653 {"line-spacing", &Qline_spacing},
2654 {"left-fringe", &Qleft_fringe},
2655 {"right-fringe", &Qright_fringe},
2656 {"wait-for-wm", &Qwait_for_wm},
2657 {"fullscreen", &Qfullscreen},
2660 #ifdef HAVE_WINDOW_SYSTEM
2662 extern Lisp_Object Qbox;
2663 extern Lisp_Object Qtop;
2665 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2666 wanted positions of the WM window (not emacs window).
2667 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2668 window (FRAME_X_WINDOW).
2671 void
2672 x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2673 struct frame *f;
2674 int *width;
2675 int *height;
2676 int *top_pos;
2677 int *left_pos;
2679 int newwidth = FRAME_COLS (f);
2680 int newheight = FRAME_LINES (f);
2682 *top_pos = f->top_pos;
2683 *left_pos = f->left_pos;
2685 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2687 int ph;
2689 ph = FRAME_X_DISPLAY_INFO (f)->height;
2690 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2691 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2692 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2693 *top_pos = 0;
2696 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2698 int pw;
2700 pw = FRAME_X_DISPLAY_INFO (f)->width;
2701 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2702 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2703 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2704 *left_pos = 0;
2707 *width = newwidth;
2708 *height = newheight;
2712 /* Change the parameters of frame F as specified by ALIST.
2713 If a parameter is not specially recognized, do nothing special;
2714 otherwise call the `x_set_...' function for that parameter.
2715 Except for certain geometry properties, always call store_frame_param
2716 to store the new value in the parameter alist. */
2718 void
2719 x_set_frame_parameters (f, alist)
2720 FRAME_PTR f;
2721 Lisp_Object alist;
2723 Lisp_Object tail;
2725 /* If both of these parameters are present, it's more efficient to
2726 set them both at once. So we wait until we've looked at the
2727 entire list before we set them. */
2728 int width, height;
2730 /* Same here. */
2731 Lisp_Object left, top;
2733 /* Same with these. */
2734 Lisp_Object icon_left, icon_top;
2736 /* Record in these vectors all the parms specified. */
2737 Lisp_Object *parms;
2738 Lisp_Object *values;
2739 int i, p;
2740 int left_no_change = 0, top_no_change = 0;
2741 int icon_left_no_change = 0, icon_top_no_change = 0;
2742 int fullscreen_is_being_set = 0;
2744 struct gcpro gcpro1, gcpro2;
2746 i = 0;
2747 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2748 i++;
2750 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2751 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2753 /* Extract parm names and values into those vectors. */
2755 i = 0;
2756 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2758 Lisp_Object elt;
2760 elt = Fcar (tail);
2761 parms[i] = Fcar (elt);
2762 values[i] = Fcdr (elt);
2763 i++;
2765 /* TAIL and ALIST are not used again below here. */
2766 alist = tail = Qnil;
2768 GCPRO2 (*parms, *values);
2769 gcpro1.nvars = i;
2770 gcpro2.nvars = i;
2772 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2773 because their values appear in VALUES and strings are not valid. */
2774 top = left = Qunbound;
2775 icon_left = icon_top = Qunbound;
2777 /* Provide default values for HEIGHT and WIDTH. */
2778 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2779 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2781 /* Process foreground_color and background_color before anything else.
2782 They are independent of other properties, but other properties (e.g.,
2783 cursor_color) are dependent upon them. */
2784 /* Process default font as well, since fringe widths depends on it. */
2785 /* Also, process fullscreen, width and height depend upon that */
2786 for (p = 0; p < i; p++)
2788 Lisp_Object prop, val;
2790 prop = parms[p];
2791 val = values[p];
2792 if (EQ (prop, Qforeground_color)
2793 || EQ (prop, Qbackground_color)
2794 || EQ (prop, Qfont)
2795 || EQ (prop, Qfullscreen))
2797 register Lisp_Object param_index, old_value;
2799 old_value = get_frame_param (f, prop);
2800 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
2802 if (NILP (Fequal (val, old_value)))
2804 store_frame_param (f, prop, val);
2806 param_index = Fget (prop, Qx_frame_parameter);
2807 if (NATNUMP (param_index)
2808 && (XFASTINT (param_index)
2809 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2810 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2811 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2816 /* Now process them in reverse of specified order. */
2817 for (i--; i >= 0; i--)
2819 Lisp_Object prop, val;
2821 prop = parms[i];
2822 val = values[i];
2824 if (EQ (prop, Qwidth) && NUMBERP (val))
2825 width = XFASTINT (val);
2826 else if (EQ (prop, Qheight) && NUMBERP (val))
2827 height = XFASTINT (val);
2828 else if (EQ (prop, Qtop))
2829 top = val;
2830 else if (EQ (prop, Qleft))
2831 left = val;
2832 else if (EQ (prop, Qicon_top))
2833 icon_top = val;
2834 else if (EQ (prop, Qicon_left))
2835 icon_left = val;
2836 else if (EQ (prop, Qforeground_color)
2837 || EQ (prop, Qbackground_color)
2838 || EQ (prop, Qfont)
2839 || EQ (prop, Qfullscreen))
2840 /* Processed above. */
2841 continue;
2842 else
2844 register Lisp_Object param_index, old_value;
2846 old_value = get_frame_param (f, prop);
2848 store_frame_param (f, prop, val);
2850 param_index = Fget (prop, Qx_frame_parameter);
2851 if (NATNUMP (param_index)
2852 && (XFASTINT (param_index)
2853 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2854 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2855 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2859 /* Don't die if just one of these was set. */
2860 if (EQ (left, Qunbound))
2862 left_no_change = 1;
2863 if (f->left_pos < 0)
2864 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
2865 else
2866 XSETINT (left, f->left_pos);
2868 if (EQ (top, Qunbound))
2870 top_no_change = 1;
2871 if (f->top_pos < 0)
2872 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
2873 else
2874 XSETINT (top, f->top_pos);
2877 /* If one of the icon positions was not set, preserve or default it. */
2878 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
2880 icon_left_no_change = 1;
2881 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2882 if (NILP (icon_left))
2883 XSETINT (icon_left, 0);
2885 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
2887 icon_top_no_change = 1;
2888 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2889 if (NILP (icon_top))
2890 XSETINT (icon_top, 0);
2893 #ifndef HAVE_CARBON
2894 /* MAC_TODO: fullscreen */
2895 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
2897 /* If the frame is visible already and the fullscreen parameter is
2898 being set, it is too late to set WM manager hints to specify
2899 size and position.
2900 Here we first get the width, height and position that applies to
2901 fullscreen. We then move the frame to the appropriate
2902 position. Resize of the frame is taken care of in the code after
2903 this if-statement. */
2904 int new_left, new_top;
2906 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
2907 if (new_top != f->top_pos || new_left != f->left_pos)
2908 x_set_offset (f, new_left, new_top, 1);
2910 #endif
2912 /* Don't set these parameters unless they've been explicitly
2913 specified. The window might be mapped or resized while we're in
2914 this function, and we don't want to override that unless the lisp
2915 code has asked for it.
2917 Don't set these parameters unless they actually differ from the
2918 window's current parameters; the window may not actually exist
2919 yet. */
2921 Lisp_Object frame;
2923 check_frame_size (f, &height, &width);
2925 XSETFRAME (frame, f);
2927 if (width != FRAME_COLS (f)
2928 || height != FRAME_LINES (f)
2929 || f->new_text_lines || f->new_text_cols)
2930 Fset_frame_size (frame, make_number (width), make_number (height));
2932 if ((!NILP (left) || !NILP (top))
2933 && ! (left_no_change && top_no_change)
2934 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2935 && NUMBERP (top) && XINT (top) == f->top_pos))
2937 int leftpos = 0;
2938 int toppos = 0;
2940 /* Record the signs. */
2941 f->size_hint_flags &= ~ (XNegative | YNegative);
2942 if (EQ (left, Qminus))
2943 f->size_hint_flags |= XNegative;
2944 else if (INTEGERP (left))
2946 leftpos = XINT (left);
2947 if (leftpos < 0)
2948 f->size_hint_flags |= XNegative;
2950 else if (CONSP (left) && EQ (XCAR (left), Qminus)
2951 && CONSP (XCDR (left))
2952 && INTEGERP (XCAR (XCDR (left))))
2954 leftpos = - XINT (XCAR (XCDR (left)));
2955 f->size_hint_flags |= XNegative;
2957 else if (CONSP (left) && EQ (XCAR (left), Qplus)
2958 && CONSP (XCDR (left))
2959 && INTEGERP (XCAR (XCDR (left))))
2961 leftpos = XINT (XCAR (XCDR (left)));
2964 if (EQ (top, Qminus))
2965 f->size_hint_flags |= YNegative;
2966 else if (INTEGERP (top))
2968 toppos = XINT (top);
2969 if (toppos < 0)
2970 f->size_hint_flags |= YNegative;
2972 else if (CONSP (top) && EQ (XCAR (top), Qminus)
2973 && CONSP (XCDR (top))
2974 && INTEGERP (XCAR (XCDR (top))))
2976 toppos = - XINT (XCAR (XCDR (top)));
2977 f->size_hint_flags |= YNegative;
2979 else if (CONSP (top) && EQ (XCAR (top), Qplus)
2980 && CONSP (XCDR (top))
2981 && INTEGERP (XCAR (XCDR (top))))
2983 toppos = XINT (XCAR (XCDR (top)));
2987 /* Store the numeric value of the position. */
2988 f->top_pos = toppos;
2989 f->left_pos = leftpos;
2991 f->win_gravity = NorthWestGravity;
2993 /* Actually set that position, and convert to absolute. */
2994 x_set_offset (f, leftpos, toppos, -1);
2997 if ((!NILP (icon_left) || !NILP (icon_top))
2998 && ! (icon_left_no_change && icon_top_no_change))
2999 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3002 UNGCPRO;
3006 /* Insert a description of internally-recorded parameters of frame X
3007 into the parameter alist *ALISTPTR that is to be given to the user.
3008 Only parameters that are specific to the X window system
3009 and whose values are not correctly recorded in the frame's
3010 param_alist need to be considered here. */
3012 void
3013 x_report_frame_params (f, alistptr)
3014 struct frame *f;
3015 Lisp_Object *alistptr;
3017 char buf[16];
3018 Lisp_Object tem;
3020 /* Represent negative positions (off the top or left screen edge)
3021 in a way that Fmodify_frame_parameters will understand correctly. */
3022 XSETINT (tem, f->left_pos);
3023 if (f->left_pos >= 0)
3024 store_in_alist (alistptr, Qleft, tem);
3025 else
3026 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3028 XSETINT (tem, f->top_pos);
3029 if (f->top_pos >= 0)
3030 store_in_alist (alistptr, Qtop, tem);
3031 else
3032 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3034 store_in_alist (alistptr, Qborder_width,
3035 make_number (f->border_width));
3036 store_in_alist (alistptr, Qinternal_border_width,
3037 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3038 store_in_alist (alistptr, Qleft_fringe,
3039 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3040 store_in_alist (alistptr, Qright_fringe,
3041 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3042 store_in_alist (alistptr, Qscroll_bar_width,
3043 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3044 ? make_number (0)
3045 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3046 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3047 /* nil means "use default width"
3048 for non-toolkit scroll bar.
3049 ruler-mode.el depends on this. */
3050 : Qnil));
3051 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3052 store_in_alist (alistptr, Qwindow_id,
3053 build_string (buf));
3054 #ifdef HAVE_X_WINDOWS
3055 #ifdef USE_X_TOOLKIT
3056 /* Tooltip frame may not have this widget. */
3057 if (FRAME_X_OUTPUT (f)->widget)
3058 #endif
3059 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3060 store_in_alist (alistptr, Qouter_window_id,
3061 build_string (buf));
3062 #endif
3063 store_in_alist (alistptr, Qicon_name, f->icon_name);
3064 FRAME_SAMPLE_VISIBILITY (f);
3065 store_in_alist (alistptr, Qvisibility,
3066 (FRAME_VISIBLE_P (f) ? Qt
3067 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3068 store_in_alist (alistptr, Qdisplay,
3069 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3071 #ifndef HAVE_CARBON
3072 /* A Mac Window is identified by a struct, not an integer. */
3073 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3074 tem = Qnil;
3075 else
3076 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3077 store_in_alist (alistptr, Qparent_id, tem);
3078 #endif
3082 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3083 the previous value of that parameter, NEW_VALUE is the new value. */
3085 void
3086 x_set_fullscreen (f, new_value, old_value)
3087 struct frame *f;
3088 Lisp_Object new_value, old_value;
3090 #ifndef HAVE_CARBON
3091 if (NILP (new_value))
3092 f->want_fullscreen = FULLSCREEN_NONE;
3093 else if (EQ (new_value, Qfullboth))
3094 f->want_fullscreen = FULLSCREEN_BOTH;
3095 else if (EQ (new_value, Qfullwidth))
3096 f->want_fullscreen = FULLSCREEN_WIDTH;
3097 else if (EQ (new_value, Qfullheight))
3098 f->want_fullscreen = FULLSCREEN_HEIGHT;
3099 #endif
3103 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3104 the previous value of that parameter, NEW_VALUE is the new value. */
3106 void
3107 x_set_line_spacing (f, new_value, old_value)
3108 struct frame *f;
3109 Lisp_Object new_value, old_value;
3111 if (NILP (new_value))
3112 f->extra_line_spacing = 0;
3113 else if (NATNUMP (new_value))
3114 f->extra_line_spacing = XFASTINT (new_value);
3115 else
3116 Fsignal (Qerror, Fcons (build_string ("Invalid line-spacing"),
3117 Fcons (new_value, Qnil)));
3118 if (FRAME_VISIBLE_P (f))
3119 redraw_frame (f);
3123 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3124 the previous value of that parameter, NEW_VALUE is the new value. */
3126 void
3127 x_set_screen_gamma (f, new_value, old_value)
3128 struct frame *f;
3129 Lisp_Object new_value, old_value;
3131 if (NILP (new_value))
3132 f->gamma = 0;
3133 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3134 /* The value 0.4545 is the normal viewing gamma. */
3135 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3136 else
3137 Fsignal (Qerror, Fcons (build_string ("Invalid screen-gamma"),
3138 Fcons (new_value, Qnil)));
3140 clear_face_cache (0);
3144 void
3145 x_set_font (f, arg, oldval)
3146 struct frame *f;
3147 Lisp_Object arg, oldval;
3149 Lisp_Object result;
3150 Lisp_Object fontset_name;
3151 Lisp_Object frame;
3152 int old_fontset = FRAME_FONTSET(f);
3154 CHECK_STRING (arg);
3156 fontset_name = Fquery_fontset (arg, Qnil);
3158 BLOCK_INPUT;
3159 result = (STRINGP (fontset_name)
3160 ? x_new_fontset (f, SDATA (fontset_name))
3161 : x_new_font (f, SDATA (arg)));
3162 UNBLOCK_INPUT;
3164 if (EQ (result, Qnil))
3165 error ("Font `%s' is not defined", SDATA (arg));
3166 else if (EQ (result, Qt))
3167 error ("The characters of the given font have varying widths");
3168 else if (STRINGP (result))
3170 if (STRINGP (fontset_name))
3172 /* Fontset names are built from ASCII font names, so the
3173 names may be equal despite there was a change. */
3174 if (old_fontset == FRAME_FONTSET (f))
3175 return;
3177 else if (!NILP (Fequal (result, oldval)))
3178 return;
3180 store_frame_param (f, Qfont, result);
3181 recompute_basic_faces (f);
3183 else
3184 abort ();
3186 do_pending_window_change (0);
3188 /* Don't call `face-set-after-frame-default' when faces haven't been
3189 initialized yet. This is the case when called from
3190 Fx_create_frame. In that case, the X widget or window doesn't
3191 exist either, and we can end up in x_report_frame_params with a
3192 null widget which gives a segfault. */
3193 if (FRAME_FACE_CACHE (f))
3195 XSETFRAME (frame, f);
3196 call1 (Qface_set_after_frame_default, frame);
3201 void
3202 x_set_fringe_width (f, new_value, old_value)
3203 struct frame *f;
3204 Lisp_Object new_value, old_value;
3206 compute_fringe_widths (f, 1);
3209 void
3210 x_set_border_width (f, arg, oldval)
3211 struct frame *f;
3212 Lisp_Object arg, oldval;
3214 CHECK_NUMBER (arg);
3216 if (XINT (arg) == f->border_width)
3217 return;
3219 #ifndef HAVE_CARBON
3220 if (FRAME_X_WINDOW (f) != 0)
3221 error ("Cannot change the border width of a window");
3222 #endif /* MAC_TODO */
3224 f->border_width = XINT (arg);
3227 void
3228 x_set_internal_border_width (f, arg, oldval)
3229 struct frame *f;
3230 Lisp_Object arg, oldval;
3232 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3234 CHECK_NUMBER (arg);
3235 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3236 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3237 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3239 #ifdef USE_X_TOOLKIT
3240 if (FRAME_X_OUTPUT (f)->edit_widget)
3241 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3242 #endif
3244 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3245 return;
3247 if (FRAME_X_WINDOW (f) != 0)
3249 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3250 SET_FRAME_GARBAGED (f);
3251 do_pending_window_change (0);
3253 else
3254 SET_FRAME_GARBAGED (f);
3257 void
3258 x_set_visibility (f, value, oldval)
3259 struct frame *f;
3260 Lisp_Object value, oldval;
3262 Lisp_Object frame;
3263 XSETFRAME (frame, f);
3265 if (NILP (value))
3266 Fmake_frame_invisible (frame, Qt);
3267 else if (EQ (value, Qicon))
3268 Ficonify_frame (frame);
3269 else
3270 Fmake_frame_visible (frame);
3273 void
3274 x_set_autoraise (f, arg, oldval)
3275 struct frame *f;
3276 Lisp_Object arg, oldval;
3278 f->auto_raise = !EQ (Qnil, arg);
3281 void
3282 x_set_autolower (f, arg, oldval)
3283 struct frame *f;
3284 Lisp_Object arg, oldval;
3286 f->auto_lower = !EQ (Qnil, arg);
3289 void
3290 x_set_unsplittable (f, arg, oldval)
3291 struct frame *f;
3292 Lisp_Object arg, oldval;
3294 f->no_split = !NILP (arg);
3297 void
3298 x_set_vertical_scroll_bars (f, arg, oldval)
3299 struct frame *f;
3300 Lisp_Object arg, oldval;
3302 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3303 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3304 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3305 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3307 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3308 = (NILP (arg)
3309 ? vertical_scroll_bar_none
3310 : EQ (Qleft, arg)
3311 ? vertical_scroll_bar_left
3312 : EQ (Qright, arg)
3313 ? vertical_scroll_bar_right
3314 : EQ (Qleft, Vdefault_frame_scroll_bars)
3315 ? vertical_scroll_bar_left
3316 : EQ (Qright, Vdefault_frame_scroll_bars)
3317 ? vertical_scroll_bar_right
3318 : vertical_scroll_bar_none);
3320 /* We set this parameter before creating the X window for the
3321 frame, so we can get the geometry right from the start.
3322 However, if the window hasn't been created yet, we shouldn't
3323 call x_set_window_size. */
3324 if (FRAME_X_WINDOW (f))
3325 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3326 do_pending_window_change (0);
3330 void
3331 x_set_scroll_bar_width (f, arg, oldval)
3332 struct frame *f;
3333 Lisp_Object arg, oldval;
3335 int wid = FRAME_COLUMN_WIDTH (f);
3337 if (NILP (arg))
3339 x_set_scroll_bar_default_width (f);
3341 if (FRAME_X_WINDOW (f))
3342 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3343 do_pending_window_change (0);
3345 else if (INTEGERP (arg) && XINT (arg) > 0
3346 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3348 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3349 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3351 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3352 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3353 if (FRAME_X_WINDOW (f))
3354 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3355 do_pending_window_change (0);
3358 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3359 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3360 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3365 /* Return non-nil if frame F wants a bitmap icon. */
3367 Lisp_Object
3368 x_icon_type (f)
3369 FRAME_PTR f;
3371 Lisp_Object tem;
3373 tem = assq_no_quit (Qicon_type, f->param_alist);
3374 if (CONSP (tem))
3375 return XCDR (tem);
3376 else
3377 return Qnil;
3381 /* Subroutines of creating an X frame. */
3383 /* Make sure that Vx_resource_name is set to a reasonable value.
3384 Fix it up, or set it to `emacs' if it is too hopeless. */
3386 void
3387 validate_x_resource_name ()
3389 int len = 0;
3390 /* Number of valid characters in the resource name. */
3391 int good_count = 0;
3392 /* Number of invalid characters in the resource name. */
3393 int bad_count = 0;
3394 Lisp_Object new;
3395 int i;
3397 if (!STRINGP (Vx_resource_class))
3398 Vx_resource_class = build_string (EMACS_CLASS);
3400 if (STRINGP (Vx_resource_name))
3402 unsigned char *p = SDATA (Vx_resource_name);
3403 int i;
3405 len = SBYTES (Vx_resource_name);
3407 /* Only letters, digits, - and _ are valid in resource names.
3408 Count the valid characters and count the invalid ones. */
3409 for (i = 0; i < len; i++)
3411 int c = p[i];
3412 if (! ((c >= 'a' && c <= 'z')
3413 || (c >= 'A' && c <= 'Z')
3414 || (c >= '0' && c <= '9')
3415 || c == '-' || c == '_'))
3416 bad_count++;
3417 else
3418 good_count++;
3421 else
3422 /* Not a string => completely invalid. */
3423 bad_count = 5, good_count = 0;
3425 /* If name is valid already, return. */
3426 if (bad_count == 0)
3427 return;
3429 /* If name is entirely invalid, or nearly so, use `emacs'. */
3430 if (good_count == 0
3431 || (good_count == 1 && bad_count > 0))
3433 Vx_resource_name = build_string ("emacs");
3434 return;
3437 /* Name is partly valid. Copy it and replace the invalid characters
3438 with underscores. */
3440 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3442 for (i = 0; i < len; i++)
3444 int c = SREF (new, i);
3445 if (! ((c >= 'a' && c <= 'z')
3446 || (c >= 'A' && c <= 'Z')
3447 || (c >= '0' && c <= '9')
3448 || c == '-' || c == '_'))
3449 SSET (new, i, '_');
3454 extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3455 extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3458 /* Get specified attribute from resource database RDB.
3459 See Fx_get_resource below for other parameters. */
3461 static Lisp_Object
3462 xrdb_get_resource (rdb, attribute, class, component, subclass)
3463 XrmDatabase rdb;
3464 Lisp_Object attribute, class, component, subclass;
3466 register char *value;
3467 char *name_key;
3468 char *class_key;
3470 CHECK_STRING (attribute);
3471 CHECK_STRING (class);
3473 if (!NILP (component))
3474 CHECK_STRING (component);
3475 if (!NILP (subclass))
3476 CHECK_STRING (subclass);
3477 if (NILP (component) != NILP (subclass))
3478 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3480 validate_x_resource_name ();
3482 /* Allocate space for the components, the dots which separate them,
3483 and the final '\0'. Make them big enough for the worst case. */
3484 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3485 + (STRINGP (component)
3486 ? SBYTES (component) : 0)
3487 + SBYTES (attribute)
3488 + 3);
3490 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3491 + SBYTES (class)
3492 + (STRINGP (subclass)
3493 ? SBYTES (subclass) : 0)
3494 + 3);
3496 /* Start with emacs.FRAMENAME for the name (the specific one)
3497 and with `Emacs' for the class key (the general one). */
3498 strcpy (name_key, SDATA (Vx_resource_name));
3499 strcpy (class_key, SDATA (Vx_resource_class));
3501 strcat (class_key, ".");
3502 strcat (class_key, SDATA (class));
3504 if (!NILP (component))
3506 strcat (class_key, ".");
3507 strcat (class_key, SDATA (subclass));
3509 strcat (name_key, ".");
3510 strcat (name_key, SDATA (component));
3513 strcat (name_key, ".");
3514 strcat (name_key, SDATA (attribute));
3516 value = x_get_string_resource (rdb, name_key, class_key);
3518 if (value != (char *) 0)
3519 return build_string (value);
3520 else
3521 return Qnil;
3525 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3526 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3527 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3528 class, where INSTANCE is the name under which Emacs was invoked, or
3529 the name specified by the `-name' or `-rn' command-line arguments.
3531 The optional arguments COMPONENT and SUBCLASS add to the key and the
3532 class, respectively. You must specify both of them or neither.
3533 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3534 and the class is `Emacs.CLASS.SUBCLASS'. */)
3535 (attribute, class, component, subclass)
3536 Lisp_Object attribute, class, component, subclass;
3538 #ifdef HAVE_X_WINDOWS
3539 check_x ();
3540 #endif
3542 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3543 attribute, class, component, subclass);
3546 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3548 Lisp_Object
3549 display_x_get_resource (dpyinfo, attribute, class, component, subclass)
3550 Display_Info *dpyinfo;
3551 Lisp_Object attribute, class, component, subclass;
3553 return xrdb_get_resource (dpyinfo->xrdb,
3554 attribute, class, component, subclass);
3557 /* Used when C code wants a resource value. */
3559 char *
3560 x_get_resource_string (attribute, class)
3561 char *attribute, *class;
3563 char *name_key;
3564 char *class_key;
3565 struct frame *sf = SELECTED_FRAME ();
3567 /* Allocate space for the components, the dots which separate them,
3568 and the final '\0'. */
3569 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3570 + strlen (attribute) + 2);
3571 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3572 + strlen (class) + 2);
3574 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3575 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3577 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3578 name_key, class_key);
3582 /* Return the value of parameter PARAM.
3584 First search ALIST, then Vdefault_frame_alist, then the X defaults
3585 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3587 Convert the resource to the type specified by desired_type.
3589 If no default is specified, return Qunbound. If you call
3590 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3591 and don't let it get stored in any Lisp-visible variables! */
3593 Lisp_Object
3594 x_get_arg (dpyinfo, alist, param, attribute, class, type)
3595 Display_Info *dpyinfo;
3596 Lisp_Object alist, param;
3597 char *attribute;
3598 char *class;
3599 enum resource_types type;
3601 register Lisp_Object tem;
3603 tem = Fassq (param, alist);
3604 if (EQ (tem, Qnil))
3605 tem = Fassq (param, Vdefault_frame_alist);
3606 if (EQ (tem, Qnil))
3608 if (attribute)
3610 tem = display_x_get_resource (dpyinfo,
3611 build_string (attribute),
3612 build_string (class),
3613 Qnil, Qnil);
3615 if (NILP (tem))
3616 return Qunbound;
3618 switch (type)
3620 case RES_TYPE_NUMBER:
3621 return make_number (atoi (SDATA (tem)));
3623 case RES_TYPE_FLOAT:
3624 return make_float (atof (SDATA (tem)));
3626 case RES_TYPE_BOOLEAN:
3627 tem = Fdowncase (tem);
3628 if (!strcmp (SDATA (tem), "on")
3629 || !strcmp (SDATA (tem), "true"))
3630 return Qt;
3631 else
3632 return Qnil;
3634 case RES_TYPE_STRING:
3635 return tem;
3637 case RES_TYPE_SYMBOL:
3638 /* As a special case, we map the values `true' and `on'
3639 to Qt, and `false' and `off' to Qnil. */
3641 Lisp_Object lower;
3642 lower = Fdowncase (tem);
3643 if (!strcmp (SDATA (lower), "on")
3644 || !strcmp (SDATA (lower), "true"))
3645 return Qt;
3646 else if (!strcmp (SDATA (lower), "off")
3647 || !strcmp (SDATA (lower), "false"))
3648 return Qnil;
3649 else
3650 return Fintern (tem, Qnil);
3653 default:
3654 abort ();
3657 else
3658 return Qunbound;
3660 return Fcdr (tem);
3663 Lisp_Object
3664 x_frame_get_arg (f, alist, param, attribute, class, type)
3665 struct frame *f;
3666 Lisp_Object alist, param;
3667 char *attribute;
3668 char *class;
3669 enum resource_types type;
3671 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3672 alist, param, attribute, class, type);
3675 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3677 Lisp_Object
3678 x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
3679 struct frame *f;
3680 Lisp_Object alist, param;
3681 char *attribute;
3682 char *class;
3683 enum resource_types type;
3685 Lisp_Object value;
3687 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3688 attribute, class, type);
3689 if (! NILP (value))
3690 store_frame_param (f, param, value);
3692 return value;
3696 /* Record in frame F the specified or default value according to ALIST
3697 of the parameter named PROP (a Lisp symbol).
3698 If no value is specified for PROP, look for an X default for XPROP
3699 on the frame named NAME.
3700 If that is not found either, use the value DEFLT. */
3702 Lisp_Object
3703 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
3704 struct frame *f;
3705 Lisp_Object alist;
3706 Lisp_Object prop;
3707 Lisp_Object deflt;
3708 char *xprop;
3709 char *xclass;
3710 enum resource_types type;
3712 Lisp_Object tem;
3714 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3715 if (EQ (tem, Qunbound))
3716 tem = deflt;
3717 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3718 return tem;
3724 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3725 doc: /* Parse an X-style geometry string STRING.
3726 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3727 The properties returned may include `top', `left', `height', and `width'.
3728 The value of `left' or `top' may be an integer,
3729 or a list (+ N) meaning N pixels relative to top/left corner,
3730 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3731 (string)
3732 Lisp_Object string;
3734 int geometry, x, y;
3735 unsigned int width, height;
3736 Lisp_Object result;
3738 CHECK_STRING (string);
3740 geometry = XParseGeometry ((char *) SDATA (string),
3741 &x, &y, &width, &height);
3743 #if 0
3744 if (!!(geometry & XValue) != !!(geometry & YValue))
3745 error ("Must specify both x and y position, or neither");
3746 #endif
3748 result = Qnil;
3749 if (geometry & XValue)
3751 Lisp_Object element;
3753 if (x >= 0 && (geometry & XNegative))
3754 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3755 else if (x < 0 && ! (geometry & XNegative))
3756 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3757 else
3758 element = Fcons (Qleft, make_number (x));
3759 result = Fcons (element, result);
3762 if (geometry & YValue)
3764 Lisp_Object element;
3766 if (y >= 0 && (geometry & YNegative))
3767 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3768 else if (y < 0 && ! (geometry & YNegative))
3769 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3770 else
3771 element = Fcons (Qtop, make_number (y));
3772 result = Fcons (element, result);
3775 if (geometry & WidthValue)
3776 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3777 if (geometry & HeightValue)
3778 result = Fcons (Fcons (Qheight, make_number (height)), result);
3780 return result;
3783 /* Calculate the desired size and position of frame F.
3784 Return the flags saying which aspects were specified.
3786 Also set the win_gravity and size_hint_flags of F.
3788 Adjust height for toolbar if TOOLBAR_P is 1.
3790 This function does not make the coordinates positive. */
3792 #define DEFAULT_ROWS 40
3793 #define DEFAULT_COLS 80
3796 x_figure_window_size (f, parms, toolbar_p)
3797 struct frame *f;
3798 Lisp_Object parms;
3799 int toolbar_p;
3801 register Lisp_Object tem0, tem1, tem2;
3802 long window_prompting = 0;
3803 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3805 /* Default values if we fall through.
3806 Actually, if that happens we should get
3807 window manager prompting. */
3808 SET_FRAME_COLS (f, DEFAULT_COLS);
3809 FRAME_LINES (f) = DEFAULT_ROWS;
3810 /* Window managers expect that if program-specified
3811 positions are not (0,0), they're intentional, not defaults. */
3812 f->top_pos = 0;
3813 f->left_pos = 0;
3815 /* Ensure that old new_text_cols and new_text_lines will not override the
3816 values set here. */
3817 /* ++KFS: This was specific to W32, but seems ok for all platforms */
3818 f->new_text_cols = f->new_text_lines = 0;
3820 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
3821 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
3822 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
3823 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3825 if (!EQ (tem0, Qunbound))
3827 CHECK_NUMBER (tem0);
3828 FRAME_LINES (f) = XINT (tem0);
3830 if (!EQ (tem1, Qunbound))
3832 CHECK_NUMBER (tem1);
3833 SET_FRAME_COLS (f, XINT (tem1));
3835 if (!NILP (tem2) && !EQ (tem2, Qunbound))
3836 window_prompting |= USSize;
3837 else
3838 window_prompting |= PSize;
3841 f->scroll_bar_actual_width
3842 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
3844 /* This used to be done _before_ calling x_figure_window_size, but
3845 since the height is reset here, this was really a no-op. I
3846 assume that moving it here does what Gerd intended (although he
3847 no longer can remember what that was... ++KFS, 2003-03-25. */
3849 /* Add the tool-bar height to the initial frame height so that the
3850 user gets a text display area of the size he specified with -g or
3851 via .Xdefaults. Later changes of the tool-bar height don't
3852 change the frame size. This is done so that users can create
3853 tall Emacs frames without having to guess how tall the tool-bar
3854 will get. */
3855 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
3857 int margin, relief, bar_height;
3859 relief = (tool_bar_button_relief >= 0
3860 ? tool_bar_button_relief
3861 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
3863 if (INTEGERP (Vtool_bar_button_margin)
3864 && XINT (Vtool_bar_button_margin) > 0)
3865 margin = XFASTINT (Vtool_bar_button_margin);
3866 else if (CONSP (Vtool_bar_button_margin)
3867 && INTEGERP (XCDR (Vtool_bar_button_margin))
3868 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
3869 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
3870 else
3871 margin = 0;
3873 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
3874 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
3877 compute_fringe_widths (f, 0);
3879 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
3880 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
3882 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
3883 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
3884 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
3885 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3887 if (EQ (tem0, Qminus))
3889 f->top_pos = 0;
3890 window_prompting |= YNegative;
3892 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
3893 && CONSP (XCDR (tem0))
3894 && INTEGERP (XCAR (XCDR (tem0))))
3896 f->top_pos = - XINT (XCAR (XCDR (tem0)));
3897 window_prompting |= YNegative;
3899 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
3900 && CONSP (XCDR (tem0))
3901 && INTEGERP (XCAR (XCDR (tem0))))
3903 f->top_pos = XINT (XCAR (XCDR (tem0)));
3905 else if (EQ (tem0, Qunbound))
3906 f->top_pos = 0;
3907 else
3909 CHECK_NUMBER (tem0);
3910 f->top_pos = XINT (tem0);
3911 if (f->top_pos < 0)
3912 window_prompting |= YNegative;
3915 if (EQ (tem1, Qminus))
3917 f->left_pos = 0;
3918 window_prompting |= XNegative;
3920 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
3921 && CONSP (XCDR (tem1))
3922 && INTEGERP (XCAR (XCDR (tem1))))
3924 f->left_pos = - XINT (XCAR (XCDR (tem1)));
3925 window_prompting |= XNegative;
3927 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
3928 && CONSP (XCDR (tem1))
3929 && INTEGERP (XCAR (XCDR (tem1))))
3931 f->left_pos = XINT (XCAR (XCDR (tem1)));
3933 else if (EQ (tem1, Qunbound))
3934 f->left_pos = 0;
3935 else
3937 CHECK_NUMBER (tem1);
3938 f->left_pos = XINT (tem1);
3939 if (f->left_pos < 0)
3940 window_prompting |= XNegative;
3943 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
3944 window_prompting |= USPosition;
3945 else
3946 window_prompting |= PPosition;
3949 if (f->want_fullscreen != FULLSCREEN_NONE)
3951 int left, top;
3952 int width, height;
3954 /* It takes both for some WM:s to place it where we want */
3955 window_prompting = USPosition | PPosition;
3956 x_fullscreen_adjust (f, &width, &height, &top, &left);
3957 FRAME_COLS (f) = width;
3958 FRAME_LINES (f) = height;
3959 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
3960 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
3961 f->left_pos = left;
3962 f->top_pos = top;
3965 if (window_prompting & XNegative)
3967 if (window_prompting & YNegative)
3968 f->win_gravity = SouthEastGravity;
3969 else
3970 f->win_gravity = NorthEastGravity;
3972 else
3974 if (window_prompting & YNegative)
3975 f->win_gravity = SouthWestGravity;
3976 else
3977 f->win_gravity = NorthWestGravity;
3980 f->size_hint_flags = window_prompting;
3982 return window_prompting;
3987 #endif /* HAVE_WINDOW_SYSTEM */
3991 /***********************************************************************
3992 Initialization
3993 ***********************************************************************/
3995 void
3996 syms_of_frame ()
3998 Qframep = intern ("framep");
3999 staticpro (&Qframep);
4000 Qframe_live_p = intern ("frame-live-p");
4001 staticpro (&Qframe_live_p);
4002 Qheight = intern ("height");
4003 staticpro (&Qheight);
4004 Qicon = intern ("icon");
4005 staticpro (&Qicon);
4006 Qminibuffer = intern ("minibuffer");
4007 staticpro (&Qminibuffer);
4008 Qmodeline = intern ("modeline");
4009 staticpro (&Qmodeline);
4010 Qonly = intern ("only");
4011 staticpro (&Qonly);
4012 Qwidth = intern ("width");
4013 staticpro (&Qwidth);
4014 Qgeometry = intern ("geometry");
4015 staticpro (&Qgeometry);
4016 Qicon_left = intern ("icon-left");
4017 staticpro (&Qicon_left);
4018 Qicon_top = intern ("icon-top");
4019 staticpro (&Qicon_top);
4020 Qleft = intern ("left");
4021 staticpro (&Qleft);
4022 Qright = intern ("right");
4023 staticpro (&Qright);
4024 Quser_position = intern ("user-position");
4025 staticpro (&Quser_position);
4026 Quser_size = intern ("user-size");
4027 staticpro (&Quser_size);
4028 Qwindow_id = intern ("window-id");
4029 staticpro (&Qwindow_id);
4030 #ifdef HAVE_X_WINDOWS
4031 Qouter_window_id = intern ("outer-window-id");
4032 staticpro (&Qouter_window_id);
4033 #endif
4034 Qparent_id = intern ("parent-id");
4035 staticpro (&Qparent_id);
4036 Qx = intern ("x");
4037 staticpro (&Qx);
4038 Qw32 = intern ("w32");
4039 staticpro (&Qw32);
4040 Qpc = intern ("pc");
4041 staticpro (&Qpc);
4042 Qmac = intern ("mac");
4043 staticpro (&Qmac);
4044 Qvisible = intern ("visible");
4045 staticpro (&Qvisible);
4046 Qbuffer_predicate = intern ("buffer-predicate");
4047 staticpro (&Qbuffer_predicate);
4048 Qbuffer_list = intern ("buffer-list");
4049 staticpro (&Qbuffer_list);
4050 Qdisplay_type = intern ("display-type");
4051 staticpro (&Qdisplay_type);
4052 Qbackground_mode = intern ("background-mode");
4053 staticpro (&Qbackground_mode);
4054 Qtty_color_mode = intern ("tty-color-mode");
4055 staticpro (&Qtty_color_mode);
4056 Qtty = intern ("tty");
4057 staticpro (&Qtty);
4058 Qtty_type = intern ("tty-type");
4059 staticpro (&Qtty_type);
4061 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4062 staticpro (&Qface_set_after_frame_default);
4064 Qfullwidth = intern ("fullwidth");
4065 staticpro (&Qfullwidth);
4066 Qfullheight = intern ("fullheight");
4067 staticpro (&Qfullheight);
4068 Qfullboth = intern ("fullboth");
4069 staticpro (&Qfullboth);
4070 Qx_resource_name = intern ("x-resource-name");
4071 staticpro (&Qx_resource_name);
4073 Qx_frame_parameter = intern ("x-frame-parameter");
4074 staticpro (&Qx_frame_parameter);
4077 int i;
4079 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4081 Lisp_Object v = intern (frame_parms[i].name);
4082 if (frame_parms[i].variable)
4084 *frame_parms[i].variable = v;
4085 staticpro (frame_parms[i].variable);
4087 Fput (v, Qx_frame_parameter, make_number (i));
4091 #ifdef HAVE_WINDOW_SYSTEM
4092 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4093 doc: /* The name Emacs uses to look up X resources.
4094 `x-get-resource' uses this as the first component of the instance name
4095 when requesting resource values.
4096 Emacs initially sets `x-resource-name' to the name under which Emacs
4097 was invoked, or to the value specified with the `-name' or `-rn'
4098 switches, if present.
4100 It may be useful to bind this variable locally around a call
4101 to `x-get-resource'. See also the variable `x-resource-class'. */);
4102 Vx_resource_name = Qnil;
4104 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4105 doc: /* The class Emacs uses to look up X resources.
4106 `x-get-resource' uses this as the first component of the instance class
4107 when requesting resource values.
4109 Emacs initially sets `x-resource-class' to "Emacs".
4111 Setting this variable permanently is not a reasonable thing to do,
4112 but binding this variable locally around a call to `x-get-resource'
4113 is a reasonable practice. See also the variable `x-resource-name'. */);
4114 Vx_resource_class = build_string (EMACS_CLASS);
4115 #endif
4117 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4118 doc: /* Alist of default values for frame creation.
4119 These may be set in your init file, like this:
4120 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1))
4121 These override values given in window system configuration data,
4122 including X Windows' defaults database.
4123 For values specific to the first Emacs frame, see `initial-frame-alist'.
4124 For values specific to the separate minibuffer frame, see
4125 `minibuffer-frame-alist'.
4126 The `menu-bar-lines' element of the list controls whether new frames
4127 have menu bars; `menu-bar-mode' works by altering this element.
4128 Setting this variable does not affect existing frames, only new ones. */);
4129 Vdefault_frame_alist = Qnil;
4131 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4132 doc: /* Default position of scroll bars on this window-system. */);
4133 #ifdef HAVE_WINDOW_SYSTEM
4134 #if defined(HAVE_NTGUI) || defined(HAVE_CARBON)
4135 /* MS-Windows has scroll bars on the right by default. */
4136 Vdefault_frame_scroll_bars = Qright;
4137 #else
4138 Vdefault_frame_scroll_bars = Qleft;
4139 #endif
4140 #else
4141 Vdefault_frame_scroll_bars = Qnil;
4142 #endif
4144 Qinhibit_default_face_x_resources
4145 = intern ("inhibit-default-face-x-resources");
4146 staticpro (&Qinhibit_default_face_x_resources);
4148 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4149 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4151 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4152 doc: /* Non-nil if all of emacs is iconified and frame updates are not needed. */);
4153 Vemacs_iconified = Qnil;
4155 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4156 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4157 `mouse-position' calls this function, passing its usual return value as
4158 argument, and returns whatever this function returns.
4159 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4160 which need to do mouse handling at the Lisp level. */);
4161 Vmouse_position_function = Qnil;
4163 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4164 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4165 If the value is an integer, highlighting is only shown after moving the
4166 mouse, while keyboard input turns off the highlight even when the mouse
4167 is over the clickable text. However, the mouse shape still indicates
4168 when the mouse is over clickable text. */);
4169 Vmouse_highlight = Qt;
4171 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4172 doc: /* Functions to be run before deleting a frame.
4173 The functions are run with one arg, the frame to be deleted.
4174 See `delete-frame'. */);
4175 Vdelete_frame_functions = Qnil;
4177 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4178 doc: /* Minibufferless frames use this frame's minibuffer.
4180 Emacs cannot create minibufferless frames unless this is set to an
4181 appropriate surrogate.
4183 Emacs consults this variable only when creating minibufferless
4184 frames; once the frame is created, it sticks with its assigned
4185 minibuffer, no matter what this variable is set to. This means that
4186 this variable doesn't necessarily say anything meaningful about the
4187 current set of frames, or where the minibuffer is currently being
4188 displayed.
4190 This variable is local to the current terminal and cannot be buffer-local. */);
4192 staticpro (&Vframe_list);
4194 defsubr (&Sactive_minibuffer_window);
4195 defsubr (&Sframep);
4196 defsubr (&Sframe_live_p);
4197 defsubr (&Smake_terminal_frame);
4198 defsubr (&Shandle_switch_frame);
4199 defsubr (&Signore_event);
4200 defsubr (&Sselect_frame);
4201 defsubr (&Sselected_frame);
4202 defsubr (&Swindow_frame);
4203 defsubr (&Sframe_root_window);
4204 defsubr (&Sframe_first_window);
4205 defsubr (&Sframe_selected_window);
4206 defsubr (&Sset_frame_selected_window);
4207 defsubr (&Sframe_list);
4208 defsubr (&Snext_frame);
4209 defsubr (&Sprevious_frame);
4210 defsubr (&Sdelete_frame);
4211 defsubr (&Smouse_position);
4212 defsubr (&Smouse_pixel_position);
4213 defsubr (&Sset_mouse_position);
4214 defsubr (&Sset_mouse_pixel_position);
4215 #if 0
4216 defsubr (&Sframe_configuration);
4217 defsubr (&Srestore_frame_configuration);
4218 #endif
4219 defsubr (&Smake_frame_visible);
4220 defsubr (&Smake_frame_invisible);
4221 defsubr (&Siconify_frame);
4222 defsubr (&Sframe_visible_p);
4223 defsubr (&Svisible_frame_list);
4224 defsubr (&Sraise_frame);
4225 defsubr (&Slower_frame);
4226 defsubr (&Sredirect_frame_focus);
4227 defsubr (&Sframe_focus);
4228 defsubr (&Sframe_parameters);
4229 defsubr (&Sframe_parameter);
4230 defsubr (&Smodify_frame_parameters);
4231 defsubr (&Sframe_char_height);
4232 defsubr (&Sframe_char_width);
4233 defsubr (&Sframe_pixel_height);
4234 defsubr (&Sframe_pixel_width);
4235 defsubr (&Sset_frame_height);
4236 defsubr (&Sset_frame_width);
4237 defsubr (&Sset_frame_size);
4238 defsubr (&Sset_frame_position);
4240 #ifdef HAVE_WINDOW_SYSTEM
4241 defsubr (&Sx_get_resource);
4242 defsubr (&Sx_parse_geometry);
4243 #endif
4247 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4248 (do not change this comment) */