Set can_x_set_window_size and after_make_frame in terminal frames (Bug#19962)
[emacs.git] / src / frame.c
blob4a526e228f95772abfaaee3a61112db71710460b
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2015 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <errno.h>
24 #include <limits.h>
26 #include <c-ctype.h>
28 #include "lisp.h"
29 #include "character.h"
31 #ifdef HAVE_WINDOW_SYSTEM
32 #include TERM_HEADER
33 #endif /* HAVE_WINDOW_SYSTEM */
35 #include "buffer.h"
36 /* These help us bind and responding to switch-frame events. */
37 #include "commands.h"
38 #include "keyboard.h"
39 #include "frame.h"
40 #include "blockinput.h"
41 #include "termchar.h"
42 #include "termhooks.h"
43 #include "dispextern.h"
44 #include "window.h"
45 #include "font.h"
46 #ifdef HAVE_WINDOW_SYSTEM
47 #include "fontset.h"
48 #endif
49 #include "cm.h"
50 #ifdef MSDOS
51 #include "msdos.h"
52 #include "dosfns.h"
53 #endif
54 #ifdef USE_X_TOOLKIT
55 #include "widget.h"
56 #endif
58 /* The currently selected frame. */
60 Lisp_Object selected_frame;
62 /* A frame which is not just a mini-buffer, or NULL if there are no such
63 frames. This is usually the most recent such frame that was selected. */
65 static struct frame *last_nonminibuf_frame;
67 /* False means there are no visible garbaged frames. */
68 bool frame_garbaged;
70 /* The default tool bar height for future frames. */
71 #if defined USE_GTK || defined HAVE_NS
72 enum { frame_default_tool_bar_height = 0 };
73 #else
74 int frame_default_tool_bar_height;
75 #endif
77 #ifdef HAVE_WINDOW_SYSTEM
78 static void x_report_frame_params (struct frame *, Lisp_Object *);
79 #endif
81 /* These setters are used only in this file, so they can be private. */
82 static void
83 fset_buffer_predicate (struct frame *f, Lisp_Object val)
85 f->buffer_predicate = val;
87 static void
88 fset_minibuffer_window (struct frame *f, Lisp_Object val)
90 f->minibuffer_window = val;
93 struct frame *
94 decode_live_frame (register Lisp_Object frame)
96 if (NILP (frame))
97 frame = selected_frame;
98 CHECK_LIVE_FRAME (frame);
99 return XFRAME (frame);
102 struct frame *
103 decode_any_frame (register Lisp_Object frame)
105 if (NILP (frame))
106 frame = selected_frame;
107 CHECK_FRAME (frame);
108 return XFRAME (frame);
111 #ifdef HAVE_WINDOW_SYSTEM
113 bool
114 window_system_available (struct frame *f)
116 return f ? FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f) : x_display_list != NULL;
119 #endif /* HAVE_WINDOW_SYSTEM */
121 struct frame *
122 decode_window_system_frame (Lisp_Object frame)
124 struct frame *f = decode_live_frame (frame);
126 if (!window_system_available (f))
127 error ("Window system frame should be used");
128 return f;
131 void
132 check_window_system (struct frame *f)
134 if (!window_system_available (f))
135 error (f ? "Window system frame should be used"
136 : "Window system is not in use or not initialized");
139 /* Return the value of frame parameter PROP in frame FRAME. */
141 Lisp_Object
142 get_frame_param (register struct frame *frame, Lisp_Object prop)
144 register Lisp_Object tem;
146 tem = Fassq (prop, frame->param_alist);
147 if (EQ (tem, Qnil))
148 return tem;
149 return Fcdr (tem);
153 void
154 frame_size_history_add (struct frame *f, Lisp_Object fun_symbol,
155 int width, int height, Lisp_Object rest)
157 Lisp_Object frame;
159 XSETFRAME (frame, f);
160 if (CONSP (frame_size_history)
161 && INTEGERP (XCAR (frame_size_history))
162 && 0 < XINT (XCAR (frame_size_history)))
163 frame_size_history =
164 Fcons (make_number (XINT (XCAR (frame_size_history)) - 1),
165 Fcons (list4
166 (frame, fun_symbol,
167 ((width > 0)
168 ? list4 (make_number (FRAME_TEXT_WIDTH (f)),
169 make_number (FRAME_TEXT_HEIGHT (f)),
170 make_number (width),
171 make_number (height))
172 : Qnil),
173 rest),
174 XCDR (frame_size_history)));
178 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
179 state of frame F would be affected by a vertical (horizontal if
180 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
181 parameter that is changed. */
182 bool
183 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
185 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
186 bool inhibit
187 = ((f->after_make_frame
188 && (EQ (frame_inhibit_implied_resize, Qt)
189 || (CONSP (frame_inhibit_implied_resize)
190 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))))
191 || (horizontal
192 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight))
193 || (!horizontal
194 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth))
195 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f));
197 if (inhibit && !FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
198 frame_size_history_add
199 (f, Qframe_inhibit_resize, 0, 0,
200 list5 (horizontal ? Qt : Qnil, parameter,
201 f->after_make_frame ? Qt : Qnil,
202 frame_inhibit_implied_resize,
203 fullscreen));
205 return inhibit;
208 static void
209 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
211 int nlines;
212 int olines = FRAME_MENU_BAR_LINES (f);
214 /* Right now, menu bars don't work properly in minibuf-only frames;
215 most of the commands try to apply themselves to the minibuffer
216 frame itself, and get an error because you can't switch buffers
217 in or split the minibuffer window. */
218 if (FRAME_MINIBUF_ONLY_P (f))
219 return;
221 if (TYPE_RANGED_INTEGERP (int, value))
222 nlines = XINT (value);
223 else
224 nlines = 0;
226 if (nlines != olines)
228 windows_or_buffers_changed = 14;
229 FRAME_MENU_BAR_LINES (f) = nlines;
230 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
231 change_frame_size (f, FRAME_COLS (f),
232 FRAME_LINES (f) + olines - nlines,
233 0, 1, 0, 0);
237 Lisp_Object Vframe_list;
240 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
241 doc: /* Return non-nil if OBJECT is a frame.
242 Value is:
243 t for a termcap frame (a character-only terminal),
244 'x' for an Emacs frame that is really an X window,
245 'w32' for an Emacs frame that is a window on MS-Windows display,
246 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
247 'pc' for a direct-write MS-DOS frame.
248 See also `frame-live-p'. */)
249 (Lisp_Object object)
251 if (!FRAMEP (object))
252 return Qnil;
253 switch (XFRAME (object)->output_method)
255 case output_initial: /* The initial frame is like a termcap frame. */
256 case output_termcap:
257 return Qt;
258 case output_x_window:
259 return Qx;
260 case output_w32:
261 return Qw32;
262 case output_msdos_raw:
263 return Qpc;
264 case output_ns:
265 return Qns;
266 default:
267 emacs_abort ();
271 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
272 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
273 Value is nil if OBJECT is not a live frame. If object is a live
274 frame, the return value indicates what sort of terminal device it is
275 displayed on. See the documentation of `framep' for possible
276 return values. */)
277 (Lisp_Object object)
279 return ((FRAMEP (object)
280 && FRAME_LIVE_P (XFRAME (object)))
281 ? Fframep (object)
282 : Qnil);
285 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
286 doc: /* The name of the window system that FRAME is displaying through.
287 The value is a symbol:
288 nil for a termcap frame (a character-only terminal),
289 'x' for an Emacs frame that is really an X window,
290 'w32' for an Emacs frame that is a window on MS-Windows display,
291 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
292 'pc' for a direct-write MS-DOS frame.
294 FRAME defaults to the currently selected frame.
296 Use of this function as a predicate is deprecated. Instead,
297 use `display-graphic-p' or any of the other `display-*-p'
298 predicates which report frame's specific UI-related capabilities. */)
299 (Lisp_Object frame)
301 Lisp_Object type;
302 if (NILP (frame))
303 frame = selected_frame;
305 type = Fframep (frame);
307 if (NILP (type))
308 wrong_type_argument (Qframep, frame);
310 if (EQ (type, Qt))
311 return Qnil;
312 else
313 return type;
316 /* Placeholder used by temacs -nw before window.el is loaded. */
317 DEFUN ("frame-windows-min-size", Fframe_windows_min_size,
318 Sframe_windows_min_size, 4, 4, 0,
319 doc: /* */
320 attributes: const)
321 (Lisp_Object frame, Lisp_Object horizontal,
322 Lisp_Object ignore, Lisp_Object pixelwise)
324 return make_number (0);
327 static int
328 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal,
329 Lisp_Object ignore, Lisp_Object pixelwise)
331 return XINT (call4 (Qframe_windows_min_size, frame, horizontal,
332 ignore, pixelwise));
336 /* Make sure windows sizes of frame F are OK. new_width and new_height
337 are in pixels. A value of -1 means no change is requested for that
338 size (but the frame may still have to be resized to accommodate
339 windows with their minimum sizes). This can either issue a request
340 to resize the frame externally (via x_set_window_size), to resize the
341 frame internally (via resize_frame_windows) or do nothing at all.
343 The argument INHIBIT can assume the following values:
345 0 means to unconditionally call x_set_window_size even if sizes
346 apparently do not change. Fx_create_frame uses this to pass the
347 initial size to the window manager.
349 1 means to call x_set_window_size if the outer frame size really
350 changes. Fset_frame_size, Fset_frame_height, ... use this.
352 2 means to call x_set_window_size provided frame_inhibit_resize
353 allows it. The menu and tool bar code use this ("3" won't work
354 here in general because menu and tool bar are often not counted in
355 the frame's text height).
357 3 means call x_set_window_size if window minimum sizes must be
358 preserved or frame_inhibit_resize allows it. x_set_left_fringe,
359 x_set_scroll_bar_width, x_new_font ... use (or should use) this.
361 4 means call x_set_window_size only if window minimum sizes must be
362 preserved. x_set_right_divider_width, x_set_border_width and the
363 code responsible for wrapping the tool bar use this.
365 5 means to never call x_set_window_size. change_frame_size uses
366 this.
368 Note that even when x_set_window_size is not called, individual
369 windows may have to be resized (via `window--sanitize-window-sizes')
370 in order to support minimum size constraints.
372 PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the
373 symbol of the parameter changed (like `menu-bar-lines', `font', ...).
374 This is passed on to frame_inhibit_resize to let the latter decide on
375 a case-by-case basis whether the frame may be resized externally. */
376 void
377 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
378 bool pretend, Lisp_Object parameter)
380 int unit_width = FRAME_COLUMN_WIDTH (f);
381 int unit_height = FRAME_LINE_HEIGHT (f);
382 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
383 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
384 int old_cols = FRAME_COLS (f);
385 int old_lines = FRAME_LINES (f);
386 int new_pixel_width, new_pixel_height;
387 /* The following two values are calculated from the old frame pixel
388 sizes and any "new" settings for tool bar, menu bar and internal
389 borders. We do it this way to detect whether we have to call
390 x_set_window_size as consequence of the new settings. */
391 int windows_width = FRAME_WINDOWS_WIDTH (f);
392 int windows_height = FRAME_WINDOWS_HEIGHT (f);
393 int min_windows_width, min_windows_height;
394 /* These are a bit tedious, maybe we should use a macro. */
395 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
396 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
397 int old_windows_height
398 = (WINDOW_PIXEL_HEIGHT (r)
399 + (FRAME_HAS_MINIBUF_P (f)
400 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
401 : 0));
402 int new_windows_width, new_windows_height;
403 int old_text_width = FRAME_TEXT_WIDTH (f);
404 int old_text_height = FRAME_TEXT_HEIGHT (f);
405 /* If a size is < 0 use the old value. */
406 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
407 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
408 int new_cols, new_lines;
409 bool inhibit_horizontal, inhibit_vertical;
410 Lisp_Object frame;
412 XSETFRAME (frame, f);
414 frame_size_history_add
415 (f, Qadjust_frame_size_1, new_text_width, new_text_height,
416 list2 (parameter, make_number (inhibit)));
418 /* The following two values are calculated from the old window body
419 sizes and any "new" settings for scroll bars, dividers, fringes and
420 margins (though the latter should have been processed already). */
421 min_windows_width
422 = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qt : Qnil, Qt);
423 min_windows_height
424 = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qt : Qnil, Qt);
426 if (inhibit >= 2 && inhibit <= 4)
427 /* When INHIBIT is in [2..4] inhibit if the "old" window sizes stay
428 within the limits and either frame_inhibit_resize tells us to do
429 so or INHIBIT equals 4. */
431 inhibit_horizontal = ((windows_width >= min_windows_width
432 && (inhibit == 4
433 || frame_inhibit_resize (f, true, parameter)))
434 ? true : false);
435 inhibit_vertical = ((windows_height >= min_windows_height
436 && (inhibit == 4
437 || frame_inhibit_resize (f, false, parameter)))
438 ? true : false);
440 else
441 /* Otherwise inhibit if INHIBIT equals 5. */
442 inhibit_horizontal = inhibit_vertical = inhibit == 5;
444 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
445 ? old_pixel_width
446 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
447 min_windows_width
448 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
449 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
450 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
451 new_cols = new_text_width / unit_width;
453 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
454 ? old_pixel_height
455 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
456 min_windows_height
457 + FRAME_TOP_MARGIN_HEIGHT (f)
458 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
459 new_windows_height = (new_pixel_height
460 - FRAME_TOP_MARGIN_HEIGHT (f)
461 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
462 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
463 new_lines = new_text_height / unit_height;
465 #ifdef HAVE_WINDOW_SYSTEM
466 if (FRAME_WINDOW_P (f)
467 && f->can_x_set_window_size
468 && ((!inhibit_horizontal
469 && (new_pixel_width != old_pixel_width
470 || inhibit == 0 || inhibit == 2))
471 || (!inhibit_vertical
472 && (new_pixel_height != old_pixel_height
473 || inhibit == 0 || inhibit == 2))))
474 /* We are either allowed to change the frame size or the minimum
475 sizes request such a change. Do not care for fixing minimum
476 sizes here, we do that eventually when we're called from
477 change_frame_size. */
479 /* Make sure we respect fullheight and fullwidth. */
480 if (inhibit_horizontal)
481 new_text_width = old_text_width;
482 else if (inhibit_vertical)
483 new_text_height = old_text_height;
485 frame_size_history_add
486 (f, Qadjust_frame_size_2, new_text_width, new_text_height,
487 list2 (inhibit_horizontal ? Qt : Qnil,
488 inhibit_vertical ? Qt : Qnil));
490 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
491 f->resized_p = true;
493 return;
495 #endif
497 if (new_text_width == old_text_width
498 && new_text_height == old_text_height
499 && new_windows_width == old_windows_width
500 && new_windows_height == old_windows_height
501 && new_pixel_width == old_pixel_width
502 && new_pixel_height == old_pixel_height
503 && new_cols == old_cols
504 && new_lines == old_lines)
505 /* No change. Sanitize window sizes and return. */
507 sanitize_window_sizes (frame, Qt);
508 sanitize_window_sizes (frame, Qnil);
510 return;
513 block_input ();
515 #ifdef MSDOS
516 /* We only can set screen dimensions to certain values supported
517 by our video hardware. Try to find the smallest size greater
518 or equal to the requested dimensions. */
519 dos_set_window_size (&new_lines, &new_cols);
520 #endif
522 if (new_windows_width != old_windows_width)
524 resize_frame_windows (f, new_windows_width, 1, 1);
526 /* MSDOS frames cannot PRETEND, as they change frame size by
527 manipulating video hardware. */
528 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
529 FrameCols (FRAME_TTY (f)) = new_cols;
531 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
532 if (WINDOWP (f->tool_bar_window))
534 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
535 XWINDOW (f->tool_bar_window)->total_cols
536 = new_windows_width / unit_width;
538 #endif
541 if (new_windows_height != old_windows_height
542 /* When the top margin has changed we have to recalculate the top
543 edges of all windows. No such calculation is necessary for the
544 left edges. */
545 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
547 resize_frame_windows (f, new_windows_height, 0, 1);
549 /* MSDOS frames cannot PRETEND, as they change frame size by
550 manipulating video hardware. */
551 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
552 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
555 frame_size_history_add
556 (f, Qadjust_frame_size_3, new_text_width, new_text_height,
557 list4 (make_number (old_pixel_width), make_number (old_pixel_height),
558 make_number (new_pixel_width), make_number (new_pixel_height)));
560 /* Assign new sizes. */
561 FRAME_TEXT_WIDTH (f) = new_text_width;
562 FRAME_TEXT_HEIGHT (f) = new_text_height;
563 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
564 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
565 SET_FRAME_COLS (f, new_cols);
566 SET_FRAME_LINES (f, new_lines);
569 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
570 int text_area_x, text_area_y, text_area_width, text_area_height;
572 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
573 &text_area_height);
574 if (w->cursor.x >= text_area_x + text_area_width)
575 w->cursor.hpos = w->cursor.x = 0;
576 if (w->cursor.y >= text_area_y + text_area_height)
577 w->cursor.vpos = w->cursor.y = 0;
580 /* Sanitize window sizes. */
581 sanitize_window_sizes (frame, Qt);
582 sanitize_window_sizes (frame, Qnil);
584 adjust_frame_glyphs (f);
585 calculate_costs (f);
586 SET_FRAME_GARBAGED (f);
588 /* A frame was "resized" if one of its pixelsizes changed, even if its
589 X window wasn't resized at all. */
590 f->resized_p = (new_pixel_width != old_pixel_width
591 || new_pixel_height != old_pixel_height);
593 unblock_input ();
595 run_window_configuration_change_hook (f);
598 /* Allocate basically initialized frame. */
600 static struct frame *
601 allocate_frame (void)
603 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
606 struct frame *
607 make_frame (bool mini_p)
609 Lisp_Object frame;
610 register struct frame *f;
611 register struct window *rw, *mw;
612 register Lisp_Object root_window;
613 register Lisp_Object mini_window;
615 f = allocate_frame ();
616 XSETFRAME (frame, f);
618 #ifdef USE_GTK
619 /* Initialize Lisp data. Note that allocate_frame initializes all
620 Lisp data to nil, so do it only for slots which should not be nil. */
621 fset_tool_bar_position (f, Qtop);
622 #endif
624 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
625 non-Lisp data, so do it only for slots which should not be zero.
626 To avoid subtle bugs and for the sake of readability, it's better to
627 initialize enum members explicitly even if their values are zero. */
628 f->wants_modeline = true;
629 f->redisplay = true;
630 f->garbaged = true;
631 f->can_x_set_window_size = false;
632 f->after_make_frame = false;
633 f->tool_bar_redisplayed_once = false;
634 f->column_width = 1; /* !FRAME_WINDOW_P value. */
635 f->line_height = 1; /* !FRAME_WINDOW_P value. */
636 #ifdef HAVE_WINDOW_SYSTEM
637 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
638 f->horizontal_scroll_bars = false;
639 f->want_fullscreen = FULLSCREEN_NONE;
640 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
641 f->last_tool_bar_item = -1;
642 #endif
643 #endif
645 root_window = make_window ();
646 rw = XWINDOW (root_window);
647 if (mini_p)
649 mini_window = make_window ();
650 mw = XWINDOW (mini_window);
651 wset_next (rw, mini_window);
652 wset_prev (mw, root_window);
653 mw->mini = 1;
654 wset_frame (mw, frame);
655 fset_minibuffer_window (f, mini_window);
657 else
659 mini_window = Qnil;
660 wset_next (rw, Qnil);
661 fset_minibuffer_window (f, Qnil);
664 wset_frame (rw, frame);
666 /* 10 is arbitrary,
667 just so that there is "something there."
668 Correct size will be set up later with adjust_frame_size. */
670 SET_FRAME_COLS (f, 10);
671 SET_FRAME_LINES (f, 10);
672 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
673 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
675 rw->total_cols = 10;
676 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
677 rw->total_lines = mini_p ? 9 : 10;
678 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
680 if (mini_p)
682 mw->top_line = rw->total_lines;
683 mw->pixel_top = rw->pixel_height;
684 mw->total_cols = rw->total_cols;
685 mw->pixel_width = rw->pixel_width;
686 mw->total_lines = 1;
687 mw->pixel_height = FRAME_LINE_HEIGHT (f);
690 /* Choose a buffer for the frame's root window. */
692 Lisp_Object buf = Fcurrent_buffer ();
694 /* If current buffer is hidden, try to find another one. */
695 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
696 buf = other_buffer_safely (buf);
698 /* Use set_window_buffer, not Fset_window_buffer, and don't let
699 hooks be run by it. The reason is that the whole frame/window
700 arrangement is not yet fully initialized at this point. Windows
701 don't have the right size, glyph matrices aren't initialized
702 etc. Running Lisp functions at this point surely ends in a
703 SEGV. */
704 set_window_buffer (root_window, buf, 0, 0);
705 fset_buffer_list (f, list1 (buf));
708 if (mini_p)
710 set_window_buffer (mini_window,
711 (NILP (Vminibuffer_list)
712 ? get_minibuffer (0)
713 : Fcar (Vminibuffer_list)),
714 0, 0);
715 /* No horizontal scroll bars in minibuffers. */
716 wset_horizontal_scroll_bar (mw, Qnil);
719 fset_root_window (f, root_window);
720 fset_selected_window (f, root_window);
721 /* Make sure this window seems more recently used than
722 a newly-created, never-selected window. */
723 XWINDOW (f->selected_window)->use_time = ++window_select_count;
725 return f;
728 #ifdef HAVE_WINDOW_SYSTEM
729 /* Make a frame using a separate minibuffer window on another frame.
730 MINI_WINDOW is the minibuffer window to use. nil means use the
731 default (the global minibuffer). */
733 struct frame *
734 make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
736 register struct frame *f;
737 struct gcpro gcpro1;
739 if (!NILP (mini_window))
740 CHECK_LIVE_WINDOW (mini_window);
742 if (!NILP (mini_window)
743 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
744 error ("Frame and minibuffer must be on the same terminal");
746 /* Make a frame containing just a root window. */
747 f = make_frame (0);
749 if (NILP (mini_window))
751 /* Use default-minibuffer-frame if possible. */
752 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
753 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
755 Lisp_Object frame_dummy;
757 XSETFRAME (frame_dummy, f);
758 GCPRO1 (frame_dummy);
759 /* If there's no minibuffer frame to use, create one. */
760 kset_default_minibuffer_frame
761 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
762 UNGCPRO;
765 mini_window
766 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
769 fset_minibuffer_window (f, mini_window);
771 /* Make the chosen minibuffer window display the proper minibuffer,
772 unless it is already showing a minibuffer. */
773 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
774 /* Use set_window_buffer instead of Fset_window_buffer (see
775 discussion of bug#11984, bug#12025, bug#12026). */
776 set_window_buffer (mini_window,
777 (NILP (Vminibuffer_list)
778 ? get_minibuffer (0)
779 : Fcar (Vminibuffer_list)), 0, 0);
780 return f;
783 /* Make a frame containing only a minibuffer window. */
785 struct frame *
786 make_minibuffer_frame (void)
788 /* First make a frame containing just a root window, no minibuffer. */
790 register struct frame *f = make_frame (0);
791 register Lisp_Object mini_window;
792 register Lisp_Object frame;
794 XSETFRAME (frame, f);
796 f->auto_raise = 0;
797 f->auto_lower = 0;
798 f->no_split = 1;
799 f->wants_modeline = 0;
801 /* Now label the root window as also being the minibuffer.
802 Avoid infinite looping on the window chain by marking next pointer
803 as nil. */
805 mini_window = f->root_window;
806 fset_minibuffer_window (f, mini_window);
807 XWINDOW (mini_window)->mini = 1;
808 wset_next (XWINDOW (mini_window), Qnil);
809 wset_prev (XWINDOW (mini_window), Qnil);
810 wset_frame (XWINDOW (mini_window), frame);
812 /* Put the proper buffer in that window. */
814 /* Use set_window_buffer instead of Fset_window_buffer (see
815 discussion of bug#11984, bug#12025, bug#12026). */
816 set_window_buffer (mini_window,
817 (NILP (Vminibuffer_list)
818 ? get_minibuffer (0)
819 : Fcar (Vminibuffer_list)), 0, 0);
820 return f;
822 #endif /* HAVE_WINDOW_SYSTEM */
824 /* Construct a frame that refers to a terminal. */
826 static printmax_t tty_frame_count;
828 struct frame *
829 make_initial_frame (void)
831 struct frame *f;
832 struct terminal *terminal;
833 Lisp_Object frame;
835 eassert (initial_kboard);
837 /* The first call must initialize Vframe_list. */
838 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
839 Vframe_list = Qnil;
841 terminal = init_initial_terminal ();
843 f = make_frame (1);
844 XSETFRAME (frame, f);
846 Vframe_list = Fcons (frame, Vframe_list);
848 tty_frame_count = 1;
849 fset_name (f, build_pure_c_string ("F1"));
851 SET_FRAME_VISIBLE (f, 1);
853 f->output_method = terminal->type;
854 f->terminal = terminal;
855 f->terminal->reference_count++;
856 f->output_data.nothing = 0;
858 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
859 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
861 #ifdef HAVE_WINDOW_SYSTEM
862 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
863 f->horizontal_scroll_bars = false;
864 #endif
866 /* The default value of menu-bar-mode is t. */
867 set_menu_bar_lines (f, make_number (1), Qnil);
869 if (!noninteractive)
870 init_frame_faces (f);
872 last_nonminibuf_frame = f;
874 f->can_x_set_window_size = true;
875 f->after_make_frame = true;
877 return f;
881 static struct frame *
882 make_terminal_frame (struct terminal *terminal)
884 register struct frame *f;
885 Lisp_Object frame;
886 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
888 if (!terminal->name)
889 error ("Terminal is not live, can't create new frames on it");
891 f = make_frame (1);
893 XSETFRAME (frame, f);
894 Vframe_list = Fcons (frame, Vframe_list);
896 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
898 SET_FRAME_VISIBLE (f, 1);
900 f->terminal = terminal;
901 f->terminal->reference_count++;
902 #ifdef MSDOS
903 f->output_data.tty->display_info = &the_only_display_info;
904 if (!inhibit_window_system
905 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
906 || XFRAME (selected_frame)->output_method == output_msdos_raw))
907 f->output_method = output_msdos_raw;
908 else
909 f->output_method = output_termcap;
910 #else /* not MSDOS */
911 f->output_method = output_termcap;
912 create_tty_output (f);
913 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
914 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
915 #endif /* not MSDOS */
917 #ifdef HAVE_WINDOW_SYSTEM
918 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
919 f->horizontal_scroll_bars = false;
920 #endif
922 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
923 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
924 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
925 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
927 /* Set the top frame to the newly created frame. */
928 if (FRAMEP (FRAME_TTY (f)->top_frame)
929 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
930 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
932 FRAME_TTY (f)->top_frame = frame;
934 if (!noninteractive)
935 init_frame_faces (f);
937 return f;
940 /* Get a suitable value for frame parameter PARAMETER for a newly
941 created frame, based on (1) the user-supplied frame parameter
942 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
944 static Lisp_Object
945 get_future_frame_param (Lisp_Object parameter,
946 Lisp_Object supplied_parms,
947 char *current_value)
949 Lisp_Object result;
951 result = Fassq (parameter, supplied_parms);
952 if (NILP (result))
953 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
954 if (NILP (result) && current_value != NULL)
955 result = build_string (current_value);
956 if (!NILP (result) && !STRINGP (result))
957 result = XCDR (result);
958 if (NILP (result) || !STRINGP (result))
959 result = Qnil;
961 return result;
964 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
965 1, 1, 0,
966 doc: /* Create an additional terminal frame, possibly on another terminal.
967 This function takes one argument, an alist specifying frame parameters.
969 You can create multiple frames on a single text terminal, but only one
970 of them (the selected terminal frame) is actually displayed.
972 In practice, generally you don't need to specify any parameters,
973 except when you want to create a new frame on another terminal.
974 In that case, the `tty' parameter specifies the device file to open,
975 and the `tty-type' parameter specifies the terminal type. Example:
977 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
979 Note that changing the size of one terminal frame automatically
980 affects all frames on the same terminal device. */)
981 (Lisp_Object parms)
983 struct frame *f;
984 struct terminal *t = NULL;
985 Lisp_Object frame, tem;
986 struct frame *sf = SELECTED_FRAME ();
988 #ifdef MSDOS
989 if (sf->output_method != output_msdos_raw
990 && sf->output_method != output_termcap)
991 emacs_abort ();
992 #else /* not MSDOS */
994 #ifdef WINDOWSNT /* This should work now! */
995 if (sf->output_method != output_termcap)
996 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
997 #endif
998 #endif /* not MSDOS */
1001 Lisp_Object terminal;
1003 terminal = Fassq (Qterminal, parms);
1004 if (CONSP (terminal))
1006 terminal = XCDR (terminal);
1007 t = decode_live_terminal (terminal);
1009 #ifdef MSDOS
1010 if (t && t != the_only_display_info.terminal)
1011 /* msdos.c assumes a single tty_display_info object. */
1012 error ("Multiple terminals are not supported on this platform");
1013 if (!t)
1014 t = the_only_display_info.terminal;
1015 #endif
1018 if (!t)
1020 char *name = 0, *type = 0;
1021 Lisp_Object tty, tty_type;
1022 USE_SAFE_ALLOCA;
1024 tty = get_future_frame_param
1025 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1026 ? FRAME_TTY (XFRAME (selected_frame))->name
1027 : NULL));
1028 if (!NILP (tty))
1029 SAFE_ALLOCA_STRING (name, tty);
1031 tty_type = get_future_frame_param
1032 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1033 ? FRAME_TTY (XFRAME (selected_frame))->type
1034 : NULL));
1035 if (!NILP (tty_type))
1036 SAFE_ALLOCA_STRING (type, tty_type);
1038 t = init_tty (name, type, 0); /* Errors are not fatal. */
1039 SAFE_FREE ();
1042 f = make_terminal_frame (t);
1045 int width, height;
1046 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1047 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f),
1048 5, 0, Qterminal_frame);
1051 adjust_frame_glyphs (f);
1052 calculate_costs (f);
1053 XSETFRAME (frame, f);
1055 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1056 store_in_alist (&parms, Qtty,
1057 (t->display_info.tty->name
1058 ? build_string (t->display_info.tty->name)
1059 : Qnil));
1060 Fmodify_frame_parameters (frame, parms);
1062 /* Make the frame face alist be frame-specific, so that each
1063 frame could change its face definitions independently. */
1064 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1065 /* Simple Fcopy_alist isn't enough, because we need the contents of
1066 the vectors which are the CDRs of associations in face_alist to
1067 be copied as well. */
1068 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1069 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1071 f->can_x_set_window_size = true;
1072 f->after_make_frame = true;
1074 return frame;
1078 /* Perform the switch to frame FRAME.
1080 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1081 FRAME1 as frame.
1083 If TRACK is non-zero and the frame that currently has the focus
1084 redirects its focus to the selected frame, redirect that focused
1085 frame's focus to FRAME instead.
1087 FOR_DELETION non-zero means that the selected frame is being
1088 deleted, which includes the possibility that the frame's terminal
1089 is dead.
1091 The value of NORECORD is passed as argument to Fselect_window. */
1093 Lisp_Object
1094 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1096 struct frame *sf = SELECTED_FRAME ();
1098 /* If FRAME is a switch-frame event, extract the frame we should
1099 switch to. */
1100 if (CONSP (frame)
1101 && EQ (XCAR (frame), Qswitch_frame)
1102 && CONSP (XCDR (frame)))
1103 frame = XCAR (XCDR (frame));
1105 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1106 a switch-frame event to arrive after a frame is no longer live,
1107 especially when deleting the initial frame during startup. */
1108 CHECK_FRAME (frame);
1109 if (! FRAME_LIVE_P (XFRAME (frame)))
1110 return Qnil;
1112 if (sf == XFRAME (frame))
1113 return frame;
1115 /* If a frame's focus has been redirected toward the currently
1116 selected frame, we should change the redirection to point to the
1117 newly selected frame. This means that if the focus is redirected
1118 from a minibufferless frame to a surrogate minibuffer frame, we
1119 can use `other-window' to switch between all the frames using
1120 that minibuffer frame, and the focus redirection will follow us
1121 around. */
1122 #if 0
1123 /* This is too greedy; it causes inappropriate focus redirection
1124 that's hard to get rid of. */
1125 if (track)
1127 Lisp_Object tail;
1129 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1131 Lisp_Object focus;
1133 if (!FRAMEP (XCAR (tail)))
1134 emacs_abort ();
1136 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1138 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1139 Fredirect_frame_focus (XCAR (tail), frame);
1142 #else /* ! 0 */
1143 /* Instead, apply it only to the frame we're pointing to. */
1144 #ifdef HAVE_WINDOW_SYSTEM
1145 if (track && FRAME_WINDOW_P (XFRAME (frame)))
1147 Lisp_Object focus, xfocus;
1149 xfocus = x_get_focus_frame (XFRAME (frame));
1150 if (FRAMEP (xfocus))
1152 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1153 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1154 Fredirect_frame_focus (xfocus, frame);
1157 #endif /* HAVE_X_WINDOWS */
1158 #endif /* ! 0 */
1160 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1161 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1163 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
1165 struct frame *f = XFRAME (frame);
1166 struct tty_display_info *tty = FRAME_TTY (f);
1167 Lisp_Object top_frame = tty->top_frame;
1169 /* Don't mark the frame garbaged and/or obscured if we are
1170 switching to the frame that is already the top frame of that
1171 TTY. */
1172 if (!EQ (frame, top_frame))
1174 if (FRAMEP (top_frame))
1175 /* Mark previously displayed frame as now obscured. */
1176 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1177 SET_FRAME_VISIBLE (f, 1);
1178 /* If the new TTY frame changed dimensions, we need to
1179 resync term.c's idea of the frame size with the new
1180 frame's data. */
1181 if (FRAME_COLS (f) != FrameCols (tty))
1182 FrameCols (tty) = FRAME_COLS (f);
1183 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1184 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1186 tty->top_frame = frame;
1189 selected_frame = frame;
1190 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1191 last_nonminibuf_frame = XFRAME (selected_frame);
1193 Fselect_window (XFRAME (frame)->selected_window, norecord);
1195 /* We want to make sure that the next event generates a frame-switch
1196 event to the appropriate frame. This seems kludgy to me, but
1197 before you take it out, make sure that evaluating something like
1198 (select-window (frame-root-window (new-frame))) doesn't end up
1199 with your typing being interpreted in the new frame instead of
1200 the one you're actually typing in. */
1201 internal_last_event_frame = Qnil;
1203 return frame;
1206 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1207 doc: /* Select FRAME.
1208 Subsequent editing commands apply to its selected window.
1209 Optional argument NORECORD means to neither change the order of
1210 recently selected windows nor the buffer list.
1212 The selection of FRAME lasts until the next time the user does
1213 something to select a different frame, or until the next time
1214 this function is called. If you are using a window system, the
1215 previously selected frame may be restored as the selected frame
1216 when returning to the command loop, because it still may have
1217 the window system's input focus. On a text terminal, the next
1218 redisplay will display FRAME.
1220 This function returns FRAME, or nil if FRAME has been deleted. */)
1221 (Lisp_Object frame, Lisp_Object norecord)
1223 return do_switch_frame (frame, 1, 0, norecord);
1226 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1227 doc: /* Handle a switch-frame event EVENT.
1228 Switch-frame events are usually bound to this function.
1229 A switch-frame event tells Emacs that the window manager has requested
1230 that the user's events be directed to the frame mentioned in the event.
1231 This function selects the selected window of the frame of EVENT.
1233 If EVENT is frame object, handle it as if it were a switch-frame event
1234 to that frame. */)
1235 (Lisp_Object event)
1237 /* Preserve prefix arg that the command loop just cleared. */
1238 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1239 run_hook (Qmouse_leave_buffer_hook);
1240 /* `switch-frame' implies a focus in. */
1241 call1 (intern ("handle-focus-in"), event);
1242 return do_switch_frame (event, 0, 0, Qnil);
1245 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1246 doc: /* Return the frame that is now selected. */)
1247 (void)
1249 return selected_frame;
1252 DEFUN ("frame-list", Fframe_list, Sframe_list,
1253 0, 0, 0,
1254 doc: /* Return a list of all live frames. */)
1255 (void)
1257 Lisp_Object frames;
1258 frames = Fcopy_sequence (Vframe_list);
1259 #ifdef HAVE_WINDOW_SYSTEM
1260 if (FRAMEP (tip_frame))
1261 frames = Fdelq (tip_frame, frames);
1262 #endif
1263 return frames;
1266 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1267 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1268 If MINIBUF is nil, do not consider minibuffer-only candidate.
1269 If MINIBUF is `visible', do not consider an invisible candidate.
1270 If MINIBUF is a window, consider only its own frame and candidate now
1271 using that window as the minibuffer.
1272 If MINIBUF is 0, consider candidate if it is visible or iconified.
1273 Otherwise consider any candidate and return nil if CANDIDATE is not
1274 acceptable. */
1276 static Lisp_Object
1277 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1279 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1281 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1282 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1283 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1284 && FRAME_TTY (c) == FRAME_TTY (f)))
1286 if (NILP (minibuf))
1288 if (!FRAME_MINIBUF_ONLY_P (c))
1289 return candidate;
1291 else if (EQ (minibuf, Qvisible))
1293 if (FRAME_VISIBLE_P (c))
1294 return candidate;
1296 else if (WINDOWP (minibuf))
1298 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1299 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1300 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1301 FRAME_FOCUS_FRAME (c)))
1302 return candidate;
1304 else if (XFASTINT (minibuf) == 0)
1306 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1307 return candidate;
1309 else
1310 return candidate;
1312 return Qnil;
1315 /* Return the next frame in the frame list after FRAME. */
1317 static Lisp_Object
1318 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1320 Lisp_Object f, tail;
1321 int passed = 0;
1323 /* There must always be at least one frame in Vframe_list. */
1324 eassert (CONSP (Vframe_list));
1326 while (passed < 2)
1327 FOR_EACH_FRAME (tail, f)
1329 if (passed)
1331 f = candidate_frame (f, frame, minibuf);
1332 if (!NILP (f))
1333 return f;
1335 if (EQ (frame, f))
1336 passed++;
1338 return frame;
1341 /* Return the previous frame in the frame list before FRAME. */
1343 static Lisp_Object
1344 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1346 Lisp_Object f, tail, prev = Qnil;
1348 /* There must always be at least one frame in Vframe_list. */
1349 eassert (CONSP (Vframe_list));
1351 FOR_EACH_FRAME (tail, f)
1353 if (EQ (frame, f) && !NILP (prev))
1354 return prev;
1355 f = candidate_frame (f, frame, minibuf);
1356 if (!NILP (f))
1357 prev = f;
1360 /* We've scanned the entire list. */
1361 if (NILP (prev))
1362 /* We went through the whole frame list without finding a single
1363 acceptable frame. Return the original frame. */
1364 return frame;
1365 else
1366 /* There were no acceptable frames in the list before FRAME; otherwise,
1367 we would have returned directly from the loop. Since PREV is the last
1368 acceptable frame in the list, return it. */
1369 return prev;
1373 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1374 doc: /* Return the next frame in the frame list after FRAME.
1375 It considers only frames on the same terminal as FRAME.
1376 By default, skip minibuffer-only frames.
1377 If omitted, FRAME defaults to the selected frame.
1378 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1379 If MINIFRAME is a window, include only its own frame
1380 and any frame now using that window as the minibuffer.
1381 If MINIFRAME is `visible', include all visible frames.
1382 If MINIFRAME is 0, include all visible and iconified frames.
1383 Otherwise, include all frames. */)
1384 (Lisp_Object frame, Lisp_Object miniframe)
1386 if (NILP (frame))
1387 frame = selected_frame;
1388 CHECK_LIVE_FRAME (frame);
1389 return next_frame (frame, miniframe);
1392 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1393 doc: /* Return the previous frame in the frame list before FRAME.
1394 It considers only frames on the same terminal as FRAME.
1395 By default, skip minibuffer-only frames.
1396 If omitted, FRAME defaults to the selected frame.
1397 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1398 If MINIFRAME is a window, include only its own frame
1399 and any frame now using that window as the minibuffer.
1400 If MINIFRAME is `visible', include all visible frames.
1401 If MINIFRAME is 0, include all visible and iconified frames.
1402 Otherwise, include all frames. */)
1403 (Lisp_Object frame, Lisp_Object miniframe)
1405 if (NILP (frame))
1406 frame = selected_frame;
1407 CHECK_LIVE_FRAME (frame);
1408 return prev_frame (frame, miniframe);
1411 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1412 Slast_nonminibuf_frame, 0, 0, 0,
1413 doc: /* Return last non-minibuffer frame selected. */)
1414 (void)
1416 Lisp_Object frame = Qnil;
1418 if (last_nonminibuf_frame)
1419 XSETFRAME (frame, last_nonminibuf_frame);
1421 return frame;
1424 /* Return 1 if it is ok to delete frame F;
1425 0 if all frames aside from F are invisible.
1426 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1428 static int
1429 other_visible_frames (struct frame *f)
1431 Lisp_Object frames, this;
1433 FOR_EACH_FRAME (frames, this)
1435 if (f == XFRAME (this))
1436 continue;
1438 /* Verify that we can still talk to the frame's X window,
1439 and note any recent change in visibility. */
1440 #ifdef HAVE_X_WINDOWS
1441 if (FRAME_WINDOW_P (XFRAME (this)))
1442 x_sync (XFRAME (this));
1443 #endif
1445 if (FRAME_VISIBLE_P (XFRAME (this))
1446 || FRAME_ICONIFIED_P (XFRAME (this))
1447 /* Allow deleting the terminal frame when at least one X
1448 frame exists. */
1449 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1450 return 1;
1452 return 0;
1455 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1456 window. Preferably use the selected frame's minibuffer window
1457 instead. If the selected frame doesn't have one, get some other
1458 frame's minibuffer window. SELECT non-zero means select the new
1459 minibuffer window. */
1460 static void
1461 check_minibuf_window (Lisp_Object frame, int select)
1463 struct frame *f = decode_live_frame (frame);
1465 XSETFRAME (frame, f);
1467 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1469 Lisp_Object frames, this, window = make_number (0);
1471 if (!EQ (frame, selected_frame)
1472 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1473 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1474 else
1475 FOR_EACH_FRAME (frames, this)
1477 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1479 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1480 break;
1484 /* Don't abort if no window was found (Bug#15247). */
1485 if (WINDOWP (window))
1487 /* Use set_window_buffer instead of Fset_window_buffer (see
1488 discussion of bug#11984, bug#12025, bug#12026). */
1489 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1490 minibuf_window = window;
1492 /* SELECT non-zero usually means that FRAME's minibuffer
1493 window was selected; select the new one. */
1494 if (select)
1495 Fselect_window (minibuf_window, Qnil);
1501 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1502 unconditionally. x_connection_closed and delete_terminal use
1503 this. Any other value of FORCE implements the semantics
1504 described for Fdelete_frame. */
1505 Lisp_Object
1506 delete_frame (Lisp_Object frame, Lisp_Object force)
1508 struct frame *f = decode_any_frame (frame);
1509 struct frame *sf;
1510 struct kboard *kb;
1512 int minibuffer_selected, is_tooltip_frame;
1514 if (! FRAME_LIVE_P (f))
1515 return Qnil;
1517 if (NILP (force) && !other_visible_frames (f))
1518 error ("Attempt to delete the sole visible or iconified frame");
1520 /* x_connection_closed must have set FORCE to `noelisp' in order
1521 to delete the last frame, if it is gone. */
1522 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1523 error ("Attempt to delete the only frame");
1525 XSETFRAME (frame, f);
1527 /* Does this frame have a minibuffer, and is it the surrogate
1528 minibuffer for any other frame? */
1529 if (FRAME_HAS_MINIBUF_P (f))
1531 Lisp_Object frames, this;
1533 FOR_EACH_FRAME (frames, this)
1535 Lisp_Object fminiw;
1537 if (EQ (this, frame))
1538 continue;
1540 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1542 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1544 /* If we MUST delete this frame, delete the other first.
1545 But do this only if FORCE equals `noelisp'. */
1546 if (EQ (force, Qnoelisp))
1547 delete_frame (this, Qnoelisp);
1548 else
1549 error ("Attempt to delete a surrogate minibuffer frame");
1554 is_tooltip_frame = !NILP (Fframe_parameter (frame, Qtooltip));
1556 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1557 frame is a tooltip. FORCE is set to `noelisp' when handling
1558 a disconnect from the terminal, so we don't dare call Lisp
1559 code. */
1560 if (NILP (Vrun_hooks) || is_tooltip_frame)
1562 else if (EQ (force, Qnoelisp))
1563 pending_funcalls
1564 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1565 pending_funcalls);
1566 else
1568 #ifdef HAVE_X_WINDOWS
1569 /* Also, save clipboard to the clipboard manager. */
1570 x_clipboard_manager_save_frame (frame);
1571 #endif
1573 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1576 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1577 if (! FRAME_LIVE_P (f))
1578 return Qnil;
1580 /* At this point, we are committed to deleting the frame.
1581 There is no more chance for errors to prevent it. */
1583 minibuffer_selected = EQ (minibuf_window, selected_window);
1584 sf = SELECTED_FRAME ();
1585 /* Don't let the frame remain selected. */
1586 if (f == sf)
1588 Lisp_Object tail;
1589 Lisp_Object frame1 = Qnil;
1591 /* Look for another visible frame on the same terminal.
1592 Do not call next_frame here because it may loop forever.
1593 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1594 FOR_EACH_FRAME (tail, frame1)
1595 if (!EQ (frame, frame1)
1596 && (FRAME_TERMINAL (XFRAME (frame))
1597 == FRAME_TERMINAL (XFRAME (frame1)))
1598 && FRAME_VISIBLE_P (XFRAME (frame1)))
1599 break;
1601 /* If there is none, find *some* other frame. */
1602 if (NILP (frame1) || EQ (frame1, frame))
1604 FOR_EACH_FRAME (tail, frame1)
1606 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1608 /* Do not change a text terminal's top-frame. */
1609 struct frame *f1 = XFRAME (frame1);
1610 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1612 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1613 if (!EQ (top_frame, frame))
1614 frame1 = top_frame;
1616 break;
1620 #ifdef NS_IMPL_COCOA
1621 else
1622 /* Under NS, there is no system mechanism for choosing a new
1623 window to get focus -- it is left to application code.
1624 So the portion of THIS application interfacing with NS
1625 needs to know about it. We call Fraise_frame, but the
1626 purpose is really to transfer focus. */
1627 Fraise_frame (frame1);
1628 #endif
1630 do_switch_frame (frame1, 0, 1, Qnil);
1631 sf = SELECTED_FRAME ();
1634 /* Don't allow minibuf_window to remain on a deleted frame. */
1635 check_minibuf_window (frame, minibuffer_selected);
1637 /* Don't let echo_area_window to remain on a deleted frame. */
1638 if (EQ (f->minibuffer_window, echo_area_window))
1639 echo_area_window = sf->minibuffer_window;
1641 /* Clear any X selections for this frame. */
1642 #ifdef HAVE_X_WINDOWS
1643 if (FRAME_X_P (f))
1644 x_clear_frame_selections (f);
1645 #endif
1647 /* Free glyphs.
1648 This function must be called before the window tree of the
1649 frame is deleted because windows contain dynamically allocated
1650 memory. */
1651 free_glyphs (f);
1653 #ifdef HAVE_WINDOW_SYSTEM
1654 /* Give chance to each font driver to free a frame specific data. */
1655 font_update_drivers (f, Qnil);
1656 #endif
1658 /* Mark all the windows that used to be on FRAME as deleted, and then
1659 remove the reference to them. */
1660 delete_all_child_windows (f->root_window);
1661 fset_root_window (f, Qnil);
1663 Vframe_list = Fdelq (frame, Vframe_list);
1664 SET_FRAME_VISIBLE (f, 0);
1666 /* Allow the vector of menu bar contents to be freed in the next
1667 garbage collection. The frame object itself may not be garbage
1668 collected until much later, because recent_keys and other data
1669 structures can still refer to it. */
1670 fset_menu_bar_vector (f, Qnil);
1672 /* If FRAME's buffer lists contains killed
1673 buffers, this helps GC to reclaim them. */
1674 fset_buffer_list (f, Qnil);
1675 fset_buried_buffer_list (f, Qnil);
1677 free_font_driver_list (f);
1678 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1679 xfree (f->namebuf);
1680 #endif
1681 xfree (f->decode_mode_spec_buffer);
1682 xfree (FRAME_INSERT_COST (f));
1683 xfree (FRAME_DELETEN_COST (f));
1684 xfree (FRAME_INSERTN_COST (f));
1685 xfree (FRAME_DELETE_COST (f));
1687 /* Since some events are handled at the interrupt level, we may get
1688 an event for f at any time; if we zero out the frame's terminal
1689 now, then we may trip up the event-handling code. Instead, we'll
1690 promise that the terminal of the frame must be valid until we
1691 have called the window-system-dependent frame destruction
1692 routine. */
1696 struct terminal *terminal;
1697 block_input ();
1698 if (FRAME_TERMINAL (f)->delete_frame_hook)
1699 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1700 terminal = FRAME_TERMINAL (f);
1701 f->output_data.nothing = 0;
1702 f->terminal = 0; /* Now the frame is dead. */
1703 unblock_input ();
1705 /* If needed, delete the terminal that this frame was on.
1706 (This must be done after the frame is killed.) */
1707 terminal->reference_count--;
1708 #ifdef USE_GTK
1709 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1710 bug.
1711 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1712 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1713 terminal->reference_count = 1;
1714 #endif /* USE_GTK */
1715 if (terminal->reference_count == 0)
1717 Lisp_Object tmp;
1718 XSETTERMINAL (tmp, terminal);
1720 kb = NULL;
1721 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1723 else
1724 kb = terminal->kboard;
1727 /* If we've deleted the last_nonminibuf_frame, then try to find
1728 another one. */
1729 if (f == last_nonminibuf_frame)
1731 Lisp_Object frames, this;
1733 last_nonminibuf_frame = 0;
1735 FOR_EACH_FRAME (frames, this)
1737 f = XFRAME (this);
1738 if (!FRAME_MINIBUF_ONLY_P (f))
1740 last_nonminibuf_frame = f;
1741 break;
1746 /* If there's no other frame on the same kboard, get out of
1747 single-kboard state if we're in it for this kboard. */
1748 if (kb != NULL)
1750 Lisp_Object frames, this;
1751 /* Some frame we found on the same kboard, or nil if there are none. */
1752 Lisp_Object frame_on_same_kboard = Qnil;
1754 FOR_EACH_FRAME (frames, this)
1755 if (kb == FRAME_KBOARD (XFRAME (this)))
1756 frame_on_same_kboard = this;
1758 if (NILP (frame_on_same_kboard))
1759 not_single_kboard_state (kb);
1763 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1764 find another one. Prefer minibuffer-only frames, but also notice
1765 frames with other windows. */
1766 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1768 Lisp_Object frames, this;
1770 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1771 Lisp_Object frame_with_minibuf = Qnil;
1772 /* Some frame we found on the same kboard, or nil if there are none. */
1773 Lisp_Object frame_on_same_kboard = Qnil;
1775 FOR_EACH_FRAME (frames, this)
1777 struct frame *f1 = XFRAME (this);
1779 /* Consider only frames on the same kboard
1780 and only those with minibuffers. */
1781 if (kb == FRAME_KBOARD (f1)
1782 && FRAME_HAS_MINIBUF_P (f1))
1784 frame_with_minibuf = this;
1785 if (FRAME_MINIBUF_ONLY_P (f1))
1786 break;
1789 if (kb == FRAME_KBOARD (f1))
1790 frame_on_same_kboard = this;
1793 if (!NILP (frame_on_same_kboard))
1795 /* We know that there must be some frame with a minibuffer out
1796 there. If this were not true, all of the frames present
1797 would have to be minibufferless, which implies that at some
1798 point their minibuffer frames must have been deleted, but
1799 that is prohibited at the top; you can't delete surrogate
1800 minibuffer frames. */
1801 if (NILP (frame_with_minibuf))
1802 emacs_abort ();
1804 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1806 else
1807 /* No frames left on this kboard--say no minibuffer either. */
1808 kset_default_minibuffer_frame (kb, Qnil);
1811 /* Cause frame titles to update--necessary if we now have just one frame. */
1812 if (!is_tooltip_frame)
1813 update_mode_lines = 15;
1815 return Qnil;
1818 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1819 doc: /* Delete FRAME, permanently eliminating it from use.
1820 FRAME defaults to the selected frame.
1822 A frame may not be deleted if its minibuffer is used by other frames.
1823 Normally, you may not delete a frame if all other frames are invisible,
1824 but if the second optional argument FORCE is non-nil, you may do so.
1826 This function runs `delete-frame-functions' before actually
1827 deleting the frame, unless the frame is a tooltip.
1828 The functions are run with one argument, the frame to be deleted. */)
1829 (Lisp_Object frame, Lisp_Object force)
1831 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1835 /* Return mouse position in character cell units. */
1837 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1838 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1839 The position is given in canonical character cells, where (0, 0) is the
1840 upper-left corner of the frame, X is the horizontal offset, and Y is the
1841 vertical offset, measured in units of the frame's default character size.
1842 If Emacs is running on a mouseless terminal or hasn't been programmed
1843 to read the mouse position, it returns the selected frame for FRAME
1844 and nil for X and Y.
1845 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1846 passing the normal return value to that function as an argument,
1847 and returns whatever that function returns. */)
1848 (void)
1850 struct frame *f;
1851 Lisp_Object lispy_dummy;
1852 Lisp_Object x, y, retval;
1853 struct gcpro gcpro1;
1855 f = SELECTED_FRAME ();
1856 x = y = Qnil;
1858 /* It's okay for the hook to refrain from storing anything. */
1859 if (FRAME_TERMINAL (f)->mouse_position_hook)
1861 enum scroll_bar_part party_dummy;
1862 Time time_dummy;
1863 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1864 &lispy_dummy, &party_dummy,
1865 &x, &y,
1866 &time_dummy);
1869 if (! NILP (x))
1871 int col = XINT (x);
1872 int row = XINT (y);
1873 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1874 XSETINT (x, col);
1875 XSETINT (y, row);
1877 XSETFRAME (lispy_dummy, f);
1878 retval = Fcons (lispy_dummy, Fcons (x, y));
1879 GCPRO1 (retval);
1880 if (!NILP (Vmouse_position_function))
1881 retval = call1 (Vmouse_position_function, retval);
1882 RETURN_UNGCPRO (retval);
1885 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1886 Smouse_pixel_position, 0, 0, 0,
1887 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1888 The position is given in pixel units, where (0, 0) is the
1889 upper-left corner of the frame, X is the horizontal offset, and Y is
1890 the vertical offset.
1891 If Emacs is running on a mouseless terminal or hasn't been programmed
1892 to read the mouse position, it returns the selected frame for FRAME
1893 and nil for X and Y. */)
1894 (void)
1896 struct frame *f;
1897 Lisp_Object lispy_dummy;
1898 Lisp_Object x, y, retval;
1899 struct gcpro gcpro1;
1901 f = SELECTED_FRAME ();
1902 x = y = Qnil;
1904 /* It's okay for the hook to refrain from storing anything. */
1905 if (FRAME_TERMINAL (f)->mouse_position_hook)
1907 enum scroll_bar_part party_dummy;
1908 Time time_dummy;
1909 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1910 &lispy_dummy, &party_dummy,
1911 &x, &y,
1912 &time_dummy);
1915 XSETFRAME (lispy_dummy, f);
1916 retval = Fcons (lispy_dummy, Fcons (x, y));
1917 GCPRO1 (retval);
1918 if (!NILP (Vmouse_position_function))
1919 retval = call1 (Vmouse_position_function, retval);
1920 RETURN_UNGCPRO (retval);
1923 #ifdef HAVE_WINDOW_SYSTEM
1925 /* On frame F, convert character coordinates X and Y to pixel
1926 coordinates *PIX_X and *PIX_Y. */
1928 static void
1929 frame_char_to_pixel_position (struct frame *f, int x, int y,
1930 int *pix_x, int *pix_y)
1932 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
1933 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
1935 if (*pix_x < 0)
1936 *pix_x = 0;
1937 if (*pix_x > FRAME_PIXEL_WIDTH (f))
1938 *pix_x = FRAME_PIXEL_WIDTH (f);
1940 if (*pix_y < 0)
1941 *pix_y = 0;
1942 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
1943 *pix_y = FRAME_PIXEL_HEIGHT (f);
1946 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1948 static void
1949 frame_set_mouse_position (struct frame *f, int x, int y)
1951 int pix_x, pix_y;
1953 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
1954 frame_set_mouse_pixel_position (f, pix_x, pix_y);
1957 #endif /* HAVE_WINDOW_SYSTEM */
1959 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1960 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1961 Coordinates are relative to the frame, not a window,
1962 so the coordinates of the top left character in the frame
1963 may be nonzero due to left-hand scroll bars or the menu bar.
1965 The position is given in canonical character cells, where (0, 0) is
1966 the upper-left corner of the frame, X is the horizontal offset, and
1967 Y is the vertical offset, measured in units of the frame's default
1968 character size.
1970 This function is a no-op for an X frame that is not visible.
1971 If you have just created a frame, you must wait for it to become visible
1972 before calling this function on it, like this.
1973 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1974 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1976 CHECK_LIVE_FRAME (frame);
1977 CHECK_TYPE_RANGED_INTEGER (int, x);
1978 CHECK_TYPE_RANGED_INTEGER (int, y);
1980 /* I think this should be done with a hook. */
1981 #ifdef HAVE_WINDOW_SYSTEM
1982 if (FRAME_WINDOW_P (XFRAME (frame)))
1983 /* Warping the mouse will cause enternotify and focus events. */
1984 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1985 #else
1986 #if defined (MSDOS)
1987 if (FRAME_MSDOS_P (XFRAME (frame)))
1989 Fselect_frame (frame, Qnil);
1990 mouse_moveto (XINT (x), XINT (y));
1992 #else
1993 #ifdef HAVE_GPM
1995 Fselect_frame (frame, Qnil);
1996 term_mouse_moveto (XINT (x), XINT (y));
1998 #endif
1999 #endif
2000 #endif
2002 return Qnil;
2005 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
2006 Sset_mouse_pixel_position, 3, 3, 0,
2007 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
2008 The position is given in pixels, where (0, 0) is the upper-left corner
2009 of the frame, X is the horizontal offset, and Y is the vertical offset.
2011 Note, this is a no-op for an X frame that is not visible.
2012 If you have just created a frame, you must wait for it to become visible
2013 before calling this function on it, like this.
2014 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2015 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2017 CHECK_LIVE_FRAME (frame);
2018 CHECK_TYPE_RANGED_INTEGER (int, x);
2019 CHECK_TYPE_RANGED_INTEGER (int, y);
2021 /* I think this should be done with a hook. */
2022 #ifdef HAVE_WINDOW_SYSTEM
2023 if (FRAME_WINDOW_P (XFRAME (frame)))
2024 /* Warping the mouse will cause enternotify and focus events. */
2025 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
2026 #else
2027 #if defined (MSDOS)
2028 if (FRAME_MSDOS_P (XFRAME (frame)))
2030 Fselect_frame (frame, Qnil);
2031 mouse_moveto (XINT (x), XINT (y));
2033 #else
2034 #ifdef HAVE_GPM
2036 Fselect_frame (frame, Qnil);
2037 term_mouse_moveto (XINT (x), XINT (y));
2039 #endif
2040 #endif
2041 #endif
2043 return Qnil;
2046 static void make_frame_visible_1 (Lisp_Object);
2048 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2049 0, 1, "",
2050 doc: /* Make the frame FRAME visible (assuming it is an X window).
2051 If omitted, FRAME defaults to the currently selected frame. */)
2052 (Lisp_Object frame)
2054 struct frame *f = decode_live_frame (frame);
2056 /* I think this should be done with a hook. */
2057 #ifdef HAVE_WINDOW_SYSTEM
2058 if (FRAME_WINDOW_P (f))
2059 x_make_frame_visible (f);
2060 #endif
2062 make_frame_visible_1 (f->root_window);
2064 /* Make menu bar update for the Buffers and Frames menus. */
2065 /* windows_or_buffers_changed = 15; FIXME: Why? */
2067 XSETFRAME (frame, f);
2068 return frame;
2071 /* Update the display_time slot of the buffers shown in WINDOW
2072 and all its descendants. */
2074 static void
2075 make_frame_visible_1 (Lisp_Object window)
2077 struct window *w;
2079 for (; !NILP (window); window = w->next)
2081 w = XWINDOW (window);
2082 if (WINDOWP (w->contents))
2083 make_frame_visible_1 (w->contents);
2084 else
2085 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2089 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2090 0, 2, "",
2091 doc: /* Make the frame FRAME invisible.
2092 If omitted, FRAME defaults to the currently selected frame.
2093 On graphical displays, invisible frames are not updated and are
2094 usually not displayed at all, even in a window system's \"taskbar\".
2096 Normally you may not make FRAME invisible if all other frames are invisible,
2097 but if the second optional argument FORCE is non-nil, you may do so.
2099 This function has no effect on text terminal frames. Such frames are
2100 always considered visible, whether or not they are currently being
2101 displayed in the terminal. */)
2102 (Lisp_Object frame, Lisp_Object force)
2104 struct frame *f = decode_live_frame (frame);
2106 if (NILP (force) && !other_visible_frames (f))
2107 error ("Attempt to make invisible the sole visible or iconified frame");
2109 /* Don't allow minibuf_window to remain on an invisible frame. */
2110 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2112 /* I think this should be done with a hook. */
2113 #ifdef HAVE_WINDOW_SYSTEM
2114 if (FRAME_WINDOW_P (f))
2115 x_make_frame_invisible (f);
2116 #endif
2118 /* Make menu bar update for the Buffers and Frames menus. */
2119 windows_or_buffers_changed = 16;
2121 return Qnil;
2124 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2125 0, 1, "",
2126 doc: /* Make the frame FRAME into an icon.
2127 If omitted, FRAME defaults to the currently selected frame. */)
2128 (Lisp_Object frame)
2130 struct frame *f = decode_live_frame (frame);
2132 /* Don't allow minibuf_window to remain on an iconified frame. */
2133 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2135 /* I think this should be done with a hook. */
2136 #ifdef HAVE_WINDOW_SYSTEM
2137 if (FRAME_WINDOW_P (f))
2138 x_iconify_frame (f);
2139 #endif
2141 /* Make menu bar update for the Buffers and Frames menus. */
2142 windows_or_buffers_changed = 17;
2144 return Qnil;
2147 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2148 1, 1, 0,
2149 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2150 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2151 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2152 On graphical displays, invisible frames are not updated and are
2153 usually not displayed at all, even in a window system's \"taskbar\".
2155 If FRAME is a text terminal frame, this always returns t.
2156 Such frames are always considered visible, whether or not they are
2157 currently being displayed on the terminal. */)
2158 (Lisp_Object frame)
2160 CHECK_LIVE_FRAME (frame);
2162 if (FRAME_VISIBLE_P (XFRAME (frame)))
2163 return Qt;
2164 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2165 return Qicon;
2166 return Qnil;
2169 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2170 0, 0, 0,
2171 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2172 (void)
2174 Lisp_Object tail, frame, value = Qnil;
2176 FOR_EACH_FRAME (tail, frame)
2177 if (FRAME_VISIBLE_P (XFRAME (frame)))
2178 value = Fcons (frame, value);
2180 return value;
2184 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2185 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2186 If FRAME is invisible or iconified, make it visible.
2187 If you don't specify a frame, the selected frame is used.
2188 If Emacs is displaying on an ordinary terminal or some other device which
2189 doesn't support multiple overlapping frames, this function selects FRAME. */)
2190 (Lisp_Object frame)
2192 struct frame *f = decode_live_frame (frame);
2194 XSETFRAME (frame, f);
2196 if (FRAME_TERMCAP_P (f))
2197 /* On a text terminal select FRAME. */
2198 Fselect_frame (frame, Qnil);
2199 else
2200 /* Do like the documentation says. */
2201 Fmake_frame_visible (frame);
2203 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2204 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2206 return Qnil;
2209 /* Should we have a corresponding function called Flower_Power? */
2210 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2211 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2212 If you don't specify a frame, the selected frame is used.
2213 If Emacs is displaying on an ordinary terminal or some other device which
2214 doesn't support multiple overlapping frames, this function does nothing. */)
2215 (Lisp_Object frame)
2217 struct frame *f = decode_live_frame (frame);
2219 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2220 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2222 return Qnil;
2226 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2227 1, 2, 0,
2228 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2229 In other words, switch-frame events caused by events in FRAME will
2230 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2231 FOCUS-FRAME after reading an event typed at FRAME.
2233 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2234 frame again receives its own keystrokes.
2236 Focus redirection is useful for temporarily redirecting keystrokes to
2237 a surrogate minibuffer frame when a frame doesn't have its own
2238 minibuffer window.
2240 A frame's focus redirection can be changed by `select-frame'. If frame
2241 FOO is selected, and then a different frame BAR is selected, any
2242 frames redirecting their focus to FOO are shifted to redirect their
2243 focus to BAR. This allows focus redirection to work properly when the
2244 user switches from one frame to another using `select-window'.
2246 This means that a frame whose focus is redirected to itself is treated
2247 differently from a frame whose focus is redirected to nil; the former
2248 is affected by `select-frame', while the latter is not.
2250 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2251 (Lisp_Object frame, Lisp_Object focus_frame)
2253 /* Note that we don't check for a live frame here. It's reasonable
2254 to redirect the focus of a frame you're about to delete, if you
2255 know what other frame should receive those keystrokes. */
2256 struct frame *f = decode_any_frame (frame);
2258 if (! NILP (focus_frame))
2259 CHECK_LIVE_FRAME (focus_frame);
2261 fset_focus_frame (f, focus_frame);
2263 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2264 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2266 return Qnil;
2270 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2271 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2272 If FRAME is omitted or nil, the selected frame is used.
2273 Return nil if FRAME's focus is not redirected.
2274 See `redirect-frame-focus'. */)
2275 (Lisp_Object frame)
2277 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2280 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2281 doc: /* Set the input focus to FRAME.
2282 FRAME nil means use the selected frame.
2283 If there is no window system support, this function does nothing. */)
2284 (Lisp_Object frame)
2286 #ifdef HAVE_WINDOW_SYSTEM
2287 x_focus_frame (decode_window_system_frame (frame));
2288 #endif
2289 return Qnil;
2292 DEFUN ("frame-after-make-frame",
2293 Fframe_after_make_frame,
2294 Sframe_after_make_frame, 2, 2, 0,
2295 doc: /* Mark FRAME as made.
2296 FRAME nil means use the selected frame. Second argument MADE non-nil
2297 means functions on `window-configuration-change-hook' are called
2298 whenever the window configuration of FRAME changes. MADE nil means
2299 these functions are not called.
2301 This function is currently called by `make-frame' only and should be
2302 otherwise used with utter care to avoid that running functions on
2303 `window-configuration-change-hook' is impeded forever. */)
2304 (Lisp_Object frame, Lisp_Object made)
2306 struct frame *f = decode_live_frame (frame);
2307 f->after_make_frame = !NILP (made);
2308 return made;
2312 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2314 void
2315 frames_discard_buffer (Lisp_Object buffer)
2317 Lisp_Object frame, tail;
2319 FOR_EACH_FRAME (tail, frame)
2321 fset_buffer_list
2322 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2323 fset_buried_buffer_list
2324 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2328 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2329 If the alist already has an element for PROP, we change it. */
2331 void
2332 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2334 register Lisp_Object tem;
2336 tem = Fassq (prop, *alistptr);
2337 if (EQ (tem, Qnil))
2338 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2339 else
2340 Fsetcdr (tem, val);
2343 static int
2344 frame_name_fnn_p (char *str, ptrdiff_t len)
2346 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2348 char *p = str + 2;
2349 while ('0' <= *p && *p <= '9')
2350 p++;
2351 if (p == str + len)
2352 return 1;
2354 return 0;
2357 /* Set the name of the terminal frame. Also used by MSDOS frames.
2358 Modeled after x_set_name which is used for WINDOW frames. */
2360 static void
2361 set_term_frame_name (struct frame *f, Lisp_Object name)
2363 f->explicit_name = ! NILP (name);
2365 /* If NAME is nil, set the name to F<num>. */
2366 if (NILP (name))
2368 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2370 /* Check for no change needed in this very common case
2371 before we do any consing. */
2372 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2373 return;
2375 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2377 else
2379 CHECK_STRING (name);
2381 /* Don't change the name if it's already NAME. */
2382 if (! NILP (Fstring_equal (name, f->name)))
2383 return;
2385 /* Don't allow the user to set the frame name to F<num>, so it
2386 doesn't clash with the names we generate for terminal frames. */
2387 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2388 error ("Frame names of the form F<num> are usurped by Emacs");
2391 fset_name (f, name);
2392 update_mode_lines = 16;
2395 void
2396 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2398 register Lisp_Object old_alist_elt;
2400 /* The buffer-list parameters are stored in a special place and not
2401 in the alist. All buffers must be live. */
2402 if (EQ (prop, Qbuffer_list))
2404 Lisp_Object list = Qnil;
2405 for (; CONSP (val); val = XCDR (val))
2406 if (!NILP (Fbuffer_live_p (XCAR (val))))
2407 list = Fcons (XCAR (val), list);
2408 fset_buffer_list (f, Fnreverse (list));
2409 return;
2411 if (EQ (prop, Qburied_buffer_list))
2413 Lisp_Object list = Qnil;
2414 for (; CONSP (val); val = XCDR (val))
2415 if (!NILP (Fbuffer_live_p (XCAR (val))))
2416 list = Fcons (XCAR (val), list);
2417 fset_buried_buffer_list (f, Fnreverse (list));
2418 return;
2421 /* If PROP is a symbol which is supposed to have frame-local values,
2422 and it is set up based on this frame, switch to the global
2423 binding. That way, we can create or alter the frame-local binding
2424 without messing up the symbol's status. */
2425 if (SYMBOLP (prop))
2427 struct Lisp_Symbol *sym = XSYMBOL (prop);
2428 start:
2429 switch (sym->redirect)
2431 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2432 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2433 case SYMBOL_LOCALIZED:
2434 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2435 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2436 swap_in_global_binding (sym);
2437 break;
2439 default: emacs_abort ();
2443 /* The tty color needed to be set before the frame's parameter
2444 alist was updated with the new value. This is not true any more,
2445 but we still do this test early on. */
2446 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2447 && f == FRAME_TTY (f)->previous_frame)
2448 /* Force redisplay of this tty. */
2449 FRAME_TTY (f)->previous_frame = NULL;
2451 /* Update the frame parameter alist. */
2452 old_alist_elt = Fassq (prop, f->param_alist);
2453 if (EQ (old_alist_elt, Qnil))
2454 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2455 else
2456 Fsetcdr (old_alist_elt, val);
2458 /* Update some other special parameters in their special places
2459 in addition to the alist. */
2461 if (EQ (prop, Qbuffer_predicate))
2462 fset_buffer_predicate (f, val);
2464 if (! FRAME_WINDOW_P (f))
2466 if (EQ (prop, Qmenu_bar_lines))
2467 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2468 else if (EQ (prop, Qname))
2469 set_term_frame_name (f, val);
2472 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2474 if (! MINI_WINDOW_P (XWINDOW (val)))
2475 error ("Surrogate minibuffer windows must be minibuffer windows");
2477 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2478 && !EQ (val, f->minibuffer_window))
2479 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2481 /* Install the chosen minibuffer window, with proper buffer. */
2482 fset_minibuffer_window (f, val);
2486 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2487 is not an unspecified foreground or background color. */
2489 static Lisp_Object
2490 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2492 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2493 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2494 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2495 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2498 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2499 doc: /* Return the parameters-alist of frame FRAME.
2500 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2501 The meaningful PARMs depend on the kind of frame.
2502 If FRAME is omitted or nil, return information on the currently selected frame. */)
2503 (Lisp_Object frame)
2505 Lisp_Object alist;
2506 struct frame *f = decode_any_frame (frame);
2507 int height, width;
2508 struct gcpro gcpro1;
2510 if (!FRAME_LIVE_P (f))
2511 return Qnil;
2513 alist = Fcopy_alist (f->param_alist);
2514 GCPRO1 (alist);
2516 if (!FRAME_WINDOW_P (f))
2518 Lisp_Object elt;
2520 /* If the frame's parameter alist says the colors are
2521 unspecified and reversed, take the frame's background pixel
2522 for foreground and vice versa. */
2523 elt = Fassq (Qforeground_color, alist);
2524 if (CONSP (elt) && STRINGP (XCDR (elt)))
2526 elt = frame_unspecified_color (f, XCDR (elt));
2527 if (!NILP (elt))
2528 store_in_alist (&alist, Qforeground_color, elt);
2530 else
2531 store_in_alist (&alist, Qforeground_color,
2532 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2533 elt = Fassq (Qbackground_color, alist);
2534 if (CONSP (elt) && STRINGP (XCDR (elt)))
2536 elt = frame_unspecified_color (f, XCDR (elt));
2537 if (!NILP (elt))
2538 store_in_alist (&alist, Qbackground_color, elt);
2540 else
2541 store_in_alist (&alist, Qbackground_color,
2542 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2543 store_in_alist (&alist, Qfont,
2544 build_string (FRAME_MSDOS_P (f)
2545 ? "ms-dos"
2546 : FRAME_W32_P (f) ? "w32term"
2547 :"tty"));
2549 store_in_alist (&alist, Qname, f->name);
2550 height = (f->new_height
2551 ? (f->new_pixelwise
2552 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2553 : f->new_height)
2554 : FRAME_LINES (f));
2555 store_in_alist (&alist, Qheight, make_number (height));
2556 width = (f->new_width
2557 ? (f->new_pixelwise
2558 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2559 : f->new_width)
2560 : FRAME_COLS (f));
2561 store_in_alist (&alist, Qwidth, make_number (width));
2562 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2563 store_in_alist (&alist, Qminibuffer,
2564 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2565 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2566 : FRAME_MINIBUF_WINDOW (f)));
2567 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2568 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2569 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2571 /* I think this should be done with a hook. */
2572 #ifdef HAVE_WINDOW_SYSTEM
2573 if (FRAME_WINDOW_P (f))
2574 x_report_frame_params (f, &alist);
2575 else
2576 #endif
2578 /* This ought to be correct in f->param_alist for an X frame. */
2579 Lisp_Object lines;
2580 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2581 store_in_alist (&alist, Qmenu_bar_lines, lines);
2584 UNGCPRO;
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 ("set-frame-position", Fset_frame_position,
2976 Sset_frame_position, 3, 3, 0,
2977 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2978 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2979 actually the position of the upper left corner of the frame. Negative
2980 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2981 or bottommost possible position (that stays within the screen). */)
2982 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2984 register struct frame *f = decode_live_frame (frame);
2986 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2987 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2989 /* I think this should be done with a hook. */
2990 #ifdef HAVE_WINDOW_SYSTEM
2991 if (FRAME_WINDOW_P (f))
2992 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2993 #endif
2995 return Qt;
2999 /***********************************************************************
3000 Frame Parameters
3001 ***********************************************************************/
3003 /* Connect the frame-parameter names for X frames
3004 to the ways of passing the parameter values to the window system.
3006 The name of a parameter, as a Lisp symbol,
3007 has an `x-frame-parameter' property which is an integer in Lisp
3008 that is an index in this table. */
3010 struct frame_parm_table {
3011 const char *name;
3012 int sym;
3015 static const struct frame_parm_table frame_parms[] =
3017 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3018 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3019 {"background-color", -1},
3020 {"border-color", SYMBOL_INDEX (Qborder_color)},
3021 {"border-width", SYMBOL_INDEX (Qborder_width)},
3022 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3023 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3024 {"font", -1},
3025 {"foreground-color", -1},
3026 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3027 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3028 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3029 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3030 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3031 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3032 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3033 {"name", SYMBOL_INDEX (Qname)},
3034 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3035 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3036 {"title", SYMBOL_INDEX (Qtitle)},
3037 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3038 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3039 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3040 {"visibility", SYMBOL_INDEX (Qvisibility)},
3041 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3042 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3043 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3044 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3045 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3046 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3047 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3048 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3049 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3050 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3051 {"alpha", SYMBOL_INDEX (Qalpha)},
3052 {"sticky", SYMBOL_INDEX (Qsticky)},
3053 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3056 #ifdef HAVE_WINDOW_SYSTEM
3058 /* Change the parameters of frame F as specified by ALIST.
3059 If a parameter is not specially recognized, do nothing special;
3060 otherwise call the `x_set_...' function for that parameter.
3061 Except for certain geometry properties, always call store_frame_param
3062 to store the new value in the parameter alist. */
3064 void
3065 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3067 Lisp_Object tail;
3069 /* If both of these parameters are present, it's more efficient to
3070 set them both at once. So we wait until we've looked at the
3071 entire list before we set them. */
3072 int width IF_LINT (= 0), height IF_LINT (= 0);
3073 bool width_change = false, height_change = false;
3075 /* Same here. */
3076 Lisp_Object left, top;
3078 /* Same with these. */
3079 Lisp_Object icon_left, icon_top;
3081 /* And with this. */
3082 Lisp_Object fullscreen;
3083 bool fullscreen_change = false;
3085 /* Record in these vectors all the parms specified. */
3086 Lisp_Object *parms;
3087 Lisp_Object *values;
3088 ptrdiff_t i, p;
3089 bool left_no_change = 0, top_no_change = 0;
3090 #ifdef HAVE_X_WINDOWS
3091 bool icon_left_no_change = 0, icon_top_no_change = 0;
3092 #endif
3094 i = 0;
3095 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3096 i++;
3098 USE_SAFE_ALLOCA;
3099 SAFE_ALLOCA_LISP (parms, 2 * i);
3100 values = parms + i;
3102 /* Extract parm names and values into those vectors. */
3104 i = 0;
3105 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3107 Lisp_Object elt;
3109 elt = XCAR (tail);
3110 parms[i] = Fcar (elt);
3111 values[i] = Fcdr (elt);
3112 i++;
3114 /* TAIL and ALIST are not used again below here. */
3115 alist = tail = Qnil;
3117 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
3118 because their values appear in VALUES and strings are not valid. */
3119 top = left = Qunbound;
3120 icon_left = icon_top = Qunbound;
3122 /* Process foreground_color and background_color before anything else.
3123 They are independent of other properties, but other properties (e.g.,
3124 cursor_color) are dependent upon them. */
3125 /* Process default font as well, since fringe widths depends on it. */
3126 for (p = 0; p < i; p++)
3128 Lisp_Object prop, val;
3130 prop = parms[p];
3131 val = values[p];
3132 if (EQ (prop, Qforeground_color)
3133 || EQ (prop, Qbackground_color)
3134 || EQ (prop, Qfont))
3136 register Lisp_Object param_index, old_value;
3138 old_value = get_frame_param (f, prop);
3139 if (NILP (Fequal (val, old_value)))
3141 store_frame_param (f, prop, val);
3143 param_index = Fget (prop, Qx_frame_parameter);
3144 if (NATNUMP (param_index)
3145 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3146 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3147 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3152 /* Now process them in reverse of specified order. */
3153 while (i-- != 0)
3155 Lisp_Object prop, val;
3157 prop = parms[i];
3158 val = values[i];
3160 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
3162 width_change = 1;
3163 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3165 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
3167 height_change = 1;
3168 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3170 else if (EQ (prop, Qtop))
3171 top = val;
3172 else if (EQ (prop, Qleft))
3173 left = val;
3174 else if (EQ (prop, Qicon_top))
3175 icon_top = val;
3176 else if (EQ (prop, Qicon_left))
3177 icon_left = val;
3178 else if (EQ (prop, Qfullscreen))
3180 fullscreen = val;
3181 fullscreen_change = true;
3183 else if (EQ (prop, Qforeground_color)
3184 || EQ (prop, Qbackground_color)
3185 || EQ (prop, Qfont))
3186 /* Processed above. */
3187 continue;
3188 else
3190 register Lisp_Object param_index, old_value;
3192 old_value = get_frame_param (f, prop);
3194 store_frame_param (f, prop, val);
3196 param_index = Fget (prop, Qx_frame_parameter);
3197 if (NATNUMP (param_index)
3198 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3199 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3200 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3204 /* Don't die if just one of these was set. */
3205 if (EQ (left, Qunbound))
3207 left_no_change = 1;
3208 if (f->left_pos < 0)
3209 left = list2 (Qplus, make_number (f->left_pos));
3210 else
3211 XSETINT (left, f->left_pos);
3213 if (EQ (top, Qunbound))
3215 top_no_change = 1;
3216 if (f->top_pos < 0)
3217 top = list2 (Qplus, make_number (f->top_pos));
3218 else
3219 XSETINT (top, f->top_pos);
3222 /* If one of the icon positions was not set, preserve or default it. */
3223 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3225 #ifdef HAVE_X_WINDOWS
3226 icon_left_no_change = 1;
3227 #endif
3228 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3229 if (NILP (icon_left))
3230 XSETINT (icon_left, 0);
3232 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3234 #ifdef HAVE_X_WINDOWS
3235 icon_top_no_change = 1;
3236 #endif
3237 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3238 if (NILP (icon_top))
3239 XSETINT (icon_top, 0);
3242 /* Don't set these parameters unless they've been explicitly
3243 specified. The window might be mapped or resized while we're in
3244 this function, and we don't want to override that unless the lisp
3245 code has asked for it.
3247 Don't set these parameters unless they actually differ from the
3248 window's current parameters; the window may not actually exist
3249 yet. */
3251 Lisp_Object frame;
3253 XSETFRAME (frame, f);
3255 if ((width_change && width != FRAME_TEXT_WIDTH (f))
3256 || (height_change && height != FRAME_TEXT_HEIGHT (f))
3257 || (f->can_x_set_window_size && (f->new_height || f->new_width)))
3259 /* If necessary provide default values for HEIGHT and WIDTH. Do
3260 that here since otherwise a size change implied by an
3261 intermittent font change may get lost as in Bug#17142. */
3262 if (!width_change)
3263 width = ((f->can_x_set_window_size && f->new_width)
3264 ? (f->new_pixelwise
3265 ? f->new_width
3266 : (f->new_width * FRAME_COLUMN_WIDTH (f)))
3267 : FRAME_TEXT_WIDTH (f));
3269 if (!height_change)
3270 height = ((f->can_x_set_window_size && f->new_height)
3271 ? (f->new_pixelwise
3272 ? f->new_height
3273 : (f->new_height * FRAME_LINE_HEIGHT (f)))
3274 : FRAME_TEXT_HEIGHT (f));
3276 Fset_frame_size (frame, make_number (width), make_number (height), Qt);
3279 if ((!NILP (left) || !NILP (top))
3280 && ! (left_no_change && top_no_change)
3281 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3282 && NUMBERP (top) && XINT (top) == f->top_pos))
3284 int leftpos = 0;
3285 int toppos = 0;
3287 /* Record the signs. */
3288 f->size_hint_flags &= ~ (XNegative | YNegative);
3289 if (EQ (left, Qminus))
3290 f->size_hint_flags |= XNegative;
3291 else if (TYPE_RANGED_INTEGERP (int, left))
3293 leftpos = XINT (left);
3294 if (leftpos < 0)
3295 f->size_hint_flags |= XNegative;
3297 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3298 && CONSP (XCDR (left))
3299 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3301 leftpos = - XINT (XCAR (XCDR (left)));
3302 f->size_hint_flags |= XNegative;
3304 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3305 && CONSP (XCDR (left))
3306 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3308 leftpos = XINT (XCAR (XCDR (left)));
3311 if (EQ (top, Qminus))
3312 f->size_hint_flags |= YNegative;
3313 else if (TYPE_RANGED_INTEGERP (int, top))
3315 toppos = XINT (top);
3316 if (toppos < 0)
3317 f->size_hint_flags |= YNegative;
3319 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3320 && CONSP (XCDR (top))
3321 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3323 toppos = - XINT (XCAR (XCDR (top)));
3324 f->size_hint_flags |= YNegative;
3326 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3327 && CONSP (XCDR (top))
3328 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3330 toppos = XINT (XCAR (XCDR (top)));
3334 /* Store the numeric value of the position. */
3335 f->top_pos = toppos;
3336 f->left_pos = leftpos;
3338 f->win_gravity = NorthWestGravity;
3340 /* Actually set that position, and convert to absolute. */
3341 x_set_offset (f, leftpos, toppos, -1);
3344 if (fullscreen_change)
3346 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
3348 frame_size_history_add
3349 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
3351 store_frame_param (f, Qfullscreen, fullscreen);
3352 if (!EQ (fullscreen, old_value))
3353 x_set_fullscreen (f, fullscreen, old_value);
3357 #ifdef HAVE_X_WINDOWS
3358 if ((!NILP (icon_left) || !NILP (icon_top))
3359 && ! (icon_left_no_change && icon_top_no_change))
3360 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3361 #endif /* HAVE_X_WINDOWS */
3364 SAFE_FREE ();
3368 /* Insert a description of internally-recorded parameters of frame X
3369 into the parameter alist *ALISTPTR that is to be given to the user.
3370 Only parameters that are specific to the X window system
3371 and whose values are not correctly recorded in the frame's
3372 param_alist need to be considered here. */
3374 void
3375 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3377 Lisp_Object tem;
3378 uprintmax_t w;
3379 char buf[INT_BUFSIZE_BOUND (w)];
3381 /* Represent negative positions (off the top or left screen edge)
3382 in a way that Fmodify_frame_parameters will understand correctly. */
3383 XSETINT (tem, f->left_pos);
3384 if (f->left_pos >= 0)
3385 store_in_alist (alistptr, Qleft, tem);
3386 else
3387 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3389 XSETINT (tem, f->top_pos);
3390 if (f->top_pos >= 0)
3391 store_in_alist (alistptr, Qtop, tem);
3392 else
3393 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3395 store_in_alist (alistptr, Qborder_width,
3396 make_number (f->border_width));
3397 store_in_alist (alistptr, Qinternal_border_width,
3398 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3399 store_in_alist (alistptr, Qright_divider_width,
3400 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3401 store_in_alist (alistptr, Qbottom_divider_width,
3402 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3403 store_in_alist (alistptr, Qleft_fringe,
3404 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3405 store_in_alist (alistptr, Qright_fringe,
3406 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3407 store_in_alist (alistptr, Qscroll_bar_width,
3408 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3409 ? make_number (0)
3410 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3411 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3412 /* nil means "use default width"
3413 for non-toolkit scroll bar.
3414 ruler-mode.el depends on this. */
3415 : Qnil));
3416 store_in_alist (alistptr, Qscroll_bar_height,
3417 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3418 ? make_number (0)
3419 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3420 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3421 /* nil means "use default height"
3422 for non-toolkit scroll bar. */
3423 : Qnil));
3424 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3425 MS-Windows it returns a value whose type is HANDLE, which is
3426 actually a pointer. Explicit casting avoids compiler
3427 warnings. */
3428 w = (uintptr_t) FRAME_X_WINDOW (f);
3429 store_in_alist (alistptr, Qwindow_id,
3430 make_formatted_string (buf, "%"pMu, w));
3431 #ifdef HAVE_X_WINDOWS
3432 #ifdef USE_X_TOOLKIT
3433 /* Tooltip frame may not have this widget. */
3434 if (FRAME_X_OUTPUT (f)->widget)
3435 #endif
3436 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3437 store_in_alist (alistptr, Qouter_window_id,
3438 make_formatted_string (buf, "%"pMu, w));
3439 #endif
3440 store_in_alist (alistptr, Qicon_name, f->icon_name);
3441 store_in_alist (alistptr, Qvisibility,
3442 (FRAME_VISIBLE_P (f) ? Qt
3443 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3444 store_in_alist (alistptr, Qdisplay,
3445 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3447 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3448 tem = Qnil;
3449 else
3450 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3451 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3452 store_in_alist (alistptr, Qparent_id, tem);
3453 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3457 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3458 the previous value of that parameter, NEW_VALUE is the new value. */
3460 void
3461 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3463 if (NILP (new_value))
3464 f->want_fullscreen = FULLSCREEN_NONE;
3465 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3466 f->want_fullscreen = FULLSCREEN_BOTH;
3467 else if (EQ (new_value, Qfullwidth))
3468 f->want_fullscreen = FULLSCREEN_WIDTH;
3469 else if (EQ (new_value, Qfullheight))
3470 f->want_fullscreen = FULLSCREEN_HEIGHT;
3471 else if (EQ (new_value, Qmaximized))
3472 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3474 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3475 FRAME_TERMINAL (f)->fullscreen_hook (f);
3479 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3480 the previous value of that parameter, NEW_VALUE is the new value. */
3482 void
3483 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3485 if (NILP (new_value))
3486 f->extra_line_spacing = 0;
3487 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3488 f->extra_line_spacing = XFASTINT (new_value);
3489 else if (FLOATP (new_value))
3491 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3493 if (new_spacing >= 0)
3494 f->extra_line_spacing = new_spacing;
3495 else
3496 signal_error ("Invalid line-spacing", new_value);
3498 else
3499 signal_error ("Invalid line-spacing", new_value);
3500 if (FRAME_VISIBLE_P (f))
3501 redraw_frame (f);
3505 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3506 the previous value of that parameter, NEW_VALUE is the new value. */
3508 void
3509 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3511 Lisp_Object bgcolor;
3513 if (NILP (new_value))
3514 f->gamma = 0;
3515 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3516 /* The value 0.4545 is the normal viewing gamma. */
3517 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3518 else
3519 signal_error ("Invalid screen-gamma", new_value);
3521 /* Apply the new gamma value to the frame background. */
3522 bgcolor = Fassq (Qbackground_color, f->param_alist);
3523 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3525 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3526 if (NATNUMP (parm_index)
3527 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3528 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3529 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3530 (f, bgcolor, Qnil);
3533 Fclear_face_cache (Qnil);
3537 void
3538 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3540 Lisp_Object font_object;
3541 int fontset = -1;
3542 #ifdef HAVE_X_WINDOWS
3543 Lisp_Object font_param = arg;
3544 #endif
3546 /* Set the frame parameter back to the old value because we may
3547 fail to use ARG as the new parameter value. */
3548 store_frame_param (f, Qfont, oldval);
3550 /* ARG is a fontset name, a font name, a cons of fontset name and a
3551 font object, or a font object. In the last case, this function
3552 never fail. */
3553 if (STRINGP (arg))
3555 fontset = fs_query_fontset (arg, 0);
3556 if (fontset < 0)
3558 font_object = font_open_by_name (f, arg);
3559 if (NILP (font_object))
3560 error ("Font `%s' is not defined", SSDATA (arg));
3561 arg = AREF (font_object, FONT_NAME_INDEX);
3563 else if (fontset > 0)
3565 font_object = font_open_by_name (f, fontset_ascii (fontset));
3566 if (NILP (font_object))
3567 error ("Font `%s' is not defined", SDATA (arg));
3568 arg = AREF (font_object, FONT_NAME_INDEX);
3570 else
3571 error ("The default fontset can't be used for a frame font");
3573 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3575 /* This is the case that the ASCII font of F's fontset XCAR
3576 (arg) is changed to the font XCDR (arg) by
3577 `set-fontset-font'. */
3578 fontset = fs_query_fontset (XCAR (arg), 0);
3579 if (fontset < 0)
3580 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3581 font_object = XCDR (arg);
3582 arg = AREF (font_object, FONT_NAME_INDEX);
3583 #ifdef HAVE_X_WINDOWS
3584 font_param = Ffont_get (font_object, QCname);
3585 #endif
3587 else if (FONT_OBJECT_P (arg))
3589 font_object = arg;
3590 #ifdef HAVE_X_WINDOWS
3591 font_param = Ffont_get (font_object, QCname);
3592 #endif
3593 /* This is to store the XLFD font name in the frame parameter for
3594 backward compatibility. We should store the font-object
3595 itself in the future. */
3596 arg = AREF (font_object, FONT_NAME_INDEX);
3597 fontset = FRAME_FONTSET (f);
3598 /* Check if we can use the current fontset. If not, set FONTSET
3599 to -1 to generate a new fontset from FONT-OBJECT. */
3600 if (fontset >= 0)
3602 Lisp_Object ascii_font = fontset_ascii (fontset);
3603 Lisp_Object spec = font_spec_from_name (ascii_font);
3605 if (NILP (spec))
3606 signal_error ("Invalid font name", ascii_font);
3608 if (! font_match_p (spec, font_object))
3609 fontset = -1;
3612 else
3613 signal_error ("Invalid font", arg);
3615 if (! NILP (Fequal (font_object, oldval)))
3616 return;
3618 x_new_font (f, font_object, fontset);
3619 store_frame_param (f, Qfont, arg);
3620 #ifdef HAVE_X_WINDOWS
3621 store_frame_param (f, Qfont_param, font_param);
3622 #endif
3623 /* Recalculate toolbar height. */
3624 f->n_tool_bar_rows = 0;
3626 /* Ensure we redraw it. */
3627 clear_current_matrices (f);
3629 /* Attempt to hunt down bug#16028. */
3630 SET_FRAME_GARBAGED (f);
3632 recompute_basic_faces (f);
3634 do_pending_window_change (0);
3636 /* We used to call face-set-after-frame-default here, but it leads to
3637 recursive calls (since that function can set the `default' face's
3638 font which in turns changes the frame's `font' parameter).
3639 Also I don't know what this call is meant to do, but it seems the
3640 wrong way to do it anyway (it does a lot more work than what seems
3641 reasonable in response to a change to `font'). */
3645 void
3646 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3648 if (! NILP (new_value)
3649 && !CONSP (new_value))
3651 char *p0, *p1;
3653 CHECK_STRING (new_value);
3654 p0 = p1 = SSDATA (new_value);
3655 new_value = Qnil;
3656 while (*p0)
3658 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3659 if (p0 < p1)
3660 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3661 new_value);
3662 if (*p1)
3664 int c;
3666 while ((c = *++p1) && c_isspace (c));
3668 p0 = p1;
3670 new_value = Fnreverse (new_value);
3673 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3674 return;
3676 if (FRAME_FONT (f))
3677 free_all_realized_faces (Qnil);
3679 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3680 if (NILP (new_value))
3682 if (NILP (old_value))
3683 error ("No font backend available");
3684 font_update_drivers (f, old_value);
3685 error ("None of specified font backends are available");
3687 store_frame_param (f, Qfont_backend, new_value);
3689 if (FRAME_FONT (f))
3691 Lisp_Object frame;
3693 XSETFRAME (frame, f);
3694 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3695 face_change = true;
3696 windows_or_buffers_changed = 18;
3700 void
3701 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3703 int unit = FRAME_COLUMN_WIDTH (f);
3704 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3705 int new_width;
3707 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3708 ? eabs (XINT (new_value)) : 8);
3710 if (new_width != old_width)
3712 FRAME_LEFT_FRINGE_WIDTH (f) = new_width;
3713 FRAME_FRINGE_COLS (f) /* Round up. */
3714 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3716 if (FRAME_X_WINDOW (f) != 0)
3717 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
3719 SET_FRAME_GARBAGED (f);
3724 void
3725 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3727 int unit = FRAME_COLUMN_WIDTH (f);
3728 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3729 int new_width;
3731 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3732 ? eabs (XINT (new_value)) : 8);
3734 if (new_width != old_width)
3736 FRAME_RIGHT_FRINGE_WIDTH (f) = new_width;
3737 FRAME_FRINGE_COLS (f) /* Round up. */
3738 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3740 if (FRAME_X_WINDOW (f) != 0)
3741 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
3743 SET_FRAME_GARBAGED (f);
3748 void
3749 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3751 CHECK_TYPE_RANGED_INTEGER (int, arg);
3753 if (XINT (arg) == f->border_width)
3754 return;
3756 if (FRAME_X_WINDOW (f) != 0)
3757 error ("Cannot change the border width of a frame");
3759 f->border_width = XINT (arg);
3762 void
3763 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3765 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3767 CHECK_TYPE_RANGED_INTEGER (int, arg);
3768 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3769 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3770 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3771 if (FRAME_RIGHT_DIVIDER_WIDTH (f) != old)
3773 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
3774 adjust_frame_glyphs (f);
3775 SET_FRAME_GARBAGED (f);
3780 void
3781 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3783 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3785 CHECK_TYPE_RANGED_INTEGER (int, arg);
3786 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3787 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3788 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3789 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) != old)
3791 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
3792 adjust_frame_glyphs (f);
3793 SET_FRAME_GARBAGED (f);
3797 void
3798 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3800 Lisp_Object frame;
3801 XSETFRAME (frame, f);
3803 if (NILP (value))
3804 Fmake_frame_invisible (frame, Qt);
3805 else if (EQ (value, Qicon))
3806 Ficonify_frame (frame);
3807 else
3808 Fmake_frame_visible (frame);
3811 void
3812 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3814 f->auto_raise = !EQ (Qnil, arg);
3817 void
3818 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3820 f->auto_lower = !EQ (Qnil, arg);
3823 void
3824 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3826 f->no_split = !NILP (arg);
3829 void
3830 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3832 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3833 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3834 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3835 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3837 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3838 = (NILP (arg)
3839 ? vertical_scroll_bar_none
3840 : EQ (Qleft, arg)
3841 ? vertical_scroll_bar_left
3842 : EQ (Qright, arg)
3843 ? vertical_scroll_bar_right
3844 : EQ (Qleft, Vdefault_frame_scroll_bars)
3845 ? vertical_scroll_bar_left
3846 : EQ (Qright, Vdefault_frame_scroll_bars)
3847 ? vertical_scroll_bar_right
3848 : vertical_scroll_bar_none);
3850 /* We set this parameter before creating the X window for the
3851 frame, so we can get the geometry right from the start.
3852 However, if the window hasn't been created yet, we shouldn't
3853 call x_set_window_size. */
3854 if (FRAME_X_WINDOW (f))
3855 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
3857 SET_FRAME_GARBAGED (f);
3861 void
3862 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3864 #if USE_HORIZONTAL_SCROLL_BARS
3865 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3866 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3868 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3870 /* We set this parameter before creating the X window for the
3871 frame, so we can get the geometry right from the start.
3872 However, if the window hasn't been created yet, we shouldn't
3873 call x_set_window_size. */
3874 if (FRAME_X_WINDOW (f))
3875 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
3877 SET_FRAME_GARBAGED (f);
3879 #endif
3882 void
3883 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3885 int unit = FRAME_COLUMN_WIDTH (f);
3887 if (NILP (arg))
3889 x_set_scroll_bar_default_width (f);
3891 if (FRAME_X_WINDOW (f))
3892 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3894 SET_FRAME_GARBAGED (f);
3896 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3897 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3899 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3900 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3901 if (FRAME_X_WINDOW (f))
3902 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3904 SET_FRAME_GARBAGED (f);
3907 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3908 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3911 void
3912 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3914 #if USE_HORIZONTAL_SCROLL_BARS
3915 int unit = FRAME_LINE_HEIGHT (f);
3917 if (NILP (arg))
3919 x_set_scroll_bar_default_height (f);
3921 if (FRAME_X_WINDOW (f))
3922 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3924 SET_FRAME_GARBAGED (f);
3926 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3927 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3929 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3930 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3931 if (FRAME_X_WINDOW (f))
3932 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3934 SET_FRAME_GARBAGED (f);
3937 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3938 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3939 #endif
3942 void
3943 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3945 double alpha = 1.0;
3946 double newval[2];
3947 int i;
3948 Lisp_Object item;
3950 for (i = 0; i < 2; i++)
3952 newval[i] = 1.0;
3953 if (CONSP (arg))
3955 item = CAR (arg);
3956 arg = CDR (arg);
3958 else
3959 item = arg;
3961 if (NILP (item))
3962 alpha = - 1.0;
3963 else if (FLOATP (item))
3965 alpha = XFLOAT_DATA (item);
3966 if (! (0 <= alpha && alpha <= 1.0))
3967 args_out_of_range (make_float (0.0), make_float (1.0));
3969 else if (INTEGERP (item))
3971 EMACS_INT ialpha = XINT (item);
3972 if (! (0 <= ialpha && alpha <= 100))
3973 args_out_of_range (make_number (0), make_number (100));
3974 alpha = ialpha / 100.0;
3976 else
3977 wrong_type_argument (Qnumberp, item);
3978 newval[i] = alpha;
3981 for (i = 0; i < 2; i++)
3982 f->alpha[i] = newval[i];
3984 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3985 block_input ();
3986 x_set_frame_alpha (f);
3987 unblock_input ();
3988 #endif
3990 return;
3993 #ifndef HAVE_NS
3995 /* Non-zero if mouse is grabbed on DPYINFO
3996 and we know the frame where it is. */
3998 bool x_mouse_grabbed (Display_Info *dpyinfo)
4000 return (dpyinfo->grabbed
4001 && dpyinfo->last_mouse_frame
4002 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4005 /* Re-highlight something with mouse-face properties
4006 on DPYINFO using saved frame and mouse position. */
4008 void
4009 x_redo_mouse_highlight (Display_Info *dpyinfo)
4011 if (dpyinfo->last_mouse_motion_frame
4012 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4013 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4014 dpyinfo->last_mouse_motion_x,
4015 dpyinfo->last_mouse_motion_y);
4018 #endif /* HAVE_NS */
4020 /* Subroutines of creating an X frame. */
4022 /* Make sure that Vx_resource_name is set to a reasonable value.
4023 Fix it up, or set it to `emacs' if it is too hopeless. */
4025 void
4026 validate_x_resource_name (void)
4028 ptrdiff_t len = 0;
4029 /* Number of valid characters in the resource name. */
4030 ptrdiff_t good_count = 0;
4031 /* Number of invalid characters in the resource name. */
4032 ptrdiff_t bad_count = 0;
4033 Lisp_Object new;
4034 ptrdiff_t i;
4036 if (!STRINGP (Vx_resource_class))
4037 Vx_resource_class = build_string (EMACS_CLASS);
4039 if (STRINGP (Vx_resource_name))
4041 unsigned char *p = SDATA (Vx_resource_name);
4043 len = SBYTES (Vx_resource_name);
4045 /* Only letters, digits, - and _ are valid in resource names.
4046 Count the valid characters and count the invalid ones. */
4047 for (i = 0; i < len; i++)
4049 int c = p[i];
4050 if (! ((c >= 'a' && c <= 'z')
4051 || (c >= 'A' && c <= 'Z')
4052 || (c >= '0' && c <= '9')
4053 || c == '-' || c == '_'))
4054 bad_count++;
4055 else
4056 good_count++;
4059 else
4060 /* Not a string => completely invalid. */
4061 bad_count = 5, good_count = 0;
4063 /* If name is valid already, return. */
4064 if (bad_count == 0)
4065 return;
4067 /* If name is entirely invalid, or nearly so, or is so implausibly
4068 large that alloca might not work, use `emacs'. */
4069 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4071 Vx_resource_name = build_string ("emacs");
4072 return;
4075 /* Name is partly valid. Copy it and replace the invalid characters
4076 with underscores. */
4078 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4080 for (i = 0; i < len; i++)
4082 int c = SREF (new, i);
4083 if (! ((c >= 'a' && c <= 'z')
4084 || (c >= 'A' && c <= 'Z')
4085 || (c >= '0' && c <= '9')
4086 || c == '-' || c == '_'))
4087 SSET (new, i, '_');
4091 /* Get specified attribute from resource database RDB.
4092 See Fx_get_resource below for other parameters. */
4094 static Lisp_Object
4095 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4097 CHECK_STRING (attribute);
4098 CHECK_STRING (class);
4100 if (!NILP (component))
4101 CHECK_STRING (component);
4102 if (!NILP (subclass))
4103 CHECK_STRING (subclass);
4104 if (NILP (component) != NILP (subclass))
4105 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4107 validate_x_resource_name ();
4109 /* Allocate space for the components, the dots which separate them,
4110 and the final '\0'. Make them big enough for the worst case. */
4111 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4112 + (STRINGP (component)
4113 ? SBYTES (component) : 0)
4114 + SBYTES (attribute)
4115 + 3);
4117 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4118 + SBYTES (class)
4119 + (STRINGP (subclass)
4120 ? SBYTES (subclass) : 0)
4121 + 3);
4122 USE_SAFE_ALLOCA;
4123 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4124 char *class_key = name_key + name_keysize;
4126 /* Start with emacs.FRAMENAME for the name (the specific one)
4127 and with `Emacs' for the class key (the general one). */
4128 char *nz = lispstpcpy (name_key, Vx_resource_name);
4129 char *cz = lispstpcpy (class_key, Vx_resource_class);
4131 *cz++ = '.';
4132 cz = lispstpcpy (cz, class);
4134 if (!NILP (component))
4136 *cz++ = '.';
4137 lispstpcpy (cz, subclass);
4139 *nz++ = '.';
4140 nz = lispstpcpy (nz, component);
4143 *nz++ = '.';
4144 lispstpcpy (nz, attribute);
4146 char *value = x_get_string_resource (rdb, name_key, class_key);
4147 SAFE_FREE();
4149 if (value && *value)
4150 return build_string (value);
4151 else
4152 return Qnil;
4156 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4157 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4158 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4159 class, where INSTANCE is the name under which Emacs was invoked, or
4160 the name specified by the `-name' or `-rn' command-line arguments.
4162 The optional arguments COMPONENT and SUBCLASS add to the key and the
4163 class, respectively. You must specify both of them or neither.
4164 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4165 and the class is `Emacs.CLASS.SUBCLASS'. */)
4166 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4167 Lisp_Object subclass)
4169 check_window_system (NULL);
4171 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4172 attribute, class, component, subclass);
4175 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4177 Lisp_Object
4178 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4179 Lisp_Object class, Lisp_Object component,
4180 Lisp_Object subclass)
4182 return xrdb_get_resource (dpyinfo->xrdb,
4183 attribute, class, component, subclass);
4186 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
4187 /* Used when C code wants a resource value. */
4188 /* Called from oldXMenu/Create.c. */
4189 char *
4190 x_get_resource_string (const char *attribute, const char *class)
4192 char *result;
4193 struct frame *sf = SELECTED_FRAME ();
4194 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4195 USE_SAFE_ALLOCA;
4197 /* Allocate space for the components, the dots which separate them,
4198 and the final '\0'. */
4199 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4200 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4201 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4202 char *class_key = name_key + name_keysize;
4204 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4205 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4207 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4208 name_key, class_key);
4209 SAFE_FREE ();
4210 return result;
4212 #endif
4214 /* Return the value of parameter PARAM.
4216 First search ALIST, then Vdefault_frame_alist, then the X defaults
4217 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4219 Convert the resource to the type specified by desired_type.
4221 If no default is specified, return Qunbound. If you call
4222 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4223 and don't let it get stored in any Lisp-visible variables! */
4225 Lisp_Object
4226 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4227 const char *attribute, const char *class, enum resource_types type)
4229 Lisp_Object tem;
4231 tem = Fassq (param, alist);
4233 if (!NILP (tem))
4235 /* If we find this parm in ALIST, clear it out
4236 so that it won't be "left over" at the end. */
4237 Lisp_Object tail;
4238 XSETCAR (tem, Qnil);
4239 /* In case the parameter appears more than once in the alist,
4240 clear it out. */
4241 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4242 if (CONSP (XCAR (tail))
4243 && EQ (XCAR (XCAR (tail)), param))
4244 XSETCAR (XCAR (tail), Qnil);
4246 else
4247 tem = Fassq (param, Vdefault_frame_alist);
4249 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4250 look in the X resources. */
4251 if (EQ (tem, Qnil))
4253 if (attribute && dpyinfo)
4255 AUTO_STRING (at, attribute);
4256 AUTO_STRING (cl, class);
4257 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4259 if (NILP (tem))
4260 return Qunbound;
4262 switch (type)
4264 case RES_TYPE_NUMBER:
4265 return make_number (atoi (SSDATA (tem)));
4267 case RES_TYPE_BOOLEAN_NUMBER:
4268 if (!strcmp (SSDATA (tem), "on")
4269 || !strcmp (SSDATA (tem), "true"))
4270 return make_number (1);
4271 return make_number (atoi (SSDATA (tem)));
4272 break;
4274 case RES_TYPE_FLOAT:
4275 return make_float (atof (SSDATA (tem)));
4277 case RES_TYPE_BOOLEAN:
4278 tem = Fdowncase (tem);
4279 if (!strcmp (SSDATA (tem), "on")
4280 #ifdef HAVE_NS
4281 || !strcmp (SSDATA (tem), "yes")
4282 #endif
4283 || !strcmp (SSDATA (tem), "true"))
4284 return Qt;
4285 else
4286 return Qnil;
4288 case RES_TYPE_STRING:
4289 return tem;
4291 case RES_TYPE_SYMBOL:
4292 /* As a special case, we map the values `true' and `on'
4293 to Qt, and `false' and `off' to Qnil. */
4295 Lisp_Object lower;
4296 lower = Fdowncase (tem);
4297 if (!strcmp (SSDATA (lower), "on")
4298 #ifdef HAVE_NS
4299 || !strcmp (SSDATA (lower), "yes")
4300 #endif
4301 || !strcmp (SSDATA (lower), "true"))
4302 return Qt;
4303 else if (!strcmp (SSDATA (lower), "off")
4304 #ifdef HAVE_NS
4305 || !strcmp (SSDATA (lower), "no")
4306 #endif
4307 || !strcmp (SSDATA (lower), "false"))
4308 return Qnil;
4309 else
4310 return Fintern (tem, Qnil);
4313 default:
4314 emacs_abort ();
4317 else
4318 return Qunbound;
4320 return Fcdr (tem);
4323 static Lisp_Object
4324 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4325 const char *attribute, const char *class,
4326 enum resource_types type)
4328 return x_get_arg (FRAME_DISPLAY_INFO (f),
4329 alist, param, attribute, class, type);
4332 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4334 Lisp_Object
4335 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4336 Lisp_Object param,
4337 const char *attribute, const char *class,
4338 enum resource_types type)
4340 Lisp_Object value;
4342 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4343 attribute, class, type);
4344 if (! NILP (value) && ! EQ (value, Qunbound))
4345 store_frame_param (f, param, value);
4347 return value;
4351 /* Record in frame F the specified or default value according to ALIST
4352 of the parameter named PROP (a Lisp symbol).
4353 If no value is specified for PROP, look for an X default for XPROP
4354 on the frame named NAME.
4355 If that is not found either, use the value DEFLT. */
4357 Lisp_Object
4358 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4359 Lisp_Object deflt, const char *xprop, const char *xclass,
4360 enum resource_types type)
4362 Lisp_Object tem;
4364 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4365 if (EQ (tem, Qunbound))
4366 tem = deflt;
4367 AUTO_FRAME_ARG (arg, prop, tem);
4368 x_set_frame_parameters (f, arg);
4369 return tem;
4373 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4376 * XParseGeometry parses strings of the form
4377 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4378 * width, height, xoffset, and yoffset are unsigned integers.
4379 * Example: "=80x24+300-49"
4380 * The equal sign is optional.
4381 * It returns a bitmask that indicates which of the four values
4382 * were actually found in the string. For each value found,
4383 * the corresponding argument is updated; for each value
4384 * not found, the corresponding argument is left unchanged.
4387 static int
4388 XParseGeometry (char *string,
4389 int *x, int *y,
4390 unsigned int *width, unsigned int *height)
4392 int mask = NoValue;
4393 char *strind;
4394 unsigned long tempWidth, tempHeight;
4395 long int tempX, tempY;
4396 char *nextCharacter;
4398 if (string == NULL || *string == '\0')
4399 return mask;
4400 if (*string == '=')
4401 string++; /* ignore possible '=' at beg of geometry spec */
4403 strind = string;
4404 if (*strind != '+' && *strind != '-' && *strind != 'x')
4406 tempWidth = strtoul (strind, &nextCharacter, 10);
4407 if (strind == nextCharacter)
4408 return 0;
4409 strind = nextCharacter;
4410 mask |= WidthValue;
4413 if (*strind == 'x' || *strind == 'X')
4415 strind++;
4416 tempHeight = strtoul (strind, &nextCharacter, 10);
4417 if (strind == nextCharacter)
4418 return 0;
4419 strind = nextCharacter;
4420 mask |= HeightValue;
4423 if (*strind == '+' || *strind == '-')
4425 if (*strind == '-')
4426 mask |= XNegative;
4427 tempX = strtol (strind, &nextCharacter, 10);
4428 if (strind == nextCharacter)
4429 return 0;
4430 strind = nextCharacter;
4431 mask |= XValue;
4432 if (*strind == '+' || *strind == '-')
4434 if (*strind == '-')
4435 mask |= YNegative;
4436 tempY = strtol (strind, &nextCharacter, 10);
4437 if (strind == nextCharacter)
4438 return 0;
4439 strind = nextCharacter;
4440 mask |= YValue;
4444 /* If strind isn't at the end of the string then it's an invalid
4445 geometry specification. */
4447 if (*strind != '\0')
4448 return 0;
4450 if (mask & XValue)
4451 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4452 if (mask & YValue)
4453 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4454 if (mask & WidthValue)
4455 *width = min (tempWidth, UINT_MAX);
4456 if (mask & HeightValue)
4457 *height = min (tempHeight, UINT_MAX);
4458 return mask;
4461 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4464 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4465 make-docfile: the documentation string in ns-win.el was used for
4466 x-parse-geometry even in non-NS builds.
4468 With two definitions of x-parse-geometry in this file, various
4469 things still get confused (eg M-x apropos documentation), so that
4470 it is best if the two definitions just share the same doc-string.
4472 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4473 doc: /* Parse a display geometry string STRING.
4474 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4475 The properties returned may include `top', `left', `height', and `width'.
4476 For X, the value of `left' or `top' may be an integer,
4477 or a list (+ N) meaning N pixels relative to top/left corner,
4478 or a list (- N) meaning -N pixels relative to bottom/right corner.
4479 On Nextstep, this just calls `ns-parse-geometry'. */)
4480 (Lisp_Object string)
4482 int geometry, x, y;
4483 unsigned int width, height;
4484 Lisp_Object result;
4486 CHECK_STRING (string);
4488 #ifdef HAVE_NS
4489 if (strchr (SSDATA (string), ' ') != NULL)
4490 return call1 (Qns_parse_geometry, string);
4491 #endif
4492 geometry = XParseGeometry (SSDATA (string),
4493 &x, &y, &width, &height);
4494 result = Qnil;
4495 if (geometry & XValue)
4497 Lisp_Object element;
4499 if (x >= 0 && (geometry & XNegative))
4500 element = list3 (Qleft, Qminus, make_number (-x));
4501 else if (x < 0 && ! (geometry & XNegative))
4502 element = list3 (Qleft, Qplus, make_number (x));
4503 else
4504 element = Fcons (Qleft, make_number (x));
4505 result = Fcons (element, result);
4508 if (geometry & YValue)
4510 Lisp_Object element;
4512 if (y >= 0 && (geometry & YNegative))
4513 element = list3 (Qtop, Qminus, make_number (-y));
4514 else if (y < 0 && ! (geometry & YNegative))
4515 element = list3 (Qtop, Qplus, make_number (y));
4516 else
4517 element = Fcons (Qtop, make_number (y));
4518 result = Fcons (element, result);
4521 if (geometry & WidthValue)
4522 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4523 if (geometry & HeightValue)
4524 result = Fcons (Fcons (Qheight, make_number (height)), result);
4526 return result;
4530 /* Calculate the desired size and position of frame F.
4531 Return the flags saying which aspects were specified.
4533 Also set the win_gravity and size_hint_flags of F.
4535 Adjust height for toolbar if TOOLBAR_P is 1.
4537 This function does not make the coordinates positive. */
4539 #define DEFAULT_ROWS 35
4540 #define DEFAULT_COLS 80
4542 long
4543 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p)
4545 Lisp_Object height, width, user_size, top, left, user_position;
4546 long window_prompting = 0;
4547 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4549 /* Default values if we fall through.
4550 Actually, if that happens we should get
4551 window manager prompting. */
4552 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4553 SET_FRAME_COLS (f, DEFAULT_COLS);
4554 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4555 SET_FRAME_LINES (f, DEFAULT_ROWS);
4557 /* Window managers expect that if program-specified
4558 positions are not (0,0), they're intentional, not defaults. */
4559 f->top_pos = 0;
4560 f->left_pos = 0;
4562 /* Ensure that earlier new_width and new_height settings won't
4563 override what we specify below. */
4564 f->new_width = f->new_height = 0;
4566 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4567 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4568 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4570 if (!EQ (width, Qunbound))
4572 CHECK_NUMBER (width);
4573 if (! (0 <= XINT (width) && XINT (width) <= INT_MAX))
4574 xsignal1 (Qargs_out_of_range, width);
4576 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4579 if (!EQ (height, Qunbound))
4581 CHECK_NUMBER (height);
4582 if (! (0 <= XINT (height) && XINT (height) <= INT_MAX))
4583 xsignal1 (Qargs_out_of_range, height);
4585 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4588 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4589 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4590 window_prompting |= USSize;
4591 else
4592 window_prompting |= PSize;
4595 /* Add a tool bar height to the initial frame height so that the user
4596 gets a text display area of the size he specified with -g or via
4597 .Xdefaults. Later changes of the tool bar height don't change the
4598 frame size. This is done so that users can create tall Emacs
4599 frames without having to guess how tall the tool bar will get. */
4600 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4602 if (frame_default_tool_bar_height)
4603 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
4604 else
4606 int margin, relief;
4608 relief = (tool_bar_button_relief >= 0
4609 ? tool_bar_button_relief
4610 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4612 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4613 margin = XFASTINT (Vtool_bar_button_margin);
4614 else if (CONSP (Vtool_bar_button_margin)
4615 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4616 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4617 else
4618 margin = 0;
4620 FRAME_TOOL_BAR_HEIGHT (f)
4621 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4625 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4626 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4627 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4628 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4630 if (EQ (top, Qminus))
4632 f->top_pos = 0;
4633 window_prompting |= YNegative;
4635 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4636 && CONSP (XCDR (top))
4637 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4639 f->top_pos = - XINT (XCAR (XCDR (top)));
4640 window_prompting |= YNegative;
4642 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4643 && CONSP (XCDR (top))
4644 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4646 f->top_pos = XINT (XCAR (XCDR (top)));
4648 else if (EQ (top, Qunbound))
4649 f->top_pos = 0;
4650 else
4652 CHECK_TYPE_RANGED_INTEGER (int, top);
4653 f->top_pos = XINT (top);
4654 if (f->top_pos < 0)
4655 window_prompting |= YNegative;
4658 if (EQ (left, Qminus))
4660 f->left_pos = 0;
4661 window_prompting |= XNegative;
4663 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4664 && CONSP (XCDR (left))
4665 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4667 f->left_pos = - XINT (XCAR (XCDR (left)));
4668 window_prompting |= XNegative;
4670 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4671 && CONSP (XCDR (left))
4672 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4674 f->left_pos = XINT (XCAR (XCDR (left)));
4676 else if (EQ (left, Qunbound))
4677 f->left_pos = 0;
4678 else
4680 CHECK_TYPE_RANGED_INTEGER (int, left);
4681 f->left_pos = XINT (left);
4682 if (f->left_pos < 0)
4683 window_prompting |= XNegative;
4686 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4687 window_prompting |= USPosition;
4688 else
4689 window_prompting |= PPosition;
4692 if (window_prompting & XNegative)
4694 if (window_prompting & YNegative)
4695 f->win_gravity = SouthEastGravity;
4696 else
4697 f->win_gravity = NorthEastGravity;
4699 else
4701 if (window_prompting & YNegative)
4702 f->win_gravity = SouthWestGravity;
4703 else
4704 f->win_gravity = NorthWestGravity;
4707 f->size_hint_flags = window_prompting;
4709 return window_prompting;
4714 #endif /* HAVE_WINDOW_SYSTEM */
4716 void
4717 frame_make_pointer_invisible (struct frame *f)
4719 if (! NILP (Vmake_pointer_invisible))
4721 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4722 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4724 f->mouse_moved = 0;
4725 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4726 f->pointer_invisible = 1;
4731 void
4732 frame_make_pointer_visible (struct frame *f)
4734 /* We don't check Vmake_pointer_invisible here in case the
4735 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4736 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4737 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4739 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4740 f->pointer_invisible = 0;
4744 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4745 Sframe_pointer_visible_p, 0, 1, 0,
4746 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4747 Otherwise it returns nil. FRAME omitted or nil means the
4748 selected frame. This is useful when `make-pointer-invisible' is set. */)
4749 (Lisp_Object frame)
4751 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4756 /***********************************************************************
4757 Multimonitor data
4758 ***********************************************************************/
4760 #ifdef HAVE_WINDOW_SYSTEM
4762 # if (defined HAVE_NS \
4763 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4764 void
4765 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4767 int i;
4768 for (i = 0; i < n_monitors; ++i)
4769 xfree (monitors[i].name);
4770 xfree (monitors);
4772 # endif
4774 Lisp_Object
4775 make_monitor_attribute_list (struct MonitorInfo *monitors,
4776 int n_monitors,
4777 int primary_monitor,
4778 Lisp_Object monitor_frames,
4779 const char *source)
4781 Lisp_Object attributes_list = Qnil;
4782 Lisp_Object primary_monitor_attributes = Qnil;
4783 int i;
4785 for (i = 0; i < n_monitors; ++i)
4787 Lisp_Object geometry, workarea, attributes = Qnil;
4788 struct MonitorInfo *mi = &monitors[i];
4790 if (mi->geom.width == 0) continue;
4792 workarea = list4i (mi->work.x, mi->work.y,
4793 mi->work.width, mi->work.height);
4794 geometry = list4i (mi->geom.x, mi->geom.y,
4795 mi->geom.width, mi->geom.height);
4796 attributes = Fcons (Fcons (Qsource, build_string (source)),
4797 attributes);
4798 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4799 attributes);
4800 attributes = Fcons (Fcons (Qmm_size,
4801 list2i (mi->mm_width, mi->mm_height)),
4802 attributes);
4803 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4804 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4805 if (mi->name)
4806 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4807 strlen (mi->name))),
4808 attributes);
4810 if (i == primary_monitor)
4811 primary_monitor_attributes = attributes;
4812 else
4813 attributes_list = Fcons (attributes, attributes_list);
4816 if (!NILP (primary_monitor_attributes))
4817 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4818 return attributes_list;
4821 #endif /* HAVE_WINDOW_SYSTEM */
4824 /***********************************************************************
4825 Initialization
4826 ***********************************************************************/
4828 void
4829 syms_of_frame (void)
4831 DEFSYM (Qframep, "framep");
4832 DEFSYM (Qframe_live_p, "frame-live-p");
4833 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4834 DEFSYM (Qexplicit_name, "explicit-name");
4835 DEFSYM (Qheight, "height");
4836 DEFSYM (Qicon, "icon");
4837 DEFSYM (Qminibuffer, "minibuffer");
4838 DEFSYM (Qmodeline, "modeline");
4839 DEFSYM (Qonly, "only");
4840 DEFSYM (Qnone, "none");
4841 DEFSYM (Qwidth, "width");
4842 DEFSYM (Qgeometry, "geometry");
4843 DEFSYM (Qicon_left, "icon-left");
4844 DEFSYM (Qicon_top, "icon-top");
4845 DEFSYM (Qtooltip, "tooltip");
4846 DEFSYM (Quser_position, "user-position");
4847 DEFSYM (Quser_size, "user-size");
4848 DEFSYM (Qwindow_id, "window-id");
4849 #ifdef HAVE_X_WINDOWS
4850 DEFSYM (Qouter_window_id, "outer-window-id");
4851 #endif
4852 DEFSYM (Qparent_id, "parent-id");
4853 DEFSYM (Qx, "x");
4854 DEFSYM (Qw32, "w32");
4855 DEFSYM (Qpc, "pc");
4856 DEFSYM (Qns, "ns");
4857 DEFSYM (Qvisible, "visible");
4858 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4859 DEFSYM (Qbuffer_list, "buffer-list");
4860 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4861 DEFSYM (Qdisplay_type, "display-type");
4862 DEFSYM (Qbackground_mode, "background-mode");
4863 DEFSYM (Qnoelisp, "noelisp");
4864 DEFSYM (Qtty_color_mode, "tty-color-mode");
4865 DEFSYM (Qtty, "tty");
4866 DEFSYM (Qtty_type, "tty-type");
4868 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4870 DEFSYM (Qfullwidth, "fullwidth");
4871 DEFSYM (Qfullheight, "fullheight");
4872 DEFSYM (Qfullboth, "fullboth");
4873 DEFSYM (Qmaximized, "maximized");
4874 DEFSYM (Qx_resource_name, "x-resource-name");
4875 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4877 DEFSYM (Qterminal, "terminal");
4879 DEFSYM (Qworkarea, "workarea");
4880 DEFSYM (Qmm_size, "mm-size");
4881 DEFSYM (Qframes, "frames");
4882 DEFSYM (Qsource, "source");
4884 DEFSYM (Qframe_position, "frame-position");
4885 DEFSYM (Qframe_outer_size, "frame-outer-size");
4886 DEFSYM (Qexternal_border_size, "external-border-size");
4887 DEFSYM (Qtitle_height, "title-height");
4888 DEFSYM (Qmenu_bar_external, "menu-bar-external");
4889 DEFSYM (Qmenu_bar_size, "menu-bar-size");
4890 DEFSYM (Qtool_bar_external, "tool-bar-external");
4891 DEFSYM (Qtool_bar_size, "tool-bar-size");
4892 DEFSYM (Qframe_inner_size, "frame-inner-size");
4893 /* The following are used for frame_size_history. */
4894 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
4895 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
4896 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
4897 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
4898 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
4899 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
4900 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
4901 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
4902 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
4903 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
4904 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
4905 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
4906 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
4907 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
4908 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
4909 DEFSYM (Qtb_size_cb, "tb-size-cb");
4910 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
4911 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
4913 DEFSYM (Qchange_frame_size, "change-frame-size");
4914 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
4915 DEFSYM (Qset_window_configuration, "set-window-configuration");
4916 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
4917 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
4918 DEFSYM (Qtip_frame, "tip-frame");
4919 DEFSYM (Qterminal_frame, "terminal-frame");
4921 #ifdef HAVE_NS
4922 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4923 #endif
4925 DEFSYM (Qalpha, "alpha");
4926 DEFSYM (Qauto_lower, "auto-lower");
4927 DEFSYM (Qauto_raise, "auto-raise");
4928 DEFSYM (Qborder_color, "border-color");
4929 DEFSYM (Qborder_width, "border-width");
4930 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
4931 DEFSYM (Qcursor_color, "cursor-color");
4932 DEFSYM (Qcursor_type, "cursor-type");
4933 DEFSYM (Qfont_backend, "font-backend");
4934 DEFSYM (Qfullscreen, "fullscreen");
4935 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
4936 DEFSYM (Qicon_name, "icon-name");
4937 DEFSYM (Qicon_type, "icon-type");
4938 DEFSYM (Qinternal_border_width, "internal-border-width");
4939 DEFSYM (Qleft_fringe, "left-fringe");
4940 DEFSYM (Qline_spacing, "line-spacing");
4941 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
4942 DEFSYM (Qmouse_color, "mouse-color");
4943 DEFSYM (Qname, "name");
4944 DEFSYM (Qright_divider_width, "right-divider-width");
4945 DEFSYM (Qright_fringe, "right-fringe");
4946 DEFSYM (Qscreen_gamma, "screen-gamma");
4947 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
4948 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
4949 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
4950 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
4951 DEFSYM (Qsticky, "sticky");
4952 DEFSYM (Qtitle, "title");
4953 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
4954 DEFSYM (Qtool_bar_position, "tool-bar-position");
4955 DEFSYM (Qunsplittable, "unsplittable");
4956 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
4957 DEFSYM (Qvisibility, "visibility");
4958 DEFSYM (Qwait_for_wm, "wait-for-wm");
4961 int i;
4963 for (i = 0; i < ARRAYELTS (frame_parms); i++)
4965 Lisp_Object v = (frame_parms[i].sym < 0
4966 ? intern_c_string (frame_parms[i].name)
4967 : builtin_lisp_symbol (frame_parms[i].sym));
4968 Fput (v, Qx_frame_parameter, make_number (i));
4972 #ifdef HAVE_WINDOW_SYSTEM
4973 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4974 doc: /* The name Emacs uses to look up X resources.
4975 `x-get-resource' uses this as the first component of the instance name
4976 when requesting resource values.
4977 Emacs initially sets `x-resource-name' to the name under which Emacs
4978 was invoked, or to the value specified with the `-name' or `-rn'
4979 switches, if present.
4981 It may be useful to bind this variable locally around a call
4982 to `x-get-resource'. See also the variable `x-resource-class'. */);
4983 Vx_resource_name = Qnil;
4985 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4986 doc: /* The class Emacs uses to look up X resources.
4987 `x-get-resource' uses this as the first component of the instance class
4988 when requesting resource values.
4990 Emacs initially sets `x-resource-class' to "Emacs".
4992 Setting this variable permanently is not a reasonable thing to do,
4993 but binding this variable locally around a call to `x-get-resource'
4994 is a reasonable practice. See also the variable `x-resource-name'. */);
4995 Vx_resource_class = build_string (EMACS_CLASS);
4997 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4998 doc: /* The lower limit of the frame opacity (alpha transparency).
4999 The value should range from 0 (invisible) to 100 (completely opaque).
5000 You can also use a floating number between 0.0 and 1.0. */);
5001 Vframe_alpha_lower_limit = make_number (20);
5002 #endif
5004 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5005 doc: /* Alist of default values for frame creation.
5006 These may be set in your init file, like this:
5007 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
5008 These override values given in window system configuration data,
5009 including X Windows' defaults database.
5010 For values specific to the first Emacs frame, see `initial-frame-alist'.
5011 For window-system specific values, see `window-system-default-frame-alist'.
5012 For values specific to the separate minibuffer frame, see
5013 `minibuffer-frame-alist'.
5014 The `menu-bar-lines' element of the list controls whether new frames
5015 have menu bars; `menu-bar-mode' works by altering this element.
5016 Setting this variable does not affect existing frames, only new ones. */);
5017 Vdefault_frame_alist = Qnil;
5019 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5020 doc: /* Default position of vertical scroll bars on this window-system. */);
5021 #ifdef HAVE_WINDOW_SYSTEM
5022 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5023 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
5024 default. */
5025 Vdefault_frame_scroll_bars = Qright;
5026 #else
5027 Vdefault_frame_scroll_bars = Qleft;
5028 #endif
5029 #else
5030 Vdefault_frame_scroll_bars = Qnil;
5031 #endif
5033 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5034 scroll_bar_adjust_thumb_portion_p,
5035 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5036 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5037 even if the end of the buffer is shown (i.e. overscrolling).
5038 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5039 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5040 is visible. In this case you can not overscroll. */);
5041 scroll_bar_adjust_thumb_portion_p = 1;
5043 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5044 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5046 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5047 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5048 `mouse-position' and `mouse-pixel-position' call this function, passing their
5049 usual return value as argument, and return whatever this function returns.
5050 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5051 which need to do mouse handling at the Lisp level. */);
5052 Vmouse_position_function = Qnil;
5054 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5055 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5056 If the value is an integer, highlighting is only shown after moving the
5057 mouse, while keyboard input turns off the highlight even when the mouse
5058 is over the clickable text. However, the mouse shape still indicates
5059 when the mouse is over clickable text. */);
5060 Vmouse_highlight = Qt;
5062 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5063 doc: /* If non-nil, make pointer invisible while typing.
5064 The pointer becomes visible again when the mouse is moved. */);
5065 Vmake_pointer_invisible = Qt;
5067 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5068 doc: /* Normal hook run when a frame gains input focus. */);
5069 Vfocus_in_hook = Qnil;
5070 DEFSYM (Qfocus_in_hook, "focus-in-hook");
5072 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5073 doc: /* Normal hook run when a frame loses input focus. */);
5074 Vfocus_out_hook = Qnil;
5075 DEFSYM (Qfocus_out_hook, "focus-out-hook");
5077 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5078 doc: /* Functions run before deleting a frame.
5079 The functions are run with one arg, the frame to be deleted.
5080 See `delete-frame'.
5082 Note that functions in this list may be called just before the frame is
5083 actually deleted, or some time later (or even both when an earlier function
5084 in `delete-frame-functions' (indirectly) calls `delete-frame'
5085 recursively). */);
5086 Vdelete_frame_functions = Qnil;
5087 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5089 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5090 doc: /* Non-nil if Menu-Bar mode is enabled.
5091 See the command `menu-bar-mode' for a description of this minor mode.
5092 Setting this variable directly does not take effect;
5093 either customize it (see the info node `Easy Customization')
5094 or call the function `menu-bar-mode'. */);
5095 Vmenu_bar_mode = Qt;
5097 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5098 doc: /* Non-nil if Tool-Bar mode is enabled.
5099 See the command `tool-bar-mode' for a description of this minor mode.
5100 Setting this variable directly does not take effect;
5101 either customize it (see the info node `Easy Customization')
5102 or call the function `tool-bar-mode'. */);
5103 #ifdef HAVE_WINDOW_SYSTEM
5104 Vtool_bar_mode = Qt;
5105 #else
5106 Vtool_bar_mode = Qnil;
5107 #endif
5109 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5110 doc: /* Minibufferless frames use this frame's minibuffer.
5111 Emacs cannot create minibufferless frames unless this is set to an
5112 appropriate surrogate.
5114 Emacs consults this variable only when creating minibufferless
5115 frames; once the frame is created, it sticks with its assigned
5116 minibuffer, no matter what this variable is set to. This means that
5117 this variable doesn't necessarily say anything meaningful about the
5118 current set of frames, or where the minibuffer is currently being
5119 displayed.
5121 This variable is local to the current terminal and cannot be buffer-local. */);
5123 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
5124 doc: /* Non-nil if window system changes focus when you move the mouse.
5125 You should set this variable to tell Emacs how your window manager
5126 handles focus, since there is no way in general for Emacs to find out
5127 automatically. See also `mouse-autoselect-window'. */);
5128 focus_follows_mouse = 0;
5130 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5131 doc: /* Non-nil means resize frames pixelwise.
5132 If this option is nil, resizing a frame rounds its sizes to the frame's
5133 current values of `frame-char-height' and `frame-char-width'. If this
5134 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5135 by one pixel.
5137 With some window managers you may have to set this to non-nil in order
5138 to set the size of a frame in pixels, to maximize frames or to make them
5139 fullscreen. To resize your initial frame pixelwise, set this option to
5140 a non-nil value in your init file. */);
5141 frame_resize_pixelwise = 0;
5143 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5144 doc: /* Whether frames should be resized implicitly.
5145 If this option is nil, setting font, menu bar, tool bar, internal
5146 borders, fringes or scroll bars of a specific frame may resize the frame
5147 in order to preserve the number of columns or lines it displays. If
5148 this option is `t', no such resizing is done. Note that the size of
5149 fullscreen and maximized frames, the height of fullheight frames and the
5150 width of fullwidth frames never change implicitly.
5152 The value of this option can be also be a list of frame parameters. In
5153 this case, resizing is inhibited when changing a parameter that appears
5154 in that list. The parameters currently handled by this option include
5155 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5156 `tool-bar-lines'.
5158 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5159 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5160 `right-fringe' is handled as if the frame contained just one live
5161 window. This means, for example, that removing vertical scroll bars on
5162 a frame containing several side by side windows will shrink the frame
5163 width by the width of one scroll bar provided this option is nil and
5164 keep it unchanged if this option is either `t' or a list containing
5165 `vertical-scroll-bars'.
5167 The default value is '(tool-bar-lines) on Lucid, Motif and Windows
5168 \(which means that adding/removing a tool bar does not change the frame
5169 height), nil on all other window systems including GTK+ (which means
5170 that changing any of the parameters listed above may change the size of
5171 the frame), and `t' otherwise (which means the frame size never changes
5172 implicitly when there's no window system support).
5174 Note that when a frame is not large enough to accommodate a change of
5175 any of the parameters listed above, Emacs may try to enlarge the frame
5176 even if this option is non-nil. */);
5177 #if defined (HAVE_WINDOW_SYSTEM)
5178 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
5179 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
5180 #else
5181 frame_inhibit_implied_resize = Qnil;
5182 #endif
5183 #else
5184 frame_inhibit_implied_resize = Qt;
5185 #endif
5187 DEFVAR_LISP ("frame-size-history", frame_size_history,
5188 doc: /* History of frame size adjustments.
5189 If non-nil, list recording frame size adjustment. Adjustments are
5190 recorded only if the first element of this list is a positive number.
5191 Adding an adjustment decrements that number by one.
5193 The remaining elements are the adjustments. Each adjustment is a list
5194 of four elements `frame', `function', `sizes' and `more'. `frame' is
5195 the affected frame and `function' the invoking function. `sizes' is
5196 usually a list of four elements `old-width', `old-height', `new-width'
5197 and `new-height' representing the old and new sizes recorded/requested
5198 by `function'. `more' is a list with additional information.
5200 The function `frame--size-history' displays the value of this variable
5201 in a more readable form. */);
5202 frame_size_history = Qnil;
5204 staticpro (&Vframe_list);
5206 defsubr (&Sframep);
5207 defsubr (&Sframe_live_p);
5208 defsubr (&Swindow_system);
5209 defsubr (&Sframe_windows_min_size);
5210 defsubr (&Smake_terminal_frame);
5211 defsubr (&Shandle_switch_frame);
5212 defsubr (&Sselect_frame);
5213 defsubr (&Sselected_frame);
5214 defsubr (&Sframe_list);
5215 defsubr (&Snext_frame);
5216 defsubr (&Sprevious_frame);
5217 defsubr (&Slast_nonminibuf_frame);
5218 defsubr (&Sdelete_frame);
5219 defsubr (&Smouse_position);
5220 defsubr (&Smouse_pixel_position);
5221 defsubr (&Sset_mouse_position);
5222 defsubr (&Sset_mouse_pixel_position);
5223 #if 0
5224 defsubr (&Sframe_configuration);
5225 defsubr (&Srestore_frame_configuration);
5226 #endif
5227 defsubr (&Smake_frame_visible);
5228 defsubr (&Smake_frame_invisible);
5229 defsubr (&Siconify_frame);
5230 defsubr (&Sframe_visible_p);
5231 defsubr (&Svisible_frame_list);
5232 defsubr (&Sraise_frame);
5233 defsubr (&Slower_frame);
5234 defsubr (&Sx_focus_frame);
5235 defsubr (&Sframe_after_make_frame);
5236 defsubr (&Sredirect_frame_focus);
5237 defsubr (&Sframe_focus);
5238 defsubr (&Sframe_parameters);
5239 defsubr (&Sframe_parameter);
5240 defsubr (&Smodify_frame_parameters);
5241 defsubr (&Sframe_char_height);
5242 defsubr (&Sframe_char_width);
5243 defsubr (&Sframe_pixel_height);
5244 defsubr (&Sframe_pixel_width);
5245 defsubr (&Sframe_text_cols);
5246 defsubr (&Sframe_text_lines);
5247 defsubr (&Sframe_total_cols);
5248 defsubr (&Sframe_total_lines);
5249 defsubr (&Sframe_text_width);
5250 defsubr (&Sframe_text_height);
5251 defsubr (&Sscroll_bar_width);
5252 defsubr (&Sscroll_bar_height);
5253 defsubr (&Sfringe_width);
5254 defsubr (&Sborder_width);
5255 defsubr (&Sright_divider_width);
5256 defsubr (&Sbottom_divider_width);
5257 defsubr (&Stool_bar_pixel_width);
5258 defsubr (&Sset_frame_height);
5259 defsubr (&Sset_frame_width);
5260 defsubr (&Sset_frame_size);
5261 defsubr (&Sset_frame_position);
5262 defsubr (&Sframe_pointer_visible_p);
5264 #ifdef HAVE_WINDOW_SYSTEM
5265 defsubr (&Sx_get_resource);
5266 defsubr (&Sx_parse_geometry);
5267 #endif