Allow ff-find-other-file (etc) to work with indirect clone buffers
[emacs.git] / src / frame.c
blobdf473aebc213134fbe93b56955edb54cb59edcfe
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2016 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
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"
30 #ifdef HAVE_WINDOW_SYSTEM
31 #include TERM_HEADER
32 #endif /* HAVE_WINDOW_SYSTEM */
34 #include "buffer.h"
35 /* These help us bind and responding to switch-frame events. */
36 #include "keyboard.h"
37 #include "frame.h"
38 #include "blockinput.h"
39 #include "termchar.h"
40 #include "termhooks.h"
41 #include "dispextern.h"
42 #include "window.h"
43 #ifdef HAVE_WINDOW_SYSTEM
44 #include "fontset.h"
45 #endif
46 #include "cm.h"
47 #ifdef MSDOS
48 #include "msdos.h"
49 #include "dosfns.h"
50 #endif
51 #ifdef USE_X_TOOLKIT
52 #include "widget.h"
53 #endif
55 /* The currently selected frame. */
57 Lisp_Object selected_frame;
59 /* A frame which is not just a mini-buffer, or NULL if there are no such
60 frames. This is usually the most recent such frame that was selected. */
62 static struct frame *last_nonminibuf_frame;
64 /* False means there are no visible garbaged frames. */
65 bool frame_garbaged;
67 /* The default tool bar height for future frames. */
68 #if defined USE_GTK || defined HAVE_NS
69 enum { frame_default_tool_bar_height = 0 };
70 #else
71 int frame_default_tool_bar_height;
72 #endif
74 #ifdef HAVE_WINDOW_SYSTEM
75 static void x_report_frame_params (struct frame *, Lisp_Object *);
76 #endif
78 /* These setters are used only in this file, so they can be private. */
79 static void
80 fset_buffer_predicate (struct frame *f, Lisp_Object val)
82 f->buffer_predicate = val;
84 static void
85 fset_minibuffer_window (struct frame *f, Lisp_Object val)
87 f->minibuffer_window = val;
90 struct frame *
91 decode_live_frame (register Lisp_Object frame)
93 if (NILP (frame))
94 frame = selected_frame;
95 CHECK_LIVE_FRAME (frame);
96 return XFRAME (frame);
99 struct frame *
100 decode_any_frame (register Lisp_Object frame)
102 if (NILP (frame))
103 frame = selected_frame;
104 CHECK_FRAME (frame);
105 return XFRAME (frame);
108 #ifdef HAVE_WINDOW_SYSTEM
110 bool
111 window_system_available (struct frame *f)
113 return f ? FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f) : x_display_list != NULL;
116 #endif /* HAVE_WINDOW_SYSTEM */
118 struct frame *
119 decode_window_system_frame (Lisp_Object frame)
121 struct frame *f = decode_live_frame (frame);
123 if (!window_system_available (f))
124 error ("Window system frame should be used");
125 return f;
128 void
129 check_window_system (struct frame *f)
131 if (!window_system_available (f))
132 error (f ? "Window system frame should be used"
133 : "Window system is not in use or not initialized");
136 /* Return the value of frame parameter PROP in frame FRAME. */
138 Lisp_Object
139 get_frame_param (register struct frame *frame, Lisp_Object prop)
141 register Lisp_Object tem;
143 tem = Fassq (prop, frame->param_alist);
144 if (EQ (tem, Qnil))
145 return tem;
146 return Fcdr (tem);
150 void
151 frame_size_history_add (struct frame *f, Lisp_Object fun_symbol,
152 int width, int height, Lisp_Object rest)
154 Lisp_Object frame;
156 XSETFRAME (frame, f);
157 if (CONSP (frame_size_history)
158 && INTEGERP (XCAR (frame_size_history))
159 && 0 < XINT (XCAR (frame_size_history)))
160 frame_size_history =
161 Fcons (make_number (XINT (XCAR (frame_size_history)) - 1),
162 Fcons (list4
163 (frame, fun_symbol,
164 ((width > 0)
165 ? list4 (make_number (FRAME_TEXT_WIDTH (f)),
166 make_number (FRAME_TEXT_HEIGHT (f)),
167 make_number (width),
168 make_number (height))
169 : Qnil),
170 rest),
171 XCDR (frame_size_history)));
175 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
176 state of frame F would be affected by a vertical (horizontal if
177 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
178 parameter that is changed. */
179 bool
180 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
182 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
183 bool inhibit
184 = (f->after_make_frame
185 ? (EQ (frame_inhibit_implied_resize, Qt)
186 || (CONSP (frame_inhibit_implied_resize)
187 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))
188 || (horizontal
189 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight))
190 || (!horizontal
191 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth))
192 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
193 : ((horizontal && f->inhibit_horizontal_resize)
194 || (!horizontal && f->inhibit_vertical_resize)));
195 if (inhibit && !FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
196 frame_size_history_add
197 (f, Qframe_inhibit_resize, 0, 0,
198 list5 (horizontal ? Qt : Qnil, parameter,
199 f->after_make_frame ? Qt : Qnil,
200 frame_inhibit_implied_resize,
201 fullscreen));
203 return inhibit;
206 static void
207 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
209 int nlines;
210 int olines = FRAME_MENU_BAR_LINES (f);
212 /* Right now, menu bars don't work properly in minibuf-only frames;
213 most of the commands try to apply themselves to the minibuffer
214 frame itself, and get an error because you can't switch buffers
215 in or split the minibuffer window. */
216 if (FRAME_MINIBUF_ONLY_P (f))
217 return;
219 if (TYPE_RANGED_INTEGERP (int, value))
220 nlines = XINT (value);
221 else
222 nlines = 0;
224 if (nlines != olines)
226 windows_or_buffers_changed = 14;
227 FRAME_MENU_BAR_LINES (f) = nlines;
228 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
229 change_frame_size (f, FRAME_COLS (f),
230 FRAME_LINES (f) + olines - nlines,
231 0, 1, 0, 0);
235 Lisp_Object Vframe_list;
238 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
239 doc: /* Return non-nil if OBJECT is a frame.
240 Value is:
241 t for a termcap frame (a character-only terminal),
242 `x' for an Emacs frame that is really an X window,
243 `w32' for an Emacs frame that is a window on MS-Windows display,
244 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
245 `pc' for a direct-write MS-DOS frame.
246 See also `frame-live-p'. */)
247 (Lisp_Object object)
249 if (!FRAMEP (object))
250 return Qnil;
251 switch (XFRAME (object)->output_method)
253 case output_initial: /* The initial frame is like a termcap frame. */
254 case output_termcap:
255 return Qt;
256 case output_x_window:
257 return Qx;
258 case output_w32:
259 return Qw32;
260 case output_msdos_raw:
261 return Qpc;
262 case output_ns:
263 return Qns;
264 default:
265 emacs_abort ();
269 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
270 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
271 Value is nil if OBJECT is not a live frame. If object is a live
272 frame, the return value indicates what sort of terminal device it is
273 displayed on. See the documentation of `framep' for possible
274 return values. */)
275 (Lisp_Object object)
277 return ((FRAMEP (object)
278 && FRAME_LIVE_P (XFRAME (object)))
279 ? Fframep (object)
280 : Qnil);
283 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
284 doc: /* The name of the window system that FRAME is displaying through.
285 The value is a symbol:
286 nil for a termcap frame (a character-only terminal),
287 `x' for an Emacs frame that is really an X window,
288 `w32' for an Emacs frame that is a window on MS-Windows display,
289 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
290 `pc' for a direct-write MS-DOS frame.
292 FRAME defaults to the currently selected frame.
294 Use of this function as a predicate is deprecated. Instead,
295 use `display-graphic-p' or any of the other `display-*-p'
296 predicates which report frame's specific UI-related capabilities. */)
297 (Lisp_Object frame)
299 Lisp_Object type;
300 if (NILP (frame))
301 frame = selected_frame;
303 type = Fframep (frame);
305 if (NILP (type))
306 wrong_type_argument (Qframep, frame);
308 if (EQ (type, Qt))
309 return Qnil;
310 else
311 return type;
314 /* Placeholder used by temacs -nw before window.el is loaded. */
315 DEFUN ("frame-windows-min-size", Fframe_windows_min_size,
316 Sframe_windows_min_size, 4, 4, 0,
317 doc: /* */
318 attributes: const)
319 (Lisp_Object frame, Lisp_Object horizontal,
320 Lisp_Object ignore, Lisp_Object pixelwise)
322 return make_number (0);
325 static int
326 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal,
327 Lisp_Object ignore, Lisp_Object pixelwise)
329 return XINT (call4 (Qframe_windows_min_size, frame, horizontal,
330 ignore, pixelwise));
334 /* Make sure windows sizes of frame F are OK. new_width and new_height
335 are in pixels. A value of -1 means no change is requested for that
336 size (but the frame may still have to be resized to accommodate
337 windows with their minimum sizes). This can either issue a request
338 to resize the frame externally (via x_set_window_size), to resize the
339 frame internally (via resize_frame_windows) or do nothing at all.
341 The argument INHIBIT can assume the following values:
343 0 means to unconditionally call x_set_window_size even if sizes
344 apparently do not change. Fx_create_frame uses this to pass the
345 initial size to the window manager.
347 1 means to call x_set_window_size if the outer frame size really
348 changes. Fset_frame_size, Fset_frame_height, ... use this.
350 2 means to call x_set_window_size provided frame_inhibit_resize
351 allows it. The menu and tool bar code use this ("3" won't work
352 here in general because menu and tool bar are often not counted in
353 the frame's text height).
355 3 means call x_set_window_size if window minimum sizes must be
356 preserved or frame_inhibit_resize allows it. x_set_left_fringe,
357 x_set_scroll_bar_width, x_new_font ... use (or should use) this.
359 4 means call x_set_window_size only if window minimum sizes must be
360 preserved. x_set_right_divider_width, x_set_border_width and the
361 code responsible for wrapping the tool bar use this.
363 5 means to never call x_set_window_size. change_frame_size uses
364 this.
366 Note that even when x_set_window_size is not called, individual
367 windows may have to be resized (via `window--sanitize-window-sizes')
368 in order to support minimum size constraints.
370 PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the
371 symbol of the parameter changed (like `menu-bar-lines', `font', ...).
372 This is passed on to frame_inhibit_resize to let the latter decide on
373 a case-by-case basis whether the frame may be resized externally. */
374 void
375 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
376 bool pretend, Lisp_Object parameter)
378 int unit_width = FRAME_COLUMN_WIDTH (f);
379 int unit_height = FRAME_LINE_HEIGHT (f);
380 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
381 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
382 int old_cols = FRAME_COLS (f);
383 int old_lines = FRAME_LINES (f);
384 int new_pixel_width, new_pixel_height;
385 /* The following two values are calculated from the old frame pixel
386 sizes and any "new" settings for tool bar, menu bar and internal
387 borders. We do it this way to detect whether we have to call
388 x_set_window_size as consequence of the new settings. */
389 int windows_width = FRAME_WINDOWS_WIDTH (f);
390 int windows_height = FRAME_WINDOWS_HEIGHT (f);
391 int min_windows_width, min_windows_height;
392 /* These are a bit tedious, maybe we should use a macro. */
393 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
394 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
395 int old_windows_height
396 = (WINDOW_PIXEL_HEIGHT (r)
397 + ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
398 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
399 : 0));
400 int new_windows_width, new_windows_height;
401 int old_text_width = FRAME_TEXT_WIDTH (f);
402 int old_text_height = FRAME_TEXT_HEIGHT (f);
403 /* If a size is < 0 use the old value. */
404 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
405 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
406 int new_cols, new_lines;
407 bool inhibit_horizontal, inhibit_vertical;
408 Lisp_Object frame;
410 XSETFRAME (frame, f);
412 frame_size_history_add
413 (f, Qadjust_frame_size_1, new_text_width, new_text_height,
414 list2 (parameter, make_number (inhibit)));
416 /* The following two values are calculated from the old window body
417 sizes and any "new" settings for scroll bars, dividers, fringes and
418 margins (though the latter should have been processed already). */
419 min_windows_width
420 = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qt : Qnil, Qt);
421 min_windows_height
422 = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qt : Qnil, Qt);
424 if (inhibit >= 2 && inhibit <= 4)
425 /* When INHIBIT is in [2..4] inhibit if the "old" window sizes stay
426 within the limits and either resizing is inhibited or INHIBIT
427 equals 4. */
429 inhibit_horizontal = (windows_width >= min_windows_width
430 && (inhibit == 4
431 || frame_inhibit_resize (f, true, parameter)));
432 inhibit_vertical = (windows_height >= min_windows_height
433 && (inhibit == 4
434 || frame_inhibit_resize (f, false, parameter)));
436 else
437 /* Otherwise inhibit if INHIBIT equals 5. */
438 inhibit_horizontal = inhibit_vertical = inhibit == 5;
440 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
441 ? old_pixel_width
442 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
443 min_windows_width
444 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
445 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
446 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
447 new_cols = new_text_width / unit_width;
449 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
450 ? old_pixel_height
451 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
452 min_windows_height
453 + FRAME_TOP_MARGIN_HEIGHT (f)
454 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
455 new_windows_height = (new_pixel_height
456 - FRAME_TOP_MARGIN_HEIGHT (f)
457 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
458 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
459 new_lines = new_text_height / unit_height;
461 #ifdef HAVE_WINDOW_SYSTEM
462 if (FRAME_WINDOW_P (f)
463 && f->can_x_set_window_size
464 && ((!inhibit_horizontal
465 && (new_pixel_width != old_pixel_width
466 || inhibit == 0 || inhibit == 2))
467 || (!inhibit_vertical
468 && (new_pixel_height != old_pixel_height
469 || inhibit == 0 || inhibit == 2))))
470 /* We are either allowed to change the frame size or the minimum
471 sizes request such a change. Do not care for fixing minimum
472 sizes here, we do that eventually when we're called from
473 change_frame_size. */
475 /* Make sure we respect fullheight and fullwidth. */
476 if (inhibit_horizontal)
477 new_text_width = old_text_width;
478 else if (inhibit_vertical)
479 new_text_height = old_text_height;
481 frame_size_history_add
482 (f, Qadjust_frame_size_2, new_text_width, new_text_height,
483 list2 (inhibit_horizontal ? Qt : Qnil,
484 inhibit_vertical ? Qt : Qnil));
486 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
487 f->resized_p = true;
489 return;
491 #endif
493 if (new_text_width == old_text_width
494 && new_text_height == old_text_height
495 && new_windows_width == old_windows_width
496 && new_windows_height == old_windows_height
497 && new_pixel_width == old_pixel_width
498 && new_pixel_height == old_pixel_height
499 && new_cols == old_cols
500 && new_lines == old_lines)
501 /* No change. Sanitize window sizes and return. */
503 sanitize_window_sizes (frame, Qt);
504 sanitize_window_sizes (frame, Qnil);
506 return;
509 block_input ();
511 #ifdef MSDOS
512 /* We only can set screen dimensions to certain values supported
513 by our video hardware. Try to find the smallest size greater
514 or equal to the requested dimensions. */
515 dos_set_window_size (&new_lines, &new_cols);
516 #endif
518 if (new_windows_width != old_windows_width)
520 resize_frame_windows (f, new_windows_width, 1, 1);
522 /* MSDOS frames cannot PRETEND, as they change frame size by
523 manipulating video hardware. */
524 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
525 FrameCols (FRAME_TTY (f)) = new_cols;
527 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
528 if (WINDOWP (f->tool_bar_window))
530 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
531 XWINDOW (f->tool_bar_window)->total_cols
532 = new_windows_width / unit_width;
534 #endif
536 else if (new_cols != old_cols)
537 call2 (Qwindow_pixel_to_total, frame, Qt);
539 if (new_windows_height != old_windows_height
540 /* When the top margin has changed we have to recalculate the top
541 edges of all windows. No such calculation is necessary for the
542 left edges. */
543 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
545 resize_frame_windows (f, new_windows_height, 0, 1);
547 /* MSDOS frames cannot PRETEND, as they change frame size by
548 manipulating video hardware. */
549 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
550 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
552 else if (new_lines != old_lines)
553 call2 (Qwindow_pixel_to_total, frame, Qnil);
555 frame_size_history_add
556 (f, Qadjust_frame_size_3, new_text_width, new_text_height,
557 list4 (make_number (old_pixel_width), make_number (old_pixel_height),
558 make_number (new_pixel_width), make_number (new_pixel_height)));
560 /* Assign new sizes. */
561 FRAME_TEXT_WIDTH (f) = new_text_width;
562 FRAME_TEXT_HEIGHT (f) = new_text_height;
563 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
564 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
565 SET_FRAME_COLS (f, new_cols);
566 SET_FRAME_LINES (f, new_lines);
569 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
570 int text_area_x, text_area_y, text_area_width, text_area_height;
572 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
573 &text_area_height);
574 if (w->cursor.x >= text_area_x + text_area_width)
575 w->cursor.hpos = w->cursor.x = 0;
576 if (w->cursor.y >= text_area_y + text_area_height)
577 w->cursor.vpos = w->cursor.y = 0;
580 /* Sanitize window sizes. */
581 sanitize_window_sizes (frame, Qt);
582 sanitize_window_sizes (frame, Qnil);
584 adjust_frame_glyphs (f);
585 calculate_costs (f);
586 SET_FRAME_GARBAGED (f);
588 /* A frame was "resized" if one of its pixelsizes changed, even if its
589 X window wasn't resized at all. */
590 f->resized_p = (new_pixel_width != old_pixel_width
591 || new_pixel_height != old_pixel_height);
593 unblock_input ();
596 /* Allocate basically initialized frame. */
598 static struct frame *
599 allocate_frame (void)
601 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
604 struct frame *
605 make_frame (bool mini_p)
607 Lisp_Object frame;
608 struct frame *f;
609 struct window *rw, *mw IF_LINT (= NULL);
610 Lisp_Object root_window;
611 Lisp_Object mini_window;
613 f = allocate_frame ();
614 XSETFRAME (frame, f);
616 #ifdef USE_GTK
617 /* Initialize Lisp data. Note that allocate_frame initializes all
618 Lisp data to nil, so do it only for slots which should not be nil. */
619 fset_tool_bar_position (f, Qtop);
620 #endif
622 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
623 non-Lisp data, so do it only for slots which should not be zero.
624 To avoid subtle bugs and for the sake of readability, it's better to
625 initialize enum members explicitly even if their values are zero. */
626 f->wants_modeline = true;
627 f->redisplay = true;
628 f->garbaged = true;
629 f->can_x_set_window_size = false;
630 f->after_make_frame = false;
631 f->inhibit_horizontal_resize = false;
632 f->inhibit_vertical_resize = false;
633 f->tool_bar_redisplayed = false;
634 f->tool_bar_resized = false;
635 f->column_width = 1; /* !FRAME_WINDOW_P value. */
636 f->line_height = 1; /* !FRAME_WINDOW_P value. */
637 #ifdef HAVE_WINDOW_SYSTEM
638 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
639 f->horizontal_scroll_bars = false;
640 f->want_fullscreen = FULLSCREEN_NONE;
641 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
642 f->last_tool_bar_item = -1;
643 #endif
644 #endif
646 root_window = make_window ();
647 rw = XWINDOW (root_window);
648 if (mini_p)
650 mini_window = make_window ();
651 mw = XWINDOW (mini_window);
652 wset_next (rw, mini_window);
653 wset_prev (mw, root_window);
654 mw->mini = 1;
655 wset_frame (mw, frame);
656 fset_minibuffer_window (f, mini_window);
658 else
660 mini_window = Qnil;
661 wset_next (rw, Qnil);
662 fset_minibuffer_window (f, Qnil);
665 wset_frame (rw, frame);
667 /* 10 is arbitrary,
668 just so that there is "something there."
669 Correct size will be set up later with adjust_frame_size. */
671 SET_FRAME_COLS (f, 10);
672 SET_FRAME_LINES (f, 10);
673 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
674 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
676 rw->total_cols = 10;
677 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
678 rw->total_lines = mini_p ? 9 : 10;
679 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
681 if (mini_p)
683 mw->top_line = rw->total_lines;
684 mw->pixel_top = rw->pixel_height;
685 mw->total_cols = rw->total_cols;
686 mw->pixel_width = rw->pixel_width;
687 mw->total_lines = 1;
688 mw->pixel_height = FRAME_LINE_HEIGHT (f);
691 /* Choose a buffer for the frame's root window. */
693 Lisp_Object buf = Fcurrent_buffer ();
695 /* If current buffer is hidden, try to find another one. */
696 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
697 buf = other_buffer_safely (buf);
699 /* Use set_window_buffer, not Fset_window_buffer, and don't let
700 hooks be run by it. The reason is that the whole frame/window
701 arrangement is not yet fully initialized at this point. Windows
702 don't have the right size, glyph matrices aren't initialized
703 etc. Running Lisp functions at this point surely ends in a
704 SEGV. */
705 set_window_buffer (root_window, buf, 0, 0);
706 fset_buffer_list (f, list1 (buf));
709 if (mini_p)
711 set_window_buffer (mini_window,
712 (NILP (Vminibuffer_list)
713 ? get_minibuffer (0)
714 : Fcar (Vminibuffer_list)),
715 0, 0);
716 /* No horizontal scroll bars in minibuffers. */
717 wset_horizontal_scroll_bar (mw, Qnil);
720 fset_root_window (f, root_window);
721 fset_selected_window (f, root_window);
722 /* Make sure this window seems more recently used than
723 a newly-created, never-selected window. */
724 XWINDOW (f->selected_window)->use_time = ++window_select_count;
726 return f;
729 #ifdef HAVE_WINDOW_SYSTEM
730 /* Make a frame using a separate minibuffer window on another frame.
731 MINI_WINDOW is the minibuffer window to use. nil means use the
732 default (the global minibuffer). */
734 struct frame *
735 make_frame_without_minibuffer (Lisp_Object mini_window, KBOARD *kb,
736 Lisp_Object display)
738 struct frame *f;
740 if (!NILP (mini_window))
741 CHECK_LIVE_WINDOW (mini_window);
743 if (!NILP (mini_window)
744 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
745 error ("Frame and minibuffer must be on the same terminal");
747 /* Make a frame containing just a root window. */
748 f = make_frame (0);
750 if (NILP (mini_window))
752 /* Use default-minibuffer-frame if possible. */
753 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
754 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
756 Lisp_Object frame_dummy;
758 XSETFRAME (frame_dummy, f);
759 /* If there's no minibuffer frame to use, create one. */
760 kset_default_minibuffer_frame
761 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
764 mini_window
765 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
768 fset_minibuffer_window (f, mini_window);
770 /* Make the chosen minibuffer window display the proper minibuffer,
771 unless it is already showing a minibuffer. */
772 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
773 /* Use set_window_buffer instead of Fset_window_buffer (see
774 discussion of bug#11984, bug#12025, bug#12026). */
775 set_window_buffer (mini_window,
776 (NILP (Vminibuffer_list)
777 ? get_minibuffer (0)
778 : Fcar (Vminibuffer_list)), 0, 0);
779 return f;
782 /* Make a frame containing only a minibuffer window. */
784 struct frame *
785 make_minibuffer_frame (void)
787 /* First make a frame containing just a root window, no minibuffer. */
789 register struct frame *f = make_frame (0);
790 register Lisp_Object mini_window;
791 register Lisp_Object frame;
793 XSETFRAME (frame, f);
795 f->auto_raise = 0;
796 f->auto_lower = 0;
797 f->no_split = 1;
798 f->wants_modeline = 0;
800 /* Now label the root window as also being the minibuffer.
801 Avoid infinite looping on the window chain by marking next pointer
802 as nil. */
804 mini_window = f->root_window;
805 fset_minibuffer_window (f, mini_window);
806 XWINDOW (mini_window)->mini = 1;
807 wset_next (XWINDOW (mini_window), Qnil);
808 wset_prev (XWINDOW (mini_window), Qnil);
809 wset_frame (XWINDOW (mini_window), frame);
811 /* Put the proper buffer in that window. */
813 /* Use set_window_buffer instead of Fset_window_buffer (see
814 discussion of bug#11984, bug#12025, bug#12026). */
815 set_window_buffer (mini_window,
816 (NILP (Vminibuffer_list)
817 ? get_minibuffer (0)
818 : Fcar (Vminibuffer_list)), 0, 0);
819 return f;
821 #endif /* HAVE_WINDOW_SYSTEM */
823 /* Construct a frame that refers to a terminal. */
825 static printmax_t tty_frame_count;
827 struct frame *
828 make_initial_frame (void)
830 struct frame *f;
831 struct terminal *terminal;
832 Lisp_Object frame;
834 eassert (initial_kboard);
836 /* The first call must initialize Vframe_list. */
837 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
838 Vframe_list = Qnil;
840 terminal = init_initial_terminal ();
842 f = make_frame (1);
843 XSETFRAME (frame, f);
845 Vframe_list = Fcons (frame, Vframe_list);
847 tty_frame_count = 1;
848 fset_name (f, build_pure_c_string ("F1"));
850 SET_FRAME_VISIBLE (f, 1);
852 f->output_method = terminal->type;
853 f->terminal = terminal;
854 f->terminal->reference_count++;
855 f->output_data.nothing = 0;
857 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
858 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
860 #ifdef HAVE_WINDOW_SYSTEM
861 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
862 f->horizontal_scroll_bars = false;
863 #endif
865 /* The default value of menu-bar-mode is t. */
866 set_menu_bar_lines (f, make_number (1), Qnil);
868 if (!noninteractive)
869 init_frame_faces (f);
871 last_nonminibuf_frame = f;
873 f->can_x_set_window_size = true;
874 f->after_make_frame = true;
876 return f;
880 static struct frame *
881 make_terminal_frame (struct terminal *terminal)
883 register struct frame *f;
884 Lisp_Object frame;
885 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
887 if (!terminal->name)
888 error ("Terminal is not live, can't create new frames on it");
890 f = make_frame (1);
892 XSETFRAME (frame, f);
893 Vframe_list = Fcons (frame, Vframe_list);
895 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
897 SET_FRAME_VISIBLE (f, 1);
899 f->terminal = terminal;
900 f->terminal->reference_count++;
901 #ifdef MSDOS
902 f->output_data.tty->display_info = &the_only_display_info;
903 if (!inhibit_window_system
904 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
905 || XFRAME (selected_frame)->output_method == output_msdos_raw))
906 f->output_method = output_msdos_raw;
907 else
908 f->output_method = output_termcap;
909 #else /* not MSDOS */
910 f->output_method = output_termcap;
911 create_tty_output (f);
912 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
913 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
914 #endif /* not MSDOS */
916 #ifdef HAVE_WINDOW_SYSTEM
917 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
918 f->horizontal_scroll_bars = false;
919 #endif
921 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
922 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
923 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
924 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
926 /* Set the top frame to the newly created frame. */
927 if (FRAMEP (FRAME_TTY (f)->top_frame)
928 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
929 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
931 FRAME_TTY (f)->top_frame = frame;
933 if (!noninteractive)
934 init_frame_faces (f);
936 return f;
939 /* Get a suitable value for frame parameter PARAMETER for a newly
940 created frame, based on (1) the user-supplied frame parameter
941 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
943 static Lisp_Object
944 get_future_frame_param (Lisp_Object parameter,
945 Lisp_Object supplied_parms,
946 char *current_value)
948 Lisp_Object result;
950 result = Fassq (parameter, supplied_parms);
951 if (NILP (result))
952 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
953 if (NILP (result) && current_value != NULL)
954 result = build_string (current_value);
955 if (!NILP (result) && !STRINGP (result))
956 result = XCDR (result);
957 if (NILP (result) || !STRINGP (result))
958 result = Qnil;
960 return result;
963 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
964 1, 1, 0,
965 doc: /* Create an additional terminal frame, possibly on another terminal.
966 This function takes one argument, an alist specifying frame parameters.
968 You can create multiple frames on a single text terminal, but only one
969 of them (the selected terminal frame) is actually displayed.
971 In practice, generally you don't need to specify any parameters,
972 except when you want to create a new frame on another terminal.
973 In that case, the `tty' parameter specifies the device file to open,
974 and the `tty-type' parameter specifies the terminal type. Example:
976 (make-terminal-frame \\='((tty . "/dev/pts/5") (tty-type . "xterm")))
978 Note that changing the size of one terminal frame automatically
979 affects all frames on the same terminal device. */)
980 (Lisp_Object parms)
982 struct frame *f;
983 struct terminal *t = NULL;
984 Lisp_Object frame, tem;
985 struct frame *sf = SELECTED_FRAME ();
987 #ifdef MSDOS
988 if (sf->output_method != output_msdos_raw
989 && sf->output_method != output_termcap)
990 emacs_abort ();
991 #else /* not MSDOS */
993 #ifdef WINDOWSNT /* This should work now! */
994 if (sf->output_method != output_termcap)
995 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
996 #endif
997 #endif /* not MSDOS */
1000 Lisp_Object terminal;
1002 terminal = Fassq (Qterminal, parms);
1003 if (CONSP (terminal))
1005 terminal = XCDR (terminal);
1006 t = decode_live_terminal (terminal);
1008 #ifdef MSDOS
1009 if (t && t != the_only_display_info.terminal)
1010 /* msdos.c assumes a single tty_display_info object. */
1011 error ("Multiple terminals are not supported on this platform");
1012 if (!t)
1013 t = the_only_display_info.terminal;
1014 #endif
1017 if (!t)
1019 char *name = 0, *type = 0;
1020 Lisp_Object tty, tty_type;
1021 USE_SAFE_ALLOCA;
1023 tty = get_future_frame_param
1024 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1025 ? FRAME_TTY (XFRAME (selected_frame))->name
1026 : NULL));
1027 if (!NILP (tty))
1028 SAFE_ALLOCA_STRING (name, tty);
1030 tty_type = get_future_frame_param
1031 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1032 ? FRAME_TTY (XFRAME (selected_frame))->type
1033 : NULL));
1034 if (!NILP (tty_type))
1035 SAFE_ALLOCA_STRING (type, tty_type);
1037 t = init_tty (name, type, 0); /* Errors are not fatal. */
1038 SAFE_FREE ();
1041 f = make_terminal_frame (t);
1044 int width, height;
1045 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1046 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f),
1047 5, 0, Qterminal_frame);
1050 adjust_frame_glyphs (f);
1051 calculate_costs (f);
1052 XSETFRAME (frame, f);
1054 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1055 store_in_alist (&parms, Qtty,
1056 (t->display_info.tty->name
1057 ? build_string (t->display_info.tty->name)
1058 : Qnil));
1059 Fmodify_frame_parameters (frame, parms);
1061 /* Make the frame face alist be frame-specific, so that each
1062 frame could change its face definitions independently. */
1063 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1064 /* Simple Fcopy_alist isn't enough, because we need the contents of
1065 the vectors which are the CDRs of associations in face_alist to
1066 be copied as well. */
1067 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1068 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1070 f->can_x_set_window_size = true;
1071 f->after_make_frame = true;
1073 return frame;
1077 /* Perform the switch to frame FRAME.
1079 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1080 FRAME1 as frame.
1082 If TRACK is non-zero and the frame that currently has the focus
1083 redirects its focus to the selected frame, redirect that focused
1084 frame's focus to FRAME instead.
1086 FOR_DELETION non-zero means that the selected frame is being
1087 deleted, which includes the possibility that the frame's terminal
1088 is dead.
1090 The value of NORECORD is passed as argument to Fselect_window. */
1092 Lisp_Object
1093 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1095 struct frame *sf = SELECTED_FRAME ();
1097 /* If FRAME is a switch-frame event, extract the frame we should
1098 switch to. */
1099 if (CONSP (frame)
1100 && EQ (XCAR (frame), Qswitch_frame)
1101 && CONSP (XCDR (frame)))
1102 frame = XCAR (XCDR (frame));
1104 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1105 a switch-frame event to arrive after a frame is no longer live,
1106 especially when deleting the initial frame during startup. */
1107 CHECK_FRAME (frame);
1108 if (! FRAME_LIVE_P (XFRAME (frame)))
1109 return Qnil;
1111 if (sf == XFRAME (frame))
1112 return frame;
1114 /* If a frame's focus has been redirected toward the currently
1115 selected frame, we should change the redirection to point to the
1116 newly selected frame. This means that if the focus is redirected
1117 from a minibufferless frame to a surrogate minibuffer frame, we
1118 can use `other-window' to switch between all the frames using
1119 that minibuffer frame, and the focus redirection will follow us
1120 around. */
1121 #if 0
1122 /* This is too greedy; it causes inappropriate focus redirection
1123 that's hard to get rid of. */
1124 if (track)
1126 Lisp_Object tail;
1128 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1130 Lisp_Object focus;
1132 if (!FRAMEP (XCAR (tail)))
1133 emacs_abort ();
1135 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1137 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1138 Fredirect_frame_focus (XCAR (tail), frame);
1141 #else /* ! 0 */
1142 /* Instead, apply it only to the frame we're pointing to. */
1143 #ifdef HAVE_WINDOW_SYSTEM
1144 if (track && FRAME_WINDOW_P (XFRAME (frame)))
1146 Lisp_Object focus, xfocus;
1148 xfocus = x_get_focus_frame (XFRAME (frame));
1149 if (FRAMEP (xfocus))
1151 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1152 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1153 Fredirect_frame_focus (xfocus, frame);
1156 #endif /* HAVE_X_WINDOWS */
1157 #endif /* ! 0 */
1159 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1160 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1162 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
1164 struct frame *f = XFRAME (frame);
1165 struct tty_display_info *tty = FRAME_TTY (f);
1166 Lisp_Object top_frame = tty->top_frame;
1168 /* Don't mark the frame garbaged and/or obscured if we are
1169 switching to the frame that is already the top frame of that
1170 TTY. */
1171 if (!EQ (frame, top_frame))
1173 if (FRAMEP (top_frame))
1174 /* Mark previously displayed frame as now obscured. */
1175 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1176 SET_FRAME_VISIBLE (f, 1);
1177 /* If the new TTY frame changed dimensions, we need to
1178 resync term.c's idea of the frame size with the new
1179 frame's data. */
1180 if (FRAME_COLS (f) != FrameCols (tty))
1181 FrameCols (tty) = FRAME_COLS (f);
1182 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1183 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1185 tty->top_frame = frame;
1188 selected_frame = frame;
1189 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1190 last_nonminibuf_frame = XFRAME (selected_frame);
1192 Fselect_window (XFRAME (frame)->selected_window, norecord);
1194 /* We want to make sure that the next event generates a frame-switch
1195 event to the appropriate frame. This seems kludgy to me, but
1196 before you take it out, make sure that evaluating something like
1197 (select-window (frame-root-window (new-frame))) doesn't end up
1198 with your typing being interpreted in the new frame instead of
1199 the one you're actually typing in. */
1200 internal_last_event_frame = Qnil;
1202 return frame;
1205 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1206 doc: /* Select FRAME.
1207 Subsequent editing commands apply to its selected window.
1208 Optional argument NORECORD means to neither change the order of
1209 recently selected windows nor the buffer list.
1211 The selection of FRAME lasts until the next time the user does
1212 something to select a different frame, or until the next time
1213 this function is called. If you are using a window system, the
1214 previously selected frame may be restored as the selected frame
1215 when returning to the command loop, because it still may have
1216 the window system's input focus. On a text terminal, the next
1217 redisplay will display FRAME.
1219 This function returns FRAME, or nil if FRAME has been deleted. */)
1220 (Lisp_Object frame, Lisp_Object norecord)
1222 return do_switch_frame (frame, 1, 0, norecord);
1225 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1226 doc: /* Handle a switch-frame event EVENT.
1227 Switch-frame events are usually bound to this function.
1228 A switch-frame event tells Emacs that the window manager has requested
1229 that the user's events be directed to the frame mentioned in the event.
1230 This function selects the selected window of the frame of EVENT.
1232 If EVENT is frame object, handle it as if it were a switch-frame event
1233 to that frame. */)
1234 (Lisp_Object event)
1236 /* Preserve prefix arg that the command loop just cleared. */
1237 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1238 run_hook (Qmouse_leave_buffer_hook);
1239 /* `switch-frame' implies a focus in. */
1240 call1 (intern ("handle-focus-in"), event);
1241 return do_switch_frame (event, 0, 0, Qnil);
1244 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1245 doc: /* Return the frame that is now selected. */)
1246 (void)
1248 return selected_frame;
1251 DEFUN ("frame-list", Fframe_list, Sframe_list,
1252 0, 0, 0,
1253 doc: /* Return a list of all live frames. */)
1254 (void)
1256 Lisp_Object frames;
1257 frames = Fcopy_sequence (Vframe_list);
1258 #ifdef HAVE_WINDOW_SYSTEM
1259 if (FRAMEP (tip_frame))
1260 frames = Fdelq (tip_frame, frames);
1261 #endif
1262 return frames;
1265 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1266 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1267 If MINIBUF is nil, do not consider minibuffer-only candidate.
1268 If MINIBUF is `visible', do not consider an invisible candidate.
1269 If MINIBUF is a window, consider only its own frame and candidate now
1270 using that window as the minibuffer.
1271 If MINIBUF is 0, consider candidate if it is visible or iconified.
1272 Otherwise consider any candidate and return nil if CANDIDATE is not
1273 acceptable. */
1275 static Lisp_Object
1276 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1278 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1280 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1281 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1282 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1283 && FRAME_TTY (c) == FRAME_TTY (f)))
1285 if (NILP (minibuf))
1287 if (!FRAME_MINIBUF_ONLY_P (c))
1288 return candidate;
1290 else if (EQ (minibuf, Qvisible))
1292 if (FRAME_VISIBLE_P (c))
1293 return candidate;
1295 else if (WINDOWP (minibuf))
1297 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1298 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1299 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1300 FRAME_FOCUS_FRAME (c)))
1301 return candidate;
1303 else if (XFASTINT (minibuf) == 0)
1305 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1306 return candidate;
1308 else
1309 return candidate;
1311 return Qnil;
1314 /* Return the next frame in the frame list after FRAME. */
1316 static Lisp_Object
1317 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1319 Lisp_Object f, tail;
1320 int passed = 0;
1322 /* There must always be at least one frame in Vframe_list. */
1323 eassert (CONSP (Vframe_list));
1325 while (passed < 2)
1326 FOR_EACH_FRAME (tail, f)
1328 if (passed)
1330 f = candidate_frame (f, frame, minibuf);
1331 if (!NILP (f))
1332 return f;
1334 if (EQ (frame, f))
1335 passed++;
1337 return frame;
1340 /* Return the previous frame in the frame list before FRAME. */
1342 static Lisp_Object
1343 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1345 Lisp_Object f, tail, prev = Qnil;
1347 /* There must always be at least one frame in Vframe_list. */
1348 eassert (CONSP (Vframe_list));
1350 FOR_EACH_FRAME (tail, f)
1352 if (EQ (frame, f) && !NILP (prev))
1353 return prev;
1354 f = candidate_frame (f, frame, minibuf);
1355 if (!NILP (f))
1356 prev = f;
1359 /* We've scanned the entire list. */
1360 if (NILP (prev))
1361 /* We went through the whole frame list without finding a single
1362 acceptable frame. Return the original frame. */
1363 return frame;
1364 else
1365 /* There were no acceptable frames in the list before FRAME; otherwise,
1366 we would have returned directly from the loop. Since PREV is the last
1367 acceptable frame in the list, return it. */
1368 return prev;
1372 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1373 doc: /* Return the next frame in the frame list after FRAME.
1374 It considers only frames on the same terminal as FRAME.
1375 By default, skip minibuffer-only frames.
1376 If omitted, FRAME defaults to the selected frame.
1377 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1378 If MINIFRAME is a window, include only its own frame
1379 and any frame now using that window as the minibuffer.
1380 If MINIFRAME is `visible', include all visible frames.
1381 If MINIFRAME is 0, include all visible and iconified frames.
1382 Otherwise, include all frames. */)
1383 (Lisp_Object frame, Lisp_Object miniframe)
1385 if (NILP (frame))
1386 frame = selected_frame;
1387 CHECK_LIVE_FRAME (frame);
1388 return next_frame (frame, miniframe);
1391 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1392 doc: /* Return the previous frame in the frame list before FRAME.
1393 It considers only frames on the same terminal as FRAME.
1394 By default, skip minibuffer-only frames.
1395 If omitted, FRAME defaults to the selected frame.
1396 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1397 If MINIFRAME is a window, include only its own frame
1398 and any frame now using that window as the minibuffer.
1399 If MINIFRAME is `visible', include all visible frames.
1400 If MINIFRAME is 0, include all visible and iconified frames.
1401 Otherwise, include all frames. */)
1402 (Lisp_Object frame, Lisp_Object miniframe)
1404 if (NILP (frame))
1405 frame = selected_frame;
1406 CHECK_LIVE_FRAME (frame);
1407 return prev_frame (frame, miniframe);
1410 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1411 Slast_nonminibuf_frame, 0, 0, 0,
1412 doc: /* Return last non-minibuffer frame selected. */)
1413 (void)
1415 Lisp_Object frame = Qnil;
1417 if (last_nonminibuf_frame)
1418 XSETFRAME (frame, last_nonminibuf_frame);
1420 return frame;
1423 /* Return 1 if it is ok to delete frame F;
1424 0 if all frames aside from F are invisible.
1425 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1427 static int
1428 other_visible_frames (struct frame *f)
1430 Lisp_Object frames, this;
1432 FOR_EACH_FRAME (frames, this)
1434 if (f == XFRAME (this))
1435 continue;
1437 /* Verify that we can still talk to the frame's X window,
1438 and note any recent change in visibility. */
1439 #ifdef HAVE_X_WINDOWS
1440 if (FRAME_WINDOW_P (XFRAME (this)))
1441 x_sync (XFRAME (this));
1442 #endif
1444 if (FRAME_VISIBLE_P (XFRAME (this))
1445 || FRAME_ICONIFIED_P (XFRAME (this))
1446 /* Allow deleting the terminal frame when at least one X
1447 frame exists. */
1448 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1449 return 1;
1451 return 0;
1454 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1455 window. Preferably use the selected frame's minibuffer window
1456 instead. If the selected frame doesn't have one, get some other
1457 frame's minibuffer window. SELECT non-zero means select the new
1458 minibuffer window. */
1459 static void
1460 check_minibuf_window (Lisp_Object frame, int select)
1462 struct frame *f = decode_live_frame (frame);
1464 XSETFRAME (frame, f);
1466 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1468 Lisp_Object frames, this, window = make_number (0);
1470 if (!EQ (frame, selected_frame)
1471 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1472 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1473 else
1474 FOR_EACH_FRAME (frames, this)
1476 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1478 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1479 break;
1483 /* Don't abort if no window was found (Bug#15247). */
1484 if (WINDOWP (window))
1486 /* Use set_window_buffer instead of Fset_window_buffer (see
1487 discussion of bug#11984, bug#12025, bug#12026). */
1488 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1489 minibuf_window = window;
1491 /* SELECT non-zero usually means that FRAME's minibuffer
1492 window was selected; select the new one. */
1493 if (select)
1494 Fselect_window (minibuf_window, Qnil);
1500 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1501 unconditionally. x_connection_closed and delete_terminal use
1502 this. Any other value of FORCE implements the semantics
1503 described for Fdelete_frame. */
1504 Lisp_Object
1505 delete_frame (Lisp_Object frame, Lisp_Object force)
1507 struct frame *f = decode_any_frame (frame);
1508 struct frame *sf;
1509 struct kboard *kb;
1511 int minibuffer_selected, is_tooltip_frame;
1513 if (! FRAME_LIVE_P (f))
1514 return Qnil;
1516 if (NILP (force) && !other_visible_frames (f))
1517 error ("Attempt to delete the sole visible or iconified frame");
1519 /* x_connection_closed must have set FORCE to `noelisp' in order
1520 to delete the last frame, if it is gone. */
1521 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1522 error ("Attempt to delete the only frame");
1524 XSETFRAME (frame, f);
1526 /* Does this frame have a minibuffer, and is it the surrogate
1527 minibuffer for any other frame? */
1528 if (FRAME_HAS_MINIBUF_P (f))
1530 Lisp_Object frames, this;
1532 FOR_EACH_FRAME (frames, this)
1534 Lisp_Object fminiw;
1536 if (EQ (this, frame))
1537 continue;
1539 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1541 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1543 /* If we MUST delete this frame, delete the other first.
1544 But do this only if FORCE equals `noelisp'. */
1545 if (EQ (force, Qnoelisp))
1546 delete_frame (this, Qnoelisp);
1547 else
1548 error ("Attempt to delete a surrogate minibuffer frame");
1553 is_tooltip_frame = !NILP (Fframe_parameter (frame, Qtooltip));
1555 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1556 frame is a tooltip. FORCE is set to `noelisp' when handling
1557 a disconnect from the terminal, so we don't dare call Lisp
1558 code. */
1559 if (NILP (Vrun_hooks) || is_tooltip_frame)
1561 else if (EQ (force, Qnoelisp))
1562 pending_funcalls
1563 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1564 pending_funcalls);
1565 else
1567 #ifdef HAVE_X_WINDOWS
1568 /* Also, save clipboard to the clipboard manager. */
1569 x_clipboard_manager_save_frame (frame);
1570 #endif
1572 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1575 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1576 if (! FRAME_LIVE_P (f))
1577 return Qnil;
1579 /* At this point, we are committed to deleting the frame.
1580 There is no more chance for errors to prevent it. */
1582 minibuffer_selected = EQ (minibuf_window, selected_window);
1583 sf = SELECTED_FRAME ();
1584 /* Don't let the frame remain selected. */
1585 if (f == sf)
1587 Lisp_Object tail;
1588 Lisp_Object frame1 = Qnil;
1590 /* Look for another visible frame on the same terminal.
1591 Do not call next_frame here because it may loop forever.
1592 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1593 FOR_EACH_FRAME (tail, frame1)
1594 if (!EQ (frame, frame1)
1595 && (FRAME_TERMINAL (XFRAME (frame))
1596 == FRAME_TERMINAL (XFRAME (frame1)))
1597 && FRAME_VISIBLE_P (XFRAME (frame1)))
1598 break;
1600 /* If there is none, find *some* other frame. */
1601 if (NILP (frame1) || EQ (frame1, frame))
1603 FOR_EACH_FRAME (tail, frame1)
1605 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1607 /* Do not change a text terminal's top-frame. */
1608 struct frame *f1 = XFRAME (frame1);
1609 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1611 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1612 if (!EQ (top_frame, frame))
1613 frame1 = top_frame;
1615 break;
1619 #ifdef NS_IMPL_COCOA
1620 else
1621 /* Under NS, there is no system mechanism for choosing a new
1622 window to get focus -- it is left to application code.
1623 So the portion of THIS application interfacing with NS
1624 needs to know about it. We call Fraise_frame, but the
1625 purpose is really to transfer focus. */
1626 Fraise_frame (frame1);
1627 #endif
1629 do_switch_frame (frame1, 0, 1, Qnil);
1630 sf = SELECTED_FRAME ();
1633 /* Don't allow minibuf_window to remain on a deleted frame. */
1634 check_minibuf_window (frame, minibuffer_selected);
1636 /* Don't let echo_area_window to remain on a deleted frame. */
1637 if (EQ (f->minibuffer_window, echo_area_window))
1638 echo_area_window = sf->minibuffer_window;
1640 /* Clear any X selections for this frame. */
1641 #ifdef HAVE_X_WINDOWS
1642 if (FRAME_X_P (f))
1643 x_clear_frame_selections (f);
1644 #endif
1646 /* Free glyphs.
1647 This function must be called before the window tree of the
1648 frame is deleted because windows contain dynamically allocated
1649 memory. */
1650 free_glyphs (f);
1652 #ifdef HAVE_WINDOW_SYSTEM
1653 /* Give chance to each font driver to free a frame specific data. */
1654 font_update_drivers (f, Qnil);
1655 #endif
1657 /* Mark all the windows that used to be on FRAME as deleted, and then
1658 remove the reference to them. */
1659 delete_all_child_windows (f->root_window);
1660 fset_root_window (f, Qnil);
1662 Vframe_list = Fdelq (frame, Vframe_list);
1663 SET_FRAME_VISIBLE (f, 0);
1665 /* Allow the vector of menu bar contents to be freed in the next
1666 garbage collection. The frame object itself may not be garbage
1667 collected until much later, because recent_keys and other data
1668 structures can still refer to it. */
1669 fset_menu_bar_vector (f, Qnil);
1671 /* If FRAME's buffer lists contains killed
1672 buffers, this helps GC to reclaim them. */
1673 fset_buffer_list (f, Qnil);
1674 fset_buried_buffer_list (f, Qnil);
1676 free_font_driver_list (f);
1677 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1678 xfree (f->namebuf);
1679 #endif
1680 xfree (f->decode_mode_spec_buffer);
1681 xfree (FRAME_INSERT_COST (f));
1682 xfree (FRAME_DELETEN_COST (f));
1683 xfree (FRAME_INSERTN_COST (f));
1684 xfree (FRAME_DELETE_COST (f));
1686 /* Since some events are handled at the interrupt level, we may get
1687 an event for f at any time; if we zero out the frame's terminal
1688 now, then we may trip up the event-handling code. Instead, we'll
1689 promise that the terminal of the frame must be valid until we
1690 have called the window-system-dependent frame destruction
1691 routine. */
1695 struct terminal *terminal;
1696 block_input ();
1697 if (FRAME_TERMINAL (f)->delete_frame_hook)
1698 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1699 terminal = FRAME_TERMINAL (f);
1700 f->output_data.nothing = 0;
1701 f->terminal = 0; /* Now the frame is dead. */
1702 unblock_input ();
1704 /* If needed, delete the terminal that this frame was on.
1705 (This must be done after the frame is killed.) */
1706 terminal->reference_count--;
1707 #ifdef USE_GTK
1708 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1709 bug.
1710 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1711 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1712 terminal->reference_count = 1;
1713 #endif /* USE_GTK */
1714 if (terminal->reference_count == 0)
1716 Lisp_Object tmp;
1717 XSETTERMINAL (tmp, terminal);
1719 kb = NULL;
1720 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1722 else
1723 kb = terminal->kboard;
1726 /* If we've deleted the last_nonminibuf_frame, then try to find
1727 another one. */
1728 if (f == last_nonminibuf_frame)
1730 Lisp_Object frames, this;
1732 last_nonminibuf_frame = 0;
1734 FOR_EACH_FRAME (frames, this)
1736 f = XFRAME (this);
1737 if (!FRAME_MINIBUF_ONLY_P (f))
1739 last_nonminibuf_frame = f;
1740 break;
1745 /* If there's no other frame on the same kboard, get out of
1746 single-kboard state if we're in it for this kboard. */
1747 if (kb != NULL)
1749 Lisp_Object frames, this;
1750 /* Some frame we found on the same kboard, or nil if there are none. */
1751 Lisp_Object frame_on_same_kboard = Qnil;
1753 FOR_EACH_FRAME (frames, this)
1754 if (kb == FRAME_KBOARD (XFRAME (this)))
1755 frame_on_same_kboard = this;
1757 if (NILP (frame_on_same_kboard))
1758 not_single_kboard_state (kb);
1762 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1763 find another one. Prefer minibuffer-only frames, but also notice
1764 frames with other windows. */
1765 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1767 Lisp_Object frames, this;
1769 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1770 Lisp_Object frame_with_minibuf = Qnil;
1771 /* Some frame we found on the same kboard, or nil if there are none. */
1772 Lisp_Object frame_on_same_kboard = Qnil;
1774 FOR_EACH_FRAME (frames, this)
1776 struct frame *f1 = XFRAME (this);
1778 /* Consider only frames on the same kboard
1779 and only those with minibuffers. */
1780 if (kb == FRAME_KBOARD (f1)
1781 && FRAME_HAS_MINIBUF_P (f1))
1783 frame_with_minibuf = this;
1784 if (FRAME_MINIBUF_ONLY_P (f1))
1785 break;
1788 if (kb == FRAME_KBOARD (f1))
1789 frame_on_same_kboard = this;
1792 if (!NILP (frame_on_same_kboard))
1794 /* We know that there must be some frame with a minibuffer out
1795 there. If this were not true, all of the frames present
1796 would have to be minibufferless, which implies that at some
1797 point their minibuffer frames must have been deleted, but
1798 that is prohibited at the top; you can't delete surrogate
1799 minibuffer frames. */
1800 if (NILP (frame_with_minibuf))
1801 emacs_abort ();
1803 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1805 else
1806 /* No frames left on this kboard--say no minibuffer either. */
1807 kset_default_minibuffer_frame (kb, Qnil);
1810 /* Cause frame titles to update--necessary if we now have just one frame. */
1811 if (!is_tooltip_frame)
1812 update_mode_lines = 15;
1814 return Qnil;
1817 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1818 doc: /* Delete FRAME, permanently eliminating it from use.
1819 FRAME defaults to the selected frame.
1821 A frame may not be deleted if its minibuffer serves as surrogate
1822 minibuffer for another frame. Normally, you may not delete a frame if
1823 all other frames are invisible, but if the second optional argument
1824 FORCE is non-nil, you may do so.
1826 This function runs `delete-frame-functions' before actually
1827 deleting the frame, unless the frame is a tooltip.
1828 The functions are run with one argument, the frame to be deleted. */)
1829 (Lisp_Object frame, Lisp_Object force)
1831 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1835 /* Return mouse position in character cell units. */
1837 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1838 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1839 The position is given in canonical character cells, where (0, 0) is the
1840 upper-left corner of the frame, X is the horizontal offset, and Y is the
1841 vertical offset, measured in units of the frame's default character size.
1842 If Emacs is running on a mouseless terminal or hasn't been programmed
1843 to read the mouse position, it returns the selected frame for FRAME
1844 and nil for X and Y.
1845 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1846 passing the normal return value to that function as an argument,
1847 and returns whatever that function returns. */)
1848 (void)
1850 struct frame *f;
1851 Lisp_Object lispy_dummy;
1852 Lisp_Object x, y, retval;
1854 f = SELECTED_FRAME ();
1855 x = y = Qnil;
1857 /* It's okay for the hook to refrain from storing anything. */
1858 if (FRAME_TERMINAL (f)->mouse_position_hook)
1860 enum scroll_bar_part party_dummy;
1861 Time time_dummy;
1862 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1863 &lispy_dummy, &party_dummy,
1864 &x, &y,
1865 &time_dummy);
1868 if (! NILP (x))
1870 int col = XINT (x);
1871 int row = XINT (y);
1872 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1873 XSETINT (x, col);
1874 XSETINT (y, row);
1876 XSETFRAME (lispy_dummy, f);
1877 retval = Fcons (lispy_dummy, Fcons (x, y));
1878 if (!NILP (Vmouse_position_function))
1879 retval = call1 (Vmouse_position_function, retval);
1880 return retval;
1883 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1884 Smouse_pixel_position, 0, 0, 0,
1885 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1886 The position is given in pixel units, where (0, 0) is the
1887 upper-left corner of the frame, X is the horizontal offset, and Y is
1888 the vertical offset.
1889 If Emacs is running on a mouseless terminal or hasn't been programmed
1890 to read the mouse position, it returns the selected frame for FRAME
1891 and nil for X and Y. */)
1892 (void)
1894 struct frame *f;
1895 Lisp_Object lispy_dummy;
1896 Lisp_Object x, y, retval;
1898 f = SELECTED_FRAME ();
1899 x = y = Qnil;
1901 /* It's okay for the hook to refrain from storing anything. */
1902 if (FRAME_TERMINAL (f)->mouse_position_hook)
1904 enum scroll_bar_part party_dummy;
1905 Time time_dummy;
1906 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1907 &lispy_dummy, &party_dummy,
1908 &x, &y,
1909 &time_dummy);
1912 XSETFRAME (lispy_dummy, f);
1913 retval = Fcons (lispy_dummy, Fcons (x, y));
1914 if (!NILP (Vmouse_position_function))
1915 retval = call1 (Vmouse_position_function, retval);
1916 return retval;
1919 #ifdef HAVE_WINDOW_SYSTEM
1921 /* On frame F, convert character coordinates X and Y to pixel
1922 coordinates *PIX_X and *PIX_Y. */
1924 static void
1925 frame_char_to_pixel_position (struct frame *f, int x, int y,
1926 int *pix_x, int *pix_y)
1928 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
1929 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
1931 if (*pix_x < 0)
1932 *pix_x = 0;
1933 if (*pix_x > FRAME_PIXEL_WIDTH (f))
1934 *pix_x = FRAME_PIXEL_WIDTH (f);
1936 if (*pix_y < 0)
1937 *pix_y = 0;
1938 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
1939 *pix_y = FRAME_PIXEL_HEIGHT (f);
1942 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1944 static void
1945 frame_set_mouse_position (struct frame *f, int x, int y)
1947 int pix_x, pix_y;
1949 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
1950 frame_set_mouse_pixel_position (f, pix_x, pix_y);
1953 #endif /* HAVE_WINDOW_SYSTEM */
1955 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1956 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1957 Coordinates are relative to the frame, not a window,
1958 so the coordinates of the top left character in the frame
1959 may be nonzero due to left-hand scroll bars or the menu bar.
1961 The position is given in canonical character cells, where (0, 0) is
1962 the upper-left corner of the frame, X is the horizontal offset, and
1963 Y is the vertical offset, measured in units of the frame's default
1964 character size.
1966 This function is a no-op for an X frame that is not visible.
1967 If you have just created a frame, you must wait for it to become visible
1968 before calling this function on it, like this.
1969 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1970 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1972 CHECK_LIVE_FRAME (frame);
1973 CHECK_TYPE_RANGED_INTEGER (int, x);
1974 CHECK_TYPE_RANGED_INTEGER (int, y);
1976 /* I think this should be done with a hook. */
1977 #ifdef HAVE_WINDOW_SYSTEM
1978 if (FRAME_WINDOW_P (XFRAME (frame)))
1979 /* Warping the mouse will cause enternotify and focus events. */
1980 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1981 #else
1982 #if defined (MSDOS)
1983 if (FRAME_MSDOS_P (XFRAME (frame)))
1985 Fselect_frame (frame, Qnil);
1986 mouse_moveto (XINT (x), XINT (y));
1988 #else
1989 #ifdef HAVE_GPM
1991 Fselect_frame (frame, Qnil);
1992 term_mouse_moveto (XINT (x), XINT (y));
1994 #endif
1995 #endif
1996 #endif
1998 return Qnil;
2001 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
2002 Sset_mouse_pixel_position, 3, 3, 0,
2003 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
2004 The position is given in pixels, where (0, 0) is the upper-left corner
2005 of the frame, X is the horizontal offset, and Y is the vertical offset.
2007 Note, this is a no-op for an X frame that is not visible.
2008 If you have just created a frame, you must wait for it to become visible
2009 before calling this function on it, like this.
2010 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2011 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2013 CHECK_LIVE_FRAME (frame);
2014 CHECK_TYPE_RANGED_INTEGER (int, x);
2015 CHECK_TYPE_RANGED_INTEGER (int, y);
2017 /* I think this should be done with a hook. */
2018 #ifdef HAVE_WINDOW_SYSTEM
2019 if (FRAME_WINDOW_P (XFRAME (frame)))
2020 /* Warping the mouse will cause enternotify and focus events. */
2021 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
2022 #else
2023 #if defined (MSDOS)
2024 if (FRAME_MSDOS_P (XFRAME (frame)))
2026 Fselect_frame (frame, Qnil);
2027 mouse_moveto (XINT (x), XINT (y));
2029 #else
2030 #ifdef HAVE_GPM
2032 Fselect_frame (frame, Qnil);
2033 term_mouse_moveto (XINT (x), XINT (y));
2035 #endif
2036 #endif
2037 #endif
2039 return Qnil;
2042 static void make_frame_visible_1 (Lisp_Object);
2044 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2045 0, 1, "",
2046 doc: /* Make the frame FRAME visible (assuming it is an X window).
2047 If omitted, FRAME defaults to the currently selected frame. */)
2048 (Lisp_Object frame)
2050 struct frame *f = decode_live_frame (frame);
2052 /* I think this should be done with a hook. */
2053 #ifdef HAVE_WINDOW_SYSTEM
2054 if (FRAME_WINDOW_P (f))
2055 x_make_frame_visible (f);
2056 #endif
2058 make_frame_visible_1 (f->root_window);
2060 /* Make menu bar update for the Buffers and Frames menus. */
2061 /* windows_or_buffers_changed = 15; FIXME: Why? */
2063 XSETFRAME (frame, f);
2064 return frame;
2067 /* Update the display_time slot of the buffers shown in WINDOW
2068 and all its descendants. */
2070 static void
2071 make_frame_visible_1 (Lisp_Object window)
2073 struct window *w;
2075 for (; !NILP (window); window = w->next)
2077 w = XWINDOW (window);
2078 if (WINDOWP (w->contents))
2079 make_frame_visible_1 (w->contents);
2080 else
2081 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2085 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2086 0, 2, "",
2087 doc: /* Make the frame FRAME invisible.
2088 If omitted, FRAME defaults to the currently selected frame.
2089 On graphical displays, invisible frames are not updated and are
2090 usually not displayed at all, even in a window system's \"taskbar\".
2092 Normally you may not make FRAME invisible if all other frames are invisible,
2093 but if the second optional argument FORCE is non-nil, you may do so.
2095 This function has no effect on text terminal frames. Such frames are
2096 always considered visible, whether or not they are currently being
2097 displayed in the terminal. */)
2098 (Lisp_Object frame, Lisp_Object force)
2100 struct frame *f = decode_live_frame (frame);
2102 if (NILP (force) && !other_visible_frames (f))
2103 error ("Attempt to make invisible the sole visible or iconified frame");
2105 /* Don't allow minibuf_window to remain on an invisible frame. */
2106 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2108 /* I think this should be done with a hook. */
2109 #ifdef HAVE_WINDOW_SYSTEM
2110 if (FRAME_WINDOW_P (f))
2111 x_make_frame_invisible (f);
2112 #endif
2114 /* Make menu bar update for the Buffers and Frames menus. */
2115 windows_or_buffers_changed = 16;
2117 return Qnil;
2120 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2121 0, 1, "",
2122 doc: /* Make the frame FRAME into an icon.
2123 If omitted, FRAME defaults to the currently selected frame. */)
2124 (Lisp_Object frame)
2126 struct frame *f = decode_live_frame (frame);
2128 /* Don't allow minibuf_window to remain on an iconified frame. */
2129 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2131 /* I think this should be done with a hook. */
2132 #ifdef HAVE_WINDOW_SYSTEM
2133 if (FRAME_WINDOW_P (f))
2134 x_iconify_frame (f);
2135 #endif
2137 /* Make menu bar update for the Buffers and Frames menus. */
2138 windows_or_buffers_changed = 17;
2140 return Qnil;
2143 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2144 1, 1, 0,
2145 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2146 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2147 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2148 On graphical displays, invisible frames are not updated and are
2149 usually not displayed at all, even in a window system's \"taskbar\".
2151 If FRAME is a text terminal frame, this always returns t.
2152 Such frames are always considered visible, whether or not they are
2153 currently being displayed on the terminal. */)
2154 (Lisp_Object frame)
2156 CHECK_LIVE_FRAME (frame);
2158 if (FRAME_VISIBLE_P (XFRAME (frame)))
2159 return Qt;
2160 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2161 return Qicon;
2162 return Qnil;
2165 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2166 0, 0, 0,
2167 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2168 (void)
2170 Lisp_Object tail, frame, value = Qnil;
2172 FOR_EACH_FRAME (tail, frame)
2173 if (FRAME_VISIBLE_P (XFRAME (frame)))
2174 value = Fcons (frame, value);
2176 return value;
2180 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2181 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2182 If FRAME is invisible or iconified, make it visible.
2183 If you don't specify a frame, the selected frame is used.
2184 If Emacs is displaying on an ordinary terminal or some other device which
2185 doesn't support multiple overlapping frames, this function selects FRAME. */)
2186 (Lisp_Object frame)
2188 struct frame *f = decode_live_frame (frame);
2190 XSETFRAME (frame, f);
2192 if (FRAME_TERMCAP_P (f))
2193 /* On a text terminal select FRAME. */
2194 Fselect_frame (frame, Qnil);
2195 else
2196 /* Do like the documentation says. */
2197 Fmake_frame_visible (frame);
2199 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2200 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2202 return Qnil;
2205 /* Should we have a corresponding function called Flower_Power? */
2206 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2207 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2208 If you don't specify a frame, the selected frame is used.
2209 If Emacs is displaying on an ordinary terminal or some other device which
2210 doesn't support multiple overlapping frames, this function does nothing. */)
2211 (Lisp_Object frame)
2213 struct frame *f = decode_live_frame (frame);
2215 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2216 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2218 return Qnil;
2222 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2223 1, 2, 0,
2224 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2225 In other words, switch-frame events caused by events in FRAME will
2226 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2227 FOCUS-FRAME after reading an event typed at FRAME.
2229 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2230 frame again receives its own keystrokes.
2232 Focus redirection is useful for temporarily redirecting keystrokes to
2233 a surrogate minibuffer frame when a frame doesn't have its own
2234 minibuffer window.
2236 A frame's focus redirection can be changed by `select-frame'. If frame
2237 FOO is selected, and then a different frame BAR is selected, any
2238 frames redirecting their focus to FOO are shifted to redirect their
2239 focus to BAR. This allows focus redirection to work properly when the
2240 user switches from one frame to another using `select-window'.
2242 This means that a frame whose focus is redirected to itself is treated
2243 differently from a frame whose focus is redirected to nil; the former
2244 is affected by `select-frame', while the latter is not.
2246 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2247 (Lisp_Object frame, Lisp_Object focus_frame)
2249 /* Note that we don't check for a live frame here. It's reasonable
2250 to redirect the focus of a frame you're about to delete, if you
2251 know what other frame should receive those keystrokes. */
2252 struct frame *f = decode_any_frame (frame);
2254 if (! NILP (focus_frame))
2255 CHECK_LIVE_FRAME (focus_frame);
2257 fset_focus_frame (f, focus_frame);
2259 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2260 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2262 return Qnil;
2266 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2267 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2268 If FRAME is omitted or nil, the selected frame is used.
2269 Return nil if FRAME's focus is not redirected.
2270 See `redirect-frame-focus'. */)
2271 (Lisp_Object frame)
2273 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2276 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2277 doc: /* Set the input focus to FRAME.
2278 FRAME nil means use the selected frame.
2279 If there is no window system support, this function does nothing. */)
2280 (Lisp_Object frame)
2282 #ifdef HAVE_WINDOW_SYSTEM
2283 x_focus_frame (decode_window_system_frame (frame));
2284 #endif
2285 return Qnil;
2288 DEFUN ("frame-after-make-frame",
2289 Fframe_after_make_frame,
2290 Sframe_after_make_frame, 2, 2, 0,
2291 doc: /* Mark FRAME as made.
2292 FRAME nil means use the selected frame. Second argument MADE non-nil
2293 means functions on `window-configuration-change-hook' are called
2294 whenever the window configuration of FRAME changes. MADE nil means
2295 these functions are not called.
2297 This function is currently called by `make-frame' only and should be
2298 otherwise used with utter care to avoid that running functions on
2299 `window-configuration-change-hook' is impeded forever. */)
2300 (Lisp_Object frame, Lisp_Object made)
2302 struct frame *f = decode_live_frame (frame);
2303 f->after_make_frame = !NILP (made);
2304 f->inhibit_horizontal_resize = false;
2305 f->inhibit_vertical_resize = false;
2306 return made;
2310 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2312 void
2313 frames_discard_buffer (Lisp_Object buffer)
2315 Lisp_Object frame, tail;
2317 FOR_EACH_FRAME (tail, frame)
2319 fset_buffer_list
2320 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2321 fset_buried_buffer_list
2322 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2326 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2327 If the alist already has an element for PROP, we change it. */
2329 void
2330 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2332 register Lisp_Object tem;
2334 tem = Fassq (prop, *alistptr);
2335 if (EQ (tem, Qnil))
2336 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2337 else
2338 Fsetcdr (tem, val);
2341 static int
2342 frame_name_fnn_p (char *str, ptrdiff_t len)
2344 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2346 char *p = str + 2;
2347 while ('0' <= *p && *p <= '9')
2348 p++;
2349 if (p == str + len)
2350 return 1;
2352 return 0;
2355 /* Set the name of the terminal frame. Also used by MSDOS frames.
2356 Modeled after x_set_name which is used for WINDOW frames. */
2358 static void
2359 set_term_frame_name (struct frame *f, Lisp_Object name)
2361 f->explicit_name = ! NILP (name);
2363 /* If NAME is nil, set the name to F<num>. */
2364 if (NILP (name))
2366 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2368 /* Check for no change needed in this very common case
2369 before we do any consing. */
2370 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2371 return;
2373 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2375 else
2377 CHECK_STRING (name);
2379 /* Don't change the name if it's already NAME. */
2380 if (! NILP (Fstring_equal (name, f->name)))
2381 return;
2383 /* Don't allow the user to set the frame name to F<num>, so it
2384 doesn't clash with the names we generate for terminal frames. */
2385 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2386 error ("Frame names of the form F<num> are usurped by Emacs");
2389 fset_name (f, name);
2390 update_mode_lines = 16;
2393 void
2394 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2396 register Lisp_Object old_alist_elt;
2398 /* The buffer-list parameters are stored in a special place and not
2399 in the alist. All buffers must be live. */
2400 if (EQ (prop, Qbuffer_list))
2402 Lisp_Object list = Qnil;
2403 for (; CONSP (val); val = XCDR (val))
2404 if (!NILP (Fbuffer_live_p (XCAR (val))))
2405 list = Fcons (XCAR (val), list);
2406 fset_buffer_list (f, Fnreverse (list));
2407 return;
2409 if (EQ (prop, Qburied_buffer_list))
2411 Lisp_Object list = Qnil;
2412 for (; CONSP (val); val = XCDR (val))
2413 if (!NILP (Fbuffer_live_p (XCAR (val))))
2414 list = Fcons (XCAR (val), list);
2415 fset_buried_buffer_list (f, Fnreverse (list));
2416 return;
2419 /* If PROP is a symbol which is supposed to have frame-local values,
2420 and it is set up based on this frame, switch to the global
2421 binding. That way, we can create or alter the frame-local binding
2422 without messing up the symbol's status. */
2423 if (SYMBOLP (prop))
2425 struct Lisp_Symbol *sym = XSYMBOL (prop);
2426 start:
2427 switch (sym->redirect)
2429 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2430 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2431 case SYMBOL_LOCALIZED:
2432 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2433 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2434 swap_in_global_binding (sym);
2435 break;
2437 default: emacs_abort ();
2441 /* The tty color needed to be set before the frame's parameter
2442 alist was updated with the new value. This is not true any more,
2443 but we still do this test early on. */
2444 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2445 && f == FRAME_TTY (f)->previous_frame)
2446 /* Force redisplay of this tty. */
2447 FRAME_TTY (f)->previous_frame = NULL;
2449 /* Update the frame parameter alist. */
2450 old_alist_elt = Fassq (prop, f->param_alist);
2451 if (EQ (old_alist_elt, Qnil))
2452 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2453 else
2454 Fsetcdr (old_alist_elt, val);
2456 /* Update some other special parameters in their special places
2457 in addition to the alist. */
2459 if (EQ (prop, Qbuffer_predicate))
2460 fset_buffer_predicate (f, val);
2462 if (! FRAME_WINDOW_P (f))
2464 if (EQ (prop, Qmenu_bar_lines))
2465 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2466 else if (EQ (prop, Qname))
2467 set_term_frame_name (f, val);
2470 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2472 if (! MINI_WINDOW_P (XWINDOW (val)))
2473 error ("Surrogate minibuffer windows must be minibuffer windows");
2475 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2476 && !EQ (val, f->minibuffer_window))
2477 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2479 /* Install the chosen minibuffer window, with proper buffer. */
2480 fset_minibuffer_window (f, val);
2484 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2485 is not an unspecified foreground or background color. */
2487 static Lisp_Object
2488 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2490 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2491 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2492 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2493 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2496 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2497 doc: /* Return the parameters-alist of frame FRAME.
2498 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2499 The meaningful PARMs depend on the kind of frame.
2500 If FRAME is omitted or nil, return information on the currently selected frame. */)
2501 (Lisp_Object frame)
2503 Lisp_Object alist;
2504 struct frame *f = decode_any_frame (frame);
2505 int height, width;
2507 if (!FRAME_LIVE_P (f))
2508 return Qnil;
2510 alist = Fcopy_alist (f->param_alist);
2512 if (!FRAME_WINDOW_P (f))
2514 Lisp_Object elt;
2516 /* If the frame's parameter alist says the colors are
2517 unspecified and reversed, take the frame's background pixel
2518 for foreground and vice versa. */
2519 elt = Fassq (Qforeground_color, alist);
2520 if (CONSP (elt) && STRINGP (XCDR (elt)))
2522 elt = frame_unspecified_color (f, XCDR (elt));
2523 if (!NILP (elt))
2524 store_in_alist (&alist, Qforeground_color, elt);
2526 else
2527 store_in_alist (&alist, Qforeground_color,
2528 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2529 elt = Fassq (Qbackground_color, alist);
2530 if (CONSP (elt) && STRINGP (XCDR (elt)))
2532 elt = frame_unspecified_color (f, XCDR (elt));
2533 if (!NILP (elt))
2534 store_in_alist (&alist, Qbackground_color, elt);
2536 else
2537 store_in_alist (&alist, Qbackground_color,
2538 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2539 store_in_alist (&alist, Qfont,
2540 build_string (FRAME_MSDOS_P (f)
2541 ? "ms-dos"
2542 : FRAME_W32_P (f) ? "w32term"
2543 :"tty"));
2545 store_in_alist (&alist, Qname, f->name);
2546 height = (f->new_height
2547 ? (f->new_pixelwise
2548 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2549 : f->new_height)
2550 : FRAME_LINES (f));
2551 store_in_alist (&alist, Qheight, make_number (height));
2552 width = (f->new_width
2553 ? (f->new_pixelwise
2554 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2555 : f->new_width)
2556 : FRAME_COLS (f));
2557 store_in_alist (&alist, Qwidth, make_number (width));
2558 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2559 store_in_alist (&alist, Qminibuffer,
2560 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2561 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2562 : FRAME_MINIBUF_WINDOW (f)));
2563 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2564 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2565 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2567 /* I think this should be done with a hook. */
2568 #ifdef HAVE_WINDOW_SYSTEM
2569 if (FRAME_WINDOW_P (f))
2570 x_report_frame_params (f, &alist);
2571 else
2572 #endif
2574 /* This ought to be correct in f->param_alist for an X frame. */
2575 Lisp_Object lines;
2576 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2577 store_in_alist (&alist, Qmenu_bar_lines, lines);
2580 return alist;
2584 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2585 doc: /* Return FRAME's value for parameter PARAMETER.
2586 If FRAME is nil, describe the currently selected frame. */)
2587 (Lisp_Object frame, Lisp_Object parameter)
2589 struct frame *f = decode_any_frame (frame);
2590 Lisp_Object value = Qnil;
2592 CHECK_SYMBOL (parameter);
2594 XSETFRAME (frame, f);
2596 if (FRAME_LIVE_P (f))
2598 /* Avoid consing in frequent cases. */
2599 if (EQ (parameter, Qname))
2600 value = f->name;
2601 #ifdef HAVE_X_WINDOWS
2602 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2603 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2604 #endif /* HAVE_X_WINDOWS */
2605 else if (EQ (parameter, Qbackground_color)
2606 || EQ (parameter, Qforeground_color))
2608 value = Fassq (parameter, f->param_alist);
2609 if (CONSP (value))
2611 value = XCDR (value);
2612 /* Fframe_parameters puts the actual fg/bg color names,
2613 even if f->param_alist says otherwise. This is
2614 important when param_alist's notion of colors is
2615 "unspecified". We need to do the same here. */
2616 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2618 Lisp_Object tem = frame_unspecified_color (f, value);
2620 if (!NILP (tem))
2621 value = tem;
2624 else
2625 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2627 else if (EQ (parameter, Qdisplay_type)
2628 || EQ (parameter, Qbackground_mode))
2629 value = Fcdr (Fassq (parameter, f->param_alist));
2630 else
2631 /* FIXME: Avoid this code path at all (as well as code duplication)
2632 by sharing more code with Fframe_parameters. */
2633 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2636 return value;
2640 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2641 Smodify_frame_parameters, 2, 2, 0,
2642 doc: /* Modify FRAME according to new values of its parameters in ALIST.
2643 If FRAME is nil, it defaults to the selected frame.
2644 ALIST is an alist of parameters to change and their new values.
2645 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2646 Which PARMs are meaningful depends on the kind of frame.
2647 The meaningful parameters are acted upon, i.e. the frame is changed
2648 according to their new values, and are also stored in the frame's
2649 parameter list so that `frame-parameters' will return them.
2650 PARMs that are not meaningful are still stored in the frame's parameter
2651 list, but are otherwise ignored.
2653 The value of frame parameter FOO can also be accessed
2654 as a frame-local binding for the variable FOO, if you have
2655 enabled such bindings for that variable with `make-variable-frame-local'.
2656 Note that this functionality is obsolete as of Emacs 22.2, and its
2657 use is not recommended. Explicitly check for a frame-parameter instead. */)
2658 (Lisp_Object frame, Lisp_Object alist)
2660 struct frame *f = decode_live_frame (frame);
2661 register Lisp_Object prop, val;
2663 CHECK_LIST (alist);
2665 /* I think this should be done with a hook. */
2666 #ifdef HAVE_WINDOW_SYSTEM
2667 if (FRAME_WINDOW_P (f))
2668 x_set_frame_parameters (f, alist);
2669 else
2670 #endif
2671 #ifdef MSDOS
2672 if (FRAME_MSDOS_P (f))
2673 IT_set_frame_parameters (f, alist);
2674 else
2675 #endif
2678 EMACS_INT length = XFASTINT (Flength (alist));
2679 ptrdiff_t i;
2680 Lisp_Object *parms;
2681 Lisp_Object *values;
2682 USE_SAFE_ALLOCA;
2683 SAFE_ALLOCA_LISP (parms, 2 * length);
2684 values = parms + length;
2686 /* Extract parm names and values into those vectors. */
2688 for (i = 0; CONSP (alist); alist = XCDR (alist))
2690 Lisp_Object elt;
2692 elt = XCAR (alist);
2693 parms[i] = Fcar (elt);
2694 values[i] = Fcdr (elt);
2695 i++;
2698 /* Now process them in reverse of specified order. */
2699 while (--i >= 0)
2701 prop = parms[i];
2702 val = values[i];
2703 store_frame_param (f, prop, val);
2705 if (EQ (prop, Qforeground_color)
2706 || EQ (prop, Qbackground_color))
2707 update_face_from_frame_parameter (f, prop, val);
2710 SAFE_FREE ();
2712 return Qnil;
2715 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2716 0, 1, 0,
2717 doc: /* Height in pixels of a line in the font in frame FRAME.
2718 If FRAME is omitted or nil, the selected frame is used.
2719 For a terminal frame, the value is always 1. */)
2720 (Lisp_Object frame)
2722 #ifdef HAVE_WINDOW_SYSTEM
2723 struct frame *f = decode_any_frame (frame);
2725 if (FRAME_WINDOW_P (f))
2726 return make_number (FRAME_LINE_HEIGHT (f));
2727 else
2728 #endif
2729 return make_number (1);
2733 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2734 0, 1, 0,
2735 doc: /* Width in pixels of characters in the font in frame FRAME.
2736 If FRAME is omitted or nil, the selected frame is used.
2737 On a graphical screen, the width is the standard width of the default font.
2738 For a terminal screen, the value is always 1. */)
2739 (Lisp_Object frame)
2741 #ifdef HAVE_WINDOW_SYSTEM
2742 struct frame *f = decode_any_frame (frame);
2744 if (FRAME_WINDOW_P (f))
2745 return make_number (FRAME_COLUMN_WIDTH (f));
2746 else
2747 #endif
2748 return make_number (1);
2751 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2752 Sframe_pixel_height, 0, 1, 0,
2753 doc: /* Return a FRAME's height in pixels.
2754 If FRAME is omitted or nil, the selected frame is used. The exact value
2755 of the result depends on the window-system and toolkit in use:
2757 In the Gtk+ version of Emacs, it includes only any window (including
2758 the minibuffer or echo area), mode line, and header line. It does not
2759 include the tool bar or menu bar.
2761 With other graphical versions, it also includes the tool bar and the
2762 menu bar.
2764 For a text terminal, it includes the menu bar. In this case, the
2765 result is really in characters rather than pixels (i.e., is identical
2766 to `frame-height'). */)
2767 (Lisp_Object frame)
2769 struct frame *f = decode_any_frame (frame);
2771 #ifdef HAVE_WINDOW_SYSTEM
2772 if (FRAME_WINDOW_P (f))
2773 return make_number (FRAME_PIXEL_HEIGHT (f));
2774 else
2775 #endif
2776 return make_number (FRAME_TOTAL_LINES (f));
2779 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2780 Sframe_pixel_width, 0, 1, 0,
2781 doc: /* Return FRAME's width in pixels.
2782 For a terminal frame, the result really gives the width in characters.
2783 If FRAME is omitted or nil, the selected frame is used. */)
2784 (Lisp_Object frame)
2786 struct frame *f = decode_any_frame (frame);
2788 #ifdef HAVE_WINDOW_SYSTEM
2789 if (FRAME_WINDOW_P (f))
2790 return make_number (FRAME_PIXEL_WIDTH (f));
2791 else
2792 #endif
2793 return make_number (FRAME_TOTAL_COLS (f));
2796 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2797 Stool_bar_pixel_width, 0, 1, 0,
2798 doc: /* Return width in pixels of FRAME's tool bar.
2799 The result is greater than zero only when the tool bar is on the left
2800 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2801 is used. */)
2802 (Lisp_Object frame)
2804 #ifdef FRAME_TOOLBAR_WIDTH
2805 struct frame *f = decode_any_frame (frame);
2807 if (FRAME_WINDOW_P (f))
2808 return make_number (FRAME_TOOLBAR_WIDTH (f));
2809 #endif
2810 return make_number (0);
2813 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2814 doc: /* Return width in columns of FRAME's text area. */)
2815 (Lisp_Object frame)
2817 return make_number (FRAME_COLS (decode_any_frame (frame)));
2820 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2821 doc: /* Return height in lines of FRAME's text area. */)
2822 (Lisp_Object frame)
2824 return make_number (FRAME_LINES (decode_any_frame (frame)));
2827 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2828 doc: /* Return number of total columns of FRAME. */)
2829 (Lisp_Object frame)
2831 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2834 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2835 doc: /* Return number of total lines of FRAME. */)
2836 (Lisp_Object frame)
2838 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2841 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2842 doc: /* Return text area width of FRAME in pixels. */)
2843 (Lisp_Object frame)
2845 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2848 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2849 doc: /* Return text area height of FRAME in pixels. */)
2850 (Lisp_Object frame)
2852 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2855 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2856 doc: /* Return scroll bar width of FRAME in pixels. */)
2857 (Lisp_Object frame)
2859 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2862 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2863 doc: /* Return scroll bar height of FRAME in pixels. */)
2864 (Lisp_Object frame)
2866 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2869 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2870 doc: /* Return fringe width of FRAME in pixels. */)
2871 (Lisp_Object frame)
2873 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2876 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2877 doc: /* Return border width of FRAME in pixels. */)
2878 (Lisp_Object frame)
2880 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2883 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2884 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2885 (Lisp_Object frame)
2887 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2890 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2891 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2892 (Lisp_Object frame)
2894 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2897 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2898 doc: /* Set text height of frame FRAME to HEIGHT lines.
2899 Optional third arg PRETEND non-nil means that redisplay should use
2900 HEIGHT lines but that the idea of the actual height of the frame should
2901 not be changed.
2903 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2904 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
2905 window managers may refuse to honor a HEIGHT that is not an integer
2906 multiple of the default frame font height. */)
2907 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2909 struct frame *f = decode_live_frame (frame);
2910 int pixel_height;
2912 CHECK_TYPE_RANGED_INTEGER (int, height);
2914 pixel_height = (!NILP (pixelwise)
2915 ? XINT (height)
2916 : XINT (height) * FRAME_LINE_HEIGHT (f));
2917 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
2919 return Qnil;
2922 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2923 doc: /* Set text width of frame FRAME to WIDTH columns.
2924 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2925 columns but that the idea of the actual width of the frame should not
2926 be changed.
2928 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2929 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
2930 window managers may refuse to honor a WIDTH that is not an integer
2931 multiple of the default frame font width. */)
2932 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2934 struct frame *f = decode_live_frame (frame);
2935 int pixel_width;
2937 CHECK_TYPE_RANGED_INTEGER (int, width);
2939 pixel_width = (!NILP (pixelwise)
2940 ? XINT (width)
2941 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2942 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
2944 return Qnil;
2947 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2948 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
2949 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
2950 When `frame-resize-pixelwise' is nil, some window managers may refuse to
2951 honor a WIDTH that is not an integer multiple of the default frame font
2952 width or a HEIGHT that is not an integer multiple of the default frame
2953 font height. */)
2954 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2956 struct frame *f = decode_live_frame (frame);
2957 int pixel_width, pixel_height;
2959 CHECK_TYPE_RANGED_INTEGER (int, width);
2960 CHECK_TYPE_RANGED_INTEGER (int, height);
2962 pixel_width = (!NILP (pixelwise)
2963 ? XINT (width)
2964 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2965 pixel_height = (!NILP (pixelwise)
2966 ? XINT (height)
2967 : XINT (height) * FRAME_LINE_HEIGHT (f));
2968 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
2970 return Qnil;
2973 DEFUN ("frame-position", Fframe_position,
2974 Sframe_position, 0, 1, 0,
2975 doc: /* Return top left corner of FRAME in pixels.
2976 FRAME must be a live frame and defaults to the selected one. The return
2977 value is a cons (x, y) of the coordinates of the top left corner of
2978 FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's
2979 display. */)
2980 (Lisp_Object frame)
2982 register struct frame *f = decode_live_frame (frame);
2984 return Fcons (make_number (f->left_pos), make_number (f->top_pos));
2987 DEFUN ("set-frame-position", Fset_frame_position,
2988 Sset_frame_position, 3, 3, 0,
2989 doc: /* Set position of FRAME to (X, Y).
2990 FRAME must be a live frame and defaults to the selected one. X and Y,
2991 if positive, specify the coordinate of the left and top edge of FRAME's
2992 outer frame in pixels relative to an origin (0, 0) of FRAME's display.
2993 If any of X or Y is negative, it specifies the coordinates of the right
2994 or bottom edge of the outer frame of FRAME relative to the right or
2995 bottom edge of FRAME's display. */)
2996 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2998 register struct frame *f = decode_live_frame (frame);
3000 CHECK_TYPE_RANGED_INTEGER (int, x);
3001 CHECK_TYPE_RANGED_INTEGER (int, y);
3003 /* I think this should be done with a hook. */
3004 #ifdef HAVE_WINDOW_SYSTEM
3005 if (FRAME_WINDOW_P (f))
3006 x_set_offset (f, XINT (x), XINT (y), 1);
3007 #endif
3009 return Qt;
3013 /***********************************************************************
3014 Frame Parameters
3015 ***********************************************************************/
3017 /* Connect the frame-parameter names for X frames
3018 to the ways of passing the parameter values to the window system.
3020 The name of a parameter, as a Lisp symbol,
3021 has an `x-frame-parameter' property which is an integer in Lisp
3022 that is an index in this table. */
3024 struct frame_parm_table {
3025 const char *name;
3026 int sym;
3029 static const struct frame_parm_table frame_parms[] =
3031 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3032 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3033 {"background-color", -1},
3034 {"border-color", SYMBOL_INDEX (Qborder_color)},
3035 {"border-width", SYMBOL_INDEX (Qborder_width)},
3036 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3037 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3038 {"font", -1},
3039 {"foreground-color", -1},
3040 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3041 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3042 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3043 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3044 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3045 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3046 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3047 {"name", SYMBOL_INDEX (Qname)},
3048 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3049 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3050 {"title", SYMBOL_INDEX (Qtitle)},
3051 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3052 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3053 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3054 {"visibility", SYMBOL_INDEX (Qvisibility)},
3055 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3056 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3057 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3058 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3059 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3060 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3061 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3062 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3063 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3064 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3065 {"alpha", SYMBOL_INDEX (Qalpha)},
3066 {"sticky", SYMBOL_INDEX (Qsticky)},
3067 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3070 #ifdef HAVE_WINDOW_SYSTEM
3072 /* Change the parameters of frame F as specified by ALIST.
3073 If a parameter is not specially recognized, do nothing special;
3074 otherwise call the `x_set_...' function for that parameter.
3075 Except for certain geometry properties, always call store_frame_param
3076 to store the new value in the parameter alist. */
3078 void
3079 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3081 Lisp_Object tail;
3083 /* If both of these parameters are present, it's more efficient to
3084 set them both at once. So we wait until we've looked at the
3085 entire list before we set them. */
3086 int width IF_LINT (= 0), height IF_LINT (= 0);
3087 bool width_change = false, height_change = false;
3089 /* Same here. */
3090 Lisp_Object left, top;
3092 /* Same with these. */
3093 Lisp_Object icon_left, icon_top;
3095 /* And with this. */
3096 Lisp_Object fullscreen;
3097 bool fullscreen_change = false;
3099 /* Record in these vectors all the parms specified. */
3100 Lisp_Object *parms;
3101 Lisp_Object *values;
3102 ptrdiff_t i, p;
3103 bool left_no_change = 0, top_no_change = 0;
3104 #ifdef HAVE_X_WINDOWS
3105 bool icon_left_no_change = 0, icon_top_no_change = 0;
3106 #endif
3108 i = 0;
3109 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3110 i++;
3112 USE_SAFE_ALLOCA;
3113 SAFE_ALLOCA_LISP (parms, 2 * i);
3114 values = parms + i;
3116 /* Extract parm names and values into those vectors. */
3118 i = 0;
3119 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3121 Lisp_Object elt;
3123 elt = XCAR (tail);
3124 parms[i] = Fcar (elt);
3125 values[i] = Fcdr (elt);
3126 i++;
3128 /* TAIL and ALIST are not used again below here. */
3129 alist = tail = Qnil;
3131 top = left = Qunbound;
3132 icon_left = icon_top = Qunbound;
3134 /* Process foreground_color and background_color before anything else.
3135 They are independent of other properties, but other properties (e.g.,
3136 cursor_color) are dependent upon them. */
3137 /* Process default font as well, since fringe widths depends on it. */
3138 for (p = 0; p < i; p++)
3140 Lisp_Object prop, val;
3142 prop = parms[p];
3143 val = values[p];
3144 if (EQ (prop, Qforeground_color)
3145 || EQ (prop, Qbackground_color)
3146 || EQ (prop, Qfont))
3148 register Lisp_Object param_index, old_value;
3150 old_value = get_frame_param (f, prop);
3151 if (NILP (Fequal (val, old_value)))
3153 store_frame_param (f, prop, val);
3155 param_index = Fget (prop, Qx_frame_parameter);
3156 if (NATNUMP (param_index)
3157 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3158 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3159 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3164 /* Now process them in reverse of specified order. */
3165 while (i-- != 0)
3167 Lisp_Object prop, val;
3169 prop = parms[i];
3170 val = values[i];
3172 if (EQ (prop, Qwidth))
3174 if (RANGED_INTEGERP (0, val, INT_MAX))
3176 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3177 width_change = true;
3179 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3180 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3182 width = XFASTINT (XCDR (val));
3183 width_change = true;
3186 else if (EQ (prop, Qheight))
3188 if (RANGED_INTEGERP (0, val, INT_MAX))
3190 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3191 height_change = true;
3193 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3194 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3196 height = XFASTINT (XCDR (val));
3197 height_change = true;
3200 else if (EQ (prop, Qtop))
3201 top = val;
3202 else if (EQ (prop, Qleft))
3203 left = val;
3204 else if (EQ (prop, Qicon_top))
3205 icon_top = val;
3206 else if (EQ (prop, Qicon_left))
3207 icon_left = val;
3208 else if (EQ (prop, Qfullscreen))
3210 fullscreen = val;
3211 fullscreen_change = true;
3213 else if (EQ (prop, Qforeground_color)
3214 || EQ (prop, Qbackground_color)
3215 || EQ (prop, Qfont))
3216 /* Processed above. */
3217 continue;
3218 else
3220 register Lisp_Object param_index, old_value;
3222 old_value = get_frame_param (f, prop);
3224 store_frame_param (f, prop, val);
3226 param_index = Fget (prop, Qx_frame_parameter);
3227 if (NATNUMP (param_index)
3228 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3229 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3230 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3234 /* Don't die if just one of these was set. */
3235 if (EQ (left, Qunbound))
3237 left_no_change = 1;
3238 if (f->left_pos < 0)
3239 left = list2 (Qplus, make_number (f->left_pos));
3240 else
3241 XSETINT (left, f->left_pos);
3243 if (EQ (top, Qunbound))
3245 top_no_change = 1;
3246 if (f->top_pos < 0)
3247 top = list2 (Qplus, make_number (f->top_pos));
3248 else
3249 XSETINT (top, f->top_pos);
3252 /* If one of the icon positions was not set, preserve or default it. */
3253 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3255 #ifdef HAVE_X_WINDOWS
3256 icon_left_no_change = 1;
3257 #endif
3258 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3259 if (NILP (icon_left))
3260 XSETINT (icon_left, 0);
3262 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3264 #ifdef HAVE_X_WINDOWS
3265 icon_top_no_change = 1;
3266 #endif
3267 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3268 if (NILP (icon_top))
3269 XSETINT (icon_top, 0);
3272 /* Don't set these parameters unless they've been explicitly
3273 specified. The window might be mapped or resized while we're in
3274 this function, and we don't want to override that unless the lisp
3275 code has asked for it.
3277 Don't set these parameters unless they actually differ from the
3278 window's current parameters; the window may not actually exist
3279 yet. */
3281 Lisp_Object frame;
3283 XSETFRAME (frame, f);
3285 if ((width_change && width != FRAME_TEXT_WIDTH (f))
3286 || (height_change && height != FRAME_TEXT_HEIGHT (f)))
3287 /* We could consider checking f->after_make_frame here, but I
3288 don't have the faintest idea why the following is needed at
3289 all. With the old setting it can get a Heisenbug when
3290 EmacsFrameResize intermittently provokes a delayed
3291 change_frame_size in the middle of adjust_frame_size. */
3292 /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
3293 adjust_frame_size (f, width_change ? width : -1,
3294 height_change ? height : -1, 1, 0, Qx_set_frame_parameters);
3296 if ((!NILP (left) || !NILP (top))
3297 && ! (left_no_change && top_no_change)
3298 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3299 && NUMBERP (top) && XINT (top) == f->top_pos))
3301 int leftpos = 0;
3302 int toppos = 0;
3304 /* Record the signs. */
3305 f->size_hint_flags &= ~ (XNegative | YNegative);
3306 if (EQ (left, Qminus))
3307 f->size_hint_flags |= XNegative;
3308 else if (TYPE_RANGED_INTEGERP (int, left))
3310 leftpos = XINT (left);
3311 if (leftpos < 0)
3312 f->size_hint_flags |= XNegative;
3314 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3315 && CONSP (XCDR (left))
3316 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3318 leftpos = - XINT (XCAR (XCDR (left)));
3319 f->size_hint_flags |= XNegative;
3321 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3322 && CONSP (XCDR (left))
3323 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3325 leftpos = XINT (XCAR (XCDR (left)));
3328 if (EQ (top, Qminus))
3329 f->size_hint_flags |= YNegative;
3330 else if (TYPE_RANGED_INTEGERP (int, top))
3332 toppos = XINT (top);
3333 if (toppos < 0)
3334 f->size_hint_flags |= YNegative;
3336 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3337 && CONSP (XCDR (top))
3338 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3340 toppos = - XINT (XCAR (XCDR (top)));
3341 f->size_hint_flags |= YNegative;
3343 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3344 && CONSP (XCDR (top))
3345 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3347 toppos = XINT (XCAR (XCDR (top)));
3351 /* Store the numeric value of the position. */
3352 f->top_pos = toppos;
3353 f->left_pos = leftpos;
3355 f->win_gravity = NorthWestGravity;
3357 /* Actually set that position, and convert to absolute. */
3358 x_set_offset (f, leftpos, toppos, -1);
3361 if (fullscreen_change)
3363 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
3365 frame_size_history_add
3366 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
3368 store_frame_param (f, Qfullscreen, fullscreen);
3369 if (!EQ (fullscreen, old_value))
3370 x_set_fullscreen (f, fullscreen, old_value);
3374 #ifdef HAVE_X_WINDOWS
3375 if ((!NILP (icon_left) || !NILP (icon_top))
3376 && ! (icon_left_no_change && icon_top_no_change))
3377 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3378 #endif /* HAVE_X_WINDOWS */
3381 SAFE_FREE ();
3385 /* Insert a description of internally-recorded parameters of frame X
3386 into the parameter alist *ALISTPTR that is to be given to the user.
3387 Only parameters that are specific to the X window system
3388 and whose values are not correctly recorded in the frame's
3389 param_alist need to be considered here. */
3391 void
3392 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3394 Lisp_Object tem;
3395 uprintmax_t w;
3396 char buf[INT_BUFSIZE_BOUND (w)];
3398 /* Represent negative positions (off the top or left screen edge)
3399 in a way that Fmodify_frame_parameters will understand correctly. */
3400 XSETINT (tem, f->left_pos);
3401 if (f->left_pos >= 0)
3402 store_in_alist (alistptr, Qleft, tem);
3403 else
3404 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3406 XSETINT (tem, f->top_pos);
3407 if (f->top_pos >= 0)
3408 store_in_alist (alistptr, Qtop, tem);
3409 else
3410 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3412 store_in_alist (alistptr, Qborder_width,
3413 make_number (f->border_width));
3414 store_in_alist (alistptr, Qinternal_border_width,
3415 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3416 store_in_alist (alistptr, Qright_divider_width,
3417 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3418 store_in_alist (alistptr, Qbottom_divider_width,
3419 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3420 store_in_alist (alistptr, Qleft_fringe,
3421 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3422 store_in_alist (alistptr, Qright_fringe,
3423 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3424 store_in_alist (alistptr, Qscroll_bar_width,
3425 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3426 ? make_number (0)
3427 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3428 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3429 /* nil means "use default width"
3430 for non-toolkit scroll bar.
3431 ruler-mode.el depends on this. */
3432 : Qnil));
3433 store_in_alist (alistptr, Qscroll_bar_height,
3434 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3435 ? make_number (0)
3436 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3437 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3438 /* nil means "use default height"
3439 for non-toolkit scroll bar. */
3440 : Qnil));
3441 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3442 MS-Windows it returns a value whose type is HANDLE, which is
3443 actually a pointer. Explicit casting avoids compiler
3444 warnings. */
3445 w = (uintptr_t) FRAME_X_WINDOW (f);
3446 store_in_alist (alistptr, Qwindow_id,
3447 make_formatted_string (buf, "%"pMu, w));
3448 #ifdef HAVE_X_WINDOWS
3449 #ifdef USE_X_TOOLKIT
3450 /* Tooltip frame may not have this widget. */
3451 if (FRAME_X_OUTPUT (f)->widget)
3452 #endif
3453 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3454 store_in_alist (alistptr, Qouter_window_id,
3455 make_formatted_string (buf, "%"pMu, w));
3456 #endif
3457 store_in_alist (alistptr, Qicon_name, f->icon_name);
3458 store_in_alist (alistptr, Qvisibility,
3459 (FRAME_VISIBLE_P (f) ? Qt
3460 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3461 store_in_alist (alistptr, Qdisplay,
3462 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3464 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3465 tem = Qnil;
3466 else
3467 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3468 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3469 store_in_alist (alistptr, Qparent_id, tem);
3470 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3474 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3475 the previous value of that parameter, NEW_VALUE is the new value. */
3477 void
3478 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3480 if (NILP (new_value))
3481 f->want_fullscreen = FULLSCREEN_NONE;
3482 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3483 f->want_fullscreen = FULLSCREEN_BOTH;
3484 else if (EQ (new_value, Qfullwidth))
3485 f->want_fullscreen = FULLSCREEN_WIDTH;
3486 else if (EQ (new_value, Qfullheight))
3487 f->want_fullscreen = FULLSCREEN_HEIGHT;
3488 else if (EQ (new_value, Qmaximized))
3489 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3491 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3492 FRAME_TERMINAL (f)->fullscreen_hook (f);
3496 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3497 the previous value of that parameter, NEW_VALUE is the new value. */
3499 void
3500 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3502 if (NILP (new_value))
3503 f->extra_line_spacing = 0;
3504 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3505 f->extra_line_spacing = XFASTINT (new_value);
3506 else if (FLOATP (new_value))
3508 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3510 if (new_spacing >= 0)
3511 f->extra_line_spacing = new_spacing;
3512 else
3513 signal_error ("Invalid line-spacing", new_value);
3515 else
3516 signal_error ("Invalid line-spacing", new_value);
3517 if (FRAME_VISIBLE_P (f))
3518 redraw_frame (f);
3522 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3523 the previous value of that parameter, NEW_VALUE is the new value. */
3525 void
3526 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3528 Lisp_Object bgcolor;
3530 if (NILP (new_value))
3531 f->gamma = 0;
3532 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3533 /* The value 0.4545 is the normal viewing gamma. */
3534 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3535 else
3536 signal_error ("Invalid screen-gamma", new_value);
3538 /* Apply the new gamma value to the frame background. */
3539 bgcolor = Fassq (Qbackground_color, f->param_alist);
3540 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3542 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3543 if (NATNUMP (parm_index)
3544 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3545 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3546 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3547 (f, bgcolor, Qnil);
3550 clear_face_cache (true); /* FIXME: Why of all frames? */
3551 fset_redisplay (f);
3555 void
3556 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3558 Lisp_Object font_object;
3559 int fontset = -1;
3560 #ifdef HAVE_X_WINDOWS
3561 Lisp_Object font_param = arg;
3562 #endif
3564 /* Set the frame parameter back to the old value because we may
3565 fail to use ARG as the new parameter value. */
3566 store_frame_param (f, Qfont, oldval);
3568 /* ARG is a fontset name, a font name, a cons of fontset name and a
3569 font object, or a font object. In the last case, this function
3570 never fail. */
3571 if (STRINGP (arg))
3573 fontset = fs_query_fontset (arg, 0);
3574 if (fontset < 0)
3576 font_object = font_open_by_name (f, arg);
3577 if (NILP (font_object))
3578 error ("Font `%s' is not defined", SSDATA (arg));
3579 arg = AREF (font_object, FONT_NAME_INDEX);
3581 else if (fontset > 0)
3583 font_object = font_open_by_name (f, fontset_ascii (fontset));
3584 if (NILP (font_object))
3585 error ("Font `%s' is not defined", SDATA (arg));
3586 arg = AREF (font_object, FONT_NAME_INDEX);
3588 else
3589 error ("The default fontset can't be used for a frame font");
3591 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3593 /* This is the case that the ASCII font of F's fontset XCAR
3594 (arg) is changed to the font XCDR (arg) by
3595 `set-fontset-font'. */
3596 fontset = fs_query_fontset (XCAR (arg), 0);
3597 if (fontset < 0)
3598 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3599 font_object = XCDR (arg);
3600 arg = AREF (font_object, FONT_NAME_INDEX);
3601 #ifdef HAVE_X_WINDOWS
3602 font_param = Ffont_get (font_object, QCname);
3603 #endif
3605 else if (FONT_OBJECT_P (arg))
3607 font_object = arg;
3608 #ifdef HAVE_X_WINDOWS
3609 font_param = Ffont_get (font_object, QCname);
3610 #endif
3611 /* This is to store the XLFD font name in the frame parameter for
3612 backward compatibility. We should store the font-object
3613 itself in the future. */
3614 arg = AREF (font_object, FONT_NAME_INDEX);
3615 fontset = FRAME_FONTSET (f);
3616 /* Check if we can use the current fontset. If not, set FONTSET
3617 to -1 to generate a new fontset from FONT-OBJECT. */
3618 if (fontset >= 0)
3620 Lisp_Object ascii_font = fontset_ascii (fontset);
3621 Lisp_Object spec = font_spec_from_name (ascii_font);
3623 /* SPEC might be nil because ASCII_FONT's name doesn't parse
3624 according to stupid XLFD rules, which, for example,
3625 disallow font names that include a dash followed by a
3626 number. So in those cases we simply request x_new_font
3627 below to generate a new fontset. */
3628 if (NILP (spec) || ! font_match_p (spec, font_object))
3629 fontset = -1;
3632 else
3633 signal_error ("Invalid font", arg);
3635 if (! NILP (Fequal (font_object, oldval)))
3636 return;
3638 x_new_font (f, font_object, fontset);
3639 store_frame_param (f, Qfont, arg);
3640 #ifdef HAVE_X_WINDOWS
3641 store_frame_param (f, Qfont_param, font_param);
3642 #endif
3643 /* Recalculate toolbar height. */
3644 f->n_tool_bar_rows = 0;
3646 /* Ensure we redraw it. */
3647 clear_current_matrices (f);
3649 /* Attempt to hunt down bug#16028. */
3650 SET_FRAME_GARBAGED (f);
3652 /* This is important if we are called by some Lisp as part of
3653 redisplaying the frame, see redisplay_internal. */
3654 f->fonts_changed = true;
3656 recompute_basic_faces (f);
3658 do_pending_window_change (0);
3660 /* We used to call face-set-after-frame-default here, but it leads to
3661 recursive calls (since that function can set the `default' face's
3662 font which in turns changes the frame's `font' parameter).
3663 Also I don't know what this call is meant to do, but it seems the
3664 wrong way to do it anyway (it does a lot more work than what seems
3665 reasonable in response to a change to `font'). */
3669 void
3670 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3672 if (! NILP (new_value)
3673 && !CONSP (new_value))
3675 char *p0, *p1;
3677 CHECK_STRING (new_value);
3678 p0 = p1 = SSDATA (new_value);
3679 new_value = Qnil;
3680 while (*p0)
3682 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3683 if (p0 < p1)
3684 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3685 new_value);
3686 if (*p1)
3688 int c;
3690 while ((c = *++p1) && c_isspace (c));
3692 p0 = p1;
3694 new_value = Fnreverse (new_value);
3697 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3698 return;
3700 if (FRAME_FONT (f))
3701 free_all_realized_faces (Qnil);
3703 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3704 if (NILP (new_value))
3706 if (NILP (old_value))
3707 error ("No font backend available");
3708 font_update_drivers (f, old_value);
3709 error ("None of specified font backends are available");
3711 store_frame_param (f, Qfont_backend, new_value);
3713 if (FRAME_FONT (f))
3715 Lisp_Object frame;
3717 XSETFRAME (frame, f);
3718 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3719 face_change = true;
3720 windows_or_buffers_changed = 18;
3724 void
3725 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3727 int unit = FRAME_COLUMN_WIDTH (f);
3728 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3729 int new_width;
3731 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3732 ? eabs (XINT (new_value)) : 8);
3734 if (new_width != old_width)
3736 FRAME_LEFT_FRINGE_WIDTH (f) = new_width;
3737 FRAME_FRINGE_COLS (f) /* Round up. */
3738 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3740 if (FRAME_X_WINDOW (f) != 0)
3741 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
3743 SET_FRAME_GARBAGED (f);
3748 void
3749 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3751 int unit = FRAME_COLUMN_WIDTH (f);
3752 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3753 int new_width;
3755 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3756 ? eabs (XINT (new_value)) : 8);
3758 if (new_width != old_width)
3760 FRAME_RIGHT_FRINGE_WIDTH (f) = new_width;
3761 FRAME_FRINGE_COLS (f) /* Round up. */
3762 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3764 if (FRAME_X_WINDOW (f) != 0)
3765 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
3767 SET_FRAME_GARBAGED (f);
3772 void
3773 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3775 CHECK_TYPE_RANGED_INTEGER (int, arg);
3777 if (XINT (arg) == f->border_width)
3778 return;
3780 if (FRAME_X_WINDOW (f) != 0)
3781 error ("Cannot change the border width of a frame");
3783 f->border_width = XINT (arg);
3786 void
3787 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3789 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3791 CHECK_TYPE_RANGED_INTEGER (int, arg);
3792 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3793 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3794 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3795 if (FRAME_RIGHT_DIVIDER_WIDTH (f) != old)
3797 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
3798 adjust_frame_glyphs (f);
3799 SET_FRAME_GARBAGED (f);
3804 void
3805 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3807 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3809 CHECK_TYPE_RANGED_INTEGER (int, arg);
3810 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3811 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3812 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3813 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) != old)
3815 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
3816 adjust_frame_glyphs (f);
3817 SET_FRAME_GARBAGED (f);
3821 void
3822 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3824 Lisp_Object frame;
3825 XSETFRAME (frame, f);
3827 if (NILP (value))
3828 Fmake_frame_invisible (frame, Qt);
3829 else if (EQ (value, Qicon))
3830 Ficonify_frame (frame);
3831 else
3832 Fmake_frame_visible (frame);
3835 void
3836 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3838 f->auto_raise = !EQ (Qnil, arg);
3841 void
3842 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3844 f->auto_lower = !EQ (Qnil, arg);
3847 void
3848 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3850 f->no_split = !NILP (arg);
3853 void
3854 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3856 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3857 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3858 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3859 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3861 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3862 = (NILP (arg)
3863 ? vertical_scroll_bar_none
3864 : EQ (Qleft, arg)
3865 ? vertical_scroll_bar_left
3866 : EQ (Qright, arg)
3867 ? vertical_scroll_bar_right
3868 : EQ (Qleft, Vdefault_frame_scroll_bars)
3869 ? vertical_scroll_bar_left
3870 : EQ (Qright, Vdefault_frame_scroll_bars)
3871 ? vertical_scroll_bar_right
3872 : vertical_scroll_bar_none);
3874 /* We set this parameter before creating the X window for the
3875 frame, so we can get the geometry right from the start.
3876 However, if the window hasn't been created yet, we shouldn't
3877 call x_set_window_size. */
3878 if (FRAME_X_WINDOW (f))
3879 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
3881 SET_FRAME_GARBAGED (f);
3885 void
3886 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3888 #if USE_HORIZONTAL_SCROLL_BARS
3889 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3890 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3892 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3894 /* We set this parameter before creating the X window for the
3895 frame, so we can get the geometry right from the start.
3896 However, if the window hasn't been created yet, we shouldn't
3897 call x_set_window_size. */
3898 if (FRAME_X_WINDOW (f))
3899 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
3901 SET_FRAME_GARBAGED (f);
3903 #endif
3906 void
3907 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3909 int unit = FRAME_COLUMN_WIDTH (f);
3911 if (NILP (arg))
3913 x_set_scroll_bar_default_width (f);
3915 if (FRAME_X_WINDOW (f))
3916 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3918 SET_FRAME_GARBAGED (f);
3920 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3921 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3923 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3924 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3925 if (FRAME_X_WINDOW (f))
3926 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3928 SET_FRAME_GARBAGED (f);
3931 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3932 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3935 void
3936 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3938 #if USE_HORIZONTAL_SCROLL_BARS
3939 int unit = FRAME_LINE_HEIGHT (f);
3941 if (NILP (arg))
3943 x_set_scroll_bar_default_height (f);
3945 if (FRAME_X_WINDOW (f))
3946 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3948 SET_FRAME_GARBAGED (f);
3950 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3951 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3953 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3954 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3955 if (FRAME_X_WINDOW (f))
3956 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3958 SET_FRAME_GARBAGED (f);
3961 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3962 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3963 #endif
3966 void
3967 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3969 double alpha = 1.0;
3970 double newval[2];
3971 int i;
3972 Lisp_Object item;
3974 for (i = 0; i < 2; i++)
3976 newval[i] = 1.0;
3977 if (CONSP (arg))
3979 item = CAR (arg);
3980 arg = CDR (arg);
3982 else
3983 item = arg;
3985 if (NILP (item))
3986 alpha = - 1.0;
3987 else if (FLOATP (item))
3989 alpha = XFLOAT_DATA (item);
3990 if (! (0 <= alpha && alpha <= 1.0))
3991 args_out_of_range (make_float (0.0), make_float (1.0));
3993 else if (INTEGERP (item))
3995 EMACS_INT ialpha = XINT (item);
3996 if (! (0 <= ialpha && alpha <= 100))
3997 args_out_of_range (make_number (0), make_number (100));
3998 alpha = ialpha / 100.0;
4000 else
4001 wrong_type_argument (Qnumberp, item);
4002 newval[i] = alpha;
4005 for (i = 0; i < 2; i++)
4006 f->alpha[i] = newval[i];
4008 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4009 block_input ();
4010 x_set_frame_alpha (f);
4011 unblock_input ();
4012 #endif
4014 return;
4017 #ifndef HAVE_NS
4019 /* Non-zero if mouse is grabbed on DPYINFO
4020 and we know the frame where it is. */
4022 bool x_mouse_grabbed (Display_Info *dpyinfo)
4024 return (dpyinfo->grabbed
4025 && dpyinfo->last_mouse_frame
4026 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4029 /* Re-highlight something with mouse-face properties
4030 on DPYINFO using saved frame and mouse position. */
4032 void
4033 x_redo_mouse_highlight (Display_Info *dpyinfo)
4035 if (dpyinfo->last_mouse_motion_frame
4036 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4037 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4038 dpyinfo->last_mouse_motion_x,
4039 dpyinfo->last_mouse_motion_y);
4042 #endif /* HAVE_NS */
4044 /* Subroutines of creating an X frame. */
4046 /* Make sure that Vx_resource_name is set to a reasonable value.
4047 Fix it up, or set it to `emacs' if it is too hopeless. */
4049 void
4050 validate_x_resource_name (void)
4052 ptrdiff_t len = 0;
4053 /* Number of valid characters in the resource name. */
4054 ptrdiff_t good_count = 0;
4055 /* Number of invalid characters in the resource name. */
4056 ptrdiff_t bad_count = 0;
4057 Lisp_Object new;
4058 ptrdiff_t i;
4060 if (!STRINGP (Vx_resource_class))
4061 Vx_resource_class = build_string (EMACS_CLASS);
4063 if (STRINGP (Vx_resource_name))
4065 unsigned char *p = SDATA (Vx_resource_name);
4067 len = SBYTES (Vx_resource_name);
4069 /* Only letters, digits, - and _ are valid in resource names.
4070 Count the valid characters and count the invalid ones. */
4071 for (i = 0; i < len; i++)
4073 int c = p[i];
4074 if (! ((c >= 'a' && c <= 'z')
4075 || (c >= 'A' && c <= 'Z')
4076 || (c >= '0' && c <= '9')
4077 || c == '-' || c == '_'))
4078 bad_count++;
4079 else
4080 good_count++;
4083 else
4084 /* Not a string => completely invalid. */
4085 bad_count = 5, good_count = 0;
4087 /* If name is valid already, return. */
4088 if (bad_count == 0)
4089 return;
4091 /* If name is entirely invalid, or nearly so, or is so implausibly
4092 large that alloca might not work, use `emacs'. */
4093 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4095 Vx_resource_name = build_string ("emacs");
4096 return;
4099 /* Name is partly valid. Copy it and replace the invalid characters
4100 with underscores. */
4102 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4104 for (i = 0; i < len; i++)
4106 int c = SREF (new, i);
4107 if (! ((c >= 'a' && c <= 'z')
4108 || (c >= 'A' && c <= 'Z')
4109 || (c >= '0' && c <= '9')
4110 || c == '-' || c == '_'))
4111 SSET (new, i, '_');
4115 /* Get specified attribute from resource database RDB.
4116 See Fx_get_resource below for other parameters. */
4118 static Lisp_Object
4119 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4121 CHECK_STRING (attribute);
4122 CHECK_STRING (class);
4124 if (!NILP (component))
4125 CHECK_STRING (component);
4126 if (!NILP (subclass))
4127 CHECK_STRING (subclass);
4128 if (NILP (component) != NILP (subclass))
4129 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4131 validate_x_resource_name ();
4133 /* Allocate space for the components, the dots which separate them,
4134 and the final '\0'. Make them big enough for the worst case. */
4135 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4136 + (STRINGP (component)
4137 ? SBYTES (component) : 0)
4138 + SBYTES (attribute)
4139 + 3);
4141 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4142 + SBYTES (class)
4143 + (STRINGP (subclass)
4144 ? SBYTES (subclass) : 0)
4145 + 3);
4146 USE_SAFE_ALLOCA;
4147 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4148 char *class_key = name_key + name_keysize;
4150 /* Start with emacs.FRAMENAME for the name (the specific one)
4151 and with `Emacs' for the class key (the general one). */
4152 char *nz = lispstpcpy (name_key, Vx_resource_name);
4153 char *cz = lispstpcpy (class_key, Vx_resource_class);
4155 *cz++ = '.';
4156 cz = lispstpcpy (cz, class);
4158 if (!NILP (component))
4160 *cz++ = '.';
4161 lispstpcpy (cz, subclass);
4163 *nz++ = '.';
4164 nz = lispstpcpy (nz, component);
4167 *nz++ = '.';
4168 lispstpcpy (nz, attribute);
4170 char *value = x_get_string_resource (rdb, name_key, class_key);
4171 SAFE_FREE();
4173 if (value && *value)
4174 return build_string (value);
4175 else
4176 return Qnil;
4180 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4181 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4182 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4183 class, where INSTANCE is the name under which Emacs was invoked, or
4184 the name specified by the `-name' or `-rn' command-line arguments.
4186 The optional arguments COMPONENT and SUBCLASS add to the key and the
4187 class, respectively. You must specify both of them or neither.
4188 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4189 and the class is `Emacs.CLASS.SUBCLASS'. */)
4190 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4191 Lisp_Object subclass)
4193 check_window_system (NULL);
4195 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4196 attribute, class, component, subclass);
4199 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4201 Lisp_Object
4202 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4203 Lisp_Object class, Lisp_Object component,
4204 Lisp_Object subclass)
4206 return xrdb_get_resource (dpyinfo->xrdb,
4207 attribute, class, component, subclass);
4210 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4211 /* Used when C code wants a resource value. */
4212 /* Called from oldXMenu/Create.c. */
4213 char *
4214 x_get_resource_string (const char *attribute, const char *class)
4216 char *result;
4217 struct frame *sf = SELECTED_FRAME ();
4218 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4219 USE_SAFE_ALLOCA;
4221 /* Allocate space for the components, the dots which separate them,
4222 and the final '\0'. */
4223 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4224 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4225 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4226 char *class_key = name_key + name_keysize;
4228 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4229 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4231 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4232 name_key, class_key);
4233 SAFE_FREE ();
4234 return result;
4236 #endif
4238 /* Return the value of parameter PARAM.
4240 First search ALIST, then Vdefault_frame_alist, then the X defaults
4241 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4243 Convert the resource to the type specified by desired_type.
4245 If no default is specified, return Qunbound. If you call
4246 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4247 and don't let it get stored in any Lisp-visible variables! */
4249 Lisp_Object
4250 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4251 const char *attribute, const char *class, enum resource_types type)
4253 Lisp_Object tem;
4255 tem = Fassq (param, alist);
4257 if (!NILP (tem))
4259 /* If we find this parm in ALIST, clear it out
4260 so that it won't be "left over" at the end. */
4261 Lisp_Object tail;
4262 XSETCAR (tem, Qnil);
4263 /* In case the parameter appears more than once in the alist,
4264 clear it out. */
4265 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4266 if (CONSP (XCAR (tail))
4267 && EQ (XCAR (XCAR (tail)), param))
4268 XSETCAR (XCAR (tail), Qnil);
4270 else
4271 tem = Fassq (param, Vdefault_frame_alist);
4273 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4274 look in the X resources. */
4275 if (EQ (tem, Qnil))
4277 if (attribute && dpyinfo)
4279 AUTO_STRING (at, attribute);
4280 AUTO_STRING (cl, class);
4281 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4283 if (NILP (tem))
4284 return Qunbound;
4286 switch (type)
4288 case RES_TYPE_NUMBER:
4289 return make_number (atoi (SSDATA (tem)));
4291 case RES_TYPE_BOOLEAN_NUMBER:
4292 if (!strcmp (SSDATA (tem), "on")
4293 || !strcmp (SSDATA (tem), "true"))
4294 return make_number (1);
4295 return make_number (atoi (SSDATA (tem)));
4296 break;
4298 case RES_TYPE_FLOAT:
4299 return make_float (atof (SSDATA (tem)));
4301 case RES_TYPE_BOOLEAN:
4302 tem = Fdowncase (tem);
4303 if (!strcmp (SSDATA (tem), "on")
4304 #ifdef HAVE_NS
4305 || !strcmp (SSDATA (tem), "yes")
4306 #endif
4307 || !strcmp (SSDATA (tem), "true"))
4308 return Qt;
4309 else
4310 return Qnil;
4312 case RES_TYPE_STRING:
4313 return tem;
4315 case RES_TYPE_SYMBOL:
4316 /* As a special case, we map the values `true' and `on'
4317 to Qt, and `false' and `off' to Qnil. */
4319 Lisp_Object lower;
4320 lower = Fdowncase (tem);
4321 if (!strcmp (SSDATA (lower), "on")
4322 #ifdef HAVE_NS
4323 || !strcmp (SSDATA (lower), "yes")
4324 #endif
4325 || !strcmp (SSDATA (lower), "true"))
4326 return Qt;
4327 else if (!strcmp (SSDATA (lower), "off")
4328 #ifdef HAVE_NS
4329 || !strcmp (SSDATA (lower), "no")
4330 #endif
4331 || !strcmp (SSDATA (lower), "false"))
4332 return Qnil;
4333 else
4334 return Fintern (tem, Qnil);
4337 default:
4338 emacs_abort ();
4341 else
4342 return Qunbound;
4344 return Fcdr (tem);
4347 static Lisp_Object
4348 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4349 const char *attribute, const char *class,
4350 enum resource_types type)
4352 return x_get_arg (FRAME_DISPLAY_INFO (f),
4353 alist, param, attribute, class, type);
4356 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4358 Lisp_Object
4359 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4360 Lisp_Object param,
4361 const char *attribute, const char *class,
4362 enum resource_types type)
4364 Lisp_Object value;
4366 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4367 attribute, class, type);
4368 if (! NILP (value) && ! EQ (value, Qunbound))
4369 store_frame_param (f, param, value);
4371 return value;
4375 /* Record in frame F the specified or default value according to ALIST
4376 of the parameter named PROP (a Lisp symbol).
4377 If no value is specified for PROP, look for an X default for XPROP
4378 on the frame named NAME.
4379 If that is not found either, use the value DEFLT. */
4381 Lisp_Object
4382 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4383 Lisp_Object deflt, const char *xprop, const char *xclass,
4384 enum resource_types type)
4386 Lisp_Object tem;
4388 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4389 if (EQ (tem, Qunbound))
4390 tem = deflt;
4391 AUTO_FRAME_ARG (arg, prop, tem);
4392 x_set_frame_parameters (f, arg);
4393 return tem;
4397 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4400 * XParseGeometry parses strings of the form
4401 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4402 * width, height, xoffset, and yoffset are unsigned integers.
4403 * Example: "=80x24+300-49"
4404 * The equal sign is optional.
4405 * It returns a bitmask that indicates which of the four values
4406 * were actually found in the string. For each value found,
4407 * the corresponding argument is updated; for each value
4408 * not found, the corresponding argument is left unchanged.
4411 static int
4412 XParseGeometry (char *string,
4413 int *x, int *y,
4414 unsigned int *width, unsigned int *height)
4416 int mask = NoValue;
4417 char *strind;
4418 unsigned long tempWidth, tempHeight;
4419 long int tempX, tempY;
4420 char *nextCharacter;
4422 if (string == NULL || *string == '\0')
4423 return mask;
4424 if (*string == '=')
4425 string++; /* ignore possible '=' at beg of geometry spec */
4427 strind = string;
4428 if (*strind != '+' && *strind != '-' && *strind != 'x')
4430 tempWidth = strtoul (strind, &nextCharacter, 10);
4431 if (strind == nextCharacter)
4432 return 0;
4433 strind = nextCharacter;
4434 mask |= WidthValue;
4437 if (*strind == 'x' || *strind == 'X')
4439 strind++;
4440 tempHeight = strtoul (strind, &nextCharacter, 10);
4441 if (strind == nextCharacter)
4442 return 0;
4443 strind = nextCharacter;
4444 mask |= HeightValue;
4447 if (*strind == '+' || *strind == '-')
4449 if (*strind == '-')
4450 mask |= XNegative;
4451 tempX = strtol (strind, &nextCharacter, 10);
4452 if (strind == nextCharacter)
4453 return 0;
4454 strind = nextCharacter;
4455 mask |= XValue;
4456 if (*strind == '+' || *strind == '-')
4458 if (*strind == '-')
4459 mask |= YNegative;
4460 tempY = strtol (strind, &nextCharacter, 10);
4461 if (strind == nextCharacter)
4462 return 0;
4463 strind = nextCharacter;
4464 mask |= YValue;
4468 /* If strind isn't at the end of the string then it's an invalid
4469 geometry specification. */
4471 if (*strind != '\0')
4472 return 0;
4474 if (mask & XValue)
4475 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4476 if (mask & YValue)
4477 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4478 if (mask & WidthValue)
4479 *width = min (tempWidth, UINT_MAX);
4480 if (mask & HeightValue)
4481 *height = min (tempHeight, UINT_MAX);
4482 return mask;
4485 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4488 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4489 make-docfile: the documentation string in ns-win.el was used for
4490 x-parse-geometry even in non-NS builds.
4492 With two definitions of x-parse-geometry in this file, various
4493 things still get confused (eg M-x apropos documentation), so that
4494 it is best if the two definitions just share the same doc-string.
4496 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4497 doc: /* Parse a display geometry string STRING.
4498 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4499 The properties returned may include `top', `left', `height', and `width'.
4500 For X, the value of `left' or `top' may be an integer,
4501 or a list (+ N) meaning N pixels relative to top/left corner,
4502 or a list (- N) meaning -N pixels relative to bottom/right corner.
4503 On Nextstep, this just calls `ns-parse-geometry'. */)
4504 (Lisp_Object string)
4506 int geometry, x, y;
4507 unsigned int width, height;
4508 Lisp_Object result;
4510 CHECK_STRING (string);
4512 #ifdef HAVE_NS
4513 if (strchr (SSDATA (string), ' ') != NULL)
4514 return call1 (Qns_parse_geometry, string);
4515 #endif
4516 geometry = XParseGeometry (SSDATA (string),
4517 &x, &y, &width, &height);
4518 result = Qnil;
4519 if (geometry & XValue)
4521 Lisp_Object element;
4523 if (x >= 0 && (geometry & XNegative))
4524 element = list3 (Qleft, Qminus, make_number (-x));
4525 else if (x < 0 && ! (geometry & XNegative))
4526 element = list3 (Qleft, Qplus, make_number (x));
4527 else
4528 element = Fcons (Qleft, make_number (x));
4529 result = Fcons (element, result);
4532 if (geometry & YValue)
4534 Lisp_Object element;
4536 if (y >= 0 && (geometry & YNegative))
4537 element = list3 (Qtop, Qminus, make_number (-y));
4538 else if (y < 0 && ! (geometry & YNegative))
4539 element = list3 (Qtop, Qplus, make_number (y));
4540 else
4541 element = Fcons (Qtop, make_number (y));
4542 result = Fcons (element, result);
4545 if (geometry & WidthValue)
4546 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4547 if (geometry & HeightValue)
4548 result = Fcons (Fcons (Qheight, make_number (height)), result);
4550 return result;
4554 /* Calculate the desired size and position of frame F.
4555 Return the flags saying which aspects were specified.
4557 Also set the win_gravity and size_hint_flags of F.
4559 Adjust height for toolbar if TOOLBAR_P is 1.
4561 This function does not make the coordinates positive. */
4563 #define DEFAULT_ROWS 35
4564 #define DEFAULT_COLS 80
4566 long
4567 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
4569 Lisp_Object height, width, user_size, top, left, user_position;
4570 long window_prompting = 0;
4571 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4573 /* Default values if we fall through.
4574 Actually, if that happens we should get
4575 window manager prompting. */
4576 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4577 SET_FRAME_COLS (f, DEFAULT_COLS);
4578 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4579 SET_FRAME_LINES (f, DEFAULT_ROWS);
4581 /* Window managers expect that if program-specified
4582 positions are not (0,0), they're intentional, not defaults. */
4583 f->top_pos = 0;
4584 f->left_pos = 0;
4586 /* Calculate a tool bar height so that the user gets a text display
4587 area of the size he specified with -g or via .Xdefaults. Later
4588 changes of the tool bar height don't change the frame size. This
4589 is done so that users can create tall Emacs frames without having
4590 to guess how tall the tool bar will get. */
4591 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4593 if (frame_default_tool_bar_height)
4594 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
4595 else
4597 int margin, relief;
4599 relief = (tool_bar_button_relief >= 0
4600 ? tool_bar_button_relief
4601 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4603 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4604 margin = XFASTINT (Vtool_bar_button_margin);
4605 else if (CONSP (Vtool_bar_button_margin)
4606 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4607 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4608 else
4609 margin = 0;
4611 FRAME_TOOL_BAR_HEIGHT (f)
4612 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4616 /* Ensure that earlier new_width and new_height settings won't
4617 override what we specify below. */
4618 f->new_width = f->new_height = 0;
4620 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4621 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4622 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4624 if (!EQ (width, Qunbound))
4626 if (CONSP (width) && EQ (XCAR (width), Qtext_pixels))
4628 CHECK_NUMBER (XCDR (width));
4629 if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX))
4630 xsignal1 (Qargs_out_of_range, XCDR (width));
4632 SET_FRAME_WIDTH (f, XINT (XCDR (width)));
4633 f->inhibit_horizontal_resize = true;
4634 *x_width = XINT (XCDR (width));
4636 else
4638 CHECK_NUMBER (width);
4639 if ((XINT (width) < 0 || XINT (width) > INT_MAX))
4640 xsignal1 (Qargs_out_of_range, width);
4642 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4646 if (!EQ (height, Qunbound))
4648 if (CONSP (height) && EQ (XCAR (height), Qtext_pixels))
4650 CHECK_NUMBER (XCDR (height));
4651 if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX))
4652 xsignal1 (Qargs_out_of_range, XCDR (height));
4654 SET_FRAME_HEIGHT (f, XINT (XCDR (height)));
4655 f->inhibit_vertical_resize = true;
4656 *x_height = XINT (XCDR (height));
4658 else
4660 CHECK_NUMBER (height);
4661 if ((XINT (height) < 0) || (XINT (height) > INT_MAX))
4662 xsignal1 (Qargs_out_of_range, height);
4664 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4668 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4669 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4670 window_prompting |= USSize;
4671 else
4672 window_prompting |= PSize;
4675 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4676 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4677 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4678 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4680 if (EQ (top, Qminus))
4682 f->top_pos = 0;
4683 window_prompting |= YNegative;
4685 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4686 && CONSP (XCDR (top))
4687 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4689 f->top_pos = - XINT (XCAR (XCDR (top)));
4690 window_prompting |= YNegative;
4692 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4693 && CONSP (XCDR (top))
4694 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4696 f->top_pos = XINT (XCAR (XCDR (top)));
4698 else if (EQ (top, Qunbound))
4699 f->top_pos = 0;
4700 else
4702 CHECK_TYPE_RANGED_INTEGER (int, top);
4703 f->top_pos = XINT (top);
4704 if (f->top_pos < 0)
4705 window_prompting |= YNegative;
4708 if (EQ (left, Qminus))
4710 f->left_pos = 0;
4711 window_prompting |= XNegative;
4713 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4714 && CONSP (XCDR (left))
4715 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4717 f->left_pos = - XINT (XCAR (XCDR (left)));
4718 window_prompting |= XNegative;
4720 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4721 && CONSP (XCDR (left))
4722 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4724 f->left_pos = XINT (XCAR (XCDR (left)));
4726 else if (EQ (left, Qunbound))
4727 f->left_pos = 0;
4728 else
4730 CHECK_TYPE_RANGED_INTEGER (int, left);
4731 f->left_pos = XINT (left);
4732 if (f->left_pos < 0)
4733 window_prompting |= XNegative;
4736 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4737 window_prompting |= USPosition;
4738 else
4739 window_prompting |= PPosition;
4742 if (window_prompting & XNegative)
4744 if (window_prompting & YNegative)
4745 f->win_gravity = SouthEastGravity;
4746 else
4747 f->win_gravity = NorthEastGravity;
4749 else
4751 if (window_prompting & YNegative)
4752 f->win_gravity = SouthWestGravity;
4753 else
4754 f->win_gravity = NorthWestGravity;
4757 f->size_hint_flags = window_prompting;
4759 return window_prompting;
4764 #endif /* HAVE_WINDOW_SYSTEM */
4766 void
4767 frame_make_pointer_invisible (struct frame *f)
4769 if (! NILP (Vmake_pointer_invisible))
4771 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4772 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4774 f->mouse_moved = 0;
4775 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4776 f->pointer_invisible = 1;
4781 void
4782 frame_make_pointer_visible (struct frame *f)
4784 /* We don't check Vmake_pointer_invisible here in case the
4785 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4786 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4787 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4789 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4790 f->pointer_invisible = 0;
4794 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4795 Sframe_pointer_visible_p, 0, 1, 0,
4796 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4797 Otherwise it returns nil. FRAME omitted or nil means the
4798 selected frame. This is useful when `make-pointer-invisible' is set. */)
4799 (Lisp_Object frame)
4801 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4806 /***********************************************************************
4807 Multimonitor data
4808 ***********************************************************************/
4810 #ifdef HAVE_WINDOW_SYSTEM
4812 # if (defined HAVE_NS \
4813 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4814 void
4815 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4817 int i;
4818 for (i = 0; i < n_monitors; ++i)
4819 xfree (monitors[i].name);
4820 xfree (monitors);
4822 # endif
4824 Lisp_Object
4825 make_monitor_attribute_list (struct MonitorInfo *monitors,
4826 int n_monitors,
4827 int primary_monitor,
4828 Lisp_Object monitor_frames,
4829 const char *source)
4831 Lisp_Object attributes_list = Qnil;
4832 Lisp_Object primary_monitor_attributes = Qnil;
4833 int i;
4835 for (i = 0; i < n_monitors; ++i)
4837 Lisp_Object geometry, workarea, attributes = Qnil;
4838 struct MonitorInfo *mi = &monitors[i];
4840 if (mi->geom.width == 0) continue;
4842 workarea = list4i (mi->work.x, mi->work.y,
4843 mi->work.width, mi->work.height);
4844 geometry = list4i (mi->geom.x, mi->geom.y,
4845 mi->geom.width, mi->geom.height);
4846 attributes = Fcons (Fcons (Qsource, build_string (source)),
4847 attributes);
4848 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4849 attributes);
4850 attributes = Fcons (Fcons (Qmm_size,
4851 list2i (mi->mm_width, mi->mm_height)),
4852 attributes);
4853 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4854 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4855 if (mi->name)
4856 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4857 strlen (mi->name))),
4858 attributes);
4860 if (i == primary_monitor)
4861 primary_monitor_attributes = attributes;
4862 else
4863 attributes_list = Fcons (attributes, attributes_list);
4866 if (!NILP (primary_monitor_attributes))
4867 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4868 return attributes_list;
4871 #endif /* HAVE_WINDOW_SYSTEM */
4874 /***********************************************************************
4875 Initialization
4876 ***********************************************************************/
4878 void
4879 syms_of_frame (void)
4881 DEFSYM (Qframep, "framep");
4882 DEFSYM (Qframe_live_p, "frame-live-p");
4883 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4884 DEFSYM (Qwindow_pixel_to_total, "window--pixel-to-total");
4885 DEFSYM (Qexplicit_name, "explicit-name");
4886 DEFSYM (Qheight, "height");
4887 DEFSYM (Qicon, "icon");
4888 DEFSYM (Qminibuffer, "minibuffer");
4889 DEFSYM (Qmodeline, "modeline");
4890 DEFSYM (Qonly, "only");
4891 DEFSYM (Qnone, "none");
4892 DEFSYM (Qwidth, "width");
4893 DEFSYM (Qtext_pixels, "text-pixels");
4894 DEFSYM (Qgeometry, "geometry");
4895 DEFSYM (Qicon_left, "icon-left");
4896 DEFSYM (Qicon_top, "icon-top");
4897 DEFSYM (Qtooltip, "tooltip");
4898 DEFSYM (Quser_position, "user-position");
4899 DEFSYM (Quser_size, "user-size");
4900 DEFSYM (Qwindow_id, "window-id");
4901 #ifdef HAVE_X_WINDOWS
4902 DEFSYM (Qouter_window_id, "outer-window-id");
4903 #endif
4904 DEFSYM (Qparent_id, "parent-id");
4905 DEFSYM (Qx, "x");
4906 DEFSYM (Qw32, "w32");
4907 DEFSYM (Qpc, "pc");
4908 DEFSYM (Qns, "ns");
4909 DEFSYM (Qvisible, "visible");
4910 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4911 DEFSYM (Qbuffer_list, "buffer-list");
4912 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4913 DEFSYM (Qdisplay_type, "display-type");
4914 DEFSYM (Qbackground_mode, "background-mode");
4915 DEFSYM (Qnoelisp, "noelisp");
4916 DEFSYM (Qtty_color_mode, "tty-color-mode");
4917 DEFSYM (Qtty, "tty");
4918 DEFSYM (Qtty_type, "tty-type");
4920 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4922 DEFSYM (Qfullwidth, "fullwidth");
4923 DEFSYM (Qfullheight, "fullheight");
4924 DEFSYM (Qfullboth, "fullboth");
4925 DEFSYM (Qmaximized, "maximized");
4926 DEFSYM (Qx_resource_name, "x-resource-name");
4927 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4929 DEFSYM (Qterminal, "terminal");
4931 DEFSYM (Qworkarea, "workarea");
4932 DEFSYM (Qmm_size, "mm-size");
4933 DEFSYM (Qframes, "frames");
4934 DEFSYM (Qsource, "source");
4936 DEFSYM (Qouter_edges, "outer-edges");
4937 DEFSYM (Qouter_position, "outer-position");
4938 DEFSYM (Qouter_size, "outer-size");
4939 DEFSYM (Qnative_edges, "native-edges");
4940 DEFSYM (Qinner_edges, "inner-edges");
4941 DEFSYM (Qexternal_border_size, "external-border-size");
4942 DEFSYM (Qtitle_bar_size, "title-bar-size");
4943 DEFSYM (Qmenu_bar_external, "menu-bar-external");
4944 DEFSYM (Qmenu_bar_size, "menu-bar-size");
4945 DEFSYM (Qtool_bar_external, "tool-bar-external");
4946 DEFSYM (Qtool_bar_size, "tool-bar-size");
4947 /* The following are used for frame_size_history. */
4948 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
4949 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
4950 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
4951 DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
4952 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
4953 DEFSYM (Qset_frame_size, "set-frame-size");
4954 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
4955 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
4956 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
4957 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
4958 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
4959 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
4960 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
4961 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
4962 DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
4963 DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
4964 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
4965 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
4966 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
4967 DEFSYM (Qtb_size_cb, "tb-size-cb");
4968 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
4969 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
4970 DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines");
4971 DEFSYM (Qchange_frame_size, "change-frame-size");
4972 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
4973 DEFSYM (Qset_window_configuration, "set-window-configuration");
4974 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
4975 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
4976 DEFSYM (Qterminal_frame, "terminal-frame");
4978 #ifdef HAVE_NS
4979 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4980 #endif
4982 DEFSYM (Qalpha, "alpha");
4983 DEFSYM (Qauto_lower, "auto-lower");
4984 DEFSYM (Qauto_raise, "auto-raise");
4985 DEFSYM (Qborder_color, "border-color");
4986 DEFSYM (Qborder_width, "border-width");
4987 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
4988 DEFSYM (Qcursor_color, "cursor-color");
4989 DEFSYM (Qcursor_type, "cursor-type");
4990 DEFSYM (Qfont_backend, "font-backend");
4991 DEFSYM (Qfullscreen, "fullscreen");
4992 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
4993 DEFSYM (Qicon_name, "icon-name");
4994 DEFSYM (Qicon_type, "icon-type");
4995 DEFSYM (Qinternal_border_width, "internal-border-width");
4996 DEFSYM (Qleft_fringe, "left-fringe");
4997 DEFSYM (Qline_spacing, "line-spacing");
4998 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
4999 DEFSYM (Qupdate_frame_menubar, "update-frame-menubar");
5000 DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1");
5001 DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2");
5002 DEFSYM (Qmouse_color, "mouse-color");
5003 DEFSYM (Qname, "name");
5004 DEFSYM (Qright_divider_width, "right-divider-width");
5005 DEFSYM (Qright_fringe, "right-fringe");
5006 DEFSYM (Qscreen_gamma, "screen-gamma");
5007 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
5008 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
5009 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
5010 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
5011 DEFSYM (Qsticky, "sticky");
5012 DEFSYM (Qtitle, "title");
5013 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
5014 DEFSYM (Qtool_bar_position, "tool-bar-position");
5015 DEFSYM (Qunsplittable, "unsplittable");
5016 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
5017 DEFSYM (Qvisibility, "visibility");
5018 DEFSYM (Qwait_for_wm, "wait-for-wm");
5021 int i;
5023 for (i = 0; i < ARRAYELTS (frame_parms); i++)
5025 Lisp_Object v = (frame_parms[i].sym < 0
5026 ? intern_c_string (frame_parms[i].name)
5027 : builtin_lisp_symbol (frame_parms[i].sym));
5028 Fput (v, Qx_frame_parameter, make_number (i));
5032 #ifdef HAVE_WINDOW_SYSTEM
5033 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
5034 doc: /* The name Emacs uses to look up X resources.
5035 `x-get-resource' uses this as the first component of the instance name
5036 when requesting resource values.
5037 Emacs initially sets `x-resource-name' to the name under which Emacs
5038 was invoked, or to the value specified with the `-name' or `-rn'
5039 switches, if present.
5041 It may be useful to bind this variable locally around a call
5042 to `x-get-resource'. See also the variable `x-resource-class'. */);
5043 Vx_resource_name = Qnil;
5045 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5046 doc: /* The class Emacs uses to look up X resources.
5047 `x-get-resource' uses this as the first component of the instance class
5048 when requesting resource values.
5050 Emacs initially sets `x-resource-class' to "Emacs".
5052 Setting this variable permanently is not a reasonable thing to do,
5053 but binding this variable locally around a call to `x-get-resource'
5054 is a reasonable practice. See also the variable `x-resource-name'. */);
5055 Vx_resource_class = build_string (EMACS_CLASS);
5057 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5058 doc: /* The lower limit of the frame opacity (alpha transparency).
5059 The value should range from 0 (invisible) to 100 (completely opaque).
5060 You can also use a floating number between 0.0 and 1.0. */);
5061 Vframe_alpha_lower_limit = make_number (20);
5062 #endif
5064 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5065 doc: /* Alist of default values for frame creation.
5066 These may be set in your init file, like this:
5067 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5068 These override values given in window system configuration data,
5069 including X Windows' defaults database.
5070 For values specific to the first Emacs frame, see `initial-frame-alist'.
5071 For window-system specific values, see `window-system-default-frame-alist'.
5072 For values specific to the separate minibuffer frame, see
5073 `minibuffer-frame-alist'.
5074 The `menu-bar-lines' element of the list controls whether new frames
5075 have menu bars; `menu-bar-mode' works by altering this element.
5076 Setting this variable does not affect existing frames, only new ones. */);
5077 Vdefault_frame_alist = Qnil;
5079 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5080 doc: /* Default position of vertical scroll bars on this window-system. */);
5081 #ifdef HAVE_WINDOW_SYSTEM
5082 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5083 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
5084 default. */
5085 Vdefault_frame_scroll_bars = Qright;
5086 #else
5087 Vdefault_frame_scroll_bars = Qleft;
5088 #endif
5089 #else
5090 Vdefault_frame_scroll_bars = Qnil;
5091 #endif
5093 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5094 scroll_bar_adjust_thumb_portion_p,
5095 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5096 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5097 even if the end of the buffer is shown (i.e. overscrolling).
5098 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5099 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5100 is visible. In this case you can not overscroll. */);
5101 scroll_bar_adjust_thumb_portion_p = 1;
5103 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5104 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5106 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5107 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5108 `mouse-position' and `mouse-pixel-position' call this function, passing their
5109 usual return value as argument, and return whatever this function returns.
5110 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5111 which need to do mouse handling at the Lisp level. */);
5112 Vmouse_position_function = Qnil;
5114 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5115 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5116 If the value is an integer, highlighting is only shown after moving the
5117 mouse, while keyboard input turns off the highlight even when the mouse
5118 is over the clickable text. However, the mouse shape still indicates
5119 when the mouse is over clickable text. */);
5120 Vmouse_highlight = Qt;
5122 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5123 doc: /* If non-nil, make pointer invisible while typing.
5124 The pointer becomes visible again when the mouse is moved. */);
5125 Vmake_pointer_invisible = Qt;
5127 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5128 doc: /* Normal hook run when a frame gains input focus. */);
5129 Vfocus_in_hook = Qnil;
5131 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5132 doc: /* Normal hook run when a frame loses input focus. */);
5133 Vfocus_out_hook = Qnil;
5135 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5136 doc: /* Functions run before deleting a frame.
5137 The functions are run with one arg, the frame to be deleted.
5138 See `delete-frame'.
5140 Note that functions in this list may be called just before the frame is
5141 actually deleted, or some time later (or even both when an earlier function
5142 in `delete-frame-functions' (indirectly) calls `delete-frame'
5143 recursively). */);
5144 Vdelete_frame_functions = Qnil;
5145 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5147 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5148 doc: /* Non-nil if Menu-Bar mode is enabled.
5149 See the command `menu-bar-mode' for a description of this minor mode.
5150 Setting this variable directly does not take effect;
5151 either customize it (see the info node `Easy Customization')
5152 or call the function `menu-bar-mode'. */);
5153 Vmenu_bar_mode = Qt;
5155 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5156 doc: /* Non-nil if Tool-Bar mode is enabled.
5157 See the command `tool-bar-mode' for a description of this minor mode.
5158 Setting this variable directly does not take effect;
5159 either customize it (see the info node `Easy Customization')
5160 or call the function `tool-bar-mode'. */);
5161 #ifdef HAVE_WINDOW_SYSTEM
5162 Vtool_bar_mode = Qt;
5163 #else
5164 Vtool_bar_mode = Qnil;
5165 #endif
5167 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5168 doc: /* Minibufferless frames use this frame's minibuffer.
5169 Emacs cannot create minibufferless frames unless this is set to an
5170 appropriate surrogate.
5172 Emacs consults this variable only when creating minibufferless
5173 frames; once the frame is created, it sticks with its assigned
5174 minibuffer, no matter what this variable is set to. This means that
5175 this variable doesn't necessarily say anything meaningful about the
5176 current set of frames, or where the minibuffer is currently being
5177 displayed.
5179 This variable is local to the current terminal and cannot be buffer-local. */);
5181 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
5182 doc: /* Non-nil if window system changes focus when you move the mouse.
5183 You should set this variable to tell Emacs how your window manager
5184 handles focus, since there is no way in general for Emacs to find out
5185 automatically. See also `mouse-autoselect-window'. */);
5186 focus_follows_mouse = 0;
5188 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5189 doc: /* Non-nil means resize frames pixelwise.
5190 If this option is nil, resizing a frame rounds its sizes to the frame's
5191 current values of `frame-char-height' and `frame-char-width'. If this
5192 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5193 by one pixel.
5195 With some window managers you may have to set this to non-nil in order
5196 to set the size of a frame in pixels, to maximize frames or to make them
5197 fullscreen. To resize your initial frame pixelwise, set this option to
5198 a non-nil value in your init file. */);
5199 frame_resize_pixelwise = 0;
5201 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5202 doc: /* Whether frames should be resized implicitly.
5203 If this option is nil, setting font, menu bar, tool bar, internal
5204 borders, fringes or scroll bars of a specific frame may resize the frame
5205 in order to preserve the number of columns or lines it displays. If
5206 this option is t, no such resizing is done. Note that the size of
5207 fullscreen and maximized frames, the height of fullheight frames and the
5208 width of fullwidth frames never change implicitly.
5210 The value of this option can be also be a list of frame parameters. In
5211 this case, resizing is inhibited when changing a parameter that appears
5212 in that list. The parameters currently handled by this option include
5213 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5214 `tool-bar-lines'.
5216 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5217 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5218 `right-fringe' is handled as if the frame contained just one live
5219 window. This means, for example, that removing vertical scroll bars on
5220 a frame containing several side by side windows will shrink the frame
5221 width by the width of one scroll bar provided this option is nil and
5222 keep it unchanged if this option is either t or a list containing
5223 `vertical-scroll-bars'.
5225 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
5226 (which means that adding/removing a tool bar does not change the frame
5227 height), nil on all other window systems including GTK+ (which means
5228 that changing any of the parameters listed above may change the size of
5229 the frame), and t otherwise (which means the frame size never changes
5230 implicitly when there's no window system support).
5232 Note that when a frame is not large enough to accommodate a change of
5233 any of the parameters listed above, Emacs may try to enlarge the frame
5234 even if this option is non-nil. */);
5235 #if defined (HAVE_WINDOW_SYSTEM)
5236 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
5237 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
5238 #else
5239 frame_inhibit_implied_resize = Qnil;
5240 #endif
5241 #else
5242 frame_inhibit_implied_resize = Qt;
5243 #endif
5245 DEFVAR_LISP ("frame-size-history", frame_size_history,
5246 doc: /* History of frame size adjustments.
5247 If non-nil, list recording frame size adjustment. Adjustments are
5248 recorded only if the first element of this list is a positive number.
5249 Adding an adjustment decrements that number by one.
5251 The remaining elements are the adjustments. Each adjustment is a list
5252 of four elements `frame', `function', `sizes' and `more'. `frame' is
5253 the affected frame and `function' the invoking function. `sizes' is
5254 usually a list of four elements `old-width', `old-height', `new-width'
5255 and `new-height' representing the old and new sizes recorded/requested
5256 by `function'. `more' is a list with additional information.
5258 The function `frame--size-history' displays the value of this variable
5259 in a more readable form. */);
5260 frame_size_history = Qnil;
5262 staticpro (&Vframe_list);
5264 defsubr (&Sframep);
5265 defsubr (&Sframe_live_p);
5266 defsubr (&Swindow_system);
5267 defsubr (&Sframe_windows_min_size);
5268 defsubr (&Smake_terminal_frame);
5269 defsubr (&Shandle_switch_frame);
5270 defsubr (&Sselect_frame);
5271 defsubr (&Sselected_frame);
5272 defsubr (&Sframe_list);
5273 defsubr (&Snext_frame);
5274 defsubr (&Sprevious_frame);
5275 defsubr (&Slast_nonminibuf_frame);
5276 defsubr (&Sdelete_frame);
5277 defsubr (&Smouse_position);
5278 defsubr (&Smouse_pixel_position);
5279 defsubr (&Sset_mouse_position);
5280 defsubr (&Sset_mouse_pixel_position);
5281 #if 0
5282 defsubr (&Sframe_configuration);
5283 defsubr (&Srestore_frame_configuration);
5284 #endif
5285 defsubr (&Smake_frame_visible);
5286 defsubr (&Smake_frame_invisible);
5287 defsubr (&Siconify_frame);
5288 defsubr (&Sframe_visible_p);
5289 defsubr (&Svisible_frame_list);
5290 defsubr (&Sraise_frame);
5291 defsubr (&Slower_frame);
5292 defsubr (&Sx_focus_frame);
5293 defsubr (&Sframe_after_make_frame);
5294 defsubr (&Sredirect_frame_focus);
5295 defsubr (&Sframe_focus);
5296 defsubr (&Sframe_parameters);
5297 defsubr (&Sframe_parameter);
5298 defsubr (&Smodify_frame_parameters);
5299 defsubr (&Sframe_char_height);
5300 defsubr (&Sframe_char_width);
5301 defsubr (&Sframe_pixel_height);
5302 defsubr (&Sframe_pixel_width);
5303 defsubr (&Sframe_text_cols);
5304 defsubr (&Sframe_text_lines);
5305 defsubr (&Sframe_total_cols);
5306 defsubr (&Sframe_total_lines);
5307 defsubr (&Sframe_text_width);
5308 defsubr (&Sframe_text_height);
5309 defsubr (&Sscroll_bar_width);
5310 defsubr (&Sscroll_bar_height);
5311 defsubr (&Sfringe_width);
5312 defsubr (&Sborder_width);
5313 defsubr (&Sright_divider_width);
5314 defsubr (&Sbottom_divider_width);
5315 defsubr (&Stool_bar_pixel_width);
5316 defsubr (&Sset_frame_height);
5317 defsubr (&Sset_frame_width);
5318 defsubr (&Sset_frame_size);
5319 defsubr (&Sframe_position);
5320 defsubr (&Sset_frame_position);
5321 defsubr (&Sframe_pointer_visible_p);
5323 #ifdef HAVE_WINDOW_SYSTEM
5324 defsubr (&Sx_get_resource);
5325 defsubr (&Sx_parse_geometry);
5326 #endif