Docstring fixes re quotes in C code
[emacs.git] / src / frame.c
blob6debcb8e7bc68e9ef1fa1b20a80c79720718805d
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2015 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <errno.h>
24 #include <limits.h>
26 #include <c-ctype.h>
28 #include "lisp.h"
29 #include "character.h"
31 #ifdef HAVE_WINDOW_SYSTEM
32 #include TERM_HEADER
33 #endif /* HAVE_WINDOW_SYSTEM */
35 #include "buffer.h"
36 /* These help us bind and responding to switch-frame events. */
37 #include "commands.h"
38 #include "keyboard.h"
39 #include "frame.h"
40 #include "blockinput.h"
41 #include "termchar.h"
42 #include "termhooks.h"
43 #include "dispextern.h"
44 #include "window.h"
45 #include "font.h"
46 #ifdef HAVE_WINDOW_SYSTEM
47 #include "fontset.h"
48 #endif
49 #include "cm.h"
50 #ifdef MSDOS
51 #include "msdos.h"
52 #include "dosfns.h"
53 #endif
54 #ifdef USE_X_TOOLKIT
55 #include "widget.h"
56 #endif
58 /* The currently selected frame. */
60 Lisp_Object selected_frame;
62 /* A frame which is not just a mini-buffer, or NULL if there are no such
63 frames. This is usually the most recent such frame that was selected. */
65 static struct frame *last_nonminibuf_frame;
67 /* False means there are no visible garbaged frames. */
68 bool frame_garbaged;
70 /* The default tool bar height for future frames. */
71 #if defined USE_GTK || defined HAVE_NS
72 enum { frame_default_tool_bar_height = 0 };
73 #else
74 int frame_default_tool_bar_height;
75 #endif
77 #ifdef HAVE_WINDOW_SYSTEM
78 static void x_report_frame_params (struct frame *, Lisp_Object *);
79 #endif
81 /* These setters are used only in this file, so they can be private. */
82 static void
83 fset_buffer_predicate (struct frame *f, Lisp_Object val)
85 f->buffer_predicate = val;
87 static void
88 fset_minibuffer_window (struct frame *f, Lisp_Object val)
90 f->minibuffer_window = val;
93 struct frame *
94 decode_live_frame (register Lisp_Object frame)
96 if (NILP (frame))
97 frame = selected_frame;
98 CHECK_LIVE_FRAME (frame);
99 return XFRAME (frame);
102 struct frame *
103 decode_any_frame (register Lisp_Object frame)
105 if (NILP (frame))
106 frame = selected_frame;
107 CHECK_FRAME (frame);
108 return XFRAME (frame);
111 #ifdef HAVE_WINDOW_SYSTEM
113 bool
114 window_system_available (struct frame *f)
116 return f ? FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f) : x_display_list != NULL;
119 #endif /* HAVE_WINDOW_SYSTEM */
121 struct frame *
122 decode_window_system_frame (Lisp_Object frame)
124 struct frame *f = decode_live_frame (frame);
126 if (!window_system_available (f))
127 error ("Window system frame should be used");
128 return f;
131 void
132 check_window_system (struct frame *f)
134 if (!window_system_available (f))
135 error (f ? "Window system frame should be used"
136 : "Window system is not in use or not initialized");
139 /* Return the value of frame parameter PROP in frame FRAME. */
141 Lisp_Object
142 get_frame_param (register struct frame *frame, Lisp_Object prop)
144 register Lisp_Object tem;
146 tem = Fassq (prop, frame->param_alist);
147 if (EQ (tem, Qnil))
148 return tem;
149 return Fcdr (tem);
153 void
154 frame_size_history_add (struct frame *f, Lisp_Object fun_symbol,
155 int width, int height, Lisp_Object rest)
157 Lisp_Object frame;
159 XSETFRAME (frame, f);
160 if (CONSP (frame_size_history)
161 && INTEGERP (XCAR (frame_size_history))
162 && 0 < XINT (XCAR (frame_size_history)))
163 frame_size_history =
164 Fcons (make_number (XINT (XCAR (frame_size_history)) - 1),
165 Fcons (list4
166 (frame, fun_symbol,
167 ((width > 0)
168 ? list4 (make_number (FRAME_TEXT_WIDTH (f)),
169 make_number (FRAME_TEXT_HEIGHT (f)),
170 make_number (width),
171 make_number (height))
172 : Qnil),
173 rest),
174 XCDR (frame_size_history)));
178 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
179 state of frame F would be affected by a vertical (horizontal if
180 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
181 parameter that is changed. */
182 bool
183 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
185 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
186 bool inhibit
187 = ((f->after_make_frame
188 && (EQ (frame_inhibit_implied_resize, Qt)
189 || (CONSP (frame_inhibit_implied_resize)
190 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))))
191 || (horizontal
192 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight))
193 || (!horizontal
194 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth))
195 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f));
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)
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 frame_inhibit_resize tells us to do
429 so or INHIBIT equals 4. */
431 inhibit_horizontal = ((windows_width >= min_windows_width
432 && (inhibit == 4
433 || frame_inhibit_resize (f, true, parameter)))
434 ? true : false);
435 inhibit_vertical = ((windows_height >= min_windows_height
436 && (inhibit == 4
437 || frame_inhibit_resize (f, false, parameter)))
438 ? true : false);
440 else
441 /* Otherwise inhibit if INHIBIT equals 5. */
442 inhibit_horizontal = inhibit_vertical = inhibit == 5;
444 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
445 ? old_pixel_width
446 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
447 min_windows_width
448 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
449 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
450 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
451 new_cols = new_text_width / unit_width;
453 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
454 ? old_pixel_height
455 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
456 min_windows_height
457 + FRAME_TOP_MARGIN_HEIGHT (f)
458 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
459 new_windows_height = (new_pixel_height
460 - FRAME_TOP_MARGIN_HEIGHT (f)
461 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
462 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
463 new_lines = new_text_height / unit_height;
465 #ifdef HAVE_WINDOW_SYSTEM
466 if (FRAME_WINDOW_P (f)
467 && f->can_x_set_window_size
468 && ((!inhibit_horizontal
469 && (new_pixel_width != old_pixel_width
470 || inhibit == 0 || inhibit == 2))
471 || (!inhibit_vertical
472 && (new_pixel_height != old_pixel_height
473 || inhibit == 0 || inhibit == 2))))
474 /* We are either allowed to change the frame size or the minimum
475 sizes request such a change. Do not care for fixing minimum
476 sizes here, we do that eventually when we're called from
477 change_frame_size. */
479 /* Make sure we respect fullheight and fullwidth. */
480 if (inhibit_horizontal)
481 new_text_width = old_text_width;
482 else if (inhibit_vertical)
483 new_text_height = old_text_height;
485 frame_size_history_add
486 (f, Qadjust_frame_size_2, new_text_width, new_text_height,
487 list2 (inhibit_horizontal ? Qt : Qnil,
488 inhibit_vertical ? Qt : Qnil));
490 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
491 f->resized_p = true;
493 return;
495 #endif
497 if (new_text_width == old_text_width
498 && new_text_height == old_text_height
499 && new_windows_width == old_windows_width
500 && new_windows_height == old_windows_height
501 && new_pixel_width == old_pixel_width
502 && new_pixel_height == old_pixel_height
503 && new_cols == old_cols
504 && new_lines == old_lines)
505 /* No change. Sanitize window sizes and return. */
507 sanitize_window_sizes (frame, Qt);
508 sanitize_window_sizes (frame, Qnil);
510 return;
513 block_input ();
515 #ifdef MSDOS
516 /* We only can set screen dimensions to certain values supported
517 by our video hardware. Try to find the smallest size greater
518 or equal to the requested dimensions. */
519 dos_set_window_size (&new_lines, &new_cols);
520 #endif
522 if (new_windows_width != old_windows_width)
524 resize_frame_windows (f, new_windows_width, 1, 1);
526 /* MSDOS frames cannot PRETEND, as they change frame size by
527 manipulating video hardware. */
528 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
529 FrameCols (FRAME_TTY (f)) = new_cols;
531 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
532 if (WINDOWP (f->tool_bar_window))
534 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
535 XWINDOW (f->tool_bar_window)->total_cols
536 = new_windows_width / unit_width;
538 #endif
540 else if (new_cols != old_cols)
541 call2 (Qwindow_pixel_to_total, frame, Qt);
543 if (new_windows_height != old_windows_height
544 /* When the top margin has changed we have to recalculate the top
545 edges of all windows. No such calculation is necessary for the
546 left edges. */
547 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
549 resize_frame_windows (f, new_windows_height, 0, 1);
551 /* MSDOS frames cannot PRETEND, as they change frame size by
552 manipulating video hardware. */
553 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
554 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
556 else if (new_lines != old_lines)
557 call2 (Qwindow_pixel_to_total, frame, Qnil);
559 frame_size_history_add
560 (f, Qadjust_frame_size_3, new_text_width, new_text_height,
561 list4 (make_number (old_pixel_width), make_number (old_pixel_height),
562 make_number (new_pixel_width), make_number (new_pixel_height)));
564 /* Assign new sizes. */
565 FRAME_TEXT_WIDTH (f) = new_text_width;
566 FRAME_TEXT_HEIGHT (f) = new_text_height;
567 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
568 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
569 SET_FRAME_COLS (f, new_cols);
570 SET_FRAME_LINES (f, new_lines);
573 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
574 int text_area_x, text_area_y, text_area_width, text_area_height;
576 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
577 &text_area_height);
578 if (w->cursor.x >= text_area_x + text_area_width)
579 w->cursor.hpos = w->cursor.x = 0;
580 if (w->cursor.y >= text_area_y + text_area_height)
581 w->cursor.vpos = w->cursor.y = 0;
584 /* Sanitize window sizes. */
585 sanitize_window_sizes (frame, Qt);
586 sanitize_window_sizes (frame, Qnil);
588 adjust_frame_glyphs (f);
589 calculate_costs (f);
590 SET_FRAME_GARBAGED (f);
592 /* A frame was "resized" if one of its pixelsizes changed, even if its
593 X window wasn't resized at all. */
594 f->resized_p = (new_pixel_width != old_pixel_width
595 || new_pixel_height != old_pixel_height);
597 unblock_input ();
599 run_window_configuration_change_hook (f);
602 /* Allocate basically initialized frame. */
604 static struct frame *
605 allocate_frame (void)
607 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
610 struct frame *
611 make_frame (bool mini_p)
613 Lisp_Object frame;
614 struct frame *f;
615 struct window *rw, *mw IF_LINT (= NULL);
616 Lisp_Object root_window;
617 Lisp_Object mini_window;
619 f = allocate_frame ();
620 XSETFRAME (frame, f);
622 #ifdef USE_GTK
623 /* Initialize Lisp data. Note that allocate_frame initializes all
624 Lisp data to nil, so do it only for slots which should not be nil. */
625 fset_tool_bar_position (f, Qtop);
626 #endif
628 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
629 non-Lisp data, so do it only for slots which should not be zero.
630 To avoid subtle bugs and for the sake of readability, it's better to
631 initialize enum members explicitly even if their values are zero. */
632 f->wants_modeline = true;
633 f->redisplay = true;
634 f->garbaged = true;
635 f->can_x_set_window_size = false;
636 f->after_make_frame = false;
637 f->tool_bar_redisplayed_once = false;
638 f->column_width = 1; /* !FRAME_WINDOW_P value. */
639 f->line_height = 1; /* !FRAME_WINDOW_P value. */
640 #ifdef HAVE_WINDOW_SYSTEM
641 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
642 f->horizontal_scroll_bars = false;
643 f->want_fullscreen = FULLSCREEN_NONE;
644 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
645 f->last_tool_bar_item = -1;
646 #endif
647 #endif
649 root_window = make_window ();
650 rw = XWINDOW (root_window);
651 if (mini_p)
653 mini_window = make_window ();
654 mw = XWINDOW (mini_window);
655 wset_next (rw, mini_window);
656 wset_prev (mw, root_window);
657 mw->mini = 1;
658 wset_frame (mw, frame);
659 fset_minibuffer_window (f, mini_window);
661 else
663 mini_window = Qnil;
664 wset_next (rw, Qnil);
665 fset_minibuffer_window (f, Qnil);
668 wset_frame (rw, frame);
670 /* 10 is arbitrary,
671 just so that there is "something there."
672 Correct size will be set up later with adjust_frame_size. */
674 SET_FRAME_COLS (f, 10);
675 SET_FRAME_LINES (f, 10);
676 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
677 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
679 rw->total_cols = 10;
680 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
681 rw->total_lines = mini_p ? 9 : 10;
682 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
684 if (mini_p)
686 mw->top_line = rw->total_lines;
687 mw->pixel_top = rw->pixel_height;
688 mw->total_cols = rw->total_cols;
689 mw->pixel_width = rw->pixel_width;
690 mw->total_lines = 1;
691 mw->pixel_height = FRAME_LINE_HEIGHT (f);
694 /* Choose a buffer for the frame's root window. */
696 Lisp_Object buf = Fcurrent_buffer ();
698 /* If current buffer is hidden, try to find another one. */
699 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
700 buf = other_buffer_safely (buf);
702 /* Use set_window_buffer, not Fset_window_buffer, and don't let
703 hooks be run by it. The reason is that the whole frame/window
704 arrangement is not yet fully initialized at this point. Windows
705 don't have the right size, glyph matrices aren't initialized
706 etc. Running Lisp functions at this point surely ends in a
707 SEGV. */
708 set_window_buffer (root_window, buf, 0, 0);
709 fset_buffer_list (f, list1 (buf));
712 if (mini_p)
714 set_window_buffer (mini_window,
715 (NILP (Vminibuffer_list)
716 ? get_minibuffer (0)
717 : Fcar (Vminibuffer_list)),
718 0, 0);
719 /* No horizontal scroll bars in minibuffers. */
720 wset_horizontal_scroll_bar (mw, Qnil);
723 fset_root_window (f, root_window);
724 fset_selected_window (f, root_window);
725 /* Make sure this window seems more recently used than
726 a newly-created, never-selected window. */
727 XWINDOW (f->selected_window)->use_time = ++window_select_count;
729 return f;
732 #ifdef HAVE_WINDOW_SYSTEM
733 /* Make a frame using a separate minibuffer window on another frame.
734 MINI_WINDOW is the minibuffer window to use. nil means use the
735 default (the global minibuffer). */
737 struct frame *
738 make_frame_without_minibuffer (Lisp_Object mini_window, KBOARD *kb,
739 Lisp_Object display)
741 struct frame *f;
743 if (!NILP (mini_window))
744 CHECK_LIVE_WINDOW (mini_window);
746 if (!NILP (mini_window)
747 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
748 error ("Frame and minibuffer must be on the same terminal");
750 /* Make a frame containing just a root window. */
751 f = make_frame (0);
753 if (NILP (mini_window))
755 /* Use default-minibuffer-frame if possible. */
756 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
757 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
759 Lisp_Object frame_dummy;
761 XSETFRAME (frame_dummy, f);
762 /* If there's no minibuffer frame to use, create one. */
763 kset_default_minibuffer_frame
764 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
767 mini_window
768 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
771 fset_minibuffer_window (f, mini_window);
773 /* Make the chosen minibuffer window display the proper minibuffer,
774 unless it is already showing a minibuffer. */
775 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
776 /* Use set_window_buffer instead of Fset_window_buffer (see
777 discussion of bug#11984, bug#12025, bug#12026). */
778 set_window_buffer (mini_window,
779 (NILP (Vminibuffer_list)
780 ? get_minibuffer (0)
781 : Fcar (Vminibuffer_list)), 0, 0);
782 return f;
785 /* Make a frame containing only a minibuffer window. */
787 struct frame *
788 make_minibuffer_frame (void)
790 /* First make a frame containing just a root window, no minibuffer. */
792 register struct frame *f = make_frame (0);
793 register Lisp_Object mini_window;
794 register Lisp_Object frame;
796 XSETFRAME (frame, f);
798 f->auto_raise = 0;
799 f->auto_lower = 0;
800 f->no_split = 1;
801 f->wants_modeline = 0;
803 /* Now label the root window as also being the minibuffer.
804 Avoid infinite looping on the window chain by marking next pointer
805 as nil. */
807 mini_window = f->root_window;
808 fset_minibuffer_window (f, mini_window);
809 XWINDOW (mini_window)->mini = 1;
810 wset_next (XWINDOW (mini_window), Qnil);
811 wset_prev (XWINDOW (mini_window), Qnil);
812 wset_frame (XWINDOW (mini_window), frame);
814 /* Put the proper buffer in that window. */
816 /* Use set_window_buffer instead of Fset_window_buffer (see
817 discussion of bug#11984, bug#12025, bug#12026). */
818 set_window_buffer (mini_window,
819 (NILP (Vminibuffer_list)
820 ? get_minibuffer (0)
821 : Fcar (Vminibuffer_list)), 0, 0);
822 return f;
824 #endif /* HAVE_WINDOW_SYSTEM */
826 /* Construct a frame that refers to a terminal. */
828 static printmax_t tty_frame_count;
830 struct frame *
831 make_initial_frame (void)
833 struct frame *f;
834 struct terminal *terminal;
835 Lisp_Object frame;
837 eassert (initial_kboard);
839 /* The first call must initialize Vframe_list. */
840 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
841 Vframe_list = Qnil;
843 terminal = init_initial_terminal ();
845 f = make_frame (1);
846 XSETFRAME (frame, f);
848 Vframe_list = Fcons (frame, Vframe_list);
850 tty_frame_count = 1;
851 fset_name (f, build_pure_c_string ("F1"));
853 SET_FRAME_VISIBLE (f, 1);
855 f->output_method = terminal->type;
856 f->terminal = terminal;
857 f->terminal->reference_count++;
858 f->output_data.nothing = 0;
860 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
861 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
863 #ifdef HAVE_WINDOW_SYSTEM
864 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
865 f->horizontal_scroll_bars = false;
866 #endif
868 /* The default value of menu-bar-mode is t. */
869 set_menu_bar_lines (f, make_number (1), Qnil);
871 if (!noninteractive)
872 init_frame_faces (f);
874 last_nonminibuf_frame = f;
876 f->can_x_set_window_size = true;
877 f->after_make_frame = true;
879 return f;
883 static struct frame *
884 make_terminal_frame (struct terminal *terminal)
886 register struct frame *f;
887 Lisp_Object frame;
888 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
890 if (!terminal->name)
891 error ("Terminal is not live, can't create new frames on it");
893 f = make_frame (1);
895 XSETFRAME (frame, f);
896 Vframe_list = Fcons (frame, Vframe_list);
898 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
900 SET_FRAME_VISIBLE (f, 1);
902 f->terminal = terminal;
903 f->terminal->reference_count++;
904 #ifdef MSDOS
905 f->output_data.tty->display_info = &the_only_display_info;
906 if (!inhibit_window_system
907 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
908 || XFRAME (selected_frame)->output_method == output_msdos_raw))
909 f->output_method = output_msdos_raw;
910 else
911 f->output_method = output_termcap;
912 #else /* not MSDOS */
913 f->output_method = output_termcap;
914 create_tty_output (f);
915 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
916 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
917 #endif /* not MSDOS */
919 #ifdef HAVE_WINDOW_SYSTEM
920 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
921 f->horizontal_scroll_bars = false;
922 #endif
924 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
925 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
926 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
927 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
929 /* Set the top frame to the newly created frame. */
930 if (FRAMEP (FRAME_TTY (f)->top_frame)
931 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
932 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
934 FRAME_TTY (f)->top_frame = frame;
936 if (!noninteractive)
937 init_frame_faces (f);
939 return f;
942 /* Get a suitable value for frame parameter PARAMETER for a newly
943 created frame, based on (1) the user-supplied frame parameter
944 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
946 static Lisp_Object
947 get_future_frame_param (Lisp_Object parameter,
948 Lisp_Object supplied_parms,
949 char *current_value)
951 Lisp_Object result;
953 result = Fassq (parameter, supplied_parms);
954 if (NILP (result))
955 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
956 if (NILP (result) && current_value != NULL)
957 result = build_string (current_value);
958 if (!NILP (result) && !STRINGP (result))
959 result = XCDR (result);
960 if (NILP (result) || !STRINGP (result))
961 result = Qnil;
963 return result;
966 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
967 1, 1, 0,
968 doc: /* Create an additional terminal frame, possibly on another terminal.
969 This function takes one argument, an alist specifying frame parameters.
971 You can create multiple frames on a single text terminal, but only one
972 of them (the selected terminal frame) is actually displayed.
974 In practice, generally you don't need to specify any parameters,
975 except when you want to create a new frame on another terminal.
976 In that case, the `tty' parameter specifies the device file to open,
977 and the `tty-type' parameter specifies the terminal type. Example:
979 (make-terminal-frame \\='((tty . "/dev/pts/5") (tty-type . "xterm")))
981 Note that changing the size of one terminal frame automatically
982 affects all frames on the same terminal device. */)
983 (Lisp_Object parms)
985 struct frame *f;
986 struct terminal *t = NULL;
987 Lisp_Object frame, tem;
988 struct frame *sf = SELECTED_FRAME ();
990 #ifdef MSDOS
991 if (sf->output_method != output_msdos_raw
992 && sf->output_method != output_termcap)
993 emacs_abort ();
994 #else /* not MSDOS */
996 #ifdef WINDOWSNT /* This should work now! */
997 if (sf->output_method != output_termcap)
998 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
999 #endif
1000 #endif /* not MSDOS */
1003 Lisp_Object terminal;
1005 terminal = Fassq (Qterminal, parms);
1006 if (CONSP (terminal))
1008 terminal = XCDR (terminal);
1009 t = decode_live_terminal (terminal);
1011 #ifdef MSDOS
1012 if (t && t != the_only_display_info.terminal)
1013 /* msdos.c assumes a single tty_display_info object. */
1014 error ("Multiple terminals are not supported on this platform");
1015 if (!t)
1016 t = the_only_display_info.terminal;
1017 #endif
1020 if (!t)
1022 char *name = 0, *type = 0;
1023 Lisp_Object tty, tty_type;
1024 USE_SAFE_ALLOCA;
1026 tty = get_future_frame_param
1027 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1028 ? FRAME_TTY (XFRAME (selected_frame))->name
1029 : NULL));
1030 if (!NILP (tty))
1031 SAFE_ALLOCA_STRING (name, tty);
1033 tty_type = get_future_frame_param
1034 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1035 ? FRAME_TTY (XFRAME (selected_frame))->type
1036 : NULL));
1037 if (!NILP (tty_type))
1038 SAFE_ALLOCA_STRING (type, tty_type);
1040 t = init_tty (name, type, 0); /* Errors are not fatal. */
1041 SAFE_FREE ();
1044 f = make_terminal_frame (t);
1047 int width, height;
1048 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1049 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f),
1050 5, 0, Qterminal_frame);
1053 adjust_frame_glyphs (f);
1054 calculate_costs (f);
1055 XSETFRAME (frame, f);
1057 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1058 store_in_alist (&parms, Qtty,
1059 (t->display_info.tty->name
1060 ? build_string (t->display_info.tty->name)
1061 : Qnil));
1062 Fmodify_frame_parameters (frame, parms);
1064 /* Make the frame face alist be frame-specific, so that each
1065 frame could change its face definitions independently. */
1066 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1067 /* Simple Fcopy_alist isn't enough, because we need the contents of
1068 the vectors which are the CDRs of associations in face_alist to
1069 be copied as well. */
1070 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1071 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1073 f->can_x_set_window_size = true;
1074 f->after_make_frame = true;
1076 return frame;
1080 /* Perform the switch to frame FRAME.
1082 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1083 FRAME1 as frame.
1085 If TRACK is non-zero and the frame that currently has the focus
1086 redirects its focus to the selected frame, redirect that focused
1087 frame's focus to FRAME instead.
1089 FOR_DELETION non-zero means that the selected frame is being
1090 deleted, which includes the possibility that the frame's terminal
1091 is dead.
1093 The value of NORECORD is passed as argument to Fselect_window. */
1095 Lisp_Object
1096 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1098 struct frame *sf = SELECTED_FRAME ();
1100 /* If FRAME is a switch-frame event, extract the frame we should
1101 switch to. */
1102 if (CONSP (frame)
1103 && EQ (XCAR (frame), Qswitch_frame)
1104 && CONSP (XCDR (frame)))
1105 frame = XCAR (XCDR (frame));
1107 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1108 a switch-frame event to arrive after a frame is no longer live,
1109 especially when deleting the initial frame during startup. */
1110 CHECK_FRAME (frame);
1111 if (! FRAME_LIVE_P (XFRAME (frame)))
1112 return Qnil;
1114 if (sf == XFRAME (frame))
1115 return frame;
1117 /* If a frame's focus has been redirected toward the currently
1118 selected frame, we should change the redirection to point to the
1119 newly selected frame. This means that if the focus is redirected
1120 from a minibufferless frame to a surrogate minibuffer frame, we
1121 can use `other-window' to switch between all the frames using
1122 that minibuffer frame, and the focus redirection will follow us
1123 around. */
1124 #if 0
1125 /* This is too greedy; it causes inappropriate focus redirection
1126 that's hard to get rid of. */
1127 if (track)
1129 Lisp_Object tail;
1131 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1133 Lisp_Object focus;
1135 if (!FRAMEP (XCAR (tail)))
1136 emacs_abort ();
1138 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1140 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1141 Fredirect_frame_focus (XCAR (tail), frame);
1144 #else /* ! 0 */
1145 /* Instead, apply it only to the frame we're pointing to. */
1146 #ifdef HAVE_WINDOW_SYSTEM
1147 if (track && FRAME_WINDOW_P (XFRAME (frame)))
1149 Lisp_Object focus, xfocus;
1151 xfocus = x_get_focus_frame (XFRAME (frame));
1152 if (FRAMEP (xfocus))
1154 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1155 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1156 Fredirect_frame_focus (xfocus, frame);
1159 #endif /* HAVE_X_WINDOWS */
1160 #endif /* ! 0 */
1162 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1163 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1165 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
1167 struct frame *f = XFRAME (frame);
1168 struct tty_display_info *tty = FRAME_TTY (f);
1169 Lisp_Object top_frame = tty->top_frame;
1171 /* Don't mark the frame garbaged and/or obscured if we are
1172 switching to the frame that is already the top frame of that
1173 TTY. */
1174 if (!EQ (frame, top_frame))
1176 if (FRAMEP (top_frame))
1177 /* Mark previously displayed frame as now obscured. */
1178 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1179 SET_FRAME_VISIBLE (f, 1);
1180 /* If the new TTY frame changed dimensions, we need to
1181 resync term.c's idea of the frame size with the new
1182 frame's data. */
1183 if (FRAME_COLS (f) != FrameCols (tty))
1184 FrameCols (tty) = FRAME_COLS (f);
1185 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1186 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1188 tty->top_frame = frame;
1191 selected_frame = frame;
1192 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1193 last_nonminibuf_frame = XFRAME (selected_frame);
1195 Fselect_window (XFRAME (frame)->selected_window, norecord);
1197 /* We want to make sure that the next event generates a frame-switch
1198 event to the appropriate frame. This seems kludgy to me, but
1199 before you take it out, make sure that evaluating something like
1200 (select-window (frame-root-window (new-frame))) doesn't end up
1201 with your typing being interpreted in the new frame instead of
1202 the one you're actually typing in. */
1203 internal_last_event_frame = Qnil;
1205 return frame;
1208 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1209 doc: /* Select FRAME.
1210 Subsequent editing commands apply to its selected window.
1211 Optional argument NORECORD means to neither change the order of
1212 recently selected windows nor the buffer list.
1214 The selection of FRAME lasts until the next time the user does
1215 something to select a different frame, or until the next time
1216 this function is called. If you are using a window system, the
1217 previously selected frame may be restored as the selected frame
1218 when returning to the command loop, because it still may have
1219 the window system's input focus. On a text terminal, the next
1220 redisplay will display FRAME.
1222 This function returns FRAME, or nil if FRAME has been deleted. */)
1223 (Lisp_Object frame, Lisp_Object norecord)
1225 return do_switch_frame (frame, 1, 0, norecord);
1228 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1229 doc: /* Handle a switch-frame event EVENT.
1230 Switch-frame events are usually bound to this function.
1231 A switch-frame event tells Emacs that the window manager has requested
1232 that the user's events be directed to the frame mentioned in the event.
1233 This function selects the selected window of the frame of EVENT.
1235 If EVENT is frame object, handle it as if it were a switch-frame event
1236 to that frame. */)
1237 (Lisp_Object event)
1239 /* Preserve prefix arg that the command loop just cleared. */
1240 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1241 run_hook (Qmouse_leave_buffer_hook);
1242 /* `switch-frame' implies a focus in. */
1243 call1 (intern ("handle-focus-in"), event);
1244 return do_switch_frame (event, 0, 0, Qnil);
1247 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1248 doc: /* Return the frame that is now selected. */)
1249 (void)
1251 return selected_frame;
1254 DEFUN ("frame-list", Fframe_list, Sframe_list,
1255 0, 0, 0,
1256 doc: /* Return a list of all live frames. */)
1257 (void)
1259 Lisp_Object frames;
1260 frames = Fcopy_sequence (Vframe_list);
1261 #ifdef HAVE_WINDOW_SYSTEM
1262 if (FRAMEP (tip_frame))
1263 frames = Fdelq (tip_frame, frames);
1264 #endif
1265 return frames;
1268 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1269 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1270 If MINIBUF is nil, do not consider minibuffer-only candidate.
1271 If MINIBUF is `visible', do not consider an invisible candidate.
1272 If MINIBUF is a window, consider only its own frame and candidate now
1273 using that window as the minibuffer.
1274 If MINIBUF is 0, consider candidate if it is visible or iconified.
1275 Otherwise consider any candidate and return nil if CANDIDATE is not
1276 acceptable. */
1278 static Lisp_Object
1279 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1281 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1283 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1284 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1285 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1286 && FRAME_TTY (c) == FRAME_TTY (f)))
1288 if (NILP (minibuf))
1290 if (!FRAME_MINIBUF_ONLY_P (c))
1291 return candidate;
1293 else if (EQ (minibuf, Qvisible))
1295 if (FRAME_VISIBLE_P (c))
1296 return candidate;
1298 else if (WINDOWP (minibuf))
1300 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1301 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1302 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1303 FRAME_FOCUS_FRAME (c)))
1304 return candidate;
1306 else if (XFASTINT (minibuf) == 0)
1308 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1309 return candidate;
1311 else
1312 return candidate;
1314 return Qnil;
1317 /* Return the next frame in the frame list after FRAME. */
1319 static Lisp_Object
1320 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1322 Lisp_Object f, tail;
1323 int passed = 0;
1325 /* There must always be at least one frame in Vframe_list. */
1326 eassert (CONSP (Vframe_list));
1328 while (passed < 2)
1329 FOR_EACH_FRAME (tail, f)
1331 if (passed)
1333 f = candidate_frame (f, frame, minibuf);
1334 if (!NILP (f))
1335 return f;
1337 if (EQ (frame, f))
1338 passed++;
1340 return frame;
1343 /* Return the previous frame in the frame list before FRAME. */
1345 static Lisp_Object
1346 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1348 Lisp_Object f, tail, prev = Qnil;
1350 /* There must always be at least one frame in Vframe_list. */
1351 eassert (CONSP (Vframe_list));
1353 FOR_EACH_FRAME (tail, f)
1355 if (EQ (frame, f) && !NILP (prev))
1356 return prev;
1357 f = candidate_frame (f, frame, minibuf);
1358 if (!NILP (f))
1359 prev = f;
1362 /* We've scanned the entire list. */
1363 if (NILP (prev))
1364 /* We went through the whole frame list without finding a single
1365 acceptable frame. Return the original frame. */
1366 return frame;
1367 else
1368 /* There were no acceptable frames in the list before FRAME; otherwise,
1369 we would have returned directly from the loop. Since PREV is the last
1370 acceptable frame in the list, return it. */
1371 return prev;
1375 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1376 doc: /* Return the next frame in the frame list after FRAME.
1377 It considers only frames on the same terminal as FRAME.
1378 By default, skip minibuffer-only frames.
1379 If omitted, FRAME defaults to the selected frame.
1380 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1381 If MINIFRAME is a window, include only its own frame
1382 and any frame now using that window as the minibuffer.
1383 If MINIFRAME is `visible', include all visible frames.
1384 If MINIFRAME is 0, include all visible and iconified frames.
1385 Otherwise, include all frames. */)
1386 (Lisp_Object frame, Lisp_Object miniframe)
1388 if (NILP (frame))
1389 frame = selected_frame;
1390 CHECK_LIVE_FRAME (frame);
1391 return next_frame (frame, miniframe);
1394 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1395 doc: /* Return the previous frame in the frame list before FRAME.
1396 It considers only frames on the same terminal as FRAME.
1397 By default, skip minibuffer-only frames.
1398 If omitted, FRAME defaults to the selected frame.
1399 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1400 If MINIFRAME is a window, include only its own frame
1401 and any frame now using that window as the minibuffer.
1402 If MINIFRAME is `visible', include all visible frames.
1403 If MINIFRAME is 0, include all visible and iconified frames.
1404 Otherwise, include all frames. */)
1405 (Lisp_Object frame, Lisp_Object miniframe)
1407 if (NILP (frame))
1408 frame = selected_frame;
1409 CHECK_LIVE_FRAME (frame);
1410 return prev_frame (frame, miniframe);
1413 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1414 Slast_nonminibuf_frame, 0, 0, 0,
1415 doc: /* Return last non-minibuffer frame selected. */)
1416 (void)
1418 Lisp_Object frame = Qnil;
1420 if (last_nonminibuf_frame)
1421 XSETFRAME (frame, last_nonminibuf_frame);
1423 return frame;
1426 /* Return 1 if it is ok to delete frame F;
1427 0 if all frames aside from F are invisible.
1428 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1430 static int
1431 other_visible_frames (struct frame *f)
1433 Lisp_Object frames, this;
1435 FOR_EACH_FRAME (frames, this)
1437 if (f == XFRAME (this))
1438 continue;
1440 /* Verify that we can still talk to the frame's X window,
1441 and note any recent change in visibility. */
1442 #ifdef HAVE_X_WINDOWS
1443 if (FRAME_WINDOW_P (XFRAME (this)))
1444 x_sync (XFRAME (this));
1445 #endif
1447 if (FRAME_VISIBLE_P (XFRAME (this))
1448 || FRAME_ICONIFIED_P (XFRAME (this))
1449 /* Allow deleting the terminal frame when at least one X
1450 frame exists. */
1451 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1452 return 1;
1454 return 0;
1457 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1458 window. Preferably use the selected frame's minibuffer window
1459 instead. If the selected frame doesn't have one, get some other
1460 frame's minibuffer window. SELECT non-zero means select the new
1461 minibuffer window. */
1462 static void
1463 check_minibuf_window (Lisp_Object frame, int select)
1465 struct frame *f = decode_live_frame (frame);
1467 XSETFRAME (frame, f);
1469 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1471 Lisp_Object frames, this, window = make_number (0);
1473 if (!EQ (frame, selected_frame)
1474 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1475 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1476 else
1477 FOR_EACH_FRAME (frames, this)
1479 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1481 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1482 break;
1486 /* Don't abort if no window was found (Bug#15247). */
1487 if (WINDOWP (window))
1489 /* Use set_window_buffer instead of Fset_window_buffer (see
1490 discussion of bug#11984, bug#12025, bug#12026). */
1491 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1492 minibuf_window = window;
1494 /* SELECT non-zero usually means that FRAME's minibuffer
1495 window was selected; select the new one. */
1496 if (select)
1497 Fselect_window (minibuf_window, Qnil);
1503 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1504 unconditionally. x_connection_closed and delete_terminal use
1505 this. Any other value of FORCE implements the semantics
1506 described for Fdelete_frame. */
1507 Lisp_Object
1508 delete_frame (Lisp_Object frame, Lisp_Object force)
1510 struct frame *f = decode_any_frame (frame);
1511 struct frame *sf;
1512 struct kboard *kb;
1514 int minibuffer_selected, is_tooltip_frame;
1516 if (! FRAME_LIVE_P (f))
1517 return Qnil;
1519 if (NILP (force) && !other_visible_frames (f))
1520 error ("Attempt to delete the sole visible or iconified frame");
1522 /* x_connection_closed must have set FORCE to `noelisp' in order
1523 to delete the last frame, if it is gone. */
1524 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1525 error ("Attempt to delete the only frame");
1527 XSETFRAME (frame, f);
1529 /* Does this frame have a minibuffer, and is it the surrogate
1530 minibuffer for any other frame? */
1531 if (FRAME_HAS_MINIBUF_P (f))
1533 Lisp_Object frames, this;
1535 FOR_EACH_FRAME (frames, this)
1537 Lisp_Object fminiw;
1539 if (EQ (this, frame))
1540 continue;
1542 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1544 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1546 /* If we MUST delete this frame, delete the other first.
1547 But do this only if FORCE equals `noelisp'. */
1548 if (EQ (force, Qnoelisp))
1549 delete_frame (this, Qnoelisp);
1550 else
1551 error ("Attempt to delete a surrogate minibuffer frame");
1556 is_tooltip_frame = !NILP (Fframe_parameter (frame, Qtooltip));
1558 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1559 frame is a tooltip. FORCE is set to `noelisp' when handling
1560 a disconnect from the terminal, so we don't dare call Lisp
1561 code. */
1562 if (NILP (Vrun_hooks) || is_tooltip_frame)
1564 else if (EQ (force, Qnoelisp))
1565 pending_funcalls
1566 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1567 pending_funcalls);
1568 else
1570 #ifdef HAVE_X_WINDOWS
1571 /* Also, save clipboard to the clipboard manager. */
1572 x_clipboard_manager_save_frame (frame);
1573 #endif
1575 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1578 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1579 if (! FRAME_LIVE_P (f))
1580 return Qnil;
1582 /* At this point, we are committed to deleting the frame.
1583 There is no more chance for errors to prevent it. */
1585 minibuffer_selected = EQ (minibuf_window, selected_window);
1586 sf = SELECTED_FRAME ();
1587 /* Don't let the frame remain selected. */
1588 if (f == sf)
1590 Lisp_Object tail;
1591 Lisp_Object frame1 = Qnil;
1593 /* Look for another visible frame on the same terminal.
1594 Do not call next_frame here because it may loop forever.
1595 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1596 FOR_EACH_FRAME (tail, frame1)
1597 if (!EQ (frame, frame1)
1598 && (FRAME_TERMINAL (XFRAME (frame))
1599 == FRAME_TERMINAL (XFRAME (frame1)))
1600 && FRAME_VISIBLE_P (XFRAME (frame1)))
1601 break;
1603 /* If there is none, find *some* other frame. */
1604 if (NILP (frame1) || EQ (frame1, frame))
1606 FOR_EACH_FRAME (tail, frame1)
1608 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1610 /* Do not change a text terminal's top-frame. */
1611 struct frame *f1 = XFRAME (frame1);
1612 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1614 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1615 if (!EQ (top_frame, frame))
1616 frame1 = top_frame;
1618 break;
1622 #ifdef NS_IMPL_COCOA
1623 else
1624 /* Under NS, there is no system mechanism for choosing a new
1625 window to get focus -- it is left to application code.
1626 So the portion of THIS application interfacing with NS
1627 needs to know about it. We call Fraise_frame, but the
1628 purpose is really to transfer focus. */
1629 Fraise_frame (frame1);
1630 #endif
1632 do_switch_frame (frame1, 0, 1, Qnil);
1633 sf = SELECTED_FRAME ();
1636 /* Don't allow minibuf_window to remain on a deleted frame. */
1637 check_minibuf_window (frame, minibuffer_selected);
1639 /* Don't let echo_area_window to remain on a deleted frame. */
1640 if (EQ (f->minibuffer_window, echo_area_window))
1641 echo_area_window = sf->minibuffer_window;
1643 /* Clear any X selections for this frame. */
1644 #ifdef HAVE_X_WINDOWS
1645 if (FRAME_X_P (f))
1646 x_clear_frame_selections (f);
1647 #endif
1649 /* Free glyphs.
1650 This function must be called before the window tree of the
1651 frame is deleted because windows contain dynamically allocated
1652 memory. */
1653 free_glyphs (f);
1655 #ifdef HAVE_WINDOW_SYSTEM
1656 /* Give chance to each font driver to free a frame specific data. */
1657 font_update_drivers (f, Qnil);
1658 #endif
1660 /* Mark all the windows that used to be on FRAME as deleted, and then
1661 remove the reference to them. */
1662 delete_all_child_windows (f->root_window);
1663 fset_root_window (f, Qnil);
1665 Vframe_list = Fdelq (frame, Vframe_list);
1666 SET_FRAME_VISIBLE (f, 0);
1668 /* Allow the vector of menu bar contents to be freed in the next
1669 garbage collection. The frame object itself may not be garbage
1670 collected until much later, because recent_keys and other data
1671 structures can still refer to it. */
1672 fset_menu_bar_vector (f, Qnil);
1674 /* If FRAME's buffer lists contains killed
1675 buffers, this helps GC to reclaim them. */
1676 fset_buffer_list (f, Qnil);
1677 fset_buried_buffer_list (f, Qnil);
1679 free_font_driver_list (f);
1680 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1681 xfree (f->namebuf);
1682 #endif
1683 xfree (f->decode_mode_spec_buffer);
1684 xfree (FRAME_INSERT_COST (f));
1685 xfree (FRAME_DELETEN_COST (f));
1686 xfree (FRAME_INSERTN_COST (f));
1687 xfree (FRAME_DELETE_COST (f));
1689 /* Since some events are handled at the interrupt level, we may get
1690 an event for f at any time; if we zero out the frame's terminal
1691 now, then we may trip up the event-handling code. Instead, we'll
1692 promise that the terminal of the frame must be valid until we
1693 have called the window-system-dependent frame destruction
1694 routine. */
1698 struct terminal *terminal;
1699 block_input ();
1700 if (FRAME_TERMINAL (f)->delete_frame_hook)
1701 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1702 terminal = FRAME_TERMINAL (f);
1703 f->output_data.nothing = 0;
1704 f->terminal = 0; /* Now the frame is dead. */
1705 unblock_input ();
1707 /* If needed, delete the terminal that this frame was on.
1708 (This must be done after the frame is killed.) */
1709 terminal->reference_count--;
1710 #ifdef USE_GTK
1711 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1712 bug.
1713 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1714 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1715 terminal->reference_count = 1;
1716 #endif /* USE_GTK */
1717 if (terminal->reference_count == 0)
1719 Lisp_Object tmp;
1720 XSETTERMINAL (tmp, terminal);
1722 kb = NULL;
1723 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1725 else
1726 kb = terminal->kboard;
1729 /* If we've deleted the last_nonminibuf_frame, then try to find
1730 another one. */
1731 if (f == last_nonminibuf_frame)
1733 Lisp_Object frames, this;
1735 last_nonminibuf_frame = 0;
1737 FOR_EACH_FRAME (frames, this)
1739 f = XFRAME (this);
1740 if (!FRAME_MINIBUF_ONLY_P (f))
1742 last_nonminibuf_frame = f;
1743 break;
1748 /* If there's no other frame on the same kboard, get out of
1749 single-kboard state if we're in it for this kboard. */
1750 if (kb != NULL)
1752 Lisp_Object frames, this;
1753 /* Some frame we found on the same kboard, or nil if there are none. */
1754 Lisp_Object frame_on_same_kboard = Qnil;
1756 FOR_EACH_FRAME (frames, this)
1757 if (kb == FRAME_KBOARD (XFRAME (this)))
1758 frame_on_same_kboard = this;
1760 if (NILP (frame_on_same_kboard))
1761 not_single_kboard_state (kb);
1765 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1766 find another one. Prefer minibuffer-only frames, but also notice
1767 frames with other windows. */
1768 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1770 Lisp_Object frames, this;
1772 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1773 Lisp_Object frame_with_minibuf = Qnil;
1774 /* Some frame we found on the same kboard, or nil if there are none. */
1775 Lisp_Object frame_on_same_kboard = Qnil;
1777 FOR_EACH_FRAME (frames, this)
1779 struct frame *f1 = XFRAME (this);
1781 /* Consider only frames on the same kboard
1782 and only those with minibuffers. */
1783 if (kb == FRAME_KBOARD (f1)
1784 && FRAME_HAS_MINIBUF_P (f1))
1786 frame_with_minibuf = this;
1787 if (FRAME_MINIBUF_ONLY_P (f1))
1788 break;
1791 if (kb == FRAME_KBOARD (f1))
1792 frame_on_same_kboard = this;
1795 if (!NILP (frame_on_same_kboard))
1797 /* We know that there must be some frame with a minibuffer out
1798 there. If this were not true, all of the frames present
1799 would have to be minibufferless, which implies that at some
1800 point their minibuffer frames must have been deleted, but
1801 that is prohibited at the top; you can't delete surrogate
1802 minibuffer frames. */
1803 if (NILP (frame_with_minibuf))
1804 emacs_abort ();
1806 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1808 else
1809 /* No frames left on this kboard--say no minibuffer either. */
1810 kset_default_minibuffer_frame (kb, Qnil);
1813 /* Cause frame titles to update--necessary if we now have just one frame. */
1814 if (!is_tooltip_frame)
1815 update_mode_lines = 15;
1817 return Qnil;
1820 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1821 doc: /* Delete FRAME, permanently eliminating it from use.
1822 FRAME defaults to the selected frame.
1824 A frame may not be deleted if its minibuffer serves as surrogate
1825 minibuffer for another frame. Normally, you may not delete a frame if
1826 all other frames are invisible, but if the second optional argument
1827 FORCE is non-nil, you may do so.
1829 This function runs `delete-frame-functions' before actually
1830 deleting the frame, unless the frame is a tooltip.
1831 The functions are run with one argument, the frame to be deleted. */)
1832 (Lisp_Object frame, Lisp_Object force)
1834 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1838 /* Return mouse position in character cell units. */
1840 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1841 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1842 The position is given in canonical character cells, where (0, 0) is the
1843 upper-left corner of the frame, X is the horizontal offset, and Y is the
1844 vertical offset, measured in units of the frame's default character size.
1845 If Emacs is running on a mouseless terminal or hasn't been programmed
1846 to read the mouse position, it returns the selected frame for FRAME
1847 and nil for X and Y.
1848 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1849 passing the normal return value to that function as an argument,
1850 and returns whatever that function returns. */)
1851 (void)
1853 struct frame *f;
1854 Lisp_Object lispy_dummy;
1855 Lisp_Object x, y, retval;
1857 f = SELECTED_FRAME ();
1858 x = y = Qnil;
1860 /* It's okay for the hook to refrain from storing anything. */
1861 if (FRAME_TERMINAL (f)->mouse_position_hook)
1863 enum scroll_bar_part party_dummy;
1864 Time time_dummy;
1865 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1866 &lispy_dummy, &party_dummy,
1867 &x, &y,
1868 &time_dummy);
1871 if (! NILP (x))
1873 int col = XINT (x);
1874 int row = XINT (y);
1875 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1876 XSETINT (x, col);
1877 XSETINT (y, row);
1879 XSETFRAME (lispy_dummy, f);
1880 retval = Fcons (lispy_dummy, Fcons (x, y));
1881 if (!NILP (Vmouse_position_function))
1882 retval = call1 (Vmouse_position_function, retval);
1883 return retval;
1886 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1887 Smouse_pixel_position, 0, 0, 0,
1888 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1889 The position is given in pixel units, where (0, 0) is the
1890 upper-left corner of the frame, X is the horizontal offset, and Y is
1891 the vertical offset.
1892 If Emacs is running on a mouseless terminal or hasn't been programmed
1893 to read the mouse position, it returns the selected frame for FRAME
1894 and nil for X and Y. */)
1895 (void)
1897 struct frame *f;
1898 Lisp_Object lispy_dummy;
1899 Lisp_Object x, y, retval;
1901 f = SELECTED_FRAME ();
1902 x = y = Qnil;
1904 /* It's okay for the hook to refrain from storing anything. */
1905 if (FRAME_TERMINAL (f)->mouse_position_hook)
1907 enum scroll_bar_part party_dummy;
1908 Time time_dummy;
1909 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1910 &lispy_dummy, &party_dummy,
1911 &x, &y,
1912 &time_dummy);
1915 XSETFRAME (lispy_dummy, f);
1916 retval = Fcons (lispy_dummy, Fcons (x, y));
1917 if (!NILP (Vmouse_position_function))
1918 retval = call1 (Vmouse_position_function, retval);
1919 return retval;
1922 #ifdef HAVE_WINDOW_SYSTEM
1924 /* On frame F, convert character coordinates X and Y to pixel
1925 coordinates *PIX_X and *PIX_Y. */
1927 static void
1928 frame_char_to_pixel_position (struct frame *f, int x, int y,
1929 int *pix_x, int *pix_y)
1931 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
1932 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
1934 if (*pix_x < 0)
1935 *pix_x = 0;
1936 if (*pix_x > FRAME_PIXEL_WIDTH (f))
1937 *pix_x = FRAME_PIXEL_WIDTH (f);
1939 if (*pix_y < 0)
1940 *pix_y = 0;
1941 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
1942 *pix_y = FRAME_PIXEL_HEIGHT (f);
1945 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1947 static void
1948 frame_set_mouse_position (struct frame *f, int x, int y)
1950 int pix_x, pix_y;
1952 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
1953 frame_set_mouse_pixel_position (f, pix_x, pix_y);
1956 #endif /* HAVE_WINDOW_SYSTEM */
1958 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1959 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1960 Coordinates are relative to the frame, not a window,
1961 so the coordinates of the top left character in the frame
1962 may be nonzero due to left-hand scroll bars or the menu bar.
1964 The position is given in canonical character cells, where (0, 0) is
1965 the upper-left corner of the frame, X is the horizontal offset, and
1966 Y is the vertical offset, measured in units of the frame's default
1967 character size.
1969 This function is a no-op for an X frame that is not visible.
1970 If you have just created a frame, you must wait for it to become visible
1971 before calling this function on it, like this.
1972 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1973 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1975 CHECK_LIVE_FRAME (frame);
1976 CHECK_TYPE_RANGED_INTEGER (int, x);
1977 CHECK_TYPE_RANGED_INTEGER (int, y);
1979 /* I think this should be done with a hook. */
1980 #ifdef HAVE_WINDOW_SYSTEM
1981 if (FRAME_WINDOW_P (XFRAME (frame)))
1982 /* Warping the mouse will cause enternotify and focus events. */
1983 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1984 #else
1985 #if defined (MSDOS)
1986 if (FRAME_MSDOS_P (XFRAME (frame)))
1988 Fselect_frame (frame, Qnil);
1989 mouse_moveto (XINT (x), XINT (y));
1991 #else
1992 #ifdef HAVE_GPM
1994 Fselect_frame (frame, Qnil);
1995 term_mouse_moveto (XINT (x), XINT (y));
1997 #endif
1998 #endif
1999 #endif
2001 return Qnil;
2004 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
2005 Sset_mouse_pixel_position, 3, 3, 0,
2006 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
2007 The position is given in pixels, where (0, 0) is the upper-left corner
2008 of the frame, X is the horizontal offset, and Y is the vertical offset.
2010 Note, this is a no-op for an X frame that is not visible.
2011 If you have just created a frame, you must wait for it to become visible
2012 before calling this function on it, like this.
2013 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2014 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2016 CHECK_LIVE_FRAME (frame);
2017 CHECK_TYPE_RANGED_INTEGER (int, x);
2018 CHECK_TYPE_RANGED_INTEGER (int, y);
2020 /* I think this should be done with a hook. */
2021 #ifdef HAVE_WINDOW_SYSTEM
2022 if (FRAME_WINDOW_P (XFRAME (frame)))
2023 /* Warping the mouse will cause enternotify and focus events. */
2024 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
2025 #else
2026 #if defined (MSDOS)
2027 if (FRAME_MSDOS_P (XFRAME (frame)))
2029 Fselect_frame (frame, Qnil);
2030 mouse_moveto (XINT (x), XINT (y));
2032 #else
2033 #ifdef HAVE_GPM
2035 Fselect_frame (frame, Qnil);
2036 term_mouse_moveto (XINT (x), XINT (y));
2038 #endif
2039 #endif
2040 #endif
2042 return Qnil;
2045 static void make_frame_visible_1 (Lisp_Object);
2047 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2048 0, 1, "",
2049 doc: /* Make the frame FRAME visible (assuming it is an X window).
2050 If omitted, FRAME defaults to the currently selected frame. */)
2051 (Lisp_Object frame)
2053 struct frame *f = decode_live_frame (frame);
2055 /* I think this should be done with a hook. */
2056 #ifdef HAVE_WINDOW_SYSTEM
2057 if (FRAME_WINDOW_P (f))
2058 x_make_frame_visible (f);
2059 #endif
2061 make_frame_visible_1 (f->root_window);
2063 /* Make menu bar update for the Buffers and Frames menus. */
2064 /* windows_or_buffers_changed = 15; FIXME: Why? */
2066 XSETFRAME (frame, f);
2067 return frame;
2070 /* Update the display_time slot of the buffers shown in WINDOW
2071 and all its descendants. */
2073 static void
2074 make_frame_visible_1 (Lisp_Object window)
2076 struct window *w;
2078 for (; !NILP (window); window = w->next)
2080 w = XWINDOW (window);
2081 if (WINDOWP (w->contents))
2082 make_frame_visible_1 (w->contents);
2083 else
2084 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2088 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2089 0, 2, "",
2090 doc: /* Make the frame FRAME invisible.
2091 If omitted, FRAME defaults to the currently selected frame.
2092 On graphical displays, invisible frames are not updated and are
2093 usually not displayed at all, even in a window system's \"taskbar\".
2095 Normally you may not make FRAME invisible if all other frames are invisible,
2096 but if the second optional argument FORCE is non-nil, you may do so.
2098 This function has no effect on text terminal frames. Such frames are
2099 always considered visible, whether or not they are currently being
2100 displayed in the terminal. */)
2101 (Lisp_Object frame, Lisp_Object force)
2103 struct frame *f = decode_live_frame (frame);
2105 if (NILP (force) && !other_visible_frames (f))
2106 error ("Attempt to make invisible the sole visible or iconified frame");
2108 /* Don't allow minibuf_window to remain on an invisible frame. */
2109 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2111 /* I think this should be done with a hook. */
2112 #ifdef HAVE_WINDOW_SYSTEM
2113 if (FRAME_WINDOW_P (f))
2114 x_make_frame_invisible (f);
2115 #endif
2117 /* Make menu bar update for the Buffers and Frames menus. */
2118 windows_or_buffers_changed = 16;
2120 return Qnil;
2123 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2124 0, 1, "",
2125 doc: /* Make the frame FRAME into an icon.
2126 If omitted, FRAME defaults to the currently selected frame. */)
2127 (Lisp_Object frame)
2129 struct frame *f = decode_live_frame (frame);
2131 /* Don't allow minibuf_window to remain on an iconified frame. */
2132 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2134 /* I think this should be done with a hook. */
2135 #ifdef HAVE_WINDOW_SYSTEM
2136 if (FRAME_WINDOW_P (f))
2137 x_iconify_frame (f);
2138 #endif
2140 /* Make menu bar update for the Buffers and Frames menus. */
2141 windows_or_buffers_changed = 17;
2143 return Qnil;
2146 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2147 1, 1, 0,
2148 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2149 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2150 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2151 On graphical displays, invisible frames are not updated and are
2152 usually not displayed at all, even in a window system's \"taskbar\".
2154 If FRAME is a text terminal frame, this always returns t.
2155 Such frames are always considered visible, whether or not they are
2156 currently being displayed on the terminal. */)
2157 (Lisp_Object frame)
2159 CHECK_LIVE_FRAME (frame);
2161 if (FRAME_VISIBLE_P (XFRAME (frame)))
2162 return Qt;
2163 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2164 return Qicon;
2165 return Qnil;
2168 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2169 0, 0, 0,
2170 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2171 (void)
2173 Lisp_Object tail, frame, value = Qnil;
2175 FOR_EACH_FRAME (tail, frame)
2176 if (FRAME_VISIBLE_P (XFRAME (frame)))
2177 value = Fcons (frame, value);
2179 return value;
2183 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2184 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2185 If FRAME is invisible or iconified, make it visible.
2186 If you don't specify a frame, the selected frame is used.
2187 If Emacs is displaying on an ordinary terminal or some other device which
2188 doesn't support multiple overlapping frames, this function selects FRAME. */)
2189 (Lisp_Object frame)
2191 struct frame *f = decode_live_frame (frame);
2193 XSETFRAME (frame, f);
2195 if (FRAME_TERMCAP_P (f))
2196 /* On a text terminal select FRAME. */
2197 Fselect_frame (frame, Qnil);
2198 else
2199 /* Do like the documentation says. */
2200 Fmake_frame_visible (frame);
2202 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2203 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2205 return Qnil;
2208 /* Should we have a corresponding function called Flower_Power? */
2209 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2210 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2211 If you don't specify a frame, the selected frame is used.
2212 If Emacs is displaying on an ordinary terminal or some other device which
2213 doesn't support multiple overlapping frames, this function does nothing. */)
2214 (Lisp_Object frame)
2216 struct frame *f = decode_live_frame (frame);
2218 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2219 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2221 return Qnil;
2225 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2226 1, 2, 0,
2227 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2228 In other words, switch-frame events caused by events in FRAME will
2229 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2230 FOCUS-FRAME after reading an event typed at FRAME.
2232 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2233 frame again receives its own keystrokes.
2235 Focus redirection is useful for temporarily redirecting keystrokes to
2236 a surrogate minibuffer frame when a frame doesn't have its own
2237 minibuffer window.
2239 A frame's focus redirection can be changed by `select-frame'. If frame
2240 FOO is selected, and then a different frame BAR is selected, any
2241 frames redirecting their focus to FOO are shifted to redirect their
2242 focus to BAR. This allows focus redirection to work properly when the
2243 user switches from one frame to another using `select-window'.
2245 This means that a frame whose focus is redirected to itself is treated
2246 differently from a frame whose focus is redirected to nil; the former
2247 is affected by `select-frame', while the latter is not.
2249 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2250 (Lisp_Object frame, Lisp_Object focus_frame)
2252 /* Note that we don't check for a live frame here. It's reasonable
2253 to redirect the focus of a frame you're about to delete, if you
2254 know what other frame should receive those keystrokes. */
2255 struct frame *f = decode_any_frame (frame);
2257 if (! NILP (focus_frame))
2258 CHECK_LIVE_FRAME (focus_frame);
2260 fset_focus_frame (f, focus_frame);
2262 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2263 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2265 return Qnil;
2269 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2270 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2271 If FRAME is omitted or nil, the selected frame is used.
2272 Return nil if FRAME's focus is not redirected.
2273 See `redirect-frame-focus'. */)
2274 (Lisp_Object frame)
2276 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2279 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2280 doc: /* Set the input focus to FRAME.
2281 FRAME nil means use the selected frame.
2282 If there is no window system support, this function does nothing. */)
2283 (Lisp_Object frame)
2285 #ifdef HAVE_WINDOW_SYSTEM
2286 x_focus_frame (decode_window_system_frame (frame));
2287 #endif
2288 return Qnil;
2291 DEFUN ("frame-after-make-frame",
2292 Fframe_after_make_frame,
2293 Sframe_after_make_frame, 2, 2, 0,
2294 doc: /* Mark FRAME as made.
2295 FRAME nil means use the selected frame. Second argument MADE non-nil
2296 means functions on `window-configuration-change-hook' are called
2297 whenever the window configuration of FRAME changes. MADE nil means
2298 these functions are not called.
2300 This function is currently called by `make-frame' only and should be
2301 otherwise used with utter care to avoid that running functions on
2302 `window-configuration-change-hook' is impeded forever. */)
2303 (Lisp_Object frame, Lisp_Object made)
2305 struct frame *f = decode_live_frame (frame);
2306 f->after_make_frame = !NILP (made);
2307 return made;
2311 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2313 void
2314 frames_discard_buffer (Lisp_Object buffer)
2316 Lisp_Object frame, tail;
2318 FOR_EACH_FRAME (tail, frame)
2320 fset_buffer_list
2321 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2322 fset_buried_buffer_list
2323 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2327 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2328 If the alist already has an element for PROP, we change it. */
2330 void
2331 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2333 register Lisp_Object tem;
2335 tem = Fassq (prop, *alistptr);
2336 if (EQ (tem, Qnil))
2337 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2338 else
2339 Fsetcdr (tem, val);
2342 static int
2343 frame_name_fnn_p (char *str, ptrdiff_t len)
2345 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2347 char *p = str + 2;
2348 while ('0' <= *p && *p <= '9')
2349 p++;
2350 if (p == str + len)
2351 return 1;
2353 return 0;
2356 /* Set the name of the terminal frame. Also used by MSDOS frames.
2357 Modeled after x_set_name which is used for WINDOW frames. */
2359 static void
2360 set_term_frame_name (struct frame *f, Lisp_Object name)
2362 f->explicit_name = ! NILP (name);
2364 /* If NAME is nil, set the name to F<num>. */
2365 if (NILP (name))
2367 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2369 /* Check for no change needed in this very common case
2370 before we do any consing. */
2371 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2372 return;
2374 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2376 else
2378 CHECK_STRING (name);
2380 /* Don't change the name if it's already NAME. */
2381 if (! NILP (Fstring_equal (name, f->name)))
2382 return;
2384 /* Don't allow the user to set the frame name to F<num>, so it
2385 doesn't clash with the names we generate for terminal frames. */
2386 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2387 error ("Frame names of the form F<num> are usurped by Emacs");
2390 fset_name (f, name);
2391 update_mode_lines = 16;
2394 void
2395 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2397 register Lisp_Object old_alist_elt;
2399 /* The buffer-list parameters are stored in a special place and not
2400 in the alist. All buffers must be live. */
2401 if (EQ (prop, Qbuffer_list))
2403 Lisp_Object list = Qnil;
2404 for (; CONSP (val); val = XCDR (val))
2405 if (!NILP (Fbuffer_live_p (XCAR (val))))
2406 list = Fcons (XCAR (val), list);
2407 fset_buffer_list (f, Fnreverse (list));
2408 return;
2410 if (EQ (prop, Qburied_buffer_list))
2412 Lisp_Object list = Qnil;
2413 for (; CONSP (val); val = XCDR (val))
2414 if (!NILP (Fbuffer_live_p (XCAR (val))))
2415 list = Fcons (XCAR (val), list);
2416 fset_buried_buffer_list (f, Fnreverse (list));
2417 return;
2420 /* If PROP is a symbol which is supposed to have frame-local values,
2421 and it is set up based on this frame, switch to the global
2422 binding. That way, we can create or alter the frame-local binding
2423 without messing up the symbol's status. */
2424 if (SYMBOLP (prop))
2426 struct Lisp_Symbol *sym = XSYMBOL (prop);
2427 start:
2428 switch (sym->redirect)
2430 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2431 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2432 case SYMBOL_LOCALIZED:
2433 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2434 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2435 swap_in_global_binding (sym);
2436 break;
2438 default: emacs_abort ();
2442 /* The tty color needed to be set before the frame's parameter
2443 alist was updated with the new value. This is not true any more,
2444 but we still do this test early on. */
2445 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2446 && f == FRAME_TTY (f)->previous_frame)
2447 /* Force redisplay of this tty. */
2448 FRAME_TTY (f)->previous_frame = NULL;
2450 /* Update the frame parameter alist. */
2451 old_alist_elt = Fassq (prop, f->param_alist);
2452 if (EQ (old_alist_elt, Qnil))
2453 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2454 else
2455 Fsetcdr (old_alist_elt, val);
2457 /* Update some other special parameters in their special places
2458 in addition to the alist. */
2460 if (EQ (prop, Qbuffer_predicate))
2461 fset_buffer_predicate (f, val);
2463 if (! FRAME_WINDOW_P (f))
2465 if (EQ (prop, Qmenu_bar_lines))
2466 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2467 else if (EQ (prop, Qname))
2468 set_term_frame_name (f, val);
2471 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2473 if (! MINI_WINDOW_P (XWINDOW (val)))
2474 error ("Surrogate minibuffer windows must be minibuffer windows");
2476 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2477 && !EQ (val, f->minibuffer_window))
2478 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2480 /* Install the chosen minibuffer window, with proper buffer. */
2481 fset_minibuffer_window (f, val);
2485 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2486 is not an unspecified foreground or background color. */
2488 static Lisp_Object
2489 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2491 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2492 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2493 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2494 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2497 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2498 doc: /* Return the parameters-alist of frame FRAME.
2499 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2500 The meaningful PARMs depend on the kind of frame.
2501 If FRAME is omitted or nil, return information on the currently selected frame. */)
2502 (Lisp_Object frame)
2504 Lisp_Object alist;
2505 struct frame *f = decode_any_frame (frame);
2506 int height, width;
2508 if (!FRAME_LIVE_P (f))
2509 return Qnil;
2511 alist = Fcopy_alist (f->param_alist);
2513 if (!FRAME_WINDOW_P (f))
2515 Lisp_Object elt;
2517 /* If the frame's parameter alist says the colors are
2518 unspecified and reversed, take the frame's background pixel
2519 for foreground and vice versa. */
2520 elt = Fassq (Qforeground_color, alist);
2521 if (CONSP (elt) && STRINGP (XCDR (elt)))
2523 elt = frame_unspecified_color (f, XCDR (elt));
2524 if (!NILP (elt))
2525 store_in_alist (&alist, Qforeground_color, elt);
2527 else
2528 store_in_alist (&alist, Qforeground_color,
2529 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2530 elt = Fassq (Qbackground_color, alist);
2531 if (CONSP (elt) && STRINGP (XCDR (elt)))
2533 elt = frame_unspecified_color (f, XCDR (elt));
2534 if (!NILP (elt))
2535 store_in_alist (&alist, Qbackground_color, elt);
2537 else
2538 store_in_alist (&alist, Qbackground_color,
2539 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2540 store_in_alist (&alist, Qfont,
2541 build_string (FRAME_MSDOS_P (f)
2542 ? "ms-dos"
2543 : FRAME_W32_P (f) ? "w32term"
2544 :"tty"));
2546 store_in_alist (&alist, Qname, f->name);
2547 height = (f->new_height
2548 ? (f->new_pixelwise
2549 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2550 : f->new_height)
2551 : FRAME_LINES (f));
2552 store_in_alist (&alist, Qheight, make_number (height));
2553 width = (f->new_width
2554 ? (f->new_pixelwise
2555 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2556 : f->new_width)
2557 : FRAME_COLS (f));
2558 store_in_alist (&alist, Qwidth, make_number (width));
2559 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2560 store_in_alist (&alist, Qminibuffer,
2561 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2562 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2563 : FRAME_MINIBUF_WINDOW (f)));
2564 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2565 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2566 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2568 /* I think this should be done with a hook. */
2569 #ifdef HAVE_WINDOW_SYSTEM
2570 if (FRAME_WINDOW_P (f))
2571 x_report_frame_params (f, &alist);
2572 else
2573 #endif
2575 /* This ought to be correct in f->param_alist for an X frame. */
2576 Lisp_Object lines;
2577 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2578 store_in_alist (&alist, Qmenu_bar_lines, lines);
2581 return alist;
2585 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2586 doc: /* Return FRAME's value for parameter PARAMETER.
2587 If FRAME is nil, describe the currently selected frame. */)
2588 (Lisp_Object frame, Lisp_Object parameter)
2590 struct frame *f = decode_any_frame (frame);
2591 Lisp_Object value = Qnil;
2593 CHECK_SYMBOL (parameter);
2595 XSETFRAME (frame, f);
2597 if (FRAME_LIVE_P (f))
2599 /* Avoid consing in frequent cases. */
2600 if (EQ (parameter, Qname))
2601 value = f->name;
2602 #ifdef HAVE_X_WINDOWS
2603 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2604 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2605 #endif /* HAVE_X_WINDOWS */
2606 else if (EQ (parameter, Qbackground_color)
2607 || EQ (parameter, Qforeground_color))
2609 value = Fassq (parameter, f->param_alist);
2610 if (CONSP (value))
2612 value = XCDR (value);
2613 /* Fframe_parameters puts the actual fg/bg color names,
2614 even if f->param_alist says otherwise. This is
2615 important when param_alist's notion of colors is
2616 "unspecified". We need to do the same here. */
2617 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2619 Lisp_Object tem = frame_unspecified_color (f, value);
2621 if (!NILP (tem))
2622 value = tem;
2625 else
2626 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2628 else if (EQ (parameter, Qdisplay_type)
2629 || EQ (parameter, Qbackground_mode))
2630 value = Fcdr (Fassq (parameter, f->param_alist));
2631 else
2632 /* FIXME: Avoid this code path at all (as well as code duplication)
2633 by sharing more code with Fframe_parameters. */
2634 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2637 return value;
2641 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2642 Smodify_frame_parameters, 2, 2, 0,
2643 doc: /* Modify the parameters of frame FRAME according to ALIST.
2644 If FRAME is nil, it defaults to the selected frame.
2645 ALIST is an alist of parameters to change and their new values.
2646 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2647 The meaningful PARMs depend on the kind of frame.
2648 Undefined PARMs are ignored, but stored in the frame's parameter list
2649 so that `frame-parameters' will return them.
2651 The value of frame parameter FOO can also be accessed
2652 as a frame-local binding for the variable FOO, if you have
2653 enabled such bindings for that variable with `make-variable-frame-local'.
2654 Note that this functionality is obsolete as of Emacs 22.2, and its
2655 use is not recommended. Explicitly check for a frame-parameter instead. */)
2656 (Lisp_Object frame, Lisp_Object alist)
2658 struct frame *f = decode_live_frame (frame);
2659 register Lisp_Object prop, val;
2661 CHECK_LIST (alist);
2663 /* I think this should be done with a hook. */
2664 #ifdef HAVE_WINDOW_SYSTEM
2665 if (FRAME_WINDOW_P (f))
2666 x_set_frame_parameters (f, alist);
2667 else
2668 #endif
2669 #ifdef MSDOS
2670 if (FRAME_MSDOS_P (f))
2671 IT_set_frame_parameters (f, alist);
2672 else
2673 #endif
2676 EMACS_INT length = XFASTINT (Flength (alist));
2677 ptrdiff_t i;
2678 Lisp_Object *parms;
2679 Lisp_Object *values;
2680 USE_SAFE_ALLOCA;
2681 SAFE_ALLOCA_LISP (parms, 2 * length);
2682 values = parms + length;
2684 /* Extract parm names and values into those vectors. */
2686 for (i = 0; CONSP (alist); alist = XCDR (alist))
2688 Lisp_Object elt;
2690 elt = XCAR (alist);
2691 parms[i] = Fcar (elt);
2692 values[i] = Fcdr (elt);
2693 i++;
2696 /* Now process them in reverse of specified order. */
2697 while (--i >= 0)
2699 prop = parms[i];
2700 val = values[i];
2701 store_frame_param (f, prop, val);
2703 if (EQ (prop, Qforeground_color)
2704 || EQ (prop, Qbackground_color))
2705 update_face_from_frame_parameter (f, prop, val);
2708 SAFE_FREE ();
2710 return Qnil;
2713 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2714 0, 1, 0,
2715 doc: /* Height in pixels of a line in the font in frame FRAME.
2716 If FRAME is omitted or nil, the selected frame is used.
2717 For a terminal frame, the value is always 1. */)
2718 (Lisp_Object frame)
2720 #ifdef HAVE_WINDOW_SYSTEM
2721 struct frame *f = decode_any_frame (frame);
2723 if (FRAME_WINDOW_P (f))
2724 return make_number (FRAME_LINE_HEIGHT (f));
2725 else
2726 #endif
2727 return make_number (1);
2731 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2732 0, 1, 0,
2733 doc: /* Width in pixels of characters in the font in frame FRAME.
2734 If FRAME is omitted or nil, the selected frame is used.
2735 On a graphical screen, the width is the standard width of the default font.
2736 For a terminal screen, the value is always 1. */)
2737 (Lisp_Object frame)
2739 #ifdef HAVE_WINDOW_SYSTEM
2740 struct frame *f = decode_any_frame (frame);
2742 if (FRAME_WINDOW_P (f))
2743 return make_number (FRAME_COLUMN_WIDTH (f));
2744 else
2745 #endif
2746 return make_number (1);
2749 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2750 Sframe_pixel_height, 0, 1, 0,
2751 doc: /* Return a FRAME's height in pixels.
2752 If FRAME is omitted or nil, the selected frame is used. The exact value
2753 of the result depends on the window-system and toolkit in use:
2755 In the Gtk+ version of Emacs, it includes only any window (including
2756 the minibuffer or echo area), mode line, and header line. It does not
2757 include the tool bar or menu bar.
2759 With other graphical versions, it also includes the tool bar and the
2760 menu bar.
2762 For a text terminal, it includes the menu bar. In this case, the
2763 result is really in characters rather than pixels (i.e., is identical
2764 to `frame-height'). */)
2765 (Lisp_Object frame)
2767 struct frame *f = decode_any_frame (frame);
2769 #ifdef HAVE_WINDOW_SYSTEM
2770 if (FRAME_WINDOW_P (f))
2771 return make_number (FRAME_PIXEL_HEIGHT (f));
2772 else
2773 #endif
2774 return make_number (FRAME_TOTAL_LINES (f));
2777 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2778 Sframe_pixel_width, 0, 1, 0,
2779 doc: /* Return FRAME's width in pixels.
2780 For a terminal frame, the result really gives the width in characters.
2781 If FRAME is omitted or nil, the selected frame is used. */)
2782 (Lisp_Object frame)
2784 struct frame *f = decode_any_frame (frame);
2786 #ifdef HAVE_WINDOW_SYSTEM
2787 if (FRAME_WINDOW_P (f))
2788 return make_number (FRAME_PIXEL_WIDTH (f));
2789 else
2790 #endif
2791 return make_number (FRAME_TOTAL_COLS (f));
2794 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2795 Stool_bar_pixel_width, 0, 1, 0,
2796 doc: /* Return width in pixels of FRAME's tool bar.
2797 The result is greater than zero only when the tool bar is on the left
2798 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2799 is used. */)
2800 (Lisp_Object frame)
2802 #ifdef FRAME_TOOLBAR_WIDTH
2803 struct frame *f = decode_any_frame (frame);
2805 if (FRAME_WINDOW_P (f))
2806 return make_number (FRAME_TOOLBAR_WIDTH (f));
2807 #endif
2808 return make_number (0);
2811 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2812 doc: /* Return width in columns of FRAME's text area. */)
2813 (Lisp_Object frame)
2815 return make_number (FRAME_COLS (decode_any_frame (frame)));
2818 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2819 doc: /* Return height in lines of FRAME's text area. */)
2820 (Lisp_Object frame)
2822 return make_number (FRAME_LINES (decode_any_frame (frame)));
2825 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2826 doc: /* Return number of total columns of FRAME. */)
2827 (Lisp_Object frame)
2829 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2832 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2833 doc: /* Return number of total lines of FRAME. */)
2834 (Lisp_Object frame)
2836 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2839 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2840 doc: /* Return text area width of FRAME in pixels. */)
2841 (Lisp_Object frame)
2843 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2846 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2847 doc: /* Return text area height of FRAME in pixels. */)
2848 (Lisp_Object frame)
2850 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2853 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2854 doc: /* Return scroll bar width of FRAME in pixels. */)
2855 (Lisp_Object frame)
2857 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2860 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2861 doc: /* Return scroll bar height of FRAME in pixels. */)
2862 (Lisp_Object frame)
2864 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2867 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2868 doc: /* Return fringe width of FRAME in pixels. */)
2869 (Lisp_Object frame)
2871 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2874 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2875 doc: /* Return border width of FRAME in pixels. */)
2876 (Lisp_Object frame)
2878 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2881 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2882 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2883 (Lisp_Object frame)
2885 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2888 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2889 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2890 (Lisp_Object frame)
2892 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2895 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2896 doc: /* Set text height of frame FRAME to HEIGHT lines.
2897 Optional third arg PRETEND non-nil means that redisplay should use
2898 HEIGHT lines but that the idea of the actual height of the frame should
2899 not be changed.
2901 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2902 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
2903 window managers may refuse to honor a HEIGHT that is not an integer
2904 multiple of the default frame font height. */)
2905 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2907 struct frame *f = decode_live_frame (frame);
2908 int pixel_height;
2910 CHECK_TYPE_RANGED_INTEGER (int, height);
2912 pixel_height = (!NILP (pixelwise)
2913 ? XINT (height)
2914 : XINT (height) * FRAME_LINE_HEIGHT (f));
2915 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
2917 return Qnil;
2920 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2921 doc: /* Set text width of frame FRAME to WIDTH columns.
2922 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2923 columns but that the idea of the actual width of the frame should not
2924 be changed.
2926 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2927 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
2928 window managers may refuse to honor a WIDTH that is not an integer
2929 multiple of the default frame font width. */)
2930 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2932 struct frame *f = decode_live_frame (frame);
2933 int pixel_width;
2935 CHECK_TYPE_RANGED_INTEGER (int, width);
2937 pixel_width = (!NILP (pixelwise)
2938 ? XINT (width)
2939 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2940 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
2942 return Qnil;
2945 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2946 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
2947 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
2948 When `frame-resize-pixelwise' is nil, some window managers may refuse to
2949 honor a WIDTH that is not an integer multiple of the default frame font
2950 width or a HEIGHT that is not an integer multiple of the default frame
2951 font height. */)
2952 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2954 struct frame *f = decode_live_frame (frame);
2955 int pixel_width, pixel_height;
2957 CHECK_TYPE_RANGED_INTEGER (int, width);
2958 CHECK_TYPE_RANGED_INTEGER (int, height);
2960 pixel_width = (!NILP (pixelwise)
2961 ? XINT (width)
2962 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2963 pixel_height = (!NILP (pixelwise)
2964 ? XINT (height)
2965 : XINT (height) * FRAME_LINE_HEIGHT (f));
2966 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
2968 return Qnil;
2971 DEFUN ("frame-position", Fframe_position,
2972 Sframe_position, 0, 1, 0,
2973 doc: /* Return top left corner of FRAME in pixels.
2974 FRAME must be a live frame and defaults to the selected one. The return
2975 value is a cons (x, y) of the coordinates of the top left corner of
2976 FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's
2977 display. */)
2978 (Lisp_Object frame)
2980 register struct frame *f = decode_live_frame (frame);
2982 return Fcons (make_number (f->left_pos), make_number (f->top_pos));
2985 DEFUN ("set-frame-position", Fset_frame_position,
2986 Sset_frame_position, 3, 3, 0,
2987 doc: /* Set position of FRAME to (X, Y).
2988 FRAME must be a live frame and defaults to the selected one. X and Y,
2989 if positive, specify the coordinate of the left and top edge of FRAME's
2990 outer frame in pixels relative to an origin (0, 0) of FRAME's display.
2991 If any of X or Y is negative, it specifies the coordinates of the right
2992 or bottom edge of the outer frame of FRAME relative to the right or
2993 bottom edge of FRAME's display. */)
2994 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2996 register struct frame *f = decode_live_frame (frame);
2998 CHECK_TYPE_RANGED_INTEGER (int, x);
2999 CHECK_TYPE_RANGED_INTEGER (int, y);
3001 /* I think this should be done with a hook. */
3002 #ifdef HAVE_WINDOW_SYSTEM
3003 if (FRAME_WINDOW_P (f))
3004 x_set_offset (f, XINT (x), XINT (y), 1);
3005 #endif
3007 return Qt;
3011 /***********************************************************************
3012 Frame Parameters
3013 ***********************************************************************/
3015 /* Connect the frame-parameter names for X frames
3016 to the ways of passing the parameter values to the window system.
3018 The name of a parameter, as a Lisp symbol,
3019 has an `x-frame-parameter' property which is an integer in Lisp
3020 that is an index in this table. */
3022 struct frame_parm_table {
3023 const char *name;
3024 int sym;
3027 static const struct frame_parm_table frame_parms[] =
3029 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3030 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3031 {"background-color", -1},
3032 {"border-color", SYMBOL_INDEX (Qborder_color)},
3033 {"border-width", SYMBOL_INDEX (Qborder_width)},
3034 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3035 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3036 {"font", -1},
3037 {"foreground-color", -1},
3038 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3039 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3040 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3041 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3042 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3043 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3044 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3045 {"name", SYMBOL_INDEX (Qname)},
3046 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3047 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3048 {"title", SYMBOL_INDEX (Qtitle)},
3049 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3050 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3051 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3052 {"visibility", SYMBOL_INDEX (Qvisibility)},
3053 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3054 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3055 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3056 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3057 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3058 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3059 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3060 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3061 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3062 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3063 {"alpha", SYMBOL_INDEX (Qalpha)},
3064 {"sticky", SYMBOL_INDEX (Qsticky)},
3065 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3068 #ifdef HAVE_WINDOW_SYSTEM
3070 /* Change the parameters of frame F as specified by ALIST.
3071 If a parameter is not specially recognized, do nothing special;
3072 otherwise call the `x_set_...' function for that parameter.
3073 Except for certain geometry properties, always call store_frame_param
3074 to store the new value in the parameter alist. */
3076 void
3077 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3079 Lisp_Object tail;
3081 /* If both of these parameters are present, it's more efficient to
3082 set them both at once. So we wait until we've looked at the
3083 entire list before we set them. */
3084 int width IF_LINT (= 0), height IF_LINT (= 0);
3085 bool width_change = false, height_change = false;
3087 /* Same here. */
3088 Lisp_Object left, top;
3090 /* Same with these. */
3091 Lisp_Object icon_left, icon_top;
3093 /* And with this. */
3094 Lisp_Object fullscreen;
3095 bool fullscreen_change = false;
3097 /* Record in these vectors all the parms specified. */
3098 Lisp_Object *parms;
3099 Lisp_Object *values;
3100 ptrdiff_t i, p;
3101 bool left_no_change = 0, top_no_change = 0;
3102 #ifdef HAVE_X_WINDOWS
3103 bool icon_left_no_change = 0, icon_top_no_change = 0;
3104 #endif
3106 i = 0;
3107 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3108 i++;
3110 USE_SAFE_ALLOCA;
3111 SAFE_ALLOCA_LISP (parms, 2 * i);
3112 values = parms + i;
3114 /* Extract parm names and values into those vectors. */
3116 i = 0;
3117 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3119 Lisp_Object elt;
3121 elt = XCAR (tail);
3122 parms[i] = Fcar (elt);
3123 values[i] = Fcdr (elt);
3124 i++;
3126 /* TAIL and ALIST are not used again below here. */
3127 alist = tail = Qnil;
3129 top = left = Qunbound;
3130 icon_left = icon_top = Qunbound;
3132 /* Process foreground_color and background_color before anything else.
3133 They are independent of other properties, but other properties (e.g.,
3134 cursor_color) are dependent upon them. */
3135 /* Process default font as well, since fringe widths depends on it. */
3136 for (p = 0; p < i; p++)
3138 Lisp_Object prop, val;
3140 prop = parms[p];
3141 val = values[p];
3142 if (EQ (prop, Qforeground_color)
3143 || EQ (prop, Qbackground_color)
3144 || EQ (prop, Qfont))
3146 register Lisp_Object param_index, old_value;
3148 old_value = get_frame_param (f, prop);
3149 if (NILP (Fequal (val, old_value)))
3151 store_frame_param (f, prop, val);
3153 param_index = Fget (prop, Qx_frame_parameter);
3154 if (NATNUMP (param_index)
3155 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3156 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3157 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3162 /* Now process them in reverse of specified order. */
3163 while (i-- != 0)
3165 Lisp_Object prop, val;
3167 prop = parms[i];
3168 val = values[i];
3170 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
3172 width_change = 1;
3173 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3175 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
3177 height_change = 1;
3178 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3180 else if (EQ (prop, Qtop))
3181 top = val;
3182 else if (EQ (prop, Qleft))
3183 left = val;
3184 else if (EQ (prop, Qicon_top))
3185 icon_top = val;
3186 else if (EQ (prop, Qicon_left))
3187 icon_left = val;
3188 else if (EQ (prop, Qfullscreen))
3190 fullscreen = val;
3191 fullscreen_change = true;
3193 else if (EQ (prop, Qforeground_color)
3194 || EQ (prop, Qbackground_color)
3195 || EQ (prop, Qfont))
3196 /* Processed above. */
3197 continue;
3198 else
3200 register Lisp_Object param_index, old_value;
3202 old_value = get_frame_param (f, prop);
3204 store_frame_param (f, prop, val);
3206 param_index = Fget (prop, Qx_frame_parameter);
3207 if (NATNUMP (param_index)
3208 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3209 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3210 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3214 /* Don't die if just one of these was set. */
3215 if (EQ (left, Qunbound))
3217 left_no_change = 1;
3218 if (f->left_pos < 0)
3219 left = list2 (Qplus, make_number (f->left_pos));
3220 else
3221 XSETINT (left, f->left_pos);
3223 if (EQ (top, Qunbound))
3225 top_no_change = 1;
3226 if (f->top_pos < 0)
3227 top = list2 (Qplus, make_number (f->top_pos));
3228 else
3229 XSETINT (top, f->top_pos);
3232 /* If one of the icon positions was not set, preserve or default it. */
3233 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3235 #ifdef HAVE_X_WINDOWS
3236 icon_left_no_change = 1;
3237 #endif
3238 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3239 if (NILP (icon_left))
3240 XSETINT (icon_left, 0);
3242 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3244 #ifdef HAVE_X_WINDOWS
3245 icon_top_no_change = 1;
3246 #endif
3247 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3248 if (NILP (icon_top))
3249 XSETINT (icon_top, 0);
3252 /* Don't set these parameters unless they've been explicitly
3253 specified. The window might be mapped or resized while we're in
3254 this function, and we don't want to override that unless the lisp
3255 code has asked for it.
3257 Don't set these parameters unless they actually differ from the
3258 window's current parameters; the window may not actually exist
3259 yet. */
3261 Lisp_Object frame;
3263 XSETFRAME (frame, f);
3265 if ((width_change && width != FRAME_TEXT_WIDTH (f))
3266 || (height_change && height != FRAME_TEXT_HEIGHT (f))
3267 || (f->can_x_set_window_size && (f->new_height || f->new_width)))
3269 /* If necessary provide default values for HEIGHT and WIDTH. Do
3270 that here since otherwise a size change implied by an
3271 intermittent font change may get lost as in Bug#17142. */
3272 if (!width_change)
3273 width = ((f->can_x_set_window_size && f->new_width)
3274 ? (f->new_pixelwise
3275 ? f->new_width
3276 : (f->new_width * FRAME_COLUMN_WIDTH (f)))
3277 : FRAME_TEXT_WIDTH (f));
3279 if (!height_change)
3280 height = ((f->can_x_set_window_size && f->new_height)
3281 ? (f->new_pixelwise
3282 ? f->new_height
3283 : (f->new_height * FRAME_LINE_HEIGHT (f)))
3284 : FRAME_TEXT_HEIGHT (f));
3286 Fset_frame_size (frame, make_number (width), make_number (height), Qt);
3289 if ((!NILP (left) || !NILP (top))
3290 && ! (left_no_change && top_no_change)
3291 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3292 && NUMBERP (top) && XINT (top) == f->top_pos))
3294 int leftpos = 0;
3295 int toppos = 0;
3297 /* Record the signs. */
3298 f->size_hint_flags &= ~ (XNegative | YNegative);
3299 if (EQ (left, Qminus))
3300 f->size_hint_flags |= XNegative;
3301 else if (TYPE_RANGED_INTEGERP (int, left))
3303 leftpos = XINT (left);
3304 if (leftpos < 0)
3305 f->size_hint_flags |= XNegative;
3307 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3308 && CONSP (XCDR (left))
3309 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3311 leftpos = - XINT (XCAR (XCDR (left)));
3312 f->size_hint_flags |= XNegative;
3314 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3315 && CONSP (XCDR (left))
3316 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3318 leftpos = XINT (XCAR (XCDR (left)));
3321 if (EQ (top, Qminus))
3322 f->size_hint_flags |= YNegative;
3323 else if (TYPE_RANGED_INTEGERP (int, top))
3325 toppos = XINT (top);
3326 if (toppos < 0)
3327 f->size_hint_flags |= YNegative;
3329 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3330 && CONSP (XCDR (top))
3331 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3333 toppos = - XINT (XCAR (XCDR (top)));
3334 f->size_hint_flags |= YNegative;
3336 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3337 && CONSP (XCDR (top))
3338 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3340 toppos = XINT (XCAR (XCDR (top)));
3344 /* Store the numeric value of the position. */
3345 f->top_pos = toppos;
3346 f->left_pos = leftpos;
3348 f->win_gravity = NorthWestGravity;
3350 /* Actually set that position, and convert to absolute. */
3351 x_set_offset (f, leftpos, toppos, -1);
3354 if (fullscreen_change)
3356 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
3358 frame_size_history_add
3359 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
3361 store_frame_param (f, Qfullscreen, fullscreen);
3362 if (!EQ (fullscreen, old_value))
3363 x_set_fullscreen (f, fullscreen, old_value);
3367 #ifdef HAVE_X_WINDOWS
3368 if ((!NILP (icon_left) || !NILP (icon_top))
3369 && ! (icon_left_no_change && icon_top_no_change))
3370 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3371 #endif /* HAVE_X_WINDOWS */
3374 SAFE_FREE ();
3378 /* Insert a description of internally-recorded parameters of frame X
3379 into the parameter alist *ALISTPTR that is to be given to the user.
3380 Only parameters that are specific to the X window system
3381 and whose values are not correctly recorded in the frame's
3382 param_alist need to be considered here. */
3384 void
3385 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3387 Lisp_Object tem;
3388 uprintmax_t w;
3389 char buf[INT_BUFSIZE_BOUND (w)];
3391 /* Represent negative positions (off the top or left screen edge)
3392 in a way that Fmodify_frame_parameters will understand correctly. */
3393 XSETINT (tem, f->left_pos);
3394 if (f->left_pos >= 0)
3395 store_in_alist (alistptr, Qleft, tem);
3396 else
3397 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3399 XSETINT (tem, f->top_pos);
3400 if (f->top_pos >= 0)
3401 store_in_alist (alistptr, Qtop, tem);
3402 else
3403 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3405 store_in_alist (alistptr, Qborder_width,
3406 make_number (f->border_width));
3407 store_in_alist (alistptr, Qinternal_border_width,
3408 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3409 store_in_alist (alistptr, Qright_divider_width,
3410 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3411 store_in_alist (alistptr, Qbottom_divider_width,
3412 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3413 store_in_alist (alistptr, Qleft_fringe,
3414 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3415 store_in_alist (alistptr, Qright_fringe,
3416 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3417 store_in_alist (alistptr, Qscroll_bar_width,
3418 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3419 ? make_number (0)
3420 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3421 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3422 /* nil means "use default width"
3423 for non-toolkit scroll bar.
3424 ruler-mode.el depends on this. */
3425 : Qnil));
3426 store_in_alist (alistptr, Qscroll_bar_height,
3427 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3428 ? make_number (0)
3429 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3430 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3431 /* nil means "use default height"
3432 for non-toolkit scroll bar. */
3433 : Qnil));
3434 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3435 MS-Windows it returns a value whose type is HANDLE, which is
3436 actually a pointer. Explicit casting avoids compiler
3437 warnings. */
3438 w = (uintptr_t) FRAME_X_WINDOW (f);
3439 store_in_alist (alistptr, Qwindow_id,
3440 make_formatted_string (buf, "%"pMu, w));
3441 #ifdef HAVE_X_WINDOWS
3442 #ifdef USE_X_TOOLKIT
3443 /* Tooltip frame may not have this widget. */
3444 if (FRAME_X_OUTPUT (f)->widget)
3445 #endif
3446 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3447 store_in_alist (alistptr, Qouter_window_id,
3448 make_formatted_string (buf, "%"pMu, w));
3449 #endif
3450 store_in_alist (alistptr, Qicon_name, f->icon_name);
3451 store_in_alist (alistptr, Qvisibility,
3452 (FRAME_VISIBLE_P (f) ? Qt
3453 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3454 store_in_alist (alistptr, Qdisplay,
3455 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3457 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3458 tem = Qnil;
3459 else
3460 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3461 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3462 store_in_alist (alistptr, Qparent_id, tem);
3463 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3467 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3468 the previous value of that parameter, NEW_VALUE is the new value. */
3470 void
3471 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3473 if (NILP (new_value))
3474 f->want_fullscreen = FULLSCREEN_NONE;
3475 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3476 f->want_fullscreen = FULLSCREEN_BOTH;
3477 else if (EQ (new_value, Qfullwidth))
3478 f->want_fullscreen = FULLSCREEN_WIDTH;
3479 else if (EQ (new_value, Qfullheight))
3480 f->want_fullscreen = FULLSCREEN_HEIGHT;
3481 else if (EQ (new_value, Qmaximized))
3482 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3484 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3485 FRAME_TERMINAL (f)->fullscreen_hook (f);
3489 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3490 the previous value of that parameter, NEW_VALUE is the new value. */
3492 void
3493 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3495 if (NILP (new_value))
3496 f->extra_line_spacing = 0;
3497 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3498 f->extra_line_spacing = XFASTINT (new_value);
3499 else if (FLOATP (new_value))
3501 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3503 if (new_spacing >= 0)
3504 f->extra_line_spacing = new_spacing;
3505 else
3506 signal_error ("Invalid line-spacing", new_value);
3508 else
3509 signal_error ("Invalid line-spacing", new_value);
3510 if (FRAME_VISIBLE_P (f))
3511 redraw_frame (f);
3515 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3516 the previous value of that parameter, NEW_VALUE is the new value. */
3518 void
3519 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3521 Lisp_Object bgcolor;
3523 if (NILP (new_value))
3524 f->gamma = 0;
3525 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3526 /* The value 0.4545 is the normal viewing gamma. */
3527 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3528 else
3529 signal_error ("Invalid screen-gamma", new_value);
3531 /* Apply the new gamma value to the frame background. */
3532 bgcolor = Fassq (Qbackground_color, f->param_alist);
3533 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3535 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3536 if (NATNUMP (parm_index)
3537 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3538 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3539 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3540 (f, bgcolor, Qnil);
3543 Fclear_face_cache (Qnil);
3547 void
3548 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3550 Lisp_Object font_object;
3551 int fontset = -1;
3552 #ifdef HAVE_X_WINDOWS
3553 Lisp_Object font_param = arg;
3554 #endif
3556 /* Set the frame parameter back to the old value because we may
3557 fail to use ARG as the new parameter value. */
3558 store_frame_param (f, Qfont, oldval);
3560 /* ARG is a fontset name, a font name, a cons of fontset name and a
3561 font object, or a font object. In the last case, this function
3562 never fail. */
3563 if (STRINGP (arg))
3565 fontset = fs_query_fontset (arg, 0);
3566 if (fontset < 0)
3568 font_object = font_open_by_name (f, arg);
3569 if (NILP (font_object))
3570 error ("Font `%s' is not defined", SSDATA (arg));
3571 arg = AREF (font_object, FONT_NAME_INDEX);
3573 else if (fontset > 0)
3575 font_object = font_open_by_name (f, fontset_ascii (fontset));
3576 if (NILP (font_object))
3577 error ("Font `%s' is not defined", SDATA (arg));
3578 arg = AREF (font_object, FONT_NAME_INDEX);
3580 else
3581 error ("The default fontset can't be used for a frame font");
3583 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3585 /* This is the case that the ASCII font of F's fontset XCAR
3586 (arg) is changed to the font XCDR (arg) by
3587 `set-fontset-font'. */
3588 fontset = fs_query_fontset (XCAR (arg), 0);
3589 if (fontset < 0)
3590 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3591 font_object = XCDR (arg);
3592 arg = AREF (font_object, FONT_NAME_INDEX);
3593 #ifdef HAVE_X_WINDOWS
3594 font_param = Ffont_get (font_object, QCname);
3595 #endif
3597 else if (FONT_OBJECT_P (arg))
3599 font_object = arg;
3600 #ifdef HAVE_X_WINDOWS
3601 font_param = Ffont_get (font_object, QCname);
3602 #endif
3603 /* This is to store the XLFD font name in the frame parameter for
3604 backward compatibility. We should store the font-object
3605 itself in the future. */
3606 arg = AREF (font_object, FONT_NAME_INDEX);
3607 fontset = FRAME_FONTSET (f);
3608 /* Check if we can use the current fontset. If not, set FONTSET
3609 to -1 to generate a new fontset from FONT-OBJECT. */
3610 if (fontset >= 0)
3612 Lisp_Object ascii_font = fontset_ascii (fontset);
3613 Lisp_Object spec = font_spec_from_name (ascii_font);
3615 /* SPEC might be nil because ASCII_FONT's name doesn't parse
3616 according to stupid XLFD rules, which, for example,
3617 disallow font names that include a dash followed by a
3618 number. So in those cases we simply request x_new_font
3619 below to generate a new fontset. */
3620 if (NILP (spec) || ! font_match_p (spec, font_object))
3621 fontset = -1;
3624 else
3625 signal_error ("Invalid font", arg);
3627 if (! NILP (Fequal (font_object, oldval)))
3628 return;
3630 x_new_font (f, font_object, fontset);
3631 store_frame_param (f, Qfont, arg);
3632 #ifdef HAVE_X_WINDOWS
3633 store_frame_param (f, Qfont_param, font_param);
3634 #endif
3635 /* Recalculate toolbar height. */
3636 f->n_tool_bar_rows = 0;
3637 f->tool_bar_redisplayed_once = false;
3639 /* Ensure we redraw it. */
3640 clear_current_matrices (f);
3642 /* Attempt to hunt down bug#16028. */
3643 SET_FRAME_GARBAGED (f);
3645 recompute_basic_faces (f);
3647 do_pending_window_change (0);
3649 /* We used to call face-set-after-frame-default here, but it leads to
3650 recursive calls (since that function can set the `default' face's
3651 font which in turns changes the frame's `font' parameter).
3652 Also I don't know what this call is meant to do, but it seems the
3653 wrong way to do it anyway (it does a lot more work than what seems
3654 reasonable in response to a change to `font'). */
3658 void
3659 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3661 if (! NILP (new_value)
3662 && !CONSP (new_value))
3664 char *p0, *p1;
3666 CHECK_STRING (new_value);
3667 p0 = p1 = SSDATA (new_value);
3668 new_value = Qnil;
3669 while (*p0)
3671 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3672 if (p0 < p1)
3673 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3674 new_value);
3675 if (*p1)
3677 int c;
3679 while ((c = *++p1) && c_isspace (c));
3681 p0 = p1;
3683 new_value = Fnreverse (new_value);
3686 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3687 return;
3689 if (FRAME_FONT (f))
3690 free_all_realized_faces (Qnil);
3692 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3693 if (NILP (new_value))
3695 if (NILP (old_value))
3696 error ("No font backend available");
3697 font_update_drivers (f, old_value);
3698 error ("None of specified font backends are available");
3700 store_frame_param (f, Qfont_backend, new_value);
3702 if (FRAME_FONT (f))
3704 Lisp_Object frame;
3706 XSETFRAME (frame, f);
3707 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3708 face_change = true;
3709 windows_or_buffers_changed = 18;
3713 void
3714 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3716 int unit = FRAME_COLUMN_WIDTH (f);
3717 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3718 int new_width;
3720 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3721 ? eabs (XINT (new_value)) : 8);
3723 if (new_width != old_width)
3725 FRAME_LEFT_FRINGE_WIDTH (f) = new_width;
3726 FRAME_FRINGE_COLS (f) /* Round up. */
3727 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3729 if (FRAME_X_WINDOW (f) != 0)
3730 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
3732 SET_FRAME_GARBAGED (f);
3737 void
3738 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3740 int unit = FRAME_COLUMN_WIDTH (f);
3741 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3742 int new_width;
3744 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3745 ? eabs (XINT (new_value)) : 8);
3747 if (new_width != old_width)
3749 FRAME_RIGHT_FRINGE_WIDTH (f) = new_width;
3750 FRAME_FRINGE_COLS (f) /* Round up. */
3751 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3753 if (FRAME_X_WINDOW (f) != 0)
3754 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
3756 SET_FRAME_GARBAGED (f);
3761 void
3762 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3764 CHECK_TYPE_RANGED_INTEGER (int, arg);
3766 if (XINT (arg) == f->border_width)
3767 return;
3769 if (FRAME_X_WINDOW (f) != 0)
3770 error ("Cannot change the border width of a frame");
3772 f->border_width = XINT (arg);
3775 void
3776 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3778 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3780 CHECK_TYPE_RANGED_INTEGER (int, arg);
3781 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3782 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3783 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3784 if (FRAME_RIGHT_DIVIDER_WIDTH (f) != old)
3786 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
3787 adjust_frame_glyphs (f);
3788 SET_FRAME_GARBAGED (f);
3793 void
3794 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3796 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3798 CHECK_TYPE_RANGED_INTEGER (int, arg);
3799 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3800 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3801 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3802 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) != old)
3804 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
3805 adjust_frame_glyphs (f);
3806 SET_FRAME_GARBAGED (f);
3810 void
3811 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3813 Lisp_Object frame;
3814 XSETFRAME (frame, f);
3816 if (NILP (value))
3817 Fmake_frame_invisible (frame, Qt);
3818 else if (EQ (value, Qicon))
3819 Ficonify_frame (frame);
3820 else
3821 Fmake_frame_visible (frame);
3824 void
3825 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3827 f->auto_raise = !EQ (Qnil, arg);
3830 void
3831 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3833 f->auto_lower = !EQ (Qnil, arg);
3836 void
3837 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3839 f->no_split = !NILP (arg);
3842 void
3843 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3845 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3846 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3847 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3848 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3850 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3851 = (NILP (arg)
3852 ? vertical_scroll_bar_none
3853 : EQ (Qleft, arg)
3854 ? vertical_scroll_bar_left
3855 : EQ (Qright, arg)
3856 ? vertical_scroll_bar_right
3857 : EQ (Qleft, Vdefault_frame_scroll_bars)
3858 ? vertical_scroll_bar_left
3859 : EQ (Qright, Vdefault_frame_scroll_bars)
3860 ? vertical_scroll_bar_right
3861 : vertical_scroll_bar_none);
3863 /* We set this parameter before creating the X window for the
3864 frame, so we can get the geometry right from the start.
3865 However, if the window hasn't been created yet, we shouldn't
3866 call x_set_window_size. */
3867 if (FRAME_X_WINDOW (f))
3868 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
3870 SET_FRAME_GARBAGED (f);
3874 void
3875 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3877 #if USE_HORIZONTAL_SCROLL_BARS
3878 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3879 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3881 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3883 /* We set this parameter before creating the X window for the
3884 frame, so we can get the geometry right from the start.
3885 However, if the window hasn't been created yet, we shouldn't
3886 call x_set_window_size. */
3887 if (FRAME_X_WINDOW (f))
3888 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
3890 SET_FRAME_GARBAGED (f);
3892 #endif
3895 void
3896 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3898 int unit = FRAME_COLUMN_WIDTH (f);
3900 if (NILP (arg))
3902 x_set_scroll_bar_default_width (f);
3904 if (FRAME_X_WINDOW (f))
3905 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3907 SET_FRAME_GARBAGED (f);
3909 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3910 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3912 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3913 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3914 if (FRAME_X_WINDOW (f))
3915 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3917 SET_FRAME_GARBAGED (f);
3920 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3921 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3924 void
3925 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3927 #if USE_HORIZONTAL_SCROLL_BARS
3928 int unit = FRAME_LINE_HEIGHT (f);
3930 if (NILP (arg))
3932 x_set_scroll_bar_default_height (f);
3934 if (FRAME_X_WINDOW (f))
3935 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3937 SET_FRAME_GARBAGED (f);
3939 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3940 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3942 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3943 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3944 if (FRAME_X_WINDOW (f))
3945 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3947 SET_FRAME_GARBAGED (f);
3950 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3951 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3952 #endif
3955 void
3956 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3958 double alpha = 1.0;
3959 double newval[2];
3960 int i;
3961 Lisp_Object item;
3963 for (i = 0; i < 2; i++)
3965 newval[i] = 1.0;
3966 if (CONSP (arg))
3968 item = CAR (arg);
3969 arg = CDR (arg);
3971 else
3972 item = arg;
3974 if (NILP (item))
3975 alpha = - 1.0;
3976 else if (FLOATP (item))
3978 alpha = XFLOAT_DATA (item);
3979 if (! (0 <= alpha && alpha <= 1.0))
3980 args_out_of_range (make_float (0.0), make_float (1.0));
3982 else if (INTEGERP (item))
3984 EMACS_INT ialpha = XINT (item);
3985 if (! (0 <= ialpha && alpha <= 100))
3986 args_out_of_range (make_number (0), make_number (100));
3987 alpha = ialpha / 100.0;
3989 else
3990 wrong_type_argument (Qnumberp, item);
3991 newval[i] = alpha;
3994 for (i = 0; i < 2; i++)
3995 f->alpha[i] = newval[i];
3997 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3998 block_input ();
3999 x_set_frame_alpha (f);
4000 unblock_input ();
4001 #endif
4003 return;
4006 #ifndef HAVE_NS
4008 /* Non-zero if mouse is grabbed on DPYINFO
4009 and we know the frame where it is. */
4011 bool x_mouse_grabbed (Display_Info *dpyinfo)
4013 return (dpyinfo->grabbed
4014 && dpyinfo->last_mouse_frame
4015 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4018 /* Re-highlight something with mouse-face properties
4019 on DPYINFO using saved frame and mouse position. */
4021 void
4022 x_redo_mouse_highlight (Display_Info *dpyinfo)
4024 if (dpyinfo->last_mouse_motion_frame
4025 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4026 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4027 dpyinfo->last_mouse_motion_x,
4028 dpyinfo->last_mouse_motion_y);
4031 #endif /* HAVE_NS */
4033 /* Subroutines of creating an X frame. */
4035 /* Make sure that Vx_resource_name is set to a reasonable value.
4036 Fix it up, or set it to `emacs' if it is too hopeless. */
4038 void
4039 validate_x_resource_name (void)
4041 ptrdiff_t len = 0;
4042 /* Number of valid characters in the resource name. */
4043 ptrdiff_t good_count = 0;
4044 /* Number of invalid characters in the resource name. */
4045 ptrdiff_t bad_count = 0;
4046 Lisp_Object new;
4047 ptrdiff_t i;
4049 if (!STRINGP (Vx_resource_class))
4050 Vx_resource_class = build_string (EMACS_CLASS);
4052 if (STRINGP (Vx_resource_name))
4054 unsigned char *p = SDATA (Vx_resource_name);
4056 len = SBYTES (Vx_resource_name);
4058 /* Only letters, digits, - and _ are valid in resource names.
4059 Count the valid characters and count the invalid ones. */
4060 for (i = 0; i < len; i++)
4062 int c = p[i];
4063 if (! ((c >= 'a' && c <= 'z')
4064 || (c >= 'A' && c <= 'Z')
4065 || (c >= '0' && c <= '9')
4066 || c == '-' || c == '_'))
4067 bad_count++;
4068 else
4069 good_count++;
4072 else
4073 /* Not a string => completely invalid. */
4074 bad_count = 5, good_count = 0;
4076 /* If name is valid already, return. */
4077 if (bad_count == 0)
4078 return;
4080 /* If name is entirely invalid, or nearly so, or is so implausibly
4081 large that alloca might not work, use `emacs'. */
4082 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4084 Vx_resource_name = build_string ("emacs");
4085 return;
4088 /* Name is partly valid. Copy it and replace the invalid characters
4089 with underscores. */
4091 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4093 for (i = 0; i < len; i++)
4095 int c = SREF (new, i);
4096 if (! ((c >= 'a' && c <= 'z')
4097 || (c >= 'A' && c <= 'Z')
4098 || (c >= '0' && c <= '9')
4099 || c == '-' || c == '_'))
4100 SSET (new, i, '_');
4104 /* Get specified attribute from resource database RDB.
4105 See Fx_get_resource below for other parameters. */
4107 static Lisp_Object
4108 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4110 CHECK_STRING (attribute);
4111 CHECK_STRING (class);
4113 if (!NILP (component))
4114 CHECK_STRING (component);
4115 if (!NILP (subclass))
4116 CHECK_STRING (subclass);
4117 if (NILP (component) != NILP (subclass))
4118 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4120 validate_x_resource_name ();
4122 /* Allocate space for the components, the dots which separate them,
4123 and the final '\0'. Make them big enough for the worst case. */
4124 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4125 + (STRINGP (component)
4126 ? SBYTES (component) : 0)
4127 + SBYTES (attribute)
4128 + 3);
4130 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4131 + SBYTES (class)
4132 + (STRINGP (subclass)
4133 ? SBYTES (subclass) : 0)
4134 + 3);
4135 USE_SAFE_ALLOCA;
4136 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4137 char *class_key = name_key + name_keysize;
4139 /* Start with emacs.FRAMENAME for the name (the specific one)
4140 and with `Emacs' for the class key (the general one). */
4141 char *nz = lispstpcpy (name_key, Vx_resource_name);
4142 char *cz = lispstpcpy (class_key, Vx_resource_class);
4144 *cz++ = '.';
4145 cz = lispstpcpy (cz, class);
4147 if (!NILP (component))
4149 *cz++ = '.';
4150 lispstpcpy (cz, subclass);
4152 *nz++ = '.';
4153 nz = lispstpcpy (nz, component);
4156 *nz++ = '.';
4157 lispstpcpy (nz, attribute);
4159 char *value = x_get_string_resource (rdb, name_key, class_key);
4160 SAFE_FREE();
4162 if (value && *value)
4163 return build_string (value);
4164 else
4165 return Qnil;
4169 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4170 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4171 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4172 class, where INSTANCE is the name under which Emacs was invoked, or
4173 the name specified by the `-name' or `-rn' command-line arguments.
4175 The optional arguments COMPONENT and SUBCLASS add to the key and the
4176 class, respectively. You must specify both of them or neither.
4177 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4178 and the class is `Emacs.CLASS.SUBCLASS'. */)
4179 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4180 Lisp_Object subclass)
4182 check_window_system (NULL);
4184 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4185 attribute, class, component, subclass);
4188 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4190 Lisp_Object
4191 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4192 Lisp_Object class, Lisp_Object component,
4193 Lisp_Object subclass)
4195 return xrdb_get_resource (dpyinfo->xrdb,
4196 attribute, class, component, subclass);
4199 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4200 /* Used when C code wants a resource value. */
4201 /* Called from oldXMenu/Create.c. */
4202 char *
4203 x_get_resource_string (const char *attribute, const char *class)
4205 char *result;
4206 struct frame *sf = SELECTED_FRAME ();
4207 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4208 USE_SAFE_ALLOCA;
4210 /* Allocate space for the components, the dots which separate them,
4211 and the final '\0'. */
4212 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4213 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4214 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4215 char *class_key = name_key + name_keysize;
4217 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4218 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4220 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4221 name_key, class_key);
4222 SAFE_FREE ();
4223 return result;
4225 #endif
4227 /* Return the value of parameter PARAM.
4229 First search ALIST, then Vdefault_frame_alist, then the X defaults
4230 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4232 Convert the resource to the type specified by desired_type.
4234 If no default is specified, return Qunbound. If you call
4235 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4236 and don't let it get stored in any Lisp-visible variables! */
4238 Lisp_Object
4239 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4240 const char *attribute, const char *class, enum resource_types type)
4242 Lisp_Object tem;
4244 tem = Fassq (param, alist);
4246 if (!NILP (tem))
4248 /* If we find this parm in ALIST, clear it out
4249 so that it won't be "left over" at the end. */
4250 Lisp_Object tail;
4251 XSETCAR (tem, Qnil);
4252 /* In case the parameter appears more than once in the alist,
4253 clear it out. */
4254 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4255 if (CONSP (XCAR (tail))
4256 && EQ (XCAR (XCAR (tail)), param))
4257 XSETCAR (XCAR (tail), Qnil);
4259 else
4260 tem = Fassq (param, Vdefault_frame_alist);
4262 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4263 look in the X resources. */
4264 if (EQ (tem, Qnil))
4266 if (attribute && dpyinfo)
4268 AUTO_STRING (at, attribute);
4269 AUTO_STRING (cl, class);
4270 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4272 if (NILP (tem))
4273 return Qunbound;
4275 switch (type)
4277 case RES_TYPE_NUMBER:
4278 return make_number (atoi (SSDATA (tem)));
4280 case RES_TYPE_BOOLEAN_NUMBER:
4281 if (!strcmp (SSDATA (tem), "on")
4282 || !strcmp (SSDATA (tem), "true"))
4283 return make_number (1);
4284 return make_number (atoi (SSDATA (tem)));
4285 break;
4287 case RES_TYPE_FLOAT:
4288 return make_float (atof (SSDATA (tem)));
4290 case RES_TYPE_BOOLEAN:
4291 tem = Fdowncase (tem);
4292 if (!strcmp (SSDATA (tem), "on")
4293 #ifdef HAVE_NS
4294 || !strcmp (SSDATA (tem), "yes")
4295 #endif
4296 || !strcmp (SSDATA (tem), "true"))
4297 return Qt;
4298 else
4299 return Qnil;
4301 case RES_TYPE_STRING:
4302 return tem;
4304 case RES_TYPE_SYMBOL:
4305 /* As a special case, we map the values `true' and `on'
4306 to Qt, and `false' and `off' to Qnil. */
4308 Lisp_Object lower;
4309 lower = Fdowncase (tem);
4310 if (!strcmp (SSDATA (lower), "on")
4311 #ifdef HAVE_NS
4312 || !strcmp (SSDATA (lower), "yes")
4313 #endif
4314 || !strcmp (SSDATA (lower), "true"))
4315 return Qt;
4316 else if (!strcmp (SSDATA (lower), "off")
4317 #ifdef HAVE_NS
4318 || !strcmp (SSDATA (lower), "no")
4319 #endif
4320 || !strcmp (SSDATA (lower), "false"))
4321 return Qnil;
4322 else
4323 return Fintern (tem, Qnil);
4326 default:
4327 emacs_abort ();
4330 else
4331 return Qunbound;
4333 return Fcdr (tem);
4336 static Lisp_Object
4337 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4338 const char *attribute, const char *class,
4339 enum resource_types type)
4341 return x_get_arg (FRAME_DISPLAY_INFO (f),
4342 alist, param, attribute, class, type);
4345 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4347 Lisp_Object
4348 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4349 Lisp_Object param,
4350 const char *attribute, const char *class,
4351 enum resource_types type)
4353 Lisp_Object value;
4355 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4356 attribute, class, type);
4357 if (! NILP (value) && ! EQ (value, Qunbound))
4358 store_frame_param (f, param, value);
4360 return value;
4364 /* Record in frame F the specified or default value according to ALIST
4365 of the parameter named PROP (a Lisp symbol).
4366 If no value is specified for PROP, look for an X default for XPROP
4367 on the frame named NAME.
4368 If that is not found either, use the value DEFLT. */
4370 Lisp_Object
4371 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4372 Lisp_Object deflt, const char *xprop, const char *xclass,
4373 enum resource_types type)
4375 Lisp_Object tem;
4377 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4378 if (EQ (tem, Qunbound))
4379 tem = deflt;
4380 AUTO_FRAME_ARG (arg, prop, tem);
4381 x_set_frame_parameters (f, arg);
4382 return tem;
4386 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4389 * XParseGeometry parses strings of the form
4390 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4391 * width, height, xoffset, and yoffset are unsigned integers.
4392 * Example: "=80x24+300-49"
4393 * The equal sign is optional.
4394 * It returns a bitmask that indicates which of the four values
4395 * were actually found in the string. For each value found,
4396 * the corresponding argument is updated; for each value
4397 * not found, the corresponding argument is left unchanged.
4400 static int
4401 XParseGeometry (char *string,
4402 int *x, int *y,
4403 unsigned int *width, unsigned int *height)
4405 int mask = NoValue;
4406 char *strind;
4407 unsigned long tempWidth, tempHeight;
4408 long int tempX, tempY;
4409 char *nextCharacter;
4411 if (string == NULL || *string == '\0')
4412 return mask;
4413 if (*string == '=')
4414 string++; /* ignore possible '=' at beg of geometry spec */
4416 strind = string;
4417 if (*strind != '+' && *strind != '-' && *strind != 'x')
4419 tempWidth = strtoul (strind, &nextCharacter, 10);
4420 if (strind == nextCharacter)
4421 return 0;
4422 strind = nextCharacter;
4423 mask |= WidthValue;
4426 if (*strind == 'x' || *strind == 'X')
4428 strind++;
4429 tempHeight = strtoul (strind, &nextCharacter, 10);
4430 if (strind == nextCharacter)
4431 return 0;
4432 strind = nextCharacter;
4433 mask |= HeightValue;
4436 if (*strind == '+' || *strind == '-')
4438 if (*strind == '-')
4439 mask |= XNegative;
4440 tempX = strtol (strind, &nextCharacter, 10);
4441 if (strind == nextCharacter)
4442 return 0;
4443 strind = nextCharacter;
4444 mask |= XValue;
4445 if (*strind == '+' || *strind == '-')
4447 if (*strind == '-')
4448 mask |= YNegative;
4449 tempY = strtol (strind, &nextCharacter, 10);
4450 if (strind == nextCharacter)
4451 return 0;
4452 strind = nextCharacter;
4453 mask |= YValue;
4457 /* If strind isn't at the end of the string then it's an invalid
4458 geometry specification. */
4460 if (*strind != '\0')
4461 return 0;
4463 if (mask & XValue)
4464 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4465 if (mask & YValue)
4466 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4467 if (mask & WidthValue)
4468 *width = min (tempWidth, UINT_MAX);
4469 if (mask & HeightValue)
4470 *height = min (tempHeight, UINT_MAX);
4471 return mask;
4474 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4477 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4478 make-docfile: the documentation string in ns-win.el was used for
4479 x-parse-geometry even in non-NS builds.
4481 With two definitions of x-parse-geometry in this file, various
4482 things still get confused (eg M-x apropos documentation), so that
4483 it is best if the two definitions just share the same doc-string.
4485 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4486 doc: /* Parse a display geometry string STRING.
4487 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4488 The properties returned may include `top', `left', `height', and `width'.
4489 For X, the value of `left' or `top' may be an integer,
4490 or a list (+ N) meaning N pixels relative to top/left corner,
4491 or a list (- N) meaning -N pixels relative to bottom/right corner.
4492 On Nextstep, this just calls `ns-parse-geometry'. */)
4493 (Lisp_Object string)
4495 int geometry, x, y;
4496 unsigned int width, height;
4497 Lisp_Object result;
4499 CHECK_STRING (string);
4501 #ifdef HAVE_NS
4502 if (strchr (SSDATA (string), ' ') != NULL)
4503 return call1 (Qns_parse_geometry, string);
4504 #endif
4505 geometry = XParseGeometry (SSDATA (string),
4506 &x, &y, &width, &height);
4507 result = Qnil;
4508 if (geometry & XValue)
4510 Lisp_Object element;
4512 if (x >= 0 && (geometry & XNegative))
4513 element = list3 (Qleft, Qminus, make_number (-x));
4514 else if (x < 0 && ! (geometry & XNegative))
4515 element = list3 (Qleft, Qplus, make_number (x));
4516 else
4517 element = Fcons (Qleft, make_number (x));
4518 result = Fcons (element, result);
4521 if (geometry & YValue)
4523 Lisp_Object element;
4525 if (y >= 0 && (geometry & YNegative))
4526 element = list3 (Qtop, Qminus, make_number (-y));
4527 else if (y < 0 && ! (geometry & YNegative))
4528 element = list3 (Qtop, Qplus, make_number (y));
4529 else
4530 element = Fcons (Qtop, make_number (y));
4531 result = Fcons (element, result);
4534 if (geometry & WidthValue)
4535 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4536 if (geometry & HeightValue)
4537 result = Fcons (Fcons (Qheight, make_number (height)), result);
4539 return result;
4543 /* Calculate the desired size and position of frame F.
4544 Return the flags saying which aspects were specified.
4546 Also set the win_gravity and size_hint_flags of F.
4548 Adjust height for toolbar if TOOLBAR_P is 1.
4550 This function does not make the coordinates positive. */
4552 #define DEFAULT_ROWS 35
4553 #define DEFAULT_COLS 80
4555 long
4556 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p)
4558 Lisp_Object height, width, user_size, top, left, user_position;
4559 long window_prompting = 0;
4560 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4562 /* Default values if we fall through.
4563 Actually, if that happens we should get
4564 window manager prompting. */
4565 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4566 SET_FRAME_COLS (f, DEFAULT_COLS);
4567 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4568 SET_FRAME_LINES (f, DEFAULT_ROWS);
4570 /* Window managers expect that if program-specified
4571 positions are not (0,0), they're intentional, not defaults. */
4572 f->top_pos = 0;
4573 f->left_pos = 0;
4575 /* Ensure that earlier new_width and new_height settings won't
4576 override what we specify below. */
4577 f->new_width = f->new_height = 0;
4579 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4580 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4581 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4583 if (!EQ (width, Qunbound))
4585 CHECK_NUMBER (width);
4586 if (! (0 <= XINT (width) && XINT (width) <= INT_MAX))
4587 xsignal1 (Qargs_out_of_range, width);
4589 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4592 if (!EQ (height, Qunbound))
4594 CHECK_NUMBER (height);
4595 if (! (0 <= XINT (height) && XINT (height) <= INT_MAX))
4596 xsignal1 (Qargs_out_of_range, height);
4598 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4601 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4602 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4603 window_prompting |= USSize;
4604 else
4605 window_prompting |= PSize;
4608 /* Add a tool bar height to the initial frame height so that the user
4609 gets a text display area of the size he specified with -g or via
4610 .Xdefaults. Later changes of the tool bar height don't change the
4611 frame size. This is done so that users can create tall Emacs
4612 frames without having to guess how tall the tool bar will get. */
4613 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4615 if (frame_default_tool_bar_height)
4616 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
4617 else
4619 int margin, relief;
4621 relief = (tool_bar_button_relief >= 0
4622 ? tool_bar_button_relief
4623 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4625 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4626 margin = XFASTINT (Vtool_bar_button_margin);
4627 else if (CONSP (Vtool_bar_button_margin)
4628 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4629 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4630 else
4631 margin = 0;
4633 FRAME_TOOL_BAR_HEIGHT (f)
4634 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4638 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4639 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4640 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4641 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4643 if (EQ (top, Qminus))
4645 f->top_pos = 0;
4646 window_prompting |= YNegative;
4648 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4649 && CONSP (XCDR (top))
4650 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4652 f->top_pos = - XINT (XCAR (XCDR (top)));
4653 window_prompting |= YNegative;
4655 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4656 && CONSP (XCDR (top))
4657 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4659 f->top_pos = XINT (XCAR (XCDR (top)));
4661 else if (EQ (top, Qunbound))
4662 f->top_pos = 0;
4663 else
4665 CHECK_TYPE_RANGED_INTEGER (int, top);
4666 f->top_pos = XINT (top);
4667 if (f->top_pos < 0)
4668 window_prompting |= YNegative;
4671 if (EQ (left, Qminus))
4673 f->left_pos = 0;
4674 window_prompting |= XNegative;
4676 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4677 && CONSP (XCDR (left))
4678 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4680 f->left_pos = - XINT (XCAR (XCDR (left)));
4681 window_prompting |= XNegative;
4683 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4684 && CONSP (XCDR (left))
4685 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4687 f->left_pos = XINT (XCAR (XCDR (left)));
4689 else if (EQ (left, Qunbound))
4690 f->left_pos = 0;
4691 else
4693 CHECK_TYPE_RANGED_INTEGER (int, left);
4694 f->left_pos = XINT (left);
4695 if (f->left_pos < 0)
4696 window_prompting |= XNegative;
4699 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4700 window_prompting |= USPosition;
4701 else
4702 window_prompting |= PPosition;
4705 if (window_prompting & XNegative)
4707 if (window_prompting & YNegative)
4708 f->win_gravity = SouthEastGravity;
4709 else
4710 f->win_gravity = NorthEastGravity;
4712 else
4714 if (window_prompting & YNegative)
4715 f->win_gravity = SouthWestGravity;
4716 else
4717 f->win_gravity = NorthWestGravity;
4720 f->size_hint_flags = window_prompting;
4722 return window_prompting;
4727 #endif /* HAVE_WINDOW_SYSTEM */
4729 void
4730 frame_make_pointer_invisible (struct frame *f)
4732 if (! NILP (Vmake_pointer_invisible))
4734 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4735 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4737 f->mouse_moved = 0;
4738 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4739 f->pointer_invisible = 1;
4744 void
4745 frame_make_pointer_visible (struct frame *f)
4747 /* We don't check Vmake_pointer_invisible here in case the
4748 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4749 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4750 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4752 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4753 f->pointer_invisible = 0;
4757 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4758 Sframe_pointer_visible_p, 0, 1, 0,
4759 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4760 Otherwise it returns nil. FRAME omitted or nil means the
4761 selected frame. This is useful when `make-pointer-invisible' is set. */)
4762 (Lisp_Object frame)
4764 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4769 /***********************************************************************
4770 Multimonitor data
4771 ***********************************************************************/
4773 #ifdef HAVE_WINDOW_SYSTEM
4775 # if (defined HAVE_NS \
4776 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4777 void
4778 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4780 int i;
4781 for (i = 0; i < n_monitors; ++i)
4782 xfree (monitors[i].name);
4783 xfree (monitors);
4785 # endif
4787 Lisp_Object
4788 make_monitor_attribute_list (struct MonitorInfo *monitors,
4789 int n_monitors,
4790 int primary_monitor,
4791 Lisp_Object monitor_frames,
4792 const char *source)
4794 Lisp_Object attributes_list = Qnil;
4795 Lisp_Object primary_monitor_attributes = Qnil;
4796 int i;
4798 for (i = 0; i < n_monitors; ++i)
4800 Lisp_Object geometry, workarea, attributes = Qnil;
4801 struct MonitorInfo *mi = &monitors[i];
4803 if (mi->geom.width == 0) continue;
4805 workarea = list4i (mi->work.x, mi->work.y,
4806 mi->work.width, mi->work.height);
4807 geometry = list4i (mi->geom.x, mi->geom.y,
4808 mi->geom.width, mi->geom.height);
4809 attributes = Fcons (Fcons (Qsource, build_string (source)),
4810 attributes);
4811 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4812 attributes);
4813 attributes = Fcons (Fcons (Qmm_size,
4814 list2i (mi->mm_width, mi->mm_height)),
4815 attributes);
4816 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4817 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4818 if (mi->name)
4819 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4820 strlen (mi->name))),
4821 attributes);
4823 if (i == primary_monitor)
4824 primary_monitor_attributes = attributes;
4825 else
4826 attributes_list = Fcons (attributes, attributes_list);
4829 if (!NILP (primary_monitor_attributes))
4830 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4831 return attributes_list;
4834 #endif /* HAVE_WINDOW_SYSTEM */
4837 /***********************************************************************
4838 Initialization
4839 ***********************************************************************/
4841 void
4842 syms_of_frame (void)
4844 DEFSYM (Qframep, "framep");
4845 DEFSYM (Qframe_live_p, "frame-live-p");
4846 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4847 DEFSYM (Qwindow_pixel_to_total, "window--pixel-to-total");
4848 DEFSYM (Qexplicit_name, "explicit-name");
4849 DEFSYM (Qheight, "height");
4850 DEFSYM (Qicon, "icon");
4851 DEFSYM (Qminibuffer, "minibuffer");
4852 DEFSYM (Qmodeline, "modeline");
4853 DEFSYM (Qonly, "only");
4854 DEFSYM (Qnone, "none");
4855 DEFSYM (Qwidth, "width");
4856 DEFSYM (Qgeometry, "geometry");
4857 DEFSYM (Qicon_left, "icon-left");
4858 DEFSYM (Qicon_top, "icon-top");
4859 DEFSYM (Qtooltip, "tooltip");
4860 DEFSYM (Quser_position, "user-position");
4861 DEFSYM (Quser_size, "user-size");
4862 DEFSYM (Qwindow_id, "window-id");
4863 #ifdef HAVE_X_WINDOWS
4864 DEFSYM (Qouter_window_id, "outer-window-id");
4865 #endif
4866 DEFSYM (Qparent_id, "parent-id");
4867 DEFSYM (Qx, "x");
4868 DEFSYM (Qw32, "w32");
4869 DEFSYM (Qpc, "pc");
4870 DEFSYM (Qns, "ns");
4871 DEFSYM (Qvisible, "visible");
4872 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4873 DEFSYM (Qbuffer_list, "buffer-list");
4874 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4875 DEFSYM (Qdisplay_type, "display-type");
4876 DEFSYM (Qbackground_mode, "background-mode");
4877 DEFSYM (Qnoelisp, "noelisp");
4878 DEFSYM (Qtty_color_mode, "tty-color-mode");
4879 DEFSYM (Qtty, "tty");
4880 DEFSYM (Qtty_type, "tty-type");
4882 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4884 DEFSYM (Qfullwidth, "fullwidth");
4885 DEFSYM (Qfullheight, "fullheight");
4886 DEFSYM (Qfullboth, "fullboth");
4887 DEFSYM (Qmaximized, "maximized");
4888 DEFSYM (Qx_resource_name, "x-resource-name");
4889 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4891 DEFSYM (Qterminal, "terminal");
4893 DEFSYM (Qworkarea, "workarea");
4894 DEFSYM (Qmm_size, "mm-size");
4895 DEFSYM (Qframes, "frames");
4896 DEFSYM (Qsource, "source");
4898 DEFSYM (Qouter_edges, "outer-edges");
4899 DEFSYM (Qouter_position, "outer-position");
4900 DEFSYM (Qouter_size, "outer-size");
4901 DEFSYM (Qnative_edges, "native-edges");
4902 DEFSYM (Qinner_edges, "inner-edges");
4903 DEFSYM (Qexternal_border_size, "external-border-size");
4904 DEFSYM (Qtitle_bar_size, "title-bar-size");
4905 DEFSYM (Qmenu_bar_external, "menu-bar-external");
4906 DEFSYM (Qmenu_bar_size, "menu-bar-size");
4907 DEFSYM (Qtool_bar_external, "tool-bar-external");
4908 DEFSYM (Qtool_bar_size, "tool-bar-size");
4909 /* The following are used for frame_size_history. */
4910 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
4911 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
4912 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
4913 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
4914 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
4915 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
4916 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
4917 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
4918 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
4919 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
4920 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
4921 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
4922 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
4923 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
4924 DEFSYM (Qtb_size_cb, "tb-size-cb");
4925 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
4926 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
4928 DEFSYM (Qchange_frame_size, "change-frame-size");
4929 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
4930 DEFSYM (Qset_window_configuration, "set-window-configuration");
4931 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
4932 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
4933 DEFSYM (Qterminal_frame, "terminal-frame");
4935 #ifdef HAVE_NS
4936 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4937 #endif
4939 DEFSYM (Qalpha, "alpha");
4940 DEFSYM (Qauto_lower, "auto-lower");
4941 DEFSYM (Qauto_raise, "auto-raise");
4942 DEFSYM (Qborder_color, "border-color");
4943 DEFSYM (Qborder_width, "border-width");
4944 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
4945 DEFSYM (Qcursor_color, "cursor-color");
4946 DEFSYM (Qcursor_type, "cursor-type");
4947 DEFSYM (Qfont_backend, "font-backend");
4948 DEFSYM (Qfullscreen, "fullscreen");
4949 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
4950 DEFSYM (Qicon_name, "icon-name");
4951 DEFSYM (Qicon_type, "icon-type");
4952 DEFSYM (Qinternal_border_width, "internal-border-width");
4953 DEFSYM (Qleft_fringe, "left-fringe");
4954 DEFSYM (Qline_spacing, "line-spacing");
4955 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
4956 DEFSYM (Qmouse_color, "mouse-color");
4957 DEFSYM (Qname, "name");
4958 DEFSYM (Qright_divider_width, "right-divider-width");
4959 DEFSYM (Qright_fringe, "right-fringe");
4960 DEFSYM (Qscreen_gamma, "screen-gamma");
4961 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
4962 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
4963 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
4964 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
4965 DEFSYM (Qsticky, "sticky");
4966 DEFSYM (Qtitle, "title");
4967 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
4968 DEFSYM (Qtool_bar_position, "tool-bar-position");
4969 DEFSYM (Qunsplittable, "unsplittable");
4970 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
4971 DEFSYM (Qvisibility, "visibility");
4972 DEFSYM (Qwait_for_wm, "wait-for-wm");
4975 int i;
4977 for (i = 0; i < ARRAYELTS (frame_parms); i++)
4979 Lisp_Object v = (frame_parms[i].sym < 0
4980 ? intern_c_string (frame_parms[i].name)
4981 : builtin_lisp_symbol (frame_parms[i].sym));
4982 Fput (v, Qx_frame_parameter, make_number (i));
4986 #ifdef HAVE_WINDOW_SYSTEM
4987 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4988 doc: /* The name Emacs uses to look up X resources.
4989 `x-get-resource' uses this as the first component of the instance name
4990 when requesting resource values.
4991 Emacs initially sets `x-resource-name' to the name under which Emacs
4992 was invoked, or to the value specified with the `-name' or `-rn'
4993 switches, if present.
4995 It may be useful to bind this variable locally around a call
4996 to `x-get-resource'. See also the variable `x-resource-class'. */);
4997 Vx_resource_name = Qnil;
4999 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5000 doc: /* The class Emacs uses to look up X resources.
5001 `x-get-resource' uses this as the first component of the instance class
5002 when requesting resource values.
5004 Emacs initially sets `x-resource-class' to "Emacs".
5006 Setting this variable permanently is not a reasonable thing to do,
5007 but binding this variable locally around a call to `x-get-resource'
5008 is a reasonable practice. See also the variable `x-resource-name'. */);
5009 Vx_resource_class = build_string (EMACS_CLASS);
5011 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5012 doc: /* The lower limit of the frame opacity (alpha transparency).
5013 The value should range from 0 (invisible) to 100 (completely opaque).
5014 You can also use a floating number between 0.0 and 1.0. */);
5015 Vframe_alpha_lower_limit = make_number (20);
5016 #endif
5018 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5019 doc: /* Alist of default values for frame creation.
5020 These may be set in your init file, like this:
5021 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5022 These override values given in window system configuration data,
5023 including X Windows' defaults database.
5024 For values specific to the first Emacs frame, see `initial-frame-alist'.
5025 For window-system specific values, see `window-system-default-frame-alist'.
5026 For values specific to the separate minibuffer frame, see
5027 `minibuffer-frame-alist'.
5028 The `menu-bar-lines' element of the list controls whether new frames
5029 have menu bars; `menu-bar-mode' works by altering this element.
5030 Setting this variable does not affect existing frames, only new ones. */);
5031 Vdefault_frame_alist = Qnil;
5033 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5034 doc: /* Default position of vertical scroll bars on this window-system. */);
5035 #ifdef HAVE_WINDOW_SYSTEM
5036 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5037 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
5038 default. */
5039 Vdefault_frame_scroll_bars = Qright;
5040 #else
5041 Vdefault_frame_scroll_bars = Qleft;
5042 #endif
5043 #else
5044 Vdefault_frame_scroll_bars = Qnil;
5045 #endif
5047 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5048 scroll_bar_adjust_thumb_portion_p,
5049 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5050 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5051 even if the end of the buffer is shown (i.e. overscrolling).
5052 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5053 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5054 is visible. In this case you can not overscroll. */);
5055 scroll_bar_adjust_thumb_portion_p = 1;
5057 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5058 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5060 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5061 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5062 `mouse-position' and `mouse-pixel-position' call this function, passing their
5063 usual return value as argument, and return whatever this function returns.
5064 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5065 which need to do mouse handling at the Lisp level. */);
5066 Vmouse_position_function = Qnil;
5068 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5069 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5070 If the value is an integer, highlighting is only shown after moving the
5071 mouse, while keyboard input turns off the highlight even when the mouse
5072 is over the clickable text. However, the mouse shape still indicates
5073 when the mouse is over clickable text. */);
5074 Vmouse_highlight = Qt;
5076 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5077 doc: /* If non-nil, make pointer invisible while typing.
5078 The pointer becomes visible again when the mouse is moved. */);
5079 Vmake_pointer_invisible = Qt;
5081 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5082 doc: /* Normal hook run when a frame gains input focus. */);
5083 Vfocus_in_hook = Qnil;
5085 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5086 doc: /* Normal hook run when a frame loses input focus. */);
5087 Vfocus_out_hook = Qnil;
5089 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5090 doc: /* Functions run before deleting a frame.
5091 The functions are run with one arg, the frame to be deleted.
5092 See `delete-frame'.
5094 Note that functions in this list may be called just before the frame is
5095 actually deleted, or some time later (or even both when an earlier function
5096 in `delete-frame-functions' (indirectly) calls `delete-frame'
5097 recursively). */);
5098 Vdelete_frame_functions = Qnil;
5099 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5101 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5102 doc: /* Non-nil if Menu-Bar mode is enabled.
5103 See the command `menu-bar-mode' for a description of this minor mode.
5104 Setting this variable directly does not take effect;
5105 either customize it (see the info node `Easy Customization')
5106 or call the function `menu-bar-mode'. */);
5107 Vmenu_bar_mode = Qt;
5109 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5110 doc: /* Non-nil if Tool-Bar mode is enabled.
5111 See the command `tool-bar-mode' for a description of this minor mode.
5112 Setting this variable directly does not take effect;
5113 either customize it (see the info node `Easy Customization')
5114 or call the function `tool-bar-mode'. */);
5115 #ifdef HAVE_WINDOW_SYSTEM
5116 Vtool_bar_mode = Qt;
5117 #else
5118 Vtool_bar_mode = Qnil;
5119 #endif
5121 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5122 doc: /* Minibufferless frames use this frame's minibuffer.
5123 Emacs cannot create minibufferless frames unless this is set to an
5124 appropriate surrogate.
5126 Emacs consults this variable only when creating minibufferless
5127 frames; once the frame is created, it sticks with its assigned
5128 minibuffer, no matter what this variable is set to. This means that
5129 this variable doesn't necessarily say anything meaningful about the
5130 current set of frames, or where the minibuffer is currently being
5131 displayed.
5133 This variable is local to the current terminal and cannot be buffer-local. */);
5135 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
5136 doc: /* Non-nil if window system changes focus when you move the mouse.
5137 You should set this variable to tell Emacs how your window manager
5138 handles focus, since there is no way in general for Emacs to find out
5139 automatically. See also `mouse-autoselect-window'. */);
5140 focus_follows_mouse = 0;
5142 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5143 doc: /* Non-nil means resize frames pixelwise.
5144 If this option is nil, resizing a frame rounds its sizes to the frame's
5145 current values of `frame-char-height' and `frame-char-width'. If this
5146 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5147 by one pixel.
5149 With some window managers you may have to set this to non-nil in order
5150 to set the size of a frame in pixels, to maximize frames or to make them
5151 fullscreen. To resize your initial frame pixelwise, set this option to
5152 a non-nil value in your init file. */);
5153 frame_resize_pixelwise = 0;
5155 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5156 doc: /* Whether frames should be resized implicitly.
5157 If this option is nil, setting font, menu bar, tool bar, internal
5158 borders, fringes or scroll bars of a specific frame may resize the frame
5159 in order to preserve the number of columns or lines it displays. If
5160 this option is t, no such resizing is done. Note that the size of
5161 fullscreen and maximized frames, the height of fullheight frames and the
5162 width of fullwidth frames never change implicitly.
5164 The value of this option can be also be a list of frame parameters. In
5165 this case, resizing is inhibited when changing a parameter that appears
5166 in that list. The parameters currently handled by this option include
5167 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5168 `tool-bar-lines'.
5170 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5171 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5172 `right-fringe' is handled as if the frame contained just one live
5173 window. This means, for example, that removing vertical scroll bars on
5174 a frame containing several side by side windows will shrink the frame
5175 width by the width of one scroll bar provided this option is nil and
5176 keep it unchanged if this option is either t or a list containing
5177 `vertical-scroll-bars'.
5179 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
5180 \(which means that adding/removing a tool bar does not change the frame
5181 height), nil on all other window systems including GTK+ (which means
5182 that changing any of the parameters listed above may change the size of
5183 the frame), and t otherwise (which means the frame size never changes
5184 implicitly when there's no window system support).
5186 Note that when a frame is not large enough to accommodate a change of
5187 any of the parameters listed above, Emacs may try to enlarge the frame
5188 even if this option is non-nil. */);
5189 #if defined (HAVE_WINDOW_SYSTEM)
5190 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
5191 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
5192 #else
5193 frame_inhibit_implied_resize = Qnil;
5194 #endif
5195 #else
5196 frame_inhibit_implied_resize = Qt;
5197 #endif
5199 DEFVAR_LISP ("frame-size-history", frame_size_history,
5200 doc: /* History of frame size adjustments.
5201 If non-nil, list recording frame size adjustment. Adjustments are
5202 recorded only if the first element of this list is a positive number.
5203 Adding an adjustment decrements that number by one.
5205 The remaining elements are the adjustments. Each adjustment is a list
5206 of four elements `frame', `function', `sizes' and `more'. `frame' is
5207 the affected frame and `function' the invoking function. `sizes' is
5208 usually a list of four elements `old-width', `old-height', `new-width'
5209 and `new-height' representing the old and new sizes recorded/requested
5210 by `function'. `more' is a list with additional information.
5212 The function `frame--size-history' displays the value of this variable
5213 in a more readable form. */);
5214 frame_size_history = Qnil;
5216 staticpro (&Vframe_list);
5218 defsubr (&Sframep);
5219 defsubr (&Sframe_live_p);
5220 defsubr (&Swindow_system);
5221 defsubr (&Sframe_windows_min_size);
5222 defsubr (&Smake_terminal_frame);
5223 defsubr (&Shandle_switch_frame);
5224 defsubr (&Sselect_frame);
5225 defsubr (&Sselected_frame);
5226 defsubr (&Sframe_list);
5227 defsubr (&Snext_frame);
5228 defsubr (&Sprevious_frame);
5229 defsubr (&Slast_nonminibuf_frame);
5230 defsubr (&Sdelete_frame);
5231 defsubr (&Smouse_position);
5232 defsubr (&Smouse_pixel_position);
5233 defsubr (&Sset_mouse_position);
5234 defsubr (&Sset_mouse_pixel_position);
5235 #if 0
5236 defsubr (&Sframe_configuration);
5237 defsubr (&Srestore_frame_configuration);
5238 #endif
5239 defsubr (&Smake_frame_visible);
5240 defsubr (&Smake_frame_invisible);
5241 defsubr (&Siconify_frame);
5242 defsubr (&Sframe_visible_p);
5243 defsubr (&Svisible_frame_list);
5244 defsubr (&Sraise_frame);
5245 defsubr (&Slower_frame);
5246 defsubr (&Sx_focus_frame);
5247 defsubr (&Sframe_after_make_frame);
5248 defsubr (&Sredirect_frame_focus);
5249 defsubr (&Sframe_focus);
5250 defsubr (&Sframe_parameters);
5251 defsubr (&Sframe_parameter);
5252 defsubr (&Smodify_frame_parameters);
5253 defsubr (&Sframe_char_height);
5254 defsubr (&Sframe_char_width);
5255 defsubr (&Sframe_pixel_height);
5256 defsubr (&Sframe_pixel_width);
5257 defsubr (&Sframe_text_cols);
5258 defsubr (&Sframe_text_lines);
5259 defsubr (&Sframe_total_cols);
5260 defsubr (&Sframe_total_lines);
5261 defsubr (&Sframe_text_width);
5262 defsubr (&Sframe_text_height);
5263 defsubr (&Sscroll_bar_width);
5264 defsubr (&Sscroll_bar_height);
5265 defsubr (&Sfringe_width);
5266 defsubr (&Sborder_width);
5267 defsubr (&Sright_divider_width);
5268 defsubr (&Sbottom_divider_width);
5269 defsubr (&Stool_bar_pixel_width);
5270 defsubr (&Sset_frame_height);
5271 defsubr (&Sset_frame_width);
5272 defsubr (&Sset_frame_size);
5273 defsubr (&Sframe_position);
5274 defsubr (&Sset_frame_position);
5275 defsubr (&Sframe_pointer_visible_p);
5277 #ifdef HAVE_WINDOW_SYSTEM
5278 defsubr (&Sx_get_resource);
5279 defsubr (&Sx_parse_geometry);
5280 #endif