* eval.c (internal_lisp_condition_case): Don't overrun the stack
[emacs.git] / src / frame.c
blob0c13016435214ba34b96cbcead2b442814daa147
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2014 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <errno.h>
24 #include <limits.h>
26 #include <c-ctype.h>
28 #include "lisp.h"
29 #include "character.h"
31 #ifdef HAVE_WINDOW_SYSTEM
32 #include TERM_HEADER
33 #endif /* HAVE_WINDOW_SYSTEM */
35 #include "buffer.h"
36 /* These help us bind and responding to switch-frame events. */
37 #include "commands.h"
38 #include "keyboard.h"
39 #include "frame.h"
40 #include "blockinput.h"
41 #include "termchar.h"
42 #include "termhooks.h"
43 #include "dispextern.h"
44 #include "window.h"
45 #include "font.h"
46 #ifdef HAVE_WINDOW_SYSTEM
47 #include "fontset.h"
48 #endif
49 #include "cm.h"
50 #ifdef MSDOS
51 #include "msdos.h"
52 #include "dosfns.h"
53 #endif
55 #ifdef HAVE_NS
56 Lisp_Object Qns_parse_geometry;
57 #endif
59 Lisp_Object Qframep, Qframe_live_p;
60 Lisp_Object Qicon, Qmodeline;
61 Lisp_Object Qonly, Qnone;
62 Lisp_Object Qx, Qw32, Qpc, Qns;
63 Lisp_Object Qvisible;
64 Lisp_Object Qdisplay_type;
65 static Lisp_Object Qbackground_mode;
66 Lisp_Object Qnoelisp;
68 static Lisp_Object Qx_frame_parameter;
69 Lisp_Object Qx_resource_name;
70 Lisp_Object Qterminal;
72 /* Frame parameters (set or reported). */
74 Lisp_Object Qauto_raise, Qauto_lower;
75 Lisp_Object Qborder_color, Qborder_width;
76 Lisp_Object Qcursor_color, Qcursor_type;
77 Lisp_Object Qheight, Qwidth;
78 Lisp_Object Qleft, Qright;
79 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
80 Lisp_Object Qtooltip;
81 Lisp_Object Qinternal_border_width;
82 Lisp_Object Qright_divider_width, Qbottom_divider_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 Qfocus_in_hook;
115 static Lisp_Object Qfocus_out_hook;
116 static Lisp_Object Qdelete_frame_functions;
118 static Lisp_Object Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource;
120 /* The currently selected frame. */
122 Lisp_Object selected_frame;
124 /* A frame which is not just a mini-buffer, or NULL if there are no such
125 frames. This is usually the most recent such frame that was selected. */
127 static struct frame *last_nonminibuf_frame;
129 /* False means there are no visible garbaged frames. */
130 bool frame_garbaged;
132 #ifdef HAVE_WINDOW_SYSTEM
133 static void x_report_frame_params (struct frame *, Lisp_Object *);
134 #endif
136 /* These setters are used only in this file, so they can be private. */
137 static void
138 fset_buffer_predicate (struct frame *f, Lisp_Object val)
140 f->buffer_predicate = val;
142 static void
143 fset_minibuffer_window (struct frame *f, Lisp_Object val)
145 f->minibuffer_window = val;
148 struct frame *
149 decode_live_frame (register Lisp_Object frame)
151 if (NILP (frame))
152 frame = selected_frame;
153 CHECK_LIVE_FRAME (frame);
154 return XFRAME (frame);
157 struct frame *
158 decode_any_frame (register Lisp_Object frame)
160 if (NILP (frame))
161 frame = selected_frame;
162 CHECK_FRAME (frame);
163 return XFRAME (frame);
166 bool
167 window_system_available (struct frame *f)
169 if (f)
170 return FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f);
171 else
172 #ifdef HAVE_WINDOW_SYSTEM
173 return x_display_list != NULL;
174 #else
175 return 0;
176 #endif
179 struct frame *
180 decode_window_system_frame (Lisp_Object frame)
182 struct frame *f = decode_live_frame (frame);
184 if (!window_system_available (f))
185 error ("Window system frame should be used");
186 return f;
189 void
190 check_window_system (struct frame *f)
192 if (!window_system_available (f))
193 error (f ? "Window system frame should be used"
194 : "Window system is not in use or not initialized");
197 static void
198 set_menu_bar_lines_1 (Lisp_Object window, int n)
200 struct window *w = XWINDOW (window);
201 struct frame *f = XFRAME (WINDOW_FRAME (w));
203 w->top_line += n;
204 w->pixel_top += n * FRAME_LINE_HEIGHT (f);
205 w->total_lines -= n;
206 w->pixel_height -= n * FRAME_LINE_HEIGHT (f);
208 /* Handle just the top child in a vertical split. */
209 if (WINDOW_VERTICAL_COMBINATION_P (w))
210 set_menu_bar_lines_1 (w->contents, n);
211 else if (WINDOW_HORIZONTAL_COMBINATION_P (w))
212 /* Adjust all children in a horizontal split. */
213 for (window = w->contents; !NILP (window); window = w->next)
215 w = XWINDOW (window);
216 set_menu_bar_lines_1 (window, n);
220 void
221 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
223 int nlines;
224 int olines = FRAME_MENU_BAR_LINES (f);
226 /* Right now, menu bars don't work properly in minibuf-only frames;
227 most of the commands try to apply themselves to the minibuffer
228 frame itself, and get an error because you can't switch buffers
229 in or split the minibuffer window. */
230 if (FRAME_MINIBUF_ONLY_P (f))
231 return;
233 if (TYPE_RANGED_INTEGERP (int, value))
234 nlines = XINT (value);
235 else
236 nlines = 0;
238 if (nlines != olines)
240 windows_or_buffers_changed = 14;
241 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
242 FRAME_MENU_BAR_LINES (f) = nlines;
243 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
244 set_menu_bar_lines_1 (f->root_window, nlines - olines);
245 adjust_frame_glyphs (f);
249 Lisp_Object Vframe_list;
252 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
253 doc: /* Return non-nil if OBJECT is a frame.
254 Value is:
255 t for a termcap frame (a character-only terminal),
256 'x' for an Emacs frame that is really an X window,
257 'w32' for an Emacs frame that is a window on MS-Windows display,
258 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
259 'pc' for a direct-write MS-DOS frame.
260 See also `frame-live-p'. */)
261 (Lisp_Object object)
263 if (!FRAMEP (object))
264 return Qnil;
265 switch (XFRAME (object)->output_method)
267 case output_initial: /* The initial frame is like a termcap frame. */
268 case output_termcap:
269 return Qt;
270 case output_x_window:
271 return Qx;
272 case output_w32:
273 return Qw32;
274 case output_msdos_raw:
275 return Qpc;
276 case output_ns:
277 return Qns;
278 default:
279 emacs_abort ();
283 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
284 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
285 Value is nil if OBJECT is not a live frame. If object is a live
286 frame, the return value indicates what sort of terminal device it is
287 displayed on. See the documentation of `framep' for possible
288 return values. */)
289 (Lisp_Object object)
291 return ((FRAMEP (object)
292 && FRAME_LIVE_P (XFRAME (object)))
293 ? Fframep (object)
294 : Qnil);
297 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
298 doc: /* The name of the window system that FRAME is displaying through.
299 The value is a symbol:
300 nil for a termcap frame (a character-only terminal),
301 'x' for an Emacs frame that is really an X window,
302 'w32' for an Emacs frame that is a window on MS-Windows display,
303 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
304 'pc' for a direct-write MS-DOS frame.
306 FRAME defaults to the currently selected frame.
308 Use of this function as a predicate is deprecated. Instead,
309 use `display-graphic-p' or any of the other `display-*-p'
310 predicates which report frame's specific UI-related capabilities. */)
311 (Lisp_Object frame)
313 Lisp_Object type;
314 if (NILP (frame))
315 frame = selected_frame;
317 type = Fframep (frame);
319 if (NILP (type))
320 wrong_type_argument (Qframep, frame);
322 if (EQ (type, Qt))
323 return Qnil;
324 else
325 return type;
328 struct frame *
329 make_frame (bool mini_p)
331 Lisp_Object frame;
332 register struct frame *f;
333 register struct window *rw, *mw;
334 register Lisp_Object root_window;
335 register Lisp_Object mini_window;
337 f = allocate_frame ();
338 XSETFRAME (frame, f);
340 /* Initialize Lisp data. Note that allocate_frame initializes all
341 Lisp data to nil, so do it only for slots which should not be nil. */
342 fset_tool_bar_position (f, Qtop);
344 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
345 non-Lisp data, so do it only for slots which should not be zero.
346 To avoid subtle bugs and for the sake of readability, it's better to
347 initialize enum members explicitly even if their values are zero. */
348 f->wants_modeline = true;
349 f->redisplay = true;
350 f->garbaged = true;
351 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
352 f->column_width = 1; /* !FRAME_WINDOW_P value. */
353 f->line_height = 1; /* !FRAME_WINDOW_P value. */
354 #ifdef HAVE_WINDOW_SYSTEM
355 f->want_fullscreen = FULLSCREEN_NONE;
356 #endif
358 root_window = make_window ();
359 rw = XWINDOW (root_window);
360 if (mini_p)
362 mini_window = make_window ();
363 mw = XWINDOW (mini_window);
364 wset_next (rw, mini_window);
365 wset_prev (mw, root_window);
366 mw->mini = 1;
367 wset_frame (mw, frame);
368 fset_minibuffer_window (f, mini_window);
370 else
372 mini_window = Qnil;
373 wset_next (rw, Qnil);
374 fset_minibuffer_window (f, Qnil);
377 wset_frame (rw, frame);
379 /* 10 is arbitrary,
380 just so that there is "something there."
381 Correct size will be set up later with change_frame_size. */
383 SET_FRAME_COLS (f, 10);
384 FRAME_LINES (f) = 10;
385 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
386 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
388 rw->total_cols = 10;
389 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
390 rw->total_lines = mini_p ? 9 : 10;
391 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
393 if (mini_p)
395 mw->top_line = rw->total_lines;
396 mw->pixel_top = rw->pixel_height;
397 mw->total_cols = rw->total_cols;
398 mw->pixel_width = rw->pixel_width;
399 mw->total_lines = 1;
400 mw->pixel_height = FRAME_LINE_HEIGHT (f);
403 /* Choose a buffer for the frame's root window. */
405 Lisp_Object buf = Fcurrent_buffer ();
407 /* If current buffer is hidden, try to find another one. */
408 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
409 buf = other_buffer_safely (buf);
411 /* Use set_window_buffer, not Fset_window_buffer, and don't let
412 hooks be run by it. The reason is that the whole frame/window
413 arrangement is not yet fully initialized at this point. Windows
414 don't have the right size, glyph matrices aren't initialized
415 etc. Running Lisp functions at this point surely ends in a
416 SEGV. */
417 set_window_buffer (root_window, buf, 0, 0);
418 fset_buffer_list (f, list1 (buf));
421 if (mini_p)
422 set_window_buffer (mini_window,
423 (NILP (Vminibuffer_list)
424 ? get_minibuffer (0)
425 : Fcar (Vminibuffer_list)),
426 0, 0);
428 fset_root_window (f, root_window);
429 fset_selected_window (f, root_window);
430 /* Make sure this window seems more recently used than
431 a newly-created, never-selected window. */
432 XWINDOW (f->selected_window)->use_time = ++window_select_count;
434 return f;
437 #ifdef HAVE_WINDOW_SYSTEM
438 /* Make a frame using a separate minibuffer window on another frame.
439 MINI_WINDOW is the minibuffer window to use. nil means use the
440 default (the global minibuffer). */
442 struct frame *
443 make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
445 register struct frame *f;
446 struct gcpro gcpro1;
448 if (!NILP (mini_window))
449 CHECK_LIVE_WINDOW (mini_window);
451 if (!NILP (mini_window)
452 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
453 error ("Frame and minibuffer must be on the same terminal");
455 /* Make a frame containing just a root window. */
456 f = make_frame (0);
458 if (NILP (mini_window))
460 /* Use default-minibuffer-frame if possible. */
461 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
462 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
464 Lisp_Object frame_dummy;
466 XSETFRAME (frame_dummy, f);
467 GCPRO1 (frame_dummy);
468 /* If there's no minibuffer frame to use, create one. */
469 kset_default_minibuffer_frame
470 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
471 UNGCPRO;
474 mini_window
475 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
478 fset_minibuffer_window (f, mini_window);
480 /* Make the chosen minibuffer window display the proper minibuffer,
481 unless it is already showing a minibuffer. */
482 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
483 /* Use set_window_buffer instead of Fset_window_buffer (see
484 discussion of bug#11984, bug#12025, bug#12026). */
485 set_window_buffer (mini_window,
486 (NILP (Vminibuffer_list)
487 ? get_minibuffer (0)
488 : Fcar (Vminibuffer_list)), 0, 0);
489 return f;
492 /* Make a frame containing only a minibuffer window. */
494 struct frame *
495 make_minibuffer_frame (void)
497 /* First make a frame containing just a root window, no minibuffer. */
499 register struct frame *f = make_frame (0);
500 register Lisp_Object mini_window;
501 register Lisp_Object frame;
503 XSETFRAME (frame, f);
505 f->auto_raise = 0;
506 f->auto_lower = 0;
507 f->no_split = 1;
508 f->wants_modeline = 0;
510 /* Now label the root window as also being the minibuffer.
511 Avoid infinite looping on the window chain by marking next pointer
512 as nil. */
514 mini_window = f->root_window;
515 fset_minibuffer_window (f, mini_window);
516 XWINDOW (mini_window)->mini = 1;
517 wset_next (XWINDOW (mini_window), Qnil);
518 wset_prev (XWINDOW (mini_window), Qnil);
519 wset_frame (XWINDOW (mini_window), frame);
521 /* Put the proper buffer in that window. */
523 /* Use set_window_buffer instead of Fset_window_buffer (see
524 discussion of bug#11984, bug#12025, bug#12026). */
525 set_window_buffer (mini_window,
526 (NILP (Vminibuffer_list)
527 ? get_minibuffer (0)
528 : Fcar (Vminibuffer_list)), 0, 0);
529 return f;
531 #endif /* HAVE_WINDOW_SYSTEM */
533 /* Construct a frame that refers to a terminal. */
535 static printmax_t tty_frame_count;
537 struct frame *
538 make_initial_frame (void)
540 struct frame *f;
541 struct terminal *terminal;
542 Lisp_Object frame;
544 eassert (initial_kboard);
546 /* The first call must initialize Vframe_list. */
547 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
548 Vframe_list = Qnil;
550 terminal = init_initial_terminal ();
552 f = make_frame (1);
553 XSETFRAME (frame, f);
555 Vframe_list = Fcons (frame, Vframe_list);
557 tty_frame_count = 1;
558 fset_name (f, build_pure_c_string ("F1"));
560 SET_FRAME_VISIBLE (f, 1);
562 f->output_method = terminal->type;
563 f->terminal = terminal;
564 f->terminal->reference_count++;
565 f->output_data.nothing = 0;
567 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
568 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
570 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
572 /* The default value of menu-bar-mode is t. */
573 set_menu_bar_lines (f, make_number (1), Qnil);
575 if (!noninteractive)
576 init_frame_faces (f);
578 last_nonminibuf_frame = f;
580 return f;
584 static struct frame *
585 make_terminal_frame (struct terminal *terminal)
587 register struct frame *f;
588 Lisp_Object frame;
589 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
591 if (!terminal->name)
592 error ("Terminal is not live, can't create new frames on it");
594 f = make_frame (1);
596 XSETFRAME (frame, f);
597 Vframe_list = Fcons (frame, Vframe_list);
599 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
601 SET_FRAME_VISIBLE (f, 1);
603 f->terminal = terminal;
604 f->terminal->reference_count++;
605 #ifdef MSDOS
606 f->output_data.tty->display_info = &the_only_display_info;
607 if (!inhibit_window_system
608 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
609 || XFRAME (selected_frame)->output_method == output_msdos_raw))
610 f->output_method = output_msdos_raw;
611 else
612 f->output_method = output_termcap;
613 #else /* not MSDOS */
614 f->output_method = output_termcap;
615 create_tty_output (f);
616 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
617 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
618 #endif /* not MSDOS */
620 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
621 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
622 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
624 /* Set the top frame to the newly created frame. */
625 if (FRAMEP (FRAME_TTY (f)->top_frame)
626 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
627 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
629 FRAME_TTY (f)->top_frame = frame;
631 if (!noninteractive)
632 init_frame_faces (f);
634 return f;
637 /* Get a suitable value for frame parameter PARAMETER for a newly
638 created frame, based on (1) the user-supplied frame parameter
639 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
641 static Lisp_Object
642 get_future_frame_param (Lisp_Object parameter,
643 Lisp_Object supplied_parms,
644 char *current_value)
646 Lisp_Object result;
648 result = Fassq (parameter, supplied_parms);
649 if (NILP (result))
650 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
651 if (NILP (result) && current_value != NULL)
652 result = build_string (current_value);
653 if (!NILP (result) && !STRINGP (result))
654 result = XCDR (result);
655 if (NILP (result) || !STRINGP (result))
656 result = Qnil;
658 return result;
661 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
662 1, 1, 0,
663 doc: /* Create an additional terminal frame, possibly on another terminal.
664 This function takes one argument, an alist specifying frame parameters.
666 You can create multiple frames on a single text terminal, but only one
667 of them (the selected terminal frame) is actually displayed.
669 In practice, generally you don't need to specify any parameters,
670 except when you want to create a new frame on another terminal.
671 In that case, the `tty' parameter specifies the device file to open,
672 and the `tty-type' parameter specifies the terminal type. Example:
674 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
676 Note that changing the size of one terminal frame automatically
677 affects all frames on the same terminal device. */)
678 (Lisp_Object parms)
680 struct frame *f;
681 struct terminal *t = NULL;
682 Lisp_Object frame, tem;
683 struct frame *sf = SELECTED_FRAME ();
685 #ifdef MSDOS
686 if (sf->output_method != output_msdos_raw
687 && sf->output_method != output_termcap)
688 emacs_abort ();
689 #else /* not MSDOS */
691 #ifdef WINDOWSNT /* This should work now! */
692 if (sf->output_method != output_termcap)
693 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
694 #endif
695 #endif /* not MSDOS */
698 Lisp_Object terminal;
700 terminal = Fassq (Qterminal, parms);
701 if (CONSP (terminal))
703 terminal = XCDR (terminal);
704 t = get_terminal (terminal, 1);
706 #ifdef MSDOS
707 if (t && t != the_only_display_info.terminal)
708 /* msdos.c assumes a single tty_display_info object. */
709 error ("Multiple terminals are not supported on this platform");
710 if (!t)
711 t = the_only_display_info.terminal;
712 #endif
715 if (!t)
717 char *name = 0, *type = 0;
718 Lisp_Object tty, tty_type;
720 tty = get_future_frame_param
721 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
722 ? FRAME_TTY (XFRAME (selected_frame))->name
723 : NULL));
724 if (!NILP (tty))
725 name = xlispstrdupa (tty);
727 tty_type = get_future_frame_param
728 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
729 ? FRAME_TTY (XFRAME (selected_frame))->type
730 : NULL));
731 if (!NILP (tty_type))
732 type = xlispstrdupa (tty_type);
734 t = init_tty (name, type, 0); /* Errors are not fatal. */
737 f = make_terminal_frame (t);
740 int width, height;
741 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
742 change_frame_size (f, width, height, 0, 0, 0, 0);
745 adjust_frame_glyphs (f);
746 calculate_costs (f);
747 XSETFRAME (frame, f);
749 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
750 store_in_alist (&parms, Qtty,
751 (t->display_info.tty->name
752 ? build_string (t->display_info.tty->name)
753 : Qnil));
754 Fmodify_frame_parameters (frame, parms);
756 /* Make the frame face alist be frame-specific, so that each
757 frame could change its face definitions independently. */
758 fset_face_alist (f, Fcopy_alist (sf->face_alist));
759 /* Simple Fcopy_alist isn't enough, because we need the contents of
760 the vectors which are the CDRs of associations in face_alist to
761 be copied as well. */
762 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
763 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
764 return frame;
768 /* Perform the switch to frame FRAME.
770 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
771 FRAME1 as frame.
773 If TRACK is non-zero and the frame that currently has the focus
774 redirects its focus to the selected frame, redirect that focused
775 frame's focus to FRAME instead.
777 FOR_DELETION non-zero means that the selected frame is being
778 deleted, which includes the possibility that the frame's terminal
779 is dead.
781 The value of NORECORD is passed as argument to Fselect_window. */
783 Lisp_Object
784 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
786 struct frame *sf = SELECTED_FRAME ();
788 /* If FRAME is a switch-frame event, extract the frame we should
789 switch to. */
790 if (CONSP (frame)
791 && EQ (XCAR (frame), Qswitch_frame)
792 && CONSP (XCDR (frame)))
793 frame = XCAR (XCDR (frame));
795 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
796 a switch-frame event to arrive after a frame is no longer live,
797 especially when deleting the initial frame during startup. */
798 CHECK_FRAME (frame);
799 if (! FRAME_LIVE_P (XFRAME (frame)))
800 return Qnil;
802 if (sf == XFRAME (frame))
803 return frame;
805 /* If a frame's focus has been redirected toward the currently
806 selected frame, we should change the redirection to point to the
807 newly selected frame. This means that if the focus is redirected
808 from a minibufferless frame to a surrogate minibuffer frame, we
809 can use `other-window' to switch between all the frames using
810 that minibuffer frame, and the focus redirection will follow us
811 around. */
812 #if 0
813 /* This is too greedy; it causes inappropriate focus redirection
814 that's hard to get rid of. */
815 if (track)
817 Lisp_Object tail;
819 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
821 Lisp_Object focus;
823 if (!FRAMEP (XCAR (tail)))
824 emacs_abort ();
826 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
828 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
829 Fredirect_frame_focus (XCAR (tail), frame);
832 #else /* ! 0 */
833 /* Instead, apply it only to the frame we're pointing to. */
834 #ifdef HAVE_WINDOW_SYSTEM
835 if (track && FRAME_WINDOW_P (XFRAME (frame)))
837 Lisp_Object focus, xfocus;
839 xfocus = x_get_focus_frame (XFRAME (frame));
840 if (FRAMEP (xfocus))
842 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
843 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
844 Fredirect_frame_focus (xfocus, frame);
847 #endif /* HAVE_X_WINDOWS */
848 #endif /* ! 0 */
850 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
851 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
853 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
855 struct frame *f = XFRAME (frame);
856 struct tty_display_info *tty = FRAME_TTY (f);
857 Lisp_Object top_frame = tty->top_frame;
859 /* Don't mark the frame garbaged and/or obscured if we are
860 switching to the frame that is already the top frame of that
861 TTY. */
862 if (!EQ (frame, top_frame))
864 if (FRAMEP (top_frame))
865 /* Mark previously displayed frame as now obscured. */
866 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
867 SET_FRAME_VISIBLE (f, 1);
868 /* If the new TTY frame changed dimensions, we need to
869 resync term.c's idea of the frame size with the new
870 frame's data. */
871 if (FRAME_COLS (f) != FrameCols (tty))
872 FrameCols (tty) = FRAME_COLS (f);
873 if (FRAME_LINES (f) != FrameRows (tty))
874 FrameRows (tty) = FRAME_LINES (f);
876 tty->top_frame = frame;
879 selected_frame = frame;
880 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
881 last_nonminibuf_frame = XFRAME (selected_frame);
883 Fselect_window (XFRAME (frame)->selected_window, norecord);
885 /* We want to make sure that the next event generates a frame-switch
886 event to the appropriate frame. This seems kludgy to me, but
887 before you take it out, make sure that evaluating something like
888 (select-window (frame-root-window (new-frame))) doesn't end up
889 with your typing being interpreted in the new frame instead of
890 the one you're actually typing in. */
891 internal_last_event_frame = Qnil;
893 return frame;
896 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
897 doc: /* Select FRAME.
898 Subsequent editing commands apply to its selected window.
899 Optional argument NORECORD means to neither change the order of
900 recently selected windows nor the buffer list.
902 The selection of FRAME lasts until the next time the user does
903 something to select a different frame, or until the next time
904 this function is called. If you are using a window system, the
905 previously selected frame may be restored as the selected frame
906 when returning to the command loop, because it still may have
907 the window system's input focus. On a text terminal, the next
908 redisplay will display FRAME.
910 This function returns FRAME, or nil if FRAME has been deleted. */)
911 (Lisp_Object frame, Lisp_Object norecord)
913 return do_switch_frame (frame, 1, 0, norecord);
916 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
917 doc: /* Handle a switch-frame event EVENT.
918 Switch-frame events are usually bound to this function.
919 A switch-frame event tells Emacs that the window manager has requested
920 that the user's events be directed to the frame mentioned in the event.
921 This function selects the selected window of the frame of EVENT.
923 If EVENT is frame object, handle it as if it were a switch-frame event
924 to that frame. */)
925 (Lisp_Object event)
927 /* Preserve prefix arg that the command loop just cleared. */
928 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
929 Frun_hooks (1, &Qmouse_leave_buffer_hook);
930 /* `switch-frame' implies a focus in. */
931 call1 (intern ("handle-focus-in"), event);
932 return do_switch_frame (event, 0, 0, Qnil);
935 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
936 doc: /* Return the frame that is now selected. */)
937 (void)
939 return selected_frame;
942 DEFUN ("frame-list", Fframe_list, Sframe_list,
943 0, 0, 0,
944 doc: /* Return a list of all live frames. */)
945 (void)
947 Lisp_Object frames;
948 frames = Fcopy_sequence (Vframe_list);
949 #ifdef HAVE_WINDOW_SYSTEM
950 if (FRAMEP (tip_frame))
951 frames = Fdelq (tip_frame, frames);
952 #endif
953 return frames;
956 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
957 same tty (for tty frames) or among frames which uses FRAME's keyboard.
958 If MINIBUF is nil, do not consider minibuffer-only candidate.
959 If MINIBUF is `visible', do not consider an invisible candidate.
960 If MINIBUF is a window, consider only its own frame and candidate now
961 using that window as the minibuffer.
962 If MINIBUF is 0, consider candidate if it is visible or iconified.
963 Otherwise consider any candidate and return nil if CANDIDATE is not
964 acceptable. */
966 static Lisp_Object
967 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
969 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
971 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
972 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
973 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
974 && FRAME_TTY (c) == FRAME_TTY (f)))
976 if (NILP (minibuf))
978 if (!FRAME_MINIBUF_ONLY_P (c))
979 return candidate;
981 else if (EQ (minibuf, Qvisible))
983 if (FRAME_VISIBLE_P (c))
984 return candidate;
986 else if (WINDOWP (minibuf))
988 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
989 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
990 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
991 FRAME_FOCUS_FRAME (c)))
992 return candidate;
994 else if (XFASTINT (minibuf) == 0)
996 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
997 return candidate;
999 else
1000 return candidate;
1002 return Qnil;
1005 /* Return the next frame in the frame list after FRAME. */
1007 static Lisp_Object
1008 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1010 Lisp_Object f, tail;
1011 int passed = 0;
1013 /* There must always be at least one frame in Vframe_list. */
1014 eassert (CONSP (Vframe_list));
1016 while (passed < 2)
1017 FOR_EACH_FRAME (tail, f)
1019 if (passed)
1021 f = candidate_frame (f, frame, minibuf);
1022 if (!NILP (f))
1023 return f;
1025 if (EQ (frame, f))
1026 passed++;
1028 return frame;
1031 /* Return the previous frame in the frame list before FRAME. */
1033 static Lisp_Object
1034 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1036 Lisp_Object f, tail, prev = Qnil;
1038 /* There must always be at least one frame in Vframe_list. */
1039 eassert (CONSP (Vframe_list));
1041 FOR_EACH_FRAME (tail, f)
1043 if (EQ (frame, f) && !NILP (prev))
1044 return prev;
1045 f = candidate_frame (f, frame, minibuf);
1046 if (!NILP (f))
1047 prev = f;
1050 /* We've scanned the entire list. */
1051 if (NILP (prev))
1052 /* We went through the whole frame list without finding a single
1053 acceptable frame. Return the original frame. */
1054 return frame;
1055 else
1056 /* There were no acceptable frames in the list before FRAME; otherwise,
1057 we would have returned directly from the loop. Since PREV is the last
1058 acceptable frame in the list, return it. */
1059 return prev;
1063 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1064 doc: /* Return the next frame in the frame list after 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 next_frame (frame, miniframe);
1082 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1083 doc: /* Return the previous frame in the frame list before FRAME.
1084 It considers only frames on the same terminal as FRAME.
1085 By default, skip minibuffer-only frames.
1086 If omitted, FRAME defaults to the selected frame.
1087 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1088 If MINIFRAME is a window, include only its own frame
1089 and any frame now using that window as the minibuffer.
1090 If MINIFRAME is `visible', include all visible frames.
1091 If MINIFRAME is 0, include all visible and iconified frames.
1092 Otherwise, include all frames. */)
1093 (Lisp_Object frame, Lisp_Object miniframe)
1095 if (NILP (frame))
1096 frame = selected_frame;
1097 CHECK_LIVE_FRAME (frame);
1098 return prev_frame (frame, miniframe);
1101 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1102 Slast_nonminibuf_frame, 0, 0, 0,
1103 doc: /* Return last non-minibuffer frame selected. */)
1104 (void)
1106 Lisp_Object frame = Qnil;
1108 if (last_nonminibuf_frame)
1109 XSETFRAME (frame, last_nonminibuf_frame);
1111 return frame;
1114 /* Return 1 if it is ok to delete frame F;
1115 0 if all frames aside from F are invisible.
1116 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1118 static int
1119 other_visible_frames (struct frame *f)
1121 Lisp_Object frames, this;
1123 FOR_EACH_FRAME (frames, this)
1125 if (f == XFRAME (this))
1126 continue;
1128 /* Verify that we can still talk to the frame's X window,
1129 and note any recent change in visibility. */
1130 #ifdef HAVE_X_WINDOWS
1131 if (FRAME_WINDOW_P (XFRAME (this)))
1132 x_sync (XFRAME (this));
1133 #endif
1135 if (FRAME_VISIBLE_P (XFRAME (this))
1136 || FRAME_ICONIFIED_P (XFRAME (this))
1137 /* Allow deleting the terminal frame when at least one X
1138 frame exists. */
1139 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1140 return 1;
1142 return 0;
1145 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1146 window. Preferably use the selected frame's minibuffer window
1147 instead. If the selected frame doesn't have one, get some other
1148 frame's minibuffer window. SELECT non-zero means select the new
1149 minibuffer window. */
1150 static void
1151 check_minibuf_window (Lisp_Object frame, int select)
1153 struct frame *f = decode_live_frame (frame);
1155 XSETFRAME (frame, f);
1157 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1159 Lisp_Object frames, this, window = make_number (0);
1161 if (!EQ (frame, selected_frame)
1162 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1163 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1164 else
1165 FOR_EACH_FRAME (frames, this)
1167 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1169 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1170 break;
1174 /* Don't abort if no window was found (Bug#15247). */
1175 if (WINDOWP (window))
1177 /* Use set_window_buffer instead of Fset_window_buffer (see
1178 discussion of bug#11984, bug#12025, bug#12026). */
1179 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1180 minibuf_window = window;
1182 /* SELECT non-zero usually means that FRAME's minibuffer
1183 window was selected; select the new one. */
1184 if (select)
1185 Fselect_window (minibuf_window, Qnil);
1191 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1192 unconditionally. x_connection_closed and delete_terminal use
1193 this. Any other value of FORCE implements the semantics
1194 described for Fdelete_frame. */
1195 Lisp_Object
1196 delete_frame (Lisp_Object frame, Lisp_Object force)
1198 struct frame *f = decode_any_frame (frame);
1199 struct frame *sf;
1200 struct kboard *kb;
1202 int minibuffer_selected, is_tooltip_frame;
1204 if (! FRAME_LIVE_P (f))
1205 return Qnil;
1207 if (NILP (force) && !other_visible_frames (f))
1208 error ("Attempt to delete the sole visible or iconified frame");
1210 /* x_connection_closed must have set FORCE to `noelisp' in order
1211 to delete the last frame, if it is gone. */
1212 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1213 error ("Attempt to delete the only frame");
1215 XSETFRAME (frame, f);
1217 /* Does this frame have a minibuffer, and is it the surrogate
1218 minibuffer for any other frame? */
1219 if (FRAME_HAS_MINIBUF_P (f))
1221 Lisp_Object frames, this;
1223 FOR_EACH_FRAME (frames, this)
1225 Lisp_Object fminiw;
1227 if (EQ (this, frame))
1228 continue;
1230 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1232 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1234 /* If we MUST delete this frame, delete the other first.
1235 But do this only if FORCE equals `noelisp'. */
1236 if (EQ (force, Qnoelisp))
1237 delete_frame (this, Qnoelisp);
1238 else
1239 error ("Attempt to delete a surrogate minibuffer frame");
1244 is_tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1246 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1247 frame is a tooltip. FORCE is set to `noelisp' when handling
1248 a disconnect from the terminal, so we don't dare call Lisp
1249 code. */
1250 if (NILP (Vrun_hooks) || is_tooltip_frame)
1252 else if (EQ (force, Qnoelisp))
1253 pending_funcalls
1254 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1255 pending_funcalls);
1256 else
1258 #ifdef HAVE_X_WINDOWS
1259 /* Also, save clipboard to the clipboard manager. */
1260 x_clipboard_manager_save_frame (frame);
1261 #endif
1263 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1266 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1267 if (! FRAME_LIVE_P (f))
1268 return Qnil;
1270 /* At this point, we are committed to deleting the frame.
1271 There is no more chance for errors to prevent it. */
1273 minibuffer_selected = EQ (minibuf_window, selected_window);
1274 sf = SELECTED_FRAME ();
1275 /* Don't let the frame remain selected. */
1276 if (f == sf)
1278 Lisp_Object tail;
1279 Lisp_Object frame1 = Qnil;
1281 /* Look for another visible frame on the same terminal.
1282 Do not call next_frame here because it may loop forever.
1283 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1284 FOR_EACH_FRAME (tail, frame1)
1285 if (!EQ (frame, frame1)
1286 && (FRAME_TERMINAL (XFRAME (frame))
1287 == FRAME_TERMINAL (XFRAME (frame1)))
1288 && FRAME_VISIBLE_P (XFRAME (frame1)))
1289 break;
1291 /* If there is none, find *some* other frame. */
1292 if (NILP (frame1) || EQ (frame1, frame))
1294 FOR_EACH_FRAME (tail, frame1)
1296 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1298 /* Do not change a text terminal's top-frame. */
1299 struct frame *f1 = XFRAME (frame1);
1300 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1302 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1303 if (!EQ (top_frame, frame))
1304 frame1 = top_frame;
1306 break;
1310 #ifdef NS_IMPL_COCOA
1311 else
1312 /* Under NS, there is no system mechanism for choosing a new
1313 window to get focus -- it is left to application code.
1314 So the portion of THIS application interfacing with NS
1315 needs to know about it. We call Fraise_frame, but the
1316 purpose is really to transfer focus. */
1317 Fraise_frame (frame1);
1318 #endif
1320 do_switch_frame (frame1, 0, 1, Qnil);
1321 sf = SELECTED_FRAME ();
1324 /* Don't allow minibuf_window to remain on a deleted frame. */
1325 check_minibuf_window (frame, minibuffer_selected);
1327 /* Don't let echo_area_window to remain on a deleted frame. */
1328 if (EQ (f->minibuffer_window, echo_area_window))
1329 echo_area_window = sf->minibuffer_window;
1331 /* Clear any X selections for this frame. */
1332 #ifdef HAVE_X_WINDOWS
1333 if (FRAME_X_P (f))
1334 x_clear_frame_selections (f);
1335 #endif
1337 /* Free glyphs.
1338 This function must be called before the window tree of the
1339 frame is deleted because windows contain dynamically allocated
1340 memory. */
1341 free_glyphs (f);
1343 #ifdef HAVE_WINDOW_SYSTEM
1344 /* Give chance to each font driver to free a frame specific data. */
1345 font_update_drivers (f, Qnil);
1346 #endif
1348 /* Mark all the windows that used to be on FRAME as deleted, and then
1349 remove the reference to them. */
1350 delete_all_child_windows (f->root_window);
1351 fset_root_window (f, Qnil);
1353 Vframe_list = Fdelq (frame, Vframe_list);
1354 SET_FRAME_VISIBLE (f, 0);
1356 /* Allow the vector of menu bar contents to be freed in the next
1357 garbage collection. The frame object itself may not be garbage
1358 collected until much later, because recent_keys and other data
1359 structures can still refer to it. */
1360 fset_menu_bar_vector (f, Qnil);
1362 /* If FRAME's buffer lists contains killed
1363 buffers, this helps GC to reclaim them. */
1364 fset_buffer_list (f, Qnil);
1365 fset_buried_buffer_list (f, Qnil);
1367 free_font_driver_list (f);
1368 xfree (f->namebuf);
1369 xfree (f->decode_mode_spec_buffer);
1370 xfree (FRAME_INSERT_COST (f));
1371 xfree (FRAME_DELETEN_COST (f));
1372 xfree (FRAME_INSERTN_COST (f));
1373 xfree (FRAME_DELETE_COST (f));
1375 /* Since some events are handled at the interrupt level, we may get
1376 an event for f at any time; if we zero out the frame's terminal
1377 now, then we may trip up the event-handling code. Instead, we'll
1378 promise that the terminal of the frame must be valid until we
1379 have called the window-system-dependent frame destruction
1380 routine. */
1384 struct terminal *terminal;
1385 block_input ();
1386 if (FRAME_TERMINAL (f)->delete_frame_hook)
1387 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1388 terminal = FRAME_TERMINAL (f);
1389 f->output_data.nothing = 0;
1390 f->terminal = 0; /* Now the frame is dead. */
1391 unblock_input ();
1393 /* If needed, delete the terminal that this frame was on.
1394 (This must be done after the frame is killed.) */
1395 terminal->reference_count--;
1396 #ifdef USE_GTK
1397 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1398 bug.
1399 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1400 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1401 terminal->reference_count = 1;
1402 #endif /* USE_GTK */
1403 if (terminal->reference_count == 0)
1405 Lisp_Object tmp;
1406 XSETTERMINAL (tmp, terminal);
1408 kb = NULL;
1409 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1411 else
1412 kb = terminal->kboard;
1415 /* If we've deleted the last_nonminibuf_frame, then try to find
1416 another one. */
1417 if (f == last_nonminibuf_frame)
1419 Lisp_Object frames, this;
1421 last_nonminibuf_frame = 0;
1423 FOR_EACH_FRAME (frames, this)
1425 f = XFRAME (this);
1426 if (!FRAME_MINIBUF_ONLY_P (f))
1428 last_nonminibuf_frame = f;
1429 break;
1434 /* If there's no other frame on the same kboard, get out of
1435 single-kboard state if we're in it for this kboard. */
1436 if (kb != NULL)
1438 Lisp_Object frames, this;
1439 /* Some frame we found on the same kboard, or nil if there are none. */
1440 Lisp_Object frame_on_same_kboard = Qnil;
1442 FOR_EACH_FRAME (frames, this)
1443 if (kb == FRAME_KBOARD (XFRAME (this)))
1444 frame_on_same_kboard = this;
1446 if (NILP (frame_on_same_kboard))
1447 not_single_kboard_state (kb);
1451 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1452 find another one. Prefer minibuffer-only frames, but also notice
1453 frames with other windows. */
1454 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1456 Lisp_Object frames, this;
1458 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1459 Lisp_Object frame_with_minibuf = Qnil;
1460 /* Some frame we found on the same kboard, or nil if there are none. */
1461 Lisp_Object frame_on_same_kboard = Qnil;
1463 FOR_EACH_FRAME (frames, this)
1465 struct frame *f1 = XFRAME (this);
1467 /* Consider only frames on the same kboard
1468 and only those with minibuffers. */
1469 if (kb == FRAME_KBOARD (f1)
1470 && FRAME_HAS_MINIBUF_P (f1))
1472 frame_with_minibuf = this;
1473 if (FRAME_MINIBUF_ONLY_P (f1))
1474 break;
1477 if (kb == FRAME_KBOARD (f1))
1478 frame_on_same_kboard = this;
1481 if (!NILP (frame_on_same_kboard))
1483 /* We know that there must be some frame with a minibuffer out
1484 there. If this were not true, all of the frames present
1485 would have to be minibufferless, which implies that at some
1486 point their minibuffer frames must have been deleted, but
1487 that is prohibited at the top; you can't delete surrogate
1488 minibuffer frames. */
1489 if (NILP (frame_with_minibuf))
1490 emacs_abort ();
1492 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1494 else
1495 /* No frames left on this kboard--say no minibuffer either. */
1496 kset_default_minibuffer_frame (kb, Qnil);
1499 /* Cause frame titles to update--necessary if we now have just one frame. */
1500 if (!is_tooltip_frame)
1501 update_mode_lines = 15;
1503 return Qnil;
1506 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1507 doc: /* Delete FRAME, permanently eliminating it from use.
1508 FRAME defaults to the selected frame.
1510 A frame may not be deleted if its minibuffer is used by other frames.
1511 Normally, you may not delete a frame if all other frames are invisible,
1512 but if the second optional argument FORCE is non-nil, you may do so.
1514 This function runs `delete-frame-functions' before actually
1515 deleting the frame, unless the frame is a tooltip.
1516 The functions are run with one argument, the frame to be deleted. */)
1517 (Lisp_Object frame, Lisp_Object force)
1519 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1523 /* Return mouse position in character cell units. */
1525 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1526 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1527 The position is given in character cells, where (0, 0) is the
1528 upper-left corner of the frame, X is the horizontal offset, and Y is
1529 the vertical offset.
1530 If Emacs is running on a mouseless terminal or hasn't been programmed
1531 to read the mouse position, it returns the selected frame for FRAME
1532 and nil for X and Y.
1533 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1534 passing the normal return value to that function as an argument,
1535 and returns whatever that function returns. */)
1536 (void)
1538 struct frame *f;
1539 Lisp_Object lispy_dummy;
1540 Lisp_Object x, y, retval;
1541 struct gcpro gcpro1;
1543 f = SELECTED_FRAME ();
1544 x = y = Qnil;
1546 /* It's okay for the hook to refrain from storing anything. */
1547 if (FRAME_TERMINAL (f)->mouse_position_hook)
1549 enum scroll_bar_part party_dummy;
1550 Time time_dummy;
1551 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1552 &lispy_dummy, &party_dummy,
1553 &x, &y,
1554 &time_dummy);
1557 if (! NILP (x))
1559 int col = XINT (x);
1560 int row = XINT (y);
1561 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1562 XSETINT (x, col);
1563 XSETINT (y, row);
1565 XSETFRAME (lispy_dummy, f);
1566 retval = Fcons (lispy_dummy, Fcons (x, y));
1567 GCPRO1 (retval);
1568 if (!NILP (Vmouse_position_function))
1569 retval = call1 (Vmouse_position_function, retval);
1570 RETURN_UNGCPRO (retval);
1573 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1574 Smouse_pixel_position, 0, 0, 0,
1575 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1576 The position is given in pixel units, where (0, 0) is the
1577 upper-left corner of the frame, X is the horizontal offset, and Y is
1578 the vertical offset.
1579 If Emacs is running on a mouseless terminal or hasn't been programmed
1580 to read the mouse position, it returns the selected frame for FRAME
1581 and nil for X and Y. */)
1582 (void)
1584 struct frame *f;
1585 Lisp_Object lispy_dummy;
1586 Lisp_Object x, y;
1588 f = SELECTED_FRAME ();
1589 x = y = Qnil;
1591 /* It's okay for the hook to refrain from storing anything. */
1592 if (FRAME_TERMINAL (f)->mouse_position_hook)
1594 enum scroll_bar_part party_dummy;
1595 Time time_dummy;
1596 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1597 &lispy_dummy, &party_dummy,
1598 &x, &y,
1599 &time_dummy);
1602 XSETFRAME (lispy_dummy, f);
1603 return Fcons (lispy_dummy, Fcons (x, y));
1606 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1607 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1608 Coordinates are relative to the frame, not a window,
1609 so the coordinates of the top left character in the frame
1610 may be nonzero due to left-hand scroll bars or the menu bar.
1612 The position is given in character cells, where (0, 0) is the
1613 upper-left corner of the frame, X is the horizontal offset, and Y is
1614 the vertical offset.
1616 This function is a no-op for an X frame that is not visible.
1617 If you have just created a frame, you must wait for it to become visible
1618 before calling this function on it, like this.
1619 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1620 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1622 CHECK_LIVE_FRAME (frame);
1623 CHECK_TYPE_RANGED_INTEGER (int, x);
1624 CHECK_TYPE_RANGED_INTEGER (int, y);
1626 /* I think this should be done with a hook. */
1627 #ifdef HAVE_WINDOW_SYSTEM
1628 if (FRAME_WINDOW_P (XFRAME (frame)))
1629 /* Warping the mouse will cause enternotify and focus events. */
1630 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1631 #else
1632 #if defined (MSDOS)
1633 if (FRAME_MSDOS_P (XFRAME (frame)))
1635 Fselect_frame (frame, Qnil);
1636 mouse_moveto (XINT (x), XINT (y));
1638 #else
1639 #ifdef HAVE_GPM
1641 Fselect_frame (frame, Qnil);
1642 term_mouse_moveto (XINT (x), XINT (y));
1644 #endif
1645 #endif
1646 #endif
1648 return Qnil;
1651 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1652 Sset_mouse_pixel_position, 3, 3, 0,
1653 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1654 The position is given in pixels, where (0, 0) is the upper-left corner
1655 of the frame, X is the horizontal offset, and Y is the vertical offset.
1657 Note, this is a no-op for an X frame that is not visible.
1658 If you have just created a frame, you must wait for it to become visible
1659 before calling this function on it, like this.
1660 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1661 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1663 CHECK_LIVE_FRAME (frame);
1664 CHECK_TYPE_RANGED_INTEGER (int, x);
1665 CHECK_TYPE_RANGED_INTEGER (int, y);
1667 /* I think this should be done with a hook. */
1668 #ifdef HAVE_WINDOW_SYSTEM
1669 if (FRAME_WINDOW_P (XFRAME (frame)))
1670 /* Warping the mouse will cause enternotify and focus events. */
1671 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1672 #else
1673 #if defined (MSDOS)
1674 if (FRAME_MSDOS_P (XFRAME (frame)))
1676 Fselect_frame (frame, Qnil);
1677 mouse_moveto (XINT (x), XINT (y));
1679 #else
1680 #ifdef HAVE_GPM
1682 Fselect_frame (frame, Qnil);
1683 term_mouse_moveto (XINT (x), XINT (y));
1685 #endif
1686 #endif
1687 #endif
1689 return Qnil;
1692 static void make_frame_visible_1 (Lisp_Object);
1694 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1695 0, 1, "",
1696 doc: /* Make the frame FRAME visible (assuming it is an X window).
1697 If omitted, FRAME defaults to the currently selected frame. */)
1698 (Lisp_Object frame)
1700 struct frame *f = decode_live_frame (frame);
1702 /* I think this should be done with a hook. */
1703 #ifdef HAVE_WINDOW_SYSTEM
1704 if (FRAME_WINDOW_P (f))
1705 x_make_frame_visible (f);
1706 #endif
1708 make_frame_visible_1 (f->root_window);
1710 /* Make menu bar update for the Buffers and Frames menus. */
1711 /* windows_or_buffers_changed = 15; FIXME: Why? */
1713 XSETFRAME (frame, f);
1714 return frame;
1717 /* Update the display_time slot of the buffers shown in WINDOW
1718 and all its descendants. */
1720 static void
1721 make_frame_visible_1 (Lisp_Object window)
1723 struct window *w;
1725 for (; !NILP (window); window = w->next)
1727 w = XWINDOW (window);
1728 if (WINDOWP (w->contents))
1729 make_frame_visible_1 (w->contents);
1730 else
1731 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
1735 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1736 0, 2, "",
1737 doc: /* Make the frame FRAME invisible.
1738 If omitted, FRAME defaults to the currently selected frame.
1739 On graphical displays, invisible frames are not updated and are
1740 usually not displayed at all, even in a window system's \"taskbar\".
1742 Normally you may not make FRAME invisible if all other frames are invisible,
1743 but if the second optional argument FORCE is non-nil, you may do so.
1745 This function has no effect on text terminal frames. Such frames are
1746 always considered visible, whether or not they are currently being
1747 displayed in the terminal. */)
1748 (Lisp_Object frame, Lisp_Object force)
1750 struct frame *f = decode_live_frame (frame);
1752 if (NILP (force) && !other_visible_frames (f))
1753 error ("Attempt to make invisible the sole visible or iconified frame");
1755 /* Don't allow minibuf_window to remain on an invisible frame. */
1756 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
1758 /* I think this should be done with a hook. */
1759 #ifdef HAVE_WINDOW_SYSTEM
1760 if (FRAME_WINDOW_P (f))
1761 x_make_frame_invisible (f);
1762 #endif
1764 /* Make menu bar update for the Buffers and Frames menus. */
1765 windows_or_buffers_changed = 16;
1767 return Qnil;
1770 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1771 0, 1, "",
1772 doc: /* Make the frame FRAME into an icon.
1773 If omitted, FRAME defaults to the currently selected frame. */)
1774 (Lisp_Object frame)
1776 struct frame *f = decode_live_frame (frame);
1778 /* Don't allow minibuf_window to remain on an iconified frame. */
1779 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
1781 /* I think this should be done with a hook. */
1782 #ifdef HAVE_WINDOW_SYSTEM
1783 if (FRAME_WINDOW_P (f))
1784 x_iconify_frame (f);
1785 #endif
1787 /* Make menu bar update for the Buffers and Frames menus. */
1788 windows_or_buffers_changed = 17;
1790 return Qnil;
1793 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1794 1, 1, 0,
1795 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1796 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1797 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1798 On graphical displays, invisible frames are not updated and are
1799 usually not displayed at all, even in a window system's \"taskbar\".
1801 If FRAME is a text terminal frame, this always returns t.
1802 Such frames are always considered visible, whether or not they are
1803 currently being displayed on the terminal. */)
1804 (Lisp_Object frame)
1806 CHECK_LIVE_FRAME (frame);
1808 if (FRAME_VISIBLE_P (XFRAME (frame)))
1809 return Qt;
1810 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1811 return Qicon;
1812 return Qnil;
1815 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1816 0, 0, 0,
1817 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1818 (void)
1820 Lisp_Object tail, frame, value = Qnil;
1822 FOR_EACH_FRAME (tail, frame)
1823 if (FRAME_VISIBLE_P (XFRAME (frame)))
1824 value = Fcons (frame, value);
1826 return value;
1830 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1831 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1832 If FRAME is invisible or iconified, make it visible.
1833 If you don't specify a frame, the selected frame is used.
1834 If Emacs is displaying on an ordinary terminal or some other device which
1835 doesn't support multiple overlapping frames, this function selects FRAME. */)
1836 (Lisp_Object frame)
1838 struct frame *f = decode_live_frame (frame);
1840 XSETFRAME (frame, f);
1842 if (FRAME_TERMCAP_P (f))
1843 /* On a text terminal select FRAME. */
1844 Fselect_frame (frame, Qnil);
1845 else
1846 /* Do like the documentation says. */
1847 Fmake_frame_visible (frame);
1849 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1850 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
1852 return Qnil;
1855 /* Should we have a corresponding function called Flower_Power? */
1856 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1857 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1858 If you don't specify a frame, the selected frame is used.
1859 If Emacs is displaying on an ordinary terminal or some other device which
1860 doesn't support multiple overlapping frames, this function does nothing. */)
1861 (Lisp_Object frame)
1863 struct frame *f = decode_live_frame (frame);
1865 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1866 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
1868 return Qnil;
1872 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1873 1, 2, 0,
1874 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1875 In other words, switch-frame events caused by events in FRAME will
1876 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1877 FOCUS-FRAME after reading an event typed at FRAME.
1879 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
1880 frame again receives its own keystrokes.
1882 Focus redirection is useful for temporarily redirecting keystrokes to
1883 a surrogate minibuffer frame when a frame doesn't have its own
1884 minibuffer window.
1886 A frame's focus redirection can be changed by `select-frame'. If frame
1887 FOO is selected, and then a different frame BAR is selected, any
1888 frames redirecting their focus to FOO are shifted to redirect their
1889 focus to BAR. This allows focus redirection to work properly when the
1890 user switches from one frame to another using `select-window'.
1892 This means that a frame whose focus is redirected to itself is treated
1893 differently from a frame whose focus is redirected to nil; the former
1894 is affected by `select-frame', while the latter is not.
1896 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1897 (Lisp_Object frame, Lisp_Object focus_frame)
1899 /* Note that we don't check for a live frame here. It's reasonable
1900 to redirect the focus of a frame you're about to delete, if you
1901 know what other frame should receive those keystrokes. */
1902 struct frame *f = decode_any_frame (frame);
1904 if (! NILP (focus_frame))
1905 CHECK_LIVE_FRAME (focus_frame);
1907 fset_focus_frame (f, focus_frame);
1909 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
1910 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
1912 return Qnil;
1916 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
1917 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1918 If FRAME is omitted or nil, the selected frame is used.
1919 Return nil if FRAME's focus is not redirected.
1920 See `redirect-frame-focus'. */)
1921 (Lisp_Object frame)
1923 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
1926 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
1927 doc: /* Set the input focus to FRAME.
1928 FRAME nil means use the selected frame.
1929 If there is no window system support, this function does nothing. */)
1930 (Lisp_Object frame)
1932 #ifdef HAVE_WINDOW_SYSTEM
1933 x_focus_frame (decode_window_system_frame (frame));
1934 #endif
1935 return Qnil;
1939 /* Return the value of frame parameter PROP in frame FRAME. */
1941 #ifdef HAVE_WINDOW_SYSTEM
1942 #if !HAVE_NS && !HAVE_NTGUI
1943 static
1944 #endif
1945 Lisp_Object
1946 get_frame_param (register struct frame *frame, Lisp_Object prop)
1948 register Lisp_Object tem;
1950 tem = Fassq (prop, frame->param_alist);
1951 if (EQ (tem, Qnil))
1952 return tem;
1953 return Fcdr (tem);
1955 #endif
1957 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
1959 void
1960 frames_discard_buffer (Lisp_Object buffer)
1962 Lisp_Object frame, tail;
1964 FOR_EACH_FRAME (tail, frame)
1966 fset_buffer_list
1967 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
1968 fset_buried_buffer_list
1969 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
1973 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1974 If the alist already has an element for PROP, we change it. */
1976 void
1977 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
1979 register Lisp_Object tem;
1981 tem = Fassq (prop, *alistptr);
1982 if (EQ (tem, Qnil))
1983 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1984 else
1985 Fsetcdr (tem, val);
1988 static int
1989 frame_name_fnn_p (char *str, ptrdiff_t len)
1991 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
1993 char *p = str + 2;
1994 while ('0' <= *p && *p <= '9')
1995 p++;
1996 if (p == str + len)
1997 return 1;
1999 return 0;
2002 /* Set the name of the terminal frame. Also used by MSDOS frames.
2003 Modeled after x_set_name which is used for WINDOW frames. */
2005 static void
2006 set_term_frame_name (struct frame *f, Lisp_Object name)
2008 f->explicit_name = ! NILP (name);
2010 /* If NAME is nil, set the name to F<num>. */
2011 if (NILP (name))
2013 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2015 /* Check for no change needed in this very common case
2016 before we do any consing. */
2017 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2018 return;
2020 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2022 else
2024 CHECK_STRING (name);
2026 /* Don't change the name if it's already NAME. */
2027 if (! NILP (Fstring_equal (name, f->name)))
2028 return;
2030 /* Don't allow the user to set the frame name to F<num>, so it
2031 doesn't clash with the names we generate for terminal frames. */
2032 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2033 error ("Frame names of the form F<num> are usurped by Emacs");
2036 fset_name (f, name);
2037 update_mode_lines = 16;
2040 #ifdef HAVE_NTGUI
2041 void
2042 set_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2044 register Lisp_Object old_alist_elt;
2046 old_alist_elt = Fassq (prop, f->param_alist);
2047 if (EQ (old_alist_elt, Qnil))
2048 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2049 else
2050 Fsetcdr (old_alist_elt, val);
2052 #endif
2054 void
2055 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2057 register Lisp_Object old_alist_elt;
2059 /* The buffer-list parameters are stored in a special place and not
2060 in the alist. All buffers must be live. */
2061 if (EQ (prop, Qbuffer_list))
2063 Lisp_Object list = Qnil;
2064 for (; CONSP (val); val = XCDR (val))
2065 if (!NILP (Fbuffer_live_p (XCAR (val))))
2066 list = Fcons (XCAR (val), list);
2067 fset_buffer_list (f, Fnreverse (list));
2068 return;
2070 if (EQ (prop, Qburied_buffer_list))
2072 Lisp_Object list = Qnil;
2073 for (; CONSP (val); val = XCDR (val))
2074 if (!NILP (Fbuffer_live_p (XCAR (val))))
2075 list = Fcons (XCAR (val), list);
2076 fset_buried_buffer_list (f, Fnreverse (list));
2077 return;
2080 /* If PROP is a symbol which is supposed to have frame-local values,
2081 and it is set up based on this frame, switch to the global
2082 binding. That way, we can create or alter the frame-local binding
2083 without messing up the symbol's status. */
2084 if (SYMBOLP (prop))
2086 struct Lisp_Symbol *sym = XSYMBOL (prop);
2087 start:
2088 switch (sym->redirect)
2090 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2091 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2092 case SYMBOL_LOCALIZED:
2093 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2094 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2095 swap_in_global_binding (sym);
2096 break;
2098 default: emacs_abort ();
2102 /* The tty color needed to be set before the frame's parameter
2103 alist was updated with the new value. This is not true any more,
2104 but we still do this test early on. */
2105 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2106 && f == FRAME_TTY (f)->previous_frame)
2107 /* Force redisplay of this tty. */
2108 FRAME_TTY (f)->previous_frame = NULL;
2110 /* Update the frame parameter alist. */
2111 old_alist_elt = Fassq (prop, f->param_alist);
2112 if (EQ (old_alist_elt, Qnil))
2113 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2114 else
2115 Fsetcdr (old_alist_elt, val);
2117 /* Update some other special parameters in their special places
2118 in addition to the alist. */
2120 if (EQ (prop, Qbuffer_predicate))
2121 fset_buffer_predicate (f, val);
2123 if (! FRAME_WINDOW_P (f))
2125 if (EQ (prop, Qmenu_bar_lines))
2126 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2127 else if (EQ (prop, Qname))
2128 set_term_frame_name (f, val);
2131 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2133 if (! MINI_WINDOW_P (XWINDOW (val)))
2134 error ("Surrogate minibuffer windows must be minibuffer windows");
2136 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2137 && !EQ (val, f->minibuffer_window))
2138 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2140 /* Install the chosen minibuffer window, with proper buffer. */
2141 fset_minibuffer_window (f, val);
2145 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2146 doc: /* Return the parameters-alist of frame FRAME.
2147 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2148 The meaningful PARMs depend on the kind of frame.
2149 If FRAME is omitted or nil, return information on the currently selected frame. */)
2150 (Lisp_Object frame)
2152 Lisp_Object alist;
2153 struct frame *f = decode_any_frame (frame);
2154 int height, width;
2155 struct gcpro gcpro1;
2157 if (!FRAME_LIVE_P (f))
2158 return Qnil;
2160 alist = Fcopy_alist (f->param_alist);
2161 GCPRO1 (alist);
2163 if (!FRAME_WINDOW_P (f))
2165 int fg = FRAME_FOREGROUND_PIXEL (f);
2166 int bg = FRAME_BACKGROUND_PIXEL (f);
2167 Lisp_Object elt;
2169 /* If the frame's parameter alist says the colors are
2170 unspecified and reversed, take the frame's background pixel
2171 for foreground and vice versa. */
2172 elt = Fassq (Qforeground_color, alist);
2173 if (CONSP (elt) && STRINGP (XCDR (elt)))
2175 if (strncmp (SSDATA (XCDR (elt)),
2176 unspecified_bg,
2177 SCHARS (XCDR (elt))) == 0)
2178 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2179 else if (strncmp (SSDATA (XCDR (elt)),
2180 unspecified_fg,
2181 SCHARS (XCDR (elt))) == 0)
2182 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2184 else
2185 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2186 elt = Fassq (Qbackground_color, alist);
2187 if (CONSP (elt) && STRINGP (XCDR (elt)))
2189 if (strncmp (SSDATA (XCDR (elt)),
2190 unspecified_fg,
2191 SCHARS (XCDR (elt))) == 0)
2192 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2193 else if (strncmp (SSDATA (XCDR (elt)),
2194 unspecified_bg,
2195 SCHARS (XCDR (elt))) == 0)
2196 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2198 else
2199 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2200 store_in_alist (&alist, intern ("font"),
2201 build_string (FRAME_MSDOS_P (f)
2202 ? "ms-dos"
2203 : FRAME_W32_P (f) ? "w32term"
2204 :"tty"));
2206 store_in_alist (&alist, Qname, f->name);
2207 height = (f->new_height
2208 ? (f->new_pixelwise
2209 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2210 : f->new_height)
2211 : FRAME_LINES (f));
2212 store_in_alist (&alist, Qheight, make_number (height));
2213 width = (f->new_width
2214 ? (f->new_pixelwise
2215 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2216 : f->new_width)
2217 : FRAME_COLS (f));
2218 store_in_alist (&alist, Qwidth, make_number (width));
2219 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2220 store_in_alist (&alist, Qminibuffer,
2221 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2222 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2223 : FRAME_MINIBUF_WINDOW (f)));
2224 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2225 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2226 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2228 /* I think this should be done with a hook. */
2229 #ifdef HAVE_WINDOW_SYSTEM
2230 if (FRAME_WINDOW_P (f))
2231 x_report_frame_params (f, &alist);
2232 else
2233 #endif
2235 /* This ought to be correct in f->param_alist for an X frame. */
2236 Lisp_Object lines;
2237 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2238 store_in_alist (&alist, Qmenu_bar_lines, lines);
2241 UNGCPRO;
2242 return alist;
2246 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2247 doc: /* Return FRAME's value for parameter PARAMETER.
2248 If FRAME is nil, describe the currently selected frame. */)
2249 (Lisp_Object frame, Lisp_Object parameter)
2251 struct frame *f = decode_any_frame (frame);
2252 Lisp_Object value = Qnil;
2254 CHECK_SYMBOL (parameter);
2256 XSETFRAME (frame, f);
2258 if (FRAME_LIVE_P (f))
2260 /* Avoid consing in frequent cases. */
2261 if (EQ (parameter, Qname))
2262 value = f->name;
2263 #ifdef HAVE_X_WINDOWS
2264 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2265 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2266 #endif /* HAVE_X_WINDOWS */
2267 else if (EQ (parameter, Qbackground_color)
2268 || EQ (parameter, Qforeground_color))
2270 value = Fassq (parameter, f->param_alist);
2271 if (CONSP (value))
2273 value = XCDR (value);
2274 /* Fframe_parameters puts the actual fg/bg color names,
2275 even if f->param_alist says otherwise. This is
2276 important when param_alist's notion of colors is
2277 "unspecified". We need to do the same here. */
2278 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2280 const char *color_name;
2281 ptrdiff_t csz;
2283 if (EQ (parameter, Qbackground_color))
2285 color_name = SSDATA (value);
2286 csz = SCHARS (value);
2287 if (strncmp (color_name, unspecified_bg, csz) == 0)
2288 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2289 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2290 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2292 else if (EQ (parameter, Qforeground_color))
2294 color_name = SSDATA (value);
2295 csz = SCHARS (value);
2296 if (strncmp (color_name, unspecified_fg, csz) == 0)
2297 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2298 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2299 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2303 else
2304 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2306 else if (EQ (parameter, Qdisplay_type)
2307 || EQ (parameter, Qbackground_mode))
2308 value = Fcdr (Fassq (parameter, f->param_alist));
2309 else
2310 /* FIXME: Avoid this code path at all (as well as code duplication)
2311 by sharing more code with Fframe_parameters. */
2312 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2315 return value;
2319 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2320 Smodify_frame_parameters, 2, 2, 0,
2321 doc: /* Modify the parameters of frame FRAME according to ALIST.
2322 If FRAME is nil, it defaults to the selected frame.
2323 ALIST is an alist of parameters to change and their new values.
2324 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2325 The meaningful PARMs depend on the kind of frame.
2326 Undefined PARMs are ignored, but stored in the frame's parameter list
2327 so that `frame-parameters' will return them.
2329 The value of frame parameter FOO can also be accessed
2330 as a frame-local binding for the variable FOO, if you have
2331 enabled such bindings for that variable with `make-variable-frame-local'.
2332 Note that this functionality is obsolete as of Emacs 22.2, and its
2333 use is not recommended. Explicitly check for a frame-parameter instead. */)
2334 (Lisp_Object frame, Lisp_Object alist)
2336 struct frame *f = decode_live_frame (frame);
2337 register Lisp_Object prop, val;
2339 CHECK_LIST (alist);
2341 /* I think this should be done with a hook. */
2342 #ifdef HAVE_WINDOW_SYSTEM
2343 if (FRAME_WINDOW_P (f))
2344 x_set_frame_parameters (f, alist);
2345 else
2346 #endif
2347 #ifdef MSDOS
2348 if (FRAME_MSDOS_P (f))
2349 IT_set_frame_parameters (f, alist);
2350 else
2351 #endif
2354 EMACS_INT length = XFASTINT (Flength (alist));
2355 ptrdiff_t i;
2356 Lisp_Object *parms;
2357 Lisp_Object *values;
2358 USE_SAFE_ALLOCA;
2359 SAFE_ALLOCA_LISP (parms, 2 * length);
2360 values = parms + length;
2362 /* Extract parm names and values into those vectors. */
2364 for (i = 0; CONSP (alist); alist = XCDR (alist))
2366 Lisp_Object elt;
2368 elt = XCAR (alist);
2369 parms[i] = Fcar (elt);
2370 values[i] = Fcdr (elt);
2371 i++;
2374 /* Now process them in reverse of specified order. */
2375 while (--i >= 0)
2377 prop = parms[i];
2378 val = values[i];
2379 store_frame_param (f, prop, val);
2381 if (EQ (prop, Qforeground_color)
2382 || EQ (prop, Qbackground_color))
2383 update_face_from_frame_parameter (f, prop, val);
2386 SAFE_FREE ();
2388 return Qnil;
2391 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2392 0, 1, 0,
2393 doc: /* Height in pixels of a line in the font in frame FRAME.
2394 If FRAME is omitted or nil, the selected frame is used.
2395 For a terminal frame, the value is always 1. */)
2396 (Lisp_Object frame)
2398 #ifdef HAVE_WINDOW_SYSTEM
2399 struct frame *f = decode_any_frame (frame);
2401 if (FRAME_WINDOW_P (f))
2402 return make_number (FRAME_LINE_HEIGHT (f));
2403 else
2404 #endif
2405 return make_number (1);
2409 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2410 0, 1, 0,
2411 doc: /* Width in pixels of characters in the font in frame FRAME.
2412 If FRAME is omitted or nil, the selected frame is used.
2413 On a graphical screen, the width is the standard width of the default font.
2414 For a terminal screen, the value is always 1. */)
2415 (Lisp_Object frame)
2417 #ifdef HAVE_WINDOW_SYSTEM
2418 struct frame *f = decode_any_frame (frame);
2420 if (FRAME_WINDOW_P (f))
2421 return make_number (FRAME_COLUMN_WIDTH (f));
2422 else
2423 #endif
2424 return make_number (1);
2427 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2428 Sframe_pixel_height, 0, 1, 0,
2429 doc: /* Return a FRAME's height in pixels.
2430 If FRAME is omitted or nil, the selected frame is used. The exact value
2431 of the result depends on the window-system and toolkit in use:
2433 In the Gtk+ version of Emacs, it includes only any window (including
2434 the minibuffer or echo area), mode line, and header line. It does not
2435 include the tool bar or menu bar.
2437 With other graphical versions, it also includes the tool bar and the
2438 menu bar.
2440 For a text terminal, it includes the menu bar. In this case, the
2441 result is really in characters rather than pixels (i.e., is identical
2442 to `frame-height'). */)
2443 (Lisp_Object frame)
2445 struct frame *f = decode_any_frame (frame);
2447 #ifdef HAVE_WINDOW_SYSTEM
2448 if (FRAME_WINDOW_P (f))
2449 return make_number (FRAME_PIXEL_HEIGHT (f));
2450 else
2451 #endif
2452 return make_number (FRAME_LINES (f));
2455 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2456 Sframe_pixel_width, 0, 1, 0,
2457 doc: /* Return FRAME's width in pixels.
2458 For a terminal frame, the result really gives the width in characters.
2459 If FRAME is omitted or nil, the selected frame is used. */)
2460 (Lisp_Object frame)
2462 struct frame *f = decode_any_frame (frame);
2464 #ifdef HAVE_WINDOW_SYSTEM
2465 if (FRAME_WINDOW_P (f))
2466 return make_number (FRAME_PIXEL_WIDTH (f));
2467 else
2468 #endif
2469 return make_number (FRAME_COLS (f));
2472 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2473 Stool_bar_pixel_width, 0, 1, 0,
2474 doc: /* Return width in pixels of FRAME's tool bar.
2475 The result is greater than zero only when the tool bar is on the left
2476 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2477 is used. */)
2478 (Lisp_Object frame)
2480 #ifdef FRAME_TOOLBAR_WIDTH
2481 struct frame *f = decode_any_frame (frame);
2483 if (FRAME_WINDOW_P (f))
2484 return make_number (FRAME_TOOLBAR_WIDTH (f));
2485 #endif
2486 return make_number (0);
2489 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2490 doc: /* Return width in columns of FRAME's text area. */)
2491 (Lisp_Object frame)
2493 return make_number (FRAME_COLS (decode_any_frame (frame)));
2496 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2497 doc: /* Return height in lines of FRAME's text area. */)
2498 (Lisp_Object frame)
2500 return make_number (FRAME_LINES (decode_any_frame (frame)));
2503 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2504 doc: /* Return total columns of FRAME. */)
2505 (Lisp_Object frame)
2507 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2510 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2511 doc: /* Return text area width of FRAME in pixels. */)
2512 (Lisp_Object frame)
2514 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2517 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2518 doc: /* Return text area height of FRAME in pixels. */)
2519 (Lisp_Object frame)
2521 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2524 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2525 doc: /* Return scroll bar width of FRAME in pixels. */)
2526 (Lisp_Object frame)
2528 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2531 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2532 doc: /* Return fringe width of FRAME in pixels. */)
2533 (Lisp_Object frame)
2535 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2538 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2539 doc: /* Return border width of FRAME in pixels. */)
2540 (Lisp_Object frame)
2542 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2545 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2546 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2547 (Lisp_Object frame)
2549 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2552 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2553 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2554 (Lisp_Object frame)
2556 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2559 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2560 doc: /* Specify that the frame FRAME has HEIGHT text lines.
2561 Optional third arg PRETEND non-nil means that redisplay should use
2562 HEIGHT lines but that the idea of the actual height of the frame should
2563 not be changed. Optional fourth argument PIXELWISE non-nil means that
2564 FRAME should be HEIGHT pixels high. */)
2565 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2567 register struct frame *f = decode_live_frame (frame);
2569 CHECK_TYPE_RANGED_INTEGER (int, height);
2571 /* I think this should be done with a hook. */
2572 #ifdef HAVE_WINDOW_SYSTEM
2573 if (FRAME_WINDOW_P (f))
2575 if (NILP (pixelwise))
2577 if (XINT (height) != FRAME_LINES (f))
2578 x_set_window_size (f, 1, FRAME_COLS (f), XINT (height), 0);
2580 do_pending_window_change (0);
2582 else if (XINT (height) != FRAME_TEXT_HEIGHT (f))
2584 x_set_window_size (f, 1, FRAME_TEXT_WIDTH (f), XINT (height), 1);
2585 do_pending_window_change (0);
2588 else
2589 #endif
2590 change_frame_size (f, 0, XINT (height), !NILP (pretend), 0, 0,
2591 NILP (pixelwise) ? 0 : 1);
2592 return Qnil;
2595 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2596 doc: /* Specify that the frame FRAME has WIDTH columns.
2597 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2598 columns but that the idea of the actual width of the frame should not
2599 be changed. Optional fourth argument PIXELWISE non-nil means that FRAME
2600 should be WIDTH pixels wide. */)
2601 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2603 register struct frame *f = decode_live_frame (frame);
2605 CHECK_TYPE_RANGED_INTEGER (int, width);
2607 /* I think this should be done with a hook. */
2608 #ifdef HAVE_WINDOW_SYSTEM
2609 if (FRAME_WINDOW_P (f))
2611 if (NILP (pixelwise))
2613 if (XINT (width) != FRAME_COLS (f))
2614 x_set_window_size (f, 1, XINT (width), FRAME_LINES (f), 0);
2616 do_pending_window_change (0);
2618 else if (XINT (width) != FRAME_TEXT_WIDTH (f))
2620 x_set_window_size (f, 1, XINT (width), FRAME_TEXT_HEIGHT (f), 1);
2621 do_pending_window_change (0);
2624 else
2625 #endif
2626 change_frame_size (f, XINT (width), 0, !NILP (pretend), 0, 0,
2627 NILP (pixelwise) ? 0 : 1);
2628 return Qnil;
2631 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2632 doc: /* Sets size of FRAME to WIDTH by HEIGHT, measured in characters.
2633 Optional argument PIXELWISE non-nil means to measure in pixels. */)
2634 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2636 register struct frame *f = decode_live_frame (frame);
2638 CHECK_TYPE_RANGED_INTEGER (int, width);
2639 CHECK_TYPE_RANGED_INTEGER (int, height);
2641 /* I think this should be done with a hook. */
2642 #ifdef HAVE_WINDOW_SYSTEM
2643 if (FRAME_WINDOW_P (f))
2645 if (!NILP (pixelwise)
2646 ? (XINT (width) != FRAME_TEXT_WIDTH (f)
2647 || XINT (height) != FRAME_TEXT_HEIGHT (f)
2648 || f->new_height || f->new_width)
2649 : (XINT (width) != FRAME_COLS (f)
2650 || XINT (height) != FRAME_LINES (f)
2651 || f->new_height || f->new_width))
2653 x_set_window_size (f, 1, XINT (width), XINT (height),
2654 NILP (pixelwise) ? 0 : 1);
2655 do_pending_window_change (0);
2658 else
2659 #endif
2660 change_frame_size (f, XINT (width), XINT (height), 0, 0, 0,
2661 NILP (pixelwise) ? 0 : 1);
2663 return Qnil;
2666 DEFUN ("set-frame-position", Fset_frame_position,
2667 Sset_frame_position, 3, 3, 0,
2668 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2669 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2670 actually the position of the upper left corner of the frame. Negative
2671 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2672 or bottommost possible position (that stays within the screen). */)
2673 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2675 register struct frame *f = decode_live_frame (frame);
2677 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2678 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2680 /* I think this should be done with a hook. */
2681 #ifdef HAVE_WINDOW_SYSTEM
2682 if (FRAME_WINDOW_P (f))
2683 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2684 #endif
2686 return Qt;
2690 /***********************************************************************
2691 Frame Parameters
2692 ***********************************************************************/
2694 /* Connect the frame-parameter names for X frames
2695 to the ways of passing the parameter values to the window system.
2697 The name of a parameter, as a Lisp symbol,
2698 has an `x-frame-parameter' property which is an integer in Lisp
2699 that is an index in this table. */
2701 struct frame_parm_table {
2702 const char *name;
2703 Lisp_Object *variable;
2706 static const struct frame_parm_table frame_parms[] =
2708 {"auto-raise", &Qauto_raise},
2709 {"auto-lower", &Qauto_lower},
2710 {"background-color", 0},
2711 {"border-color", &Qborder_color},
2712 {"border-width", &Qborder_width},
2713 {"cursor-color", &Qcursor_color},
2714 {"cursor-type", &Qcursor_type},
2715 {"font", 0},
2716 {"foreground-color", 0},
2717 {"icon-name", &Qicon_name},
2718 {"icon-type", &Qicon_type},
2719 {"internal-border-width", &Qinternal_border_width},
2720 {"right-divider-width", &Qright_divider_width},
2721 {"bottom-divider-width", &Qbottom_divider_width},
2722 {"menu-bar-lines", &Qmenu_bar_lines},
2723 {"mouse-color", &Qmouse_color},
2724 {"name", &Qname},
2725 {"scroll-bar-width", &Qscroll_bar_width},
2726 {"title", &Qtitle},
2727 {"unsplittable", &Qunsplittable},
2728 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2729 {"visibility", &Qvisibility},
2730 {"tool-bar-lines", &Qtool_bar_lines},
2731 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2732 {"scroll-bar-background", &Qscroll_bar_background},
2733 {"screen-gamma", &Qscreen_gamma},
2734 {"line-spacing", &Qline_spacing},
2735 {"left-fringe", &Qleft_fringe},
2736 {"right-fringe", &Qright_fringe},
2737 {"wait-for-wm", &Qwait_for_wm},
2738 {"fullscreen", &Qfullscreen},
2739 {"font-backend", &Qfont_backend},
2740 {"alpha", &Qalpha},
2741 {"sticky", &Qsticky},
2742 {"tool-bar-position", &Qtool_bar_position},
2745 #ifdef HAVE_NTGUI
2747 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2748 wanted positions of the WM window (not Emacs window).
2749 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2750 window (FRAME_X_WINDOW).
2753 void
2754 x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
2756 int newwidth = FRAME_COLS (f);
2757 int newheight = FRAME_LINES (f);
2758 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
2760 *top_pos = f->top_pos;
2761 *left_pos = f->left_pos;
2763 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2765 int ph;
2767 ph = x_display_pixel_height (dpyinfo);
2768 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2769 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2770 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2771 *top_pos = 0;
2774 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2776 int pw;
2778 pw = x_display_pixel_width (dpyinfo);
2779 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2780 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2781 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2782 *left_pos = 0;
2785 *width = newwidth;
2786 *height = newheight;
2789 #endif /* HAVE_NTGUI */
2791 #ifdef HAVE_WINDOW_SYSTEM
2793 /* Change the parameters of frame F as specified by ALIST.
2794 If a parameter is not specially recognized, do nothing special;
2795 otherwise call the `x_set_...' function for that parameter.
2796 Except for certain geometry properties, always call store_frame_param
2797 to store the new value in the parameter alist. */
2799 void
2800 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
2802 Lisp_Object tail;
2804 /* If both of these parameters are present, it's more efficient to
2805 set them both at once. So we wait until we've looked at the
2806 entire list before we set them. */
2807 int width = 0, height = 0;
2808 bool width_change = 0, height_change = 0;
2810 /* Same here. */
2811 Lisp_Object left, top;
2813 /* Same with these. */
2814 Lisp_Object icon_left, icon_top;
2816 /* Record in these vectors all the parms specified. */
2817 Lisp_Object *parms;
2818 Lisp_Object *values;
2819 ptrdiff_t i, p;
2820 bool left_no_change = 0, top_no_change = 0;
2821 #ifdef HAVE_X_WINDOWS
2822 bool icon_left_no_change = 0, icon_top_no_change = 0;
2823 #endif
2824 struct gcpro gcpro1, gcpro2;
2826 i = 0;
2827 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2828 i++;
2830 parms = alloca (i * sizeof *parms);
2831 values = alloca (i * sizeof *values);
2833 /* Extract parm names and values into those vectors. */
2835 i = 0;
2836 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2838 Lisp_Object elt;
2840 elt = XCAR (tail);
2841 parms[i] = Fcar (elt);
2842 values[i] = Fcdr (elt);
2843 i++;
2845 /* TAIL and ALIST are not used again below here. */
2846 alist = tail = Qnil;
2848 GCPRO2 (*parms, *values);
2849 gcpro1.nvars = i;
2850 gcpro2.nvars = i;
2852 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2853 because their values appear in VALUES and strings are not valid. */
2854 top = left = Qunbound;
2855 icon_left = icon_top = Qunbound;
2857 /* Process foreground_color and background_color before anything else.
2858 They are independent of other properties, but other properties (e.g.,
2859 cursor_color) are dependent upon them. */
2860 /* Process default font as well, since fringe widths depends on it. */
2861 for (p = 0; p < i; p++)
2863 Lisp_Object prop, val;
2865 prop = parms[p];
2866 val = values[p];
2867 if (EQ (prop, Qforeground_color)
2868 || EQ (prop, Qbackground_color)
2869 || EQ (prop, Qfont))
2871 register Lisp_Object param_index, old_value;
2873 old_value = get_frame_param (f, prop);
2874 if (NILP (Fequal (val, old_value)))
2876 store_frame_param (f, prop, val);
2878 param_index = Fget (prop, Qx_frame_parameter);
2879 if (NATNUMP (param_index)
2880 && (XFASTINT (param_index)
2881 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2882 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2883 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2888 /* Now process them in reverse of specified order. */
2889 while (i-- != 0)
2891 Lisp_Object prop, val;
2893 prop = parms[i];
2894 val = values[i];
2896 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
2898 width_change = 1;
2899 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
2901 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
2903 height_change = 1;
2904 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
2906 else if (EQ (prop, Qtop))
2907 top = val;
2908 else if (EQ (prop, Qleft))
2909 left = val;
2910 else if (EQ (prop, Qicon_top))
2911 icon_top = val;
2912 else if (EQ (prop, Qicon_left))
2913 icon_left = val;
2914 else if (EQ (prop, Qforeground_color)
2915 || EQ (prop, Qbackground_color)
2916 || EQ (prop, Qfont))
2917 /* Processed above. */
2918 continue;
2919 else
2921 register Lisp_Object param_index, old_value;
2923 old_value = get_frame_param (f, prop);
2925 store_frame_param (f, prop, val);
2927 param_index = Fget (prop, Qx_frame_parameter);
2928 if (NATNUMP (param_index)
2929 && (XFASTINT (param_index)
2930 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2931 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2932 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2936 /* Don't die if just one of these was set. */
2937 if (EQ (left, Qunbound))
2939 left_no_change = 1;
2940 if (f->left_pos < 0)
2941 left = list2 (Qplus, make_number (f->left_pos));
2942 else
2943 XSETINT (left, f->left_pos);
2945 if (EQ (top, Qunbound))
2947 top_no_change = 1;
2948 if (f->top_pos < 0)
2949 top = list2 (Qplus, make_number (f->top_pos));
2950 else
2951 XSETINT (top, f->top_pos);
2954 /* If one of the icon positions was not set, preserve or default it. */
2955 if (! TYPE_RANGED_INTEGERP (int, icon_left))
2957 #ifdef HAVE_X_WINDOWS
2958 icon_left_no_change = 1;
2959 #endif
2960 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2961 if (NILP (icon_left))
2962 XSETINT (icon_left, 0);
2964 if (! TYPE_RANGED_INTEGERP (int, icon_top))
2966 #ifdef HAVE_X_WINDOWS
2967 icon_top_no_change = 1;
2968 #endif
2969 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2970 if (NILP (icon_top))
2971 XSETINT (icon_top, 0);
2974 /* Don't set these parameters unless they've been explicitly
2975 specified. The window might be mapped or resized while we're in
2976 this function, and we don't want to override that unless the lisp
2977 code has asked for it.
2979 Don't set these parameters unless they actually differ from the
2980 window's current parameters; the window may not actually exist
2981 yet. */
2983 Lisp_Object frame;
2985 /* Make this 1, eventually. */
2986 check_frame_size (f, &width, &height, 1);
2988 XSETFRAME (frame, f);
2990 if ((width_change || height_change)
2991 && (width != FRAME_TEXT_WIDTH (f)
2992 || height != FRAME_TEXT_HEIGHT (f)
2993 || f->new_height || f->new_width))
2995 /* If necessary provide default values for HEIGHT and WIDTH. Do
2996 that here since otherwise a size change implied by an
2997 intermittent font change may get lost as in Bug#17142. */
2998 if (!width_change)
2999 width = (f->new_width
3000 ? (f->new_pixelwise
3001 ? f->new_width
3002 : (f->new_width * FRAME_COLUMN_WIDTH (f)))
3003 : FRAME_TEXT_WIDTH (f));
3005 if (!height_change)
3006 height = (f->new_height
3007 ? (f->new_pixelwise
3008 ? f->new_height
3009 : (f->new_height * FRAME_LINE_HEIGHT (f)))
3010 : FRAME_TEXT_HEIGHT (f));
3012 Fset_frame_size (frame, make_number (width), make_number (height), Qt);
3015 if ((!NILP (left) || !NILP (top))
3016 && ! (left_no_change && top_no_change)
3017 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3018 && NUMBERP (top) && XINT (top) == f->top_pos))
3020 int leftpos = 0;
3021 int toppos = 0;
3023 /* Record the signs. */
3024 f->size_hint_flags &= ~ (XNegative | YNegative);
3025 if (EQ (left, Qminus))
3026 f->size_hint_flags |= XNegative;
3027 else if (TYPE_RANGED_INTEGERP (int, left))
3029 leftpos = XINT (left);
3030 if (leftpos < 0)
3031 f->size_hint_flags |= XNegative;
3033 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3034 && CONSP (XCDR (left))
3035 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3037 leftpos = - XINT (XCAR (XCDR (left)));
3038 f->size_hint_flags |= XNegative;
3040 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3041 && CONSP (XCDR (left))
3042 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3044 leftpos = XINT (XCAR (XCDR (left)));
3047 if (EQ (top, Qminus))
3048 f->size_hint_flags |= YNegative;
3049 else if (TYPE_RANGED_INTEGERP (int, top))
3051 toppos = XINT (top);
3052 if (toppos < 0)
3053 f->size_hint_flags |= YNegative;
3055 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3056 && CONSP (XCDR (top))
3057 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3059 toppos = - XINT (XCAR (XCDR (top)));
3060 f->size_hint_flags |= YNegative;
3062 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3063 && CONSP (XCDR (top))
3064 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3066 toppos = XINT (XCAR (XCDR (top)));
3070 /* Store the numeric value of the position. */
3071 f->top_pos = toppos;
3072 f->left_pos = leftpos;
3074 f->win_gravity = NorthWestGravity;
3076 /* Actually set that position, and convert to absolute. */
3077 x_set_offset (f, leftpos, toppos, -1);
3079 #ifdef HAVE_X_WINDOWS
3080 if ((!NILP (icon_left) || !NILP (icon_top))
3081 && ! (icon_left_no_change && icon_top_no_change))
3082 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3083 #endif /* HAVE_X_WINDOWS */
3086 UNGCPRO;
3090 /* Insert a description of internally-recorded parameters of frame X
3091 into the parameter alist *ALISTPTR that is to be given to the user.
3092 Only parameters that are specific to the X window system
3093 and whose values are not correctly recorded in the frame's
3094 param_alist need to be considered here. */
3096 void
3097 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3099 Lisp_Object tem;
3100 uprintmax_t w;
3101 char buf[INT_BUFSIZE_BOUND (w)];
3103 /* Represent negative positions (off the top or left screen edge)
3104 in a way that Fmodify_frame_parameters will understand correctly. */
3105 XSETINT (tem, f->left_pos);
3106 if (f->left_pos >= 0)
3107 store_in_alist (alistptr, Qleft, tem);
3108 else
3109 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3111 XSETINT (tem, f->top_pos);
3112 if (f->top_pos >= 0)
3113 store_in_alist (alistptr, Qtop, tem);
3114 else
3115 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3117 store_in_alist (alistptr, Qborder_width,
3118 make_number (f->border_width));
3119 store_in_alist (alistptr, Qinternal_border_width,
3120 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3121 store_in_alist (alistptr, Qright_divider_width,
3122 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3123 store_in_alist (alistptr, Qbottom_divider_width,
3124 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3125 store_in_alist (alistptr, Qleft_fringe,
3126 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3127 store_in_alist (alistptr, Qright_fringe,
3128 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3129 store_in_alist (alistptr, Qscroll_bar_width,
3130 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3131 ? make_number (0)
3132 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3133 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3134 /* nil means "use default width"
3135 for non-toolkit scroll bar.
3136 ruler-mode.el depends on this. */
3137 : Qnil));
3138 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3139 MS-Windows it returns a value whose type is HANDLE, which is
3140 actually a pointer. Explicit casting avoids compiler
3141 warnings. */
3142 w = (uintptr_t) FRAME_X_WINDOW (f);
3143 store_in_alist (alistptr, Qwindow_id,
3144 make_formatted_string (buf, "%"pMu, w));
3145 #ifdef HAVE_X_WINDOWS
3146 #ifdef USE_X_TOOLKIT
3147 /* Tooltip frame may not have this widget. */
3148 if (FRAME_X_OUTPUT (f)->widget)
3149 #endif
3150 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3151 store_in_alist (alistptr, Qouter_window_id,
3152 make_formatted_string (buf, "%"pMu, w));
3153 #endif
3154 store_in_alist (alistptr, Qicon_name, f->icon_name);
3155 store_in_alist (alistptr, Qvisibility,
3156 (FRAME_VISIBLE_P (f) ? Qt
3157 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3158 store_in_alist (alistptr, Qdisplay,
3159 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3161 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3162 tem = Qnil;
3163 else
3164 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3165 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3166 store_in_alist (alistptr, Qparent_id, tem);
3167 store_in_alist (alistptr, Qtool_bar_position, f->tool_bar_position);
3171 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3172 the previous value of that parameter, NEW_VALUE is the new value. */
3174 void
3175 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3177 if (NILP (new_value))
3178 f->want_fullscreen = FULLSCREEN_NONE;
3179 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3180 f->want_fullscreen = FULLSCREEN_BOTH;
3181 else if (EQ (new_value, Qfullwidth))
3182 f->want_fullscreen = FULLSCREEN_WIDTH;
3183 else if (EQ (new_value, Qfullheight))
3184 f->want_fullscreen = FULLSCREEN_HEIGHT;
3185 else if (EQ (new_value, Qmaximized))
3186 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3188 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3189 FRAME_TERMINAL (f)->fullscreen_hook (f);
3193 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3194 the previous value of that parameter, NEW_VALUE is the new value. */
3196 void
3197 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3199 if (NILP (new_value))
3200 f->extra_line_spacing = 0;
3201 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3202 f->extra_line_spacing = XFASTINT (new_value);
3203 else if (FLOATP (new_value))
3205 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3207 if (new_spacing >= 0)
3208 f->extra_line_spacing = new_spacing;
3209 else
3210 signal_error ("Invalid line-spacing", new_value);
3212 else
3213 signal_error ("Invalid line-spacing", new_value);
3214 if (FRAME_VISIBLE_P (f))
3215 redraw_frame (f);
3219 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3220 the previous value of that parameter, NEW_VALUE is the new value. */
3222 void
3223 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3225 Lisp_Object bgcolor;
3227 if (NILP (new_value))
3228 f->gamma = 0;
3229 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3230 /* The value 0.4545 is the normal viewing gamma. */
3231 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3232 else
3233 signal_error ("Invalid screen-gamma", new_value);
3235 /* Apply the new gamma value to the frame background. */
3236 bgcolor = Fassq (Qbackground_color, f->param_alist);
3237 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3239 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3240 if (NATNUMP (parm_index)
3241 && (XFASTINT (parm_index)
3242 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3243 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3244 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3245 (f, bgcolor, Qnil);
3248 Fclear_face_cache (Qnil);
3252 void
3253 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3255 Lisp_Object font_object;
3256 int fontset = -1;
3257 #ifdef HAVE_X_WINDOWS
3258 Lisp_Object font_param = arg;
3259 #endif
3261 /* Set the frame parameter back to the old value because we may
3262 fail to use ARG as the new parameter value. */
3263 store_frame_param (f, Qfont, oldval);
3265 /* ARG is a fontset name, a font name, a cons of fontset name and a
3266 font object, or a font object. In the last case, this function
3267 never fail. */
3268 if (STRINGP (arg))
3270 fontset = fs_query_fontset (arg, 0);
3271 if (fontset < 0)
3273 font_object = font_open_by_name (f, arg);
3274 if (NILP (font_object))
3275 error ("Font `%s' is not defined", SSDATA (arg));
3276 arg = AREF (font_object, FONT_NAME_INDEX);
3278 else if (fontset > 0)
3280 font_object = font_open_by_name (f, fontset_ascii (fontset));
3281 if (NILP (font_object))
3282 error ("Font `%s' is not defined", SDATA (arg));
3283 arg = AREF (font_object, FONT_NAME_INDEX);
3285 else
3286 error ("The default fontset can't be used for a frame font");
3288 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3290 /* This is the case that the ASCII font of F's fontset XCAR
3291 (arg) is changed to the font XCDR (arg) by
3292 `set-fontset-font'. */
3293 fontset = fs_query_fontset (XCAR (arg), 0);
3294 if (fontset < 0)
3295 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3296 font_object = XCDR (arg);
3297 arg = AREF (font_object, FONT_NAME_INDEX);
3298 #ifdef HAVE_X_WINDOWS
3299 font_param = Ffont_get (font_object, QCname);
3300 #endif
3302 else if (FONT_OBJECT_P (arg))
3304 font_object = arg;
3305 #ifdef HAVE_X_WINDOWS
3306 font_param = Ffont_get (font_object, QCname);
3307 #endif
3308 /* This is to store the XLFD font name in the frame parameter for
3309 backward compatibility. We should store the font-object
3310 itself in the future. */
3311 arg = AREF (font_object, FONT_NAME_INDEX);
3312 fontset = FRAME_FONTSET (f);
3313 /* Check if we can use the current fontset. If not, set FONTSET
3314 to -1 to generate a new fontset from FONT-OBJECT. */
3315 if (fontset >= 0)
3317 Lisp_Object ascii_font = fontset_ascii (fontset);
3318 Lisp_Object spec = font_spec_from_name (ascii_font);
3320 if (NILP (spec))
3321 signal_error ("Invalid font name", ascii_font);
3323 if (! font_match_p (spec, font_object))
3324 fontset = -1;
3327 else
3328 signal_error ("Invalid font", arg);
3330 if (! NILP (Fequal (font_object, oldval)))
3331 return;
3333 x_new_font (f, font_object, fontset);
3334 store_frame_param (f, Qfont, arg);
3335 #ifdef HAVE_X_WINDOWS
3336 store_frame_param (f, Qfont_param, font_param);
3337 #endif
3338 /* Recalculate toolbar height. */
3339 f->n_tool_bar_rows = 0;
3341 /* Ensure we redraw it. */
3342 clear_current_matrices (f);
3344 /* Attempt to hunt down bug#16028. */
3345 SET_FRAME_GARBAGED (f);
3347 recompute_basic_faces (f);
3349 do_pending_window_change (0);
3351 /* We used to call face-set-after-frame-default here, but it leads to
3352 recursive calls (since that function can set the `default' face's
3353 font which in turns changes the frame's `font' parameter).
3354 Also I don't know what this call is meant to do, but it seems the
3355 wrong way to do it anyway (it does a lot more work than what seems
3356 reasonable in response to a change to `font'). */
3360 void
3361 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3363 if (! NILP (new_value)
3364 && !CONSP (new_value))
3366 char *p0, *p1;
3368 CHECK_STRING (new_value);
3369 p0 = p1 = SSDATA (new_value);
3370 new_value = Qnil;
3371 while (*p0)
3373 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3374 if (p0 < p1)
3375 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3376 new_value);
3377 if (*p1)
3379 int c;
3381 while ((c = *++p1) && c_isspace (c));
3383 p0 = p1;
3385 new_value = Fnreverse (new_value);
3388 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3389 return;
3391 if (FRAME_FONT (f))
3392 free_all_realized_faces (Qnil);
3394 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3395 if (NILP (new_value))
3397 if (NILP (old_value))
3398 error ("No font backend available");
3399 font_update_drivers (f, old_value);
3400 error ("None of specified font backends are available");
3402 store_frame_param (f, Qfont_backend, new_value);
3404 if (FRAME_FONT (f))
3406 Lisp_Object frame;
3408 XSETFRAME (frame, f);
3409 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3410 ++face_change_count;
3411 windows_or_buffers_changed = 18;
3416 void
3417 x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3419 compute_fringe_widths (f, 1);
3420 #ifdef HAVE_X_WINDOWS
3421 /* Must adjust this so window managers report correct number of columns. */
3422 if (FRAME_X_WINDOW (f) != 0)
3423 x_wm_set_size_hint (f, 0, 0);
3424 #endif
3427 void
3428 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3430 CHECK_TYPE_RANGED_INTEGER (int, arg);
3432 if (XINT (arg) == f->border_width)
3433 return;
3435 if (FRAME_X_WINDOW (f) != 0)
3436 error ("Cannot change the border width of a frame");
3438 f->border_width = XINT (arg);
3441 void
3442 x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3444 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3446 CHECK_TYPE_RANGED_INTEGER (int, arg);
3447 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3448 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3449 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3451 #ifdef USE_X_TOOLKIT
3452 if (FRAME_X_OUTPUT (f)->edit_widget)
3453 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3454 #endif
3456 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3457 return;
3459 if (FRAME_X_WINDOW (f) != 0)
3461 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 1);
3462 SET_FRAME_GARBAGED (f);
3463 do_pending_window_change (0);
3465 else
3466 SET_FRAME_GARBAGED (f);
3469 void
3470 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3472 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3474 CHECK_TYPE_RANGED_INTEGER (int, arg);
3475 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3476 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3477 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3479 if (FRAME_RIGHT_DIVIDER_WIDTH (f) == old)
3480 return;
3482 if (FRAME_X_WINDOW (f) != 0)
3484 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 1);
3485 SET_FRAME_GARBAGED (f);
3486 do_pending_window_change (0);
3488 else
3489 SET_FRAME_GARBAGED (f);
3492 void
3493 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3495 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3497 CHECK_TYPE_RANGED_INTEGER (int, arg);
3498 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3499 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3500 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3502 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) == old)
3503 return;
3505 if (FRAME_X_WINDOW (f) != 0)
3507 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 1);
3508 SET_FRAME_GARBAGED (f);
3509 do_pending_window_change (0);
3511 else
3512 SET_FRAME_GARBAGED (f);
3515 void
3516 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3518 Lisp_Object frame;
3519 XSETFRAME (frame, f);
3521 if (NILP (value))
3522 Fmake_frame_invisible (frame, Qt);
3523 else if (EQ (value, Qicon))
3524 Ficonify_frame (frame);
3525 else
3526 Fmake_frame_visible (frame);
3529 void
3530 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3532 f->auto_raise = !EQ (Qnil, arg);
3535 void
3536 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3538 f->auto_lower = !EQ (Qnil, arg);
3541 void
3542 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3544 f->no_split = !NILP (arg);
3547 void
3548 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3550 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3551 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3552 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3553 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3555 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3556 = (NILP (arg)
3557 ? vertical_scroll_bar_none
3558 : EQ (Qleft, arg)
3559 ? vertical_scroll_bar_left
3560 : EQ (Qright, arg)
3561 ? vertical_scroll_bar_right
3562 : EQ (Qleft, Vdefault_frame_scroll_bars)
3563 ? vertical_scroll_bar_left
3564 : EQ (Qright, Vdefault_frame_scroll_bars)
3565 ? vertical_scroll_bar_right
3566 : vertical_scroll_bar_none);
3568 /* We set this parameter before creating the X window for the
3569 frame, so we can get the geometry right from the start.
3570 However, if the window hasn't been created yet, we shouldn't
3571 call x_set_window_size. */
3572 if (FRAME_X_WINDOW (f))
3573 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f),
3574 FRAME_TEXT_HEIGHT (f), 1);
3575 do_pending_window_change (0);
3579 void
3580 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3582 int unit = FRAME_COLUMN_WIDTH (f);
3584 if (NILP (arg))
3586 x_set_scroll_bar_default_width (f);
3588 if (FRAME_X_WINDOW (f))
3589 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f),
3590 FRAME_TEXT_HEIGHT (f), 1);
3591 do_pending_window_change (0);
3593 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3594 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3596 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3597 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3598 if (FRAME_X_WINDOW (f))
3599 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f),
3600 FRAME_TEXT_HEIGHT (f), 1);
3601 do_pending_window_change (0);
3604 /* Eventually remove the following call. It should have been done by
3605 x_set_window_size already. */
3606 change_frame_size (f, 0, 0, 0, 0, 0, 1);
3607 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3608 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3611 void
3612 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3614 double alpha = 1.0;
3615 double newval[2];
3616 int i;
3617 Lisp_Object item;
3619 for (i = 0; i < 2; i++)
3621 newval[i] = 1.0;
3622 if (CONSP (arg))
3624 item = CAR (arg);
3625 arg = CDR (arg);
3627 else
3628 item = arg;
3630 if (NILP (item))
3631 alpha = - 1.0;
3632 else if (FLOATP (item))
3634 alpha = XFLOAT_DATA (item);
3635 if (! (0 <= alpha && alpha <= 1.0))
3636 args_out_of_range (make_float (0.0), make_float (1.0));
3638 else if (INTEGERP (item))
3640 EMACS_INT ialpha = XINT (item);
3641 if (! (0 <= ialpha && alpha <= 100))
3642 args_out_of_range (make_number (0), make_number (100));
3643 alpha = ialpha / 100.0;
3645 else
3646 wrong_type_argument (Qnumberp, item);
3647 newval[i] = alpha;
3650 for (i = 0; i < 2; i++)
3651 f->alpha[i] = newval[i];
3653 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3654 block_input ();
3655 x_set_frame_alpha (f);
3656 unblock_input ();
3657 #endif
3659 return;
3662 #ifndef HAVE_NS
3664 /* Non-zero if mouse is grabbed on DPYINFO
3665 and we know the frame where it is. */
3667 bool x_mouse_grabbed (Display_Info *dpyinfo)
3669 return (dpyinfo->grabbed
3670 && dpyinfo->last_mouse_frame
3671 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
3674 /* Re-highlight something with mouse-face properties
3675 on DPYINFO using saved frame and mouse position. */
3677 void
3678 x_redo_mouse_highlight (Display_Info *dpyinfo)
3680 if (dpyinfo->last_mouse_motion_frame
3681 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
3682 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
3683 dpyinfo->last_mouse_motion_x,
3684 dpyinfo->last_mouse_motion_y);
3687 #endif /* HAVE_NS */
3689 /* Subroutines of creating an X frame. */
3691 /* Make sure that Vx_resource_name is set to a reasonable value.
3692 Fix it up, or set it to `emacs' if it is too hopeless. */
3694 void
3695 validate_x_resource_name (void)
3697 ptrdiff_t len = 0;
3698 /* Number of valid characters in the resource name. */
3699 ptrdiff_t good_count = 0;
3700 /* Number of invalid characters in the resource name. */
3701 ptrdiff_t bad_count = 0;
3702 Lisp_Object new;
3703 ptrdiff_t i;
3705 if (!STRINGP (Vx_resource_class))
3706 Vx_resource_class = build_string (EMACS_CLASS);
3708 if (STRINGP (Vx_resource_name))
3710 unsigned char *p = SDATA (Vx_resource_name);
3712 len = SBYTES (Vx_resource_name);
3714 /* Only letters, digits, - and _ are valid in resource names.
3715 Count the valid characters and count the invalid ones. */
3716 for (i = 0; i < len; i++)
3718 int c = p[i];
3719 if (! ((c >= 'a' && c <= 'z')
3720 || (c >= 'A' && c <= 'Z')
3721 || (c >= '0' && c <= '9')
3722 || c == '-' || c == '_'))
3723 bad_count++;
3724 else
3725 good_count++;
3728 else
3729 /* Not a string => completely invalid. */
3730 bad_count = 5, good_count = 0;
3732 /* If name is valid already, return. */
3733 if (bad_count == 0)
3734 return;
3736 /* If name is entirely invalid, or nearly so, or is so implausibly
3737 large that alloca might not work, use `emacs'. */
3738 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3740 Vx_resource_name = build_string ("emacs");
3741 return;
3744 /* Name is partly valid. Copy it and replace the invalid characters
3745 with underscores. */
3747 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3749 for (i = 0; i < len; i++)
3751 int c = SREF (new, i);
3752 if (! ((c >= 'a' && c <= 'z')
3753 || (c >= 'A' && c <= 'Z')
3754 || (c >= '0' && c <= '9')
3755 || c == '-' || c == '_'))
3756 SSET (new, i, '_');
3760 /* Get specified attribute from resource database RDB.
3761 See Fx_get_resource below for other parameters. */
3763 static Lisp_Object
3764 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3766 register char *value;
3767 char *name_key;
3768 char *class_key;
3770 CHECK_STRING (attribute);
3771 CHECK_STRING (class);
3773 if (!NILP (component))
3774 CHECK_STRING (component);
3775 if (!NILP (subclass))
3776 CHECK_STRING (subclass);
3777 if (NILP (component) != NILP (subclass))
3778 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3780 validate_x_resource_name ();
3782 /* Allocate space for the components, the dots which separate them,
3783 and the final '\0'. Make them big enough for the worst case. */
3784 name_key = alloca (SBYTES (Vx_resource_name)
3785 + (STRINGP (component)
3786 ? SBYTES (component) : 0)
3787 + SBYTES (attribute)
3788 + 3);
3790 class_key = alloca (SBYTES (Vx_resource_class)
3791 + SBYTES (class)
3792 + (STRINGP (subclass)
3793 ? SBYTES (subclass) : 0)
3794 + 3);
3796 /* Start with emacs.FRAMENAME for the name (the specific one)
3797 and with `Emacs' for the class key (the general one). */
3798 strcpy (name_key, SSDATA (Vx_resource_name));
3799 strcpy (class_key, SSDATA (Vx_resource_class));
3801 strcat (class_key, ".");
3802 strcat (class_key, SSDATA (class));
3804 if (!NILP (component))
3806 strcat (class_key, ".");
3807 strcat (class_key, SSDATA (subclass));
3809 strcat (name_key, ".");
3810 strcat (name_key, SSDATA (component));
3813 strcat (name_key, ".");
3814 strcat (name_key, SSDATA (attribute));
3816 value = x_get_string_resource (rdb, name_key, class_key);
3818 if (value && *value)
3819 return build_string (value);
3820 else
3821 return Qnil;
3825 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3826 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3827 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3828 class, where INSTANCE is the name under which Emacs was invoked, or
3829 the name specified by the `-name' or `-rn' command-line arguments.
3831 The optional arguments COMPONENT and SUBCLASS add to the key and the
3832 class, respectively. You must specify both of them or neither.
3833 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3834 and the class is `Emacs.CLASS.SUBCLASS'. */)
3835 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
3836 Lisp_Object subclass)
3838 check_window_system (NULL);
3840 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3841 attribute, class, component, subclass);
3844 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3846 Lisp_Object
3847 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
3848 Lisp_Object class, Lisp_Object component,
3849 Lisp_Object subclass)
3851 return xrdb_get_resource (dpyinfo->xrdb,
3852 attribute, class, component, subclass);
3855 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3856 /* Used when C code wants a resource value. */
3857 /* Called from oldXMenu/Create.c. */
3858 char *
3859 x_get_resource_string (const char *attribute, const char *class)
3861 char *result;
3862 struct frame *sf = SELECTED_FRAME ();
3863 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
3864 USE_SAFE_ALLOCA;
3866 /* Allocate space for the components, the dots which separate them,
3867 and the final '\0'. */
3868 char *name_key = SAFE_ALLOCA (invocation_namelen + strlen (attribute) + 2);
3869 char *class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2);
3871 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
3872 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3874 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
3875 name_key, class_key);
3876 SAFE_FREE ();
3877 return result;
3879 #endif
3881 /* Return the value of parameter PARAM.
3883 First search ALIST, then Vdefault_frame_alist, then the X defaults
3884 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3886 Convert the resource to the type specified by desired_type.
3888 If no default is specified, return Qunbound. If you call
3889 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3890 and don't let it get stored in any Lisp-visible variables! */
3892 Lisp_Object
3893 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
3894 const char *attribute, const char *class, enum resource_types type)
3896 register Lisp_Object tem;
3898 tem = Fassq (param, alist);
3900 if (!NILP (tem))
3902 /* If we find this parm in ALIST, clear it out
3903 so that it won't be "left over" at the end. */
3904 Lisp_Object tail;
3905 XSETCAR (tem, Qnil);
3906 /* In case the parameter appears more than once in the alist,
3907 clear it out. */
3908 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3909 if (CONSP (XCAR (tail))
3910 && EQ (XCAR (XCAR (tail)), param))
3911 XSETCAR (XCAR (tail), Qnil);
3913 else
3914 tem = Fassq (param, Vdefault_frame_alist);
3916 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3917 look in the X resources. */
3918 if (EQ (tem, Qnil))
3920 if (attribute && dpyinfo)
3922 tem = display_x_get_resource (dpyinfo,
3923 build_string (attribute),
3924 build_string (class),
3925 Qnil, Qnil);
3927 if (NILP (tem))
3928 return Qunbound;
3930 switch (type)
3932 case RES_TYPE_NUMBER:
3933 return make_number (atoi (SSDATA (tem)));
3935 case RES_TYPE_BOOLEAN_NUMBER:
3936 if (!strcmp (SSDATA (tem), "on")
3937 || !strcmp (SSDATA (tem), "true"))
3938 return make_number (1);
3939 return make_number (atoi (SSDATA (tem)));
3940 break;
3942 case RES_TYPE_FLOAT:
3943 return make_float (atof (SSDATA (tem)));
3945 case RES_TYPE_BOOLEAN:
3946 tem = Fdowncase (tem);
3947 if (!strcmp (SSDATA (tem), "on")
3948 #ifdef HAVE_NS
3949 || !strcmp (SSDATA (tem), "yes")
3950 #endif
3951 || !strcmp (SSDATA (tem), "true"))
3952 return Qt;
3953 else
3954 return Qnil;
3956 case RES_TYPE_STRING:
3957 return tem;
3959 case RES_TYPE_SYMBOL:
3960 /* As a special case, we map the values `true' and `on'
3961 to Qt, and `false' and `off' to Qnil. */
3963 Lisp_Object lower;
3964 lower = Fdowncase (tem);
3965 if (!strcmp (SSDATA (lower), "on")
3966 #ifdef HAVE_NS
3967 || !strcmp (SSDATA (lower), "yes")
3968 #endif
3969 || !strcmp (SSDATA (lower), "true"))
3970 return Qt;
3971 else if (!strcmp (SSDATA (lower), "off")
3972 #ifdef HAVE_NS
3973 || !strcmp (SSDATA (lower), "no")
3974 #endif
3975 || !strcmp (SSDATA (lower), "false"))
3976 return Qnil;
3977 else
3978 return Fintern (tem, Qnil);
3981 default:
3982 emacs_abort ();
3985 else
3986 return Qunbound;
3988 return Fcdr (tem);
3991 static Lisp_Object
3992 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
3993 const char *attribute, const char *class,
3994 enum resource_types type)
3996 return x_get_arg (FRAME_DISPLAY_INFO (f),
3997 alist, param, attribute, class, type);
4000 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4002 Lisp_Object
4003 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4004 Lisp_Object param,
4005 const char *attribute, const char *class,
4006 enum resource_types type)
4008 Lisp_Object value;
4010 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4011 attribute, class, type);
4012 if (! NILP (value) && ! EQ (value, Qunbound))
4013 store_frame_param (f, param, value);
4015 return value;
4019 /* Record in frame F the specified or default value according to ALIST
4020 of the parameter named PROP (a Lisp symbol).
4021 If no value is specified for PROP, look for an X default for XPROP
4022 on the frame named NAME.
4023 If that is not found either, use the value DEFLT. */
4025 Lisp_Object
4026 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4027 Lisp_Object deflt, const char *xprop, const char *xclass,
4028 enum resource_types type)
4030 Lisp_Object tem;
4032 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4033 if (EQ (tem, Qunbound))
4034 tem = deflt;
4035 x_set_frame_parameters (f, list1 (Fcons (prop, tem)));
4036 return tem;
4040 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4043 * XParseGeometry parses strings of the form
4044 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4045 * width, height, xoffset, and yoffset are unsigned integers.
4046 * Example: "=80x24+300-49"
4047 * The equal sign is optional.
4048 * It returns a bitmask that indicates which of the four values
4049 * were actually found in the string. For each value found,
4050 * the corresponding argument is updated; for each value
4051 * not found, the corresponding argument is left unchanged.
4054 static int
4055 XParseGeometry (char *string,
4056 int *x, int *y,
4057 unsigned int *width, unsigned int *height)
4059 int mask = NoValue;
4060 char *strind;
4061 unsigned long tempWidth, tempHeight;
4062 long int tempX, tempY;
4063 char *nextCharacter;
4065 if (string == NULL || *string == '\0')
4066 return mask;
4067 if (*string == '=')
4068 string++; /* ignore possible '=' at beg of geometry spec */
4070 strind = string;
4071 if (*strind != '+' && *strind != '-' && *strind != 'x')
4073 tempWidth = strtoul (strind, &nextCharacter, 10);
4074 if (strind == nextCharacter)
4075 return 0;
4076 strind = nextCharacter;
4077 mask |= WidthValue;
4080 if (*strind == 'x' || *strind == 'X')
4082 strind++;
4083 tempHeight = strtoul (strind, &nextCharacter, 10);
4084 if (strind == nextCharacter)
4085 return 0;
4086 strind = nextCharacter;
4087 mask |= HeightValue;
4090 if (*strind == '+' || *strind == '-')
4092 if (*strind == '-')
4093 mask |= XNegative;
4094 tempX = strtol (strind, &nextCharacter, 10);
4095 if (strind == nextCharacter)
4096 return 0;
4097 strind = nextCharacter;
4098 mask |= XValue;
4099 if (*strind == '+' || *strind == '-')
4101 if (*strind == '-')
4102 mask |= YNegative;
4103 tempY = strtol (strind, &nextCharacter, 10);
4104 if (strind == nextCharacter)
4105 return 0;
4106 strind = nextCharacter;
4107 mask |= YValue;
4111 /* If strind isn't at the end of the string then it's an invalid
4112 geometry specification. */
4114 if (*strind != '\0')
4115 return 0;
4117 if (mask & XValue)
4118 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4119 if (mask & YValue)
4120 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4121 if (mask & WidthValue)
4122 *width = min (tempWidth, UINT_MAX);
4123 if (mask & HeightValue)
4124 *height = min (tempHeight, UINT_MAX);
4125 return mask;
4128 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4131 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4132 make-docfile: the documentation string in ns-win.el was used for
4133 x-parse-geometry even in non-NS builds.
4135 With two definitions of x-parse-geometry in this file, various
4136 things still get confused (eg M-x apropos documentation), so that
4137 it is best if the two definitions just share the same doc-string.
4139 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4140 doc: /* Parse a display geometry string STRING.
4141 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4142 The properties returned may include `top', `left', `height', and `width'.
4143 For X, the value of `left' or `top' may be an integer,
4144 or a list (+ N) meaning N pixels relative to top/left corner,
4145 or a list (- N) meaning -N pixels relative to bottom/right corner.
4146 On Nextstep, this just calls `ns-parse-geometry'. */)
4147 (Lisp_Object string)
4149 int geometry, x, y;
4150 unsigned int width, height;
4151 Lisp_Object result;
4153 CHECK_STRING (string);
4155 #ifdef HAVE_NS
4156 if (strchr (SSDATA (string), ' ') != NULL)
4157 return call1 (Qns_parse_geometry, string);
4158 #endif
4159 geometry = XParseGeometry (SSDATA (string),
4160 &x, &y, &width, &height);
4161 result = Qnil;
4162 if (geometry & XValue)
4164 Lisp_Object element;
4166 if (x >= 0 && (geometry & XNegative))
4167 element = list3 (Qleft, Qminus, make_number (-x));
4168 else if (x < 0 && ! (geometry & XNegative))
4169 element = list3 (Qleft, Qplus, make_number (x));
4170 else
4171 element = Fcons (Qleft, make_number (x));
4172 result = Fcons (element, result);
4175 if (geometry & YValue)
4177 Lisp_Object element;
4179 if (y >= 0 && (geometry & YNegative))
4180 element = list3 (Qtop, Qminus, make_number (-y));
4181 else if (y < 0 && ! (geometry & YNegative))
4182 element = list3 (Qtop, Qplus, make_number (y));
4183 else
4184 element = Fcons (Qtop, make_number (y));
4185 result = Fcons (element, result);
4188 if (geometry & WidthValue)
4189 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4190 if (geometry & HeightValue)
4191 result = Fcons (Fcons (Qheight, make_number (height)), result);
4193 return result;
4197 /* Calculate the desired size and position of frame F.
4198 Return the flags saying which aspects were specified.
4200 Also set the win_gravity and size_hint_flags of F.
4202 Adjust height for toolbar if TOOLBAR_P is 1.
4204 This function does not make the coordinates positive. */
4206 #define DEFAULT_ROWS 35
4207 #define DEFAULT_COLS 80
4209 long
4210 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p)
4212 register Lisp_Object tem0, tem1, tem2;
4213 long window_prompting = 0;
4214 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4216 /* Default values if we fall through.
4217 Actually, if that happens we should get
4218 window manager prompting. */
4219 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4220 SET_FRAME_COLS (f, DEFAULT_COLS);
4221 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4222 FRAME_LINES (f) = DEFAULT_ROWS;
4224 /* Window managers expect that if program-specified
4225 positions are not (0,0), they're intentional, not defaults. */
4226 f->top_pos = 0;
4227 f->left_pos = 0;
4229 /* Ensure that old new_width and new_height will not override the
4230 values set here. */
4231 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4232 f->new_width = f->new_height = f->new_pixelwise = 0;
4234 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4235 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4236 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4237 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4239 if (!EQ (tem0, Qunbound))
4241 CHECK_NUMBER (tem0);
4242 if (! (0 <= XINT (tem0) && XINT (tem0) <= INT_MAX))
4243 xsignal1 (Qargs_out_of_range, tem0);
4244 FRAME_LINES (f) = XINT (tem0);
4246 if (!EQ (tem1, Qunbound))
4248 CHECK_NUMBER (tem1);
4249 if (! (0 <= XINT (tem1) && XINT (tem1) <= INT_MAX))
4250 xsignal1 (Qargs_out_of_range, tem1);
4251 SET_FRAME_COLS (f, XINT (tem1));
4253 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4254 window_prompting |= USSize;
4255 else
4256 window_prompting |= PSize;
4260 /* This used to be done _before_ calling x_figure_window_size, but
4261 since the height is reset here, this was really a no-op. I
4262 assume that moving it here does what Gerd intended (although he
4263 no longer can remember what that was... ++KFS, 2003-03-25. */
4265 /* Add the tool-bar height to the initial frame height so that the
4266 user gets a text display area of the size he specified with -g or
4267 via .Xdefaults. Later changes of the tool-bar height don't
4268 change the frame size. This is done so that users can create
4269 tall Emacs frames without having to guess how tall the tool-bar
4270 will get. */
4271 if (toolbar_p && FRAME_TOOL_BAR_HEIGHT (f))
4273 int margin, relief, bar_height;
4275 relief = (tool_bar_button_relief >= 0
4276 ? tool_bar_button_relief
4277 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4279 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4280 margin = XFASTINT (Vtool_bar_button_margin);
4281 else if (CONSP (Vtool_bar_button_margin)
4282 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4283 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4284 else
4285 margin = 0;
4287 /* PXW: We should be able to not round here. */
4288 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4289 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4292 compute_fringe_widths (f, 0);
4294 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
4295 SET_FRAME_HEIGHT(f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
4297 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4298 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4299 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4300 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4302 if (EQ (tem0, Qminus))
4304 f->top_pos = 0;
4305 window_prompting |= YNegative;
4307 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4308 && CONSP (XCDR (tem0))
4309 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem0)), INT_MAX))
4311 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4312 window_prompting |= YNegative;
4314 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4315 && CONSP (XCDR (tem0))
4316 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0))))
4318 f->top_pos = XINT (XCAR (XCDR (tem0)));
4320 else if (EQ (tem0, Qunbound))
4321 f->top_pos = 0;
4322 else
4324 CHECK_TYPE_RANGED_INTEGER (int, tem0);
4325 f->top_pos = XINT (tem0);
4326 if (f->top_pos < 0)
4327 window_prompting |= YNegative;
4330 if (EQ (tem1, Qminus))
4332 f->left_pos = 0;
4333 window_prompting |= XNegative;
4335 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4336 && CONSP (XCDR (tem1))
4337 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem1)), INT_MAX))
4339 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4340 window_prompting |= XNegative;
4342 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4343 && CONSP (XCDR (tem1))
4344 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1))))
4346 f->left_pos = XINT (XCAR (XCDR (tem1)));
4348 else if (EQ (tem1, Qunbound))
4349 f->left_pos = 0;
4350 else
4352 CHECK_TYPE_RANGED_INTEGER (int, tem1);
4353 f->left_pos = XINT (tem1);
4354 if (f->left_pos < 0)
4355 window_prompting |= XNegative;
4358 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4359 window_prompting |= USPosition;
4360 else
4361 window_prompting |= PPosition;
4364 if (window_prompting & XNegative)
4366 if (window_prompting & YNegative)
4367 f->win_gravity = SouthEastGravity;
4368 else
4369 f->win_gravity = NorthEastGravity;
4371 else
4373 if (window_prompting & YNegative)
4374 f->win_gravity = SouthWestGravity;
4375 else
4376 f->win_gravity = NorthWestGravity;
4379 f->size_hint_flags = window_prompting;
4381 return window_prompting;
4386 #endif /* HAVE_WINDOW_SYSTEM */
4388 void
4389 frame_make_pointer_invisible (void)
4391 if (! NILP (Vmake_pointer_invisible))
4393 struct frame *f;
4394 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4395 return;
4397 f = SELECTED_FRAME ();
4398 if (f && !f->pointer_invisible
4399 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4401 f->mouse_moved = 0;
4402 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4403 f->pointer_invisible = 1;
4408 void
4409 frame_make_pointer_visible (void)
4411 /* We don't check Vmake_pointer_invisible here in case the
4412 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4413 struct frame *f;
4415 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4416 return;
4418 f = SELECTED_FRAME ();
4419 if (f && f->pointer_invisible && f->mouse_moved
4420 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4422 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4423 f->pointer_invisible = 0;
4427 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4428 Sframe_pointer_visible_p, 0, 1, 0,
4429 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4430 Otherwise it returns nil. FRAME omitted or nil means the
4431 selected frame. This is useful when `make-pointer-invisible' is set. */)
4432 (Lisp_Object frame)
4434 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4439 /***********************************************************************
4440 Multimonitor data
4441 ***********************************************************************/
4443 #ifdef HAVE_WINDOW_SYSTEM
4445 # if (defined HAVE_NS \
4446 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4447 void
4448 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4450 int i;
4451 for (i = 0; i < n_monitors; ++i)
4452 xfree (monitors[i].name);
4453 xfree (monitors);
4455 # endif
4457 Lisp_Object
4458 make_monitor_attribute_list (struct MonitorInfo *monitors,
4459 int n_monitors,
4460 int primary_monitor,
4461 Lisp_Object monitor_frames,
4462 const char *source)
4464 Lisp_Object attributes_list = Qnil;
4465 Lisp_Object primary_monitor_attributes = Qnil;
4466 int i;
4468 for (i = 0; i < n_monitors; ++i)
4470 Lisp_Object geometry, workarea, attributes = Qnil;
4471 struct MonitorInfo *mi = &monitors[i];
4473 if (mi->geom.width == 0) continue;
4475 workarea = list4i (mi->work.x, mi->work.y,
4476 mi->work.width, mi->work.height);
4477 geometry = list4i (mi->geom.x, mi->geom.y,
4478 mi->geom.width, mi->geom.height);
4479 attributes = Fcons (Fcons (Qsource, build_string (source)),
4480 attributes);
4481 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4482 attributes);
4483 attributes = Fcons (Fcons (Qmm_size,
4484 list2i (mi->mm_width, mi->mm_height)),
4485 attributes);
4486 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4487 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4488 if (mi->name)
4489 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4490 strlen (mi->name))),
4491 attributes);
4493 if (i == primary_monitor)
4494 primary_monitor_attributes = attributes;
4495 else
4496 attributes_list = Fcons (attributes, attributes_list);
4499 if (!NILP (primary_monitor_attributes))
4500 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4501 return attributes_list;
4504 #endif /* HAVE_WINDOW_SYSTEM */
4507 /***********************************************************************
4508 Initialization
4509 ***********************************************************************/
4511 void
4512 syms_of_frame (void)
4514 DEFSYM (Qframep, "framep");
4515 DEFSYM (Qframe_live_p, "frame-live-p");
4516 DEFSYM (Qexplicit_name, "explicit-name");
4517 DEFSYM (Qheight, "height");
4518 DEFSYM (Qicon, "icon");
4519 DEFSYM (Qminibuffer, "minibuffer");
4520 DEFSYM (Qmodeline, "modeline");
4521 DEFSYM (Qonly, "only");
4522 DEFSYM (Qnone, "none");
4523 DEFSYM (Qwidth, "width");
4524 DEFSYM (Qgeometry, "geometry");
4525 DEFSYM (Qicon_left, "icon-left");
4526 DEFSYM (Qicon_top, "icon-top");
4527 DEFSYM (Qtooltip, "tooltip");
4528 DEFSYM (Qleft, "left");
4529 DEFSYM (Qright, "right");
4530 DEFSYM (Quser_position, "user-position");
4531 DEFSYM (Quser_size, "user-size");
4532 DEFSYM (Qwindow_id, "window-id");
4533 #ifdef HAVE_X_WINDOWS
4534 DEFSYM (Qouter_window_id, "outer-window-id");
4535 #endif
4536 DEFSYM (Qparent_id, "parent-id");
4537 DEFSYM (Qx, "x");
4538 DEFSYM (Qw32, "w32");
4539 DEFSYM (Qpc, "pc");
4540 DEFSYM (Qns, "ns");
4541 DEFSYM (Qvisible, "visible");
4542 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4543 DEFSYM (Qbuffer_list, "buffer-list");
4544 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4545 DEFSYM (Qdisplay_type, "display-type");
4546 DEFSYM (Qbackground_mode, "background-mode");
4547 DEFSYM (Qnoelisp, "noelisp");
4548 DEFSYM (Qtty_color_mode, "tty-color-mode");
4549 DEFSYM (Qtty, "tty");
4550 DEFSYM (Qtty_type, "tty-type");
4552 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4554 DEFSYM (Qfullwidth, "fullwidth");
4555 DEFSYM (Qfullheight, "fullheight");
4556 DEFSYM (Qfullboth, "fullboth");
4557 DEFSYM (Qmaximized, "maximized");
4558 DEFSYM (Qx_resource_name, "x-resource-name");
4559 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4561 DEFSYM (Qterminal, "terminal");
4563 DEFSYM (Qgeometry, "geometry");
4564 DEFSYM (Qworkarea, "workarea");
4565 DEFSYM (Qmm_size, "mm-size");
4566 DEFSYM (Qframes, "frames");
4567 DEFSYM (Qsource, "source");
4569 #ifdef HAVE_NS
4570 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4571 #endif
4574 int i;
4576 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4578 Lisp_Object v = intern_c_string (frame_parms[i].name);
4579 if (frame_parms[i].variable)
4581 *frame_parms[i].variable = v;
4582 staticpro (frame_parms[i].variable);
4584 Fput (v, Qx_frame_parameter, make_number (i));
4588 #ifdef HAVE_WINDOW_SYSTEM
4589 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4590 doc: /* The name Emacs uses to look up X resources.
4591 `x-get-resource' uses this as the first component of the instance name
4592 when requesting resource values.
4593 Emacs initially sets `x-resource-name' to the name under which Emacs
4594 was invoked, or to the value specified with the `-name' or `-rn'
4595 switches, if present.
4597 It may be useful to bind this variable locally around a call
4598 to `x-get-resource'. See also the variable `x-resource-class'. */);
4599 Vx_resource_name = Qnil;
4601 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4602 doc: /* The class Emacs uses to look up X resources.
4603 `x-get-resource' uses this as the first component of the instance class
4604 when requesting resource values.
4606 Emacs initially sets `x-resource-class' to "Emacs".
4608 Setting this variable permanently is not a reasonable thing to do,
4609 but binding this variable locally around a call to `x-get-resource'
4610 is a reasonable practice. See also the variable `x-resource-name'. */);
4611 Vx_resource_class = build_string (EMACS_CLASS);
4613 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4614 doc: /* The lower limit of the frame opacity (alpha transparency).
4615 The value should range from 0 (invisible) to 100 (completely opaque).
4616 You can also use a floating number between 0.0 and 1.0. */);
4617 Vframe_alpha_lower_limit = make_number (20);
4618 #endif
4620 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4621 doc: /* Alist of default values for frame creation.
4622 These may be set in your init file, like this:
4623 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4624 These override values given in window system configuration data,
4625 including X Windows' defaults database.
4626 For values specific to the first Emacs frame, see `initial-frame-alist'.
4627 For window-system specific values, see `window-system-default-frame-alist'.
4628 For values specific to the separate minibuffer frame, see
4629 `minibuffer-frame-alist'.
4630 The `menu-bar-lines' element of the list controls whether new frames
4631 have menu bars; `menu-bar-mode' works by altering this element.
4632 Setting this variable does not affect existing frames, only new ones. */);
4633 Vdefault_frame_alist = Qnil;
4635 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4636 doc: /* Default position of scroll bars on this window-system. */);
4637 #ifdef HAVE_WINDOW_SYSTEM
4638 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4639 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4640 default. */
4641 Vdefault_frame_scroll_bars = Qright;
4642 #else
4643 Vdefault_frame_scroll_bars = Qleft;
4644 #endif
4645 #else
4646 Vdefault_frame_scroll_bars = Qnil;
4647 #endif
4649 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
4650 scroll_bar_adjust_thumb_portion_p,
4651 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
4652 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
4653 even if the end of the buffer is shown (i.e. overscrolling).
4654 Set to nil if you want the thumb to be at the bottom when the end of the buffer
4655 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
4656 is visible. In this case you can not overscroll. */);
4657 scroll_bar_adjust_thumb_portion_p = 1;
4659 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4660 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4662 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4663 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4664 `mouse-position' calls this function, passing its usual return value as
4665 argument, and returns whatever this function returns.
4666 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4667 which need to do mouse handling at the Lisp level. */);
4668 Vmouse_position_function = Qnil;
4670 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4671 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4672 If the value is an integer, highlighting is only shown after moving the
4673 mouse, while keyboard input turns off the highlight even when the mouse
4674 is over the clickable text. However, the mouse shape still indicates
4675 when the mouse is over clickable text. */);
4676 Vmouse_highlight = Qt;
4678 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4679 doc: /* If non-nil, make pointer invisible while typing.
4680 The pointer becomes visible again when the mouse is moved. */);
4681 Vmake_pointer_invisible = Qt;
4683 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
4684 doc: /* Normal hook run when a frame gains input focus. */);
4685 Vfocus_in_hook = Qnil;
4686 DEFSYM (Qfocus_in_hook, "focus-in-hook");
4688 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
4689 doc: /* Normal hook run when a frame loses input focus. */);
4690 Vfocus_out_hook = Qnil;
4691 DEFSYM (Qfocus_out_hook, "focus-out-hook");
4693 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4694 doc: /* Functions run before deleting a frame.
4695 The functions are run with one arg, the frame to be deleted.
4696 See `delete-frame'.
4698 Note that functions in this list may be called just before the frame is
4699 actually deleted, or some time later (or even both when an earlier function
4700 in `delete-frame-functions' (indirectly) calls `delete-frame'
4701 recursively). */);
4702 Vdelete_frame_functions = Qnil;
4703 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4705 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4706 doc: /* Non-nil if Menu-Bar mode is enabled.
4707 See the command `menu-bar-mode' for a description of this minor mode.
4708 Setting this variable directly does not take effect;
4709 either customize it (see the info node `Easy Customization')
4710 or call the function `menu-bar-mode'. */);
4711 Vmenu_bar_mode = Qt;
4713 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4714 doc: /* Non-nil if Tool-Bar mode is enabled.
4715 See the command `tool-bar-mode' for a description of this minor mode.
4716 Setting this variable directly does not take effect;
4717 either customize it (see the info node `Easy Customization')
4718 or call the function `tool-bar-mode'. */);
4719 #ifdef HAVE_WINDOW_SYSTEM
4720 Vtool_bar_mode = Qt;
4721 #else
4722 Vtool_bar_mode = Qnil;
4723 #endif
4725 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4726 doc: /* Minibufferless frames use this frame's minibuffer.
4727 Emacs cannot create minibufferless frames unless this is set to an
4728 appropriate surrogate.
4730 Emacs consults this variable only when creating minibufferless
4731 frames; once the frame is created, it sticks with its assigned
4732 minibuffer, no matter what this variable is set to. This means that
4733 this variable doesn't necessarily say anything meaningful about the
4734 current set of frames, or where the minibuffer is currently being
4735 displayed.
4737 This variable is local to the current terminal and cannot be buffer-local. */);
4739 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4740 doc: /* Non-nil if window system changes focus when you move the mouse.
4741 You should set this variable to tell Emacs how your window manager
4742 handles focus, since there is no way in general for Emacs to find out
4743 automatically. See also `mouse-autoselect-window'. */);
4744 focus_follows_mouse = 0;
4746 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
4747 doc: /* Non-nil means resize frames pixelwise.
4748 If this option is nil, resizing a frame rounds its sizes to the frame's
4749 current values of `frame-char-height' and `frame-char-width'. If this
4750 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
4751 by one pixel.
4753 With some window managers you have to set this to non-nil in order to
4754 fully maximize frames. To resize your initial frame pixelwise,
4755 set this option to a non-nil value in your init file. */);
4756 frame_resize_pixelwise = 0;
4758 staticpro (&Vframe_list);
4760 defsubr (&Sframep);
4761 defsubr (&Sframe_live_p);
4762 defsubr (&Swindow_system);
4763 defsubr (&Smake_terminal_frame);
4764 defsubr (&Shandle_switch_frame);
4765 defsubr (&Sselect_frame);
4766 defsubr (&Sselected_frame);
4767 defsubr (&Sframe_list);
4768 defsubr (&Snext_frame);
4769 defsubr (&Sprevious_frame);
4770 defsubr (&Slast_nonminibuf_frame);
4771 defsubr (&Sdelete_frame);
4772 defsubr (&Smouse_position);
4773 defsubr (&Smouse_pixel_position);
4774 defsubr (&Sset_mouse_position);
4775 defsubr (&Sset_mouse_pixel_position);
4776 #if 0
4777 defsubr (&Sframe_configuration);
4778 defsubr (&Srestore_frame_configuration);
4779 #endif
4780 defsubr (&Smake_frame_visible);
4781 defsubr (&Smake_frame_invisible);
4782 defsubr (&Siconify_frame);
4783 defsubr (&Sframe_visible_p);
4784 defsubr (&Svisible_frame_list);
4785 defsubr (&Sraise_frame);
4786 defsubr (&Slower_frame);
4787 defsubr (&Sx_focus_frame);
4788 defsubr (&Sredirect_frame_focus);
4789 defsubr (&Sframe_focus);
4790 defsubr (&Sframe_parameters);
4791 defsubr (&Sframe_parameter);
4792 defsubr (&Smodify_frame_parameters);
4793 defsubr (&Sframe_char_height);
4794 defsubr (&Sframe_char_width);
4795 defsubr (&Sframe_pixel_height);
4796 defsubr (&Sframe_pixel_width);
4797 defsubr (&Sframe_text_cols);
4798 defsubr (&Sframe_text_lines);
4799 defsubr (&Sframe_total_cols);
4800 defsubr (&Sframe_text_width);
4801 defsubr (&Sframe_text_height);
4802 defsubr (&Sscroll_bar_width);
4803 defsubr (&Sfringe_width);
4804 defsubr (&Sborder_width);
4805 defsubr (&Sright_divider_width);
4806 defsubr (&Sbottom_divider_width);
4807 defsubr (&Stool_bar_pixel_width);
4808 defsubr (&Sset_frame_height);
4809 defsubr (&Sset_frame_width);
4810 defsubr (&Sset_frame_size);
4811 defsubr (&Sset_frame_position);
4812 defsubr (&Sframe_pointer_visible_p);
4814 #ifdef HAVE_WINDOW_SYSTEM
4815 defsubr (&Sx_get_resource);
4816 defsubr (&Sx_parse_geometry);
4817 #endif