Allow setting frame pixel sizes from frame parameters (Bug#21415)
[emacs.git] / src / frame.c
blob98a7a57a98817f6adaf94aae97d4c85e300264bf
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2015 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <errno.h>
24 #include <limits.h>
26 #include <c-ctype.h>
28 #include "lisp.h"
29 #include "character.h"
31 #ifdef HAVE_WINDOW_SYSTEM
32 #include TERM_HEADER
33 #endif /* HAVE_WINDOW_SYSTEM */
35 #include "buffer.h"
36 /* These help us bind and responding to switch-frame events. */
37 #include "commands.h"
38 #include "keyboard.h"
39 #include "frame.h"
40 #include "blockinput.h"
41 #include "termchar.h"
42 #include "termhooks.h"
43 #include "dispextern.h"
44 #include "window.h"
45 #include "font.h"
46 #ifdef HAVE_WINDOW_SYSTEM
47 #include "fontset.h"
48 #endif
49 #include "cm.h"
50 #ifdef MSDOS
51 #include "msdos.h"
52 #include "dosfns.h"
53 #endif
54 #ifdef USE_X_TOOLKIT
55 #include "widget.h"
56 #endif
58 /* The currently selected frame. */
60 Lisp_Object selected_frame;
62 /* A frame which is not just a mini-buffer, or NULL if there are no such
63 frames. This is usually the most recent such frame that was selected. */
65 static struct frame *last_nonminibuf_frame;
67 /* False means there are no visible garbaged frames. */
68 bool frame_garbaged;
70 /* The default tool bar height for future frames. */
71 #if defined USE_GTK || defined HAVE_NS
72 enum { frame_default_tool_bar_height = 0 };
73 #else
74 int frame_default_tool_bar_height;
75 #endif
77 #ifdef HAVE_WINDOW_SYSTEM
78 static void x_report_frame_params (struct frame *, Lisp_Object *);
79 #endif
81 /* These setters are used only in this file, so they can be private. */
82 static void
83 fset_buffer_predicate (struct frame *f, Lisp_Object val)
85 f->buffer_predicate = val;
87 static void
88 fset_minibuffer_window (struct frame *f, Lisp_Object val)
90 f->minibuffer_window = val;
93 struct frame *
94 decode_live_frame (register Lisp_Object frame)
96 if (NILP (frame))
97 frame = selected_frame;
98 CHECK_LIVE_FRAME (frame);
99 return XFRAME (frame);
102 struct frame *
103 decode_any_frame (register Lisp_Object frame)
105 if (NILP (frame))
106 frame = selected_frame;
107 CHECK_FRAME (frame);
108 return XFRAME (frame);
111 #ifdef HAVE_WINDOW_SYSTEM
113 bool
114 window_system_available (struct frame *f)
116 return f ? FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f) : x_display_list != NULL;
119 #endif /* HAVE_WINDOW_SYSTEM */
121 struct frame *
122 decode_window_system_frame (Lisp_Object frame)
124 struct frame *f = decode_live_frame (frame);
126 if (!window_system_available (f))
127 error ("Window system frame should be used");
128 return f;
131 void
132 check_window_system (struct frame *f)
134 if (!window_system_available (f))
135 error (f ? "Window system frame should be used"
136 : "Window system is not in use or not initialized");
139 /* Return the value of frame parameter PROP in frame FRAME. */
141 Lisp_Object
142 get_frame_param (register struct frame *frame, Lisp_Object prop)
144 register Lisp_Object tem;
146 tem = Fassq (prop, frame->param_alist);
147 if (EQ (tem, Qnil))
148 return tem;
149 return Fcdr (tem);
153 void
154 frame_size_history_add (struct frame *f, Lisp_Object fun_symbol,
155 int width, int height, Lisp_Object rest)
157 Lisp_Object frame;
159 XSETFRAME (frame, f);
160 if (CONSP (frame_size_history)
161 && INTEGERP (XCAR (frame_size_history))
162 && 0 < XINT (XCAR (frame_size_history)))
163 frame_size_history =
164 Fcons (make_number (XINT (XCAR (frame_size_history)) - 1),
165 Fcons (list4
166 (frame, fun_symbol,
167 ((width > 0)
168 ? list4 (make_number (FRAME_TEXT_WIDTH (f)),
169 make_number (FRAME_TEXT_HEIGHT (f)),
170 make_number (width),
171 make_number (height))
172 : Qnil),
173 rest),
174 XCDR (frame_size_history)));
178 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
179 state of frame F would be affected by a vertical (horizontal if
180 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
181 parameter that is changed. */
182 bool
183 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
185 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
186 bool inhibit
187 = (f->after_make_frame
188 ? (EQ (frame_inhibit_implied_resize, Qt)
189 || (CONSP (frame_inhibit_implied_resize)
190 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))
191 || (horizontal
192 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight))
193 || (!horizontal
194 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth))
195 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
196 : ((horizontal && f->inhibit_horizontal_resize)
197 || (!horizontal && f->inhibit_vertical_resize)));
198 if (inhibit && !FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
199 frame_size_history_add
200 (f, Qframe_inhibit_resize, 0, 0,
201 list5 (horizontal ? Qt : Qnil, parameter,
202 f->after_make_frame ? Qt : Qnil,
203 frame_inhibit_implied_resize,
204 fullscreen));
206 return inhibit;
209 static void
210 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
212 int nlines;
213 int olines = FRAME_MENU_BAR_LINES (f);
215 /* Right now, menu bars don't work properly in minibuf-only frames;
216 most of the commands try to apply themselves to the minibuffer
217 frame itself, and get an error because you can't switch buffers
218 in or split the minibuffer window. */
219 if (FRAME_MINIBUF_ONLY_P (f))
220 return;
222 if (TYPE_RANGED_INTEGERP (int, value))
223 nlines = XINT (value);
224 else
225 nlines = 0;
227 if (nlines != olines)
229 windows_or_buffers_changed = 14;
230 FRAME_MENU_BAR_LINES (f) = nlines;
231 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
232 change_frame_size (f, FRAME_COLS (f),
233 FRAME_LINES (f) + olines - nlines,
234 0, 1, 0, 0);
238 Lisp_Object Vframe_list;
241 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
242 doc: /* Return non-nil if OBJECT is a frame.
243 Value is:
244 t for a termcap frame (a character-only terminal),
245 'x' for an Emacs frame that is really an X window,
246 'w32' for an Emacs frame that is a window on MS-Windows display,
247 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
248 'pc' for a direct-write MS-DOS frame.
249 See also `frame-live-p'. */)
250 (Lisp_Object object)
252 if (!FRAMEP (object))
253 return Qnil;
254 switch (XFRAME (object)->output_method)
256 case output_initial: /* The initial frame is like a termcap frame. */
257 case output_termcap:
258 return Qt;
259 case output_x_window:
260 return Qx;
261 case output_w32:
262 return Qw32;
263 case output_msdos_raw:
264 return Qpc;
265 case output_ns:
266 return Qns;
267 default:
268 emacs_abort ();
272 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
273 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
274 Value is nil if OBJECT is not a live frame. If object is a live
275 frame, the return value indicates what sort of terminal device it is
276 displayed on. See the documentation of `framep' for possible
277 return values. */)
278 (Lisp_Object object)
280 return ((FRAMEP (object)
281 && FRAME_LIVE_P (XFRAME (object)))
282 ? Fframep (object)
283 : Qnil);
286 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
287 doc: /* The name of the window system that FRAME is displaying through.
288 The value is a symbol:
289 nil for a termcap frame (a character-only terminal),
290 'x' for an Emacs frame that is really an X window,
291 'w32' for an Emacs frame that is a window on MS-Windows display,
292 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
293 'pc' for a direct-write MS-DOS frame.
295 FRAME defaults to the currently selected frame.
297 Use of this function as a predicate is deprecated. Instead,
298 use `display-graphic-p' or any of the other `display-*-p'
299 predicates which report frame's specific UI-related capabilities. */)
300 (Lisp_Object frame)
302 Lisp_Object type;
303 if (NILP (frame))
304 frame = selected_frame;
306 type = Fframep (frame);
308 if (NILP (type))
309 wrong_type_argument (Qframep, frame);
311 if (EQ (type, Qt))
312 return Qnil;
313 else
314 return type;
317 /* Placeholder used by temacs -nw before window.el is loaded. */
318 DEFUN ("frame-windows-min-size", Fframe_windows_min_size,
319 Sframe_windows_min_size, 4, 4, 0,
320 doc: /* */
321 attributes: const)
322 (Lisp_Object frame, Lisp_Object horizontal,
323 Lisp_Object ignore, Lisp_Object pixelwise)
325 return make_number (0);
328 static int
329 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal,
330 Lisp_Object ignore, Lisp_Object pixelwise)
332 return XINT (call4 (Qframe_windows_min_size, frame, horizontal,
333 ignore, pixelwise));
337 /* Make sure windows sizes of frame F are OK. new_width and new_height
338 are in pixels. A value of -1 means no change is requested for that
339 size (but the frame may still have to be resized to accommodate
340 windows with their minimum sizes). This can either issue a request
341 to resize the frame externally (via x_set_window_size), to resize the
342 frame internally (via resize_frame_windows) or do nothing at all.
344 The argument INHIBIT can assume the following values:
346 0 means to unconditionally call x_set_window_size even if sizes
347 apparently do not change. Fx_create_frame uses this to pass the
348 initial size to the window manager.
350 1 means to call x_set_window_size if the outer frame size really
351 changes. Fset_frame_size, Fset_frame_height, ... use this.
353 2 means to call x_set_window_size provided frame_inhibit_resize
354 allows it. The menu and tool bar code use this ("3" won't work
355 here in general because menu and tool bar are often not counted in
356 the frame's text height).
358 3 means call x_set_window_size if window minimum sizes must be
359 preserved or frame_inhibit_resize allows it. x_set_left_fringe,
360 x_set_scroll_bar_width, x_new_font ... use (or should use) this.
362 4 means call x_set_window_size only if window minimum sizes must be
363 preserved. x_set_right_divider_width, x_set_border_width and the
364 code responsible for wrapping the tool bar use this.
366 5 means to never call x_set_window_size. change_frame_size uses
367 this.
369 Note that even when x_set_window_size is not called, individual
370 windows may have to be resized (via `window--sanitize-window-sizes')
371 in order to support minimum size constraints.
373 PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the
374 symbol of the parameter changed (like `menu-bar-lines', `font', ...).
375 This is passed on to frame_inhibit_resize to let the latter decide on
376 a case-by-case basis whether the frame may be resized externally. */
377 void
378 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
379 bool pretend, Lisp_Object parameter)
381 int unit_width = FRAME_COLUMN_WIDTH (f);
382 int unit_height = FRAME_LINE_HEIGHT (f);
383 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
384 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
385 int old_cols = FRAME_COLS (f);
386 int old_lines = FRAME_LINES (f);
387 int new_pixel_width, new_pixel_height;
388 /* The following two values are calculated from the old frame pixel
389 sizes and any "new" settings for tool bar, menu bar and internal
390 borders. We do it this way to detect whether we have to call
391 x_set_window_size as consequence of the new settings. */
392 int windows_width = FRAME_WINDOWS_WIDTH (f);
393 int windows_height = FRAME_WINDOWS_HEIGHT (f);
394 int min_windows_width, min_windows_height;
395 /* These are a bit tedious, maybe we should use a macro. */
396 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
397 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
398 int old_windows_height
399 = (WINDOW_PIXEL_HEIGHT (r)
400 + ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
401 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
402 : 0));
403 int new_windows_width, new_windows_height;
404 int old_text_width = FRAME_TEXT_WIDTH (f);
405 int old_text_height = FRAME_TEXT_HEIGHT (f);
406 /* If a size is < 0 use the old value. */
407 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
408 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
409 int new_cols, new_lines;
410 bool inhibit_horizontal, inhibit_vertical;
411 Lisp_Object frame;
413 XSETFRAME (frame, f);
415 frame_size_history_add
416 (f, Qadjust_frame_size_1, new_text_width, new_text_height,
417 list2 (parameter, make_number (inhibit)));
419 /* The following two values are calculated from the old window body
420 sizes and any "new" settings for scroll bars, dividers, fringes and
421 margins (though the latter should have been processed already). */
422 min_windows_width
423 = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qt : Qnil, Qt);
424 min_windows_height
425 = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qt : Qnil, Qt);
427 if (inhibit >= 2 && inhibit <= 4)
428 /* When INHIBIT is in [2..4] inhibit if the "old" window sizes stay
429 within the limits and either resizing is inhibited or INHIBIT
430 equals 4. */
432 inhibit_horizontal = (windows_width >= min_windows_width
433 && (inhibit == 4
434 || frame_inhibit_resize (f, true, parameter)));
435 inhibit_vertical = (windows_height >= min_windows_height
436 && (inhibit == 4
437 || frame_inhibit_resize (f, false, parameter)));
439 else
440 /* Otherwise inhibit if INHIBIT equals 5. */
441 inhibit_horizontal = inhibit_vertical = inhibit == 5;
443 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
444 ? old_pixel_width
445 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
446 min_windows_width
447 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
448 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
449 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
450 new_cols = new_text_width / unit_width;
452 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
453 ? old_pixel_height
454 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
455 min_windows_height
456 + FRAME_TOP_MARGIN_HEIGHT (f)
457 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
458 new_windows_height = (new_pixel_height
459 - FRAME_TOP_MARGIN_HEIGHT (f)
460 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
461 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
462 new_lines = new_text_height / unit_height;
464 #ifdef HAVE_WINDOW_SYSTEM
465 if (FRAME_WINDOW_P (f)
466 && f->can_x_set_window_size
467 && ((!inhibit_horizontal
468 && (new_pixel_width != old_pixel_width
469 || inhibit == 0 || inhibit == 2))
470 || (!inhibit_vertical
471 && (new_pixel_height != old_pixel_height
472 || inhibit == 0 || inhibit == 2))))
473 /* We are either allowed to change the frame size or the minimum
474 sizes request such a change. Do not care for fixing minimum
475 sizes here, we do that eventually when we're called from
476 change_frame_size. */
478 /* Make sure we respect fullheight and fullwidth. */
479 if (inhibit_horizontal)
480 new_text_width = old_text_width;
481 else if (inhibit_vertical)
482 new_text_height = old_text_height;
484 frame_size_history_add
485 (f, Qadjust_frame_size_2, new_text_width, new_text_height,
486 list2 (inhibit_horizontal ? Qt : Qnil,
487 inhibit_vertical ? Qt : Qnil));
489 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
490 f->resized_p = true;
492 return;
494 #endif
496 if (new_text_width == old_text_width
497 && new_text_height == old_text_height
498 && new_windows_width == old_windows_width
499 && new_windows_height == old_windows_height
500 && new_pixel_width == old_pixel_width
501 && new_pixel_height == old_pixel_height
502 && new_cols == old_cols
503 && new_lines == old_lines)
504 /* No change. Sanitize window sizes and return. */
506 sanitize_window_sizes (frame, Qt);
507 sanitize_window_sizes (frame, Qnil);
509 return;
512 block_input ();
514 #ifdef MSDOS
515 /* We only can set screen dimensions to certain values supported
516 by our video hardware. Try to find the smallest size greater
517 or equal to the requested dimensions. */
518 dos_set_window_size (&new_lines, &new_cols);
519 #endif
521 if (new_windows_width != old_windows_width)
523 resize_frame_windows (f, new_windows_width, 1, 1);
525 /* MSDOS frames cannot PRETEND, as they change frame size by
526 manipulating video hardware. */
527 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
528 FrameCols (FRAME_TTY (f)) = new_cols;
530 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
531 if (WINDOWP (f->tool_bar_window))
533 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
534 XWINDOW (f->tool_bar_window)->total_cols
535 = new_windows_width / unit_width;
537 #endif
539 else if (new_cols != old_cols)
540 call2 (Qwindow_pixel_to_total, frame, Qt);
542 if (new_windows_height != old_windows_height
543 /* When the top margin has changed we have to recalculate the top
544 edges of all windows. No such calculation is necessary for the
545 left edges. */
546 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
548 resize_frame_windows (f, new_windows_height, 0, 1);
550 /* MSDOS frames cannot PRETEND, as they change frame size by
551 manipulating video hardware. */
552 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
553 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
555 else if (new_lines != old_lines)
556 call2 (Qwindow_pixel_to_total, frame, Qnil);
558 frame_size_history_add
559 (f, Qadjust_frame_size_3, new_text_width, new_text_height,
560 list4 (make_number (old_pixel_width), make_number (old_pixel_height),
561 make_number (new_pixel_width), make_number (new_pixel_height)));
563 /* Assign new sizes. */
564 FRAME_TEXT_WIDTH (f) = new_text_width;
565 FRAME_TEXT_HEIGHT (f) = new_text_height;
566 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
567 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
568 SET_FRAME_COLS (f, new_cols);
569 SET_FRAME_LINES (f, new_lines);
572 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
573 int text_area_x, text_area_y, text_area_width, text_area_height;
575 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
576 &text_area_height);
577 if (w->cursor.x >= text_area_x + text_area_width)
578 w->cursor.hpos = w->cursor.x = 0;
579 if (w->cursor.y >= text_area_y + text_area_height)
580 w->cursor.vpos = w->cursor.y = 0;
583 /* Sanitize window sizes. */
584 sanitize_window_sizes (frame, Qt);
585 sanitize_window_sizes (frame, Qnil);
587 adjust_frame_glyphs (f);
588 calculate_costs (f);
589 SET_FRAME_GARBAGED (f);
591 /* A frame was "resized" if one of its pixelsizes changed, even if its
592 X window wasn't resized at all. */
593 f->resized_p = (new_pixel_width != old_pixel_width
594 || new_pixel_height != old_pixel_height);
596 unblock_input ();
598 run_window_configuration_change_hook (f);
601 /* Allocate basically initialized frame. */
603 static struct frame *
604 allocate_frame (void)
606 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
609 struct frame *
610 make_frame (bool mini_p)
612 Lisp_Object frame;
613 struct frame *f;
614 struct window *rw, *mw IF_LINT (= NULL);
615 Lisp_Object root_window;
616 Lisp_Object mini_window;
618 f = allocate_frame ();
619 XSETFRAME (frame, f);
621 #ifdef USE_GTK
622 /* Initialize Lisp data. Note that allocate_frame initializes all
623 Lisp data to nil, so do it only for slots which should not be nil. */
624 fset_tool_bar_position (f, Qtop);
625 #endif
627 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
628 non-Lisp data, so do it only for slots which should not be zero.
629 To avoid subtle bugs and for the sake of readability, it's better to
630 initialize enum members explicitly even if their values are zero. */
631 f->wants_modeline = true;
632 f->redisplay = true;
633 f->garbaged = true;
634 f->can_x_set_window_size = false;
635 f->after_make_frame = false;
636 f->inhibit_horizontal_resize = false;
637 f->inhibit_vertical_resize = false;
638 f->tool_bar_redisplayed = false;
639 f->tool_bar_resized = false;
640 f->column_width = 1; /* !FRAME_WINDOW_P value. */
641 f->line_height = 1; /* !FRAME_WINDOW_P value. */
642 #ifdef HAVE_WINDOW_SYSTEM
643 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
644 f->horizontal_scroll_bars = false;
645 f->want_fullscreen = FULLSCREEN_NONE;
646 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
647 f->last_tool_bar_item = -1;
648 #endif
649 #endif
651 root_window = make_window ();
652 rw = XWINDOW (root_window);
653 if (mini_p)
655 mini_window = make_window ();
656 mw = XWINDOW (mini_window);
657 wset_next (rw, mini_window);
658 wset_prev (mw, root_window);
659 mw->mini = 1;
660 wset_frame (mw, frame);
661 fset_minibuffer_window (f, mini_window);
663 else
665 mini_window = Qnil;
666 wset_next (rw, Qnil);
667 fset_minibuffer_window (f, Qnil);
670 wset_frame (rw, frame);
672 /* 10 is arbitrary,
673 just so that there is "something there."
674 Correct size will be set up later with adjust_frame_size. */
676 SET_FRAME_COLS (f, 10);
677 SET_FRAME_LINES (f, 10);
678 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
679 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
681 rw->total_cols = 10;
682 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
683 rw->total_lines = mini_p ? 9 : 10;
684 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
686 if (mini_p)
688 mw->top_line = rw->total_lines;
689 mw->pixel_top = rw->pixel_height;
690 mw->total_cols = rw->total_cols;
691 mw->pixel_width = rw->pixel_width;
692 mw->total_lines = 1;
693 mw->pixel_height = FRAME_LINE_HEIGHT (f);
696 /* Choose a buffer for the frame's root window. */
698 Lisp_Object buf = Fcurrent_buffer ();
700 /* If current buffer is hidden, try to find another one. */
701 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
702 buf = other_buffer_safely (buf);
704 /* Use set_window_buffer, not Fset_window_buffer, and don't let
705 hooks be run by it. The reason is that the whole frame/window
706 arrangement is not yet fully initialized at this point. Windows
707 don't have the right size, glyph matrices aren't initialized
708 etc. Running Lisp functions at this point surely ends in a
709 SEGV. */
710 set_window_buffer (root_window, buf, 0, 0);
711 fset_buffer_list (f, list1 (buf));
714 if (mini_p)
716 set_window_buffer (mini_window,
717 (NILP (Vminibuffer_list)
718 ? get_minibuffer (0)
719 : Fcar (Vminibuffer_list)),
720 0, 0);
721 /* No horizontal scroll bars in minibuffers. */
722 wset_horizontal_scroll_bar (mw, Qnil);
725 fset_root_window (f, root_window);
726 fset_selected_window (f, root_window);
727 /* Make sure this window seems more recently used than
728 a newly-created, never-selected window. */
729 XWINDOW (f->selected_window)->use_time = ++window_select_count;
731 return f;
734 #ifdef HAVE_WINDOW_SYSTEM
735 /* Make a frame using a separate minibuffer window on another frame.
736 MINI_WINDOW is the minibuffer window to use. nil means use the
737 default (the global minibuffer). */
739 struct frame *
740 make_frame_without_minibuffer (Lisp_Object mini_window, KBOARD *kb,
741 Lisp_Object display)
743 struct frame *f;
745 if (!NILP (mini_window))
746 CHECK_LIVE_WINDOW (mini_window);
748 if (!NILP (mini_window)
749 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
750 error ("Frame and minibuffer must be on the same terminal");
752 /* Make a frame containing just a root window. */
753 f = make_frame (0);
755 if (NILP (mini_window))
757 /* Use default-minibuffer-frame if possible. */
758 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
759 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
761 Lisp_Object frame_dummy;
763 XSETFRAME (frame_dummy, f);
764 /* If there's no minibuffer frame to use, create one. */
765 kset_default_minibuffer_frame
766 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
769 mini_window
770 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
773 fset_minibuffer_window (f, mini_window);
775 /* Make the chosen minibuffer window display the proper minibuffer,
776 unless it is already showing a minibuffer. */
777 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
778 /* Use set_window_buffer instead of Fset_window_buffer (see
779 discussion of bug#11984, bug#12025, bug#12026). */
780 set_window_buffer (mini_window,
781 (NILP (Vminibuffer_list)
782 ? get_minibuffer (0)
783 : Fcar (Vminibuffer_list)), 0, 0);
784 return f;
787 /* Make a frame containing only a minibuffer window. */
789 struct frame *
790 make_minibuffer_frame (void)
792 /* First make a frame containing just a root window, no minibuffer. */
794 register struct frame *f = make_frame (0);
795 register Lisp_Object mini_window;
796 register Lisp_Object frame;
798 XSETFRAME (frame, f);
800 f->auto_raise = 0;
801 f->auto_lower = 0;
802 f->no_split = 1;
803 f->wants_modeline = 0;
805 /* Now label the root window as also being the minibuffer.
806 Avoid infinite looping on the window chain by marking next pointer
807 as nil. */
809 mini_window = f->root_window;
810 fset_minibuffer_window (f, mini_window);
811 XWINDOW (mini_window)->mini = 1;
812 wset_next (XWINDOW (mini_window), Qnil);
813 wset_prev (XWINDOW (mini_window), Qnil);
814 wset_frame (XWINDOW (mini_window), frame);
816 /* Put the proper buffer in that window. */
818 /* Use set_window_buffer instead of Fset_window_buffer (see
819 discussion of bug#11984, bug#12025, bug#12026). */
820 set_window_buffer (mini_window,
821 (NILP (Vminibuffer_list)
822 ? get_minibuffer (0)
823 : Fcar (Vminibuffer_list)), 0, 0);
824 return f;
826 #endif /* HAVE_WINDOW_SYSTEM */
828 /* Construct a frame that refers to a terminal. */
830 static printmax_t tty_frame_count;
832 struct frame *
833 make_initial_frame (void)
835 struct frame *f;
836 struct terminal *terminal;
837 Lisp_Object frame;
839 eassert (initial_kboard);
841 /* The first call must initialize Vframe_list. */
842 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
843 Vframe_list = Qnil;
845 terminal = init_initial_terminal ();
847 f = make_frame (1);
848 XSETFRAME (frame, f);
850 Vframe_list = Fcons (frame, Vframe_list);
852 tty_frame_count = 1;
853 fset_name (f, build_pure_c_string ("F1"));
855 SET_FRAME_VISIBLE (f, 1);
857 f->output_method = terminal->type;
858 f->terminal = terminal;
859 f->terminal->reference_count++;
860 f->output_data.nothing = 0;
862 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
863 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
865 #ifdef HAVE_WINDOW_SYSTEM
866 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
867 f->horizontal_scroll_bars = false;
868 #endif
870 /* The default value of menu-bar-mode is t. */
871 set_menu_bar_lines (f, make_number (1), Qnil);
873 if (!noninteractive)
874 init_frame_faces (f);
876 last_nonminibuf_frame = f;
878 f->can_x_set_window_size = true;
879 f->after_make_frame = true;
881 return f;
885 static struct frame *
886 make_terminal_frame (struct terminal *terminal)
888 register struct frame *f;
889 Lisp_Object frame;
890 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
892 if (!terminal->name)
893 error ("Terminal is not live, can't create new frames on it");
895 f = make_frame (1);
897 XSETFRAME (frame, f);
898 Vframe_list = Fcons (frame, Vframe_list);
900 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
902 SET_FRAME_VISIBLE (f, 1);
904 f->terminal = terminal;
905 f->terminal->reference_count++;
906 #ifdef MSDOS
907 f->output_data.tty->display_info = &the_only_display_info;
908 if (!inhibit_window_system
909 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
910 || XFRAME (selected_frame)->output_method == output_msdos_raw))
911 f->output_method = output_msdos_raw;
912 else
913 f->output_method = output_termcap;
914 #else /* not MSDOS */
915 f->output_method = output_termcap;
916 create_tty_output (f);
917 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
918 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
919 #endif /* not MSDOS */
921 #ifdef HAVE_WINDOW_SYSTEM
922 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
923 f->horizontal_scroll_bars = false;
924 #endif
926 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
927 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
928 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
929 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
931 /* Set the top frame to the newly created frame. */
932 if (FRAMEP (FRAME_TTY (f)->top_frame)
933 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
934 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
936 FRAME_TTY (f)->top_frame = frame;
938 if (!noninteractive)
939 init_frame_faces (f);
941 return f;
944 /* Get a suitable value for frame parameter PARAMETER for a newly
945 created frame, based on (1) the user-supplied frame parameter
946 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
948 static Lisp_Object
949 get_future_frame_param (Lisp_Object parameter,
950 Lisp_Object supplied_parms,
951 char *current_value)
953 Lisp_Object result;
955 result = Fassq (parameter, supplied_parms);
956 if (NILP (result))
957 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
958 if (NILP (result) && current_value != NULL)
959 result = build_string (current_value);
960 if (!NILP (result) && !STRINGP (result))
961 result = XCDR (result);
962 if (NILP (result) || !STRINGP (result))
963 result = Qnil;
965 return result;
968 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
969 1, 1, 0,
970 doc: /* Create an additional terminal frame, possibly on another terminal.
971 This function takes one argument, an alist specifying frame parameters.
973 You can create multiple frames on a single text terminal, but only one
974 of them (the selected terminal frame) is actually displayed.
976 In practice, generally you don't need to specify any parameters,
977 except when you want to create a new frame on another terminal.
978 In that case, the `tty' parameter specifies the device file to open,
979 and the `tty-type' parameter specifies the terminal type. Example:
981 (make-terminal-frame \\='((tty . "/dev/pts/5") (tty-type . "xterm")))
983 Note that changing the size of one terminal frame automatically
984 affects all frames on the same terminal device. */)
985 (Lisp_Object parms)
987 struct frame *f;
988 struct terminal *t = NULL;
989 Lisp_Object frame, tem;
990 struct frame *sf = SELECTED_FRAME ();
992 #ifdef MSDOS
993 if (sf->output_method != output_msdos_raw
994 && sf->output_method != output_termcap)
995 emacs_abort ();
996 #else /* not MSDOS */
998 #ifdef WINDOWSNT /* This should work now! */
999 if (sf->output_method != output_termcap)
1000 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
1001 #endif
1002 #endif /* not MSDOS */
1005 Lisp_Object terminal;
1007 terminal = Fassq (Qterminal, parms);
1008 if (CONSP (terminal))
1010 terminal = XCDR (terminal);
1011 t = decode_live_terminal (terminal);
1013 #ifdef MSDOS
1014 if (t && t != the_only_display_info.terminal)
1015 /* msdos.c assumes a single tty_display_info object. */
1016 error ("Multiple terminals are not supported on this platform");
1017 if (!t)
1018 t = the_only_display_info.terminal;
1019 #endif
1022 if (!t)
1024 char *name = 0, *type = 0;
1025 Lisp_Object tty, tty_type;
1026 USE_SAFE_ALLOCA;
1028 tty = get_future_frame_param
1029 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1030 ? FRAME_TTY (XFRAME (selected_frame))->name
1031 : NULL));
1032 if (!NILP (tty))
1033 SAFE_ALLOCA_STRING (name, tty);
1035 tty_type = get_future_frame_param
1036 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1037 ? FRAME_TTY (XFRAME (selected_frame))->type
1038 : NULL));
1039 if (!NILP (tty_type))
1040 SAFE_ALLOCA_STRING (type, tty_type);
1042 t = init_tty (name, type, 0); /* Errors are not fatal. */
1043 SAFE_FREE ();
1046 f = make_terminal_frame (t);
1049 int width, height;
1050 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1051 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f),
1052 5, 0, Qterminal_frame);
1055 adjust_frame_glyphs (f);
1056 calculate_costs (f);
1057 XSETFRAME (frame, f);
1059 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1060 store_in_alist (&parms, Qtty,
1061 (t->display_info.tty->name
1062 ? build_string (t->display_info.tty->name)
1063 : Qnil));
1064 Fmodify_frame_parameters (frame, parms);
1066 /* Make the frame face alist be frame-specific, so that each
1067 frame could change its face definitions independently. */
1068 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1069 /* Simple Fcopy_alist isn't enough, because we need the contents of
1070 the vectors which are the CDRs of associations in face_alist to
1071 be copied as well. */
1072 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1073 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1075 f->can_x_set_window_size = true;
1076 f->after_make_frame = true;
1078 return frame;
1082 /* Perform the switch to frame FRAME.
1084 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1085 FRAME1 as frame.
1087 If TRACK is non-zero and the frame that currently has the focus
1088 redirects its focus to the selected frame, redirect that focused
1089 frame's focus to FRAME instead.
1091 FOR_DELETION non-zero means that the selected frame is being
1092 deleted, which includes the possibility that the frame's terminal
1093 is dead.
1095 The value of NORECORD is passed as argument to Fselect_window. */
1097 Lisp_Object
1098 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1100 struct frame *sf = SELECTED_FRAME ();
1102 /* If FRAME is a switch-frame event, extract the frame we should
1103 switch to. */
1104 if (CONSP (frame)
1105 && EQ (XCAR (frame), Qswitch_frame)
1106 && CONSP (XCDR (frame)))
1107 frame = XCAR (XCDR (frame));
1109 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1110 a switch-frame event to arrive after a frame is no longer live,
1111 especially when deleting the initial frame during startup. */
1112 CHECK_FRAME (frame);
1113 if (! FRAME_LIVE_P (XFRAME (frame)))
1114 return Qnil;
1116 if (sf == XFRAME (frame))
1117 return frame;
1119 /* If a frame's focus has been redirected toward the currently
1120 selected frame, we should change the redirection to point to the
1121 newly selected frame. This means that if the focus is redirected
1122 from a minibufferless frame to a surrogate minibuffer frame, we
1123 can use `other-window' to switch between all the frames using
1124 that minibuffer frame, and the focus redirection will follow us
1125 around. */
1126 #if 0
1127 /* This is too greedy; it causes inappropriate focus redirection
1128 that's hard to get rid of. */
1129 if (track)
1131 Lisp_Object tail;
1133 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1135 Lisp_Object focus;
1137 if (!FRAMEP (XCAR (tail)))
1138 emacs_abort ();
1140 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1142 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1143 Fredirect_frame_focus (XCAR (tail), frame);
1146 #else /* ! 0 */
1147 /* Instead, apply it only to the frame we're pointing to. */
1148 #ifdef HAVE_WINDOW_SYSTEM
1149 if (track && FRAME_WINDOW_P (XFRAME (frame)))
1151 Lisp_Object focus, xfocus;
1153 xfocus = x_get_focus_frame (XFRAME (frame));
1154 if (FRAMEP (xfocus))
1156 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1157 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1158 Fredirect_frame_focus (xfocus, frame);
1161 #endif /* HAVE_X_WINDOWS */
1162 #endif /* ! 0 */
1164 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1165 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1167 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
1169 struct frame *f = XFRAME (frame);
1170 struct tty_display_info *tty = FRAME_TTY (f);
1171 Lisp_Object top_frame = tty->top_frame;
1173 /* Don't mark the frame garbaged and/or obscured if we are
1174 switching to the frame that is already the top frame of that
1175 TTY. */
1176 if (!EQ (frame, top_frame))
1178 if (FRAMEP (top_frame))
1179 /* Mark previously displayed frame as now obscured. */
1180 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1181 SET_FRAME_VISIBLE (f, 1);
1182 /* If the new TTY frame changed dimensions, we need to
1183 resync term.c's idea of the frame size with the new
1184 frame's data. */
1185 if (FRAME_COLS (f) != FrameCols (tty))
1186 FrameCols (tty) = FRAME_COLS (f);
1187 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1188 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1190 tty->top_frame = frame;
1193 selected_frame = frame;
1194 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1195 last_nonminibuf_frame = XFRAME (selected_frame);
1197 Fselect_window (XFRAME (frame)->selected_window, norecord);
1199 /* We want to make sure that the next event generates a frame-switch
1200 event to the appropriate frame. This seems kludgy to me, but
1201 before you take it out, make sure that evaluating something like
1202 (select-window (frame-root-window (new-frame))) doesn't end up
1203 with your typing being interpreted in the new frame instead of
1204 the one you're actually typing in. */
1205 internal_last_event_frame = Qnil;
1207 return frame;
1210 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1211 doc: /* Select FRAME.
1212 Subsequent editing commands apply to its selected window.
1213 Optional argument NORECORD means to neither change the order of
1214 recently selected windows nor the buffer list.
1216 The selection of FRAME lasts until the next time the user does
1217 something to select a different frame, or until the next time
1218 this function is called. If you are using a window system, the
1219 previously selected frame may be restored as the selected frame
1220 when returning to the command loop, because it still may have
1221 the window system's input focus. On a text terminal, the next
1222 redisplay will display FRAME.
1224 This function returns FRAME, or nil if FRAME has been deleted. */)
1225 (Lisp_Object frame, Lisp_Object norecord)
1227 return do_switch_frame (frame, 1, 0, norecord);
1230 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1231 doc: /* Handle a switch-frame event EVENT.
1232 Switch-frame events are usually bound to this function.
1233 A switch-frame event tells Emacs that the window manager has requested
1234 that the user's events be directed to the frame mentioned in the event.
1235 This function selects the selected window of the frame of EVENT.
1237 If EVENT is frame object, handle it as if it were a switch-frame event
1238 to that frame. */)
1239 (Lisp_Object event)
1241 /* Preserve prefix arg that the command loop just cleared. */
1242 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1243 run_hook (Qmouse_leave_buffer_hook);
1244 /* `switch-frame' implies a focus in. */
1245 call1 (intern ("handle-focus-in"), event);
1246 return do_switch_frame (event, 0, 0, Qnil);
1249 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1250 doc: /* Return the frame that is now selected. */)
1251 (void)
1253 return selected_frame;
1256 DEFUN ("frame-list", Fframe_list, Sframe_list,
1257 0, 0, 0,
1258 doc: /* Return a list of all live frames. */)
1259 (void)
1261 Lisp_Object frames;
1262 frames = Fcopy_sequence (Vframe_list);
1263 #ifdef HAVE_WINDOW_SYSTEM
1264 if (FRAMEP (tip_frame))
1265 frames = Fdelq (tip_frame, frames);
1266 #endif
1267 return frames;
1270 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1271 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1272 If MINIBUF is nil, do not consider minibuffer-only candidate.
1273 If MINIBUF is `visible', do not consider an invisible candidate.
1274 If MINIBUF is a window, consider only its own frame and candidate now
1275 using that window as the minibuffer.
1276 If MINIBUF is 0, consider candidate if it is visible or iconified.
1277 Otherwise consider any candidate and return nil if CANDIDATE is not
1278 acceptable. */
1280 static Lisp_Object
1281 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1283 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1285 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1286 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1287 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1288 && FRAME_TTY (c) == FRAME_TTY (f)))
1290 if (NILP (minibuf))
1292 if (!FRAME_MINIBUF_ONLY_P (c))
1293 return candidate;
1295 else if (EQ (minibuf, Qvisible))
1297 if (FRAME_VISIBLE_P (c))
1298 return candidate;
1300 else if (WINDOWP (minibuf))
1302 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1303 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1304 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1305 FRAME_FOCUS_FRAME (c)))
1306 return candidate;
1308 else if (XFASTINT (minibuf) == 0)
1310 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1311 return candidate;
1313 else
1314 return candidate;
1316 return Qnil;
1319 /* Return the next frame in the frame list after FRAME. */
1321 static Lisp_Object
1322 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1324 Lisp_Object f, tail;
1325 int passed = 0;
1327 /* There must always be at least one frame in Vframe_list. */
1328 eassert (CONSP (Vframe_list));
1330 while (passed < 2)
1331 FOR_EACH_FRAME (tail, f)
1333 if (passed)
1335 f = candidate_frame (f, frame, minibuf);
1336 if (!NILP (f))
1337 return f;
1339 if (EQ (frame, f))
1340 passed++;
1342 return frame;
1345 /* Return the previous frame in the frame list before FRAME. */
1347 static Lisp_Object
1348 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1350 Lisp_Object f, tail, prev = Qnil;
1352 /* There must always be at least one frame in Vframe_list. */
1353 eassert (CONSP (Vframe_list));
1355 FOR_EACH_FRAME (tail, f)
1357 if (EQ (frame, f) && !NILP (prev))
1358 return prev;
1359 f = candidate_frame (f, frame, minibuf);
1360 if (!NILP (f))
1361 prev = f;
1364 /* We've scanned the entire list. */
1365 if (NILP (prev))
1366 /* We went through the whole frame list without finding a single
1367 acceptable frame. Return the original frame. */
1368 return frame;
1369 else
1370 /* There were no acceptable frames in the list before FRAME; otherwise,
1371 we would have returned directly from the loop. Since PREV is the last
1372 acceptable frame in the list, return it. */
1373 return prev;
1377 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1378 doc: /* Return the next frame in the frame list after FRAME.
1379 It considers only frames on the same terminal as FRAME.
1380 By default, skip minibuffer-only frames.
1381 If omitted, FRAME defaults to the selected frame.
1382 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1383 If MINIFRAME is a window, include only its own frame
1384 and any frame now using that window as the minibuffer.
1385 If MINIFRAME is `visible', include all visible frames.
1386 If MINIFRAME is 0, include all visible and iconified frames.
1387 Otherwise, include all frames. */)
1388 (Lisp_Object frame, Lisp_Object miniframe)
1390 if (NILP (frame))
1391 frame = selected_frame;
1392 CHECK_LIVE_FRAME (frame);
1393 return next_frame (frame, miniframe);
1396 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1397 doc: /* Return the previous frame in the frame list before FRAME.
1398 It considers only frames on the same terminal as FRAME.
1399 By default, skip minibuffer-only frames.
1400 If omitted, FRAME defaults to the selected frame.
1401 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1402 If MINIFRAME is a window, include only its own frame
1403 and any frame now using that window as the minibuffer.
1404 If MINIFRAME is `visible', include all visible frames.
1405 If MINIFRAME is 0, include all visible and iconified frames.
1406 Otherwise, include all frames. */)
1407 (Lisp_Object frame, Lisp_Object miniframe)
1409 if (NILP (frame))
1410 frame = selected_frame;
1411 CHECK_LIVE_FRAME (frame);
1412 return prev_frame (frame, miniframe);
1415 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1416 Slast_nonminibuf_frame, 0, 0, 0,
1417 doc: /* Return last non-minibuffer frame selected. */)
1418 (void)
1420 Lisp_Object frame = Qnil;
1422 if (last_nonminibuf_frame)
1423 XSETFRAME (frame, last_nonminibuf_frame);
1425 return frame;
1428 /* Return 1 if it is ok to delete frame F;
1429 0 if all frames aside from F are invisible.
1430 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1432 static int
1433 other_visible_frames (struct frame *f)
1435 Lisp_Object frames, this;
1437 FOR_EACH_FRAME (frames, this)
1439 if (f == XFRAME (this))
1440 continue;
1442 /* Verify that we can still talk to the frame's X window,
1443 and note any recent change in visibility. */
1444 #ifdef HAVE_X_WINDOWS
1445 if (FRAME_WINDOW_P (XFRAME (this)))
1446 x_sync (XFRAME (this));
1447 #endif
1449 if (FRAME_VISIBLE_P (XFRAME (this))
1450 || FRAME_ICONIFIED_P (XFRAME (this))
1451 /* Allow deleting the terminal frame when at least one X
1452 frame exists. */
1453 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1454 return 1;
1456 return 0;
1459 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1460 window. Preferably use the selected frame's minibuffer window
1461 instead. If the selected frame doesn't have one, get some other
1462 frame's minibuffer window. SELECT non-zero means select the new
1463 minibuffer window. */
1464 static void
1465 check_minibuf_window (Lisp_Object frame, int select)
1467 struct frame *f = decode_live_frame (frame);
1469 XSETFRAME (frame, f);
1471 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1473 Lisp_Object frames, this, window = make_number (0);
1475 if (!EQ (frame, selected_frame)
1476 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1477 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1478 else
1479 FOR_EACH_FRAME (frames, this)
1481 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1483 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1484 break;
1488 /* Don't abort if no window was found (Bug#15247). */
1489 if (WINDOWP (window))
1491 /* Use set_window_buffer instead of Fset_window_buffer (see
1492 discussion of bug#11984, bug#12025, bug#12026). */
1493 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1494 minibuf_window = window;
1496 /* SELECT non-zero usually means that FRAME's minibuffer
1497 window was selected; select the new one. */
1498 if (select)
1499 Fselect_window (minibuf_window, Qnil);
1505 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1506 unconditionally. x_connection_closed and delete_terminal use
1507 this. Any other value of FORCE implements the semantics
1508 described for Fdelete_frame. */
1509 Lisp_Object
1510 delete_frame (Lisp_Object frame, Lisp_Object force)
1512 struct frame *f = decode_any_frame (frame);
1513 struct frame *sf;
1514 struct kboard *kb;
1516 int minibuffer_selected, is_tooltip_frame;
1518 if (! FRAME_LIVE_P (f))
1519 return Qnil;
1521 if (NILP (force) && !other_visible_frames (f))
1522 error ("Attempt to delete the sole visible or iconified frame");
1524 /* x_connection_closed must have set FORCE to `noelisp' in order
1525 to delete the last frame, if it is gone. */
1526 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1527 error ("Attempt to delete the only frame");
1529 XSETFRAME (frame, f);
1531 /* Does this frame have a minibuffer, and is it the surrogate
1532 minibuffer for any other frame? */
1533 if (FRAME_HAS_MINIBUF_P (f))
1535 Lisp_Object frames, this;
1537 FOR_EACH_FRAME (frames, this)
1539 Lisp_Object fminiw;
1541 if (EQ (this, frame))
1542 continue;
1544 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1546 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1548 /* If we MUST delete this frame, delete the other first.
1549 But do this only if FORCE equals `noelisp'. */
1550 if (EQ (force, Qnoelisp))
1551 delete_frame (this, Qnoelisp);
1552 else
1553 error ("Attempt to delete a surrogate minibuffer frame");
1558 is_tooltip_frame = !NILP (Fframe_parameter (frame, Qtooltip));
1560 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1561 frame is a tooltip. FORCE is set to `noelisp' when handling
1562 a disconnect from the terminal, so we don't dare call Lisp
1563 code. */
1564 if (NILP (Vrun_hooks) || is_tooltip_frame)
1566 else if (EQ (force, Qnoelisp))
1567 pending_funcalls
1568 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1569 pending_funcalls);
1570 else
1572 #ifdef HAVE_X_WINDOWS
1573 /* Also, save clipboard to the clipboard manager. */
1574 x_clipboard_manager_save_frame (frame);
1575 #endif
1577 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1580 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1581 if (! FRAME_LIVE_P (f))
1582 return Qnil;
1584 /* At this point, we are committed to deleting the frame.
1585 There is no more chance for errors to prevent it. */
1587 minibuffer_selected = EQ (minibuf_window, selected_window);
1588 sf = SELECTED_FRAME ();
1589 /* Don't let the frame remain selected. */
1590 if (f == sf)
1592 Lisp_Object tail;
1593 Lisp_Object frame1 = Qnil;
1595 /* Look for another visible frame on the same terminal.
1596 Do not call next_frame here because it may loop forever.
1597 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1598 FOR_EACH_FRAME (tail, frame1)
1599 if (!EQ (frame, frame1)
1600 && (FRAME_TERMINAL (XFRAME (frame))
1601 == FRAME_TERMINAL (XFRAME (frame1)))
1602 && FRAME_VISIBLE_P (XFRAME (frame1)))
1603 break;
1605 /* If there is none, find *some* other frame. */
1606 if (NILP (frame1) || EQ (frame1, frame))
1608 FOR_EACH_FRAME (tail, frame1)
1610 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1612 /* Do not change a text terminal's top-frame. */
1613 struct frame *f1 = XFRAME (frame1);
1614 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1616 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1617 if (!EQ (top_frame, frame))
1618 frame1 = top_frame;
1620 break;
1624 #ifdef NS_IMPL_COCOA
1625 else
1626 /* Under NS, there is no system mechanism for choosing a new
1627 window to get focus -- it is left to application code.
1628 So the portion of THIS application interfacing with NS
1629 needs to know about it. We call Fraise_frame, but the
1630 purpose is really to transfer focus. */
1631 Fraise_frame (frame1);
1632 #endif
1634 do_switch_frame (frame1, 0, 1, Qnil);
1635 sf = SELECTED_FRAME ();
1638 /* Don't allow minibuf_window to remain on a deleted frame. */
1639 check_minibuf_window (frame, minibuffer_selected);
1641 /* Don't let echo_area_window to remain on a deleted frame. */
1642 if (EQ (f->minibuffer_window, echo_area_window))
1643 echo_area_window = sf->minibuffer_window;
1645 /* Clear any X selections for this frame. */
1646 #ifdef HAVE_X_WINDOWS
1647 if (FRAME_X_P (f))
1648 x_clear_frame_selections (f);
1649 #endif
1651 /* Free glyphs.
1652 This function must be called before the window tree of the
1653 frame is deleted because windows contain dynamically allocated
1654 memory. */
1655 free_glyphs (f);
1657 #ifdef HAVE_WINDOW_SYSTEM
1658 /* Give chance to each font driver to free a frame specific data. */
1659 font_update_drivers (f, Qnil);
1660 #endif
1662 /* Mark all the windows that used to be on FRAME as deleted, and then
1663 remove the reference to them. */
1664 delete_all_child_windows (f->root_window);
1665 fset_root_window (f, Qnil);
1667 Vframe_list = Fdelq (frame, Vframe_list);
1668 SET_FRAME_VISIBLE (f, 0);
1670 /* Allow the vector of menu bar contents to be freed in the next
1671 garbage collection. The frame object itself may not be garbage
1672 collected until much later, because recent_keys and other data
1673 structures can still refer to it. */
1674 fset_menu_bar_vector (f, Qnil);
1676 /* If FRAME's buffer lists contains killed
1677 buffers, this helps GC to reclaim them. */
1678 fset_buffer_list (f, Qnil);
1679 fset_buried_buffer_list (f, Qnil);
1681 free_font_driver_list (f);
1682 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1683 xfree (f->namebuf);
1684 #endif
1685 xfree (f->decode_mode_spec_buffer);
1686 xfree (FRAME_INSERT_COST (f));
1687 xfree (FRAME_DELETEN_COST (f));
1688 xfree (FRAME_INSERTN_COST (f));
1689 xfree (FRAME_DELETE_COST (f));
1691 /* Since some events are handled at the interrupt level, we may get
1692 an event for f at any time; if we zero out the frame's terminal
1693 now, then we may trip up the event-handling code. Instead, we'll
1694 promise that the terminal of the frame must be valid until we
1695 have called the window-system-dependent frame destruction
1696 routine. */
1700 struct terminal *terminal;
1701 block_input ();
1702 if (FRAME_TERMINAL (f)->delete_frame_hook)
1703 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1704 terminal = FRAME_TERMINAL (f);
1705 f->output_data.nothing = 0;
1706 f->terminal = 0; /* Now the frame is dead. */
1707 unblock_input ();
1709 /* If needed, delete the terminal that this frame was on.
1710 (This must be done after the frame is killed.) */
1711 terminal->reference_count--;
1712 #ifdef USE_GTK
1713 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1714 bug.
1715 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1716 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1717 terminal->reference_count = 1;
1718 #endif /* USE_GTK */
1719 if (terminal->reference_count == 0)
1721 Lisp_Object tmp;
1722 XSETTERMINAL (tmp, terminal);
1724 kb = NULL;
1725 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1727 else
1728 kb = terminal->kboard;
1731 /* If we've deleted the last_nonminibuf_frame, then try to find
1732 another one. */
1733 if (f == last_nonminibuf_frame)
1735 Lisp_Object frames, this;
1737 last_nonminibuf_frame = 0;
1739 FOR_EACH_FRAME (frames, this)
1741 f = XFRAME (this);
1742 if (!FRAME_MINIBUF_ONLY_P (f))
1744 last_nonminibuf_frame = f;
1745 break;
1750 /* If there's no other frame on the same kboard, get out of
1751 single-kboard state if we're in it for this kboard. */
1752 if (kb != NULL)
1754 Lisp_Object frames, this;
1755 /* Some frame we found on the same kboard, or nil if there are none. */
1756 Lisp_Object frame_on_same_kboard = Qnil;
1758 FOR_EACH_FRAME (frames, this)
1759 if (kb == FRAME_KBOARD (XFRAME (this)))
1760 frame_on_same_kboard = this;
1762 if (NILP (frame_on_same_kboard))
1763 not_single_kboard_state (kb);
1767 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1768 find another one. Prefer minibuffer-only frames, but also notice
1769 frames with other windows. */
1770 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1772 Lisp_Object frames, this;
1774 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1775 Lisp_Object frame_with_minibuf = Qnil;
1776 /* Some frame we found on the same kboard, or nil if there are none. */
1777 Lisp_Object frame_on_same_kboard = Qnil;
1779 FOR_EACH_FRAME (frames, this)
1781 struct frame *f1 = XFRAME (this);
1783 /* Consider only frames on the same kboard
1784 and only those with minibuffers. */
1785 if (kb == FRAME_KBOARD (f1)
1786 && FRAME_HAS_MINIBUF_P (f1))
1788 frame_with_minibuf = this;
1789 if (FRAME_MINIBUF_ONLY_P (f1))
1790 break;
1793 if (kb == FRAME_KBOARD (f1))
1794 frame_on_same_kboard = this;
1797 if (!NILP (frame_on_same_kboard))
1799 /* We know that there must be some frame with a minibuffer out
1800 there. If this were not true, all of the frames present
1801 would have to be minibufferless, which implies that at some
1802 point their minibuffer frames must have been deleted, but
1803 that is prohibited at the top; you can't delete surrogate
1804 minibuffer frames. */
1805 if (NILP (frame_with_minibuf))
1806 emacs_abort ();
1808 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1810 else
1811 /* No frames left on this kboard--say no minibuffer either. */
1812 kset_default_minibuffer_frame (kb, Qnil);
1815 /* Cause frame titles to update--necessary if we now have just one frame. */
1816 if (!is_tooltip_frame)
1817 update_mode_lines = 15;
1819 return Qnil;
1822 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1823 doc: /* Delete FRAME, permanently eliminating it from use.
1824 FRAME defaults to the selected frame.
1826 A frame may not be deleted if its minibuffer serves as surrogate
1827 minibuffer for another frame. Normally, you may not delete a frame if
1828 all other frames are invisible, but if the second optional argument
1829 FORCE is non-nil, you may do so.
1831 This function runs `delete-frame-functions' before actually
1832 deleting the frame, unless the frame is a tooltip.
1833 The functions are run with one argument, the frame to be deleted. */)
1834 (Lisp_Object frame, Lisp_Object force)
1836 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1840 /* Return mouse position in character cell units. */
1842 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1843 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1844 The position is given in canonical character cells, where (0, 0) is the
1845 upper-left corner of the frame, X is the horizontal offset, and Y is the
1846 vertical offset, measured in units of the frame's default character size.
1847 If Emacs is running on a mouseless terminal or hasn't been programmed
1848 to read the mouse position, it returns the selected frame for FRAME
1849 and nil for X and Y.
1850 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1851 passing the normal return value to that function as an argument,
1852 and returns whatever that function returns. */)
1853 (void)
1855 struct frame *f;
1856 Lisp_Object lispy_dummy;
1857 Lisp_Object x, y, retval;
1859 f = SELECTED_FRAME ();
1860 x = y = Qnil;
1862 /* It's okay for the hook to refrain from storing anything. */
1863 if (FRAME_TERMINAL (f)->mouse_position_hook)
1865 enum scroll_bar_part party_dummy;
1866 Time time_dummy;
1867 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1868 &lispy_dummy, &party_dummy,
1869 &x, &y,
1870 &time_dummy);
1873 if (! NILP (x))
1875 int col = XINT (x);
1876 int row = XINT (y);
1877 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1878 XSETINT (x, col);
1879 XSETINT (y, row);
1881 XSETFRAME (lispy_dummy, f);
1882 retval = Fcons (lispy_dummy, Fcons (x, y));
1883 if (!NILP (Vmouse_position_function))
1884 retval = call1 (Vmouse_position_function, retval);
1885 return retval;
1888 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1889 Smouse_pixel_position, 0, 0, 0,
1890 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1891 The position is given in pixel units, where (0, 0) is the
1892 upper-left corner of the frame, X is the horizontal offset, and Y is
1893 the vertical offset.
1894 If Emacs is running on a mouseless terminal or hasn't been programmed
1895 to read the mouse position, it returns the selected frame for FRAME
1896 and nil for X and Y. */)
1897 (void)
1899 struct frame *f;
1900 Lisp_Object lispy_dummy;
1901 Lisp_Object x, y, retval;
1903 f = SELECTED_FRAME ();
1904 x = y = Qnil;
1906 /* It's okay for the hook to refrain from storing anything. */
1907 if (FRAME_TERMINAL (f)->mouse_position_hook)
1909 enum scroll_bar_part party_dummy;
1910 Time time_dummy;
1911 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1912 &lispy_dummy, &party_dummy,
1913 &x, &y,
1914 &time_dummy);
1917 XSETFRAME (lispy_dummy, f);
1918 retval = Fcons (lispy_dummy, Fcons (x, y));
1919 if (!NILP (Vmouse_position_function))
1920 retval = call1 (Vmouse_position_function, retval);
1921 return retval;
1924 #ifdef HAVE_WINDOW_SYSTEM
1926 /* On frame F, convert character coordinates X and Y to pixel
1927 coordinates *PIX_X and *PIX_Y. */
1929 static void
1930 frame_char_to_pixel_position (struct frame *f, int x, int y,
1931 int *pix_x, int *pix_y)
1933 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
1934 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
1936 if (*pix_x < 0)
1937 *pix_x = 0;
1938 if (*pix_x > FRAME_PIXEL_WIDTH (f))
1939 *pix_x = FRAME_PIXEL_WIDTH (f);
1941 if (*pix_y < 0)
1942 *pix_y = 0;
1943 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
1944 *pix_y = FRAME_PIXEL_HEIGHT (f);
1947 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1949 static void
1950 frame_set_mouse_position (struct frame *f, int x, int y)
1952 int pix_x, pix_y;
1954 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
1955 frame_set_mouse_pixel_position (f, pix_x, pix_y);
1958 #endif /* HAVE_WINDOW_SYSTEM */
1960 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1961 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1962 Coordinates are relative to the frame, not a window,
1963 so the coordinates of the top left character in the frame
1964 may be nonzero due to left-hand scroll bars or the menu bar.
1966 The position is given in canonical character cells, where (0, 0) is
1967 the upper-left corner of the frame, X is the horizontal offset, and
1968 Y is the vertical offset, measured in units of the frame's default
1969 character size.
1971 This function is a no-op for an X frame that is not visible.
1972 If you have just created a frame, you must wait for it to become visible
1973 before calling this function on it, like this.
1974 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1975 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1977 CHECK_LIVE_FRAME (frame);
1978 CHECK_TYPE_RANGED_INTEGER (int, x);
1979 CHECK_TYPE_RANGED_INTEGER (int, y);
1981 /* I think this should be done with a hook. */
1982 #ifdef HAVE_WINDOW_SYSTEM
1983 if (FRAME_WINDOW_P (XFRAME (frame)))
1984 /* Warping the mouse will cause enternotify and focus events. */
1985 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1986 #else
1987 #if defined (MSDOS)
1988 if (FRAME_MSDOS_P (XFRAME (frame)))
1990 Fselect_frame (frame, Qnil);
1991 mouse_moveto (XINT (x), XINT (y));
1993 #else
1994 #ifdef HAVE_GPM
1996 Fselect_frame (frame, Qnil);
1997 term_mouse_moveto (XINT (x), XINT (y));
1999 #endif
2000 #endif
2001 #endif
2003 return Qnil;
2006 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
2007 Sset_mouse_pixel_position, 3, 3, 0,
2008 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
2009 The position is given in pixels, where (0, 0) is the upper-left corner
2010 of the frame, X is the horizontal offset, and Y is the vertical offset.
2012 Note, this is a no-op for an X frame that is not visible.
2013 If you have just created a frame, you must wait for it to become visible
2014 before calling this function on it, like this.
2015 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2016 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2018 CHECK_LIVE_FRAME (frame);
2019 CHECK_TYPE_RANGED_INTEGER (int, x);
2020 CHECK_TYPE_RANGED_INTEGER (int, y);
2022 /* I think this should be done with a hook. */
2023 #ifdef HAVE_WINDOW_SYSTEM
2024 if (FRAME_WINDOW_P (XFRAME (frame)))
2025 /* Warping the mouse will cause enternotify and focus events. */
2026 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
2027 #else
2028 #if defined (MSDOS)
2029 if (FRAME_MSDOS_P (XFRAME (frame)))
2031 Fselect_frame (frame, Qnil);
2032 mouse_moveto (XINT (x), XINT (y));
2034 #else
2035 #ifdef HAVE_GPM
2037 Fselect_frame (frame, Qnil);
2038 term_mouse_moveto (XINT (x), XINT (y));
2040 #endif
2041 #endif
2042 #endif
2044 return Qnil;
2047 static void make_frame_visible_1 (Lisp_Object);
2049 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2050 0, 1, "",
2051 doc: /* Make the frame FRAME visible (assuming it is an X window).
2052 If omitted, FRAME defaults to the currently selected frame. */)
2053 (Lisp_Object frame)
2055 struct frame *f = decode_live_frame (frame);
2057 /* I think this should be done with a hook. */
2058 #ifdef HAVE_WINDOW_SYSTEM
2059 if (FRAME_WINDOW_P (f))
2060 x_make_frame_visible (f);
2061 #endif
2063 make_frame_visible_1 (f->root_window);
2065 /* Make menu bar update for the Buffers and Frames menus. */
2066 /* windows_or_buffers_changed = 15; FIXME: Why? */
2068 XSETFRAME (frame, f);
2069 return frame;
2072 /* Update the display_time slot of the buffers shown in WINDOW
2073 and all its descendants. */
2075 static void
2076 make_frame_visible_1 (Lisp_Object window)
2078 struct window *w;
2080 for (; !NILP (window); window = w->next)
2082 w = XWINDOW (window);
2083 if (WINDOWP (w->contents))
2084 make_frame_visible_1 (w->contents);
2085 else
2086 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2090 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2091 0, 2, "",
2092 doc: /* Make the frame FRAME invisible.
2093 If omitted, FRAME defaults to the currently selected frame.
2094 On graphical displays, invisible frames are not updated and are
2095 usually not displayed at all, even in a window system's \"taskbar\".
2097 Normally you may not make FRAME invisible if all other frames are invisible,
2098 but if the second optional argument FORCE is non-nil, you may do so.
2100 This function has no effect on text terminal frames. Such frames are
2101 always considered visible, whether or not they are currently being
2102 displayed in the terminal. */)
2103 (Lisp_Object frame, Lisp_Object force)
2105 struct frame *f = decode_live_frame (frame);
2107 if (NILP (force) && !other_visible_frames (f))
2108 error ("Attempt to make invisible the sole visible or iconified frame");
2110 /* Don't allow minibuf_window to remain on an invisible frame. */
2111 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2113 /* I think this should be done with a hook. */
2114 #ifdef HAVE_WINDOW_SYSTEM
2115 if (FRAME_WINDOW_P (f))
2116 x_make_frame_invisible (f);
2117 #endif
2119 /* Make menu bar update for the Buffers and Frames menus. */
2120 windows_or_buffers_changed = 16;
2122 return Qnil;
2125 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2126 0, 1, "",
2127 doc: /* Make the frame FRAME into an icon.
2128 If omitted, FRAME defaults to the currently selected frame. */)
2129 (Lisp_Object frame)
2131 struct frame *f = decode_live_frame (frame);
2133 /* Don't allow minibuf_window to remain on an iconified frame. */
2134 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2136 /* I think this should be done with a hook. */
2137 #ifdef HAVE_WINDOW_SYSTEM
2138 if (FRAME_WINDOW_P (f))
2139 x_iconify_frame (f);
2140 #endif
2142 /* Make menu bar update for the Buffers and Frames menus. */
2143 windows_or_buffers_changed = 17;
2145 return Qnil;
2148 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2149 1, 1, 0,
2150 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2151 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2152 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2153 On graphical displays, invisible frames are not updated and are
2154 usually not displayed at all, even in a window system's \"taskbar\".
2156 If FRAME is a text terminal frame, this always returns t.
2157 Such frames are always considered visible, whether or not they are
2158 currently being displayed on the terminal. */)
2159 (Lisp_Object frame)
2161 CHECK_LIVE_FRAME (frame);
2163 if (FRAME_VISIBLE_P (XFRAME (frame)))
2164 return Qt;
2165 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2166 return Qicon;
2167 return Qnil;
2170 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2171 0, 0, 0,
2172 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2173 (void)
2175 Lisp_Object tail, frame, value = Qnil;
2177 FOR_EACH_FRAME (tail, frame)
2178 if (FRAME_VISIBLE_P (XFRAME (frame)))
2179 value = Fcons (frame, value);
2181 return value;
2185 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2186 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2187 If FRAME is invisible or iconified, make it visible.
2188 If you don't specify a frame, the selected frame is used.
2189 If Emacs is displaying on an ordinary terminal or some other device which
2190 doesn't support multiple overlapping frames, this function selects FRAME. */)
2191 (Lisp_Object frame)
2193 struct frame *f = decode_live_frame (frame);
2195 XSETFRAME (frame, f);
2197 if (FRAME_TERMCAP_P (f))
2198 /* On a text terminal select FRAME. */
2199 Fselect_frame (frame, Qnil);
2200 else
2201 /* Do like the documentation says. */
2202 Fmake_frame_visible (frame);
2204 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2205 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2207 return Qnil;
2210 /* Should we have a corresponding function called Flower_Power? */
2211 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2212 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2213 If you don't specify a frame, the selected frame is used.
2214 If Emacs is displaying on an ordinary terminal or some other device which
2215 doesn't support multiple overlapping frames, this function does nothing. */)
2216 (Lisp_Object frame)
2218 struct frame *f = decode_live_frame (frame);
2220 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2221 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2223 return Qnil;
2227 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2228 1, 2, 0,
2229 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2230 In other words, switch-frame events caused by events in FRAME will
2231 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2232 FOCUS-FRAME after reading an event typed at FRAME.
2234 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2235 frame again receives its own keystrokes.
2237 Focus redirection is useful for temporarily redirecting keystrokes to
2238 a surrogate minibuffer frame when a frame doesn't have its own
2239 minibuffer window.
2241 A frame's focus redirection can be changed by `select-frame'. If frame
2242 FOO is selected, and then a different frame BAR is selected, any
2243 frames redirecting their focus to FOO are shifted to redirect their
2244 focus to BAR. This allows focus redirection to work properly when the
2245 user switches from one frame to another using `select-window'.
2247 This means that a frame whose focus is redirected to itself is treated
2248 differently from a frame whose focus is redirected to nil; the former
2249 is affected by `select-frame', while the latter is not.
2251 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2252 (Lisp_Object frame, Lisp_Object focus_frame)
2254 /* Note that we don't check for a live frame here. It's reasonable
2255 to redirect the focus of a frame you're about to delete, if you
2256 know what other frame should receive those keystrokes. */
2257 struct frame *f = decode_any_frame (frame);
2259 if (! NILP (focus_frame))
2260 CHECK_LIVE_FRAME (focus_frame);
2262 fset_focus_frame (f, focus_frame);
2264 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2265 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2267 return Qnil;
2271 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2272 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2273 If FRAME is omitted or nil, the selected frame is used.
2274 Return nil if FRAME's focus is not redirected.
2275 See `redirect-frame-focus'. */)
2276 (Lisp_Object frame)
2278 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2281 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2282 doc: /* Set the input focus to FRAME.
2283 FRAME nil means use the selected frame.
2284 If there is no window system support, this function does nothing. */)
2285 (Lisp_Object frame)
2287 #ifdef HAVE_WINDOW_SYSTEM
2288 x_focus_frame (decode_window_system_frame (frame));
2289 #endif
2290 return Qnil;
2293 DEFUN ("frame-after-make-frame",
2294 Fframe_after_make_frame,
2295 Sframe_after_make_frame, 2, 2, 0,
2296 doc: /* Mark FRAME as made.
2297 FRAME nil means use the selected frame. Second argument MADE non-nil
2298 means functions on `window-configuration-change-hook' are called
2299 whenever the window configuration of FRAME changes. MADE nil means
2300 these functions are not called.
2302 This function is currently called by `make-frame' only and should be
2303 otherwise used with utter care to avoid that running functions on
2304 `window-configuration-change-hook' is impeded forever. */)
2305 (Lisp_Object frame, Lisp_Object made)
2307 struct frame *f = decode_live_frame (frame);
2308 f->after_make_frame = !NILP (made);
2309 f->inhibit_horizontal_resize = false;
2310 f->inhibit_vertical_resize = false;
2311 return made;
2315 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2317 void
2318 frames_discard_buffer (Lisp_Object buffer)
2320 Lisp_Object frame, tail;
2322 FOR_EACH_FRAME (tail, frame)
2324 fset_buffer_list
2325 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2326 fset_buried_buffer_list
2327 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2331 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2332 If the alist already has an element for PROP, we change it. */
2334 void
2335 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2337 register Lisp_Object tem;
2339 tem = Fassq (prop, *alistptr);
2340 if (EQ (tem, Qnil))
2341 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2342 else
2343 Fsetcdr (tem, val);
2346 static int
2347 frame_name_fnn_p (char *str, ptrdiff_t len)
2349 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2351 char *p = str + 2;
2352 while ('0' <= *p && *p <= '9')
2353 p++;
2354 if (p == str + len)
2355 return 1;
2357 return 0;
2360 /* Set the name of the terminal frame. Also used by MSDOS frames.
2361 Modeled after x_set_name which is used for WINDOW frames. */
2363 static void
2364 set_term_frame_name (struct frame *f, Lisp_Object name)
2366 f->explicit_name = ! NILP (name);
2368 /* If NAME is nil, set the name to F<num>. */
2369 if (NILP (name))
2371 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2373 /* Check for no change needed in this very common case
2374 before we do any consing. */
2375 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2376 return;
2378 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2380 else
2382 CHECK_STRING (name);
2384 /* Don't change the name if it's already NAME. */
2385 if (! NILP (Fstring_equal (name, f->name)))
2386 return;
2388 /* Don't allow the user to set the frame name to F<num>, so it
2389 doesn't clash with the names we generate for terminal frames. */
2390 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2391 error ("Frame names of the form F<num> are usurped by Emacs");
2394 fset_name (f, name);
2395 update_mode_lines = 16;
2398 void
2399 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2401 register Lisp_Object old_alist_elt;
2403 /* The buffer-list parameters are stored in a special place and not
2404 in the alist. All buffers must be live. */
2405 if (EQ (prop, Qbuffer_list))
2407 Lisp_Object list = Qnil;
2408 for (; CONSP (val); val = XCDR (val))
2409 if (!NILP (Fbuffer_live_p (XCAR (val))))
2410 list = Fcons (XCAR (val), list);
2411 fset_buffer_list (f, Fnreverse (list));
2412 return;
2414 if (EQ (prop, Qburied_buffer_list))
2416 Lisp_Object list = Qnil;
2417 for (; CONSP (val); val = XCDR (val))
2418 if (!NILP (Fbuffer_live_p (XCAR (val))))
2419 list = Fcons (XCAR (val), list);
2420 fset_buried_buffer_list (f, Fnreverse (list));
2421 return;
2424 /* If PROP is a symbol which is supposed to have frame-local values,
2425 and it is set up based on this frame, switch to the global
2426 binding. That way, we can create or alter the frame-local binding
2427 without messing up the symbol's status. */
2428 if (SYMBOLP (prop))
2430 struct Lisp_Symbol *sym = XSYMBOL (prop);
2431 start:
2432 switch (sym->redirect)
2434 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2435 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2436 case SYMBOL_LOCALIZED:
2437 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2438 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2439 swap_in_global_binding (sym);
2440 break;
2442 default: emacs_abort ();
2446 /* The tty color needed to be set before the frame's parameter
2447 alist was updated with the new value. This is not true any more,
2448 but we still do this test early on. */
2449 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2450 && f == FRAME_TTY (f)->previous_frame)
2451 /* Force redisplay of this tty. */
2452 FRAME_TTY (f)->previous_frame = NULL;
2454 /* Update the frame parameter alist. */
2455 old_alist_elt = Fassq (prop, f->param_alist);
2456 if (EQ (old_alist_elt, Qnil))
2457 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2458 else
2459 Fsetcdr (old_alist_elt, val);
2461 /* Update some other special parameters in their special places
2462 in addition to the alist. */
2464 if (EQ (prop, Qbuffer_predicate))
2465 fset_buffer_predicate (f, val);
2467 if (! FRAME_WINDOW_P (f))
2469 if (EQ (prop, Qmenu_bar_lines))
2470 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2471 else if (EQ (prop, Qname))
2472 set_term_frame_name (f, val);
2475 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2477 if (! MINI_WINDOW_P (XWINDOW (val)))
2478 error ("Surrogate minibuffer windows must be minibuffer windows");
2480 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2481 && !EQ (val, f->minibuffer_window))
2482 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2484 /* Install the chosen minibuffer window, with proper buffer. */
2485 fset_minibuffer_window (f, val);
2489 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2490 is not an unspecified foreground or background color. */
2492 static Lisp_Object
2493 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2495 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2496 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2497 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2498 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2501 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2502 doc: /* Return the parameters-alist of frame FRAME.
2503 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2504 The meaningful PARMs depend on the kind of frame.
2505 If FRAME is omitted or nil, return information on the currently selected frame. */)
2506 (Lisp_Object frame)
2508 Lisp_Object alist;
2509 struct frame *f = decode_any_frame (frame);
2510 int height, width;
2512 if (!FRAME_LIVE_P (f))
2513 return Qnil;
2515 alist = Fcopy_alist (f->param_alist);
2517 if (!FRAME_WINDOW_P (f))
2519 Lisp_Object elt;
2521 /* If the frame's parameter alist says the colors are
2522 unspecified and reversed, take the frame's background pixel
2523 for foreground and vice versa. */
2524 elt = Fassq (Qforeground_color, alist);
2525 if (CONSP (elt) && STRINGP (XCDR (elt)))
2527 elt = frame_unspecified_color (f, XCDR (elt));
2528 if (!NILP (elt))
2529 store_in_alist (&alist, Qforeground_color, elt);
2531 else
2532 store_in_alist (&alist, Qforeground_color,
2533 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2534 elt = Fassq (Qbackground_color, alist);
2535 if (CONSP (elt) && STRINGP (XCDR (elt)))
2537 elt = frame_unspecified_color (f, XCDR (elt));
2538 if (!NILP (elt))
2539 store_in_alist (&alist, Qbackground_color, elt);
2541 else
2542 store_in_alist (&alist, Qbackground_color,
2543 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2544 store_in_alist (&alist, Qfont,
2545 build_string (FRAME_MSDOS_P (f)
2546 ? "ms-dos"
2547 : FRAME_W32_P (f) ? "w32term"
2548 :"tty"));
2550 store_in_alist (&alist, Qname, f->name);
2551 height = (f->new_height
2552 ? (f->new_pixelwise
2553 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2554 : f->new_height)
2555 : FRAME_LINES (f));
2556 store_in_alist (&alist, Qheight, make_number (height));
2557 width = (f->new_width
2558 ? (f->new_pixelwise
2559 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2560 : f->new_width)
2561 : FRAME_COLS (f));
2562 store_in_alist (&alist, Qwidth, make_number (width));
2563 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2564 store_in_alist (&alist, Qminibuffer,
2565 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2566 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2567 : FRAME_MINIBUF_WINDOW (f)));
2568 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2569 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2570 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2572 /* I think this should be done with a hook. */
2573 #ifdef HAVE_WINDOW_SYSTEM
2574 if (FRAME_WINDOW_P (f))
2575 x_report_frame_params (f, &alist);
2576 else
2577 #endif
2579 /* This ought to be correct in f->param_alist for an X frame. */
2580 Lisp_Object lines;
2581 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2582 store_in_alist (&alist, Qmenu_bar_lines, lines);
2585 return alist;
2589 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2590 doc: /* Return FRAME's value for parameter PARAMETER.
2591 If FRAME is nil, describe the currently selected frame. */)
2592 (Lisp_Object frame, Lisp_Object parameter)
2594 struct frame *f = decode_any_frame (frame);
2595 Lisp_Object value = Qnil;
2597 CHECK_SYMBOL (parameter);
2599 XSETFRAME (frame, f);
2601 if (FRAME_LIVE_P (f))
2603 /* Avoid consing in frequent cases. */
2604 if (EQ (parameter, Qname))
2605 value = f->name;
2606 #ifdef HAVE_X_WINDOWS
2607 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2608 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2609 #endif /* HAVE_X_WINDOWS */
2610 else if (EQ (parameter, Qbackground_color)
2611 || EQ (parameter, Qforeground_color))
2613 value = Fassq (parameter, f->param_alist);
2614 if (CONSP (value))
2616 value = XCDR (value);
2617 /* Fframe_parameters puts the actual fg/bg color names,
2618 even if f->param_alist says otherwise. This is
2619 important when param_alist's notion of colors is
2620 "unspecified". We need to do the same here. */
2621 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2623 Lisp_Object tem = frame_unspecified_color (f, value);
2625 if (!NILP (tem))
2626 value = tem;
2629 else
2630 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2632 else if (EQ (parameter, Qdisplay_type)
2633 || EQ (parameter, Qbackground_mode))
2634 value = Fcdr (Fassq (parameter, f->param_alist));
2635 else
2636 /* FIXME: Avoid this code path at all (as well as code duplication)
2637 by sharing more code with Fframe_parameters. */
2638 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2641 return value;
2645 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2646 Smodify_frame_parameters, 2, 2, 0,
2647 doc: /* Modify the parameters of frame FRAME according to ALIST.
2648 If FRAME is nil, it defaults to the selected frame.
2649 ALIST is an alist of parameters to change and their new values.
2650 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2651 The meaningful PARMs depend on the kind of frame.
2652 Undefined PARMs are ignored, but stored in the frame's parameter list
2653 so that `frame-parameters' will return them.
2655 The value of frame parameter FOO can also be accessed
2656 as a frame-local binding for the variable FOO, if you have
2657 enabled such bindings for that variable with `make-variable-frame-local'.
2658 Note that this functionality is obsolete as of Emacs 22.2, and its
2659 use is not recommended. Explicitly check for a frame-parameter instead. */)
2660 (Lisp_Object frame, Lisp_Object alist)
2662 struct frame *f = decode_live_frame (frame);
2663 register Lisp_Object prop, val;
2665 CHECK_LIST (alist);
2667 /* I think this should be done with a hook. */
2668 #ifdef HAVE_WINDOW_SYSTEM
2669 if (FRAME_WINDOW_P (f))
2670 x_set_frame_parameters (f, alist);
2671 else
2672 #endif
2673 #ifdef MSDOS
2674 if (FRAME_MSDOS_P (f))
2675 IT_set_frame_parameters (f, alist);
2676 else
2677 #endif
2680 EMACS_INT length = XFASTINT (Flength (alist));
2681 ptrdiff_t i;
2682 Lisp_Object *parms;
2683 Lisp_Object *values;
2684 USE_SAFE_ALLOCA;
2685 SAFE_ALLOCA_LISP (parms, 2 * length);
2686 values = parms + length;
2688 /* Extract parm names and values into those vectors. */
2690 for (i = 0; CONSP (alist); alist = XCDR (alist))
2692 Lisp_Object elt;
2694 elt = XCAR (alist);
2695 parms[i] = Fcar (elt);
2696 values[i] = Fcdr (elt);
2697 i++;
2700 /* Now process them in reverse of specified order. */
2701 while (--i >= 0)
2703 prop = parms[i];
2704 val = values[i];
2705 store_frame_param (f, prop, val);
2707 if (EQ (prop, Qforeground_color)
2708 || EQ (prop, Qbackground_color))
2709 update_face_from_frame_parameter (f, prop, val);
2712 SAFE_FREE ();
2714 return Qnil;
2717 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2718 0, 1, 0,
2719 doc: /* Height in pixels of a line in the font in frame FRAME.
2720 If FRAME is omitted or nil, the selected frame is used.
2721 For a terminal frame, the value is always 1. */)
2722 (Lisp_Object frame)
2724 #ifdef HAVE_WINDOW_SYSTEM
2725 struct frame *f = decode_any_frame (frame);
2727 if (FRAME_WINDOW_P (f))
2728 return make_number (FRAME_LINE_HEIGHT (f));
2729 else
2730 #endif
2731 return make_number (1);
2735 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2736 0, 1, 0,
2737 doc: /* Width in pixels of characters in the font in frame FRAME.
2738 If FRAME is omitted or nil, the selected frame is used.
2739 On a graphical screen, the width is the standard width of the default font.
2740 For a terminal screen, the value is always 1. */)
2741 (Lisp_Object frame)
2743 #ifdef HAVE_WINDOW_SYSTEM
2744 struct frame *f = decode_any_frame (frame);
2746 if (FRAME_WINDOW_P (f))
2747 return make_number (FRAME_COLUMN_WIDTH (f));
2748 else
2749 #endif
2750 return make_number (1);
2753 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2754 Sframe_pixel_height, 0, 1, 0,
2755 doc: /* Return a FRAME's height in pixels.
2756 If FRAME is omitted or nil, the selected frame is used. The exact value
2757 of the result depends on the window-system and toolkit in use:
2759 In the Gtk+ version of Emacs, it includes only any window (including
2760 the minibuffer or echo area), mode line, and header line. It does not
2761 include the tool bar or menu bar.
2763 With other graphical versions, it also includes the tool bar and the
2764 menu bar.
2766 For a text terminal, it includes the menu bar. In this case, the
2767 result is really in characters rather than pixels (i.e., is identical
2768 to `frame-height'). */)
2769 (Lisp_Object frame)
2771 struct frame *f = decode_any_frame (frame);
2773 #ifdef HAVE_WINDOW_SYSTEM
2774 if (FRAME_WINDOW_P (f))
2775 return make_number (FRAME_PIXEL_HEIGHT (f));
2776 else
2777 #endif
2778 return make_number (FRAME_TOTAL_LINES (f));
2781 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2782 Sframe_pixel_width, 0, 1, 0,
2783 doc: /* Return FRAME's width in pixels.
2784 For a terminal frame, the result really gives the width in characters.
2785 If FRAME is omitted or nil, the selected frame is used. */)
2786 (Lisp_Object frame)
2788 struct frame *f = decode_any_frame (frame);
2790 #ifdef HAVE_WINDOW_SYSTEM
2791 if (FRAME_WINDOW_P (f))
2792 return make_number (FRAME_PIXEL_WIDTH (f));
2793 else
2794 #endif
2795 return make_number (FRAME_TOTAL_COLS (f));
2798 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2799 Stool_bar_pixel_width, 0, 1, 0,
2800 doc: /* Return width in pixels of FRAME's tool bar.
2801 The result is greater than zero only when the tool bar is on the left
2802 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2803 is used. */)
2804 (Lisp_Object frame)
2806 #ifdef FRAME_TOOLBAR_WIDTH
2807 struct frame *f = decode_any_frame (frame);
2809 if (FRAME_WINDOW_P (f))
2810 return make_number (FRAME_TOOLBAR_WIDTH (f));
2811 #endif
2812 return make_number (0);
2815 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2816 doc: /* Return width in columns of FRAME's text area. */)
2817 (Lisp_Object frame)
2819 return make_number (FRAME_COLS (decode_any_frame (frame)));
2822 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2823 doc: /* Return height in lines of FRAME's text area. */)
2824 (Lisp_Object frame)
2826 return make_number (FRAME_LINES (decode_any_frame (frame)));
2829 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2830 doc: /* Return number of total columns of FRAME. */)
2831 (Lisp_Object frame)
2833 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2836 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2837 doc: /* Return number of total lines of FRAME. */)
2838 (Lisp_Object frame)
2840 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2843 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2844 doc: /* Return text area width of FRAME in pixels. */)
2845 (Lisp_Object frame)
2847 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2850 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2851 doc: /* Return text area height of FRAME in pixels. */)
2852 (Lisp_Object frame)
2854 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2857 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2858 doc: /* Return scroll bar width of FRAME in pixels. */)
2859 (Lisp_Object frame)
2861 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2864 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2865 doc: /* Return scroll bar height of FRAME in pixels. */)
2866 (Lisp_Object frame)
2868 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2871 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2872 doc: /* Return fringe width of FRAME in pixels. */)
2873 (Lisp_Object frame)
2875 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2878 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2879 doc: /* Return border width of FRAME in pixels. */)
2880 (Lisp_Object frame)
2882 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2885 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2886 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2887 (Lisp_Object frame)
2889 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2892 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2893 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2894 (Lisp_Object frame)
2896 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2899 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2900 doc: /* Set text height of frame FRAME to HEIGHT lines.
2901 Optional third arg PRETEND non-nil means that redisplay should use
2902 HEIGHT lines but that the idea of the actual height of the frame should
2903 not be changed.
2905 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2906 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
2907 window managers may refuse to honor a HEIGHT that is not an integer
2908 multiple of the default frame font height. */)
2909 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2911 struct frame *f = decode_live_frame (frame);
2912 int pixel_height;
2914 CHECK_TYPE_RANGED_INTEGER (int, height);
2916 pixel_height = (!NILP (pixelwise)
2917 ? XINT (height)
2918 : XINT (height) * FRAME_LINE_HEIGHT (f));
2919 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
2921 return Qnil;
2924 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2925 doc: /* Set text width of frame FRAME to WIDTH columns.
2926 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2927 columns but that the idea of the actual width of the frame should not
2928 be changed.
2930 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2931 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
2932 window managers may refuse to honor a WIDTH that is not an integer
2933 multiple of the default frame font width. */)
2934 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2936 struct frame *f = decode_live_frame (frame);
2937 int pixel_width;
2939 CHECK_TYPE_RANGED_INTEGER (int, width);
2941 pixel_width = (!NILP (pixelwise)
2942 ? XINT (width)
2943 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2944 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
2946 return Qnil;
2949 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2950 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
2951 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
2952 When `frame-resize-pixelwise' is nil, some window managers may refuse to
2953 honor a WIDTH that is not an integer multiple of the default frame font
2954 width or a HEIGHT that is not an integer multiple of the default frame
2955 font height. */)
2956 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2958 struct frame *f = decode_live_frame (frame);
2959 int pixel_width, pixel_height;
2961 CHECK_TYPE_RANGED_INTEGER (int, width);
2962 CHECK_TYPE_RANGED_INTEGER (int, height);
2964 pixel_width = (!NILP (pixelwise)
2965 ? XINT (width)
2966 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2967 pixel_height = (!NILP (pixelwise)
2968 ? XINT (height)
2969 : XINT (height) * FRAME_LINE_HEIGHT (f));
2970 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
2972 return Qnil;
2975 DEFUN ("frame-position", Fframe_position,
2976 Sframe_position, 0, 1, 0,
2977 doc: /* Return top left corner of FRAME in pixels.
2978 FRAME must be a live frame and defaults to the selected one. The return
2979 value is a cons (x, y) of the coordinates of the top left corner of
2980 FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's
2981 display. */)
2982 (Lisp_Object frame)
2984 register struct frame *f = decode_live_frame (frame);
2986 return Fcons (make_number (f->left_pos), make_number (f->top_pos));
2989 DEFUN ("set-frame-position", Fset_frame_position,
2990 Sset_frame_position, 3, 3, 0,
2991 doc: /* Set position of FRAME to (X, Y).
2992 FRAME must be a live frame and defaults to the selected one. X and Y,
2993 if positive, specify the coordinate of the left and top edge of FRAME's
2994 outer frame in pixels relative to an origin (0, 0) of FRAME's display.
2995 If any of X or Y is negative, it specifies the coordinates of the right
2996 or bottom edge of the outer frame of FRAME relative to the right or
2997 bottom edge of FRAME's display. */)
2998 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
3000 register struct frame *f = decode_live_frame (frame);
3002 CHECK_TYPE_RANGED_INTEGER (int, x);
3003 CHECK_TYPE_RANGED_INTEGER (int, y);
3005 /* I think this should be done with a hook. */
3006 #ifdef HAVE_WINDOW_SYSTEM
3007 if (FRAME_WINDOW_P (f))
3008 x_set_offset (f, XINT (x), XINT (y), 1);
3009 #endif
3011 return Qt;
3015 /***********************************************************************
3016 Frame Parameters
3017 ***********************************************************************/
3019 /* Connect the frame-parameter names for X frames
3020 to the ways of passing the parameter values to the window system.
3022 The name of a parameter, as a Lisp symbol,
3023 has an `x-frame-parameter' property which is an integer in Lisp
3024 that is an index in this table. */
3026 struct frame_parm_table {
3027 const char *name;
3028 int sym;
3031 static const struct frame_parm_table frame_parms[] =
3033 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3034 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3035 {"background-color", -1},
3036 {"border-color", SYMBOL_INDEX (Qborder_color)},
3037 {"border-width", SYMBOL_INDEX (Qborder_width)},
3038 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3039 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3040 {"font", -1},
3041 {"foreground-color", -1},
3042 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3043 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3044 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3045 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3046 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3047 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3048 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3049 {"name", SYMBOL_INDEX (Qname)},
3050 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3051 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3052 {"title", SYMBOL_INDEX (Qtitle)},
3053 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3054 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3055 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3056 {"visibility", SYMBOL_INDEX (Qvisibility)},
3057 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3058 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3059 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3060 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3061 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3062 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3063 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3064 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3065 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3066 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3067 {"alpha", SYMBOL_INDEX (Qalpha)},
3068 {"sticky", SYMBOL_INDEX (Qsticky)},
3069 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3072 #ifdef HAVE_WINDOW_SYSTEM
3074 /* Change the parameters of frame F as specified by ALIST.
3075 If a parameter is not specially recognized, do nothing special;
3076 otherwise call the `x_set_...' function for that parameter.
3077 Except for certain geometry properties, always call store_frame_param
3078 to store the new value in the parameter alist. */
3080 void
3081 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3083 Lisp_Object tail;
3085 /* If both of these parameters are present, it's more efficient to
3086 set them both at once. So we wait until we've looked at the
3087 entire list before we set them. */
3088 int width IF_LINT (= 0), height IF_LINT (= 0);
3089 bool width_change = false, height_change = false;
3091 /* Same here. */
3092 Lisp_Object left, top;
3094 /* Same with these. */
3095 Lisp_Object icon_left, icon_top;
3097 /* And with this. */
3098 Lisp_Object fullscreen;
3099 bool fullscreen_change = false;
3101 /* Record in these vectors all the parms specified. */
3102 Lisp_Object *parms;
3103 Lisp_Object *values;
3104 ptrdiff_t i, p;
3105 bool left_no_change = 0, top_no_change = 0;
3106 #ifdef HAVE_X_WINDOWS
3107 bool icon_left_no_change = 0, icon_top_no_change = 0;
3108 #endif
3110 i = 0;
3111 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3112 i++;
3114 USE_SAFE_ALLOCA;
3115 SAFE_ALLOCA_LISP (parms, 2 * i);
3116 values = parms + i;
3118 /* Extract parm names and values into those vectors. */
3120 i = 0;
3121 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3123 Lisp_Object elt;
3125 elt = XCAR (tail);
3126 parms[i] = Fcar (elt);
3127 values[i] = Fcdr (elt);
3128 i++;
3130 /* TAIL and ALIST are not used again below here. */
3131 alist = tail = Qnil;
3133 top = left = Qunbound;
3134 icon_left = icon_top = Qunbound;
3136 /* Process foreground_color and background_color before anything else.
3137 They are independent of other properties, but other properties (e.g.,
3138 cursor_color) are dependent upon them. */
3139 /* Process default font as well, since fringe widths depends on it. */
3140 for (p = 0; p < i; p++)
3142 Lisp_Object prop, val;
3144 prop = parms[p];
3145 val = values[p];
3146 if (EQ (prop, Qforeground_color)
3147 || EQ (prop, Qbackground_color)
3148 || EQ (prop, Qfont))
3150 register Lisp_Object param_index, old_value;
3152 old_value = get_frame_param (f, prop);
3153 if (NILP (Fequal (val, old_value)))
3155 store_frame_param (f, prop, val);
3157 param_index = Fget (prop, Qx_frame_parameter);
3158 if (NATNUMP (param_index)
3159 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3160 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3161 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3166 /* Now process them in reverse of specified order. */
3167 while (i-- != 0)
3169 Lisp_Object prop, val;
3171 prop = parms[i];
3172 val = values[i];
3174 if (EQ (prop, Qwidth))
3176 if (RANGED_INTEGERP (0, val, INT_MAX))
3178 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3179 width_change = true;
3181 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3182 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3184 width = XFASTINT (XCDR (val));
3185 width_change = true;
3188 else if (EQ (prop, Qheight))
3190 if (RANGED_INTEGERP (0, val, INT_MAX))
3192 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3193 height_change = true;
3195 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3196 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3198 height = XFASTINT (XCDR (val));
3199 height_change = true;
3202 else if (EQ (prop, Qtop))
3203 top = val;
3204 else if (EQ (prop, Qleft))
3205 left = val;
3206 else if (EQ (prop, Qicon_top))
3207 icon_top = val;
3208 else if (EQ (prop, Qicon_left))
3209 icon_left = val;
3210 else if (EQ (prop, Qfullscreen))
3212 fullscreen = val;
3213 fullscreen_change = true;
3215 else if (EQ (prop, Qforeground_color)
3216 || EQ (prop, Qbackground_color)
3217 || EQ (prop, Qfont))
3218 /* Processed above. */
3219 continue;
3220 else
3222 register Lisp_Object param_index, old_value;
3224 old_value = get_frame_param (f, prop);
3226 store_frame_param (f, prop, val);
3228 param_index = Fget (prop, Qx_frame_parameter);
3229 if (NATNUMP (param_index)
3230 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3231 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3232 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3236 /* Don't die if just one of these was set. */
3237 if (EQ (left, Qunbound))
3239 left_no_change = 1;
3240 if (f->left_pos < 0)
3241 left = list2 (Qplus, make_number (f->left_pos));
3242 else
3243 XSETINT (left, f->left_pos);
3245 if (EQ (top, Qunbound))
3247 top_no_change = 1;
3248 if (f->top_pos < 0)
3249 top = list2 (Qplus, make_number (f->top_pos));
3250 else
3251 XSETINT (top, f->top_pos);
3254 /* If one of the icon positions was not set, preserve or default it. */
3255 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3257 #ifdef HAVE_X_WINDOWS
3258 icon_left_no_change = 1;
3259 #endif
3260 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3261 if (NILP (icon_left))
3262 XSETINT (icon_left, 0);
3264 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3266 #ifdef HAVE_X_WINDOWS
3267 icon_top_no_change = 1;
3268 #endif
3269 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3270 if (NILP (icon_top))
3271 XSETINT (icon_top, 0);
3274 /* Don't set these parameters unless they've been explicitly
3275 specified. The window might be mapped or resized while we're in
3276 this function, and we don't want to override that unless the lisp
3277 code has asked for it.
3279 Don't set these parameters unless they actually differ from the
3280 window's current parameters; the window may not actually exist
3281 yet. */
3283 Lisp_Object frame;
3285 XSETFRAME (frame, f);
3287 if ((width_change && width != FRAME_TEXT_WIDTH (f))
3288 || (height_change && height != FRAME_TEXT_HEIGHT (f)))
3289 /* We could consider checking f->after_make_frame here, but I
3290 don't have the faintest idea why the following is needed at
3291 all. With the old setting it can get a Heisenbug when
3292 EmacsFrameResize intermittently provokes a delayed
3293 change_frame_size in the middle of adjust_frame_size. */
3294 /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
3295 adjust_frame_size (f, width_change ? width : -1,
3296 height_change ? height : -1, 1, 0, Qx_set_frame_parameters);
3298 if ((!NILP (left) || !NILP (top))
3299 && ! (left_no_change && top_no_change)
3300 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3301 && NUMBERP (top) && XINT (top) == f->top_pos))
3303 int leftpos = 0;
3304 int toppos = 0;
3306 /* Record the signs. */
3307 f->size_hint_flags &= ~ (XNegative | YNegative);
3308 if (EQ (left, Qminus))
3309 f->size_hint_flags |= XNegative;
3310 else if (TYPE_RANGED_INTEGERP (int, left))
3312 leftpos = XINT (left);
3313 if (leftpos < 0)
3314 f->size_hint_flags |= XNegative;
3316 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3317 && CONSP (XCDR (left))
3318 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3320 leftpos = - XINT (XCAR (XCDR (left)));
3321 f->size_hint_flags |= XNegative;
3323 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3324 && CONSP (XCDR (left))
3325 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3327 leftpos = XINT (XCAR (XCDR (left)));
3330 if (EQ (top, Qminus))
3331 f->size_hint_flags |= YNegative;
3332 else if (TYPE_RANGED_INTEGERP (int, top))
3334 toppos = XINT (top);
3335 if (toppos < 0)
3336 f->size_hint_flags |= YNegative;
3338 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3339 && CONSP (XCDR (top))
3340 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3342 toppos = - XINT (XCAR (XCDR (top)));
3343 f->size_hint_flags |= YNegative;
3345 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3346 && CONSP (XCDR (top))
3347 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3349 toppos = XINT (XCAR (XCDR (top)));
3353 /* Store the numeric value of the position. */
3354 f->top_pos = toppos;
3355 f->left_pos = leftpos;
3357 f->win_gravity = NorthWestGravity;
3359 /* Actually set that position, and convert to absolute. */
3360 x_set_offset (f, leftpos, toppos, -1);
3363 if (fullscreen_change)
3365 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
3367 frame_size_history_add
3368 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
3370 store_frame_param (f, Qfullscreen, fullscreen);
3371 if (!EQ (fullscreen, old_value))
3372 x_set_fullscreen (f, fullscreen, old_value);
3376 #ifdef HAVE_X_WINDOWS
3377 if ((!NILP (icon_left) || !NILP (icon_top))
3378 && ! (icon_left_no_change && icon_top_no_change))
3379 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3380 #endif /* HAVE_X_WINDOWS */
3383 SAFE_FREE ();
3387 /* Insert a description of internally-recorded parameters of frame X
3388 into the parameter alist *ALISTPTR that is to be given to the user.
3389 Only parameters that are specific to the X window system
3390 and whose values are not correctly recorded in the frame's
3391 param_alist need to be considered here. */
3393 void
3394 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3396 Lisp_Object tem;
3397 uprintmax_t w;
3398 char buf[INT_BUFSIZE_BOUND (w)];
3400 /* Represent negative positions (off the top or left screen edge)
3401 in a way that Fmodify_frame_parameters will understand correctly. */
3402 XSETINT (tem, f->left_pos);
3403 if (f->left_pos >= 0)
3404 store_in_alist (alistptr, Qleft, tem);
3405 else
3406 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3408 XSETINT (tem, f->top_pos);
3409 if (f->top_pos >= 0)
3410 store_in_alist (alistptr, Qtop, tem);
3411 else
3412 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3414 store_in_alist (alistptr, Qborder_width,
3415 make_number (f->border_width));
3416 store_in_alist (alistptr, Qinternal_border_width,
3417 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3418 store_in_alist (alistptr, Qright_divider_width,
3419 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3420 store_in_alist (alistptr, Qbottom_divider_width,
3421 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3422 store_in_alist (alistptr, Qleft_fringe,
3423 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3424 store_in_alist (alistptr, Qright_fringe,
3425 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3426 store_in_alist (alistptr, Qscroll_bar_width,
3427 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3428 ? make_number (0)
3429 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3430 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3431 /* nil means "use default width"
3432 for non-toolkit scroll bar.
3433 ruler-mode.el depends on this. */
3434 : Qnil));
3435 store_in_alist (alistptr, Qscroll_bar_height,
3436 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3437 ? make_number (0)
3438 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3439 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3440 /* nil means "use default height"
3441 for non-toolkit scroll bar. */
3442 : Qnil));
3443 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3444 MS-Windows it returns a value whose type is HANDLE, which is
3445 actually a pointer. Explicit casting avoids compiler
3446 warnings. */
3447 w = (uintptr_t) FRAME_X_WINDOW (f);
3448 store_in_alist (alistptr, Qwindow_id,
3449 make_formatted_string (buf, "%"pMu, w));
3450 #ifdef HAVE_X_WINDOWS
3451 #ifdef USE_X_TOOLKIT
3452 /* Tooltip frame may not have this widget. */
3453 if (FRAME_X_OUTPUT (f)->widget)
3454 #endif
3455 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3456 store_in_alist (alistptr, Qouter_window_id,
3457 make_formatted_string (buf, "%"pMu, w));
3458 #endif
3459 store_in_alist (alistptr, Qicon_name, f->icon_name);
3460 store_in_alist (alistptr, Qvisibility,
3461 (FRAME_VISIBLE_P (f) ? Qt
3462 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3463 store_in_alist (alistptr, Qdisplay,
3464 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3466 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3467 tem = Qnil;
3468 else
3469 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3470 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3471 store_in_alist (alistptr, Qparent_id, tem);
3472 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3476 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3477 the previous value of that parameter, NEW_VALUE is the new value. */
3479 void
3480 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3482 if (NILP (new_value))
3483 f->want_fullscreen = FULLSCREEN_NONE;
3484 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3485 f->want_fullscreen = FULLSCREEN_BOTH;
3486 else if (EQ (new_value, Qfullwidth))
3487 f->want_fullscreen = FULLSCREEN_WIDTH;
3488 else if (EQ (new_value, Qfullheight))
3489 f->want_fullscreen = FULLSCREEN_HEIGHT;
3490 else if (EQ (new_value, Qmaximized))
3491 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3493 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3494 FRAME_TERMINAL (f)->fullscreen_hook (f);
3498 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3499 the previous value of that parameter, NEW_VALUE is the new value. */
3501 void
3502 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3504 if (NILP (new_value))
3505 f->extra_line_spacing = 0;
3506 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3507 f->extra_line_spacing = XFASTINT (new_value);
3508 else if (FLOATP (new_value))
3510 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3512 if (new_spacing >= 0)
3513 f->extra_line_spacing = new_spacing;
3514 else
3515 signal_error ("Invalid line-spacing", new_value);
3517 else
3518 signal_error ("Invalid line-spacing", new_value);
3519 if (FRAME_VISIBLE_P (f))
3520 redraw_frame (f);
3524 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3525 the previous value of that parameter, NEW_VALUE is the new value. */
3527 void
3528 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3530 Lisp_Object bgcolor;
3532 if (NILP (new_value))
3533 f->gamma = 0;
3534 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3535 /* The value 0.4545 is the normal viewing gamma. */
3536 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3537 else
3538 signal_error ("Invalid screen-gamma", new_value);
3540 /* Apply the new gamma value to the frame background. */
3541 bgcolor = Fassq (Qbackground_color, f->param_alist);
3542 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3544 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3545 if (NATNUMP (parm_index)
3546 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3547 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3548 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3549 (f, bgcolor, Qnil);
3552 clear_face_cache (true); /* FIXME: Why of all frames? */
3553 fset_redisplay (f);
3557 void
3558 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3560 Lisp_Object font_object;
3561 int fontset = -1;
3562 #ifdef HAVE_X_WINDOWS
3563 Lisp_Object font_param = arg;
3564 #endif
3566 /* Set the frame parameter back to the old value because we may
3567 fail to use ARG as the new parameter value. */
3568 store_frame_param (f, Qfont, oldval);
3570 /* ARG is a fontset name, a font name, a cons of fontset name and a
3571 font object, or a font object. In the last case, this function
3572 never fail. */
3573 if (STRINGP (arg))
3575 fontset = fs_query_fontset (arg, 0);
3576 if (fontset < 0)
3578 font_object = font_open_by_name (f, arg);
3579 if (NILP (font_object))
3580 error ("Font `%s' is not defined", SSDATA (arg));
3581 arg = AREF (font_object, FONT_NAME_INDEX);
3583 else if (fontset > 0)
3585 font_object = font_open_by_name (f, fontset_ascii (fontset));
3586 if (NILP (font_object))
3587 error ("Font `%s' is not defined", SDATA (arg));
3588 arg = AREF (font_object, FONT_NAME_INDEX);
3590 else
3591 error ("The default fontset can't be used for a frame font");
3593 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3595 /* This is the case that the ASCII font of F's fontset XCAR
3596 (arg) is changed to the font XCDR (arg) by
3597 `set-fontset-font'. */
3598 fontset = fs_query_fontset (XCAR (arg), 0);
3599 if (fontset < 0)
3600 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3601 font_object = XCDR (arg);
3602 arg = AREF (font_object, FONT_NAME_INDEX);
3603 #ifdef HAVE_X_WINDOWS
3604 font_param = Ffont_get (font_object, QCname);
3605 #endif
3607 else if (FONT_OBJECT_P (arg))
3609 font_object = arg;
3610 #ifdef HAVE_X_WINDOWS
3611 font_param = Ffont_get (font_object, QCname);
3612 #endif
3613 /* This is to store the XLFD font name in the frame parameter for
3614 backward compatibility. We should store the font-object
3615 itself in the future. */
3616 arg = AREF (font_object, FONT_NAME_INDEX);
3617 fontset = FRAME_FONTSET (f);
3618 /* Check if we can use the current fontset. If not, set FONTSET
3619 to -1 to generate a new fontset from FONT-OBJECT. */
3620 if (fontset >= 0)
3622 Lisp_Object ascii_font = fontset_ascii (fontset);
3623 Lisp_Object spec = font_spec_from_name (ascii_font);
3625 /* SPEC might be nil because ASCII_FONT's name doesn't parse
3626 according to stupid XLFD rules, which, for example,
3627 disallow font names that include a dash followed by a
3628 number. So in those cases we simply request x_new_font
3629 below to generate a new fontset. */
3630 if (NILP (spec) || ! font_match_p (spec, font_object))
3631 fontset = -1;
3634 else
3635 signal_error ("Invalid font", arg);
3637 if (! NILP (Fequal (font_object, oldval)))
3638 return;
3640 x_new_font (f, font_object, fontset);
3641 store_frame_param (f, Qfont, arg);
3642 #ifdef HAVE_X_WINDOWS
3643 store_frame_param (f, Qfont_param, font_param);
3644 #endif
3645 /* Recalculate toolbar height. */
3646 f->n_tool_bar_rows = 0;
3648 /* Ensure we redraw it. */
3649 clear_current_matrices (f);
3651 /* Attempt to hunt down bug#16028. */
3652 SET_FRAME_GARBAGED (f);
3654 recompute_basic_faces (f);
3656 do_pending_window_change (0);
3658 /* We used to call face-set-after-frame-default here, but it leads to
3659 recursive calls (since that function can set the `default' face's
3660 font which in turns changes the frame's `font' parameter).
3661 Also I don't know what this call is meant to do, but it seems the
3662 wrong way to do it anyway (it does a lot more work than what seems
3663 reasonable in response to a change to `font'). */
3667 void
3668 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3670 if (! NILP (new_value)
3671 && !CONSP (new_value))
3673 char *p0, *p1;
3675 CHECK_STRING (new_value);
3676 p0 = p1 = SSDATA (new_value);
3677 new_value = Qnil;
3678 while (*p0)
3680 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3681 if (p0 < p1)
3682 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3683 new_value);
3684 if (*p1)
3686 int c;
3688 while ((c = *++p1) && c_isspace (c));
3690 p0 = p1;
3692 new_value = Fnreverse (new_value);
3695 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3696 return;
3698 if (FRAME_FONT (f))
3699 free_all_realized_faces (Qnil);
3701 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3702 if (NILP (new_value))
3704 if (NILP (old_value))
3705 error ("No font backend available");
3706 font_update_drivers (f, old_value);
3707 error ("None of specified font backends are available");
3709 store_frame_param (f, Qfont_backend, new_value);
3711 if (FRAME_FONT (f))
3713 Lisp_Object frame;
3715 XSETFRAME (frame, f);
3716 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3717 face_change = true;
3718 windows_or_buffers_changed = 18;
3722 void
3723 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3725 int unit = FRAME_COLUMN_WIDTH (f);
3726 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3727 int new_width;
3729 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3730 ? eabs (XINT (new_value)) : 8);
3732 if (new_width != old_width)
3734 FRAME_LEFT_FRINGE_WIDTH (f) = new_width;
3735 FRAME_FRINGE_COLS (f) /* Round up. */
3736 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3738 if (FRAME_X_WINDOW (f) != 0)
3739 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
3741 SET_FRAME_GARBAGED (f);
3746 void
3747 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3749 int unit = FRAME_COLUMN_WIDTH (f);
3750 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3751 int new_width;
3753 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3754 ? eabs (XINT (new_value)) : 8);
3756 if (new_width != old_width)
3758 FRAME_RIGHT_FRINGE_WIDTH (f) = new_width;
3759 FRAME_FRINGE_COLS (f) /* Round up. */
3760 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3762 if (FRAME_X_WINDOW (f) != 0)
3763 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
3765 SET_FRAME_GARBAGED (f);
3770 void
3771 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3773 CHECK_TYPE_RANGED_INTEGER (int, arg);
3775 if (XINT (arg) == f->border_width)
3776 return;
3778 if (FRAME_X_WINDOW (f) != 0)
3779 error ("Cannot change the border width of a frame");
3781 f->border_width = XINT (arg);
3784 void
3785 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3787 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3789 CHECK_TYPE_RANGED_INTEGER (int, arg);
3790 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3791 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3792 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3793 if (FRAME_RIGHT_DIVIDER_WIDTH (f) != old)
3795 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
3796 adjust_frame_glyphs (f);
3797 SET_FRAME_GARBAGED (f);
3802 void
3803 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3805 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3807 CHECK_TYPE_RANGED_INTEGER (int, arg);
3808 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3809 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3810 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3811 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) != old)
3813 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
3814 adjust_frame_glyphs (f);
3815 SET_FRAME_GARBAGED (f);
3819 void
3820 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3822 Lisp_Object frame;
3823 XSETFRAME (frame, f);
3825 if (NILP (value))
3826 Fmake_frame_invisible (frame, Qt);
3827 else if (EQ (value, Qicon))
3828 Ficonify_frame (frame);
3829 else
3830 Fmake_frame_visible (frame);
3833 void
3834 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3836 f->auto_raise = !EQ (Qnil, arg);
3839 void
3840 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3842 f->auto_lower = !EQ (Qnil, arg);
3845 void
3846 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3848 f->no_split = !NILP (arg);
3851 void
3852 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3854 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3855 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3856 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3857 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3859 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3860 = (NILP (arg)
3861 ? vertical_scroll_bar_none
3862 : EQ (Qleft, arg)
3863 ? vertical_scroll_bar_left
3864 : EQ (Qright, arg)
3865 ? vertical_scroll_bar_right
3866 : EQ (Qleft, Vdefault_frame_scroll_bars)
3867 ? vertical_scroll_bar_left
3868 : EQ (Qright, Vdefault_frame_scroll_bars)
3869 ? vertical_scroll_bar_right
3870 : vertical_scroll_bar_none);
3872 /* We set this parameter before creating the X window for the
3873 frame, so we can get the geometry right from the start.
3874 However, if the window hasn't been created yet, we shouldn't
3875 call x_set_window_size. */
3876 if (FRAME_X_WINDOW (f))
3877 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
3879 SET_FRAME_GARBAGED (f);
3883 void
3884 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3886 #if USE_HORIZONTAL_SCROLL_BARS
3887 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3888 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3890 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3892 /* We set this parameter before creating the X window for the
3893 frame, so we can get the geometry right from the start.
3894 However, if the window hasn't been created yet, we shouldn't
3895 call x_set_window_size. */
3896 if (FRAME_X_WINDOW (f))
3897 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
3899 SET_FRAME_GARBAGED (f);
3901 #endif
3904 void
3905 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3907 int unit = FRAME_COLUMN_WIDTH (f);
3909 if (NILP (arg))
3911 x_set_scroll_bar_default_width (f);
3913 if (FRAME_X_WINDOW (f))
3914 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3916 SET_FRAME_GARBAGED (f);
3918 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3919 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3921 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3922 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3923 if (FRAME_X_WINDOW (f))
3924 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3926 SET_FRAME_GARBAGED (f);
3929 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3930 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3933 void
3934 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3936 #if USE_HORIZONTAL_SCROLL_BARS
3937 int unit = FRAME_LINE_HEIGHT (f);
3939 if (NILP (arg))
3941 x_set_scroll_bar_default_height (f);
3943 if (FRAME_X_WINDOW (f))
3944 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3946 SET_FRAME_GARBAGED (f);
3948 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3949 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3951 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3952 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3953 if (FRAME_X_WINDOW (f))
3954 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3956 SET_FRAME_GARBAGED (f);
3959 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3960 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3961 #endif
3964 void
3965 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3967 double alpha = 1.0;
3968 double newval[2];
3969 int i;
3970 Lisp_Object item;
3972 for (i = 0; i < 2; i++)
3974 newval[i] = 1.0;
3975 if (CONSP (arg))
3977 item = CAR (arg);
3978 arg = CDR (arg);
3980 else
3981 item = arg;
3983 if (NILP (item))
3984 alpha = - 1.0;
3985 else if (FLOATP (item))
3987 alpha = XFLOAT_DATA (item);
3988 if (! (0 <= alpha && alpha <= 1.0))
3989 args_out_of_range (make_float (0.0), make_float (1.0));
3991 else if (INTEGERP (item))
3993 EMACS_INT ialpha = XINT (item);
3994 if (! (0 <= ialpha && alpha <= 100))
3995 args_out_of_range (make_number (0), make_number (100));
3996 alpha = ialpha / 100.0;
3998 else
3999 wrong_type_argument (Qnumberp, item);
4000 newval[i] = alpha;
4003 for (i = 0; i < 2; i++)
4004 f->alpha[i] = newval[i];
4006 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4007 block_input ();
4008 x_set_frame_alpha (f);
4009 unblock_input ();
4010 #endif
4012 return;
4015 #ifndef HAVE_NS
4017 /* Non-zero if mouse is grabbed on DPYINFO
4018 and we know the frame where it is. */
4020 bool x_mouse_grabbed (Display_Info *dpyinfo)
4022 return (dpyinfo->grabbed
4023 && dpyinfo->last_mouse_frame
4024 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4027 /* Re-highlight something with mouse-face properties
4028 on DPYINFO using saved frame and mouse position. */
4030 void
4031 x_redo_mouse_highlight (Display_Info *dpyinfo)
4033 if (dpyinfo->last_mouse_motion_frame
4034 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4035 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4036 dpyinfo->last_mouse_motion_x,
4037 dpyinfo->last_mouse_motion_y);
4040 #endif /* HAVE_NS */
4042 /* Subroutines of creating an X frame. */
4044 /* Make sure that Vx_resource_name is set to a reasonable value.
4045 Fix it up, or set it to `emacs' if it is too hopeless. */
4047 void
4048 validate_x_resource_name (void)
4050 ptrdiff_t len = 0;
4051 /* Number of valid characters in the resource name. */
4052 ptrdiff_t good_count = 0;
4053 /* Number of invalid characters in the resource name. */
4054 ptrdiff_t bad_count = 0;
4055 Lisp_Object new;
4056 ptrdiff_t i;
4058 if (!STRINGP (Vx_resource_class))
4059 Vx_resource_class = build_string (EMACS_CLASS);
4061 if (STRINGP (Vx_resource_name))
4063 unsigned char *p = SDATA (Vx_resource_name);
4065 len = SBYTES (Vx_resource_name);
4067 /* Only letters, digits, - and _ are valid in resource names.
4068 Count the valid characters and count the invalid ones. */
4069 for (i = 0; i < len; i++)
4071 int c = p[i];
4072 if (! ((c >= 'a' && c <= 'z')
4073 || (c >= 'A' && c <= 'Z')
4074 || (c >= '0' && c <= '9')
4075 || c == '-' || c == '_'))
4076 bad_count++;
4077 else
4078 good_count++;
4081 else
4082 /* Not a string => completely invalid. */
4083 bad_count = 5, good_count = 0;
4085 /* If name is valid already, return. */
4086 if (bad_count == 0)
4087 return;
4089 /* If name is entirely invalid, or nearly so, or is so implausibly
4090 large that alloca might not work, use `emacs'. */
4091 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4093 Vx_resource_name = build_string ("emacs");
4094 return;
4097 /* Name is partly valid. Copy it and replace the invalid characters
4098 with underscores. */
4100 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4102 for (i = 0; i < len; i++)
4104 int c = SREF (new, i);
4105 if (! ((c >= 'a' && c <= 'z')
4106 || (c >= 'A' && c <= 'Z')
4107 || (c >= '0' && c <= '9')
4108 || c == '-' || c == '_'))
4109 SSET (new, i, '_');
4113 /* Get specified attribute from resource database RDB.
4114 See Fx_get_resource below for other parameters. */
4116 static Lisp_Object
4117 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4119 CHECK_STRING (attribute);
4120 CHECK_STRING (class);
4122 if (!NILP (component))
4123 CHECK_STRING (component);
4124 if (!NILP (subclass))
4125 CHECK_STRING (subclass);
4126 if (NILP (component) != NILP (subclass))
4127 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4129 validate_x_resource_name ();
4131 /* Allocate space for the components, the dots which separate them,
4132 and the final '\0'. Make them big enough for the worst case. */
4133 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4134 + (STRINGP (component)
4135 ? SBYTES (component) : 0)
4136 + SBYTES (attribute)
4137 + 3);
4139 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4140 + SBYTES (class)
4141 + (STRINGP (subclass)
4142 ? SBYTES (subclass) : 0)
4143 + 3);
4144 USE_SAFE_ALLOCA;
4145 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4146 char *class_key = name_key + name_keysize;
4148 /* Start with emacs.FRAMENAME for the name (the specific one)
4149 and with `Emacs' for the class key (the general one). */
4150 char *nz = lispstpcpy (name_key, Vx_resource_name);
4151 char *cz = lispstpcpy (class_key, Vx_resource_class);
4153 *cz++ = '.';
4154 cz = lispstpcpy (cz, class);
4156 if (!NILP (component))
4158 *cz++ = '.';
4159 lispstpcpy (cz, subclass);
4161 *nz++ = '.';
4162 nz = lispstpcpy (nz, component);
4165 *nz++ = '.';
4166 lispstpcpy (nz, attribute);
4168 char *value = x_get_string_resource (rdb, name_key, class_key);
4169 SAFE_FREE();
4171 if (value && *value)
4172 return build_string (value);
4173 else
4174 return Qnil;
4178 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4179 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4180 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4181 class, where INSTANCE is the name under which Emacs was invoked, or
4182 the name specified by the `-name' or `-rn' command-line arguments.
4184 The optional arguments COMPONENT and SUBCLASS add to the key and the
4185 class, respectively. You must specify both of them or neither.
4186 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4187 and the class is `Emacs.CLASS.SUBCLASS'. */)
4188 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4189 Lisp_Object subclass)
4191 check_window_system (NULL);
4193 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4194 attribute, class, component, subclass);
4197 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4199 Lisp_Object
4200 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4201 Lisp_Object class, Lisp_Object component,
4202 Lisp_Object subclass)
4204 return xrdb_get_resource (dpyinfo->xrdb,
4205 attribute, class, component, subclass);
4208 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4209 /* Used when C code wants a resource value. */
4210 /* Called from oldXMenu/Create.c. */
4211 char *
4212 x_get_resource_string (const char *attribute, const char *class)
4214 char *result;
4215 struct frame *sf = SELECTED_FRAME ();
4216 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4217 USE_SAFE_ALLOCA;
4219 /* Allocate space for the components, the dots which separate them,
4220 and the final '\0'. */
4221 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4222 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4223 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4224 char *class_key = name_key + name_keysize;
4226 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4227 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4229 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4230 name_key, class_key);
4231 SAFE_FREE ();
4232 return result;
4234 #endif
4236 /* Return the value of parameter PARAM.
4238 First search ALIST, then Vdefault_frame_alist, then the X defaults
4239 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4241 Convert the resource to the type specified by desired_type.
4243 If no default is specified, return Qunbound. If you call
4244 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4245 and don't let it get stored in any Lisp-visible variables! */
4247 Lisp_Object
4248 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4249 const char *attribute, const char *class, enum resource_types type)
4251 Lisp_Object tem;
4253 tem = Fassq (param, alist);
4255 if (!NILP (tem))
4257 /* If we find this parm in ALIST, clear it out
4258 so that it won't be "left over" at the end. */
4259 Lisp_Object tail;
4260 XSETCAR (tem, Qnil);
4261 /* In case the parameter appears more than once in the alist,
4262 clear it out. */
4263 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4264 if (CONSP (XCAR (tail))
4265 && EQ (XCAR (XCAR (tail)), param))
4266 XSETCAR (XCAR (tail), Qnil);
4268 else
4269 tem = Fassq (param, Vdefault_frame_alist);
4271 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4272 look in the X resources. */
4273 if (EQ (tem, Qnil))
4275 if (attribute && dpyinfo)
4277 AUTO_STRING (at, attribute);
4278 AUTO_STRING (cl, class);
4279 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4281 if (NILP (tem))
4282 return Qunbound;
4284 switch (type)
4286 case RES_TYPE_NUMBER:
4287 return make_number (atoi (SSDATA (tem)));
4289 case RES_TYPE_BOOLEAN_NUMBER:
4290 if (!strcmp (SSDATA (tem), "on")
4291 || !strcmp (SSDATA (tem), "true"))
4292 return make_number (1);
4293 return make_number (atoi (SSDATA (tem)));
4294 break;
4296 case RES_TYPE_FLOAT:
4297 return make_float (atof (SSDATA (tem)));
4299 case RES_TYPE_BOOLEAN:
4300 tem = Fdowncase (tem);
4301 if (!strcmp (SSDATA (tem), "on")
4302 #ifdef HAVE_NS
4303 || !strcmp (SSDATA (tem), "yes")
4304 #endif
4305 || !strcmp (SSDATA (tem), "true"))
4306 return Qt;
4307 else
4308 return Qnil;
4310 case RES_TYPE_STRING:
4311 return tem;
4313 case RES_TYPE_SYMBOL:
4314 /* As a special case, we map the values `true' and `on'
4315 to Qt, and `false' and `off' to Qnil. */
4317 Lisp_Object lower;
4318 lower = Fdowncase (tem);
4319 if (!strcmp (SSDATA (lower), "on")
4320 #ifdef HAVE_NS
4321 || !strcmp (SSDATA (lower), "yes")
4322 #endif
4323 || !strcmp (SSDATA (lower), "true"))
4324 return Qt;
4325 else if (!strcmp (SSDATA (lower), "off")
4326 #ifdef HAVE_NS
4327 || !strcmp (SSDATA (lower), "no")
4328 #endif
4329 || !strcmp (SSDATA (lower), "false"))
4330 return Qnil;
4331 else
4332 return Fintern (tem, Qnil);
4335 default:
4336 emacs_abort ();
4339 else
4340 return Qunbound;
4342 return Fcdr (tem);
4345 static Lisp_Object
4346 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4347 const char *attribute, const char *class,
4348 enum resource_types type)
4350 return x_get_arg (FRAME_DISPLAY_INFO (f),
4351 alist, param, attribute, class, type);
4354 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4356 Lisp_Object
4357 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4358 Lisp_Object param,
4359 const char *attribute, const char *class,
4360 enum resource_types type)
4362 Lisp_Object value;
4364 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4365 attribute, class, type);
4366 if (! NILP (value) && ! EQ (value, Qunbound))
4367 store_frame_param (f, param, value);
4369 return value;
4373 /* Record in frame F the specified or default value according to ALIST
4374 of the parameter named PROP (a Lisp symbol).
4375 If no value is specified for PROP, look for an X default for XPROP
4376 on the frame named NAME.
4377 If that is not found either, use the value DEFLT. */
4379 Lisp_Object
4380 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4381 Lisp_Object deflt, const char *xprop, const char *xclass,
4382 enum resource_types type)
4384 Lisp_Object tem;
4386 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4387 if (EQ (tem, Qunbound))
4388 tem = deflt;
4389 AUTO_FRAME_ARG (arg, prop, tem);
4390 x_set_frame_parameters (f, arg);
4391 return tem;
4395 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4398 * XParseGeometry parses strings of the form
4399 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4400 * width, height, xoffset, and yoffset are unsigned integers.
4401 * Example: "=80x24+300-49"
4402 * The equal sign is optional.
4403 * It returns a bitmask that indicates which of the four values
4404 * were actually found in the string. For each value found,
4405 * the corresponding argument is updated; for each value
4406 * not found, the corresponding argument is left unchanged.
4409 static int
4410 XParseGeometry (char *string,
4411 int *x, int *y,
4412 unsigned int *width, unsigned int *height)
4414 int mask = NoValue;
4415 char *strind;
4416 unsigned long tempWidth, tempHeight;
4417 long int tempX, tempY;
4418 char *nextCharacter;
4420 if (string == NULL || *string == '\0')
4421 return mask;
4422 if (*string == '=')
4423 string++; /* ignore possible '=' at beg of geometry spec */
4425 strind = string;
4426 if (*strind != '+' && *strind != '-' && *strind != 'x')
4428 tempWidth = strtoul (strind, &nextCharacter, 10);
4429 if (strind == nextCharacter)
4430 return 0;
4431 strind = nextCharacter;
4432 mask |= WidthValue;
4435 if (*strind == 'x' || *strind == 'X')
4437 strind++;
4438 tempHeight = strtoul (strind, &nextCharacter, 10);
4439 if (strind == nextCharacter)
4440 return 0;
4441 strind = nextCharacter;
4442 mask |= HeightValue;
4445 if (*strind == '+' || *strind == '-')
4447 if (*strind == '-')
4448 mask |= XNegative;
4449 tempX = strtol (strind, &nextCharacter, 10);
4450 if (strind == nextCharacter)
4451 return 0;
4452 strind = nextCharacter;
4453 mask |= XValue;
4454 if (*strind == '+' || *strind == '-')
4456 if (*strind == '-')
4457 mask |= YNegative;
4458 tempY = strtol (strind, &nextCharacter, 10);
4459 if (strind == nextCharacter)
4460 return 0;
4461 strind = nextCharacter;
4462 mask |= YValue;
4466 /* If strind isn't at the end of the string then it's an invalid
4467 geometry specification. */
4469 if (*strind != '\0')
4470 return 0;
4472 if (mask & XValue)
4473 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4474 if (mask & YValue)
4475 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4476 if (mask & WidthValue)
4477 *width = min (tempWidth, UINT_MAX);
4478 if (mask & HeightValue)
4479 *height = min (tempHeight, UINT_MAX);
4480 return mask;
4483 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4486 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4487 make-docfile: the documentation string in ns-win.el was used for
4488 x-parse-geometry even in non-NS builds.
4490 With two definitions of x-parse-geometry in this file, various
4491 things still get confused (eg M-x apropos documentation), so that
4492 it is best if the two definitions just share the same doc-string.
4494 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4495 doc: /* Parse a display geometry string STRING.
4496 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4497 The properties returned may include `top', `left', `height', and `width'.
4498 For X, the value of `left' or `top' may be an integer,
4499 or a list (+ N) meaning N pixels relative to top/left corner,
4500 or a list (- N) meaning -N pixels relative to bottom/right corner.
4501 On Nextstep, this just calls `ns-parse-geometry'. */)
4502 (Lisp_Object string)
4504 int geometry, x, y;
4505 unsigned int width, height;
4506 Lisp_Object result;
4508 CHECK_STRING (string);
4510 #ifdef HAVE_NS
4511 if (strchr (SSDATA (string), ' ') != NULL)
4512 return call1 (Qns_parse_geometry, string);
4513 #endif
4514 geometry = XParseGeometry (SSDATA (string),
4515 &x, &y, &width, &height);
4516 result = Qnil;
4517 if (geometry & XValue)
4519 Lisp_Object element;
4521 if (x >= 0 && (geometry & XNegative))
4522 element = list3 (Qleft, Qminus, make_number (-x));
4523 else if (x < 0 && ! (geometry & XNegative))
4524 element = list3 (Qleft, Qplus, make_number (x));
4525 else
4526 element = Fcons (Qleft, make_number (x));
4527 result = Fcons (element, result);
4530 if (geometry & YValue)
4532 Lisp_Object element;
4534 if (y >= 0 && (geometry & YNegative))
4535 element = list3 (Qtop, Qminus, make_number (-y));
4536 else if (y < 0 && ! (geometry & YNegative))
4537 element = list3 (Qtop, Qplus, make_number (y));
4538 else
4539 element = Fcons (Qtop, make_number (y));
4540 result = Fcons (element, result);
4543 if (geometry & WidthValue)
4544 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4545 if (geometry & HeightValue)
4546 result = Fcons (Fcons (Qheight, make_number (height)), result);
4548 return result;
4552 /* Calculate the desired size and position of frame F.
4553 Return the flags saying which aspects were specified.
4555 Also set the win_gravity and size_hint_flags of F.
4557 Adjust height for toolbar if TOOLBAR_P is 1.
4559 This function does not make the coordinates positive. */
4561 #define DEFAULT_ROWS 35
4562 #define DEFAULT_COLS 80
4564 long
4565 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
4567 Lisp_Object height, width, user_size, top, left, user_position;
4568 long window_prompting = 0;
4569 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4571 /* Default values if we fall through.
4572 Actually, if that happens we should get
4573 window manager prompting. */
4574 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4575 SET_FRAME_COLS (f, DEFAULT_COLS);
4576 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4577 SET_FRAME_LINES (f, DEFAULT_ROWS);
4579 /* Window managers expect that if program-specified
4580 positions are not (0,0), they're intentional, not defaults. */
4581 f->top_pos = 0;
4582 f->left_pos = 0;
4584 /* Calculate a tool bar height so that the user gets a text display
4585 area of the size he specified with -g or via .Xdefaults. Later
4586 changes of the tool bar height don't change the frame size. This
4587 is done so that users can create tall Emacs frames without having
4588 to guess how tall the tool bar will get. */
4589 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4591 if (frame_default_tool_bar_height)
4592 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
4593 else
4595 int margin, relief;
4597 relief = (tool_bar_button_relief >= 0
4598 ? tool_bar_button_relief
4599 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4601 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4602 margin = XFASTINT (Vtool_bar_button_margin);
4603 else if (CONSP (Vtool_bar_button_margin)
4604 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4605 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4606 else
4607 margin = 0;
4609 FRAME_TOOL_BAR_HEIGHT (f)
4610 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4614 /* Ensure that earlier new_width and new_height settings won't
4615 override what we specify below. */
4616 f->new_width = f->new_height = 0;
4618 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4619 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4620 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4622 if (!EQ (width, Qunbound))
4624 if (CONSP (width) && EQ (XCAR (width), Qtext_pixels))
4626 CHECK_NUMBER (XCDR (width));
4627 if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX))
4628 xsignal1 (Qargs_out_of_range, XCDR (width));
4630 SET_FRAME_WIDTH (f, XINT (XCDR (width)));
4631 f->inhibit_horizontal_resize = true;
4632 *x_width = XINT (XCDR (width));
4634 else
4636 CHECK_NUMBER (width);
4637 if ((XINT (width) < 0 || XINT (width) > INT_MAX))
4638 xsignal1 (Qargs_out_of_range, width);
4640 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4644 if (!EQ (height, Qunbound))
4646 if (CONSP (height) && EQ (XCAR (height), Qtext_pixels))
4648 CHECK_NUMBER (XCDR (height));
4649 if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX))
4650 xsignal1 (Qargs_out_of_range, XCDR (height));
4652 SET_FRAME_HEIGHT (f, XINT (XCDR (height)));
4653 f->inhibit_vertical_resize = true;
4654 *x_height = XINT (XCDR (height));
4656 else
4658 CHECK_NUMBER (height);
4659 if ((XINT (height) < 0) || (XINT (height) > INT_MAX))
4660 xsignal1 (Qargs_out_of_range, height);
4662 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4666 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4667 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4668 window_prompting |= USSize;
4669 else
4670 window_prompting |= PSize;
4673 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4674 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4675 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4676 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4678 if (EQ (top, Qminus))
4680 f->top_pos = 0;
4681 window_prompting |= YNegative;
4683 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4684 && CONSP (XCDR (top))
4685 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4687 f->top_pos = - XINT (XCAR (XCDR (top)));
4688 window_prompting |= YNegative;
4690 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4691 && CONSP (XCDR (top))
4692 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4694 f->top_pos = XINT (XCAR (XCDR (top)));
4696 else if (EQ (top, Qunbound))
4697 f->top_pos = 0;
4698 else
4700 CHECK_TYPE_RANGED_INTEGER (int, top);
4701 f->top_pos = XINT (top);
4702 if (f->top_pos < 0)
4703 window_prompting |= YNegative;
4706 if (EQ (left, Qminus))
4708 f->left_pos = 0;
4709 window_prompting |= XNegative;
4711 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4712 && CONSP (XCDR (left))
4713 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4715 f->left_pos = - XINT (XCAR (XCDR (left)));
4716 window_prompting |= XNegative;
4718 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4719 && CONSP (XCDR (left))
4720 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4722 f->left_pos = XINT (XCAR (XCDR (left)));
4724 else if (EQ (left, Qunbound))
4725 f->left_pos = 0;
4726 else
4728 CHECK_TYPE_RANGED_INTEGER (int, left);
4729 f->left_pos = XINT (left);
4730 if (f->left_pos < 0)
4731 window_prompting |= XNegative;
4734 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4735 window_prompting |= USPosition;
4736 else
4737 window_prompting |= PPosition;
4740 if (window_prompting & XNegative)
4742 if (window_prompting & YNegative)
4743 f->win_gravity = SouthEastGravity;
4744 else
4745 f->win_gravity = NorthEastGravity;
4747 else
4749 if (window_prompting & YNegative)
4750 f->win_gravity = SouthWestGravity;
4751 else
4752 f->win_gravity = NorthWestGravity;
4755 f->size_hint_flags = window_prompting;
4757 return window_prompting;
4762 #endif /* HAVE_WINDOW_SYSTEM */
4764 void
4765 frame_make_pointer_invisible (struct frame *f)
4767 if (! NILP (Vmake_pointer_invisible))
4769 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4770 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4772 f->mouse_moved = 0;
4773 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4774 f->pointer_invisible = 1;
4779 void
4780 frame_make_pointer_visible (struct frame *f)
4782 /* We don't check Vmake_pointer_invisible here in case the
4783 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4784 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4785 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4787 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4788 f->pointer_invisible = 0;
4792 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4793 Sframe_pointer_visible_p, 0, 1, 0,
4794 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4795 Otherwise it returns nil. FRAME omitted or nil means the
4796 selected frame. This is useful when `make-pointer-invisible' is set. */)
4797 (Lisp_Object frame)
4799 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4804 /***********************************************************************
4805 Multimonitor data
4806 ***********************************************************************/
4808 #ifdef HAVE_WINDOW_SYSTEM
4810 # if (defined HAVE_NS \
4811 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4812 void
4813 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4815 int i;
4816 for (i = 0; i < n_monitors; ++i)
4817 xfree (monitors[i].name);
4818 xfree (monitors);
4820 # endif
4822 Lisp_Object
4823 make_monitor_attribute_list (struct MonitorInfo *monitors,
4824 int n_monitors,
4825 int primary_monitor,
4826 Lisp_Object monitor_frames,
4827 const char *source)
4829 Lisp_Object attributes_list = Qnil;
4830 Lisp_Object primary_monitor_attributes = Qnil;
4831 int i;
4833 for (i = 0; i < n_monitors; ++i)
4835 Lisp_Object geometry, workarea, attributes = Qnil;
4836 struct MonitorInfo *mi = &monitors[i];
4838 if (mi->geom.width == 0) continue;
4840 workarea = list4i (mi->work.x, mi->work.y,
4841 mi->work.width, mi->work.height);
4842 geometry = list4i (mi->geom.x, mi->geom.y,
4843 mi->geom.width, mi->geom.height);
4844 attributes = Fcons (Fcons (Qsource, build_string (source)),
4845 attributes);
4846 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4847 attributes);
4848 attributes = Fcons (Fcons (Qmm_size,
4849 list2i (mi->mm_width, mi->mm_height)),
4850 attributes);
4851 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4852 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4853 if (mi->name)
4854 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4855 strlen (mi->name))),
4856 attributes);
4858 if (i == primary_monitor)
4859 primary_monitor_attributes = attributes;
4860 else
4861 attributes_list = Fcons (attributes, attributes_list);
4864 if (!NILP (primary_monitor_attributes))
4865 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4866 return attributes_list;
4869 #endif /* HAVE_WINDOW_SYSTEM */
4872 /***********************************************************************
4873 Initialization
4874 ***********************************************************************/
4876 void
4877 syms_of_frame (void)
4879 DEFSYM (Qframep, "framep");
4880 DEFSYM (Qframe_live_p, "frame-live-p");
4881 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4882 DEFSYM (Qwindow_pixel_to_total, "window--pixel-to-total");
4883 DEFSYM (Qexplicit_name, "explicit-name");
4884 DEFSYM (Qheight, "height");
4885 DEFSYM (Qicon, "icon");
4886 DEFSYM (Qminibuffer, "minibuffer");
4887 DEFSYM (Qmodeline, "modeline");
4888 DEFSYM (Qonly, "only");
4889 DEFSYM (Qnone, "none");
4890 DEFSYM (Qwidth, "width");
4891 DEFSYM (Qtext_pixels, "text-pixels");
4892 DEFSYM (Qgeometry, "geometry");
4893 DEFSYM (Qicon_left, "icon-left");
4894 DEFSYM (Qicon_top, "icon-top");
4895 DEFSYM (Qtooltip, "tooltip");
4896 DEFSYM (Quser_position, "user-position");
4897 DEFSYM (Quser_size, "user-size");
4898 DEFSYM (Qwindow_id, "window-id");
4899 #ifdef HAVE_X_WINDOWS
4900 DEFSYM (Qouter_window_id, "outer-window-id");
4901 #endif
4902 DEFSYM (Qparent_id, "parent-id");
4903 DEFSYM (Qx, "x");
4904 DEFSYM (Qw32, "w32");
4905 DEFSYM (Qpc, "pc");
4906 DEFSYM (Qns, "ns");
4907 DEFSYM (Qvisible, "visible");
4908 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4909 DEFSYM (Qbuffer_list, "buffer-list");
4910 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4911 DEFSYM (Qdisplay_type, "display-type");
4912 DEFSYM (Qbackground_mode, "background-mode");
4913 DEFSYM (Qnoelisp, "noelisp");
4914 DEFSYM (Qtty_color_mode, "tty-color-mode");
4915 DEFSYM (Qtty, "tty");
4916 DEFSYM (Qtty_type, "tty-type");
4918 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4920 DEFSYM (Qfullwidth, "fullwidth");
4921 DEFSYM (Qfullheight, "fullheight");
4922 DEFSYM (Qfullboth, "fullboth");
4923 DEFSYM (Qmaximized, "maximized");
4924 DEFSYM (Qx_resource_name, "x-resource-name");
4925 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4927 DEFSYM (Qterminal, "terminal");
4929 DEFSYM (Qworkarea, "workarea");
4930 DEFSYM (Qmm_size, "mm-size");
4931 DEFSYM (Qframes, "frames");
4932 DEFSYM (Qsource, "source");
4934 DEFSYM (Qouter_edges, "outer-edges");
4935 DEFSYM (Qouter_position, "outer-position");
4936 DEFSYM (Qouter_size, "outer-size");
4937 DEFSYM (Qnative_edges, "native-edges");
4938 DEFSYM (Qinner_edges, "inner-edges");
4939 DEFSYM (Qexternal_border_size, "external-border-size");
4940 DEFSYM (Qtitle_bar_size, "title-bar-size");
4941 DEFSYM (Qmenu_bar_external, "menu-bar-external");
4942 DEFSYM (Qmenu_bar_size, "menu-bar-size");
4943 DEFSYM (Qtool_bar_external, "tool-bar-external");
4944 DEFSYM (Qtool_bar_size, "tool-bar-size");
4945 /* The following are used for frame_size_history. */
4946 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
4947 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
4948 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
4949 DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
4950 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
4951 DEFSYM (Qset_frame_size, "set-frame-size");
4952 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
4953 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
4954 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
4955 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
4956 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
4957 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
4958 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
4959 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
4960 DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
4961 DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
4962 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
4963 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
4964 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
4965 DEFSYM (Qtb_size_cb, "tb-size-cb");
4966 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
4967 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
4968 DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines");
4969 DEFSYM (Qchange_frame_size, "change-frame-size");
4970 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
4971 DEFSYM (Qset_window_configuration, "set-window-configuration");
4972 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
4973 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
4974 DEFSYM (Qterminal_frame, "terminal-frame");
4976 #ifdef HAVE_NS
4977 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4978 #endif
4980 DEFSYM (Qalpha, "alpha");
4981 DEFSYM (Qauto_lower, "auto-lower");
4982 DEFSYM (Qauto_raise, "auto-raise");
4983 DEFSYM (Qborder_color, "border-color");
4984 DEFSYM (Qborder_width, "border-width");
4985 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
4986 DEFSYM (Qcursor_color, "cursor-color");
4987 DEFSYM (Qcursor_type, "cursor-type");
4988 DEFSYM (Qfont_backend, "font-backend");
4989 DEFSYM (Qfullscreen, "fullscreen");
4990 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
4991 DEFSYM (Qicon_name, "icon-name");
4992 DEFSYM (Qicon_type, "icon-type");
4993 DEFSYM (Qinternal_border_width, "internal-border-width");
4994 DEFSYM (Qleft_fringe, "left-fringe");
4995 DEFSYM (Qline_spacing, "line-spacing");
4996 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
4997 DEFSYM (Qupdate_frame_menubar, "update-frame-menubar");
4998 DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1");
4999 DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2");
5000 DEFSYM (Qmouse_color, "mouse-color");
5001 DEFSYM (Qname, "name");
5002 DEFSYM (Qright_divider_width, "right-divider-width");
5003 DEFSYM (Qright_fringe, "right-fringe");
5004 DEFSYM (Qscreen_gamma, "screen-gamma");
5005 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
5006 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
5007 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
5008 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
5009 DEFSYM (Qsticky, "sticky");
5010 DEFSYM (Qtitle, "title");
5011 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
5012 DEFSYM (Qtool_bar_position, "tool-bar-position");
5013 DEFSYM (Qunsplittable, "unsplittable");
5014 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
5015 DEFSYM (Qvisibility, "visibility");
5016 DEFSYM (Qwait_for_wm, "wait-for-wm");
5019 int i;
5021 for (i = 0; i < ARRAYELTS (frame_parms); i++)
5023 Lisp_Object v = (frame_parms[i].sym < 0
5024 ? intern_c_string (frame_parms[i].name)
5025 : builtin_lisp_symbol (frame_parms[i].sym));
5026 Fput (v, Qx_frame_parameter, make_number (i));
5030 #ifdef HAVE_WINDOW_SYSTEM
5031 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
5032 doc: /* The name Emacs uses to look up X resources.
5033 `x-get-resource' uses this as the first component of the instance name
5034 when requesting resource values.
5035 Emacs initially sets `x-resource-name' to the name under which Emacs
5036 was invoked, or to the value specified with the `-name' or `-rn'
5037 switches, if present.
5039 It may be useful to bind this variable locally around a call
5040 to `x-get-resource'. See also the variable `x-resource-class'. */);
5041 Vx_resource_name = Qnil;
5043 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5044 doc: /* The class Emacs uses to look up X resources.
5045 `x-get-resource' uses this as the first component of the instance class
5046 when requesting resource values.
5048 Emacs initially sets `x-resource-class' to "Emacs".
5050 Setting this variable permanently is not a reasonable thing to do,
5051 but binding this variable locally around a call to `x-get-resource'
5052 is a reasonable practice. See also the variable `x-resource-name'. */);
5053 Vx_resource_class = build_string (EMACS_CLASS);
5055 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5056 doc: /* The lower limit of the frame opacity (alpha transparency).
5057 The value should range from 0 (invisible) to 100 (completely opaque).
5058 You can also use a floating number between 0.0 and 1.0. */);
5059 Vframe_alpha_lower_limit = make_number (20);
5060 #endif
5062 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5063 doc: /* Alist of default values for frame creation.
5064 These may be set in your init file, like this:
5065 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5066 These override values given in window system configuration data,
5067 including X Windows' defaults database.
5068 For values specific to the first Emacs frame, see `initial-frame-alist'.
5069 For window-system specific values, see `window-system-default-frame-alist'.
5070 For values specific to the separate minibuffer frame, see
5071 `minibuffer-frame-alist'.
5072 The `menu-bar-lines' element of the list controls whether new frames
5073 have menu bars; `menu-bar-mode' works by altering this element.
5074 Setting this variable does not affect existing frames, only new ones. */);
5075 Vdefault_frame_alist = Qnil;
5077 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5078 doc: /* Default position of vertical scroll bars on this window-system. */);
5079 #ifdef HAVE_WINDOW_SYSTEM
5080 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5081 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
5082 default. */
5083 Vdefault_frame_scroll_bars = Qright;
5084 #else
5085 Vdefault_frame_scroll_bars = Qleft;
5086 #endif
5087 #else
5088 Vdefault_frame_scroll_bars = Qnil;
5089 #endif
5091 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5092 scroll_bar_adjust_thumb_portion_p,
5093 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5094 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5095 even if the end of the buffer is shown (i.e. overscrolling).
5096 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5097 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5098 is visible. In this case you can not overscroll. */);
5099 scroll_bar_adjust_thumb_portion_p = 1;
5101 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5102 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5104 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5105 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5106 `mouse-position' and `mouse-pixel-position' call this function, passing their
5107 usual return value as argument, and return whatever this function returns.
5108 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5109 which need to do mouse handling at the Lisp level. */);
5110 Vmouse_position_function = Qnil;
5112 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5113 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5114 If the value is an integer, highlighting is only shown after moving the
5115 mouse, while keyboard input turns off the highlight even when the mouse
5116 is over the clickable text. However, the mouse shape still indicates
5117 when the mouse is over clickable text. */);
5118 Vmouse_highlight = Qt;
5120 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5121 doc: /* If non-nil, make pointer invisible while typing.
5122 The pointer becomes visible again when the mouse is moved. */);
5123 Vmake_pointer_invisible = Qt;
5125 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5126 doc: /* Normal hook run when a frame gains input focus. */);
5127 Vfocus_in_hook = Qnil;
5129 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5130 doc: /* Normal hook run when a frame loses input focus. */);
5131 Vfocus_out_hook = Qnil;
5133 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5134 doc: /* Functions run before deleting a frame.
5135 The functions are run with one arg, the frame to be deleted.
5136 See `delete-frame'.
5138 Note that functions in this list may be called just before the frame is
5139 actually deleted, or some time later (or even both when an earlier function
5140 in `delete-frame-functions' (indirectly) calls `delete-frame'
5141 recursively). */);
5142 Vdelete_frame_functions = Qnil;
5143 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5145 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5146 doc: /* Non-nil if Menu-Bar mode is enabled.
5147 See the command `menu-bar-mode' for a description of this minor mode.
5148 Setting this variable directly does not take effect;
5149 either customize it (see the info node `Easy Customization')
5150 or call the function `menu-bar-mode'. */);
5151 Vmenu_bar_mode = Qt;
5153 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5154 doc: /* Non-nil if Tool-Bar mode is enabled.
5155 See the command `tool-bar-mode' for a description of this minor mode.
5156 Setting this variable directly does not take effect;
5157 either customize it (see the info node `Easy Customization')
5158 or call the function `tool-bar-mode'. */);
5159 #ifdef HAVE_WINDOW_SYSTEM
5160 Vtool_bar_mode = Qt;
5161 #else
5162 Vtool_bar_mode = Qnil;
5163 #endif
5165 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5166 doc: /* Minibufferless frames use this frame's minibuffer.
5167 Emacs cannot create minibufferless frames unless this is set to an
5168 appropriate surrogate.
5170 Emacs consults this variable only when creating minibufferless
5171 frames; once the frame is created, it sticks with its assigned
5172 minibuffer, no matter what this variable is set to. This means that
5173 this variable doesn't necessarily say anything meaningful about the
5174 current set of frames, or where the minibuffer is currently being
5175 displayed.
5177 This variable is local to the current terminal and cannot be buffer-local. */);
5179 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
5180 doc: /* Non-nil if window system changes focus when you move the mouse.
5181 You should set this variable to tell Emacs how your window manager
5182 handles focus, since there is no way in general for Emacs to find out
5183 automatically. See also `mouse-autoselect-window'. */);
5184 focus_follows_mouse = 0;
5186 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5187 doc: /* Non-nil means resize frames pixelwise.
5188 If this option is nil, resizing a frame rounds its sizes to the frame's
5189 current values of `frame-char-height' and `frame-char-width'. If this
5190 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5191 by one pixel.
5193 With some window managers you may have to set this to non-nil in order
5194 to set the size of a frame in pixels, to maximize frames or to make them
5195 fullscreen. To resize your initial frame pixelwise, set this option to
5196 a non-nil value in your init file. */);
5197 frame_resize_pixelwise = 0;
5199 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5200 doc: /* Whether frames should be resized implicitly.
5201 If this option is nil, setting font, menu bar, tool bar, internal
5202 borders, fringes or scroll bars of a specific frame may resize the frame
5203 in order to preserve the number of columns or lines it displays. If
5204 this option is t, no such resizing is done. Note that the size of
5205 fullscreen and maximized frames, the height of fullheight frames and the
5206 width of fullwidth frames never change implicitly.
5208 The value of this option can be also be a list of frame parameters. In
5209 this case, resizing is inhibited when changing a parameter that appears
5210 in that list. The parameters currently handled by this option include
5211 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5212 `tool-bar-lines'.
5214 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5215 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5216 `right-fringe' is handled as if the frame contained just one live
5217 window. This means, for example, that removing vertical scroll bars on
5218 a frame containing several side by side windows will shrink the frame
5219 width by the width of one scroll bar provided this option is nil and
5220 keep it unchanged if this option is either t or a list containing
5221 `vertical-scroll-bars'.
5223 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
5224 (which means that adding/removing a tool bar does not change the frame
5225 height), nil on all other window systems including GTK+ (which means
5226 that changing any of the parameters listed above may change the size of
5227 the frame), and t otherwise (which means the frame size never changes
5228 implicitly when there's no window system support).
5230 Note that when a frame is not large enough to accommodate a change of
5231 any of the parameters listed above, Emacs may try to enlarge the frame
5232 even if this option is non-nil. */);
5233 #if defined (HAVE_WINDOW_SYSTEM)
5234 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
5235 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
5236 #else
5237 frame_inhibit_implied_resize = Qnil;
5238 #endif
5239 #else
5240 frame_inhibit_implied_resize = Qt;
5241 #endif
5243 DEFVAR_LISP ("frame-size-history", frame_size_history,
5244 doc: /* History of frame size adjustments.
5245 If non-nil, list recording frame size adjustment. Adjustments are
5246 recorded only if the first element of this list is a positive number.
5247 Adding an adjustment decrements that number by one.
5249 The remaining elements are the adjustments. Each adjustment is a list
5250 of four elements `frame', `function', `sizes' and `more'. `frame' is
5251 the affected frame and `function' the invoking function. `sizes' is
5252 usually a list of four elements `old-width', `old-height', `new-width'
5253 and `new-height' representing the old and new sizes recorded/requested
5254 by `function'. `more' is a list with additional information.
5256 The function `frame--size-history' displays the value of this variable
5257 in a more readable form. */);
5258 frame_size_history = Qnil;
5260 staticpro (&Vframe_list);
5262 defsubr (&Sframep);
5263 defsubr (&Sframe_live_p);
5264 defsubr (&Swindow_system);
5265 defsubr (&Sframe_windows_min_size);
5266 defsubr (&Smake_terminal_frame);
5267 defsubr (&Shandle_switch_frame);
5268 defsubr (&Sselect_frame);
5269 defsubr (&Sselected_frame);
5270 defsubr (&Sframe_list);
5271 defsubr (&Snext_frame);
5272 defsubr (&Sprevious_frame);
5273 defsubr (&Slast_nonminibuf_frame);
5274 defsubr (&Sdelete_frame);
5275 defsubr (&Smouse_position);
5276 defsubr (&Smouse_pixel_position);
5277 defsubr (&Sset_mouse_position);
5278 defsubr (&Sset_mouse_pixel_position);
5279 #if 0
5280 defsubr (&Sframe_configuration);
5281 defsubr (&Srestore_frame_configuration);
5282 #endif
5283 defsubr (&Smake_frame_visible);
5284 defsubr (&Smake_frame_invisible);
5285 defsubr (&Siconify_frame);
5286 defsubr (&Sframe_visible_p);
5287 defsubr (&Svisible_frame_list);
5288 defsubr (&Sraise_frame);
5289 defsubr (&Slower_frame);
5290 defsubr (&Sx_focus_frame);
5291 defsubr (&Sframe_after_make_frame);
5292 defsubr (&Sredirect_frame_focus);
5293 defsubr (&Sframe_focus);
5294 defsubr (&Sframe_parameters);
5295 defsubr (&Sframe_parameter);
5296 defsubr (&Smodify_frame_parameters);
5297 defsubr (&Sframe_char_height);
5298 defsubr (&Sframe_char_width);
5299 defsubr (&Sframe_pixel_height);
5300 defsubr (&Sframe_pixel_width);
5301 defsubr (&Sframe_text_cols);
5302 defsubr (&Sframe_text_lines);
5303 defsubr (&Sframe_total_cols);
5304 defsubr (&Sframe_total_lines);
5305 defsubr (&Sframe_text_width);
5306 defsubr (&Sframe_text_height);
5307 defsubr (&Sscroll_bar_width);
5308 defsubr (&Sscroll_bar_height);
5309 defsubr (&Sfringe_width);
5310 defsubr (&Sborder_width);
5311 defsubr (&Sright_divider_width);
5312 defsubr (&Sbottom_divider_width);
5313 defsubr (&Stool_bar_pixel_width);
5314 defsubr (&Sset_frame_height);
5315 defsubr (&Sset_frame_width);
5316 defsubr (&Sset_frame_size);
5317 defsubr (&Sframe_position);
5318 defsubr (&Sset_frame_position);
5319 defsubr (&Sframe_pointer_visible_p);
5321 #ifdef HAVE_WINDOW_SYSTEM
5322 defsubr (&Sx_get_resource);
5323 defsubr (&Sx_parse_geometry);
5324 #endif