Merge from origin/emacs-25
[emacs.git] / src / frame.c
blob2c2c1e150d470fe44aa30d37d8fc6cfc078d299a
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2017 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or (at
10 your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <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 UNINIT;
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 /* The tty color needed to be set before the frame's parameter
2482 alist was updated with the new value. This is not true any more,
2483 but we still do this test early on. */
2484 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2485 && f == FRAME_TTY (f)->previous_frame)
2486 /* Force redisplay of this tty. */
2487 FRAME_TTY (f)->previous_frame = NULL;
2489 /* Update the frame parameter alist. */
2490 old_alist_elt = Fassq (prop, f->param_alist);
2491 if (EQ (old_alist_elt, Qnil))
2492 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2493 else
2494 Fsetcdr (old_alist_elt, val);
2496 /* Update some other special parameters in their special places
2497 in addition to the alist. */
2499 if (EQ (prop, Qbuffer_predicate))
2500 fset_buffer_predicate (f, val);
2502 if (! FRAME_WINDOW_P (f))
2504 if (EQ (prop, Qmenu_bar_lines))
2505 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2506 else if (EQ (prop, Qname))
2507 set_term_frame_name (f, val);
2511 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2512 is not an unspecified foreground or background color. */
2514 static Lisp_Object
2515 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2517 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2518 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2519 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2520 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2523 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2524 doc: /* Return the parameters-alist of frame FRAME.
2525 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2526 The meaningful PARMs depend on the kind of frame.
2527 If FRAME is omitted or nil, return information on the currently selected frame. */)
2528 (Lisp_Object frame)
2530 Lisp_Object alist;
2531 struct frame *f = decode_any_frame (frame);
2532 int height, width;
2534 if (!FRAME_LIVE_P (f))
2535 return Qnil;
2537 alist = Fcopy_alist (f->param_alist);
2539 if (!FRAME_WINDOW_P (f))
2541 Lisp_Object elt;
2543 /* If the frame's parameter alist says the colors are
2544 unspecified and reversed, take the frame's background pixel
2545 for foreground and vice versa. */
2546 elt = Fassq (Qforeground_color, alist);
2547 if (CONSP (elt) && STRINGP (XCDR (elt)))
2549 elt = frame_unspecified_color (f, XCDR (elt));
2550 if (!NILP (elt))
2551 store_in_alist (&alist, Qforeground_color, elt);
2553 else
2554 store_in_alist (&alist, Qforeground_color,
2555 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2556 elt = Fassq (Qbackground_color, alist);
2557 if (CONSP (elt) && STRINGP (XCDR (elt)))
2559 elt = frame_unspecified_color (f, XCDR (elt));
2560 if (!NILP (elt))
2561 store_in_alist (&alist, Qbackground_color, elt);
2563 else
2564 store_in_alist (&alist, Qbackground_color,
2565 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2566 store_in_alist (&alist, Qfont,
2567 build_string (FRAME_MSDOS_P (f)
2568 ? "ms-dos"
2569 : FRAME_W32_P (f) ? "w32term"
2570 :"tty"));
2572 store_in_alist (&alist, Qname, f->name);
2573 height = (f->new_height
2574 ? (f->new_pixelwise
2575 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2576 : f->new_height)
2577 : FRAME_LINES (f));
2578 store_in_alist (&alist, Qheight, make_number (height));
2579 width = (f->new_width
2580 ? (f->new_pixelwise
2581 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2582 : f->new_width)
2583 : FRAME_COLS (f));
2584 store_in_alist (&alist, Qwidth, make_number (width));
2585 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2586 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2587 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2588 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2590 /* I think this should be done with a hook. */
2591 #ifdef HAVE_WINDOW_SYSTEM
2592 if (FRAME_WINDOW_P (f))
2593 x_report_frame_params (f, &alist);
2594 else
2595 #endif
2597 /* This ought to be correct in f->param_alist for an X frame. */
2598 Lisp_Object lines;
2599 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2600 store_in_alist (&alist, Qmenu_bar_lines, lines);
2603 return alist;
2607 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2608 doc: /* Return FRAME's value for parameter PARAMETER.
2609 If FRAME is nil, describe the currently selected frame. */)
2610 (Lisp_Object frame, Lisp_Object parameter)
2612 struct frame *f = decode_any_frame (frame);
2613 Lisp_Object value = Qnil;
2615 CHECK_SYMBOL (parameter);
2617 XSETFRAME (frame, f);
2619 if (FRAME_LIVE_P (f))
2621 /* Avoid consing in frequent cases. */
2622 if (EQ (parameter, Qname))
2623 value = f->name;
2624 #ifdef HAVE_WINDOW_SYSTEM
2625 /* These are used by vertical motion commands. */
2626 else if (EQ (parameter, Qvertical_scroll_bars))
2627 value = (f->vertical_scroll_bar_type == vertical_scroll_bar_none
2628 ? Qnil
2629 : (f->vertical_scroll_bar_type == vertical_scroll_bar_left
2630 ? Qleft : Qright));
2631 else if (EQ (parameter, Qhorizontal_scroll_bars))
2632 value = f->horizontal_scroll_bars ? Qt : Qnil;
2633 else if (EQ (parameter, Qline_spacing) && f->extra_line_spacing == 0)
2634 /* If this is non-zero, we can't determine whether the user specified
2635 an integer or float value without looking through 'param_alist'. */
2636 value = make_number (0);
2637 else if (EQ (parameter, Qfont) && FRAME_X_P (f))
2638 value = FRAME_FONT (f)->props[FONT_NAME_INDEX];
2639 #endif /* HAVE_WINDOW_SYSTEM */
2640 #ifdef HAVE_X_WINDOWS
2641 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2642 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2643 #endif /* HAVE_X_WINDOWS */
2644 else if (EQ (parameter, Qbackground_color)
2645 || EQ (parameter, Qforeground_color))
2647 value = Fassq (parameter, f->param_alist);
2648 if (CONSP (value))
2650 value = XCDR (value);
2651 /* Fframe_parameters puts the actual fg/bg color names,
2652 even if f->param_alist says otherwise. This is
2653 important when param_alist's notion of colors is
2654 "unspecified". We need to do the same here. */
2655 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2657 Lisp_Object tem = frame_unspecified_color (f, value);
2659 if (!NILP (tem))
2660 value = tem;
2663 else
2664 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2666 else if (EQ (parameter, Qdisplay_type)
2667 || EQ (parameter, Qbackground_mode))
2668 value = Fcdr (Fassq (parameter, f->param_alist));
2669 else
2670 /* FIXME: Avoid this code path at all (as well as code duplication)
2671 by sharing more code with Fframe_parameters. */
2672 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2675 return value;
2679 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2680 Smodify_frame_parameters, 2, 2, 0,
2681 doc: /* Modify FRAME according to new values of its parameters in ALIST.
2682 If FRAME is nil, it defaults to the selected frame.
2683 ALIST is an alist of parameters to change and their new values.
2684 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2685 Which PARMs are meaningful depends on the kind of frame.
2686 The meaningful parameters are acted upon, i.e. the frame is changed
2687 according to their new values, and are also stored in the frame's
2688 parameter list so that `frame-parameters' will return them.
2689 PARMs that are not meaningful are still stored in the frame's parameter
2690 list, but are otherwise ignored. */)
2691 (Lisp_Object frame, Lisp_Object alist)
2693 struct frame *f = decode_live_frame (frame);
2694 register Lisp_Object prop, val;
2696 CHECK_LIST (alist);
2698 /* I think this should be done with a hook. */
2699 #ifdef HAVE_WINDOW_SYSTEM
2700 if (FRAME_WINDOW_P (f))
2701 x_set_frame_parameters (f, alist);
2702 else
2703 #endif
2704 #ifdef MSDOS
2705 if (FRAME_MSDOS_P (f))
2706 IT_set_frame_parameters (f, alist);
2707 else
2708 #endif
2711 EMACS_INT length = XFASTINT (Flength (alist));
2712 ptrdiff_t i;
2713 Lisp_Object *parms;
2714 Lisp_Object *values;
2715 USE_SAFE_ALLOCA;
2716 SAFE_ALLOCA_LISP (parms, 2 * length);
2717 values = parms + length;
2719 /* Extract parm names and values into those vectors. */
2721 for (i = 0; CONSP (alist); alist = XCDR (alist))
2723 Lisp_Object elt;
2725 elt = XCAR (alist);
2726 parms[i] = Fcar (elt);
2727 values[i] = Fcdr (elt);
2728 i++;
2731 /* Now process them in reverse of specified order. */
2732 while (--i >= 0)
2734 prop = parms[i];
2735 val = values[i];
2736 store_frame_param (f, prop, val);
2738 if (EQ (prop, Qforeground_color)
2739 || EQ (prop, Qbackground_color))
2740 update_face_from_frame_parameter (f, prop, val);
2743 SAFE_FREE ();
2745 return Qnil;
2748 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2749 0, 1, 0,
2750 doc: /* Height in pixels of a line in the font in frame FRAME.
2751 If FRAME is omitted or nil, the selected frame is used.
2752 For a terminal frame, the value is always 1. */)
2753 (Lisp_Object frame)
2755 #ifdef HAVE_WINDOW_SYSTEM
2756 struct frame *f = decode_any_frame (frame);
2758 if (FRAME_WINDOW_P (f))
2759 return make_number (FRAME_LINE_HEIGHT (f));
2760 else
2761 #endif
2762 return make_number (1);
2766 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2767 0, 1, 0,
2768 doc: /* Width in pixels of characters in the font in frame FRAME.
2769 If FRAME is omitted or nil, the selected frame is used.
2770 On a graphical screen, the width is the standard width of the default font.
2771 For a terminal screen, the value is always 1. */)
2772 (Lisp_Object frame)
2774 #ifdef HAVE_WINDOW_SYSTEM
2775 struct frame *f = decode_any_frame (frame);
2777 if (FRAME_WINDOW_P (f))
2778 return make_number (FRAME_COLUMN_WIDTH (f));
2779 else
2780 #endif
2781 return make_number (1);
2784 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2785 Sframe_pixel_height, 0, 1, 0,
2786 doc: /* Return a FRAME's height in pixels.
2787 If FRAME is omitted or nil, the selected frame is used. The exact value
2788 of the result depends on the window-system and toolkit in use:
2790 In the Gtk+ version of Emacs, it includes only any window (including
2791 the minibuffer or echo area), mode line, and header line. It does not
2792 include the tool bar or menu bar.
2794 With other graphical versions, it also includes the tool bar and the
2795 menu bar.
2797 For a text terminal, it includes the menu bar. In this case, the
2798 result is really in characters rather than pixels (i.e., is identical
2799 to `frame-height'). */)
2800 (Lisp_Object frame)
2802 struct frame *f = decode_any_frame (frame);
2804 #ifdef HAVE_WINDOW_SYSTEM
2805 if (FRAME_WINDOW_P (f))
2806 return make_number (FRAME_PIXEL_HEIGHT (f));
2807 else
2808 #endif
2809 return make_number (FRAME_TOTAL_LINES (f));
2812 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2813 Sframe_pixel_width, 0, 1, 0,
2814 doc: /* Return FRAME's width in pixels.
2815 For a terminal frame, the result really gives the width in characters.
2816 If FRAME is omitted or nil, the selected frame is used. */)
2817 (Lisp_Object frame)
2819 struct frame *f = decode_any_frame (frame);
2821 #ifdef HAVE_WINDOW_SYSTEM
2822 if (FRAME_WINDOW_P (f))
2823 return make_number (FRAME_PIXEL_WIDTH (f));
2824 else
2825 #endif
2826 return make_number (FRAME_TOTAL_COLS (f));
2829 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2830 Stool_bar_pixel_width, 0, 1, 0,
2831 doc: /* Return width in pixels of FRAME's tool bar.
2832 The result is greater than zero only when the tool bar is on the left
2833 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2834 is used. */)
2835 (Lisp_Object frame)
2837 #ifdef FRAME_TOOLBAR_WIDTH
2838 struct frame *f = decode_any_frame (frame);
2840 if (FRAME_WINDOW_P (f))
2841 return make_number (FRAME_TOOLBAR_WIDTH (f));
2842 #endif
2843 return make_number (0);
2846 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2847 doc: /* Return width in columns of FRAME's text area. */)
2848 (Lisp_Object frame)
2850 return make_number (FRAME_COLS (decode_any_frame (frame)));
2853 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2854 doc: /* Return height in lines of FRAME's text area. */)
2855 (Lisp_Object frame)
2857 return make_number (FRAME_LINES (decode_any_frame (frame)));
2860 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2861 doc: /* Return number of total columns of FRAME. */)
2862 (Lisp_Object frame)
2864 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2867 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2868 doc: /* Return number of total lines of FRAME. */)
2869 (Lisp_Object frame)
2871 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2874 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2875 doc: /* Return text area width of FRAME in pixels. */)
2876 (Lisp_Object frame)
2878 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2881 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2882 doc: /* Return text area height of FRAME in pixels. */)
2883 (Lisp_Object frame)
2885 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2888 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2889 doc: /* Return scroll bar width of FRAME in pixels. */)
2890 (Lisp_Object frame)
2892 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2895 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2896 doc: /* Return scroll bar height of FRAME in pixels. */)
2897 (Lisp_Object frame)
2899 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2902 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2903 doc: /* Return fringe width of FRAME in pixels. */)
2904 (Lisp_Object frame)
2906 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2909 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2910 doc: /* Return border width of FRAME in pixels. */)
2911 (Lisp_Object frame)
2913 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2916 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2917 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2918 (Lisp_Object frame)
2920 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2923 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2924 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2925 (Lisp_Object frame)
2927 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2930 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2931 doc: /* Set text height of frame FRAME to HEIGHT lines.
2932 Optional third arg PRETEND non-nil means that redisplay should use
2933 HEIGHT lines but that the idea of the actual height of the frame should
2934 not be changed.
2936 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2937 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
2938 window managers may refuse to honor a HEIGHT that is not an integer
2939 multiple of the default frame font height. */)
2940 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2942 struct frame *f = decode_live_frame (frame);
2943 int pixel_height;
2945 CHECK_TYPE_RANGED_INTEGER (int, height);
2947 pixel_height = (!NILP (pixelwise)
2948 ? XINT (height)
2949 : XINT (height) * FRAME_LINE_HEIGHT (f));
2950 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
2952 return Qnil;
2955 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2956 doc: /* Set text width of frame FRAME to WIDTH columns.
2957 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2958 columns but that the idea of the actual width of the frame should not
2959 be changed.
2961 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2962 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
2963 window managers may refuse to honor a WIDTH that is not an integer
2964 multiple of the default frame font width. */)
2965 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2967 struct frame *f = decode_live_frame (frame);
2968 int pixel_width;
2970 CHECK_TYPE_RANGED_INTEGER (int, width);
2972 pixel_width = (!NILP (pixelwise)
2973 ? XINT (width)
2974 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2975 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
2977 return Qnil;
2980 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2981 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
2982 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
2983 When `frame-resize-pixelwise' is nil, some window managers may refuse to
2984 honor a WIDTH that is not an integer multiple of the default frame font
2985 width or a HEIGHT that is not an integer multiple of the default frame
2986 font height. */)
2987 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2989 struct frame *f = decode_live_frame (frame);
2990 int pixel_width, pixel_height;
2992 CHECK_TYPE_RANGED_INTEGER (int, width);
2993 CHECK_TYPE_RANGED_INTEGER (int, height);
2995 pixel_width = (!NILP (pixelwise)
2996 ? XINT (width)
2997 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2998 pixel_height = (!NILP (pixelwise)
2999 ? XINT (height)
3000 : XINT (height) * FRAME_LINE_HEIGHT (f));
3001 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
3003 return Qnil;
3006 DEFUN ("frame-position", Fframe_position,
3007 Sframe_position, 0, 1, 0,
3008 doc: /* Return top left corner of FRAME in pixels.
3009 FRAME must be a live frame and defaults to the selected one. The return
3010 value is a cons (x, y) of the coordinates of the top left corner of
3011 FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's
3012 display. */)
3013 (Lisp_Object frame)
3015 register struct frame *f = decode_live_frame (frame);
3017 return Fcons (make_number (f->left_pos), make_number (f->top_pos));
3020 DEFUN ("set-frame-position", Fset_frame_position,
3021 Sset_frame_position, 3, 3, 0,
3022 doc: /* Set position of FRAME to (X, Y).
3023 FRAME must be a live frame and defaults to the selected one. X and Y,
3024 if positive, specify the coordinate of the left and top edge of FRAME's
3025 outer frame in pixels relative to an origin (0, 0) of FRAME's display.
3026 If any of X or Y is negative, it specifies the coordinates of the right
3027 or bottom edge of the outer frame of FRAME relative to the right or
3028 bottom edge of FRAME's display. */)
3029 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
3031 struct frame *f = decode_live_frame (frame);
3033 CHECK_TYPE_RANGED_INTEGER (int, x);
3034 CHECK_TYPE_RANGED_INTEGER (int, y);
3036 /* I think this should be done with a hook. */
3037 if (FRAME_WINDOW_P (f))
3039 #ifdef HAVE_WINDOW_SYSTEM
3040 x_set_offset (f, XINT (x), XINT (y), 1);
3041 #endif
3044 return Qt;
3048 /***********************************************************************
3049 Frame Parameters
3050 ***********************************************************************/
3052 /* Connect the frame-parameter names for X frames
3053 to the ways of passing the parameter values to the window system.
3055 The name of a parameter, as a Lisp symbol,
3056 has an `x-frame-parameter' property which is an integer in Lisp
3057 that is an index in this table. */
3059 struct frame_parm_table {
3060 const char *name;
3061 int sym;
3064 static const struct frame_parm_table frame_parms[] =
3066 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3067 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3068 {"background-color", -1},
3069 {"border-color", SYMBOL_INDEX (Qborder_color)},
3070 {"border-width", SYMBOL_INDEX (Qborder_width)},
3071 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3072 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3073 {"font", -1},
3074 {"foreground-color", -1},
3075 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3076 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3077 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3078 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3079 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3080 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3081 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3082 {"name", SYMBOL_INDEX (Qname)},
3083 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3084 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3085 {"title", SYMBOL_INDEX (Qtitle)},
3086 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3087 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3088 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3089 {"visibility", SYMBOL_INDEX (Qvisibility)},
3090 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3091 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3092 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3093 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3094 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3095 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3096 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3097 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3098 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3099 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3100 {"alpha", SYMBOL_INDEX (Qalpha)},
3101 {"sticky", SYMBOL_INDEX (Qsticky)},
3102 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3103 {"inhibit-double-buffering", SYMBOL_INDEX (Qinhibit_double_buffering)},
3106 #ifdef HAVE_WINDOW_SYSTEM
3108 /* Change the parameters of frame F as specified by ALIST.
3109 If a parameter is not specially recognized, do nothing special;
3110 otherwise call the `x_set_...' function for that parameter.
3111 Except for certain geometry properties, always call store_frame_param
3112 to store the new value in the parameter alist. */
3114 void
3115 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3117 Lisp_Object tail;
3119 /* If both of these parameters are present, it's more efficient to
3120 set them both at once. So we wait until we've looked at the
3121 entire list before we set them. */
3122 int width = -1, height = -1; /* -1 denotes they were not changed. */
3124 /* Same here. */
3125 Lisp_Object left, top;
3127 /* Same with these. */
3128 Lisp_Object icon_left, icon_top;
3130 /* And with this. */
3131 Lisp_Object fullscreen;
3132 bool fullscreen_change = false;
3134 /* Record in these vectors all the parms specified. */
3135 Lisp_Object *parms;
3136 Lisp_Object *values;
3137 ptrdiff_t i, j, size;
3138 bool left_no_change = 0, top_no_change = 0;
3139 #ifdef HAVE_X_WINDOWS
3140 bool icon_left_no_change = 0, icon_top_no_change = 0;
3141 #endif
3143 for (size = 0, tail = alist; CONSP (tail); tail = XCDR (tail))
3144 size++;
3146 USE_SAFE_ALLOCA;
3147 SAFE_ALLOCA_LISP (parms, 2 * size);
3148 values = parms + size;
3150 /* Extract parm names and values into those vectors. */
3152 i = 0, j = size - 1;
3153 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3155 Lisp_Object elt = XCAR (tail), prop = Fcar (elt), val = Fcdr (elt);
3157 /* Some properties are independent of other properties, but other
3158 properties are dependent upon them. These special properties
3159 are foreground_color, background_color (affects cursor_color)
3160 and font (affects fringe widths); they're recorded starting
3161 from the end of PARMS and VALUES to process them first by using
3162 reverse iteration. */
3164 if (EQ (prop, Qforeground_color)
3165 || EQ (prop, Qbackground_color)
3166 || EQ (prop, Qfont))
3168 parms[j] = prop;
3169 values[j] = val;
3170 j--;
3172 else
3174 parms[i] = prop;
3175 values[i] = val;
3176 i++;
3180 /* TAIL and ALIST are not used again below here. */
3181 alist = tail = Qnil;
3183 top = left = Qunbound;
3184 icon_left = icon_top = Qunbound;
3186 /* Reverse order is used to make sure that special
3187 properties noticed above are processed first. */
3188 for (i = size - 1; i >= 0; i--)
3190 Lisp_Object prop, val;
3192 prop = parms[i];
3193 val = values[i];
3195 if (EQ (prop, Qwidth))
3197 if (RANGED_INTEGERP (0, val, INT_MAX))
3198 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3199 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3200 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3201 width = XFASTINT (XCDR (val));
3203 else if (EQ (prop, Qheight))
3205 if (RANGED_INTEGERP (0, val, INT_MAX))
3206 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3207 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3208 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3209 height = XFASTINT (XCDR (val));
3211 else if (EQ (prop, Qtop))
3212 top = val;
3213 else if (EQ (prop, Qleft))
3214 left = val;
3215 else if (EQ (prop, Qicon_top))
3216 icon_top = val;
3217 else if (EQ (prop, Qicon_left))
3218 icon_left = val;
3219 else if (EQ (prop, Qfullscreen))
3221 fullscreen = val;
3222 fullscreen_change = true;
3224 else
3226 register Lisp_Object param_index, old_value;
3228 old_value = get_frame_param (f, prop);
3230 store_frame_param (f, prop, val);
3232 param_index = Fget (prop, Qx_frame_parameter);
3233 if (NATNUMP (param_index)
3234 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3235 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3236 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3240 /* Don't die if just one of these was set. */
3241 if (EQ (left, Qunbound))
3243 left_no_change = 1;
3244 if (f->left_pos < 0)
3245 left = list2 (Qplus, make_number (f->left_pos));
3246 else
3247 XSETINT (left, f->left_pos);
3249 if (EQ (top, Qunbound))
3251 top_no_change = 1;
3252 if (f->top_pos < 0)
3253 top = list2 (Qplus, make_number (f->top_pos));
3254 else
3255 XSETINT (top, f->top_pos);
3258 /* If one of the icon positions was not set, preserve or default it. */
3259 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3261 #ifdef HAVE_X_WINDOWS
3262 icon_left_no_change = 1;
3263 #endif
3264 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3265 if (NILP (icon_left))
3266 XSETINT (icon_left, 0);
3268 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3270 #ifdef HAVE_X_WINDOWS
3271 icon_top_no_change = 1;
3272 #endif
3273 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3274 if (NILP (icon_top))
3275 XSETINT (icon_top, 0);
3278 /* Don't set these parameters unless they've been explicitly
3279 specified. The window might be mapped or resized while we're in
3280 this function, and we don't want to override that unless the lisp
3281 code has asked for it.
3283 Don't set these parameters unless they actually differ from the
3284 window's current parameters; the window may not actually exist
3285 yet. */
3287 Lisp_Object frame;
3289 XSETFRAME (frame, f);
3291 if ((width != -1 && width != FRAME_TEXT_WIDTH (f))
3292 || (height != -1 && height != FRAME_TEXT_HEIGHT (f)))
3293 /* We could consider checking f->after_make_frame here, but I
3294 don't have the faintest idea why the following is needed at
3295 all. With the old setting it can get a Heisenbug when
3296 EmacsFrameResize intermittently provokes a delayed
3297 change_frame_size in the middle of adjust_frame_size. */
3298 /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
3299 adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters);
3301 if ((!NILP (left) || !NILP (top))
3302 && ! (left_no_change && top_no_change)
3303 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3304 && NUMBERP (top) && XINT (top) == f->top_pos))
3306 int leftpos = 0;
3307 int toppos = 0;
3309 /* Record the signs. */
3310 f->size_hint_flags &= ~ (XNegative | YNegative);
3311 if (EQ (left, Qminus))
3312 f->size_hint_flags |= XNegative;
3313 else if (TYPE_RANGED_INTEGERP (int, left))
3315 leftpos = XINT (left);
3316 if (leftpos < 0)
3317 f->size_hint_flags |= XNegative;
3319 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3320 && CONSP (XCDR (left))
3321 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3323 leftpos = - XINT (XCAR (XCDR (left)));
3324 f->size_hint_flags |= XNegative;
3326 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3327 && CONSP (XCDR (left))
3328 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3330 leftpos = XINT (XCAR (XCDR (left)));
3333 if (EQ (top, Qminus))
3334 f->size_hint_flags |= YNegative;
3335 else if (TYPE_RANGED_INTEGERP (int, top))
3337 toppos = XINT (top);
3338 if (toppos < 0)
3339 f->size_hint_flags |= YNegative;
3341 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3342 && CONSP (XCDR (top))
3343 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3345 toppos = - XINT (XCAR (XCDR (top)));
3346 f->size_hint_flags |= YNegative;
3348 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3349 && CONSP (XCDR (top))
3350 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3352 toppos = XINT (XCAR (XCDR (top)));
3356 /* Store the numeric value of the position. */
3357 f->top_pos = toppos;
3358 f->left_pos = leftpos;
3360 f->win_gravity = NorthWestGravity;
3362 /* Actually set that position, and convert to absolute. */
3363 x_set_offset (f, leftpos, toppos, -1);
3366 if (fullscreen_change)
3368 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
3370 frame_size_history_add
3371 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
3373 store_frame_param (f, Qfullscreen, fullscreen);
3374 if (!EQ (fullscreen, old_value))
3375 x_set_fullscreen (f, fullscreen, old_value);
3379 #ifdef HAVE_X_WINDOWS
3380 if ((!NILP (icon_left) || !NILP (icon_top))
3381 && ! (icon_left_no_change && icon_top_no_change))
3382 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3383 #endif /* HAVE_X_WINDOWS */
3386 SAFE_FREE ();
3390 /* Insert a description of internally-recorded parameters of frame X
3391 into the parameter alist *ALISTPTR that is to be given to the user.
3392 Only parameters that are specific to the X window system
3393 and whose values are not correctly recorded in the frame's
3394 param_alist need to be considered here. */
3396 void
3397 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3399 Lisp_Object tem;
3400 uprintmax_t w;
3401 char buf[INT_BUFSIZE_BOUND (w)];
3403 /* Represent negative positions (off the top or left screen edge)
3404 in a way that Fmodify_frame_parameters will understand correctly. */
3405 XSETINT (tem, f->left_pos);
3406 if (f->left_pos >= 0)
3407 store_in_alist (alistptr, Qleft, tem);
3408 else
3409 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3411 XSETINT (tem, f->top_pos);
3412 if (f->top_pos >= 0)
3413 store_in_alist (alistptr, Qtop, tem);
3414 else
3415 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3417 store_in_alist (alistptr, Qborder_width,
3418 make_number (f->border_width));
3419 store_in_alist (alistptr, Qinternal_border_width,
3420 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3421 store_in_alist (alistptr, Qright_divider_width,
3422 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3423 store_in_alist (alistptr, Qbottom_divider_width,
3424 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3425 store_in_alist (alistptr, Qleft_fringe,
3426 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3427 store_in_alist (alistptr, Qright_fringe,
3428 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3429 store_in_alist (alistptr, Qscroll_bar_width,
3430 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3431 ? make_number (0)
3432 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3433 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3434 /* nil means "use default width"
3435 for non-toolkit scroll bar.
3436 ruler-mode.el depends on this. */
3437 : Qnil));
3438 store_in_alist (alistptr, Qscroll_bar_height,
3439 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3440 ? make_number (0)
3441 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3442 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3443 /* nil means "use default height"
3444 for non-toolkit scroll bar. */
3445 : Qnil));
3446 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3447 MS-Windows it returns a value whose type is HANDLE, which is
3448 actually a pointer. Explicit casting avoids compiler
3449 warnings. */
3450 w = (uintptr_t) FRAME_X_WINDOW (f);
3451 store_in_alist (alistptr, Qwindow_id,
3452 make_formatted_string (buf, "%"pMu, w));
3453 #ifdef HAVE_X_WINDOWS
3454 #ifdef USE_X_TOOLKIT
3455 /* Tooltip frame may not have this widget. */
3456 if (FRAME_X_OUTPUT (f)->widget)
3457 #endif
3458 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3459 store_in_alist (alistptr, Qouter_window_id,
3460 make_formatted_string (buf, "%"pMu, w));
3461 #endif
3462 store_in_alist (alistptr, Qicon_name, f->icon_name);
3463 store_in_alist (alistptr, Qvisibility,
3464 (FRAME_VISIBLE_P (f) ? Qt
3465 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3466 store_in_alist (alistptr, Qdisplay,
3467 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3469 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3470 tem = Qnil;
3471 else
3472 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3473 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3474 store_in_alist (alistptr, Qparent_id, tem);
3475 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3479 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3480 the previous value of that parameter, NEW_VALUE is the new value. */
3482 void
3483 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3485 if (NILP (new_value))
3486 f->want_fullscreen = FULLSCREEN_NONE;
3487 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3488 f->want_fullscreen = FULLSCREEN_BOTH;
3489 else if (EQ (new_value, Qfullwidth))
3490 f->want_fullscreen = FULLSCREEN_WIDTH;
3491 else if (EQ (new_value, Qfullheight))
3492 f->want_fullscreen = FULLSCREEN_HEIGHT;
3493 else if (EQ (new_value, Qmaximized))
3494 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3496 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3497 FRAME_TERMINAL (f)->fullscreen_hook (f);
3501 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3502 the previous value of that parameter, NEW_VALUE is the new value. */
3504 void
3505 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3507 if (NILP (new_value))
3508 f->extra_line_spacing = 0;
3509 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3510 f->extra_line_spacing = XFASTINT (new_value);
3511 else if (FLOATP (new_value))
3513 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3515 if (new_spacing >= 0)
3516 f->extra_line_spacing = new_spacing;
3517 else
3518 signal_error ("Invalid line-spacing", new_value);
3520 else
3521 signal_error ("Invalid line-spacing", new_value);
3522 if (FRAME_VISIBLE_P (f))
3523 redraw_frame (f);
3527 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3528 the previous value of that parameter, NEW_VALUE is the new value. */
3530 void
3531 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3533 Lisp_Object bgcolor;
3535 if (NILP (new_value))
3536 f->gamma = 0;
3537 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3538 /* The value 0.4545 is the normal viewing gamma. */
3539 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3540 else
3541 signal_error ("Invalid screen-gamma", new_value);
3543 /* Apply the new gamma value to the frame background. */
3544 bgcolor = Fassq (Qbackground_color, f->param_alist);
3545 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3547 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3548 if (NATNUMP (parm_index)
3549 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3550 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3551 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3552 (f, bgcolor, Qnil);
3555 clear_face_cache (true); /* FIXME: Why of all frames? */
3556 fset_redisplay (f);
3560 void
3561 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3563 Lisp_Object font_object;
3564 int fontset = -1;
3565 #ifdef HAVE_X_WINDOWS
3566 Lisp_Object font_param = arg;
3567 #endif
3569 /* Set the frame parameter back to the old value because we may
3570 fail to use ARG as the new parameter value. */
3571 store_frame_param (f, Qfont, oldval);
3573 /* ARG is a fontset name, a font name, a cons of fontset name and a
3574 font object, or a font object. In the last case, this function
3575 never fail. */
3576 if (STRINGP (arg))
3578 fontset = fs_query_fontset (arg, 0);
3579 if (fontset < 0)
3581 font_object = font_open_by_name (f, arg);
3582 if (NILP (font_object))
3583 error ("Font `%s' is not defined", SSDATA (arg));
3584 arg = AREF (font_object, FONT_NAME_INDEX);
3586 else if (fontset > 0)
3588 font_object = font_open_by_name (f, fontset_ascii (fontset));
3589 if (NILP (font_object))
3590 error ("Font `%s' is not defined", SDATA (arg));
3591 arg = AREF (font_object, FONT_NAME_INDEX);
3593 else
3594 error ("The default fontset can't be used for a frame font");
3596 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3598 /* This is the case that the ASCII font of F's fontset XCAR
3599 (arg) is changed to the font XCDR (arg) by
3600 `set-fontset-font'. */
3601 fontset = fs_query_fontset (XCAR (arg), 0);
3602 if (fontset < 0)
3603 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3604 font_object = XCDR (arg);
3605 arg = AREF (font_object, FONT_NAME_INDEX);
3606 #ifdef HAVE_X_WINDOWS
3607 font_param = Ffont_get (font_object, QCname);
3608 #endif
3610 else if (FONT_OBJECT_P (arg))
3612 font_object = arg;
3613 #ifdef HAVE_X_WINDOWS
3614 font_param = Ffont_get (font_object, QCname);
3615 #endif
3616 /* This is to store the XLFD font name in the frame parameter for
3617 backward compatibility. We should store the font-object
3618 itself in the future. */
3619 arg = AREF (font_object, FONT_NAME_INDEX);
3620 fontset = FRAME_FONTSET (f);
3621 /* Check if we can use the current fontset. If not, set FONTSET
3622 to -1 to generate a new fontset from FONT-OBJECT. */
3623 if (fontset >= 0)
3625 Lisp_Object ascii_font = fontset_ascii (fontset);
3626 Lisp_Object spec = font_spec_from_name (ascii_font);
3628 /* SPEC might be nil because ASCII_FONT's name doesn't parse
3629 according to stupid XLFD rules, which, for example,
3630 disallow font names that include a dash followed by a
3631 number. So in those cases we simply request x_new_font
3632 below to generate a new fontset. */
3633 if (NILP (spec) || ! font_match_p (spec, font_object))
3634 fontset = -1;
3637 else
3638 signal_error ("Invalid font", arg);
3640 if (! NILP (Fequal (font_object, oldval)))
3641 return;
3643 x_new_font (f, font_object, fontset);
3644 store_frame_param (f, Qfont, arg);
3645 #ifdef HAVE_X_WINDOWS
3646 store_frame_param (f, Qfont_parameter, font_param);
3647 #endif
3648 /* Recalculate toolbar height. */
3649 f->n_tool_bar_rows = 0;
3651 /* Ensure we redraw it. */
3652 clear_current_matrices (f);
3654 /* Attempt to hunt down bug#16028. */
3655 SET_FRAME_GARBAGED (f);
3657 /* This is important if we are called by some Lisp as part of
3658 redisplaying the frame, see redisplay_internal. */
3659 f->fonts_changed = true;
3661 recompute_basic_faces (f);
3663 do_pending_window_change (0);
3665 /* We used to call face-set-after-frame-default here, but it leads to
3666 recursive calls (since that function can set the `default' face's
3667 font which in turns changes the frame's `font' parameter).
3668 Also I don't know what this call is meant to do, but it seems the
3669 wrong way to do it anyway (it does a lot more work than what seems
3670 reasonable in response to a change to `font'). */
3674 void
3675 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3677 if (! NILP (new_value)
3678 && !CONSP (new_value))
3680 char *p0, *p1;
3682 CHECK_STRING (new_value);
3683 p0 = p1 = SSDATA (new_value);
3684 new_value = Qnil;
3685 while (*p0)
3687 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3688 if (p0 < p1)
3689 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3690 new_value);
3691 if (*p1)
3693 int c;
3695 while ((c = *++p1) && c_isspace (c));
3697 p0 = p1;
3699 new_value = Fnreverse (new_value);
3702 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3703 return;
3705 if (FRAME_FONT (f))
3706 free_all_realized_faces (Qnil);
3708 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3709 if (NILP (new_value))
3711 if (NILP (old_value))
3712 error ("No font backend available");
3713 font_update_drivers (f, old_value);
3714 error ("None of specified font backends are available");
3716 store_frame_param (f, Qfont_backend, new_value);
3718 if (FRAME_FONT (f))
3720 Lisp_Object frame;
3722 XSETFRAME (frame, f);
3723 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3724 face_change = true;
3725 windows_or_buffers_changed = 18;
3729 void
3730 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3732 int unit = FRAME_COLUMN_WIDTH (f);
3733 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3734 int new_width;
3736 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3737 ? eabs (XINT (new_value)) : 8);
3739 if (new_width != old_width)
3741 f->left_fringe_width = new_width;
3742 f->fringe_cols /* Round up. */
3743 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3745 if (FRAME_X_WINDOW (f) != 0)
3746 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
3748 SET_FRAME_GARBAGED (f);
3753 void
3754 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3756 int unit = FRAME_COLUMN_WIDTH (f);
3757 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3758 int new_width;
3760 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3761 ? eabs (XINT (new_value)) : 8);
3763 if (new_width != old_width)
3765 f->right_fringe_width = new_width;
3766 f->fringe_cols /* Round up. */
3767 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3769 if (FRAME_X_WINDOW (f) != 0)
3770 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
3772 SET_FRAME_GARBAGED (f);
3777 void
3778 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3780 CHECK_TYPE_RANGED_INTEGER (int, arg);
3782 if (XINT (arg) == f->border_width)
3783 return;
3785 if (FRAME_X_WINDOW (f) != 0)
3786 error ("Cannot change the border width of a frame");
3788 f->border_width = XINT (arg);
3791 void
3792 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3794 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3795 CHECK_TYPE_RANGED_INTEGER (int, arg);
3796 int new = max (0, XINT (arg));
3797 if (new != old)
3799 f->right_divider_width = new;
3800 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
3801 adjust_frame_glyphs (f);
3802 SET_FRAME_GARBAGED (f);
3807 void
3808 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3810 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3811 CHECK_TYPE_RANGED_INTEGER (int, arg);
3812 int new = max (0, XINT (arg));
3813 if (new != old)
3815 f->bottom_divider_width = new;
3816 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
3817 adjust_frame_glyphs (f);
3818 SET_FRAME_GARBAGED (f);
3822 void
3823 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3825 Lisp_Object frame;
3826 XSETFRAME (frame, f);
3828 if (NILP (value))
3829 Fmake_frame_invisible (frame, Qt);
3830 else if (EQ (value, Qicon))
3831 Ficonify_frame (frame);
3832 else
3833 Fmake_frame_visible (frame);
3836 void
3837 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3839 f->auto_raise = !EQ (Qnil, arg);
3842 void
3843 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3845 f->auto_lower = !EQ (Qnil, arg);
3848 void
3849 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3851 f->no_split = !NILP (arg);
3854 void
3855 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3857 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3858 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3859 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3860 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3862 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3863 = (NILP (arg)
3864 ? vertical_scroll_bar_none
3865 : EQ (Qleft, arg)
3866 ? vertical_scroll_bar_left
3867 : EQ (Qright, arg)
3868 ? vertical_scroll_bar_right
3869 : EQ (Qleft, Vdefault_frame_scroll_bars)
3870 ? vertical_scroll_bar_left
3871 : EQ (Qright, Vdefault_frame_scroll_bars)
3872 ? vertical_scroll_bar_right
3873 : vertical_scroll_bar_none);
3875 /* We set this parameter before creating the X window for the
3876 frame, so we can get the geometry right from the start.
3877 However, if the window hasn't been created yet, we shouldn't
3878 call x_set_window_size. */
3879 if (FRAME_X_WINDOW (f))
3880 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
3882 SET_FRAME_GARBAGED (f);
3886 void
3887 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3889 #if USE_HORIZONTAL_SCROLL_BARS
3890 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3891 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3893 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3895 /* We set this parameter before creating the X window for the
3896 frame, so we can get the geometry right from the start.
3897 However, if the window hasn't been created yet, we shouldn't
3898 call x_set_window_size. */
3899 if (FRAME_X_WINDOW (f))
3900 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
3902 SET_FRAME_GARBAGED (f);
3904 #endif
3907 void
3908 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3910 int unit = FRAME_COLUMN_WIDTH (f);
3912 if (NILP (arg))
3914 x_set_scroll_bar_default_width (f);
3916 if (FRAME_X_WINDOW (f))
3917 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3919 SET_FRAME_GARBAGED (f);
3921 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3922 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3924 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3925 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3926 if (FRAME_X_WINDOW (f))
3927 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3929 SET_FRAME_GARBAGED (f);
3932 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3933 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3936 void
3937 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3939 #if USE_HORIZONTAL_SCROLL_BARS
3940 int unit = FRAME_LINE_HEIGHT (f);
3942 if (NILP (arg))
3944 x_set_scroll_bar_default_height (f);
3946 if (FRAME_X_WINDOW (f))
3947 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3949 SET_FRAME_GARBAGED (f);
3951 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3952 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3954 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3955 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3956 if (FRAME_X_WINDOW (f))
3957 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3959 SET_FRAME_GARBAGED (f);
3962 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3963 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3964 #endif
3967 void
3968 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3970 double alpha = 1.0;
3971 double newval[2];
3972 int i;
3973 Lisp_Object item;
3975 for (i = 0; i < 2; i++)
3977 newval[i] = 1.0;
3978 if (CONSP (arg))
3980 item = CAR (arg);
3981 arg = CDR (arg);
3983 else
3984 item = arg;
3986 if (NILP (item))
3987 alpha = - 1.0;
3988 else if (FLOATP (item))
3990 alpha = XFLOAT_DATA (item);
3991 if (! (0 <= alpha && alpha <= 1.0))
3992 args_out_of_range (make_float (0.0), make_float (1.0));
3994 else if (INTEGERP (item))
3996 EMACS_INT ialpha = XINT (item);
3997 if (! (0 <= ialpha && alpha <= 100))
3998 args_out_of_range (make_number (0), make_number (100));
3999 alpha = ialpha / 100.0;
4001 else
4002 wrong_type_argument (Qnumberp, item);
4003 newval[i] = alpha;
4006 for (i = 0; i < 2; i++)
4007 f->alpha[i] = newval[i];
4009 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4010 block_input ();
4011 x_set_frame_alpha (f);
4012 unblock_input ();
4013 #endif
4015 return;
4018 #ifndef HAVE_NS
4020 /* Non-zero if mouse is grabbed on DPYINFO
4021 and we know the frame where it is. */
4023 bool x_mouse_grabbed (Display_Info *dpyinfo)
4025 return (dpyinfo->grabbed
4026 && dpyinfo->last_mouse_frame
4027 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4030 /* Re-highlight something with mouse-face properties
4031 on DPYINFO using saved frame and mouse position. */
4033 void
4034 x_redo_mouse_highlight (Display_Info *dpyinfo)
4036 if (dpyinfo->last_mouse_motion_frame
4037 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4038 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4039 dpyinfo->last_mouse_motion_x,
4040 dpyinfo->last_mouse_motion_y);
4043 #endif /* HAVE_NS */
4045 /* Subroutines of creating an X frame. */
4047 /* Make sure that Vx_resource_name is set to a reasonable value.
4048 Fix it up, or set it to `emacs' if it is too hopeless. */
4050 void
4051 validate_x_resource_name (void)
4053 ptrdiff_t len = 0;
4054 /* Number of valid characters in the resource name. */
4055 ptrdiff_t good_count = 0;
4056 /* Number of invalid characters in the resource name. */
4057 ptrdiff_t bad_count = 0;
4058 Lisp_Object new;
4059 ptrdiff_t i;
4061 if (!STRINGP (Vx_resource_class))
4062 Vx_resource_class = build_string (EMACS_CLASS);
4064 if (STRINGP (Vx_resource_name))
4066 unsigned char *p = SDATA (Vx_resource_name);
4068 len = SBYTES (Vx_resource_name);
4070 /* Only letters, digits, - and _ are valid in resource names.
4071 Count the valid characters and count the invalid ones. */
4072 for (i = 0; i < len; i++)
4074 int c = p[i];
4075 if (! ((c >= 'a' && c <= 'z')
4076 || (c >= 'A' && c <= 'Z')
4077 || (c >= '0' && c <= '9')
4078 || c == '-' || c == '_'))
4079 bad_count++;
4080 else
4081 good_count++;
4084 else
4085 /* Not a string => completely invalid. */
4086 bad_count = 5, good_count = 0;
4088 /* If name is valid already, return. */
4089 if (bad_count == 0)
4090 return;
4092 /* If name is entirely invalid, or nearly so, or is so implausibly
4093 large that alloca might not work, use `emacs'. */
4094 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4096 Vx_resource_name = build_string ("emacs");
4097 return;
4100 /* Name is partly valid. Copy it and replace the invalid characters
4101 with underscores. */
4103 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4105 for (i = 0; i < len; i++)
4107 int c = SREF (new, i);
4108 if (! ((c >= 'a' && c <= 'z')
4109 || (c >= 'A' && c <= 'Z')
4110 || (c >= '0' && c <= '9')
4111 || c == '-' || c == '_'))
4112 SSET (new, i, '_');
4116 /* Get specified attribute from resource database RDB.
4117 See Fx_get_resource below for other parameters. */
4119 static Lisp_Object
4120 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4122 CHECK_STRING (attribute);
4123 CHECK_STRING (class);
4125 if (!NILP (component))
4126 CHECK_STRING (component);
4127 if (!NILP (subclass))
4128 CHECK_STRING (subclass);
4129 if (NILP (component) != NILP (subclass))
4130 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4132 validate_x_resource_name ();
4134 /* Allocate space for the components, the dots which separate them,
4135 and the final '\0'. Make them big enough for the worst case. */
4136 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4137 + (STRINGP (component)
4138 ? SBYTES (component) : 0)
4139 + SBYTES (attribute)
4140 + 3);
4142 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4143 + SBYTES (class)
4144 + (STRINGP (subclass)
4145 ? SBYTES (subclass) : 0)
4146 + 3);
4147 USE_SAFE_ALLOCA;
4148 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4149 char *class_key = name_key + name_keysize;
4151 /* Start with emacs.FRAMENAME for the name (the specific one)
4152 and with `Emacs' for the class key (the general one). */
4153 char *nz = lispstpcpy (name_key, Vx_resource_name);
4154 char *cz = lispstpcpy (class_key, Vx_resource_class);
4156 *cz++ = '.';
4157 cz = lispstpcpy (cz, class);
4159 if (!NILP (component))
4161 *cz++ = '.';
4162 lispstpcpy (cz, subclass);
4164 *nz++ = '.';
4165 nz = lispstpcpy (nz, component);
4168 *nz++ = '.';
4169 lispstpcpy (nz, attribute);
4171 char *value = x_get_string_resource (rdb, name_key, class_key);
4172 SAFE_FREE();
4174 if (value && *value)
4175 return build_string (value);
4176 else
4177 return Qnil;
4181 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4182 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4183 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4184 class, where INSTANCE is the name under which Emacs was invoked, or
4185 the name specified by the `-name' or `-rn' command-line arguments.
4187 The optional arguments COMPONENT and SUBCLASS add to the key and the
4188 class, respectively. You must specify both of them or neither.
4189 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4190 and the class is `Emacs.CLASS.SUBCLASS'. */)
4191 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4192 Lisp_Object subclass)
4194 check_window_system (NULL);
4196 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4197 attribute, class, component, subclass);
4200 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4202 Lisp_Object
4203 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4204 Lisp_Object class, Lisp_Object component,
4205 Lisp_Object subclass)
4207 return xrdb_get_resource (dpyinfo->xrdb,
4208 attribute, class, component, subclass);
4211 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4212 /* Used when C code wants a resource value. */
4213 /* Called from oldXMenu/Create.c. */
4214 char *
4215 x_get_resource_string (const char *attribute, const char *class)
4217 char *result;
4218 struct frame *sf = SELECTED_FRAME ();
4219 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4220 USE_SAFE_ALLOCA;
4222 /* Allocate space for the components, the dots which separate them,
4223 and the final '\0'. */
4224 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4225 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4226 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4227 char *class_key = name_key + name_keysize;
4229 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4230 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4232 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4233 name_key, class_key);
4234 SAFE_FREE ();
4235 return result;
4237 #endif
4239 /* Return the value of parameter PARAM.
4241 First search ALIST, then Vdefault_frame_alist, then the X defaults
4242 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4244 Convert the resource to the type specified by desired_type.
4246 If no default is specified, return Qunbound. If you call
4247 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4248 and don't let it get stored in any Lisp-visible variables! */
4250 Lisp_Object
4251 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4252 const char *attribute, const char *class, enum resource_types type)
4254 Lisp_Object tem;
4256 tem = Fassq (param, alist);
4258 if (!NILP (tem))
4260 /* If we find this parm in ALIST, clear it out
4261 so that it won't be "left over" at the end. */
4262 Lisp_Object tail;
4263 XSETCAR (tem, Qnil);
4264 /* In case the parameter appears more than once in the alist,
4265 clear it out. */
4266 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4267 if (CONSP (XCAR (tail))
4268 && EQ (XCAR (XCAR (tail)), param))
4269 XSETCAR (XCAR (tail), Qnil);
4271 else
4272 tem = Fassq (param, Vdefault_frame_alist);
4274 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4275 look in the X resources. */
4276 if (EQ (tem, Qnil))
4278 if (attribute && dpyinfo)
4280 AUTO_STRING (at, attribute);
4281 AUTO_STRING (cl, class);
4282 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4284 if (NILP (tem))
4285 return Qunbound;
4287 switch (type)
4289 case RES_TYPE_NUMBER:
4290 return make_number (atoi (SSDATA (tem)));
4292 case RES_TYPE_BOOLEAN_NUMBER:
4293 if (!strcmp (SSDATA (tem), "on")
4294 || !strcmp (SSDATA (tem), "true"))
4295 return make_number (1);
4296 return make_number (atoi (SSDATA (tem)));
4297 break;
4299 case RES_TYPE_FLOAT:
4300 return make_float (atof (SSDATA (tem)));
4302 case RES_TYPE_BOOLEAN:
4303 tem = Fdowncase (tem);
4304 if (!strcmp (SSDATA (tem), "on")
4305 #ifdef HAVE_NS
4306 || !strcmp (SSDATA (tem), "yes")
4307 #endif
4308 || !strcmp (SSDATA (tem), "true"))
4309 return Qt;
4310 else
4311 return Qnil;
4313 case RES_TYPE_STRING:
4314 return tem;
4316 case RES_TYPE_SYMBOL:
4317 /* As a special case, we map the values `true' and `on'
4318 to Qt, and `false' and `off' to Qnil. */
4320 Lisp_Object lower;
4321 lower = Fdowncase (tem);
4322 if (!strcmp (SSDATA (lower), "on")
4323 #ifdef HAVE_NS
4324 || !strcmp (SSDATA (lower), "yes")
4325 #endif
4326 || !strcmp (SSDATA (lower), "true"))
4327 return Qt;
4328 else if (!strcmp (SSDATA (lower), "off")
4329 #ifdef HAVE_NS
4330 || !strcmp (SSDATA (lower), "no")
4331 #endif
4332 || !strcmp (SSDATA (lower), "false"))
4333 return Qnil;
4334 else
4335 return Fintern (tem, Qnil);
4338 default:
4339 emacs_abort ();
4342 else
4343 return Qunbound;
4345 return Fcdr (tem);
4348 static Lisp_Object
4349 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4350 const char *attribute, const char *class,
4351 enum resource_types type)
4353 return x_get_arg (FRAME_DISPLAY_INFO (f),
4354 alist, param, attribute, class, type);
4357 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4359 Lisp_Object
4360 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4361 Lisp_Object param,
4362 const char *attribute, const char *class,
4363 enum resource_types type)
4365 Lisp_Object value;
4367 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4368 attribute, class, type);
4369 if (! NILP (value) && ! EQ (value, Qunbound))
4370 store_frame_param (f, param, value);
4372 return value;
4376 /* Record in frame F the specified or default value according to ALIST
4377 of the parameter named PROP (a Lisp symbol).
4378 If no value is specified for PROP, look for an X default for XPROP
4379 on the frame named NAME.
4380 If that is not found either, use the value DEFLT. */
4382 Lisp_Object
4383 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4384 Lisp_Object deflt, const char *xprop, const char *xclass,
4385 enum resource_types type)
4387 Lisp_Object tem;
4389 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4390 if (EQ (tem, Qunbound))
4391 tem = deflt;
4392 AUTO_FRAME_ARG (arg, prop, tem);
4393 x_set_frame_parameters (f, arg);
4394 return tem;
4398 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4401 * XParseGeometry parses strings of the form
4402 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4403 * width, height, xoffset, and yoffset are unsigned integers.
4404 * Example: "=80x24+300-49"
4405 * The equal sign is optional.
4406 * It returns a bitmask that indicates which of the four values
4407 * were actually found in the string. For each value found,
4408 * the corresponding argument is updated; for each value
4409 * not found, the corresponding argument is left unchanged.
4412 static int
4413 XParseGeometry (char *string,
4414 int *x, int *y,
4415 unsigned int *width, unsigned int *height)
4417 int mask = NoValue;
4418 char *strind;
4419 unsigned long tempWidth UNINIT, tempHeight UNINIT;
4420 long int tempX UNINIT, tempY UNINIT;
4421 char *nextCharacter;
4423 if (string == NULL || *string == '\0')
4424 return mask;
4425 if (*string == '=')
4426 string++; /* ignore possible '=' at beg of geometry spec */
4428 strind = string;
4429 if (*strind != '+' && *strind != '-' && *strind != 'x')
4431 tempWidth = strtoul (strind, &nextCharacter, 10);
4432 if (strind == nextCharacter)
4433 return 0;
4434 strind = nextCharacter;
4435 mask |= WidthValue;
4438 if (*strind == 'x' || *strind == 'X')
4440 strind++;
4441 tempHeight = strtoul (strind, &nextCharacter, 10);
4442 if (strind == nextCharacter)
4443 return 0;
4444 strind = nextCharacter;
4445 mask |= HeightValue;
4448 if (*strind == '+' || *strind == '-')
4450 if (*strind == '-')
4451 mask |= XNegative;
4452 tempX = strtol (strind, &nextCharacter, 10);
4453 if (strind == nextCharacter)
4454 return 0;
4455 strind = nextCharacter;
4456 mask |= XValue;
4457 if (*strind == '+' || *strind == '-')
4459 if (*strind == '-')
4460 mask |= YNegative;
4461 tempY = strtol (strind, &nextCharacter, 10);
4462 if (strind == nextCharacter)
4463 return 0;
4464 strind = nextCharacter;
4465 mask |= YValue;
4469 /* If strind isn't at the end of the string then it's an invalid
4470 geometry specification. */
4472 if (*strind != '\0')
4473 return 0;
4475 if (mask & XValue)
4476 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4477 if (mask & YValue)
4478 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4479 if (mask & WidthValue)
4480 *width = min (tempWidth, UINT_MAX);
4481 if (mask & HeightValue)
4482 *height = min (tempHeight, UINT_MAX);
4483 return mask;
4486 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4489 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4490 make-docfile: the documentation string in ns-win.el was used for
4491 x-parse-geometry even in non-NS builds.
4493 With two definitions of x-parse-geometry in this file, various
4494 things still get confused (eg M-x apropos documentation), so that
4495 it is best if the two definitions just share the same doc-string.
4497 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4498 doc: /* Parse a display geometry string STRING.
4499 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4500 The properties returned may include `top', `left', `height', and `width'.
4501 For X, the value of `left' or `top' may be an integer,
4502 or a list (+ N) meaning N pixels relative to top/left corner,
4503 or a list (- N) meaning -N pixels relative to bottom/right corner.
4504 On Nextstep, this just calls `ns-parse-geometry'. */)
4505 (Lisp_Object string)
4507 int geometry, x, y;
4508 unsigned int width, height;
4509 Lisp_Object result;
4511 CHECK_STRING (string);
4513 #ifdef HAVE_NS
4514 if (strchr (SSDATA (string), ' ') != NULL)
4515 return call1 (Qns_parse_geometry, string);
4516 #endif
4517 geometry = XParseGeometry (SSDATA (string),
4518 &x, &y, &width, &height);
4519 result = Qnil;
4520 if (geometry & XValue)
4522 Lisp_Object element;
4524 if (x >= 0 && (geometry & XNegative))
4525 element = list3 (Qleft, Qminus, make_number (-x));
4526 else if (x < 0 && ! (geometry & XNegative))
4527 element = list3 (Qleft, Qplus, make_number (x));
4528 else
4529 element = Fcons (Qleft, make_number (x));
4530 result = Fcons (element, result);
4533 if (geometry & YValue)
4535 Lisp_Object element;
4537 if (y >= 0 && (geometry & YNegative))
4538 element = list3 (Qtop, Qminus, make_number (-y));
4539 else if (y < 0 && ! (geometry & YNegative))
4540 element = list3 (Qtop, Qplus, make_number (y));
4541 else
4542 element = Fcons (Qtop, make_number (y));
4543 result = Fcons (element, result);
4546 if (geometry & WidthValue)
4547 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4548 if (geometry & HeightValue)
4549 result = Fcons (Fcons (Qheight, make_number (height)), result);
4551 return result;
4555 /* Calculate the desired size and position of frame F.
4556 Return the flags saying which aspects were specified.
4558 Also set the win_gravity and size_hint_flags of F.
4560 Adjust height for toolbar if TOOLBAR_P is 1.
4562 This function does not make the coordinates positive. */
4564 #define DEFAULT_ROWS 36
4565 #define DEFAULT_COLS 80
4567 long
4568 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
4570 Lisp_Object height, width, user_size, top, left, user_position;
4571 long window_prompting = 0;
4572 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4574 /* Default values if we fall through.
4575 Actually, if that happens we should get
4576 window manager prompting. */
4577 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4578 SET_FRAME_COLS (f, DEFAULT_COLS);
4579 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4580 SET_FRAME_LINES (f, DEFAULT_ROWS);
4582 /* Window managers expect that if program-specified
4583 positions are not (0,0), they're intentional, not defaults. */
4584 f->top_pos = 0;
4585 f->left_pos = 0;
4587 /* Calculate a tool bar height so that the user gets a text display
4588 area of the size he specified with -g or via .Xdefaults. Later
4589 changes of the tool bar height don't change the frame size. This
4590 is done so that users can create tall Emacs frames without having
4591 to guess how tall the tool bar will get. */
4592 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4594 if (frame_default_tool_bar_height)
4595 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
4596 else
4598 int margin, relief;
4600 relief = (tool_bar_button_relief >= 0
4601 ? tool_bar_button_relief
4602 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4604 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4605 margin = XFASTINT (Vtool_bar_button_margin);
4606 else if (CONSP (Vtool_bar_button_margin)
4607 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4608 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4609 else
4610 margin = 0;
4612 FRAME_TOOL_BAR_HEIGHT (f)
4613 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4617 /* Ensure that earlier new_width and new_height settings won't
4618 override what we specify below. */
4619 f->new_width = f->new_height = 0;
4621 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4622 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4623 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4625 if (!EQ (width, Qunbound))
4627 if (CONSP (width) && EQ (XCAR (width), Qtext_pixels))
4629 CHECK_NUMBER (XCDR (width));
4630 if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX))
4631 xsignal1 (Qargs_out_of_range, XCDR (width));
4633 SET_FRAME_WIDTH (f, XINT (XCDR (width)));
4634 f->inhibit_horizontal_resize = true;
4635 *x_width = XINT (XCDR (width));
4637 else
4639 CHECK_NUMBER (width);
4640 if ((XINT (width) < 0 || XINT (width) > INT_MAX))
4641 xsignal1 (Qargs_out_of_range, width);
4643 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4647 if (!EQ (height, Qunbound))
4649 if (CONSP (height) && EQ (XCAR (height), Qtext_pixels))
4651 CHECK_NUMBER (XCDR (height));
4652 if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX))
4653 xsignal1 (Qargs_out_of_range, XCDR (height));
4655 SET_FRAME_HEIGHT (f, XINT (XCDR (height)));
4656 f->inhibit_vertical_resize = true;
4657 *x_height = XINT (XCDR (height));
4659 else
4661 CHECK_NUMBER (height);
4662 if ((XINT (height) < 0) || (XINT (height) > INT_MAX))
4663 xsignal1 (Qargs_out_of_range, height);
4665 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4669 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4670 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4671 window_prompting |= USSize;
4672 else
4673 window_prompting |= PSize;
4676 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4677 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4678 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4679 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4681 if (EQ (top, Qminus))
4683 f->top_pos = 0;
4684 window_prompting |= YNegative;
4686 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4687 && CONSP (XCDR (top))
4688 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4690 f->top_pos = - XINT (XCAR (XCDR (top)));
4691 window_prompting |= YNegative;
4693 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4694 && CONSP (XCDR (top))
4695 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4697 f->top_pos = XINT (XCAR (XCDR (top)));
4699 else if (EQ (top, Qunbound))
4700 f->top_pos = 0;
4701 else
4703 CHECK_TYPE_RANGED_INTEGER (int, top);
4704 f->top_pos = XINT (top);
4705 if (f->top_pos < 0)
4706 window_prompting |= YNegative;
4709 if (EQ (left, Qminus))
4711 f->left_pos = 0;
4712 window_prompting |= XNegative;
4714 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4715 && CONSP (XCDR (left))
4716 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4718 f->left_pos = - XINT (XCAR (XCDR (left)));
4719 window_prompting |= XNegative;
4721 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4722 && CONSP (XCDR (left))
4723 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4725 f->left_pos = XINT (XCAR (XCDR (left)));
4727 else if (EQ (left, Qunbound))
4728 f->left_pos = 0;
4729 else
4731 CHECK_TYPE_RANGED_INTEGER (int, left);
4732 f->left_pos = XINT (left);
4733 if (f->left_pos < 0)
4734 window_prompting |= XNegative;
4737 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4738 window_prompting |= USPosition;
4739 else
4740 window_prompting |= PPosition;
4743 if (window_prompting & XNegative)
4745 if (window_prompting & YNegative)
4746 f->win_gravity = SouthEastGravity;
4747 else
4748 f->win_gravity = NorthEastGravity;
4750 else
4752 if (window_prompting & YNegative)
4753 f->win_gravity = SouthWestGravity;
4754 else
4755 f->win_gravity = NorthWestGravity;
4758 f->size_hint_flags = window_prompting;
4760 return window_prompting;
4765 #endif /* HAVE_WINDOW_SYSTEM */
4767 void
4768 frame_make_pointer_invisible (struct frame *f)
4770 if (! NILP (Vmake_pointer_invisible))
4772 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4773 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4775 f->mouse_moved = 0;
4776 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4777 f->pointer_invisible = 1;
4782 void
4783 frame_make_pointer_visible (struct frame *f)
4785 /* We don't check Vmake_pointer_invisible here in case the
4786 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4787 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4788 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4790 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4791 f->pointer_invisible = 0;
4795 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4796 Sframe_pointer_visible_p, 0, 1, 0,
4797 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4798 Otherwise it returns nil. FRAME omitted or nil means the
4799 selected frame. This is useful when `make-pointer-invisible' is set. */)
4800 (Lisp_Object frame)
4802 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4807 /***********************************************************************
4808 Multimonitor data
4809 ***********************************************************************/
4811 #ifdef HAVE_WINDOW_SYSTEM
4813 # if (defined HAVE_NS \
4814 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4815 void
4816 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4818 int i;
4819 for (i = 0; i < n_monitors; ++i)
4820 xfree (monitors[i].name);
4821 xfree (monitors);
4823 # endif
4825 Lisp_Object
4826 make_monitor_attribute_list (struct MonitorInfo *monitors,
4827 int n_monitors,
4828 int primary_monitor,
4829 Lisp_Object monitor_frames,
4830 const char *source)
4832 Lisp_Object attributes_list = Qnil;
4833 Lisp_Object primary_monitor_attributes = Qnil;
4834 int i;
4836 for (i = 0; i < n_monitors; ++i)
4838 Lisp_Object geometry, workarea, attributes = Qnil;
4839 struct MonitorInfo *mi = &monitors[i];
4841 if (mi->geom.width == 0) continue;
4843 workarea = list4i (mi->work.x, mi->work.y,
4844 mi->work.width, mi->work.height);
4845 geometry = list4i (mi->geom.x, mi->geom.y,
4846 mi->geom.width, mi->geom.height);
4847 attributes = Fcons (Fcons (Qsource, build_string (source)),
4848 attributes);
4849 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4850 attributes);
4851 attributes = Fcons (Fcons (Qmm_size,
4852 list2i (mi->mm_width, mi->mm_height)),
4853 attributes);
4854 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4855 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4856 if (mi->name)
4857 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4858 strlen (mi->name))),
4859 attributes);
4861 if (i == primary_monitor)
4862 primary_monitor_attributes = attributes;
4863 else
4864 attributes_list = Fcons (attributes, attributes_list);
4867 if (!NILP (primary_monitor_attributes))
4868 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4869 return attributes_list;
4872 #endif /* HAVE_WINDOW_SYSTEM */
4875 /***********************************************************************
4876 Initialization
4877 ***********************************************************************/
4879 void
4880 syms_of_frame (void)
4882 DEFSYM (Qframep, "framep");
4883 DEFSYM (Qframe_live_p, "frame-live-p");
4884 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4885 DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total");
4886 DEFSYM (Qexplicit_name, "explicit-name");
4887 DEFSYM (Qheight, "height");
4888 DEFSYM (Qicon, "icon");
4889 DEFSYM (Qminibuffer, "minibuffer");
4890 DEFSYM (Qmodeline, "modeline");
4891 DEFSYM (Qonly, "only");
4892 DEFSYM (Qnone, "none");
4893 DEFSYM (Qwidth, "width");
4894 DEFSYM (Qtext_pixels, "text-pixels");
4895 DEFSYM (Qgeometry, "geometry");
4896 DEFSYM (Qicon_left, "icon-left");
4897 DEFSYM (Qicon_top, "icon-top");
4898 DEFSYM (Qtooltip, "tooltip");
4899 DEFSYM (Quser_position, "user-position");
4900 DEFSYM (Quser_size, "user-size");
4901 DEFSYM (Qwindow_id, "window-id");
4902 #ifdef HAVE_X_WINDOWS
4903 DEFSYM (Qouter_window_id, "outer-window-id");
4904 #endif
4905 DEFSYM (Qparent_id, "parent-id");
4906 DEFSYM (Qx, "x");
4907 DEFSYM (Qw32, "w32");
4908 DEFSYM (Qpc, "pc");
4909 DEFSYM (Qns, "ns");
4910 DEFSYM (Qvisible, "visible");
4911 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4912 DEFSYM (Qbuffer_list, "buffer-list");
4913 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4914 DEFSYM (Qdisplay_type, "display-type");
4915 DEFSYM (Qbackground_mode, "background-mode");
4916 DEFSYM (Qnoelisp, "noelisp");
4917 DEFSYM (Qtty_color_mode, "tty-color-mode");
4918 DEFSYM (Qtty, "tty");
4919 DEFSYM (Qtty_type, "tty-type");
4921 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4923 DEFSYM (Qfullwidth, "fullwidth");
4924 DEFSYM (Qfullheight, "fullheight");
4925 DEFSYM (Qfullboth, "fullboth");
4926 DEFSYM (Qmaximized, "maximized");
4927 DEFSYM (Qx_resource_name, "x-resource-name");
4928 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4930 DEFSYM (Qterminal, "terminal");
4932 DEFSYM (Qworkarea, "workarea");
4933 DEFSYM (Qmm_size, "mm-size");
4934 DEFSYM (Qframes, "frames");
4935 DEFSYM (Qsource, "source");
4937 DEFSYM (Qouter_edges, "outer-edges");
4938 DEFSYM (Qouter_position, "outer-position");
4939 DEFSYM (Qouter_size, "outer-size");
4940 DEFSYM (Qnative_edges, "native-edges");
4941 DEFSYM (Qinner_edges, "inner-edges");
4942 DEFSYM (Qexternal_border_size, "external-border-size");
4943 DEFSYM (Qtitle_bar_size, "title-bar-size");
4944 DEFSYM (Qmenu_bar_external, "menu-bar-external");
4945 DEFSYM (Qmenu_bar_size, "menu-bar-size");
4946 DEFSYM (Qtool_bar_external, "tool-bar-external");
4947 DEFSYM (Qtool_bar_size, "tool-bar-size");
4948 /* The following are used for frame_size_history. */
4949 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
4950 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
4951 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
4952 DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
4953 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
4954 DEFSYM (Qset_frame_size, "set-frame-size");
4955 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
4956 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
4957 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
4958 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
4959 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
4960 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
4961 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
4962 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
4963 DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
4964 DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
4965 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
4966 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
4967 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
4968 DEFSYM (Qtb_size_cb, "tb-size-cb");
4969 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
4970 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
4971 DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines");
4972 DEFSYM (Qchange_frame_size, "change-frame-size");
4973 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
4974 DEFSYM (Qset_window_configuration, "set-window-configuration");
4975 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
4976 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
4977 DEFSYM (Qterminal_frame, "terminal-frame");
4979 #ifdef HAVE_NS
4980 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4981 #endif
4983 DEFSYM (Qalpha, "alpha");
4984 DEFSYM (Qauto_lower, "auto-lower");
4985 DEFSYM (Qauto_raise, "auto-raise");
4986 DEFSYM (Qborder_color, "border-color");
4987 DEFSYM (Qborder_width, "border-width");
4988 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
4989 DEFSYM (Qcursor_color, "cursor-color");
4990 DEFSYM (Qcursor_type, "cursor-type");
4991 DEFSYM (Qfont_backend, "font-backend");
4992 DEFSYM (Qfullscreen, "fullscreen");
4993 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
4994 DEFSYM (Qicon_name, "icon-name");
4995 DEFSYM (Qicon_type, "icon-type");
4996 DEFSYM (Qinternal_border_width, "internal-border-width");
4997 DEFSYM (Qleft_fringe, "left-fringe");
4998 DEFSYM (Qline_spacing, "line-spacing");
4999 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
5000 DEFSYM (Qupdate_frame_menubar, "update-frame-menubar");
5001 DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1");
5002 DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2");
5003 DEFSYM (Qmouse_color, "mouse-color");
5004 DEFSYM (Qname, "name");
5005 DEFSYM (Qright_divider_width, "right-divider-width");
5006 DEFSYM (Qright_fringe, "right-fringe");
5007 DEFSYM (Qscreen_gamma, "screen-gamma");
5008 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
5009 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
5010 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
5011 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
5012 DEFSYM (Qsticky, "sticky");
5013 DEFSYM (Qtitle, "title");
5014 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
5015 DEFSYM (Qtool_bar_position, "tool-bar-position");
5016 DEFSYM (Qunsplittable, "unsplittable");
5017 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
5018 DEFSYM (Qvisibility, "visibility");
5019 DEFSYM (Qwait_for_wm, "wait-for-wm");
5020 DEFSYM (Qinhibit_double_buffering, "inhibit-double-buffering");
5023 int i;
5025 for (i = 0; i < ARRAYELTS (frame_parms); i++)
5027 Lisp_Object v = (frame_parms[i].sym < 0
5028 ? intern_c_string (frame_parms[i].name)
5029 : builtin_lisp_symbol (frame_parms[i].sym));
5030 Fput (v, Qx_frame_parameter, make_number (i));
5034 #ifdef HAVE_WINDOW_SYSTEM
5035 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
5036 doc: /* The name Emacs uses to look up X resources.
5037 `x-get-resource' uses this as the first component of the instance name
5038 when requesting resource values.
5039 Emacs initially sets `x-resource-name' to the name under which Emacs
5040 was invoked, or to the value specified with the `-name' or `-rn'
5041 switches, if present.
5043 It may be useful to bind this variable locally around a call
5044 to `x-get-resource'. See also the variable `x-resource-class'. */);
5045 Vx_resource_name = Qnil;
5047 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5048 doc: /* The class Emacs uses to look up X resources.
5049 `x-get-resource' uses this as the first component of the instance class
5050 when requesting resource values.
5052 Emacs initially sets `x-resource-class' to "Emacs".
5054 Setting this variable permanently is not a reasonable thing to do,
5055 but binding this variable locally around a call to `x-get-resource'
5056 is a reasonable practice. See also the variable `x-resource-name'. */);
5057 Vx_resource_class = build_string (EMACS_CLASS);
5059 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5060 doc: /* The lower limit of the frame opacity (alpha transparency).
5061 The value should range from 0 (invisible) to 100 (completely opaque).
5062 You can also use a floating number between 0.0 and 1.0. */);
5063 Vframe_alpha_lower_limit = make_number (20);
5064 #endif
5066 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5067 doc: /* Alist of default values for frame creation.
5068 These may be set in your init file, like this:
5069 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5070 These override values given in window system configuration data,
5071 including X Windows' defaults database.
5072 For values specific to the first Emacs frame, see `initial-frame-alist'.
5073 For window-system specific values, see `window-system-default-frame-alist'.
5074 For values specific to the separate minibuffer frame, see
5075 `minibuffer-frame-alist'.
5076 The `menu-bar-lines' element of the list controls whether new frames
5077 have menu bars; `menu-bar-mode' works by altering this element.
5078 Setting this variable does not affect existing frames, only new ones. */);
5079 Vdefault_frame_alist = Qnil;
5081 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5082 doc: /* Default position of vertical scroll bars on this window-system. */);
5083 #ifdef HAVE_WINDOW_SYSTEM
5084 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5085 /* MS-Windows, macOS, and GTK have scroll bars on the right by
5086 default. */
5087 Vdefault_frame_scroll_bars = Qright;
5088 #else
5089 Vdefault_frame_scroll_bars = Qleft;
5090 #endif
5091 #else
5092 Vdefault_frame_scroll_bars = Qnil;
5093 #endif
5095 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5096 scroll_bar_adjust_thumb_portion_p,
5097 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5098 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5099 even if the end of the buffer is shown (i.e. overscrolling).
5100 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5101 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5102 is visible. In this case you can not overscroll. */);
5103 scroll_bar_adjust_thumb_portion_p = 1;
5105 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5106 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5108 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5109 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5110 `mouse-position' and `mouse-pixel-position' call this function, passing their
5111 usual return value as argument, and return whatever this function returns.
5112 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5113 which need to do mouse handling at the Lisp level. */);
5114 Vmouse_position_function = Qnil;
5116 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5117 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5118 If the value is an integer, highlighting is only shown after moving the
5119 mouse, while keyboard input turns off the highlight even when the mouse
5120 is over the clickable text. However, the mouse shape still indicates
5121 when the mouse is over clickable text. */);
5122 Vmouse_highlight = Qt;
5124 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5125 doc: /* If non-nil, make pointer invisible while typing.
5126 The pointer becomes visible again when the mouse is moved. */);
5127 Vmake_pointer_invisible = Qt;
5129 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5130 doc: /* Normal hook run when a frame gains input focus. */);
5131 Vfocus_in_hook = Qnil;
5133 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5134 doc: /* Normal hook run when a frame loses input focus. */);
5135 Vfocus_out_hook = Qnil;
5137 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5138 doc: /* Functions run before deleting a frame.
5139 The functions are run with one arg, the frame to be deleted.
5140 See `delete-frame'.
5142 Note that functions in this list may be called just before the frame is
5143 actually deleted, or some time later (or even both when an earlier function
5144 in `delete-frame-functions' (indirectly) calls `delete-frame'
5145 recursively). */);
5146 Vdelete_frame_functions = Qnil;
5147 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5149 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5150 doc: /* Non-nil if Menu-Bar mode is enabled.
5151 See the command `menu-bar-mode' for a description of this minor mode.
5152 Setting this variable directly does not take effect;
5153 either customize it (see the info node `Easy Customization')
5154 or call the function `menu-bar-mode'. */);
5155 Vmenu_bar_mode = Qt;
5157 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5158 doc: /* Non-nil if Tool-Bar mode is enabled.
5159 See the command `tool-bar-mode' for a description of this minor mode.
5160 Setting this variable directly does not take effect;
5161 either customize it (see the info node `Easy Customization')
5162 or call the function `tool-bar-mode'. */);
5163 #ifdef HAVE_WINDOW_SYSTEM
5164 Vtool_bar_mode = Qt;
5165 #else
5166 Vtool_bar_mode = Qnil;
5167 #endif
5169 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5170 doc: /* Minibufferless frames use this frame's minibuffer.
5171 Emacs cannot create minibufferless frames unless this is set to an
5172 appropriate surrogate.
5174 Emacs consults this variable only when creating minibufferless
5175 frames; once the frame is created, it sticks with its assigned
5176 minibuffer, no matter what this variable is set to. This means that
5177 this variable doesn't necessarily say anything meaningful about the
5178 current set of frames, or where the minibuffer is currently being
5179 displayed.
5181 This variable is local to the current terminal and cannot be buffer-local. */);
5183 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
5184 doc: /* Non-nil if window system changes focus when you move the mouse.
5185 You should set this variable to tell Emacs how your window manager
5186 handles focus, since there is no way in general for Emacs to find out
5187 automatically. See also `mouse-autoselect-window'. */);
5188 focus_follows_mouse = 0;
5190 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5191 doc: /* Non-nil means resize frames pixelwise.
5192 If this option is nil, resizing a frame rounds its sizes to the frame's
5193 current values of `frame-char-height' and `frame-char-width'. If this
5194 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5195 by one pixel.
5197 With some window managers you may have to set this to non-nil in order
5198 to set the size of a frame in pixels, to maximize frames or to make them
5199 fullscreen. To resize your initial frame pixelwise, set this option to
5200 a non-nil value in your init file. */);
5201 frame_resize_pixelwise = 0;
5203 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5204 doc: /* Whether frames should be resized implicitly.
5205 If this option is nil, setting font, menu bar, tool bar, internal
5206 borders, fringes or scroll bars of a specific frame may resize the frame
5207 in order to preserve the number of columns or lines it displays. If
5208 this option is t, no such resizing is done. Note that the size of
5209 fullscreen and maximized frames, the height of fullheight frames and the
5210 width of fullwidth frames never change implicitly.
5212 The value of this option can be also be a list of frame parameters. In
5213 this case, resizing is inhibited when changing a parameter that appears
5214 in that list. The parameters currently handled by this option include
5215 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5216 `tool-bar-lines'.
5218 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5219 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5220 `right-fringe' is handled as if the frame contained just one live
5221 window. This means, for example, that removing vertical scroll bars on
5222 a frame containing several side by side windows will shrink the frame
5223 width by the width of one scroll bar provided this option is nil and
5224 keep it unchanged if this option is either t or a list containing
5225 `vertical-scroll-bars'.
5227 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
5228 \(which means that adding/removing a tool bar does not change the frame
5229 height), nil on all other window systems including GTK+ (which means
5230 that changing any of the parameters listed above may change the size of
5231 the frame), and t otherwise (which means the frame size never changes
5232 implicitly when there's no window system support).
5234 Note that when a frame is not large enough to accommodate a change of
5235 any of the parameters listed above, Emacs may try to enlarge the frame
5236 even if this option is non-nil. */);
5237 #if defined (HAVE_WINDOW_SYSTEM)
5238 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
5239 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
5240 #else
5241 frame_inhibit_implied_resize = Qnil;
5242 #endif
5243 #else
5244 frame_inhibit_implied_resize = Qt;
5245 #endif
5247 DEFVAR_LISP ("frame-size-history", frame_size_history,
5248 doc: /* History of frame size adjustments.
5249 If non-nil, list recording frame size adjustment. Adjustments are
5250 recorded only if the first element of this list is a positive number.
5251 Adding an adjustment decrements that number by one.
5253 The remaining elements are the adjustments. Each adjustment is a list
5254 of four elements `frame', `function', `sizes' and `more'. `frame' is
5255 the affected frame and `function' the invoking function. `sizes' is
5256 usually a list of four elements `old-width', `old-height', `new-width'
5257 and `new-height' representing the old and new sizes recorded/requested
5258 by `function'. `more' is a list with additional information.
5260 The function `frame--size-history' displays the value of this variable
5261 in a more readable form. */);
5262 frame_size_history = Qnil;
5264 DEFVAR_BOOL ("tooltip-reuse-hidden-frame", tooltip_reuse_hidden_frame,
5265 doc: /* Non-nil means reuse hidden tooltip frames.
5266 When this is nil, delete a tooltip frame when hiding the associated
5267 tooltip. When this is non-nil, make the tooltip frame invisible only,
5268 so it can be reused when the next tooltip is shown.
5270 Setting this to non-nil may drastically reduce the consing overhead
5271 incurred by creating new tooltip frames. However, a value of non-nil
5272 means also that intermittent changes of faces or `default-frame-alist'
5273 are not applied when showing a tooltip in a reused frame.
5275 This variable is effective only with the X toolkit (and there only when
5276 Gtk+ tooltips are not used) and on Windows. */);
5277 tooltip_reuse_hidden_frame = false;
5279 staticpro (&Vframe_list);
5281 defsubr (&Sframep);
5282 defsubr (&Sframe_live_p);
5283 defsubr (&Swindow_system);
5284 defsubr (&Sframe_windows_min_size);
5285 defsubr (&Smake_terminal_frame);
5286 defsubr (&Shandle_switch_frame);
5287 defsubr (&Sselect_frame);
5288 defsubr (&Sselected_frame);
5289 defsubr (&Sframe_list);
5290 defsubr (&Snext_frame);
5291 defsubr (&Sprevious_frame);
5292 defsubr (&Slast_nonminibuf_frame);
5293 defsubr (&Sdelete_frame);
5294 defsubr (&Smouse_position);
5295 defsubr (&Smouse_pixel_position);
5296 defsubr (&Sset_mouse_position);
5297 defsubr (&Sset_mouse_pixel_position);
5298 #if 0
5299 defsubr (&Sframe_configuration);
5300 defsubr (&Srestore_frame_configuration);
5301 #endif
5302 defsubr (&Smake_frame_visible);
5303 defsubr (&Smake_frame_invisible);
5304 defsubr (&Siconify_frame);
5305 defsubr (&Sframe_visible_p);
5306 defsubr (&Svisible_frame_list);
5307 defsubr (&Sraise_frame);
5308 defsubr (&Slower_frame);
5309 defsubr (&Sx_focus_frame);
5310 defsubr (&Sframe_after_make_frame);
5311 defsubr (&Sredirect_frame_focus);
5312 defsubr (&Sframe_focus);
5313 defsubr (&Sframe_parameters);
5314 defsubr (&Sframe_parameter);
5315 defsubr (&Smodify_frame_parameters);
5316 defsubr (&Sframe_char_height);
5317 defsubr (&Sframe_char_width);
5318 defsubr (&Sframe_pixel_height);
5319 defsubr (&Sframe_pixel_width);
5320 defsubr (&Sframe_text_cols);
5321 defsubr (&Sframe_text_lines);
5322 defsubr (&Sframe_total_cols);
5323 defsubr (&Sframe_total_lines);
5324 defsubr (&Sframe_text_width);
5325 defsubr (&Sframe_text_height);
5326 defsubr (&Sscroll_bar_width);
5327 defsubr (&Sscroll_bar_height);
5328 defsubr (&Sfringe_width);
5329 defsubr (&Sborder_width);
5330 defsubr (&Sright_divider_width);
5331 defsubr (&Sbottom_divider_width);
5332 defsubr (&Stool_bar_pixel_width);
5333 defsubr (&Sset_frame_height);
5334 defsubr (&Sset_frame_width);
5335 defsubr (&Sset_frame_size);
5336 defsubr (&Sframe_position);
5337 defsubr (&Sset_frame_position);
5338 defsubr (&Sframe_pointer_visible_p);
5340 #ifdef HAVE_WINDOW_SYSTEM
5341 defsubr (&Sx_get_resource);
5342 defsubr (&Sx_parse_geometry);
5343 #endif