Merge from origin/emacs-25
[emacs.git] / src / frame.c
blobf3a548cbce7ebc1dd5547af1eef02c8214cbea2e
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2016 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or (at
10 your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <limits.h>
27 #include <c-ctype.h>
29 #include "lisp.h"
31 #ifdef HAVE_WINDOW_SYSTEM
32 #include TERM_HEADER
33 #endif /* HAVE_WINDOW_SYSTEM */
35 #include "buffer.h"
36 /* These help us bind and responding to switch-frame events. */
37 #include "keyboard.h"
38 #include "frame.h"
39 #include "blockinput.h"
40 #include "termchar.h"
41 #include "termhooks.h"
42 #include "dispextern.h"
43 #include "window.h"
44 #ifdef HAVE_WINDOW_SYSTEM
45 #include "fontset.h"
46 #endif
47 #include "cm.h"
48 #ifdef MSDOS
49 #include "msdos.h"
50 #include "dosfns.h"
51 #endif
52 #ifdef USE_X_TOOLKIT
53 #include "widget.h"
54 #endif
56 /* The currently selected frame. */
58 Lisp_Object selected_frame;
60 /* A frame which is not just a mini-buffer, or NULL if there are no such
61 frames. This is usually the most recent such frame that was selected. */
63 static struct frame *last_nonminibuf_frame;
65 /* False means there are no visible garbaged frames. */
66 bool frame_garbaged;
68 /* The default tool bar height for future frames. */
69 #if defined USE_GTK || defined HAVE_NS
70 enum { frame_default_tool_bar_height = 0 };
71 #else
72 int frame_default_tool_bar_height;
73 #endif
75 #ifdef HAVE_WINDOW_SYSTEM
76 static void x_report_frame_params (struct frame *, Lisp_Object *);
77 #endif
79 /* These setters are used only in this file, so they can be private. */
80 static void
81 fset_buffer_predicate (struct frame *f, Lisp_Object val)
83 f->buffer_predicate = val;
85 static void
86 fset_minibuffer_window (struct frame *f, Lisp_Object val)
88 f->minibuffer_window = val;
91 struct frame *
92 decode_live_frame (register Lisp_Object frame)
94 if (NILP (frame))
95 frame = selected_frame;
96 CHECK_LIVE_FRAME (frame);
97 return XFRAME (frame);
100 struct frame *
101 decode_any_frame (register Lisp_Object frame)
103 if (NILP (frame))
104 frame = selected_frame;
105 CHECK_FRAME (frame);
106 return XFRAME (frame);
109 #ifdef HAVE_WINDOW_SYSTEM
110 bool
111 display_available (void)
113 return x_display_list != NULL;
115 #endif
117 struct frame *
118 decode_window_system_frame (Lisp_Object frame)
120 struct frame *f = decode_live_frame (frame);
121 check_window_system (f);
122 #ifdef HAVE_WINDOW_SYSTEM
123 return f;
124 #endif
127 void
128 check_window_system (struct frame *f)
130 #ifdef HAVE_WINDOW_SYSTEM
131 if (window_system_available (f))
132 return;
133 #endif
134 error (f ? "Window system frame should be used"
135 : "Window system is not in use or not initialized");
138 /* Return the value of frame parameter PROP in frame FRAME. */
140 Lisp_Object
141 get_frame_param (register struct frame *frame, Lisp_Object prop)
143 register Lisp_Object tem;
145 tem = Fassq (prop, frame->param_alist);
146 if (EQ (tem, Qnil))
147 return tem;
148 return Fcdr (tem);
152 void
153 frame_size_history_add (struct frame *f, Lisp_Object fun_symbol,
154 int width, int height, Lisp_Object rest)
156 Lisp_Object frame;
158 XSETFRAME (frame, f);
159 if (CONSP (frame_size_history)
160 && INTEGERP (XCAR (frame_size_history))
161 && 0 < XINT (XCAR (frame_size_history)))
162 frame_size_history =
163 Fcons (make_number (XINT (XCAR (frame_size_history)) - 1),
164 Fcons (list4
165 (frame, fun_symbol,
166 ((width > 0)
167 ? list4 (make_number (FRAME_TEXT_WIDTH (f)),
168 make_number (FRAME_TEXT_HEIGHT (f)),
169 make_number (width),
170 make_number (height))
171 : Qnil),
172 rest),
173 XCDR (frame_size_history)));
177 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
178 state of frame F would be affected by a vertical (horizontal if
179 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
180 parameter that is changed. */
181 bool
182 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
184 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
185 bool inhibit
186 = (f->after_make_frame
187 ? (EQ (frame_inhibit_implied_resize, Qt)
188 || (CONSP (frame_inhibit_implied_resize)
189 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))
190 || (horizontal
191 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight))
192 || (!horizontal
193 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth))
194 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
195 : ((horizontal && f->inhibit_horizontal_resize)
196 || (!horizontal && f->inhibit_vertical_resize)));
197 if (inhibit && !FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
198 frame_size_history_add
199 (f, Qframe_inhibit_resize, 0, 0,
200 list5 (horizontal ? Qt : Qnil, parameter,
201 f->after_make_frame ? Qt : Qnil,
202 frame_inhibit_implied_resize,
203 fullscreen));
205 return inhibit;
208 static void
209 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
211 int nlines;
212 int olines = FRAME_MENU_BAR_LINES (f);
214 /* Right now, menu bars don't work properly in minibuf-only frames;
215 most of the commands try to apply themselves to the minibuffer
216 frame itself, and get an error because you can't switch buffers
217 in or split the minibuffer window. */
218 if (FRAME_MINIBUF_ONLY_P (f))
219 return;
221 if (TYPE_RANGED_INTEGERP (int, value))
222 nlines = XINT (value);
223 else
224 nlines = 0;
226 if (nlines != olines)
228 windows_or_buffers_changed = 14;
229 FRAME_MENU_BAR_LINES (f) = nlines;
230 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
231 change_frame_size (f, FRAME_COLS (f),
232 FRAME_LINES (f) + olines - nlines,
233 0, 1, 0, 0);
237 Lisp_Object Vframe_list;
240 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
241 doc: /* Return non-nil if OBJECT is a frame.
242 Value is:
243 t for a termcap frame (a character-only terminal),
244 `x' for an Emacs frame that is really an X window,
245 `w32' for an Emacs frame that is a window on MS-Windows display,
246 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
247 `pc' for a direct-write MS-DOS frame.
248 See also `frame-live-p'. */)
249 (Lisp_Object object)
251 if (!FRAMEP (object))
252 return Qnil;
253 switch (XFRAME (object)->output_method)
255 case output_initial: /* The initial frame is like a termcap frame. */
256 case output_termcap:
257 return Qt;
258 case output_x_window:
259 return Qx;
260 case output_w32:
261 return Qw32;
262 case output_msdos_raw:
263 return Qpc;
264 case output_ns:
265 return Qns;
266 default:
267 emacs_abort ();
271 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
272 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
273 Value is nil if OBJECT is not a live frame. If object is a live
274 frame, the return value indicates what sort of terminal device it is
275 displayed on. See the documentation of `framep' for possible
276 return values. */)
277 (Lisp_Object object)
279 return ((FRAMEP (object)
280 && FRAME_LIVE_P (XFRAME (object)))
281 ? Fframep (object)
282 : Qnil);
285 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
286 doc: /* The name of the window system that FRAME is displaying through.
287 The value is a symbol:
288 nil for a termcap frame (a character-only terminal),
289 `x' for an Emacs frame that is really an X window,
290 `w32' for an Emacs frame that is a window on MS-Windows display,
291 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
292 `pc' for a direct-write MS-DOS frame.
294 FRAME defaults to the currently selected frame.
296 Use of this function as a predicate is deprecated. Instead,
297 use `display-graphic-p' or any of the other `display-*-p'
298 predicates which report frame's specific UI-related capabilities. */)
299 (Lisp_Object frame)
301 Lisp_Object type;
302 if (NILP (frame))
303 frame = selected_frame;
305 type = Fframep (frame);
307 if (NILP (type))
308 wrong_type_argument (Qframep, frame);
310 if (EQ (type, Qt))
311 return Qnil;
312 else
313 return type;
316 /* Placeholder used by temacs -nw before window.el is loaded. */
317 DEFUN ("frame-windows-min-size", Fframe_windows_min_size,
318 Sframe_windows_min_size, 4, 4, 0,
319 doc: /* */
320 attributes: const)
321 (Lisp_Object frame, Lisp_Object horizontal,
322 Lisp_Object ignore, Lisp_Object pixelwise)
324 return make_number (0);
327 static int
328 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal,
329 Lisp_Object ignore, Lisp_Object pixelwise)
331 return XINT (call4 (Qframe_windows_min_size, frame, horizontal,
332 ignore, pixelwise));
336 /* Make sure windows sizes of frame F are OK. new_width and new_height
337 are in pixels. A value of -1 means no change is requested for that
338 size (but the frame may still have to be resized to accommodate
339 windows with their minimum sizes). This can either issue a request
340 to resize the frame externally (via x_set_window_size), to resize the
341 frame internally (via resize_frame_windows) or do nothing at all.
343 The argument INHIBIT can assume the following values:
345 0 means to unconditionally call x_set_window_size even if sizes
346 apparently do not change. Fx_create_frame uses this to pass the
347 initial size to the window manager.
349 1 means to call x_set_window_size if the outer frame size really
350 changes. Fset_frame_size, Fset_frame_height, ... use this.
352 2 means to call x_set_window_size provided frame_inhibit_resize
353 allows it. The menu and tool bar code use this ("3" won't work
354 here in general because menu and tool bar are often not counted in
355 the frame's text height).
357 3 means call x_set_window_size if window minimum sizes must be
358 preserved or frame_inhibit_resize allows it. x_set_left_fringe,
359 x_set_scroll_bar_width, x_new_font ... use (or should use) this.
361 4 means call x_set_window_size only if window minimum sizes must be
362 preserved. x_set_right_divider_width, x_set_border_width and the
363 code responsible for wrapping the tool bar use this.
365 5 means to never call x_set_window_size. change_frame_size uses
366 this.
368 Note that even when x_set_window_size is not called, individual
369 windows may have to be resized (via `window--sanitize-window-sizes')
370 in order to support minimum size constraints.
372 PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the
373 symbol of the parameter changed (like `menu-bar-lines', `font', ...).
374 This is passed on to frame_inhibit_resize to let the latter decide on
375 a case-by-case basis whether the frame may be resized externally. */
376 void
377 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
378 bool pretend, Lisp_Object parameter)
380 int unit_width = FRAME_COLUMN_WIDTH (f);
381 int unit_height = FRAME_LINE_HEIGHT (f);
382 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
383 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
384 int old_cols = FRAME_COLS (f);
385 int old_lines = FRAME_LINES (f);
386 int new_pixel_width, new_pixel_height;
387 /* The following two values are calculated from the old frame pixel
388 sizes and any "new" settings for tool bar, menu bar and internal
389 borders. We do it this way to detect whether we have to call
390 x_set_window_size as consequence of the new settings. */
391 int windows_width = FRAME_WINDOWS_WIDTH (f);
392 int windows_height = FRAME_WINDOWS_HEIGHT (f);
393 int min_windows_width, min_windows_height;
394 /* These are a bit tedious, maybe we should use a macro. */
395 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
396 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
397 int old_windows_height
398 = (WINDOW_PIXEL_HEIGHT (r)
399 + ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
400 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
401 : 0));
402 int new_windows_width, new_windows_height;
403 int old_text_width = FRAME_TEXT_WIDTH (f);
404 int old_text_height = FRAME_TEXT_HEIGHT (f);
405 /* If a size is < 0 use the old value. */
406 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
407 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
408 int new_cols, new_lines;
409 bool inhibit_horizontal, inhibit_vertical;
410 Lisp_Object frame;
412 XSETFRAME (frame, f);
414 frame_size_history_add
415 (f, Qadjust_frame_size_1, new_text_width, new_text_height,
416 list2 (parameter, make_number (inhibit)));
418 /* The following two values are calculated from the old window body
419 sizes and any "new" settings for scroll bars, dividers, fringes and
420 margins (though the latter should have been processed already). */
421 min_windows_width
422 = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qt : Qnil, Qt);
423 min_windows_height
424 = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qt : Qnil, Qt);
426 if (inhibit >= 2 && inhibit <= 4)
427 /* When INHIBIT is in [2..4] inhibit if the "old" window sizes stay
428 within the limits and either resizing is inhibited or INHIBIT
429 equals 4. */
431 inhibit_horizontal = (windows_width >= min_windows_width
432 && (inhibit == 4
433 || frame_inhibit_resize (f, true, parameter)));
434 inhibit_vertical = (windows_height >= min_windows_height
435 && (inhibit == 4
436 || frame_inhibit_resize (f, false, parameter)));
438 else
439 /* Otherwise inhibit if INHIBIT equals 5. */
440 inhibit_horizontal = inhibit_vertical = inhibit == 5;
442 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
443 ? old_pixel_width
444 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
445 min_windows_width
446 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
447 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
448 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
449 new_cols = new_text_width / unit_width;
451 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
452 ? old_pixel_height
453 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
454 min_windows_height
455 + FRAME_TOP_MARGIN_HEIGHT (f)
456 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
457 new_windows_height = (new_pixel_height
458 - FRAME_TOP_MARGIN_HEIGHT (f)
459 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
460 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
461 new_lines = new_text_height / unit_height;
463 #ifdef HAVE_WINDOW_SYSTEM
464 if (FRAME_WINDOW_P (f)
465 && f->can_x_set_window_size
466 && ((!inhibit_horizontal
467 && (new_pixel_width != old_pixel_width
468 || inhibit == 0 || inhibit == 2))
469 || (!inhibit_vertical
470 && (new_pixel_height != old_pixel_height
471 || inhibit == 0 || inhibit == 2))))
472 /* We are either allowed to change the frame size or the minimum
473 sizes request such a change. Do not care for fixing minimum
474 sizes here, we do that eventually when we're called from
475 change_frame_size. */
477 /* Make sure we respect fullheight and fullwidth. */
478 if (inhibit_horizontal)
479 new_text_width = old_text_width;
480 else if (inhibit_vertical)
481 new_text_height = old_text_height;
483 frame_size_history_add
484 (f, Qadjust_frame_size_2, new_text_width, new_text_height,
485 list2 (inhibit_horizontal ? Qt : Qnil,
486 inhibit_vertical ? Qt : Qnil));
488 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
489 f->resized_p = true;
491 return;
493 #endif
495 if (new_text_width == old_text_width
496 && new_text_height == old_text_height
497 && new_windows_width == old_windows_width
498 && new_windows_height == old_windows_height
499 && new_pixel_width == old_pixel_width
500 && new_pixel_height == old_pixel_height
501 && new_cols == old_cols
502 && new_lines == old_lines)
503 /* No change. Sanitize window sizes and return. */
505 sanitize_window_sizes (Qt);
506 sanitize_window_sizes (Qnil);
508 return;
511 block_input ();
513 #ifdef MSDOS
514 /* We only can set screen dimensions to certain values supported by
515 our video hardware. Try to find the smallest size greater or
516 equal to the requested dimensions, while accounting for the fact
517 that the menu-bar lines are not counted in the frame height. */
518 int dos_new_lines = new_lines + FRAME_TOP_MARGIN (f);
519 dos_set_window_size (&dos_new_lines, &new_cols);
520 new_lines = dos_new_lines - FRAME_TOP_MARGIN (f);
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
541 else if (new_cols != old_cols)
542 call2 (Qwindow__pixel_to_total, frame, Qt);
544 if (new_windows_height != old_windows_height
545 /* When the top margin has changed we have to recalculate the top
546 edges of all windows. No such calculation is necessary for the
547 left edges. */
548 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
550 resize_frame_windows (f, new_windows_height, 0, 1);
552 /* MSDOS frames cannot PRETEND, as they change frame size by
553 manipulating video hardware. */
554 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
555 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
557 else if (new_lines != old_lines)
558 call2 (Qwindow__pixel_to_total, frame, Qnil);
560 frame_size_history_add
561 (f, Qadjust_frame_size_3, new_text_width, new_text_height,
562 list4 (make_number (old_pixel_width), make_number (old_pixel_height),
563 make_number (new_pixel_width), make_number (new_pixel_height)));
565 /* Assign new sizes. */
566 FRAME_TEXT_WIDTH (f) = new_text_width;
567 FRAME_TEXT_HEIGHT (f) = new_text_height;
568 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
569 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
570 SET_FRAME_COLS (f, new_cols);
571 SET_FRAME_LINES (f, new_lines);
574 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
575 int text_area_x, text_area_y, text_area_width, text_area_height;
577 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
578 &text_area_height);
579 if (w->cursor.x >= text_area_x + text_area_width)
580 w->cursor.hpos = w->cursor.x = 0;
581 if (w->cursor.y >= text_area_y + text_area_height)
582 w->cursor.vpos = w->cursor.y = 0;
585 /* Sanitize window sizes. */
586 sanitize_window_sizes (Qt);
587 sanitize_window_sizes (Qnil);
589 adjust_frame_glyphs (f);
590 calculate_costs (f);
591 SET_FRAME_GARBAGED (f);
593 /* A frame was "resized" if one of its pixelsizes changed, even if its
594 X window wasn't resized at all. */
595 f->resized_p = (new_pixel_width != old_pixel_width
596 || new_pixel_height != old_pixel_height);
598 unblock_input ();
601 /* Allocate basically initialized frame. */
603 static struct frame *
604 allocate_frame (void)
606 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
609 struct frame *
610 make_frame (bool mini_p)
612 Lisp_Object frame;
613 struct frame *f;
614 struct window *rw, *mw;
615 Lisp_Object root_window;
616 Lisp_Object mini_window;
618 f = allocate_frame ();
619 XSETFRAME (frame, f);
621 #ifdef USE_GTK
622 /* Initialize Lisp data. Note that allocate_frame initializes all
623 Lisp data to nil, so do it only for slots which should not be nil. */
624 fset_tool_bar_position (f, Qtop);
625 #endif
627 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
628 non-Lisp data, so do it only for slots which should not be zero.
629 To avoid subtle bugs and for the sake of readability, it's better to
630 initialize enum members explicitly even if their values are zero. */
631 f->wants_modeline = true;
632 f->redisplay = true;
633 f->garbaged = true;
634 f->can_x_set_window_size = false;
635 f->after_make_frame = false;
636 f->inhibit_horizontal_resize = false;
637 f->inhibit_vertical_resize = false;
638 f->tool_bar_redisplayed = false;
639 f->tool_bar_resized = false;
640 f->column_width = 1; /* !FRAME_WINDOW_P value. */
641 f->line_height = 1; /* !FRAME_WINDOW_P value. */
642 #ifdef HAVE_WINDOW_SYSTEM
643 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
644 f->horizontal_scroll_bars = false;
645 f->want_fullscreen = FULLSCREEN_NONE;
646 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
647 f->last_tool_bar_item = -1;
648 #endif
649 #endif
651 root_window = make_window ();
652 rw = XWINDOW (root_window);
653 if (mini_p)
655 mini_window = make_window ();
656 mw = XWINDOW (mini_window);
657 wset_next (rw, mini_window);
658 wset_prev (mw, root_window);
659 mw->mini = 1;
660 wset_frame (mw, frame);
661 fset_minibuffer_window (f, mini_window);
662 store_frame_param (f, Qminibuffer, Qt);
664 else
666 mini_window = Qnil;
667 wset_next (rw, Qnil);
668 fset_minibuffer_window (f, Qnil);
671 wset_frame (rw, frame);
673 /* 10 is arbitrary,
674 just so that there is "something there."
675 Correct size will be set up later with adjust_frame_size. */
677 SET_FRAME_COLS (f, 10);
678 SET_FRAME_LINES (f, 10);
679 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
680 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
682 rw->total_cols = 10;
683 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
684 rw->total_lines = mini_p ? 9 : 10;
685 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
687 if (mini_p)
689 mw->top_line = rw->total_lines;
690 mw->pixel_top = rw->pixel_height;
691 mw->total_cols = rw->total_cols;
692 mw->pixel_width = rw->pixel_width;
693 mw->total_lines = 1;
694 mw->pixel_height = FRAME_LINE_HEIGHT (f);
697 /* Choose a buffer for the frame's root window. */
699 Lisp_Object buf = Fcurrent_buffer ();
701 /* If current buffer is hidden, try to find another one. */
702 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
703 buf = other_buffer_safely (buf);
705 /* Use set_window_buffer, not Fset_window_buffer, and don't let
706 hooks be run by it. The reason is that the whole frame/window
707 arrangement is not yet fully initialized at this point. Windows
708 don't have the right size, glyph matrices aren't initialized
709 etc. Running Lisp functions at this point surely ends in a
710 SEGV. */
711 set_window_buffer (root_window, buf, 0, 0);
712 fset_buffer_list (f, list1 (buf));
715 if (mini_p)
717 set_window_buffer (mini_window,
718 (NILP (Vminibuffer_list)
719 ? get_minibuffer (0)
720 : Fcar (Vminibuffer_list)),
721 0, 0);
722 /* No horizontal scroll bars in minibuffers. */
723 wset_horizontal_scroll_bar (mw, Qnil);
726 fset_root_window (f, root_window);
727 fset_selected_window (f, root_window);
728 /* Make sure this window seems more recently used than
729 a newly-created, never-selected window. */
730 XWINDOW (f->selected_window)->use_time = ++window_select_count;
732 return f;
735 #ifdef HAVE_WINDOW_SYSTEM
736 /* Make a frame using a separate minibuffer window on another frame.
737 MINI_WINDOW is the minibuffer window to use. nil means use the
738 default (the global minibuffer). */
740 struct frame *
741 make_frame_without_minibuffer (Lisp_Object mini_window, KBOARD *kb,
742 Lisp_Object display)
744 struct frame *f;
746 if (!NILP (mini_window))
747 CHECK_LIVE_WINDOW (mini_window);
749 if (!NILP (mini_window)
750 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
751 error ("Frame and minibuffer must be on the same terminal");
753 /* Make a frame containing just a root window. */
754 f = make_frame (0);
756 if (NILP (mini_window))
758 /* Use default-minibuffer-frame if possible. */
759 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
760 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
762 Lisp_Object frame_dummy;
764 XSETFRAME (frame_dummy, f);
765 /* If there's no minibuffer frame to use, create one. */
766 kset_default_minibuffer_frame
767 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
770 mini_window
771 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
774 fset_minibuffer_window (f, mini_window);
775 store_frame_param (f, Qminibuffer, mini_window);
777 /* Make the chosen minibuffer window display the proper minibuffer,
778 unless it is already showing a minibuffer. */
779 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
780 /* Use set_window_buffer instead of Fset_window_buffer (see
781 discussion of bug#11984, bug#12025, bug#12026). */
782 set_window_buffer (mini_window,
783 (NILP (Vminibuffer_list)
784 ? get_minibuffer (0)
785 : Fcar (Vminibuffer_list)), 0, 0);
786 return f;
789 /* Make a frame containing only a minibuffer window. */
791 struct frame *
792 make_minibuffer_frame (void)
794 /* First make a frame containing just a root window, no minibuffer. */
796 register struct frame *f = make_frame (0);
797 register Lisp_Object mini_window;
798 register Lisp_Object frame;
800 XSETFRAME (frame, f);
802 f->auto_raise = 0;
803 f->auto_lower = 0;
804 f->no_split = 1;
805 f->wants_modeline = 0;
807 /* Now label the root window as also being the minibuffer.
808 Avoid infinite looping on the window chain by marking next pointer
809 as nil. */
811 mini_window = f->root_window;
812 fset_minibuffer_window (f, mini_window);
813 store_frame_param (f, Qminibuffer, Qonly);
814 XWINDOW (mini_window)->mini = 1;
815 wset_next (XWINDOW (mini_window), Qnil);
816 wset_prev (XWINDOW (mini_window), Qnil);
817 wset_frame (XWINDOW (mini_window), frame);
819 /* Put the proper buffer in that window. */
821 /* Use set_window_buffer instead of Fset_window_buffer (see
822 discussion of bug#11984, bug#12025, bug#12026). */
823 set_window_buffer (mini_window,
824 (NILP (Vminibuffer_list)
825 ? get_minibuffer (0)
826 : Fcar (Vminibuffer_list)), 0, 0);
827 return f;
829 #endif /* HAVE_WINDOW_SYSTEM */
831 /* Construct a frame that refers to a terminal. */
833 static printmax_t tty_frame_count;
835 struct frame *
836 make_initial_frame (void)
838 struct frame *f;
839 struct terminal *terminal;
840 Lisp_Object frame;
842 eassert (initial_kboard);
844 /* The first call must initialize Vframe_list. */
845 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
846 Vframe_list = Qnil;
848 terminal = init_initial_terminal ();
850 f = make_frame (1);
851 XSETFRAME (frame, f);
853 Vframe_list = Fcons (frame, Vframe_list);
855 tty_frame_count = 1;
856 fset_name (f, build_pure_c_string ("F1"));
858 SET_FRAME_VISIBLE (f, 1);
860 f->output_method = terminal->type;
861 f->terminal = terminal;
862 f->terminal->reference_count++;
863 f->output_data.nothing = 0;
865 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
866 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
868 #ifdef HAVE_WINDOW_SYSTEM
869 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
870 f->horizontal_scroll_bars = false;
871 #endif
873 /* The default value of menu-bar-mode is t. */
874 set_menu_bar_lines (f, make_number (1), Qnil);
876 /* Allocate glyph matrices. */
877 adjust_frame_glyphs (f);
879 if (!noninteractive)
880 init_frame_faces (f);
882 last_nonminibuf_frame = f;
884 f->can_x_set_window_size = true;
885 f->after_make_frame = true;
887 return f;
891 static struct frame *
892 make_terminal_frame (struct terminal *terminal)
894 register struct frame *f;
895 Lisp_Object frame;
896 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
898 if (!terminal->name)
899 error ("Terminal is not live, can't create new frames on it");
901 f = make_frame (1);
903 XSETFRAME (frame, f);
904 Vframe_list = Fcons (frame, Vframe_list);
906 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
908 SET_FRAME_VISIBLE (f, 1);
910 f->terminal = terminal;
911 f->terminal->reference_count++;
912 #ifdef MSDOS
913 f->output_data.tty->display_info = &the_only_display_info;
914 if (!inhibit_window_system
915 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
916 || XFRAME (selected_frame)->output_method == output_msdos_raw))
917 f->output_method = output_msdos_raw;
918 else
919 f->output_method = output_termcap;
920 #else /* not MSDOS */
921 f->output_method = output_termcap;
922 create_tty_output (f);
923 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
924 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
925 #endif /* not MSDOS */
927 #ifdef HAVE_WINDOW_SYSTEM
928 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
929 f->horizontal_scroll_bars = false;
930 #endif
932 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
933 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
934 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
935 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
937 /* Set the top frame to the newly created frame. */
938 if (FRAMEP (FRAME_TTY (f)->top_frame)
939 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
940 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
942 FRAME_TTY (f)->top_frame = frame;
944 if (!noninteractive)
945 init_frame_faces (f);
947 return f;
950 /* Get a suitable value for frame parameter PARAMETER for a newly
951 created frame, based on (1) the user-supplied frame parameter
952 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
954 static Lisp_Object
955 get_future_frame_param (Lisp_Object parameter,
956 Lisp_Object supplied_parms,
957 char *current_value)
959 Lisp_Object result;
961 result = Fassq (parameter, supplied_parms);
962 if (NILP (result))
963 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
964 if (NILP (result) && current_value != NULL)
965 result = build_string (current_value);
966 if (!NILP (result) && !STRINGP (result))
967 result = XCDR (result);
968 if (NILP (result) || !STRINGP (result))
969 result = Qnil;
971 return result;
974 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
975 1, 1, 0,
976 doc: /* Create an additional terminal frame, possibly on another terminal.
977 This function takes one argument, an alist specifying frame parameters.
979 You can create multiple frames on a single text terminal, but only one
980 of them (the selected terminal frame) is actually displayed.
982 In practice, generally you don't need to specify any parameters,
983 except when you want to create a new frame on another terminal.
984 In that case, the `tty' parameter specifies the device file to open,
985 and the `tty-type' parameter specifies the terminal type. Example:
987 (make-terminal-frame \\='((tty . "/dev/pts/5") (tty-type . "xterm")))
989 Note that changing the size of one terminal frame automatically
990 affects all frames on the same terminal device. */)
991 (Lisp_Object parms)
993 struct frame *f;
994 struct terminal *t = NULL;
995 Lisp_Object frame, tem;
996 struct frame *sf = SELECTED_FRAME ();
998 #ifdef MSDOS
999 if (sf->output_method != output_msdos_raw
1000 && sf->output_method != output_termcap)
1001 emacs_abort ();
1002 #else /* not MSDOS */
1004 #ifdef WINDOWSNT /* This should work now! */
1005 if (sf->output_method != output_termcap)
1006 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
1007 #endif
1008 #endif /* not MSDOS */
1011 Lisp_Object terminal;
1013 terminal = Fassq (Qterminal, parms);
1014 if (CONSP (terminal))
1016 terminal = XCDR (terminal);
1017 t = decode_live_terminal (terminal);
1019 #ifdef MSDOS
1020 if (t && t != the_only_display_info.terminal)
1021 /* msdos.c assumes a single tty_display_info object. */
1022 error ("Multiple terminals are not supported on this platform");
1023 if (!t)
1024 t = the_only_display_info.terminal;
1025 #endif
1028 if (!t)
1030 char *name = 0, *type = 0;
1031 Lisp_Object tty, tty_type;
1032 USE_SAFE_ALLOCA;
1034 tty = get_future_frame_param
1035 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1036 ? FRAME_TTY (XFRAME (selected_frame))->name
1037 : NULL));
1038 if (!NILP (tty))
1039 SAFE_ALLOCA_STRING (name, tty);
1041 tty_type = get_future_frame_param
1042 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1043 ? FRAME_TTY (XFRAME (selected_frame))->type
1044 : NULL));
1045 if (!NILP (tty_type))
1046 SAFE_ALLOCA_STRING (type, tty_type);
1048 t = init_tty (name, type, 0); /* Errors are not fatal. */
1049 SAFE_FREE ();
1052 f = make_terminal_frame (t);
1055 int width, height;
1056 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1057 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f),
1058 5, 0, Qterminal_frame);
1061 adjust_frame_glyphs (f);
1062 calculate_costs (f);
1063 XSETFRAME (frame, f);
1065 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1066 store_in_alist (&parms, Qtty,
1067 (t->display_info.tty->name
1068 ? build_string (t->display_info.tty->name)
1069 : Qnil));
1070 /* On terminal frames the `minibuffer' frame parameter is always
1071 virtually t. Avoid that a different value in parms causes
1072 complaints, see Bug#24758. */
1073 store_in_alist (&parms, Qminibuffer, Qt);
1074 Fmodify_frame_parameters (frame, parms);
1076 /* Make the frame face alist be frame-specific, so that each
1077 frame could change its face definitions independently. */
1078 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1079 /* Simple Fcopy_alist isn't enough, because we need the contents of
1080 the vectors which are the CDRs of associations in face_alist to
1081 be copied as well. */
1082 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1083 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1085 f->can_x_set_window_size = true;
1086 f->after_make_frame = true;
1088 return frame;
1092 /* Perform the switch to frame FRAME.
1094 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1095 FRAME1 as frame.
1097 If TRACK is non-zero and the frame that currently has the focus
1098 redirects its focus to the selected frame, redirect that focused
1099 frame's focus to FRAME instead.
1101 FOR_DELETION non-zero means that the selected frame is being
1102 deleted, which includes the possibility that the frame's terminal
1103 is dead.
1105 The value of NORECORD is passed as argument to Fselect_window. */
1107 Lisp_Object
1108 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1110 struct frame *sf = SELECTED_FRAME ();
1112 /* If FRAME is a switch-frame event, extract the frame we should
1113 switch to. */
1114 if (CONSP (frame)
1115 && EQ (XCAR (frame), Qswitch_frame)
1116 && CONSP (XCDR (frame)))
1117 frame = XCAR (XCDR (frame));
1119 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1120 a switch-frame event to arrive after a frame is no longer live,
1121 especially when deleting the initial frame during startup. */
1122 CHECK_FRAME (frame);
1123 if (! FRAME_LIVE_P (XFRAME (frame)))
1124 return Qnil;
1126 if (sf == XFRAME (frame))
1127 return frame;
1129 /* If a frame's focus has been redirected toward the currently
1130 selected frame, we should change the redirection to point to the
1131 newly selected frame. This means that if the focus is redirected
1132 from a minibufferless frame to a surrogate minibuffer frame, we
1133 can use `other-window' to switch between all the frames using
1134 that minibuffer frame, and the focus redirection will follow us
1135 around. */
1136 #if 0
1137 /* This is too greedy; it causes inappropriate focus redirection
1138 that's hard to get rid of. */
1139 if (track)
1141 Lisp_Object tail;
1143 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1145 Lisp_Object focus;
1147 if (!FRAMEP (XCAR (tail)))
1148 emacs_abort ();
1150 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1152 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1153 Fredirect_frame_focus (XCAR (tail), frame);
1156 #else /* ! 0 */
1157 /* Instead, apply it only to the frame we're pointing to. */
1158 #ifdef HAVE_WINDOW_SYSTEM
1159 if (track && FRAME_WINDOW_P (XFRAME (frame)))
1161 Lisp_Object focus, xfocus;
1163 xfocus = x_get_focus_frame (XFRAME (frame));
1164 if (FRAMEP (xfocus))
1166 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1167 if ((FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1168 /* Redirect frame focus also when FRAME has its minibuffer
1169 window on the selected frame (see Bug#24500). */
1170 || (NILP (focus)
1171 && EQ (FRAME_MINIBUF_WINDOW (XFRAME (frame)),
1172 sf->selected_window)))
1173 Fredirect_frame_focus (xfocus, frame);
1176 #endif /* HAVE_X_WINDOWS */
1177 #endif /* ! 0 */
1179 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1180 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1182 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
1184 struct frame *f = XFRAME (frame);
1185 struct tty_display_info *tty = FRAME_TTY (f);
1186 Lisp_Object top_frame = tty->top_frame;
1188 /* Don't mark the frame garbaged and/or obscured if we are
1189 switching to the frame that is already the top frame of that
1190 TTY. */
1191 if (!EQ (frame, top_frame))
1193 if (FRAMEP (top_frame))
1194 /* Mark previously displayed frame as now obscured. */
1195 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1196 SET_FRAME_VISIBLE (f, 1);
1197 /* If the new TTY frame changed dimensions, we need to
1198 resync term.c's idea of the frame size with the new
1199 frame's data. */
1200 if (FRAME_COLS (f) != FrameCols (tty))
1201 FrameCols (tty) = FRAME_COLS (f);
1202 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1203 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1205 tty->top_frame = frame;
1208 selected_frame = frame;
1209 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1210 last_nonminibuf_frame = XFRAME (selected_frame);
1212 Fselect_window (XFRAME (frame)->selected_window, norecord);
1214 /* We want to make sure that the next event generates a frame-switch
1215 event to the appropriate frame. This seems kludgy to me, but
1216 before you take it out, make sure that evaluating something like
1217 (select-window (frame-root-window (new-frame))) doesn't end up
1218 with your typing being interpreted in the new frame instead of
1219 the one you're actually typing in. */
1220 internal_last_event_frame = Qnil;
1222 return frame;
1225 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1226 doc: /* Select FRAME.
1227 Subsequent editing commands apply to its selected window.
1228 Optional argument NORECORD means to neither change the order of
1229 recently selected windows nor the buffer list.
1231 The selection of FRAME lasts until the next time the user does
1232 something to select a different frame, or until the next time
1233 this function is called. If you are using a window system, the
1234 previously selected frame may be restored as the selected frame
1235 when returning to the command loop, because it still may have
1236 the window system's input focus. On a text terminal, the next
1237 redisplay will display FRAME.
1239 This function returns FRAME, or nil if FRAME has been deleted. */)
1240 (Lisp_Object frame, Lisp_Object norecord)
1242 return do_switch_frame (frame, 1, 0, norecord);
1245 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1246 doc: /* Handle a switch-frame event EVENT.
1247 Switch-frame events are usually bound to this function.
1248 A switch-frame event tells Emacs that the window manager has requested
1249 that the user's events be directed to the frame mentioned in the event.
1250 This function selects the selected window of the frame of EVENT.
1252 If EVENT is frame object, handle it as if it were a switch-frame event
1253 to that frame. */)
1254 (Lisp_Object event)
1256 /* Preserve prefix arg that the command loop just cleared. */
1257 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1258 run_hook (Qmouse_leave_buffer_hook);
1259 /* `switch-frame' implies a focus in. */
1260 call1 (intern ("handle-focus-in"), event);
1261 return do_switch_frame (event, 0, 0, Qnil);
1264 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1265 doc: /* Return the frame that is now selected. */)
1266 (void)
1268 return selected_frame;
1271 DEFUN ("frame-list", Fframe_list, Sframe_list,
1272 0, 0, 0,
1273 doc: /* Return a list of all live frames. */)
1274 (void)
1276 Lisp_Object frames;
1277 frames = Fcopy_sequence (Vframe_list);
1278 #ifdef HAVE_WINDOW_SYSTEM
1279 if (FRAMEP (tip_frame))
1280 frames = Fdelq (tip_frame, frames);
1281 #endif
1282 return frames;
1285 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1286 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1287 If MINIBUF is nil, do not consider minibuffer-only candidate.
1288 If MINIBUF is `visible', do not consider an invisible candidate.
1289 If MINIBUF is a window, consider only its own frame and candidate now
1290 using that window as the minibuffer.
1291 If MINIBUF is 0, consider candidate if it is visible or iconified.
1292 Otherwise consider any candidate and return nil if CANDIDATE is not
1293 acceptable. */
1295 static Lisp_Object
1296 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1298 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1300 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1301 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1302 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1303 && FRAME_TTY (c) == FRAME_TTY (f)))
1305 if (NILP (minibuf))
1307 if (!FRAME_MINIBUF_ONLY_P (c))
1308 return candidate;
1310 else if (EQ (minibuf, Qvisible))
1312 if (FRAME_VISIBLE_P (c))
1313 return candidate;
1315 else if (WINDOWP (minibuf))
1317 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1318 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1319 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1320 FRAME_FOCUS_FRAME (c)))
1321 return candidate;
1323 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1325 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1326 return candidate;
1328 else
1329 return candidate;
1331 return Qnil;
1334 /* Return the next frame in the frame list after FRAME. */
1336 static Lisp_Object
1337 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1339 Lisp_Object f, tail;
1340 int passed = 0;
1342 /* There must always be at least one frame in Vframe_list. */
1343 eassert (CONSP (Vframe_list));
1345 while (passed < 2)
1346 FOR_EACH_FRAME (tail, f)
1348 if (passed)
1350 f = candidate_frame (f, frame, minibuf);
1351 if (!NILP (f))
1352 return f;
1354 if (EQ (frame, f))
1355 passed++;
1357 return frame;
1360 /* Return the previous frame in the frame list before FRAME. */
1362 static Lisp_Object
1363 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1365 Lisp_Object f, tail, prev = Qnil;
1367 /* There must always be at least one frame in Vframe_list. */
1368 eassert (CONSP (Vframe_list));
1370 FOR_EACH_FRAME (tail, f)
1372 if (EQ (frame, f) && !NILP (prev))
1373 return prev;
1374 f = candidate_frame (f, frame, minibuf);
1375 if (!NILP (f))
1376 prev = f;
1379 /* We've scanned the entire list. */
1380 if (NILP (prev))
1381 /* We went through the whole frame list without finding a single
1382 acceptable frame. Return the original frame. */
1383 return frame;
1384 else
1385 /* There were no acceptable frames in the list before FRAME; otherwise,
1386 we would have returned directly from the loop. Since PREV is the last
1387 acceptable frame in the list, return it. */
1388 return prev;
1392 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1393 doc: /* Return the next frame in the frame list after FRAME.
1394 It considers only frames on the same terminal as FRAME.
1395 By default, skip minibuffer-only frames.
1396 If omitted, FRAME defaults to the selected frame.
1397 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1398 If MINIFRAME is a window, include only its own frame
1399 and any frame now using that window as the minibuffer.
1400 If MINIFRAME is `visible', include all visible frames.
1401 If MINIFRAME is 0, include all visible and iconified frames.
1402 Otherwise, include all frames. */)
1403 (Lisp_Object frame, Lisp_Object miniframe)
1405 if (NILP (frame))
1406 frame = selected_frame;
1407 CHECK_LIVE_FRAME (frame);
1408 return next_frame (frame, miniframe);
1411 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1412 doc: /* Return the previous frame in the frame list before FRAME.
1413 It considers only frames on the same terminal as FRAME.
1414 By default, skip minibuffer-only frames.
1415 If omitted, FRAME defaults to the selected frame.
1416 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1417 If MINIFRAME is a window, include only its own frame
1418 and any frame now using that window as the minibuffer.
1419 If MINIFRAME is `visible', include all visible frames.
1420 If MINIFRAME is 0, include all visible and iconified frames.
1421 Otherwise, include all frames. */)
1422 (Lisp_Object frame, Lisp_Object miniframe)
1424 if (NILP (frame))
1425 frame = selected_frame;
1426 CHECK_LIVE_FRAME (frame);
1427 return prev_frame (frame, miniframe);
1430 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1431 Slast_nonminibuf_frame, 0, 0, 0,
1432 doc: /* Return last non-minibuffer frame selected. */)
1433 (void)
1435 Lisp_Object frame = Qnil;
1437 if (last_nonminibuf_frame)
1438 XSETFRAME (frame, last_nonminibuf_frame);
1440 return frame;
1443 /* Return 1 if it is ok to delete frame F;
1444 0 if all frames aside from F are invisible.
1445 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1447 static int
1448 other_visible_frames (struct frame *f)
1450 Lisp_Object frames, this;
1452 FOR_EACH_FRAME (frames, this)
1454 if (f == XFRAME (this))
1455 continue;
1457 /* Verify that we can still talk to the frame's X window,
1458 and note any recent change in visibility. */
1459 #ifdef HAVE_X_WINDOWS
1460 if (FRAME_WINDOW_P (XFRAME (this)))
1461 x_sync (XFRAME (this));
1462 #endif
1464 if (FRAME_VISIBLE_P (XFRAME (this))
1465 || FRAME_ICONIFIED_P (XFRAME (this))
1466 /* Allow deleting the terminal frame when at least one X
1467 frame exists. */
1468 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1469 return 1;
1471 return 0;
1474 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1475 window. Preferably use the selected frame's minibuffer window
1476 instead. If the selected frame doesn't have one, get some other
1477 frame's minibuffer window. SELECT non-zero means select the new
1478 minibuffer window. */
1479 static void
1480 check_minibuf_window (Lisp_Object frame, int select)
1482 struct frame *f = decode_live_frame (frame);
1484 XSETFRAME (frame, f);
1486 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1488 Lisp_Object frames, this, window = make_number (0);
1490 if (!EQ (frame, selected_frame)
1491 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1492 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1493 else
1494 FOR_EACH_FRAME (frames, this)
1496 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1498 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1499 break;
1503 /* Don't abort if no window was found (Bug#15247). */
1504 if (WINDOWP (window))
1506 /* Use set_window_buffer instead of Fset_window_buffer (see
1507 discussion of bug#11984, bug#12025, bug#12026). */
1508 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1509 minibuf_window = window;
1511 /* SELECT non-zero usually means that FRAME's minibuffer
1512 window was selected; select the new one. */
1513 if (select)
1514 Fselect_window (minibuf_window, Qnil);
1520 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1521 unconditionally. x_connection_closed and delete_terminal use
1522 this. Any other value of FORCE implements the semantics
1523 described for Fdelete_frame. */
1524 Lisp_Object
1525 delete_frame (Lisp_Object frame, Lisp_Object force)
1527 struct frame *f = decode_any_frame (frame);
1528 struct frame *sf;
1529 struct kboard *kb;
1531 int minibuffer_selected, is_tooltip_frame;
1533 if (! FRAME_LIVE_P (f))
1534 return Qnil;
1536 if (NILP (force) && !other_visible_frames (f))
1537 error ("Attempt to delete the sole visible or iconified frame");
1539 /* x_connection_closed must have set FORCE to `noelisp' in order
1540 to delete the last frame, if it is gone. */
1541 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1542 error ("Attempt to delete the only frame");
1544 XSETFRAME (frame, f);
1546 /* Does this frame have a minibuffer, and is it the surrogate
1547 minibuffer for any other frame? */
1548 if (FRAME_HAS_MINIBUF_P (f))
1550 Lisp_Object frames, this;
1552 FOR_EACH_FRAME (frames, this)
1554 Lisp_Object fminiw;
1556 if (EQ (this, frame))
1557 continue;
1559 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1561 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1563 /* If we MUST delete this frame, delete the other first.
1564 But do this only if FORCE equals `noelisp'. */
1565 if (EQ (force, Qnoelisp))
1566 delete_frame (this, Qnoelisp);
1567 else
1568 error ("Attempt to delete a surrogate minibuffer frame");
1573 is_tooltip_frame = !NILP (Fframe_parameter (frame, Qtooltip));
1575 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1576 frame is a tooltip. FORCE is set to `noelisp' when handling
1577 a disconnect from the terminal, so we don't dare call Lisp
1578 code. */
1579 if (NILP (Vrun_hooks) || is_tooltip_frame)
1581 else if (EQ (force, Qnoelisp))
1582 pending_funcalls
1583 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1584 pending_funcalls);
1585 else
1587 #ifdef HAVE_X_WINDOWS
1588 /* Also, save clipboard to the clipboard manager. */
1589 x_clipboard_manager_save_frame (frame);
1590 #endif
1592 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1595 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1596 if (! FRAME_LIVE_P (f))
1597 return Qnil;
1599 /* At this point, we are committed to deleting the frame.
1600 There is no more chance for errors to prevent it. */
1602 minibuffer_selected = EQ (minibuf_window, selected_window);
1603 sf = SELECTED_FRAME ();
1604 /* Don't let the frame remain selected. */
1605 if (f == sf)
1607 Lisp_Object tail;
1608 Lisp_Object frame1 = Qnil;
1610 /* Look for another visible frame on the same terminal.
1611 Do not call next_frame here because it may loop forever.
1612 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1613 FOR_EACH_FRAME (tail, frame1)
1614 if (!EQ (frame, frame1)
1615 && (FRAME_TERMINAL (XFRAME (frame))
1616 == FRAME_TERMINAL (XFRAME (frame1)))
1617 && FRAME_VISIBLE_P (XFRAME (frame1)))
1618 break;
1620 /* If there is none, find *some* other frame. */
1621 if (NILP (frame1) || EQ (frame1, frame))
1623 FOR_EACH_FRAME (tail, frame1)
1625 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1627 /* Do not change a text terminal's top-frame. */
1628 struct frame *f1 = XFRAME (frame1);
1629 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1631 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1632 if (!EQ (top_frame, frame))
1633 frame1 = top_frame;
1635 break;
1639 #ifdef NS_IMPL_COCOA
1640 else
1641 /* Under NS, there is no system mechanism for choosing a new
1642 window to get focus -- it is left to application code.
1643 So the portion of THIS application interfacing with NS
1644 needs to know about it. We call Fraise_frame, but the
1645 purpose is really to transfer focus. */
1646 Fraise_frame (frame1);
1647 #endif
1649 do_switch_frame (frame1, 0, 1, Qnil);
1650 sf = SELECTED_FRAME ();
1653 /* Don't allow minibuf_window to remain on a deleted frame. */
1654 check_minibuf_window (frame, minibuffer_selected);
1656 /* Don't let echo_area_window to remain on a deleted frame. */
1657 if (EQ (f->minibuffer_window, echo_area_window))
1658 echo_area_window = sf->minibuffer_window;
1660 /* Clear any X selections for this frame. */
1661 #ifdef HAVE_X_WINDOWS
1662 if (FRAME_X_P (f))
1663 x_clear_frame_selections (f);
1664 #endif
1666 /* Free glyphs.
1667 This function must be called before the window tree of the
1668 frame is deleted because windows contain dynamically allocated
1669 memory. */
1670 free_glyphs (f);
1672 #ifdef HAVE_WINDOW_SYSTEM
1673 /* Give chance to each font driver to free a frame specific data. */
1674 font_update_drivers (f, Qnil);
1675 #endif
1677 /* Mark all the windows that used to be on FRAME as deleted, and then
1678 remove the reference to them. */
1679 delete_all_child_windows (f->root_window);
1680 fset_root_window (f, Qnil);
1682 Vframe_list = Fdelq (frame, Vframe_list);
1683 SET_FRAME_VISIBLE (f, 0);
1685 /* Allow the vector of menu bar contents to be freed in the next
1686 garbage collection. The frame object itself may not be garbage
1687 collected until much later, because recent_keys and other data
1688 structures can still refer to it. */
1689 fset_menu_bar_vector (f, Qnil);
1691 /* If FRAME's buffer lists contains killed
1692 buffers, this helps GC to reclaim them. */
1693 fset_buffer_list (f, Qnil);
1694 fset_buried_buffer_list (f, Qnil);
1696 free_font_driver_list (f);
1697 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1698 xfree (f->namebuf);
1699 #endif
1700 xfree (f->decode_mode_spec_buffer);
1701 xfree (FRAME_INSERT_COST (f));
1702 xfree (FRAME_DELETEN_COST (f));
1703 xfree (FRAME_INSERTN_COST (f));
1704 xfree (FRAME_DELETE_COST (f));
1706 /* Since some events are handled at the interrupt level, we may get
1707 an event for f at any time; if we zero out the frame's terminal
1708 now, then we may trip up the event-handling code. Instead, we'll
1709 promise that the terminal of the frame must be valid until we
1710 have called the window-system-dependent frame destruction
1711 routine. */
1715 struct terminal *terminal;
1716 block_input ();
1717 if (FRAME_TERMINAL (f)->delete_frame_hook)
1718 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1719 terminal = FRAME_TERMINAL (f);
1720 f->output_data.nothing = 0;
1721 f->terminal = 0; /* Now the frame is dead. */
1722 unblock_input ();
1724 /* If needed, delete the terminal that this frame was on.
1725 (This must be done after the frame is killed.) */
1726 terminal->reference_count--;
1727 #ifdef USE_GTK
1728 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1729 bug.
1730 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1731 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1732 terminal->reference_count = 1;
1733 #endif /* USE_GTK */
1734 if (terminal->reference_count == 0)
1736 Lisp_Object tmp;
1737 XSETTERMINAL (tmp, terminal);
1739 kb = NULL;
1740 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1742 else
1743 kb = terminal->kboard;
1746 /* If we've deleted the last_nonminibuf_frame, then try to find
1747 another one. */
1748 if (f == last_nonminibuf_frame)
1750 Lisp_Object frames, this;
1752 last_nonminibuf_frame = 0;
1754 FOR_EACH_FRAME (frames, this)
1756 f = XFRAME (this);
1757 if (!FRAME_MINIBUF_ONLY_P (f))
1759 last_nonminibuf_frame = f;
1760 break;
1765 /* If there's no other frame on the same kboard, get out of
1766 single-kboard state if we're in it for this kboard. */
1767 if (kb != NULL)
1769 Lisp_Object frames, this;
1770 /* Some frame we found on the same kboard, or nil if there are none. */
1771 Lisp_Object frame_on_same_kboard = Qnil;
1773 FOR_EACH_FRAME (frames, this)
1774 if (kb == FRAME_KBOARD (XFRAME (this)))
1775 frame_on_same_kboard = this;
1777 if (NILP (frame_on_same_kboard))
1778 not_single_kboard_state (kb);
1782 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1783 find another one. Prefer minibuffer-only frames, but also notice
1784 frames with other windows. */
1785 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1787 Lisp_Object frames, this;
1789 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1790 Lisp_Object frame_with_minibuf = Qnil;
1791 /* Some frame we found on the same kboard, or nil if there are none. */
1792 Lisp_Object frame_on_same_kboard = Qnil;
1794 FOR_EACH_FRAME (frames, this)
1796 struct frame *f1 = XFRAME (this);
1798 /* Consider only frames on the same kboard
1799 and only those with minibuffers. */
1800 if (kb == FRAME_KBOARD (f1)
1801 && FRAME_HAS_MINIBUF_P (f1))
1803 frame_with_minibuf = this;
1804 if (FRAME_MINIBUF_ONLY_P (f1))
1805 break;
1808 if (kb == FRAME_KBOARD (f1))
1809 frame_on_same_kboard = this;
1812 if (!NILP (frame_on_same_kboard))
1814 /* We know that there must be some frame with a minibuffer out
1815 there. If this were not true, all of the frames present
1816 would have to be minibufferless, which implies that at some
1817 point their minibuffer frames must have been deleted, but
1818 that is prohibited at the top; you can't delete surrogate
1819 minibuffer frames. */
1820 if (NILP (frame_with_minibuf))
1821 emacs_abort ();
1823 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1825 else
1826 /* No frames left on this kboard--say no minibuffer either. */
1827 kset_default_minibuffer_frame (kb, Qnil);
1830 /* Cause frame titles to update--necessary if we now have just one frame. */
1831 if (!is_tooltip_frame)
1832 update_mode_lines = 15;
1834 return Qnil;
1837 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1838 doc: /* Delete FRAME, permanently eliminating it from use.
1839 FRAME must be a live frame and defaults to the selected one.
1841 A frame may not be deleted if its minibuffer serves as surrogate
1842 minibuffer for another frame. Normally, you may not delete a frame if
1843 all other frames are invisible, but if the second optional argument
1844 FORCE is non-nil, you may do so.
1846 This function runs `delete-frame-functions' before actually
1847 deleting the frame, unless the frame is a tooltip.
1848 The functions are run with one argument, the frame to be deleted. */)
1849 (Lisp_Object frame, Lisp_Object force)
1851 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1855 /* Return mouse position in character cell units. */
1857 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1858 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1859 The position is given in canonical character cells, where (0, 0) is the
1860 upper-left corner of the frame, X is the horizontal offset, and Y is the
1861 vertical offset, measured in units of the frame's default character size.
1862 If Emacs is running on a mouseless terminal or hasn't been programmed
1863 to read the mouse position, it returns the selected frame for FRAME
1864 and nil for X and Y.
1865 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1866 passing the normal return value to that function as an argument,
1867 and returns whatever that function returns. */)
1868 (void)
1870 struct frame *f;
1871 Lisp_Object lispy_dummy;
1872 Lisp_Object x, y, retval;
1874 f = SELECTED_FRAME ();
1875 x = y = Qnil;
1877 /* It's okay for the hook to refrain from storing anything. */
1878 if (FRAME_TERMINAL (f)->mouse_position_hook)
1880 enum scroll_bar_part party_dummy;
1881 Time time_dummy;
1882 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1883 &lispy_dummy, &party_dummy,
1884 &x, &y,
1885 &time_dummy);
1888 if (! NILP (x))
1890 int col = XINT (x);
1891 int row = XINT (y);
1892 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1893 XSETINT (x, col);
1894 XSETINT (y, row);
1896 XSETFRAME (lispy_dummy, f);
1897 retval = Fcons (lispy_dummy, Fcons (x, y));
1898 if (!NILP (Vmouse_position_function))
1899 retval = call1 (Vmouse_position_function, retval);
1900 return retval;
1903 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1904 Smouse_pixel_position, 0, 0, 0,
1905 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1906 The position is given in pixel units, where (0, 0) is the
1907 upper-left corner of the frame, X is the horizontal offset, and Y is
1908 the vertical offset.
1909 If Emacs is running on a mouseless terminal or hasn't been programmed
1910 to read the mouse position, it returns the selected frame for FRAME
1911 and nil for X and Y. */)
1912 (void)
1914 struct frame *f;
1915 Lisp_Object lispy_dummy;
1916 Lisp_Object x, y, retval;
1918 f = SELECTED_FRAME ();
1919 x = y = Qnil;
1921 /* It's okay for the hook to refrain from storing anything. */
1922 if (FRAME_TERMINAL (f)->mouse_position_hook)
1924 enum scroll_bar_part party_dummy;
1925 Time time_dummy;
1926 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1927 &lispy_dummy, &party_dummy,
1928 &x, &y,
1929 &time_dummy);
1932 XSETFRAME (lispy_dummy, f);
1933 retval = Fcons (lispy_dummy, Fcons (x, y));
1934 if (!NILP (Vmouse_position_function))
1935 retval = call1 (Vmouse_position_function, retval);
1936 return retval;
1939 #ifdef HAVE_WINDOW_SYSTEM
1941 /* On frame F, convert character coordinates X and Y to pixel
1942 coordinates *PIX_X and *PIX_Y. */
1944 static void
1945 frame_char_to_pixel_position (struct frame *f, int x, int y,
1946 int *pix_x, int *pix_y)
1948 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
1949 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
1951 if (*pix_x < 0)
1952 *pix_x = 0;
1953 if (*pix_x > FRAME_PIXEL_WIDTH (f))
1954 *pix_x = FRAME_PIXEL_WIDTH (f);
1956 if (*pix_y < 0)
1957 *pix_y = 0;
1958 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
1959 *pix_y = FRAME_PIXEL_HEIGHT (f);
1962 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1964 static void
1965 frame_set_mouse_position (struct frame *f, int x, int y)
1967 int pix_x, pix_y;
1969 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
1970 frame_set_mouse_pixel_position (f, pix_x, pix_y);
1973 #endif /* HAVE_WINDOW_SYSTEM */
1975 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1976 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1977 Coordinates are relative to the frame, not a window,
1978 so the coordinates of the top left character in the frame
1979 may be nonzero due to left-hand scroll bars or the menu bar.
1981 The position is given in canonical character cells, where (0, 0) is
1982 the upper-left corner of the frame, X is the horizontal offset, and
1983 Y is the vertical offset, measured in units of the frame's default
1984 character size.
1986 This function is a no-op for an X frame that is not visible.
1987 If you have just created a frame, you must wait for it to become visible
1988 before calling this function on it, like this.
1989 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1990 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1992 CHECK_LIVE_FRAME (frame);
1993 CHECK_TYPE_RANGED_INTEGER (int, x);
1994 CHECK_TYPE_RANGED_INTEGER (int, y);
1996 /* I think this should be done with a hook. */
1997 #ifdef HAVE_WINDOW_SYSTEM
1998 if (FRAME_WINDOW_P (XFRAME (frame)))
1999 /* Warping the mouse will cause enternotify and focus events. */
2000 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
2001 #else
2002 #if defined (MSDOS)
2003 if (FRAME_MSDOS_P (XFRAME (frame)))
2005 Fselect_frame (frame, Qnil);
2006 mouse_moveto (XINT (x), XINT (y));
2008 #else
2009 #ifdef HAVE_GPM
2011 Fselect_frame (frame, Qnil);
2012 term_mouse_moveto (XINT (x), XINT (y));
2014 #endif
2015 #endif
2016 #endif
2018 return Qnil;
2021 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
2022 Sset_mouse_pixel_position, 3, 3, 0,
2023 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
2024 The position is given in pixels, where (0, 0) is the upper-left corner
2025 of the frame, X is the horizontal offset, and Y is the vertical offset.
2027 Note, this is a no-op for an X frame that is not visible.
2028 If you have just created a frame, you must wait for it to become visible
2029 before calling this function on it, like this.
2030 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2031 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2033 CHECK_LIVE_FRAME (frame);
2034 CHECK_TYPE_RANGED_INTEGER (int, x);
2035 CHECK_TYPE_RANGED_INTEGER (int, y);
2037 /* I think this should be done with a hook. */
2038 #ifdef HAVE_WINDOW_SYSTEM
2039 if (FRAME_WINDOW_P (XFRAME (frame)))
2040 /* Warping the mouse will cause enternotify and focus events. */
2041 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
2042 #else
2043 #if defined (MSDOS)
2044 if (FRAME_MSDOS_P (XFRAME (frame)))
2046 Fselect_frame (frame, Qnil);
2047 mouse_moveto (XINT (x), XINT (y));
2049 #else
2050 #ifdef HAVE_GPM
2052 Fselect_frame (frame, Qnil);
2053 term_mouse_moveto (XINT (x), XINT (y));
2055 #endif
2056 #endif
2057 #endif
2059 return Qnil;
2062 static void make_frame_visible_1 (Lisp_Object);
2064 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2065 0, 1, "",
2066 doc: /* Make the frame FRAME visible (assuming it is an X window).
2067 If omitted, FRAME defaults to the currently selected frame. */)
2068 (Lisp_Object frame)
2070 struct frame *f = decode_live_frame (frame);
2072 /* I think this should be done with a hook. */
2073 #ifdef HAVE_WINDOW_SYSTEM
2074 if (FRAME_WINDOW_P (f))
2075 x_make_frame_visible (f);
2076 #endif
2078 make_frame_visible_1 (f->root_window);
2080 /* Make menu bar update for the Buffers and Frames menus. */
2081 /* windows_or_buffers_changed = 15; FIXME: Why? */
2083 XSETFRAME (frame, f);
2084 return frame;
2087 /* Update the display_time slot of the buffers shown in WINDOW
2088 and all its descendants. */
2090 static void
2091 make_frame_visible_1 (Lisp_Object window)
2093 struct window *w;
2095 for (; !NILP (window); window = w->next)
2097 w = XWINDOW (window);
2098 if (WINDOWP (w->contents))
2099 make_frame_visible_1 (w->contents);
2100 else
2101 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2105 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2106 0, 2, "",
2107 doc: /* Make the frame FRAME invisible.
2108 If omitted, FRAME defaults to the currently selected frame.
2109 On graphical displays, invisible frames are not updated and are
2110 usually not displayed at all, even in a window system's \"taskbar\".
2112 Normally you may not make FRAME invisible if all other frames are invisible,
2113 but if the second optional argument FORCE is non-nil, you may do so.
2115 This function has no effect on text terminal frames. Such frames are
2116 always considered visible, whether or not they are currently being
2117 displayed in the terminal. */)
2118 (Lisp_Object frame, Lisp_Object force)
2120 struct frame *f = decode_live_frame (frame);
2122 if (NILP (force) && !other_visible_frames (f))
2123 error ("Attempt to make invisible the sole visible or iconified frame");
2125 /* Don't allow minibuf_window to remain on an invisible frame. */
2126 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2128 /* I think this should be done with a hook. */
2129 #ifdef HAVE_WINDOW_SYSTEM
2130 if (FRAME_WINDOW_P (f))
2131 x_make_frame_invisible (f);
2132 #endif
2134 /* Make menu bar update for the Buffers and Frames menus. */
2135 windows_or_buffers_changed = 16;
2137 return Qnil;
2140 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2141 0, 1, "",
2142 doc: /* Make the frame FRAME into an icon.
2143 If omitted, FRAME defaults to the currently selected frame. */)
2144 (Lisp_Object frame)
2146 struct frame *f = decode_live_frame (frame);
2148 /* Don't allow minibuf_window to remain on an iconified frame. */
2149 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2151 /* I think this should be done with a hook. */
2152 if (FRAME_WINDOW_P (f))
2154 #ifdef HAVE_WINDOW_SYSTEM
2155 x_iconify_frame (f);
2156 #endif
2159 /* Make menu bar update for the Buffers and Frames menus. */
2160 windows_or_buffers_changed = 17;
2162 return Qnil;
2165 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2166 1, 1, 0,
2167 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2168 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2169 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2170 On graphical displays, invisible frames are not updated and are
2171 usually not displayed at all, even in a window system's \"taskbar\".
2173 If FRAME is a text terminal frame, this always returns t.
2174 Such frames are always considered visible, whether or not they are
2175 currently being displayed on the terminal. */)
2176 (Lisp_Object frame)
2178 CHECK_LIVE_FRAME (frame);
2180 if (FRAME_VISIBLE_P (XFRAME (frame)))
2181 return Qt;
2182 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2183 return Qicon;
2184 return Qnil;
2187 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2188 0, 0, 0,
2189 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2190 (void)
2192 Lisp_Object tail, frame, value = Qnil;
2194 FOR_EACH_FRAME (tail, frame)
2195 if (FRAME_VISIBLE_P (XFRAME (frame)))
2196 value = Fcons (frame, value);
2198 return value;
2202 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2203 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2204 If FRAME is invisible or iconified, make it visible.
2205 If you don't specify a frame, the selected frame is used.
2206 If Emacs is displaying on an ordinary terminal or some other device which
2207 doesn't support multiple overlapping frames, this function selects FRAME. */)
2208 (Lisp_Object frame)
2210 struct frame *f = decode_live_frame (frame);
2212 XSETFRAME (frame, f);
2214 if (FRAME_TERMCAP_P (f))
2215 /* On a text terminal select FRAME. */
2216 Fselect_frame (frame, Qnil);
2217 else
2218 /* Do like the documentation says. */
2219 Fmake_frame_visible (frame);
2221 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2222 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2224 return Qnil;
2227 /* Should we have a corresponding function called Flower_Power? */
2228 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2229 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2230 If you don't specify a frame, the selected frame is used.
2231 If Emacs is displaying on an ordinary terminal or some other device which
2232 doesn't support multiple overlapping frames, this function does nothing. */)
2233 (Lisp_Object frame)
2235 struct frame *f = decode_live_frame (frame);
2237 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2238 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2240 return Qnil;
2244 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2245 1, 2, 0,
2246 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2247 In other words, switch-frame events caused by events in FRAME will
2248 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2249 FOCUS-FRAME after reading an event typed at FRAME.
2251 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2252 frame again receives its own keystrokes.
2254 Focus redirection is useful for temporarily redirecting keystrokes to
2255 a surrogate minibuffer frame when a frame doesn't have its own
2256 minibuffer window.
2258 A frame's focus redirection can be changed by `select-frame'. If frame
2259 FOO is selected, and then a different frame BAR is selected, any
2260 frames redirecting their focus to FOO are shifted to redirect their
2261 focus to BAR. This allows focus redirection to work properly when the
2262 user switches from one frame to another using `select-window'.
2264 This means that a frame whose focus is redirected to itself is treated
2265 differently from a frame whose focus is redirected to nil; the former
2266 is affected by `select-frame', while the latter is not.
2268 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2269 (Lisp_Object frame, Lisp_Object focus_frame)
2271 /* Note that we don't check for a live frame here. It's reasonable
2272 to redirect the focus of a frame you're about to delete, if you
2273 know what other frame should receive those keystrokes. */
2274 struct frame *f = decode_any_frame (frame);
2276 if (! NILP (focus_frame))
2277 CHECK_LIVE_FRAME (focus_frame);
2279 fset_focus_frame (f, focus_frame);
2281 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2282 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2284 return Qnil;
2288 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2289 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2290 If FRAME is omitted or nil, the selected frame is used.
2291 Return nil if FRAME's focus is not redirected.
2292 See `redirect-frame-focus'. */)
2293 (Lisp_Object frame)
2295 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2298 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2299 doc: /* Set the input focus to FRAME.
2300 FRAME nil means use the selected frame.
2301 If there is no window system support, this function does nothing. */)
2302 (Lisp_Object frame)
2304 #ifdef HAVE_WINDOW_SYSTEM
2305 x_focus_frame (decode_window_system_frame (frame));
2306 #endif
2307 return Qnil;
2310 DEFUN ("frame-after-make-frame",
2311 Fframe_after_make_frame,
2312 Sframe_after_make_frame, 2, 2, 0,
2313 doc: /* Mark FRAME as made.
2314 FRAME nil means use the selected frame. Second argument MADE non-nil
2315 means functions on `window-configuration-change-hook' are called
2316 whenever the window configuration of FRAME changes. MADE nil means
2317 these functions are not called.
2319 This function is currently called by `make-frame' only and should be
2320 otherwise used with utter care to avoid that running functions on
2321 `window-configuration-change-hook' is impeded forever. */)
2322 (Lisp_Object frame, Lisp_Object made)
2324 struct frame *f = decode_live_frame (frame);
2325 f->after_make_frame = !NILP (made);
2326 f->inhibit_horizontal_resize = false;
2327 f->inhibit_vertical_resize = false;
2328 return made;
2332 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2334 void
2335 frames_discard_buffer (Lisp_Object buffer)
2337 Lisp_Object frame, tail;
2339 FOR_EACH_FRAME (tail, frame)
2341 fset_buffer_list
2342 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2343 fset_buried_buffer_list
2344 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2348 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2349 If the alist already has an element for PROP, we change it. */
2351 void
2352 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2354 register Lisp_Object tem;
2356 tem = Fassq (prop, *alistptr);
2357 if (EQ (tem, Qnil))
2358 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2359 else
2360 Fsetcdr (tem, val);
2363 static int
2364 frame_name_fnn_p (char *str, ptrdiff_t len)
2366 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2368 char *p = str + 2;
2369 while ('0' <= *p && *p <= '9')
2370 p++;
2371 if (p == str + len)
2372 return 1;
2374 return 0;
2377 /* Set the name of the terminal frame. Also used by MSDOS frames.
2378 Modeled after x_set_name which is used for WINDOW frames. */
2380 static void
2381 set_term_frame_name (struct frame *f, Lisp_Object name)
2383 f->explicit_name = ! NILP (name);
2385 /* If NAME is nil, set the name to F<num>. */
2386 if (NILP (name))
2388 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2390 /* Check for no change needed in this very common case
2391 before we do any consing. */
2392 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2393 return;
2395 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2397 else
2399 CHECK_STRING (name);
2401 /* Don't change the name if it's already NAME. */
2402 if (! NILP (Fstring_equal (name, f->name)))
2403 return;
2405 /* Don't allow the user to set the frame name to F<num>, so it
2406 doesn't clash with the names we generate for terminal frames. */
2407 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2408 error ("Frame names of the form F<num> are usurped by Emacs");
2411 fset_name (f, name);
2412 update_mode_lines = 16;
2415 void
2416 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2418 register Lisp_Object old_alist_elt;
2420 if (EQ (prop, Qminibuffer))
2422 if (WINDOWP (val))
2424 if (!MINI_WINDOW_P (XWINDOW (val)))
2425 error ("The `minibuffer' parameter does not specify a valid minibuffer window");
2426 else if (FRAME_MINIBUF_ONLY_P (f))
2428 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2429 val = Qonly;
2430 else
2431 error ("Can't change the minibuffer window of a minibuffer-only frame");
2433 else if (FRAME_HAS_MINIBUF_P (f))
2435 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2436 val = Qt;
2437 else
2438 error ("Can't change the minibuffer window of a frame with its own minibuffer");
2440 else
2441 /* Store the chosen minibuffer window. */
2442 fset_minibuffer_window (f, val);
2444 else
2446 Lisp_Object old_val = Fcdr (Fassq (Qminibuffer, f->param_alist));
2448 if (!NILP (old_val))
2450 if (WINDOWP (old_val) && NILP (val))
2451 /* Don't change the value for a minibuffer-less frame if
2452 only nil was specified as new value. */
2453 val = old_val;
2454 else if (!EQ (old_val, val))
2455 error ("Can't change the `minibuffer' parameter of this frame");
2460 /* The buffer-list parameters are stored in a special place and not
2461 in the alist. All buffers must be live. */
2462 if (EQ (prop, Qbuffer_list))
2464 Lisp_Object list = Qnil;
2465 for (; CONSP (val); val = XCDR (val))
2466 if (!NILP (Fbuffer_live_p (XCAR (val))))
2467 list = Fcons (XCAR (val), list);
2468 fset_buffer_list (f, Fnreverse (list));
2469 return;
2471 if (EQ (prop, Qburied_buffer_list))
2473 Lisp_Object list = Qnil;
2474 for (; CONSP (val); val = XCDR (val))
2475 if (!NILP (Fbuffer_live_p (XCAR (val))))
2476 list = Fcons (XCAR (val), list);
2477 fset_buried_buffer_list (f, Fnreverse (list));
2478 return;
2481 /* If PROP is a symbol which is supposed to have frame-local values,
2482 and it is set up based on this frame, switch to the global
2483 binding. That way, we can create or alter the frame-local binding
2484 without messing up the symbol's status. */
2485 if (SYMBOLP (prop))
2487 struct Lisp_Symbol *sym = XSYMBOL (prop);
2488 start:
2489 switch (sym->redirect)
2491 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2492 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2493 case SYMBOL_LOCALIZED:
2494 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2495 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2496 swap_in_global_binding (sym);
2497 break;
2499 default: emacs_abort ();
2503 /* The tty color needed to be set before the frame's parameter
2504 alist was updated with the new value. This is not true any more,
2505 but we still do this test early on. */
2506 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2507 && f == FRAME_TTY (f)->previous_frame)
2508 /* Force redisplay of this tty. */
2509 FRAME_TTY (f)->previous_frame = NULL;
2511 /* Update the frame parameter alist. */
2512 old_alist_elt = Fassq (prop, f->param_alist);
2513 if (EQ (old_alist_elt, Qnil))
2514 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2515 else
2516 Fsetcdr (old_alist_elt, val);
2518 /* Update some other special parameters in their special places
2519 in addition to the alist. */
2521 if (EQ (prop, Qbuffer_predicate))
2522 fset_buffer_predicate (f, val);
2524 if (! FRAME_WINDOW_P (f))
2526 if (EQ (prop, Qmenu_bar_lines))
2527 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2528 else if (EQ (prop, Qname))
2529 set_term_frame_name (f, val);
2533 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2534 is not an unspecified foreground or background color. */
2536 static Lisp_Object
2537 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2539 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2540 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2541 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2542 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2545 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2546 doc: /* Return the parameters-alist of frame FRAME.
2547 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2548 The meaningful PARMs depend on the kind of frame.
2549 If FRAME is omitted or nil, return information on the currently selected frame. */)
2550 (Lisp_Object frame)
2552 Lisp_Object alist;
2553 struct frame *f = decode_any_frame (frame);
2554 int height, width;
2556 if (!FRAME_LIVE_P (f))
2557 return Qnil;
2559 alist = Fcopy_alist (f->param_alist);
2561 if (!FRAME_WINDOW_P (f))
2563 Lisp_Object elt;
2565 /* If the frame's parameter alist says the colors are
2566 unspecified and reversed, take the frame's background pixel
2567 for foreground and vice versa. */
2568 elt = Fassq (Qforeground_color, alist);
2569 if (CONSP (elt) && STRINGP (XCDR (elt)))
2571 elt = frame_unspecified_color (f, XCDR (elt));
2572 if (!NILP (elt))
2573 store_in_alist (&alist, Qforeground_color, elt);
2575 else
2576 store_in_alist (&alist, Qforeground_color,
2577 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2578 elt = Fassq (Qbackground_color, alist);
2579 if (CONSP (elt) && STRINGP (XCDR (elt)))
2581 elt = frame_unspecified_color (f, XCDR (elt));
2582 if (!NILP (elt))
2583 store_in_alist (&alist, Qbackground_color, elt);
2585 else
2586 store_in_alist (&alist, Qbackground_color,
2587 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2588 store_in_alist (&alist, Qfont,
2589 build_string (FRAME_MSDOS_P (f)
2590 ? "ms-dos"
2591 : FRAME_W32_P (f) ? "w32term"
2592 :"tty"));
2594 store_in_alist (&alist, Qname, f->name);
2595 height = (f->new_height
2596 ? (f->new_pixelwise
2597 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2598 : f->new_height)
2599 : FRAME_LINES (f));
2600 store_in_alist (&alist, Qheight, make_number (height));
2601 width = (f->new_width
2602 ? (f->new_pixelwise
2603 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2604 : f->new_width)
2605 : FRAME_COLS (f));
2606 store_in_alist (&alist, Qwidth, make_number (width));
2607 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2608 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2609 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2610 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2612 /* I think this should be done with a hook. */
2613 #ifdef HAVE_WINDOW_SYSTEM
2614 if (FRAME_WINDOW_P (f))
2615 x_report_frame_params (f, &alist);
2616 else
2617 #endif
2619 /* This ought to be correct in f->param_alist for an X frame. */
2620 Lisp_Object lines;
2621 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2622 store_in_alist (&alist, Qmenu_bar_lines, lines);
2625 return alist;
2629 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2630 doc: /* Return FRAME's value for parameter PARAMETER.
2631 If FRAME is nil, describe the currently selected frame. */)
2632 (Lisp_Object frame, Lisp_Object parameter)
2634 struct frame *f = decode_any_frame (frame);
2635 Lisp_Object value = Qnil;
2637 CHECK_SYMBOL (parameter);
2639 XSETFRAME (frame, f);
2641 if (FRAME_LIVE_P (f))
2643 /* Avoid consing in frequent cases. */
2644 if (EQ (parameter, Qname))
2645 value = f->name;
2646 #ifdef HAVE_WINDOW_SYSTEM
2647 /* These are used by vertical motion commands. */
2648 else if (EQ (parameter, Qvertical_scroll_bars))
2649 value = (f->vertical_scroll_bar_type == vertical_scroll_bar_none
2650 ? Qnil
2651 : (f->vertical_scroll_bar_type == vertical_scroll_bar_left
2652 ? Qleft : Qright));
2653 else if (EQ (parameter, Qhorizontal_scroll_bars))
2654 value = f->horizontal_scroll_bars ? Qt : Qnil;
2655 else if (EQ (parameter, Qline_spacing) && f->extra_line_spacing == 0)
2656 /* If this is non-zero, we can't determine whether the user specified
2657 an integer or float value without looking through 'param_alist'. */
2658 value = make_number (0);
2659 else if (EQ (parameter, Qfont) && FRAME_X_P (f))
2660 value = FRAME_FONT (f)->props[FONT_NAME_INDEX];
2661 #endif /* HAVE_WINDOW_SYSTEM */
2662 #ifdef HAVE_X_WINDOWS
2663 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2664 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2665 #endif /* HAVE_X_WINDOWS */
2666 else if (EQ (parameter, Qbackground_color)
2667 || EQ (parameter, Qforeground_color))
2669 value = Fassq (parameter, f->param_alist);
2670 if (CONSP (value))
2672 value = XCDR (value);
2673 /* Fframe_parameters puts the actual fg/bg color names,
2674 even if f->param_alist says otherwise. This is
2675 important when param_alist's notion of colors is
2676 "unspecified". We need to do the same here. */
2677 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2679 Lisp_Object tem = frame_unspecified_color (f, value);
2681 if (!NILP (tem))
2682 value = tem;
2685 else
2686 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2688 else if (EQ (parameter, Qdisplay_type)
2689 || EQ (parameter, Qbackground_mode))
2690 value = Fcdr (Fassq (parameter, f->param_alist));
2691 else
2692 /* FIXME: Avoid this code path at all (as well as code duplication)
2693 by sharing more code with Fframe_parameters. */
2694 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2697 return value;
2701 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2702 Smodify_frame_parameters, 2, 2, 0,
2703 doc: /* Modify FRAME according to new values of its parameters in ALIST.
2704 If FRAME is nil, it defaults to the selected frame.
2705 ALIST is an alist of parameters to change and their new values.
2706 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2707 Which PARMs are meaningful depends on the kind of frame.
2708 The meaningful parameters are acted upon, i.e. the frame is changed
2709 according to their new values, and are also stored in the frame's
2710 parameter list so that `frame-parameters' will return them.
2711 PARMs that are not meaningful are still stored in the frame's parameter
2712 list, but are otherwise ignored.
2714 The value of frame parameter FOO can also be accessed
2715 as a frame-local binding for the variable FOO, if you have
2716 enabled such bindings for that variable with `make-variable-frame-local'.
2717 Note that this functionality is obsolete as of Emacs 22.2, and its
2718 use is not recommended. Explicitly check for a frame-parameter instead. */)
2719 (Lisp_Object frame, Lisp_Object alist)
2721 struct frame *f = decode_live_frame (frame);
2722 register Lisp_Object prop, val;
2724 CHECK_LIST (alist);
2726 /* I think this should be done with a hook. */
2727 #ifdef HAVE_WINDOW_SYSTEM
2728 if (FRAME_WINDOW_P (f))
2729 x_set_frame_parameters (f, alist);
2730 else
2731 #endif
2732 #ifdef MSDOS
2733 if (FRAME_MSDOS_P (f))
2734 IT_set_frame_parameters (f, alist);
2735 else
2736 #endif
2739 EMACS_INT length = XFASTINT (Flength (alist));
2740 ptrdiff_t i;
2741 Lisp_Object *parms;
2742 Lisp_Object *values;
2743 USE_SAFE_ALLOCA;
2744 SAFE_ALLOCA_LISP (parms, 2 * length);
2745 values = parms + length;
2747 /* Extract parm names and values into those vectors. */
2749 for (i = 0; CONSP (alist); alist = XCDR (alist))
2751 Lisp_Object elt;
2753 elt = XCAR (alist);
2754 parms[i] = Fcar (elt);
2755 values[i] = Fcdr (elt);
2756 i++;
2759 /* Now process them in reverse of specified order. */
2760 while (--i >= 0)
2762 prop = parms[i];
2763 val = values[i];
2764 store_frame_param (f, prop, val);
2766 if (EQ (prop, Qforeground_color)
2767 || EQ (prop, Qbackground_color))
2768 update_face_from_frame_parameter (f, prop, val);
2771 SAFE_FREE ();
2773 return Qnil;
2776 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2777 0, 1, 0,
2778 doc: /* Height in pixels of a line in the font in frame FRAME.
2779 If FRAME is omitted or nil, the selected frame is used.
2780 For a terminal frame, the value is always 1. */)
2781 (Lisp_Object frame)
2783 #ifdef HAVE_WINDOW_SYSTEM
2784 struct frame *f = decode_any_frame (frame);
2786 if (FRAME_WINDOW_P (f))
2787 return make_number (FRAME_LINE_HEIGHT (f));
2788 else
2789 #endif
2790 return make_number (1);
2794 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2795 0, 1, 0,
2796 doc: /* Width in pixels of characters in the font in frame FRAME.
2797 If FRAME is omitted or nil, the selected frame is used.
2798 On a graphical screen, the width is the standard width of the default font.
2799 For a terminal screen, the value is always 1. */)
2800 (Lisp_Object frame)
2802 #ifdef HAVE_WINDOW_SYSTEM
2803 struct frame *f = decode_any_frame (frame);
2805 if (FRAME_WINDOW_P (f))
2806 return make_number (FRAME_COLUMN_WIDTH (f));
2807 else
2808 #endif
2809 return make_number (1);
2812 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2813 Sframe_pixel_height, 0, 1, 0,
2814 doc: /* Return a FRAME's height in pixels.
2815 If FRAME is omitted or nil, the selected frame is used. The exact value
2816 of the result depends on the window-system and toolkit in use:
2818 In the Gtk+ version of Emacs, it includes only any window (including
2819 the minibuffer or echo area), mode line, and header line. It does not
2820 include the tool bar or menu bar.
2822 With other graphical versions, it also includes the tool bar and the
2823 menu bar.
2825 For a text terminal, it includes the menu bar. In this case, the
2826 result is really in characters rather than pixels (i.e., is identical
2827 to `frame-height'). */)
2828 (Lisp_Object frame)
2830 struct frame *f = decode_any_frame (frame);
2832 #ifdef HAVE_WINDOW_SYSTEM
2833 if (FRAME_WINDOW_P (f))
2834 return make_number (FRAME_PIXEL_HEIGHT (f));
2835 else
2836 #endif
2837 return make_number (FRAME_TOTAL_LINES (f));
2840 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2841 Sframe_pixel_width, 0, 1, 0,
2842 doc: /* Return FRAME's width in pixels.
2843 For a terminal frame, the result really gives the width in characters.
2844 If FRAME is omitted or nil, the selected frame is used. */)
2845 (Lisp_Object frame)
2847 struct frame *f = decode_any_frame (frame);
2849 #ifdef HAVE_WINDOW_SYSTEM
2850 if (FRAME_WINDOW_P (f))
2851 return make_number (FRAME_PIXEL_WIDTH (f));
2852 else
2853 #endif
2854 return make_number (FRAME_TOTAL_COLS (f));
2857 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2858 Stool_bar_pixel_width, 0, 1, 0,
2859 doc: /* Return width in pixels of FRAME's tool bar.
2860 The result is greater than zero only when the tool bar is on the left
2861 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2862 is used. */)
2863 (Lisp_Object frame)
2865 #ifdef FRAME_TOOLBAR_WIDTH
2866 struct frame *f = decode_any_frame (frame);
2868 if (FRAME_WINDOW_P (f))
2869 return make_number (FRAME_TOOLBAR_WIDTH (f));
2870 #endif
2871 return make_number (0);
2874 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2875 doc: /* Return width in columns of FRAME's text area. */)
2876 (Lisp_Object frame)
2878 return make_number (FRAME_COLS (decode_any_frame (frame)));
2881 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2882 doc: /* Return height in lines of FRAME's text area. */)
2883 (Lisp_Object frame)
2885 return make_number (FRAME_LINES (decode_any_frame (frame)));
2888 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2889 doc: /* Return number of total columns of FRAME. */)
2890 (Lisp_Object frame)
2892 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2895 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2896 doc: /* Return number of total lines of FRAME. */)
2897 (Lisp_Object frame)
2899 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2902 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2903 doc: /* Return text area width of FRAME in pixels. */)
2904 (Lisp_Object frame)
2906 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2909 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2910 doc: /* Return text area height of FRAME in pixels. */)
2911 (Lisp_Object frame)
2913 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2916 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2917 doc: /* Return scroll bar width of FRAME in pixels. */)
2918 (Lisp_Object frame)
2920 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2923 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2924 doc: /* Return scroll bar height of FRAME in pixels. */)
2925 (Lisp_Object frame)
2927 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2930 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2931 doc: /* Return fringe width of FRAME in pixels. */)
2932 (Lisp_Object frame)
2934 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2937 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2938 doc: /* Return border width of FRAME in pixels. */)
2939 (Lisp_Object frame)
2941 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2944 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2945 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2946 (Lisp_Object frame)
2948 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2951 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2952 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2953 (Lisp_Object frame)
2955 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2958 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2959 doc: /* Set text height of frame FRAME to HEIGHT lines.
2960 Optional third arg PRETEND non-nil means that redisplay should use
2961 HEIGHT lines but that the idea of the actual height of the frame should
2962 not be changed.
2964 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2965 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
2966 window managers may refuse to honor a HEIGHT that is not an integer
2967 multiple of the default frame font height. */)
2968 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2970 struct frame *f = decode_live_frame (frame);
2971 int pixel_height;
2973 CHECK_TYPE_RANGED_INTEGER (int, height);
2975 pixel_height = (!NILP (pixelwise)
2976 ? XINT (height)
2977 : XINT (height) * FRAME_LINE_HEIGHT (f));
2978 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
2980 return Qnil;
2983 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2984 doc: /* Set text width of frame FRAME to WIDTH columns.
2985 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2986 columns but that the idea of the actual width of the frame should not
2987 be changed.
2989 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2990 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
2991 window managers may refuse to honor a WIDTH that is not an integer
2992 multiple of the default frame font width. */)
2993 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2995 struct frame *f = decode_live_frame (frame);
2996 int pixel_width;
2998 CHECK_TYPE_RANGED_INTEGER (int, width);
3000 pixel_width = (!NILP (pixelwise)
3001 ? XINT (width)
3002 : XINT (width) * FRAME_COLUMN_WIDTH (f));
3003 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
3005 return Qnil;
3008 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
3009 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
3010 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
3011 When `frame-resize-pixelwise' is nil, some window managers may refuse to
3012 honor a WIDTH that is not an integer multiple of the default frame font
3013 width or a HEIGHT that is not an integer multiple of the default frame
3014 font height. */)
3015 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
3017 struct frame *f = decode_live_frame (frame);
3018 int pixel_width, pixel_height;
3020 CHECK_TYPE_RANGED_INTEGER (int, width);
3021 CHECK_TYPE_RANGED_INTEGER (int, height);
3023 pixel_width = (!NILP (pixelwise)
3024 ? XINT (width)
3025 : XINT (width) * FRAME_COLUMN_WIDTH (f));
3026 pixel_height = (!NILP (pixelwise)
3027 ? XINT (height)
3028 : XINT (height) * FRAME_LINE_HEIGHT (f));
3029 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
3031 return Qnil;
3034 DEFUN ("frame-position", Fframe_position,
3035 Sframe_position, 0, 1, 0,
3036 doc: /* Return top left corner of FRAME in pixels.
3037 FRAME must be a live frame and defaults to the selected one. The return
3038 value is a cons (x, y) of the coordinates of the top left corner of
3039 FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's
3040 display. */)
3041 (Lisp_Object frame)
3043 register struct frame *f = decode_live_frame (frame);
3045 return Fcons (make_number (f->left_pos), make_number (f->top_pos));
3048 DEFUN ("set-frame-position", Fset_frame_position,
3049 Sset_frame_position, 3, 3, 0,
3050 doc: /* Set position of FRAME to (X, Y).
3051 FRAME must be a live frame and defaults to the selected one. X and Y,
3052 if positive, specify the coordinate of the left and top edge of FRAME's
3053 outer frame in pixels relative to an origin (0, 0) of FRAME's display.
3054 If any of X or Y is negative, it specifies the coordinates of the right
3055 or bottom edge of the outer frame of FRAME relative to the right or
3056 bottom edge of FRAME's display. */)
3057 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
3059 struct frame *f = decode_live_frame (frame);
3061 CHECK_TYPE_RANGED_INTEGER (int, x);
3062 CHECK_TYPE_RANGED_INTEGER (int, y);
3064 /* I think this should be done with a hook. */
3065 if (FRAME_WINDOW_P (f))
3067 #ifdef HAVE_WINDOW_SYSTEM
3068 x_set_offset (f, XINT (x), XINT (y), 1);
3069 #endif
3072 return Qt;
3076 /***********************************************************************
3077 Frame Parameters
3078 ***********************************************************************/
3080 /* Connect the frame-parameter names for X frames
3081 to the ways of passing the parameter values to the window system.
3083 The name of a parameter, as a Lisp symbol,
3084 has an `x-frame-parameter' property which is an integer in Lisp
3085 that is an index in this table. */
3087 struct frame_parm_table {
3088 const char *name;
3089 int sym;
3092 static const struct frame_parm_table frame_parms[] =
3094 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3095 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3096 {"background-color", -1},
3097 {"border-color", SYMBOL_INDEX (Qborder_color)},
3098 {"border-width", SYMBOL_INDEX (Qborder_width)},
3099 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3100 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3101 {"font", -1},
3102 {"foreground-color", -1},
3103 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3104 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3105 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3106 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3107 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3108 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3109 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3110 {"name", SYMBOL_INDEX (Qname)},
3111 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3112 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3113 {"title", SYMBOL_INDEX (Qtitle)},
3114 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3115 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3116 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3117 {"visibility", SYMBOL_INDEX (Qvisibility)},
3118 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3119 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3120 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3121 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3122 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3123 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3124 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3125 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3126 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3127 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3128 {"alpha", SYMBOL_INDEX (Qalpha)},
3129 {"sticky", SYMBOL_INDEX (Qsticky)},
3130 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3133 #ifdef HAVE_WINDOW_SYSTEM
3135 /* Change the parameters of frame F as specified by ALIST.
3136 If a parameter is not specially recognized, do nothing special;
3137 otherwise call the `x_set_...' function for that parameter.
3138 Except for certain geometry properties, always call store_frame_param
3139 to store the new value in the parameter alist. */
3141 void
3142 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3144 Lisp_Object tail;
3146 /* If both of these parameters are present, it's more efficient to
3147 set them both at once. So we wait until we've looked at the
3148 entire list before we set them. */
3149 int width = -1, height = -1; /* -1 denotes they were not changed. */
3151 /* Same here. */
3152 Lisp_Object left, top;
3154 /* Same with these. */
3155 Lisp_Object icon_left, icon_top;
3157 /* And with this. */
3158 Lisp_Object fullscreen;
3159 bool fullscreen_change = false;
3161 /* Record in these vectors all the parms specified. */
3162 Lisp_Object *parms;
3163 Lisp_Object *values;
3164 ptrdiff_t i, j, size;
3165 bool left_no_change = 0, top_no_change = 0;
3166 #ifdef HAVE_X_WINDOWS
3167 bool icon_left_no_change = 0, icon_top_no_change = 0;
3168 #endif
3170 for (size = 0, tail = alist; CONSP (tail); tail = XCDR (tail))
3171 size++;
3173 USE_SAFE_ALLOCA;
3174 SAFE_ALLOCA_LISP (parms, 2 * size);
3175 values = parms + size;
3177 /* Extract parm names and values into those vectors. */
3179 i = 0, j = size - 1;
3180 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3182 Lisp_Object elt = XCAR (tail), prop = Fcar (elt), val = Fcdr (elt);
3184 /* Some properties are independent of other properties, but other
3185 properties are dependent upon them. These special properties
3186 are foreground_color, background_color (affects cursor_color)
3187 and font (affects fringe widths); they're recorded starting
3188 from the end of PARMS and VALUES to process them first by using
3189 reverse iteration. */
3191 if (EQ (prop, Qforeground_color)
3192 || EQ (prop, Qbackground_color)
3193 || EQ (prop, Qfont))
3195 parms[j] = prop;
3196 values[j] = val;
3197 j--;
3199 else
3201 parms[i] = prop;
3202 values[i] = val;
3203 i++;
3207 /* TAIL and ALIST are not used again below here. */
3208 alist = tail = Qnil;
3210 top = left = Qunbound;
3211 icon_left = icon_top = Qunbound;
3213 /* Reverse order is used to make sure that special
3214 properties noticed above are processed first. */
3215 for (i = size - 1; i >= 0; i--)
3217 Lisp_Object prop, val;
3219 prop = parms[i];
3220 val = values[i];
3222 if (EQ (prop, Qwidth))
3224 if (RANGED_INTEGERP (0, val, INT_MAX))
3225 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3226 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3227 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3228 width = XFASTINT (XCDR (val));
3230 else if (EQ (prop, Qheight))
3232 if (RANGED_INTEGERP (0, val, INT_MAX))
3233 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3234 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3235 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3236 height = XFASTINT (XCDR (val));
3238 else if (EQ (prop, Qtop))
3239 top = val;
3240 else if (EQ (prop, Qleft))
3241 left = val;
3242 else if (EQ (prop, Qicon_top))
3243 icon_top = val;
3244 else if (EQ (prop, Qicon_left))
3245 icon_left = val;
3246 else if (EQ (prop, Qfullscreen))
3248 fullscreen = val;
3249 fullscreen_change = true;
3251 else
3253 register Lisp_Object param_index, old_value;
3255 old_value = get_frame_param (f, prop);
3257 store_frame_param (f, prop, val);
3259 param_index = Fget (prop, Qx_frame_parameter);
3260 if (NATNUMP (param_index)
3261 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3262 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3263 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3267 /* Don't die if just one of these was set. */
3268 if (EQ (left, Qunbound))
3270 left_no_change = 1;
3271 if (f->left_pos < 0)
3272 left = list2 (Qplus, make_number (f->left_pos));
3273 else
3274 XSETINT (left, f->left_pos);
3276 if (EQ (top, Qunbound))
3278 top_no_change = 1;
3279 if (f->top_pos < 0)
3280 top = list2 (Qplus, make_number (f->top_pos));
3281 else
3282 XSETINT (top, f->top_pos);
3285 /* If one of the icon positions was not set, preserve or default it. */
3286 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3288 #ifdef HAVE_X_WINDOWS
3289 icon_left_no_change = 1;
3290 #endif
3291 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3292 if (NILP (icon_left))
3293 XSETINT (icon_left, 0);
3295 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3297 #ifdef HAVE_X_WINDOWS
3298 icon_top_no_change = 1;
3299 #endif
3300 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3301 if (NILP (icon_top))
3302 XSETINT (icon_top, 0);
3305 /* Don't set these parameters unless they've been explicitly
3306 specified. The window might be mapped or resized while we're in
3307 this function, and we don't want to override that unless the lisp
3308 code has asked for it.
3310 Don't set these parameters unless they actually differ from the
3311 window's current parameters; the window may not actually exist
3312 yet. */
3314 Lisp_Object frame;
3316 XSETFRAME (frame, f);
3318 if ((width != -1 && width != FRAME_TEXT_WIDTH (f))
3319 || (height != -1 && height != FRAME_TEXT_HEIGHT (f)))
3320 /* We could consider checking f->after_make_frame here, but I
3321 don't have the faintest idea why the following is needed at
3322 all. With the old setting it can get a Heisenbug when
3323 EmacsFrameResize intermittently provokes a delayed
3324 change_frame_size in the middle of adjust_frame_size. */
3325 /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
3326 adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters);
3328 if ((!NILP (left) || !NILP (top))
3329 && ! (left_no_change && top_no_change)
3330 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3331 && NUMBERP (top) && XINT (top) == f->top_pos))
3333 int leftpos = 0;
3334 int toppos = 0;
3336 /* Record the signs. */
3337 f->size_hint_flags &= ~ (XNegative | YNegative);
3338 if (EQ (left, Qminus))
3339 f->size_hint_flags |= XNegative;
3340 else if (TYPE_RANGED_INTEGERP (int, left))
3342 leftpos = XINT (left);
3343 if (leftpos < 0)
3344 f->size_hint_flags |= XNegative;
3346 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3347 && CONSP (XCDR (left))
3348 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3350 leftpos = - XINT (XCAR (XCDR (left)));
3351 f->size_hint_flags |= XNegative;
3353 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3354 && CONSP (XCDR (left))
3355 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3357 leftpos = XINT (XCAR (XCDR (left)));
3360 if (EQ (top, Qminus))
3361 f->size_hint_flags |= YNegative;
3362 else if (TYPE_RANGED_INTEGERP (int, top))
3364 toppos = XINT (top);
3365 if (toppos < 0)
3366 f->size_hint_flags |= YNegative;
3368 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3369 && CONSP (XCDR (top))
3370 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3372 toppos = - XINT (XCAR (XCDR (top)));
3373 f->size_hint_flags |= YNegative;
3375 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3376 && CONSP (XCDR (top))
3377 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3379 toppos = XINT (XCAR (XCDR (top)));
3383 /* Store the numeric value of the position. */
3384 f->top_pos = toppos;
3385 f->left_pos = leftpos;
3387 f->win_gravity = NorthWestGravity;
3389 /* Actually set that position, and convert to absolute. */
3390 x_set_offset (f, leftpos, toppos, -1);
3393 if (fullscreen_change)
3395 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
3397 frame_size_history_add
3398 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
3400 store_frame_param (f, Qfullscreen, fullscreen);
3401 if (!EQ (fullscreen, old_value))
3402 x_set_fullscreen (f, fullscreen, old_value);
3406 #ifdef HAVE_X_WINDOWS
3407 if ((!NILP (icon_left) || !NILP (icon_top))
3408 && ! (icon_left_no_change && icon_top_no_change))
3409 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3410 #endif /* HAVE_X_WINDOWS */
3413 SAFE_FREE ();
3417 /* Insert a description of internally-recorded parameters of frame X
3418 into the parameter alist *ALISTPTR that is to be given to the user.
3419 Only parameters that are specific to the X window system
3420 and whose values are not correctly recorded in the frame's
3421 param_alist need to be considered here. */
3423 void
3424 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3426 Lisp_Object tem;
3427 uprintmax_t w;
3428 char buf[INT_BUFSIZE_BOUND (w)];
3430 /* Represent negative positions (off the top or left screen edge)
3431 in a way that Fmodify_frame_parameters will understand correctly. */
3432 XSETINT (tem, f->left_pos);
3433 if (f->left_pos >= 0)
3434 store_in_alist (alistptr, Qleft, tem);
3435 else
3436 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3438 XSETINT (tem, f->top_pos);
3439 if (f->top_pos >= 0)
3440 store_in_alist (alistptr, Qtop, tem);
3441 else
3442 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3444 store_in_alist (alistptr, Qborder_width,
3445 make_number (f->border_width));
3446 store_in_alist (alistptr, Qinternal_border_width,
3447 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3448 store_in_alist (alistptr, Qright_divider_width,
3449 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3450 store_in_alist (alistptr, Qbottom_divider_width,
3451 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3452 store_in_alist (alistptr, Qleft_fringe,
3453 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3454 store_in_alist (alistptr, Qright_fringe,
3455 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3456 store_in_alist (alistptr, Qscroll_bar_width,
3457 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3458 ? make_number (0)
3459 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3460 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3461 /* nil means "use default width"
3462 for non-toolkit scroll bar.
3463 ruler-mode.el depends on this. */
3464 : Qnil));
3465 store_in_alist (alistptr, Qscroll_bar_height,
3466 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3467 ? make_number (0)
3468 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3469 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3470 /* nil means "use default height"
3471 for non-toolkit scroll bar. */
3472 : Qnil));
3473 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3474 MS-Windows it returns a value whose type is HANDLE, which is
3475 actually a pointer. Explicit casting avoids compiler
3476 warnings. */
3477 w = (uintptr_t) FRAME_X_WINDOW (f);
3478 store_in_alist (alistptr, Qwindow_id,
3479 make_formatted_string (buf, "%"pMu, w));
3480 #ifdef HAVE_X_WINDOWS
3481 #ifdef USE_X_TOOLKIT
3482 /* Tooltip frame may not have this widget. */
3483 if (FRAME_X_OUTPUT (f)->widget)
3484 #endif
3485 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3486 store_in_alist (alistptr, Qouter_window_id,
3487 make_formatted_string (buf, "%"pMu, w));
3488 #endif
3489 store_in_alist (alistptr, Qicon_name, f->icon_name);
3490 store_in_alist (alistptr, Qvisibility,
3491 (FRAME_VISIBLE_P (f) ? Qt
3492 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3493 store_in_alist (alistptr, Qdisplay,
3494 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3496 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3497 tem = Qnil;
3498 else
3499 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3500 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3501 store_in_alist (alistptr, Qparent_id, tem);
3502 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3506 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3507 the previous value of that parameter, NEW_VALUE is the new value. */
3509 void
3510 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3512 if (NILP (new_value))
3513 f->want_fullscreen = FULLSCREEN_NONE;
3514 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3515 f->want_fullscreen = FULLSCREEN_BOTH;
3516 else if (EQ (new_value, Qfullwidth))
3517 f->want_fullscreen = FULLSCREEN_WIDTH;
3518 else if (EQ (new_value, Qfullheight))
3519 f->want_fullscreen = FULLSCREEN_HEIGHT;
3520 else if (EQ (new_value, Qmaximized))
3521 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3523 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3524 FRAME_TERMINAL (f)->fullscreen_hook (f);
3528 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3529 the previous value of that parameter, NEW_VALUE is the new value. */
3531 void
3532 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3534 if (NILP (new_value))
3535 f->extra_line_spacing = 0;
3536 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3537 f->extra_line_spacing = XFASTINT (new_value);
3538 else if (FLOATP (new_value))
3540 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3542 if (new_spacing >= 0)
3543 f->extra_line_spacing = new_spacing;
3544 else
3545 signal_error ("Invalid line-spacing", new_value);
3547 else
3548 signal_error ("Invalid line-spacing", new_value);
3549 if (FRAME_VISIBLE_P (f))
3550 redraw_frame (f);
3554 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3555 the previous value of that parameter, NEW_VALUE is the new value. */
3557 void
3558 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3560 Lisp_Object bgcolor;
3562 if (NILP (new_value))
3563 f->gamma = 0;
3564 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3565 /* The value 0.4545 is the normal viewing gamma. */
3566 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3567 else
3568 signal_error ("Invalid screen-gamma", new_value);
3570 /* Apply the new gamma value to the frame background. */
3571 bgcolor = Fassq (Qbackground_color, f->param_alist);
3572 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3574 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3575 if (NATNUMP (parm_index)
3576 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3577 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3578 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3579 (f, bgcolor, Qnil);
3582 clear_face_cache (true); /* FIXME: Why of all frames? */
3583 fset_redisplay (f);
3587 void
3588 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3590 Lisp_Object font_object;
3591 int fontset = -1;
3592 #ifdef HAVE_X_WINDOWS
3593 Lisp_Object font_param = arg;
3594 #endif
3596 /* Set the frame parameter back to the old value because we may
3597 fail to use ARG as the new parameter value. */
3598 store_frame_param (f, Qfont, oldval);
3600 /* ARG is a fontset name, a font name, a cons of fontset name and a
3601 font object, or a font object. In the last case, this function
3602 never fail. */
3603 if (STRINGP (arg))
3605 fontset = fs_query_fontset (arg, 0);
3606 if (fontset < 0)
3608 font_object = font_open_by_name (f, arg);
3609 if (NILP (font_object))
3610 error ("Font `%s' is not defined", SSDATA (arg));
3611 arg = AREF (font_object, FONT_NAME_INDEX);
3613 else if (fontset > 0)
3615 font_object = font_open_by_name (f, fontset_ascii (fontset));
3616 if (NILP (font_object))
3617 error ("Font `%s' is not defined", SDATA (arg));
3618 arg = AREF (font_object, FONT_NAME_INDEX);
3620 else
3621 error ("The default fontset can't be used for a frame font");
3623 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3625 /* This is the case that the ASCII font of F's fontset XCAR
3626 (arg) is changed to the font XCDR (arg) by
3627 `set-fontset-font'. */
3628 fontset = fs_query_fontset (XCAR (arg), 0);
3629 if (fontset < 0)
3630 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3631 font_object = XCDR (arg);
3632 arg = AREF (font_object, FONT_NAME_INDEX);
3633 #ifdef HAVE_X_WINDOWS
3634 font_param = Ffont_get (font_object, QCname);
3635 #endif
3637 else if (FONT_OBJECT_P (arg))
3639 font_object = arg;
3640 #ifdef HAVE_X_WINDOWS
3641 font_param = Ffont_get (font_object, QCname);
3642 #endif
3643 /* This is to store the XLFD font name in the frame parameter for
3644 backward compatibility. We should store the font-object
3645 itself in the future. */
3646 arg = AREF (font_object, FONT_NAME_INDEX);
3647 fontset = FRAME_FONTSET (f);
3648 /* Check if we can use the current fontset. If not, set FONTSET
3649 to -1 to generate a new fontset from FONT-OBJECT. */
3650 if (fontset >= 0)
3652 Lisp_Object ascii_font = fontset_ascii (fontset);
3653 Lisp_Object spec = font_spec_from_name (ascii_font);
3655 /* SPEC might be nil because ASCII_FONT's name doesn't parse
3656 according to stupid XLFD rules, which, for example,
3657 disallow font names that include a dash followed by a
3658 number. So in those cases we simply request x_new_font
3659 below to generate a new fontset. */
3660 if (NILP (spec) || ! font_match_p (spec, font_object))
3661 fontset = -1;
3664 else
3665 signal_error ("Invalid font", arg);
3667 if (! NILP (Fequal (font_object, oldval)))
3668 return;
3670 x_new_font (f, font_object, fontset);
3671 store_frame_param (f, Qfont, arg);
3672 #ifdef HAVE_X_WINDOWS
3673 store_frame_param (f, Qfont_parameter, font_param);
3674 #endif
3675 /* Recalculate toolbar height. */
3676 f->n_tool_bar_rows = 0;
3678 /* Ensure we redraw it. */
3679 clear_current_matrices (f);
3681 /* Attempt to hunt down bug#16028. */
3682 SET_FRAME_GARBAGED (f);
3684 /* This is important if we are called by some Lisp as part of
3685 redisplaying the frame, see redisplay_internal. */
3686 f->fonts_changed = true;
3688 recompute_basic_faces (f);
3690 do_pending_window_change (0);
3692 /* We used to call face-set-after-frame-default here, but it leads to
3693 recursive calls (since that function can set the `default' face's
3694 font which in turns changes the frame's `font' parameter).
3695 Also I don't know what this call is meant to do, but it seems the
3696 wrong way to do it anyway (it does a lot more work than what seems
3697 reasonable in response to a change to `font'). */
3701 void
3702 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3704 if (! NILP (new_value)
3705 && !CONSP (new_value))
3707 char *p0, *p1;
3709 CHECK_STRING (new_value);
3710 p0 = p1 = SSDATA (new_value);
3711 new_value = Qnil;
3712 while (*p0)
3714 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3715 if (p0 < p1)
3716 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3717 new_value);
3718 if (*p1)
3720 int c;
3722 while ((c = *++p1) && c_isspace (c));
3724 p0 = p1;
3726 new_value = Fnreverse (new_value);
3729 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3730 return;
3732 if (FRAME_FONT (f))
3733 free_all_realized_faces (Qnil);
3735 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3736 if (NILP (new_value))
3738 if (NILP (old_value))
3739 error ("No font backend available");
3740 font_update_drivers (f, old_value);
3741 error ("None of specified font backends are available");
3743 store_frame_param (f, Qfont_backend, new_value);
3745 if (FRAME_FONT (f))
3747 Lisp_Object frame;
3749 XSETFRAME (frame, f);
3750 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3751 face_change = true;
3752 windows_or_buffers_changed = 18;
3756 void
3757 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3759 int unit = FRAME_COLUMN_WIDTH (f);
3760 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3761 int new_width;
3763 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3764 ? eabs (XINT (new_value)) : 8);
3766 if (new_width != old_width)
3768 f->left_fringe_width = new_width;
3769 f->fringe_cols /* Round up. */
3770 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3772 if (FRAME_X_WINDOW (f) != 0)
3773 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
3775 SET_FRAME_GARBAGED (f);
3780 void
3781 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3783 int unit = FRAME_COLUMN_WIDTH (f);
3784 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3785 int new_width;
3787 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3788 ? eabs (XINT (new_value)) : 8);
3790 if (new_width != old_width)
3792 f->right_fringe_width = new_width;
3793 f->fringe_cols /* Round up. */
3794 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3796 if (FRAME_X_WINDOW (f) != 0)
3797 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
3799 SET_FRAME_GARBAGED (f);
3804 void
3805 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3807 CHECK_TYPE_RANGED_INTEGER (int, arg);
3809 if (XINT (arg) == f->border_width)
3810 return;
3812 if (FRAME_X_WINDOW (f) != 0)
3813 error ("Cannot change the border width of a frame");
3815 f->border_width = XINT (arg);
3818 void
3819 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3821 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3822 CHECK_TYPE_RANGED_INTEGER (int, arg);
3823 int new = max (0, XINT (arg));
3824 if (new != old)
3826 f->right_divider_width = new;
3827 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
3828 adjust_frame_glyphs (f);
3829 SET_FRAME_GARBAGED (f);
3834 void
3835 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3837 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3838 CHECK_TYPE_RANGED_INTEGER (int, arg);
3839 int new = max (0, XINT (arg));
3840 if (new != old)
3842 f->bottom_divider_width = new;
3843 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
3844 adjust_frame_glyphs (f);
3845 SET_FRAME_GARBAGED (f);
3849 void
3850 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3852 Lisp_Object frame;
3853 XSETFRAME (frame, f);
3855 if (NILP (value))
3856 Fmake_frame_invisible (frame, Qt);
3857 else if (EQ (value, Qicon))
3858 Ficonify_frame (frame);
3859 else
3860 Fmake_frame_visible (frame);
3863 void
3864 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3866 f->auto_raise = !EQ (Qnil, arg);
3869 void
3870 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3872 f->auto_lower = !EQ (Qnil, arg);
3875 void
3876 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3878 f->no_split = !NILP (arg);
3881 void
3882 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3884 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3885 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3886 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3887 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3889 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3890 = (NILP (arg)
3891 ? vertical_scroll_bar_none
3892 : EQ (Qleft, arg)
3893 ? vertical_scroll_bar_left
3894 : EQ (Qright, arg)
3895 ? vertical_scroll_bar_right
3896 : EQ (Qleft, Vdefault_frame_scroll_bars)
3897 ? vertical_scroll_bar_left
3898 : EQ (Qright, Vdefault_frame_scroll_bars)
3899 ? vertical_scroll_bar_right
3900 : vertical_scroll_bar_none);
3902 /* We set this parameter before creating the X window for the
3903 frame, so we can get the geometry right from the start.
3904 However, if the window hasn't been created yet, we shouldn't
3905 call x_set_window_size. */
3906 if (FRAME_X_WINDOW (f))
3907 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
3909 SET_FRAME_GARBAGED (f);
3913 void
3914 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3916 #if USE_HORIZONTAL_SCROLL_BARS
3917 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3918 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3920 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3922 /* We set this parameter before creating the X window for the
3923 frame, so we can get the geometry right from the start.
3924 However, if the window hasn't been created yet, we shouldn't
3925 call x_set_window_size. */
3926 if (FRAME_X_WINDOW (f))
3927 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
3929 SET_FRAME_GARBAGED (f);
3931 #endif
3934 void
3935 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3937 int unit = FRAME_COLUMN_WIDTH (f);
3939 if (NILP (arg))
3941 x_set_scroll_bar_default_width (f);
3943 if (FRAME_X_WINDOW (f))
3944 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3946 SET_FRAME_GARBAGED (f);
3948 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3949 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3951 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3952 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3953 if (FRAME_X_WINDOW (f))
3954 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3956 SET_FRAME_GARBAGED (f);
3959 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3960 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3963 void
3964 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3966 #if USE_HORIZONTAL_SCROLL_BARS
3967 int unit = FRAME_LINE_HEIGHT (f);
3969 if (NILP (arg))
3971 x_set_scroll_bar_default_height (f);
3973 if (FRAME_X_WINDOW (f))
3974 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3976 SET_FRAME_GARBAGED (f);
3978 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3979 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3981 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3982 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3983 if (FRAME_X_WINDOW (f))
3984 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3986 SET_FRAME_GARBAGED (f);
3989 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3990 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3991 #endif
3994 void
3995 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3997 double alpha = 1.0;
3998 double newval[2];
3999 int i;
4000 Lisp_Object item;
4002 for (i = 0; i < 2; i++)
4004 newval[i] = 1.0;
4005 if (CONSP (arg))
4007 item = CAR (arg);
4008 arg = CDR (arg);
4010 else
4011 item = arg;
4013 if (NILP (item))
4014 alpha = - 1.0;
4015 else if (FLOATP (item))
4017 alpha = XFLOAT_DATA (item);
4018 if (! (0 <= alpha && alpha <= 1.0))
4019 args_out_of_range (make_float (0.0), make_float (1.0));
4021 else if (INTEGERP (item))
4023 EMACS_INT ialpha = XINT (item);
4024 if (! (0 <= ialpha && alpha <= 100))
4025 args_out_of_range (make_number (0), make_number (100));
4026 alpha = ialpha / 100.0;
4028 else
4029 wrong_type_argument (Qnumberp, item);
4030 newval[i] = alpha;
4033 for (i = 0; i < 2; i++)
4034 f->alpha[i] = newval[i];
4036 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4037 block_input ();
4038 x_set_frame_alpha (f);
4039 unblock_input ();
4040 #endif
4042 return;
4045 #ifndef HAVE_NS
4047 /* Non-zero if mouse is grabbed on DPYINFO
4048 and we know the frame where it is. */
4050 bool x_mouse_grabbed (Display_Info *dpyinfo)
4052 return (dpyinfo->grabbed
4053 && dpyinfo->last_mouse_frame
4054 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4057 /* Re-highlight something with mouse-face properties
4058 on DPYINFO using saved frame and mouse position. */
4060 void
4061 x_redo_mouse_highlight (Display_Info *dpyinfo)
4063 if (dpyinfo->last_mouse_motion_frame
4064 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4065 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4066 dpyinfo->last_mouse_motion_x,
4067 dpyinfo->last_mouse_motion_y);
4070 #endif /* HAVE_NS */
4072 /* Subroutines of creating an X frame. */
4074 /* Make sure that Vx_resource_name is set to a reasonable value.
4075 Fix it up, or set it to `emacs' if it is too hopeless. */
4077 void
4078 validate_x_resource_name (void)
4080 ptrdiff_t len = 0;
4081 /* Number of valid characters in the resource name. */
4082 ptrdiff_t good_count = 0;
4083 /* Number of invalid characters in the resource name. */
4084 ptrdiff_t bad_count = 0;
4085 Lisp_Object new;
4086 ptrdiff_t i;
4088 if (!STRINGP (Vx_resource_class))
4089 Vx_resource_class = build_string (EMACS_CLASS);
4091 if (STRINGP (Vx_resource_name))
4093 unsigned char *p = SDATA (Vx_resource_name);
4095 len = SBYTES (Vx_resource_name);
4097 /* Only letters, digits, - and _ are valid in resource names.
4098 Count the valid characters and count the invalid ones. */
4099 for (i = 0; i < len; i++)
4101 int c = p[i];
4102 if (! ((c >= 'a' && c <= 'z')
4103 || (c >= 'A' && c <= 'Z')
4104 || (c >= '0' && c <= '9')
4105 || c == '-' || c == '_'))
4106 bad_count++;
4107 else
4108 good_count++;
4111 else
4112 /* Not a string => completely invalid. */
4113 bad_count = 5, good_count = 0;
4115 /* If name is valid already, return. */
4116 if (bad_count == 0)
4117 return;
4119 /* If name is entirely invalid, or nearly so, or is so implausibly
4120 large that alloca might not work, use `emacs'. */
4121 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4123 Vx_resource_name = build_string ("emacs");
4124 return;
4127 /* Name is partly valid. Copy it and replace the invalid characters
4128 with underscores. */
4130 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4132 for (i = 0; i < len; i++)
4134 int c = SREF (new, i);
4135 if (! ((c >= 'a' && c <= 'z')
4136 || (c >= 'A' && c <= 'Z')
4137 || (c >= '0' && c <= '9')
4138 || c == '-' || c == '_'))
4139 SSET (new, i, '_');
4143 /* Get specified attribute from resource database RDB.
4144 See Fx_get_resource below for other parameters. */
4146 static Lisp_Object
4147 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4149 CHECK_STRING (attribute);
4150 CHECK_STRING (class);
4152 if (!NILP (component))
4153 CHECK_STRING (component);
4154 if (!NILP (subclass))
4155 CHECK_STRING (subclass);
4156 if (NILP (component) != NILP (subclass))
4157 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4159 validate_x_resource_name ();
4161 /* Allocate space for the components, the dots which separate them,
4162 and the final '\0'. Make them big enough for the worst case. */
4163 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4164 + (STRINGP (component)
4165 ? SBYTES (component) : 0)
4166 + SBYTES (attribute)
4167 + 3);
4169 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4170 + SBYTES (class)
4171 + (STRINGP (subclass)
4172 ? SBYTES (subclass) : 0)
4173 + 3);
4174 USE_SAFE_ALLOCA;
4175 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4176 char *class_key = name_key + name_keysize;
4178 /* Start with emacs.FRAMENAME for the name (the specific one)
4179 and with `Emacs' for the class key (the general one). */
4180 char *nz = lispstpcpy (name_key, Vx_resource_name);
4181 char *cz = lispstpcpy (class_key, Vx_resource_class);
4183 *cz++ = '.';
4184 cz = lispstpcpy (cz, class);
4186 if (!NILP (component))
4188 *cz++ = '.';
4189 lispstpcpy (cz, subclass);
4191 *nz++ = '.';
4192 nz = lispstpcpy (nz, component);
4195 *nz++ = '.';
4196 lispstpcpy (nz, attribute);
4198 char *value = x_get_string_resource (rdb, name_key, class_key);
4199 SAFE_FREE();
4201 if (value && *value)
4202 return build_string (value);
4203 else
4204 return Qnil;
4208 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4209 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4210 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4211 class, where INSTANCE is the name under which Emacs was invoked, or
4212 the name specified by the `-name' or `-rn' command-line arguments.
4214 The optional arguments COMPONENT and SUBCLASS add to the key and the
4215 class, respectively. You must specify both of them or neither.
4216 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4217 and the class is `Emacs.CLASS.SUBCLASS'. */)
4218 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4219 Lisp_Object subclass)
4221 check_window_system (NULL);
4223 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4224 attribute, class, component, subclass);
4227 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4229 Lisp_Object
4230 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4231 Lisp_Object class, Lisp_Object component,
4232 Lisp_Object subclass)
4234 return xrdb_get_resource (dpyinfo->xrdb,
4235 attribute, class, component, subclass);
4238 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4239 /* Used when C code wants a resource value. */
4240 /* Called from oldXMenu/Create.c. */
4241 char *
4242 x_get_resource_string (const char *attribute, const char *class)
4244 char *result;
4245 struct frame *sf = SELECTED_FRAME ();
4246 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4247 USE_SAFE_ALLOCA;
4249 /* Allocate space for the components, the dots which separate them,
4250 and the final '\0'. */
4251 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4252 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4253 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4254 char *class_key = name_key + name_keysize;
4256 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4257 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4259 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4260 name_key, class_key);
4261 SAFE_FREE ();
4262 return result;
4264 #endif
4266 /* Return the value of parameter PARAM.
4268 First search ALIST, then Vdefault_frame_alist, then the X defaults
4269 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4271 Convert the resource to the type specified by desired_type.
4273 If no default is specified, return Qunbound. If you call
4274 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4275 and don't let it get stored in any Lisp-visible variables! */
4277 Lisp_Object
4278 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4279 const char *attribute, const char *class, enum resource_types type)
4281 Lisp_Object tem;
4283 tem = Fassq (param, alist);
4285 if (!NILP (tem))
4287 /* If we find this parm in ALIST, clear it out
4288 so that it won't be "left over" at the end. */
4289 Lisp_Object tail;
4290 XSETCAR (tem, Qnil);
4291 /* In case the parameter appears more than once in the alist,
4292 clear it out. */
4293 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4294 if (CONSP (XCAR (tail))
4295 && EQ (XCAR (XCAR (tail)), param))
4296 XSETCAR (XCAR (tail), Qnil);
4298 else
4299 tem = Fassq (param, Vdefault_frame_alist);
4301 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4302 look in the X resources. */
4303 if (EQ (tem, Qnil))
4305 if (attribute && dpyinfo)
4307 AUTO_STRING (at, attribute);
4308 AUTO_STRING (cl, class);
4309 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4311 if (NILP (tem))
4312 return Qunbound;
4314 switch (type)
4316 case RES_TYPE_NUMBER:
4317 return make_number (atoi (SSDATA (tem)));
4319 case RES_TYPE_BOOLEAN_NUMBER:
4320 if (!strcmp (SSDATA (tem), "on")
4321 || !strcmp (SSDATA (tem), "true"))
4322 return make_number (1);
4323 return make_number (atoi (SSDATA (tem)));
4324 break;
4326 case RES_TYPE_FLOAT:
4327 return make_float (atof (SSDATA (tem)));
4329 case RES_TYPE_BOOLEAN:
4330 tem = Fdowncase (tem);
4331 if (!strcmp (SSDATA (tem), "on")
4332 #ifdef HAVE_NS
4333 || !strcmp (SSDATA (tem), "yes")
4334 #endif
4335 || !strcmp (SSDATA (tem), "true"))
4336 return Qt;
4337 else
4338 return Qnil;
4340 case RES_TYPE_STRING:
4341 return tem;
4343 case RES_TYPE_SYMBOL:
4344 /* As a special case, we map the values `true' and `on'
4345 to Qt, and `false' and `off' to Qnil. */
4347 Lisp_Object lower;
4348 lower = Fdowncase (tem);
4349 if (!strcmp (SSDATA (lower), "on")
4350 #ifdef HAVE_NS
4351 || !strcmp (SSDATA (lower), "yes")
4352 #endif
4353 || !strcmp (SSDATA (lower), "true"))
4354 return Qt;
4355 else if (!strcmp (SSDATA (lower), "off")
4356 #ifdef HAVE_NS
4357 || !strcmp (SSDATA (lower), "no")
4358 #endif
4359 || !strcmp (SSDATA (lower), "false"))
4360 return Qnil;
4361 else
4362 return Fintern (tem, Qnil);
4365 default:
4366 emacs_abort ();
4369 else
4370 return Qunbound;
4372 return Fcdr (tem);
4375 static Lisp_Object
4376 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4377 const char *attribute, const char *class,
4378 enum resource_types type)
4380 return x_get_arg (FRAME_DISPLAY_INFO (f),
4381 alist, param, attribute, class, type);
4384 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4386 Lisp_Object
4387 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4388 Lisp_Object param,
4389 const char *attribute, const char *class,
4390 enum resource_types type)
4392 Lisp_Object value;
4394 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4395 attribute, class, type);
4396 if (! NILP (value) && ! EQ (value, Qunbound))
4397 store_frame_param (f, param, value);
4399 return value;
4403 /* Record in frame F the specified or default value according to ALIST
4404 of the parameter named PROP (a Lisp symbol).
4405 If no value is specified for PROP, look for an X default for XPROP
4406 on the frame named NAME.
4407 If that is not found either, use the value DEFLT. */
4409 Lisp_Object
4410 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4411 Lisp_Object deflt, const char *xprop, const char *xclass,
4412 enum resource_types type)
4414 Lisp_Object tem;
4416 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4417 if (EQ (tem, Qunbound))
4418 tem = deflt;
4419 AUTO_FRAME_ARG (arg, prop, tem);
4420 x_set_frame_parameters (f, arg);
4421 return tem;
4425 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4428 * XParseGeometry parses strings of the form
4429 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4430 * width, height, xoffset, and yoffset are unsigned integers.
4431 * Example: "=80x24+300-49"
4432 * The equal sign is optional.
4433 * It returns a bitmask that indicates which of the four values
4434 * were actually found in the string. For each value found,
4435 * the corresponding argument is updated; for each value
4436 * not found, the corresponding argument is left unchanged.
4439 static int
4440 XParseGeometry (char *string,
4441 int *x, int *y,
4442 unsigned int *width, unsigned int *height)
4444 int mask = NoValue;
4445 char *strind;
4446 unsigned long tempWidth UNINIT, tempHeight UNINIT;
4447 long int tempX UNINIT, tempY UNINIT;
4448 char *nextCharacter;
4450 if (string == NULL || *string == '\0')
4451 return mask;
4452 if (*string == '=')
4453 string++; /* ignore possible '=' at beg of geometry spec */
4455 strind = string;
4456 if (*strind != '+' && *strind != '-' && *strind != 'x')
4458 tempWidth = strtoul (strind, &nextCharacter, 10);
4459 if (strind == nextCharacter)
4460 return 0;
4461 strind = nextCharacter;
4462 mask |= WidthValue;
4465 if (*strind == 'x' || *strind == 'X')
4467 strind++;
4468 tempHeight = strtoul (strind, &nextCharacter, 10);
4469 if (strind == nextCharacter)
4470 return 0;
4471 strind = nextCharacter;
4472 mask |= HeightValue;
4475 if (*strind == '+' || *strind == '-')
4477 if (*strind == '-')
4478 mask |= XNegative;
4479 tempX = strtol (strind, &nextCharacter, 10);
4480 if (strind == nextCharacter)
4481 return 0;
4482 strind = nextCharacter;
4483 mask |= XValue;
4484 if (*strind == '+' || *strind == '-')
4486 if (*strind == '-')
4487 mask |= YNegative;
4488 tempY = strtol (strind, &nextCharacter, 10);
4489 if (strind == nextCharacter)
4490 return 0;
4491 strind = nextCharacter;
4492 mask |= YValue;
4496 /* If strind isn't at the end of the string then it's an invalid
4497 geometry specification. */
4499 if (*strind != '\0')
4500 return 0;
4502 if (mask & XValue)
4503 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4504 if (mask & YValue)
4505 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4506 if (mask & WidthValue)
4507 *width = min (tempWidth, UINT_MAX);
4508 if (mask & HeightValue)
4509 *height = min (tempHeight, UINT_MAX);
4510 return mask;
4513 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4516 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4517 make-docfile: the documentation string in ns-win.el was used for
4518 x-parse-geometry even in non-NS builds.
4520 With two definitions of x-parse-geometry in this file, various
4521 things still get confused (eg M-x apropos documentation), so that
4522 it is best if the two definitions just share the same doc-string.
4524 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4525 doc: /* Parse a display geometry string STRING.
4526 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4527 The properties returned may include `top', `left', `height', and `width'.
4528 For X, the value of `left' or `top' may be an integer,
4529 or a list (+ N) meaning N pixels relative to top/left corner,
4530 or a list (- N) meaning -N pixels relative to bottom/right corner.
4531 On Nextstep, this just calls `ns-parse-geometry'. */)
4532 (Lisp_Object string)
4534 int geometry, x, y;
4535 unsigned int width, height;
4536 Lisp_Object result;
4538 CHECK_STRING (string);
4540 #ifdef HAVE_NS
4541 if (strchr (SSDATA (string), ' ') != NULL)
4542 return call1 (Qns_parse_geometry, string);
4543 #endif
4544 geometry = XParseGeometry (SSDATA (string),
4545 &x, &y, &width, &height);
4546 result = Qnil;
4547 if (geometry & XValue)
4549 Lisp_Object element;
4551 if (x >= 0 && (geometry & XNegative))
4552 element = list3 (Qleft, Qminus, make_number (-x));
4553 else if (x < 0 && ! (geometry & XNegative))
4554 element = list3 (Qleft, Qplus, make_number (x));
4555 else
4556 element = Fcons (Qleft, make_number (x));
4557 result = Fcons (element, result);
4560 if (geometry & YValue)
4562 Lisp_Object element;
4564 if (y >= 0 && (geometry & YNegative))
4565 element = list3 (Qtop, Qminus, make_number (-y));
4566 else if (y < 0 && ! (geometry & YNegative))
4567 element = list3 (Qtop, Qplus, make_number (y));
4568 else
4569 element = Fcons (Qtop, make_number (y));
4570 result = Fcons (element, result);
4573 if (geometry & WidthValue)
4574 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4575 if (geometry & HeightValue)
4576 result = Fcons (Fcons (Qheight, make_number (height)), result);
4578 return result;
4582 /* Calculate the desired size and position of frame F.
4583 Return the flags saying which aspects were specified.
4585 Also set the win_gravity and size_hint_flags of F.
4587 Adjust height for toolbar if TOOLBAR_P is 1.
4589 This function does not make the coordinates positive. */
4591 #define DEFAULT_ROWS 36
4592 #define DEFAULT_COLS 80
4594 long
4595 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
4597 Lisp_Object height, width, user_size, top, left, user_position;
4598 long window_prompting = 0;
4599 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4601 /* Default values if we fall through.
4602 Actually, if that happens we should get
4603 window manager prompting. */
4604 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4605 SET_FRAME_COLS (f, DEFAULT_COLS);
4606 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4607 SET_FRAME_LINES (f, DEFAULT_ROWS);
4609 /* Window managers expect that if program-specified
4610 positions are not (0,0), they're intentional, not defaults. */
4611 f->top_pos = 0;
4612 f->left_pos = 0;
4614 /* Calculate a tool bar height so that the user gets a text display
4615 area of the size he specified with -g or via .Xdefaults. Later
4616 changes of the tool bar height don't change the frame size. This
4617 is done so that users can create tall Emacs frames without having
4618 to guess how tall the tool bar will get. */
4619 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4621 if (frame_default_tool_bar_height)
4622 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
4623 else
4625 int margin, relief;
4627 relief = (tool_bar_button_relief >= 0
4628 ? tool_bar_button_relief
4629 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4631 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4632 margin = XFASTINT (Vtool_bar_button_margin);
4633 else if (CONSP (Vtool_bar_button_margin)
4634 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4635 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4636 else
4637 margin = 0;
4639 FRAME_TOOL_BAR_HEIGHT (f)
4640 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4644 /* Ensure that earlier new_width and new_height settings won't
4645 override what we specify below. */
4646 f->new_width = f->new_height = 0;
4648 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4649 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4650 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4652 if (!EQ (width, Qunbound))
4654 if (CONSP (width) && EQ (XCAR (width), Qtext_pixels))
4656 CHECK_NUMBER (XCDR (width));
4657 if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX))
4658 xsignal1 (Qargs_out_of_range, XCDR (width));
4660 SET_FRAME_WIDTH (f, XINT (XCDR (width)));
4661 f->inhibit_horizontal_resize = true;
4662 *x_width = XINT (XCDR (width));
4664 else
4666 CHECK_NUMBER (width);
4667 if ((XINT (width) < 0 || XINT (width) > INT_MAX))
4668 xsignal1 (Qargs_out_of_range, width);
4670 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4674 if (!EQ (height, Qunbound))
4676 if (CONSP (height) && EQ (XCAR (height), Qtext_pixels))
4678 CHECK_NUMBER (XCDR (height));
4679 if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX))
4680 xsignal1 (Qargs_out_of_range, XCDR (height));
4682 SET_FRAME_HEIGHT (f, XINT (XCDR (height)));
4683 f->inhibit_vertical_resize = true;
4684 *x_height = XINT (XCDR (height));
4686 else
4688 CHECK_NUMBER (height);
4689 if ((XINT (height) < 0) || (XINT (height) > INT_MAX))
4690 xsignal1 (Qargs_out_of_range, height);
4692 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4696 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4697 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4698 window_prompting |= USSize;
4699 else
4700 window_prompting |= PSize;
4703 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4704 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4705 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4706 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4708 if (EQ (top, Qminus))
4710 f->top_pos = 0;
4711 window_prompting |= YNegative;
4713 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4714 && CONSP (XCDR (top))
4715 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4717 f->top_pos = - XINT (XCAR (XCDR (top)));
4718 window_prompting |= YNegative;
4720 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4721 && CONSP (XCDR (top))
4722 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4724 f->top_pos = XINT (XCAR (XCDR (top)));
4726 else if (EQ (top, Qunbound))
4727 f->top_pos = 0;
4728 else
4730 CHECK_TYPE_RANGED_INTEGER (int, top);
4731 f->top_pos = XINT (top);
4732 if (f->top_pos < 0)
4733 window_prompting |= YNegative;
4736 if (EQ (left, Qminus))
4738 f->left_pos = 0;
4739 window_prompting |= XNegative;
4741 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4742 && CONSP (XCDR (left))
4743 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4745 f->left_pos = - XINT (XCAR (XCDR (left)));
4746 window_prompting |= XNegative;
4748 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4749 && CONSP (XCDR (left))
4750 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4752 f->left_pos = XINT (XCAR (XCDR (left)));
4754 else if (EQ (left, Qunbound))
4755 f->left_pos = 0;
4756 else
4758 CHECK_TYPE_RANGED_INTEGER (int, left);
4759 f->left_pos = XINT (left);
4760 if (f->left_pos < 0)
4761 window_prompting |= XNegative;
4764 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4765 window_prompting |= USPosition;
4766 else
4767 window_prompting |= PPosition;
4770 if (window_prompting & XNegative)
4772 if (window_prompting & YNegative)
4773 f->win_gravity = SouthEastGravity;
4774 else
4775 f->win_gravity = NorthEastGravity;
4777 else
4779 if (window_prompting & YNegative)
4780 f->win_gravity = SouthWestGravity;
4781 else
4782 f->win_gravity = NorthWestGravity;
4785 f->size_hint_flags = window_prompting;
4787 return window_prompting;
4792 #endif /* HAVE_WINDOW_SYSTEM */
4794 void
4795 frame_make_pointer_invisible (struct frame *f)
4797 if (! NILP (Vmake_pointer_invisible))
4799 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4800 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4802 f->mouse_moved = 0;
4803 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4804 f->pointer_invisible = 1;
4809 void
4810 frame_make_pointer_visible (struct frame *f)
4812 /* We don't check Vmake_pointer_invisible here in case the
4813 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4814 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4815 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4817 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4818 f->pointer_invisible = 0;
4822 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4823 Sframe_pointer_visible_p, 0, 1, 0,
4824 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4825 Otherwise it returns nil. FRAME omitted or nil means the
4826 selected frame. This is useful when `make-pointer-invisible' is set. */)
4827 (Lisp_Object frame)
4829 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4834 /***********************************************************************
4835 Multimonitor data
4836 ***********************************************************************/
4838 #ifdef HAVE_WINDOW_SYSTEM
4840 # if (defined HAVE_NS \
4841 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4842 void
4843 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4845 int i;
4846 for (i = 0; i < n_monitors; ++i)
4847 xfree (monitors[i].name);
4848 xfree (monitors);
4850 # endif
4852 Lisp_Object
4853 make_monitor_attribute_list (struct MonitorInfo *monitors,
4854 int n_monitors,
4855 int primary_monitor,
4856 Lisp_Object monitor_frames,
4857 const char *source)
4859 Lisp_Object attributes_list = Qnil;
4860 Lisp_Object primary_monitor_attributes = Qnil;
4861 int i;
4863 for (i = 0; i < n_monitors; ++i)
4865 Lisp_Object geometry, workarea, attributes = Qnil;
4866 struct MonitorInfo *mi = &monitors[i];
4868 if (mi->geom.width == 0) continue;
4870 workarea = list4i (mi->work.x, mi->work.y,
4871 mi->work.width, mi->work.height);
4872 geometry = list4i (mi->geom.x, mi->geom.y,
4873 mi->geom.width, mi->geom.height);
4874 attributes = Fcons (Fcons (Qsource, build_string (source)),
4875 attributes);
4876 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4877 attributes);
4878 attributes = Fcons (Fcons (Qmm_size,
4879 list2i (mi->mm_width, mi->mm_height)),
4880 attributes);
4881 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4882 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4883 if (mi->name)
4884 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4885 strlen (mi->name))),
4886 attributes);
4888 if (i == primary_monitor)
4889 primary_monitor_attributes = attributes;
4890 else
4891 attributes_list = Fcons (attributes, attributes_list);
4894 if (!NILP (primary_monitor_attributes))
4895 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4896 return attributes_list;
4899 #endif /* HAVE_WINDOW_SYSTEM */
4902 /***********************************************************************
4903 Initialization
4904 ***********************************************************************/
4906 void
4907 syms_of_frame (void)
4909 DEFSYM (Qframep, "framep");
4910 DEFSYM (Qframe_live_p, "frame-live-p");
4911 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4912 DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total");
4913 DEFSYM (Qexplicit_name, "explicit-name");
4914 DEFSYM (Qheight, "height");
4915 DEFSYM (Qicon, "icon");
4916 DEFSYM (Qminibuffer, "minibuffer");
4917 DEFSYM (Qmodeline, "modeline");
4918 DEFSYM (Qonly, "only");
4919 DEFSYM (Qnone, "none");
4920 DEFSYM (Qwidth, "width");
4921 DEFSYM (Qtext_pixels, "text-pixels");
4922 DEFSYM (Qgeometry, "geometry");
4923 DEFSYM (Qicon_left, "icon-left");
4924 DEFSYM (Qicon_top, "icon-top");
4925 DEFSYM (Qtooltip, "tooltip");
4926 DEFSYM (Quser_position, "user-position");
4927 DEFSYM (Quser_size, "user-size");
4928 DEFSYM (Qwindow_id, "window-id");
4929 #ifdef HAVE_X_WINDOWS
4930 DEFSYM (Qouter_window_id, "outer-window-id");
4931 #endif
4932 DEFSYM (Qparent_id, "parent-id");
4933 DEFSYM (Qx, "x");
4934 DEFSYM (Qw32, "w32");
4935 DEFSYM (Qpc, "pc");
4936 DEFSYM (Qns, "ns");
4937 DEFSYM (Qvisible, "visible");
4938 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4939 DEFSYM (Qbuffer_list, "buffer-list");
4940 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4941 DEFSYM (Qdisplay_type, "display-type");
4942 DEFSYM (Qbackground_mode, "background-mode");
4943 DEFSYM (Qnoelisp, "noelisp");
4944 DEFSYM (Qtty_color_mode, "tty-color-mode");
4945 DEFSYM (Qtty, "tty");
4946 DEFSYM (Qtty_type, "tty-type");
4948 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4950 DEFSYM (Qfullwidth, "fullwidth");
4951 DEFSYM (Qfullheight, "fullheight");
4952 DEFSYM (Qfullboth, "fullboth");
4953 DEFSYM (Qmaximized, "maximized");
4954 DEFSYM (Qx_resource_name, "x-resource-name");
4955 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4957 DEFSYM (Qterminal, "terminal");
4959 DEFSYM (Qworkarea, "workarea");
4960 DEFSYM (Qmm_size, "mm-size");
4961 DEFSYM (Qframes, "frames");
4962 DEFSYM (Qsource, "source");
4964 DEFSYM (Qouter_edges, "outer-edges");
4965 DEFSYM (Qouter_position, "outer-position");
4966 DEFSYM (Qouter_size, "outer-size");
4967 DEFSYM (Qnative_edges, "native-edges");
4968 DEFSYM (Qinner_edges, "inner-edges");
4969 DEFSYM (Qexternal_border_size, "external-border-size");
4970 DEFSYM (Qtitle_bar_size, "title-bar-size");
4971 DEFSYM (Qmenu_bar_external, "menu-bar-external");
4972 DEFSYM (Qmenu_bar_size, "menu-bar-size");
4973 DEFSYM (Qtool_bar_external, "tool-bar-external");
4974 DEFSYM (Qtool_bar_size, "tool-bar-size");
4975 /* The following are used for frame_size_history. */
4976 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
4977 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
4978 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
4979 DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
4980 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
4981 DEFSYM (Qset_frame_size, "set-frame-size");
4982 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
4983 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
4984 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
4985 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
4986 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
4987 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
4988 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
4989 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
4990 DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
4991 DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
4992 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
4993 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
4994 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
4995 DEFSYM (Qtb_size_cb, "tb-size-cb");
4996 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
4997 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
4998 DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines");
4999 DEFSYM (Qchange_frame_size, "change-frame-size");
5000 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
5001 DEFSYM (Qset_window_configuration, "set-window-configuration");
5002 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
5003 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
5004 DEFSYM (Qterminal_frame, "terminal-frame");
5006 #ifdef HAVE_NS
5007 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
5008 #endif
5010 DEFSYM (Qalpha, "alpha");
5011 DEFSYM (Qauto_lower, "auto-lower");
5012 DEFSYM (Qauto_raise, "auto-raise");
5013 DEFSYM (Qborder_color, "border-color");
5014 DEFSYM (Qborder_width, "border-width");
5015 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
5016 DEFSYM (Qcursor_color, "cursor-color");
5017 DEFSYM (Qcursor_type, "cursor-type");
5018 DEFSYM (Qfont_backend, "font-backend");
5019 DEFSYM (Qfullscreen, "fullscreen");
5020 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
5021 DEFSYM (Qicon_name, "icon-name");
5022 DEFSYM (Qicon_type, "icon-type");
5023 DEFSYM (Qinternal_border_width, "internal-border-width");
5024 DEFSYM (Qleft_fringe, "left-fringe");
5025 DEFSYM (Qline_spacing, "line-spacing");
5026 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
5027 DEFSYM (Qupdate_frame_menubar, "update-frame-menubar");
5028 DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1");
5029 DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2");
5030 DEFSYM (Qmouse_color, "mouse-color");
5031 DEFSYM (Qname, "name");
5032 DEFSYM (Qright_divider_width, "right-divider-width");
5033 DEFSYM (Qright_fringe, "right-fringe");
5034 DEFSYM (Qscreen_gamma, "screen-gamma");
5035 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
5036 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
5037 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
5038 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
5039 DEFSYM (Qsticky, "sticky");
5040 DEFSYM (Qtitle, "title");
5041 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
5042 DEFSYM (Qtool_bar_position, "tool-bar-position");
5043 DEFSYM (Qunsplittable, "unsplittable");
5044 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
5045 DEFSYM (Qvisibility, "visibility");
5046 DEFSYM (Qwait_for_wm, "wait-for-wm");
5049 int i;
5051 for (i = 0; i < ARRAYELTS (frame_parms); i++)
5053 Lisp_Object v = (frame_parms[i].sym < 0
5054 ? intern_c_string (frame_parms[i].name)
5055 : builtin_lisp_symbol (frame_parms[i].sym));
5056 Fput (v, Qx_frame_parameter, make_number (i));
5060 #ifdef HAVE_WINDOW_SYSTEM
5061 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
5062 doc: /* The name Emacs uses to look up X resources.
5063 `x-get-resource' uses this as the first component of the instance name
5064 when requesting resource values.
5065 Emacs initially sets `x-resource-name' to the name under which Emacs
5066 was invoked, or to the value specified with the `-name' or `-rn'
5067 switches, if present.
5069 It may be useful to bind this variable locally around a call
5070 to `x-get-resource'. See also the variable `x-resource-class'. */);
5071 Vx_resource_name = Qnil;
5073 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5074 doc: /* The class Emacs uses to look up X resources.
5075 `x-get-resource' uses this as the first component of the instance class
5076 when requesting resource values.
5078 Emacs initially sets `x-resource-class' to "Emacs".
5080 Setting this variable permanently is not a reasonable thing to do,
5081 but binding this variable locally around a call to `x-get-resource'
5082 is a reasonable practice. See also the variable `x-resource-name'. */);
5083 Vx_resource_class = build_string (EMACS_CLASS);
5085 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5086 doc: /* The lower limit of the frame opacity (alpha transparency).
5087 The value should range from 0 (invisible) to 100 (completely opaque).
5088 You can also use a floating number between 0.0 and 1.0. */);
5089 Vframe_alpha_lower_limit = make_number (20);
5090 #endif
5092 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5093 doc: /* Alist of default values for frame creation.
5094 These may be set in your init file, like this:
5095 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5096 These override values given in window system configuration data,
5097 including X Windows' defaults database.
5098 For values specific to the first Emacs frame, see `initial-frame-alist'.
5099 For window-system specific values, see `window-system-default-frame-alist'.
5100 For values specific to the separate minibuffer frame, see
5101 `minibuffer-frame-alist'.
5102 The `menu-bar-lines' element of the list controls whether new frames
5103 have menu bars; `menu-bar-mode' works by altering this element.
5104 Setting this variable does not affect existing frames, only new ones. */);
5105 Vdefault_frame_alist = Qnil;
5107 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5108 doc: /* Default position of vertical scroll bars on this window-system. */);
5109 #ifdef HAVE_WINDOW_SYSTEM
5110 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5111 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
5112 default. */
5113 Vdefault_frame_scroll_bars = Qright;
5114 #else
5115 Vdefault_frame_scroll_bars = Qleft;
5116 #endif
5117 #else
5118 Vdefault_frame_scroll_bars = Qnil;
5119 #endif
5121 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5122 scroll_bar_adjust_thumb_portion_p,
5123 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5124 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5125 even if the end of the buffer is shown (i.e. overscrolling).
5126 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5127 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5128 is visible. In this case you can not overscroll. */);
5129 scroll_bar_adjust_thumb_portion_p = 1;
5131 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5132 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5134 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5135 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5136 `mouse-position' and `mouse-pixel-position' call this function, passing their
5137 usual return value as argument, and return whatever this function returns.
5138 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5139 which need to do mouse handling at the Lisp level. */);
5140 Vmouse_position_function = Qnil;
5142 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5143 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5144 If the value is an integer, highlighting is only shown after moving the
5145 mouse, while keyboard input turns off the highlight even when the mouse
5146 is over the clickable text. However, the mouse shape still indicates
5147 when the mouse is over clickable text. */);
5148 Vmouse_highlight = Qt;
5150 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5151 doc: /* If non-nil, make pointer invisible while typing.
5152 The pointer becomes visible again when the mouse is moved. */);
5153 Vmake_pointer_invisible = Qt;
5155 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5156 doc: /* Normal hook run when a frame gains input focus. */);
5157 Vfocus_in_hook = Qnil;
5159 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5160 doc: /* Normal hook run when a frame loses input focus. */);
5161 Vfocus_out_hook = Qnil;
5163 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5164 doc: /* Functions run before deleting a frame.
5165 The functions are run with one arg, the frame to be deleted.
5166 See `delete-frame'.
5168 Note that functions in this list may be called just before the frame is
5169 actually deleted, or some time later (or even both when an earlier function
5170 in `delete-frame-functions' (indirectly) calls `delete-frame'
5171 recursively). */);
5172 Vdelete_frame_functions = Qnil;
5173 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5175 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5176 doc: /* Non-nil if Menu-Bar mode is enabled.
5177 See the command `menu-bar-mode' for a description of this minor mode.
5178 Setting this variable directly does not take effect;
5179 either customize it (see the info node `Easy Customization')
5180 or call the function `menu-bar-mode'. */);
5181 Vmenu_bar_mode = Qt;
5183 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5184 doc: /* Non-nil if Tool-Bar mode is enabled.
5185 See the command `tool-bar-mode' for a description of this minor mode.
5186 Setting this variable directly does not take effect;
5187 either customize it (see the info node `Easy Customization')
5188 or call the function `tool-bar-mode'. */);
5189 #ifdef HAVE_WINDOW_SYSTEM
5190 Vtool_bar_mode = Qt;
5191 #else
5192 Vtool_bar_mode = Qnil;
5193 #endif
5195 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5196 doc: /* Minibufferless frames use this frame's minibuffer.
5197 Emacs cannot create minibufferless frames unless this is set to an
5198 appropriate surrogate.
5200 Emacs consults this variable only when creating minibufferless
5201 frames; once the frame is created, it sticks with its assigned
5202 minibuffer, no matter what this variable is set to. This means that
5203 this variable doesn't necessarily say anything meaningful about the
5204 current set of frames, or where the minibuffer is currently being
5205 displayed.
5207 This variable is local to the current terminal and cannot be buffer-local. */);
5209 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
5210 doc: /* Non-nil if window system changes focus when you move the mouse.
5211 You should set this variable to tell Emacs how your window manager
5212 handles focus, since there is no way in general for Emacs to find out
5213 automatically. See also `mouse-autoselect-window'. */);
5214 focus_follows_mouse = 0;
5216 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5217 doc: /* Non-nil means resize frames pixelwise.
5218 If this option is nil, resizing a frame rounds its sizes to the frame's
5219 current values of `frame-char-height' and `frame-char-width'. If this
5220 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5221 by one pixel.
5223 With some window managers you may have to set this to non-nil in order
5224 to set the size of a frame in pixels, to maximize frames or to make them
5225 fullscreen. To resize your initial frame pixelwise, set this option to
5226 a non-nil value in your init file. */);
5227 frame_resize_pixelwise = 0;
5229 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5230 doc: /* Whether frames should be resized implicitly.
5231 If this option is nil, setting font, menu bar, tool bar, internal
5232 borders, fringes or scroll bars of a specific frame may resize the frame
5233 in order to preserve the number of columns or lines it displays. If
5234 this option is t, no such resizing is done. Note that the size of
5235 fullscreen and maximized frames, the height of fullheight frames and the
5236 width of fullwidth frames never change implicitly.
5238 The value of this option can be also be a list of frame parameters. In
5239 this case, resizing is inhibited when changing a parameter that appears
5240 in that list. The parameters currently handled by this option include
5241 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5242 `tool-bar-lines'.
5244 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5245 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5246 `right-fringe' is handled as if the frame contained just one live
5247 window. This means, for example, that removing vertical scroll bars on
5248 a frame containing several side by side windows will shrink the frame
5249 width by the width of one scroll bar provided this option is nil and
5250 keep it unchanged if this option is either t or a list containing
5251 `vertical-scroll-bars'.
5253 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
5254 \(which means that adding/removing a tool bar does not change the frame
5255 height), nil on all other window systems including GTK+ (which means
5256 that changing any of the parameters listed above may change the size of
5257 the frame), and t otherwise (which means the frame size never changes
5258 implicitly when there's no window system support).
5260 Note that when a frame is not large enough to accommodate a change of
5261 any of the parameters listed above, Emacs may try to enlarge the frame
5262 even if this option is non-nil. */);
5263 #if defined (HAVE_WINDOW_SYSTEM)
5264 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
5265 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
5266 #else
5267 frame_inhibit_implied_resize = Qnil;
5268 #endif
5269 #else
5270 frame_inhibit_implied_resize = Qt;
5271 #endif
5273 DEFVAR_LISP ("frame-size-history", frame_size_history,
5274 doc: /* History of frame size adjustments.
5275 If non-nil, list recording frame size adjustment. Adjustments are
5276 recorded only if the first element of this list is a positive number.
5277 Adding an adjustment decrements that number by one.
5279 The remaining elements are the adjustments. Each adjustment is a list
5280 of four elements `frame', `function', `sizes' and `more'. `frame' is
5281 the affected frame and `function' the invoking function. `sizes' is
5282 usually a list of four elements `old-width', `old-height', `new-width'
5283 and `new-height' representing the old and new sizes recorded/requested
5284 by `function'. `more' is a list with additional information.
5286 The function `frame--size-history' displays the value of this variable
5287 in a more readable form. */);
5288 frame_size_history = Qnil;
5290 DEFVAR_BOOL ("tooltip-reuse-hidden-frame", tooltip_reuse_hidden_frame,
5291 doc: /* Non-nil means reuse hidden tooltip frames.
5292 When this is nil, delete a tooltip frame when hiding the associated
5293 tooltip. When this is non-nil, make the tooltip frame invisible only,
5294 so it can be reused when the next tooltip is shown.
5296 Setting this to non-nil may drastically reduce the consing overhead
5297 incurred by creating new tooltip frames. However, a value of non-nil
5298 means also that intermittent changes of faces or `default-frame-alist'
5299 are not applied when showing a tooltip in a reused frame.
5301 This variable is effective only with the X toolkit (and there only when
5302 Gtk+ tooltips are not used) and on Windows. */);
5303 tooltip_reuse_hidden_frame = false;
5305 staticpro (&Vframe_list);
5307 defsubr (&Sframep);
5308 defsubr (&Sframe_live_p);
5309 defsubr (&Swindow_system);
5310 defsubr (&Sframe_windows_min_size);
5311 defsubr (&Smake_terminal_frame);
5312 defsubr (&Shandle_switch_frame);
5313 defsubr (&Sselect_frame);
5314 defsubr (&Sselected_frame);
5315 defsubr (&Sframe_list);
5316 defsubr (&Snext_frame);
5317 defsubr (&Sprevious_frame);
5318 defsubr (&Slast_nonminibuf_frame);
5319 defsubr (&Sdelete_frame);
5320 defsubr (&Smouse_position);
5321 defsubr (&Smouse_pixel_position);
5322 defsubr (&Sset_mouse_position);
5323 defsubr (&Sset_mouse_pixel_position);
5324 #if 0
5325 defsubr (&Sframe_configuration);
5326 defsubr (&Srestore_frame_configuration);
5327 #endif
5328 defsubr (&Smake_frame_visible);
5329 defsubr (&Smake_frame_invisible);
5330 defsubr (&Siconify_frame);
5331 defsubr (&Sframe_visible_p);
5332 defsubr (&Svisible_frame_list);
5333 defsubr (&Sraise_frame);
5334 defsubr (&Slower_frame);
5335 defsubr (&Sx_focus_frame);
5336 defsubr (&Sframe_after_make_frame);
5337 defsubr (&Sredirect_frame_focus);
5338 defsubr (&Sframe_focus);
5339 defsubr (&Sframe_parameters);
5340 defsubr (&Sframe_parameter);
5341 defsubr (&Smodify_frame_parameters);
5342 defsubr (&Sframe_char_height);
5343 defsubr (&Sframe_char_width);
5344 defsubr (&Sframe_pixel_height);
5345 defsubr (&Sframe_pixel_width);
5346 defsubr (&Sframe_text_cols);
5347 defsubr (&Sframe_text_lines);
5348 defsubr (&Sframe_total_cols);
5349 defsubr (&Sframe_total_lines);
5350 defsubr (&Sframe_text_width);
5351 defsubr (&Sframe_text_height);
5352 defsubr (&Sscroll_bar_width);
5353 defsubr (&Sscroll_bar_height);
5354 defsubr (&Sfringe_width);
5355 defsubr (&Sborder_width);
5356 defsubr (&Sright_divider_width);
5357 defsubr (&Sbottom_divider_width);
5358 defsubr (&Stool_bar_pixel_width);
5359 defsubr (&Sset_frame_height);
5360 defsubr (&Sset_frame_width);
5361 defsubr (&Sset_frame_size);
5362 defsubr (&Sframe_position);
5363 defsubr (&Sset_frame_position);
5364 defsubr (&Sframe_pointer_visible_p);
5366 #ifdef HAVE_WINDOW_SYSTEM
5367 defsubr (&Sx_get_resource);
5368 defsubr (&Sx_parse_geometry);
5369 #endif