Try to improve handling of fullwidth/-height frames.
[emacs.git] / src / frame.c
blob96fe3778dbce0149d56461ec7dd86ceafa564849
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2015 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 /* The currently selected frame. */
60 Lisp_Object selected_frame;
62 /* A frame which is not just a mini-buffer, or NULL if there are no such
63 frames. This is usually the most recent such frame that was selected. */
65 static struct frame *last_nonminibuf_frame;
67 /* False means there are no visible garbaged frames. */
68 bool frame_garbaged;
70 /* The default tool bar height for future frames. */
71 #if defined USE_GTK || defined HAVE_NS
72 enum { frame_default_tool_bar_height = 0 };
73 #else
74 int frame_default_tool_bar_height;
75 #endif
77 #ifdef HAVE_WINDOW_SYSTEM
78 static void x_report_frame_params (struct frame *, Lisp_Object *);
79 #endif
81 /* These setters are used only in this file, so they can be private. */
82 static void
83 fset_buffer_predicate (struct frame *f, Lisp_Object val)
85 f->buffer_predicate = val;
87 static void
88 fset_minibuffer_window (struct frame *f, Lisp_Object val)
90 f->minibuffer_window = val;
93 struct frame *
94 decode_live_frame (register Lisp_Object frame)
96 if (NILP (frame))
97 frame = selected_frame;
98 CHECK_LIVE_FRAME (frame);
99 return XFRAME (frame);
102 struct frame *
103 decode_any_frame (register Lisp_Object frame)
105 if (NILP (frame))
106 frame = selected_frame;
107 CHECK_FRAME (frame);
108 return XFRAME (frame);
111 #ifdef HAVE_WINDOW_SYSTEM
113 bool
114 window_system_available (struct frame *f)
116 return f ? FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f) : x_display_list != NULL;
119 #endif /* HAVE_WINDOW_SYSTEM */
121 struct frame *
122 decode_window_system_frame (Lisp_Object frame)
124 struct frame *f = decode_live_frame (frame);
126 if (!window_system_available (f))
127 error ("Window system frame should be used");
128 return f;
131 void
132 check_window_system (struct frame *f)
134 if (!window_system_available (f))
135 error (f ? "Window system frame should be used"
136 : "Window system is not in use or not initialized");
139 /* Return the value of frame parameter PROP in frame FRAME. */
141 Lisp_Object
142 get_frame_param (register struct frame *frame, Lisp_Object prop)
144 register Lisp_Object tem;
146 tem = Fassq (prop, frame->param_alist);
147 if (EQ (tem, Qnil))
148 return tem;
149 return Fcdr (tem);
153 void
154 frame_size_history_add (struct frame *f, Lisp_Object fun_symbol,
155 int width, int height, Lisp_Object rest)
157 Lisp_Object frame;
158 int number;
160 XSETFRAME (frame, f);
161 if (CONSP (frame_size_history)
162 && NUMBERP (Fcar (frame_size_history))
163 && ((number = XINT (Fcar (frame_size_history))) > 0))
164 frame_size_history =
165 Fcons (make_number (number - 1),
166 Fcons (list4
167 (frame, fun_symbol,
168 ((width > 0)
169 ? list4 (make_number (FRAME_TEXT_WIDTH (f)),
170 make_number (FRAME_TEXT_HEIGHT (f)),
171 make_number (width),
172 make_number (height))
173 : Qnil),
174 rest),
175 Fcdr (frame_size_history)));
179 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
180 state of frame F would be affected by a vertical (horizontal if
181 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
182 parameter that is changed. */
183 bool
184 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
186 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
187 bool inhibit
188 = ((f->after_make_frame
189 && (EQ (frame_inhibit_implied_resize, Qt)
190 || (CONSP (frame_inhibit_implied_resize)
191 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))))
192 || (horizontal
193 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight))
194 || (!horizontal
195 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth))
196 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f));
198 if (inhibit && !FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
199 frame_size_history_add
200 (f, Qframe_inhibit_resize, 0, 0,
201 list5 (horizontal ? Qt : Qnil, parameter,
202 f->after_make_frame ? Qt : Qnil,
203 frame_inhibit_implied_resize,
204 fullscreen));
206 return inhibit;
209 static void
210 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
212 int nlines;
213 int olines = FRAME_MENU_BAR_LINES (f);
215 /* Right now, menu bars don't work properly in minibuf-only frames;
216 most of the commands try to apply themselves to the minibuffer
217 frame itself, and get an error because you can't switch buffers
218 in or split the minibuffer window. */
219 if (FRAME_MINIBUF_ONLY_P (f))
220 return;
222 if (TYPE_RANGED_INTEGERP (int, value))
223 nlines = XINT (value);
224 else
225 nlines = 0;
227 if (nlines != olines)
229 windows_or_buffers_changed = 14;
230 FRAME_MENU_BAR_LINES (f) = nlines;
231 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
232 change_frame_size (f, FRAME_COLS (f),
233 FRAME_LINES (f) + olines - nlines,
234 0, 1, 0, 0);
238 Lisp_Object Vframe_list;
241 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
242 doc: /* Return non-nil if OBJECT is a frame.
243 Value is:
244 t for a termcap frame (a character-only terminal),
245 'x' for an Emacs frame that is really an X window,
246 'w32' for an Emacs frame that is a window on MS-Windows display,
247 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
248 'pc' for a direct-write MS-DOS frame.
249 See also `frame-live-p'. */)
250 (Lisp_Object object)
252 if (!FRAMEP (object))
253 return Qnil;
254 switch (XFRAME (object)->output_method)
256 case output_initial: /* The initial frame is like a termcap frame. */
257 case output_termcap:
258 return Qt;
259 case output_x_window:
260 return Qx;
261 case output_w32:
262 return Qw32;
263 case output_msdos_raw:
264 return Qpc;
265 case output_ns:
266 return Qns;
267 default:
268 emacs_abort ();
272 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
273 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
274 Value is nil if OBJECT is not a live frame. If object is a live
275 frame, the return value indicates what sort of terminal device it is
276 displayed on. See the documentation of `framep' for possible
277 return values. */)
278 (Lisp_Object object)
280 return ((FRAMEP (object)
281 && FRAME_LIVE_P (XFRAME (object)))
282 ? Fframep (object)
283 : Qnil);
286 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
287 doc: /* The name of the window system that FRAME is displaying through.
288 The value is a symbol:
289 nil for a termcap frame (a character-only terminal),
290 'x' for an Emacs frame that is really an X window,
291 'w32' for an Emacs frame that is a window on MS-Windows display,
292 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
293 'pc' for a direct-write MS-DOS frame.
295 FRAME defaults to the currently selected frame.
297 Use of this function as a predicate is deprecated. Instead,
298 use `display-graphic-p' or any of the other `display-*-p'
299 predicates which report frame's specific UI-related capabilities. */)
300 (Lisp_Object frame)
302 Lisp_Object type;
303 if (NILP (frame))
304 frame = selected_frame;
306 type = Fframep (frame);
308 if (NILP (type))
309 wrong_type_argument (Qframep, frame);
311 if (EQ (type, Qt))
312 return Qnil;
313 else
314 return type;
317 /* Placeholder used by temacs -nw before window.el is loaded. */
318 DEFUN ("frame-windows-min-size", Fframe_windows_min_size,
319 Sframe_windows_min_size, 4, 4, 0,
320 doc: /* */
321 attributes: const)
322 (Lisp_Object frame, Lisp_Object horizontal,
323 Lisp_Object ignore, Lisp_Object pixelwise)
325 return make_number (0);
328 static int
329 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal,
330 Lisp_Object ignore, Lisp_Object pixelwise)
332 return XINT (call4 (Qframe_windows_min_size, frame, horizontal,
333 ignore, pixelwise));
337 /* Make sure windows sizes of frame F are OK. new_width and new_height
338 are in pixels. A value of -1 means no change is requested for that
339 size (but the frame may still have to be resized to accommodate
340 windows with their minimum sizes). This can either issue a request
341 to resize the frame externally (via x_set_window_size), to resize the
342 frame internally (via resize_frame_windows) or do nothing at all.
344 The argument INHIBIT can assume the following values:
346 0 means to unconditionally call x_set_window_size even if sizes
347 apparently do not change. Fx_create_frame uses this to pass the
348 initial size to the window manager.
350 1 means to call x_set_window_size if the outer frame size really
351 changes. Fset_frame_size, Fset_frame_height, ... use this.
353 2 means to call x_set_window_size provided frame_inhibit_resize
354 allows it. The menu and tool bar code use this ("3" won't work
355 here in general because menu and tool bar are often not counted in
356 the frame's text height).
358 3 means call x_set_window_size if window minimum sizes must be
359 preserved or frame_inhibit_resize allows it. x_set_left_fringe,
360 x_set_scroll_bar_width, x_new_font ... use (or should use) this.
362 4 means call x_set_window_size only if window minimum sizes must be
363 preserved. x_set_right_divider_width, x_set_border_width and the
364 code responsible for wrapping the tool bar use this.
366 5 means to never call x_set_window_size. change_frame_size uses
367 this.
369 Note that even when x_set_window_size is not called, individual
370 windows may have to be resized (via `window--sanitize-window-sizes')
371 in order to support minimum size constraints.
373 PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the
374 symbol of the parameter changed (like `menu-bar-lines', `font', ...).
375 This is passed on to frame_inhibit_resize to let the latter decide on
376 a case-by-case basis whether the frame may be resized externally. */
377 void
378 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
379 bool pretend, Lisp_Object parameter)
381 int unit_width = FRAME_COLUMN_WIDTH (f);
382 int unit_height = FRAME_LINE_HEIGHT (f);
383 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
384 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
385 int old_cols = FRAME_COLS (f);
386 int old_lines = FRAME_LINES (f);
387 int new_pixel_width, new_pixel_height;
388 /* The following two values are calculated from the old frame pixel
389 sizes and any "new" settings for tool bar, menu bar and internal
390 borders. We do it this way to detect whether we have to call
391 x_set_window_size as consequence of the new settings. */
392 int windows_width = FRAME_WINDOWS_WIDTH (f);
393 int windows_height = FRAME_WINDOWS_HEIGHT (f);
394 int min_windows_width, min_windows_height;
395 /* These are a bit tedious, maybe we should use a macro. */
396 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
397 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
398 int old_windows_height
399 = (WINDOW_PIXEL_HEIGHT (r)
400 + (FRAME_HAS_MINIBUF_P (f)
401 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
402 : 0));
403 int new_windows_width, new_windows_height;
404 int old_text_width = FRAME_TEXT_WIDTH (f);
405 int old_text_height = FRAME_TEXT_HEIGHT (f);
406 /* If a size is < 0 use the old value. */
407 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
408 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
409 int new_cols, new_lines;
410 bool inhibit_horizontal, inhibit_vertical;
411 Lisp_Object frame;
413 XSETFRAME (frame, f);
415 frame_size_history_add
416 (f, Qadjust_frame_size_1, new_text_width, new_text_height,
417 list2 (parameter, make_number (inhibit)));
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 /* When 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 frame_size_history_add
487 (f, Qadjust_frame_size_2, new_text_width, new_text_height,
488 list2 (inhibit_horizontal ? Qt : Qnil,
489 inhibit_vertical ? Qt : Qnil));
491 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
492 f->resized_p = true;
494 return;
496 #endif
498 if (new_text_width == old_text_width
499 && new_text_height == old_text_height
500 && new_windows_width == old_windows_width
501 && new_windows_height == old_windows_height
502 && new_pixel_width == old_pixel_width
503 && new_pixel_height == old_pixel_height
504 && new_cols == old_cols
505 && new_lines == old_lines)
506 /* No change. Sanitize window sizes and return. */
508 sanitize_window_sizes (frame, Qt);
509 sanitize_window_sizes (frame, Qnil);
511 return;
514 block_input ();
516 #ifdef MSDOS
517 /* We only can set screen dimensions to certain values supported
518 by our video hardware. Try to find the smallest size greater
519 or equal to the requested dimensions. */
520 dos_set_window_size (&new_lines, &new_cols);
521 #endif
523 if (new_windows_width != old_windows_width)
525 resize_frame_windows (f, new_windows_width, 1, 1);
527 /* MSDOS frames cannot PRETEND, as they change frame size by
528 manipulating video hardware. */
529 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
530 FrameCols (FRAME_TTY (f)) = new_cols;
532 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
533 if (WINDOWP (f->tool_bar_window))
535 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
536 XWINDOW (f->tool_bar_window)->total_cols
537 = new_windows_width / unit_width;
539 #endif
542 if (new_windows_height != old_windows_height
543 /* When the top margin has changed we have to recalculate the top
544 edges of all windows. No such calculation is necessary for the
545 left edges. */
546 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
548 resize_frame_windows (f, new_windows_height, 0, 1);
550 /* MSDOS frames cannot PRETEND, as they change frame size by
551 manipulating video hardware. */
552 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
553 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
556 frame_size_history_add
557 (f, Qadjust_frame_size_3, new_text_width, new_text_height,
558 list4 (make_number (old_pixel_width), make_number (old_pixel_height),
559 make_number (new_pixel_width), make_number (new_pixel_height)));
561 /* Assign new sizes. */
562 FRAME_TEXT_WIDTH (f) = new_text_width;
563 FRAME_TEXT_HEIGHT (f) = new_text_height;
564 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
565 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
566 SET_FRAME_COLS (f, new_cols);
567 SET_FRAME_LINES (f, new_lines);
570 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
571 int text_area_x, text_area_y, text_area_width, text_area_height;
573 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
574 &text_area_height);
575 if (w->cursor.x >= text_area_x + text_area_width)
576 w->cursor.hpos = w->cursor.x = 0;
577 if (w->cursor.y >= text_area_y + text_area_height)
578 w->cursor.vpos = w->cursor.y = 0;
581 /* Sanitize window sizes. */
582 sanitize_window_sizes (frame, Qt);
583 sanitize_window_sizes (frame, Qnil);
585 adjust_frame_glyphs (f);
586 calculate_costs (f);
587 SET_FRAME_GARBAGED (f);
589 /* A frame was "resized" if one of its pixelsizes changed, even if its
590 X window wasn't resized at all. */
591 f->resized_p = (new_pixel_width != old_pixel_width
592 || new_pixel_height != old_pixel_height);
594 unblock_input ();
596 run_window_configuration_change_hook (f);
599 /* Allocate basically initialized frame. */
601 static struct frame *
602 allocate_frame (void)
604 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
607 struct frame *
608 make_frame (bool mini_p)
610 Lisp_Object frame;
611 register struct frame *f;
612 register struct window *rw, *mw;
613 register Lisp_Object root_window;
614 register Lisp_Object mini_window;
616 f = allocate_frame ();
617 XSETFRAME (frame, f);
619 #ifdef USE_GTK
620 /* Initialize Lisp data. Note that allocate_frame initializes all
621 Lisp data to nil, so do it only for slots which should not be nil. */
622 fset_tool_bar_position (f, Qtop);
623 #endif
625 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
626 non-Lisp data, so do it only for slots which should not be zero.
627 To avoid subtle bugs and for the sake of readability, it's better to
628 initialize enum members explicitly even if their values are zero. */
629 f->wants_modeline = true;
630 f->redisplay = true;
631 f->garbaged = true;
632 f->can_x_set_window_size = false;
633 f->after_make_frame = false;
634 f->tool_bar_redisplayed_once = false;
635 f->column_width = 1; /* !FRAME_WINDOW_P value. */
636 f->line_height = 1; /* !FRAME_WINDOW_P value. */
637 #ifdef HAVE_WINDOW_SYSTEM
638 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
639 f->horizontal_scroll_bars = false;
640 f->want_fullscreen = FULLSCREEN_NONE;
641 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
642 f->last_tool_bar_item = -1;
643 #endif
644 #endif
646 root_window = make_window ();
647 rw = XWINDOW (root_window);
648 if (mini_p)
650 mini_window = make_window ();
651 mw = XWINDOW (mini_window);
652 wset_next (rw, mini_window);
653 wset_prev (mw, root_window);
654 mw->mini = 1;
655 wset_frame (mw, frame);
656 fset_minibuffer_window (f, mini_window);
658 else
660 mini_window = Qnil;
661 wset_next (rw, Qnil);
662 fset_minibuffer_window (f, Qnil);
665 wset_frame (rw, frame);
667 /* 10 is arbitrary,
668 just so that there is "something there."
669 Correct size will be set up later with adjust_frame_size. */
671 SET_FRAME_COLS (f, 10);
672 SET_FRAME_LINES (f, 10);
673 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
674 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
676 rw->total_cols = 10;
677 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
678 rw->total_lines = mini_p ? 9 : 10;
679 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
681 if (mini_p)
683 mw->top_line = rw->total_lines;
684 mw->pixel_top = rw->pixel_height;
685 mw->total_cols = rw->total_cols;
686 mw->pixel_width = rw->pixel_width;
687 mw->total_lines = 1;
688 mw->pixel_height = FRAME_LINE_HEIGHT (f);
691 /* Choose a buffer for the frame's root window. */
693 Lisp_Object buf = Fcurrent_buffer ();
695 /* If current buffer is hidden, try to find another one. */
696 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
697 buf = other_buffer_safely (buf);
699 /* Use set_window_buffer, not Fset_window_buffer, and don't let
700 hooks be run by it. The reason is that the whole frame/window
701 arrangement is not yet fully initialized at this point. Windows
702 don't have the right size, glyph matrices aren't initialized
703 etc. Running Lisp functions at this point surely ends in a
704 SEGV. */
705 set_window_buffer (root_window, buf, 0, 0);
706 fset_buffer_list (f, list1 (buf));
709 if (mini_p)
711 set_window_buffer (mini_window,
712 (NILP (Vminibuffer_list)
713 ? get_minibuffer (0)
714 : Fcar (Vminibuffer_list)),
715 0, 0);
716 /* No horizontal scroll bars in minibuffers. */
717 wset_horizontal_scroll_bar (mw, Qnil);
720 fset_root_window (f, root_window);
721 fset_selected_window (f, root_window);
722 /* Make sure this window seems more recently used than
723 a newly-created, never-selected window. */
724 XWINDOW (f->selected_window)->use_time = ++window_select_count;
726 return f;
729 #ifdef HAVE_WINDOW_SYSTEM
730 /* Make a frame using a separate minibuffer window on another frame.
731 MINI_WINDOW is the minibuffer window to use. nil means use the
732 default (the global minibuffer). */
734 struct frame *
735 make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
737 register struct frame *f;
738 struct gcpro gcpro1;
740 if (!NILP (mini_window))
741 CHECK_LIVE_WINDOW (mini_window);
743 if (!NILP (mini_window)
744 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
745 error ("Frame and minibuffer must be on the same terminal");
747 /* Make a frame containing just a root window. */
748 f = make_frame (0);
750 if (NILP (mini_window))
752 /* Use default-minibuffer-frame if possible. */
753 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
754 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
756 Lisp_Object frame_dummy;
758 XSETFRAME (frame_dummy, f);
759 GCPRO1 (frame_dummy);
760 /* If there's no minibuffer frame to use, create one. */
761 kset_default_minibuffer_frame
762 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
763 UNGCPRO;
766 mini_window
767 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
770 fset_minibuffer_window (f, mini_window);
772 /* Make the chosen minibuffer window display the proper minibuffer,
773 unless it is already showing a minibuffer. */
774 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
775 /* Use set_window_buffer instead of Fset_window_buffer (see
776 discussion of bug#11984, bug#12025, bug#12026). */
777 set_window_buffer (mini_window,
778 (NILP (Vminibuffer_list)
779 ? get_minibuffer (0)
780 : Fcar (Vminibuffer_list)), 0, 0);
781 return f;
784 /* Make a frame containing only a minibuffer window. */
786 struct frame *
787 make_minibuffer_frame (void)
789 /* First make a frame containing just a root window, no minibuffer. */
791 register struct frame *f = make_frame (0);
792 register Lisp_Object mini_window;
793 register Lisp_Object frame;
795 XSETFRAME (frame, f);
797 f->auto_raise = 0;
798 f->auto_lower = 0;
799 f->no_split = 1;
800 f->wants_modeline = 0;
802 /* Now label the root window as also being the minibuffer.
803 Avoid infinite looping on the window chain by marking next pointer
804 as nil. */
806 mini_window = f->root_window;
807 fset_minibuffer_window (f, mini_window);
808 XWINDOW (mini_window)->mini = 1;
809 wset_next (XWINDOW (mini_window), Qnil);
810 wset_prev (XWINDOW (mini_window), Qnil);
811 wset_frame (XWINDOW (mini_window), frame);
813 /* Put the proper buffer in that window. */
815 /* Use set_window_buffer instead of Fset_window_buffer (see
816 discussion of bug#11984, bug#12025, bug#12026). */
817 set_window_buffer (mini_window,
818 (NILP (Vminibuffer_list)
819 ? get_minibuffer (0)
820 : Fcar (Vminibuffer_list)), 0, 0);
821 return f;
823 #endif /* HAVE_WINDOW_SYSTEM */
825 /* Construct a frame that refers to a terminal. */
827 static printmax_t tty_frame_count;
829 struct frame *
830 make_initial_frame (void)
832 struct frame *f;
833 struct terminal *terminal;
834 Lisp_Object frame;
836 eassert (initial_kboard);
838 /* The first call must initialize Vframe_list. */
839 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
840 Vframe_list = Qnil;
842 terminal = init_initial_terminal ();
844 f = make_frame (1);
845 XSETFRAME (frame, f);
847 Vframe_list = Fcons (frame, Vframe_list);
849 tty_frame_count = 1;
850 fset_name (f, build_pure_c_string ("F1"));
852 SET_FRAME_VISIBLE (f, 1);
854 f->output_method = terminal->type;
855 f->terminal = terminal;
856 f->terminal->reference_count++;
857 f->output_data.nothing = 0;
859 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
860 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
862 #ifdef HAVE_WINDOW_SYSTEM
863 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
864 f->horizontal_scroll_bars = false;
865 #endif
867 /* The default value of menu-bar-mode is t. */
868 set_menu_bar_lines (f, make_number (1), Qnil);
870 if (!noninteractive)
871 init_frame_faces (f);
873 last_nonminibuf_frame = f;
875 return f;
879 static struct frame *
880 make_terminal_frame (struct terminal *terminal)
882 register struct frame *f;
883 Lisp_Object frame;
884 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
886 if (!terminal->name)
887 error ("Terminal is not live, can't create new frames on it");
889 f = make_frame (1);
891 XSETFRAME (frame, f);
892 Vframe_list = Fcons (frame, Vframe_list);
894 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
896 SET_FRAME_VISIBLE (f, 1);
898 f->terminal = terminal;
899 f->terminal->reference_count++;
900 #ifdef MSDOS
901 f->output_data.tty->display_info = &the_only_display_info;
902 if (!inhibit_window_system
903 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
904 || XFRAME (selected_frame)->output_method == output_msdos_raw))
905 f->output_method = output_msdos_raw;
906 else
907 f->output_method = output_termcap;
908 #else /* not MSDOS */
909 f->output_method = output_termcap;
910 create_tty_output (f);
911 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
912 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
913 #endif /* not MSDOS */
915 #ifdef HAVE_WINDOW_SYSTEM
916 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
917 f->horizontal_scroll_bars = false;
918 #endif
920 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
921 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
922 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
923 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
925 /* Set the top frame to the newly created frame. */
926 if (FRAMEP (FRAME_TTY (f)->top_frame)
927 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
928 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
930 FRAME_TTY (f)->top_frame = frame;
932 if (!noninteractive)
933 init_frame_faces (f);
935 return f;
938 /* Get a suitable value for frame parameter PARAMETER for a newly
939 created frame, based on (1) the user-supplied frame parameter
940 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
942 static Lisp_Object
943 get_future_frame_param (Lisp_Object parameter,
944 Lisp_Object supplied_parms,
945 char *current_value)
947 Lisp_Object result;
949 result = Fassq (parameter, supplied_parms);
950 if (NILP (result))
951 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
952 if (NILP (result) && current_value != NULL)
953 result = build_string (current_value);
954 if (!NILP (result) && !STRINGP (result))
955 result = XCDR (result);
956 if (NILP (result) || !STRINGP (result))
957 result = Qnil;
959 return result;
962 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
963 1, 1, 0,
964 doc: /* Create an additional terminal frame, possibly on another terminal.
965 This function takes one argument, an alist specifying frame parameters.
967 You can create multiple frames on a single text terminal, but only one
968 of them (the selected terminal frame) is actually displayed.
970 In practice, generally you don't need to specify any parameters,
971 except when you want to create a new frame on another terminal.
972 In that case, the `tty' parameter specifies the device file to open,
973 and the `tty-type' parameter specifies the terminal type. Example:
975 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
977 Note that changing the size of one terminal frame automatically
978 affects all frames on the same terminal device. */)
979 (Lisp_Object parms)
981 struct frame *f;
982 struct terminal *t = NULL;
983 Lisp_Object frame, tem;
984 struct frame *sf = SELECTED_FRAME ();
986 #ifdef MSDOS
987 if (sf->output_method != output_msdos_raw
988 && sf->output_method != output_termcap)
989 emacs_abort ();
990 #else /* not MSDOS */
992 #ifdef WINDOWSNT /* This should work now! */
993 if (sf->output_method != output_termcap)
994 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
995 #endif
996 #endif /* not MSDOS */
999 Lisp_Object terminal;
1001 terminal = Fassq (Qterminal, parms);
1002 if (CONSP (terminal))
1004 terminal = XCDR (terminal);
1005 t = decode_live_terminal (terminal);
1007 #ifdef MSDOS
1008 if (t && t != the_only_display_info.terminal)
1009 /* msdos.c assumes a single tty_display_info object. */
1010 error ("Multiple terminals are not supported on this platform");
1011 if (!t)
1012 t = the_only_display_info.terminal;
1013 #endif
1016 if (!t)
1018 char *name = 0, *type = 0;
1019 Lisp_Object tty, tty_type;
1020 USE_SAFE_ALLOCA;
1022 tty = get_future_frame_param
1023 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1024 ? FRAME_TTY (XFRAME (selected_frame))->name
1025 : NULL));
1026 if (!NILP (tty))
1027 SAFE_ALLOCA_STRING (name, tty);
1029 tty_type = get_future_frame_param
1030 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1031 ? FRAME_TTY (XFRAME (selected_frame))->type
1032 : NULL));
1033 if (!NILP (tty_type))
1034 SAFE_ALLOCA_STRING (type, tty_type);
1036 t = init_tty (name, type, 0); /* Errors are not fatal. */
1037 SAFE_FREE ();
1040 f = make_terminal_frame (t);
1043 int width, height;
1044 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1045 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f),
1046 5, 0, Qterminal_frame);
1049 adjust_frame_glyphs (f);
1050 calculate_costs (f);
1051 XSETFRAME (frame, f);
1053 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1054 store_in_alist (&parms, Qtty,
1055 (t->display_info.tty->name
1056 ? build_string (t->display_info.tty->name)
1057 : Qnil));
1058 Fmodify_frame_parameters (frame, parms);
1060 /* Make the frame face alist be frame-specific, so that each
1061 frame could change its face definitions independently. */
1062 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1063 /* Simple Fcopy_alist isn't enough, because we need the contents of
1064 the vectors which are the CDRs of associations in face_alist to
1065 be copied as well. */
1066 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1067 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1068 return frame;
1072 /* Perform the switch to frame FRAME.
1074 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1075 FRAME1 as frame.
1077 If TRACK is non-zero and the frame that currently has the focus
1078 redirects its focus to the selected frame, redirect that focused
1079 frame's focus to FRAME instead.
1081 FOR_DELETION non-zero means that the selected frame is being
1082 deleted, which includes the possibility that the frame's terminal
1083 is dead.
1085 The value of NORECORD is passed as argument to Fselect_window. */
1087 Lisp_Object
1088 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1090 struct frame *sf = SELECTED_FRAME ();
1092 /* If FRAME is a switch-frame event, extract the frame we should
1093 switch to. */
1094 if (CONSP (frame)
1095 && EQ (XCAR (frame), Qswitch_frame)
1096 && CONSP (XCDR (frame)))
1097 frame = XCAR (XCDR (frame));
1099 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1100 a switch-frame event to arrive after a frame is no longer live,
1101 especially when deleting the initial frame during startup. */
1102 CHECK_FRAME (frame);
1103 if (! FRAME_LIVE_P (XFRAME (frame)))
1104 return Qnil;
1106 if (sf == XFRAME (frame))
1107 return frame;
1109 /* If a frame's focus has been redirected toward the currently
1110 selected frame, we should change the redirection to point to the
1111 newly selected frame. This means that if the focus is redirected
1112 from a minibufferless frame to a surrogate minibuffer frame, we
1113 can use `other-window' to switch between all the frames using
1114 that minibuffer frame, and the focus redirection will follow us
1115 around. */
1116 #if 0
1117 /* This is too greedy; it causes inappropriate focus redirection
1118 that's hard to get rid of. */
1119 if (track)
1121 Lisp_Object tail;
1123 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1125 Lisp_Object focus;
1127 if (!FRAMEP (XCAR (tail)))
1128 emacs_abort ();
1130 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1132 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1133 Fredirect_frame_focus (XCAR (tail), frame);
1136 #else /* ! 0 */
1137 /* Instead, apply it only to the frame we're pointing to. */
1138 #ifdef HAVE_WINDOW_SYSTEM
1139 if (track && FRAME_WINDOW_P (XFRAME (frame)))
1141 Lisp_Object focus, xfocus;
1143 xfocus = x_get_focus_frame (XFRAME (frame));
1144 if (FRAMEP (xfocus))
1146 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1147 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1148 Fredirect_frame_focus (xfocus, frame);
1151 #endif /* HAVE_X_WINDOWS */
1152 #endif /* ! 0 */
1154 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1155 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1157 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
1159 struct frame *f = XFRAME (frame);
1160 struct tty_display_info *tty = FRAME_TTY (f);
1161 Lisp_Object top_frame = tty->top_frame;
1163 /* Don't mark the frame garbaged and/or obscured if we are
1164 switching to the frame that is already the top frame of that
1165 TTY. */
1166 if (!EQ (frame, top_frame))
1168 if (FRAMEP (top_frame))
1169 /* Mark previously displayed frame as now obscured. */
1170 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1171 SET_FRAME_VISIBLE (f, 1);
1172 /* If the new TTY frame changed dimensions, we need to
1173 resync term.c's idea of the frame size with the new
1174 frame's data. */
1175 if (FRAME_COLS (f) != FrameCols (tty))
1176 FrameCols (tty) = FRAME_COLS (f);
1177 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1178 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1180 tty->top_frame = frame;
1183 selected_frame = frame;
1184 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1185 last_nonminibuf_frame = XFRAME (selected_frame);
1187 Fselect_window (XFRAME (frame)->selected_window, norecord);
1189 /* We want to make sure that the next event generates a frame-switch
1190 event to the appropriate frame. This seems kludgy to me, but
1191 before you take it out, make sure that evaluating something like
1192 (select-window (frame-root-window (new-frame))) doesn't end up
1193 with your typing being interpreted in the new frame instead of
1194 the one you're actually typing in. */
1195 internal_last_event_frame = Qnil;
1197 return frame;
1200 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1201 doc: /* Select FRAME.
1202 Subsequent editing commands apply to its selected window.
1203 Optional argument NORECORD means to neither change the order of
1204 recently selected windows nor the buffer list.
1206 The selection of FRAME lasts until the next time the user does
1207 something to select a different frame, or until the next time
1208 this function is called. If you are using a window system, the
1209 previously selected frame may be restored as the selected frame
1210 when returning to the command loop, because it still may have
1211 the window system's input focus. On a text terminal, the next
1212 redisplay will display FRAME.
1214 This function returns FRAME, or nil if FRAME has been deleted. */)
1215 (Lisp_Object frame, Lisp_Object norecord)
1217 return do_switch_frame (frame, 1, 0, norecord);
1220 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1221 doc: /* Handle a switch-frame event EVENT.
1222 Switch-frame events are usually bound to this function.
1223 A switch-frame event tells Emacs that the window manager has requested
1224 that the user's events be directed to the frame mentioned in the event.
1225 This function selects the selected window of the frame of EVENT.
1227 If EVENT is frame object, handle it as if it were a switch-frame event
1228 to that frame. */)
1229 (Lisp_Object event)
1231 /* Preserve prefix arg that the command loop just cleared. */
1232 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1233 run_hook (Qmouse_leave_buffer_hook);
1234 /* `switch-frame' implies a focus in. */
1235 call1 (intern ("handle-focus-in"), event);
1236 return do_switch_frame (event, 0, 0, Qnil);
1239 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1240 doc: /* Return the frame that is now selected. */)
1241 (void)
1243 return selected_frame;
1246 DEFUN ("frame-list", Fframe_list, Sframe_list,
1247 0, 0, 0,
1248 doc: /* Return a list of all live frames. */)
1249 (void)
1251 Lisp_Object frames;
1252 frames = Fcopy_sequence (Vframe_list);
1253 #ifdef HAVE_WINDOW_SYSTEM
1254 if (FRAMEP (tip_frame))
1255 frames = Fdelq (tip_frame, frames);
1256 #endif
1257 return frames;
1260 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1261 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1262 If MINIBUF is nil, do not consider minibuffer-only candidate.
1263 If MINIBUF is `visible', do not consider an invisible candidate.
1264 If MINIBUF is a window, consider only its own frame and candidate now
1265 using that window as the minibuffer.
1266 If MINIBUF is 0, consider candidate if it is visible or iconified.
1267 Otherwise consider any candidate and return nil if CANDIDATE is not
1268 acceptable. */
1270 static Lisp_Object
1271 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1273 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1275 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1276 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1277 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1278 && FRAME_TTY (c) == FRAME_TTY (f)))
1280 if (NILP (minibuf))
1282 if (!FRAME_MINIBUF_ONLY_P (c))
1283 return candidate;
1285 else if (EQ (minibuf, Qvisible))
1287 if (FRAME_VISIBLE_P (c))
1288 return candidate;
1290 else if (WINDOWP (minibuf))
1292 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1293 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1294 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1295 FRAME_FOCUS_FRAME (c)))
1296 return candidate;
1298 else if (XFASTINT (minibuf) == 0)
1300 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1301 return candidate;
1303 else
1304 return candidate;
1306 return Qnil;
1309 /* Return the next frame in the frame list after FRAME. */
1311 static Lisp_Object
1312 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1314 Lisp_Object f, tail;
1315 int passed = 0;
1317 /* There must always be at least one frame in Vframe_list. */
1318 eassert (CONSP (Vframe_list));
1320 while (passed < 2)
1321 FOR_EACH_FRAME (tail, f)
1323 if (passed)
1325 f = candidate_frame (f, frame, minibuf);
1326 if (!NILP (f))
1327 return f;
1329 if (EQ (frame, f))
1330 passed++;
1332 return frame;
1335 /* Return the previous frame in the frame list before FRAME. */
1337 static Lisp_Object
1338 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1340 Lisp_Object f, tail, prev = Qnil;
1342 /* There must always be at least one frame in Vframe_list. */
1343 eassert (CONSP (Vframe_list));
1345 FOR_EACH_FRAME (tail, f)
1347 if (EQ (frame, f) && !NILP (prev))
1348 return prev;
1349 f = candidate_frame (f, frame, minibuf);
1350 if (!NILP (f))
1351 prev = f;
1354 /* We've scanned the entire list. */
1355 if (NILP (prev))
1356 /* We went through the whole frame list without finding a single
1357 acceptable frame. Return the original frame. */
1358 return frame;
1359 else
1360 /* There were no acceptable frames in the list before FRAME; otherwise,
1361 we would have returned directly from the loop. Since PREV is the last
1362 acceptable frame in the list, return it. */
1363 return prev;
1367 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1368 doc: /* Return the next frame in the frame list after FRAME.
1369 It considers only frames on the same terminal as FRAME.
1370 By default, skip minibuffer-only frames.
1371 If omitted, FRAME defaults to the selected frame.
1372 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1373 If MINIFRAME is a window, include only its own frame
1374 and any frame now using that window as the minibuffer.
1375 If MINIFRAME is `visible', include all visible frames.
1376 If MINIFRAME is 0, include all visible and iconified frames.
1377 Otherwise, include all frames. */)
1378 (Lisp_Object frame, Lisp_Object miniframe)
1380 if (NILP (frame))
1381 frame = selected_frame;
1382 CHECK_LIVE_FRAME (frame);
1383 return next_frame (frame, miniframe);
1386 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1387 doc: /* Return the previous frame in the frame list before FRAME.
1388 It considers only frames on the same terminal as FRAME.
1389 By default, skip minibuffer-only frames.
1390 If omitted, FRAME defaults to the selected frame.
1391 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1392 If MINIFRAME is a window, include only its own frame
1393 and any frame now using that window as the minibuffer.
1394 If MINIFRAME is `visible', include all visible frames.
1395 If MINIFRAME is 0, include all visible and iconified frames.
1396 Otherwise, include all frames. */)
1397 (Lisp_Object frame, Lisp_Object miniframe)
1399 if (NILP (frame))
1400 frame = selected_frame;
1401 CHECK_LIVE_FRAME (frame);
1402 return prev_frame (frame, miniframe);
1405 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1406 Slast_nonminibuf_frame, 0, 0, 0,
1407 doc: /* Return last non-minibuffer frame selected. */)
1408 (void)
1410 Lisp_Object frame = Qnil;
1412 if (last_nonminibuf_frame)
1413 XSETFRAME (frame, last_nonminibuf_frame);
1415 return frame;
1418 /* Return 1 if it is ok to delete frame F;
1419 0 if all frames aside from F are invisible.
1420 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1422 static int
1423 other_visible_frames (struct frame *f)
1425 Lisp_Object frames, this;
1427 FOR_EACH_FRAME (frames, this)
1429 if (f == XFRAME (this))
1430 continue;
1432 /* Verify that we can still talk to the frame's X window,
1433 and note any recent change in visibility. */
1434 #ifdef HAVE_X_WINDOWS
1435 if (FRAME_WINDOW_P (XFRAME (this)))
1436 x_sync (XFRAME (this));
1437 #endif
1439 if (FRAME_VISIBLE_P (XFRAME (this))
1440 || FRAME_ICONIFIED_P (XFRAME (this))
1441 /* Allow deleting the terminal frame when at least one X
1442 frame exists. */
1443 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1444 return 1;
1446 return 0;
1449 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1450 window. Preferably use the selected frame's minibuffer window
1451 instead. If the selected frame doesn't have one, get some other
1452 frame's minibuffer window. SELECT non-zero means select the new
1453 minibuffer window. */
1454 static void
1455 check_minibuf_window (Lisp_Object frame, int select)
1457 struct frame *f = decode_live_frame (frame);
1459 XSETFRAME (frame, f);
1461 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1463 Lisp_Object frames, this, window = make_number (0);
1465 if (!EQ (frame, selected_frame)
1466 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1467 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1468 else
1469 FOR_EACH_FRAME (frames, this)
1471 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1473 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1474 break;
1478 /* Don't abort if no window was found (Bug#15247). */
1479 if (WINDOWP (window))
1481 /* Use set_window_buffer instead of Fset_window_buffer (see
1482 discussion of bug#11984, bug#12025, bug#12026). */
1483 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1484 minibuf_window = window;
1486 /* SELECT non-zero usually means that FRAME's minibuffer
1487 window was selected; select the new one. */
1488 if (select)
1489 Fselect_window (minibuf_window, Qnil);
1495 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1496 unconditionally. x_connection_closed and delete_terminal use
1497 this. Any other value of FORCE implements the semantics
1498 described for Fdelete_frame. */
1499 Lisp_Object
1500 delete_frame (Lisp_Object frame, Lisp_Object force)
1502 struct frame *f = decode_any_frame (frame);
1503 struct frame *sf;
1504 struct kboard *kb;
1506 int minibuffer_selected, is_tooltip_frame;
1508 if (! FRAME_LIVE_P (f))
1509 return Qnil;
1511 if (NILP (force) && !other_visible_frames (f))
1512 error ("Attempt to delete the sole visible or iconified frame");
1514 /* x_connection_closed must have set FORCE to `noelisp' in order
1515 to delete the last frame, if it is gone. */
1516 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1517 error ("Attempt to delete the only frame");
1519 XSETFRAME (frame, f);
1521 /* Does this frame have a minibuffer, and is it the surrogate
1522 minibuffer for any other frame? */
1523 if (FRAME_HAS_MINIBUF_P (f))
1525 Lisp_Object frames, this;
1527 FOR_EACH_FRAME (frames, this)
1529 Lisp_Object fminiw;
1531 if (EQ (this, frame))
1532 continue;
1534 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1536 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1538 /* If we MUST delete this frame, delete the other first.
1539 But do this only if FORCE equals `noelisp'. */
1540 if (EQ (force, Qnoelisp))
1541 delete_frame (this, Qnoelisp);
1542 else
1543 error ("Attempt to delete a surrogate minibuffer frame");
1548 is_tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1550 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1551 frame is a tooltip. FORCE is set to `noelisp' when handling
1552 a disconnect from the terminal, so we don't dare call Lisp
1553 code. */
1554 if (NILP (Vrun_hooks) || is_tooltip_frame)
1556 else if (EQ (force, Qnoelisp))
1557 pending_funcalls
1558 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1559 pending_funcalls);
1560 else
1562 #ifdef HAVE_X_WINDOWS
1563 /* Also, save clipboard to the clipboard manager. */
1564 x_clipboard_manager_save_frame (frame);
1565 #endif
1567 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1570 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1571 if (! FRAME_LIVE_P (f))
1572 return Qnil;
1574 /* At this point, we are committed to deleting the frame.
1575 There is no more chance for errors to prevent it. */
1577 minibuffer_selected = EQ (minibuf_window, selected_window);
1578 sf = SELECTED_FRAME ();
1579 /* Don't let the frame remain selected. */
1580 if (f == sf)
1582 Lisp_Object tail;
1583 Lisp_Object frame1 = Qnil;
1585 /* Look for another visible frame on the same terminal.
1586 Do not call next_frame here because it may loop forever.
1587 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1588 FOR_EACH_FRAME (tail, frame1)
1589 if (!EQ (frame, frame1)
1590 && (FRAME_TERMINAL (XFRAME (frame))
1591 == FRAME_TERMINAL (XFRAME (frame1)))
1592 && FRAME_VISIBLE_P (XFRAME (frame1)))
1593 break;
1595 /* If there is none, find *some* other frame. */
1596 if (NILP (frame1) || EQ (frame1, frame))
1598 FOR_EACH_FRAME (tail, frame1)
1600 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1602 /* Do not change a text terminal's top-frame. */
1603 struct frame *f1 = XFRAME (frame1);
1604 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1606 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1607 if (!EQ (top_frame, frame))
1608 frame1 = top_frame;
1610 break;
1614 #ifdef NS_IMPL_COCOA
1615 else
1616 /* Under NS, there is no system mechanism for choosing a new
1617 window to get focus -- it is left to application code.
1618 So the portion of THIS application interfacing with NS
1619 needs to know about it. We call Fraise_frame, but the
1620 purpose is really to transfer focus. */
1621 Fraise_frame (frame1);
1622 #endif
1624 do_switch_frame (frame1, 0, 1, Qnil);
1625 sf = SELECTED_FRAME ();
1628 /* Don't allow minibuf_window to remain on a deleted frame. */
1629 check_minibuf_window (frame, minibuffer_selected);
1631 /* Don't let echo_area_window to remain on a deleted frame. */
1632 if (EQ (f->minibuffer_window, echo_area_window))
1633 echo_area_window = sf->minibuffer_window;
1635 /* Clear any X selections for this frame. */
1636 #ifdef HAVE_X_WINDOWS
1637 if (FRAME_X_P (f))
1638 x_clear_frame_selections (f);
1639 #endif
1641 /* Free glyphs.
1642 This function must be called before the window tree of the
1643 frame is deleted because windows contain dynamically allocated
1644 memory. */
1645 free_glyphs (f);
1647 #ifdef HAVE_WINDOW_SYSTEM
1648 /* Give chance to each font driver to free a frame specific data. */
1649 font_update_drivers (f, Qnil);
1650 #endif
1652 /* Mark all the windows that used to be on FRAME as deleted, and then
1653 remove the reference to them. */
1654 delete_all_child_windows (f->root_window);
1655 fset_root_window (f, Qnil);
1657 Vframe_list = Fdelq (frame, Vframe_list);
1658 SET_FRAME_VISIBLE (f, 0);
1660 /* Allow the vector of menu bar contents to be freed in the next
1661 garbage collection. The frame object itself may not be garbage
1662 collected until much later, because recent_keys and other data
1663 structures can still refer to it. */
1664 fset_menu_bar_vector (f, Qnil);
1666 /* If FRAME's buffer lists contains killed
1667 buffers, this helps GC to reclaim them. */
1668 fset_buffer_list (f, Qnil);
1669 fset_buried_buffer_list (f, Qnil);
1671 free_font_driver_list (f);
1672 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1673 xfree (f->namebuf);
1674 #endif
1675 xfree (f->decode_mode_spec_buffer);
1676 xfree (FRAME_INSERT_COST (f));
1677 xfree (FRAME_DELETEN_COST (f));
1678 xfree (FRAME_INSERTN_COST (f));
1679 xfree (FRAME_DELETE_COST (f));
1681 /* Since some events are handled at the interrupt level, we may get
1682 an event for f at any time; if we zero out the frame's terminal
1683 now, then we may trip up the event-handling code. Instead, we'll
1684 promise that the terminal of the frame must be valid until we
1685 have called the window-system-dependent frame destruction
1686 routine. */
1690 struct terminal *terminal;
1691 block_input ();
1692 if (FRAME_TERMINAL (f)->delete_frame_hook)
1693 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1694 terminal = FRAME_TERMINAL (f);
1695 f->output_data.nothing = 0;
1696 f->terminal = 0; /* Now the frame is dead. */
1697 unblock_input ();
1699 /* If needed, delete the terminal that this frame was on.
1700 (This must be done after the frame is killed.) */
1701 terminal->reference_count--;
1702 #ifdef USE_GTK
1703 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1704 bug.
1705 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1706 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1707 terminal->reference_count = 1;
1708 #endif /* USE_GTK */
1709 if (terminal->reference_count == 0)
1711 Lisp_Object tmp;
1712 XSETTERMINAL (tmp, terminal);
1714 kb = NULL;
1715 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1717 else
1718 kb = terminal->kboard;
1721 /* If we've deleted the last_nonminibuf_frame, then try to find
1722 another one. */
1723 if (f == last_nonminibuf_frame)
1725 Lisp_Object frames, this;
1727 last_nonminibuf_frame = 0;
1729 FOR_EACH_FRAME (frames, this)
1731 f = XFRAME (this);
1732 if (!FRAME_MINIBUF_ONLY_P (f))
1734 last_nonminibuf_frame = f;
1735 break;
1740 /* If there's no other frame on the same kboard, get out of
1741 single-kboard state if we're in it for this kboard. */
1742 if (kb != NULL)
1744 Lisp_Object frames, this;
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)
1749 if (kb == FRAME_KBOARD (XFRAME (this)))
1750 frame_on_same_kboard = this;
1752 if (NILP (frame_on_same_kboard))
1753 not_single_kboard_state (kb);
1757 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1758 find another one. Prefer minibuffer-only frames, but also notice
1759 frames with other windows. */
1760 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1762 Lisp_Object frames, this;
1764 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1765 Lisp_Object frame_with_minibuf = Qnil;
1766 /* Some frame we found on the same kboard, or nil if there are none. */
1767 Lisp_Object frame_on_same_kboard = Qnil;
1769 FOR_EACH_FRAME (frames, this)
1771 struct frame *f1 = XFRAME (this);
1773 /* Consider only frames on the same kboard
1774 and only those with minibuffers. */
1775 if (kb == FRAME_KBOARD (f1)
1776 && FRAME_HAS_MINIBUF_P (f1))
1778 frame_with_minibuf = this;
1779 if (FRAME_MINIBUF_ONLY_P (f1))
1780 break;
1783 if (kb == FRAME_KBOARD (f1))
1784 frame_on_same_kboard = this;
1787 if (!NILP (frame_on_same_kboard))
1789 /* We know that there must be some frame with a minibuffer out
1790 there. If this were not true, all of the frames present
1791 would have to be minibufferless, which implies that at some
1792 point their minibuffer frames must have been deleted, but
1793 that is prohibited at the top; you can't delete surrogate
1794 minibuffer frames. */
1795 if (NILP (frame_with_minibuf))
1796 emacs_abort ();
1798 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1800 else
1801 /* No frames left on this kboard--say no minibuffer either. */
1802 kset_default_minibuffer_frame (kb, Qnil);
1805 /* Cause frame titles to update--necessary if we now have just one frame. */
1806 if (!is_tooltip_frame)
1807 update_mode_lines = 15;
1809 return Qnil;
1812 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1813 doc: /* Delete FRAME, permanently eliminating it from use.
1814 FRAME defaults to the selected frame.
1816 A frame may not be deleted if its minibuffer is used by other frames.
1817 Normally, you may not delete a frame if all other frames are invisible,
1818 but if the second optional argument FORCE is non-nil, you may do so.
1820 This function runs `delete-frame-functions' before actually
1821 deleting the frame, unless the frame is a tooltip.
1822 The functions are run with one argument, the frame to be deleted. */)
1823 (Lisp_Object frame, Lisp_Object force)
1825 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1829 /* Return mouse position in character cell units. */
1831 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1832 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1833 The position is given in canonical character cells, where (0, 0) is the
1834 upper-left corner of the frame, X is the horizontal offset, and Y is the
1835 vertical offset, measured in units of the frame's default character size.
1836 If Emacs is running on a mouseless terminal or hasn't been programmed
1837 to read the mouse position, it returns the selected frame for FRAME
1838 and nil for X and Y.
1839 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1840 passing the normal return value to that function as an argument,
1841 and returns whatever that function returns. */)
1842 (void)
1844 struct frame *f;
1845 Lisp_Object lispy_dummy;
1846 Lisp_Object x, y, retval;
1847 struct gcpro gcpro1;
1849 f = SELECTED_FRAME ();
1850 x = y = Qnil;
1852 /* It's okay for the hook to refrain from storing anything. */
1853 if (FRAME_TERMINAL (f)->mouse_position_hook)
1855 enum scroll_bar_part party_dummy;
1856 Time time_dummy;
1857 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1858 &lispy_dummy, &party_dummy,
1859 &x, &y,
1860 &time_dummy);
1863 if (! NILP (x))
1865 int col = XINT (x);
1866 int row = XINT (y);
1867 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1868 XSETINT (x, col);
1869 XSETINT (y, row);
1871 XSETFRAME (lispy_dummy, f);
1872 retval = Fcons (lispy_dummy, Fcons (x, y));
1873 GCPRO1 (retval);
1874 if (!NILP (Vmouse_position_function))
1875 retval = call1 (Vmouse_position_function, retval);
1876 RETURN_UNGCPRO (retval);
1879 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1880 Smouse_pixel_position, 0, 0, 0,
1881 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1882 The position is given in pixel units, where (0, 0) is the
1883 upper-left corner of the frame, X is the horizontal offset, and Y is
1884 the vertical offset.
1885 If Emacs is running on a mouseless terminal or hasn't been programmed
1886 to read the mouse position, it returns the selected frame for FRAME
1887 and nil for X and Y. */)
1888 (void)
1890 struct frame *f;
1891 Lisp_Object lispy_dummy;
1892 Lisp_Object x, y, retval;
1893 struct gcpro gcpro1;
1895 f = SELECTED_FRAME ();
1896 x = y = Qnil;
1898 /* It's okay for the hook to refrain from storing anything. */
1899 if (FRAME_TERMINAL (f)->mouse_position_hook)
1901 enum scroll_bar_part party_dummy;
1902 Time time_dummy;
1903 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1904 &lispy_dummy, &party_dummy,
1905 &x, &y,
1906 &time_dummy);
1909 XSETFRAME (lispy_dummy, f);
1910 retval = Fcons (lispy_dummy, Fcons (x, y));
1911 GCPRO1 (retval);
1912 if (!NILP (Vmouse_position_function))
1913 retval = call1 (Vmouse_position_function, retval);
1914 RETURN_UNGCPRO (retval);
1917 #ifdef HAVE_WINDOW_SYSTEM
1919 /* On frame F, convert character coordinates X and Y to pixel
1920 coordinates *PIX_X and *PIX_Y. */
1922 static void
1923 frame_char_to_pixel_position (struct frame *f, int x, int y,
1924 int *pix_x, int *pix_y)
1926 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
1927 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
1929 if (*pix_x < 0)
1930 *pix_x = 0;
1931 if (*pix_x > FRAME_PIXEL_WIDTH (f))
1932 *pix_x = FRAME_PIXEL_WIDTH (f);
1934 if (*pix_y < 0)
1935 *pix_y = 0;
1936 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
1937 *pix_y = FRAME_PIXEL_HEIGHT (f);
1940 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1942 static void
1943 frame_set_mouse_position (struct frame *f, int x, int y)
1945 int pix_x, pix_y;
1947 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
1948 frame_set_mouse_pixel_position (f, pix_x, pix_y);
1951 #endif /* HAVE_WINDOW_SYSTEM */
1953 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1954 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1955 Coordinates are relative to the frame, not a window,
1956 so the coordinates of the top left character in the frame
1957 may be nonzero due to left-hand scroll bars or the menu bar.
1959 The position is given in canonical character cells, where (0, 0) is
1960 the upper-left corner of the frame, X is the horizontal offset, and
1961 Y is the vertical offset, measured in units of the frame's default
1962 character size.
1964 This function is a no-op for an X frame that is not visible.
1965 If you have just created a frame, you must wait for it to become visible
1966 before calling this function on it, like this.
1967 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1968 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1970 CHECK_LIVE_FRAME (frame);
1971 CHECK_TYPE_RANGED_INTEGER (int, x);
1972 CHECK_TYPE_RANGED_INTEGER (int, y);
1974 /* I think this should be done with a hook. */
1975 #ifdef HAVE_WINDOW_SYSTEM
1976 if (FRAME_WINDOW_P (XFRAME (frame)))
1977 /* Warping the mouse will cause enternotify and focus events. */
1978 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1979 #else
1980 #if defined (MSDOS)
1981 if (FRAME_MSDOS_P (XFRAME (frame)))
1983 Fselect_frame (frame, Qnil);
1984 mouse_moveto (XINT (x), XINT (y));
1986 #else
1987 #ifdef HAVE_GPM
1989 Fselect_frame (frame, Qnil);
1990 term_mouse_moveto (XINT (x), XINT (y));
1992 #endif
1993 #endif
1994 #endif
1996 return Qnil;
1999 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
2000 Sset_mouse_pixel_position, 3, 3, 0,
2001 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
2002 The position is given in pixels, where (0, 0) is the upper-left corner
2003 of the frame, X is the horizontal offset, and Y is the vertical offset.
2005 Note, this is a no-op for an X frame that is not visible.
2006 If you have just created a frame, you must wait for it to become visible
2007 before calling this function on it, like this.
2008 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2009 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2011 CHECK_LIVE_FRAME (frame);
2012 CHECK_TYPE_RANGED_INTEGER (int, x);
2013 CHECK_TYPE_RANGED_INTEGER (int, y);
2015 /* I think this should be done with a hook. */
2016 #ifdef HAVE_WINDOW_SYSTEM
2017 if (FRAME_WINDOW_P (XFRAME (frame)))
2018 /* Warping the mouse will cause enternotify and focus events. */
2019 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
2020 #else
2021 #if defined (MSDOS)
2022 if (FRAME_MSDOS_P (XFRAME (frame)))
2024 Fselect_frame (frame, Qnil);
2025 mouse_moveto (XINT (x), XINT (y));
2027 #else
2028 #ifdef HAVE_GPM
2030 Fselect_frame (frame, Qnil);
2031 term_mouse_moveto (XINT (x), XINT (y));
2033 #endif
2034 #endif
2035 #endif
2037 return Qnil;
2040 static void make_frame_visible_1 (Lisp_Object);
2042 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2043 0, 1, "",
2044 doc: /* Make the frame FRAME visible (assuming it is an X window).
2045 If omitted, FRAME defaults to the currently selected frame. */)
2046 (Lisp_Object frame)
2048 struct frame *f = decode_live_frame (frame);
2050 /* I think this should be done with a hook. */
2051 #ifdef HAVE_WINDOW_SYSTEM
2052 if (FRAME_WINDOW_P (f))
2053 x_make_frame_visible (f);
2054 #endif
2056 make_frame_visible_1 (f->root_window);
2058 /* Make menu bar update for the Buffers and Frames menus. */
2059 /* windows_or_buffers_changed = 15; FIXME: Why? */
2061 XSETFRAME (frame, f);
2062 return frame;
2065 /* Update the display_time slot of the buffers shown in WINDOW
2066 and all its descendants. */
2068 static void
2069 make_frame_visible_1 (Lisp_Object window)
2071 struct window *w;
2073 for (; !NILP (window); window = w->next)
2075 w = XWINDOW (window);
2076 if (WINDOWP (w->contents))
2077 make_frame_visible_1 (w->contents);
2078 else
2079 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2083 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2084 0, 2, "",
2085 doc: /* Make the frame FRAME invisible.
2086 If omitted, FRAME defaults to the currently selected frame.
2087 On graphical displays, invisible frames are not updated and are
2088 usually not displayed at all, even in a window system's \"taskbar\".
2090 Normally you may not make FRAME invisible if all other frames are invisible,
2091 but if the second optional argument FORCE is non-nil, you may do so.
2093 This function has no effect on text terminal frames. Such frames are
2094 always considered visible, whether or not they are currently being
2095 displayed in the terminal. */)
2096 (Lisp_Object frame, Lisp_Object force)
2098 struct frame *f = decode_live_frame (frame);
2100 if (NILP (force) && !other_visible_frames (f))
2101 error ("Attempt to make invisible the sole visible or iconified frame");
2103 /* Don't allow minibuf_window to remain on an invisible frame. */
2104 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2106 /* I think this should be done with a hook. */
2107 #ifdef HAVE_WINDOW_SYSTEM
2108 if (FRAME_WINDOW_P (f))
2109 x_make_frame_invisible (f);
2110 #endif
2112 /* Make menu bar update for the Buffers and Frames menus. */
2113 windows_or_buffers_changed = 16;
2115 return Qnil;
2118 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2119 0, 1, "",
2120 doc: /* Make the frame FRAME into an icon.
2121 If omitted, FRAME defaults to the currently selected frame. */)
2122 (Lisp_Object frame)
2124 struct frame *f = decode_live_frame (frame);
2126 /* Don't allow minibuf_window to remain on an iconified frame. */
2127 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2129 /* I think this should be done with a hook. */
2130 #ifdef HAVE_WINDOW_SYSTEM
2131 if (FRAME_WINDOW_P (f))
2132 x_iconify_frame (f);
2133 #endif
2135 /* Make menu bar update for the Buffers and Frames menus. */
2136 windows_or_buffers_changed = 17;
2138 return Qnil;
2141 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2142 1, 1, 0,
2143 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2144 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2145 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2146 On graphical displays, invisible frames are not updated and are
2147 usually not displayed at all, even in a window system's \"taskbar\".
2149 If FRAME is a text terminal frame, this always returns t.
2150 Such frames are always considered visible, whether or not they are
2151 currently being displayed on the terminal. */)
2152 (Lisp_Object frame)
2154 CHECK_LIVE_FRAME (frame);
2156 if (FRAME_VISIBLE_P (XFRAME (frame)))
2157 return Qt;
2158 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2159 return Qicon;
2160 return Qnil;
2163 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2164 0, 0, 0,
2165 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2166 (void)
2168 Lisp_Object tail, frame, value = Qnil;
2170 FOR_EACH_FRAME (tail, frame)
2171 if (FRAME_VISIBLE_P (XFRAME (frame)))
2172 value = Fcons (frame, value);
2174 return value;
2178 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2179 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2180 If FRAME is invisible or iconified, make it visible.
2181 If you don't specify a frame, the selected frame is used.
2182 If Emacs is displaying on an ordinary terminal or some other device which
2183 doesn't support multiple overlapping frames, this function selects FRAME. */)
2184 (Lisp_Object frame)
2186 struct frame *f = decode_live_frame (frame);
2188 XSETFRAME (frame, f);
2190 if (FRAME_TERMCAP_P (f))
2191 /* On a text terminal select FRAME. */
2192 Fselect_frame (frame, Qnil);
2193 else
2194 /* Do like the documentation says. */
2195 Fmake_frame_visible (frame);
2197 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2198 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2200 return Qnil;
2203 /* Should we have a corresponding function called Flower_Power? */
2204 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2205 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2206 If you don't specify a frame, the selected frame is used.
2207 If Emacs is displaying on an ordinary terminal or some other device which
2208 doesn't support multiple overlapping frames, this function does nothing. */)
2209 (Lisp_Object frame)
2211 struct frame *f = decode_live_frame (frame);
2213 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2214 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2216 return Qnil;
2220 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2221 1, 2, 0,
2222 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2223 In other words, switch-frame events caused by events in FRAME will
2224 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2225 FOCUS-FRAME after reading an event typed at FRAME.
2227 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2228 frame again receives its own keystrokes.
2230 Focus redirection is useful for temporarily redirecting keystrokes to
2231 a surrogate minibuffer frame when a frame doesn't have its own
2232 minibuffer window.
2234 A frame's focus redirection can be changed by `select-frame'. If frame
2235 FOO is selected, and then a different frame BAR is selected, any
2236 frames redirecting their focus to FOO are shifted to redirect their
2237 focus to BAR. This allows focus redirection to work properly when the
2238 user switches from one frame to another using `select-window'.
2240 This means that a frame whose focus is redirected to itself is treated
2241 differently from a frame whose focus is redirected to nil; the former
2242 is affected by `select-frame', while the latter is not.
2244 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2245 (Lisp_Object frame, Lisp_Object focus_frame)
2247 /* Note that we don't check for a live frame here. It's reasonable
2248 to redirect the focus of a frame you're about to delete, if you
2249 know what other frame should receive those keystrokes. */
2250 struct frame *f = decode_any_frame (frame);
2252 if (! NILP (focus_frame))
2253 CHECK_LIVE_FRAME (focus_frame);
2255 fset_focus_frame (f, focus_frame);
2257 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2258 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2260 return Qnil;
2264 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2265 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2266 If FRAME is omitted or nil, the selected frame is used.
2267 Return nil if FRAME's focus is not redirected.
2268 See `redirect-frame-focus'. */)
2269 (Lisp_Object frame)
2271 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2274 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2275 doc: /* Set the input focus to FRAME.
2276 FRAME nil means use the selected frame.
2277 If there is no window system support, this function does nothing. */)
2278 (Lisp_Object frame)
2280 #ifdef HAVE_WINDOW_SYSTEM
2281 x_focus_frame (decode_window_system_frame (frame));
2282 #endif
2283 return Qnil;
2286 DEFUN ("frame-after-make-frame",
2287 Fframe_after_make_frame,
2288 Sframe_after_make_frame, 2, 2, 0,
2289 doc: /* Mark FRAME as made.
2290 FRAME nil means use the selected frame. Second argument MADE non-nil
2291 means functions on `window-configuration-change-hook' are called
2292 whenever the window configuration of FRAME changes. MADE nil means
2293 these functions are not called.
2295 This function is currently called by `make-frame' only and should be
2296 otherwise used with utter care to avoid that running functions on
2297 `window-configuration-change-hook' is impeded forever. */)
2298 (Lisp_Object frame, Lisp_Object made)
2300 struct frame *f = decode_live_frame (frame);
2302 f->after_make_frame = NILP (made) ? false : true;
2304 return made;
2308 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2310 void
2311 frames_discard_buffer (Lisp_Object buffer)
2313 Lisp_Object frame, tail;
2315 FOR_EACH_FRAME (tail, frame)
2317 fset_buffer_list
2318 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2319 fset_buried_buffer_list
2320 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2324 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2325 If the alist already has an element for PROP, we change it. */
2327 void
2328 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2330 register Lisp_Object tem;
2332 tem = Fassq (prop, *alistptr);
2333 if (EQ (tem, Qnil))
2334 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2335 else
2336 Fsetcdr (tem, val);
2339 static int
2340 frame_name_fnn_p (char *str, ptrdiff_t len)
2342 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2344 char *p = str + 2;
2345 while ('0' <= *p && *p <= '9')
2346 p++;
2347 if (p == str + len)
2348 return 1;
2350 return 0;
2353 /* Set the name of the terminal frame. Also used by MSDOS frames.
2354 Modeled after x_set_name which is used for WINDOW frames. */
2356 static void
2357 set_term_frame_name (struct frame *f, Lisp_Object name)
2359 f->explicit_name = ! NILP (name);
2361 /* If NAME is nil, set the name to F<num>. */
2362 if (NILP (name))
2364 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2366 /* Check for no change needed in this very common case
2367 before we do any consing. */
2368 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2369 return;
2371 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2373 else
2375 CHECK_STRING (name);
2377 /* Don't change the name if it's already NAME. */
2378 if (! NILP (Fstring_equal (name, f->name)))
2379 return;
2381 /* Don't allow the user to set the frame name to F<num>, so it
2382 doesn't clash with the names we generate for terminal frames. */
2383 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2384 error ("Frame names of the form F<num> are usurped by Emacs");
2387 fset_name (f, name);
2388 update_mode_lines = 16;
2391 void
2392 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2394 register Lisp_Object old_alist_elt;
2396 /* The buffer-list parameters are stored in a special place and not
2397 in the alist. All buffers must be live. */
2398 if (EQ (prop, Qbuffer_list))
2400 Lisp_Object list = Qnil;
2401 for (; CONSP (val); val = XCDR (val))
2402 if (!NILP (Fbuffer_live_p (XCAR (val))))
2403 list = Fcons (XCAR (val), list);
2404 fset_buffer_list (f, Fnreverse (list));
2405 return;
2407 if (EQ (prop, Qburied_buffer_list))
2409 Lisp_Object list = Qnil;
2410 for (; CONSP (val); val = XCDR (val))
2411 if (!NILP (Fbuffer_live_p (XCAR (val))))
2412 list = Fcons (XCAR (val), list);
2413 fset_buried_buffer_list (f, Fnreverse (list));
2414 return;
2417 /* If PROP is a symbol which is supposed to have frame-local values,
2418 and it is set up based on this frame, switch to the global
2419 binding. That way, we can create or alter the frame-local binding
2420 without messing up the symbol's status. */
2421 if (SYMBOLP (prop))
2423 struct Lisp_Symbol *sym = XSYMBOL (prop);
2424 start:
2425 switch (sym->redirect)
2427 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2428 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2429 case SYMBOL_LOCALIZED:
2430 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2431 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2432 swap_in_global_binding (sym);
2433 break;
2435 default: emacs_abort ();
2439 /* The tty color needed to be set before the frame's parameter
2440 alist was updated with the new value. This is not true any more,
2441 but we still do this test early on. */
2442 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2443 && f == FRAME_TTY (f)->previous_frame)
2444 /* Force redisplay of this tty. */
2445 FRAME_TTY (f)->previous_frame = NULL;
2447 /* Update the frame parameter alist. */
2448 old_alist_elt = Fassq (prop, f->param_alist);
2449 if (EQ (old_alist_elt, Qnil))
2450 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2451 else
2452 Fsetcdr (old_alist_elt, val);
2454 /* Update some other special parameters in their special places
2455 in addition to the alist. */
2457 if (EQ (prop, Qbuffer_predicate))
2458 fset_buffer_predicate (f, val);
2460 if (! FRAME_WINDOW_P (f))
2462 if (EQ (prop, Qmenu_bar_lines))
2463 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2464 else if (EQ (prop, Qname))
2465 set_term_frame_name (f, val);
2468 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2470 if (! MINI_WINDOW_P (XWINDOW (val)))
2471 error ("Surrogate minibuffer windows must be minibuffer windows");
2473 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2474 && !EQ (val, f->minibuffer_window))
2475 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2477 /* Install the chosen minibuffer window, with proper buffer. */
2478 fset_minibuffer_window (f, val);
2482 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2483 is not an unspecified foreground or background color. */
2485 static Lisp_Object
2486 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2488 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2489 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2490 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2491 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2494 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2495 doc: /* Return the parameters-alist of frame FRAME.
2496 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2497 The meaningful PARMs depend on the kind of frame.
2498 If FRAME is omitted or nil, return information on the currently selected frame. */)
2499 (Lisp_Object frame)
2501 Lisp_Object alist;
2502 struct frame *f = decode_any_frame (frame);
2503 int height, width;
2504 struct gcpro gcpro1;
2506 if (!FRAME_LIVE_P (f))
2507 return Qnil;
2509 alist = Fcopy_alist (f->param_alist);
2510 GCPRO1 (alist);
2512 if (!FRAME_WINDOW_P (f))
2514 Lisp_Object elt;
2516 /* If the frame's parameter alist says the colors are
2517 unspecified and reversed, take the frame's background pixel
2518 for foreground and vice versa. */
2519 elt = Fassq (Qforeground_color, alist);
2520 if (CONSP (elt) && STRINGP (XCDR (elt)))
2522 elt = frame_unspecified_color (f, XCDR (elt));
2523 if (!NILP (elt))
2524 store_in_alist (&alist, Qforeground_color, elt);
2526 else
2527 store_in_alist (&alist, Qforeground_color,
2528 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2529 elt = Fassq (Qbackground_color, alist);
2530 if (CONSP (elt) && STRINGP (XCDR (elt)))
2532 elt = frame_unspecified_color (f, XCDR (elt));
2533 if (!NILP (elt))
2534 store_in_alist (&alist, Qbackground_color, elt);
2536 else
2537 store_in_alist (&alist, Qbackground_color,
2538 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2539 store_in_alist (&alist, intern ("font"),
2540 build_string (FRAME_MSDOS_P (f)
2541 ? "ms-dos"
2542 : FRAME_W32_P (f) ? "w32term"
2543 :"tty"));
2545 store_in_alist (&alist, Qname, f->name);
2546 height = (f->new_height
2547 ? (f->new_pixelwise
2548 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2549 : f->new_height)
2550 : FRAME_LINES (f));
2551 store_in_alist (&alist, Qheight, make_number (height));
2552 width = (f->new_width
2553 ? (f->new_pixelwise
2554 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2555 : f->new_width)
2556 : FRAME_COLS (f));
2557 store_in_alist (&alist, Qwidth, make_number (width));
2558 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2559 store_in_alist (&alist, Qminibuffer,
2560 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2561 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2562 : FRAME_MINIBUF_WINDOW (f)));
2563 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2564 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2565 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2567 /* I think this should be done with a hook. */
2568 #ifdef HAVE_WINDOW_SYSTEM
2569 if (FRAME_WINDOW_P (f))
2570 x_report_frame_params (f, &alist);
2571 else
2572 #endif
2574 /* This ought to be correct in f->param_alist for an X frame. */
2575 Lisp_Object lines;
2576 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2577 store_in_alist (&alist, Qmenu_bar_lines, lines);
2580 UNGCPRO;
2581 return alist;
2585 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2586 doc: /* Return FRAME's value for parameter PARAMETER.
2587 If FRAME is nil, describe the currently selected frame. */)
2588 (Lisp_Object frame, Lisp_Object parameter)
2590 struct frame *f = decode_any_frame (frame);
2591 Lisp_Object value = Qnil;
2593 CHECK_SYMBOL (parameter);
2595 XSETFRAME (frame, f);
2597 if (FRAME_LIVE_P (f))
2599 /* Avoid consing in frequent cases. */
2600 if (EQ (parameter, Qname))
2601 value = f->name;
2602 #ifdef HAVE_X_WINDOWS
2603 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2604 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2605 #endif /* HAVE_X_WINDOWS */
2606 else if (EQ (parameter, Qbackground_color)
2607 || EQ (parameter, Qforeground_color))
2609 value = Fassq (parameter, f->param_alist);
2610 if (CONSP (value))
2612 value = XCDR (value);
2613 /* Fframe_parameters puts the actual fg/bg color names,
2614 even if f->param_alist says otherwise. This is
2615 important when param_alist's notion of colors is
2616 "unspecified". We need to do the same here. */
2617 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2618 value = frame_unspecified_color (f, value);
2620 else
2621 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2623 else if (EQ (parameter, Qdisplay_type)
2624 || EQ (parameter, Qbackground_mode))
2625 value = Fcdr (Fassq (parameter, f->param_alist));
2626 else
2627 /* FIXME: Avoid this code path at all (as well as code duplication)
2628 by sharing more code with Fframe_parameters. */
2629 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2632 return value;
2636 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2637 Smodify_frame_parameters, 2, 2, 0,
2638 doc: /* Modify the parameters of frame FRAME according to ALIST.
2639 If FRAME is nil, it defaults to the selected frame.
2640 ALIST is an alist of parameters to change and their new values.
2641 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2642 The meaningful PARMs depend on the kind of frame.
2643 Undefined PARMs are ignored, but stored in the frame's parameter list
2644 so that `frame-parameters' will return them.
2646 The value of frame parameter FOO can also be accessed
2647 as a frame-local binding for the variable FOO, if you have
2648 enabled such bindings for that variable with `make-variable-frame-local'.
2649 Note that this functionality is obsolete as of Emacs 22.2, and its
2650 use is not recommended. Explicitly check for a frame-parameter instead. */)
2651 (Lisp_Object frame, Lisp_Object alist)
2653 struct frame *f = decode_live_frame (frame);
2654 register Lisp_Object prop, val;
2656 CHECK_LIST (alist);
2658 /* I think this should be done with a hook. */
2659 #ifdef HAVE_WINDOW_SYSTEM
2660 if (FRAME_WINDOW_P (f))
2661 x_set_frame_parameters (f, alist);
2662 else
2663 #endif
2664 #ifdef MSDOS
2665 if (FRAME_MSDOS_P (f))
2666 IT_set_frame_parameters (f, alist);
2667 else
2668 #endif
2671 EMACS_INT length = XFASTINT (Flength (alist));
2672 ptrdiff_t i;
2673 Lisp_Object *parms;
2674 Lisp_Object *values;
2675 USE_SAFE_ALLOCA;
2676 SAFE_ALLOCA_LISP (parms, 2 * length);
2677 values = parms + length;
2679 /* Extract parm names and values into those vectors. */
2681 for (i = 0; CONSP (alist); alist = XCDR (alist))
2683 Lisp_Object elt;
2685 elt = XCAR (alist);
2686 parms[i] = Fcar (elt);
2687 values[i] = Fcdr (elt);
2688 i++;
2691 /* Now process them in reverse of specified order. */
2692 while (--i >= 0)
2694 prop = parms[i];
2695 val = values[i];
2696 store_frame_param (f, prop, val);
2698 if (EQ (prop, Qforeground_color)
2699 || EQ (prop, Qbackground_color))
2700 update_face_from_frame_parameter (f, prop, val);
2703 SAFE_FREE ();
2705 return Qnil;
2708 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2709 0, 1, 0,
2710 doc: /* Height in pixels of a line in the font in frame FRAME.
2711 If FRAME is omitted or nil, the selected frame is used.
2712 For a terminal frame, the value is always 1. */)
2713 (Lisp_Object frame)
2715 #ifdef HAVE_WINDOW_SYSTEM
2716 struct frame *f = decode_any_frame (frame);
2718 if (FRAME_WINDOW_P (f))
2719 return make_number (FRAME_LINE_HEIGHT (f));
2720 else
2721 #endif
2722 return make_number (1);
2726 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2727 0, 1, 0,
2728 doc: /* Width in pixels of characters in the font in frame FRAME.
2729 If FRAME is omitted or nil, the selected frame is used.
2730 On a graphical screen, the width is the standard width of the default font.
2731 For a terminal screen, the value is always 1. */)
2732 (Lisp_Object frame)
2734 #ifdef HAVE_WINDOW_SYSTEM
2735 struct frame *f = decode_any_frame (frame);
2737 if (FRAME_WINDOW_P (f))
2738 return make_number (FRAME_COLUMN_WIDTH (f));
2739 else
2740 #endif
2741 return make_number (1);
2744 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2745 Sframe_pixel_height, 0, 1, 0,
2746 doc: /* Return a FRAME's height in pixels.
2747 If FRAME is omitted or nil, the selected frame is used. The exact value
2748 of the result depends on the window-system and toolkit in use:
2750 In the Gtk+ version of Emacs, it includes only any window (including
2751 the minibuffer or echo area), mode line, and header line. It does not
2752 include the tool bar or menu bar.
2754 With other graphical versions, it also includes the tool bar and the
2755 menu bar.
2757 For a text terminal, it includes the menu bar. In this case, the
2758 result is really in characters rather than pixels (i.e., is identical
2759 to `frame-height'). */)
2760 (Lisp_Object frame)
2762 struct frame *f = decode_any_frame (frame);
2764 #ifdef HAVE_WINDOW_SYSTEM
2765 if (FRAME_WINDOW_P (f))
2766 return make_number (FRAME_PIXEL_HEIGHT (f));
2767 else
2768 #endif
2769 return make_number (FRAME_TOTAL_LINES (f));
2772 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2773 Sframe_pixel_width, 0, 1, 0,
2774 doc: /* Return FRAME's width in pixels.
2775 For a terminal frame, the result really gives the width in characters.
2776 If FRAME is omitted or nil, the selected frame is used. */)
2777 (Lisp_Object frame)
2779 struct frame *f = decode_any_frame (frame);
2781 #ifdef HAVE_WINDOW_SYSTEM
2782 if (FRAME_WINDOW_P (f))
2783 return make_number (FRAME_PIXEL_WIDTH (f));
2784 else
2785 #endif
2786 return make_number (FRAME_TOTAL_COLS (f));
2789 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2790 Stool_bar_pixel_width, 0, 1, 0,
2791 doc: /* Return width in pixels of FRAME's tool bar.
2792 The result is greater than zero only when the tool bar is on the left
2793 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2794 is used. */)
2795 (Lisp_Object frame)
2797 #ifdef FRAME_TOOLBAR_WIDTH
2798 struct frame *f = decode_any_frame (frame);
2800 if (FRAME_WINDOW_P (f))
2801 return make_number (FRAME_TOOLBAR_WIDTH (f));
2802 #endif
2803 return make_number (0);
2806 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2807 doc: /* Return width in columns of FRAME's text area. */)
2808 (Lisp_Object frame)
2810 return make_number (FRAME_COLS (decode_any_frame (frame)));
2813 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2814 doc: /* Return height in lines of FRAME's text area. */)
2815 (Lisp_Object frame)
2817 return make_number (FRAME_LINES (decode_any_frame (frame)));
2820 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2821 doc: /* Return number of total columns of FRAME. */)
2822 (Lisp_Object frame)
2824 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2827 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2828 doc: /* Return number of total lines of FRAME. */)
2829 (Lisp_Object frame)
2831 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2834 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2835 doc: /* Return text area width of FRAME in pixels. */)
2836 (Lisp_Object frame)
2838 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2841 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2842 doc: /* Return text area height of FRAME in pixels. */)
2843 (Lisp_Object frame)
2845 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2848 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2849 doc: /* Return scroll bar width of FRAME in pixels. */)
2850 (Lisp_Object frame)
2852 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2855 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2856 doc: /* Return scroll bar height of FRAME in pixels. */)
2857 (Lisp_Object frame)
2859 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2862 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2863 doc: /* Return fringe width of FRAME in pixels. */)
2864 (Lisp_Object frame)
2866 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2869 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2870 doc: /* Return border width of FRAME in pixels. */)
2871 (Lisp_Object frame)
2873 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2876 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2877 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2878 (Lisp_Object frame)
2880 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2883 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2884 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2885 (Lisp_Object frame)
2887 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2890 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2891 doc: /* Set text height of frame FRAME to HEIGHT lines.
2892 Optional third arg PRETEND non-nil means that redisplay should use
2893 HEIGHT lines but that the idea of the actual height of the frame should
2894 not be changed.
2896 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2897 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
2898 window managers may refuse to honor a HEIGHT that is not an integer
2899 multiple of the default frame font height. */)
2900 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2902 struct frame *f = decode_live_frame (frame);
2903 int pixel_height;
2905 CHECK_TYPE_RANGED_INTEGER (int, height);
2907 pixel_height = (!NILP (pixelwise)
2908 ? XINT (height)
2909 : XINT (height) * FRAME_LINE_HEIGHT (f));
2910 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
2912 return Qnil;
2915 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2916 doc: /* Set text width of frame FRAME to WIDTH columns.
2917 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2918 columns but that the idea of the actual width of the frame should not
2919 be changed.
2921 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2922 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
2923 window managers may refuse to honor a WIDTH that is not an integer
2924 multiple of the default frame font width. */)
2925 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2927 struct frame *f = decode_live_frame (frame);
2928 int pixel_width;
2930 CHECK_TYPE_RANGED_INTEGER (int, width);
2932 pixel_width = (!NILP (pixelwise)
2933 ? XINT (width)
2934 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2935 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
2937 return Qnil;
2940 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2941 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
2942 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
2943 When `frame-resize-pixelwise' is nil, some window managers may refuse to
2944 honor a WIDTH that is not an integer multiple of the default frame font
2945 width or a HEIGHT that is not an integer multiple of the default frame
2946 font height. */)
2947 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2949 struct frame *f = decode_live_frame (frame);
2950 int pixel_width, pixel_height;
2952 CHECK_TYPE_RANGED_INTEGER (int, width);
2953 CHECK_TYPE_RANGED_INTEGER (int, height);
2955 pixel_width = (!NILP (pixelwise)
2956 ? XINT (width)
2957 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2958 pixel_height = (!NILP (pixelwise)
2959 ? XINT (height)
2960 : XINT (height) * FRAME_LINE_HEIGHT (f));
2961 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
2963 return Qnil;
2966 DEFUN ("set-frame-position", Fset_frame_position,
2967 Sset_frame_position, 3, 3, 0,
2968 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2969 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2970 actually the position of the upper left corner of the frame. Negative
2971 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2972 or bottommost possible position (that stays within the screen). */)
2973 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2975 register struct frame *f = decode_live_frame (frame);
2977 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2978 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2980 /* I think this should be done with a hook. */
2981 #ifdef HAVE_WINDOW_SYSTEM
2982 if (FRAME_WINDOW_P (f))
2983 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2984 #endif
2986 return Qt;
2990 /***********************************************************************
2991 Frame Parameters
2992 ***********************************************************************/
2994 /* Connect the frame-parameter names for X frames
2995 to the ways of passing the parameter values to the window system.
2997 The name of a parameter, as a Lisp symbol,
2998 has an `x-frame-parameter' property which is an integer in Lisp
2999 that is an index in this table. */
3001 struct frame_parm_table {
3002 const char *name;
3003 int sym;
3006 static const struct frame_parm_table frame_parms[] =
3008 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3009 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3010 {"background-color", -1},
3011 {"border-color", SYMBOL_INDEX (Qborder_color)},
3012 {"border-width", SYMBOL_INDEX (Qborder_width)},
3013 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3014 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3015 {"font", -1},
3016 {"foreground-color", -1},
3017 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3018 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3019 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3020 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3021 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3022 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3023 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3024 {"name", SYMBOL_INDEX (Qname)},
3025 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3026 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3027 {"title", SYMBOL_INDEX (Qtitle)},
3028 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3029 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3030 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3031 {"visibility", SYMBOL_INDEX (Qvisibility)},
3032 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3033 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3034 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3035 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3036 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3037 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3038 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3039 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3040 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3041 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3042 {"alpha", SYMBOL_INDEX (Qalpha)},
3043 {"sticky", SYMBOL_INDEX (Qsticky)},
3044 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3047 #ifdef HAVE_WINDOW_SYSTEM
3049 /* Change the parameters of frame F as specified by ALIST.
3050 If a parameter is not specially recognized, do nothing special;
3051 otherwise call the `x_set_...' function for that parameter.
3052 Except for certain geometry properties, always call store_frame_param
3053 to store the new value in the parameter alist. */
3055 void
3056 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3058 Lisp_Object tail;
3060 /* If both of these parameters are present, it's more efficient to
3061 set them both at once. So we wait until we've looked at the
3062 entire list before we set them. */
3063 int width IF_LINT (= 0), height IF_LINT (= 0);
3064 bool width_change = false, height_change = false;
3066 /* Same here. */
3067 Lisp_Object left, top;
3069 /* Same with these. */
3070 Lisp_Object icon_left, icon_top;
3072 /* And with this. */
3073 Lisp_Object fullscreen;
3074 bool fullscreen_change = false;
3076 /* Record in these vectors all the parms specified. */
3077 Lisp_Object *parms;
3078 Lisp_Object *values;
3079 ptrdiff_t i, p;
3080 bool left_no_change = 0, top_no_change = 0;
3081 #ifdef HAVE_X_WINDOWS
3082 bool icon_left_no_change = 0, icon_top_no_change = 0;
3083 #endif
3085 i = 0;
3086 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3087 i++;
3089 USE_SAFE_ALLOCA;
3090 SAFE_ALLOCA_LISP (parms, 2 * i);
3091 values = parms + i;
3093 /* Extract parm names and values into those vectors. */
3095 i = 0;
3096 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3098 Lisp_Object elt;
3100 elt = XCAR (tail);
3101 parms[i] = Fcar (elt);
3102 values[i] = Fcdr (elt);
3103 i++;
3105 /* TAIL and ALIST are not used again below here. */
3106 alist = tail = Qnil;
3108 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
3109 because their values appear in VALUES and strings are not valid. */
3110 top = left = Qunbound;
3111 icon_left = icon_top = Qunbound;
3113 /* Process foreground_color and background_color before anything else.
3114 They are independent of other properties, but other properties (e.g.,
3115 cursor_color) are dependent upon them. */
3116 /* Process default font as well, since fringe widths depends on it. */
3117 for (p = 0; p < i; p++)
3119 Lisp_Object prop, val;
3121 prop = parms[p];
3122 val = values[p];
3123 if (EQ (prop, Qforeground_color)
3124 || EQ (prop, Qbackground_color)
3125 || EQ (prop, Qfont))
3127 register Lisp_Object param_index, old_value;
3129 old_value = get_frame_param (f, prop);
3130 if (NILP (Fequal (val, old_value)))
3132 store_frame_param (f, prop, val);
3134 param_index = Fget (prop, Qx_frame_parameter);
3135 if (NATNUMP (param_index)
3136 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3137 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3138 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3143 /* Now process them in reverse of specified order. */
3144 while (i-- != 0)
3146 Lisp_Object prop, val;
3148 prop = parms[i];
3149 val = values[i];
3151 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
3153 width_change = 1;
3154 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3156 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
3158 height_change = 1;
3159 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3161 else if (EQ (prop, Qtop))
3162 top = val;
3163 else if (EQ (prop, Qleft))
3164 left = val;
3165 else if (EQ (prop, Qicon_top))
3166 icon_top = val;
3167 else if (EQ (prop, Qicon_left))
3168 icon_left = val;
3169 else if (EQ (prop, Qfullscreen))
3171 fullscreen = val;
3172 fullscreen_change = true;
3174 else if (EQ (prop, Qforeground_color)
3175 || EQ (prop, Qbackground_color)
3176 || EQ (prop, Qfont))
3177 /* Processed above. */
3178 continue;
3179 else
3181 register Lisp_Object param_index, old_value;
3183 old_value = get_frame_param (f, prop);
3185 store_frame_param (f, prop, val);
3187 param_index = Fget (prop, Qx_frame_parameter);
3188 if (NATNUMP (param_index)
3189 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3190 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3191 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3195 /* Don't die if just one of these was set. */
3196 if (EQ (left, Qunbound))
3198 left_no_change = 1;
3199 if (f->left_pos < 0)
3200 left = list2 (Qplus, make_number (f->left_pos));
3201 else
3202 XSETINT (left, f->left_pos);
3204 if (EQ (top, Qunbound))
3206 top_no_change = 1;
3207 if (f->top_pos < 0)
3208 top = list2 (Qplus, make_number (f->top_pos));
3209 else
3210 XSETINT (top, f->top_pos);
3213 /* If one of the icon positions was not set, preserve or default it. */
3214 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3216 #ifdef HAVE_X_WINDOWS
3217 icon_left_no_change = 1;
3218 #endif
3219 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3220 if (NILP (icon_left))
3221 XSETINT (icon_left, 0);
3223 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3225 #ifdef HAVE_X_WINDOWS
3226 icon_top_no_change = 1;
3227 #endif
3228 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3229 if (NILP (icon_top))
3230 XSETINT (icon_top, 0);
3233 /* Don't set these parameters unless they've been explicitly
3234 specified. The window might be mapped or resized while we're in
3235 this function, and we don't want to override that unless the lisp
3236 code has asked for it.
3238 Don't set these parameters unless they actually differ from the
3239 window's current parameters; the window may not actually exist
3240 yet. */
3242 Lisp_Object frame;
3244 XSETFRAME (frame, f);
3246 if ((width_change && width != FRAME_TEXT_WIDTH (f))
3247 || (height_change && height != FRAME_TEXT_HEIGHT (f))
3248 || (f->can_x_set_window_size && (f->new_height || f->new_width)))
3250 /* If necessary provide default values for HEIGHT and WIDTH. Do
3251 that here since otherwise a size change implied by an
3252 intermittent font change may get lost as in Bug#17142. */
3253 if (!width_change)
3254 width = ((f->can_x_set_window_size && f->new_width)
3255 ? (f->new_pixelwise
3256 ? f->new_width
3257 : (f->new_width * FRAME_COLUMN_WIDTH (f)))
3258 : FRAME_TEXT_WIDTH (f));
3260 if (!height_change)
3261 height = ((f->can_x_set_window_size && f->new_height)
3262 ? (f->new_pixelwise
3263 ? f->new_height
3264 : (f->new_height * FRAME_LINE_HEIGHT (f)))
3265 : FRAME_TEXT_HEIGHT (f));
3267 Fset_frame_size (frame, make_number (width), make_number (height), Qt);
3270 if ((!NILP (left) || !NILP (top))
3271 && ! (left_no_change && top_no_change)
3272 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3273 && NUMBERP (top) && XINT (top) == f->top_pos))
3275 int leftpos = 0;
3276 int toppos = 0;
3278 /* Record the signs. */
3279 f->size_hint_flags &= ~ (XNegative | YNegative);
3280 if (EQ (left, Qminus))
3281 f->size_hint_flags |= XNegative;
3282 else if (TYPE_RANGED_INTEGERP (int, left))
3284 leftpos = XINT (left);
3285 if (leftpos < 0)
3286 f->size_hint_flags |= XNegative;
3288 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3289 && CONSP (XCDR (left))
3290 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3292 leftpos = - XINT (XCAR (XCDR (left)));
3293 f->size_hint_flags |= XNegative;
3295 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3296 && CONSP (XCDR (left))
3297 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3299 leftpos = XINT (XCAR (XCDR (left)));
3302 if (EQ (top, Qminus))
3303 f->size_hint_flags |= YNegative;
3304 else if (TYPE_RANGED_INTEGERP (int, top))
3306 toppos = XINT (top);
3307 if (toppos < 0)
3308 f->size_hint_flags |= YNegative;
3310 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3311 && CONSP (XCDR (top))
3312 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3314 toppos = - XINT (XCAR (XCDR (top)));
3315 f->size_hint_flags |= YNegative;
3317 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3318 && CONSP (XCDR (top))
3319 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3321 toppos = XINT (XCAR (XCDR (top)));
3325 /* Store the numeric value of the position. */
3326 f->top_pos = toppos;
3327 f->left_pos = leftpos;
3329 f->win_gravity = NorthWestGravity;
3331 /* Actually set that position, and convert to absolute. */
3332 x_set_offset (f, leftpos, toppos, -1);
3335 if (fullscreen_change)
3337 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
3339 frame_size_history_add
3340 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
3342 store_frame_param (f, Qfullscreen, fullscreen);
3343 if (!EQ (fullscreen, old_value))
3344 x_set_fullscreen (f, fullscreen, old_value);
3348 #ifdef HAVE_X_WINDOWS
3349 if ((!NILP (icon_left) || !NILP (icon_top))
3350 && ! (icon_left_no_change && icon_top_no_change))
3351 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3352 #endif /* HAVE_X_WINDOWS */
3355 SAFE_FREE ();
3359 /* Insert a description of internally-recorded parameters of frame X
3360 into the parameter alist *ALISTPTR that is to be given to the user.
3361 Only parameters that are specific to the X window system
3362 and whose values are not correctly recorded in the frame's
3363 param_alist need to be considered here. */
3365 void
3366 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3368 Lisp_Object tem;
3369 uprintmax_t w;
3370 char buf[INT_BUFSIZE_BOUND (w)];
3372 /* Represent negative positions (off the top or left screen edge)
3373 in a way that Fmodify_frame_parameters will understand correctly. */
3374 XSETINT (tem, f->left_pos);
3375 if (f->left_pos >= 0)
3376 store_in_alist (alistptr, Qleft, tem);
3377 else
3378 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3380 XSETINT (tem, f->top_pos);
3381 if (f->top_pos >= 0)
3382 store_in_alist (alistptr, Qtop, tem);
3383 else
3384 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3386 store_in_alist (alistptr, Qborder_width,
3387 make_number (f->border_width));
3388 store_in_alist (alistptr, Qinternal_border_width,
3389 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3390 store_in_alist (alistptr, Qright_divider_width,
3391 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3392 store_in_alist (alistptr, Qbottom_divider_width,
3393 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3394 store_in_alist (alistptr, Qleft_fringe,
3395 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3396 store_in_alist (alistptr, Qright_fringe,
3397 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3398 store_in_alist (alistptr, Qscroll_bar_width,
3399 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3400 ? make_number (0)
3401 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3402 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3403 /* nil means "use default width"
3404 for non-toolkit scroll bar.
3405 ruler-mode.el depends on this. */
3406 : Qnil));
3407 store_in_alist (alistptr, Qscroll_bar_height,
3408 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3409 ? make_number (0)
3410 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3411 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3412 /* nil means "use default height"
3413 for non-toolkit scroll bar. */
3414 : Qnil));
3415 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3416 MS-Windows it returns a value whose type is HANDLE, which is
3417 actually a pointer. Explicit casting avoids compiler
3418 warnings. */
3419 w = (uintptr_t) FRAME_X_WINDOW (f);
3420 store_in_alist (alistptr, Qwindow_id,
3421 make_formatted_string (buf, "%"pMu, w));
3422 #ifdef HAVE_X_WINDOWS
3423 #ifdef USE_X_TOOLKIT
3424 /* Tooltip frame may not have this widget. */
3425 if (FRAME_X_OUTPUT (f)->widget)
3426 #endif
3427 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3428 store_in_alist (alistptr, Qouter_window_id,
3429 make_formatted_string (buf, "%"pMu, w));
3430 #endif
3431 store_in_alist (alistptr, Qicon_name, f->icon_name);
3432 store_in_alist (alistptr, Qvisibility,
3433 (FRAME_VISIBLE_P (f) ? Qt
3434 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3435 store_in_alist (alistptr, Qdisplay,
3436 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3438 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3439 tem = Qnil;
3440 else
3441 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3442 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3443 store_in_alist (alistptr, Qparent_id, tem);
3444 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3448 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3449 the previous value of that parameter, NEW_VALUE is the new value. */
3451 void
3452 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3454 if (NILP (new_value))
3455 f->want_fullscreen = FULLSCREEN_NONE;
3456 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3457 f->want_fullscreen = FULLSCREEN_BOTH;
3458 else if (EQ (new_value, Qfullwidth))
3459 f->want_fullscreen = FULLSCREEN_WIDTH;
3460 else if (EQ (new_value, Qfullheight))
3461 f->want_fullscreen = FULLSCREEN_HEIGHT;
3462 else if (EQ (new_value, Qmaximized))
3463 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3465 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3466 FRAME_TERMINAL (f)->fullscreen_hook (f);
3470 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3471 the previous value of that parameter, NEW_VALUE is the new value. */
3473 void
3474 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3476 if (NILP (new_value))
3477 f->extra_line_spacing = 0;
3478 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3479 f->extra_line_spacing = XFASTINT (new_value);
3480 else if (FLOATP (new_value))
3482 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3484 if (new_spacing >= 0)
3485 f->extra_line_spacing = new_spacing;
3486 else
3487 signal_error ("Invalid line-spacing", new_value);
3489 else
3490 signal_error ("Invalid line-spacing", new_value);
3491 if (FRAME_VISIBLE_P (f))
3492 redraw_frame (f);
3496 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3497 the previous value of that parameter, NEW_VALUE is the new value. */
3499 void
3500 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3502 Lisp_Object bgcolor;
3504 if (NILP (new_value))
3505 f->gamma = 0;
3506 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3507 /* The value 0.4545 is the normal viewing gamma. */
3508 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3509 else
3510 signal_error ("Invalid screen-gamma", new_value);
3512 /* Apply the new gamma value to the frame background. */
3513 bgcolor = Fassq (Qbackground_color, f->param_alist);
3514 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3516 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3517 if (NATNUMP (parm_index)
3518 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3519 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3520 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3521 (f, bgcolor, Qnil);
3524 Fclear_face_cache (Qnil);
3528 void
3529 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3531 Lisp_Object font_object;
3532 int fontset = -1;
3533 #ifdef HAVE_X_WINDOWS
3534 Lisp_Object font_param = arg;
3535 #endif
3537 /* Set the frame parameter back to the old value because we may
3538 fail to use ARG as the new parameter value. */
3539 store_frame_param (f, Qfont, oldval);
3541 /* ARG is a fontset name, a font name, a cons of fontset name and a
3542 font object, or a font object. In the last case, this function
3543 never fail. */
3544 if (STRINGP (arg))
3546 fontset = fs_query_fontset (arg, 0);
3547 if (fontset < 0)
3549 font_object = font_open_by_name (f, arg);
3550 if (NILP (font_object))
3551 error ("Font `%s' is not defined", SSDATA (arg));
3552 arg = AREF (font_object, FONT_NAME_INDEX);
3554 else if (fontset > 0)
3556 font_object = font_open_by_name (f, fontset_ascii (fontset));
3557 if (NILP (font_object))
3558 error ("Font `%s' is not defined", SDATA (arg));
3559 arg = AREF (font_object, FONT_NAME_INDEX);
3561 else
3562 error ("The default fontset can't be used for a frame font");
3564 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3566 /* This is the case that the ASCII font of F's fontset XCAR
3567 (arg) is changed to the font XCDR (arg) by
3568 `set-fontset-font'. */
3569 fontset = fs_query_fontset (XCAR (arg), 0);
3570 if (fontset < 0)
3571 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3572 font_object = XCDR (arg);
3573 arg = AREF (font_object, FONT_NAME_INDEX);
3574 #ifdef HAVE_X_WINDOWS
3575 font_param = Ffont_get (font_object, QCname);
3576 #endif
3578 else if (FONT_OBJECT_P (arg))
3580 font_object = arg;
3581 #ifdef HAVE_X_WINDOWS
3582 font_param = Ffont_get (font_object, QCname);
3583 #endif
3584 /* This is to store the XLFD font name in the frame parameter for
3585 backward compatibility. We should store the font-object
3586 itself in the future. */
3587 arg = AREF (font_object, FONT_NAME_INDEX);
3588 fontset = FRAME_FONTSET (f);
3589 /* Check if we can use the current fontset. If not, set FONTSET
3590 to -1 to generate a new fontset from FONT-OBJECT. */
3591 if (fontset >= 0)
3593 Lisp_Object ascii_font = fontset_ascii (fontset);
3594 Lisp_Object spec = font_spec_from_name (ascii_font);
3596 if (NILP (spec))
3597 signal_error ("Invalid font name", ascii_font);
3599 if (! font_match_p (spec, font_object))
3600 fontset = -1;
3603 else
3604 signal_error ("Invalid font", arg);
3606 if (! NILP (Fequal (font_object, oldval)))
3607 return;
3609 x_new_font (f, font_object, fontset);
3610 store_frame_param (f, Qfont, arg);
3611 #ifdef HAVE_X_WINDOWS
3612 store_frame_param (f, Qfont_param, font_param);
3613 #endif
3614 /* Recalculate toolbar height. */
3615 f->n_tool_bar_rows = 0;
3617 /* Ensure we redraw it. */
3618 clear_current_matrices (f);
3620 /* Attempt to hunt down bug#16028. */
3621 SET_FRAME_GARBAGED (f);
3623 recompute_basic_faces (f);
3625 do_pending_window_change (0);
3627 /* We used to call face-set-after-frame-default here, but it leads to
3628 recursive calls (since that function can set the `default' face's
3629 font which in turns changes the frame's `font' parameter).
3630 Also I don't know what this call is meant to do, but it seems the
3631 wrong way to do it anyway (it does a lot more work than what seems
3632 reasonable in response to a change to `font'). */
3636 void
3637 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3639 if (! NILP (new_value)
3640 && !CONSP (new_value))
3642 char *p0, *p1;
3644 CHECK_STRING (new_value);
3645 p0 = p1 = SSDATA (new_value);
3646 new_value = Qnil;
3647 while (*p0)
3649 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3650 if (p0 < p1)
3651 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3652 new_value);
3653 if (*p1)
3655 int c;
3657 while ((c = *++p1) && c_isspace (c));
3659 p0 = p1;
3661 new_value = Fnreverse (new_value);
3664 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3665 return;
3667 if (FRAME_FONT (f))
3668 free_all_realized_faces (Qnil);
3670 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3671 if (NILP (new_value))
3673 if (NILP (old_value))
3674 error ("No font backend available");
3675 font_update_drivers (f, old_value);
3676 error ("None of specified font backends are available");
3678 store_frame_param (f, Qfont_backend, new_value);
3680 if (FRAME_FONT (f))
3682 Lisp_Object frame;
3684 XSETFRAME (frame, f);
3685 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3686 face_change = true;
3687 windows_or_buffers_changed = 18;
3691 void
3692 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3694 int unit = FRAME_COLUMN_WIDTH (f);
3695 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3696 int new_width;
3698 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3699 ? eabs (XINT (new_value)) : 8);
3701 if (new_width != old_width)
3703 FRAME_LEFT_FRINGE_WIDTH (f) = new_width;
3704 FRAME_FRINGE_COLS (f) /* Round up. */
3705 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3707 if (FRAME_X_WINDOW (f) != 0)
3708 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
3710 SET_FRAME_GARBAGED (f);
3715 void
3716 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3718 int unit = FRAME_COLUMN_WIDTH (f);
3719 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3720 int new_width;
3722 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3723 ? eabs (XINT (new_value)) : 8);
3725 if (new_width != old_width)
3727 FRAME_RIGHT_FRINGE_WIDTH (f) = new_width;
3728 FRAME_FRINGE_COLS (f) /* Round up. */
3729 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3731 if (FRAME_X_WINDOW (f) != 0)
3732 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
3734 SET_FRAME_GARBAGED (f);
3739 void
3740 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3742 CHECK_TYPE_RANGED_INTEGER (int, arg);
3744 if (XINT (arg) == f->border_width)
3745 return;
3747 if (FRAME_X_WINDOW (f) != 0)
3748 error ("Cannot change the border width of a frame");
3750 f->border_width = XINT (arg);
3753 void
3754 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3756 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3758 CHECK_TYPE_RANGED_INTEGER (int, arg);
3759 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3760 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3761 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3762 if (FRAME_RIGHT_DIVIDER_WIDTH (f) != old)
3764 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
3765 adjust_frame_glyphs (f);
3766 SET_FRAME_GARBAGED (f);
3771 void
3772 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3774 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3776 CHECK_TYPE_RANGED_INTEGER (int, arg);
3777 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3778 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3779 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3780 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) != old)
3782 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
3783 adjust_frame_glyphs (f);
3784 SET_FRAME_GARBAGED (f);
3788 void
3789 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3791 Lisp_Object frame;
3792 XSETFRAME (frame, f);
3794 if (NILP (value))
3795 Fmake_frame_invisible (frame, Qt);
3796 else if (EQ (value, Qicon))
3797 Ficonify_frame (frame);
3798 else
3799 Fmake_frame_visible (frame);
3802 void
3803 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3805 f->auto_raise = !EQ (Qnil, arg);
3808 void
3809 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3811 f->auto_lower = !EQ (Qnil, arg);
3814 void
3815 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3817 f->no_split = !NILP (arg);
3820 void
3821 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3823 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3824 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3825 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3826 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3828 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3829 = (NILP (arg)
3830 ? vertical_scroll_bar_none
3831 : EQ (Qleft, arg)
3832 ? vertical_scroll_bar_left
3833 : EQ (Qright, arg)
3834 ? vertical_scroll_bar_right
3835 : EQ (Qleft, Vdefault_frame_scroll_bars)
3836 ? vertical_scroll_bar_left
3837 : EQ (Qright, Vdefault_frame_scroll_bars)
3838 ? vertical_scroll_bar_right
3839 : vertical_scroll_bar_none);
3841 /* We set this parameter before creating the X window for the
3842 frame, so we can get the geometry right from the start.
3843 However, if the window hasn't been created yet, we shouldn't
3844 call x_set_window_size. */
3845 if (FRAME_X_WINDOW (f))
3846 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
3848 SET_FRAME_GARBAGED (f);
3852 void
3853 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3855 #if USE_HORIZONTAL_SCROLL_BARS
3856 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3857 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3859 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3861 /* We set this parameter before creating the X window for the
3862 frame, so we can get the geometry right from the start.
3863 However, if the window hasn't been created yet, we shouldn't
3864 call x_set_window_size. */
3865 if (FRAME_X_WINDOW (f))
3866 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
3868 SET_FRAME_GARBAGED (f);
3870 #endif
3873 void
3874 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3876 int unit = FRAME_COLUMN_WIDTH (f);
3878 if (NILP (arg))
3880 x_set_scroll_bar_default_width (f);
3882 if (FRAME_X_WINDOW (f))
3883 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3885 SET_FRAME_GARBAGED (f);
3887 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3888 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3890 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3891 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3892 if (FRAME_X_WINDOW (f))
3893 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3895 SET_FRAME_GARBAGED (f);
3898 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3899 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3902 void
3903 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3905 #if USE_HORIZONTAL_SCROLL_BARS
3906 int unit = FRAME_LINE_HEIGHT (f);
3908 if (NILP (arg))
3910 x_set_scroll_bar_default_height (f);
3912 if (FRAME_X_WINDOW (f))
3913 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3915 SET_FRAME_GARBAGED (f);
3917 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3918 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3920 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3921 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3922 if (FRAME_X_WINDOW (f))
3923 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3925 SET_FRAME_GARBAGED (f);
3928 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3929 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3930 #endif
3933 void
3934 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3936 double alpha = 1.0;
3937 double newval[2];
3938 int i;
3939 Lisp_Object item;
3941 for (i = 0; i < 2; i++)
3943 newval[i] = 1.0;
3944 if (CONSP (arg))
3946 item = CAR (arg);
3947 arg = CDR (arg);
3949 else
3950 item = arg;
3952 if (NILP (item))
3953 alpha = - 1.0;
3954 else if (FLOATP (item))
3956 alpha = XFLOAT_DATA (item);
3957 if (! (0 <= alpha && alpha <= 1.0))
3958 args_out_of_range (make_float (0.0), make_float (1.0));
3960 else if (INTEGERP (item))
3962 EMACS_INT ialpha = XINT (item);
3963 if (! (0 <= ialpha && alpha <= 100))
3964 args_out_of_range (make_number (0), make_number (100));
3965 alpha = ialpha / 100.0;
3967 else
3968 wrong_type_argument (Qnumberp, item);
3969 newval[i] = alpha;
3972 for (i = 0; i < 2; i++)
3973 f->alpha[i] = newval[i];
3975 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3976 block_input ();
3977 x_set_frame_alpha (f);
3978 unblock_input ();
3979 #endif
3981 return;
3984 #ifndef HAVE_NS
3986 /* Non-zero if mouse is grabbed on DPYINFO
3987 and we know the frame where it is. */
3989 bool x_mouse_grabbed (Display_Info *dpyinfo)
3991 return (dpyinfo->grabbed
3992 && dpyinfo->last_mouse_frame
3993 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
3996 /* Re-highlight something with mouse-face properties
3997 on DPYINFO using saved frame and mouse position. */
3999 void
4000 x_redo_mouse_highlight (Display_Info *dpyinfo)
4002 if (dpyinfo->last_mouse_motion_frame
4003 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4004 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4005 dpyinfo->last_mouse_motion_x,
4006 dpyinfo->last_mouse_motion_y);
4009 #endif /* HAVE_NS */
4011 /* Subroutines of creating an X frame. */
4013 /* Make sure that Vx_resource_name is set to a reasonable value.
4014 Fix it up, or set it to `emacs' if it is too hopeless. */
4016 void
4017 validate_x_resource_name (void)
4019 ptrdiff_t len = 0;
4020 /* Number of valid characters in the resource name. */
4021 ptrdiff_t good_count = 0;
4022 /* Number of invalid characters in the resource name. */
4023 ptrdiff_t bad_count = 0;
4024 Lisp_Object new;
4025 ptrdiff_t i;
4027 if (!STRINGP (Vx_resource_class))
4028 Vx_resource_class = build_string (EMACS_CLASS);
4030 if (STRINGP (Vx_resource_name))
4032 unsigned char *p = SDATA (Vx_resource_name);
4034 len = SBYTES (Vx_resource_name);
4036 /* Only letters, digits, - and _ are valid in resource names.
4037 Count the valid characters and count the invalid ones. */
4038 for (i = 0; i < len; i++)
4040 int c = p[i];
4041 if (! ((c >= 'a' && c <= 'z')
4042 || (c >= 'A' && c <= 'Z')
4043 || (c >= '0' && c <= '9')
4044 || c == '-' || c == '_'))
4045 bad_count++;
4046 else
4047 good_count++;
4050 else
4051 /* Not a string => completely invalid. */
4052 bad_count = 5, good_count = 0;
4054 /* If name is valid already, return. */
4055 if (bad_count == 0)
4056 return;
4058 /* If name is entirely invalid, or nearly so, or is so implausibly
4059 large that alloca might not work, use `emacs'. */
4060 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4062 Vx_resource_name = build_string ("emacs");
4063 return;
4066 /* Name is partly valid. Copy it and replace the invalid characters
4067 with underscores. */
4069 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4071 for (i = 0; i < len; i++)
4073 int c = SREF (new, i);
4074 if (! ((c >= 'a' && c <= 'z')
4075 || (c >= 'A' && c <= 'Z')
4076 || (c >= '0' && c <= '9')
4077 || c == '-' || c == '_'))
4078 SSET (new, i, '_');
4082 /* Get specified attribute from resource database RDB.
4083 See Fx_get_resource below for other parameters. */
4085 static Lisp_Object
4086 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4088 CHECK_STRING (attribute);
4089 CHECK_STRING (class);
4091 if (!NILP (component))
4092 CHECK_STRING (component);
4093 if (!NILP (subclass))
4094 CHECK_STRING (subclass);
4095 if (NILP (component) != NILP (subclass))
4096 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4098 validate_x_resource_name ();
4100 /* Allocate space for the components, the dots which separate them,
4101 and the final '\0'. Make them big enough for the worst case. */
4102 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4103 + (STRINGP (component)
4104 ? SBYTES (component) : 0)
4105 + SBYTES (attribute)
4106 + 3);
4108 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4109 + SBYTES (class)
4110 + (STRINGP (subclass)
4111 ? SBYTES (subclass) : 0)
4112 + 3);
4113 USE_SAFE_ALLOCA;
4114 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4115 char *class_key = name_key + name_keysize;
4117 /* Start with emacs.FRAMENAME for the name (the specific one)
4118 and with `Emacs' for the class key (the general one). */
4119 char *nz = lispstpcpy (name_key, Vx_resource_name);
4120 char *cz = lispstpcpy (class_key, Vx_resource_class);
4122 *cz++ = '.';
4123 cz = lispstpcpy (cz, class);
4125 if (!NILP (component))
4127 *cz++ = '.';
4128 lispstpcpy (cz, subclass);
4130 *nz++ = '.';
4131 nz = lispstpcpy (nz, component);
4134 *nz++ = '.';
4135 lispstpcpy (nz, attribute);
4137 char *value = x_get_string_resource (rdb, name_key, class_key);
4138 SAFE_FREE();
4140 if (value && *value)
4141 return build_string (value);
4142 else
4143 return Qnil;
4147 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4148 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4149 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4150 class, where INSTANCE is the name under which Emacs was invoked, or
4151 the name specified by the `-name' or `-rn' command-line arguments.
4153 The optional arguments COMPONENT and SUBCLASS add to the key and the
4154 class, respectively. You must specify both of them or neither.
4155 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4156 and the class is `Emacs.CLASS.SUBCLASS'. */)
4157 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4158 Lisp_Object subclass)
4160 check_window_system (NULL);
4162 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4163 attribute, class, component, subclass);
4166 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4168 Lisp_Object
4169 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4170 Lisp_Object class, Lisp_Object component,
4171 Lisp_Object subclass)
4173 return xrdb_get_resource (dpyinfo->xrdb,
4174 attribute, class, component, subclass);
4177 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
4178 /* Used when C code wants a resource value. */
4179 /* Called from oldXMenu/Create.c. */
4180 char *
4181 x_get_resource_string (const char *attribute, const char *class)
4183 char *result;
4184 struct frame *sf = SELECTED_FRAME ();
4185 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4186 USE_SAFE_ALLOCA;
4188 /* Allocate space for the components, the dots which separate them,
4189 and the final '\0'. */
4190 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4191 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4192 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4193 char *class_key = name_key + name_keysize;
4195 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4196 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4198 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4199 name_key, class_key);
4200 SAFE_FREE ();
4201 return result;
4203 #endif
4205 /* Return the value of parameter PARAM.
4207 First search ALIST, then Vdefault_frame_alist, then the X defaults
4208 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4210 Convert the resource to the type specified by desired_type.
4212 If no default is specified, return Qunbound. If you call
4213 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4214 and don't let it get stored in any Lisp-visible variables! */
4216 Lisp_Object
4217 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4218 const char *attribute, const char *class, enum resource_types type)
4220 Lisp_Object tem;
4222 tem = Fassq (param, alist);
4224 if (!NILP (tem))
4226 /* If we find this parm in ALIST, clear it out
4227 so that it won't be "left over" at the end. */
4228 Lisp_Object tail;
4229 XSETCAR (tem, Qnil);
4230 /* In case the parameter appears more than once in the alist,
4231 clear it out. */
4232 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4233 if (CONSP (XCAR (tail))
4234 && EQ (XCAR (XCAR (tail)), param))
4235 XSETCAR (XCAR (tail), Qnil);
4237 else
4238 tem = Fassq (param, Vdefault_frame_alist);
4240 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4241 look in the X resources. */
4242 if (EQ (tem, Qnil))
4244 if (attribute && dpyinfo)
4246 AUTO_STRING (at, attribute);
4247 AUTO_STRING (cl, class);
4248 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4250 if (NILP (tem))
4251 return Qunbound;
4253 switch (type)
4255 case RES_TYPE_NUMBER:
4256 return make_number (atoi (SSDATA (tem)));
4258 case RES_TYPE_BOOLEAN_NUMBER:
4259 if (!strcmp (SSDATA (tem), "on")
4260 || !strcmp (SSDATA (tem), "true"))
4261 return make_number (1);
4262 return make_number (atoi (SSDATA (tem)));
4263 break;
4265 case RES_TYPE_FLOAT:
4266 return make_float (atof (SSDATA (tem)));
4268 case RES_TYPE_BOOLEAN:
4269 tem = Fdowncase (tem);
4270 if (!strcmp (SSDATA (tem), "on")
4271 #ifdef HAVE_NS
4272 || !strcmp (SSDATA (tem), "yes")
4273 #endif
4274 || !strcmp (SSDATA (tem), "true"))
4275 return Qt;
4276 else
4277 return Qnil;
4279 case RES_TYPE_STRING:
4280 return tem;
4282 case RES_TYPE_SYMBOL:
4283 /* As a special case, we map the values `true' and `on'
4284 to Qt, and `false' and `off' to Qnil. */
4286 Lisp_Object lower;
4287 lower = Fdowncase (tem);
4288 if (!strcmp (SSDATA (lower), "on")
4289 #ifdef HAVE_NS
4290 || !strcmp (SSDATA (lower), "yes")
4291 #endif
4292 || !strcmp (SSDATA (lower), "true"))
4293 return Qt;
4294 else if (!strcmp (SSDATA (lower), "off")
4295 #ifdef HAVE_NS
4296 || !strcmp (SSDATA (lower), "no")
4297 #endif
4298 || !strcmp (SSDATA (lower), "false"))
4299 return Qnil;
4300 else
4301 return Fintern (tem, Qnil);
4304 default:
4305 emacs_abort ();
4308 else
4309 return Qunbound;
4311 return Fcdr (tem);
4314 static Lisp_Object
4315 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4316 const char *attribute, const char *class,
4317 enum resource_types type)
4319 return x_get_arg (FRAME_DISPLAY_INFO (f),
4320 alist, param, attribute, class, type);
4323 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4325 Lisp_Object
4326 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4327 Lisp_Object param,
4328 const char *attribute, const char *class,
4329 enum resource_types type)
4331 Lisp_Object value;
4333 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4334 attribute, class, type);
4335 if (! NILP (value) && ! EQ (value, Qunbound))
4336 store_frame_param (f, param, value);
4338 return value;
4342 /* Record in frame F the specified or default value according to ALIST
4343 of the parameter named PROP (a Lisp symbol).
4344 If no value is specified for PROP, look for an X default for XPROP
4345 on the frame named NAME.
4346 If that is not found either, use the value DEFLT. */
4348 Lisp_Object
4349 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4350 Lisp_Object deflt, const char *xprop, const char *xclass,
4351 enum resource_types type)
4353 Lisp_Object tem;
4355 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4356 if (EQ (tem, Qunbound))
4357 tem = deflt;
4358 AUTO_FRAME_ARG (arg, prop, tem);
4359 x_set_frame_parameters (f, arg);
4360 return tem;
4364 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4367 * XParseGeometry parses strings of the form
4368 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4369 * width, height, xoffset, and yoffset are unsigned integers.
4370 * Example: "=80x24+300-49"
4371 * The equal sign is optional.
4372 * It returns a bitmask that indicates which of the four values
4373 * were actually found in the string. For each value found,
4374 * the corresponding argument is updated; for each value
4375 * not found, the corresponding argument is left unchanged.
4378 static int
4379 XParseGeometry (char *string,
4380 int *x, int *y,
4381 unsigned int *width, unsigned int *height)
4383 int mask = NoValue;
4384 char *strind;
4385 unsigned long tempWidth, tempHeight;
4386 long int tempX, tempY;
4387 char *nextCharacter;
4389 if (string == NULL || *string == '\0')
4390 return mask;
4391 if (*string == '=')
4392 string++; /* ignore possible '=' at beg of geometry spec */
4394 strind = string;
4395 if (*strind != '+' && *strind != '-' && *strind != 'x')
4397 tempWidth = strtoul (strind, &nextCharacter, 10);
4398 if (strind == nextCharacter)
4399 return 0;
4400 strind = nextCharacter;
4401 mask |= WidthValue;
4404 if (*strind == 'x' || *strind == 'X')
4406 strind++;
4407 tempHeight = strtoul (strind, &nextCharacter, 10);
4408 if (strind == nextCharacter)
4409 return 0;
4410 strind = nextCharacter;
4411 mask |= HeightValue;
4414 if (*strind == '+' || *strind == '-')
4416 if (*strind == '-')
4417 mask |= XNegative;
4418 tempX = strtol (strind, &nextCharacter, 10);
4419 if (strind == nextCharacter)
4420 return 0;
4421 strind = nextCharacter;
4422 mask |= XValue;
4423 if (*strind == '+' || *strind == '-')
4425 if (*strind == '-')
4426 mask |= YNegative;
4427 tempY = strtol (strind, &nextCharacter, 10);
4428 if (strind == nextCharacter)
4429 return 0;
4430 strind = nextCharacter;
4431 mask |= YValue;
4435 /* If strind isn't at the end of the string then it's an invalid
4436 geometry specification. */
4438 if (*strind != '\0')
4439 return 0;
4441 if (mask & XValue)
4442 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4443 if (mask & YValue)
4444 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4445 if (mask & WidthValue)
4446 *width = min (tempWidth, UINT_MAX);
4447 if (mask & HeightValue)
4448 *height = min (tempHeight, UINT_MAX);
4449 return mask;
4452 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4455 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4456 make-docfile: the documentation string in ns-win.el was used for
4457 x-parse-geometry even in non-NS builds.
4459 With two definitions of x-parse-geometry in this file, various
4460 things still get confused (eg M-x apropos documentation), so that
4461 it is best if the two definitions just share the same doc-string.
4463 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4464 doc: /* Parse a display geometry string STRING.
4465 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4466 The properties returned may include `top', `left', `height', and `width'.
4467 For X, the value of `left' or `top' may be an integer,
4468 or a list (+ N) meaning N pixels relative to top/left corner,
4469 or a list (- N) meaning -N pixels relative to bottom/right corner.
4470 On Nextstep, this just calls `ns-parse-geometry'. */)
4471 (Lisp_Object string)
4473 int geometry, x, y;
4474 unsigned int width, height;
4475 Lisp_Object result;
4477 CHECK_STRING (string);
4479 #ifdef HAVE_NS
4480 if (strchr (SSDATA (string), ' ') != NULL)
4481 return call1 (Qns_parse_geometry, string);
4482 #endif
4483 geometry = XParseGeometry (SSDATA (string),
4484 &x, &y, &width, &height);
4485 result = Qnil;
4486 if (geometry & XValue)
4488 Lisp_Object element;
4490 if (x >= 0 && (geometry & XNegative))
4491 element = list3 (Qleft, Qminus, make_number (-x));
4492 else if (x < 0 && ! (geometry & XNegative))
4493 element = list3 (Qleft, Qplus, make_number (x));
4494 else
4495 element = Fcons (Qleft, make_number (x));
4496 result = Fcons (element, result);
4499 if (geometry & YValue)
4501 Lisp_Object element;
4503 if (y >= 0 && (geometry & YNegative))
4504 element = list3 (Qtop, Qminus, make_number (-y));
4505 else if (y < 0 && ! (geometry & YNegative))
4506 element = list3 (Qtop, Qplus, make_number (y));
4507 else
4508 element = Fcons (Qtop, make_number (y));
4509 result = Fcons (element, result);
4512 if (geometry & WidthValue)
4513 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4514 if (geometry & HeightValue)
4515 result = Fcons (Fcons (Qheight, make_number (height)), result);
4517 return result;
4521 /* Calculate the desired size and position of frame F.
4522 Return the flags saying which aspects were specified.
4524 Also set the win_gravity and size_hint_flags of F.
4526 Adjust height for toolbar if TOOLBAR_P is 1.
4528 This function does not make the coordinates positive. */
4530 #define DEFAULT_ROWS 35
4531 #define DEFAULT_COLS 80
4533 long
4534 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p)
4536 Lisp_Object height, width, user_size, top, left, user_position;
4537 long window_prompting = 0;
4538 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4540 /* Default values if we fall through.
4541 Actually, if that happens we should get
4542 window manager prompting. */
4543 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4544 SET_FRAME_COLS (f, DEFAULT_COLS);
4545 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4546 SET_FRAME_LINES (f, DEFAULT_ROWS);
4548 /* Window managers expect that if program-specified
4549 positions are not (0,0), they're intentional, not defaults. */
4550 f->top_pos = 0;
4551 f->left_pos = 0;
4553 /* Ensure that earlier new_width and new_height settings won't
4554 override what we specify below. */
4555 f->new_width = f->new_height = 0;
4557 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4558 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4559 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4561 if (!EQ (width, Qunbound))
4563 CHECK_NUMBER (width);
4564 if (! (0 <= XINT (width) && XINT (width) <= INT_MAX))
4565 xsignal1 (Qargs_out_of_range, width);
4567 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4570 if (!EQ (height, Qunbound))
4572 CHECK_NUMBER (height);
4573 if (! (0 <= XINT (height) && XINT (height) <= INT_MAX))
4574 xsignal1 (Qargs_out_of_range, height);
4576 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4579 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4580 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4581 window_prompting |= USSize;
4582 else
4583 window_prompting |= PSize;
4586 /* Add a tool bar height to the initial frame height so that the user
4587 gets a text display area of the size he specified with -g or via
4588 .Xdefaults. Later changes of the tool bar height don't change the
4589 frame size. This is done so that users can create tall Emacs
4590 frames without having to guess how tall the tool bar will get. */
4591 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4593 if (frame_default_tool_bar_height)
4594 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
4595 else
4597 int margin, relief;
4599 relief = (tool_bar_button_relief >= 0
4600 ? tool_bar_button_relief
4601 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4603 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4604 margin = XFASTINT (Vtool_bar_button_margin);
4605 else if (CONSP (Vtool_bar_button_margin)
4606 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4607 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4608 else
4609 margin = 0;
4611 FRAME_TOOL_BAR_HEIGHT (f)
4612 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4616 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4617 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4618 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4619 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4621 if (EQ (top, Qminus))
4623 f->top_pos = 0;
4624 window_prompting |= YNegative;
4626 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4627 && CONSP (XCDR (top))
4628 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4630 f->top_pos = - XINT (XCAR (XCDR (top)));
4631 window_prompting |= YNegative;
4633 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4634 && CONSP (XCDR (top))
4635 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4637 f->top_pos = XINT (XCAR (XCDR (top)));
4639 else if (EQ (top, Qunbound))
4640 f->top_pos = 0;
4641 else
4643 CHECK_TYPE_RANGED_INTEGER (int, top);
4644 f->top_pos = XINT (top);
4645 if (f->top_pos < 0)
4646 window_prompting |= YNegative;
4649 if (EQ (left, Qminus))
4651 f->left_pos = 0;
4652 window_prompting |= XNegative;
4654 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4655 && CONSP (XCDR (left))
4656 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4658 f->left_pos = - XINT (XCAR (XCDR (left)));
4659 window_prompting |= XNegative;
4661 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4662 && CONSP (XCDR (left))
4663 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4665 f->left_pos = XINT (XCAR (XCDR (left)));
4667 else if (EQ (left, Qunbound))
4668 f->left_pos = 0;
4669 else
4671 CHECK_TYPE_RANGED_INTEGER (int, left);
4672 f->left_pos = XINT (left);
4673 if (f->left_pos < 0)
4674 window_prompting |= XNegative;
4677 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4678 window_prompting |= USPosition;
4679 else
4680 window_prompting |= PPosition;
4683 if (window_prompting & XNegative)
4685 if (window_prompting & YNegative)
4686 f->win_gravity = SouthEastGravity;
4687 else
4688 f->win_gravity = NorthEastGravity;
4690 else
4692 if (window_prompting & YNegative)
4693 f->win_gravity = SouthWestGravity;
4694 else
4695 f->win_gravity = NorthWestGravity;
4698 f->size_hint_flags = window_prompting;
4700 return window_prompting;
4705 #endif /* HAVE_WINDOW_SYSTEM */
4707 void
4708 frame_make_pointer_invisible (struct frame *f)
4710 if (! NILP (Vmake_pointer_invisible))
4712 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4713 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4715 f->mouse_moved = 0;
4716 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4717 f->pointer_invisible = 1;
4722 void
4723 frame_make_pointer_visible (struct frame *f)
4725 /* We don't check Vmake_pointer_invisible here in case the
4726 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4727 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4728 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4730 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4731 f->pointer_invisible = 0;
4735 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4736 Sframe_pointer_visible_p, 0, 1, 0,
4737 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4738 Otherwise it returns nil. FRAME omitted or nil means the
4739 selected frame. This is useful when `make-pointer-invisible' is set. */)
4740 (Lisp_Object frame)
4742 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4747 /***********************************************************************
4748 Multimonitor data
4749 ***********************************************************************/
4751 #ifdef HAVE_WINDOW_SYSTEM
4753 # if (defined HAVE_NS \
4754 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4755 void
4756 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4758 int i;
4759 for (i = 0; i < n_monitors; ++i)
4760 xfree (monitors[i].name);
4761 xfree (monitors);
4763 # endif
4765 Lisp_Object
4766 make_monitor_attribute_list (struct MonitorInfo *monitors,
4767 int n_monitors,
4768 int primary_monitor,
4769 Lisp_Object monitor_frames,
4770 const char *source)
4772 Lisp_Object attributes_list = Qnil;
4773 Lisp_Object primary_monitor_attributes = Qnil;
4774 int i;
4776 for (i = 0; i < n_monitors; ++i)
4778 Lisp_Object geometry, workarea, attributes = Qnil;
4779 struct MonitorInfo *mi = &monitors[i];
4781 if (mi->geom.width == 0) continue;
4783 workarea = list4i (mi->work.x, mi->work.y,
4784 mi->work.width, mi->work.height);
4785 geometry = list4i (mi->geom.x, mi->geom.y,
4786 mi->geom.width, mi->geom.height);
4787 attributes = Fcons (Fcons (Qsource, build_string (source)),
4788 attributes);
4789 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4790 attributes);
4791 attributes = Fcons (Fcons (Qmm_size,
4792 list2i (mi->mm_width, mi->mm_height)),
4793 attributes);
4794 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4795 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4796 if (mi->name)
4797 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4798 strlen (mi->name))),
4799 attributes);
4801 if (i == primary_monitor)
4802 primary_monitor_attributes = attributes;
4803 else
4804 attributes_list = Fcons (attributes, attributes_list);
4807 if (!NILP (primary_monitor_attributes))
4808 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4809 return attributes_list;
4812 #endif /* HAVE_WINDOW_SYSTEM */
4815 /***********************************************************************
4816 Initialization
4817 ***********************************************************************/
4819 void
4820 syms_of_frame (void)
4822 DEFSYM (Qframep, "framep");
4823 DEFSYM (Qframe_live_p, "frame-live-p");
4824 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4825 DEFSYM (Qexplicit_name, "explicit-name");
4826 DEFSYM (Qheight, "height");
4827 DEFSYM (Qicon, "icon");
4828 DEFSYM (Qminibuffer, "minibuffer");
4829 DEFSYM (Qmodeline, "modeline");
4830 DEFSYM (Qonly, "only");
4831 DEFSYM (Qnone, "none");
4832 DEFSYM (Qwidth, "width");
4833 DEFSYM (Qgeometry, "geometry");
4834 DEFSYM (Qicon_left, "icon-left");
4835 DEFSYM (Qicon_top, "icon-top");
4836 DEFSYM (Qtooltip, "tooltip");
4837 DEFSYM (Quser_position, "user-position");
4838 DEFSYM (Quser_size, "user-size");
4839 DEFSYM (Qwindow_id, "window-id");
4840 #ifdef HAVE_X_WINDOWS
4841 DEFSYM (Qouter_window_id, "outer-window-id");
4842 #endif
4843 DEFSYM (Qparent_id, "parent-id");
4844 DEFSYM (Qx, "x");
4845 DEFSYM (Qw32, "w32");
4846 DEFSYM (Qpc, "pc");
4847 DEFSYM (Qns, "ns");
4848 DEFSYM (Qvisible, "visible");
4849 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4850 DEFSYM (Qbuffer_list, "buffer-list");
4851 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4852 DEFSYM (Qdisplay_type, "display-type");
4853 DEFSYM (Qbackground_mode, "background-mode");
4854 DEFSYM (Qnoelisp, "noelisp");
4855 DEFSYM (Qtty_color_mode, "tty-color-mode");
4856 DEFSYM (Qtty, "tty");
4857 DEFSYM (Qtty_type, "tty-type");
4859 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4861 DEFSYM (Qfullwidth, "fullwidth");
4862 DEFSYM (Qfullheight, "fullheight");
4863 DEFSYM (Qfullboth, "fullboth");
4864 DEFSYM (Qmaximized, "maximized");
4865 DEFSYM (Qx_resource_name, "x-resource-name");
4866 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4868 DEFSYM (Qterminal, "terminal");
4870 DEFSYM (Qworkarea, "workarea");
4871 DEFSYM (Qmm_size, "mm-size");
4872 DEFSYM (Qframes, "frames");
4873 DEFSYM (Qsource, "source");
4875 DEFSYM (Qframe_position, "frame-position");
4876 DEFSYM (Qframe_outer_size, "frame-outer-size");
4877 DEFSYM (Qexternal_border_size, "external-border-size");
4878 DEFSYM (Qtitle_height, "title-height");
4879 DEFSYM (Qmenu_bar_external, "menu-bar-external");
4880 DEFSYM (Qmenu_bar_size, "menu-bar-size");
4881 DEFSYM (Qtool_bar_external, "tool-bar-external");
4882 DEFSYM (Qtool_bar_size, "tool-bar-size");
4883 DEFSYM (Qframe_inner_size, "frame-inner-size");
4884 /* The following are used for frame_size_history. */
4885 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
4886 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
4887 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
4888 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
4889 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
4890 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
4891 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
4892 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
4893 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
4894 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
4895 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
4896 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
4897 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
4898 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
4899 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
4900 DEFSYM (Qtb_size_cb, "tb-size-cb");
4901 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
4902 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
4904 DEFSYM (Qchange_frame_size, "change-frame-size");
4905 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
4906 DEFSYM (Qset_window_configuration, "set-window-configuration");
4907 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
4908 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
4909 DEFSYM (Qtip_frame, "tip-frame");
4910 DEFSYM (Qterminal_frame, "terminal-frame");
4912 #ifdef HAVE_NS
4913 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4914 #endif
4916 DEFSYM (Qalpha, "alpha");
4917 DEFSYM (Qauto_lower, "auto-lower");
4918 DEFSYM (Qauto_raise, "auto-raise");
4919 DEFSYM (Qborder_color, "border-color");
4920 DEFSYM (Qborder_width, "border-width");
4921 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
4922 DEFSYM (Qcursor_color, "cursor-color");
4923 DEFSYM (Qcursor_type, "cursor-type");
4924 DEFSYM (Qfont_backend, "font-backend");
4925 DEFSYM (Qfullscreen, "fullscreen");
4926 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
4927 DEFSYM (Qicon_name, "icon-name");
4928 DEFSYM (Qicon_type, "icon-type");
4929 DEFSYM (Qinternal_border_width, "internal-border-width");
4930 DEFSYM (Qleft_fringe, "left-fringe");
4931 DEFSYM (Qline_spacing, "line-spacing");
4932 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
4933 DEFSYM (Qmouse_color, "mouse-color");
4934 DEFSYM (Qname, "name");
4935 DEFSYM (Qright_divider_width, "right-divider-width");
4936 DEFSYM (Qright_fringe, "right-fringe");
4937 DEFSYM (Qscreen_gamma, "screen-gamma");
4938 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
4939 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
4940 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
4941 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
4942 DEFSYM (Qsticky, "sticky");
4943 DEFSYM (Qtitle, "title");
4944 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
4945 DEFSYM (Qtool_bar_position, "tool-bar-position");
4946 DEFSYM (Qunsplittable, "unsplittable");
4947 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
4948 DEFSYM (Qvisibility, "visibility");
4949 DEFSYM (Qwait_for_wm, "wait-for-wm");
4952 int i;
4954 for (i = 0; i < ARRAYELTS (frame_parms); i++)
4956 Lisp_Object v = (frame_parms[i].sym < 0
4957 ? intern_c_string (frame_parms[i].name)
4958 : builtin_lisp_symbol (frame_parms[i].sym));
4959 Fput (v, Qx_frame_parameter, make_number (i));
4963 #ifdef HAVE_WINDOW_SYSTEM
4964 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4965 doc: /* The name Emacs uses to look up X resources.
4966 `x-get-resource' uses this as the first component of the instance name
4967 when requesting resource values.
4968 Emacs initially sets `x-resource-name' to the name under which Emacs
4969 was invoked, or to the value specified with the `-name' or `-rn'
4970 switches, if present.
4972 It may be useful to bind this variable locally around a call
4973 to `x-get-resource'. See also the variable `x-resource-class'. */);
4974 Vx_resource_name = Qnil;
4976 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4977 doc: /* The class Emacs uses to look up X resources.
4978 `x-get-resource' uses this as the first component of the instance class
4979 when requesting resource values.
4981 Emacs initially sets `x-resource-class' to "Emacs".
4983 Setting this variable permanently is not a reasonable thing to do,
4984 but binding this variable locally around a call to `x-get-resource'
4985 is a reasonable practice. See also the variable `x-resource-name'. */);
4986 Vx_resource_class = build_string (EMACS_CLASS);
4988 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4989 doc: /* The lower limit of the frame opacity (alpha transparency).
4990 The value should range from 0 (invisible) to 100 (completely opaque).
4991 You can also use a floating number between 0.0 and 1.0. */);
4992 Vframe_alpha_lower_limit = make_number (20);
4993 #endif
4995 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4996 doc: /* Alist of default values for frame creation.
4997 These may be set in your init file, like this:
4998 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4999 These override values given in window system configuration data,
5000 including X Windows' defaults database.
5001 For values specific to the first Emacs frame, see `initial-frame-alist'.
5002 For window-system specific values, see `window-system-default-frame-alist'.
5003 For values specific to the separate minibuffer frame, see
5004 `minibuffer-frame-alist'.
5005 The `menu-bar-lines' element of the list controls whether new frames
5006 have menu bars; `menu-bar-mode' works by altering this element.
5007 Setting this variable does not affect existing frames, only new ones. */);
5008 Vdefault_frame_alist = Qnil;
5010 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5011 doc: /* Default position of vertical scroll bars on this window-system. */);
5012 #ifdef HAVE_WINDOW_SYSTEM
5013 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5014 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
5015 default. */
5016 Vdefault_frame_scroll_bars = Qright;
5017 #else
5018 Vdefault_frame_scroll_bars = Qleft;
5019 #endif
5020 #else
5021 Vdefault_frame_scroll_bars = Qnil;
5022 #endif
5024 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5025 scroll_bar_adjust_thumb_portion_p,
5026 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5027 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5028 even if the end of the buffer is shown (i.e. overscrolling).
5029 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5030 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5031 is visible. In this case you can not overscroll. */);
5032 scroll_bar_adjust_thumb_portion_p = 1;
5034 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5035 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5037 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5038 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5039 `mouse-position' and `mouse-pixel-position' call this function, passing their
5040 usual return value as argument, and return whatever this function returns.
5041 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5042 which need to do mouse handling at the Lisp level. */);
5043 Vmouse_position_function = Qnil;
5045 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5046 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5047 If the value is an integer, highlighting is only shown after moving the
5048 mouse, while keyboard input turns off the highlight even when the mouse
5049 is over the clickable text. However, the mouse shape still indicates
5050 when the mouse is over clickable text. */);
5051 Vmouse_highlight = Qt;
5053 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5054 doc: /* If non-nil, make pointer invisible while typing.
5055 The pointer becomes visible again when the mouse is moved. */);
5056 Vmake_pointer_invisible = Qt;
5058 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5059 doc: /* Normal hook run when a frame gains input focus. */);
5060 Vfocus_in_hook = Qnil;
5061 DEFSYM (Qfocus_in_hook, "focus-in-hook");
5063 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5064 doc: /* Normal hook run when a frame loses input focus. */);
5065 Vfocus_out_hook = Qnil;
5066 DEFSYM (Qfocus_out_hook, "focus-out-hook");
5068 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5069 doc: /* Functions run before deleting a frame.
5070 The functions are run with one arg, the frame to be deleted.
5071 See `delete-frame'.
5073 Note that functions in this list may be called just before the frame is
5074 actually deleted, or some time later (or even both when an earlier function
5075 in `delete-frame-functions' (indirectly) calls `delete-frame'
5076 recursively). */);
5077 Vdelete_frame_functions = Qnil;
5078 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5080 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5081 doc: /* Non-nil if Menu-Bar mode is enabled.
5082 See the command `menu-bar-mode' for a description of this minor mode.
5083 Setting this variable directly does not take effect;
5084 either customize it (see the info node `Easy Customization')
5085 or call the function `menu-bar-mode'. */);
5086 Vmenu_bar_mode = Qt;
5088 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5089 doc: /* Non-nil if Tool-Bar mode is enabled.
5090 See the command `tool-bar-mode' for a description of this minor mode.
5091 Setting this variable directly does not take effect;
5092 either customize it (see the info node `Easy Customization')
5093 or call the function `tool-bar-mode'. */);
5094 #ifdef HAVE_WINDOW_SYSTEM
5095 Vtool_bar_mode = Qt;
5096 #else
5097 Vtool_bar_mode = Qnil;
5098 #endif
5100 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5101 doc: /* Minibufferless frames use this frame's minibuffer.
5102 Emacs cannot create minibufferless frames unless this is set to an
5103 appropriate surrogate.
5105 Emacs consults this variable only when creating minibufferless
5106 frames; once the frame is created, it sticks with its assigned
5107 minibuffer, no matter what this variable is set to. This means that
5108 this variable doesn't necessarily say anything meaningful about the
5109 current set of frames, or where the minibuffer is currently being
5110 displayed.
5112 This variable is local to the current terminal and cannot be buffer-local. */);
5114 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
5115 doc: /* Non-nil if window system changes focus when you move the mouse.
5116 You should set this variable to tell Emacs how your window manager
5117 handles focus, since there is no way in general for Emacs to find out
5118 automatically. See also `mouse-autoselect-window'. */);
5119 focus_follows_mouse = 0;
5121 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5122 doc: /* Non-nil means resize frames pixelwise.
5123 If this option is nil, resizing a frame rounds its sizes to the frame's
5124 current values of `frame-char-height' and `frame-char-width'. If this
5125 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5126 by one pixel.
5128 With some window managers you may have to set this to non-nil in order
5129 to set the size of a frame in pixels, to maximize frames or to make them
5130 fullscreen. To resize your initial frame pixelwise, set this option to
5131 a non-nil value in your init file. */);
5132 frame_resize_pixelwise = 0;
5134 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5135 doc: /* Whether frames should be resized implicitly.
5136 If this option is nil, setting font, menu bar, tool bar, internal
5137 borders, fringes or scroll bars of a specific frame may resize the frame
5138 in order to preserve the number of columns or lines it displays. If
5139 this option is `t', no such resizing is done. Note that the size of
5140 fullscreen and maximized frames, the height of fullheight frames and the
5141 width of fullwidth frames never change implicitly.
5143 The value of this option can be also be a list of frame parameters. In
5144 this case, resizing is inhibited when changing a parameter that appears
5145 in that list. The parameters currently handled by this option include
5146 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5147 `tool-bar-lines'.
5149 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5150 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5151 `right-fringe' is handled as if the frame contained just one live
5152 window. This means, for example, that removing vertical scroll bars on
5153 a frame containing several side by side windows will shrink the frame
5154 width by the width of one scroll bar provided this option is nil and
5155 keep it unchanged if this option is either `t' or a list containing
5156 `vertical-scroll-bars'.
5158 The default value is '(tool-bar-lines) on Lucid, Motif and Windows
5159 \(which means that adding/removing a tool bar does not change the frame
5160 height), nil on all other window systems including GTK+ (which means
5161 that changing any of the parameters listed above may change the size of
5162 the frame), and `t' otherwise (which means the frame size never changes
5163 implicitly when there's no window system support).
5165 Note that when a frame is not large enough to accommodate a change of
5166 any of the parameters listed above, Emacs may try to enlarge the frame
5167 even if this option is non-nil. */);
5168 #if defined (HAVE_WINDOW_SYSTEM)
5169 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
5170 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
5171 #else
5172 frame_inhibit_implied_resize = Qnil;
5173 #endif
5174 #else
5175 frame_inhibit_implied_resize = Qt;
5176 #endif
5178 DEFVAR_LISP ("frame-size-history", frame_size_history,
5179 doc: /* History of frame size adjustments.
5180 If non-nil, list recording frame size adjustment. Adjustments are
5181 recorded only if the first element of this list is a positive number.
5182 Adding an adjustment decrements that number by one.
5184 The remaining elements are the adjustments. Each adjustment is a list
5185 of four elements `frame', `function', `sizes' and `more'. `frame' is
5186 the affected frame and `function' the invoking function. `sizes' is
5187 usually a list of four elements `old-width', `old-height', `new-width'
5188 and `new-height' representing the old and new sizes recorded/requested
5189 by `function'. `more' is a list with additional information.
5191 The function `frame--size-history' displays the value of this variable
5192 in a more readable form. */);
5193 frame_size_history = Qnil;
5195 staticpro (&Vframe_list);
5197 defsubr (&Sframep);
5198 defsubr (&Sframe_live_p);
5199 defsubr (&Swindow_system);
5200 defsubr (&Sframe_windows_min_size);
5201 defsubr (&Smake_terminal_frame);
5202 defsubr (&Shandle_switch_frame);
5203 defsubr (&Sselect_frame);
5204 defsubr (&Sselected_frame);
5205 defsubr (&Sframe_list);
5206 defsubr (&Snext_frame);
5207 defsubr (&Sprevious_frame);
5208 defsubr (&Slast_nonminibuf_frame);
5209 defsubr (&Sdelete_frame);
5210 defsubr (&Smouse_position);
5211 defsubr (&Smouse_pixel_position);
5212 defsubr (&Sset_mouse_position);
5213 defsubr (&Sset_mouse_pixel_position);
5214 #if 0
5215 defsubr (&Sframe_configuration);
5216 defsubr (&Srestore_frame_configuration);
5217 #endif
5218 defsubr (&Smake_frame_visible);
5219 defsubr (&Smake_frame_invisible);
5220 defsubr (&Siconify_frame);
5221 defsubr (&Sframe_visible_p);
5222 defsubr (&Svisible_frame_list);
5223 defsubr (&Sraise_frame);
5224 defsubr (&Slower_frame);
5225 defsubr (&Sx_focus_frame);
5226 defsubr (&Sframe_after_make_frame);
5227 defsubr (&Sredirect_frame_focus);
5228 defsubr (&Sframe_focus);
5229 defsubr (&Sframe_parameters);
5230 defsubr (&Sframe_parameter);
5231 defsubr (&Smodify_frame_parameters);
5232 defsubr (&Sframe_char_height);
5233 defsubr (&Sframe_char_width);
5234 defsubr (&Sframe_pixel_height);
5235 defsubr (&Sframe_pixel_width);
5236 defsubr (&Sframe_text_cols);
5237 defsubr (&Sframe_text_lines);
5238 defsubr (&Sframe_total_cols);
5239 defsubr (&Sframe_total_lines);
5240 defsubr (&Sframe_text_width);
5241 defsubr (&Sframe_text_height);
5242 defsubr (&Sscroll_bar_width);
5243 defsubr (&Sscroll_bar_height);
5244 defsubr (&Sfringe_width);
5245 defsubr (&Sborder_width);
5246 defsubr (&Sright_divider_width);
5247 defsubr (&Sbottom_divider_width);
5248 defsubr (&Stool_bar_pixel_width);
5249 defsubr (&Sset_frame_height);
5250 defsubr (&Sset_frame_width);
5251 defsubr (&Sset_frame_size);
5252 defsubr (&Sset_frame_position);
5253 defsubr (&Sframe_pointer_visible_p);
5255 #ifdef HAVE_WINDOW_SYSTEM
5256 defsubr (&Sx_get_resource);
5257 defsubr (&Sx_parse_geometry);
5258 #endif