Fix the --without-x build
[emacs.git] / src / frame.c
blobab801eec9c7907f265c1d4079fa7003102dafac2
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2017 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or (at
10 your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <limits.h>
27 #include <c-ctype.h>
29 #include "lisp.h"
31 #ifdef HAVE_WINDOW_SYSTEM
32 #include TERM_HEADER
33 #endif /* HAVE_WINDOW_SYSTEM */
35 #include "buffer.h"
36 /* These help us bind and responding to switch-frame events. */
37 #include "keyboard.h"
38 #include "frame.h"
39 #include "blockinput.h"
40 #include "termchar.h"
41 #include "termhooks.h"
42 #include "dispextern.h"
43 #include "window.h"
44 #ifdef HAVE_WINDOW_SYSTEM
45 #include "fontset.h"
46 #endif
47 #include "cm.h"
48 #ifdef MSDOS
49 #include "msdos.h"
50 #include "dosfns.h"
51 #endif
52 #ifdef USE_X_TOOLKIT
53 #include "widget.h"
54 #endif
56 /* The currently selected frame. */
58 Lisp_Object selected_frame;
60 /* A frame which is not just a mini-buffer, or NULL if there are no such
61 frames. This is usually the most recent such frame that was selected. */
63 static struct frame *last_nonminibuf_frame;
65 /* False means there are no visible garbaged frames. */
66 bool frame_garbaged;
68 /* The default tool bar height for future frames. */
69 #if defined USE_GTK || defined HAVE_NS
70 enum { frame_default_tool_bar_height = 0 };
71 #else
72 int frame_default_tool_bar_height;
73 #endif
75 #ifdef HAVE_WINDOW_SYSTEM
76 static void x_report_frame_params (struct frame *, Lisp_Object *);
77 #endif
79 /* These setters are used only in this file, so they can be private. */
80 static void
81 fset_buffer_predicate (struct frame *f, Lisp_Object val)
83 f->buffer_predicate = val;
85 static void
86 fset_minibuffer_window (struct frame *f, Lisp_Object val)
88 f->minibuffer_window = val;
91 struct frame *
92 decode_live_frame (register Lisp_Object frame)
94 if (NILP (frame))
95 frame = selected_frame;
96 CHECK_LIVE_FRAME (frame);
97 return XFRAME (frame);
100 struct frame *
101 decode_any_frame (register Lisp_Object frame)
103 if (NILP (frame))
104 frame = selected_frame;
105 CHECK_FRAME (frame);
106 return XFRAME (frame);
109 #ifdef HAVE_WINDOW_SYSTEM
110 bool
111 display_available (void)
113 return x_display_list != NULL;
115 #endif
117 struct frame *
118 decode_window_system_frame (Lisp_Object frame)
120 struct frame *f = decode_live_frame (frame);
121 check_window_system (f);
122 #ifdef HAVE_WINDOW_SYSTEM
123 return f;
124 #endif
127 void
128 check_window_system (struct frame *f)
130 #ifdef HAVE_WINDOW_SYSTEM
131 if (window_system_available (f))
132 return;
133 #endif
134 error (f ? "Window system frame should be used"
135 : "Window system is not in use or not initialized");
138 /* Return the value of frame parameter PROP in frame FRAME. */
140 Lisp_Object
141 get_frame_param (register struct frame *frame, Lisp_Object prop)
143 register Lisp_Object tem;
145 tem = Fassq (prop, frame->param_alist);
146 if (EQ (tem, Qnil))
147 return tem;
148 return Fcdr (tem);
152 void
153 frame_size_history_add (struct frame *f, Lisp_Object fun_symbol,
154 int width, int height, Lisp_Object rest)
156 Lisp_Object frame;
158 XSETFRAME (frame, f);
159 if (CONSP (frame_size_history)
160 && INTEGERP (XCAR (frame_size_history))
161 && 0 < XINT (XCAR (frame_size_history)))
162 frame_size_history =
163 Fcons (make_number (XINT (XCAR (frame_size_history)) - 1),
164 Fcons (list4
165 (frame, fun_symbol,
166 ((width > 0)
167 ? list4 (make_number (FRAME_TEXT_WIDTH (f)),
168 make_number (FRAME_TEXT_HEIGHT (f)),
169 make_number (width),
170 make_number (height))
171 : Qnil),
172 rest),
173 XCDR (frame_size_history)));
177 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
178 state of frame F would be affected by a vertical (horizontal if
179 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
180 parameter that is changed. */
181 bool
182 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
184 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
185 bool inhibit
186 = (f->after_make_frame
187 ? (EQ (frame_inhibit_implied_resize, Qt)
188 || (CONSP (frame_inhibit_implied_resize)
189 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))
190 || (horizontal
191 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight))
192 || (!horizontal
193 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth))
194 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
195 : ((horizontal && f->inhibit_horizontal_resize)
196 || (!horizontal && f->inhibit_vertical_resize)));
197 if (inhibit && !FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
198 frame_size_history_add
199 (f, Qframe_inhibit_resize, 0, 0,
200 list5 (horizontal ? Qt : Qnil, parameter,
201 f->after_make_frame ? Qt : Qnil,
202 frame_inhibit_implied_resize,
203 fullscreen));
205 return inhibit;
208 static void
209 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
211 int nlines;
212 int olines = FRAME_MENU_BAR_LINES (f);
214 /* Right now, menu bars don't work properly in minibuf-only frames;
215 most of the commands try to apply themselves to the minibuffer
216 frame itself, and get an error because you can't switch buffers
217 in or split the minibuffer window. */
218 if (FRAME_MINIBUF_ONLY_P (f))
219 return;
221 if (TYPE_RANGED_INTEGERP (int, value))
222 nlines = XINT (value);
223 else
224 nlines = 0;
226 if (nlines != olines)
228 windows_or_buffers_changed = 14;
229 FRAME_MENU_BAR_LINES (f) = nlines;
230 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
231 change_frame_size (f, FRAME_COLS (f),
232 FRAME_LINES (f) + olines - nlines,
233 0, 1, 0, 0);
237 Lisp_Object Vframe_list;
240 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
241 doc: /* Return non-nil if OBJECT is a frame.
242 Value is:
243 t for a termcap frame (a character-only terminal),
244 `x' for an Emacs frame that is really an X window,
245 `w32' for an Emacs frame that is a window on MS-Windows display,
246 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
247 `pc' for a direct-write MS-DOS frame.
248 See also `frame-live-p'. */)
249 (Lisp_Object object)
251 if (!FRAMEP (object))
252 return Qnil;
253 switch (XFRAME (object)->output_method)
255 case output_initial: /* The initial frame is like a termcap frame. */
256 case output_termcap:
257 return Qt;
258 case output_x_window:
259 return Qx;
260 case output_w32:
261 return Qw32;
262 case output_msdos_raw:
263 return Qpc;
264 case output_ns:
265 return Qns;
266 default:
267 emacs_abort ();
271 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
272 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
273 Value is nil if OBJECT is not a live frame. If object is a live
274 frame, the return value indicates what sort of terminal device it is
275 displayed on. See the documentation of `framep' for possible
276 return values. */)
277 (Lisp_Object object)
279 return ((FRAMEP (object)
280 && FRAME_LIVE_P (XFRAME (object)))
281 ? Fframep (object)
282 : Qnil);
285 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
286 doc: /* The name of the window system that FRAME is displaying through.
287 The value is a symbol:
288 nil for a termcap frame (a character-only terminal),
289 `x' for an Emacs frame that is really an X window,
290 `w32' for an Emacs frame that is a window on MS-Windows display,
291 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
292 `pc' for a direct-write MS-DOS frame.
294 FRAME defaults to the currently selected frame.
296 Use of this function as a predicate is deprecated. Instead,
297 use `display-graphic-p' or any of the other `display-*-p'
298 predicates which report frame's specific UI-related capabilities. */)
299 (Lisp_Object frame)
301 Lisp_Object type;
302 if (NILP (frame))
303 frame = selected_frame;
305 type = Fframep (frame);
307 if (NILP (type))
308 wrong_type_argument (Qframep, frame);
310 if (EQ (type, Qt))
311 return Qnil;
312 else
313 return type;
316 /* Placeholder used by temacs -nw before window.el is loaded. */
317 DEFUN ("frame-windows-min-size", Fframe_windows_min_size,
318 Sframe_windows_min_size, 4, 4, 0,
319 doc: /* */
320 attributes: const)
321 (Lisp_Object frame, Lisp_Object horizontal,
322 Lisp_Object ignore, Lisp_Object pixelwise)
324 return make_number (0);
328 * frame_windows_min_size:
330 * Return the minimum number of lines (columns if HORIZONTAL is non-nil)
331 * of FRAME. If PIXELWISE is non-nil, return the minimum inner height
332 * (width) of FRAME in pixels.
334 * This value is calculated by the function `frame-windows-min-size' in
335 * window.el unless the `min-height' (`min-width' if HORIZONTAL is
336 * non-nil) parameter of FRAME is non-nil thus explicitly specifying the
337 * value to be returned. In that latter case IGNORE is ignored.
339 * If `frame-windows-min-size' is called, it will make sure that the
340 * return value accommodates all windows of FRAME respecting the values
341 * of `window-min-height' (`window-min-width' if HORIZONTAL is non-nil).
342 * With IGNORE non-nil the values of these variables are ignored.
344 * In either case, never return a value less than 1.
346 static int
347 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal,
348 Lisp_Object ignore, Lisp_Object pixelwise)
350 struct frame *f = XFRAME (frame);
351 Lisp_Object par_size;
353 if ((!NILP (horizontal)
354 && NUMBERP (par_size = get_frame_param (f, Qmin_width)))
355 || (NILP (horizontal)
356 && NUMBERP (par_size = get_frame_param (f, Qmin_height))))
358 int min_size = XINT (par_size);
360 /* Don't allow phantom frames. */
361 if (min_size < 1)
362 min_size = 1;
364 return (NILP (pixelwise)
365 ? min_size
366 : min_size * (NILP (horizontal)
367 ? FRAME_LINE_HEIGHT (f)
368 : FRAME_COLUMN_WIDTH (f)));
370 else
371 return XINT (call4 (Qframe_windows_min_size, frame, horizontal,
372 ignore, pixelwise));
376 #ifdef HAVE_WINDOW_SYSTEM
378 * keep_ratio:
380 * Preserve ratios of frame F which usually happens after its parent
381 * frame P got resized. OLD_WIDTH, OLD_HEIGHT specifies the old native
382 * size of F's parent, NEW_WIDTH and NEW_HEIGHT its new size.
384 * Adjust F's width if F's 'keep_ratio' parameter is non-nil and, if
385 * it is a cons, its car is not 'height-only'. Adjust F's height if F's
386 * 'keep_ratio' parameter is non-nil and, if it is a cons, its car
387 * is not 'width-only'.
389 * Adjust F's left position if F's 'keep_ratio' parameter is non-nil
390 * and, if its is a cons, its cdr is non-nil and not 'top-only'. Adjust
391 * F's top position if F's 'keep_ratio' parameter is non-nil and, if
392 * its is a cons, its cdr is non-nil and not 'left-only'.
394 * Note that when positional adjustment is requested but the size of F
395 * should remain unaltered in the corresponding direction, this routine
396 * tries to constrain F to its parent frame - something which usually
397 * happens when the parent frame shrinks. This means, however, that
398 * when the parent frame is re-enlarged later, the child's original
399 * position will not get restored to its pre-shrinking value.
401 * This routine is currently useful for child frames only. It might be
402 * eventually useful when moving non-child frames between monitors with
403 * different resolutions.
405 static void
406 keep_ratio (struct frame *f, struct frame *p, int old_width, int old_height,
407 int new_width, int new_height)
409 Lisp_Object keep_ratio = get_frame_param (f, Qkeep_ratio);
412 if (!NILP (keep_ratio))
414 double width_factor = (double)new_width / (double)old_width;
415 double height_factor = (double)new_height / (double)old_height;
416 int pixel_width, pixel_height, pos_x, pos_y;
418 if (!CONSP (keep_ratio) || !NILP (Fcdr (keep_ratio)))
420 if (CONSP (keep_ratio) && EQ (Fcdr (keep_ratio), Qtop_only))
421 pos_x = f->left_pos;
422 else
424 pos_x = (int)(f->left_pos * width_factor + 0.5);
426 if (CONSP (keep_ratio)
427 && (NILP (Fcar (keep_ratio))
428 || EQ (Fcar (keep_ratio), Qheight_only))
429 && p->pixel_width - f->pixel_width < pos_x)
431 int p_f_width = p->pixel_width - f->pixel_width;
433 if (p_f_width <= 0)
434 pos_x = 0;
435 else
436 pos_x = (int)(p_f_width * width_factor * 0.5 + 0.5);
439 f->left_pos = pos_x;
442 if (CONSP (keep_ratio) && EQ (Fcdr (keep_ratio), Qleft_only))
443 pos_y = f->top_pos;
444 else
446 pos_y = (int)(f->top_pos * height_factor + 0.5);
448 if (CONSP (keep_ratio)
449 && (NILP (Fcar (keep_ratio))
450 || EQ (Fcar (keep_ratio), Qwidth_only))
451 && p->pixel_height - f->pixel_height < pos_y)
452 /* When positional adjustment was requested and the
453 width of F should remain unaltered, try to constrain
454 F to its parent. This means that when the parent
455 frame is enlarged later the child's original position
456 won't get restored. */
458 int p_f_height = p->pixel_height - f->pixel_height;
460 if (p_f_height <= 0)
461 pos_y = 0;
462 else
463 pos_y = (int)(p_f_height * height_factor * 0.5 + 0.5);
466 f->top_pos = pos_y;
469 x_set_offset (f, pos_x, pos_y, -1);
472 if (!CONSP (keep_ratio) || !NILP (Fcar (keep_ratio)))
474 if (CONSP (keep_ratio) && EQ (Fcar (keep_ratio), Qheight_only))
475 pixel_width = -1;
476 else
478 pixel_width = (int)(f->pixel_width * width_factor + 0.5);
479 pixel_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, pixel_width);
482 if (CONSP (keep_ratio) && EQ (Fcar (keep_ratio), Qwidth_only))
483 pixel_height = -1;
484 else
486 pixel_height = (int)(f->pixel_height * height_factor + 0.5);
487 pixel_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, pixel_height);
490 adjust_frame_size (f, pixel_width, pixel_height, 1, 0,
491 Qkeep_ratio);
495 #endif
499 * adjust_frame_size:
501 * Adjust size of frame F. NEW_WIDTH and NEW_HEIGHT specify the new
502 * text size of F in pixels. A value of -1 means no change is requested
503 * for that direction (but the frame may still have to be resized to
504 * accommodate windows with their minimum sizes). This can either issue
505 * a request to resize the frame externally (via x_set_window_size), to
506 * resize the frame internally (via resize_frame_windows) or do nothing
507 * at all.
509 * The argument INHIBIT can assume the following values:
511 * 0 means to unconditionally call x_set_window_size even if sizes
512 * apparently do not change. Fx_create_frame uses this to pass the
513 * initial size to the window manager.
515 * 1 means to call x_set_window_size if the native frame size really
516 * changes. Fset_frame_size, Fset_frame_height, ... use this.
518 * 2 means to call x_set_window_size provided frame_inhibit_resize
519 * allows it. The menu and tool bar code use this ("3" won't work
520 * here in general because menu and tool bar are often not counted in
521 * the frame's text height).
523 * 3 means call x_set_window_size if window minimum sizes must be
524 * preserved or frame_inhibit_resize allows it. x_set_left_fringe,
525 * x_set_scroll_bar_width, x_new_font ... use (or should use) this.
527 * 4 means call x_set_window_size only if window minimum sizes must be
528 * preserved. x_set_right_divider_width, x_set_border_width and the
529 * code responsible for wrapping the tool bar use this.
531 * 5 means to never call x_set_window_size. change_frame_size uses
532 * this.
534 * Note that even when x_set_window_size is not called, individual
535 * windows may have to be resized (via `window--sanitize-window-sizes')
536 * in order to support minimum size constraints.
538 * PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the
539 * symbol of the parameter changed (like `menu-bar-lines', `font', ...).
540 * This is passed on to frame_inhibit_resize to let the latter decide on
541 * a case-by-case basis whether the frame may be resized externally.
543 void
544 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
545 bool pretend, Lisp_Object parameter)
547 int unit_width = FRAME_COLUMN_WIDTH (f);
548 int unit_height = FRAME_LINE_HEIGHT (f);
549 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
550 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
551 int old_cols = FRAME_COLS (f);
552 int old_lines = FRAME_LINES (f);
553 int new_pixel_width, new_pixel_height;
554 /* The following two values are calculated from the old frame pixel
555 sizes and any "new" settings for tool bar, menu bar and internal
556 borders. We do it this way to detect whether we have to call
557 x_set_window_size as consequence of the new settings. */
558 int windows_width = FRAME_WINDOWS_WIDTH (f);
559 int windows_height = FRAME_WINDOWS_HEIGHT (f);
560 int min_windows_width, min_windows_height;
561 /* These are a bit tedious, maybe we should use a macro. */
562 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
563 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
564 int old_windows_height
565 = (WINDOW_PIXEL_HEIGHT (r)
566 + ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
567 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
568 : 0));
569 int new_windows_width, new_windows_height;
570 int old_text_width = FRAME_TEXT_WIDTH (f);
571 int old_text_height = FRAME_TEXT_HEIGHT (f);
572 /* If a size is < 0 use the old value. */
573 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
574 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
575 int new_cols, new_lines;
576 bool inhibit_horizontal, inhibit_vertical;
577 Lisp_Object frame;
579 XSETFRAME (frame, f);
581 frame_size_history_add
582 (f, Qadjust_frame_size_1, new_text_width, new_text_height,
583 list2 (parameter, make_number (inhibit)));
585 /* The following two values are calculated from the old window body
586 sizes and any "new" settings for scroll bars, dividers, fringes and
587 margins (though the latter should have been processed already). */
588 min_windows_width
589 = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qt : Qnil, Qt);
590 min_windows_height
591 = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qt : Qnil, Qt);
593 if (inhibit >= 2 && inhibit <= 4)
594 /* When INHIBIT is in [2..4] inhibit if the "old" window sizes stay
595 within the limits and either resizing is inhibited or INHIBIT
596 equals 4. */
598 inhibit_horizontal = (windows_width >= min_windows_width
599 && (inhibit == 4
600 || frame_inhibit_resize (f, true, parameter)));
601 inhibit_vertical = (windows_height >= min_windows_height
602 && (inhibit == 4
603 || frame_inhibit_resize (f, false, parameter)));
605 else
606 /* Otherwise inhibit if INHIBIT equals 5. */
607 inhibit_horizontal = inhibit_vertical = inhibit == 5;
609 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
610 ? old_pixel_width
611 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
612 min_windows_width
613 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
614 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
615 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
616 new_cols = new_text_width / unit_width;
618 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
619 ? old_pixel_height
620 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
621 min_windows_height
622 + FRAME_TOP_MARGIN_HEIGHT (f)
623 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
624 new_windows_height = (new_pixel_height
625 - FRAME_TOP_MARGIN_HEIGHT (f)
626 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
627 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
628 new_lines = new_text_height / unit_height;
630 #ifdef HAVE_WINDOW_SYSTEM
631 if (FRAME_WINDOW_P (f)
632 && f->can_x_set_window_size
633 && ((!inhibit_horizontal
634 && (new_pixel_width != old_pixel_width
635 || inhibit == 0 || inhibit == 2))
636 || (!inhibit_vertical
637 && (new_pixel_height != old_pixel_height
638 || inhibit == 0 || inhibit == 2))))
639 /* We are either allowed to change the frame size or the minimum
640 sizes request such a change. Do not care for fixing minimum
641 sizes here, we do that eventually when we're called from
642 change_frame_size. */
644 /* Make sure we respect fullheight and fullwidth. */
645 if (inhibit_horizontal)
646 new_text_width = old_text_width;
647 else if (inhibit_vertical)
648 new_text_height = old_text_height;
650 frame_size_history_add
651 (f, Qadjust_frame_size_2, new_text_width, new_text_height,
652 list2 (inhibit_horizontal ? Qt : Qnil,
653 inhibit_vertical ? Qt : Qnil));
655 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
656 f->resized_p = true;
658 return;
660 #endif
662 if (new_text_width == old_text_width
663 && new_text_height == old_text_height
664 && new_windows_width == old_windows_width
665 && new_windows_height == old_windows_height
666 && new_pixel_width == old_pixel_width
667 && new_pixel_height == old_pixel_height
668 && new_cols == old_cols
669 && new_lines == old_lines)
670 /* No change. Sanitize window sizes and return. */
672 sanitize_window_sizes (Qt);
673 sanitize_window_sizes (Qnil);
675 return;
678 block_input ();
680 #ifdef MSDOS
681 /* We only can set screen dimensions to certain values supported by
682 our video hardware. Try to find the smallest size greater or
683 equal to the requested dimensions, while accounting for the fact
684 that the menu-bar lines are not counted in the frame height. */
685 int dos_new_lines = new_lines + FRAME_TOP_MARGIN (f);
686 dos_set_window_size (&dos_new_lines, &new_cols);
687 new_lines = dos_new_lines - FRAME_TOP_MARGIN (f);
688 #endif
690 if (new_windows_width != old_windows_width)
692 resize_frame_windows (f, new_windows_width, 1, 1);
694 /* MSDOS frames cannot PRETEND, as they change frame size by
695 manipulating video hardware. */
696 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
697 FrameCols (FRAME_TTY (f)) = new_cols;
699 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
700 if (WINDOWP (f->tool_bar_window))
702 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
703 XWINDOW (f->tool_bar_window)->total_cols
704 = new_windows_width / unit_width;
706 #endif
708 else if (new_cols != old_cols)
709 call2 (Qwindow__pixel_to_total, frame, Qt);
711 if (new_windows_height != old_windows_height
712 /* When the top margin has changed we have to recalculate the top
713 edges of all windows. No such calculation is necessary for the
714 left edges. */
715 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
717 resize_frame_windows (f, new_windows_height, 0, 1);
719 /* MSDOS frames cannot PRETEND, as they change frame size by
720 manipulating video hardware. */
721 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
722 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
724 else if (new_lines != old_lines)
725 call2 (Qwindow__pixel_to_total, frame, Qnil);
727 frame_size_history_add
728 (f, Qadjust_frame_size_3, new_text_width, new_text_height,
729 list4 (make_number (old_pixel_width), make_number (old_pixel_height),
730 make_number (new_pixel_width), make_number (new_pixel_height)));
732 /* Assign new sizes. */
733 FRAME_TEXT_WIDTH (f) = new_text_width;
734 FRAME_TEXT_HEIGHT (f) = new_text_height;
735 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
736 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
737 SET_FRAME_COLS (f, new_cols);
738 SET_FRAME_LINES (f, new_lines);
741 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
742 int text_area_x, text_area_y, text_area_width, text_area_height;
744 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
745 &text_area_height);
746 if (w->cursor.x >= text_area_x + text_area_width)
747 w->cursor.hpos = w->cursor.x = 0;
748 if (w->cursor.y >= text_area_y + text_area_height)
749 w->cursor.vpos = w->cursor.y = 0;
752 /* Sanitize window sizes. */
753 sanitize_window_sizes (Qt);
754 sanitize_window_sizes (Qnil);
756 adjust_frame_glyphs (f);
757 calculate_costs (f);
758 SET_FRAME_GARBAGED (f);
760 /* A frame was "resized" if one of its pixelsizes changed, even if its
761 X window wasn't resized at all. */
762 f->resized_p = (new_pixel_width != old_pixel_width
763 || new_pixel_height != old_pixel_height);
765 unblock_input ();
767 #ifdef HAVE_WINDOW_SYSTEM
769 /* Adjust size of F's child frames. */
770 Lisp_Object frames, frame1;
772 FOR_EACH_FRAME (frames, frame1)
773 if (FRAME_PARENT_FRAME (XFRAME (frame1)) == f)
774 keep_ratio (XFRAME (frame1), f, old_pixel_width, old_pixel_height,
775 new_pixel_width, new_pixel_height);
777 #endif
780 /* Allocate basically initialized frame. */
782 static struct frame *
783 allocate_frame (void)
785 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
788 struct frame *
789 make_frame (bool mini_p)
791 Lisp_Object frame;
792 struct frame *f;
793 struct window *rw, *mw UNINIT;
794 Lisp_Object root_window;
795 Lisp_Object mini_window;
797 f = allocate_frame ();
798 XSETFRAME (frame, f);
800 #ifdef USE_GTK
801 /* Initialize Lisp data. Note that allocate_frame initializes all
802 Lisp data to nil, so do it only for slots which should not be nil. */
803 fset_tool_bar_position (f, Qtop);
804 #endif
806 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
807 non-Lisp data, so do it only for slots which should not be zero.
808 To avoid subtle bugs and for the sake of readability, it's better to
809 initialize enum members explicitly even if their values are zero. */
810 f->wants_modeline = true;
811 f->redisplay = true;
812 f->garbaged = true;
813 f->can_x_set_window_size = false;
814 f->after_make_frame = false;
815 f->inhibit_horizontal_resize = false;
816 f->inhibit_vertical_resize = false;
817 f->tool_bar_redisplayed = false;
818 f->tool_bar_resized = false;
819 f->column_width = 1; /* !FRAME_WINDOW_P value. */
820 f->line_height = 1; /* !FRAME_WINDOW_P value. */
821 #ifdef HAVE_WINDOW_SYSTEM
822 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
823 f->horizontal_scroll_bars = false;
824 f->want_fullscreen = FULLSCREEN_NONE;
825 f->undecorated = false;
826 f->no_special_glyphs = false;
827 #ifndef HAVE_NTGUI
828 f->override_redirect = false;
829 #endif
830 f->skip_taskbar = false;
831 f->no_focus_on_map = false;
832 f->no_accept_focus = false;
833 f->z_group = z_group_none;
834 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
835 f->last_tool_bar_item = -1;
836 #endif
837 #ifdef NS_IMPL_COCOA
838 f->ns_appearance = ns_appearance_aqua;
839 f->ns_transparent_titlebar = false;
840 #endif
841 #endif
843 root_window = make_window ();
844 rw = XWINDOW (root_window);
845 if (mini_p)
847 mini_window = make_window ();
848 mw = XWINDOW (mini_window);
849 wset_next (rw, mini_window);
850 wset_prev (mw, root_window);
851 mw->mini = 1;
852 wset_frame (mw, frame);
853 fset_minibuffer_window (f, mini_window);
854 store_frame_param (f, Qminibuffer, Qt);
856 else
858 mini_window = Qnil;
859 wset_next (rw, Qnil);
860 fset_minibuffer_window (f, Qnil);
863 wset_frame (rw, frame);
865 /* 10 is arbitrary,
866 just so that there is "something there."
867 Correct size will be set up later with adjust_frame_size. */
869 SET_FRAME_COLS (f, 10);
870 SET_FRAME_LINES (f, 10);
871 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
872 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
874 rw->total_cols = 10;
875 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
876 rw->total_lines = mini_p ? 9 : 10;
877 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
879 if (mini_p)
881 mw->top_line = rw->total_lines;
882 mw->pixel_top = rw->pixel_height;
883 mw->total_cols = rw->total_cols;
884 mw->pixel_width = rw->pixel_width;
885 mw->total_lines = 1;
886 mw->pixel_height = FRAME_LINE_HEIGHT (f);
889 /* Choose a buffer for the frame's root window. */
891 Lisp_Object buf = Fcurrent_buffer ();
893 /* If current buffer is hidden, try to find another one. */
894 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
895 buf = other_buffer_safely (buf);
897 /* Use set_window_buffer, not Fset_window_buffer, and don't let
898 hooks be run by it. The reason is that the whole frame/window
899 arrangement is not yet fully initialized at this point. Windows
900 don't have the right size, glyph matrices aren't initialized
901 etc. Running Lisp functions at this point surely ends in a
902 SEGV. */
903 set_window_buffer (root_window, buf, 0, 0);
904 fset_buffer_list (f, list1 (buf));
907 if (mini_p)
909 set_window_buffer (mini_window,
910 (NILP (Vminibuffer_list)
911 ? get_minibuffer (0)
912 : Fcar (Vminibuffer_list)),
913 0, 0);
914 /* No horizontal scroll bars in minibuffers. */
915 wset_horizontal_scroll_bar (mw, Qnil);
918 fset_root_window (f, root_window);
919 fset_selected_window (f, root_window);
920 /* Make sure this window seems more recently used than
921 a newly-created, never-selected window. */
922 XWINDOW (f->selected_window)->use_time = ++window_select_count;
924 return f;
927 #ifdef HAVE_WINDOW_SYSTEM
928 /* Make a frame using a separate minibuffer window on another frame.
929 MINI_WINDOW is the minibuffer window to use. nil means use the
930 default (the global minibuffer). */
932 struct frame *
933 make_frame_without_minibuffer (Lisp_Object mini_window, KBOARD *kb,
934 Lisp_Object display)
936 struct frame *f;
938 if (!NILP (mini_window))
939 CHECK_LIVE_WINDOW (mini_window);
941 if (!NILP (mini_window)
942 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
943 error ("Frame and minibuffer must be on the same terminal");
945 /* Make a frame containing just a root window. */
946 f = make_frame (0);
948 if (NILP (mini_window))
950 /* Use default-minibuffer-frame if possible. */
951 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
952 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
954 Lisp_Object frame_dummy;
956 XSETFRAME (frame_dummy, f);
957 /* If there's no minibuffer frame to use, create one. */
958 kset_default_minibuffer_frame
959 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
962 mini_window
963 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
966 fset_minibuffer_window (f, mini_window);
967 store_frame_param (f, Qminibuffer, mini_window);
969 /* Make the chosen minibuffer window display the proper minibuffer,
970 unless it is already showing a minibuffer. */
971 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
972 /* Use set_window_buffer instead of Fset_window_buffer (see
973 discussion of bug#11984, bug#12025, bug#12026). */
974 set_window_buffer (mini_window,
975 (NILP (Vminibuffer_list)
976 ? get_minibuffer (0)
977 : Fcar (Vminibuffer_list)), 0, 0);
978 return f;
981 /* Make a frame containing only a minibuffer window. */
983 struct frame *
984 make_minibuffer_frame (void)
986 /* First make a frame containing just a root window, no minibuffer. */
988 register struct frame *f = make_frame (0);
989 register Lisp_Object mini_window;
990 register Lisp_Object frame;
992 XSETFRAME (frame, f);
994 f->auto_raise = 0;
995 f->auto_lower = 0;
996 f->no_split = 1;
997 f->wants_modeline = 0;
999 /* Now label the root window as also being the minibuffer.
1000 Avoid infinite looping on the window chain by marking next pointer
1001 as nil. */
1003 mini_window = f->root_window;
1004 fset_minibuffer_window (f, mini_window);
1005 store_frame_param (f, Qminibuffer, Qonly);
1006 XWINDOW (mini_window)->mini = 1;
1007 wset_next (XWINDOW (mini_window), Qnil);
1008 wset_prev (XWINDOW (mini_window), Qnil);
1009 wset_frame (XWINDOW (mini_window), frame);
1011 /* Put the proper buffer in that window. */
1013 /* Use set_window_buffer instead of Fset_window_buffer (see
1014 discussion of bug#11984, bug#12025, bug#12026). */
1015 set_window_buffer (mini_window,
1016 (NILP (Vminibuffer_list)
1017 ? get_minibuffer (0)
1018 : Fcar (Vminibuffer_list)), 0, 0);
1019 return f;
1021 #endif /* HAVE_WINDOW_SYSTEM */
1023 /* Construct a frame that refers to a terminal. */
1025 static printmax_t tty_frame_count;
1027 struct frame *
1028 make_initial_frame (void)
1030 struct frame *f;
1031 struct terminal *terminal;
1032 Lisp_Object frame;
1034 eassert (initial_kboard);
1036 /* The first call must initialize Vframe_list. */
1037 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
1038 Vframe_list = Qnil;
1040 terminal = init_initial_terminal ();
1042 f = make_frame (1);
1043 XSETFRAME (frame, f);
1045 Vframe_list = Fcons (frame, Vframe_list);
1047 tty_frame_count = 1;
1048 fset_name (f, build_pure_c_string ("F1"));
1050 SET_FRAME_VISIBLE (f, 1);
1052 f->output_method = terminal->type;
1053 f->terminal = terminal;
1054 f->terminal->reference_count++;
1055 f->output_data.nothing = 0;
1057 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
1058 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
1060 #ifdef HAVE_WINDOW_SYSTEM
1061 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
1062 f->horizontal_scroll_bars = false;
1063 #endif
1065 /* The default value of menu-bar-mode is t. */
1066 set_menu_bar_lines (f, make_number (1), Qnil);
1068 /* Allocate glyph matrices. */
1069 adjust_frame_glyphs (f);
1071 if (!noninteractive)
1072 init_frame_faces (f);
1074 last_nonminibuf_frame = f;
1076 f->can_x_set_window_size = true;
1077 f->after_make_frame = true;
1079 return f;
1083 static struct frame *
1084 make_terminal_frame (struct terminal *terminal)
1086 register struct frame *f;
1087 Lisp_Object frame;
1088 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
1090 if (!terminal->name)
1091 error ("Terminal is not live, can't create new frames on it");
1093 f = make_frame (1);
1095 XSETFRAME (frame, f);
1096 Vframe_list = Fcons (frame, Vframe_list);
1098 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
1100 SET_FRAME_VISIBLE (f, 1);
1102 f->terminal = terminal;
1103 f->terminal->reference_count++;
1104 #ifdef MSDOS
1105 f->output_data.tty->display_info = &the_only_display_info;
1106 if (!inhibit_window_system
1107 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
1108 || XFRAME (selected_frame)->output_method == output_msdos_raw))
1109 f->output_method = output_msdos_raw;
1110 else
1111 f->output_method = output_termcap;
1112 #else /* not MSDOS */
1113 f->output_method = output_termcap;
1114 create_tty_output (f);
1115 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
1116 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
1117 #endif /* not MSDOS */
1119 #ifdef HAVE_WINDOW_SYSTEM
1120 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
1121 f->horizontal_scroll_bars = false;
1122 #endif
1124 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
1125 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
1126 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
1127 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
1129 /* Set the top frame to the newly created frame. */
1130 if (FRAMEP (FRAME_TTY (f)->top_frame)
1131 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
1132 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
1134 FRAME_TTY (f)->top_frame = frame;
1136 if (!noninteractive)
1137 init_frame_faces (f);
1139 return f;
1142 /* Get a suitable value for frame parameter PARAMETER for a newly
1143 created frame, based on (1) the user-supplied frame parameter
1144 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
1146 static Lisp_Object
1147 get_future_frame_param (Lisp_Object parameter,
1148 Lisp_Object supplied_parms,
1149 char *current_value)
1151 Lisp_Object result;
1153 result = Fassq (parameter, supplied_parms);
1154 if (NILP (result))
1155 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
1156 if (NILP (result) && current_value != NULL)
1157 result = build_string (current_value);
1158 if (!NILP (result) && !STRINGP (result))
1159 result = XCDR (result);
1160 if (NILP (result) || !STRINGP (result))
1161 result = Qnil;
1163 return result;
1166 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
1167 1, 1, 0,
1168 doc: /* Create an additional terminal frame, possibly on another terminal.
1169 This function takes one argument, an alist specifying frame parameters.
1171 You can create multiple frames on a single text terminal, but only one
1172 of them (the selected terminal frame) is actually displayed.
1174 In practice, generally you don't need to specify any parameters,
1175 except when you want to create a new frame on another terminal.
1176 In that case, the `tty' parameter specifies the device file to open,
1177 and the `tty-type' parameter specifies the terminal type. Example:
1179 (make-terminal-frame \\='((tty . "/dev/pts/5") (tty-type . "xterm")))
1181 Note that changing the size of one terminal frame automatically
1182 affects all frames on the same terminal device. */)
1183 (Lisp_Object parms)
1185 struct frame *f;
1186 struct terminal *t = NULL;
1187 Lisp_Object frame, tem;
1188 struct frame *sf = SELECTED_FRAME ();
1190 #ifdef MSDOS
1191 if (sf->output_method != output_msdos_raw
1192 && sf->output_method != output_termcap)
1193 emacs_abort ();
1194 #else /* not MSDOS */
1196 #ifdef WINDOWSNT /* This should work now! */
1197 if (sf->output_method != output_termcap)
1198 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
1199 #endif
1200 #endif /* not MSDOS */
1203 Lisp_Object terminal;
1205 terminal = Fassq (Qterminal, parms);
1206 if (CONSP (terminal))
1208 terminal = XCDR (terminal);
1209 t = decode_live_terminal (terminal);
1211 #ifdef MSDOS
1212 if (t && t != the_only_display_info.terminal)
1213 /* msdos.c assumes a single tty_display_info object. */
1214 error ("Multiple terminals are not supported on this platform");
1215 if (!t)
1216 t = the_only_display_info.terminal;
1217 #endif
1220 if (!t)
1222 char *name = 0, *type = 0;
1223 Lisp_Object tty, tty_type;
1224 USE_SAFE_ALLOCA;
1226 tty = get_future_frame_param
1227 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1228 ? FRAME_TTY (XFRAME (selected_frame))->name
1229 : NULL));
1230 if (!NILP (tty))
1231 SAFE_ALLOCA_STRING (name, tty);
1233 tty_type = get_future_frame_param
1234 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1235 ? FRAME_TTY (XFRAME (selected_frame))->type
1236 : NULL));
1237 if (!NILP (tty_type))
1238 SAFE_ALLOCA_STRING (type, tty_type);
1240 t = init_tty (name, type, 0); /* Errors are not fatal. */
1241 SAFE_FREE ();
1244 f = make_terminal_frame (t);
1247 int width, height;
1248 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1249 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f),
1250 5, 0, Qterminal_frame);
1253 adjust_frame_glyphs (f);
1254 calculate_costs (f);
1255 XSETFRAME (frame, f);
1257 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1258 store_in_alist (&parms, Qtty,
1259 (t->display_info.tty->name
1260 ? build_string (t->display_info.tty->name)
1261 : Qnil));
1262 /* On terminal frames the `minibuffer' frame parameter is always
1263 virtually t. Avoid that a different value in parms causes
1264 complaints, see Bug#24758. */
1265 store_in_alist (&parms, Qminibuffer, Qt);
1266 Fmodify_frame_parameters (frame, parms);
1268 /* Make the frame face alist be frame-specific, so that each
1269 frame could change its face definitions independently. */
1270 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1271 /* Simple Fcopy_alist isn't enough, because we need the contents of
1272 the vectors which are the CDRs of associations in face_alist to
1273 be copied as well. */
1274 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1275 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1277 f->can_x_set_window_size = true;
1278 f->after_make_frame = true;
1280 return frame;
1284 /* Perform the switch to frame FRAME.
1286 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1287 FRAME1 as frame.
1289 If TRACK is non-zero and the frame that currently has the focus
1290 redirects its focus to the selected frame, redirect that focused
1291 frame's focus to FRAME instead.
1293 FOR_DELETION non-zero means that the selected frame is being
1294 deleted, which includes the possibility that the frame's terminal
1295 is dead.
1297 The value of NORECORD is passed as argument to Fselect_window. */
1299 Lisp_Object
1300 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1302 struct frame *sf = SELECTED_FRAME (), *f;
1304 /* If FRAME is a switch-frame event, extract the frame we should
1305 switch to. */
1306 if (CONSP (frame)
1307 && EQ (XCAR (frame), Qswitch_frame)
1308 && CONSP (XCDR (frame)))
1309 frame = XCAR (XCDR (frame));
1311 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1312 a switch-frame event to arrive after a frame is no longer live,
1313 especially when deleting the initial frame during startup. */
1314 CHECK_FRAME (frame);
1315 f = XFRAME (frame);
1316 if (!FRAME_LIVE_P (f))
1317 return Qnil;
1318 else if (f == sf)
1319 return frame;
1321 /* If a frame's focus has been redirected toward the currently
1322 selected frame, we should change the redirection to point to the
1323 newly selected frame. This means that if the focus is redirected
1324 from a minibufferless frame to a surrogate minibuffer frame, we
1325 can use `other-window' to switch between all the frames using
1326 that minibuffer frame, and the focus redirection will follow us
1327 around. */
1328 #if 0
1329 /* This is too greedy; it causes inappropriate focus redirection
1330 that's hard to get rid of. */
1331 if (track)
1333 Lisp_Object tail;
1335 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1337 Lisp_Object focus;
1339 if (!FRAMEP (XCAR (tail)))
1340 emacs_abort ();
1342 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1344 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1345 Fredirect_frame_focus (XCAR (tail), frame);
1348 #else /* ! 0 */
1349 /* Instead, apply it only to the frame we're pointing to. */
1350 #ifdef HAVE_WINDOW_SYSTEM
1351 if (track && FRAME_WINDOW_P (f))
1353 Lisp_Object focus, xfocus;
1355 xfocus = x_get_focus_frame (f);
1356 if (FRAMEP (xfocus))
1358 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1359 if ((FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1360 /* Redirect frame focus also when FRAME has its minibuffer
1361 window on the selected frame (see Bug#24500). */
1362 || (NILP (focus)
1363 && EQ (FRAME_MINIBUF_WINDOW (f), sf->selected_window)))
1364 Fredirect_frame_focus (xfocus, frame);
1367 #endif /* HAVE_X_WINDOWS */
1368 #endif /* ! 0 */
1370 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1371 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1373 if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
1375 struct tty_display_info *tty = FRAME_TTY (f);
1376 Lisp_Object top_frame = tty->top_frame;
1378 /* Don't mark the frame garbaged and/or obscured if we are
1379 switching to the frame that is already the top frame of that
1380 TTY. */
1381 if (!EQ (frame, top_frame))
1383 if (FRAMEP (top_frame))
1384 /* Mark previously displayed frame as now obscured. */
1385 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1386 SET_FRAME_VISIBLE (f, 1);
1387 /* If the new TTY frame changed dimensions, we need to
1388 resync term.c's idea of the frame size with the new
1389 frame's data. */
1390 if (FRAME_COLS (f) != FrameCols (tty))
1391 FrameCols (tty) = FRAME_COLS (f);
1392 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1393 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1395 tty->top_frame = frame;
1398 selected_frame = frame;
1399 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1400 last_nonminibuf_frame = XFRAME (selected_frame);
1402 Fselect_window (f->selected_window, norecord);
1404 /* We want to make sure that the next event generates a frame-switch
1405 event to the appropriate frame. This seems kludgy to me, but
1406 before you take it out, make sure that evaluating something like
1407 (select-window (frame-root-window (new-frame))) doesn't end up
1408 with your typing being interpreted in the new frame instead of
1409 the one you're actually typing in. */
1410 #ifdef HAVE_WINDOW_SYSTEM
1411 if (!frame_ancestor_p (f, sf))
1412 #endif
1413 internal_last_event_frame = Qnil;
1415 return frame;
1418 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1419 doc: /* Select FRAME.
1420 Subsequent editing commands apply to its selected window.
1421 Optional argument NORECORD means to neither change the order of
1422 recently selected windows nor the buffer list.
1424 The selection of FRAME lasts until the next time the user does
1425 something to select a different frame, or until the next time
1426 this function is called. If you are using a window system, the
1427 previously selected frame may be restored as the selected frame
1428 when returning to the command loop, because it still may have
1429 the window system's input focus. On a text terminal, the next
1430 redisplay will display FRAME.
1432 This function returns FRAME, or nil if FRAME has been deleted. */)
1433 (Lisp_Object frame, Lisp_Object norecord)
1435 return do_switch_frame (frame, 1, 0, norecord);
1438 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1439 doc: /* Handle a switch-frame event EVENT.
1440 Switch-frame events are usually bound to this function.
1441 A switch-frame event tells Emacs that the window manager has requested
1442 that the user's events be directed to the frame mentioned in the event.
1443 This function selects the selected window of the frame of EVENT.
1445 If EVENT is frame object, handle it as if it were a switch-frame event
1446 to that frame. */)
1447 (Lisp_Object event)
1449 Lisp_Object value;
1451 /* Preserve prefix arg that the command loop just cleared. */
1452 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1453 run_hook (Qmouse_leave_buffer_hook);
1454 /* `switch-frame' implies a focus in. */
1455 value = do_switch_frame (event, 0, 0, Qnil);
1456 call1 (intern ("handle-focus-in"), event);
1457 return value;
1460 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1461 doc: /* Return the frame that is now selected. */)
1462 (void)
1464 return selected_frame;
1467 DEFUN ("frame-list", Fframe_list, Sframe_list,
1468 0, 0, 0,
1469 doc: /* Return a list of all live frames. */)
1470 (void)
1472 Lisp_Object frames;
1473 frames = Fcopy_sequence (Vframe_list);
1474 #ifdef HAVE_WINDOW_SYSTEM
1475 if (FRAMEP (tip_frame))
1476 frames = Fdelq (tip_frame, frames);
1477 #endif
1478 return frames;
1481 DEFUN ("frame-parent", Fframe_parent, Sframe_parent,
1482 0, 1, 0,
1483 doc: /* Return the parent frame of FRAME.
1484 The parent frame of FRAME is the Emacs frame whose window-system window
1485 is the parent window of FRAME's window-system window. When such a frame
1486 exists, FRAME is considered a child frame of that frame.
1488 Return nil if FRAME has no parent frame. This means that FRAME's
1489 window-system window is either a "top-level" window (a window whose
1490 parent window is the window-system's root window) or an embedded window
1491 \(a window whose parent window is owned by some other application). */)
1492 (Lisp_Object frame)
1494 struct frame *f = decode_live_frame (frame);
1495 struct frame *p = FRAME_PARENT_FRAME (f);
1496 Lisp_Object parent;
1498 /* Can't return f->parent_frame directly since it might not be defined
1499 for this platform. */
1500 if (p)
1502 XSETFRAME (parent, p);
1504 return parent;
1506 else
1507 return Qnil;
1510 #ifdef HAVE_WINDOW_SYSTEM
1511 bool
1512 frame_ancestor_p (struct frame *af, struct frame *df)
1514 struct frame *pf = FRAME_PARENT_FRAME (df);
1516 while (pf)
1518 if (pf == af)
1519 return true;
1520 else
1521 pf = FRAME_PARENT_FRAME (pf);
1524 return false;
1526 #endif
1528 DEFUN ("frame-ancestor-p", Fframe_ancestor_p, Sframe_ancestor_p,
1529 2, 2, 0,
1530 doc: /* Return non-nil if ANCESTOR is an ancestor of DESCENDANT.
1531 ANCESTOR is an ancestor of DESCENDANT when it is either DESCENDANT's
1532 parent frame or it is an ancestor of DESCENDANT's parent frame. Both,
1533 ANCESTOR and DESCENDANT must be live frames and default to the selected
1534 frame. */)
1535 (Lisp_Object ancestor, Lisp_Object descendant)
1537 #ifdef HAVE_WINDOW_SYSTEM
1538 struct frame *af = decode_live_frame (ancestor);
1539 struct frame *df = decode_live_frame (descendant);
1541 return frame_ancestor_p (af, df) ? Qt : Qnil;
1542 #else
1543 return Qnil;
1544 #endif
1547 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1548 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1549 If MINIBUF is nil, do not consider minibuffer-only candidate.
1550 If MINIBUF is `visible', do not consider an invisible candidate.
1551 If MINIBUF is a window, consider only its own frame and candidate now
1552 using that window as the minibuffer.
1553 If MINIBUF is 0, consider candidate if it is visible or iconified.
1554 Otherwise consider any candidate and return nil if CANDIDATE is not
1555 acceptable. */
1557 static Lisp_Object
1558 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1560 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1562 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1563 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1564 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1565 && FRAME_TTY (c) == FRAME_TTY (f)))
1567 if (!NILP (get_frame_param (c, Qno_other_frame)))
1568 return Qnil;
1569 else if (NILP (minibuf))
1571 if (!FRAME_MINIBUF_ONLY_P (c))
1572 return candidate;
1574 else if (EQ (minibuf, Qvisible))
1576 if (FRAME_VISIBLE_P (c))
1577 return candidate;
1579 else if (WINDOWP (minibuf))
1581 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1582 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1583 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1584 FRAME_FOCUS_FRAME (c)))
1585 return candidate;
1587 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1589 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1590 return candidate;
1592 else
1593 return candidate;
1595 return Qnil;
1598 /* Return the next frame in the frame list after FRAME. */
1600 static Lisp_Object
1601 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1603 Lisp_Object f, tail;
1604 int passed = 0;
1606 while (passed < 2)
1607 FOR_EACH_FRAME (tail, f)
1609 if (passed)
1611 f = candidate_frame (f, frame, minibuf);
1612 if (!NILP (f))
1613 return f;
1615 if (EQ (frame, f))
1616 passed++;
1618 return frame;
1621 /* Return the previous frame in the frame list before FRAME. */
1623 static Lisp_Object
1624 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1626 Lisp_Object f, tail, prev = Qnil;
1628 FOR_EACH_FRAME (tail, f)
1630 if (EQ (frame, f) && !NILP (prev))
1631 return prev;
1632 f = candidate_frame (f, frame, minibuf);
1633 if (!NILP (f))
1634 prev = f;
1637 /* We've scanned the entire list. */
1638 if (NILP (prev))
1639 /* We went through the whole frame list without finding a single
1640 acceptable frame. Return the original frame. */
1641 return frame;
1642 else
1643 /* There were no acceptable frames in the list before FRAME; otherwise,
1644 we would have returned directly from the loop. Since PREV is the last
1645 acceptable frame in the list, return it. */
1646 return prev;
1650 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1651 doc: /* Return the next frame in the frame list after FRAME.
1652 It considers only frames on the same terminal as FRAME.
1653 By default, skip minibuffer-only frames.
1654 If omitted, FRAME defaults to the selected frame.
1655 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1656 If MINIFRAME is a window, include only its own frame
1657 and any frame now using that window as the minibuffer.
1658 If MINIFRAME is `visible', include all visible frames.
1659 If MINIFRAME is 0, include all visible and iconified frames.
1660 Otherwise, include all frames. */)
1661 (Lisp_Object frame, Lisp_Object miniframe)
1663 if (NILP (frame))
1664 frame = selected_frame;
1665 CHECK_LIVE_FRAME (frame);
1666 return next_frame (frame, miniframe);
1669 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1670 doc: /* Return the previous frame in the frame list before FRAME.
1671 It considers only frames on the same terminal as FRAME.
1672 By default, skip minibuffer-only frames.
1673 If omitted, FRAME defaults to the selected frame.
1674 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1675 If MINIFRAME is a window, include only its own frame
1676 and any frame now using that window as the minibuffer.
1677 If MINIFRAME is `visible', include all visible frames.
1678 If MINIFRAME is 0, include all visible and iconified frames.
1679 Otherwise, include all frames. */)
1680 (Lisp_Object frame, Lisp_Object miniframe)
1682 if (NILP (frame))
1683 frame = selected_frame;
1684 CHECK_LIVE_FRAME (frame);
1685 return prev_frame (frame, miniframe);
1688 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1689 Slast_nonminibuf_frame, 0, 0, 0,
1690 doc: /* Return last non-minibuffer frame selected. */)
1691 (void)
1693 Lisp_Object frame = Qnil;
1695 if (last_nonminibuf_frame)
1696 XSETFRAME (frame, last_nonminibuf_frame);
1698 return frame;
1702 * other_frames:
1704 * Return true if there exists at least one visible or iconified frame
1705 * but F. Return false otherwise.
1707 * INVISIBLE true means we are called from make_frame_invisible where
1708 * such a frame must be visible or iconified. INVISIBLE nil means we
1709 * are called from delete_frame. In that case FORCE true means that the
1710 * visibility status of such a frame can be ignored.
1712 * If F is the terminal frame and we are using X, return true if at
1713 * least one X frame exists.
1715 static bool
1716 other_frames (struct frame *f, bool invisible, bool force)
1718 Lisp_Object frames, frame, frame1;
1719 struct frame *f1;
1720 Lisp_Object minibuffer_window = FRAME_MINIBUF_WINDOW (f);
1722 XSETFRAME (frame, f);
1723 if (WINDOWP (minibuffer_window)
1724 && !EQ (frame, WINDOW_FRAME (XWINDOW (minibuffer_window))))
1725 minibuffer_window = Qnil;
1727 FOR_EACH_FRAME (frames, frame1)
1729 f1 = XFRAME (frame1);
1730 if (f != f1)
1732 /* Verify that we can still talk to the frame's X window, and
1733 note any recent change in visibility. */
1734 #ifdef HAVE_X_WINDOWS
1735 if (FRAME_WINDOW_P (f1))
1736 x_sync (f1);
1737 #endif
1738 if (NILP (Fframe_parameter (frame1, Qtooltip))
1739 /* Tooltips and child frames count neither for
1740 invisibility nor for deletions. */
1741 && !FRAME_PARENT_FRAME (f1)
1742 /* Frames with a non-nil `delete-before' parameter don't
1743 count for deletions. */
1744 && (invisible || NILP (get_frame_param (f1, Qdelete_before)))
1745 /* For invisibility and normal deletions, at least one
1746 visible or iconified frame must remain (Bug#26682). */
1747 && (FRAME_VISIBLE_P (f1) || FRAME_ICONIFIED_P (f1)
1748 || (!invisible
1749 && (force
1750 /* Allow deleting the terminal frame when at
1751 least one X frame exists. */
1752 || (FRAME_WINDOW_P (f1) && !FRAME_WINDOW_P (f))))))
1753 return true;
1757 return false;
1760 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1761 window. Preferably use the selected frame's minibuffer window
1762 instead. If the selected frame doesn't have one, get some other
1763 frame's minibuffer window. SELECT non-zero means select the new
1764 minibuffer window. */
1765 static void
1766 check_minibuf_window (Lisp_Object frame, int select)
1768 struct frame *f = decode_live_frame (frame);
1770 XSETFRAME (frame, f);
1772 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1774 Lisp_Object frames, this, window = make_number (0);
1776 if (!EQ (frame, selected_frame)
1777 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1778 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1779 else
1780 FOR_EACH_FRAME (frames, this)
1782 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1784 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1785 break;
1789 /* Don't abort if no window was found (Bug#15247). */
1790 if (WINDOWP (window))
1792 /* Use set_window_buffer instead of Fset_window_buffer (see
1793 discussion of bug#11984, bug#12025, bug#12026). */
1794 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1795 minibuf_window = window;
1797 /* SELECT non-zero usually means that FRAME's minibuffer
1798 window was selected; select the new one. */
1799 if (select)
1800 Fselect_window (minibuf_window, Qnil);
1807 * delete_frame:
1809 * Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1810 * unconditionally. x_connection_closed and delete_terminal use this.
1811 * Any other value of FORCE implements the semantics described for
1812 * Fdelete_frame. */
1813 Lisp_Object
1814 delete_frame (Lisp_Object frame, Lisp_Object force)
1816 struct frame *f = decode_any_frame (frame);
1817 struct frame *sf;
1818 struct kboard *kb;
1819 Lisp_Object frames, frame1;
1820 int minibuffer_selected, is_tooltip_frame;
1821 bool nochild = !FRAME_PARENT_FRAME (f);
1823 if (!FRAME_LIVE_P (f))
1824 return Qnil;
1825 else if (!EQ (force, Qnoelisp) && !other_frames (f, false, !NILP (force)))
1827 if (NILP (force))
1828 error ("Attempt to delete the sole visible or iconified frame");
1829 else
1830 error ("Attempt to delete the only frame");
1833 XSETFRAME (frame, f);
1835 /* Softly delete all frames with this frame as their parent frame or
1836 as their `delete-before' frame parameter value. */
1837 FOR_EACH_FRAME (frames, frame1)
1838 if (FRAME_PARENT_FRAME (XFRAME (frame1)) == f
1839 /* Process `delete-before' parameter iff FRAME is not a child
1840 frame. This avoids that we enter an infinite chain of mixed
1841 dependencies. */
1842 || (nochild
1843 && EQ (get_frame_param (XFRAME (frame1), Qdelete_before), frame)))
1844 delete_frame (frame1, Qnil);
1846 /* Does this frame have a minibuffer, and is it the surrogate
1847 minibuffer for any other frame? */
1848 if (FRAME_HAS_MINIBUF_P (f))
1850 FOR_EACH_FRAME (frames, frame1)
1852 Lisp_Object fminiw;
1854 if (EQ (frame1, frame))
1855 continue;
1857 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (frame1));
1859 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1861 /* If we MUST delete this frame, delete the other first.
1862 But do this only if FORCE equals `noelisp'. */
1863 if (EQ (force, Qnoelisp))
1864 delete_frame (frame1, Qnoelisp);
1865 else
1866 error ("Attempt to delete a surrogate minibuffer frame");
1871 is_tooltip_frame = !NILP (Fframe_parameter (frame, Qtooltip));
1873 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1874 frame is a tooltip. FORCE is set to `noelisp' when handling
1875 a disconnect from the terminal, so we don't dare call Lisp
1876 code. */
1877 if (NILP (Vrun_hooks) || is_tooltip_frame)
1879 else if (EQ (force, Qnoelisp))
1880 pending_funcalls
1881 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1882 pending_funcalls);
1883 else
1885 #ifdef HAVE_X_WINDOWS
1886 /* Also, save clipboard to the clipboard manager. */
1887 x_clipboard_manager_save_frame (frame);
1888 #endif
1890 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1893 /* delete_frame_functions may have deleted any frame, including this
1894 one. */
1895 if (!FRAME_LIVE_P (f))
1896 return Qnil;
1897 else if (!EQ (force, Qnoelisp) && !other_frames (f, false, !NILP (force)))
1899 if (NILP (force))
1900 error ("Attempt to delete the sole visible or iconified frame");
1901 else
1902 error ("Attempt to delete the only frame");
1905 /* At this point, we are committed to deleting the frame.
1906 There is no more chance for errors to prevent it. */
1907 minibuffer_selected = EQ (minibuf_window, selected_window);
1908 sf = SELECTED_FRAME ();
1909 /* Don't let the frame remain selected. */
1910 if (f == sf)
1912 Lisp_Object tail;
1914 /* Look for another visible frame on the same terminal.
1915 Do not call next_frame here because it may loop forever.
1916 See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1917 FOR_EACH_FRAME (tail, frame1)
1918 if (!EQ (frame, frame1)
1919 && (FRAME_TERMINAL (XFRAME (frame))
1920 == FRAME_TERMINAL (XFRAME (frame1)))
1921 && FRAME_VISIBLE_P (XFRAME (frame1)))
1922 break;
1924 /* If there is none, find *some* other frame. */
1925 if (NILP (frame1) || EQ (frame1, frame))
1927 FOR_EACH_FRAME (tail, frame1)
1929 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1931 /* Do not change a text terminal's top-frame. */
1932 struct frame *f1 = XFRAME (frame1);
1933 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1935 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1936 if (!EQ (top_frame, frame))
1937 frame1 = top_frame;
1939 break;
1943 #ifdef NS_IMPL_COCOA
1944 else
1945 /* Under NS, there is no system mechanism for choosing a new
1946 window to get focus -- it is left to application code.
1947 So the portion of THIS application interfacing with NS
1948 needs to know about it. We call Fraise_frame, but the
1949 purpose is really to transfer focus. */
1950 Fraise_frame (frame1);
1951 #endif
1953 do_switch_frame (frame1, 0, 1, Qnil);
1954 sf = SELECTED_FRAME ();
1957 /* Don't allow minibuf_window to remain on a deleted frame. */
1958 check_minibuf_window (frame, minibuffer_selected);
1960 /* Don't let echo_area_window to remain on a deleted frame. */
1961 if (EQ (f->minibuffer_window, echo_area_window))
1962 echo_area_window = sf->minibuffer_window;
1964 /* Clear any X selections for this frame. */
1965 #ifdef HAVE_X_WINDOWS
1966 if (FRAME_X_P (f))
1967 x_clear_frame_selections (f);
1968 #endif
1970 /* Free glyphs.
1971 This function must be called before the window tree of the
1972 frame is deleted because windows contain dynamically allocated
1973 memory. */
1974 free_glyphs (f);
1976 #ifdef HAVE_WINDOW_SYSTEM
1977 /* Give chance to each font driver to free a frame specific data. */
1978 font_update_drivers (f, Qnil);
1979 #endif
1981 /* Mark all the windows that used to be on FRAME as deleted, and then
1982 remove the reference to them. */
1983 delete_all_child_windows (f->root_window);
1984 fset_root_window (f, Qnil);
1986 Vframe_list = Fdelq (frame, Vframe_list);
1987 SET_FRAME_VISIBLE (f, 0);
1989 /* Allow the vector of menu bar contents to be freed in the next
1990 garbage collection. The frame object itself may not be garbage
1991 collected until much later, because recent_keys and other data
1992 structures can still refer to it. */
1993 fset_menu_bar_vector (f, Qnil);
1995 /* If FRAME's buffer lists contains killed
1996 buffers, this helps GC to reclaim them. */
1997 fset_buffer_list (f, Qnil);
1998 fset_buried_buffer_list (f, Qnil);
2000 free_font_driver_list (f);
2001 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2002 xfree (f->namebuf);
2003 #endif
2004 xfree (f->decode_mode_spec_buffer);
2005 xfree (FRAME_INSERT_COST (f));
2006 xfree (FRAME_DELETEN_COST (f));
2007 xfree (FRAME_INSERTN_COST (f));
2008 xfree (FRAME_DELETE_COST (f));
2010 /* Since some events are handled at the interrupt level, we may get
2011 an event for f at any time; if we zero out the frame's terminal
2012 now, then we may trip up the event-handling code. Instead, we'll
2013 promise that the terminal of the frame must be valid until we
2014 have called the window-system-dependent frame destruction
2015 routine. */
2017 struct terminal *terminal;
2018 block_input ();
2019 if (FRAME_TERMINAL (f)->delete_frame_hook)
2020 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
2021 terminal = FRAME_TERMINAL (f);
2022 f->output_data.nothing = 0;
2023 f->terminal = 0; /* Now the frame is dead. */
2024 unblock_input ();
2026 /* If needed, delete the terminal that this frame was on.
2027 (This must be done after the frame is killed.) */
2028 terminal->reference_count--;
2029 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
2030 /* FIXME: Deleting the terminal crashes emacs because of a GTK
2031 bug.
2032 https://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
2034 /* Since a similar behavior was observed on the Lucid and Motif
2035 builds (see Bug#5802, Bug#21509, Bug#23499, Bug#27816), we now
2036 don't delete the terminal for these builds either. */
2037 if (terminal->reference_count == 0 && terminal->type == output_x_window)
2038 terminal->reference_count = 1;
2039 #endif /* USE_X_TOOLKIT || USE_GTK */
2040 if (terminal->reference_count == 0)
2042 Lisp_Object tmp;
2043 XSETTERMINAL (tmp, terminal);
2045 kb = NULL;
2046 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
2048 else
2049 kb = terminal->kboard;
2052 /* If we've deleted the last_nonminibuf_frame, then try to find
2053 another one. */
2054 if (f == last_nonminibuf_frame)
2056 last_nonminibuf_frame = 0;
2058 FOR_EACH_FRAME (frames, frame1)
2060 struct frame *f1 = XFRAME (frame1);
2062 if (!FRAME_MINIBUF_ONLY_P (f1))
2064 last_nonminibuf_frame = f1;
2065 break;
2070 /* If there's no other frame on the same kboard, get out of
2071 single-kboard state if we're in it for this kboard. */
2072 if (kb != NULL)
2074 /* Some frame we found on the same kboard, or nil if there are none. */
2075 Lisp_Object frame_on_same_kboard = Qnil;
2077 FOR_EACH_FRAME (frames, frame1)
2078 if (kb == FRAME_KBOARD (XFRAME (frame1)))
2079 frame_on_same_kboard = frame1;
2081 if (NILP (frame_on_same_kboard))
2082 not_single_kboard_state (kb);
2086 /* If we've deleted this keyboard's default_minibuffer_frame, try to
2087 find another one. Prefer minibuffer-only frames, but also notice
2088 frames with other windows. */
2089 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
2091 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
2092 Lisp_Object frame_with_minibuf = Qnil;
2093 /* Some frame we found on the same kboard, or nil if there are none. */
2094 Lisp_Object frame_on_same_kboard = Qnil;
2096 FOR_EACH_FRAME (frames, frame1)
2098 struct frame *f1 = XFRAME (frame1);
2100 /* Consider only frames on the same kboard
2101 and only those with minibuffers. */
2102 if (kb == FRAME_KBOARD (f1)
2103 && FRAME_HAS_MINIBUF_P (f1))
2105 frame_with_minibuf = frame1;
2106 if (FRAME_MINIBUF_ONLY_P (f1))
2107 break;
2110 if (kb == FRAME_KBOARD (f1))
2111 frame_on_same_kboard = frame1;
2114 if (!NILP (frame_on_same_kboard))
2116 /* We know that there must be some frame with a minibuffer out
2117 there. If this were not true, all of the frames present
2118 would have to be minibufferless, which implies that at some
2119 point their minibuffer frames must have been deleted, but
2120 that is prohibited at the top; you can't delete surrogate
2121 minibuffer frames. */
2122 if (NILP (frame_with_minibuf))
2123 emacs_abort ();
2125 kset_default_minibuffer_frame (kb, frame_with_minibuf);
2127 else
2128 /* No frames left on this kboard--say no minibuffer either. */
2129 kset_default_minibuffer_frame (kb, Qnil);
2132 /* Cause frame titles to update--necessary if we now have just one frame. */
2133 if (!is_tooltip_frame)
2134 update_mode_lines = 15;
2136 return Qnil;
2139 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
2140 doc: /* Delete FRAME, permanently eliminating it from use.
2141 FRAME must be a live frame and defaults to the selected one.
2143 A frame may not be deleted if its minibuffer serves as surrogate
2144 minibuffer for another frame. Normally, you may not delete a frame if
2145 all other frames are invisible, but if the second optional argument
2146 FORCE is non-nil, you may do so.
2148 This function runs `delete-frame-functions' before actually
2149 deleting the frame, unless the frame is a tooltip.
2150 The functions are run with one argument, the frame to be deleted. */)
2151 (Lisp_Object frame, Lisp_Object force)
2153 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
2156 #ifdef HAVE_WINDOW_SYSTEM
2158 * frame_internal_border_part:
2160 * Return part of internal border the coordinates X and Y relative to
2161 * frame F are on. Return nil if the coordinates are not on the
2162 * internal border of F.
2164 * Return one of INTERNAL_BORDER_LEFT_EDGE, INTERNAL_BORDER_TOP_EDGE,
2165 * INTERNAL_BORDER_RIGHT_EDGE or INTERNAL_BORDER_BOTTOM_EDGE when the
2166 * mouse cursor is on the corresponding border with an offset of at
2167 * least one canonical character height from that border's edges.
2169 * If no border part could be found this way, return one of
2170 * INTERNAL_BORDER_TOP_LEFT_CORNER, INTERNAL_BORDER_TOP_RIGHT_CORNER,
2171 * INTERNAL_BORDER_BOTTOM_LEFT_CORNER or
2172 * INTERNAL_BORDER_BOTTOM_RIGHT_CORNER to indicate that the mouse is in
2173 * one of the corresponding corners. This means that for very small
2174 * frames an `edge' return value is preferred.
2176 enum internal_border_part
2177 frame_internal_border_part (struct frame *f, int x, int y)
2179 int border = FRAME_INTERNAL_BORDER_WIDTH (f);
2180 int offset = FRAME_LINE_HEIGHT (f);
2181 int width = FRAME_PIXEL_WIDTH (f);
2182 int height = FRAME_PIXEL_HEIGHT (f);
2183 enum internal_border_part part = INTERNAL_BORDER_NONE;
2185 if (offset < border)
2186 /* For very wide borders make offset at least as large as
2187 border. */
2188 offset = border;
2190 if (offset < x && x < width - offset)
2191 /* Top or bottom border. */
2193 if (0 <= y && y <= border)
2194 part = INTERNAL_BORDER_TOP_EDGE;
2195 else if (height - border <= y && y <= height)
2196 part = INTERNAL_BORDER_BOTTOM_EDGE;
2198 else if (offset < y && y < height - offset)
2199 /* Left or right border. */
2201 if (0 <= x && x <= border)
2202 part = INTERNAL_BORDER_LEFT_EDGE;
2203 else if (width - border <= x && x <= width)
2204 part = INTERNAL_BORDER_RIGHT_EDGE;
2206 else
2208 /* An edge. */
2209 int half_width = width / 2;
2210 int half_height = height / 2;
2212 if (0 <= x && x <= border)
2214 /* A left edge. */
2215 if (0 <= y && y <= half_height)
2216 part = INTERNAL_BORDER_TOP_LEFT_CORNER;
2217 else if (half_height < y && y <= height)
2218 part = INTERNAL_BORDER_BOTTOM_LEFT_CORNER;
2220 else if (width - border <= x && x <= width)
2222 /* A right edge. */
2223 if (0 <= y && y <= half_height)
2224 part = INTERNAL_BORDER_TOP_RIGHT_CORNER;
2225 else if (half_height < y && y <= height)
2226 part = INTERNAL_BORDER_BOTTOM_RIGHT_CORNER;
2228 else if (0 <= y && y <= border)
2230 /* A top edge. */
2231 if (0 <= x && x <= half_width)
2232 part = INTERNAL_BORDER_TOP_LEFT_CORNER;
2233 else if (half_width < x && x <= width)
2234 part = INTERNAL_BORDER_TOP_RIGHT_CORNER;
2236 else if (height - border <= y && y <= height)
2238 /* A bottom edge. */
2239 if (0 <= x && x <= half_width)
2240 part = INTERNAL_BORDER_BOTTOM_LEFT_CORNER;
2241 else if (half_width < x && x <= width)
2242 part = INTERNAL_BORDER_BOTTOM_RIGHT_CORNER;
2246 return part;
2248 #endif
2250 /* Return mouse position in character cell units. */
2252 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
2253 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
2254 The position is given in canonical character cells, where (0, 0) is the
2255 upper-left corner of the frame, X is the horizontal offset, and Y is the
2256 vertical offset, measured in units of the frame's default character size.
2257 If Emacs is running on a mouseless terminal or hasn't been programmed
2258 to read the mouse position, it returns the selected frame for FRAME
2259 and nil for X and Y.
2260 If `mouse-position-function' is non-nil, `mouse-position' calls it,
2261 passing the normal return value to that function as an argument,
2262 and returns whatever that function returns. */)
2263 (void)
2265 struct frame *f;
2266 Lisp_Object lispy_dummy;
2267 Lisp_Object x, y, retval;
2269 f = SELECTED_FRAME ();
2270 x = y = Qnil;
2272 /* It's okay for the hook to refrain from storing anything. */
2273 if (FRAME_TERMINAL (f)->mouse_position_hook)
2275 enum scroll_bar_part party_dummy;
2276 Time time_dummy;
2277 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
2278 &lispy_dummy, &party_dummy,
2279 &x, &y,
2280 &time_dummy);
2283 if (! NILP (x))
2285 int col = XINT (x);
2286 int row = XINT (y);
2287 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
2288 XSETINT (x, col);
2289 XSETINT (y, row);
2291 XSETFRAME (lispy_dummy, f);
2292 retval = Fcons (lispy_dummy, Fcons (x, y));
2293 if (!NILP (Vmouse_position_function))
2294 retval = call1 (Vmouse_position_function, retval);
2295 return retval;
2298 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
2299 Smouse_pixel_position, 0, 0, 0,
2300 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
2301 The position is given in pixel units, where (0, 0) is the
2302 upper-left corner of the frame, X is the horizontal offset, and Y is
2303 the vertical offset.
2304 If Emacs is running on a mouseless terminal or hasn't been programmed
2305 to read the mouse position, it returns the selected frame for FRAME
2306 and nil for X and Y. */)
2307 (void)
2309 struct frame *f;
2310 Lisp_Object lispy_dummy;
2311 Lisp_Object x, y, retval;
2313 f = SELECTED_FRAME ();
2314 x = y = Qnil;
2316 /* It's okay for the hook to refrain from storing anything. */
2317 if (FRAME_TERMINAL (f)->mouse_position_hook)
2319 enum scroll_bar_part party_dummy;
2320 Time time_dummy;
2321 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
2322 &lispy_dummy, &party_dummy,
2323 &x, &y,
2324 &time_dummy);
2327 XSETFRAME (lispy_dummy, f);
2328 retval = Fcons (lispy_dummy, Fcons (x, y));
2329 if (!NILP (Vmouse_position_function))
2330 retval = call1 (Vmouse_position_function, retval);
2331 return retval;
2334 #ifdef HAVE_WINDOW_SYSTEM
2336 /* On frame F, convert character coordinates X and Y to pixel
2337 coordinates *PIX_X and *PIX_Y. */
2339 static void
2340 frame_char_to_pixel_position (struct frame *f, int x, int y,
2341 int *pix_x, int *pix_y)
2343 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
2344 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
2346 if (*pix_x < 0)
2347 *pix_x = 0;
2348 if (*pix_x > FRAME_PIXEL_WIDTH (f))
2349 *pix_x = FRAME_PIXEL_WIDTH (f);
2351 if (*pix_y < 0)
2352 *pix_y = 0;
2353 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
2354 *pix_y = FRAME_PIXEL_HEIGHT (f);
2357 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
2359 static void
2360 frame_set_mouse_position (struct frame *f, int x, int y)
2362 int pix_x, pix_y;
2364 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
2365 frame_set_mouse_pixel_position (f, pix_x, pix_y);
2368 #endif /* HAVE_WINDOW_SYSTEM */
2370 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
2371 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
2372 Coordinates are relative to the frame, not a window,
2373 so the coordinates of the top left character in the frame
2374 may be nonzero due to left-hand scroll bars or the menu bar.
2376 The position is given in canonical character cells, where (0, 0) is
2377 the upper-left corner of the frame, X is the horizontal offset, and
2378 Y is the vertical offset, measured in units of the frame's default
2379 character size.
2381 This function is a no-op for an X frame that is not visible.
2382 If you have just created a frame, you must wait for it to become visible
2383 before calling this function on it, like this.
2384 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2385 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2387 CHECK_LIVE_FRAME (frame);
2388 CHECK_TYPE_RANGED_INTEGER (int, x);
2389 CHECK_TYPE_RANGED_INTEGER (int, y);
2391 /* I think this should be done with a hook. */
2392 #ifdef HAVE_WINDOW_SYSTEM
2393 if (FRAME_WINDOW_P (XFRAME (frame)))
2394 /* Warping the mouse will cause enternotify and focus events. */
2395 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
2396 #else
2397 #if defined (MSDOS)
2398 if (FRAME_MSDOS_P (XFRAME (frame)))
2400 Fselect_frame (frame, Qnil);
2401 mouse_moveto (XINT (x), XINT (y));
2403 #else
2404 #ifdef HAVE_GPM
2406 Fselect_frame (frame, Qnil);
2407 term_mouse_moveto (XINT (x), XINT (y));
2409 #endif
2410 #endif
2411 #endif
2413 return Qnil;
2416 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
2417 Sset_mouse_pixel_position, 3, 3, 0,
2418 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
2419 The position is given in pixels, where (0, 0) is the upper-left corner
2420 of the frame, X is the horizontal offset, and Y is the vertical offset.
2422 Note, this is a no-op for an X frame that is not visible.
2423 If you have just created a frame, you must wait for it to become visible
2424 before calling this function on it, like this.
2425 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2426 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2428 CHECK_LIVE_FRAME (frame);
2429 CHECK_TYPE_RANGED_INTEGER (int, x);
2430 CHECK_TYPE_RANGED_INTEGER (int, y);
2432 /* I think this should be done with a hook. */
2433 #ifdef HAVE_WINDOW_SYSTEM
2434 if (FRAME_WINDOW_P (XFRAME (frame)))
2435 /* Warping the mouse will cause enternotify and focus events. */
2436 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
2437 #else
2438 #if defined (MSDOS)
2439 if (FRAME_MSDOS_P (XFRAME (frame)))
2441 Fselect_frame (frame, Qnil);
2442 mouse_moveto (XINT (x), XINT (y));
2444 #else
2445 #ifdef HAVE_GPM
2447 Fselect_frame (frame, Qnil);
2448 term_mouse_moveto (XINT (x), XINT (y));
2450 #endif
2451 #endif
2452 #endif
2454 return Qnil;
2457 static void make_frame_visible_1 (Lisp_Object);
2459 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2460 0, 1, "",
2461 doc: /* Make the frame FRAME visible (assuming it is an X window).
2462 If omitted, FRAME defaults to the currently selected frame. */)
2463 (Lisp_Object frame)
2465 struct frame *f = decode_live_frame (frame);
2467 /* I think this should be done with a hook. */
2468 #ifdef HAVE_WINDOW_SYSTEM
2469 if (FRAME_WINDOW_P (f))
2470 x_make_frame_visible (f);
2471 #endif
2473 make_frame_visible_1 (f->root_window);
2475 /* Make menu bar update for the Buffers and Frames menus. */
2476 /* windows_or_buffers_changed = 15; FIXME: Why? */
2478 XSETFRAME (frame, f);
2479 return frame;
2482 /* Update the display_time slot of the buffers shown in WINDOW
2483 and all its descendants. */
2485 static void
2486 make_frame_visible_1 (Lisp_Object window)
2488 struct window *w;
2490 for (; !NILP (window); window = w->next)
2492 w = XWINDOW (window);
2493 if (WINDOWP (w->contents))
2494 make_frame_visible_1 (w->contents);
2495 else
2496 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2500 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2501 0, 2, "",
2502 doc: /* Make the frame FRAME invisible.
2503 If omitted, FRAME defaults to the currently selected frame.
2504 On graphical displays, invisible frames are not updated and are
2505 usually not displayed at all, even in a window system's \"taskbar\".
2507 Normally you may not make FRAME invisible if all other frames are invisible,
2508 but if the second optional argument FORCE is non-nil, you may do so.
2510 This function has no effect on text terminal frames. Such frames are
2511 always considered visible, whether or not they are currently being
2512 displayed in the terminal. */)
2513 (Lisp_Object frame, Lisp_Object force)
2515 struct frame *f = decode_live_frame (frame);
2517 if (NILP (force) && !other_frames (f, true, false))
2518 error ("Attempt to make invisible the sole visible or iconified frame");
2520 /* Don't allow minibuf_window to remain on an invisible frame. */
2521 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2523 /* I think this should be done with a hook. */
2524 #ifdef HAVE_WINDOW_SYSTEM
2525 if (FRAME_WINDOW_P (f))
2526 x_make_frame_invisible (f);
2527 #endif
2529 /* Make menu bar update for the Buffers and Frames menus. */
2530 windows_or_buffers_changed = 16;
2532 return Qnil;
2535 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2536 0, 1, "",
2537 doc: /* Make the frame FRAME into an icon.
2538 If omitted, FRAME defaults to the currently selected frame.
2540 If FRAME is a child frame, consult the variable `iconify-child-frame'
2541 for how to proceed. */)
2542 (Lisp_Object frame)
2544 struct frame *f = decode_live_frame (frame);
2545 #ifdef HAVE_WINDOW_SYSTEM
2546 Lisp_Object parent = f->parent_frame;
2548 if (!NILP (parent))
2550 if (NILP (iconify_child_frame))
2551 /* Do nothing. */
2552 return Qnil;
2553 else if (EQ (iconify_child_frame, Qiconify_top_level))
2555 /* Iconify top level frame instead (the default). */
2556 Ficonify_frame (parent);
2557 return Qnil;
2559 else if (EQ (iconify_child_frame, Qmake_invisible))
2561 /* Make frame invisible instead. */
2562 Fmake_frame_invisible (frame, Qnil);
2563 return Qnil;
2566 #endif /* HAVE_WINDOW_SYSTEM */
2568 /* Don't allow minibuf_window to remain on an iconified frame. */
2569 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2571 /* I think this should be done with a hook. */
2572 if (FRAME_WINDOW_P (f))
2574 #ifdef HAVE_WINDOW_SYSTEM
2575 x_iconify_frame (f);
2576 #endif
2579 return Qnil;
2582 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2583 1, 1, 0,
2584 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2585 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2586 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2587 On graphical displays, invisible frames are not updated and are
2588 usually not displayed at all, even in a window system's \"taskbar\".
2590 If FRAME is a text terminal frame, this always returns t.
2591 Such frames are always considered visible, whether or not they are
2592 currently being displayed on the terminal. */)
2593 (Lisp_Object frame)
2595 CHECK_LIVE_FRAME (frame);
2597 if (FRAME_VISIBLE_P (XFRAME (frame)))
2598 return Qt;
2599 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2600 return Qicon;
2601 return Qnil;
2604 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2605 0, 0, 0,
2606 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2607 (void)
2609 Lisp_Object tail, frame, value = Qnil;
2611 FOR_EACH_FRAME (tail, frame)
2612 if (FRAME_VISIBLE_P (XFRAME (frame)))
2613 value = Fcons (frame, value);
2615 return value;
2619 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2620 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2621 If FRAME is invisible or iconified, make it visible.
2622 If you don't specify a frame, the selected frame is used.
2623 If Emacs is displaying on an ordinary terminal or some other device which
2624 doesn't support multiple overlapping frames, this function selects FRAME. */)
2625 (Lisp_Object frame)
2627 struct frame *f = decode_live_frame (frame);
2629 XSETFRAME (frame, f);
2631 if (FRAME_TERMCAP_P (f))
2632 /* On a text terminal select FRAME. */
2633 Fselect_frame (frame, Qnil);
2634 else
2635 /* Do like the documentation says. */
2636 Fmake_frame_visible (frame);
2638 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2639 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2641 return Qnil;
2644 /* Should we have a corresponding function called Flower_Power? */
2645 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2646 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2647 If you don't specify a frame, the selected frame is used.
2648 If Emacs is displaying on an ordinary terminal or some other device which
2649 doesn't support multiple overlapping frames, this function does nothing. */)
2650 (Lisp_Object frame)
2652 struct frame *f = decode_live_frame (frame);
2654 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2655 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2657 return Qnil;
2661 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2662 1, 2, 0,
2663 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2664 In other words, switch-frame events caused by events in FRAME will
2665 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2666 FOCUS-FRAME after reading an event typed at FRAME.
2668 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2669 frame again receives its own keystrokes.
2671 Focus redirection is useful for temporarily redirecting keystrokes to
2672 a surrogate minibuffer frame when a frame doesn't have its own
2673 minibuffer window.
2675 A frame's focus redirection can be changed by `select-frame'. If frame
2676 FOO is selected, and then a different frame BAR is selected, any
2677 frames redirecting their focus to FOO are shifted to redirect their
2678 focus to BAR. This allows focus redirection to work properly when the
2679 user switches from one frame to another using `select-window'.
2681 This means that a frame whose focus is redirected to itself is treated
2682 differently from a frame whose focus is redirected to nil; the former
2683 is affected by `select-frame', while the latter is not.
2685 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2686 (Lisp_Object frame, Lisp_Object focus_frame)
2688 /* Note that we don't check for a live frame here. It's reasonable
2689 to redirect the focus of a frame you're about to delete, if you
2690 know what other frame should receive those keystrokes. */
2691 struct frame *f = decode_any_frame (frame);
2693 if (! NILP (focus_frame))
2694 CHECK_LIVE_FRAME (focus_frame);
2696 fset_focus_frame (f, focus_frame);
2698 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2699 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2701 return Qnil;
2705 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2706 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2707 If FRAME is omitted or nil, the selected frame is used.
2708 Return nil if FRAME's focus is not redirected.
2709 See `redirect-frame-focus'. */)
2710 (Lisp_Object frame)
2712 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2715 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 2, 0,
2716 doc: /* Set the input focus to FRAME.
2717 FRAME nil means use the selected frame. Optional argument NOACTIVATE
2718 means do not activate FRAME.
2720 If there is no window system support, this function does nothing. */)
2721 (Lisp_Object frame, Lisp_Object noactivate)
2723 #ifdef HAVE_WINDOW_SYSTEM
2724 x_focus_frame (decode_window_system_frame (frame), !NILP (noactivate));
2725 #endif
2726 return Qnil;
2729 DEFUN ("frame-after-make-frame",
2730 Fframe_after_make_frame,
2731 Sframe_after_make_frame, 2, 2, 0,
2732 doc: /* Mark FRAME as made.
2733 FRAME nil means use the selected frame. Second argument MADE non-nil
2734 means functions on `window-configuration-change-hook' are called
2735 whenever the window configuration of FRAME changes. MADE nil means
2736 these functions are not called.
2738 This function is currently called by `make-frame' only and should be
2739 otherwise used with utter care to avoid that running functions on
2740 `window-configuration-change-hook' is impeded forever. */)
2741 (Lisp_Object frame, Lisp_Object made)
2743 struct frame *f = decode_live_frame (frame);
2744 f->after_make_frame = !NILP (made);
2745 f->inhibit_horizontal_resize = false;
2746 f->inhibit_vertical_resize = false;
2747 return made;
2751 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2753 void
2754 frames_discard_buffer (Lisp_Object buffer)
2756 Lisp_Object frame, tail;
2758 FOR_EACH_FRAME (tail, frame)
2760 fset_buffer_list
2761 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2762 fset_buried_buffer_list
2763 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2767 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2768 If the alist already has an element for PROP, we change it. */
2770 void
2771 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2773 register Lisp_Object tem;
2775 tem = Fassq (prop, *alistptr);
2776 if (EQ (tem, Qnil))
2777 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2778 else
2779 Fsetcdr (tem, val);
2782 static int
2783 frame_name_fnn_p (char *str, ptrdiff_t len)
2785 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2787 char *p = str + 2;
2788 while ('0' <= *p && *p <= '9')
2789 p++;
2790 if (p == str + len)
2791 return 1;
2793 return 0;
2796 /* Set the name of the terminal frame. Also used by MSDOS frames.
2797 Modeled after x_set_name which is used for WINDOW frames. */
2799 static void
2800 set_term_frame_name (struct frame *f, Lisp_Object name)
2802 f->explicit_name = ! NILP (name);
2804 /* If NAME is nil, set the name to F<num>. */
2805 if (NILP (name))
2807 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2809 /* Check for no change needed in this very common case
2810 before we do any consing. */
2811 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2812 return;
2814 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2816 else
2818 CHECK_STRING (name);
2820 /* Don't change the name if it's already NAME. */
2821 if (! NILP (Fstring_equal (name, f->name)))
2822 return;
2824 /* Don't allow the user to set the frame name to F<num>, so it
2825 doesn't clash with the names we generate for terminal frames. */
2826 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2827 error ("Frame names of the form F<num> are usurped by Emacs");
2830 fset_name (f, name);
2831 update_mode_lines = 16;
2834 void
2835 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2837 register Lisp_Object old_alist_elt;
2839 if (EQ (prop, Qminibuffer))
2841 if (WINDOWP (val))
2843 if (!MINI_WINDOW_P (XWINDOW (val)))
2844 error ("The `minibuffer' parameter does not specify a valid minibuffer window");
2845 else if (FRAME_MINIBUF_ONLY_P (f))
2847 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2848 val = Qonly;
2849 else
2850 error ("Can't change the minibuffer window of a minibuffer-only frame");
2852 else if (FRAME_HAS_MINIBUF_P (f))
2854 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2855 val = Qt;
2856 else
2857 error ("Can't change the minibuffer window of a frame with its own minibuffer");
2859 else
2860 /* Store the chosen minibuffer window. */
2861 fset_minibuffer_window (f, val);
2863 else
2865 Lisp_Object old_val = Fcdr (Fassq (Qminibuffer, f->param_alist));
2867 if (!NILP (old_val))
2869 if (WINDOWP (old_val) && NILP (val))
2870 /* Don't change the value for a minibuffer-less frame if
2871 only nil was specified as new value. */
2872 val = old_val;
2873 else if (!EQ (old_val, val))
2874 error ("Can't change the `minibuffer' parameter of this frame");
2879 /* Check each parent-frame and delete-before parameter for a
2880 circular dependency. Do not check between parameters, so you can
2881 still create circular dependencies with different properties, for
2882 example a chain of frames F1->F2->...Fn such that F1 is an ancestor
2883 frame of Fn and thus cannot be deleted before Fn and a second chain
2884 Fn->Fn-1->...F1 such that Fn cannot be deleted before F1. */
2885 else if (EQ (prop, Qparent_frame) || EQ (prop, Qdelete_before))
2887 Lisp_Object oldval = Fcdr (Fassq (prop, f->param_alist));
2889 if (!EQ (oldval, val) && !NILP (val))
2891 Lisp_Object frame;
2892 Lisp_Object frame1 = val;
2894 if (!FRAMEP (frame1) || !FRAME_LIVE_P (XFRAME (frame1)))
2895 error ("Invalid `%s' frame parameter",
2896 SSDATA (SYMBOL_NAME (prop)));
2898 XSETFRAME (frame, f);
2900 while (FRAMEP (frame1) && FRAME_LIVE_P (XFRAME (frame1)))
2901 if (EQ (frame1, frame))
2902 error ("Circular specification of `%s' frame parameter",
2903 SSDATA (SYMBOL_NAME (prop)));
2904 else
2905 frame1 = get_frame_param (XFRAME (frame1), prop);
2909 /* The buffer-list parameters are stored in a special place and not
2910 in the alist. All buffers must be live. */
2911 else if (EQ (prop, Qbuffer_list))
2913 Lisp_Object list = Qnil;
2914 for (; CONSP (val); val = XCDR (val))
2915 if (!NILP (Fbuffer_live_p (XCAR (val))))
2916 list = Fcons (XCAR (val), list);
2917 fset_buffer_list (f, Fnreverse (list));
2918 return;
2920 else if (EQ (prop, Qburied_buffer_list))
2922 Lisp_Object list = Qnil;
2923 for (; CONSP (val); val = XCDR (val))
2924 if (!NILP (Fbuffer_live_p (XCAR (val))))
2925 list = Fcons (XCAR (val), list);
2926 fset_buried_buffer_list (f, Fnreverse (list));
2927 return;
2930 /* The tty color needed to be set before the frame's parameter
2931 alist was updated with the new value. This is not true any more,
2932 but we still do this test early on. */
2933 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2934 && f == FRAME_TTY (f)->previous_frame)
2935 /* Force redisplay of this tty. */
2936 FRAME_TTY (f)->previous_frame = NULL;
2938 /* Update the frame parameter alist. */
2939 old_alist_elt = Fassq (prop, f->param_alist);
2940 if (EQ (old_alist_elt, Qnil))
2941 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2942 else
2943 Fsetcdr (old_alist_elt, val);
2945 /* Update some other special parameters in their special places
2946 in addition to the alist. */
2948 if (EQ (prop, Qbuffer_predicate))
2949 fset_buffer_predicate (f, val);
2951 if (! FRAME_WINDOW_P (f))
2953 if (EQ (prop, Qmenu_bar_lines))
2954 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2955 else if (EQ (prop, Qname))
2956 set_term_frame_name (f, val);
2960 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2961 is not an unspecified foreground or background color. */
2963 static Lisp_Object
2964 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2966 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2967 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2968 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2969 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2972 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2973 doc: /* Return the parameters-alist of frame FRAME.
2974 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2975 The meaningful PARMs depend on the kind of frame.
2976 If FRAME is omitted or nil, return information on the currently selected frame. */)
2977 (Lisp_Object frame)
2979 Lisp_Object alist;
2980 struct frame *f = decode_any_frame (frame);
2981 int height, width;
2983 if (!FRAME_LIVE_P (f))
2984 return Qnil;
2986 alist = Fcopy_alist (f->param_alist);
2988 if (!FRAME_WINDOW_P (f))
2990 Lisp_Object elt;
2992 /* If the frame's parameter alist says the colors are
2993 unspecified and reversed, take the frame's background pixel
2994 for foreground and vice versa. */
2995 elt = Fassq (Qforeground_color, alist);
2996 if (CONSP (elt) && STRINGP (XCDR (elt)))
2998 elt = frame_unspecified_color (f, XCDR (elt));
2999 if (!NILP (elt))
3000 store_in_alist (&alist, Qforeground_color, elt);
3002 else
3003 store_in_alist (&alist, Qforeground_color,
3004 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
3005 elt = Fassq (Qbackground_color, alist);
3006 if (CONSP (elt) && STRINGP (XCDR (elt)))
3008 elt = frame_unspecified_color (f, XCDR (elt));
3009 if (!NILP (elt))
3010 store_in_alist (&alist, Qbackground_color, elt);
3012 else
3013 store_in_alist (&alist, Qbackground_color,
3014 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
3015 store_in_alist (&alist, Qfont,
3016 build_string (FRAME_MSDOS_P (f)
3017 ? "ms-dos"
3018 : FRAME_W32_P (f) ? "w32term"
3019 :"tty"));
3021 store_in_alist (&alist, Qname, f->name);
3022 height = (f->new_height
3023 ? (f->new_pixelwise
3024 ? (f->new_height / FRAME_LINE_HEIGHT (f))
3025 : f->new_height)
3026 : FRAME_LINES (f));
3027 store_in_alist (&alist, Qheight, make_number (height));
3028 width = (f->new_width
3029 ? (f->new_pixelwise
3030 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
3031 : f->new_width)
3032 : FRAME_COLS (f));
3033 store_in_alist (&alist, Qwidth, make_number (width));
3034 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
3035 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
3036 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
3037 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
3039 /* I think this should be done with a hook. */
3040 #ifdef HAVE_WINDOW_SYSTEM
3041 if (FRAME_WINDOW_P (f))
3042 x_report_frame_params (f, &alist);
3043 else
3044 #endif
3046 /* This ought to be correct in f->param_alist for an X frame. */
3047 Lisp_Object lines;
3048 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
3049 store_in_alist (&alist, Qmenu_bar_lines, lines);
3052 return alist;
3056 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
3057 doc: /* Return FRAME's value for parameter PARAMETER.
3058 If FRAME is nil, describe the currently selected frame. */)
3059 (Lisp_Object frame, Lisp_Object parameter)
3061 struct frame *f = decode_any_frame (frame);
3062 Lisp_Object value = Qnil;
3064 CHECK_SYMBOL (parameter);
3066 XSETFRAME (frame, f);
3068 if (FRAME_LIVE_P (f))
3070 /* Avoid consing in frequent cases. */
3071 if (EQ (parameter, Qname))
3072 value = f->name;
3073 #ifdef HAVE_WINDOW_SYSTEM
3074 /* These are used by vertical motion commands. */
3075 else if (EQ (parameter, Qvertical_scroll_bars))
3076 value = (f->vertical_scroll_bar_type == vertical_scroll_bar_none
3077 ? Qnil
3078 : (f->vertical_scroll_bar_type == vertical_scroll_bar_left
3079 ? Qleft : Qright));
3080 else if (EQ (parameter, Qhorizontal_scroll_bars))
3081 value = f->horizontal_scroll_bars ? Qt : Qnil;
3082 else if (EQ (parameter, Qline_spacing) && f->extra_line_spacing == 0)
3083 /* If this is non-zero, we can't determine whether the user specified
3084 an integer or float value without looking through 'param_alist'. */
3085 value = make_number (0);
3086 else if (EQ (parameter, Qfont) && FRAME_X_P (f))
3087 value = FRAME_FONT (f)->props[FONT_NAME_INDEX];
3088 #endif /* HAVE_WINDOW_SYSTEM */
3089 #ifdef HAVE_X_WINDOWS
3090 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
3091 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
3092 #endif /* HAVE_X_WINDOWS */
3093 else if (EQ (parameter, Qbackground_color)
3094 || EQ (parameter, Qforeground_color))
3096 value = Fassq (parameter, f->param_alist);
3097 if (CONSP (value))
3099 value = XCDR (value);
3100 /* Fframe_parameters puts the actual fg/bg color names,
3101 even if f->param_alist says otherwise. This is
3102 important when param_alist's notion of colors is
3103 "unspecified". We need to do the same here. */
3104 if (STRINGP (value) && !FRAME_WINDOW_P (f))
3106 Lisp_Object tem = frame_unspecified_color (f, value);
3108 if (!NILP (tem))
3109 value = tem;
3112 else
3113 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
3115 else if (EQ (parameter, Qdisplay_type)
3116 || EQ (parameter, Qbackground_mode))
3117 value = Fcdr (Fassq (parameter, f->param_alist));
3118 else
3119 /* FIXME: Avoid this code path at all (as well as code duplication)
3120 by sharing more code with Fframe_parameters. */
3121 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
3124 return value;
3128 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
3129 Smodify_frame_parameters, 2, 2, 0,
3130 doc: /* Modify FRAME according to new values of its parameters in ALIST.
3131 If FRAME is nil, it defaults to the selected frame.
3132 ALIST is an alist of parameters to change and their new values.
3133 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
3134 Which PARMs are meaningful depends on the kind of frame.
3135 The meaningful parameters are acted upon, i.e. the frame is changed
3136 according to their new values, and are also stored in the frame's
3137 parameter list so that `frame-parameters' will return them.
3138 PARMs that are not meaningful are still stored in the frame's parameter
3139 list, but are otherwise ignored. */)
3140 (Lisp_Object frame, Lisp_Object alist)
3142 struct frame *f = decode_live_frame (frame);
3143 Lisp_Object prop, val;
3145 /* I think this should be done with a hook. */
3146 #ifdef HAVE_WINDOW_SYSTEM
3147 if (FRAME_WINDOW_P (f))
3148 x_set_frame_parameters (f, alist);
3149 else
3150 #endif
3151 #ifdef MSDOS
3152 if (FRAME_MSDOS_P (f))
3153 IT_set_frame_parameters (f, alist);
3154 else
3155 #endif
3158 EMACS_INT length = XFASTINT (Flength (alist));
3159 ptrdiff_t i;
3160 Lisp_Object *parms;
3161 Lisp_Object *values;
3162 USE_SAFE_ALLOCA;
3163 SAFE_ALLOCA_LISP (parms, 2 * length);
3164 values = parms + length;
3166 /* Extract parm names and values into those vectors. */
3168 for (i = 0; CONSP (alist); alist = XCDR (alist))
3170 Lisp_Object elt;
3172 elt = XCAR (alist);
3173 parms[i] = Fcar (elt);
3174 values[i] = Fcdr (elt);
3175 i++;
3178 /* Now process them in reverse of specified order. */
3179 while (--i >= 0)
3181 prop = parms[i];
3182 val = values[i];
3183 store_frame_param (f, prop, val);
3185 if (EQ (prop, Qforeground_color)
3186 || EQ (prop, Qbackground_color))
3187 update_face_from_frame_parameter (f, prop, val);
3190 SAFE_FREE ();
3192 return Qnil;
3195 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
3196 0, 1, 0,
3197 doc: /* Height in pixels of a line in the font in frame FRAME.
3198 If FRAME is omitted or nil, the selected frame is used.
3199 For a terminal frame, the value is always 1. */)
3200 (Lisp_Object frame)
3202 #ifdef HAVE_WINDOW_SYSTEM
3203 struct frame *f = decode_any_frame (frame);
3205 if (FRAME_WINDOW_P (f))
3206 return make_number (FRAME_LINE_HEIGHT (f));
3207 else
3208 #endif
3209 return make_number (1);
3213 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
3214 0, 1, 0,
3215 doc: /* Width in pixels of characters in the font in frame FRAME.
3216 If FRAME is omitted or nil, the selected frame is used.
3217 On a graphical screen, the width is the standard width of the default font.
3218 For a terminal screen, the value is always 1. */)
3219 (Lisp_Object frame)
3221 #ifdef HAVE_WINDOW_SYSTEM
3222 struct frame *f = decode_any_frame (frame);
3224 if (FRAME_WINDOW_P (f))
3225 return make_number (FRAME_COLUMN_WIDTH (f));
3226 else
3227 #endif
3228 return make_number (1);
3231 DEFUN ("frame-native-width", Fframe_native_width,
3232 Sframe_native_width, 0, 1, 0,
3233 doc: /* Return FRAME's native width in pixels.
3234 For a terminal frame, the result really gives the width in characters.
3235 If FRAME is omitted or nil, the selected frame is used. */)
3236 (Lisp_Object frame)
3238 struct frame *f = decode_any_frame (frame);
3240 #ifdef HAVE_WINDOW_SYSTEM
3241 if (FRAME_WINDOW_P (f))
3242 return make_number (FRAME_PIXEL_WIDTH (f));
3243 else
3244 #endif
3245 return make_number (FRAME_TOTAL_COLS (f));
3248 DEFUN ("frame-native-height", Fframe_native_height,
3249 Sframe_native_height, 0, 1, 0,
3250 doc: /* Return FRAME's native height in pixels.
3251 If FRAME is omitted or nil, the selected frame is used. The exact value
3252 of the result depends on the window-system and toolkit in use:
3254 In the Gtk+ and NS versions, it includes only any window (including the
3255 minibuffer or echo area), mode line, and header line. It does not
3256 include the tool bar or menu bar. With other graphical versions, it may
3257 also include the tool bar and the menu bar.
3259 For a text terminal, it includes the menu bar. In this case, the
3260 result is really in characters rather than pixels (i.e., is identical
3261 to `frame-height'). */)
3262 (Lisp_Object frame)
3264 struct frame *f = decode_any_frame (frame);
3266 #ifdef HAVE_WINDOW_SYSTEM
3267 if (FRAME_WINDOW_P (f))
3268 return make_number (FRAME_PIXEL_HEIGHT (f));
3269 else
3270 #endif
3271 return make_number (FRAME_TOTAL_LINES (f));
3274 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
3275 Stool_bar_pixel_width, 0, 1, 0,
3276 doc: /* Return width in pixels of FRAME's tool bar.
3277 The result is greater than zero only when the tool bar is on the left
3278 or right side of FRAME. If FRAME is omitted or nil, the selected frame
3279 is used. */)
3280 (Lisp_Object frame)
3282 #ifdef FRAME_TOOLBAR_WIDTH
3283 struct frame *f = decode_any_frame (frame);
3285 if (FRAME_WINDOW_P (f))
3286 return make_number (FRAME_TOOLBAR_WIDTH (f));
3287 #endif
3288 return make_number (0);
3291 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
3292 doc: /* Return width in columns of FRAME's text area. */)
3293 (Lisp_Object frame)
3295 return make_number (FRAME_COLS (decode_any_frame (frame)));
3298 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
3299 doc: /* Return height in lines of FRAME's text area. */)
3300 (Lisp_Object frame)
3302 return make_number (FRAME_LINES (decode_any_frame (frame)));
3305 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
3306 doc: /* Return number of total columns of FRAME. */)
3307 (Lisp_Object frame)
3309 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
3312 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
3313 doc: /* Return number of total lines of FRAME. */)
3314 (Lisp_Object frame)
3316 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
3319 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
3320 doc: /* Return text area width of FRAME in pixels. */)
3321 (Lisp_Object frame)
3323 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
3326 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
3327 doc: /* Return text area height of FRAME in pixels. */)
3328 (Lisp_Object frame)
3330 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
3333 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
3334 doc: /* Return scroll bar width of FRAME in pixels. */)
3335 (Lisp_Object frame)
3337 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
3340 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
3341 doc: /* Return scroll bar height of FRAME in pixels. */)
3342 (Lisp_Object frame)
3344 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
3347 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
3348 doc: /* Return fringe width of FRAME in pixels. */)
3349 (Lisp_Object frame)
3351 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
3354 DEFUN ("frame-internal-border-width", Fframe_internal_border_width, Sframe_internal_border_width, 0, 1, 0,
3355 doc: /* Return width of FRAME's internal border in pixels. */)
3356 (Lisp_Object frame)
3358 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
3361 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
3362 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
3363 (Lisp_Object frame)
3365 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
3368 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
3369 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
3370 (Lisp_Object frame)
3372 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
3375 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
3376 doc: /* Set text height of frame FRAME to HEIGHT lines.
3377 Optional third arg PRETEND non-nil means that redisplay should use
3378 HEIGHT lines but that the idea of the actual height of the frame should
3379 not be changed.
3381 Optional fourth argument PIXELWISE non-nil means that FRAME should be
3382 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
3383 window managers may refuse to honor a HEIGHT that is not an integer
3384 multiple of the default frame font height. */)
3385 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
3387 struct frame *f = decode_live_frame (frame);
3388 int pixel_height;
3390 CHECK_TYPE_RANGED_INTEGER (int, height);
3392 pixel_height = (!NILP (pixelwise)
3393 ? XINT (height)
3394 : XINT (height) * FRAME_LINE_HEIGHT (f));
3395 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
3397 return Qnil;
3400 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
3401 doc: /* Set text width of frame FRAME to WIDTH columns.
3402 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
3403 columns but that the idea of the actual width of the frame should not
3404 be changed.
3406 Optional fourth argument PIXELWISE non-nil means that FRAME should be
3407 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
3408 window managers may refuse to honor a WIDTH that is not an integer
3409 multiple of the default frame font width. */)
3410 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
3412 struct frame *f = decode_live_frame (frame);
3413 int pixel_width;
3415 CHECK_TYPE_RANGED_INTEGER (int, width);
3417 pixel_width = (!NILP (pixelwise)
3418 ? XINT (width)
3419 : XINT (width) * FRAME_COLUMN_WIDTH (f));
3420 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
3422 return Qnil;
3425 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
3426 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
3427 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
3428 When `frame-resize-pixelwise' is nil, some window managers may refuse to
3429 honor a WIDTH that is not an integer multiple of the default frame font
3430 width or a HEIGHT that is not an integer multiple of the default frame
3431 font height. */)
3432 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
3434 struct frame *f = decode_live_frame (frame);
3435 int pixel_width, pixel_height;
3437 CHECK_TYPE_RANGED_INTEGER (int, width);
3438 CHECK_TYPE_RANGED_INTEGER (int, height);
3440 pixel_width = (!NILP (pixelwise)
3441 ? XINT (width)
3442 : XINT (width) * FRAME_COLUMN_WIDTH (f));
3443 pixel_height = (!NILP (pixelwise)
3444 ? XINT (height)
3445 : XINT (height) * FRAME_LINE_HEIGHT (f));
3446 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
3448 return Qnil;
3451 DEFUN ("frame-position", Fframe_position,
3452 Sframe_position, 0, 1, 0,
3453 doc: /* Return top left corner of FRAME in pixels.
3454 FRAME must be a live frame and defaults to the selected one. The return
3455 value is a cons (x, y) of the coordinates of the top left corner of
3456 FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's
3457 display. */)
3458 (Lisp_Object frame)
3460 register struct frame *f = decode_live_frame (frame);
3462 return Fcons (make_number (f->left_pos), make_number (f->top_pos));
3465 DEFUN ("set-frame-position", Fset_frame_position,
3466 Sset_frame_position, 3, 3, 0,
3467 doc: /* Set position of FRAME to (X, Y).
3468 FRAME must be a live frame and defaults to the selected one. X and Y,
3469 if positive, specify the coordinate of the left and top edge of FRAME's
3470 outer frame in pixels relative to an origin (0, 0) of FRAME's display.
3471 If any of X or Y is negative, it specifies the coordinates of the right
3472 or bottom edge of the outer frame of FRAME relative to the right or
3473 bottom edge of FRAME's display. */)
3474 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
3476 struct frame *f = decode_live_frame (frame);
3478 CHECK_TYPE_RANGED_INTEGER (int, x);
3479 CHECK_TYPE_RANGED_INTEGER (int, y);
3481 /* I think this should be done with a hook. */
3482 if (FRAME_WINDOW_P (f))
3484 #ifdef HAVE_WINDOW_SYSTEM
3485 x_set_offset (f, XINT (x), XINT (y), 1);
3486 #endif
3489 return Qt;
3492 /***********************************************************************
3493 Frame Parameters
3494 ***********************************************************************/
3496 /* Connect the frame-parameter names for X frames
3497 to the ways of passing the parameter values to the window system.
3499 The name of a parameter, as a Lisp symbol,
3500 has an `x-frame-parameter' property which is an integer in Lisp
3501 that is an index in this table. */
3503 struct frame_parm_table {
3504 const char *name;
3505 int sym;
3508 static const struct frame_parm_table frame_parms[] =
3510 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3511 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3512 {"background-color", -1},
3513 {"border-color", SYMBOL_INDEX (Qborder_color)},
3514 {"border-width", SYMBOL_INDEX (Qborder_width)},
3515 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3516 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3517 {"font", -1},
3518 {"foreground-color", -1},
3519 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3520 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3521 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3522 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3523 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3524 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3525 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3526 {"name", SYMBOL_INDEX (Qname)},
3527 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3528 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3529 {"title", SYMBOL_INDEX (Qtitle)},
3530 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3531 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3532 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3533 {"visibility", SYMBOL_INDEX (Qvisibility)},
3534 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3535 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3536 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3537 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3538 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3539 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3540 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3541 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3542 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3543 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3544 {"alpha", SYMBOL_INDEX (Qalpha)},
3545 {"sticky", SYMBOL_INDEX (Qsticky)},
3546 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3547 {"inhibit-double-buffering", SYMBOL_INDEX (Qinhibit_double_buffering)},
3548 {"undecorated", SYMBOL_INDEX (Qundecorated)},
3549 {"parent-frame", SYMBOL_INDEX (Qparent_frame)},
3550 {"skip-taskbar", SYMBOL_INDEX (Qskip_taskbar)},
3551 {"no-focus-on-map", SYMBOL_INDEX (Qno_focus_on_map)},
3552 {"no-accept-focus", SYMBOL_INDEX (Qno_accept_focus)},
3553 {"z-group", SYMBOL_INDEX (Qz_group)},
3554 {"override-redirect", SYMBOL_INDEX (Qoverride_redirect)},
3555 {"no-special-glyphs", SYMBOL_INDEX (Qno_special_glyphs)},
3556 #ifdef NS_IMPL_COCOA
3557 {"ns-appearance", SYMBOL_INDEX (Qns_appearance)},
3558 {"ns-transparent-titlebar", SYMBOL_INDEX (Qns_transparent_titlebar)},
3559 #endif
3562 #ifdef HAVE_WINDOW_SYSTEM
3564 /* Enumeration type for switch in frame_float. */
3565 enum frame_float_type
3567 FRAME_FLOAT_WIDTH,
3568 FRAME_FLOAT_HEIGHT,
3569 FRAME_FLOAT_LEFT,
3570 FRAME_FLOAT_TOP
3574 * frame_float:
3576 * Process the value VAL of the float type frame parameter 'width',
3577 * 'height', 'left', or 'top' specified via a frame_float_type
3578 * enumeration type WHAT for frame F. Such parameters relate the outer
3579 * size or position of F to the size of the F's display or parent frame
3580 * which have to be both available in some way.
3582 * The return value is a size or position value in pixels. VAL must be
3583 * in the range 0.0 to 1.0 where a width/height of 0.0 means to return 0
3584 * and 1.0 means to return the full width/height of the display/parent.
3585 * For positions, 0.0 means position in the left/top corner of the
3586 * display/parent while 1.0 means to position at the right/bottom corner
3587 * of the display/parent frame.
3589 * Set PARENT_DONE and OUTER_DONE to avoid recalculation of the outer
3590 * size or parent or display attributes when more float parameters are
3591 * calculated in a row: -1 means not processed yet, 0 means processing
3592 * failed, 1 means processing succeeded.
3594 * Return DEFAULT_VALUE when processing fails for whatever reason with
3595 * one exception: When calculating F's outer edges fails (probably
3596 * because F has not been created yet) return the difference between F's
3597 * native and text size.
3599 static int
3600 frame_float (struct frame *f, Lisp_Object val, enum frame_float_type what,
3601 int *parent_done, int *outer_done, int default_value)
3603 double d_val = XFLOAT_DATA (val);
3605 if (d_val < 0.0 || d_val > 1.0)
3606 /* Invalid VAL. */
3607 return default_value;
3608 else
3610 static unsigned parent_width, parent_height;
3611 static int parent_left, parent_top;
3612 static unsigned outer_minus_text_width, outer_minus_text_height;
3613 struct frame *p = FRAME_PARENT_FRAME (f);
3615 if (*parent_done == 1)
3617 else if (p)
3619 parent_width = FRAME_PIXEL_WIDTH (p);
3620 parent_height = FRAME_PIXEL_HEIGHT (p);
3621 *parent_done = 1;
3623 else
3625 if (*parent_done == 0)
3626 /* No workarea available. */
3627 return default_value;
3628 else if (*parent_done == -1)
3630 Lisp_Object monitor_attributes;
3631 Lisp_Object workarea;
3632 Lisp_Object frame;
3634 XSETFRAME (frame, f);
3635 monitor_attributes = Fcar (call1 (Qdisplay_monitor_attributes_list, frame));
3636 if (NILP (monitor_attributes))
3638 /* No monitor attributes available. */
3639 *parent_done = 0;
3641 return default_value;
3644 workarea = Fcdr (Fassq (Qworkarea, monitor_attributes));
3645 if (NILP (workarea))
3647 /* No workarea available. */
3648 *parent_done = 0;
3650 return default_value;
3653 /* Workarea available. */
3654 parent_left = XINT (Fnth (make_number (0), workarea));
3655 parent_top = XINT (Fnth (make_number (1), workarea));
3656 parent_width = XINT (Fnth (make_number (2), workarea));
3657 parent_height = XINT (Fnth (make_number (3), workarea));
3658 *parent_done = 1;
3662 if (*outer_done == 1)
3664 else if (FRAME_UNDECORATED (f))
3666 outer_minus_text_width
3667 = FRAME_PIXEL_WIDTH (f) - FRAME_TEXT_WIDTH (f);
3668 outer_minus_text_height
3669 = FRAME_PIXEL_HEIGHT (f) - FRAME_TEXT_HEIGHT (f);
3670 *outer_done = 1;
3672 else if (*outer_done == 0)
3673 /* No outer size available. */
3674 return default_value;
3675 else if (*outer_done == -1)
3677 Lisp_Object frame, outer_edges;
3679 XSETFRAME (frame, f);
3680 outer_edges = call2 (Qframe_edges, frame, Qouter_edges);
3682 if (!NILP (outer_edges))
3684 outer_minus_text_width
3685 = (XINT (Fnth (make_number (2), outer_edges))
3686 - XINT (Fnth (make_number (0), outer_edges))
3687 - FRAME_TEXT_WIDTH (f));
3688 outer_minus_text_height
3689 = (XINT (Fnth (make_number (3), outer_edges))
3690 - XINT (Fnth (make_number (1), outer_edges))
3691 - FRAME_TEXT_HEIGHT (f));
3693 else
3695 /* If we can't get any outer edges, proceed as if the frame
3696 were undecorated. */
3697 outer_minus_text_width
3698 = FRAME_PIXEL_WIDTH (f) - FRAME_TEXT_WIDTH (f);
3699 outer_minus_text_height
3700 = FRAME_PIXEL_HEIGHT (f) - FRAME_TEXT_HEIGHT (f);
3703 *outer_done = 1;
3706 switch (what)
3708 case FRAME_FLOAT_WIDTH:
3709 return parent_width * d_val - outer_minus_text_width;
3711 case FRAME_FLOAT_HEIGHT:
3712 return parent_height * d_val - outer_minus_text_height;
3714 case FRAME_FLOAT_LEFT:
3716 int rest_width = (parent_width
3717 - FRAME_TEXT_WIDTH (f)
3718 - outer_minus_text_width);
3720 if (p)
3721 return (rest_width <= 0 ? 0 : d_val * rest_width);
3722 else
3723 return (rest_width <= 0
3724 ? parent_left
3725 : parent_left + d_val * rest_width);
3727 case FRAME_FLOAT_TOP:
3729 int rest_height = (parent_height
3730 - FRAME_TEXT_HEIGHT (f)
3731 - outer_minus_text_height);
3733 if (p)
3734 return (rest_height <= 0 ? 0 : d_val * rest_height);
3735 else
3736 return (rest_height <= 0
3737 ? parent_top
3738 : parent_top + d_val * rest_height);
3740 default:
3741 emacs_abort ();
3746 /* Change the parameters of frame F as specified by ALIST.
3747 If a parameter is not specially recognized, do nothing special;
3748 otherwise call the `x_set_...' function for that parameter.
3749 Except for certain geometry properties, always call store_frame_param
3750 to store the new value in the parameter alist. */
3752 void
3753 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3755 Lisp_Object tail, frame;
3758 /* If both of these parameters are present, it's more efficient to
3759 set them both at once. So we wait until we've looked at the
3760 entire list before we set them. */
3761 int width = -1, height = -1; /* -1 denotes they were not changed. */
3763 /* Same here. */
3764 Lisp_Object left, top;
3766 /* Same with these. */
3767 Lisp_Object icon_left, icon_top;
3769 /* And with this. */
3770 Lisp_Object fullscreen;
3771 bool fullscreen_change = false;
3773 /* Record in these vectors all the parms specified. */
3774 Lisp_Object *parms;
3775 Lisp_Object *values;
3776 ptrdiff_t i, j, size;
3777 bool left_no_change = 0, top_no_change = 0;
3778 #ifdef HAVE_X_WINDOWS
3779 bool icon_left_no_change = 0, icon_top_no_change = 0;
3780 #endif
3781 int parent_done = -1, outer_done = -1;
3783 XSETFRAME (frame, f);
3784 for (size = 0, tail = alist; CONSP (tail); tail = XCDR (tail))
3785 size++;
3786 CHECK_LIST_END (tail, alist);
3788 USE_SAFE_ALLOCA;
3789 SAFE_ALLOCA_LISP (parms, 2 * size);
3790 values = parms + size;
3792 /* Extract parm names and values into those vectors. */
3794 i = 0, j = size - 1;
3795 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3797 Lisp_Object elt = XCAR (tail), prop = Fcar (elt), val = Fcdr (elt);
3799 /* Some properties are independent of other properties, but other
3800 properties are dependent upon them. These special properties
3801 are foreground_color, background_color (affects cursor_color)
3802 and font (affects fringe widths); they're recorded starting
3803 from the end of PARMS and VALUES to process them first by using
3804 reverse iteration. */
3806 if (EQ (prop, Qforeground_color)
3807 || EQ (prop, Qbackground_color)
3808 || EQ (prop, Qfont))
3810 parms[j] = prop;
3811 values[j] = val;
3812 j--;
3814 else
3816 parms[i] = prop;
3817 values[i] = val;
3818 i++;
3822 /* TAIL and ALIST are not used again below here. */
3823 alist = tail = Qnil;
3825 top = left = Qunbound;
3826 icon_left = icon_top = Qunbound;
3828 /* Reverse order is used to make sure that special
3829 properties noticed above are processed first. */
3830 for (i = size - 1; i >= 0; i--)
3832 Lisp_Object prop, val;
3834 prop = parms[i];
3835 val = values[i];
3837 if (EQ (prop, Qwidth))
3839 if (RANGED_INTEGERP (0, val, INT_MAX))
3840 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3841 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3842 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3843 width = XFASTINT (XCDR (val));
3844 else if (FLOATP (val))
3845 width = frame_float (f, val, FRAME_FLOAT_WIDTH, &parent_done,
3846 &outer_done, -1);
3848 else if (EQ (prop, Qheight))
3850 if (RANGED_INTEGERP (0, val, INT_MAX))
3851 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3852 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3853 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3854 height = XFASTINT (XCDR (val));
3855 else if (FLOATP (val))
3856 height = frame_float (f, val, FRAME_FLOAT_HEIGHT, &parent_done,
3857 &outer_done, -1);
3859 else if (EQ (prop, Qtop))
3860 top = val;
3861 else if (EQ (prop, Qleft))
3862 left = val;
3863 else if (EQ (prop, Qicon_top))
3864 icon_top = val;
3865 else if (EQ (prop, Qicon_left))
3866 icon_left = val;
3867 else if (EQ (prop, Qfullscreen))
3869 fullscreen = val;
3870 fullscreen_change = true;
3872 else
3874 register Lisp_Object param_index, old_value;
3876 old_value = get_frame_param (f, prop);
3878 store_frame_param (f, prop, val);
3880 param_index = Fget (prop, Qx_frame_parameter);
3881 if (NATNUMP (param_index)
3882 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3883 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3884 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3888 /* Don't die if just one of these was set. */
3889 if (EQ (left, Qunbound))
3891 left_no_change = 1;
3892 if (f->left_pos < 0)
3893 left = list2 (Qplus, make_number (f->left_pos));
3894 else
3895 XSETINT (left, f->left_pos);
3897 if (EQ (top, Qunbound))
3899 top_no_change = 1;
3900 if (f->top_pos < 0)
3901 top = list2 (Qplus, make_number (f->top_pos));
3902 else
3903 XSETINT (top, f->top_pos);
3906 /* If one of the icon positions was not set, preserve or default it. */
3907 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3909 #ifdef HAVE_X_WINDOWS
3910 icon_left_no_change = 1;
3911 #endif
3912 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3913 if (NILP (icon_left))
3914 XSETINT (icon_left, 0);
3916 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3918 #ifdef HAVE_X_WINDOWS
3919 icon_top_no_change = 1;
3920 #endif
3921 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3922 if (NILP (icon_top))
3923 XSETINT (icon_top, 0);
3926 /* Don't set these parameters unless they've been explicitly
3927 specified. The window might be mapped or resized while we're in
3928 this function, and we don't want to override that unless the lisp
3929 code has asked for it.
3931 Don't set these parameters unless they actually differ from the
3932 window's current parameters; the window may not actually exist
3933 yet. */
3934 if ((width != -1 && width != FRAME_TEXT_WIDTH (f))
3935 || (height != -1 && height != FRAME_TEXT_HEIGHT (f)))
3936 /* We could consider checking f->after_make_frame here, but I
3937 don't have the faintest idea why the following is needed at
3938 all. With the old setting it can get a Heisenbug when
3939 EmacsFrameResize intermittently provokes a delayed
3940 change_frame_size in the middle of adjust_frame_size. */
3941 /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
3942 adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters);
3944 if ((!NILP (left) || !NILP (top))
3945 && ! (left_no_change && top_no_change)
3946 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3947 && NUMBERP (top) && XINT (top) == f->top_pos))
3949 int leftpos = 0;
3950 int toppos = 0;
3952 /* Record the signs. */
3953 f->size_hint_flags &= ~ (XNegative | YNegative);
3954 if (EQ (left, Qminus))
3955 f->size_hint_flags |= XNegative;
3956 else if (TYPE_RANGED_INTEGERP (int, left))
3958 leftpos = XINT (left);
3959 if (leftpos < 0)
3960 f->size_hint_flags |= XNegative;
3962 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3963 && CONSP (XCDR (left))
3964 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3966 leftpos = - XINT (XCAR (XCDR (left)));
3967 f->size_hint_flags |= XNegative;
3969 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3970 && CONSP (XCDR (left))
3971 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3972 leftpos = XINT (XCAR (XCDR (left)));
3973 else if (FLOATP (left))
3974 leftpos = frame_float (f, left, FRAME_FLOAT_LEFT, &parent_done,
3975 &outer_done, 0);
3977 if (EQ (top, Qminus))
3978 f->size_hint_flags |= YNegative;
3979 else if (TYPE_RANGED_INTEGERP (int, top))
3981 toppos = XINT (top);
3982 if (toppos < 0)
3983 f->size_hint_flags |= YNegative;
3985 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3986 && CONSP (XCDR (top))
3987 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3989 toppos = - XINT (XCAR (XCDR (top)));
3990 f->size_hint_flags |= YNegative;
3992 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3993 && CONSP (XCDR (top))
3994 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3995 toppos = XINT (XCAR (XCDR (top)));
3996 else if (FLOATP (top))
3997 toppos = frame_float (f, top, FRAME_FLOAT_TOP, &parent_done,
3998 &outer_done, 0);
4000 /* Store the numeric value of the position. */
4001 f->top_pos = toppos;
4002 f->left_pos = leftpos;
4004 f->win_gravity = NorthWestGravity;
4006 /* Actually set that position, and convert to absolute. */
4007 x_set_offset (f, leftpos, toppos, -1);
4010 if (fullscreen_change)
4012 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
4014 frame_size_history_add
4015 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
4017 store_frame_param (f, Qfullscreen, fullscreen);
4018 if (!EQ (fullscreen, old_value))
4019 x_set_fullscreen (f, fullscreen, old_value);
4023 #ifdef HAVE_X_WINDOWS
4024 if ((!NILP (icon_left) || !NILP (icon_top))
4025 && ! (icon_left_no_change && icon_top_no_change))
4026 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
4027 #endif /* HAVE_X_WINDOWS */
4029 SAFE_FREE ();
4033 /* Insert a description of internally-recorded parameters of frame X
4034 into the parameter alist *ALISTPTR that is to be given to the user.
4035 Only parameters that are specific to the X window system
4036 and whose values are not correctly recorded in the frame's
4037 param_alist need to be considered here. */
4039 void
4040 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
4042 Lisp_Object tem;
4043 uprintmax_t w;
4044 char buf[INT_BUFSIZE_BOUND (w)];
4046 /* Represent negative positions (off the top or left screen edge)
4047 in a way that Fmodify_frame_parameters will understand correctly. */
4048 XSETINT (tem, f->left_pos);
4049 if (f->left_pos >= 0)
4050 store_in_alist (alistptr, Qleft, tem);
4051 else
4052 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
4054 XSETINT (tem, f->top_pos);
4055 if (f->top_pos >= 0)
4056 store_in_alist (alistptr, Qtop, tem);
4057 else
4058 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
4060 store_in_alist (alistptr, Qborder_width,
4061 make_number (f->border_width));
4062 store_in_alist (alistptr, Qinternal_border_width,
4063 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
4064 store_in_alist (alistptr, Qright_divider_width,
4065 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
4066 store_in_alist (alistptr, Qbottom_divider_width,
4067 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
4068 store_in_alist (alistptr, Qleft_fringe,
4069 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
4070 store_in_alist (alistptr, Qright_fringe,
4071 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
4072 store_in_alist (alistptr, Qscroll_bar_width,
4073 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
4074 ? make_number (0)
4075 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
4076 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
4077 /* nil means "use default width"
4078 for non-toolkit scroll bar.
4079 ruler-mode.el depends on this. */
4080 : Qnil));
4081 store_in_alist (alistptr, Qscroll_bar_height,
4082 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
4083 ? make_number (0)
4084 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
4085 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
4086 /* nil means "use default height"
4087 for non-toolkit scroll bar. */
4088 : Qnil));
4089 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
4090 MS-Windows it returns a value whose type is HANDLE, which is
4091 actually a pointer. Explicit casting avoids compiler
4092 warnings. */
4093 w = (uintptr_t) FRAME_X_WINDOW (f);
4094 store_in_alist (alistptr, Qwindow_id,
4095 make_formatted_string (buf, "%"pMu, w));
4096 #ifdef HAVE_X_WINDOWS
4097 #ifdef USE_X_TOOLKIT
4098 /* Tooltip frame may not have this widget. */
4099 if (FRAME_X_OUTPUT (f)->widget)
4100 #endif
4101 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
4102 store_in_alist (alistptr, Qouter_window_id,
4103 make_formatted_string (buf, "%"pMu, w));
4104 #endif
4105 store_in_alist (alistptr, Qicon_name, f->icon_name);
4106 store_in_alist (alistptr, Qvisibility,
4107 (FRAME_VISIBLE_P (f) ? Qt
4108 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
4109 store_in_alist (alistptr, Qdisplay,
4110 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
4112 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
4113 tem = Qnil;
4114 else
4115 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
4116 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
4117 store_in_alist (alistptr, Qparent_id, tem);
4118 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
4122 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
4123 the previous value of that parameter, NEW_VALUE is the new value. */
4125 void
4126 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4128 if (NILP (new_value))
4129 f->want_fullscreen = FULLSCREEN_NONE;
4130 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
4131 f->want_fullscreen = FULLSCREEN_BOTH;
4132 else if (EQ (new_value, Qfullwidth))
4133 f->want_fullscreen = FULLSCREEN_WIDTH;
4134 else if (EQ (new_value, Qfullheight))
4135 f->want_fullscreen = FULLSCREEN_HEIGHT;
4136 else if (EQ (new_value, Qmaximized))
4137 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
4139 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
4140 FRAME_TERMINAL (f)->fullscreen_hook (f);
4144 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
4145 the previous value of that parameter, NEW_VALUE is the new value. */
4147 void
4148 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4150 if (NILP (new_value))
4151 f->extra_line_spacing = 0;
4152 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
4153 f->extra_line_spacing = XFASTINT (new_value);
4154 else if (FLOATP (new_value))
4156 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
4158 if (new_spacing >= 0)
4159 f->extra_line_spacing = new_spacing;
4160 else
4161 signal_error ("Invalid line-spacing", new_value);
4163 else
4164 signal_error ("Invalid line-spacing", new_value);
4165 if (FRAME_VISIBLE_P (f))
4166 redraw_frame (f);
4170 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
4171 the previous value of that parameter, NEW_VALUE is the new value. */
4173 void
4174 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4176 Lisp_Object bgcolor;
4178 if (NILP (new_value))
4179 f->gamma = 0;
4180 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
4181 /* The value 0.4545 is the normal viewing gamma. */
4182 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
4183 else
4184 signal_error ("Invalid screen-gamma", new_value);
4186 /* Apply the new gamma value to the frame background. */
4187 bgcolor = Fassq (Qbackground_color, f->param_alist);
4188 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
4190 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
4191 if (NATNUMP (parm_index)
4192 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
4193 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
4194 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
4195 (f, bgcolor, Qnil);
4198 clear_face_cache (true); /* FIXME: Why of all frames? */
4199 fset_redisplay (f);
4203 void
4204 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4206 Lisp_Object font_object;
4207 int fontset = -1;
4208 #ifdef HAVE_X_WINDOWS
4209 Lisp_Object font_param = arg;
4210 #endif
4212 /* Set the frame parameter back to the old value because we may
4213 fail to use ARG as the new parameter value. */
4214 store_frame_param (f, Qfont, oldval);
4216 /* ARG is a fontset name, a font name, a cons of fontset name and a
4217 font object, or a font object. In the last case, this function
4218 never fail. */
4219 if (STRINGP (arg))
4221 fontset = fs_query_fontset (arg, 0);
4222 if (fontset < 0)
4224 font_object = font_open_by_name (f, arg);
4225 if (NILP (font_object))
4226 error ("Font `%s' is not defined", SSDATA (arg));
4227 arg = AREF (font_object, FONT_NAME_INDEX);
4229 else if (fontset > 0)
4231 font_object = font_open_by_name (f, fontset_ascii (fontset));
4232 if (NILP (font_object))
4233 error ("Font `%s' is not defined", SDATA (arg));
4234 arg = AREF (font_object, FONT_NAME_INDEX);
4236 else
4237 error ("The default fontset can't be used for a frame font");
4239 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
4241 /* This is the case that the ASCII font of F's fontset XCAR
4242 (arg) is changed to the font XCDR (arg) by
4243 `set-fontset-font'. */
4244 fontset = fs_query_fontset (XCAR (arg), 0);
4245 if (fontset < 0)
4246 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
4247 font_object = XCDR (arg);
4248 arg = AREF (font_object, FONT_NAME_INDEX);
4249 #ifdef HAVE_X_WINDOWS
4250 font_param = Ffont_get (font_object, QCname);
4251 #endif
4253 else if (FONT_OBJECT_P (arg))
4255 font_object = arg;
4256 #ifdef HAVE_X_WINDOWS
4257 font_param = Ffont_get (font_object, QCname);
4258 #endif
4259 /* This is to store the XLFD font name in the frame parameter for
4260 backward compatibility. We should store the font-object
4261 itself in the future. */
4262 arg = AREF (font_object, FONT_NAME_INDEX);
4263 fontset = FRAME_FONTSET (f);
4264 /* Check if we can use the current fontset. If not, set FONTSET
4265 to -1 to generate a new fontset from FONT-OBJECT. */
4266 if (fontset >= 0)
4268 Lisp_Object ascii_font = fontset_ascii (fontset);
4269 Lisp_Object spec = font_spec_from_name (ascii_font);
4271 /* SPEC might be nil because ASCII_FONT's name doesn't parse
4272 according to stupid XLFD rules, which, for example,
4273 disallow font names that include a dash followed by a
4274 number. So in those cases we simply request x_new_font
4275 below to generate a new fontset. */
4276 if (NILP (spec) || ! font_match_p (spec, font_object))
4277 fontset = -1;
4280 else
4281 signal_error ("Invalid font", arg);
4283 if (! NILP (Fequal (font_object, oldval)))
4284 return;
4286 x_new_font (f, font_object, fontset);
4287 store_frame_param (f, Qfont, arg);
4288 #ifdef HAVE_X_WINDOWS
4289 store_frame_param (f, Qfont_parameter, font_param);
4290 #endif
4291 /* Recalculate toolbar height. */
4292 f->n_tool_bar_rows = 0;
4294 /* Ensure we redraw it. */
4295 clear_current_matrices (f);
4297 /* Attempt to hunt down bug#16028. */
4298 SET_FRAME_GARBAGED (f);
4300 /* This is important if we are called by some Lisp as part of
4301 redisplaying the frame, see redisplay_internal. */
4302 f->fonts_changed = true;
4304 recompute_basic_faces (f);
4306 do_pending_window_change (0);
4308 /* We used to call face-set-after-frame-default here, but it leads to
4309 recursive calls (since that function can set the `default' face's
4310 font which in turns changes the frame's `font' parameter).
4311 Also I don't know what this call is meant to do, but it seems the
4312 wrong way to do it anyway (it does a lot more work than what seems
4313 reasonable in response to a change to `font'). */
4317 void
4318 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4320 if (! NILP (new_value)
4321 && !CONSP (new_value))
4323 char *p0, *p1;
4325 CHECK_STRING (new_value);
4326 p0 = p1 = SSDATA (new_value);
4327 new_value = Qnil;
4328 while (*p0)
4330 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
4331 if (p0 < p1)
4332 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
4333 new_value);
4334 if (*p1)
4336 int c;
4338 while ((c = *++p1) && c_isspace (c));
4340 p0 = p1;
4342 new_value = Fnreverse (new_value);
4345 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
4346 return;
4348 if (FRAME_FONT (f))
4349 free_all_realized_faces (Qnil);
4351 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
4352 if (NILP (new_value))
4354 if (NILP (old_value))
4355 error ("No font backend available");
4356 font_update_drivers (f, old_value);
4357 error ("None of specified font backends are available");
4359 store_frame_param (f, Qfont_backend, new_value);
4361 if (FRAME_FONT (f))
4363 Lisp_Object frame;
4365 XSETFRAME (frame, f);
4366 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
4367 face_change = true;
4368 windows_or_buffers_changed = 18;
4372 void
4373 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4375 int unit = FRAME_COLUMN_WIDTH (f);
4376 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
4377 int new_width;
4379 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
4380 ? eabs (XINT (new_value)) : 8);
4382 if (new_width != old_width)
4384 f->left_fringe_width = new_width;
4385 f->fringe_cols /* Round up. */
4386 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
4388 if (FRAME_X_WINDOW (f) != 0)
4389 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
4391 SET_FRAME_GARBAGED (f);
4396 void
4397 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4399 int unit = FRAME_COLUMN_WIDTH (f);
4400 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
4401 int new_width;
4403 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
4404 ? eabs (XINT (new_value)) : 8);
4406 if (new_width != old_width)
4408 f->right_fringe_width = new_width;
4409 f->fringe_cols /* Round up. */
4410 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
4412 if (FRAME_X_WINDOW (f) != 0)
4413 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
4415 SET_FRAME_GARBAGED (f);
4420 void
4421 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4423 CHECK_TYPE_RANGED_INTEGER (int, arg);
4425 if (XINT (arg) == f->border_width)
4426 return;
4428 if (FRAME_X_WINDOW (f) != 0)
4429 error ("Cannot change the border width of a frame");
4431 f->border_width = XINT (arg);
4434 void
4435 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4437 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
4438 CHECK_TYPE_RANGED_INTEGER (int, arg);
4439 int new = max (0, XINT (arg));
4440 if (new != old)
4442 f->right_divider_width = new;
4443 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
4444 adjust_frame_glyphs (f);
4445 SET_FRAME_GARBAGED (f);
4449 void
4450 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4452 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
4453 CHECK_TYPE_RANGED_INTEGER (int, arg);
4454 int new = max (0, XINT (arg));
4455 if (new != old)
4457 f->bottom_divider_width = new;
4458 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
4459 adjust_frame_glyphs (f);
4460 SET_FRAME_GARBAGED (f);
4464 void
4465 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
4467 Lisp_Object frame;
4468 XSETFRAME (frame, f);
4470 if (NILP (value))
4471 Fmake_frame_invisible (frame, Qt);
4472 else if (EQ (value, Qicon))
4473 Ficonify_frame (frame);
4474 else
4475 Fmake_frame_visible (frame);
4478 void
4479 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4481 f->auto_raise = !EQ (Qnil, arg);
4484 void
4485 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4487 f->auto_lower = !EQ (Qnil, arg);
4490 void
4491 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4493 f->no_split = !NILP (arg);
4496 void
4497 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4499 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
4500 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
4501 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
4502 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
4504 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
4505 = (NILP (arg)
4506 ? vertical_scroll_bar_none
4507 : EQ (Qleft, arg)
4508 ? vertical_scroll_bar_left
4509 : EQ (Qright, arg)
4510 ? vertical_scroll_bar_right
4511 : EQ (Qleft, Vdefault_frame_scroll_bars)
4512 ? vertical_scroll_bar_left
4513 : EQ (Qright, Vdefault_frame_scroll_bars)
4514 ? vertical_scroll_bar_right
4515 : vertical_scroll_bar_none);
4517 /* We set this parameter before creating the X window for the
4518 frame, so we can get the geometry right from the start.
4519 However, if the window hasn't been created yet, we shouldn't
4520 call x_set_window_size. */
4521 if (FRAME_X_WINDOW (f))
4522 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
4524 SET_FRAME_GARBAGED (f);
4528 void
4529 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4531 #if USE_HORIZONTAL_SCROLL_BARS
4532 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
4533 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
4535 f->horizontal_scroll_bars = NILP (arg) ? false : true;
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, Qhorizontal_scroll_bars);
4544 SET_FRAME_GARBAGED (f);
4546 #endif
4549 void
4550 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4552 int unit = FRAME_COLUMN_WIDTH (f);
4554 if (NILP (arg))
4556 x_set_scroll_bar_default_width (f);
4558 if (FRAME_X_WINDOW (f))
4559 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
4561 SET_FRAME_GARBAGED (f);
4563 else if (RANGED_INTEGERP (1, arg, INT_MAX)
4564 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
4566 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
4567 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
4568 if (FRAME_X_WINDOW (f))
4569 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
4571 SET_FRAME_GARBAGED (f);
4574 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
4575 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
4578 void
4579 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4581 #if USE_HORIZONTAL_SCROLL_BARS
4582 int unit = FRAME_LINE_HEIGHT (f);
4584 if (NILP (arg))
4586 x_set_scroll_bar_default_height (f);
4588 if (FRAME_X_WINDOW (f))
4589 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
4591 SET_FRAME_GARBAGED (f);
4593 else if (RANGED_INTEGERP (1, arg, INT_MAX)
4594 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
4596 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
4597 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
4598 if (FRAME_X_WINDOW (f))
4599 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
4601 SET_FRAME_GARBAGED (f);
4604 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
4605 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
4606 #endif
4609 void
4610 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4612 double alpha = 1.0;
4613 double newval[2];
4614 int i;
4615 Lisp_Object item;
4617 for (i = 0; i < 2; i++)
4619 newval[i] = 1.0;
4620 if (CONSP (arg))
4622 item = CAR (arg);
4623 arg = CDR (arg);
4625 else
4626 item = arg;
4628 if (NILP (item))
4629 alpha = - 1.0;
4630 else if (FLOATP (item))
4632 alpha = XFLOAT_DATA (item);
4633 if (! (0 <= alpha && alpha <= 1.0))
4634 args_out_of_range (make_float (0.0), make_float (1.0));
4636 else if (INTEGERP (item))
4638 EMACS_INT ialpha = XINT (item);
4639 if (! (0 <= ialpha && ialpha <= 100))
4640 args_out_of_range (make_number (0), make_number (100));
4641 alpha = ialpha / 100.0;
4643 else
4644 wrong_type_argument (Qnumberp, item);
4645 newval[i] = alpha;
4648 for (i = 0; i < 2; i++)
4649 f->alpha[i] = newval[i];
4651 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4652 block_input ();
4653 x_set_frame_alpha (f);
4654 unblock_input ();
4655 #endif
4657 return;
4662 * x_set_no_special_glyphs:
4664 * Set frame F's `no-special-glyphs' parameter which, if non-nil,
4665 * suppresses the display of truncation and continuation glyphs
4666 * outside fringes.
4668 void
4669 x_set_no_special_glyphs (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
4671 if (!EQ (new_value, old_value))
4672 FRAME_NO_SPECIAL_GLYPHS (f) = !NILP (new_value);
4676 #ifndef HAVE_NS
4678 /* Non-zero if mouse is grabbed on DPYINFO
4679 and we know the frame where it is. */
4681 bool x_mouse_grabbed (Display_Info *dpyinfo)
4683 return (dpyinfo->grabbed
4684 && dpyinfo->last_mouse_frame
4685 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4688 /* Re-highlight something with mouse-face properties
4689 on DPYINFO using saved frame and mouse position. */
4691 void
4692 x_redo_mouse_highlight (Display_Info *dpyinfo)
4694 if (dpyinfo->last_mouse_motion_frame
4695 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4696 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4697 dpyinfo->last_mouse_motion_x,
4698 dpyinfo->last_mouse_motion_y);
4701 #endif /* HAVE_NS */
4703 /* Subroutines of creating an X frame. */
4705 /* Make sure that Vx_resource_name is set to a reasonable value.
4706 Fix it up, or set it to `emacs' if it is too hopeless. */
4708 void
4709 validate_x_resource_name (void)
4711 ptrdiff_t len = 0;
4712 /* Number of valid characters in the resource name. */
4713 ptrdiff_t good_count = 0;
4714 /* Number of invalid characters in the resource name. */
4715 ptrdiff_t bad_count = 0;
4716 Lisp_Object new;
4717 ptrdiff_t i;
4719 if (!STRINGP (Vx_resource_class))
4720 Vx_resource_class = build_string (EMACS_CLASS);
4722 if (STRINGP (Vx_resource_name))
4724 unsigned char *p = SDATA (Vx_resource_name);
4726 len = SBYTES (Vx_resource_name);
4728 /* Only letters, digits, - and _ are valid in resource names.
4729 Count the valid characters and count the invalid ones. */
4730 for (i = 0; i < len; i++)
4732 int c = p[i];
4733 if (! ((c >= 'a' && c <= 'z')
4734 || (c >= 'A' && c <= 'Z')
4735 || (c >= '0' && c <= '9')
4736 || c == '-' || c == '_'))
4737 bad_count++;
4738 else
4739 good_count++;
4742 else
4743 /* Not a string => completely invalid. */
4744 bad_count = 5, good_count = 0;
4746 /* If name is valid already, return. */
4747 if (bad_count == 0)
4748 return;
4750 /* If name is entirely invalid, or nearly so, or is so implausibly
4751 large that alloca might not work, use `emacs'. */
4752 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4754 Vx_resource_name = build_string ("emacs");
4755 return;
4758 /* Name is partly valid. Copy it and replace the invalid characters
4759 with underscores. */
4761 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4763 for (i = 0; i < len; i++)
4765 int c = SREF (new, i);
4766 if (! ((c >= 'a' && c <= 'z')
4767 || (c >= 'A' && c <= 'Z')
4768 || (c >= '0' && c <= '9')
4769 || c == '-' || c == '_'))
4770 SSET (new, i, '_');
4774 /* Get specified attribute from resource database RDB.
4775 See Fx_get_resource below for other parameters. */
4777 static Lisp_Object
4778 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4780 CHECK_STRING (attribute);
4781 CHECK_STRING (class);
4783 if (!NILP (component))
4784 CHECK_STRING (component);
4785 if (!NILP (subclass))
4786 CHECK_STRING (subclass);
4787 if (NILP (component) != NILP (subclass))
4788 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4790 validate_x_resource_name ();
4792 /* Allocate space for the components, the dots which separate them,
4793 and the final '\0'. Make them big enough for the worst case. */
4794 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4795 + (STRINGP (component)
4796 ? SBYTES (component) : 0)
4797 + SBYTES (attribute)
4798 + 3);
4800 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4801 + SBYTES (class)
4802 + (STRINGP (subclass)
4803 ? SBYTES (subclass) : 0)
4804 + 3);
4805 USE_SAFE_ALLOCA;
4806 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4807 char *class_key = name_key + name_keysize;
4809 /* Start with emacs.FRAMENAME for the name (the specific one)
4810 and with `Emacs' for the class key (the general one). */
4811 char *nz = lispstpcpy (name_key, Vx_resource_name);
4812 char *cz = lispstpcpy (class_key, Vx_resource_class);
4814 *cz++ = '.';
4815 cz = lispstpcpy (cz, class);
4817 if (!NILP (component))
4819 *cz++ = '.';
4820 lispstpcpy (cz, subclass);
4822 *nz++ = '.';
4823 nz = lispstpcpy (nz, component);
4826 *nz++ = '.';
4827 lispstpcpy (nz, attribute);
4829 char *value = x_get_string_resource (rdb, name_key, class_key);
4830 SAFE_FREE();
4832 if (value && *value)
4833 return build_string (value);
4834 else
4835 return Qnil;
4839 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4840 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4841 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4842 class, where INSTANCE is the name under which Emacs was invoked, or
4843 the name specified by the `-name' or `-rn' command-line arguments.
4845 The optional arguments COMPONENT and SUBCLASS add to the key and the
4846 class, respectively. You must specify both of them or neither.
4847 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4848 and the class is `Emacs.CLASS.SUBCLASS'. */)
4849 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4850 Lisp_Object subclass)
4852 check_window_system (NULL);
4854 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4855 attribute, class, component, subclass);
4858 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4860 Lisp_Object
4861 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4862 Lisp_Object class, Lisp_Object component,
4863 Lisp_Object subclass)
4865 return xrdb_get_resource (dpyinfo->xrdb,
4866 attribute, class, component, subclass);
4869 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4870 /* Used when C code wants a resource value. */
4871 /* Called from oldXMenu/Create.c. */
4872 char *
4873 x_get_resource_string (const char *attribute, const char *class)
4875 char *result;
4876 struct frame *sf = SELECTED_FRAME ();
4877 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4878 USE_SAFE_ALLOCA;
4880 /* Allocate space for the components, the dots which separate them,
4881 and the final '\0'. */
4882 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4883 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4884 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4885 char *class_key = name_key + name_keysize;
4887 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4888 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4890 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4891 name_key, class_key);
4892 SAFE_FREE ();
4893 return result;
4895 #endif
4897 /* Return the value of parameter PARAM.
4899 First search ALIST, then Vdefault_frame_alist, then the X defaults
4900 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4902 Convert the resource to the type specified by desired_type.
4904 If no default is specified, return Qunbound. If you call
4905 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4906 and don't let it get stored in any Lisp-visible variables! */
4908 Lisp_Object
4909 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4910 const char *attribute, const char *class, enum resource_types type)
4912 Lisp_Object tem;
4914 tem = Fassq (param, alist);
4916 if (!NILP (tem))
4918 /* If we find this parm in ALIST, clear it out
4919 so that it won't be "left over" at the end. */
4920 Lisp_Object tail;
4921 XSETCAR (tem, Qnil);
4922 /* In case the parameter appears more than once in the alist,
4923 clear it out. */
4924 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4925 if (CONSP (XCAR (tail))
4926 && EQ (XCAR (XCAR (tail)), param))
4927 XSETCAR (XCAR (tail), Qnil);
4929 else
4930 tem = Fassq (param, Vdefault_frame_alist);
4932 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4933 look in the X resources. */
4934 if (EQ (tem, Qnil))
4936 if (attribute && dpyinfo)
4938 AUTO_STRING (at, attribute);
4939 AUTO_STRING (cl, class);
4940 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4942 if (NILP (tem))
4943 return Qunbound;
4945 switch (type)
4947 case RES_TYPE_NUMBER:
4948 return make_number (atoi (SSDATA (tem)));
4950 case RES_TYPE_BOOLEAN_NUMBER:
4951 if (!strcmp (SSDATA (tem), "on")
4952 || !strcmp (SSDATA (tem), "true"))
4953 return make_number (1);
4954 return make_number (atoi (SSDATA (tem)));
4955 break;
4957 case RES_TYPE_FLOAT:
4958 return make_float (atof (SSDATA (tem)));
4960 case RES_TYPE_BOOLEAN:
4961 tem = Fdowncase (tem);
4962 if (!strcmp (SSDATA (tem), "on")
4963 #ifdef HAVE_NS
4964 || !strcmp (SSDATA (tem), "yes")
4965 #endif
4966 || !strcmp (SSDATA (tem), "true"))
4967 return Qt;
4968 else
4969 return Qnil;
4971 case RES_TYPE_STRING:
4972 return tem;
4974 case RES_TYPE_SYMBOL:
4975 /* As a special case, we map the values `true' and `on'
4976 to Qt, and `false' and `off' to Qnil. */
4978 Lisp_Object lower;
4979 lower = Fdowncase (tem);
4980 if (!strcmp (SSDATA (lower), "on")
4981 #ifdef HAVE_NS
4982 || !strcmp (SSDATA (lower), "yes")
4983 #endif
4984 || !strcmp (SSDATA (lower), "true"))
4985 return Qt;
4986 else if (!strcmp (SSDATA (lower), "off")
4987 #ifdef HAVE_NS
4988 || !strcmp (SSDATA (lower), "no")
4989 #endif
4990 || !strcmp (SSDATA (lower), "false"))
4991 return Qnil;
4992 else
4993 return Fintern (tem, Qnil);
4996 default:
4997 emacs_abort ();
5000 else
5001 return Qunbound;
5003 return Fcdr (tem);
5006 static Lisp_Object
5007 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
5008 const char *attribute, const char *class,
5009 enum resource_types type)
5011 return x_get_arg (FRAME_DISPLAY_INFO (f),
5012 alist, param, attribute, class, type);
5015 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
5017 Lisp_Object
5018 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
5019 Lisp_Object param,
5020 const char *attribute, const char *class,
5021 enum resource_types type)
5023 Lisp_Object value;
5025 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
5026 attribute, class, type);
5027 if (! NILP (value) && ! EQ (value, Qunbound))
5028 store_frame_param (f, param, value);
5030 return value;
5034 /* Record in frame F the specified or default value according to ALIST
5035 of the parameter named PROP (a Lisp symbol).
5036 If no value is specified for PROP, look for an X default for XPROP
5037 on the frame named NAME.
5038 If that is not found either, use the value DEFLT. */
5040 Lisp_Object
5041 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
5042 Lisp_Object deflt, const char *xprop, const char *xclass,
5043 enum resource_types type)
5045 Lisp_Object tem;
5047 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
5048 if (EQ (tem, Qunbound))
5049 tem = deflt;
5050 AUTO_FRAME_ARG (arg, prop, tem);
5051 x_set_frame_parameters (f, arg);
5052 return tem;
5056 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
5059 * XParseGeometry parses strings of the form
5060 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
5061 * width, height, xoffset, and yoffset are unsigned integers.
5062 * Example: "=80x24+300-49"
5063 * The equal sign is optional.
5064 * It returns a bitmask that indicates which of the four values
5065 * were actually found in the string. For each value found,
5066 * the corresponding argument is updated; for each value
5067 * not found, the corresponding argument is left unchanged.
5070 static int
5071 XParseGeometry (char *string,
5072 int *x, int *y,
5073 unsigned int *width, unsigned int *height)
5075 int mask = NoValue;
5076 char *strind;
5077 unsigned long tempWidth UNINIT, tempHeight UNINIT;
5078 long int tempX UNINIT, tempY UNINIT;
5079 char *nextCharacter;
5081 if (string == NULL || *string == '\0')
5082 return mask;
5083 if (*string == '=')
5084 string++; /* ignore possible '=' at beg of geometry spec */
5086 strind = string;
5087 if (*strind != '+' && *strind != '-' && *strind != 'x')
5089 tempWidth = strtoul (strind, &nextCharacter, 10);
5090 if (strind == nextCharacter)
5091 return 0;
5092 strind = nextCharacter;
5093 mask |= WidthValue;
5096 if (*strind == 'x' || *strind == 'X')
5098 strind++;
5099 tempHeight = strtoul (strind, &nextCharacter, 10);
5100 if (strind == nextCharacter)
5101 return 0;
5102 strind = nextCharacter;
5103 mask |= HeightValue;
5106 if (*strind == '+' || *strind == '-')
5108 if (*strind == '-')
5109 mask |= XNegative;
5110 tempX = strtol (strind, &nextCharacter, 10);
5111 if (strind == nextCharacter)
5112 return 0;
5113 strind = nextCharacter;
5114 mask |= XValue;
5115 if (*strind == '+' || *strind == '-')
5117 if (*strind == '-')
5118 mask |= YNegative;
5119 tempY = strtol (strind, &nextCharacter, 10);
5120 if (strind == nextCharacter)
5121 return 0;
5122 strind = nextCharacter;
5123 mask |= YValue;
5127 /* If strind isn't at the end of the string then it's an invalid
5128 geometry specification. */
5130 if (*strind != '\0')
5131 return 0;
5133 if (mask & XValue)
5134 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
5135 if (mask & YValue)
5136 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
5137 if (mask & WidthValue)
5138 *width = min (tempWidth, UINT_MAX);
5139 if (mask & HeightValue)
5140 *height = min (tempHeight, UINT_MAX);
5141 return mask;
5144 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
5147 /* NS used to define x-parse-geometry in ns-win.el, but that confused
5148 make-docfile: the documentation string in ns-win.el was used for
5149 x-parse-geometry even in non-NS builds.
5151 With two definitions of x-parse-geometry in this file, various
5152 things still get confused (eg M-x apropos documentation), so that
5153 it is best if the two definitions just share the same doc-string.
5155 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
5156 doc: /* Parse a display geometry string STRING.
5157 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
5158 The properties returned may include `top', `left', `height', and `width'.
5159 For X, the value of `left' or `top' may be an integer,
5160 or a list (+ N) meaning N pixels relative to top/left corner,
5161 or a list (- N) meaning -N pixels relative to bottom/right corner.
5162 On Nextstep, this just calls `ns-parse-geometry'. */)
5163 (Lisp_Object string)
5165 int geometry, x, y;
5166 unsigned int width, height;
5167 Lisp_Object result;
5169 CHECK_STRING (string);
5171 #ifdef HAVE_NS
5172 if (strchr (SSDATA (string), ' ') != NULL)
5173 return call1 (Qns_parse_geometry, string);
5174 #endif
5175 geometry = XParseGeometry (SSDATA (string),
5176 &x, &y, &width, &height);
5177 result = Qnil;
5178 if (geometry & XValue)
5180 Lisp_Object element;
5182 if (x >= 0 && (geometry & XNegative))
5183 element = list3 (Qleft, Qminus, make_number (-x));
5184 else if (x < 0 && ! (geometry & XNegative))
5185 element = list3 (Qleft, Qplus, make_number (x));
5186 else
5187 element = Fcons (Qleft, make_number (x));
5188 result = Fcons (element, result);
5191 if (geometry & YValue)
5193 Lisp_Object element;
5195 if (y >= 0 && (geometry & YNegative))
5196 element = list3 (Qtop, Qminus, make_number (-y));
5197 else if (y < 0 && ! (geometry & YNegative))
5198 element = list3 (Qtop, Qplus, make_number (y));
5199 else
5200 element = Fcons (Qtop, make_number (y));
5201 result = Fcons (element, result);
5204 if (geometry & WidthValue)
5205 result = Fcons (Fcons (Qwidth, make_number (width)), result);
5206 if (geometry & HeightValue)
5207 result = Fcons (Fcons (Qheight, make_number (height)), result);
5209 return result;
5213 /* Calculate the desired size and position of frame F.
5214 Return the flags saying which aspects were specified.
5216 Also set the win_gravity and size_hint_flags of F.
5218 Adjust height for toolbar if TOOLBAR_P is 1.
5220 This function does not make the coordinates positive. */
5222 #define DEFAULT_ROWS 36
5223 #define DEFAULT_COLS 80
5225 long
5226 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
5228 Lisp_Object height, width, user_size, top, left, user_position;
5229 long window_prompting = 0;
5230 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
5231 int parent_done = -1, outer_done = -1;
5233 /* Default values if we fall through.
5234 Actually, if that happens we should get
5235 window manager prompting. */
5236 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
5237 SET_FRAME_COLS (f, DEFAULT_COLS);
5238 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
5239 SET_FRAME_LINES (f, DEFAULT_ROWS);
5241 /* Window managers expect that if program-specified
5242 positions are not (0,0), they're intentional, not defaults. */
5243 f->top_pos = 0;
5244 f->left_pos = 0;
5246 /* Calculate a tool bar height so that the user gets a text display
5247 area of the size he specified with -g or via .Xdefaults. Later
5248 changes of the tool bar height don't change the frame size. This
5249 is done so that users can create tall Emacs frames without having
5250 to guess how tall the tool bar will get. */
5251 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
5253 if (frame_default_tool_bar_height)
5254 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
5255 else
5257 int margin, relief;
5259 relief = (tool_bar_button_relief >= 0
5260 ? tool_bar_button_relief
5261 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
5263 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
5264 margin = XFASTINT (Vtool_bar_button_margin);
5265 else if (CONSP (Vtool_bar_button_margin)
5266 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
5267 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
5268 else
5269 margin = 0;
5271 FRAME_TOOL_BAR_HEIGHT (f)
5272 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
5276 /* Ensure that earlier new_width and new_height settings won't
5277 override what we specify below. */
5278 f->new_width = f->new_height = 0;
5280 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
5281 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
5282 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
5284 if (!EQ (width, Qunbound))
5286 if (CONSP (width) && EQ (XCAR (width), Qtext_pixels))
5288 CHECK_NUMBER (XCDR (width));
5289 if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX))
5290 xsignal1 (Qargs_out_of_range, XCDR (width));
5292 SET_FRAME_WIDTH (f, XINT (XCDR (width)));
5293 f->inhibit_horizontal_resize = true;
5294 *x_width = XINT (XCDR (width));
5296 else if (FLOATP (width))
5298 double d_width = XFLOAT_DATA (width);
5300 if (d_width < 0.0 || d_width > 1.0)
5301 xsignal1 (Qargs_out_of_range, width);
5302 else
5304 int new_width = frame_float (f, width, FRAME_FLOAT_WIDTH,
5305 &parent_done, &outer_done, -1);
5307 if (new_width > -1)
5308 SET_FRAME_WIDTH (f, new_width);
5311 else
5313 CHECK_NUMBER (width);
5314 if ((XINT (width) < 0 || XINT (width) > INT_MAX))
5315 xsignal1 (Qargs_out_of_range, width);
5317 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
5321 if (!EQ (height, Qunbound))
5323 if (CONSP (height) && EQ (XCAR (height), Qtext_pixels))
5325 CHECK_NUMBER (XCDR (height));
5326 if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX))
5327 xsignal1 (Qargs_out_of_range, XCDR (height));
5329 SET_FRAME_HEIGHT (f, XINT (XCDR (height)));
5330 f->inhibit_vertical_resize = true;
5331 *x_height = XINT (XCDR (height));
5333 else if (FLOATP (height))
5335 double d_height = XFLOAT_DATA (height);
5337 if (d_height < 0.0 || d_height > 1.0)
5338 xsignal1 (Qargs_out_of_range, height);
5339 else
5341 int new_height = frame_float (f, height, FRAME_FLOAT_HEIGHT,
5342 &parent_done, &outer_done, -1);
5344 if (new_height > -1)
5345 SET_FRAME_HEIGHT (f, new_height);
5348 else
5350 CHECK_NUMBER (height);
5351 if ((XINT (height) < 0) || (XINT (height) > INT_MAX))
5352 xsignal1 (Qargs_out_of_range, height);
5354 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
5358 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
5359 if (!NILP (user_size) && !EQ (user_size, Qunbound))
5360 window_prompting |= USSize;
5361 else
5362 window_prompting |= PSize;
5365 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
5366 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
5367 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
5368 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
5370 if (EQ (top, Qminus))
5372 f->top_pos = 0;
5373 window_prompting |= YNegative;
5375 else if (CONSP (top) && EQ (XCAR (top), Qminus)
5376 && CONSP (XCDR (top))
5377 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
5379 f->top_pos = - XINT (XCAR (XCDR (top)));
5380 window_prompting |= YNegative;
5382 else if (CONSP (top) && EQ (XCAR (top), Qplus)
5383 && CONSP (XCDR (top))
5384 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
5386 f->top_pos = XINT (XCAR (XCDR (top)));
5388 else if (FLOATP (top))
5389 f->top_pos = frame_float (f, top, FRAME_FLOAT_TOP, &parent_done,
5390 &outer_done, 0);
5391 else if (EQ (top, Qunbound))
5392 f->top_pos = 0;
5393 else
5395 CHECK_TYPE_RANGED_INTEGER (int, top);
5396 f->top_pos = XINT (top);
5397 if (f->top_pos < 0)
5398 window_prompting |= YNegative;
5401 if (EQ (left, Qminus))
5403 f->left_pos = 0;
5404 window_prompting |= XNegative;
5406 else if (CONSP (left) && EQ (XCAR (left), Qminus)
5407 && CONSP (XCDR (left))
5408 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
5410 f->left_pos = - XINT (XCAR (XCDR (left)));
5411 window_prompting |= XNegative;
5413 else if (CONSP (left) && EQ (XCAR (left), Qplus)
5414 && CONSP (XCDR (left))
5415 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
5417 f->left_pos = XINT (XCAR (XCDR (left)));
5419 else if (FLOATP (left))
5420 f->left_pos = frame_float (f, left, FRAME_FLOAT_LEFT, &parent_done,
5421 &outer_done, 0);
5422 else if (EQ (left, Qunbound))
5423 f->left_pos = 0;
5424 else
5426 CHECK_TYPE_RANGED_INTEGER (int, left);
5427 f->left_pos = XINT (left);
5428 if (f->left_pos < 0)
5429 window_prompting |= XNegative;
5432 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
5433 window_prompting |= USPosition;
5434 else
5435 window_prompting |= PPosition;
5438 if (window_prompting & XNegative)
5440 if (window_prompting & YNegative)
5441 f->win_gravity = SouthEastGravity;
5442 else
5443 f->win_gravity = NorthEastGravity;
5445 else
5447 if (window_prompting & YNegative)
5448 f->win_gravity = SouthWestGravity;
5449 else
5450 f->win_gravity = NorthWestGravity;
5453 f->size_hint_flags = window_prompting;
5455 return window_prompting;
5460 #endif /* HAVE_WINDOW_SYSTEM */
5462 void
5463 frame_make_pointer_invisible (struct frame *f)
5465 if (! NILP (Vmake_pointer_invisible))
5467 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
5468 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
5470 f->mouse_moved = 0;
5471 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
5472 f->pointer_invisible = 1;
5477 void
5478 frame_make_pointer_visible (struct frame *f)
5480 /* We don't check Vmake_pointer_invisible here in case the
5481 pointer was invisible when Vmake_pointer_invisible was set to nil. */
5482 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
5483 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
5485 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
5486 f->pointer_invisible = 0;
5490 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
5491 Sframe_pointer_visible_p, 0, 1, 0,
5492 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
5493 Otherwise it returns nil. FRAME omitted or nil means the
5494 selected frame. This is useful when `make-pointer-invisible' is set. */)
5495 (Lisp_Object frame)
5497 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
5502 /***********************************************************************
5503 Multimonitor data
5504 ***********************************************************************/
5506 #ifdef HAVE_WINDOW_SYSTEM
5508 # if (defined HAVE_NS \
5509 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
5510 void
5511 free_monitors (struct MonitorInfo *monitors, int n_monitors)
5513 int i;
5514 for (i = 0; i < n_monitors; ++i)
5515 xfree (monitors[i].name);
5516 xfree (monitors);
5518 # endif
5520 Lisp_Object
5521 make_monitor_attribute_list (struct MonitorInfo *monitors,
5522 int n_monitors,
5523 int primary_monitor,
5524 Lisp_Object monitor_frames,
5525 const char *source)
5527 Lisp_Object attributes_list = Qnil;
5528 Lisp_Object primary_monitor_attributes = Qnil;
5529 int i;
5531 for (i = 0; i < n_monitors; ++i)
5533 Lisp_Object geometry, workarea, attributes = Qnil;
5534 struct MonitorInfo *mi = &monitors[i];
5536 if (mi->geom.width == 0) continue;
5538 workarea = list4i (mi->work.x, mi->work.y,
5539 mi->work.width, mi->work.height);
5540 geometry = list4i (mi->geom.x, mi->geom.y,
5541 mi->geom.width, mi->geom.height);
5542 attributes = Fcons (Fcons (Qsource, build_string (source)),
5543 attributes);
5544 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
5545 attributes);
5546 attributes = Fcons (Fcons (Qmm_size,
5547 list2i (mi->mm_width, mi->mm_height)),
5548 attributes);
5549 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
5550 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
5551 if (mi->name)
5552 attributes = Fcons (Fcons (Qname, make_string (mi->name,
5553 strlen (mi->name))),
5554 attributes);
5556 if (i == primary_monitor)
5557 primary_monitor_attributes = attributes;
5558 else
5559 attributes_list = Fcons (attributes, attributes_list);
5562 if (!NILP (primary_monitor_attributes))
5563 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
5564 return attributes_list;
5567 #endif /* HAVE_WINDOW_SYSTEM */
5570 /***********************************************************************
5571 Initialization
5572 ***********************************************************************/
5574 void
5575 syms_of_frame (void)
5577 DEFSYM (Qframep, "framep");
5578 DEFSYM (Qframe_live_p, "frame-live-p");
5579 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
5580 DEFSYM (Qdisplay_monitor_attributes_list, "display-monitor-attributes-list");
5581 DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total");
5582 DEFSYM (Qexplicit_name, "explicit-name");
5583 DEFSYM (Qheight, "height");
5584 DEFSYM (Qicon, "icon");
5585 DEFSYM (Qminibuffer, "minibuffer");
5586 DEFSYM (Qundecorated, "undecorated");
5587 DEFSYM (Qno_special_glyphs, "no-special-glyphs");
5588 DEFSYM (Qparent_frame, "parent-frame");
5589 DEFSYM (Qskip_taskbar, "skip-taskbar");
5590 DEFSYM (Qno_focus_on_map, "no-focus-on-map");
5591 DEFSYM (Qno_accept_focus, "no-accept-focus");
5592 DEFSYM (Qz_group, "z-group");
5593 DEFSYM (Qoverride_redirect, "override-redirect");
5594 DEFSYM (Qdelete_before, "delete-before");
5595 DEFSYM (Qmodeline, "modeline");
5596 DEFSYM (Qonly, "only");
5597 DEFSYM (Qnone, "none");
5598 DEFSYM (Qwidth, "width");
5599 DEFSYM (Qtext_pixels, "text-pixels");
5600 DEFSYM (Qgeometry, "geometry");
5601 DEFSYM (Qicon_left, "icon-left");
5602 DEFSYM (Qicon_top, "icon-top");
5603 DEFSYM (Qtooltip, "tooltip");
5604 DEFSYM (Quser_position, "user-position");
5605 DEFSYM (Quser_size, "user-size");
5606 DEFSYM (Qwindow_id, "window-id");
5607 #ifdef HAVE_X_WINDOWS
5608 DEFSYM (Qouter_window_id, "outer-window-id");
5609 #endif
5610 DEFSYM (Qparent_id, "parent-id");
5611 DEFSYM (Qx, "x");
5612 DEFSYM (Qw32, "w32");
5613 DEFSYM (Qpc, "pc");
5614 DEFSYM (Qns, "ns");
5615 DEFSYM (Qvisible, "visible");
5616 DEFSYM (Qbuffer_predicate, "buffer-predicate");
5617 DEFSYM (Qbuffer_list, "buffer-list");
5618 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
5619 DEFSYM (Qdisplay_type, "display-type");
5620 DEFSYM (Qbackground_mode, "background-mode");
5621 DEFSYM (Qnoelisp, "noelisp");
5622 DEFSYM (Qtty_color_mode, "tty-color-mode");
5623 DEFSYM (Qtty, "tty");
5624 DEFSYM (Qtty_type, "tty-type");
5626 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
5628 DEFSYM (Qfullwidth, "fullwidth");
5629 DEFSYM (Qfullheight, "fullheight");
5630 DEFSYM (Qfullboth, "fullboth");
5631 DEFSYM (Qmaximized, "maximized");
5632 DEFSYM (Qx_resource_name, "x-resource-name");
5633 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
5635 DEFSYM (Qworkarea, "workarea");
5636 DEFSYM (Qmm_size, "mm-size");
5637 DEFSYM (Qframes, "frames");
5638 DEFSYM (Qsource, "source");
5640 DEFSYM (Qframe_edges, "frame-edges");
5641 DEFSYM (Qouter_edges, "outer-edges");
5642 DEFSYM (Qouter_position, "outer-position");
5643 DEFSYM (Qouter_size, "outer-size");
5644 DEFSYM (Qnative_edges, "native-edges");
5645 DEFSYM (Qinner_edges, "inner-edges");
5646 DEFSYM (Qexternal_border_size, "external-border-size");
5647 DEFSYM (Qtitle_bar_size, "title-bar-size");
5648 DEFSYM (Qmenu_bar_external, "menu-bar-external");
5649 DEFSYM (Qmenu_bar_size, "menu-bar-size");
5650 DEFSYM (Qtool_bar_external, "tool-bar-external");
5651 DEFSYM (Qtool_bar_size, "tool-bar-size");
5652 /* The following are used for frame_size_history. */
5653 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
5654 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
5655 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
5656 DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
5657 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
5658 DEFSYM (Qset_frame_size, "set-frame-size");
5659 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
5660 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
5661 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
5662 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
5663 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
5664 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
5665 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
5666 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
5667 DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
5668 DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
5669 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
5670 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
5671 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
5672 DEFSYM (Qtb_size_cb, "tb-size-cb");
5673 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
5674 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
5675 DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines");
5676 DEFSYM (Qchange_frame_size, "change-frame-size");
5677 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
5678 DEFSYM (Qset_window_configuration, "set-window-configuration");
5679 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
5680 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
5681 DEFSYM (Qterminal_frame, "terminal-frame");
5683 #ifdef HAVE_NS
5684 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
5685 #endif
5686 #ifdef NS_IMPL_COCOA
5687 DEFSYM (Qns_appearance, "ns-appearance");
5688 DEFSYM (Qns_transparent_titlebar, "ns-transparent-titlebar");
5689 #endif
5691 DEFSYM (Qalpha, "alpha");
5692 DEFSYM (Qauto_lower, "auto-lower");
5693 DEFSYM (Qauto_raise, "auto-raise");
5694 DEFSYM (Qborder_color, "border-color");
5695 DEFSYM (Qborder_width, "border-width");
5696 DEFSYM (Qouter_border_width, "outer-border-width");
5697 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
5698 DEFSYM (Qcursor_color, "cursor-color");
5699 DEFSYM (Qcursor_type, "cursor-type");
5700 DEFSYM (Qfont_backend, "font-backend");
5701 DEFSYM (Qfullscreen, "fullscreen");
5702 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
5703 DEFSYM (Qicon_name, "icon-name");
5704 DEFSYM (Qicon_type, "icon-type");
5705 DEFSYM (Qinternal_border_width, "internal-border-width");
5706 DEFSYM (Qleft_fringe, "left-fringe");
5707 DEFSYM (Qline_spacing, "line-spacing");
5708 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
5709 DEFSYM (Qupdate_frame_menubar, "update-frame-menubar");
5710 DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1");
5711 DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2");
5712 DEFSYM (Qmouse_color, "mouse-color");
5713 DEFSYM (Qname, "name");
5714 DEFSYM (Qright_divider_width, "right-divider-width");
5715 DEFSYM (Qright_fringe, "right-fringe");
5716 DEFSYM (Qscreen_gamma, "screen-gamma");
5717 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
5718 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
5719 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
5720 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
5721 DEFSYM (Qsticky, "sticky");
5722 DEFSYM (Qtitle, "title");
5723 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
5724 DEFSYM (Qtool_bar_position, "tool-bar-position");
5725 DEFSYM (Qunsplittable, "unsplittable");
5726 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
5727 DEFSYM (Qvisibility, "visibility");
5728 DEFSYM (Qwait_for_wm, "wait-for-wm");
5729 DEFSYM (Qinhibit_double_buffering, "inhibit-double-buffering");
5730 DEFSYM (Qno_other_frame, "no-other-frame");
5731 DEFSYM (Qbelow, "below");
5732 DEFSYM (Qabove_suspended, "above-suspended");
5733 DEFSYM (Qmin_width, "min-width");
5734 DEFSYM (Qmin_height, "min-height");
5735 DEFSYM (Qmouse_wheel_frame, "mouse-wheel-frame");
5736 DEFSYM (Qkeep_ratio, "keep-ratio");
5737 DEFSYM (Qwidth_only, "width-only");
5738 DEFSYM (Qheight_only, "height-only");
5739 DEFSYM (Qleft_only, "left-only");
5740 DEFSYM (Qtop_only, "top-only");
5741 DEFSYM (Qiconify_top_level, "iconify-top-level");
5742 DEFSYM (Qmake_invisible, "make-invisible");
5745 int i;
5747 for (i = 0; i < ARRAYELTS (frame_parms); i++)
5749 Lisp_Object v = (frame_parms[i].sym < 0
5750 ? intern_c_string (frame_parms[i].name)
5751 : builtin_lisp_symbol (frame_parms[i].sym));
5752 Fput (v, Qx_frame_parameter, make_number (i));
5756 #ifdef HAVE_WINDOW_SYSTEM
5757 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
5758 doc: /* The name Emacs uses to look up X resources.
5759 `x-get-resource' uses this as the first component of the instance name
5760 when requesting resource values.
5761 Emacs initially sets `x-resource-name' to the name under which Emacs
5762 was invoked, or to the value specified with the `-name' or `-rn'
5763 switches, if present.
5765 It may be useful to bind this variable locally around a call
5766 to `x-get-resource'. See also the variable `x-resource-class'. */);
5767 Vx_resource_name = Qnil;
5769 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5770 doc: /* The class Emacs uses to look up X resources.
5771 `x-get-resource' uses this as the first component of the instance class
5772 when requesting resource values.
5774 Emacs initially sets `x-resource-class' to "Emacs".
5776 Setting this variable permanently is not a reasonable thing to do,
5777 but binding this variable locally around a call to `x-get-resource'
5778 is a reasonable practice. See also the variable `x-resource-name'. */);
5779 Vx_resource_class = build_string (EMACS_CLASS);
5781 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5782 doc: /* The lower limit of the frame opacity (alpha transparency).
5783 The value should range from 0 (invisible) to 100 (completely opaque).
5784 You can also use a floating number between 0.0 and 1.0. */);
5785 Vframe_alpha_lower_limit = make_number (20);
5786 #endif
5788 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5789 doc: /* Alist of default values for frame creation.
5790 These may be set in your init file, like this:
5791 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5792 These override values given in window system configuration data,
5793 including X Windows' defaults database.
5794 For values specific to the first Emacs frame, see `initial-frame-alist'.
5795 For window-system specific values, see `window-system-default-frame-alist'.
5796 For values specific to the separate minibuffer frame, see
5797 `minibuffer-frame-alist'.
5798 The `menu-bar-lines' element of the list controls whether new frames
5799 have menu bars; `menu-bar-mode' works by altering this element.
5800 Setting this variable does not affect existing frames, only new ones. */);
5801 Vdefault_frame_alist = Qnil;
5803 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5804 doc: /* Default position of vertical scroll bars on this window-system. */);
5805 #ifdef HAVE_WINDOW_SYSTEM
5806 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5807 /* MS-Windows, macOS, and GTK have scroll bars on the right by
5808 default. */
5809 Vdefault_frame_scroll_bars = Qright;
5810 #else
5811 Vdefault_frame_scroll_bars = Qleft;
5812 #endif
5813 #else
5814 Vdefault_frame_scroll_bars = Qnil;
5815 #endif
5817 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5818 scroll_bar_adjust_thumb_portion_p,
5819 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5820 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5821 even if the end of the buffer is shown (i.e. overscrolling).
5822 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5823 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5824 is visible. In this case you can not overscroll. */);
5825 scroll_bar_adjust_thumb_portion_p = 1;
5827 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5828 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5830 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5831 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5832 `mouse-position' and `mouse-pixel-position' call this function, passing their
5833 usual return value as argument, and return whatever this function returns.
5834 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5835 which need to do mouse handling at the Lisp level. */);
5836 Vmouse_position_function = Qnil;
5838 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5839 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5840 If the value is an integer, highlighting is only shown after moving the
5841 mouse, while keyboard input turns off the highlight even when the mouse
5842 is over the clickable text. However, the mouse shape still indicates
5843 when the mouse is over clickable text. */);
5844 Vmouse_highlight = Qt;
5846 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5847 doc: /* If non-nil, make pointer invisible while typing.
5848 The pointer becomes visible again when the mouse is moved. */);
5849 Vmake_pointer_invisible = Qt;
5851 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5852 doc: /* Normal hook run when a frame gains input focus.
5853 The frame gaining focus is selected at the time this hook is run. */);
5854 Vfocus_in_hook = Qnil;
5856 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5857 doc: /* Normal hook run when all frames lost input focus. */);
5858 Vfocus_out_hook = Qnil;
5860 DEFVAR_LISP ("move-frame-functions", Vmove_frame_functions,
5861 doc: /* Functions run after a frame was moved.
5862 The functions are run with one arg, the frame that moved. */);
5863 Vmove_frame_functions = Qnil;
5865 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5866 doc: /* Functions run before deleting a frame.
5867 The functions are run with one arg, the frame to be deleted.
5868 See `delete-frame'.
5870 Note that functions in this list may be called just before the frame is
5871 actually deleted, or some time later (or even both when an earlier function
5872 in `delete-frame-functions' (indirectly) calls `delete-frame'
5873 recursively). */);
5874 Vdelete_frame_functions = Qnil;
5875 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5877 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5878 doc: /* Non-nil if Menu-Bar mode is enabled.
5879 See the command `menu-bar-mode' for a description of this minor mode.
5880 Setting this variable directly does not take effect;
5881 either customize it (see the info node `Easy Customization')
5882 or call the function `menu-bar-mode'. */);
5883 Vmenu_bar_mode = Qt;
5885 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5886 doc: /* Non-nil if Tool-Bar mode is enabled.
5887 See the command `tool-bar-mode' for a description of this minor mode.
5888 Setting this variable directly does not take effect;
5889 either customize it (see the info node `Easy Customization')
5890 or call the function `tool-bar-mode'. */);
5891 #ifdef HAVE_WINDOW_SYSTEM
5892 Vtool_bar_mode = Qt;
5893 #else
5894 Vtool_bar_mode = Qnil;
5895 #endif
5897 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5898 doc: /* Minibufferless frames use this frame's minibuffer.
5899 Emacs cannot create minibufferless frames unless this is set to an
5900 appropriate surrogate.
5902 Emacs consults this variable only when creating minibufferless
5903 frames; once the frame is created, it sticks with its assigned
5904 minibuffer, no matter what this variable is set to. This means that
5905 this variable doesn't necessarily say anything meaningful about the
5906 current set of frames, or where the minibuffer is currently being
5907 displayed.
5909 This variable is local to the current terminal and cannot be buffer-local. */);
5911 DEFVAR_LISP ("focus-follows-mouse", focus_follows_mouse,
5912 doc: /* Non-nil if window system changes focus when you move the mouse.
5913 You should set this variable to tell Emacs how your window manager
5914 handles focus, since there is no way in general for Emacs to find out
5915 automatically.
5917 There are three meaningful values:
5919 - The default nil should be used when your window manager follows a
5920 "click-to-focus" policy where you have to click the mouse inside of a
5921 frame in order for that frame to get focus.
5923 - The value t should be used when your window manager has the focus
5924 automatically follow the position of the mouse pointer but a window
5925 that gains focus is not raised automatically.
5927 - The value `auto-raise' should be used when your window manager has the
5928 focus automatically follow the position of the mouse pointer and a
5929 window that gains focus is raised automatically.
5931 If this option is non-nil, Emacs moves the mouse pointer to the frame
5932 selected by `select-frame-set-input-focus'. This function is used by a
5933 number of commands like, for example, `other-frame' and `pop-to-buffer'.
5934 If this option is nil and your focus follows mouse window manager does
5935 not autonomously move the mouse pointer to the newly selected frame, the
5936 previously selected window manager window might get reselected instead
5937 immediately.
5939 The distinction between the values t and `auto-raise' is not needed for
5940 "normal" frames because the window manager takes care of raising them.
5941 Setting this to `auto-raise' will, however, override the standard
5942 behavior of a window manager that does not automatically raise the frame
5943 that gets focus. Setting this to `auto-raise' is also necessary to
5944 automatically raise child frames which are usually left alone by the
5945 window manager.
5947 Note that this option does not distinguish "sloppy" focus (where the
5948 frame that previously had focus retains focus as long as the mouse
5949 pointer does not move into another window manager window) from "strict"
5950 focus (where a frame immediately loses focus when it's left by the mouse
5951 pointer).
5953 In order to extend a "focus follows mouse" policy to individual Emacs
5954 windows, customize the variable `mouse-autoselect-window'. */);
5955 focus_follows_mouse = Qnil;
5957 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5958 doc: /* Non-nil means resize frames pixelwise.
5959 If this option is nil, resizing a frame rounds its sizes to the frame's
5960 current values of `frame-char-height' and `frame-char-width'. If this
5961 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5962 by one pixel.
5964 With some window managers you may have to set this to non-nil in order
5965 to set the size of a frame in pixels, to maximize frames or to make them
5966 fullscreen. To resize your initial frame pixelwise, set this option to
5967 a non-nil value in your init file. */);
5968 frame_resize_pixelwise = 0;
5970 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5971 doc: /* Whether frames should be resized implicitly.
5972 If this option is nil, setting font, menu bar, tool bar, internal
5973 borders, fringes or scroll bars of a specific frame may resize the frame
5974 in order to preserve the number of columns or lines it displays. If
5975 this option is t, no such resizing is done. Note that the size of
5976 fullscreen and maximized frames, the height of fullheight frames and the
5977 width of fullwidth frames never change implicitly.
5979 The value of this option can be also be a list of frame parameters. In
5980 this case, resizing is inhibited when changing a parameter that appears
5981 in that list. The parameters currently handled by this option include
5982 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5983 `tool-bar-lines'.
5985 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5986 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5987 `right-fringe' is handled as if the frame contained just one live
5988 window. This means, for example, that removing vertical scroll bars on
5989 a frame containing several side by side windows will shrink the frame
5990 width by the width of one scroll bar provided this option is nil and
5991 keep it unchanged if this option is either t or a list containing
5992 `vertical-scroll-bars'.
5994 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
5995 \(which means that adding/removing a tool bar does not change the frame
5996 height), nil on all other window systems including GTK+ (which means
5997 that changing any of the parameters listed above may change the size of
5998 the frame), and t otherwise (which means the frame size never changes
5999 implicitly when there's no window system support).
6001 Note that when a frame is not large enough to accommodate a change of
6002 any of the parameters listed above, Emacs may try to enlarge the frame
6003 even if this option is non-nil. */);
6004 #if defined (HAVE_WINDOW_SYSTEM)
6005 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
6006 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
6007 #else
6008 frame_inhibit_implied_resize = Qnil;
6009 #endif
6010 #else
6011 frame_inhibit_implied_resize = Qt;
6012 #endif
6014 DEFVAR_LISP ("frame-size-history", frame_size_history,
6015 doc: /* History of frame size adjustments.
6016 If non-nil, list recording frame size adjustment. Adjustments are
6017 recorded only if the first element of this list is a positive number.
6018 Adding an adjustment decrements that number by one.
6020 The remaining elements are the adjustments. Each adjustment is a list
6021 of four elements `frame', `function', `sizes' and `more'. `frame' is
6022 the affected frame and `function' the invoking function. `sizes' is
6023 usually a list of four elements `old-width', `old-height', `new-width'
6024 and `new-height' representing the old and new sizes recorded/requested
6025 by `function'. `more' is a list with additional information.
6027 The function `frame--size-history' displays the value of this variable
6028 in a more readable form. */);
6029 frame_size_history = Qnil;
6031 DEFVAR_BOOL ("tooltip-reuse-hidden-frame", tooltip_reuse_hidden_frame,
6032 doc: /* Non-nil means reuse hidden tooltip frames.
6033 When this is nil, delete a tooltip frame when hiding the associated
6034 tooltip. When this is non-nil, make the tooltip frame invisible only,
6035 so it can be reused when the next tooltip is shown.
6037 Setting this to non-nil may drastically reduce the consing overhead
6038 incurred by creating new tooltip frames. However, a value of non-nil
6039 means also that intermittent changes of faces or `default-frame-alist'
6040 are not applied when showing a tooltip in a reused frame.
6042 This variable is effective only with the X toolkit (and there only when
6043 Gtk+ tooltips are not used) and on Windows. */);
6044 tooltip_reuse_hidden_frame = false;
6046 DEFVAR_LISP ("iconify-child-frame", iconify_child_frame,
6047 doc: /* How to handle iconification of child frames.
6048 This variable tells Emacs how to proceed when it is asked to iconify a
6049 child frame. If it is nil, `iconify-frame' will do nothing when invoked
6050 on a child frame. If it is `iconify-top-level', Emacs will try to
6051 iconify the top level frame associated with this child frame instead.
6052 If it is `make-invisible', Emacs will try to make this child frame
6053 invisible instead.
6055 Any other value means to try iconifying the child frame. Since such an
6056 attempt is not honored by all window managers and may even lead to
6057 making the child frame unresponsive to user actions, the default is to
6058 iconify the top level frame instead. */);
6059 iconify_child_frame = Qiconify_top_level;
6061 staticpro (&Vframe_list);
6063 defsubr (&Sframep);
6064 defsubr (&Sframe_live_p);
6065 defsubr (&Swindow_system);
6066 defsubr (&Sframe_windows_min_size);
6067 defsubr (&Smake_terminal_frame);
6068 defsubr (&Shandle_switch_frame);
6069 defsubr (&Sselect_frame);
6070 defsubr (&Sselected_frame);
6071 defsubr (&Sframe_list);
6072 defsubr (&Sframe_parent);
6073 defsubr (&Sframe_ancestor_p);
6074 defsubr (&Snext_frame);
6075 defsubr (&Sprevious_frame);
6076 defsubr (&Slast_nonminibuf_frame);
6077 defsubr (&Sdelete_frame);
6078 defsubr (&Smouse_position);
6079 defsubr (&Smouse_pixel_position);
6080 defsubr (&Sset_mouse_position);
6081 defsubr (&Sset_mouse_pixel_position);
6082 #if 0
6083 defsubr (&Sframe_configuration);
6084 defsubr (&Srestore_frame_configuration);
6085 #endif
6086 defsubr (&Smake_frame_visible);
6087 defsubr (&Smake_frame_invisible);
6088 defsubr (&Siconify_frame);
6089 defsubr (&Sframe_visible_p);
6090 defsubr (&Svisible_frame_list);
6091 defsubr (&Sraise_frame);
6092 defsubr (&Slower_frame);
6093 defsubr (&Sx_focus_frame);
6094 defsubr (&Sframe_after_make_frame);
6095 defsubr (&Sredirect_frame_focus);
6096 defsubr (&Sframe_focus);
6097 defsubr (&Sframe_parameters);
6098 defsubr (&Sframe_parameter);
6099 defsubr (&Smodify_frame_parameters);
6100 defsubr (&Sframe_char_height);
6101 defsubr (&Sframe_char_width);
6102 defsubr (&Sframe_native_height);
6103 defsubr (&Sframe_native_width);
6104 defsubr (&Sframe_text_cols);
6105 defsubr (&Sframe_text_lines);
6106 defsubr (&Sframe_total_cols);
6107 defsubr (&Sframe_total_lines);
6108 defsubr (&Sframe_text_width);
6109 defsubr (&Sframe_text_height);
6110 defsubr (&Sscroll_bar_width);
6111 defsubr (&Sscroll_bar_height);
6112 defsubr (&Sfringe_width);
6113 defsubr (&Sframe_internal_border_width);
6114 defsubr (&Sright_divider_width);
6115 defsubr (&Sbottom_divider_width);
6116 defsubr (&Stool_bar_pixel_width);
6117 defsubr (&Sset_frame_height);
6118 defsubr (&Sset_frame_width);
6119 defsubr (&Sset_frame_size);
6120 defsubr (&Sframe_position);
6121 defsubr (&Sset_frame_position);
6122 defsubr (&Sframe_pointer_visible_p);
6124 #ifdef HAVE_WINDOW_SYSTEM
6125 defsubr (&Sx_get_resource);
6126 defsubr (&Sx_parse_geometry);
6127 #endif