* lisp/mouse.el (popup-menu): Fix last change.
[emacs.git] / src / frame.c
blob07783bd8c07e3c8eb40c12eb47ac8af8bfabf862
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <ctype.h>
24 #include <errno.h>
25 #include <limits.h>
26 #include <setjmp.h>
27 #include "lisp.h"
28 #include "character.h"
29 #ifdef HAVE_X_WINDOWS
30 #include "xterm.h"
31 #endif
32 #ifdef WINDOWSNT
33 #include "w32term.h"
34 #endif
35 #ifdef HAVE_NS
36 #include "nsterm.h"
37 #endif
38 #include "buffer.h"
39 /* These help us bind and responding to switch-frame events. */
40 #include "commands.h"
41 #include "keyboard.h"
42 #include "frame.h"
43 #include "blockinput.h"
44 #include "termchar.h"
45 #include "termhooks.h"
46 #include "dispextern.h"
47 #include "window.h"
48 #include "font.h"
49 #ifdef HAVE_WINDOW_SYSTEM
50 #include "fontset.h"
51 #endif
52 #ifdef MSDOS
53 #include "msdos.h"
54 #include "dosfns.h"
55 #endif
58 #ifdef HAVE_WINDOW_SYSTEM
60 #endif
62 #ifdef HAVE_NS
63 Lisp_Object Qns_parse_geometry;
64 #endif
66 Lisp_Object Qframep, Qframe_live_p;
67 Lisp_Object Qicon, Qmodeline;
68 Lisp_Object Qonly;
69 Lisp_Object Qx, Qw32, Qmac, Qpc, Qns;
70 Lisp_Object Qvisible;
71 Lisp_Object Qdisplay_type;
72 static Lisp_Object Qbackground_mode;
73 Lisp_Object Qnoelisp;
75 static Lisp_Object Qx_frame_parameter;
76 Lisp_Object Qx_resource_name;
77 Lisp_Object Qterminal;
78 Lisp_Object Qterminal_live_p;
80 /* Frame parameters (set or reported). */
82 Lisp_Object Qauto_raise, Qauto_lower;
83 Lisp_Object Qborder_color, Qborder_width;
84 Lisp_Object Qcursor_color, Qcursor_type;
85 static Lisp_Object Qgeometry; /* Not used */
86 Lisp_Object Qheight, Qwidth;
87 Lisp_Object Qleft, Qright;
88 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
89 Lisp_Object Qtooltip;
90 Lisp_Object Qinternal_border_width;
91 Lisp_Object Qmouse_color;
92 Lisp_Object Qminibuffer;
93 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
94 Lisp_Object Qvisibility;
95 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
96 Lisp_Object Qscreen_gamma;
97 Lisp_Object Qline_spacing;
98 static Lisp_Object Quser_position, Quser_size;
99 Lisp_Object Qwait_for_wm;
100 static Lisp_Object Qwindow_id;
101 #ifdef HAVE_X_WINDOWS
102 static Lisp_Object Qouter_window_id;
103 #endif
104 Lisp_Object Qparent_id;
105 Lisp_Object Qtitle, Qname;
106 static Lisp_Object Qexplicit_name;
107 Lisp_Object Qunsplittable;
108 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines, Qtool_bar_position;
109 Lisp_Object Qleft_fringe, Qright_fringe;
110 Lisp_Object Qbuffer_predicate;
111 static Lisp_Object Qbuffer_list, Qburied_buffer_list;
112 Lisp_Object Qtty_color_mode;
113 Lisp_Object Qtty, Qtty_type;
115 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth, Qmaximized;
116 Lisp_Object Qsticky;
117 Lisp_Object Qfont_backend;
118 Lisp_Object Qalpha;
120 Lisp_Object Qface_set_after_frame_default;
122 static Lisp_Object Qdelete_frame_functions;
124 #ifdef HAVE_WINDOW_SYSTEM
125 static void x_report_frame_params (struct frame *, Lisp_Object *);
126 #endif
129 static void
130 set_menu_bar_lines_1 (Lisp_Object window, int n)
132 struct window *w = XWINDOW (window);
134 w->last_modified = 0;
135 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
136 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
138 /* Handle just the top child in a vertical split. */
139 if (!NILP (w->vchild))
140 set_menu_bar_lines_1 (w->vchild, n);
142 /* Adjust all children in a horizontal split. */
143 for (window = w->hchild; !NILP (window); window = w->next)
145 w = XWINDOW (window);
146 set_menu_bar_lines_1 (window, n);
150 void
151 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
153 int nlines;
154 int olines = FRAME_MENU_BAR_LINES (f);
156 /* Right now, menu bars don't work properly in minibuf-only frames;
157 most of the commands try to apply themselves to the minibuffer
158 frame itself, and get an error because you can't switch buffers
159 in or split the minibuffer window. */
160 if (FRAME_MINIBUF_ONLY_P (f))
161 return;
163 if (TYPE_RANGED_INTEGERP (int, value))
164 nlines = XINT (value);
165 else
166 nlines = 0;
168 if (nlines != olines)
170 windows_or_buffers_changed++;
171 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
172 FRAME_MENU_BAR_LINES (f) = nlines;
173 set_menu_bar_lines_1 (f->root_window, nlines - olines);
174 adjust_glyphs (f);
178 Lisp_Object Vframe_list;
181 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
182 doc: /* Return non-nil if OBJECT is a frame.
183 Value is:
184 t for a termcap frame (a character-only terminal),
185 'x' for an Emacs frame that is really an X window,
186 'w32' for an Emacs frame that is a window on MS-Windows display,
187 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
188 'pc' for a direct-write MS-DOS frame.
189 See also `frame-live-p'. */)
190 (Lisp_Object object)
192 if (!FRAMEP (object))
193 return Qnil;
194 switch (XFRAME (object)->output_method)
196 case output_initial: /* The initial frame is like a termcap frame. */
197 case output_termcap:
198 return Qt;
199 case output_x_window:
200 return Qx;
201 case output_w32:
202 return Qw32;
203 case output_msdos_raw:
204 return Qpc;
205 case output_mac:
206 return Qmac;
207 case output_ns:
208 return Qns;
209 default:
210 abort ();
214 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
215 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
216 Value is nil if OBJECT is not a live frame. If object is a live
217 frame, the return value indicates what sort of terminal device it is
218 displayed on. See the documentation of `framep' for possible
219 return values. */)
220 (Lisp_Object object)
222 return ((FRAMEP (object)
223 && FRAME_LIVE_P (XFRAME (object)))
224 ? Fframep (object)
225 : Qnil);
228 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
229 doc: /* The name of the window system that FRAME is displaying through.
230 The value is a symbol:
231 nil for a termcap frame (a character-only terminal),
232 'x' for an Emacs frame that is really an X window,
233 'w32' for an Emacs frame that is a window on MS-Windows display,
234 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
235 'pc' for a direct-write MS-DOS frame.
237 FRAME defaults to the currently selected frame.
239 Use of this function as a predicate is deprecated. Instead,
240 use `display-graphic-p' or any of the other `display-*-p'
241 predicates which report frame's specific UI-related capabilities. */)
242 (Lisp_Object frame)
244 Lisp_Object type;
245 if (NILP (frame))
246 frame = selected_frame;
248 type = Fframep (frame);
250 if (NILP (type))
251 wrong_type_argument (Qframep, frame);
253 if (EQ (type, Qt))
254 return Qnil;
255 else
256 return type;
259 struct frame *
260 make_frame (int mini_p)
262 Lisp_Object frame;
263 register struct frame *f;
264 register Lisp_Object root_window;
265 register Lisp_Object mini_window;
267 f = allocate_frame ();
268 XSETFRAME (frame, f);
270 /* Initialize Lisp data. Note that allocate_frame initializes all
271 Lisp data to nil, so do it only for slots which should not be nil. */
272 f->tool_bar_position = Qtop;
274 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
275 non-Lisp data, so do it only for slots which should not be zero.
276 To avoid subtle bugs and for the sake of readability, it's better to
277 initialize enum members explicitly even if their values are zero. */
278 f->wants_modeline = 1;
279 f->garbaged = 1;
280 f->has_minibuffer = mini_p;
281 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
282 f->column_width = 1; /* !FRAME_WINDOW_P value */
283 f->line_height = 1; /* !FRAME_WINDOW_P value */
284 #ifdef HAVE_WINDOW_SYSTEM
285 f->want_fullscreen = FULLSCREEN_NONE;
286 #endif
288 root_window = make_window ();
289 if (mini_p)
291 mini_window = make_window ();
292 XWINDOW (root_window)->next = mini_window;
293 XWINDOW (mini_window)->prev = root_window;
294 XWINDOW (mini_window)->mini = 1;
295 XWINDOW (mini_window)->frame = frame;
296 f->minibuffer_window = mini_window;
298 else
300 mini_window = Qnil;
301 XWINDOW (root_window)->next = Qnil;
302 f->minibuffer_window = Qnil;
305 XWINDOW (root_window)->frame = frame;
307 /* 10 is arbitrary,
308 just so that there is "something there."
309 Correct size will be set up later with change_frame_size. */
311 SET_FRAME_COLS (f, 10);
312 FRAME_LINES (f) = 10;
314 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
315 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
317 if (mini_p)
319 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
320 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
321 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
324 /* Choose a buffer for the frame's root window. */
326 Lisp_Object buf;
328 XWINDOW (root_window)->buffer = Qt;
329 buf = Fcurrent_buffer ();
330 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
331 a space), try to find another one. */
332 if (SREF (Fbuffer_name (buf), 0) == ' ')
333 buf = other_buffer_safely (buf);
335 /* Use set_window_buffer, not Fset_window_buffer, and don't let
336 hooks be run by it. The reason is that the whole frame/window
337 arrangement is not yet fully initialized at this point. Windows
338 don't have the right size, glyph matrices aren't initialized
339 etc. Running Lisp functions at this point surely ends in a
340 SEGV. */
341 set_window_buffer (root_window, buf, 0, 0);
342 f->buffer_list = Fcons (buf, Qnil);
345 if (mini_p)
347 XWINDOW (mini_window)->buffer = Qt;
348 set_window_buffer (mini_window,
349 (NILP (Vminibuffer_list)
350 ? get_minibuffer (0)
351 : Fcar (Vminibuffer_list)),
352 0, 0);
355 f->root_window = root_window;
356 f->selected_window = root_window;
357 /* Make sure this window seems more recently used than
358 a newly-created, never-selected window. */
359 XWINDOW (f->selected_window)->use_time = ++window_select_count;
361 return f;
364 #ifdef HAVE_WINDOW_SYSTEM
365 /* Make a frame using a separate minibuffer window on another frame.
366 MINI_WINDOW is the minibuffer window to use. nil means use the
367 default (the global minibuffer). */
369 struct frame *
370 make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
372 register struct frame *f;
373 struct gcpro gcpro1;
375 if (!NILP (mini_window))
376 CHECK_LIVE_WINDOW (mini_window);
378 if (!NILP (mini_window)
379 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
380 error ("Frame and minibuffer must be on the same terminal");
382 /* Make a frame containing just a root window. */
383 f = make_frame (0);
385 if (NILP (mini_window))
387 /* Use default-minibuffer-frame if possible. */
388 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
389 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
391 Lisp_Object frame_dummy;
393 XSETFRAME (frame_dummy, f);
394 GCPRO1 (frame_dummy);
395 /* If there's no minibuffer frame to use, create one. */
396 KVAR (kb, Vdefault_minibuffer_frame) =
397 call1 (intern ("make-initial-minibuffer-frame"), display);
398 UNGCPRO;
401 mini_window = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
404 f->minibuffer_window = mini_window;
406 /* Make the chosen minibuffer window display the proper minibuffer,
407 unless it is already showing a minibuffer. */
408 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
409 Fset_window_buffer (mini_window,
410 (NILP (Vminibuffer_list)
411 ? get_minibuffer (0)
412 : Fcar (Vminibuffer_list)), Qnil);
413 return f;
416 /* Make a frame containing only a minibuffer window. */
418 struct frame *
419 make_minibuffer_frame (void)
421 /* First make a frame containing just a root window, no minibuffer. */
423 register struct frame *f = make_frame (0);
424 register Lisp_Object mini_window;
425 register Lisp_Object frame;
427 XSETFRAME (frame, f);
429 f->auto_raise = 0;
430 f->auto_lower = 0;
431 f->no_split = 1;
432 f->wants_modeline = 0;
433 f->has_minibuffer = 1;
435 /* Now label the root window as also being the minibuffer.
436 Avoid infinite looping on the window chain by marking next pointer
437 as nil. */
439 mini_window = f->minibuffer_window = f->root_window;
440 XWINDOW (mini_window)->mini = 1;
441 XWINDOW (mini_window)->next = Qnil;
442 XWINDOW (mini_window)->prev = Qnil;
443 XWINDOW (mini_window)->frame = frame;
445 /* Put the proper buffer in that window. */
447 Fset_window_buffer (mini_window,
448 (NILP (Vminibuffer_list)
449 ? get_minibuffer (0)
450 : Fcar (Vminibuffer_list)), Qnil);
451 return f;
453 #endif /* HAVE_WINDOW_SYSTEM */
455 /* Construct a frame that refers to a terminal. */
457 static printmax_t tty_frame_count;
459 struct frame *
460 make_initial_frame (void)
462 struct frame *f;
463 struct terminal *terminal;
464 Lisp_Object frame;
466 eassert (initial_kboard);
468 /* The first call must initialize Vframe_list. */
469 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
470 Vframe_list = Qnil;
472 terminal = init_initial_terminal ();
474 f = make_frame (1);
475 XSETFRAME (frame, f);
477 Vframe_list = Fcons (frame, Vframe_list);
479 tty_frame_count = 1;
480 f->name = build_pure_c_string ("F1");
482 f->visible = 1;
483 f->async_visible = 1;
485 f->output_method = terminal->type;
486 f->terminal = terminal;
487 f->terminal->reference_count++;
488 f->output_data.nothing = 0;
490 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
491 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
493 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
494 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
496 /* The default value of menu-bar-mode is t. */
497 set_menu_bar_lines (f, make_number (1), Qnil);
499 if (!noninteractive)
500 init_frame_faces (f);
502 return f;
506 static struct frame *
507 make_terminal_frame (struct terminal *terminal)
509 register struct frame *f;
510 Lisp_Object frame;
511 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
513 if (!terminal->name)
514 error ("Terminal is not live, can't create new frames on it");
516 f = make_frame (1);
518 XSETFRAME (frame, f);
519 Vframe_list = Fcons (frame, Vframe_list);
521 f->name = make_formatted_string (name, "F%"pMd, ++tty_frame_count);
523 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
524 f->async_visible = 1; /* Don't let visible be cleared later. */
525 f->terminal = terminal;
526 f->terminal->reference_count++;
527 #ifdef MSDOS
528 f->output_data.tty->display_info = &the_only_display_info;
529 if (!inhibit_window_system
530 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
531 || XFRAME (selected_frame)->output_method == output_msdos_raw))
532 f->output_method = output_msdos_raw;
533 else
534 f->output_method = output_termcap;
535 #else /* not MSDOS */
536 f->output_method = output_termcap;
537 create_tty_output (f);
538 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
539 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
540 #endif /* not MSDOS */
542 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
543 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
544 FRAME_MENU_BAR_LINES(f) = NILP (Vmenu_bar_mode) ? 0 : 1;
546 /* Set the top frame to the newly created frame. */
547 if (FRAMEP (FRAME_TTY (f)->top_frame)
548 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
549 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
551 FRAME_TTY (f)->top_frame = frame;
553 if (!noninteractive)
554 init_frame_faces (f);
556 return f;
559 /* Get a suitable value for frame parameter PARAMETER for a newly
560 created frame, based on (1) the user-supplied frame parameter
561 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
563 static Lisp_Object
564 get_future_frame_param (Lisp_Object parameter,
565 Lisp_Object supplied_parms,
566 char *current_value)
568 Lisp_Object result;
570 result = Fassq (parameter, supplied_parms);
571 if (NILP (result))
572 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
573 if (NILP (result) && current_value != NULL)
574 result = build_string (current_value);
575 if (!NILP (result) && !STRINGP (result))
576 result = XCDR (result);
577 if (NILP (result) || !STRINGP (result))
578 result = Qnil;
580 return result;
583 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
584 1, 1, 0,
585 doc: /* Create an additional terminal frame, possibly on another terminal.
586 This function takes one argument, an alist specifying frame parameters.
588 You can create multiple frames on a single text terminal, but only one
589 of them (the selected terminal frame) is actually displayed.
591 In practice, generally you don't need to specify any parameters,
592 except when you want to create a new frame on another terminal.
593 In that case, the `tty' parameter specifies the device file to open,
594 and the `tty-type' parameter specifies the terminal type. Example:
596 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
598 Note that changing the size of one terminal frame automatically
599 affects all frames on the same terminal device. */)
600 (Lisp_Object parms)
602 struct frame *f;
603 struct terminal *t = NULL;
604 Lisp_Object frame, tem;
605 struct frame *sf = SELECTED_FRAME ();
607 #ifdef MSDOS
608 if (sf->output_method != output_msdos_raw
609 && sf->output_method != output_termcap)
610 abort ();
611 #else /* not MSDOS */
613 #ifdef WINDOWSNT /* This should work now! */
614 if (sf->output_method != output_termcap)
615 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
616 #endif
617 #endif /* not MSDOS */
620 Lisp_Object terminal;
622 terminal = Fassq (Qterminal, parms);
623 if (!NILP (terminal))
625 terminal = XCDR (terminal);
626 t = get_terminal (terminal, 1);
628 #ifdef MSDOS
629 if (t && t != the_only_display_info.terminal)
630 /* msdos.c assumes a single tty_display_info object. */
631 error ("Multiple terminals are not supported on this platform");
632 if (!t)
633 t = the_only_display_info.terminal;
634 #endif
637 if (!t)
639 char *name = 0, *type = 0;
640 Lisp_Object tty, tty_type;
642 tty = get_future_frame_param
643 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
644 ? FRAME_TTY (XFRAME (selected_frame))->name
645 : NULL));
646 if (!NILP (tty))
648 name = alloca (SBYTES (tty) + 1);
649 memcpy (name, SSDATA (tty), SBYTES (tty));
650 name[SBYTES (tty)] = 0;
653 tty_type = get_future_frame_param
654 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
655 ? FRAME_TTY (XFRAME (selected_frame))->type
656 : NULL));
657 if (!NILP (tty_type))
659 type = alloca (SBYTES (tty_type) + 1);
660 memcpy (type, SSDATA (tty_type), SBYTES (tty_type));
661 type[SBYTES (tty_type)] = 0;
664 t = init_tty (name, type, 0); /* Errors are not fatal. */
667 f = make_terminal_frame (t);
670 int width, height;
671 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
672 change_frame_size (f, height, width, 0, 0, 0);
675 adjust_glyphs (f);
676 calculate_costs (f);
677 XSETFRAME (frame, f);
678 Fmodify_frame_parameters (frame, parms);
679 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
680 build_string (t->display_info.tty->type)),
681 Qnil));
682 if (t->display_info.tty->name != NULL)
683 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
684 build_string (t->display_info.tty->name)),
685 Qnil));
686 else
687 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
689 /* Make the frame face alist be frame-specific, so that each
690 frame could change its face definitions independently. */
691 f->face_alist = Fcopy_alist (sf->face_alist);
692 /* Simple Fcopy_alist isn't enough, because we need the contents of
693 the vectors which are the CDRs of associations in face_alist to
694 be copied as well. */
695 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
696 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
697 return frame;
701 /* Perform the switch to frame FRAME.
703 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
704 FRAME1 as frame.
706 If TRACK is non-zero and the frame that currently has the focus
707 redirects its focus to the selected frame, redirect that focused
708 frame's focus to FRAME instead.
710 FOR_DELETION non-zero means that the selected frame is being
711 deleted, which includes the possibility that the frame's terminal
712 is dead.
714 The value of NORECORD is passed as argument to Fselect_window. */
716 Lisp_Object
717 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
719 struct frame *sf = SELECTED_FRAME ();
721 /* If FRAME is a switch-frame event, extract the frame we should
722 switch to. */
723 if (CONSP (frame)
724 && EQ (XCAR (frame), Qswitch_frame)
725 && CONSP (XCDR (frame)))
726 frame = XCAR (XCDR (frame));
728 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
729 a switch-frame event to arrive after a frame is no longer live,
730 especially when deleting the initial frame during startup. */
731 CHECK_FRAME (frame);
732 if (! FRAME_LIVE_P (XFRAME (frame)))
733 return Qnil;
735 if (sf == XFRAME (frame))
736 return frame;
738 /* This is too greedy; it causes inappropriate focus redirection
739 that's hard to get rid of. */
740 #if 0
741 /* If a frame's focus has been redirected toward the currently
742 selected frame, we should change the redirection to point to the
743 newly selected frame. This means that if the focus is redirected
744 from a minibufferless frame to a surrogate minibuffer frame, we
745 can use `other-window' to switch between all the frames using
746 that minibuffer frame, and the focus redirection will follow us
747 around. */
748 if (track)
750 Lisp_Object tail;
752 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
754 Lisp_Object focus;
756 if (!FRAMEP (XCAR (tail)))
757 abort ();
759 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
761 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
762 Fredirect_frame_focus (XCAR (tail), frame);
765 #else /* ! 0 */
766 /* Instead, apply it only to the frame we're pointing to. */
767 #ifdef HAVE_WINDOW_SYSTEM
768 if (track && FRAME_WINDOW_P (XFRAME (frame)))
770 Lisp_Object focus, xfocus;
772 xfocus = x_get_focus_frame (XFRAME (frame));
773 if (FRAMEP (xfocus))
775 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
776 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
777 Fredirect_frame_focus (xfocus, frame);
780 #endif /* HAVE_X_WINDOWS */
781 #endif /* ! 0 */
783 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
784 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
786 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
788 if (FRAMEP (FRAME_TTY (XFRAME (frame))->top_frame))
789 /* Mark previously displayed frame as now obscured. */
790 XFRAME (FRAME_TTY (XFRAME (frame))->top_frame)->async_visible = 2;
791 XFRAME (frame)->async_visible = 1;
792 FRAME_TTY (XFRAME (frame))->top_frame = frame;
795 selected_frame = frame;
796 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
797 last_nonminibuf_frame = XFRAME (selected_frame);
799 Fselect_window (XFRAME (frame)->selected_window, norecord);
801 /* We want to make sure that the next event generates a frame-switch
802 event to the appropriate frame. This seems kludgy to me, but
803 before you take it out, make sure that evaluating something like
804 (select-window (frame-root-window (new-frame))) doesn't end up
805 with your typing being interpreted in the new frame instead of
806 the one you're actually typing in. */
807 internal_last_event_frame = Qnil;
809 return frame;
812 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
813 doc: /* Select FRAME.
814 Subsequent editing commands apply to its selected window.
815 Optional argument NORECORD means to neither change the order of
816 recently selected windows nor the buffer list.
818 The selection of FRAME lasts until the next time the user does
819 something to select a different frame, or until the next time
820 this function is called. If you are using a window system, the
821 previously selected frame may be restored as the selected frame
822 when returning to the command loop, because it still may have
823 the window system's input focus. On a text terminal, the next
824 redisplay will display FRAME.
826 This function returns FRAME, or nil if FRAME has been deleted. */)
827 (Lisp_Object frame, Lisp_Object norecord)
829 return do_switch_frame (frame, 1, 0, norecord);
833 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
834 doc: /* Handle a switch-frame event EVENT.
835 Switch-frame events are usually bound to this function.
836 A switch-frame event tells Emacs that the window manager has requested
837 that the user's events be directed to the frame mentioned in the event.
838 This function selects the selected window of the frame of EVENT.
840 If EVENT is frame object, handle it as if it were a switch-frame event
841 to that frame. */)
842 (Lisp_Object event)
844 /* Preserve prefix arg that the command loop just cleared. */
845 KVAR (current_kboard, Vprefix_arg) = Vcurrent_prefix_arg;
846 Frun_hooks (1, &Qmouse_leave_buffer_hook);
847 return do_switch_frame (event, 0, 0, Qnil);
850 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
851 doc: /* Return the frame that is now selected. */)
852 (void)
854 return selected_frame;
857 DEFUN ("frame-list", Fframe_list, Sframe_list,
858 0, 0, 0,
859 doc: /* Return a list of all live frames. */)
860 (void)
862 Lisp_Object frames;
863 frames = Fcopy_sequence (Vframe_list);
864 #ifdef HAVE_WINDOW_SYSTEM
865 if (FRAMEP (tip_frame))
866 frames = Fdelq (tip_frame, frames);
867 #endif
868 return frames;
871 /* Return the next frame in the frame list after FRAME.
872 If MINIBUF is nil, exclude minibuffer-only frames.
873 If MINIBUF is a window, include only its own frame
874 and any frame now using that window as the minibuffer.
875 If MINIBUF is `visible', include all visible frames.
876 If MINIBUF is 0, include all visible and iconified frames.
877 Otherwise, include all frames. */
879 static Lisp_Object
880 next_frame (Lisp_Object frame, Lisp_Object minibuf)
882 Lisp_Object tail;
883 int passed = 0;
885 /* There must always be at least one frame in Vframe_list. */
886 if (! CONSP (Vframe_list))
887 abort ();
889 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
890 forever. Forestall that. */
891 CHECK_LIVE_FRAME (frame);
893 while (1)
894 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
896 Lisp_Object f;
898 f = XCAR (tail);
900 if (passed
901 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
902 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
903 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
904 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
906 /* Decide whether this frame is eligible to be returned. */
908 /* If we've looped all the way around without finding any
909 eligible frames, return the original frame. */
910 if (EQ (f, frame))
911 return f;
913 /* Let minibuf decide if this frame is acceptable. */
914 if (NILP (minibuf))
916 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
917 return f;
919 else if (EQ (minibuf, Qvisible))
921 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
922 if (FRAME_VISIBLE_P (XFRAME (f)))
923 return f;
925 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
927 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
928 if (FRAME_VISIBLE_P (XFRAME (f))
929 || FRAME_ICONIFIED_P (XFRAME (f)))
930 return f;
932 else if (WINDOWP (minibuf))
934 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
935 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
936 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
937 FRAME_FOCUS_FRAME (XFRAME (f))))
938 return f;
940 else
941 return f;
944 if (EQ (frame, f))
945 passed++;
949 /* Return the previous frame in the frame list before FRAME.
950 If MINIBUF is nil, exclude minibuffer-only frames.
951 If MINIBUF is a window, include only its own frame
952 and any frame now using that window as the minibuffer.
953 If MINIBUF is `visible', include all visible frames.
954 If MINIBUF is 0, include all visible and iconified frames.
955 Otherwise, include all frames. */
957 static Lisp_Object
958 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
960 Lisp_Object tail;
961 Lisp_Object prev;
963 /* There must always be at least one frame in Vframe_list. */
964 if (! CONSP (Vframe_list))
965 abort ();
967 prev = Qnil;
968 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
970 Lisp_Object f;
972 f = XCAR (tail);
973 if (!FRAMEP (f))
974 abort ();
976 if (EQ (frame, f) && !NILP (prev))
977 return prev;
979 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
980 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
981 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
982 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
984 /* Decide whether this frame is eligible to be returned,
985 according to minibuf. */
986 if (NILP (minibuf))
988 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
989 prev = f;
991 else if (WINDOWP (minibuf))
993 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
994 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
995 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
996 FRAME_FOCUS_FRAME (XFRAME (f))))
997 prev = f;
999 else if (EQ (minibuf, Qvisible))
1001 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1002 if (FRAME_VISIBLE_P (XFRAME (f)))
1003 prev = f;
1005 else if (XFASTINT (minibuf) == 0)
1007 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1008 if (FRAME_VISIBLE_P (XFRAME (f))
1009 || FRAME_ICONIFIED_P (XFRAME (f)))
1010 prev = f;
1012 else
1013 prev = f;
1017 /* We've scanned the entire list. */
1018 if (NILP (prev))
1019 /* We went through the whole frame list without finding a single
1020 acceptable frame. Return the original frame. */
1021 return frame;
1022 else
1023 /* There were no acceptable frames in the list before FRAME; otherwise,
1024 we would have returned directly from the loop. Since PREV is the last
1025 acceptable frame in the list, return it. */
1026 return prev;
1030 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1031 doc: /* Return the next frame in the frame list after FRAME.
1032 It considers only frames on the same terminal as FRAME.
1033 By default, skip minibuffer-only frames.
1034 If omitted, FRAME defaults to the selected frame.
1035 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1036 If MINIFRAME is a window, include only its own frame
1037 and any frame now using that window as the minibuffer.
1038 If MINIFRAME is `visible', include all visible frames.
1039 If MINIFRAME is 0, include all visible and iconified frames.
1040 Otherwise, include all frames. */)
1041 (Lisp_Object frame, Lisp_Object miniframe)
1043 if (NILP (frame))
1044 frame = selected_frame;
1046 CHECK_LIVE_FRAME (frame);
1047 return next_frame (frame, miniframe);
1050 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1051 doc: /* Return the previous frame in the frame list before FRAME.
1052 It considers only frames on the same terminal as FRAME.
1053 By default, skip minibuffer-only frames.
1054 If omitted, FRAME defaults to the selected frame.
1055 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1056 If MINIFRAME is a window, include only its own frame
1057 and any frame now using that window as the minibuffer.
1058 If MINIFRAME is `visible', include all visible frames.
1059 If MINIFRAME is 0, include all visible and iconified frames.
1060 Otherwise, include all frames. */)
1061 (Lisp_Object frame, Lisp_Object miniframe)
1063 if (NILP (frame))
1064 frame = selected_frame;
1065 CHECK_LIVE_FRAME (frame);
1066 return prev_frame (frame, miniframe);
1069 /* Return 1 if it is ok to delete frame F;
1070 0 if all frames aside from F are invisible.
1071 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1073 static int
1074 other_visible_frames (FRAME_PTR f)
1076 Lisp_Object frames;
1078 for (frames = Vframe_list; CONSP (frames); frames = XCDR (frames))
1080 Lisp_Object this = XCAR (frames);
1081 if (f == XFRAME (this))
1082 continue;
1084 /* Verify that we can still talk to the frame's X window,
1085 and note any recent change in visibility. */
1086 #ifdef HAVE_WINDOW_SYSTEM
1087 if (FRAME_WINDOW_P (XFRAME (this)))
1089 x_sync (XFRAME (this));
1090 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1092 #endif
1094 if (FRAME_VISIBLE_P (XFRAME (this))
1095 || FRAME_ICONIFIED_P (XFRAME (this))
1096 /* Allow deleting the terminal frame when at least one X
1097 frame exists. */
1098 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1099 return 1;
1101 return 0;
1104 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1105 unconditionally. x_connection_closed and delete_terminal use
1106 this. Any other value of FORCE implements the semantics
1107 described for Fdelete_frame. */
1108 Lisp_Object
1109 delete_frame (Lisp_Object frame, Lisp_Object force)
1111 struct frame *f;
1112 struct frame *sf = SELECTED_FRAME ();
1113 struct kboard *kb;
1115 int minibuffer_selected, tooltip_frame;
1117 if (EQ (frame, Qnil))
1119 f = sf;
1120 XSETFRAME (frame, f);
1122 else
1124 CHECK_FRAME (frame);
1125 f = XFRAME (frame);
1128 if (! FRAME_LIVE_P (f))
1129 return Qnil;
1131 if (NILP (force) && !other_visible_frames (f))
1132 error ("Attempt to delete the sole visible or iconified frame");
1134 /* x_connection_closed must have set FORCE to `noelisp' in order
1135 to delete the last frame, if it is gone. */
1136 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1137 error ("Attempt to delete the only frame");
1139 /* Does this frame have a minibuffer, and is it the surrogate
1140 minibuffer for any other frame? */
1141 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1143 Lisp_Object frames;
1145 for (frames = Vframe_list;
1146 CONSP (frames);
1147 frames = XCDR (frames))
1149 Lisp_Object this;
1150 this = XCAR (frames);
1152 if (! EQ (this, frame)
1153 && EQ (frame,
1154 WINDOW_FRAME (XWINDOW
1155 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1157 /* If we MUST delete this frame, delete the other first.
1158 But do this only if FORCE equals `noelisp'. */
1159 if (EQ (force, Qnoelisp))
1160 delete_frame (this, Qnoelisp);
1161 else
1162 error ("Attempt to delete a surrogate minibuffer frame");
1167 tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1169 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1170 frame is a tooltip. FORCE is set to `noelisp' when handling
1171 a disconnect from the terminal, so we don't dare call Lisp
1172 code. */
1173 if (NILP (Vrun_hooks) || tooltip_frame)
1175 else if (EQ (force, Qnoelisp))
1176 pending_funcalls
1177 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1178 pending_funcalls);
1179 else
1181 #ifdef HAVE_X_WINDOWS
1182 /* Also, save clipboard to the clipboard manager. */
1183 x_clipboard_manager_save_frame (frame);
1184 #endif
1186 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1189 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1190 if (! FRAME_LIVE_P (f))
1191 return Qnil;
1193 /* At this point, we are committed to deleting the frame.
1194 There is no more chance for errors to prevent it. */
1196 minibuffer_selected = EQ (minibuf_window, selected_window);
1198 /* Don't let the frame remain selected. */
1199 if (f == sf)
1201 Lisp_Object tail, frame1;
1203 /* Look for another visible frame on the same terminal. */
1204 frame1 = next_frame (frame, Qvisible);
1206 /* If there is none, find *some* other frame. */
1207 if (NILP (frame1) || EQ (frame1, frame))
1209 FOR_EACH_FRAME (tail, frame1)
1211 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1213 /* Do not change a text terminal's top-frame. */
1214 struct frame *f1 = XFRAME (frame1);
1215 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1217 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1218 if (!EQ (top_frame, frame))
1219 frame1 = top_frame;
1221 break;
1225 #ifdef NS_IMPL_COCOA
1226 else
1227 /* Under NS, there is no system mechanism for choosing a new
1228 window to get focus -- it is left to application code.
1229 So the portion of THIS application interfacing with NS
1230 needs to know about it. We call Fraise_frame, but the
1231 purpose is really to transfer focus. */
1232 Fraise_frame (frame1);
1233 #endif
1235 do_switch_frame (frame1, 0, 1, Qnil);
1236 sf = SELECTED_FRAME ();
1239 /* Don't allow minibuf_window to remain on a deleted frame. */
1240 if (EQ (f->minibuffer_window, minibuf_window))
1242 Fset_window_buffer (sf->minibuffer_window,
1243 XWINDOW (minibuf_window)->buffer, Qnil);
1244 minibuf_window = sf->minibuffer_window;
1246 /* If the dying minibuffer window was selected,
1247 select the new one. */
1248 if (minibuffer_selected)
1249 Fselect_window (minibuf_window, Qnil);
1252 /* Don't let echo_area_window to remain on a deleted frame. */
1253 if (EQ (f->minibuffer_window, echo_area_window))
1254 echo_area_window = sf->minibuffer_window;
1256 /* Clear any X selections for this frame. */
1257 #ifdef HAVE_X_WINDOWS
1258 if (FRAME_X_P (f))
1259 x_clear_frame_selections (f);
1260 #endif
1262 /* Free glyphs.
1263 This function must be called before the window tree of the
1264 frame is deleted because windows contain dynamically allocated
1265 memory. */
1266 free_glyphs (f);
1268 #ifdef HAVE_WINDOW_SYSTEM
1269 /* Give chance to each font driver to free a frame specific data. */
1270 font_update_drivers (f, Qnil);
1271 #endif
1273 /* Mark all the windows that used to be on FRAME as deleted, and then
1274 remove the reference to them. */
1275 delete_all_child_windows (f->root_window);
1276 f->root_window = Qnil;
1278 Vframe_list = Fdelq (frame, Vframe_list);
1279 FRAME_SET_VISIBLE (f, 0);
1281 /* Allow the vector of menu bar contents to be freed in the next
1282 garbage collection. The frame object itself may not be garbage
1283 collected until much later, because recent_keys and other data
1284 structures can still refer to it. */
1285 f->menu_bar_vector = Qnil;
1287 free_font_driver_list (f);
1288 xfree (f->namebuf);
1289 xfree (f->decode_mode_spec_buffer);
1290 xfree (FRAME_INSERT_COST (f));
1291 xfree (FRAME_DELETEN_COST (f));
1292 xfree (FRAME_INSERTN_COST (f));
1293 xfree (FRAME_DELETE_COST (f));
1294 xfree (FRAME_MESSAGE_BUF (f));
1296 /* Since some events are handled at the interrupt level, we may get
1297 an event for f at any time; if we zero out the frame's terminal
1298 now, then we may trip up the event-handling code. Instead, we'll
1299 promise that the terminal of the frame must be valid until we
1300 have called the window-system-dependent frame destruction
1301 routine. */
1303 if (FRAME_TERMINAL (f)->delete_frame_hook)
1304 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1307 struct terminal *terminal = FRAME_TERMINAL (f);
1308 f->output_data.nothing = 0;
1309 f->terminal = 0; /* Now the frame is dead. */
1311 /* If needed, delete the terminal that this frame was on.
1312 (This must be done after the frame is killed.) */
1313 terminal->reference_count--;
1314 #ifdef USE_GTK
1315 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1316 bug.
1317 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1318 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1319 terminal->reference_count = 1;
1320 #endif /* USE_GTK */
1321 if (terminal->reference_count == 0)
1323 Lisp_Object tmp;
1324 XSETTERMINAL (tmp, terminal);
1326 kb = NULL;
1327 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1329 else
1330 kb = terminal->kboard;
1333 /* If we've deleted the last_nonminibuf_frame, then try to find
1334 another one. */
1335 if (f == last_nonminibuf_frame)
1337 Lisp_Object frames;
1339 last_nonminibuf_frame = 0;
1341 for (frames = Vframe_list;
1342 CONSP (frames);
1343 frames = XCDR (frames))
1345 f = XFRAME (XCAR (frames));
1346 if (!FRAME_MINIBUF_ONLY_P (f))
1348 last_nonminibuf_frame = f;
1349 break;
1354 /* If there's no other frame on the same kboard, get out of
1355 single-kboard state if we're in it for this kboard. */
1356 if (kb != NULL)
1358 Lisp_Object frames;
1359 /* Some frame we found on the same kboard, or nil if there are none. */
1360 Lisp_Object frame_on_same_kboard;
1362 frame_on_same_kboard = Qnil;
1364 for (frames = Vframe_list;
1365 CONSP (frames);
1366 frames = XCDR (frames))
1368 Lisp_Object this;
1369 struct frame *f1;
1371 this = XCAR (frames);
1372 if (!FRAMEP (this))
1373 abort ();
1374 f1 = XFRAME (this);
1376 if (kb == FRAME_KBOARD (f1))
1377 frame_on_same_kboard = this;
1380 if (NILP (frame_on_same_kboard))
1381 not_single_kboard_state (kb);
1385 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1386 find another one. Prefer minibuffer-only frames, but also notice
1387 frames with other windows. */
1388 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1390 Lisp_Object frames;
1392 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1393 Lisp_Object frame_with_minibuf;
1394 /* Some frame we found on the same kboard, or nil if there are none. */
1395 Lisp_Object frame_on_same_kboard;
1397 frame_on_same_kboard = Qnil;
1398 frame_with_minibuf = Qnil;
1400 for (frames = Vframe_list;
1401 CONSP (frames);
1402 frames = XCDR (frames))
1404 Lisp_Object this;
1405 struct frame *f1;
1407 this = XCAR (frames);
1408 if (!FRAMEP (this))
1409 abort ();
1410 f1 = XFRAME (this);
1412 /* Consider only frames on the same kboard
1413 and only those with minibuffers. */
1414 if (kb == FRAME_KBOARD (f1)
1415 && FRAME_HAS_MINIBUF_P (f1))
1417 frame_with_minibuf = this;
1418 if (FRAME_MINIBUF_ONLY_P (f1))
1419 break;
1422 if (kb == FRAME_KBOARD (f1))
1423 frame_on_same_kboard = this;
1426 if (!NILP (frame_on_same_kboard))
1428 /* We know that there must be some frame with a minibuffer out
1429 there. If this were not true, all of the frames present
1430 would have to be minibufferless, which implies that at some
1431 point their minibuffer frames must have been deleted, but
1432 that is prohibited at the top; you can't delete surrogate
1433 minibuffer frames. */
1434 if (NILP (frame_with_minibuf))
1435 abort ();
1437 KVAR (kb, Vdefault_minibuffer_frame) = frame_with_minibuf;
1439 else
1440 /* No frames left on this kboard--say no minibuffer either. */
1441 KVAR (kb, Vdefault_minibuffer_frame) = Qnil;
1444 /* Cause frame titles to update--necessary if we now have just one frame. */
1445 if (!tooltip_frame)
1446 update_mode_lines = 1;
1448 return Qnil;
1451 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1452 doc: /* Delete FRAME, permanently eliminating it from use.
1453 FRAME defaults to the selected frame.
1455 A frame may not be deleted if its minibuffer is used by other frames.
1456 Normally, you may not delete a frame if all other frames are invisible,
1457 but if the second optional argument FORCE is non-nil, you may do so.
1459 This function runs `delete-frame-functions' before actually
1460 deleting the frame, unless the frame is a tooltip.
1461 The functions are run with one argument, the frame to be deleted. */)
1462 (Lisp_Object frame, Lisp_Object force)
1464 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1468 /* Return mouse position in character cell units. */
1470 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1471 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1472 The position is given in character cells, where (0, 0) is the
1473 upper-left corner of the frame, X is the horizontal offset, and Y is
1474 the vertical offset.
1475 If Emacs is running on a mouseless terminal or hasn't been programmed
1476 to read the mouse position, it returns the selected frame for FRAME
1477 and nil for X and Y.
1478 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1479 passing the normal return value to that function as an argument,
1480 and returns whatever that function returns. */)
1481 (void)
1483 FRAME_PTR f;
1484 Lisp_Object lispy_dummy;
1485 enum scroll_bar_part party_dummy;
1486 Lisp_Object x, y, retval;
1487 int col, row;
1488 Time long_dummy;
1489 struct gcpro gcpro1;
1491 f = SELECTED_FRAME ();
1492 x = y = Qnil;
1494 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1495 /* It's okay for the hook to refrain from storing anything. */
1496 if (FRAME_TERMINAL (f)->mouse_position_hook)
1497 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1498 &lispy_dummy, &party_dummy,
1499 &x, &y,
1500 &long_dummy);
1501 if (! NILP (x))
1503 col = XINT (x);
1504 row = XINT (y);
1505 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1506 XSETINT (x, col);
1507 XSETINT (y, row);
1509 #endif
1510 XSETFRAME (lispy_dummy, f);
1511 retval = Fcons (lispy_dummy, Fcons (x, y));
1512 GCPRO1 (retval);
1513 if (!NILP (Vmouse_position_function))
1514 retval = call1 (Vmouse_position_function, retval);
1515 RETURN_UNGCPRO (retval);
1518 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1519 Smouse_pixel_position, 0, 0, 0,
1520 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1521 The position is given in pixel units, where (0, 0) is the
1522 upper-left corner of the frame, X is the horizontal offset, and Y is
1523 the vertical offset.
1524 If Emacs is running on a mouseless terminal or hasn't been programmed
1525 to read the mouse position, it returns the selected frame for FRAME
1526 and nil for X and Y. */)
1527 (void)
1529 FRAME_PTR f;
1530 Lisp_Object lispy_dummy;
1531 enum scroll_bar_part party_dummy;
1532 Lisp_Object x, y;
1533 Time long_dummy;
1535 f = SELECTED_FRAME ();
1536 x = y = Qnil;
1538 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1539 /* It's okay for the hook to refrain from storing anything. */
1540 if (FRAME_TERMINAL (f)->mouse_position_hook)
1541 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1542 &lispy_dummy, &party_dummy,
1543 &x, &y,
1544 &long_dummy);
1545 #endif
1546 XSETFRAME (lispy_dummy, f);
1547 return Fcons (lispy_dummy, Fcons (x, y));
1550 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1551 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1552 Coordinates are relative to the frame, not a window,
1553 so the coordinates of the top left character in the frame
1554 may be nonzero due to left-hand scroll bars or the menu bar.
1556 The position is given in character cells, where (0, 0) is the
1557 upper-left corner of the frame, X is the horizontal offset, and Y is
1558 the vertical offset.
1560 This function is a no-op for an X frame that is not visible.
1561 If you have just created a frame, you must wait for it to become visible
1562 before calling this function on it, like this.
1563 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1564 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1566 CHECK_LIVE_FRAME (frame);
1567 CHECK_TYPE_RANGED_INTEGER (int, x);
1568 CHECK_TYPE_RANGED_INTEGER (int, y);
1570 /* I think this should be done with a hook. */
1571 #ifdef HAVE_WINDOW_SYSTEM
1572 if (FRAME_WINDOW_P (XFRAME (frame)))
1573 /* Warping the mouse will cause enternotify and focus events. */
1574 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1575 #else
1576 #if defined (MSDOS) && defined (HAVE_MOUSE)
1577 if (FRAME_MSDOS_P (XFRAME (frame)))
1579 Fselect_frame (frame, Qnil);
1580 mouse_moveto (XINT (x), XINT (y));
1582 #else
1583 #ifdef HAVE_GPM
1585 Fselect_frame (frame, Qnil);
1586 term_mouse_moveto (XINT (x), XINT (y));
1588 #endif
1589 #endif
1590 #endif
1592 return Qnil;
1595 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1596 Sset_mouse_pixel_position, 3, 3, 0,
1597 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1598 The position is given in pixels, where (0, 0) is the upper-left corner
1599 of the frame, X is the horizontal offset, and Y is the vertical offset.
1601 Note, this is a no-op for an X frame that is not visible.
1602 If you have just created a frame, you must wait for it to become visible
1603 before calling this function on it, like this.
1604 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1605 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1607 CHECK_LIVE_FRAME (frame);
1608 CHECK_TYPE_RANGED_INTEGER (int, x);
1609 CHECK_TYPE_RANGED_INTEGER (int, y);
1611 /* I think this should be done with a hook. */
1612 #ifdef HAVE_WINDOW_SYSTEM
1613 if (FRAME_WINDOW_P (XFRAME (frame)))
1614 /* Warping the mouse will cause enternotify and focus events. */
1615 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1616 #else
1617 #if defined (MSDOS) && defined (HAVE_MOUSE)
1618 if (FRAME_MSDOS_P (XFRAME (frame)))
1620 Fselect_frame (frame, Qnil);
1621 mouse_moveto (XINT (x), XINT (y));
1623 #else
1624 #ifdef HAVE_GPM
1626 Fselect_frame (frame, Qnil);
1627 term_mouse_moveto (XINT (x), XINT (y));
1629 #endif
1630 #endif
1631 #endif
1633 return Qnil;
1636 static void make_frame_visible_1 (Lisp_Object);
1638 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1639 0, 1, "",
1640 doc: /* Make the frame FRAME visible (assuming it is an X window).
1641 If omitted, FRAME defaults to the currently selected frame. */)
1642 (Lisp_Object frame)
1644 if (NILP (frame))
1645 frame = selected_frame;
1647 CHECK_LIVE_FRAME (frame);
1649 /* I think this should be done with a hook. */
1650 #ifdef HAVE_WINDOW_SYSTEM
1651 if (FRAME_WINDOW_P (XFRAME (frame)))
1653 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1654 x_make_frame_visible (XFRAME (frame));
1656 #endif
1658 make_frame_visible_1 (XFRAME (frame)->root_window);
1660 /* Make menu bar update for the Buffers and Frames menus. */
1661 windows_or_buffers_changed++;
1663 return frame;
1666 /* Update the display_time slot of the buffers shown in WINDOW
1667 and all its descendants. */
1669 static void
1670 make_frame_visible_1 (Lisp_Object window)
1672 struct window *w;
1674 for (;!NILP (window); window = w->next)
1676 w = XWINDOW (window);
1678 if (!NILP (w->buffer))
1679 BVAR (XBUFFER (w->buffer), display_time) = Fcurrent_time ();
1681 if (!NILP (w->vchild))
1682 make_frame_visible_1 (w->vchild);
1683 if (!NILP (w->hchild))
1684 make_frame_visible_1 (w->hchild);
1688 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1689 0, 2, "",
1690 doc: /* Make the frame FRAME invisible.
1691 If omitted, FRAME defaults to the currently selected frame.
1692 On graphical displays, invisible frames are not updated and are
1693 usually not displayed at all, even in a window system's \"taskbar\".
1695 Normally you may not make FRAME invisible if all other frames are invisible,
1696 but if the second optional argument FORCE is non-nil, you may do so.
1698 This function has no effect on text terminal frames. Such frames are
1699 always considered visible, whether or not they are currently being
1700 displayed in the terminal. */)
1701 (Lisp_Object frame, Lisp_Object force)
1703 if (NILP (frame))
1704 frame = selected_frame;
1706 CHECK_LIVE_FRAME (frame);
1708 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1709 error ("Attempt to make invisible the sole visible or iconified frame");
1711 /* Don't allow minibuf_window to remain on a deleted frame. */
1712 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1714 struct frame *sf = XFRAME (selected_frame);
1715 Fset_window_buffer (sf->minibuffer_window,
1716 XWINDOW (minibuf_window)->buffer, Qnil);
1717 minibuf_window = sf->minibuffer_window;
1720 /* I think this should be done with a hook. */
1721 #ifdef HAVE_WINDOW_SYSTEM
1722 if (FRAME_WINDOW_P (XFRAME (frame)))
1723 x_make_frame_invisible (XFRAME (frame));
1724 #endif
1726 /* Make menu bar update for the Buffers and Frames menus. */
1727 windows_or_buffers_changed++;
1729 return Qnil;
1732 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1733 0, 1, "",
1734 doc: /* Make the frame FRAME into an icon.
1735 If omitted, FRAME defaults to the currently selected frame. */)
1736 (Lisp_Object frame)
1738 if (NILP (frame))
1739 frame = selected_frame;
1741 CHECK_LIVE_FRAME (frame);
1743 #if 0 /* This isn't logically necessary, and it can do GC. */
1744 /* Don't let the frame remain selected. */
1745 if (EQ (frame, selected_frame))
1746 Fhandle_switch_frame (next_frame (frame, Qt));
1747 #endif
1749 /* Don't allow minibuf_window to remain on a deleted frame. */
1750 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1752 struct frame *sf = XFRAME (selected_frame);
1753 Fset_window_buffer (sf->minibuffer_window,
1754 XWINDOW (minibuf_window)->buffer, Qnil);
1755 minibuf_window = sf->minibuffer_window;
1758 /* I think this should be done with a hook. */
1759 #ifdef HAVE_WINDOW_SYSTEM
1760 if (FRAME_WINDOW_P (XFRAME (frame)))
1761 x_iconify_frame (XFRAME (frame));
1762 #endif
1764 /* Make menu bar update for the Buffers and Frames menus. */
1765 windows_or_buffers_changed++;
1767 return Qnil;
1770 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1771 1, 1, 0,
1772 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1773 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1774 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1775 On graphical displays, invisible frames are not updated and are
1776 usually not displayed at all, even in a window system's \"taskbar\".
1778 If FRAME is a text terminal frame, this always returns t.
1779 Such frames are always considered visible, whether or not they are
1780 currently being displayed on the terminal. */)
1781 (Lisp_Object frame)
1783 CHECK_LIVE_FRAME (frame);
1785 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1787 if (FRAME_VISIBLE_P (XFRAME (frame)))
1788 return Qt;
1789 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1790 return Qicon;
1791 return Qnil;
1794 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1795 0, 0, 0,
1796 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1797 (void)
1799 Lisp_Object tail, frame;
1800 struct frame *f;
1801 Lisp_Object value;
1803 value = Qnil;
1804 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1806 frame = XCAR (tail);
1807 if (!FRAMEP (frame))
1808 continue;
1809 f = XFRAME (frame);
1810 if (FRAME_VISIBLE_P (f))
1811 value = Fcons (frame, value);
1813 return value;
1817 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1818 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1819 If FRAME is invisible or iconified, make it visible.
1820 If you don't specify a frame, the selected frame is used.
1821 If Emacs is displaying on an ordinary terminal or some other device which
1822 doesn't support multiple overlapping frames, this function selects FRAME. */)
1823 (Lisp_Object frame)
1825 struct frame *f;
1826 if (NILP (frame))
1827 frame = selected_frame;
1829 CHECK_LIVE_FRAME (frame);
1831 f = XFRAME (frame);
1833 if (FRAME_TERMCAP_P (f))
1834 /* On a text terminal select FRAME. */
1835 Fselect_frame (frame, Qnil);
1836 else
1837 /* Do like the documentation says. */
1838 Fmake_frame_visible (frame);
1840 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1841 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
1843 return Qnil;
1846 /* Should we have a corresponding function called Flower_Power? */
1847 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1848 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1849 If you don't specify a frame, the selected frame is used.
1850 If Emacs is displaying on an ordinary terminal or some other device which
1851 doesn't support multiple overlapping frames, this function does nothing. */)
1852 (Lisp_Object frame)
1854 struct frame *f;
1856 if (NILP (frame))
1857 frame = selected_frame;
1859 CHECK_LIVE_FRAME (frame);
1861 f = XFRAME (frame);
1863 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1864 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
1866 return Qnil;
1870 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1871 1, 2, 0,
1872 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1873 In other words, switch-frame events caused by events in FRAME will
1874 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1875 FOCUS-FRAME after reading an event typed at FRAME.
1877 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
1878 frame again receives its own keystrokes.
1880 Focus redirection is useful for temporarily redirecting keystrokes to
1881 a surrogate minibuffer frame when a frame doesn't have its own
1882 minibuffer window.
1884 A frame's focus redirection can be changed by `select-frame'. If frame
1885 FOO is selected, and then a different frame BAR is selected, any
1886 frames redirecting their focus to FOO are shifted to redirect their
1887 focus to BAR. This allows focus redirection to work properly when the
1888 user switches from one frame to another using `select-window'.
1890 This means that a frame whose focus is redirected to itself is treated
1891 differently from a frame whose focus is redirected to nil; the former
1892 is affected by `select-frame', while the latter is not.
1894 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1895 (Lisp_Object frame, Lisp_Object focus_frame)
1897 struct frame *f;
1899 /* Note that we don't check for a live frame here. It's reasonable
1900 to redirect the focus of a frame you're about to delete, if you
1901 know what other frame should receive those keystrokes. */
1902 CHECK_FRAME (frame);
1904 if (! NILP (focus_frame))
1905 CHECK_LIVE_FRAME (focus_frame);
1907 f = XFRAME (frame);
1909 f->focus_frame = focus_frame;
1911 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
1912 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
1914 return Qnil;
1918 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1919 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1920 This returns nil if FRAME's focus is not redirected.
1921 See `redirect-frame-focus'. */)
1922 (Lisp_Object frame)
1924 CHECK_LIVE_FRAME (frame);
1926 return FRAME_FOCUS_FRAME (XFRAME (frame));
1931 /* Return the value of frame parameter PROP in frame FRAME. */
1933 #ifdef HAVE_WINDOW_SYSTEM
1934 #if !HAVE_NS
1935 static
1936 #endif
1937 Lisp_Object
1938 get_frame_param (register struct frame *frame, Lisp_Object prop)
1940 register Lisp_Object tem;
1942 tem = Fassq (prop, frame->param_alist);
1943 if (EQ (tem, Qnil))
1944 return tem;
1945 return Fcdr (tem);
1947 #endif
1949 /* Return the buffer-predicate of the selected frame. */
1951 Lisp_Object
1952 frame_buffer_predicate (Lisp_Object frame)
1954 return XFRAME (frame)->buffer_predicate;
1957 /* Return the buffer-list of the selected frame. */
1959 static Lisp_Object
1960 frame_buffer_list (Lisp_Object frame)
1962 return XFRAME (frame)->buffer_list;
1965 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
1967 void
1968 frames_discard_buffer (Lisp_Object buffer)
1970 Lisp_Object frame, tail;
1972 FOR_EACH_FRAME (tail, frame)
1974 XFRAME (frame)->buffer_list
1975 = Fdelq (buffer, XFRAME (frame)->buffer_list);
1976 XFRAME (frame)->buried_buffer_list
1977 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
1981 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1982 If the alist already has an element for PROP, we change it. */
1984 void
1985 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
1987 register Lisp_Object tem;
1989 tem = Fassq (prop, *alistptr);
1990 if (EQ (tem, Qnil))
1991 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1992 else
1993 Fsetcdr (tem, val);
1996 static int
1997 frame_name_fnn_p (char *str, ptrdiff_t len)
1999 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2001 char *p = str + 2;
2002 while ('0' <= *p && *p <= '9')
2003 p++;
2004 if (p == str + len)
2005 return 1;
2007 return 0;
2010 /* Set the name of the terminal frame. Also used by MSDOS frames.
2011 Modeled after x_set_name which is used for WINDOW frames. */
2013 static void
2014 set_term_frame_name (struct frame *f, Lisp_Object name)
2016 f->explicit_name = ! NILP (name);
2018 /* If NAME is nil, set the name to F<num>. */
2019 if (NILP (name))
2021 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2023 /* Check for no change needed in this very common case
2024 before we do any consing. */
2025 if (frame_name_fnn_p (SSDATA (f->name),
2026 SBYTES (f->name)))
2027 return;
2029 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2031 else
2033 CHECK_STRING (name);
2035 /* Don't change the name if it's already NAME. */
2036 if (! NILP (Fstring_equal (name, f->name)))
2037 return;
2039 /* Don't allow the user to set the frame name to F<num>, so it
2040 doesn't clash with the names we generate for terminal frames. */
2041 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2042 error ("Frame names of the form F<num> are usurped by Emacs");
2045 f->name = name;
2046 update_mode_lines = 1;
2049 void
2050 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2052 register Lisp_Object old_alist_elt;
2054 /* The buffer-list parameters are stored in a special place and not
2055 in the alist. All buffers must be live. */
2056 if (EQ (prop, Qbuffer_list))
2058 Lisp_Object list = Qnil;
2059 for (; CONSP (val); val = XCDR (val))
2060 if (!NILP (Fbuffer_live_p (XCAR (val))))
2061 list = Fcons (XCAR (val), list);
2062 f->buffer_list = Fnreverse (list);
2063 return;
2065 if (EQ (prop, Qburied_buffer_list))
2067 Lisp_Object list = Qnil;
2068 for (; CONSP (val); val = XCDR (val))
2069 if (!NILP (Fbuffer_live_p (XCAR (val))))
2070 list = Fcons (XCAR (val), list);
2071 f->buried_buffer_list = Fnreverse (list);
2072 return;
2075 /* If PROP is a symbol which is supposed to have frame-local values,
2076 and it is set up based on this frame, switch to the global
2077 binding. That way, we can create or alter the frame-local binding
2078 without messing up the symbol's status. */
2079 if (SYMBOLP (prop))
2081 struct Lisp_Symbol *sym = XSYMBOL (prop);
2082 start:
2083 switch (sym->redirect)
2085 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2086 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2087 case SYMBOL_LOCALIZED:
2088 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2089 if (blv->frame_local && BLV_FOUND (blv) && XFRAME (blv->where) == f)
2090 swap_in_global_binding (sym);
2091 break;
2093 default: abort ();
2097 /* The tty color needed to be set before the frame's parameter
2098 alist was updated with the new value. This is not true any more,
2099 but we still do this test early on. */
2100 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2101 && f == FRAME_TTY (f)->previous_frame)
2102 /* Force redisplay of this tty. */
2103 FRAME_TTY (f)->previous_frame = NULL;
2105 /* Update the frame parameter alist. */
2106 old_alist_elt = Fassq (prop, f->param_alist);
2107 if (EQ (old_alist_elt, Qnil))
2108 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2109 else
2110 Fsetcdr (old_alist_elt, val);
2112 /* Update some other special parameters in their special places
2113 in addition to the alist. */
2115 if (EQ (prop, Qbuffer_predicate))
2116 f->buffer_predicate = val;
2118 if (! FRAME_WINDOW_P (f))
2120 if (EQ (prop, Qmenu_bar_lines))
2121 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2122 else if (EQ (prop, Qname))
2123 set_term_frame_name (f, val);
2126 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2128 if (! MINI_WINDOW_P (XWINDOW (val)))
2129 error ("Surrogate minibuffer windows must be minibuffer windows");
2131 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2132 && !EQ (val, f->minibuffer_window))
2133 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2135 /* Install the chosen minibuffer window, with proper buffer. */
2136 f->minibuffer_window = val;
2140 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2141 doc: /* Return the parameters-alist of frame FRAME.
2142 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2143 The meaningful PARMs depend on the kind of frame.
2144 If FRAME is omitted, return information on the currently selected frame. */)
2145 (Lisp_Object frame)
2147 Lisp_Object alist;
2148 FRAME_PTR f;
2149 int height, width;
2150 struct gcpro gcpro1;
2152 if (NILP (frame))
2153 frame = selected_frame;
2155 CHECK_FRAME (frame);
2156 f = XFRAME (frame);
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_text_lines ? f->new_text_lines : FRAME_LINES (f));
2209 store_in_alist (&alist, Qheight, make_number (height));
2210 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2211 store_in_alist (&alist, Qwidth, make_number (width));
2212 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2213 store_in_alist (&alist, Qminibuffer,
2214 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2215 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2216 : FRAME_MINIBUF_WINDOW (f)));
2217 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2218 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2219 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2221 /* I think this should be done with a hook. */
2222 #ifdef HAVE_WINDOW_SYSTEM
2223 if (FRAME_WINDOW_P (f))
2224 x_report_frame_params (f, &alist);
2225 else
2226 #endif
2228 /* This ought to be correct in f->param_alist for an X frame. */
2229 Lisp_Object lines;
2230 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2231 store_in_alist (&alist, Qmenu_bar_lines, lines);
2234 UNGCPRO;
2235 return alist;
2239 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2240 doc: /* Return FRAME's value for parameter PARAMETER.
2241 If FRAME is nil, describe the currently selected frame. */)
2242 (Lisp_Object frame, Lisp_Object parameter)
2244 struct frame *f;
2245 Lisp_Object value;
2247 if (NILP (frame))
2248 frame = selected_frame;
2249 else
2250 CHECK_FRAME (frame);
2251 CHECK_SYMBOL (parameter);
2253 f = XFRAME (frame);
2254 value = Qnil;
2256 if (FRAME_LIVE_P (f))
2258 /* Avoid consing in frequent cases. */
2259 if (EQ (parameter, Qname))
2260 value = f->name;
2261 #ifdef HAVE_X_WINDOWS
2262 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2263 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2264 #endif /* HAVE_X_WINDOWS */
2265 else if (EQ (parameter, Qbackground_color)
2266 || EQ (parameter, Qforeground_color))
2268 value = Fassq (parameter, f->param_alist);
2269 if (CONSP (value))
2271 value = XCDR (value);
2272 /* Fframe_parameters puts the actual fg/bg color names,
2273 even if f->param_alist says otherwise. This is
2274 important when param_alist's notion of colors is
2275 "unspecified". We need to do the same here. */
2276 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2278 const char *color_name;
2279 ptrdiff_t csz;
2281 if (EQ (parameter, Qbackground_color))
2283 color_name = SSDATA (value);
2284 csz = SCHARS (value);
2285 if (strncmp (color_name, unspecified_bg, csz) == 0)
2286 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2287 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2288 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2290 else if (EQ (parameter, Qforeground_color))
2292 color_name = SSDATA (value);
2293 csz = SCHARS (value);
2294 if (strncmp (color_name, unspecified_fg, csz) == 0)
2295 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2296 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2297 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2301 else
2302 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2304 else if (EQ (parameter, Qdisplay_type)
2305 || EQ (parameter, Qbackground_mode))
2306 value = Fcdr (Fassq (parameter, f->param_alist));
2307 else
2308 /* FIXME: Avoid this code path at all (as well as code duplication)
2309 by sharing more code with Fframe_parameters. */
2310 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2313 return value;
2317 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2318 Smodify_frame_parameters, 2, 2, 0,
2319 doc: /* Modify the parameters of frame FRAME according to ALIST.
2320 If FRAME is nil, it defaults to the selected frame.
2321 ALIST is an alist of parameters to change and their new values.
2322 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2323 The meaningful PARMs depend on the kind of frame.
2324 Undefined PARMs are ignored, but stored in the frame's parameter list
2325 so that `frame-parameters' will return them.
2327 The value of frame parameter FOO can also be accessed
2328 as a frame-local binding for the variable FOO, if you have
2329 enabled such bindings for that variable with `make-variable-frame-local'.
2330 Note that this functionality is obsolete as of Emacs 22.2, and its
2331 use is not recommended. Explicitly check for a frame-parameter instead. */)
2332 (Lisp_Object frame, Lisp_Object alist)
2334 FRAME_PTR f;
2335 register Lisp_Object tail, prop, val;
2337 if (EQ (frame, Qnil))
2338 frame = selected_frame;
2339 CHECK_LIVE_FRAME (frame);
2340 f = XFRAME (frame);
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 i = 0;
2366 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2368 Lisp_Object elt;
2370 elt = XCAR (tail);
2371 parms[i] = Fcar (elt);
2372 values[i] = Fcdr (elt);
2373 i++;
2376 /* Now process them in reverse of specified order. */
2377 while (--i >= 0)
2379 prop = parms[i];
2380 val = values[i];
2381 store_frame_param (f, prop, val);
2383 if (EQ (prop, Qforeground_color)
2384 || EQ (prop, Qbackground_color))
2385 update_face_from_frame_parameter (f, prop, val);
2388 SAFE_FREE ();
2390 return Qnil;
2393 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2394 0, 1, 0,
2395 doc: /* Height in pixels of a line in the font in frame FRAME.
2396 If FRAME is omitted, the selected frame is used.
2397 For a terminal frame, the value is always 1. */)
2398 (Lisp_Object frame)
2400 struct frame *f;
2402 if (NILP (frame))
2403 frame = selected_frame;
2404 CHECK_FRAME (frame);
2405 f = XFRAME (frame);
2407 #ifdef HAVE_WINDOW_SYSTEM
2408 if (FRAME_WINDOW_P (f))
2409 return make_number (x_char_height (f));
2410 else
2411 #endif
2412 return make_number (1);
2416 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2417 0, 1, 0,
2418 doc: /* Width in pixels of characters in the font in frame FRAME.
2419 If FRAME is omitted, the selected frame is used.
2420 On a graphical screen, the width is the standard width of the default font.
2421 For a terminal screen, the value is always 1. */)
2422 (Lisp_Object frame)
2424 struct frame *f;
2426 if (NILP (frame))
2427 frame = selected_frame;
2428 CHECK_FRAME (frame);
2429 f = XFRAME (frame);
2431 #ifdef HAVE_WINDOW_SYSTEM
2432 if (FRAME_WINDOW_P (f))
2433 return make_number (x_char_width (f));
2434 else
2435 #endif
2436 return make_number (1);
2439 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2440 Sframe_pixel_height, 0, 1, 0,
2441 doc: /* Return a FRAME's height in pixels.
2442 If FRAME is omitted, the selected frame is used. The exact value
2443 of the result depends on the window-system and toolkit in use:
2445 In the Gtk+ version of Emacs, it includes only any window (including
2446 the minibuffer or echo area), mode line, and header line. It does not
2447 include the tool bar or menu bar.
2449 With the Motif or Lucid toolkits, it also includes the tool bar (but
2450 not the menu bar).
2452 In a graphical version with no toolkit, it includes both the tool bar
2453 and menu bar.
2455 For a text terminal, it includes the menu bar. In this case, the
2456 result is really in characters rather than pixels (i.e., is identical
2457 to `frame-height'). */)
2458 (Lisp_Object frame)
2460 struct frame *f;
2462 if (NILP (frame))
2463 frame = selected_frame;
2464 CHECK_FRAME (frame);
2465 f = XFRAME (frame);
2467 #ifdef HAVE_WINDOW_SYSTEM
2468 if (FRAME_WINDOW_P (f))
2469 return make_number (x_pixel_height (f));
2470 else
2471 #endif
2472 return make_number (FRAME_LINES (f));
2475 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2476 Sframe_pixel_width, 0, 1, 0,
2477 doc: /* Return FRAME's width in pixels.
2478 For a terminal frame, the result really gives the width in characters.
2479 If FRAME is omitted, the selected frame is used. */)
2480 (Lisp_Object frame)
2482 struct frame *f;
2484 if (NILP (frame))
2485 frame = selected_frame;
2486 CHECK_FRAME (frame);
2487 f = XFRAME (frame);
2489 #ifdef HAVE_WINDOW_SYSTEM
2490 if (FRAME_WINDOW_P (f))
2491 return make_number (x_pixel_width (f));
2492 else
2493 #endif
2494 return make_number (FRAME_COLS (f));
2497 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2498 Stool_bar_pixel_width, 0, 1, 0,
2499 doc: /* Return width in pixels of FRAME's tool bar.
2500 The result is greater than zero only when the tool bar is on the left
2501 or right side of FRAME. If FRAME is omitted, the selected frame is
2502 used. */)
2503 (Lisp_Object frame)
2505 if (NILP (frame))
2506 frame = selected_frame;
2507 CHECK_FRAME (frame);
2509 #ifdef FRAME_TOOLBAR_WIDTH
2510 if (FRAME_WINDOW_P (XFRAME (frame)))
2511 return make_number (FRAME_TOOLBAR_WIDTH (XFRAME (frame)));
2512 #endif
2513 return make_number (0);
2516 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2517 doc: /* Specify that the frame FRAME has LINES lines.
2518 Optional third arg non-nil means that redisplay should use LINES lines
2519 but that the idea of the actual height of the frame should not be changed. */)
2520 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend)
2522 register struct frame *f;
2524 CHECK_TYPE_RANGED_INTEGER (int, lines);
2525 if (NILP (frame))
2526 frame = selected_frame;
2527 CHECK_LIVE_FRAME (frame);
2528 f = XFRAME (frame);
2530 /* I think this should be done with a hook. */
2531 #ifdef HAVE_WINDOW_SYSTEM
2532 if (FRAME_WINDOW_P (f))
2534 if (XINT (lines) != FRAME_LINES (f))
2535 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2536 do_pending_window_change (0);
2538 else
2539 #endif
2540 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2541 return Qnil;
2544 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2545 doc: /* Specify that the frame FRAME has COLS columns.
2546 Optional third arg non-nil means that redisplay should use COLS columns
2547 but that the idea of the actual width of the frame should not be changed. */)
2548 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2550 register struct frame *f;
2551 CHECK_TYPE_RANGED_INTEGER (int, cols);
2552 if (NILP (frame))
2553 frame = selected_frame;
2554 CHECK_LIVE_FRAME (frame);
2555 f = XFRAME (frame);
2557 /* I think this should be done with a hook. */
2558 #ifdef HAVE_WINDOW_SYSTEM
2559 if (FRAME_WINDOW_P (f))
2561 if (XINT (cols) != FRAME_COLS (f))
2562 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2563 do_pending_window_change (0);
2565 else
2566 #endif
2567 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2568 return Qnil;
2571 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2572 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2573 (Lisp_Object frame, Lisp_Object cols, Lisp_Object rows)
2575 register struct frame *f;
2577 CHECK_LIVE_FRAME (frame);
2578 CHECK_TYPE_RANGED_INTEGER (int, cols);
2579 CHECK_TYPE_RANGED_INTEGER (int, rows);
2580 f = XFRAME (frame);
2582 /* I think this should be done with a hook. */
2583 #ifdef HAVE_WINDOW_SYSTEM
2584 if (FRAME_WINDOW_P (f))
2586 if (XINT (rows) != FRAME_LINES (f)
2587 || XINT (cols) != FRAME_COLS (f)
2588 || f->new_text_lines || f->new_text_cols)
2589 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2590 do_pending_window_change (0);
2592 else
2593 #endif
2594 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2596 return Qnil;
2599 DEFUN ("set-frame-position", Fset_frame_position,
2600 Sset_frame_position, 3, 3, 0,
2601 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2602 This is actually the position of the upper left corner of the frame.
2603 Negative values for XOFFSET or YOFFSET are interpreted relative to
2604 the rightmost or bottommost possible position (that stays within the screen). */)
2605 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2607 register struct frame *f;
2609 CHECK_LIVE_FRAME (frame);
2610 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2611 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2612 f = XFRAME (frame);
2614 /* I think this should be done with a hook. */
2615 #ifdef HAVE_WINDOW_SYSTEM
2616 if (FRAME_WINDOW_P (f))
2617 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2618 #endif
2620 return Qt;
2624 /***********************************************************************
2625 Frame Parameters
2626 ***********************************************************************/
2628 /* Connect the frame-parameter names for X frames
2629 to the ways of passing the parameter values to the window system.
2631 The name of a parameter, as a Lisp symbol,
2632 has an `x-frame-parameter' property which is an integer in Lisp
2633 that is an index in this table. */
2635 struct frame_parm_table {
2636 const char *name;
2637 Lisp_Object *variable;
2640 static const struct frame_parm_table frame_parms[] =
2642 {"auto-raise", &Qauto_raise},
2643 {"auto-lower", &Qauto_lower},
2644 {"background-color", 0},
2645 {"border-color", &Qborder_color},
2646 {"border-width", &Qborder_width},
2647 {"cursor-color", &Qcursor_color},
2648 {"cursor-type", &Qcursor_type},
2649 {"font", 0},
2650 {"foreground-color", 0},
2651 {"icon-name", &Qicon_name},
2652 {"icon-type", &Qicon_type},
2653 {"internal-border-width", &Qinternal_border_width},
2654 {"menu-bar-lines", &Qmenu_bar_lines},
2655 {"mouse-color", &Qmouse_color},
2656 {"name", &Qname},
2657 {"scroll-bar-width", &Qscroll_bar_width},
2658 {"title", &Qtitle},
2659 {"unsplittable", &Qunsplittable},
2660 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2661 {"visibility", &Qvisibility},
2662 {"tool-bar-lines", &Qtool_bar_lines},
2663 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2664 {"scroll-bar-background", &Qscroll_bar_background},
2665 {"screen-gamma", &Qscreen_gamma},
2666 {"line-spacing", &Qline_spacing},
2667 {"left-fringe", &Qleft_fringe},
2668 {"right-fringe", &Qright_fringe},
2669 {"wait-for-wm", &Qwait_for_wm},
2670 {"fullscreen", &Qfullscreen},
2671 {"font-backend", &Qfont_backend},
2672 {"alpha", &Qalpha},
2673 {"sticky", &Qsticky},
2674 {"tool-bar-position", &Qtool_bar_position},
2677 #ifdef WINDOWSNT
2679 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2680 wanted positions of the WM window (not Emacs window).
2681 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2682 window (FRAME_X_WINDOW).
2685 void
2686 x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
2688 int newwidth = FRAME_COLS (f);
2689 int newheight = FRAME_LINES (f);
2690 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2692 *top_pos = f->top_pos;
2693 *left_pos = f->left_pos;
2695 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2697 int ph;
2699 ph = x_display_pixel_height (dpyinfo);
2700 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2701 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2702 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2703 *top_pos = 0;
2706 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2708 int pw;
2710 pw = x_display_pixel_width (dpyinfo);
2711 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2712 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2713 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2714 *left_pos = 0;
2717 *width = newwidth;
2718 *height = newheight;
2721 #endif /* WINDOWSNT */
2723 #ifdef HAVE_WINDOW_SYSTEM
2725 /* Change the parameters of frame F as specified by ALIST.
2726 If a parameter is not specially recognized, do nothing special;
2727 otherwise call the `x_set_...' function for that parameter.
2728 Except for certain geometry properties, always call store_frame_param
2729 to store the new value in the parameter alist. */
2731 void
2732 x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2734 Lisp_Object tail;
2736 /* If both of these parameters are present, it's more efficient to
2737 set them both at once. So we wait until we've looked at the
2738 entire list before we set them. */
2739 int width, height;
2741 /* Same here. */
2742 Lisp_Object left, top;
2744 /* Same with these. */
2745 Lisp_Object icon_left, icon_top;
2747 /* Record in these vectors all the parms specified. */
2748 Lisp_Object *parms;
2749 Lisp_Object *values;
2750 ptrdiff_t i, p;
2751 int left_no_change = 0, top_no_change = 0;
2752 int icon_left_no_change = 0, icon_top_no_change = 0;
2753 int size_changed = 0;
2754 struct gcpro gcpro1, gcpro2;
2756 i = 0;
2757 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2758 i++;
2760 parms = alloca (i * sizeof *parms);
2761 values = alloca (i * sizeof *values);
2763 /* Extract parm names and values into those vectors. */
2765 i = 0;
2766 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2768 Lisp_Object elt;
2770 elt = XCAR (tail);
2771 parms[i] = Fcar (elt);
2772 values[i] = Fcdr (elt);
2773 i++;
2775 /* TAIL and ALIST are not used again below here. */
2776 alist = tail = Qnil;
2778 GCPRO2 (*parms, *values);
2779 gcpro1.nvars = i;
2780 gcpro2.nvars = i;
2782 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2783 because their values appear in VALUES and strings are not valid. */
2784 top = left = Qunbound;
2785 icon_left = icon_top = Qunbound;
2787 /* Provide default values for HEIGHT and WIDTH. */
2788 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2789 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2791 /* Process foreground_color and background_color before anything else.
2792 They are independent of other properties, but other properties (e.g.,
2793 cursor_color) are dependent upon them. */
2794 /* Process default font as well, since fringe widths depends on it. */
2795 for (p = 0; p < i; p++)
2797 Lisp_Object prop, val;
2799 prop = parms[p];
2800 val = values[p];
2801 if (EQ (prop, Qforeground_color)
2802 || EQ (prop, Qbackground_color)
2803 || EQ (prop, Qfont))
2805 register Lisp_Object param_index, old_value;
2807 old_value = get_frame_param (f, prop);
2808 if (NILP (Fequal (val, old_value)))
2810 store_frame_param (f, prop, val);
2812 param_index = Fget (prop, Qx_frame_parameter);
2813 if (NATNUMP (param_index)
2814 && (XFASTINT (param_index)
2815 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2816 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2817 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2822 /* Now process them in reverse of specified order. */
2823 while (i-- != 0)
2825 Lisp_Object prop, val;
2827 prop = parms[i];
2828 val = values[i];
2830 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
2832 size_changed = 1;
2833 width = XFASTINT (val);
2835 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
2837 size_changed = 1;
2838 height = XFASTINT (val);
2840 else if (EQ (prop, Qtop))
2841 top = val;
2842 else if (EQ (prop, Qleft))
2843 left = val;
2844 else if (EQ (prop, Qicon_top))
2845 icon_top = val;
2846 else if (EQ (prop, Qicon_left))
2847 icon_left = val;
2848 else if (EQ (prop, Qforeground_color)
2849 || EQ (prop, Qbackground_color)
2850 || EQ (prop, Qfont))
2851 /* Processed above. */
2852 continue;
2853 else
2855 register Lisp_Object param_index, old_value;
2857 old_value = get_frame_param (f, prop);
2859 store_frame_param (f, prop, val);
2861 param_index = Fget (prop, Qx_frame_parameter);
2862 if (NATNUMP (param_index)
2863 && (XFASTINT (param_index)
2864 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2865 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2866 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2870 /* Don't die if just one of these was set. */
2871 if (EQ (left, Qunbound))
2873 left_no_change = 1;
2874 if (f->left_pos < 0)
2875 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
2876 else
2877 XSETINT (left, f->left_pos);
2879 if (EQ (top, Qunbound))
2881 top_no_change = 1;
2882 if (f->top_pos < 0)
2883 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
2884 else
2885 XSETINT (top, f->top_pos);
2888 /* If one of the icon positions was not set, preserve or default it. */
2889 if (! TYPE_RANGED_INTEGERP (int, icon_left))
2891 icon_left_no_change = 1;
2892 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2893 if (NILP (icon_left))
2894 XSETINT (icon_left, 0);
2896 if (! TYPE_RANGED_INTEGERP (int, icon_top))
2898 icon_top_no_change = 1;
2899 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2900 if (NILP (icon_top))
2901 XSETINT (icon_top, 0);
2904 /* Don't set these parameters unless they've been explicitly
2905 specified. The window might be mapped or resized while we're in
2906 this function, and we don't want to override that unless the lisp
2907 code has asked for it.
2909 Don't set these parameters unless they actually differ from the
2910 window's current parameters; the window may not actually exist
2911 yet. */
2913 Lisp_Object frame;
2915 check_frame_size (f, &height, &width);
2917 XSETFRAME (frame, f);
2919 if (size_changed
2920 && (width != FRAME_COLS (f)
2921 || height != FRAME_LINES (f)
2922 || f->new_text_lines || f->new_text_cols))
2923 Fset_frame_size (frame, make_number (width), make_number (height));
2925 if ((!NILP (left) || !NILP (top))
2926 && ! (left_no_change && top_no_change)
2927 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2928 && NUMBERP (top) && XINT (top) == f->top_pos))
2930 int leftpos = 0;
2931 int toppos = 0;
2933 /* Record the signs. */
2934 f->size_hint_flags &= ~ (XNegative | YNegative);
2935 if (EQ (left, Qminus))
2936 f->size_hint_flags |= XNegative;
2937 else if (TYPE_RANGED_INTEGERP (int, left))
2939 leftpos = XINT (left);
2940 if (leftpos < 0)
2941 f->size_hint_flags |= XNegative;
2943 else if (CONSP (left) && EQ (XCAR (left), Qminus)
2944 && CONSP (XCDR (left))
2945 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
2947 leftpos = - XINT (XCAR (XCDR (left)));
2948 f->size_hint_flags |= XNegative;
2950 else if (CONSP (left) && EQ (XCAR (left), Qplus)
2951 && CONSP (XCDR (left))
2952 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
2954 leftpos = XINT (XCAR (XCDR (left)));
2957 if (EQ (top, Qminus))
2958 f->size_hint_flags |= YNegative;
2959 else if (TYPE_RANGED_INTEGERP (int, top))
2961 toppos = XINT (top);
2962 if (toppos < 0)
2963 f->size_hint_flags |= YNegative;
2965 else if (CONSP (top) && EQ (XCAR (top), Qminus)
2966 && CONSP (XCDR (top))
2967 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
2969 toppos = - XINT (XCAR (XCDR (top)));
2970 f->size_hint_flags |= YNegative;
2972 else if (CONSP (top) && EQ (XCAR (top), Qplus)
2973 && CONSP (XCDR (top))
2974 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
2976 toppos = XINT (XCAR (XCDR (top)));
2980 /* Store the numeric value of the position. */
2981 f->top_pos = toppos;
2982 f->left_pos = leftpos;
2984 f->win_gravity = NorthWestGravity;
2986 /* Actually set that position, and convert to absolute. */
2987 x_set_offset (f, leftpos, toppos, -1);
2990 if ((!NILP (icon_left) || !NILP (icon_top))
2991 && ! (icon_left_no_change && icon_top_no_change))
2992 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
2995 UNGCPRO;
2999 /* Insert a description of internally-recorded parameters of frame X
3000 into the parameter alist *ALISTPTR that is to be given to the user.
3001 Only parameters that are specific to the X window system
3002 and whose values are not correctly recorded in the frame's
3003 param_alist need to be considered here. */
3005 void
3006 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3008 char buf[16];
3009 Lisp_Object tem;
3010 unsigned long w;
3012 /* Represent negative positions (off the top or left screen edge)
3013 in a way that Fmodify_frame_parameters will understand correctly. */
3014 XSETINT (tem, f->left_pos);
3015 if (f->left_pos >= 0)
3016 store_in_alist (alistptr, Qleft, tem);
3017 else
3018 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3020 XSETINT (tem, f->top_pos);
3021 if (f->top_pos >= 0)
3022 store_in_alist (alistptr, Qtop, tem);
3023 else
3024 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3026 store_in_alist (alistptr, Qborder_width,
3027 make_number (f->border_width));
3028 store_in_alist (alistptr, Qinternal_border_width,
3029 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3030 store_in_alist (alistptr, Qleft_fringe,
3031 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3032 store_in_alist (alistptr, Qright_fringe,
3033 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3034 store_in_alist (alistptr, Qscroll_bar_width,
3035 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3036 ? make_number (0)
3037 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3038 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3039 /* nil means "use default width"
3040 for non-toolkit scroll bar.
3041 ruler-mode.el depends on this. */
3042 : Qnil));
3043 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3044 MS-Windows it returns a value whose type is HANDLE, which is
3045 actually a pointer. Explicit casting avoids compiler
3046 warnings. */
3047 w = (unsigned long) FRAME_X_WINDOW (f);
3048 store_in_alist (alistptr, Qwindow_id,
3049 make_formatted_string (buf, "%lu", w));
3050 #ifdef HAVE_X_WINDOWS
3051 #ifdef USE_X_TOOLKIT
3052 /* Tooltip frame may not have this widget. */
3053 if (FRAME_X_OUTPUT (f)->widget)
3054 #endif
3055 w = (unsigned long) FRAME_OUTER_WINDOW (f);
3056 store_in_alist (alistptr, Qouter_window_id,
3057 make_formatted_string (buf, "%lu", w));
3058 #endif
3059 store_in_alist (alistptr, Qicon_name, f->icon_name);
3060 FRAME_SAMPLE_VISIBILITY (f);
3061 store_in_alist (alistptr, Qvisibility,
3062 (FRAME_VISIBLE_P (f) ? Qt
3063 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3064 store_in_alist (alistptr, Qdisplay,
3065 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3067 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3068 tem = Qnil;
3069 else
3070 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3071 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3072 store_in_alist (alistptr, Qparent_id, tem);
3073 store_in_alist (alistptr, Qtool_bar_position, f->tool_bar_position);
3077 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3078 the previous value of that parameter, NEW_VALUE is the new value. */
3080 void
3081 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3083 if (NILP (new_value))
3084 f->want_fullscreen = FULLSCREEN_NONE;
3085 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3086 f->want_fullscreen = FULLSCREEN_BOTH;
3087 else if (EQ (new_value, Qfullwidth))
3088 f->want_fullscreen = FULLSCREEN_WIDTH;
3089 else if (EQ (new_value, Qfullheight))
3090 f->want_fullscreen = FULLSCREEN_HEIGHT;
3091 else if (EQ (new_value, Qmaximized))
3092 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3094 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3095 FRAME_TERMINAL (f)->fullscreen_hook (f);
3099 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3100 the previous value of that parameter, NEW_VALUE is the new value. */
3102 void
3103 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3105 if (NILP (new_value))
3106 f->extra_line_spacing = 0;
3107 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3108 f->extra_line_spacing = XFASTINT (new_value);
3109 else
3110 signal_error ("Invalid line-spacing", new_value);
3111 if (FRAME_VISIBLE_P (f))
3112 redraw_frame (f);
3116 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3117 the previous value of that parameter, NEW_VALUE is the new value. */
3119 void
3120 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3122 Lisp_Object bgcolor;
3124 if (NILP (new_value))
3125 f->gamma = 0;
3126 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3127 /* The value 0.4545 is the normal viewing gamma. */
3128 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3129 else
3130 signal_error ("Invalid screen-gamma", new_value);
3132 /* Apply the new gamma value to the frame background. */
3133 bgcolor = Fassq (Qbackground_color, f->param_alist);
3134 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3136 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3137 if (NATNUMP (parm_index)
3138 && (XFASTINT (parm_index)
3139 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3140 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3141 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3142 (f, bgcolor, Qnil);
3145 Fclear_face_cache (Qnil);
3149 void
3150 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3152 Lisp_Object font_object;
3153 int fontset = -1;
3154 #ifdef HAVE_X_WINDOWS
3155 Lisp_Object font_param = arg;
3156 #endif
3158 /* Set the frame parameter back to the old value because we may
3159 fail to use ARG as the new parameter value. */
3160 store_frame_param (f, Qfont, oldval);
3162 /* ARG is a fontset name, a font name, a cons of fontset name and a
3163 font object, or a font object. In the last case, this function
3164 never fail. */
3165 if (STRINGP (arg))
3167 fontset = fs_query_fontset (arg, 0);
3168 if (fontset < 0)
3170 font_object = font_open_by_name (f, arg);
3171 if (NILP (font_object))
3172 error ("Font `%s' is not defined", SSDATA (arg));
3173 arg = AREF (font_object, FONT_NAME_INDEX);
3175 else if (fontset > 0)
3177 font_object = font_open_by_name (f, fontset_ascii (fontset));
3178 if (NILP (font_object))
3179 error ("Font `%s' is not defined", SDATA (arg));
3180 arg = AREF (font_object, FONT_NAME_INDEX);
3182 else
3183 error ("The default fontset can't be used for a frame font");
3185 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3187 /* This is the case that the ASCII font of F's fontset XCAR
3188 (arg) is changed to the font XCDR (arg) by
3189 `set-fontset-font'. */
3190 fontset = fs_query_fontset (XCAR (arg), 0);
3191 if (fontset < 0)
3192 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3193 font_object = XCDR (arg);
3194 arg = AREF (font_object, FONT_NAME_INDEX);
3195 #ifdef HAVE_X_WINDOWS
3196 font_param = Ffont_get (font_object, QCname);
3197 #endif
3199 else if (FONT_OBJECT_P (arg))
3201 font_object = arg;
3202 #ifdef HAVE_X_WINDOWS
3203 font_param = Ffont_get (font_object, QCname);
3204 #endif
3205 /* This is to store the XLFD font name in the frame parameter for
3206 backward compatibility. We should store the font-object
3207 itself in the future. */
3208 arg = AREF (font_object, FONT_NAME_INDEX);
3209 fontset = FRAME_FONTSET (f);
3210 /* Check if we can use the current fontset. If not, set FONTSET
3211 to -1 to generate a new fontset from FONT-OBJECT. */
3212 if (fontset >= 0)
3214 Lisp_Object ascii_font = fontset_ascii (fontset);
3215 Lisp_Object spec = font_spec_from_name (ascii_font);
3217 if (! font_match_p (spec, font_object))
3218 fontset = -1;
3221 else
3222 signal_error ("Invalid font", arg);
3224 if (! NILP (Fequal (font_object, oldval)))
3225 return;
3227 x_new_font (f, font_object, fontset);
3228 store_frame_param (f, Qfont, arg);
3229 #ifdef HAVE_X_WINDOWS
3230 store_frame_param (f, Qfont_param, font_param);
3231 #endif
3232 /* Recalculate toolbar height. */
3233 f->n_tool_bar_rows = 0;
3234 /* Ensure we redraw it. */
3235 clear_current_matrices (f);
3237 recompute_basic_faces (f);
3239 do_pending_window_change (0);
3241 /* We used to call face-set-after-frame-default here, but it leads to
3242 recursive calls (since that function can set the `default' face's
3243 font which in turns changes the frame's `font' parameter).
3244 Also I don't know what this call is meant to do, but it seems the
3245 wrong way to do it anyway (it does a lot more work than what seems
3246 reasonable in response to a change to `font'). */
3250 void
3251 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3253 if (! NILP (new_value)
3254 && !CONSP (new_value))
3256 char *p0, *p1;
3258 CHECK_STRING (new_value);
3259 p0 = p1 = SSDATA (new_value);
3260 new_value = Qnil;
3261 while (*p0)
3263 while (*p1 && ! isspace (*p1) && *p1 != ',') p1++;
3264 if (p0 < p1)
3265 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3266 new_value);
3267 if (*p1)
3269 int c;
3271 while ((c = *++p1) && isspace (c));
3273 p0 = p1;
3275 new_value = Fnreverse (new_value);
3278 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3279 return;
3281 if (FRAME_FONT (f))
3282 free_all_realized_faces (Qnil);
3284 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3285 if (NILP (new_value))
3287 if (NILP (old_value))
3288 error ("No font backend available");
3289 font_update_drivers (f, old_value);
3290 error ("None of specified font backends are available");
3292 store_frame_param (f, Qfont_backend, new_value);
3294 if (FRAME_FONT (f))
3296 Lisp_Object frame;
3298 XSETFRAME (frame, f);
3299 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3300 ++face_change_count;
3301 ++windows_or_buffers_changed;
3306 void
3307 x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3309 compute_fringe_widths (f, 1);
3310 #ifdef HAVE_X_WINDOWS
3311 /* Must adjust this so window managers report correct number of columns. */
3312 if (FRAME_X_WINDOW (f) != 0)
3313 x_wm_set_size_hint (f, 0, 0);
3314 #endif
3317 void
3318 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3320 CHECK_TYPE_RANGED_INTEGER (int, arg);
3322 if (XINT (arg) == f->border_width)
3323 return;
3325 if (FRAME_X_WINDOW (f) != 0)
3326 error ("Cannot change the border width of a frame");
3328 f->border_width = XINT (arg);
3331 void
3332 x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3334 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3336 CHECK_TYPE_RANGED_INTEGER (int, arg);
3337 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3338 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3339 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3341 #ifdef USE_X_TOOLKIT
3342 if (FRAME_X_OUTPUT (f)->edit_widget)
3343 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3344 #endif
3346 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3347 return;
3349 if (FRAME_X_WINDOW (f) != 0)
3351 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3352 SET_FRAME_GARBAGED (f);
3353 do_pending_window_change (0);
3355 else
3356 SET_FRAME_GARBAGED (f);
3359 void
3360 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3362 Lisp_Object frame;
3363 XSETFRAME (frame, f);
3365 if (NILP (value))
3366 Fmake_frame_invisible (frame, Qt);
3367 else if (EQ (value, Qicon))
3368 Ficonify_frame (frame);
3369 else
3370 Fmake_frame_visible (frame);
3373 void
3374 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3376 f->auto_raise = !EQ (Qnil, arg);
3379 void
3380 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3382 f->auto_lower = !EQ (Qnil, arg);
3385 void
3386 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3388 f->no_split = !NILP (arg);
3391 void
3392 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3394 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3395 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3396 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3397 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3399 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3400 = (NILP (arg)
3401 ? vertical_scroll_bar_none
3402 : EQ (Qleft, arg)
3403 ? vertical_scroll_bar_left
3404 : EQ (Qright, arg)
3405 ? vertical_scroll_bar_right
3406 : EQ (Qleft, Vdefault_frame_scroll_bars)
3407 ? vertical_scroll_bar_left
3408 : EQ (Qright, Vdefault_frame_scroll_bars)
3409 ? vertical_scroll_bar_right
3410 : vertical_scroll_bar_none);
3412 /* We set this parameter before creating the X window for the
3413 frame, so we can get the geometry right from the start.
3414 However, if the window hasn't been created yet, we shouldn't
3415 call x_set_window_size. */
3416 if (FRAME_X_WINDOW (f))
3417 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3418 do_pending_window_change (0);
3422 void
3423 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3425 int wid = FRAME_COLUMN_WIDTH (f);
3427 if (NILP (arg))
3429 x_set_scroll_bar_default_width (f);
3431 if (FRAME_X_WINDOW (f))
3432 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3433 do_pending_window_change (0);
3435 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3436 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3438 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3439 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3441 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3442 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3443 if (FRAME_X_WINDOW (f))
3444 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3445 do_pending_window_change (0);
3448 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3449 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3450 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3455 /* Return non-nil if frame F wants a bitmap icon. */
3457 Lisp_Object
3458 x_icon_type (FRAME_PTR f)
3460 Lisp_Object tem;
3462 tem = assq_no_quit (Qicon_type, f->param_alist);
3463 if (CONSP (tem))
3464 return XCDR (tem);
3465 else
3466 return Qnil;
3469 void
3470 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3472 double alpha = 1.0;
3473 double newval[2];
3474 int i;
3475 Lisp_Object item;
3477 for (i = 0; i < 2; i++)
3479 newval[i] = 1.0;
3480 if (CONSP (arg))
3482 item = CAR (arg);
3483 arg = CDR (arg);
3485 else
3486 item = arg;
3488 if (NILP (item))
3489 alpha = - 1.0;
3490 else if (FLOATP (item))
3492 alpha = XFLOAT_DATA (item);
3493 if (alpha < 0.0 || 1.0 < alpha)
3494 args_out_of_range (make_float (0.0), make_float (1.0));
3496 else if (INTEGERP (item))
3498 EMACS_INT ialpha = XINT (item);
3499 if (ialpha < 0 || 100 < ialpha)
3500 args_out_of_range (make_number (0), make_number (100));
3501 else
3502 alpha = ialpha / 100.0;
3504 else
3505 wrong_type_argument (Qnumberp, item);
3506 newval[i] = alpha;
3509 for (i = 0; i < 2; i++)
3510 f->alpha[i] = newval[i];
3512 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3513 BLOCK_INPUT;
3514 x_set_frame_alpha (f);
3515 UNBLOCK_INPUT;
3516 #endif
3518 return;
3522 /* Subroutines of creating an X frame. */
3524 /* Make sure that Vx_resource_name is set to a reasonable value.
3525 Fix it up, or set it to `emacs' if it is too hopeless. */
3527 void
3528 validate_x_resource_name (void)
3530 ptrdiff_t len = 0;
3531 /* Number of valid characters in the resource name. */
3532 ptrdiff_t good_count = 0;
3533 /* Number of invalid characters in the resource name. */
3534 ptrdiff_t bad_count = 0;
3535 Lisp_Object new;
3536 ptrdiff_t i;
3538 if (!STRINGP (Vx_resource_class))
3539 Vx_resource_class = build_string (EMACS_CLASS);
3541 if (STRINGP (Vx_resource_name))
3543 unsigned char *p = SDATA (Vx_resource_name);
3545 len = SBYTES (Vx_resource_name);
3547 /* Only letters, digits, - and _ are valid in resource names.
3548 Count the valid characters and count the invalid ones. */
3549 for (i = 0; i < len; i++)
3551 int c = p[i];
3552 if (! ((c >= 'a' && c <= 'z')
3553 || (c >= 'A' && c <= 'Z')
3554 || (c >= '0' && c <= '9')
3555 || c == '-' || c == '_'))
3556 bad_count++;
3557 else
3558 good_count++;
3561 else
3562 /* Not a string => completely invalid. */
3563 bad_count = 5, good_count = 0;
3565 /* If name is valid already, return. */
3566 if (bad_count == 0)
3567 return;
3569 /* If name is entirely invalid, or nearly so, or is so implausibly
3570 large that alloca might not work, use `emacs'. */
3571 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3573 Vx_resource_name = build_string ("emacs");
3574 return;
3577 /* Name is partly valid. Copy it and replace the invalid characters
3578 with underscores. */
3580 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3582 for (i = 0; i < len; i++)
3584 int c = SREF (new, i);
3585 if (! ((c >= 'a' && c <= 'z')
3586 || (c >= 'A' && c <= 'Z')
3587 || (c >= '0' && c <= '9')
3588 || c == '-' || c == '_'))
3589 SSET (new, i, '_');
3594 extern char *x_get_string_resource (XrmDatabase, const char *, const char *);
3595 extern Display_Info *check_x_display_info (Lisp_Object);
3598 /* Get specified attribute from resource database RDB.
3599 See Fx_get_resource below for other parameters. */
3601 static Lisp_Object
3602 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3604 register char *value;
3605 char *name_key;
3606 char *class_key;
3608 CHECK_STRING (attribute);
3609 CHECK_STRING (class);
3611 if (!NILP (component))
3612 CHECK_STRING (component);
3613 if (!NILP (subclass))
3614 CHECK_STRING (subclass);
3615 if (NILP (component) != NILP (subclass))
3616 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3618 validate_x_resource_name ();
3620 /* Allocate space for the components, the dots which separate them,
3621 and the final '\0'. Make them big enough for the worst case. */
3622 name_key = alloca (SBYTES (Vx_resource_name)
3623 + (STRINGP (component)
3624 ? SBYTES (component) : 0)
3625 + SBYTES (attribute)
3626 + 3);
3628 class_key = alloca (SBYTES (Vx_resource_class)
3629 + SBYTES (class)
3630 + (STRINGP (subclass)
3631 ? SBYTES (subclass) : 0)
3632 + 3);
3634 /* Start with emacs.FRAMENAME for the name (the specific one)
3635 and with `Emacs' for the class key (the general one). */
3636 strcpy (name_key, SSDATA (Vx_resource_name));
3637 strcpy (class_key, SSDATA (Vx_resource_class));
3639 strcat (class_key, ".");
3640 strcat (class_key, SSDATA (class));
3642 if (!NILP (component))
3644 strcat (class_key, ".");
3645 strcat (class_key, SSDATA (subclass));
3647 strcat (name_key, ".");
3648 strcat (name_key, SSDATA (component));
3651 strcat (name_key, ".");
3652 strcat (name_key, SSDATA (attribute));
3654 value = x_get_string_resource (rdb, name_key, class_key);
3656 if (value != (char *) 0 && *value)
3657 return build_string (value);
3658 else
3659 return Qnil;
3663 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3664 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3665 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3666 class, where INSTANCE is the name under which Emacs was invoked, or
3667 the name specified by the `-name' or `-rn' command-line arguments.
3669 The optional arguments COMPONENT and SUBCLASS add to the key and the
3670 class, respectively. You must specify both of them or neither.
3671 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3672 and the class is `Emacs.CLASS.SUBCLASS'. */)
3673 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3675 #ifdef HAVE_X_WINDOWS
3676 check_x ();
3677 #endif
3679 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3680 attribute, class, component, subclass);
3683 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3685 Lisp_Object
3686 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3688 return xrdb_get_resource (dpyinfo->xrdb,
3689 attribute, class, component, subclass);
3692 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3693 /* Used when C code wants a resource value. */
3694 /* Called from oldXMenu/Create.c. */
3695 char *
3696 x_get_resource_string (const char *attribute, const char *class)
3698 char *name_key;
3699 char *class_key;
3700 char *result;
3701 struct frame *sf = SELECTED_FRAME ();
3702 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
3703 USE_SAFE_ALLOCA;
3705 /* Allocate space for the components, the dots which separate them,
3706 and the final '\0'. */
3707 SAFE_ALLOCA (name_key, char *, invocation_namelen + strlen (attribute) + 2);
3708 class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2);
3710 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
3711 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3713 result = x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3714 name_key, class_key);
3715 SAFE_FREE ();
3716 return result;
3718 #endif
3720 /* Return the value of parameter PARAM.
3722 First search ALIST, then Vdefault_frame_alist, then the X defaults
3723 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3725 Convert the resource to the type specified by desired_type.
3727 If no default is specified, return Qunbound. If you call
3728 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3729 and don't let it get stored in any Lisp-visible variables! */
3731 Lisp_Object
3732 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
3733 const char *attribute, const char *class, enum resource_types type)
3735 register Lisp_Object tem;
3737 tem = Fassq (param, alist);
3739 if (!NILP (tem))
3741 /* If we find this parm in ALIST, clear it out
3742 so that it won't be "left over" at the end. */
3743 Lisp_Object tail;
3744 XSETCAR (tem, Qnil);
3745 /* In case the parameter appears more than once in the alist,
3746 clear it out. */
3747 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3748 if (CONSP (XCAR (tail))
3749 && EQ (XCAR (XCAR (tail)), param))
3750 XSETCAR (XCAR (tail), Qnil);
3752 else
3753 tem = Fassq (param, Vdefault_frame_alist);
3755 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3756 look in the X resources. */
3757 if (EQ (tem, Qnil))
3759 if (attribute && dpyinfo)
3761 tem = display_x_get_resource (dpyinfo,
3762 build_string (attribute),
3763 build_string (class),
3764 Qnil, Qnil);
3766 if (NILP (tem))
3767 return Qunbound;
3769 switch (type)
3771 case RES_TYPE_NUMBER:
3772 return make_number (atoi (SSDATA (tem)));
3774 case RES_TYPE_BOOLEAN_NUMBER:
3775 if (!strcmp (SSDATA (tem), "on")
3776 || !strcmp (SSDATA (tem), "true"))
3777 return make_number (1);
3778 return make_number (atoi (SSDATA (tem)));
3779 break;
3781 case RES_TYPE_FLOAT:
3782 return make_float (atof (SSDATA (tem)));
3784 case RES_TYPE_BOOLEAN:
3785 tem = Fdowncase (tem);
3786 if (!strcmp (SSDATA (tem), "on")
3787 #ifdef HAVE_NS
3788 || !strcmp (SSDATA (tem), "yes")
3789 #endif
3790 || !strcmp (SSDATA (tem), "true"))
3791 return Qt;
3792 else
3793 return Qnil;
3795 case RES_TYPE_STRING:
3796 return tem;
3798 case RES_TYPE_SYMBOL:
3799 /* As a special case, we map the values `true' and `on'
3800 to Qt, and `false' and `off' to Qnil. */
3802 Lisp_Object lower;
3803 lower = Fdowncase (tem);
3804 if (!strcmp (SSDATA (lower), "on")
3805 #ifdef HAVE_NS
3806 || !strcmp (SSDATA (lower), "yes")
3807 #endif
3808 || !strcmp (SSDATA (lower), "true"))
3809 return Qt;
3810 else if (!strcmp (SSDATA (lower), "off")
3811 #ifdef HAVE_NS
3812 || !strcmp (SSDATA (lower), "no")
3813 #endif
3814 || !strcmp (SSDATA (lower), "false"))
3815 return Qnil;
3816 else
3817 return Fintern (tem, Qnil);
3820 default:
3821 abort ();
3824 else
3825 return Qunbound;
3827 return Fcdr (tem);
3830 static Lisp_Object
3831 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
3832 const char *attribute, const char *class,
3833 enum resource_types type)
3835 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3836 alist, param, attribute, class, type);
3839 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3841 Lisp_Object
3842 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
3843 Lisp_Object param,
3844 const char *attribute, const char *class,
3845 enum resource_types type)
3847 Lisp_Object value;
3849 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3850 attribute, class, type);
3851 if (! NILP (value) && ! EQ (value, Qunbound))
3852 store_frame_param (f, param, value);
3854 return value;
3858 /* Record in frame F the specified or default value according to ALIST
3859 of the parameter named PROP (a Lisp symbol).
3860 If no value is specified for PROP, look for an X default for XPROP
3861 on the frame named NAME.
3862 If that is not found either, use the value DEFLT. */
3864 Lisp_Object
3865 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
3866 Lisp_Object deflt, const char *xprop, const char *xclass,
3867 enum resource_types type)
3869 Lisp_Object tem;
3871 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3872 if (EQ (tem, Qunbound))
3873 tem = deflt;
3874 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3875 return tem;
3881 /* NS used to define x-parse-geometry in ns-win.el, but that confused
3882 make-docfile: the documentation string in ns-win.el was used for
3883 x-parse-geometry even in non-NS builds.
3885 With two definitions of x-parse-geometry in this file, various
3886 things still get confused (eg M-x apropos documentation), so that
3887 it is best if the two definitions just share the same doc-string.
3889 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3890 doc: /* Parse a display geometry string STRING.
3891 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3892 The properties returned may include `top', `left', `height', and `width'.
3893 For X, the value of `left' or `top' may be an integer,
3894 or a list (+ N) meaning N pixels relative to top/left corner,
3895 or a list (- N) meaning -N pixels relative to bottom/right corner.
3896 On Nextstep, this just calls `ns-parse-geometry'. */)
3897 (Lisp_Object string)
3899 #ifdef HAVE_NS
3900 return call1 (Qns_parse_geometry, string);
3901 #else
3902 int geometry, x, y;
3903 unsigned int width, height;
3904 Lisp_Object result;
3906 CHECK_STRING (string);
3908 geometry = XParseGeometry (SSDATA (string),
3909 &x, &y, &width, &height);
3910 result = Qnil;
3911 if (geometry & XValue)
3913 Lisp_Object element;
3915 if (x >= 0 && (geometry & XNegative))
3916 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3917 else if (x < 0 && ! (geometry & XNegative))
3918 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3919 else
3920 element = Fcons (Qleft, make_number (x));
3921 result = Fcons (element, result);
3924 if (geometry & YValue)
3926 Lisp_Object element;
3928 if (y >= 0 && (geometry & YNegative))
3929 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3930 else if (y < 0 && ! (geometry & YNegative))
3931 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3932 else
3933 element = Fcons (Qtop, make_number (y));
3934 result = Fcons (element, result);
3937 if (geometry & WidthValue)
3938 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3939 if (geometry & HeightValue)
3940 result = Fcons (Fcons (Qheight, make_number (height)), result);
3942 return result;
3943 #endif /* HAVE_NS */
3947 /* Calculate the desired size and position of frame F.
3948 Return the flags saying which aspects were specified.
3950 Also set the win_gravity and size_hint_flags of F.
3952 Adjust height for toolbar if TOOLBAR_P is 1.
3954 This function does not make the coordinates positive. */
3956 #define DEFAULT_ROWS 35
3957 #define DEFAULT_COLS 80
3960 x_figure_window_size (struct frame *f, Lisp_Object parms, int toolbar_p)
3962 register Lisp_Object tem0, tem1, tem2;
3963 long window_prompting = 0;
3964 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3966 /* Default values if we fall through.
3967 Actually, if that happens we should get
3968 window manager prompting. */
3969 SET_FRAME_COLS (f, DEFAULT_COLS);
3970 FRAME_LINES (f) = DEFAULT_ROWS;
3971 /* Window managers expect that if program-specified
3972 positions are not (0,0), they're intentional, not defaults. */
3973 f->top_pos = 0;
3974 f->left_pos = 0;
3976 /* Ensure that old new_text_cols and new_text_lines will not override the
3977 values set here. */
3978 /* ++KFS: This was specific to W32, but seems ok for all platforms */
3979 f->new_text_cols = f->new_text_lines = 0;
3981 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
3982 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
3983 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
3984 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3986 if (!EQ (tem0, Qunbound))
3988 CHECK_NUMBER (tem0);
3989 if (! (0 <= XINT (tem0) && XINT (tem0) <= INT_MAX))
3990 xsignal1 (Qargs_out_of_range, tem0);
3991 FRAME_LINES (f) = XINT (tem0);
3993 if (!EQ (tem1, Qunbound))
3995 CHECK_NUMBER (tem1);
3996 if (! (0 <= XINT (tem1) && XINT (tem1) <= INT_MAX))
3997 xsignal1 (Qargs_out_of_range, tem1);
3998 SET_FRAME_COLS (f, XINT (tem1));
4000 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4001 window_prompting |= USSize;
4002 else
4003 window_prompting |= PSize;
4006 f->scroll_bar_actual_width
4007 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4009 /* This used to be done _before_ calling x_figure_window_size, but
4010 since the height is reset here, this was really a no-op. I
4011 assume that moving it here does what Gerd intended (although he
4012 no longer can remember what that was... ++KFS, 2003-03-25. */
4014 /* Add the tool-bar height to the initial frame height so that the
4015 user gets a text display area of the size he specified with -g or
4016 via .Xdefaults. Later changes of the tool-bar height don't
4017 change the frame size. This is done so that users can create
4018 tall Emacs frames without having to guess how tall the tool-bar
4019 will get. */
4020 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4022 int margin, relief, bar_height;
4024 relief = (tool_bar_button_relief >= 0
4025 ? tool_bar_button_relief
4026 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4028 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4029 margin = XFASTINT (Vtool_bar_button_margin);
4030 else if (CONSP (Vtool_bar_button_margin)
4031 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4032 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4033 else
4034 margin = 0;
4036 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4037 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4040 compute_fringe_widths (f, 0);
4042 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4043 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4045 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4046 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4047 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4048 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4050 if (EQ (tem0, Qminus))
4052 f->top_pos = 0;
4053 window_prompting |= YNegative;
4055 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4056 && CONSP (XCDR (tem0))
4057 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem0)), INT_MAX))
4059 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4060 window_prompting |= YNegative;
4062 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4063 && CONSP (XCDR (tem0))
4064 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0))))
4066 f->top_pos = XINT (XCAR (XCDR (tem0)));
4068 else if (EQ (tem0, Qunbound))
4069 f->top_pos = 0;
4070 else
4072 CHECK_TYPE_RANGED_INTEGER (int, tem0);
4073 f->top_pos = XINT (tem0);
4074 if (f->top_pos < 0)
4075 window_prompting |= YNegative;
4078 if (EQ (tem1, Qminus))
4080 f->left_pos = 0;
4081 window_prompting |= XNegative;
4083 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4084 && CONSP (XCDR (tem1))
4085 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem1)), INT_MAX))
4087 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4088 window_prompting |= XNegative;
4090 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4091 && CONSP (XCDR (tem1))
4092 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1))))
4094 f->left_pos = XINT (XCAR (XCDR (tem1)));
4096 else if (EQ (tem1, Qunbound))
4097 f->left_pos = 0;
4098 else
4100 CHECK_TYPE_RANGED_INTEGER (int, tem1);
4101 f->left_pos = XINT (tem1);
4102 if (f->left_pos < 0)
4103 window_prompting |= XNegative;
4106 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4107 window_prompting |= USPosition;
4108 else
4109 window_prompting |= PPosition;
4112 if (window_prompting & XNegative)
4114 if (window_prompting & YNegative)
4115 f->win_gravity = SouthEastGravity;
4116 else
4117 f->win_gravity = NorthEastGravity;
4119 else
4121 if (window_prompting & YNegative)
4122 f->win_gravity = SouthWestGravity;
4123 else
4124 f->win_gravity = NorthWestGravity;
4127 f->size_hint_flags = window_prompting;
4129 return window_prompting;
4134 #endif /* HAVE_WINDOW_SYSTEM */
4136 void
4137 frame_make_pointer_invisible (void)
4139 if (! NILP (Vmake_pointer_invisible))
4141 struct frame *f;
4142 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4143 return;
4145 f = SELECTED_FRAME ();
4146 if (f && !f->pointer_invisible
4147 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4149 f->mouse_moved = 0;
4150 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4151 f->pointer_invisible = 1;
4156 void
4157 frame_make_pointer_visible (void)
4159 /* We don't check Vmake_pointer_invisible here in case the
4160 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4161 struct frame *f;
4163 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4164 return;
4166 f = SELECTED_FRAME ();
4167 if (f && f->pointer_invisible && f->mouse_moved
4168 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4170 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4171 f->pointer_invisible = 0;
4175 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4176 Sframe_pointer_visible_p, 0, 1, 0,
4177 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4178 Otherwise it returns nil. FRAME omitted or nil means the
4179 selected frame. This is useful when `make-pointer-invisible' is set. */)
4180 (Lisp_Object frame)
4182 if (NILP (frame))
4183 frame = selected_frame;
4185 CHECK_FRAME (frame);
4187 return (XFRAME (frame)->pointer_invisible ? Qnil : Qt);
4191 /***********************************************************************
4192 Initialization
4193 ***********************************************************************/
4195 void
4196 syms_of_frame (void)
4198 DEFSYM (Qframep, "framep");
4199 DEFSYM (Qframe_live_p, "frame-live-p");
4200 DEFSYM (Qexplicit_name, "explicit-name");
4201 DEFSYM (Qheight, "height");
4202 DEFSYM (Qicon, "icon");
4203 DEFSYM (Qminibuffer, "minibuffer");
4204 DEFSYM (Qmodeline, "modeline");
4205 DEFSYM (Qonly, "only");
4206 DEFSYM (Qwidth, "width");
4207 DEFSYM (Qgeometry, "geometry");
4208 DEFSYM (Qicon_left, "icon-left");
4209 DEFSYM (Qicon_top, "icon-top");
4210 DEFSYM (Qtooltip, "tooltip");
4211 DEFSYM (Qleft, "left");
4212 DEFSYM (Qright, "right");
4213 DEFSYM (Quser_position, "user-position");
4214 DEFSYM (Quser_size, "user-size");
4215 DEFSYM (Qwindow_id, "window-id");
4216 #ifdef HAVE_X_WINDOWS
4217 DEFSYM (Qouter_window_id, "outer-window-id");
4218 #endif
4219 DEFSYM (Qparent_id, "parent-id");
4220 DEFSYM (Qx, "x");
4221 DEFSYM (Qw32, "w32");
4222 DEFSYM (Qpc, "pc");
4223 DEFSYM (Qmac, "mac");
4224 DEFSYM (Qns, "ns");
4225 DEFSYM (Qvisible, "visible");
4226 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4227 DEFSYM (Qbuffer_list, "buffer-list");
4228 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4229 DEFSYM (Qdisplay_type, "display-type");
4230 DEFSYM (Qbackground_mode, "background-mode");
4231 DEFSYM (Qnoelisp, "noelisp");
4232 DEFSYM (Qtty_color_mode, "tty-color-mode");
4233 DEFSYM (Qtty, "tty");
4234 DEFSYM (Qtty_type, "tty-type");
4236 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4238 DEFSYM (Qfullwidth, "fullwidth");
4239 DEFSYM (Qfullheight, "fullheight");
4240 DEFSYM (Qfullboth, "fullboth");
4241 DEFSYM (Qmaximized, "maximized");
4242 DEFSYM (Qx_resource_name, "x-resource-name");
4243 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4245 DEFSYM (Qterminal, "terminal");
4246 DEFSYM (Qterminal_live_p, "terminal-live-p");
4248 #ifdef HAVE_NS
4249 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4250 #endif
4253 int i;
4255 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4257 Lisp_Object v = intern_c_string (frame_parms[i].name);
4258 if (frame_parms[i].variable)
4260 *frame_parms[i].variable = v;
4261 staticpro (frame_parms[i].variable);
4263 Fput (v, Qx_frame_parameter, make_number (i));
4267 #ifdef HAVE_WINDOW_SYSTEM
4268 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4269 doc: /* The name Emacs uses to look up X resources.
4270 `x-get-resource' uses this as the first component of the instance name
4271 when requesting resource values.
4272 Emacs initially sets `x-resource-name' to the name under which Emacs
4273 was invoked, or to the value specified with the `-name' or `-rn'
4274 switches, if present.
4276 It may be useful to bind this variable locally around a call
4277 to `x-get-resource'. See also the variable `x-resource-class'. */);
4278 Vx_resource_name = Qnil;
4280 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4281 doc: /* The class Emacs uses to look up X resources.
4282 `x-get-resource' uses this as the first component of the instance class
4283 when requesting resource values.
4285 Emacs initially sets `x-resource-class' to "Emacs".
4287 Setting this variable permanently is not a reasonable thing to do,
4288 but binding this variable locally around a call to `x-get-resource'
4289 is a reasonable practice. See also the variable `x-resource-name'. */);
4290 Vx_resource_class = build_string (EMACS_CLASS);
4292 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4293 doc: /* The lower limit of the frame opacity (alpha transparency).
4294 The value should range from 0 (invisible) to 100 (completely opaque).
4295 You can also use a floating number between 0.0 and 1.0.
4296 The default is 20. */);
4297 Vframe_alpha_lower_limit = make_number (20);
4298 #endif
4300 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4301 doc: /* Alist of default values for frame creation.
4302 These may be set in your init file, like this:
4303 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4304 These override values given in window system configuration data,
4305 including X Windows' defaults database.
4306 For values specific to the first Emacs frame, see `initial-frame-alist'.
4307 For window-system specific values, see `window-system-default-frame-alist'.
4308 For values specific to the separate minibuffer frame, see
4309 `minibuffer-frame-alist'.
4310 The `menu-bar-lines' element of the list controls whether new frames
4311 have menu bars; `menu-bar-mode' works by altering this element.
4312 Setting this variable does not affect existing frames, only new ones. */);
4313 Vdefault_frame_alist = Qnil;
4315 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4316 doc: /* Default position of scroll bars on this window-system. */);
4317 #ifdef HAVE_WINDOW_SYSTEM
4318 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4319 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4320 default. */
4321 Vdefault_frame_scroll_bars = Qright;
4322 #else
4323 Vdefault_frame_scroll_bars = Qleft;
4324 #endif
4325 #else
4326 Vdefault_frame_scroll_bars = Qnil;
4327 #endif
4329 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4330 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4332 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4333 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4334 `mouse-position' calls this function, passing its usual return value as
4335 argument, and returns whatever this function returns.
4336 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4337 which need to do mouse handling at the Lisp level. */);
4338 Vmouse_position_function = Qnil;
4340 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4341 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4342 If the value is an integer, highlighting is only shown after moving the
4343 mouse, while keyboard input turns off the highlight even when the mouse
4344 is over the clickable text. However, the mouse shape still indicates
4345 when the mouse is over clickable text. */);
4346 Vmouse_highlight = Qt;
4348 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4349 doc: /* If non-nil, make pointer invisible while typing.
4350 The pointer becomes visible again when the mouse is moved. */);
4351 Vmake_pointer_invisible = Qt;
4353 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4354 doc: /* Functions to be run before deleting a frame.
4355 The functions are run with one arg, the frame to be deleted.
4356 See `delete-frame'.
4358 Note that functions in this list may be called just before the frame is
4359 actually deleted, or some time later (or even both when an earlier function
4360 in `delete-frame-functions' (indirectly) calls `delete-frame'
4361 recursively). */);
4362 Vdelete_frame_functions = Qnil;
4363 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4365 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4366 doc: /* Non-nil if Menu-Bar mode is enabled.
4367 See the command `menu-bar-mode' for a description of this minor mode.
4368 Setting this variable directly does not take effect;
4369 either customize it (see the info node `Easy Customization')
4370 or call the function `menu-bar-mode'. */);
4371 Vmenu_bar_mode = Qt;
4373 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4374 doc: /* Non-nil if Tool-Bar mode is enabled.
4375 See the command `tool-bar-mode' for a description of this minor mode.
4376 Setting this variable directly does not take effect;
4377 either customize it (see the info node `Easy Customization')
4378 or call the function `tool-bar-mode'. */);
4379 #ifdef HAVE_WINDOW_SYSTEM
4380 Vtool_bar_mode = Qt;
4381 #else
4382 Vtool_bar_mode = Qnil;
4383 #endif
4385 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4386 doc: /* Minibufferless frames use this frame's minibuffer.
4388 Emacs cannot create minibufferless frames unless this is set to an
4389 appropriate surrogate.
4391 Emacs consults this variable only when creating minibufferless
4392 frames; once the frame is created, it sticks with its assigned
4393 minibuffer, no matter what this variable is set to. This means that
4394 this variable doesn't necessarily say anything meaningful about the
4395 current set of frames, or where the minibuffer is currently being
4396 displayed.
4398 This variable is local to the current terminal and cannot be buffer-local. */);
4400 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4401 doc: /* Non-nil if window system changes focus when you move the mouse.
4402 You should set this variable to tell Emacs how your window manager
4403 handles focus, since there is no way in general for Emacs to find out
4404 automatically. See also `mouse-autoselect-window'. */);
4405 focus_follows_mouse = 0;
4407 staticpro (&Vframe_list);
4409 defsubr (&Sframep);
4410 defsubr (&Sframe_live_p);
4411 defsubr (&Swindow_system);
4412 defsubr (&Smake_terminal_frame);
4413 defsubr (&Shandle_switch_frame);
4414 defsubr (&Sselect_frame);
4415 defsubr (&Sselected_frame);
4416 defsubr (&Sframe_list);
4417 defsubr (&Snext_frame);
4418 defsubr (&Sprevious_frame);
4419 defsubr (&Sdelete_frame);
4420 defsubr (&Smouse_position);
4421 defsubr (&Smouse_pixel_position);
4422 defsubr (&Sset_mouse_position);
4423 defsubr (&Sset_mouse_pixel_position);
4424 #if 0
4425 defsubr (&Sframe_configuration);
4426 defsubr (&Srestore_frame_configuration);
4427 #endif
4428 defsubr (&Smake_frame_visible);
4429 defsubr (&Smake_frame_invisible);
4430 defsubr (&Siconify_frame);
4431 defsubr (&Sframe_visible_p);
4432 defsubr (&Svisible_frame_list);
4433 defsubr (&Sraise_frame);
4434 defsubr (&Slower_frame);
4435 defsubr (&Sredirect_frame_focus);
4436 defsubr (&Sframe_focus);
4437 defsubr (&Sframe_parameters);
4438 defsubr (&Sframe_parameter);
4439 defsubr (&Smodify_frame_parameters);
4440 defsubr (&Sframe_char_height);
4441 defsubr (&Sframe_char_width);
4442 defsubr (&Sframe_pixel_height);
4443 defsubr (&Sframe_pixel_width);
4444 defsubr (&Stool_bar_pixel_width);
4445 defsubr (&Sset_frame_height);
4446 defsubr (&Sset_frame_width);
4447 defsubr (&Sset_frame_size);
4448 defsubr (&Sset_frame_position);
4449 defsubr (&Sframe_pointer_visible_p);
4451 #ifdef HAVE_WINDOW_SYSTEM
4452 defsubr (&Sx_get_resource);
4453 defsubr (&Sx_parse_geometry);
4454 #endif