* src/keyboard.c (syms_of_keyboard): Doc fix. (Bug#30588)
[emacs.git] / src / frame.c
bloba86f05191a8d6fd11dd73eacd60aa80e1935b536
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 "frame.h"
39 #include "blockinput.h"
40 #include "termchar.h"
41 #include "termhooks.h"
42 #include "dispextern.h"
43 #include "window.h"
44 #ifdef HAVE_WINDOW_SYSTEM
45 #include "fontset.h"
46 #endif
47 #include "cm.h"
48 #ifdef MSDOS
49 #include "msdos.h"
50 #include "dosfns.h"
51 #endif
52 #ifdef USE_X_TOOLKIT
53 #include "widget.h"
54 #endif
56 /* The currently selected frame. */
58 Lisp_Object selected_frame;
60 /* A frame which is not just a mini-buffer, or NULL if there are no such
61 frames. This is usually the most recent such frame that was selected. */
63 static struct frame *last_nonminibuf_frame;
65 /* False means there are no visible garbaged frames. */
66 bool frame_garbaged;
68 /* The default tool bar height for future frames. */
69 #if defined USE_GTK || defined HAVE_NS
70 enum { frame_default_tool_bar_height = 0 };
71 #else
72 int frame_default_tool_bar_height;
73 #endif
75 #ifdef HAVE_WINDOW_SYSTEM
76 static void x_report_frame_params (struct frame *, Lisp_Object *);
77 #endif
79 /* These setters are used only in this file, so they can be private. */
80 static void
81 fset_buffer_predicate (struct frame *f, Lisp_Object val)
83 f->buffer_predicate = val;
85 static void
86 fset_minibuffer_window (struct frame *f, Lisp_Object val)
88 f->minibuffer_window = val;
91 struct frame *
92 decode_live_frame (register Lisp_Object frame)
94 if (NILP (frame))
95 frame = selected_frame;
96 CHECK_LIVE_FRAME (frame);
97 return XFRAME (frame);
100 struct frame *
101 decode_any_frame (register Lisp_Object frame)
103 if (NILP (frame))
104 frame = selected_frame;
105 CHECK_FRAME (frame);
106 return XFRAME (frame);
109 #ifdef HAVE_WINDOW_SYSTEM
110 bool
111 display_available (void)
113 return x_display_list != NULL;
115 #endif
117 struct frame *
118 decode_window_system_frame (Lisp_Object frame)
120 struct frame *f = decode_live_frame (frame);
121 check_window_system (f);
122 #ifdef HAVE_WINDOW_SYSTEM
123 return f;
124 #endif
127 void
128 check_window_system (struct frame *f)
130 #ifdef HAVE_WINDOW_SYSTEM
131 if (window_system_available (f))
132 return;
133 #endif
134 error (f ? "Window system frame should be used"
135 : "Window system is not in use or not initialized");
138 /* Return the value of frame parameter PROP in frame FRAME. */
140 Lisp_Object
141 get_frame_param (register struct frame *frame, Lisp_Object prop)
143 register Lisp_Object tem;
145 tem = Fassq (prop, frame->param_alist);
146 if (EQ (tem, Qnil))
147 return tem;
148 return Fcdr (tem);
152 void
153 frame_size_history_add (struct frame *f, Lisp_Object fun_symbol,
154 int width, int height, Lisp_Object rest)
156 Lisp_Object frame;
158 XSETFRAME (frame, f);
159 if (CONSP (frame_size_history)
160 && INTEGERP (XCAR (frame_size_history))
161 && 0 < XINT (XCAR (frame_size_history)))
162 frame_size_history =
163 Fcons (make_number (XINT (XCAR (frame_size_history)) - 1),
164 Fcons (list4
165 (frame, fun_symbol,
166 ((width > 0)
167 ? list4 (make_number (FRAME_TEXT_WIDTH (f)),
168 make_number (FRAME_TEXT_HEIGHT (f)),
169 make_number (width),
170 make_number (height))
171 : Qnil),
172 rest),
173 XCDR (frame_size_history)));
177 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
178 state of frame F would be affected by a vertical (horizontal if
179 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
180 parameter that is changed. */
181 bool
182 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
184 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
185 bool inhibit
186 = (f->after_make_frame
187 ? (EQ (frame_inhibit_implied_resize, Qt)
188 || (CONSP (frame_inhibit_implied_resize)
189 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))
190 || (horizontal
191 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight))
192 || (!horizontal
193 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth))
194 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
195 : ((horizontal && f->inhibit_horizontal_resize)
196 || (!horizontal && f->inhibit_vertical_resize)));
197 if (inhibit && !FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
198 frame_size_history_add
199 (f, Qframe_inhibit_resize, 0, 0,
200 list5 (horizontal ? Qt : Qnil, parameter,
201 f->after_make_frame ? Qt : Qnil,
202 frame_inhibit_implied_resize,
203 fullscreen));
205 return inhibit;
208 static void
209 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
211 int nlines;
212 int olines = FRAME_MENU_BAR_LINES (f);
214 /* Right now, menu bars don't work properly in minibuf-only frames;
215 most of the commands try to apply themselves to the minibuffer
216 frame itself, and get an error because you can't switch buffers
217 in or split the minibuffer window. */
218 if (FRAME_MINIBUF_ONLY_P (f))
219 return;
221 if (TYPE_RANGED_INTEGERP (int, value))
222 nlines = XINT (value);
223 else
224 nlines = 0;
226 if (nlines != olines)
228 windows_or_buffers_changed = 14;
229 FRAME_MENU_BAR_LINES (f) = nlines;
230 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
231 change_frame_size (f, FRAME_COLS (f),
232 FRAME_LINES (f) + olines - nlines,
233 0, 1, 0, 0);
237 Lisp_Object Vframe_list;
240 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
241 doc: /* Return non-nil if OBJECT is a frame.
242 Value is:
243 t for a termcap frame (a character-only terminal),
244 `x' for an Emacs frame that is really an X window,
245 `w32' for an Emacs frame that is a window on MS-Windows display,
246 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
247 `pc' for a direct-write MS-DOS frame.
248 See also `frame-live-p'. */)
249 (Lisp_Object object)
251 if (!FRAMEP (object))
252 return Qnil;
253 switch (XFRAME (object)->output_method)
255 case output_initial: /* The initial frame is like a termcap frame. */
256 case output_termcap:
257 return Qt;
258 case output_x_window:
259 return Qx;
260 case output_w32:
261 return Qw32;
262 case output_msdos_raw:
263 return Qpc;
264 case output_ns:
265 return Qns;
266 default:
267 emacs_abort ();
271 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
272 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
273 Value is nil if OBJECT is not a live frame. If object is a live
274 frame, the return value indicates what sort of terminal device it is
275 displayed on. See the documentation of `framep' for possible
276 return values. */)
277 (Lisp_Object object)
279 return ((FRAMEP (object)
280 && FRAME_LIVE_P (XFRAME (object)))
281 ? Fframep (object)
282 : Qnil);
285 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
286 doc: /* The name of the window system that FRAME is displaying through.
287 The value is a symbol:
288 nil for a termcap frame (a character-only terminal),
289 `x' for an Emacs frame that is really an X window,
290 `w32' for an Emacs frame that is a window on MS-Windows display,
291 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
292 `pc' for a direct-write MS-DOS frame.
294 FRAME defaults to the currently selected frame.
296 Use of this function as a predicate is deprecated. Instead,
297 use `display-graphic-p' or any of the other `display-*-p'
298 predicates which report frame's specific UI-related capabilities. */)
299 (Lisp_Object frame)
301 Lisp_Object type;
302 if (NILP (frame))
303 frame = selected_frame;
305 type = Fframep (frame);
307 if (NILP (type))
308 wrong_type_argument (Qframep, frame);
310 if (EQ (type, Qt))
311 return Qnil;
312 else
313 return type;
316 /* Placeholder used by temacs -nw before window.el is loaded. */
317 DEFUN ("frame-windows-min-size", Fframe_windows_min_size,
318 Sframe_windows_min_size, 4, 4, 0,
319 doc: /* */
320 attributes: const)
321 (Lisp_Object frame, Lisp_Object horizontal,
322 Lisp_Object ignore, Lisp_Object pixelwise)
324 return make_number (0);
328 * frame_windows_min_size:
330 * Return the minimum number of lines (columns if HORIZONTAL is non-nil)
331 * of FRAME. If PIXELWISE is non-nil, return the minimum inner height
332 * (width) of FRAME in pixels.
334 * This value is calculated by the function `frame-windows-min-size' in
335 * window.el unless the `min-height' (`min-width' if HORIZONTAL is
336 * non-nil) parameter of FRAME is non-nil thus explicitly specifying the
337 * value to be returned. In that latter case IGNORE is ignored.
339 * If `frame-windows-min-size' is called, it will make sure that the
340 * return value accommodates all windows of FRAME respecting the values
341 * of `window-min-height' (`window-min-width' if HORIZONTAL is non-nil).
342 * With IGNORE non-nil the values of these variables are ignored.
344 * In either case, never return a value less than 1. For TTY frames,
345 * additionally limit the minimum frame height to a value large enough
346 * to support the menu bar, the mode line, and the echo area.
348 static int
349 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal,
350 Lisp_Object ignore, Lisp_Object pixelwise)
352 struct frame *f = XFRAME (frame);
353 Lisp_Object par_size;
354 int retval;
356 if ((!NILP (horizontal)
357 && NUMBERP (par_size = get_frame_param (f, Qmin_width)))
358 || (NILP (horizontal)
359 && NUMBERP (par_size = get_frame_param (f, Qmin_height))))
361 int min_size = XINT (par_size);
363 /* Don't allow phantom frames. */
364 if (min_size < 1)
365 min_size = 1;
367 retval = (NILP (pixelwise)
368 ? min_size
369 : min_size * (NILP (horizontal)
370 ? FRAME_LINE_HEIGHT (f)
371 : FRAME_COLUMN_WIDTH (f)));
373 else
374 retval = XINT (call4 (Qframe_windows_min_size, frame, horizontal,
375 ignore, pixelwise));
376 /* Don't allow too small height of text-mode frames, or else cm.c
377 might abort in cmcheckmagic. */
378 if ((FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) && NILP (horizontal))
380 int min_height = (FRAME_MENU_BAR_LINES (f)
381 + FRAME_WANTS_MODELINE_P (f)
382 + 2); /* one text line and one echo-area line */
383 if (retval < min_height)
384 retval = min_height;
387 return retval;
391 #ifdef HAVE_WINDOW_SYSTEM
393 * keep_ratio:
395 * Preserve ratios of frame F which usually happens after its parent
396 * frame P got resized. OLD_WIDTH, OLD_HEIGHT specifies the old native
397 * size of F's parent, NEW_WIDTH and NEW_HEIGHT its new size.
399 * Adjust F's width if F's 'keep_ratio' parameter is non-nil and, if
400 * it is a cons, its car is not 'height-only'. Adjust F's height if F's
401 * 'keep_ratio' parameter is non-nil and, if it is a cons, its car
402 * is not 'width-only'.
404 * Adjust F's left position if F's 'keep_ratio' parameter is non-nil
405 * and, if its is a cons, its cdr is non-nil and not 'top-only'. Adjust
406 * F's top position if F's 'keep_ratio' parameter is non-nil and, if
407 * its is a cons, its cdr is non-nil and not 'left-only'.
409 * Note that when positional adjustment is requested but the size of F
410 * should remain unaltered in the corresponding direction, this routine
411 * tries to constrain F to its parent frame - something which usually
412 * happens when the parent frame shrinks. This means, however, that
413 * when the parent frame is re-enlarged later, the child's original
414 * position will not get restored to its pre-shrinking value.
416 * This routine is currently useful for child frames only. It might be
417 * eventually useful when moving non-child frames between monitors with
418 * different resolutions.
420 static void
421 keep_ratio (struct frame *f, struct frame *p, int old_width, int old_height,
422 int new_width, int new_height)
424 Lisp_Object keep_ratio = get_frame_param (f, Qkeep_ratio);
427 if (!NILP (keep_ratio))
429 double width_factor = (double)new_width / (double)old_width;
430 double height_factor = (double)new_height / (double)old_height;
431 int pixel_width, pixel_height, pos_x, pos_y;
433 if (!CONSP (keep_ratio) || !NILP (Fcdr (keep_ratio)))
435 if (CONSP (keep_ratio) && EQ (Fcdr (keep_ratio), Qtop_only))
436 pos_x = f->left_pos;
437 else
439 pos_x = (int)(f->left_pos * width_factor + 0.5);
441 if (CONSP (keep_ratio)
442 && (NILP (Fcar (keep_ratio))
443 || EQ (Fcar (keep_ratio), Qheight_only))
444 && p->pixel_width - f->pixel_width < pos_x)
446 int p_f_width = p->pixel_width - f->pixel_width;
448 if (p_f_width <= 0)
449 pos_x = 0;
450 else
451 pos_x = (int)(p_f_width * width_factor * 0.5 + 0.5);
454 f->left_pos = pos_x;
457 if (CONSP (keep_ratio) && EQ (Fcdr (keep_ratio), Qleft_only))
458 pos_y = f->top_pos;
459 else
461 pos_y = (int)(f->top_pos * height_factor + 0.5);
463 if (CONSP (keep_ratio)
464 && (NILP (Fcar (keep_ratio))
465 || EQ (Fcar (keep_ratio), Qwidth_only))
466 && p->pixel_height - f->pixel_height < pos_y)
467 /* When positional adjustment was requested and the
468 width of F should remain unaltered, try to constrain
469 F to its parent. This means that when the parent
470 frame is enlarged later the child's original position
471 won't get restored. */
473 int p_f_height = p->pixel_height - f->pixel_height;
475 if (p_f_height <= 0)
476 pos_y = 0;
477 else
478 pos_y = (int)(p_f_height * height_factor * 0.5 + 0.5);
481 f->top_pos = pos_y;
484 x_set_offset (f, pos_x, pos_y, -1);
487 if (!CONSP (keep_ratio) || !NILP (Fcar (keep_ratio)))
489 if (CONSP (keep_ratio) && EQ (Fcar (keep_ratio), Qheight_only))
490 pixel_width = -1;
491 else
493 pixel_width = (int)(f->pixel_width * width_factor + 0.5);
494 pixel_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, pixel_width);
497 if (CONSP (keep_ratio) && EQ (Fcar (keep_ratio), Qwidth_only))
498 pixel_height = -1;
499 else
501 pixel_height = (int)(f->pixel_height * height_factor + 0.5);
502 pixel_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, pixel_height);
505 adjust_frame_size (f, pixel_width, pixel_height, 1, 0,
506 Qkeep_ratio);
510 #endif
514 * adjust_frame_size:
516 * Adjust size of frame F. NEW_WIDTH and NEW_HEIGHT specify the new
517 * text size of F in pixels. A value of -1 means no change is requested
518 * for that direction (but the frame may still have to be resized to
519 * accommodate windows with their minimum sizes). This can either issue
520 * a request to resize the frame externally (via x_set_window_size), to
521 * resize the frame internally (via resize_frame_windows) or do nothing
522 * at all.
524 * The argument INHIBIT can assume the following values:
526 * 0 means to unconditionally call x_set_window_size even if sizes
527 * apparently do not change. Fx_create_frame uses this to pass the
528 * initial size to the window manager.
530 * 1 means to call x_set_window_size if the native frame size really
531 * changes. Fset_frame_size, Fset_frame_height, ... use this.
533 * 2 means to call x_set_window_size provided frame_inhibit_resize
534 * allows it. The menu and tool bar code use this ("3" won't work
535 * here in general because menu and tool bar are often not counted in
536 * the frame's text height).
538 * 3 means call x_set_window_size if window minimum sizes must be
539 * preserved or frame_inhibit_resize allows it. x_set_left_fringe,
540 * x_set_scroll_bar_width, x_new_font ... use (or should use) this.
542 * 4 means call x_set_window_size only if window minimum sizes must be
543 * preserved. x_set_right_divider_width, x_set_border_width and the
544 * code responsible for wrapping the tool bar use this.
546 * 5 means to never call x_set_window_size. change_frame_size uses
547 * this.
549 * Note that even when x_set_window_size is not called, individual
550 * windows may have to be resized (via `window--sanitize-window-sizes')
551 * in order to support minimum size constraints.
553 * PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the
554 * symbol of the parameter changed (like `menu-bar-lines', `font', ...).
555 * This is passed on to frame_inhibit_resize to let the latter decide on
556 * a case-by-case basis whether the frame may be resized externally.
558 void
559 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
560 bool pretend, Lisp_Object parameter)
562 int unit_width = FRAME_COLUMN_WIDTH (f);
563 int unit_height = FRAME_LINE_HEIGHT (f);
564 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
565 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
566 int old_cols = FRAME_COLS (f);
567 int old_lines = FRAME_LINES (f);
568 int new_pixel_width, new_pixel_height;
569 /* The following two values are calculated from the old frame pixel
570 sizes and any "new" settings for tool bar, menu bar and internal
571 borders. We do it this way to detect whether we have to call
572 x_set_window_size as consequence of the new settings. */
573 int windows_width = FRAME_WINDOWS_WIDTH (f);
574 int windows_height = FRAME_WINDOWS_HEIGHT (f);
575 int min_windows_width, min_windows_height;
576 /* These are a bit tedious, maybe we should use a macro. */
577 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
578 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
579 int old_windows_height
580 = (WINDOW_PIXEL_HEIGHT (r)
581 + ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
582 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
583 : 0));
584 int new_windows_width, new_windows_height;
585 int old_text_width = FRAME_TEXT_WIDTH (f);
586 int old_text_height = FRAME_TEXT_HEIGHT (f);
587 /* If a size is < 0 use the old value. */
588 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
589 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
590 int new_cols, new_lines;
591 bool inhibit_horizontal, inhibit_vertical;
592 Lisp_Object frame;
594 XSETFRAME (frame, f);
596 frame_size_history_add
597 (f, Qadjust_frame_size_1, new_text_width, new_text_height,
598 list2 (parameter, make_number (inhibit)));
600 /* The following two values are calculated from the old window body
601 sizes and any "new" settings for scroll bars, dividers, fringes and
602 margins (though the latter should have been processed already). */
603 min_windows_width
604 = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qt : Qnil, Qt);
605 min_windows_height
606 = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qt : Qnil, Qt);
608 if (inhibit >= 2 && inhibit <= 4)
609 /* When INHIBIT is in [2..4] inhibit if the "old" window sizes stay
610 within the limits and either resizing is inhibited or INHIBIT
611 equals 4. */
613 inhibit_horizontal = (windows_width >= min_windows_width
614 && (inhibit == 4
615 || frame_inhibit_resize (f, true, parameter)));
616 inhibit_vertical = (windows_height >= min_windows_height
617 && (inhibit == 4
618 || frame_inhibit_resize (f, false, parameter)));
620 else
621 /* Otherwise inhibit if INHIBIT equals 5. */
622 inhibit_horizontal = inhibit_vertical = inhibit == 5;
624 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
625 ? old_pixel_width
626 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
627 min_windows_width
628 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
629 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
630 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
631 new_cols = new_text_width / unit_width;
633 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
634 ? old_pixel_height
635 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
636 min_windows_height
637 + FRAME_TOP_MARGIN_HEIGHT (f)
638 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
639 new_windows_height = (new_pixel_height
640 - FRAME_TOP_MARGIN_HEIGHT (f)
641 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
642 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
643 new_lines = new_text_height / unit_height;
645 #ifdef HAVE_WINDOW_SYSTEM
646 if (FRAME_WINDOW_P (f)
647 && f->can_x_set_window_size
648 && ((!inhibit_horizontal
649 && (new_pixel_width != old_pixel_width
650 || inhibit == 0 || inhibit == 2))
651 || (!inhibit_vertical
652 && (new_pixel_height != old_pixel_height
653 || inhibit == 0 || inhibit == 2))))
654 /* We are either allowed to change the frame size or the minimum
655 sizes request such a change. Do not care for fixing minimum
656 sizes here, we do that eventually when we're called from
657 change_frame_size. */
659 /* Make sure we respect fullheight and fullwidth. */
660 if (inhibit_horizontal)
661 new_text_width = old_text_width;
662 else if (inhibit_vertical)
663 new_text_height = old_text_height;
665 frame_size_history_add
666 (f, Qadjust_frame_size_2, new_text_width, new_text_height,
667 list2 (inhibit_horizontal ? Qt : Qnil,
668 inhibit_vertical ? Qt : Qnil));
670 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
671 f->resized_p = true;
673 return;
675 #endif
677 if (new_text_width == old_text_width
678 && new_text_height == old_text_height
679 && new_windows_width == old_windows_width
680 && new_windows_height == old_windows_height
681 && new_pixel_width == old_pixel_width
682 && new_pixel_height == old_pixel_height
683 && new_cols == old_cols
684 && new_lines == old_lines)
685 /* No change. Sanitize window sizes and return. */
687 sanitize_window_sizes (Qt);
688 sanitize_window_sizes (Qnil);
690 return;
693 block_input ();
695 #ifdef MSDOS
696 /* We only can set screen dimensions to certain values supported by
697 our video hardware. Try to find the smallest size greater or
698 equal to the requested dimensions, while accounting for the fact
699 that the menu-bar lines are not counted in the frame height. */
700 int dos_new_lines = new_lines + FRAME_TOP_MARGIN (f);
701 dos_set_window_size (&dos_new_lines, &new_cols);
702 new_lines = dos_new_lines - FRAME_TOP_MARGIN (f);
703 #endif
705 if (new_windows_width != old_windows_width)
707 resize_frame_windows (f, new_windows_width, 1, 1);
709 /* MSDOS frames cannot PRETEND, as they change frame size by
710 manipulating video hardware. */
711 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
712 FrameCols (FRAME_TTY (f)) = new_cols;
714 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
715 if (WINDOWP (f->tool_bar_window))
717 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
718 XWINDOW (f->tool_bar_window)->total_cols
719 = new_windows_width / unit_width;
721 #endif
723 else if (new_cols != old_cols)
724 call2 (Qwindow__pixel_to_total, frame, Qt);
726 if (new_windows_height != old_windows_height
727 /* When the top margin has changed we have to recalculate the top
728 edges of all windows. No such calculation is necessary for the
729 left edges. */
730 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
732 resize_frame_windows (f, new_windows_height, 0, 1);
734 /* MSDOS frames cannot PRETEND, as they change frame size by
735 manipulating video hardware. */
736 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
737 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
739 else if (new_lines != old_lines)
740 call2 (Qwindow__pixel_to_total, frame, Qnil);
742 frame_size_history_add
743 (f, Qadjust_frame_size_3, new_text_width, new_text_height,
744 list4 (make_number (old_pixel_width), make_number (old_pixel_height),
745 make_number (new_pixel_width), make_number (new_pixel_height)));
747 /* Assign new sizes. */
748 FRAME_TEXT_WIDTH (f) = new_text_width;
749 FRAME_TEXT_HEIGHT (f) = new_text_height;
750 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
751 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
752 SET_FRAME_COLS (f, new_cols);
753 SET_FRAME_LINES (f, new_lines);
756 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
757 int text_area_x, text_area_y, text_area_width, text_area_height;
759 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
760 &text_area_height);
761 if (w->cursor.x >= text_area_x + text_area_width)
762 w->cursor.hpos = w->cursor.x = 0;
763 if (w->cursor.y >= text_area_y + text_area_height)
764 w->cursor.vpos = w->cursor.y = 0;
767 /* Sanitize window sizes. */
768 sanitize_window_sizes (Qt);
769 sanitize_window_sizes (Qnil);
771 adjust_frame_glyphs (f);
772 calculate_costs (f);
773 SET_FRAME_GARBAGED (f);
775 /* A frame was "resized" if one of its pixelsizes changed, even if its
776 X window wasn't resized at all. */
777 f->resized_p = (new_pixel_width != old_pixel_width
778 || new_pixel_height != old_pixel_height);
780 unblock_input ();
782 #ifdef HAVE_WINDOW_SYSTEM
784 /* Adjust size of F's child frames. */
785 Lisp_Object frames, frame1;
787 FOR_EACH_FRAME (frames, frame1)
788 if (FRAME_PARENT_FRAME (XFRAME (frame1)) == f)
789 keep_ratio (XFRAME (frame1), f, old_pixel_width, old_pixel_height,
790 new_pixel_width, new_pixel_height);
792 #endif
795 /* Allocate basically initialized frame. */
797 static struct frame *
798 allocate_frame (void)
800 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
803 struct frame *
804 make_frame (bool mini_p)
806 Lisp_Object frame;
807 struct frame *f;
808 struct window *rw, *mw UNINIT;
809 Lisp_Object root_window;
810 Lisp_Object mini_window;
812 f = allocate_frame ();
813 XSETFRAME (frame, f);
815 #ifdef USE_GTK
816 /* Initialize Lisp data. Note that allocate_frame initializes all
817 Lisp data to nil, so do it only for slots which should not be nil. */
818 fset_tool_bar_position (f, Qtop);
819 #endif
821 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
822 non-Lisp data, so do it only for slots which should not be zero.
823 To avoid subtle bugs and for the sake of readability, it's better to
824 initialize enum members explicitly even if their values are zero. */
825 f->wants_modeline = true;
826 f->redisplay = true;
827 f->garbaged = true;
828 f->can_x_set_window_size = false;
829 f->after_make_frame = false;
830 f->inhibit_horizontal_resize = false;
831 f->inhibit_vertical_resize = false;
832 f->tool_bar_redisplayed = false;
833 f->tool_bar_resized = false;
834 f->column_width = 1; /* !FRAME_WINDOW_P value. */
835 f->line_height = 1; /* !FRAME_WINDOW_P value. */
836 #ifdef HAVE_WINDOW_SYSTEM
837 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
838 f->horizontal_scroll_bars = false;
839 f->want_fullscreen = FULLSCREEN_NONE;
840 f->undecorated = false;
841 f->no_special_glyphs = false;
842 #ifndef HAVE_NTGUI
843 f->override_redirect = false;
844 #endif
845 f->skip_taskbar = false;
846 f->no_focus_on_map = false;
847 f->no_accept_focus = false;
848 f->z_group = z_group_none;
849 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
850 f->last_tool_bar_item = -1;
851 #endif
852 #ifdef NS_IMPL_COCOA
853 f->ns_appearance = ns_appearance_aqua;
854 f->ns_transparent_titlebar = false;
855 #endif
856 #endif
858 root_window = make_window ();
859 rw = XWINDOW (root_window);
860 if (mini_p)
862 mini_window = make_window ();
863 mw = XWINDOW (mini_window);
864 wset_next (rw, mini_window);
865 wset_prev (mw, root_window);
866 mw->mini = 1;
867 wset_frame (mw, frame);
868 fset_minibuffer_window (f, mini_window);
869 store_frame_param (f, Qminibuffer, Qt);
871 else
873 mini_window = Qnil;
874 wset_next (rw, Qnil);
875 fset_minibuffer_window (f, Qnil);
878 wset_frame (rw, frame);
880 /* 10 is arbitrary,
881 just so that there is "something there."
882 Correct size will be set up later with adjust_frame_size. */
884 SET_FRAME_COLS (f, 10);
885 SET_FRAME_LINES (f, 10);
886 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
887 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
889 rw->total_cols = 10;
890 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
891 rw->total_lines = mini_p ? 9 : 10;
892 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
894 if (mini_p)
896 mw->top_line = rw->total_lines;
897 mw->pixel_top = rw->pixel_height;
898 mw->total_cols = rw->total_cols;
899 mw->pixel_width = rw->pixel_width;
900 mw->total_lines = 1;
901 mw->pixel_height = FRAME_LINE_HEIGHT (f);
904 /* Choose a buffer for the frame's root window. */
906 Lisp_Object buf = Fcurrent_buffer ();
908 /* If current buffer is hidden, try to find another one. */
909 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
910 buf = other_buffer_safely (buf);
912 /* Use set_window_buffer, not Fset_window_buffer, and don't let
913 hooks be run by it. The reason is that the whole frame/window
914 arrangement is not yet fully initialized at this point. Windows
915 don't have the right size, glyph matrices aren't initialized
916 etc. Running Lisp functions at this point surely ends in a
917 SEGV. */
918 set_window_buffer (root_window, buf, 0, 0);
919 fset_buffer_list (f, list1 (buf));
922 if (mini_p)
924 set_window_buffer (mini_window,
925 (NILP (Vminibuffer_list)
926 ? get_minibuffer (0)
927 : Fcar (Vminibuffer_list)),
928 0, 0);
929 /* No horizontal scroll bars in minibuffers. */
930 wset_horizontal_scroll_bar (mw, Qnil);
933 fset_root_window (f, root_window);
934 fset_selected_window (f, root_window);
935 /* Make sure this window seems more recently used than
936 a newly-created, never-selected window. */
937 XWINDOW (f->selected_window)->use_time = ++window_select_count;
939 return f;
942 #ifdef HAVE_WINDOW_SYSTEM
943 /* Make a frame using a separate minibuffer window on another frame.
944 MINI_WINDOW is the minibuffer window to use. nil means use the
945 default (the global minibuffer). */
947 struct frame *
948 make_frame_without_minibuffer (Lisp_Object mini_window, KBOARD *kb,
949 Lisp_Object display)
951 struct frame *f;
953 if (!NILP (mini_window))
954 CHECK_LIVE_WINDOW (mini_window);
956 if (!NILP (mini_window)
957 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
958 error ("Frame and minibuffer must be on the same terminal");
960 /* Make a frame containing just a root window. */
961 f = make_frame (0);
963 if (NILP (mini_window))
965 /* Use default-minibuffer-frame if possible. */
966 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
967 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
969 Lisp_Object frame_dummy;
971 XSETFRAME (frame_dummy, f);
972 /* If there's no minibuffer frame to use, create one. */
973 kset_default_minibuffer_frame
974 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
977 mini_window
978 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
981 fset_minibuffer_window (f, mini_window);
982 store_frame_param (f, Qminibuffer, mini_window);
984 /* Make the chosen minibuffer window display the proper minibuffer,
985 unless it is already showing a minibuffer. */
986 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
987 /* Use set_window_buffer instead of Fset_window_buffer (see
988 discussion of bug#11984, bug#12025, bug#12026). */
989 set_window_buffer (mini_window,
990 (NILP (Vminibuffer_list)
991 ? get_minibuffer (0)
992 : Fcar (Vminibuffer_list)), 0, 0);
993 return f;
996 /* Make a frame containing only a minibuffer window. */
998 struct frame *
999 make_minibuffer_frame (void)
1001 /* First make a frame containing just a root window, no minibuffer. */
1003 register struct frame *f = make_frame (0);
1004 register Lisp_Object mini_window;
1005 register Lisp_Object frame;
1007 XSETFRAME (frame, f);
1009 f->auto_raise = 0;
1010 f->auto_lower = 0;
1011 f->no_split = 1;
1012 f->wants_modeline = 0;
1014 /* Now label the root window as also being the minibuffer.
1015 Avoid infinite looping on the window chain by marking next pointer
1016 as nil. */
1018 mini_window = f->root_window;
1019 fset_minibuffer_window (f, mini_window);
1020 store_frame_param (f, Qminibuffer, Qonly);
1021 XWINDOW (mini_window)->mini = 1;
1022 wset_next (XWINDOW (mini_window), Qnil);
1023 wset_prev (XWINDOW (mini_window), Qnil);
1024 wset_frame (XWINDOW (mini_window), frame);
1026 /* Put the proper buffer in that window. */
1028 /* Use set_window_buffer instead of Fset_window_buffer (see
1029 discussion of bug#11984, bug#12025, bug#12026). */
1030 set_window_buffer (mini_window,
1031 (NILP (Vminibuffer_list)
1032 ? get_minibuffer (0)
1033 : Fcar (Vminibuffer_list)), 0, 0);
1034 return f;
1036 #endif /* HAVE_WINDOW_SYSTEM */
1038 /* Construct a frame that refers to a terminal. */
1040 static printmax_t tty_frame_count;
1042 struct frame *
1043 make_initial_frame (void)
1045 struct frame *f;
1046 struct terminal *terminal;
1047 Lisp_Object frame;
1049 eassert (initial_kboard);
1051 /* The first call must initialize Vframe_list. */
1052 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
1053 Vframe_list = Qnil;
1055 terminal = init_initial_terminal ();
1057 f = make_frame (1);
1058 XSETFRAME (frame, f);
1060 Vframe_list = Fcons (frame, Vframe_list);
1062 tty_frame_count = 1;
1063 fset_name (f, build_pure_c_string ("F1"));
1065 SET_FRAME_VISIBLE (f, 1);
1067 f->output_method = terminal->type;
1068 f->terminal = terminal;
1069 f->terminal->reference_count++;
1070 f->output_data.nothing = 0;
1072 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
1073 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
1075 #ifdef HAVE_WINDOW_SYSTEM
1076 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
1077 f->horizontal_scroll_bars = false;
1078 #endif
1080 /* The default value of menu-bar-mode is t. */
1081 set_menu_bar_lines (f, make_number (1), Qnil);
1083 /* Allocate glyph matrices. */
1084 adjust_frame_glyphs (f);
1086 if (!noninteractive)
1087 init_frame_faces (f);
1089 last_nonminibuf_frame = f;
1091 f->can_x_set_window_size = true;
1092 f->after_make_frame = true;
1094 return f;
1098 static struct frame *
1099 make_terminal_frame (struct terminal *terminal)
1101 register struct frame *f;
1102 Lisp_Object frame;
1103 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
1105 if (!terminal->name)
1106 error ("Terminal is not live, can't create new frames on it");
1108 f = make_frame (1);
1110 XSETFRAME (frame, f);
1111 Vframe_list = Fcons (frame, Vframe_list);
1113 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
1115 SET_FRAME_VISIBLE (f, 1);
1117 f->terminal = terminal;
1118 f->terminal->reference_count++;
1119 #ifdef MSDOS
1120 f->output_data.tty->display_info = &the_only_display_info;
1121 if (!inhibit_window_system
1122 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
1123 || XFRAME (selected_frame)->output_method == output_msdos_raw))
1124 f->output_method = output_msdos_raw;
1125 else
1126 f->output_method = output_termcap;
1127 #else /* not MSDOS */
1128 f->output_method = output_termcap;
1129 create_tty_output (f);
1130 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
1131 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
1132 #endif /* not MSDOS */
1134 #ifdef HAVE_WINDOW_SYSTEM
1135 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
1136 f->horizontal_scroll_bars = false;
1137 #endif
1139 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
1140 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
1141 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
1142 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
1144 /* Set the top frame to the newly created frame. */
1145 if (FRAMEP (FRAME_TTY (f)->top_frame)
1146 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
1147 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
1149 FRAME_TTY (f)->top_frame = frame;
1151 if (!noninteractive)
1152 init_frame_faces (f);
1154 return f;
1157 /* Get a suitable value for frame parameter PARAMETER for a newly
1158 created frame, based on (1) the user-supplied frame parameter
1159 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
1161 static Lisp_Object
1162 get_future_frame_param (Lisp_Object parameter,
1163 Lisp_Object supplied_parms,
1164 char *current_value)
1166 Lisp_Object result;
1168 result = Fassq (parameter, supplied_parms);
1169 if (NILP (result))
1170 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
1171 if (NILP (result) && current_value != NULL)
1172 result = build_string (current_value);
1173 if (!NILP (result) && !STRINGP (result))
1174 result = XCDR (result);
1175 if (NILP (result) || !STRINGP (result))
1176 result = Qnil;
1178 return result;
1181 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
1182 1, 1, 0,
1183 doc: /* Create an additional terminal frame, possibly on another terminal.
1184 This function takes one argument, an alist specifying frame parameters.
1186 You can create multiple frames on a single text terminal, but only one
1187 of them (the selected terminal frame) is actually displayed.
1189 In practice, generally you don't need to specify any parameters,
1190 except when you want to create a new frame on another terminal.
1191 In that case, the `tty' parameter specifies the device file to open,
1192 and the `tty-type' parameter specifies the terminal type. Example:
1194 (make-terminal-frame \\='((tty . "/dev/pts/5") (tty-type . "xterm")))
1196 Note that changing the size of one terminal frame automatically
1197 affects all frames on the same terminal device. */)
1198 (Lisp_Object parms)
1200 struct frame *f;
1201 struct terminal *t = NULL;
1202 Lisp_Object frame, tem;
1203 struct frame *sf = SELECTED_FRAME ();
1205 #ifdef MSDOS
1206 if (sf->output_method != output_msdos_raw
1207 && sf->output_method != output_termcap)
1208 emacs_abort ();
1209 #else /* not MSDOS */
1211 #ifdef WINDOWSNT /* This should work now! */
1212 if (sf->output_method != output_termcap)
1213 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
1214 #endif
1215 #endif /* not MSDOS */
1218 Lisp_Object terminal;
1220 terminal = Fassq (Qterminal, parms);
1221 if (CONSP (terminal))
1223 terminal = XCDR (terminal);
1224 t = decode_live_terminal (terminal);
1226 #ifdef MSDOS
1227 if (t && t != the_only_display_info.terminal)
1228 /* msdos.c assumes a single tty_display_info object. */
1229 error ("Multiple terminals are not supported on this platform");
1230 if (!t)
1231 t = the_only_display_info.terminal;
1232 #endif
1235 if (!t)
1237 char *name = 0, *type = 0;
1238 Lisp_Object tty, tty_type;
1239 USE_SAFE_ALLOCA;
1241 tty = get_future_frame_param
1242 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1243 ? FRAME_TTY (XFRAME (selected_frame))->name
1244 : NULL));
1245 if (!NILP (tty))
1246 SAFE_ALLOCA_STRING (name, tty);
1248 tty_type = get_future_frame_param
1249 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1250 ? FRAME_TTY (XFRAME (selected_frame))->type
1251 : NULL));
1252 if (!NILP (tty_type))
1253 SAFE_ALLOCA_STRING (type, tty_type);
1255 t = init_tty (name, type, 0); /* Errors are not fatal. */
1256 SAFE_FREE ();
1259 f = make_terminal_frame (t);
1262 int width, height;
1263 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1264 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f),
1265 5, 0, Qterminal_frame);
1268 adjust_frame_glyphs (f);
1269 calculate_costs (f);
1270 XSETFRAME (frame, f);
1272 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1273 store_in_alist (&parms, Qtty,
1274 (t->display_info.tty->name
1275 ? build_string (t->display_info.tty->name)
1276 : Qnil));
1277 /* On terminal frames the `minibuffer' frame parameter is always
1278 virtually t. Avoid that a different value in parms causes
1279 complaints, see Bug#24758. */
1280 store_in_alist (&parms, Qminibuffer, Qt);
1281 Fmodify_frame_parameters (frame, parms);
1283 /* Make the frame face alist be frame-specific, so that each
1284 frame could change its face definitions independently. */
1285 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1286 /* Simple Fcopy_alist isn't enough, because we need the contents of
1287 the vectors which are the CDRs of associations in face_alist to
1288 be copied as well. */
1289 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1290 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1292 f->can_x_set_window_size = true;
1293 f->after_make_frame = true;
1295 return frame;
1299 /* Perform the switch to frame FRAME.
1301 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1302 FRAME1 as frame.
1304 If TRACK is non-zero and the frame that currently has the focus
1305 redirects its focus to the selected frame, redirect that focused
1306 frame's focus to FRAME instead.
1308 FOR_DELETION non-zero means that the selected frame is being
1309 deleted, which includes the possibility that the frame's terminal
1310 is dead.
1312 The value of NORECORD is passed as argument to Fselect_window. */
1314 Lisp_Object
1315 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1317 struct frame *sf = SELECTED_FRAME (), *f;
1319 /* If FRAME is a switch-frame event, extract the frame we should
1320 switch to. */
1321 if (CONSP (frame)
1322 && EQ (XCAR (frame), Qswitch_frame)
1323 && CONSP (XCDR (frame)))
1324 frame = XCAR (XCDR (frame));
1326 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1327 a switch-frame event to arrive after a frame is no longer live,
1328 especially when deleting the initial frame during startup. */
1329 CHECK_FRAME (frame);
1330 f = XFRAME (frame);
1331 if (!FRAME_LIVE_P (f))
1332 return Qnil;
1333 else if (f == sf)
1334 return frame;
1336 /* If a frame's focus has been redirected toward the currently
1337 selected frame, we should change the redirection to point to the
1338 newly selected frame. This means that if the focus is redirected
1339 from a minibufferless frame to a surrogate minibuffer frame, we
1340 can use `other-window' to switch between all the frames using
1341 that minibuffer frame, and the focus redirection will follow us
1342 around. */
1343 #if 0
1344 /* This is too greedy; it causes inappropriate focus redirection
1345 that's hard to get rid of. */
1346 if (track)
1348 Lisp_Object tail;
1350 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1352 Lisp_Object focus;
1354 if (!FRAMEP (XCAR (tail)))
1355 emacs_abort ();
1357 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1359 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1360 Fredirect_frame_focus (XCAR (tail), frame);
1363 #else /* ! 0 */
1364 /* Instead, apply it only to the frame we're pointing to. */
1365 #ifdef HAVE_WINDOW_SYSTEM
1366 if (track && FRAME_WINDOW_P (f))
1368 Lisp_Object focus, xfocus;
1370 xfocus = x_get_focus_frame (f);
1371 if (FRAMEP (xfocus))
1373 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1374 if ((FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1375 /* Redirect frame focus also when FRAME has its minibuffer
1376 window on the selected frame (see Bug#24500). */
1377 || (NILP (focus)
1378 && EQ (FRAME_MINIBUF_WINDOW (f), sf->selected_window)))
1379 Fredirect_frame_focus (xfocus, frame);
1382 #endif /* HAVE_X_WINDOWS */
1383 #endif /* ! 0 */
1385 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1386 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1388 if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
1390 struct tty_display_info *tty = FRAME_TTY (f);
1391 Lisp_Object top_frame = tty->top_frame;
1393 /* Don't mark the frame garbaged and/or obscured if we are
1394 switching to the frame that is already the top frame of that
1395 TTY. */
1396 if (!EQ (frame, top_frame))
1398 if (FRAMEP (top_frame))
1399 /* Mark previously displayed frame as now obscured. */
1400 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1401 SET_FRAME_VISIBLE (f, 1);
1402 /* If the new TTY frame changed dimensions, we need to
1403 resync term.c's idea of the frame size with the new
1404 frame's data. */
1405 if (FRAME_COLS (f) != FrameCols (tty))
1406 FrameCols (tty) = FRAME_COLS (f);
1407 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1408 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1410 tty->top_frame = frame;
1413 selected_frame = frame;
1414 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1415 last_nonminibuf_frame = XFRAME (selected_frame);
1417 Fselect_window (f->selected_window, norecord);
1419 /* We want to make sure that the next event generates a frame-switch
1420 event to the appropriate frame. This seems kludgy to me, but
1421 before you take it out, make sure that evaluating something like
1422 (select-window (frame-root-window (new-frame))) doesn't end up
1423 with your typing being interpreted in the new frame instead of
1424 the one you're actually typing in. */
1425 #ifdef HAVE_WINDOW_SYSTEM
1426 if (!frame_ancestor_p (f, sf))
1427 #endif
1428 internal_last_event_frame = Qnil;
1430 return frame;
1433 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1434 doc: /* Select FRAME.
1435 Subsequent editing commands apply to its selected window.
1436 Optional argument NORECORD means to neither change the order of
1437 recently selected windows nor the buffer list.
1439 The selection of FRAME lasts until the next time the user does
1440 something to select a different frame, or until the next time
1441 this function is called. If you are using a window system, the
1442 previously selected frame may be restored as the selected frame
1443 when returning to the command loop, because it still may have
1444 the window system's input focus. On a text terminal, the next
1445 redisplay will display FRAME.
1447 This function returns FRAME, or nil if FRAME has been deleted. */)
1448 (Lisp_Object frame, Lisp_Object norecord)
1450 return do_switch_frame (frame, 1, 0, norecord);
1453 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1454 doc: /* Handle a switch-frame event EVENT.
1455 Switch-frame events are usually bound to this function.
1456 A switch-frame event tells Emacs that the window manager has requested
1457 that the user's events be directed to the frame mentioned in the event.
1458 This function selects the selected window of the frame of EVENT.
1460 If EVENT is frame object, handle it as if it were a switch-frame event
1461 to that frame. */)
1462 (Lisp_Object event)
1464 Lisp_Object value;
1466 /* Preserve prefix arg that the command loop just cleared. */
1467 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1468 run_hook (Qmouse_leave_buffer_hook);
1469 /* `switch-frame' implies a focus in. */
1470 value = do_switch_frame (event, 0, 0, Qnil);
1471 call1 (intern ("handle-focus-in"), event);
1472 return value;
1475 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1476 doc: /* Return the frame that is now selected. */)
1477 (void)
1479 return selected_frame;
1482 DEFUN ("frame-list", Fframe_list, Sframe_list,
1483 0, 0, 0,
1484 doc: /* Return a list of all live frames. */)
1485 (void)
1487 Lisp_Object frames;
1488 frames = Fcopy_sequence (Vframe_list);
1489 #ifdef HAVE_WINDOW_SYSTEM
1490 if (FRAMEP (tip_frame)
1491 #ifdef USE_GTK
1492 && !NILP (Fframe_parameter (tip_frame, Qtooltip))
1493 #endif
1495 frames = Fdelq (tip_frame, frames);
1496 #endif
1497 return frames;
1500 DEFUN ("frame-parent", Fframe_parent, Sframe_parent,
1501 0, 1, 0,
1502 doc: /* Return the parent frame of FRAME.
1503 The parent frame of FRAME is the Emacs frame whose window-system window
1504 is the parent window of FRAME's window-system window. When such a frame
1505 exists, FRAME is considered a child frame of that frame.
1507 Return nil if FRAME has no parent frame. This means that FRAME's
1508 window-system window is either a "top-level" window (a window whose
1509 parent window is the window-system's root window) or an embedded window
1510 \(a window whose parent window is owned by some other application). */)
1511 (Lisp_Object frame)
1513 struct frame *f = decode_live_frame (frame);
1514 struct frame *p = FRAME_PARENT_FRAME (f);
1515 Lisp_Object parent;
1517 /* Can't return f->parent_frame directly since it might not be defined
1518 for this platform. */
1519 if (p)
1521 XSETFRAME (parent, p);
1523 return parent;
1525 else
1526 return Qnil;
1529 #ifdef HAVE_WINDOW_SYSTEM
1530 bool
1531 frame_ancestor_p (struct frame *af, struct frame *df)
1533 struct frame *pf = FRAME_PARENT_FRAME (df);
1535 while (pf)
1537 if (pf == af)
1538 return true;
1539 else
1540 pf = FRAME_PARENT_FRAME (pf);
1543 return false;
1545 #endif
1547 DEFUN ("frame-ancestor-p", Fframe_ancestor_p, Sframe_ancestor_p,
1548 2, 2, 0,
1549 doc: /* Return non-nil if ANCESTOR is an ancestor of DESCENDANT.
1550 ANCESTOR is an ancestor of DESCENDANT when it is either DESCENDANT's
1551 parent frame or it is an ancestor of DESCENDANT's parent frame. Both,
1552 ANCESTOR and DESCENDANT must be live frames and default to the selected
1553 frame. */)
1554 (Lisp_Object ancestor, Lisp_Object descendant)
1556 #ifdef HAVE_WINDOW_SYSTEM
1557 struct frame *af = decode_live_frame (ancestor);
1558 struct frame *df = decode_live_frame (descendant);
1560 return frame_ancestor_p (af, df) ? Qt : Qnil;
1561 #else
1562 return Qnil;
1563 #endif
1566 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1567 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1568 If MINIBUF is nil, do not consider minibuffer-only candidate.
1569 If MINIBUF is `visible', do not consider an invisible candidate.
1570 If MINIBUF is a window, consider only its own frame and candidate now
1571 using that window as the minibuffer.
1572 If MINIBUF is 0, consider candidate if it is visible or iconified.
1573 Otherwise consider any candidate and return nil if CANDIDATE is not
1574 acceptable. */
1576 static Lisp_Object
1577 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1579 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1581 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1582 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1583 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1584 && FRAME_TTY (c) == FRAME_TTY (f)))
1586 if (!NILP (get_frame_param (c, Qno_other_frame)))
1587 return Qnil;
1588 else if (NILP (minibuf))
1590 if (!FRAME_MINIBUF_ONLY_P (c))
1591 return candidate;
1593 else if (EQ (minibuf, Qvisible))
1595 if (FRAME_VISIBLE_P (c))
1596 return candidate;
1598 else if (WINDOWP (minibuf))
1600 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1601 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1602 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1603 FRAME_FOCUS_FRAME (c)))
1604 return candidate;
1606 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1608 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1609 return candidate;
1611 else
1612 return candidate;
1614 return Qnil;
1617 /* Return the next frame in the frame list after FRAME. */
1619 static Lisp_Object
1620 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1622 Lisp_Object f, tail;
1623 int passed = 0;
1625 eassume (CONSP (Vframe_list));
1627 while (passed < 2)
1628 FOR_EACH_FRAME (tail, f)
1630 if (passed)
1632 f = candidate_frame (f, frame, minibuf);
1633 if (!NILP (f))
1634 return f;
1636 if (EQ (frame, f))
1637 passed++;
1639 return frame;
1642 /* Return the previous frame in the frame list before FRAME. */
1644 static Lisp_Object
1645 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1647 Lisp_Object f, tail, prev = Qnil;
1649 eassume (CONSP (Vframe_list));
1651 FOR_EACH_FRAME (tail, f)
1653 if (EQ (frame, f) && !NILP (prev))
1654 return prev;
1655 f = candidate_frame (f, frame, minibuf);
1656 if (!NILP (f))
1657 prev = f;
1660 /* We've scanned the entire list. */
1661 if (NILP (prev))
1662 /* We went through the whole frame list without finding a single
1663 acceptable frame. Return the original frame. */
1664 return frame;
1665 else
1666 /* There were no acceptable frames in the list before FRAME; otherwise,
1667 we would have returned directly from the loop. Since PREV is the last
1668 acceptable frame in the list, return it. */
1669 return prev;
1673 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1674 doc: /* Return the next frame in the frame list after FRAME.
1675 It considers only frames on the same terminal as FRAME.
1676 By default, skip minibuffer-only frames.
1677 If omitted, FRAME defaults to the selected frame.
1678 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1679 If MINIFRAME is a window, include only its own frame
1680 and any frame now using that window as the minibuffer.
1681 If MINIFRAME is `visible', include all visible frames.
1682 If MINIFRAME is 0, include all visible and iconified frames.
1683 Otherwise, include all frames. */)
1684 (Lisp_Object frame, Lisp_Object miniframe)
1686 if (NILP (frame))
1687 frame = selected_frame;
1688 CHECK_LIVE_FRAME (frame);
1689 return next_frame (frame, miniframe);
1692 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1693 doc: /* Return the previous frame in the frame list before FRAME.
1694 It considers only frames on the same terminal as FRAME.
1695 By default, skip minibuffer-only frames.
1696 If omitted, FRAME defaults to the selected frame.
1697 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1698 If MINIFRAME is a window, include only its own frame
1699 and any frame now using that window as the minibuffer.
1700 If MINIFRAME is `visible', include all visible frames.
1701 If MINIFRAME is 0, include all visible and iconified frames.
1702 Otherwise, include all frames. */)
1703 (Lisp_Object frame, Lisp_Object miniframe)
1705 if (NILP (frame))
1706 frame = selected_frame;
1707 CHECK_LIVE_FRAME (frame);
1708 return prev_frame (frame, miniframe);
1711 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1712 Slast_nonminibuf_frame, 0, 0, 0,
1713 doc: /* Return last non-minibuffer frame selected. */)
1714 (void)
1716 Lisp_Object frame = Qnil;
1718 if (last_nonminibuf_frame)
1719 XSETFRAME (frame, last_nonminibuf_frame);
1721 return frame;
1725 * other_frames:
1727 * Return true if there exists at least one visible or iconified frame
1728 * but F. Return false otherwise.
1730 * INVISIBLE true means we are called from make_frame_invisible where
1731 * such a frame must be visible or iconified. INVISIBLE nil means we
1732 * are called from delete_frame. In that case FORCE true means that the
1733 * visibility status of such a frame can be ignored.
1735 * If F is the terminal frame and we are using X, return true if at
1736 * least one X frame exists.
1738 static bool
1739 other_frames (struct frame *f, bool invisible, bool force)
1741 Lisp_Object frames, frame, frame1;
1742 struct frame *f1;
1743 Lisp_Object minibuffer_window = FRAME_MINIBUF_WINDOW (f);
1745 XSETFRAME (frame, f);
1746 if (WINDOWP (minibuffer_window)
1747 && !EQ (frame, WINDOW_FRAME (XWINDOW (minibuffer_window))))
1748 minibuffer_window = Qnil;
1750 FOR_EACH_FRAME (frames, frame1)
1752 f1 = XFRAME (frame1);
1753 if (f != f1)
1755 /* Verify that we can still talk to the frame's X window, and
1756 note any recent change in visibility. */
1757 #ifdef HAVE_X_WINDOWS
1758 if (FRAME_WINDOW_P (f1))
1759 x_sync (f1);
1760 #endif
1761 if (NILP (Fframe_parameter (frame1, Qtooltip))
1762 /* Tooltips and child frames count neither for
1763 invisibility nor for deletions. */
1764 && !FRAME_PARENT_FRAME (f1)
1765 /* Frames with a non-nil `delete-before' parameter don't
1766 count for deletions. */
1767 && (invisible || NILP (get_frame_param (f1, Qdelete_before)))
1768 /* For invisibility and normal deletions, at least one
1769 visible or iconified frame must remain (Bug#26682). */
1770 && (FRAME_VISIBLE_P (f1) || FRAME_ICONIFIED_P (f1)
1771 || (!invisible
1772 && (force
1773 /* Allow deleting the terminal frame when at
1774 least one X frame exists. */
1775 || (FRAME_WINDOW_P (f1) && !FRAME_WINDOW_P (f))))))
1776 return true;
1780 return false;
1783 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1784 window. Preferably use the selected frame's minibuffer window
1785 instead. If the selected frame doesn't have one, get some other
1786 frame's minibuffer window. SELECT non-zero means select the new
1787 minibuffer window. */
1788 static void
1789 check_minibuf_window (Lisp_Object frame, int select)
1791 struct frame *f = decode_live_frame (frame);
1793 XSETFRAME (frame, f);
1795 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1797 Lisp_Object frames, this, window = make_number (0);
1799 if (!EQ (frame, selected_frame)
1800 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1801 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1802 else
1803 FOR_EACH_FRAME (frames, this)
1805 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1807 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1808 break;
1812 /* Don't abort if no window was found (Bug#15247). */
1813 if (WINDOWP (window))
1815 /* Use set_window_buffer instead of Fset_window_buffer (see
1816 discussion of bug#11984, bug#12025, bug#12026). */
1817 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1818 minibuf_window = window;
1820 /* SELECT non-zero usually means that FRAME's minibuffer
1821 window was selected; select the new one. */
1822 if (select)
1823 Fselect_window (minibuf_window, Qnil);
1830 * delete_frame:
1832 * Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1833 * unconditionally. x_connection_closed and delete_terminal use this.
1834 * Any other value of FORCE implements the semantics described for
1835 * Fdelete_frame. */
1836 Lisp_Object
1837 delete_frame (Lisp_Object frame, Lisp_Object force)
1839 struct frame *f = decode_any_frame (frame);
1840 struct frame *sf;
1841 struct kboard *kb;
1842 Lisp_Object frames, frame1;
1843 int minibuffer_selected, is_tooltip_frame;
1844 bool nochild = !FRAME_PARENT_FRAME (f);
1846 if (!FRAME_LIVE_P (f))
1847 return Qnil;
1848 else if (!EQ (force, Qnoelisp) && !other_frames (f, false, !NILP (force)))
1850 if (NILP (force))
1851 error ("Attempt to delete the sole visible or iconified frame");
1852 else
1853 error ("Attempt to delete the only frame");
1856 XSETFRAME (frame, f);
1858 /* Softly delete all frames with this frame as their parent frame or
1859 as their `delete-before' frame parameter value. */
1860 FOR_EACH_FRAME (frames, frame1)
1861 if (FRAME_PARENT_FRAME (XFRAME (frame1)) == f
1862 /* Process `delete-before' parameter iff FRAME is not a child
1863 frame. This avoids that we enter an infinite chain of mixed
1864 dependencies. */
1865 || (nochild
1866 && EQ (get_frame_param (XFRAME (frame1), Qdelete_before), frame)))
1867 delete_frame (frame1, Qnil);
1869 /* Does this frame have a minibuffer, and is it the surrogate
1870 minibuffer for any other frame? */
1871 if (FRAME_HAS_MINIBUF_P (f))
1873 FOR_EACH_FRAME (frames, frame1)
1875 Lisp_Object fminiw;
1877 if (EQ (frame1, frame))
1878 continue;
1880 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (frame1));
1882 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1884 /* If we MUST delete this frame, delete the other first.
1885 But do this only if FORCE equals `noelisp'. */
1886 if (EQ (force, Qnoelisp))
1887 delete_frame (frame1, Qnoelisp);
1888 else
1889 error ("Attempt to delete a surrogate minibuffer frame");
1894 is_tooltip_frame = !NILP (Fframe_parameter (frame, Qtooltip));
1896 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1897 frame is a tooltip. FORCE is set to `noelisp' when handling
1898 a disconnect from the terminal, so we don't dare call Lisp
1899 code. */
1900 if (NILP (Vrun_hooks) || is_tooltip_frame)
1902 else if (EQ (force, Qnoelisp))
1903 pending_funcalls
1904 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1905 pending_funcalls);
1906 else
1908 #ifdef HAVE_X_WINDOWS
1909 /* Also, save clipboard to the clipboard manager. */
1910 x_clipboard_manager_save_frame (frame);
1911 #endif
1913 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1916 /* delete_frame_functions may have deleted any frame, including this
1917 one. */
1918 if (!FRAME_LIVE_P (f))
1919 return Qnil;
1920 else if (!EQ (force, Qnoelisp) && !other_frames (f, false, !NILP (force)))
1922 if (NILP (force))
1923 error ("Attempt to delete the sole visible or iconified frame");
1924 else
1925 error ("Attempt to delete the only frame");
1928 /* At this point, we are committed to deleting the frame.
1929 There is no more chance for errors to prevent it. */
1930 minibuffer_selected = EQ (minibuf_window, selected_window);
1931 sf = SELECTED_FRAME ();
1932 /* Don't let the frame remain selected. */
1933 if (f == sf)
1935 Lisp_Object tail;
1936 eassume (CONSP (Vframe_list));
1938 /* Look for another visible frame on the same terminal.
1939 Do not call next_frame here because it may loop forever.
1940 See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1941 FOR_EACH_FRAME (tail, frame1)
1942 if (!EQ (frame, frame1)
1943 && NILP (Fframe_parameter (frame1, Qtooltip))
1944 && (FRAME_TERMINAL (XFRAME (frame))
1945 == FRAME_TERMINAL (XFRAME (frame1)))
1946 && FRAME_VISIBLE_P (XFRAME (frame1)))
1947 break;
1949 /* If there is none, find *some* other frame. */
1950 if (NILP (frame1) || EQ (frame1, frame))
1952 FOR_EACH_FRAME (tail, frame1)
1954 if (!EQ (frame, frame1)
1955 && FRAME_LIVE_P (XFRAME (frame1))
1956 && NILP (Fframe_parameter (frame1, Qtooltip)))
1958 /* Do not change a text terminal's top-frame. */
1959 struct frame *f1 = XFRAME (frame1);
1960 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1962 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1963 if (!EQ (top_frame, frame))
1964 frame1 = top_frame;
1966 break;
1970 #ifdef NS_IMPL_COCOA
1971 else
1972 /* Under NS, there is no system mechanism for choosing a new
1973 window to get focus -- it is left to application code.
1974 So the portion of THIS application interfacing with NS
1975 needs to know about it. We call Fraise_frame, but the
1976 purpose is really to transfer focus. */
1977 Fraise_frame (frame1);
1978 #endif
1980 do_switch_frame (frame1, 0, 1, Qnil);
1981 sf = SELECTED_FRAME ();
1984 /* Don't allow minibuf_window to remain on a deleted frame. */
1985 check_minibuf_window (frame, minibuffer_selected);
1987 /* Don't let echo_area_window to remain on a deleted frame. */
1988 if (EQ (f->minibuffer_window, echo_area_window))
1989 echo_area_window = sf->minibuffer_window;
1991 /* Clear any X selections for this frame. */
1992 #ifdef HAVE_X_WINDOWS
1993 if (FRAME_X_P (f))
1994 x_clear_frame_selections (f);
1995 #endif
1997 /* Free glyphs.
1998 This function must be called before the window tree of the
1999 frame is deleted because windows contain dynamically allocated
2000 memory. */
2001 free_glyphs (f);
2003 #ifdef HAVE_WINDOW_SYSTEM
2004 /* Give chance to each font driver to free a frame specific data. */
2005 font_update_drivers (f, Qnil);
2006 #endif
2008 /* Mark all the windows that used to be on FRAME as deleted, and then
2009 remove the reference to them. */
2010 delete_all_child_windows (f->root_window);
2011 fset_root_window (f, Qnil);
2013 Vframe_list = Fdelq (frame, Vframe_list);
2014 SET_FRAME_VISIBLE (f, 0);
2016 /* Allow the vector of menu bar contents to be freed in the next
2017 garbage collection. The frame object itself may not be garbage
2018 collected until much later, because recent_keys and other data
2019 structures can still refer to it. */
2020 fset_menu_bar_vector (f, Qnil);
2022 /* If FRAME's buffer lists contains killed
2023 buffers, this helps GC to reclaim them. */
2024 fset_buffer_list (f, Qnil);
2025 fset_buried_buffer_list (f, Qnil);
2027 free_font_driver_list (f);
2028 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2029 xfree (f->namebuf);
2030 #endif
2031 xfree (f->decode_mode_spec_buffer);
2032 xfree (FRAME_INSERT_COST (f));
2033 xfree (FRAME_DELETEN_COST (f));
2034 xfree (FRAME_INSERTN_COST (f));
2035 xfree (FRAME_DELETE_COST (f));
2037 /* Since some events are handled at the interrupt level, we may get
2038 an event for f at any time; if we zero out the frame's terminal
2039 now, then we may trip up the event-handling code. Instead, we'll
2040 promise that the terminal of the frame must be valid until we
2041 have called the window-system-dependent frame destruction
2042 routine. */
2044 struct terminal *terminal;
2045 block_input ();
2046 if (FRAME_TERMINAL (f)->delete_frame_hook)
2047 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
2048 terminal = FRAME_TERMINAL (f);
2049 f->output_data.nothing = 0;
2050 f->terminal = 0; /* Now the frame is dead. */
2051 unblock_input ();
2053 /* If needed, delete the terminal that this frame was on.
2054 (This must be done after the frame is killed.) */
2055 terminal->reference_count--;
2056 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
2057 /* FIXME: Deleting the terminal crashes emacs because of a GTK
2058 bug.
2059 https://lists.gnu.org/r/emacs-devel/2011-10/msg00363.html */
2061 /* Since a similar behavior was observed on the Lucid and Motif
2062 builds (see Bug#5802, Bug#21509, Bug#23499, Bug#27816), we now
2063 don't delete the terminal for these builds either. */
2064 if (terminal->reference_count == 0 && terminal->type == output_x_window)
2065 terminal->reference_count = 1;
2066 #endif /* USE_X_TOOLKIT || USE_GTK */
2067 if (terminal->reference_count == 0)
2069 Lisp_Object tmp;
2070 XSETTERMINAL (tmp, terminal);
2072 kb = NULL;
2073 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
2075 else
2076 kb = terminal->kboard;
2079 /* If we've deleted the last_nonminibuf_frame, then try to find
2080 another one. */
2081 if (f == last_nonminibuf_frame)
2083 last_nonminibuf_frame = 0;
2085 FOR_EACH_FRAME (frames, frame1)
2087 struct frame *f1 = XFRAME (frame1);
2089 if (!FRAME_MINIBUF_ONLY_P (f1))
2091 last_nonminibuf_frame = f1;
2092 break;
2097 /* If there's no other frame on the same kboard, get out of
2098 single-kboard state if we're in it for this kboard. */
2099 if (kb != NULL)
2101 /* Some frame we found on the same kboard, or nil if there are none. */
2102 Lisp_Object frame_on_same_kboard = Qnil;
2104 FOR_EACH_FRAME (frames, frame1)
2105 if (kb == FRAME_KBOARD (XFRAME (frame1)))
2106 frame_on_same_kboard = frame1;
2108 if (NILP (frame_on_same_kboard))
2109 not_single_kboard_state (kb);
2113 /* If we've deleted this keyboard's default_minibuffer_frame, try to
2114 find another one. Prefer minibuffer-only frames, but also notice
2115 frames with other windows. */
2116 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
2118 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
2119 Lisp_Object frame_with_minibuf = Qnil;
2120 /* Some frame we found on the same kboard, or nil if there are none. */
2121 Lisp_Object frame_on_same_kboard = Qnil;
2123 FOR_EACH_FRAME (frames, frame1)
2125 struct frame *f1 = XFRAME (frame1);
2127 /* Consider only frames on the same kboard
2128 and only those with minibuffers. */
2129 if (kb == FRAME_KBOARD (f1)
2130 && FRAME_HAS_MINIBUF_P (f1))
2132 frame_with_minibuf = frame1;
2133 if (FRAME_MINIBUF_ONLY_P (f1))
2134 break;
2137 if (kb == FRAME_KBOARD (f1))
2138 frame_on_same_kboard = frame1;
2141 if (!NILP (frame_on_same_kboard))
2143 /* We know that there must be some frame with a minibuffer out
2144 there. If this were not true, all of the frames present
2145 would have to be minibufferless, which implies that at some
2146 point their minibuffer frames must have been deleted, but
2147 that is prohibited at the top; you can't delete surrogate
2148 minibuffer frames. */
2149 if (NILP (frame_with_minibuf))
2150 emacs_abort ();
2152 kset_default_minibuffer_frame (kb, frame_with_minibuf);
2154 else
2155 /* No frames left on this kboard--say no minibuffer either. */
2156 kset_default_minibuffer_frame (kb, Qnil);
2159 /* Cause frame titles to update--necessary if we now have just one frame. */
2160 if (!is_tooltip_frame)
2161 update_mode_lines = 15;
2163 return Qnil;
2166 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
2167 doc: /* Delete FRAME, permanently eliminating it from use.
2168 FRAME must be a live frame and defaults to the selected one.
2170 A frame may not be deleted if its minibuffer serves as surrogate
2171 minibuffer for another frame. Normally, you may not delete a frame if
2172 all other frames are invisible, but if the second optional argument
2173 FORCE is non-nil, you may do so.
2175 This function runs `delete-frame-functions' before actually
2176 deleting the frame, unless the frame is a tooltip.
2177 The functions are run with one argument, the frame to be deleted. */)
2178 (Lisp_Object frame, Lisp_Object force)
2180 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
2183 #ifdef HAVE_WINDOW_SYSTEM
2185 * frame_internal_border_part:
2187 * Return part of internal border the coordinates X and Y relative to
2188 * frame F are on. Return nil if the coordinates are not on the
2189 * internal border of F.
2191 * Return one of INTERNAL_BORDER_LEFT_EDGE, INTERNAL_BORDER_TOP_EDGE,
2192 * INTERNAL_BORDER_RIGHT_EDGE or INTERNAL_BORDER_BOTTOM_EDGE when the
2193 * mouse cursor is on the corresponding border with an offset of at
2194 * least one canonical character height from that border's edges.
2196 * If no border part could be found this way, return one of
2197 * INTERNAL_BORDER_TOP_LEFT_CORNER, INTERNAL_BORDER_TOP_RIGHT_CORNER,
2198 * INTERNAL_BORDER_BOTTOM_LEFT_CORNER or
2199 * INTERNAL_BORDER_BOTTOM_RIGHT_CORNER to indicate that the mouse is in
2200 * one of the corresponding corners. This means that for very small
2201 * frames an `edge' return value is preferred.
2203 enum internal_border_part
2204 frame_internal_border_part (struct frame *f, int x, int y)
2206 int border = FRAME_INTERNAL_BORDER_WIDTH (f);
2207 int offset = FRAME_LINE_HEIGHT (f);
2208 int width = FRAME_PIXEL_WIDTH (f);
2209 int height = FRAME_PIXEL_HEIGHT (f);
2210 enum internal_border_part part = INTERNAL_BORDER_NONE;
2212 if (offset < border)
2213 /* For very wide borders make offset at least as large as
2214 border. */
2215 offset = border;
2217 if (offset < x && x < width - offset)
2218 /* Top or bottom border. */
2220 if (0 <= y && y <= border)
2221 part = INTERNAL_BORDER_TOP_EDGE;
2222 else if (height - border <= y && y <= height)
2223 part = INTERNAL_BORDER_BOTTOM_EDGE;
2225 else if (offset < y && y < height - offset)
2226 /* Left or right border. */
2228 if (0 <= x && x <= border)
2229 part = INTERNAL_BORDER_LEFT_EDGE;
2230 else if (width - border <= x && x <= width)
2231 part = INTERNAL_BORDER_RIGHT_EDGE;
2233 else
2235 /* An edge. */
2236 int half_width = width / 2;
2237 int half_height = height / 2;
2239 if (0 <= x && x <= border)
2241 /* A left edge. */
2242 if (0 <= y && y <= half_height)
2243 part = INTERNAL_BORDER_TOP_LEFT_CORNER;
2244 else if (half_height < y && y <= height)
2245 part = INTERNAL_BORDER_BOTTOM_LEFT_CORNER;
2247 else if (width - border <= x && x <= width)
2249 /* A right edge. */
2250 if (0 <= y && y <= half_height)
2251 part = INTERNAL_BORDER_TOP_RIGHT_CORNER;
2252 else if (half_height < y && y <= height)
2253 part = INTERNAL_BORDER_BOTTOM_RIGHT_CORNER;
2255 else if (0 <= y && y <= border)
2257 /* A top edge. */
2258 if (0 <= x && x <= half_width)
2259 part = INTERNAL_BORDER_TOP_LEFT_CORNER;
2260 else if (half_width < x && x <= width)
2261 part = INTERNAL_BORDER_TOP_RIGHT_CORNER;
2263 else if (height - border <= y && y <= height)
2265 /* A bottom edge. */
2266 if (0 <= x && x <= half_width)
2267 part = INTERNAL_BORDER_BOTTOM_LEFT_CORNER;
2268 else if (half_width < x && x <= width)
2269 part = INTERNAL_BORDER_BOTTOM_RIGHT_CORNER;
2273 return part;
2275 #endif
2277 /* Return mouse position in character cell units. */
2279 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
2280 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
2281 The position is given in canonical character cells, where (0, 0) is the
2282 upper-left corner of the frame, X is the horizontal offset, and Y is the
2283 vertical offset, measured in units of the frame's default character size.
2284 If Emacs is running on a mouseless terminal or hasn't been programmed
2285 to read the mouse position, it returns the selected frame for FRAME
2286 and nil for X and Y.
2287 If `mouse-position-function' is non-nil, `mouse-position' calls it,
2288 passing the normal return value to that function as an argument,
2289 and returns whatever that function returns. */)
2290 (void)
2292 struct frame *f;
2293 Lisp_Object lispy_dummy;
2294 Lisp_Object x, y, retval;
2296 f = SELECTED_FRAME ();
2297 x = y = Qnil;
2299 /* It's okay for the hook to refrain from storing anything. */
2300 if (FRAME_TERMINAL (f)->mouse_position_hook)
2302 enum scroll_bar_part party_dummy;
2303 Time time_dummy;
2304 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
2305 &lispy_dummy, &party_dummy,
2306 &x, &y,
2307 &time_dummy);
2310 if (! NILP (x))
2312 int col = XINT (x);
2313 int row = XINT (y);
2314 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
2315 XSETINT (x, col);
2316 XSETINT (y, row);
2318 XSETFRAME (lispy_dummy, f);
2319 retval = Fcons (lispy_dummy, Fcons (x, y));
2320 if (!NILP (Vmouse_position_function))
2321 retval = call1 (Vmouse_position_function, retval);
2322 return retval;
2325 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
2326 Smouse_pixel_position, 0, 0, 0,
2327 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
2328 The position is given in pixel units, where (0, 0) is the
2329 upper-left corner of the frame, X is the horizontal offset, and Y is
2330 the vertical offset.
2331 If Emacs is running on a mouseless terminal or hasn't been programmed
2332 to read the mouse position, it returns the selected frame for FRAME
2333 and nil for X and Y. */)
2334 (void)
2336 struct frame *f;
2337 Lisp_Object lispy_dummy;
2338 Lisp_Object x, y, retval;
2340 f = SELECTED_FRAME ();
2341 x = y = Qnil;
2343 /* It's okay for the hook to refrain from storing anything. */
2344 if (FRAME_TERMINAL (f)->mouse_position_hook)
2346 enum scroll_bar_part party_dummy;
2347 Time time_dummy;
2348 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
2349 &lispy_dummy, &party_dummy,
2350 &x, &y,
2351 &time_dummy);
2354 XSETFRAME (lispy_dummy, f);
2355 retval = Fcons (lispy_dummy, Fcons (x, y));
2356 if (!NILP (Vmouse_position_function))
2357 retval = call1 (Vmouse_position_function, retval);
2358 return retval;
2361 #ifdef HAVE_WINDOW_SYSTEM
2363 /* On frame F, convert character coordinates X and Y to pixel
2364 coordinates *PIX_X and *PIX_Y. */
2366 static void
2367 frame_char_to_pixel_position (struct frame *f, int x, int y,
2368 int *pix_x, int *pix_y)
2370 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
2371 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
2373 if (*pix_x < 0)
2374 *pix_x = 0;
2375 if (*pix_x > FRAME_PIXEL_WIDTH (f))
2376 *pix_x = FRAME_PIXEL_WIDTH (f);
2378 if (*pix_y < 0)
2379 *pix_y = 0;
2380 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
2381 *pix_y = FRAME_PIXEL_HEIGHT (f);
2384 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
2386 static void
2387 frame_set_mouse_position (struct frame *f, int x, int y)
2389 int pix_x, pix_y;
2391 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
2392 frame_set_mouse_pixel_position (f, pix_x, pix_y);
2395 #endif /* HAVE_WINDOW_SYSTEM */
2397 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
2398 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
2399 Coordinates are relative to the frame, not a window,
2400 so the coordinates of the top left character in the frame
2401 may be nonzero due to left-hand scroll bars or the menu bar.
2403 The position is given in canonical character cells, where (0, 0) is
2404 the upper-left corner of the frame, X is the horizontal offset, and
2405 Y is the vertical offset, measured in units of the frame's default
2406 character size.
2408 This function is a no-op for an X frame that is not visible.
2409 If you have just created a frame, you must wait for it to become visible
2410 before calling this function on it, like this.
2411 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2412 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2414 CHECK_LIVE_FRAME (frame);
2415 CHECK_TYPE_RANGED_INTEGER (int, x);
2416 CHECK_TYPE_RANGED_INTEGER (int, y);
2418 /* I think this should be done with a hook. */
2419 #ifdef HAVE_WINDOW_SYSTEM
2420 if (FRAME_WINDOW_P (XFRAME (frame)))
2421 /* Warping the mouse will cause enternotify and focus events. */
2422 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
2423 #else
2424 #if defined (MSDOS)
2425 if (FRAME_MSDOS_P (XFRAME (frame)))
2427 Fselect_frame (frame, Qnil);
2428 mouse_moveto (XINT (x), XINT (y));
2430 #else
2431 #ifdef HAVE_GPM
2433 Fselect_frame (frame, Qnil);
2434 term_mouse_moveto (XINT (x), XINT (y));
2436 #endif
2437 #endif
2438 #endif
2440 return Qnil;
2443 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
2444 Sset_mouse_pixel_position, 3, 3, 0,
2445 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
2446 The position is given in pixels, where (0, 0) is the upper-left corner
2447 of the frame, X is the horizontal offset, and Y is the vertical offset.
2449 Note, this is a no-op for an X frame that is not visible.
2450 If you have just created a frame, you must wait for it to become visible
2451 before calling this function on it, like this.
2452 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2453 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2455 CHECK_LIVE_FRAME (frame);
2456 CHECK_TYPE_RANGED_INTEGER (int, x);
2457 CHECK_TYPE_RANGED_INTEGER (int, y);
2459 /* I think this should be done with a hook. */
2460 #ifdef HAVE_WINDOW_SYSTEM
2461 if (FRAME_WINDOW_P (XFRAME (frame)))
2462 /* Warping the mouse will cause enternotify and focus events. */
2463 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
2464 #else
2465 #if defined (MSDOS)
2466 if (FRAME_MSDOS_P (XFRAME (frame)))
2468 Fselect_frame (frame, Qnil);
2469 mouse_moveto (XINT (x), XINT (y));
2471 #else
2472 #ifdef HAVE_GPM
2474 Fselect_frame (frame, Qnil);
2475 term_mouse_moveto (XINT (x), XINT (y));
2477 #endif
2478 #endif
2479 #endif
2481 return Qnil;
2484 static void make_frame_visible_1 (Lisp_Object);
2486 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2487 0, 1, "",
2488 doc: /* Make the frame FRAME visible (assuming it is an X window).
2489 If omitted, FRAME defaults to the currently selected frame. */)
2490 (Lisp_Object frame)
2492 struct frame *f = decode_live_frame (frame);
2494 /* I think this should be done with a hook. */
2495 #ifdef HAVE_WINDOW_SYSTEM
2496 if (FRAME_WINDOW_P (f))
2497 x_make_frame_visible (f);
2498 #endif
2500 make_frame_visible_1 (f->root_window);
2502 /* Make menu bar update for the Buffers and Frames menus. */
2503 /* windows_or_buffers_changed = 15; FIXME: Why? */
2505 XSETFRAME (frame, f);
2506 return frame;
2509 /* Update the display_time slot of the buffers shown in WINDOW
2510 and all its descendants. */
2512 static void
2513 make_frame_visible_1 (Lisp_Object window)
2515 struct window *w;
2517 for (; !NILP (window); window = w->next)
2519 w = XWINDOW (window);
2520 if (WINDOWP (w->contents))
2521 make_frame_visible_1 (w->contents);
2522 else
2523 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2527 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2528 0, 2, "",
2529 doc: /* Make the frame FRAME invisible.
2530 If omitted, FRAME defaults to the currently selected frame.
2531 On graphical displays, invisible frames are not updated and are
2532 usually not displayed at all, even in a window system's \"taskbar\".
2534 Normally you may not make FRAME invisible if all other frames are invisible,
2535 but if the second optional argument FORCE is non-nil, you may do so.
2537 This function has no effect on text terminal frames. Such frames are
2538 always considered visible, whether or not they are currently being
2539 displayed in the terminal. */)
2540 (Lisp_Object frame, Lisp_Object force)
2542 struct frame *f = decode_live_frame (frame);
2544 if (NILP (force) && !other_frames (f, true, false))
2545 error ("Attempt to make invisible the sole visible or iconified frame");
2547 /* Don't allow minibuf_window to remain on an invisible frame. */
2548 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2550 /* I think this should be done with a hook. */
2551 #ifdef HAVE_WINDOW_SYSTEM
2552 if (FRAME_WINDOW_P (f))
2553 x_make_frame_invisible (f);
2554 #endif
2556 /* Make menu bar update for the Buffers and Frames menus. */
2557 windows_or_buffers_changed = 16;
2559 return Qnil;
2562 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2563 0, 1, "",
2564 doc: /* Make the frame FRAME into an icon.
2565 If omitted, FRAME defaults to the currently selected frame.
2567 If FRAME is a child frame, consult the variable `iconify-child-frame'
2568 for how to proceed. */)
2569 (Lisp_Object frame)
2571 struct frame *f = decode_live_frame (frame);
2572 #ifdef HAVE_WINDOW_SYSTEM
2573 Lisp_Object parent = f->parent_frame;
2575 if (!NILP (parent))
2577 if (NILP (iconify_child_frame))
2578 /* Do nothing. */
2579 return Qnil;
2580 else if (EQ (iconify_child_frame, Qiconify_top_level))
2582 /* Iconify top level frame instead (the default). */
2583 Ficonify_frame (parent);
2584 return Qnil;
2586 else if (EQ (iconify_child_frame, Qmake_invisible))
2588 /* Make frame invisible instead. */
2589 Fmake_frame_invisible (frame, Qnil);
2590 return Qnil;
2593 #endif /* HAVE_WINDOW_SYSTEM */
2595 /* Don't allow minibuf_window to remain on an iconified frame. */
2596 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2598 /* I think this should be done with a hook. */
2599 if (FRAME_WINDOW_P (f))
2601 #ifdef HAVE_WINDOW_SYSTEM
2602 x_iconify_frame (f);
2603 #endif
2606 return Qnil;
2609 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2610 1, 1, 0,
2611 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2612 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2613 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2614 On graphical displays, invisible frames are not updated and are
2615 usually not displayed at all, even in a window system's \"taskbar\".
2617 If FRAME is a text terminal frame, this always returns t.
2618 Such frames are always considered visible, whether or not they are
2619 currently being displayed on the terminal. */)
2620 (Lisp_Object frame)
2622 CHECK_LIVE_FRAME (frame);
2624 if (FRAME_VISIBLE_P (XFRAME (frame)))
2625 return Qt;
2626 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2627 return Qicon;
2628 return Qnil;
2631 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2632 0, 0, 0,
2633 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2634 (void)
2636 Lisp_Object tail, frame, value = Qnil;
2638 FOR_EACH_FRAME (tail, frame)
2639 if (FRAME_VISIBLE_P (XFRAME (frame)))
2640 value = Fcons (frame, value);
2642 return value;
2646 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2647 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2648 If FRAME is invisible or iconified, make it visible.
2649 If you don't specify a frame, the selected frame is used.
2650 If Emacs is displaying on an ordinary terminal or some other device which
2651 doesn't support multiple overlapping frames, this function selects FRAME. */)
2652 (Lisp_Object frame)
2654 struct frame *f = decode_live_frame (frame);
2656 XSETFRAME (frame, f);
2658 if (FRAME_TERMCAP_P (f))
2659 /* On a text terminal select FRAME. */
2660 Fselect_frame (frame, Qnil);
2661 else
2662 /* Do like the documentation says. */
2663 Fmake_frame_visible (frame);
2665 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2666 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2668 return Qnil;
2671 /* Should we have a corresponding function called Flower_Power? */
2672 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2673 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2674 If you don't specify a frame, the selected frame is used.
2675 If Emacs is displaying on an ordinary terminal or some other device which
2676 doesn't support multiple overlapping frames, this function does nothing. */)
2677 (Lisp_Object frame)
2679 struct frame *f = decode_live_frame (frame);
2681 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2682 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2684 return Qnil;
2688 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2689 1, 2, 0,
2690 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2691 In other words, switch-frame events caused by events in FRAME will
2692 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2693 FOCUS-FRAME after reading an event typed at FRAME.
2695 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2696 frame again receives its own keystrokes.
2698 Focus redirection is useful for temporarily redirecting keystrokes to
2699 a surrogate minibuffer frame when a frame doesn't have its own
2700 minibuffer window.
2702 A frame's focus redirection can be changed by `select-frame'. If frame
2703 FOO is selected, and then a different frame BAR is selected, any
2704 frames redirecting their focus to FOO are shifted to redirect their
2705 focus to BAR. This allows focus redirection to work properly when the
2706 user switches from one frame to another using `select-window'.
2708 This means that a frame whose focus is redirected to itself is treated
2709 differently from a frame whose focus is redirected to nil; the former
2710 is affected by `select-frame', while the latter is not.
2712 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2713 (Lisp_Object frame, Lisp_Object focus_frame)
2715 /* Note that we don't check for a live frame here. It's reasonable
2716 to redirect the focus of a frame you're about to delete, if you
2717 know what other frame should receive those keystrokes. */
2718 struct frame *f = decode_any_frame (frame);
2720 if (! NILP (focus_frame))
2721 CHECK_LIVE_FRAME (focus_frame);
2723 fset_focus_frame (f, focus_frame);
2725 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2726 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2728 return Qnil;
2732 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2733 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2734 If FRAME is omitted or nil, the selected frame is used.
2735 Return nil if FRAME's focus is not redirected.
2736 See `redirect-frame-focus'. */)
2737 (Lisp_Object frame)
2739 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2742 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 2, 0,
2743 doc: /* Set the input focus to FRAME.
2744 FRAME nil means use the selected frame. Optional argument NOACTIVATE
2745 means do not activate FRAME.
2747 If there is no window system support, this function does nothing. */)
2748 (Lisp_Object frame, Lisp_Object noactivate)
2750 #ifdef HAVE_WINDOW_SYSTEM
2751 x_focus_frame (decode_window_system_frame (frame), !NILP (noactivate));
2752 #endif
2753 return Qnil;
2756 DEFUN ("frame-after-make-frame",
2757 Fframe_after_make_frame,
2758 Sframe_after_make_frame, 2, 2, 0,
2759 doc: /* Mark FRAME as made.
2760 FRAME nil means use the selected frame. Second argument MADE non-nil
2761 means functions on `window-configuration-change-hook' are called
2762 whenever the window configuration of FRAME changes. MADE nil means
2763 these functions are not called.
2765 This function is currently called by `make-frame' only and should be
2766 otherwise used with utter care to avoid that running functions on
2767 `window-configuration-change-hook' is impeded forever. */)
2768 (Lisp_Object frame, Lisp_Object made)
2770 struct frame *f = decode_live_frame (frame);
2771 f->after_make_frame = !NILP (made);
2772 f->inhibit_horizontal_resize = false;
2773 f->inhibit_vertical_resize = false;
2774 return made;
2778 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2780 void
2781 frames_discard_buffer (Lisp_Object buffer)
2783 Lisp_Object frame, tail;
2785 FOR_EACH_FRAME (tail, frame)
2787 fset_buffer_list
2788 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2789 fset_buried_buffer_list
2790 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2794 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2795 If the alist already has an element for PROP, we change it. */
2797 void
2798 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2800 register Lisp_Object tem;
2802 tem = Fassq (prop, *alistptr);
2803 if (EQ (tem, Qnil))
2804 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2805 else
2806 Fsetcdr (tem, val);
2809 static int
2810 frame_name_fnn_p (char *str, ptrdiff_t len)
2812 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2814 char *p = str + 2;
2815 while ('0' <= *p && *p <= '9')
2816 p++;
2817 if (p == str + len)
2818 return 1;
2820 return 0;
2823 /* Set the name of the terminal frame. Also used by MSDOS frames.
2824 Modeled after x_set_name which is used for WINDOW frames. */
2826 static void
2827 set_term_frame_name (struct frame *f, Lisp_Object name)
2829 f->explicit_name = ! NILP (name);
2831 /* If NAME is nil, set the name to F<num>. */
2832 if (NILP (name))
2834 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2836 /* Check for no change needed in this very common case
2837 before we do any consing. */
2838 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2839 return;
2841 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2843 else
2845 CHECK_STRING (name);
2847 /* Don't change the name if it's already NAME. */
2848 if (! NILP (Fstring_equal (name, f->name)))
2849 return;
2851 /* Don't allow the user to set the frame name to F<num>, so it
2852 doesn't clash with the names we generate for terminal frames. */
2853 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2854 error ("Frame names of the form F<num> are usurped by Emacs");
2857 fset_name (f, name);
2858 update_mode_lines = 16;
2861 void
2862 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2864 register Lisp_Object old_alist_elt;
2866 if (EQ (prop, Qminibuffer))
2868 if (WINDOWP (val))
2870 if (!MINI_WINDOW_P (XWINDOW (val)))
2871 error ("The `minibuffer' parameter does not specify a valid minibuffer window");
2872 else if (FRAME_MINIBUF_ONLY_P (f))
2874 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2875 val = Qonly;
2876 else
2877 error ("Can't change the minibuffer window of a minibuffer-only frame");
2879 else if (FRAME_HAS_MINIBUF_P (f))
2881 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2882 val = Qt;
2883 else
2884 error ("Can't change the minibuffer window of a frame with its own minibuffer");
2886 else
2887 /* Store the chosen minibuffer window. */
2888 fset_minibuffer_window (f, val);
2890 else
2892 Lisp_Object old_val = Fcdr (Fassq (Qminibuffer, f->param_alist));
2894 if (!NILP (old_val))
2896 if (WINDOWP (old_val) && NILP (val))
2897 /* Don't change the value for a minibuffer-less frame if
2898 only nil was specified as new value. */
2899 val = old_val;
2900 else if (!EQ (old_val, val))
2901 error ("Can't change the `minibuffer' parameter of this frame");
2906 /* Check each parent-frame and delete-before parameter for a
2907 circular dependency. Do not check between parameters, so you can
2908 still create circular dependencies with different properties, for
2909 example a chain of frames F1->F2->...Fn such that F1 is an ancestor
2910 frame of Fn and thus cannot be deleted before Fn and a second chain
2911 Fn->Fn-1->...F1 such that Fn cannot be deleted before F1. */
2912 else if (EQ (prop, Qparent_frame) || EQ (prop, Qdelete_before))
2914 Lisp_Object oldval = Fcdr (Fassq (prop, f->param_alist));
2916 if (!EQ (oldval, val) && !NILP (val))
2918 Lisp_Object frame;
2919 Lisp_Object frame1 = val;
2921 if (!FRAMEP (frame1) || !FRAME_LIVE_P (XFRAME (frame1)))
2922 error ("Invalid `%s' frame parameter",
2923 SSDATA (SYMBOL_NAME (prop)));
2925 XSETFRAME (frame, f);
2927 while (FRAMEP (frame1) && FRAME_LIVE_P (XFRAME (frame1)))
2928 if (EQ (frame1, frame))
2929 error ("Circular specification of `%s' frame parameter",
2930 SSDATA (SYMBOL_NAME (prop)));
2931 else
2932 frame1 = get_frame_param (XFRAME (frame1), prop);
2936 /* The buffer-list parameters are stored in a special place and not
2937 in the alist. All buffers must be live. */
2938 else if (EQ (prop, Qbuffer_list))
2940 Lisp_Object list = Qnil;
2941 for (; CONSP (val); val = XCDR (val))
2942 if (!NILP (Fbuffer_live_p (XCAR (val))))
2943 list = Fcons (XCAR (val), list);
2944 fset_buffer_list (f, Fnreverse (list));
2945 return;
2947 else if (EQ (prop, Qburied_buffer_list))
2949 Lisp_Object list = Qnil;
2950 for (; CONSP (val); val = XCDR (val))
2951 if (!NILP (Fbuffer_live_p (XCAR (val))))
2952 list = Fcons (XCAR (val), list);
2953 fset_buried_buffer_list (f, Fnreverse (list));
2954 return;
2957 /* The tty color needed to be set before the frame's parameter
2958 alist was updated with the new value. This is not true any more,
2959 but we still do this test early on. */
2960 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2961 && f == FRAME_TTY (f)->previous_frame)
2962 /* Force redisplay of this tty. */
2963 FRAME_TTY (f)->previous_frame = NULL;
2965 /* Update the frame parameter alist. */
2966 old_alist_elt = Fassq (prop, f->param_alist);
2967 if (EQ (old_alist_elt, Qnil))
2968 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2969 else
2970 Fsetcdr (old_alist_elt, val);
2972 /* Update some other special parameters in their special places
2973 in addition to the alist. */
2975 if (EQ (prop, Qbuffer_predicate))
2976 fset_buffer_predicate (f, val);
2978 if (! FRAME_WINDOW_P (f))
2980 if (EQ (prop, Qmenu_bar_lines))
2981 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2982 else if (EQ (prop, Qname))
2983 set_term_frame_name (f, val);
2987 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2988 is not an unspecified foreground or background color. */
2990 static Lisp_Object
2991 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2993 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2994 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2995 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2996 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2999 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
3000 doc: /* Return the parameters-alist of frame FRAME.
3001 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
3002 The meaningful PARMs depend on the kind of frame.
3003 If FRAME is omitted or nil, return information on the currently selected frame. */)
3004 (Lisp_Object frame)
3006 Lisp_Object alist;
3007 struct frame *f = decode_any_frame (frame);
3008 int height, width;
3010 if (!FRAME_LIVE_P (f))
3011 return Qnil;
3013 alist = Fcopy_alist (f->param_alist);
3015 if (!FRAME_WINDOW_P (f))
3017 Lisp_Object elt;
3019 /* If the frame's parameter alist says the colors are
3020 unspecified and reversed, take the frame's background pixel
3021 for foreground and vice versa. */
3022 elt = Fassq (Qforeground_color, alist);
3023 if (CONSP (elt) && STRINGP (XCDR (elt)))
3025 elt = frame_unspecified_color (f, XCDR (elt));
3026 if (!NILP (elt))
3027 store_in_alist (&alist, Qforeground_color, elt);
3029 else
3030 store_in_alist (&alist, Qforeground_color,
3031 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
3032 elt = Fassq (Qbackground_color, alist);
3033 if (CONSP (elt) && STRINGP (XCDR (elt)))
3035 elt = frame_unspecified_color (f, XCDR (elt));
3036 if (!NILP (elt))
3037 store_in_alist (&alist, Qbackground_color, elt);
3039 else
3040 store_in_alist (&alist, Qbackground_color,
3041 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
3042 store_in_alist (&alist, Qfont,
3043 build_string (FRAME_MSDOS_P (f)
3044 ? "ms-dos"
3045 : FRAME_W32_P (f) ? "w32term"
3046 :"tty"));
3048 store_in_alist (&alist, Qname, f->name);
3049 height = (f->new_height
3050 ? (f->new_pixelwise
3051 ? (f->new_height / FRAME_LINE_HEIGHT (f))
3052 : f->new_height)
3053 : FRAME_LINES (f));
3054 store_in_alist (&alist, Qheight, make_number (height));
3055 width = (f->new_width
3056 ? (f->new_pixelwise
3057 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
3058 : f->new_width)
3059 : FRAME_COLS (f));
3060 store_in_alist (&alist, Qwidth, make_number (width));
3061 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
3062 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
3063 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
3064 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
3066 /* I think this should be done with a hook. */
3067 #ifdef HAVE_WINDOW_SYSTEM
3068 if (FRAME_WINDOW_P (f))
3069 x_report_frame_params (f, &alist);
3070 else
3071 #endif
3073 /* This ought to be correct in f->param_alist for an X frame. */
3074 Lisp_Object lines;
3075 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
3076 store_in_alist (&alist, Qmenu_bar_lines, lines);
3079 return alist;
3083 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
3084 doc: /* Return FRAME's value for parameter PARAMETER.
3085 If FRAME is nil, describe the currently selected frame. */)
3086 (Lisp_Object frame, Lisp_Object parameter)
3088 struct frame *f = decode_any_frame (frame);
3089 Lisp_Object value = Qnil;
3091 CHECK_SYMBOL (parameter);
3093 XSETFRAME (frame, f);
3095 if (FRAME_LIVE_P (f))
3097 /* Avoid consing in frequent cases. */
3098 if (EQ (parameter, Qname))
3099 value = f->name;
3100 #ifdef HAVE_WINDOW_SYSTEM
3101 /* These are used by vertical motion commands. */
3102 else if (EQ (parameter, Qvertical_scroll_bars))
3103 value = (f->vertical_scroll_bar_type == vertical_scroll_bar_none
3104 ? Qnil
3105 : (f->vertical_scroll_bar_type == vertical_scroll_bar_left
3106 ? Qleft : Qright));
3107 else if (EQ (parameter, Qhorizontal_scroll_bars))
3108 value = f->horizontal_scroll_bars ? Qt : Qnil;
3109 else if (EQ (parameter, Qline_spacing) && f->extra_line_spacing == 0)
3110 /* If this is non-zero, we can't determine whether the user specified
3111 an integer or float value without looking through 'param_alist'. */
3112 value = make_number (0);
3113 else if (EQ (parameter, Qfont) && FRAME_X_P (f))
3114 value = FRAME_FONT (f)->props[FONT_NAME_INDEX];
3115 #endif /* HAVE_WINDOW_SYSTEM */
3116 #ifdef HAVE_X_WINDOWS
3117 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
3118 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
3119 #endif /* HAVE_X_WINDOWS */
3120 else if (EQ (parameter, Qbackground_color)
3121 || EQ (parameter, Qforeground_color))
3123 value = Fassq (parameter, f->param_alist);
3124 if (CONSP (value))
3126 value = XCDR (value);
3127 /* Fframe_parameters puts the actual fg/bg color names,
3128 even if f->param_alist says otherwise. This is
3129 important when param_alist's notion of colors is
3130 "unspecified". We need to do the same here. */
3131 if (STRINGP (value) && !FRAME_WINDOW_P (f))
3133 Lisp_Object tem = frame_unspecified_color (f, value);
3135 if (!NILP (tem))
3136 value = tem;
3139 else
3140 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
3142 else if (EQ (parameter, Qdisplay_type)
3143 || EQ (parameter, Qbackground_mode))
3144 value = Fcdr (Fassq (parameter, f->param_alist));
3145 else
3146 /* FIXME: Avoid this code path at all (as well as code duplication)
3147 by sharing more code with Fframe_parameters. */
3148 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
3151 return value;
3155 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
3156 Smodify_frame_parameters, 2, 2, 0,
3157 doc: /* Modify FRAME according to new values of its parameters in ALIST.
3158 If FRAME is nil, it defaults to the selected frame.
3159 ALIST is an alist of parameters to change and their new values.
3160 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
3161 Which PARMs are meaningful depends on the kind of frame.
3162 The meaningful parameters are acted upon, i.e. the frame is changed
3163 according to their new values, and are also stored in the frame's
3164 parameter list so that `frame-parameters' will return them.
3165 PARMs that are not meaningful are still stored in the frame's parameter
3166 list, but are otherwise ignored. */)
3167 (Lisp_Object frame, Lisp_Object alist)
3169 struct frame *f = decode_live_frame (frame);
3170 Lisp_Object prop, val;
3172 /* I think this should be done with a hook. */
3173 #ifdef HAVE_WINDOW_SYSTEM
3174 if (FRAME_WINDOW_P (f))
3175 x_set_frame_parameters (f, alist);
3176 else
3177 #endif
3178 #ifdef MSDOS
3179 if (FRAME_MSDOS_P (f))
3180 IT_set_frame_parameters (f, alist);
3181 else
3182 #endif
3185 EMACS_INT length = XFASTINT (Flength (alist));
3186 ptrdiff_t i;
3187 Lisp_Object *parms;
3188 Lisp_Object *values;
3189 USE_SAFE_ALLOCA;
3190 SAFE_ALLOCA_LISP (parms, 2 * length);
3191 values = parms + length;
3193 /* Extract parm names and values into those vectors. */
3195 for (i = 0; CONSP (alist); alist = XCDR (alist))
3197 Lisp_Object elt;
3199 elt = XCAR (alist);
3200 parms[i] = Fcar (elt);
3201 values[i] = Fcdr (elt);
3202 i++;
3205 /* Now process them in reverse of specified order. */
3206 while (--i >= 0)
3208 prop = parms[i];
3209 val = values[i];
3210 store_frame_param (f, prop, val);
3212 if (EQ (prop, Qforeground_color)
3213 || EQ (prop, Qbackground_color))
3214 update_face_from_frame_parameter (f, prop, val);
3217 SAFE_FREE ();
3219 return Qnil;
3222 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
3223 0, 1, 0,
3224 doc: /* Height in pixels of a line in the font in frame FRAME.
3225 If FRAME is omitted or nil, the selected frame is used.
3226 For a terminal frame, the value is always 1. */)
3227 (Lisp_Object frame)
3229 #ifdef HAVE_WINDOW_SYSTEM
3230 struct frame *f = decode_any_frame (frame);
3232 if (FRAME_WINDOW_P (f))
3233 return make_number (FRAME_LINE_HEIGHT (f));
3234 else
3235 #endif
3236 return make_number (1);
3240 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
3241 0, 1, 0,
3242 doc: /* Width in pixels of characters in the font in frame FRAME.
3243 If FRAME is omitted or nil, the selected frame is used.
3244 On a graphical screen, the width is the standard width of the default font.
3245 For a terminal screen, the value is always 1. */)
3246 (Lisp_Object frame)
3248 #ifdef HAVE_WINDOW_SYSTEM
3249 struct frame *f = decode_any_frame (frame);
3251 if (FRAME_WINDOW_P (f))
3252 return make_number (FRAME_COLUMN_WIDTH (f));
3253 else
3254 #endif
3255 return make_number (1);
3258 DEFUN ("frame-native-width", Fframe_native_width,
3259 Sframe_native_width, 0, 1, 0,
3260 doc: /* Return FRAME's native width in pixels.
3261 For a terminal frame, the result really gives the width in characters.
3262 If FRAME is omitted or nil, the selected frame is used. */)
3263 (Lisp_Object frame)
3265 struct frame *f = decode_any_frame (frame);
3267 #ifdef HAVE_WINDOW_SYSTEM
3268 if (FRAME_WINDOW_P (f))
3269 return make_number (FRAME_PIXEL_WIDTH (f));
3270 else
3271 #endif
3272 return make_number (FRAME_TOTAL_COLS (f));
3275 DEFUN ("frame-native-height", Fframe_native_height,
3276 Sframe_native_height, 0, 1, 0,
3277 doc: /* Return FRAME's native height in pixels.
3278 If FRAME is omitted or nil, the selected frame is used. The exact value
3279 of the result depends on the window-system and toolkit in use:
3281 In the Gtk+ and NS versions, it includes only any window (including the
3282 minibuffer or echo area), mode line, and header line. It does not
3283 include the tool bar or menu bar. With other graphical versions, it may
3284 also include the tool bar and the menu bar.
3286 For a text terminal, it includes the menu bar. In this case, the
3287 result is really in characters rather than pixels (i.e., is identical
3288 to `frame-height'). */)
3289 (Lisp_Object frame)
3291 struct frame *f = decode_any_frame (frame);
3293 #ifdef HAVE_WINDOW_SYSTEM
3294 if (FRAME_WINDOW_P (f))
3295 return make_number (FRAME_PIXEL_HEIGHT (f));
3296 else
3297 #endif
3298 return make_number (FRAME_TOTAL_LINES (f));
3301 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
3302 Stool_bar_pixel_width, 0, 1, 0,
3303 doc: /* Return width in pixels of FRAME's tool bar.
3304 The result is greater than zero only when the tool bar is on the left
3305 or right side of FRAME. If FRAME is omitted or nil, the selected frame
3306 is used. */)
3307 (Lisp_Object frame)
3309 #ifdef FRAME_TOOLBAR_WIDTH
3310 struct frame *f = decode_any_frame (frame);
3312 if (FRAME_WINDOW_P (f))
3313 return make_number (FRAME_TOOLBAR_WIDTH (f));
3314 #endif
3315 return make_number (0);
3318 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
3319 doc: /* Return width in columns of FRAME's text area. */)
3320 (Lisp_Object frame)
3322 return make_number (FRAME_COLS (decode_any_frame (frame)));
3325 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
3326 doc: /* Return height in lines of FRAME's text area. */)
3327 (Lisp_Object frame)
3329 return make_number (FRAME_LINES (decode_any_frame (frame)));
3332 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
3333 doc: /* Return number of total columns of FRAME. */)
3334 (Lisp_Object frame)
3336 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
3339 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
3340 doc: /* Return number of total lines of FRAME. */)
3341 (Lisp_Object frame)
3343 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
3346 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
3347 doc: /* Return text area width of FRAME in pixels. */)
3348 (Lisp_Object frame)
3350 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
3353 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
3354 doc: /* Return text area height of FRAME in pixels. */)
3355 (Lisp_Object frame)
3357 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
3360 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
3361 doc: /* Return scroll bar width of FRAME in pixels. */)
3362 (Lisp_Object frame)
3364 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
3367 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
3368 doc: /* Return scroll bar height of FRAME in pixels. */)
3369 (Lisp_Object frame)
3371 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
3374 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
3375 doc: /* Return fringe width of FRAME in pixels. */)
3376 (Lisp_Object frame)
3378 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
3381 DEFUN ("frame-internal-border-width", Fframe_internal_border_width, Sframe_internal_border_width, 0, 1, 0,
3382 doc: /* Return width of FRAME's internal border in pixels. */)
3383 (Lisp_Object frame)
3385 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
3388 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
3389 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
3390 (Lisp_Object frame)
3392 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
3395 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
3396 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
3397 (Lisp_Object frame)
3399 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
3402 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
3403 doc: /* Set text height of frame FRAME to HEIGHT lines.
3404 Optional third arg PRETEND non-nil means that redisplay should use
3405 HEIGHT lines but that the idea of the actual height of the frame should
3406 not be changed.
3408 Optional fourth argument PIXELWISE non-nil means that FRAME should be
3409 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
3410 window managers may refuse to honor a HEIGHT that is not an integer
3411 multiple of the default frame font height. */)
3412 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
3414 struct frame *f = decode_live_frame (frame);
3415 int pixel_height;
3417 CHECK_TYPE_RANGED_INTEGER (int, height);
3419 pixel_height = (!NILP (pixelwise)
3420 ? XINT (height)
3421 : XINT (height) * FRAME_LINE_HEIGHT (f));
3422 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
3424 return Qnil;
3427 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
3428 doc: /* Set text width of frame FRAME to WIDTH columns.
3429 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
3430 columns but that the idea of the actual width of the frame should not
3431 be changed.
3433 Optional fourth argument PIXELWISE non-nil means that FRAME should be
3434 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
3435 window managers may refuse to honor a WIDTH that is not an integer
3436 multiple of the default frame font width. */)
3437 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
3439 struct frame *f = decode_live_frame (frame);
3440 int pixel_width;
3442 CHECK_TYPE_RANGED_INTEGER (int, width);
3444 pixel_width = (!NILP (pixelwise)
3445 ? XINT (width)
3446 : XINT (width) * FRAME_COLUMN_WIDTH (f));
3447 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
3449 return Qnil;
3452 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
3453 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
3454 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
3455 When `frame-resize-pixelwise' is nil, some window managers may refuse to
3456 honor a WIDTH that is not an integer multiple of the default frame font
3457 width or a HEIGHT that is not an integer multiple of the default frame
3458 font height. */)
3459 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
3461 struct frame *f = decode_live_frame (frame);
3462 int pixel_width, pixel_height;
3464 CHECK_TYPE_RANGED_INTEGER (int, width);
3465 CHECK_TYPE_RANGED_INTEGER (int, height);
3467 pixel_width = (!NILP (pixelwise)
3468 ? XINT (width)
3469 : XINT (width) * FRAME_COLUMN_WIDTH (f));
3470 pixel_height = (!NILP (pixelwise)
3471 ? XINT (height)
3472 : XINT (height) * FRAME_LINE_HEIGHT (f));
3473 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
3475 return Qnil;
3478 DEFUN ("frame-position", Fframe_position,
3479 Sframe_position, 0, 1, 0,
3480 doc: /* Return top left corner of FRAME in pixels.
3481 FRAME must be a live frame and defaults to the selected one. The return
3482 value is a cons (x, y) of the coordinates of the top left corner of
3483 FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's
3484 display. */)
3485 (Lisp_Object frame)
3487 register struct frame *f = decode_live_frame (frame);
3489 return Fcons (make_number (f->left_pos), make_number (f->top_pos));
3492 DEFUN ("set-frame-position", Fset_frame_position,
3493 Sset_frame_position, 3, 3, 0,
3494 doc: /* Set position of FRAME to (X, Y).
3495 FRAME must be a live frame and defaults to the selected one. X and Y,
3496 if positive, specify the coordinate of the left and top edge of FRAME's
3497 outer frame in pixels relative to an origin (0, 0) of FRAME's display.
3498 If any of X or Y is negative, it specifies the coordinates of the right
3499 or bottom edge of the outer frame of FRAME relative to the right or
3500 bottom edge of FRAME's display. */)
3501 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
3503 struct frame *f = decode_live_frame (frame);
3505 CHECK_TYPE_RANGED_INTEGER (int, x);
3506 CHECK_TYPE_RANGED_INTEGER (int, y);
3508 /* I think this should be done with a hook. */
3509 if (FRAME_WINDOW_P (f))
3511 #ifdef HAVE_WINDOW_SYSTEM
3512 x_set_offset (f, XINT (x), XINT (y), 1);
3513 #endif
3516 return Qt;
3519 /***********************************************************************
3520 Frame Parameters
3521 ***********************************************************************/
3523 /* Connect the frame-parameter names for X frames
3524 to the ways of passing the parameter values to the window system.
3526 The name of a parameter, as a Lisp symbol,
3527 has an `x-frame-parameter' property which is an integer in Lisp
3528 that is an index in this table. */
3530 struct frame_parm_table {
3531 const char *name;
3532 int sym;
3535 static const struct frame_parm_table frame_parms[] =
3537 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3538 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3539 {"background-color", -1},
3540 {"border-color", SYMBOL_INDEX (Qborder_color)},
3541 {"border-width", SYMBOL_INDEX (Qborder_width)},
3542 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3543 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3544 {"font", -1},
3545 {"foreground-color", -1},
3546 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3547 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3548 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3549 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3550 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3551 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3552 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3553 {"name", SYMBOL_INDEX (Qname)},
3554 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3555 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3556 {"title", SYMBOL_INDEX (Qtitle)},
3557 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3558 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3559 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3560 {"visibility", SYMBOL_INDEX (Qvisibility)},
3561 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3562 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3563 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3564 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3565 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3566 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3567 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3568 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3569 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3570 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3571 {"alpha", SYMBOL_INDEX (Qalpha)},
3572 {"sticky", SYMBOL_INDEX (Qsticky)},
3573 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3574 {"inhibit-double-buffering", SYMBOL_INDEX (Qinhibit_double_buffering)},
3575 {"undecorated", SYMBOL_INDEX (Qundecorated)},
3576 {"parent-frame", SYMBOL_INDEX (Qparent_frame)},
3577 {"skip-taskbar", SYMBOL_INDEX (Qskip_taskbar)},
3578 {"no-focus-on-map", SYMBOL_INDEX (Qno_focus_on_map)},
3579 {"no-accept-focus", SYMBOL_INDEX (Qno_accept_focus)},
3580 {"z-group", SYMBOL_INDEX (Qz_group)},
3581 {"override-redirect", SYMBOL_INDEX (Qoverride_redirect)},
3582 {"no-special-glyphs", SYMBOL_INDEX (Qno_special_glyphs)},
3583 #ifdef NS_IMPL_COCOA
3584 {"ns-appearance", SYMBOL_INDEX (Qns_appearance)},
3585 {"ns-transparent-titlebar", SYMBOL_INDEX (Qns_transparent_titlebar)},
3586 #endif
3589 #ifdef HAVE_WINDOW_SYSTEM
3591 /* Enumeration type for switch in frame_float. */
3592 enum frame_float_type
3594 FRAME_FLOAT_WIDTH,
3595 FRAME_FLOAT_HEIGHT,
3596 FRAME_FLOAT_LEFT,
3597 FRAME_FLOAT_TOP
3601 * frame_float:
3603 * Process the value VAL of the float type frame parameter 'width',
3604 * 'height', 'left', or 'top' specified via a frame_float_type
3605 * enumeration type WHAT for frame F. Such parameters relate the outer
3606 * size or position of F to the size of the F's display or parent frame
3607 * which have to be both available in some way.
3609 * The return value is a size or position value in pixels. VAL must be
3610 * in the range 0.0 to 1.0 where a width/height of 0.0 means to return 0
3611 * and 1.0 means to return the full width/height of the display/parent.
3612 * For positions, 0.0 means position in the left/top corner of the
3613 * display/parent while 1.0 means to position at the right/bottom corner
3614 * of the display/parent frame.
3616 * Set PARENT_DONE and OUTER_DONE to avoid recalculation of the outer
3617 * size or parent or display attributes when more float parameters are
3618 * calculated in a row: -1 means not processed yet, 0 means processing
3619 * failed, 1 means processing succeeded.
3621 * Return DEFAULT_VALUE when processing fails for whatever reason with
3622 * one exception: When calculating F's outer edges fails (probably
3623 * because F has not been created yet) return the difference between F's
3624 * native and text size.
3626 static int
3627 frame_float (struct frame *f, Lisp_Object val, enum frame_float_type what,
3628 int *parent_done, int *outer_done, int default_value)
3630 double d_val = XFLOAT_DATA (val);
3632 if (d_val < 0.0 || d_val > 1.0)
3633 /* Invalid VAL. */
3634 return default_value;
3635 else
3637 static unsigned parent_width, parent_height;
3638 static int parent_left, parent_top;
3639 static unsigned outer_minus_text_width, outer_minus_text_height;
3640 struct frame *p = FRAME_PARENT_FRAME (f);
3642 if (*parent_done == 1)
3644 else if (p)
3646 parent_width = FRAME_PIXEL_WIDTH (p);
3647 parent_height = FRAME_PIXEL_HEIGHT (p);
3648 *parent_done = 1;
3650 else
3652 if (*parent_done == 0)
3653 /* No workarea available. */
3654 return default_value;
3655 else if (*parent_done == -1)
3657 Lisp_Object monitor_attributes;
3658 Lisp_Object workarea;
3659 Lisp_Object frame;
3661 XSETFRAME (frame, f);
3662 monitor_attributes = Fcar (call1 (Qdisplay_monitor_attributes_list, frame));
3663 if (NILP (monitor_attributes))
3665 /* No monitor attributes available. */
3666 *parent_done = 0;
3668 return default_value;
3671 workarea = Fcdr (Fassq (Qworkarea, monitor_attributes));
3672 if (NILP (workarea))
3674 /* No workarea available. */
3675 *parent_done = 0;
3677 return default_value;
3680 /* Workarea available. */
3681 parent_left = XINT (Fnth (make_number (0), workarea));
3682 parent_top = XINT (Fnth (make_number (1), workarea));
3683 parent_width = XINT (Fnth (make_number (2), workarea));
3684 parent_height = XINT (Fnth (make_number (3), workarea));
3685 *parent_done = 1;
3689 if (*outer_done == 1)
3691 else if (FRAME_UNDECORATED (f))
3693 outer_minus_text_width
3694 = FRAME_PIXEL_WIDTH (f) - FRAME_TEXT_WIDTH (f);
3695 outer_minus_text_height
3696 = FRAME_PIXEL_HEIGHT (f) - FRAME_TEXT_HEIGHT (f);
3697 *outer_done = 1;
3699 else if (*outer_done == 0)
3700 /* No outer size available. */
3701 return default_value;
3702 else if (*outer_done == -1)
3704 Lisp_Object frame, outer_edges;
3706 XSETFRAME (frame, f);
3707 outer_edges = call2 (Qframe_edges, frame, Qouter_edges);
3709 if (!NILP (outer_edges))
3711 outer_minus_text_width
3712 = (XINT (Fnth (make_number (2), outer_edges))
3713 - XINT (Fnth (make_number (0), outer_edges))
3714 - FRAME_TEXT_WIDTH (f));
3715 outer_minus_text_height
3716 = (XINT (Fnth (make_number (3), outer_edges))
3717 - XINT (Fnth (make_number (1), outer_edges))
3718 - FRAME_TEXT_HEIGHT (f));
3720 else
3722 /* If we can't get any outer edges, proceed as if the frame
3723 were undecorated. */
3724 outer_minus_text_width
3725 = FRAME_PIXEL_WIDTH (f) - FRAME_TEXT_WIDTH (f);
3726 outer_minus_text_height
3727 = FRAME_PIXEL_HEIGHT (f) - FRAME_TEXT_HEIGHT (f);
3730 *outer_done = 1;
3733 switch (what)
3735 case FRAME_FLOAT_WIDTH:
3736 return parent_width * d_val - outer_minus_text_width;
3738 case FRAME_FLOAT_HEIGHT:
3739 return parent_height * d_val - outer_minus_text_height;
3741 case FRAME_FLOAT_LEFT:
3743 int rest_width = (parent_width
3744 - FRAME_TEXT_WIDTH (f)
3745 - outer_minus_text_width);
3747 if (p)
3748 return (rest_width <= 0 ? 0 : d_val * rest_width);
3749 else
3750 return (rest_width <= 0
3751 ? parent_left
3752 : parent_left + d_val * rest_width);
3754 case FRAME_FLOAT_TOP:
3756 int rest_height = (parent_height
3757 - FRAME_TEXT_HEIGHT (f)
3758 - outer_minus_text_height);
3760 if (p)
3761 return (rest_height <= 0 ? 0 : d_val * rest_height);
3762 else
3763 return (rest_height <= 0
3764 ? parent_top
3765 : parent_top + d_val * rest_height);
3767 default:
3768 emacs_abort ();
3773 /* Change the parameters of frame F as specified by ALIST.
3774 If a parameter is not specially recognized, do nothing special;
3775 otherwise call the `x_set_...' function for that parameter.
3776 Except for certain geometry properties, always call store_frame_param
3777 to store the new value in the parameter alist. */
3779 void
3780 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3782 Lisp_Object tail, frame;
3785 /* If both of these parameters are present, it's more efficient to
3786 set them both at once. So we wait until we've looked at the
3787 entire list before we set them. */
3788 int width = -1, height = -1; /* -1 denotes they were not changed. */
3790 /* Same here. */
3791 Lisp_Object left, top;
3793 /* Same with these. */
3794 Lisp_Object icon_left, icon_top;
3796 /* And with this. */
3797 Lisp_Object fullscreen;
3798 bool fullscreen_change = false;
3800 /* Record in these vectors all the parms specified. */
3801 Lisp_Object *parms;
3802 Lisp_Object *values;
3803 ptrdiff_t i, j, size;
3804 bool left_no_change = 0, top_no_change = 0;
3805 #ifdef HAVE_X_WINDOWS
3806 bool icon_left_no_change = 0, icon_top_no_change = 0;
3807 #endif
3808 int parent_done = -1, outer_done = -1;
3810 XSETFRAME (frame, f);
3811 for (size = 0, tail = alist; CONSP (tail); tail = XCDR (tail))
3812 size++;
3813 CHECK_LIST_END (tail, alist);
3815 USE_SAFE_ALLOCA;
3816 SAFE_ALLOCA_LISP (parms, 2 * size);
3817 values = parms + size;
3819 /* Extract parm names and values into those vectors. */
3821 i = 0, j = size - 1;
3822 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3824 Lisp_Object elt = XCAR (tail), prop = Fcar (elt), val = Fcdr (elt);
3826 /* Some properties are independent of other properties, but other
3827 properties are dependent upon them. These special properties
3828 are foreground_color, background_color (affects cursor_color)
3829 and font (affects fringe widths); they're recorded starting
3830 from the end of PARMS and VALUES to process them first by using
3831 reverse iteration. */
3833 if (EQ (prop, Qforeground_color)
3834 || EQ (prop, Qbackground_color)
3835 || EQ (prop, Qfont))
3837 parms[j] = prop;
3838 values[j] = val;
3839 j--;
3841 else
3843 parms[i] = prop;
3844 values[i] = val;
3845 i++;
3849 /* TAIL and ALIST are not used again below here. */
3850 alist = tail = Qnil;
3852 top = left = Qunbound;
3853 icon_left = icon_top = Qunbound;
3855 /* Reverse order is used to make sure that special
3856 properties noticed above are processed first. */
3857 for (i = size - 1; i >= 0; i--)
3859 Lisp_Object prop, val;
3861 prop = parms[i];
3862 val = values[i];
3864 if (EQ (prop, Qwidth))
3866 if (RANGED_INTEGERP (0, val, INT_MAX))
3867 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3868 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3869 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3870 width = XFASTINT (XCDR (val));
3871 else if (FLOATP (val))
3872 width = frame_float (f, val, FRAME_FLOAT_WIDTH, &parent_done,
3873 &outer_done, -1);
3875 else if (EQ (prop, Qheight))
3877 if (RANGED_INTEGERP (0, val, INT_MAX))
3878 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3879 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3880 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3881 height = XFASTINT (XCDR (val));
3882 else if (FLOATP (val))
3883 height = frame_float (f, val, FRAME_FLOAT_HEIGHT, &parent_done,
3884 &outer_done, -1);
3886 else if (EQ (prop, Qtop))
3887 top = val;
3888 else if (EQ (prop, Qleft))
3889 left = val;
3890 else if (EQ (prop, Qicon_top))
3891 icon_top = val;
3892 else if (EQ (prop, Qicon_left))
3893 icon_left = val;
3894 else if (EQ (prop, Qfullscreen))
3896 fullscreen = val;
3897 fullscreen_change = true;
3899 else
3901 register Lisp_Object param_index, old_value;
3903 old_value = get_frame_param (f, prop);
3905 store_frame_param (f, prop, val);
3907 param_index = Fget (prop, Qx_frame_parameter);
3908 if (NATNUMP (param_index)
3909 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3910 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3911 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3915 /* Don't die if just one of these was set. */
3916 if (EQ (left, Qunbound))
3918 left_no_change = 1;
3919 if (f->left_pos < 0)
3920 left = list2 (Qplus, make_number (f->left_pos));
3921 else
3922 XSETINT (left, f->left_pos);
3924 if (EQ (top, Qunbound))
3926 top_no_change = 1;
3927 if (f->top_pos < 0)
3928 top = list2 (Qplus, make_number (f->top_pos));
3929 else
3930 XSETINT (top, f->top_pos);
3933 /* If one of the icon positions was not set, preserve or default it. */
3934 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3936 #ifdef HAVE_X_WINDOWS
3937 icon_left_no_change = 1;
3938 #endif
3939 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3940 if (NILP (icon_left))
3941 XSETINT (icon_left, 0);
3943 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3945 #ifdef HAVE_X_WINDOWS
3946 icon_top_no_change = 1;
3947 #endif
3948 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3949 if (NILP (icon_top))
3950 XSETINT (icon_top, 0);
3953 /* Don't set these parameters unless they've been explicitly
3954 specified. The window might be mapped or resized while we're in
3955 this function, and we don't want to override that unless the lisp
3956 code has asked for it.
3958 Don't set these parameters unless they actually differ from the
3959 window's current parameters; the window may not actually exist
3960 yet. */
3961 if ((width != -1 && width != FRAME_TEXT_WIDTH (f))
3962 || (height != -1 && height != FRAME_TEXT_HEIGHT (f)))
3963 /* We could consider checking f->after_make_frame here, but I
3964 don't have the faintest idea why the following is needed at
3965 all. With the old setting it can get a Heisenbug when
3966 EmacsFrameResize intermittently provokes a delayed
3967 change_frame_size in the middle of adjust_frame_size. */
3968 /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
3969 adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters);
3971 if ((!NILP (left) || !NILP (top))
3972 && ! (left_no_change && top_no_change)
3973 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3974 && NUMBERP (top) && XINT (top) == f->top_pos))
3976 int leftpos = 0;
3977 int toppos = 0;
3979 /* Record the signs. */
3980 f->size_hint_flags &= ~ (XNegative | YNegative);
3981 if (EQ (left, Qminus))
3982 f->size_hint_flags |= XNegative;
3983 else if (TYPE_RANGED_INTEGERP (int, left))
3985 leftpos = XINT (left);
3986 if (leftpos < 0)
3987 f->size_hint_flags |= XNegative;
3989 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3990 && CONSP (XCDR (left))
3991 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3993 leftpos = - XINT (XCAR (XCDR (left)));
3994 f->size_hint_flags |= XNegative;
3996 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3997 && CONSP (XCDR (left))
3998 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3999 leftpos = XINT (XCAR (XCDR (left)));
4000 else if (FLOATP (left))
4001 leftpos = frame_float (f, left, FRAME_FLOAT_LEFT, &parent_done,
4002 &outer_done, 0);
4004 if (EQ (top, Qminus))
4005 f->size_hint_flags |= YNegative;
4006 else if (TYPE_RANGED_INTEGERP (int, top))
4008 toppos = XINT (top);
4009 if (toppos < 0)
4010 f->size_hint_flags |= YNegative;
4012 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4013 && CONSP (XCDR (top))
4014 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4016 toppos = - XINT (XCAR (XCDR (top)));
4017 f->size_hint_flags |= YNegative;
4019 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4020 && CONSP (XCDR (top))
4021 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4022 toppos = XINT (XCAR (XCDR (top)));
4023 else if (FLOATP (top))
4024 toppos = frame_float (f, top, FRAME_FLOAT_TOP, &parent_done,
4025 &outer_done, 0);
4027 /* Store the numeric value of the position. */
4028 f->top_pos = toppos;
4029 f->left_pos = leftpos;
4031 f->win_gravity = NorthWestGravity;
4033 /* Actually set that position, and convert to absolute. */
4034 x_set_offset (f, leftpos, toppos, -1);
4037 if (fullscreen_change)
4039 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
4041 frame_size_history_add
4042 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
4044 store_frame_param (f, Qfullscreen, fullscreen);
4045 if (!EQ (fullscreen, old_value))
4046 x_set_fullscreen (f, fullscreen, old_value);
4050 #ifdef HAVE_X_WINDOWS
4051 if ((!NILP (icon_left) || !NILP (icon_top))
4052 && ! (icon_left_no_change && icon_top_no_change))
4053 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
4054 #endif /* HAVE_X_WINDOWS */
4056 SAFE_FREE ();
4060 /* Insert a description of internally-recorded parameters of frame X
4061 into the parameter alist *ALISTPTR that is to be given to the user.
4062 Only parameters that are specific to the X window system
4063 and whose values are not correctly recorded in the frame's
4064 param_alist need to be considered here. */
4066 void
4067 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
4069 Lisp_Object tem;
4070 uprintmax_t w;
4071 char buf[INT_BUFSIZE_BOUND (w)];
4073 /* Represent negative positions (off the top or left screen edge)
4074 in a way that Fmodify_frame_parameters will understand correctly. */
4075 XSETINT (tem, f->left_pos);
4076 if (f->left_pos >= 0)
4077 store_in_alist (alistptr, Qleft, tem);
4078 else
4079 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
4081 XSETINT (tem, f->top_pos);
4082 if (f->top_pos >= 0)
4083 store_in_alist (alistptr, Qtop, tem);
4084 else
4085 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
4087 store_in_alist (alistptr, Qborder_width,
4088 make_number (f->border_width));
4089 store_in_alist (alistptr, Qinternal_border_width,
4090 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
4091 store_in_alist (alistptr, Qright_divider_width,
4092 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
4093 store_in_alist (alistptr, Qbottom_divider_width,
4094 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
4095 store_in_alist (alistptr, Qleft_fringe,
4096 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
4097 store_in_alist (alistptr, Qright_fringe,
4098 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
4099 store_in_alist (alistptr, Qscroll_bar_width,
4100 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
4101 ? make_number (0)
4102 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
4103 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
4104 /* nil means "use default width"
4105 for non-toolkit scroll bar.
4106 ruler-mode.el depends on this. */
4107 : Qnil));
4108 store_in_alist (alistptr, Qscroll_bar_height,
4109 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
4110 ? make_number (0)
4111 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
4112 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
4113 /* nil means "use default height"
4114 for non-toolkit scroll bar. */
4115 : Qnil));
4116 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
4117 MS-Windows it returns a value whose type is HANDLE, which is
4118 actually a pointer. Explicit casting avoids compiler
4119 warnings. */
4120 w = (uintptr_t) FRAME_X_WINDOW (f);
4121 store_in_alist (alistptr, Qwindow_id,
4122 make_formatted_string (buf, "%"pMu, w));
4123 #ifdef HAVE_X_WINDOWS
4124 #ifdef USE_X_TOOLKIT
4125 /* Tooltip frame may not have this widget. */
4126 if (FRAME_X_OUTPUT (f)->widget)
4127 #endif
4128 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
4129 store_in_alist (alistptr, Qouter_window_id,
4130 make_formatted_string (buf, "%"pMu, w));
4131 #endif
4132 store_in_alist (alistptr, Qicon_name, f->icon_name);
4133 store_in_alist (alistptr, Qvisibility,
4134 (FRAME_VISIBLE_P (f) ? Qt
4135 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
4136 store_in_alist (alistptr, Qdisplay,
4137 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
4139 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
4140 tem = Qnil;
4141 else
4142 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
4143 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
4144 store_in_alist (alistptr, Qparent_id, tem);
4145 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
4149 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
4150 the previous value of that parameter, NEW_VALUE is the new value. */
4152 void
4153 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4155 if (NILP (new_value))
4156 f->want_fullscreen = FULLSCREEN_NONE;
4157 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
4158 f->want_fullscreen = FULLSCREEN_BOTH;
4159 else if (EQ (new_value, Qfullwidth))
4160 f->want_fullscreen = FULLSCREEN_WIDTH;
4161 else if (EQ (new_value, Qfullheight))
4162 f->want_fullscreen = FULLSCREEN_HEIGHT;
4163 else if (EQ (new_value, Qmaximized))
4164 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
4166 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
4167 FRAME_TERMINAL (f)->fullscreen_hook (f);
4171 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
4172 the previous value of that parameter, NEW_VALUE is the new value. */
4174 void
4175 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4177 if (NILP (new_value))
4178 f->extra_line_spacing = 0;
4179 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
4180 f->extra_line_spacing = XFASTINT (new_value);
4181 else if (FLOATP (new_value))
4183 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
4185 if (new_spacing >= 0)
4186 f->extra_line_spacing = new_spacing;
4187 else
4188 signal_error ("Invalid line-spacing", new_value);
4190 else
4191 signal_error ("Invalid line-spacing", new_value);
4192 if (FRAME_VISIBLE_P (f))
4193 redraw_frame (f);
4197 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
4198 the previous value of that parameter, NEW_VALUE is the new value. */
4200 void
4201 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4203 Lisp_Object bgcolor;
4205 if (NILP (new_value))
4206 f->gamma = 0;
4207 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
4208 /* The value 0.4545 is the normal viewing gamma. */
4209 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
4210 else
4211 signal_error ("Invalid screen-gamma", new_value);
4213 /* Apply the new gamma value to the frame background. */
4214 bgcolor = Fassq (Qbackground_color, f->param_alist);
4215 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
4217 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
4218 if (NATNUMP (parm_index)
4219 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
4220 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
4221 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
4222 (f, bgcolor, Qnil);
4225 clear_face_cache (true); /* FIXME: Why of all frames? */
4226 fset_redisplay (f);
4230 void
4231 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4233 Lisp_Object font_object;
4234 int fontset = -1;
4235 #ifdef HAVE_X_WINDOWS
4236 Lisp_Object font_param = arg;
4237 #endif
4239 /* Set the frame parameter back to the old value because we may
4240 fail to use ARG as the new parameter value. */
4241 store_frame_param (f, Qfont, oldval);
4243 /* ARG is a fontset name, a font name, a cons of fontset name and a
4244 font object, or a font object. In the last case, this function
4245 never fail. */
4246 if (STRINGP (arg))
4248 fontset = fs_query_fontset (arg, 0);
4249 if (fontset < 0)
4251 font_object = font_open_by_name (f, arg);
4252 if (NILP (font_object))
4253 error ("Font `%s' is not defined", SSDATA (arg));
4254 arg = AREF (font_object, FONT_NAME_INDEX);
4256 else if (fontset > 0)
4258 font_object = font_open_by_name (f, fontset_ascii (fontset));
4259 if (NILP (font_object))
4260 error ("Font `%s' is not defined", SDATA (arg));
4261 arg = AREF (font_object, FONT_NAME_INDEX);
4263 else
4264 error ("The default fontset can't be used for a frame font");
4266 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
4268 /* This is the case that the ASCII font of F's fontset XCAR
4269 (arg) is changed to the font XCDR (arg) by
4270 `set-fontset-font'. */
4271 fontset = fs_query_fontset (XCAR (arg), 0);
4272 if (fontset < 0)
4273 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
4274 font_object = XCDR (arg);
4275 arg = AREF (font_object, FONT_NAME_INDEX);
4276 #ifdef HAVE_X_WINDOWS
4277 font_param = Ffont_get (font_object, QCname);
4278 #endif
4280 else if (FONT_OBJECT_P (arg))
4282 font_object = arg;
4283 #ifdef HAVE_X_WINDOWS
4284 font_param = Ffont_get (font_object, QCname);
4285 #endif
4286 /* This is to store the XLFD font name in the frame parameter for
4287 backward compatibility. We should store the font-object
4288 itself in the future. */
4289 arg = AREF (font_object, FONT_NAME_INDEX);
4290 fontset = FRAME_FONTSET (f);
4291 /* Check if we can use the current fontset. If not, set FONTSET
4292 to -1 to generate a new fontset from FONT-OBJECT. */
4293 if (fontset >= 0)
4295 Lisp_Object ascii_font = fontset_ascii (fontset);
4296 Lisp_Object spec = font_spec_from_name (ascii_font);
4298 /* SPEC might be nil because ASCII_FONT's name doesn't parse
4299 according to stupid XLFD rules, which, for example,
4300 disallow font names that include a dash followed by a
4301 number. So in those cases we simply request x_new_font
4302 below to generate a new fontset. */
4303 if (NILP (spec) || ! font_match_p (spec, font_object))
4304 fontset = -1;
4307 else
4308 signal_error ("Invalid font", arg);
4310 if (! NILP (Fequal (font_object, oldval)))
4311 return;
4313 x_new_font (f, font_object, fontset);
4314 store_frame_param (f, Qfont, arg);
4315 #ifdef HAVE_X_WINDOWS
4316 store_frame_param (f, Qfont_parameter, font_param);
4317 #endif
4318 /* Recalculate toolbar height. */
4319 f->n_tool_bar_rows = 0;
4321 /* Ensure we redraw it. */
4322 clear_current_matrices (f);
4324 /* Attempt to hunt down bug#16028. */
4325 SET_FRAME_GARBAGED (f);
4327 /* This is important if we are called by some Lisp as part of
4328 redisplaying the frame, see redisplay_internal. */
4329 f->fonts_changed = true;
4331 recompute_basic_faces (f);
4333 do_pending_window_change (0);
4335 /* We used to call face-set-after-frame-default here, but it leads to
4336 recursive calls (since that function can set the `default' face's
4337 font which in turns changes the frame's `font' parameter).
4338 Also I don't know what this call is meant to do, but it seems the
4339 wrong way to do it anyway (it does a lot more work than what seems
4340 reasonable in response to a change to `font'). */
4344 void
4345 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4347 if (! NILP (new_value)
4348 && !CONSP (new_value))
4350 char *p0, *p1;
4352 CHECK_STRING (new_value);
4353 p0 = p1 = SSDATA (new_value);
4354 new_value = Qnil;
4355 while (*p0)
4357 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
4358 if (p0 < p1)
4359 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
4360 new_value);
4361 if (*p1)
4363 int c;
4365 while ((c = *++p1) && c_isspace (c));
4367 p0 = p1;
4369 new_value = Fnreverse (new_value);
4372 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
4373 return;
4375 if (FRAME_FONT (f))
4376 free_all_realized_faces (Qnil);
4378 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
4379 if (NILP (new_value))
4381 if (NILP (old_value))
4382 error ("No font backend available");
4383 font_update_drivers (f, old_value);
4384 error ("None of specified font backends are available");
4386 store_frame_param (f, Qfont_backend, new_value);
4388 if (FRAME_FONT (f))
4390 Lisp_Object frame;
4392 XSETFRAME (frame, f);
4393 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
4394 face_change = true;
4395 windows_or_buffers_changed = 18;
4399 void
4400 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4402 int unit = FRAME_COLUMN_WIDTH (f);
4403 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
4404 int new_width;
4406 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
4407 ? eabs (XINT (new_value)) : 8);
4409 if (new_width != old_width)
4411 f->left_fringe_width = new_width;
4412 f->fringe_cols /* Round up. */
4413 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
4415 if (FRAME_X_WINDOW (f) != 0)
4416 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
4418 SET_FRAME_GARBAGED (f);
4423 void
4424 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4426 int unit = FRAME_COLUMN_WIDTH (f);
4427 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
4428 int new_width;
4430 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
4431 ? eabs (XINT (new_value)) : 8);
4433 if (new_width != old_width)
4435 f->right_fringe_width = new_width;
4436 f->fringe_cols /* Round up. */
4437 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
4439 if (FRAME_X_WINDOW (f) != 0)
4440 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
4442 SET_FRAME_GARBAGED (f);
4447 void
4448 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4450 CHECK_TYPE_RANGED_INTEGER (int, arg);
4452 if (XINT (arg) == f->border_width)
4453 return;
4455 if (FRAME_X_WINDOW (f) != 0)
4456 error ("Cannot change the border width of a frame");
4458 f->border_width = XINT (arg);
4461 void
4462 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4464 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
4465 CHECK_TYPE_RANGED_INTEGER (int, arg);
4466 int new = max (0, XINT (arg));
4467 if (new != old)
4469 f->right_divider_width = new;
4470 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
4471 adjust_frame_glyphs (f);
4472 SET_FRAME_GARBAGED (f);
4476 void
4477 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4479 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
4480 CHECK_TYPE_RANGED_INTEGER (int, arg);
4481 int new = max (0, XINT (arg));
4482 if (new != old)
4484 f->bottom_divider_width = new;
4485 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
4486 adjust_frame_glyphs (f);
4487 SET_FRAME_GARBAGED (f);
4491 void
4492 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
4494 Lisp_Object frame;
4495 XSETFRAME (frame, f);
4497 if (NILP (value))
4498 Fmake_frame_invisible (frame, Qt);
4499 else if (EQ (value, Qicon))
4500 Ficonify_frame (frame);
4501 else
4502 Fmake_frame_visible (frame);
4505 void
4506 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4508 f->auto_raise = !EQ (Qnil, arg);
4511 void
4512 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4514 f->auto_lower = !EQ (Qnil, arg);
4517 void
4518 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4520 f->no_split = !NILP (arg);
4523 void
4524 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4526 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
4527 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
4528 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4529 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
4531 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
4532 = (NILP (arg)
4533 ? vertical_scroll_bar_none
4534 : EQ (Qleft, arg)
4535 ? vertical_scroll_bar_left
4536 : EQ (Qright, arg)
4537 ? vertical_scroll_bar_right
4538 : EQ (Qleft, Vdefault_frame_scroll_bars)
4539 ? vertical_scroll_bar_left
4540 : EQ (Qright, Vdefault_frame_scroll_bars)
4541 ? vertical_scroll_bar_right
4542 : vertical_scroll_bar_none);
4544 /* We set this parameter before creating the X window for the
4545 frame, so we can get the geometry right from the start.
4546 However, if the window hasn't been created yet, we shouldn't
4547 call x_set_window_size. */
4548 if (FRAME_X_WINDOW (f))
4549 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
4551 SET_FRAME_GARBAGED (f);
4555 void
4556 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4558 #if USE_HORIZONTAL_SCROLL_BARS
4559 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
4560 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
4562 f->horizontal_scroll_bars = NILP (arg) ? false : true;
4564 /* We set this parameter before creating the X window for the
4565 frame, so we can get the geometry right from the start.
4566 However, if the window hasn't been created yet, we shouldn't
4567 call x_set_window_size. */
4568 if (FRAME_X_WINDOW (f))
4569 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
4571 SET_FRAME_GARBAGED (f);
4573 #endif
4576 void
4577 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4579 int unit = FRAME_COLUMN_WIDTH (f);
4581 if (NILP (arg))
4583 x_set_scroll_bar_default_width (f);
4585 if (FRAME_X_WINDOW (f))
4586 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
4588 SET_FRAME_GARBAGED (f);
4590 else if (RANGED_INTEGERP (1, arg, INT_MAX)
4591 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
4593 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
4594 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
4595 if (FRAME_X_WINDOW (f))
4596 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
4598 SET_FRAME_GARBAGED (f);
4601 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
4602 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
4605 void
4606 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4608 #if USE_HORIZONTAL_SCROLL_BARS
4609 int unit = FRAME_LINE_HEIGHT (f);
4611 if (NILP (arg))
4613 x_set_scroll_bar_default_height (f);
4615 if (FRAME_X_WINDOW (f))
4616 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
4618 SET_FRAME_GARBAGED (f);
4620 else if (RANGED_INTEGERP (1, arg, INT_MAX)
4621 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
4623 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
4624 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
4625 if (FRAME_X_WINDOW (f))
4626 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
4628 SET_FRAME_GARBAGED (f);
4631 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
4632 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
4633 #endif
4636 void
4637 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4639 double alpha = 1.0;
4640 double newval[2];
4641 int i;
4642 Lisp_Object item;
4644 for (i = 0; i < 2; i++)
4646 newval[i] = 1.0;
4647 if (CONSP (arg))
4649 item = CAR (arg);
4650 arg = CDR (arg);
4652 else
4653 item = arg;
4655 if (NILP (item))
4656 alpha = - 1.0;
4657 else if (FLOATP (item))
4659 alpha = XFLOAT_DATA (item);
4660 if (! (0 <= alpha && alpha <= 1.0))
4661 args_out_of_range (make_float (0.0), make_float (1.0));
4663 else if (INTEGERP (item))
4665 EMACS_INT ialpha = XINT (item);
4666 if (! (0 <= ialpha && ialpha <= 100))
4667 args_out_of_range (make_number (0), make_number (100));
4668 alpha = ialpha / 100.0;
4670 else
4671 wrong_type_argument (Qnumberp, item);
4672 newval[i] = alpha;
4675 for (i = 0; i < 2; i++)
4676 f->alpha[i] = newval[i];
4678 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4679 block_input ();
4680 x_set_frame_alpha (f);
4681 unblock_input ();
4682 #endif
4684 return;
4689 * x_set_no_special_glyphs:
4691 * Set frame F's `no-special-glyphs' parameter which, if non-nil,
4692 * suppresses the display of truncation and continuation glyphs
4693 * outside fringes.
4695 void
4696 x_set_no_special_glyphs (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4698 if (!EQ (new_value, old_value))
4699 FRAME_NO_SPECIAL_GLYPHS (f) = !NILP (new_value);
4703 #ifndef HAVE_NS
4705 /* Non-zero if mouse is grabbed on DPYINFO
4706 and we know the frame where it is. */
4708 bool x_mouse_grabbed (Display_Info *dpyinfo)
4710 return (dpyinfo->grabbed
4711 && dpyinfo->last_mouse_frame
4712 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4715 /* Re-highlight something with mouse-face properties
4716 on DPYINFO using saved frame and mouse position. */
4718 void
4719 x_redo_mouse_highlight (Display_Info *dpyinfo)
4721 if (dpyinfo->last_mouse_motion_frame
4722 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4723 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4724 dpyinfo->last_mouse_motion_x,
4725 dpyinfo->last_mouse_motion_y);
4728 #endif /* HAVE_NS */
4730 /* Subroutines of creating an X frame. */
4732 /* Make sure that Vx_resource_name is set to a reasonable value.
4733 Fix it up, or set it to `emacs' if it is too hopeless. */
4735 void
4736 validate_x_resource_name (void)
4738 ptrdiff_t len = 0;
4739 /* Number of valid characters in the resource name. */
4740 ptrdiff_t good_count = 0;
4741 /* Number of invalid characters in the resource name. */
4742 ptrdiff_t bad_count = 0;
4743 Lisp_Object new;
4744 ptrdiff_t i;
4746 if (!STRINGP (Vx_resource_class))
4747 Vx_resource_class = build_string (EMACS_CLASS);
4749 if (STRINGP (Vx_resource_name))
4751 unsigned char *p = SDATA (Vx_resource_name);
4753 len = SBYTES (Vx_resource_name);
4755 /* Only letters, digits, - and _ are valid in resource names.
4756 Count the valid characters and count the invalid ones. */
4757 for (i = 0; i < len; i++)
4759 int c = p[i];
4760 if (! ((c >= 'a' && c <= 'z')
4761 || (c >= 'A' && c <= 'Z')
4762 || (c >= '0' && c <= '9')
4763 || c == '-' || c == '_'))
4764 bad_count++;
4765 else
4766 good_count++;
4769 else
4770 /* Not a string => completely invalid. */
4771 bad_count = 5, good_count = 0;
4773 /* If name is valid already, return. */
4774 if (bad_count == 0)
4775 return;
4777 /* If name is entirely invalid, or nearly so, or is so implausibly
4778 large that alloca might not work, use `emacs'. */
4779 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4781 Vx_resource_name = build_string ("emacs");
4782 return;
4785 /* Name is partly valid. Copy it and replace the invalid characters
4786 with underscores. */
4788 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4790 for (i = 0; i < len; i++)
4792 int c = SREF (new, i);
4793 if (! ((c >= 'a' && c <= 'z')
4794 || (c >= 'A' && c <= 'Z')
4795 || (c >= '0' && c <= '9')
4796 || c == '-' || c == '_'))
4797 SSET (new, i, '_');
4801 /* Get specified attribute from resource database RDB.
4802 See Fx_get_resource below for other parameters. */
4804 static Lisp_Object
4805 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4807 CHECK_STRING (attribute);
4808 CHECK_STRING (class);
4810 if (!NILP (component))
4811 CHECK_STRING (component);
4812 if (!NILP (subclass))
4813 CHECK_STRING (subclass);
4814 if (NILP (component) != NILP (subclass))
4815 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4817 validate_x_resource_name ();
4819 /* Allocate space for the components, the dots which separate them,
4820 and the final '\0'. Make them big enough for the worst case. */
4821 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4822 + (STRINGP (component)
4823 ? SBYTES (component) : 0)
4824 + SBYTES (attribute)
4825 + 3);
4827 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4828 + SBYTES (class)
4829 + (STRINGP (subclass)
4830 ? SBYTES (subclass) : 0)
4831 + 3);
4832 USE_SAFE_ALLOCA;
4833 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4834 char *class_key = name_key + name_keysize;
4836 /* Start with emacs.FRAMENAME for the name (the specific one)
4837 and with `Emacs' for the class key (the general one). */
4838 char *nz = lispstpcpy (name_key, Vx_resource_name);
4839 char *cz = lispstpcpy (class_key, Vx_resource_class);
4841 *cz++ = '.';
4842 cz = lispstpcpy (cz, class);
4844 if (!NILP (component))
4846 *cz++ = '.';
4847 lispstpcpy (cz, subclass);
4849 *nz++ = '.';
4850 nz = lispstpcpy (nz, component);
4853 *nz++ = '.';
4854 lispstpcpy (nz, attribute);
4856 char *value = x_get_string_resource (rdb, name_key, class_key);
4857 SAFE_FREE();
4859 if (value && *value)
4860 return build_string (value);
4861 else
4862 return Qnil;
4866 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4867 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4868 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4869 class, where INSTANCE is the name under which Emacs was invoked, or
4870 the name specified by the `-name' or `-rn' command-line arguments.
4872 The optional arguments COMPONENT and SUBCLASS add to the key and the
4873 class, respectively. You must specify both of them or neither.
4874 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4875 and the class is `Emacs.CLASS.SUBCLASS'. */)
4876 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4877 Lisp_Object subclass)
4879 check_window_system (NULL);
4881 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4882 attribute, class, component, subclass);
4885 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4887 Lisp_Object
4888 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4889 Lisp_Object class, Lisp_Object component,
4890 Lisp_Object subclass)
4892 return xrdb_get_resource (dpyinfo->xrdb,
4893 attribute, class, component, subclass);
4896 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4897 /* Used when C code wants a resource value. */
4898 /* Called from oldXMenu/Create.c. */
4899 char *
4900 x_get_resource_string (const char *attribute, const char *class)
4902 char *result;
4903 struct frame *sf = SELECTED_FRAME ();
4904 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4905 USE_SAFE_ALLOCA;
4907 /* Allocate space for the components, the dots which separate them,
4908 and the final '\0'. */
4909 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4910 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4911 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4912 char *class_key = name_key + name_keysize;
4914 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4915 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4917 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4918 name_key, class_key);
4919 SAFE_FREE ();
4920 return result;
4922 #endif
4924 /* Return the value of parameter PARAM.
4926 First search ALIST, then Vdefault_frame_alist, then the X defaults
4927 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4929 Convert the resource to the type specified by desired_type.
4931 If no default is specified, return Qunbound. If you call
4932 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4933 and don't let it get stored in any Lisp-visible variables! */
4935 Lisp_Object
4936 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4937 const char *attribute, const char *class, enum resource_types type)
4939 Lisp_Object tem;
4941 tem = Fassq (param, alist);
4943 if (!NILP (tem))
4945 /* If we find this parm in ALIST, clear it out
4946 so that it won't be "left over" at the end. */
4947 Lisp_Object tail;
4948 XSETCAR (tem, Qnil);
4949 /* In case the parameter appears more than once in the alist,
4950 clear it out. */
4951 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4952 if (CONSP (XCAR (tail))
4953 && EQ (XCAR (XCAR (tail)), param))
4954 XSETCAR (XCAR (tail), Qnil);
4956 else
4957 tem = Fassq (param, Vdefault_frame_alist);
4959 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4960 look in the X resources. */
4961 if (EQ (tem, Qnil))
4963 if (attribute && dpyinfo)
4965 AUTO_STRING (at, attribute);
4966 AUTO_STRING (cl, class);
4967 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4969 if (NILP (tem))
4970 return Qunbound;
4972 switch (type)
4974 case RES_TYPE_NUMBER:
4975 return make_number (atoi (SSDATA (tem)));
4977 case RES_TYPE_BOOLEAN_NUMBER:
4978 if (!strcmp (SSDATA (tem), "on")
4979 || !strcmp (SSDATA (tem), "true"))
4980 return make_number (1);
4981 return make_number (atoi (SSDATA (tem)));
4982 break;
4984 case RES_TYPE_FLOAT:
4985 return make_float (atof (SSDATA (tem)));
4987 case RES_TYPE_BOOLEAN:
4988 tem = Fdowncase (tem);
4989 if (!strcmp (SSDATA (tem), "on")
4990 #ifdef HAVE_NS
4991 || !strcmp (SSDATA (tem), "yes")
4992 #endif
4993 || !strcmp (SSDATA (tem), "true"))
4994 return Qt;
4995 else
4996 return Qnil;
4998 case RES_TYPE_STRING:
4999 return tem;
5001 case RES_TYPE_SYMBOL:
5002 /* As a special case, we map the values `true' and `on'
5003 to Qt, and `false' and `off' to Qnil. */
5005 Lisp_Object lower;
5006 lower = Fdowncase (tem);
5007 if (!strcmp (SSDATA (lower), "on")
5008 #ifdef HAVE_NS
5009 || !strcmp (SSDATA (lower), "yes")
5010 #endif
5011 || !strcmp (SSDATA (lower), "true"))
5012 return Qt;
5013 else if (!strcmp (SSDATA (lower), "off")
5014 #ifdef HAVE_NS
5015 || !strcmp (SSDATA (lower), "no")
5016 #endif
5017 || !strcmp (SSDATA (lower), "false"))
5018 return Qnil;
5019 else
5020 return Fintern (tem, Qnil);
5023 default:
5024 emacs_abort ();
5027 else
5028 return Qunbound;
5030 return Fcdr (tem);
5033 static Lisp_Object
5034 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
5035 const char *attribute, const char *class,
5036 enum resource_types type)
5038 return x_get_arg (FRAME_DISPLAY_INFO (f),
5039 alist, param, attribute, class, type);
5042 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
5044 Lisp_Object
5045 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
5046 Lisp_Object param,
5047 const char *attribute, const char *class,
5048 enum resource_types type)
5050 Lisp_Object value;
5052 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
5053 attribute, class, type);
5054 if (! NILP (value) && ! EQ (value, Qunbound))
5055 store_frame_param (f, param, value);
5057 return value;
5061 /* Record in frame F the specified or default value according to ALIST
5062 of the parameter named PROP (a Lisp symbol).
5063 If no value is specified for PROP, look for an X default for XPROP
5064 on the frame named NAME.
5065 If that is not found either, use the value DEFLT. */
5067 Lisp_Object
5068 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
5069 Lisp_Object deflt, const char *xprop, const char *xclass,
5070 enum resource_types type)
5072 Lisp_Object tem;
5074 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
5075 if (EQ (tem, Qunbound))
5076 tem = deflt;
5077 AUTO_FRAME_ARG (arg, prop, tem);
5078 x_set_frame_parameters (f, arg);
5079 return tem;
5083 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
5086 * XParseGeometry parses strings of the form
5087 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
5088 * width, height, xoffset, and yoffset are unsigned integers.
5089 * Example: "=80x24+300-49"
5090 * The equal sign is optional.
5091 * It returns a bitmask that indicates which of the four values
5092 * were actually found in the string. For each value found,
5093 * the corresponding argument is updated; for each value
5094 * not found, the corresponding argument is left unchanged.
5097 static int
5098 XParseGeometry (char *string,
5099 int *x, int *y,
5100 unsigned int *width, unsigned int *height)
5102 int mask = NoValue;
5103 char *strind;
5104 unsigned long tempWidth UNINIT, tempHeight UNINIT;
5105 long int tempX UNINIT, tempY UNINIT;
5106 char *nextCharacter;
5108 if (string == NULL || *string == '\0')
5109 return mask;
5110 if (*string == '=')
5111 string++; /* ignore possible '=' at beg of geometry spec */
5113 strind = string;
5114 if (*strind != '+' && *strind != '-' && *strind != 'x')
5116 tempWidth = strtoul (strind, &nextCharacter, 10);
5117 if (strind == nextCharacter)
5118 return 0;
5119 strind = nextCharacter;
5120 mask |= WidthValue;
5123 if (*strind == 'x' || *strind == 'X')
5125 strind++;
5126 tempHeight = strtoul (strind, &nextCharacter, 10);
5127 if (strind == nextCharacter)
5128 return 0;
5129 strind = nextCharacter;
5130 mask |= HeightValue;
5133 if (*strind == '+' || *strind == '-')
5135 if (*strind == '-')
5136 mask |= XNegative;
5137 tempX = strtol (strind, &nextCharacter, 10);
5138 if (strind == nextCharacter)
5139 return 0;
5140 strind = nextCharacter;
5141 mask |= XValue;
5142 if (*strind == '+' || *strind == '-')
5144 if (*strind == '-')
5145 mask |= YNegative;
5146 tempY = strtol (strind, &nextCharacter, 10);
5147 if (strind == nextCharacter)
5148 return 0;
5149 strind = nextCharacter;
5150 mask |= YValue;
5154 /* If strind isn't at the end of the string then it's an invalid
5155 geometry specification. */
5157 if (*strind != '\0')
5158 return 0;
5160 if (mask & XValue)
5161 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
5162 if (mask & YValue)
5163 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
5164 if (mask & WidthValue)
5165 *width = min (tempWidth, UINT_MAX);
5166 if (mask & HeightValue)
5167 *height = min (tempHeight, UINT_MAX);
5168 return mask;
5171 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
5174 /* NS used to define x-parse-geometry in ns-win.el, but that confused
5175 make-docfile: the documentation string in ns-win.el was used for
5176 x-parse-geometry even in non-NS builds.
5178 With two definitions of x-parse-geometry in this file, various
5179 things still get confused (eg M-x apropos documentation), so that
5180 it is best if the two definitions just share the same doc-string.
5182 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
5183 doc: /* Parse a display geometry string STRING.
5184 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
5185 The properties returned may include `top', `left', `height', and `width'.
5186 For X, the value of `left' or `top' may be an integer,
5187 or a list (+ N) meaning N pixels relative to top/left corner,
5188 or a list (- N) meaning -N pixels relative to bottom/right corner.
5189 On Nextstep, this just calls `ns-parse-geometry'. */)
5190 (Lisp_Object string)
5192 int geometry, x, y;
5193 unsigned int width, height;
5194 Lisp_Object result;
5196 CHECK_STRING (string);
5198 #ifdef HAVE_NS
5199 if (strchr (SSDATA (string), ' ') != NULL)
5200 return call1 (Qns_parse_geometry, string);
5201 #endif
5202 geometry = XParseGeometry (SSDATA (string),
5203 &x, &y, &width, &height);
5204 result = Qnil;
5205 if (geometry & XValue)
5207 Lisp_Object element;
5209 if (x >= 0 && (geometry & XNegative))
5210 element = list3 (Qleft, Qminus, make_number (-x));
5211 else if (x < 0 && ! (geometry & XNegative))
5212 element = list3 (Qleft, Qplus, make_number (x));
5213 else
5214 element = Fcons (Qleft, make_number (x));
5215 result = Fcons (element, result);
5218 if (geometry & YValue)
5220 Lisp_Object element;
5222 if (y >= 0 && (geometry & YNegative))
5223 element = list3 (Qtop, Qminus, make_number (-y));
5224 else if (y < 0 && ! (geometry & YNegative))
5225 element = list3 (Qtop, Qplus, make_number (y));
5226 else
5227 element = Fcons (Qtop, make_number (y));
5228 result = Fcons (element, result);
5231 if (geometry & WidthValue)
5232 result = Fcons (Fcons (Qwidth, make_number (width)), result);
5233 if (geometry & HeightValue)
5234 result = Fcons (Fcons (Qheight, make_number (height)), result);
5236 return result;
5240 /* Calculate the desired size and position of frame F.
5241 Return the flags saying which aspects were specified.
5243 Also set the win_gravity and size_hint_flags of F.
5245 Adjust height for toolbar if TOOLBAR_P is 1.
5247 This function does not make the coordinates positive. */
5249 #define DEFAULT_ROWS 36
5250 #define DEFAULT_COLS 80
5252 long
5253 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
5255 Lisp_Object height, width, user_size, top, left, user_position;
5256 long window_prompting = 0;
5257 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
5258 int parent_done = -1, outer_done = -1;
5260 /* Default values if we fall through.
5261 Actually, if that happens we should get
5262 window manager prompting. */
5263 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
5264 SET_FRAME_COLS (f, DEFAULT_COLS);
5265 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
5266 SET_FRAME_LINES (f, DEFAULT_ROWS);
5268 /* Window managers expect that if program-specified
5269 positions are not (0,0), they're intentional, not defaults. */
5270 f->top_pos = 0;
5271 f->left_pos = 0;
5273 /* Calculate a tool bar height so that the user gets a text display
5274 area of the size he specified with -g or via .Xdefaults. Later
5275 changes of the tool bar height don't change the frame size. This
5276 is done so that users can create tall Emacs frames without having
5277 to guess how tall the tool bar will get. */
5278 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
5280 if (frame_default_tool_bar_height)
5281 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
5282 else
5284 int margin, relief;
5286 relief = (tool_bar_button_relief >= 0
5287 ? tool_bar_button_relief
5288 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
5290 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
5291 margin = XFASTINT (Vtool_bar_button_margin);
5292 else if (CONSP (Vtool_bar_button_margin)
5293 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
5294 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
5295 else
5296 margin = 0;
5298 FRAME_TOOL_BAR_HEIGHT (f)
5299 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
5303 /* Ensure that earlier new_width and new_height settings won't
5304 override what we specify below. */
5305 f->new_width = f->new_height = 0;
5307 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
5308 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
5309 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
5311 if (!EQ (width, Qunbound))
5313 if (CONSP (width) && EQ (XCAR (width), Qtext_pixels))
5315 CHECK_NUMBER (XCDR (width));
5316 if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX))
5317 xsignal1 (Qargs_out_of_range, XCDR (width));
5319 SET_FRAME_WIDTH (f, XINT (XCDR (width)));
5320 f->inhibit_horizontal_resize = true;
5321 *x_width = XINT (XCDR (width));
5323 else if (FLOATP (width))
5325 double d_width = XFLOAT_DATA (width);
5327 if (d_width < 0.0 || d_width > 1.0)
5328 xsignal1 (Qargs_out_of_range, width);
5329 else
5331 int new_width = frame_float (f, width, FRAME_FLOAT_WIDTH,
5332 &parent_done, &outer_done, -1);
5334 if (new_width > -1)
5335 SET_FRAME_WIDTH (f, new_width);
5338 else
5340 CHECK_NUMBER (width);
5341 if ((XINT (width) < 0 || XINT (width) > INT_MAX))
5342 xsignal1 (Qargs_out_of_range, width);
5344 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
5348 if (!EQ (height, Qunbound))
5350 if (CONSP (height) && EQ (XCAR (height), Qtext_pixels))
5352 CHECK_NUMBER (XCDR (height));
5353 if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX))
5354 xsignal1 (Qargs_out_of_range, XCDR (height));
5356 SET_FRAME_HEIGHT (f, XINT (XCDR (height)));
5357 f->inhibit_vertical_resize = true;
5358 *x_height = XINT (XCDR (height));
5360 else if (FLOATP (height))
5362 double d_height = XFLOAT_DATA (height);
5364 if (d_height < 0.0 || d_height > 1.0)
5365 xsignal1 (Qargs_out_of_range, height);
5366 else
5368 int new_height = frame_float (f, height, FRAME_FLOAT_HEIGHT,
5369 &parent_done, &outer_done, -1);
5371 if (new_height > -1)
5372 SET_FRAME_HEIGHT (f, new_height);
5375 else
5377 CHECK_NUMBER (height);
5378 if ((XINT (height) < 0) || (XINT (height) > INT_MAX))
5379 xsignal1 (Qargs_out_of_range, height);
5381 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
5385 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
5386 if (!NILP (user_size) && !EQ (user_size, Qunbound))
5387 window_prompting |= USSize;
5388 else
5389 window_prompting |= PSize;
5392 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
5393 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
5394 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
5395 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
5397 if (EQ (top, Qminus))
5399 f->top_pos = 0;
5400 window_prompting |= YNegative;
5402 else if (CONSP (top) && EQ (XCAR (top), Qminus)
5403 && CONSP (XCDR (top))
5404 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
5406 f->top_pos = - XINT (XCAR (XCDR (top)));
5407 window_prompting |= YNegative;
5409 else if (CONSP (top) && EQ (XCAR (top), Qplus)
5410 && CONSP (XCDR (top))
5411 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
5413 f->top_pos = XINT (XCAR (XCDR (top)));
5415 else if (FLOATP (top))
5416 f->top_pos = frame_float (f, top, FRAME_FLOAT_TOP, &parent_done,
5417 &outer_done, 0);
5418 else if (EQ (top, Qunbound))
5419 f->top_pos = 0;
5420 else
5422 CHECK_TYPE_RANGED_INTEGER (int, top);
5423 f->top_pos = XINT (top);
5424 if (f->top_pos < 0)
5425 window_prompting |= YNegative;
5428 if (EQ (left, Qminus))
5430 f->left_pos = 0;
5431 window_prompting |= XNegative;
5433 else if (CONSP (left) && EQ (XCAR (left), Qminus)
5434 && CONSP (XCDR (left))
5435 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
5437 f->left_pos = - XINT (XCAR (XCDR (left)));
5438 window_prompting |= XNegative;
5440 else if (CONSP (left) && EQ (XCAR (left), Qplus)
5441 && CONSP (XCDR (left))
5442 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
5444 f->left_pos = XINT (XCAR (XCDR (left)));
5446 else if (FLOATP (left))
5447 f->left_pos = frame_float (f, left, FRAME_FLOAT_LEFT, &parent_done,
5448 &outer_done, 0);
5449 else if (EQ (left, Qunbound))
5450 f->left_pos = 0;
5451 else
5453 CHECK_TYPE_RANGED_INTEGER (int, left);
5454 f->left_pos = XINT (left);
5455 if (f->left_pos < 0)
5456 window_prompting |= XNegative;
5459 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
5460 window_prompting |= USPosition;
5461 else
5462 window_prompting |= PPosition;
5465 if (window_prompting & XNegative)
5467 if (window_prompting & YNegative)
5468 f->win_gravity = SouthEastGravity;
5469 else
5470 f->win_gravity = NorthEastGravity;
5472 else
5474 if (window_prompting & YNegative)
5475 f->win_gravity = SouthWestGravity;
5476 else
5477 f->win_gravity = NorthWestGravity;
5480 f->size_hint_flags = window_prompting;
5482 return window_prompting;
5487 #endif /* HAVE_WINDOW_SYSTEM */
5489 void
5490 frame_make_pointer_invisible (struct frame *f)
5492 if (! NILP (Vmake_pointer_invisible))
5494 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
5495 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
5497 f->mouse_moved = 0;
5498 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
5499 f->pointer_invisible = 1;
5504 void
5505 frame_make_pointer_visible (struct frame *f)
5507 /* We don't check Vmake_pointer_invisible here in case the
5508 pointer was invisible when Vmake_pointer_invisible was set to nil. */
5509 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
5510 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
5512 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
5513 f->pointer_invisible = 0;
5517 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
5518 Sframe_pointer_visible_p, 0, 1, 0,
5519 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
5520 Otherwise it returns nil. FRAME omitted or nil means the
5521 selected frame. This is useful when `make-pointer-invisible' is set. */)
5522 (Lisp_Object frame)
5524 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
5529 /***********************************************************************
5530 Multimonitor data
5531 ***********************************************************************/
5533 #ifdef HAVE_WINDOW_SYSTEM
5535 # if (defined HAVE_NS \
5536 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
5537 void
5538 free_monitors (struct MonitorInfo *monitors, int n_monitors)
5540 int i;
5541 for (i = 0; i < n_monitors; ++i)
5542 xfree (monitors[i].name);
5543 xfree (monitors);
5545 # endif
5547 Lisp_Object
5548 make_monitor_attribute_list (struct MonitorInfo *monitors,
5549 int n_monitors,
5550 int primary_monitor,
5551 Lisp_Object monitor_frames,
5552 const char *source)
5554 Lisp_Object attributes_list = Qnil;
5555 Lisp_Object primary_monitor_attributes = Qnil;
5556 int i;
5558 for (i = 0; i < n_monitors; ++i)
5560 Lisp_Object geometry, workarea, attributes = Qnil;
5561 struct MonitorInfo *mi = &monitors[i];
5563 if (mi->geom.width == 0) continue;
5565 workarea = list4i (mi->work.x, mi->work.y,
5566 mi->work.width, mi->work.height);
5567 geometry = list4i (mi->geom.x, mi->geom.y,
5568 mi->geom.width, mi->geom.height);
5569 attributes = Fcons (Fcons (Qsource, build_string (source)),
5570 attributes);
5571 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
5572 attributes);
5573 attributes = Fcons (Fcons (Qmm_size,
5574 list2i (mi->mm_width, mi->mm_height)),
5575 attributes);
5576 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
5577 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
5578 if (mi->name)
5579 attributes = Fcons (Fcons (Qname, make_string (mi->name,
5580 strlen (mi->name))),
5581 attributes);
5583 if (i == primary_monitor)
5584 primary_monitor_attributes = attributes;
5585 else
5586 attributes_list = Fcons (attributes, attributes_list);
5589 if (!NILP (primary_monitor_attributes))
5590 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
5591 return attributes_list;
5594 #endif /* HAVE_WINDOW_SYSTEM */
5597 /***********************************************************************
5598 Initialization
5599 ***********************************************************************/
5601 void
5602 syms_of_frame (void)
5604 DEFSYM (Qframep, "framep");
5605 DEFSYM (Qframe_live_p, "frame-live-p");
5606 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
5607 DEFSYM (Qdisplay_monitor_attributes_list, "display-monitor-attributes-list");
5608 DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total");
5609 DEFSYM (Qexplicit_name, "explicit-name");
5610 DEFSYM (Qheight, "height");
5611 DEFSYM (Qicon, "icon");
5612 DEFSYM (Qminibuffer, "minibuffer");
5613 DEFSYM (Qundecorated, "undecorated");
5614 DEFSYM (Qno_special_glyphs, "no-special-glyphs");
5615 DEFSYM (Qparent_frame, "parent-frame");
5616 DEFSYM (Qskip_taskbar, "skip-taskbar");
5617 DEFSYM (Qno_focus_on_map, "no-focus-on-map");
5618 DEFSYM (Qno_accept_focus, "no-accept-focus");
5619 DEFSYM (Qz_group, "z-group");
5620 DEFSYM (Qoverride_redirect, "override-redirect");
5621 DEFSYM (Qdelete_before, "delete-before");
5622 DEFSYM (Qmodeline, "modeline");
5623 DEFSYM (Qonly, "only");
5624 DEFSYM (Qnone, "none");
5625 DEFSYM (Qwidth, "width");
5626 DEFSYM (Qtext_pixels, "text-pixels");
5627 DEFSYM (Qgeometry, "geometry");
5628 DEFSYM (Qicon_left, "icon-left");
5629 DEFSYM (Qicon_top, "icon-top");
5630 DEFSYM (Qtooltip, "tooltip");
5631 DEFSYM (Quser_position, "user-position");
5632 DEFSYM (Quser_size, "user-size");
5633 DEFSYM (Qwindow_id, "window-id");
5634 #ifdef HAVE_X_WINDOWS
5635 DEFSYM (Qouter_window_id, "outer-window-id");
5636 #endif
5637 DEFSYM (Qparent_id, "parent-id");
5638 DEFSYM (Qx, "x");
5639 DEFSYM (Qw32, "w32");
5640 DEFSYM (Qpc, "pc");
5641 DEFSYM (Qns, "ns");
5642 DEFSYM (Qvisible, "visible");
5643 DEFSYM (Qbuffer_predicate, "buffer-predicate");
5644 DEFSYM (Qbuffer_list, "buffer-list");
5645 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
5646 DEFSYM (Qdisplay_type, "display-type");
5647 DEFSYM (Qbackground_mode, "background-mode");
5648 DEFSYM (Qnoelisp, "noelisp");
5649 DEFSYM (Qtty_color_mode, "tty-color-mode");
5650 DEFSYM (Qtty, "tty");
5651 DEFSYM (Qtty_type, "tty-type");
5653 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
5655 DEFSYM (Qfullwidth, "fullwidth");
5656 DEFSYM (Qfullheight, "fullheight");
5657 DEFSYM (Qfullboth, "fullboth");
5658 DEFSYM (Qmaximized, "maximized");
5659 DEFSYM (Qx_resource_name, "x-resource-name");
5660 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
5662 DEFSYM (Qworkarea, "workarea");
5663 DEFSYM (Qmm_size, "mm-size");
5664 DEFSYM (Qframes, "frames");
5665 DEFSYM (Qsource, "source");
5667 DEFSYM (Qframe_edges, "frame-edges");
5668 DEFSYM (Qouter_edges, "outer-edges");
5669 DEFSYM (Qouter_position, "outer-position");
5670 DEFSYM (Qouter_size, "outer-size");
5671 DEFSYM (Qnative_edges, "native-edges");
5672 DEFSYM (Qinner_edges, "inner-edges");
5673 DEFSYM (Qexternal_border_size, "external-border-size");
5674 DEFSYM (Qtitle_bar_size, "title-bar-size");
5675 DEFSYM (Qmenu_bar_external, "menu-bar-external");
5676 DEFSYM (Qmenu_bar_size, "menu-bar-size");
5677 DEFSYM (Qtool_bar_external, "tool-bar-external");
5678 DEFSYM (Qtool_bar_size, "tool-bar-size");
5679 /* The following are used for frame_size_history. */
5680 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
5681 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
5682 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
5683 DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
5684 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
5685 DEFSYM (Qset_frame_size, "set-frame-size");
5686 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
5687 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
5688 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
5689 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
5690 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
5691 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
5692 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
5693 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
5694 DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
5695 DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
5696 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
5697 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
5698 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
5699 DEFSYM (Qtb_size_cb, "tb-size-cb");
5700 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
5701 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
5702 DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines");
5703 DEFSYM (Qchange_frame_size, "change-frame-size");
5704 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
5705 DEFSYM (Qset_window_configuration, "set-window-configuration");
5706 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
5707 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
5708 DEFSYM (Qterminal_frame, "terminal-frame");
5710 #ifdef HAVE_NS
5711 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
5712 #endif
5713 #ifdef NS_IMPL_COCOA
5714 DEFSYM (Qns_appearance, "ns-appearance");
5715 DEFSYM (Qns_transparent_titlebar, "ns-transparent-titlebar");
5716 #endif
5718 DEFSYM (Qalpha, "alpha");
5719 DEFSYM (Qauto_lower, "auto-lower");
5720 DEFSYM (Qauto_raise, "auto-raise");
5721 DEFSYM (Qborder_color, "border-color");
5722 DEFSYM (Qborder_width, "border-width");
5723 DEFSYM (Qouter_border_width, "outer-border-width");
5724 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
5725 DEFSYM (Qcursor_color, "cursor-color");
5726 DEFSYM (Qcursor_type, "cursor-type");
5727 DEFSYM (Qfont_backend, "font-backend");
5728 DEFSYM (Qfullscreen, "fullscreen");
5729 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
5730 DEFSYM (Qicon_name, "icon-name");
5731 DEFSYM (Qicon_type, "icon-type");
5732 DEFSYM (Qinternal_border_width, "internal-border-width");
5733 DEFSYM (Qleft_fringe, "left-fringe");
5734 DEFSYM (Qline_spacing, "line-spacing");
5735 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
5736 DEFSYM (Qupdate_frame_menubar, "update-frame-menubar");
5737 DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1");
5738 DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2");
5739 DEFSYM (Qmouse_color, "mouse-color");
5740 DEFSYM (Qname, "name");
5741 DEFSYM (Qright_divider_width, "right-divider-width");
5742 DEFSYM (Qright_fringe, "right-fringe");
5743 DEFSYM (Qscreen_gamma, "screen-gamma");
5744 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
5745 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
5746 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
5747 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
5748 DEFSYM (Qsticky, "sticky");
5749 DEFSYM (Qtitle, "title");
5750 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
5751 DEFSYM (Qtool_bar_position, "tool-bar-position");
5752 DEFSYM (Qunsplittable, "unsplittable");
5753 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
5754 DEFSYM (Qvisibility, "visibility");
5755 DEFSYM (Qwait_for_wm, "wait-for-wm");
5756 DEFSYM (Qinhibit_double_buffering, "inhibit-double-buffering");
5757 DEFSYM (Qno_other_frame, "no-other-frame");
5758 DEFSYM (Qbelow, "below");
5759 DEFSYM (Qabove_suspended, "above-suspended");
5760 DEFSYM (Qmin_width, "min-width");
5761 DEFSYM (Qmin_height, "min-height");
5762 DEFSYM (Qmouse_wheel_frame, "mouse-wheel-frame");
5763 DEFSYM (Qkeep_ratio, "keep-ratio");
5764 DEFSYM (Qwidth_only, "width-only");
5765 DEFSYM (Qheight_only, "height-only");
5766 DEFSYM (Qleft_only, "left-only");
5767 DEFSYM (Qtop_only, "top-only");
5768 DEFSYM (Qiconify_top_level, "iconify-top-level");
5769 DEFSYM (Qmake_invisible, "make-invisible");
5772 int i;
5774 for (i = 0; i < ARRAYELTS (frame_parms); i++)
5776 Lisp_Object v = (frame_parms[i].sym < 0
5777 ? intern_c_string (frame_parms[i].name)
5778 : builtin_lisp_symbol (frame_parms[i].sym));
5779 Fput (v, Qx_frame_parameter, make_number (i));
5783 #ifdef HAVE_WINDOW_SYSTEM
5784 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
5785 doc: /* The name Emacs uses to look up X resources.
5786 `x-get-resource' uses this as the first component of the instance name
5787 when requesting resource values.
5788 Emacs initially sets `x-resource-name' to the name under which Emacs
5789 was invoked, or to the value specified with the `-name' or `-rn'
5790 switches, if present.
5792 It may be useful to bind this variable locally around a call
5793 to `x-get-resource'. See also the variable `x-resource-class'. */);
5794 Vx_resource_name = Qnil;
5796 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5797 doc: /* The class Emacs uses to look up X resources.
5798 `x-get-resource' uses this as the first component of the instance class
5799 when requesting resource values.
5801 Emacs initially sets `x-resource-class' to "Emacs".
5803 Setting this variable permanently is not a reasonable thing to do,
5804 but binding this variable locally around a call to `x-get-resource'
5805 is a reasonable practice. See also the variable `x-resource-name'. */);
5806 Vx_resource_class = build_string (EMACS_CLASS);
5808 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5809 doc: /* The lower limit of the frame opacity (alpha transparency).
5810 The value should range from 0 (invisible) to 100 (completely opaque).
5811 You can also use a floating number between 0.0 and 1.0. */);
5812 Vframe_alpha_lower_limit = make_number (20);
5813 #endif
5815 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5816 doc: /* Alist of default values for frame creation.
5817 These may be set in your init file, like this:
5818 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5819 These override values given in window system configuration data,
5820 including X Windows' defaults database.
5821 For values specific to the first Emacs frame, see `initial-frame-alist'.
5822 For window-system specific values, see `window-system-default-frame-alist'.
5823 For values specific to the separate minibuffer frame, see
5824 `minibuffer-frame-alist'.
5825 The `menu-bar-lines' element of the list controls whether new frames
5826 have menu bars; `menu-bar-mode' works by altering this element.
5827 Setting this variable does not affect existing frames, only new ones. */);
5828 Vdefault_frame_alist = Qnil;
5830 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5831 doc: /* Default position of vertical scroll bars on this window-system. */);
5832 #ifdef HAVE_WINDOW_SYSTEM
5833 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5834 /* MS-Windows, macOS, and GTK have scroll bars on the right by
5835 default. */
5836 Vdefault_frame_scroll_bars = Qright;
5837 #else
5838 Vdefault_frame_scroll_bars = Qleft;
5839 #endif
5840 #else
5841 Vdefault_frame_scroll_bars = Qnil;
5842 #endif
5844 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5845 scroll_bar_adjust_thumb_portion_p,
5846 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5847 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5848 even if the end of the buffer is shown (i.e. overscrolling).
5849 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5850 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5851 is visible. In this case you can not overscroll. */);
5852 scroll_bar_adjust_thumb_portion_p = 1;
5854 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5855 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5857 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5858 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5859 `mouse-position' and `mouse-pixel-position' call this function, passing their
5860 usual return value as argument, and return whatever this function returns.
5861 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5862 which need to do mouse handling at the Lisp level. */);
5863 Vmouse_position_function = Qnil;
5865 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5866 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5867 If the value is an integer, highlighting is only shown after moving the
5868 mouse, while keyboard input turns off the highlight even when the mouse
5869 is over the clickable text. However, the mouse shape still indicates
5870 when the mouse is over clickable text. */);
5871 Vmouse_highlight = Qt;
5873 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5874 doc: /* If non-nil, make pointer invisible while typing.
5875 The pointer becomes visible again when the mouse is moved. */);
5876 Vmake_pointer_invisible = Qt;
5878 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5879 doc: /* Normal hook run when a frame gains input focus.
5880 The frame gaining focus is selected at the time this hook is run. */);
5881 Vfocus_in_hook = Qnil;
5883 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5884 doc: /* Normal hook run when all frames lost input focus. */);
5885 Vfocus_out_hook = Qnil;
5887 DEFVAR_LISP ("move-frame-functions", Vmove_frame_functions,
5888 doc: /* Functions run after a frame was moved.
5889 The functions are run with one arg, the frame that moved. */);
5890 Vmove_frame_functions = Qnil;
5892 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5893 doc: /* Functions run before deleting a frame.
5894 The functions are run with one arg, the frame to be deleted.
5895 See `delete-frame'.
5897 Note that functions in this list may be called just before the frame is
5898 actually deleted, or some time later (or even both when an earlier function
5899 in `delete-frame-functions' (indirectly) calls `delete-frame'
5900 recursively). */);
5901 Vdelete_frame_functions = Qnil;
5902 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5904 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5905 doc: /* Non-nil if Menu-Bar mode is enabled.
5906 See the command `menu-bar-mode' for a description of this minor mode.
5907 Setting this variable directly does not take effect;
5908 either customize it (see the info node `Easy Customization')
5909 or call the function `menu-bar-mode'. */);
5910 Vmenu_bar_mode = Qt;
5912 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5913 doc: /* Non-nil if Tool-Bar mode is enabled.
5914 See the command `tool-bar-mode' for a description of this minor mode.
5915 Setting this variable directly does not take effect;
5916 either customize it (see the info node `Easy Customization')
5917 or call the function `tool-bar-mode'. */);
5918 #ifdef HAVE_WINDOW_SYSTEM
5919 Vtool_bar_mode = Qt;
5920 #else
5921 Vtool_bar_mode = Qnil;
5922 #endif
5924 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5925 doc: /* Minibuffer-less frames by default use this frame's minibuffer.
5926 Emacs consults this variable only when creating a minibuffer-less frame
5927 and no explicit minibuffer window has been specified for that frame via
5928 the `minibuffer' frame parameter. Once such a frame has been created,
5929 setting this variable does not change that frame's previous association.
5931 This variable is local to the current terminal and cannot be buffer-local. */);
5933 DEFVAR_LISP ("focus-follows-mouse", focus_follows_mouse,
5934 doc: /* Non-nil if window system changes focus when you move the mouse.
5935 You should set this variable to tell Emacs how your window manager
5936 handles focus, since there is no way in general for Emacs to find out
5937 automatically.
5939 There are three meaningful values:
5941 - The default nil should be used when your window manager follows a
5942 "click-to-focus" policy where you have to click the mouse inside of a
5943 frame in order for that frame to get focus.
5945 - The value t should be used when your window manager has the focus
5946 automatically follow the position of the mouse pointer but a window
5947 that gains focus is not raised automatically.
5949 - The value `auto-raise' should be used when your window manager has the
5950 focus automatically follow the position of the mouse pointer and a
5951 window that gains focus is raised automatically.
5953 If this option is non-nil, Emacs moves the mouse pointer to the frame
5954 selected by `select-frame-set-input-focus'. This function is used by a
5955 number of commands like, for example, `other-frame' and `pop-to-buffer'.
5956 If this option is nil and your focus follows mouse window manager does
5957 not autonomously move the mouse pointer to the newly selected frame, the
5958 previously selected window manager window might get reselected instead
5959 immediately.
5961 The distinction between the values t and `auto-raise' is not needed for
5962 "normal" frames because the window manager takes care of raising them.
5963 Setting this to `auto-raise' will, however, override the standard
5964 behavior of a window manager that does not automatically raise the frame
5965 that gets focus. Setting this to `auto-raise' is also necessary to
5966 automatically raise child frames which are usually left alone by the
5967 window manager.
5969 Note that this option does not distinguish "sloppy" focus (where the
5970 frame that previously had focus retains focus as long as the mouse
5971 pointer does not move into another window manager window) from "strict"
5972 focus (where a frame immediately loses focus when it's left by the mouse
5973 pointer).
5975 In order to extend a "focus follows mouse" policy to individual Emacs
5976 windows, customize the variable `mouse-autoselect-window'. */);
5977 focus_follows_mouse = Qnil;
5979 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5980 doc: /* Non-nil means resize frames pixelwise.
5981 If this option is nil, resizing a frame rounds its sizes to the frame's
5982 current values of `frame-char-height' and `frame-char-width'. If this
5983 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5984 by one pixel.
5986 With some window managers you may have to set this to non-nil in order
5987 to set the size of a frame in pixels, to maximize frames or to make them
5988 fullscreen. To resize your initial frame pixelwise, set this option to
5989 a non-nil value in your init file. */);
5990 frame_resize_pixelwise = 0;
5992 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5993 doc: /* Whether frames should be resized implicitly.
5994 If this option is nil, setting font, menu bar, tool bar, internal
5995 borders, fringes or scroll bars of a specific frame may resize the frame
5996 in order to preserve the number of columns or lines it displays. If
5997 this option is t, no such resizing is done. Note that the size of
5998 fullscreen and maximized frames, the height of fullheight frames and the
5999 width of fullwidth frames never change implicitly.
6001 The value of this option can be also be a list of frame parameters. In
6002 this case, resizing is inhibited when changing a parameter that appears
6003 in that list. The parameters currently handled by this option include
6004 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
6005 `tool-bar-lines'.
6007 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
6008 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
6009 `right-fringe' is handled as if the frame contained just one live
6010 window. This means, for example, that removing vertical scroll bars on
6011 a frame containing several side by side windows will shrink the frame
6012 width by the width of one scroll bar provided this option is nil and
6013 keep it unchanged if this option is either t or a list containing
6014 `vertical-scroll-bars'.
6016 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
6017 \(which means that adding/removing a tool bar does not change the frame
6018 height), nil on all other window systems including GTK+ (which means
6019 that changing any of the parameters listed above may change the size of
6020 the frame), and t otherwise (which means the frame size never changes
6021 implicitly when there's no window system support).
6023 Note that when a frame is not large enough to accommodate a change of
6024 any of the parameters listed above, Emacs may try to enlarge the frame
6025 even if this option is non-nil. */);
6026 #if defined (HAVE_WINDOW_SYSTEM)
6027 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
6028 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
6029 #else
6030 frame_inhibit_implied_resize = Qnil;
6031 #endif
6032 #else
6033 frame_inhibit_implied_resize = Qt;
6034 #endif
6036 DEFVAR_LISP ("frame-size-history", frame_size_history,
6037 doc: /* History of frame size adjustments.
6038 If non-nil, list recording frame size adjustment. Adjustments are
6039 recorded only if the first element of this list is a positive number.
6040 Adding an adjustment decrements that number by one.
6042 The remaining elements are the adjustments. Each adjustment is a list
6043 of four elements `frame', `function', `sizes' and `more'. `frame' is
6044 the affected frame and `function' the invoking function. `sizes' is
6045 usually a list of four elements `old-width', `old-height', `new-width'
6046 and `new-height' representing the old and new sizes recorded/requested
6047 by `function'. `more' is a list with additional information.
6049 The function `frame--size-history' displays the value of this variable
6050 in a more readable form. */);
6051 frame_size_history = Qnil;
6053 DEFVAR_BOOL ("tooltip-reuse-hidden-frame", tooltip_reuse_hidden_frame,
6054 doc: /* Non-nil means reuse hidden tooltip frames.
6055 When this is nil, delete a tooltip frame when hiding the associated
6056 tooltip. When this is non-nil, make the tooltip frame invisible only,
6057 so it can be reused when the next tooltip is shown.
6059 Setting this to non-nil may drastically reduce the consing overhead
6060 incurred by creating new tooltip frames. However, a value of non-nil
6061 means also that intermittent changes of faces or `default-frame-alist'
6062 are not applied when showing a tooltip in a reused frame.
6064 This variable is effective only with the X toolkit (and there only when
6065 Gtk+ tooltips are not used) and on Windows. */);
6066 tooltip_reuse_hidden_frame = false;
6068 DEFVAR_LISP ("iconify-child-frame", iconify_child_frame,
6069 doc: /* How to handle iconification of child frames.
6070 This variable tells Emacs how to proceed when it is asked to iconify a
6071 child frame. If it is nil, `iconify-frame' will do nothing when invoked
6072 on a child frame. If it is `iconify-top-level', Emacs will try to
6073 iconify the top level frame associated with this child frame instead.
6074 If it is `make-invisible', Emacs will try to make this child frame
6075 invisible instead.
6077 Any other value means to try iconifying the child frame. Since such an
6078 attempt is not honored by all window managers and may even lead to
6079 making the child frame unresponsive to user actions, the default is to
6080 iconify the top level frame instead. */);
6081 iconify_child_frame = Qiconify_top_level;
6083 staticpro (&Vframe_list);
6085 defsubr (&Sframep);
6086 defsubr (&Sframe_live_p);
6087 defsubr (&Swindow_system);
6088 defsubr (&Sframe_windows_min_size);
6089 defsubr (&Smake_terminal_frame);
6090 defsubr (&Shandle_switch_frame);
6091 defsubr (&Sselect_frame);
6092 defsubr (&Sselected_frame);
6093 defsubr (&Sframe_list);
6094 defsubr (&Sframe_parent);
6095 defsubr (&Sframe_ancestor_p);
6096 defsubr (&Snext_frame);
6097 defsubr (&Sprevious_frame);
6098 defsubr (&Slast_nonminibuf_frame);
6099 defsubr (&Sdelete_frame);
6100 defsubr (&Smouse_position);
6101 defsubr (&Smouse_pixel_position);
6102 defsubr (&Sset_mouse_position);
6103 defsubr (&Sset_mouse_pixel_position);
6104 #if 0
6105 defsubr (&Sframe_configuration);
6106 defsubr (&Srestore_frame_configuration);
6107 #endif
6108 defsubr (&Smake_frame_visible);
6109 defsubr (&Smake_frame_invisible);
6110 defsubr (&Siconify_frame);
6111 defsubr (&Sframe_visible_p);
6112 defsubr (&Svisible_frame_list);
6113 defsubr (&Sraise_frame);
6114 defsubr (&Slower_frame);
6115 defsubr (&Sx_focus_frame);
6116 defsubr (&Sframe_after_make_frame);
6117 defsubr (&Sredirect_frame_focus);
6118 defsubr (&Sframe_focus);
6119 defsubr (&Sframe_parameters);
6120 defsubr (&Sframe_parameter);
6121 defsubr (&Smodify_frame_parameters);
6122 defsubr (&Sframe_char_height);
6123 defsubr (&Sframe_char_width);
6124 defsubr (&Sframe_native_height);
6125 defsubr (&Sframe_native_width);
6126 defsubr (&Sframe_text_cols);
6127 defsubr (&Sframe_text_lines);
6128 defsubr (&Sframe_total_cols);
6129 defsubr (&Sframe_total_lines);
6130 defsubr (&Sframe_text_width);
6131 defsubr (&Sframe_text_height);
6132 defsubr (&Sscroll_bar_width);
6133 defsubr (&Sscroll_bar_height);
6134 defsubr (&Sfringe_width);
6135 defsubr (&Sframe_internal_border_width);
6136 defsubr (&Sright_divider_width);
6137 defsubr (&Sbottom_divider_width);
6138 defsubr (&Stool_bar_pixel_width);
6139 defsubr (&Sset_frame_height);
6140 defsubr (&Sset_frame_width);
6141 defsubr (&Sset_frame_size);
6142 defsubr (&Sframe_position);
6143 defsubr (&Sset_frame_position);
6144 defsubr (&Sframe_pointer_visible_p);
6146 #ifdef HAVE_WINDOW_SYSTEM
6147 defsubr (&Sx_get_resource);
6148 defsubr (&Sx_parse_geometry);
6149 #endif