* test/lisp/mouse-tests.el: Fix tests broken by mouse.el change
[emacs.git] / src / frame.c
blob9b5608081285b03f6d81e3187e07ecc6b6411590
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2018 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or (at
10 your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <limits.h>
27 #include <c-ctype.h>
29 #include "lisp.h"
31 #ifdef HAVE_WINDOW_SYSTEM
32 #include TERM_HEADER
33 #endif /* HAVE_WINDOW_SYSTEM */
35 #include "buffer.h"
36 /* These help us bind and responding to switch-frame events. */
37 #include "keyboard.h"
38 #include "ptr-bounds.h"
39 #include "frame.h"
40 #include "blockinput.h"
41 #include "termchar.h"
42 #include "termhooks.h"
43 #include "dispextern.h"
44 #include "window.h"
45 #ifdef HAVE_WINDOW_SYSTEM
46 #include "fontset.h"
47 #endif
48 #include "cm.h"
49 #ifdef MSDOS
50 #include "msdos.h"
51 #include "dosfns.h"
52 #endif
53 #ifdef USE_X_TOOLKIT
54 #include "widget.h"
55 #endif
57 /* The currently selected frame. */
59 Lisp_Object selected_frame;
61 /* A frame which is not just a mini-buffer, or NULL if there are no such
62 frames. This is usually the most recent such frame that was selected. */
64 static struct frame *last_nonminibuf_frame;
66 /* False means there are no visible garbaged frames. */
67 bool frame_garbaged;
69 /* The default tool bar height for future frames. */
70 #if defined USE_GTK || defined HAVE_NS
71 enum { frame_default_tool_bar_height = 0 };
72 #else
73 int frame_default_tool_bar_height;
74 #endif
76 #ifdef HAVE_WINDOW_SYSTEM
77 static void x_report_frame_params (struct frame *, Lisp_Object *);
78 #endif
80 /* These setters are used only in this file, so they can be private. */
81 static void
82 fset_buffer_predicate (struct frame *f, Lisp_Object val)
84 f->buffer_predicate = val;
86 static void
87 fset_minibuffer_window (struct frame *f, Lisp_Object val)
89 f->minibuffer_window = val;
92 struct frame *
93 decode_live_frame (register Lisp_Object frame)
95 if (NILP (frame))
96 frame = selected_frame;
97 CHECK_LIVE_FRAME (frame);
98 return XFRAME (frame);
101 struct frame *
102 decode_any_frame (register Lisp_Object frame)
104 if (NILP (frame))
105 frame = selected_frame;
106 CHECK_FRAME (frame);
107 return XFRAME (frame);
110 #ifdef HAVE_WINDOW_SYSTEM
111 bool
112 display_available (void)
114 return x_display_list != NULL;
116 #endif
118 struct frame *
119 decode_window_system_frame (Lisp_Object frame)
121 struct frame *f = decode_live_frame (frame);
122 check_window_system (f);
123 #ifdef HAVE_WINDOW_SYSTEM
124 return f;
125 #endif
128 void
129 check_window_system (struct frame *f)
131 #ifdef HAVE_WINDOW_SYSTEM
132 if (window_system_available (f))
133 return;
134 #endif
135 error (f ? "Window system frame should be used"
136 : "Window system is not in use or not initialized");
139 /* Return the value of frame parameter PROP in frame FRAME. */
141 Lisp_Object
142 get_frame_param (register struct frame *frame, Lisp_Object prop)
144 register Lisp_Object tem;
146 tem = Fassq (prop, frame->param_alist);
147 if (EQ (tem, Qnil))
148 return tem;
149 return Fcdr (tem);
153 void
154 frame_size_history_add (struct frame *f, Lisp_Object fun_symbol,
155 int width, int height, Lisp_Object rest)
157 Lisp_Object frame;
159 XSETFRAME (frame, f);
160 if (CONSP (frame_size_history)
161 && INTEGERP (XCAR (frame_size_history))
162 && 0 < XINT (XCAR (frame_size_history)))
163 frame_size_history =
164 Fcons (make_number (XINT (XCAR (frame_size_history)) - 1),
165 Fcons (list4
166 (frame, fun_symbol,
167 ((width > 0)
168 ? list4 (make_number (FRAME_TEXT_WIDTH (f)),
169 make_number (FRAME_TEXT_HEIGHT (f)),
170 make_number (width),
171 make_number (height))
172 : Qnil),
173 rest),
174 XCDR (frame_size_history)));
178 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
179 state of frame F would be affected by a vertical (horizontal if
180 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
181 parameter that is changed. */
182 bool
183 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
185 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
186 bool inhibit
187 = (f->after_make_frame
188 ? (EQ (frame_inhibit_implied_resize, Qt)
189 || (CONSP (frame_inhibit_implied_resize)
190 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))
191 || (horizontal
192 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight))
193 || (!horizontal
194 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth))
195 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
196 : ((horizontal && f->inhibit_horizontal_resize)
197 || (!horizontal && f->inhibit_vertical_resize)));
198 if (inhibit && !FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
199 frame_size_history_add
200 (f, Qframe_inhibit_resize, 0, 0,
201 list5 (horizontal ? Qt : Qnil, parameter,
202 f->after_make_frame ? Qt : Qnil,
203 frame_inhibit_implied_resize,
204 fullscreen));
206 return inhibit;
209 static void
210 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
212 int nlines;
213 int olines = FRAME_MENU_BAR_LINES (f);
215 /* Right now, menu bars don't work properly in minibuf-only frames;
216 most of the commands try to apply themselves to the minibuffer
217 frame itself, and get an error because you can't switch buffers
218 in or split the minibuffer window. */
219 if (FRAME_MINIBUF_ONLY_P (f))
220 return;
222 if (TYPE_RANGED_INTEGERP (int, value))
223 nlines = XINT (value);
224 else
225 nlines = 0;
227 if (nlines != olines)
229 windows_or_buffers_changed = 14;
230 FRAME_MENU_BAR_LINES (f) = nlines;
231 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
232 change_frame_size (f, FRAME_COLS (f),
233 FRAME_LINES (f) + olines - nlines,
234 0, 1, 0, 0);
238 Lisp_Object Vframe_list;
241 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
242 doc: /* Return non-nil if OBJECT is a frame.
243 Value is:
244 t for a termcap frame (a character-only terminal),
245 `x' for an Emacs frame that is really an X window,
246 `w32' for an Emacs frame that is a window on MS-Windows display,
247 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
248 `pc' for a direct-write MS-DOS frame.
249 See also `frame-live-p'. */)
250 (Lisp_Object object)
252 if (!FRAMEP (object))
253 return Qnil;
254 switch (XFRAME (object)->output_method)
256 case output_initial: /* The initial frame is like a termcap frame. */
257 case output_termcap:
258 return Qt;
259 case output_x_window:
260 return Qx;
261 case output_w32:
262 return Qw32;
263 case output_msdos_raw:
264 return Qpc;
265 case output_ns:
266 return Qns;
267 default:
268 emacs_abort ();
272 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
273 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
274 Value is nil if OBJECT is not a live frame. If object is a live
275 frame, the return value indicates what sort of terminal device it is
276 displayed on. See the documentation of `framep' for possible
277 return values. */)
278 (Lisp_Object object)
280 return ((FRAMEP (object)
281 && FRAME_LIVE_P (XFRAME (object)))
282 ? Fframep (object)
283 : Qnil);
286 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
287 doc: /* The name of the window system that FRAME is displaying through.
288 The value is a symbol:
289 nil for a termcap frame (a character-only terminal),
290 `x' for an Emacs frame that is really an X window,
291 `w32' for an Emacs frame that is a window on MS-Windows display,
292 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
293 `pc' for a direct-write MS-DOS frame.
295 FRAME defaults to the currently selected frame.
297 Use of this function as a predicate is deprecated. Instead,
298 use `display-graphic-p' or any of the other `display-*-p'
299 predicates which report frame's specific UI-related capabilities. */)
300 (Lisp_Object frame)
302 Lisp_Object type;
303 if (NILP (frame))
304 frame = selected_frame;
306 type = Fframep (frame);
308 if (NILP (type))
309 wrong_type_argument (Qframep, frame);
311 if (EQ (type, Qt))
312 return Qnil;
313 else
314 return type;
317 /* Placeholder used by temacs -nw before window.el is loaded. */
318 DEFUN ("frame-windows-min-size", Fframe_windows_min_size,
319 Sframe_windows_min_size, 4, 4, 0,
320 doc: /* */
321 attributes: const)
322 (Lisp_Object frame, Lisp_Object horizontal,
323 Lisp_Object ignore, Lisp_Object pixelwise)
325 return make_number (0);
329 * frame_windows_min_size:
331 * Return the minimum number of lines (columns if HORIZONTAL is non-nil)
332 * of FRAME. If PIXELWISE is non-nil, return the minimum inner height
333 * (width) of FRAME in pixels.
335 * This value is calculated by the function `frame-windows-min-size' in
336 * window.el unless the `min-height' (`min-width' if HORIZONTAL is
337 * non-nil) parameter of FRAME is non-nil thus explicitly specifying the
338 * value to be returned. In that latter case IGNORE is ignored.
340 * If `frame-windows-min-size' is called, it will make sure that the
341 * return value accommodates all windows of FRAME respecting the values
342 * of `window-min-height' (`window-min-width' if HORIZONTAL is non-nil).
343 * With IGNORE non-nil the values of these variables are ignored.
345 * In either case, never return a value less than 1.
347 static int
348 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal,
349 Lisp_Object ignore, Lisp_Object pixelwise)
351 struct frame *f = XFRAME (frame);
352 Lisp_Object par_size;
354 if ((!NILP (horizontal)
355 && NUMBERP (par_size = get_frame_param (f, Qmin_width)))
356 || (NILP (horizontal)
357 && NUMBERP (par_size = get_frame_param (f, Qmin_height))))
359 int min_size = XINT (par_size);
361 /* Don't allow phantom frames. */
362 if (min_size < 1)
363 min_size = 1;
365 return (NILP (pixelwise)
366 ? min_size
367 : min_size * (NILP (horizontal)
368 ? FRAME_LINE_HEIGHT (f)
369 : FRAME_COLUMN_WIDTH (f)));
371 else
372 return XINT (call4 (Qframe_windows_min_size, frame, horizontal,
373 ignore, pixelwise));
377 #ifdef HAVE_WINDOW_SYSTEM
379 * keep_ratio:
381 * Preserve ratios of frame F which usually happens after its parent
382 * frame P got resized. OLD_WIDTH, OLD_HEIGHT specifies the old native
383 * size of F's parent, NEW_WIDTH and NEW_HEIGHT its new size.
385 * Adjust F's width if F's 'keep_ratio' parameter is non-nil and, if
386 * it is a cons, its car is not 'height-only'. Adjust F's height if F's
387 * 'keep_ratio' parameter is non-nil and, if it is a cons, its car
388 * is not 'width-only'.
390 * Adjust F's left position if F's 'keep_ratio' parameter is non-nil
391 * and, if its is a cons, its cdr is non-nil and not 'top-only'. Adjust
392 * F's top position if F's 'keep_ratio' parameter is non-nil and, if
393 * its is a cons, its cdr is non-nil and not 'left-only'.
395 * Note that when positional adjustment is requested but the size of F
396 * should remain unaltered in the corresponding direction, this routine
397 * tries to constrain F to its parent frame - something which usually
398 * happens when the parent frame shrinks. This means, however, that
399 * when the parent frame is re-enlarged later, the child's original
400 * position will not get restored to its pre-shrinking value.
402 * This routine is currently useful for child frames only. It might be
403 * eventually useful when moving non-child frames between monitors with
404 * different resolutions.
406 static void
407 keep_ratio (struct frame *f, struct frame *p, int old_width, int old_height,
408 int new_width, int new_height)
410 Lisp_Object keep_ratio = get_frame_param (f, Qkeep_ratio);
413 if (!NILP (keep_ratio))
415 double width_factor = (double)new_width / (double)old_width;
416 double height_factor = (double)new_height / (double)old_height;
417 int pixel_width, pixel_height, pos_x, pos_y;
419 if (!CONSP (keep_ratio) || !NILP (Fcdr (keep_ratio)))
421 if (CONSP (keep_ratio) && EQ (Fcdr (keep_ratio), Qtop_only))
422 pos_x = f->left_pos;
423 else
425 pos_x = (int)(f->left_pos * width_factor + 0.5);
427 if (CONSP (keep_ratio)
428 && (NILP (Fcar (keep_ratio))
429 || EQ (Fcar (keep_ratio), Qheight_only))
430 && p->pixel_width - f->pixel_width < pos_x)
432 int p_f_width = p->pixel_width - f->pixel_width;
434 if (p_f_width <= 0)
435 pos_x = 0;
436 else
437 pos_x = (int)(p_f_width * width_factor * 0.5 + 0.5);
440 f->left_pos = pos_x;
443 if (CONSP (keep_ratio) && EQ (Fcdr (keep_ratio), Qleft_only))
444 pos_y = f->top_pos;
445 else
447 pos_y = (int)(f->top_pos * height_factor + 0.5);
449 if (CONSP (keep_ratio)
450 && (NILP (Fcar (keep_ratio))
451 || EQ (Fcar (keep_ratio), Qwidth_only))
452 && p->pixel_height - f->pixel_height < pos_y)
453 /* When positional adjustment was requested and the
454 width of F should remain unaltered, try to constrain
455 F to its parent. This means that when the parent
456 frame is enlarged later the child's original position
457 won't get restored. */
459 int p_f_height = p->pixel_height - f->pixel_height;
461 if (p_f_height <= 0)
462 pos_y = 0;
463 else
464 pos_y = (int)(p_f_height * height_factor * 0.5 + 0.5);
467 f->top_pos = pos_y;
470 x_set_offset (f, pos_x, pos_y, -1);
473 if (!CONSP (keep_ratio) || !NILP (Fcar (keep_ratio)))
475 if (CONSP (keep_ratio) && EQ (Fcar (keep_ratio), Qheight_only))
476 pixel_width = -1;
477 else
479 pixel_width = (int)(f->pixel_width * width_factor + 0.5);
480 pixel_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, pixel_width);
483 if (CONSP (keep_ratio) && EQ (Fcar (keep_ratio), Qwidth_only))
484 pixel_height = -1;
485 else
487 pixel_height = (int)(f->pixel_height * height_factor + 0.5);
488 pixel_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, pixel_height);
491 adjust_frame_size (f, pixel_width, pixel_height, 1, 0,
492 Qkeep_ratio);
496 #endif
500 * adjust_frame_size:
502 * Adjust size of frame F. NEW_WIDTH and NEW_HEIGHT specify the new
503 * text size of F in pixels. A value of -1 means no change is requested
504 * for that direction (but the frame may still have to be resized to
505 * accommodate windows with their minimum sizes). This can either issue
506 * a request to resize the frame externally (via x_set_window_size), to
507 * resize the frame internally (via resize_frame_windows) or do nothing
508 * at all.
510 * The argument INHIBIT can assume the following values:
512 * 0 means to unconditionally call x_set_window_size even if sizes
513 * apparently do not change. Fx_create_frame uses this to pass the
514 * initial size to the window manager.
516 * 1 means to call x_set_window_size if the native frame size really
517 * changes. Fset_frame_size, Fset_frame_height, ... use this.
519 * 2 means to call x_set_window_size provided frame_inhibit_resize
520 * allows it. The menu and tool bar code use this ("3" won't work
521 * here in general because menu and tool bar are often not counted in
522 * the frame's text height).
524 * 3 means call x_set_window_size if window minimum sizes must be
525 * preserved or frame_inhibit_resize allows it. x_set_left_fringe,
526 * x_set_scroll_bar_width, x_new_font ... use (or should use) this.
528 * 4 means call x_set_window_size only if window minimum sizes must be
529 * preserved. x_set_right_divider_width, x_set_border_width and the
530 * code responsible for wrapping the tool bar use this.
532 * 5 means to never call x_set_window_size. change_frame_size uses
533 * this.
535 * Note that even when x_set_window_size is not called, individual
536 * windows may have to be resized (via `window--sanitize-window-sizes')
537 * in order to support minimum size constraints.
539 * PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the
540 * symbol of the parameter changed (like `menu-bar-lines', `font', ...).
541 * This is passed on to frame_inhibit_resize to let the latter decide on
542 * a case-by-case basis whether the frame may be resized externally.
544 void
545 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
546 bool pretend, Lisp_Object parameter)
548 int unit_width = FRAME_COLUMN_WIDTH (f);
549 int unit_height = FRAME_LINE_HEIGHT (f);
550 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
551 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
552 int old_cols = FRAME_COLS (f);
553 int old_lines = FRAME_LINES (f);
554 int new_pixel_width, new_pixel_height;
555 /* The following two values are calculated from the old frame pixel
556 sizes and any "new" settings for tool bar, menu bar and internal
557 borders. We do it this way to detect whether we have to call
558 x_set_window_size as consequence of the new settings. */
559 int windows_width = FRAME_WINDOWS_WIDTH (f);
560 int windows_height = FRAME_WINDOWS_HEIGHT (f);
561 int min_windows_width, min_windows_height;
562 /* These are a bit tedious, maybe we should use a macro. */
563 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
564 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
565 int old_windows_height
566 = (WINDOW_PIXEL_HEIGHT (r)
567 + ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
568 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
569 : 0));
570 int new_windows_width, new_windows_height;
571 int old_text_width = FRAME_TEXT_WIDTH (f);
572 int old_text_height = FRAME_TEXT_HEIGHT (f);
573 /* If a size is < 0 use the old value. */
574 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
575 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
576 int new_cols, new_lines;
577 bool inhibit_horizontal, inhibit_vertical;
578 Lisp_Object frame;
580 XSETFRAME (frame, f);
582 frame_size_history_add
583 (f, Qadjust_frame_size_1, new_text_width, new_text_height,
584 list2 (parameter, make_number (inhibit)));
586 /* The following two values are calculated from the old window body
587 sizes and any "new" settings for scroll bars, dividers, fringes and
588 margins (though the latter should have been processed already). */
589 min_windows_width
590 = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qt : Qnil, Qt);
591 min_windows_height
592 = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qt : Qnil, Qt);
594 if (inhibit >= 2 && inhibit <= 4)
595 /* When INHIBIT is in [2..4] inhibit if the "old" window sizes stay
596 within the limits and either resizing is inhibited or INHIBIT
597 equals 4. */
599 inhibit_horizontal = (windows_width >= min_windows_width
600 && (inhibit == 4
601 || frame_inhibit_resize (f, true, parameter)));
602 inhibit_vertical = (windows_height >= min_windows_height
603 && (inhibit == 4
604 || frame_inhibit_resize (f, false, parameter)));
606 else
607 /* Otherwise inhibit if INHIBIT equals 5. */
608 inhibit_horizontal = inhibit_vertical = inhibit == 5;
610 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
611 ? old_pixel_width
612 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
613 min_windows_width
614 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
615 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
616 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
617 new_cols = new_text_width / unit_width;
619 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
620 ? old_pixel_height
621 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
622 min_windows_height
623 + FRAME_TOP_MARGIN_HEIGHT (f)
624 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
625 new_windows_height = (new_pixel_height
626 - FRAME_TOP_MARGIN_HEIGHT (f)
627 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
628 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
629 new_lines = new_text_height / unit_height;
631 #ifdef HAVE_WINDOW_SYSTEM
632 if (FRAME_WINDOW_P (f)
633 && f->can_x_set_window_size
634 && ((!inhibit_horizontal
635 && (new_pixel_width != old_pixel_width
636 || inhibit == 0 || inhibit == 2))
637 || (!inhibit_vertical
638 && (new_pixel_height != old_pixel_height
639 || inhibit == 0 || inhibit == 2))))
640 /* We are either allowed to change the frame size or the minimum
641 sizes request such a change. Do not care for fixing minimum
642 sizes here, we do that eventually when we're called from
643 change_frame_size. */
645 /* Make sure we respect fullheight and fullwidth. */
646 if (inhibit_horizontal)
647 new_text_width = old_text_width;
648 else if (inhibit_vertical)
649 new_text_height = old_text_height;
651 frame_size_history_add
652 (f, Qadjust_frame_size_2, new_text_width, new_text_height,
653 list2 (inhibit_horizontal ? Qt : Qnil,
654 inhibit_vertical ? Qt : Qnil));
656 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
657 f->resized_p = true;
659 return;
661 #endif
663 if (new_text_width == old_text_width
664 && new_text_height == old_text_height
665 && new_windows_width == old_windows_width
666 && new_windows_height == old_windows_height
667 && new_pixel_width == old_pixel_width
668 && new_pixel_height == old_pixel_height
669 && new_cols == old_cols
670 && new_lines == old_lines)
671 /* No change. Sanitize window sizes and return. */
673 sanitize_window_sizes (Qt);
674 sanitize_window_sizes (Qnil);
676 return;
679 block_input ();
681 #ifdef MSDOS
682 /* We only can set screen dimensions to certain values supported by
683 our video hardware. Try to find the smallest size greater or
684 equal to the requested dimensions, while accounting for the fact
685 that the menu-bar lines are not counted in the frame height. */
686 int dos_new_lines = new_lines + FRAME_TOP_MARGIN (f);
687 dos_set_window_size (&dos_new_lines, &new_cols);
688 new_lines = dos_new_lines - FRAME_TOP_MARGIN (f);
689 #endif
691 if (new_windows_width != old_windows_width)
693 resize_frame_windows (f, new_windows_width, 1, 1);
695 /* MSDOS frames cannot PRETEND, as they change frame size by
696 manipulating video hardware. */
697 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
698 FrameCols (FRAME_TTY (f)) = new_cols;
700 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
701 if (WINDOWP (f->tool_bar_window))
703 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
704 XWINDOW (f->tool_bar_window)->total_cols
705 = new_windows_width / unit_width;
707 #endif
709 else if (new_cols != old_cols)
710 call2 (Qwindow__pixel_to_total, frame, Qt);
712 if (new_windows_height != old_windows_height
713 /* When the top margin has changed we have to recalculate the top
714 edges of all windows. No such calculation is necessary for the
715 left edges. */
716 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
718 resize_frame_windows (f, new_windows_height, 0, 1);
720 /* MSDOS frames cannot PRETEND, as they change frame size by
721 manipulating video hardware. */
722 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
723 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
725 else if (new_lines != old_lines)
726 call2 (Qwindow__pixel_to_total, frame, Qnil);
728 frame_size_history_add
729 (f, Qadjust_frame_size_3, new_text_width, new_text_height,
730 list4 (make_number (old_pixel_width), make_number (old_pixel_height),
731 make_number (new_pixel_width), make_number (new_pixel_height)));
733 /* Assign new sizes. */
734 FRAME_TEXT_WIDTH (f) = new_text_width;
735 FRAME_TEXT_HEIGHT (f) = new_text_height;
736 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
737 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
738 SET_FRAME_COLS (f, new_cols);
739 SET_FRAME_LINES (f, new_lines);
742 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
743 int text_area_x, text_area_y, text_area_width, text_area_height;
745 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
746 &text_area_height);
747 if (w->cursor.x >= text_area_x + text_area_width)
748 w->cursor.hpos = w->cursor.x = 0;
749 if (w->cursor.y >= text_area_y + text_area_height)
750 w->cursor.vpos = w->cursor.y = 0;
753 /* Sanitize window sizes. */
754 sanitize_window_sizes (Qt);
755 sanitize_window_sizes (Qnil);
757 adjust_frame_glyphs (f);
758 calculate_costs (f);
759 SET_FRAME_GARBAGED (f);
761 /* A frame was "resized" if one of its pixelsizes changed, even if its
762 X window wasn't resized at all. */
763 f->resized_p = (new_pixel_width != old_pixel_width
764 || new_pixel_height != old_pixel_height);
766 unblock_input ();
768 #ifdef HAVE_WINDOW_SYSTEM
770 /* Adjust size of F's child frames. */
771 Lisp_Object frames, frame1;
773 FOR_EACH_FRAME (frames, frame1)
774 if (FRAME_PARENT_FRAME (XFRAME (frame1)) == f)
775 keep_ratio (XFRAME (frame1), f, old_pixel_width, old_pixel_height,
776 new_pixel_width, new_pixel_height);
778 #endif
781 /* Allocate basically initialized frame. */
783 static struct frame *
784 allocate_frame (void)
786 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
789 struct frame *
790 make_frame (bool mini_p)
792 Lisp_Object frame;
793 struct frame *f;
794 struct window *rw, *mw UNINIT;
795 Lisp_Object root_window;
796 Lisp_Object mini_window;
798 f = allocate_frame ();
799 XSETFRAME (frame, f);
801 #ifdef USE_GTK
802 /* Initialize Lisp data. Note that allocate_frame initializes all
803 Lisp data to nil, so do it only for slots which should not be nil. */
804 fset_tool_bar_position (f, Qtop);
805 #endif
807 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
808 non-Lisp data, so do it only for slots which should not be zero.
809 To avoid subtle bugs and for the sake of readability, it's better to
810 initialize enum members explicitly even if their values are zero. */
811 f->wants_modeline = true;
812 f->redisplay = true;
813 f->garbaged = true;
814 f->can_x_set_window_size = false;
815 f->after_make_frame = false;
816 f->inhibit_horizontal_resize = false;
817 f->inhibit_vertical_resize = false;
818 f->tool_bar_redisplayed = false;
819 f->tool_bar_resized = false;
820 f->column_width = 1; /* !FRAME_WINDOW_P value. */
821 f->line_height = 1; /* !FRAME_WINDOW_P value. */
822 #ifdef HAVE_WINDOW_SYSTEM
823 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
824 f->horizontal_scroll_bars = false;
825 f->want_fullscreen = FULLSCREEN_NONE;
826 f->undecorated = false;
827 f->no_special_glyphs = false;
828 #ifndef HAVE_NTGUI
829 f->override_redirect = false;
830 #endif
831 f->skip_taskbar = false;
832 f->no_focus_on_map = false;
833 f->no_accept_focus = false;
834 f->z_group = z_group_none;
835 f->tooltip = false;
836 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
837 f->last_tool_bar_item = -1;
838 #endif
839 #ifdef NS_IMPL_COCOA
840 f->ns_appearance = ns_appearance_aqua;
841 f->ns_transparent_titlebar = false;
842 #endif
843 #endif
845 root_window = make_window ();
846 rw = XWINDOW (root_window);
847 if (mini_p)
849 mini_window = make_window ();
850 mw = XWINDOW (mini_window);
851 wset_next (rw, mini_window);
852 wset_prev (mw, root_window);
853 mw->mini = 1;
854 wset_frame (mw, frame);
855 fset_minibuffer_window (f, mini_window);
856 store_frame_param (f, Qminibuffer, Qt);
858 else
860 mini_window = Qnil;
861 wset_next (rw, Qnil);
862 fset_minibuffer_window (f, Qnil);
865 wset_frame (rw, frame);
867 /* 10 is arbitrary,
868 just so that there is "something there."
869 Correct size will be set up later with adjust_frame_size. */
871 SET_FRAME_COLS (f, 10);
872 SET_FRAME_LINES (f, 10);
873 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
874 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
876 rw->total_cols = 10;
877 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
878 rw->total_lines = mini_p ? 9 : 10;
879 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
881 if (mini_p)
883 mw->top_line = rw->total_lines;
884 mw->pixel_top = rw->pixel_height;
885 mw->total_cols = rw->total_cols;
886 mw->pixel_width = rw->pixel_width;
887 mw->total_lines = 1;
888 mw->pixel_height = FRAME_LINE_HEIGHT (f);
891 /* Choose a buffer for the frame's root window. */
893 Lisp_Object buf = Fcurrent_buffer ();
895 /* If current buffer is hidden, try to find another one. */
896 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
897 buf = other_buffer_safely (buf);
899 /* Use set_window_buffer, not Fset_window_buffer, and don't let
900 hooks be run by it. The reason is that the whole frame/window
901 arrangement is not yet fully initialized at this point. Windows
902 don't have the right size, glyph matrices aren't initialized
903 etc. Running Lisp functions at this point surely ends in a
904 SEGV. */
905 set_window_buffer (root_window, buf, 0, 0);
906 fset_buffer_list (f, list1 (buf));
909 if (mini_p)
911 set_window_buffer (mini_window,
912 (NILP (Vminibuffer_list)
913 ? get_minibuffer (0)
914 : Fcar (Vminibuffer_list)),
915 0, 0);
916 /* No horizontal scroll bars in minibuffers. */
917 wset_horizontal_scroll_bar (mw, Qnil);
920 fset_root_window (f, root_window);
921 fset_selected_window (f, root_window);
922 /* Make sure this window seems more recently used than
923 a newly-created, never-selected window. */
924 XWINDOW (f->selected_window)->use_time = ++window_select_count;
926 return f;
929 #ifdef HAVE_WINDOW_SYSTEM
930 /* Make a frame using a separate minibuffer window on another frame.
931 MINI_WINDOW is the minibuffer window to use. nil means use the
932 default (the global minibuffer). */
934 struct frame *
935 make_frame_without_minibuffer (Lisp_Object mini_window, KBOARD *kb,
936 Lisp_Object display)
938 struct frame *f;
940 if (!NILP (mini_window))
941 CHECK_LIVE_WINDOW (mini_window);
943 if (!NILP (mini_window)
944 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
945 error ("Frame and minibuffer must be on the same terminal");
947 /* Make a frame containing just a root window. */
948 f = make_frame (0);
950 if (NILP (mini_window))
952 /* Use default-minibuffer-frame if possible. */
953 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
954 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
956 Lisp_Object frame_dummy;
958 XSETFRAME (frame_dummy, f);
959 /* If there's no minibuffer frame to use, create one. */
960 kset_default_minibuffer_frame
961 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
964 mini_window
965 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
968 fset_minibuffer_window (f, mini_window);
969 store_frame_param (f, Qminibuffer, mini_window);
971 /* Make the chosen minibuffer window display the proper minibuffer,
972 unless it is already showing a minibuffer. */
973 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
974 /* Use set_window_buffer instead of Fset_window_buffer (see
975 discussion of bug#11984, bug#12025, bug#12026). */
976 set_window_buffer (mini_window,
977 (NILP (Vminibuffer_list)
978 ? get_minibuffer (0)
979 : Fcar (Vminibuffer_list)), 0, 0);
980 return f;
983 /* Make a frame containing only a minibuffer window. */
985 struct frame *
986 make_minibuffer_frame (void)
988 /* First make a frame containing just a root window, no minibuffer. */
990 register struct frame *f = make_frame (0);
991 register Lisp_Object mini_window;
992 register Lisp_Object frame;
994 XSETFRAME (frame, f);
996 f->auto_raise = 0;
997 f->auto_lower = 0;
998 f->no_split = 1;
999 f->wants_modeline = 0;
1001 /* Now label the root window as also being the minibuffer.
1002 Avoid infinite looping on the window chain by marking next pointer
1003 as nil. */
1005 mini_window = f->root_window;
1006 fset_minibuffer_window (f, mini_window);
1007 store_frame_param (f, Qminibuffer, Qonly);
1008 XWINDOW (mini_window)->mini = 1;
1009 wset_next (XWINDOW (mini_window), Qnil);
1010 wset_prev (XWINDOW (mini_window), Qnil);
1011 wset_frame (XWINDOW (mini_window), frame);
1013 /* Put the proper buffer in that window. */
1015 /* Use set_window_buffer instead of Fset_window_buffer (see
1016 discussion of bug#11984, bug#12025, bug#12026). */
1017 set_window_buffer (mini_window,
1018 (NILP (Vminibuffer_list)
1019 ? get_minibuffer (0)
1020 : Fcar (Vminibuffer_list)), 0, 0);
1021 return f;
1023 #endif /* HAVE_WINDOW_SYSTEM */
1025 /* Construct a frame that refers to a terminal. */
1027 static printmax_t tty_frame_count;
1029 struct frame *
1030 make_initial_frame (void)
1032 struct frame *f;
1033 struct terminal *terminal;
1034 Lisp_Object frame;
1036 eassert (initial_kboard);
1038 /* The first call must initialize Vframe_list. */
1039 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
1040 Vframe_list = Qnil;
1042 terminal = init_initial_terminal ();
1044 f = make_frame (1);
1045 XSETFRAME (frame, f);
1047 Vframe_list = Fcons (frame, Vframe_list);
1049 tty_frame_count = 1;
1050 fset_name (f, build_pure_c_string ("F1"));
1052 SET_FRAME_VISIBLE (f, 1);
1054 f->output_method = terminal->type;
1055 f->terminal = terminal;
1056 f->terminal->reference_count++;
1057 f->output_data.nothing = 0;
1059 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
1060 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
1062 #ifdef HAVE_WINDOW_SYSTEM
1063 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
1064 f->horizontal_scroll_bars = false;
1065 #endif
1067 /* The default value of menu-bar-mode is t. */
1068 set_menu_bar_lines (f, make_number (1), Qnil);
1070 /* Allocate glyph matrices. */
1071 adjust_frame_glyphs (f);
1073 if (!noninteractive)
1074 init_frame_faces (f);
1076 last_nonminibuf_frame = f;
1078 f->can_x_set_window_size = true;
1079 f->after_make_frame = true;
1081 return f;
1085 static struct frame *
1086 make_terminal_frame (struct terminal *terminal)
1088 register struct frame *f;
1089 Lisp_Object frame;
1090 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
1092 if (!terminal->name)
1093 error ("Terminal is not live, can't create new frames on it");
1095 f = make_frame (1);
1097 XSETFRAME (frame, f);
1098 Vframe_list = Fcons (frame, Vframe_list);
1100 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
1102 SET_FRAME_VISIBLE (f, 1);
1104 f->terminal = terminal;
1105 f->terminal->reference_count++;
1106 #ifdef MSDOS
1107 f->output_data.tty->display_info = &the_only_display_info;
1108 if (!inhibit_window_system
1109 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
1110 || XFRAME (selected_frame)->output_method == output_msdos_raw))
1111 f->output_method = output_msdos_raw;
1112 else
1113 f->output_method = output_termcap;
1114 #else /* not MSDOS */
1115 f->output_method = output_termcap;
1116 create_tty_output (f);
1117 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
1118 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
1119 #endif /* not MSDOS */
1121 #ifdef HAVE_WINDOW_SYSTEM
1122 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
1123 f->horizontal_scroll_bars = false;
1124 #endif
1126 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
1127 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
1128 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
1129 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
1131 /* Set the top frame to the newly created frame. */
1132 if (FRAMEP (FRAME_TTY (f)->top_frame)
1133 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
1134 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
1136 FRAME_TTY (f)->top_frame = frame;
1138 if (!noninteractive)
1139 init_frame_faces (f);
1141 return f;
1144 /* Get a suitable value for frame parameter PARAMETER for a newly
1145 created frame, based on (1) the user-supplied frame parameter
1146 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
1148 static Lisp_Object
1149 get_future_frame_param (Lisp_Object parameter,
1150 Lisp_Object supplied_parms,
1151 char *current_value)
1153 Lisp_Object result;
1155 result = Fassq (parameter, supplied_parms);
1156 if (NILP (result))
1157 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
1158 if (NILP (result) && current_value != NULL)
1159 result = build_string (current_value);
1160 if (!NILP (result) && !STRINGP (result))
1161 result = XCDR (result);
1162 if (NILP (result) || !STRINGP (result))
1163 result = Qnil;
1165 return result;
1168 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
1169 1, 1, 0,
1170 doc: /* Create an additional terminal frame, possibly on another terminal.
1171 This function takes one argument, an alist specifying frame parameters.
1173 You can create multiple frames on a single text terminal, but only one
1174 of them (the selected terminal frame) is actually displayed.
1176 In practice, generally you don't need to specify any parameters,
1177 except when you want to create a new frame on another terminal.
1178 In that case, the `tty' parameter specifies the device file to open,
1179 and the `tty-type' parameter specifies the terminal type. Example:
1181 (make-terminal-frame \\='((tty . "/dev/pts/5") (tty-type . "xterm")))
1183 Note that changing the size of one terminal frame automatically
1184 affects all frames on the same terminal device. */)
1185 (Lisp_Object parms)
1187 struct frame *f;
1188 struct terminal *t = NULL;
1189 Lisp_Object frame, tem;
1190 struct frame *sf = SELECTED_FRAME ();
1192 #ifdef MSDOS
1193 if (sf->output_method != output_msdos_raw
1194 && sf->output_method != output_termcap)
1195 emacs_abort ();
1196 #else /* not MSDOS */
1198 #ifdef WINDOWSNT /* This should work now! */
1199 if (sf->output_method != output_termcap)
1200 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
1201 #endif
1202 #endif /* not MSDOS */
1205 Lisp_Object terminal;
1207 terminal = Fassq (Qterminal, parms);
1208 if (CONSP (terminal))
1210 terminal = XCDR (terminal);
1211 t = decode_live_terminal (terminal);
1213 #ifdef MSDOS
1214 if (t && t != the_only_display_info.terminal)
1215 /* msdos.c assumes a single tty_display_info object. */
1216 error ("Multiple terminals are not supported on this platform");
1217 if (!t)
1218 t = the_only_display_info.terminal;
1219 #endif
1222 if (!t)
1224 char *name = 0, *type = 0;
1225 Lisp_Object tty, tty_type;
1226 USE_SAFE_ALLOCA;
1228 tty = get_future_frame_param
1229 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1230 ? FRAME_TTY (XFRAME (selected_frame))->name
1231 : NULL));
1232 if (!NILP (tty))
1233 SAFE_ALLOCA_STRING (name, tty);
1235 tty_type = get_future_frame_param
1236 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1237 ? FRAME_TTY (XFRAME (selected_frame))->type
1238 : NULL));
1239 if (!NILP (tty_type))
1240 SAFE_ALLOCA_STRING (type, tty_type);
1242 t = init_tty (name, type, 0); /* Errors are not fatal. */
1243 SAFE_FREE ();
1246 f = make_terminal_frame (t);
1249 int width, height;
1250 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1251 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f),
1252 5, 0, Qterminal_frame);
1255 adjust_frame_glyphs (f);
1256 calculate_costs (f);
1257 XSETFRAME (frame, f);
1259 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1260 store_in_alist (&parms, Qtty,
1261 (t->display_info.tty->name
1262 ? build_string (t->display_info.tty->name)
1263 : Qnil));
1264 /* On terminal frames the `minibuffer' frame parameter is always
1265 virtually t. Avoid that a different value in parms causes
1266 complaints, see Bug#24758. */
1267 store_in_alist (&parms, Qminibuffer, Qt);
1268 Fmodify_frame_parameters (frame, parms);
1270 /* Make the frame face alist be frame-specific, so that each
1271 frame could change its face definitions independently. */
1272 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1273 /* Simple Fcopy_alist isn't enough, because we need the contents of
1274 the vectors which are the CDRs of associations in face_alist to
1275 be copied as well. */
1276 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1277 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1279 f->can_x_set_window_size = true;
1280 f->after_make_frame = true;
1282 return frame;
1286 /* Perform the switch to frame FRAME.
1288 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1289 FRAME1 as frame.
1291 If TRACK is non-zero and the frame that currently has the focus
1292 redirects its focus to the selected frame, redirect that focused
1293 frame's focus to FRAME instead.
1295 FOR_DELETION non-zero means that the selected frame is being
1296 deleted, which includes the possibility that the frame's terminal
1297 is dead.
1299 The value of NORECORD is passed as argument to Fselect_window. */
1301 Lisp_Object
1302 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1304 struct frame *sf = SELECTED_FRAME (), *f;
1306 /* If FRAME is a switch-frame event, extract the frame we should
1307 switch to. */
1308 if (CONSP (frame)
1309 && EQ (XCAR (frame), Qswitch_frame)
1310 && CONSP (XCDR (frame)))
1311 frame = XCAR (XCDR (frame));
1313 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1314 a switch-frame event to arrive after a frame is no longer live,
1315 especially when deleting the initial frame during startup. */
1316 CHECK_FRAME (frame);
1317 f = XFRAME (frame);
1318 if (!FRAME_LIVE_P (f))
1319 return Qnil;
1320 else if (f == sf)
1321 return frame;
1323 /* If a frame's focus has been redirected toward the currently
1324 selected frame, we should change the redirection to point to the
1325 newly selected frame. This means that if the focus is redirected
1326 from a minibufferless frame to a surrogate minibuffer frame, we
1327 can use `other-window' to switch between all the frames using
1328 that minibuffer frame, and the focus redirection will follow us
1329 around. */
1330 #if 0
1331 /* This is too greedy; it causes inappropriate focus redirection
1332 that's hard to get rid of. */
1333 if (track)
1335 Lisp_Object tail;
1337 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1339 Lisp_Object focus;
1341 if (!FRAMEP (XCAR (tail)))
1342 emacs_abort ();
1344 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1346 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1347 Fredirect_frame_focus (XCAR (tail), frame);
1350 #else /* ! 0 */
1351 /* Instead, apply it only to the frame we're pointing to. */
1352 #ifdef HAVE_WINDOW_SYSTEM
1353 if (track && FRAME_WINDOW_P (f))
1355 Lisp_Object focus, xfocus;
1357 xfocus = x_get_focus_frame (f);
1358 if (FRAMEP (xfocus))
1360 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1361 if ((FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1362 /* Redirect frame focus also when FRAME has its minibuffer
1363 window on the selected frame (see Bug#24500). */
1364 || (NILP (focus)
1365 && EQ (FRAME_MINIBUF_WINDOW (f), sf->selected_window)))
1366 Fredirect_frame_focus (xfocus, frame);
1369 #endif /* HAVE_X_WINDOWS */
1370 #endif /* ! 0 */
1372 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1373 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1375 if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
1377 struct tty_display_info *tty = FRAME_TTY (f);
1378 Lisp_Object top_frame = tty->top_frame;
1380 /* Don't mark the frame garbaged and/or obscured if we are
1381 switching to the frame that is already the top frame of that
1382 TTY. */
1383 if (!EQ (frame, top_frame))
1385 if (FRAMEP (top_frame))
1386 /* Mark previously displayed frame as now obscured. */
1387 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1388 SET_FRAME_VISIBLE (f, 1);
1389 /* If the new TTY frame changed dimensions, we need to
1390 resync term.c's idea of the frame size with the new
1391 frame's data. */
1392 if (FRAME_COLS (f) != FrameCols (tty))
1393 FrameCols (tty) = FRAME_COLS (f);
1394 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1395 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1397 tty->top_frame = frame;
1400 selected_frame = frame;
1401 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1402 last_nonminibuf_frame = XFRAME (selected_frame);
1404 Fselect_window (f->selected_window, norecord);
1406 /* We want to make sure that the next event generates a frame-switch
1407 event to the appropriate frame. This seems kludgy to me, but
1408 before you take it out, make sure that evaluating something like
1409 (select-window (frame-root-window (new-frame))) doesn't end up
1410 with your typing being interpreted in the new frame instead of
1411 the one you're actually typing in. */
1412 #ifdef HAVE_WINDOW_SYSTEM
1413 if (!frame_ancestor_p (f, sf))
1414 #endif
1415 internal_last_event_frame = Qnil;
1417 return frame;
1420 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1421 doc: /* Select FRAME.
1422 Subsequent editing commands apply to its selected window.
1423 Optional argument NORECORD means to neither change the order of
1424 recently selected windows nor the buffer list.
1426 The selection of FRAME lasts until the next time the user does
1427 something to select a different frame, or until the next time
1428 this function is called. If you are using a window system, the
1429 previously selected frame may be restored as the selected frame
1430 when returning to the command loop, because it still may have
1431 the window system's input focus. On a text terminal, the next
1432 redisplay will display FRAME.
1434 This function returns FRAME, or nil if FRAME has been deleted. */)
1435 (Lisp_Object frame, Lisp_Object norecord)
1437 return do_switch_frame (frame, 1, 0, norecord);
1440 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1441 doc: /* Handle a switch-frame event EVENT.
1442 Switch-frame events are usually bound to this function.
1443 A switch-frame event tells Emacs that the window manager has requested
1444 that the user's events be directed to the frame mentioned in the event.
1445 This function selects the selected window of the frame of EVENT.
1447 If EVENT is frame object, handle it as if it were a switch-frame event
1448 to that frame. */)
1449 (Lisp_Object event)
1451 Lisp_Object value;
1453 /* Preserve prefix arg that the command loop just cleared. */
1454 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1455 run_hook (Qmouse_leave_buffer_hook);
1456 /* `switch-frame' implies a focus in. */
1457 value = do_switch_frame (event, 0, 0, Qnil);
1458 call1 (intern ("handle-focus-in"), event);
1459 return value;
1462 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1463 doc: /* Return the frame that is now selected. */)
1464 (void)
1466 return selected_frame;
1469 DEFUN ("frame-list", Fframe_list, Sframe_list,
1470 0, 0, 0,
1471 doc: /* Return a list of all live frames.
1472 The return value does not include any tooltip frame. */)
1473 (void)
1475 #ifdef HAVE_WINDOW_SYSTEM
1476 Lisp_Object list = Qnil, tail, frame;
1478 FOR_EACH_FRAME (tail, frame)
1479 if (!FRAME_TOOLTIP_P (XFRAME (frame)))
1480 list = Fcons (frame, list);
1481 /* Reverse list for consistency with the !HAVE_WINDOW_SYSTEM case. */
1482 return Fnreverse (list);
1483 #else /* !HAVE_WINDOW_SYSTEM */
1484 return Fcopy_sequence (Vframe_list);
1485 #endif /* HAVE_WINDOW_SYSTEM */
1488 DEFUN ("frame-parent", Fframe_parent, Sframe_parent,
1489 0, 1, 0,
1490 doc: /* Return the parent frame of FRAME.
1491 The parent frame of FRAME is the Emacs frame whose window-system window
1492 is the parent window of FRAME's window-system window. When such a frame
1493 exists, FRAME is considered a child frame of that frame.
1495 Return nil if FRAME has no parent frame. This means that FRAME's
1496 window-system window is either a "top-level" window (a window whose
1497 parent window is the window-system's root window) or an embedded window
1498 \(a window whose parent window is owned by some other application). */)
1499 (Lisp_Object frame)
1501 struct frame *f = decode_live_frame (frame);
1502 struct frame *p = FRAME_PARENT_FRAME (f);
1503 Lisp_Object parent;
1505 /* Can't return f->parent_frame directly since it might not be defined
1506 for this platform. */
1507 if (p)
1509 XSETFRAME (parent, p);
1511 return parent;
1513 else
1514 return Qnil;
1517 #ifdef HAVE_WINDOW_SYSTEM
1518 bool
1519 frame_ancestor_p (struct frame *af, struct frame *df)
1521 struct frame *pf = FRAME_PARENT_FRAME (df);
1523 while (pf)
1525 if (pf == af)
1526 return true;
1527 else
1528 pf = FRAME_PARENT_FRAME (pf);
1531 return false;
1533 #endif
1535 DEFUN ("frame-ancestor-p", Fframe_ancestor_p, Sframe_ancestor_p,
1536 2, 2, 0,
1537 doc: /* Return non-nil if ANCESTOR is an ancestor of DESCENDANT.
1538 ANCESTOR is an ancestor of DESCENDANT when it is either DESCENDANT's
1539 parent frame or it is an ancestor of DESCENDANT's parent frame. Both,
1540 ANCESTOR and DESCENDANT must be live frames and default to the selected
1541 frame. */)
1542 (Lisp_Object ancestor, Lisp_Object descendant)
1544 #ifdef HAVE_WINDOW_SYSTEM
1545 struct frame *af = decode_live_frame (ancestor);
1546 struct frame *df = decode_live_frame (descendant);
1548 return frame_ancestor_p (af, df) ? Qt : Qnil;
1549 #else
1550 return Qnil;
1551 #endif
1554 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1555 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1556 If MINIBUF is nil, do not consider minibuffer-only candidate.
1557 If MINIBUF is `visible', do not consider an invisible candidate.
1558 If MINIBUF is a window, consider only its own frame and candidate now
1559 using that window as the minibuffer.
1560 If MINIBUF is 0, consider candidate if it is visible or iconified.
1561 Otherwise consider any candidate and return nil if CANDIDATE is not
1562 acceptable. */
1564 static Lisp_Object
1565 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1567 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1569 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1570 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1571 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1572 && FRAME_TTY (c) == FRAME_TTY (f)))
1574 if (!NILP (get_frame_param (c, Qno_other_frame)))
1575 return Qnil;
1576 else if (NILP (minibuf))
1578 if (!FRAME_MINIBUF_ONLY_P (c))
1579 return candidate;
1581 else if (EQ (minibuf, Qvisible))
1583 if (FRAME_VISIBLE_P (c))
1584 return candidate;
1586 else if (WINDOWP (minibuf))
1588 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1589 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1590 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1591 FRAME_FOCUS_FRAME (c)))
1592 return candidate;
1594 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1596 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1597 return candidate;
1599 else
1600 return candidate;
1602 return Qnil;
1605 /* Return the next frame in the frame list after FRAME. */
1607 static Lisp_Object
1608 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1610 Lisp_Object f, tail;
1611 int passed = 0;
1613 eassume (CONSP (Vframe_list));
1615 while (passed < 2)
1616 FOR_EACH_FRAME (tail, f)
1618 if (passed)
1620 f = candidate_frame (f, frame, minibuf);
1621 if (!NILP (f))
1622 return f;
1624 if (EQ (frame, f))
1625 passed++;
1627 return frame;
1630 /* Return the previous frame in the frame list before FRAME. */
1632 static Lisp_Object
1633 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1635 Lisp_Object f, tail, prev = Qnil;
1637 eassume (CONSP (Vframe_list));
1639 FOR_EACH_FRAME (tail, f)
1641 if (EQ (frame, f) && !NILP (prev))
1642 return prev;
1643 f = candidate_frame (f, frame, minibuf);
1644 if (!NILP (f))
1645 prev = f;
1648 /* We've scanned the entire list. */
1649 if (NILP (prev))
1650 /* We went through the whole frame list without finding a single
1651 acceptable frame. Return the original frame. */
1652 return frame;
1653 else
1654 /* There were no acceptable frames in the list before FRAME; otherwise,
1655 we would have returned directly from the loop. Since PREV is the last
1656 acceptable frame in the list, return it. */
1657 return prev;
1661 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1662 doc: /* Return the next frame in the frame list after FRAME.
1663 It considers only frames on the same terminal as FRAME.
1664 By default, skip minibuffer-only frames.
1665 If omitted, FRAME defaults to the selected frame.
1666 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1667 If MINIFRAME is a window, include only its own frame
1668 and any frame now using that window as the minibuffer.
1669 If MINIFRAME is `visible', include all visible frames.
1670 If MINIFRAME is 0, include all visible and iconified frames.
1671 Otherwise, include all frames. */)
1672 (Lisp_Object frame, Lisp_Object miniframe)
1674 if (NILP (frame))
1675 frame = selected_frame;
1676 CHECK_LIVE_FRAME (frame);
1677 return next_frame (frame, miniframe);
1680 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1681 doc: /* Return the previous frame in the frame list before FRAME.
1682 It considers only frames on the same terminal as FRAME.
1683 By default, skip minibuffer-only frames.
1684 If omitted, FRAME defaults to the selected frame.
1685 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1686 If MINIFRAME is a window, include only its own frame
1687 and any frame now using that window as the minibuffer.
1688 If MINIFRAME is `visible', include all visible frames.
1689 If MINIFRAME is 0, include all visible and iconified frames.
1690 Otherwise, include all frames. */)
1691 (Lisp_Object frame, Lisp_Object miniframe)
1693 if (NILP (frame))
1694 frame = selected_frame;
1695 CHECK_LIVE_FRAME (frame);
1696 return prev_frame (frame, miniframe);
1699 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1700 Slast_nonminibuf_frame, 0, 0, 0,
1701 doc: /* Return last non-minibuffer frame selected. */)
1702 (void)
1704 Lisp_Object frame = Qnil;
1706 if (last_nonminibuf_frame)
1707 XSETFRAME (frame, last_nonminibuf_frame);
1709 return frame;
1713 * other_frames:
1715 * Return true if there exists at least one visible or iconified frame
1716 * but F. Tooltip frames do not qualify as candidates. Return false
1717 * if no such frame exists.
1719 * INVISIBLE true means we are called from make_frame_invisible where
1720 * such a frame must be visible or iconified. INVISIBLE nil means we
1721 * are called from delete_frame. In that case FORCE true means that the
1722 * visibility status of such a frame can be ignored.
1724 * If F is the terminal frame and we are using X, return true if at
1725 * least one X frame exists.
1727 static bool
1728 other_frames (struct frame *f, bool invisible, bool force)
1730 Lisp_Object frames, frame, frame1;
1731 Lisp_Object minibuffer_window = FRAME_MINIBUF_WINDOW (f);
1733 XSETFRAME (frame, f);
1734 if (WINDOWP (minibuffer_window)
1735 && !EQ (frame, WINDOW_FRAME (XWINDOW (minibuffer_window))))
1736 minibuffer_window = Qnil;
1738 FOR_EACH_FRAME (frames, frame1)
1740 struct frame *f1 = XFRAME (frame1);
1742 if (f != f1)
1744 /* Verify that we can still talk to the frame's X window, and
1745 note any recent change in visibility. */
1746 #ifdef HAVE_X_WINDOWS
1747 if (FRAME_WINDOW_P (f1))
1748 x_sync (f1);
1749 #endif
1750 if (!FRAME_TOOLTIP_P (f1)
1751 /* Tooltips and child frames count neither for
1752 invisibility nor for deletions. */
1753 && !FRAME_PARENT_FRAME (f1)
1754 /* Frames with a non-nil `delete-before' parameter don't
1755 count for deletions. */
1756 && (invisible || NILP (get_frame_param (f1, Qdelete_before)))
1757 /* For invisibility and normal deletions, at least one
1758 visible or iconified frame must remain (Bug#26682). */
1759 && (FRAME_VISIBLE_P (f1) || FRAME_ICONIFIED_P (f1)
1760 || (!invisible
1761 && (force
1762 /* Allow deleting the terminal frame when at
1763 least one X frame exists. */
1764 || (FRAME_WINDOW_P (f1) && !FRAME_WINDOW_P (f))))))
1765 return true;
1769 return false;
1772 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1773 window. Preferably use the selected frame's minibuffer window
1774 instead. If the selected frame doesn't have one, get some other
1775 frame's minibuffer window. SELECT non-zero means select the new
1776 minibuffer window. */
1777 static void
1778 check_minibuf_window (Lisp_Object frame, int select)
1780 struct frame *f = decode_live_frame (frame);
1782 XSETFRAME (frame, f);
1784 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1786 Lisp_Object frames, this, window = make_number (0);
1788 if (!EQ (frame, selected_frame)
1789 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1790 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1791 else
1792 FOR_EACH_FRAME (frames, this)
1794 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1796 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1797 break;
1801 /* Don't abort if no window was found (Bug#15247). */
1802 if (WINDOWP (window))
1804 /* Use set_window_buffer instead of Fset_window_buffer (see
1805 discussion of bug#11984, bug#12025, bug#12026). */
1806 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1807 minibuf_window = window;
1809 /* SELECT non-zero usually means that FRAME's minibuffer
1810 window was selected; select the new one. */
1811 if (select)
1812 Fselect_window (minibuf_window, Qnil);
1819 * delete_frame:
1821 * Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1822 * unconditionally. x_connection_closed and delete_terminal use this.
1823 * Any other value of FORCE implements the semantics described for
1824 * Fdelete_frame. */
1825 Lisp_Object
1826 delete_frame (Lisp_Object frame, Lisp_Object force)
1828 struct frame *f = decode_any_frame (frame);
1829 struct frame *sf;
1830 struct kboard *kb;
1831 Lisp_Object frames, frame1;
1832 int minibuffer_selected, is_tooltip_frame;
1833 bool nochild = !FRAME_PARENT_FRAME (f);
1835 if (!FRAME_LIVE_P (f))
1836 return Qnil;
1837 else if (!EQ (force, Qnoelisp) && !other_frames (f, false, !NILP (force)))
1839 if (NILP (force))
1840 error ("Attempt to delete the sole visible or iconified frame");
1841 else
1842 error ("Attempt to delete the only frame");
1845 XSETFRAME (frame, f);
1847 /* Softly delete all frames with this frame as their parent frame or
1848 as their `delete-before' frame parameter value. */
1849 FOR_EACH_FRAME (frames, frame1)
1850 if (FRAME_PARENT_FRAME (XFRAME (frame1)) == f
1851 /* Process `delete-before' parameter iff FRAME is not a child
1852 frame. This avoids that we enter an infinite chain of mixed
1853 dependencies. */
1854 || (nochild
1855 && EQ (get_frame_param (XFRAME (frame1), Qdelete_before), frame)))
1856 delete_frame (frame1, Qnil);
1858 /* Does this frame have a minibuffer, and is it the surrogate
1859 minibuffer for any other frame? */
1860 if (FRAME_HAS_MINIBUF_P (f))
1862 FOR_EACH_FRAME (frames, frame1)
1864 Lisp_Object fminiw;
1866 if (EQ (frame1, frame))
1867 continue;
1869 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (frame1));
1871 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1873 /* If we MUST delete this frame, delete the other first.
1874 But do this only if FORCE equals `noelisp'. */
1875 if (EQ (force, Qnoelisp))
1876 delete_frame (frame1, Qnoelisp);
1877 else
1878 error ("Attempt to delete a surrogate minibuffer frame");
1883 is_tooltip_frame = FRAME_TOOLTIP_P (f);
1885 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1886 frame is a tooltip. FORCE is set to `noelisp' when handling
1887 a disconnect from the terminal, so we don't dare call Lisp
1888 code. */
1889 if (NILP (Vrun_hooks) || is_tooltip_frame)
1891 else if (EQ (force, Qnoelisp))
1892 pending_funcalls
1893 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1894 pending_funcalls);
1895 else
1897 #ifdef HAVE_X_WINDOWS
1898 /* Also, save clipboard to the clipboard manager. */
1899 x_clipboard_manager_save_frame (frame);
1900 #endif
1902 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1905 /* delete_frame_functions may have deleted any frame, including this
1906 one. */
1907 if (!FRAME_LIVE_P (f))
1908 return Qnil;
1909 else if (!EQ (force, Qnoelisp) && !other_frames (f, false, !NILP (force)))
1911 if (NILP (force))
1912 error ("Attempt to delete the sole visible or iconified frame");
1913 else
1914 error ("Attempt to delete the only frame");
1917 /* At this point, we are committed to deleting the frame.
1918 There is no more chance for errors to prevent it. */
1919 minibuffer_selected = EQ (minibuf_window, selected_window);
1920 sf = SELECTED_FRAME ();
1921 /* Don't let the frame remain selected. */
1922 if (f == sf)
1924 Lisp_Object tail;
1925 eassume (CONSP (Vframe_list));
1927 /* Look for another visible frame on the same terminal.
1928 Do not call next_frame here because it may loop forever.
1929 See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1930 FOR_EACH_FRAME (tail, frame1)
1932 struct frame *f1 = XFRAME (frame1);
1934 if (!EQ (frame, frame1)
1935 && !FRAME_TOOLTIP_P (f1)
1936 && FRAME_TERMINAL (f) == FRAME_TERMINAL (f1)
1937 && FRAME_VISIBLE_P (f1))
1938 break;
1941 /* If there is none, find *some* other frame. */
1942 if (NILP (frame1) || EQ (frame1, frame))
1944 FOR_EACH_FRAME (tail, frame1)
1946 struct frame *f1 = XFRAME (frame1);
1948 if (!EQ (frame, frame1)
1949 && FRAME_LIVE_P (f1)
1950 && !FRAME_TOOLTIP_P (f1))
1952 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1954 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1956 if (!EQ (top_frame, frame))
1957 frame1 = top_frame;
1959 break;
1963 #ifdef NS_IMPL_COCOA
1964 else
1965 /* Under NS, there is no system mechanism for choosing a new
1966 window to get focus -- it is left to application code.
1967 So the portion of THIS application interfacing with NS
1968 needs to know about it. We call Fraise_frame, but the
1969 purpose is really to transfer focus. */
1970 Fraise_frame (frame1);
1971 #endif
1973 do_switch_frame (frame1, 0, 1, Qnil);
1974 sf = SELECTED_FRAME ();
1977 /* Don't allow minibuf_window to remain on a deleted frame. */
1978 check_minibuf_window (frame, minibuffer_selected);
1980 /* Don't let echo_area_window to remain on a deleted frame. */
1981 if (EQ (f->minibuffer_window, echo_area_window))
1982 echo_area_window = sf->minibuffer_window;
1984 /* Clear any X selections for this frame. */
1985 #ifdef HAVE_X_WINDOWS
1986 if (FRAME_X_P (f))
1987 x_clear_frame_selections (f);
1988 #endif
1990 /* Free glyphs.
1991 This function must be called before the window tree of the
1992 frame is deleted because windows contain dynamically allocated
1993 memory. */
1994 free_glyphs (f);
1996 #ifdef HAVE_WINDOW_SYSTEM
1997 /* Give chance to each font driver to free a frame specific data. */
1998 font_update_drivers (f, Qnil);
1999 #endif
2001 /* Mark all the windows that used to be on FRAME as deleted, and then
2002 remove the reference to them. */
2003 delete_all_child_windows (f->root_window);
2004 fset_root_window (f, Qnil);
2006 Vframe_list = Fdelq (frame, Vframe_list);
2007 SET_FRAME_VISIBLE (f, 0);
2009 /* Allow the vector of menu bar contents to be freed in the next
2010 garbage collection. The frame object itself may not be garbage
2011 collected until much later, because recent_keys and other data
2012 structures can still refer to it. */
2013 fset_menu_bar_vector (f, Qnil);
2015 /* If FRAME's buffer lists contains killed
2016 buffers, this helps GC to reclaim them. */
2017 fset_buffer_list (f, Qnil);
2018 fset_buried_buffer_list (f, Qnil);
2020 free_font_driver_list (f);
2021 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2022 xfree (f->namebuf);
2023 #endif
2024 xfree (f->decode_mode_spec_buffer);
2025 xfree (FRAME_INSERT_COST (f));
2026 xfree (FRAME_DELETEN_COST (f));
2027 xfree (FRAME_INSERTN_COST (f));
2028 xfree (FRAME_DELETE_COST (f));
2030 /* Since some events are handled at the interrupt level, we may get
2031 an event for f at any time; if we zero out the frame's terminal
2032 now, then we may trip up the event-handling code. Instead, we'll
2033 promise that the terminal of the frame must be valid until we
2034 have called the window-system-dependent frame destruction
2035 routine. */
2037 struct terminal *terminal;
2038 block_input ();
2039 if (FRAME_TERMINAL (f)->delete_frame_hook)
2040 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
2041 terminal = FRAME_TERMINAL (f);
2042 f->output_data.nothing = 0;
2043 f->terminal = 0; /* Now the frame is dead. */
2044 unblock_input ();
2046 /* If needed, delete the terminal that this frame was on.
2047 (This must be done after the frame is killed.) */
2048 terminal->reference_count--;
2049 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
2050 /* FIXME: Deleting the terminal crashes emacs because of a GTK
2051 bug.
2052 https://lists.gnu.org/r/emacs-devel/2011-10/msg00363.html */
2054 /* Since a similar behavior was observed on the Lucid and Motif
2055 builds (see Bug#5802, Bug#21509, Bug#23499, Bug#27816), we now
2056 don't delete the terminal for these builds either. */
2057 if (terminal->reference_count == 0 && terminal->type == output_x_window)
2058 terminal->reference_count = 1;
2059 #endif /* USE_X_TOOLKIT || USE_GTK */
2060 if (terminal->reference_count == 0)
2062 Lisp_Object tmp;
2063 XSETTERMINAL (tmp, terminal);
2065 kb = NULL;
2066 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
2068 else
2069 kb = terminal->kboard;
2072 /* If we've deleted the last_nonminibuf_frame, then try to find
2073 another one. */
2074 if (f == last_nonminibuf_frame)
2076 last_nonminibuf_frame = 0;
2078 FOR_EACH_FRAME (frames, frame1)
2080 struct frame *f1 = XFRAME (frame1);
2082 if (!FRAME_MINIBUF_ONLY_P (f1))
2084 last_nonminibuf_frame = f1;
2085 break;
2090 /* If there's no other frame on the same kboard, get out of
2091 single-kboard state if we're in it for this kboard. */
2092 if (kb != NULL)
2094 /* Some frame we found on the same kboard, or nil if there are none. */
2095 Lisp_Object frame_on_same_kboard = Qnil;
2097 FOR_EACH_FRAME (frames, frame1)
2098 if (kb == FRAME_KBOARD (XFRAME (frame1)))
2099 frame_on_same_kboard = frame1;
2101 if (NILP (frame_on_same_kboard))
2102 not_single_kboard_state (kb);
2106 /* If we've deleted this keyboard's default_minibuffer_frame, try to
2107 find another one. Prefer minibuffer-only frames, but also notice
2108 frames with other windows. */
2109 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
2111 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
2112 Lisp_Object frame_with_minibuf = Qnil;
2113 /* Some frame we found on the same kboard, or nil if there are none. */
2114 Lisp_Object frame_on_same_kboard = Qnil;
2116 FOR_EACH_FRAME (frames, frame1)
2118 struct frame *f1 = XFRAME (frame1);
2120 /* Consider only frames on the same kboard
2121 and only those with minibuffers. */
2122 if (kb == FRAME_KBOARD (f1)
2123 && FRAME_HAS_MINIBUF_P (f1))
2125 frame_with_minibuf = frame1;
2126 if (FRAME_MINIBUF_ONLY_P (f1))
2127 break;
2130 if (kb == FRAME_KBOARD (f1))
2131 frame_on_same_kboard = frame1;
2134 if (!NILP (frame_on_same_kboard))
2136 /* We know that there must be some frame with a minibuffer out
2137 there. If this were not true, all of the frames present
2138 would have to be minibufferless, which implies that at some
2139 point their minibuffer frames must have been deleted, but
2140 that is prohibited at the top; you can't delete surrogate
2141 minibuffer frames. */
2142 if (NILP (frame_with_minibuf))
2143 emacs_abort ();
2145 kset_default_minibuffer_frame (kb, frame_with_minibuf);
2147 else
2148 /* No frames left on this kboard--say no minibuffer either. */
2149 kset_default_minibuffer_frame (kb, Qnil);
2152 /* Cause frame titles to update--necessary if we now have just one frame. */
2153 if (!is_tooltip_frame)
2154 update_mode_lines = 15;
2156 return Qnil;
2159 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
2160 doc: /* Delete FRAME, permanently eliminating it from use.
2161 FRAME must be a live frame and defaults to the selected one.
2163 A frame may not be deleted if its minibuffer serves as surrogate
2164 minibuffer for another frame. Normally, you may not delete a frame if
2165 all other frames are invisible, but if the second optional argument
2166 FORCE is non-nil, you may do so.
2168 This function runs `delete-frame-functions' before actually
2169 deleting the frame, unless the frame is a tooltip.
2170 The functions are run with one argument, the frame to be deleted. */)
2171 (Lisp_Object frame, Lisp_Object force)
2173 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
2176 #ifdef HAVE_WINDOW_SYSTEM
2178 * frame_internal_border_part:
2180 * Return part of internal border the coordinates X and Y relative to
2181 * frame F are on. Return nil if the coordinates are not on the
2182 * internal border of F.
2184 * Return one of INTERNAL_BORDER_LEFT_EDGE, INTERNAL_BORDER_TOP_EDGE,
2185 * INTERNAL_BORDER_RIGHT_EDGE or INTERNAL_BORDER_BOTTOM_EDGE when the
2186 * mouse cursor is on the corresponding border with an offset of at
2187 * least one canonical character height from that border's edges.
2189 * If no border part could be found this way, return one of
2190 * INTERNAL_BORDER_TOP_LEFT_CORNER, INTERNAL_BORDER_TOP_RIGHT_CORNER,
2191 * INTERNAL_BORDER_BOTTOM_LEFT_CORNER or
2192 * INTERNAL_BORDER_BOTTOM_RIGHT_CORNER to indicate that the mouse is in
2193 * one of the corresponding corners. This means that for very small
2194 * frames an `edge' return value is preferred.
2196 enum internal_border_part
2197 frame_internal_border_part (struct frame *f, int x, int y)
2199 int border = FRAME_INTERNAL_BORDER_WIDTH (f);
2200 int offset = FRAME_LINE_HEIGHT (f);
2201 int width = FRAME_PIXEL_WIDTH (f);
2202 int height = FRAME_PIXEL_HEIGHT (f);
2203 enum internal_border_part part = INTERNAL_BORDER_NONE;
2205 if (offset < border)
2206 /* For very wide borders make offset at least as large as
2207 border. */
2208 offset = border;
2210 if (offset < x && x < width - offset)
2211 /* Top or bottom border. */
2213 if (0 <= y && y <= border)
2214 part = INTERNAL_BORDER_TOP_EDGE;
2215 else if (height - border <= y && y <= height)
2216 part = INTERNAL_BORDER_BOTTOM_EDGE;
2218 else if (offset < y && y < height - offset)
2219 /* Left or right border. */
2221 if (0 <= x && x <= border)
2222 part = INTERNAL_BORDER_LEFT_EDGE;
2223 else if (width - border <= x && x <= width)
2224 part = INTERNAL_BORDER_RIGHT_EDGE;
2226 else
2228 /* An edge. */
2229 int half_width = width / 2;
2230 int half_height = height / 2;
2232 if (0 <= x && x <= border)
2234 /* A left edge. */
2235 if (0 <= y && y <= half_height)
2236 part = INTERNAL_BORDER_TOP_LEFT_CORNER;
2237 else if (half_height < y && y <= height)
2238 part = INTERNAL_BORDER_BOTTOM_LEFT_CORNER;
2240 else if (width - border <= x && x <= width)
2242 /* A right edge. */
2243 if (0 <= y && y <= half_height)
2244 part = INTERNAL_BORDER_TOP_RIGHT_CORNER;
2245 else if (half_height < y && y <= height)
2246 part = INTERNAL_BORDER_BOTTOM_RIGHT_CORNER;
2248 else if (0 <= y && y <= border)
2250 /* A top edge. */
2251 if (0 <= x && x <= half_width)
2252 part = INTERNAL_BORDER_TOP_LEFT_CORNER;
2253 else if (half_width < x && x <= width)
2254 part = INTERNAL_BORDER_TOP_RIGHT_CORNER;
2256 else if (height - border <= y && y <= height)
2258 /* A bottom edge. */
2259 if (0 <= x && x <= half_width)
2260 part = INTERNAL_BORDER_BOTTOM_LEFT_CORNER;
2261 else if (half_width < x && x <= width)
2262 part = INTERNAL_BORDER_BOTTOM_RIGHT_CORNER;
2266 return part;
2268 #endif
2270 /* Return mouse position in character cell units. */
2272 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
2273 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
2274 The position is given in canonical character cells, where (0, 0) is the
2275 upper-left corner of the frame, X is the horizontal offset, and Y is the
2276 vertical offset, measured in units of the frame's default character size.
2277 If Emacs is running on a mouseless terminal or hasn't been programmed
2278 to read the mouse position, it returns the selected frame for FRAME
2279 and nil for X and Y.
2280 If `mouse-position-function' is non-nil, `mouse-position' calls it,
2281 passing the normal return value to that function as an argument,
2282 and returns whatever that function returns. */)
2283 (void)
2285 struct frame *f;
2286 Lisp_Object lispy_dummy;
2287 Lisp_Object x, y, retval;
2289 f = SELECTED_FRAME ();
2290 x = y = Qnil;
2292 /* It's okay for the hook to refrain from storing anything. */
2293 if (FRAME_TERMINAL (f)->mouse_position_hook)
2295 enum scroll_bar_part party_dummy;
2296 Time time_dummy;
2297 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
2298 &lispy_dummy, &party_dummy,
2299 &x, &y,
2300 &time_dummy);
2303 if (! NILP (x))
2305 int col = XINT (x);
2306 int row = XINT (y);
2307 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
2308 XSETINT (x, col);
2309 XSETINT (y, row);
2311 XSETFRAME (lispy_dummy, f);
2312 retval = Fcons (lispy_dummy, Fcons (x, y));
2313 if (!NILP (Vmouse_position_function))
2314 retval = call1 (Vmouse_position_function, retval);
2315 return retval;
2318 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
2319 Smouse_pixel_position, 0, 0, 0,
2320 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
2321 The position is given in pixel units, where (0, 0) is the
2322 upper-left corner of the frame, X is the horizontal offset, and Y is
2323 the vertical offset.
2324 If Emacs is running on a mouseless terminal or hasn't been programmed
2325 to read the mouse position, it returns the selected frame for FRAME
2326 and nil for X and Y. */)
2327 (void)
2329 struct frame *f;
2330 Lisp_Object lispy_dummy;
2331 Lisp_Object x, y, retval;
2333 f = SELECTED_FRAME ();
2334 x = y = Qnil;
2336 /* It's okay for the hook to refrain from storing anything. */
2337 if (FRAME_TERMINAL (f)->mouse_position_hook)
2339 enum scroll_bar_part party_dummy;
2340 Time time_dummy;
2341 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
2342 &lispy_dummy, &party_dummy,
2343 &x, &y,
2344 &time_dummy);
2347 XSETFRAME (lispy_dummy, f);
2348 retval = Fcons (lispy_dummy, Fcons (x, y));
2349 if (!NILP (Vmouse_position_function))
2350 retval = call1 (Vmouse_position_function, retval);
2351 return retval;
2354 #ifdef HAVE_WINDOW_SYSTEM
2356 /* On frame F, convert character coordinates X and Y to pixel
2357 coordinates *PIX_X and *PIX_Y. */
2359 static void
2360 frame_char_to_pixel_position (struct frame *f, int x, int y,
2361 int *pix_x, int *pix_y)
2363 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
2364 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
2366 if (*pix_x < 0)
2367 *pix_x = 0;
2368 if (*pix_x > FRAME_PIXEL_WIDTH (f))
2369 *pix_x = FRAME_PIXEL_WIDTH (f);
2371 if (*pix_y < 0)
2372 *pix_y = 0;
2373 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
2374 *pix_y = FRAME_PIXEL_HEIGHT (f);
2377 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
2379 static void
2380 frame_set_mouse_position (struct frame *f, int x, int y)
2382 int pix_x, pix_y;
2384 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
2385 frame_set_mouse_pixel_position (f, pix_x, pix_y);
2388 #endif /* HAVE_WINDOW_SYSTEM */
2390 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
2391 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
2392 Coordinates are relative to the frame, not a window,
2393 so the coordinates of the top left character in the frame
2394 may be nonzero due to left-hand scroll bars or the menu bar.
2396 The position is given in canonical character cells, where (0, 0) is
2397 the upper-left corner of the frame, X is the horizontal offset, and
2398 Y is the vertical offset, measured in units of the frame's default
2399 character size.
2401 This function is a no-op for an X frame that is not visible.
2402 If you have just created a frame, you must wait for it to become visible
2403 before calling this function on it, like this.
2404 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2405 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2407 CHECK_LIVE_FRAME (frame);
2408 CHECK_TYPE_RANGED_INTEGER (int, x);
2409 CHECK_TYPE_RANGED_INTEGER (int, y);
2411 /* I think this should be done with a hook. */
2412 #ifdef HAVE_WINDOW_SYSTEM
2413 if (FRAME_WINDOW_P (XFRAME (frame)))
2414 /* Warping the mouse will cause enternotify and focus events. */
2415 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
2416 #else
2417 #if defined (MSDOS)
2418 if (FRAME_MSDOS_P (XFRAME (frame)))
2420 Fselect_frame (frame, Qnil);
2421 mouse_moveto (XINT (x), XINT (y));
2423 #else
2424 #ifdef HAVE_GPM
2426 Fselect_frame (frame, Qnil);
2427 term_mouse_moveto (XINT (x), XINT (y));
2429 #endif
2430 #endif
2431 #endif
2433 return Qnil;
2436 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
2437 Sset_mouse_pixel_position, 3, 3, 0,
2438 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
2439 The position is given in pixels, where (0, 0) is the upper-left corner
2440 of the frame, X is the horizontal offset, and Y is the vertical offset.
2442 Note, this is a no-op for an X frame that is not visible.
2443 If you have just created a frame, you must wait for it to become visible
2444 before calling this function on it, like this.
2445 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2446 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2448 CHECK_LIVE_FRAME (frame);
2449 CHECK_TYPE_RANGED_INTEGER (int, x);
2450 CHECK_TYPE_RANGED_INTEGER (int, y);
2452 /* I think this should be done with a hook. */
2453 #ifdef HAVE_WINDOW_SYSTEM
2454 if (FRAME_WINDOW_P (XFRAME (frame)))
2455 /* Warping the mouse will cause enternotify and focus events. */
2456 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
2457 #else
2458 #if defined (MSDOS)
2459 if (FRAME_MSDOS_P (XFRAME (frame)))
2461 Fselect_frame (frame, Qnil);
2462 mouse_moveto (XINT (x), XINT (y));
2464 #else
2465 #ifdef HAVE_GPM
2467 Fselect_frame (frame, Qnil);
2468 term_mouse_moveto (XINT (x), XINT (y));
2470 #endif
2471 #endif
2472 #endif
2474 return Qnil;
2477 static void make_frame_visible_1 (Lisp_Object);
2479 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2480 0, 1, "",
2481 doc: /* Make the frame FRAME visible (assuming it is an X window).
2482 If omitted, FRAME defaults to the currently selected frame. */)
2483 (Lisp_Object frame)
2485 struct frame *f = decode_live_frame (frame);
2487 /* I think this should be done with a hook. */
2488 #ifdef HAVE_WINDOW_SYSTEM
2489 if (FRAME_WINDOW_P (f))
2490 x_make_frame_visible (f);
2491 #endif
2493 make_frame_visible_1 (f->root_window);
2495 /* Make menu bar update for the Buffers and Frames menus. */
2496 /* windows_or_buffers_changed = 15; FIXME: Why? */
2498 XSETFRAME (frame, f);
2499 return frame;
2502 /* Update the display_time slot of the buffers shown in WINDOW
2503 and all its descendants. */
2505 static void
2506 make_frame_visible_1 (Lisp_Object window)
2508 struct window *w;
2510 for (; !NILP (window); window = w->next)
2512 w = XWINDOW (window);
2513 if (WINDOWP (w->contents))
2514 make_frame_visible_1 (w->contents);
2515 else
2516 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2520 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2521 0, 2, "",
2522 doc: /* Make the frame FRAME invisible.
2523 If omitted, FRAME defaults to the currently selected frame.
2524 On graphical displays, invisible frames are not updated and are
2525 usually not displayed at all, even in a window system's \"taskbar\".
2527 Normally you may not make FRAME invisible if all other frames are invisible,
2528 but if the second optional argument FORCE is non-nil, you may do so.
2530 This function has no effect on text terminal frames. Such frames are
2531 always considered visible, whether or not they are currently being
2532 displayed in the terminal. */)
2533 (Lisp_Object frame, Lisp_Object force)
2535 struct frame *f = decode_live_frame (frame);
2537 if (NILP (force) && !other_frames (f, true, false))
2538 error ("Attempt to make invisible the sole visible or iconified frame");
2540 /* Don't allow minibuf_window to remain on an invisible frame. */
2541 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2543 /* I think this should be done with a hook. */
2544 #ifdef HAVE_WINDOW_SYSTEM
2545 if (FRAME_WINDOW_P (f))
2546 x_make_frame_invisible (f);
2547 #endif
2549 /* Make menu bar update for the Buffers and Frames menus. */
2550 windows_or_buffers_changed = 16;
2552 return Qnil;
2555 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2556 0, 1, "",
2557 doc: /* Make the frame FRAME into an icon.
2558 If omitted, FRAME defaults to the currently selected frame.
2560 If FRAME is a child frame, consult the variable `iconify-child-frame'
2561 for how to proceed. */)
2562 (Lisp_Object frame)
2564 struct frame *f = decode_live_frame (frame);
2565 #ifdef HAVE_WINDOW_SYSTEM
2566 Lisp_Object parent = f->parent_frame;
2568 if (!NILP (parent))
2570 if (NILP (iconify_child_frame))
2571 /* Do nothing. */
2572 return Qnil;
2573 else if (EQ (iconify_child_frame, Qiconify_top_level))
2575 /* Iconify top level frame instead (the default). */
2576 Ficonify_frame (parent);
2577 return Qnil;
2579 else if (EQ (iconify_child_frame, Qmake_invisible))
2581 /* Make frame invisible instead. */
2582 Fmake_frame_invisible (frame, Qnil);
2583 return Qnil;
2586 #endif /* HAVE_WINDOW_SYSTEM */
2588 /* Don't allow minibuf_window to remain on an iconified frame. */
2589 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2591 /* I think this should be done with a hook. */
2592 if (FRAME_WINDOW_P (f))
2594 #ifdef HAVE_WINDOW_SYSTEM
2595 x_iconify_frame (f);
2596 #endif
2599 return Qnil;
2602 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2603 1, 1, 0,
2604 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2605 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2606 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2607 On graphical displays, invisible frames are not updated and are
2608 usually not displayed at all, even in a window system's \"taskbar\".
2610 If FRAME is a text terminal frame, this always returns t.
2611 Such frames are always considered visible, whether or not they are
2612 currently being displayed on the terminal. */)
2613 (Lisp_Object frame)
2615 CHECK_LIVE_FRAME (frame);
2617 if (FRAME_VISIBLE_P (XFRAME (frame)))
2618 return Qt;
2619 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2620 return Qicon;
2621 return Qnil;
2624 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2625 0, 0, 0,
2626 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2627 (void)
2629 Lisp_Object tail, frame, value = Qnil;
2631 FOR_EACH_FRAME (tail, frame)
2632 if (FRAME_VISIBLE_P (XFRAME (frame)))
2633 value = Fcons (frame, value);
2635 return value;
2639 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2640 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2641 If FRAME is invisible or iconified, make it visible.
2642 If you don't specify a frame, the selected frame is used.
2643 If Emacs is displaying on an ordinary terminal or some other device which
2644 doesn't support multiple overlapping frames, this function selects FRAME. */)
2645 (Lisp_Object frame)
2647 struct frame *f = decode_live_frame (frame);
2649 XSETFRAME (frame, f);
2651 if (FRAME_TERMCAP_P (f))
2652 /* On a text terminal select FRAME. */
2653 Fselect_frame (frame, Qnil);
2654 else
2655 /* Do like the documentation says. */
2656 Fmake_frame_visible (frame);
2658 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2659 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2661 return Qnil;
2664 /* Should we have a corresponding function called Flower_Power? */
2665 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2666 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2667 If you don't specify a frame, the selected frame is used.
2668 If Emacs is displaying on an ordinary terminal or some other device which
2669 doesn't support multiple overlapping frames, this function does nothing. */)
2670 (Lisp_Object frame)
2672 struct frame *f = decode_live_frame (frame);
2674 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2675 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2677 return Qnil;
2681 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2682 1, 2, 0,
2683 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2684 In other words, switch-frame events caused by events in FRAME will
2685 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2686 FOCUS-FRAME after reading an event typed at FRAME.
2688 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2689 frame again receives its own keystrokes.
2691 Focus redirection is useful for temporarily redirecting keystrokes to
2692 a surrogate minibuffer frame when a frame doesn't have its own
2693 minibuffer window.
2695 A frame's focus redirection can be changed by `select-frame'. If frame
2696 FOO is selected, and then a different frame BAR is selected, any
2697 frames redirecting their focus to FOO are shifted to redirect their
2698 focus to BAR. This allows focus redirection to work properly when the
2699 user switches from one frame to another using `select-window'.
2701 This means that a frame whose focus is redirected to itself is treated
2702 differently from a frame whose focus is redirected to nil; the former
2703 is affected by `select-frame', while the latter is not.
2705 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2706 (Lisp_Object frame, Lisp_Object focus_frame)
2708 /* Note that we don't check for a live frame here. It's reasonable
2709 to redirect the focus of a frame you're about to delete, if you
2710 know what other frame should receive those keystrokes. */
2711 struct frame *f = decode_any_frame (frame);
2713 if (! NILP (focus_frame))
2714 CHECK_LIVE_FRAME (focus_frame);
2716 fset_focus_frame (f, focus_frame);
2718 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2719 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2721 return Qnil;
2725 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2726 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2727 If FRAME is omitted or nil, the selected frame is used.
2728 Return nil if FRAME's focus is not redirected.
2729 See `redirect-frame-focus'. */)
2730 (Lisp_Object frame)
2732 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2735 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 2, 0,
2736 doc: /* Set the input focus to FRAME.
2737 FRAME nil means use the selected frame. Optional argument NOACTIVATE
2738 means do not activate FRAME.
2740 If there is no window system support, this function does nothing. */)
2741 (Lisp_Object frame, Lisp_Object noactivate)
2743 #ifdef HAVE_WINDOW_SYSTEM
2744 x_focus_frame (decode_window_system_frame (frame), !NILP (noactivate));
2745 #endif
2746 return Qnil;
2749 DEFUN ("frame-after-make-frame",
2750 Fframe_after_make_frame,
2751 Sframe_after_make_frame, 2, 2, 0,
2752 doc: /* Mark FRAME as made.
2753 FRAME nil means use the selected frame. Second argument MADE non-nil
2754 means functions on `window-configuration-change-hook' are called
2755 whenever the window configuration of FRAME changes. MADE nil means
2756 these functions are not called.
2758 This function is currently called by `make-frame' only and should be
2759 otherwise used with utter care to avoid that running functions on
2760 `window-configuration-change-hook' is impeded forever. */)
2761 (Lisp_Object frame, Lisp_Object made)
2763 struct frame *f = decode_live_frame (frame);
2764 f->after_make_frame = !NILP (made);
2765 f->inhibit_horizontal_resize = false;
2766 f->inhibit_vertical_resize = false;
2767 return made;
2771 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2773 void
2774 frames_discard_buffer (Lisp_Object buffer)
2776 Lisp_Object frame, tail;
2778 FOR_EACH_FRAME (tail, frame)
2780 fset_buffer_list
2781 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2782 fset_buried_buffer_list
2783 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2787 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2788 If the alist already has an element for PROP, we change it. */
2790 void
2791 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2793 register Lisp_Object tem;
2795 tem = Fassq (prop, *alistptr);
2796 if (EQ (tem, Qnil))
2797 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2798 else
2799 Fsetcdr (tem, val);
2802 static int
2803 frame_name_fnn_p (char *str, ptrdiff_t len)
2805 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2807 char *p = str + 2;
2808 while ('0' <= *p && *p <= '9')
2809 p++;
2810 if (p == str + len)
2811 return 1;
2813 return 0;
2816 /* Set the name of the terminal frame. Also used by MSDOS frames.
2817 Modeled after x_set_name which is used for WINDOW frames. */
2819 static void
2820 set_term_frame_name (struct frame *f, Lisp_Object name)
2822 f->explicit_name = ! NILP (name);
2824 /* If NAME is nil, set the name to F<num>. */
2825 if (NILP (name))
2827 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2829 /* Check for no change needed in this very common case
2830 before we do any consing. */
2831 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2832 return;
2834 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2836 else
2838 CHECK_STRING (name);
2840 /* Don't change the name if it's already NAME. */
2841 if (! NILP (Fstring_equal (name, f->name)))
2842 return;
2844 /* Don't allow the user to set the frame name to F<num>, so it
2845 doesn't clash with the names we generate for terminal frames. */
2846 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2847 error ("Frame names of the form F<num> are usurped by Emacs");
2850 fset_name (f, name);
2851 update_mode_lines = 16;
2854 void
2855 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2857 register Lisp_Object old_alist_elt;
2859 if (EQ (prop, Qminibuffer))
2861 if (WINDOWP (val))
2863 if (!MINI_WINDOW_P (XWINDOW (val)))
2864 error ("The `minibuffer' parameter does not specify a valid minibuffer window");
2865 else if (FRAME_MINIBUF_ONLY_P (f))
2867 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2868 val = Qonly;
2869 else
2870 error ("Can't change the minibuffer window of a minibuffer-only frame");
2872 else if (FRAME_HAS_MINIBUF_P (f))
2874 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2875 val = Qt;
2876 else
2877 error ("Can't change the minibuffer window of a frame with its own minibuffer");
2879 else
2880 /* Store the chosen minibuffer window. */
2881 fset_minibuffer_window (f, val);
2883 else
2885 Lisp_Object old_val = Fcdr (Fassq (Qminibuffer, f->param_alist));
2887 if (!NILP (old_val))
2889 if (WINDOWP (old_val) && NILP (val))
2890 /* Don't change the value for a minibuffer-less frame if
2891 only nil was specified as new value. */
2892 val = old_val;
2893 else if (!EQ (old_val, val))
2894 error ("Can't change the `minibuffer' parameter of this frame");
2899 /* Check each parent-frame and delete-before parameter for a
2900 circular dependency. Do not check between parameters, so you can
2901 still create circular dependencies with different properties, for
2902 example a chain of frames F1->F2->...Fn such that F1 is an ancestor
2903 frame of Fn and thus cannot be deleted before Fn and a second chain
2904 Fn->Fn-1->...F1 such that Fn cannot be deleted before F1. */
2905 else if (EQ (prop, Qparent_frame) || EQ (prop, Qdelete_before))
2907 Lisp_Object oldval = Fcdr (Fassq (prop, f->param_alist));
2909 if (!EQ (oldval, val) && !NILP (val))
2911 Lisp_Object frame;
2912 Lisp_Object frame1 = val;
2914 if (!FRAMEP (frame1) || !FRAME_LIVE_P (XFRAME (frame1)))
2915 error ("Invalid `%s' frame parameter",
2916 SSDATA (SYMBOL_NAME (prop)));
2918 XSETFRAME (frame, f);
2920 while (FRAMEP (frame1) && FRAME_LIVE_P (XFRAME (frame1)))
2921 if (EQ (frame1, frame))
2922 error ("Circular specification of `%s' frame parameter",
2923 SSDATA (SYMBOL_NAME (prop)));
2924 else
2925 frame1 = get_frame_param (XFRAME (frame1), prop);
2929 /* The buffer-list parameters are stored in a special place and not
2930 in the alist. All buffers must be live. */
2931 else if (EQ (prop, Qbuffer_list))
2933 Lisp_Object list = Qnil;
2934 for (; CONSP (val); val = XCDR (val))
2935 if (!NILP (Fbuffer_live_p (XCAR (val))))
2936 list = Fcons (XCAR (val), list);
2937 fset_buffer_list (f, Fnreverse (list));
2938 return;
2940 else if (EQ (prop, Qburied_buffer_list))
2942 Lisp_Object list = Qnil;
2943 for (; CONSP (val); val = XCDR (val))
2944 if (!NILP (Fbuffer_live_p (XCAR (val))))
2945 list = Fcons (XCAR (val), list);
2946 fset_buried_buffer_list (f, Fnreverse (list));
2947 return;
2950 /* The tty color needed to be set before the frame's parameter
2951 alist was updated with the new value. This is not true any more,
2952 but we still do this test early on. */
2953 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2954 && f == FRAME_TTY (f)->previous_frame)
2955 /* Force redisplay of this tty. */
2956 FRAME_TTY (f)->previous_frame = NULL;
2958 /* Update the frame parameter alist. */
2959 old_alist_elt = Fassq (prop, f->param_alist);
2960 if (EQ (old_alist_elt, Qnil))
2961 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2962 else
2963 Fsetcdr (old_alist_elt, val);
2965 /* Update some other special parameters in their special places
2966 in addition to the alist. */
2968 if (EQ (prop, Qbuffer_predicate))
2969 fset_buffer_predicate (f, val);
2971 if (! FRAME_WINDOW_P (f))
2973 if (EQ (prop, Qmenu_bar_lines))
2974 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2975 else if (EQ (prop, Qname))
2976 set_term_frame_name (f, val);
2980 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2981 is not an unspecified foreground or background color. */
2983 static Lisp_Object
2984 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2986 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2987 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2988 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2989 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2992 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2993 doc: /* Return the parameters-alist of frame FRAME.
2994 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2995 The meaningful PARMs depend on the kind of frame.
2996 If FRAME is omitted or nil, return information on the currently selected frame. */)
2997 (Lisp_Object frame)
2999 Lisp_Object alist;
3000 struct frame *f = decode_any_frame (frame);
3001 int height, width;
3003 if (!FRAME_LIVE_P (f))
3004 return Qnil;
3006 alist = Fcopy_alist (f->param_alist);
3008 if (!FRAME_WINDOW_P (f))
3010 Lisp_Object elt;
3012 /* If the frame's parameter alist says the colors are
3013 unspecified and reversed, take the frame's background pixel
3014 for foreground and vice versa. */
3015 elt = Fassq (Qforeground_color, alist);
3016 if (CONSP (elt) && STRINGP (XCDR (elt)))
3018 elt = frame_unspecified_color (f, XCDR (elt));
3019 if (!NILP (elt))
3020 store_in_alist (&alist, Qforeground_color, elt);
3022 else
3023 store_in_alist (&alist, Qforeground_color,
3024 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
3025 elt = Fassq (Qbackground_color, alist);
3026 if (CONSP (elt) && STRINGP (XCDR (elt)))
3028 elt = frame_unspecified_color (f, XCDR (elt));
3029 if (!NILP (elt))
3030 store_in_alist (&alist, Qbackground_color, elt);
3032 else
3033 store_in_alist (&alist, Qbackground_color,
3034 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
3035 store_in_alist (&alist, Qfont,
3036 build_string (FRAME_MSDOS_P (f)
3037 ? "ms-dos"
3038 : FRAME_W32_P (f) ? "w32term"
3039 :"tty"));
3041 store_in_alist (&alist, Qname, f->name);
3042 height = (f->new_height
3043 ? (f->new_pixelwise
3044 ? (f->new_height / FRAME_LINE_HEIGHT (f))
3045 : f->new_height)
3046 : FRAME_LINES (f));
3047 store_in_alist (&alist, Qheight, make_number (height));
3048 width = (f->new_width
3049 ? (f->new_pixelwise
3050 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
3051 : f->new_width)
3052 : FRAME_COLS (f));
3053 store_in_alist (&alist, Qwidth, make_number (width));
3054 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
3055 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
3056 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
3057 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
3059 /* I think this should be done with a hook. */
3060 #ifdef HAVE_WINDOW_SYSTEM
3061 if (FRAME_WINDOW_P (f))
3062 x_report_frame_params (f, &alist);
3063 else
3064 #endif
3066 /* This ought to be correct in f->param_alist for an X frame. */
3067 Lisp_Object lines;
3068 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
3069 store_in_alist (&alist, Qmenu_bar_lines, lines);
3072 return alist;
3076 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
3077 doc: /* Return FRAME's value for parameter PARAMETER.
3078 If FRAME is nil, describe the currently selected frame. */)
3079 (Lisp_Object frame, Lisp_Object parameter)
3081 struct frame *f = decode_any_frame (frame);
3082 Lisp_Object value = Qnil;
3084 CHECK_SYMBOL (parameter);
3086 XSETFRAME (frame, f);
3088 if (FRAME_LIVE_P (f))
3090 /* Avoid consing in frequent cases. */
3091 if (EQ (parameter, Qname))
3092 value = f->name;
3093 #ifdef HAVE_WINDOW_SYSTEM
3094 /* These are used by vertical motion commands. */
3095 else if (EQ (parameter, Qvertical_scroll_bars))
3096 value = (f->vertical_scroll_bar_type == vertical_scroll_bar_none
3097 ? Qnil
3098 : (f->vertical_scroll_bar_type == vertical_scroll_bar_left
3099 ? Qleft : Qright));
3100 else if (EQ (parameter, Qhorizontal_scroll_bars))
3101 value = f->horizontal_scroll_bars ? Qt : Qnil;
3102 else if (EQ (parameter, Qline_spacing) && f->extra_line_spacing == 0)
3103 /* If this is non-zero, we can't determine whether the user specified
3104 an integer or float value without looking through 'param_alist'. */
3105 value = make_number (0);
3106 else if (EQ (parameter, Qfont) && FRAME_X_P (f))
3107 value = FRAME_FONT (f)->props[FONT_NAME_INDEX];
3108 #endif /* HAVE_WINDOW_SYSTEM */
3109 #ifdef HAVE_X_WINDOWS
3110 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
3111 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
3112 #endif /* HAVE_X_WINDOWS */
3113 else if (EQ (parameter, Qbackground_color)
3114 || EQ (parameter, Qforeground_color))
3116 value = Fassq (parameter, f->param_alist);
3117 if (CONSP (value))
3119 value = XCDR (value);
3120 /* Fframe_parameters puts the actual fg/bg color names,
3121 even if f->param_alist says otherwise. This is
3122 important when param_alist's notion of colors is
3123 "unspecified". We need to do the same here. */
3124 if (STRINGP (value) && !FRAME_WINDOW_P (f))
3126 Lisp_Object tem = frame_unspecified_color (f, value);
3128 if (!NILP (tem))
3129 value = tem;
3132 else
3133 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
3135 else if (EQ (parameter, Qdisplay_type)
3136 || EQ (parameter, Qbackground_mode))
3137 value = Fcdr (Fassq (parameter, f->param_alist));
3138 else
3139 /* FIXME: Avoid this code path at all (as well as code duplication)
3140 by sharing more code with Fframe_parameters. */
3141 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
3144 return value;
3148 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
3149 Smodify_frame_parameters, 2, 2, 0,
3150 doc: /* Modify FRAME according to new values of its parameters in ALIST.
3151 If FRAME is nil, it defaults to the selected frame.
3152 ALIST is an alist of parameters to change and their new values.
3153 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
3154 Which PARMs are meaningful depends on the kind of frame.
3155 The meaningful parameters are acted upon, i.e. the frame is changed
3156 according to their new values, and are also stored in the frame's
3157 parameter list so that `frame-parameters' will return them.
3158 PARMs that are not meaningful are still stored in the frame's parameter
3159 list, but are otherwise ignored. */)
3160 (Lisp_Object frame, Lisp_Object alist)
3162 struct frame *f = decode_live_frame (frame);
3163 Lisp_Object prop, val;
3165 /* I think this should be done with a hook. */
3166 #ifdef HAVE_WINDOW_SYSTEM
3167 if (FRAME_WINDOW_P (f))
3168 x_set_frame_parameters (f, alist);
3169 else
3170 #endif
3171 #ifdef MSDOS
3172 if (FRAME_MSDOS_P (f))
3173 IT_set_frame_parameters (f, alist);
3174 else
3175 #endif
3178 EMACS_INT length = XFASTINT (Flength (alist));
3179 ptrdiff_t i;
3180 Lisp_Object *parms;
3181 Lisp_Object *values;
3182 USE_SAFE_ALLOCA;
3183 SAFE_ALLOCA_LISP (parms, 2 * length);
3184 values = parms + length;
3186 /* Extract parm names and values into those vectors. */
3188 for (i = 0; CONSP (alist); alist = XCDR (alist))
3190 Lisp_Object elt;
3192 elt = XCAR (alist);
3193 parms[i] = Fcar (elt);
3194 values[i] = Fcdr (elt);
3195 i++;
3198 /* Now process them in reverse of specified order. */
3199 while (--i >= 0)
3201 prop = parms[i];
3202 val = values[i];
3203 store_frame_param (f, prop, val);
3205 if (EQ (prop, Qforeground_color)
3206 || EQ (prop, Qbackground_color))
3207 update_face_from_frame_parameter (f, prop, val);
3210 SAFE_FREE ();
3212 return Qnil;
3215 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
3216 0, 1, 0,
3217 doc: /* Height in pixels of a line in the font in frame FRAME.
3218 If FRAME is omitted or nil, the selected frame is used.
3219 For a terminal frame, the value is always 1. */)
3220 (Lisp_Object frame)
3222 #ifdef HAVE_WINDOW_SYSTEM
3223 struct frame *f = decode_any_frame (frame);
3225 if (FRAME_WINDOW_P (f))
3226 return make_number (FRAME_LINE_HEIGHT (f));
3227 else
3228 #endif
3229 return make_number (1);
3233 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
3234 0, 1, 0,
3235 doc: /* Width in pixels of characters in the font in frame FRAME.
3236 If FRAME is omitted or nil, the selected frame is used.
3237 On a graphical screen, the width is the standard width of the default font.
3238 For a terminal screen, the value is always 1. */)
3239 (Lisp_Object frame)
3241 #ifdef HAVE_WINDOW_SYSTEM
3242 struct frame *f = decode_any_frame (frame);
3244 if (FRAME_WINDOW_P (f))
3245 return make_number (FRAME_COLUMN_WIDTH (f));
3246 else
3247 #endif
3248 return make_number (1);
3251 DEFUN ("frame-native-width", Fframe_native_width,
3252 Sframe_native_width, 0, 1, 0,
3253 doc: /* Return FRAME's native width in pixels.
3254 For a terminal frame, the result really gives the width in characters.
3255 If FRAME is omitted or nil, the selected frame is used. */)
3256 (Lisp_Object frame)
3258 struct frame *f = decode_any_frame (frame);
3260 #ifdef HAVE_WINDOW_SYSTEM
3261 if (FRAME_WINDOW_P (f))
3262 return make_number (FRAME_PIXEL_WIDTH (f));
3263 else
3264 #endif
3265 return make_number (FRAME_TOTAL_COLS (f));
3268 DEFUN ("frame-native-height", Fframe_native_height,
3269 Sframe_native_height, 0, 1, 0,
3270 doc: /* Return FRAME's native height in pixels.
3271 If FRAME is omitted or nil, the selected frame is used. The exact value
3272 of the result depends on the window-system and toolkit in use:
3274 In the Gtk+ and NS versions, it includes only any window (including the
3275 minibuffer or echo area), mode line, and header line. It does not
3276 include the tool bar or menu bar. With other graphical versions, it may
3277 also include the tool bar and the menu bar.
3279 For a text terminal, it includes the menu bar. In this case, the
3280 result is really in characters rather than pixels (i.e., is identical
3281 to `frame-height'). */)
3282 (Lisp_Object frame)
3284 struct frame *f = decode_any_frame (frame);
3286 #ifdef HAVE_WINDOW_SYSTEM
3287 if (FRAME_WINDOW_P (f))
3288 return make_number (FRAME_PIXEL_HEIGHT (f));
3289 else
3290 #endif
3291 return make_number (FRAME_TOTAL_LINES (f));
3294 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
3295 Stool_bar_pixel_width, 0, 1, 0,
3296 doc: /* Return width in pixels of FRAME's tool bar.
3297 The result is greater than zero only when the tool bar is on the left
3298 or right side of FRAME. If FRAME is omitted or nil, the selected frame
3299 is used. */)
3300 (Lisp_Object frame)
3302 #ifdef FRAME_TOOLBAR_WIDTH
3303 struct frame *f = decode_any_frame (frame);
3305 if (FRAME_WINDOW_P (f))
3306 return make_number (FRAME_TOOLBAR_WIDTH (f));
3307 #endif
3308 return make_number (0);
3311 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
3312 doc: /* Return width in columns of FRAME's text area. */)
3313 (Lisp_Object frame)
3315 return make_number (FRAME_COLS (decode_any_frame (frame)));
3318 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
3319 doc: /* Return height in lines of FRAME's text area. */)
3320 (Lisp_Object frame)
3322 return make_number (FRAME_LINES (decode_any_frame (frame)));
3325 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
3326 doc: /* Return number of total columns of FRAME. */)
3327 (Lisp_Object frame)
3329 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
3332 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
3333 doc: /* Return number of total lines of FRAME. */)
3334 (Lisp_Object frame)
3336 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
3339 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
3340 doc: /* Return text area width of FRAME in pixels. */)
3341 (Lisp_Object frame)
3343 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
3346 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
3347 doc: /* Return text area height of FRAME in pixels. */)
3348 (Lisp_Object frame)
3350 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
3353 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
3354 doc: /* Return scroll bar width of FRAME in pixels. */)
3355 (Lisp_Object frame)
3357 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
3360 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
3361 doc: /* Return scroll bar height of FRAME in pixels. */)
3362 (Lisp_Object frame)
3364 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
3367 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
3368 doc: /* Return fringe width of FRAME in pixels. */)
3369 (Lisp_Object frame)
3371 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
3374 DEFUN ("frame-internal-border-width", Fframe_internal_border_width, Sframe_internal_border_width, 0, 1, 0,
3375 doc: /* Return width of FRAME's internal border in pixels. */)
3376 (Lisp_Object frame)
3378 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
3381 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
3382 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
3383 (Lisp_Object frame)
3385 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
3388 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
3389 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
3390 (Lisp_Object frame)
3392 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
3395 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
3396 doc: /* Set text height of frame FRAME to HEIGHT lines.
3397 Optional third arg PRETEND non-nil means that redisplay should use
3398 HEIGHT lines but that the idea of the actual height of the frame should
3399 not be changed.
3401 Optional fourth argument PIXELWISE non-nil means that FRAME should be
3402 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
3403 window managers may refuse to honor a HEIGHT that is not an integer
3404 multiple of the default frame font height. */)
3405 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
3407 struct frame *f = decode_live_frame (frame);
3408 int pixel_height;
3410 CHECK_TYPE_RANGED_INTEGER (int, height);
3412 pixel_height = (!NILP (pixelwise)
3413 ? XINT (height)
3414 : XINT (height) * FRAME_LINE_HEIGHT (f));
3415 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
3417 return Qnil;
3420 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
3421 doc: /* Set text width of frame FRAME to WIDTH columns.
3422 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
3423 columns but that the idea of the actual width of the frame should not
3424 be changed.
3426 Optional fourth argument PIXELWISE non-nil means that FRAME should be
3427 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
3428 window managers may refuse to honor a WIDTH that is not an integer
3429 multiple of the default frame font width. */)
3430 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
3432 struct frame *f = decode_live_frame (frame);
3433 int pixel_width;
3435 CHECK_TYPE_RANGED_INTEGER (int, width);
3437 pixel_width = (!NILP (pixelwise)
3438 ? XINT (width)
3439 : XINT (width) * FRAME_COLUMN_WIDTH (f));
3440 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
3442 return Qnil;
3445 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
3446 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
3447 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
3448 When `frame-resize-pixelwise' is nil, some window managers may refuse to
3449 honor a WIDTH that is not an integer multiple of the default frame font
3450 width or a HEIGHT that is not an integer multiple of the default frame
3451 font height. */)
3452 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
3454 struct frame *f = decode_live_frame (frame);
3455 int pixel_width, pixel_height;
3457 CHECK_TYPE_RANGED_INTEGER (int, width);
3458 CHECK_TYPE_RANGED_INTEGER (int, height);
3460 pixel_width = (!NILP (pixelwise)
3461 ? XINT (width)
3462 : XINT (width) * FRAME_COLUMN_WIDTH (f));
3463 pixel_height = (!NILP (pixelwise)
3464 ? XINT (height)
3465 : XINT (height) * FRAME_LINE_HEIGHT (f));
3466 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
3468 return Qnil;
3471 DEFUN ("frame-position", Fframe_position,
3472 Sframe_position, 0, 1, 0,
3473 doc: /* Return top left corner of FRAME in pixels.
3474 FRAME must be a live frame and defaults to the selected one. The return
3475 value is a cons (x, y) of the coordinates of the top left corner of
3476 FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's
3477 display. */)
3478 (Lisp_Object frame)
3480 register struct frame *f = decode_live_frame (frame);
3482 return Fcons (make_number (f->left_pos), make_number (f->top_pos));
3485 DEFUN ("set-frame-position", Fset_frame_position,
3486 Sset_frame_position, 3, 3, 0,
3487 doc: /* Set position of FRAME to (X, Y).
3488 FRAME must be a live frame and defaults to the selected one. X and Y,
3489 if positive, specify the coordinate of the left and top edge of FRAME's
3490 outer frame in pixels relative to an origin (0, 0) of FRAME's display.
3491 If any of X or Y is negative, it specifies the coordinates of the right
3492 or bottom edge of the outer frame of FRAME relative to the right or
3493 bottom edge of FRAME's display. */)
3494 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
3496 struct frame *f = decode_live_frame (frame);
3498 CHECK_TYPE_RANGED_INTEGER (int, x);
3499 CHECK_TYPE_RANGED_INTEGER (int, y);
3501 /* I think this should be done with a hook. */
3502 if (FRAME_WINDOW_P (f))
3504 #ifdef HAVE_WINDOW_SYSTEM
3505 x_set_offset (f, XINT (x), XINT (y), 1);
3506 #endif
3509 return Qt;
3512 /***********************************************************************
3513 Frame Parameters
3514 ***********************************************************************/
3516 /* Connect the frame-parameter names for X frames
3517 to the ways of passing the parameter values to the window system.
3519 The name of a parameter, as a Lisp symbol,
3520 has an `x-frame-parameter' property which is an integer in Lisp
3521 that is an index in this table. */
3523 struct frame_parm_table {
3524 const char *name;
3525 int sym;
3528 static const struct frame_parm_table frame_parms[] =
3530 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3531 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3532 {"background-color", -1},
3533 {"border-color", SYMBOL_INDEX (Qborder_color)},
3534 {"border-width", SYMBOL_INDEX (Qborder_width)},
3535 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3536 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3537 {"font", -1},
3538 {"foreground-color", -1},
3539 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3540 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3541 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3542 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3543 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3544 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3545 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3546 {"name", SYMBOL_INDEX (Qname)},
3547 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3548 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3549 {"title", SYMBOL_INDEX (Qtitle)},
3550 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3551 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3552 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3553 {"visibility", SYMBOL_INDEX (Qvisibility)},
3554 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3555 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3556 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3557 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3558 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3559 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3560 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3561 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3562 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3563 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3564 {"alpha", SYMBOL_INDEX (Qalpha)},
3565 {"sticky", SYMBOL_INDEX (Qsticky)},
3566 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3567 {"inhibit-double-buffering", SYMBOL_INDEX (Qinhibit_double_buffering)},
3568 {"undecorated", SYMBOL_INDEX (Qundecorated)},
3569 {"parent-frame", SYMBOL_INDEX (Qparent_frame)},
3570 {"skip-taskbar", SYMBOL_INDEX (Qskip_taskbar)},
3571 {"no-focus-on-map", SYMBOL_INDEX (Qno_focus_on_map)},
3572 {"no-accept-focus", SYMBOL_INDEX (Qno_accept_focus)},
3573 {"z-group", SYMBOL_INDEX (Qz_group)},
3574 {"override-redirect", SYMBOL_INDEX (Qoverride_redirect)},
3575 {"no-special-glyphs", SYMBOL_INDEX (Qno_special_glyphs)},
3576 #ifdef NS_IMPL_COCOA
3577 {"ns-appearance", SYMBOL_INDEX (Qns_appearance)},
3578 {"ns-transparent-titlebar", SYMBOL_INDEX (Qns_transparent_titlebar)},
3579 #endif
3582 #ifdef HAVE_WINDOW_SYSTEM
3584 /* Enumeration type for switch in frame_float. */
3585 enum frame_float_type
3587 FRAME_FLOAT_WIDTH,
3588 FRAME_FLOAT_HEIGHT,
3589 FRAME_FLOAT_LEFT,
3590 FRAME_FLOAT_TOP
3594 * frame_float:
3596 * Process the value VAL of the float type frame parameter 'width',
3597 * 'height', 'left', or 'top' specified via a frame_float_type
3598 * enumeration type WHAT for frame F. Such parameters relate the outer
3599 * size or position of F to the size of the F's display or parent frame
3600 * which have to be both available in some way.
3602 * The return value is a size or position value in pixels. VAL must be
3603 * in the range 0.0 to 1.0 where a width/height of 0.0 means to return 0
3604 * and 1.0 means to return the full width/height of the display/parent.
3605 * For positions, 0.0 means position in the left/top corner of the
3606 * display/parent while 1.0 means to position at the right/bottom corner
3607 * of the display/parent frame.
3609 * Set PARENT_DONE and OUTER_DONE to avoid recalculation of the outer
3610 * size or parent or display attributes when more float parameters are
3611 * calculated in a row: -1 means not processed yet, 0 means processing
3612 * failed, 1 means processing succeeded.
3614 * Return DEFAULT_VALUE when processing fails for whatever reason with
3615 * one exception: When calculating F's outer edges fails (probably
3616 * because F has not been created yet) return the difference between F's
3617 * native and text size.
3619 static int
3620 frame_float (struct frame *f, Lisp_Object val, enum frame_float_type what,
3621 int *parent_done, int *outer_done, int default_value)
3623 double d_val = XFLOAT_DATA (val);
3625 if (d_val < 0.0 || d_val > 1.0)
3626 /* Invalid VAL. */
3627 return default_value;
3628 else
3630 static unsigned parent_width, parent_height;
3631 static int parent_left, parent_top;
3632 static unsigned outer_minus_text_width, outer_minus_text_height;
3633 struct frame *p = FRAME_PARENT_FRAME (f);
3635 if (*parent_done == 1)
3637 else if (p)
3639 parent_width = FRAME_PIXEL_WIDTH (p);
3640 parent_height = FRAME_PIXEL_HEIGHT (p);
3641 *parent_done = 1;
3643 else
3645 if (*parent_done == 0)
3646 /* No workarea available. */
3647 return default_value;
3648 else if (*parent_done == -1)
3650 Lisp_Object monitor_attributes;
3651 Lisp_Object workarea;
3652 Lisp_Object frame;
3654 XSETFRAME (frame, f);
3655 monitor_attributes = Fcar (call1 (Qdisplay_monitor_attributes_list, frame));
3656 if (NILP (monitor_attributes))
3658 /* No monitor attributes available. */
3659 *parent_done = 0;
3661 return default_value;
3664 workarea = Fcdr (Fassq (Qworkarea, monitor_attributes));
3665 if (NILP (workarea))
3667 /* No workarea available. */
3668 *parent_done = 0;
3670 return default_value;
3673 /* Workarea available. */
3674 parent_left = XINT (Fnth (make_number (0), workarea));
3675 parent_top = XINT (Fnth (make_number (1), workarea));
3676 parent_width = XINT (Fnth (make_number (2), workarea));
3677 parent_height = XINT (Fnth (make_number (3), workarea));
3678 *parent_done = 1;
3682 if (*outer_done == 1)
3684 else if (FRAME_UNDECORATED (f))
3686 outer_minus_text_width
3687 = FRAME_PIXEL_WIDTH (f) - FRAME_TEXT_WIDTH (f);
3688 outer_minus_text_height
3689 = FRAME_PIXEL_HEIGHT (f) - FRAME_TEXT_HEIGHT (f);
3690 *outer_done = 1;
3692 else if (*outer_done == 0)
3693 /* No outer size available. */
3694 return default_value;
3695 else if (*outer_done == -1)
3697 Lisp_Object frame, outer_edges;
3699 XSETFRAME (frame, f);
3700 outer_edges = call2 (Qframe_edges, frame, Qouter_edges);
3702 if (!NILP (outer_edges))
3704 outer_minus_text_width
3705 = (XINT (Fnth (make_number (2), outer_edges))
3706 - XINT (Fnth (make_number (0), outer_edges))
3707 - FRAME_TEXT_WIDTH (f));
3708 outer_minus_text_height
3709 = (XINT (Fnth (make_number (3), outer_edges))
3710 - XINT (Fnth (make_number (1), outer_edges))
3711 - FRAME_TEXT_HEIGHT (f));
3713 else
3715 /* If we can't get any outer edges, proceed as if the frame
3716 were undecorated. */
3717 outer_minus_text_width
3718 = FRAME_PIXEL_WIDTH (f) - FRAME_TEXT_WIDTH (f);
3719 outer_minus_text_height
3720 = FRAME_PIXEL_HEIGHT (f) - FRAME_TEXT_HEIGHT (f);
3723 *outer_done = 1;
3726 switch (what)
3728 case FRAME_FLOAT_WIDTH:
3729 return parent_width * d_val - outer_minus_text_width;
3731 case FRAME_FLOAT_HEIGHT:
3732 return parent_height * d_val - outer_minus_text_height;
3734 case FRAME_FLOAT_LEFT:
3736 int rest_width = (parent_width
3737 - FRAME_TEXT_WIDTH (f)
3738 - outer_minus_text_width);
3740 if (p)
3741 return (rest_width <= 0 ? 0 : d_val * rest_width);
3742 else
3743 return (rest_width <= 0
3744 ? parent_left
3745 : parent_left + d_val * rest_width);
3747 case FRAME_FLOAT_TOP:
3749 int rest_height = (parent_height
3750 - FRAME_TEXT_HEIGHT (f)
3751 - outer_minus_text_height);
3753 if (p)
3754 return (rest_height <= 0 ? 0 : d_val * rest_height);
3755 else
3756 return (rest_height <= 0
3757 ? parent_top
3758 : parent_top + d_val * rest_height);
3760 default:
3761 emacs_abort ();
3766 /* Change the parameters of frame F as specified by ALIST.
3767 If a parameter is not specially recognized, do nothing special;
3768 otherwise call the `x_set_...' function for that parameter.
3769 Except for certain geometry properties, always call store_frame_param
3770 to store the new value in the parameter alist. */
3772 void
3773 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3775 Lisp_Object tail, frame;
3778 /* If both of these parameters are present, it's more efficient to
3779 set them both at once. So we wait until we've looked at the
3780 entire list before we set them. */
3781 int width = -1, height = -1; /* -1 denotes they were not changed. */
3783 /* Same here. */
3784 Lisp_Object left, top;
3786 /* Same with these. */
3787 Lisp_Object icon_left, icon_top;
3789 /* And with this. */
3790 Lisp_Object fullscreen;
3791 bool fullscreen_change = false;
3793 /* Record in these vectors all the parms specified. */
3794 Lisp_Object *parms;
3795 Lisp_Object *values;
3796 ptrdiff_t i, j, size;
3797 bool left_no_change = 0, top_no_change = 0;
3798 #ifdef HAVE_X_WINDOWS
3799 bool icon_left_no_change = 0, icon_top_no_change = 0;
3800 #endif
3801 int parent_done = -1, outer_done = -1;
3803 XSETFRAME (frame, f);
3804 for (size = 0, tail = alist; CONSP (tail); tail = XCDR (tail))
3805 size++;
3806 CHECK_LIST_END (tail, alist);
3808 USE_SAFE_ALLOCA;
3809 SAFE_ALLOCA_LISP (parms, 2 * size);
3810 values = parms + size;
3812 /* Extract parm names and values into those vectors. */
3814 i = 0, j = size - 1;
3815 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3817 Lisp_Object elt = XCAR (tail), prop = Fcar (elt), val = Fcdr (elt);
3819 /* Some properties are independent of other properties, but other
3820 properties are dependent upon them. These special properties
3821 are foreground_color, background_color (affects cursor_color)
3822 and font (affects fringe widths); they're recorded starting
3823 from the end of PARMS and VALUES to process them first by using
3824 reverse iteration. */
3826 if (EQ (prop, Qforeground_color)
3827 || EQ (prop, Qbackground_color)
3828 || EQ (prop, Qfont))
3830 parms[j] = prop;
3831 values[j] = val;
3832 j--;
3834 else
3836 parms[i] = prop;
3837 values[i] = val;
3838 i++;
3842 /* TAIL and ALIST are not used again below here. */
3843 alist = tail = Qnil;
3845 top = left = Qunbound;
3846 icon_left = icon_top = Qunbound;
3848 /* Reverse order is used to make sure that special
3849 properties noticed above are processed first. */
3850 for (i = size - 1; i >= 0; i--)
3852 Lisp_Object prop, val;
3854 prop = parms[i];
3855 val = values[i];
3857 if (EQ (prop, Qwidth))
3859 if (RANGED_INTEGERP (0, val, INT_MAX))
3860 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3861 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3862 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3863 width = XFASTINT (XCDR (val));
3864 else if (FLOATP (val))
3865 width = frame_float (f, val, FRAME_FLOAT_WIDTH, &parent_done,
3866 &outer_done, -1);
3868 else if (EQ (prop, Qheight))
3870 if (RANGED_INTEGERP (0, val, INT_MAX))
3871 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3872 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3873 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3874 height = XFASTINT (XCDR (val));
3875 else if (FLOATP (val))
3876 height = frame_float (f, val, FRAME_FLOAT_HEIGHT, &parent_done,
3877 &outer_done, -1);
3879 else if (EQ (prop, Qtop))
3880 top = val;
3881 else if (EQ (prop, Qleft))
3882 left = val;
3883 else if (EQ (prop, Qicon_top))
3884 icon_top = val;
3885 else if (EQ (prop, Qicon_left))
3886 icon_left = val;
3887 else if (EQ (prop, Qfullscreen))
3889 fullscreen = val;
3890 fullscreen_change = true;
3892 else
3894 register Lisp_Object param_index, old_value;
3896 old_value = get_frame_param (f, prop);
3898 store_frame_param (f, prop, val);
3900 param_index = Fget (prop, Qx_frame_parameter);
3901 if (NATNUMP (param_index)
3902 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3903 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3904 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3908 /* Don't die if just one of these was set. */
3909 if (EQ (left, Qunbound))
3911 left_no_change = 1;
3912 if (f->left_pos < 0)
3913 left = list2 (Qplus, make_number (f->left_pos));
3914 else
3915 XSETINT (left, f->left_pos);
3917 if (EQ (top, Qunbound))
3919 top_no_change = 1;
3920 if (f->top_pos < 0)
3921 top = list2 (Qplus, make_number (f->top_pos));
3922 else
3923 XSETINT (top, f->top_pos);
3926 /* If one of the icon positions was not set, preserve or default it. */
3927 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3929 #ifdef HAVE_X_WINDOWS
3930 icon_left_no_change = 1;
3931 #endif
3932 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3933 if (NILP (icon_left))
3934 XSETINT (icon_left, 0);
3936 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3938 #ifdef HAVE_X_WINDOWS
3939 icon_top_no_change = 1;
3940 #endif
3941 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3942 if (NILP (icon_top))
3943 XSETINT (icon_top, 0);
3946 /* Don't set these parameters unless they've been explicitly
3947 specified. The window might be mapped or resized while we're in
3948 this function, and we don't want to override that unless the lisp
3949 code has asked for it.
3951 Don't set these parameters unless they actually differ from the
3952 window's current parameters; the window may not actually exist
3953 yet. */
3954 if ((width != -1 && width != FRAME_TEXT_WIDTH (f))
3955 || (height != -1 && height != FRAME_TEXT_HEIGHT (f)))
3956 /* We could consider checking f->after_make_frame here, but I
3957 don't have the faintest idea why the following is needed at
3958 all. With the old setting it can get a Heisenbug when
3959 EmacsFrameResize intermittently provokes a delayed
3960 change_frame_size in the middle of adjust_frame_size. */
3961 /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
3962 adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters);
3964 if ((!NILP (left) || !NILP (top))
3965 && ! (left_no_change && top_no_change)
3966 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3967 && NUMBERP (top) && XINT (top) == f->top_pos))
3969 int leftpos = 0;
3970 int toppos = 0;
3972 /* Record the signs. */
3973 f->size_hint_flags &= ~ (XNegative | YNegative);
3974 if (EQ (left, Qminus))
3975 f->size_hint_flags |= XNegative;
3976 else if (TYPE_RANGED_INTEGERP (int, left))
3978 leftpos = XINT (left);
3979 if (leftpos < 0)
3980 f->size_hint_flags |= XNegative;
3982 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3983 && CONSP (XCDR (left))
3984 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3986 leftpos = - XINT (XCAR (XCDR (left)));
3987 f->size_hint_flags |= XNegative;
3989 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3990 && CONSP (XCDR (left))
3991 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3992 leftpos = XINT (XCAR (XCDR (left)));
3993 else if (FLOATP (left))
3994 leftpos = frame_float (f, left, FRAME_FLOAT_LEFT, &parent_done,
3995 &outer_done, 0);
3997 if (EQ (top, Qminus))
3998 f->size_hint_flags |= YNegative;
3999 else if (TYPE_RANGED_INTEGERP (int, top))
4001 toppos = XINT (top);
4002 if (toppos < 0)
4003 f->size_hint_flags |= YNegative;
4005 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4006 && CONSP (XCDR (top))
4007 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4009 toppos = - XINT (XCAR (XCDR (top)));
4010 f->size_hint_flags |= YNegative;
4012 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4013 && CONSP (XCDR (top))
4014 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4015 toppos = XINT (XCAR (XCDR (top)));
4016 else if (FLOATP (top))
4017 toppos = frame_float (f, top, FRAME_FLOAT_TOP, &parent_done,
4018 &outer_done, 0);
4020 /* Store the numeric value of the position. */
4021 f->top_pos = toppos;
4022 f->left_pos = leftpos;
4024 f->win_gravity = NorthWestGravity;
4026 /* Actually set that position, and convert to absolute. */
4027 x_set_offset (f, leftpos, toppos, -1);
4030 if (fullscreen_change)
4032 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
4034 frame_size_history_add
4035 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
4037 store_frame_param (f, Qfullscreen, fullscreen);
4038 if (!EQ (fullscreen, old_value))
4039 x_set_fullscreen (f, fullscreen, old_value);
4043 #ifdef HAVE_X_WINDOWS
4044 if ((!NILP (icon_left) || !NILP (icon_top))
4045 && ! (icon_left_no_change && icon_top_no_change))
4046 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
4047 #endif /* HAVE_X_WINDOWS */
4049 SAFE_FREE ();
4053 /* Insert a description of internally-recorded parameters of frame X
4054 into the parameter alist *ALISTPTR that is to be given to the user.
4055 Only parameters that are specific to the X window system
4056 and whose values are not correctly recorded in the frame's
4057 param_alist need to be considered here. */
4059 void
4060 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
4062 Lisp_Object tem;
4063 uprintmax_t w;
4064 char buf[INT_BUFSIZE_BOUND (w)];
4066 /* Represent negative positions (off the top or left screen edge)
4067 in a way that Fmodify_frame_parameters will understand correctly. */
4068 XSETINT (tem, f->left_pos);
4069 if (f->left_pos >= 0)
4070 store_in_alist (alistptr, Qleft, tem);
4071 else
4072 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
4074 XSETINT (tem, f->top_pos);
4075 if (f->top_pos >= 0)
4076 store_in_alist (alistptr, Qtop, tem);
4077 else
4078 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
4080 store_in_alist (alistptr, Qborder_width,
4081 make_number (f->border_width));
4082 store_in_alist (alistptr, Qinternal_border_width,
4083 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
4084 store_in_alist (alistptr, Qright_divider_width,
4085 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
4086 store_in_alist (alistptr, Qbottom_divider_width,
4087 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
4088 store_in_alist (alistptr, Qleft_fringe,
4089 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
4090 store_in_alist (alistptr, Qright_fringe,
4091 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
4092 store_in_alist (alistptr, Qscroll_bar_width,
4093 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
4094 ? make_number (0)
4095 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
4096 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
4097 /* nil means "use default width"
4098 for non-toolkit scroll bar.
4099 ruler-mode.el depends on this. */
4100 : Qnil));
4101 store_in_alist (alistptr, Qscroll_bar_height,
4102 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
4103 ? make_number (0)
4104 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
4105 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
4106 /* nil means "use default height"
4107 for non-toolkit scroll bar. */
4108 : Qnil));
4109 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
4110 MS-Windows it returns a value whose type is HANDLE, which is
4111 actually a pointer. Explicit casting avoids compiler
4112 warnings. */
4113 w = (uintptr_t) FRAME_X_WINDOW (f);
4114 store_in_alist (alistptr, Qwindow_id,
4115 make_formatted_string (buf, "%"pMu, w));
4116 #ifdef HAVE_X_WINDOWS
4117 #ifdef USE_X_TOOLKIT
4118 /* Tooltip frame may not have this widget. */
4119 if (FRAME_X_OUTPUT (f)->widget)
4120 #endif
4121 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
4122 store_in_alist (alistptr, Qouter_window_id,
4123 make_formatted_string (buf, "%"pMu, w));
4124 #endif
4125 store_in_alist (alistptr, Qicon_name, f->icon_name);
4126 store_in_alist (alistptr, Qvisibility,
4127 (FRAME_VISIBLE_P (f) ? Qt
4128 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
4129 store_in_alist (alistptr, Qdisplay,
4130 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
4132 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
4133 tem = Qnil;
4134 else
4135 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
4136 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
4137 store_in_alist (alistptr, Qparent_id, tem);
4138 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
4142 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
4143 the previous value of that parameter, NEW_VALUE is the new value. */
4145 void
4146 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4148 if (NILP (new_value))
4149 f->want_fullscreen = FULLSCREEN_NONE;
4150 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
4151 f->want_fullscreen = FULLSCREEN_BOTH;
4152 else if (EQ (new_value, Qfullwidth))
4153 f->want_fullscreen = FULLSCREEN_WIDTH;
4154 else if (EQ (new_value, Qfullheight))
4155 f->want_fullscreen = FULLSCREEN_HEIGHT;
4156 else if (EQ (new_value, Qmaximized))
4157 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
4159 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
4160 FRAME_TERMINAL (f)->fullscreen_hook (f);
4164 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
4165 the previous value of that parameter, NEW_VALUE is the new value. */
4167 void
4168 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4170 if (NILP (new_value))
4171 f->extra_line_spacing = 0;
4172 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
4173 f->extra_line_spacing = XFASTINT (new_value);
4174 else if (FLOATP (new_value))
4176 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
4178 if (new_spacing >= 0)
4179 f->extra_line_spacing = new_spacing;
4180 else
4181 signal_error ("Invalid line-spacing", new_value);
4183 else
4184 signal_error ("Invalid line-spacing", new_value);
4185 if (FRAME_VISIBLE_P (f))
4186 redraw_frame (f);
4190 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
4191 the previous value of that parameter, NEW_VALUE is the new value. */
4193 void
4194 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4196 Lisp_Object bgcolor;
4198 if (NILP (new_value))
4199 f->gamma = 0;
4200 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
4201 /* The value 0.4545 is the normal viewing gamma. */
4202 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
4203 else
4204 signal_error ("Invalid screen-gamma", new_value);
4206 /* Apply the new gamma value to the frame background. */
4207 bgcolor = Fassq (Qbackground_color, f->param_alist);
4208 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
4210 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
4211 if (NATNUMP (parm_index)
4212 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
4213 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
4214 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
4215 (f, bgcolor, Qnil);
4218 clear_face_cache (true); /* FIXME: Why of all frames? */
4219 fset_redisplay (f);
4223 void
4224 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4226 Lisp_Object font_object;
4227 int fontset = -1;
4228 #ifdef HAVE_X_WINDOWS
4229 Lisp_Object font_param = arg;
4230 #endif
4232 /* Set the frame parameter back to the old value because we may
4233 fail to use ARG as the new parameter value. */
4234 store_frame_param (f, Qfont, oldval);
4236 /* ARG is a fontset name, a font name, a cons of fontset name and a
4237 font object, or a font object. In the last case, this function
4238 never fail. */
4239 if (STRINGP (arg))
4241 fontset = fs_query_fontset (arg, 0);
4242 if (fontset < 0)
4244 font_object = font_open_by_name (f, arg);
4245 if (NILP (font_object))
4246 error ("Font `%s' is not defined", SSDATA (arg));
4247 arg = AREF (font_object, FONT_NAME_INDEX);
4249 else if (fontset > 0)
4251 font_object = font_open_by_name (f, fontset_ascii (fontset));
4252 if (NILP (font_object))
4253 error ("Font `%s' is not defined", SDATA (arg));
4254 arg = AREF (font_object, FONT_NAME_INDEX);
4256 else
4257 error ("The default fontset can't be used for a frame font");
4259 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
4261 /* This is the case that the ASCII font of F's fontset XCAR
4262 (arg) is changed to the font XCDR (arg) by
4263 `set-fontset-font'. */
4264 fontset = fs_query_fontset (XCAR (arg), 0);
4265 if (fontset < 0)
4266 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
4267 font_object = XCDR (arg);
4268 arg = AREF (font_object, FONT_NAME_INDEX);
4269 #ifdef HAVE_X_WINDOWS
4270 font_param = Ffont_get (font_object, QCname);
4271 #endif
4273 else if (FONT_OBJECT_P (arg))
4275 font_object = arg;
4276 #ifdef HAVE_X_WINDOWS
4277 font_param = Ffont_get (font_object, QCname);
4278 #endif
4279 /* This is to store the XLFD font name in the frame parameter for
4280 backward compatibility. We should store the font-object
4281 itself in the future. */
4282 arg = AREF (font_object, FONT_NAME_INDEX);
4283 fontset = FRAME_FONTSET (f);
4284 /* Check if we can use the current fontset. If not, set FONTSET
4285 to -1 to generate a new fontset from FONT-OBJECT. */
4286 if (fontset >= 0)
4288 Lisp_Object ascii_font = fontset_ascii (fontset);
4289 Lisp_Object spec = font_spec_from_name (ascii_font);
4291 /* SPEC might be nil because ASCII_FONT's name doesn't parse
4292 according to stupid XLFD rules, which, for example,
4293 disallow font names that include a dash followed by a
4294 number. So in those cases we simply request x_new_font
4295 below to generate a new fontset. */
4296 if (NILP (spec) || ! font_match_p (spec, font_object))
4297 fontset = -1;
4300 else
4301 signal_error ("Invalid font", arg);
4303 if (! NILP (Fequal (font_object, oldval)))
4304 return;
4306 x_new_font (f, font_object, fontset);
4307 store_frame_param (f, Qfont, arg);
4308 #ifdef HAVE_X_WINDOWS
4309 store_frame_param (f, Qfont_parameter, font_param);
4310 #endif
4311 /* Recalculate toolbar height. */
4312 f->n_tool_bar_rows = 0;
4314 /* Ensure we redraw it. */
4315 clear_current_matrices (f);
4317 /* Attempt to hunt down bug#16028. */
4318 SET_FRAME_GARBAGED (f);
4320 /* This is important if we are called by some Lisp as part of
4321 redisplaying the frame, see redisplay_internal. */
4322 f->fonts_changed = true;
4324 recompute_basic_faces (f);
4326 do_pending_window_change (0);
4328 /* We used to call face-set-after-frame-default here, but it leads to
4329 recursive calls (since that function can set the `default' face's
4330 font which in turns changes the frame's `font' parameter).
4331 Also I don't know what this call is meant to do, but it seems the
4332 wrong way to do it anyway (it does a lot more work than what seems
4333 reasonable in response to a change to `font'). */
4337 void
4338 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4340 if (! NILP (new_value)
4341 && !CONSP (new_value))
4343 char *p0, *p1;
4345 CHECK_STRING (new_value);
4346 p0 = p1 = SSDATA (new_value);
4347 new_value = Qnil;
4348 while (*p0)
4350 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
4351 if (p0 < p1)
4352 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
4353 new_value);
4354 if (*p1)
4356 int c;
4358 while ((c = *++p1) && c_isspace (c));
4360 p0 = p1;
4362 new_value = Fnreverse (new_value);
4365 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
4366 return;
4368 if (FRAME_FONT (f))
4369 free_all_realized_faces (Qnil);
4371 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
4372 if (NILP (new_value))
4374 if (NILP (old_value))
4375 error ("No font backend available");
4376 font_update_drivers (f, old_value);
4377 error ("None of specified font backends are available");
4379 store_frame_param (f, Qfont_backend, new_value);
4381 if (FRAME_FONT (f))
4383 Lisp_Object frame;
4385 XSETFRAME (frame, f);
4386 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
4387 face_change = true;
4388 windows_or_buffers_changed = 18;
4392 void
4393 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4395 int unit = FRAME_COLUMN_WIDTH (f);
4396 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
4397 int new_width;
4399 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
4400 ? eabs (XINT (new_value)) : 8);
4402 if (new_width != old_width)
4404 f->left_fringe_width = new_width;
4405 f->fringe_cols /* Round up. */
4406 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
4408 if (FRAME_X_WINDOW (f) != 0)
4409 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
4411 SET_FRAME_GARBAGED (f);
4416 void
4417 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4419 int unit = FRAME_COLUMN_WIDTH (f);
4420 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
4421 int new_width;
4423 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
4424 ? eabs (XINT (new_value)) : 8);
4426 if (new_width != old_width)
4428 f->right_fringe_width = new_width;
4429 f->fringe_cols /* Round up. */
4430 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
4432 if (FRAME_X_WINDOW (f) != 0)
4433 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
4435 SET_FRAME_GARBAGED (f);
4440 void
4441 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4443 CHECK_TYPE_RANGED_INTEGER (int, arg);
4445 if (XINT (arg) == f->border_width)
4446 return;
4448 if (FRAME_X_WINDOW (f) != 0)
4449 error ("Cannot change the border width of a frame");
4451 f->border_width = XINT (arg);
4454 void
4455 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4457 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
4458 CHECK_TYPE_RANGED_INTEGER (int, arg);
4459 int new = max (0, XINT (arg));
4460 if (new != old)
4462 f->right_divider_width = new;
4463 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
4464 adjust_frame_glyphs (f);
4465 SET_FRAME_GARBAGED (f);
4469 void
4470 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4472 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
4473 CHECK_TYPE_RANGED_INTEGER (int, arg);
4474 int new = max (0, XINT (arg));
4475 if (new != old)
4477 f->bottom_divider_width = new;
4478 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
4479 adjust_frame_glyphs (f);
4480 SET_FRAME_GARBAGED (f);
4484 void
4485 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
4487 Lisp_Object frame;
4488 XSETFRAME (frame, f);
4490 if (NILP (value))
4491 Fmake_frame_invisible (frame, Qt);
4492 else if (EQ (value, Qicon))
4493 Ficonify_frame (frame);
4494 else
4495 Fmake_frame_visible (frame);
4498 void
4499 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4501 f->auto_raise = !EQ (Qnil, arg);
4504 void
4505 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4507 f->auto_lower = !EQ (Qnil, arg);
4510 void
4511 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4513 f->no_split = !NILP (arg);
4516 void
4517 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4519 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
4520 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
4521 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4522 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
4524 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
4525 = (NILP (arg)
4526 ? vertical_scroll_bar_none
4527 : EQ (Qleft, arg)
4528 ? vertical_scroll_bar_left
4529 : EQ (Qright, arg)
4530 ? vertical_scroll_bar_right
4531 : EQ (Qleft, Vdefault_frame_scroll_bars)
4532 ? vertical_scroll_bar_left
4533 : EQ (Qright, Vdefault_frame_scroll_bars)
4534 ? vertical_scroll_bar_right
4535 : vertical_scroll_bar_none);
4537 /* We set this parameter before creating the X window for the
4538 frame, so we can get the geometry right from the start.
4539 However, if the window hasn't been created yet, we shouldn't
4540 call x_set_window_size. */
4541 if (FRAME_X_WINDOW (f))
4542 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
4544 SET_FRAME_GARBAGED (f);
4548 void
4549 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4551 #if USE_HORIZONTAL_SCROLL_BARS
4552 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
4553 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
4555 f->horizontal_scroll_bars = NILP (arg) ? false : true;
4557 /* We set this parameter before creating the X window for the
4558 frame, so we can get the geometry right from the start.
4559 However, if the window hasn't been created yet, we shouldn't
4560 call x_set_window_size. */
4561 if (FRAME_X_WINDOW (f))
4562 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
4564 SET_FRAME_GARBAGED (f);
4566 #endif
4569 void
4570 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4572 int unit = FRAME_COLUMN_WIDTH (f);
4574 if (NILP (arg))
4576 x_set_scroll_bar_default_width (f);
4578 if (FRAME_X_WINDOW (f))
4579 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
4581 SET_FRAME_GARBAGED (f);
4583 else if (RANGED_INTEGERP (1, arg, INT_MAX)
4584 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
4586 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
4587 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
4588 if (FRAME_X_WINDOW (f))
4589 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
4591 SET_FRAME_GARBAGED (f);
4594 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
4595 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
4598 void
4599 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4601 #if USE_HORIZONTAL_SCROLL_BARS
4602 int unit = FRAME_LINE_HEIGHT (f);
4604 if (NILP (arg))
4606 x_set_scroll_bar_default_height (f);
4608 if (FRAME_X_WINDOW (f))
4609 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
4611 SET_FRAME_GARBAGED (f);
4613 else if (RANGED_INTEGERP (1, arg, INT_MAX)
4614 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
4616 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
4617 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
4618 if (FRAME_X_WINDOW (f))
4619 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
4621 SET_FRAME_GARBAGED (f);
4624 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
4625 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
4626 #endif
4629 void
4630 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4632 double alpha = 1.0;
4633 double newval[2];
4634 int i;
4635 Lisp_Object item;
4637 for (i = 0; i < 2; i++)
4639 newval[i] = 1.0;
4640 if (CONSP (arg))
4642 item = CAR (arg);
4643 arg = CDR (arg);
4645 else
4646 item = arg;
4648 if (NILP (item))
4649 alpha = - 1.0;
4650 else if (FLOATP (item))
4652 alpha = XFLOAT_DATA (item);
4653 if (! (0 <= alpha && alpha <= 1.0))
4654 args_out_of_range (make_float (0.0), make_float (1.0));
4656 else if (INTEGERP (item))
4658 EMACS_INT ialpha = XINT (item);
4659 if (! (0 <= ialpha && ialpha <= 100))
4660 args_out_of_range (make_number (0), make_number (100));
4661 alpha = ialpha / 100.0;
4663 else
4664 wrong_type_argument (Qnumberp, item);
4665 newval[i] = alpha;
4668 for (i = 0; i < 2; i++)
4669 f->alpha[i] = newval[i];
4671 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4672 block_input ();
4673 x_set_frame_alpha (f);
4674 unblock_input ();
4675 #endif
4677 return;
4682 * x_set_no_special_glyphs:
4684 * Set frame F's `no-special-glyphs' parameter which, if non-nil,
4685 * suppresses the display of truncation and continuation glyphs
4686 * outside fringes.
4688 void
4689 x_set_no_special_glyphs (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4691 if (!EQ (new_value, old_value))
4692 FRAME_NO_SPECIAL_GLYPHS (f) = !NILP (new_value);
4696 #ifndef HAVE_NS
4698 /* Non-zero if mouse is grabbed on DPYINFO
4699 and we know the frame where it is. */
4701 bool x_mouse_grabbed (Display_Info *dpyinfo)
4703 return (dpyinfo->grabbed
4704 && dpyinfo->last_mouse_frame
4705 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4708 /* Re-highlight something with mouse-face properties
4709 on DPYINFO using saved frame and mouse position. */
4711 void
4712 x_redo_mouse_highlight (Display_Info *dpyinfo)
4714 if (dpyinfo->last_mouse_motion_frame
4715 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4716 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4717 dpyinfo->last_mouse_motion_x,
4718 dpyinfo->last_mouse_motion_y);
4721 #endif /* HAVE_NS */
4723 /* Subroutines of creating an X frame. */
4725 /* Make sure that Vx_resource_name is set to a reasonable value.
4726 Fix it up, or set it to `emacs' if it is too hopeless. */
4728 void
4729 validate_x_resource_name (void)
4731 ptrdiff_t len = 0;
4732 /* Number of valid characters in the resource name. */
4733 ptrdiff_t good_count = 0;
4734 /* Number of invalid characters in the resource name. */
4735 ptrdiff_t bad_count = 0;
4736 Lisp_Object new;
4737 ptrdiff_t i;
4739 if (!STRINGP (Vx_resource_class))
4740 Vx_resource_class = build_string (EMACS_CLASS);
4742 if (STRINGP (Vx_resource_name))
4744 unsigned char *p = SDATA (Vx_resource_name);
4746 len = SBYTES (Vx_resource_name);
4748 /* Only letters, digits, - and _ are valid in resource names.
4749 Count the valid characters and count the invalid ones. */
4750 for (i = 0; i < len; i++)
4752 int c = p[i];
4753 if (! ((c >= 'a' && c <= 'z')
4754 || (c >= 'A' && c <= 'Z')
4755 || (c >= '0' && c <= '9')
4756 || c == '-' || c == '_'))
4757 bad_count++;
4758 else
4759 good_count++;
4762 else
4763 /* Not a string => completely invalid. */
4764 bad_count = 5, good_count = 0;
4766 /* If name is valid already, return. */
4767 if (bad_count == 0)
4768 return;
4770 /* If name is entirely invalid, or nearly so, or is so implausibly
4771 large that alloca might not work, use `emacs'. */
4772 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4774 Vx_resource_name = build_string ("emacs");
4775 return;
4778 /* Name is partly valid. Copy it and replace the invalid characters
4779 with underscores. */
4781 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4783 for (i = 0; i < len; i++)
4785 int c = SREF (new, i);
4786 if (! ((c >= 'a' && c <= 'z')
4787 || (c >= 'A' && c <= 'Z')
4788 || (c >= '0' && c <= '9')
4789 || c == '-' || c == '_'))
4790 SSET (new, i, '_');
4794 /* Get specified attribute from resource database RDB.
4795 See Fx_get_resource below for other parameters. */
4797 static Lisp_Object
4798 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4800 CHECK_STRING (attribute);
4801 CHECK_STRING (class);
4803 if (!NILP (component))
4804 CHECK_STRING (component);
4805 if (!NILP (subclass))
4806 CHECK_STRING (subclass);
4807 if (NILP (component) != NILP (subclass))
4808 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4810 validate_x_resource_name ();
4812 /* Allocate space for the components, the dots which separate them,
4813 and the final '\0'. Make them big enough for the worst case. */
4814 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4815 + (STRINGP (component)
4816 ? SBYTES (component) : 0)
4817 + SBYTES (attribute)
4818 + 3);
4820 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4821 + SBYTES (class)
4822 + (STRINGP (subclass)
4823 ? SBYTES (subclass) : 0)
4824 + 3);
4825 USE_SAFE_ALLOCA;
4826 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4827 char *class_key = name_key + name_keysize;
4828 name_key = ptr_bounds_clip (name_key, name_keysize);
4829 class_key = ptr_bounds_clip (class_key, class_keysize);
4831 /* Start with emacs.FRAMENAME for the name (the specific one)
4832 and with `Emacs' for the class key (the general one). */
4833 char *nz = lispstpcpy (name_key, Vx_resource_name);
4834 char *cz = lispstpcpy (class_key, Vx_resource_class);
4836 *cz++ = '.';
4837 cz = lispstpcpy (cz, class);
4839 if (!NILP (component))
4841 *cz++ = '.';
4842 lispstpcpy (cz, subclass);
4844 *nz++ = '.';
4845 nz = lispstpcpy (nz, component);
4848 *nz++ = '.';
4849 lispstpcpy (nz, attribute);
4851 char *value = x_get_string_resource (rdb, name_key, class_key);
4852 SAFE_FREE();
4854 if (value && *value)
4855 return build_string (value);
4856 else
4857 return Qnil;
4861 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4862 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4863 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4864 class, where INSTANCE is the name under which Emacs was invoked, or
4865 the name specified by the `-name' or `-rn' command-line arguments.
4867 The optional arguments COMPONENT and SUBCLASS add to the key and the
4868 class, respectively. You must specify both of them or neither.
4869 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4870 and the class is `Emacs.CLASS.SUBCLASS'. */)
4871 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4872 Lisp_Object subclass)
4874 check_window_system (NULL);
4876 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4877 attribute, class, component, subclass);
4880 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4882 Lisp_Object
4883 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4884 Lisp_Object class, Lisp_Object component,
4885 Lisp_Object subclass)
4887 return xrdb_get_resource (dpyinfo->xrdb,
4888 attribute, class, component, subclass);
4891 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4892 /* Used when C code wants a resource value. */
4893 /* Called from oldXMenu/Create.c. */
4894 char *
4895 x_get_resource_string (const char *attribute, const char *class)
4897 char *result;
4898 struct frame *sf = SELECTED_FRAME ();
4899 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4900 USE_SAFE_ALLOCA;
4902 /* Allocate space for the components, the dots which separate them,
4903 and the final '\0'. */
4904 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4905 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4906 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4907 char *class_key = name_key + name_keysize;
4908 name_key = ptr_bounds_clip (name_key, name_keysize);
4909 class_key = ptr_bounds_clip (class_key, class_keysize);
4911 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4912 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4914 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4915 name_key, class_key);
4916 SAFE_FREE ();
4917 return result;
4919 #endif
4921 /* Return the value of parameter PARAM.
4923 First search ALIST, then Vdefault_frame_alist, then the X defaults
4924 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4926 Convert the resource to the type specified by desired_type.
4928 If no default is specified, return Qunbound. If you call
4929 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4930 and don't let it get stored in any Lisp-visible variables! */
4932 Lisp_Object
4933 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4934 const char *attribute, const char *class, enum resource_types type)
4936 Lisp_Object tem;
4938 tem = Fassq (param, alist);
4940 if (!NILP (tem))
4942 /* If we find this parm in ALIST, clear it out
4943 so that it won't be "left over" at the end. */
4944 Lisp_Object tail;
4945 XSETCAR (tem, Qnil);
4946 /* In case the parameter appears more than once in the alist,
4947 clear it out. */
4948 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4949 if (CONSP (XCAR (tail))
4950 && EQ (XCAR (XCAR (tail)), param))
4951 XSETCAR (XCAR (tail), Qnil);
4953 else
4954 tem = Fassq (param, Vdefault_frame_alist);
4956 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4957 look in the X resources. */
4958 if (EQ (tem, Qnil))
4960 if (attribute && dpyinfo)
4962 AUTO_STRING (at, attribute);
4963 AUTO_STRING (cl, class);
4964 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4966 if (NILP (tem))
4967 return Qunbound;
4969 switch (type)
4971 case RES_TYPE_NUMBER:
4972 return make_number (atoi (SSDATA (tem)));
4974 case RES_TYPE_BOOLEAN_NUMBER:
4975 if (!strcmp (SSDATA (tem), "on")
4976 || !strcmp (SSDATA (tem), "true"))
4977 return make_number (1);
4978 return make_number (atoi (SSDATA (tem)));
4979 break;
4981 case RES_TYPE_FLOAT:
4982 return make_float (atof (SSDATA (tem)));
4984 case RES_TYPE_BOOLEAN:
4985 tem = Fdowncase (tem);
4986 if (!strcmp (SSDATA (tem), "on")
4987 #ifdef HAVE_NS
4988 || !strcmp (SSDATA (tem), "yes")
4989 #endif
4990 || !strcmp (SSDATA (tem), "true"))
4991 return Qt;
4992 else
4993 return Qnil;
4995 case RES_TYPE_STRING:
4996 return tem;
4998 case RES_TYPE_SYMBOL:
4999 /* As a special case, we map the values `true' and `on'
5000 to Qt, and `false' and `off' to Qnil. */
5002 Lisp_Object lower;
5003 lower = Fdowncase (tem);
5004 if (!strcmp (SSDATA (lower), "on")
5005 #ifdef HAVE_NS
5006 || !strcmp (SSDATA (lower), "yes")
5007 #endif
5008 || !strcmp (SSDATA (lower), "true"))
5009 return Qt;
5010 else if (!strcmp (SSDATA (lower), "off")
5011 #ifdef HAVE_NS
5012 || !strcmp (SSDATA (lower), "no")
5013 #endif
5014 || !strcmp (SSDATA (lower), "false"))
5015 return Qnil;
5016 else
5017 return Fintern (tem, Qnil);
5020 default:
5021 emacs_abort ();
5024 else
5025 return Qunbound;
5027 return Fcdr (tem);
5030 static Lisp_Object
5031 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
5032 const char *attribute, const char *class,
5033 enum resource_types type)
5035 return x_get_arg (FRAME_DISPLAY_INFO (f),
5036 alist, param, attribute, class, type);
5039 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
5041 Lisp_Object
5042 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
5043 Lisp_Object param,
5044 const char *attribute, const char *class,
5045 enum resource_types type)
5047 Lisp_Object value;
5049 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
5050 attribute, class, type);
5051 if (! NILP (value) && ! EQ (value, Qunbound))
5052 store_frame_param (f, param, value);
5054 return value;
5058 /* Record in frame F the specified or default value according to ALIST
5059 of the parameter named PROP (a Lisp symbol).
5060 If no value is specified for PROP, look for an X default for XPROP
5061 on the frame named NAME.
5062 If that is not found either, use the value DEFLT. */
5064 Lisp_Object
5065 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
5066 Lisp_Object deflt, const char *xprop, const char *xclass,
5067 enum resource_types type)
5069 Lisp_Object tem;
5071 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
5072 if (EQ (tem, Qunbound))
5073 tem = deflt;
5074 AUTO_FRAME_ARG (arg, prop, tem);
5075 x_set_frame_parameters (f, arg);
5076 return tem;
5080 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
5083 * XParseGeometry parses strings of the form
5084 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
5085 * width, height, xoffset, and yoffset are unsigned integers.
5086 * Example: "=80x24+300-49"
5087 * The equal sign is optional.
5088 * It returns a bitmask that indicates which of the four values
5089 * were actually found in the string. For each value found,
5090 * the corresponding argument is updated; for each value
5091 * not found, the corresponding argument is left unchanged.
5094 static int
5095 XParseGeometry (char *string,
5096 int *x, int *y,
5097 unsigned int *width, unsigned int *height)
5099 int mask = NoValue;
5100 char *strind;
5101 unsigned long tempWidth UNINIT, tempHeight UNINIT;
5102 long int tempX UNINIT, tempY UNINIT;
5103 char *nextCharacter;
5105 if (string == NULL || *string == '\0')
5106 return mask;
5107 if (*string == '=')
5108 string++; /* ignore possible '=' at beg of geometry spec */
5110 strind = string;
5111 if (*strind != '+' && *strind != '-' && *strind != 'x')
5113 tempWidth = strtoul (strind, &nextCharacter, 10);
5114 if (strind == nextCharacter)
5115 return 0;
5116 strind = nextCharacter;
5117 mask |= WidthValue;
5120 if (*strind == 'x' || *strind == 'X')
5122 strind++;
5123 tempHeight = strtoul (strind, &nextCharacter, 10);
5124 if (strind == nextCharacter)
5125 return 0;
5126 strind = nextCharacter;
5127 mask |= HeightValue;
5130 if (*strind == '+' || *strind == '-')
5132 if (*strind == '-')
5133 mask |= XNegative;
5134 tempX = strtol (strind, &nextCharacter, 10);
5135 if (strind == nextCharacter)
5136 return 0;
5137 strind = nextCharacter;
5138 mask |= XValue;
5139 if (*strind == '+' || *strind == '-')
5141 if (*strind == '-')
5142 mask |= YNegative;
5143 tempY = strtol (strind, &nextCharacter, 10);
5144 if (strind == nextCharacter)
5145 return 0;
5146 strind = nextCharacter;
5147 mask |= YValue;
5151 /* If strind isn't at the end of the string then it's an invalid
5152 geometry specification. */
5154 if (*strind != '\0')
5155 return 0;
5157 if (mask & XValue)
5158 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
5159 if (mask & YValue)
5160 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
5161 if (mask & WidthValue)
5162 *width = min (tempWidth, UINT_MAX);
5163 if (mask & HeightValue)
5164 *height = min (tempHeight, UINT_MAX);
5165 return mask;
5168 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
5171 /* NS used to define x-parse-geometry in ns-win.el, but that confused
5172 make-docfile: the documentation string in ns-win.el was used for
5173 x-parse-geometry even in non-NS builds.
5175 With two definitions of x-parse-geometry in this file, various
5176 things still get confused (eg M-x apropos documentation), so that
5177 it is best if the two definitions just share the same doc-string.
5179 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
5180 doc: /* Parse a display geometry string STRING.
5181 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
5182 The properties returned may include `top', `left', `height', and `width'.
5183 For X, the value of `left' or `top' may be an integer,
5184 or a list (+ N) meaning N pixels relative to top/left corner,
5185 or a list (- N) meaning -N pixels relative to bottom/right corner.
5186 On Nextstep, this just calls `ns-parse-geometry'. */)
5187 (Lisp_Object string)
5189 int geometry, x, y;
5190 unsigned int width, height;
5191 Lisp_Object result;
5193 CHECK_STRING (string);
5195 #ifdef HAVE_NS
5196 if (strchr (SSDATA (string), ' ') != NULL)
5197 return call1 (Qns_parse_geometry, string);
5198 #endif
5199 geometry = XParseGeometry (SSDATA (string),
5200 &x, &y, &width, &height);
5201 result = Qnil;
5202 if (geometry & XValue)
5204 Lisp_Object element;
5206 if (x >= 0 && (geometry & XNegative))
5207 element = list3 (Qleft, Qminus, make_number (-x));
5208 else if (x < 0 && ! (geometry & XNegative))
5209 element = list3 (Qleft, Qplus, make_number (x));
5210 else
5211 element = Fcons (Qleft, make_number (x));
5212 result = Fcons (element, result);
5215 if (geometry & YValue)
5217 Lisp_Object element;
5219 if (y >= 0 && (geometry & YNegative))
5220 element = list3 (Qtop, Qminus, make_number (-y));
5221 else if (y < 0 && ! (geometry & YNegative))
5222 element = list3 (Qtop, Qplus, make_number (y));
5223 else
5224 element = Fcons (Qtop, make_number (y));
5225 result = Fcons (element, result);
5228 if (geometry & WidthValue)
5229 result = Fcons (Fcons (Qwidth, make_number (width)), result);
5230 if (geometry & HeightValue)
5231 result = Fcons (Fcons (Qheight, make_number (height)), result);
5233 return result;
5237 /* Calculate the desired size and position of frame F.
5238 Return the flags saying which aspects were specified.
5240 Also set the win_gravity and size_hint_flags of F.
5242 Adjust height for toolbar if TOOLBAR_P is 1.
5244 This function does not make the coordinates positive. */
5246 #define DEFAULT_ROWS 36
5247 #define DEFAULT_COLS 80
5249 long
5250 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
5252 Lisp_Object height, width, user_size, top, left, user_position;
5253 long window_prompting = 0;
5254 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
5255 int parent_done = -1, outer_done = -1;
5257 /* Default values if we fall through.
5258 Actually, if that happens we should get
5259 window manager prompting. */
5260 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
5261 SET_FRAME_COLS (f, DEFAULT_COLS);
5262 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
5263 SET_FRAME_LINES (f, DEFAULT_ROWS);
5265 /* Window managers expect that if program-specified
5266 positions are not (0,0), they're intentional, not defaults. */
5267 f->top_pos = 0;
5268 f->left_pos = 0;
5270 /* Calculate a tool bar height so that the user gets a text display
5271 area of the size he specified with -g or via .Xdefaults. Later
5272 changes of the tool bar height don't change the frame size. This
5273 is done so that users can create tall Emacs frames without having
5274 to guess how tall the tool bar will get. */
5275 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
5277 if (frame_default_tool_bar_height)
5278 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
5279 else
5281 int margin, relief;
5283 relief = (tool_bar_button_relief >= 0
5284 ? tool_bar_button_relief
5285 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
5287 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
5288 margin = XFASTINT (Vtool_bar_button_margin);
5289 else if (CONSP (Vtool_bar_button_margin)
5290 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
5291 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
5292 else
5293 margin = 0;
5295 FRAME_TOOL_BAR_HEIGHT (f)
5296 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
5300 /* Ensure that earlier new_width and new_height settings won't
5301 override what we specify below. */
5302 f->new_width = f->new_height = 0;
5304 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
5305 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
5306 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
5308 if (!EQ (width, Qunbound))
5310 if (CONSP (width) && EQ (XCAR (width), Qtext_pixels))
5312 CHECK_NUMBER (XCDR (width));
5313 if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX))
5314 xsignal1 (Qargs_out_of_range, XCDR (width));
5316 SET_FRAME_WIDTH (f, XINT (XCDR (width)));
5317 f->inhibit_horizontal_resize = true;
5318 *x_width = XINT (XCDR (width));
5320 else if (FLOATP (width))
5322 double d_width = XFLOAT_DATA (width);
5324 if (d_width < 0.0 || d_width > 1.0)
5325 xsignal1 (Qargs_out_of_range, width);
5326 else
5328 int new_width = frame_float (f, width, FRAME_FLOAT_WIDTH,
5329 &parent_done, &outer_done, -1);
5331 if (new_width > -1)
5332 SET_FRAME_WIDTH (f, new_width);
5335 else
5337 CHECK_NUMBER (width);
5338 if ((XINT (width) < 0 || XINT (width) > INT_MAX))
5339 xsignal1 (Qargs_out_of_range, width);
5341 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
5345 if (!EQ (height, Qunbound))
5347 if (CONSP (height) && EQ (XCAR (height), Qtext_pixels))
5349 CHECK_NUMBER (XCDR (height));
5350 if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX))
5351 xsignal1 (Qargs_out_of_range, XCDR (height));
5353 SET_FRAME_HEIGHT (f, XINT (XCDR (height)));
5354 f->inhibit_vertical_resize = true;
5355 *x_height = XINT (XCDR (height));
5357 else if (FLOATP (height))
5359 double d_height = XFLOAT_DATA (height);
5361 if (d_height < 0.0 || d_height > 1.0)
5362 xsignal1 (Qargs_out_of_range, height);
5363 else
5365 int new_height = frame_float (f, height, FRAME_FLOAT_HEIGHT,
5366 &parent_done, &outer_done, -1);
5368 if (new_height > -1)
5369 SET_FRAME_HEIGHT (f, new_height);
5372 else
5374 CHECK_NUMBER (height);
5375 if ((XINT (height) < 0) || (XINT (height) > INT_MAX))
5376 xsignal1 (Qargs_out_of_range, height);
5378 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
5382 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
5383 if (!NILP (user_size) && !EQ (user_size, Qunbound))
5384 window_prompting |= USSize;
5385 else
5386 window_prompting |= PSize;
5389 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
5390 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
5391 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
5392 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
5394 if (EQ (top, Qminus))
5396 f->top_pos = 0;
5397 window_prompting |= YNegative;
5399 else if (CONSP (top) && EQ (XCAR (top), Qminus)
5400 && CONSP (XCDR (top))
5401 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
5403 f->top_pos = - XINT (XCAR (XCDR (top)));
5404 window_prompting |= YNegative;
5406 else if (CONSP (top) && EQ (XCAR (top), Qplus)
5407 && CONSP (XCDR (top))
5408 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
5410 f->top_pos = XINT (XCAR (XCDR (top)));
5412 else if (FLOATP (top))
5413 f->top_pos = frame_float (f, top, FRAME_FLOAT_TOP, &parent_done,
5414 &outer_done, 0);
5415 else if (EQ (top, Qunbound))
5416 f->top_pos = 0;
5417 else
5419 CHECK_TYPE_RANGED_INTEGER (int, top);
5420 f->top_pos = XINT (top);
5421 if (f->top_pos < 0)
5422 window_prompting |= YNegative;
5425 if (EQ (left, Qminus))
5427 f->left_pos = 0;
5428 window_prompting |= XNegative;
5430 else if (CONSP (left) && EQ (XCAR (left), Qminus)
5431 && CONSP (XCDR (left))
5432 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
5434 f->left_pos = - XINT (XCAR (XCDR (left)));
5435 window_prompting |= XNegative;
5437 else if (CONSP (left) && EQ (XCAR (left), Qplus)
5438 && CONSP (XCDR (left))
5439 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
5441 f->left_pos = XINT (XCAR (XCDR (left)));
5443 else if (FLOATP (left))
5444 f->left_pos = frame_float (f, left, FRAME_FLOAT_LEFT, &parent_done,
5445 &outer_done, 0);
5446 else if (EQ (left, Qunbound))
5447 f->left_pos = 0;
5448 else
5450 CHECK_TYPE_RANGED_INTEGER (int, left);
5451 f->left_pos = XINT (left);
5452 if (f->left_pos < 0)
5453 window_prompting |= XNegative;
5456 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
5457 window_prompting |= USPosition;
5458 else
5459 window_prompting |= PPosition;
5462 if (window_prompting & XNegative)
5464 if (window_prompting & YNegative)
5465 f->win_gravity = SouthEastGravity;
5466 else
5467 f->win_gravity = NorthEastGravity;
5469 else
5471 if (window_prompting & YNegative)
5472 f->win_gravity = SouthWestGravity;
5473 else
5474 f->win_gravity = NorthWestGravity;
5477 f->size_hint_flags = window_prompting;
5479 return window_prompting;
5484 #endif /* HAVE_WINDOW_SYSTEM */
5486 void
5487 frame_make_pointer_invisible (struct frame *f)
5489 if (! NILP (Vmake_pointer_invisible))
5491 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
5492 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
5494 f->mouse_moved = 0;
5495 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
5496 f->pointer_invisible = 1;
5501 void
5502 frame_make_pointer_visible (struct frame *f)
5504 /* We don't check Vmake_pointer_invisible here in case the
5505 pointer was invisible when Vmake_pointer_invisible was set to nil. */
5506 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
5507 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
5509 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
5510 f->pointer_invisible = 0;
5514 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
5515 Sframe_pointer_visible_p, 0, 1, 0,
5516 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
5517 Otherwise it returns nil. FRAME omitted or nil means the
5518 selected frame. This is useful when `make-pointer-invisible' is set. */)
5519 (Lisp_Object frame)
5521 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
5526 /***********************************************************************
5527 Multimonitor data
5528 ***********************************************************************/
5530 #ifdef HAVE_WINDOW_SYSTEM
5532 # if (defined HAVE_NS \
5533 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
5534 void
5535 free_monitors (struct MonitorInfo *monitors, int n_monitors)
5537 int i;
5538 for (i = 0; i < n_monitors; ++i)
5539 xfree (monitors[i].name);
5540 xfree (monitors);
5542 # endif
5544 Lisp_Object
5545 make_monitor_attribute_list (struct MonitorInfo *monitors,
5546 int n_monitors,
5547 int primary_monitor,
5548 Lisp_Object monitor_frames,
5549 const char *source)
5551 Lisp_Object attributes_list = Qnil;
5552 Lisp_Object primary_monitor_attributes = Qnil;
5553 int i;
5555 for (i = 0; i < n_monitors; ++i)
5557 Lisp_Object geometry, workarea, attributes = Qnil;
5558 struct MonitorInfo *mi = &monitors[i];
5560 if (mi->geom.width == 0) continue;
5562 workarea = list4i (mi->work.x, mi->work.y,
5563 mi->work.width, mi->work.height);
5564 geometry = list4i (mi->geom.x, mi->geom.y,
5565 mi->geom.width, mi->geom.height);
5566 attributes = Fcons (Fcons (Qsource, build_string (source)),
5567 attributes);
5568 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
5569 attributes);
5570 attributes = Fcons (Fcons (Qmm_size,
5571 list2i (mi->mm_width, mi->mm_height)),
5572 attributes);
5573 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
5574 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
5575 if (mi->name)
5576 attributes = Fcons (Fcons (Qname, make_string (mi->name,
5577 strlen (mi->name))),
5578 attributes);
5580 if (i == primary_monitor)
5581 primary_monitor_attributes = attributes;
5582 else
5583 attributes_list = Fcons (attributes, attributes_list);
5586 if (!NILP (primary_monitor_attributes))
5587 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
5588 return attributes_list;
5591 #endif /* HAVE_WINDOW_SYSTEM */
5594 /***********************************************************************
5595 Initialization
5596 ***********************************************************************/
5598 void
5599 syms_of_frame (void)
5601 DEFSYM (Qframep, "framep");
5602 DEFSYM (Qframe_live_p, "frame-live-p");
5603 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
5604 DEFSYM (Qdisplay_monitor_attributes_list, "display-monitor-attributes-list");
5605 DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total");
5606 DEFSYM (Qexplicit_name, "explicit-name");
5607 DEFSYM (Qheight, "height");
5608 DEFSYM (Qicon, "icon");
5609 DEFSYM (Qminibuffer, "minibuffer");
5610 DEFSYM (Qundecorated, "undecorated");
5611 DEFSYM (Qno_special_glyphs, "no-special-glyphs");
5612 DEFSYM (Qparent_frame, "parent-frame");
5613 DEFSYM (Qskip_taskbar, "skip-taskbar");
5614 DEFSYM (Qno_focus_on_map, "no-focus-on-map");
5615 DEFSYM (Qno_accept_focus, "no-accept-focus");
5616 DEFSYM (Qz_group, "z-group");
5617 DEFSYM (Qoverride_redirect, "override-redirect");
5618 DEFSYM (Qdelete_before, "delete-before");
5619 DEFSYM (Qmodeline, "modeline");
5620 DEFSYM (Qonly, "only");
5621 DEFSYM (Qnone, "none");
5622 DEFSYM (Qwidth, "width");
5623 DEFSYM (Qtext_pixels, "text-pixels");
5624 DEFSYM (Qgeometry, "geometry");
5625 DEFSYM (Qicon_left, "icon-left");
5626 DEFSYM (Qicon_top, "icon-top");
5627 DEFSYM (Qtooltip, "tooltip");
5628 DEFSYM (Quser_position, "user-position");
5629 DEFSYM (Quser_size, "user-size");
5630 DEFSYM (Qwindow_id, "window-id");
5631 #ifdef HAVE_X_WINDOWS
5632 DEFSYM (Qouter_window_id, "outer-window-id");
5633 #endif
5634 DEFSYM (Qparent_id, "parent-id");
5635 DEFSYM (Qx, "x");
5636 DEFSYM (Qw32, "w32");
5637 DEFSYM (Qpc, "pc");
5638 DEFSYM (Qns, "ns");
5639 DEFSYM (Qvisible, "visible");
5640 DEFSYM (Qbuffer_predicate, "buffer-predicate");
5641 DEFSYM (Qbuffer_list, "buffer-list");
5642 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
5643 DEFSYM (Qdisplay_type, "display-type");
5644 DEFSYM (Qbackground_mode, "background-mode");
5645 DEFSYM (Qnoelisp, "noelisp");
5646 DEFSYM (Qtty_color_mode, "tty-color-mode");
5647 DEFSYM (Qtty, "tty");
5648 DEFSYM (Qtty_type, "tty-type");
5650 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
5652 DEFSYM (Qfullwidth, "fullwidth");
5653 DEFSYM (Qfullheight, "fullheight");
5654 DEFSYM (Qfullboth, "fullboth");
5655 DEFSYM (Qmaximized, "maximized");
5656 DEFSYM (Qx_resource_name, "x-resource-name");
5657 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
5659 DEFSYM (Qworkarea, "workarea");
5660 DEFSYM (Qmm_size, "mm-size");
5661 DEFSYM (Qframes, "frames");
5662 DEFSYM (Qsource, "source");
5664 DEFSYM (Qframe_edges, "frame-edges");
5665 DEFSYM (Qouter_edges, "outer-edges");
5666 DEFSYM (Qouter_position, "outer-position");
5667 DEFSYM (Qouter_size, "outer-size");
5668 DEFSYM (Qnative_edges, "native-edges");
5669 DEFSYM (Qinner_edges, "inner-edges");
5670 DEFSYM (Qexternal_border_size, "external-border-size");
5671 DEFSYM (Qtitle_bar_size, "title-bar-size");
5672 DEFSYM (Qmenu_bar_external, "menu-bar-external");
5673 DEFSYM (Qmenu_bar_size, "menu-bar-size");
5674 DEFSYM (Qtool_bar_external, "tool-bar-external");
5675 DEFSYM (Qtool_bar_size, "tool-bar-size");
5676 /* The following are used for frame_size_history. */
5677 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
5678 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
5679 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
5680 DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
5681 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
5682 DEFSYM (Qset_frame_size, "set-frame-size");
5683 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
5684 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
5685 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
5686 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
5687 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
5688 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
5689 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
5690 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
5691 DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
5692 DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
5693 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
5694 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
5695 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
5696 DEFSYM (Qtb_size_cb, "tb-size-cb");
5697 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
5698 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
5699 DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines");
5700 DEFSYM (Qchange_frame_size, "change-frame-size");
5701 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
5702 DEFSYM (Qset_window_configuration, "set-window-configuration");
5703 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
5704 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
5705 DEFSYM (Qterminal_frame, "terminal-frame");
5707 #ifdef HAVE_NS
5708 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
5709 #endif
5710 #ifdef NS_IMPL_COCOA
5711 DEFSYM (Qns_appearance, "ns-appearance");
5712 DEFSYM (Qns_transparent_titlebar, "ns-transparent-titlebar");
5713 #endif
5715 DEFSYM (Qalpha, "alpha");
5716 DEFSYM (Qauto_lower, "auto-lower");
5717 DEFSYM (Qauto_raise, "auto-raise");
5718 DEFSYM (Qborder_color, "border-color");
5719 DEFSYM (Qborder_width, "border-width");
5720 DEFSYM (Qouter_border_width, "outer-border-width");
5721 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
5722 DEFSYM (Qcursor_color, "cursor-color");
5723 DEFSYM (Qcursor_type, "cursor-type");
5724 DEFSYM (Qfont_backend, "font-backend");
5725 DEFSYM (Qfullscreen, "fullscreen");
5726 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
5727 DEFSYM (Qicon_name, "icon-name");
5728 DEFSYM (Qicon_type, "icon-type");
5729 DEFSYM (Qinternal_border_width, "internal-border-width");
5730 DEFSYM (Qleft_fringe, "left-fringe");
5731 DEFSYM (Qline_spacing, "line-spacing");
5732 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
5733 DEFSYM (Qupdate_frame_menubar, "update-frame-menubar");
5734 DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1");
5735 DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2");
5736 DEFSYM (Qmouse_color, "mouse-color");
5737 DEFSYM (Qname, "name");
5738 DEFSYM (Qright_divider_width, "right-divider-width");
5739 DEFSYM (Qright_fringe, "right-fringe");
5740 DEFSYM (Qscreen_gamma, "screen-gamma");
5741 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
5742 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
5743 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
5744 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
5745 DEFSYM (Qsticky, "sticky");
5746 DEFSYM (Qtitle, "title");
5747 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
5748 DEFSYM (Qtool_bar_position, "tool-bar-position");
5749 DEFSYM (Qunsplittable, "unsplittable");
5750 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
5751 DEFSYM (Qvisibility, "visibility");
5752 DEFSYM (Qwait_for_wm, "wait-for-wm");
5753 DEFSYM (Qinhibit_double_buffering, "inhibit-double-buffering");
5754 DEFSYM (Qno_other_frame, "no-other-frame");
5755 DEFSYM (Qbelow, "below");
5756 DEFSYM (Qabove_suspended, "above-suspended");
5757 DEFSYM (Qmin_width, "min-width");
5758 DEFSYM (Qmin_height, "min-height");
5759 DEFSYM (Qmouse_wheel_frame, "mouse-wheel-frame");
5760 DEFSYM (Qkeep_ratio, "keep-ratio");
5761 DEFSYM (Qwidth_only, "width-only");
5762 DEFSYM (Qheight_only, "height-only");
5763 DEFSYM (Qleft_only, "left-only");
5764 DEFSYM (Qtop_only, "top-only");
5765 DEFSYM (Qiconify_top_level, "iconify-top-level");
5766 DEFSYM (Qmake_invisible, "make-invisible");
5769 int i;
5771 for (i = 0; i < ARRAYELTS (frame_parms); i++)
5773 Lisp_Object v = (frame_parms[i].sym < 0
5774 ? intern_c_string (frame_parms[i].name)
5775 : builtin_lisp_symbol (frame_parms[i].sym));
5776 Fput (v, Qx_frame_parameter, make_number (i));
5780 #ifdef HAVE_WINDOW_SYSTEM
5781 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
5782 doc: /* The name Emacs uses to look up X resources.
5783 `x-get-resource' uses this as the first component of the instance name
5784 when requesting resource values.
5785 Emacs initially sets `x-resource-name' to the name under which Emacs
5786 was invoked, or to the value specified with the `-name' or `-rn'
5787 switches, if present.
5789 It may be useful to bind this variable locally around a call
5790 to `x-get-resource'. See also the variable `x-resource-class'. */);
5791 Vx_resource_name = Qnil;
5793 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5794 doc: /* The class Emacs uses to look up X resources.
5795 `x-get-resource' uses this as the first component of the instance class
5796 when requesting resource values.
5798 Emacs initially sets `x-resource-class' to "Emacs".
5800 Setting this variable permanently is not a reasonable thing to do,
5801 but binding this variable locally around a call to `x-get-resource'
5802 is a reasonable practice. See also the variable `x-resource-name'. */);
5803 Vx_resource_class = build_string (EMACS_CLASS);
5805 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5806 doc: /* The lower limit of the frame opacity (alpha transparency).
5807 The value should range from 0 (invisible) to 100 (completely opaque).
5808 You can also use a floating number between 0.0 and 1.0. */);
5809 Vframe_alpha_lower_limit = make_number (20);
5810 #endif
5812 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5813 doc: /* Alist of default values for frame creation.
5814 These may be set in your init file, like this:
5815 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5816 These override values given in window system configuration data,
5817 including X Windows' defaults database.
5818 For values specific to the first Emacs frame, see `initial-frame-alist'.
5819 For window-system specific values, see `window-system-default-frame-alist'.
5820 For values specific to the separate minibuffer frame, see
5821 `minibuffer-frame-alist'.
5822 The `menu-bar-lines' element of the list controls whether new frames
5823 have menu bars; `menu-bar-mode' works by altering this element.
5824 Setting this variable does not affect existing frames, only new ones. */);
5825 Vdefault_frame_alist = Qnil;
5827 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5828 doc: /* Default position of vertical scroll bars on this window-system. */);
5829 #ifdef HAVE_WINDOW_SYSTEM
5830 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5831 /* MS-Windows, macOS, and GTK have scroll bars on the right by
5832 default. */
5833 Vdefault_frame_scroll_bars = Qright;
5834 #else
5835 Vdefault_frame_scroll_bars = Qleft;
5836 #endif
5837 #else
5838 Vdefault_frame_scroll_bars = Qnil;
5839 #endif
5841 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5842 scroll_bar_adjust_thumb_portion_p,
5843 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5844 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5845 even if the end of the buffer is shown (i.e. overscrolling).
5846 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5847 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5848 is visible. In this case you can not overscroll. */);
5849 scroll_bar_adjust_thumb_portion_p = 1;
5851 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5852 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5854 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5855 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5856 `mouse-position' and `mouse-pixel-position' call this function, passing their
5857 usual return value as argument, and return whatever this function returns.
5858 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5859 which need to do mouse handling at the Lisp level. */);
5860 Vmouse_position_function = Qnil;
5862 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5863 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5864 If the value is an integer, highlighting is only shown after moving the
5865 mouse, while keyboard input turns off the highlight even when the mouse
5866 is over the clickable text. However, the mouse shape still indicates
5867 when the mouse is over clickable text. */);
5868 Vmouse_highlight = Qt;
5870 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5871 doc: /* If non-nil, make pointer invisible while typing.
5872 The pointer becomes visible again when the mouse is moved. */);
5873 Vmake_pointer_invisible = Qt;
5875 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5876 doc: /* Normal hook run when a frame gains input focus.
5877 The frame gaining focus is selected at the time this hook is run. */);
5878 Vfocus_in_hook = Qnil;
5880 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5881 doc: /* Normal hook run when all frames lost input focus. */);
5882 Vfocus_out_hook = Qnil;
5884 DEFVAR_LISP ("move-frame-functions", Vmove_frame_functions,
5885 doc: /* Functions run after a frame was moved.
5886 The functions are run with one arg, the frame that moved. */);
5887 Vmove_frame_functions = Qnil;
5889 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5890 doc: /* Functions run before deleting a frame.
5891 The functions are run with one arg, the frame to be deleted.
5892 See `delete-frame'.
5894 Note that functions in this list may be called just before the frame is
5895 actually deleted, or some time later (or even both when an earlier function
5896 in `delete-frame-functions' (indirectly) calls `delete-frame'
5897 recursively). */);
5898 Vdelete_frame_functions = Qnil;
5899 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5901 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5902 doc: /* Non-nil if Menu-Bar mode is enabled.
5903 See the command `menu-bar-mode' for a description of this minor mode.
5904 Setting this variable directly does not take effect;
5905 either customize it (see the info node `Easy Customization')
5906 or call the function `menu-bar-mode'. */);
5907 Vmenu_bar_mode = Qt;
5909 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5910 doc: /* Non-nil if Tool-Bar mode is enabled.
5911 See the command `tool-bar-mode' for a description of this minor mode.
5912 Setting this variable directly does not take effect;
5913 either customize it (see the info node `Easy Customization')
5914 or call the function `tool-bar-mode'. */);
5915 #ifdef HAVE_WINDOW_SYSTEM
5916 Vtool_bar_mode = Qt;
5917 #else
5918 Vtool_bar_mode = Qnil;
5919 #endif
5921 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5922 doc: /* Minibuffer-less frames by default use this frame's minibuffer.
5923 Emacs consults this variable only when creating a minibuffer-less frame
5924 and no explicit minibuffer window has been specified for that frame via
5925 the `minibuffer' frame parameter. Once such a frame has been created,
5926 setting this variable does not change that frame's previous association.
5928 This variable is local to the current terminal and cannot be buffer-local. */);
5930 DEFVAR_LISP ("focus-follows-mouse", focus_follows_mouse,
5931 doc: /* Non-nil if window system changes focus when you move the mouse.
5932 You should set this variable to tell Emacs how your window manager
5933 handles focus, since there is no way in general for Emacs to find out
5934 automatically.
5936 There are three meaningful values:
5938 - The default nil should be used when your window manager follows a
5939 "click-to-focus" policy where you have to click the mouse inside of a
5940 frame in order for that frame to get focus.
5942 - The value t should be used when your window manager has the focus
5943 automatically follow the position of the mouse pointer but a window
5944 that gains focus is not raised automatically.
5946 - The value `auto-raise' should be used when your window manager has the
5947 focus automatically follow the position of the mouse pointer and a
5948 window that gains focus is raised automatically.
5950 If this option is non-nil, Emacs moves the mouse pointer to the frame
5951 selected by `select-frame-set-input-focus'. This function is used by a
5952 number of commands like, for example, `other-frame' and `pop-to-buffer'.
5953 If this option is nil and your focus follows mouse window manager does
5954 not autonomously move the mouse pointer to the newly selected frame, the
5955 previously selected window manager window might get reselected instead
5956 immediately.
5958 The distinction between the values t and `auto-raise' is not needed for
5959 "normal" frames because the window manager takes care of raising them.
5960 Setting this to `auto-raise' will, however, override the standard
5961 behavior of a window manager that does not automatically raise the frame
5962 that gets focus. Setting this to `auto-raise' is also necessary to
5963 automatically raise child frames which are usually left alone by the
5964 window manager.
5966 Note that this option does not distinguish "sloppy" focus (where the
5967 frame that previously had focus retains focus as long as the mouse
5968 pointer does not move into another window manager window) from "strict"
5969 focus (where a frame immediately loses focus when it's left by the mouse
5970 pointer).
5972 In order to extend a "focus follows mouse" policy to individual Emacs
5973 windows, customize the variable `mouse-autoselect-window'. */);
5974 focus_follows_mouse = Qnil;
5976 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5977 doc: /* Non-nil means resize frames pixelwise.
5978 If this option is nil, resizing a frame rounds its sizes to the frame's
5979 current values of `frame-char-height' and `frame-char-width'. If this
5980 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5981 by one pixel.
5983 With some window managers you may have to set this to non-nil in order
5984 to set the size of a frame in pixels, to maximize frames or to make them
5985 fullscreen. To resize your initial frame pixelwise, set this option to
5986 a non-nil value in your init file. */);
5987 frame_resize_pixelwise = 0;
5989 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5990 doc: /* Whether frames should be resized implicitly.
5991 If this option is nil, setting font, menu bar, tool bar, internal
5992 borders, fringes or scroll bars of a specific frame may resize the frame
5993 in order to preserve the number of columns or lines it displays. If
5994 this option is t, no such resizing is done. Note that the size of
5995 fullscreen and maximized frames, the height of fullheight frames and the
5996 width of fullwidth frames never change implicitly.
5998 The value of this option can be also be a list of frame parameters. In
5999 this case, resizing is inhibited when changing a parameter that appears
6000 in that list. The parameters currently handled by this option include
6001 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
6002 `tool-bar-lines'.
6004 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
6005 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
6006 `right-fringe' is handled as if the frame contained just one live
6007 window. This means, for example, that removing vertical scroll bars on
6008 a frame containing several side by side windows will shrink the frame
6009 width by the width of one scroll bar provided this option is nil and
6010 keep it unchanged if this option is either t or a list containing
6011 `vertical-scroll-bars'.
6013 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
6014 \(which means that adding/removing a tool bar does not change the frame
6015 height), nil on all other window systems including GTK+ (which means
6016 that changing any of the parameters listed above may change the size of
6017 the frame), and t otherwise (which means the frame size never changes
6018 implicitly when there's no window system support).
6020 Note that when a frame is not large enough to accommodate a change of
6021 any of the parameters listed above, Emacs may try to enlarge the frame
6022 even if this option is non-nil. */);
6023 #if defined (HAVE_WINDOW_SYSTEM)
6024 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
6025 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
6026 #else
6027 frame_inhibit_implied_resize = Qnil;
6028 #endif
6029 #else
6030 frame_inhibit_implied_resize = Qt;
6031 #endif
6033 DEFVAR_LISP ("frame-size-history", frame_size_history,
6034 doc: /* History of frame size adjustments.
6035 If non-nil, list recording frame size adjustment. Adjustments are
6036 recorded only if the first element of this list is a positive number.
6037 Adding an adjustment decrements that number by one.
6039 The remaining elements are the adjustments. Each adjustment is a list
6040 of four elements `frame', `function', `sizes' and `more'. `frame' is
6041 the affected frame and `function' the invoking function. `sizes' is
6042 usually a list of four elements `old-width', `old-height', `new-width'
6043 and `new-height' representing the old and new sizes recorded/requested
6044 by `function'. `more' is a list with additional information.
6046 The function `frame--size-history' displays the value of this variable
6047 in a more readable form. */);
6048 frame_size_history = Qnil;
6050 DEFVAR_BOOL ("tooltip-reuse-hidden-frame", tooltip_reuse_hidden_frame,
6051 doc: /* Non-nil means reuse hidden tooltip frames.
6052 When this is nil, delete a tooltip frame when hiding the associated
6053 tooltip. When this is non-nil, make the tooltip frame invisible only,
6054 so it can be reused when the next tooltip is shown.
6056 Setting this to non-nil may drastically reduce the consing overhead
6057 incurred by creating new tooltip frames. However, a value of non-nil
6058 means also that intermittent changes of faces or `default-frame-alist'
6059 are not applied when showing a tooltip in a reused frame.
6061 This variable is effective only with the X toolkit (and there only when
6062 Gtk+ tooltips are not used) and on Windows. */);
6063 tooltip_reuse_hidden_frame = false;
6065 DEFVAR_LISP ("iconify-child-frame", iconify_child_frame,
6066 doc: /* How to handle iconification of child frames.
6067 This variable tells Emacs how to proceed when it is asked to iconify a
6068 child frame. If it is nil, `iconify-frame' will do nothing when invoked
6069 on a child frame. If it is `iconify-top-level', Emacs will try to
6070 iconify the top level frame associated with this child frame instead.
6071 If it is `make-invisible', Emacs will try to make this child frame
6072 invisible instead.
6074 Any other value means to try iconifying the child frame. Since such an
6075 attempt is not honored by all window managers and may even lead to
6076 making the child frame unresponsive to user actions, the default is to
6077 iconify the top level frame instead. */);
6078 iconify_child_frame = Qiconify_top_level;
6080 staticpro (&Vframe_list);
6082 defsubr (&Sframep);
6083 defsubr (&Sframe_live_p);
6084 defsubr (&Swindow_system);
6085 defsubr (&Sframe_windows_min_size);
6086 defsubr (&Smake_terminal_frame);
6087 defsubr (&Shandle_switch_frame);
6088 defsubr (&Sselect_frame);
6089 defsubr (&Sselected_frame);
6090 defsubr (&Sframe_list);
6091 defsubr (&Sframe_parent);
6092 defsubr (&Sframe_ancestor_p);
6093 defsubr (&Snext_frame);
6094 defsubr (&Sprevious_frame);
6095 defsubr (&Slast_nonminibuf_frame);
6096 defsubr (&Sdelete_frame);
6097 defsubr (&Smouse_position);
6098 defsubr (&Smouse_pixel_position);
6099 defsubr (&Sset_mouse_position);
6100 defsubr (&Sset_mouse_pixel_position);
6101 #if 0
6102 defsubr (&Sframe_configuration);
6103 defsubr (&Srestore_frame_configuration);
6104 #endif
6105 defsubr (&Smake_frame_visible);
6106 defsubr (&Smake_frame_invisible);
6107 defsubr (&Siconify_frame);
6108 defsubr (&Sframe_visible_p);
6109 defsubr (&Svisible_frame_list);
6110 defsubr (&Sraise_frame);
6111 defsubr (&Slower_frame);
6112 defsubr (&Sx_focus_frame);
6113 defsubr (&Sframe_after_make_frame);
6114 defsubr (&Sredirect_frame_focus);
6115 defsubr (&Sframe_focus);
6116 defsubr (&Sframe_parameters);
6117 defsubr (&Sframe_parameter);
6118 defsubr (&Smodify_frame_parameters);
6119 defsubr (&Sframe_char_height);
6120 defsubr (&Sframe_char_width);
6121 defsubr (&Sframe_native_height);
6122 defsubr (&Sframe_native_width);
6123 defsubr (&Sframe_text_cols);
6124 defsubr (&Sframe_text_lines);
6125 defsubr (&Sframe_total_cols);
6126 defsubr (&Sframe_total_lines);
6127 defsubr (&Sframe_text_width);
6128 defsubr (&Sframe_text_height);
6129 defsubr (&Sscroll_bar_width);
6130 defsubr (&Sscroll_bar_height);
6131 defsubr (&Sfringe_width);
6132 defsubr (&Sframe_internal_border_width);
6133 defsubr (&Sright_divider_width);
6134 defsubr (&Sbottom_divider_width);
6135 defsubr (&Stool_bar_pixel_width);
6136 defsubr (&Sset_frame_height);
6137 defsubr (&Sset_frame_width);
6138 defsubr (&Sset_frame_size);
6139 defsubr (&Sframe_position);
6140 defsubr (&Sset_frame_position);
6141 defsubr (&Sframe_pointer_visible_p);
6143 #ifdef HAVE_WINDOW_SYSTEM
6144 defsubr (&Sx_get_resource);
6145 defsubr (&Sx_parse_geometry);
6146 #endif