Avoid compilation warnings in nt/*.c files
[emacs.git] / src / frame.c
blobb1d89f396ec1ed9b93654e36c736e14b321a0408
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)},
3131 {"inhibit-double-buffering", SYMBOL_INDEX (Qinhibit_double_buffering)},
3134 #ifdef HAVE_WINDOW_SYSTEM
3136 /* Change the parameters of frame F as specified by ALIST.
3137 If a parameter is not specially recognized, do nothing special;
3138 otherwise call the `x_set_...' function for that parameter.
3139 Except for certain geometry properties, always call store_frame_param
3140 to store the new value in the parameter alist. */
3142 void
3143 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3145 Lisp_Object tail;
3147 /* If both of these parameters are present, it's more efficient to
3148 set them both at once. So we wait until we've looked at the
3149 entire list before we set them. */
3150 int width = -1, height = -1; /* -1 denotes they were not changed. */
3152 /* Same here. */
3153 Lisp_Object left, top;
3155 /* Same with these. */
3156 Lisp_Object icon_left, icon_top;
3158 /* And with this. */
3159 Lisp_Object fullscreen;
3160 bool fullscreen_change = false;
3162 /* Record in these vectors all the parms specified. */
3163 Lisp_Object *parms;
3164 Lisp_Object *values;
3165 ptrdiff_t i, j, size;
3166 bool left_no_change = 0, top_no_change = 0;
3167 #ifdef HAVE_X_WINDOWS
3168 bool icon_left_no_change = 0, icon_top_no_change = 0;
3169 #endif
3171 for (size = 0, tail = alist; CONSP (tail); tail = XCDR (tail))
3172 size++;
3174 USE_SAFE_ALLOCA;
3175 SAFE_ALLOCA_LISP (parms, 2 * size);
3176 values = parms + size;
3178 /* Extract parm names and values into those vectors. */
3180 i = 0, j = size - 1;
3181 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3183 Lisp_Object elt = XCAR (tail), prop = Fcar (elt), val = Fcdr (elt);
3185 /* Some properties are independent of other properties, but other
3186 properties are dependent upon them. These special properties
3187 are foreground_color, background_color (affects cursor_color)
3188 and font (affects fringe widths); they're recorded starting
3189 from the end of PARMS and VALUES to process them first by using
3190 reverse iteration. */
3192 if (EQ (prop, Qforeground_color)
3193 || EQ (prop, Qbackground_color)
3194 || EQ (prop, Qfont))
3196 parms[j] = prop;
3197 values[j] = val;
3198 j--;
3200 else
3202 parms[i] = prop;
3203 values[i] = val;
3204 i++;
3208 /* TAIL and ALIST are not used again below here. */
3209 alist = tail = Qnil;
3211 top = left = Qunbound;
3212 icon_left = icon_top = Qunbound;
3214 /* Reverse order is used to make sure that special
3215 properties noticed above are processed first. */
3216 for (i = size - 1; i >= 0; i--)
3218 Lisp_Object prop, val;
3220 prop = parms[i];
3221 val = values[i];
3223 if (EQ (prop, Qwidth))
3225 if (RANGED_INTEGERP (0, val, INT_MAX))
3226 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3227 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3228 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3229 width = XFASTINT (XCDR (val));
3231 else if (EQ (prop, Qheight))
3233 if (RANGED_INTEGERP (0, val, INT_MAX))
3234 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3235 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3236 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3237 height = XFASTINT (XCDR (val));
3239 else if (EQ (prop, Qtop))
3240 top = val;
3241 else if (EQ (prop, Qleft))
3242 left = val;
3243 else if (EQ (prop, Qicon_top))
3244 icon_top = val;
3245 else if (EQ (prop, Qicon_left))
3246 icon_left = val;
3247 else if (EQ (prop, Qfullscreen))
3249 fullscreen = val;
3250 fullscreen_change = true;
3252 else
3254 register Lisp_Object param_index, old_value;
3256 old_value = get_frame_param (f, prop);
3258 store_frame_param (f, prop, val);
3260 param_index = Fget (prop, Qx_frame_parameter);
3261 if (NATNUMP (param_index)
3262 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3263 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3264 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3268 /* Don't die if just one of these was set. */
3269 if (EQ (left, Qunbound))
3271 left_no_change = 1;
3272 if (f->left_pos < 0)
3273 left = list2 (Qplus, make_number (f->left_pos));
3274 else
3275 XSETINT (left, f->left_pos);
3277 if (EQ (top, Qunbound))
3279 top_no_change = 1;
3280 if (f->top_pos < 0)
3281 top = list2 (Qplus, make_number (f->top_pos));
3282 else
3283 XSETINT (top, f->top_pos);
3286 /* If one of the icon positions was not set, preserve or default it. */
3287 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3289 #ifdef HAVE_X_WINDOWS
3290 icon_left_no_change = 1;
3291 #endif
3292 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3293 if (NILP (icon_left))
3294 XSETINT (icon_left, 0);
3296 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3298 #ifdef HAVE_X_WINDOWS
3299 icon_top_no_change = 1;
3300 #endif
3301 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3302 if (NILP (icon_top))
3303 XSETINT (icon_top, 0);
3306 /* Don't set these parameters unless they've been explicitly
3307 specified. The window might be mapped or resized while we're in
3308 this function, and we don't want to override that unless the lisp
3309 code has asked for it.
3311 Don't set these parameters unless they actually differ from the
3312 window's current parameters; the window may not actually exist
3313 yet. */
3315 Lisp_Object frame;
3317 XSETFRAME (frame, f);
3319 if ((width != -1 && width != FRAME_TEXT_WIDTH (f))
3320 || (height != -1 && height != FRAME_TEXT_HEIGHT (f)))
3321 /* We could consider checking f->after_make_frame here, but I
3322 don't have the faintest idea why the following is needed at
3323 all. With the old setting it can get a Heisenbug when
3324 EmacsFrameResize intermittently provokes a delayed
3325 change_frame_size in the middle of adjust_frame_size. */
3326 /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
3327 adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters);
3329 if ((!NILP (left) || !NILP (top))
3330 && ! (left_no_change && top_no_change)
3331 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3332 && NUMBERP (top) && XINT (top) == f->top_pos))
3334 int leftpos = 0;
3335 int toppos = 0;
3337 /* Record the signs. */
3338 f->size_hint_flags &= ~ (XNegative | YNegative);
3339 if (EQ (left, Qminus))
3340 f->size_hint_flags |= XNegative;
3341 else if (TYPE_RANGED_INTEGERP (int, left))
3343 leftpos = XINT (left);
3344 if (leftpos < 0)
3345 f->size_hint_flags |= XNegative;
3347 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3348 && CONSP (XCDR (left))
3349 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3351 leftpos = - XINT (XCAR (XCDR (left)));
3352 f->size_hint_flags |= XNegative;
3354 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3355 && CONSP (XCDR (left))
3356 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3358 leftpos = XINT (XCAR (XCDR (left)));
3361 if (EQ (top, Qminus))
3362 f->size_hint_flags |= YNegative;
3363 else if (TYPE_RANGED_INTEGERP (int, top))
3365 toppos = XINT (top);
3366 if (toppos < 0)
3367 f->size_hint_flags |= YNegative;
3369 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3370 && CONSP (XCDR (top))
3371 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3373 toppos = - XINT (XCAR (XCDR (top)));
3374 f->size_hint_flags |= YNegative;
3376 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3377 && CONSP (XCDR (top))
3378 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3380 toppos = XINT (XCAR (XCDR (top)));
3384 /* Store the numeric value of the position. */
3385 f->top_pos = toppos;
3386 f->left_pos = leftpos;
3388 f->win_gravity = NorthWestGravity;
3390 /* Actually set that position, and convert to absolute. */
3391 x_set_offset (f, leftpos, toppos, -1);
3394 if (fullscreen_change)
3396 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
3398 frame_size_history_add
3399 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
3401 store_frame_param (f, Qfullscreen, fullscreen);
3402 if (!EQ (fullscreen, old_value))
3403 x_set_fullscreen (f, fullscreen, old_value);
3407 #ifdef HAVE_X_WINDOWS
3408 if ((!NILP (icon_left) || !NILP (icon_top))
3409 && ! (icon_left_no_change && icon_top_no_change))
3410 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3411 #endif /* HAVE_X_WINDOWS */
3414 SAFE_FREE ();
3418 /* Insert a description of internally-recorded parameters of frame X
3419 into the parameter alist *ALISTPTR that is to be given to the user.
3420 Only parameters that are specific to the X window system
3421 and whose values are not correctly recorded in the frame's
3422 param_alist need to be considered here. */
3424 void
3425 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3427 Lisp_Object tem;
3428 uprintmax_t w;
3429 char buf[INT_BUFSIZE_BOUND (w)];
3431 /* Represent negative positions (off the top or left screen edge)
3432 in a way that Fmodify_frame_parameters will understand correctly. */
3433 XSETINT (tem, f->left_pos);
3434 if (f->left_pos >= 0)
3435 store_in_alist (alistptr, Qleft, tem);
3436 else
3437 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3439 XSETINT (tem, f->top_pos);
3440 if (f->top_pos >= 0)
3441 store_in_alist (alistptr, Qtop, tem);
3442 else
3443 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3445 store_in_alist (alistptr, Qborder_width,
3446 make_number (f->border_width));
3447 store_in_alist (alistptr, Qinternal_border_width,
3448 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3449 store_in_alist (alistptr, Qright_divider_width,
3450 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3451 store_in_alist (alistptr, Qbottom_divider_width,
3452 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3453 store_in_alist (alistptr, Qleft_fringe,
3454 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3455 store_in_alist (alistptr, Qright_fringe,
3456 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3457 store_in_alist (alistptr, Qscroll_bar_width,
3458 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3459 ? make_number (0)
3460 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3461 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3462 /* nil means "use default width"
3463 for non-toolkit scroll bar.
3464 ruler-mode.el depends on this. */
3465 : Qnil));
3466 store_in_alist (alistptr, Qscroll_bar_height,
3467 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3468 ? make_number (0)
3469 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3470 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3471 /* nil means "use default height"
3472 for non-toolkit scroll bar. */
3473 : Qnil));
3474 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3475 MS-Windows it returns a value whose type is HANDLE, which is
3476 actually a pointer. Explicit casting avoids compiler
3477 warnings. */
3478 w = (uintptr_t) FRAME_X_WINDOW (f);
3479 store_in_alist (alistptr, Qwindow_id,
3480 make_formatted_string (buf, "%"pMu, w));
3481 #ifdef HAVE_X_WINDOWS
3482 #ifdef USE_X_TOOLKIT
3483 /* Tooltip frame may not have this widget. */
3484 if (FRAME_X_OUTPUT (f)->widget)
3485 #endif
3486 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3487 store_in_alist (alistptr, Qouter_window_id,
3488 make_formatted_string (buf, "%"pMu, w));
3489 #endif
3490 store_in_alist (alistptr, Qicon_name, f->icon_name);
3491 store_in_alist (alistptr, Qvisibility,
3492 (FRAME_VISIBLE_P (f) ? Qt
3493 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3494 store_in_alist (alistptr, Qdisplay,
3495 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3497 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3498 tem = Qnil;
3499 else
3500 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3501 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3502 store_in_alist (alistptr, Qparent_id, tem);
3503 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3507 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3508 the previous value of that parameter, NEW_VALUE is the new value. */
3510 void
3511 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3513 if (NILP (new_value))
3514 f->want_fullscreen = FULLSCREEN_NONE;
3515 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3516 f->want_fullscreen = FULLSCREEN_BOTH;
3517 else if (EQ (new_value, Qfullwidth))
3518 f->want_fullscreen = FULLSCREEN_WIDTH;
3519 else if (EQ (new_value, Qfullheight))
3520 f->want_fullscreen = FULLSCREEN_HEIGHT;
3521 else if (EQ (new_value, Qmaximized))
3522 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3524 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3525 FRAME_TERMINAL (f)->fullscreen_hook (f);
3529 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3530 the previous value of that parameter, NEW_VALUE is the new value. */
3532 void
3533 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3535 if (NILP (new_value))
3536 f->extra_line_spacing = 0;
3537 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3538 f->extra_line_spacing = XFASTINT (new_value);
3539 else if (FLOATP (new_value))
3541 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3543 if (new_spacing >= 0)
3544 f->extra_line_spacing = new_spacing;
3545 else
3546 signal_error ("Invalid line-spacing", new_value);
3548 else
3549 signal_error ("Invalid line-spacing", new_value);
3550 if (FRAME_VISIBLE_P (f))
3551 redraw_frame (f);
3555 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3556 the previous value of that parameter, NEW_VALUE is the new value. */
3558 void
3559 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3561 Lisp_Object bgcolor;
3563 if (NILP (new_value))
3564 f->gamma = 0;
3565 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3566 /* The value 0.4545 is the normal viewing gamma. */
3567 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3568 else
3569 signal_error ("Invalid screen-gamma", new_value);
3571 /* Apply the new gamma value to the frame background. */
3572 bgcolor = Fassq (Qbackground_color, f->param_alist);
3573 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3575 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3576 if (NATNUMP (parm_index)
3577 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3578 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3579 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3580 (f, bgcolor, Qnil);
3583 clear_face_cache (true); /* FIXME: Why of all frames? */
3584 fset_redisplay (f);
3588 void
3589 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3591 Lisp_Object font_object;
3592 int fontset = -1;
3593 #ifdef HAVE_X_WINDOWS
3594 Lisp_Object font_param = arg;
3595 #endif
3597 /* Set the frame parameter back to the old value because we may
3598 fail to use ARG as the new parameter value. */
3599 store_frame_param (f, Qfont, oldval);
3601 /* ARG is a fontset name, a font name, a cons of fontset name and a
3602 font object, or a font object. In the last case, this function
3603 never fail. */
3604 if (STRINGP (arg))
3606 fontset = fs_query_fontset (arg, 0);
3607 if (fontset < 0)
3609 font_object = font_open_by_name (f, arg);
3610 if (NILP (font_object))
3611 error ("Font `%s' is not defined", SSDATA (arg));
3612 arg = AREF (font_object, FONT_NAME_INDEX);
3614 else if (fontset > 0)
3616 font_object = font_open_by_name (f, fontset_ascii (fontset));
3617 if (NILP (font_object))
3618 error ("Font `%s' is not defined", SDATA (arg));
3619 arg = AREF (font_object, FONT_NAME_INDEX);
3621 else
3622 error ("The default fontset can't be used for a frame font");
3624 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3626 /* This is the case that the ASCII font of F's fontset XCAR
3627 (arg) is changed to the font XCDR (arg) by
3628 `set-fontset-font'. */
3629 fontset = fs_query_fontset (XCAR (arg), 0);
3630 if (fontset < 0)
3631 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3632 font_object = XCDR (arg);
3633 arg = AREF (font_object, FONT_NAME_INDEX);
3634 #ifdef HAVE_X_WINDOWS
3635 font_param = Ffont_get (font_object, QCname);
3636 #endif
3638 else if (FONT_OBJECT_P (arg))
3640 font_object = arg;
3641 #ifdef HAVE_X_WINDOWS
3642 font_param = Ffont_get (font_object, QCname);
3643 #endif
3644 /* This is to store the XLFD font name in the frame parameter for
3645 backward compatibility. We should store the font-object
3646 itself in the future. */
3647 arg = AREF (font_object, FONT_NAME_INDEX);
3648 fontset = FRAME_FONTSET (f);
3649 /* Check if we can use the current fontset. If not, set FONTSET
3650 to -1 to generate a new fontset from FONT-OBJECT. */
3651 if (fontset >= 0)
3653 Lisp_Object ascii_font = fontset_ascii (fontset);
3654 Lisp_Object spec = font_spec_from_name (ascii_font);
3656 /* SPEC might be nil because ASCII_FONT's name doesn't parse
3657 according to stupid XLFD rules, which, for example,
3658 disallow font names that include a dash followed by a
3659 number. So in those cases we simply request x_new_font
3660 below to generate a new fontset. */
3661 if (NILP (spec) || ! font_match_p (spec, font_object))
3662 fontset = -1;
3665 else
3666 signal_error ("Invalid font", arg);
3668 if (! NILP (Fequal (font_object, oldval)))
3669 return;
3671 x_new_font (f, font_object, fontset);
3672 store_frame_param (f, Qfont, arg);
3673 #ifdef HAVE_X_WINDOWS
3674 store_frame_param (f, Qfont_parameter, font_param);
3675 #endif
3676 /* Recalculate toolbar height. */
3677 f->n_tool_bar_rows = 0;
3679 /* Ensure we redraw it. */
3680 clear_current_matrices (f);
3682 /* Attempt to hunt down bug#16028. */
3683 SET_FRAME_GARBAGED (f);
3685 /* This is important if we are called by some Lisp as part of
3686 redisplaying the frame, see redisplay_internal. */
3687 f->fonts_changed = true;
3689 recompute_basic_faces (f);
3691 do_pending_window_change (0);
3693 /* We used to call face-set-after-frame-default here, but it leads to
3694 recursive calls (since that function can set the `default' face's
3695 font which in turns changes the frame's `font' parameter).
3696 Also I don't know what this call is meant to do, but it seems the
3697 wrong way to do it anyway (it does a lot more work than what seems
3698 reasonable in response to a change to `font'). */
3702 void
3703 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3705 if (! NILP (new_value)
3706 && !CONSP (new_value))
3708 char *p0, *p1;
3710 CHECK_STRING (new_value);
3711 p0 = p1 = SSDATA (new_value);
3712 new_value = Qnil;
3713 while (*p0)
3715 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3716 if (p0 < p1)
3717 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3718 new_value);
3719 if (*p1)
3721 int c;
3723 while ((c = *++p1) && c_isspace (c));
3725 p0 = p1;
3727 new_value = Fnreverse (new_value);
3730 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3731 return;
3733 if (FRAME_FONT (f))
3734 free_all_realized_faces (Qnil);
3736 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3737 if (NILP (new_value))
3739 if (NILP (old_value))
3740 error ("No font backend available");
3741 font_update_drivers (f, old_value);
3742 error ("None of specified font backends are available");
3744 store_frame_param (f, Qfont_backend, new_value);
3746 if (FRAME_FONT (f))
3748 Lisp_Object frame;
3750 XSETFRAME (frame, f);
3751 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3752 face_change = true;
3753 windows_or_buffers_changed = 18;
3757 void
3758 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3760 int unit = FRAME_COLUMN_WIDTH (f);
3761 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3762 int new_width;
3764 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3765 ? eabs (XINT (new_value)) : 8);
3767 if (new_width != old_width)
3769 f->left_fringe_width = new_width;
3770 f->fringe_cols /* Round up. */
3771 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3773 if (FRAME_X_WINDOW (f) != 0)
3774 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
3776 SET_FRAME_GARBAGED (f);
3781 void
3782 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3784 int unit = FRAME_COLUMN_WIDTH (f);
3785 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3786 int new_width;
3788 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3789 ? eabs (XINT (new_value)) : 8);
3791 if (new_width != old_width)
3793 f->right_fringe_width = new_width;
3794 f->fringe_cols /* Round up. */
3795 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3797 if (FRAME_X_WINDOW (f) != 0)
3798 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
3800 SET_FRAME_GARBAGED (f);
3805 void
3806 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3808 CHECK_TYPE_RANGED_INTEGER (int, arg);
3810 if (XINT (arg) == f->border_width)
3811 return;
3813 if (FRAME_X_WINDOW (f) != 0)
3814 error ("Cannot change the border width of a frame");
3816 f->border_width = XINT (arg);
3819 void
3820 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3822 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3823 CHECK_TYPE_RANGED_INTEGER (int, arg);
3824 int new = max (0, XINT (arg));
3825 if (new != old)
3827 f->right_divider_width = new;
3828 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
3829 adjust_frame_glyphs (f);
3830 SET_FRAME_GARBAGED (f);
3835 void
3836 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3838 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3839 CHECK_TYPE_RANGED_INTEGER (int, arg);
3840 int new = max (0, XINT (arg));
3841 if (new != old)
3843 f->bottom_divider_width = new;
3844 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
3845 adjust_frame_glyphs (f);
3846 SET_FRAME_GARBAGED (f);
3850 void
3851 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3853 Lisp_Object frame;
3854 XSETFRAME (frame, f);
3856 if (NILP (value))
3857 Fmake_frame_invisible (frame, Qt);
3858 else if (EQ (value, Qicon))
3859 Ficonify_frame (frame);
3860 else
3861 Fmake_frame_visible (frame);
3864 void
3865 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3867 f->auto_raise = !EQ (Qnil, arg);
3870 void
3871 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3873 f->auto_lower = !EQ (Qnil, arg);
3876 void
3877 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3879 f->no_split = !NILP (arg);
3882 void
3883 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3885 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3886 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3887 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3888 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3890 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3891 = (NILP (arg)
3892 ? vertical_scroll_bar_none
3893 : EQ (Qleft, arg)
3894 ? vertical_scroll_bar_left
3895 : EQ (Qright, arg)
3896 ? vertical_scroll_bar_right
3897 : EQ (Qleft, Vdefault_frame_scroll_bars)
3898 ? vertical_scroll_bar_left
3899 : EQ (Qright, Vdefault_frame_scroll_bars)
3900 ? vertical_scroll_bar_right
3901 : vertical_scroll_bar_none);
3903 /* We set this parameter before creating the X window for the
3904 frame, so we can get the geometry right from the start.
3905 However, if the window hasn't been created yet, we shouldn't
3906 call x_set_window_size. */
3907 if (FRAME_X_WINDOW (f))
3908 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
3910 SET_FRAME_GARBAGED (f);
3914 void
3915 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3917 #if USE_HORIZONTAL_SCROLL_BARS
3918 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3919 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3921 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3923 /* We set this parameter before creating the X window for the
3924 frame, so we can get the geometry right from the start.
3925 However, if the window hasn't been created yet, we shouldn't
3926 call x_set_window_size. */
3927 if (FRAME_X_WINDOW (f))
3928 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
3930 SET_FRAME_GARBAGED (f);
3932 #endif
3935 void
3936 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3938 int unit = FRAME_COLUMN_WIDTH (f);
3940 if (NILP (arg))
3942 x_set_scroll_bar_default_width (f);
3944 if (FRAME_X_WINDOW (f))
3945 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3947 SET_FRAME_GARBAGED (f);
3949 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3950 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3952 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3953 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3954 if (FRAME_X_WINDOW (f))
3955 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3957 SET_FRAME_GARBAGED (f);
3960 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3961 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3964 void
3965 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3967 #if USE_HORIZONTAL_SCROLL_BARS
3968 int unit = FRAME_LINE_HEIGHT (f);
3970 if (NILP (arg))
3972 x_set_scroll_bar_default_height (f);
3974 if (FRAME_X_WINDOW (f))
3975 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3977 SET_FRAME_GARBAGED (f);
3979 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3980 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3982 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3983 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3984 if (FRAME_X_WINDOW (f))
3985 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3987 SET_FRAME_GARBAGED (f);
3990 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3991 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3992 #endif
3995 void
3996 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3998 double alpha = 1.0;
3999 double newval[2];
4000 int i;
4001 Lisp_Object item;
4003 for (i = 0; i < 2; i++)
4005 newval[i] = 1.0;
4006 if (CONSP (arg))
4008 item = CAR (arg);
4009 arg = CDR (arg);
4011 else
4012 item = arg;
4014 if (NILP (item))
4015 alpha = - 1.0;
4016 else if (FLOATP (item))
4018 alpha = XFLOAT_DATA (item);
4019 if (! (0 <= alpha && alpha <= 1.0))
4020 args_out_of_range (make_float (0.0), make_float (1.0));
4022 else if (INTEGERP (item))
4024 EMACS_INT ialpha = XINT (item);
4025 if (! (0 <= ialpha && alpha <= 100))
4026 args_out_of_range (make_number (0), make_number (100));
4027 alpha = ialpha / 100.0;
4029 else
4030 wrong_type_argument (Qnumberp, item);
4031 newval[i] = alpha;
4034 for (i = 0; i < 2; i++)
4035 f->alpha[i] = newval[i];
4037 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4038 block_input ();
4039 x_set_frame_alpha (f);
4040 unblock_input ();
4041 #endif
4043 return;
4046 #ifndef HAVE_NS
4048 /* Non-zero if mouse is grabbed on DPYINFO
4049 and we know the frame where it is. */
4051 bool x_mouse_grabbed (Display_Info *dpyinfo)
4053 return (dpyinfo->grabbed
4054 && dpyinfo->last_mouse_frame
4055 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4058 /* Re-highlight something with mouse-face properties
4059 on DPYINFO using saved frame and mouse position. */
4061 void
4062 x_redo_mouse_highlight (Display_Info *dpyinfo)
4064 if (dpyinfo->last_mouse_motion_frame
4065 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4066 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4067 dpyinfo->last_mouse_motion_x,
4068 dpyinfo->last_mouse_motion_y);
4071 #endif /* HAVE_NS */
4073 /* Subroutines of creating an X frame. */
4075 /* Make sure that Vx_resource_name is set to a reasonable value.
4076 Fix it up, or set it to `emacs' if it is too hopeless. */
4078 void
4079 validate_x_resource_name (void)
4081 ptrdiff_t len = 0;
4082 /* Number of valid characters in the resource name. */
4083 ptrdiff_t good_count = 0;
4084 /* Number of invalid characters in the resource name. */
4085 ptrdiff_t bad_count = 0;
4086 Lisp_Object new;
4087 ptrdiff_t i;
4089 if (!STRINGP (Vx_resource_class))
4090 Vx_resource_class = build_string (EMACS_CLASS);
4092 if (STRINGP (Vx_resource_name))
4094 unsigned char *p = SDATA (Vx_resource_name);
4096 len = SBYTES (Vx_resource_name);
4098 /* Only letters, digits, - and _ are valid in resource names.
4099 Count the valid characters and count the invalid ones. */
4100 for (i = 0; i < len; i++)
4102 int c = p[i];
4103 if (! ((c >= 'a' && c <= 'z')
4104 || (c >= 'A' && c <= 'Z')
4105 || (c >= '0' && c <= '9')
4106 || c == '-' || c == '_'))
4107 bad_count++;
4108 else
4109 good_count++;
4112 else
4113 /* Not a string => completely invalid. */
4114 bad_count = 5, good_count = 0;
4116 /* If name is valid already, return. */
4117 if (bad_count == 0)
4118 return;
4120 /* If name is entirely invalid, or nearly so, or is so implausibly
4121 large that alloca might not work, use `emacs'. */
4122 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4124 Vx_resource_name = build_string ("emacs");
4125 return;
4128 /* Name is partly valid. Copy it and replace the invalid characters
4129 with underscores. */
4131 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4133 for (i = 0; i < len; i++)
4135 int c = SREF (new, i);
4136 if (! ((c >= 'a' && c <= 'z')
4137 || (c >= 'A' && c <= 'Z')
4138 || (c >= '0' && c <= '9')
4139 || c == '-' || c == '_'))
4140 SSET (new, i, '_');
4144 /* Get specified attribute from resource database RDB.
4145 See Fx_get_resource below for other parameters. */
4147 static Lisp_Object
4148 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4150 CHECK_STRING (attribute);
4151 CHECK_STRING (class);
4153 if (!NILP (component))
4154 CHECK_STRING (component);
4155 if (!NILP (subclass))
4156 CHECK_STRING (subclass);
4157 if (NILP (component) != NILP (subclass))
4158 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4160 validate_x_resource_name ();
4162 /* Allocate space for the components, the dots which separate them,
4163 and the final '\0'. Make them big enough for the worst case. */
4164 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4165 + (STRINGP (component)
4166 ? SBYTES (component) : 0)
4167 + SBYTES (attribute)
4168 + 3);
4170 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4171 + SBYTES (class)
4172 + (STRINGP (subclass)
4173 ? SBYTES (subclass) : 0)
4174 + 3);
4175 USE_SAFE_ALLOCA;
4176 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4177 char *class_key = name_key + name_keysize;
4179 /* Start with emacs.FRAMENAME for the name (the specific one)
4180 and with `Emacs' for the class key (the general one). */
4181 char *nz = lispstpcpy (name_key, Vx_resource_name);
4182 char *cz = lispstpcpy (class_key, Vx_resource_class);
4184 *cz++ = '.';
4185 cz = lispstpcpy (cz, class);
4187 if (!NILP (component))
4189 *cz++ = '.';
4190 lispstpcpy (cz, subclass);
4192 *nz++ = '.';
4193 nz = lispstpcpy (nz, component);
4196 *nz++ = '.';
4197 lispstpcpy (nz, attribute);
4199 char *value = x_get_string_resource (rdb, name_key, class_key);
4200 SAFE_FREE();
4202 if (value && *value)
4203 return build_string (value);
4204 else
4205 return Qnil;
4209 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4210 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4211 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4212 class, where INSTANCE is the name under which Emacs was invoked, or
4213 the name specified by the `-name' or `-rn' command-line arguments.
4215 The optional arguments COMPONENT and SUBCLASS add to the key and the
4216 class, respectively. You must specify both of them or neither.
4217 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4218 and the class is `Emacs.CLASS.SUBCLASS'. */)
4219 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4220 Lisp_Object subclass)
4222 check_window_system (NULL);
4224 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4225 attribute, class, component, subclass);
4228 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4230 Lisp_Object
4231 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4232 Lisp_Object class, Lisp_Object component,
4233 Lisp_Object subclass)
4235 return xrdb_get_resource (dpyinfo->xrdb,
4236 attribute, class, component, subclass);
4239 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4240 /* Used when C code wants a resource value. */
4241 /* Called from oldXMenu/Create.c. */
4242 char *
4243 x_get_resource_string (const char *attribute, const char *class)
4245 char *result;
4246 struct frame *sf = SELECTED_FRAME ();
4247 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4248 USE_SAFE_ALLOCA;
4250 /* Allocate space for the components, the dots which separate them,
4251 and the final '\0'. */
4252 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4253 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4254 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4255 char *class_key = name_key + name_keysize;
4257 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4258 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4260 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4261 name_key, class_key);
4262 SAFE_FREE ();
4263 return result;
4265 #endif
4267 /* Return the value of parameter PARAM.
4269 First search ALIST, then Vdefault_frame_alist, then the X defaults
4270 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4272 Convert the resource to the type specified by desired_type.
4274 If no default is specified, return Qunbound. If you call
4275 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4276 and don't let it get stored in any Lisp-visible variables! */
4278 Lisp_Object
4279 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4280 const char *attribute, const char *class, enum resource_types type)
4282 Lisp_Object tem;
4284 tem = Fassq (param, alist);
4286 if (!NILP (tem))
4288 /* If we find this parm in ALIST, clear it out
4289 so that it won't be "left over" at the end. */
4290 Lisp_Object tail;
4291 XSETCAR (tem, Qnil);
4292 /* In case the parameter appears more than once in the alist,
4293 clear it out. */
4294 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4295 if (CONSP (XCAR (tail))
4296 && EQ (XCAR (XCAR (tail)), param))
4297 XSETCAR (XCAR (tail), Qnil);
4299 else
4300 tem = Fassq (param, Vdefault_frame_alist);
4302 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4303 look in the X resources. */
4304 if (EQ (tem, Qnil))
4306 if (attribute && dpyinfo)
4308 AUTO_STRING (at, attribute);
4309 AUTO_STRING (cl, class);
4310 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4312 if (NILP (tem))
4313 return Qunbound;
4315 switch (type)
4317 case RES_TYPE_NUMBER:
4318 return make_number (atoi (SSDATA (tem)));
4320 case RES_TYPE_BOOLEAN_NUMBER:
4321 if (!strcmp (SSDATA (tem), "on")
4322 || !strcmp (SSDATA (tem), "true"))
4323 return make_number (1);
4324 return make_number (atoi (SSDATA (tem)));
4325 break;
4327 case RES_TYPE_FLOAT:
4328 return make_float (atof (SSDATA (tem)));
4330 case RES_TYPE_BOOLEAN:
4331 tem = Fdowncase (tem);
4332 if (!strcmp (SSDATA (tem), "on")
4333 #ifdef HAVE_NS
4334 || !strcmp (SSDATA (tem), "yes")
4335 #endif
4336 || !strcmp (SSDATA (tem), "true"))
4337 return Qt;
4338 else
4339 return Qnil;
4341 case RES_TYPE_STRING:
4342 return tem;
4344 case RES_TYPE_SYMBOL:
4345 /* As a special case, we map the values `true' and `on'
4346 to Qt, and `false' and `off' to Qnil. */
4348 Lisp_Object lower;
4349 lower = Fdowncase (tem);
4350 if (!strcmp (SSDATA (lower), "on")
4351 #ifdef HAVE_NS
4352 || !strcmp (SSDATA (lower), "yes")
4353 #endif
4354 || !strcmp (SSDATA (lower), "true"))
4355 return Qt;
4356 else if (!strcmp (SSDATA (lower), "off")
4357 #ifdef HAVE_NS
4358 || !strcmp (SSDATA (lower), "no")
4359 #endif
4360 || !strcmp (SSDATA (lower), "false"))
4361 return Qnil;
4362 else
4363 return Fintern (tem, Qnil);
4366 default:
4367 emacs_abort ();
4370 else
4371 return Qunbound;
4373 return Fcdr (tem);
4376 static Lisp_Object
4377 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4378 const char *attribute, const char *class,
4379 enum resource_types type)
4381 return x_get_arg (FRAME_DISPLAY_INFO (f),
4382 alist, param, attribute, class, type);
4385 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4387 Lisp_Object
4388 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4389 Lisp_Object param,
4390 const char *attribute, const char *class,
4391 enum resource_types type)
4393 Lisp_Object value;
4395 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4396 attribute, class, type);
4397 if (! NILP (value) && ! EQ (value, Qunbound))
4398 store_frame_param (f, param, value);
4400 return value;
4404 /* Record in frame F the specified or default value according to ALIST
4405 of the parameter named PROP (a Lisp symbol).
4406 If no value is specified for PROP, look for an X default for XPROP
4407 on the frame named NAME.
4408 If that is not found either, use the value DEFLT. */
4410 Lisp_Object
4411 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4412 Lisp_Object deflt, const char *xprop, const char *xclass,
4413 enum resource_types type)
4415 Lisp_Object tem;
4417 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4418 if (EQ (tem, Qunbound))
4419 tem = deflt;
4420 AUTO_FRAME_ARG (arg, prop, tem);
4421 x_set_frame_parameters (f, arg);
4422 return tem;
4426 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4429 * XParseGeometry parses strings of the form
4430 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4431 * width, height, xoffset, and yoffset are unsigned integers.
4432 * Example: "=80x24+300-49"
4433 * The equal sign is optional.
4434 * It returns a bitmask that indicates which of the four values
4435 * were actually found in the string. For each value found,
4436 * the corresponding argument is updated; for each value
4437 * not found, the corresponding argument is left unchanged.
4440 static int
4441 XParseGeometry (char *string,
4442 int *x, int *y,
4443 unsigned int *width, unsigned int *height)
4445 int mask = NoValue;
4446 char *strind;
4447 unsigned long tempWidth UNINIT, tempHeight UNINIT;
4448 long int tempX UNINIT, tempY UNINIT;
4449 char *nextCharacter;
4451 if (string == NULL || *string == '\0')
4452 return mask;
4453 if (*string == '=')
4454 string++; /* ignore possible '=' at beg of geometry spec */
4456 strind = string;
4457 if (*strind != '+' && *strind != '-' && *strind != 'x')
4459 tempWidth = strtoul (strind, &nextCharacter, 10);
4460 if (strind == nextCharacter)
4461 return 0;
4462 strind = nextCharacter;
4463 mask |= WidthValue;
4466 if (*strind == 'x' || *strind == 'X')
4468 strind++;
4469 tempHeight = strtoul (strind, &nextCharacter, 10);
4470 if (strind == nextCharacter)
4471 return 0;
4472 strind = nextCharacter;
4473 mask |= HeightValue;
4476 if (*strind == '+' || *strind == '-')
4478 if (*strind == '-')
4479 mask |= XNegative;
4480 tempX = strtol (strind, &nextCharacter, 10);
4481 if (strind == nextCharacter)
4482 return 0;
4483 strind = nextCharacter;
4484 mask |= XValue;
4485 if (*strind == '+' || *strind == '-')
4487 if (*strind == '-')
4488 mask |= YNegative;
4489 tempY = strtol (strind, &nextCharacter, 10);
4490 if (strind == nextCharacter)
4491 return 0;
4492 strind = nextCharacter;
4493 mask |= YValue;
4497 /* If strind isn't at the end of the string then it's an invalid
4498 geometry specification. */
4500 if (*strind != '\0')
4501 return 0;
4503 if (mask & XValue)
4504 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4505 if (mask & YValue)
4506 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4507 if (mask & WidthValue)
4508 *width = min (tempWidth, UINT_MAX);
4509 if (mask & HeightValue)
4510 *height = min (tempHeight, UINT_MAX);
4511 return mask;
4514 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4517 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4518 make-docfile: the documentation string in ns-win.el was used for
4519 x-parse-geometry even in non-NS builds.
4521 With two definitions of x-parse-geometry in this file, various
4522 things still get confused (eg M-x apropos documentation), so that
4523 it is best if the two definitions just share the same doc-string.
4525 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4526 doc: /* Parse a display geometry string STRING.
4527 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4528 The properties returned may include `top', `left', `height', and `width'.
4529 For X, the value of `left' or `top' may be an integer,
4530 or a list (+ N) meaning N pixels relative to top/left corner,
4531 or a list (- N) meaning -N pixels relative to bottom/right corner.
4532 On Nextstep, this just calls `ns-parse-geometry'. */)
4533 (Lisp_Object string)
4535 int geometry, x, y;
4536 unsigned int width, height;
4537 Lisp_Object result;
4539 CHECK_STRING (string);
4541 #ifdef HAVE_NS
4542 if (strchr (SSDATA (string), ' ') != NULL)
4543 return call1 (Qns_parse_geometry, string);
4544 #endif
4545 geometry = XParseGeometry (SSDATA (string),
4546 &x, &y, &width, &height);
4547 result = Qnil;
4548 if (geometry & XValue)
4550 Lisp_Object element;
4552 if (x >= 0 && (geometry & XNegative))
4553 element = list3 (Qleft, Qminus, make_number (-x));
4554 else if (x < 0 && ! (geometry & XNegative))
4555 element = list3 (Qleft, Qplus, make_number (x));
4556 else
4557 element = Fcons (Qleft, make_number (x));
4558 result = Fcons (element, result);
4561 if (geometry & YValue)
4563 Lisp_Object element;
4565 if (y >= 0 && (geometry & YNegative))
4566 element = list3 (Qtop, Qminus, make_number (-y));
4567 else if (y < 0 && ! (geometry & YNegative))
4568 element = list3 (Qtop, Qplus, make_number (y));
4569 else
4570 element = Fcons (Qtop, make_number (y));
4571 result = Fcons (element, result);
4574 if (geometry & WidthValue)
4575 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4576 if (geometry & HeightValue)
4577 result = Fcons (Fcons (Qheight, make_number (height)), result);
4579 return result;
4583 /* Calculate the desired size and position of frame F.
4584 Return the flags saying which aspects were specified.
4586 Also set the win_gravity and size_hint_flags of F.
4588 Adjust height for toolbar if TOOLBAR_P is 1.
4590 This function does not make the coordinates positive. */
4592 #define DEFAULT_ROWS 36
4593 #define DEFAULT_COLS 80
4595 long
4596 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
4598 Lisp_Object height, width, user_size, top, left, user_position;
4599 long window_prompting = 0;
4600 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4602 /* Default values if we fall through.
4603 Actually, if that happens we should get
4604 window manager prompting. */
4605 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4606 SET_FRAME_COLS (f, DEFAULT_COLS);
4607 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4608 SET_FRAME_LINES (f, DEFAULT_ROWS);
4610 /* Window managers expect that if program-specified
4611 positions are not (0,0), they're intentional, not defaults. */
4612 f->top_pos = 0;
4613 f->left_pos = 0;
4615 /* Calculate a tool bar height so that the user gets a text display
4616 area of the size he specified with -g or via .Xdefaults. Later
4617 changes of the tool bar height don't change the frame size. This
4618 is done so that users can create tall Emacs frames without having
4619 to guess how tall the tool bar will get. */
4620 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4622 if (frame_default_tool_bar_height)
4623 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
4624 else
4626 int margin, relief;
4628 relief = (tool_bar_button_relief >= 0
4629 ? tool_bar_button_relief
4630 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4632 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4633 margin = XFASTINT (Vtool_bar_button_margin);
4634 else if (CONSP (Vtool_bar_button_margin)
4635 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4636 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4637 else
4638 margin = 0;
4640 FRAME_TOOL_BAR_HEIGHT (f)
4641 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4645 /* Ensure that earlier new_width and new_height settings won't
4646 override what we specify below. */
4647 f->new_width = f->new_height = 0;
4649 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4650 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4651 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4653 if (!EQ (width, Qunbound))
4655 if (CONSP (width) && EQ (XCAR (width), Qtext_pixels))
4657 CHECK_NUMBER (XCDR (width));
4658 if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX))
4659 xsignal1 (Qargs_out_of_range, XCDR (width));
4661 SET_FRAME_WIDTH (f, XINT (XCDR (width)));
4662 f->inhibit_horizontal_resize = true;
4663 *x_width = XINT (XCDR (width));
4665 else
4667 CHECK_NUMBER (width);
4668 if ((XINT (width) < 0 || XINT (width) > INT_MAX))
4669 xsignal1 (Qargs_out_of_range, width);
4671 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4675 if (!EQ (height, Qunbound))
4677 if (CONSP (height) && EQ (XCAR (height), Qtext_pixels))
4679 CHECK_NUMBER (XCDR (height));
4680 if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX))
4681 xsignal1 (Qargs_out_of_range, XCDR (height));
4683 SET_FRAME_HEIGHT (f, XINT (XCDR (height)));
4684 f->inhibit_vertical_resize = true;
4685 *x_height = XINT (XCDR (height));
4687 else
4689 CHECK_NUMBER (height);
4690 if ((XINT (height) < 0) || (XINT (height) > INT_MAX))
4691 xsignal1 (Qargs_out_of_range, height);
4693 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4697 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4698 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4699 window_prompting |= USSize;
4700 else
4701 window_prompting |= PSize;
4704 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4705 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4706 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4707 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4709 if (EQ (top, Qminus))
4711 f->top_pos = 0;
4712 window_prompting |= YNegative;
4714 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4715 && CONSP (XCDR (top))
4716 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4718 f->top_pos = - XINT (XCAR (XCDR (top)));
4719 window_prompting |= YNegative;
4721 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4722 && CONSP (XCDR (top))
4723 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4725 f->top_pos = XINT (XCAR (XCDR (top)));
4727 else if (EQ (top, Qunbound))
4728 f->top_pos = 0;
4729 else
4731 CHECK_TYPE_RANGED_INTEGER (int, top);
4732 f->top_pos = XINT (top);
4733 if (f->top_pos < 0)
4734 window_prompting |= YNegative;
4737 if (EQ (left, Qminus))
4739 f->left_pos = 0;
4740 window_prompting |= XNegative;
4742 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4743 && CONSP (XCDR (left))
4744 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4746 f->left_pos = - XINT (XCAR (XCDR (left)));
4747 window_prompting |= XNegative;
4749 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4750 && CONSP (XCDR (left))
4751 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4753 f->left_pos = XINT (XCAR (XCDR (left)));
4755 else if (EQ (left, Qunbound))
4756 f->left_pos = 0;
4757 else
4759 CHECK_TYPE_RANGED_INTEGER (int, left);
4760 f->left_pos = XINT (left);
4761 if (f->left_pos < 0)
4762 window_prompting |= XNegative;
4765 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4766 window_prompting |= USPosition;
4767 else
4768 window_prompting |= PPosition;
4771 if (window_prompting & XNegative)
4773 if (window_prompting & YNegative)
4774 f->win_gravity = SouthEastGravity;
4775 else
4776 f->win_gravity = NorthEastGravity;
4778 else
4780 if (window_prompting & YNegative)
4781 f->win_gravity = SouthWestGravity;
4782 else
4783 f->win_gravity = NorthWestGravity;
4786 f->size_hint_flags = window_prompting;
4788 return window_prompting;
4793 #endif /* HAVE_WINDOW_SYSTEM */
4795 void
4796 frame_make_pointer_invisible (struct frame *f)
4798 if (! NILP (Vmake_pointer_invisible))
4800 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4801 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4803 f->mouse_moved = 0;
4804 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4805 f->pointer_invisible = 1;
4810 void
4811 frame_make_pointer_visible (struct frame *f)
4813 /* We don't check Vmake_pointer_invisible here in case the
4814 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4815 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4816 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4818 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4819 f->pointer_invisible = 0;
4823 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4824 Sframe_pointer_visible_p, 0, 1, 0,
4825 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4826 Otherwise it returns nil. FRAME omitted or nil means the
4827 selected frame. This is useful when `make-pointer-invisible' is set. */)
4828 (Lisp_Object frame)
4830 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4835 /***********************************************************************
4836 Multimonitor data
4837 ***********************************************************************/
4839 #ifdef HAVE_WINDOW_SYSTEM
4841 # if (defined HAVE_NS \
4842 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4843 void
4844 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4846 int i;
4847 for (i = 0; i < n_monitors; ++i)
4848 xfree (monitors[i].name);
4849 xfree (monitors);
4851 # endif
4853 Lisp_Object
4854 make_monitor_attribute_list (struct MonitorInfo *monitors,
4855 int n_monitors,
4856 int primary_monitor,
4857 Lisp_Object monitor_frames,
4858 const char *source)
4860 Lisp_Object attributes_list = Qnil;
4861 Lisp_Object primary_monitor_attributes = Qnil;
4862 int i;
4864 for (i = 0; i < n_monitors; ++i)
4866 Lisp_Object geometry, workarea, attributes = Qnil;
4867 struct MonitorInfo *mi = &monitors[i];
4869 if (mi->geom.width == 0) continue;
4871 workarea = list4i (mi->work.x, mi->work.y,
4872 mi->work.width, mi->work.height);
4873 geometry = list4i (mi->geom.x, mi->geom.y,
4874 mi->geom.width, mi->geom.height);
4875 attributes = Fcons (Fcons (Qsource, build_string (source)),
4876 attributes);
4877 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4878 attributes);
4879 attributes = Fcons (Fcons (Qmm_size,
4880 list2i (mi->mm_width, mi->mm_height)),
4881 attributes);
4882 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4883 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4884 if (mi->name)
4885 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4886 strlen (mi->name))),
4887 attributes);
4889 if (i == primary_monitor)
4890 primary_monitor_attributes = attributes;
4891 else
4892 attributes_list = Fcons (attributes, attributes_list);
4895 if (!NILP (primary_monitor_attributes))
4896 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4897 return attributes_list;
4900 #endif /* HAVE_WINDOW_SYSTEM */
4903 /***********************************************************************
4904 Initialization
4905 ***********************************************************************/
4907 void
4908 syms_of_frame (void)
4910 DEFSYM (Qframep, "framep");
4911 DEFSYM (Qframe_live_p, "frame-live-p");
4912 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4913 DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total");
4914 DEFSYM (Qexplicit_name, "explicit-name");
4915 DEFSYM (Qheight, "height");
4916 DEFSYM (Qicon, "icon");
4917 DEFSYM (Qminibuffer, "minibuffer");
4918 DEFSYM (Qmodeline, "modeline");
4919 DEFSYM (Qonly, "only");
4920 DEFSYM (Qnone, "none");
4921 DEFSYM (Qwidth, "width");
4922 DEFSYM (Qtext_pixels, "text-pixels");
4923 DEFSYM (Qgeometry, "geometry");
4924 DEFSYM (Qicon_left, "icon-left");
4925 DEFSYM (Qicon_top, "icon-top");
4926 DEFSYM (Qtooltip, "tooltip");
4927 DEFSYM (Quser_position, "user-position");
4928 DEFSYM (Quser_size, "user-size");
4929 DEFSYM (Qwindow_id, "window-id");
4930 #ifdef HAVE_X_WINDOWS
4931 DEFSYM (Qouter_window_id, "outer-window-id");
4932 #endif
4933 DEFSYM (Qparent_id, "parent-id");
4934 DEFSYM (Qx, "x");
4935 DEFSYM (Qw32, "w32");
4936 DEFSYM (Qpc, "pc");
4937 DEFSYM (Qns, "ns");
4938 DEFSYM (Qvisible, "visible");
4939 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4940 DEFSYM (Qbuffer_list, "buffer-list");
4941 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4942 DEFSYM (Qdisplay_type, "display-type");
4943 DEFSYM (Qbackground_mode, "background-mode");
4944 DEFSYM (Qnoelisp, "noelisp");
4945 DEFSYM (Qtty_color_mode, "tty-color-mode");
4946 DEFSYM (Qtty, "tty");
4947 DEFSYM (Qtty_type, "tty-type");
4949 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4951 DEFSYM (Qfullwidth, "fullwidth");
4952 DEFSYM (Qfullheight, "fullheight");
4953 DEFSYM (Qfullboth, "fullboth");
4954 DEFSYM (Qmaximized, "maximized");
4955 DEFSYM (Qx_resource_name, "x-resource-name");
4956 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4958 DEFSYM (Qterminal, "terminal");
4960 DEFSYM (Qworkarea, "workarea");
4961 DEFSYM (Qmm_size, "mm-size");
4962 DEFSYM (Qframes, "frames");
4963 DEFSYM (Qsource, "source");
4965 DEFSYM (Qouter_edges, "outer-edges");
4966 DEFSYM (Qouter_position, "outer-position");
4967 DEFSYM (Qouter_size, "outer-size");
4968 DEFSYM (Qnative_edges, "native-edges");
4969 DEFSYM (Qinner_edges, "inner-edges");
4970 DEFSYM (Qexternal_border_size, "external-border-size");
4971 DEFSYM (Qtitle_bar_size, "title-bar-size");
4972 DEFSYM (Qmenu_bar_external, "menu-bar-external");
4973 DEFSYM (Qmenu_bar_size, "menu-bar-size");
4974 DEFSYM (Qtool_bar_external, "tool-bar-external");
4975 DEFSYM (Qtool_bar_size, "tool-bar-size");
4976 /* The following are used for frame_size_history. */
4977 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
4978 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
4979 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
4980 DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
4981 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
4982 DEFSYM (Qset_frame_size, "set-frame-size");
4983 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
4984 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
4985 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
4986 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
4987 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
4988 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
4989 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
4990 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
4991 DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
4992 DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
4993 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
4994 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
4995 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
4996 DEFSYM (Qtb_size_cb, "tb-size-cb");
4997 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
4998 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
4999 DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines");
5000 DEFSYM (Qchange_frame_size, "change-frame-size");
5001 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
5002 DEFSYM (Qset_window_configuration, "set-window-configuration");
5003 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
5004 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
5005 DEFSYM (Qterminal_frame, "terminal-frame");
5007 #ifdef HAVE_NS
5008 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
5009 #endif
5011 DEFSYM (Qalpha, "alpha");
5012 DEFSYM (Qauto_lower, "auto-lower");
5013 DEFSYM (Qauto_raise, "auto-raise");
5014 DEFSYM (Qborder_color, "border-color");
5015 DEFSYM (Qborder_width, "border-width");
5016 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
5017 DEFSYM (Qcursor_color, "cursor-color");
5018 DEFSYM (Qcursor_type, "cursor-type");
5019 DEFSYM (Qfont_backend, "font-backend");
5020 DEFSYM (Qfullscreen, "fullscreen");
5021 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
5022 DEFSYM (Qicon_name, "icon-name");
5023 DEFSYM (Qicon_type, "icon-type");
5024 DEFSYM (Qinternal_border_width, "internal-border-width");
5025 DEFSYM (Qleft_fringe, "left-fringe");
5026 DEFSYM (Qline_spacing, "line-spacing");
5027 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
5028 DEFSYM (Qupdate_frame_menubar, "update-frame-menubar");
5029 DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1");
5030 DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2");
5031 DEFSYM (Qmouse_color, "mouse-color");
5032 DEFSYM (Qname, "name");
5033 DEFSYM (Qright_divider_width, "right-divider-width");
5034 DEFSYM (Qright_fringe, "right-fringe");
5035 DEFSYM (Qscreen_gamma, "screen-gamma");
5036 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
5037 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
5038 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
5039 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
5040 DEFSYM (Qsticky, "sticky");
5041 DEFSYM (Qtitle, "title");
5042 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
5043 DEFSYM (Qtool_bar_position, "tool-bar-position");
5044 DEFSYM (Qunsplittable, "unsplittable");
5045 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
5046 DEFSYM (Qvisibility, "visibility");
5047 DEFSYM (Qwait_for_wm, "wait-for-wm");
5048 DEFSYM (Qinhibit_double_buffering, "inhibit-double-buffering");
5051 int i;
5053 for (i = 0; i < ARRAYELTS (frame_parms); i++)
5055 Lisp_Object v = (frame_parms[i].sym < 0
5056 ? intern_c_string (frame_parms[i].name)
5057 : builtin_lisp_symbol (frame_parms[i].sym));
5058 Fput (v, Qx_frame_parameter, make_number (i));
5062 #ifdef HAVE_WINDOW_SYSTEM
5063 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
5064 doc: /* The name Emacs uses to look up X resources.
5065 `x-get-resource' uses this as the first component of the instance name
5066 when requesting resource values.
5067 Emacs initially sets `x-resource-name' to the name under which Emacs
5068 was invoked, or to the value specified with the `-name' or `-rn'
5069 switches, if present.
5071 It may be useful to bind this variable locally around a call
5072 to `x-get-resource'. See also the variable `x-resource-class'. */);
5073 Vx_resource_name = Qnil;
5075 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5076 doc: /* The class Emacs uses to look up X resources.
5077 `x-get-resource' uses this as the first component of the instance class
5078 when requesting resource values.
5080 Emacs initially sets `x-resource-class' to "Emacs".
5082 Setting this variable permanently is not a reasonable thing to do,
5083 but binding this variable locally around a call to `x-get-resource'
5084 is a reasonable practice. See also the variable `x-resource-name'. */);
5085 Vx_resource_class = build_string (EMACS_CLASS);
5087 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5088 doc: /* The lower limit of the frame opacity (alpha transparency).
5089 The value should range from 0 (invisible) to 100 (completely opaque).
5090 You can also use a floating number between 0.0 and 1.0. */);
5091 Vframe_alpha_lower_limit = make_number (20);
5092 #endif
5094 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5095 doc: /* Alist of default values for frame creation.
5096 These may be set in your init file, like this:
5097 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5098 These override values given in window system configuration data,
5099 including X Windows' defaults database.
5100 For values specific to the first Emacs frame, see `initial-frame-alist'.
5101 For window-system specific values, see `window-system-default-frame-alist'.
5102 For values specific to the separate minibuffer frame, see
5103 `minibuffer-frame-alist'.
5104 The `menu-bar-lines' element of the list controls whether new frames
5105 have menu bars; `menu-bar-mode' works by altering this element.
5106 Setting this variable does not affect existing frames, only new ones. */);
5107 Vdefault_frame_alist = Qnil;
5109 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5110 doc: /* Default position of vertical scroll bars on this window-system. */);
5111 #ifdef HAVE_WINDOW_SYSTEM
5112 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5113 /* MS-Windows, macOS, and GTK have scroll bars on the right by
5114 default. */
5115 Vdefault_frame_scroll_bars = Qright;
5116 #else
5117 Vdefault_frame_scroll_bars = Qleft;
5118 #endif
5119 #else
5120 Vdefault_frame_scroll_bars = Qnil;
5121 #endif
5123 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5124 scroll_bar_adjust_thumb_portion_p,
5125 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5126 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5127 even if the end of the buffer is shown (i.e. overscrolling).
5128 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5129 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5130 is visible. In this case you can not overscroll. */);
5131 scroll_bar_adjust_thumb_portion_p = 1;
5133 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5134 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5136 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5137 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5138 `mouse-position' and `mouse-pixel-position' call this function, passing their
5139 usual return value as argument, and return whatever this function returns.
5140 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5141 which need to do mouse handling at the Lisp level. */);
5142 Vmouse_position_function = Qnil;
5144 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5145 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5146 If the value is an integer, highlighting is only shown after moving the
5147 mouse, while keyboard input turns off the highlight even when the mouse
5148 is over the clickable text. However, the mouse shape still indicates
5149 when the mouse is over clickable text. */);
5150 Vmouse_highlight = Qt;
5152 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5153 doc: /* If non-nil, make pointer invisible while typing.
5154 The pointer becomes visible again when the mouse is moved. */);
5155 Vmake_pointer_invisible = Qt;
5157 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5158 doc: /* Normal hook run when a frame gains input focus. */);
5159 Vfocus_in_hook = Qnil;
5161 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5162 doc: /* Normal hook run when a frame loses input focus. */);
5163 Vfocus_out_hook = Qnil;
5165 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5166 doc: /* Functions run before deleting a frame.
5167 The functions are run with one arg, the frame to be deleted.
5168 See `delete-frame'.
5170 Note that functions in this list may be called just before the frame is
5171 actually deleted, or some time later (or even both when an earlier function
5172 in `delete-frame-functions' (indirectly) calls `delete-frame'
5173 recursively). */);
5174 Vdelete_frame_functions = Qnil;
5175 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5177 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5178 doc: /* Non-nil if Menu-Bar mode is enabled.
5179 See the command `menu-bar-mode' for a description of this minor mode.
5180 Setting this variable directly does not take effect;
5181 either customize it (see the info node `Easy Customization')
5182 or call the function `menu-bar-mode'. */);
5183 Vmenu_bar_mode = Qt;
5185 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5186 doc: /* Non-nil if Tool-Bar mode is enabled.
5187 See the command `tool-bar-mode' for a description of this minor mode.
5188 Setting this variable directly does not take effect;
5189 either customize it (see the info node `Easy Customization')
5190 or call the function `tool-bar-mode'. */);
5191 #ifdef HAVE_WINDOW_SYSTEM
5192 Vtool_bar_mode = Qt;
5193 #else
5194 Vtool_bar_mode = Qnil;
5195 #endif
5197 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5198 doc: /* Minibufferless frames use this frame's minibuffer.
5199 Emacs cannot create minibufferless frames unless this is set to an
5200 appropriate surrogate.
5202 Emacs consults this variable only when creating minibufferless
5203 frames; once the frame is created, it sticks with its assigned
5204 minibuffer, no matter what this variable is set to. This means that
5205 this variable doesn't necessarily say anything meaningful about the
5206 current set of frames, or where the minibuffer is currently being
5207 displayed.
5209 This variable is local to the current terminal and cannot be buffer-local. */);
5211 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
5212 doc: /* Non-nil if window system changes focus when you move the mouse.
5213 You should set this variable to tell Emacs how your window manager
5214 handles focus, since there is no way in general for Emacs to find out
5215 automatically. See also `mouse-autoselect-window'. */);
5216 focus_follows_mouse = 0;
5218 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5219 doc: /* Non-nil means resize frames pixelwise.
5220 If this option is nil, resizing a frame rounds its sizes to the frame's
5221 current values of `frame-char-height' and `frame-char-width'. If this
5222 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5223 by one pixel.
5225 With some window managers you may have to set this to non-nil in order
5226 to set the size of a frame in pixels, to maximize frames or to make them
5227 fullscreen. To resize your initial frame pixelwise, set this option to
5228 a non-nil value in your init file. */);
5229 frame_resize_pixelwise = 0;
5231 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5232 doc: /* Whether frames should be resized implicitly.
5233 If this option is nil, setting font, menu bar, tool bar, internal
5234 borders, fringes or scroll bars of a specific frame may resize the frame
5235 in order to preserve the number of columns or lines it displays. If
5236 this option is t, no such resizing is done. Note that the size of
5237 fullscreen and maximized frames, the height of fullheight frames and the
5238 width of fullwidth frames never change implicitly.
5240 The value of this option can be also be a list of frame parameters. In
5241 this case, resizing is inhibited when changing a parameter that appears
5242 in that list. The parameters currently handled by this option include
5243 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5244 `tool-bar-lines'.
5246 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5247 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5248 `right-fringe' is handled as if the frame contained just one live
5249 window. This means, for example, that removing vertical scroll bars on
5250 a frame containing several side by side windows will shrink the frame
5251 width by the width of one scroll bar provided this option is nil and
5252 keep it unchanged if this option is either t or a list containing
5253 `vertical-scroll-bars'.
5255 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
5256 \(which means that adding/removing a tool bar does not change the frame
5257 height), nil on all other window systems including GTK+ (which means
5258 that changing any of the parameters listed above may change the size of
5259 the frame), and t otherwise (which means the frame size never changes
5260 implicitly when there's no window system support).
5262 Note that when a frame is not large enough to accommodate a change of
5263 any of the parameters listed above, Emacs may try to enlarge the frame
5264 even if this option is non-nil. */);
5265 #if defined (HAVE_WINDOW_SYSTEM)
5266 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
5267 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
5268 #else
5269 frame_inhibit_implied_resize = Qnil;
5270 #endif
5271 #else
5272 frame_inhibit_implied_resize = Qt;
5273 #endif
5275 DEFVAR_LISP ("frame-size-history", frame_size_history,
5276 doc: /* History of frame size adjustments.
5277 If non-nil, list recording frame size adjustment. Adjustments are
5278 recorded only if the first element of this list is a positive number.
5279 Adding an adjustment decrements that number by one.
5281 The remaining elements are the adjustments. Each adjustment is a list
5282 of four elements `frame', `function', `sizes' and `more'. `frame' is
5283 the affected frame and `function' the invoking function. `sizes' is
5284 usually a list of four elements `old-width', `old-height', `new-width'
5285 and `new-height' representing the old and new sizes recorded/requested
5286 by `function'. `more' is a list with additional information.
5288 The function `frame--size-history' displays the value of this variable
5289 in a more readable form. */);
5290 frame_size_history = Qnil;
5292 DEFVAR_BOOL ("tooltip-reuse-hidden-frame", tooltip_reuse_hidden_frame,
5293 doc: /* Non-nil means reuse hidden tooltip frames.
5294 When this is nil, delete a tooltip frame when hiding the associated
5295 tooltip. When this is non-nil, make the tooltip frame invisible only,
5296 so it can be reused when the next tooltip is shown.
5298 Setting this to non-nil may drastically reduce the consing overhead
5299 incurred by creating new tooltip frames. However, a value of non-nil
5300 means also that intermittent changes of faces or `default-frame-alist'
5301 are not applied when showing a tooltip in a reused frame.
5303 This variable is effective only with the X toolkit (and there only when
5304 Gtk+ tooltips are not used) and on Windows. */);
5305 tooltip_reuse_hidden_frame = false;
5307 staticpro (&Vframe_list);
5309 defsubr (&Sframep);
5310 defsubr (&Sframe_live_p);
5311 defsubr (&Swindow_system);
5312 defsubr (&Sframe_windows_min_size);
5313 defsubr (&Smake_terminal_frame);
5314 defsubr (&Shandle_switch_frame);
5315 defsubr (&Sselect_frame);
5316 defsubr (&Sselected_frame);
5317 defsubr (&Sframe_list);
5318 defsubr (&Snext_frame);
5319 defsubr (&Sprevious_frame);
5320 defsubr (&Slast_nonminibuf_frame);
5321 defsubr (&Sdelete_frame);
5322 defsubr (&Smouse_position);
5323 defsubr (&Smouse_pixel_position);
5324 defsubr (&Sset_mouse_position);
5325 defsubr (&Sset_mouse_pixel_position);
5326 #if 0
5327 defsubr (&Sframe_configuration);
5328 defsubr (&Srestore_frame_configuration);
5329 #endif
5330 defsubr (&Smake_frame_visible);
5331 defsubr (&Smake_frame_invisible);
5332 defsubr (&Siconify_frame);
5333 defsubr (&Sframe_visible_p);
5334 defsubr (&Svisible_frame_list);
5335 defsubr (&Sraise_frame);
5336 defsubr (&Slower_frame);
5337 defsubr (&Sx_focus_frame);
5338 defsubr (&Sframe_after_make_frame);
5339 defsubr (&Sredirect_frame_focus);
5340 defsubr (&Sframe_focus);
5341 defsubr (&Sframe_parameters);
5342 defsubr (&Sframe_parameter);
5343 defsubr (&Smodify_frame_parameters);
5344 defsubr (&Sframe_char_height);
5345 defsubr (&Sframe_char_width);
5346 defsubr (&Sframe_pixel_height);
5347 defsubr (&Sframe_pixel_width);
5348 defsubr (&Sframe_text_cols);
5349 defsubr (&Sframe_text_lines);
5350 defsubr (&Sframe_total_cols);
5351 defsubr (&Sframe_total_lines);
5352 defsubr (&Sframe_text_width);
5353 defsubr (&Sframe_text_height);
5354 defsubr (&Sscroll_bar_width);
5355 defsubr (&Sscroll_bar_height);
5356 defsubr (&Sfringe_width);
5357 defsubr (&Sborder_width);
5358 defsubr (&Sright_divider_width);
5359 defsubr (&Sbottom_divider_width);
5360 defsubr (&Stool_bar_pixel_width);
5361 defsubr (&Sset_frame_height);
5362 defsubr (&Sset_frame_width);
5363 defsubr (&Sset_frame_size);
5364 defsubr (&Sframe_position);
5365 defsubr (&Sset_frame_position);
5366 defsubr (&Sframe_pointer_visible_p);
5368 #ifdef HAVE_WINDOW_SYSTEM
5369 defsubr (&Sx_get_resource);
5370 defsubr (&Sx_parse_geometry);
5371 #endif