* lisp/comint.el: Clean up namespace
[emacs.git] / src / frame.c
blobd477c1acc3f58a22aee22319dc706088bd09165a
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2018 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 (at
10 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 <https://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <limits.h>
27 #include <c-ctype.h>
29 #include "lisp.h"
31 #ifdef HAVE_WINDOW_SYSTEM
32 #include TERM_HEADER
33 #endif /* HAVE_WINDOW_SYSTEM */
35 #include "buffer.h"
36 /* These help us bind and responding to switch-frame events. */
37 #include "keyboard.h"
38 #include "ptr-bounds.h"
39 #include "frame.h"
40 #include "blockinput.h"
41 #include "termchar.h"
42 #include "termhooks.h"
43 #include "dispextern.h"
44 #include "window.h"
45 #ifdef HAVE_WINDOW_SYSTEM
46 #include "fontset.h"
47 #endif
48 #include "cm.h"
49 #ifdef MSDOS
50 #include "msdos.h"
51 #include "dosfns.h"
52 #endif
53 #ifdef USE_X_TOOLKIT
54 #include "widget.h"
55 #endif
57 /* The currently selected frame. */
59 Lisp_Object selected_frame;
61 /* A frame which is not just a mini-buffer, or NULL if there are no such
62 frames. This is usually the most recent such frame that was selected. */
64 static struct frame *last_nonminibuf_frame;
66 /* False means there are no visible garbaged frames. */
67 bool frame_garbaged;
69 /* The default tool bar height for future frames. */
70 #if defined USE_GTK || defined HAVE_NS
71 enum { frame_default_tool_bar_height = 0 };
72 #else
73 int frame_default_tool_bar_height;
74 #endif
76 #ifdef HAVE_WINDOW_SYSTEM
77 static void x_report_frame_params (struct frame *, Lisp_Object *);
78 #endif
80 /* These setters are used only in this file, so they can be private. */
81 static void
82 fset_buffer_predicate (struct frame *f, Lisp_Object val)
84 f->buffer_predicate = val;
86 static void
87 fset_minibuffer_window (struct frame *f, Lisp_Object val)
89 f->minibuffer_window = val;
92 struct frame *
93 decode_live_frame (register Lisp_Object frame)
95 if (NILP (frame))
96 frame = selected_frame;
97 CHECK_LIVE_FRAME (frame);
98 return XFRAME (frame);
101 struct frame *
102 decode_any_frame (register Lisp_Object frame)
104 if (NILP (frame))
105 frame = selected_frame;
106 CHECK_FRAME (frame);
107 return XFRAME (frame);
110 #ifdef HAVE_WINDOW_SYSTEM
111 bool
112 display_available (void)
114 return x_display_list != NULL;
116 #endif
118 struct frame *
119 decode_window_system_frame (Lisp_Object frame)
121 struct frame *f = decode_live_frame (frame);
122 check_window_system (f);
123 #ifdef HAVE_WINDOW_SYSTEM
124 return f;
125 #endif
128 void
129 check_window_system (struct frame *f)
131 #ifdef HAVE_WINDOW_SYSTEM
132 if (window_system_available (f))
133 return;
134 #endif
135 error (f ? "Window system frame should be used"
136 : "Window system is not in use or not initialized");
139 /* Return the value of frame parameter PROP in frame FRAME. */
141 Lisp_Object
142 get_frame_param (register struct frame *frame, Lisp_Object prop)
144 register Lisp_Object tem;
146 tem = Fassq (prop, frame->param_alist);
147 if (EQ (tem, Qnil))
148 return tem;
149 return Fcdr (tem);
153 void
154 frame_size_history_add (struct frame *f, Lisp_Object fun_symbol,
155 int width, int height, Lisp_Object rest)
157 Lisp_Object frame;
159 XSETFRAME (frame, f);
160 if (CONSP (frame_size_history)
161 && INTEGERP (XCAR (frame_size_history))
162 && 0 < XINT (XCAR (frame_size_history)))
163 frame_size_history =
164 Fcons (make_number (XINT (XCAR (frame_size_history)) - 1),
165 Fcons (list4
166 (frame, fun_symbol,
167 ((width > 0)
168 ? list4 (make_number (FRAME_TEXT_WIDTH (f)),
169 make_number (FRAME_TEXT_HEIGHT (f)),
170 make_number (width),
171 make_number (height))
172 : Qnil),
173 rest),
174 XCDR (frame_size_history)));
178 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
179 state of frame F would be affected by a vertical (horizontal if
180 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
181 parameter that is changed. */
182 bool
183 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
185 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
186 bool inhibit
187 = (f->after_make_frame
188 ? (EQ (frame_inhibit_implied_resize, Qt)
189 || (CONSP (frame_inhibit_implied_resize)
190 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))
191 || (horizontal
192 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight))
193 || (!horizontal
194 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth))
195 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
196 : ((horizontal && f->inhibit_horizontal_resize)
197 || (!horizontal && f->inhibit_vertical_resize)));
198 if (inhibit && !FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
199 frame_size_history_add
200 (f, Qframe_inhibit_resize, 0, 0,
201 list5 (horizontal ? Qt : Qnil, parameter,
202 f->after_make_frame ? Qt : Qnil,
203 frame_inhibit_implied_resize,
204 fullscreen));
206 return inhibit;
209 static void
210 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
212 int nlines;
213 int olines = FRAME_MENU_BAR_LINES (f);
215 /* Right now, menu bars don't work properly in minibuf-only frames;
216 most of the commands try to apply themselves to the minibuffer
217 frame itself, and get an error because you can't switch buffers
218 in or split the minibuffer window. */
219 if (FRAME_MINIBUF_ONLY_P (f))
220 return;
222 if (TYPE_RANGED_INTEGERP (int, value))
223 nlines = XINT (value);
224 else
225 nlines = 0;
227 if (nlines != olines)
229 windows_or_buffers_changed = 14;
230 FRAME_MENU_BAR_LINES (f) = nlines;
231 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
232 change_frame_size (f, FRAME_COLS (f),
233 FRAME_LINES (f) + olines - nlines,
234 0, 1, 0, 0);
238 Lisp_Object Vframe_list;
241 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
242 doc: /* Return non-nil if OBJECT is a frame.
243 Value is:
244 t for a termcap frame (a character-only terminal),
245 `x' for an Emacs frame that is really an X window,
246 `w32' for an Emacs frame that is a window on MS-Windows display,
247 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
248 `pc' for a direct-write MS-DOS frame.
249 See also `frame-live-p'. */)
250 (Lisp_Object object)
252 if (!FRAMEP (object))
253 return Qnil;
254 switch (XFRAME (object)->output_method)
256 case output_initial: /* The initial frame is like a termcap frame. */
257 case output_termcap:
258 return Qt;
259 case output_x_window:
260 return Qx;
261 case output_w32:
262 return Qw32;
263 case output_msdos_raw:
264 return Qpc;
265 case output_ns:
266 return Qns;
267 default:
268 emacs_abort ();
272 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
273 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
274 Value is nil if OBJECT is not a live frame. If object is a live
275 frame, the return value indicates what sort of terminal device it is
276 displayed on. See the documentation of `framep' for possible
277 return values. */)
278 (Lisp_Object object)
280 return ((FRAMEP (object)
281 && FRAME_LIVE_P (XFRAME (object)))
282 ? Fframep (object)
283 : Qnil);
286 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
287 doc: /* The name of the window system that FRAME is displaying through.
288 The value is a symbol:
289 nil for a termcap frame (a character-only terminal),
290 `x' for an Emacs frame that is really an X window,
291 `w32' for an Emacs frame that is a window on MS-Windows display,
292 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
293 `pc' for a direct-write MS-DOS frame.
295 FRAME defaults to the currently selected frame.
297 Use of this function as a predicate is deprecated. Instead,
298 use `display-graphic-p' or any of the other `display-*-p'
299 predicates which report frame's specific UI-related capabilities. */)
300 (Lisp_Object frame)
302 Lisp_Object type;
303 if (NILP (frame))
304 frame = selected_frame;
306 type = Fframep (frame);
308 if (NILP (type))
309 wrong_type_argument (Qframep, frame);
311 if (EQ (type, Qt))
312 return Qnil;
313 else
314 return type;
317 /* Placeholder used by temacs -nw before window.el is loaded. */
318 DEFUN ("frame-windows-min-size", Fframe_windows_min_size,
319 Sframe_windows_min_size, 4, 4, 0,
320 doc: /* SKIP: real doc in window.el. */
321 attributes: const)
322 (Lisp_Object frame, Lisp_Object horizontal,
323 Lisp_Object ignore, Lisp_Object pixelwise)
325 return make_number (0);
329 * frame_windows_min_size:
331 * Return the minimum number of lines (columns if HORIZONTAL is non-nil)
332 * of FRAME. If PIXELWISE is non-nil, return the minimum inner height
333 * (width) of FRAME in pixels.
335 * This value is calculated by the function `frame-windows-min-size' in
336 * window.el unless the `min-height' (`min-width' if HORIZONTAL is
337 * non-nil) parameter of FRAME is non-nil thus explicitly specifying the
338 * value to be returned. In that latter case IGNORE is ignored.
340 * If `frame-windows-min-size' is called, it will make sure that the
341 * return value accommodates all windows of FRAME respecting the values
342 * of `window-min-height' (`window-min-width' if HORIZONTAL is non-nil).
343 * With IGNORE non-nil the values of these variables are ignored.
345 * In either case, never return a value less than 1. For TTY frames,
346 * additionally limit the minimum frame height to a value large enough
347 * to support the menu bar, the mode line, and the echo area.
349 static int
350 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal,
351 Lisp_Object ignore, Lisp_Object pixelwise)
353 struct frame *f = XFRAME (frame);
354 Lisp_Object par_size;
355 int retval;
357 if ((!NILP (horizontal)
358 && NUMBERP (par_size = get_frame_param (f, Qmin_width)))
359 || (NILP (horizontal)
360 && NUMBERP (par_size = get_frame_param (f, Qmin_height))))
362 int min_size = XINT (par_size);
364 /* Don't allow phantom frames. */
365 if (min_size < 1)
366 min_size = 1;
368 retval = (NILP (pixelwise)
369 ? min_size
370 : min_size * (NILP (horizontal)
371 ? FRAME_LINE_HEIGHT (f)
372 : FRAME_COLUMN_WIDTH (f)));
374 else
375 retval = XINT (call4 (Qframe_windows_min_size, frame, horizontal,
376 ignore, pixelwise));
377 /* Don't allow too small height of text-mode frames, or else cm.c
378 might abort in cmcheckmagic. */
379 if ((FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) && NILP (horizontal))
381 int min_height = (FRAME_MENU_BAR_LINES (f)
382 + FRAME_WANTS_MODELINE_P (f)
383 + 2); /* one text line and one echo-area line */
384 if (retval < min_height)
385 retval = min_height;
388 return retval;
392 #ifdef HAVE_WINDOW_SYSTEM
394 * keep_ratio:
396 * Preserve ratios of frame F which usually happens after its parent
397 * frame P got resized. OLD_WIDTH, OLD_HEIGHT specifies the old native
398 * size of F's parent, NEW_WIDTH and NEW_HEIGHT its new size.
400 * Adjust F's width if F's 'keep_ratio' parameter is non-nil and, if
401 * it is a cons, its car is not 'height-only'. Adjust F's height if F's
402 * 'keep_ratio' parameter is non-nil and, if it is a cons, its car
403 * is not 'width-only'.
405 * Adjust F's left position if F's 'keep_ratio' parameter is non-nil
406 * and, if its is a cons, its cdr is non-nil and not 'top-only'. Adjust
407 * F's top position if F's 'keep_ratio' parameter is non-nil and, if
408 * its is a cons, its cdr is non-nil and not 'left-only'.
410 * Note that when positional adjustment is requested but the size of F
411 * should remain unaltered in the corresponding direction, this routine
412 * tries to constrain F to its parent frame - something which usually
413 * happens when the parent frame shrinks. This means, however, that
414 * when the parent frame is re-enlarged later, the child's original
415 * position will not get restored to its pre-shrinking value.
417 * This routine is currently useful for child frames only. It might be
418 * eventually useful when moving non-child frames between monitors with
419 * different resolutions.
421 static void
422 keep_ratio (struct frame *f, struct frame *p, int old_width, int old_height,
423 int new_width, int new_height)
425 Lisp_Object keep_ratio = get_frame_param (f, Qkeep_ratio);
428 if (!NILP (keep_ratio))
430 double width_factor = (double)new_width / (double)old_width;
431 double height_factor = (double)new_height / (double)old_height;
432 int pixel_width, pixel_height, pos_x, pos_y;
434 if (!CONSP (keep_ratio) || !NILP (Fcdr (keep_ratio)))
436 if (CONSP (keep_ratio) && EQ (Fcdr (keep_ratio), Qtop_only))
437 pos_x = f->left_pos;
438 else
440 pos_x = (int)(f->left_pos * width_factor + 0.5);
442 if (CONSP (keep_ratio)
443 && (NILP (Fcar (keep_ratio))
444 || EQ (Fcar (keep_ratio), Qheight_only))
445 && p->pixel_width - f->pixel_width < pos_x)
447 int p_f_width = p->pixel_width - f->pixel_width;
449 if (p_f_width <= 0)
450 pos_x = 0;
451 else
452 pos_x = (int)(p_f_width * width_factor * 0.5 + 0.5);
455 f->left_pos = pos_x;
458 if (CONSP (keep_ratio) && EQ (Fcdr (keep_ratio), Qleft_only))
459 pos_y = f->top_pos;
460 else
462 pos_y = (int)(f->top_pos * height_factor + 0.5);
464 if (CONSP (keep_ratio)
465 && (NILP (Fcar (keep_ratio))
466 || EQ (Fcar (keep_ratio), Qwidth_only))
467 && p->pixel_height - f->pixel_height < pos_y)
468 /* When positional adjustment was requested and the
469 width of F should remain unaltered, try to constrain
470 F to its parent. This means that when the parent
471 frame is enlarged later the child's original position
472 won't get restored. */
474 int p_f_height = p->pixel_height - f->pixel_height;
476 if (p_f_height <= 0)
477 pos_y = 0;
478 else
479 pos_y = (int)(p_f_height * height_factor * 0.5 + 0.5);
482 f->top_pos = pos_y;
485 x_set_offset (f, pos_x, pos_y, -1);
488 if (!CONSP (keep_ratio) || !NILP (Fcar (keep_ratio)))
490 if (CONSP (keep_ratio) && EQ (Fcar (keep_ratio), Qheight_only))
491 pixel_width = -1;
492 else
494 pixel_width = (int)(f->pixel_width * width_factor + 0.5);
495 pixel_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, pixel_width);
498 if (CONSP (keep_ratio) && EQ (Fcar (keep_ratio), Qwidth_only))
499 pixel_height = -1;
500 else
502 pixel_height = (int)(f->pixel_height * height_factor + 0.5);
503 pixel_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, pixel_height);
506 adjust_frame_size (f, pixel_width, pixel_height, 1, 0,
507 Qkeep_ratio);
511 #endif
515 * adjust_frame_size:
517 * Adjust size of frame F. NEW_WIDTH and NEW_HEIGHT specify the new
518 * text size of F in pixels. A value of -1 means no change is requested
519 * for that direction (but the frame may still have to be resized to
520 * accommodate windows with their minimum sizes). This can either issue
521 * a request to resize the frame externally (via x_set_window_size), to
522 * resize the frame internally (via resize_frame_windows) or do nothing
523 * at all.
525 * The argument INHIBIT can assume the following values:
527 * 0 means to unconditionally call x_set_window_size even if sizes
528 * apparently do not change. Fx_create_frame uses this to pass the
529 * initial size to the window manager.
531 * 1 means to call x_set_window_size if the native frame size really
532 * changes. Fset_frame_size, Fset_frame_height, ... use this.
534 * 2 means to call x_set_window_size provided frame_inhibit_resize
535 * allows it. The menu and tool bar code use this ("3" won't work
536 * here in general because menu and tool bar are often not counted in
537 * the frame's text height).
539 * 3 means call x_set_window_size if window minimum sizes must be
540 * preserved or frame_inhibit_resize allows it. x_set_left_fringe,
541 * x_set_scroll_bar_width, x_new_font ... use (or should use) this.
543 * 4 means call x_set_window_size only if window minimum sizes must be
544 * preserved. x_set_right_divider_width, x_set_border_width and the
545 * code responsible for wrapping the tool bar use this.
547 * 5 means to never call x_set_window_size. change_frame_size uses
548 * this.
550 * Note that even when x_set_window_size is not called, individual
551 * windows may have to be resized (via `window--sanitize-window-sizes')
552 * in order to support minimum size constraints.
554 * PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the
555 * symbol of the parameter changed (like `menu-bar-lines', `font', ...).
556 * This is passed on to frame_inhibit_resize to let the latter decide on
557 * a case-by-case basis whether the frame may be resized externally.
559 void
560 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
561 bool pretend, Lisp_Object parameter)
563 int unit_width = FRAME_COLUMN_WIDTH (f);
564 int unit_height = FRAME_LINE_HEIGHT (f);
565 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
566 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
567 int old_cols = FRAME_COLS (f);
568 int old_lines = FRAME_LINES (f);
569 int new_pixel_width, new_pixel_height;
570 /* The following two values are calculated from the old frame pixel
571 sizes and any "new" settings for tool bar, menu bar and internal
572 borders. We do it this way to detect whether we have to call
573 x_set_window_size as consequence of the new settings. */
574 int windows_width = FRAME_WINDOWS_WIDTH (f);
575 int windows_height = FRAME_WINDOWS_HEIGHT (f);
576 int min_windows_width, min_windows_height;
577 /* These are a bit tedious, maybe we should use a macro. */
578 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
579 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
580 int old_windows_height
581 = (WINDOW_PIXEL_HEIGHT (r)
582 + ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
583 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
584 : 0));
585 int new_windows_width, new_windows_height;
586 int old_text_width = FRAME_TEXT_WIDTH (f);
587 int old_text_height = FRAME_TEXT_HEIGHT (f);
588 /* If a size is < 0 use the old value. */
589 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
590 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
591 int new_cols, new_lines;
592 bool inhibit_horizontal, inhibit_vertical;
593 Lisp_Object frame;
595 XSETFRAME (frame, f);
597 frame_size_history_add
598 (f, Qadjust_frame_size_1, new_text_width, new_text_height,
599 list2 (parameter, make_number (inhibit)));
601 /* The following two values are calculated from the old window body
602 sizes and any "new" settings for scroll bars, dividers, fringes and
603 margins (though the latter should have been processed already). */
604 min_windows_width
605 = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qt : Qnil, Qt);
606 min_windows_height
607 = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qt : Qnil, Qt);
609 if (inhibit >= 2 && inhibit <= 4)
610 /* When INHIBIT is in [2..4] inhibit if the "old" window sizes stay
611 within the limits and either resizing is inhibited or INHIBIT
612 equals 4. */
614 inhibit_horizontal = (windows_width >= min_windows_width
615 && (inhibit == 4
616 || frame_inhibit_resize (f, true, parameter)));
617 inhibit_vertical = (windows_height >= min_windows_height
618 && (inhibit == 4
619 || frame_inhibit_resize (f, false, parameter)));
621 else
622 /* Otherwise inhibit if INHIBIT equals 5. */
623 inhibit_horizontal = inhibit_vertical = inhibit == 5;
625 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
626 ? old_pixel_width
627 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
628 min_windows_width
629 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
630 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
631 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
632 new_cols = new_text_width / unit_width;
634 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
635 ? old_pixel_height
636 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
637 min_windows_height
638 + FRAME_TOP_MARGIN_HEIGHT (f)
639 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
640 new_windows_height = (new_pixel_height
641 - FRAME_TOP_MARGIN_HEIGHT (f)
642 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
643 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
644 new_lines = new_text_height / unit_height;
646 #ifdef HAVE_WINDOW_SYSTEM
647 if (FRAME_WINDOW_P (f)
648 && f->can_x_set_window_size
649 && ((!inhibit_horizontal
650 && (new_pixel_width != old_pixel_width
651 || inhibit == 0 || inhibit == 2))
652 || (!inhibit_vertical
653 && (new_pixel_height != old_pixel_height
654 || inhibit == 0 || inhibit == 2))))
655 /* We are either allowed to change the frame size or the minimum
656 sizes request such a change. Do not care for fixing minimum
657 sizes here, we do that eventually when we're called from
658 change_frame_size. */
660 /* Make sure we respect fullheight and fullwidth. */
661 if (inhibit_horizontal)
662 new_text_width = old_text_width;
663 else if (inhibit_vertical)
664 new_text_height = old_text_height;
666 frame_size_history_add
667 (f, Qadjust_frame_size_2, new_text_width, new_text_height,
668 list2 (inhibit_horizontal ? Qt : Qnil,
669 inhibit_vertical ? Qt : Qnil));
671 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
672 f->resized_p = true;
674 return;
676 #endif
678 if (new_text_width == old_text_width
679 && new_text_height == old_text_height
680 && new_windows_width == old_windows_width
681 && new_windows_height == old_windows_height
682 && new_pixel_width == old_pixel_width
683 && new_pixel_height == old_pixel_height
684 && new_cols == old_cols
685 && new_lines == old_lines)
686 /* No change. Sanitize window sizes and return. */
688 sanitize_window_sizes (Qt);
689 sanitize_window_sizes (Qnil);
691 return;
694 block_input ();
696 #ifdef MSDOS
697 /* We only can set screen dimensions to certain values supported by
698 our video hardware. Try to find the smallest size greater or
699 equal to the requested dimensions, while accounting for the fact
700 that the menu-bar lines are not counted in the frame height. */
701 int dos_new_lines = new_lines + FRAME_TOP_MARGIN (f);
702 dos_set_window_size (&dos_new_lines, &new_cols);
703 new_lines = dos_new_lines - FRAME_TOP_MARGIN (f);
704 #endif
706 if (new_windows_width != old_windows_width)
708 resize_frame_windows (f, new_windows_width, 1, 1);
710 /* MSDOS frames cannot PRETEND, as they change frame size by
711 manipulating video hardware. */
712 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
713 FrameCols (FRAME_TTY (f)) = new_cols;
715 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
716 if (WINDOWP (f->tool_bar_window))
718 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
719 XWINDOW (f->tool_bar_window)->total_cols
720 = new_windows_width / unit_width;
722 #endif
724 else if (new_cols != old_cols)
725 call2 (Qwindow__pixel_to_total, frame, Qt);
727 if (new_windows_height != old_windows_height
728 /* When the top margin has changed we have to recalculate the top
729 edges of all windows. No such calculation is necessary for the
730 left edges. */
731 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
733 resize_frame_windows (f, new_windows_height, 0, 1);
735 /* MSDOS frames cannot PRETEND, as they change frame size by
736 manipulating video hardware. */
737 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
738 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
740 else if (new_lines != old_lines)
741 call2 (Qwindow__pixel_to_total, frame, Qnil);
743 frame_size_history_add
744 (f, Qadjust_frame_size_3, new_text_width, new_text_height,
745 list4 (make_number (old_pixel_width), make_number (old_pixel_height),
746 make_number (new_pixel_width), make_number (new_pixel_height)));
748 /* Assign new sizes. */
749 FRAME_TEXT_WIDTH (f) = new_text_width;
750 FRAME_TEXT_HEIGHT (f) = new_text_height;
751 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
752 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
753 SET_FRAME_COLS (f, new_cols);
754 SET_FRAME_LINES (f, new_lines);
757 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
758 int text_area_x, text_area_y, text_area_width, text_area_height;
760 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
761 &text_area_height);
762 if (w->cursor.x >= text_area_x + text_area_width)
763 w->cursor.hpos = w->cursor.x = 0;
764 if (w->cursor.y >= text_area_y + text_area_height)
765 w->cursor.vpos = w->cursor.y = 0;
768 /* Sanitize window sizes. */
769 sanitize_window_sizes (Qt);
770 sanitize_window_sizes (Qnil);
772 adjust_frame_glyphs (f);
773 calculate_costs (f);
774 SET_FRAME_GARBAGED (f);
776 /* A frame was "resized" if one of its pixelsizes changed, even if its
777 X window wasn't resized at all. */
778 f->resized_p = (new_pixel_width != old_pixel_width
779 || new_pixel_height != old_pixel_height);
781 unblock_input ();
783 #ifdef HAVE_WINDOW_SYSTEM
785 /* Adjust size of F's child frames. */
786 Lisp_Object frames, frame1;
788 FOR_EACH_FRAME (frames, frame1)
789 if (FRAME_PARENT_FRAME (XFRAME (frame1)) == f)
790 keep_ratio (XFRAME (frame1), f, old_pixel_width, old_pixel_height,
791 new_pixel_width, new_pixel_height);
793 #endif
796 /* Allocate basically initialized frame. */
798 static struct frame *
799 allocate_frame (void)
801 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
804 struct frame *
805 make_frame (bool mini_p)
807 Lisp_Object frame;
808 struct frame *f;
809 struct window *rw, *mw UNINIT;
810 Lisp_Object root_window;
811 Lisp_Object mini_window;
813 f = allocate_frame ();
814 XSETFRAME (frame, f);
816 #ifdef USE_GTK
817 /* Initialize Lisp data. Note that allocate_frame initializes all
818 Lisp data to nil, so do it only for slots which should not be nil. */
819 fset_tool_bar_position (f, Qtop);
820 #endif
822 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
823 non-Lisp data, so do it only for slots which should not be zero.
824 To avoid subtle bugs and for the sake of readability, it's better to
825 initialize enum members explicitly even if their values are zero. */
826 f->wants_modeline = true;
827 f->redisplay = true;
828 f->garbaged = true;
829 f->can_x_set_window_size = false;
830 f->after_make_frame = false;
831 f->inhibit_horizontal_resize = false;
832 f->inhibit_vertical_resize = false;
833 f->tool_bar_redisplayed = false;
834 f->tool_bar_resized = false;
835 f->column_width = 1; /* !FRAME_WINDOW_P value. */
836 f->line_height = 1; /* !FRAME_WINDOW_P value. */
837 #ifdef HAVE_WINDOW_SYSTEM
838 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
839 f->horizontal_scroll_bars = false;
840 f->want_fullscreen = FULLSCREEN_NONE;
841 f->undecorated = false;
842 f->no_special_glyphs = false;
843 #ifndef HAVE_NTGUI
844 f->override_redirect = false;
845 #endif
846 f->skip_taskbar = false;
847 f->no_focus_on_map = false;
848 f->no_accept_focus = false;
849 f->z_group = z_group_none;
850 f->tooltip = false;
851 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
852 f->last_tool_bar_item = -1;
853 #endif
854 #ifdef NS_IMPL_COCOA
855 f->ns_appearance = ns_appearance_aqua;
856 f->ns_transparent_titlebar = false;
857 #endif
858 #endif
860 root_window = make_window ();
861 rw = XWINDOW (root_window);
862 if (mini_p)
864 mini_window = make_window ();
865 mw = XWINDOW (mini_window);
866 wset_next (rw, mini_window);
867 wset_prev (mw, root_window);
868 mw->mini = 1;
869 wset_frame (mw, frame);
870 fset_minibuffer_window (f, mini_window);
871 store_frame_param (f, Qminibuffer, Qt);
873 else
875 mini_window = Qnil;
876 wset_next (rw, Qnil);
877 fset_minibuffer_window (f, Qnil);
880 wset_frame (rw, frame);
882 /* 10 is arbitrary,
883 just so that there is "something there."
884 Correct size will be set up later with adjust_frame_size. */
886 SET_FRAME_COLS (f, 10);
887 SET_FRAME_LINES (f, 10);
888 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
889 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
891 rw->total_cols = 10;
892 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
893 rw->total_lines = mini_p ? 9 : 10;
894 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
896 if (mini_p)
898 mw->top_line = rw->total_lines;
899 mw->pixel_top = rw->pixel_height;
900 mw->total_cols = rw->total_cols;
901 mw->pixel_width = rw->pixel_width;
902 mw->total_lines = 1;
903 mw->pixel_height = FRAME_LINE_HEIGHT (f);
906 /* Choose a buffer for the frame's root window. */
908 Lisp_Object buf = Fcurrent_buffer ();
910 /* If current buffer is hidden, try to find another one. */
911 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
912 buf = other_buffer_safely (buf);
914 /* Use set_window_buffer, not Fset_window_buffer, and don't let
915 hooks be run by it. The reason is that the whole frame/window
916 arrangement is not yet fully initialized at this point. Windows
917 don't have the right size, glyph matrices aren't initialized
918 etc. Running Lisp functions at this point surely ends in a
919 SEGV. */
920 set_window_buffer (root_window, buf, 0, 0);
921 fset_buffer_list (f, list1 (buf));
924 if (mini_p)
926 set_window_buffer (mini_window,
927 (NILP (Vminibuffer_list)
928 ? get_minibuffer (0)
929 : Fcar (Vminibuffer_list)),
930 0, 0);
931 /* No horizontal scroll bars in minibuffers. */
932 wset_horizontal_scroll_bar (mw, Qnil);
935 fset_root_window (f, root_window);
936 fset_selected_window (f, root_window);
937 /* Make sure this window seems more recently used than
938 a newly-created, never-selected window. */
939 XWINDOW (f->selected_window)->use_time = ++window_select_count;
941 return f;
944 #ifdef HAVE_WINDOW_SYSTEM
945 /* Make a frame using a separate minibuffer window on another frame.
946 MINI_WINDOW is the minibuffer window to use. nil means use the
947 default (the global minibuffer). */
949 struct frame *
950 make_frame_without_minibuffer (Lisp_Object mini_window, KBOARD *kb,
951 Lisp_Object display)
953 struct frame *f;
955 if (!NILP (mini_window))
956 CHECK_LIVE_WINDOW (mini_window);
958 if (!NILP (mini_window)
959 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
960 error ("Frame and minibuffer must be on the same terminal");
962 /* Make a frame containing just a root window. */
963 f = make_frame (0);
965 if (NILP (mini_window))
967 /* Use default-minibuffer-frame if possible. */
968 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
969 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
971 Lisp_Object frame_dummy;
973 XSETFRAME (frame_dummy, f);
974 /* If there's no minibuffer frame to use, create one. */
975 kset_default_minibuffer_frame
976 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
979 mini_window
980 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
983 fset_minibuffer_window (f, mini_window);
984 store_frame_param (f, Qminibuffer, mini_window);
986 /* Make the chosen minibuffer window display the proper minibuffer,
987 unless it is already showing a minibuffer. */
988 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
989 /* Use set_window_buffer instead of Fset_window_buffer (see
990 discussion of bug#11984, bug#12025, bug#12026). */
991 set_window_buffer (mini_window,
992 (NILP (Vminibuffer_list)
993 ? get_minibuffer (0)
994 : Fcar (Vminibuffer_list)), 0, 0);
995 return f;
998 /* Make a frame containing only a minibuffer window. */
1000 struct frame *
1001 make_minibuffer_frame (void)
1003 /* First make a frame containing just a root window, no minibuffer. */
1005 register struct frame *f = make_frame (0);
1006 register Lisp_Object mini_window;
1007 register Lisp_Object frame;
1009 XSETFRAME (frame, f);
1011 f->auto_raise = 0;
1012 f->auto_lower = 0;
1013 f->no_split = 1;
1014 f->wants_modeline = 0;
1016 /* Now label the root window as also being the minibuffer.
1017 Avoid infinite looping on the window chain by marking next pointer
1018 as nil. */
1020 mini_window = f->root_window;
1021 fset_minibuffer_window (f, mini_window);
1022 store_frame_param (f, Qminibuffer, Qonly);
1023 XWINDOW (mini_window)->mini = 1;
1024 wset_next (XWINDOW (mini_window), Qnil);
1025 wset_prev (XWINDOW (mini_window), Qnil);
1026 wset_frame (XWINDOW (mini_window), frame);
1028 /* Put the proper buffer in that window. */
1030 /* Use set_window_buffer instead of Fset_window_buffer (see
1031 discussion of bug#11984, bug#12025, bug#12026). */
1032 set_window_buffer (mini_window,
1033 (NILP (Vminibuffer_list)
1034 ? get_minibuffer (0)
1035 : Fcar (Vminibuffer_list)), 0, 0);
1036 return f;
1038 #endif /* HAVE_WINDOW_SYSTEM */
1040 /* Construct a frame that refers to a terminal. */
1042 static printmax_t tty_frame_count;
1044 struct frame *
1045 make_initial_frame (void)
1047 struct frame *f;
1048 struct terminal *terminal;
1049 Lisp_Object frame;
1051 eassert (initial_kboard);
1053 /* The first call must initialize Vframe_list. */
1054 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
1055 Vframe_list = Qnil;
1057 terminal = init_initial_terminal ();
1059 f = make_frame (1);
1060 XSETFRAME (frame, f);
1062 Vframe_list = Fcons (frame, Vframe_list);
1064 tty_frame_count = 1;
1065 fset_name (f, build_pure_c_string ("F1"));
1067 SET_FRAME_VISIBLE (f, 1);
1069 f->output_method = terminal->type;
1070 f->terminal = terminal;
1071 f->terminal->reference_count++;
1072 f->output_data.nothing = 0;
1074 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
1075 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
1077 #ifdef HAVE_WINDOW_SYSTEM
1078 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
1079 f->horizontal_scroll_bars = false;
1080 #endif
1082 /* The default value of menu-bar-mode is t. */
1083 set_menu_bar_lines (f, make_number (1), Qnil);
1085 /* Allocate glyph matrices. */
1086 adjust_frame_glyphs (f);
1088 if (!noninteractive)
1089 init_frame_faces (f);
1091 last_nonminibuf_frame = f;
1093 f->can_x_set_window_size = true;
1094 f->after_make_frame = true;
1096 return f;
1100 static struct frame *
1101 make_terminal_frame (struct terminal *terminal)
1103 register struct frame *f;
1104 Lisp_Object frame;
1105 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
1107 if (!terminal->name)
1108 error ("Terminal is not live, can't create new frames on it");
1110 f = make_frame (1);
1112 XSETFRAME (frame, f);
1113 Vframe_list = Fcons (frame, Vframe_list);
1115 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
1117 SET_FRAME_VISIBLE (f, 1);
1119 f->terminal = terminal;
1120 f->terminal->reference_count++;
1121 #ifdef MSDOS
1122 f->output_data.tty->display_info = &the_only_display_info;
1123 if (!inhibit_window_system
1124 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
1125 || XFRAME (selected_frame)->output_method == output_msdos_raw))
1126 f->output_method = output_msdos_raw;
1127 else
1128 f->output_method = output_termcap;
1129 #else /* not MSDOS */
1130 f->output_method = output_termcap;
1131 create_tty_output (f);
1132 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
1133 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
1134 #endif /* not MSDOS */
1136 #ifdef HAVE_WINDOW_SYSTEM
1137 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
1138 f->horizontal_scroll_bars = false;
1139 #endif
1141 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
1142 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
1143 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
1144 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
1146 /* Set the top frame to the newly created frame. */
1147 if (FRAMEP (FRAME_TTY (f)->top_frame)
1148 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
1149 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
1151 FRAME_TTY (f)->top_frame = frame;
1153 if (!noninteractive)
1154 init_frame_faces (f);
1156 return f;
1159 /* Get a suitable value for frame parameter PARAMETER for a newly
1160 created frame, based on (1) the user-supplied frame parameter
1161 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
1163 static Lisp_Object
1164 get_future_frame_param (Lisp_Object parameter,
1165 Lisp_Object supplied_parms,
1166 char *current_value)
1168 Lisp_Object result;
1170 result = Fassq (parameter, supplied_parms);
1171 if (NILP (result))
1172 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
1173 if (NILP (result) && current_value != NULL)
1174 result = build_string (current_value);
1175 if (!NILP (result) && !STRINGP (result))
1176 result = XCDR (result);
1177 if (NILP (result) || !STRINGP (result))
1178 result = Qnil;
1180 return result;
1183 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
1184 1, 1, 0,
1185 doc: /* Create an additional terminal frame, possibly on another terminal.
1186 This function takes one argument, an alist specifying frame parameters.
1188 You can create multiple frames on a single text terminal, but only one
1189 of them (the selected terminal frame) is actually displayed.
1191 In practice, generally you don't need to specify any parameters,
1192 except when you want to create a new frame on another terminal.
1193 In that case, the `tty' parameter specifies the device file to open,
1194 and the `tty-type' parameter specifies the terminal type. Example:
1196 (make-terminal-frame \\='((tty . "/dev/pts/5") (tty-type . "xterm")))
1198 Note that changing the size of one terminal frame automatically
1199 affects all frames on the same terminal device. */)
1200 (Lisp_Object parms)
1202 struct frame *f;
1203 struct terminal *t = NULL;
1204 Lisp_Object frame, tem;
1205 struct frame *sf = SELECTED_FRAME ();
1207 #ifdef MSDOS
1208 if (sf->output_method != output_msdos_raw
1209 && sf->output_method != output_termcap)
1210 emacs_abort ();
1211 #else /* not MSDOS */
1213 #ifdef WINDOWSNT /* This should work now! */
1214 if (sf->output_method != output_termcap)
1215 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
1216 #endif
1217 #endif /* not MSDOS */
1220 Lisp_Object terminal;
1222 terminal = Fassq (Qterminal, parms);
1223 if (CONSP (terminal))
1225 terminal = XCDR (terminal);
1226 t = decode_live_terminal (terminal);
1228 #ifdef MSDOS
1229 if (t && t != the_only_display_info.terminal)
1230 /* msdos.c assumes a single tty_display_info object. */
1231 error ("Multiple terminals are not supported on this platform");
1232 if (!t)
1233 t = the_only_display_info.terminal;
1234 #endif
1237 if (!t)
1239 char *name = 0, *type = 0;
1240 Lisp_Object tty, tty_type;
1241 USE_SAFE_ALLOCA;
1243 tty = get_future_frame_param
1244 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1245 ? FRAME_TTY (XFRAME (selected_frame))->name
1246 : NULL));
1247 if (!NILP (tty))
1248 SAFE_ALLOCA_STRING (name, tty);
1250 tty_type = get_future_frame_param
1251 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1252 ? FRAME_TTY (XFRAME (selected_frame))->type
1253 : NULL));
1254 if (!NILP (tty_type))
1255 SAFE_ALLOCA_STRING (type, tty_type);
1257 t = init_tty (name, type, 0); /* Errors are not fatal. */
1258 SAFE_FREE ();
1261 f = make_terminal_frame (t);
1264 int width, height;
1265 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1266 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f),
1267 5, 0, Qterminal_frame);
1270 adjust_frame_glyphs (f);
1271 calculate_costs (f);
1272 XSETFRAME (frame, f);
1274 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1275 store_in_alist (&parms, Qtty,
1276 (t->display_info.tty->name
1277 ? build_string (t->display_info.tty->name)
1278 : Qnil));
1279 /* On terminal frames the `minibuffer' frame parameter is always
1280 virtually t. Avoid that a different value in parms causes
1281 complaints, see Bug#24758. */
1282 store_in_alist (&parms, Qminibuffer, Qt);
1283 Fmodify_frame_parameters (frame, parms);
1285 /* Make the frame face alist be frame-specific, so that each
1286 frame could change its face definitions independently. */
1287 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1288 /* Simple Fcopy_alist isn't enough, because we need the contents of
1289 the vectors which are the CDRs of associations in face_alist to
1290 be copied as well. */
1291 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1292 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1294 f->can_x_set_window_size = true;
1295 f->after_make_frame = true;
1297 return frame;
1301 /* Perform the switch to frame FRAME.
1303 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1304 FRAME1 as frame.
1306 If TRACK is non-zero and the frame that currently has the focus
1307 redirects its focus to the selected frame, redirect that focused
1308 frame's focus to FRAME instead.
1310 FOR_DELETION non-zero means that the selected frame is being
1311 deleted, which includes the possibility that the frame's terminal
1312 is dead.
1314 The value of NORECORD is passed as argument to Fselect_window. */
1316 Lisp_Object
1317 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1319 struct frame *sf = SELECTED_FRAME (), *f;
1321 /* If FRAME is a switch-frame event, extract the frame we should
1322 switch to. */
1323 if (CONSP (frame)
1324 && EQ (XCAR (frame), Qswitch_frame)
1325 && CONSP (XCDR (frame)))
1326 frame = XCAR (XCDR (frame));
1328 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1329 a switch-frame event to arrive after a frame is no longer live,
1330 especially when deleting the initial frame during startup. */
1331 CHECK_FRAME (frame);
1332 f = XFRAME (frame);
1333 if (!FRAME_LIVE_P (f))
1334 return Qnil;
1335 else if (f == sf)
1336 return frame;
1338 /* If a frame's focus has been redirected toward the currently
1339 selected frame, we should change the redirection to point to the
1340 newly selected frame. This means that if the focus is redirected
1341 from a minibufferless frame to a surrogate minibuffer frame, we
1342 can use `other-window' to switch between all the frames using
1343 that minibuffer frame, and the focus redirection will follow us
1344 around. */
1345 #if 0
1346 /* This is too greedy; it causes inappropriate focus redirection
1347 that's hard to get rid of. */
1348 if (track)
1350 Lisp_Object tail;
1352 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1354 Lisp_Object focus;
1356 if (!FRAMEP (XCAR (tail)))
1357 emacs_abort ();
1359 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1361 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1362 Fredirect_frame_focus (XCAR (tail), frame);
1365 #else /* ! 0 */
1366 /* Instead, apply it only to the frame we're pointing to. */
1367 #ifdef HAVE_WINDOW_SYSTEM
1368 if (track && FRAME_WINDOW_P (f))
1370 Lisp_Object focus, xfocus;
1372 xfocus = x_get_focus_frame (f);
1373 if (FRAMEP (xfocus))
1375 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1376 if ((FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1377 /* Redirect frame focus also when FRAME has its minibuffer
1378 window on the selected frame (see Bug#24500). */
1379 || (NILP (focus)
1380 && EQ (FRAME_MINIBUF_WINDOW (f), sf->selected_window)))
1381 Fredirect_frame_focus (xfocus, frame);
1384 #endif /* HAVE_X_WINDOWS */
1385 #endif /* ! 0 */
1387 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1388 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1390 if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
1392 struct tty_display_info *tty = FRAME_TTY (f);
1393 Lisp_Object top_frame = tty->top_frame;
1395 /* Don't mark the frame garbaged and/or obscured if we are
1396 switching to the frame that is already the top frame of that
1397 TTY. */
1398 if (!EQ (frame, top_frame))
1400 if (FRAMEP (top_frame))
1401 /* Mark previously displayed frame as now obscured. */
1402 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1403 SET_FRAME_VISIBLE (f, 1);
1404 /* If the new TTY frame changed dimensions, we need to
1405 resync term.c's idea of the frame size with the new
1406 frame's data. */
1407 if (FRAME_COLS (f) != FrameCols (tty))
1408 FrameCols (tty) = FRAME_COLS (f);
1409 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1410 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1412 tty->top_frame = frame;
1415 selected_frame = frame;
1416 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1417 last_nonminibuf_frame = XFRAME (selected_frame);
1419 Fselect_window (f->selected_window, norecord);
1421 /* We want to make sure that the next event generates a frame-switch
1422 event to the appropriate frame. This seems kludgy to me, but
1423 before you take it out, make sure that evaluating something like
1424 (select-window (frame-root-window (make-frame))) doesn't end up
1425 with your typing being interpreted in the new frame instead of
1426 the one you're actually typing in. */
1427 #ifdef HAVE_WINDOW_SYSTEM
1428 if (!frame_ancestor_p (f, sf))
1429 #endif
1430 internal_last_event_frame = Qnil;
1432 return frame;
1435 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1436 doc: /* Select FRAME.
1437 Subsequent editing commands apply to its selected window.
1438 Optional argument NORECORD means to neither change the order of
1439 recently selected windows nor the buffer list.
1441 The selection of FRAME lasts until the next time the user does
1442 something to select a different frame, or until the next time
1443 this function is called. If you are using a window system, the
1444 previously selected frame may be restored as the selected frame
1445 when returning to the command loop, because it still may have
1446 the window system's input focus. On a text terminal, the next
1447 redisplay will display FRAME.
1449 This function returns FRAME, or nil if FRAME has been deleted. */)
1450 (Lisp_Object frame, Lisp_Object norecord)
1452 return do_switch_frame (frame, 1, 0, norecord);
1455 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1456 doc: /* Handle a switch-frame event EVENT.
1457 Switch-frame events are usually bound to this function.
1458 A switch-frame event is an event Emacs sends itself to
1459 indicate that input is arriving in a new frame. It does not
1460 necessarily represent user-visible input focus. */)
1461 (Lisp_Object event)
1463 /* Preserve prefix arg that the command loop just cleared. */
1464 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1465 run_hook (Qmouse_leave_buffer_hook);
1466 return do_switch_frame (event, 0, 0, Qnil);
1469 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1470 doc: /* Return the frame that is now selected. */)
1471 (void)
1473 return selected_frame;
1476 DEFUN ("frame-list", Fframe_list, Sframe_list,
1477 0, 0, 0,
1478 doc: /* Return a list of all live frames.
1479 The return value does not include any tooltip frame. */)
1480 (void)
1482 #ifdef HAVE_WINDOW_SYSTEM
1483 Lisp_Object list = Qnil, tail, frame;
1485 FOR_EACH_FRAME (tail, frame)
1486 if (!FRAME_TOOLTIP_P (XFRAME (frame)))
1487 list = Fcons (frame, list);
1488 /* Reverse list for consistency with the !HAVE_WINDOW_SYSTEM case. */
1489 return Fnreverse (list);
1490 #else /* !HAVE_WINDOW_SYSTEM */
1491 return Fcopy_sequence (Vframe_list);
1492 #endif /* HAVE_WINDOW_SYSTEM */
1495 DEFUN ("frame-parent", Fframe_parent, Sframe_parent,
1496 0, 1, 0,
1497 doc: /* Return the parent frame of FRAME.
1498 The parent frame of FRAME is the Emacs frame whose window-system window
1499 is the parent window of FRAME's window-system window. When such a frame
1500 exists, FRAME is considered a child frame of that frame.
1502 Return nil if FRAME has no parent frame. This means that FRAME's
1503 window-system window is either a "top-level" window (a window whose
1504 parent window is the window-system's root window) or an embedded window
1505 \(a window whose parent window is owned by some other application). */)
1506 (Lisp_Object frame)
1508 struct frame *f = decode_live_frame (frame);
1509 struct frame *p = FRAME_PARENT_FRAME (f);
1510 Lisp_Object parent;
1512 /* Can't return f->parent_frame directly since it might not be defined
1513 for this platform. */
1514 if (p)
1516 XSETFRAME (parent, p);
1518 return parent;
1520 else
1521 return Qnil;
1524 #ifdef HAVE_WINDOW_SYSTEM
1525 bool
1526 frame_ancestor_p (struct frame *af, struct frame *df)
1528 struct frame *pf = FRAME_PARENT_FRAME (df);
1530 while (pf)
1532 if (pf == af)
1533 return true;
1534 else
1535 pf = FRAME_PARENT_FRAME (pf);
1538 return false;
1540 #endif
1542 DEFUN ("frame-ancestor-p", Fframe_ancestor_p, Sframe_ancestor_p,
1543 2, 2, 0,
1544 doc: /* Return non-nil if ANCESTOR is an ancestor of DESCENDANT.
1545 ANCESTOR is an ancestor of DESCENDANT when it is either DESCENDANT's
1546 parent frame or it is an ancestor of DESCENDANT's parent frame. Both,
1547 ANCESTOR and DESCENDANT must be live frames and default to the selected
1548 frame. */)
1549 (Lisp_Object ancestor, Lisp_Object descendant)
1551 #ifdef HAVE_WINDOW_SYSTEM
1552 struct frame *af = decode_live_frame (ancestor);
1553 struct frame *df = decode_live_frame (descendant);
1555 return frame_ancestor_p (af, df) ? Qt : Qnil;
1556 #else
1557 return Qnil;
1558 #endif
1561 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1562 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1563 If MINIBUF is nil, do not consider minibuffer-only candidate.
1564 If MINIBUF is `visible', do not consider an invisible candidate.
1565 If MINIBUF is a window, consider only its own frame and candidate now
1566 using that window as the minibuffer.
1567 If MINIBUF is 0, consider candidate if it is visible or iconified.
1568 Otherwise consider any candidate and return nil if CANDIDATE is not
1569 acceptable. */
1571 static Lisp_Object
1572 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1574 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1576 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1577 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1578 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1579 && FRAME_TTY (c) == FRAME_TTY (f)))
1581 if (!NILP (get_frame_param (c, Qno_other_frame)))
1582 return Qnil;
1583 else if (NILP (minibuf))
1585 if (!FRAME_MINIBUF_ONLY_P (c))
1586 return candidate;
1588 else if (EQ (minibuf, Qvisible))
1590 if (FRAME_VISIBLE_P (c))
1591 return candidate;
1593 else if (WINDOWP (minibuf))
1595 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1596 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1597 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1598 FRAME_FOCUS_FRAME (c)))
1599 return candidate;
1601 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1603 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1604 return candidate;
1606 else
1607 return candidate;
1609 return Qnil;
1612 /* Return the next frame in the frame list after FRAME. */
1614 static Lisp_Object
1615 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1617 Lisp_Object f, tail;
1618 int passed = 0;
1620 eassume (CONSP (Vframe_list));
1622 while (passed < 2)
1623 FOR_EACH_FRAME (tail, f)
1625 if (passed)
1627 f = candidate_frame (f, frame, minibuf);
1628 if (!NILP (f))
1629 return f;
1631 if (EQ (frame, f))
1632 passed++;
1634 return frame;
1637 /* Return the previous frame in the frame list before FRAME. */
1639 static Lisp_Object
1640 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1642 Lisp_Object f, tail, prev = Qnil;
1644 eassume (CONSP (Vframe_list));
1646 FOR_EACH_FRAME (tail, f)
1648 if (EQ (frame, f) && !NILP (prev))
1649 return prev;
1650 f = candidate_frame (f, frame, minibuf);
1651 if (!NILP (f))
1652 prev = f;
1655 /* We've scanned the entire list. */
1656 if (NILP (prev))
1657 /* We went through the whole frame list without finding a single
1658 acceptable frame. Return the original frame. */
1659 return frame;
1660 else
1661 /* There were no acceptable frames in the list before FRAME; otherwise,
1662 we would have returned directly from the loop. Since PREV is the last
1663 acceptable frame in the list, return it. */
1664 return prev;
1668 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1669 doc: /* Return the next frame in the frame list after FRAME.
1670 It considers only frames on the same terminal as FRAME.
1671 By default, skip minibuffer-only frames.
1672 If omitted, FRAME defaults to the selected frame.
1673 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1674 If MINIFRAME is a window, include only its own frame
1675 and any frame now using that window as the minibuffer.
1676 If MINIFRAME is `visible', include all visible frames.
1677 If MINIFRAME is 0, include all visible and iconified frames.
1678 Otherwise, include all frames. */)
1679 (Lisp_Object frame, Lisp_Object miniframe)
1681 if (NILP (frame))
1682 frame = selected_frame;
1683 CHECK_LIVE_FRAME (frame);
1684 return next_frame (frame, miniframe);
1687 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1688 doc: /* Return the previous frame in the frame list before FRAME.
1689 It considers only frames on the same terminal as FRAME.
1690 By default, skip minibuffer-only frames.
1691 If omitted, FRAME defaults to the selected frame.
1692 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1693 If MINIFRAME is a window, include only its own frame
1694 and any frame now using that window as the minibuffer.
1695 If MINIFRAME is `visible', include all visible frames.
1696 If MINIFRAME is 0, include all visible and iconified frames.
1697 Otherwise, include all frames. */)
1698 (Lisp_Object frame, Lisp_Object miniframe)
1700 if (NILP (frame))
1701 frame = selected_frame;
1702 CHECK_LIVE_FRAME (frame);
1703 return prev_frame (frame, miniframe);
1706 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1707 Slast_nonminibuf_frame, 0, 0, 0,
1708 doc: /* Return last non-minibuffer frame selected. */)
1709 (void)
1711 Lisp_Object frame = Qnil;
1713 if (last_nonminibuf_frame)
1714 XSETFRAME (frame, last_nonminibuf_frame);
1716 return frame;
1720 * other_frames:
1722 * Return true if there exists at least one visible or iconified frame
1723 * but F. Tooltip frames do not qualify as candidates. Return false
1724 * if no such frame exists.
1726 * INVISIBLE true means we are called from make_frame_invisible where
1727 * such a frame must be visible or iconified. INVISIBLE nil means we
1728 * are called from delete_frame. In that case FORCE true means that the
1729 * visibility status of such a frame can be ignored.
1731 * If F is the terminal frame and we are using X, return true if at
1732 * least one X frame exists.
1734 static bool
1735 other_frames (struct frame *f, bool invisible, bool force)
1737 Lisp_Object frames, frame, frame1;
1738 Lisp_Object minibuffer_window = FRAME_MINIBUF_WINDOW (f);
1740 XSETFRAME (frame, f);
1741 if (WINDOWP (minibuffer_window)
1742 && !EQ (frame, WINDOW_FRAME (XWINDOW (minibuffer_window))))
1743 minibuffer_window = Qnil;
1745 FOR_EACH_FRAME (frames, frame1)
1747 struct frame *f1 = XFRAME (frame1);
1749 if (f != f1)
1751 /* Verify that we can still talk to the frame's X window, and
1752 note any recent change in visibility. */
1753 #ifdef HAVE_X_WINDOWS
1754 if (FRAME_WINDOW_P (f1))
1755 x_sync (f1);
1756 #endif
1757 if (!FRAME_TOOLTIP_P (f1)
1758 /* Tooltips and child frames count neither for
1759 invisibility nor for deletions. */
1760 && !FRAME_PARENT_FRAME (f1)
1761 /* Frames with a non-nil `delete-before' parameter don't
1762 count for deletions. */
1763 && (invisible || NILP (get_frame_param (f1, Qdelete_before)))
1764 /* For invisibility and normal deletions, at least one
1765 visible or iconified frame must remain (Bug#26682). */
1766 && (FRAME_VISIBLE_P (f1) || FRAME_ICONIFIED_P (f1)
1767 || (!invisible
1768 && (force
1769 /* Allow deleting the terminal frame when at
1770 least one X frame exists. */
1771 || (FRAME_WINDOW_P (f1) && !FRAME_WINDOW_P (f))))))
1772 return true;
1776 return false;
1779 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1780 window. Preferably use the selected frame's minibuffer window
1781 instead. If the selected frame doesn't have one, get some other
1782 frame's minibuffer window. SELECT non-zero means select the new
1783 minibuffer window. */
1784 static void
1785 check_minibuf_window (Lisp_Object frame, int select)
1787 struct frame *f = decode_live_frame (frame);
1789 XSETFRAME (frame, f);
1791 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1793 Lisp_Object frames, this, window = make_number (0);
1795 if (!EQ (frame, selected_frame)
1796 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1797 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1798 else
1799 FOR_EACH_FRAME (frames, this)
1801 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1803 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1804 break;
1808 /* Don't abort if no window was found (Bug#15247). */
1809 if (WINDOWP (window))
1811 /* Use set_window_buffer instead of Fset_window_buffer (see
1812 discussion of bug#11984, bug#12025, bug#12026). */
1813 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1814 minibuf_window = window;
1816 /* SELECT non-zero usually means that FRAME's minibuffer
1817 window was selected; select the new one. */
1818 if (select)
1819 Fselect_window (minibuf_window, Qnil);
1826 * delete_frame:
1828 * Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1829 * unconditionally. x_connection_closed and delete_terminal use this.
1830 * Any other value of FORCE implements the semantics described for
1831 * Fdelete_frame. */
1832 Lisp_Object
1833 delete_frame (Lisp_Object frame, Lisp_Object force)
1835 struct frame *f = decode_any_frame (frame);
1836 struct frame *sf;
1837 struct kboard *kb;
1838 Lisp_Object frames, frame1;
1839 int minibuffer_selected, is_tooltip_frame;
1840 bool nochild = !FRAME_PARENT_FRAME (f);
1842 if (!FRAME_LIVE_P (f))
1843 return Qnil;
1844 else if (!EQ (force, Qnoelisp) && !other_frames (f, false, !NILP (force)))
1846 if (NILP (force))
1847 error ("Attempt to delete the sole visible or iconified frame");
1848 else
1849 error ("Attempt to delete the only frame");
1852 XSETFRAME (frame, f);
1854 /* Softly delete all frames with this frame as their parent frame or
1855 as their `delete-before' frame parameter value. */
1856 FOR_EACH_FRAME (frames, frame1)
1857 if (FRAME_PARENT_FRAME (XFRAME (frame1)) == f
1858 /* Process `delete-before' parameter iff FRAME is not a child
1859 frame. This avoids that we enter an infinite chain of mixed
1860 dependencies. */
1861 || (nochild
1862 && EQ (get_frame_param (XFRAME (frame1), Qdelete_before), frame)))
1863 delete_frame (frame1, Qnil);
1865 /* Does this frame have a minibuffer, and is it the surrogate
1866 minibuffer for any other frame? */
1867 if (FRAME_HAS_MINIBUF_P (f))
1869 FOR_EACH_FRAME (frames, frame1)
1871 Lisp_Object fminiw;
1873 if (EQ (frame1, frame))
1874 continue;
1876 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (frame1));
1878 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1880 /* If we MUST delete this frame, delete the other first.
1881 But do this only if FORCE equals `noelisp'. */
1882 if (EQ (force, Qnoelisp))
1883 delete_frame (frame1, Qnoelisp);
1884 else
1885 error ("Attempt to delete a surrogate minibuffer frame");
1890 is_tooltip_frame = FRAME_TOOLTIP_P (f);
1892 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1893 frame is a tooltip. FORCE is set to `noelisp' when handling
1894 a disconnect from the terminal, so we don't dare call Lisp
1895 code. */
1896 if (NILP (Vrun_hooks) || is_tooltip_frame)
1898 else if (EQ (force, Qnoelisp))
1899 pending_funcalls
1900 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1901 pending_funcalls);
1902 else
1904 #ifdef HAVE_X_WINDOWS
1905 /* Also, save clipboard to the clipboard manager. */
1906 x_clipboard_manager_save_frame (frame);
1907 #endif
1909 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1912 /* delete_frame_functions may have deleted any frame, including this
1913 one. */
1914 if (!FRAME_LIVE_P (f))
1915 return Qnil;
1916 else if (!EQ (force, Qnoelisp) && !other_frames (f, false, !NILP (force)))
1918 if (NILP (force))
1919 error ("Attempt to delete the sole visible or iconified frame");
1920 else
1921 error ("Attempt to delete the only frame");
1924 /* At this point, we are committed to deleting the frame.
1925 There is no more chance for errors to prevent it. */
1926 minibuffer_selected = EQ (minibuf_window, selected_window);
1927 sf = SELECTED_FRAME ();
1928 /* Don't let the frame remain selected. */
1929 if (f == sf)
1931 Lisp_Object tail;
1932 Lisp_Object frame1 UNINIT; /* This line works around GCC bug 85563. */
1933 eassume (CONSP (Vframe_list));
1935 /* Look for another visible frame on the same terminal.
1936 Do not call next_frame here because it may loop forever.
1937 See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1938 FOR_EACH_FRAME (tail, frame1)
1940 struct frame *f1 = XFRAME (frame1);
1942 if (!EQ (frame, frame1)
1943 && !FRAME_TOOLTIP_P (f1)
1944 && FRAME_TERMINAL (f) == FRAME_TERMINAL (f1)
1945 && FRAME_VISIBLE_P (f1))
1946 break;
1949 /* If there is none, find *some* other frame. */
1950 if (NILP (frame1) || EQ (frame1, frame))
1952 FOR_EACH_FRAME (tail, frame1)
1954 struct frame *f1 = XFRAME (frame1);
1956 if (!EQ (frame, frame1)
1957 && FRAME_LIVE_P (f1)
1958 && !FRAME_TOOLTIP_P (f1))
1960 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1962 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1964 if (!EQ (top_frame, frame))
1965 frame1 = top_frame;
1967 break;
1971 #ifdef NS_IMPL_COCOA
1972 else
1973 /* Under NS, there is no system mechanism for choosing a new
1974 window to get focus -- it is left to application code.
1975 So the portion of THIS application interfacing with NS
1976 needs to know about it. We call Fraise_frame, but the
1977 purpose is really to transfer focus. */
1978 Fraise_frame (frame1);
1979 #endif
1981 do_switch_frame (frame1, 0, 1, Qnil);
1982 sf = SELECTED_FRAME ();
1985 /* Don't allow minibuf_window to remain on a deleted frame. */
1986 check_minibuf_window (frame, minibuffer_selected);
1988 /* Don't let echo_area_window to remain on a deleted frame. */
1989 if (EQ (f->minibuffer_window, echo_area_window))
1990 echo_area_window = sf->minibuffer_window;
1992 /* Clear any X selections for this frame. */
1993 #ifdef HAVE_X_WINDOWS
1994 if (FRAME_X_P (f))
1995 x_clear_frame_selections (f);
1996 #endif
1998 /* Free glyphs.
1999 This function must be called before the window tree of the
2000 frame is deleted because windows contain dynamically allocated
2001 memory. */
2002 free_glyphs (f);
2004 #ifdef HAVE_WINDOW_SYSTEM
2005 /* Give chance to each font driver to free a frame specific data. */
2006 font_update_drivers (f, Qnil);
2007 #endif
2009 /* Mark all the windows that used to be on FRAME as deleted, and then
2010 remove the reference to them. */
2011 delete_all_child_windows (f->root_window);
2012 fset_root_window (f, Qnil);
2014 Vframe_list = Fdelq (frame, Vframe_list);
2015 SET_FRAME_VISIBLE (f, 0);
2017 /* Allow the vector of menu bar contents to be freed in the next
2018 garbage collection. The frame object itself may not be garbage
2019 collected until much later, because recent_keys and other data
2020 structures can still refer to it. */
2021 fset_menu_bar_vector (f, Qnil);
2023 /* If FRAME's buffer lists contains killed
2024 buffers, this helps GC to reclaim them. */
2025 fset_buffer_list (f, Qnil);
2026 fset_buried_buffer_list (f, Qnil);
2028 free_font_driver_list (f);
2029 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2030 xfree (f->namebuf);
2031 #endif
2032 xfree (f->decode_mode_spec_buffer);
2033 xfree (FRAME_INSERT_COST (f));
2034 xfree (FRAME_DELETEN_COST (f));
2035 xfree (FRAME_INSERTN_COST (f));
2036 xfree (FRAME_DELETE_COST (f));
2038 /* Since some events are handled at the interrupt level, we may get
2039 an event for f at any time; if we zero out the frame's terminal
2040 now, then we may trip up the event-handling code. Instead, we'll
2041 promise that the terminal of the frame must be valid until we
2042 have called the window-system-dependent frame destruction
2043 routine. */
2045 struct terminal *terminal;
2046 block_input ();
2047 if (FRAME_TERMINAL (f)->delete_frame_hook)
2048 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
2049 terminal = FRAME_TERMINAL (f);
2050 f->output_data.nothing = 0;
2051 f->terminal = 0; /* Now the frame is dead. */
2052 unblock_input ();
2054 /* If needed, delete the terminal that this frame was on.
2055 (This must be done after the frame is killed.) */
2056 terminal->reference_count--;
2057 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
2058 /* FIXME: Deleting the terminal crashes emacs because of a GTK
2059 bug.
2060 https://lists.gnu.org/r/emacs-devel/2011-10/msg00363.html */
2062 /* Since a similar behavior was observed on the Lucid and Motif
2063 builds (see Bug#5802, Bug#21509, Bug#23499, Bug#27816), we now
2064 don't delete the terminal for these builds either. */
2065 if (terminal->reference_count == 0 && terminal->type == output_x_window)
2066 terminal->reference_count = 1;
2067 #endif /* USE_X_TOOLKIT || USE_GTK */
2068 if (terminal->reference_count == 0)
2070 Lisp_Object tmp;
2071 XSETTERMINAL (tmp, terminal);
2073 kb = NULL;
2074 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
2076 else
2077 kb = terminal->kboard;
2080 /* If we've deleted the last_nonminibuf_frame, then try to find
2081 another one. */
2082 if (f == last_nonminibuf_frame)
2084 last_nonminibuf_frame = 0;
2086 FOR_EACH_FRAME (frames, frame1)
2088 struct frame *f1 = XFRAME (frame1);
2090 if (!FRAME_MINIBUF_ONLY_P (f1))
2092 last_nonminibuf_frame = f1;
2093 break;
2098 /* If there's no other frame on the same kboard, get out of
2099 single-kboard state if we're in it for this kboard. */
2100 if (kb != NULL)
2102 /* Some frame we found on the same kboard, or nil if there are none. */
2103 Lisp_Object frame_on_same_kboard = Qnil;
2105 FOR_EACH_FRAME (frames, frame1)
2106 if (kb == FRAME_KBOARD (XFRAME (frame1)))
2107 frame_on_same_kboard = frame1;
2109 if (NILP (frame_on_same_kboard))
2110 not_single_kboard_state (kb);
2114 /* If we've deleted this keyboard's default_minibuffer_frame, try to
2115 find another one. Prefer minibuffer-only frames, but also notice
2116 frames with other windows. */
2117 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
2119 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
2120 Lisp_Object frame_with_minibuf = Qnil;
2121 /* Some frame we found on the same kboard, or nil if there are none. */
2122 Lisp_Object frame_on_same_kboard = Qnil;
2124 FOR_EACH_FRAME (frames, frame1)
2126 struct frame *f1 = XFRAME (frame1);
2128 /* Consider only frames on the same kboard
2129 and only those with minibuffers. */
2130 if (kb == FRAME_KBOARD (f1)
2131 && FRAME_HAS_MINIBUF_P (f1))
2133 frame_with_minibuf = frame1;
2134 if (FRAME_MINIBUF_ONLY_P (f1))
2135 break;
2138 if (kb == FRAME_KBOARD (f1))
2139 frame_on_same_kboard = frame1;
2142 if (!NILP (frame_on_same_kboard))
2144 /* We know that there must be some frame with a minibuffer out
2145 there. If this were not true, all of the frames present
2146 would have to be minibufferless, which implies that at some
2147 point their minibuffer frames must have been deleted, but
2148 that is prohibited at the top; you can't delete surrogate
2149 minibuffer frames. */
2150 if (NILP (frame_with_minibuf))
2151 emacs_abort ();
2153 kset_default_minibuffer_frame (kb, frame_with_minibuf);
2155 else
2156 /* No frames left on this kboard--say no minibuffer either. */
2157 kset_default_minibuffer_frame (kb, Qnil);
2160 /* Cause frame titles to update--necessary if we now have just one frame. */
2161 if (!is_tooltip_frame)
2162 update_mode_lines = 15;
2164 /* Now run the post-deletion hooks. */
2165 if (NILP (Vrun_hooks) || is_tooltip_frame)
2167 else if (EQ (force, Qnoelisp))
2168 pending_funcalls
2169 = Fcons (list3 (Qrun_hook_with_args, Qafter_delete_frame_functions, frame),
2170 pending_funcalls);
2171 else
2172 safe_call2 (Qrun_hook_with_args, Qafter_delete_frame_functions, frame);
2174 return Qnil;
2177 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
2178 doc: /* Delete FRAME, permanently eliminating it from use.
2179 FRAME must be a live frame and defaults to the selected one.
2181 A frame may not be deleted if its minibuffer serves as surrogate
2182 minibuffer for another frame. Normally, you may not delete a frame if
2183 all other frames are invisible, but if the second optional argument
2184 FORCE is non-nil, you may do so.
2186 This function runs `delete-frame-functions' before actually
2187 deleting the frame, unless the frame is a tooltip.
2188 The functions are run with one argument, the frame to be deleted. */)
2189 (Lisp_Object frame, Lisp_Object force)
2191 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
2194 #ifdef HAVE_WINDOW_SYSTEM
2196 * frame_internal_border_part:
2198 * Return part of internal border the coordinates X and Y relative to
2199 * frame F are on. Return nil if the coordinates are not on the
2200 * internal border of F.
2202 * Return one of INTERNAL_BORDER_LEFT_EDGE, INTERNAL_BORDER_TOP_EDGE,
2203 * INTERNAL_BORDER_RIGHT_EDGE or INTERNAL_BORDER_BOTTOM_EDGE when the
2204 * mouse cursor is on the corresponding border with an offset of at
2205 * least one canonical character height from that border's edges.
2207 * If no border part could be found this way, return one of
2208 * INTERNAL_BORDER_TOP_LEFT_CORNER, INTERNAL_BORDER_TOP_RIGHT_CORNER,
2209 * INTERNAL_BORDER_BOTTOM_LEFT_CORNER or
2210 * INTERNAL_BORDER_BOTTOM_RIGHT_CORNER to indicate that the mouse is in
2211 * one of the corresponding corners. This means that for very small
2212 * frames an `edge' return value is preferred.
2214 enum internal_border_part
2215 frame_internal_border_part (struct frame *f, int x, int y)
2217 int border = FRAME_INTERNAL_BORDER_WIDTH (f);
2218 int offset = FRAME_LINE_HEIGHT (f);
2219 int width = FRAME_PIXEL_WIDTH (f);
2220 int height = FRAME_PIXEL_HEIGHT (f);
2221 enum internal_border_part part = INTERNAL_BORDER_NONE;
2223 if (offset < border)
2224 /* For very wide borders make offset at least as large as
2225 border. */
2226 offset = border;
2228 if (offset < x && x < width - offset)
2229 /* Top or bottom border. */
2231 if (0 <= y && y <= border)
2232 part = INTERNAL_BORDER_TOP_EDGE;
2233 else if (height - border <= y && y <= height)
2234 part = INTERNAL_BORDER_BOTTOM_EDGE;
2236 else if (offset < y && y < height - offset)
2237 /* Left or right border. */
2239 if (0 <= x && x <= border)
2240 part = INTERNAL_BORDER_LEFT_EDGE;
2241 else if (width - border <= x && x <= width)
2242 part = INTERNAL_BORDER_RIGHT_EDGE;
2244 else
2246 /* An edge. */
2247 int half_width = width / 2;
2248 int half_height = height / 2;
2250 if (0 <= x && x <= border)
2252 /* A left edge. */
2253 if (0 <= y && y <= half_height)
2254 part = INTERNAL_BORDER_TOP_LEFT_CORNER;
2255 else if (half_height < y && y <= height)
2256 part = INTERNAL_BORDER_BOTTOM_LEFT_CORNER;
2258 else if (width - border <= x && x <= width)
2260 /* A right edge. */
2261 if (0 <= y && y <= half_height)
2262 part = INTERNAL_BORDER_TOP_RIGHT_CORNER;
2263 else if (half_height < y && y <= height)
2264 part = INTERNAL_BORDER_BOTTOM_RIGHT_CORNER;
2266 else if (0 <= y && y <= border)
2268 /* A top edge. */
2269 if (0 <= x && x <= half_width)
2270 part = INTERNAL_BORDER_TOP_LEFT_CORNER;
2271 else if (half_width < x && x <= width)
2272 part = INTERNAL_BORDER_TOP_RIGHT_CORNER;
2274 else if (height - border <= y && y <= height)
2276 /* A bottom edge. */
2277 if (0 <= x && x <= half_width)
2278 part = INTERNAL_BORDER_BOTTOM_LEFT_CORNER;
2279 else if (half_width < x && x <= width)
2280 part = INTERNAL_BORDER_BOTTOM_RIGHT_CORNER;
2284 return part;
2286 #endif
2288 /* Return mouse position in character cell units. */
2290 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
2291 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
2292 The position is given in canonical character cells, where (0, 0) is the
2293 upper-left corner of the frame, X is the horizontal offset, and Y is the
2294 vertical offset, measured in units of the frame's default character size.
2295 If Emacs is running on a mouseless terminal or hasn't been programmed
2296 to read the mouse position, it returns the selected frame for FRAME
2297 and nil for X and Y.
2298 If `mouse-position-function' is non-nil, `mouse-position' calls it,
2299 passing the normal return value to that function as an argument,
2300 and returns whatever that function returns. */)
2301 (void)
2303 struct frame *f;
2304 Lisp_Object lispy_dummy;
2305 Lisp_Object x, y, retval;
2307 f = SELECTED_FRAME ();
2308 x = y = Qnil;
2310 /* It's okay for the hook to refrain from storing anything. */
2311 if (FRAME_TERMINAL (f)->mouse_position_hook)
2313 enum scroll_bar_part party_dummy;
2314 Time time_dummy;
2315 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
2316 &lispy_dummy, &party_dummy,
2317 &x, &y,
2318 &time_dummy);
2321 if (! NILP (x))
2323 int col = XINT (x);
2324 int row = XINT (y);
2325 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
2326 XSETINT (x, col);
2327 XSETINT (y, row);
2329 XSETFRAME (lispy_dummy, f);
2330 retval = Fcons (lispy_dummy, Fcons (x, y));
2331 if (!NILP (Vmouse_position_function))
2332 retval = call1 (Vmouse_position_function, retval);
2333 return retval;
2336 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
2337 Smouse_pixel_position, 0, 0, 0,
2338 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
2339 The position is given in pixel units, where (0, 0) is the
2340 upper-left corner of the frame, X is the horizontal offset, and Y is
2341 the vertical offset.
2342 If Emacs is running on a mouseless terminal or hasn't been programmed
2343 to read the mouse position, it returns the selected frame for FRAME
2344 and nil for X and Y. */)
2345 (void)
2347 struct frame *f;
2348 Lisp_Object lispy_dummy;
2349 Lisp_Object x, y, retval;
2351 f = SELECTED_FRAME ();
2352 x = y = Qnil;
2354 /* It's okay for the hook to refrain from storing anything. */
2355 if (FRAME_TERMINAL (f)->mouse_position_hook)
2357 enum scroll_bar_part party_dummy;
2358 Time time_dummy;
2359 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
2360 &lispy_dummy, &party_dummy,
2361 &x, &y,
2362 &time_dummy);
2365 XSETFRAME (lispy_dummy, f);
2366 retval = Fcons (lispy_dummy, Fcons (x, y));
2367 if (!NILP (Vmouse_position_function))
2368 retval = call1 (Vmouse_position_function, retval);
2369 return retval;
2372 #ifdef HAVE_WINDOW_SYSTEM
2374 /* On frame F, convert character coordinates X and Y to pixel
2375 coordinates *PIX_X and *PIX_Y. */
2377 static void
2378 frame_char_to_pixel_position (struct frame *f, int x, int y,
2379 int *pix_x, int *pix_y)
2381 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
2382 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
2384 if (*pix_x < 0)
2385 *pix_x = 0;
2386 if (*pix_x > FRAME_PIXEL_WIDTH (f))
2387 *pix_x = FRAME_PIXEL_WIDTH (f);
2389 if (*pix_y < 0)
2390 *pix_y = 0;
2391 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
2392 *pix_y = FRAME_PIXEL_HEIGHT (f);
2395 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
2397 static void
2398 frame_set_mouse_position (struct frame *f, int x, int y)
2400 int pix_x, pix_y;
2402 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
2403 frame_set_mouse_pixel_position (f, pix_x, pix_y);
2406 #endif /* HAVE_WINDOW_SYSTEM */
2408 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
2409 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
2410 Coordinates are relative to the frame, not a window,
2411 so the coordinates of the top left character in the frame
2412 may be nonzero due to left-hand scroll bars or the menu bar.
2414 The position is given in canonical character cells, where (0, 0) is
2415 the upper-left corner of the frame, X is the horizontal offset, and
2416 Y is the vertical offset, measured in units of the frame's default
2417 character size.
2419 This function is a no-op for an X frame that is not visible.
2420 If you have just created a frame, you must wait for it to become visible
2421 before calling this function on it, like this.
2422 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2423 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2425 CHECK_LIVE_FRAME (frame);
2426 CHECK_TYPE_RANGED_INTEGER (int, x);
2427 CHECK_TYPE_RANGED_INTEGER (int, y);
2429 /* I think this should be done with a hook. */
2430 #ifdef HAVE_WINDOW_SYSTEM
2431 if (FRAME_WINDOW_P (XFRAME (frame)))
2432 /* Warping the mouse will cause enternotify and focus events. */
2433 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
2434 #else
2435 #if defined (MSDOS)
2436 if (FRAME_MSDOS_P (XFRAME (frame)))
2438 Fselect_frame (frame, Qnil);
2439 mouse_moveto (XINT (x), XINT (y));
2441 #else
2442 #ifdef HAVE_GPM
2444 Fselect_frame (frame, Qnil);
2445 term_mouse_moveto (XINT (x), XINT (y));
2447 #endif
2448 #endif
2449 #endif
2451 return Qnil;
2454 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
2455 Sset_mouse_pixel_position, 3, 3, 0,
2456 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
2457 The position is given in pixels, where (0, 0) is the upper-left corner
2458 of the frame, X is the horizontal offset, and Y is the vertical offset.
2460 Note, this is a no-op for an X frame that is not visible.
2461 If you have just created a frame, you must wait for it to become visible
2462 before calling this function on it, like this.
2463 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2464 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2466 CHECK_LIVE_FRAME (frame);
2467 CHECK_TYPE_RANGED_INTEGER (int, x);
2468 CHECK_TYPE_RANGED_INTEGER (int, y);
2470 /* I think this should be done with a hook. */
2471 #ifdef HAVE_WINDOW_SYSTEM
2472 if (FRAME_WINDOW_P (XFRAME (frame)))
2473 /* Warping the mouse will cause enternotify and focus events. */
2474 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
2475 #else
2476 #if defined (MSDOS)
2477 if (FRAME_MSDOS_P (XFRAME (frame)))
2479 Fselect_frame (frame, Qnil);
2480 mouse_moveto (XINT (x), XINT (y));
2482 #else
2483 #ifdef HAVE_GPM
2485 Fselect_frame (frame, Qnil);
2486 term_mouse_moveto (XINT (x), XINT (y));
2488 #endif
2489 #endif
2490 #endif
2492 return Qnil;
2495 static void make_frame_visible_1 (Lisp_Object);
2497 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2498 0, 1, "",
2499 doc: /* Make the frame FRAME visible (assuming it is an X window).
2500 If omitted, FRAME defaults to the currently selected frame. */)
2501 (Lisp_Object frame)
2503 struct frame *f = decode_live_frame (frame);
2505 /* I think this should be done with a hook. */
2506 #ifdef HAVE_WINDOW_SYSTEM
2507 if (FRAME_WINDOW_P (f))
2508 x_make_frame_visible (f);
2509 #endif
2511 make_frame_visible_1 (f->root_window);
2513 /* Make menu bar update for the Buffers and Frames menus. */
2514 /* windows_or_buffers_changed = 15; FIXME: Why? */
2516 XSETFRAME (frame, f);
2517 return frame;
2520 /* Update the display_time slot of the buffers shown in WINDOW
2521 and all its descendants. */
2523 static void
2524 make_frame_visible_1 (Lisp_Object window)
2526 struct window *w;
2528 for (; !NILP (window); window = w->next)
2530 w = XWINDOW (window);
2531 if (WINDOWP (w->contents))
2532 make_frame_visible_1 (w->contents);
2533 else
2534 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2538 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2539 0, 2, "",
2540 doc: /* Make the frame FRAME invisible.
2541 If omitted, FRAME defaults to the currently selected frame.
2542 On graphical displays, invisible frames are not updated and are
2543 usually not displayed at all, even in a window system's \"taskbar\".
2545 Normally you may not make FRAME invisible if all other frames are invisible,
2546 but if the second optional argument FORCE is non-nil, you may do so.
2548 This function has no effect on text terminal frames. Such frames are
2549 always considered visible, whether or not they are currently being
2550 displayed in the terminal. */)
2551 (Lisp_Object frame, Lisp_Object force)
2553 struct frame *f = decode_live_frame (frame);
2555 if (NILP (force) && !other_frames (f, true, false))
2556 error ("Attempt to make invisible the sole visible or iconified frame");
2558 /* Don't allow minibuf_window to remain on an invisible frame. */
2559 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2561 /* I think this should be done with a hook. */
2562 #ifdef HAVE_WINDOW_SYSTEM
2563 if (FRAME_WINDOW_P (f))
2564 x_make_frame_invisible (f);
2565 #endif
2567 /* Make menu bar update for the Buffers and Frames menus. */
2568 windows_or_buffers_changed = 16;
2570 return Qnil;
2573 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2574 0, 1, "",
2575 doc: /* Make the frame FRAME into an icon.
2576 If omitted, FRAME defaults to the currently selected frame.
2578 If FRAME is a child frame, consult the variable `iconify-child-frame'
2579 for how to proceed. */)
2580 (Lisp_Object frame)
2582 struct frame *f = decode_live_frame (frame);
2583 #ifdef HAVE_WINDOW_SYSTEM
2584 Lisp_Object parent = f->parent_frame;
2586 if (!NILP (parent))
2588 if (NILP (iconify_child_frame))
2589 /* Do nothing. */
2590 return Qnil;
2591 else if (EQ (iconify_child_frame, Qiconify_top_level))
2593 /* Iconify top level frame instead (the default). */
2594 Ficonify_frame (parent);
2595 return Qnil;
2597 else if (EQ (iconify_child_frame, Qmake_invisible))
2599 /* Make frame invisible instead. */
2600 Fmake_frame_invisible (frame, Qnil);
2601 return Qnil;
2604 #endif /* HAVE_WINDOW_SYSTEM */
2606 /* Don't allow minibuf_window to remain on an iconified frame. */
2607 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2609 /* I think this should be done with a hook. */
2610 if (FRAME_WINDOW_P (f))
2612 #ifdef HAVE_WINDOW_SYSTEM
2613 x_iconify_frame (f);
2614 #endif
2617 return Qnil;
2620 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2621 1, 1, 0,
2622 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2623 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2624 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2625 On graphical displays, invisible frames are not updated and are
2626 usually not displayed at all, even in a window system's \"taskbar\".
2628 If FRAME is a text terminal frame, this always returns t.
2629 Such frames are always considered visible, whether or not they are
2630 currently being displayed on the terminal. */)
2631 (Lisp_Object frame)
2633 CHECK_LIVE_FRAME (frame);
2635 if (FRAME_VISIBLE_P (XFRAME (frame)))
2636 return Qt;
2637 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2638 return Qicon;
2639 return Qnil;
2642 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2643 0, 0, 0,
2644 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2645 (void)
2647 Lisp_Object tail, frame, value = Qnil;
2649 FOR_EACH_FRAME (tail, frame)
2650 if (FRAME_VISIBLE_P (XFRAME (frame)))
2651 value = Fcons (frame, value);
2653 return value;
2657 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2658 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2659 If FRAME is invisible or iconified, make it visible.
2660 If you don't specify a frame, the selected frame is used.
2661 If Emacs is displaying on an ordinary terminal or some other device which
2662 doesn't support multiple overlapping frames, this function selects FRAME. */)
2663 (Lisp_Object frame)
2665 struct frame *f = decode_live_frame (frame);
2667 XSETFRAME (frame, f);
2669 if (FRAME_TERMCAP_P (f))
2670 /* On a text terminal select FRAME. */
2671 Fselect_frame (frame, Qnil);
2672 else
2673 /* Do like the documentation says. */
2674 Fmake_frame_visible (frame);
2676 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2677 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2679 return Qnil;
2682 /* Should we have a corresponding function called Flower_Power? */
2683 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2684 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2685 If you don't specify a frame, the selected frame is used.
2686 If Emacs is displaying on an ordinary terminal or some other device which
2687 doesn't support multiple overlapping frames, this function does nothing. */)
2688 (Lisp_Object frame)
2690 struct frame *f = decode_live_frame (frame);
2692 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2693 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2695 return Qnil;
2699 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2700 1, 2, 0,
2701 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2702 In other words, switch-frame events caused by events in FRAME will
2703 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2704 FOCUS-FRAME after reading an event typed at FRAME.
2706 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2707 frame again receives its own keystrokes.
2709 Focus redirection is useful for temporarily redirecting keystrokes to
2710 a surrogate minibuffer frame when a frame doesn't have its own
2711 minibuffer window.
2713 A frame's focus redirection can be changed by `select-frame'. If frame
2714 FOO is selected, and then a different frame BAR is selected, any
2715 frames redirecting their focus to FOO are shifted to redirect their
2716 focus to BAR. This allows focus redirection to work properly when the
2717 user switches from one frame to another using `select-window'.
2719 This means that a frame whose focus is redirected to itself is treated
2720 differently from a frame whose focus is redirected to nil; the former
2721 is affected by `select-frame', while the latter is not.
2723 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2724 (Lisp_Object frame, Lisp_Object focus_frame)
2726 /* Note that we don't check for a live frame here. It's reasonable
2727 to redirect the focus of a frame you're about to delete, if you
2728 know what other frame should receive those keystrokes. */
2729 struct frame *f = decode_any_frame (frame);
2731 if (! NILP (focus_frame))
2732 CHECK_LIVE_FRAME (focus_frame);
2734 fset_focus_frame (f, focus_frame);
2736 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2737 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2739 return Qnil;
2743 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2744 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2745 If FRAME is omitted or nil, the selected frame is used.
2746 Return nil if FRAME's focus is not redirected.
2747 See `redirect-frame-focus'. */)
2748 (Lisp_Object frame)
2750 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2753 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 2, 0,
2754 doc: /* Set the input focus to FRAME.
2755 FRAME nil means use the selected frame. Optional argument NOACTIVATE
2756 means do not activate FRAME.
2758 If there is no window system support, this function does nothing. */)
2759 (Lisp_Object frame, Lisp_Object noactivate)
2761 #ifdef HAVE_WINDOW_SYSTEM
2762 x_focus_frame (decode_window_system_frame (frame), !NILP (noactivate));
2763 #endif
2764 return Qnil;
2767 DEFUN ("frame-after-make-frame",
2768 Fframe_after_make_frame,
2769 Sframe_after_make_frame, 2, 2, 0,
2770 doc: /* Mark FRAME as made.
2771 FRAME nil means use the selected frame. Second argument MADE non-nil
2772 means functions on `window-configuration-change-hook' are called
2773 whenever the window configuration of FRAME changes. MADE nil means
2774 these functions are not called.
2776 This function is currently called by `make-frame' only and should be
2777 otherwise used with utter care to avoid that running functions on
2778 `window-configuration-change-hook' is impeded forever. */)
2779 (Lisp_Object frame, Lisp_Object made)
2781 struct frame *f = decode_live_frame (frame);
2782 f->after_make_frame = !NILP (made);
2783 f->inhibit_horizontal_resize = false;
2784 f->inhibit_vertical_resize = false;
2785 return made;
2789 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2791 void
2792 frames_discard_buffer (Lisp_Object buffer)
2794 Lisp_Object frame, tail;
2796 FOR_EACH_FRAME (tail, frame)
2798 fset_buffer_list
2799 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2800 fset_buried_buffer_list
2801 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2805 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2806 If the alist already has an element for PROP, we change it. */
2808 void
2809 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2811 register Lisp_Object tem;
2813 tem = Fassq (prop, *alistptr);
2814 if (EQ (tem, Qnil))
2815 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2816 else
2817 Fsetcdr (tem, val);
2820 static int
2821 frame_name_fnn_p (char *str, ptrdiff_t len)
2823 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2825 char *p = str + 2;
2826 while ('0' <= *p && *p <= '9')
2827 p++;
2828 if (p == str + len)
2829 return 1;
2831 return 0;
2834 /* Set the name of the terminal frame. Also used by MSDOS frames.
2835 Modeled after x_set_name which is used for WINDOW frames. */
2837 static void
2838 set_term_frame_name (struct frame *f, Lisp_Object name)
2840 f->explicit_name = ! NILP (name);
2842 /* If NAME is nil, set the name to F<num>. */
2843 if (NILP (name))
2845 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2847 /* Check for no change needed in this very common case
2848 before we do any consing. */
2849 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2850 return;
2852 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2854 else
2856 CHECK_STRING (name);
2858 /* Don't change the name if it's already NAME. */
2859 if (! NILP (Fstring_equal (name, f->name)))
2860 return;
2862 /* Don't allow the user to set the frame name to F<num>, so it
2863 doesn't clash with the names we generate for terminal frames. */
2864 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2865 error ("Frame names of the form F<num> are usurped by Emacs");
2868 fset_name (f, name);
2869 update_mode_lines = 16;
2872 void
2873 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2875 register Lisp_Object old_alist_elt;
2877 if (EQ (prop, Qminibuffer))
2879 if (WINDOWP (val))
2881 if (!MINI_WINDOW_P (XWINDOW (val)))
2882 error ("The `minibuffer' parameter does not specify a valid minibuffer window");
2883 else if (FRAME_MINIBUF_ONLY_P (f))
2885 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2886 val = Qonly;
2887 else
2888 error ("Can't change the minibuffer window of a minibuffer-only frame");
2890 else if (FRAME_HAS_MINIBUF_P (f))
2892 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2893 val = Qt;
2894 else
2895 error ("Can't change the minibuffer window of a frame with its own minibuffer");
2897 else
2898 /* Store the chosen minibuffer window. */
2899 fset_minibuffer_window (f, val);
2901 else
2903 Lisp_Object old_val = Fcdr (Fassq (Qminibuffer, f->param_alist));
2905 if (!NILP (old_val))
2907 if (WINDOWP (old_val) && NILP (val))
2908 /* Don't change the value for a minibuffer-less frame if
2909 only nil was specified as new value. */
2910 val = old_val;
2911 else if (!EQ (old_val, val))
2912 error ("Can't change the `minibuffer' parameter of this frame");
2917 /* Check each parent-frame and delete-before parameter for a
2918 circular dependency. Do not check between parameters, so you can
2919 still create circular dependencies with different properties, for
2920 example a chain of frames F1->F2->...Fn such that F1 is an ancestor
2921 frame of Fn and thus cannot be deleted before Fn and a second chain
2922 Fn->Fn-1->...F1 such that Fn cannot be deleted before F1. */
2923 else if (EQ (prop, Qparent_frame) || EQ (prop, Qdelete_before))
2925 Lisp_Object oldval = Fcdr (Fassq (prop, f->param_alist));
2927 if (!EQ (oldval, val) && !NILP (val))
2929 Lisp_Object frame;
2930 Lisp_Object frame1 = val;
2932 if (!FRAMEP (frame1) || !FRAME_LIVE_P (XFRAME (frame1)))
2933 error ("Invalid `%s' frame parameter",
2934 SSDATA (SYMBOL_NAME (prop)));
2936 XSETFRAME (frame, f);
2938 while (FRAMEP (frame1) && FRAME_LIVE_P (XFRAME (frame1)))
2939 if (EQ (frame1, frame))
2940 error ("Circular specification of `%s' frame parameter",
2941 SSDATA (SYMBOL_NAME (prop)));
2942 else
2943 frame1 = get_frame_param (XFRAME (frame1), prop);
2947 /* The buffer-list parameters are stored in a special place and not
2948 in the alist. All buffers must be live. */
2949 else if (EQ (prop, Qbuffer_list))
2951 Lisp_Object list = Qnil;
2952 for (; CONSP (val); val = XCDR (val))
2953 if (!NILP (Fbuffer_live_p (XCAR (val))))
2954 list = Fcons (XCAR (val), list);
2955 fset_buffer_list (f, Fnreverse (list));
2956 return;
2958 else if (EQ (prop, Qburied_buffer_list))
2960 Lisp_Object list = Qnil;
2961 for (; CONSP (val); val = XCDR (val))
2962 if (!NILP (Fbuffer_live_p (XCAR (val))))
2963 list = Fcons (XCAR (val), list);
2964 fset_buried_buffer_list (f, Fnreverse (list));
2965 return;
2968 /* The tty color needed to be set before the frame's parameter
2969 alist was updated with the new value. This is not true any more,
2970 but we still do this test early on. */
2971 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2972 && f == FRAME_TTY (f)->previous_frame)
2973 /* Force redisplay of this tty. */
2974 FRAME_TTY (f)->previous_frame = NULL;
2976 /* Update the frame parameter alist. */
2977 old_alist_elt = Fassq (prop, f->param_alist);
2978 if (EQ (old_alist_elt, Qnil))
2979 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2980 else
2981 Fsetcdr (old_alist_elt, val);
2983 /* Update some other special parameters in their special places
2984 in addition to the alist. */
2986 if (EQ (prop, Qbuffer_predicate))
2987 fset_buffer_predicate (f, val);
2989 if (! FRAME_WINDOW_P (f))
2991 if (EQ (prop, Qmenu_bar_lines))
2992 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2993 else if (EQ (prop, Qname))
2994 set_term_frame_name (f, val);
2998 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2999 is not an unspecified foreground or background color. */
3001 static Lisp_Object
3002 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
3004 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
3005 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
3006 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
3007 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
3010 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
3011 doc: /* Return the parameters-alist of frame FRAME.
3012 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
3013 The meaningful PARMs depend on the kind of frame.
3014 If FRAME is omitted or nil, return information on the currently selected frame. */)
3015 (Lisp_Object frame)
3017 Lisp_Object alist;
3018 struct frame *f = decode_any_frame (frame);
3019 int height, width;
3021 if (!FRAME_LIVE_P (f))
3022 return Qnil;
3024 alist = Fcopy_alist (f->param_alist);
3026 if (!FRAME_WINDOW_P (f))
3028 Lisp_Object elt;
3030 /* If the frame's parameter alist says the colors are
3031 unspecified and reversed, take the frame's background pixel
3032 for foreground and vice versa. */
3033 elt = Fassq (Qforeground_color, alist);
3034 if (CONSP (elt) && STRINGP (XCDR (elt)))
3036 elt = frame_unspecified_color (f, XCDR (elt));
3037 if (!NILP (elt))
3038 store_in_alist (&alist, Qforeground_color, elt);
3040 else
3041 store_in_alist (&alist, Qforeground_color,
3042 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
3043 elt = Fassq (Qbackground_color, alist);
3044 if (CONSP (elt) && STRINGP (XCDR (elt)))
3046 elt = frame_unspecified_color (f, XCDR (elt));
3047 if (!NILP (elt))
3048 store_in_alist (&alist, Qbackground_color, elt);
3050 else
3051 store_in_alist (&alist, Qbackground_color,
3052 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
3053 store_in_alist (&alist, Qfont,
3054 build_string (FRAME_MSDOS_P (f)
3055 ? "ms-dos"
3056 : FRAME_W32_P (f) ? "w32term"
3057 :"tty"));
3059 store_in_alist (&alist, Qname, f->name);
3060 height = (f->new_height
3061 ? (f->new_pixelwise
3062 ? (f->new_height / FRAME_LINE_HEIGHT (f))
3063 : f->new_height)
3064 : FRAME_LINES (f));
3065 store_in_alist (&alist, Qheight, make_number (height));
3066 width = (f->new_width
3067 ? (f->new_pixelwise
3068 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
3069 : f->new_width)
3070 : FRAME_COLS (f));
3071 store_in_alist (&alist, Qwidth, make_number (width));
3072 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
3073 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
3074 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
3075 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
3077 /* I think this should be done with a hook. */
3078 #ifdef HAVE_WINDOW_SYSTEM
3079 if (FRAME_WINDOW_P (f))
3080 x_report_frame_params (f, &alist);
3081 else
3082 #endif
3084 /* This ought to be correct in f->param_alist for an X frame. */
3085 Lisp_Object lines;
3086 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
3087 store_in_alist (&alist, Qmenu_bar_lines, lines);
3090 return alist;
3094 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
3095 doc: /* Return FRAME's value for parameter PARAMETER.
3096 If FRAME is nil, describe the currently selected frame. */)
3097 (Lisp_Object frame, Lisp_Object parameter)
3099 struct frame *f = decode_any_frame (frame);
3100 Lisp_Object value = Qnil;
3102 CHECK_SYMBOL (parameter);
3104 XSETFRAME (frame, f);
3106 if (FRAME_LIVE_P (f))
3108 /* Avoid consing in frequent cases. */
3109 if (EQ (parameter, Qname))
3110 value = f->name;
3111 #ifdef HAVE_WINDOW_SYSTEM
3112 /* These are used by vertical motion commands. */
3113 else if (EQ (parameter, Qvertical_scroll_bars))
3114 value = (f->vertical_scroll_bar_type == vertical_scroll_bar_none
3115 ? Qnil
3116 : (f->vertical_scroll_bar_type == vertical_scroll_bar_left
3117 ? Qleft : Qright));
3118 else if (EQ (parameter, Qhorizontal_scroll_bars))
3119 value = f->horizontal_scroll_bars ? Qt : Qnil;
3120 else if (EQ (parameter, Qline_spacing) && f->extra_line_spacing == 0)
3121 /* If this is non-zero, we can't determine whether the user specified
3122 an integer or float value without looking through 'param_alist'. */
3123 value = make_number (0);
3124 else if (EQ (parameter, Qfont) && FRAME_X_P (f))
3125 value = FRAME_FONT (f)->props[FONT_NAME_INDEX];
3126 #endif /* HAVE_WINDOW_SYSTEM */
3127 #ifdef HAVE_X_WINDOWS
3128 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
3129 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
3130 #endif /* HAVE_X_WINDOWS */
3131 else if (EQ (parameter, Qbackground_color)
3132 || EQ (parameter, Qforeground_color))
3134 value = Fassq (parameter, f->param_alist);
3135 if (CONSP (value))
3137 value = XCDR (value);
3138 /* Fframe_parameters puts the actual fg/bg color names,
3139 even if f->param_alist says otherwise. This is
3140 important when param_alist's notion of colors is
3141 "unspecified". We need to do the same here. */
3142 if (STRINGP (value) && !FRAME_WINDOW_P (f))
3144 Lisp_Object tem = frame_unspecified_color (f, value);
3146 if (!NILP (tem))
3147 value = tem;
3150 else
3151 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
3153 else if (EQ (parameter, Qdisplay_type)
3154 || EQ (parameter, Qbackground_mode))
3155 value = Fcdr (Fassq (parameter, f->param_alist));
3156 else
3157 /* FIXME: Avoid this code path at all (as well as code duplication)
3158 by sharing more code with Fframe_parameters. */
3159 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
3162 return value;
3166 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
3167 Smodify_frame_parameters, 2, 2, 0,
3168 doc: /* Modify FRAME according to new values of its parameters in ALIST.
3169 If FRAME is nil, it defaults to the selected frame.
3170 ALIST is an alist of parameters to change and their new values.
3171 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
3172 Which PARMs are meaningful depends on the kind of frame.
3173 The meaningful parameters are acted upon, i.e. the frame is changed
3174 according to their new values, and are also stored in the frame's
3175 parameter list so that `frame-parameters' will return them.
3176 PARMs that are not meaningful are still stored in the frame's parameter
3177 list, but are otherwise ignored. */)
3178 (Lisp_Object frame, Lisp_Object alist)
3180 struct frame *f = decode_live_frame (frame);
3181 Lisp_Object prop, val;
3183 /* I think this should be done with a hook. */
3184 #ifdef HAVE_WINDOW_SYSTEM
3185 if (FRAME_WINDOW_P (f))
3186 x_set_frame_parameters (f, alist);
3187 else
3188 #endif
3189 #ifdef MSDOS
3190 if (FRAME_MSDOS_P (f))
3191 IT_set_frame_parameters (f, alist);
3192 else
3193 #endif
3196 EMACS_INT length = XFASTINT (Flength (alist));
3197 ptrdiff_t i;
3198 Lisp_Object *parms;
3199 Lisp_Object *values;
3200 USE_SAFE_ALLOCA;
3201 SAFE_ALLOCA_LISP (parms, 2 * length);
3202 values = parms + length;
3204 /* Extract parm names and values into those vectors. */
3206 for (i = 0; CONSP (alist); alist = XCDR (alist))
3208 Lisp_Object elt;
3210 elt = XCAR (alist);
3211 parms[i] = Fcar (elt);
3212 values[i] = Fcdr (elt);
3213 i++;
3216 /* Now process them in reverse of specified order. */
3217 while (--i >= 0)
3219 prop = parms[i];
3220 val = values[i];
3221 store_frame_param (f, prop, val);
3223 if (EQ (prop, Qforeground_color)
3224 || EQ (prop, Qbackground_color))
3225 update_face_from_frame_parameter (f, prop, val);
3228 SAFE_FREE ();
3230 return Qnil;
3233 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
3234 0, 1, 0,
3235 doc: /* Height in pixels of a line in the font in frame FRAME.
3236 If FRAME is omitted or nil, the selected frame is used.
3237 For a terminal frame, the value is always 1. */)
3238 (Lisp_Object frame)
3240 #ifdef HAVE_WINDOW_SYSTEM
3241 struct frame *f = decode_any_frame (frame);
3243 if (FRAME_WINDOW_P (f))
3244 return make_number (FRAME_LINE_HEIGHT (f));
3245 else
3246 #endif
3247 return make_number (1);
3251 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
3252 0, 1, 0,
3253 doc: /* Width in pixels of characters in the font in frame FRAME.
3254 If FRAME is omitted or nil, the selected frame is used.
3255 On a graphical screen, the width is the standard width of the default font.
3256 For a terminal screen, the value is always 1. */)
3257 (Lisp_Object frame)
3259 #ifdef HAVE_WINDOW_SYSTEM
3260 struct frame *f = decode_any_frame (frame);
3262 if (FRAME_WINDOW_P (f))
3263 return make_number (FRAME_COLUMN_WIDTH (f));
3264 else
3265 #endif
3266 return make_number (1);
3269 DEFUN ("frame-native-width", Fframe_native_width,
3270 Sframe_native_width, 0, 1, 0,
3271 doc: /* Return FRAME's native width in pixels.
3272 For a terminal frame, the result really gives the width in characters.
3273 If FRAME is omitted or nil, the selected frame is used. */)
3274 (Lisp_Object frame)
3276 struct frame *f = decode_any_frame (frame);
3278 #ifdef HAVE_WINDOW_SYSTEM
3279 if (FRAME_WINDOW_P (f))
3280 return make_number (FRAME_PIXEL_WIDTH (f));
3281 else
3282 #endif
3283 return make_number (FRAME_TOTAL_COLS (f));
3286 DEFUN ("frame-native-height", Fframe_native_height,
3287 Sframe_native_height, 0, 1, 0,
3288 doc: /* Return FRAME's native height in pixels.
3289 If FRAME is omitted or nil, the selected frame is used. The exact value
3290 of the result depends on the window-system and toolkit in use:
3292 In the Gtk+ and NS versions, it includes only any window (including the
3293 minibuffer or echo area), mode line, and header line. It does not
3294 include the tool bar or menu bar. With other graphical versions, it may
3295 also include the tool bar and the menu bar.
3297 For a text terminal, it includes the menu bar. In this case, the
3298 result is really in characters rather than pixels (i.e., is identical
3299 to `frame-height'). */)
3300 (Lisp_Object frame)
3302 struct frame *f = decode_any_frame (frame);
3304 #ifdef HAVE_WINDOW_SYSTEM
3305 if (FRAME_WINDOW_P (f))
3306 return make_number (FRAME_PIXEL_HEIGHT (f));
3307 else
3308 #endif
3309 return make_number (FRAME_TOTAL_LINES (f));
3312 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
3313 Stool_bar_pixel_width, 0, 1, 0,
3314 doc: /* Return width in pixels of FRAME's tool bar.
3315 The result is greater than zero only when the tool bar is on the left
3316 or right side of FRAME. If FRAME is omitted or nil, the selected frame
3317 is used. */)
3318 (Lisp_Object frame)
3320 #ifdef FRAME_TOOLBAR_WIDTH
3321 struct frame *f = decode_any_frame (frame);
3323 if (FRAME_WINDOW_P (f))
3324 return make_number (FRAME_TOOLBAR_WIDTH (f));
3325 #endif
3326 return make_number (0);
3329 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
3330 doc: /* Return width in columns of FRAME's text area. */)
3331 (Lisp_Object frame)
3333 return make_number (FRAME_COLS (decode_any_frame (frame)));
3336 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
3337 doc: /* Return height in lines of FRAME's text area. */)
3338 (Lisp_Object frame)
3340 return make_number (FRAME_LINES (decode_any_frame (frame)));
3343 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
3344 doc: /* Return number of total columns of FRAME. */)
3345 (Lisp_Object frame)
3347 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
3350 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
3351 doc: /* Return number of total lines of FRAME. */)
3352 (Lisp_Object frame)
3354 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
3357 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
3358 doc: /* Return text area width of FRAME in pixels. */)
3359 (Lisp_Object frame)
3361 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
3364 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
3365 doc: /* Return text area height of FRAME in pixels. */)
3366 (Lisp_Object frame)
3368 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
3371 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
3372 doc: /* Return scroll bar width of FRAME in pixels. */)
3373 (Lisp_Object frame)
3375 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
3378 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
3379 doc: /* Return scroll bar height of FRAME in pixels. */)
3380 (Lisp_Object frame)
3382 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
3385 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
3386 doc: /* Return fringe width of FRAME in pixels. */)
3387 (Lisp_Object frame)
3389 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
3392 DEFUN ("frame-internal-border-width", Fframe_internal_border_width, Sframe_internal_border_width, 0, 1, 0,
3393 doc: /* Return width of FRAME's internal border in pixels. */)
3394 (Lisp_Object frame)
3396 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
3399 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
3400 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
3401 (Lisp_Object frame)
3403 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
3406 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
3407 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
3408 (Lisp_Object frame)
3410 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
3413 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
3414 doc: /* Set text height of frame FRAME to HEIGHT lines.
3415 Optional third arg PRETEND non-nil means that redisplay should use
3416 HEIGHT lines but that the idea of the actual height of the frame should
3417 not be changed.
3419 Optional fourth argument PIXELWISE non-nil means that FRAME should be
3420 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
3421 window managers may refuse to honor a HEIGHT that is not an integer
3422 multiple of the default frame font height. */)
3423 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
3425 struct frame *f = decode_live_frame (frame);
3426 int pixel_height;
3428 CHECK_TYPE_RANGED_INTEGER (int, height);
3430 pixel_height = (!NILP (pixelwise)
3431 ? XINT (height)
3432 : XINT (height) * FRAME_LINE_HEIGHT (f));
3433 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
3435 return Qnil;
3438 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
3439 doc: /* Set text width of frame FRAME to WIDTH columns.
3440 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
3441 columns but that the idea of the actual width of the frame should not
3442 be changed.
3444 Optional fourth argument PIXELWISE non-nil means that FRAME should be
3445 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
3446 window managers may refuse to honor a WIDTH that is not an integer
3447 multiple of the default frame font width. */)
3448 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
3450 struct frame *f = decode_live_frame (frame);
3451 int pixel_width;
3453 CHECK_TYPE_RANGED_INTEGER (int, width);
3455 pixel_width = (!NILP (pixelwise)
3456 ? XINT (width)
3457 : XINT (width) * FRAME_COLUMN_WIDTH (f));
3458 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
3460 return Qnil;
3463 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
3464 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
3465 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
3466 When `frame-resize-pixelwise' is nil, some window managers may refuse to
3467 honor a WIDTH that is not an integer multiple of the default frame font
3468 width or a HEIGHT that is not an integer multiple of the default frame
3469 font height. */)
3470 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
3472 struct frame *f = decode_live_frame (frame);
3473 int pixel_width, pixel_height;
3475 CHECK_TYPE_RANGED_INTEGER (int, width);
3476 CHECK_TYPE_RANGED_INTEGER (int, height);
3478 pixel_width = (!NILP (pixelwise)
3479 ? XINT (width)
3480 : XINT (width) * FRAME_COLUMN_WIDTH (f));
3481 pixel_height = (!NILP (pixelwise)
3482 ? XINT (height)
3483 : XINT (height) * FRAME_LINE_HEIGHT (f));
3484 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
3486 return Qnil;
3489 DEFUN ("frame-position", Fframe_position,
3490 Sframe_position, 0, 1, 0,
3491 doc: /* Return top left corner of FRAME in pixels.
3492 FRAME must be a live frame and defaults to the selected one. The return
3493 value is a cons (x, y) of the coordinates of the top left corner of
3494 FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's
3495 display. */)
3496 (Lisp_Object frame)
3498 register struct frame *f = decode_live_frame (frame);
3500 return Fcons (make_number (f->left_pos), make_number (f->top_pos));
3503 DEFUN ("set-frame-position", Fset_frame_position,
3504 Sset_frame_position, 3, 3, 0,
3505 doc: /* Set position of FRAME to (X, Y).
3506 FRAME must be a live frame and defaults to the selected one. X and Y,
3507 if positive, specify the coordinate of the left and top edge of FRAME's
3508 outer frame in pixels relative to an origin (0, 0) of FRAME's display.
3509 If any of X or Y is negative, it specifies the coordinates of the right
3510 or bottom edge of the outer frame of FRAME relative to the right or
3511 bottom edge of FRAME's display. */)
3512 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
3514 struct frame *f = decode_live_frame (frame);
3516 CHECK_TYPE_RANGED_INTEGER (int, x);
3517 CHECK_TYPE_RANGED_INTEGER (int, y);
3519 /* I think this should be done with a hook. */
3520 if (FRAME_WINDOW_P (f))
3522 #ifdef HAVE_WINDOW_SYSTEM
3523 x_set_offset (f, XINT (x), XINT (y), 1);
3524 #endif
3527 return Qt;
3530 /***********************************************************************
3531 Frame Parameters
3532 ***********************************************************************/
3534 /* Connect the frame-parameter names for X frames
3535 to the ways of passing the parameter values to the window system.
3537 The name of a parameter, as a Lisp symbol,
3538 has an `x-frame-parameter' property which is an integer in Lisp
3539 that is an index in this table. */
3541 struct frame_parm_table {
3542 const char *name;
3543 int sym;
3546 static const struct frame_parm_table frame_parms[] =
3548 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3549 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3550 {"background-color", -1},
3551 {"border-color", SYMBOL_INDEX (Qborder_color)},
3552 {"border-width", SYMBOL_INDEX (Qborder_width)},
3553 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3554 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3555 {"font", -1},
3556 {"foreground-color", -1},
3557 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3558 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3559 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3560 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3561 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3562 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3563 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3564 {"name", SYMBOL_INDEX (Qname)},
3565 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3566 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3567 {"title", SYMBOL_INDEX (Qtitle)},
3568 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3569 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3570 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3571 {"visibility", SYMBOL_INDEX (Qvisibility)},
3572 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3573 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3574 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3575 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3576 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3577 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3578 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3579 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3580 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3581 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3582 {"alpha", SYMBOL_INDEX (Qalpha)},
3583 {"sticky", SYMBOL_INDEX (Qsticky)},
3584 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3585 {"inhibit-double-buffering", SYMBOL_INDEX (Qinhibit_double_buffering)},
3586 {"undecorated", SYMBOL_INDEX (Qundecorated)},
3587 {"parent-frame", SYMBOL_INDEX (Qparent_frame)},
3588 {"skip-taskbar", SYMBOL_INDEX (Qskip_taskbar)},
3589 {"no-focus-on-map", SYMBOL_INDEX (Qno_focus_on_map)},
3590 {"no-accept-focus", SYMBOL_INDEX (Qno_accept_focus)},
3591 {"z-group", SYMBOL_INDEX (Qz_group)},
3592 {"override-redirect", SYMBOL_INDEX (Qoverride_redirect)},
3593 {"no-special-glyphs", SYMBOL_INDEX (Qno_special_glyphs)},
3594 #ifdef NS_IMPL_COCOA
3595 {"ns-appearance", SYMBOL_INDEX (Qns_appearance)},
3596 {"ns-transparent-titlebar", SYMBOL_INDEX (Qns_transparent_titlebar)},
3597 #endif
3600 #ifdef HAVE_WINDOW_SYSTEM
3602 /* Enumeration type for switch in frame_float. */
3603 enum frame_float_type
3605 FRAME_FLOAT_WIDTH,
3606 FRAME_FLOAT_HEIGHT,
3607 FRAME_FLOAT_LEFT,
3608 FRAME_FLOAT_TOP
3612 * frame_float:
3614 * Process the value VAL of the float type frame parameter 'width',
3615 * 'height', 'left', or 'top' specified via a frame_float_type
3616 * enumeration type WHAT for frame F. Such parameters relate the outer
3617 * size or position of F to the size of the F's display or parent frame
3618 * which have to be both available in some way.
3620 * The return value is a size or position value in pixels. VAL must be
3621 * in the range 0.0 to 1.0 where a width/height of 0.0 means to return 0
3622 * and 1.0 means to return the full width/height of the display/parent.
3623 * For positions, 0.0 means position in the left/top corner of the
3624 * display/parent while 1.0 means to position at the right/bottom corner
3625 * of the display/parent frame.
3627 * Set PARENT_DONE and OUTER_DONE to avoid recalculation of the outer
3628 * size or parent or display attributes when more float parameters are
3629 * calculated in a row: -1 means not processed yet, 0 means processing
3630 * failed, 1 means processing succeeded.
3632 * Return DEFAULT_VALUE when processing fails for whatever reason with
3633 * one exception: When calculating F's outer edges fails (probably
3634 * because F has not been created yet) return the difference between F's
3635 * native and text size.
3637 static int
3638 frame_float (struct frame *f, Lisp_Object val, enum frame_float_type what,
3639 int *parent_done, int *outer_done, int default_value)
3641 double d_val = XFLOAT_DATA (val);
3643 if (d_val < 0.0 || d_val > 1.0)
3644 /* Invalid VAL. */
3645 return default_value;
3646 else
3648 static unsigned parent_width, parent_height;
3649 static int parent_left, parent_top;
3650 static unsigned outer_minus_text_width, outer_minus_text_height;
3651 struct frame *p = FRAME_PARENT_FRAME (f);
3653 if (*parent_done == 1)
3655 else if (p)
3657 parent_width = FRAME_PIXEL_WIDTH (p);
3658 parent_height = FRAME_PIXEL_HEIGHT (p);
3659 *parent_done = 1;
3661 else
3663 if (*parent_done == 0)
3664 /* No workarea available. */
3665 return default_value;
3666 else if (*parent_done == -1)
3668 Lisp_Object monitor_attributes;
3669 Lisp_Object workarea;
3670 Lisp_Object frame;
3672 XSETFRAME (frame, f);
3673 monitor_attributes = Fcar (call1 (Qdisplay_monitor_attributes_list, frame));
3674 if (NILP (monitor_attributes))
3676 /* No monitor attributes available. */
3677 *parent_done = 0;
3679 return default_value;
3682 workarea = Fcdr (Fassq (Qworkarea, monitor_attributes));
3683 if (NILP (workarea))
3685 /* No workarea available. */
3686 *parent_done = 0;
3688 return default_value;
3691 /* Workarea available. */
3692 parent_left = XINT (Fnth (make_number (0), workarea));
3693 parent_top = XINT (Fnth (make_number (1), workarea));
3694 parent_width = XINT (Fnth (make_number (2), workarea));
3695 parent_height = XINT (Fnth (make_number (3), workarea));
3696 *parent_done = 1;
3700 if (*outer_done == 1)
3702 else if (FRAME_UNDECORATED (f))
3704 outer_minus_text_width
3705 = FRAME_PIXEL_WIDTH (f) - FRAME_TEXT_WIDTH (f);
3706 outer_minus_text_height
3707 = FRAME_PIXEL_HEIGHT (f) - FRAME_TEXT_HEIGHT (f);
3708 *outer_done = 1;
3710 else if (*outer_done == 0)
3711 /* No outer size available. */
3712 return default_value;
3713 else if (*outer_done == -1)
3715 Lisp_Object frame, outer_edges;
3717 XSETFRAME (frame, f);
3718 outer_edges = call2 (Qframe_edges, frame, Qouter_edges);
3720 if (!NILP (outer_edges))
3722 outer_minus_text_width
3723 = (XINT (Fnth (make_number (2), outer_edges))
3724 - XINT (Fnth (make_number (0), outer_edges))
3725 - FRAME_TEXT_WIDTH (f));
3726 outer_minus_text_height
3727 = (XINT (Fnth (make_number (3), outer_edges))
3728 - XINT (Fnth (make_number (1), outer_edges))
3729 - FRAME_TEXT_HEIGHT (f));
3731 else
3733 /* If we can't get any outer edges, proceed as if the frame
3734 were undecorated. */
3735 outer_minus_text_width
3736 = FRAME_PIXEL_WIDTH (f) - FRAME_TEXT_WIDTH (f);
3737 outer_minus_text_height
3738 = FRAME_PIXEL_HEIGHT (f) - FRAME_TEXT_HEIGHT (f);
3741 *outer_done = 1;
3744 switch (what)
3746 case FRAME_FLOAT_WIDTH:
3747 return parent_width * d_val - outer_minus_text_width;
3749 case FRAME_FLOAT_HEIGHT:
3750 return parent_height * d_val - outer_minus_text_height;
3752 case FRAME_FLOAT_LEFT:
3754 int rest_width = (parent_width
3755 - FRAME_TEXT_WIDTH (f)
3756 - outer_minus_text_width);
3758 if (p)
3759 return (rest_width <= 0 ? 0 : d_val * rest_width);
3760 else
3761 return (rest_width <= 0
3762 ? parent_left
3763 : parent_left + d_val * rest_width);
3765 case FRAME_FLOAT_TOP:
3767 int rest_height = (parent_height
3768 - FRAME_TEXT_HEIGHT (f)
3769 - outer_minus_text_height);
3771 if (p)
3772 return (rest_height <= 0 ? 0 : d_val * rest_height);
3773 else
3774 return (rest_height <= 0
3775 ? parent_top
3776 : parent_top + d_val * rest_height);
3778 default:
3779 emacs_abort ();
3784 /* Change the parameters of frame F as specified by ALIST.
3785 If a parameter is not specially recognized, do nothing special;
3786 otherwise call the `x_set_...' function for that parameter.
3787 Except for certain geometry properties, always call store_frame_param
3788 to store the new value in the parameter alist. */
3790 void
3791 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3793 Lisp_Object tail, frame;
3796 /* If both of these parameters are present, it's more efficient to
3797 set them both at once. So we wait until we've looked at the
3798 entire list before we set them. */
3799 int width = -1, height = -1; /* -1 denotes they were not changed. */
3801 /* Same here. */
3802 Lisp_Object left, top;
3804 /* Same with these. */
3805 Lisp_Object icon_left, icon_top;
3807 /* And with this. */
3808 Lisp_Object fullscreen;
3809 bool fullscreen_change = false;
3811 /* Record in these vectors all the parms specified. */
3812 Lisp_Object *parms;
3813 Lisp_Object *values;
3814 ptrdiff_t i, j, size;
3815 bool left_no_change = 0, top_no_change = 0;
3816 #ifdef HAVE_X_WINDOWS
3817 bool icon_left_no_change = 0, icon_top_no_change = 0;
3818 #endif
3819 int parent_done = -1, outer_done = -1;
3821 XSETFRAME (frame, f);
3822 for (size = 0, tail = alist; CONSP (tail); tail = XCDR (tail))
3823 size++;
3824 CHECK_LIST_END (tail, alist);
3826 USE_SAFE_ALLOCA;
3827 SAFE_ALLOCA_LISP (parms, 2 * size);
3828 values = parms + size;
3830 /* Extract parm names and values into those vectors. */
3832 i = 0, j = size - 1;
3833 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3835 Lisp_Object elt = XCAR (tail), prop = Fcar (elt), val = Fcdr (elt);
3837 /* Some properties are independent of other properties, but other
3838 properties are dependent upon them. These special properties
3839 are foreground_color, background_color (affects cursor_color)
3840 and font (affects fringe widths); they're recorded starting
3841 from the end of PARMS and VALUES to process them first by using
3842 reverse iteration. */
3844 if (EQ (prop, Qforeground_color)
3845 || EQ (prop, Qbackground_color)
3846 || EQ (prop, Qfont))
3848 parms[j] = prop;
3849 values[j] = val;
3850 j--;
3852 else
3854 parms[i] = prop;
3855 values[i] = val;
3856 i++;
3860 /* TAIL and ALIST are not used again below here. */
3861 alist = tail = Qnil;
3863 top = left = Qunbound;
3864 icon_left = icon_top = Qunbound;
3866 /* Reverse order is used to make sure that special
3867 properties noticed above are processed first. */
3868 for (i = size - 1; i >= 0; i--)
3870 Lisp_Object prop, val;
3872 prop = parms[i];
3873 val = values[i];
3875 if (EQ (prop, Qwidth))
3877 if (RANGED_INTEGERP (0, val, INT_MAX))
3878 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3879 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3880 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3881 width = XFASTINT (XCDR (val));
3882 else if (FLOATP (val))
3883 width = frame_float (f, val, FRAME_FLOAT_WIDTH, &parent_done,
3884 &outer_done, -1);
3886 else if (EQ (prop, Qheight))
3888 if (RANGED_INTEGERP (0, val, INT_MAX))
3889 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3890 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3891 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3892 height = XFASTINT (XCDR (val));
3893 else if (FLOATP (val))
3894 height = frame_float (f, val, FRAME_FLOAT_HEIGHT, &parent_done,
3895 &outer_done, -1);
3897 else if (EQ (prop, Qtop))
3898 top = val;
3899 else if (EQ (prop, Qleft))
3900 left = val;
3901 else if (EQ (prop, Qicon_top))
3902 icon_top = val;
3903 else if (EQ (prop, Qicon_left))
3904 icon_left = val;
3905 else if (EQ (prop, Qfullscreen))
3907 fullscreen = val;
3908 fullscreen_change = true;
3910 else
3912 register Lisp_Object param_index, old_value;
3914 old_value = get_frame_param (f, prop);
3916 store_frame_param (f, prop, val);
3918 param_index = Fget (prop, Qx_frame_parameter);
3919 if (NATNUMP (param_index)
3920 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3921 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3922 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3926 /* Don't die if just one of these was set. */
3927 if (EQ (left, Qunbound))
3929 left_no_change = 1;
3930 if (f->left_pos < 0)
3931 left = list2 (Qplus, make_number (f->left_pos));
3932 else
3933 XSETINT (left, f->left_pos);
3935 if (EQ (top, Qunbound))
3937 top_no_change = 1;
3938 if (f->top_pos < 0)
3939 top = list2 (Qplus, make_number (f->top_pos));
3940 else
3941 XSETINT (top, f->top_pos);
3944 /* If one of the icon positions was not set, preserve or default it. */
3945 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3947 #ifdef HAVE_X_WINDOWS
3948 icon_left_no_change = 1;
3949 #endif
3950 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3951 if (NILP (icon_left))
3952 XSETINT (icon_left, 0);
3954 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3956 #ifdef HAVE_X_WINDOWS
3957 icon_top_no_change = 1;
3958 #endif
3959 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3960 if (NILP (icon_top))
3961 XSETINT (icon_top, 0);
3964 /* Don't set these parameters unless they've been explicitly
3965 specified. The window might be mapped or resized while we're in
3966 this function, and we don't want to override that unless the lisp
3967 code has asked for it.
3969 Don't set these parameters unless they actually differ from the
3970 window's current parameters; the window may not actually exist
3971 yet. */
3972 if ((width != -1 && width != FRAME_TEXT_WIDTH (f))
3973 || (height != -1 && height != FRAME_TEXT_HEIGHT (f)))
3974 /* We could consider checking f->after_make_frame here, but I
3975 don't have the faintest idea why the following is needed at
3976 all. With the old setting it can get a Heisenbug when
3977 EmacsFrameResize intermittently provokes a delayed
3978 change_frame_size in the middle of adjust_frame_size. */
3979 /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
3980 adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters);
3982 if ((!NILP (left) || !NILP (top))
3983 && ! (left_no_change && top_no_change)
3984 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3985 && NUMBERP (top) && XINT (top) == f->top_pos))
3987 int leftpos = 0;
3988 int toppos = 0;
3990 /* Record the signs. */
3991 f->size_hint_flags &= ~ (XNegative | YNegative);
3992 if (EQ (left, Qminus))
3993 f->size_hint_flags |= XNegative;
3994 else if (TYPE_RANGED_INTEGERP (int, left))
3996 leftpos = XINT (left);
3997 if (leftpos < 0)
3998 f->size_hint_flags |= XNegative;
4000 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4001 && CONSP (XCDR (left))
4002 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4004 leftpos = - XINT (XCAR (XCDR (left)));
4005 f->size_hint_flags |= XNegative;
4007 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4008 && CONSP (XCDR (left))
4009 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4010 leftpos = XINT (XCAR (XCDR (left)));
4011 else if (FLOATP (left))
4012 leftpos = frame_float (f, left, FRAME_FLOAT_LEFT, &parent_done,
4013 &outer_done, 0);
4015 if (EQ (top, Qminus))
4016 f->size_hint_flags |= YNegative;
4017 else if (TYPE_RANGED_INTEGERP (int, top))
4019 toppos = XINT (top);
4020 if (toppos < 0)
4021 f->size_hint_flags |= YNegative;
4023 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4024 && CONSP (XCDR (top))
4025 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4027 toppos = - XINT (XCAR (XCDR (top)));
4028 f->size_hint_flags |= YNegative;
4030 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4031 && CONSP (XCDR (top))
4032 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4033 toppos = XINT (XCAR (XCDR (top)));
4034 else if (FLOATP (top))
4035 toppos = frame_float (f, top, FRAME_FLOAT_TOP, &parent_done,
4036 &outer_done, 0);
4038 /* Store the numeric value of the position. */
4039 f->top_pos = toppos;
4040 f->left_pos = leftpos;
4042 f->win_gravity = NorthWestGravity;
4044 /* Actually set that position, and convert to absolute. */
4045 x_set_offset (f, leftpos, toppos, -1);
4048 if (fullscreen_change)
4050 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
4052 frame_size_history_add
4053 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
4055 store_frame_param (f, Qfullscreen, fullscreen);
4056 if (!EQ (fullscreen, old_value))
4057 x_set_fullscreen (f, fullscreen, old_value);
4061 #ifdef HAVE_X_WINDOWS
4062 if ((!NILP (icon_left) || !NILP (icon_top))
4063 && ! (icon_left_no_change && icon_top_no_change))
4064 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
4065 #endif /* HAVE_X_WINDOWS */
4067 SAFE_FREE ();
4071 /* Insert a description of internally-recorded parameters of frame X
4072 into the parameter alist *ALISTPTR that is to be given to the user.
4073 Only parameters that are specific to the X window system
4074 and whose values are not correctly recorded in the frame's
4075 param_alist need to be considered here. */
4077 void
4078 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
4080 Lisp_Object tem;
4081 uprintmax_t w;
4082 char buf[INT_BUFSIZE_BOUND (w)];
4084 /* Represent negative positions (off the top or left screen edge)
4085 in a way that Fmodify_frame_parameters will understand correctly. */
4086 XSETINT (tem, f->left_pos);
4087 if (f->left_pos >= 0)
4088 store_in_alist (alistptr, Qleft, tem);
4089 else
4090 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
4092 XSETINT (tem, f->top_pos);
4093 if (f->top_pos >= 0)
4094 store_in_alist (alistptr, Qtop, tem);
4095 else
4096 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
4098 store_in_alist (alistptr, Qborder_width,
4099 make_number (f->border_width));
4100 store_in_alist (alistptr, Qinternal_border_width,
4101 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
4102 store_in_alist (alistptr, Qright_divider_width,
4103 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
4104 store_in_alist (alistptr, Qbottom_divider_width,
4105 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
4106 store_in_alist (alistptr, Qleft_fringe,
4107 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
4108 store_in_alist (alistptr, Qright_fringe,
4109 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
4110 store_in_alist (alistptr, Qscroll_bar_width,
4111 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
4112 ? make_number (0)
4113 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
4114 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
4115 /* nil means "use default width"
4116 for non-toolkit scroll bar.
4117 ruler-mode.el depends on this. */
4118 : Qnil));
4119 store_in_alist (alistptr, Qscroll_bar_height,
4120 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
4121 ? make_number (0)
4122 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
4123 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
4124 /* nil means "use default height"
4125 for non-toolkit scroll bar. */
4126 : Qnil));
4127 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
4128 MS-Windows it returns a value whose type is HANDLE, which is
4129 actually a pointer. Explicit casting avoids compiler
4130 warnings. */
4131 w = (uintptr_t) FRAME_X_WINDOW (f);
4132 store_in_alist (alistptr, Qwindow_id,
4133 make_formatted_string (buf, "%"pMu, w));
4134 #ifdef HAVE_X_WINDOWS
4135 #ifdef USE_X_TOOLKIT
4136 /* Tooltip frame may not have this widget. */
4137 if (FRAME_X_OUTPUT (f)->widget)
4138 #endif
4139 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
4140 store_in_alist (alistptr, Qouter_window_id,
4141 make_formatted_string (buf, "%"pMu, w));
4142 #endif
4143 store_in_alist (alistptr, Qicon_name, f->icon_name);
4144 store_in_alist (alistptr, Qvisibility,
4145 (FRAME_VISIBLE_P (f) ? Qt
4146 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
4147 store_in_alist (alistptr, Qdisplay,
4148 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
4150 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
4151 tem = Qnil;
4152 else
4153 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
4154 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
4155 store_in_alist (alistptr, Qparent_id, tem);
4156 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
4160 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
4161 the previous value of that parameter, NEW_VALUE is the new value. */
4163 void
4164 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4166 if (NILP (new_value))
4167 f->want_fullscreen = FULLSCREEN_NONE;
4168 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
4169 f->want_fullscreen = FULLSCREEN_BOTH;
4170 else if (EQ (new_value, Qfullwidth))
4171 f->want_fullscreen = FULLSCREEN_WIDTH;
4172 else if (EQ (new_value, Qfullheight))
4173 f->want_fullscreen = FULLSCREEN_HEIGHT;
4174 else if (EQ (new_value, Qmaximized))
4175 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
4177 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
4178 FRAME_TERMINAL (f)->fullscreen_hook (f);
4182 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
4183 the previous value of that parameter, NEW_VALUE is the new value. */
4185 void
4186 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4188 if (NILP (new_value))
4189 f->extra_line_spacing = 0;
4190 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
4191 f->extra_line_spacing = XFASTINT (new_value);
4192 else if (FLOATP (new_value))
4194 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
4196 if (new_spacing >= 0)
4197 f->extra_line_spacing = new_spacing;
4198 else
4199 signal_error ("Invalid line-spacing", new_value);
4201 else
4202 signal_error ("Invalid line-spacing", new_value);
4203 if (FRAME_VISIBLE_P (f))
4204 redraw_frame (f);
4208 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
4209 the previous value of that parameter, NEW_VALUE is the new value. */
4211 void
4212 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4214 Lisp_Object bgcolor;
4216 if (NILP (new_value))
4217 f->gamma = 0;
4218 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
4219 /* The value 0.4545 is the normal viewing gamma. */
4220 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
4221 else
4222 signal_error ("Invalid screen-gamma", new_value);
4224 /* Apply the new gamma value to the frame background. */
4225 bgcolor = Fassq (Qbackground_color, f->param_alist);
4226 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
4228 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
4229 if (NATNUMP (parm_index)
4230 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
4231 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
4232 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
4233 (f, bgcolor, Qnil);
4236 clear_face_cache (true); /* FIXME: Why of all frames? */
4237 fset_redisplay (f);
4241 void
4242 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4244 Lisp_Object font_object;
4245 int fontset = -1;
4246 #ifdef HAVE_X_WINDOWS
4247 Lisp_Object font_param = arg;
4248 #endif
4250 /* Set the frame parameter back to the old value because we may
4251 fail to use ARG as the new parameter value. */
4252 store_frame_param (f, Qfont, oldval);
4254 /* ARG is a fontset name, a font name, a cons of fontset name and a
4255 font object, or a font object. In the last case, this function
4256 never fail. */
4257 if (STRINGP (arg))
4259 fontset = fs_query_fontset (arg, 0);
4260 if (fontset < 0)
4262 font_object = font_open_by_name (f, arg);
4263 if (NILP (font_object))
4264 error ("Font `%s' is not defined", SSDATA (arg));
4265 arg = AREF (font_object, FONT_NAME_INDEX);
4267 else if (fontset > 0)
4269 font_object = font_open_by_name (f, fontset_ascii (fontset));
4270 if (NILP (font_object))
4271 error ("Font `%s' is not defined", SDATA (arg));
4272 arg = AREF (font_object, FONT_NAME_INDEX);
4274 else
4275 error ("The default fontset can't be used for a frame font");
4277 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
4279 /* This is the case that the ASCII font of F's fontset XCAR
4280 (arg) is changed to the font XCDR (arg) by
4281 `set-fontset-font'. */
4282 fontset = fs_query_fontset (XCAR (arg), 0);
4283 if (fontset < 0)
4284 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
4285 font_object = XCDR (arg);
4286 arg = AREF (font_object, FONT_NAME_INDEX);
4287 #ifdef HAVE_X_WINDOWS
4288 font_param = Ffont_get (font_object, QCname);
4289 #endif
4291 else if (FONT_OBJECT_P (arg))
4293 font_object = arg;
4294 #ifdef HAVE_X_WINDOWS
4295 font_param = Ffont_get (font_object, QCname);
4296 #endif
4297 /* This is to store the XLFD font name in the frame parameter for
4298 backward compatibility. We should store the font-object
4299 itself in the future. */
4300 arg = AREF (font_object, FONT_NAME_INDEX);
4301 fontset = FRAME_FONTSET (f);
4302 /* Check if we can use the current fontset. If not, set FONTSET
4303 to -1 to generate a new fontset from FONT-OBJECT. */
4304 if (fontset >= 0)
4306 Lisp_Object ascii_font = fontset_ascii (fontset);
4307 Lisp_Object spec = font_spec_from_name (ascii_font);
4309 /* SPEC might be nil because ASCII_FONT's name doesn't parse
4310 according to stupid XLFD rules, which, for example,
4311 disallow font names that include a dash followed by a
4312 number. So in those cases we simply request x_new_font
4313 below to generate a new fontset. */
4314 if (NILP (spec) || ! font_match_p (spec, font_object))
4315 fontset = -1;
4318 else
4319 signal_error ("Invalid font", arg);
4321 if (! NILP (Fequal (font_object, oldval)))
4322 return;
4324 x_new_font (f, font_object, fontset);
4325 store_frame_param (f, Qfont, arg);
4326 #ifdef HAVE_X_WINDOWS
4327 store_frame_param (f, Qfont_parameter, font_param);
4328 #endif
4329 /* Recalculate toolbar height. */
4330 f->n_tool_bar_rows = 0;
4332 /* Ensure we redraw it. */
4333 clear_current_matrices (f);
4335 /* Attempt to hunt down bug#16028. */
4336 SET_FRAME_GARBAGED (f);
4338 /* This is important if we are called by some Lisp as part of
4339 redisplaying the frame, see redisplay_internal. */
4340 f->fonts_changed = true;
4342 recompute_basic_faces (f);
4344 do_pending_window_change (0);
4346 /* We used to call face-set-after-frame-default here, but it leads to
4347 recursive calls (since that function can set the `default' face's
4348 font which in turns changes the frame's `font' parameter).
4349 Also I don't know what this call is meant to do, but it seems the
4350 wrong way to do it anyway (it does a lot more work than what seems
4351 reasonable in response to a change to `font'). */
4355 void
4356 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4358 if (! NILP (new_value)
4359 && !CONSP (new_value))
4361 char *p0, *p1;
4363 CHECK_STRING (new_value);
4364 p0 = p1 = SSDATA (new_value);
4365 new_value = Qnil;
4366 while (*p0)
4368 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
4369 if (p0 < p1)
4370 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
4371 new_value);
4372 if (*p1)
4374 int c;
4376 while ((c = *++p1) && c_isspace (c));
4378 p0 = p1;
4380 new_value = Fnreverse (new_value);
4383 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
4384 return;
4386 if (FRAME_FONT (f))
4387 free_all_realized_faces (Qnil);
4389 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
4390 if (NILP (new_value))
4392 if (NILP (old_value))
4393 error ("No font backend available");
4394 font_update_drivers (f, old_value);
4395 error ("None of specified font backends are available");
4397 store_frame_param (f, Qfont_backend, new_value);
4399 if (FRAME_FONT (f))
4401 Lisp_Object frame;
4403 XSETFRAME (frame, f);
4404 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
4405 face_change = true;
4406 windows_or_buffers_changed = 18;
4410 void
4411 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4413 int unit = FRAME_COLUMN_WIDTH (f);
4414 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
4415 int new_width;
4417 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
4418 ? eabs (XINT (new_value)) : 8);
4420 if (new_width != old_width)
4422 f->left_fringe_width = new_width;
4423 f->fringe_cols /* Round up. */
4424 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
4426 if (FRAME_X_WINDOW (f) != 0)
4427 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
4429 SET_FRAME_GARBAGED (f);
4434 void
4435 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4437 int unit = FRAME_COLUMN_WIDTH (f);
4438 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
4439 int new_width;
4441 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
4442 ? eabs (XINT (new_value)) : 8);
4444 if (new_width != old_width)
4446 f->right_fringe_width = new_width;
4447 f->fringe_cols /* Round up. */
4448 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
4450 if (FRAME_X_WINDOW (f) != 0)
4451 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
4453 SET_FRAME_GARBAGED (f);
4458 void
4459 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4461 CHECK_TYPE_RANGED_INTEGER (int, arg);
4463 if (XINT (arg) == f->border_width)
4464 return;
4466 if (FRAME_X_WINDOW (f) != 0)
4467 error ("Cannot change the border width of a frame");
4469 f->border_width = XINT (arg);
4472 void
4473 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4475 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
4476 CHECK_TYPE_RANGED_INTEGER (int, arg);
4477 int new = max (0, XINT (arg));
4478 if (new != old)
4480 f->right_divider_width = new;
4481 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
4482 adjust_frame_glyphs (f);
4483 SET_FRAME_GARBAGED (f);
4487 void
4488 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4490 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
4491 CHECK_TYPE_RANGED_INTEGER (int, arg);
4492 int new = max (0, XINT (arg));
4493 if (new != old)
4495 f->bottom_divider_width = new;
4496 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
4497 adjust_frame_glyphs (f);
4498 SET_FRAME_GARBAGED (f);
4502 void
4503 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
4505 Lisp_Object frame;
4506 XSETFRAME (frame, f);
4508 if (NILP (value))
4509 Fmake_frame_invisible (frame, Qt);
4510 else if (EQ (value, Qicon))
4511 Ficonify_frame (frame);
4512 else
4513 Fmake_frame_visible (frame);
4516 void
4517 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4519 f->auto_raise = !EQ (Qnil, arg);
4522 void
4523 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4525 f->auto_lower = !EQ (Qnil, arg);
4528 void
4529 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4531 f->no_split = !NILP (arg);
4534 void
4535 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4537 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
4538 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
4539 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4540 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
4542 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
4543 = (NILP (arg)
4544 ? vertical_scroll_bar_none
4545 : EQ (Qleft, arg)
4546 ? vertical_scroll_bar_left
4547 : EQ (Qright, arg)
4548 ? vertical_scroll_bar_right
4549 : EQ (Qleft, Vdefault_frame_scroll_bars)
4550 ? vertical_scroll_bar_left
4551 : EQ (Qright, Vdefault_frame_scroll_bars)
4552 ? vertical_scroll_bar_right
4553 : vertical_scroll_bar_none);
4555 /* We set this parameter before creating the X window for the
4556 frame, so we can get the geometry right from the start.
4557 However, if the window hasn't been created yet, we shouldn't
4558 call x_set_window_size. */
4559 if (FRAME_X_WINDOW (f))
4560 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
4562 SET_FRAME_GARBAGED (f);
4566 void
4567 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4569 #if USE_HORIZONTAL_SCROLL_BARS
4570 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
4571 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
4573 f->horizontal_scroll_bars = NILP (arg) ? false : true;
4575 /* We set this parameter before creating the X window for the
4576 frame, so we can get the geometry right from the start.
4577 However, if the window hasn't been created yet, we shouldn't
4578 call x_set_window_size. */
4579 if (FRAME_X_WINDOW (f))
4580 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
4582 SET_FRAME_GARBAGED (f);
4584 #endif
4587 void
4588 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4590 int unit = FRAME_COLUMN_WIDTH (f);
4592 if (NILP (arg))
4594 x_set_scroll_bar_default_width (f);
4596 if (FRAME_X_WINDOW (f))
4597 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
4599 SET_FRAME_GARBAGED (f);
4601 else if (RANGED_INTEGERP (1, arg, INT_MAX)
4602 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
4604 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
4605 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
4606 if (FRAME_X_WINDOW (f))
4607 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
4609 SET_FRAME_GARBAGED (f);
4612 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
4613 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
4616 void
4617 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4619 #if USE_HORIZONTAL_SCROLL_BARS
4620 int unit = FRAME_LINE_HEIGHT (f);
4622 if (NILP (arg))
4624 x_set_scroll_bar_default_height (f);
4626 if (FRAME_X_WINDOW (f))
4627 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
4629 SET_FRAME_GARBAGED (f);
4631 else if (RANGED_INTEGERP (1, arg, INT_MAX)
4632 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
4634 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
4635 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
4636 if (FRAME_X_WINDOW (f))
4637 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
4639 SET_FRAME_GARBAGED (f);
4642 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
4643 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
4644 #endif
4647 void
4648 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4650 double alpha = 1.0;
4651 double newval[2];
4652 int i;
4653 Lisp_Object item;
4655 for (i = 0; i < 2; i++)
4657 newval[i] = 1.0;
4658 if (CONSP (arg))
4660 item = CAR (arg);
4661 arg = CDR (arg);
4663 else
4664 item = arg;
4666 if (NILP (item))
4667 alpha = - 1.0;
4668 else if (FLOATP (item))
4670 alpha = XFLOAT_DATA (item);
4671 if (! (0 <= alpha && alpha <= 1.0))
4672 args_out_of_range (make_float (0.0), make_float (1.0));
4674 else if (INTEGERP (item))
4676 EMACS_INT ialpha = XINT (item);
4677 if (! (0 <= ialpha && ialpha <= 100))
4678 args_out_of_range (make_number (0), make_number (100));
4679 alpha = ialpha / 100.0;
4681 else
4682 wrong_type_argument (Qnumberp, item);
4683 newval[i] = alpha;
4686 for (i = 0; i < 2; i++)
4687 f->alpha[i] = newval[i];
4689 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4690 block_input ();
4691 x_set_frame_alpha (f);
4692 unblock_input ();
4693 #endif
4695 return;
4700 * x_set_no_special_glyphs:
4702 * Set frame F's `no-special-glyphs' parameter which, if non-nil,
4703 * suppresses the display of truncation and continuation glyphs
4704 * outside fringes.
4706 void
4707 x_set_no_special_glyphs (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4709 if (!EQ (new_value, old_value))
4710 FRAME_NO_SPECIAL_GLYPHS (f) = !NILP (new_value);
4714 #ifndef HAVE_NS
4716 /* Non-zero if mouse is grabbed on DPYINFO
4717 and we know the frame where it is. */
4719 bool x_mouse_grabbed (Display_Info *dpyinfo)
4721 return (dpyinfo->grabbed
4722 && dpyinfo->last_mouse_frame
4723 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4726 /* Re-highlight something with mouse-face properties
4727 on DPYINFO using saved frame and mouse position. */
4729 void
4730 x_redo_mouse_highlight (Display_Info *dpyinfo)
4732 if (dpyinfo->last_mouse_motion_frame
4733 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4734 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4735 dpyinfo->last_mouse_motion_x,
4736 dpyinfo->last_mouse_motion_y);
4739 #endif /* HAVE_NS */
4741 /* Subroutines of creating an X frame. */
4743 /* Make sure that Vx_resource_name is set to a reasonable value.
4744 Fix it up, or set it to `emacs' if it is too hopeless. */
4746 void
4747 validate_x_resource_name (void)
4749 ptrdiff_t len = 0;
4750 /* Number of valid characters in the resource name. */
4751 ptrdiff_t good_count = 0;
4752 /* Number of invalid characters in the resource name. */
4753 ptrdiff_t bad_count = 0;
4754 Lisp_Object new;
4755 ptrdiff_t i;
4757 if (!STRINGP (Vx_resource_class))
4758 Vx_resource_class = build_string (EMACS_CLASS);
4760 if (STRINGP (Vx_resource_name))
4762 unsigned char *p = SDATA (Vx_resource_name);
4764 len = SBYTES (Vx_resource_name);
4766 /* Only letters, digits, - and _ are valid in resource names.
4767 Count the valid characters and count the invalid ones. */
4768 for (i = 0; i < len; i++)
4770 int c = p[i];
4771 if (! ((c >= 'a' && c <= 'z')
4772 || (c >= 'A' && c <= 'Z')
4773 || (c >= '0' && c <= '9')
4774 || c == '-' || c == '_'))
4775 bad_count++;
4776 else
4777 good_count++;
4780 else
4781 /* Not a string => completely invalid. */
4782 bad_count = 5, good_count = 0;
4784 /* If name is valid already, return. */
4785 if (bad_count == 0)
4786 return;
4788 /* If name is entirely invalid, or nearly so, or is so implausibly
4789 large that alloca might not work, use `emacs'. */
4790 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4792 Vx_resource_name = build_string ("emacs");
4793 return;
4796 /* Name is partly valid. Copy it and replace the invalid characters
4797 with underscores. */
4799 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4801 for (i = 0; i < len; i++)
4803 int c = SREF (new, i);
4804 if (! ((c >= 'a' && c <= 'z')
4805 || (c >= 'A' && c <= 'Z')
4806 || (c >= '0' && c <= '9')
4807 || c == '-' || c == '_'))
4808 SSET (new, i, '_');
4812 /* Get specified attribute from resource database RDB.
4813 See Fx_get_resource below for other parameters. */
4815 static Lisp_Object
4816 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4818 CHECK_STRING (attribute);
4819 CHECK_STRING (class);
4821 if (!NILP (component))
4822 CHECK_STRING (component);
4823 if (!NILP (subclass))
4824 CHECK_STRING (subclass);
4825 if (NILP (component) != NILP (subclass))
4826 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4828 validate_x_resource_name ();
4830 /* Allocate space for the components, the dots which separate them,
4831 and the final '\0'. Make them big enough for the worst case. */
4832 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4833 + (STRINGP (component)
4834 ? SBYTES (component) : 0)
4835 + SBYTES (attribute)
4836 + 3);
4838 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4839 + SBYTES (class)
4840 + (STRINGP (subclass)
4841 ? SBYTES (subclass) : 0)
4842 + 3);
4843 USE_SAFE_ALLOCA;
4844 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4845 char *class_key = name_key + name_keysize;
4846 name_key = ptr_bounds_clip (name_key, name_keysize);
4847 class_key = ptr_bounds_clip (class_key, class_keysize);
4849 /* Start with emacs.FRAMENAME for the name (the specific one)
4850 and with `Emacs' for the class key (the general one). */
4851 char *nz = lispstpcpy (name_key, Vx_resource_name);
4852 char *cz = lispstpcpy (class_key, Vx_resource_class);
4854 *cz++ = '.';
4855 cz = lispstpcpy (cz, class);
4857 if (!NILP (component))
4859 *cz++ = '.';
4860 lispstpcpy (cz, subclass);
4862 *nz++ = '.';
4863 nz = lispstpcpy (nz, component);
4866 *nz++ = '.';
4867 lispstpcpy (nz, attribute);
4869 char *value = x_get_string_resource (rdb, name_key, class_key);
4870 SAFE_FREE();
4872 if (value && *value)
4873 return build_string (value);
4874 else
4875 return Qnil;
4879 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4880 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4881 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4882 class, where INSTANCE is the name under which Emacs was invoked, or
4883 the name specified by the `-name' or `-rn' command-line arguments.
4885 The optional arguments COMPONENT and SUBCLASS add to the key and the
4886 class, respectively. You must specify both of them or neither.
4887 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4888 and the class is `Emacs.CLASS.SUBCLASS'. */)
4889 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4890 Lisp_Object subclass)
4892 check_window_system (NULL);
4894 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4895 attribute, class, component, subclass);
4898 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4900 Lisp_Object
4901 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4902 Lisp_Object class, Lisp_Object component,
4903 Lisp_Object subclass)
4905 return xrdb_get_resource (dpyinfo->xrdb,
4906 attribute, class, component, subclass);
4909 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4910 /* Used when C code wants a resource value. */
4911 /* Called from oldXMenu/Create.c. */
4912 char *
4913 x_get_resource_string (const char *attribute, const char *class)
4915 char *result;
4916 struct frame *sf = SELECTED_FRAME ();
4917 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4918 USE_SAFE_ALLOCA;
4920 /* Allocate space for the components, the dots which separate them,
4921 and the final '\0'. */
4922 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4923 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4924 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4925 char *class_key = name_key + name_keysize;
4926 name_key = ptr_bounds_clip (name_key, name_keysize);
4927 class_key = ptr_bounds_clip (class_key, class_keysize);
4929 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4930 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4932 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4933 name_key, class_key);
4934 SAFE_FREE ();
4935 return result;
4937 #endif
4939 /* Return the value of parameter PARAM.
4941 First search ALIST, then Vdefault_frame_alist, then the X defaults
4942 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4944 Convert the resource to the type specified by desired_type.
4946 If no default is specified, return Qunbound. If you call
4947 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4948 and don't let it get stored in any Lisp-visible variables! */
4950 Lisp_Object
4951 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4952 const char *attribute, const char *class, enum resource_types type)
4954 Lisp_Object tem;
4956 tem = Fassq (param, alist);
4958 if (!NILP (tem))
4960 /* If we find this parm in ALIST, clear it out
4961 so that it won't be "left over" at the end. */
4962 Lisp_Object tail;
4963 XSETCAR (tem, Qnil);
4964 /* In case the parameter appears more than once in the alist,
4965 clear it out. */
4966 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4967 if (CONSP (XCAR (tail))
4968 && EQ (XCAR (XCAR (tail)), param))
4969 XSETCAR (XCAR (tail), Qnil);
4971 else
4972 tem = Fassq (param, Vdefault_frame_alist);
4974 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4975 look in the X resources. */
4976 if (EQ (tem, Qnil))
4978 if (attribute && dpyinfo)
4980 AUTO_STRING (at, attribute);
4981 AUTO_STRING (cl, class);
4982 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4984 if (NILP (tem))
4985 return Qunbound;
4987 switch (type)
4989 case RES_TYPE_NUMBER:
4990 return make_number (atoi (SSDATA (tem)));
4992 case RES_TYPE_BOOLEAN_NUMBER:
4993 if (!strcmp (SSDATA (tem), "on")
4994 || !strcmp (SSDATA (tem), "true"))
4995 return make_number (1);
4996 return make_number (atoi (SSDATA (tem)));
4997 break;
4999 case RES_TYPE_FLOAT:
5000 return make_float (atof (SSDATA (tem)));
5002 case RES_TYPE_BOOLEAN:
5003 tem = Fdowncase (tem);
5004 if (!strcmp (SSDATA (tem), "on")
5005 #ifdef HAVE_NS
5006 || !strcmp (SSDATA (tem), "yes")
5007 #endif
5008 || !strcmp (SSDATA (tem), "true"))
5009 return Qt;
5010 else
5011 return Qnil;
5013 case RES_TYPE_STRING:
5014 return tem;
5016 case RES_TYPE_SYMBOL:
5017 /* As a special case, we map the values `true' and `on'
5018 to Qt, and `false' and `off' to Qnil. */
5020 Lisp_Object lower;
5021 lower = Fdowncase (tem);
5022 if (!strcmp (SSDATA (lower), "on")
5023 #ifdef HAVE_NS
5024 || !strcmp (SSDATA (lower), "yes")
5025 #endif
5026 || !strcmp (SSDATA (lower), "true"))
5027 return Qt;
5028 else if (!strcmp (SSDATA (lower), "off")
5029 #ifdef HAVE_NS
5030 || !strcmp (SSDATA (lower), "no")
5031 #endif
5032 || !strcmp (SSDATA (lower), "false"))
5033 return Qnil;
5034 else
5035 return Fintern (tem, Qnil);
5038 default:
5039 emacs_abort ();
5042 else
5043 return Qunbound;
5045 return Fcdr (tem);
5048 static Lisp_Object
5049 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
5050 const char *attribute, const char *class,
5051 enum resource_types type)
5053 return x_get_arg (FRAME_DISPLAY_INFO (f),
5054 alist, param, attribute, class, type);
5057 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
5059 Lisp_Object
5060 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
5061 Lisp_Object param,
5062 const char *attribute, const char *class,
5063 enum resource_types type)
5065 Lisp_Object value;
5067 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
5068 attribute, class, type);
5069 if (! NILP (value) && ! EQ (value, Qunbound))
5070 store_frame_param (f, param, value);
5072 return value;
5076 /* Record in frame F the specified or default value according to ALIST
5077 of the parameter named PROP (a Lisp symbol).
5078 If no value is specified for PROP, look for an X default for XPROP
5079 on the frame named NAME.
5080 If that is not found either, use the value DEFLT. */
5082 Lisp_Object
5083 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
5084 Lisp_Object deflt, const char *xprop, const char *xclass,
5085 enum resource_types type)
5087 Lisp_Object tem;
5089 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
5090 if (EQ (tem, Qunbound))
5091 tem = deflt;
5092 AUTO_FRAME_ARG (arg, prop, tem);
5093 x_set_frame_parameters (f, arg);
5094 return tem;
5098 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
5101 * XParseGeometry parses strings of the form
5102 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
5103 * width, height, xoffset, and yoffset are unsigned integers.
5104 * Example: "=80x24+300-49"
5105 * The equal sign is optional.
5106 * It returns a bitmask that indicates which of the four values
5107 * were actually found in the string. For each value found,
5108 * the corresponding argument is updated; for each value
5109 * not found, the corresponding argument is left unchanged.
5112 static int
5113 XParseGeometry (char *string,
5114 int *x, int *y,
5115 unsigned int *width, unsigned int *height)
5117 int mask = NoValue;
5118 char *strind;
5119 unsigned long tempWidth UNINIT, tempHeight UNINIT;
5120 long int tempX UNINIT, tempY UNINIT;
5121 char *nextCharacter;
5123 if (string == NULL || *string == '\0')
5124 return mask;
5125 if (*string == '=')
5126 string++; /* ignore possible '=' at beg of geometry spec */
5128 strind = string;
5129 if (*strind != '+' && *strind != '-' && *strind != 'x')
5131 tempWidth = strtoul (strind, &nextCharacter, 10);
5132 if (strind == nextCharacter)
5133 return 0;
5134 strind = nextCharacter;
5135 mask |= WidthValue;
5138 if (*strind == 'x' || *strind == 'X')
5140 strind++;
5141 tempHeight = strtoul (strind, &nextCharacter, 10);
5142 if (strind == nextCharacter)
5143 return 0;
5144 strind = nextCharacter;
5145 mask |= HeightValue;
5148 if (*strind == '+' || *strind == '-')
5150 if (*strind == '-')
5151 mask |= XNegative;
5152 tempX = strtol (strind, &nextCharacter, 10);
5153 if (strind == nextCharacter)
5154 return 0;
5155 strind = nextCharacter;
5156 mask |= XValue;
5157 if (*strind == '+' || *strind == '-')
5159 if (*strind == '-')
5160 mask |= YNegative;
5161 tempY = strtol (strind, &nextCharacter, 10);
5162 if (strind == nextCharacter)
5163 return 0;
5164 strind = nextCharacter;
5165 mask |= YValue;
5169 /* If strind isn't at the end of the string then it's an invalid
5170 geometry specification. */
5172 if (*strind != '\0')
5173 return 0;
5175 if (mask & XValue)
5176 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
5177 if (mask & YValue)
5178 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
5179 if (mask & WidthValue)
5180 *width = min (tempWidth, UINT_MAX);
5181 if (mask & HeightValue)
5182 *height = min (tempHeight, UINT_MAX);
5183 return mask;
5186 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
5189 /* NS used to define x-parse-geometry in ns-win.el, but that confused
5190 make-docfile: the documentation string in ns-win.el was used for
5191 x-parse-geometry even in non-NS builds.
5193 With two definitions of x-parse-geometry in this file, various
5194 things still get confused (eg M-x apropos documentation), so that
5195 it is best if the two definitions just share the same doc-string.
5197 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
5198 doc: /* Parse a display geometry string STRING.
5199 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
5200 The properties returned may include `top', `left', `height', and `width'.
5201 For X, the value of `left' or `top' may be an integer,
5202 or a list (+ N) meaning N pixels relative to top/left corner,
5203 or a list (- N) meaning -N pixels relative to bottom/right corner.
5204 On Nextstep, this just calls `ns-parse-geometry'. */)
5205 (Lisp_Object string)
5207 int geometry, x, y;
5208 unsigned int width, height;
5209 Lisp_Object result;
5211 CHECK_STRING (string);
5213 #ifdef HAVE_NS
5214 if (strchr (SSDATA (string), ' ') != NULL)
5215 return call1 (Qns_parse_geometry, string);
5216 #endif
5217 geometry = XParseGeometry (SSDATA (string),
5218 &x, &y, &width, &height);
5219 result = Qnil;
5220 if (geometry & XValue)
5222 Lisp_Object element;
5224 if (x >= 0 && (geometry & XNegative))
5225 element = list3 (Qleft, Qminus, make_number (-x));
5226 else if (x < 0 && ! (geometry & XNegative))
5227 element = list3 (Qleft, Qplus, make_number (x));
5228 else
5229 element = Fcons (Qleft, make_number (x));
5230 result = Fcons (element, result);
5233 if (geometry & YValue)
5235 Lisp_Object element;
5237 if (y >= 0 && (geometry & YNegative))
5238 element = list3 (Qtop, Qminus, make_number (-y));
5239 else if (y < 0 && ! (geometry & YNegative))
5240 element = list3 (Qtop, Qplus, make_number (y));
5241 else
5242 element = Fcons (Qtop, make_number (y));
5243 result = Fcons (element, result);
5246 if (geometry & WidthValue)
5247 result = Fcons (Fcons (Qwidth, make_number (width)), result);
5248 if (geometry & HeightValue)
5249 result = Fcons (Fcons (Qheight, make_number (height)), result);
5251 return result;
5255 /* Calculate the desired size and position of frame F.
5256 Return the flags saying which aspects were specified.
5258 Also set the win_gravity and size_hint_flags of F.
5260 Adjust height for toolbar if TOOLBAR_P is 1.
5262 This function does not make the coordinates positive. */
5264 #define DEFAULT_ROWS 36
5265 #define DEFAULT_COLS 80
5267 long
5268 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
5270 Lisp_Object height, width, user_size, top, left, user_position;
5271 long window_prompting = 0;
5272 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
5273 int parent_done = -1, outer_done = -1;
5275 /* Default values if we fall through.
5276 Actually, if that happens we should get
5277 window manager prompting. */
5278 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
5279 SET_FRAME_COLS (f, DEFAULT_COLS);
5280 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
5281 SET_FRAME_LINES (f, DEFAULT_ROWS);
5283 /* Window managers expect that if program-specified
5284 positions are not (0,0), they're intentional, not defaults. */
5285 f->top_pos = 0;
5286 f->left_pos = 0;
5288 /* Calculate a tool bar height so that the user gets a text display
5289 area of the size he specified with -g or via .Xdefaults. Later
5290 changes of the tool bar height don't change the frame size. This
5291 is done so that users can create tall Emacs frames without having
5292 to guess how tall the tool bar will get. */
5293 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
5295 if (frame_default_tool_bar_height)
5296 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
5297 else
5299 int margin, relief;
5301 relief = (tool_bar_button_relief >= 0
5302 ? tool_bar_button_relief
5303 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
5305 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
5306 margin = XFASTINT (Vtool_bar_button_margin);
5307 else if (CONSP (Vtool_bar_button_margin)
5308 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
5309 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
5310 else
5311 margin = 0;
5313 FRAME_TOOL_BAR_HEIGHT (f)
5314 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
5318 /* Ensure that earlier new_width and new_height settings won't
5319 override what we specify below. */
5320 f->new_width = f->new_height = 0;
5322 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
5323 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
5324 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
5326 if (!EQ (width, Qunbound))
5328 if (CONSP (width) && EQ (XCAR (width), Qtext_pixels))
5330 CHECK_NUMBER (XCDR (width));
5331 if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX))
5332 xsignal1 (Qargs_out_of_range, XCDR (width));
5334 SET_FRAME_WIDTH (f, XINT (XCDR (width)));
5335 f->inhibit_horizontal_resize = true;
5336 *x_width = XINT (XCDR (width));
5338 else if (FLOATP (width))
5340 double d_width = XFLOAT_DATA (width);
5342 if (d_width < 0.0 || d_width > 1.0)
5343 xsignal1 (Qargs_out_of_range, width);
5344 else
5346 int new_width = frame_float (f, width, FRAME_FLOAT_WIDTH,
5347 &parent_done, &outer_done, -1);
5349 if (new_width > -1)
5350 SET_FRAME_WIDTH (f, new_width);
5353 else
5355 CHECK_NUMBER (width);
5356 if ((XINT (width) < 0 || XINT (width) > INT_MAX))
5357 xsignal1 (Qargs_out_of_range, width);
5359 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
5363 if (!EQ (height, Qunbound))
5365 if (CONSP (height) && EQ (XCAR (height), Qtext_pixels))
5367 CHECK_NUMBER (XCDR (height));
5368 if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX))
5369 xsignal1 (Qargs_out_of_range, XCDR (height));
5371 SET_FRAME_HEIGHT (f, XINT (XCDR (height)));
5372 f->inhibit_vertical_resize = true;
5373 *x_height = XINT (XCDR (height));
5375 else if (FLOATP (height))
5377 double d_height = XFLOAT_DATA (height);
5379 if (d_height < 0.0 || d_height > 1.0)
5380 xsignal1 (Qargs_out_of_range, height);
5381 else
5383 int new_height = frame_float (f, height, FRAME_FLOAT_HEIGHT,
5384 &parent_done, &outer_done, -1);
5386 if (new_height > -1)
5387 SET_FRAME_HEIGHT (f, new_height);
5390 else
5392 CHECK_NUMBER (height);
5393 if ((XINT (height) < 0) || (XINT (height) > INT_MAX))
5394 xsignal1 (Qargs_out_of_range, height);
5396 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
5400 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
5401 if (!NILP (user_size) && !EQ (user_size, Qunbound))
5402 window_prompting |= USSize;
5403 else
5404 window_prompting |= PSize;
5407 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
5408 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
5409 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
5410 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
5412 if (EQ (top, Qminus))
5414 f->top_pos = 0;
5415 window_prompting |= YNegative;
5417 else if (CONSP (top) && EQ (XCAR (top), Qminus)
5418 && CONSP (XCDR (top))
5419 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
5421 f->top_pos = - XINT (XCAR (XCDR (top)));
5422 window_prompting |= YNegative;
5424 else if (CONSP (top) && EQ (XCAR (top), Qplus)
5425 && CONSP (XCDR (top))
5426 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
5428 f->top_pos = XINT (XCAR (XCDR (top)));
5430 else if (FLOATP (top))
5431 f->top_pos = frame_float (f, top, FRAME_FLOAT_TOP, &parent_done,
5432 &outer_done, 0);
5433 else if (EQ (top, Qunbound))
5434 f->top_pos = 0;
5435 else
5437 CHECK_TYPE_RANGED_INTEGER (int, top);
5438 f->top_pos = XINT (top);
5439 if (f->top_pos < 0)
5440 window_prompting |= YNegative;
5443 if (EQ (left, Qminus))
5445 f->left_pos = 0;
5446 window_prompting |= XNegative;
5448 else if (CONSP (left) && EQ (XCAR (left), Qminus)
5449 && CONSP (XCDR (left))
5450 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
5452 f->left_pos = - XINT (XCAR (XCDR (left)));
5453 window_prompting |= XNegative;
5455 else if (CONSP (left) && EQ (XCAR (left), Qplus)
5456 && CONSP (XCDR (left))
5457 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
5459 f->left_pos = XINT (XCAR (XCDR (left)));
5461 else if (FLOATP (left))
5462 f->left_pos = frame_float (f, left, FRAME_FLOAT_LEFT, &parent_done,
5463 &outer_done, 0);
5464 else if (EQ (left, Qunbound))
5465 f->left_pos = 0;
5466 else
5468 CHECK_TYPE_RANGED_INTEGER (int, left);
5469 f->left_pos = XINT (left);
5470 if (f->left_pos < 0)
5471 window_prompting |= XNegative;
5474 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
5475 window_prompting |= USPosition;
5476 else
5477 window_prompting |= PPosition;
5480 if (window_prompting & XNegative)
5482 if (window_prompting & YNegative)
5483 f->win_gravity = SouthEastGravity;
5484 else
5485 f->win_gravity = NorthEastGravity;
5487 else
5489 if (window_prompting & YNegative)
5490 f->win_gravity = SouthWestGravity;
5491 else
5492 f->win_gravity = NorthWestGravity;
5495 f->size_hint_flags = window_prompting;
5497 return window_prompting;
5502 #endif /* HAVE_WINDOW_SYSTEM */
5504 void
5505 frame_make_pointer_invisible (struct frame *f)
5507 if (! NILP (Vmake_pointer_invisible))
5509 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
5510 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
5512 f->mouse_moved = 0;
5513 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
5514 f->pointer_invisible = 1;
5519 void
5520 frame_make_pointer_visible (struct frame *f)
5522 /* We don't check Vmake_pointer_invisible here in case the
5523 pointer was invisible when Vmake_pointer_invisible was set to nil. */
5524 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
5525 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
5527 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
5528 f->pointer_invisible = 0;
5532 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
5533 Sframe_pointer_visible_p, 0, 1, 0,
5534 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
5535 Otherwise it returns nil. FRAME omitted or nil means the
5536 selected frame. This is useful when `make-pointer-invisible' is set. */)
5537 (Lisp_Object frame)
5539 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
5544 /***********************************************************************
5545 Multimonitor data
5546 ***********************************************************************/
5548 #ifdef HAVE_WINDOW_SYSTEM
5550 # if (defined HAVE_NS \
5551 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
5552 void
5553 free_monitors (struct MonitorInfo *monitors, int n_monitors)
5555 int i;
5556 for (i = 0; i < n_monitors; ++i)
5557 xfree (monitors[i].name);
5558 xfree (monitors);
5560 # endif
5562 Lisp_Object
5563 make_monitor_attribute_list (struct MonitorInfo *monitors,
5564 int n_monitors,
5565 int primary_monitor,
5566 Lisp_Object monitor_frames,
5567 const char *source)
5569 Lisp_Object attributes_list = Qnil;
5570 Lisp_Object primary_monitor_attributes = Qnil;
5571 int i;
5573 for (i = 0; i < n_monitors; ++i)
5575 Lisp_Object geometry, workarea, attributes = Qnil;
5576 struct MonitorInfo *mi = &monitors[i];
5578 if (mi->geom.width == 0) continue;
5580 workarea = list4i (mi->work.x, mi->work.y,
5581 mi->work.width, mi->work.height);
5582 geometry = list4i (mi->geom.x, mi->geom.y,
5583 mi->geom.width, mi->geom.height);
5584 attributes = Fcons (Fcons (Qsource, build_string (source)),
5585 attributes);
5586 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
5587 attributes);
5588 attributes = Fcons (Fcons (Qmm_size,
5589 list2i (mi->mm_width, mi->mm_height)),
5590 attributes);
5591 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
5592 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
5593 if (mi->name)
5594 attributes = Fcons (Fcons (Qname, make_string (mi->name,
5595 strlen (mi->name))),
5596 attributes);
5598 if (i == primary_monitor)
5599 primary_monitor_attributes = attributes;
5600 else
5601 attributes_list = Fcons (attributes, attributes_list);
5604 if (!NILP (primary_monitor_attributes))
5605 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
5606 return attributes_list;
5609 #endif /* HAVE_WINDOW_SYSTEM */
5612 /***********************************************************************
5613 Initialization
5614 ***********************************************************************/
5616 void
5617 syms_of_frame (void)
5619 DEFSYM (Qframep, "framep");
5620 DEFSYM (Qframe_live_p, "frame-live-p");
5621 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
5622 DEFSYM (Qdisplay_monitor_attributes_list, "display-monitor-attributes-list");
5623 DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total");
5624 DEFSYM (Qexplicit_name, "explicit-name");
5625 DEFSYM (Qheight, "height");
5626 DEFSYM (Qicon, "icon");
5627 DEFSYM (Qminibuffer, "minibuffer");
5628 DEFSYM (Qundecorated, "undecorated");
5629 DEFSYM (Qno_special_glyphs, "no-special-glyphs");
5630 DEFSYM (Qparent_frame, "parent-frame");
5631 DEFSYM (Qskip_taskbar, "skip-taskbar");
5632 DEFSYM (Qno_focus_on_map, "no-focus-on-map");
5633 DEFSYM (Qno_accept_focus, "no-accept-focus");
5634 DEFSYM (Qz_group, "z-group");
5635 DEFSYM (Qoverride_redirect, "override-redirect");
5636 DEFSYM (Qdelete_before, "delete-before");
5637 DEFSYM (Qmodeline, "modeline");
5638 DEFSYM (Qonly, "only");
5639 DEFSYM (Qnone, "none");
5640 DEFSYM (Qwidth, "width");
5641 DEFSYM (Qtext_pixels, "text-pixels");
5642 DEFSYM (Qgeometry, "geometry");
5643 DEFSYM (Qicon_left, "icon-left");
5644 DEFSYM (Qicon_top, "icon-top");
5645 DEFSYM (Qtooltip, "tooltip");
5646 DEFSYM (Quser_position, "user-position");
5647 DEFSYM (Quser_size, "user-size");
5648 DEFSYM (Qwindow_id, "window-id");
5649 #ifdef HAVE_X_WINDOWS
5650 DEFSYM (Qouter_window_id, "outer-window-id");
5651 #endif
5652 DEFSYM (Qparent_id, "parent-id");
5653 DEFSYM (Qx, "x");
5654 DEFSYM (Qw32, "w32");
5655 DEFSYM (Qpc, "pc");
5656 DEFSYM (Qns, "ns");
5657 DEFSYM (Qvisible, "visible");
5658 DEFSYM (Qbuffer_predicate, "buffer-predicate");
5659 DEFSYM (Qbuffer_list, "buffer-list");
5660 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
5661 DEFSYM (Qdisplay_type, "display-type");
5662 DEFSYM (Qbackground_mode, "background-mode");
5663 DEFSYM (Qnoelisp, "noelisp");
5664 DEFSYM (Qtty_color_mode, "tty-color-mode");
5665 DEFSYM (Qtty, "tty");
5666 DEFSYM (Qtty_type, "tty-type");
5668 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
5670 DEFSYM (Qfullwidth, "fullwidth");
5671 DEFSYM (Qfullheight, "fullheight");
5672 DEFSYM (Qfullboth, "fullboth");
5673 DEFSYM (Qmaximized, "maximized");
5674 DEFSYM (Qx_resource_name, "x-resource-name");
5675 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
5677 DEFSYM (Qworkarea, "workarea");
5678 DEFSYM (Qmm_size, "mm-size");
5679 DEFSYM (Qframes, "frames");
5680 DEFSYM (Qsource, "source");
5682 DEFSYM (Qframe_edges, "frame-edges");
5683 DEFSYM (Qouter_edges, "outer-edges");
5684 DEFSYM (Qouter_position, "outer-position");
5685 DEFSYM (Qouter_size, "outer-size");
5686 DEFSYM (Qnative_edges, "native-edges");
5687 DEFSYM (Qinner_edges, "inner-edges");
5688 DEFSYM (Qexternal_border_size, "external-border-size");
5689 DEFSYM (Qtitle_bar_size, "title-bar-size");
5690 DEFSYM (Qmenu_bar_external, "menu-bar-external");
5691 DEFSYM (Qmenu_bar_size, "menu-bar-size");
5692 DEFSYM (Qtool_bar_external, "tool-bar-external");
5693 DEFSYM (Qtool_bar_size, "tool-bar-size");
5694 /* The following are used for frame_size_history. */
5695 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
5696 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
5697 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
5698 DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
5699 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
5700 DEFSYM (Qset_frame_size, "set-frame-size");
5701 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
5702 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
5703 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
5704 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
5705 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
5706 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
5707 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
5708 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
5709 DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
5710 DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
5711 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
5712 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
5713 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
5714 DEFSYM (Qtb_size_cb, "tb-size-cb");
5715 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
5716 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
5717 DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines");
5718 DEFSYM (Qchange_frame_size, "change-frame-size");
5719 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
5720 DEFSYM (Qset_window_configuration, "set-window-configuration");
5721 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
5722 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
5723 DEFSYM (Qterminal_frame, "terminal-frame");
5725 #ifdef HAVE_NS
5726 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
5727 #endif
5728 #ifdef NS_IMPL_COCOA
5729 DEFSYM (Qns_appearance, "ns-appearance");
5730 DEFSYM (Qns_transparent_titlebar, "ns-transparent-titlebar");
5731 #endif
5733 DEFSYM (Qalpha, "alpha");
5734 DEFSYM (Qauto_lower, "auto-lower");
5735 DEFSYM (Qauto_raise, "auto-raise");
5736 DEFSYM (Qborder_color, "border-color");
5737 DEFSYM (Qborder_width, "border-width");
5738 DEFSYM (Qouter_border_width, "outer-border-width");
5739 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
5740 DEFSYM (Qcursor_color, "cursor-color");
5741 DEFSYM (Qcursor_type, "cursor-type");
5742 DEFSYM (Qfont_backend, "font-backend");
5743 DEFSYM (Qfullscreen, "fullscreen");
5744 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
5745 DEFSYM (Qicon_name, "icon-name");
5746 DEFSYM (Qicon_type, "icon-type");
5747 DEFSYM (Qinternal_border_width, "internal-border-width");
5748 DEFSYM (Qleft_fringe, "left-fringe");
5749 DEFSYM (Qline_spacing, "line-spacing");
5750 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
5751 DEFSYM (Qupdate_frame_menubar, "update-frame-menubar");
5752 DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1");
5753 DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2");
5754 DEFSYM (Qmouse_color, "mouse-color");
5755 DEFSYM (Qname, "name");
5756 DEFSYM (Qright_divider_width, "right-divider-width");
5757 DEFSYM (Qright_fringe, "right-fringe");
5758 DEFSYM (Qscreen_gamma, "screen-gamma");
5759 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
5760 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
5761 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
5762 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
5763 DEFSYM (Qsticky, "sticky");
5764 DEFSYM (Qtitle, "title");
5765 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
5766 DEFSYM (Qtool_bar_position, "tool-bar-position");
5767 DEFSYM (Qunsplittable, "unsplittable");
5768 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
5769 DEFSYM (Qvisibility, "visibility");
5770 DEFSYM (Qwait_for_wm, "wait-for-wm");
5771 DEFSYM (Qinhibit_double_buffering, "inhibit-double-buffering");
5772 DEFSYM (Qno_other_frame, "no-other-frame");
5773 DEFSYM (Qbelow, "below");
5774 DEFSYM (Qabove_suspended, "above-suspended");
5775 DEFSYM (Qmin_width, "min-width");
5776 DEFSYM (Qmin_height, "min-height");
5777 DEFSYM (Qmouse_wheel_frame, "mouse-wheel-frame");
5778 DEFSYM (Qkeep_ratio, "keep-ratio");
5779 DEFSYM (Qwidth_only, "width-only");
5780 DEFSYM (Qheight_only, "height-only");
5781 DEFSYM (Qleft_only, "left-only");
5782 DEFSYM (Qtop_only, "top-only");
5783 DEFSYM (Qiconify_top_level, "iconify-top-level");
5784 DEFSYM (Qmake_invisible, "make-invisible");
5787 int i;
5789 for (i = 0; i < ARRAYELTS (frame_parms); i++)
5791 Lisp_Object v = (frame_parms[i].sym < 0
5792 ? intern_c_string (frame_parms[i].name)
5793 : builtin_lisp_symbol (frame_parms[i].sym));
5794 Fput (v, Qx_frame_parameter, make_number (i));
5798 #ifdef HAVE_WINDOW_SYSTEM
5799 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
5800 doc: /* The name Emacs uses to look up X resources.
5801 `x-get-resource' uses this as the first component of the instance name
5802 when requesting resource values.
5803 Emacs initially sets `x-resource-name' to the name under which Emacs
5804 was invoked, or to the value specified with the `-name' or `-rn'
5805 switches, if present.
5807 It may be useful to bind this variable locally around a call
5808 to `x-get-resource'. See also the variable `x-resource-class'. */);
5809 Vx_resource_name = Qnil;
5811 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5812 doc: /* The class Emacs uses to look up X resources.
5813 `x-get-resource' uses this as the first component of the instance class
5814 when requesting resource values.
5816 Emacs initially sets `x-resource-class' to "Emacs".
5818 Setting this variable permanently is not a reasonable thing to do,
5819 but binding this variable locally around a call to `x-get-resource'
5820 is a reasonable practice. See also the variable `x-resource-name'. */);
5821 Vx_resource_class = build_string (EMACS_CLASS);
5823 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5824 doc: /* The lower limit of the frame opacity (alpha transparency).
5825 The value should range from 0 (invisible) to 100 (completely opaque).
5826 You can also use a floating number between 0.0 and 1.0. */);
5827 Vframe_alpha_lower_limit = make_number (20);
5828 #endif
5830 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5831 doc: /* Alist of default values for frame creation.
5832 These may be set in your init file, like this:
5833 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5834 These override values given in window system configuration data,
5835 including X Windows' defaults database.
5836 For values specific to the first Emacs frame, see `initial-frame-alist'.
5837 For window-system specific values, see `window-system-default-frame-alist'.
5838 For values specific to the separate minibuffer frame, see
5839 `minibuffer-frame-alist'.
5840 The `menu-bar-lines' element of the list controls whether new frames
5841 have menu bars; `menu-bar-mode' works by altering this element.
5842 Setting this variable does not affect existing frames, only new ones. */);
5843 Vdefault_frame_alist = Qnil;
5845 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5846 doc: /* Default position of vertical scroll bars on this window-system. */);
5847 #ifdef HAVE_WINDOW_SYSTEM
5848 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5849 /* MS-Windows, macOS, and GTK have scroll bars on the right by
5850 default. */
5851 Vdefault_frame_scroll_bars = Qright;
5852 #else
5853 Vdefault_frame_scroll_bars = Qleft;
5854 #endif
5855 #else
5856 Vdefault_frame_scroll_bars = Qnil;
5857 #endif
5859 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5860 scroll_bar_adjust_thumb_portion_p,
5861 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5862 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5863 even if the end of the buffer is shown (i.e. overscrolling).
5864 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5865 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5866 is visible. In this case you can not overscroll. */);
5867 scroll_bar_adjust_thumb_portion_p = 1;
5869 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5870 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5872 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5873 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5874 `mouse-position' and `mouse-pixel-position' call this function, passing their
5875 usual return value as argument, and return whatever this function returns.
5876 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5877 which need to do mouse handling at the Lisp level. */);
5878 Vmouse_position_function = Qnil;
5880 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5881 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5882 If the value is an integer, highlighting is only shown after moving the
5883 mouse, while keyboard input turns off the highlight even when the mouse
5884 is over the clickable text. However, the mouse shape still indicates
5885 when the mouse is over clickable text. */);
5886 Vmouse_highlight = Qt;
5888 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5889 doc: /* If non-nil, make pointer invisible while typing.
5890 The pointer becomes visible again when the mouse is moved. */);
5891 Vmake_pointer_invisible = Qt;
5893 DEFVAR_LISP ("move-frame-functions", Vmove_frame_functions,
5894 doc: /* Functions run after a frame was moved.
5895 The functions are run with one arg, the frame that moved. */);
5896 Vmove_frame_functions = Qnil;
5898 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5899 doc: /* Functions run before deleting a frame.
5900 The functions are run with one arg, the frame to be deleted.
5901 See `delete-frame'.
5903 Note that functions in this list may be called just before the frame is
5904 actually deleted, or some time later (or even both when an earlier function
5905 in `delete-frame-functions' (indirectly) calls `delete-frame'
5906 recursively). */);
5907 Vdelete_frame_functions = Qnil;
5908 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5910 DEFVAR_LISP ("after-delete-frame-functions",
5911 Vafter_delete_frame_functions,
5912 doc: /* Functions run after deleting a frame.
5913 The functions are run with one arg, the frame that was deleted and
5914 which is now dead. */);
5915 Vafter_delete_frame_functions = Qnil;
5916 DEFSYM (Qafter_delete_frame_functions, "after-delete-frame-functions");
5918 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5919 doc: /* Non-nil if Menu-Bar mode is enabled.
5920 See the command `menu-bar-mode' for a description of this minor mode.
5921 Setting this variable directly does not take effect;
5922 either customize it (see the info node `Easy Customization')
5923 or call the function `menu-bar-mode'. */);
5924 Vmenu_bar_mode = Qt;
5926 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5927 doc: /* Non-nil if Tool-Bar mode is enabled.
5928 See the command `tool-bar-mode' for a description of this minor mode.
5929 Setting this variable directly does not take effect;
5930 either customize it (see the info node `Easy Customization')
5931 or call the function `tool-bar-mode'. */);
5932 #ifdef HAVE_WINDOW_SYSTEM
5933 Vtool_bar_mode = Qt;
5934 #else
5935 Vtool_bar_mode = Qnil;
5936 #endif
5938 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5939 doc: /* Minibuffer-less frames by default use this frame's minibuffer.
5940 Emacs consults this variable only when creating a minibuffer-less frame
5941 and no explicit minibuffer window has been specified for that frame via
5942 the `minibuffer' frame parameter. Once such a frame has been created,
5943 setting this variable does not change that frame's previous association.
5945 This variable is local to the current terminal and cannot be buffer-local. */);
5947 DEFVAR_LISP ("focus-follows-mouse", focus_follows_mouse,
5948 doc: /* Non-nil if window system changes focus when you move the mouse.
5949 You should set this variable to tell Emacs how your window manager
5950 handles focus, since there is no way in general for Emacs to find out
5951 automatically.
5953 There are three meaningful values:
5955 - The default nil should be used when your window manager follows a
5956 "click-to-focus" policy where you have to click the mouse inside of a
5957 frame in order for that frame to get focus.
5959 - The value t should be used when your window manager has the focus
5960 automatically follow the position of the mouse pointer but a window
5961 that gains focus is not raised automatically.
5963 - The value `auto-raise' should be used when your window manager has the
5964 focus automatically follow the position of the mouse pointer and a
5965 window that gains focus is raised automatically.
5967 If this option is non-nil, Emacs moves the mouse pointer to the frame
5968 selected by `select-frame-set-input-focus'. This function is used by a
5969 number of commands like, for example, `other-frame' and `pop-to-buffer'.
5970 If this option is nil and your focus follows mouse window manager does
5971 not autonomously move the mouse pointer to the newly selected frame, the
5972 previously selected window manager window might get reselected instead
5973 immediately.
5975 The distinction between the values t and `auto-raise' is not needed for
5976 "normal" frames because the window manager takes care of raising them.
5977 Setting this to `auto-raise' will, however, override the standard
5978 behavior of a window manager that does not automatically raise the frame
5979 that gets focus. Setting this to `auto-raise' is also necessary to
5980 automatically raise child frames which are usually left alone by the
5981 window manager.
5983 Note that this option does not distinguish "sloppy" focus (where the
5984 frame that previously had focus retains focus as long as the mouse
5985 pointer does not move into another window manager window) from "strict"
5986 focus (where a frame immediately loses focus when it's left by the mouse
5987 pointer).
5989 In order to extend a "focus follows mouse" policy to individual Emacs
5990 windows, customize the variable `mouse-autoselect-window'. */);
5991 focus_follows_mouse = Qnil;
5993 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5994 doc: /* Non-nil means resize frames pixelwise.
5995 If this option is nil, resizing a frame rounds its sizes to the frame's
5996 current values of `frame-char-height' and `frame-char-width'. If this
5997 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5998 by one pixel.
6000 With some window managers you may have to set this to non-nil in order
6001 to set the size of a frame in pixels, to maximize frames or to make them
6002 fullscreen. To resize your initial frame pixelwise, set this option to
6003 a non-nil value in your init file. */);
6004 frame_resize_pixelwise = 0;
6006 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
6007 doc: /* Whether frames should be resized implicitly.
6008 If this option is nil, setting font, menu bar, tool bar, internal
6009 borders, fringes or scroll bars of a specific frame may resize the frame
6010 in order to preserve the number of columns or lines it displays. If
6011 this option is t, no such resizing is done. Note that the size of
6012 fullscreen and maximized frames, the height of fullheight frames and the
6013 width of fullwidth frames never change implicitly.
6015 The value of this option can be also be a list of frame parameters. In
6016 this case, resizing is inhibited when changing a parameter that appears
6017 in that list. The parameters currently handled by this option include
6018 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
6019 `tool-bar-lines'.
6021 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
6022 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
6023 `right-fringe' is handled as if the frame contained just one live
6024 window. This means, for example, that removing vertical scroll bars on
6025 a frame containing several side by side windows will shrink the frame
6026 width by the width of one scroll bar provided this option is nil and
6027 keep it unchanged if this option is either t or a list containing
6028 `vertical-scroll-bars'.
6030 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
6031 \(which means that adding/removing a tool bar does not change the frame
6032 height), nil on all other window systems including GTK+ (which means
6033 that changing any of the parameters listed above may change the size of
6034 the frame), and t otherwise (which means the frame size never changes
6035 implicitly when there's no window system support).
6037 Note that when a frame is not large enough to accommodate a change of
6038 any of the parameters listed above, Emacs may try to enlarge the frame
6039 even if this option is non-nil. */);
6040 #if defined (HAVE_WINDOW_SYSTEM)
6041 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
6042 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
6043 #else
6044 frame_inhibit_implied_resize = Qnil;
6045 #endif
6046 #else
6047 frame_inhibit_implied_resize = Qt;
6048 #endif
6050 DEFVAR_LISP ("frame-size-history", frame_size_history,
6051 doc: /* History of frame size adjustments.
6052 If non-nil, list recording frame size adjustment. Adjustments are
6053 recorded only if the first element of this list is a positive number.
6054 Adding an adjustment decrements that number by one.
6056 The remaining elements are the adjustments. Each adjustment is a list
6057 of four elements `frame', `function', `sizes' and `more'. `frame' is
6058 the affected frame and `function' the invoking function. `sizes' is
6059 usually a list of four elements `old-width', `old-height', `new-width'
6060 and `new-height' representing the old and new sizes recorded/requested
6061 by `function'. `more' is a list with additional information.
6063 The function `frame--size-history' displays the value of this variable
6064 in a more readable form. */);
6065 frame_size_history = Qnil;
6067 DEFVAR_BOOL ("tooltip-reuse-hidden-frame", tooltip_reuse_hidden_frame,
6068 doc: /* Non-nil means reuse hidden tooltip frames.
6069 When this is nil, delete a tooltip frame when hiding the associated
6070 tooltip. When this is non-nil, make the tooltip frame invisible only,
6071 so it can be reused when the next tooltip is shown.
6073 Setting this to non-nil may drastically reduce the consing overhead
6074 incurred by creating new tooltip frames. However, a value of non-nil
6075 means also that intermittent changes of faces or `default-frame-alist'
6076 are not applied when showing a tooltip in a reused frame.
6078 This variable is effective only with the X toolkit (and there only when
6079 Gtk+ tooltips are not used) and on Windows. */);
6080 tooltip_reuse_hidden_frame = false;
6082 DEFVAR_LISP ("iconify-child-frame", iconify_child_frame,
6083 doc: /* How to handle iconification of child frames.
6084 This variable tells Emacs how to proceed when it is asked to iconify a
6085 child frame. If it is nil, `iconify-frame' will do nothing when invoked
6086 on a child frame. If it is `iconify-top-level', Emacs will try to
6087 iconify the top level frame associated with this child frame instead.
6088 If it is `make-invisible', Emacs will try to make this child frame
6089 invisible instead.
6091 Any other value means to try iconifying the child frame. Since such an
6092 attempt is not honored by all window managers and may even lead to
6093 making the child frame unresponsive to user actions, the default is to
6094 iconify the top level frame instead. */);
6095 iconify_child_frame = Qiconify_top_level;
6097 staticpro (&Vframe_list);
6099 defsubr (&Sframep);
6100 defsubr (&Sframe_live_p);
6101 defsubr (&Swindow_system);
6102 defsubr (&Sframe_windows_min_size);
6103 defsubr (&Smake_terminal_frame);
6104 defsubr (&Shandle_switch_frame);
6105 defsubr (&Sselect_frame);
6106 defsubr (&Sselected_frame);
6107 defsubr (&Sframe_list);
6108 defsubr (&Sframe_parent);
6109 defsubr (&Sframe_ancestor_p);
6110 defsubr (&Snext_frame);
6111 defsubr (&Sprevious_frame);
6112 defsubr (&Slast_nonminibuf_frame);
6113 defsubr (&Sdelete_frame);
6114 defsubr (&Smouse_position);
6115 defsubr (&Smouse_pixel_position);
6116 defsubr (&Sset_mouse_position);
6117 defsubr (&Sset_mouse_pixel_position);
6118 #if 0
6119 defsubr (&Sframe_configuration);
6120 defsubr (&Srestore_frame_configuration);
6121 #endif
6122 defsubr (&Smake_frame_visible);
6123 defsubr (&Smake_frame_invisible);
6124 defsubr (&Siconify_frame);
6125 defsubr (&Sframe_visible_p);
6126 defsubr (&Svisible_frame_list);
6127 defsubr (&Sraise_frame);
6128 defsubr (&Slower_frame);
6129 defsubr (&Sx_focus_frame);
6130 defsubr (&Sframe_after_make_frame);
6131 defsubr (&Sredirect_frame_focus);
6132 defsubr (&Sframe_focus);
6133 defsubr (&Sframe_parameters);
6134 defsubr (&Sframe_parameter);
6135 defsubr (&Smodify_frame_parameters);
6136 defsubr (&Sframe_char_height);
6137 defsubr (&Sframe_char_width);
6138 defsubr (&Sframe_native_height);
6139 defsubr (&Sframe_native_width);
6140 defsubr (&Sframe_text_cols);
6141 defsubr (&Sframe_text_lines);
6142 defsubr (&Sframe_total_cols);
6143 defsubr (&Sframe_total_lines);
6144 defsubr (&Sframe_text_width);
6145 defsubr (&Sframe_text_height);
6146 defsubr (&Sscroll_bar_width);
6147 defsubr (&Sscroll_bar_height);
6148 defsubr (&Sfringe_width);
6149 defsubr (&Sframe_internal_border_width);
6150 defsubr (&Sright_divider_width);
6151 defsubr (&Sbottom_divider_width);
6152 defsubr (&Stool_bar_pixel_width);
6153 defsubr (&Sset_frame_height);
6154 defsubr (&Sset_frame_width);
6155 defsubr (&Sset_frame_size);
6156 defsubr (&Sframe_position);
6157 defsubr (&Sset_frame_position);
6158 defsubr (&Sframe_pointer_visible_p);
6160 #ifdef HAVE_WINDOW_SYSTEM
6161 defsubr (&Sx_get_resource);
6162 defsubr (&Sx_parse_geometry);
6163 #endif