Auto-commit of generated files.
[emacs.git] / src / frame.c
blob78cd6914bc4255328c892d890d968ac9b9e2596d
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2013 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>
28 #include <c-ctype.h>
30 #include "lisp.h"
31 #include "character.h"
33 #ifdef HAVE_WINDOW_SYSTEM
34 #include TERM_HEADER
35 #endif /* HAVE_WINDOW_SYSTEM */
37 #include "buffer.h"
38 /* These help us bind and responding to switch-frame events. */
39 #include "commands.h"
40 #include "keyboard.h"
41 #include "frame.h"
42 #include "blockinput.h"
43 #include "termchar.h"
44 #include "termhooks.h"
45 #include "dispextern.h"
46 #include "window.h"
47 #include "font.h"
48 #ifdef HAVE_WINDOW_SYSTEM
49 #include "fontset.h"
50 #endif
51 #ifdef MSDOS
52 #include "msdos.h"
53 #include "dosfns.h"
54 #endif
56 #ifdef HAVE_NS
57 Lisp_Object Qns_parse_geometry;
58 #endif
60 Lisp_Object Qframep, Qframe_live_p;
61 Lisp_Object Qicon, Qmodeline;
62 Lisp_Object Qonly, Qnone;
63 Lisp_Object Qx, Qw32, Qpc, Qns;
64 Lisp_Object Qvisible;
65 Lisp_Object Qdisplay_type;
66 static Lisp_Object Qbackground_mode;
67 Lisp_Object Qnoelisp;
69 static Lisp_Object Qx_frame_parameter;
70 Lisp_Object Qx_resource_name;
71 Lisp_Object Qterminal;
73 /* Frame parameters (set or reported). */
75 Lisp_Object Qauto_raise, Qauto_lower;
76 Lisp_Object Qborder_color, Qborder_width;
77 Lisp_Object Qcursor_color, Qcursor_type;
78 Lisp_Object Qheight, Qwidth;
79 Lisp_Object Qleft, Qright;
80 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
81 Lisp_Object Qtooltip;
82 Lisp_Object Qinternal_border_width;
83 Lisp_Object Qmouse_color;
84 Lisp_Object Qminibuffer;
85 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
86 Lisp_Object Qvisibility;
87 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
88 Lisp_Object Qscreen_gamma;
89 Lisp_Object Qline_spacing;
90 static Lisp_Object Quser_position, Quser_size;
91 Lisp_Object Qwait_for_wm;
92 static Lisp_Object Qwindow_id;
93 #ifdef HAVE_X_WINDOWS
94 static Lisp_Object Qouter_window_id;
95 #endif
96 Lisp_Object Qparent_id;
97 Lisp_Object Qtitle, Qname;
98 static Lisp_Object Qexplicit_name;
99 Lisp_Object Qunsplittable;
100 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines, Qtool_bar_position;
101 Lisp_Object Qleft_fringe, Qright_fringe;
102 Lisp_Object Qbuffer_predicate;
103 static Lisp_Object Qbuffer_list, Qburied_buffer_list;
104 Lisp_Object Qtty_color_mode;
105 Lisp_Object Qtty, Qtty_type;
107 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth, Qmaximized;
108 Lisp_Object Qsticky;
109 Lisp_Object Qfont_backend;
110 Lisp_Object Qalpha;
112 Lisp_Object Qface_set_after_frame_default;
114 static Lisp_Object Qdelete_frame_functions;
116 static Lisp_Object Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource;
118 #ifdef HAVE_WINDOW_SYSTEM
119 static void x_report_frame_params (struct frame *, Lisp_Object *);
120 #endif
122 /* These setters are used only in this file, so they can be private. */
123 static void
124 fset_buffer_predicate (struct frame *f, Lisp_Object val)
126 f->buffer_predicate = val;
128 static void
129 fset_minibuffer_window (struct frame *f, Lisp_Object val)
131 f->minibuffer_window = val;
134 struct frame *
135 decode_live_frame (register Lisp_Object frame)
137 if (NILP (frame))
138 frame = selected_frame;
139 CHECK_LIVE_FRAME (frame);
140 return XFRAME (frame);
143 struct frame *
144 decode_any_frame (register Lisp_Object frame)
146 if (NILP (frame))
147 frame = selected_frame;
148 CHECK_FRAME (frame);
149 return XFRAME (frame);
152 bool
153 window_system_available (struct frame *f)
155 if (f)
156 return FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f);
157 else
158 #ifdef HAVE_WINDOW_SYSTEM
159 return x_display_list != NULL;
160 #else
161 return 0;
162 #endif
165 struct frame *
166 decode_window_system_frame (Lisp_Object frame)
168 struct frame *f = decode_live_frame (frame);
170 if (!window_system_available (f))
171 error ("Window system frame should be used");
172 return f;
175 void
176 check_window_system (struct frame *f)
178 if (!window_system_available (f))
179 error (f ? "Window system frame should be used"
180 : "Window system is not in use or not initialized");
183 static void
184 set_menu_bar_lines_1 (Lisp_Object window, int n)
186 struct window *w = XWINDOW (window);
188 w->top_line += n;
189 w->total_lines -= n;
191 /* Handle just the top child in a vertical split. */
192 if (WINDOW_VERTICAL_COMBINATION_P (w))
193 set_menu_bar_lines_1 (w->contents, n);
194 else if (WINDOW_HORIZONTAL_COMBINATION_P (w))
195 /* Adjust all children in a horizontal split. */
196 for (window = w->contents; !NILP (window); window = w->next)
198 w = XWINDOW (window);
199 set_menu_bar_lines_1 (window, n);
203 void
204 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
206 int nlines;
207 int olines = FRAME_MENU_BAR_LINES (f);
209 /* Right now, menu bars don't work properly in minibuf-only frames;
210 most of the commands try to apply themselves to the minibuffer
211 frame itself, and get an error because you can't switch buffers
212 in or split the minibuffer window. */
213 if (FRAME_MINIBUF_ONLY_P (f))
214 return;
216 if (TYPE_RANGED_INTEGERP (int, value))
217 nlines = XINT (value);
218 else
219 nlines = 0;
221 if (nlines != olines)
223 windows_or_buffers_changed++;
224 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
225 FRAME_MENU_BAR_LINES (f) = nlines;
226 set_menu_bar_lines_1 (f->root_window, nlines - olines);
227 adjust_frame_glyphs (f);
231 Lisp_Object Vframe_list;
234 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
235 doc: /* Return non-nil if OBJECT is a frame.
236 Value is:
237 t for a termcap frame (a character-only terminal),
238 'x' for an Emacs frame that is really an X window,
239 'w32' for an Emacs frame that is a window on MS-Windows display,
240 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
241 'pc' for a direct-write MS-DOS frame.
242 See also `frame-live-p'. */)
243 (Lisp_Object object)
245 if (!FRAMEP (object))
246 return Qnil;
247 switch (XFRAME (object)->output_method)
249 case output_initial: /* The initial frame is like a termcap frame. */
250 case output_termcap:
251 return Qt;
252 case output_x_window:
253 return Qx;
254 case output_w32:
255 return Qw32;
256 case output_msdos_raw:
257 return Qpc;
258 case output_ns:
259 return Qns;
260 default:
261 emacs_abort ();
265 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
266 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
267 Value is nil if OBJECT is not a live frame. If object is a live
268 frame, the return value indicates what sort of terminal device it is
269 displayed on. See the documentation of `framep' for possible
270 return values. */)
271 (Lisp_Object object)
273 return ((FRAMEP (object)
274 && FRAME_LIVE_P (XFRAME (object)))
275 ? Fframep (object)
276 : Qnil);
279 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
280 doc: /* The name of the window system that FRAME is displaying through.
281 The value is a symbol:
282 nil for a termcap frame (a character-only terminal),
283 'x' for an Emacs frame that is really an X window,
284 'w32' for an Emacs frame that is a window on MS-Windows display,
285 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
286 'pc' for a direct-write MS-DOS frame.
288 FRAME defaults to the currently selected frame.
290 Use of this function as a predicate is deprecated. Instead,
291 use `display-graphic-p' or any of the other `display-*-p'
292 predicates which report frame's specific UI-related capabilities. */)
293 (Lisp_Object frame)
295 Lisp_Object type;
296 if (NILP (frame))
297 frame = selected_frame;
299 type = Fframep (frame);
301 if (NILP (type))
302 wrong_type_argument (Qframep, frame);
304 if (EQ (type, Qt))
305 return Qnil;
306 else
307 return type;
310 struct frame *
311 make_frame (bool mini_p)
313 Lisp_Object frame;
314 register struct frame *f;
315 register Lisp_Object root_window;
316 register Lisp_Object mini_window;
318 f = allocate_frame ();
319 XSETFRAME (frame, f);
321 /* Initialize Lisp data. Note that allocate_frame initializes all
322 Lisp data to nil, so do it only for slots which should not be nil. */
323 fset_tool_bar_position (f, Qtop);
325 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
326 non-Lisp data, so do it only for slots which should not be zero.
327 To avoid subtle bugs and for the sake of readability, it's better to
328 initialize enum members explicitly even if their values are zero. */
329 f->wants_modeline = 1;
330 f->garbaged = 1;
331 f->has_minibuffer = mini_p;
332 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
333 f->column_width = 1; /* !FRAME_WINDOW_P value */
334 f->line_height = 1; /* !FRAME_WINDOW_P value */
335 #ifdef HAVE_WINDOW_SYSTEM
336 f->want_fullscreen = FULLSCREEN_NONE;
337 #endif
339 root_window = make_window ();
340 if (mini_p)
342 mini_window = make_window ();
343 wset_next (XWINDOW (root_window), mini_window);
344 wset_prev (XWINDOW (mini_window), root_window);
345 XWINDOW (mini_window)->mini = 1;
346 wset_frame (XWINDOW (mini_window), frame);
347 fset_minibuffer_window (f, mini_window);
349 else
351 mini_window = Qnil;
352 wset_next (XWINDOW (root_window), Qnil);
353 fset_minibuffer_window (f, Qnil);
356 wset_frame (XWINDOW (root_window), frame);
358 /* 10 is arbitrary,
359 just so that there is "something there."
360 Correct size will be set up later with change_frame_size. */
362 SET_FRAME_COLS (f, 10);
363 FRAME_LINES (f) = 10;
365 XWINDOW (root_window)->total_cols = 10;
366 XWINDOW (root_window)->total_lines = mini_p ? 9 : 10;
368 if (mini_p)
370 XWINDOW (mini_window)->total_cols = 10;
371 XWINDOW (mini_window)->top_line = 9;
372 XWINDOW (mini_window)->total_lines = 1;
375 /* Choose a buffer for the frame's root window. */
377 Lisp_Object buf = Fcurrent_buffer ();
379 /* If current buffer is hidden, try to find another one. */
380 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
381 buf = other_buffer_safely (buf);
383 /* Use set_window_buffer, not Fset_window_buffer, and don't let
384 hooks be run by it. The reason is that the whole frame/window
385 arrangement is not yet fully initialized at this point. Windows
386 don't have the right size, glyph matrices aren't initialized
387 etc. Running Lisp functions at this point surely ends in a
388 SEGV. */
389 set_window_buffer (root_window, buf, 0, 0);
390 fset_buffer_list (f, list1 (buf));
393 if (mini_p)
394 set_window_buffer (mini_window,
395 (NILP (Vminibuffer_list)
396 ? get_minibuffer (0)
397 : Fcar (Vminibuffer_list)),
398 0, 0);
400 fset_root_window (f, root_window);
401 fset_selected_window (f, root_window);
402 /* Make sure this window seems more recently used than
403 a newly-created, never-selected window. */
404 XWINDOW (f->selected_window)->use_time = ++window_select_count;
406 return f;
409 #ifdef HAVE_WINDOW_SYSTEM
410 /* Make a frame using a separate minibuffer window on another frame.
411 MINI_WINDOW is the minibuffer window to use. nil means use the
412 default (the global minibuffer). */
414 struct frame *
415 make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
417 register struct frame *f;
418 struct gcpro gcpro1;
420 if (!NILP (mini_window))
421 CHECK_LIVE_WINDOW (mini_window);
423 if (!NILP (mini_window)
424 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
425 error ("Frame and minibuffer must be on the same terminal");
427 /* Make a frame containing just a root window. */
428 f = make_frame (0);
430 if (NILP (mini_window))
432 /* Use default-minibuffer-frame if possible. */
433 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
434 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
436 Lisp_Object frame_dummy;
438 XSETFRAME (frame_dummy, f);
439 GCPRO1 (frame_dummy);
440 /* If there's no minibuffer frame to use, create one. */
441 kset_default_minibuffer_frame
442 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
443 UNGCPRO;
446 mini_window
447 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
450 fset_minibuffer_window (f, mini_window);
452 /* Make the chosen minibuffer window display the proper minibuffer,
453 unless it is already showing a minibuffer. */
454 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
455 /* Use set_window_buffer instead of Fset_window_buffer (see
456 discussion of bug#11984, bug#12025, bug#12026). */
457 set_window_buffer (mini_window,
458 (NILP (Vminibuffer_list)
459 ? get_minibuffer (0)
460 : Fcar (Vminibuffer_list)), 0, 0);
461 return f;
464 /* Make a frame containing only a minibuffer window. */
466 struct frame *
467 make_minibuffer_frame (void)
469 /* First make a frame containing just a root window, no minibuffer. */
471 register struct frame *f = make_frame (0);
472 register Lisp_Object mini_window;
473 register Lisp_Object frame;
475 XSETFRAME (frame, f);
477 f->auto_raise = 0;
478 f->auto_lower = 0;
479 f->no_split = 1;
480 f->wants_modeline = 0;
481 f->has_minibuffer = 1;
483 /* Now label the root window as also being the minibuffer.
484 Avoid infinite looping on the window chain by marking next pointer
485 as nil. */
487 mini_window = f->root_window;
488 fset_minibuffer_window (f, mini_window);
489 XWINDOW (mini_window)->mini = 1;
490 wset_next (XWINDOW (mini_window), Qnil);
491 wset_prev (XWINDOW (mini_window), Qnil);
492 wset_frame (XWINDOW (mini_window), frame);
494 /* Put the proper buffer in that window. */
496 /* Use set_window_buffer instead of Fset_window_buffer (see
497 discussion of bug#11984, bug#12025, bug#12026). */
498 set_window_buffer (mini_window,
499 (NILP (Vminibuffer_list)
500 ? get_minibuffer (0)
501 : Fcar (Vminibuffer_list)), 0, 0);
502 return f;
504 #endif /* HAVE_WINDOW_SYSTEM */
506 /* Construct a frame that refers to a terminal. */
508 static printmax_t tty_frame_count;
510 struct frame *
511 make_initial_frame (void)
513 struct frame *f;
514 struct terminal *terminal;
515 Lisp_Object frame;
517 eassert (initial_kboard);
519 /* The first call must initialize Vframe_list. */
520 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
521 Vframe_list = Qnil;
523 terminal = init_initial_terminal ();
525 f = make_frame (1);
526 XSETFRAME (frame, f);
528 Vframe_list = Fcons (frame, Vframe_list);
530 tty_frame_count = 1;
531 fset_name (f, build_pure_c_string ("F1"));
533 SET_FRAME_VISIBLE (f, 1);
535 f->output_method = terminal->type;
536 f->terminal = terminal;
537 f->terminal->reference_count++;
538 f->output_data.nothing = 0;
540 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
541 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
543 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
545 /* The default value of menu-bar-mode is t. */
546 set_menu_bar_lines (f, make_number (1), Qnil);
548 if (!noninteractive)
549 init_frame_faces (f);
551 return f;
555 static struct frame *
556 make_terminal_frame (struct terminal *terminal)
558 register struct frame *f;
559 Lisp_Object frame;
560 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
562 if (!terminal->name)
563 error ("Terminal is not live, can't create new frames on it");
565 f = make_frame (1);
567 XSETFRAME (frame, f);
568 Vframe_list = Fcons (frame, Vframe_list);
570 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
572 SET_FRAME_VISIBLE (f, 1);
574 f->terminal = terminal;
575 f->terminal->reference_count++;
576 #ifdef MSDOS
577 f->output_data.tty->display_info = &the_only_display_info;
578 if (!inhibit_window_system
579 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
580 || XFRAME (selected_frame)->output_method == output_msdos_raw))
581 f->output_method = output_msdos_raw;
582 else
583 f->output_method = output_termcap;
584 #else /* not MSDOS */
585 f->output_method = output_termcap;
586 create_tty_output (f);
587 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
588 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
589 #endif /* not MSDOS */
591 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
592 FRAME_MENU_BAR_LINES(f) = NILP (Vmenu_bar_mode) ? 0 : 1;
594 /* Set the top frame to the newly created frame. */
595 if (FRAMEP (FRAME_TTY (f)->top_frame)
596 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
597 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
599 FRAME_TTY (f)->top_frame = frame;
601 if (!noninteractive)
602 init_frame_faces (f);
604 return f;
607 /* Get a suitable value for frame parameter PARAMETER for a newly
608 created frame, based on (1) the user-supplied frame parameter
609 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
611 static Lisp_Object
612 get_future_frame_param (Lisp_Object parameter,
613 Lisp_Object supplied_parms,
614 char *current_value)
616 Lisp_Object result;
618 result = Fassq (parameter, supplied_parms);
619 if (NILP (result))
620 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
621 if (NILP (result) && current_value != NULL)
622 result = build_string (current_value);
623 if (!NILP (result) && !STRINGP (result))
624 result = XCDR (result);
625 if (NILP (result) || !STRINGP (result))
626 result = Qnil;
628 return result;
631 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
632 1, 1, 0,
633 doc: /* Create an additional terminal frame, possibly on another terminal.
634 This function takes one argument, an alist specifying frame parameters.
636 You can create multiple frames on a single text terminal, but only one
637 of them (the selected terminal frame) is actually displayed.
639 In practice, generally you don't need to specify any parameters,
640 except when you want to create a new frame on another terminal.
641 In that case, the `tty' parameter specifies the device file to open,
642 and the `tty-type' parameter specifies the terminal type. Example:
644 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
646 Note that changing the size of one terminal frame automatically
647 affects all frames on the same terminal device. */)
648 (Lisp_Object parms)
650 struct frame *f;
651 struct terminal *t = NULL;
652 Lisp_Object frame, tem;
653 struct frame *sf = SELECTED_FRAME ();
655 #ifdef MSDOS
656 if (sf->output_method != output_msdos_raw
657 && sf->output_method != output_termcap)
658 emacs_abort ();
659 #else /* not MSDOS */
661 #ifdef WINDOWSNT /* This should work now! */
662 if (sf->output_method != output_termcap)
663 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
664 #endif
665 #endif /* not MSDOS */
668 Lisp_Object terminal;
670 terminal = Fassq (Qterminal, parms);
671 if (CONSP (terminal))
673 terminal = XCDR (terminal);
674 t = get_terminal (terminal, 1);
676 #ifdef MSDOS
677 if (t && t != the_only_display_info.terminal)
678 /* msdos.c assumes a single tty_display_info object. */
679 error ("Multiple terminals are not supported on this platform");
680 if (!t)
681 t = the_only_display_info.terminal;
682 #endif
685 if (!t)
687 char *name = 0, *type = 0;
688 Lisp_Object tty, tty_type;
690 tty = get_future_frame_param
691 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
692 ? FRAME_TTY (XFRAME (selected_frame))->name
693 : NULL));
694 if (!NILP (tty))
695 name = xlispstrdupa (tty);
697 tty_type = get_future_frame_param
698 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
699 ? FRAME_TTY (XFRAME (selected_frame))->type
700 : NULL));
701 if (!NILP (tty_type))
702 type = xlispstrdupa (tty_type);
704 t = init_tty (name, type, 0); /* Errors are not fatal. */
707 f = make_terminal_frame (t);
710 int width, height;
711 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
712 change_frame_size (f, height, width, 0, 0, 0);
715 adjust_frame_glyphs (f);
716 calculate_costs (f);
717 XSETFRAME (frame, f);
719 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
720 store_in_alist (&parms, Qtty,
721 (t->display_info.tty->name
722 ? build_string (t->display_info.tty->name)
723 : Qnil));
724 Fmodify_frame_parameters (frame, parms);
726 /* Make the frame face alist be frame-specific, so that each
727 frame could change its face definitions independently. */
728 fset_face_alist (f, Fcopy_alist (sf->face_alist));
729 /* Simple Fcopy_alist isn't enough, because we need the contents of
730 the vectors which are the CDRs of associations in face_alist to
731 be copied as well. */
732 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
733 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
734 return frame;
738 /* Perform the switch to frame FRAME.
740 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
741 FRAME1 as frame.
743 If TRACK is non-zero and the frame that currently has the focus
744 redirects its focus to the selected frame, redirect that focused
745 frame's focus to FRAME instead.
747 FOR_DELETION non-zero means that the selected frame is being
748 deleted, which includes the possibility that the frame's terminal
749 is dead.
751 The value of NORECORD is passed as argument to Fselect_window. */
753 Lisp_Object
754 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
756 struct frame *sf = SELECTED_FRAME ();
758 /* If FRAME is a switch-frame event, extract the frame we should
759 switch to. */
760 if (CONSP (frame)
761 && EQ (XCAR (frame), Qswitch_frame)
762 && CONSP (XCDR (frame)))
763 frame = XCAR (XCDR (frame));
765 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
766 a switch-frame event to arrive after a frame is no longer live,
767 especially when deleting the initial frame during startup. */
768 CHECK_FRAME (frame);
769 if (! FRAME_LIVE_P (XFRAME (frame)))
770 return Qnil;
772 if (sf == XFRAME (frame))
773 return frame;
775 /* This is too greedy; it causes inappropriate focus redirection
776 that's hard to get rid of. */
777 #if 0
778 /* If a frame's focus has been redirected toward the currently
779 selected frame, we should change the redirection to point to the
780 newly selected frame. This means that if the focus is redirected
781 from a minibufferless frame to a surrogate minibuffer frame, we
782 can use `other-window' to switch between all the frames using
783 that minibuffer frame, and the focus redirection will follow us
784 around. */
785 if (track)
787 Lisp_Object tail;
789 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
791 Lisp_Object focus;
793 if (!FRAMEP (XCAR (tail)))
794 emacs_abort ();
796 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
798 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
799 Fredirect_frame_focus (XCAR (tail), frame);
802 #else /* ! 0 */
803 /* Instead, apply it only to the frame we're pointing to. */
804 #ifdef HAVE_WINDOW_SYSTEM
805 if (track && FRAME_WINDOW_P (XFRAME (frame)))
807 Lisp_Object focus, xfocus;
809 xfocus = x_get_focus_frame (XFRAME (frame));
810 if (FRAMEP (xfocus))
812 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
813 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
814 Fredirect_frame_focus (xfocus, frame);
817 #endif /* HAVE_X_WINDOWS */
818 #endif /* ! 0 */
820 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
821 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
823 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
825 Lisp_Object top_frame = FRAME_TTY (XFRAME (frame))->top_frame;
827 /* Don't mark the frame garbaged and/or obscured if we are
828 switching to the frame that is already the top frame of that
829 TTY. */
830 if (!EQ (frame, top_frame))
832 if (FRAMEP (top_frame))
833 /* Mark previously displayed frame as now obscured. */
834 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
835 SET_FRAME_VISIBLE (XFRAME (frame), 1);
837 FRAME_TTY (XFRAME (frame))->top_frame = frame;
840 selected_frame = frame;
841 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
842 last_nonminibuf_frame = XFRAME (selected_frame);
844 Fselect_window (XFRAME (frame)->selected_window, norecord);
846 /* We want to make sure that the next event generates a frame-switch
847 event to the appropriate frame. This seems kludgy to me, but
848 before you take it out, make sure that evaluating something like
849 (select-window (frame-root-window (new-frame))) doesn't end up
850 with your typing being interpreted in the new frame instead of
851 the one you're actually typing in. */
852 internal_last_event_frame = Qnil;
854 return frame;
857 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
858 doc: /* Select FRAME.
859 Subsequent editing commands apply to its selected window.
860 Optional argument NORECORD means to neither change the order of
861 recently selected windows nor the buffer list.
863 The selection of FRAME lasts until the next time the user does
864 something to select a different frame, or until the next time
865 this function is called. If you are using a window system, the
866 previously selected frame may be restored as the selected frame
867 when returning to the command loop, because it still may have
868 the window system's input focus. On a text terminal, the next
869 redisplay will display FRAME.
871 This function returns FRAME, or nil if FRAME has been deleted. */)
872 (Lisp_Object frame, Lisp_Object norecord)
874 return do_switch_frame (frame, 1, 0, norecord);
877 DEFUN ("handle-focus-in", Fhandle_focus_in, Shandle_focus_in, 1, 1, "e",
878 doc: /* Handle a focus-in event.
879 Focus in events are usually bound to this function.
880 Focus in events occur when a frame has focus, but a switch-frame event
881 is not generated.
882 This function checks if blink-cursor timers should be turned on again. */)
883 (Lisp_Object event)
885 return call0 (intern ("blink-cursor-check"));
888 DEFUN ("handle-focus-out", Fhandle_focus_out, Shandle_focus_out, 1, 1, "e",
889 doc: /* Handle a focus-out event.
890 Focus out events are usually bound to this function.
891 Focus out events occur when no frame has focus.
892 This function checks if blink-cursor timers should be turned off. */)
893 (Lisp_Object event)
895 return call0 (intern ("blink-cursor-suspend"));
898 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
899 doc: /* Handle a switch-frame event EVENT.
900 Switch-frame events are usually bound to this function.
901 A switch-frame event tells Emacs that the window manager has requested
902 that the user's events be directed to the frame mentioned in the event.
903 This function selects the selected window of the frame of EVENT.
905 If EVENT is frame object, handle it as if it were a switch-frame event
906 to that frame. */)
907 (Lisp_Object event)
909 /* Preserve prefix arg that the command loop just cleared. */
910 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
911 Frun_hooks (1, &Qmouse_leave_buffer_hook);
912 Fhandle_focus_in (event); // switch-frame implies a focus in.
913 return do_switch_frame (event, 0, 0, Qnil);
916 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
917 doc: /* Return the frame that is now selected. */)
918 (void)
920 return selected_frame;
923 DEFUN ("frame-list", Fframe_list, Sframe_list,
924 0, 0, 0,
925 doc: /* Return a list of all live frames. */)
926 (void)
928 Lisp_Object frames;
929 frames = Fcopy_sequence (Vframe_list);
930 #ifdef HAVE_WINDOW_SYSTEM
931 if (FRAMEP (tip_frame))
932 frames = Fdelq (tip_frame, frames);
933 #endif
934 return frames;
937 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
938 same tty (for tty frames) or among frames which uses FRAME's keyboard.
939 If MINIBUF is nil, do not consider minibuffer-only candidate.
940 If MINIBUF is `visible', do not consider an invisible candidate.
941 If MINIBUF is a window, consider only its own frame and candidate now
942 using that window as the minibuffer.
943 If MINIBUF is 0, consider candidate if it is visible or iconified.
944 Otherwise consider any candidate and return nil if CANDIDATE is not
945 acceptable. */
947 static Lisp_Object
948 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
950 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
952 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
953 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
954 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
955 && FRAME_TTY (c) == FRAME_TTY (f)))
957 if (NILP (minibuf))
959 if (!FRAME_MINIBUF_ONLY_P (c))
960 return candidate;
962 else if (EQ (minibuf, Qvisible))
964 if (FRAME_VISIBLE_P (c))
965 return candidate;
967 else if (WINDOWP (minibuf))
969 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
970 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
971 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
972 FRAME_FOCUS_FRAME (c)))
973 return candidate;
975 else if (XFASTINT (minibuf) == 0)
977 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
978 return candidate;
980 else
981 return candidate;
983 return Qnil;
986 /* Return the next frame in the frame list after FRAME. */
988 static Lisp_Object
989 next_frame (Lisp_Object frame, Lisp_Object minibuf)
991 Lisp_Object f, tail;
992 int passed = 0;
994 /* There must always be at least one frame in Vframe_list. */
995 eassert (CONSP (Vframe_list));
997 while (passed < 2)
998 FOR_EACH_FRAME (tail, f)
1000 if (passed)
1002 f = candidate_frame (f, frame, minibuf);
1003 if (!NILP (f))
1004 return f;
1006 if (EQ (frame, f))
1007 passed++;
1009 return frame;
1012 /* Return the previous frame in the frame list before FRAME. */
1014 static Lisp_Object
1015 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1017 Lisp_Object f, tail, prev = Qnil;
1019 /* There must always be at least one frame in Vframe_list. */
1020 eassert (CONSP (Vframe_list));
1022 FOR_EACH_FRAME (tail, f)
1024 if (EQ (frame, f) && !NILP (prev))
1025 return prev;
1026 f = candidate_frame (f, frame, minibuf);
1027 if (!NILP (f))
1028 prev = f;
1031 /* We've scanned the entire list. */
1032 if (NILP (prev))
1033 /* We went through the whole frame list without finding a single
1034 acceptable frame. Return the original frame. */
1035 return frame;
1036 else
1037 /* There were no acceptable frames in the list before FRAME; otherwise,
1038 we would have returned directly from the loop. Since PREV is the last
1039 acceptable frame in the list, return it. */
1040 return prev;
1044 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1045 doc: /* Return the next frame in the frame list after FRAME.
1046 It considers only frames on the same terminal as FRAME.
1047 By default, skip minibuffer-only frames.
1048 If omitted, FRAME defaults to the selected frame.
1049 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1050 If MINIFRAME is a window, include only its own frame
1051 and any frame now using that window as the minibuffer.
1052 If MINIFRAME is `visible', include all visible frames.
1053 If MINIFRAME is 0, include all visible and iconified frames.
1054 Otherwise, include all frames. */)
1055 (Lisp_Object frame, Lisp_Object miniframe)
1057 if (NILP (frame))
1058 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 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1083 Slast_nonminibuf_frame, 0, 0, 0,
1084 doc: /* Return last non-minibuffer frame selected. */)
1085 (void)
1087 Lisp_Object frame = Qnil;
1089 if (last_nonminibuf_frame)
1090 XSETFRAME (frame, last_nonminibuf_frame);
1092 return frame;
1095 /* Return 1 if it is ok to delete frame F;
1096 0 if all frames aside from F are invisible.
1097 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1099 static int
1100 other_visible_frames (struct frame *f)
1102 Lisp_Object frames, this;
1104 FOR_EACH_FRAME (frames, this)
1106 if (f == XFRAME (this))
1107 continue;
1109 /* Verify that we can still talk to the frame's X window,
1110 and note any recent change in visibility. */
1111 #ifdef HAVE_X_WINDOWS
1112 if (FRAME_WINDOW_P (XFRAME (this)))
1113 x_sync (XFRAME (this));
1114 #endif
1116 if (FRAME_VISIBLE_P (XFRAME (this))
1117 || FRAME_ICONIFIED_P (XFRAME (this))
1118 /* Allow deleting the terminal frame when at least one X
1119 frame exists. */
1120 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1121 return 1;
1123 return 0;
1126 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1127 window. Preferably use the selected frame's minibuffer window
1128 instead. If the selected frame doesn't have one, get some other
1129 frame's minibuffer window. SELECT non-zero means select the new
1130 minibuffer window. */
1131 static void
1132 check_minibuf_window (Lisp_Object frame, int select)
1134 struct frame *f = decode_live_frame (frame);
1136 XSETFRAME (frame, f);
1138 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1140 Lisp_Object frames, this, window = make_number (0);
1142 if (!EQ (frame, selected_frame)
1143 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1144 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1145 else
1146 FOR_EACH_FRAME (frames, this)
1148 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1150 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1151 break;
1155 /* Don't abort if no window was found (Bug#15247). */
1156 if (WINDOWP (window))
1158 /* Use set_window_buffer instead of Fset_window_buffer (see
1159 discussion of bug#11984, bug#12025, bug#12026). */
1160 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1161 minibuf_window = window;
1163 /* SELECT non-zero usually means that FRAME's minibuffer
1164 window was selected; select the new one. */
1165 if (select)
1166 Fselect_window (minibuf_window, Qnil);
1172 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1173 unconditionally. x_connection_closed and delete_terminal use
1174 this. Any other value of FORCE implements the semantics
1175 described for Fdelete_frame. */
1176 Lisp_Object
1177 delete_frame (Lisp_Object frame, Lisp_Object force)
1179 struct frame *f = decode_any_frame (frame);
1180 struct frame *sf = SELECTED_FRAME ();
1181 struct kboard *kb;
1183 int minibuffer_selected, is_tooltip_frame;
1185 if (! FRAME_LIVE_P (f))
1186 return Qnil;
1188 if (NILP (force) && !other_visible_frames (f))
1189 error ("Attempt to delete the sole visible or iconified frame");
1191 /* x_connection_closed must have set FORCE to `noelisp' in order
1192 to delete the last frame, if it is gone. */
1193 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1194 error ("Attempt to delete the only frame");
1196 XSETFRAME (frame, f);
1198 /* Does this frame have a minibuffer, and is it the surrogate
1199 minibuffer for any other frame? */
1200 if (FRAME_HAS_MINIBUF_P (f))
1202 Lisp_Object frames, this;
1204 FOR_EACH_FRAME (frames, this)
1206 Lisp_Object fminiw;
1208 if (EQ (this, frame))
1209 continue;
1211 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1213 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1215 /* If we MUST delete this frame, delete the other first.
1216 But do this only if FORCE equals `noelisp'. */
1217 if (EQ (force, Qnoelisp))
1218 delete_frame (this, Qnoelisp);
1219 else
1220 error ("Attempt to delete a surrogate minibuffer frame");
1225 is_tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1227 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1228 frame is a tooltip. FORCE is set to `noelisp' when handling
1229 a disconnect from the terminal, so we don't dare call Lisp
1230 code. */
1231 if (NILP (Vrun_hooks) || is_tooltip_frame)
1233 else if (EQ (force, Qnoelisp))
1234 pending_funcalls
1235 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1236 pending_funcalls);
1237 else
1239 #ifdef HAVE_X_WINDOWS
1240 /* Also, save clipboard to the clipboard manager. */
1241 x_clipboard_manager_save_frame (frame);
1242 #endif
1244 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1247 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1248 if (! FRAME_LIVE_P (f))
1249 return Qnil;
1251 /* At this point, we are committed to deleting the frame.
1252 There is no more chance for errors to prevent it. */
1254 minibuffer_selected = EQ (minibuf_window, selected_window);
1256 /* Don't let the frame remain selected. */
1257 if (f == sf)
1259 Lisp_Object tail;
1260 Lisp_Object frame1 = Qnil;
1262 /* Look for another visible frame on the same terminal.
1263 Do not call next_frame here because it may loop forever.
1264 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1265 FOR_EACH_FRAME (tail, frame1)
1266 if (!EQ (frame, frame1)
1267 && (FRAME_TERMINAL (XFRAME (frame))
1268 == FRAME_TERMINAL (XFRAME (frame1)))
1269 && FRAME_VISIBLE_P (XFRAME (frame1)))
1270 break;
1272 /* If there is none, find *some* other frame. */
1273 if (NILP (frame1) || EQ (frame1, frame))
1275 FOR_EACH_FRAME (tail, frame1)
1277 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1279 /* Do not change a text terminal's top-frame. */
1280 struct frame *f1 = XFRAME (frame1);
1281 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1283 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1284 if (!EQ (top_frame, frame))
1285 frame1 = top_frame;
1287 break;
1291 #ifdef NS_IMPL_COCOA
1292 else
1293 /* Under NS, there is no system mechanism for choosing a new
1294 window to get focus -- it is left to application code.
1295 So the portion of THIS application interfacing with NS
1296 needs to know about it. We call Fraise_frame, but the
1297 purpose is really to transfer focus. */
1298 Fraise_frame (frame1);
1299 #endif
1301 do_switch_frame (frame1, 0, 1, Qnil);
1302 sf = SELECTED_FRAME ();
1305 /* Don't allow minibuf_window to remain on a deleted frame. */
1306 check_minibuf_window (frame, minibuffer_selected);
1308 /* Don't let echo_area_window to remain on a deleted frame. */
1309 if (EQ (f->minibuffer_window, echo_area_window))
1310 echo_area_window = sf->minibuffer_window;
1312 /* Clear any X selections for this frame. */
1313 #ifdef HAVE_X_WINDOWS
1314 if (FRAME_X_P (f))
1315 x_clear_frame_selections (f);
1316 #endif
1318 /* Free glyphs.
1319 This function must be called before the window tree of the
1320 frame is deleted because windows contain dynamically allocated
1321 memory. */
1322 free_glyphs (f);
1324 #ifdef HAVE_WINDOW_SYSTEM
1325 /* Give chance to each font driver to free a frame specific data. */
1326 font_update_drivers (f, Qnil);
1327 #endif
1329 /* Mark all the windows that used to be on FRAME as deleted, and then
1330 remove the reference to them. */
1331 delete_all_child_windows (f->root_window);
1332 fset_root_window (f, Qnil);
1334 Vframe_list = Fdelq (frame, Vframe_list);
1335 SET_FRAME_VISIBLE (f, 0);
1337 /* Allow the vector of menu bar contents to be freed in the next
1338 garbage collection. The frame object itself may not be garbage
1339 collected until much later, because recent_keys and other data
1340 structures can still refer to it. */
1341 fset_menu_bar_vector (f, Qnil);
1343 /* If FRAME's buffer lists contains killed
1344 buffers, this helps GC to reclaim them. */
1345 fset_buffer_list (f, Qnil);
1346 fset_buried_buffer_list (f, Qnil);
1348 free_font_driver_list (f);
1349 xfree (f->namebuf);
1350 xfree (f->decode_mode_spec_buffer);
1351 xfree (FRAME_INSERT_COST (f));
1352 xfree (FRAME_DELETEN_COST (f));
1353 xfree (FRAME_INSERTN_COST (f));
1354 xfree (FRAME_DELETE_COST (f));
1356 /* Since some events are handled at the interrupt level, we may get
1357 an event for f at any time; if we zero out the frame's terminal
1358 now, then we may trip up the event-handling code. Instead, we'll
1359 promise that the terminal of the frame must be valid until we
1360 have called the window-system-dependent frame destruction
1361 routine. */
1363 if (FRAME_TERMINAL (f)->delete_frame_hook)
1364 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1367 struct terminal *terminal = FRAME_TERMINAL (f);
1368 f->output_data.nothing = 0;
1369 f->terminal = 0; /* Now the frame is dead. */
1371 /* If needed, delete the terminal that this frame was on.
1372 (This must be done after the frame is killed.) */
1373 terminal->reference_count--;
1374 #ifdef USE_GTK
1375 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1376 bug.
1377 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1378 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1379 terminal->reference_count = 1;
1380 #endif /* USE_GTK */
1381 if (terminal->reference_count == 0)
1383 Lisp_Object tmp;
1384 XSETTERMINAL (tmp, terminal);
1386 kb = NULL;
1387 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1389 else
1390 kb = terminal->kboard;
1393 /* If we've deleted the last_nonminibuf_frame, then try to find
1394 another one. */
1395 if (f == last_nonminibuf_frame)
1397 Lisp_Object frames, this;
1399 last_nonminibuf_frame = 0;
1401 FOR_EACH_FRAME (frames, this)
1403 f = XFRAME (this);
1404 if (!FRAME_MINIBUF_ONLY_P (f))
1406 last_nonminibuf_frame = f;
1407 break;
1412 /* If there's no other frame on the same kboard, get out of
1413 single-kboard state if we're in it for this kboard. */
1414 if (kb != NULL)
1416 Lisp_Object frames, this;
1417 /* Some frame we found on the same kboard, or nil if there are none. */
1418 Lisp_Object frame_on_same_kboard = Qnil;
1420 FOR_EACH_FRAME (frames, this)
1421 if (kb == FRAME_KBOARD (XFRAME (this)))
1422 frame_on_same_kboard = this;
1424 if (NILP (frame_on_same_kboard))
1425 not_single_kboard_state (kb);
1429 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1430 find another one. Prefer minibuffer-only frames, but also notice
1431 frames with other windows. */
1432 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1434 Lisp_Object frames, this;
1436 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1437 Lisp_Object frame_with_minibuf = Qnil;
1438 /* Some frame we found on the same kboard, or nil if there are none. */
1439 Lisp_Object frame_on_same_kboard = Qnil;
1441 FOR_EACH_FRAME (frames, this)
1443 struct frame *f1 = XFRAME (this);
1445 /* Consider only frames on the same kboard
1446 and only those with minibuffers. */
1447 if (kb == FRAME_KBOARD (f1)
1448 && FRAME_HAS_MINIBUF_P (f1))
1450 frame_with_minibuf = this;
1451 if (FRAME_MINIBUF_ONLY_P (f1))
1452 break;
1455 if (kb == FRAME_KBOARD (f1))
1456 frame_on_same_kboard = this;
1459 if (!NILP (frame_on_same_kboard))
1461 /* We know that there must be some frame with a minibuffer out
1462 there. If this were not true, all of the frames present
1463 would have to be minibufferless, which implies that at some
1464 point their minibuffer frames must have been deleted, but
1465 that is prohibited at the top; you can't delete surrogate
1466 minibuffer frames. */
1467 if (NILP (frame_with_minibuf))
1468 emacs_abort ();
1470 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1472 else
1473 /* No frames left on this kboard--say no minibuffer either. */
1474 kset_default_minibuffer_frame (kb, Qnil);
1477 /* Cause frame titles to update--necessary if we now have just one frame. */
1478 if (!is_tooltip_frame)
1479 update_mode_lines = 1;
1481 return Qnil;
1484 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1485 doc: /* Delete FRAME, permanently eliminating it from use.
1486 FRAME defaults to the selected frame.
1488 A frame may not be deleted if its minibuffer is used by other frames.
1489 Normally, you may not delete a frame if all other frames are invisible,
1490 but if the second optional argument FORCE is non-nil, you may do so.
1492 This function runs `delete-frame-functions' before actually
1493 deleting the frame, unless the frame is a tooltip.
1494 The functions are run with one argument, the frame to be deleted. */)
1495 (Lisp_Object frame, Lisp_Object force)
1497 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1501 /* Return mouse position in character cell units. */
1503 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1504 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1505 The position is given in character cells, where (0, 0) is the
1506 upper-left corner of the frame, X is the horizontal offset, and Y is
1507 the vertical offset.
1508 If Emacs is running on a mouseless terminal or hasn't been programmed
1509 to read the mouse position, it returns the selected frame for FRAME
1510 and nil for X and Y.
1511 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1512 passing the normal return value to that function as an argument,
1513 and returns whatever that function returns. */)
1514 (void)
1516 struct frame *f;
1517 Lisp_Object lispy_dummy;
1518 Lisp_Object x, y, retval;
1519 struct gcpro gcpro1;
1521 f = SELECTED_FRAME ();
1522 x = y = Qnil;
1524 /* It's okay for the hook to refrain from storing anything. */
1525 if (FRAME_TERMINAL (f)->mouse_position_hook)
1527 enum scroll_bar_part party_dummy;
1528 Time time_dummy;
1529 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1530 &lispy_dummy, &party_dummy,
1531 &x, &y,
1532 &time_dummy);
1535 if (! NILP (x))
1537 int col = XINT (x);
1538 int row = XINT (y);
1539 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1540 XSETINT (x, col);
1541 XSETINT (y, row);
1543 XSETFRAME (lispy_dummy, f);
1544 retval = Fcons (lispy_dummy, Fcons (x, y));
1545 GCPRO1 (retval);
1546 if (!NILP (Vmouse_position_function))
1547 retval = call1 (Vmouse_position_function, retval);
1548 RETURN_UNGCPRO (retval);
1551 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1552 Smouse_pixel_position, 0, 0, 0,
1553 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1554 The position is given in pixel units, where (0, 0) is the
1555 upper-left corner of the frame, X is the horizontal offset, and Y is
1556 the vertical offset.
1557 If Emacs is running on a mouseless terminal or hasn't been programmed
1558 to read the mouse position, it returns the selected frame for FRAME
1559 and nil for X and Y. */)
1560 (void)
1562 struct frame *f;
1563 Lisp_Object lispy_dummy;
1564 Lisp_Object x, y;
1566 f = SELECTED_FRAME ();
1567 x = y = Qnil;
1569 /* It's okay for the hook to refrain from storing anything. */
1570 if (FRAME_TERMINAL (f)->mouse_position_hook)
1572 enum scroll_bar_part party_dummy;
1573 Time time_dummy;
1574 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1575 &lispy_dummy, &party_dummy,
1576 &x, &y,
1577 &time_dummy);
1580 XSETFRAME (lispy_dummy, f);
1581 return Fcons (lispy_dummy, Fcons (x, y));
1584 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1585 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1586 Coordinates are relative to the frame, not a window,
1587 so the coordinates of the top left character in the frame
1588 may be nonzero due to left-hand scroll bars or the menu bar.
1590 The position is given in character cells, where (0, 0) is the
1591 upper-left corner of the frame, X is the horizontal offset, and Y is
1592 the vertical offset.
1594 This function is a no-op for an X frame that is not visible.
1595 If you have just created a frame, you must wait for it to become visible
1596 before calling this function on it, like this.
1597 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1598 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1600 CHECK_LIVE_FRAME (frame);
1601 CHECK_TYPE_RANGED_INTEGER (int, x);
1602 CHECK_TYPE_RANGED_INTEGER (int, y);
1604 /* I think this should be done with a hook. */
1605 #ifdef HAVE_WINDOW_SYSTEM
1606 if (FRAME_WINDOW_P (XFRAME (frame)))
1607 /* Warping the mouse will cause enternotify and focus events. */
1608 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1609 #else
1610 #if defined (MSDOS)
1611 if (FRAME_MSDOS_P (XFRAME (frame)))
1613 Fselect_frame (frame, Qnil);
1614 mouse_moveto (XINT (x), XINT (y));
1616 #else
1617 #ifdef HAVE_GPM
1619 Fselect_frame (frame, Qnil);
1620 term_mouse_moveto (XINT (x), XINT (y));
1622 #endif
1623 #endif
1624 #endif
1626 return Qnil;
1629 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1630 Sset_mouse_pixel_position, 3, 3, 0,
1631 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1632 The position is given in pixels, where (0, 0) is the upper-left corner
1633 of the frame, X is the horizontal offset, and Y is the vertical offset.
1635 Note, this is a no-op for an X frame that is not visible.
1636 If you have just created a frame, you must wait for it to become visible
1637 before calling this function on it, like this.
1638 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1639 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1641 CHECK_LIVE_FRAME (frame);
1642 CHECK_TYPE_RANGED_INTEGER (int, x);
1643 CHECK_TYPE_RANGED_INTEGER (int, y);
1645 /* I think this should be done with a hook. */
1646 #ifdef HAVE_WINDOW_SYSTEM
1647 if (FRAME_WINDOW_P (XFRAME (frame)))
1648 /* Warping the mouse will cause enternotify and focus events. */
1649 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1650 #else
1651 #if defined (MSDOS)
1652 if (FRAME_MSDOS_P (XFRAME (frame)))
1654 Fselect_frame (frame, Qnil);
1655 mouse_moveto (XINT (x), XINT (y));
1657 #else
1658 #ifdef HAVE_GPM
1660 Fselect_frame (frame, Qnil);
1661 term_mouse_moveto (XINT (x), XINT (y));
1663 #endif
1664 #endif
1665 #endif
1667 return Qnil;
1670 static void make_frame_visible_1 (Lisp_Object);
1672 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1673 0, 1, "",
1674 doc: /* Make the frame FRAME visible (assuming it is an X window).
1675 If omitted, FRAME defaults to the currently selected frame. */)
1676 (Lisp_Object frame)
1678 struct frame *f = decode_live_frame (frame);
1680 /* I think this should be done with a hook. */
1681 #ifdef HAVE_WINDOW_SYSTEM
1682 if (FRAME_WINDOW_P (f))
1683 x_make_frame_visible (f);
1684 #endif
1686 make_frame_visible_1 (f->root_window);
1688 /* Make menu bar update for the Buffers and Frames menus. */
1689 windows_or_buffers_changed++;
1691 XSETFRAME (frame, f);
1692 return frame;
1695 /* Update the display_time slot of the buffers shown in WINDOW
1696 and all its descendants. */
1698 static void
1699 make_frame_visible_1 (Lisp_Object window)
1701 struct window *w;
1703 for (; !NILP (window); window = w->next)
1705 w = XWINDOW (window);
1706 if (WINDOWP (w->contents))
1707 make_frame_visible_1 (w->contents);
1708 else
1709 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
1713 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1714 0, 2, "",
1715 doc: /* Make the frame FRAME invisible.
1716 If omitted, FRAME defaults to the currently selected frame.
1717 On graphical displays, invisible frames are not updated and are
1718 usually not displayed at all, even in a window system's \"taskbar\".
1720 Normally you may not make FRAME invisible if all other frames are invisible,
1721 but if the second optional argument FORCE is non-nil, you may do so.
1723 This function has no effect on text terminal frames. Such frames are
1724 always considered visible, whether or not they are currently being
1725 displayed in the terminal. */)
1726 (Lisp_Object frame, Lisp_Object force)
1728 struct frame *f = decode_live_frame (frame);
1730 if (NILP (force) && !other_visible_frames (f))
1731 error ("Attempt to make invisible the sole visible or iconified frame");
1733 /* Don't allow minibuf_window to remain on an invisible frame. */
1734 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
1736 /* I think this should be done with a hook. */
1737 #ifdef HAVE_WINDOW_SYSTEM
1738 if (FRAME_WINDOW_P (f))
1739 x_make_frame_invisible (f);
1740 #endif
1742 /* Make menu bar update for the Buffers and Frames menus. */
1743 windows_or_buffers_changed++;
1745 return Qnil;
1748 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1749 0, 1, "",
1750 doc: /* Make the frame FRAME into an icon.
1751 If omitted, FRAME defaults to the currently selected frame. */)
1752 (Lisp_Object frame)
1754 struct frame *f = decode_live_frame (frame);
1756 /* Don't allow minibuf_window to remain on an iconified frame. */
1757 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
1759 /* I think this should be done with a hook. */
1760 #ifdef HAVE_WINDOW_SYSTEM
1761 if (FRAME_WINDOW_P (f))
1762 x_iconify_frame (f);
1763 #endif
1765 /* Make menu bar update for the Buffers and Frames menus. */
1766 windows_or_buffers_changed++;
1768 return Qnil;
1771 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1772 1, 1, 0,
1773 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1774 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1775 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1776 On graphical displays, invisible frames are not updated and are
1777 usually not displayed at all, even in a window system's \"taskbar\".
1779 If FRAME is a text terminal frame, this always returns t.
1780 Such frames are always considered visible, whether or not they are
1781 currently being displayed on the terminal. */)
1782 (Lisp_Object frame)
1784 CHECK_LIVE_FRAME (frame);
1786 if (FRAME_VISIBLE_P (XFRAME (frame)))
1787 return Qt;
1788 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1789 return Qicon;
1790 return Qnil;
1793 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1794 0, 0, 0,
1795 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1796 (void)
1798 Lisp_Object tail, frame, value = Qnil;
1800 FOR_EACH_FRAME (tail, frame)
1801 if (FRAME_VISIBLE_P (XFRAME (frame)))
1802 value = Fcons (frame, value);
1804 return value;
1808 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1809 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1810 If FRAME is invisible or iconified, make it visible.
1811 If you don't specify a frame, the selected frame is used.
1812 If Emacs is displaying on an ordinary terminal or some other device which
1813 doesn't support multiple overlapping frames, this function selects FRAME. */)
1814 (Lisp_Object frame)
1816 struct frame *f = decode_live_frame (frame);
1818 XSETFRAME (frame, f);
1820 if (FRAME_TERMCAP_P (f))
1821 /* On a text terminal select FRAME. */
1822 Fselect_frame (frame, Qnil);
1823 else
1824 /* Do like the documentation says. */
1825 Fmake_frame_visible (frame);
1827 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1828 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
1830 return Qnil;
1833 /* Should we have a corresponding function called Flower_Power? */
1834 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1835 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1836 If you don't specify a frame, the selected frame is used.
1837 If Emacs is displaying on an ordinary terminal or some other device which
1838 doesn't support multiple overlapping frames, this function does nothing. */)
1839 (Lisp_Object frame)
1841 struct frame *f = decode_live_frame (frame);
1843 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1844 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
1846 return Qnil;
1850 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1851 1, 2, 0,
1852 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1853 In other words, switch-frame events caused by events in FRAME will
1854 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1855 FOCUS-FRAME after reading an event typed at FRAME.
1857 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
1858 frame again receives its own keystrokes.
1860 Focus redirection is useful for temporarily redirecting keystrokes to
1861 a surrogate minibuffer frame when a frame doesn't have its own
1862 minibuffer window.
1864 A frame's focus redirection can be changed by `select-frame'. If frame
1865 FOO is selected, and then a different frame BAR is selected, any
1866 frames redirecting their focus to FOO are shifted to redirect their
1867 focus to BAR. This allows focus redirection to work properly when the
1868 user switches from one frame to another using `select-window'.
1870 This means that a frame whose focus is redirected to itself is treated
1871 differently from a frame whose focus is redirected to nil; the former
1872 is affected by `select-frame', while the latter is not.
1874 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1875 (Lisp_Object frame, Lisp_Object focus_frame)
1877 /* Note that we don't check for a live frame here. It's reasonable
1878 to redirect the focus of a frame you're about to delete, if you
1879 know what other frame should receive those keystrokes. */
1880 struct frame *f = decode_any_frame (frame);
1882 if (! NILP (focus_frame))
1883 CHECK_LIVE_FRAME (focus_frame);
1885 fset_focus_frame (f, focus_frame);
1887 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
1888 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
1890 return Qnil;
1894 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
1895 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1896 If FRAME is omitted or nil, the selected frame is used.
1897 Return nil if FRAME's focus is not redirected.
1898 See `redirect-frame-focus'. */)
1899 (Lisp_Object frame)
1901 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
1904 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
1905 doc: /* Set the input focus to FRAME.
1906 FRAME nil means use the selected frame.
1907 If there is no window system support, this function does nothing. */)
1908 (Lisp_Object frame)
1910 #ifdef HAVE_WINDOW_SYSTEM
1911 x_focus_frame (decode_window_system_frame (frame));
1912 #endif
1913 return Qnil;
1917 /* Return the value of frame parameter PROP in frame FRAME. */
1919 #ifdef HAVE_WINDOW_SYSTEM
1920 #if !HAVE_NS && !defined (WINDOWSNT)
1921 static
1922 #endif
1923 Lisp_Object
1924 get_frame_param (register struct frame *frame, Lisp_Object prop)
1926 register Lisp_Object tem;
1928 tem = Fassq (prop, frame->param_alist);
1929 if (EQ (tem, Qnil))
1930 return tem;
1931 return Fcdr (tem);
1933 #endif
1935 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
1937 void
1938 frames_discard_buffer (Lisp_Object buffer)
1940 Lisp_Object frame, tail;
1942 FOR_EACH_FRAME (tail, frame)
1944 fset_buffer_list
1945 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
1946 fset_buried_buffer_list
1947 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
1951 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1952 If the alist already has an element for PROP, we change it. */
1954 void
1955 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
1957 register Lisp_Object tem;
1959 tem = Fassq (prop, *alistptr);
1960 if (EQ (tem, Qnil))
1961 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1962 else
1963 Fsetcdr (tem, val);
1966 static int
1967 frame_name_fnn_p (char *str, ptrdiff_t len)
1969 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
1971 char *p = str + 2;
1972 while ('0' <= *p && *p <= '9')
1973 p++;
1974 if (p == str + len)
1975 return 1;
1977 return 0;
1980 /* Set the name of the terminal frame. Also used by MSDOS frames.
1981 Modeled after x_set_name which is used for WINDOW frames. */
1983 static void
1984 set_term_frame_name (struct frame *f, Lisp_Object name)
1986 f->explicit_name = ! NILP (name);
1988 /* If NAME is nil, set the name to F<num>. */
1989 if (NILP (name))
1991 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
1993 /* Check for no change needed in this very common case
1994 before we do any consing. */
1995 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
1996 return;
1998 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2000 else
2002 CHECK_STRING (name);
2004 /* Don't change the name if it's already NAME. */
2005 if (! NILP (Fstring_equal (name, f->name)))
2006 return;
2008 /* Don't allow the user to set the frame name to F<num>, so it
2009 doesn't clash with the names we generate for terminal frames. */
2010 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2011 error ("Frame names of the form F<num> are usurped by Emacs");
2014 fset_name (f, name);
2015 update_mode_lines = 1;
2018 void
2019 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2021 register Lisp_Object old_alist_elt;
2023 /* The buffer-list parameters are stored in a special place and not
2024 in the alist. All buffers must be live. */
2025 if (EQ (prop, Qbuffer_list))
2027 Lisp_Object list = Qnil;
2028 for (; CONSP (val); val = XCDR (val))
2029 if (!NILP (Fbuffer_live_p (XCAR (val))))
2030 list = Fcons (XCAR (val), list);
2031 fset_buffer_list (f, Fnreverse (list));
2032 return;
2034 if (EQ (prop, Qburied_buffer_list))
2036 Lisp_Object list = Qnil;
2037 for (; CONSP (val); val = XCDR (val))
2038 if (!NILP (Fbuffer_live_p (XCAR (val))))
2039 list = Fcons (XCAR (val), list);
2040 fset_buried_buffer_list (f, Fnreverse (list));
2041 return;
2044 /* If PROP is a symbol which is supposed to have frame-local values,
2045 and it is set up based on this frame, switch to the global
2046 binding. That way, we can create or alter the frame-local binding
2047 without messing up the symbol's status. */
2048 if (SYMBOLP (prop))
2050 struct Lisp_Symbol *sym = XSYMBOL (prop);
2051 start:
2052 switch (sym->redirect)
2054 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2055 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2056 case SYMBOL_LOCALIZED:
2057 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2058 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2059 swap_in_global_binding (sym);
2060 break;
2062 default: emacs_abort ();
2066 /* The tty color needed to be set before the frame's parameter
2067 alist was updated with the new value. This is not true any more,
2068 but we still do this test early on. */
2069 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2070 && f == FRAME_TTY (f)->previous_frame)
2071 /* Force redisplay of this tty. */
2072 FRAME_TTY (f)->previous_frame = NULL;
2074 /* Update the frame parameter alist. */
2075 old_alist_elt = Fassq (prop, f->param_alist);
2076 if (EQ (old_alist_elt, Qnil))
2077 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2078 else
2079 Fsetcdr (old_alist_elt, val);
2081 /* Update some other special parameters in their special places
2082 in addition to the alist. */
2084 if (EQ (prop, Qbuffer_predicate))
2085 fset_buffer_predicate (f, val);
2087 if (! FRAME_WINDOW_P (f))
2089 if (EQ (prop, Qmenu_bar_lines))
2090 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2091 else if (EQ (prop, Qname))
2092 set_term_frame_name (f, val);
2095 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2097 if (! MINI_WINDOW_P (XWINDOW (val)))
2098 error ("Surrogate minibuffer windows must be minibuffer windows");
2100 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2101 && !EQ (val, f->minibuffer_window))
2102 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2104 /* Install the chosen minibuffer window, with proper buffer. */
2105 fset_minibuffer_window (f, val);
2109 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2110 doc: /* Return the parameters-alist of frame FRAME.
2111 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2112 The meaningful PARMs depend on the kind of frame.
2113 If FRAME is omitted or nil, return information on the currently selected frame. */)
2114 (Lisp_Object frame)
2116 Lisp_Object alist;
2117 struct frame *f = decode_any_frame (frame);
2118 int height, width;
2119 struct gcpro gcpro1;
2121 if (!FRAME_LIVE_P (f))
2122 return Qnil;
2124 alist = Fcopy_alist (f->param_alist);
2125 GCPRO1 (alist);
2127 if (!FRAME_WINDOW_P (f))
2129 int fg = FRAME_FOREGROUND_PIXEL (f);
2130 int bg = FRAME_BACKGROUND_PIXEL (f);
2131 Lisp_Object elt;
2133 /* If the frame's parameter alist says the colors are
2134 unspecified and reversed, take the frame's background pixel
2135 for foreground and vice versa. */
2136 elt = Fassq (Qforeground_color, alist);
2137 if (CONSP (elt) && STRINGP (XCDR (elt)))
2139 if (strncmp (SSDATA (XCDR (elt)),
2140 unspecified_bg,
2141 SCHARS (XCDR (elt))) == 0)
2142 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2143 else if (strncmp (SSDATA (XCDR (elt)),
2144 unspecified_fg,
2145 SCHARS (XCDR (elt))) == 0)
2146 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2148 else
2149 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2150 elt = Fassq (Qbackground_color, alist);
2151 if (CONSP (elt) && STRINGP (XCDR (elt)))
2153 if (strncmp (SSDATA (XCDR (elt)),
2154 unspecified_fg,
2155 SCHARS (XCDR (elt))) == 0)
2156 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2157 else if (strncmp (SSDATA (XCDR (elt)),
2158 unspecified_bg,
2159 SCHARS (XCDR (elt))) == 0)
2160 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2162 else
2163 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2164 store_in_alist (&alist, intern ("font"),
2165 build_string (FRAME_MSDOS_P (f)
2166 ? "ms-dos"
2167 : FRAME_W32_P (f) ? "w32term"
2168 :"tty"));
2170 store_in_alist (&alist, Qname, f->name);
2171 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2172 store_in_alist (&alist, Qheight, make_number (height));
2173 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2174 store_in_alist (&alist, Qwidth, make_number (width));
2175 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2176 store_in_alist (&alist, Qminibuffer,
2177 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2178 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2179 : FRAME_MINIBUF_WINDOW (f)));
2180 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2181 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2182 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2184 /* I think this should be done with a hook. */
2185 #ifdef HAVE_WINDOW_SYSTEM
2186 if (FRAME_WINDOW_P (f))
2187 x_report_frame_params (f, &alist);
2188 else
2189 #endif
2191 /* This ought to be correct in f->param_alist for an X frame. */
2192 Lisp_Object lines;
2193 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2194 store_in_alist (&alist, Qmenu_bar_lines, lines);
2197 UNGCPRO;
2198 return alist;
2202 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2203 doc: /* Return FRAME's value for parameter PARAMETER.
2204 If FRAME is nil, describe the currently selected frame. */)
2205 (Lisp_Object frame, Lisp_Object parameter)
2207 struct frame *f = decode_any_frame (frame);
2208 Lisp_Object value = Qnil;
2210 CHECK_SYMBOL (parameter);
2212 XSETFRAME (frame, f);
2214 if (FRAME_LIVE_P (f))
2216 /* Avoid consing in frequent cases. */
2217 if (EQ (parameter, Qname))
2218 value = f->name;
2219 #ifdef HAVE_X_WINDOWS
2220 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2221 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2222 #endif /* HAVE_X_WINDOWS */
2223 else if (EQ (parameter, Qbackground_color)
2224 || EQ (parameter, Qforeground_color))
2226 value = Fassq (parameter, f->param_alist);
2227 if (CONSP (value))
2229 value = XCDR (value);
2230 /* Fframe_parameters puts the actual fg/bg color names,
2231 even if f->param_alist says otherwise. This is
2232 important when param_alist's notion of colors is
2233 "unspecified". We need to do the same here. */
2234 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2236 const char *color_name;
2237 ptrdiff_t csz;
2239 if (EQ (parameter, Qbackground_color))
2241 color_name = SSDATA (value);
2242 csz = SCHARS (value);
2243 if (strncmp (color_name, unspecified_bg, csz) == 0)
2244 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2245 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2246 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2248 else if (EQ (parameter, Qforeground_color))
2250 color_name = SSDATA (value);
2251 csz = SCHARS (value);
2252 if (strncmp (color_name, unspecified_fg, csz) == 0)
2253 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2254 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2255 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2259 else
2260 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2262 else if (EQ (parameter, Qdisplay_type)
2263 || EQ (parameter, Qbackground_mode))
2264 value = Fcdr (Fassq (parameter, f->param_alist));
2265 else
2266 /* FIXME: Avoid this code path at all (as well as code duplication)
2267 by sharing more code with Fframe_parameters. */
2268 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2271 return value;
2275 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2276 Smodify_frame_parameters, 2, 2, 0,
2277 doc: /* Modify the parameters of frame FRAME according to ALIST.
2278 If FRAME is nil, it defaults to the selected frame.
2279 ALIST is an alist of parameters to change and their new values.
2280 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2281 The meaningful PARMs depend on the kind of frame.
2282 Undefined PARMs are ignored, but stored in the frame's parameter list
2283 so that `frame-parameters' will return them.
2285 The value of frame parameter FOO can also be accessed
2286 as a frame-local binding for the variable FOO, if you have
2287 enabled such bindings for that variable with `make-variable-frame-local'.
2288 Note that this functionality is obsolete as of Emacs 22.2, and its
2289 use is not recommended. Explicitly check for a frame-parameter instead. */)
2290 (Lisp_Object frame, Lisp_Object alist)
2292 struct frame *f = decode_live_frame (frame);
2293 register Lisp_Object prop, val;
2295 CHECK_LIST (alist);
2297 /* I think this should be done with a hook. */
2298 #ifdef HAVE_WINDOW_SYSTEM
2299 if (FRAME_WINDOW_P (f))
2300 x_set_frame_parameters (f, alist);
2301 else
2302 #endif
2303 #ifdef MSDOS
2304 if (FRAME_MSDOS_P (f))
2305 IT_set_frame_parameters (f, alist);
2306 else
2307 #endif
2310 EMACS_INT length = XFASTINT (Flength (alist));
2311 ptrdiff_t i;
2312 Lisp_Object *parms;
2313 Lisp_Object *values;
2314 USE_SAFE_ALLOCA;
2315 SAFE_ALLOCA_LISP (parms, 2 * length);
2316 values = parms + length;
2318 /* Extract parm names and values into those vectors. */
2320 for (i = 0; CONSP (alist); alist = XCDR (alist))
2322 Lisp_Object elt;
2324 elt = XCAR (alist);
2325 parms[i] = Fcar (elt);
2326 values[i] = Fcdr (elt);
2327 i++;
2330 /* Now process them in reverse of specified order. */
2331 while (--i >= 0)
2333 prop = parms[i];
2334 val = values[i];
2335 store_frame_param (f, prop, val);
2337 if (EQ (prop, Qforeground_color)
2338 || EQ (prop, Qbackground_color))
2339 update_face_from_frame_parameter (f, prop, val);
2342 SAFE_FREE ();
2344 return Qnil;
2347 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2348 0, 1, 0,
2349 doc: /* Height in pixels of a line in the font in frame FRAME.
2350 If FRAME is omitted or nil, the selected frame is used.
2351 For a terminal frame, the value is always 1. */)
2352 (Lisp_Object frame)
2354 #ifdef HAVE_WINDOW_SYSTEM
2355 struct frame *f = decode_any_frame (frame);
2357 if (FRAME_WINDOW_P (f))
2358 return make_number (FRAME_LINE_HEIGHT (f));
2359 else
2360 #endif
2361 return make_number (1);
2365 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2366 0, 1, 0,
2367 doc: /* Width in pixels of characters in the font in frame FRAME.
2368 If FRAME is omitted or nil, the selected frame is used.
2369 On a graphical screen, the width is the standard width of the default font.
2370 For a terminal screen, the value is always 1. */)
2371 (Lisp_Object frame)
2373 #ifdef HAVE_WINDOW_SYSTEM
2374 struct frame *f = decode_any_frame (frame);
2376 if (FRAME_WINDOW_P (f))
2377 return make_number (FRAME_COLUMN_WIDTH (f));
2378 else
2379 #endif
2380 return make_number (1);
2383 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2384 Sframe_pixel_height, 0, 1, 0,
2385 doc: /* Return a FRAME's height in pixels.
2386 If FRAME is omitted or nil, the selected frame is used. The exact value
2387 of the result depends on the window-system and toolkit in use:
2389 In the Gtk+ version of Emacs, it includes only any window (including
2390 the minibuffer or echo area), mode line, and header line. It does not
2391 include the tool bar or menu bar.
2393 With other graphical versions, it also includes the tool bar and the
2394 menu bar.
2396 For a text terminal, it includes the menu bar. In this case, the
2397 result is really in characters rather than pixels (i.e., is identical
2398 to `frame-height'). */)
2399 (Lisp_Object frame)
2401 struct frame *f = decode_any_frame (frame);
2403 #ifdef HAVE_WINDOW_SYSTEM
2404 if (FRAME_WINDOW_P (f))
2405 return make_number (FRAME_PIXEL_HEIGHT (f));
2406 else
2407 #endif
2408 return make_number (FRAME_LINES (f));
2411 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2412 Sframe_pixel_width, 0, 1, 0,
2413 doc: /* Return FRAME's width in pixels.
2414 For a terminal frame, the result really gives the width in characters.
2415 If FRAME is omitted or nil, the selected frame is used. */)
2416 (Lisp_Object frame)
2418 struct frame *f = decode_any_frame (frame);
2420 #ifdef HAVE_WINDOW_SYSTEM
2421 if (FRAME_WINDOW_P (f))
2422 return make_number (FRAME_PIXEL_WIDTH (f));
2423 else
2424 #endif
2425 return make_number (FRAME_COLS (f));
2428 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2429 Stool_bar_pixel_width, 0, 1, 0,
2430 doc: /* Return width in pixels of FRAME's tool bar.
2431 The result is greater than zero only when the tool bar is on the left
2432 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2433 is used. */)
2434 (Lisp_Object frame)
2436 #ifdef FRAME_TOOLBAR_WIDTH
2437 struct frame *f = decode_any_frame (frame);
2439 if (FRAME_WINDOW_P (f))
2440 return make_number (FRAME_TOOLBAR_WIDTH (f));
2441 #endif
2442 return make_number (0);
2445 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2446 doc: /* Specify that the frame FRAME has LINES lines.
2447 If FRAME is nil, the selected frame is used. Optional third arg
2448 non-nil means that redisplay should use LINES lines but that the
2449 idea of the actual height of the frame should not be changed. */)
2450 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend)
2452 register struct frame *f = decode_live_frame (frame);
2454 CHECK_TYPE_RANGED_INTEGER (int, lines);
2456 /* I think this should be done with a hook. */
2457 #ifdef HAVE_WINDOW_SYSTEM
2458 if (FRAME_WINDOW_P (f))
2460 if (XINT (lines) != FRAME_LINES (f))
2461 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2462 do_pending_window_change (0);
2464 else
2465 #endif
2466 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2467 return Qnil;
2470 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2471 doc: /* Specify that the frame FRAME has COLS columns.
2472 If FRAME is nil, the selected frame is used. Optional third arg
2473 non-nil means that redisplay should use COLS columns but that the
2474 idea of the actual width of the frame should not be changed. */)
2475 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2477 register struct frame *f = decode_live_frame (frame);
2479 CHECK_TYPE_RANGED_INTEGER (int, cols);
2481 /* I think this should be done with a hook. */
2482 #ifdef HAVE_WINDOW_SYSTEM
2483 if (FRAME_WINDOW_P (f))
2485 if (XINT (cols) != FRAME_COLS (f))
2486 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2487 do_pending_window_change (0);
2489 else
2490 #endif
2491 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2492 return Qnil;
2495 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2496 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters.
2497 If FRAME is nil, the selected frame is used. */)
2498 (Lisp_Object frame, Lisp_Object cols, Lisp_Object rows)
2500 register struct frame *f = decode_live_frame (frame);
2502 CHECK_TYPE_RANGED_INTEGER (int, cols);
2503 CHECK_TYPE_RANGED_INTEGER (int, rows);
2505 /* I think this should be done with a hook. */
2506 #ifdef HAVE_WINDOW_SYSTEM
2507 if (FRAME_WINDOW_P (f))
2509 if (XINT (rows) != FRAME_LINES (f)
2510 || XINT (cols) != FRAME_COLS (f)
2511 || f->new_text_lines || f->new_text_cols)
2512 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2513 do_pending_window_change (0);
2515 else
2516 #endif
2517 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2519 return Qnil;
2522 DEFUN ("set-frame-position", Fset_frame_position,
2523 Sset_frame_position, 3, 3, 0,
2524 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2525 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2526 actually the position of the upper left corner of the frame. Negative
2527 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2528 or bottommost possible position (that stays within the screen). */)
2529 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2531 register struct frame *f = decode_live_frame (frame);
2533 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2534 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2536 /* I think this should be done with a hook. */
2537 #ifdef HAVE_WINDOW_SYSTEM
2538 if (FRAME_WINDOW_P (f))
2539 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2540 #endif
2542 return Qt;
2546 /***********************************************************************
2547 Frame Parameters
2548 ***********************************************************************/
2550 /* Connect the frame-parameter names for X frames
2551 to the ways of passing the parameter values to the window system.
2553 The name of a parameter, as a Lisp symbol,
2554 has an `x-frame-parameter' property which is an integer in Lisp
2555 that is an index in this table. */
2557 struct frame_parm_table {
2558 const char *name;
2559 Lisp_Object *variable;
2562 static const struct frame_parm_table frame_parms[] =
2564 {"auto-raise", &Qauto_raise},
2565 {"auto-lower", &Qauto_lower},
2566 {"background-color", 0},
2567 {"border-color", &Qborder_color},
2568 {"border-width", &Qborder_width},
2569 {"cursor-color", &Qcursor_color},
2570 {"cursor-type", &Qcursor_type},
2571 {"font", 0},
2572 {"foreground-color", 0},
2573 {"icon-name", &Qicon_name},
2574 {"icon-type", &Qicon_type},
2575 {"internal-border-width", &Qinternal_border_width},
2576 {"menu-bar-lines", &Qmenu_bar_lines},
2577 {"mouse-color", &Qmouse_color},
2578 {"name", &Qname},
2579 {"scroll-bar-width", &Qscroll_bar_width},
2580 {"title", &Qtitle},
2581 {"unsplittable", &Qunsplittable},
2582 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2583 {"visibility", &Qvisibility},
2584 {"tool-bar-lines", &Qtool_bar_lines},
2585 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2586 {"scroll-bar-background", &Qscroll_bar_background},
2587 {"screen-gamma", &Qscreen_gamma},
2588 {"line-spacing", &Qline_spacing},
2589 {"left-fringe", &Qleft_fringe},
2590 {"right-fringe", &Qright_fringe},
2591 {"wait-for-wm", &Qwait_for_wm},
2592 {"fullscreen", &Qfullscreen},
2593 {"font-backend", &Qfont_backend},
2594 {"alpha", &Qalpha},
2595 {"sticky", &Qsticky},
2596 {"tool-bar-position", &Qtool_bar_position},
2599 #ifdef HAVE_NTGUI
2601 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2602 wanted positions of the WM window (not Emacs window).
2603 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2604 window (FRAME_X_WINDOW).
2607 void
2608 x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
2610 int newwidth = FRAME_COLS (f);
2611 int newheight = FRAME_LINES (f);
2612 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
2614 *top_pos = f->top_pos;
2615 *left_pos = f->left_pos;
2617 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2619 int ph;
2621 ph = x_display_pixel_height (dpyinfo);
2622 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2623 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2624 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2625 *top_pos = 0;
2628 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2630 int pw;
2632 pw = x_display_pixel_width (dpyinfo);
2633 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2634 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2635 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2636 *left_pos = 0;
2639 *width = newwidth;
2640 *height = newheight;
2643 #endif /* HAVE_NTGUI */
2645 #ifdef HAVE_WINDOW_SYSTEM
2647 /* Change the parameters of frame F as specified by ALIST.
2648 If a parameter is not specially recognized, do nothing special;
2649 otherwise call the `x_set_...' function for that parameter.
2650 Except for certain geometry properties, always call store_frame_param
2651 to store the new value in the parameter alist. */
2653 void
2654 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
2656 Lisp_Object tail;
2658 /* If both of these parameters are present, it's more efficient to
2659 set them both at once. So we wait until we've looked at the
2660 entire list before we set them. */
2661 int width, height;
2663 /* Same here. */
2664 Lisp_Object left, top;
2666 /* Same with these. */
2667 Lisp_Object icon_left, icon_top;
2669 /* Record in these vectors all the parms specified. */
2670 Lisp_Object *parms;
2671 Lisp_Object *values;
2672 ptrdiff_t i, p;
2673 bool left_no_change = 0, top_no_change = 0;
2674 bool icon_left_no_change = 0, icon_top_no_change = 0;
2675 bool size_changed = 0;
2676 struct gcpro gcpro1, gcpro2;
2678 i = 0;
2679 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2680 i++;
2682 parms = alloca (i * sizeof *parms);
2683 values = alloca (i * sizeof *values);
2685 /* Extract parm names and values into those vectors. */
2687 i = 0;
2688 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2690 Lisp_Object elt;
2692 elt = XCAR (tail);
2693 parms[i] = Fcar (elt);
2694 values[i] = Fcdr (elt);
2695 i++;
2697 /* TAIL and ALIST are not used again below here. */
2698 alist = tail = Qnil;
2700 GCPRO2 (*parms, *values);
2701 gcpro1.nvars = i;
2702 gcpro2.nvars = i;
2704 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2705 because their values appear in VALUES and strings are not valid. */
2706 top = left = Qunbound;
2707 icon_left = icon_top = Qunbound;
2709 /* Provide default values for HEIGHT and WIDTH. */
2710 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2711 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2713 /* Process foreground_color and background_color before anything else.
2714 They are independent of other properties, but other properties (e.g.,
2715 cursor_color) are dependent upon them. */
2716 /* Process default font as well, since fringe widths depends on it. */
2717 for (p = 0; p < i; p++)
2719 Lisp_Object prop, val;
2721 prop = parms[p];
2722 val = values[p];
2723 if (EQ (prop, Qforeground_color)
2724 || EQ (prop, Qbackground_color)
2725 || EQ (prop, Qfont))
2727 register Lisp_Object param_index, old_value;
2729 old_value = get_frame_param (f, prop);
2730 if (NILP (Fequal (val, old_value)))
2732 store_frame_param (f, prop, val);
2734 param_index = Fget (prop, Qx_frame_parameter);
2735 if (NATNUMP (param_index)
2736 && (XFASTINT (param_index)
2737 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2738 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2739 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2744 /* Now process them in reverse of specified order. */
2745 while (i-- != 0)
2747 Lisp_Object prop, val;
2749 prop = parms[i];
2750 val = values[i];
2752 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
2754 size_changed = 1;
2755 width = XFASTINT (val);
2757 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
2759 size_changed = 1;
2760 height = XFASTINT (val);
2762 else if (EQ (prop, Qtop))
2763 top = val;
2764 else if (EQ (prop, Qleft))
2765 left = val;
2766 else if (EQ (prop, Qicon_top))
2767 icon_top = val;
2768 else if (EQ (prop, Qicon_left))
2769 icon_left = val;
2770 else if (EQ (prop, Qforeground_color)
2771 || EQ (prop, Qbackground_color)
2772 || EQ (prop, Qfont))
2773 /* Processed above. */
2774 continue;
2775 else
2777 register Lisp_Object param_index, old_value;
2779 old_value = get_frame_param (f, prop);
2781 store_frame_param (f, prop, val);
2783 param_index = Fget (prop, Qx_frame_parameter);
2784 if (NATNUMP (param_index)
2785 && (XFASTINT (param_index)
2786 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2787 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2788 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2792 /* Don't die if just one of these was set. */
2793 if (EQ (left, Qunbound))
2795 left_no_change = 1;
2796 if (f->left_pos < 0)
2797 left = list2 (Qplus, make_number (f->left_pos));
2798 else
2799 XSETINT (left, f->left_pos);
2801 if (EQ (top, Qunbound))
2803 top_no_change = 1;
2804 if (f->top_pos < 0)
2805 top = list2 (Qplus, make_number (f->top_pos));
2806 else
2807 XSETINT (top, f->top_pos);
2810 /* If one of the icon positions was not set, preserve or default it. */
2811 if (! TYPE_RANGED_INTEGERP (int, icon_left))
2813 icon_left_no_change = 1;
2814 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2815 if (NILP (icon_left))
2816 XSETINT (icon_left, 0);
2818 if (! TYPE_RANGED_INTEGERP (int, icon_top))
2820 icon_top_no_change = 1;
2821 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2822 if (NILP (icon_top))
2823 XSETINT (icon_top, 0);
2826 /* Don't set these parameters unless they've been explicitly
2827 specified. The window might be mapped or resized while we're in
2828 this function, and we don't want to override that unless the lisp
2829 code has asked for it.
2831 Don't set these parameters unless they actually differ from the
2832 window's current parameters; the window may not actually exist
2833 yet. */
2835 Lisp_Object frame;
2837 check_frame_size (f, &height, &width);
2839 XSETFRAME (frame, f);
2841 if (size_changed
2842 && (width != FRAME_COLS (f)
2843 || height != FRAME_LINES (f)
2844 || f->new_text_lines || f->new_text_cols))
2845 Fset_frame_size (frame, make_number (width), make_number (height));
2847 if ((!NILP (left) || !NILP (top))
2848 && ! (left_no_change && top_no_change)
2849 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2850 && NUMBERP (top) && XINT (top) == f->top_pos))
2852 int leftpos = 0;
2853 int toppos = 0;
2855 /* Record the signs. */
2856 f->size_hint_flags &= ~ (XNegative | YNegative);
2857 if (EQ (left, Qminus))
2858 f->size_hint_flags |= XNegative;
2859 else if (TYPE_RANGED_INTEGERP (int, left))
2861 leftpos = XINT (left);
2862 if (leftpos < 0)
2863 f->size_hint_flags |= XNegative;
2865 else if (CONSP (left) && EQ (XCAR (left), Qminus)
2866 && CONSP (XCDR (left))
2867 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
2869 leftpos = - XINT (XCAR (XCDR (left)));
2870 f->size_hint_flags |= XNegative;
2872 else if (CONSP (left) && EQ (XCAR (left), Qplus)
2873 && CONSP (XCDR (left))
2874 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
2876 leftpos = XINT (XCAR (XCDR (left)));
2879 if (EQ (top, Qminus))
2880 f->size_hint_flags |= YNegative;
2881 else if (TYPE_RANGED_INTEGERP (int, top))
2883 toppos = XINT (top);
2884 if (toppos < 0)
2885 f->size_hint_flags |= YNegative;
2887 else if (CONSP (top) && EQ (XCAR (top), Qminus)
2888 && CONSP (XCDR (top))
2889 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
2891 toppos = - XINT (XCAR (XCDR (top)));
2892 f->size_hint_flags |= YNegative;
2894 else if (CONSP (top) && EQ (XCAR (top), Qplus)
2895 && CONSP (XCDR (top))
2896 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
2898 toppos = XINT (XCAR (XCDR (top)));
2902 /* Store the numeric value of the position. */
2903 f->top_pos = toppos;
2904 f->left_pos = leftpos;
2906 f->win_gravity = NorthWestGravity;
2908 /* Actually set that position, and convert to absolute. */
2909 x_set_offset (f, leftpos, toppos, -1);
2911 #ifdef HAVE_X_WINDOWS
2912 if ((!NILP (icon_left) || !NILP (icon_top))
2913 && ! (icon_left_no_change && icon_top_no_change))
2914 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
2915 #endif /* HAVE_X_WINDOWS */
2918 UNGCPRO;
2922 /* Insert a description of internally-recorded parameters of frame X
2923 into the parameter alist *ALISTPTR that is to be given to the user.
2924 Only parameters that are specific to the X window system
2925 and whose values are not correctly recorded in the frame's
2926 param_alist need to be considered here. */
2928 void
2929 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
2931 Lisp_Object tem;
2932 uprintmax_t w;
2933 char buf[INT_BUFSIZE_BOUND (w)];
2935 /* Represent negative positions (off the top or left screen edge)
2936 in a way that Fmodify_frame_parameters will understand correctly. */
2937 XSETINT (tem, f->left_pos);
2938 if (f->left_pos >= 0)
2939 store_in_alist (alistptr, Qleft, tem);
2940 else
2941 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
2943 XSETINT (tem, f->top_pos);
2944 if (f->top_pos >= 0)
2945 store_in_alist (alistptr, Qtop, tem);
2946 else
2947 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
2949 store_in_alist (alistptr, Qborder_width,
2950 make_number (f->border_width));
2951 store_in_alist (alistptr, Qinternal_border_width,
2952 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
2953 store_in_alist (alistptr, Qleft_fringe,
2954 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
2955 store_in_alist (alistptr, Qright_fringe,
2956 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
2957 store_in_alist (alistptr, Qscroll_bar_width,
2958 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
2959 ? make_number (0)
2960 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
2961 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
2962 /* nil means "use default width"
2963 for non-toolkit scroll bar.
2964 ruler-mode.el depends on this. */
2965 : Qnil));
2966 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
2967 MS-Windows it returns a value whose type is HANDLE, which is
2968 actually a pointer. Explicit casting avoids compiler
2969 warnings. */
2970 w = (uintptr_t) FRAME_X_WINDOW (f);
2971 store_in_alist (alistptr, Qwindow_id,
2972 make_formatted_string (buf, "%"pMu, w));
2973 #ifdef HAVE_X_WINDOWS
2974 #ifdef USE_X_TOOLKIT
2975 /* Tooltip frame may not have this widget. */
2976 if (FRAME_X_OUTPUT (f)->widget)
2977 #endif
2978 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
2979 store_in_alist (alistptr, Qouter_window_id,
2980 make_formatted_string (buf, "%"pMu, w));
2981 #endif
2982 store_in_alist (alistptr, Qicon_name, f->icon_name);
2983 store_in_alist (alistptr, Qvisibility,
2984 (FRAME_VISIBLE_P (f) ? Qt
2985 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
2986 store_in_alist (alistptr, Qdisplay,
2987 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
2989 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
2990 tem = Qnil;
2991 else
2992 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
2993 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
2994 store_in_alist (alistptr, Qparent_id, tem);
2995 store_in_alist (alistptr, Qtool_bar_position, f->tool_bar_position);
2999 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3000 the previous value of that parameter, NEW_VALUE is the new value. */
3002 void
3003 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3005 if (NILP (new_value))
3006 f->want_fullscreen = FULLSCREEN_NONE;
3007 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3008 f->want_fullscreen = FULLSCREEN_BOTH;
3009 else if (EQ (new_value, Qfullwidth))
3010 f->want_fullscreen = FULLSCREEN_WIDTH;
3011 else if (EQ (new_value, Qfullheight))
3012 f->want_fullscreen = FULLSCREEN_HEIGHT;
3013 else if (EQ (new_value, Qmaximized))
3014 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3016 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3017 FRAME_TERMINAL (f)->fullscreen_hook (f);
3021 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3022 the previous value of that parameter, NEW_VALUE is the new value. */
3024 void
3025 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3027 if (NILP (new_value))
3028 f->extra_line_spacing = 0;
3029 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3030 f->extra_line_spacing = XFASTINT (new_value);
3031 else if (FLOATP (new_value))
3033 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3035 if (new_spacing >= 0)
3036 f->extra_line_spacing = new_spacing;
3037 else
3038 signal_error ("Invalid line-spacing", new_value);
3040 else
3041 signal_error ("Invalid line-spacing", new_value);
3042 if (FRAME_VISIBLE_P (f))
3043 redraw_frame (f);
3047 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3048 the previous value of that parameter, NEW_VALUE is the new value. */
3050 void
3051 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3053 Lisp_Object bgcolor;
3055 if (NILP (new_value))
3056 f->gamma = 0;
3057 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3058 /* The value 0.4545 is the normal viewing gamma. */
3059 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3060 else
3061 signal_error ("Invalid screen-gamma", new_value);
3063 /* Apply the new gamma value to the frame background. */
3064 bgcolor = Fassq (Qbackground_color, f->param_alist);
3065 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3067 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3068 if (NATNUMP (parm_index)
3069 && (XFASTINT (parm_index)
3070 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3071 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3072 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3073 (f, bgcolor, Qnil);
3076 Fclear_face_cache (Qnil);
3080 void
3081 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3083 Lisp_Object font_object;
3084 int fontset = -1;
3085 #ifdef HAVE_X_WINDOWS
3086 Lisp_Object font_param = arg;
3087 #endif
3089 /* Set the frame parameter back to the old value because we may
3090 fail to use ARG as the new parameter value. */
3091 store_frame_param (f, Qfont, oldval);
3093 /* ARG is a fontset name, a font name, a cons of fontset name and a
3094 font object, or a font object. In the last case, this function
3095 never fail. */
3096 if (STRINGP (arg))
3098 fontset = fs_query_fontset (arg, 0);
3099 if (fontset < 0)
3101 font_object = font_open_by_name (f, arg);
3102 if (NILP (font_object))
3103 error ("Font `%s' is not defined", SSDATA (arg));
3104 arg = AREF (font_object, FONT_NAME_INDEX);
3106 else if (fontset > 0)
3108 font_object = font_open_by_name (f, fontset_ascii (fontset));
3109 if (NILP (font_object))
3110 error ("Font `%s' is not defined", SDATA (arg));
3111 arg = AREF (font_object, FONT_NAME_INDEX);
3113 else
3114 error ("The default fontset can't be used for a frame font");
3116 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3118 /* This is the case that the ASCII font of F's fontset XCAR
3119 (arg) is changed to the font XCDR (arg) by
3120 `set-fontset-font'. */
3121 fontset = fs_query_fontset (XCAR (arg), 0);
3122 if (fontset < 0)
3123 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3124 font_object = XCDR (arg);
3125 arg = AREF (font_object, FONT_NAME_INDEX);
3126 #ifdef HAVE_X_WINDOWS
3127 font_param = Ffont_get (font_object, QCname);
3128 #endif
3130 else if (FONT_OBJECT_P (arg))
3132 font_object = arg;
3133 #ifdef HAVE_X_WINDOWS
3134 font_param = Ffont_get (font_object, QCname);
3135 #endif
3136 /* This is to store the XLFD font name in the frame parameter for
3137 backward compatibility. We should store the font-object
3138 itself in the future. */
3139 arg = AREF (font_object, FONT_NAME_INDEX);
3140 fontset = FRAME_FONTSET (f);
3141 /* Check if we can use the current fontset. If not, set FONTSET
3142 to -1 to generate a new fontset from FONT-OBJECT. */
3143 if (fontset >= 0)
3145 Lisp_Object ascii_font = fontset_ascii (fontset);
3146 Lisp_Object spec = font_spec_from_name (ascii_font);
3148 if (NILP (spec))
3149 signal_error ("Invalid font name", ascii_font);
3151 if (! font_match_p (spec, font_object))
3152 fontset = -1;
3155 else
3156 signal_error ("Invalid font", arg);
3158 if (! NILP (Fequal (font_object, oldval)))
3159 return;
3161 x_new_font (f, font_object, fontset);
3162 store_frame_param (f, Qfont, arg);
3163 #ifdef HAVE_X_WINDOWS
3164 store_frame_param (f, Qfont_param, font_param);
3165 #endif
3166 /* Recalculate toolbar height. */
3167 f->n_tool_bar_rows = 0;
3168 /* Ensure we redraw it. */
3169 clear_current_matrices (f);
3171 recompute_basic_faces (f);
3173 do_pending_window_change (0);
3175 /* We used to call face-set-after-frame-default here, but it leads to
3176 recursive calls (since that function can set the `default' face's
3177 font which in turns changes the frame's `font' parameter).
3178 Also I don't know what this call is meant to do, but it seems the
3179 wrong way to do it anyway (it does a lot more work than what seems
3180 reasonable in response to a change to `font'). */
3184 void
3185 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3187 if (! NILP (new_value)
3188 && !CONSP (new_value))
3190 char *p0, *p1;
3192 CHECK_STRING (new_value);
3193 p0 = p1 = SSDATA (new_value);
3194 new_value = Qnil;
3195 while (*p0)
3197 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3198 if (p0 < p1)
3199 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3200 new_value);
3201 if (*p1)
3203 int c;
3205 while ((c = *++p1) && c_isspace (c));
3207 p0 = p1;
3209 new_value = Fnreverse (new_value);
3212 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3213 return;
3215 if (FRAME_FONT (f))
3216 free_all_realized_faces (Qnil);
3218 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3219 if (NILP (new_value))
3221 if (NILP (old_value))
3222 error ("No font backend available");
3223 font_update_drivers (f, old_value);
3224 error ("None of specified font backends are available");
3226 store_frame_param (f, Qfont_backend, new_value);
3228 if (FRAME_FONT (f))
3230 Lisp_Object frame;
3232 XSETFRAME (frame, f);
3233 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3234 ++face_change_count;
3235 ++windows_or_buffers_changed;
3240 void
3241 x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3243 compute_fringe_widths (f, 1);
3244 #ifdef HAVE_X_WINDOWS
3245 /* Must adjust this so window managers report correct number of columns. */
3246 if (FRAME_X_WINDOW (f) != 0)
3247 x_wm_set_size_hint (f, 0, 0);
3248 #endif
3251 void
3252 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3254 CHECK_TYPE_RANGED_INTEGER (int, arg);
3256 if (XINT (arg) == f->border_width)
3257 return;
3259 if (FRAME_X_WINDOW (f) != 0)
3260 error ("Cannot change the border width of a frame");
3262 f->border_width = XINT (arg);
3265 void
3266 x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3268 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3270 CHECK_TYPE_RANGED_INTEGER (int, arg);
3271 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3272 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3273 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3275 #ifdef USE_X_TOOLKIT
3276 if (FRAME_X_OUTPUT (f)->edit_widget)
3277 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3278 #endif
3280 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3281 return;
3283 if (FRAME_X_WINDOW (f) != 0)
3285 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3286 SET_FRAME_GARBAGED (f);
3287 do_pending_window_change (0);
3289 else
3290 SET_FRAME_GARBAGED (f);
3293 void
3294 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3296 Lisp_Object frame;
3297 XSETFRAME (frame, f);
3299 if (NILP (value))
3300 Fmake_frame_invisible (frame, Qt);
3301 else if (EQ (value, Qicon))
3302 Ficonify_frame (frame);
3303 else
3304 Fmake_frame_visible (frame);
3307 void
3308 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3310 f->auto_raise = !EQ (Qnil, arg);
3313 void
3314 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3316 f->auto_lower = !EQ (Qnil, arg);
3319 void
3320 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3322 f->no_split = !NILP (arg);
3325 void
3326 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3328 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3329 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3330 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3331 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3333 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3334 = (NILP (arg)
3335 ? vertical_scroll_bar_none
3336 : EQ (Qleft, arg)
3337 ? vertical_scroll_bar_left
3338 : EQ (Qright, arg)
3339 ? vertical_scroll_bar_right
3340 : EQ (Qleft, Vdefault_frame_scroll_bars)
3341 ? vertical_scroll_bar_left
3342 : EQ (Qright, Vdefault_frame_scroll_bars)
3343 ? vertical_scroll_bar_right
3344 : vertical_scroll_bar_none);
3346 /* We set this parameter before creating the X window for the
3347 frame, so we can get the geometry right from the start.
3348 However, if the window hasn't been created yet, we shouldn't
3349 call x_set_window_size. */
3350 if (FRAME_X_WINDOW (f))
3351 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3352 do_pending_window_change (0);
3356 void
3357 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3359 int wid = FRAME_COLUMN_WIDTH (f);
3361 if (NILP (arg))
3363 x_set_scroll_bar_default_width (f);
3365 if (FRAME_X_WINDOW (f))
3366 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3367 do_pending_window_change (0);
3369 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3370 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3372 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3373 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3374 if (FRAME_X_WINDOW (f))
3375 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3376 do_pending_window_change (0);
3379 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3380 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3381 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3384 void
3385 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3387 double alpha = 1.0;
3388 double newval[2];
3389 int i;
3390 Lisp_Object item;
3392 for (i = 0; i < 2; i++)
3394 newval[i] = 1.0;
3395 if (CONSP (arg))
3397 item = CAR (arg);
3398 arg = CDR (arg);
3400 else
3401 item = arg;
3403 if (NILP (item))
3404 alpha = - 1.0;
3405 else if (FLOATP (item))
3407 alpha = XFLOAT_DATA (item);
3408 if (! (0 <= alpha && alpha <= 1.0))
3409 args_out_of_range (make_float (0.0), make_float (1.0));
3411 else if (INTEGERP (item))
3413 EMACS_INT ialpha = XINT (item);
3414 if (! (0 <= ialpha && alpha <= 100))
3415 args_out_of_range (make_number (0), make_number (100));
3416 alpha = ialpha / 100.0;
3418 else
3419 wrong_type_argument (Qnumberp, item);
3420 newval[i] = alpha;
3423 for (i = 0; i < 2; i++)
3424 f->alpha[i] = newval[i];
3426 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3427 block_input ();
3428 x_set_frame_alpha (f);
3429 unblock_input ();
3430 #endif
3432 return;
3435 #ifndef HAVE_NS
3437 /* Non-zero if mouse is grabbed on DPYINFO
3438 and we know the frame where it is. */
3440 bool x_mouse_grabbed (Display_Info *dpyinfo)
3442 return (dpyinfo->grabbed
3443 && dpyinfo->last_mouse_frame
3444 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
3447 /* Re-highlight something with mouse-face properties
3448 on DPYINFO using saved frame and mouse position. */
3450 void
3451 x_redo_mouse_highlight (Display_Info *dpyinfo)
3453 if (dpyinfo->last_mouse_motion_frame
3454 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
3455 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
3456 dpyinfo->last_mouse_motion_x,
3457 dpyinfo->last_mouse_motion_y);
3460 #endif /* HAVE_NS */
3462 /* Subroutines of creating an X frame. */
3464 /* Make sure that Vx_resource_name is set to a reasonable value.
3465 Fix it up, or set it to `emacs' if it is too hopeless. */
3467 void
3468 validate_x_resource_name (void)
3470 ptrdiff_t len = 0;
3471 /* Number of valid characters in the resource name. */
3472 ptrdiff_t good_count = 0;
3473 /* Number of invalid characters in the resource name. */
3474 ptrdiff_t bad_count = 0;
3475 Lisp_Object new;
3476 ptrdiff_t i;
3478 if (!STRINGP (Vx_resource_class))
3479 Vx_resource_class = build_string (EMACS_CLASS);
3481 if (STRINGP (Vx_resource_name))
3483 unsigned char *p = SDATA (Vx_resource_name);
3485 len = SBYTES (Vx_resource_name);
3487 /* Only letters, digits, - and _ are valid in resource names.
3488 Count the valid characters and count the invalid ones. */
3489 for (i = 0; i < len; i++)
3491 int c = p[i];
3492 if (! ((c >= 'a' && c <= 'z')
3493 || (c >= 'A' && c <= 'Z')
3494 || (c >= '0' && c <= '9')
3495 || c == '-' || c == '_'))
3496 bad_count++;
3497 else
3498 good_count++;
3501 else
3502 /* Not a string => completely invalid. */
3503 bad_count = 5, good_count = 0;
3505 /* If name is valid already, return. */
3506 if (bad_count == 0)
3507 return;
3509 /* If name is entirely invalid, or nearly so, or is so implausibly
3510 large that alloca might not work, use `emacs'. */
3511 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3513 Vx_resource_name = build_string ("emacs");
3514 return;
3517 /* Name is partly valid. Copy it and replace the invalid characters
3518 with underscores. */
3520 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3522 for (i = 0; i < len; i++)
3524 int c = SREF (new, i);
3525 if (! ((c >= 'a' && c <= 'z')
3526 || (c >= 'A' && c <= 'Z')
3527 || (c >= '0' && c <= '9')
3528 || c == '-' || c == '_'))
3529 SSET (new, i, '_');
3533 /* Get specified attribute from resource database RDB.
3534 See Fx_get_resource below for other parameters. */
3536 static Lisp_Object
3537 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3539 register char *value;
3540 char *name_key;
3541 char *class_key;
3543 CHECK_STRING (attribute);
3544 CHECK_STRING (class);
3546 if (!NILP (component))
3547 CHECK_STRING (component);
3548 if (!NILP (subclass))
3549 CHECK_STRING (subclass);
3550 if (NILP (component) != NILP (subclass))
3551 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3553 validate_x_resource_name ();
3555 /* Allocate space for the components, the dots which separate them,
3556 and the final '\0'. Make them big enough for the worst case. */
3557 name_key = alloca (SBYTES (Vx_resource_name)
3558 + (STRINGP (component)
3559 ? SBYTES (component) : 0)
3560 + SBYTES (attribute)
3561 + 3);
3563 class_key = alloca (SBYTES (Vx_resource_class)
3564 + SBYTES (class)
3565 + (STRINGP (subclass)
3566 ? SBYTES (subclass) : 0)
3567 + 3);
3569 /* Start with emacs.FRAMENAME for the name (the specific one)
3570 and with `Emacs' for the class key (the general one). */
3571 strcpy (name_key, SSDATA (Vx_resource_name));
3572 strcpy (class_key, SSDATA (Vx_resource_class));
3574 strcat (class_key, ".");
3575 strcat (class_key, SSDATA (class));
3577 if (!NILP (component))
3579 strcat (class_key, ".");
3580 strcat (class_key, SSDATA (subclass));
3582 strcat (name_key, ".");
3583 strcat (name_key, SSDATA (component));
3586 strcat (name_key, ".");
3587 strcat (name_key, SSDATA (attribute));
3589 value = x_get_string_resource (rdb, name_key, class_key);
3591 if (value && *value)
3592 return build_string (value);
3593 else
3594 return Qnil;
3598 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3599 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3600 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3601 class, where INSTANCE is the name under which Emacs was invoked, or
3602 the name specified by the `-name' or `-rn' command-line arguments.
3604 The optional arguments COMPONENT and SUBCLASS add to the key and the
3605 class, respectively. You must specify both of them or neither.
3606 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3607 and the class is `Emacs.CLASS.SUBCLASS'. */)
3608 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
3609 Lisp_Object subclass)
3611 check_window_system (NULL);
3613 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3614 attribute, class, component, subclass);
3617 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3619 Lisp_Object
3620 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
3621 Lisp_Object class, Lisp_Object component,
3622 Lisp_Object subclass)
3624 return xrdb_get_resource (dpyinfo->xrdb,
3625 attribute, class, component, subclass);
3628 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3629 /* Used when C code wants a resource value. */
3630 /* Called from oldXMenu/Create.c. */
3631 char *
3632 x_get_resource_string (const char *attribute, const char *class)
3634 char *result;
3635 struct frame *sf = SELECTED_FRAME ();
3636 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
3637 USE_SAFE_ALLOCA;
3639 /* Allocate space for the components, the dots which separate them,
3640 and the final '\0'. */
3641 char *name_key = SAFE_ALLOCA (invocation_namelen + strlen (attribute) + 2);
3642 char *class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2);
3644 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
3645 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3647 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
3648 name_key, class_key);
3649 SAFE_FREE ();
3650 return result;
3652 #endif
3654 /* Return the value of parameter PARAM.
3656 First search ALIST, then Vdefault_frame_alist, then the X defaults
3657 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3659 Convert the resource to the type specified by desired_type.
3661 If no default is specified, return Qunbound. If you call
3662 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3663 and don't let it get stored in any Lisp-visible variables! */
3665 Lisp_Object
3666 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
3667 const char *attribute, const char *class, enum resource_types type)
3669 register Lisp_Object tem;
3671 tem = Fassq (param, alist);
3673 if (!NILP (tem))
3675 /* If we find this parm in ALIST, clear it out
3676 so that it won't be "left over" at the end. */
3677 Lisp_Object tail;
3678 XSETCAR (tem, Qnil);
3679 /* In case the parameter appears more than once in the alist,
3680 clear it out. */
3681 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3682 if (CONSP (XCAR (tail))
3683 && EQ (XCAR (XCAR (tail)), param))
3684 XSETCAR (XCAR (tail), Qnil);
3686 else
3687 tem = Fassq (param, Vdefault_frame_alist);
3689 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3690 look in the X resources. */
3691 if (EQ (tem, Qnil))
3693 if (attribute && dpyinfo)
3695 tem = display_x_get_resource (dpyinfo,
3696 build_string (attribute),
3697 build_string (class),
3698 Qnil, Qnil);
3700 if (NILP (tem))
3701 return Qunbound;
3703 switch (type)
3705 case RES_TYPE_NUMBER:
3706 return make_number (atoi (SSDATA (tem)));
3708 case RES_TYPE_BOOLEAN_NUMBER:
3709 if (!strcmp (SSDATA (tem), "on")
3710 || !strcmp (SSDATA (tem), "true"))
3711 return make_number (1);
3712 return make_number (atoi (SSDATA (tem)));
3713 break;
3715 case RES_TYPE_FLOAT:
3716 return make_float (atof (SSDATA (tem)));
3718 case RES_TYPE_BOOLEAN:
3719 tem = Fdowncase (tem);
3720 if (!strcmp (SSDATA (tem), "on")
3721 #ifdef HAVE_NS
3722 || !strcmp (SSDATA (tem), "yes")
3723 #endif
3724 || !strcmp (SSDATA (tem), "true"))
3725 return Qt;
3726 else
3727 return Qnil;
3729 case RES_TYPE_STRING:
3730 return tem;
3732 case RES_TYPE_SYMBOL:
3733 /* As a special case, we map the values `true' and `on'
3734 to Qt, and `false' and `off' to Qnil. */
3736 Lisp_Object lower;
3737 lower = Fdowncase (tem);
3738 if (!strcmp (SSDATA (lower), "on")
3739 #ifdef HAVE_NS
3740 || !strcmp (SSDATA (lower), "yes")
3741 #endif
3742 || !strcmp (SSDATA (lower), "true"))
3743 return Qt;
3744 else if (!strcmp (SSDATA (lower), "off")
3745 #ifdef HAVE_NS
3746 || !strcmp (SSDATA (lower), "no")
3747 #endif
3748 || !strcmp (SSDATA (lower), "false"))
3749 return Qnil;
3750 else
3751 return Fintern (tem, Qnil);
3754 default:
3755 emacs_abort ();
3758 else
3759 return Qunbound;
3761 return Fcdr (tem);
3764 static Lisp_Object
3765 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
3766 const char *attribute, const char *class,
3767 enum resource_types type)
3769 return x_get_arg (FRAME_DISPLAY_INFO (f),
3770 alist, param, attribute, class, type);
3773 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3775 Lisp_Object
3776 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
3777 Lisp_Object param,
3778 const char *attribute, const char *class,
3779 enum resource_types type)
3781 Lisp_Object value;
3783 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
3784 attribute, class, type);
3785 if (! NILP (value) && ! EQ (value, Qunbound))
3786 store_frame_param (f, param, value);
3788 return value;
3792 /* Record in frame F the specified or default value according to ALIST
3793 of the parameter named PROP (a Lisp symbol).
3794 If no value is specified for PROP, look for an X default for XPROP
3795 on the frame named NAME.
3796 If that is not found either, use the value DEFLT. */
3798 Lisp_Object
3799 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
3800 Lisp_Object deflt, const char *xprop, const char *xclass,
3801 enum resource_types type)
3803 Lisp_Object tem;
3805 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3806 if (EQ (tem, Qunbound))
3807 tem = deflt;
3808 x_set_frame_parameters (f, list1 (Fcons (prop, tem)));
3809 return tem;
3813 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
3816 * XParseGeometry parses strings of the form
3817 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
3818 * width, height, xoffset, and yoffset are unsigned integers.
3819 * Example: "=80x24+300-49"
3820 * The equal sign is optional.
3821 * It returns a bitmask that indicates which of the four values
3822 * were actually found in the string. For each value found,
3823 * the corresponding argument is updated; for each value
3824 * not found, the corresponding argument is left unchanged.
3827 static int
3828 XParseGeometry (char *string,
3829 int *x, int *y,
3830 unsigned int *width, unsigned int *height)
3832 int mask = NoValue;
3833 char *strind;
3834 unsigned long int tempWidth, tempHeight;
3835 long int tempX, tempY;
3836 char *nextCharacter;
3838 if (string == NULL || *string == '\0')
3839 return mask;
3840 if (*string == '=')
3841 string++; /* ignore possible '=' at beg of geometry spec */
3843 strind = string;
3844 if (*strind != '+' && *strind != '-' && *strind != 'x')
3846 tempWidth = strtoul (strind, &nextCharacter, 10);
3847 if (strind == nextCharacter)
3848 return 0;
3849 strind = nextCharacter;
3850 mask |= WidthValue;
3853 if (*strind == 'x' || *strind == 'X')
3855 strind++;
3856 tempHeight = strtoul (strind, &nextCharacter, 10);
3857 if (strind == nextCharacter)
3858 return 0;
3859 strind = nextCharacter;
3860 mask |= HeightValue;
3863 if (*strind == '+' || *strind == '-')
3865 if (*strind == '-')
3866 mask |= XNegative;
3867 tempX = strtol (strind, &nextCharacter, 10);
3868 if (strind == nextCharacter)
3869 return 0;
3870 strind = nextCharacter;
3871 mask |= XValue;
3872 if (*strind == '+' || *strind == '-')
3874 if (*strind == '-')
3875 mask |= YNegative;
3876 tempY = strtol (strind, &nextCharacter, 10);
3877 if (strind == nextCharacter)
3878 return 0;
3879 strind = nextCharacter;
3880 mask |= YValue;
3884 /* If strind isn't at the end of the string then it's an invalid
3885 geometry specification. */
3887 if (*strind != '\0')
3888 return 0;
3890 if (mask & XValue)
3891 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
3892 if (mask & YValue)
3893 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
3894 if (mask & WidthValue)
3895 *width = min (tempWidth, UINT_MAX);
3896 if (mask & HeightValue)
3897 *height = min (tempHeight, UINT_MAX);
3898 return mask;
3901 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
3904 /* NS used to define x-parse-geometry in ns-win.el, but that confused
3905 make-docfile: the documentation string in ns-win.el was used for
3906 x-parse-geometry even in non-NS builds.
3908 With two definitions of x-parse-geometry in this file, various
3909 things still get confused (eg M-x apropos documentation), so that
3910 it is best if the two definitions just share the same doc-string.
3912 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3913 doc: /* Parse a display geometry string STRING.
3914 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3915 The properties returned may include `top', `left', `height', and `width'.
3916 For X, the value of `left' or `top' may be an integer,
3917 or a list (+ N) meaning N pixels relative to top/left corner,
3918 or a list (- N) meaning -N pixels relative to bottom/right corner.
3919 On Nextstep, this just calls `ns-parse-geometry'. */)
3920 (Lisp_Object string)
3922 int geometry, x, y;
3923 unsigned int width, height;
3924 Lisp_Object result;
3926 CHECK_STRING (string);
3928 #ifdef HAVE_NS
3929 if (strchr (SSDATA (string), ' ') != NULL)
3930 return call1 (Qns_parse_geometry, string);
3931 #endif
3932 geometry = XParseGeometry (SSDATA (string),
3933 &x, &y, &width, &height);
3934 result = Qnil;
3935 if (geometry & XValue)
3937 Lisp_Object element;
3939 if (x >= 0 && (geometry & XNegative))
3940 element = list3 (Qleft, Qminus, make_number (-x));
3941 else if (x < 0 && ! (geometry & XNegative))
3942 element = list3 (Qleft, Qplus, make_number (x));
3943 else
3944 element = Fcons (Qleft, make_number (x));
3945 result = Fcons (element, result);
3948 if (geometry & YValue)
3950 Lisp_Object element;
3952 if (y >= 0 && (geometry & YNegative))
3953 element = list3 (Qtop, Qminus, make_number (-y));
3954 else if (y < 0 && ! (geometry & YNegative))
3955 element = list3 (Qtop, Qplus, make_number (y));
3956 else
3957 element = Fcons (Qtop, make_number (y));
3958 result = Fcons (element, result);
3961 if (geometry & WidthValue)
3962 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3963 if (geometry & HeightValue)
3964 result = Fcons (Fcons (Qheight, make_number (height)), result);
3966 return result;
3970 /* Calculate the desired size and position of frame F.
3971 Return the flags saying which aspects were specified.
3973 Also set the win_gravity and size_hint_flags of F.
3975 Adjust height for toolbar if TOOLBAR_P is 1.
3977 This function does not make the coordinates positive. */
3979 #define DEFAULT_ROWS 35
3980 #define DEFAULT_COLS 80
3982 long
3983 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p)
3985 register Lisp_Object tem0, tem1, tem2;
3986 long window_prompting = 0;
3987 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
3989 /* Default values if we fall through.
3990 Actually, if that happens we should get
3991 window manager prompting. */
3992 SET_FRAME_COLS (f, DEFAULT_COLS);
3993 FRAME_LINES (f) = DEFAULT_ROWS;
3994 /* Window managers expect that if program-specified
3995 positions are not (0,0), they're intentional, not defaults. */
3996 f->top_pos = 0;
3997 f->left_pos = 0;
3999 /* Ensure that old new_text_cols and new_text_lines will not override the
4000 values set here. */
4001 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4002 f->new_text_cols = f->new_text_lines = 0;
4004 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4005 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4006 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4007 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4009 if (!EQ (tem0, Qunbound))
4011 CHECK_NUMBER (tem0);
4012 if (! (0 <= XINT (tem0) && XINT (tem0) <= INT_MAX))
4013 xsignal1 (Qargs_out_of_range, tem0);
4014 FRAME_LINES (f) = XINT (tem0);
4016 if (!EQ (tem1, Qunbound))
4018 CHECK_NUMBER (tem1);
4019 if (! (0 <= XINT (tem1) && XINT (tem1) <= INT_MAX))
4020 xsignal1 (Qargs_out_of_range, tem1);
4021 SET_FRAME_COLS (f, XINT (tem1));
4023 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4024 window_prompting |= USSize;
4025 else
4026 window_prompting |= PSize;
4029 f->scroll_bar_actual_width
4030 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4032 /* This used to be done _before_ calling x_figure_window_size, but
4033 since the height is reset here, this was really a no-op. I
4034 assume that moving it here does what Gerd intended (although he
4035 no longer can remember what that was... ++KFS, 2003-03-25. */
4037 /* Add the tool-bar height to the initial frame height so that the
4038 user gets a text display area of the size he specified with -g or
4039 via .Xdefaults. Later changes of the tool-bar height don't
4040 change the frame size. This is done so that users can create
4041 tall Emacs frames without having to guess how tall the tool-bar
4042 will get. */
4043 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4045 int margin, relief, bar_height;
4047 relief = (tool_bar_button_relief >= 0
4048 ? tool_bar_button_relief
4049 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4051 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4052 margin = XFASTINT (Vtool_bar_button_margin);
4053 else if (CONSP (Vtool_bar_button_margin)
4054 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4055 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4056 else
4057 margin = 0;
4059 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4060 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4063 compute_fringe_widths (f, 0);
4065 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4066 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4068 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4069 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4070 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4071 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4073 if (EQ (tem0, Qminus))
4075 f->top_pos = 0;
4076 window_prompting |= YNegative;
4078 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4079 && CONSP (XCDR (tem0))
4080 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem0)), INT_MAX))
4082 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4083 window_prompting |= YNegative;
4085 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4086 && CONSP (XCDR (tem0))
4087 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0))))
4089 f->top_pos = XINT (XCAR (XCDR (tem0)));
4091 else if (EQ (tem0, Qunbound))
4092 f->top_pos = 0;
4093 else
4095 CHECK_TYPE_RANGED_INTEGER (int, tem0);
4096 f->top_pos = XINT (tem0);
4097 if (f->top_pos < 0)
4098 window_prompting |= YNegative;
4101 if (EQ (tem1, Qminus))
4103 f->left_pos = 0;
4104 window_prompting |= XNegative;
4106 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4107 && CONSP (XCDR (tem1))
4108 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem1)), INT_MAX))
4110 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4111 window_prompting |= XNegative;
4113 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4114 && CONSP (XCDR (tem1))
4115 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1))))
4117 f->left_pos = XINT (XCAR (XCDR (tem1)));
4119 else if (EQ (tem1, Qunbound))
4120 f->left_pos = 0;
4121 else
4123 CHECK_TYPE_RANGED_INTEGER (int, tem1);
4124 f->left_pos = XINT (tem1);
4125 if (f->left_pos < 0)
4126 window_prompting |= XNegative;
4129 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4130 window_prompting |= USPosition;
4131 else
4132 window_prompting |= PPosition;
4135 if (window_prompting & XNegative)
4137 if (window_prompting & YNegative)
4138 f->win_gravity = SouthEastGravity;
4139 else
4140 f->win_gravity = NorthEastGravity;
4142 else
4144 if (window_prompting & YNegative)
4145 f->win_gravity = SouthWestGravity;
4146 else
4147 f->win_gravity = NorthWestGravity;
4150 f->size_hint_flags = window_prompting;
4152 return window_prompting;
4157 #endif /* HAVE_WINDOW_SYSTEM */
4159 void
4160 frame_make_pointer_invisible (void)
4162 if (! NILP (Vmake_pointer_invisible))
4164 struct frame *f;
4165 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4166 return;
4168 f = SELECTED_FRAME ();
4169 if (f && !f->pointer_invisible
4170 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4172 f->mouse_moved = 0;
4173 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4174 f->pointer_invisible = 1;
4179 void
4180 frame_make_pointer_visible (void)
4182 /* We don't check Vmake_pointer_invisible here in case the
4183 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4184 struct frame *f;
4186 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4187 return;
4189 f = SELECTED_FRAME ();
4190 if (f && f->pointer_invisible && f->mouse_moved
4191 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4193 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4194 f->pointer_invisible = 0;
4198 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4199 Sframe_pointer_visible_p, 0, 1, 0,
4200 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4201 Otherwise it returns nil. FRAME omitted or nil means the
4202 selected frame. This is useful when `make-pointer-invisible' is set. */)
4203 (Lisp_Object frame)
4205 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4210 /***********************************************************************
4211 Multimonitor data
4212 ***********************************************************************/
4214 #ifdef HAVE_WINDOW_SYSTEM
4216 # if (defined HAVE_NS \
4217 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4218 void
4219 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4221 int i;
4222 for (i = 0; i < n_monitors; ++i)
4223 xfree (monitors[i].name);
4224 xfree (monitors);
4226 # endif
4228 Lisp_Object
4229 make_monitor_attribute_list (struct MonitorInfo *monitors,
4230 int n_monitors,
4231 int primary_monitor,
4232 Lisp_Object monitor_frames,
4233 const char *source)
4235 Lisp_Object attributes_list = Qnil;
4236 Lisp_Object primary_monitor_attributes = Qnil;
4237 int i;
4239 for (i = 0; i < n_monitors; ++i)
4241 Lisp_Object geometry, workarea, attributes = Qnil;
4242 struct MonitorInfo *mi = &monitors[i];
4244 if (mi->geom.width == 0) continue;
4246 workarea = list4i (mi->work.x, mi->work.y,
4247 mi->work.width, mi->work.height);
4248 geometry = list4i (mi->geom.x, mi->geom.y,
4249 mi->geom.width, mi->geom.height);
4250 attributes = Fcons (Fcons (Qsource, build_string (source)),
4251 attributes);
4252 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4253 attributes);
4254 attributes = Fcons (Fcons (Qmm_size,
4255 list2i (mi->mm_width, mi->mm_height)),
4256 attributes);
4257 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4258 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4259 if (mi->name)
4260 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4261 strlen (mi->name))),
4262 attributes);
4264 if (i == primary_monitor)
4265 primary_monitor_attributes = attributes;
4266 else
4267 attributes_list = Fcons (attributes, attributes_list);
4270 if (!NILP (primary_monitor_attributes))
4271 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4272 return attributes_list;
4275 #endif /* HAVE_WINDOW_SYSTEM */
4278 /***********************************************************************
4279 Initialization
4280 ***********************************************************************/
4282 void
4283 syms_of_frame (void)
4285 DEFSYM (Qframep, "framep");
4286 DEFSYM (Qframe_live_p, "frame-live-p");
4287 DEFSYM (Qexplicit_name, "explicit-name");
4288 DEFSYM (Qheight, "height");
4289 DEFSYM (Qicon, "icon");
4290 DEFSYM (Qminibuffer, "minibuffer");
4291 DEFSYM (Qmodeline, "modeline");
4292 DEFSYM (Qonly, "only");
4293 DEFSYM (Qnone, "none");
4294 DEFSYM (Qwidth, "width");
4295 DEFSYM (Qgeometry, "geometry");
4296 DEFSYM (Qicon_left, "icon-left");
4297 DEFSYM (Qicon_top, "icon-top");
4298 DEFSYM (Qtooltip, "tooltip");
4299 DEFSYM (Qleft, "left");
4300 DEFSYM (Qright, "right");
4301 DEFSYM (Quser_position, "user-position");
4302 DEFSYM (Quser_size, "user-size");
4303 DEFSYM (Qwindow_id, "window-id");
4304 #ifdef HAVE_X_WINDOWS
4305 DEFSYM (Qouter_window_id, "outer-window-id");
4306 #endif
4307 DEFSYM (Qparent_id, "parent-id");
4308 DEFSYM (Qx, "x");
4309 DEFSYM (Qw32, "w32");
4310 DEFSYM (Qpc, "pc");
4311 DEFSYM (Qns, "ns");
4312 DEFSYM (Qvisible, "visible");
4313 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4314 DEFSYM (Qbuffer_list, "buffer-list");
4315 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4316 DEFSYM (Qdisplay_type, "display-type");
4317 DEFSYM (Qbackground_mode, "background-mode");
4318 DEFSYM (Qnoelisp, "noelisp");
4319 DEFSYM (Qtty_color_mode, "tty-color-mode");
4320 DEFSYM (Qtty, "tty");
4321 DEFSYM (Qtty_type, "tty-type");
4323 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4325 DEFSYM (Qfullwidth, "fullwidth");
4326 DEFSYM (Qfullheight, "fullheight");
4327 DEFSYM (Qfullboth, "fullboth");
4328 DEFSYM (Qmaximized, "maximized");
4329 DEFSYM (Qx_resource_name, "x-resource-name");
4330 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4332 DEFSYM (Qterminal, "terminal");
4334 DEFSYM (Qgeometry, "geometry");
4335 DEFSYM (Qworkarea, "workarea");
4336 DEFSYM (Qmm_size, "mm-size");
4337 DEFSYM (Qframes, "frames");
4338 DEFSYM (Qsource, "source");
4340 #ifdef HAVE_NS
4341 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4342 #endif
4345 int i;
4347 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4349 Lisp_Object v = intern_c_string (frame_parms[i].name);
4350 if (frame_parms[i].variable)
4352 *frame_parms[i].variable = v;
4353 staticpro (frame_parms[i].variable);
4355 Fput (v, Qx_frame_parameter, make_number (i));
4359 #ifdef HAVE_WINDOW_SYSTEM
4360 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4361 doc: /* The name Emacs uses to look up X resources.
4362 `x-get-resource' uses this as the first component of the instance name
4363 when requesting resource values.
4364 Emacs initially sets `x-resource-name' to the name under which Emacs
4365 was invoked, or to the value specified with the `-name' or `-rn'
4366 switches, if present.
4368 It may be useful to bind this variable locally around a call
4369 to `x-get-resource'. See also the variable `x-resource-class'. */);
4370 Vx_resource_name = Qnil;
4372 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4373 doc: /* The class Emacs uses to look up X resources.
4374 `x-get-resource' uses this as the first component of the instance class
4375 when requesting resource values.
4377 Emacs initially sets `x-resource-class' to "Emacs".
4379 Setting this variable permanently is not a reasonable thing to do,
4380 but binding this variable locally around a call to `x-get-resource'
4381 is a reasonable practice. See also the variable `x-resource-name'. */);
4382 Vx_resource_class = build_string (EMACS_CLASS);
4384 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4385 doc: /* The lower limit of the frame opacity (alpha transparency).
4386 The value should range from 0 (invisible) to 100 (completely opaque).
4387 You can also use a floating number between 0.0 and 1.0.
4388 The default is 20. */);
4389 Vframe_alpha_lower_limit = make_number (20);
4390 #endif
4392 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4393 doc: /* Alist of default values for frame creation.
4394 These may be set in your init file, like this:
4395 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4396 These override values given in window system configuration data,
4397 including X Windows' defaults database.
4398 For values specific to the first Emacs frame, see `initial-frame-alist'.
4399 For window-system specific values, see `window-system-default-frame-alist'.
4400 For values specific to the separate minibuffer frame, see
4401 `minibuffer-frame-alist'.
4402 The `menu-bar-lines' element of the list controls whether new frames
4403 have menu bars; `menu-bar-mode' works by altering this element.
4404 Setting this variable does not affect existing frames, only new ones. */);
4405 Vdefault_frame_alist = Qnil;
4407 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4408 doc: /* Default position of scroll bars on this window-system. */);
4409 #ifdef HAVE_WINDOW_SYSTEM
4410 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4411 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4412 default. */
4413 Vdefault_frame_scroll_bars = Qright;
4414 #else
4415 Vdefault_frame_scroll_bars = Qleft;
4416 #endif
4417 #else
4418 Vdefault_frame_scroll_bars = Qnil;
4419 #endif
4421 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
4422 scroll_bar_adjust_thumb_portion_p,
4423 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
4424 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
4425 even if the end of the buffer is shown (i.e. overscrolling).
4426 Set to nil if you want the thumb to be at the bottom when the end of the buffer
4427 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
4428 is visible. In this case you can not overscroll. */);
4429 scroll_bar_adjust_thumb_portion_p = 1;
4431 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4432 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4434 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4435 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4436 `mouse-position' calls this function, passing its usual return value as
4437 argument, and returns whatever this function returns.
4438 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4439 which need to do mouse handling at the Lisp level. */);
4440 Vmouse_position_function = Qnil;
4442 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4443 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4444 If the value is an integer, highlighting is only shown after moving the
4445 mouse, while keyboard input turns off the highlight even when the mouse
4446 is over the clickable text. However, the mouse shape still indicates
4447 when the mouse is over clickable text. */);
4448 Vmouse_highlight = Qt;
4450 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4451 doc: /* If non-nil, make pointer invisible while typing.
4452 The pointer becomes visible again when the mouse is moved. */);
4453 Vmake_pointer_invisible = Qt;
4455 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4456 doc: /* Functions run before deleting a frame.
4457 The functions are run with one arg, the frame to be deleted.
4458 See `delete-frame'.
4460 Note that functions in this list may be called just before the frame is
4461 actually deleted, or some time later (or even both when an earlier function
4462 in `delete-frame-functions' (indirectly) calls `delete-frame'
4463 recursively). */);
4464 Vdelete_frame_functions = Qnil;
4465 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4467 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4468 doc: /* Non-nil if Menu-Bar mode is enabled.
4469 See the command `menu-bar-mode' for a description of this minor mode.
4470 Setting this variable directly does not take effect;
4471 either customize it (see the info node `Easy Customization')
4472 or call the function `menu-bar-mode'. */);
4473 Vmenu_bar_mode = Qt;
4475 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4476 doc: /* Non-nil if Tool-Bar mode is enabled.
4477 See the command `tool-bar-mode' for a description of this minor mode.
4478 Setting this variable directly does not take effect;
4479 either customize it (see the info node `Easy Customization')
4480 or call the function `tool-bar-mode'. */);
4481 #ifdef HAVE_WINDOW_SYSTEM
4482 Vtool_bar_mode = Qt;
4483 #else
4484 Vtool_bar_mode = Qnil;
4485 #endif
4487 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4488 doc: /* Minibufferless frames use this frame's minibuffer.
4490 Emacs cannot create minibufferless frames unless this is set to an
4491 appropriate surrogate.
4493 Emacs consults this variable only when creating minibufferless
4494 frames; once the frame is created, it sticks with its assigned
4495 minibuffer, no matter what this variable is set to. This means that
4496 this variable doesn't necessarily say anything meaningful about the
4497 current set of frames, or where the minibuffer is currently being
4498 displayed.
4500 This variable is local to the current terminal and cannot be buffer-local. */);
4502 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4503 doc: /* Non-nil if window system changes focus when you move the mouse.
4504 You should set this variable to tell Emacs how your window manager
4505 handles focus, since there is no way in general for Emacs to find out
4506 automatically. See also `mouse-autoselect-window'. */);
4507 focus_follows_mouse = 0;
4509 staticpro (&Vframe_list);
4511 defsubr (&Sframep);
4512 defsubr (&Sframe_live_p);
4513 defsubr (&Swindow_system);
4514 defsubr (&Smake_terminal_frame);
4515 defsubr (&Shandle_switch_frame);
4516 defsubr (&Shandle_focus_in);
4517 defsubr (&Shandle_focus_out);
4518 defsubr (&Sselect_frame);
4519 defsubr (&Sselected_frame);
4520 defsubr (&Sframe_list);
4521 defsubr (&Snext_frame);
4522 defsubr (&Sprevious_frame);
4523 defsubr (&Slast_nonminibuf_frame);
4524 defsubr (&Sdelete_frame);
4525 defsubr (&Smouse_position);
4526 defsubr (&Smouse_pixel_position);
4527 defsubr (&Sset_mouse_position);
4528 defsubr (&Sset_mouse_pixel_position);
4529 #if 0
4530 defsubr (&Sframe_configuration);
4531 defsubr (&Srestore_frame_configuration);
4532 #endif
4533 defsubr (&Smake_frame_visible);
4534 defsubr (&Smake_frame_invisible);
4535 defsubr (&Siconify_frame);
4536 defsubr (&Sframe_visible_p);
4537 defsubr (&Svisible_frame_list);
4538 defsubr (&Sraise_frame);
4539 defsubr (&Slower_frame);
4540 defsubr (&Sx_focus_frame);
4541 defsubr (&Sredirect_frame_focus);
4542 defsubr (&Sframe_focus);
4543 defsubr (&Sframe_parameters);
4544 defsubr (&Sframe_parameter);
4545 defsubr (&Smodify_frame_parameters);
4546 defsubr (&Sframe_char_height);
4547 defsubr (&Sframe_char_width);
4548 defsubr (&Sframe_pixel_height);
4549 defsubr (&Sframe_pixel_width);
4550 defsubr (&Stool_bar_pixel_width);
4551 defsubr (&Sset_frame_height);
4552 defsubr (&Sset_frame_width);
4553 defsubr (&Sset_frame_size);
4554 defsubr (&Sset_frame_position);
4555 defsubr (&Sframe_pointer_visible_p);
4557 #ifdef HAVE_WINDOW_SYSTEM
4558 defsubr (&Sx_get_resource);
4559 defsubr (&Sx_parse_geometry);
4560 #endif