Inline setter functions for hash table members.
[emacs.git] / src / frame.c
bloba00f44a1e5a31bdc3d519d368d42505352a9fe79
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #define FRAME_INLINE EXTERN_INLINE
24 #include <stdio.h>
25 #include <errno.h>
26 #include <limits.h>
27 #include <setjmp.h>
29 #include <c-ctype.h>
31 #include "lisp.h"
32 #include "character.h"
33 #ifdef HAVE_X_WINDOWS
34 #include "xterm.h"
35 #endif
36 #ifdef WINDOWSNT
37 #include "w32term.h"
38 #endif
39 #ifdef HAVE_NS
40 #include "nsterm.h"
41 #endif
42 #include "buffer.h"
43 /* These help us bind and responding to switch-frame events. */
44 #include "commands.h"
45 #include "keyboard.h"
46 #include "frame.h"
47 #include "blockinput.h"
48 #include "termchar.h"
49 #include "termhooks.h"
50 #include "dispextern.h"
51 #include "window.h"
52 #include "font.h"
53 #ifdef HAVE_WINDOW_SYSTEM
54 #include "fontset.h"
55 #endif
56 #ifdef MSDOS
57 #include "msdos.h"
58 #include "dosfns.h"
59 #endif
62 #ifdef HAVE_WINDOW_SYSTEM
64 #endif
66 #ifdef HAVE_NS
67 Lisp_Object Qns_parse_geometry;
68 #endif
70 Lisp_Object Qframep, Qframe_live_p;
71 Lisp_Object Qicon, Qmodeline;
72 Lisp_Object Qonly, Qnone;
73 Lisp_Object Qx, Qw32, Qmac, Qpc, Qns;
74 Lisp_Object Qvisible;
75 Lisp_Object Qdisplay_type;
76 static Lisp_Object Qbackground_mode;
77 Lisp_Object Qnoelisp;
79 static Lisp_Object Qx_frame_parameter;
80 Lisp_Object Qx_resource_name;
81 Lisp_Object Qterminal;
82 Lisp_Object Qterminal_live_p;
84 /* Frame parameters (set or reported). */
86 Lisp_Object Qauto_raise, Qauto_lower;
87 Lisp_Object Qborder_color, Qborder_width;
88 Lisp_Object Qcursor_color, Qcursor_type;
89 static Lisp_Object Qgeometry; /* Not used */
90 Lisp_Object Qheight, Qwidth;
91 Lisp_Object Qleft, Qright;
92 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
93 Lisp_Object Qtooltip;
94 Lisp_Object Qinternal_border_width;
95 Lisp_Object Qmouse_color;
96 Lisp_Object Qminibuffer;
97 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
98 Lisp_Object Qvisibility;
99 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
100 Lisp_Object Qscreen_gamma;
101 Lisp_Object Qline_spacing;
102 static Lisp_Object Quser_position, Quser_size;
103 Lisp_Object Qwait_for_wm;
104 static Lisp_Object Qwindow_id;
105 #ifdef HAVE_X_WINDOWS
106 static Lisp_Object Qouter_window_id;
107 #endif
108 Lisp_Object Qparent_id;
109 Lisp_Object Qtitle, Qname;
110 static Lisp_Object Qexplicit_name;
111 Lisp_Object Qunsplittable;
112 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines, Qtool_bar_position;
113 Lisp_Object Qleft_fringe, Qright_fringe;
114 Lisp_Object Qbuffer_predicate;
115 static Lisp_Object Qbuffer_list, Qburied_buffer_list;
116 Lisp_Object Qtty_color_mode;
117 Lisp_Object Qtty, Qtty_type;
119 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth, Qmaximized;
120 Lisp_Object Qsticky;
121 Lisp_Object Qfont_backend;
122 Lisp_Object Qalpha;
124 Lisp_Object Qface_set_after_frame_default;
126 static Lisp_Object Qdelete_frame_functions;
128 #ifdef HAVE_WINDOW_SYSTEM
129 static void x_report_frame_params (struct frame *, Lisp_Object *);
130 #endif
132 /* These setters are used only in this file, so they can be private. */
133 static inline void
134 fset_buffer_predicate (struct frame *f, Lisp_Object val)
136 f->buffer_predicate = val;
138 static inline void
139 fset_minibuffer_window (struct frame *f, Lisp_Object val)
141 f->minibuffer_window = val;
145 static void
146 set_menu_bar_lines_1 (Lisp_Object window, int n)
148 struct window *w = XWINDOW (window);
150 w->last_modified = 0;
151 wset_top_line (w, make_number (XFASTINT (w->top_line) + n));
152 wset_total_lines (w, make_number (XFASTINT (w->total_lines) - n));
154 /* Handle just the top child in a vertical split. */
155 if (!NILP (w->vchild))
156 set_menu_bar_lines_1 (w->vchild, n);
158 /* Adjust all children in a horizontal split. */
159 for (window = w->hchild; !NILP (window); window = w->next)
161 w = XWINDOW (window);
162 set_menu_bar_lines_1 (window, n);
166 void
167 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
169 int nlines;
170 int olines = FRAME_MENU_BAR_LINES (f);
172 /* Right now, menu bars don't work properly in minibuf-only frames;
173 most of the commands try to apply themselves to the minibuffer
174 frame itself, and get an error because you can't switch buffers
175 in or split the minibuffer window. */
176 if (FRAME_MINIBUF_ONLY_P (f))
177 return;
179 if (TYPE_RANGED_INTEGERP (int, value))
180 nlines = XINT (value);
181 else
182 nlines = 0;
184 if (nlines != olines)
186 windows_or_buffers_changed++;
187 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
188 FRAME_MENU_BAR_LINES (f) = nlines;
189 set_menu_bar_lines_1 (f->root_window, nlines - olines);
190 adjust_glyphs (f);
194 Lisp_Object Vframe_list;
197 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
198 doc: /* Return non-nil if OBJECT is a frame.
199 Value is:
200 t for a termcap frame (a character-only terminal),
201 'x' for an Emacs frame that is really an X window,
202 'w32' for an Emacs frame that is a window on MS-Windows display,
203 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
204 'pc' for a direct-write MS-DOS frame.
205 See also `frame-live-p'. */)
206 (Lisp_Object object)
208 if (!FRAMEP (object))
209 return Qnil;
210 switch (XFRAME (object)->output_method)
212 case output_initial: /* The initial frame is like a termcap frame. */
213 case output_termcap:
214 return Qt;
215 case output_x_window:
216 return Qx;
217 case output_w32:
218 return Qw32;
219 case output_msdos_raw:
220 return Qpc;
221 case output_mac:
222 return Qmac;
223 case output_ns:
224 return Qns;
225 default:
226 abort ();
230 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
231 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
232 Value is nil if OBJECT is not a live frame. If object is a live
233 frame, the return value indicates what sort of terminal device it is
234 displayed on. See the documentation of `framep' for possible
235 return values. */)
236 (Lisp_Object object)
238 return ((FRAMEP (object)
239 && FRAME_LIVE_P (XFRAME (object)))
240 ? Fframep (object)
241 : Qnil);
244 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
245 doc: /* The name of the window system that FRAME is displaying through.
246 The value is a symbol:
247 nil for a termcap frame (a character-only terminal),
248 'x' for an Emacs frame that is really an X window,
249 'w32' for an Emacs frame that is a window on MS-Windows display,
250 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
251 'pc' for a direct-write MS-DOS frame.
253 FRAME defaults to the currently selected frame.
255 Use of this function as a predicate is deprecated. Instead,
256 use `display-graphic-p' or any of the other `display-*-p'
257 predicates which report frame's specific UI-related capabilities. */)
258 (Lisp_Object frame)
260 Lisp_Object type;
261 if (NILP (frame))
262 frame = selected_frame;
264 type = Fframep (frame);
266 if (NILP (type))
267 wrong_type_argument (Qframep, frame);
269 if (EQ (type, Qt))
270 return Qnil;
271 else
272 return type;
275 struct frame *
276 make_frame (int mini_p)
278 Lisp_Object frame;
279 register struct frame *f;
280 register Lisp_Object root_window;
281 register Lisp_Object mini_window;
283 f = allocate_frame ();
284 XSETFRAME (frame, f);
286 /* Initialize Lisp data. Note that allocate_frame initializes all
287 Lisp data to nil, so do it only for slots which should not be nil. */
288 fset_tool_bar_position (f, Qtop);
290 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
291 non-Lisp data, so do it only for slots which should not be zero.
292 To avoid subtle bugs and for the sake of readability, it's better to
293 initialize enum members explicitly even if their values are zero. */
294 f->wants_modeline = 1;
295 f->garbaged = 1;
296 f->has_minibuffer = mini_p;
297 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
298 f->column_width = 1; /* !FRAME_WINDOW_P value */
299 f->line_height = 1; /* !FRAME_WINDOW_P value */
300 #ifdef HAVE_WINDOW_SYSTEM
301 f->want_fullscreen = FULLSCREEN_NONE;
302 #endif
304 root_window = make_window ();
305 if (mini_p)
307 mini_window = make_window ();
308 wset_next (XWINDOW (root_window), mini_window);
309 wset_prev (XWINDOW (mini_window), root_window);
310 XWINDOW (mini_window)->mini = 1;
311 wset_frame (XWINDOW (mini_window), frame);
312 fset_minibuffer_window (f, mini_window);
314 else
316 mini_window = Qnil;
317 wset_next (XWINDOW (root_window), Qnil);
318 fset_minibuffer_window (f, Qnil);
321 wset_frame (XWINDOW (root_window), frame);
323 /* 10 is arbitrary,
324 just so that there is "something there."
325 Correct size will be set up later with change_frame_size. */
327 SET_FRAME_COLS (f, 10);
328 FRAME_LINES (f) = 10;
330 wset_total_cols (XWINDOW (root_window), make_number (10));
331 wset_total_lines (XWINDOW (root_window), make_number (mini_p ? 9 : 10));
333 if (mini_p)
335 wset_total_cols (XWINDOW (mini_window), make_number (10));
336 wset_top_line (XWINDOW (mini_window), make_number (9));
337 wset_total_lines (XWINDOW (mini_window), make_number (1));
340 /* Choose a buffer for the frame's root window. */
342 Lisp_Object buf;
344 wset_buffer (XWINDOW (root_window), Qt);
345 buf = Fcurrent_buffer ();
346 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
347 a space), try to find another one. */
348 if (SREF (Fbuffer_name (buf), 0) == ' ')
349 buf = other_buffer_safely (buf);
351 /* Use set_window_buffer, not Fset_window_buffer, and don't let
352 hooks be run by it. The reason is that the whole frame/window
353 arrangement is not yet fully initialized at this point. Windows
354 don't have the right size, glyph matrices aren't initialized
355 etc. Running Lisp functions at this point surely ends in a
356 SEGV. */
357 set_window_buffer (root_window, buf, 0, 0);
358 fset_buffer_list (f, Fcons (buf, Qnil));
361 if (mini_p)
363 wset_buffer (XWINDOW (mini_window), Qt);
364 set_window_buffer (mini_window,
365 (NILP (Vminibuffer_list)
366 ? get_minibuffer (0)
367 : Fcar (Vminibuffer_list)),
368 0, 0);
371 fset_root_window (f, root_window);
372 fset_selected_window (f, root_window);
373 /* Make sure this window seems more recently used than
374 a newly-created, never-selected window. */
375 XWINDOW (f->selected_window)->use_time = ++window_select_count;
377 return f;
380 #ifdef HAVE_WINDOW_SYSTEM
381 /* Make a frame using a separate minibuffer window on another frame.
382 MINI_WINDOW is the minibuffer window to use. nil means use the
383 default (the global minibuffer). */
385 struct frame *
386 make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
388 register struct frame *f;
389 struct gcpro gcpro1;
391 if (!NILP (mini_window))
392 CHECK_LIVE_WINDOW (mini_window);
394 if (!NILP (mini_window)
395 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
396 error ("Frame and minibuffer must be on the same terminal");
398 /* Make a frame containing just a root window. */
399 f = make_frame (0);
401 if (NILP (mini_window))
403 /* Use default-minibuffer-frame if possible. */
404 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
405 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
407 Lisp_Object frame_dummy;
409 XSETFRAME (frame_dummy, f);
410 GCPRO1 (frame_dummy);
411 /* If there's no minibuffer frame to use, create one. */
412 kset_default_minibuffer_frame
413 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
414 UNGCPRO;
417 mini_window
418 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
421 fset_minibuffer_window (f, mini_window);
423 /* Make the chosen minibuffer window display the proper minibuffer,
424 unless it is already showing a minibuffer. */
425 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
426 /* Use set_window_buffer instead of Fset_window_buffer (see
427 discussion of bug#11984, bug#12025, bug#12026). */
428 set_window_buffer (mini_window,
429 (NILP (Vminibuffer_list)
430 ? get_minibuffer (0)
431 : Fcar (Vminibuffer_list)), 0, 0);
432 return f;
435 /* Make a frame containing only a minibuffer window. */
437 struct frame *
438 make_minibuffer_frame (void)
440 /* First make a frame containing just a root window, no minibuffer. */
442 register struct frame *f = make_frame (0);
443 register Lisp_Object mini_window;
444 register Lisp_Object frame;
446 XSETFRAME (frame, f);
448 f->auto_raise = 0;
449 f->auto_lower = 0;
450 f->no_split = 1;
451 f->wants_modeline = 0;
452 f->has_minibuffer = 1;
454 /* Now label the root window as also being the minibuffer.
455 Avoid infinite looping on the window chain by marking next pointer
456 as nil. */
458 mini_window = f->root_window;
459 fset_minibuffer_window (f, mini_window);
460 XWINDOW (mini_window)->mini = 1;
461 wset_next (XWINDOW (mini_window), Qnil);
462 wset_prev (XWINDOW (mini_window), Qnil);
463 wset_frame (XWINDOW (mini_window), frame);
465 /* Put the proper buffer in that window. */
467 /* Use set_window_buffer instead of Fset_window_buffer (see
468 discussion of bug#11984, bug#12025, bug#12026). */
469 set_window_buffer (mini_window,
470 (NILP (Vminibuffer_list)
471 ? get_minibuffer (0)
472 : Fcar (Vminibuffer_list)), 0, 0);
473 return f;
475 #endif /* HAVE_WINDOW_SYSTEM */
477 /* Construct a frame that refers to a terminal. */
479 static printmax_t tty_frame_count;
481 struct frame *
482 make_initial_frame (void)
484 struct frame *f;
485 struct terminal *terminal;
486 Lisp_Object frame;
488 eassert (initial_kboard);
490 /* The first call must initialize Vframe_list. */
491 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
492 Vframe_list = Qnil;
494 terminal = init_initial_terminal ();
496 f = make_frame (1);
497 XSETFRAME (frame, f);
499 Vframe_list = Fcons (frame, Vframe_list);
501 tty_frame_count = 1;
502 fset_name (f, build_pure_c_string ("F1"));
504 f->visible = 1;
505 f->async_visible = 1;
507 f->output_method = terminal->type;
508 f->terminal = terminal;
509 f->terminal->reference_count++;
510 f->output_data.nothing = 0;
512 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
513 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
515 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
516 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
518 /* The default value of menu-bar-mode is t. */
519 set_menu_bar_lines (f, make_number (1), Qnil);
521 if (!noninteractive)
522 init_frame_faces (f);
524 return f;
528 static struct frame *
529 make_terminal_frame (struct terminal *terminal)
531 register struct frame *f;
532 Lisp_Object frame;
533 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
535 if (!terminal->name)
536 error ("Terminal is not live, can't create new frames on it");
538 f = make_frame (1);
540 XSETFRAME (frame, f);
541 Vframe_list = Fcons (frame, Vframe_list);
543 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
545 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
546 f->async_visible = 1; /* Don't let visible be cleared later. */
547 f->terminal = terminal;
548 f->terminal->reference_count++;
549 #ifdef MSDOS
550 f->output_data.tty->display_info = &the_only_display_info;
551 if (!inhibit_window_system
552 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
553 || XFRAME (selected_frame)->output_method == output_msdos_raw))
554 f->output_method = output_msdos_raw;
555 else
556 f->output_method = output_termcap;
557 #else /* not MSDOS */
558 f->output_method = output_termcap;
559 create_tty_output (f);
560 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
561 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
562 #endif /* not MSDOS */
564 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
565 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
566 FRAME_MENU_BAR_LINES(f) = NILP (Vmenu_bar_mode) ? 0 : 1;
568 /* Set the top frame to the newly created frame. */
569 if (FRAMEP (FRAME_TTY (f)->top_frame)
570 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
571 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
573 FRAME_TTY (f)->top_frame = frame;
575 if (!noninteractive)
576 init_frame_faces (f);
578 return f;
581 /* Get a suitable value for frame parameter PARAMETER for a newly
582 created frame, based on (1) the user-supplied frame parameter
583 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
585 static Lisp_Object
586 get_future_frame_param (Lisp_Object parameter,
587 Lisp_Object supplied_parms,
588 char *current_value)
590 Lisp_Object result;
592 result = Fassq (parameter, supplied_parms);
593 if (NILP (result))
594 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
595 if (NILP (result) && current_value != NULL)
596 result = build_string (current_value);
597 if (!NILP (result) && !STRINGP (result))
598 result = XCDR (result);
599 if (NILP (result) || !STRINGP (result))
600 result = Qnil;
602 return result;
605 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
606 1, 1, 0,
607 doc: /* Create an additional terminal frame, possibly on another terminal.
608 This function takes one argument, an alist specifying frame parameters.
610 You can create multiple frames on a single text terminal, but only one
611 of them (the selected terminal frame) is actually displayed.
613 In practice, generally you don't need to specify any parameters,
614 except when you want to create a new frame on another terminal.
615 In that case, the `tty' parameter specifies the device file to open,
616 and the `tty-type' parameter specifies the terminal type. Example:
618 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
620 Note that changing the size of one terminal frame automatically
621 affects all frames on the same terminal device. */)
622 (Lisp_Object parms)
624 struct frame *f;
625 struct terminal *t = NULL;
626 Lisp_Object frame, tem;
627 struct frame *sf = SELECTED_FRAME ();
629 #ifdef MSDOS
630 if (sf->output_method != output_msdos_raw
631 && sf->output_method != output_termcap)
632 abort ();
633 #else /* not MSDOS */
635 #ifdef WINDOWSNT /* This should work now! */
636 if (sf->output_method != output_termcap)
637 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
638 #endif
639 #endif /* not MSDOS */
642 Lisp_Object terminal;
644 terminal = Fassq (Qterminal, parms);
645 if (!NILP (terminal))
647 terminal = XCDR (terminal);
648 t = get_terminal (terminal, 1);
650 #ifdef MSDOS
651 if (t && t != the_only_display_info.terminal)
652 /* msdos.c assumes a single tty_display_info object. */
653 error ("Multiple terminals are not supported on this platform");
654 if (!t)
655 t = the_only_display_info.terminal;
656 #endif
659 if (!t)
661 char *name = 0, *type = 0;
662 Lisp_Object tty, tty_type;
664 tty = get_future_frame_param
665 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
666 ? FRAME_TTY (XFRAME (selected_frame))->name
667 : NULL));
668 if (!NILP (tty))
670 name = alloca (SBYTES (tty) + 1);
671 memcpy (name, SSDATA (tty), SBYTES (tty));
672 name[SBYTES (tty)] = 0;
675 tty_type = get_future_frame_param
676 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
677 ? FRAME_TTY (XFRAME (selected_frame))->type
678 : NULL));
679 if (!NILP (tty_type))
681 type = alloca (SBYTES (tty_type) + 1);
682 memcpy (type, SSDATA (tty_type), SBYTES (tty_type));
683 type[SBYTES (tty_type)] = 0;
686 t = init_tty (name, type, 0); /* Errors are not fatal. */
689 f = make_terminal_frame (t);
692 int width, height;
693 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
694 change_frame_size (f, height, width, 0, 0, 0);
697 adjust_glyphs (f);
698 calculate_costs (f);
699 XSETFRAME (frame, f);
700 Fmodify_frame_parameters (frame, parms);
701 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
702 build_string (t->display_info.tty->type)),
703 Qnil));
704 if (t->display_info.tty->name != NULL)
705 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
706 build_string (t->display_info.tty->name)),
707 Qnil));
708 else
709 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
711 /* Make the frame face alist be frame-specific, so that each
712 frame could change its face definitions independently. */
713 fset_face_alist (f, Fcopy_alist (sf->face_alist));
714 /* Simple Fcopy_alist isn't enough, because we need the contents of
715 the vectors which are the CDRs of associations in face_alist to
716 be copied as well. */
717 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
718 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
719 return frame;
723 /* Perform the switch to frame FRAME.
725 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
726 FRAME1 as frame.
728 If TRACK is non-zero and the frame that currently has the focus
729 redirects its focus to the selected frame, redirect that focused
730 frame's focus to FRAME instead.
732 FOR_DELETION non-zero means that the selected frame is being
733 deleted, which includes the possibility that the frame's terminal
734 is dead.
736 The value of NORECORD is passed as argument to Fselect_window. */
738 Lisp_Object
739 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
741 struct frame *sf = SELECTED_FRAME ();
743 /* If FRAME is a switch-frame event, extract the frame we should
744 switch to. */
745 if (CONSP (frame)
746 && EQ (XCAR (frame), Qswitch_frame)
747 && CONSP (XCDR (frame)))
748 frame = XCAR (XCDR (frame));
750 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
751 a switch-frame event to arrive after a frame is no longer live,
752 especially when deleting the initial frame during startup. */
753 CHECK_FRAME (frame);
754 if (! FRAME_LIVE_P (XFRAME (frame)))
755 return Qnil;
757 if (sf == XFRAME (frame))
758 return frame;
760 /* This is too greedy; it causes inappropriate focus redirection
761 that's hard to get rid of. */
762 #if 0
763 /* If a frame's focus has been redirected toward the currently
764 selected frame, we should change the redirection to point to the
765 newly selected frame. This means that if the focus is redirected
766 from a minibufferless frame to a surrogate minibuffer frame, we
767 can use `other-window' to switch between all the frames using
768 that minibuffer frame, and the focus redirection will follow us
769 around. */
770 if (track)
772 Lisp_Object tail;
774 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
776 Lisp_Object focus;
778 if (!FRAMEP (XCAR (tail)))
779 abort ();
781 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
783 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
784 Fredirect_frame_focus (XCAR (tail), frame);
787 #else /* ! 0 */
788 /* Instead, apply it only to the frame we're pointing to. */
789 #ifdef HAVE_WINDOW_SYSTEM
790 if (track && FRAME_WINDOW_P (XFRAME (frame)))
792 Lisp_Object focus, xfocus;
794 xfocus = x_get_focus_frame (XFRAME (frame));
795 if (FRAMEP (xfocus))
797 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
798 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
799 Fredirect_frame_focus (xfocus, frame);
802 #endif /* HAVE_X_WINDOWS */
803 #endif /* ! 0 */
805 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
806 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
808 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
810 if (FRAMEP (FRAME_TTY (XFRAME (frame))->top_frame))
811 /* Mark previously displayed frame as now obscured. */
812 XFRAME (FRAME_TTY (XFRAME (frame))->top_frame)->async_visible = 2;
813 XFRAME (frame)->async_visible = 1;
814 FRAME_TTY (XFRAME (frame))->top_frame = frame;
817 selected_frame = frame;
818 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
819 last_nonminibuf_frame = XFRAME (selected_frame);
821 Fselect_window (XFRAME (frame)->selected_window, norecord);
823 /* We want to make sure that the next event generates a frame-switch
824 event to the appropriate frame. This seems kludgy to me, but
825 before you take it out, make sure that evaluating something like
826 (select-window (frame-root-window (new-frame))) doesn't end up
827 with your typing being interpreted in the new frame instead of
828 the one you're actually typing in. */
829 internal_last_event_frame = Qnil;
831 return frame;
834 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
835 doc: /* Select FRAME.
836 Subsequent editing commands apply to its selected window.
837 Optional argument NORECORD means to neither change the order of
838 recently selected windows nor the buffer list.
840 The selection of FRAME lasts until the next time the user does
841 something to select a different frame, or until the next time
842 this function is called. If you are using a window system, the
843 previously selected frame may be restored as the selected frame
844 when returning to the command loop, because it still may have
845 the window system's input focus. On a text terminal, the next
846 redisplay will display FRAME.
848 This function returns FRAME, or nil if FRAME has been deleted. */)
849 (Lisp_Object frame, Lisp_Object norecord)
851 return do_switch_frame (frame, 1, 0, norecord);
855 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
856 doc: /* Handle a switch-frame event EVENT.
857 Switch-frame events are usually bound to this function.
858 A switch-frame event tells Emacs that the window manager has requested
859 that the user's events be directed to the frame mentioned in the event.
860 This function selects the selected window of the frame of EVENT.
862 If EVENT is frame object, handle it as if it were a switch-frame event
863 to that frame. */)
864 (Lisp_Object event)
866 /* Preserve prefix arg that the command loop just cleared. */
867 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
868 Frun_hooks (1, &Qmouse_leave_buffer_hook);
869 return do_switch_frame (event, 0, 0, Qnil);
872 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
873 doc: /* Return the frame that is now selected. */)
874 (void)
876 return selected_frame;
879 DEFUN ("frame-list", Fframe_list, Sframe_list,
880 0, 0, 0,
881 doc: /* Return a list of all live frames. */)
882 (void)
884 Lisp_Object frames;
885 frames = Fcopy_sequence (Vframe_list);
886 #ifdef HAVE_WINDOW_SYSTEM
887 if (FRAMEP (tip_frame))
888 frames = Fdelq (tip_frame, frames);
889 #endif
890 return frames;
893 /* Return the next frame in the frame list after FRAME.
894 If MINIBUF is nil, exclude minibuffer-only frames.
895 If MINIBUF is a window, include only its own frame
896 and any frame now using that window as the minibuffer.
897 If MINIBUF is `visible', include all visible frames.
898 If MINIBUF is 0, include all visible and iconified frames.
899 Otherwise, include all frames. */
901 static Lisp_Object
902 next_frame (Lisp_Object frame, Lisp_Object minibuf)
904 Lisp_Object tail;
905 int passed = 0;
907 /* There must always be at least one frame in Vframe_list. */
908 if (! CONSP (Vframe_list))
909 abort ();
911 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
912 forever. Forestall that. */
913 CHECK_LIVE_FRAME (frame);
915 while (1)
916 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
918 Lisp_Object f;
920 f = XCAR (tail);
922 if (passed
923 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
924 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
925 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
926 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
928 /* Decide whether this frame is eligible to be returned. */
930 /* If we've looped all the way around without finding any
931 eligible frames, return the original frame. */
932 if (EQ (f, frame))
933 return f;
935 /* Let minibuf decide if this frame is acceptable. */
936 if (NILP (minibuf))
938 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
939 return f;
941 else if (EQ (minibuf, Qvisible))
943 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
944 if (FRAME_VISIBLE_P (XFRAME (f)))
945 return f;
947 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
949 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
950 if (FRAME_VISIBLE_P (XFRAME (f))
951 || FRAME_ICONIFIED_P (XFRAME (f)))
952 return f;
954 else if (WINDOWP (minibuf))
956 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
957 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
958 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
959 FRAME_FOCUS_FRAME (XFRAME (f))))
960 return f;
962 else
963 return f;
966 if (EQ (frame, f))
967 passed++;
971 /* Return the previous frame in the frame list before FRAME.
972 If MINIBUF is nil, exclude minibuffer-only frames.
973 If MINIBUF is a window, include only its own frame
974 and any frame now using that window as the minibuffer.
975 If MINIBUF is `visible', include all visible frames.
976 If MINIBUF is 0, include all visible and iconified frames.
977 Otherwise, include all frames. */
979 static Lisp_Object
980 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
982 Lisp_Object tail;
983 Lisp_Object prev;
985 /* There must always be at least one frame in Vframe_list. */
986 if (! CONSP (Vframe_list))
987 abort ();
989 prev = Qnil;
990 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
992 Lisp_Object f;
994 f = XCAR (tail);
995 if (!FRAMEP (f))
996 abort ();
998 if (EQ (frame, f) && !NILP (prev))
999 return prev;
1001 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1002 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1003 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1004 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1006 /* Decide whether this frame is eligible to be returned,
1007 according to minibuf. */
1008 if (NILP (minibuf))
1010 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1011 prev = f;
1013 else if (WINDOWP (minibuf))
1015 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1016 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1017 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1018 FRAME_FOCUS_FRAME (XFRAME (f))))
1019 prev = f;
1021 else if (EQ (minibuf, Qvisible))
1023 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1024 if (FRAME_VISIBLE_P (XFRAME (f)))
1025 prev = f;
1027 else if (XFASTINT (minibuf) == 0)
1029 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1030 if (FRAME_VISIBLE_P (XFRAME (f))
1031 || FRAME_ICONIFIED_P (XFRAME (f)))
1032 prev = f;
1034 else
1035 prev = f;
1039 /* We've scanned the entire list. */
1040 if (NILP (prev))
1041 /* We went through the whole frame list without finding a single
1042 acceptable frame. Return the original frame. */
1043 return frame;
1044 else
1045 /* There were no acceptable frames in the list before FRAME; otherwise,
1046 we would have returned directly from the loop. Since PREV is the last
1047 acceptable frame in the list, return it. */
1048 return prev;
1052 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1053 doc: /* Return the next frame in the frame list after FRAME.
1054 It considers only frames on the same terminal as FRAME.
1055 By default, skip minibuffer-only frames.
1056 If omitted, FRAME defaults to the selected frame.
1057 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1058 If MINIFRAME is a window, include only its own frame
1059 and any frame now using that window as the minibuffer.
1060 If MINIFRAME is `visible', include all visible frames.
1061 If MINIFRAME is 0, include all visible and iconified frames.
1062 Otherwise, include all frames. */)
1063 (Lisp_Object frame, Lisp_Object miniframe)
1065 if (NILP (frame))
1066 frame = selected_frame;
1068 CHECK_LIVE_FRAME (frame);
1069 return next_frame (frame, miniframe);
1072 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1073 doc: /* Return the previous frame in the frame list before FRAME.
1074 It considers only frames on the same terminal as FRAME.
1075 By default, skip minibuffer-only frames.
1076 If omitted, FRAME defaults to the selected frame.
1077 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1078 If MINIFRAME is a window, include only its own frame
1079 and any frame now using that window as the minibuffer.
1080 If MINIFRAME is `visible', include all visible frames.
1081 If MINIFRAME is 0, include all visible and iconified frames.
1082 Otherwise, include all frames. */)
1083 (Lisp_Object frame, Lisp_Object miniframe)
1085 if (NILP (frame))
1086 frame = selected_frame;
1087 CHECK_LIVE_FRAME (frame);
1088 return prev_frame (frame, miniframe);
1091 /* Return 1 if it is ok to delete frame F;
1092 0 if all frames aside from F are invisible.
1093 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1095 static int
1096 other_visible_frames (FRAME_PTR f)
1098 Lisp_Object frames;
1100 for (frames = Vframe_list; CONSP (frames); frames = XCDR (frames))
1102 Lisp_Object this = XCAR (frames);
1103 if (f == XFRAME (this))
1104 continue;
1106 /* Verify that we can still talk to the frame's X window,
1107 and note any recent change in visibility. */
1108 #ifdef HAVE_WINDOW_SYSTEM
1109 if (FRAME_WINDOW_P (XFRAME (this)))
1111 x_sync (XFRAME (this));
1112 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1114 #endif
1116 if (FRAME_VISIBLE_P (XFRAME (this))
1117 || FRAME_ICONIFIED_P (XFRAME (this))
1118 /* Allow deleting the terminal frame when at least one X
1119 frame exists. */
1120 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1121 return 1;
1123 return 0;
1126 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1127 unconditionally. x_connection_closed and delete_terminal use
1128 this. Any other value of FORCE implements the semantics
1129 described for Fdelete_frame. */
1130 Lisp_Object
1131 delete_frame (Lisp_Object frame, Lisp_Object force)
1133 struct frame *f;
1134 struct frame *sf = SELECTED_FRAME ();
1135 struct kboard *kb;
1137 int minibuffer_selected, tooltip_frame;
1139 if (EQ (frame, Qnil))
1141 f = sf;
1142 XSETFRAME (frame, f);
1144 else
1146 CHECK_FRAME (frame);
1147 f = XFRAME (frame);
1150 if (! FRAME_LIVE_P (f))
1151 return Qnil;
1153 if (NILP (force) && !other_visible_frames (f))
1154 error ("Attempt to delete the sole visible or iconified frame");
1156 /* x_connection_closed must have set FORCE to `noelisp' in order
1157 to delete the last frame, if it is gone. */
1158 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1159 error ("Attempt to delete the only frame");
1161 /* Does this frame have a minibuffer, and is it the surrogate
1162 minibuffer for any other frame? */
1163 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1165 Lisp_Object frames;
1167 for (frames = Vframe_list;
1168 CONSP (frames);
1169 frames = XCDR (frames))
1171 Lisp_Object this;
1172 this = XCAR (frames);
1174 if (! EQ (this, frame)
1175 && EQ (frame,
1176 WINDOW_FRAME (XWINDOW
1177 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1179 /* If we MUST delete this frame, delete the other first.
1180 But do this only if FORCE equals `noelisp'. */
1181 if (EQ (force, Qnoelisp))
1182 delete_frame (this, Qnoelisp);
1183 else
1184 error ("Attempt to delete a surrogate minibuffer frame");
1189 tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1191 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1192 frame is a tooltip. FORCE is set to `noelisp' when handling
1193 a disconnect from the terminal, so we don't dare call Lisp
1194 code. */
1195 if (NILP (Vrun_hooks) || tooltip_frame)
1197 else if (EQ (force, Qnoelisp))
1198 pending_funcalls
1199 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1200 pending_funcalls);
1201 else
1203 #ifdef HAVE_X_WINDOWS
1204 /* Also, save clipboard to the clipboard manager. */
1205 x_clipboard_manager_save_frame (frame);
1206 #endif
1208 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1211 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1212 if (! FRAME_LIVE_P (f))
1213 return Qnil;
1215 /* At this point, we are committed to deleting the frame.
1216 There is no more chance for errors to prevent it. */
1218 minibuffer_selected = EQ (minibuf_window, selected_window);
1220 /* Don't let the frame remain selected. */
1221 if (f == sf)
1223 Lisp_Object tail, frame1;
1225 /* Look for another visible frame on the same terminal. */
1226 frame1 = next_frame (frame, Qvisible);
1228 /* If there is none, find *some* other frame. */
1229 if (NILP (frame1) || EQ (frame1, frame))
1231 FOR_EACH_FRAME (tail, frame1)
1233 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1235 /* Do not change a text terminal's top-frame. */
1236 struct frame *f1 = XFRAME (frame1);
1237 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1239 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1240 if (!EQ (top_frame, frame))
1241 frame1 = top_frame;
1243 break;
1247 #ifdef NS_IMPL_COCOA
1248 else
1249 /* Under NS, there is no system mechanism for choosing a new
1250 window to get focus -- it is left to application code.
1251 So the portion of THIS application interfacing with NS
1252 needs to know about it. We call Fraise_frame, but the
1253 purpose is really to transfer focus. */
1254 Fraise_frame (frame1);
1255 #endif
1257 do_switch_frame (frame1, 0, 1, Qnil);
1258 sf = SELECTED_FRAME ();
1261 /* Don't allow minibuf_window to remain on a deleted frame. */
1262 if (EQ (f->minibuffer_window, minibuf_window))
1264 /* Use set_window_buffer instead of Fset_window_buffer (see
1265 discussion of bug#11984, bug#12025, bug#12026). */
1266 set_window_buffer (sf->minibuffer_window,
1267 XWINDOW (minibuf_window)->buffer, 0, 0);
1268 minibuf_window = sf->minibuffer_window;
1270 /* If the dying minibuffer window was selected,
1271 select the new one. */
1272 if (minibuffer_selected)
1273 Fselect_window (minibuf_window, Qnil);
1276 /* Don't let echo_area_window to remain on a deleted frame. */
1277 if (EQ (f->minibuffer_window, echo_area_window))
1278 echo_area_window = sf->minibuffer_window;
1280 /* Clear any X selections for this frame. */
1281 #ifdef HAVE_X_WINDOWS
1282 if (FRAME_X_P (f))
1283 x_clear_frame_selections (f);
1284 #endif
1286 /* Free glyphs.
1287 This function must be called before the window tree of the
1288 frame is deleted because windows contain dynamically allocated
1289 memory. */
1290 free_glyphs (f);
1292 #ifdef HAVE_WINDOW_SYSTEM
1293 /* Give chance to each font driver to free a frame specific data. */
1294 font_update_drivers (f, Qnil);
1295 #endif
1297 /* Mark all the windows that used to be on FRAME as deleted, and then
1298 remove the reference to them. */
1299 delete_all_child_windows (f->root_window);
1300 fset_root_window (f, Qnil);
1302 Vframe_list = Fdelq (frame, Vframe_list);
1303 FRAME_SET_VISIBLE (f, 0);
1305 /* Allow the vector of menu bar contents to be freed in the next
1306 garbage collection. The frame object itself may not be garbage
1307 collected until much later, because recent_keys and other data
1308 structures can still refer to it. */
1309 fset_menu_bar_vector (f, Qnil);
1311 free_font_driver_list (f);
1312 xfree (f->namebuf);
1313 xfree (f->decode_mode_spec_buffer);
1314 xfree (FRAME_INSERT_COST (f));
1315 xfree (FRAME_DELETEN_COST (f));
1316 xfree (FRAME_INSERTN_COST (f));
1317 xfree (FRAME_DELETE_COST (f));
1318 xfree (FRAME_MESSAGE_BUF (f));
1320 /* Since some events are handled at the interrupt level, we may get
1321 an event for f at any time; if we zero out the frame's terminal
1322 now, then we may trip up the event-handling code. Instead, we'll
1323 promise that the terminal of the frame must be valid until we
1324 have called the window-system-dependent frame destruction
1325 routine. */
1327 if (FRAME_TERMINAL (f)->delete_frame_hook)
1328 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1331 struct terminal *terminal = FRAME_TERMINAL (f);
1332 f->output_data.nothing = 0;
1333 f->terminal = 0; /* Now the frame is dead. */
1335 /* If needed, delete the terminal that this frame was on.
1336 (This must be done after the frame is killed.) */
1337 terminal->reference_count--;
1338 #ifdef USE_GTK
1339 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1340 bug.
1341 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1342 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1343 terminal->reference_count = 1;
1344 #endif /* USE_GTK */
1345 if (terminal->reference_count == 0)
1347 Lisp_Object tmp;
1348 XSETTERMINAL (tmp, terminal);
1350 kb = NULL;
1351 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1353 else
1354 kb = terminal->kboard;
1357 /* If we've deleted the last_nonminibuf_frame, then try to find
1358 another one. */
1359 if (f == last_nonminibuf_frame)
1361 Lisp_Object frames;
1363 last_nonminibuf_frame = 0;
1365 for (frames = Vframe_list;
1366 CONSP (frames);
1367 frames = XCDR (frames))
1369 f = XFRAME (XCAR (frames));
1370 if (!FRAME_MINIBUF_ONLY_P (f))
1372 last_nonminibuf_frame = f;
1373 break;
1378 /* If there's no other frame on the same kboard, get out of
1379 single-kboard state if we're in it for this kboard. */
1380 if (kb != NULL)
1382 Lisp_Object frames;
1383 /* Some frame we found on the same kboard, or nil if there are none. */
1384 Lisp_Object frame_on_same_kboard;
1386 frame_on_same_kboard = Qnil;
1388 for (frames = Vframe_list;
1389 CONSP (frames);
1390 frames = XCDR (frames))
1392 Lisp_Object this;
1393 struct frame *f1;
1395 this = XCAR (frames);
1396 if (!FRAMEP (this))
1397 abort ();
1398 f1 = XFRAME (this);
1400 if (kb == FRAME_KBOARD (f1))
1401 frame_on_same_kboard = this;
1404 if (NILP (frame_on_same_kboard))
1405 not_single_kboard_state (kb);
1409 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1410 find another one. Prefer minibuffer-only frames, but also notice
1411 frames with other windows. */
1412 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1414 Lisp_Object frames;
1416 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1417 Lisp_Object frame_with_minibuf;
1418 /* Some frame we found on the same kboard, or nil if there are none. */
1419 Lisp_Object frame_on_same_kboard;
1421 frame_on_same_kboard = Qnil;
1422 frame_with_minibuf = Qnil;
1424 for (frames = Vframe_list;
1425 CONSP (frames);
1426 frames = XCDR (frames))
1428 Lisp_Object this;
1429 struct frame *f1;
1431 this = XCAR (frames);
1432 if (!FRAMEP (this))
1433 abort ();
1434 f1 = XFRAME (this);
1436 /* Consider only frames on the same kboard
1437 and only those with minibuffers. */
1438 if (kb == FRAME_KBOARD (f1)
1439 && FRAME_HAS_MINIBUF_P (f1))
1441 frame_with_minibuf = this;
1442 if (FRAME_MINIBUF_ONLY_P (f1))
1443 break;
1446 if (kb == FRAME_KBOARD (f1))
1447 frame_on_same_kboard = this;
1450 if (!NILP (frame_on_same_kboard))
1452 /* We know that there must be some frame with a minibuffer out
1453 there. If this were not true, all of the frames present
1454 would have to be minibufferless, which implies that at some
1455 point their minibuffer frames must have been deleted, but
1456 that is prohibited at the top; you can't delete surrogate
1457 minibuffer frames. */
1458 if (NILP (frame_with_minibuf))
1459 abort ();
1461 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1463 else
1464 /* No frames left on this kboard--say no minibuffer either. */
1465 kset_default_minibuffer_frame (kb, Qnil);
1468 /* Cause frame titles to update--necessary if we now have just one frame. */
1469 if (!tooltip_frame)
1470 update_mode_lines = 1;
1472 return Qnil;
1475 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1476 doc: /* Delete FRAME, permanently eliminating it from use.
1477 FRAME defaults to the selected frame.
1479 A frame may not be deleted if its minibuffer is used by other frames.
1480 Normally, you may not delete a frame if all other frames are invisible,
1481 but if the second optional argument FORCE is non-nil, you may do so.
1483 This function runs `delete-frame-functions' before actually
1484 deleting the frame, unless the frame is a tooltip.
1485 The functions are run with one argument, the frame to be deleted. */)
1486 (Lisp_Object frame, Lisp_Object force)
1488 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1492 /* Return mouse position in character cell units. */
1494 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1495 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1496 The position is given in character cells, where (0, 0) is the
1497 upper-left corner of the frame, X is the horizontal offset, and Y is
1498 the vertical offset.
1499 If Emacs is running on a mouseless terminal or hasn't been programmed
1500 to read the mouse position, it returns the selected frame for FRAME
1501 and nil for X and Y.
1502 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1503 passing the normal return value to that function as an argument,
1504 and returns whatever that function returns. */)
1505 (void)
1507 FRAME_PTR f;
1508 Lisp_Object lispy_dummy;
1509 enum scroll_bar_part party_dummy;
1510 Lisp_Object x, y, retval;
1511 int col, row;
1512 Time long_dummy;
1513 struct gcpro gcpro1;
1515 f = SELECTED_FRAME ();
1516 x = y = Qnil;
1518 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1519 /* It's okay for the hook to refrain from storing anything. */
1520 if (FRAME_TERMINAL (f)->mouse_position_hook)
1521 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1522 &lispy_dummy, &party_dummy,
1523 &x, &y,
1524 &long_dummy);
1525 if (! NILP (x))
1527 col = XINT (x);
1528 row = XINT (y);
1529 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1530 XSETINT (x, col);
1531 XSETINT (y, row);
1533 #endif
1534 XSETFRAME (lispy_dummy, f);
1535 retval = Fcons (lispy_dummy, Fcons (x, y));
1536 GCPRO1 (retval);
1537 if (!NILP (Vmouse_position_function))
1538 retval = call1 (Vmouse_position_function, retval);
1539 RETURN_UNGCPRO (retval);
1542 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1543 Smouse_pixel_position, 0, 0, 0,
1544 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1545 The position is given in pixel units, where (0, 0) is the
1546 upper-left corner of the frame, X is the horizontal offset, and Y is
1547 the vertical offset.
1548 If Emacs is running on a mouseless terminal or hasn't been programmed
1549 to read the mouse position, it returns the selected frame for FRAME
1550 and nil for X and Y. */)
1551 (void)
1553 FRAME_PTR f;
1554 Lisp_Object lispy_dummy;
1555 enum scroll_bar_part party_dummy;
1556 Lisp_Object x, y;
1557 Time long_dummy;
1559 f = SELECTED_FRAME ();
1560 x = y = Qnil;
1562 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1563 /* It's okay for the hook to refrain from storing anything. */
1564 if (FRAME_TERMINAL (f)->mouse_position_hook)
1565 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1566 &lispy_dummy, &party_dummy,
1567 &x, &y,
1568 &long_dummy);
1569 #endif
1570 XSETFRAME (lispy_dummy, f);
1571 return Fcons (lispy_dummy, Fcons (x, y));
1574 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1575 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1576 Coordinates are relative to the frame, not a window,
1577 so the coordinates of the top left character in the frame
1578 may be nonzero due to left-hand scroll bars or the menu bar.
1580 The position is given in character cells, where (0, 0) is the
1581 upper-left corner of the frame, X is the horizontal offset, and Y is
1582 the vertical offset.
1584 This function is a no-op for an X frame that is not visible.
1585 If you have just created a frame, you must wait for it to become visible
1586 before calling this function on it, like this.
1587 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1588 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1590 CHECK_LIVE_FRAME (frame);
1591 CHECK_TYPE_RANGED_INTEGER (int, x);
1592 CHECK_TYPE_RANGED_INTEGER (int, y);
1594 /* I think this should be done with a hook. */
1595 #ifdef HAVE_WINDOW_SYSTEM
1596 if (FRAME_WINDOW_P (XFRAME (frame)))
1597 /* Warping the mouse will cause enternotify and focus events. */
1598 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1599 #else
1600 #if defined (MSDOS) && defined (HAVE_MOUSE)
1601 if (FRAME_MSDOS_P (XFRAME (frame)))
1603 Fselect_frame (frame, Qnil);
1604 mouse_moveto (XINT (x), XINT (y));
1606 #else
1607 #ifdef HAVE_GPM
1609 Fselect_frame (frame, Qnil);
1610 term_mouse_moveto (XINT (x), XINT (y));
1612 #endif
1613 #endif
1614 #endif
1616 return Qnil;
1619 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1620 Sset_mouse_pixel_position, 3, 3, 0,
1621 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1622 The position is given in pixels, where (0, 0) is the upper-left corner
1623 of the frame, X is the horizontal offset, and Y is the vertical offset.
1625 Note, this is a no-op for an X frame that is not visible.
1626 If you have just created a frame, you must wait for it to become visible
1627 before calling this function on it, like this.
1628 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1629 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1631 CHECK_LIVE_FRAME (frame);
1632 CHECK_TYPE_RANGED_INTEGER (int, x);
1633 CHECK_TYPE_RANGED_INTEGER (int, y);
1635 /* I think this should be done with a hook. */
1636 #ifdef HAVE_WINDOW_SYSTEM
1637 if (FRAME_WINDOW_P (XFRAME (frame)))
1638 /* Warping the mouse will cause enternotify and focus events. */
1639 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1640 #else
1641 #if defined (MSDOS) && defined (HAVE_MOUSE)
1642 if (FRAME_MSDOS_P (XFRAME (frame)))
1644 Fselect_frame (frame, Qnil);
1645 mouse_moveto (XINT (x), XINT (y));
1647 #else
1648 #ifdef HAVE_GPM
1650 Fselect_frame (frame, Qnil);
1651 term_mouse_moveto (XINT (x), XINT (y));
1653 #endif
1654 #endif
1655 #endif
1657 return Qnil;
1660 static void make_frame_visible_1 (Lisp_Object);
1662 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1663 0, 1, "",
1664 doc: /* Make the frame FRAME visible (assuming it is an X window).
1665 If omitted, FRAME defaults to the currently selected frame. */)
1666 (Lisp_Object frame)
1668 if (NILP (frame))
1669 frame = selected_frame;
1671 CHECK_LIVE_FRAME (frame);
1673 /* I think this should be done with a hook. */
1674 #ifdef HAVE_WINDOW_SYSTEM
1675 if (FRAME_WINDOW_P (XFRAME (frame)))
1677 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1678 x_make_frame_visible (XFRAME (frame));
1680 #endif
1682 make_frame_visible_1 (XFRAME (frame)->root_window);
1684 /* Make menu bar update for the Buffers and Frames menus. */
1685 windows_or_buffers_changed++;
1687 return frame;
1690 /* Update the display_time slot of the buffers shown in WINDOW
1691 and all its descendants. */
1693 static void
1694 make_frame_visible_1 (Lisp_Object window)
1696 struct window *w;
1698 for (;!NILP (window); window = w->next)
1700 w = XWINDOW (window);
1702 if (!NILP (w->buffer))
1703 bset_display_time (XBUFFER (w->buffer), 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.
1715 If omitted, FRAME defaults to the currently selected frame.
1716 On graphical displays, invisible frames are not updated and are
1717 usually not displayed at all, even in a window system's \"taskbar\".
1719 Normally you may not make FRAME invisible if all other frames are invisible,
1720 but if the second optional argument FORCE is non-nil, you may do so.
1722 This function has no effect on text terminal frames. Such frames are
1723 always considered visible, whether or not they are currently being
1724 displayed in the terminal. */)
1725 (Lisp_Object frame, Lisp_Object force)
1727 if (NILP (frame))
1728 frame = selected_frame;
1730 CHECK_LIVE_FRAME (frame);
1732 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1733 error ("Attempt to make invisible the sole visible or iconified frame");
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 /* Use set_window_buffer instead of Fset_window_buffer (see
1740 discussion of bug#11984, bug#12025, bug#12026). */
1741 set_window_buffer (sf->minibuffer_window,
1742 XWINDOW (minibuf_window)->buffer, 0, 0);
1743 minibuf_window = sf->minibuffer_window;
1746 /* I think this should be done with a hook. */
1747 #ifdef HAVE_WINDOW_SYSTEM
1748 if (FRAME_WINDOW_P (XFRAME (frame)))
1749 x_make_frame_invisible (XFRAME (frame));
1750 #endif
1752 /* Make menu bar update for the Buffers and Frames menus. */
1753 windows_or_buffers_changed++;
1755 return Qnil;
1758 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1759 0, 1, "",
1760 doc: /* Make the frame FRAME into an icon.
1761 If omitted, FRAME defaults to the currently selected frame. */)
1762 (Lisp_Object frame)
1764 if (NILP (frame))
1765 frame = selected_frame;
1767 CHECK_LIVE_FRAME (frame);
1769 #if 0 /* This isn't logically necessary, and it can do GC. */
1770 /* Don't let the frame remain selected. */
1771 if (EQ (frame, selected_frame))
1772 Fhandle_switch_frame (next_frame (frame, Qt));
1773 #endif
1775 /* Don't allow minibuf_window to remain on an iconified frame. */
1776 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1778 struct frame *sf = XFRAME (selected_frame);
1779 /* Use set_window_buffer instead of Fset_window_buffer (see
1780 discussion of bug#11984, bug#12025, bug#12026). */
1781 set_window_buffer (sf->minibuffer_window,
1782 XWINDOW (minibuf_window)->buffer, 0, 0);
1783 minibuf_window = sf->minibuffer_window;
1786 /* I think this should be done with a hook. */
1787 #ifdef HAVE_WINDOW_SYSTEM
1788 if (FRAME_WINDOW_P (XFRAME (frame)))
1789 x_iconify_frame (XFRAME (frame));
1790 #endif
1792 /* Make menu bar update for the Buffers and Frames menus. */
1793 windows_or_buffers_changed++;
1795 return Qnil;
1798 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1799 1, 1, 0,
1800 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1801 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1802 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1803 On graphical displays, invisible frames are not updated and are
1804 usually not displayed at all, even in a window system's \"taskbar\".
1806 If FRAME is a text terminal frame, this always returns t.
1807 Such frames are always considered visible, whether or not they are
1808 currently being displayed on the terminal. */)
1809 (Lisp_Object frame)
1811 CHECK_LIVE_FRAME (frame);
1813 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1815 if (FRAME_VISIBLE_P (XFRAME (frame)))
1816 return Qt;
1817 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1818 return Qicon;
1819 return Qnil;
1822 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1823 0, 0, 0,
1824 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1825 (void)
1827 Lisp_Object tail, frame;
1828 struct frame *f;
1829 Lisp_Object value;
1831 value = Qnil;
1832 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1834 frame = XCAR (tail);
1835 if (!FRAMEP (frame))
1836 continue;
1837 f = XFRAME (frame);
1838 if (FRAME_VISIBLE_P (f))
1839 value = Fcons (frame, value);
1841 return value;
1845 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1846 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1847 If FRAME is invisible or iconified, make it visible.
1848 If you don't specify a frame, the selected frame is used.
1849 If Emacs is displaying on an ordinary terminal or some other device which
1850 doesn't support multiple overlapping frames, this function selects FRAME. */)
1851 (Lisp_Object frame)
1853 struct frame *f;
1854 if (NILP (frame))
1855 frame = selected_frame;
1857 CHECK_LIVE_FRAME (frame);
1859 f = XFRAME (frame);
1861 if (FRAME_TERMCAP_P (f))
1862 /* On a text terminal select FRAME. */
1863 Fselect_frame (frame, Qnil);
1864 else
1865 /* Do like the documentation says. */
1866 Fmake_frame_visible (frame);
1868 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1869 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
1871 return Qnil;
1874 /* Should we have a corresponding function called Flower_Power? */
1875 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1876 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1877 If you don't specify a frame, the selected frame is used.
1878 If Emacs is displaying on an ordinary terminal or some other device which
1879 doesn't support multiple overlapping frames, this function does nothing. */)
1880 (Lisp_Object frame)
1882 struct frame *f;
1884 if (NILP (frame))
1885 frame = selected_frame;
1887 CHECK_LIVE_FRAME (frame);
1889 f = XFRAME (frame);
1891 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1892 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
1894 return Qnil;
1898 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1899 1, 2, 0,
1900 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1901 In other words, switch-frame events caused by events in FRAME will
1902 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1903 FOCUS-FRAME after reading an event typed at FRAME.
1905 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
1906 frame again receives its own keystrokes.
1908 Focus redirection is useful for temporarily redirecting keystrokes to
1909 a surrogate minibuffer frame when a frame doesn't have its own
1910 minibuffer window.
1912 A frame's focus redirection can be changed by `select-frame'. If frame
1913 FOO is selected, and then a different frame BAR is selected, any
1914 frames redirecting their focus to FOO are shifted to redirect their
1915 focus to BAR. This allows focus redirection to work properly when the
1916 user switches from one frame to another using `select-window'.
1918 This means that a frame whose focus is redirected to itself is treated
1919 differently from a frame whose focus is redirected to nil; the former
1920 is affected by `select-frame', while the latter is not.
1922 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1923 (Lisp_Object frame, Lisp_Object focus_frame)
1925 struct frame *f;
1927 /* Note that we don't check for a live frame here. It's reasonable
1928 to redirect the focus of a frame you're about to delete, if you
1929 know what other frame should receive those keystrokes. */
1930 CHECK_FRAME (frame);
1932 if (! NILP (focus_frame))
1933 CHECK_LIVE_FRAME (focus_frame);
1935 f = XFRAME (frame);
1937 fset_focus_frame (f, focus_frame);
1939 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
1940 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
1942 return Qnil;
1946 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1947 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1948 This returns nil if FRAME's focus is not redirected.
1949 See `redirect-frame-focus'. */)
1950 (Lisp_Object frame)
1952 CHECK_LIVE_FRAME (frame);
1954 return FRAME_FOCUS_FRAME (XFRAME (frame));
1959 /* Return the value of frame parameter PROP in frame FRAME. */
1961 #ifdef HAVE_WINDOW_SYSTEM
1962 #if !HAVE_NS
1963 static
1964 #endif
1965 Lisp_Object
1966 get_frame_param (register struct frame *frame, Lisp_Object prop)
1968 register Lisp_Object tem;
1970 tem = Fassq (prop, frame->param_alist);
1971 if (EQ (tem, Qnil))
1972 return tem;
1973 return Fcdr (tem);
1975 #endif
1977 /* Return the buffer-predicate of the selected frame. */
1979 Lisp_Object
1980 frame_buffer_predicate (Lisp_Object frame)
1982 return XFRAME (frame)->buffer_predicate;
1985 /* Return the buffer-list of the selected frame. */
1987 static Lisp_Object
1988 frame_buffer_list (Lisp_Object frame)
1990 return XFRAME (frame)->buffer_list;
1993 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
1995 void
1996 frames_discard_buffer (Lisp_Object buffer)
1998 Lisp_Object frame, tail;
2000 FOR_EACH_FRAME (tail, frame)
2002 fset_buffer_list
2003 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2004 fset_buried_buffer_list
2005 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2009 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2010 If the alist already has an element for PROP, we change it. */
2012 void
2013 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2015 register Lisp_Object tem;
2017 tem = Fassq (prop, *alistptr);
2018 if (EQ (tem, Qnil))
2019 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2020 else
2021 Fsetcdr (tem, val);
2024 static int
2025 frame_name_fnn_p (char *str, ptrdiff_t len)
2027 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2029 char *p = str + 2;
2030 while ('0' <= *p && *p <= '9')
2031 p++;
2032 if (p == str + len)
2033 return 1;
2035 return 0;
2038 /* Set the name of the terminal frame. Also used by MSDOS frames.
2039 Modeled after x_set_name which is used for WINDOW frames. */
2041 static void
2042 set_term_frame_name (struct frame *f, Lisp_Object name)
2044 f->explicit_name = ! NILP (name);
2046 /* If NAME is nil, set the name to F<num>. */
2047 if (NILP (name))
2049 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2051 /* Check for no change needed in this very common case
2052 before we do any consing. */
2053 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2054 return;
2056 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2058 else
2060 CHECK_STRING (name);
2062 /* Don't change the name if it's already NAME. */
2063 if (! NILP (Fstring_equal (name, f->name)))
2064 return;
2066 /* Don't allow the user to set the frame name to F<num>, so it
2067 doesn't clash with the names we generate for terminal frames. */
2068 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2069 error ("Frame names of the form F<num> are usurped by Emacs");
2072 fset_name (f, name);
2073 update_mode_lines = 1;
2076 void
2077 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2079 register Lisp_Object old_alist_elt;
2081 /* The buffer-list parameters are stored in a special place and not
2082 in the alist. All buffers must be live. */
2083 if (EQ (prop, Qbuffer_list))
2085 Lisp_Object list = Qnil;
2086 for (; CONSP (val); val = XCDR (val))
2087 if (!NILP (Fbuffer_live_p (XCAR (val))))
2088 list = Fcons (XCAR (val), list);
2089 fset_buffer_list (f, Fnreverse (list));
2090 return;
2092 if (EQ (prop, Qburied_buffer_list))
2094 Lisp_Object list = Qnil;
2095 for (; CONSP (val); val = XCDR (val))
2096 if (!NILP (Fbuffer_live_p (XCAR (val))))
2097 list = Fcons (XCAR (val), list);
2098 fset_buried_buffer_list (f, Fnreverse (list));
2099 return;
2102 /* If PROP is a symbol which is supposed to have frame-local values,
2103 and it is set up based on this frame, switch to the global
2104 binding. That way, we can create or alter the frame-local binding
2105 without messing up the symbol's status. */
2106 if (SYMBOLP (prop))
2108 struct Lisp_Symbol *sym = XSYMBOL (prop);
2109 start:
2110 switch (sym->redirect)
2112 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2113 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2114 case SYMBOL_LOCALIZED:
2115 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2116 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2117 swap_in_global_binding (sym);
2118 break;
2120 default: abort ();
2124 /* The tty color needed to be set before the frame's parameter
2125 alist was updated with the new value. This is not true any more,
2126 but we still do this test early on. */
2127 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2128 && f == FRAME_TTY (f)->previous_frame)
2129 /* Force redisplay of this tty. */
2130 FRAME_TTY (f)->previous_frame = NULL;
2132 /* Update the frame parameter alist. */
2133 old_alist_elt = Fassq (prop, f->param_alist);
2134 if (EQ (old_alist_elt, Qnil))
2135 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2136 else
2137 Fsetcdr (old_alist_elt, val);
2139 /* Update some other special parameters in their special places
2140 in addition to the alist. */
2142 if (EQ (prop, Qbuffer_predicate))
2143 fset_buffer_predicate (f, val);
2145 if (! FRAME_WINDOW_P (f))
2147 if (EQ (prop, Qmenu_bar_lines))
2148 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2149 else if (EQ (prop, Qname))
2150 set_term_frame_name (f, val);
2153 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2155 if (! MINI_WINDOW_P (XWINDOW (val)))
2156 error ("Surrogate minibuffer windows must be minibuffer windows");
2158 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2159 && !EQ (val, f->minibuffer_window))
2160 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2162 /* Install the chosen minibuffer window, with proper buffer. */
2163 fset_minibuffer_window (f, val);
2167 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2168 doc: /* Return the parameters-alist of frame FRAME.
2169 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2170 The meaningful PARMs depend on the kind of frame.
2171 If FRAME is omitted, return information on the currently selected frame. */)
2172 (Lisp_Object frame)
2174 Lisp_Object alist;
2175 FRAME_PTR f;
2176 int height, width;
2177 struct gcpro gcpro1;
2179 if (NILP (frame))
2180 frame = selected_frame;
2182 CHECK_FRAME (frame);
2183 f = XFRAME (frame);
2185 if (!FRAME_LIVE_P (f))
2186 return Qnil;
2188 alist = Fcopy_alist (f->param_alist);
2189 GCPRO1 (alist);
2191 if (!FRAME_WINDOW_P (f))
2193 int fg = FRAME_FOREGROUND_PIXEL (f);
2194 int bg = FRAME_BACKGROUND_PIXEL (f);
2195 Lisp_Object elt;
2197 /* If the frame's parameter alist says the colors are
2198 unspecified and reversed, take the frame's background pixel
2199 for foreground and vice versa. */
2200 elt = Fassq (Qforeground_color, alist);
2201 if (CONSP (elt) && STRINGP (XCDR (elt)))
2203 if (strncmp (SSDATA (XCDR (elt)),
2204 unspecified_bg,
2205 SCHARS (XCDR (elt))) == 0)
2206 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2207 else if (strncmp (SSDATA (XCDR (elt)),
2208 unspecified_fg,
2209 SCHARS (XCDR (elt))) == 0)
2210 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2212 else
2213 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2214 elt = Fassq (Qbackground_color, alist);
2215 if (CONSP (elt) && STRINGP (XCDR (elt)))
2217 if (strncmp (SSDATA (XCDR (elt)),
2218 unspecified_fg,
2219 SCHARS (XCDR (elt))) == 0)
2220 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2221 else if (strncmp (SSDATA (XCDR (elt)),
2222 unspecified_bg,
2223 SCHARS (XCDR (elt))) == 0)
2224 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2226 else
2227 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2228 store_in_alist (&alist, intern ("font"),
2229 build_string (FRAME_MSDOS_P (f)
2230 ? "ms-dos"
2231 : FRAME_W32_P (f) ? "w32term"
2232 :"tty"));
2234 store_in_alist (&alist, Qname, f->name);
2235 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2236 store_in_alist (&alist, Qheight, make_number (height));
2237 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2238 store_in_alist (&alist, Qwidth, make_number (width));
2239 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2240 store_in_alist (&alist, Qminibuffer,
2241 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2242 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2243 : FRAME_MINIBUF_WINDOW (f)));
2244 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2245 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2246 store_in_alist (&alist, Qburied_buffer_list,
2247 XFRAME (frame)->buried_buffer_list);
2249 /* I think this should be done with a hook. */
2250 #ifdef HAVE_WINDOW_SYSTEM
2251 if (FRAME_WINDOW_P (f))
2252 x_report_frame_params (f, &alist);
2253 else
2254 #endif
2256 /* This ought to be correct in f->param_alist for an X frame. */
2257 Lisp_Object lines;
2258 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2259 store_in_alist (&alist, Qmenu_bar_lines, lines);
2262 UNGCPRO;
2263 return alist;
2267 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2268 doc: /* Return FRAME's value for parameter PARAMETER.
2269 If FRAME is nil, describe the currently selected frame. */)
2270 (Lisp_Object frame, Lisp_Object parameter)
2272 struct frame *f;
2273 Lisp_Object value;
2275 if (NILP (frame))
2276 frame = selected_frame;
2277 else
2278 CHECK_FRAME (frame);
2279 CHECK_SYMBOL (parameter);
2281 f = XFRAME (frame);
2282 value = Qnil;
2284 if (FRAME_LIVE_P (f))
2286 /* Avoid consing in frequent cases. */
2287 if (EQ (parameter, Qname))
2288 value = f->name;
2289 #ifdef HAVE_X_WINDOWS
2290 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2291 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2292 #endif /* HAVE_X_WINDOWS */
2293 else if (EQ (parameter, Qbackground_color)
2294 || EQ (parameter, Qforeground_color))
2296 value = Fassq (parameter, f->param_alist);
2297 if (CONSP (value))
2299 value = XCDR (value);
2300 /* Fframe_parameters puts the actual fg/bg color names,
2301 even if f->param_alist says otherwise. This is
2302 important when param_alist's notion of colors is
2303 "unspecified". We need to do the same here. */
2304 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2306 const char *color_name;
2307 ptrdiff_t csz;
2309 if (EQ (parameter, Qbackground_color))
2311 color_name = SSDATA (value);
2312 csz = SCHARS (value);
2313 if (strncmp (color_name, unspecified_bg, csz) == 0)
2314 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2315 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2316 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2318 else if (EQ (parameter, Qforeground_color))
2320 color_name = SSDATA (value);
2321 csz = SCHARS (value);
2322 if (strncmp (color_name, unspecified_fg, csz) == 0)
2323 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2324 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2325 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2329 else
2330 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2332 else if (EQ (parameter, Qdisplay_type)
2333 || EQ (parameter, Qbackground_mode))
2334 value = Fcdr (Fassq (parameter, f->param_alist));
2335 else
2336 /* FIXME: Avoid this code path at all (as well as code duplication)
2337 by sharing more code with Fframe_parameters. */
2338 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2341 return value;
2345 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2346 Smodify_frame_parameters, 2, 2, 0,
2347 doc: /* Modify the parameters of frame FRAME according to ALIST.
2348 If FRAME is nil, it defaults to the selected frame.
2349 ALIST is an alist of parameters to change and their new values.
2350 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2351 The meaningful PARMs depend on the kind of frame.
2352 Undefined PARMs are ignored, but stored in the frame's parameter list
2353 so that `frame-parameters' will return them.
2355 The value of frame parameter FOO can also be accessed
2356 as a frame-local binding for the variable FOO, if you have
2357 enabled such bindings for that variable with `make-variable-frame-local'.
2358 Note that this functionality is obsolete as of Emacs 22.2, and its
2359 use is not recommended. Explicitly check for a frame-parameter instead. */)
2360 (Lisp_Object frame, Lisp_Object alist)
2362 FRAME_PTR f;
2363 register Lisp_Object tail, prop, val;
2365 if (EQ (frame, Qnil))
2366 frame = selected_frame;
2367 CHECK_LIVE_FRAME (frame);
2368 f = XFRAME (frame);
2370 /* I think this should be done with a hook. */
2371 #ifdef HAVE_WINDOW_SYSTEM
2372 if (FRAME_WINDOW_P (f))
2373 x_set_frame_parameters (f, alist);
2374 else
2375 #endif
2376 #ifdef MSDOS
2377 if (FRAME_MSDOS_P (f))
2378 IT_set_frame_parameters (f, alist);
2379 else
2380 #endif
2383 EMACS_INT length = XFASTINT (Flength (alist));
2384 ptrdiff_t i;
2385 Lisp_Object *parms;
2386 Lisp_Object *values;
2387 USE_SAFE_ALLOCA;
2388 SAFE_ALLOCA_LISP (parms, 2 * length);
2389 values = parms + length;
2391 /* Extract parm names and values into those vectors. */
2393 i = 0;
2394 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2396 Lisp_Object elt;
2398 elt = XCAR (tail);
2399 parms[i] = Fcar (elt);
2400 values[i] = Fcdr (elt);
2401 i++;
2404 /* Now process them in reverse of specified order. */
2405 while (--i >= 0)
2407 prop = parms[i];
2408 val = values[i];
2409 store_frame_param (f, prop, val);
2411 if (EQ (prop, Qforeground_color)
2412 || EQ (prop, Qbackground_color))
2413 update_face_from_frame_parameter (f, prop, val);
2416 SAFE_FREE ();
2418 return Qnil;
2421 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2422 0, 1, 0,
2423 doc: /* Height in pixels of a line in the font in frame FRAME.
2424 If FRAME is omitted, the selected frame is used.
2425 For a terminal frame, the value is always 1. */)
2426 (Lisp_Object frame)
2428 struct frame *f;
2430 if (NILP (frame))
2431 frame = selected_frame;
2432 CHECK_FRAME (frame);
2433 f = XFRAME (frame);
2435 #ifdef HAVE_WINDOW_SYSTEM
2436 if (FRAME_WINDOW_P (f))
2437 return make_number (x_char_height (f));
2438 else
2439 #endif
2440 return make_number (1);
2444 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2445 0, 1, 0,
2446 doc: /* Width in pixels of characters in the font in frame FRAME.
2447 If FRAME is omitted, the selected frame is used.
2448 On a graphical screen, the width is the standard width of the default font.
2449 For a terminal screen, the value is always 1. */)
2450 (Lisp_Object frame)
2452 struct frame *f;
2454 if (NILP (frame))
2455 frame = selected_frame;
2456 CHECK_FRAME (frame);
2457 f = XFRAME (frame);
2459 #ifdef HAVE_WINDOW_SYSTEM
2460 if (FRAME_WINDOW_P (f))
2461 return make_number (x_char_width (f));
2462 else
2463 #endif
2464 return make_number (1);
2467 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2468 Sframe_pixel_height, 0, 1, 0,
2469 doc: /* Return a FRAME's height in pixels.
2470 If FRAME is omitted, the selected frame is used. The exact value
2471 of the result depends on the window-system and toolkit in use:
2473 In the Gtk+ version of Emacs, it includes only any window (including
2474 the minibuffer or echo area), mode line, and header line. It does not
2475 include the tool bar or menu bar.
2477 With the Motif or Lucid toolkits, it also includes the tool bar (but
2478 not the menu bar).
2480 In a graphical version with no toolkit, it includes both the tool bar
2481 and menu bar.
2483 For a text terminal, it includes the menu bar. In this case, the
2484 result is really in characters rather than pixels (i.e., is identical
2485 to `frame-height'). */)
2486 (Lisp_Object frame)
2488 struct frame *f;
2490 if (NILP (frame))
2491 frame = selected_frame;
2492 CHECK_FRAME (frame);
2493 f = XFRAME (frame);
2495 #ifdef HAVE_WINDOW_SYSTEM
2496 if (FRAME_WINDOW_P (f))
2497 return make_number (x_pixel_height (f));
2498 else
2499 #endif
2500 return make_number (FRAME_LINES (f));
2503 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2504 Sframe_pixel_width, 0, 1, 0,
2505 doc: /* Return FRAME's width in pixels.
2506 For a terminal frame, the result really gives the width in characters.
2507 If FRAME is omitted, the selected frame is used. */)
2508 (Lisp_Object frame)
2510 struct frame *f;
2512 if (NILP (frame))
2513 frame = selected_frame;
2514 CHECK_FRAME (frame);
2515 f = XFRAME (frame);
2517 #ifdef HAVE_WINDOW_SYSTEM
2518 if (FRAME_WINDOW_P (f))
2519 return make_number (x_pixel_width (f));
2520 else
2521 #endif
2522 return make_number (FRAME_COLS (f));
2525 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2526 Stool_bar_pixel_width, 0, 1, 0,
2527 doc: /* Return width in pixels of FRAME's tool bar.
2528 The result is greater than zero only when the tool bar is on the left
2529 or right side of FRAME. If FRAME is omitted, the selected frame is
2530 used. */)
2531 (Lisp_Object frame)
2533 if (NILP (frame))
2534 frame = selected_frame;
2535 CHECK_FRAME (frame);
2537 #ifdef FRAME_TOOLBAR_WIDTH
2538 if (FRAME_WINDOW_P (XFRAME (frame)))
2539 return make_number (FRAME_TOOLBAR_WIDTH (XFRAME (frame)));
2540 #endif
2541 return make_number (0);
2544 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2545 doc: /* Specify that the frame FRAME has LINES lines.
2546 Optional third arg non-nil means that redisplay should use LINES lines
2547 but that the idea of the actual height of the frame should not be changed. */)
2548 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend)
2550 register struct frame *f;
2552 CHECK_TYPE_RANGED_INTEGER (int, lines);
2553 if (NILP (frame))
2554 frame = selected_frame;
2555 CHECK_LIVE_FRAME (frame);
2556 f = XFRAME (frame);
2558 /* I think this should be done with a hook. */
2559 #ifdef HAVE_WINDOW_SYSTEM
2560 if (FRAME_WINDOW_P (f))
2562 if (XINT (lines) != FRAME_LINES (f))
2563 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2564 do_pending_window_change (0);
2566 else
2567 #endif
2568 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2569 return Qnil;
2572 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2573 doc: /* Specify that the frame FRAME has COLS columns.
2574 Optional third arg non-nil means that redisplay should use COLS columns
2575 but that the idea of the actual width of the frame should not be changed. */)
2576 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2578 register struct frame *f;
2579 CHECK_TYPE_RANGED_INTEGER (int, cols);
2580 if (NILP (frame))
2581 frame = selected_frame;
2582 CHECK_LIVE_FRAME (frame);
2583 f = XFRAME (frame);
2585 /* I think this should be done with a hook. */
2586 #ifdef HAVE_WINDOW_SYSTEM
2587 if (FRAME_WINDOW_P (f))
2589 if (XINT (cols) != FRAME_COLS (f))
2590 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2591 do_pending_window_change (0);
2593 else
2594 #endif
2595 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2596 return Qnil;
2599 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2600 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2601 (Lisp_Object frame, Lisp_Object cols, Lisp_Object rows)
2603 register struct frame *f;
2605 CHECK_LIVE_FRAME (frame);
2606 CHECK_TYPE_RANGED_INTEGER (int, cols);
2607 CHECK_TYPE_RANGED_INTEGER (int, rows);
2608 f = XFRAME (frame);
2610 /* I think this should be done with a hook. */
2611 #ifdef HAVE_WINDOW_SYSTEM
2612 if (FRAME_WINDOW_P (f))
2614 if (XINT (rows) != FRAME_LINES (f)
2615 || XINT (cols) != FRAME_COLS (f)
2616 || f->new_text_lines || f->new_text_cols)
2617 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2618 do_pending_window_change (0);
2620 else
2621 #endif
2622 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2624 return Qnil;
2627 DEFUN ("set-frame-position", Fset_frame_position,
2628 Sset_frame_position, 3, 3, 0,
2629 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2630 This is actually the position of the upper left corner of the frame.
2631 Negative values for XOFFSET or YOFFSET are interpreted relative to
2632 the rightmost or bottommost possible position (that stays within the screen). */)
2633 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2635 register struct frame *f;
2637 CHECK_LIVE_FRAME (frame);
2638 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2639 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2640 f = XFRAME (frame);
2642 /* I think this should be done with a hook. */
2643 #ifdef HAVE_WINDOW_SYSTEM
2644 if (FRAME_WINDOW_P (f))
2645 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2646 #endif
2648 return Qt;
2652 /***********************************************************************
2653 Frame Parameters
2654 ***********************************************************************/
2656 /* Connect the frame-parameter names for X frames
2657 to the ways of passing the parameter values to the window system.
2659 The name of a parameter, as a Lisp symbol,
2660 has an `x-frame-parameter' property which is an integer in Lisp
2661 that is an index in this table. */
2663 struct frame_parm_table {
2664 const char *name;
2665 Lisp_Object *variable;
2668 static const struct frame_parm_table frame_parms[] =
2670 {"auto-raise", &Qauto_raise},
2671 {"auto-lower", &Qauto_lower},
2672 {"background-color", 0},
2673 {"border-color", &Qborder_color},
2674 {"border-width", &Qborder_width},
2675 {"cursor-color", &Qcursor_color},
2676 {"cursor-type", &Qcursor_type},
2677 {"font", 0},
2678 {"foreground-color", 0},
2679 {"icon-name", &Qicon_name},
2680 {"icon-type", &Qicon_type},
2681 {"internal-border-width", &Qinternal_border_width},
2682 {"menu-bar-lines", &Qmenu_bar_lines},
2683 {"mouse-color", &Qmouse_color},
2684 {"name", &Qname},
2685 {"scroll-bar-width", &Qscroll_bar_width},
2686 {"title", &Qtitle},
2687 {"unsplittable", &Qunsplittable},
2688 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2689 {"visibility", &Qvisibility},
2690 {"tool-bar-lines", &Qtool_bar_lines},
2691 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2692 {"scroll-bar-background", &Qscroll_bar_background},
2693 {"screen-gamma", &Qscreen_gamma},
2694 {"line-spacing", &Qline_spacing},
2695 {"left-fringe", &Qleft_fringe},
2696 {"right-fringe", &Qright_fringe},
2697 {"wait-for-wm", &Qwait_for_wm},
2698 {"fullscreen", &Qfullscreen},
2699 {"font-backend", &Qfont_backend},
2700 {"alpha", &Qalpha},
2701 {"sticky", &Qsticky},
2702 {"tool-bar-position", &Qtool_bar_position},
2705 #ifdef WINDOWSNT
2707 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2708 wanted positions of the WM window (not Emacs window).
2709 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2710 window (FRAME_X_WINDOW).
2713 void
2714 x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
2716 int newwidth = FRAME_COLS (f);
2717 int newheight = FRAME_LINES (f);
2718 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2720 *top_pos = f->top_pos;
2721 *left_pos = f->left_pos;
2723 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2725 int ph;
2727 ph = x_display_pixel_height (dpyinfo);
2728 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2729 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2730 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2731 *top_pos = 0;
2734 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2736 int pw;
2738 pw = x_display_pixel_width (dpyinfo);
2739 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2740 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2741 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2742 *left_pos = 0;
2745 *width = newwidth;
2746 *height = newheight;
2749 #endif /* WINDOWSNT */
2751 #ifdef HAVE_WINDOW_SYSTEM
2753 /* Change the parameters of frame F as specified by ALIST.
2754 If a parameter is not specially recognized, do nothing special;
2755 otherwise call the `x_set_...' function for that parameter.
2756 Except for certain geometry properties, always call store_frame_param
2757 to store the new value in the parameter alist. */
2759 void
2760 x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2762 Lisp_Object tail;
2764 /* If both of these parameters are present, it's more efficient to
2765 set them both at once. So we wait until we've looked at the
2766 entire list before we set them. */
2767 int width, height;
2769 /* Same here. */
2770 Lisp_Object left, top;
2772 /* Same with these. */
2773 Lisp_Object icon_left, icon_top;
2775 /* Record in these vectors all the parms specified. */
2776 Lisp_Object *parms;
2777 Lisp_Object *values;
2778 ptrdiff_t i, p;
2779 int left_no_change = 0, top_no_change = 0;
2780 int icon_left_no_change = 0, icon_top_no_change = 0;
2781 int size_changed = 0;
2782 struct gcpro gcpro1, gcpro2;
2784 i = 0;
2785 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2786 i++;
2788 parms = alloca (i * sizeof *parms);
2789 values = alloca (i * sizeof *values);
2791 /* Extract parm names and values into those vectors. */
2793 i = 0;
2794 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2796 Lisp_Object elt;
2798 elt = XCAR (tail);
2799 parms[i] = Fcar (elt);
2800 values[i] = Fcdr (elt);
2801 i++;
2803 /* TAIL and ALIST are not used again below here. */
2804 alist = tail = Qnil;
2806 GCPRO2 (*parms, *values);
2807 gcpro1.nvars = i;
2808 gcpro2.nvars = i;
2810 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2811 because their values appear in VALUES and strings are not valid. */
2812 top = left = Qunbound;
2813 icon_left = icon_top = Qunbound;
2815 /* Provide default values for HEIGHT and WIDTH. */
2816 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2817 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2819 /* Process foreground_color and background_color before anything else.
2820 They are independent of other properties, but other properties (e.g.,
2821 cursor_color) are dependent upon them. */
2822 /* Process default font as well, since fringe widths depends on it. */
2823 for (p = 0; p < i; p++)
2825 Lisp_Object prop, val;
2827 prop = parms[p];
2828 val = values[p];
2829 if (EQ (prop, Qforeground_color)
2830 || EQ (prop, Qbackground_color)
2831 || EQ (prop, Qfont))
2833 register Lisp_Object param_index, old_value;
2835 old_value = get_frame_param (f, prop);
2836 if (NILP (Fequal (val, old_value)))
2838 store_frame_param (f, prop, val);
2840 param_index = Fget (prop, Qx_frame_parameter);
2841 if (NATNUMP (param_index)
2842 && (XFASTINT (param_index)
2843 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2844 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2845 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2850 /* Now process them in reverse of specified order. */
2851 while (i-- != 0)
2853 Lisp_Object prop, val;
2855 prop = parms[i];
2856 val = values[i];
2858 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
2860 size_changed = 1;
2861 width = XFASTINT (val);
2863 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
2865 size_changed = 1;
2866 height = XFASTINT (val);
2868 else if (EQ (prop, Qtop))
2869 top = val;
2870 else if (EQ (prop, Qleft))
2871 left = val;
2872 else if (EQ (prop, Qicon_top))
2873 icon_top = val;
2874 else if (EQ (prop, Qicon_left))
2875 icon_left = val;
2876 else if (EQ (prop, Qforeground_color)
2877 || EQ (prop, Qbackground_color)
2878 || EQ (prop, Qfont))
2879 /* Processed above. */
2880 continue;
2881 else
2883 register Lisp_Object param_index, old_value;
2885 old_value = get_frame_param (f, prop);
2887 store_frame_param (f, prop, val);
2889 param_index = Fget (prop, Qx_frame_parameter);
2890 if (NATNUMP (param_index)
2891 && (XFASTINT (param_index)
2892 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2893 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2894 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2898 /* Don't die if just one of these was set. */
2899 if (EQ (left, Qunbound))
2901 left_no_change = 1;
2902 if (f->left_pos < 0)
2903 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
2904 else
2905 XSETINT (left, f->left_pos);
2907 if (EQ (top, Qunbound))
2909 top_no_change = 1;
2910 if (f->top_pos < 0)
2911 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
2912 else
2913 XSETINT (top, f->top_pos);
2916 /* If one of the icon positions was not set, preserve or default it. */
2917 if (! TYPE_RANGED_INTEGERP (int, icon_left))
2919 icon_left_no_change = 1;
2920 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2921 if (NILP (icon_left))
2922 XSETINT (icon_left, 0);
2924 if (! TYPE_RANGED_INTEGERP (int, icon_top))
2926 icon_top_no_change = 1;
2927 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2928 if (NILP (icon_top))
2929 XSETINT (icon_top, 0);
2932 /* Don't set these parameters unless they've been explicitly
2933 specified. The window might be mapped or resized while we're in
2934 this function, and we don't want to override that unless the lisp
2935 code has asked for it.
2937 Don't set these parameters unless they actually differ from the
2938 window's current parameters; the window may not actually exist
2939 yet. */
2941 Lisp_Object frame;
2943 check_frame_size (f, &height, &width);
2945 XSETFRAME (frame, f);
2947 if (size_changed
2948 && (width != FRAME_COLS (f)
2949 || height != FRAME_LINES (f)
2950 || f->new_text_lines || f->new_text_cols))
2951 Fset_frame_size (frame, make_number (width), make_number (height));
2953 if ((!NILP (left) || !NILP (top))
2954 && ! (left_no_change && top_no_change)
2955 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2956 && NUMBERP (top) && XINT (top) == f->top_pos))
2958 int leftpos = 0;
2959 int toppos = 0;
2961 /* Record the signs. */
2962 f->size_hint_flags &= ~ (XNegative | YNegative);
2963 if (EQ (left, Qminus))
2964 f->size_hint_flags |= XNegative;
2965 else if (TYPE_RANGED_INTEGERP (int, left))
2967 leftpos = XINT (left);
2968 if (leftpos < 0)
2969 f->size_hint_flags |= XNegative;
2971 else if (CONSP (left) && EQ (XCAR (left), Qminus)
2972 && CONSP (XCDR (left))
2973 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
2975 leftpos = - XINT (XCAR (XCDR (left)));
2976 f->size_hint_flags |= XNegative;
2978 else if (CONSP (left) && EQ (XCAR (left), Qplus)
2979 && CONSP (XCDR (left))
2980 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
2982 leftpos = XINT (XCAR (XCDR (left)));
2985 if (EQ (top, Qminus))
2986 f->size_hint_flags |= YNegative;
2987 else if (TYPE_RANGED_INTEGERP (int, top))
2989 toppos = XINT (top);
2990 if (toppos < 0)
2991 f->size_hint_flags |= YNegative;
2993 else if (CONSP (top) && EQ (XCAR (top), Qminus)
2994 && CONSP (XCDR (top))
2995 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
2997 toppos = - XINT (XCAR (XCDR (top)));
2998 f->size_hint_flags |= YNegative;
3000 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3001 && CONSP (XCDR (top))
3002 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3004 toppos = XINT (XCAR (XCDR (top)));
3008 /* Store the numeric value of the position. */
3009 f->top_pos = toppos;
3010 f->left_pos = leftpos;
3012 f->win_gravity = NorthWestGravity;
3014 /* Actually set that position, and convert to absolute. */
3015 x_set_offset (f, leftpos, toppos, -1);
3018 if ((!NILP (icon_left) || !NILP (icon_top))
3019 && ! (icon_left_no_change && icon_top_no_change))
3020 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3023 UNGCPRO;
3027 /* Insert a description of internally-recorded parameters of frame X
3028 into the parameter alist *ALISTPTR that is to be given to the user.
3029 Only parameters that are specific to the X window system
3030 and whose values are not correctly recorded in the frame's
3031 param_alist need to be considered here. */
3033 void
3034 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3036 char buf[16];
3037 Lisp_Object tem;
3038 unsigned long w;
3040 /* Represent negative positions (off the top or left screen edge)
3041 in a way that Fmodify_frame_parameters will understand correctly. */
3042 XSETINT (tem, f->left_pos);
3043 if (f->left_pos >= 0)
3044 store_in_alist (alistptr, Qleft, tem);
3045 else
3046 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3048 XSETINT (tem, f->top_pos);
3049 if (f->top_pos >= 0)
3050 store_in_alist (alistptr, Qtop, tem);
3051 else
3052 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3054 store_in_alist (alistptr, Qborder_width,
3055 make_number (f->border_width));
3056 store_in_alist (alistptr, Qinternal_border_width,
3057 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3058 store_in_alist (alistptr, Qleft_fringe,
3059 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3060 store_in_alist (alistptr, Qright_fringe,
3061 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3062 store_in_alist (alistptr, Qscroll_bar_width,
3063 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3064 ? make_number (0)
3065 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3066 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3067 /* nil means "use default width"
3068 for non-toolkit scroll bar.
3069 ruler-mode.el depends on this. */
3070 : Qnil));
3071 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3072 MS-Windows it returns a value whose type is HANDLE, which is
3073 actually a pointer. Explicit casting avoids compiler
3074 warnings. */
3075 w = (unsigned long) FRAME_X_WINDOW (f);
3076 store_in_alist (alistptr, Qwindow_id,
3077 make_formatted_string (buf, "%lu", w));
3078 #ifdef HAVE_X_WINDOWS
3079 #ifdef USE_X_TOOLKIT
3080 /* Tooltip frame may not have this widget. */
3081 if (FRAME_X_OUTPUT (f)->widget)
3082 #endif
3083 w = (unsigned long) FRAME_OUTER_WINDOW (f);
3084 store_in_alist (alistptr, Qouter_window_id,
3085 make_formatted_string (buf, "%lu", w));
3086 #endif
3087 store_in_alist (alistptr, Qicon_name, f->icon_name);
3088 FRAME_SAMPLE_VISIBILITY (f);
3089 store_in_alist (alistptr, Qvisibility,
3090 (FRAME_VISIBLE_P (f) ? Qt
3091 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3092 store_in_alist (alistptr, Qdisplay,
3093 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3095 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3096 tem = Qnil;
3097 else
3098 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3099 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3100 store_in_alist (alistptr, Qparent_id, tem);
3101 store_in_alist (alistptr, Qtool_bar_position, f->tool_bar_position);
3105 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3106 the previous value of that parameter, NEW_VALUE is the new value. */
3108 void
3109 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3111 if (NILP (new_value))
3112 f->want_fullscreen = FULLSCREEN_NONE;
3113 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3114 f->want_fullscreen = FULLSCREEN_BOTH;
3115 else if (EQ (new_value, Qfullwidth))
3116 f->want_fullscreen = FULLSCREEN_WIDTH;
3117 else if (EQ (new_value, Qfullheight))
3118 f->want_fullscreen = FULLSCREEN_HEIGHT;
3119 else if (EQ (new_value, Qmaximized))
3120 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3122 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3123 FRAME_TERMINAL (f)->fullscreen_hook (f);
3127 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3128 the previous value of that parameter, NEW_VALUE is the new value. */
3130 void
3131 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3133 if (NILP (new_value))
3134 f->extra_line_spacing = 0;
3135 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3136 f->extra_line_spacing = XFASTINT (new_value);
3137 else
3138 signal_error ("Invalid line-spacing", new_value);
3139 if (FRAME_VISIBLE_P (f))
3140 redraw_frame (f);
3144 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3145 the previous value of that parameter, NEW_VALUE is the new value. */
3147 void
3148 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3150 Lisp_Object bgcolor;
3152 if (NILP (new_value))
3153 f->gamma = 0;
3154 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3155 /* The value 0.4545 is the normal viewing gamma. */
3156 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3157 else
3158 signal_error ("Invalid screen-gamma", new_value);
3160 /* Apply the new gamma value to the frame background. */
3161 bgcolor = Fassq (Qbackground_color, f->param_alist);
3162 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3164 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3165 if (NATNUMP (parm_index)
3166 && (XFASTINT (parm_index)
3167 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3168 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3169 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3170 (f, bgcolor, Qnil);
3173 Fclear_face_cache (Qnil);
3177 void
3178 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3180 Lisp_Object font_object;
3181 int fontset = -1;
3182 #ifdef HAVE_X_WINDOWS
3183 Lisp_Object font_param = arg;
3184 #endif
3186 /* Set the frame parameter back to the old value because we may
3187 fail to use ARG as the new parameter value. */
3188 store_frame_param (f, Qfont, oldval);
3190 /* ARG is a fontset name, a font name, a cons of fontset name and a
3191 font object, or a font object. In the last case, this function
3192 never fail. */
3193 if (STRINGP (arg))
3195 fontset = fs_query_fontset (arg, 0);
3196 if (fontset < 0)
3198 font_object = font_open_by_name (f, arg);
3199 if (NILP (font_object))
3200 error ("Font `%s' is not defined", SSDATA (arg));
3201 arg = AREF (font_object, FONT_NAME_INDEX);
3203 else if (fontset > 0)
3205 font_object = font_open_by_name (f, fontset_ascii (fontset));
3206 if (NILP (font_object))
3207 error ("Font `%s' is not defined", SDATA (arg));
3208 arg = AREF (font_object, FONT_NAME_INDEX);
3210 else
3211 error ("The default fontset can't be used for a frame font");
3213 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3215 /* This is the case that the ASCII font of F's fontset XCAR
3216 (arg) is changed to the font XCDR (arg) by
3217 `set-fontset-font'. */
3218 fontset = fs_query_fontset (XCAR (arg), 0);
3219 if (fontset < 0)
3220 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3221 font_object = XCDR (arg);
3222 arg = AREF (font_object, FONT_NAME_INDEX);
3223 #ifdef HAVE_X_WINDOWS
3224 font_param = Ffont_get (font_object, QCname);
3225 #endif
3227 else if (FONT_OBJECT_P (arg))
3229 font_object = arg;
3230 #ifdef HAVE_X_WINDOWS
3231 font_param = Ffont_get (font_object, QCname);
3232 #endif
3233 /* This is to store the XLFD font name in the frame parameter for
3234 backward compatibility. We should store the font-object
3235 itself in the future. */
3236 arg = AREF (font_object, FONT_NAME_INDEX);
3237 fontset = FRAME_FONTSET (f);
3238 /* Check if we can use the current fontset. If not, set FONTSET
3239 to -1 to generate a new fontset from FONT-OBJECT. */
3240 if (fontset >= 0)
3242 Lisp_Object ascii_font = fontset_ascii (fontset);
3243 Lisp_Object spec = font_spec_from_name (ascii_font);
3245 if (! font_match_p (spec, font_object))
3246 fontset = -1;
3249 else
3250 signal_error ("Invalid font", arg);
3252 if (! NILP (Fequal (font_object, oldval)))
3253 return;
3255 x_new_font (f, font_object, fontset);
3256 store_frame_param (f, Qfont, arg);
3257 #ifdef HAVE_X_WINDOWS
3258 store_frame_param (f, Qfont_param, font_param);
3259 #endif
3260 /* Recalculate toolbar height. */
3261 f->n_tool_bar_rows = 0;
3262 /* Ensure we redraw it. */
3263 clear_current_matrices (f);
3265 recompute_basic_faces (f);
3267 do_pending_window_change (0);
3269 /* We used to call face-set-after-frame-default here, but it leads to
3270 recursive calls (since that function can set the `default' face's
3271 font which in turns changes the frame's `font' parameter).
3272 Also I don't know what this call is meant to do, but it seems the
3273 wrong way to do it anyway (it does a lot more work than what seems
3274 reasonable in response to a change to `font'). */
3278 void
3279 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3281 if (! NILP (new_value)
3282 && !CONSP (new_value))
3284 char *p0, *p1;
3286 CHECK_STRING (new_value);
3287 p0 = p1 = SSDATA (new_value);
3288 new_value = Qnil;
3289 while (*p0)
3291 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3292 if (p0 < p1)
3293 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3294 new_value);
3295 if (*p1)
3297 int c;
3299 while ((c = *++p1) && c_isspace (c));
3301 p0 = p1;
3303 new_value = Fnreverse (new_value);
3306 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3307 return;
3309 if (FRAME_FONT (f))
3310 free_all_realized_faces (Qnil);
3312 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3313 if (NILP (new_value))
3315 if (NILP (old_value))
3316 error ("No font backend available");
3317 font_update_drivers (f, old_value);
3318 error ("None of specified font backends are available");
3320 store_frame_param (f, Qfont_backend, new_value);
3322 if (FRAME_FONT (f))
3324 Lisp_Object frame;
3326 XSETFRAME (frame, f);
3327 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3328 ++face_change_count;
3329 ++windows_or_buffers_changed;
3334 void
3335 x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3337 compute_fringe_widths (f, 1);
3338 #ifdef HAVE_X_WINDOWS
3339 /* Must adjust this so window managers report correct number of columns. */
3340 if (FRAME_X_WINDOW (f) != 0)
3341 x_wm_set_size_hint (f, 0, 0);
3342 #endif
3345 void
3346 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3348 CHECK_TYPE_RANGED_INTEGER (int, arg);
3350 if (XINT (arg) == f->border_width)
3351 return;
3353 if (FRAME_X_WINDOW (f) != 0)
3354 error ("Cannot change the border width of a frame");
3356 f->border_width = XINT (arg);
3359 void
3360 x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3362 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3364 CHECK_TYPE_RANGED_INTEGER (int, arg);
3365 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3366 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3367 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3369 #ifdef USE_X_TOOLKIT
3370 if (FRAME_X_OUTPUT (f)->edit_widget)
3371 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3372 #endif
3374 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3375 return;
3377 if (FRAME_X_WINDOW (f) != 0)
3379 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3380 SET_FRAME_GARBAGED (f);
3381 do_pending_window_change (0);
3383 else
3384 SET_FRAME_GARBAGED (f);
3387 void
3388 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3390 Lisp_Object frame;
3391 XSETFRAME (frame, f);
3393 if (NILP (value))
3394 Fmake_frame_invisible (frame, Qt);
3395 else if (EQ (value, Qicon))
3396 Ficonify_frame (frame);
3397 else
3398 Fmake_frame_visible (frame);
3401 void
3402 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3404 f->auto_raise = !EQ (Qnil, arg);
3407 void
3408 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3410 f->auto_lower = !EQ (Qnil, arg);
3413 void
3414 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3416 f->no_split = !NILP (arg);
3419 void
3420 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3422 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3423 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3424 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3425 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3427 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3428 = (NILP (arg)
3429 ? vertical_scroll_bar_none
3430 : EQ (Qleft, arg)
3431 ? vertical_scroll_bar_left
3432 : EQ (Qright, arg)
3433 ? vertical_scroll_bar_right
3434 : EQ (Qleft, Vdefault_frame_scroll_bars)
3435 ? vertical_scroll_bar_left
3436 : EQ (Qright, Vdefault_frame_scroll_bars)
3437 ? vertical_scroll_bar_right
3438 : vertical_scroll_bar_none);
3440 /* We set this parameter before creating the X window for the
3441 frame, so we can get the geometry right from the start.
3442 However, if the window hasn't been created yet, we shouldn't
3443 call x_set_window_size. */
3444 if (FRAME_X_WINDOW (f))
3445 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3446 do_pending_window_change (0);
3450 void
3451 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3453 int wid = FRAME_COLUMN_WIDTH (f);
3455 if (NILP (arg))
3457 x_set_scroll_bar_default_width (f);
3459 if (FRAME_X_WINDOW (f))
3460 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3461 do_pending_window_change (0);
3463 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3464 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3466 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3467 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3469 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3470 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3471 if (FRAME_X_WINDOW (f))
3472 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3473 do_pending_window_change (0);
3476 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3477 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3478 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3483 /* Return non-nil if frame F wants a bitmap icon. */
3485 Lisp_Object
3486 x_icon_type (FRAME_PTR f)
3488 Lisp_Object tem;
3490 tem = assq_no_quit (Qicon_type, f->param_alist);
3491 if (CONSP (tem))
3492 return XCDR (tem);
3493 else
3494 return Qnil;
3497 void
3498 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3500 double alpha = 1.0;
3501 double newval[2];
3502 int i;
3503 Lisp_Object item;
3505 for (i = 0; i < 2; i++)
3507 newval[i] = 1.0;
3508 if (CONSP (arg))
3510 item = CAR (arg);
3511 arg = CDR (arg);
3513 else
3514 item = arg;
3516 if (NILP (item))
3517 alpha = - 1.0;
3518 else if (FLOATP (item))
3520 alpha = XFLOAT_DATA (item);
3521 if (alpha < 0.0 || 1.0 < alpha)
3522 args_out_of_range (make_float (0.0), make_float (1.0));
3524 else if (INTEGERP (item))
3526 EMACS_INT ialpha = XINT (item);
3527 if (ialpha < 0 || 100 < ialpha)
3528 args_out_of_range (make_number (0), make_number (100));
3529 else
3530 alpha = ialpha / 100.0;
3532 else
3533 wrong_type_argument (Qnumberp, item);
3534 newval[i] = alpha;
3537 for (i = 0; i < 2; i++)
3538 f->alpha[i] = newval[i];
3540 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3541 BLOCK_INPUT;
3542 x_set_frame_alpha (f);
3543 UNBLOCK_INPUT;
3544 #endif
3546 return;
3550 /* Subroutines of creating an X frame. */
3552 /* Make sure that Vx_resource_name is set to a reasonable value.
3553 Fix it up, or set it to `emacs' if it is too hopeless. */
3555 void
3556 validate_x_resource_name (void)
3558 ptrdiff_t len = 0;
3559 /* Number of valid characters in the resource name. */
3560 ptrdiff_t good_count = 0;
3561 /* Number of invalid characters in the resource name. */
3562 ptrdiff_t bad_count = 0;
3563 Lisp_Object new;
3564 ptrdiff_t i;
3566 if (!STRINGP (Vx_resource_class))
3567 Vx_resource_class = build_string (EMACS_CLASS);
3569 if (STRINGP (Vx_resource_name))
3571 unsigned char *p = SDATA (Vx_resource_name);
3573 len = SBYTES (Vx_resource_name);
3575 /* Only letters, digits, - and _ are valid in resource names.
3576 Count the valid characters and count the invalid ones. */
3577 for (i = 0; i < len; i++)
3579 int c = p[i];
3580 if (! ((c >= 'a' && c <= 'z')
3581 || (c >= 'A' && c <= 'Z')
3582 || (c >= '0' && c <= '9')
3583 || c == '-' || c == '_'))
3584 bad_count++;
3585 else
3586 good_count++;
3589 else
3590 /* Not a string => completely invalid. */
3591 bad_count = 5, good_count = 0;
3593 /* If name is valid already, return. */
3594 if (bad_count == 0)
3595 return;
3597 /* If name is entirely invalid, or nearly so, or is so implausibly
3598 large that alloca might not work, use `emacs'. */
3599 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3601 Vx_resource_name = build_string ("emacs");
3602 return;
3605 /* Name is partly valid. Copy it and replace the invalid characters
3606 with underscores. */
3608 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3610 for (i = 0; i < len; i++)
3612 int c = SREF (new, i);
3613 if (! ((c >= 'a' && c <= 'z')
3614 || (c >= 'A' && c <= 'Z')
3615 || (c >= '0' && c <= '9')
3616 || c == '-' || c == '_'))
3617 SSET (new, i, '_');
3622 extern char *x_get_string_resource (XrmDatabase, const char *, const char *);
3623 extern Display_Info *check_x_display_info (Lisp_Object);
3626 /* Get specified attribute from resource database RDB.
3627 See Fx_get_resource below for other parameters. */
3629 static Lisp_Object
3630 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3632 register char *value;
3633 char *name_key;
3634 char *class_key;
3636 CHECK_STRING (attribute);
3637 CHECK_STRING (class);
3639 if (!NILP (component))
3640 CHECK_STRING (component);
3641 if (!NILP (subclass))
3642 CHECK_STRING (subclass);
3643 if (NILP (component) != NILP (subclass))
3644 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3646 validate_x_resource_name ();
3648 /* Allocate space for the components, the dots which separate them,
3649 and the final '\0'. Make them big enough for the worst case. */
3650 name_key = alloca (SBYTES (Vx_resource_name)
3651 + (STRINGP (component)
3652 ? SBYTES (component) : 0)
3653 + SBYTES (attribute)
3654 + 3);
3656 class_key = alloca (SBYTES (Vx_resource_class)
3657 + SBYTES (class)
3658 + (STRINGP (subclass)
3659 ? SBYTES (subclass) : 0)
3660 + 3);
3662 /* Start with emacs.FRAMENAME for the name (the specific one)
3663 and with `Emacs' for the class key (the general one). */
3664 strcpy (name_key, SSDATA (Vx_resource_name));
3665 strcpy (class_key, SSDATA (Vx_resource_class));
3667 strcat (class_key, ".");
3668 strcat (class_key, SSDATA (class));
3670 if (!NILP (component))
3672 strcat (class_key, ".");
3673 strcat (class_key, SSDATA (subclass));
3675 strcat (name_key, ".");
3676 strcat (name_key, SSDATA (component));
3679 strcat (name_key, ".");
3680 strcat (name_key, SSDATA (attribute));
3682 value = x_get_string_resource (rdb, name_key, class_key);
3684 if (value != (char *) 0 && *value)
3685 return build_string (value);
3686 else
3687 return Qnil;
3691 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3692 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3693 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3694 class, where INSTANCE is the name under which Emacs was invoked, or
3695 the name specified by the `-name' or `-rn' command-line arguments.
3697 The optional arguments COMPONENT and SUBCLASS add to the key and the
3698 class, respectively. You must specify both of them or neither.
3699 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3700 and the class is `Emacs.CLASS.SUBCLASS'. */)
3701 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3703 #ifdef HAVE_X_WINDOWS
3704 check_x ();
3705 #endif
3707 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3708 attribute, class, component, subclass);
3711 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3713 Lisp_Object
3714 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3716 return xrdb_get_resource (dpyinfo->xrdb,
3717 attribute, class, component, subclass);
3720 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3721 /* Used when C code wants a resource value. */
3722 /* Called from oldXMenu/Create.c. */
3723 char *
3724 x_get_resource_string (const char *attribute, const char *class)
3726 char *result;
3727 struct frame *sf = SELECTED_FRAME ();
3728 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
3729 USE_SAFE_ALLOCA;
3731 /* Allocate space for the components, the dots which separate them,
3732 and the final '\0'. */
3733 char *name_key = SAFE_ALLOCA (invocation_namelen + strlen (attribute) + 2);
3734 char *class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2);
3736 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
3737 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3739 result = x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3740 name_key, class_key);
3741 SAFE_FREE ();
3742 return result;
3744 #endif
3746 /* Return the value of parameter PARAM.
3748 First search ALIST, then Vdefault_frame_alist, then the X defaults
3749 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3751 Convert the resource to the type specified by desired_type.
3753 If no default is specified, return Qunbound. If you call
3754 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3755 and don't let it get stored in any Lisp-visible variables! */
3757 Lisp_Object
3758 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
3759 const char *attribute, const char *class, enum resource_types type)
3761 register Lisp_Object tem;
3763 tem = Fassq (param, alist);
3765 if (!NILP (tem))
3767 /* If we find this parm in ALIST, clear it out
3768 so that it won't be "left over" at the end. */
3769 Lisp_Object tail;
3770 XSETCAR (tem, Qnil);
3771 /* In case the parameter appears more than once in the alist,
3772 clear it out. */
3773 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3774 if (CONSP (XCAR (tail))
3775 && EQ (XCAR (XCAR (tail)), param))
3776 XSETCAR (XCAR (tail), Qnil);
3778 else
3779 tem = Fassq (param, Vdefault_frame_alist);
3781 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3782 look in the X resources. */
3783 if (EQ (tem, Qnil))
3785 if (attribute && dpyinfo)
3787 tem = display_x_get_resource (dpyinfo,
3788 build_string (attribute),
3789 build_string (class),
3790 Qnil, Qnil);
3792 if (NILP (tem))
3793 return Qunbound;
3795 switch (type)
3797 case RES_TYPE_NUMBER:
3798 return make_number (atoi (SSDATA (tem)));
3800 case RES_TYPE_BOOLEAN_NUMBER:
3801 if (!strcmp (SSDATA (tem), "on")
3802 || !strcmp (SSDATA (tem), "true"))
3803 return make_number (1);
3804 return make_number (atoi (SSDATA (tem)));
3805 break;
3807 case RES_TYPE_FLOAT:
3808 return make_float (atof (SSDATA (tem)));
3810 case RES_TYPE_BOOLEAN:
3811 tem = Fdowncase (tem);
3812 if (!strcmp (SSDATA (tem), "on")
3813 #ifdef HAVE_NS
3814 || !strcmp (SSDATA (tem), "yes")
3815 #endif
3816 || !strcmp (SSDATA (tem), "true"))
3817 return Qt;
3818 else
3819 return Qnil;
3821 case RES_TYPE_STRING:
3822 return tem;
3824 case RES_TYPE_SYMBOL:
3825 /* As a special case, we map the values `true' and `on'
3826 to Qt, and `false' and `off' to Qnil. */
3828 Lisp_Object lower;
3829 lower = Fdowncase (tem);
3830 if (!strcmp (SSDATA (lower), "on")
3831 #ifdef HAVE_NS
3832 || !strcmp (SSDATA (lower), "yes")
3833 #endif
3834 || !strcmp (SSDATA (lower), "true"))
3835 return Qt;
3836 else if (!strcmp (SSDATA (lower), "off")
3837 #ifdef HAVE_NS
3838 || !strcmp (SSDATA (lower), "no")
3839 #endif
3840 || !strcmp (SSDATA (lower), "false"))
3841 return Qnil;
3842 else
3843 return Fintern (tem, Qnil);
3846 default:
3847 abort ();
3850 else
3851 return Qunbound;
3853 return Fcdr (tem);
3856 static Lisp_Object
3857 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
3858 const char *attribute, const char *class,
3859 enum resource_types type)
3861 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3862 alist, param, attribute, class, type);
3865 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3867 Lisp_Object
3868 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
3869 Lisp_Object param,
3870 const char *attribute, const char *class,
3871 enum resource_types type)
3873 Lisp_Object value;
3875 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3876 attribute, class, type);
3877 if (! NILP (value) && ! EQ (value, Qunbound))
3878 store_frame_param (f, param, value);
3880 return value;
3884 /* Record in frame F the specified or default value according to ALIST
3885 of the parameter named PROP (a Lisp symbol).
3886 If no value is specified for PROP, look for an X default for XPROP
3887 on the frame named NAME.
3888 If that is not found either, use the value DEFLT. */
3890 Lisp_Object
3891 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
3892 Lisp_Object deflt, const char *xprop, const char *xclass,
3893 enum resource_types type)
3895 Lisp_Object tem;
3897 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3898 if (EQ (tem, Qunbound))
3899 tem = deflt;
3900 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3901 return tem;
3907 /* NS used to define x-parse-geometry in ns-win.el, but that confused
3908 make-docfile: the documentation string in ns-win.el was used for
3909 x-parse-geometry even in non-NS builds.
3911 With two definitions of x-parse-geometry in this file, various
3912 things still get confused (eg M-x apropos documentation), so that
3913 it is best if the two definitions just share the same doc-string.
3915 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3916 doc: /* Parse a display geometry string STRING.
3917 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3918 The properties returned may include `top', `left', `height', and `width'.
3919 For X, the value of `left' or `top' may be an integer,
3920 or a list (+ N) meaning N pixels relative to top/left corner,
3921 or a list (- N) meaning -N pixels relative to bottom/right corner.
3922 On Nextstep, this just calls `ns-parse-geometry'. */)
3923 (Lisp_Object string)
3925 #ifdef HAVE_NS
3926 return call1 (Qns_parse_geometry, string);
3927 #else
3928 int geometry, x, y;
3929 unsigned int width, height;
3930 Lisp_Object result;
3932 CHECK_STRING (string);
3934 geometry = XParseGeometry (SSDATA (string),
3935 &x, &y, &width, &height);
3936 result = Qnil;
3937 if (geometry & XValue)
3939 Lisp_Object element;
3941 if (x >= 0 && (geometry & XNegative))
3942 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3943 else if (x < 0 && ! (geometry & XNegative))
3944 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3945 else
3946 element = Fcons (Qleft, make_number (x));
3947 result = Fcons (element, result);
3950 if (geometry & YValue)
3952 Lisp_Object element;
3954 if (y >= 0 && (geometry & YNegative))
3955 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3956 else if (y < 0 && ! (geometry & YNegative))
3957 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3958 else
3959 element = Fcons (Qtop, make_number (y));
3960 result = Fcons (element, result);
3963 if (geometry & WidthValue)
3964 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3965 if (geometry & HeightValue)
3966 result = Fcons (Fcons (Qheight, make_number (height)), result);
3968 return result;
3969 #endif /* HAVE_NS */
3973 /* Calculate the desired size and position of frame F.
3974 Return the flags saying which aspects were specified.
3976 Also set the win_gravity and size_hint_flags of F.
3978 Adjust height for toolbar if TOOLBAR_P is 1.
3980 This function does not make the coordinates positive. */
3982 #define DEFAULT_ROWS 35
3983 #define DEFAULT_COLS 80
3986 x_figure_window_size (struct frame *f, Lisp_Object parms, int toolbar_p)
3988 register Lisp_Object tem0, tem1, tem2;
3989 long window_prompting = 0;
3990 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3992 /* Default values if we fall through.
3993 Actually, if that happens we should get
3994 window manager prompting. */
3995 SET_FRAME_COLS (f, DEFAULT_COLS);
3996 FRAME_LINES (f) = DEFAULT_ROWS;
3997 /* Window managers expect that if program-specified
3998 positions are not (0,0), they're intentional, not defaults. */
3999 f->top_pos = 0;
4000 f->left_pos = 0;
4002 /* Ensure that old new_text_cols and new_text_lines will not override the
4003 values set here. */
4004 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4005 f->new_text_cols = f->new_text_lines = 0;
4007 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4008 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4009 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4010 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4012 if (!EQ (tem0, Qunbound))
4014 CHECK_NUMBER (tem0);
4015 if (! (0 <= XINT (tem0) && XINT (tem0) <= INT_MAX))
4016 xsignal1 (Qargs_out_of_range, tem0);
4017 FRAME_LINES (f) = XINT (tem0);
4019 if (!EQ (tem1, Qunbound))
4021 CHECK_NUMBER (tem1);
4022 if (! (0 <= XINT (tem1) && XINT (tem1) <= INT_MAX))
4023 xsignal1 (Qargs_out_of_range, tem1);
4024 SET_FRAME_COLS (f, XINT (tem1));
4026 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4027 window_prompting |= USSize;
4028 else
4029 window_prompting |= PSize;
4032 f->scroll_bar_actual_width
4033 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4035 /* This used to be done _before_ calling x_figure_window_size, but
4036 since the height is reset here, this was really a no-op. I
4037 assume that moving it here does what Gerd intended (although he
4038 no longer can remember what that was... ++KFS, 2003-03-25. */
4040 /* Add the tool-bar height to the initial frame height so that the
4041 user gets a text display area of the size he specified with -g or
4042 via .Xdefaults. Later changes of the tool-bar height don't
4043 change the frame size. This is done so that users can create
4044 tall Emacs frames without having to guess how tall the tool-bar
4045 will get. */
4046 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4048 int margin, relief, bar_height;
4050 relief = (tool_bar_button_relief >= 0
4051 ? tool_bar_button_relief
4052 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4054 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4055 margin = XFASTINT (Vtool_bar_button_margin);
4056 else if (CONSP (Vtool_bar_button_margin)
4057 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4058 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4059 else
4060 margin = 0;
4062 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4063 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4066 compute_fringe_widths (f, 0);
4068 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4069 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4071 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4072 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4073 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4074 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4076 if (EQ (tem0, Qminus))
4078 f->top_pos = 0;
4079 window_prompting |= YNegative;
4081 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4082 && CONSP (XCDR (tem0))
4083 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem0)), INT_MAX))
4085 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4086 window_prompting |= YNegative;
4088 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4089 && CONSP (XCDR (tem0))
4090 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0))))
4092 f->top_pos = XINT (XCAR (XCDR (tem0)));
4094 else if (EQ (tem0, Qunbound))
4095 f->top_pos = 0;
4096 else
4098 CHECK_TYPE_RANGED_INTEGER (int, tem0);
4099 f->top_pos = XINT (tem0);
4100 if (f->top_pos < 0)
4101 window_prompting |= YNegative;
4104 if (EQ (tem1, Qminus))
4106 f->left_pos = 0;
4107 window_prompting |= XNegative;
4109 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4110 && CONSP (XCDR (tem1))
4111 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem1)), INT_MAX))
4113 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4114 window_prompting |= XNegative;
4116 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4117 && CONSP (XCDR (tem1))
4118 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1))))
4120 f->left_pos = XINT (XCAR (XCDR (tem1)));
4122 else if (EQ (tem1, Qunbound))
4123 f->left_pos = 0;
4124 else
4126 CHECK_TYPE_RANGED_INTEGER (int, tem1);
4127 f->left_pos = XINT (tem1);
4128 if (f->left_pos < 0)
4129 window_prompting |= XNegative;
4132 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4133 window_prompting |= USPosition;
4134 else
4135 window_prompting |= PPosition;
4138 if (window_prompting & XNegative)
4140 if (window_prompting & YNegative)
4141 f->win_gravity = SouthEastGravity;
4142 else
4143 f->win_gravity = NorthEastGravity;
4145 else
4147 if (window_prompting & YNegative)
4148 f->win_gravity = SouthWestGravity;
4149 else
4150 f->win_gravity = NorthWestGravity;
4153 f->size_hint_flags = window_prompting;
4155 return window_prompting;
4160 #endif /* HAVE_WINDOW_SYSTEM */
4162 void
4163 frame_make_pointer_invisible (void)
4165 if (! NILP (Vmake_pointer_invisible))
4167 struct frame *f;
4168 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4169 return;
4171 f = SELECTED_FRAME ();
4172 if (f && !f->pointer_invisible
4173 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4175 f->mouse_moved = 0;
4176 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4177 f->pointer_invisible = 1;
4182 void
4183 frame_make_pointer_visible (void)
4185 /* We don't check Vmake_pointer_invisible here in case the
4186 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4187 struct frame *f;
4189 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4190 return;
4192 f = SELECTED_FRAME ();
4193 if (f && f->pointer_invisible && f->mouse_moved
4194 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4196 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4197 f->pointer_invisible = 0;
4201 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4202 Sframe_pointer_visible_p, 0, 1, 0,
4203 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4204 Otherwise it returns nil. FRAME omitted or nil means the
4205 selected frame. This is useful when `make-pointer-invisible' is set. */)
4206 (Lisp_Object frame)
4208 if (NILP (frame))
4209 frame = selected_frame;
4211 CHECK_FRAME (frame);
4213 return (XFRAME (frame)->pointer_invisible ? Qnil : Qt);
4217 /***********************************************************************
4218 Initialization
4219 ***********************************************************************/
4221 void
4222 syms_of_frame (void)
4224 DEFSYM (Qframep, "framep");
4225 DEFSYM (Qframe_live_p, "frame-live-p");
4226 DEFSYM (Qexplicit_name, "explicit-name");
4227 DEFSYM (Qheight, "height");
4228 DEFSYM (Qicon, "icon");
4229 DEFSYM (Qminibuffer, "minibuffer");
4230 DEFSYM (Qmodeline, "modeline");
4231 DEFSYM (Qonly, "only");
4232 DEFSYM (Qnone, "none");
4233 DEFSYM (Qwidth, "width");
4234 DEFSYM (Qgeometry, "geometry");
4235 DEFSYM (Qicon_left, "icon-left");
4236 DEFSYM (Qicon_top, "icon-top");
4237 DEFSYM (Qtooltip, "tooltip");
4238 DEFSYM (Qleft, "left");
4239 DEFSYM (Qright, "right");
4240 DEFSYM (Quser_position, "user-position");
4241 DEFSYM (Quser_size, "user-size");
4242 DEFSYM (Qwindow_id, "window-id");
4243 #ifdef HAVE_X_WINDOWS
4244 DEFSYM (Qouter_window_id, "outer-window-id");
4245 #endif
4246 DEFSYM (Qparent_id, "parent-id");
4247 DEFSYM (Qx, "x");
4248 DEFSYM (Qw32, "w32");
4249 DEFSYM (Qpc, "pc");
4250 DEFSYM (Qmac, "mac");
4251 DEFSYM (Qns, "ns");
4252 DEFSYM (Qvisible, "visible");
4253 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4254 DEFSYM (Qbuffer_list, "buffer-list");
4255 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4256 DEFSYM (Qdisplay_type, "display-type");
4257 DEFSYM (Qbackground_mode, "background-mode");
4258 DEFSYM (Qnoelisp, "noelisp");
4259 DEFSYM (Qtty_color_mode, "tty-color-mode");
4260 DEFSYM (Qtty, "tty");
4261 DEFSYM (Qtty_type, "tty-type");
4263 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4265 DEFSYM (Qfullwidth, "fullwidth");
4266 DEFSYM (Qfullheight, "fullheight");
4267 DEFSYM (Qfullboth, "fullboth");
4268 DEFSYM (Qmaximized, "maximized");
4269 DEFSYM (Qx_resource_name, "x-resource-name");
4270 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4272 DEFSYM (Qterminal, "terminal");
4273 DEFSYM (Qterminal_live_p, "terminal-live-p");
4275 #ifdef HAVE_NS
4276 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4277 #endif
4280 int i;
4282 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4284 Lisp_Object v = intern_c_string (frame_parms[i].name);
4285 if (frame_parms[i].variable)
4287 *frame_parms[i].variable = v;
4288 staticpro (frame_parms[i].variable);
4290 Fput (v, Qx_frame_parameter, make_number (i));
4294 #ifdef HAVE_WINDOW_SYSTEM
4295 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4296 doc: /* The name Emacs uses to look up X resources.
4297 `x-get-resource' uses this as the first component of the instance name
4298 when requesting resource values.
4299 Emacs initially sets `x-resource-name' to the name under which Emacs
4300 was invoked, or to the value specified with the `-name' or `-rn'
4301 switches, if present.
4303 It may be useful to bind this variable locally around a call
4304 to `x-get-resource'. See also the variable `x-resource-class'. */);
4305 Vx_resource_name = Qnil;
4307 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4308 doc: /* The class Emacs uses to look up X resources.
4309 `x-get-resource' uses this as the first component of the instance class
4310 when requesting resource values.
4312 Emacs initially sets `x-resource-class' to "Emacs".
4314 Setting this variable permanently is not a reasonable thing to do,
4315 but binding this variable locally around a call to `x-get-resource'
4316 is a reasonable practice. See also the variable `x-resource-name'. */);
4317 Vx_resource_class = build_string (EMACS_CLASS);
4319 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4320 doc: /* The lower limit of the frame opacity (alpha transparency).
4321 The value should range from 0 (invisible) to 100 (completely opaque).
4322 You can also use a floating number between 0.0 and 1.0.
4323 The default is 20. */);
4324 Vframe_alpha_lower_limit = make_number (20);
4325 #endif
4327 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4328 doc: /* Alist of default values for frame creation.
4329 These may be set in your init file, like this:
4330 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4331 These override values given in window system configuration data,
4332 including X Windows' defaults database.
4333 For values specific to the first Emacs frame, see `initial-frame-alist'.
4334 For window-system specific values, see `window-system-default-frame-alist'.
4335 For values specific to the separate minibuffer frame, see
4336 `minibuffer-frame-alist'.
4337 The `menu-bar-lines' element of the list controls whether new frames
4338 have menu bars; `menu-bar-mode' works by altering this element.
4339 Setting this variable does not affect existing frames, only new ones. */);
4340 Vdefault_frame_alist = Qnil;
4342 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4343 doc: /* Default position of scroll bars on this window-system. */);
4344 #ifdef HAVE_WINDOW_SYSTEM
4345 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4346 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4347 default. */
4348 Vdefault_frame_scroll_bars = Qright;
4349 #else
4350 Vdefault_frame_scroll_bars = Qleft;
4351 #endif
4352 #else
4353 Vdefault_frame_scroll_bars = Qnil;
4354 #endif
4356 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4357 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4359 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4360 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4361 `mouse-position' calls this function, passing its usual return value as
4362 argument, and returns whatever this function returns.
4363 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4364 which need to do mouse handling at the Lisp level. */);
4365 Vmouse_position_function = Qnil;
4367 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4368 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4369 If the value is an integer, highlighting is only shown after moving the
4370 mouse, while keyboard input turns off the highlight even when the mouse
4371 is over the clickable text. However, the mouse shape still indicates
4372 when the mouse is over clickable text. */);
4373 Vmouse_highlight = Qt;
4375 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4376 doc: /* If non-nil, make pointer invisible while typing.
4377 The pointer becomes visible again when the mouse is moved. */);
4378 Vmake_pointer_invisible = Qt;
4380 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4381 doc: /* Functions run before deleting a frame.
4382 The functions are run with one arg, the frame to be deleted.
4383 See `delete-frame'.
4385 Note that functions in this list may be called just before the frame is
4386 actually deleted, or some time later (or even both when an earlier function
4387 in `delete-frame-functions' (indirectly) calls `delete-frame'
4388 recursively). */);
4389 Vdelete_frame_functions = Qnil;
4390 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4392 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4393 doc: /* Non-nil if Menu-Bar mode is enabled.
4394 See the command `menu-bar-mode' for a description of this minor mode.
4395 Setting this variable directly does not take effect;
4396 either customize it (see the info node `Easy Customization')
4397 or call the function `menu-bar-mode'. */);
4398 Vmenu_bar_mode = Qt;
4400 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4401 doc: /* Non-nil if Tool-Bar mode is enabled.
4402 See the command `tool-bar-mode' for a description of this minor mode.
4403 Setting this variable directly does not take effect;
4404 either customize it (see the info node `Easy Customization')
4405 or call the function `tool-bar-mode'. */);
4406 #ifdef HAVE_WINDOW_SYSTEM
4407 Vtool_bar_mode = Qt;
4408 #else
4409 Vtool_bar_mode = Qnil;
4410 #endif
4412 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4413 doc: /* Minibufferless frames use this frame's minibuffer.
4415 Emacs cannot create minibufferless frames unless this is set to an
4416 appropriate surrogate.
4418 Emacs consults this variable only when creating minibufferless
4419 frames; once the frame is created, it sticks with its assigned
4420 minibuffer, no matter what this variable is set to. This means that
4421 this variable doesn't necessarily say anything meaningful about the
4422 current set of frames, or where the minibuffer is currently being
4423 displayed.
4425 This variable is local to the current terminal and cannot be buffer-local. */);
4427 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4428 doc: /* Non-nil if window system changes focus when you move the mouse.
4429 You should set this variable to tell Emacs how your window manager
4430 handles focus, since there is no way in general for Emacs to find out
4431 automatically. See also `mouse-autoselect-window'. */);
4432 focus_follows_mouse = 0;
4434 staticpro (&Vframe_list);
4436 defsubr (&Sframep);
4437 defsubr (&Sframe_live_p);
4438 defsubr (&Swindow_system);
4439 defsubr (&Smake_terminal_frame);
4440 defsubr (&Shandle_switch_frame);
4441 defsubr (&Sselect_frame);
4442 defsubr (&Sselected_frame);
4443 defsubr (&Sframe_list);
4444 defsubr (&Snext_frame);
4445 defsubr (&Sprevious_frame);
4446 defsubr (&Sdelete_frame);
4447 defsubr (&Smouse_position);
4448 defsubr (&Smouse_pixel_position);
4449 defsubr (&Sset_mouse_position);
4450 defsubr (&Sset_mouse_pixel_position);
4451 #if 0
4452 defsubr (&Sframe_configuration);
4453 defsubr (&Srestore_frame_configuration);
4454 #endif
4455 defsubr (&Smake_frame_visible);
4456 defsubr (&Smake_frame_invisible);
4457 defsubr (&Siconify_frame);
4458 defsubr (&Sframe_visible_p);
4459 defsubr (&Svisible_frame_list);
4460 defsubr (&Sraise_frame);
4461 defsubr (&Slower_frame);
4462 defsubr (&Sredirect_frame_focus);
4463 defsubr (&Sframe_focus);
4464 defsubr (&Sframe_parameters);
4465 defsubr (&Sframe_parameter);
4466 defsubr (&Smodify_frame_parameters);
4467 defsubr (&Sframe_char_height);
4468 defsubr (&Sframe_char_width);
4469 defsubr (&Sframe_pixel_height);
4470 defsubr (&Sframe_pixel_width);
4471 defsubr (&Stool_bar_pixel_width);
4472 defsubr (&Sset_frame_height);
4473 defsubr (&Sset_frame_width);
4474 defsubr (&Sset_frame_size);
4475 defsubr (&Sset_frame_position);
4476 defsubr (&Sframe_pointer_visible_p);
4478 #ifdef HAVE_WINDOW_SYSTEM
4479 defsubr (&Sx_get_resource);
4480 defsubr (&Sx_parse_geometry);
4481 #endif