Add more branch support to vc-dir
[emacs.git] / src / frame.c
blob5e1e2f19906837bdfb972749efcbd57b5f72c91d
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 return Qnil;
2162 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2163 1, 1, 0,
2164 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2165 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2166 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2167 On graphical displays, invisible frames are not updated and are
2168 usually not displayed at all, even in a window system's \"taskbar\".
2170 If FRAME is a text terminal frame, this always returns t.
2171 Such frames are always considered visible, whether or not they are
2172 currently being displayed on the terminal. */)
2173 (Lisp_Object frame)
2175 CHECK_LIVE_FRAME (frame);
2177 if (FRAME_VISIBLE_P (XFRAME (frame)))
2178 return Qt;
2179 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2180 return Qicon;
2181 return Qnil;
2184 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2185 0, 0, 0,
2186 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2187 (void)
2189 Lisp_Object tail, frame, value = Qnil;
2191 FOR_EACH_FRAME (tail, frame)
2192 if (FRAME_VISIBLE_P (XFRAME (frame)))
2193 value = Fcons (frame, value);
2195 return value;
2199 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2200 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2201 If FRAME is invisible or iconified, make it visible.
2202 If you don't specify a frame, the selected frame is used.
2203 If Emacs is displaying on an ordinary terminal or some other device which
2204 doesn't support multiple overlapping frames, this function selects FRAME. */)
2205 (Lisp_Object frame)
2207 struct frame *f = decode_live_frame (frame);
2209 XSETFRAME (frame, f);
2211 if (FRAME_TERMCAP_P (f))
2212 /* On a text terminal select FRAME. */
2213 Fselect_frame (frame, Qnil);
2214 else
2215 /* Do like the documentation says. */
2216 Fmake_frame_visible (frame);
2218 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2219 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2221 return Qnil;
2224 /* Should we have a corresponding function called Flower_Power? */
2225 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2226 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2227 If you don't specify a frame, the selected frame is used.
2228 If Emacs is displaying on an ordinary terminal or some other device which
2229 doesn't support multiple overlapping frames, this function does nothing. */)
2230 (Lisp_Object frame)
2232 struct frame *f = decode_live_frame (frame);
2234 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2235 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2237 return Qnil;
2241 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2242 1, 2, 0,
2243 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2244 In other words, switch-frame events caused by events in FRAME will
2245 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2246 FOCUS-FRAME after reading an event typed at FRAME.
2248 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2249 frame again receives its own keystrokes.
2251 Focus redirection is useful for temporarily redirecting keystrokes to
2252 a surrogate minibuffer frame when a frame doesn't have its own
2253 minibuffer window.
2255 A frame's focus redirection can be changed by `select-frame'. If frame
2256 FOO is selected, and then a different frame BAR is selected, any
2257 frames redirecting their focus to FOO are shifted to redirect their
2258 focus to BAR. This allows focus redirection to work properly when the
2259 user switches from one frame to another using `select-window'.
2261 This means that a frame whose focus is redirected to itself is treated
2262 differently from a frame whose focus is redirected to nil; the former
2263 is affected by `select-frame', while the latter is not.
2265 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2266 (Lisp_Object frame, Lisp_Object focus_frame)
2268 /* Note that we don't check for a live frame here. It's reasonable
2269 to redirect the focus of a frame you're about to delete, if you
2270 know what other frame should receive those keystrokes. */
2271 struct frame *f = decode_any_frame (frame);
2273 if (! NILP (focus_frame))
2274 CHECK_LIVE_FRAME (focus_frame);
2276 fset_focus_frame (f, focus_frame);
2278 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2279 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2281 return Qnil;
2285 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2286 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2287 If FRAME is omitted or nil, the selected frame is used.
2288 Return nil if FRAME's focus is not redirected.
2289 See `redirect-frame-focus'. */)
2290 (Lisp_Object frame)
2292 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2295 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2296 doc: /* Set the input focus to FRAME.
2297 FRAME nil means use the selected frame.
2298 If there is no window system support, this function does nothing. */)
2299 (Lisp_Object frame)
2301 #ifdef HAVE_WINDOW_SYSTEM
2302 x_focus_frame (decode_window_system_frame (frame));
2303 #endif
2304 return Qnil;
2307 DEFUN ("frame-after-make-frame",
2308 Fframe_after_make_frame,
2309 Sframe_after_make_frame, 2, 2, 0,
2310 doc: /* Mark FRAME as made.
2311 FRAME nil means use the selected frame. Second argument MADE non-nil
2312 means functions on `window-configuration-change-hook' are called
2313 whenever the window configuration of FRAME changes. MADE nil means
2314 these functions are not called.
2316 This function is currently called by `make-frame' only and should be
2317 otherwise used with utter care to avoid that running functions on
2318 `window-configuration-change-hook' is impeded forever. */)
2319 (Lisp_Object frame, Lisp_Object made)
2321 struct frame *f = decode_live_frame (frame);
2322 f->after_make_frame = !NILP (made);
2323 f->inhibit_horizontal_resize = false;
2324 f->inhibit_vertical_resize = false;
2325 return made;
2329 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2331 void
2332 frames_discard_buffer (Lisp_Object buffer)
2334 Lisp_Object frame, tail;
2336 FOR_EACH_FRAME (tail, frame)
2338 fset_buffer_list
2339 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2340 fset_buried_buffer_list
2341 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2345 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2346 If the alist already has an element for PROP, we change it. */
2348 void
2349 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2351 register Lisp_Object tem;
2353 tem = Fassq (prop, *alistptr);
2354 if (EQ (tem, Qnil))
2355 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2356 else
2357 Fsetcdr (tem, val);
2360 static int
2361 frame_name_fnn_p (char *str, ptrdiff_t len)
2363 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2365 char *p = str + 2;
2366 while ('0' <= *p && *p <= '9')
2367 p++;
2368 if (p == str + len)
2369 return 1;
2371 return 0;
2374 /* Set the name of the terminal frame. Also used by MSDOS frames.
2375 Modeled after x_set_name which is used for WINDOW frames. */
2377 static void
2378 set_term_frame_name (struct frame *f, Lisp_Object name)
2380 f->explicit_name = ! NILP (name);
2382 /* If NAME is nil, set the name to F<num>. */
2383 if (NILP (name))
2385 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2387 /* Check for no change needed in this very common case
2388 before we do any consing. */
2389 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2390 return;
2392 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2394 else
2396 CHECK_STRING (name);
2398 /* Don't change the name if it's already NAME. */
2399 if (! NILP (Fstring_equal (name, f->name)))
2400 return;
2402 /* Don't allow the user to set the frame name to F<num>, so it
2403 doesn't clash with the names we generate for terminal frames. */
2404 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2405 error ("Frame names of the form F<num> are usurped by Emacs");
2408 fset_name (f, name);
2409 update_mode_lines = 16;
2412 void
2413 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2415 register Lisp_Object old_alist_elt;
2417 if (EQ (prop, Qminibuffer))
2419 if (WINDOWP (val))
2421 if (!MINI_WINDOW_P (XWINDOW (val)))
2422 error ("The `minibuffer' parameter does not specify a valid minibuffer window");
2423 else if (FRAME_MINIBUF_ONLY_P (f))
2425 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2426 val = Qonly;
2427 else
2428 error ("Can't change the minibuffer window of a minibuffer-only frame");
2430 else if (FRAME_HAS_MINIBUF_P (f))
2432 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2433 val = Qt;
2434 else
2435 error ("Can't change the minibuffer window of a frame with its own minibuffer");
2437 else
2438 /* Store the chosen minibuffer window. */
2439 fset_minibuffer_window (f, val);
2441 else
2443 Lisp_Object old_val = Fcdr (Fassq (Qminibuffer, f->param_alist));
2445 if (!NILP (old_val))
2447 if (WINDOWP (old_val) && NILP (val))
2448 /* Don't change the value for a minibuffer-less frame if
2449 only nil was specified as new value. */
2450 val = old_val;
2451 else if (!EQ (old_val, val))
2452 error ("Can't change the `minibuffer' parameter of this frame");
2457 /* The buffer-list parameters are stored in a special place and not
2458 in the alist. All buffers must be live. */
2459 if (EQ (prop, Qbuffer_list))
2461 Lisp_Object list = Qnil;
2462 for (; CONSP (val); val = XCDR (val))
2463 if (!NILP (Fbuffer_live_p (XCAR (val))))
2464 list = Fcons (XCAR (val), list);
2465 fset_buffer_list (f, Fnreverse (list));
2466 return;
2468 if (EQ (prop, Qburied_buffer_list))
2470 Lisp_Object list = Qnil;
2471 for (; CONSP (val); val = XCDR (val))
2472 if (!NILP (Fbuffer_live_p (XCAR (val))))
2473 list = Fcons (XCAR (val), list);
2474 fset_buried_buffer_list (f, Fnreverse (list));
2475 return;
2478 /* The tty color needed to be set before the frame's parameter
2479 alist was updated with the new value. This is not true any more,
2480 but we still do this test early on. */
2481 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2482 && f == FRAME_TTY (f)->previous_frame)
2483 /* Force redisplay of this tty. */
2484 FRAME_TTY (f)->previous_frame = NULL;
2486 /* Update the frame parameter alist. */
2487 old_alist_elt = Fassq (prop, f->param_alist);
2488 if (EQ (old_alist_elt, Qnil))
2489 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2490 else
2491 Fsetcdr (old_alist_elt, val);
2493 /* Update some other special parameters in their special places
2494 in addition to the alist. */
2496 if (EQ (prop, Qbuffer_predicate))
2497 fset_buffer_predicate (f, val);
2499 if (! FRAME_WINDOW_P (f))
2501 if (EQ (prop, Qmenu_bar_lines))
2502 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2503 else if (EQ (prop, Qname))
2504 set_term_frame_name (f, val);
2508 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2509 is not an unspecified foreground or background color. */
2511 static Lisp_Object
2512 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2514 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2515 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2516 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2517 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2520 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2521 doc: /* Return the parameters-alist of frame FRAME.
2522 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2523 The meaningful PARMs depend on the kind of frame.
2524 If FRAME is omitted or nil, return information on the currently selected frame. */)
2525 (Lisp_Object frame)
2527 Lisp_Object alist;
2528 struct frame *f = decode_any_frame (frame);
2529 int height, width;
2531 if (!FRAME_LIVE_P (f))
2532 return Qnil;
2534 alist = Fcopy_alist (f->param_alist);
2536 if (!FRAME_WINDOW_P (f))
2538 Lisp_Object elt;
2540 /* If the frame's parameter alist says the colors are
2541 unspecified and reversed, take the frame's background pixel
2542 for foreground and vice versa. */
2543 elt = Fassq (Qforeground_color, alist);
2544 if (CONSP (elt) && STRINGP (XCDR (elt)))
2546 elt = frame_unspecified_color (f, XCDR (elt));
2547 if (!NILP (elt))
2548 store_in_alist (&alist, Qforeground_color, elt);
2550 else
2551 store_in_alist (&alist, Qforeground_color,
2552 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2553 elt = Fassq (Qbackground_color, alist);
2554 if (CONSP (elt) && STRINGP (XCDR (elt)))
2556 elt = frame_unspecified_color (f, XCDR (elt));
2557 if (!NILP (elt))
2558 store_in_alist (&alist, Qbackground_color, elt);
2560 else
2561 store_in_alist (&alist, Qbackground_color,
2562 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2563 store_in_alist (&alist, Qfont,
2564 build_string (FRAME_MSDOS_P (f)
2565 ? "ms-dos"
2566 : FRAME_W32_P (f) ? "w32term"
2567 :"tty"));
2569 store_in_alist (&alist, Qname, f->name);
2570 height = (f->new_height
2571 ? (f->new_pixelwise
2572 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2573 : f->new_height)
2574 : FRAME_LINES (f));
2575 store_in_alist (&alist, Qheight, make_number (height));
2576 width = (f->new_width
2577 ? (f->new_pixelwise
2578 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2579 : f->new_width)
2580 : FRAME_COLS (f));
2581 store_in_alist (&alist, Qwidth, make_number (width));
2582 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2583 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2584 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2585 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2587 /* I think this should be done with a hook. */
2588 #ifdef HAVE_WINDOW_SYSTEM
2589 if (FRAME_WINDOW_P (f))
2590 x_report_frame_params (f, &alist);
2591 else
2592 #endif
2594 /* This ought to be correct in f->param_alist for an X frame. */
2595 Lisp_Object lines;
2596 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2597 store_in_alist (&alist, Qmenu_bar_lines, lines);
2600 return alist;
2604 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2605 doc: /* Return FRAME's value for parameter PARAMETER.
2606 If FRAME is nil, describe the currently selected frame. */)
2607 (Lisp_Object frame, Lisp_Object parameter)
2609 struct frame *f = decode_any_frame (frame);
2610 Lisp_Object value = Qnil;
2612 CHECK_SYMBOL (parameter);
2614 XSETFRAME (frame, f);
2616 if (FRAME_LIVE_P (f))
2618 /* Avoid consing in frequent cases. */
2619 if (EQ (parameter, Qname))
2620 value = f->name;
2621 #ifdef HAVE_WINDOW_SYSTEM
2622 /* These are used by vertical motion commands. */
2623 else if (EQ (parameter, Qvertical_scroll_bars))
2624 value = (f->vertical_scroll_bar_type == vertical_scroll_bar_none
2625 ? Qnil
2626 : (f->vertical_scroll_bar_type == vertical_scroll_bar_left
2627 ? Qleft : Qright));
2628 else if (EQ (parameter, Qhorizontal_scroll_bars))
2629 value = f->horizontal_scroll_bars ? Qt : Qnil;
2630 else if (EQ (parameter, Qline_spacing) && f->extra_line_spacing == 0)
2631 /* If this is non-zero, we can't determine whether the user specified
2632 an integer or float value without looking through 'param_alist'. */
2633 value = make_number (0);
2634 else if (EQ (parameter, Qfont) && FRAME_X_P (f))
2635 value = FRAME_FONT (f)->props[FONT_NAME_INDEX];
2636 #endif /* HAVE_WINDOW_SYSTEM */
2637 #ifdef HAVE_X_WINDOWS
2638 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2639 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2640 #endif /* HAVE_X_WINDOWS */
2641 else if (EQ (parameter, Qbackground_color)
2642 || EQ (parameter, Qforeground_color))
2644 value = Fassq (parameter, f->param_alist);
2645 if (CONSP (value))
2647 value = XCDR (value);
2648 /* Fframe_parameters puts the actual fg/bg color names,
2649 even if f->param_alist says otherwise. This is
2650 important when param_alist's notion of colors is
2651 "unspecified". We need to do the same here. */
2652 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2654 Lisp_Object tem = frame_unspecified_color (f, value);
2656 if (!NILP (tem))
2657 value = tem;
2660 else
2661 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2663 else if (EQ (parameter, Qdisplay_type)
2664 || EQ (parameter, Qbackground_mode))
2665 value = Fcdr (Fassq (parameter, f->param_alist));
2666 else
2667 /* FIXME: Avoid this code path at all (as well as code duplication)
2668 by sharing more code with Fframe_parameters. */
2669 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2672 return value;
2676 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2677 Smodify_frame_parameters, 2, 2, 0,
2678 doc: /* Modify FRAME according to new values of its parameters in ALIST.
2679 If FRAME is nil, it defaults to the selected frame.
2680 ALIST is an alist of parameters to change and their new values.
2681 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2682 Which PARMs are meaningful depends on the kind of frame.
2683 The meaningful parameters are acted upon, i.e. the frame is changed
2684 according to their new values, and are also stored in the frame's
2685 parameter list so that `frame-parameters' will return them.
2686 PARMs that are not meaningful are still stored in the frame's parameter
2687 list, but are otherwise ignored. */)
2688 (Lisp_Object frame, Lisp_Object alist)
2690 struct frame *f = decode_live_frame (frame);
2691 Lisp_Object prop, val;
2693 /* I think this should be done with a hook. */
2694 #ifdef HAVE_WINDOW_SYSTEM
2695 if (FRAME_WINDOW_P (f))
2696 x_set_frame_parameters (f, alist);
2697 else
2698 #endif
2699 #ifdef MSDOS
2700 if (FRAME_MSDOS_P (f))
2701 IT_set_frame_parameters (f, alist);
2702 else
2703 #endif
2706 EMACS_INT length = XFASTINT (Flength (alist));
2707 ptrdiff_t i;
2708 Lisp_Object *parms;
2709 Lisp_Object *values;
2710 USE_SAFE_ALLOCA;
2711 SAFE_ALLOCA_LISP (parms, 2 * length);
2712 values = parms + length;
2714 /* Extract parm names and values into those vectors. */
2716 for (i = 0; CONSP (alist); alist = XCDR (alist))
2718 Lisp_Object elt;
2720 elt = XCAR (alist);
2721 parms[i] = Fcar (elt);
2722 values[i] = Fcdr (elt);
2723 i++;
2726 /* Now process them in reverse of specified order. */
2727 while (--i >= 0)
2729 prop = parms[i];
2730 val = values[i];
2731 store_frame_param (f, prop, val);
2733 if (EQ (prop, Qforeground_color)
2734 || EQ (prop, Qbackground_color))
2735 update_face_from_frame_parameter (f, prop, val);
2738 SAFE_FREE ();
2740 return Qnil;
2743 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2744 0, 1, 0,
2745 doc: /* Height in pixels of a line in the font in frame FRAME.
2746 If FRAME is omitted or nil, the selected frame is used.
2747 For a terminal frame, the value is always 1. */)
2748 (Lisp_Object frame)
2750 #ifdef HAVE_WINDOW_SYSTEM
2751 struct frame *f = decode_any_frame (frame);
2753 if (FRAME_WINDOW_P (f))
2754 return make_number (FRAME_LINE_HEIGHT (f));
2755 else
2756 #endif
2757 return make_number (1);
2761 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2762 0, 1, 0,
2763 doc: /* Width in pixels of characters in the font in frame FRAME.
2764 If FRAME is omitted or nil, the selected frame is used.
2765 On a graphical screen, the width is the standard width of the default font.
2766 For a terminal screen, the value is always 1. */)
2767 (Lisp_Object frame)
2769 #ifdef HAVE_WINDOW_SYSTEM
2770 struct frame *f = decode_any_frame (frame);
2772 if (FRAME_WINDOW_P (f))
2773 return make_number (FRAME_COLUMN_WIDTH (f));
2774 else
2775 #endif
2776 return make_number (1);
2779 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2780 Sframe_pixel_height, 0, 1, 0,
2781 doc: /* Return a FRAME's height in pixels.
2782 If FRAME is omitted or nil, the selected frame is used. The exact value
2783 of the result depends on the window-system and toolkit in use:
2785 In the Gtk+ version of Emacs, it includes only any window (including
2786 the minibuffer or echo area), mode line, and header line. It does not
2787 include the tool bar or menu bar.
2789 With other graphical versions, it also includes the tool bar and the
2790 menu bar.
2792 For a text terminal, it includes the menu bar. In this case, the
2793 result is really in characters rather than pixels (i.e., is identical
2794 to `frame-height'). */)
2795 (Lisp_Object frame)
2797 struct frame *f = decode_any_frame (frame);
2799 #ifdef HAVE_WINDOW_SYSTEM
2800 if (FRAME_WINDOW_P (f))
2801 return make_number (FRAME_PIXEL_HEIGHT (f));
2802 else
2803 #endif
2804 return make_number (FRAME_TOTAL_LINES (f));
2807 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2808 Sframe_pixel_width, 0, 1, 0,
2809 doc: /* Return FRAME's width in pixels.
2810 For a terminal frame, the result really gives the width in characters.
2811 If FRAME is omitted or nil, the selected frame is used. */)
2812 (Lisp_Object frame)
2814 struct frame *f = decode_any_frame (frame);
2816 #ifdef HAVE_WINDOW_SYSTEM
2817 if (FRAME_WINDOW_P (f))
2818 return make_number (FRAME_PIXEL_WIDTH (f));
2819 else
2820 #endif
2821 return make_number (FRAME_TOTAL_COLS (f));
2824 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2825 Stool_bar_pixel_width, 0, 1, 0,
2826 doc: /* Return width in pixels of FRAME's tool bar.
2827 The result is greater than zero only when the tool bar is on the left
2828 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2829 is used. */)
2830 (Lisp_Object frame)
2832 #ifdef FRAME_TOOLBAR_WIDTH
2833 struct frame *f = decode_any_frame (frame);
2835 if (FRAME_WINDOW_P (f))
2836 return make_number (FRAME_TOOLBAR_WIDTH (f));
2837 #endif
2838 return make_number (0);
2841 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2842 doc: /* Return width in columns of FRAME's text area. */)
2843 (Lisp_Object frame)
2845 return make_number (FRAME_COLS (decode_any_frame (frame)));
2848 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2849 doc: /* Return height in lines of FRAME's text area. */)
2850 (Lisp_Object frame)
2852 return make_number (FRAME_LINES (decode_any_frame (frame)));
2855 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2856 doc: /* Return number of total columns of FRAME. */)
2857 (Lisp_Object frame)
2859 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2862 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2863 doc: /* Return number of total lines of FRAME. */)
2864 (Lisp_Object frame)
2866 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2869 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2870 doc: /* Return text area width of FRAME in pixels. */)
2871 (Lisp_Object frame)
2873 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2876 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2877 doc: /* Return text area height of FRAME in pixels. */)
2878 (Lisp_Object frame)
2880 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2883 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2884 doc: /* Return scroll bar width of FRAME in pixels. */)
2885 (Lisp_Object frame)
2887 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2890 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2891 doc: /* Return scroll bar height of FRAME in pixels. */)
2892 (Lisp_Object frame)
2894 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2897 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2898 doc: /* Return fringe width of FRAME in pixels. */)
2899 (Lisp_Object frame)
2901 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2904 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2905 doc: /* Return border width of FRAME in pixels. */)
2906 (Lisp_Object frame)
2908 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2911 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2912 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2913 (Lisp_Object frame)
2915 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2918 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2919 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2920 (Lisp_Object frame)
2922 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2925 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2926 doc: /* Set text height of frame FRAME to HEIGHT lines.
2927 Optional third arg PRETEND non-nil means that redisplay should use
2928 HEIGHT lines but that the idea of the actual height of the frame should
2929 not be changed.
2931 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2932 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
2933 window managers may refuse to honor a HEIGHT that is not an integer
2934 multiple of the default frame font height. */)
2935 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2937 struct frame *f = decode_live_frame (frame);
2938 int pixel_height;
2940 CHECK_TYPE_RANGED_INTEGER (int, height);
2942 pixel_height = (!NILP (pixelwise)
2943 ? XINT (height)
2944 : XINT (height) * FRAME_LINE_HEIGHT (f));
2945 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
2947 return Qnil;
2950 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2951 doc: /* Set text width of frame FRAME to WIDTH columns.
2952 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2953 columns but that the idea of the actual width of the frame should not
2954 be changed.
2956 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2957 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
2958 window managers may refuse to honor a WIDTH that is not an integer
2959 multiple of the default frame font width. */)
2960 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2962 struct frame *f = decode_live_frame (frame);
2963 int pixel_width;
2965 CHECK_TYPE_RANGED_INTEGER (int, width);
2967 pixel_width = (!NILP (pixelwise)
2968 ? XINT (width)
2969 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2970 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
2972 return Qnil;
2975 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2976 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
2977 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
2978 When `frame-resize-pixelwise' is nil, some window managers may refuse to
2979 honor a WIDTH that is not an integer multiple of the default frame font
2980 width or a HEIGHT that is not an integer multiple of the default frame
2981 font height. */)
2982 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2984 struct frame *f = decode_live_frame (frame);
2985 int pixel_width, pixel_height;
2987 CHECK_TYPE_RANGED_INTEGER (int, width);
2988 CHECK_TYPE_RANGED_INTEGER (int, height);
2990 pixel_width = (!NILP (pixelwise)
2991 ? XINT (width)
2992 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2993 pixel_height = (!NILP (pixelwise)
2994 ? XINT (height)
2995 : XINT (height) * FRAME_LINE_HEIGHT (f));
2996 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
2998 return Qnil;
3001 DEFUN ("frame-position", Fframe_position,
3002 Sframe_position, 0, 1, 0,
3003 doc: /* Return top left corner of FRAME in pixels.
3004 FRAME must be a live frame and defaults to the selected one. The return
3005 value is a cons (x, y) of the coordinates of the top left corner of
3006 FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's
3007 display. */)
3008 (Lisp_Object frame)
3010 register struct frame *f = decode_live_frame (frame);
3012 return Fcons (make_number (f->left_pos), make_number (f->top_pos));
3015 DEFUN ("set-frame-position", Fset_frame_position,
3016 Sset_frame_position, 3, 3, 0,
3017 doc: /* Set position of FRAME to (X, Y).
3018 FRAME must be a live frame and defaults to the selected one. X and Y,
3019 if positive, specify the coordinate of the left and top edge of FRAME's
3020 outer frame in pixels relative to an origin (0, 0) of FRAME's display.
3021 If any of X or Y is negative, it specifies the coordinates of the right
3022 or bottom edge of the outer frame of FRAME relative to the right or
3023 bottom edge of FRAME's display. */)
3024 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
3026 struct frame *f = decode_live_frame (frame);
3028 CHECK_TYPE_RANGED_INTEGER (int, x);
3029 CHECK_TYPE_RANGED_INTEGER (int, y);
3031 /* I think this should be done with a hook. */
3032 if (FRAME_WINDOW_P (f))
3034 #ifdef HAVE_WINDOW_SYSTEM
3035 x_set_offset (f, XINT (x), XINT (y), 1);
3036 #endif
3039 return Qt;
3043 /***********************************************************************
3044 Frame Parameters
3045 ***********************************************************************/
3047 /* Connect the frame-parameter names for X frames
3048 to the ways of passing the parameter values to the window system.
3050 The name of a parameter, as a Lisp symbol,
3051 has an `x-frame-parameter' property which is an integer in Lisp
3052 that is an index in this table. */
3054 struct frame_parm_table {
3055 const char *name;
3056 int sym;
3059 static const struct frame_parm_table frame_parms[] =
3061 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3062 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3063 {"background-color", -1},
3064 {"border-color", SYMBOL_INDEX (Qborder_color)},
3065 {"border-width", SYMBOL_INDEX (Qborder_width)},
3066 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3067 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3068 {"font", -1},
3069 {"foreground-color", -1},
3070 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3071 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3072 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3073 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3074 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3075 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3076 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3077 {"name", SYMBOL_INDEX (Qname)},
3078 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3079 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3080 {"title", SYMBOL_INDEX (Qtitle)},
3081 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3082 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3083 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3084 {"visibility", SYMBOL_INDEX (Qvisibility)},
3085 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3086 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3087 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3088 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3089 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3090 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3091 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3092 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3093 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3094 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3095 {"alpha", SYMBOL_INDEX (Qalpha)},
3096 {"sticky", SYMBOL_INDEX (Qsticky)},
3097 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3098 {"inhibit-double-buffering", SYMBOL_INDEX (Qinhibit_double_buffering)},
3101 #ifdef HAVE_WINDOW_SYSTEM
3103 /* Change the parameters of frame F as specified by ALIST.
3104 If a parameter is not specially recognized, do nothing special;
3105 otherwise call the `x_set_...' function for that parameter.
3106 Except for certain geometry properties, always call store_frame_param
3107 to store the new value in the parameter alist. */
3109 void
3110 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3112 Lisp_Object tail;
3114 /* If both of these parameters are present, it's more efficient to
3115 set them both at once. So we wait until we've looked at the
3116 entire list before we set them. */
3117 int width = -1, height = -1; /* -1 denotes they were not changed. */
3119 /* Same here. */
3120 Lisp_Object left, top;
3122 /* Same with these. */
3123 Lisp_Object icon_left, icon_top;
3125 /* And with this. */
3126 Lisp_Object fullscreen;
3127 bool fullscreen_change = false;
3129 /* Record in these vectors all the parms specified. */
3130 Lisp_Object *parms;
3131 Lisp_Object *values;
3132 ptrdiff_t i, j, size;
3133 bool left_no_change = 0, top_no_change = 0;
3134 #ifdef HAVE_X_WINDOWS
3135 bool icon_left_no_change = 0, icon_top_no_change = 0;
3136 #endif
3138 for (size = 0, tail = alist; CONSP (tail); tail = XCDR (tail))
3139 size++;
3140 CHECK_LIST_END (tail, alist);
3142 USE_SAFE_ALLOCA;
3143 SAFE_ALLOCA_LISP (parms, 2 * size);
3144 values = parms + size;
3146 /* Extract parm names and values into those vectors. */
3148 i = 0, j = size - 1;
3149 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3151 Lisp_Object elt = XCAR (tail), prop = Fcar (elt), val = Fcdr (elt);
3153 /* Some properties are independent of other properties, but other
3154 properties are dependent upon them. These special properties
3155 are foreground_color, background_color (affects cursor_color)
3156 and font (affects fringe widths); they're recorded starting
3157 from the end of PARMS and VALUES to process them first by using
3158 reverse iteration. */
3160 if (EQ (prop, Qforeground_color)
3161 || EQ (prop, Qbackground_color)
3162 || EQ (prop, Qfont))
3164 parms[j] = prop;
3165 values[j] = val;
3166 j--;
3168 else
3170 parms[i] = prop;
3171 values[i] = val;
3172 i++;
3176 /* TAIL and ALIST are not used again below here. */
3177 alist = tail = Qnil;
3179 top = left = Qunbound;
3180 icon_left = icon_top = Qunbound;
3182 /* Reverse order is used to make sure that special
3183 properties noticed above are processed first. */
3184 for (i = size - 1; i >= 0; i--)
3186 Lisp_Object prop, val;
3188 prop = parms[i];
3189 val = values[i];
3191 if (EQ (prop, Qwidth))
3193 if (RANGED_INTEGERP (0, val, INT_MAX))
3194 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3195 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3196 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3197 width = XFASTINT (XCDR (val));
3199 else if (EQ (prop, Qheight))
3201 if (RANGED_INTEGERP (0, val, INT_MAX))
3202 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3203 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3204 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3205 height = XFASTINT (XCDR (val));
3207 else if (EQ (prop, Qtop))
3208 top = val;
3209 else if (EQ (prop, Qleft))
3210 left = val;
3211 else if (EQ (prop, Qicon_top))
3212 icon_top = val;
3213 else if (EQ (prop, Qicon_left))
3214 icon_left = val;
3215 else if (EQ (prop, Qfullscreen))
3217 fullscreen = val;
3218 fullscreen_change = true;
3220 else
3222 register Lisp_Object param_index, old_value;
3224 old_value = get_frame_param (f, prop);
3226 store_frame_param (f, prop, val);
3228 param_index = Fget (prop, Qx_frame_parameter);
3229 if (NATNUMP (param_index)
3230 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3231 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3232 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3236 /* Don't die if just one of these was set. */
3237 if (EQ (left, Qunbound))
3239 left_no_change = 1;
3240 if (f->left_pos < 0)
3241 left = list2 (Qplus, make_number (f->left_pos));
3242 else
3243 XSETINT (left, f->left_pos);
3245 if (EQ (top, Qunbound))
3247 top_no_change = 1;
3248 if (f->top_pos < 0)
3249 top = list2 (Qplus, make_number (f->top_pos));
3250 else
3251 XSETINT (top, f->top_pos);
3254 /* If one of the icon positions was not set, preserve or default it. */
3255 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3257 #ifdef HAVE_X_WINDOWS
3258 icon_left_no_change = 1;
3259 #endif
3260 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3261 if (NILP (icon_left))
3262 XSETINT (icon_left, 0);
3264 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3266 #ifdef HAVE_X_WINDOWS
3267 icon_top_no_change = 1;
3268 #endif
3269 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3270 if (NILP (icon_top))
3271 XSETINT (icon_top, 0);
3274 /* Don't set these parameters unless they've been explicitly
3275 specified. The window might be mapped or resized while we're in
3276 this function, and we don't want to override that unless the lisp
3277 code has asked for it.
3279 Don't set these parameters unless they actually differ from the
3280 window's current parameters; the window may not actually exist
3281 yet. */
3283 Lisp_Object frame;
3285 XSETFRAME (frame, f);
3287 if ((width != -1 && width != FRAME_TEXT_WIDTH (f))
3288 || (height != -1 && height != FRAME_TEXT_HEIGHT (f)))
3289 /* We could consider checking f->after_make_frame here, but I
3290 don't have the faintest idea why the following is needed at
3291 all. With the old setting it can get a Heisenbug when
3292 EmacsFrameResize intermittently provokes a delayed
3293 change_frame_size in the middle of adjust_frame_size. */
3294 /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
3295 adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters);
3297 if ((!NILP (left) || !NILP (top))
3298 && ! (left_no_change && top_no_change)
3299 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3300 && NUMBERP (top) && XINT (top) == f->top_pos))
3302 int leftpos = 0;
3303 int toppos = 0;
3305 /* Record the signs. */
3306 f->size_hint_flags &= ~ (XNegative | YNegative);
3307 if (EQ (left, Qminus))
3308 f->size_hint_flags |= XNegative;
3309 else if (TYPE_RANGED_INTEGERP (int, left))
3311 leftpos = XINT (left);
3312 if (leftpos < 0)
3313 f->size_hint_flags |= XNegative;
3315 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3316 && CONSP (XCDR (left))
3317 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3319 leftpos = - XINT (XCAR (XCDR (left)));
3320 f->size_hint_flags |= XNegative;
3322 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3323 && CONSP (XCDR (left))
3324 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3326 leftpos = XINT (XCAR (XCDR (left)));
3329 if (EQ (top, Qminus))
3330 f->size_hint_flags |= YNegative;
3331 else if (TYPE_RANGED_INTEGERP (int, top))
3333 toppos = XINT (top);
3334 if (toppos < 0)
3335 f->size_hint_flags |= YNegative;
3337 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3338 && CONSP (XCDR (top))
3339 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3341 toppos = - XINT (XCAR (XCDR (top)));
3342 f->size_hint_flags |= YNegative;
3344 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3345 && CONSP (XCDR (top))
3346 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3348 toppos = XINT (XCAR (XCDR (top)));
3352 /* Store the numeric value of the position. */
3353 f->top_pos = toppos;
3354 f->left_pos = leftpos;
3356 f->win_gravity = NorthWestGravity;
3358 /* Actually set that position, and convert to absolute. */
3359 x_set_offset (f, leftpos, toppos, -1);
3362 if (fullscreen_change)
3364 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
3366 frame_size_history_add
3367 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
3369 store_frame_param (f, Qfullscreen, fullscreen);
3370 if (!EQ (fullscreen, old_value))
3371 x_set_fullscreen (f, fullscreen, old_value);
3375 #ifdef HAVE_X_WINDOWS
3376 if ((!NILP (icon_left) || !NILP (icon_top))
3377 && ! (icon_left_no_change && icon_top_no_change))
3378 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3379 #endif /* HAVE_X_WINDOWS */
3382 SAFE_FREE ();
3386 /* Insert a description of internally-recorded parameters of frame X
3387 into the parameter alist *ALISTPTR that is to be given to the user.
3388 Only parameters that are specific to the X window system
3389 and whose values are not correctly recorded in the frame's
3390 param_alist need to be considered here. */
3392 void
3393 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3395 Lisp_Object tem;
3396 uprintmax_t w;
3397 char buf[INT_BUFSIZE_BOUND (w)];
3399 /* Represent negative positions (off the top or left screen edge)
3400 in a way that Fmodify_frame_parameters will understand correctly. */
3401 XSETINT (tem, f->left_pos);
3402 if (f->left_pos >= 0)
3403 store_in_alist (alistptr, Qleft, tem);
3404 else
3405 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3407 XSETINT (tem, f->top_pos);
3408 if (f->top_pos >= 0)
3409 store_in_alist (alistptr, Qtop, tem);
3410 else
3411 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3413 store_in_alist (alistptr, Qborder_width,
3414 make_number (f->border_width));
3415 store_in_alist (alistptr, Qinternal_border_width,
3416 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3417 store_in_alist (alistptr, Qright_divider_width,
3418 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3419 store_in_alist (alistptr, Qbottom_divider_width,
3420 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3421 store_in_alist (alistptr, Qleft_fringe,
3422 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3423 store_in_alist (alistptr, Qright_fringe,
3424 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3425 store_in_alist (alistptr, Qscroll_bar_width,
3426 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3427 ? make_number (0)
3428 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3429 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3430 /* nil means "use default width"
3431 for non-toolkit scroll bar.
3432 ruler-mode.el depends on this. */
3433 : Qnil));
3434 store_in_alist (alistptr, Qscroll_bar_height,
3435 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3436 ? make_number (0)
3437 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3438 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3439 /* nil means "use default height"
3440 for non-toolkit scroll bar. */
3441 : Qnil));
3442 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3443 MS-Windows it returns a value whose type is HANDLE, which is
3444 actually a pointer. Explicit casting avoids compiler
3445 warnings. */
3446 w = (uintptr_t) FRAME_X_WINDOW (f);
3447 store_in_alist (alistptr, Qwindow_id,
3448 make_formatted_string (buf, "%"pMu, w));
3449 #ifdef HAVE_X_WINDOWS
3450 #ifdef USE_X_TOOLKIT
3451 /* Tooltip frame may not have this widget. */
3452 if (FRAME_X_OUTPUT (f)->widget)
3453 #endif
3454 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3455 store_in_alist (alistptr, Qouter_window_id,
3456 make_formatted_string (buf, "%"pMu, w));
3457 #endif
3458 store_in_alist (alistptr, Qicon_name, f->icon_name);
3459 store_in_alist (alistptr, Qvisibility,
3460 (FRAME_VISIBLE_P (f) ? Qt
3461 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3462 store_in_alist (alistptr, Qdisplay,
3463 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3465 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3466 tem = Qnil;
3467 else
3468 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3469 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3470 store_in_alist (alistptr, Qparent_id, tem);
3471 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3475 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3476 the previous value of that parameter, NEW_VALUE is the new value. */
3478 void
3479 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3481 if (NILP (new_value))
3482 f->want_fullscreen = FULLSCREEN_NONE;
3483 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3484 f->want_fullscreen = FULLSCREEN_BOTH;
3485 else if (EQ (new_value, Qfullwidth))
3486 f->want_fullscreen = FULLSCREEN_WIDTH;
3487 else if (EQ (new_value, Qfullheight))
3488 f->want_fullscreen = FULLSCREEN_HEIGHT;
3489 else if (EQ (new_value, Qmaximized))
3490 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3492 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3493 FRAME_TERMINAL (f)->fullscreen_hook (f);
3497 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3498 the previous value of that parameter, NEW_VALUE is the new value. */
3500 void
3501 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3503 if (NILP (new_value))
3504 f->extra_line_spacing = 0;
3505 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3506 f->extra_line_spacing = XFASTINT (new_value);
3507 else if (FLOATP (new_value))
3509 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3511 if (new_spacing >= 0)
3512 f->extra_line_spacing = new_spacing;
3513 else
3514 signal_error ("Invalid line-spacing", new_value);
3516 else
3517 signal_error ("Invalid line-spacing", new_value);
3518 if (FRAME_VISIBLE_P (f))
3519 redraw_frame (f);
3523 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3524 the previous value of that parameter, NEW_VALUE is the new value. */
3526 void
3527 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3529 Lisp_Object bgcolor;
3531 if (NILP (new_value))
3532 f->gamma = 0;
3533 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3534 /* The value 0.4545 is the normal viewing gamma. */
3535 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3536 else
3537 signal_error ("Invalid screen-gamma", new_value);
3539 /* Apply the new gamma value to the frame background. */
3540 bgcolor = Fassq (Qbackground_color, f->param_alist);
3541 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3543 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3544 if (NATNUMP (parm_index)
3545 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3546 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3547 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3548 (f, bgcolor, Qnil);
3551 clear_face_cache (true); /* FIXME: Why of all frames? */
3552 fset_redisplay (f);
3556 void
3557 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3559 Lisp_Object font_object;
3560 int fontset = -1;
3561 #ifdef HAVE_X_WINDOWS
3562 Lisp_Object font_param = arg;
3563 #endif
3565 /* Set the frame parameter back to the old value because we may
3566 fail to use ARG as the new parameter value. */
3567 store_frame_param (f, Qfont, oldval);
3569 /* ARG is a fontset name, a font name, a cons of fontset name and a
3570 font object, or a font object. In the last case, this function
3571 never fail. */
3572 if (STRINGP (arg))
3574 fontset = fs_query_fontset (arg, 0);
3575 if (fontset < 0)
3577 font_object = font_open_by_name (f, arg);
3578 if (NILP (font_object))
3579 error ("Font `%s' is not defined", SSDATA (arg));
3580 arg = AREF (font_object, FONT_NAME_INDEX);
3582 else if (fontset > 0)
3584 font_object = font_open_by_name (f, fontset_ascii (fontset));
3585 if (NILP (font_object))
3586 error ("Font `%s' is not defined", SDATA (arg));
3587 arg = AREF (font_object, FONT_NAME_INDEX);
3589 else
3590 error ("The default fontset can't be used for a frame font");
3592 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3594 /* This is the case that the ASCII font of F's fontset XCAR
3595 (arg) is changed to the font XCDR (arg) by
3596 `set-fontset-font'. */
3597 fontset = fs_query_fontset (XCAR (arg), 0);
3598 if (fontset < 0)
3599 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3600 font_object = XCDR (arg);
3601 arg = AREF (font_object, FONT_NAME_INDEX);
3602 #ifdef HAVE_X_WINDOWS
3603 font_param = Ffont_get (font_object, QCname);
3604 #endif
3606 else if (FONT_OBJECT_P (arg))
3608 font_object = arg;
3609 #ifdef HAVE_X_WINDOWS
3610 font_param = Ffont_get (font_object, QCname);
3611 #endif
3612 /* This is to store the XLFD font name in the frame parameter for
3613 backward compatibility. We should store the font-object
3614 itself in the future. */
3615 arg = AREF (font_object, FONT_NAME_INDEX);
3616 fontset = FRAME_FONTSET (f);
3617 /* Check if we can use the current fontset. If not, set FONTSET
3618 to -1 to generate a new fontset from FONT-OBJECT. */
3619 if (fontset >= 0)
3621 Lisp_Object ascii_font = fontset_ascii (fontset);
3622 Lisp_Object spec = font_spec_from_name (ascii_font);
3624 /* SPEC might be nil because ASCII_FONT's name doesn't parse
3625 according to stupid XLFD rules, which, for example,
3626 disallow font names that include a dash followed by a
3627 number. So in those cases we simply request x_new_font
3628 below to generate a new fontset. */
3629 if (NILP (spec) || ! font_match_p (spec, font_object))
3630 fontset = -1;
3633 else
3634 signal_error ("Invalid font", arg);
3636 if (! NILP (Fequal (font_object, oldval)))
3637 return;
3639 x_new_font (f, font_object, fontset);
3640 store_frame_param (f, Qfont, arg);
3641 #ifdef HAVE_X_WINDOWS
3642 store_frame_param (f, Qfont_parameter, font_param);
3643 #endif
3644 /* Recalculate toolbar height. */
3645 f->n_tool_bar_rows = 0;
3647 /* Ensure we redraw it. */
3648 clear_current_matrices (f);
3650 /* Attempt to hunt down bug#16028. */
3651 SET_FRAME_GARBAGED (f);
3653 /* This is important if we are called by some Lisp as part of
3654 redisplaying the frame, see redisplay_internal. */
3655 f->fonts_changed = true;
3657 recompute_basic_faces (f);
3659 do_pending_window_change (0);
3661 /* We used to call face-set-after-frame-default here, but it leads to
3662 recursive calls (since that function can set the `default' face's
3663 font which in turns changes the frame's `font' parameter).
3664 Also I don't know what this call is meant to do, but it seems the
3665 wrong way to do it anyway (it does a lot more work than what seems
3666 reasonable in response to a change to `font'). */
3670 void
3671 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3673 if (! NILP (new_value)
3674 && !CONSP (new_value))
3676 char *p0, *p1;
3678 CHECK_STRING (new_value);
3679 p0 = p1 = SSDATA (new_value);
3680 new_value = Qnil;
3681 while (*p0)
3683 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3684 if (p0 < p1)
3685 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3686 new_value);
3687 if (*p1)
3689 int c;
3691 while ((c = *++p1) && c_isspace (c));
3693 p0 = p1;
3695 new_value = Fnreverse (new_value);
3698 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3699 return;
3701 if (FRAME_FONT (f))
3702 free_all_realized_faces (Qnil);
3704 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3705 if (NILP (new_value))
3707 if (NILP (old_value))
3708 error ("No font backend available");
3709 font_update_drivers (f, old_value);
3710 error ("None of specified font backends are available");
3712 store_frame_param (f, Qfont_backend, new_value);
3714 if (FRAME_FONT (f))
3716 Lisp_Object frame;
3718 XSETFRAME (frame, f);
3719 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3720 face_change = true;
3721 windows_or_buffers_changed = 18;
3725 void
3726 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3728 int unit = FRAME_COLUMN_WIDTH (f);
3729 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3730 int new_width;
3732 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3733 ? eabs (XINT (new_value)) : 8);
3735 if (new_width != old_width)
3737 f->left_fringe_width = new_width;
3738 f->fringe_cols /* Round up. */
3739 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3741 if (FRAME_X_WINDOW (f) != 0)
3742 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
3744 SET_FRAME_GARBAGED (f);
3749 void
3750 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3752 int unit = FRAME_COLUMN_WIDTH (f);
3753 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3754 int new_width;
3756 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3757 ? eabs (XINT (new_value)) : 8);
3759 if (new_width != old_width)
3761 f->right_fringe_width = new_width;
3762 f->fringe_cols /* Round up. */
3763 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3765 if (FRAME_X_WINDOW (f) != 0)
3766 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
3768 SET_FRAME_GARBAGED (f);
3773 void
3774 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3776 CHECK_TYPE_RANGED_INTEGER (int, arg);
3778 if (XINT (arg) == f->border_width)
3779 return;
3781 if (FRAME_X_WINDOW (f) != 0)
3782 error ("Cannot change the border width of a frame");
3784 f->border_width = XINT (arg);
3787 void
3788 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3790 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3791 CHECK_TYPE_RANGED_INTEGER (int, arg);
3792 int new = max (0, XINT (arg));
3793 if (new != old)
3795 f->right_divider_width = new;
3796 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
3797 adjust_frame_glyphs (f);
3798 SET_FRAME_GARBAGED (f);
3803 void
3804 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3806 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3807 CHECK_TYPE_RANGED_INTEGER (int, arg);
3808 int new = max (0, XINT (arg));
3809 if (new != old)
3811 f->bottom_divider_width = new;
3812 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
3813 adjust_frame_glyphs (f);
3814 SET_FRAME_GARBAGED (f);
3818 void
3819 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3821 Lisp_Object frame;
3822 XSETFRAME (frame, f);
3824 if (NILP (value))
3825 Fmake_frame_invisible (frame, Qt);
3826 else if (EQ (value, Qicon))
3827 Ficonify_frame (frame);
3828 else
3829 Fmake_frame_visible (frame);
3832 void
3833 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3835 f->auto_raise = !EQ (Qnil, arg);
3838 void
3839 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3841 f->auto_lower = !EQ (Qnil, arg);
3844 void
3845 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3847 f->no_split = !NILP (arg);
3850 void
3851 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3853 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3854 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3855 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3856 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3858 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3859 = (NILP (arg)
3860 ? vertical_scroll_bar_none
3861 : EQ (Qleft, arg)
3862 ? vertical_scroll_bar_left
3863 : EQ (Qright, arg)
3864 ? vertical_scroll_bar_right
3865 : EQ (Qleft, Vdefault_frame_scroll_bars)
3866 ? vertical_scroll_bar_left
3867 : EQ (Qright, Vdefault_frame_scroll_bars)
3868 ? vertical_scroll_bar_right
3869 : vertical_scroll_bar_none);
3871 /* We set this parameter before creating the X window for the
3872 frame, so we can get the geometry right from the start.
3873 However, if the window hasn't been created yet, we shouldn't
3874 call x_set_window_size. */
3875 if (FRAME_X_WINDOW (f))
3876 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
3878 SET_FRAME_GARBAGED (f);
3882 void
3883 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3885 #if USE_HORIZONTAL_SCROLL_BARS
3886 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3887 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3889 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3891 /* We set this parameter before creating the X window for the
3892 frame, so we can get the geometry right from the start.
3893 However, if the window hasn't been created yet, we shouldn't
3894 call x_set_window_size. */
3895 if (FRAME_X_WINDOW (f))
3896 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
3898 SET_FRAME_GARBAGED (f);
3900 #endif
3903 void
3904 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3906 int unit = FRAME_COLUMN_WIDTH (f);
3908 if (NILP (arg))
3910 x_set_scroll_bar_default_width (f);
3912 if (FRAME_X_WINDOW (f))
3913 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3915 SET_FRAME_GARBAGED (f);
3917 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3918 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3920 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3921 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3922 if (FRAME_X_WINDOW (f))
3923 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3925 SET_FRAME_GARBAGED (f);
3928 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3929 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3932 void
3933 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3935 #if USE_HORIZONTAL_SCROLL_BARS
3936 int unit = FRAME_LINE_HEIGHT (f);
3938 if (NILP (arg))
3940 x_set_scroll_bar_default_height (f);
3942 if (FRAME_X_WINDOW (f))
3943 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3945 SET_FRAME_GARBAGED (f);
3947 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3948 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3950 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3951 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3952 if (FRAME_X_WINDOW (f))
3953 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3955 SET_FRAME_GARBAGED (f);
3958 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3959 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3960 #endif
3963 void
3964 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3966 double alpha = 1.0;
3967 double newval[2];
3968 int i;
3969 Lisp_Object item;
3971 for (i = 0; i < 2; i++)
3973 newval[i] = 1.0;
3974 if (CONSP (arg))
3976 item = CAR (arg);
3977 arg = CDR (arg);
3979 else
3980 item = arg;
3982 if (NILP (item))
3983 alpha = - 1.0;
3984 else if (FLOATP (item))
3986 alpha = XFLOAT_DATA (item);
3987 if (! (0 <= alpha && alpha <= 1.0))
3988 args_out_of_range (make_float (0.0), make_float (1.0));
3990 else if (INTEGERP (item))
3992 EMACS_INT ialpha = XINT (item);
3993 if (! (0 <= ialpha && alpha <= 100))
3994 args_out_of_range (make_number (0), make_number (100));
3995 alpha = ialpha / 100.0;
3997 else
3998 wrong_type_argument (Qnumberp, item);
3999 newval[i] = alpha;
4002 for (i = 0; i < 2; i++)
4003 f->alpha[i] = newval[i];
4005 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4006 block_input ();
4007 x_set_frame_alpha (f);
4008 unblock_input ();
4009 #endif
4011 return;
4014 #ifndef HAVE_NS
4016 /* Non-zero if mouse is grabbed on DPYINFO
4017 and we know the frame where it is. */
4019 bool x_mouse_grabbed (Display_Info *dpyinfo)
4021 return (dpyinfo->grabbed
4022 && dpyinfo->last_mouse_frame
4023 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4026 /* Re-highlight something with mouse-face properties
4027 on DPYINFO using saved frame and mouse position. */
4029 void
4030 x_redo_mouse_highlight (Display_Info *dpyinfo)
4032 if (dpyinfo->last_mouse_motion_frame
4033 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4034 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4035 dpyinfo->last_mouse_motion_x,
4036 dpyinfo->last_mouse_motion_y);
4039 #endif /* HAVE_NS */
4041 /* Subroutines of creating an X frame. */
4043 /* Make sure that Vx_resource_name is set to a reasonable value.
4044 Fix it up, or set it to `emacs' if it is too hopeless. */
4046 void
4047 validate_x_resource_name (void)
4049 ptrdiff_t len = 0;
4050 /* Number of valid characters in the resource name. */
4051 ptrdiff_t good_count = 0;
4052 /* Number of invalid characters in the resource name. */
4053 ptrdiff_t bad_count = 0;
4054 Lisp_Object new;
4055 ptrdiff_t i;
4057 if (!STRINGP (Vx_resource_class))
4058 Vx_resource_class = build_string (EMACS_CLASS);
4060 if (STRINGP (Vx_resource_name))
4062 unsigned char *p = SDATA (Vx_resource_name);
4064 len = SBYTES (Vx_resource_name);
4066 /* Only letters, digits, - and _ are valid in resource names.
4067 Count the valid characters and count the invalid ones. */
4068 for (i = 0; i < len; i++)
4070 int c = p[i];
4071 if (! ((c >= 'a' && c <= 'z')
4072 || (c >= 'A' && c <= 'Z')
4073 || (c >= '0' && c <= '9')
4074 || c == '-' || c == '_'))
4075 bad_count++;
4076 else
4077 good_count++;
4080 else
4081 /* Not a string => completely invalid. */
4082 bad_count = 5, good_count = 0;
4084 /* If name is valid already, return. */
4085 if (bad_count == 0)
4086 return;
4088 /* If name is entirely invalid, or nearly so, or is so implausibly
4089 large that alloca might not work, use `emacs'. */
4090 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4092 Vx_resource_name = build_string ("emacs");
4093 return;
4096 /* Name is partly valid. Copy it and replace the invalid characters
4097 with underscores. */
4099 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4101 for (i = 0; i < len; i++)
4103 int c = SREF (new, i);
4104 if (! ((c >= 'a' && c <= 'z')
4105 || (c >= 'A' && c <= 'Z')
4106 || (c >= '0' && c <= '9')
4107 || c == '-' || c == '_'))
4108 SSET (new, i, '_');
4112 /* Get specified attribute from resource database RDB.
4113 See Fx_get_resource below for other parameters. */
4115 static Lisp_Object
4116 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4118 CHECK_STRING (attribute);
4119 CHECK_STRING (class);
4121 if (!NILP (component))
4122 CHECK_STRING (component);
4123 if (!NILP (subclass))
4124 CHECK_STRING (subclass);
4125 if (NILP (component) != NILP (subclass))
4126 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4128 validate_x_resource_name ();
4130 /* Allocate space for the components, the dots which separate them,
4131 and the final '\0'. Make them big enough for the worst case. */
4132 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4133 + (STRINGP (component)
4134 ? SBYTES (component) : 0)
4135 + SBYTES (attribute)
4136 + 3);
4138 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4139 + SBYTES (class)
4140 + (STRINGP (subclass)
4141 ? SBYTES (subclass) : 0)
4142 + 3);
4143 USE_SAFE_ALLOCA;
4144 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4145 char *class_key = name_key + name_keysize;
4147 /* Start with emacs.FRAMENAME for the name (the specific one)
4148 and with `Emacs' for the class key (the general one). */
4149 char *nz = lispstpcpy (name_key, Vx_resource_name);
4150 char *cz = lispstpcpy (class_key, Vx_resource_class);
4152 *cz++ = '.';
4153 cz = lispstpcpy (cz, class);
4155 if (!NILP (component))
4157 *cz++ = '.';
4158 lispstpcpy (cz, subclass);
4160 *nz++ = '.';
4161 nz = lispstpcpy (nz, component);
4164 *nz++ = '.';
4165 lispstpcpy (nz, attribute);
4167 char *value = x_get_string_resource (rdb, name_key, class_key);
4168 SAFE_FREE();
4170 if (value && *value)
4171 return build_string (value);
4172 else
4173 return Qnil;
4177 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4178 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4179 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4180 class, where INSTANCE is the name under which Emacs was invoked, or
4181 the name specified by the `-name' or `-rn' command-line arguments.
4183 The optional arguments COMPONENT and SUBCLASS add to the key and the
4184 class, respectively. You must specify both of them or neither.
4185 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4186 and the class is `Emacs.CLASS.SUBCLASS'. */)
4187 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4188 Lisp_Object subclass)
4190 check_window_system (NULL);
4192 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4193 attribute, class, component, subclass);
4196 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4198 Lisp_Object
4199 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4200 Lisp_Object class, Lisp_Object component,
4201 Lisp_Object subclass)
4203 return xrdb_get_resource (dpyinfo->xrdb,
4204 attribute, class, component, subclass);
4207 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4208 /* Used when C code wants a resource value. */
4209 /* Called from oldXMenu/Create.c. */
4210 char *
4211 x_get_resource_string (const char *attribute, const char *class)
4213 char *result;
4214 struct frame *sf = SELECTED_FRAME ();
4215 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4216 USE_SAFE_ALLOCA;
4218 /* Allocate space for the components, the dots which separate them,
4219 and the final '\0'. */
4220 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4221 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4222 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4223 char *class_key = name_key + name_keysize;
4225 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4226 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4228 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4229 name_key, class_key);
4230 SAFE_FREE ();
4231 return result;
4233 #endif
4235 /* Return the value of parameter PARAM.
4237 First search ALIST, then Vdefault_frame_alist, then the X defaults
4238 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4240 Convert the resource to the type specified by desired_type.
4242 If no default is specified, return Qunbound. If you call
4243 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4244 and don't let it get stored in any Lisp-visible variables! */
4246 Lisp_Object
4247 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4248 const char *attribute, const char *class, enum resource_types type)
4250 Lisp_Object tem;
4252 tem = Fassq (param, alist);
4254 if (!NILP (tem))
4256 /* If we find this parm in ALIST, clear it out
4257 so that it won't be "left over" at the end. */
4258 Lisp_Object tail;
4259 XSETCAR (tem, Qnil);
4260 /* In case the parameter appears more than once in the alist,
4261 clear it out. */
4262 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4263 if (CONSP (XCAR (tail))
4264 && EQ (XCAR (XCAR (tail)), param))
4265 XSETCAR (XCAR (tail), Qnil);
4267 else
4268 tem = Fassq (param, Vdefault_frame_alist);
4270 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4271 look in the X resources. */
4272 if (EQ (tem, Qnil))
4274 if (attribute && dpyinfo)
4276 AUTO_STRING (at, attribute);
4277 AUTO_STRING (cl, class);
4278 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4280 if (NILP (tem))
4281 return Qunbound;
4283 switch (type)
4285 case RES_TYPE_NUMBER:
4286 return make_number (atoi (SSDATA (tem)));
4288 case RES_TYPE_BOOLEAN_NUMBER:
4289 if (!strcmp (SSDATA (tem), "on")
4290 || !strcmp (SSDATA (tem), "true"))
4291 return make_number (1);
4292 return make_number (atoi (SSDATA (tem)));
4293 break;
4295 case RES_TYPE_FLOAT:
4296 return make_float (atof (SSDATA (tem)));
4298 case RES_TYPE_BOOLEAN:
4299 tem = Fdowncase (tem);
4300 if (!strcmp (SSDATA (tem), "on")
4301 #ifdef HAVE_NS
4302 || !strcmp (SSDATA (tem), "yes")
4303 #endif
4304 || !strcmp (SSDATA (tem), "true"))
4305 return Qt;
4306 else
4307 return Qnil;
4309 case RES_TYPE_STRING:
4310 return tem;
4312 case RES_TYPE_SYMBOL:
4313 /* As a special case, we map the values `true' and `on'
4314 to Qt, and `false' and `off' to Qnil. */
4316 Lisp_Object lower;
4317 lower = Fdowncase (tem);
4318 if (!strcmp (SSDATA (lower), "on")
4319 #ifdef HAVE_NS
4320 || !strcmp (SSDATA (lower), "yes")
4321 #endif
4322 || !strcmp (SSDATA (lower), "true"))
4323 return Qt;
4324 else if (!strcmp (SSDATA (lower), "off")
4325 #ifdef HAVE_NS
4326 || !strcmp (SSDATA (lower), "no")
4327 #endif
4328 || !strcmp (SSDATA (lower), "false"))
4329 return Qnil;
4330 else
4331 return Fintern (tem, Qnil);
4334 default:
4335 emacs_abort ();
4338 else
4339 return Qunbound;
4341 return Fcdr (tem);
4344 static Lisp_Object
4345 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4346 const char *attribute, const char *class,
4347 enum resource_types type)
4349 return x_get_arg (FRAME_DISPLAY_INFO (f),
4350 alist, param, attribute, class, type);
4353 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4355 Lisp_Object
4356 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4357 Lisp_Object param,
4358 const char *attribute, const char *class,
4359 enum resource_types type)
4361 Lisp_Object value;
4363 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4364 attribute, class, type);
4365 if (! NILP (value) && ! EQ (value, Qunbound))
4366 store_frame_param (f, param, value);
4368 return value;
4372 /* Record in frame F the specified or default value according to ALIST
4373 of the parameter named PROP (a Lisp symbol).
4374 If no value is specified for PROP, look for an X default for XPROP
4375 on the frame named NAME.
4376 If that is not found either, use the value DEFLT. */
4378 Lisp_Object
4379 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4380 Lisp_Object deflt, const char *xprop, const char *xclass,
4381 enum resource_types type)
4383 Lisp_Object tem;
4385 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4386 if (EQ (tem, Qunbound))
4387 tem = deflt;
4388 AUTO_FRAME_ARG (arg, prop, tem);
4389 x_set_frame_parameters (f, arg);
4390 return tem;
4394 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4397 * XParseGeometry parses strings of the form
4398 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4399 * width, height, xoffset, and yoffset are unsigned integers.
4400 * Example: "=80x24+300-49"
4401 * The equal sign is optional.
4402 * It returns a bitmask that indicates which of the four values
4403 * were actually found in the string. For each value found,
4404 * the corresponding argument is updated; for each value
4405 * not found, the corresponding argument is left unchanged.
4408 static int
4409 XParseGeometry (char *string,
4410 int *x, int *y,
4411 unsigned int *width, unsigned int *height)
4413 int mask = NoValue;
4414 char *strind;
4415 unsigned long tempWidth UNINIT, tempHeight UNINIT;
4416 long int tempX UNINIT, tempY UNINIT;
4417 char *nextCharacter;
4419 if (string == NULL || *string == '\0')
4420 return mask;
4421 if (*string == '=')
4422 string++; /* ignore possible '=' at beg of geometry spec */
4424 strind = string;
4425 if (*strind != '+' && *strind != '-' && *strind != 'x')
4427 tempWidth = strtoul (strind, &nextCharacter, 10);
4428 if (strind == nextCharacter)
4429 return 0;
4430 strind = nextCharacter;
4431 mask |= WidthValue;
4434 if (*strind == 'x' || *strind == 'X')
4436 strind++;
4437 tempHeight = strtoul (strind, &nextCharacter, 10);
4438 if (strind == nextCharacter)
4439 return 0;
4440 strind = nextCharacter;
4441 mask |= HeightValue;
4444 if (*strind == '+' || *strind == '-')
4446 if (*strind == '-')
4447 mask |= XNegative;
4448 tempX = strtol (strind, &nextCharacter, 10);
4449 if (strind == nextCharacter)
4450 return 0;
4451 strind = nextCharacter;
4452 mask |= XValue;
4453 if (*strind == '+' || *strind == '-')
4455 if (*strind == '-')
4456 mask |= YNegative;
4457 tempY = strtol (strind, &nextCharacter, 10);
4458 if (strind == nextCharacter)
4459 return 0;
4460 strind = nextCharacter;
4461 mask |= YValue;
4465 /* If strind isn't at the end of the string then it's an invalid
4466 geometry specification. */
4468 if (*strind != '\0')
4469 return 0;
4471 if (mask & XValue)
4472 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4473 if (mask & YValue)
4474 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4475 if (mask & WidthValue)
4476 *width = min (tempWidth, UINT_MAX);
4477 if (mask & HeightValue)
4478 *height = min (tempHeight, UINT_MAX);
4479 return mask;
4482 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4485 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4486 make-docfile: the documentation string in ns-win.el was used for
4487 x-parse-geometry even in non-NS builds.
4489 With two definitions of x-parse-geometry in this file, various
4490 things still get confused (eg M-x apropos documentation), so that
4491 it is best if the two definitions just share the same doc-string.
4493 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4494 doc: /* Parse a display geometry string STRING.
4495 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4496 The properties returned may include `top', `left', `height', and `width'.
4497 For X, the value of `left' or `top' may be an integer,
4498 or a list (+ N) meaning N pixels relative to top/left corner,
4499 or a list (- N) meaning -N pixels relative to bottom/right corner.
4500 On Nextstep, this just calls `ns-parse-geometry'. */)
4501 (Lisp_Object string)
4503 int geometry, x, y;
4504 unsigned int width, height;
4505 Lisp_Object result;
4507 CHECK_STRING (string);
4509 #ifdef HAVE_NS
4510 if (strchr (SSDATA (string), ' ') != NULL)
4511 return call1 (Qns_parse_geometry, string);
4512 #endif
4513 geometry = XParseGeometry (SSDATA (string),
4514 &x, &y, &width, &height);
4515 result = Qnil;
4516 if (geometry & XValue)
4518 Lisp_Object element;
4520 if (x >= 0 && (geometry & XNegative))
4521 element = list3 (Qleft, Qminus, make_number (-x));
4522 else if (x < 0 && ! (geometry & XNegative))
4523 element = list3 (Qleft, Qplus, make_number (x));
4524 else
4525 element = Fcons (Qleft, make_number (x));
4526 result = Fcons (element, result);
4529 if (geometry & YValue)
4531 Lisp_Object element;
4533 if (y >= 0 && (geometry & YNegative))
4534 element = list3 (Qtop, Qminus, make_number (-y));
4535 else if (y < 0 && ! (geometry & YNegative))
4536 element = list3 (Qtop, Qplus, make_number (y));
4537 else
4538 element = Fcons (Qtop, make_number (y));
4539 result = Fcons (element, result);
4542 if (geometry & WidthValue)
4543 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4544 if (geometry & HeightValue)
4545 result = Fcons (Fcons (Qheight, make_number (height)), result);
4547 return result;
4551 /* Calculate the desired size and position of frame F.
4552 Return the flags saying which aspects were specified.
4554 Also set the win_gravity and size_hint_flags of F.
4556 Adjust height for toolbar if TOOLBAR_P is 1.
4558 This function does not make the coordinates positive. */
4560 #define DEFAULT_ROWS 36
4561 #define DEFAULT_COLS 80
4563 long
4564 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
4566 Lisp_Object height, width, user_size, top, left, user_position;
4567 long window_prompting = 0;
4568 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4570 /* Default values if we fall through.
4571 Actually, if that happens we should get
4572 window manager prompting. */
4573 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4574 SET_FRAME_COLS (f, DEFAULT_COLS);
4575 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4576 SET_FRAME_LINES (f, DEFAULT_ROWS);
4578 /* Window managers expect that if program-specified
4579 positions are not (0,0), they're intentional, not defaults. */
4580 f->top_pos = 0;
4581 f->left_pos = 0;
4583 /* Calculate a tool bar height so that the user gets a text display
4584 area of the size he specified with -g or via .Xdefaults. Later
4585 changes of the tool bar height don't change the frame size. This
4586 is done so that users can create tall Emacs frames without having
4587 to guess how tall the tool bar will get. */
4588 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4590 if (frame_default_tool_bar_height)
4591 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
4592 else
4594 int margin, relief;
4596 relief = (tool_bar_button_relief >= 0
4597 ? tool_bar_button_relief
4598 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4600 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4601 margin = XFASTINT (Vtool_bar_button_margin);
4602 else if (CONSP (Vtool_bar_button_margin)
4603 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4604 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4605 else
4606 margin = 0;
4608 FRAME_TOOL_BAR_HEIGHT (f)
4609 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4613 /* Ensure that earlier new_width and new_height settings won't
4614 override what we specify below. */
4615 f->new_width = f->new_height = 0;
4617 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4618 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4619 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4621 if (!EQ (width, Qunbound))
4623 if (CONSP (width) && EQ (XCAR (width), Qtext_pixels))
4625 CHECK_NUMBER (XCDR (width));
4626 if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX))
4627 xsignal1 (Qargs_out_of_range, XCDR (width));
4629 SET_FRAME_WIDTH (f, XINT (XCDR (width)));
4630 f->inhibit_horizontal_resize = true;
4631 *x_width = XINT (XCDR (width));
4633 else
4635 CHECK_NUMBER (width);
4636 if ((XINT (width) < 0 || XINT (width) > INT_MAX))
4637 xsignal1 (Qargs_out_of_range, width);
4639 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4643 if (!EQ (height, Qunbound))
4645 if (CONSP (height) && EQ (XCAR (height), Qtext_pixels))
4647 CHECK_NUMBER (XCDR (height));
4648 if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX))
4649 xsignal1 (Qargs_out_of_range, XCDR (height));
4651 SET_FRAME_HEIGHT (f, XINT (XCDR (height)));
4652 f->inhibit_vertical_resize = true;
4653 *x_height = XINT (XCDR (height));
4655 else
4657 CHECK_NUMBER (height);
4658 if ((XINT (height) < 0) || (XINT (height) > INT_MAX))
4659 xsignal1 (Qargs_out_of_range, height);
4661 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4665 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4666 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4667 window_prompting |= USSize;
4668 else
4669 window_prompting |= PSize;
4672 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4673 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4674 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4675 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4677 if (EQ (top, Qminus))
4679 f->top_pos = 0;
4680 window_prompting |= YNegative;
4682 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4683 && CONSP (XCDR (top))
4684 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4686 f->top_pos = - XINT (XCAR (XCDR (top)));
4687 window_prompting |= YNegative;
4689 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4690 && CONSP (XCDR (top))
4691 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4693 f->top_pos = XINT (XCAR (XCDR (top)));
4695 else if (EQ (top, Qunbound))
4696 f->top_pos = 0;
4697 else
4699 CHECK_TYPE_RANGED_INTEGER (int, top);
4700 f->top_pos = XINT (top);
4701 if (f->top_pos < 0)
4702 window_prompting |= YNegative;
4705 if (EQ (left, Qminus))
4707 f->left_pos = 0;
4708 window_prompting |= XNegative;
4710 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4711 && CONSP (XCDR (left))
4712 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4714 f->left_pos = - XINT (XCAR (XCDR (left)));
4715 window_prompting |= XNegative;
4717 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4718 && CONSP (XCDR (left))
4719 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4721 f->left_pos = XINT (XCAR (XCDR (left)));
4723 else if (EQ (left, Qunbound))
4724 f->left_pos = 0;
4725 else
4727 CHECK_TYPE_RANGED_INTEGER (int, left);
4728 f->left_pos = XINT (left);
4729 if (f->left_pos < 0)
4730 window_prompting |= XNegative;
4733 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4734 window_prompting |= USPosition;
4735 else
4736 window_prompting |= PPosition;
4739 if (window_prompting & XNegative)
4741 if (window_prompting & YNegative)
4742 f->win_gravity = SouthEastGravity;
4743 else
4744 f->win_gravity = NorthEastGravity;
4746 else
4748 if (window_prompting & YNegative)
4749 f->win_gravity = SouthWestGravity;
4750 else
4751 f->win_gravity = NorthWestGravity;
4754 f->size_hint_flags = window_prompting;
4756 return window_prompting;
4761 #endif /* HAVE_WINDOW_SYSTEM */
4763 void
4764 frame_make_pointer_invisible (struct frame *f)
4766 if (! NILP (Vmake_pointer_invisible))
4768 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4769 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4771 f->mouse_moved = 0;
4772 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4773 f->pointer_invisible = 1;
4778 void
4779 frame_make_pointer_visible (struct frame *f)
4781 /* We don't check Vmake_pointer_invisible here in case the
4782 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4783 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4784 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4786 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4787 f->pointer_invisible = 0;
4791 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4792 Sframe_pointer_visible_p, 0, 1, 0,
4793 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4794 Otherwise it returns nil. FRAME omitted or nil means the
4795 selected frame. This is useful when `make-pointer-invisible' is set. */)
4796 (Lisp_Object frame)
4798 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4803 /***********************************************************************
4804 Multimonitor data
4805 ***********************************************************************/
4807 #ifdef HAVE_WINDOW_SYSTEM
4809 # if (defined HAVE_NS \
4810 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4811 void
4812 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4814 int i;
4815 for (i = 0; i < n_monitors; ++i)
4816 xfree (monitors[i].name);
4817 xfree (monitors);
4819 # endif
4821 Lisp_Object
4822 make_monitor_attribute_list (struct MonitorInfo *monitors,
4823 int n_monitors,
4824 int primary_monitor,
4825 Lisp_Object monitor_frames,
4826 const char *source)
4828 Lisp_Object attributes_list = Qnil;
4829 Lisp_Object primary_monitor_attributes = Qnil;
4830 int i;
4832 for (i = 0; i < n_monitors; ++i)
4834 Lisp_Object geometry, workarea, attributes = Qnil;
4835 struct MonitorInfo *mi = &monitors[i];
4837 if (mi->geom.width == 0) continue;
4839 workarea = list4i (mi->work.x, mi->work.y,
4840 mi->work.width, mi->work.height);
4841 geometry = list4i (mi->geom.x, mi->geom.y,
4842 mi->geom.width, mi->geom.height);
4843 attributes = Fcons (Fcons (Qsource, build_string (source)),
4844 attributes);
4845 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4846 attributes);
4847 attributes = Fcons (Fcons (Qmm_size,
4848 list2i (mi->mm_width, mi->mm_height)),
4849 attributes);
4850 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4851 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4852 if (mi->name)
4853 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4854 strlen (mi->name))),
4855 attributes);
4857 if (i == primary_monitor)
4858 primary_monitor_attributes = attributes;
4859 else
4860 attributes_list = Fcons (attributes, attributes_list);
4863 if (!NILP (primary_monitor_attributes))
4864 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4865 return attributes_list;
4868 #endif /* HAVE_WINDOW_SYSTEM */
4871 /***********************************************************************
4872 Initialization
4873 ***********************************************************************/
4875 void
4876 syms_of_frame (void)
4878 DEFSYM (Qframep, "framep");
4879 DEFSYM (Qframe_live_p, "frame-live-p");
4880 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4881 DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total");
4882 DEFSYM (Qexplicit_name, "explicit-name");
4883 DEFSYM (Qheight, "height");
4884 DEFSYM (Qicon, "icon");
4885 DEFSYM (Qminibuffer, "minibuffer");
4886 DEFSYM (Qmodeline, "modeline");
4887 DEFSYM (Qonly, "only");
4888 DEFSYM (Qnone, "none");
4889 DEFSYM (Qwidth, "width");
4890 DEFSYM (Qtext_pixels, "text-pixels");
4891 DEFSYM (Qgeometry, "geometry");
4892 DEFSYM (Qicon_left, "icon-left");
4893 DEFSYM (Qicon_top, "icon-top");
4894 DEFSYM (Qtooltip, "tooltip");
4895 DEFSYM (Quser_position, "user-position");
4896 DEFSYM (Quser_size, "user-size");
4897 DEFSYM (Qwindow_id, "window-id");
4898 #ifdef HAVE_X_WINDOWS
4899 DEFSYM (Qouter_window_id, "outer-window-id");
4900 #endif
4901 DEFSYM (Qparent_id, "parent-id");
4902 DEFSYM (Qx, "x");
4903 DEFSYM (Qw32, "w32");
4904 DEFSYM (Qpc, "pc");
4905 DEFSYM (Qns, "ns");
4906 DEFSYM (Qvisible, "visible");
4907 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4908 DEFSYM (Qbuffer_list, "buffer-list");
4909 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4910 DEFSYM (Qdisplay_type, "display-type");
4911 DEFSYM (Qbackground_mode, "background-mode");
4912 DEFSYM (Qnoelisp, "noelisp");
4913 DEFSYM (Qtty_color_mode, "tty-color-mode");
4914 DEFSYM (Qtty, "tty");
4915 DEFSYM (Qtty_type, "tty-type");
4917 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4919 DEFSYM (Qfullwidth, "fullwidth");
4920 DEFSYM (Qfullheight, "fullheight");
4921 DEFSYM (Qfullboth, "fullboth");
4922 DEFSYM (Qmaximized, "maximized");
4923 DEFSYM (Qx_resource_name, "x-resource-name");
4924 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4926 DEFSYM (Qterminal, "terminal");
4928 DEFSYM (Qworkarea, "workarea");
4929 DEFSYM (Qmm_size, "mm-size");
4930 DEFSYM (Qframes, "frames");
4931 DEFSYM (Qsource, "source");
4933 DEFSYM (Qouter_edges, "outer-edges");
4934 DEFSYM (Qouter_position, "outer-position");
4935 DEFSYM (Qouter_size, "outer-size");
4936 DEFSYM (Qnative_edges, "native-edges");
4937 DEFSYM (Qinner_edges, "inner-edges");
4938 DEFSYM (Qexternal_border_size, "external-border-size");
4939 DEFSYM (Qtitle_bar_size, "title-bar-size");
4940 DEFSYM (Qmenu_bar_external, "menu-bar-external");
4941 DEFSYM (Qmenu_bar_size, "menu-bar-size");
4942 DEFSYM (Qtool_bar_external, "tool-bar-external");
4943 DEFSYM (Qtool_bar_size, "tool-bar-size");
4944 /* The following are used for frame_size_history. */
4945 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
4946 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
4947 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
4948 DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
4949 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
4950 DEFSYM (Qset_frame_size, "set-frame-size");
4951 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
4952 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
4953 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
4954 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
4955 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
4956 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
4957 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
4958 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
4959 DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
4960 DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
4961 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
4962 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
4963 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
4964 DEFSYM (Qtb_size_cb, "tb-size-cb");
4965 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
4966 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
4967 DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines");
4968 DEFSYM (Qchange_frame_size, "change-frame-size");
4969 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
4970 DEFSYM (Qset_window_configuration, "set-window-configuration");
4971 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
4972 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
4973 DEFSYM (Qterminal_frame, "terminal-frame");
4975 #ifdef HAVE_NS
4976 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4977 #endif
4979 DEFSYM (Qalpha, "alpha");
4980 DEFSYM (Qauto_lower, "auto-lower");
4981 DEFSYM (Qauto_raise, "auto-raise");
4982 DEFSYM (Qborder_color, "border-color");
4983 DEFSYM (Qborder_width, "border-width");
4984 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
4985 DEFSYM (Qcursor_color, "cursor-color");
4986 DEFSYM (Qcursor_type, "cursor-type");
4987 DEFSYM (Qfont_backend, "font-backend");
4988 DEFSYM (Qfullscreen, "fullscreen");
4989 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
4990 DEFSYM (Qicon_name, "icon-name");
4991 DEFSYM (Qicon_type, "icon-type");
4992 DEFSYM (Qinternal_border_width, "internal-border-width");
4993 DEFSYM (Qleft_fringe, "left-fringe");
4994 DEFSYM (Qline_spacing, "line-spacing");
4995 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
4996 DEFSYM (Qupdate_frame_menubar, "update-frame-menubar");
4997 DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1");
4998 DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2");
4999 DEFSYM (Qmouse_color, "mouse-color");
5000 DEFSYM (Qname, "name");
5001 DEFSYM (Qright_divider_width, "right-divider-width");
5002 DEFSYM (Qright_fringe, "right-fringe");
5003 DEFSYM (Qscreen_gamma, "screen-gamma");
5004 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
5005 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
5006 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
5007 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
5008 DEFSYM (Qsticky, "sticky");
5009 DEFSYM (Qtitle, "title");
5010 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
5011 DEFSYM (Qtool_bar_position, "tool-bar-position");
5012 DEFSYM (Qunsplittable, "unsplittable");
5013 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
5014 DEFSYM (Qvisibility, "visibility");
5015 DEFSYM (Qwait_for_wm, "wait-for-wm");
5016 DEFSYM (Qinhibit_double_buffering, "inhibit-double-buffering");
5019 int i;
5021 for (i = 0; i < ARRAYELTS (frame_parms); i++)
5023 Lisp_Object v = (frame_parms[i].sym < 0
5024 ? intern_c_string (frame_parms[i].name)
5025 : builtin_lisp_symbol (frame_parms[i].sym));
5026 Fput (v, Qx_frame_parameter, make_number (i));
5030 #ifdef HAVE_WINDOW_SYSTEM
5031 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
5032 doc: /* The name Emacs uses to look up X resources.
5033 `x-get-resource' uses this as the first component of the instance name
5034 when requesting resource values.
5035 Emacs initially sets `x-resource-name' to the name under which Emacs
5036 was invoked, or to the value specified with the `-name' or `-rn'
5037 switches, if present.
5039 It may be useful to bind this variable locally around a call
5040 to `x-get-resource'. See also the variable `x-resource-class'. */);
5041 Vx_resource_name = Qnil;
5043 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5044 doc: /* The class Emacs uses to look up X resources.
5045 `x-get-resource' uses this as the first component of the instance class
5046 when requesting resource values.
5048 Emacs initially sets `x-resource-class' to "Emacs".
5050 Setting this variable permanently is not a reasonable thing to do,
5051 but binding this variable locally around a call to `x-get-resource'
5052 is a reasonable practice. See also the variable `x-resource-name'. */);
5053 Vx_resource_class = build_string (EMACS_CLASS);
5055 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5056 doc: /* The lower limit of the frame opacity (alpha transparency).
5057 The value should range from 0 (invisible) to 100 (completely opaque).
5058 You can also use a floating number between 0.0 and 1.0. */);
5059 Vframe_alpha_lower_limit = make_number (20);
5060 #endif
5062 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5063 doc: /* Alist of default values for frame creation.
5064 These may be set in your init file, like this:
5065 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5066 These override values given in window system configuration data,
5067 including X Windows' defaults database.
5068 For values specific to the first Emacs frame, see `initial-frame-alist'.
5069 For window-system specific values, see `window-system-default-frame-alist'.
5070 For values specific to the separate minibuffer frame, see
5071 `minibuffer-frame-alist'.
5072 The `menu-bar-lines' element of the list controls whether new frames
5073 have menu bars; `menu-bar-mode' works by altering this element.
5074 Setting this variable does not affect existing frames, only new ones. */);
5075 Vdefault_frame_alist = Qnil;
5077 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5078 doc: /* Default position of vertical scroll bars on this window-system. */);
5079 #ifdef HAVE_WINDOW_SYSTEM
5080 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5081 /* MS-Windows, macOS, and GTK have scroll bars on the right by
5082 default. */
5083 Vdefault_frame_scroll_bars = Qright;
5084 #else
5085 Vdefault_frame_scroll_bars = Qleft;
5086 #endif
5087 #else
5088 Vdefault_frame_scroll_bars = Qnil;
5089 #endif
5091 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5092 scroll_bar_adjust_thumb_portion_p,
5093 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5094 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5095 even if the end of the buffer is shown (i.e. overscrolling).
5096 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5097 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5098 is visible. In this case you can not overscroll. */);
5099 scroll_bar_adjust_thumb_portion_p = 1;
5101 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5102 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5104 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5105 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5106 `mouse-position' and `mouse-pixel-position' call this function, passing their
5107 usual return value as argument, and return whatever this function returns.
5108 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5109 which need to do mouse handling at the Lisp level. */);
5110 Vmouse_position_function = Qnil;
5112 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5113 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5114 If the value is an integer, highlighting is only shown after moving the
5115 mouse, while keyboard input turns off the highlight even when the mouse
5116 is over the clickable text. However, the mouse shape still indicates
5117 when the mouse is over clickable text. */);
5118 Vmouse_highlight = Qt;
5120 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5121 doc: /* If non-nil, make pointer invisible while typing.
5122 The pointer becomes visible again when the mouse is moved. */);
5123 Vmake_pointer_invisible = Qt;
5125 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5126 doc: /* Normal hook run when a frame gains input focus. */);
5127 Vfocus_in_hook = Qnil;
5129 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5130 doc: /* Normal hook run when a frame loses input focus. */);
5131 Vfocus_out_hook = Qnil;
5133 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5134 doc: /* Functions run before deleting a frame.
5135 The functions are run with one arg, the frame to be deleted.
5136 See `delete-frame'.
5138 Note that functions in this list may be called just before the frame is
5139 actually deleted, or some time later (or even both when an earlier function
5140 in `delete-frame-functions' (indirectly) calls `delete-frame'
5141 recursively). */);
5142 Vdelete_frame_functions = Qnil;
5143 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5145 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5146 doc: /* Non-nil if Menu-Bar mode is enabled.
5147 See the command `menu-bar-mode' for a description of this minor mode.
5148 Setting this variable directly does not take effect;
5149 either customize it (see the info node `Easy Customization')
5150 or call the function `menu-bar-mode'. */);
5151 Vmenu_bar_mode = Qt;
5153 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5154 doc: /* Non-nil if Tool-Bar mode is enabled.
5155 See the command `tool-bar-mode' for a description of this minor mode.
5156 Setting this variable directly does not take effect;
5157 either customize it (see the info node `Easy Customization')
5158 or call the function `tool-bar-mode'. */);
5159 #ifdef HAVE_WINDOW_SYSTEM
5160 Vtool_bar_mode = Qt;
5161 #else
5162 Vtool_bar_mode = Qnil;
5163 #endif
5165 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5166 doc: /* Minibufferless frames use this frame's minibuffer.
5167 Emacs cannot create minibufferless frames unless this is set to an
5168 appropriate surrogate.
5170 Emacs consults this variable only when creating minibufferless
5171 frames; once the frame is created, it sticks with its assigned
5172 minibuffer, no matter what this variable is set to. This means that
5173 this variable doesn't necessarily say anything meaningful about the
5174 current set of frames, or where the minibuffer is currently being
5175 displayed.
5177 This variable is local to the current terminal and cannot be buffer-local. */);
5179 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
5180 doc: /* Non-nil if window system changes focus when you move the mouse.
5181 You should set this variable to tell Emacs how your window manager
5182 handles focus, since there is no way in general for Emacs to find out
5183 automatically. See also `mouse-autoselect-window'. */);
5184 focus_follows_mouse = 0;
5186 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5187 doc: /* Non-nil means resize frames pixelwise.
5188 If this option is nil, resizing a frame rounds its sizes to the frame's
5189 current values of `frame-char-height' and `frame-char-width'. If this
5190 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5191 by one pixel.
5193 With some window managers you may have to set this to non-nil in order
5194 to set the size of a frame in pixels, to maximize frames or to make them
5195 fullscreen. To resize your initial frame pixelwise, set this option to
5196 a non-nil value in your init file. */);
5197 frame_resize_pixelwise = 0;
5199 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5200 doc: /* Whether frames should be resized implicitly.
5201 If this option is nil, setting font, menu bar, tool bar, internal
5202 borders, fringes or scroll bars of a specific frame may resize the frame
5203 in order to preserve the number of columns or lines it displays. If
5204 this option is t, no such resizing is done. Note that the size of
5205 fullscreen and maximized frames, the height of fullheight frames and the
5206 width of fullwidth frames never change implicitly.
5208 The value of this option can be also be a list of frame parameters. In
5209 this case, resizing is inhibited when changing a parameter that appears
5210 in that list. The parameters currently handled by this option include
5211 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5212 `tool-bar-lines'.
5214 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5215 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5216 `right-fringe' is handled as if the frame contained just one live
5217 window. This means, for example, that removing vertical scroll bars on
5218 a frame containing several side by side windows will shrink the frame
5219 width by the width of one scroll bar provided this option is nil and
5220 keep it unchanged if this option is either t or a list containing
5221 `vertical-scroll-bars'.
5223 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
5224 \(which means that adding/removing a tool bar does not change the frame
5225 height), nil on all other window systems including GTK+ (which means
5226 that changing any of the parameters listed above may change the size of
5227 the frame), and t otherwise (which means the frame size never changes
5228 implicitly when there's no window system support).
5230 Note that when a frame is not large enough to accommodate a change of
5231 any of the parameters listed above, Emacs may try to enlarge the frame
5232 even if this option is non-nil. */);
5233 #if defined (HAVE_WINDOW_SYSTEM)
5234 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
5235 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
5236 #else
5237 frame_inhibit_implied_resize = Qnil;
5238 #endif
5239 #else
5240 frame_inhibit_implied_resize = Qt;
5241 #endif
5243 DEFVAR_LISP ("frame-size-history", frame_size_history,
5244 doc: /* History of frame size adjustments.
5245 If non-nil, list recording frame size adjustment. Adjustments are
5246 recorded only if the first element of this list is a positive number.
5247 Adding an adjustment decrements that number by one.
5249 The remaining elements are the adjustments. Each adjustment is a list
5250 of four elements `frame', `function', `sizes' and `more'. `frame' is
5251 the affected frame and `function' the invoking function. `sizes' is
5252 usually a list of four elements `old-width', `old-height', `new-width'
5253 and `new-height' representing the old and new sizes recorded/requested
5254 by `function'. `more' is a list with additional information.
5256 The function `frame--size-history' displays the value of this variable
5257 in a more readable form. */);
5258 frame_size_history = Qnil;
5260 DEFVAR_BOOL ("tooltip-reuse-hidden-frame", tooltip_reuse_hidden_frame,
5261 doc: /* Non-nil means reuse hidden tooltip frames.
5262 When this is nil, delete a tooltip frame when hiding the associated
5263 tooltip. When this is non-nil, make the tooltip frame invisible only,
5264 so it can be reused when the next tooltip is shown.
5266 Setting this to non-nil may drastically reduce the consing overhead
5267 incurred by creating new tooltip frames. However, a value of non-nil
5268 means also that intermittent changes of faces or `default-frame-alist'
5269 are not applied when showing a tooltip in a reused frame.
5271 This variable is effective only with the X toolkit (and there only when
5272 Gtk+ tooltips are not used) and on Windows. */);
5273 tooltip_reuse_hidden_frame = false;
5275 staticpro (&Vframe_list);
5277 defsubr (&Sframep);
5278 defsubr (&Sframe_live_p);
5279 defsubr (&Swindow_system);
5280 defsubr (&Sframe_windows_min_size);
5281 defsubr (&Smake_terminal_frame);
5282 defsubr (&Shandle_switch_frame);
5283 defsubr (&Sselect_frame);
5284 defsubr (&Sselected_frame);
5285 defsubr (&Sframe_list);
5286 defsubr (&Snext_frame);
5287 defsubr (&Sprevious_frame);
5288 defsubr (&Slast_nonminibuf_frame);
5289 defsubr (&Sdelete_frame);
5290 defsubr (&Smouse_position);
5291 defsubr (&Smouse_pixel_position);
5292 defsubr (&Sset_mouse_position);
5293 defsubr (&Sset_mouse_pixel_position);
5294 #if 0
5295 defsubr (&Sframe_configuration);
5296 defsubr (&Srestore_frame_configuration);
5297 #endif
5298 defsubr (&Smake_frame_visible);
5299 defsubr (&Smake_frame_invisible);
5300 defsubr (&Siconify_frame);
5301 defsubr (&Sframe_visible_p);
5302 defsubr (&Svisible_frame_list);
5303 defsubr (&Sraise_frame);
5304 defsubr (&Slower_frame);
5305 defsubr (&Sx_focus_frame);
5306 defsubr (&Sframe_after_make_frame);
5307 defsubr (&Sredirect_frame_focus);
5308 defsubr (&Sframe_focus);
5309 defsubr (&Sframe_parameters);
5310 defsubr (&Sframe_parameter);
5311 defsubr (&Smodify_frame_parameters);
5312 defsubr (&Sframe_char_height);
5313 defsubr (&Sframe_char_width);
5314 defsubr (&Sframe_pixel_height);
5315 defsubr (&Sframe_pixel_width);
5316 defsubr (&Sframe_text_cols);
5317 defsubr (&Sframe_text_lines);
5318 defsubr (&Sframe_total_cols);
5319 defsubr (&Sframe_total_lines);
5320 defsubr (&Sframe_text_width);
5321 defsubr (&Sframe_text_height);
5322 defsubr (&Sscroll_bar_width);
5323 defsubr (&Sscroll_bar_height);
5324 defsubr (&Sfringe_width);
5325 defsubr (&Sborder_width);
5326 defsubr (&Sright_divider_width);
5327 defsubr (&Sbottom_divider_width);
5328 defsubr (&Stool_bar_pixel_width);
5329 defsubr (&Sset_frame_height);
5330 defsubr (&Sset_frame_width);
5331 defsubr (&Sset_frame_size);
5332 defsubr (&Sframe_position);
5333 defsubr (&Sset_frame_position);
5334 defsubr (&Sframe_pointer_visible_p);
5336 #ifdef HAVE_WINDOW_SYSTEM
5337 defsubr (&Sx_get_resource);
5338 defsubr (&Sx_parse_geometry);
5339 #endif