* lisp/frame.el: Fix doc typo in previous
[emacs.git] / src / frame.c
blob35fd190ba2847cfe68278619be2cb0283bc64580
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 canonical character cells, where (0, 0) is the
1528 upper-left corner of the frame, X is the horizontal offset, and Y is the
1529 vertical offset, measured in units of the frame's default character size.
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 canonical character cells, where (0, 0) is
1613 the upper-left corner of the frame, X is the horizontal offset, and
1614 Y is the vertical offset, measured in units of the frame's default
1615 character size.
1617 This function is a no-op for an X frame that is not visible.
1618 If you have just created a frame, you must wait for it to become visible
1619 before calling this function on it, like this.
1620 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1621 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1623 CHECK_LIVE_FRAME (frame);
1624 CHECK_TYPE_RANGED_INTEGER (int, x);
1625 CHECK_TYPE_RANGED_INTEGER (int, y);
1627 /* I think this should be done with a hook. */
1628 #ifdef HAVE_WINDOW_SYSTEM
1629 if (FRAME_WINDOW_P (XFRAME (frame)))
1630 /* Warping the mouse will cause enternotify and focus events. */
1631 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1632 #else
1633 #if defined (MSDOS)
1634 if (FRAME_MSDOS_P (XFRAME (frame)))
1636 Fselect_frame (frame, Qnil);
1637 mouse_moveto (XINT (x), XINT (y));
1639 #else
1640 #ifdef HAVE_GPM
1642 Fselect_frame (frame, Qnil);
1643 term_mouse_moveto (XINT (x), XINT (y));
1645 #endif
1646 #endif
1647 #endif
1649 return Qnil;
1652 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1653 Sset_mouse_pixel_position, 3, 3, 0,
1654 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1655 The position is given in pixels, where (0, 0) is the upper-left corner
1656 of the frame, X is the horizontal offset, and Y is the vertical offset.
1658 Note, this is a no-op for an X frame that is not visible.
1659 If you have just created a frame, you must wait for it to become visible
1660 before calling this function on it, like this.
1661 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1662 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1664 CHECK_LIVE_FRAME (frame);
1665 CHECK_TYPE_RANGED_INTEGER (int, x);
1666 CHECK_TYPE_RANGED_INTEGER (int, y);
1668 /* I think this should be done with a hook. */
1669 #ifdef HAVE_WINDOW_SYSTEM
1670 if (FRAME_WINDOW_P (XFRAME (frame)))
1671 /* Warping the mouse will cause enternotify and focus events. */
1672 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1673 #else
1674 #if defined (MSDOS)
1675 if (FRAME_MSDOS_P (XFRAME (frame)))
1677 Fselect_frame (frame, Qnil);
1678 mouse_moveto (XINT (x), XINT (y));
1680 #else
1681 #ifdef HAVE_GPM
1683 Fselect_frame (frame, Qnil);
1684 term_mouse_moveto (XINT (x), XINT (y));
1686 #endif
1687 #endif
1688 #endif
1690 return Qnil;
1693 static void make_frame_visible_1 (Lisp_Object);
1695 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1696 0, 1, "",
1697 doc: /* Make the frame FRAME visible (assuming it is an X window).
1698 If omitted, FRAME defaults to the currently selected frame. */)
1699 (Lisp_Object frame)
1701 struct frame *f = decode_live_frame (frame);
1703 /* I think this should be done with a hook. */
1704 #ifdef HAVE_WINDOW_SYSTEM
1705 if (FRAME_WINDOW_P (f))
1706 x_make_frame_visible (f);
1707 #endif
1709 make_frame_visible_1 (f->root_window);
1711 /* Make menu bar update for the Buffers and Frames menus. */
1712 /* windows_or_buffers_changed = 15; FIXME: Why? */
1714 XSETFRAME (frame, f);
1715 return frame;
1718 /* Update the display_time slot of the buffers shown in WINDOW
1719 and all its descendants. */
1721 static void
1722 make_frame_visible_1 (Lisp_Object window)
1724 struct window *w;
1726 for (; !NILP (window); window = w->next)
1728 w = XWINDOW (window);
1729 if (WINDOWP (w->contents))
1730 make_frame_visible_1 (w->contents);
1731 else
1732 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
1736 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1737 0, 2, "",
1738 doc: /* Make the frame FRAME invisible.
1739 If omitted, FRAME defaults to the currently selected frame.
1740 On graphical displays, invisible frames are not updated and are
1741 usually not displayed at all, even in a window system's \"taskbar\".
1743 Normally you may not make FRAME invisible if all other frames are invisible,
1744 but if the second optional argument FORCE is non-nil, you may do so.
1746 This function has no effect on text terminal frames. Such frames are
1747 always considered visible, whether or not they are currently being
1748 displayed in the terminal. */)
1749 (Lisp_Object frame, Lisp_Object force)
1751 struct frame *f = decode_live_frame (frame);
1753 if (NILP (force) && !other_visible_frames (f))
1754 error ("Attempt to make invisible the sole visible or iconified frame");
1756 /* Don't allow minibuf_window to remain on an invisible frame. */
1757 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
1759 /* I think this should be done with a hook. */
1760 #ifdef HAVE_WINDOW_SYSTEM
1761 if (FRAME_WINDOW_P (f))
1762 x_make_frame_invisible (f);
1763 #endif
1765 /* Make menu bar update for the Buffers and Frames menus. */
1766 windows_or_buffers_changed = 16;
1768 return Qnil;
1771 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1772 0, 1, "",
1773 doc: /* Make the frame FRAME into an icon.
1774 If omitted, FRAME defaults to the currently selected frame. */)
1775 (Lisp_Object frame)
1777 struct frame *f = decode_live_frame (frame);
1779 /* Don't allow minibuf_window to remain on an iconified frame. */
1780 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
1782 /* I think this should be done with a hook. */
1783 #ifdef HAVE_WINDOW_SYSTEM
1784 if (FRAME_WINDOW_P (f))
1785 x_iconify_frame (f);
1786 #endif
1788 /* Make menu bar update for the Buffers and Frames menus. */
1789 windows_or_buffers_changed = 17;
1791 return Qnil;
1794 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1795 1, 1, 0,
1796 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1797 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1798 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1799 On graphical displays, invisible frames are not updated and are
1800 usually not displayed at all, even in a window system's \"taskbar\".
1802 If FRAME is a text terminal frame, this always returns t.
1803 Such frames are always considered visible, whether or not they are
1804 currently being displayed on the terminal. */)
1805 (Lisp_Object frame)
1807 CHECK_LIVE_FRAME (frame);
1809 if (FRAME_VISIBLE_P (XFRAME (frame)))
1810 return Qt;
1811 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1812 return Qicon;
1813 return Qnil;
1816 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1817 0, 0, 0,
1818 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1819 (void)
1821 Lisp_Object tail, frame, value = Qnil;
1823 FOR_EACH_FRAME (tail, frame)
1824 if (FRAME_VISIBLE_P (XFRAME (frame)))
1825 value = Fcons (frame, value);
1827 return value;
1831 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1832 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1833 If FRAME is invisible or iconified, make it visible.
1834 If you don't specify a frame, the selected frame is used.
1835 If Emacs is displaying on an ordinary terminal or some other device which
1836 doesn't support multiple overlapping frames, this function selects FRAME. */)
1837 (Lisp_Object frame)
1839 struct frame *f = decode_live_frame (frame);
1841 XSETFRAME (frame, f);
1843 if (FRAME_TERMCAP_P (f))
1844 /* On a text terminal select FRAME. */
1845 Fselect_frame (frame, Qnil);
1846 else
1847 /* Do like the documentation says. */
1848 Fmake_frame_visible (frame);
1850 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1851 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
1853 return Qnil;
1856 /* Should we have a corresponding function called Flower_Power? */
1857 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1858 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1859 If you don't specify a frame, the selected frame is used.
1860 If Emacs is displaying on an ordinary terminal or some other device which
1861 doesn't support multiple overlapping frames, this function does nothing. */)
1862 (Lisp_Object frame)
1864 struct frame *f = decode_live_frame (frame);
1866 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1867 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
1869 return Qnil;
1873 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1874 1, 2, 0,
1875 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1876 In other words, switch-frame events caused by events in FRAME will
1877 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1878 FOCUS-FRAME after reading an event typed at FRAME.
1880 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
1881 frame again receives its own keystrokes.
1883 Focus redirection is useful for temporarily redirecting keystrokes to
1884 a surrogate minibuffer frame when a frame doesn't have its own
1885 minibuffer window.
1887 A frame's focus redirection can be changed by `select-frame'. If frame
1888 FOO is selected, and then a different frame BAR is selected, any
1889 frames redirecting their focus to FOO are shifted to redirect their
1890 focus to BAR. This allows focus redirection to work properly when the
1891 user switches from one frame to another using `select-window'.
1893 This means that a frame whose focus is redirected to itself is treated
1894 differently from a frame whose focus is redirected to nil; the former
1895 is affected by `select-frame', while the latter is not.
1897 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1898 (Lisp_Object frame, Lisp_Object focus_frame)
1900 /* Note that we don't check for a live frame here. It's reasonable
1901 to redirect the focus of a frame you're about to delete, if you
1902 know what other frame should receive those keystrokes. */
1903 struct frame *f = decode_any_frame (frame);
1905 if (! NILP (focus_frame))
1906 CHECK_LIVE_FRAME (focus_frame);
1908 fset_focus_frame (f, focus_frame);
1910 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
1911 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
1913 return Qnil;
1917 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
1918 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1919 If FRAME is omitted or nil, the selected frame is used.
1920 Return nil if FRAME's focus is not redirected.
1921 See `redirect-frame-focus'. */)
1922 (Lisp_Object frame)
1924 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
1927 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
1928 doc: /* Set the input focus to FRAME.
1929 FRAME nil means use the selected frame.
1930 If there is no window system support, this function does nothing. */)
1931 (Lisp_Object frame)
1933 #ifdef HAVE_WINDOW_SYSTEM
1934 x_focus_frame (decode_window_system_frame (frame));
1935 #endif
1936 return Qnil;
1940 /* Return the value of frame parameter PROP in frame FRAME. */
1942 #ifdef HAVE_WINDOW_SYSTEM
1943 #if !HAVE_NS && !HAVE_NTGUI
1944 static
1945 #endif
1946 Lisp_Object
1947 get_frame_param (register struct frame *frame, Lisp_Object prop)
1949 register Lisp_Object tem;
1951 tem = Fassq (prop, frame->param_alist);
1952 if (EQ (tem, Qnil))
1953 return tem;
1954 return Fcdr (tem);
1956 #endif
1958 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
1960 void
1961 frames_discard_buffer (Lisp_Object buffer)
1963 Lisp_Object frame, tail;
1965 FOR_EACH_FRAME (tail, frame)
1967 fset_buffer_list
1968 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
1969 fset_buried_buffer_list
1970 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
1974 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1975 If the alist already has an element for PROP, we change it. */
1977 void
1978 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
1980 register Lisp_Object tem;
1982 tem = Fassq (prop, *alistptr);
1983 if (EQ (tem, Qnil))
1984 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1985 else
1986 Fsetcdr (tem, val);
1989 static int
1990 frame_name_fnn_p (char *str, ptrdiff_t len)
1992 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
1994 char *p = str + 2;
1995 while ('0' <= *p && *p <= '9')
1996 p++;
1997 if (p == str + len)
1998 return 1;
2000 return 0;
2003 /* Set the name of the terminal frame. Also used by MSDOS frames.
2004 Modeled after x_set_name which is used for WINDOW frames. */
2006 static void
2007 set_term_frame_name (struct frame *f, Lisp_Object name)
2009 f->explicit_name = ! NILP (name);
2011 /* If NAME is nil, set the name to F<num>. */
2012 if (NILP (name))
2014 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2016 /* Check for no change needed in this very common case
2017 before we do any consing. */
2018 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2019 return;
2021 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2023 else
2025 CHECK_STRING (name);
2027 /* Don't change the name if it's already NAME. */
2028 if (! NILP (Fstring_equal (name, f->name)))
2029 return;
2031 /* Don't allow the user to set the frame name to F<num>, so it
2032 doesn't clash with the names we generate for terminal frames. */
2033 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2034 error ("Frame names of the form F<num> are usurped by Emacs");
2037 fset_name (f, name);
2038 update_mode_lines = 16;
2041 #ifdef HAVE_NTGUI
2042 void
2043 set_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2045 register Lisp_Object old_alist_elt;
2047 old_alist_elt = Fassq (prop, f->param_alist);
2048 if (EQ (old_alist_elt, Qnil))
2049 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2050 else
2051 Fsetcdr (old_alist_elt, val);
2053 #endif
2055 void
2056 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2058 register Lisp_Object old_alist_elt;
2060 /* The buffer-list parameters are stored in a special place and not
2061 in the alist. All buffers must be live. */
2062 if (EQ (prop, Qbuffer_list))
2064 Lisp_Object list = Qnil;
2065 for (; CONSP (val); val = XCDR (val))
2066 if (!NILP (Fbuffer_live_p (XCAR (val))))
2067 list = Fcons (XCAR (val), list);
2068 fset_buffer_list (f, Fnreverse (list));
2069 return;
2071 if (EQ (prop, Qburied_buffer_list))
2073 Lisp_Object list = Qnil;
2074 for (; CONSP (val); val = XCDR (val))
2075 if (!NILP (Fbuffer_live_p (XCAR (val))))
2076 list = Fcons (XCAR (val), list);
2077 fset_buried_buffer_list (f, Fnreverse (list));
2078 return;
2081 /* If PROP is a symbol which is supposed to have frame-local values,
2082 and it is set up based on this frame, switch to the global
2083 binding. That way, we can create or alter the frame-local binding
2084 without messing up the symbol's status. */
2085 if (SYMBOLP (prop))
2087 struct Lisp_Symbol *sym = XSYMBOL (prop);
2088 start:
2089 switch (sym->redirect)
2091 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2092 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2093 case SYMBOL_LOCALIZED:
2094 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2095 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2096 swap_in_global_binding (sym);
2097 break;
2099 default: emacs_abort ();
2103 /* The tty color needed to be set before the frame's parameter
2104 alist was updated with the new value. This is not true any more,
2105 but we still do this test early on. */
2106 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2107 && f == FRAME_TTY (f)->previous_frame)
2108 /* Force redisplay of this tty. */
2109 FRAME_TTY (f)->previous_frame = NULL;
2111 /* Update the frame parameter alist. */
2112 old_alist_elt = Fassq (prop, f->param_alist);
2113 if (EQ (old_alist_elt, Qnil))
2114 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2115 else
2116 Fsetcdr (old_alist_elt, val);
2118 /* Update some other special parameters in their special places
2119 in addition to the alist. */
2121 if (EQ (prop, Qbuffer_predicate))
2122 fset_buffer_predicate (f, val);
2124 if (! FRAME_WINDOW_P (f))
2126 if (EQ (prop, Qmenu_bar_lines))
2127 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2128 else if (EQ (prop, Qname))
2129 set_term_frame_name (f, val);
2132 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2134 if (! MINI_WINDOW_P (XWINDOW (val)))
2135 error ("Surrogate minibuffer windows must be minibuffer windows");
2137 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2138 && !EQ (val, f->minibuffer_window))
2139 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2141 /* Install the chosen minibuffer window, with proper buffer. */
2142 fset_minibuffer_window (f, val);
2146 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2147 doc: /* Return the parameters-alist of frame FRAME.
2148 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2149 The meaningful PARMs depend on the kind of frame.
2150 If FRAME is omitted or nil, return information on the currently selected frame. */)
2151 (Lisp_Object frame)
2153 Lisp_Object alist;
2154 struct frame *f = decode_any_frame (frame);
2155 int height, width;
2156 struct gcpro gcpro1;
2158 if (!FRAME_LIVE_P (f))
2159 return Qnil;
2161 alist = Fcopy_alist (f->param_alist);
2162 GCPRO1 (alist);
2164 if (!FRAME_WINDOW_P (f))
2166 int fg = FRAME_FOREGROUND_PIXEL (f);
2167 int bg = FRAME_BACKGROUND_PIXEL (f);
2168 Lisp_Object elt;
2170 /* If the frame's parameter alist says the colors are
2171 unspecified and reversed, take the frame's background pixel
2172 for foreground and vice versa. */
2173 elt = Fassq (Qforeground_color, alist);
2174 if (CONSP (elt) && STRINGP (XCDR (elt)))
2176 if (strncmp (SSDATA (XCDR (elt)),
2177 unspecified_bg,
2178 SCHARS (XCDR (elt))) == 0)
2179 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2180 else if (strncmp (SSDATA (XCDR (elt)),
2181 unspecified_fg,
2182 SCHARS (XCDR (elt))) == 0)
2183 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2185 else
2186 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2187 elt = Fassq (Qbackground_color, alist);
2188 if (CONSP (elt) && STRINGP (XCDR (elt)))
2190 if (strncmp (SSDATA (XCDR (elt)),
2191 unspecified_fg,
2192 SCHARS (XCDR (elt))) == 0)
2193 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2194 else if (strncmp (SSDATA (XCDR (elt)),
2195 unspecified_bg,
2196 SCHARS (XCDR (elt))) == 0)
2197 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2199 else
2200 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2201 store_in_alist (&alist, intern ("font"),
2202 build_string (FRAME_MSDOS_P (f)
2203 ? "ms-dos"
2204 : FRAME_W32_P (f) ? "w32term"
2205 :"tty"));
2207 store_in_alist (&alist, Qname, f->name);
2208 height = (f->new_height
2209 ? (f->new_pixelwise
2210 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2211 : f->new_height)
2212 : FRAME_LINES (f));
2213 store_in_alist (&alist, Qheight, make_number (height));
2214 width = (f->new_width
2215 ? (f->new_pixelwise
2216 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2217 : f->new_width)
2218 : FRAME_COLS (f));
2219 store_in_alist (&alist, Qwidth, make_number (width));
2220 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2221 store_in_alist (&alist, Qminibuffer,
2222 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2223 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2224 : FRAME_MINIBUF_WINDOW (f)));
2225 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2226 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2227 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2229 /* I think this should be done with a hook. */
2230 #ifdef HAVE_WINDOW_SYSTEM
2231 if (FRAME_WINDOW_P (f))
2232 x_report_frame_params (f, &alist);
2233 else
2234 #endif
2236 /* This ought to be correct in f->param_alist for an X frame. */
2237 Lisp_Object lines;
2238 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2239 store_in_alist (&alist, Qmenu_bar_lines, lines);
2242 UNGCPRO;
2243 return alist;
2247 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2248 doc: /* Return FRAME's value for parameter PARAMETER.
2249 If FRAME is nil, describe the currently selected frame. */)
2250 (Lisp_Object frame, Lisp_Object parameter)
2252 struct frame *f = decode_any_frame (frame);
2253 Lisp_Object value = Qnil;
2255 CHECK_SYMBOL (parameter);
2257 XSETFRAME (frame, f);
2259 if (FRAME_LIVE_P (f))
2261 /* Avoid consing in frequent cases. */
2262 if (EQ (parameter, Qname))
2263 value = f->name;
2264 #ifdef HAVE_X_WINDOWS
2265 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2266 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2267 #endif /* HAVE_X_WINDOWS */
2268 else if (EQ (parameter, Qbackground_color)
2269 || EQ (parameter, Qforeground_color))
2271 value = Fassq (parameter, f->param_alist);
2272 if (CONSP (value))
2274 value = XCDR (value);
2275 /* Fframe_parameters puts the actual fg/bg color names,
2276 even if f->param_alist says otherwise. This is
2277 important when param_alist's notion of colors is
2278 "unspecified". We need to do the same here. */
2279 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2281 const char *color_name;
2282 ptrdiff_t csz;
2284 if (EQ (parameter, Qbackground_color))
2286 color_name = SSDATA (value);
2287 csz = SCHARS (value);
2288 if (strncmp (color_name, unspecified_bg, csz) == 0)
2289 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2290 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2291 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2293 else if (EQ (parameter, Qforeground_color))
2295 color_name = SSDATA (value);
2296 csz = SCHARS (value);
2297 if (strncmp (color_name, unspecified_fg, csz) == 0)
2298 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2299 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2300 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2304 else
2305 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2307 else if (EQ (parameter, Qdisplay_type)
2308 || EQ (parameter, Qbackground_mode))
2309 value = Fcdr (Fassq (parameter, f->param_alist));
2310 else
2311 /* FIXME: Avoid this code path at all (as well as code duplication)
2312 by sharing more code with Fframe_parameters. */
2313 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2316 return value;
2320 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2321 Smodify_frame_parameters, 2, 2, 0,
2322 doc: /* Modify the parameters of frame FRAME according to ALIST.
2323 If FRAME is nil, it defaults to the selected frame.
2324 ALIST is an alist of parameters to change and their new values.
2325 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2326 The meaningful PARMs depend on the kind of frame.
2327 Undefined PARMs are ignored, but stored in the frame's parameter list
2328 so that `frame-parameters' will return them.
2330 The value of frame parameter FOO can also be accessed
2331 as a frame-local binding for the variable FOO, if you have
2332 enabled such bindings for that variable with `make-variable-frame-local'.
2333 Note that this functionality is obsolete as of Emacs 22.2, and its
2334 use is not recommended. Explicitly check for a frame-parameter instead. */)
2335 (Lisp_Object frame, Lisp_Object alist)
2337 struct frame *f = decode_live_frame (frame);
2338 register Lisp_Object prop, val;
2340 CHECK_LIST (alist);
2342 /* I think this should be done with a hook. */
2343 #ifdef HAVE_WINDOW_SYSTEM
2344 if (FRAME_WINDOW_P (f))
2345 x_set_frame_parameters (f, alist);
2346 else
2347 #endif
2348 #ifdef MSDOS
2349 if (FRAME_MSDOS_P (f))
2350 IT_set_frame_parameters (f, alist);
2351 else
2352 #endif
2355 EMACS_INT length = XFASTINT (Flength (alist));
2356 ptrdiff_t i;
2357 Lisp_Object *parms;
2358 Lisp_Object *values;
2359 USE_SAFE_ALLOCA;
2360 SAFE_ALLOCA_LISP (parms, 2 * length);
2361 values = parms + length;
2363 /* Extract parm names and values into those vectors. */
2365 for (i = 0; CONSP (alist); alist = XCDR (alist))
2367 Lisp_Object elt;
2369 elt = XCAR (alist);
2370 parms[i] = Fcar (elt);
2371 values[i] = Fcdr (elt);
2372 i++;
2375 /* Now process them in reverse of specified order. */
2376 while (--i >= 0)
2378 prop = parms[i];
2379 val = values[i];
2380 store_frame_param (f, prop, val);
2382 if (EQ (prop, Qforeground_color)
2383 || EQ (prop, Qbackground_color))
2384 update_face_from_frame_parameter (f, prop, val);
2387 SAFE_FREE ();
2389 return Qnil;
2392 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2393 0, 1, 0,
2394 doc: /* Height in pixels of a line in the font in frame FRAME.
2395 If FRAME is omitted or nil, the selected frame is used.
2396 For a terminal frame, the value is always 1. */)
2397 (Lisp_Object frame)
2399 #ifdef HAVE_WINDOW_SYSTEM
2400 struct frame *f = decode_any_frame (frame);
2402 if (FRAME_WINDOW_P (f))
2403 return make_number (FRAME_LINE_HEIGHT (f));
2404 else
2405 #endif
2406 return make_number (1);
2410 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2411 0, 1, 0,
2412 doc: /* Width in pixels of characters in the font in frame FRAME.
2413 If FRAME is omitted or nil, the selected frame is used.
2414 On a graphical screen, the width is the standard width of the default font.
2415 For a terminal screen, the value is always 1. */)
2416 (Lisp_Object frame)
2418 #ifdef HAVE_WINDOW_SYSTEM
2419 struct frame *f = decode_any_frame (frame);
2421 if (FRAME_WINDOW_P (f))
2422 return make_number (FRAME_COLUMN_WIDTH (f));
2423 else
2424 #endif
2425 return make_number (1);
2428 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2429 Sframe_pixel_height, 0, 1, 0,
2430 doc: /* Return a FRAME's height in pixels.
2431 If FRAME is omitted or nil, the selected frame is used. The exact value
2432 of the result depends on the window-system and toolkit in use:
2434 In the Gtk+ version of Emacs, it includes only any window (including
2435 the minibuffer or echo area), mode line, and header line. It does not
2436 include the tool bar or menu bar.
2438 With other graphical versions, it also includes the tool bar and the
2439 menu bar.
2441 For a text terminal, it includes the menu bar. In this case, the
2442 result is really in characters rather than pixels (i.e., is identical
2443 to `frame-height'). */)
2444 (Lisp_Object frame)
2446 struct frame *f = decode_any_frame (frame);
2448 #ifdef HAVE_WINDOW_SYSTEM
2449 if (FRAME_WINDOW_P (f))
2450 return make_number (FRAME_PIXEL_HEIGHT (f));
2451 else
2452 #endif
2453 return make_number (FRAME_LINES (f));
2456 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2457 Sframe_pixel_width, 0, 1, 0,
2458 doc: /* Return FRAME's width in pixels.
2459 For a terminal frame, the result really gives the width in characters.
2460 If FRAME is omitted or nil, the selected frame is used. */)
2461 (Lisp_Object frame)
2463 struct frame *f = decode_any_frame (frame);
2465 #ifdef HAVE_WINDOW_SYSTEM
2466 if (FRAME_WINDOW_P (f))
2467 return make_number (FRAME_PIXEL_WIDTH (f));
2468 else
2469 #endif
2470 return make_number (FRAME_COLS (f));
2473 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2474 Stool_bar_pixel_width, 0, 1, 0,
2475 doc: /* Return width in pixels of FRAME's tool bar.
2476 The result is greater than zero only when the tool bar is on the left
2477 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2478 is used. */)
2479 (Lisp_Object frame)
2481 #ifdef FRAME_TOOLBAR_WIDTH
2482 struct frame *f = decode_any_frame (frame);
2484 if (FRAME_WINDOW_P (f))
2485 return make_number (FRAME_TOOLBAR_WIDTH (f));
2486 #endif
2487 return make_number (0);
2490 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2491 doc: /* Return width in columns of FRAME's text area. */)
2492 (Lisp_Object frame)
2494 return make_number (FRAME_COLS (decode_any_frame (frame)));
2497 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2498 doc: /* Return height in lines of FRAME's text area. */)
2499 (Lisp_Object frame)
2501 return make_number (FRAME_LINES (decode_any_frame (frame)));
2504 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2505 doc: /* Return total columns of FRAME. */)
2506 (Lisp_Object frame)
2508 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2511 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2512 doc: /* Return text area width of FRAME in pixels. */)
2513 (Lisp_Object frame)
2515 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2518 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2519 doc: /* Return text area height of FRAME in pixels. */)
2520 (Lisp_Object frame)
2522 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2525 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2526 doc: /* Return scroll bar width of FRAME in pixels. */)
2527 (Lisp_Object frame)
2529 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2532 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2533 doc: /* Return fringe width of FRAME in pixels. */)
2534 (Lisp_Object frame)
2536 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2539 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2540 doc: /* Return border width of FRAME in pixels. */)
2541 (Lisp_Object frame)
2543 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2546 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2547 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2548 (Lisp_Object frame)
2550 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2553 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2554 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2555 (Lisp_Object frame)
2557 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2560 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2561 doc: /* Specify that the frame FRAME has HEIGHT text lines.
2562 Optional third arg PRETEND non-nil means that redisplay should use
2563 HEIGHT lines but that the idea of the actual height of the frame should
2564 not be changed. Optional fourth argument PIXELWISE non-nil means that
2565 FRAME should be HEIGHT pixels high. */)
2566 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2568 register struct frame *f = decode_live_frame (frame);
2570 CHECK_TYPE_RANGED_INTEGER (int, height);
2572 /* I think this should be done with a hook. */
2573 #ifdef HAVE_WINDOW_SYSTEM
2574 if (FRAME_WINDOW_P (f))
2576 if (NILP (pixelwise))
2578 if (XINT (height) != FRAME_LINES (f))
2579 x_set_window_size (f, 1, FRAME_COLS (f), XINT (height), 0);
2581 do_pending_window_change (0);
2583 else if (XINT (height) != FRAME_TEXT_HEIGHT (f))
2585 x_set_window_size (f, 1, FRAME_TEXT_WIDTH (f), XINT (height), 1);
2586 do_pending_window_change (0);
2589 else
2590 #endif
2591 change_frame_size (f, 0, XINT (height), !NILP (pretend), 0, 0,
2592 NILP (pixelwise) ? 0 : 1);
2593 return Qnil;
2596 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2597 doc: /* Specify that the frame FRAME has WIDTH columns.
2598 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2599 columns but that the idea of the actual width of the frame should not
2600 be changed. Optional fourth argument PIXELWISE non-nil means that FRAME
2601 should be WIDTH pixels wide. */)
2602 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2604 register struct frame *f = decode_live_frame (frame);
2606 CHECK_TYPE_RANGED_INTEGER (int, width);
2608 /* I think this should be done with a hook. */
2609 #ifdef HAVE_WINDOW_SYSTEM
2610 if (FRAME_WINDOW_P (f))
2612 if (NILP (pixelwise))
2614 if (XINT (width) != FRAME_COLS (f))
2615 x_set_window_size (f, 1, XINT (width), FRAME_LINES (f), 0);
2617 do_pending_window_change (0);
2619 else if (XINT (width) != FRAME_TEXT_WIDTH (f))
2621 x_set_window_size (f, 1, XINT (width), FRAME_TEXT_HEIGHT (f), 1);
2622 do_pending_window_change (0);
2625 else
2626 #endif
2627 change_frame_size (f, XINT (width), 0, !NILP (pretend), 0, 0,
2628 NILP (pixelwise) ? 0 : 1);
2629 return Qnil;
2632 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2633 doc: /* Sets size of FRAME to WIDTH by HEIGHT, measured in characters.
2634 Optional argument PIXELWISE non-nil means to measure in pixels. */)
2635 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2637 register struct frame *f = decode_live_frame (frame);
2639 CHECK_TYPE_RANGED_INTEGER (int, width);
2640 CHECK_TYPE_RANGED_INTEGER (int, height);
2642 /* I think this should be done with a hook. */
2643 #ifdef HAVE_WINDOW_SYSTEM
2644 if (FRAME_WINDOW_P (f))
2646 if (!NILP (pixelwise)
2647 ? (XINT (width) != FRAME_TEXT_WIDTH (f)
2648 || XINT (height) != FRAME_TEXT_HEIGHT (f)
2649 || f->new_height || f->new_width)
2650 : (XINT (width) != FRAME_COLS (f)
2651 || XINT (height) != FRAME_LINES (f)
2652 || f->new_height || f->new_width))
2654 x_set_window_size (f, 1, XINT (width), XINT (height),
2655 NILP (pixelwise) ? 0 : 1);
2656 do_pending_window_change (0);
2659 else
2660 #endif
2661 change_frame_size (f, XINT (width), XINT (height), 0, 0, 0,
2662 NILP (pixelwise) ? 0 : 1);
2664 return Qnil;
2667 DEFUN ("set-frame-position", Fset_frame_position,
2668 Sset_frame_position, 3, 3, 0,
2669 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2670 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2671 actually the position of the upper left corner of the frame. Negative
2672 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2673 or bottommost possible position (that stays within the screen). */)
2674 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2676 register struct frame *f = decode_live_frame (frame);
2678 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2679 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2681 /* I think this should be done with a hook. */
2682 #ifdef HAVE_WINDOW_SYSTEM
2683 if (FRAME_WINDOW_P (f))
2684 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2685 #endif
2687 return Qt;
2691 /***********************************************************************
2692 Frame Parameters
2693 ***********************************************************************/
2695 /* Connect the frame-parameter names for X frames
2696 to the ways of passing the parameter values to the window system.
2698 The name of a parameter, as a Lisp symbol,
2699 has an `x-frame-parameter' property which is an integer in Lisp
2700 that is an index in this table. */
2702 struct frame_parm_table {
2703 const char *name;
2704 Lisp_Object *variable;
2707 static const struct frame_parm_table frame_parms[] =
2709 {"auto-raise", &Qauto_raise},
2710 {"auto-lower", &Qauto_lower},
2711 {"background-color", 0},
2712 {"border-color", &Qborder_color},
2713 {"border-width", &Qborder_width},
2714 {"cursor-color", &Qcursor_color},
2715 {"cursor-type", &Qcursor_type},
2716 {"font", 0},
2717 {"foreground-color", 0},
2718 {"icon-name", &Qicon_name},
2719 {"icon-type", &Qicon_type},
2720 {"internal-border-width", &Qinternal_border_width},
2721 {"right-divider-width", &Qright_divider_width},
2722 {"bottom-divider-width", &Qbottom_divider_width},
2723 {"menu-bar-lines", &Qmenu_bar_lines},
2724 {"mouse-color", &Qmouse_color},
2725 {"name", &Qname},
2726 {"scroll-bar-width", &Qscroll_bar_width},
2727 {"title", &Qtitle},
2728 {"unsplittable", &Qunsplittable},
2729 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2730 {"visibility", &Qvisibility},
2731 {"tool-bar-lines", &Qtool_bar_lines},
2732 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2733 {"scroll-bar-background", &Qscroll_bar_background},
2734 {"screen-gamma", &Qscreen_gamma},
2735 {"line-spacing", &Qline_spacing},
2736 {"left-fringe", &Qleft_fringe},
2737 {"right-fringe", &Qright_fringe},
2738 {"wait-for-wm", &Qwait_for_wm},
2739 {"fullscreen", &Qfullscreen},
2740 {"font-backend", &Qfont_backend},
2741 {"alpha", &Qalpha},
2742 {"sticky", &Qsticky},
2743 {"tool-bar-position", &Qtool_bar_position},
2746 #ifdef HAVE_NTGUI
2748 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2749 wanted positions of the WM window (not Emacs window).
2750 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2751 window (FRAME_X_WINDOW).
2754 void
2755 x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
2757 int newwidth = FRAME_COLS (f);
2758 int newheight = FRAME_LINES (f);
2759 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
2761 *top_pos = f->top_pos;
2762 *left_pos = f->left_pos;
2764 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2766 int ph;
2768 ph = x_display_pixel_height (dpyinfo);
2769 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2770 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2771 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2772 *top_pos = 0;
2775 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2777 int pw;
2779 pw = x_display_pixel_width (dpyinfo);
2780 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2781 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2782 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2783 *left_pos = 0;
2786 *width = newwidth;
2787 *height = newheight;
2790 #endif /* HAVE_NTGUI */
2792 #ifdef HAVE_WINDOW_SYSTEM
2794 /* Change the parameters of frame F as specified by ALIST.
2795 If a parameter is not specially recognized, do nothing special;
2796 otherwise call the `x_set_...' function for that parameter.
2797 Except for certain geometry properties, always call store_frame_param
2798 to store the new value in the parameter alist. */
2800 void
2801 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
2803 Lisp_Object tail;
2805 /* If both of these parameters are present, it's more efficient to
2806 set them both at once. So we wait until we've looked at the
2807 entire list before we set them. */
2808 int width = 0, height = 0;
2809 bool width_change = 0, height_change = 0;
2811 /* Same here. */
2812 Lisp_Object left, top;
2814 /* Same with these. */
2815 Lisp_Object icon_left, icon_top;
2817 /* Record in these vectors all the parms specified. */
2818 Lisp_Object *parms;
2819 Lisp_Object *values;
2820 ptrdiff_t i, p;
2821 bool left_no_change = 0, top_no_change = 0;
2822 #ifdef HAVE_X_WINDOWS
2823 bool icon_left_no_change = 0, icon_top_no_change = 0;
2824 #endif
2825 struct gcpro gcpro1, gcpro2;
2827 i = 0;
2828 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2829 i++;
2831 parms = alloca (i * sizeof *parms);
2832 values = alloca (i * sizeof *values);
2834 /* Extract parm names and values into those vectors. */
2836 i = 0;
2837 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2839 Lisp_Object elt;
2841 elt = XCAR (tail);
2842 parms[i] = Fcar (elt);
2843 values[i] = Fcdr (elt);
2844 i++;
2846 /* TAIL and ALIST are not used again below here. */
2847 alist = tail = Qnil;
2849 GCPRO2 (*parms, *values);
2850 gcpro1.nvars = i;
2851 gcpro2.nvars = i;
2853 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2854 because their values appear in VALUES and strings are not valid. */
2855 top = left = Qunbound;
2856 icon_left = icon_top = Qunbound;
2858 /* Process foreground_color and background_color before anything else.
2859 They are independent of other properties, but other properties (e.g.,
2860 cursor_color) are dependent upon them. */
2861 /* Process default font as well, since fringe widths depends on it. */
2862 for (p = 0; p < i; p++)
2864 Lisp_Object prop, val;
2866 prop = parms[p];
2867 val = values[p];
2868 if (EQ (prop, Qforeground_color)
2869 || EQ (prop, Qbackground_color)
2870 || EQ (prop, Qfont))
2872 register Lisp_Object param_index, old_value;
2874 old_value = get_frame_param (f, prop);
2875 if (NILP (Fequal (val, old_value)))
2877 store_frame_param (f, prop, val);
2879 param_index = Fget (prop, Qx_frame_parameter);
2880 if (NATNUMP (param_index)
2881 && (XFASTINT (param_index)
2882 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2883 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2884 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2889 /* Now process them in reverse of specified order. */
2890 while (i-- != 0)
2892 Lisp_Object prop, val;
2894 prop = parms[i];
2895 val = values[i];
2897 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
2899 width_change = 1;
2900 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
2902 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
2904 height_change = 1;
2905 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
2907 else if (EQ (prop, Qtop))
2908 top = val;
2909 else if (EQ (prop, Qleft))
2910 left = val;
2911 else if (EQ (prop, Qicon_top))
2912 icon_top = val;
2913 else if (EQ (prop, Qicon_left))
2914 icon_left = val;
2915 else if (EQ (prop, Qforeground_color)
2916 || EQ (prop, Qbackground_color)
2917 || EQ (prop, Qfont))
2918 /* Processed above. */
2919 continue;
2920 else
2922 register Lisp_Object param_index, old_value;
2924 old_value = get_frame_param (f, prop);
2926 store_frame_param (f, prop, val);
2928 param_index = Fget (prop, Qx_frame_parameter);
2929 if (NATNUMP (param_index)
2930 && (XFASTINT (param_index)
2931 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2932 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2933 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2937 /* Don't die if just one of these was set. */
2938 if (EQ (left, Qunbound))
2940 left_no_change = 1;
2941 if (f->left_pos < 0)
2942 left = list2 (Qplus, make_number (f->left_pos));
2943 else
2944 XSETINT (left, f->left_pos);
2946 if (EQ (top, Qunbound))
2948 top_no_change = 1;
2949 if (f->top_pos < 0)
2950 top = list2 (Qplus, make_number (f->top_pos));
2951 else
2952 XSETINT (top, f->top_pos);
2955 /* If one of the icon positions was not set, preserve or default it. */
2956 if (! TYPE_RANGED_INTEGERP (int, icon_left))
2958 #ifdef HAVE_X_WINDOWS
2959 icon_left_no_change = 1;
2960 #endif
2961 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2962 if (NILP (icon_left))
2963 XSETINT (icon_left, 0);
2965 if (! TYPE_RANGED_INTEGERP (int, icon_top))
2967 #ifdef HAVE_X_WINDOWS
2968 icon_top_no_change = 1;
2969 #endif
2970 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2971 if (NILP (icon_top))
2972 XSETINT (icon_top, 0);
2975 /* Don't set these parameters unless they've been explicitly
2976 specified. The window might be mapped or resized while we're in
2977 this function, and we don't want to override that unless the lisp
2978 code has asked for it.
2980 Don't set these parameters unless they actually differ from the
2981 window's current parameters; the window may not actually exist
2982 yet. */
2984 Lisp_Object frame;
2986 /* Make this 1, eventually. */
2987 check_frame_size (f, &width, &height, 1);
2989 XSETFRAME (frame, f);
2991 if ((width_change || height_change)
2992 && (width != FRAME_TEXT_WIDTH (f)
2993 || height != FRAME_TEXT_HEIGHT (f)
2994 || f->new_height || f->new_width))
2996 /* If necessary provide default values for HEIGHT and WIDTH. Do
2997 that here since otherwise a size change implied by an
2998 intermittent font change may get lost as in Bug#17142. */
2999 if (!width_change)
3000 width = (f->new_width
3001 ? (f->new_pixelwise
3002 ? f->new_width
3003 : (f->new_width * FRAME_COLUMN_WIDTH (f)))
3004 : FRAME_TEXT_WIDTH (f));
3006 if (!height_change)
3007 height = (f->new_height
3008 ? (f->new_pixelwise
3009 ? f->new_height
3010 : (f->new_height * FRAME_LINE_HEIGHT (f)))
3011 : FRAME_TEXT_HEIGHT (f));
3013 Fset_frame_size (frame, make_number (width), make_number (height), Qt);
3016 if ((!NILP (left) || !NILP (top))
3017 && ! (left_no_change && top_no_change)
3018 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3019 && NUMBERP (top) && XINT (top) == f->top_pos))
3021 int leftpos = 0;
3022 int toppos = 0;
3024 /* Record the signs. */
3025 f->size_hint_flags &= ~ (XNegative | YNegative);
3026 if (EQ (left, Qminus))
3027 f->size_hint_flags |= XNegative;
3028 else if (TYPE_RANGED_INTEGERP (int, left))
3030 leftpos = XINT (left);
3031 if (leftpos < 0)
3032 f->size_hint_flags |= XNegative;
3034 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3035 && CONSP (XCDR (left))
3036 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3038 leftpos = - XINT (XCAR (XCDR (left)));
3039 f->size_hint_flags |= XNegative;
3041 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3042 && CONSP (XCDR (left))
3043 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3045 leftpos = XINT (XCAR (XCDR (left)));
3048 if (EQ (top, Qminus))
3049 f->size_hint_flags |= YNegative;
3050 else if (TYPE_RANGED_INTEGERP (int, top))
3052 toppos = XINT (top);
3053 if (toppos < 0)
3054 f->size_hint_flags |= YNegative;
3056 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3057 && CONSP (XCDR (top))
3058 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3060 toppos = - XINT (XCAR (XCDR (top)));
3061 f->size_hint_flags |= YNegative;
3063 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3064 && CONSP (XCDR (top))
3065 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3067 toppos = XINT (XCAR (XCDR (top)));
3071 /* Store the numeric value of the position. */
3072 f->top_pos = toppos;
3073 f->left_pos = leftpos;
3075 f->win_gravity = NorthWestGravity;
3077 /* Actually set that position, and convert to absolute. */
3078 x_set_offset (f, leftpos, toppos, -1);
3080 #ifdef HAVE_X_WINDOWS
3081 if ((!NILP (icon_left) || !NILP (icon_top))
3082 && ! (icon_left_no_change && icon_top_no_change))
3083 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3084 #endif /* HAVE_X_WINDOWS */
3087 UNGCPRO;
3091 /* Insert a description of internally-recorded parameters of frame X
3092 into the parameter alist *ALISTPTR that is to be given to the user.
3093 Only parameters that are specific to the X window system
3094 and whose values are not correctly recorded in the frame's
3095 param_alist need to be considered here. */
3097 void
3098 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3100 Lisp_Object tem;
3101 uprintmax_t w;
3102 char buf[INT_BUFSIZE_BOUND (w)];
3104 /* Represent negative positions (off the top or left screen edge)
3105 in a way that Fmodify_frame_parameters will understand correctly. */
3106 XSETINT (tem, f->left_pos);
3107 if (f->left_pos >= 0)
3108 store_in_alist (alistptr, Qleft, tem);
3109 else
3110 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3112 XSETINT (tem, f->top_pos);
3113 if (f->top_pos >= 0)
3114 store_in_alist (alistptr, Qtop, tem);
3115 else
3116 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3118 store_in_alist (alistptr, Qborder_width,
3119 make_number (f->border_width));
3120 store_in_alist (alistptr, Qinternal_border_width,
3121 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3122 store_in_alist (alistptr, Qright_divider_width,
3123 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3124 store_in_alist (alistptr, Qbottom_divider_width,
3125 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3126 store_in_alist (alistptr, Qleft_fringe,
3127 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3128 store_in_alist (alistptr, Qright_fringe,
3129 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3130 store_in_alist (alistptr, Qscroll_bar_width,
3131 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3132 ? make_number (0)
3133 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3134 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3135 /* nil means "use default width"
3136 for non-toolkit scroll bar.
3137 ruler-mode.el depends on this. */
3138 : Qnil));
3139 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3140 MS-Windows it returns a value whose type is HANDLE, which is
3141 actually a pointer. Explicit casting avoids compiler
3142 warnings. */
3143 w = (uintptr_t) FRAME_X_WINDOW (f);
3144 store_in_alist (alistptr, Qwindow_id,
3145 make_formatted_string (buf, "%"pMu, w));
3146 #ifdef HAVE_X_WINDOWS
3147 #ifdef USE_X_TOOLKIT
3148 /* Tooltip frame may not have this widget. */
3149 if (FRAME_X_OUTPUT (f)->widget)
3150 #endif
3151 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3152 store_in_alist (alistptr, Qouter_window_id,
3153 make_formatted_string (buf, "%"pMu, w));
3154 #endif
3155 store_in_alist (alistptr, Qicon_name, f->icon_name);
3156 store_in_alist (alistptr, Qvisibility,
3157 (FRAME_VISIBLE_P (f) ? Qt
3158 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3159 store_in_alist (alistptr, Qdisplay,
3160 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3162 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3163 tem = Qnil;
3164 else
3165 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3166 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3167 store_in_alist (alistptr, Qparent_id, tem);
3168 store_in_alist (alistptr, Qtool_bar_position, f->tool_bar_position);
3172 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3173 the previous value of that parameter, NEW_VALUE is the new value. */
3175 void
3176 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3178 if (NILP (new_value))
3179 f->want_fullscreen = FULLSCREEN_NONE;
3180 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3181 f->want_fullscreen = FULLSCREEN_BOTH;
3182 else if (EQ (new_value, Qfullwidth))
3183 f->want_fullscreen = FULLSCREEN_WIDTH;
3184 else if (EQ (new_value, Qfullheight))
3185 f->want_fullscreen = FULLSCREEN_HEIGHT;
3186 else if (EQ (new_value, Qmaximized))
3187 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3189 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3190 FRAME_TERMINAL (f)->fullscreen_hook (f);
3194 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3195 the previous value of that parameter, NEW_VALUE is the new value. */
3197 void
3198 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3200 if (NILP (new_value))
3201 f->extra_line_spacing = 0;
3202 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3203 f->extra_line_spacing = XFASTINT (new_value);
3204 else if (FLOATP (new_value))
3206 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3208 if (new_spacing >= 0)
3209 f->extra_line_spacing = new_spacing;
3210 else
3211 signal_error ("Invalid line-spacing", new_value);
3213 else
3214 signal_error ("Invalid line-spacing", new_value);
3215 if (FRAME_VISIBLE_P (f))
3216 redraw_frame (f);
3220 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3221 the previous value of that parameter, NEW_VALUE is the new value. */
3223 void
3224 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3226 Lisp_Object bgcolor;
3228 if (NILP (new_value))
3229 f->gamma = 0;
3230 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3231 /* The value 0.4545 is the normal viewing gamma. */
3232 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3233 else
3234 signal_error ("Invalid screen-gamma", new_value);
3236 /* Apply the new gamma value to the frame background. */
3237 bgcolor = Fassq (Qbackground_color, f->param_alist);
3238 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3240 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3241 if (NATNUMP (parm_index)
3242 && (XFASTINT (parm_index)
3243 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3244 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3245 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3246 (f, bgcolor, Qnil);
3249 Fclear_face_cache (Qnil);
3253 void
3254 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3256 Lisp_Object font_object;
3257 int fontset = -1;
3258 #ifdef HAVE_X_WINDOWS
3259 Lisp_Object font_param = arg;
3260 #endif
3262 /* Set the frame parameter back to the old value because we may
3263 fail to use ARG as the new parameter value. */
3264 store_frame_param (f, Qfont, oldval);
3266 /* ARG is a fontset name, a font name, a cons of fontset name and a
3267 font object, or a font object. In the last case, this function
3268 never fail. */
3269 if (STRINGP (arg))
3271 fontset = fs_query_fontset (arg, 0);
3272 if (fontset < 0)
3274 font_object = font_open_by_name (f, arg);
3275 if (NILP (font_object))
3276 error ("Font `%s' is not defined", SSDATA (arg));
3277 arg = AREF (font_object, FONT_NAME_INDEX);
3279 else if (fontset > 0)
3281 font_object = font_open_by_name (f, fontset_ascii (fontset));
3282 if (NILP (font_object))
3283 error ("Font `%s' is not defined", SDATA (arg));
3284 arg = AREF (font_object, FONT_NAME_INDEX);
3286 else
3287 error ("The default fontset can't be used for a frame font");
3289 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3291 /* This is the case that the ASCII font of F's fontset XCAR
3292 (arg) is changed to the font XCDR (arg) by
3293 `set-fontset-font'. */
3294 fontset = fs_query_fontset (XCAR (arg), 0);
3295 if (fontset < 0)
3296 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3297 font_object = XCDR (arg);
3298 arg = AREF (font_object, FONT_NAME_INDEX);
3299 #ifdef HAVE_X_WINDOWS
3300 font_param = Ffont_get (font_object, QCname);
3301 #endif
3303 else if (FONT_OBJECT_P (arg))
3305 font_object = arg;
3306 #ifdef HAVE_X_WINDOWS
3307 font_param = Ffont_get (font_object, QCname);
3308 #endif
3309 /* This is to store the XLFD font name in the frame parameter for
3310 backward compatibility. We should store the font-object
3311 itself in the future. */
3312 arg = AREF (font_object, FONT_NAME_INDEX);
3313 fontset = FRAME_FONTSET (f);
3314 /* Check if we can use the current fontset. If not, set FONTSET
3315 to -1 to generate a new fontset from FONT-OBJECT. */
3316 if (fontset >= 0)
3318 Lisp_Object ascii_font = fontset_ascii (fontset);
3319 Lisp_Object spec = font_spec_from_name (ascii_font);
3321 if (NILP (spec))
3322 signal_error ("Invalid font name", ascii_font);
3324 if (! font_match_p (spec, font_object))
3325 fontset = -1;
3328 else
3329 signal_error ("Invalid font", arg);
3331 if (! NILP (Fequal (font_object, oldval)))
3332 return;
3334 x_new_font (f, font_object, fontset);
3335 store_frame_param (f, Qfont, arg);
3336 #ifdef HAVE_X_WINDOWS
3337 store_frame_param (f, Qfont_param, font_param);
3338 #endif
3339 /* Recalculate toolbar height. */
3340 f->n_tool_bar_rows = 0;
3342 /* Ensure we redraw it. */
3343 clear_current_matrices (f);
3345 /* Attempt to hunt down bug#16028. */
3346 SET_FRAME_GARBAGED (f);
3348 recompute_basic_faces (f);
3350 do_pending_window_change (0);
3352 /* We used to call face-set-after-frame-default here, but it leads to
3353 recursive calls (since that function can set the `default' face's
3354 font which in turns changes the frame's `font' parameter).
3355 Also I don't know what this call is meant to do, but it seems the
3356 wrong way to do it anyway (it does a lot more work than what seems
3357 reasonable in response to a change to `font'). */
3361 void
3362 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3364 if (! NILP (new_value)
3365 && !CONSP (new_value))
3367 char *p0, *p1;
3369 CHECK_STRING (new_value);
3370 p0 = p1 = SSDATA (new_value);
3371 new_value = Qnil;
3372 while (*p0)
3374 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3375 if (p0 < p1)
3376 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3377 new_value);
3378 if (*p1)
3380 int c;
3382 while ((c = *++p1) && c_isspace (c));
3384 p0 = p1;
3386 new_value = Fnreverse (new_value);
3389 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3390 return;
3392 if (FRAME_FONT (f))
3393 free_all_realized_faces (Qnil);
3395 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3396 if (NILP (new_value))
3398 if (NILP (old_value))
3399 error ("No font backend available");
3400 font_update_drivers (f, old_value);
3401 error ("None of specified font backends are available");
3403 store_frame_param (f, Qfont_backend, new_value);
3405 if (FRAME_FONT (f))
3407 Lisp_Object frame;
3409 XSETFRAME (frame, f);
3410 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3411 ++face_change_count;
3412 windows_or_buffers_changed = 18;
3417 void
3418 x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3420 compute_fringe_widths (f, 1);
3421 #ifdef HAVE_X_WINDOWS
3422 /* Must adjust this so window managers report correct number of columns. */
3423 if (FRAME_X_WINDOW (f) != 0)
3424 x_wm_set_size_hint (f, 0, 0);
3425 #endif
3428 void
3429 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3431 CHECK_TYPE_RANGED_INTEGER (int, arg);
3433 if (XINT (arg) == f->border_width)
3434 return;
3436 if (FRAME_X_WINDOW (f) != 0)
3437 error ("Cannot change the border width of a frame");
3439 f->border_width = XINT (arg);
3442 void
3443 x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3445 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3447 CHECK_TYPE_RANGED_INTEGER (int, arg);
3448 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3449 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3450 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3452 #ifdef USE_X_TOOLKIT
3453 if (FRAME_X_OUTPUT (f)->edit_widget)
3454 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3455 #endif
3457 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3458 return;
3460 if (FRAME_X_WINDOW (f) != 0)
3462 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 1);
3463 SET_FRAME_GARBAGED (f);
3464 do_pending_window_change (0);
3466 else
3467 SET_FRAME_GARBAGED (f);
3470 void
3471 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3473 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3475 CHECK_TYPE_RANGED_INTEGER (int, arg);
3476 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3477 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3478 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3480 if (FRAME_RIGHT_DIVIDER_WIDTH (f) == old)
3481 return;
3483 if (FRAME_X_WINDOW (f) != 0)
3485 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 1);
3486 SET_FRAME_GARBAGED (f);
3487 do_pending_window_change (0);
3489 else
3490 SET_FRAME_GARBAGED (f);
3493 void
3494 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3496 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3498 CHECK_TYPE_RANGED_INTEGER (int, arg);
3499 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3500 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3501 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3503 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) == old)
3504 return;
3506 if (FRAME_X_WINDOW (f) != 0)
3508 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 1);
3509 SET_FRAME_GARBAGED (f);
3510 do_pending_window_change (0);
3512 else
3513 SET_FRAME_GARBAGED (f);
3516 void
3517 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3519 Lisp_Object frame;
3520 XSETFRAME (frame, f);
3522 if (NILP (value))
3523 Fmake_frame_invisible (frame, Qt);
3524 else if (EQ (value, Qicon))
3525 Ficonify_frame (frame);
3526 else
3527 Fmake_frame_visible (frame);
3530 void
3531 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3533 f->auto_raise = !EQ (Qnil, arg);
3536 void
3537 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3539 f->auto_lower = !EQ (Qnil, arg);
3542 void
3543 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3545 f->no_split = !NILP (arg);
3548 void
3549 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3551 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3552 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3553 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3554 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3556 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3557 = (NILP (arg)
3558 ? vertical_scroll_bar_none
3559 : EQ (Qleft, arg)
3560 ? vertical_scroll_bar_left
3561 : EQ (Qright, arg)
3562 ? vertical_scroll_bar_right
3563 : EQ (Qleft, Vdefault_frame_scroll_bars)
3564 ? vertical_scroll_bar_left
3565 : EQ (Qright, Vdefault_frame_scroll_bars)
3566 ? vertical_scroll_bar_right
3567 : vertical_scroll_bar_none);
3569 /* We set this parameter before creating the X window for the
3570 frame, so we can get the geometry right from the start.
3571 However, if the window hasn't been created yet, we shouldn't
3572 call x_set_window_size. */
3573 if (FRAME_X_WINDOW (f))
3574 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f),
3575 FRAME_TEXT_HEIGHT (f), 1);
3576 do_pending_window_change (0);
3580 void
3581 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3583 int unit = FRAME_COLUMN_WIDTH (f);
3585 if (NILP (arg))
3587 x_set_scroll_bar_default_width (f);
3589 if (FRAME_X_WINDOW (f))
3590 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f),
3591 FRAME_TEXT_HEIGHT (f), 1);
3592 do_pending_window_change (0);
3594 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3595 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3597 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3598 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3599 if (FRAME_X_WINDOW (f))
3600 x_set_window_size (f, 0, FRAME_TEXT_WIDTH (f),
3601 FRAME_TEXT_HEIGHT (f), 1);
3602 do_pending_window_change (0);
3605 /* Eventually remove the following call. It should have been done by
3606 x_set_window_size already. */
3607 change_frame_size (f, 0, 0, 0, 0, 0, 1);
3608 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3609 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3612 void
3613 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3615 double alpha = 1.0;
3616 double newval[2];
3617 int i;
3618 Lisp_Object item;
3620 for (i = 0; i < 2; i++)
3622 newval[i] = 1.0;
3623 if (CONSP (arg))
3625 item = CAR (arg);
3626 arg = CDR (arg);
3628 else
3629 item = arg;
3631 if (NILP (item))
3632 alpha = - 1.0;
3633 else if (FLOATP (item))
3635 alpha = XFLOAT_DATA (item);
3636 if (! (0 <= alpha && alpha <= 1.0))
3637 args_out_of_range (make_float (0.0), make_float (1.0));
3639 else if (INTEGERP (item))
3641 EMACS_INT ialpha = XINT (item);
3642 if (! (0 <= ialpha && alpha <= 100))
3643 args_out_of_range (make_number (0), make_number (100));
3644 alpha = ialpha / 100.0;
3646 else
3647 wrong_type_argument (Qnumberp, item);
3648 newval[i] = alpha;
3651 for (i = 0; i < 2; i++)
3652 f->alpha[i] = newval[i];
3654 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3655 block_input ();
3656 x_set_frame_alpha (f);
3657 unblock_input ();
3658 #endif
3660 return;
3663 #ifndef HAVE_NS
3665 /* Non-zero if mouse is grabbed on DPYINFO
3666 and we know the frame where it is. */
3668 bool x_mouse_grabbed (Display_Info *dpyinfo)
3670 return (dpyinfo->grabbed
3671 && dpyinfo->last_mouse_frame
3672 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
3675 /* Re-highlight something with mouse-face properties
3676 on DPYINFO using saved frame and mouse position. */
3678 void
3679 x_redo_mouse_highlight (Display_Info *dpyinfo)
3681 if (dpyinfo->last_mouse_motion_frame
3682 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
3683 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
3684 dpyinfo->last_mouse_motion_x,
3685 dpyinfo->last_mouse_motion_y);
3688 #endif /* HAVE_NS */
3690 /* Subroutines of creating an X frame. */
3692 /* Make sure that Vx_resource_name is set to a reasonable value.
3693 Fix it up, or set it to `emacs' if it is too hopeless. */
3695 void
3696 validate_x_resource_name (void)
3698 ptrdiff_t len = 0;
3699 /* Number of valid characters in the resource name. */
3700 ptrdiff_t good_count = 0;
3701 /* Number of invalid characters in the resource name. */
3702 ptrdiff_t bad_count = 0;
3703 Lisp_Object new;
3704 ptrdiff_t i;
3706 if (!STRINGP (Vx_resource_class))
3707 Vx_resource_class = build_string (EMACS_CLASS);
3709 if (STRINGP (Vx_resource_name))
3711 unsigned char *p = SDATA (Vx_resource_name);
3713 len = SBYTES (Vx_resource_name);
3715 /* Only letters, digits, - and _ are valid in resource names.
3716 Count the valid characters and count the invalid ones. */
3717 for (i = 0; i < len; i++)
3719 int c = p[i];
3720 if (! ((c >= 'a' && c <= 'z')
3721 || (c >= 'A' && c <= 'Z')
3722 || (c >= '0' && c <= '9')
3723 || c == '-' || c == '_'))
3724 bad_count++;
3725 else
3726 good_count++;
3729 else
3730 /* Not a string => completely invalid. */
3731 bad_count = 5, good_count = 0;
3733 /* If name is valid already, return. */
3734 if (bad_count == 0)
3735 return;
3737 /* If name is entirely invalid, or nearly so, or is so implausibly
3738 large that alloca might not work, use `emacs'. */
3739 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3741 Vx_resource_name = build_string ("emacs");
3742 return;
3745 /* Name is partly valid. Copy it and replace the invalid characters
3746 with underscores. */
3748 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3750 for (i = 0; i < len; i++)
3752 int c = SREF (new, i);
3753 if (! ((c >= 'a' && c <= 'z')
3754 || (c >= 'A' && c <= 'Z')
3755 || (c >= '0' && c <= '9')
3756 || c == '-' || c == '_'))
3757 SSET (new, i, '_');
3761 /* Get specified attribute from resource database RDB.
3762 See Fx_get_resource below for other parameters. */
3764 static Lisp_Object
3765 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3767 register char *value;
3768 char *name_key;
3769 char *class_key;
3771 CHECK_STRING (attribute);
3772 CHECK_STRING (class);
3774 if (!NILP (component))
3775 CHECK_STRING (component);
3776 if (!NILP (subclass))
3777 CHECK_STRING (subclass);
3778 if (NILP (component) != NILP (subclass))
3779 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3781 validate_x_resource_name ();
3783 /* Allocate space for the components, the dots which separate them,
3784 and the final '\0'. Make them big enough for the worst case. */
3785 name_key = alloca (SBYTES (Vx_resource_name)
3786 + (STRINGP (component)
3787 ? SBYTES (component) : 0)
3788 + SBYTES (attribute)
3789 + 3);
3791 class_key = alloca (SBYTES (Vx_resource_class)
3792 + SBYTES (class)
3793 + (STRINGP (subclass)
3794 ? SBYTES (subclass) : 0)
3795 + 3);
3797 /* Start with emacs.FRAMENAME for the name (the specific one)
3798 and with `Emacs' for the class key (the general one). */
3799 strcpy (name_key, SSDATA (Vx_resource_name));
3800 strcpy (class_key, SSDATA (Vx_resource_class));
3802 strcat (class_key, ".");
3803 strcat (class_key, SSDATA (class));
3805 if (!NILP (component))
3807 strcat (class_key, ".");
3808 strcat (class_key, SSDATA (subclass));
3810 strcat (name_key, ".");
3811 strcat (name_key, SSDATA (component));
3814 strcat (name_key, ".");
3815 strcat (name_key, SSDATA (attribute));
3817 value = x_get_string_resource (rdb, name_key, class_key);
3819 if (value && *value)
3820 return build_string (value);
3821 else
3822 return Qnil;
3826 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3827 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3828 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3829 class, where INSTANCE is the name under which Emacs was invoked, or
3830 the name specified by the `-name' or `-rn' command-line arguments.
3832 The optional arguments COMPONENT and SUBCLASS add to the key and the
3833 class, respectively. You must specify both of them or neither.
3834 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3835 and the class is `Emacs.CLASS.SUBCLASS'. */)
3836 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
3837 Lisp_Object subclass)
3839 check_window_system (NULL);
3841 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3842 attribute, class, component, subclass);
3845 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3847 Lisp_Object
3848 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
3849 Lisp_Object class, Lisp_Object component,
3850 Lisp_Object subclass)
3852 return xrdb_get_resource (dpyinfo->xrdb,
3853 attribute, class, component, subclass);
3856 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3857 /* Used when C code wants a resource value. */
3858 /* Called from oldXMenu/Create.c. */
3859 char *
3860 x_get_resource_string (const char *attribute, const char *class)
3862 char *result;
3863 struct frame *sf = SELECTED_FRAME ();
3864 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
3865 USE_SAFE_ALLOCA;
3867 /* Allocate space for the components, the dots which separate them,
3868 and the final '\0'. */
3869 char *name_key = SAFE_ALLOCA (invocation_namelen + strlen (attribute) + 2);
3870 char *class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2);
3872 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
3873 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3875 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
3876 name_key, class_key);
3877 SAFE_FREE ();
3878 return result;
3880 #endif
3882 /* Return the value of parameter PARAM.
3884 First search ALIST, then Vdefault_frame_alist, then the X defaults
3885 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3887 Convert the resource to the type specified by desired_type.
3889 If no default is specified, return Qunbound. If you call
3890 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3891 and don't let it get stored in any Lisp-visible variables! */
3893 Lisp_Object
3894 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
3895 const char *attribute, const char *class, enum resource_types type)
3897 register Lisp_Object tem;
3899 tem = Fassq (param, alist);
3901 if (!NILP (tem))
3903 /* If we find this parm in ALIST, clear it out
3904 so that it won't be "left over" at the end. */
3905 Lisp_Object tail;
3906 XSETCAR (tem, Qnil);
3907 /* In case the parameter appears more than once in the alist,
3908 clear it out. */
3909 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3910 if (CONSP (XCAR (tail))
3911 && EQ (XCAR (XCAR (tail)), param))
3912 XSETCAR (XCAR (tail), Qnil);
3914 else
3915 tem = Fassq (param, Vdefault_frame_alist);
3917 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3918 look in the X resources. */
3919 if (EQ (tem, Qnil))
3921 if (attribute && dpyinfo)
3923 tem = display_x_get_resource (dpyinfo,
3924 build_string (attribute),
3925 build_string (class),
3926 Qnil, Qnil);
3928 if (NILP (tem))
3929 return Qunbound;
3931 switch (type)
3933 case RES_TYPE_NUMBER:
3934 return make_number (atoi (SSDATA (tem)));
3936 case RES_TYPE_BOOLEAN_NUMBER:
3937 if (!strcmp (SSDATA (tem), "on")
3938 || !strcmp (SSDATA (tem), "true"))
3939 return make_number (1);
3940 return make_number (atoi (SSDATA (tem)));
3941 break;
3943 case RES_TYPE_FLOAT:
3944 return make_float (atof (SSDATA (tem)));
3946 case RES_TYPE_BOOLEAN:
3947 tem = Fdowncase (tem);
3948 if (!strcmp (SSDATA (tem), "on")
3949 #ifdef HAVE_NS
3950 || !strcmp (SSDATA (tem), "yes")
3951 #endif
3952 || !strcmp (SSDATA (tem), "true"))
3953 return Qt;
3954 else
3955 return Qnil;
3957 case RES_TYPE_STRING:
3958 return tem;
3960 case RES_TYPE_SYMBOL:
3961 /* As a special case, we map the values `true' and `on'
3962 to Qt, and `false' and `off' to Qnil. */
3964 Lisp_Object lower;
3965 lower = Fdowncase (tem);
3966 if (!strcmp (SSDATA (lower), "on")
3967 #ifdef HAVE_NS
3968 || !strcmp (SSDATA (lower), "yes")
3969 #endif
3970 || !strcmp (SSDATA (lower), "true"))
3971 return Qt;
3972 else if (!strcmp (SSDATA (lower), "off")
3973 #ifdef HAVE_NS
3974 || !strcmp (SSDATA (lower), "no")
3975 #endif
3976 || !strcmp (SSDATA (lower), "false"))
3977 return Qnil;
3978 else
3979 return Fintern (tem, Qnil);
3982 default:
3983 emacs_abort ();
3986 else
3987 return Qunbound;
3989 return Fcdr (tem);
3992 static Lisp_Object
3993 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
3994 const char *attribute, const char *class,
3995 enum resource_types type)
3997 return x_get_arg (FRAME_DISPLAY_INFO (f),
3998 alist, param, attribute, class, type);
4001 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4003 Lisp_Object
4004 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4005 Lisp_Object param,
4006 const char *attribute, const char *class,
4007 enum resource_types type)
4009 Lisp_Object value;
4011 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4012 attribute, class, type);
4013 if (! NILP (value) && ! EQ (value, Qunbound))
4014 store_frame_param (f, param, value);
4016 return value;
4020 /* Record in frame F the specified or default value according to ALIST
4021 of the parameter named PROP (a Lisp symbol).
4022 If no value is specified for PROP, look for an X default for XPROP
4023 on the frame named NAME.
4024 If that is not found either, use the value DEFLT. */
4026 Lisp_Object
4027 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4028 Lisp_Object deflt, const char *xprop, const char *xclass,
4029 enum resource_types type)
4031 Lisp_Object tem;
4033 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4034 if (EQ (tem, Qunbound))
4035 tem = deflt;
4036 x_set_frame_parameters (f, list1 (Fcons (prop, tem)));
4037 return tem;
4041 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4044 * XParseGeometry parses strings of the form
4045 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4046 * width, height, xoffset, and yoffset are unsigned integers.
4047 * Example: "=80x24+300-49"
4048 * The equal sign is optional.
4049 * It returns a bitmask that indicates which of the four values
4050 * were actually found in the string. For each value found,
4051 * the corresponding argument is updated; for each value
4052 * not found, the corresponding argument is left unchanged.
4055 static int
4056 XParseGeometry (char *string,
4057 int *x, int *y,
4058 unsigned int *width, unsigned int *height)
4060 int mask = NoValue;
4061 char *strind;
4062 unsigned long tempWidth, tempHeight;
4063 long int tempX, tempY;
4064 char *nextCharacter;
4066 if (string == NULL || *string == '\0')
4067 return mask;
4068 if (*string == '=')
4069 string++; /* ignore possible '=' at beg of geometry spec */
4071 strind = string;
4072 if (*strind != '+' && *strind != '-' && *strind != 'x')
4074 tempWidth = strtoul (strind, &nextCharacter, 10);
4075 if (strind == nextCharacter)
4076 return 0;
4077 strind = nextCharacter;
4078 mask |= WidthValue;
4081 if (*strind == 'x' || *strind == 'X')
4083 strind++;
4084 tempHeight = strtoul (strind, &nextCharacter, 10);
4085 if (strind == nextCharacter)
4086 return 0;
4087 strind = nextCharacter;
4088 mask |= HeightValue;
4091 if (*strind == '+' || *strind == '-')
4093 if (*strind == '-')
4094 mask |= XNegative;
4095 tempX = strtol (strind, &nextCharacter, 10);
4096 if (strind == nextCharacter)
4097 return 0;
4098 strind = nextCharacter;
4099 mask |= XValue;
4100 if (*strind == '+' || *strind == '-')
4102 if (*strind == '-')
4103 mask |= YNegative;
4104 tempY = strtol (strind, &nextCharacter, 10);
4105 if (strind == nextCharacter)
4106 return 0;
4107 strind = nextCharacter;
4108 mask |= YValue;
4112 /* If strind isn't at the end of the string then it's an invalid
4113 geometry specification. */
4115 if (*strind != '\0')
4116 return 0;
4118 if (mask & XValue)
4119 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4120 if (mask & YValue)
4121 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4122 if (mask & WidthValue)
4123 *width = min (tempWidth, UINT_MAX);
4124 if (mask & HeightValue)
4125 *height = min (tempHeight, UINT_MAX);
4126 return mask;
4129 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4132 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4133 make-docfile: the documentation string in ns-win.el was used for
4134 x-parse-geometry even in non-NS builds.
4136 With two definitions of x-parse-geometry in this file, various
4137 things still get confused (eg M-x apropos documentation), so that
4138 it is best if the two definitions just share the same doc-string.
4140 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4141 doc: /* Parse a display geometry string STRING.
4142 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4143 The properties returned may include `top', `left', `height', and `width'.
4144 For X, the value of `left' or `top' may be an integer,
4145 or a list (+ N) meaning N pixels relative to top/left corner,
4146 or a list (- N) meaning -N pixels relative to bottom/right corner.
4147 On Nextstep, this just calls `ns-parse-geometry'. */)
4148 (Lisp_Object string)
4150 int geometry, x, y;
4151 unsigned int width, height;
4152 Lisp_Object result;
4154 CHECK_STRING (string);
4156 #ifdef HAVE_NS
4157 if (strchr (SSDATA (string), ' ') != NULL)
4158 return call1 (Qns_parse_geometry, string);
4159 #endif
4160 geometry = XParseGeometry (SSDATA (string),
4161 &x, &y, &width, &height);
4162 result = Qnil;
4163 if (geometry & XValue)
4165 Lisp_Object element;
4167 if (x >= 0 && (geometry & XNegative))
4168 element = list3 (Qleft, Qminus, make_number (-x));
4169 else if (x < 0 && ! (geometry & XNegative))
4170 element = list3 (Qleft, Qplus, make_number (x));
4171 else
4172 element = Fcons (Qleft, make_number (x));
4173 result = Fcons (element, result);
4176 if (geometry & YValue)
4178 Lisp_Object element;
4180 if (y >= 0 && (geometry & YNegative))
4181 element = list3 (Qtop, Qminus, make_number (-y));
4182 else if (y < 0 && ! (geometry & YNegative))
4183 element = list3 (Qtop, Qplus, make_number (y));
4184 else
4185 element = Fcons (Qtop, make_number (y));
4186 result = Fcons (element, result);
4189 if (geometry & WidthValue)
4190 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4191 if (geometry & HeightValue)
4192 result = Fcons (Fcons (Qheight, make_number (height)), result);
4194 return result;
4198 /* Calculate the desired size and position of frame F.
4199 Return the flags saying which aspects were specified.
4201 Also set the win_gravity and size_hint_flags of F.
4203 Adjust height for toolbar if TOOLBAR_P is 1.
4205 This function does not make the coordinates positive. */
4207 #define DEFAULT_ROWS 35
4208 #define DEFAULT_COLS 80
4210 long
4211 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p)
4213 register Lisp_Object tem0, tem1, tem2;
4214 long window_prompting = 0;
4215 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4217 /* Default values if we fall through.
4218 Actually, if that happens we should get
4219 window manager prompting. */
4220 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4221 SET_FRAME_COLS (f, DEFAULT_COLS);
4222 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4223 FRAME_LINES (f) = DEFAULT_ROWS;
4225 /* Window managers expect that if program-specified
4226 positions are not (0,0), they're intentional, not defaults. */
4227 f->top_pos = 0;
4228 f->left_pos = 0;
4230 /* Ensure that old new_width and new_height will not override the
4231 values set here. */
4232 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4233 f->new_width = f->new_height = f->new_pixelwise = 0;
4235 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4236 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4237 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4238 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4240 if (!EQ (tem0, Qunbound))
4242 CHECK_NUMBER (tem0);
4243 if (! (0 <= XINT (tem0) && XINT (tem0) <= INT_MAX))
4244 xsignal1 (Qargs_out_of_range, tem0);
4245 FRAME_LINES (f) = XINT (tem0);
4247 if (!EQ (tem1, Qunbound))
4249 CHECK_NUMBER (tem1);
4250 if (! (0 <= XINT (tem1) && XINT (tem1) <= INT_MAX))
4251 xsignal1 (Qargs_out_of_range, tem1);
4252 SET_FRAME_COLS (f, XINT (tem1));
4254 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4255 window_prompting |= USSize;
4256 else
4257 window_prompting |= PSize;
4261 /* This used to be done _before_ calling x_figure_window_size, but
4262 since the height is reset here, this was really a no-op. I
4263 assume that moving it here does what Gerd intended (although he
4264 no longer can remember what that was... ++KFS, 2003-03-25. */
4266 /* Add the tool-bar height to the initial frame height so that the
4267 user gets a text display area of the size he specified with -g or
4268 via .Xdefaults. Later changes of the tool-bar height don't
4269 change the frame size. This is done so that users can create
4270 tall Emacs frames without having to guess how tall the tool-bar
4271 will get. */
4272 if (toolbar_p && FRAME_TOOL_BAR_HEIGHT (f))
4274 int margin, relief, bar_height;
4276 relief = (tool_bar_button_relief >= 0
4277 ? tool_bar_button_relief
4278 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4280 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4281 margin = XFASTINT (Vtool_bar_button_margin);
4282 else if (CONSP (Vtool_bar_button_margin)
4283 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4284 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4285 else
4286 margin = 0;
4288 /* PXW: We should be able to not round here. */
4289 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4290 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4293 compute_fringe_widths (f, 0);
4295 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
4296 SET_FRAME_HEIGHT(f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
4298 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4299 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4300 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4301 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4303 if (EQ (tem0, Qminus))
4305 f->top_pos = 0;
4306 window_prompting |= YNegative;
4308 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4309 && CONSP (XCDR (tem0))
4310 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem0)), INT_MAX))
4312 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4313 window_prompting |= YNegative;
4315 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4316 && CONSP (XCDR (tem0))
4317 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0))))
4319 f->top_pos = XINT (XCAR (XCDR (tem0)));
4321 else if (EQ (tem0, Qunbound))
4322 f->top_pos = 0;
4323 else
4325 CHECK_TYPE_RANGED_INTEGER (int, tem0);
4326 f->top_pos = XINT (tem0);
4327 if (f->top_pos < 0)
4328 window_prompting |= YNegative;
4331 if (EQ (tem1, Qminus))
4333 f->left_pos = 0;
4334 window_prompting |= XNegative;
4336 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4337 && CONSP (XCDR (tem1))
4338 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem1)), INT_MAX))
4340 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4341 window_prompting |= XNegative;
4343 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4344 && CONSP (XCDR (tem1))
4345 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1))))
4347 f->left_pos = XINT (XCAR (XCDR (tem1)));
4349 else if (EQ (tem1, Qunbound))
4350 f->left_pos = 0;
4351 else
4353 CHECK_TYPE_RANGED_INTEGER (int, tem1);
4354 f->left_pos = XINT (tem1);
4355 if (f->left_pos < 0)
4356 window_prompting |= XNegative;
4359 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4360 window_prompting |= USPosition;
4361 else
4362 window_prompting |= PPosition;
4365 if (window_prompting & XNegative)
4367 if (window_prompting & YNegative)
4368 f->win_gravity = SouthEastGravity;
4369 else
4370 f->win_gravity = NorthEastGravity;
4372 else
4374 if (window_prompting & YNegative)
4375 f->win_gravity = SouthWestGravity;
4376 else
4377 f->win_gravity = NorthWestGravity;
4380 f->size_hint_flags = window_prompting;
4382 return window_prompting;
4387 #endif /* HAVE_WINDOW_SYSTEM */
4389 void
4390 frame_make_pointer_invisible (void)
4392 if (! NILP (Vmake_pointer_invisible))
4394 struct frame *f;
4395 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4396 return;
4398 f = SELECTED_FRAME ();
4399 if (f && !f->pointer_invisible
4400 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4402 f->mouse_moved = 0;
4403 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4404 f->pointer_invisible = 1;
4409 void
4410 frame_make_pointer_visible (void)
4412 /* We don't check Vmake_pointer_invisible here in case the
4413 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4414 struct frame *f;
4416 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4417 return;
4419 f = SELECTED_FRAME ();
4420 if (f && f->pointer_invisible && f->mouse_moved
4421 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4423 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4424 f->pointer_invisible = 0;
4428 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4429 Sframe_pointer_visible_p, 0, 1, 0,
4430 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4431 Otherwise it returns nil. FRAME omitted or nil means the
4432 selected frame. This is useful when `make-pointer-invisible' is set. */)
4433 (Lisp_Object frame)
4435 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4440 /***********************************************************************
4441 Multimonitor data
4442 ***********************************************************************/
4444 #ifdef HAVE_WINDOW_SYSTEM
4446 # if (defined HAVE_NS \
4447 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4448 void
4449 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4451 int i;
4452 for (i = 0; i < n_monitors; ++i)
4453 xfree (monitors[i].name);
4454 xfree (monitors);
4456 # endif
4458 Lisp_Object
4459 make_monitor_attribute_list (struct MonitorInfo *monitors,
4460 int n_monitors,
4461 int primary_monitor,
4462 Lisp_Object monitor_frames,
4463 const char *source)
4465 Lisp_Object attributes_list = Qnil;
4466 Lisp_Object primary_monitor_attributes = Qnil;
4467 int i;
4469 for (i = 0; i < n_monitors; ++i)
4471 Lisp_Object geometry, workarea, attributes = Qnil;
4472 struct MonitorInfo *mi = &monitors[i];
4474 if (mi->geom.width == 0) continue;
4476 workarea = list4i (mi->work.x, mi->work.y,
4477 mi->work.width, mi->work.height);
4478 geometry = list4i (mi->geom.x, mi->geom.y,
4479 mi->geom.width, mi->geom.height);
4480 attributes = Fcons (Fcons (Qsource, build_string (source)),
4481 attributes);
4482 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4483 attributes);
4484 attributes = Fcons (Fcons (Qmm_size,
4485 list2i (mi->mm_width, mi->mm_height)),
4486 attributes);
4487 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4488 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4489 if (mi->name)
4490 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4491 strlen (mi->name))),
4492 attributes);
4494 if (i == primary_monitor)
4495 primary_monitor_attributes = attributes;
4496 else
4497 attributes_list = Fcons (attributes, attributes_list);
4500 if (!NILP (primary_monitor_attributes))
4501 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4502 return attributes_list;
4505 #endif /* HAVE_WINDOW_SYSTEM */
4508 /***********************************************************************
4509 Initialization
4510 ***********************************************************************/
4512 void
4513 syms_of_frame (void)
4515 DEFSYM (Qframep, "framep");
4516 DEFSYM (Qframe_live_p, "frame-live-p");
4517 DEFSYM (Qexplicit_name, "explicit-name");
4518 DEFSYM (Qheight, "height");
4519 DEFSYM (Qicon, "icon");
4520 DEFSYM (Qminibuffer, "minibuffer");
4521 DEFSYM (Qmodeline, "modeline");
4522 DEFSYM (Qonly, "only");
4523 DEFSYM (Qnone, "none");
4524 DEFSYM (Qwidth, "width");
4525 DEFSYM (Qgeometry, "geometry");
4526 DEFSYM (Qicon_left, "icon-left");
4527 DEFSYM (Qicon_top, "icon-top");
4528 DEFSYM (Qtooltip, "tooltip");
4529 DEFSYM (Qleft, "left");
4530 DEFSYM (Qright, "right");
4531 DEFSYM (Quser_position, "user-position");
4532 DEFSYM (Quser_size, "user-size");
4533 DEFSYM (Qwindow_id, "window-id");
4534 #ifdef HAVE_X_WINDOWS
4535 DEFSYM (Qouter_window_id, "outer-window-id");
4536 #endif
4537 DEFSYM (Qparent_id, "parent-id");
4538 DEFSYM (Qx, "x");
4539 DEFSYM (Qw32, "w32");
4540 DEFSYM (Qpc, "pc");
4541 DEFSYM (Qns, "ns");
4542 DEFSYM (Qvisible, "visible");
4543 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4544 DEFSYM (Qbuffer_list, "buffer-list");
4545 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4546 DEFSYM (Qdisplay_type, "display-type");
4547 DEFSYM (Qbackground_mode, "background-mode");
4548 DEFSYM (Qnoelisp, "noelisp");
4549 DEFSYM (Qtty_color_mode, "tty-color-mode");
4550 DEFSYM (Qtty, "tty");
4551 DEFSYM (Qtty_type, "tty-type");
4553 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4555 DEFSYM (Qfullwidth, "fullwidth");
4556 DEFSYM (Qfullheight, "fullheight");
4557 DEFSYM (Qfullboth, "fullboth");
4558 DEFSYM (Qmaximized, "maximized");
4559 DEFSYM (Qx_resource_name, "x-resource-name");
4560 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4562 DEFSYM (Qterminal, "terminal");
4564 DEFSYM (Qgeometry, "geometry");
4565 DEFSYM (Qworkarea, "workarea");
4566 DEFSYM (Qmm_size, "mm-size");
4567 DEFSYM (Qframes, "frames");
4568 DEFSYM (Qsource, "source");
4570 #ifdef HAVE_NS
4571 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4572 #endif
4575 int i;
4577 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4579 Lisp_Object v = intern_c_string (frame_parms[i].name);
4580 if (frame_parms[i].variable)
4582 *frame_parms[i].variable = v;
4583 staticpro (frame_parms[i].variable);
4585 Fput (v, Qx_frame_parameter, make_number (i));
4589 #ifdef HAVE_WINDOW_SYSTEM
4590 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4591 doc: /* The name Emacs uses to look up X resources.
4592 `x-get-resource' uses this as the first component of the instance name
4593 when requesting resource values.
4594 Emacs initially sets `x-resource-name' to the name under which Emacs
4595 was invoked, or to the value specified with the `-name' or `-rn'
4596 switches, if present.
4598 It may be useful to bind this variable locally around a call
4599 to `x-get-resource'. See also the variable `x-resource-class'. */);
4600 Vx_resource_name = Qnil;
4602 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4603 doc: /* The class Emacs uses to look up X resources.
4604 `x-get-resource' uses this as the first component of the instance class
4605 when requesting resource values.
4607 Emacs initially sets `x-resource-class' to "Emacs".
4609 Setting this variable permanently is not a reasonable thing to do,
4610 but binding this variable locally around a call to `x-get-resource'
4611 is a reasonable practice. See also the variable `x-resource-name'. */);
4612 Vx_resource_class = build_string (EMACS_CLASS);
4614 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4615 doc: /* The lower limit of the frame opacity (alpha transparency).
4616 The value should range from 0 (invisible) to 100 (completely opaque).
4617 You can also use a floating number between 0.0 and 1.0. */);
4618 Vframe_alpha_lower_limit = make_number (20);
4619 #endif
4621 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4622 doc: /* Alist of default values for frame creation.
4623 These may be set in your init file, like this:
4624 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4625 These override values given in window system configuration data,
4626 including X Windows' defaults database.
4627 For values specific to the first Emacs frame, see `initial-frame-alist'.
4628 For window-system specific values, see `window-system-default-frame-alist'.
4629 For values specific to the separate minibuffer frame, see
4630 `minibuffer-frame-alist'.
4631 The `menu-bar-lines' element of the list controls whether new frames
4632 have menu bars; `menu-bar-mode' works by altering this element.
4633 Setting this variable does not affect existing frames, only new ones. */);
4634 Vdefault_frame_alist = Qnil;
4636 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4637 doc: /* Default position of scroll bars on this window-system. */);
4638 #ifdef HAVE_WINDOW_SYSTEM
4639 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4640 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4641 default. */
4642 Vdefault_frame_scroll_bars = Qright;
4643 #else
4644 Vdefault_frame_scroll_bars = Qleft;
4645 #endif
4646 #else
4647 Vdefault_frame_scroll_bars = Qnil;
4648 #endif
4650 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
4651 scroll_bar_adjust_thumb_portion_p,
4652 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
4653 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
4654 even if the end of the buffer is shown (i.e. overscrolling).
4655 Set to nil if you want the thumb to be at the bottom when the end of the buffer
4656 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
4657 is visible. In this case you can not overscroll. */);
4658 scroll_bar_adjust_thumb_portion_p = 1;
4660 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4661 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4663 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4664 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4665 `mouse-position' calls this function, passing its usual return value as
4666 argument, and returns whatever this function returns.
4667 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4668 which need to do mouse handling at the Lisp level. */);
4669 Vmouse_position_function = Qnil;
4671 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4672 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4673 If the value is an integer, highlighting is only shown after moving the
4674 mouse, while keyboard input turns off the highlight even when the mouse
4675 is over the clickable text. However, the mouse shape still indicates
4676 when the mouse is over clickable text. */);
4677 Vmouse_highlight = Qt;
4679 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4680 doc: /* If non-nil, make pointer invisible while typing.
4681 The pointer becomes visible again when the mouse is moved. */);
4682 Vmake_pointer_invisible = Qt;
4684 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
4685 doc: /* Normal hook run when a frame gains input focus. */);
4686 Vfocus_in_hook = Qnil;
4687 DEFSYM (Qfocus_in_hook, "focus-in-hook");
4689 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
4690 doc: /* Normal hook run when a frame loses input focus. */);
4691 Vfocus_out_hook = Qnil;
4692 DEFSYM (Qfocus_out_hook, "focus-out-hook");
4694 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4695 doc: /* Functions run before deleting a frame.
4696 The functions are run with one arg, the frame to be deleted.
4697 See `delete-frame'.
4699 Note that functions in this list may be called just before the frame is
4700 actually deleted, or some time later (or even both when an earlier function
4701 in `delete-frame-functions' (indirectly) calls `delete-frame'
4702 recursively). */);
4703 Vdelete_frame_functions = Qnil;
4704 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4706 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4707 doc: /* Non-nil if Menu-Bar mode is enabled.
4708 See the command `menu-bar-mode' for a description of this minor mode.
4709 Setting this variable directly does not take effect;
4710 either customize it (see the info node `Easy Customization')
4711 or call the function `menu-bar-mode'. */);
4712 Vmenu_bar_mode = Qt;
4714 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4715 doc: /* Non-nil if Tool-Bar mode is enabled.
4716 See the command `tool-bar-mode' for a description of this minor mode.
4717 Setting this variable directly does not take effect;
4718 either customize it (see the info node `Easy Customization')
4719 or call the function `tool-bar-mode'. */);
4720 #ifdef HAVE_WINDOW_SYSTEM
4721 Vtool_bar_mode = Qt;
4722 #else
4723 Vtool_bar_mode = Qnil;
4724 #endif
4726 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4727 doc: /* Minibufferless frames use this frame's minibuffer.
4728 Emacs cannot create minibufferless frames unless this is set to an
4729 appropriate surrogate.
4731 Emacs consults this variable only when creating minibufferless
4732 frames; once the frame is created, it sticks with its assigned
4733 minibuffer, no matter what this variable is set to. This means that
4734 this variable doesn't necessarily say anything meaningful about the
4735 current set of frames, or where the minibuffer is currently being
4736 displayed.
4738 This variable is local to the current terminal and cannot be buffer-local. */);
4740 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4741 doc: /* Non-nil if window system changes focus when you move the mouse.
4742 You should set this variable to tell Emacs how your window manager
4743 handles focus, since there is no way in general for Emacs to find out
4744 automatically. See also `mouse-autoselect-window'. */);
4745 focus_follows_mouse = 0;
4747 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
4748 doc: /* Non-nil means resize frames pixelwise.
4749 If this option is nil, resizing a frame rounds its sizes to the frame's
4750 current values of `frame-char-height' and `frame-char-width'. If this
4751 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
4752 by one pixel.
4754 With some window managers you have to set this to non-nil in order to
4755 fully maximize frames. To resize your initial frame pixelwise,
4756 set this option to a non-nil value in your init file. */);
4757 frame_resize_pixelwise = 0;
4759 staticpro (&Vframe_list);
4761 defsubr (&Sframep);
4762 defsubr (&Sframe_live_p);
4763 defsubr (&Swindow_system);
4764 defsubr (&Smake_terminal_frame);
4765 defsubr (&Shandle_switch_frame);
4766 defsubr (&Sselect_frame);
4767 defsubr (&Sselected_frame);
4768 defsubr (&Sframe_list);
4769 defsubr (&Snext_frame);
4770 defsubr (&Sprevious_frame);
4771 defsubr (&Slast_nonminibuf_frame);
4772 defsubr (&Sdelete_frame);
4773 defsubr (&Smouse_position);
4774 defsubr (&Smouse_pixel_position);
4775 defsubr (&Sset_mouse_position);
4776 defsubr (&Sset_mouse_pixel_position);
4777 #if 0
4778 defsubr (&Sframe_configuration);
4779 defsubr (&Srestore_frame_configuration);
4780 #endif
4781 defsubr (&Smake_frame_visible);
4782 defsubr (&Smake_frame_invisible);
4783 defsubr (&Siconify_frame);
4784 defsubr (&Sframe_visible_p);
4785 defsubr (&Svisible_frame_list);
4786 defsubr (&Sraise_frame);
4787 defsubr (&Slower_frame);
4788 defsubr (&Sx_focus_frame);
4789 defsubr (&Sredirect_frame_focus);
4790 defsubr (&Sframe_focus);
4791 defsubr (&Sframe_parameters);
4792 defsubr (&Sframe_parameter);
4793 defsubr (&Smodify_frame_parameters);
4794 defsubr (&Sframe_char_height);
4795 defsubr (&Sframe_char_width);
4796 defsubr (&Sframe_pixel_height);
4797 defsubr (&Sframe_pixel_width);
4798 defsubr (&Sframe_text_cols);
4799 defsubr (&Sframe_text_lines);
4800 defsubr (&Sframe_total_cols);
4801 defsubr (&Sframe_text_width);
4802 defsubr (&Sframe_text_height);
4803 defsubr (&Sscroll_bar_width);
4804 defsubr (&Sfringe_width);
4805 defsubr (&Sborder_width);
4806 defsubr (&Sright_divider_width);
4807 defsubr (&Sbottom_divider_width);
4808 defsubr (&Stool_bar_pixel_width);
4809 defsubr (&Sset_frame_height);
4810 defsubr (&Sset_frame_width);
4811 defsubr (&Sset_frame_size);
4812 defsubr (&Sset_frame_position);
4813 defsubr (&Sframe_pointer_visible_p);
4815 #ifdef HAVE_WINDOW_SYSTEM
4816 defsubr (&Sx_get_resource);
4817 defsubr (&Sx_parse_geometry);
4818 #endif