Sync with Tramp 2.2.6.
[emacs/old-mirror.git] / src / frame.c
blob9b12842bf8943b1e9214f24c1b16fadf7cd1dc0a
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"
34 #ifdef HAVE_WINDOW_SYSTEM
35 #include TERM_HEADER
36 #endif /* HAVE_WINDOW_SYSTEM */
38 #include "buffer.h"
39 /* These help us bind and responding to switch-frame events. */
40 #include "commands.h"
41 #include "keyboard.h"
42 #include "frame.h"
43 #include "blockinput.h"
44 #include "termchar.h"
45 #include "termhooks.h"
46 #include "dispextern.h"
47 #include "window.h"
48 #include "font.h"
49 #ifdef HAVE_WINDOW_SYSTEM
50 #include "fontset.h"
51 #endif
52 #ifdef MSDOS
53 #include "msdos.h"
54 #include "dosfns.h"
55 #endif
57 #ifdef HAVE_NS
58 Lisp_Object Qns_parse_geometry;
59 #endif
61 Lisp_Object Qframep, Qframe_live_p;
62 Lisp_Object Qicon, Qmodeline;
63 Lisp_Object Qonly, Qnone;
64 Lisp_Object Qx, Qw32, Qmac, Qpc, Qns;
65 Lisp_Object Qvisible;
66 Lisp_Object Qdisplay_type;
67 static Lisp_Object Qbackground_mode;
68 Lisp_Object Qnoelisp;
70 static Lisp_Object Qx_frame_parameter;
71 Lisp_Object Qx_resource_name;
72 Lisp_Object Qterminal;
73 Lisp_Object Qterminal_live_p;
75 /* Frame parameters (set or reported). */
77 Lisp_Object Qauto_raise, Qauto_lower;
78 Lisp_Object Qborder_color, Qborder_width;
79 Lisp_Object Qcursor_color, Qcursor_type;
80 static Lisp_Object Qgeometry; /* Not used */
81 Lisp_Object Qheight, Qwidth;
82 Lisp_Object Qleft, Qright;
83 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
84 Lisp_Object Qtooltip;
85 Lisp_Object Qinternal_border_width;
86 Lisp_Object Qmouse_color;
87 Lisp_Object Qminibuffer;
88 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
89 Lisp_Object Qvisibility;
90 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
91 Lisp_Object Qscreen_gamma;
92 Lisp_Object Qline_spacing;
93 static Lisp_Object Quser_position, Quser_size;
94 Lisp_Object Qwait_for_wm;
95 static Lisp_Object Qwindow_id;
96 #ifdef HAVE_X_WINDOWS
97 static Lisp_Object Qouter_window_id;
98 #endif
99 Lisp_Object Qparent_id;
100 Lisp_Object Qtitle, Qname;
101 static Lisp_Object Qexplicit_name;
102 Lisp_Object Qunsplittable;
103 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines, Qtool_bar_position;
104 Lisp_Object Qleft_fringe, Qright_fringe;
105 Lisp_Object Qbuffer_predicate;
106 static Lisp_Object Qbuffer_list, Qburied_buffer_list;
107 Lisp_Object Qtty_color_mode;
108 Lisp_Object Qtty, Qtty_type;
110 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth, Qmaximized;
111 Lisp_Object Qsticky;
112 Lisp_Object Qfont_backend;
113 Lisp_Object Qalpha;
115 Lisp_Object Qface_set_after_frame_default;
117 static Lisp_Object Qdelete_frame_functions;
119 #ifdef HAVE_WINDOW_SYSTEM
120 static void x_report_frame_params (struct frame *, Lisp_Object *);
121 #endif
123 /* These setters are used only in this file, so they can be private. */
124 static inline void
125 fset_buffer_predicate (struct frame *f, Lisp_Object val)
127 f->buffer_predicate = val;
129 static inline void
130 fset_minibuffer_window (struct frame *f, Lisp_Object val)
132 f->minibuffer_window = val;
136 static void
137 set_menu_bar_lines_1 (Lisp_Object window, int n)
139 struct window *w = XWINDOW (window);
141 w->last_modified = 0;
142 wset_top_line (w, make_number (XFASTINT (w->top_line) + n));
143 wset_total_lines (w, make_number (XFASTINT (w->total_lines) - n));
145 /* Handle just the top child in a vertical split. */
146 if (!NILP (w->vchild))
147 set_menu_bar_lines_1 (w->vchild, n);
149 /* Adjust all children in a horizontal split. */
150 for (window = w->hchild; !NILP (window); window = w->next)
152 w = XWINDOW (window);
153 set_menu_bar_lines_1 (window, n);
157 void
158 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
160 int nlines;
161 int olines = FRAME_MENU_BAR_LINES (f);
163 /* Right now, menu bars don't work properly in minibuf-only frames;
164 most of the commands try to apply themselves to the minibuffer
165 frame itself, and get an error because you can't switch buffers
166 in or split the minibuffer window. */
167 if (FRAME_MINIBUF_ONLY_P (f))
168 return;
170 if (TYPE_RANGED_INTEGERP (int, value))
171 nlines = XINT (value);
172 else
173 nlines = 0;
175 if (nlines != olines)
177 windows_or_buffers_changed++;
178 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
179 FRAME_MENU_BAR_LINES (f) = nlines;
180 set_menu_bar_lines_1 (f->root_window, nlines - olines);
181 adjust_glyphs (f);
185 Lisp_Object Vframe_list;
188 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
189 doc: /* Return non-nil if OBJECT is a frame.
190 Value is:
191 t for a termcap frame (a character-only terminal),
192 'x' for an Emacs frame that is really an X window,
193 'w32' for an Emacs frame that is a window on MS-Windows display,
194 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
195 'pc' for a direct-write MS-DOS frame.
196 See also `frame-live-p'. */)
197 (Lisp_Object object)
199 if (!FRAMEP (object))
200 return Qnil;
201 switch (XFRAME (object)->output_method)
203 case output_initial: /* The initial frame is like a termcap frame. */
204 case output_termcap:
205 return Qt;
206 case output_x_window:
207 return Qx;
208 case output_w32:
209 return Qw32;
210 case output_msdos_raw:
211 return Qpc;
212 case output_mac:
213 return Qmac;
214 case output_ns:
215 return Qns;
216 default:
217 emacs_abort ();
221 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
222 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
223 Value is nil if OBJECT is not a live frame. If object is a live
224 frame, the return value indicates what sort of terminal device it is
225 displayed on. See the documentation of `framep' for possible
226 return values. */)
227 (Lisp_Object object)
229 return ((FRAMEP (object)
230 && FRAME_LIVE_P (XFRAME (object)))
231 ? Fframep (object)
232 : Qnil);
235 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
236 doc: /* The name of the window system that FRAME is displaying through.
237 The value is a symbol:
238 nil for a termcap frame (a character-only terminal),
239 'x' for an Emacs frame that is really an X window,
240 'w32' for an Emacs frame that is a window on MS-Windows display,
241 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
242 'pc' for a direct-write MS-DOS frame.
244 FRAME defaults to the currently selected frame.
246 Use of this function as a predicate is deprecated. Instead,
247 use `display-graphic-p' or any of the other `display-*-p'
248 predicates which report frame's specific UI-related capabilities. */)
249 (Lisp_Object frame)
251 Lisp_Object type;
252 if (NILP (frame))
253 frame = selected_frame;
255 type = Fframep (frame);
257 if (NILP (type))
258 wrong_type_argument (Qframep, frame);
260 if (EQ (type, Qt))
261 return Qnil;
262 else
263 return type;
266 struct frame *
267 make_frame (int mini_p)
269 Lisp_Object frame;
270 register struct frame *f;
271 register Lisp_Object root_window;
272 register Lisp_Object mini_window;
274 f = allocate_frame ();
275 XSETFRAME (frame, f);
277 /* Initialize Lisp data. Note that allocate_frame initializes all
278 Lisp data to nil, so do it only for slots which should not be nil. */
279 fset_tool_bar_position (f, Qtop);
281 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
282 non-Lisp data, so do it only for slots which should not be zero.
283 To avoid subtle bugs and for the sake of readability, it's better to
284 initialize enum members explicitly even if their values are zero. */
285 f->wants_modeline = 1;
286 f->garbaged = 1;
287 f->has_minibuffer = mini_p;
288 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
289 f->column_width = 1; /* !FRAME_WINDOW_P value */
290 f->line_height = 1; /* !FRAME_WINDOW_P value */
291 #ifdef HAVE_WINDOW_SYSTEM
292 f->want_fullscreen = FULLSCREEN_NONE;
293 #endif
295 root_window = make_window ();
296 if (mini_p)
298 mini_window = make_window ();
299 wset_next (XWINDOW (root_window), mini_window);
300 wset_prev (XWINDOW (mini_window), root_window);
301 XWINDOW (mini_window)->mini = 1;
302 wset_frame (XWINDOW (mini_window), frame);
303 fset_minibuffer_window (f, mini_window);
305 else
307 mini_window = Qnil;
308 wset_next (XWINDOW (root_window), Qnil);
309 fset_minibuffer_window (f, Qnil);
312 wset_frame (XWINDOW (root_window), frame);
314 /* 10 is arbitrary,
315 just so that there is "something there."
316 Correct size will be set up later with change_frame_size. */
318 SET_FRAME_COLS (f, 10);
319 FRAME_LINES (f) = 10;
321 wset_total_cols (XWINDOW (root_window), make_number (10));
322 wset_total_lines (XWINDOW (root_window), make_number (mini_p ? 9 : 10));
324 if (mini_p)
326 wset_total_cols (XWINDOW (mini_window), make_number (10));
327 wset_top_line (XWINDOW (mini_window), make_number (9));
328 wset_total_lines (XWINDOW (mini_window), make_number (1));
331 /* Choose a buffer for the frame's root window. */
333 Lisp_Object buf;
335 wset_buffer (XWINDOW (root_window), Qt);
336 buf = Fcurrent_buffer ();
337 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
338 a space), try to find another one. */
339 if (SREF (Fbuffer_name (buf), 0) == ' ')
340 buf = other_buffer_safely (buf);
342 /* Use set_window_buffer, not Fset_window_buffer, and don't let
343 hooks be run by it. The reason is that the whole frame/window
344 arrangement is not yet fully initialized at this point. Windows
345 don't have the right size, glyph matrices aren't initialized
346 etc. Running Lisp functions at this point surely ends in a
347 SEGV. */
348 set_window_buffer (root_window, buf, 0, 0);
349 fset_buffer_list (f, Fcons (buf, Qnil));
352 if (mini_p)
354 wset_buffer (XWINDOW (mini_window), Qt);
355 set_window_buffer (mini_window,
356 (NILP (Vminibuffer_list)
357 ? get_minibuffer (0)
358 : Fcar (Vminibuffer_list)),
359 0, 0);
362 fset_root_window (f, root_window);
363 fset_selected_window (f, root_window);
364 /* Make sure this window seems more recently used than
365 a newly-created, never-selected window. */
366 XWINDOW (f->selected_window)->use_time = ++window_select_count;
368 return f;
371 #ifdef HAVE_WINDOW_SYSTEM
372 /* Make a frame using a separate minibuffer window on another frame.
373 MINI_WINDOW is the minibuffer window to use. nil means use the
374 default (the global minibuffer). */
376 struct frame *
377 make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
379 register struct frame *f;
380 struct gcpro gcpro1;
382 if (!NILP (mini_window))
383 CHECK_LIVE_WINDOW (mini_window);
385 if (!NILP (mini_window)
386 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
387 error ("Frame and minibuffer must be on the same terminal");
389 /* Make a frame containing just a root window. */
390 f = make_frame (0);
392 if (NILP (mini_window))
394 /* Use default-minibuffer-frame if possible. */
395 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
396 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
398 Lisp_Object frame_dummy;
400 XSETFRAME (frame_dummy, f);
401 GCPRO1 (frame_dummy);
402 /* If there's no minibuffer frame to use, create one. */
403 kset_default_minibuffer_frame
404 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
405 UNGCPRO;
408 mini_window
409 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
412 fset_minibuffer_window (f, mini_window);
414 /* Make the chosen minibuffer window display the proper minibuffer,
415 unless it is already showing a minibuffer. */
416 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
417 /* Use set_window_buffer instead of Fset_window_buffer (see
418 discussion of bug#11984, bug#12025, bug#12026). */
419 set_window_buffer (mini_window,
420 (NILP (Vminibuffer_list)
421 ? get_minibuffer (0)
422 : Fcar (Vminibuffer_list)), 0, 0);
423 return f;
426 /* Make a frame containing only a minibuffer window. */
428 struct frame *
429 make_minibuffer_frame (void)
431 /* First make a frame containing just a root window, no minibuffer. */
433 register struct frame *f = make_frame (0);
434 register Lisp_Object mini_window;
435 register Lisp_Object frame;
437 XSETFRAME (frame, f);
439 f->auto_raise = 0;
440 f->auto_lower = 0;
441 f->no_split = 1;
442 f->wants_modeline = 0;
443 f->has_minibuffer = 1;
445 /* Now label the root window as also being the minibuffer.
446 Avoid infinite looping on the window chain by marking next pointer
447 as nil. */
449 mini_window = f->root_window;
450 fset_minibuffer_window (f, mini_window);
451 XWINDOW (mini_window)->mini = 1;
452 wset_next (XWINDOW (mini_window), Qnil);
453 wset_prev (XWINDOW (mini_window), Qnil);
454 wset_frame (XWINDOW (mini_window), frame);
456 /* Put the proper buffer in that window. */
458 /* Use set_window_buffer instead of Fset_window_buffer (see
459 discussion of bug#11984, bug#12025, bug#12026). */
460 set_window_buffer (mini_window,
461 (NILP (Vminibuffer_list)
462 ? get_minibuffer (0)
463 : Fcar (Vminibuffer_list)), 0, 0);
464 return f;
466 #endif /* HAVE_WINDOW_SYSTEM */
468 /* Construct a frame that refers to a terminal. */
470 static printmax_t tty_frame_count;
472 struct frame *
473 make_initial_frame (void)
475 struct frame *f;
476 struct terminal *terminal;
477 Lisp_Object frame;
479 eassert (initial_kboard);
481 /* The first call must initialize Vframe_list. */
482 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
483 Vframe_list = Qnil;
485 terminal = init_initial_terminal ();
487 f = make_frame (1);
488 XSETFRAME (frame, f);
490 Vframe_list = Fcons (frame, Vframe_list);
492 tty_frame_count = 1;
493 fset_name (f, build_pure_c_string ("F1"));
495 f->visible = 1;
496 f->async_visible = 1;
498 f->output_method = terminal->type;
499 f->terminal = terminal;
500 f->terminal->reference_count++;
501 f->output_data.nothing = 0;
503 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
504 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
506 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
507 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
509 /* The default value of menu-bar-mode is t. */
510 set_menu_bar_lines (f, make_number (1), Qnil);
512 if (!noninteractive)
513 init_frame_faces (f);
515 return f;
519 static struct frame *
520 make_terminal_frame (struct terminal *terminal)
522 register struct frame *f;
523 Lisp_Object frame;
524 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
526 if (!terminal->name)
527 error ("Terminal is not live, can't create new frames on it");
529 f = make_frame (1);
531 XSETFRAME (frame, f);
532 Vframe_list = Fcons (frame, Vframe_list);
534 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
536 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
537 f->async_visible = 1; /* Don't let visible be cleared later. */
538 f->terminal = terminal;
539 f->terminal->reference_count++;
540 #ifdef MSDOS
541 f->output_data.tty->display_info = &the_only_display_info;
542 if (!inhibit_window_system
543 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
544 || XFRAME (selected_frame)->output_method == output_msdos_raw))
545 f->output_method = output_msdos_raw;
546 else
547 f->output_method = output_termcap;
548 #else /* not MSDOS */
549 f->output_method = output_termcap;
550 create_tty_output (f);
551 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
552 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
553 #endif /* not MSDOS */
555 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
556 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
557 FRAME_MENU_BAR_LINES(f) = NILP (Vmenu_bar_mode) ? 0 : 1;
559 /* Set the top frame to the newly created frame. */
560 if (FRAMEP (FRAME_TTY (f)->top_frame)
561 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
562 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
564 FRAME_TTY (f)->top_frame = frame;
566 if (!noninteractive)
567 init_frame_faces (f);
569 return f;
572 /* Get a suitable value for frame parameter PARAMETER for a newly
573 created frame, based on (1) the user-supplied frame parameter
574 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
576 static Lisp_Object
577 get_future_frame_param (Lisp_Object parameter,
578 Lisp_Object supplied_parms,
579 char *current_value)
581 Lisp_Object result;
583 result = Fassq (parameter, supplied_parms);
584 if (NILP (result))
585 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
586 if (NILP (result) && current_value != NULL)
587 result = build_string (current_value);
588 if (!NILP (result) && !STRINGP (result))
589 result = XCDR (result);
590 if (NILP (result) || !STRINGP (result))
591 result = Qnil;
593 return result;
596 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
597 1, 1, 0,
598 doc: /* Create an additional terminal frame, possibly on another terminal.
599 This function takes one argument, an alist specifying frame parameters.
601 You can create multiple frames on a single text terminal, but only one
602 of them (the selected terminal frame) is actually displayed.
604 In practice, generally you don't need to specify any parameters,
605 except when you want to create a new frame on another terminal.
606 In that case, the `tty' parameter specifies the device file to open,
607 and the `tty-type' parameter specifies the terminal type. Example:
609 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
611 Note that changing the size of one terminal frame automatically
612 affects all frames on the same terminal device. */)
613 (Lisp_Object parms)
615 struct frame *f;
616 struct terminal *t = NULL;
617 Lisp_Object frame, tem;
618 struct frame *sf = SELECTED_FRAME ();
620 #ifdef MSDOS
621 if (sf->output_method != output_msdos_raw
622 && sf->output_method != output_termcap)
623 emacs_abort ();
624 #else /* not MSDOS */
626 #ifdef WINDOWSNT /* This should work now! */
627 if (sf->output_method != output_termcap)
628 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
629 #endif
630 #endif /* not MSDOS */
633 Lisp_Object terminal;
635 terminal = Fassq (Qterminal, parms);
636 if (!NILP (terminal))
638 terminal = XCDR (terminal);
639 t = get_terminal (terminal, 1);
641 #ifdef MSDOS
642 if (t && t != the_only_display_info.terminal)
643 /* msdos.c assumes a single tty_display_info object. */
644 error ("Multiple terminals are not supported on this platform");
645 if (!t)
646 t = the_only_display_info.terminal;
647 #endif
650 if (!t)
652 char *name = 0, *type = 0;
653 Lisp_Object tty, tty_type;
655 tty = get_future_frame_param
656 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
657 ? FRAME_TTY (XFRAME (selected_frame))->name
658 : NULL));
659 if (!NILP (tty))
661 name = alloca (SBYTES (tty) + 1);
662 memcpy (name, SSDATA (tty), SBYTES (tty));
663 name[SBYTES (tty)] = 0;
666 tty_type = get_future_frame_param
667 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
668 ? FRAME_TTY (XFRAME (selected_frame))->type
669 : NULL));
670 if (!NILP (tty_type))
672 type = alloca (SBYTES (tty_type) + 1);
673 memcpy (type, SSDATA (tty_type), SBYTES (tty_type));
674 type[SBYTES (tty_type)] = 0;
677 t = init_tty (name, type, 0); /* Errors are not fatal. */
680 f = make_terminal_frame (t);
683 int width, height;
684 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
685 change_frame_size (f, height, width, 0, 0, 0);
688 adjust_glyphs (f);
689 calculate_costs (f);
690 XSETFRAME (frame, f);
691 Fmodify_frame_parameters (frame, parms);
692 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
693 build_string (t->display_info.tty->type)),
694 Qnil));
695 if (t->display_info.tty->name != NULL)
696 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
697 build_string (t->display_info.tty->name)),
698 Qnil));
699 else
700 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
702 /* Make the frame face alist be frame-specific, so that each
703 frame could change its face definitions independently. */
704 fset_face_alist (f, Fcopy_alist (sf->face_alist));
705 /* Simple Fcopy_alist isn't enough, because we need the contents of
706 the vectors which are the CDRs of associations in face_alist to
707 be copied as well. */
708 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
709 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
710 return frame;
714 /* Perform the switch to frame FRAME.
716 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
717 FRAME1 as frame.
719 If TRACK is non-zero and the frame that currently has the focus
720 redirects its focus to the selected frame, redirect that focused
721 frame's focus to FRAME instead.
723 FOR_DELETION non-zero means that the selected frame is being
724 deleted, which includes the possibility that the frame's terminal
725 is dead.
727 The value of NORECORD is passed as argument to Fselect_window. */
729 Lisp_Object
730 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
732 struct frame *sf = SELECTED_FRAME ();
734 /* If FRAME is a switch-frame event, extract the frame we should
735 switch to. */
736 if (CONSP (frame)
737 && EQ (XCAR (frame), Qswitch_frame)
738 && CONSP (XCDR (frame)))
739 frame = XCAR (XCDR (frame));
741 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
742 a switch-frame event to arrive after a frame is no longer live,
743 especially when deleting the initial frame during startup. */
744 CHECK_FRAME (frame);
745 if (! FRAME_LIVE_P (XFRAME (frame)))
746 return Qnil;
748 if (sf == XFRAME (frame))
749 return frame;
751 /* This is too greedy; it causes inappropriate focus redirection
752 that's hard to get rid of. */
753 #if 0
754 /* If a frame's focus has been redirected toward the currently
755 selected frame, we should change the redirection to point to the
756 newly selected frame. This means that if the focus is redirected
757 from a minibufferless frame to a surrogate minibuffer frame, we
758 can use `other-window' to switch between all the frames using
759 that minibuffer frame, and the focus redirection will follow us
760 around. */
761 if (track)
763 Lisp_Object tail;
765 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
767 Lisp_Object focus;
769 if (!FRAMEP (XCAR (tail)))
770 emacs_abort ();
772 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
774 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
775 Fredirect_frame_focus (XCAR (tail), frame);
778 #else /* ! 0 */
779 /* Instead, apply it only to the frame we're pointing to. */
780 #ifdef HAVE_WINDOW_SYSTEM
781 if (track && FRAME_WINDOW_P (XFRAME (frame)))
783 Lisp_Object focus, xfocus;
785 xfocus = x_get_focus_frame (XFRAME (frame));
786 if (FRAMEP (xfocus))
788 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
789 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
790 Fredirect_frame_focus (xfocus, frame);
793 #endif /* HAVE_X_WINDOWS */
794 #endif /* ! 0 */
796 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
797 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
799 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
801 if (FRAMEP (FRAME_TTY (XFRAME (frame))->top_frame))
802 /* Mark previously displayed frame as now obscured. */
803 XFRAME (FRAME_TTY (XFRAME (frame))->top_frame)->async_visible = 2;
804 XFRAME (frame)->async_visible = 1;
805 FRAME_TTY (XFRAME (frame))->top_frame = frame;
808 selected_frame = frame;
809 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
810 last_nonminibuf_frame = XFRAME (selected_frame);
812 Fselect_window (XFRAME (frame)->selected_window, norecord);
814 /* We want to make sure that the next event generates a frame-switch
815 event to the appropriate frame. This seems kludgy to me, but
816 before you take it out, make sure that evaluating something like
817 (select-window (frame-root-window (new-frame))) doesn't end up
818 with your typing being interpreted in the new frame instead of
819 the one you're actually typing in. */
820 internal_last_event_frame = Qnil;
822 return frame;
825 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
826 doc: /* Select FRAME.
827 Subsequent editing commands apply to its selected window.
828 Optional argument NORECORD means to neither change the order of
829 recently selected windows nor the buffer list.
831 The selection of FRAME lasts until the next time the user does
832 something to select a different frame, or until the next time
833 this function is called. If you are using a window system, the
834 previously selected frame may be restored as the selected frame
835 when returning to the command loop, because it still may have
836 the window system's input focus. On a text terminal, the next
837 redisplay will display FRAME.
839 This function returns FRAME, or nil if FRAME has been deleted. */)
840 (Lisp_Object frame, Lisp_Object norecord)
842 return do_switch_frame (frame, 1, 0, norecord);
846 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
847 doc: /* Handle a switch-frame event EVENT.
848 Switch-frame events are usually bound to this function.
849 A switch-frame event tells Emacs that the window manager has requested
850 that the user's events be directed to the frame mentioned in the event.
851 This function selects the selected window of the frame of EVENT.
853 If EVENT is frame object, handle it as if it were a switch-frame event
854 to that frame. */)
855 (Lisp_Object event)
857 /* Preserve prefix arg that the command loop just cleared. */
858 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
859 Frun_hooks (1, &Qmouse_leave_buffer_hook);
860 return do_switch_frame (event, 0, 0, Qnil);
863 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
864 doc: /* Return the frame that is now selected. */)
865 (void)
867 return selected_frame;
870 DEFUN ("frame-list", Fframe_list, Sframe_list,
871 0, 0, 0,
872 doc: /* Return a list of all live frames. */)
873 (void)
875 Lisp_Object frames;
876 frames = Fcopy_sequence (Vframe_list);
877 #ifdef HAVE_WINDOW_SYSTEM
878 if (FRAMEP (tip_frame))
879 frames = Fdelq (tip_frame, frames);
880 #endif
881 return frames;
884 /* Return the next frame in the frame list after FRAME.
885 If MINIBUF is nil, exclude minibuffer-only frames.
886 If MINIBUF is a window, include only its own frame
887 and any frame now using that window as the minibuffer.
888 If MINIBUF is `visible', include all visible frames.
889 If MINIBUF is 0, include all visible and iconified frames.
890 Otherwise, include all frames. */
892 static Lisp_Object
893 next_frame (Lisp_Object frame, Lisp_Object minibuf)
895 Lisp_Object tail;
896 int passed = 0;
898 /* There must always be at least one frame in Vframe_list. */
899 if (! CONSP (Vframe_list))
900 emacs_abort ();
902 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
903 forever. Forestall that. */
904 CHECK_LIVE_FRAME (frame);
906 while (1)
907 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
909 Lisp_Object f;
911 f = XCAR (tail);
913 if (passed
914 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
915 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
916 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
917 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
919 /* Decide whether this frame is eligible to be returned. */
921 /* If we've looped all the way around without finding any
922 eligible frames, return the original frame. */
923 if (EQ (f, frame))
924 return f;
926 /* Let minibuf decide if this frame is acceptable. */
927 if (NILP (minibuf))
929 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
930 return f;
932 else if (EQ (minibuf, Qvisible))
934 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
935 if (FRAME_VISIBLE_P (XFRAME (f)))
936 return f;
938 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
940 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
941 if (FRAME_VISIBLE_P (XFRAME (f))
942 || FRAME_ICONIFIED_P (XFRAME (f)))
943 return f;
945 else if (WINDOWP (minibuf))
947 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
948 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
949 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
950 FRAME_FOCUS_FRAME (XFRAME (f))))
951 return f;
953 else
954 return f;
957 if (EQ (frame, f))
958 passed++;
962 /* Return the previous frame in the frame list before FRAME.
963 If MINIBUF is nil, exclude minibuffer-only frames.
964 If MINIBUF is a window, include only its own frame
965 and any frame now using that window as the minibuffer.
966 If MINIBUF is `visible', include all visible frames.
967 If MINIBUF is 0, include all visible and iconified frames.
968 Otherwise, include all frames. */
970 static Lisp_Object
971 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
973 Lisp_Object tail;
974 Lisp_Object prev;
976 /* There must always be at least one frame in Vframe_list. */
977 if (! CONSP (Vframe_list))
978 emacs_abort ();
980 prev = Qnil;
981 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
983 Lisp_Object f;
985 f = XCAR (tail);
986 if (!FRAMEP (f))
987 emacs_abort ();
989 if (EQ (frame, f) && !NILP (prev))
990 return prev;
992 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
993 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
994 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
995 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
997 /* Decide whether this frame is eligible to be returned,
998 according to minibuf. */
999 if (NILP (minibuf))
1001 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1002 prev = f;
1004 else if (WINDOWP (minibuf))
1006 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1007 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1008 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1009 FRAME_FOCUS_FRAME (XFRAME (f))))
1010 prev = f;
1012 else if (EQ (minibuf, Qvisible))
1014 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1015 if (FRAME_VISIBLE_P (XFRAME (f)))
1016 prev = f;
1018 else if (XFASTINT (minibuf) == 0)
1020 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1021 if (FRAME_VISIBLE_P (XFRAME (f))
1022 || FRAME_ICONIFIED_P (XFRAME (f)))
1023 prev = f;
1025 else
1026 prev = f;
1030 /* We've scanned the entire list. */
1031 if (NILP (prev))
1032 /* We went through the whole frame list without finding a single
1033 acceptable frame. Return the original frame. */
1034 return frame;
1035 else
1036 /* There were no acceptable frames in the list before FRAME; otherwise,
1037 we would have returned directly from the loop. Since PREV is the last
1038 acceptable frame in the list, return it. */
1039 return prev;
1043 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1044 doc: /* Return the next frame in the frame list after FRAME.
1045 It considers only frames on the same terminal as FRAME.
1046 By default, skip minibuffer-only frames.
1047 If omitted, FRAME defaults to the selected frame.
1048 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1049 If MINIFRAME is a window, include only its own frame
1050 and any frame now using that window as the minibuffer.
1051 If MINIFRAME is `visible', include all visible frames.
1052 If MINIFRAME is 0, include all visible and iconified frames.
1053 Otherwise, include all frames. */)
1054 (Lisp_Object frame, Lisp_Object miniframe)
1056 if (NILP (frame))
1057 frame = selected_frame;
1059 CHECK_LIVE_FRAME (frame);
1060 return next_frame (frame, miniframe);
1063 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1064 doc: /* Return the previous frame in the frame list before FRAME.
1065 It considers only frames on the same terminal as FRAME.
1066 By default, skip minibuffer-only frames.
1067 If omitted, FRAME defaults to the selected frame.
1068 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1069 If MINIFRAME is a window, include only its own frame
1070 and any frame now using that window as the minibuffer.
1071 If MINIFRAME is `visible', include all visible frames.
1072 If MINIFRAME is 0, include all visible and iconified frames.
1073 Otherwise, include all frames. */)
1074 (Lisp_Object frame, Lisp_Object miniframe)
1076 if (NILP (frame))
1077 frame = selected_frame;
1078 CHECK_LIVE_FRAME (frame);
1079 return prev_frame (frame, miniframe);
1082 /* Return 1 if it is ok to delete frame F;
1083 0 if all frames aside from F are invisible.
1084 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1086 static int
1087 other_visible_frames (FRAME_PTR f)
1089 Lisp_Object frames;
1091 for (frames = Vframe_list; CONSP (frames); frames = XCDR (frames))
1093 Lisp_Object this = XCAR (frames);
1094 if (f == XFRAME (this))
1095 continue;
1097 /* Verify that we can still talk to the frame's X window,
1098 and note any recent change in visibility. */
1099 #ifdef HAVE_WINDOW_SYSTEM
1100 if (FRAME_WINDOW_P (XFRAME (this)))
1102 x_sync (XFRAME (this));
1103 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1105 #endif
1107 if (FRAME_VISIBLE_P (XFRAME (this))
1108 || FRAME_ICONIFIED_P (XFRAME (this))
1109 /* Allow deleting the terminal frame when at least one X
1110 frame exists. */
1111 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1112 return 1;
1114 return 0;
1117 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1118 unconditionally. x_connection_closed and delete_terminal use
1119 this. Any other value of FORCE implements the semantics
1120 described for Fdelete_frame. */
1121 Lisp_Object
1122 delete_frame (Lisp_Object frame, Lisp_Object force)
1124 struct frame *f;
1125 struct frame *sf = SELECTED_FRAME ();
1126 struct kboard *kb;
1128 int minibuffer_selected, tooltip_frame;
1130 if (EQ (frame, Qnil))
1132 f = sf;
1133 XSETFRAME (frame, f);
1135 else
1137 CHECK_FRAME (frame);
1138 f = XFRAME (frame);
1141 if (! FRAME_LIVE_P (f))
1142 return Qnil;
1144 if (NILP (force) && !other_visible_frames (f))
1145 error ("Attempt to delete the sole visible or iconified frame");
1147 /* x_connection_closed must have set FORCE to `noelisp' in order
1148 to delete the last frame, if it is gone. */
1149 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1150 error ("Attempt to delete the only frame");
1152 /* Does this frame have a minibuffer, and is it the surrogate
1153 minibuffer for any other frame? */
1154 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1156 Lisp_Object frames;
1158 for (frames = Vframe_list;
1159 CONSP (frames);
1160 frames = XCDR (frames))
1162 Lisp_Object this;
1163 this = XCAR (frames);
1165 if (! EQ (this, frame)
1166 && EQ (frame,
1167 WINDOW_FRAME (XWINDOW
1168 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1170 /* If we MUST delete this frame, delete the other first.
1171 But do this only if FORCE equals `noelisp'. */
1172 if (EQ (force, Qnoelisp))
1173 delete_frame (this, Qnoelisp);
1174 else
1175 error ("Attempt to delete a surrogate minibuffer frame");
1180 tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1182 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1183 frame is a tooltip. FORCE is set to `noelisp' when handling
1184 a disconnect from the terminal, so we don't dare call Lisp
1185 code. */
1186 if (NILP (Vrun_hooks) || tooltip_frame)
1188 else if (EQ (force, Qnoelisp))
1189 pending_funcalls
1190 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1191 pending_funcalls);
1192 else
1194 #ifdef HAVE_X_WINDOWS
1195 /* Also, save clipboard to the clipboard manager. */
1196 x_clipboard_manager_save_frame (frame);
1197 #endif
1199 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1202 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1203 if (! FRAME_LIVE_P (f))
1204 return Qnil;
1206 /* At this point, we are committed to deleting the frame.
1207 There is no more chance for errors to prevent it. */
1209 minibuffer_selected = EQ (minibuf_window, selected_window);
1211 /* Don't let the frame remain selected. */
1212 if (f == sf)
1214 Lisp_Object tail, frame1;
1216 /* Look for another visible frame on the same terminal. */
1217 frame1 = next_frame (frame, Qvisible);
1219 /* If there is none, find *some* other frame. */
1220 if (NILP (frame1) || EQ (frame1, frame))
1222 FOR_EACH_FRAME (tail, frame1)
1224 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1226 /* Do not change a text terminal's top-frame. */
1227 struct frame *f1 = XFRAME (frame1);
1228 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1230 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1231 if (!EQ (top_frame, frame))
1232 frame1 = top_frame;
1234 break;
1238 #ifdef NS_IMPL_COCOA
1239 else
1240 /* Under NS, there is no system mechanism for choosing a new
1241 window to get focus -- it is left to application code.
1242 So the portion of THIS application interfacing with NS
1243 needs to know about it. We call Fraise_frame, but the
1244 purpose is really to transfer focus. */
1245 Fraise_frame (frame1);
1246 #endif
1248 do_switch_frame (frame1, 0, 1, Qnil);
1249 sf = SELECTED_FRAME ();
1252 /* Don't allow minibuf_window to remain on a deleted frame. */
1253 if (EQ (f->minibuffer_window, minibuf_window))
1255 /* Use set_window_buffer instead of Fset_window_buffer (see
1256 discussion of bug#11984, bug#12025, bug#12026). */
1257 set_window_buffer (sf->minibuffer_window,
1258 XWINDOW (minibuf_window)->buffer, 0, 0);
1259 minibuf_window = sf->minibuffer_window;
1261 /* If the dying minibuffer window was selected,
1262 select the new one. */
1263 if (minibuffer_selected)
1264 Fselect_window (minibuf_window, Qnil);
1267 /* Don't let echo_area_window to remain on a deleted frame. */
1268 if (EQ (f->minibuffer_window, echo_area_window))
1269 echo_area_window = sf->minibuffer_window;
1271 /* Clear any X selections for this frame. */
1272 #ifdef HAVE_X_WINDOWS
1273 if (FRAME_X_P (f))
1274 x_clear_frame_selections (f);
1275 #endif
1277 /* Free glyphs.
1278 This function must be called before the window tree of the
1279 frame is deleted because windows contain dynamically allocated
1280 memory. */
1281 free_glyphs (f);
1283 #ifdef HAVE_WINDOW_SYSTEM
1284 /* Give chance to each font driver to free a frame specific data. */
1285 font_update_drivers (f, Qnil);
1286 #endif
1288 /* Mark all the windows that used to be on FRAME as deleted, and then
1289 remove the reference to them. */
1290 delete_all_child_windows (f->root_window);
1291 fset_root_window (f, Qnil);
1293 Vframe_list = Fdelq (frame, Vframe_list);
1294 FRAME_SET_VISIBLE (f, 0);
1296 /* Allow the vector of menu bar contents to be freed in the next
1297 garbage collection. The frame object itself may not be garbage
1298 collected until much later, because recent_keys and other data
1299 structures can still refer to it. */
1300 fset_menu_bar_vector (f, Qnil);
1302 free_font_driver_list (f);
1303 xfree (f->namebuf);
1304 xfree (f->decode_mode_spec_buffer);
1305 xfree (FRAME_INSERT_COST (f));
1306 xfree (FRAME_DELETEN_COST (f));
1307 xfree (FRAME_INSERTN_COST (f));
1308 xfree (FRAME_DELETE_COST (f));
1309 xfree (FRAME_MESSAGE_BUF (f));
1311 /* Since some events are handled at the interrupt level, we may get
1312 an event for f at any time; if we zero out the frame's terminal
1313 now, then we may trip up the event-handling code. Instead, we'll
1314 promise that the terminal of the frame must be valid until we
1315 have called the window-system-dependent frame destruction
1316 routine. */
1318 if (FRAME_TERMINAL (f)->delete_frame_hook)
1319 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1322 struct terminal *terminal = FRAME_TERMINAL (f);
1323 f->output_data.nothing = 0;
1324 f->terminal = 0; /* Now the frame is dead. */
1326 /* If needed, delete the terminal that this frame was on.
1327 (This must be done after the frame is killed.) */
1328 terminal->reference_count--;
1329 #ifdef USE_GTK
1330 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1331 bug.
1332 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1333 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1334 terminal->reference_count = 1;
1335 #endif /* USE_GTK */
1336 if (terminal->reference_count == 0)
1338 Lisp_Object tmp;
1339 XSETTERMINAL (tmp, terminal);
1341 kb = NULL;
1342 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1344 else
1345 kb = terminal->kboard;
1348 /* If we've deleted the last_nonminibuf_frame, then try to find
1349 another one. */
1350 if (f == last_nonminibuf_frame)
1352 Lisp_Object frames;
1354 last_nonminibuf_frame = 0;
1356 for (frames = Vframe_list;
1357 CONSP (frames);
1358 frames = XCDR (frames))
1360 f = XFRAME (XCAR (frames));
1361 if (!FRAME_MINIBUF_ONLY_P (f))
1363 last_nonminibuf_frame = f;
1364 break;
1369 /* If there's no other frame on the same kboard, get out of
1370 single-kboard state if we're in it for this kboard. */
1371 if (kb != NULL)
1373 Lisp_Object frames;
1374 /* Some frame we found on the same kboard, or nil if there are none. */
1375 Lisp_Object frame_on_same_kboard;
1377 frame_on_same_kboard = Qnil;
1379 for (frames = Vframe_list;
1380 CONSP (frames);
1381 frames = XCDR (frames))
1383 Lisp_Object this;
1384 struct frame *f1;
1386 this = XCAR (frames);
1387 if (!FRAMEP (this))
1388 emacs_abort ();
1389 f1 = XFRAME (this);
1391 if (kb == FRAME_KBOARD (f1))
1392 frame_on_same_kboard = this;
1395 if (NILP (frame_on_same_kboard))
1396 not_single_kboard_state (kb);
1400 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1401 find another one. Prefer minibuffer-only frames, but also notice
1402 frames with other windows. */
1403 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1405 Lisp_Object frames;
1407 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1408 Lisp_Object frame_with_minibuf;
1409 /* Some frame we found on the same kboard, or nil if there are none. */
1410 Lisp_Object frame_on_same_kboard;
1412 frame_on_same_kboard = Qnil;
1413 frame_with_minibuf = Qnil;
1415 for (frames = Vframe_list;
1416 CONSP (frames);
1417 frames = XCDR (frames))
1419 Lisp_Object this;
1420 struct frame *f1;
1422 this = XCAR (frames);
1423 if (!FRAMEP (this))
1424 emacs_abort ();
1425 f1 = XFRAME (this);
1427 /* Consider only frames on the same kboard
1428 and only those with minibuffers. */
1429 if (kb == FRAME_KBOARD (f1)
1430 && FRAME_HAS_MINIBUF_P (f1))
1432 frame_with_minibuf = this;
1433 if (FRAME_MINIBUF_ONLY_P (f1))
1434 break;
1437 if (kb == FRAME_KBOARD (f1))
1438 frame_on_same_kboard = this;
1441 if (!NILP (frame_on_same_kboard))
1443 /* We know that there must be some frame with a minibuffer out
1444 there. If this were not true, all of the frames present
1445 would have to be minibufferless, which implies that at some
1446 point their minibuffer frames must have been deleted, but
1447 that is prohibited at the top; you can't delete surrogate
1448 minibuffer frames. */
1449 if (NILP (frame_with_minibuf))
1450 emacs_abort ();
1452 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1454 else
1455 /* No frames left on this kboard--say no minibuffer either. */
1456 kset_default_minibuffer_frame (kb, Qnil);
1459 /* Cause frame titles to update--necessary if we now have just one frame. */
1460 if (!tooltip_frame)
1461 update_mode_lines = 1;
1463 return Qnil;
1466 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1467 doc: /* Delete FRAME, permanently eliminating it from use.
1468 FRAME defaults to the selected frame.
1470 A frame may not be deleted if its minibuffer is used by other frames.
1471 Normally, you may not delete a frame if all other frames are invisible,
1472 but if the second optional argument FORCE is non-nil, you may do so.
1474 This function runs `delete-frame-functions' before actually
1475 deleting the frame, unless the frame is a tooltip.
1476 The functions are run with one argument, the frame to be deleted. */)
1477 (Lisp_Object frame, Lisp_Object force)
1479 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1483 /* Return mouse position in character cell units. */
1485 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1486 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1487 The position is given in character cells, where (0, 0) is the
1488 upper-left corner of the frame, X is the horizontal offset, and Y is
1489 the vertical offset.
1490 If Emacs is running on a mouseless terminal or hasn't been programmed
1491 to read the mouse position, it returns the selected frame for FRAME
1492 and nil for X and Y.
1493 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1494 passing the normal return value to that function as an argument,
1495 and returns whatever that function returns. */)
1496 (void)
1498 FRAME_PTR f;
1499 Lisp_Object lispy_dummy;
1500 enum scroll_bar_part party_dummy;
1501 Lisp_Object x, y, retval;
1502 int col, row;
1503 Time long_dummy;
1504 struct gcpro gcpro1;
1506 f = SELECTED_FRAME ();
1507 x = y = Qnil;
1509 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1510 /* It's okay for the hook to refrain from storing anything. */
1511 if (FRAME_TERMINAL (f)->mouse_position_hook)
1512 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1513 &lispy_dummy, &party_dummy,
1514 &x, &y,
1515 &long_dummy);
1516 if (! NILP (x))
1518 col = XINT (x);
1519 row = XINT (y);
1520 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1521 XSETINT (x, col);
1522 XSETINT (y, row);
1524 #endif
1525 XSETFRAME (lispy_dummy, f);
1526 retval = Fcons (lispy_dummy, Fcons (x, y));
1527 GCPRO1 (retval);
1528 if (!NILP (Vmouse_position_function))
1529 retval = call1 (Vmouse_position_function, retval);
1530 RETURN_UNGCPRO (retval);
1533 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1534 Smouse_pixel_position, 0, 0, 0,
1535 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1536 The position is given in pixel units, where (0, 0) is the
1537 upper-left corner of the frame, X is the horizontal offset, and Y is
1538 the vertical offset.
1539 If Emacs is running on a mouseless terminal or hasn't been programmed
1540 to read the mouse position, it returns the selected frame for FRAME
1541 and nil for X and Y. */)
1542 (void)
1544 FRAME_PTR f;
1545 Lisp_Object lispy_dummy;
1546 enum scroll_bar_part party_dummy;
1547 Lisp_Object x, y;
1548 Time long_dummy;
1550 f = SELECTED_FRAME ();
1551 x = y = Qnil;
1553 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1554 /* It's okay for the hook to refrain from storing anything. */
1555 if (FRAME_TERMINAL (f)->mouse_position_hook)
1556 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1557 &lispy_dummy, &party_dummy,
1558 &x, &y,
1559 &long_dummy);
1560 #endif
1561 XSETFRAME (lispy_dummy, f);
1562 return Fcons (lispy_dummy, Fcons (x, y));
1565 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1566 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1567 Coordinates are relative to the frame, not a window,
1568 so the coordinates of the top left character in the frame
1569 may be nonzero due to left-hand scroll bars or the menu bar.
1571 The position is given in character cells, where (0, 0) is the
1572 upper-left corner of the frame, X is the horizontal offset, and Y is
1573 the vertical offset.
1575 This function is a no-op for an X frame that is not visible.
1576 If you have just created a frame, you must wait for it to become visible
1577 before calling this function on it, like this.
1578 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1579 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1581 CHECK_LIVE_FRAME (frame);
1582 CHECK_TYPE_RANGED_INTEGER (int, x);
1583 CHECK_TYPE_RANGED_INTEGER (int, y);
1585 /* I think this should be done with a hook. */
1586 #ifdef HAVE_WINDOW_SYSTEM
1587 if (FRAME_WINDOW_P (XFRAME (frame)))
1588 /* Warping the mouse will cause enternotify and focus events. */
1589 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1590 #else
1591 #if defined (MSDOS) && defined (HAVE_MOUSE)
1592 if (FRAME_MSDOS_P (XFRAME (frame)))
1594 Fselect_frame (frame, Qnil);
1595 mouse_moveto (XINT (x), XINT (y));
1597 #else
1598 #ifdef HAVE_GPM
1600 Fselect_frame (frame, Qnil);
1601 term_mouse_moveto (XINT (x), XINT (y));
1603 #endif
1604 #endif
1605 #endif
1607 return Qnil;
1610 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1611 Sset_mouse_pixel_position, 3, 3, 0,
1612 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1613 The position is given in pixels, where (0, 0) is the upper-left corner
1614 of the frame, X is the horizontal offset, and Y is the vertical offset.
1616 Note, this is a no-op for an X frame that is not visible.
1617 If you have just created a frame, you must wait for it to become visible
1618 before calling this function on it, like this.
1619 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1620 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1622 CHECK_LIVE_FRAME (frame);
1623 CHECK_TYPE_RANGED_INTEGER (int, x);
1624 CHECK_TYPE_RANGED_INTEGER (int, y);
1626 /* I think this should be done with a hook. */
1627 #ifdef HAVE_WINDOW_SYSTEM
1628 if (FRAME_WINDOW_P (XFRAME (frame)))
1629 /* Warping the mouse will cause enternotify and focus events. */
1630 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1631 #else
1632 #if defined (MSDOS) && defined (HAVE_MOUSE)
1633 if (FRAME_MSDOS_P (XFRAME (frame)))
1635 Fselect_frame (frame, Qnil);
1636 mouse_moveto (XINT (x), XINT (y));
1638 #else
1639 #ifdef HAVE_GPM
1641 Fselect_frame (frame, Qnil);
1642 term_mouse_moveto (XINT (x), XINT (y));
1644 #endif
1645 #endif
1646 #endif
1648 return Qnil;
1651 static void make_frame_visible_1 (Lisp_Object);
1653 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1654 0, 1, "",
1655 doc: /* Make the frame FRAME visible (assuming it is an X window).
1656 If omitted, FRAME defaults to the currently selected frame. */)
1657 (Lisp_Object frame)
1659 if (NILP (frame))
1660 frame = selected_frame;
1662 CHECK_LIVE_FRAME (frame);
1664 /* I think this should be done with a hook. */
1665 #ifdef HAVE_WINDOW_SYSTEM
1666 if (FRAME_WINDOW_P (XFRAME (frame)))
1668 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1669 x_make_frame_visible (XFRAME (frame));
1671 #endif
1673 make_frame_visible_1 (XFRAME (frame)->root_window);
1675 /* Make menu bar update for the Buffers and Frames menus. */
1676 windows_or_buffers_changed++;
1678 return frame;
1681 /* Update the display_time slot of the buffers shown in WINDOW
1682 and all its descendants. */
1684 static void
1685 make_frame_visible_1 (Lisp_Object window)
1687 struct window *w;
1689 for (;!NILP (window); window = w->next)
1691 w = XWINDOW (window);
1693 if (!NILP (w->buffer))
1694 bset_display_time (XBUFFER (w->buffer), Fcurrent_time ());
1696 if (!NILP (w->vchild))
1697 make_frame_visible_1 (w->vchild);
1698 if (!NILP (w->hchild))
1699 make_frame_visible_1 (w->hchild);
1703 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1704 0, 2, "",
1705 doc: /* Make the frame FRAME invisible.
1706 If omitted, FRAME defaults to the currently selected frame.
1707 On graphical displays, invisible frames are not updated and are
1708 usually not displayed at all, even in a window system's \"taskbar\".
1710 Normally you may not make FRAME invisible if all other frames are invisible,
1711 but if the second optional argument FORCE is non-nil, you may do so.
1713 This function has no effect on text terminal frames. Such frames are
1714 always considered visible, whether or not they are currently being
1715 displayed in the terminal. */)
1716 (Lisp_Object frame, Lisp_Object force)
1718 if (NILP (frame))
1719 frame = selected_frame;
1721 CHECK_LIVE_FRAME (frame);
1723 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1724 error ("Attempt to make invisible the sole visible or iconified frame");
1726 /* Don't allow minibuf_window to remain on a deleted frame. */
1727 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1729 struct frame *sf = XFRAME (selected_frame);
1730 /* Use set_window_buffer instead of Fset_window_buffer (see
1731 discussion of bug#11984, bug#12025, bug#12026). */
1732 set_window_buffer (sf->minibuffer_window,
1733 XWINDOW (minibuf_window)->buffer, 0, 0);
1734 minibuf_window = sf->minibuffer_window;
1737 /* I think this should be done with a hook. */
1738 #ifdef HAVE_WINDOW_SYSTEM
1739 if (FRAME_WINDOW_P (XFRAME (frame)))
1740 x_make_frame_invisible (XFRAME (frame));
1741 #endif
1743 /* Make menu bar update for the Buffers and Frames menus. */
1744 windows_or_buffers_changed++;
1746 return Qnil;
1749 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1750 0, 1, "",
1751 doc: /* Make the frame FRAME into an icon.
1752 If omitted, FRAME defaults to the currently selected frame. */)
1753 (Lisp_Object frame)
1755 if (NILP (frame))
1756 frame = selected_frame;
1758 CHECK_LIVE_FRAME (frame);
1760 #if 0 /* This isn't logically necessary, and it can do GC. */
1761 /* Don't let the frame remain selected. */
1762 if (EQ (frame, selected_frame))
1763 Fhandle_switch_frame (next_frame (frame, Qt));
1764 #endif
1766 /* Don't allow minibuf_window to remain on an iconified frame. */
1767 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1769 struct frame *sf = XFRAME (selected_frame);
1770 /* Use set_window_buffer instead of Fset_window_buffer (see
1771 discussion of bug#11984, bug#12025, bug#12026). */
1772 set_window_buffer (sf->minibuffer_window,
1773 XWINDOW (minibuf_window)->buffer, 0, 0);
1774 minibuf_window = sf->minibuffer_window;
1777 /* I think this should be done with a hook. */
1778 #ifdef HAVE_WINDOW_SYSTEM
1779 if (FRAME_WINDOW_P (XFRAME (frame)))
1780 x_iconify_frame (XFRAME (frame));
1781 #endif
1783 /* Make menu bar update for the Buffers and Frames menus. */
1784 windows_or_buffers_changed++;
1786 return Qnil;
1789 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1790 1, 1, 0,
1791 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1792 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1793 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1794 On graphical displays, invisible frames are not updated and are
1795 usually not displayed at all, even in a window system's \"taskbar\".
1797 If FRAME is a text terminal frame, this always returns t.
1798 Such frames are always considered visible, whether or not they are
1799 currently being displayed on the terminal. */)
1800 (Lisp_Object frame)
1802 CHECK_LIVE_FRAME (frame);
1804 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1806 if (FRAME_VISIBLE_P (XFRAME (frame)))
1807 return Qt;
1808 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1809 return Qicon;
1810 return Qnil;
1813 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1814 0, 0, 0,
1815 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1816 (void)
1818 Lisp_Object tail, frame;
1819 struct frame *f;
1820 Lisp_Object value;
1822 value = Qnil;
1823 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1825 frame = XCAR (tail);
1826 if (!FRAMEP (frame))
1827 continue;
1828 f = XFRAME (frame);
1829 if (FRAME_VISIBLE_P (f))
1830 value = Fcons (frame, value);
1832 return value;
1836 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1837 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1838 If FRAME is invisible or iconified, make it visible.
1839 If you don't specify a frame, the selected frame is used.
1840 If Emacs is displaying on an ordinary terminal or some other device which
1841 doesn't support multiple overlapping frames, this function selects FRAME. */)
1842 (Lisp_Object frame)
1844 struct frame *f;
1845 if (NILP (frame))
1846 frame = selected_frame;
1848 CHECK_LIVE_FRAME (frame);
1850 f = XFRAME (frame);
1852 if (FRAME_TERMCAP_P (f))
1853 /* On a text terminal select FRAME. */
1854 Fselect_frame (frame, Qnil);
1855 else
1856 /* Do like the documentation says. */
1857 Fmake_frame_visible (frame);
1859 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1860 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
1862 return Qnil;
1865 /* Should we have a corresponding function called Flower_Power? */
1866 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1867 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1868 If you don't specify a frame, the selected frame is used.
1869 If Emacs is displaying on an ordinary terminal or some other device which
1870 doesn't support multiple overlapping frames, this function does nothing. */)
1871 (Lisp_Object frame)
1873 struct frame *f;
1875 if (NILP (frame))
1876 frame = selected_frame;
1878 CHECK_LIVE_FRAME (frame);
1880 f = XFRAME (frame);
1882 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1883 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
1885 return Qnil;
1889 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1890 1, 2, 0,
1891 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1892 In other words, switch-frame events caused by events in FRAME will
1893 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1894 FOCUS-FRAME after reading an event typed at FRAME.
1896 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
1897 frame again receives its own keystrokes.
1899 Focus redirection is useful for temporarily redirecting keystrokes to
1900 a surrogate minibuffer frame when a frame doesn't have its own
1901 minibuffer window.
1903 A frame's focus redirection can be changed by `select-frame'. If frame
1904 FOO is selected, and then a different frame BAR is selected, any
1905 frames redirecting their focus to FOO are shifted to redirect their
1906 focus to BAR. This allows focus redirection to work properly when the
1907 user switches from one frame to another using `select-window'.
1909 This means that a frame whose focus is redirected to itself is treated
1910 differently from a frame whose focus is redirected to nil; the former
1911 is affected by `select-frame', while the latter is not.
1913 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1914 (Lisp_Object frame, Lisp_Object focus_frame)
1916 struct frame *f;
1918 /* Note that we don't check for a live frame here. It's reasonable
1919 to redirect the focus of a frame you're about to delete, if you
1920 know what other frame should receive those keystrokes. */
1921 CHECK_FRAME (frame);
1923 if (! NILP (focus_frame))
1924 CHECK_LIVE_FRAME (focus_frame);
1926 f = XFRAME (frame);
1928 fset_focus_frame (f, focus_frame);
1930 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
1931 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
1933 return Qnil;
1937 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1938 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1939 This returns nil if FRAME's focus is not redirected.
1940 See `redirect-frame-focus'. */)
1941 (Lisp_Object frame)
1943 CHECK_LIVE_FRAME (frame);
1945 return FRAME_FOCUS_FRAME (XFRAME (frame));
1950 /* Return the value of frame parameter PROP in frame FRAME. */
1952 #ifdef HAVE_WINDOW_SYSTEM
1953 #if !HAVE_NS
1954 static
1955 #endif
1956 Lisp_Object
1957 get_frame_param (register struct frame *frame, Lisp_Object prop)
1959 register Lisp_Object tem;
1961 tem = Fassq (prop, frame->param_alist);
1962 if (EQ (tem, Qnil))
1963 return tem;
1964 return Fcdr (tem);
1966 #endif
1968 /* Return the buffer-predicate of the selected frame. */
1970 Lisp_Object
1971 frame_buffer_predicate (Lisp_Object frame)
1973 return XFRAME (frame)->buffer_predicate;
1976 /* Return the buffer-list of the selected frame. */
1978 static Lisp_Object
1979 frame_buffer_list (Lisp_Object frame)
1981 return XFRAME (frame)->buffer_list;
1984 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
1986 void
1987 frames_discard_buffer (Lisp_Object buffer)
1989 Lisp_Object frame, tail;
1991 FOR_EACH_FRAME (tail, frame)
1993 fset_buffer_list
1994 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
1995 fset_buried_buffer_list
1996 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2000 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2001 If the alist already has an element for PROP, we change it. */
2003 void
2004 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2006 register Lisp_Object tem;
2008 tem = Fassq (prop, *alistptr);
2009 if (EQ (tem, Qnil))
2010 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2011 else
2012 Fsetcdr (tem, val);
2015 static int
2016 frame_name_fnn_p (char *str, ptrdiff_t len)
2018 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2020 char *p = str + 2;
2021 while ('0' <= *p && *p <= '9')
2022 p++;
2023 if (p == str + len)
2024 return 1;
2026 return 0;
2029 /* Set the name of the terminal frame. Also used by MSDOS frames.
2030 Modeled after x_set_name which is used for WINDOW frames. */
2032 static void
2033 set_term_frame_name (struct frame *f, Lisp_Object name)
2035 f->explicit_name = ! NILP (name);
2037 /* If NAME is nil, set the name to F<num>. */
2038 if (NILP (name))
2040 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2042 /* Check for no change needed in this very common case
2043 before we do any consing. */
2044 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2045 return;
2047 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2049 else
2051 CHECK_STRING (name);
2053 /* Don't change the name if it's already NAME. */
2054 if (! NILP (Fstring_equal (name, f->name)))
2055 return;
2057 /* Don't allow the user to set the frame name to F<num>, so it
2058 doesn't clash with the names we generate for terminal frames. */
2059 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2060 error ("Frame names of the form F<num> are usurped by Emacs");
2063 fset_name (f, name);
2064 update_mode_lines = 1;
2067 void
2068 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2070 register Lisp_Object old_alist_elt;
2072 /* The buffer-list parameters are stored in a special place and not
2073 in the alist. All buffers must be live. */
2074 if (EQ (prop, Qbuffer_list))
2076 Lisp_Object list = Qnil;
2077 for (; CONSP (val); val = XCDR (val))
2078 if (!NILP (Fbuffer_live_p (XCAR (val))))
2079 list = Fcons (XCAR (val), list);
2080 fset_buffer_list (f, Fnreverse (list));
2081 return;
2083 if (EQ (prop, Qburied_buffer_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_buried_buffer_list (f, Fnreverse (list));
2090 return;
2093 /* If PROP is a symbol which is supposed to have frame-local values,
2094 and it is set up based on this frame, switch to the global
2095 binding. That way, we can create or alter the frame-local binding
2096 without messing up the symbol's status. */
2097 if (SYMBOLP (prop))
2099 struct Lisp_Symbol *sym = XSYMBOL (prop);
2100 start:
2101 switch (sym->redirect)
2103 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2104 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2105 case SYMBOL_LOCALIZED:
2106 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2107 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2108 swap_in_global_binding (sym);
2109 break;
2111 default: emacs_abort ();
2115 /* The tty color needed to be set before the frame's parameter
2116 alist was updated with the new value. This is not true any more,
2117 but we still do this test early on. */
2118 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2119 && f == FRAME_TTY (f)->previous_frame)
2120 /* Force redisplay of this tty. */
2121 FRAME_TTY (f)->previous_frame = NULL;
2123 /* Update the frame parameter alist. */
2124 old_alist_elt = Fassq (prop, f->param_alist);
2125 if (EQ (old_alist_elt, Qnil))
2126 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2127 else
2128 Fsetcdr (old_alist_elt, val);
2130 /* Update some other special parameters in their special places
2131 in addition to the alist. */
2133 if (EQ (prop, Qbuffer_predicate))
2134 fset_buffer_predicate (f, val);
2136 if (! FRAME_WINDOW_P (f))
2138 if (EQ (prop, Qmenu_bar_lines))
2139 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2140 else if (EQ (prop, Qname))
2141 set_term_frame_name (f, val);
2144 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2146 if (! MINI_WINDOW_P (XWINDOW (val)))
2147 error ("Surrogate minibuffer windows must be minibuffer windows");
2149 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2150 && !EQ (val, f->minibuffer_window))
2151 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2153 /* Install the chosen minibuffer window, with proper buffer. */
2154 fset_minibuffer_window (f, val);
2158 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2159 doc: /* Return the parameters-alist of frame FRAME.
2160 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2161 The meaningful PARMs depend on the kind of frame.
2162 If FRAME is omitted, return information on the currently selected frame. */)
2163 (Lisp_Object frame)
2165 Lisp_Object alist;
2166 FRAME_PTR f;
2167 int height, width;
2168 struct gcpro gcpro1;
2170 if (NILP (frame))
2171 frame = selected_frame;
2173 CHECK_FRAME (frame);
2174 f = XFRAME (frame);
2176 if (!FRAME_LIVE_P (f))
2177 return Qnil;
2179 alist = Fcopy_alist (f->param_alist);
2180 GCPRO1 (alist);
2182 if (!FRAME_WINDOW_P (f))
2184 int fg = FRAME_FOREGROUND_PIXEL (f);
2185 int bg = FRAME_BACKGROUND_PIXEL (f);
2186 Lisp_Object elt;
2188 /* If the frame's parameter alist says the colors are
2189 unspecified and reversed, take the frame's background pixel
2190 for foreground and vice versa. */
2191 elt = Fassq (Qforeground_color, alist);
2192 if (CONSP (elt) && STRINGP (XCDR (elt)))
2194 if (strncmp (SSDATA (XCDR (elt)),
2195 unspecified_bg,
2196 SCHARS (XCDR (elt))) == 0)
2197 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2198 else if (strncmp (SSDATA (XCDR (elt)),
2199 unspecified_fg,
2200 SCHARS (XCDR (elt))) == 0)
2201 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2203 else
2204 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2205 elt = Fassq (Qbackground_color, alist);
2206 if (CONSP (elt) && STRINGP (XCDR (elt)))
2208 if (strncmp (SSDATA (XCDR (elt)),
2209 unspecified_fg,
2210 SCHARS (XCDR (elt))) == 0)
2211 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2212 else if (strncmp (SSDATA (XCDR (elt)),
2213 unspecified_bg,
2214 SCHARS (XCDR (elt))) == 0)
2215 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2217 else
2218 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2219 store_in_alist (&alist, intern ("font"),
2220 build_string (FRAME_MSDOS_P (f)
2221 ? "ms-dos"
2222 : FRAME_W32_P (f) ? "w32term"
2223 :"tty"));
2225 store_in_alist (&alist, Qname, f->name);
2226 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2227 store_in_alist (&alist, Qheight, make_number (height));
2228 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2229 store_in_alist (&alist, Qwidth, make_number (width));
2230 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2231 store_in_alist (&alist, Qminibuffer,
2232 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2233 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2234 : FRAME_MINIBUF_WINDOW (f)));
2235 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2236 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2237 store_in_alist (&alist, Qburied_buffer_list,
2238 XFRAME (frame)->buried_buffer_list);
2240 /* I think this should be done with a hook. */
2241 #ifdef HAVE_WINDOW_SYSTEM
2242 if (FRAME_WINDOW_P (f))
2243 x_report_frame_params (f, &alist);
2244 else
2245 #endif
2247 /* This ought to be correct in f->param_alist for an X frame. */
2248 Lisp_Object lines;
2249 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2250 store_in_alist (&alist, Qmenu_bar_lines, lines);
2253 UNGCPRO;
2254 return alist;
2258 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2259 doc: /* Return FRAME's value for parameter PARAMETER.
2260 If FRAME is nil, describe the currently selected frame. */)
2261 (Lisp_Object frame, Lisp_Object parameter)
2263 struct frame *f;
2264 Lisp_Object value;
2266 if (NILP (frame))
2267 frame = selected_frame;
2268 else
2269 CHECK_FRAME (frame);
2270 CHECK_SYMBOL (parameter);
2272 f = XFRAME (frame);
2273 value = Qnil;
2275 if (FRAME_LIVE_P (f))
2277 /* Avoid consing in frequent cases. */
2278 if (EQ (parameter, Qname))
2279 value = f->name;
2280 #ifdef HAVE_X_WINDOWS
2281 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2282 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2283 #endif /* HAVE_X_WINDOWS */
2284 else if (EQ (parameter, Qbackground_color)
2285 || EQ (parameter, Qforeground_color))
2287 value = Fassq (parameter, f->param_alist);
2288 if (CONSP (value))
2290 value = XCDR (value);
2291 /* Fframe_parameters puts the actual fg/bg color names,
2292 even if f->param_alist says otherwise. This is
2293 important when param_alist's notion of colors is
2294 "unspecified". We need to do the same here. */
2295 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2297 const char *color_name;
2298 ptrdiff_t csz;
2300 if (EQ (parameter, Qbackground_color))
2302 color_name = SSDATA (value);
2303 csz = SCHARS (value);
2304 if (strncmp (color_name, unspecified_bg, csz) == 0)
2305 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2306 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2307 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2309 else if (EQ (parameter, Qforeground_color))
2311 color_name = SSDATA (value);
2312 csz = SCHARS (value);
2313 if (strncmp (color_name, unspecified_fg, csz) == 0)
2314 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2315 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2316 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2320 else
2321 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2323 else if (EQ (parameter, Qdisplay_type)
2324 || EQ (parameter, Qbackground_mode))
2325 value = Fcdr (Fassq (parameter, f->param_alist));
2326 else
2327 /* FIXME: Avoid this code path at all (as well as code duplication)
2328 by sharing more code with Fframe_parameters. */
2329 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2332 return value;
2336 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2337 Smodify_frame_parameters, 2, 2, 0,
2338 doc: /* Modify the parameters of frame FRAME according to ALIST.
2339 If FRAME is nil, it defaults to the selected frame.
2340 ALIST is an alist of parameters to change and their new values.
2341 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2342 The meaningful PARMs depend on the kind of frame.
2343 Undefined PARMs are ignored, but stored in the frame's parameter list
2344 so that `frame-parameters' will return them.
2346 The value of frame parameter FOO can also be accessed
2347 as a frame-local binding for the variable FOO, if you have
2348 enabled such bindings for that variable with `make-variable-frame-local'.
2349 Note that this functionality is obsolete as of Emacs 22.2, and its
2350 use is not recommended. Explicitly check for a frame-parameter instead. */)
2351 (Lisp_Object frame, Lisp_Object alist)
2353 FRAME_PTR f;
2354 register Lisp_Object tail, prop, val;
2356 if (EQ (frame, Qnil))
2357 frame = selected_frame;
2358 CHECK_LIVE_FRAME (frame);
2359 f = XFRAME (frame);
2361 /* I think this should be done with a hook. */
2362 #ifdef HAVE_WINDOW_SYSTEM
2363 if (FRAME_WINDOW_P (f))
2364 x_set_frame_parameters (f, alist);
2365 else
2366 #endif
2367 #ifdef MSDOS
2368 if (FRAME_MSDOS_P (f))
2369 IT_set_frame_parameters (f, alist);
2370 else
2371 #endif
2374 EMACS_INT length = XFASTINT (Flength (alist));
2375 ptrdiff_t i;
2376 Lisp_Object *parms;
2377 Lisp_Object *values;
2378 USE_SAFE_ALLOCA;
2379 SAFE_ALLOCA_LISP (parms, 2 * length);
2380 values = parms + length;
2382 /* Extract parm names and values into those vectors. */
2384 i = 0;
2385 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2387 Lisp_Object elt;
2389 elt = XCAR (tail);
2390 parms[i] = Fcar (elt);
2391 values[i] = Fcdr (elt);
2392 i++;
2395 /* Now process them in reverse of specified order. */
2396 while (--i >= 0)
2398 prop = parms[i];
2399 val = values[i];
2400 store_frame_param (f, prop, val);
2402 if (EQ (prop, Qforeground_color)
2403 || EQ (prop, Qbackground_color))
2404 update_face_from_frame_parameter (f, prop, val);
2407 SAFE_FREE ();
2409 return Qnil;
2412 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2413 0, 1, 0,
2414 doc: /* Height in pixels of a line in the font in frame FRAME.
2415 If FRAME is omitted, the selected frame is used.
2416 For a terminal frame, the value is always 1. */)
2417 (Lisp_Object frame)
2419 struct frame *f;
2421 if (NILP (frame))
2422 frame = selected_frame;
2423 CHECK_FRAME (frame);
2424 f = XFRAME (frame);
2426 #ifdef HAVE_WINDOW_SYSTEM
2427 if (FRAME_WINDOW_P (f))
2428 return make_number (x_char_height (f));
2429 else
2430 #endif
2431 return make_number (1);
2435 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2436 0, 1, 0,
2437 doc: /* Width in pixels of characters in the font in frame FRAME.
2438 If FRAME is omitted, the selected frame is used.
2439 On a graphical screen, the width is the standard width of the default font.
2440 For a terminal screen, the value is always 1. */)
2441 (Lisp_Object frame)
2443 struct frame *f;
2445 if (NILP (frame))
2446 frame = selected_frame;
2447 CHECK_FRAME (frame);
2448 f = XFRAME (frame);
2450 #ifdef HAVE_WINDOW_SYSTEM
2451 if (FRAME_WINDOW_P (f))
2452 return make_number (x_char_width (f));
2453 else
2454 #endif
2455 return make_number (1);
2458 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2459 Sframe_pixel_height, 0, 1, 0,
2460 doc: /* Return a FRAME's height in pixels.
2461 If FRAME is omitted, the selected frame is used. The exact value
2462 of the result depends on the window-system and toolkit in use:
2464 In the Gtk+ version of Emacs, it includes only any window (including
2465 the minibuffer or echo area), mode line, and header line. It does not
2466 include the tool bar or menu bar.
2468 With the Motif or Lucid toolkits, it also includes the tool bar (but
2469 not the menu bar).
2471 In a graphical version with no toolkit, it includes both the tool bar
2472 and menu bar.
2474 For a text terminal, it includes the menu bar. In this case, the
2475 result is really in characters rather than pixels (i.e., is identical
2476 to `frame-height'). */)
2477 (Lisp_Object frame)
2479 struct frame *f;
2481 if (NILP (frame))
2482 frame = selected_frame;
2483 CHECK_FRAME (frame);
2484 f = XFRAME (frame);
2486 #ifdef HAVE_WINDOW_SYSTEM
2487 if (FRAME_WINDOW_P (f))
2488 return make_number (x_pixel_height (f));
2489 else
2490 #endif
2491 return make_number (FRAME_LINES (f));
2494 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2495 Sframe_pixel_width, 0, 1, 0,
2496 doc: /* Return FRAME's width in pixels.
2497 For a terminal frame, the result really gives the width in characters.
2498 If FRAME is omitted, the selected frame is used. */)
2499 (Lisp_Object frame)
2501 struct frame *f;
2503 if (NILP (frame))
2504 frame = selected_frame;
2505 CHECK_FRAME (frame);
2506 f = XFRAME (frame);
2508 #ifdef HAVE_WINDOW_SYSTEM
2509 if (FRAME_WINDOW_P (f))
2510 return make_number (x_pixel_width (f));
2511 else
2512 #endif
2513 return make_number (FRAME_COLS (f));
2516 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2517 Stool_bar_pixel_width, 0, 1, 0,
2518 doc: /* Return width in pixels of FRAME's tool bar.
2519 The result is greater than zero only when the tool bar is on the left
2520 or right side of FRAME. If FRAME is omitted, the selected frame is
2521 used. */)
2522 (Lisp_Object frame)
2524 if (NILP (frame))
2525 frame = selected_frame;
2526 CHECK_FRAME (frame);
2528 #ifdef FRAME_TOOLBAR_WIDTH
2529 if (FRAME_WINDOW_P (XFRAME (frame)))
2530 return make_number (FRAME_TOOLBAR_WIDTH (XFRAME (frame)));
2531 #endif
2532 return make_number (0);
2535 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2536 doc: /* Specify that the frame FRAME has LINES lines.
2537 Optional third arg non-nil means that redisplay should use LINES lines
2538 but that the idea of the actual height of the frame should not be changed. */)
2539 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend)
2541 register struct frame *f;
2543 CHECK_TYPE_RANGED_INTEGER (int, lines);
2544 if (NILP (frame))
2545 frame = selected_frame;
2546 CHECK_LIVE_FRAME (frame);
2547 f = XFRAME (frame);
2549 /* I think this should be done with a hook. */
2550 #ifdef HAVE_WINDOW_SYSTEM
2551 if (FRAME_WINDOW_P (f))
2553 if (XINT (lines) != FRAME_LINES (f))
2554 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2555 do_pending_window_change (0);
2557 else
2558 #endif
2559 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2560 return Qnil;
2563 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2564 doc: /* Specify that the frame FRAME has COLS columns.
2565 Optional third arg non-nil means that redisplay should use COLS columns
2566 but that the idea of the actual width of the frame should not be changed. */)
2567 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2569 register struct frame *f;
2570 CHECK_TYPE_RANGED_INTEGER (int, cols);
2571 if (NILP (frame))
2572 frame = selected_frame;
2573 CHECK_LIVE_FRAME (frame);
2574 f = XFRAME (frame);
2576 /* I think this should be done with a hook. */
2577 #ifdef HAVE_WINDOW_SYSTEM
2578 if (FRAME_WINDOW_P (f))
2580 if (XINT (cols) != FRAME_COLS (f))
2581 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2582 do_pending_window_change (0);
2584 else
2585 #endif
2586 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2587 return Qnil;
2590 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2591 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2592 (Lisp_Object frame, Lisp_Object cols, Lisp_Object rows)
2594 register struct frame *f;
2596 CHECK_LIVE_FRAME (frame);
2597 CHECK_TYPE_RANGED_INTEGER (int, cols);
2598 CHECK_TYPE_RANGED_INTEGER (int, rows);
2599 f = XFRAME (frame);
2601 /* I think this should be done with a hook. */
2602 #ifdef HAVE_WINDOW_SYSTEM
2603 if (FRAME_WINDOW_P (f))
2605 if (XINT (rows) != FRAME_LINES (f)
2606 || XINT (cols) != FRAME_COLS (f)
2607 || f->new_text_lines || f->new_text_cols)
2608 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2609 do_pending_window_change (0);
2611 else
2612 #endif
2613 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2615 return Qnil;
2618 DEFUN ("set-frame-position", Fset_frame_position,
2619 Sset_frame_position, 3, 3, 0,
2620 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2621 This is actually the position of the upper left corner of the frame.
2622 Negative values for XOFFSET or YOFFSET are interpreted relative to
2623 the rightmost or bottommost possible position (that stays within the screen). */)
2624 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2626 register struct frame *f;
2628 CHECK_LIVE_FRAME (frame);
2629 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2630 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2631 f = XFRAME (frame);
2633 /* I think this should be done with a hook. */
2634 #ifdef HAVE_WINDOW_SYSTEM
2635 if (FRAME_WINDOW_P (f))
2636 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2637 #endif
2639 return Qt;
2643 /***********************************************************************
2644 Frame Parameters
2645 ***********************************************************************/
2647 /* Connect the frame-parameter names for X frames
2648 to the ways of passing the parameter values to the window system.
2650 The name of a parameter, as a Lisp symbol,
2651 has an `x-frame-parameter' property which is an integer in Lisp
2652 that is an index in this table. */
2654 struct frame_parm_table {
2655 const char *name;
2656 Lisp_Object *variable;
2659 static const struct frame_parm_table frame_parms[] =
2661 {"auto-raise", &Qauto_raise},
2662 {"auto-lower", &Qauto_lower},
2663 {"background-color", 0},
2664 {"border-color", &Qborder_color},
2665 {"border-width", &Qborder_width},
2666 {"cursor-color", &Qcursor_color},
2667 {"cursor-type", &Qcursor_type},
2668 {"font", 0},
2669 {"foreground-color", 0},
2670 {"icon-name", &Qicon_name},
2671 {"icon-type", &Qicon_type},
2672 {"internal-border-width", &Qinternal_border_width},
2673 {"menu-bar-lines", &Qmenu_bar_lines},
2674 {"mouse-color", &Qmouse_color},
2675 {"name", &Qname},
2676 {"scroll-bar-width", &Qscroll_bar_width},
2677 {"title", &Qtitle},
2678 {"unsplittable", &Qunsplittable},
2679 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2680 {"visibility", &Qvisibility},
2681 {"tool-bar-lines", &Qtool_bar_lines},
2682 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2683 {"scroll-bar-background", &Qscroll_bar_background},
2684 {"screen-gamma", &Qscreen_gamma},
2685 {"line-spacing", &Qline_spacing},
2686 {"left-fringe", &Qleft_fringe},
2687 {"right-fringe", &Qright_fringe},
2688 {"wait-for-wm", &Qwait_for_wm},
2689 {"fullscreen", &Qfullscreen},
2690 {"font-backend", &Qfont_backend},
2691 {"alpha", &Qalpha},
2692 {"sticky", &Qsticky},
2693 {"tool-bar-position", &Qtool_bar_position},
2696 #ifdef WINDOWSNT
2698 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2699 wanted positions of the WM window (not Emacs window).
2700 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2701 window (FRAME_X_WINDOW).
2704 void
2705 x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
2707 int newwidth = FRAME_COLS (f);
2708 int newheight = FRAME_LINES (f);
2709 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2711 *top_pos = f->top_pos;
2712 *left_pos = f->left_pos;
2714 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2716 int ph;
2718 ph = x_display_pixel_height (dpyinfo);
2719 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2720 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2721 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2722 *top_pos = 0;
2725 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2727 int pw;
2729 pw = x_display_pixel_width (dpyinfo);
2730 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2731 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2732 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2733 *left_pos = 0;
2736 *width = newwidth;
2737 *height = newheight;
2740 #endif /* WINDOWSNT */
2742 #ifdef HAVE_WINDOW_SYSTEM
2744 /* Change the parameters of frame F as specified by ALIST.
2745 If a parameter is not specially recognized, do nothing special;
2746 otherwise call the `x_set_...' function for that parameter.
2747 Except for certain geometry properties, always call store_frame_param
2748 to store the new value in the parameter alist. */
2750 void
2751 x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2753 Lisp_Object tail;
2755 /* If both of these parameters are present, it's more efficient to
2756 set them both at once. So we wait until we've looked at the
2757 entire list before we set them. */
2758 int width, height;
2760 /* Same here. */
2761 Lisp_Object left, top;
2763 /* Same with these. */
2764 Lisp_Object icon_left, icon_top;
2766 /* Record in these vectors all the parms specified. */
2767 Lisp_Object *parms;
2768 Lisp_Object *values;
2769 ptrdiff_t i, p;
2770 int left_no_change = 0, top_no_change = 0;
2771 int icon_left_no_change = 0, icon_top_no_change = 0;
2772 int size_changed = 0;
2773 struct gcpro gcpro1, gcpro2;
2775 i = 0;
2776 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2777 i++;
2779 parms = alloca (i * sizeof *parms);
2780 values = alloca (i * sizeof *values);
2782 /* Extract parm names and values into those vectors. */
2784 i = 0;
2785 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2787 Lisp_Object elt;
2789 elt = XCAR (tail);
2790 parms[i] = Fcar (elt);
2791 values[i] = Fcdr (elt);
2792 i++;
2794 /* TAIL and ALIST are not used again below here. */
2795 alist = tail = Qnil;
2797 GCPRO2 (*parms, *values);
2798 gcpro1.nvars = i;
2799 gcpro2.nvars = i;
2801 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2802 because their values appear in VALUES and strings are not valid. */
2803 top = left = Qunbound;
2804 icon_left = icon_top = Qunbound;
2806 /* Provide default values for HEIGHT and WIDTH. */
2807 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2808 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2810 /* Process foreground_color and background_color before anything else.
2811 They are independent of other properties, but other properties (e.g.,
2812 cursor_color) are dependent upon them. */
2813 /* Process default font as well, since fringe widths depends on it. */
2814 for (p = 0; p < i; p++)
2816 Lisp_Object prop, val;
2818 prop = parms[p];
2819 val = values[p];
2820 if (EQ (prop, Qforeground_color)
2821 || EQ (prop, Qbackground_color)
2822 || EQ (prop, Qfont))
2824 register Lisp_Object param_index, old_value;
2826 old_value = get_frame_param (f, prop);
2827 if (NILP (Fequal (val, old_value)))
2829 store_frame_param (f, prop, val);
2831 param_index = Fget (prop, Qx_frame_parameter);
2832 if (NATNUMP (param_index)
2833 && (XFASTINT (param_index)
2834 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2835 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2836 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2841 /* Now process them in reverse of specified order. */
2842 while (i-- != 0)
2844 Lisp_Object prop, val;
2846 prop = parms[i];
2847 val = values[i];
2849 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
2851 size_changed = 1;
2852 width = XFASTINT (val);
2854 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
2856 size_changed = 1;
2857 height = XFASTINT (val);
2859 else if (EQ (prop, Qtop))
2860 top = val;
2861 else if (EQ (prop, Qleft))
2862 left = val;
2863 else if (EQ (prop, Qicon_top))
2864 icon_top = val;
2865 else if (EQ (prop, Qicon_left))
2866 icon_left = val;
2867 else if (EQ (prop, Qforeground_color)
2868 || EQ (prop, Qbackground_color)
2869 || EQ (prop, Qfont))
2870 /* Processed above. */
2871 continue;
2872 else
2874 register Lisp_Object param_index, old_value;
2876 old_value = get_frame_param (f, prop);
2878 store_frame_param (f, prop, val);
2880 param_index = Fget (prop, Qx_frame_parameter);
2881 if (NATNUMP (param_index)
2882 && (XFASTINT (param_index)
2883 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2884 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2885 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2889 /* Don't die if just one of these was set. */
2890 if (EQ (left, Qunbound))
2892 left_no_change = 1;
2893 if (f->left_pos < 0)
2894 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
2895 else
2896 XSETINT (left, f->left_pos);
2898 if (EQ (top, Qunbound))
2900 top_no_change = 1;
2901 if (f->top_pos < 0)
2902 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
2903 else
2904 XSETINT (top, f->top_pos);
2907 /* If one of the icon positions was not set, preserve or default it. */
2908 if (! TYPE_RANGED_INTEGERP (int, icon_left))
2910 icon_left_no_change = 1;
2911 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2912 if (NILP (icon_left))
2913 XSETINT (icon_left, 0);
2915 if (! TYPE_RANGED_INTEGERP (int, icon_top))
2917 icon_top_no_change = 1;
2918 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2919 if (NILP (icon_top))
2920 XSETINT (icon_top, 0);
2923 /* Don't set these parameters unless they've been explicitly
2924 specified. The window might be mapped or resized while we're in
2925 this function, and we don't want to override that unless the lisp
2926 code has asked for it.
2928 Don't set these parameters unless they actually differ from the
2929 window's current parameters; the window may not actually exist
2930 yet. */
2932 Lisp_Object frame;
2934 check_frame_size (f, &height, &width);
2936 XSETFRAME (frame, f);
2938 if (size_changed
2939 && (width != FRAME_COLS (f)
2940 || height != FRAME_LINES (f)
2941 || f->new_text_lines || f->new_text_cols))
2942 Fset_frame_size (frame, make_number (width), make_number (height));
2944 if ((!NILP (left) || !NILP (top))
2945 && ! (left_no_change && top_no_change)
2946 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2947 && NUMBERP (top) && XINT (top) == f->top_pos))
2949 int leftpos = 0;
2950 int toppos = 0;
2952 /* Record the signs. */
2953 f->size_hint_flags &= ~ (XNegative | YNegative);
2954 if (EQ (left, Qminus))
2955 f->size_hint_flags |= XNegative;
2956 else if (TYPE_RANGED_INTEGERP (int, left))
2958 leftpos = XINT (left);
2959 if (leftpos < 0)
2960 f->size_hint_flags |= XNegative;
2962 else if (CONSP (left) && EQ (XCAR (left), Qminus)
2963 && CONSP (XCDR (left))
2964 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
2966 leftpos = - XINT (XCAR (XCDR (left)));
2967 f->size_hint_flags |= XNegative;
2969 else if (CONSP (left) && EQ (XCAR (left), Qplus)
2970 && CONSP (XCDR (left))
2971 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
2973 leftpos = XINT (XCAR (XCDR (left)));
2976 if (EQ (top, Qminus))
2977 f->size_hint_flags |= YNegative;
2978 else if (TYPE_RANGED_INTEGERP (int, top))
2980 toppos = XINT (top);
2981 if (toppos < 0)
2982 f->size_hint_flags |= YNegative;
2984 else if (CONSP (top) && EQ (XCAR (top), Qminus)
2985 && CONSP (XCDR (top))
2986 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
2988 toppos = - XINT (XCAR (XCDR (top)));
2989 f->size_hint_flags |= YNegative;
2991 else if (CONSP (top) && EQ (XCAR (top), Qplus)
2992 && CONSP (XCDR (top))
2993 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
2995 toppos = XINT (XCAR (XCDR (top)));
2999 /* Store the numeric value of the position. */
3000 f->top_pos = toppos;
3001 f->left_pos = leftpos;
3003 f->win_gravity = NorthWestGravity;
3005 /* Actually set that position, and convert to absolute. */
3006 x_set_offset (f, leftpos, toppos, -1);
3009 if ((!NILP (icon_left) || !NILP (icon_top))
3010 && ! (icon_left_no_change && icon_top_no_change))
3011 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3014 UNGCPRO;
3018 /* Insert a description of internally-recorded parameters of frame X
3019 into the parameter alist *ALISTPTR that is to be given to the user.
3020 Only parameters that are specific to the X window system
3021 and whose values are not correctly recorded in the frame's
3022 param_alist need to be considered here. */
3024 void
3025 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3027 char buf[16];
3028 Lisp_Object tem;
3029 unsigned long w;
3031 /* Represent negative positions (off the top or left screen edge)
3032 in a way that Fmodify_frame_parameters will understand correctly. */
3033 XSETINT (tem, f->left_pos);
3034 if (f->left_pos >= 0)
3035 store_in_alist (alistptr, Qleft, tem);
3036 else
3037 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3039 XSETINT (tem, f->top_pos);
3040 if (f->top_pos >= 0)
3041 store_in_alist (alistptr, Qtop, tem);
3042 else
3043 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3045 store_in_alist (alistptr, Qborder_width,
3046 make_number (f->border_width));
3047 store_in_alist (alistptr, Qinternal_border_width,
3048 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3049 store_in_alist (alistptr, Qleft_fringe,
3050 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3051 store_in_alist (alistptr, Qright_fringe,
3052 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3053 store_in_alist (alistptr, Qscroll_bar_width,
3054 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3055 ? make_number (0)
3056 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3057 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3058 /* nil means "use default width"
3059 for non-toolkit scroll bar.
3060 ruler-mode.el depends on this. */
3061 : Qnil));
3062 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3063 MS-Windows it returns a value whose type is HANDLE, which is
3064 actually a pointer. Explicit casting avoids compiler
3065 warnings. */
3066 w = (unsigned long) FRAME_X_WINDOW (f);
3067 store_in_alist (alistptr, Qwindow_id,
3068 make_formatted_string (buf, "%lu", w));
3069 #ifdef HAVE_X_WINDOWS
3070 #ifdef USE_X_TOOLKIT
3071 /* Tooltip frame may not have this widget. */
3072 if (FRAME_X_OUTPUT (f)->widget)
3073 #endif
3074 w = (unsigned long) FRAME_OUTER_WINDOW (f);
3075 store_in_alist (alistptr, Qouter_window_id,
3076 make_formatted_string (buf, "%lu", w));
3077 #endif
3078 store_in_alist (alistptr, Qicon_name, f->icon_name);
3079 FRAME_SAMPLE_VISIBILITY (f);
3080 store_in_alist (alistptr, Qvisibility,
3081 (FRAME_VISIBLE_P (f) ? Qt
3082 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3083 store_in_alist (alistptr, Qdisplay,
3084 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3086 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3087 tem = Qnil;
3088 else
3089 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3090 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3091 store_in_alist (alistptr, Qparent_id, tem);
3092 store_in_alist (alistptr, Qtool_bar_position, f->tool_bar_position);
3096 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3097 the previous value of that parameter, NEW_VALUE is the new value. */
3099 void
3100 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3102 if (NILP (new_value))
3103 f->want_fullscreen = FULLSCREEN_NONE;
3104 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3105 f->want_fullscreen = FULLSCREEN_BOTH;
3106 else if (EQ (new_value, Qfullwidth))
3107 f->want_fullscreen = FULLSCREEN_WIDTH;
3108 else if (EQ (new_value, Qfullheight))
3109 f->want_fullscreen = FULLSCREEN_HEIGHT;
3110 else if (EQ (new_value, Qmaximized))
3111 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3113 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3114 FRAME_TERMINAL (f)->fullscreen_hook (f);
3118 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3119 the previous value of that parameter, NEW_VALUE is the new value. */
3121 void
3122 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3124 if (NILP (new_value))
3125 f->extra_line_spacing = 0;
3126 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3127 f->extra_line_spacing = XFASTINT (new_value);
3128 else
3129 signal_error ("Invalid line-spacing", new_value);
3130 if (FRAME_VISIBLE_P (f))
3131 redraw_frame (f);
3135 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3136 the previous value of that parameter, NEW_VALUE is the new value. */
3138 void
3139 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3141 Lisp_Object bgcolor;
3143 if (NILP (new_value))
3144 f->gamma = 0;
3145 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3146 /* The value 0.4545 is the normal viewing gamma. */
3147 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3148 else
3149 signal_error ("Invalid screen-gamma", new_value);
3151 /* Apply the new gamma value to the frame background. */
3152 bgcolor = Fassq (Qbackground_color, f->param_alist);
3153 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3155 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3156 if (NATNUMP (parm_index)
3157 && (XFASTINT (parm_index)
3158 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3159 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3160 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3161 (f, bgcolor, Qnil);
3164 Fclear_face_cache (Qnil);
3168 void
3169 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3171 Lisp_Object font_object;
3172 int fontset = -1;
3173 #ifdef HAVE_X_WINDOWS
3174 Lisp_Object font_param = arg;
3175 #endif
3177 /* Set the frame parameter back to the old value because we may
3178 fail to use ARG as the new parameter value. */
3179 store_frame_param (f, Qfont, oldval);
3181 /* ARG is a fontset name, a font name, a cons of fontset name and a
3182 font object, or a font object. In the last case, this function
3183 never fail. */
3184 if (STRINGP (arg))
3186 fontset = fs_query_fontset (arg, 0);
3187 if (fontset < 0)
3189 font_object = font_open_by_name (f, arg);
3190 if (NILP (font_object))
3191 error ("Font `%s' is not defined", SSDATA (arg));
3192 arg = AREF (font_object, FONT_NAME_INDEX);
3194 else if (fontset > 0)
3196 font_object = font_open_by_name (f, fontset_ascii (fontset));
3197 if (NILP (font_object))
3198 error ("Font `%s' is not defined", SDATA (arg));
3199 arg = AREF (font_object, FONT_NAME_INDEX);
3201 else
3202 error ("The default fontset can't be used for a frame font");
3204 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3206 /* This is the case that the ASCII font of F's fontset XCAR
3207 (arg) is changed to the font XCDR (arg) by
3208 `set-fontset-font'. */
3209 fontset = fs_query_fontset (XCAR (arg), 0);
3210 if (fontset < 0)
3211 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3212 font_object = XCDR (arg);
3213 arg = AREF (font_object, FONT_NAME_INDEX);
3214 #ifdef HAVE_X_WINDOWS
3215 font_param = Ffont_get (font_object, QCname);
3216 #endif
3218 else if (FONT_OBJECT_P (arg))
3220 font_object = arg;
3221 #ifdef HAVE_X_WINDOWS
3222 font_param = Ffont_get (font_object, QCname);
3223 #endif
3224 /* This is to store the XLFD font name in the frame parameter for
3225 backward compatibility. We should store the font-object
3226 itself in the future. */
3227 arg = AREF (font_object, FONT_NAME_INDEX);
3228 fontset = FRAME_FONTSET (f);
3229 /* Check if we can use the current fontset. If not, set FONTSET
3230 to -1 to generate a new fontset from FONT-OBJECT. */
3231 if (fontset >= 0)
3233 Lisp_Object ascii_font = fontset_ascii (fontset);
3234 Lisp_Object spec = font_spec_from_name (ascii_font);
3236 if (! font_match_p (spec, font_object))
3237 fontset = -1;
3240 else
3241 signal_error ("Invalid font", arg);
3243 if (! NILP (Fequal (font_object, oldval)))
3244 return;
3246 x_new_font (f, font_object, fontset);
3247 store_frame_param (f, Qfont, arg);
3248 #ifdef HAVE_X_WINDOWS
3249 store_frame_param (f, Qfont_param, font_param);
3250 #endif
3251 /* Recalculate toolbar height. */
3252 f->n_tool_bar_rows = 0;
3253 /* Ensure we redraw it. */
3254 clear_current_matrices (f);
3256 recompute_basic_faces (f);
3258 do_pending_window_change (0);
3260 /* We used to call face-set-after-frame-default here, but it leads to
3261 recursive calls (since that function can set the `default' face's
3262 font which in turns changes the frame's `font' parameter).
3263 Also I don't know what this call is meant to do, but it seems the
3264 wrong way to do it anyway (it does a lot more work than what seems
3265 reasonable in response to a change to `font'). */
3269 void
3270 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3272 if (! NILP (new_value)
3273 && !CONSP (new_value))
3275 char *p0, *p1;
3277 CHECK_STRING (new_value);
3278 p0 = p1 = SSDATA (new_value);
3279 new_value = Qnil;
3280 while (*p0)
3282 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3283 if (p0 < p1)
3284 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3285 new_value);
3286 if (*p1)
3288 int c;
3290 while ((c = *++p1) && c_isspace (c));
3292 p0 = p1;
3294 new_value = Fnreverse (new_value);
3297 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3298 return;
3300 if (FRAME_FONT (f))
3301 free_all_realized_faces (Qnil);
3303 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3304 if (NILP (new_value))
3306 if (NILP (old_value))
3307 error ("No font backend available");
3308 font_update_drivers (f, old_value);
3309 error ("None of specified font backends are available");
3311 store_frame_param (f, Qfont_backend, new_value);
3313 if (FRAME_FONT (f))
3315 Lisp_Object frame;
3317 XSETFRAME (frame, f);
3318 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3319 ++face_change_count;
3320 ++windows_or_buffers_changed;
3325 void
3326 x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3328 compute_fringe_widths (f, 1);
3329 #ifdef HAVE_X_WINDOWS
3330 /* Must adjust this so window managers report correct number of columns. */
3331 if (FRAME_X_WINDOW (f) != 0)
3332 x_wm_set_size_hint (f, 0, 0);
3333 #endif
3336 void
3337 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3339 CHECK_TYPE_RANGED_INTEGER (int, arg);
3341 if (XINT (arg) == f->border_width)
3342 return;
3344 if (FRAME_X_WINDOW (f) != 0)
3345 error ("Cannot change the border width of a frame");
3347 f->border_width = XINT (arg);
3350 void
3351 x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3353 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3355 CHECK_TYPE_RANGED_INTEGER (int, arg);
3356 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3357 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3358 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3360 #ifdef USE_X_TOOLKIT
3361 if (FRAME_X_OUTPUT (f)->edit_widget)
3362 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3363 #endif
3365 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3366 return;
3368 if (FRAME_X_WINDOW (f) != 0)
3370 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3371 SET_FRAME_GARBAGED (f);
3372 do_pending_window_change (0);
3374 else
3375 SET_FRAME_GARBAGED (f);
3378 void
3379 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3381 Lisp_Object frame;
3382 XSETFRAME (frame, f);
3384 if (NILP (value))
3385 Fmake_frame_invisible (frame, Qt);
3386 else if (EQ (value, Qicon))
3387 Ficonify_frame (frame);
3388 else
3389 Fmake_frame_visible (frame);
3392 void
3393 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3395 f->auto_raise = !EQ (Qnil, arg);
3398 void
3399 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3401 f->auto_lower = !EQ (Qnil, arg);
3404 void
3405 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3407 f->no_split = !NILP (arg);
3410 void
3411 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3413 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3414 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3415 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3416 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3418 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3419 = (NILP (arg)
3420 ? vertical_scroll_bar_none
3421 : EQ (Qleft, arg)
3422 ? vertical_scroll_bar_left
3423 : EQ (Qright, arg)
3424 ? vertical_scroll_bar_right
3425 : EQ (Qleft, Vdefault_frame_scroll_bars)
3426 ? vertical_scroll_bar_left
3427 : EQ (Qright, Vdefault_frame_scroll_bars)
3428 ? vertical_scroll_bar_right
3429 : vertical_scroll_bar_none);
3431 /* We set this parameter before creating the X window for the
3432 frame, so we can get the geometry right from the start.
3433 However, if the window hasn't been created yet, we shouldn't
3434 call x_set_window_size. */
3435 if (FRAME_X_WINDOW (f))
3436 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3437 do_pending_window_change (0);
3441 void
3442 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3444 int wid = FRAME_COLUMN_WIDTH (f);
3446 if (NILP (arg))
3448 x_set_scroll_bar_default_width (f);
3450 if (FRAME_X_WINDOW (f))
3451 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3452 do_pending_window_change (0);
3454 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3455 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3457 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3458 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3460 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3461 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3462 if (FRAME_X_WINDOW (f))
3463 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3464 do_pending_window_change (0);
3467 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3468 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3469 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3474 /* Return non-nil if frame F wants a bitmap icon. */
3476 Lisp_Object
3477 x_icon_type (FRAME_PTR f)
3479 Lisp_Object tem;
3481 tem = assq_no_quit (Qicon_type, f->param_alist);
3482 if (CONSP (tem))
3483 return XCDR (tem);
3484 else
3485 return Qnil;
3488 void
3489 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3491 double alpha = 1.0;
3492 double newval[2];
3493 int i;
3494 Lisp_Object item;
3496 for (i = 0; i < 2; i++)
3498 newval[i] = 1.0;
3499 if (CONSP (arg))
3501 item = CAR (arg);
3502 arg = CDR (arg);
3504 else
3505 item = arg;
3507 if (NILP (item))
3508 alpha = - 1.0;
3509 else if (FLOATP (item))
3511 alpha = XFLOAT_DATA (item);
3512 if (alpha < 0.0 || 1.0 < alpha)
3513 args_out_of_range (make_float (0.0), make_float (1.0));
3515 else if (INTEGERP (item))
3517 EMACS_INT ialpha = XINT (item);
3518 if (ialpha < 0 || 100 < ialpha)
3519 args_out_of_range (make_number (0), make_number (100));
3520 else
3521 alpha = ialpha / 100.0;
3523 else
3524 wrong_type_argument (Qnumberp, item);
3525 newval[i] = alpha;
3528 for (i = 0; i < 2; i++)
3529 f->alpha[i] = newval[i];
3531 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3532 BLOCK_INPUT;
3533 x_set_frame_alpha (f);
3534 UNBLOCK_INPUT;
3535 #endif
3537 return;
3541 /* Subroutines of creating an X frame. */
3543 /* Make sure that Vx_resource_name is set to a reasonable value.
3544 Fix it up, or set it to `emacs' if it is too hopeless. */
3546 void
3547 validate_x_resource_name (void)
3549 ptrdiff_t len = 0;
3550 /* Number of valid characters in the resource name. */
3551 ptrdiff_t good_count = 0;
3552 /* Number of invalid characters in the resource name. */
3553 ptrdiff_t bad_count = 0;
3554 Lisp_Object new;
3555 ptrdiff_t i;
3557 if (!STRINGP (Vx_resource_class))
3558 Vx_resource_class = build_string (EMACS_CLASS);
3560 if (STRINGP (Vx_resource_name))
3562 unsigned char *p = SDATA (Vx_resource_name);
3564 len = SBYTES (Vx_resource_name);
3566 /* Only letters, digits, - and _ are valid in resource names.
3567 Count the valid characters and count the invalid ones. */
3568 for (i = 0; i < len; i++)
3570 int c = p[i];
3571 if (! ((c >= 'a' && c <= 'z')
3572 || (c >= 'A' && c <= 'Z')
3573 || (c >= '0' && c <= '9')
3574 || c == '-' || c == '_'))
3575 bad_count++;
3576 else
3577 good_count++;
3580 else
3581 /* Not a string => completely invalid. */
3582 bad_count = 5, good_count = 0;
3584 /* If name is valid already, return. */
3585 if (bad_count == 0)
3586 return;
3588 /* If name is entirely invalid, or nearly so, or is so implausibly
3589 large that alloca might not work, use `emacs'. */
3590 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3592 Vx_resource_name = build_string ("emacs");
3593 return;
3596 /* Name is partly valid. Copy it and replace the invalid characters
3597 with underscores. */
3599 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3601 for (i = 0; i < len; i++)
3603 int c = SREF (new, i);
3604 if (! ((c >= 'a' && c <= 'z')
3605 || (c >= 'A' && c <= 'Z')
3606 || (c >= '0' && c <= '9')
3607 || c == '-' || c == '_'))
3608 SSET (new, i, '_');
3613 extern char *x_get_string_resource (XrmDatabase, const char *, const char *);
3614 extern Display_Info *check_x_display_info (Lisp_Object);
3617 /* Get specified attribute from resource database RDB.
3618 See Fx_get_resource below for other parameters. */
3620 static Lisp_Object
3621 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3623 register char *value;
3624 char *name_key;
3625 char *class_key;
3627 CHECK_STRING (attribute);
3628 CHECK_STRING (class);
3630 if (!NILP (component))
3631 CHECK_STRING (component);
3632 if (!NILP (subclass))
3633 CHECK_STRING (subclass);
3634 if (NILP (component) != NILP (subclass))
3635 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3637 validate_x_resource_name ();
3639 /* Allocate space for the components, the dots which separate them,
3640 and the final '\0'. Make them big enough for the worst case. */
3641 name_key = alloca (SBYTES (Vx_resource_name)
3642 + (STRINGP (component)
3643 ? SBYTES (component) : 0)
3644 + SBYTES (attribute)
3645 + 3);
3647 class_key = alloca (SBYTES (Vx_resource_class)
3648 + SBYTES (class)
3649 + (STRINGP (subclass)
3650 ? SBYTES (subclass) : 0)
3651 + 3);
3653 /* Start with emacs.FRAMENAME for the name (the specific one)
3654 and with `Emacs' for the class key (the general one). */
3655 strcpy (name_key, SSDATA (Vx_resource_name));
3656 strcpy (class_key, SSDATA (Vx_resource_class));
3658 strcat (class_key, ".");
3659 strcat (class_key, SSDATA (class));
3661 if (!NILP (component))
3663 strcat (class_key, ".");
3664 strcat (class_key, SSDATA (subclass));
3666 strcat (name_key, ".");
3667 strcat (name_key, SSDATA (component));
3670 strcat (name_key, ".");
3671 strcat (name_key, SSDATA (attribute));
3673 value = x_get_string_resource (rdb, name_key, class_key);
3675 if (value != (char *) 0 && *value)
3676 return build_string (value);
3677 else
3678 return Qnil;
3682 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3683 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3684 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3685 class, where INSTANCE is the name under which Emacs was invoked, or
3686 the name specified by the `-name' or `-rn' command-line arguments.
3688 The optional arguments COMPONENT and SUBCLASS add to the key and the
3689 class, respectively. You must specify both of them or neither.
3690 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3691 and the class is `Emacs.CLASS.SUBCLASS'. */)
3692 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3694 #ifdef HAVE_X_WINDOWS
3695 check_x ();
3696 #endif
3698 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3699 attribute, class, component, subclass);
3702 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3704 Lisp_Object
3705 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3707 return xrdb_get_resource (dpyinfo->xrdb,
3708 attribute, class, component, subclass);
3711 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3712 /* Used when C code wants a resource value. */
3713 /* Called from oldXMenu/Create.c. */
3714 char *
3715 x_get_resource_string (const char *attribute, const char *class)
3717 char *result;
3718 struct frame *sf = SELECTED_FRAME ();
3719 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
3720 USE_SAFE_ALLOCA;
3722 /* Allocate space for the components, the dots which separate them,
3723 and the final '\0'. */
3724 char *name_key = SAFE_ALLOCA (invocation_namelen + strlen (attribute) + 2);
3725 char *class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2);
3727 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
3728 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3730 result = x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3731 name_key, class_key);
3732 SAFE_FREE ();
3733 return result;
3735 #endif
3737 /* Return the value of parameter PARAM.
3739 First search ALIST, then Vdefault_frame_alist, then the X defaults
3740 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3742 Convert the resource to the type specified by desired_type.
3744 If no default is specified, return Qunbound. If you call
3745 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3746 and don't let it get stored in any Lisp-visible variables! */
3748 Lisp_Object
3749 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
3750 const char *attribute, const char *class, enum resource_types type)
3752 register Lisp_Object tem;
3754 tem = Fassq (param, alist);
3756 if (!NILP (tem))
3758 /* If we find this parm in ALIST, clear it out
3759 so that it won't be "left over" at the end. */
3760 Lisp_Object tail;
3761 XSETCAR (tem, Qnil);
3762 /* In case the parameter appears more than once in the alist,
3763 clear it out. */
3764 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3765 if (CONSP (XCAR (tail))
3766 && EQ (XCAR (XCAR (tail)), param))
3767 XSETCAR (XCAR (tail), Qnil);
3769 else
3770 tem = Fassq (param, Vdefault_frame_alist);
3772 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3773 look in the X resources. */
3774 if (EQ (tem, Qnil))
3776 if (attribute && dpyinfo)
3778 tem = display_x_get_resource (dpyinfo,
3779 build_string (attribute),
3780 build_string (class),
3781 Qnil, Qnil);
3783 if (NILP (tem))
3784 return Qunbound;
3786 switch (type)
3788 case RES_TYPE_NUMBER:
3789 return make_number (atoi (SSDATA (tem)));
3791 case RES_TYPE_BOOLEAN_NUMBER:
3792 if (!strcmp (SSDATA (tem), "on")
3793 || !strcmp (SSDATA (tem), "true"))
3794 return make_number (1);
3795 return make_number (atoi (SSDATA (tem)));
3796 break;
3798 case RES_TYPE_FLOAT:
3799 return make_float (atof (SSDATA (tem)));
3801 case RES_TYPE_BOOLEAN:
3802 tem = Fdowncase (tem);
3803 if (!strcmp (SSDATA (tem), "on")
3804 #ifdef HAVE_NS
3805 || !strcmp (SSDATA (tem), "yes")
3806 #endif
3807 || !strcmp (SSDATA (tem), "true"))
3808 return Qt;
3809 else
3810 return Qnil;
3812 case RES_TYPE_STRING:
3813 return tem;
3815 case RES_TYPE_SYMBOL:
3816 /* As a special case, we map the values `true' and `on'
3817 to Qt, and `false' and `off' to Qnil. */
3819 Lisp_Object lower;
3820 lower = Fdowncase (tem);
3821 if (!strcmp (SSDATA (lower), "on")
3822 #ifdef HAVE_NS
3823 || !strcmp (SSDATA (lower), "yes")
3824 #endif
3825 || !strcmp (SSDATA (lower), "true"))
3826 return Qt;
3827 else if (!strcmp (SSDATA (lower), "off")
3828 #ifdef HAVE_NS
3829 || !strcmp (SSDATA (lower), "no")
3830 #endif
3831 || !strcmp (SSDATA (lower), "false"))
3832 return Qnil;
3833 else
3834 return Fintern (tem, Qnil);
3837 default:
3838 emacs_abort ();
3841 else
3842 return Qunbound;
3844 return Fcdr (tem);
3847 static Lisp_Object
3848 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
3849 const char *attribute, const char *class,
3850 enum resource_types type)
3852 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3853 alist, param, attribute, class, type);
3856 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3858 Lisp_Object
3859 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
3860 Lisp_Object param,
3861 const char *attribute, const char *class,
3862 enum resource_types type)
3864 Lisp_Object value;
3866 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3867 attribute, class, type);
3868 if (! NILP (value) && ! EQ (value, Qunbound))
3869 store_frame_param (f, param, value);
3871 return value;
3875 /* Record in frame F the specified or default value according to ALIST
3876 of the parameter named PROP (a Lisp symbol).
3877 If no value is specified for PROP, look for an X default for XPROP
3878 on the frame named NAME.
3879 If that is not found either, use the value DEFLT. */
3881 Lisp_Object
3882 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
3883 Lisp_Object deflt, const char *xprop, const char *xclass,
3884 enum resource_types type)
3886 Lisp_Object tem;
3888 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3889 if (EQ (tem, Qunbound))
3890 tem = deflt;
3891 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3892 return tem;
3898 /* NS used to define x-parse-geometry in ns-win.el, but that confused
3899 make-docfile: the documentation string in ns-win.el was used for
3900 x-parse-geometry even in non-NS builds.
3902 With two definitions of x-parse-geometry in this file, various
3903 things still get confused (eg M-x apropos documentation), so that
3904 it is best if the two definitions just share the same doc-string.
3906 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3907 doc: /* Parse a display geometry string STRING.
3908 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3909 The properties returned may include `top', `left', `height', and `width'.
3910 For X, the value of `left' or `top' may be an integer,
3911 or a list (+ N) meaning N pixels relative to top/left corner,
3912 or a list (- N) meaning -N pixels relative to bottom/right corner.
3913 On Nextstep, this just calls `ns-parse-geometry'. */)
3914 (Lisp_Object string)
3916 #ifdef HAVE_NS
3917 return call1 (Qns_parse_geometry, string);
3918 #else
3919 int geometry, x, y;
3920 unsigned int width, height;
3921 Lisp_Object result;
3923 CHECK_STRING (string);
3925 geometry = XParseGeometry (SSDATA (string),
3926 &x, &y, &width, &height);
3927 result = Qnil;
3928 if (geometry & XValue)
3930 Lisp_Object element;
3932 if (x >= 0 && (geometry & XNegative))
3933 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3934 else if (x < 0 && ! (geometry & XNegative))
3935 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3936 else
3937 element = Fcons (Qleft, make_number (x));
3938 result = Fcons (element, result);
3941 if (geometry & YValue)
3943 Lisp_Object element;
3945 if (y >= 0 && (geometry & YNegative))
3946 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3947 else if (y < 0 && ! (geometry & YNegative))
3948 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3949 else
3950 element = Fcons (Qtop, make_number (y));
3951 result = Fcons (element, result);
3954 if (geometry & WidthValue)
3955 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3956 if (geometry & HeightValue)
3957 result = Fcons (Fcons (Qheight, make_number (height)), result);
3959 return result;
3960 #endif /* HAVE_NS */
3964 /* Calculate the desired size and position of frame F.
3965 Return the flags saying which aspects were specified.
3967 Also set the win_gravity and size_hint_flags of F.
3969 Adjust height for toolbar if TOOLBAR_P is 1.
3971 This function does not make the coordinates positive. */
3973 #define DEFAULT_ROWS 35
3974 #define DEFAULT_COLS 80
3977 x_figure_window_size (struct frame *f, Lisp_Object parms, int toolbar_p)
3979 register Lisp_Object tem0, tem1, tem2;
3980 long window_prompting = 0;
3981 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3983 /* Default values if we fall through.
3984 Actually, if that happens we should get
3985 window manager prompting. */
3986 SET_FRAME_COLS (f, DEFAULT_COLS);
3987 FRAME_LINES (f) = DEFAULT_ROWS;
3988 /* Window managers expect that if program-specified
3989 positions are not (0,0), they're intentional, not defaults. */
3990 f->top_pos = 0;
3991 f->left_pos = 0;
3993 /* Ensure that old new_text_cols and new_text_lines will not override the
3994 values set here. */
3995 /* ++KFS: This was specific to W32, but seems ok for all platforms */
3996 f->new_text_cols = f->new_text_lines = 0;
3998 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
3999 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4000 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4001 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4003 if (!EQ (tem0, Qunbound))
4005 CHECK_NUMBER (tem0);
4006 if (! (0 <= XINT (tem0) && XINT (tem0) <= INT_MAX))
4007 xsignal1 (Qargs_out_of_range, tem0);
4008 FRAME_LINES (f) = XINT (tem0);
4010 if (!EQ (tem1, Qunbound))
4012 CHECK_NUMBER (tem1);
4013 if (! (0 <= XINT (tem1) && XINT (tem1) <= INT_MAX))
4014 xsignal1 (Qargs_out_of_range, tem1);
4015 SET_FRAME_COLS (f, XINT (tem1));
4017 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4018 window_prompting |= USSize;
4019 else
4020 window_prompting |= PSize;
4023 f->scroll_bar_actual_width
4024 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4026 /* This used to be done _before_ calling x_figure_window_size, but
4027 since the height is reset here, this was really a no-op. I
4028 assume that moving it here does what Gerd intended (although he
4029 no longer can remember what that was... ++KFS, 2003-03-25. */
4031 /* Add the tool-bar height to the initial frame height so that the
4032 user gets a text display area of the size he specified with -g or
4033 via .Xdefaults. Later changes of the tool-bar height don't
4034 change the frame size. This is done so that users can create
4035 tall Emacs frames without having to guess how tall the tool-bar
4036 will get. */
4037 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4039 int margin, relief, bar_height;
4041 relief = (tool_bar_button_relief >= 0
4042 ? tool_bar_button_relief
4043 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4045 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4046 margin = XFASTINT (Vtool_bar_button_margin);
4047 else if (CONSP (Vtool_bar_button_margin)
4048 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4049 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4050 else
4051 margin = 0;
4053 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4054 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4057 compute_fringe_widths (f, 0);
4059 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4060 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4062 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4063 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4064 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4065 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4067 if (EQ (tem0, Qminus))
4069 f->top_pos = 0;
4070 window_prompting |= YNegative;
4072 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4073 && CONSP (XCDR (tem0))
4074 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem0)), INT_MAX))
4076 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4077 window_prompting |= YNegative;
4079 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4080 && CONSP (XCDR (tem0))
4081 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0))))
4083 f->top_pos = XINT (XCAR (XCDR (tem0)));
4085 else if (EQ (tem0, Qunbound))
4086 f->top_pos = 0;
4087 else
4089 CHECK_TYPE_RANGED_INTEGER (int, tem0);
4090 f->top_pos = XINT (tem0);
4091 if (f->top_pos < 0)
4092 window_prompting |= YNegative;
4095 if (EQ (tem1, Qminus))
4097 f->left_pos = 0;
4098 window_prompting |= XNegative;
4100 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4101 && CONSP (XCDR (tem1))
4102 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem1)), INT_MAX))
4104 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4105 window_prompting |= XNegative;
4107 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4108 && CONSP (XCDR (tem1))
4109 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1))))
4111 f->left_pos = XINT (XCAR (XCDR (tem1)));
4113 else if (EQ (tem1, Qunbound))
4114 f->left_pos = 0;
4115 else
4117 CHECK_TYPE_RANGED_INTEGER (int, tem1);
4118 f->left_pos = XINT (tem1);
4119 if (f->left_pos < 0)
4120 window_prompting |= XNegative;
4123 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4124 window_prompting |= USPosition;
4125 else
4126 window_prompting |= PPosition;
4129 if (window_prompting & XNegative)
4131 if (window_prompting & YNegative)
4132 f->win_gravity = SouthEastGravity;
4133 else
4134 f->win_gravity = NorthEastGravity;
4136 else
4138 if (window_prompting & YNegative)
4139 f->win_gravity = SouthWestGravity;
4140 else
4141 f->win_gravity = NorthWestGravity;
4144 f->size_hint_flags = window_prompting;
4146 return window_prompting;
4151 #endif /* HAVE_WINDOW_SYSTEM */
4153 void
4154 frame_make_pointer_invisible (void)
4156 if (! NILP (Vmake_pointer_invisible))
4158 struct frame *f;
4159 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4160 return;
4162 f = SELECTED_FRAME ();
4163 if (f && !f->pointer_invisible
4164 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4166 f->mouse_moved = 0;
4167 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4168 f->pointer_invisible = 1;
4173 void
4174 frame_make_pointer_visible (void)
4176 /* We don't check Vmake_pointer_invisible here in case the
4177 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4178 struct frame *f;
4180 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4181 return;
4183 f = SELECTED_FRAME ();
4184 if (f && f->pointer_invisible && f->mouse_moved
4185 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4187 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4188 f->pointer_invisible = 0;
4192 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4193 Sframe_pointer_visible_p, 0, 1, 0,
4194 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4195 Otherwise it returns nil. FRAME omitted or nil means the
4196 selected frame. This is useful when `make-pointer-invisible' is set. */)
4197 (Lisp_Object frame)
4199 if (NILP (frame))
4200 frame = selected_frame;
4202 CHECK_FRAME (frame);
4204 return (XFRAME (frame)->pointer_invisible ? Qnil : Qt);
4208 /***********************************************************************
4209 Initialization
4210 ***********************************************************************/
4212 void
4213 syms_of_frame (void)
4215 DEFSYM (Qframep, "framep");
4216 DEFSYM (Qframe_live_p, "frame-live-p");
4217 DEFSYM (Qexplicit_name, "explicit-name");
4218 DEFSYM (Qheight, "height");
4219 DEFSYM (Qicon, "icon");
4220 DEFSYM (Qminibuffer, "minibuffer");
4221 DEFSYM (Qmodeline, "modeline");
4222 DEFSYM (Qonly, "only");
4223 DEFSYM (Qnone, "none");
4224 DEFSYM (Qwidth, "width");
4225 DEFSYM (Qgeometry, "geometry");
4226 DEFSYM (Qicon_left, "icon-left");
4227 DEFSYM (Qicon_top, "icon-top");
4228 DEFSYM (Qtooltip, "tooltip");
4229 DEFSYM (Qleft, "left");
4230 DEFSYM (Qright, "right");
4231 DEFSYM (Quser_position, "user-position");
4232 DEFSYM (Quser_size, "user-size");
4233 DEFSYM (Qwindow_id, "window-id");
4234 #ifdef HAVE_X_WINDOWS
4235 DEFSYM (Qouter_window_id, "outer-window-id");
4236 #endif
4237 DEFSYM (Qparent_id, "parent-id");
4238 DEFSYM (Qx, "x");
4239 DEFSYM (Qw32, "w32");
4240 DEFSYM (Qpc, "pc");
4241 DEFSYM (Qns, "ns");
4242 DEFSYM (Qvisible, "visible");
4243 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4244 DEFSYM (Qbuffer_list, "buffer-list");
4245 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4246 DEFSYM (Qdisplay_type, "display-type");
4247 DEFSYM (Qbackground_mode, "background-mode");
4248 DEFSYM (Qnoelisp, "noelisp");
4249 DEFSYM (Qtty_color_mode, "tty-color-mode");
4250 DEFSYM (Qtty, "tty");
4251 DEFSYM (Qtty_type, "tty-type");
4253 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4255 DEFSYM (Qfullwidth, "fullwidth");
4256 DEFSYM (Qfullheight, "fullheight");
4257 DEFSYM (Qfullboth, "fullboth");
4258 DEFSYM (Qmaximized, "maximized");
4259 DEFSYM (Qx_resource_name, "x-resource-name");
4260 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4262 DEFSYM (Qterminal, "terminal");
4263 DEFSYM (Qterminal_live_p, "terminal-live-p");
4265 #ifdef HAVE_NS
4266 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4267 #endif
4270 int i;
4272 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4274 Lisp_Object v = intern_c_string (frame_parms[i].name);
4275 if (frame_parms[i].variable)
4277 *frame_parms[i].variable = v;
4278 staticpro (frame_parms[i].variable);
4280 Fput (v, Qx_frame_parameter, make_number (i));
4284 #ifdef HAVE_WINDOW_SYSTEM
4285 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4286 doc: /* The name Emacs uses to look up X resources.
4287 `x-get-resource' uses this as the first component of the instance name
4288 when requesting resource values.
4289 Emacs initially sets `x-resource-name' to the name under which Emacs
4290 was invoked, or to the value specified with the `-name' or `-rn'
4291 switches, if present.
4293 It may be useful to bind this variable locally around a call
4294 to `x-get-resource'. See also the variable `x-resource-class'. */);
4295 Vx_resource_name = Qnil;
4297 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4298 doc: /* The class Emacs uses to look up X resources.
4299 `x-get-resource' uses this as the first component of the instance class
4300 when requesting resource values.
4302 Emacs initially sets `x-resource-class' to "Emacs".
4304 Setting this variable permanently is not a reasonable thing to do,
4305 but binding this variable locally around a call to `x-get-resource'
4306 is a reasonable practice. See also the variable `x-resource-name'. */);
4307 Vx_resource_class = build_string (EMACS_CLASS);
4309 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4310 doc: /* The lower limit of the frame opacity (alpha transparency).
4311 The value should range from 0 (invisible) to 100 (completely opaque).
4312 You can also use a floating number between 0.0 and 1.0.
4313 The default is 20. */);
4314 Vframe_alpha_lower_limit = make_number (20);
4315 #endif
4317 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4318 doc: /* Alist of default values for frame creation.
4319 These may be set in your init file, like this:
4320 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4321 These override values given in window system configuration data,
4322 including X Windows' defaults database.
4323 For values specific to the first Emacs frame, see `initial-frame-alist'.
4324 For window-system specific values, see `window-system-default-frame-alist'.
4325 For values specific to the separate minibuffer frame, see
4326 `minibuffer-frame-alist'.
4327 The `menu-bar-lines' element of the list controls whether new frames
4328 have menu bars; `menu-bar-mode' works by altering this element.
4329 Setting this variable does not affect existing frames, only new ones. */);
4330 Vdefault_frame_alist = Qnil;
4332 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4333 doc: /* Default position of scroll bars on this window-system. */);
4334 #ifdef HAVE_WINDOW_SYSTEM
4335 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4336 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4337 default. */
4338 Vdefault_frame_scroll_bars = Qright;
4339 #else
4340 Vdefault_frame_scroll_bars = Qleft;
4341 #endif
4342 #else
4343 Vdefault_frame_scroll_bars = Qnil;
4344 #endif
4346 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4347 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4349 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4350 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4351 `mouse-position' calls this function, passing its usual return value as
4352 argument, and returns whatever this function returns.
4353 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4354 which need to do mouse handling at the Lisp level. */);
4355 Vmouse_position_function = Qnil;
4357 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4358 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4359 If the value is an integer, highlighting is only shown after moving the
4360 mouse, while keyboard input turns off the highlight even when the mouse
4361 is over the clickable text. However, the mouse shape still indicates
4362 when the mouse is over clickable text. */);
4363 Vmouse_highlight = Qt;
4365 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4366 doc: /* If non-nil, make pointer invisible while typing.
4367 The pointer becomes visible again when the mouse is moved. */);
4368 Vmake_pointer_invisible = Qt;
4370 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4371 doc: /* Functions run before deleting a frame.
4372 The functions are run with one arg, the frame to be deleted.
4373 See `delete-frame'.
4375 Note that functions in this list may be called just before the frame is
4376 actually deleted, or some time later (or even both when an earlier function
4377 in `delete-frame-functions' (indirectly) calls `delete-frame'
4378 recursively). */);
4379 Vdelete_frame_functions = Qnil;
4380 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4382 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4383 doc: /* Non-nil if Menu-Bar mode is enabled.
4384 See the command `menu-bar-mode' for a description of this minor mode.
4385 Setting this variable directly does not take effect;
4386 either customize it (see the info node `Easy Customization')
4387 or call the function `menu-bar-mode'. */);
4388 Vmenu_bar_mode = Qt;
4390 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4391 doc: /* Non-nil if Tool-Bar mode is enabled.
4392 See the command `tool-bar-mode' for a description of this minor mode.
4393 Setting this variable directly does not take effect;
4394 either customize it (see the info node `Easy Customization')
4395 or call the function `tool-bar-mode'. */);
4396 #ifdef HAVE_WINDOW_SYSTEM
4397 Vtool_bar_mode = Qt;
4398 #else
4399 Vtool_bar_mode = Qnil;
4400 #endif
4402 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4403 doc: /* Minibufferless frames use this frame's minibuffer.
4405 Emacs cannot create minibufferless frames unless this is set to an
4406 appropriate surrogate.
4408 Emacs consults this variable only when creating minibufferless
4409 frames; once the frame is created, it sticks with its assigned
4410 minibuffer, no matter what this variable is set to. This means that
4411 this variable doesn't necessarily say anything meaningful about the
4412 current set of frames, or where the minibuffer is currently being
4413 displayed.
4415 This variable is local to the current terminal and cannot be buffer-local. */);
4417 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4418 doc: /* Non-nil if window system changes focus when you move the mouse.
4419 You should set this variable to tell Emacs how your window manager
4420 handles focus, since there is no way in general for Emacs to find out
4421 automatically. See also `mouse-autoselect-window'. */);
4422 focus_follows_mouse = 0;
4424 staticpro (&Vframe_list);
4426 defsubr (&Sframep);
4427 defsubr (&Sframe_live_p);
4428 defsubr (&Swindow_system);
4429 defsubr (&Smake_terminal_frame);
4430 defsubr (&Shandle_switch_frame);
4431 defsubr (&Sselect_frame);
4432 defsubr (&Sselected_frame);
4433 defsubr (&Sframe_list);
4434 defsubr (&Snext_frame);
4435 defsubr (&Sprevious_frame);
4436 defsubr (&Sdelete_frame);
4437 defsubr (&Smouse_position);
4438 defsubr (&Smouse_pixel_position);
4439 defsubr (&Sset_mouse_position);
4440 defsubr (&Sset_mouse_pixel_position);
4441 #if 0
4442 defsubr (&Sframe_configuration);
4443 defsubr (&Srestore_frame_configuration);
4444 #endif
4445 defsubr (&Smake_frame_visible);
4446 defsubr (&Smake_frame_invisible);
4447 defsubr (&Siconify_frame);
4448 defsubr (&Sframe_visible_p);
4449 defsubr (&Svisible_frame_list);
4450 defsubr (&Sraise_frame);
4451 defsubr (&Slower_frame);
4452 defsubr (&Sredirect_frame_focus);
4453 defsubr (&Sframe_focus);
4454 defsubr (&Sframe_parameters);
4455 defsubr (&Sframe_parameter);
4456 defsubr (&Smodify_frame_parameters);
4457 defsubr (&Sframe_char_height);
4458 defsubr (&Sframe_char_width);
4459 defsubr (&Sframe_pixel_height);
4460 defsubr (&Sframe_pixel_width);
4461 defsubr (&Stool_bar_pixel_width);
4462 defsubr (&Sset_frame_height);
4463 defsubr (&Sset_frame_width);
4464 defsubr (&Sset_frame_size);
4465 defsubr (&Sset_frame_position);
4466 defsubr (&Sframe_pointer_visible_p);
4468 #ifdef HAVE_WINDOW_SYSTEM
4469 defsubr (&Sx_get_resource);
4470 defsubr (&Sx_parse_geometry);
4471 #endif