Merge from origin/emacs-24
[emacs.git] / src / frame.c
blob2ad1c1b52b706333636889f96526eb13de00718e
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2014 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <errno.h>
24 #include <limits.h>
26 #include <c-ctype.h>
28 #include "lisp.h"
29 #include "character.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 "commands.h"
38 #include "keyboard.h"
39 #include "frame.h"
40 #include "blockinput.h"
41 #include "termchar.h"
42 #include "termhooks.h"
43 #include "dispextern.h"
44 #include "window.h"
45 #include "font.h"
46 #ifdef HAVE_WINDOW_SYSTEM
47 #include "fontset.h"
48 #endif
49 #include "cm.h"
50 #ifdef MSDOS
51 #include "msdos.h"
52 #include "dosfns.h"
53 #endif
54 #ifdef USE_X_TOOLKIT
55 #include "widget.h"
56 #endif
58 #ifdef HAVE_NS
59 Lisp_Object Qns_parse_geometry;
60 #endif
62 Lisp_Object Qframep, Qframe_live_p;
63 Lisp_Object Qicon, Qmodeline;
64 Lisp_Object Qonly, Qnone;
65 Lisp_Object Qx, Qw32, Qpc, Qns;
66 Lisp_Object Qvisible;
67 Lisp_Object Qdisplay_type;
68 static Lisp_Object Qbackground_mode;
69 Lisp_Object Qnoelisp;
71 static Lisp_Object Qx_frame_parameter;
72 Lisp_Object Qx_resource_name;
73 Lisp_Object Qterminal;
75 /* Frame parameters (set or reported). */
77 Lisp_Object Qauto_raise, Qauto_lower;
78 Lisp_Object Qborder_color, Qborder_width;
79 Lisp_Object Qcursor_color, Qcursor_type;
80 Lisp_Object Qheight, Qwidth;
81 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
82 Lisp_Object Qtooltip;
83 Lisp_Object Qinternal_border_width;
84 Lisp_Object Qright_divider_width, Qbottom_divider_width;
85 Lisp_Object Qmouse_color;
86 Lisp_Object Qminibuffer;
87 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
88 Lisp_Object Qscroll_bar_height, Qhorizontal_scroll_bars;
89 Lisp_Object Qvisibility;
90 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
91 Lisp_Object Qscreen_gamma;
92 Lisp_Object Qline_spacing;
93 static Lisp_Object Quser_position, Quser_size;
94 Lisp_Object Qwait_for_wm;
95 static Lisp_Object Qwindow_id;
96 #ifdef HAVE_X_WINDOWS
97 static Lisp_Object Qouter_window_id;
98 #endif
99 Lisp_Object Qparent_id;
100 Lisp_Object Qtitle, Qname;
101 static Lisp_Object Qexplicit_name;
102 Lisp_Object Qunsplittable;
103 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines, Qtool_bar_position;
104 Lisp_Object Qleft_fringe, Qright_fringe;
105 Lisp_Object Qbuffer_predicate;
106 static Lisp_Object Qbuffer_list, Qburied_buffer_list;
107 Lisp_Object Qtty_color_mode;
108 Lisp_Object Qtty, Qtty_type;
110 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth, Qmaximized;
111 Lisp_Object Qsticky;
112 Lisp_Object Qfont_backend;
113 Lisp_Object Qalpha;
115 Lisp_Object Qface_set_after_frame_default;
117 static Lisp_Object Qfocus_in_hook;
118 static Lisp_Object Qfocus_out_hook;
119 static Lisp_Object Qdelete_frame_functions;
120 static Lisp_Object Qframe_windows_min_size;
121 static Lisp_Object Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource;
123 Lisp_Object Qframe_position, Qframe_outer_size, Qframe_inner_size;
124 Lisp_Object Qexternal_border_size, Qtitle_height;
125 Lisp_Object Qmenu_bar_external, Qmenu_bar_size;
126 Lisp_Object Qtool_bar_external, Qtool_bar_size;
128 /* The currently selected frame. */
130 Lisp_Object selected_frame;
132 /* A frame which is not just a mini-buffer, or NULL if there are no such
133 frames. This is usually the most recent such frame that was selected. */
135 static struct frame *last_nonminibuf_frame;
137 /* False means there are no visible garbaged frames. */
138 bool frame_garbaged;
140 #ifdef HAVE_WINDOW_SYSTEM
141 static void x_report_frame_params (struct frame *, Lisp_Object *);
142 #endif
144 /* These setters are used only in this file, so they can be private. */
145 static void
146 fset_buffer_predicate (struct frame *f, Lisp_Object val)
148 f->buffer_predicate = val;
150 static void
151 fset_minibuffer_window (struct frame *f, Lisp_Object val)
153 f->minibuffer_window = val;
156 struct frame *
157 decode_live_frame (register Lisp_Object frame)
159 if (NILP (frame))
160 frame = selected_frame;
161 CHECK_LIVE_FRAME (frame);
162 return XFRAME (frame);
165 struct frame *
166 decode_any_frame (register Lisp_Object frame)
168 if (NILP (frame))
169 frame = selected_frame;
170 CHECK_FRAME (frame);
171 return XFRAME (frame);
174 #ifdef HAVE_WINDOW_SYSTEM
176 bool
177 window_system_available (struct frame *f)
179 return f ? FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f) : x_display_list != NULL;
182 #endif /* HAVE_WINDOW_SYSTEM */
184 struct frame *
185 decode_window_system_frame (Lisp_Object frame)
187 struct frame *f = decode_live_frame (frame);
189 if (!window_system_available (f))
190 error ("Window system frame should be used");
191 return f;
194 void
195 check_window_system (struct frame *f)
197 if (!window_system_available (f))
198 error (f ? "Window system frame should be used"
199 : "Window system is not in use or not initialized");
202 /* Return the value of frame parameter PROP in frame FRAME. */
204 Lisp_Object
205 get_frame_param (register struct frame *frame, Lisp_Object prop)
207 register Lisp_Object tem;
209 tem = Fassq (prop, frame->param_alist);
210 if (EQ (tem, Qnil))
211 return tem;
212 return Fcdr (tem);
215 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
216 state of frame F would be affected by a vertical (horizontal if
217 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
218 parameter that is changed. */
219 bool
220 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
222 return (EQ (frame_inhibit_implied_resize, Qt)
223 || (CONSP (frame_inhibit_implied_resize)
224 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))
225 || !NILP (get_frame_param (f, Qfullscreen))
226 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f));
229 static void
230 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
232 int nlines;
233 int olines = FRAME_MENU_BAR_LINES (f);
235 /* Right now, menu bars don't work properly in minibuf-only frames;
236 most of the commands try to apply themselves to the minibuffer
237 frame itself, and get an error because you can't switch buffers
238 in or split the minibuffer window. */
239 if (FRAME_MINIBUF_ONLY_P (f))
240 return;
242 if (TYPE_RANGED_INTEGERP (int, value))
243 nlines = XINT (value);
244 else
245 nlines = 0;
247 if (nlines != olines)
249 windows_or_buffers_changed = 14;
250 FRAME_MENU_BAR_LINES (f) = nlines;
251 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
252 change_frame_size (f, FRAME_COLS (f),
253 FRAME_LINES (f) + olines - nlines,
254 0, 1, 0, 0);
258 Lisp_Object Vframe_list;
261 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
262 doc: /* Return non-nil if OBJECT is a frame.
263 Value is:
264 t for a termcap frame (a character-only terminal),
265 'x' for an Emacs frame that is really an X window,
266 'w32' for an Emacs frame that is a window on MS-Windows display,
267 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
268 'pc' for a direct-write MS-DOS frame.
269 See also `frame-live-p'. */)
270 (Lisp_Object object)
272 if (!FRAMEP (object))
273 return Qnil;
274 switch (XFRAME (object)->output_method)
276 case output_initial: /* The initial frame is like a termcap frame. */
277 case output_termcap:
278 return Qt;
279 case output_x_window:
280 return Qx;
281 case output_w32:
282 return Qw32;
283 case output_msdos_raw:
284 return Qpc;
285 case output_ns:
286 return Qns;
287 default:
288 emacs_abort ();
292 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
293 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
294 Value is nil if OBJECT is not a live frame. If object is a live
295 frame, the return value indicates what sort of terminal device it is
296 displayed on. See the documentation of `framep' for possible
297 return values. */)
298 (Lisp_Object object)
300 return ((FRAMEP (object)
301 && FRAME_LIVE_P (XFRAME (object)))
302 ? Fframep (object)
303 : Qnil);
306 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
307 doc: /* The name of the window system that FRAME is displaying through.
308 The value is a symbol:
309 nil for a termcap frame (a character-only terminal),
310 'x' for an Emacs frame that is really an X window,
311 'w32' for an Emacs frame that is a window on MS-Windows display,
312 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
313 'pc' for a direct-write MS-DOS frame.
315 FRAME defaults to the currently selected frame.
317 Use of this function as a predicate is deprecated. Instead,
318 use `display-graphic-p' or any of the other `display-*-p'
319 predicates which report frame's specific UI-related capabilities. */)
320 (Lisp_Object frame)
322 Lisp_Object type;
323 if (NILP (frame))
324 frame = selected_frame;
326 type = Fframep (frame);
328 if (NILP (type))
329 wrong_type_argument (Qframep, frame);
331 if (EQ (type, Qt))
332 return Qnil;
333 else
334 return type;
337 static int
338 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal, Lisp_Object ignore, Lisp_Object pixelwise)
340 return XINT (call4 (Qframe_windows_min_size, frame, horizontal, ignore, pixelwise));
344 /* Make sure windows sizes of frame F are OK. new_width and new_height
345 are in pixels. A value of -1 means no change is requested for that
346 size (but the frame may still have to be resized to accommodate
347 windows with their minimum sizes). This can either issue a request
348 to resize the frame externally (via x_set_window_size), to resize the
349 frame internally (via resize_frame_windows) or do nothing at all.
351 The argument INHIBIT can assume the following values:
353 0 means to unconditionally call x_set_window_size even if sizes
354 apparently do not change. Fx_create_frame uses this to pass the
355 initial size to the window manager.
357 1 means to call x_set_window_size if the outer frame size really
358 changes. Fset_frame_size, Fset_frame_height, ... use this.
360 2 means to call x_set_window_size provided frame_inhibit_resize
361 allows it. The menu and tool bar code use this ("3" won't work
362 here in general because menu and tool bar are often not counted in
363 the frame's text height).
365 3 means call x_set_window_size if window minimum sizes must be
366 preserved or frame_inhibit_resize allows it. x_set_left_fringe,
367 x_set_scroll_bar_width, x_new_font ... use (or should use) this.
369 4 means call x_set_window_size only if window minimum sizes must be
370 preserved. x_set_right_divider_width, x_set_border_width and the
371 code responsible for wrapping the tool bar use this.
373 5 means to never call x_set_window_size. change_frame_size uses
374 this.
376 Note that even when x_set_window_size is not called, individual
377 windows may have to be resized (via `window--sanitize-window-sizes')
378 in order to support minimum size constraints.
380 PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the
381 symbol of the parameter changed (like `menu-bar-lines', `font', ...).
382 This is passed on to frame_inhibit_resize to let the latter decide on
383 a case-by-case basis whether the frame may be resized externally. */
384 void
385 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
386 bool pretend, Lisp_Object parameter)
388 int unit_width = FRAME_COLUMN_WIDTH (f);
389 int unit_height = FRAME_LINE_HEIGHT (f);
390 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
391 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
392 int new_pixel_width, new_pixel_height;
393 /* The following two values are calculated from the old frame pixel
394 sizes and any "new" settings for tool bar, menu bar and internal
395 borders. We do it this way to detect whether we have to call
396 x_set_window_size as consequence of the new settings. */
397 int windows_width = FRAME_WINDOWS_WIDTH (f);
398 int windows_height = FRAME_WINDOWS_HEIGHT (f);
399 int min_windows_width, min_windows_height;
400 /* These are a bit tedious, maybe we should use a macro. */
401 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
402 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
403 int old_windows_height
404 = (WINDOW_PIXEL_HEIGHT (r)
405 + (FRAME_HAS_MINIBUF_P (f)
406 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
407 : 0));
408 int new_windows_width, new_windows_height;
409 int old_text_width = FRAME_TEXT_WIDTH (f);
410 int old_text_height = FRAME_TEXT_HEIGHT (f);
411 /* If a size is < 0 use the old value. */
412 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
413 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
414 int new_cols, new_lines;
415 bool inhibit_horizontal, inhibit_vertical;
416 Lisp_Object frame;
418 XSETFRAME (frame, f);
419 /* The following two values are calculated from the old window body
420 sizes and any "new" settings for scroll bars, dividers, fringes and
421 margins (though the latter should have been processed already). */
422 min_windows_width
423 = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qt : Qnil, Qt);
424 min_windows_height
425 = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qt : Qnil, Qt);
427 if (inhibit >= 2 && inhibit <= 4)
428 /* If INHIBIT is in [2..4] inhibit if the "old" window sizes stay
429 within the limits and either frame_inhibit_resize tells us to do
430 so or INHIBIT equals 4. */
432 inhibit_horizontal = ((windows_width >= min_windows_width
433 && (inhibit == 4
434 || frame_inhibit_resize (f, true, parameter)))
435 ? true : false);
436 inhibit_vertical = ((windows_height >= min_windows_height
437 && (inhibit == 4
438 || frame_inhibit_resize (f, false, parameter)))
439 ? true : false);
441 else
442 /* Otherwise inhibit if INHIBIT equals 5. */
443 inhibit_horizontal = inhibit_vertical = inhibit == 5;
445 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
446 ? old_pixel_width
447 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
448 min_windows_width
449 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
450 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
451 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
452 new_cols = new_text_width / unit_width;
454 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
455 ? old_pixel_height
456 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
457 min_windows_height
458 + FRAME_TOP_MARGIN_HEIGHT (f)
459 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
460 new_windows_height = (new_pixel_height
461 - FRAME_TOP_MARGIN_HEIGHT (f)
462 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
463 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
464 new_lines = new_text_height / unit_height;
466 #ifdef HAVE_WINDOW_SYSTEM
467 if (FRAME_WINDOW_P (f)
468 && f->can_x_set_window_size
469 && ((!inhibit_horizontal
470 && (new_pixel_width != old_pixel_width
471 || inhibit == 0 || inhibit == 2))
472 || (!inhibit_vertical
473 && (new_pixel_height != old_pixel_height
474 || inhibit == 0 || inhibit == 2))))
475 /* We are either allowed to change the frame size or the minimum
476 sizes request such a change. Do not care for fixing minimum
477 sizes here, we do that eventually when we're called from
478 change_frame_size. */
480 /* Make sure we respect fullheight and fullwidth. */
481 if (inhibit_horizontal)
482 new_text_width = old_text_width;
483 else if (inhibit_vertical)
484 new_text_height = old_text_height;
486 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
487 f->resized_p = true;
489 return;
491 #endif
493 if (new_text_width == old_text_width
494 && new_text_height == old_text_height
495 && new_windows_width == old_windows_width
496 && new_windows_height == old_windows_height
497 && new_pixel_width == old_pixel_width
498 && new_pixel_height == old_pixel_height)
499 /* No change. Sanitize window sizes and return. */
501 sanitize_window_sizes (frame, Qt);
502 sanitize_window_sizes (frame, Qnil);
504 return;
507 block_input ();
509 #ifdef MSDOS
510 /* We only can set screen dimensions to certain values supported
511 by our video hardware. Try to find the smallest size greater
512 or equal to the requested dimensions. */
513 dos_set_window_size (&new_lines, &new_cols);
514 #endif
516 if (new_windows_width != old_windows_width)
518 resize_frame_windows (f, new_windows_width, 1, 1);
520 /* MSDOS frames cannot PRETEND, as they change frame size by
521 manipulating video hardware. */
522 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
523 FrameCols (FRAME_TTY (f)) = new_cols;
525 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
526 if (WINDOWP (f->tool_bar_window))
528 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
529 XWINDOW (f->tool_bar_window)->total_cols
530 = new_windows_width / unit_width;
532 #endif
535 if (new_windows_height != old_windows_height
536 /* When the top margin has changed we have to recalculate the top
537 edges of all windows. No such calculation is necessary for the
538 left edges. */
539 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
541 resize_frame_windows (f, new_windows_height, 0, 1);
543 /* MSDOS frames cannot PRETEND, as they change frame size by
544 manipulating video hardware. */
545 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
546 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
549 /* Assign new sizes. */
550 FRAME_TEXT_WIDTH (f) = new_text_width;
551 FRAME_TEXT_HEIGHT (f) = new_text_height;
552 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
553 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
554 SET_FRAME_COLS (f, new_cols);
555 SET_FRAME_LINES (f, new_lines);
558 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
559 int text_area_x, text_area_y, text_area_width, text_area_height;
561 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
562 &text_area_height);
563 if (w->cursor.x >= text_area_x + text_area_width)
564 w->cursor.hpos = w->cursor.x = 0;
565 if (w->cursor.y >= text_area_y + text_area_height)
566 w->cursor.vpos = w->cursor.y = 0;
569 /* Sanitize window sizes. */
570 sanitize_window_sizes (frame, Qt);
571 sanitize_window_sizes (frame, Qnil);
573 adjust_frame_glyphs (f);
574 calculate_costs (f);
575 SET_FRAME_GARBAGED (f);
577 /* A frame was "resized" if one of its pixelsizes changed, even if its
578 X window wasn't resized at all. */
579 f->resized_p = (new_pixel_width != old_pixel_width
580 || new_pixel_height != old_pixel_height);
582 unblock_input ();
584 run_window_configuration_change_hook (f);
588 struct frame *
589 make_frame (bool mini_p)
591 Lisp_Object frame;
592 register struct frame *f;
593 register struct window *rw, *mw;
594 register Lisp_Object root_window;
595 register Lisp_Object mini_window;
597 f = allocate_frame ();
598 XSETFRAME (frame, f);
600 #ifdef USE_GTK
601 /* Initialize Lisp data. Note that allocate_frame initializes all
602 Lisp data to nil, so do it only for slots which should not be nil. */
603 fset_tool_bar_position (f, Qtop);
604 #endif
606 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
607 non-Lisp data, so do it only for slots which should not be zero.
608 To avoid subtle bugs and for the sake of readability, it's better to
609 initialize enum members explicitly even if their values are zero. */
610 f->wants_modeline = true;
611 f->redisplay = true;
612 f->garbaged = true;
613 f->can_x_set_window_size = false;
614 f->can_run_window_configuration_change_hook = false;
615 f->column_width = 1; /* !FRAME_WINDOW_P value. */
616 f->line_height = 1; /* !FRAME_WINDOW_P value. */
617 #ifdef HAVE_WINDOW_SYSTEM
618 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
619 f->horizontal_scroll_bars = false;
620 f->want_fullscreen = FULLSCREEN_NONE;
621 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
622 f->last_tool_bar_item = -1;
623 #endif
624 #endif
626 root_window = make_window ();
627 rw = XWINDOW (root_window);
628 if (mini_p)
630 mini_window = make_window ();
631 mw = XWINDOW (mini_window);
632 wset_next (rw, mini_window);
633 wset_prev (mw, root_window);
634 mw->mini = 1;
635 wset_frame (mw, frame);
636 fset_minibuffer_window (f, mini_window);
638 else
640 mini_window = Qnil;
641 wset_next (rw, Qnil);
642 fset_minibuffer_window (f, Qnil);
645 wset_frame (rw, frame);
647 /* 10 is arbitrary,
648 just so that there is "something there."
649 Correct size will be set up later with adjust_frame_size. */
651 SET_FRAME_COLS (f, 10);
652 SET_FRAME_LINES (f, 10);
653 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
654 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
656 rw->total_cols = 10;
657 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
658 rw->total_lines = mini_p ? 9 : 10;
659 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
661 if (mini_p)
663 mw->top_line = rw->total_lines;
664 mw->pixel_top = rw->pixel_height;
665 mw->total_cols = rw->total_cols;
666 mw->pixel_width = rw->pixel_width;
667 mw->total_lines = 1;
668 mw->pixel_height = FRAME_LINE_HEIGHT (f);
671 /* Choose a buffer for the frame's root window. */
673 Lisp_Object buf = Fcurrent_buffer ();
675 /* If current buffer is hidden, try to find another one. */
676 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
677 buf = other_buffer_safely (buf);
679 /* Use set_window_buffer, not Fset_window_buffer, and don't let
680 hooks be run by it. The reason is that the whole frame/window
681 arrangement is not yet fully initialized at this point. Windows
682 don't have the right size, glyph matrices aren't initialized
683 etc. Running Lisp functions at this point surely ends in a
684 SEGV. */
685 set_window_buffer (root_window, buf, 0, 0);
686 fset_buffer_list (f, list1 (buf));
689 if (mini_p)
691 set_window_buffer (mini_window,
692 (NILP (Vminibuffer_list)
693 ? get_minibuffer (0)
694 : Fcar (Vminibuffer_list)),
695 0, 0);
696 /* No horizontal scroll bars in minibuffers. */
697 wset_horizontal_scroll_bar (mw, Qnil);
700 fset_root_window (f, root_window);
701 fset_selected_window (f, root_window);
702 /* Make sure this window seems more recently used than
703 a newly-created, never-selected window. */
704 XWINDOW (f->selected_window)->use_time = ++window_select_count;
706 return f;
709 #ifdef HAVE_WINDOW_SYSTEM
710 /* Make a frame using a separate minibuffer window on another frame.
711 MINI_WINDOW is the minibuffer window to use. nil means use the
712 default (the global minibuffer). */
714 struct frame *
715 make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
717 register struct frame *f;
718 struct gcpro gcpro1;
720 if (!NILP (mini_window))
721 CHECK_LIVE_WINDOW (mini_window);
723 if (!NILP (mini_window)
724 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
725 error ("Frame and minibuffer must be on the same terminal");
727 /* Make a frame containing just a root window. */
728 f = make_frame (0);
730 if (NILP (mini_window))
732 /* Use default-minibuffer-frame if possible. */
733 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
734 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
736 Lisp_Object frame_dummy;
738 XSETFRAME (frame_dummy, f);
739 GCPRO1 (frame_dummy);
740 /* If there's no minibuffer frame to use, create one. */
741 kset_default_minibuffer_frame
742 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
743 UNGCPRO;
746 mini_window
747 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
750 fset_minibuffer_window (f, mini_window);
752 /* Make the chosen minibuffer window display the proper minibuffer,
753 unless it is already showing a minibuffer. */
754 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
755 /* Use set_window_buffer instead of Fset_window_buffer (see
756 discussion of bug#11984, bug#12025, bug#12026). */
757 set_window_buffer (mini_window,
758 (NILP (Vminibuffer_list)
759 ? get_minibuffer (0)
760 : Fcar (Vminibuffer_list)), 0, 0);
761 return f;
764 /* Make a frame containing only a minibuffer window. */
766 struct frame *
767 make_minibuffer_frame (void)
769 /* First make a frame containing just a root window, no minibuffer. */
771 register struct frame *f = make_frame (0);
772 register Lisp_Object mini_window;
773 register Lisp_Object frame;
775 XSETFRAME (frame, f);
777 f->auto_raise = 0;
778 f->auto_lower = 0;
779 f->no_split = 1;
780 f->wants_modeline = 0;
782 /* Now label the root window as also being the minibuffer.
783 Avoid infinite looping on the window chain by marking next pointer
784 as nil. */
786 mini_window = f->root_window;
787 fset_minibuffer_window (f, mini_window);
788 XWINDOW (mini_window)->mini = 1;
789 wset_next (XWINDOW (mini_window), Qnil);
790 wset_prev (XWINDOW (mini_window), Qnil);
791 wset_frame (XWINDOW (mini_window), frame);
793 /* Put the proper buffer in that window. */
795 /* Use set_window_buffer instead of Fset_window_buffer (see
796 discussion of bug#11984, bug#12025, bug#12026). */
797 set_window_buffer (mini_window,
798 (NILP (Vminibuffer_list)
799 ? get_minibuffer (0)
800 : Fcar (Vminibuffer_list)), 0, 0);
801 return f;
803 #endif /* HAVE_WINDOW_SYSTEM */
805 /* Construct a frame that refers to a terminal. */
807 static printmax_t tty_frame_count;
809 struct frame *
810 make_initial_frame (void)
812 struct frame *f;
813 struct terminal *terminal;
814 Lisp_Object frame;
816 eassert (initial_kboard);
818 /* The first call must initialize Vframe_list. */
819 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
820 Vframe_list = Qnil;
822 terminal = init_initial_terminal ();
824 f = make_frame (1);
825 XSETFRAME (frame, f);
827 Vframe_list = Fcons (frame, Vframe_list);
829 tty_frame_count = 1;
830 fset_name (f, build_pure_c_string ("F1"));
832 SET_FRAME_VISIBLE (f, 1);
834 f->output_method = terminal->type;
835 f->terminal = terminal;
836 f->terminal->reference_count++;
837 f->output_data.nothing = 0;
839 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
840 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
842 #ifdef HAVE_WINDOW_SYSTEM
843 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
844 f->horizontal_scroll_bars = false;
845 #endif
847 /* The default value of menu-bar-mode is t. */
848 set_menu_bar_lines (f, make_number (1), Qnil);
850 if (!noninteractive)
851 init_frame_faces (f);
853 last_nonminibuf_frame = f;
855 return f;
859 static struct frame *
860 make_terminal_frame (struct terminal *terminal)
862 register struct frame *f;
863 Lisp_Object frame;
864 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
866 if (!terminal->name)
867 error ("Terminal is not live, can't create new frames on it");
869 f = make_frame (1);
871 XSETFRAME (frame, f);
872 Vframe_list = Fcons (frame, Vframe_list);
874 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
876 SET_FRAME_VISIBLE (f, 1);
878 f->terminal = terminal;
879 f->terminal->reference_count++;
880 #ifdef MSDOS
881 f->output_data.tty->display_info = &the_only_display_info;
882 if (!inhibit_window_system
883 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
884 || XFRAME (selected_frame)->output_method == output_msdos_raw))
885 f->output_method = output_msdos_raw;
886 else
887 f->output_method = output_termcap;
888 #else /* not MSDOS */
889 f->output_method = output_termcap;
890 create_tty_output (f);
891 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
892 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
893 #endif /* not MSDOS */
895 #ifdef HAVE_WINDOW_SYSTEM
896 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
897 f->horizontal_scroll_bars = false;
898 #endif
900 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
901 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
902 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
903 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
905 /* Set the top frame to the newly created frame. */
906 if (FRAMEP (FRAME_TTY (f)->top_frame)
907 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
908 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
910 FRAME_TTY (f)->top_frame = frame;
912 if (!noninteractive)
913 init_frame_faces (f);
915 return f;
918 /* Get a suitable value for frame parameter PARAMETER for a newly
919 created frame, based on (1) the user-supplied frame parameter
920 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
922 static Lisp_Object
923 get_future_frame_param (Lisp_Object parameter,
924 Lisp_Object supplied_parms,
925 char *current_value)
927 Lisp_Object result;
929 result = Fassq (parameter, supplied_parms);
930 if (NILP (result))
931 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
932 if (NILP (result) && current_value != NULL)
933 result = build_string (current_value);
934 if (!NILP (result) && !STRINGP (result))
935 result = XCDR (result);
936 if (NILP (result) || !STRINGP (result))
937 result = Qnil;
939 return result;
942 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
943 1, 1, 0,
944 doc: /* Create an additional terminal frame, possibly on another terminal.
945 This function takes one argument, an alist specifying frame parameters.
947 You can create multiple frames on a single text terminal, but only one
948 of them (the selected terminal frame) is actually displayed.
950 In practice, generally you don't need to specify any parameters,
951 except when you want to create a new frame on another terminal.
952 In that case, the `tty' parameter specifies the device file to open,
953 and the `tty-type' parameter specifies the terminal type. Example:
955 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
957 Note that changing the size of one terminal frame automatically
958 affects all frames on the same terminal device. */)
959 (Lisp_Object parms)
961 struct frame *f;
962 struct terminal *t = NULL;
963 Lisp_Object frame, tem;
964 struct frame *sf = SELECTED_FRAME ();
966 #ifdef MSDOS
967 if (sf->output_method != output_msdos_raw
968 && sf->output_method != output_termcap)
969 emacs_abort ();
970 #else /* not MSDOS */
972 #ifdef WINDOWSNT /* This should work now! */
973 if (sf->output_method != output_termcap)
974 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
975 #endif
976 #endif /* not MSDOS */
979 Lisp_Object terminal;
981 terminal = Fassq (Qterminal, parms);
982 if (CONSP (terminal))
984 terminal = XCDR (terminal);
985 t = decode_live_terminal (terminal);
987 #ifdef MSDOS
988 if (t && t != the_only_display_info.terminal)
989 /* msdos.c assumes a single tty_display_info object. */
990 error ("Multiple terminals are not supported on this platform");
991 if (!t)
992 t = the_only_display_info.terminal;
993 #endif
996 if (!t)
998 char *name = 0, *type = 0;
999 Lisp_Object tty, tty_type;
1000 USE_SAFE_ALLOCA;
1002 tty = get_future_frame_param
1003 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1004 ? FRAME_TTY (XFRAME (selected_frame))->name
1005 : NULL));
1006 if (!NILP (tty))
1007 SAFE_ALLOCA_STRING (name, tty);
1009 tty_type = get_future_frame_param
1010 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1011 ? FRAME_TTY (XFRAME (selected_frame))->type
1012 : NULL));
1013 if (!NILP (tty_type))
1014 SAFE_ALLOCA_STRING (type, tty_type);
1016 t = init_tty (name, type, 0); /* Errors are not fatal. */
1017 SAFE_FREE ();
1020 f = make_terminal_frame (t);
1023 int width, height;
1024 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1025 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f), 5, 0, Qnil);
1028 adjust_frame_glyphs (f);
1029 calculate_costs (f);
1030 XSETFRAME (frame, f);
1032 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1033 store_in_alist (&parms, Qtty,
1034 (t->display_info.tty->name
1035 ? build_string (t->display_info.tty->name)
1036 : Qnil));
1037 Fmodify_frame_parameters (frame, parms);
1039 /* Make the frame face alist be frame-specific, so that each
1040 frame could change its face definitions independently. */
1041 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1042 /* Simple Fcopy_alist isn't enough, because we need the contents of
1043 the vectors which are the CDRs of associations in face_alist to
1044 be copied as well. */
1045 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1046 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1047 return frame;
1051 /* Perform the switch to frame FRAME.
1053 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1054 FRAME1 as frame.
1056 If TRACK is non-zero and the frame that currently has the focus
1057 redirects its focus to the selected frame, redirect that focused
1058 frame's focus to FRAME instead.
1060 FOR_DELETION non-zero means that the selected frame is being
1061 deleted, which includes the possibility that the frame's terminal
1062 is dead.
1064 The value of NORECORD is passed as argument to Fselect_window. */
1066 Lisp_Object
1067 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1069 struct frame *sf = SELECTED_FRAME ();
1071 /* If FRAME is a switch-frame event, extract the frame we should
1072 switch to. */
1073 if (CONSP (frame)
1074 && EQ (XCAR (frame), Qswitch_frame)
1075 && CONSP (XCDR (frame)))
1076 frame = XCAR (XCDR (frame));
1078 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1079 a switch-frame event to arrive after a frame is no longer live,
1080 especially when deleting the initial frame during startup. */
1081 CHECK_FRAME (frame);
1082 if (! FRAME_LIVE_P (XFRAME (frame)))
1083 return Qnil;
1085 if (sf == XFRAME (frame))
1086 return frame;
1088 /* If a frame's focus has been redirected toward the currently
1089 selected frame, we should change the redirection to point to the
1090 newly selected frame. This means that if the focus is redirected
1091 from a minibufferless frame to a surrogate minibuffer frame, we
1092 can use `other-window' to switch between all the frames using
1093 that minibuffer frame, and the focus redirection will follow us
1094 around. */
1095 #if 0
1096 /* This is too greedy; it causes inappropriate focus redirection
1097 that's hard to get rid of. */
1098 if (track)
1100 Lisp_Object tail;
1102 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1104 Lisp_Object focus;
1106 if (!FRAMEP (XCAR (tail)))
1107 emacs_abort ();
1109 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1111 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1112 Fredirect_frame_focus (XCAR (tail), frame);
1115 #else /* ! 0 */
1116 /* Instead, apply it only to the frame we're pointing to. */
1117 #ifdef HAVE_WINDOW_SYSTEM
1118 if (track && FRAME_WINDOW_P (XFRAME (frame)))
1120 Lisp_Object focus, xfocus;
1122 xfocus = x_get_focus_frame (XFRAME (frame));
1123 if (FRAMEP (xfocus))
1125 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1126 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1127 Fredirect_frame_focus (xfocus, frame);
1130 #endif /* HAVE_X_WINDOWS */
1131 #endif /* ! 0 */
1133 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1134 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1136 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
1138 struct frame *f = XFRAME (frame);
1139 struct tty_display_info *tty = FRAME_TTY (f);
1140 Lisp_Object top_frame = tty->top_frame;
1142 /* Don't mark the frame garbaged and/or obscured if we are
1143 switching to the frame that is already the top frame of that
1144 TTY. */
1145 if (!EQ (frame, top_frame))
1147 if (FRAMEP (top_frame))
1148 /* Mark previously displayed frame as now obscured. */
1149 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1150 SET_FRAME_VISIBLE (f, 1);
1151 /* If the new TTY frame changed dimensions, we need to
1152 resync term.c's idea of the frame size with the new
1153 frame's data. */
1154 if (FRAME_COLS (f) != FrameCols (tty))
1155 FrameCols (tty) = FRAME_COLS (f);
1156 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1157 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1159 tty->top_frame = frame;
1162 selected_frame = frame;
1163 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1164 last_nonminibuf_frame = XFRAME (selected_frame);
1166 Fselect_window (XFRAME (frame)->selected_window, norecord);
1168 /* We want to make sure that the next event generates a frame-switch
1169 event to the appropriate frame. This seems kludgy to me, but
1170 before you take it out, make sure that evaluating something like
1171 (select-window (frame-root-window (new-frame))) doesn't end up
1172 with your typing being interpreted in the new frame instead of
1173 the one you're actually typing in. */
1174 internal_last_event_frame = Qnil;
1176 return frame;
1179 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1180 doc: /* Select FRAME.
1181 Subsequent editing commands apply to its selected window.
1182 Optional argument NORECORD means to neither change the order of
1183 recently selected windows nor the buffer list.
1185 The selection of FRAME lasts until the next time the user does
1186 something to select a different frame, or until the next time
1187 this function is called. If you are using a window system, the
1188 previously selected frame may be restored as the selected frame
1189 when returning to the command loop, because it still may have
1190 the window system's input focus. On a text terminal, the next
1191 redisplay will display FRAME.
1193 This function returns FRAME, or nil if FRAME has been deleted. */)
1194 (Lisp_Object frame, Lisp_Object norecord)
1196 return do_switch_frame (frame, 1, 0, norecord);
1199 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1200 doc: /* Handle a switch-frame event EVENT.
1201 Switch-frame events are usually bound to this function.
1202 A switch-frame event tells Emacs that the window manager has requested
1203 that the user's events be directed to the frame mentioned in the event.
1204 This function selects the selected window of the frame of EVENT.
1206 If EVENT is frame object, handle it as if it were a switch-frame event
1207 to that frame. */)
1208 (Lisp_Object event)
1210 /* Preserve prefix arg that the command loop just cleared. */
1211 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1212 Frun_hooks (1, &Qmouse_leave_buffer_hook);
1213 /* `switch-frame' implies a focus in. */
1214 call1 (intern ("handle-focus-in"), event);
1215 return do_switch_frame (event, 0, 0, Qnil);
1218 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1219 doc: /* Return the frame that is now selected. */)
1220 (void)
1222 return selected_frame;
1225 DEFUN ("frame-list", Fframe_list, Sframe_list,
1226 0, 0, 0,
1227 doc: /* Return a list of all live frames. */)
1228 (void)
1230 Lisp_Object frames;
1231 frames = Fcopy_sequence (Vframe_list);
1232 #ifdef HAVE_WINDOW_SYSTEM
1233 if (FRAMEP (tip_frame))
1234 frames = Fdelq (tip_frame, frames);
1235 #endif
1236 return frames;
1239 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1240 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1241 If MINIBUF is nil, do not consider minibuffer-only candidate.
1242 If MINIBUF is `visible', do not consider an invisible candidate.
1243 If MINIBUF is a window, consider only its own frame and candidate now
1244 using that window as the minibuffer.
1245 If MINIBUF is 0, consider candidate if it is visible or iconified.
1246 Otherwise consider any candidate and return nil if CANDIDATE is not
1247 acceptable. */
1249 static Lisp_Object
1250 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1252 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1254 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1255 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1256 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1257 && FRAME_TTY (c) == FRAME_TTY (f)))
1259 if (NILP (minibuf))
1261 if (!FRAME_MINIBUF_ONLY_P (c))
1262 return candidate;
1264 else if (EQ (minibuf, Qvisible))
1266 if (FRAME_VISIBLE_P (c))
1267 return candidate;
1269 else if (WINDOWP (minibuf))
1271 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1272 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1273 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1274 FRAME_FOCUS_FRAME (c)))
1275 return candidate;
1277 else if (XFASTINT (minibuf) == 0)
1279 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1280 return candidate;
1282 else
1283 return candidate;
1285 return Qnil;
1288 /* Return the next frame in the frame list after FRAME. */
1290 static Lisp_Object
1291 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1293 Lisp_Object f, tail;
1294 int passed = 0;
1296 /* There must always be at least one frame in Vframe_list. */
1297 eassert (CONSP (Vframe_list));
1299 while (passed < 2)
1300 FOR_EACH_FRAME (tail, f)
1302 if (passed)
1304 f = candidate_frame (f, frame, minibuf);
1305 if (!NILP (f))
1306 return f;
1308 if (EQ (frame, f))
1309 passed++;
1311 return frame;
1314 /* Return the previous frame in the frame list before FRAME. */
1316 static Lisp_Object
1317 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1319 Lisp_Object f, tail, prev = Qnil;
1321 /* There must always be at least one frame in Vframe_list. */
1322 eassert (CONSP (Vframe_list));
1324 FOR_EACH_FRAME (tail, f)
1326 if (EQ (frame, f) && !NILP (prev))
1327 return prev;
1328 f = candidate_frame (f, frame, minibuf);
1329 if (!NILP (f))
1330 prev = f;
1333 /* We've scanned the entire list. */
1334 if (NILP (prev))
1335 /* We went through the whole frame list without finding a single
1336 acceptable frame. Return the original frame. */
1337 return frame;
1338 else
1339 /* There were no acceptable frames in the list before FRAME; otherwise,
1340 we would have returned directly from the loop. Since PREV is the last
1341 acceptable frame in the list, return it. */
1342 return prev;
1346 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1347 doc: /* Return the next frame in the frame list after FRAME.
1348 It considers only frames on the same terminal as FRAME.
1349 By default, skip minibuffer-only frames.
1350 If omitted, FRAME defaults to the selected frame.
1351 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1352 If MINIFRAME is a window, include only its own frame
1353 and any frame now using that window as the minibuffer.
1354 If MINIFRAME is `visible', include all visible frames.
1355 If MINIFRAME is 0, include all visible and iconified frames.
1356 Otherwise, include all frames. */)
1357 (Lisp_Object frame, Lisp_Object miniframe)
1359 if (NILP (frame))
1360 frame = selected_frame;
1361 CHECK_LIVE_FRAME (frame);
1362 return next_frame (frame, miniframe);
1365 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1366 doc: /* Return the previous frame in the frame list before FRAME.
1367 It considers only frames on the same terminal as FRAME.
1368 By default, skip minibuffer-only frames.
1369 If omitted, FRAME defaults to the selected frame.
1370 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1371 If MINIFRAME is a window, include only its own frame
1372 and any frame now using that window as the minibuffer.
1373 If MINIFRAME is `visible', include all visible frames.
1374 If MINIFRAME is 0, include all visible and iconified frames.
1375 Otherwise, include all frames. */)
1376 (Lisp_Object frame, Lisp_Object miniframe)
1378 if (NILP (frame))
1379 frame = selected_frame;
1380 CHECK_LIVE_FRAME (frame);
1381 return prev_frame (frame, miniframe);
1384 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1385 Slast_nonminibuf_frame, 0, 0, 0,
1386 doc: /* Return last non-minibuffer frame selected. */)
1387 (void)
1389 Lisp_Object frame = Qnil;
1391 if (last_nonminibuf_frame)
1392 XSETFRAME (frame, last_nonminibuf_frame);
1394 return frame;
1397 /* Return 1 if it is ok to delete frame F;
1398 0 if all frames aside from F are invisible.
1399 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1401 static int
1402 other_visible_frames (struct frame *f)
1404 Lisp_Object frames, this;
1406 FOR_EACH_FRAME (frames, this)
1408 if (f == XFRAME (this))
1409 continue;
1411 /* Verify that we can still talk to the frame's X window,
1412 and note any recent change in visibility. */
1413 #ifdef HAVE_X_WINDOWS
1414 if (FRAME_WINDOW_P (XFRAME (this)))
1415 x_sync (XFRAME (this));
1416 #endif
1418 if (FRAME_VISIBLE_P (XFRAME (this))
1419 || FRAME_ICONIFIED_P (XFRAME (this))
1420 /* Allow deleting the terminal frame when at least one X
1421 frame exists. */
1422 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1423 return 1;
1425 return 0;
1428 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1429 window. Preferably use the selected frame's minibuffer window
1430 instead. If the selected frame doesn't have one, get some other
1431 frame's minibuffer window. SELECT non-zero means select the new
1432 minibuffer window. */
1433 static void
1434 check_minibuf_window (Lisp_Object frame, int select)
1436 struct frame *f = decode_live_frame (frame);
1438 XSETFRAME (frame, f);
1440 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1442 Lisp_Object frames, this, window = make_number (0);
1444 if (!EQ (frame, selected_frame)
1445 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1446 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1447 else
1448 FOR_EACH_FRAME (frames, this)
1450 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1452 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1453 break;
1457 /* Don't abort if no window was found (Bug#15247). */
1458 if (WINDOWP (window))
1460 /* Use set_window_buffer instead of Fset_window_buffer (see
1461 discussion of bug#11984, bug#12025, bug#12026). */
1462 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1463 minibuf_window = window;
1465 /* SELECT non-zero usually means that FRAME's minibuffer
1466 window was selected; select the new one. */
1467 if (select)
1468 Fselect_window (minibuf_window, Qnil);
1474 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1475 unconditionally. x_connection_closed and delete_terminal use
1476 this. Any other value of FORCE implements the semantics
1477 described for Fdelete_frame. */
1478 Lisp_Object
1479 delete_frame (Lisp_Object frame, Lisp_Object force)
1481 struct frame *f = decode_any_frame (frame);
1482 struct frame *sf;
1483 struct kboard *kb;
1485 int minibuffer_selected, is_tooltip_frame;
1487 if (! FRAME_LIVE_P (f))
1488 return Qnil;
1490 if (NILP (force) && !other_visible_frames (f))
1491 error ("Attempt to delete the sole visible or iconified frame");
1493 /* x_connection_closed must have set FORCE to `noelisp' in order
1494 to delete the last frame, if it is gone. */
1495 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1496 error ("Attempt to delete the only frame");
1498 XSETFRAME (frame, f);
1500 /* Does this frame have a minibuffer, and is it the surrogate
1501 minibuffer for any other frame? */
1502 if (FRAME_HAS_MINIBUF_P (f))
1504 Lisp_Object frames, this;
1506 FOR_EACH_FRAME (frames, this)
1508 Lisp_Object fminiw;
1510 if (EQ (this, frame))
1511 continue;
1513 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1515 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1517 /* If we MUST delete this frame, delete the other first.
1518 But do this only if FORCE equals `noelisp'. */
1519 if (EQ (force, Qnoelisp))
1520 delete_frame (this, Qnoelisp);
1521 else
1522 error ("Attempt to delete a surrogate minibuffer frame");
1527 is_tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1529 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1530 frame is a tooltip. FORCE is set to `noelisp' when handling
1531 a disconnect from the terminal, so we don't dare call Lisp
1532 code. */
1533 if (NILP (Vrun_hooks) || is_tooltip_frame)
1535 else if (EQ (force, Qnoelisp))
1536 pending_funcalls
1537 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1538 pending_funcalls);
1539 else
1541 #ifdef HAVE_X_WINDOWS
1542 /* Also, save clipboard to the clipboard manager. */
1543 x_clipboard_manager_save_frame (frame);
1544 #endif
1546 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1549 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1550 if (! FRAME_LIVE_P (f))
1551 return Qnil;
1553 /* At this point, we are committed to deleting the frame.
1554 There is no more chance for errors to prevent it. */
1556 minibuffer_selected = EQ (minibuf_window, selected_window);
1557 sf = SELECTED_FRAME ();
1558 /* Don't let the frame remain selected. */
1559 if (f == sf)
1561 Lisp_Object tail;
1562 Lisp_Object frame1 = Qnil;
1564 /* Look for another visible frame on the same terminal.
1565 Do not call next_frame here because it may loop forever.
1566 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1567 FOR_EACH_FRAME (tail, frame1)
1568 if (!EQ (frame, frame1)
1569 && (FRAME_TERMINAL (XFRAME (frame))
1570 == FRAME_TERMINAL (XFRAME (frame1)))
1571 && FRAME_VISIBLE_P (XFRAME (frame1)))
1572 break;
1574 /* If there is none, find *some* other frame. */
1575 if (NILP (frame1) || EQ (frame1, frame))
1577 FOR_EACH_FRAME (tail, frame1)
1579 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1581 /* Do not change a text terminal's top-frame. */
1582 struct frame *f1 = XFRAME (frame1);
1583 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1585 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1586 if (!EQ (top_frame, frame))
1587 frame1 = top_frame;
1589 break;
1593 #ifdef NS_IMPL_COCOA
1594 else
1595 /* Under NS, there is no system mechanism for choosing a new
1596 window to get focus -- it is left to application code.
1597 So the portion of THIS application interfacing with NS
1598 needs to know about it. We call Fraise_frame, but the
1599 purpose is really to transfer focus. */
1600 Fraise_frame (frame1);
1601 #endif
1603 do_switch_frame (frame1, 0, 1, Qnil);
1604 sf = SELECTED_FRAME ();
1607 /* Don't allow minibuf_window to remain on a deleted frame. */
1608 check_minibuf_window (frame, minibuffer_selected);
1610 /* Don't let echo_area_window to remain on a deleted frame. */
1611 if (EQ (f->minibuffer_window, echo_area_window))
1612 echo_area_window = sf->minibuffer_window;
1614 /* Clear any X selections for this frame. */
1615 #ifdef HAVE_X_WINDOWS
1616 if (FRAME_X_P (f))
1617 x_clear_frame_selections (f);
1618 #endif
1620 /* Free glyphs.
1621 This function must be called before the window tree of the
1622 frame is deleted because windows contain dynamically allocated
1623 memory. */
1624 free_glyphs (f);
1626 #ifdef HAVE_WINDOW_SYSTEM
1627 /* Give chance to each font driver to free a frame specific data. */
1628 font_update_drivers (f, Qnil);
1629 #endif
1631 /* Mark all the windows that used to be on FRAME as deleted, and then
1632 remove the reference to them. */
1633 delete_all_child_windows (f->root_window);
1634 fset_root_window (f, Qnil);
1636 Vframe_list = Fdelq (frame, Vframe_list);
1637 SET_FRAME_VISIBLE (f, 0);
1639 /* Allow the vector of menu bar contents to be freed in the next
1640 garbage collection. The frame object itself may not be garbage
1641 collected until much later, because recent_keys and other data
1642 structures can still refer to it. */
1643 fset_menu_bar_vector (f, Qnil);
1645 /* If FRAME's buffer lists contains killed
1646 buffers, this helps GC to reclaim them. */
1647 fset_buffer_list (f, Qnil);
1648 fset_buried_buffer_list (f, Qnil);
1650 free_font_driver_list (f);
1651 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1652 xfree (f->namebuf);
1653 #endif
1654 xfree (f->decode_mode_spec_buffer);
1655 xfree (FRAME_INSERT_COST (f));
1656 xfree (FRAME_DELETEN_COST (f));
1657 xfree (FRAME_INSERTN_COST (f));
1658 xfree (FRAME_DELETE_COST (f));
1660 /* Since some events are handled at the interrupt level, we may get
1661 an event for f at any time; if we zero out the frame's terminal
1662 now, then we may trip up the event-handling code. Instead, we'll
1663 promise that the terminal of the frame must be valid until we
1664 have called the window-system-dependent frame destruction
1665 routine. */
1669 struct terminal *terminal;
1670 block_input ();
1671 if (FRAME_TERMINAL (f)->delete_frame_hook)
1672 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1673 terminal = FRAME_TERMINAL (f);
1674 f->output_data.nothing = 0;
1675 f->terminal = 0; /* Now the frame is dead. */
1676 unblock_input ();
1678 /* If needed, delete the terminal that this frame was on.
1679 (This must be done after the frame is killed.) */
1680 terminal->reference_count--;
1681 #ifdef USE_GTK
1682 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1683 bug.
1684 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1685 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1686 terminal->reference_count = 1;
1687 #endif /* USE_GTK */
1688 if (terminal->reference_count == 0)
1690 Lisp_Object tmp;
1691 XSETTERMINAL (tmp, terminal);
1693 kb = NULL;
1694 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1696 else
1697 kb = terminal->kboard;
1700 /* If we've deleted the last_nonminibuf_frame, then try to find
1701 another one. */
1702 if (f == last_nonminibuf_frame)
1704 Lisp_Object frames, this;
1706 last_nonminibuf_frame = 0;
1708 FOR_EACH_FRAME (frames, this)
1710 f = XFRAME (this);
1711 if (!FRAME_MINIBUF_ONLY_P (f))
1713 last_nonminibuf_frame = f;
1714 break;
1719 /* If there's no other frame on the same kboard, get out of
1720 single-kboard state if we're in it for this kboard. */
1721 if (kb != NULL)
1723 Lisp_Object frames, this;
1724 /* Some frame we found on the same kboard, or nil if there are none. */
1725 Lisp_Object frame_on_same_kboard = Qnil;
1727 FOR_EACH_FRAME (frames, this)
1728 if (kb == FRAME_KBOARD (XFRAME (this)))
1729 frame_on_same_kboard = this;
1731 if (NILP (frame_on_same_kboard))
1732 not_single_kboard_state (kb);
1736 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1737 find another one. Prefer minibuffer-only frames, but also notice
1738 frames with other windows. */
1739 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1741 Lisp_Object frames, this;
1743 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1744 Lisp_Object frame_with_minibuf = Qnil;
1745 /* Some frame we found on the same kboard, or nil if there are none. */
1746 Lisp_Object frame_on_same_kboard = Qnil;
1748 FOR_EACH_FRAME (frames, this)
1750 struct frame *f1 = XFRAME (this);
1752 /* Consider only frames on the same kboard
1753 and only those with minibuffers. */
1754 if (kb == FRAME_KBOARD (f1)
1755 && FRAME_HAS_MINIBUF_P (f1))
1757 frame_with_minibuf = this;
1758 if (FRAME_MINIBUF_ONLY_P (f1))
1759 break;
1762 if (kb == FRAME_KBOARD (f1))
1763 frame_on_same_kboard = this;
1766 if (!NILP (frame_on_same_kboard))
1768 /* We know that there must be some frame with a minibuffer out
1769 there. If this were not true, all of the frames present
1770 would have to be minibufferless, which implies that at some
1771 point their minibuffer frames must have been deleted, but
1772 that is prohibited at the top; you can't delete surrogate
1773 minibuffer frames. */
1774 if (NILP (frame_with_minibuf))
1775 emacs_abort ();
1777 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1779 else
1780 /* No frames left on this kboard--say no minibuffer either. */
1781 kset_default_minibuffer_frame (kb, Qnil);
1784 /* Cause frame titles to update--necessary if we now have just one frame. */
1785 if (!is_tooltip_frame)
1786 update_mode_lines = 15;
1788 return Qnil;
1791 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1792 doc: /* Delete FRAME, permanently eliminating it from use.
1793 FRAME defaults to the selected frame.
1795 A frame may not be deleted if its minibuffer is used by other frames.
1796 Normally, you may not delete a frame if all other frames are invisible,
1797 but if the second optional argument FORCE is non-nil, you may do so.
1799 This function runs `delete-frame-functions' before actually
1800 deleting the frame, unless the frame is a tooltip.
1801 The functions are run with one argument, the frame to be deleted. */)
1802 (Lisp_Object frame, Lisp_Object force)
1804 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1808 /* Return mouse position in character cell units. */
1810 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1811 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1812 The position is given in canonical character cells, where (0, 0) is the
1813 upper-left corner of the frame, X is the horizontal offset, and Y is the
1814 vertical offset, measured in units of the frame's default character size.
1815 If Emacs is running on a mouseless terminal or hasn't been programmed
1816 to read the mouse position, it returns the selected frame for FRAME
1817 and nil for X and Y.
1818 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1819 passing the normal return value to that function as an argument,
1820 and returns whatever that function returns. */)
1821 (void)
1823 struct frame *f;
1824 Lisp_Object lispy_dummy;
1825 Lisp_Object x, y, retval;
1826 struct gcpro gcpro1;
1828 f = SELECTED_FRAME ();
1829 x = y = Qnil;
1831 /* It's okay for the hook to refrain from storing anything. */
1832 if (FRAME_TERMINAL (f)->mouse_position_hook)
1834 enum scroll_bar_part party_dummy;
1835 Time time_dummy;
1836 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1837 &lispy_dummy, &party_dummy,
1838 &x, &y,
1839 &time_dummy);
1842 if (! NILP (x))
1844 int col = XINT (x);
1845 int row = XINT (y);
1846 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1847 XSETINT (x, col);
1848 XSETINT (y, row);
1850 XSETFRAME (lispy_dummy, f);
1851 retval = Fcons (lispy_dummy, Fcons (x, y));
1852 GCPRO1 (retval);
1853 if (!NILP (Vmouse_position_function))
1854 retval = call1 (Vmouse_position_function, retval);
1855 RETURN_UNGCPRO (retval);
1858 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1859 Smouse_pixel_position, 0, 0, 0,
1860 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1861 The position is given in pixel units, where (0, 0) is the
1862 upper-left corner of the frame, X is the horizontal offset, and Y is
1863 the vertical offset.
1864 If Emacs is running on a mouseless terminal or hasn't been programmed
1865 to read the mouse position, it returns the selected frame for FRAME
1866 and nil for X and Y. */)
1867 (void)
1869 struct frame *f;
1870 Lisp_Object lispy_dummy;
1871 Lisp_Object x, y, retval;
1872 struct gcpro gcpro1;
1874 f = SELECTED_FRAME ();
1875 x = y = Qnil;
1877 /* It's okay for the hook to refrain from storing anything. */
1878 if (FRAME_TERMINAL (f)->mouse_position_hook)
1880 enum scroll_bar_part party_dummy;
1881 Time time_dummy;
1882 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1883 &lispy_dummy, &party_dummy,
1884 &x, &y,
1885 &time_dummy);
1888 XSETFRAME (lispy_dummy, f);
1889 retval = Fcons (lispy_dummy, Fcons (x, y));
1890 GCPRO1 (retval);
1891 if (!NILP (Vmouse_position_function))
1892 retval = call1 (Vmouse_position_function, retval);
1893 RETURN_UNGCPRO (retval);
1896 #ifdef HAVE_WINDOW_SYSTEM
1898 /* On frame F, convert character coordinates X and Y to pixel
1899 coordinates *PIX_X and *PIX_Y. */
1901 static void
1902 frame_char_to_pixel_position (struct frame *f, int x, int y,
1903 int *pix_x, int *pix_y)
1905 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
1906 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
1908 if (*pix_x < 0)
1909 *pix_x = 0;
1910 if (*pix_x > FRAME_PIXEL_WIDTH (f))
1911 *pix_x = FRAME_PIXEL_WIDTH (f);
1913 if (*pix_y < 0)
1914 *pix_y = 0;
1915 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
1916 *pix_y = FRAME_PIXEL_HEIGHT (f);
1919 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1921 static void
1922 frame_set_mouse_position (struct frame *f, int x, int y)
1924 int pix_x, pix_y;
1926 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
1927 frame_set_mouse_pixel_position (f, pix_x, pix_y);
1930 #endif /* HAVE_WINDOW_SYSTEM */
1932 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1933 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1934 Coordinates are relative to the frame, not a window,
1935 so the coordinates of the top left character in the frame
1936 may be nonzero due to left-hand scroll bars or the menu bar.
1938 The position is given in canonical character cells, where (0, 0) is
1939 the upper-left corner of the frame, X is the horizontal offset, and
1940 Y is the vertical offset, measured in units of the frame's default
1941 character size.
1943 This function is a no-op for an X frame that is not visible.
1944 If you have just created a frame, you must wait for it to become visible
1945 before calling this function on it, like this.
1946 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1947 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1949 CHECK_LIVE_FRAME (frame);
1950 CHECK_TYPE_RANGED_INTEGER (int, x);
1951 CHECK_TYPE_RANGED_INTEGER (int, y);
1953 /* I think this should be done with a hook. */
1954 #ifdef HAVE_WINDOW_SYSTEM
1955 if (FRAME_WINDOW_P (XFRAME (frame)))
1956 /* Warping the mouse will cause enternotify and focus events. */
1957 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1958 #else
1959 #if defined (MSDOS)
1960 if (FRAME_MSDOS_P (XFRAME (frame)))
1962 Fselect_frame (frame, Qnil);
1963 mouse_moveto (XINT (x), XINT (y));
1965 #else
1966 #ifdef HAVE_GPM
1968 Fselect_frame (frame, Qnil);
1969 term_mouse_moveto (XINT (x), XINT (y));
1971 #endif
1972 #endif
1973 #endif
1975 return Qnil;
1978 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1979 Sset_mouse_pixel_position, 3, 3, 0,
1980 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1981 The position is given in pixels, where (0, 0) is the upper-left corner
1982 of the frame, X is the horizontal offset, and Y is the vertical offset.
1984 Note, this is a no-op for an X frame that is not visible.
1985 If you have just created a frame, you must wait for it to become visible
1986 before calling this function on it, like this.
1987 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1988 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1990 CHECK_LIVE_FRAME (frame);
1991 CHECK_TYPE_RANGED_INTEGER (int, x);
1992 CHECK_TYPE_RANGED_INTEGER (int, y);
1994 /* I think this should be done with a hook. */
1995 #ifdef HAVE_WINDOW_SYSTEM
1996 if (FRAME_WINDOW_P (XFRAME (frame)))
1997 /* Warping the mouse will cause enternotify and focus events. */
1998 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1999 #else
2000 #if defined (MSDOS)
2001 if (FRAME_MSDOS_P (XFRAME (frame)))
2003 Fselect_frame (frame, Qnil);
2004 mouse_moveto (XINT (x), XINT (y));
2006 #else
2007 #ifdef HAVE_GPM
2009 Fselect_frame (frame, Qnil);
2010 term_mouse_moveto (XINT (x), XINT (y));
2012 #endif
2013 #endif
2014 #endif
2016 return Qnil;
2019 static void make_frame_visible_1 (Lisp_Object);
2021 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2022 0, 1, "",
2023 doc: /* Make the frame FRAME visible (assuming it is an X window).
2024 If omitted, FRAME defaults to the currently selected frame. */)
2025 (Lisp_Object frame)
2027 struct frame *f = decode_live_frame (frame);
2029 /* I think this should be done with a hook. */
2030 #ifdef HAVE_WINDOW_SYSTEM
2031 if (FRAME_WINDOW_P (f))
2032 x_make_frame_visible (f);
2033 #endif
2035 make_frame_visible_1 (f->root_window);
2037 /* Make menu bar update for the Buffers and Frames menus. */
2038 /* windows_or_buffers_changed = 15; FIXME: Why? */
2040 XSETFRAME (frame, f);
2041 return frame;
2044 /* Update the display_time slot of the buffers shown in WINDOW
2045 and all its descendants. */
2047 static void
2048 make_frame_visible_1 (Lisp_Object window)
2050 struct window *w;
2052 for (; !NILP (window); window = w->next)
2054 w = XWINDOW (window);
2055 if (WINDOWP (w->contents))
2056 make_frame_visible_1 (w->contents);
2057 else
2058 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2062 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2063 0, 2, "",
2064 doc: /* Make the frame FRAME invisible.
2065 If omitted, FRAME defaults to the currently selected frame.
2066 On graphical displays, invisible frames are not updated and are
2067 usually not displayed at all, even in a window system's \"taskbar\".
2069 Normally you may not make FRAME invisible if all other frames are invisible,
2070 but if the second optional argument FORCE is non-nil, you may do so.
2072 This function has no effect on text terminal frames. Such frames are
2073 always considered visible, whether or not they are currently being
2074 displayed in the terminal. */)
2075 (Lisp_Object frame, Lisp_Object force)
2077 struct frame *f = decode_live_frame (frame);
2079 if (NILP (force) && !other_visible_frames (f))
2080 error ("Attempt to make invisible the sole visible or iconified frame");
2082 /* Don't allow minibuf_window to remain on an invisible frame. */
2083 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2085 /* I think this should be done with a hook. */
2086 #ifdef HAVE_WINDOW_SYSTEM
2087 if (FRAME_WINDOW_P (f))
2088 x_make_frame_invisible (f);
2089 #endif
2091 /* Make menu bar update for the Buffers and Frames menus. */
2092 windows_or_buffers_changed = 16;
2094 return Qnil;
2097 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2098 0, 1, "",
2099 doc: /* Make the frame FRAME into an icon.
2100 If omitted, FRAME defaults to the currently selected frame. */)
2101 (Lisp_Object frame)
2103 struct frame *f = decode_live_frame (frame);
2105 /* Don't allow minibuf_window to remain on an iconified frame. */
2106 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2108 /* I think this should be done with a hook. */
2109 #ifdef HAVE_WINDOW_SYSTEM
2110 if (FRAME_WINDOW_P (f))
2111 x_iconify_frame (f);
2112 #endif
2114 /* Make menu bar update for the Buffers and Frames menus. */
2115 windows_or_buffers_changed = 17;
2117 return Qnil;
2120 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2121 1, 1, 0,
2122 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2123 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2124 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2125 On graphical displays, invisible frames are not updated and are
2126 usually not displayed at all, even in a window system's \"taskbar\".
2128 If FRAME is a text terminal frame, this always returns t.
2129 Such frames are always considered visible, whether or not they are
2130 currently being displayed on the terminal. */)
2131 (Lisp_Object frame)
2133 CHECK_LIVE_FRAME (frame);
2135 if (FRAME_VISIBLE_P (XFRAME (frame)))
2136 return Qt;
2137 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2138 return Qicon;
2139 return Qnil;
2142 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2143 0, 0, 0,
2144 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2145 (void)
2147 Lisp_Object tail, frame, value = Qnil;
2149 FOR_EACH_FRAME (tail, frame)
2150 if (FRAME_VISIBLE_P (XFRAME (frame)))
2151 value = Fcons (frame, value);
2153 return value;
2157 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2158 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2159 If FRAME is invisible or iconified, make it visible.
2160 If you don't specify a frame, the selected frame is used.
2161 If Emacs is displaying on an ordinary terminal or some other device which
2162 doesn't support multiple overlapping frames, this function selects FRAME. */)
2163 (Lisp_Object frame)
2165 struct frame *f = decode_live_frame (frame);
2167 XSETFRAME (frame, f);
2169 if (FRAME_TERMCAP_P (f))
2170 /* On a text terminal select FRAME. */
2171 Fselect_frame (frame, Qnil);
2172 else
2173 /* Do like the documentation says. */
2174 Fmake_frame_visible (frame);
2176 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2177 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2179 return Qnil;
2182 /* Should we have a corresponding function called Flower_Power? */
2183 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2184 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2185 If you don't specify a frame, the selected frame is used.
2186 If Emacs is displaying on an ordinary terminal or some other device which
2187 doesn't support multiple overlapping frames, this function does nothing. */)
2188 (Lisp_Object frame)
2190 struct frame *f = decode_live_frame (frame);
2192 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2193 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2195 return Qnil;
2199 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2200 1, 2, 0,
2201 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2202 In other words, switch-frame events caused by events in FRAME will
2203 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2204 FOCUS-FRAME after reading an event typed at FRAME.
2206 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2207 frame again receives its own keystrokes.
2209 Focus redirection is useful for temporarily redirecting keystrokes to
2210 a surrogate minibuffer frame when a frame doesn't have its own
2211 minibuffer window.
2213 A frame's focus redirection can be changed by `select-frame'. If frame
2214 FOO is selected, and then a different frame BAR is selected, any
2215 frames redirecting their focus to FOO are shifted to redirect their
2216 focus to BAR. This allows focus redirection to work properly when the
2217 user switches from one frame to another using `select-window'.
2219 This means that a frame whose focus is redirected to itself is treated
2220 differently from a frame whose focus is redirected to nil; the former
2221 is affected by `select-frame', while the latter is not.
2223 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2224 (Lisp_Object frame, Lisp_Object focus_frame)
2226 /* Note that we don't check for a live frame here. It's reasonable
2227 to redirect the focus of a frame you're about to delete, if you
2228 know what other frame should receive those keystrokes. */
2229 struct frame *f = decode_any_frame (frame);
2231 if (! NILP (focus_frame))
2232 CHECK_LIVE_FRAME (focus_frame);
2234 fset_focus_frame (f, focus_frame);
2236 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2237 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2239 return Qnil;
2243 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2244 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2245 If FRAME is omitted or nil, the selected frame is used.
2246 Return nil if FRAME's focus is not redirected.
2247 See `redirect-frame-focus'. */)
2248 (Lisp_Object frame)
2250 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2253 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2254 doc: /* Set the input focus to FRAME.
2255 FRAME nil means use the selected frame.
2256 If there is no window system support, this function does nothing. */)
2257 (Lisp_Object frame)
2259 #ifdef HAVE_WINDOW_SYSTEM
2260 x_focus_frame (decode_window_system_frame (frame));
2261 #endif
2262 return Qnil;
2265 DEFUN ("frame-can-run-window-configuration-change-hook",
2266 Fcan_run_window_configuration_change_hook,
2267 Scan_run_window_configuration_change_hook, 2, 2, 0,
2268 doc: /* Whether `window-configuration-change-hook' is run for frame FRAME.
2269 FRAME nil means use the selected frame. Second argument ALLOW non-nil
2270 means functions on `window-configuration-change-hook' are called
2271 whenever the window configuration of FRAME changes. ALLOW nil means
2272 these functions are not called.
2274 This function is currently called by `face-set-after-frame-default' only
2275 and should be otherwise used with utter care to avoid that running
2276 functions on `window-configuration-change-hook' is impeded forever. */)
2277 (Lisp_Object frame, Lisp_Object allow)
2279 struct frame *f = decode_live_frame (frame);
2281 f->can_run_window_configuration_change_hook = NILP (allow) ? false : true;
2282 return Qnil;
2286 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2288 void
2289 frames_discard_buffer (Lisp_Object buffer)
2291 Lisp_Object frame, tail;
2293 FOR_EACH_FRAME (tail, frame)
2295 fset_buffer_list
2296 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2297 fset_buried_buffer_list
2298 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2302 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2303 If the alist already has an element for PROP, we change it. */
2305 void
2306 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2308 register Lisp_Object tem;
2310 tem = Fassq (prop, *alistptr);
2311 if (EQ (tem, Qnil))
2312 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2313 else
2314 Fsetcdr (tem, val);
2317 static int
2318 frame_name_fnn_p (char *str, ptrdiff_t len)
2320 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2322 char *p = str + 2;
2323 while ('0' <= *p && *p <= '9')
2324 p++;
2325 if (p == str + len)
2326 return 1;
2328 return 0;
2331 /* Set the name of the terminal frame. Also used by MSDOS frames.
2332 Modeled after x_set_name which is used for WINDOW frames. */
2334 static void
2335 set_term_frame_name (struct frame *f, Lisp_Object name)
2337 f->explicit_name = ! NILP (name);
2339 /* If NAME is nil, set the name to F<num>. */
2340 if (NILP (name))
2342 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2344 /* Check for no change needed in this very common case
2345 before we do any consing. */
2346 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2347 return;
2349 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2351 else
2353 CHECK_STRING (name);
2355 /* Don't change the name if it's already NAME. */
2356 if (! NILP (Fstring_equal (name, f->name)))
2357 return;
2359 /* Don't allow the user to set the frame name to F<num>, so it
2360 doesn't clash with the names we generate for terminal frames. */
2361 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2362 error ("Frame names of the form F<num> are usurped by Emacs");
2365 fset_name (f, name);
2366 update_mode_lines = 16;
2369 void
2370 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2372 register Lisp_Object old_alist_elt;
2374 /* The buffer-list parameters are stored in a special place and not
2375 in the alist. All buffers must be live. */
2376 if (EQ (prop, Qbuffer_list))
2378 Lisp_Object list = Qnil;
2379 for (; CONSP (val); val = XCDR (val))
2380 if (!NILP (Fbuffer_live_p (XCAR (val))))
2381 list = Fcons (XCAR (val), list);
2382 fset_buffer_list (f, Fnreverse (list));
2383 return;
2385 if (EQ (prop, Qburied_buffer_list))
2387 Lisp_Object list = Qnil;
2388 for (; CONSP (val); val = XCDR (val))
2389 if (!NILP (Fbuffer_live_p (XCAR (val))))
2390 list = Fcons (XCAR (val), list);
2391 fset_buried_buffer_list (f, Fnreverse (list));
2392 return;
2395 /* If PROP is a symbol which is supposed to have frame-local values,
2396 and it is set up based on this frame, switch to the global
2397 binding. That way, we can create or alter the frame-local binding
2398 without messing up the symbol's status. */
2399 if (SYMBOLP (prop))
2401 struct Lisp_Symbol *sym = XSYMBOL (prop);
2402 start:
2403 switch (sym->redirect)
2405 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2406 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2407 case SYMBOL_LOCALIZED:
2408 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2409 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2410 swap_in_global_binding (sym);
2411 break;
2413 default: emacs_abort ();
2417 /* The tty color needed to be set before the frame's parameter
2418 alist was updated with the new value. This is not true any more,
2419 but we still do this test early on. */
2420 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2421 && f == FRAME_TTY (f)->previous_frame)
2422 /* Force redisplay of this tty. */
2423 FRAME_TTY (f)->previous_frame = NULL;
2425 /* Update the frame parameter alist. */
2426 old_alist_elt = Fassq (prop, f->param_alist);
2427 if (EQ (old_alist_elt, Qnil))
2428 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2429 else
2430 Fsetcdr (old_alist_elt, val);
2432 /* Update some other special parameters in their special places
2433 in addition to the alist. */
2435 if (EQ (prop, Qbuffer_predicate))
2436 fset_buffer_predicate (f, val);
2438 if (! FRAME_WINDOW_P (f))
2440 if (EQ (prop, Qmenu_bar_lines))
2441 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2442 else if (EQ (prop, Qname))
2443 set_term_frame_name (f, val);
2446 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2448 if (! MINI_WINDOW_P (XWINDOW (val)))
2449 error ("Surrogate minibuffer windows must be minibuffer windows");
2451 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2452 && !EQ (val, f->minibuffer_window))
2453 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2455 /* Install the chosen minibuffer window, with proper buffer. */
2456 fset_minibuffer_window (f, val);
2460 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2461 is not an unspecified foreground or background color. */
2463 static Lisp_Object
2464 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2466 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2467 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2468 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2469 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2472 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2473 doc: /* Return the parameters-alist of frame FRAME.
2474 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2475 The meaningful PARMs depend on the kind of frame.
2476 If FRAME is omitted or nil, return information on the currently selected frame. */)
2477 (Lisp_Object frame)
2479 Lisp_Object alist;
2480 struct frame *f = decode_any_frame (frame);
2481 int height, width;
2482 struct gcpro gcpro1;
2484 if (!FRAME_LIVE_P (f))
2485 return Qnil;
2487 alist = Fcopy_alist (f->param_alist);
2488 GCPRO1 (alist);
2490 if (!FRAME_WINDOW_P (f))
2492 Lisp_Object elt;
2494 /* If the frame's parameter alist says the colors are
2495 unspecified and reversed, take the frame's background pixel
2496 for foreground and vice versa. */
2497 elt = Fassq (Qforeground_color, alist);
2498 if (CONSP (elt) && STRINGP (XCDR (elt)))
2500 elt = frame_unspecified_color (f, XCDR (elt));
2501 if (!NILP (elt))
2502 store_in_alist (&alist, Qforeground_color, elt);
2504 else
2505 store_in_alist (&alist, Qforeground_color,
2506 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2507 elt = Fassq (Qbackground_color, alist);
2508 if (CONSP (elt) && STRINGP (XCDR (elt)))
2510 elt = frame_unspecified_color (f, XCDR (elt));
2511 if (!NILP (elt))
2512 store_in_alist (&alist, Qbackground_color, elt);
2514 else
2515 store_in_alist (&alist, Qbackground_color,
2516 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2517 store_in_alist (&alist, intern ("font"),
2518 build_string (FRAME_MSDOS_P (f)
2519 ? "ms-dos"
2520 : FRAME_W32_P (f) ? "w32term"
2521 :"tty"));
2523 store_in_alist (&alist, Qname, f->name);
2524 height = (f->new_height
2525 ? (f->new_pixelwise
2526 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2527 : f->new_height)
2528 : FRAME_LINES (f));
2529 store_in_alist (&alist, Qheight, make_number (height));
2530 width = (f->new_width
2531 ? (f->new_pixelwise
2532 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2533 : f->new_width)
2534 : FRAME_COLS (f));
2535 store_in_alist (&alist, Qwidth, make_number (width));
2536 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2537 store_in_alist (&alist, Qminibuffer,
2538 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2539 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2540 : FRAME_MINIBUF_WINDOW (f)));
2541 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2542 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2543 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2545 /* I think this should be done with a hook. */
2546 #ifdef HAVE_WINDOW_SYSTEM
2547 if (FRAME_WINDOW_P (f))
2548 x_report_frame_params (f, &alist);
2549 else
2550 #endif
2552 /* This ought to be correct in f->param_alist for an X frame. */
2553 Lisp_Object lines;
2554 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2555 store_in_alist (&alist, Qmenu_bar_lines, lines);
2558 UNGCPRO;
2559 return alist;
2563 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2564 doc: /* Return FRAME's value for parameter PARAMETER.
2565 If FRAME is nil, describe the currently selected frame. */)
2566 (Lisp_Object frame, Lisp_Object parameter)
2568 struct frame *f = decode_any_frame (frame);
2569 Lisp_Object value = Qnil;
2571 CHECK_SYMBOL (parameter);
2573 XSETFRAME (frame, f);
2575 if (FRAME_LIVE_P (f))
2577 /* Avoid consing in frequent cases. */
2578 if (EQ (parameter, Qname))
2579 value = f->name;
2580 #ifdef HAVE_X_WINDOWS
2581 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2582 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2583 #endif /* HAVE_X_WINDOWS */
2584 else if (EQ (parameter, Qbackground_color)
2585 || EQ (parameter, Qforeground_color))
2587 value = Fassq (parameter, f->param_alist);
2588 if (CONSP (value))
2590 value = XCDR (value);
2591 /* Fframe_parameters puts the actual fg/bg color names,
2592 even if f->param_alist says otherwise. This is
2593 important when param_alist's notion of colors is
2594 "unspecified". We need to do the same here. */
2595 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2596 value = frame_unspecified_color (f, value);
2598 else
2599 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2601 else if (EQ (parameter, Qdisplay_type)
2602 || EQ (parameter, Qbackground_mode))
2603 value = Fcdr (Fassq (parameter, f->param_alist));
2604 else
2605 /* FIXME: Avoid this code path at all (as well as code duplication)
2606 by sharing more code with Fframe_parameters. */
2607 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2610 return value;
2614 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2615 Smodify_frame_parameters, 2, 2, 0,
2616 doc: /* Modify the parameters of frame FRAME according to ALIST.
2617 If FRAME is nil, it defaults to the selected frame.
2618 ALIST is an alist of parameters to change and their new values.
2619 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2620 The meaningful PARMs depend on the kind of frame.
2621 Undefined PARMs are ignored, but stored in the frame's parameter list
2622 so that `frame-parameters' will return them.
2624 The value of frame parameter FOO can also be accessed
2625 as a frame-local binding for the variable FOO, if you have
2626 enabled such bindings for that variable with `make-variable-frame-local'.
2627 Note that this functionality is obsolete as of Emacs 22.2, and its
2628 use is not recommended. Explicitly check for a frame-parameter instead. */)
2629 (Lisp_Object frame, Lisp_Object alist)
2631 struct frame *f = decode_live_frame (frame);
2632 register Lisp_Object prop, val;
2634 CHECK_LIST (alist);
2636 /* I think this should be done with a hook. */
2637 #ifdef HAVE_WINDOW_SYSTEM
2638 if (FRAME_WINDOW_P (f))
2639 x_set_frame_parameters (f, alist);
2640 else
2641 #endif
2642 #ifdef MSDOS
2643 if (FRAME_MSDOS_P (f))
2644 IT_set_frame_parameters (f, alist);
2645 else
2646 #endif
2649 EMACS_INT length = XFASTINT (Flength (alist));
2650 ptrdiff_t i;
2651 Lisp_Object *parms;
2652 Lisp_Object *values;
2653 USE_SAFE_ALLOCA;
2654 SAFE_ALLOCA_LISP (parms, 2 * length);
2655 values = parms + length;
2657 /* Extract parm names and values into those vectors. */
2659 for (i = 0; CONSP (alist); alist = XCDR (alist))
2661 Lisp_Object elt;
2663 elt = XCAR (alist);
2664 parms[i] = Fcar (elt);
2665 values[i] = Fcdr (elt);
2666 i++;
2669 /* Now process them in reverse of specified order. */
2670 while (--i >= 0)
2672 prop = parms[i];
2673 val = values[i];
2674 store_frame_param (f, prop, val);
2676 if (EQ (prop, Qforeground_color)
2677 || EQ (prop, Qbackground_color))
2678 update_face_from_frame_parameter (f, prop, val);
2681 SAFE_FREE ();
2683 return Qnil;
2686 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2687 0, 1, 0,
2688 doc: /* Height in pixels of a line in the font in frame FRAME.
2689 If FRAME is omitted or nil, the selected frame is used.
2690 For a terminal frame, the value is always 1. */)
2691 (Lisp_Object frame)
2693 #ifdef HAVE_WINDOW_SYSTEM
2694 struct frame *f = decode_any_frame (frame);
2696 if (FRAME_WINDOW_P (f))
2697 return make_number (FRAME_LINE_HEIGHT (f));
2698 else
2699 #endif
2700 return make_number (1);
2704 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2705 0, 1, 0,
2706 doc: /* Width in pixels of characters in the font in frame FRAME.
2707 If FRAME is omitted or nil, the selected frame is used.
2708 On a graphical screen, the width is the standard width of the default font.
2709 For a terminal screen, the value is always 1. */)
2710 (Lisp_Object frame)
2712 #ifdef HAVE_WINDOW_SYSTEM
2713 struct frame *f = decode_any_frame (frame);
2715 if (FRAME_WINDOW_P (f))
2716 return make_number (FRAME_COLUMN_WIDTH (f));
2717 else
2718 #endif
2719 return make_number (1);
2722 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2723 Sframe_pixel_height, 0, 1, 0,
2724 doc: /* Return a FRAME's height in pixels.
2725 If FRAME is omitted or nil, the selected frame is used. The exact value
2726 of the result depends on the window-system and toolkit in use:
2728 In the Gtk+ version of Emacs, it includes only any window (including
2729 the minibuffer or echo area), mode line, and header line. It does not
2730 include the tool bar or menu bar.
2732 With other graphical versions, it also includes the tool bar and the
2733 menu bar.
2735 For a text terminal, it includes the menu bar. In this case, the
2736 result is really in characters rather than pixels (i.e., is identical
2737 to `frame-height'). */)
2738 (Lisp_Object frame)
2740 struct frame *f = decode_any_frame (frame);
2742 #ifdef HAVE_WINDOW_SYSTEM
2743 if (FRAME_WINDOW_P (f))
2744 return make_number (FRAME_PIXEL_HEIGHT (f));
2745 else
2746 #endif
2747 return make_number (FRAME_TOTAL_LINES (f));
2750 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2751 Sframe_pixel_width, 0, 1, 0,
2752 doc: /* Return FRAME's width in pixels.
2753 For a terminal frame, the result really gives the width in characters.
2754 If FRAME is omitted or nil, the selected frame is used. */)
2755 (Lisp_Object frame)
2757 struct frame *f = decode_any_frame (frame);
2759 #ifdef HAVE_WINDOW_SYSTEM
2760 if (FRAME_WINDOW_P (f))
2761 return make_number (FRAME_PIXEL_WIDTH (f));
2762 else
2763 #endif
2764 return make_number (FRAME_TOTAL_COLS (f));
2767 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2768 Stool_bar_pixel_width, 0, 1, 0,
2769 doc: /* Return width in pixels of FRAME's tool bar.
2770 The result is greater than zero only when the tool bar is on the left
2771 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2772 is used. */)
2773 (Lisp_Object frame)
2775 #ifdef FRAME_TOOLBAR_WIDTH
2776 struct frame *f = decode_any_frame (frame);
2778 if (FRAME_WINDOW_P (f))
2779 return make_number (FRAME_TOOLBAR_WIDTH (f));
2780 #endif
2781 return make_number (0);
2784 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2785 doc: /* Return width in columns of FRAME's text area. */)
2786 (Lisp_Object frame)
2788 return make_number (FRAME_COLS (decode_any_frame (frame)));
2791 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2792 doc: /* Return height in lines of FRAME's text area. */)
2793 (Lisp_Object frame)
2795 return make_number (FRAME_LINES (decode_any_frame (frame)));
2798 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2799 doc: /* Return number of total columns of FRAME. */)
2800 (Lisp_Object frame)
2802 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2805 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2806 doc: /* Return number of total lines of FRAME. */)
2807 (Lisp_Object frame)
2809 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2812 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2813 doc: /* Return text area width of FRAME in pixels. */)
2814 (Lisp_Object frame)
2816 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2819 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2820 doc: /* Return text area height of FRAME in pixels. */)
2821 (Lisp_Object frame)
2823 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2826 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2827 doc: /* Return scroll bar width of FRAME in pixels. */)
2828 (Lisp_Object frame)
2830 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2833 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2834 doc: /* Return scroll bar height of FRAME in pixels. */)
2835 (Lisp_Object frame)
2837 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2840 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2841 doc: /* Return fringe width of FRAME in pixels. */)
2842 (Lisp_Object frame)
2844 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2847 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2848 doc: /* Return border width of FRAME in pixels. */)
2849 (Lisp_Object frame)
2851 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2854 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2855 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2856 (Lisp_Object frame)
2858 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2861 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2862 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2863 (Lisp_Object frame)
2865 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2868 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2869 doc: /* Set height of frame FRAME to HEIGHT lines.
2870 Optional third arg PRETEND non-nil means that redisplay should use
2871 HEIGHT lines but that the idea of the actual height of the frame should
2872 not be changed.
2874 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2875 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
2876 window managers may refuse to honor a HEIGHT that is not an integer
2877 multiple of the default frame font height. */)
2878 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2880 struct frame *f = decode_live_frame (frame);
2881 int pixel_height;
2883 CHECK_TYPE_RANGED_INTEGER (int, height);
2885 pixel_height = (!NILP (pixelwise)
2886 ? XINT (height)
2887 : XINT (height) * FRAME_LINE_HEIGHT (f));
2888 if (pixel_height != FRAME_TEXT_HEIGHT (f))
2889 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
2891 return Qnil;
2894 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2895 doc: /* Set width of frame FRAME to WIDTH columns.
2896 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2897 columns but that the idea of the actual width of the frame should not
2898 be changed.
2900 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2901 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
2902 window managers may refuse to honor a WIDTH that is not an integer
2903 multiple of the default frame font width. */)
2904 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2906 struct frame *f = decode_live_frame (frame);
2907 int pixel_width;
2909 CHECK_TYPE_RANGED_INTEGER (int, width);
2911 pixel_width = (!NILP (pixelwise)
2912 ? XINT (width)
2913 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2914 if (pixel_width != FRAME_TEXT_WIDTH (f))
2915 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
2917 return Qnil;
2920 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2921 doc: /* Set size of FRAME to WIDTH by HEIGHT, measured in characters.
2922 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
2923 When `frame-resize-pixelwise' is nil, some window managers may refuse to
2924 honor a WIDTH that is not an integer multiple of the default frame font
2925 width or a HEIGHT that is not an integer multiple of the default frame
2926 font height. */)
2927 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2929 struct frame *f = decode_live_frame (frame);
2930 int pixel_width, pixel_height;
2932 CHECK_TYPE_RANGED_INTEGER (int, width);
2933 CHECK_TYPE_RANGED_INTEGER (int, height);
2935 pixel_width = (!NILP (pixelwise)
2936 ? XINT (width)
2937 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2938 pixel_height = (!NILP (pixelwise)
2939 ? XINT (height)
2940 : XINT (height) * FRAME_LINE_HEIGHT (f));
2942 if (pixel_width != FRAME_TEXT_WIDTH (f)
2943 || pixel_height != FRAME_TEXT_HEIGHT (f))
2944 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
2946 return Qnil;
2949 DEFUN ("set-frame-position", Fset_frame_position,
2950 Sset_frame_position, 3, 3, 0,
2951 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2952 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2953 actually the position of the upper left corner of the frame. Negative
2954 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2955 or bottommost possible position (that stays within the screen). */)
2956 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2958 register struct frame *f = decode_live_frame (frame);
2960 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2961 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2963 /* I think this should be done with a hook. */
2964 #ifdef HAVE_WINDOW_SYSTEM
2965 if (FRAME_WINDOW_P (f))
2966 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2967 #endif
2969 return Qt;
2973 /***********************************************************************
2974 Frame Parameters
2975 ***********************************************************************/
2977 /* Connect the frame-parameter names for X frames
2978 to the ways of passing the parameter values to the window system.
2980 The name of a parameter, as a Lisp symbol,
2981 has an `x-frame-parameter' property which is an integer in Lisp
2982 that is an index in this table. */
2984 struct frame_parm_table {
2985 const char *name;
2986 Lisp_Object *variable;
2989 static const struct frame_parm_table frame_parms[] =
2991 {"auto-raise", &Qauto_raise},
2992 {"auto-lower", &Qauto_lower},
2993 {"background-color", 0},
2994 {"border-color", &Qborder_color},
2995 {"border-width", &Qborder_width},
2996 {"cursor-color", &Qcursor_color},
2997 {"cursor-type", &Qcursor_type},
2998 {"font", 0},
2999 {"foreground-color", 0},
3000 {"icon-name", &Qicon_name},
3001 {"icon-type", &Qicon_type},
3002 {"internal-border-width", &Qinternal_border_width},
3003 {"right-divider-width", &Qright_divider_width},
3004 {"bottom-divider-width", &Qbottom_divider_width},
3005 {"menu-bar-lines", &Qmenu_bar_lines},
3006 {"mouse-color", &Qmouse_color},
3007 {"name", &Qname},
3008 {"scroll-bar-width", &Qscroll_bar_width},
3009 {"scroll-bar-height", &Qscroll_bar_height},
3010 {"title", &Qtitle},
3011 {"unsplittable", &Qunsplittable},
3012 {"vertical-scroll-bars", &Qvertical_scroll_bars},
3013 {"horizontal-scroll-bars", &Qhorizontal_scroll_bars},
3014 {"visibility", &Qvisibility},
3015 {"tool-bar-lines", &Qtool_bar_lines},
3016 {"scroll-bar-foreground", &Qscroll_bar_foreground},
3017 {"scroll-bar-background", &Qscroll_bar_background},
3018 {"screen-gamma", &Qscreen_gamma},
3019 {"line-spacing", &Qline_spacing},
3020 {"left-fringe", &Qleft_fringe},
3021 {"right-fringe", &Qright_fringe},
3022 {"wait-for-wm", &Qwait_for_wm},
3023 {"fullscreen", &Qfullscreen},
3024 {"font-backend", &Qfont_backend},
3025 {"alpha", &Qalpha},
3026 {"sticky", &Qsticky},
3027 {"tool-bar-position", &Qtool_bar_position},
3030 #ifdef HAVE_WINDOW_SYSTEM
3032 /* Change the parameters of frame F as specified by ALIST.
3033 If a parameter is not specially recognized, do nothing special;
3034 otherwise call the `x_set_...' function for that parameter.
3035 Except for certain geometry properties, always call store_frame_param
3036 to store the new value in the parameter alist. */
3038 void
3039 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3041 Lisp_Object tail;
3043 /* If both of these parameters are present, it's more efficient to
3044 set them both at once. So we wait until we've looked at the
3045 entire list before we set them. */
3046 int width IF_LINT (= 0), height IF_LINT (= 0);
3047 bool width_change = 0, height_change = 0;
3049 /* Same here. */
3050 Lisp_Object left, top;
3052 /* Same with these. */
3053 Lisp_Object icon_left, icon_top;
3055 /* Record in these vectors all the parms specified. */
3056 Lisp_Object *parms;
3057 Lisp_Object *values;
3058 ptrdiff_t i, p;
3059 bool left_no_change = 0, top_no_change = 0;
3060 #ifdef HAVE_X_WINDOWS
3061 bool icon_left_no_change = 0, icon_top_no_change = 0;
3062 #endif
3064 i = 0;
3065 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3066 i++;
3068 USE_SAFE_ALLOCA;
3069 SAFE_ALLOCA_LISP (parms, 2 * i);
3070 values = parms + i;
3072 /* Extract parm names and values into those vectors. */
3074 i = 0;
3075 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3077 Lisp_Object elt;
3079 elt = XCAR (tail);
3080 parms[i] = Fcar (elt);
3081 values[i] = Fcdr (elt);
3082 i++;
3084 /* TAIL and ALIST are not used again below here. */
3085 alist = tail = Qnil;
3087 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
3088 because their values appear in VALUES and strings are not valid. */
3089 top = left = Qunbound;
3090 icon_left = icon_top = Qunbound;
3092 /* Process foreground_color and background_color before anything else.
3093 They are independent of other properties, but other properties (e.g.,
3094 cursor_color) are dependent upon them. */
3095 /* Process default font as well, since fringe widths depends on it. */
3096 for (p = 0; p < i; p++)
3098 Lisp_Object prop, val;
3100 prop = parms[p];
3101 val = values[p];
3102 if (EQ (prop, Qforeground_color)
3103 || EQ (prop, Qbackground_color)
3104 || EQ (prop, Qfont))
3106 register Lisp_Object param_index, old_value;
3108 old_value = get_frame_param (f, prop);
3109 if (NILP (Fequal (val, old_value)))
3111 store_frame_param (f, prop, val);
3113 param_index = Fget (prop, Qx_frame_parameter);
3114 if (NATNUMP (param_index)
3115 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3116 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3117 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3122 /* Now process them in reverse of specified order. */
3123 while (i-- != 0)
3125 Lisp_Object prop, val;
3127 prop = parms[i];
3128 val = values[i];
3130 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
3132 width_change = 1;
3133 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3135 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
3137 height_change = 1;
3138 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3140 else if (EQ (prop, Qtop))
3141 top = val;
3142 else if (EQ (prop, Qleft))
3143 left = val;
3144 else if (EQ (prop, Qicon_top))
3145 icon_top = val;
3146 else if (EQ (prop, Qicon_left))
3147 icon_left = val;
3148 else if (EQ (prop, Qforeground_color)
3149 || EQ (prop, Qbackground_color)
3150 || EQ (prop, Qfont))
3151 /* Processed above. */
3152 continue;
3153 else
3155 register Lisp_Object param_index, old_value;
3157 old_value = get_frame_param (f, prop);
3159 store_frame_param (f, prop, val);
3161 param_index = Fget (prop, Qx_frame_parameter);
3162 if (NATNUMP (param_index)
3163 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3164 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3165 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3169 /* Don't die if just one of these was set. */
3170 if (EQ (left, Qunbound))
3172 left_no_change = 1;
3173 if (f->left_pos < 0)
3174 left = list2 (Qplus, make_number (f->left_pos));
3175 else
3176 XSETINT (left, f->left_pos);
3178 if (EQ (top, Qunbound))
3180 top_no_change = 1;
3181 if (f->top_pos < 0)
3182 top = list2 (Qplus, make_number (f->top_pos));
3183 else
3184 XSETINT (top, f->top_pos);
3187 /* If one of the icon positions was not set, preserve or default it. */
3188 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3190 #ifdef HAVE_X_WINDOWS
3191 icon_left_no_change = 1;
3192 #endif
3193 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3194 if (NILP (icon_left))
3195 XSETINT (icon_left, 0);
3197 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3199 #ifdef HAVE_X_WINDOWS
3200 icon_top_no_change = 1;
3201 #endif
3202 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3203 if (NILP (icon_top))
3204 XSETINT (icon_top, 0);
3207 /* Don't set these parameters unless they've been explicitly
3208 specified. The window might be mapped or resized while we're in
3209 this function, and we don't want to override that unless the lisp
3210 code has asked for it.
3212 Don't set these parameters unless they actually differ from the
3213 window's current parameters; the window may not actually exist
3214 yet. */
3216 Lisp_Object frame;
3218 XSETFRAME (frame, f);
3220 if ((width_change && width != FRAME_TEXT_WIDTH (f))
3221 || (height_change && height != FRAME_TEXT_HEIGHT (f))
3222 || f->new_height || f->new_width)
3224 /* If necessary provide default values for HEIGHT and WIDTH. Do
3225 that here since otherwise a size change implied by an
3226 intermittent font change may get lost as in Bug#17142. */
3227 if (!width_change)
3228 width = (f->new_width
3229 ? (f->new_pixelwise
3230 ? f->new_width
3231 : (f->new_width * FRAME_COLUMN_WIDTH (f)))
3232 : FRAME_TEXT_WIDTH (f));
3234 if (!height_change)
3235 height = (f->new_height
3236 ? (f->new_pixelwise
3237 ? f->new_height
3238 : (f->new_height * FRAME_LINE_HEIGHT (f)))
3239 : FRAME_TEXT_HEIGHT (f));
3241 Fset_frame_size (frame, make_number (width), make_number (height), Qt);
3244 if ((!NILP (left) || !NILP (top))
3245 && ! (left_no_change && top_no_change)
3246 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3247 && NUMBERP (top) && XINT (top) == f->top_pos))
3249 int leftpos = 0;
3250 int toppos = 0;
3252 /* Record the signs. */
3253 f->size_hint_flags &= ~ (XNegative | YNegative);
3254 if (EQ (left, Qminus))
3255 f->size_hint_flags |= XNegative;
3256 else if (TYPE_RANGED_INTEGERP (int, left))
3258 leftpos = XINT (left);
3259 if (leftpos < 0)
3260 f->size_hint_flags |= XNegative;
3262 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3263 && CONSP (XCDR (left))
3264 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3266 leftpos = - XINT (XCAR (XCDR (left)));
3267 f->size_hint_flags |= XNegative;
3269 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3270 && CONSP (XCDR (left))
3271 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3273 leftpos = XINT (XCAR (XCDR (left)));
3276 if (EQ (top, Qminus))
3277 f->size_hint_flags |= YNegative;
3278 else if (TYPE_RANGED_INTEGERP (int, top))
3280 toppos = XINT (top);
3281 if (toppos < 0)
3282 f->size_hint_flags |= YNegative;
3284 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3285 && CONSP (XCDR (top))
3286 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3288 toppos = - XINT (XCAR (XCDR (top)));
3289 f->size_hint_flags |= YNegative;
3291 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3292 && CONSP (XCDR (top))
3293 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3295 toppos = XINT (XCAR (XCDR (top)));
3299 /* Store the numeric value of the position. */
3300 f->top_pos = toppos;
3301 f->left_pos = leftpos;
3303 f->win_gravity = NorthWestGravity;
3305 /* Actually set that position, and convert to absolute. */
3306 x_set_offset (f, leftpos, toppos, -1);
3308 #ifdef HAVE_X_WINDOWS
3309 if ((!NILP (icon_left) || !NILP (icon_top))
3310 && ! (icon_left_no_change && icon_top_no_change))
3311 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3312 #endif /* HAVE_X_WINDOWS */
3315 SAFE_FREE ();
3319 /* Insert a description of internally-recorded parameters of frame X
3320 into the parameter alist *ALISTPTR that is to be given to the user.
3321 Only parameters that are specific to the X window system
3322 and whose values are not correctly recorded in the frame's
3323 param_alist need to be considered here. */
3325 void
3326 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3328 Lisp_Object tem;
3329 uprintmax_t w;
3330 char buf[INT_BUFSIZE_BOUND (w)];
3332 /* Represent negative positions (off the top or left screen edge)
3333 in a way that Fmodify_frame_parameters will understand correctly. */
3334 XSETINT (tem, f->left_pos);
3335 if (f->left_pos >= 0)
3336 store_in_alist (alistptr, Qleft, tem);
3337 else
3338 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3340 XSETINT (tem, f->top_pos);
3341 if (f->top_pos >= 0)
3342 store_in_alist (alistptr, Qtop, tem);
3343 else
3344 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3346 store_in_alist (alistptr, Qborder_width,
3347 make_number (f->border_width));
3348 store_in_alist (alistptr, Qinternal_border_width,
3349 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3350 store_in_alist (alistptr, Qright_divider_width,
3351 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3352 store_in_alist (alistptr, Qbottom_divider_width,
3353 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3354 store_in_alist (alistptr, Qleft_fringe,
3355 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3356 store_in_alist (alistptr, Qright_fringe,
3357 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3358 store_in_alist (alistptr, Qscroll_bar_width,
3359 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3360 ? make_number (0)
3361 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3362 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3363 /* nil means "use default width"
3364 for non-toolkit scroll bar.
3365 ruler-mode.el depends on this. */
3366 : Qnil));
3367 store_in_alist (alistptr, Qscroll_bar_height,
3368 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3369 ? make_number (0)
3370 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3371 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3372 /* nil means "use default height"
3373 for non-toolkit scroll bar. */
3374 : Qnil));
3375 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3376 MS-Windows it returns a value whose type is HANDLE, which is
3377 actually a pointer. Explicit casting avoids compiler
3378 warnings. */
3379 w = (uintptr_t) FRAME_X_WINDOW (f);
3380 store_in_alist (alistptr, Qwindow_id,
3381 make_formatted_string (buf, "%"pMu, w));
3382 #ifdef HAVE_X_WINDOWS
3383 #ifdef USE_X_TOOLKIT
3384 /* Tooltip frame may not have this widget. */
3385 if (FRAME_X_OUTPUT (f)->widget)
3386 #endif
3387 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3388 store_in_alist (alistptr, Qouter_window_id,
3389 make_formatted_string (buf, "%"pMu, w));
3390 #endif
3391 store_in_alist (alistptr, Qicon_name, f->icon_name);
3392 store_in_alist (alistptr, Qvisibility,
3393 (FRAME_VISIBLE_P (f) ? Qt
3394 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3395 store_in_alist (alistptr, Qdisplay,
3396 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3398 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3399 tem = Qnil;
3400 else
3401 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3402 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3403 store_in_alist (alistptr, Qparent_id, tem);
3404 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3408 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3409 the previous value of that parameter, NEW_VALUE is the new value. */
3411 void
3412 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3414 if (NILP (new_value))
3415 f->want_fullscreen = FULLSCREEN_NONE;
3416 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3417 f->want_fullscreen = FULLSCREEN_BOTH;
3418 else if (EQ (new_value, Qfullwidth))
3419 f->want_fullscreen = FULLSCREEN_WIDTH;
3420 else if (EQ (new_value, Qfullheight))
3421 f->want_fullscreen = FULLSCREEN_HEIGHT;
3422 else if (EQ (new_value, Qmaximized))
3423 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3425 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3426 FRAME_TERMINAL (f)->fullscreen_hook (f);
3430 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3431 the previous value of that parameter, NEW_VALUE is the new value. */
3433 void
3434 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3436 if (NILP (new_value))
3437 f->extra_line_spacing = 0;
3438 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3439 f->extra_line_spacing = XFASTINT (new_value);
3440 else if (FLOATP (new_value))
3442 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3444 if (new_spacing >= 0)
3445 f->extra_line_spacing = new_spacing;
3446 else
3447 signal_error ("Invalid line-spacing", new_value);
3449 else
3450 signal_error ("Invalid line-spacing", new_value);
3451 if (FRAME_VISIBLE_P (f))
3452 redraw_frame (f);
3456 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3457 the previous value of that parameter, NEW_VALUE is the new value. */
3459 void
3460 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3462 Lisp_Object bgcolor;
3464 if (NILP (new_value))
3465 f->gamma = 0;
3466 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3467 /* The value 0.4545 is the normal viewing gamma. */
3468 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3469 else
3470 signal_error ("Invalid screen-gamma", new_value);
3472 /* Apply the new gamma value to the frame background. */
3473 bgcolor = Fassq (Qbackground_color, f->param_alist);
3474 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3476 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3477 if (NATNUMP (parm_index)
3478 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3479 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3480 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3481 (f, bgcolor, Qnil);
3484 Fclear_face_cache (Qnil);
3488 void
3489 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3491 Lisp_Object font_object;
3492 int fontset = -1;
3493 #ifdef HAVE_X_WINDOWS
3494 Lisp_Object font_param = arg;
3495 #endif
3497 /* Set the frame parameter back to the old value because we may
3498 fail to use ARG as the new parameter value. */
3499 store_frame_param (f, Qfont, oldval);
3501 /* ARG is a fontset name, a font name, a cons of fontset name and a
3502 font object, or a font object. In the last case, this function
3503 never fail. */
3504 if (STRINGP (arg))
3506 fontset = fs_query_fontset (arg, 0);
3507 if (fontset < 0)
3509 font_object = font_open_by_name (f, arg);
3510 if (NILP (font_object))
3511 error ("Font `%s' is not defined", SSDATA (arg));
3512 arg = AREF (font_object, FONT_NAME_INDEX);
3514 else if (fontset > 0)
3516 font_object = font_open_by_name (f, fontset_ascii (fontset));
3517 if (NILP (font_object))
3518 error ("Font `%s' is not defined", SDATA (arg));
3519 arg = AREF (font_object, FONT_NAME_INDEX);
3521 else
3522 error ("The default fontset can't be used for a frame font");
3524 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3526 /* This is the case that the ASCII font of F's fontset XCAR
3527 (arg) is changed to the font XCDR (arg) by
3528 `set-fontset-font'. */
3529 fontset = fs_query_fontset (XCAR (arg), 0);
3530 if (fontset < 0)
3531 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3532 font_object = XCDR (arg);
3533 arg = AREF (font_object, FONT_NAME_INDEX);
3534 #ifdef HAVE_X_WINDOWS
3535 font_param = Ffont_get (font_object, QCname);
3536 #endif
3538 else if (FONT_OBJECT_P (arg))
3540 font_object = arg;
3541 #ifdef HAVE_X_WINDOWS
3542 font_param = Ffont_get (font_object, QCname);
3543 #endif
3544 /* This is to store the XLFD font name in the frame parameter for
3545 backward compatibility. We should store the font-object
3546 itself in the future. */
3547 arg = AREF (font_object, FONT_NAME_INDEX);
3548 fontset = FRAME_FONTSET (f);
3549 /* Check if we can use the current fontset. If not, set FONTSET
3550 to -1 to generate a new fontset from FONT-OBJECT. */
3551 if (fontset >= 0)
3553 Lisp_Object ascii_font = fontset_ascii (fontset);
3554 Lisp_Object spec = font_spec_from_name (ascii_font);
3556 if (NILP (spec))
3557 signal_error ("Invalid font name", ascii_font);
3559 if (! font_match_p (spec, font_object))
3560 fontset = -1;
3563 else
3564 signal_error ("Invalid font", arg);
3566 if (! NILP (Fequal (font_object, oldval)))
3567 return;
3569 x_new_font (f, font_object, fontset);
3570 store_frame_param (f, Qfont, arg);
3571 #ifdef HAVE_X_WINDOWS
3572 store_frame_param (f, Qfont_param, font_param);
3573 #endif
3574 /* Recalculate toolbar height. */
3575 f->n_tool_bar_rows = 0;
3577 /* Ensure we redraw it. */
3578 clear_current_matrices (f);
3580 /* Attempt to hunt down bug#16028. */
3581 SET_FRAME_GARBAGED (f);
3583 recompute_basic_faces (f);
3585 do_pending_window_change (0);
3587 /* We used to call face-set-after-frame-default here, but it leads to
3588 recursive calls (since that function can set the `default' face's
3589 font which in turns changes the frame's `font' parameter).
3590 Also I don't know what this call is meant to do, but it seems the
3591 wrong way to do it anyway (it does a lot more work than what seems
3592 reasonable in response to a change to `font'). */
3596 void
3597 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3599 if (! NILP (new_value)
3600 && !CONSP (new_value))
3602 char *p0, *p1;
3604 CHECK_STRING (new_value);
3605 p0 = p1 = SSDATA (new_value);
3606 new_value = Qnil;
3607 while (*p0)
3609 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3610 if (p0 < p1)
3611 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3612 new_value);
3613 if (*p1)
3615 int c;
3617 while ((c = *++p1) && c_isspace (c));
3619 p0 = p1;
3621 new_value = Fnreverse (new_value);
3624 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3625 return;
3627 if (FRAME_FONT (f))
3628 free_all_realized_faces (Qnil);
3630 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3631 if (NILP (new_value))
3633 if (NILP (old_value))
3634 error ("No font backend available");
3635 font_update_drivers (f, old_value);
3636 error ("None of specified font backends are available");
3638 store_frame_param (f, Qfont_backend, new_value);
3640 if (FRAME_FONT (f))
3642 Lisp_Object frame;
3644 XSETFRAME (frame, f);
3645 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3646 ++face_change_count;
3647 windows_or_buffers_changed = 18;
3651 void
3652 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3654 int unit = FRAME_COLUMN_WIDTH (f);
3655 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3656 int new_width;
3658 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3659 ? eabs (XINT (new_value)) : 8);
3661 if (new_width != old_width)
3663 FRAME_LEFT_FRINGE_WIDTH (f) = new_width;
3664 FRAME_FRINGE_COLS (f) /* Round up. */
3665 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3667 if (FRAME_X_WINDOW (f) != 0)
3668 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
3670 SET_FRAME_GARBAGED (f);
3675 void
3676 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3678 int unit = FRAME_COLUMN_WIDTH (f);
3679 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3680 int new_width;
3682 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3683 ? eabs (XINT (new_value)) : 8);
3685 if (new_width != old_width)
3687 FRAME_RIGHT_FRINGE_WIDTH (f) = new_width;
3688 FRAME_FRINGE_COLS (f) /* Round up. */
3689 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3691 if (FRAME_X_WINDOW (f) != 0)
3692 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
3694 SET_FRAME_GARBAGED (f);
3699 void
3700 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3702 CHECK_TYPE_RANGED_INTEGER (int, arg);
3704 if (XINT (arg) == f->border_width)
3705 return;
3707 if (FRAME_X_WINDOW (f) != 0)
3708 error ("Cannot change the border width of a frame");
3710 f->border_width = XINT (arg);
3713 void
3714 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3716 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3718 CHECK_TYPE_RANGED_INTEGER (int, arg);
3719 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3720 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3721 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3722 if (FRAME_RIGHT_DIVIDER_WIDTH (f) != old)
3724 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
3725 adjust_frame_glyphs (f);
3726 SET_FRAME_GARBAGED (f);
3731 void
3732 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3734 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3736 CHECK_TYPE_RANGED_INTEGER (int, arg);
3737 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3738 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3739 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3740 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) != old)
3742 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
3743 adjust_frame_glyphs (f);
3744 SET_FRAME_GARBAGED (f);
3748 void
3749 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3751 Lisp_Object frame;
3752 XSETFRAME (frame, f);
3754 if (NILP (value))
3755 Fmake_frame_invisible (frame, Qt);
3756 else if (EQ (value, Qicon))
3757 Ficonify_frame (frame);
3758 else
3759 Fmake_frame_visible (frame);
3762 void
3763 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3765 f->auto_raise = !EQ (Qnil, arg);
3768 void
3769 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3771 f->auto_lower = !EQ (Qnil, arg);
3774 void
3775 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3777 f->no_split = !NILP (arg);
3780 void
3781 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3783 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3784 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3785 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3786 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3788 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3789 = (NILP (arg)
3790 ? vertical_scroll_bar_none
3791 : EQ (Qleft, arg)
3792 ? vertical_scroll_bar_left
3793 : EQ (Qright, arg)
3794 ? vertical_scroll_bar_right
3795 : EQ (Qleft, Vdefault_frame_scroll_bars)
3796 ? vertical_scroll_bar_left
3797 : EQ (Qright, Vdefault_frame_scroll_bars)
3798 ? vertical_scroll_bar_right
3799 : vertical_scroll_bar_none);
3801 /* We set this parameter before creating the X window for the
3802 frame, so we can get the geometry right from the start.
3803 However, if the window hasn't been created yet, we shouldn't
3804 call x_set_window_size. */
3805 if (FRAME_X_WINDOW (f))
3806 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
3808 SET_FRAME_GARBAGED (f);
3812 void
3813 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3815 #if USE_HORIZONTAL_SCROLL_BARS
3816 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3817 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3819 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3821 /* We set this parameter before creating the X window for the
3822 frame, so we can get the geometry right from the start.
3823 However, if the window hasn't been created yet, we shouldn't
3824 call x_set_window_size. */
3825 if (FRAME_X_WINDOW (f))
3826 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
3828 SET_FRAME_GARBAGED (f);
3830 #endif
3833 void
3834 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3836 int unit = FRAME_COLUMN_WIDTH (f);
3838 if (NILP (arg))
3840 x_set_scroll_bar_default_width (f);
3842 if (FRAME_X_WINDOW (f))
3843 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3845 SET_FRAME_GARBAGED (f);
3847 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3848 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3850 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3851 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3852 if (FRAME_X_WINDOW (f))
3853 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3855 SET_FRAME_GARBAGED (f);
3858 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3859 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3862 void
3863 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3865 #if USE_HORIZONTAL_SCROLL_BARS
3866 int unit = FRAME_LINE_HEIGHT (f);
3868 if (NILP (arg))
3870 x_set_scroll_bar_default_height (f);
3872 if (FRAME_X_WINDOW (f))
3873 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3875 SET_FRAME_GARBAGED (f);
3877 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3878 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3880 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3881 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3882 if (FRAME_X_WINDOW (f))
3883 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3885 SET_FRAME_GARBAGED (f);
3888 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3889 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3890 #endif
3893 void
3894 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3896 double alpha = 1.0;
3897 double newval[2];
3898 int i;
3899 Lisp_Object item;
3901 for (i = 0; i < 2; i++)
3903 newval[i] = 1.0;
3904 if (CONSP (arg))
3906 item = CAR (arg);
3907 arg = CDR (arg);
3909 else
3910 item = arg;
3912 if (NILP (item))
3913 alpha = - 1.0;
3914 else if (FLOATP (item))
3916 alpha = XFLOAT_DATA (item);
3917 if (! (0 <= alpha && alpha <= 1.0))
3918 args_out_of_range (make_float (0.0), make_float (1.0));
3920 else if (INTEGERP (item))
3922 EMACS_INT ialpha = XINT (item);
3923 if (! (0 <= ialpha && alpha <= 100))
3924 args_out_of_range (make_number (0), make_number (100));
3925 alpha = ialpha / 100.0;
3927 else
3928 wrong_type_argument (Qnumberp, item);
3929 newval[i] = alpha;
3932 for (i = 0; i < 2; i++)
3933 f->alpha[i] = newval[i];
3935 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3936 block_input ();
3937 x_set_frame_alpha (f);
3938 unblock_input ();
3939 #endif
3941 return;
3944 #ifndef HAVE_NS
3946 /* Non-zero if mouse is grabbed on DPYINFO
3947 and we know the frame where it is. */
3949 bool x_mouse_grabbed (Display_Info *dpyinfo)
3951 return (dpyinfo->grabbed
3952 && dpyinfo->last_mouse_frame
3953 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
3956 /* Re-highlight something with mouse-face properties
3957 on DPYINFO using saved frame and mouse position. */
3959 void
3960 x_redo_mouse_highlight (Display_Info *dpyinfo)
3962 if (dpyinfo->last_mouse_motion_frame
3963 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
3964 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
3965 dpyinfo->last_mouse_motion_x,
3966 dpyinfo->last_mouse_motion_y);
3969 #endif /* HAVE_NS */
3971 /* Subroutines of creating an X frame. */
3973 /* Make sure that Vx_resource_name is set to a reasonable value.
3974 Fix it up, or set it to `emacs' if it is too hopeless. */
3976 void
3977 validate_x_resource_name (void)
3979 ptrdiff_t len = 0;
3980 /* Number of valid characters in the resource name. */
3981 ptrdiff_t good_count = 0;
3982 /* Number of invalid characters in the resource name. */
3983 ptrdiff_t bad_count = 0;
3984 Lisp_Object new;
3985 ptrdiff_t i;
3987 if (!STRINGP (Vx_resource_class))
3988 Vx_resource_class = build_string (EMACS_CLASS);
3990 if (STRINGP (Vx_resource_name))
3992 unsigned char *p = SDATA (Vx_resource_name);
3994 len = SBYTES (Vx_resource_name);
3996 /* Only letters, digits, - and _ are valid in resource names.
3997 Count the valid characters and count the invalid ones. */
3998 for (i = 0; i < len; i++)
4000 int c = p[i];
4001 if (! ((c >= 'a' && c <= 'z')
4002 || (c >= 'A' && c <= 'Z')
4003 || (c >= '0' && c <= '9')
4004 || c == '-' || c == '_'))
4005 bad_count++;
4006 else
4007 good_count++;
4010 else
4011 /* Not a string => completely invalid. */
4012 bad_count = 5, good_count = 0;
4014 /* If name is valid already, return. */
4015 if (bad_count == 0)
4016 return;
4018 /* If name is entirely invalid, or nearly so, or is so implausibly
4019 large that alloca might not work, use `emacs'. */
4020 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4022 Vx_resource_name = build_string ("emacs");
4023 return;
4026 /* Name is partly valid. Copy it and replace the invalid characters
4027 with underscores. */
4029 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4031 for (i = 0; i < len; i++)
4033 int c = SREF (new, i);
4034 if (! ((c >= 'a' && c <= 'z')
4035 || (c >= 'A' && c <= 'Z')
4036 || (c >= '0' && c <= '9')
4037 || c == '-' || c == '_'))
4038 SSET (new, i, '_');
4042 /* Get specified attribute from resource database RDB.
4043 See Fx_get_resource below for other parameters. */
4045 static Lisp_Object
4046 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4048 CHECK_STRING (attribute);
4049 CHECK_STRING (class);
4051 if (!NILP (component))
4052 CHECK_STRING (component);
4053 if (!NILP (subclass))
4054 CHECK_STRING (subclass);
4055 if (NILP (component) != NILP (subclass))
4056 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4058 validate_x_resource_name ();
4060 /* Allocate space for the components, the dots which separate them,
4061 and the final '\0'. Make them big enough for the worst case. */
4062 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4063 + (STRINGP (component)
4064 ? SBYTES (component) : 0)
4065 + SBYTES (attribute)
4066 + 3);
4068 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4069 + SBYTES (class)
4070 + (STRINGP (subclass)
4071 ? SBYTES (subclass) : 0)
4072 + 3);
4073 USE_SAFE_ALLOCA;
4074 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4075 char *class_key = name_key + name_keysize;
4077 /* Start with emacs.FRAMENAME for the name (the specific one)
4078 and with `Emacs' for the class key (the general one). */
4079 char *nz = lispstpcpy (name_key, Vx_resource_name);
4080 char *cz = lispstpcpy (class_key, Vx_resource_class);
4082 *cz++ = '.';
4083 cz = lispstpcpy (cz, class);
4085 if (!NILP (component))
4087 *cz++ = '.';
4088 lispstpcpy (cz, subclass);
4090 *nz++ = '.';
4091 nz = lispstpcpy (nz, component);
4094 *nz++ = '.';
4095 lispstpcpy (nz, attribute);
4097 char *value = x_get_string_resource (rdb, name_key, class_key);
4098 SAFE_FREE();
4100 if (value && *value)
4101 return build_string (value);
4102 else
4103 return Qnil;
4107 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4108 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4109 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4110 class, where INSTANCE is the name under which Emacs was invoked, or
4111 the name specified by the `-name' or `-rn' command-line arguments.
4113 The optional arguments COMPONENT and SUBCLASS add to the key and the
4114 class, respectively. You must specify both of them or neither.
4115 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4116 and the class is `Emacs.CLASS.SUBCLASS'. */)
4117 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4118 Lisp_Object subclass)
4120 check_window_system (NULL);
4122 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4123 attribute, class, component, subclass);
4126 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4128 Lisp_Object
4129 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4130 Lisp_Object class, Lisp_Object component,
4131 Lisp_Object subclass)
4133 return xrdb_get_resource (dpyinfo->xrdb,
4134 attribute, class, component, subclass);
4137 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
4138 /* Used when C code wants a resource value. */
4139 /* Called from oldXMenu/Create.c. */
4140 char *
4141 x_get_resource_string (const char *attribute, const char *class)
4143 char *result;
4144 struct frame *sf = SELECTED_FRAME ();
4145 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4146 USE_SAFE_ALLOCA;
4148 /* Allocate space for the components, the dots which separate them,
4149 and the final '\0'. */
4150 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4151 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4152 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4153 char *class_key = name_key + name_keysize;
4155 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4156 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4158 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4159 name_key, class_key);
4160 SAFE_FREE ();
4161 return result;
4163 #endif
4165 /* Return the value of parameter PARAM.
4167 First search ALIST, then Vdefault_frame_alist, then the X defaults
4168 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4170 Convert the resource to the type specified by desired_type.
4172 If no default is specified, return Qunbound. If you call
4173 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4174 and don't let it get stored in any Lisp-visible variables! */
4176 Lisp_Object
4177 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4178 const char *attribute, const char *class, enum resource_types type)
4180 Lisp_Object tem;
4182 tem = Fassq (param, alist);
4184 if (!NILP (tem))
4186 /* If we find this parm in ALIST, clear it out
4187 so that it won't be "left over" at the end. */
4188 Lisp_Object tail;
4189 XSETCAR (tem, Qnil);
4190 /* In case the parameter appears more than once in the alist,
4191 clear it out. */
4192 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4193 if (CONSP (XCAR (tail))
4194 && EQ (XCAR (XCAR (tail)), param))
4195 XSETCAR (XCAR (tail), Qnil);
4197 else
4198 tem = Fassq (param, Vdefault_frame_alist);
4200 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4201 look in the X resources. */
4202 if (EQ (tem, Qnil))
4204 if (attribute && dpyinfo)
4206 AUTO_STRING (at, attribute);
4207 AUTO_STRING (cl, class);
4208 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4210 if (NILP (tem))
4211 return Qunbound;
4213 switch (type)
4215 case RES_TYPE_NUMBER:
4216 return make_number (atoi (SSDATA (tem)));
4218 case RES_TYPE_BOOLEAN_NUMBER:
4219 if (!strcmp (SSDATA (tem), "on")
4220 || !strcmp (SSDATA (tem), "true"))
4221 return make_number (1);
4222 return make_number (atoi (SSDATA (tem)));
4223 break;
4225 case RES_TYPE_FLOAT:
4226 return make_float (atof (SSDATA (tem)));
4228 case RES_TYPE_BOOLEAN:
4229 tem = Fdowncase (tem);
4230 if (!strcmp (SSDATA (tem), "on")
4231 #ifdef HAVE_NS
4232 || !strcmp (SSDATA (tem), "yes")
4233 #endif
4234 || !strcmp (SSDATA (tem), "true"))
4235 return Qt;
4236 else
4237 return Qnil;
4239 case RES_TYPE_STRING:
4240 return tem;
4242 case RES_TYPE_SYMBOL:
4243 /* As a special case, we map the values `true' and `on'
4244 to Qt, and `false' and `off' to Qnil. */
4246 Lisp_Object lower;
4247 lower = Fdowncase (tem);
4248 if (!strcmp (SSDATA (lower), "on")
4249 #ifdef HAVE_NS
4250 || !strcmp (SSDATA (lower), "yes")
4251 #endif
4252 || !strcmp (SSDATA (lower), "true"))
4253 return Qt;
4254 else if (!strcmp (SSDATA (lower), "off")
4255 #ifdef HAVE_NS
4256 || !strcmp (SSDATA (lower), "no")
4257 #endif
4258 || !strcmp (SSDATA (lower), "false"))
4259 return Qnil;
4260 else
4261 return Fintern (tem, Qnil);
4264 default:
4265 emacs_abort ();
4268 else
4269 return Qunbound;
4271 return Fcdr (tem);
4274 static Lisp_Object
4275 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4276 const char *attribute, const char *class,
4277 enum resource_types type)
4279 return x_get_arg (FRAME_DISPLAY_INFO (f),
4280 alist, param, attribute, class, type);
4283 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4285 Lisp_Object
4286 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4287 Lisp_Object param,
4288 const char *attribute, const char *class,
4289 enum resource_types type)
4291 Lisp_Object value;
4293 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4294 attribute, class, type);
4295 if (! NILP (value) && ! EQ (value, Qunbound))
4296 store_frame_param (f, param, value);
4298 return value;
4302 /* Record in frame F the specified or default value according to ALIST
4303 of the parameter named PROP (a Lisp symbol).
4304 If no value is specified for PROP, look for an X default for XPROP
4305 on the frame named NAME.
4306 If that is not found either, use the value DEFLT. */
4308 Lisp_Object
4309 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4310 Lisp_Object deflt, const char *xprop, const char *xclass,
4311 enum resource_types type)
4313 Lisp_Object tem;
4315 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4316 if (EQ (tem, Qunbound))
4317 tem = deflt;
4318 AUTO_FRAME_ARG (arg, prop, tem);
4319 x_set_frame_parameters (f, arg);
4320 return tem;
4324 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4327 * XParseGeometry parses strings of the form
4328 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4329 * width, height, xoffset, and yoffset are unsigned integers.
4330 * Example: "=80x24+300-49"
4331 * The equal sign is optional.
4332 * It returns a bitmask that indicates which of the four values
4333 * were actually found in the string. For each value found,
4334 * the corresponding argument is updated; for each value
4335 * not found, the corresponding argument is left unchanged.
4338 static int
4339 XParseGeometry (char *string,
4340 int *x, int *y,
4341 unsigned int *width, unsigned int *height)
4343 int mask = NoValue;
4344 char *strind;
4345 unsigned long tempWidth, tempHeight;
4346 long int tempX, tempY;
4347 char *nextCharacter;
4349 if (string == NULL || *string == '\0')
4350 return mask;
4351 if (*string == '=')
4352 string++; /* ignore possible '=' at beg of geometry spec */
4354 strind = string;
4355 if (*strind != '+' && *strind != '-' && *strind != 'x')
4357 tempWidth = strtoul (strind, &nextCharacter, 10);
4358 if (strind == nextCharacter)
4359 return 0;
4360 strind = nextCharacter;
4361 mask |= WidthValue;
4364 if (*strind == 'x' || *strind == 'X')
4366 strind++;
4367 tempHeight = strtoul (strind, &nextCharacter, 10);
4368 if (strind == nextCharacter)
4369 return 0;
4370 strind = nextCharacter;
4371 mask |= HeightValue;
4374 if (*strind == '+' || *strind == '-')
4376 if (*strind == '-')
4377 mask |= XNegative;
4378 tempX = strtol (strind, &nextCharacter, 10);
4379 if (strind == nextCharacter)
4380 return 0;
4381 strind = nextCharacter;
4382 mask |= XValue;
4383 if (*strind == '+' || *strind == '-')
4385 if (*strind == '-')
4386 mask |= YNegative;
4387 tempY = strtol (strind, &nextCharacter, 10);
4388 if (strind == nextCharacter)
4389 return 0;
4390 strind = nextCharacter;
4391 mask |= YValue;
4395 /* If strind isn't at the end of the string then it's an invalid
4396 geometry specification. */
4398 if (*strind != '\0')
4399 return 0;
4401 if (mask & XValue)
4402 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4403 if (mask & YValue)
4404 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4405 if (mask & WidthValue)
4406 *width = min (tempWidth, UINT_MAX);
4407 if (mask & HeightValue)
4408 *height = min (tempHeight, UINT_MAX);
4409 return mask;
4412 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4415 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4416 make-docfile: the documentation string in ns-win.el was used for
4417 x-parse-geometry even in non-NS builds.
4419 With two definitions of x-parse-geometry in this file, various
4420 things still get confused (eg M-x apropos documentation), so that
4421 it is best if the two definitions just share the same doc-string.
4423 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4424 doc: /* Parse a display geometry string STRING.
4425 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4426 The properties returned may include `top', `left', `height', and `width'.
4427 For X, the value of `left' or `top' may be an integer,
4428 or a list (+ N) meaning N pixels relative to top/left corner,
4429 or a list (- N) meaning -N pixels relative to bottom/right corner.
4430 On Nextstep, this just calls `ns-parse-geometry'. */)
4431 (Lisp_Object string)
4433 int geometry, x, y;
4434 unsigned int width, height;
4435 Lisp_Object result;
4437 CHECK_STRING (string);
4439 #ifdef HAVE_NS
4440 if (strchr (SSDATA (string), ' ') != NULL)
4441 return call1 (Qns_parse_geometry, string);
4442 #endif
4443 geometry = XParseGeometry (SSDATA (string),
4444 &x, &y, &width, &height);
4445 result = Qnil;
4446 if (geometry & XValue)
4448 Lisp_Object element;
4450 if (x >= 0 && (geometry & XNegative))
4451 element = list3 (Qleft, Qminus, make_number (-x));
4452 else if (x < 0 && ! (geometry & XNegative))
4453 element = list3 (Qleft, Qplus, make_number (x));
4454 else
4455 element = Fcons (Qleft, make_number (x));
4456 result = Fcons (element, result);
4459 if (geometry & YValue)
4461 Lisp_Object element;
4463 if (y >= 0 && (geometry & YNegative))
4464 element = list3 (Qtop, Qminus, make_number (-y));
4465 else if (y < 0 && ! (geometry & YNegative))
4466 element = list3 (Qtop, Qplus, make_number (y));
4467 else
4468 element = Fcons (Qtop, make_number (y));
4469 result = Fcons (element, result);
4472 if (geometry & WidthValue)
4473 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4474 if (geometry & HeightValue)
4475 result = Fcons (Fcons (Qheight, make_number (height)), result);
4477 return result;
4481 /* Calculate the desired size and position of frame F.
4482 Return the flags saying which aspects were specified.
4484 Also set the win_gravity and size_hint_flags of F.
4486 Adjust height for toolbar if TOOLBAR_P is 1.
4488 This function does not make the coordinates positive. */
4490 #define DEFAULT_ROWS 35
4491 #define DEFAULT_COLS 80
4493 long
4494 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p)
4496 Lisp_Object height, width, user_size, top, left, user_position;
4497 long window_prompting = 0;
4498 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4500 /* Default values if we fall through.
4501 Actually, if that happens we should get
4502 window manager prompting. */
4503 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4504 SET_FRAME_COLS (f, DEFAULT_COLS);
4505 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4506 SET_FRAME_LINES (f, DEFAULT_ROWS);
4508 /* Window managers expect that if program-specified
4509 positions are not (0,0), they're intentional, not defaults. */
4510 f->top_pos = 0;
4511 f->left_pos = 0;
4513 /* Ensure that earlier new_width and new_height settings won't
4514 override what we specify below. */
4515 f->new_width = f->new_height = 0;
4517 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4518 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4519 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4521 if (!EQ (width, Qunbound))
4523 CHECK_NUMBER (width);
4524 if (! (0 <= XINT (width) && XINT (width) <= INT_MAX))
4525 xsignal1 (Qargs_out_of_range, width);
4527 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4530 if (!EQ (height, Qunbound))
4532 CHECK_NUMBER (height);
4533 if (! (0 <= XINT (height) && XINT (height) <= INT_MAX))
4534 xsignal1 (Qargs_out_of_range, height);
4536 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4539 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4540 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4541 window_prompting |= USSize;
4542 else
4543 window_prompting |= PSize;
4546 /* Add a tool bar height to the initial frame height so that the user
4547 gets a text display area of the size he specified with -g or via
4548 .Xdefaults. Later changes of the tool bar height don't change the
4549 frame size. This is done so that users can create tall Emacs
4550 frames without having to guess how tall the tool bar will get. */
4551 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4553 int margin, relief;
4555 relief = (tool_bar_button_relief >= 0
4556 ? tool_bar_button_relief
4557 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4559 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4560 margin = XFASTINT (Vtool_bar_button_margin);
4561 else if (CONSP (Vtool_bar_button_margin)
4562 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4563 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4564 else
4565 margin = 0;
4567 FRAME_TOOL_BAR_HEIGHT (f)
4568 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4569 Vframe_initial_frame_tool_bar_height = make_number (FRAME_TOOL_BAR_HEIGHT (f));
4572 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4573 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4574 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4575 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4577 if (EQ (top, Qminus))
4579 f->top_pos = 0;
4580 window_prompting |= YNegative;
4582 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4583 && CONSP (XCDR (top))
4584 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4586 f->top_pos = - XINT (XCAR (XCDR (top)));
4587 window_prompting |= YNegative;
4589 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4590 && CONSP (XCDR (top))
4591 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4593 f->top_pos = XINT (XCAR (XCDR (top)));
4595 else if (EQ (top, Qunbound))
4596 f->top_pos = 0;
4597 else
4599 CHECK_TYPE_RANGED_INTEGER (int, top);
4600 f->top_pos = XINT (top);
4601 if (f->top_pos < 0)
4602 window_prompting |= YNegative;
4605 if (EQ (left, Qminus))
4607 f->left_pos = 0;
4608 window_prompting |= XNegative;
4610 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4611 && CONSP (XCDR (left))
4612 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4614 f->left_pos = - XINT (XCAR (XCDR (left)));
4615 window_prompting |= XNegative;
4617 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4618 && CONSP (XCDR (left))
4619 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4621 f->left_pos = XINT (XCAR (XCDR (left)));
4623 else if (EQ (left, Qunbound))
4624 f->left_pos = 0;
4625 else
4627 CHECK_TYPE_RANGED_INTEGER (int, left);
4628 f->left_pos = XINT (left);
4629 if (f->left_pos < 0)
4630 window_prompting |= XNegative;
4633 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4634 window_prompting |= USPosition;
4635 else
4636 window_prompting |= PPosition;
4639 if (window_prompting & XNegative)
4641 if (window_prompting & YNegative)
4642 f->win_gravity = SouthEastGravity;
4643 else
4644 f->win_gravity = NorthEastGravity;
4646 else
4648 if (window_prompting & YNegative)
4649 f->win_gravity = SouthWestGravity;
4650 else
4651 f->win_gravity = NorthWestGravity;
4654 f->size_hint_flags = window_prompting;
4656 return window_prompting;
4661 #endif /* HAVE_WINDOW_SYSTEM */
4663 void
4664 frame_make_pointer_invisible (struct frame *f)
4666 if (! NILP (Vmake_pointer_invisible))
4668 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4669 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4671 f->mouse_moved = 0;
4672 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4673 f->pointer_invisible = 1;
4678 void
4679 frame_make_pointer_visible (struct frame *f)
4681 /* We don't check Vmake_pointer_invisible here in case the
4682 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4683 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4684 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4686 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4687 f->pointer_invisible = 0;
4691 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4692 Sframe_pointer_visible_p, 0, 1, 0,
4693 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4694 Otherwise it returns nil. FRAME omitted or nil means the
4695 selected frame. This is useful when `make-pointer-invisible' is set. */)
4696 (Lisp_Object frame)
4698 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4703 /***********************************************************************
4704 Multimonitor data
4705 ***********************************************************************/
4707 #ifdef HAVE_WINDOW_SYSTEM
4709 # if (defined HAVE_NS \
4710 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4711 void
4712 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4714 int i;
4715 for (i = 0; i < n_monitors; ++i)
4716 xfree (monitors[i].name);
4717 xfree (monitors);
4719 # endif
4721 Lisp_Object
4722 make_monitor_attribute_list (struct MonitorInfo *monitors,
4723 int n_monitors,
4724 int primary_monitor,
4725 Lisp_Object monitor_frames,
4726 const char *source)
4728 Lisp_Object attributes_list = Qnil;
4729 Lisp_Object primary_monitor_attributes = Qnil;
4730 int i;
4732 for (i = 0; i < n_monitors; ++i)
4734 Lisp_Object geometry, workarea, attributes = Qnil;
4735 struct MonitorInfo *mi = &monitors[i];
4737 if (mi->geom.width == 0) continue;
4739 workarea = list4i (mi->work.x, mi->work.y,
4740 mi->work.width, mi->work.height);
4741 geometry = list4i (mi->geom.x, mi->geom.y,
4742 mi->geom.width, mi->geom.height);
4743 attributes = Fcons (Fcons (Qsource, build_string (source)),
4744 attributes);
4745 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4746 attributes);
4747 attributes = Fcons (Fcons (Qmm_size,
4748 list2i (mi->mm_width, mi->mm_height)),
4749 attributes);
4750 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4751 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4752 if (mi->name)
4753 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4754 strlen (mi->name))),
4755 attributes);
4757 if (i == primary_monitor)
4758 primary_monitor_attributes = attributes;
4759 else
4760 attributes_list = Fcons (attributes, attributes_list);
4763 if (!NILP (primary_monitor_attributes))
4764 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4765 return attributes_list;
4768 #endif /* HAVE_WINDOW_SYSTEM */
4771 /***********************************************************************
4772 Initialization
4773 ***********************************************************************/
4775 void
4776 syms_of_frame (void)
4778 DEFSYM (Qframep, "framep");
4779 DEFSYM (Qframe_live_p, "frame-live-p");
4780 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4781 DEFSYM (Qexplicit_name, "explicit-name");
4782 DEFSYM (Qheight, "height");
4783 DEFSYM (Qicon, "icon");
4784 DEFSYM (Qminibuffer, "minibuffer");
4785 DEFSYM (Qmodeline, "modeline");
4786 DEFSYM (Qonly, "only");
4787 DEFSYM (Qnone, "none");
4788 DEFSYM (Qwidth, "width");
4789 DEFSYM (Qgeometry, "geometry");
4790 DEFSYM (Qicon_left, "icon-left");
4791 DEFSYM (Qicon_top, "icon-top");
4792 DEFSYM (Qtooltip, "tooltip");
4793 DEFSYM (Quser_position, "user-position");
4794 DEFSYM (Quser_size, "user-size");
4795 DEFSYM (Qwindow_id, "window-id");
4796 #ifdef HAVE_X_WINDOWS
4797 DEFSYM (Qouter_window_id, "outer-window-id");
4798 #endif
4799 DEFSYM (Qparent_id, "parent-id");
4800 DEFSYM (Qx, "x");
4801 DEFSYM (Qw32, "w32");
4802 DEFSYM (Qpc, "pc");
4803 DEFSYM (Qns, "ns");
4804 DEFSYM (Qvisible, "visible");
4805 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4806 DEFSYM (Qbuffer_list, "buffer-list");
4807 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4808 DEFSYM (Qdisplay_type, "display-type");
4809 DEFSYM (Qbackground_mode, "background-mode");
4810 DEFSYM (Qnoelisp, "noelisp");
4811 DEFSYM (Qtty_color_mode, "tty-color-mode");
4812 DEFSYM (Qtty, "tty");
4813 DEFSYM (Qtty_type, "tty-type");
4815 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4817 DEFSYM (Qfullwidth, "fullwidth");
4818 DEFSYM (Qfullheight, "fullheight");
4819 DEFSYM (Qfullboth, "fullboth");
4820 DEFSYM (Qmaximized, "maximized");
4821 DEFSYM (Qx_resource_name, "x-resource-name");
4822 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4824 DEFSYM (Qterminal, "terminal");
4826 DEFSYM (Qworkarea, "workarea");
4827 DEFSYM (Qmm_size, "mm-size");
4828 DEFSYM (Qframes, "frames");
4829 DEFSYM (Qsource, "source");
4831 DEFSYM (Qframe_position, "frame-position");
4832 DEFSYM (Qframe_outer_size, "frame-outer-size");
4833 DEFSYM (Qexternal_border_size, "external-border-size");
4834 DEFSYM (Qtitle_height, "title-height");
4835 DEFSYM (Qmenu_bar_external, "menu-bar-external");
4836 DEFSYM (Qmenu_bar_size, "menu-bar-size");
4837 DEFSYM (Qtool_bar_external, "tool-bar-external");
4838 DEFSYM (Qtool_bar_size, "tool-bar-size");
4839 DEFSYM (Qframe_inner_size, "frame-inner-size");
4841 #ifdef HAVE_NS
4842 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4843 #endif
4846 int i;
4848 for (i = 0; i < ARRAYELTS (frame_parms); i++)
4850 Lisp_Object v = intern_c_string (frame_parms[i].name);
4851 if (frame_parms[i].variable)
4853 *frame_parms[i].variable = v;
4854 staticpro (frame_parms[i].variable);
4856 Fput (v, Qx_frame_parameter, make_number (i));
4860 #ifdef HAVE_WINDOW_SYSTEM
4861 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4862 doc: /* The name Emacs uses to look up X resources.
4863 `x-get-resource' uses this as the first component of the instance name
4864 when requesting resource values.
4865 Emacs initially sets `x-resource-name' to the name under which Emacs
4866 was invoked, or to the value specified with the `-name' or `-rn'
4867 switches, if present.
4869 It may be useful to bind this variable locally around a call
4870 to `x-get-resource'. See also the variable `x-resource-class'. */);
4871 Vx_resource_name = Qnil;
4873 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4874 doc: /* The class Emacs uses to look up X resources.
4875 `x-get-resource' uses this as the first component of the instance class
4876 when requesting resource values.
4878 Emacs initially sets `x-resource-class' to "Emacs".
4880 Setting this variable permanently is not a reasonable thing to do,
4881 but binding this variable locally around a call to `x-get-resource'
4882 is a reasonable practice. See also the variable `x-resource-name'. */);
4883 Vx_resource_class = build_string (EMACS_CLASS);
4885 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4886 doc: /* The lower limit of the frame opacity (alpha transparency).
4887 The value should range from 0 (invisible) to 100 (completely opaque).
4888 You can also use a floating number between 0.0 and 1.0. */);
4889 Vframe_alpha_lower_limit = make_number (20);
4890 #endif
4892 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4893 doc: /* Alist of default values for frame creation.
4894 These may be set in your init file, like this:
4895 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4896 These override values given in window system configuration data,
4897 including X Windows' defaults database.
4898 For values specific to the first Emacs frame, see `initial-frame-alist'.
4899 For window-system specific values, see `window-system-default-frame-alist'.
4900 For values specific to the separate minibuffer frame, see
4901 `minibuffer-frame-alist'.
4902 The `menu-bar-lines' element of the list controls whether new frames
4903 have menu bars; `menu-bar-mode' works by altering this element.
4904 Setting this variable does not affect existing frames, only new ones. */);
4905 Vdefault_frame_alist = Qnil;
4907 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4908 doc: /* Default position of vertical scroll bars on this window-system. */);
4909 #ifdef HAVE_WINDOW_SYSTEM
4910 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4911 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4912 default. */
4913 Vdefault_frame_scroll_bars = Qright;
4914 #else
4915 Vdefault_frame_scroll_bars = Qleft;
4916 #endif
4917 #else
4918 Vdefault_frame_scroll_bars = Qnil;
4919 #endif
4921 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
4922 scroll_bar_adjust_thumb_portion_p,
4923 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
4924 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
4925 even if the end of the buffer is shown (i.e. overscrolling).
4926 Set to nil if you want the thumb to be at the bottom when the end of the buffer
4927 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
4928 is visible. In this case you can not overscroll. */);
4929 scroll_bar_adjust_thumb_portion_p = 1;
4931 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4932 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4934 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4935 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4936 `mouse-position' and `mouse-pixel-position' call this function, passing their
4937 usual return value as argument, and return whatever this function returns.
4938 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4939 which need to do mouse handling at the Lisp level. */);
4940 Vmouse_position_function = Qnil;
4942 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4943 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4944 If the value is an integer, highlighting is only shown after moving the
4945 mouse, while keyboard input turns off the highlight even when the mouse
4946 is over the clickable text. However, the mouse shape still indicates
4947 when the mouse is over clickable text. */);
4948 Vmouse_highlight = Qt;
4950 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4951 doc: /* If non-nil, make pointer invisible while typing.
4952 The pointer becomes visible again when the mouse is moved. */);
4953 Vmake_pointer_invisible = Qt;
4955 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
4956 doc: /* Normal hook run when a frame gains input focus. */);
4957 Vfocus_in_hook = Qnil;
4958 DEFSYM (Qfocus_in_hook, "focus-in-hook");
4960 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
4961 doc: /* Normal hook run when a frame loses input focus. */);
4962 Vfocus_out_hook = Qnil;
4963 DEFSYM (Qfocus_out_hook, "focus-out-hook");
4965 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4966 doc: /* Functions run before deleting a frame.
4967 The functions are run with one arg, the frame to be deleted.
4968 See `delete-frame'.
4970 Note that functions in this list may be called just before the frame is
4971 actually deleted, or some time later (or even both when an earlier function
4972 in `delete-frame-functions' (indirectly) calls `delete-frame'
4973 recursively). */);
4974 Vdelete_frame_functions = Qnil;
4975 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4977 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4978 doc: /* Non-nil if Menu-Bar mode is enabled.
4979 See the command `menu-bar-mode' for a description of this minor mode.
4980 Setting this variable directly does not take effect;
4981 either customize it (see the info node `Easy Customization')
4982 or call the function `menu-bar-mode'. */);
4983 Vmenu_bar_mode = Qt;
4985 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4986 doc: /* Non-nil if Tool-Bar mode is enabled.
4987 See the command `tool-bar-mode' for a description of this minor mode.
4988 Setting this variable directly does not take effect;
4989 either customize it (see the info node `Easy Customization')
4990 or call the function `tool-bar-mode'. */);
4991 #ifdef HAVE_WINDOW_SYSTEM
4992 Vtool_bar_mode = Qt;
4993 #else
4994 Vtool_bar_mode = Qnil;
4995 #endif
4997 DEFVAR_LISP ("frame-initial-frame-tool-bar-height", Vframe_initial_frame_tool_bar_height,
4998 doc: /* Height of tool bar of initial frame. */);
4999 Vframe_initial_frame_tool_bar_height = make_number (0);
5001 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5002 doc: /* Minibufferless frames use this frame's minibuffer.
5003 Emacs cannot create minibufferless frames unless this is set to an
5004 appropriate surrogate.
5006 Emacs consults this variable only when creating minibufferless
5007 frames; once the frame is created, it sticks with its assigned
5008 minibuffer, no matter what this variable is set to. This means that
5009 this variable doesn't necessarily say anything meaningful about the
5010 current set of frames, or where the minibuffer is currently being
5011 displayed.
5013 This variable is local to the current terminal and cannot be buffer-local. */);
5015 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
5016 doc: /* Non-nil if window system changes focus when you move the mouse.
5017 You should set this variable to tell Emacs how your window manager
5018 handles focus, since there is no way in general for Emacs to find out
5019 automatically. See also `mouse-autoselect-window'. */);
5020 focus_follows_mouse = 0;
5022 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5023 doc: /* Non-nil means resize frames pixelwise.
5024 If this option is nil, resizing a frame rounds its sizes to the frame's
5025 current values of `frame-char-height' and `frame-char-width'. If this
5026 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5027 by one pixel.
5029 With some window managers you may have to set this to non-nil in order
5030 to set the size of a frame in pixels, to maximize frames or to make them
5031 fullscreen. To resize your initial frame pixelwise, set this option to
5032 a non-nil value in your init file. */);
5033 frame_resize_pixelwise = 0;
5035 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5036 doc: /* Whether frames should be resized implicitly.
5037 If this option is nil, setting font, menu bar, tool bar, internal
5038 borders, fringes or scroll bars of a specific frame may resize the frame
5039 in order to preserve the number of columns or lines it displays. If
5040 this option is `t', no such resizing is done. Note that the size of
5041 fullscreen and maximized frames, the height of fullheight frames and the
5042 width of fullwidth frames never change implicitly.
5044 The value of this option can be also be a list of frame parameters. In
5045 this case, resizing is inhibited when changing a parameter that appears
5046 in that list. The parameters currently handled by this option include
5047 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5048 `tool-bar-lines'.
5050 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5051 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5052 `right-fringe' is handled as if the frame contained just one live
5053 window. This means, for example, that removing vertical scroll bars on
5054 a frame containing several side by side windows will shrink the frame
5055 width by the width of one scroll bar provided this option is nil and
5056 keep it unchanged if this option is either `t' or a list containing
5057 `vertical-scroll-bars'.
5059 The default value is '(tool-bar-lines) on Lucid, Motif and Windows
5060 (which means that adding/removing a tool bar does not change the frame
5061 height), nil on all other window systems including GTK+ (which means
5062 that changing any of the parameters listed above may change the size of
5063 the frame), and `t' otherwise (which means the frame size never changes
5064 implicitly when there's no window system support).
5066 Note that when a frame is not large enough to accommodate a change of
5067 any of the parameters listed above, Emacs may try to enlarge the frame
5068 even if this option is non-nil. */);
5069 #if defined (HAVE_WINDOW_SYSTEM)
5070 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
5071 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
5072 #else
5073 frame_inhibit_implied_resize = Qnil;
5074 #endif
5075 #else
5076 frame_inhibit_implied_resize = Qt;
5077 #endif
5079 staticpro (&Vframe_list);
5081 defsubr (&Sframep);
5082 defsubr (&Sframe_live_p);
5083 defsubr (&Swindow_system);
5084 defsubr (&Smake_terminal_frame);
5085 defsubr (&Shandle_switch_frame);
5086 defsubr (&Sselect_frame);
5087 defsubr (&Sselected_frame);
5088 defsubr (&Sframe_list);
5089 defsubr (&Snext_frame);
5090 defsubr (&Sprevious_frame);
5091 defsubr (&Slast_nonminibuf_frame);
5092 defsubr (&Sdelete_frame);
5093 defsubr (&Smouse_position);
5094 defsubr (&Smouse_pixel_position);
5095 defsubr (&Sset_mouse_position);
5096 defsubr (&Sset_mouse_pixel_position);
5097 #if 0
5098 defsubr (&Sframe_configuration);
5099 defsubr (&Srestore_frame_configuration);
5100 #endif
5101 defsubr (&Smake_frame_visible);
5102 defsubr (&Smake_frame_invisible);
5103 defsubr (&Siconify_frame);
5104 defsubr (&Sframe_visible_p);
5105 defsubr (&Svisible_frame_list);
5106 defsubr (&Sraise_frame);
5107 defsubr (&Slower_frame);
5108 defsubr (&Sx_focus_frame);
5109 defsubr (&Scan_run_window_configuration_change_hook);
5110 defsubr (&Sredirect_frame_focus);
5111 defsubr (&Sframe_focus);
5112 defsubr (&Sframe_parameters);
5113 defsubr (&Sframe_parameter);
5114 defsubr (&Smodify_frame_parameters);
5115 defsubr (&Sframe_char_height);
5116 defsubr (&Sframe_char_width);
5117 defsubr (&Sframe_pixel_height);
5118 defsubr (&Sframe_pixel_width);
5119 defsubr (&Sframe_text_cols);
5120 defsubr (&Sframe_text_lines);
5121 defsubr (&Sframe_total_cols);
5122 defsubr (&Sframe_total_lines);
5123 defsubr (&Sframe_text_width);
5124 defsubr (&Sframe_text_height);
5125 defsubr (&Sscroll_bar_width);
5126 defsubr (&Sscroll_bar_height);
5127 defsubr (&Sfringe_width);
5128 defsubr (&Sborder_width);
5129 defsubr (&Sright_divider_width);
5130 defsubr (&Sbottom_divider_width);
5131 defsubr (&Stool_bar_pixel_width);
5132 defsubr (&Sset_frame_height);
5133 defsubr (&Sset_frame_width);
5134 defsubr (&Sset_frame_size);
5135 defsubr (&Sset_frame_position);
5136 defsubr (&Sframe_pointer_visible_p);
5138 #ifdef HAVE_WINDOW_SYSTEM
5139 defsubr (&Sx_get_resource);
5140 defsubr (&Sx_parse_geometry);
5141 #endif