Subject: Restore correct Gnus newsgroup name after sending message
[emacs.git] / src / frame.c
blobd0f653fc76249475943c7cc63fcfb08eb8cb91a7
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2017 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or (at
10 your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <limits.h>
27 #include <c-ctype.h>
29 #include "lisp.h"
31 #ifdef HAVE_WINDOW_SYSTEM
32 #include TERM_HEADER
33 #endif /* HAVE_WINDOW_SYSTEM */
35 #include "buffer.h"
36 /* These help us bind and responding to switch-frame events. */
37 #include "keyboard.h"
38 #include "frame.h"
39 #include "blockinput.h"
40 #include "termchar.h"
41 #include "termhooks.h"
42 #include "dispextern.h"
43 #include "window.h"
44 #ifdef HAVE_WINDOW_SYSTEM
45 #include "fontset.h"
46 #endif
47 #include "cm.h"
48 #ifdef MSDOS
49 #include "msdos.h"
50 #include "dosfns.h"
51 #endif
52 #ifdef USE_X_TOOLKIT
53 #include "widget.h"
54 #endif
56 /* The currently selected frame. */
58 Lisp_Object selected_frame;
60 /* A frame which is not just a mini-buffer, or NULL if there are no such
61 frames. This is usually the most recent such frame that was selected. */
63 static struct frame *last_nonminibuf_frame;
65 /* False means there are no visible garbaged frames. */
66 bool frame_garbaged;
68 /* The default tool bar height for future frames. */
69 #if defined USE_GTK || defined HAVE_NS
70 enum { frame_default_tool_bar_height = 0 };
71 #else
72 int frame_default_tool_bar_height;
73 #endif
75 #ifdef HAVE_WINDOW_SYSTEM
76 static void x_report_frame_params (struct frame *, Lisp_Object *);
77 #endif
79 /* These setters are used only in this file, so they can be private. */
80 static void
81 fset_buffer_predicate (struct frame *f, Lisp_Object val)
83 f->buffer_predicate = val;
85 static void
86 fset_minibuffer_window (struct frame *f, Lisp_Object val)
88 f->minibuffer_window = val;
91 struct frame *
92 decode_live_frame (register Lisp_Object frame)
94 if (NILP (frame))
95 frame = selected_frame;
96 CHECK_LIVE_FRAME (frame);
97 return XFRAME (frame);
100 struct frame *
101 decode_any_frame (register Lisp_Object frame)
103 if (NILP (frame))
104 frame = selected_frame;
105 CHECK_FRAME (frame);
106 return XFRAME (frame);
109 #ifdef HAVE_WINDOW_SYSTEM
110 bool
111 display_available (void)
113 return x_display_list != NULL;
115 #endif
117 struct frame *
118 decode_window_system_frame (Lisp_Object frame)
120 struct frame *f = decode_live_frame (frame);
121 check_window_system (f);
122 #ifdef HAVE_WINDOW_SYSTEM
123 return f;
124 #endif
127 void
128 check_window_system (struct frame *f)
130 #ifdef HAVE_WINDOW_SYSTEM
131 if (window_system_available (f))
132 return;
133 #endif
134 error (f ? "Window system frame should be used"
135 : "Window system is not in use or not initialized");
138 /* Return the value of frame parameter PROP in frame FRAME. */
140 Lisp_Object
141 get_frame_param (register struct frame *frame, Lisp_Object prop)
143 register Lisp_Object tem;
145 tem = Fassq (prop, frame->param_alist);
146 if (EQ (tem, Qnil))
147 return tem;
148 return Fcdr (tem);
152 void
153 frame_size_history_add (struct frame *f, Lisp_Object fun_symbol,
154 int width, int height, Lisp_Object rest)
156 Lisp_Object frame;
158 XSETFRAME (frame, f);
159 if (CONSP (frame_size_history)
160 && INTEGERP (XCAR (frame_size_history))
161 && 0 < XINT (XCAR (frame_size_history)))
162 frame_size_history =
163 Fcons (make_number (XINT (XCAR (frame_size_history)) - 1),
164 Fcons (list4
165 (frame, fun_symbol,
166 ((width > 0)
167 ? list4 (make_number (FRAME_TEXT_WIDTH (f)),
168 make_number (FRAME_TEXT_HEIGHT (f)),
169 make_number (width),
170 make_number (height))
171 : Qnil),
172 rest),
173 XCDR (frame_size_history)));
177 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
178 state of frame F would be affected by a vertical (horizontal if
179 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
180 parameter that is changed. */
181 bool
182 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
184 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
185 bool inhibit
186 = (f->after_make_frame
187 ? (EQ (frame_inhibit_implied_resize, Qt)
188 || (CONSP (frame_inhibit_implied_resize)
189 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))
190 || (horizontal
191 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight))
192 || (!horizontal
193 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth))
194 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
195 : ((horizontal && f->inhibit_horizontal_resize)
196 || (!horizontal && f->inhibit_vertical_resize)));
197 if (inhibit && !FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
198 frame_size_history_add
199 (f, Qframe_inhibit_resize, 0, 0,
200 list5 (horizontal ? Qt : Qnil, parameter,
201 f->after_make_frame ? Qt : Qnil,
202 frame_inhibit_implied_resize,
203 fullscreen));
205 return inhibit;
208 static void
209 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
211 int nlines;
212 int olines = FRAME_MENU_BAR_LINES (f);
214 /* Right now, menu bars don't work properly in minibuf-only frames;
215 most of the commands try to apply themselves to the minibuffer
216 frame itself, and get an error because you can't switch buffers
217 in or split the minibuffer window. */
218 if (FRAME_MINIBUF_ONLY_P (f))
219 return;
221 if (TYPE_RANGED_INTEGERP (int, value))
222 nlines = XINT (value);
223 else
224 nlines = 0;
226 if (nlines != olines)
228 windows_or_buffers_changed = 14;
229 FRAME_MENU_BAR_LINES (f) = nlines;
230 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
231 change_frame_size (f, FRAME_COLS (f),
232 FRAME_LINES (f) + olines - nlines,
233 0, 1, 0, 0);
237 Lisp_Object Vframe_list;
240 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
241 doc: /* Return non-nil if OBJECT is a frame.
242 Value is:
243 t for a termcap frame (a character-only terminal),
244 `x' for an Emacs frame that is really an X window,
245 `w32' for an Emacs frame that is a window on MS-Windows display,
246 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
247 `pc' for a direct-write MS-DOS frame.
248 See also `frame-live-p'. */)
249 (Lisp_Object object)
251 if (!FRAMEP (object))
252 return Qnil;
253 switch (XFRAME (object)->output_method)
255 case output_initial: /* The initial frame is like a termcap frame. */
256 case output_termcap:
257 return Qt;
258 case output_x_window:
259 return Qx;
260 case output_w32:
261 return Qw32;
262 case output_msdos_raw:
263 return Qpc;
264 case output_ns:
265 return Qns;
266 default:
267 emacs_abort ();
271 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
272 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
273 Value is nil if OBJECT is not a live frame. If object is a live
274 frame, the return value indicates what sort of terminal device it is
275 displayed on. See the documentation of `framep' for possible
276 return values. */)
277 (Lisp_Object object)
279 return ((FRAMEP (object)
280 && FRAME_LIVE_P (XFRAME (object)))
281 ? Fframep (object)
282 : Qnil);
285 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
286 doc: /* The name of the window system that FRAME is displaying through.
287 The value is a symbol:
288 nil for a termcap frame (a character-only terminal),
289 `x' for an Emacs frame that is really an X window,
290 `w32' for an Emacs frame that is a window on MS-Windows display,
291 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
292 `pc' for a direct-write MS-DOS frame.
294 FRAME defaults to the currently selected frame.
296 Use of this function as a predicate is deprecated. Instead,
297 use `display-graphic-p' or any of the other `display-*-p'
298 predicates which report frame's specific UI-related capabilities. */)
299 (Lisp_Object frame)
301 Lisp_Object type;
302 if (NILP (frame))
303 frame = selected_frame;
305 type = Fframep (frame);
307 if (NILP (type))
308 wrong_type_argument (Qframep, frame);
310 if (EQ (type, Qt))
311 return Qnil;
312 else
313 return type;
316 /* Placeholder used by temacs -nw before window.el is loaded. */
317 DEFUN ("frame-windows-min-size", Fframe_windows_min_size,
318 Sframe_windows_min_size, 4, 4, 0,
319 doc: /* */
320 attributes: const)
321 (Lisp_Object frame, Lisp_Object horizontal,
322 Lisp_Object ignore, Lisp_Object pixelwise)
324 return make_number (0);
327 static int
328 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal,
329 Lisp_Object ignore, Lisp_Object pixelwise)
331 return XINT (call4 (Qframe_windows_min_size, frame, horizontal,
332 ignore, pixelwise));
336 /* Make sure windows sizes of frame F are OK. new_width and new_height
337 are in pixels. A value of -1 means no change is requested for that
338 size (but the frame may still have to be resized to accommodate
339 windows with their minimum sizes). This can either issue a request
340 to resize the frame externally (via x_set_window_size), to resize the
341 frame internally (via resize_frame_windows) or do nothing at all.
343 The argument INHIBIT can assume the following values:
345 0 means to unconditionally call x_set_window_size even if sizes
346 apparently do not change. Fx_create_frame uses this to pass the
347 initial size to the window manager.
349 1 means to call x_set_window_size if the outer frame size really
350 changes. Fset_frame_size, Fset_frame_height, ... use this.
352 2 means to call x_set_window_size provided frame_inhibit_resize
353 allows it. The menu and tool bar code use this ("3" won't work
354 here in general because menu and tool bar are often not counted in
355 the frame's text height).
357 3 means call x_set_window_size if window minimum sizes must be
358 preserved or frame_inhibit_resize allows it. x_set_left_fringe,
359 x_set_scroll_bar_width, x_new_font ... use (or should use) this.
361 4 means call x_set_window_size only if window minimum sizes must be
362 preserved. x_set_right_divider_width, x_set_border_width and the
363 code responsible for wrapping the tool bar use this.
365 5 means to never call x_set_window_size. change_frame_size uses
366 this.
368 Note that even when x_set_window_size is not called, individual
369 windows may have to be resized (via `window--sanitize-window-sizes')
370 in order to support minimum size constraints.
372 PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the
373 symbol of the parameter changed (like `menu-bar-lines', `font', ...).
374 This is passed on to frame_inhibit_resize to let the latter decide on
375 a case-by-case basis whether the frame may be resized externally. */
376 void
377 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
378 bool pretend, Lisp_Object parameter)
380 int unit_width = FRAME_COLUMN_WIDTH (f);
381 int unit_height = FRAME_LINE_HEIGHT (f);
382 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
383 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
384 int old_cols = FRAME_COLS (f);
385 int old_lines = FRAME_LINES (f);
386 int new_pixel_width, new_pixel_height;
387 /* The following two values are calculated from the old frame pixel
388 sizes and any "new" settings for tool bar, menu bar and internal
389 borders. We do it this way to detect whether we have to call
390 x_set_window_size as consequence of the new settings. */
391 int windows_width = FRAME_WINDOWS_WIDTH (f);
392 int windows_height = FRAME_WINDOWS_HEIGHT (f);
393 int min_windows_width, min_windows_height;
394 /* These are a bit tedious, maybe we should use a macro. */
395 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
396 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
397 int old_windows_height
398 = (WINDOW_PIXEL_HEIGHT (r)
399 + ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
400 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
401 : 0));
402 int new_windows_width, new_windows_height;
403 int old_text_width = FRAME_TEXT_WIDTH (f);
404 int old_text_height = FRAME_TEXT_HEIGHT (f);
405 /* If a size is < 0 use the old value. */
406 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
407 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
408 int new_cols, new_lines;
409 bool inhibit_horizontal, inhibit_vertical;
410 Lisp_Object frame;
412 XSETFRAME (frame, f);
414 frame_size_history_add
415 (f, Qadjust_frame_size_1, new_text_width, new_text_height,
416 list2 (parameter, make_number (inhibit)));
418 /* The following two values are calculated from the old window body
419 sizes and any "new" settings for scroll bars, dividers, fringes and
420 margins (though the latter should have been processed already). */
421 min_windows_width
422 = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qt : Qnil, Qt);
423 min_windows_height
424 = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qt : Qnil, Qt);
426 if (inhibit >= 2 && inhibit <= 4)
427 /* When INHIBIT is in [2..4] inhibit if the "old" window sizes stay
428 within the limits and either resizing is inhibited or INHIBIT
429 equals 4. */
431 inhibit_horizontal = (windows_width >= min_windows_width
432 && (inhibit == 4
433 || frame_inhibit_resize (f, true, parameter)));
434 inhibit_vertical = (windows_height >= min_windows_height
435 && (inhibit == 4
436 || frame_inhibit_resize (f, false, parameter)));
438 else
439 /* Otherwise inhibit if INHIBIT equals 5. */
440 inhibit_horizontal = inhibit_vertical = inhibit == 5;
442 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
443 ? old_pixel_width
444 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
445 min_windows_width
446 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
447 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
448 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
449 new_cols = new_text_width / unit_width;
451 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
452 ? old_pixel_height
453 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
454 min_windows_height
455 + FRAME_TOP_MARGIN_HEIGHT (f)
456 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
457 new_windows_height = (new_pixel_height
458 - FRAME_TOP_MARGIN_HEIGHT (f)
459 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
460 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
461 new_lines = new_text_height / unit_height;
463 #ifdef HAVE_WINDOW_SYSTEM
464 if (FRAME_WINDOW_P (f)
465 && f->can_x_set_window_size
466 && ((!inhibit_horizontal
467 && (new_pixel_width != old_pixel_width
468 || inhibit == 0 || inhibit == 2))
469 || (!inhibit_vertical
470 && (new_pixel_height != old_pixel_height
471 || inhibit == 0 || inhibit == 2))))
472 /* We are either allowed to change the frame size or the minimum
473 sizes request such a change. Do not care for fixing minimum
474 sizes here, we do that eventually when we're called from
475 change_frame_size. */
477 /* Make sure we respect fullheight and fullwidth. */
478 if (inhibit_horizontal)
479 new_text_width = old_text_width;
480 else if (inhibit_vertical)
481 new_text_height = old_text_height;
483 frame_size_history_add
484 (f, Qadjust_frame_size_2, new_text_width, new_text_height,
485 list2 (inhibit_horizontal ? Qt : Qnil,
486 inhibit_vertical ? Qt : Qnil));
488 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
489 f->resized_p = true;
491 return;
493 #endif
495 if (new_text_width == old_text_width
496 && new_text_height == old_text_height
497 && new_windows_width == old_windows_width
498 && new_windows_height == old_windows_height
499 && new_pixel_width == old_pixel_width
500 && new_pixel_height == old_pixel_height
501 && new_cols == old_cols
502 && new_lines == old_lines)
503 /* No change. Sanitize window sizes and return. */
505 sanitize_window_sizes (Qt);
506 sanitize_window_sizes (Qnil);
508 return;
511 block_input ();
513 #ifdef MSDOS
514 /* We only can set screen dimensions to certain values supported by
515 our video hardware. Try to find the smallest size greater or
516 equal to the requested dimensions, while accounting for the fact
517 that the menu-bar lines are not counted in the frame height. */
518 int dos_new_lines = new_lines + FRAME_TOP_MARGIN (f);
519 dos_set_window_size (&dos_new_lines, &new_cols);
520 new_lines = dos_new_lines - FRAME_TOP_MARGIN (f);
521 #endif
523 if (new_windows_width != old_windows_width)
525 resize_frame_windows (f, new_windows_width, 1, 1);
527 /* MSDOS frames cannot PRETEND, as they change frame size by
528 manipulating video hardware. */
529 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
530 FrameCols (FRAME_TTY (f)) = new_cols;
532 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
533 if (WINDOWP (f->tool_bar_window))
535 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
536 XWINDOW (f->tool_bar_window)->total_cols
537 = new_windows_width / unit_width;
539 #endif
541 else if (new_cols != old_cols)
542 call2 (Qwindow__pixel_to_total, frame, Qt);
544 if (new_windows_height != old_windows_height
545 /* When the top margin has changed we have to recalculate the top
546 edges of all windows. No such calculation is necessary for the
547 left edges. */
548 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
550 resize_frame_windows (f, new_windows_height, 0, 1);
552 /* MSDOS frames cannot PRETEND, as they change frame size by
553 manipulating video hardware. */
554 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
555 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
557 else if (new_lines != old_lines)
558 call2 (Qwindow__pixel_to_total, frame, Qnil);
560 frame_size_history_add
561 (f, Qadjust_frame_size_3, new_text_width, new_text_height,
562 list4 (make_number (old_pixel_width), make_number (old_pixel_height),
563 make_number (new_pixel_width), make_number (new_pixel_height)));
565 /* Assign new sizes. */
566 FRAME_TEXT_WIDTH (f) = new_text_width;
567 FRAME_TEXT_HEIGHT (f) = new_text_height;
568 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
569 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
570 SET_FRAME_COLS (f, new_cols);
571 SET_FRAME_LINES (f, new_lines);
574 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
575 int text_area_x, text_area_y, text_area_width, text_area_height;
577 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
578 &text_area_height);
579 if (w->cursor.x >= text_area_x + text_area_width)
580 w->cursor.hpos = w->cursor.x = 0;
581 if (w->cursor.y >= text_area_y + text_area_height)
582 w->cursor.vpos = w->cursor.y = 0;
585 /* Sanitize window sizes. */
586 sanitize_window_sizes (Qt);
587 sanitize_window_sizes (Qnil);
589 adjust_frame_glyphs (f);
590 calculate_costs (f);
591 SET_FRAME_GARBAGED (f);
593 /* A frame was "resized" if one of its pixelsizes changed, even if its
594 X window wasn't resized at all. */
595 f->resized_p = (new_pixel_width != old_pixel_width
596 || new_pixel_height != old_pixel_height);
598 unblock_input ();
601 /* Allocate basically initialized frame. */
603 static struct frame *
604 allocate_frame (void)
606 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
609 struct frame *
610 make_frame (bool mini_p)
612 Lisp_Object frame;
613 struct frame *f;
614 struct window *rw, *mw UNINIT;
615 Lisp_Object root_window;
616 Lisp_Object mini_window;
618 f = allocate_frame ();
619 XSETFRAME (frame, f);
621 #ifdef USE_GTK
622 /* Initialize Lisp data. Note that allocate_frame initializes all
623 Lisp data to nil, so do it only for slots which should not be nil. */
624 fset_tool_bar_position (f, Qtop);
625 #endif
627 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
628 non-Lisp data, so do it only for slots which should not be zero.
629 To avoid subtle bugs and for the sake of readability, it's better to
630 initialize enum members explicitly even if their values are zero. */
631 f->wants_modeline = true;
632 f->redisplay = true;
633 f->garbaged = true;
634 f->can_x_set_window_size = false;
635 f->after_make_frame = false;
636 f->inhibit_horizontal_resize = false;
637 f->inhibit_vertical_resize = false;
638 f->tool_bar_redisplayed = false;
639 f->tool_bar_resized = false;
640 f->column_width = 1; /* !FRAME_WINDOW_P value. */
641 f->line_height = 1; /* !FRAME_WINDOW_P value. */
642 #ifdef HAVE_WINDOW_SYSTEM
643 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
644 f->horizontal_scroll_bars = false;
645 f->want_fullscreen = FULLSCREEN_NONE;
646 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
647 f->last_tool_bar_item = -1;
648 #endif
649 #endif
651 root_window = make_window ();
652 rw = XWINDOW (root_window);
653 if (mini_p)
655 mini_window = make_window ();
656 mw = XWINDOW (mini_window);
657 wset_next (rw, mini_window);
658 wset_prev (mw, root_window);
659 mw->mini = 1;
660 wset_frame (mw, frame);
661 fset_minibuffer_window (f, mini_window);
662 store_frame_param (f, Qminibuffer, Qt);
664 else
666 mini_window = Qnil;
667 wset_next (rw, Qnil);
668 fset_minibuffer_window (f, Qnil);
671 wset_frame (rw, frame);
673 /* 10 is arbitrary,
674 just so that there is "something there."
675 Correct size will be set up later with adjust_frame_size. */
677 SET_FRAME_COLS (f, 10);
678 SET_FRAME_LINES (f, 10);
679 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
680 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
682 rw->total_cols = 10;
683 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
684 rw->total_lines = mini_p ? 9 : 10;
685 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
687 if (mini_p)
689 mw->top_line = rw->total_lines;
690 mw->pixel_top = rw->pixel_height;
691 mw->total_cols = rw->total_cols;
692 mw->pixel_width = rw->pixel_width;
693 mw->total_lines = 1;
694 mw->pixel_height = FRAME_LINE_HEIGHT (f);
697 /* Choose a buffer for the frame's root window. */
699 Lisp_Object buf = Fcurrent_buffer ();
701 /* If current buffer is hidden, try to find another one. */
702 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
703 buf = other_buffer_safely (buf);
705 /* Use set_window_buffer, not Fset_window_buffer, and don't let
706 hooks be run by it. The reason is that the whole frame/window
707 arrangement is not yet fully initialized at this point. Windows
708 don't have the right size, glyph matrices aren't initialized
709 etc. Running Lisp functions at this point surely ends in a
710 SEGV. */
711 set_window_buffer (root_window, buf, 0, 0);
712 fset_buffer_list (f, list1 (buf));
715 if (mini_p)
717 set_window_buffer (mini_window,
718 (NILP (Vminibuffer_list)
719 ? get_minibuffer (0)
720 : Fcar (Vminibuffer_list)),
721 0, 0);
722 /* No horizontal scroll bars in minibuffers. */
723 wset_horizontal_scroll_bar (mw, Qnil);
726 fset_root_window (f, root_window);
727 fset_selected_window (f, root_window);
728 /* Make sure this window seems more recently used than
729 a newly-created, never-selected window. */
730 XWINDOW (f->selected_window)->use_time = ++window_select_count;
732 return f;
735 #ifdef HAVE_WINDOW_SYSTEM
736 /* Make a frame using a separate minibuffer window on another frame.
737 MINI_WINDOW is the minibuffer window to use. nil means use the
738 default (the global minibuffer). */
740 struct frame *
741 make_frame_without_minibuffer (Lisp_Object mini_window, KBOARD *kb,
742 Lisp_Object display)
744 struct frame *f;
746 if (!NILP (mini_window))
747 CHECK_LIVE_WINDOW (mini_window);
749 if (!NILP (mini_window)
750 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
751 error ("Frame and minibuffer must be on the same terminal");
753 /* Make a frame containing just a root window. */
754 f = make_frame (0);
756 if (NILP (mini_window))
758 /* Use default-minibuffer-frame if possible. */
759 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
760 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
762 Lisp_Object frame_dummy;
764 XSETFRAME (frame_dummy, f);
765 /* If there's no minibuffer frame to use, create one. */
766 kset_default_minibuffer_frame
767 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
770 mini_window
771 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
774 fset_minibuffer_window (f, mini_window);
775 store_frame_param (f, Qminibuffer, mini_window);
777 /* Make the chosen minibuffer window display the proper minibuffer,
778 unless it is already showing a minibuffer. */
779 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
780 /* Use set_window_buffer instead of Fset_window_buffer (see
781 discussion of bug#11984, bug#12025, bug#12026). */
782 set_window_buffer (mini_window,
783 (NILP (Vminibuffer_list)
784 ? get_minibuffer (0)
785 : Fcar (Vminibuffer_list)), 0, 0);
786 return f;
789 /* Make a frame containing only a minibuffer window. */
791 struct frame *
792 make_minibuffer_frame (void)
794 /* First make a frame containing just a root window, no minibuffer. */
796 register struct frame *f = make_frame (0);
797 register Lisp_Object mini_window;
798 register Lisp_Object frame;
800 XSETFRAME (frame, f);
802 f->auto_raise = 0;
803 f->auto_lower = 0;
804 f->no_split = 1;
805 f->wants_modeline = 0;
807 /* Now label the root window as also being the minibuffer.
808 Avoid infinite looping on the window chain by marking next pointer
809 as nil. */
811 mini_window = f->root_window;
812 fset_minibuffer_window (f, mini_window);
813 store_frame_param (f, Qminibuffer, Qonly);
814 XWINDOW (mini_window)->mini = 1;
815 wset_next (XWINDOW (mini_window), Qnil);
816 wset_prev (XWINDOW (mini_window), Qnil);
817 wset_frame (XWINDOW (mini_window), frame);
819 /* Put the proper buffer in that window. */
821 /* Use set_window_buffer instead of Fset_window_buffer (see
822 discussion of bug#11984, bug#12025, bug#12026). */
823 set_window_buffer (mini_window,
824 (NILP (Vminibuffer_list)
825 ? get_minibuffer (0)
826 : Fcar (Vminibuffer_list)), 0, 0);
827 return f;
829 #endif /* HAVE_WINDOW_SYSTEM */
831 /* Construct a frame that refers to a terminal. */
833 static printmax_t tty_frame_count;
835 struct frame *
836 make_initial_frame (void)
838 struct frame *f;
839 struct terminal *terminal;
840 Lisp_Object frame;
842 eassert (initial_kboard);
844 /* The first call must initialize Vframe_list. */
845 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
846 Vframe_list = Qnil;
848 terminal = init_initial_terminal ();
850 f = make_frame (1);
851 XSETFRAME (frame, f);
853 Vframe_list = Fcons (frame, Vframe_list);
855 tty_frame_count = 1;
856 fset_name (f, build_pure_c_string ("F1"));
858 SET_FRAME_VISIBLE (f, 1);
860 f->output_method = terminal->type;
861 f->terminal = terminal;
862 f->terminal->reference_count++;
863 f->output_data.nothing = 0;
865 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
866 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
868 #ifdef HAVE_WINDOW_SYSTEM
869 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
870 f->horizontal_scroll_bars = false;
871 #endif
873 /* The default value of menu-bar-mode is t. */
874 set_menu_bar_lines (f, make_number (1), Qnil);
876 /* Allocate glyph matrices. */
877 adjust_frame_glyphs (f);
879 if (!noninteractive)
880 init_frame_faces (f);
882 last_nonminibuf_frame = f;
884 f->can_x_set_window_size = true;
885 f->after_make_frame = true;
887 return f;
891 static struct frame *
892 make_terminal_frame (struct terminal *terminal)
894 register struct frame *f;
895 Lisp_Object frame;
896 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
898 if (!terminal->name)
899 error ("Terminal is not live, can't create new frames on it");
901 f = make_frame (1);
903 XSETFRAME (frame, f);
904 Vframe_list = Fcons (frame, Vframe_list);
906 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
908 SET_FRAME_VISIBLE (f, 1);
910 f->terminal = terminal;
911 f->terminal->reference_count++;
912 #ifdef MSDOS
913 f->output_data.tty->display_info = &the_only_display_info;
914 if (!inhibit_window_system
915 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
916 || XFRAME (selected_frame)->output_method == output_msdos_raw))
917 f->output_method = output_msdos_raw;
918 else
919 f->output_method = output_termcap;
920 #else /* not MSDOS */
921 f->output_method = output_termcap;
922 create_tty_output (f);
923 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
924 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
925 #endif /* not MSDOS */
927 #ifdef HAVE_WINDOW_SYSTEM
928 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
929 f->horizontal_scroll_bars = false;
930 #endif
932 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
933 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
934 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
935 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
937 /* Set the top frame to the newly created frame. */
938 if (FRAMEP (FRAME_TTY (f)->top_frame)
939 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
940 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
942 FRAME_TTY (f)->top_frame = frame;
944 if (!noninteractive)
945 init_frame_faces (f);
947 return f;
950 /* Get a suitable value for frame parameter PARAMETER for a newly
951 created frame, based on (1) the user-supplied frame parameter
952 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
954 static Lisp_Object
955 get_future_frame_param (Lisp_Object parameter,
956 Lisp_Object supplied_parms,
957 char *current_value)
959 Lisp_Object result;
961 result = Fassq (parameter, supplied_parms);
962 if (NILP (result))
963 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
964 if (NILP (result) && current_value != NULL)
965 result = build_string (current_value);
966 if (!NILP (result) && !STRINGP (result))
967 result = XCDR (result);
968 if (NILP (result) || !STRINGP (result))
969 result = Qnil;
971 return result;
974 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
975 1, 1, 0,
976 doc: /* Create an additional terminal frame, possibly on another terminal.
977 This function takes one argument, an alist specifying frame parameters.
979 You can create multiple frames on a single text terminal, but only one
980 of them (the selected terminal frame) is actually displayed.
982 In practice, generally you don't need to specify any parameters,
983 except when you want to create a new frame on another terminal.
984 In that case, the `tty' parameter specifies the device file to open,
985 and the `tty-type' parameter specifies the terminal type. Example:
987 (make-terminal-frame \\='((tty . "/dev/pts/5") (tty-type . "xterm")))
989 Note that changing the size of one terminal frame automatically
990 affects all frames on the same terminal device. */)
991 (Lisp_Object parms)
993 struct frame *f;
994 struct terminal *t = NULL;
995 Lisp_Object frame, tem;
996 struct frame *sf = SELECTED_FRAME ();
998 #ifdef MSDOS
999 if (sf->output_method != output_msdos_raw
1000 && sf->output_method != output_termcap)
1001 emacs_abort ();
1002 #else /* not MSDOS */
1004 #ifdef WINDOWSNT /* This should work now! */
1005 if (sf->output_method != output_termcap)
1006 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
1007 #endif
1008 #endif /* not MSDOS */
1011 Lisp_Object terminal;
1013 terminal = Fassq (Qterminal, parms);
1014 if (CONSP (terminal))
1016 terminal = XCDR (terminal);
1017 t = decode_live_terminal (terminal);
1019 #ifdef MSDOS
1020 if (t && t != the_only_display_info.terminal)
1021 /* msdos.c assumes a single tty_display_info object. */
1022 error ("Multiple terminals are not supported on this platform");
1023 if (!t)
1024 t = the_only_display_info.terminal;
1025 #endif
1028 if (!t)
1030 char *name = 0, *type = 0;
1031 Lisp_Object tty, tty_type;
1032 USE_SAFE_ALLOCA;
1034 tty = get_future_frame_param
1035 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1036 ? FRAME_TTY (XFRAME (selected_frame))->name
1037 : NULL));
1038 if (!NILP (tty))
1039 SAFE_ALLOCA_STRING (name, tty);
1041 tty_type = get_future_frame_param
1042 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1043 ? FRAME_TTY (XFRAME (selected_frame))->type
1044 : NULL));
1045 if (!NILP (tty_type))
1046 SAFE_ALLOCA_STRING (type, tty_type);
1048 t = init_tty (name, type, 0); /* Errors are not fatal. */
1049 SAFE_FREE ();
1052 f = make_terminal_frame (t);
1055 int width, height;
1056 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1057 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f),
1058 5, 0, Qterminal_frame);
1061 adjust_frame_glyphs (f);
1062 calculate_costs (f);
1063 XSETFRAME (frame, f);
1065 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1066 store_in_alist (&parms, Qtty,
1067 (t->display_info.tty->name
1068 ? build_string (t->display_info.tty->name)
1069 : Qnil));
1070 /* On terminal frames the `minibuffer' frame parameter is always
1071 virtually t. Avoid that a different value in parms causes
1072 complaints, see Bug#24758. */
1073 store_in_alist (&parms, Qminibuffer, Qt);
1074 Fmodify_frame_parameters (frame, parms);
1076 /* Make the frame face alist be frame-specific, so that each
1077 frame could change its face definitions independently. */
1078 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1079 /* Simple Fcopy_alist isn't enough, because we need the contents of
1080 the vectors which are the CDRs of associations in face_alist to
1081 be copied as well. */
1082 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1083 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1085 f->can_x_set_window_size = true;
1086 f->after_make_frame = true;
1088 return frame;
1092 /* Perform the switch to frame FRAME.
1094 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1095 FRAME1 as frame.
1097 If TRACK is non-zero and the frame that currently has the focus
1098 redirects its focus to the selected frame, redirect that focused
1099 frame's focus to FRAME instead.
1101 FOR_DELETION non-zero means that the selected frame is being
1102 deleted, which includes the possibility that the frame's terminal
1103 is dead.
1105 The value of NORECORD is passed as argument to Fselect_window. */
1107 Lisp_Object
1108 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1110 struct frame *sf = SELECTED_FRAME ();
1112 /* If FRAME is a switch-frame event, extract the frame we should
1113 switch to. */
1114 if (CONSP (frame)
1115 && EQ (XCAR (frame), Qswitch_frame)
1116 && CONSP (XCDR (frame)))
1117 frame = XCAR (XCDR (frame));
1119 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1120 a switch-frame event to arrive after a frame is no longer live,
1121 especially when deleting the initial frame during startup. */
1122 CHECK_FRAME (frame);
1123 if (! FRAME_LIVE_P (XFRAME (frame)))
1124 return Qnil;
1126 if (sf == XFRAME (frame))
1127 return frame;
1129 /* If a frame's focus has been redirected toward the currently
1130 selected frame, we should change the redirection to point to the
1131 newly selected frame. This means that if the focus is redirected
1132 from a minibufferless frame to a surrogate minibuffer frame, we
1133 can use `other-window' to switch between all the frames using
1134 that minibuffer frame, and the focus redirection will follow us
1135 around. */
1136 #if 0
1137 /* This is too greedy; it causes inappropriate focus redirection
1138 that's hard to get rid of. */
1139 if (track)
1141 Lisp_Object tail;
1143 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1145 Lisp_Object focus;
1147 if (!FRAMEP (XCAR (tail)))
1148 emacs_abort ();
1150 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1152 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1153 Fredirect_frame_focus (XCAR (tail), frame);
1156 #else /* ! 0 */
1157 /* Instead, apply it only to the frame we're pointing to. */
1158 #ifdef HAVE_WINDOW_SYSTEM
1159 if (track && FRAME_WINDOW_P (XFRAME (frame)))
1161 Lisp_Object focus, xfocus;
1163 xfocus = x_get_focus_frame (XFRAME (frame));
1164 if (FRAMEP (xfocus))
1166 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1167 if ((FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1168 /* Redirect frame focus also when FRAME has its minibuffer
1169 window on the selected frame (see Bug#24500). */
1170 || (NILP (focus)
1171 && EQ (FRAME_MINIBUF_WINDOW (XFRAME (frame)),
1172 sf->selected_window)))
1173 Fredirect_frame_focus (xfocus, frame);
1176 #endif /* HAVE_X_WINDOWS */
1177 #endif /* ! 0 */
1179 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1180 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1182 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
1184 struct frame *f = XFRAME (frame);
1185 struct tty_display_info *tty = FRAME_TTY (f);
1186 Lisp_Object top_frame = tty->top_frame;
1188 /* Don't mark the frame garbaged and/or obscured if we are
1189 switching to the frame that is already the top frame of that
1190 TTY. */
1191 if (!EQ (frame, top_frame))
1193 if (FRAMEP (top_frame))
1194 /* Mark previously displayed frame as now obscured. */
1195 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1196 SET_FRAME_VISIBLE (f, 1);
1197 /* If the new TTY frame changed dimensions, we need to
1198 resync term.c's idea of the frame size with the new
1199 frame's data. */
1200 if (FRAME_COLS (f) != FrameCols (tty))
1201 FrameCols (tty) = FRAME_COLS (f);
1202 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1203 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1205 tty->top_frame = frame;
1208 selected_frame = frame;
1209 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1210 last_nonminibuf_frame = XFRAME (selected_frame);
1212 Fselect_window (XFRAME (frame)->selected_window, norecord);
1214 /* We want to make sure that the next event generates a frame-switch
1215 event to the appropriate frame. This seems kludgy to me, but
1216 before you take it out, make sure that evaluating something like
1217 (select-window (frame-root-window (new-frame))) doesn't end up
1218 with your typing being interpreted in the new frame instead of
1219 the one you're actually typing in. */
1220 internal_last_event_frame = Qnil;
1222 return frame;
1225 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1226 doc: /* Select FRAME.
1227 Subsequent editing commands apply to its selected window.
1228 Optional argument NORECORD means to neither change the order of
1229 recently selected windows nor the buffer list.
1231 The selection of FRAME lasts until the next time the user does
1232 something to select a different frame, or until the next time
1233 this function is called. If you are using a window system, the
1234 previously selected frame may be restored as the selected frame
1235 when returning to the command loop, because it still may have
1236 the window system's input focus. On a text terminal, the next
1237 redisplay will display FRAME.
1239 This function returns FRAME, or nil if FRAME has been deleted. */)
1240 (Lisp_Object frame, Lisp_Object norecord)
1242 return do_switch_frame (frame, 1, 0, norecord);
1245 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1246 doc: /* Handle a switch-frame event EVENT.
1247 Switch-frame events are usually bound to this function.
1248 A switch-frame event tells Emacs that the window manager has requested
1249 that the user's events be directed to the frame mentioned in the event.
1250 This function selects the selected window of the frame of EVENT.
1252 If EVENT is frame object, handle it as if it were a switch-frame event
1253 to that frame. */)
1254 (Lisp_Object event)
1256 /* Preserve prefix arg that the command loop just cleared. */
1257 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1258 run_hook (Qmouse_leave_buffer_hook);
1259 /* `switch-frame' implies a focus in. */
1260 call1 (intern ("handle-focus-in"), event);
1261 return do_switch_frame (event, 0, 0, Qnil);
1264 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1265 doc: /* Return the frame that is now selected. */)
1266 (void)
1268 return selected_frame;
1271 DEFUN ("frame-list", Fframe_list, Sframe_list,
1272 0, 0, 0,
1273 doc: /* Return a list of all live frames. */)
1274 (void)
1276 Lisp_Object frames;
1277 frames = Fcopy_sequence (Vframe_list);
1278 #ifdef HAVE_WINDOW_SYSTEM
1279 if (FRAMEP (tip_frame))
1280 frames = Fdelq (tip_frame, frames);
1281 #endif
1282 return frames;
1285 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1286 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1287 If MINIBUF is nil, do not consider minibuffer-only candidate.
1288 If MINIBUF is `visible', do not consider an invisible candidate.
1289 If MINIBUF is a window, consider only its own frame and candidate now
1290 using that window as the minibuffer.
1291 If MINIBUF is 0, consider candidate if it is visible or iconified.
1292 Otherwise consider any candidate and return nil if CANDIDATE is not
1293 acceptable. */
1295 static Lisp_Object
1296 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1298 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1300 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1301 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1302 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1303 && FRAME_TTY (c) == FRAME_TTY (f)))
1305 if (NILP (minibuf))
1307 if (!FRAME_MINIBUF_ONLY_P (c))
1308 return candidate;
1310 else if (EQ (minibuf, Qvisible))
1312 if (FRAME_VISIBLE_P (c))
1313 return candidate;
1315 else if (WINDOWP (minibuf))
1317 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1318 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1319 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1320 FRAME_FOCUS_FRAME (c)))
1321 return candidate;
1323 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1325 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1326 return candidate;
1328 else
1329 return candidate;
1331 return Qnil;
1334 /* Return the next frame in the frame list after FRAME. */
1336 static Lisp_Object
1337 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1339 Lisp_Object f, tail;
1340 int passed = 0;
1342 /* There must always be at least one frame in Vframe_list. */
1343 eassert (CONSP (Vframe_list));
1345 while (passed < 2)
1346 FOR_EACH_FRAME (tail, f)
1348 if (passed)
1350 f = candidate_frame (f, frame, minibuf);
1351 if (!NILP (f))
1352 return f;
1354 if (EQ (frame, f))
1355 passed++;
1357 return frame;
1360 /* Return the previous frame in the frame list before FRAME. */
1362 static Lisp_Object
1363 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1365 Lisp_Object f, tail, prev = Qnil;
1367 /* There must always be at least one frame in Vframe_list. */
1368 eassert (CONSP (Vframe_list));
1370 FOR_EACH_FRAME (tail, f)
1372 if (EQ (frame, f) && !NILP (prev))
1373 return prev;
1374 f = candidate_frame (f, frame, minibuf);
1375 if (!NILP (f))
1376 prev = f;
1379 /* We've scanned the entire list. */
1380 if (NILP (prev))
1381 /* We went through the whole frame list without finding a single
1382 acceptable frame. Return the original frame. */
1383 return frame;
1384 else
1385 /* There were no acceptable frames in the list before FRAME; otherwise,
1386 we would have returned directly from the loop. Since PREV is the last
1387 acceptable frame in the list, return it. */
1388 return prev;
1392 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1393 doc: /* Return the next frame in the frame list after FRAME.
1394 It considers only frames on the same terminal as FRAME.
1395 By default, skip minibuffer-only frames.
1396 If omitted, FRAME defaults to the selected frame.
1397 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1398 If MINIFRAME is a window, include only its own frame
1399 and any frame now using that window as the minibuffer.
1400 If MINIFRAME is `visible', include all visible frames.
1401 If MINIFRAME is 0, include all visible and iconified frames.
1402 Otherwise, include all frames. */)
1403 (Lisp_Object frame, Lisp_Object miniframe)
1405 if (NILP (frame))
1406 frame = selected_frame;
1407 CHECK_LIVE_FRAME (frame);
1408 return next_frame (frame, miniframe);
1411 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1412 doc: /* Return the previous frame in the frame list before FRAME.
1413 It considers only frames on the same terminal as FRAME.
1414 By default, skip minibuffer-only frames.
1415 If omitted, FRAME defaults to the selected frame.
1416 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1417 If MINIFRAME is a window, include only its own frame
1418 and any frame now using that window as the minibuffer.
1419 If MINIFRAME is `visible', include all visible frames.
1420 If MINIFRAME is 0, include all visible and iconified frames.
1421 Otherwise, include all frames. */)
1422 (Lisp_Object frame, Lisp_Object miniframe)
1424 if (NILP (frame))
1425 frame = selected_frame;
1426 CHECK_LIVE_FRAME (frame);
1427 return prev_frame (frame, miniframe);
1430 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1431 Slast_nonminibuf_frame, 0, 0, 0,
1432 doc: /* Return last non-minibuffer frame selected. */)
1433 (void)
1435 Lisp_Object frame = Qnil;
1437 if (last_nonminibuf_frame)
1438 XSETFRAME (frame, last_nonminibuf_frame);
1440 return frame;
1443 /* Return 1 if it is ok to delete frame F;
1444 0 if all frames aside from F are invisible.
1445 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1447 static int
1448 other_visible_frames (struct frame *f)
1450 Lisp_Object frames, this;
1452 FOR_EACH_FRAME (frames, this)
1454 if (f == XFRAME (this))
1455 continue;
1457 /* Verify that we can still talk to the frame's X window,
1458 and note any recent change in visibility. */
1459 #ifdef HAVE_X_WINDOWS
1460 if (FRAME_WINDOW_P (XFRAME (this)))
1461 x_sync (XFRAME (this));
1462 #endif
1464 if (FRAME_VISIBLE_P (XFRAME (this))
1465 || FRAME_ICONIFIED_P (XFRAME (this))
1466 /* Allow deleting the terminal frame when at least one X
1467 frame exists. */
1468 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1469 return 1;
1471 return 0;
1474 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1475 window. Preferably use the selected frame's minibuffer window
1476 instead. If the selected frame doesn't have one, get some other
1477 frame's minibuffer window. SELECT non-zero means select the new
1478 minibuffer window. */
1479 static void
1480 check_minibuf_window (Lisp_Object frame, int select)
1482 struct frame *f = decode_live_frame (frame);
1484 XSETFRAME (frame, f);
1486 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1488 Lisp_Object frames, this, window = make_number (0);
1490 if (!EQ (frame, selected_frame)
1491 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1492 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1493 else
1494 FOR_EACH_FRAME (frames, this)
1496 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1498 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1499 break;
1503 /* Don't abort if no window was found (Bug#15247). */
1504 if (WINDOWP (window))
1506 /* Use set_window_buffer instead of Fset_window_buffer (see
1507 discussion of bug#11984, bug#12025, bug#12026). */
1508 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1509 minibuf_window = window;
1511 /* SELECT non-zero usually means that FRAME's minibuffer
1512 window was selected; select the new one. */
1513 if (select)
1514 Fselect_window (minibuf_window, Qnil);
1520 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1521 unconditionally. x_connection_closed and delete_terminal use
1522 this. Any other value of FORCE implements the semantics
1523 described for Fdelete_frame. */
1524 Lisp_Object
1525 delete_frame (Lisp_Object frame, Lisp_Object force)
1527 struct frame *f = decode_any_frame (frame);
1528 struct frame *sf;
1529 struct kboard *kb;
1531 int minibuffer_selected, is_tooltip_frame;
1533 if (! FRAME_LIVE_P (f))
1534 return Qnil;
1536 if (NILP (force) && !other_visible_frames (f))
1537 error ("Attempt to delete the sole visible or iconified frame");
1539 /* x_connection_closed must have set FORCE to `noelisp' in order
1540 to delete the last frame, if it is gone. */
1541 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1542 error ("Attempt to delete the only frame");
1544 XSETFRAME (frame, f);
1546 /* Does this frame have a minibuffer, and is it the surrogate
1547 minibuffer for any other frame? */
1548 if (FRAME_HAS_MINIBUF_P (f))
1550 Lisp_Object frames, this;
1552 FOR_EACH_FRAME (frames, this)
1554 Lisp_Object fminiw;
1556 if (EQ (this, frame))
1557 continue;
1559 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1561 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1563 /* If we MUST delete this frame, delete the other first.
1564 But do this only if FORCE equals `noelisp'. */
1565 if (EQ (force, Qnoelisp))
1566 delete_frame (this, Qnoelisp);
1567 else
1568 error ("Attempt to delete a surrogate minibuffer frame");
1573 is_tooltip_frame = !NILP (Fframe_parameter (frame, Qtooltip));
1575 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1576 frame is a tooltip. FORCE is set to `noelisp' when handling
1577 a disconnect from the terminal, so we don't dare call Lisp
1578 code. */
1579 if (NILP (Vrun_hooks) || is_tooltip_frame)
1581 else if (EQ (force, Qnoelisp))
1582 pending_funcalls
1583 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1584 pending_funcalls);
1585 else
1587 #ifdef HAVE_X_WINDOWS
1588 /* Also, save clipboard to the clipboard manager. */
1589 x_clipboard_manager_save_frame (frame);
1590 #endif
1592 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1595 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1596 if (! FRAME_LIVE_P (f))
1597 return Qnil;
1599 /* At this point, we are committed to deleting the frame.
1600 There is no more chance for errors to prevent it. */
1602 minibuffer_selected = EQ (minibuf_window, selected_window);
1603 sf = SELECTED_FRAME ();
1604 /* Don't let the frame remain selected. */
1605 if (f == sf)
1607 Lisp_Object tail;
1608 Lisp_Object frame1 = Qnil;
1610 /* Look for another visible frame on the same terminal.
1611 Do not call next_frame here because it may loop forever.
1612 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1613 FOR_EACH_FRAME (tail, frame1)
1614 if (!EQ (frame, frame1)
1615 && (FRAME_TERMINAL (XFRAME (frame))
1616 == FRAME_TERMINAL (XFRAME (frame1)))
1617 && FRAME_VISIBLE_P (XFRAME (frame1)))
1618 break;
1620 /* If there is none, find *some* other frame. */
1621 if (NILP (frame1) || EQ (frame1, frame))
1623 FOR_EACH_FRAME (tail, frame1)
1625 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1627 /* Do not change a text terminal's top-frame. */
1628 struct frame *f1 = XFRAME (frame1);
1629 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1631 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1632 if (!EQ (top_frame, frame))
1633 frame1 = top_frame;
1635 break;
1639 #ifdef NS_IMPL_COCOA
1640 else
1641 /* Under NS, there is no system mechanism for choosing a new
1642 window to get focus -- it is left to application code.
1643 So the portion of THIS application interfacing with NS
1644 needs to know about it. We call Fraise_frame, but the
1645 purpose is really to transfer focus. */
1646 Fraise_frame (frame1);
1647 #endif
1649 do_switch_frame (frame1, 0, 1, Qnil);
1650 sf = SELECTED_FRAME ();
1653 /* Don't allow minibuf_window to remain on a deleted frame. */
1654 check_minibuf_window (frame, minibuffer_selected);
1656 /* Don't let echo_area_window to remain on a deleted frame. */
1657 if (EQ (f->minibuffer_window, echo_area_window))
1658 echo_area_window = sf->minibuffer_window;
1660 /* Clear any X selections for this frame. */
1661 #ifdef HAVE_X_WINDOWS
1662 if (FRAME_X_P (f))
1663 x_clear_frame_selections (f);
1664 #endif
1666 /* Free glyphs.
1667 This function must be called before the window tree of the
1668 frame is deleted because windows contain dynamically allocated
1669 memory. */
1670 free_glyphs (f);
1672 #ifdef HAVE_WINDOW_SYSTEM
1673 /* Give chance to each font driver to free a frame specific data. */
1674 font_update_drivers (f, Qnil);
1675 #endif
1677 /* Mark all the windows that used to be on FRAME as deleted, and then
1678 remove the reference to them. */
1679 delete_all_child_windows (f->root_window);
1680 fset_root_window (f, Qnil);
1682 Vframe_list = Fdelq (frame, Vframe_list);
1683 SET_FRAME_VISIBLE (f, 0);
1685 /* Allow the vector of menu bar contents to be freed in the next
1686 garbage collection. The frame object itself may not be garbage
1687 collected until much later, because recent_keys and other data
1688 structures can still refer to it. */
1689 fset_menu_bar_vector (f, Qnil);
1691 /* If FRAME's buffer lists contains killed
1692 buffers, this helps GC to reclaim them. */
1693 fset_buffer_list (f, Qnil);
1694 fset_buried_buffer_list (f, Qnil);
1696 free_font_driver_list (f);
1697 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1698 xfree (f->namebuf);
1699 #endif
1700 xfree (f->decode_mode_spec_buffer);
1701 xfree (FRAME_INSERT_COST (f));
1702 xfree (FRAME_DELETEN_COST (f));
1703 xfree (FRAME_INSERTN_COST (f));
1704 xfree (FRAME_DELETE_COST (f));
1706 /* Since some events are handled at the interrupt level, we may get
1707 an event for f at any time; if we zero out the frame's terminal
1708 now, then we may trip up the event-handling code. Instead, we'll
1709 promise that the terminal of the frame must be valid until we
1710 have called the window-system-dependent frame destruction
1711 routine. */
1715 struct terminal *terminal;
1716 block_input ();
1717 if (FRAME_TERMINAL (f)->delete_frame_hook)
1718 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1719 terminal = FRAME_TERMINAL (f);
1720 f->output_data.nothing = 0;
1721 f->terminal = 0; /* Now the frame is dead. */
1722 unblock_input ();
1724 /* If needed, delete the terminal that this frame was on.
1725 (This must be done after the frame is killed.) */
1726 terminal->reference_count--;
1727 #ifdef USE_GTK
1728 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1729 bug.
1730 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1731 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1732 terminal->reference_count = 1;
1733 #endif /* USE_GTK */
1734 if (terminal->reference_count == 0)
1736 Lisp_Object tmp;
1737 XSETTERMINAL (tmp, terminal);
1739 kb = NULL;
1740 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1742 else
1743 kb = terminal->kboard;
1746 /* If we've deleted the last_nonminibuf_frame, then try to find
1747 another one. */
1748 if (f == last_nonminibuf_frame)
1750 Lisp_Object frames, this;
1752 last_nonminibuf_frame = 0;
1754 FOR_EACH_FRAME (frames, this)
1756 f = XFRAME (this);
1757 if (!FRAME_MINIBUF_ONLY_P (f))
1759 last_nonminibuf_frame = f;
1760 break;
1765 /* If there's no other frame on the same kboard, get out of
1766 single-kboard state if we're in it for this kboard. */
1767 if (kb != NULL)
1769 Lisp_Object frames, this;
1770 /* Some frame we found on the same kboard, or nil if there are none. */
1771 Lisp_Object frame_on_same_kboard = Qnil;
1773 FOR_EACH_FRAME (frames, this)
1774 if (kb == FRAME_KBOARD (XFRAME (this)))
1775 frame_on_same_kboard = this;
1777 if (NILP (frame_on_same_kboard))
1778 not_single_kboard_state (kb);
1782 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1783 find another one. Prefer minibuffer-only frames, but also notice
1784 frames with other windows. */
1785 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1787 Lisp_Object frames, this;
1789 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1790 Lisp_Object frame_with_minibuf = Qnil;
1791 /* Some frame we found on the same kboard, or nil if there are none. */
1792 Lisp_Object frame_on_same_kboard = Qnil;
1794 FOR_EACH_FRAME (frames, this)
1796 struct frame *f1 = XFRAME (this);
1798 /* Consider only frames on the same kboard
1799 and only those with minibuffers. */
1800 if (kb == FRAME_KBOARD (f1)
1801 && FRAME_HAS_MINIBUF_P (f1))
1803 frame_with_minibuf = this;
1804 if (FRAME_MINIBUF_ONLY_P (f1))
1805 break;
1808 if (kb == FRAME_KBOARD (f1))
1809 frame_on_same_kboard = this;
1812 if (!NILP (frame_on_same_kboard))
1814 /* We know that there must be some frame with a minibuffer out
1815 there. If this were not true, all of the frames present
1816 would have to be minibufferless, which implies that at some
1817 point their minibuffer frames must have been deleted, but
1818 that is prohibited at the top; you can't delete surrogate
1819 minibuffer frames. */
1820 if (NILP (frame_with_minibuf))
1821 emacs_abort ();
1823 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1825 else
1826 /* No frames left on this kboard--say no minibuffer either. */
1827 kset_default_minibuffer_frame (kb, Qnil);
1830 /* Cause frame titles to update--necessary if we now have just one frame. */
1831 if (!is_tooltip_frame)
1832 update_mode_lines = 15;
1834 return Qnil;
1837 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1838 doc: /* Delete FRAME, permanently eliminating it from use.
1839 FRAME must be a live frame and defaults to the selected one.
1841 A frame may not be deleted if its minibuffer serves as surrogate
1842 minibuffer for another frame. Normally, you may not delete a frame if
1843 all other frames are invisible, but if the second optional argument
1844 FORCE is non-nil, you may do so.
1846 This function runs `delete-frame-functions' before actually
1847 deleting the frame, unless the frame is a tooltip.
1848 The functions are run with one argument, the frame to be deleted. */)
1849 (Lisp_Object frame, Lisp_Object force)
1851 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1855 /* Return mouse position in character cell units. */
1857 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1858 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1859 The position is given in canonical character cells, where (0, 0) is the
1860 upper-left corner of the frame, X is the horizontal offset, and Y is the
1861 vertical offset, measured in units of the frame's default character size.
1862 If Emacs is running on a mouseless terminal or hasn't been programmed
1863 to read the mouse position, it returns the selected frame for FRAME
1864 and nil for X and Y.
1865 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1866 passing the normal return value to that function as an argument,
1867 and returns whatever that function returns. */)
1868 (void)
1870 struct frame *f;
1871 Lisp_Object lispy_dummy;
1872 Lisp_Object x, y, retval;
1874 f = SELECTED_FRAME ();
1875 x = y = Qnil;
1877 /* It's okay for the hook to refrain from storing anything. */
1878 if (FRAME_TERMINAL (f)->mouse_position_hook)
1880 enum scroll_bar_part party_dummy;
1881 Time time_dummy;
1882 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1883 &lispy_dummy, &party_dummy,
1884 &x, &y,
1885 &time_dummy);
1888 if (! NILP (x))
1890 int col = XINT (x);
1891 int row = XINT (y);
1892 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1893 XSETINT (x, col);
1894 XSETINT (y, row);
1896 XSETFRAME (lispy_dummy, f);
1897 retval = Fcons (lispy_dummy, Fcons (x, y));
1898 if (!NILP (Vmouse_position_function))
1899 retval = call1 (Vmouse_position_function, retval);
1900 return retval;
1903 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1904 Smouse_pixel_position, 0, 0, 0,
1905 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1906 The position is given in pixel units, where (0, 0) is the
1907 upper-left corner of the frame, X is the horizontal offset, and Y is
1908 the vertical offset.
1909 If Emacs is running on a mouseless terminal or hasn't been programmed
1910 to read the mouse position, it returns the selected frame for FRAME
1911 and nil for X and Y. */)
1912 (void)
1914 struct frame *f;
1915 Lisp_Object lispy_dummy;
1916 Lisp_Object x, y, retval;
1918 f = SELECTED_FRAME ();
1919 x = y = Qnil;
1921 /* It's okay for the hook to refrain from storing anything. */
1922 if (FRAME_TERMINAL (f)->mouse_position_hook)
1924 enum scroll_bar_part party_dummy;
1925 Time time_dummy;
1926 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1927 &lispy_dummy, &party_dummy,
1928 &x, &y,
1929 &time_dummy);
1932 XSETFRAME (lispy_dummy, f);
1933 retval = Fcons (lispy_dummy, Fcons (x, y));
1934 if (!NILP (Vmouse_position_function))
1935 retval = call1 (Vmouse_position_function, retval);
1936 return retval;
1939 #ifdef HAVE_WINDOW_SYSTEM
1941 /* On frame F, convert character coordinates X and Y to pixel
1942 coordinates *PIX_X and *PIX_Y. */
1944 static void
1945 frame_char_to_pixel_position (struct frame *f, int x, int y,
1946 int *pix_x, int *pix_y)
1948 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
1949 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
1951 if (*pix_x < 0)
1952 *pix_x = 0;
1953 if (*pix_x > FRAME_PIXEL_WIDTH (f))
1954 *pix_x = FRAME_PIXEL_WIDTH (f);
1956 if (*pix_y < 0)
1957 *pix_y = 0;
1958 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
1959 *pix_y = FRAME_PIXEL_HEIGHT (f);
1962 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1964 static void
1965 frame_set_mouse_position (struct frame *f, int x, int y)
1967 int pix_x, pix_y;
1969 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
1970 frame_set_mouse_pixel_position (f, pix_x, pix_y);
1973 #endif /* HAVE_WINDOW_SYSTEM */
1975 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1976 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1977 Coordinates are relative to the frame, not a window,
1978 so the coordinates of the top left character in the frame
1979 may be nonzero due to left-hand scroll bars or the menu bar.
1981 The position is given in canonical character cells, where (0, 0) is
1982 the upper-left corner of the frame, X is the horizontal offset, and
1983 Y is the vertical offset, measured in units of the frame's default
1984 character size.
1986 This function is a no-op for an X frame that is not visible.
1987 If you have just created a frame, you must wait for it to become visible
1988 before calling this function on it, like this.
1989 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1990 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1992 CHECK_LIVE_FRAME (frame);
1993 CHECK_TYPE_RANGED_INTEGER (int, x);
1994 CHECK_TYPE_RANGED_INTEGER (int, y);
1996 /* I think this should be done with a hook. */
1997 #ifdef HAVE_WINDOW_SYSTEM
1998 if (FRAME_WINDOW_P (XFRAME (frame)))
1999 /* Warping the mouse will cause enternotify and focus events. */
2000 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
2001 #else
2002 #if defined (MSDOS)
2003 if (FRAME_MSDOS_P (XFRAME (frame)))
2005 Fselect_frame (frame, Qnil);
2006 mouse_moveto (XINT (x), XINT (y));
2008 #else
2009 #ifdef HAVE_GPM
2011 Fselect_frame (frame, Qnil);
2012 term_mouse_moveto (XINT (x), XINT (y));
2014 #endif
2015 #endif
2016 #endif
2018 return Qnil;
2021 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
2022 Sset_mouse_pixel_position, 3, 3, 0,
2023 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
2024 The position is given in pixels, where (0, 0) is the upper-left corner
2025 of the frame, X is the horizontal offset, and Y is the vertical offset.
2027 Note, this is a no-op for an X frame that is not visible.
2028 If you have just created a frame, you must wait for it to become visible
2029 before calling this function on it, like this.
2030 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2031 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2033 CHECK_LIVE_FRAME (frame);
2034 CHECK_TYPE_RANGED_INTEGER (int, x);
2035 CHECK_TYPE_RANGED_INTEGER (int, y);
2037 /* I think this should be done with a hook. */
2038 #ifdef HAVE_WINDOW_SYSTEM
2039 if (FRAME_WINDOW_P (XFRAME (frame)))
2040 /* Warping the mouse will cause enternotify and focus events. */
2041 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
2042 #else
2043 #if defined (MSDOS)
2044 if (FRAME_MSDOS_P (XFRAME (frame)))
2046 Fselect_frame (frame, Qnil);
2047 mouse_moveto (XINT (x), XINT (y));
2049 #else
2050 #ifdef HAVE_GPM
2052 Fselect_frame (frame, Qnil);
2053 term_mouse_moveto (XINT (x), XINT (y));
2055 #endif
2056 #endif
2057 #endif
2059 return Qnil;
2062 static void make_frame_visible_1 (Lisp_Object);
2064 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2065 0, 1, "",
2066 doc: /* Make the frame FRAME visible (assuming it is an X window).
2067 If omitted, FRAME defaults to the currently selected frame. */)
2068 (Lisp_Object frame)
2070 struct frame *f = decode_live_frame (frame);
2072 /* I think this should be done with a hook. */
2073 #ifdef HAVE_WINDOW_SYSTEM
2074 if (FRAME_WINDOW_P (f))
2075 x_make_frame_visible (f);
2076 #endif
2078 make_frame_visible_1 (f->root_window);
2080 /* Make menu bar update for the Buffers and Frames menus. */
2081 /* windows_or_buffers_changed = 15; FIXME: Why? */
2083 XSETFRAME (frame, f);
2084 return frame;
2087 /* Update the display_time slot of the buffers shown in WINDOW
2088 and all its descendants. */
2090 static void
2091 make_frame_visible_1 (Lisp_Object window)
2093 struct window *w;
2095 for (; !NILP (window); window = w->next)
2097 w = XWINDOW (window);
2098 if (WINDOWP (w->contents))
2099 make_frame_visible_1 (w->contents);
2100 else
2101 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2105 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2106 0, 2, "",
2107 doc: /* Make the frame FRAME invisible.
2108 If omitted, FRAME defaults to the currently selected frame.
2109 On graphical displays, invisible frames are not updated and are
2110 usually not displayed at all, even in a window system's \"taskbar\".
2112 Normally you may not make FRAME invisible if all other frames are invisible,
2113 but if the second optional argument FORCE is non-nil, you may do so.
2115 This function has no effect on text terminal frames. Such frames are
2116 always considered visible, whether or not they are currently being
2117 displayed in the terminal. */)
2118 (Lisp_Object frame, Lisp_Object force)
2120 struct frame *f = decode_live_frame (frame);
2122 if (NILP (force) && !other_visible_frames (f))
2123 error ("Attempt to make invisible the sole visible or iconified frame");
2125 /* Don't allow minibuf_window to remain on an invisible frame. */
2126 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2128 /* I think this should be done with a hook. */
2129 #ifdef HAVE_WINDOW_SYSTEM
2130 if (FRAME_WINDOW_P (f))
2131 x_make_frame_invisible (f);
2132 #endif
2134 /* Make menu bar update for the Buffers and Frames menus. */
2135 windows_or_buffers_changed = 16;
2137 return Qnil;
2140 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2141 0, 1, "",
2142 doc: /* Make the frame FRAME into an icon.
2143 If omitted, FRAME defaults to the currently selected frame. */)
2144 (Lisp_Object frame)
2146 struct frame *f = decode_live_frame (frame);
2148 /* Don't allow minibuf_window to remain on an iconified frame. */
2149 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2151 /* I think this should be done with a hook. */
2152 if (FRAME_WINDOW_P (f))
2154 #ifdef HAVE_WINDOW_SYSTEM
2155 x_iconify_frame (f);
2156 #endif
2159 /* Make menu bar update for the Buffers and Frames menus. */
2160 windows_or_buffers_changed = 17;
2162 return Qnil;
2165 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2166 1, 1, 0,
2167 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2168 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2169 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2170 On graphical displays, invisible frames are not updated and are
2171 usually not displayed at all, even in a window system's \"taskbar\".
2173 If FRAME is a text terminal frame, this always returns t.
2174 Such frames are always considered visible, whether or not they are
2175 currently being displayed on the terminal. */)
2176 (Lisp_Object frame)
2178 CHECK_LIVE_FRAME (frame);
2180 if (FRAME_VISIBLE_P (XFRAME (frame)))
2181 return Qt;
2182 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2183 return Qicon;
2184 return Qnil;
2187 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2188 0, 0, 0,
2189 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2190 (void)
2192 Lisp_Object tail, frame, value = Qnil;
2194 FOR_EACH_FRAME (tail, frame)
2195 if (FRAME_VISIBLE_P (XFRAME (frame)))
2196 value = Fcons (frame, value);
2198 return value;
2202 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2203 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2204 If FRAME is invisible or iconified, make it visible.
2205 If you don't specify a frame, the selected frame is used.
2206 If Emacs is displaying on an ordinary terminal or some other device which
2207 doesn't support multiple overlapping frames, this function selects FRAME. */)
2208 (Lisp_Object frame)
2210 struct frame *f = decode_live_frame (frame);
2212 XSETFRAME (frame, f);
2214 if (FRAME_TERMCAP_P (f))
2215 /* On a text terminal select FRAME. */
2216 Fselect_frame (frame, Qnil);
2217 else
2218 /* Do like the documentation says. */
2219 Fmake_frame_visible (frame);
2221 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2222 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2224 return Qnil;
2227 /* Should we have a corresponding function called Flower_Power? */
2228 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2229 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2230 If you don't specify a frame, the selected frame is used.
2231 If Emacs is displaying on an ordinary terminal or some other device which
2232 doesn't support multiple overlapping frames, this function does nothing. */)
2233 (Lisp_Object frame)
2235 struct frame *f = decode_live_frame (frame);
2237 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2238 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2240 return Qnil;
2244 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2245 1, 2, 0,
2246 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2247 In other words, switch-frame events caused by events in FRAME will
2248 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2249 FOCUS-FRAME after reading an event typed at FRAME.
2251 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2252 frame again receives its own keystrokes.
2254 Focus redirection is useful for temporarily redirecting keystrokes to
2255 a surrogate minibuffer frame when a frame doesn't have its own
2256 minibuffer window.
2258 A frame's focus redirection can be changed by `select-frame'. If frame
2259 FOO is selected, and then a different frame BAR is selected, any
2260 frames redirecting their focus to FOO are shifted to redirect their
2261 focus to BAR. This allows focus redirection to work properly when the
2262 user switches from one frame to another using `select-window'.
2264 This means that a frame whose focus is redirected to itself is treated
2265 differently from a frame whose focus is redirected to nil; the former
2266 is affected by `select-frame', while the latter is not.
2268 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2269 (Lisp_Object frame, Lisp_Object focus_frame)
2271 /* Note that we don't check for a live frame here. It's reasonable
2272 to redirect the focus of a frame you're about to delete, if you
2273 know what other frame should receive those keystrokes. */
2274 struct frame *f = decode_any_frame (frame);
2276 if (! NILP (focus_frame))
2277 CHECK_LIVE_FRAME (focus_frame);
2279 fset_focus_frame (f, focus_frame);
2281 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2282 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2284 return Qnil;
2288 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2289 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2290 If FRAME is omitted or nil, the selected frame is used.
2291 Return nil if FRAME's focus is not redirected.
2292 See `redirect-frame-focus'. */)
2293 (Lisp_Object frame)
2295 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2298 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2299 doc: /* Set the input focus to FRAME.
2300 FRAME nil means use the selected frame.
2301 If there is no window system support, this function does nothing. */)
2302 (Lisp_Object frame)
2304 #ifdef HAVE_WINDOW_SYSTEM
2305 x_focus_frame (decode_window_system_frame (frame));
2306 #endif
2307 return Qnil;
2310 DEFUN ("frame-after-make-frame",
2311 Fframe_after_make_frame,
2312 Sframe_after_make_frame, 2, 2, 0,
2313 doc: /* Mark FRAME as made.
2314 FRAME nil means use the selected frame. Second argument MADE non-nil
2315 means functions on `window-configuration-change-hook' are called
2316 whenever the window configuration of FRAME changes. MADE nil means
2317 these functions are not called.
2319 This function is currently called by `make-frame' only and should be
2320 otherwise used with utter care to avoid that running functions on
2321 `window-configuration-change-hook' is impeded forever. */)
2322 (Lisp_Object frame, Lisp_Object made)
2324 struct frame *f = decode_live_frame (frame);
2325 f->after_make_frame = !NILP (made);
2326 f->inhibit_horizontal_resize = false;
2327 f->inhibit_vertical_resize = false;
2328 return made;
2332 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2334 void
2335 frames_discard_buffer (Lisp_Object buffer)
2337 Lisp_Object frame, tail;
2339 FOR_EACH_FRAME (tail, frame)
2341 fset_buffer_list
2342 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2343 fset_buried_buffer_list
2344 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2348 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2349 If the alist already has an element for PROP, we change it. */
2351 void
2352 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2354 register Lisp_Object tem;
2356 tem = Fassq (prop, *alistptr);
2357 if (EQ (tem, Qnil))
2358 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2359 else
2360 Fsetcdr (tem, val);
2363 static int
2364 frame_name_fnn_p (char *str, ptrdiff_t len)
2366 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2368 char *p = str + 2;
2369 while ('0' <= *p && *p <= '9')
2370 p++;
2371 if (p == str + len)
2372 return 1;
2374 return 0;
2377 /* Set the name of the terminal frame. Also used by MSDOS frames.
2378 Modeled after x_set_name which is used for WINDOW frames. */
2380 static void
2381 set_term_frame_name (struct frame *f, Lisp_Object name)
2383 f->explicit_name = ! NILP (name);
2385 /* If NAME is nil, set the name to F<num>. */
2386 if (NILP (name))
2388 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2390 /* Check for no change needed in this very common case
2391 before we do any consing. */
2392 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2393 return;
2395 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2397 else
2399 CHECK_STRING (name);
2401 /* Don't change the name if it's already NAME. */
2402 if (! NILP (Fstring_equal (name, f->name)))
2403 return;
2405 /* Don't allow the user to set the frame name to F<num>, so it
2406 doesn't clash with the names we generate for terminal frames. */
2407 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2408 error ("Frame names of the form F<num> are usurped by Emacs");
2411 fset_name (f, name);
2412 update_mode_lines = 16;
2415 void
2416 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2418 register Lisp_Object old_alist_elt;
2420 if (EQ (prop, Qminibuffer))
2422 if (WINDOWP (val))
2424 if (!MINI_WINDOW_P (XWINDOW (val)))
2425 error ("The `minibuffer' parameter does not specify a valid minibuffer window");
2426 else if (FRAME_MINIBUF_ONLY_P (f))
2428 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2429 val = Qonly;
2430 else
2431 error ("Can't change the minibuffer window of a minibuffer-only frame");
2433 else if (FRAME_HAS_MINIBUF_P (f))
2435 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2436 val = Qt;
2437 else
2438 error ("Can't change the minibuffer window of a frame with its own minibuffer");
2440 else
2441 /* Store the chosen minibuffer window. */
2442 fset_minibuffer_window (f, val);
2444 else
2446 Lisp_Object old_val = Fcdr (Fassq (Qminibuffer, f->param_alist));
2448 if (!NILP (old_val))
2450 if (WINDOWP (old_val) && NILP (val))
2451 /* Don't change the value for a minibuffer-less frame if
2452 only nil was specified as new value. */
2453 val = old_val;
2454 else if (!EQ (old_val, val))
2455 error ("Can't change the `minibuffer' parameter of this frame");
2460 /* The buffer-list parameters are stored in a special place and not
2461 in the alist. All buffers must be live. */
2462 if (EQ (prop, Qbuffer_list))
2464 Lisp_Object list = Qnil;
2465 for (; CONSP (val); val = XCDR (val))
2466 if (!NILP (Fbuffer_live_p (XCAR (val))))
2467 list = Fcons (XCAR (val), list);
2468 fset_buffer_list (f, Fnreverse (list));
2469 return;
2471 if (EQ (prop, Qburied_buffer_list))
2473 Lisp_Object list = Qnil;
2474 for (; CONSP (val); val = XCDR (val))
2475 if (!NILP (Fbuffer_live_p (XCAR (val))))
2476 list = Fcons (XCAR (val), list);
2477 fset_buried_buffer_list (f, Fnreverse (list));
2478 return;
2481 /* The tty color needed to be set before the frame's parameter
2482 alist was updated with the new value. This is not true any more,
2483 but we still do this test early on. */
2484 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2485 && f == FRAME_TTY (f)->previous_frame)
2486 /* Force redisplay of this tty. */
2487 FRAME_TTY (f)->previous_frame = NULL;
2489 /* Update the frame parameter alist. */
2490 old_alist_elt = Fassq (prop, f->param_alist);
2491 if (EQ (old_alist_elt, Qnil))
2492 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2493 else
2494 Fsetcdr (old_alist_elt, val);
2496 /* Update some other special parameters in their special places
2497 in addition to the alist. */
2499 if (EQ (prop, Qbuffer_predicate))
2500 fset_buffer_predicate (f, val);
2502 if (! FRAME_WINDOW_P (f))
2504 if (EQ (prop, Qmenu_bar_lines))
2505 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2506 else if (EQ (prop, Qname))
2507 set_term_frame_name (f, val);
2511 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2512 is not an unspecified foreground or background color. */
2514 static Lisp_Object
2515 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2517 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2518 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2519 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2520 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2523 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2524 doc: /* Return the parameters-alist of frame FRAME.
2525 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2526 The meaningful PARMs depend on the kind of frame.
2527 If FRAME is omitted or nil, return information on the currently selected frame. */)
2528 (Lisp_Object frame)
2530 Lisp_Object alist;
2531 struct frame *f = decode_any_frame (frame);
2532 int height, width;
2534 if (!FRAME_LIVE_P (f))
2535 return Qnil;
2537 alist = Fcopy_alist (f->param_alist);
2539 if (!FRAME_WINDOW_P (f))
2541 Lisp_Object elt;
2543 /* If the frame's parameter alist says the colors are
2544 unspecified and reversed, take the frame's background pixel
2545 for foreground and vice versa. */
2546 elt = Fassq (Qforeground_color, alist);
2547 if (CONSP (elt) && STRINGP (XCDR (elt)))
2549 elt = frame_unspecified_color (f, XCDR (elt));
2550 if (!NILP (elt))
2551 store_in_alist (&alist, Qforeground_color, elt);
2553 else
2554 store_in_alist (&alist, Qforeground_color,
2555 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2556 elt = Fassq (Qbackground_color, alist);
2557 if (CONSP (elt) && STRINGP (XCDR (elt)))
2559 elt = frame_unspecified_color (f, XCDR (elt));
2560 if (!NILP (elt))
2561 store_in_alist (&alist, Qbackground_color, elt);
2563 else
2564 store_in_alist (&alist, Qbackground_color,
2565 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2566 store_in_alist (&alist, Qfont,
2567 build_string (FRAME_MSDOS_P (f)
2568 ? "ms-dos"
2569 : FRAME_W32_P (f) ? "w32term"
2570 :"tty"));
2572 store_in_alist (&alist, Qname, f->name);
2573 height = (f->new_height
2574 ? (f->new_pixelwise
2575 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2576 : f->new_height)
2577 : FRAME_LINES (f));
2578 store_in_alist (&alist, Qheight, make_number (height));
2579 width = (f->new_width
2580 ? (f->new_pixelwise
2581 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2582 : f->new_width)
2583 : FRAME_COLS (f));
2584 store_in_alist (&alist, Qwidth, make_number (width));
2585 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2586 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2587 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2588 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2590 /* I think this should be done with a hook. */
2591 #ifdef HAVE_WINDOW_SYSTEM
2592 if (FRAME_WINDOW_P (f))
2593 x_report_frame_params (f, &alist);
2594 else
2595 #endif
2597 /* This ought to be correct in f->param_alist for an X frame. */
2598 Lisp_Object lines;
2599 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2600 store_in_alist (&alist, Qmenu_bar_lines, lines);
2603 return alist;
2607 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2608 doc: /* Return FRAME's value for parameter PARAMETER.
2609 If FRAME is nil, describe the currently selected frame. */)
2610 (Lisp_Object frame, Lisp_Object parameter)
2612 struct frame *f = decode_any_frame (frame);
2613 Lisp_Object value = Qnil;
2615 CHECK_SYMBOL (parameter);
2617 XSETFRAME (frame, f);
2619 if (FRAME_LIVE_P (f))
2621 /* Avoid consing in frequent cases. */
2622 if (EQ (parameter, Qname))
2623 value = f->name;
2624 #ifdef HAVE_WINDOW_SYSTEM
2625 /* These are used by vertical motion commands. */
2626 else if (EQ (parameter, Qvertical_scroll_bars))
2627 value = (f->vertical_scroll_bar_type == vertical_scroll_bar_none
2628 ? Qnil
2629 : (f->vertical_scroll_bar_type == vertical_scroll_bar_left
2630 ? Qleft : Qright));
2631 else if (EQ (parameter, Qhorizontal_scroll_bars))
2632 value = f->horizontal_scroll_bars ? Qt : Qnil;
2633 else if (EQ (parameter, Qline_spacing) && f->extra_line_spacing == 0)
2634 /* If this is non-zero, we can't determine whether the user specified
2635 an integer or float value without looking through 'param_alist'. */
2636 value = make_number (0);
2637 else if (EQ (parameter, Qfont) && FRAME_X_P (f))
2638 value = FRAME_FONT (f)->props[FONT_NAME_INDEX];
2639 #endif /* HAVE_WINDOW_SYSTEM */
2640 #ifdef HAVE_X_WINDOWS
2641 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2642 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2643 #endif /* HAVE_X_WINDOWS */
2644 else if (EQ (parameter, Qbackground_color)
2645 || EQ (parameter, Qforeground_color))
2647 value = Fassq (parameter, f->param_alist);
2648 if (CONSP (value))
2650 value = XCDR (value);
2651 /* Fframe_parameters puts the actual fg/bg color names,
2652 even if f->param_alist says otherwise. This is
2653 important when param_alist's notion of colors is
2654 "unspecified". We need to do the same here. */
2655 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2657 Lisp_Object tem = frame_unspecified_color (f, value);
2659 if (!NILP (tem))
2660 value = tem;
2663 else
2664 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2666 else if (EQ (parameter, Qdisplay_type)
2667 || EQ (parameter, Qbackground_mode))
2668 value = Fcdr (Fassq (parameter, f->param_alist));
2669 else
2670 /* FIXME: Avoid this code path at all (as well as code duplication)
2671 by sharing more code with Fframe_parameters. */
2672 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2675 return value;
2679 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2680 Smodify_frame_parameters, 2, 2, 0,
2681 doc: /* Modify FRAME according to new values of its parameters in ALIST.
2682 If FRAME is nil, it defaults to the selected frame.
2683 ALIST is an alist of parameters to change and their new values.
2684 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2685 Which PARMs are meaningful depends on the kind of frame.
2686 The meaningful parameters are acted upon, i.e. the frame is changed
2687 according to their new values, and are also stored in the frame's
2688 parameter list so that `frame-parameters' will return them.
2689 PARMs that are not meaningful are still stored in the frame's parameter
2690 list, but are otherwise ignored. */)
2691 (Lisp_Object frame, Lisp_Object alist)
2693 struct frame *f = decode_live_frame (frame);
2694 Lisp_Object prop, val;
2696 /* I think this should be done with a hook. */
2697 #ifdef HAVE_WINDOW_SYSTEM
2698 if (FRAME_WINDOW_P (f))
2699 x_set_frame_parameters (f, alist);
2700 else
2701 #endif
2702 #ifdef MSDOS
2703 if (FRAME_MSDOS_P (f))
2704 IT_set_frame_parameters (f, alist);
2705 else
2706 #endif
2709 EMACS_INT length = XFASTINT (Flength (alist));
2710 ptrdiff_t i;
2711 Lisp_Object *parms;
2712 Lisp_Object *values;
2713 USE_SAFE_ALLOCA;
2714 SAFE_ALLOCA_LISP (parms, 2 * length);
2715 values = parms + length;
2717 /* Extract parm names and values into those vectors. */
2719 for (i = 0; CONSP (alist); alist = XCDR (alist))
2721 Lisp_Object elt;
2723 elt = XCAR (alist);
2724 parms[i] = Fcar (elt);
2725 values[i] = Fcdr (elt);
2726 i++;
2729 /* Now process them in reverse of specified order. */
2730 while (--i >= 0)
2732 prop = parms[i];
2733 val = values[i];
2734 store_frame_param (f, prop, val);
2736 if (EQ (prop, Qforeground_color)
2737 || EQ (prop, Qbackground_color))
2738 update_face_from_frame_parameter (f, prop, val);
2741 SAFE_FREE ();
2743 return Qnil;
2746 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2747 0, 1, 0,
2748 doc: /* Height in pixels of a line in the font in frame FRAME.
2749 If FRAME is omitted or nil, the selected frame is used.
2750 For a terminal frame, the value is always 1. */)
2751 (Lisp_Object frame)
2753 #ifdef HAVE_WINDOW_SYSTEM
2754 struct frame *f = decode_any_frame (frame);
2756 if (FRAME_WINDOW_P (f))
2757 return make_number (FRAME_LINE_HEIGHT (f));
2758 else
2759 #endif
2760 return make_number (1);
2764 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2765 0, 1, 0,
2766 doc: /* Width in pixels of characters in the font in frame FRAME.
2767 If FRAME is omitted or nil, the selected frame is used.
2768 On a graphical screen, the width is the standard width of the default font.
2769 For a terminal screen, the value is always 1. */)
2770 (Lisp_Object frame)
2772 #ifdef HAVE_WINDOW_SYSTEM
2773 struct frame *f = decode_any_frame (frame);
2775 if (FRAME_WINDOW_P (f))
2776 return make_number (FRAME_COLUMN_WIDTH (f));
2777 else
2778 #endif
2779 return make_number (1);
2782 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2783 Sframe_pixel_height, 0, 1, 0,
2784 doc: /* Return a FRAME's height in pixels.
2785 If FRAME is omitted or nil, the selected frame is used. The exact value
2786 of the result depends on the window-system and toolkit in use:
2788 In the Gtk+ version of Emacs, it includes only any window (including
2789 the minibuffer or echo area), mode line, and header line. It does not
2790 include the tool bar or menu bar.
2792 With other graphical versions, it also includes the tool bar and the
2793 menu bar.
2795 For a text terminal, it includes the menu bar. In this case, the
2796 result is really in characters rather than pixels (i.e., is identical
2797 to `frame-height'). */)
2798 (Lisp_Object frame)
2800 struct frame *f = decode_any_frame (frame);
2802 #ifdef HAVE_WINDOW_SYSTEM
2803 if (FRAME_WINDOW_P (f))
2804 return make_number (FRAME_PIXEL_HEIGHT (f));
2805 else
2806 #endif
2807 return make_number (FRAME_TOTAL_LINES (f));
2810 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2811 Sframe_pixel_width, 0, 1, 0,
2812 doc: /* Return FRAME's width in pixels.
2813 For a terminal frame, the result really gives the width in characters.
2814 If FRAME is omitted or nil, the selected frame is used. */)
2815 (Lisp_Object frame)
2817 struct frame *f = decode_any_frame (frame);
2819 #ifdef HAVE_WINDOW_SYSTEM
2820 if (FRAME_WINDOW_P (f))
2821 return make_number (FRAME_PIXEL_WIDTH (f));
2822 else
2823 #endif
2824 return make_number (FRAME_TOTAL_COLS (f));
2827 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2828 Stool_bar_pixel_width, 0, 1, 0,
2829 doc: /* Return width in pixels of FRAME's tool bar.
2830 The result is greater than zero only when the tool bar is on the left
2831 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2832 is used. */)
2833 (Lisp_Object frame)
2835 #ifdef FRAME_TOOLBAR_WIDTH
2836 struct frame *f = decode_any_frame (frame);
2838 if (FRAME_WINDOW_P (f))
2839 return make_number (FRAME_TOOLBAR_WIDTH (f));
2840 #endif
2841 return make_number (0);
2844 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2845 doc: /* Return width in columns of FRAME's text area. */)
2846 (Lisp_Object frame)
2848 return make_number (FRAME_COLS (decode_any_frame (frame)));
2851 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2852 doc: /* Return height in lines of FRAME's text area. */)
2853 (Lisp_Object frame)
2855 return make_number (FRAME_LINES (decode_any_frame (frame)));
2858 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2859 doc: /* Return number of total columns of FRAME. */)
2860 (Lisp_Object frame)
2862 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2865 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2866 doc: /* Return number of total lines of FRAME. */)
2867 (Lisp_Object frame)
2869 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2872 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2873 doc: /* Return text area width of FRAME in pixels. */)
2874 (Lisp_Object frame)
2876 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2879 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2880 doc: /* Return text area height of FRAME in pixels. */)
2881 (Lisp_Object frame)
2883 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2886 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2887 doc: /* Return scroll bar width of FRAME in pixels. */)
2888 (Lisp_Object frame)
2890 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2893 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2894 doc: /* Return scroll bar height of FRAME in pixels. */)
2895 (Lisp_Object frame)
2897 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2900 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2901 doc: /* Return fringe width of FRAME in pixels. */)
2902 (Lisp_Object frame)
2904 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2907 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2908 doc: /* Return border width of FRAME in pixels. */)
2909 (Lisp_Object frame)
2911 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2914 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2915 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2916 (Lisp_Object frame)
2918 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2921 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2922 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2923 (Lisp_Object frame)
2925 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2928 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2929 doc: /* Set text height of frame FRAME to HEIGHT lines.
2930 Optional third arg PRETEND non-nil means that redisplay should use
2931 HEIGHT lines but that the idea of the actual height of the frame should
2932 not be changed.
2934 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2935 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
2936 window managers may refuse to honor a HEIGHT that is not an integer
2937 multiple of the default frame font height. */)
2938 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2940 struct frame *f = decode_live_frame (frame);
2941 int pixel_height;
2943 CHECK_TYPE_RANGED_INTEGER (int, height);
2945 pixel_height = (!NILP (pixelwise)
2946 ? XINT (height)
2947 : XINT (height) * FRAME_LINE_HEIGHT (f));
2948 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
2950 return Qnil;
2953 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2954 doc: /* Set text width of frame FRAME to WIDTH columns.
2955 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2956 columns but that the idea of the actual width of the frame should not
2957 be changed.
2959 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2960 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
2961 window managers may refuse to honor a WIDTH that is not an integer
2962 multiple of the default frame font width. */)
2963 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2965 struct frame *f = decode_live_frame (frame);
2966 int pixel_width;
2968 CHECK_TYPE_RANGED_INTEGER (int, width);
2970 pixel_width = (!NILP (pixelwise)
2971 ? XINT (width)
2972 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2973 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
2975 return Qnil;
2978 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2979 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
2980 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
2981 When `frame-resize-pixelwise' is nil, some window managers may refuse to
2982 honor a WIDTH that is not an integer multiple of the default frame font
2983 width or a HEIGHT that is not an integer multiple of the default frame
2984 font height. */)
2985 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2987 struct frame *f = decode_live_frame (frame);
2988 int pixel_width, pixel_height;
2990 CHECK_TYPE_RANGED_INTEGER (int, width);
2991 CHECK_TYPE_RANGED_INTEGER (int, height);
2993 pixel_width = (!NILP (pixelwise)
2994 ? XINT (width)
2995 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2996 pixel_height = (!NILP (pixelwise)
2997 ? XINT (height)
2998 : XINT (height) * FRAME_LINE_HEIGHT (f));
2999 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
3001 return Qnil;
3004 DEFUN ("frame-position", Fframe_position,
3005 Sframe_position, 0, 1, 0,
3006 doc: /* Return top left corner of FRAME in pixels.
3007 FRAME must be a live frame and defaults to the selected one. The return
3008 value is a cons (x, y) of the coordinates of the top left corner of
3009 FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's
3010 display. */)
3011 (Lisp_Object frame)
3013 register struct frame *f = decode_live_frame (frame);
3015 return Fcons (make_number (f->left_pos), make_number (f->top_pos));
3018 DEFUN ("set-frame-position", Fset_frame_position,
3019 Sset_frame_position, 3, 3, 0,
3020 doc: /* Set position of FRAME to (X, Y).
3021 FRAME must be a live frame and defaults to the selected one. X and Y,
3022 if positive, specify the coordinate of the left and top edge of FRAME's
3023 outer frame in pixels relative to an origin (0, 0) of FRAME's display.
3024 If any of X or Y is negative, it specifies the coordinates of the right
3025 or bottom edge of the outer frame of FRAME relative to the right or
3026 bottom edge of FRAME's display. */)
3027 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
3029 struct frame *f = decode_live_frame (frame);
3031 CHECK_TYPE_RANGED_INTEGER (int, x);
3032 CHECK_TYPE_RANGED_INTEGER (int, y);
3034 /* I think this should be done with a hook. */
3035 if (FRAME_WINDOW_P (f))
3037 #ifdef HAVE_WINDOW_SYSTEM
3038 x_set_offset (f, XINT (x), XINT (y), 1);
3039 #endif
3042 return Qt;
3046 /***********************************************************************
3047 Frame Parameters
3048 ***********************************************************************/
3050 /* Connect the frame-parameter names for X frames
3051 to the ways of passing the parameter values to the window system.
3053 The name of a parameter, as a Lisp symbol,
3054 has an `x-frame-parameter' property which is an integer in Lisp
3055 that is an index in this table. */
3057 struct frame_parm_table {
3058 const char *name;
3059 int sym;
3062 static const struct frame_parm_table frame_parms[] =
3064 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3065 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3066 {"background-color", -1},
3067 {"border-color", SYMBOL_INDEX (Qborder_color)},
3068 {"border-width", SYMBOL_INDEX (Qborder_width)},
3069 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3070 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3071 {"font", -1},
3072 {"foreground-color", -1},
3073 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3074 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3075 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3076 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3077 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3078 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3079 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3080 {"name", SYMBOL_INDEX (Qname)},
3081 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3082 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3083 {"title", SYMBOL_INDEX (Qtitle)},
3084 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3085 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3086 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3087 {"visibility", SYMBOL_INDEX (Qvisibility)},
3088 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3089 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3090 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3091 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3092 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3093 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3094 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3095 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3096 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3097 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3098 {"alpha", SYMBOL_INDEX (Qalpha)},
3099 {"sticky", SYMBOL_INDEX (Qsticky)},
3100 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3101 {"inhibit-double-buffering", SYMBOL_INDEX (Qinhibit_double_buffering)},
3104 #ifdef HAVE_WINDOW_SYSTEM
3106 /* Change the parameters of frame F as specified by ALIST.
3107 If a parameter is not specially recognized, do nothing special;
3108 otherwise call the `x_set_...' function for that parameter.
3109 Except for certain geometry properties, always call store_frame_param
3110 to store the new value in the parameter alist. */
3112 void
3113 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3115 Lisp_Object tail;
3117 /* If both of these parameters are present, it's more efficient to
3118 set them both at once. So we wait until we've looked at the
3119 entire list before we set them. */
3120 int width = -1, height = -1; /* -1 denotes they were not changed. */
3122 /* Same here. */
3123 Lisp_Object left, top;
3125 /* Same with these. */
3126 Lisp_Object icon_left, icon_top;
3128 /* And with this. */
3129 Lisp_Object fullscreen;
3130 bool fullscreen_change = false;
3132 /* Record in these vectors all the parms specified. */
3133 Lisp_Object *parms;
3134 Lisp_Object *values;
3135 ptrdiff_t i, j, size;
3136 bool left_no_change = 0, top_no_change = 0;
3137 #ifdef HAVE_X_WINDOWS
3138 bool icon_left_no_change = 0, icon_top_no_change = 0;
3139 #endif
3141 for (size = 0, tail = alist; CONSP (tail); tail = XCDR (tail))
3142 size++;
3143 CHECK_LIST_END (tail, alist);
3145 USE_SAFE_ALLOCA;
3146 SAFE_ALLOCA_LISP (parms, 2 * size);
3147 values = parms + size;
3149 /* Extract parm names and values into those vectors. */
3151 i = 0, j = size - 1;
3152 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3154 Lisp_Object elt = XCAR (tail), prop = Fcar (elt), val = Fcdr (elt);
3156 /* Some properties are independent of other properties, but other
3157 properties are dependent upon them. These special properties
3158 are foreground_color, background_color (affects cursor_color)
3159 and font (affects fringe widths); they're recorded starting
3160 from the end of PARMS and VALUES to process them first by using
3161 reverse iteration. */
3163 if (EQ (prop, Qforeground_color)
3164 || EQ (prop, Qbackground_color)
3165 || EQ (prop, Qfont))
3167 parms[j] = prop;
3168 values[j] = val;
3169 j--;
3171 else
3173 parms[i] = prop;
3174 values[i] = val;
3175 i++;
3179 /* TAIL and ALIST are not used again below here. */
3180 alist = tail = Qnil;
3182 top = left = Qunbound;
3183 icon_left = icon_top = Qunbound;
3185 /* Reverse order is used to make sure that special
3186 properties noticed above are processed first. */
3187 for (i = size - 1; i >= 0; i--)
3189 Lisp_Object prop, val;
3191 prop = parms[i];
3192 val = values[i];
3194 if (EQ (prop, Qwidth))
3196 if (RANGED_INTEGERP (0, val, INT_MAX))
3197 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3198 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3199 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3200 width = XFASTINT (XCDR (val));
3202 else if (EQ (prop, Qheight))
3204 if (RANGED_INTEGERP (0, val, INT_MAX))
3205 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3206 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3207 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3208 height = XFASTINT (XCDR (val));
3210 else if (EQ (prop, Qtop))
3211 top = val;
3212 else if (EQ (prop, Qleft))
3213 left = val;
3214 else if (EQ (prop, Qicon_top))
3215 icon_top = val;
3216 else if (EQ (prop, Qicon_left))
3217 icon_left = val;
3218 else if (EQ (prop, Qfullscreen))
3220 fullscreen = val;
3221 fullscreen_change = true;
3223 else
3225 register Lisp_Object param_index, old_value;
3227 old_value = get_frame_param (f, prop);
3229 store_frame_param (f, prop, val);
3231 param_index = Fget (prop, Qx_frame_parameter);
3232 if (NATNUMP (param_index)
3233 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3234 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3235 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3239 /* Don't die if just one of these was set. */
3240 if (EQ (left, Qunbound))
3242 left_no_change = 1;
3243 if (f->left_pos < 0)
3244 left = list2 (Qplus, make_number (f->left_pos));
3245 else
3246 XSETINT (left, f->left_pos);
3248 if (EQ (top, Qunbound))
3250 top_no_change = 1;
3251 if (f->top_pos < 0)
3252 top = list2 (Qplus, make_number (f->top_pos));
3253 else
3254 XSETINT (top, f->top_pos);
3257 /* If one of the icon positions was not set, preserve or default it. */
3258 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3260 #ifdef HAVE_X_WINDOWS
3261 icon_left_no_change = 1;
3262 #endif
3263 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3264 if (NILP (icon_left))
3265 XSETINT (icon_left, 0);
3267 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3269 #ifdef HAVE_X_WINDOWS
3270 icon_top_no_change = 1;
3271 #endif
3272 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3273 if (NILP (icon_top))
3274 XSETINT (icon_top, 0);
3277 /* Don't set these parameters unless they've been explicitly
3278 specified. The window might be mapped or resized while we're in
3279 this function, and we don't want to override that unless the lisp
3280 code has asked for it.
3282 Don't set these parameters unless they actually differ from the
3283 window's current parameters; the window may not actually exist
3284 yet. */
3286 Lisp_Object frame;
3288 XSETFRAME (frame, f);
3290 if ((width != -1 && width != FRAME_TEXT_WIDTH (f))
3291 || (height != -1 && height != FRAME_TEXT_HEIGHT (f)))
3292 /* We could consider checking f->after_make_frame here, but I
3293 don't have the faintest idea why the following is needed at
3294 all. With the old setting it can get a Heisenbug when
3295 EmacsFrameResize intermittently provokes a delayed
3296 change_frame_size in the middle of adjust_frame_size. */
3297 /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
3298 adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters);
3300 if ((!NILP (left) || !NILP (top))
3301 && ! (left_no_change && top_no_change)
3302 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3303 && NUMBERP (top) && XINT (top) == f->top_pos))
3305 int leftpos = 0;
3306 int toppos = 0;
3308 /* Record the signs. */
3309 f->size_hint_flags &= ~ (XNegative | YNegative);
3310 if (EQ (left, Qminus))
3311 f->size_hint_flags |= XNegative;
3312 else if (TYPE_RANGED_INTEGERP (int, left))
3314 leftpos = XINT (left);
3315 if (leftpos < 0)
3316 f->size_hint_flags |= XNegative;
3318 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3319 && CONSP (XCDR (left))
3320 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3322 leftpos = - XINT (XCAR (XCDR (left)));
3323 f->size_hint_flags |= XNegative;
3325 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3326 && CONSP (XCDR (left))
3327 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3329 leftpos = XINT (XCAR (XCDR (left)));
3332 if (EQ (top, Qminus))
3333 f->size_hint_flags |= YNegative;
3334 else if (TYPE_RANGED_INTEGERP (int, top))
3336 toppos = XINT (top);
3337 if (toppos < 0)
3338 f->size_hint_flags |= YNegative;
3340 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3341 && CONSP (XCDR (top))
3342 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3344 toppos = - XINT (XCAR (XCDR (top)));
3345 f->size_hint_flags |= YNegative;
3347 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3348 && CONSP (XCDR (top))
3349 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3351 toppos = XINT (XCAR (XCDR (top)));
3355 /* Store the numeric value of the position. */
3356 f->top_pos = toppos;
3357 f->left_pos = leftpos;
3359 f->win_gravity = NorthWestGravity;
3361 /* Actually set that position, and convert to absolute. */
3362 x_set_offset (f, leftpos, toppos, -1);
3365 if (fullscreen_change)
3367 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
3369 frame_size_history_add
3370 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
3372 store_frame_param (f, Qfullscreen, fullscreen);
3373 if (!EQ (fullscreen, old_value))
3374 x_set_fullscreen (f, fullscreen, old_value);
3378 #ifdef HAVE_X_WINDOWS
3379 if ((!NILP (icon_left) || !NILP (icon_top))
3380 && ! (icon_left_no_change && icon_top_no_change))
3381 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3382 #endif /* HAVE_X_WINDOWS */
3385 SAFE_FREE ();
3389 /* Insert a description of internally-recorded parameters of frame X
3390 into the parameter alist *ALISTPTR that is to be given to the user.
3391 Only parameters that are specific to the X window system
3392 and whose values are not correctly recorded in the frame's
3393 param_alist need to be considered here. */
3395 void
3396 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3398 Lisp_Object tem;
3399 uprintmax_t w;
3400 char buf[INT_BUFSIZE_BOUND (w)];
3402 /* Represent negative positions (off the top or left screen edge)
3403 in a way that Fmodify_frame_parameters will understand correctly. */
3404 XSETINT (tem, f->left_pos);
3405 if (f->left_pos >= 0)
3406 store_in_alist (alistptr, Qleft, tem);
3407 else
3408 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3410 XSETINT (tem, f->top_pos);
3411 if (f->top_pos >= 0)
3412 store_in_alist (alistptr, Qtop, tem);
3413 else
3414 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3416 store_in_alist (alistptr, Qborder_width,
3417 make_number (f->border_width));
3418 store_in_alist (alistptr, Qinternal_border_width,
3419 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3420 store_in_alist (alistptr, Qright_divider_width,
3421 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3422 store_in_alist (alistptr, Qbottom_divider_width,
3423 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3424 store_in_alist (alistptr, Qleft_fringe,
3425 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3426 store_in_alist (alistptr, Qright_fringe,
3427 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3428 store_in_alist (alistptr, Qscroll_bar_width,
3429 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3430 ? make_number (0)
3431 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3432 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3433 /* nil means "use default width"
3434 for non-toolkit scroll bar.
3435 ruler-mode.el depends on this. */
3436 : Qnil));
3437 store_in_alist (alistptr, Qscroll_bar_height,
3438 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3439 ? make_number (0)
3440 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3441 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3442 /* nil means "use default height"
3443 for non-toolkit scroll bar. */
3444 : Qnil));
3445 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3446 MS-Windows it returns a value whose type is HANDLE, which is
3447 actually a pointer. Explicit casting avoids compiler
3448 warnings. */
3449 w = (uintptr_t) FRAME_X_WINDOW (f);
3450 store_in_alist (alistptr, Qwindow_id,
3451 make_formatted_string (buf, "%"pMu, w));
3452 #ifdef HAVE_X_WINDOWS
3453 #ifdef USE_X_TOOLKIT
3454 /* Tooltip frame may not have this widget. */
3455 if (FRAME_X_OUTPUT (f)->widget)
3456 #endif
3457 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3458 store_in_alist (alistptr, Qouter_window_id,
3459 make_formatted_string (buf, "%"pMu, w));
3460 #endif
3461 store_in_alist (alistptr, Qicon_name, f->icon_name);
3462 store_in_alist (alistptr, Qvisibility,
3463 (FRAME_VISIBLE_P (f) ? Qt
3464 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3465 store_in_alist (alistptr, Qdisplay,
3466 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3468 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3469 tem = Qnil;
3470 else
3471 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3472 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3473 store_in_alist (alistptr, Qparent_id, tem);
3474 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3478 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3479 the previous value of that parameter, NEW_VALUE is the new value. */
3481 void
3482 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3484 if (NILP (new_value))
3485 f->want_fullscreen = FULLSCREEN_NONE;
3486 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3487 f->want_fullscreen = FULLSCREEN_BOTH;
3488 else if (EQ (new_value, Qfullwidth))
3489 f->want_fullscreen = FULLSCREEN_WIDTH;
3490 else if (EQ (new_value, Qfullheight))
3491 f->want_fullscreen = FULLSCREEN_HEIGHT;
3492 else if (EQ (new_value, Qmaximized))
3493 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3495 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3496 FRAME_TERMINAL (f)->fullscreen_hook (f);
3500 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3501 the previous value of that parameter, NEW_VALUE is the new value. */
3503 void
3504 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3506 if (NILP (new_value))
3507 f->extra_line_spacing = 0;
3508 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3509 f->extra_line_spacing = XFASTINT (new_value);
3510 else if (FLOATP (new_value))
3512 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3514 if (new_spacing >= 0)
3515 f->extra_line_spacing = new_spacing;
3516 else
3517 signal_error ("Invalid line-spacing", new_value);
3519 else
3520 signal_error ("Invalid line-spacing", new_value);
3521 if (FRAME_VISIBLE_P (f))
3522 redraw_frame (f);
3526 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3527 the previous value of that parameter, NEW_VALUE is the new value. */
3529 void
3530 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3532 Lisp_Object bgcolor;
3534 if (NILP (new_value))
3535 f->gamma = 0;
3536 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3537 /* The value 0.4545 is the normal viewing gamma. */
3538 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3539 else
3540 signal_error ("Invalid screen-gamma", new_value);
3542 /* Apply the new gamma value to the frame background. */
3543 bgcolor = Fassq (Qbackground_color, f->param_alist);
3544 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3546 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3547 if (NATNUMP (parm_index)
3548 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3549 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3550 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3551 (f, bgcolor, Qnil);
3554 clear_face_cache (true); /* FIXME: Why of all frames? */
3555 fset_redisplay (f);
3559 void
3560 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3562 Lisp_Object font_object;
3563 int fontset = -1;
3564 #ifdef HAVE_X_WINDOWS
3565 Lisp_Object font_param = arg;
3566 #endif
3568 /* Set the frame parameter back to the old value because we may
3569 fail to use ARG as the new parameter value. */
3570 store_frame_param (f, Qfont, oldval);
3572 /* ARG is a fontset name, a font name, a cons of fontset name and a
3573 font object, or a font object. In the last case, this function
3574 never fail. */
3575 if (STRINGP (arg))
3577 fontset = fs_query_fontset (arg, 0);
3578 if (fontset < 0)
3580 font_object = font_open_by_name (f, arg);
3581 if (NILP (font_object))
3582 error ("Font `%s' is not defined", SSDATA (arg));
3583 arg = AREF (font_object, FONT_NAME_INDEX);
3585 else if (fontset > 0)
3587 font_object = font_open_by_name (f, fontset_ascii (fontset));
3588 if (NILP (font_object))
3589 error ("Font `%s' is not defined", SDATA (arg));
3590 arg = AREF (font_object, FONT_NAME_INDEX);
3592 else
3593 error ("The default fontset can't be used for a frame font");
3595 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3597 /* This is the case that the ASCII font of F's fontset XCAR
3598 (arg) is changed to the font XCDR (arg) by
3599 `set-fontset-font'. */
3600 fontset = fs_query_fontset (XCAR (arg), 0);
3601 if (fontset < 0)
3602 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3603 font_object = XCDR (arg);
3604 arg = AREF (font_object, FONT_NAME_INDEX);
3605 #ifdef HAVE_X_WINDOWS
3606 font_param = Ffont_get (font_object, QCname);
3607 #endif
3609 else if (FONT_OBJECT_P (arg))
3611 font_object = arg;
3612 #ifdef HAVE_X_WINDOWS
3613 font_param = Ffont_get (font_object, QCname);
3614 #endif
3615 /* This is to store the XLFD font name in the frame parameter for
3616 backward compatibility. We should store the font-object
3617 itself in the future. */
3618 arg = AREF (font_object, FONT_NAME_INDEX);
3619 fontset = FRAME_FONTSET (f);
3620 /* Check if we can use the current fontset. If not, set FONTSET
3621 to -1 to generate a new fontset from FONT-OBJECT. */
3622 if (fontset >= 0)
3624 Lisp_Object ascii_font = fontset_ascii (fontset);
3625 Lisp_Object spec = font_spec_from_name (ascii_font);
3627 /* SPEC might be nil because ASCII_FONT's name doesn't parse
3628 according to stupid XLFD rules, which, for example,
3629 disallow font names that include a dash followed by a
3630 number. So in those cases we simply request x_new_font
3631 below to generate a new fontset. */
3632 if (NILP (spec) || ! font_match_p (spec, font_object))
3633 fontset = -1;
3636 else
3637 signal_error ("Invalid font", arg);
3639 if (! NILP (Fequal (font_object, oldval)))
3640 return;
3642 x_new_font (f, font_object, fontset);
3643 store_frame_param (f, Qfont, arg);
3644 #ifdef HAVE_X_WINDOWS
3645 store_frame_param (f, Qfont_parameter, font_param);
3646 #endif
3647 /* Recalculate toolbar height. */
3648 f->n_tool_bar_rows = 0;
3650 /* Ensure we redraw it. */
3651 clear_current_matrices (f);
3653 /* Attempt to hunt down bug#16028. */
3654 SET_FRAME_GARBAGED (f);
3656 /* This is important if we are called by some Lisp as part of
3657 redisplaying the frame, see redisplay_internal. */
3658 f->fonts_changed = true;
3660 recompute_basic_faces (f);
3662 do_pending_window_change (0);
3664 /* We used to call face-set-after-frame-default here, but it leads to
3665 recursive calls (since that function can set the `default' face's
3666 font which in turns changes the frame's `font' parameter).
3667 Also I don't know what this call is meant to do, but it seems the
3668 wrong way to do it anyway (it does a lot more work than what seems
3669 reasonable in response to a change to `font'). */
3673 void
3674 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3676 if (! NILP (new_value)
3677 && !CONSP (new_value))
3679 char *p0, *p1;
3681 CHECK_STRING (new_value);
3682 p0 = p1 = SSDATA (new_value);
3683 new_value = Qnil;
3684 while (*p0)
3686 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3687 if (p0 < p1)
3688 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3689 new_value);
3690 if (*p1)
3692 int c;
3694 while ((c = *++p1) && c_isspace (c));
3696 p0 = p1;
3698 new_value = Fnreverse (new_value);
3701 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3702 return;
3704 if (FRAME_FONT (f))
3705 free_all_realized_faces (Qnil);
3707 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3708 if (NILP (new_value))
3710 if (NILP (old_value))
3711 error ("No font backend available");
3712 font_update_drivers (f, old_value);
3713 error ("None of specified font backends are available");
3715 store_frame_param (f, Qfont_backend, new_value);
3717 if (FRAME_FONT (f))
3719 Lisp_Object frame;
3721 XSETFRAME (frame, f);
3722 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3723 face_change = true;
3724 windows_or_buffers_changed = 18;
3728 void
3729 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3731 int unit = FRAME_COLUMN_WIDTH (f);
3732 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3733 int new_width;
3735 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3736 ? eabs (XINT (new_value)) : 8);
3738 if (new_width != old_width)
3740 f->left_fringe_width = new_width;
3741 f->fringe_cols /* Round up. */
3742 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3744 if (FRAME_X_WINDOW (f) != 0)
3745 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
3747 SET_FRAME_GARBAGED (f);
3752 void
3753 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3755 int unit = FRAME_COLUMN_WIDTH (f);
3756 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3757 int new_width;
3759 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3760 ? eabs (XINT (new_value)) : 8);
3762 if (new_width != old_width)
3764 f->right_fringe_width = new_width;
3765 f->fringe_cols /* Round up. */
3766 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3768 if (FRAME_X_WINDOW (f) != 0)
3769 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
3771 SET_FRAME_GARBAGED (f);
3776 void
3777 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3779 CHECK_TYPE_RANGED_INTEGER (int, arg);
3781 if (XINT (arg) == f->border_width)
3782 return;
3784 if (FRAME_X_WINDOW (f) != 0)
3785 error ("Cannot change the border width of a frame");
3787 f->border_width = XINT (arg);
3790 void
3791 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3793 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3794 CHECK_TYPE_RANGED_INTEGER (int, arg);
3795 int new = max (0, XINT (arg));
3796 if (new != old)
3798 f->right_divider_width = new;
3799 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
3800 adjust_frame_glyphs (f);
3801 SET_FRAME_GARBAGED (f);
3806 void
3807 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3809 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3810 CHECK_TYPE_RANGED_INTEGER (int, arg);
3811 int new = max (0, XINT (arg));
3812 if (new != old)
3814 f->bottom_divider_width = new;
3815 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
3816 adjust_frame_glyphs (f);
3817 SET_FRAME_GARBAGED (f);
3821 void
3822 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3824 Lisp_Object frame;
3825 XSETFRAME (frame, f);
3827 if (NILP (value))
3828 Fmake_frame_invisible (frame, Qt);
3829 else if (EQ (value, Qicon))
3830 Ficonify_frame (frame);
3831 else
3832 Fmake_frame_visible (frame);
3835 void
3836 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3838 f->auto_raise = !EQ (Qnil, arg);
3841 void
3842 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3844 f->auto_lower = !EQ (Qnil, arg);
3847 void
3848 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3850 f->no_split = !NILP (arg);
3853 void
3854 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3856 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3857 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3858 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3859 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3861 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3862 = (NILP (arg)
3863 ? vertical_scroll_bar_none
3864 : EQ (Qleft, arg)
3865 ? vertical_scroll_bar_left
3866 : EQ (Qright, arg)
3867 ? vertical_scroll_bar_right
3868 : EQ (Qleft, Vdefault_frame_scroll_bars)
3869 ? vertical_scroll_bar_left
3870 : EQ (Qright, Vdefault_frame_scroll_bars)
3871 ? vertical_scroll_bar_right
3872 : vertical_scroll_bar_none);
3874 /* We set this parameter before creating the X window for the
3875 frame, so we can get the geometry right from the start.
3876 However, if the window hasn't been created yet, we shouldn't
3877 call x_set_window_size. */
3878 if (FRAME_X_WINDOW (f))
3879 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
3881 SET_FRAME_GARBAGED (f);
3885 void
3886 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3888 #if USE_HORIZONTAL_SCROLL_BARS
3889 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3890 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3892 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3894 /* We set this parameter before creating the X window for the
3895 frame, so we can get the geometry right from the start.
3896 However, if the window hasn't been created yet, we shouldn't
3897 call x_set_window_size. */
3898 if (FRAME_X_WINDOW (f))
3899 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
3901 SET_FRAME_GARBAGED (f);
3903 #endif
3906 void
3907 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3909 int unit = FRAME_COLUMN_WIDTH (f);
3911 if (NILP (arg))
3913 x_set_scroll_bar_default_width (f);
3915 if (FRAME_X_WINDOW (f))
3916 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3918 SET_FRAME_GARBAGED (f);
3920 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3921 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3923 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3924 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3925 if (FRAME_X_WINDOW (f))
3926 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3928 SET_FRAME_GARBAGED (f);
3931 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3932 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3935 void
3936 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3938 #if USE_HORIZONTAL_SCROLL_BARS
3939 int unit = FRAME_LINE_HEIGHT (f);
3941 if (NILP (arg))
3943 x_set_scroll_bar_default_height (f);
3945 if (FRAME_X_WINDOW (f))
3946 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3948 SET_FRAME_GARBAGED (f);
3950 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3951 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3953 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3954 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3955 if (FRAME_X_WINDOW (f))
3956 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3958 SET_FRAME_GARBAGED (f);
3961 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3962 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3963 #endif
3966 void
3967 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3969 double alpha = 1.0;
3970 double newval[2];
3971 int i;
3972 Lisp_Object item;
3974 for (i = 0; i < 2; i++)
3976 newval[i] = 1.0;
3977 if (CONSP (arg))
3979 item = CAR (arg);
3980 arg = CDR (arg);
3982 else
3983 item = arg;
3985 if (NILP (item))
3986 alpha = - 1.0;
3987 else if (FLOATP (item))
3989 alpha = XFLOAT_DATA (item);
3990 if (! (0 <= alpha && alpha <= 1.0))
3991 args_out_of_range (make_float (0.0), make_float (1.0));
3993 else if (INTEGERP (item))
3995 EMACS_INT ialpha = XINT (item);
3996 if (! (0 <= ialpha && alpha <= 100))
3997 args_out_of_range (make_number (0), make_number (100));
3998 alpha = ialpha / 100.0;
4000 else
4001 wrong_type_argument (Qnumberp, item);
4002 newval[i] = alpha;
4005 for (i = 0; i < 2; i++)
4006 f->alpha[i] = newval[i];
4008 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4009 block_input ();
4010 x_set_frame_alpha (f);
4011 unblock_input ();
4012 #endif
4014 return;
4017 #ifndef HAVE_NS
4019 /* Non-zero if mouse is grabbed on DPYINFO
4020 and we know the frame where it is. */
4022 bool x_mouse_grabbed (Display_Info *dpyinfo)
4024 return (dpyinfo->grabbed
4025 && dpyinfo->last_mouse_frame
4026 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4029 /* Re-highlight something with mouse-face properties
4030 on DPYINFO using saved frame and mouse position. */
4032 void
4033 x_redo_mouse_highlight (Display_Info *dpyinfo)
4035 if (dpyinfo->last_mouse_motion_frame
4036 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4037 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4038 dpyinfo->last_mouse_motion_x,
4039 dpyinfo->last_mouse_motion_y);
4042 #endif /* HAVE_NS */
4044 /* Subroutines of creating an X frame. */
4046 /* Make sure that Vx_resource_name is set to a reasonable value.
4047 Fix it up, or set it to `emacs' if it is too hopeless. */
4049 void
4050 validate_x_resource_name (void)
4052 ptrdiff_t len = 0;
4053 /* Number of valid characters in the resource name. */
4054 ptrdiff_t good_count = 0;
4055 /* Number of invalid characters in the resource name. */
4056 ptrdiff_t bad_count = 0;
4057 Lisp_Object new;
4058 ptrdiff_t i;
4060 if (!STRINGP (Vx_resource_class))
4061 Vx_resource_class = build_string (EMACS_CLASS);
4063 if (STRINGP (Vx_resource_name))
4065 unsigned char *p = SDATA (Vx_resource_name);
4067 len = SBYTES (Vx_resource_name);
4069 /* Only letters, digits, - and _ are valid in resource names.
4070 Count the valid characters and count the invalid ones. */
4071 for (i = 0; i < len; i++)
4073 int c = p[i];
4074 if (! ((c >= 'a' && c <= 'z')
4075 || (c >= 'A' && c <= 'Z')
4076 || (c >= '0' && c <= '9')
4077 || c == '-' || c == '_'))
4078 bad_count++;
4079 else
4080 good_count++;
4083 else
4084 /* Not a string => completely invalid. */
4085 bad_count = 5, good_count = 0;
4087 /* If name is valid already, return. */
4088 if (bad_count == 0)
4089 return;
4091 /* If name is entirely invalid, or nearly so, or is so implausibly
4092 large that alloca might not work, use `emacs'. */
4093 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4095 Vx_resource_name = build_string ("emacs");
4096 return;
4099 /* Name is partly valid. Copy it and replace the invalid characters
4100 with underscores. */
4102 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4104 for (i = 0; i < len; i++)
4106 int c = SREF (new, i);
4107 if (! ((c >= 'a' && c <= 'z')
4108 || (c >= 'A' && c <= 'Z')
4109 || (c >= '0' && c <= '9')
4110 || c == '-' || c == '_'))
4111 SSET (new, i, '_');
4115 /* Get specified attribute from resource database RDB.
4116 See Fx_get_resource below for other parameters. */
4118 static Lisp_Object
4119 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4121 CHECK_STRING (attribute);
4122 CHECK_STRING (class);
4124 if (!NILP (component))
4125 CHECK_STRING (component);
4126 if (!NILP (subclass))
4127 CHECK_STRING (subclass);
4128 if (NILP (component) != NILP (subclass))
4129 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4131 validate_x_resource_name ();
4133 /* Allocate space for the components, the dots which separate them,
4134 and the final '\0'. Make them big enough for the worst case. */
4135 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4136 + (STRINGP (component)
4137 ? SBYTES (component) : 0)
4138 + SBYTES (attribute)
4139 + 3);
4141 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4142 + SBYTES (class)
4143 + (STRINGP (subclass)
4144 ? SBYTES (subclass) : 0)
4145 + 3);
4146 USE_SAFE_ALLOCA;
4147 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4148 char *class_key = name_key + name_keysize;
4150 /* Start with emacs.FRAMENAME for the name (the specific one)
4151 and with `Emacs' for the class key (the general one). */
4152 char *nz = lispstpcpy (name_key, Vx_resource_name);
4153 char *cz = lispstpcpy (class_key, Vx_resource_class);
4155 *cz++ = '.';
4156 cz = lispstpcpy (cz, class);
4158 if (!NILP (component))
4160 *cz++ = '.';
4161 lispstpcpy (cz, subclass);
4163 *nz++ = '.';
4164 nz = lispstpcpy (nz, component);
4167 *nz++ = '.';
4168 lispstpcpy (nz, attribute);
4170 char *value = x_get_string_resource (rdb, name_key, class_key);
4171 SAFE_FREE();
4173 if (value && *value)
4174 return build_string (value);
4175 else
4176 return Qnil;
4180 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4181 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4182 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4183 class, where INSTANCE is the name under which Emacs was invoked, or
4184 the name specified by the `-name' or `-rn' command-line arguments.
4186 The optional arguments COMPONENT and SUBCLASS add to the key and the
4187 class, respectively. You must specify both of them or neither.
4188 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4189 and the class is `Emacs.CLASS.SUBCLASS'. */)
4190 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4191 Lisp_Object subclass)
4193 check_window_system (NULL);
4195 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4196 attribute, class, component, subclass);
4199 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4201 Lisp_Object
4202 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4203 Lisp_Object class, Lisp_Object component,
4204 Lisp_Object subclass)
4206 return xrdb_get_resource (dpyinfo->xrdb,
4207 attribute, class, component, subclass);
4210 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4211 /* Used when C code wants a resource value. */
4212 /* Called from oldXMenu/Create.c. */
4213 char *
4214 x_get_resource_string (const char *attribute, const char *class)
4216 char *result;
4217 struct frame *sf = SELECTED_FRAME ();
4218 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4219 USE_SAFE_ALLOCA;
4221 /* Allocate space for the components, the dots which separate them,
4222 and the final '\0'. */
4223 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4224 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4225 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4226 char *class_key = name_key + name_keysize;
4228 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4229 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4231 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4232 name_key, class_key);
4233 SAFE_FREE ();
4234 return result;
4236 #endif
4238 /* Return the value of parameter PARAM.
4240 First search ALIST, then Vdefault_frame_alist, then the X defaults
4241 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4243 Convert the resource to the type specified by desired_type.
4245 If no default is specified, return Qunbound. If you call
4246 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4247 and don't let it get stored in any Lisp-visible variables! */
4249 Lisp_Object
4250 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4251 const char *attribute, const char *class, enum resource_types type)
4253 Lisp_Object tem;
4255 tem = Fassq (param, alist);
4257 if (!NILP (tem))
4259 /* If we find this parm in ALIST, clear it out
4260 so that it won't be "left over" at the end. */
4261 Lisp_Object tail;
4262 XSETCAR (tem, Qnil);
4263 /* In case the parameter appears more than once in the alist,
4264 clear it out. */
4265 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4266 if (CONSP (XCAR (tail))
4267 && EQ (XCAR (XCAR (tail)), param))
4268 XSETCAR (XCAR (tail), Qnil);
4270 else
4271 tem = Fassq (param, Vdefault_frame_alist);
4273 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4274 look in the X resources. */
4275 if (EQ (tem, Qnil))
4277 if (attribute && dpyinfo)
4279 AUTO_STRING (at, attribute);
4280 AUTO_STRING (cl, class);
4281 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4283 if (NILP (tem))
4284 return Qunbound;
4286 switch (type)
4288 case RES_TYPE_NUMBER:
4289 return make_number (atoi (SSDATA (tem)));
4291 case RES_TYPE_BOOLEAN_NUMBER:
4292 if (!strcmp (SSDATA (tem), "on")
4293 || !strcmp (SSDATA (tem), "true"))
4294 return make_number (1);
4295 return make_number (atoi (SSDATA (tem)));
4296 break;
4298 case RES_TYPE_FLOAT:
4299 return make_float (atof (SSDATA (tem)));
4301 case RES_TYPE_BOOLEAN:
4302 tem = Fdowncase (tem);
4303 if (!strcmp (SSDATA (tem), "on")
4304 #ifdef HAVE_NS
4305 || !strcmp (SSDATA (tem), "yes")
4306 #endif
4307 || !strcmp (SSDATA (tem), "true"))
4308 return Qt;
4309 else
4310 return Qnil;
4312 case RES_TYPE_STRING:
4313 return tem;
4315 case RES_TYPE_SYMBOL:
4316 /* As a special case, we map the values `true' and `on'
4317 to Qt, and `false' and `off' to Qnil. */
4319 Lisp_Object lower;
4320 lower = Fdowncase (tem);
4321 if (!strcmp (SSDATA (lower), "on")
4322 #ifdef HAVE_NS
4323 || !strcmp (SSDATA (lower), "yes")
4324 #endif
4325 || !strcmp (SSDATA (lower), "true"))
4326 return Qt;
4327 else if (!strcmp (SSDATA (lower), "off")
4328 #ifdef HAVE_NS
4329 || !strcmp (SSDATA (lower), "no")
4330 #endif
4331 || !strcmp (SSDATA (lower), "false"))
4332 return Qnil;
4333 else
4334 return Fintern (tem, Qnil);
4337 default:
4338 emacs_abort ();
4341 else
4342 return Qunbound;
4344 return Fcdr (tem);
4347 static Lisp_Object
4348 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4349 const char *attribute, const char *class,
4350 enum resource_types type)
4352 return x_get_arg (FRAME_DISPLAY_INFO (f),
4353 alist, param, attribute, class, type);
4356 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4358 Lisp_Object
4359 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4360 Lisp_Object param,
4361 const char *attribute, const char *class,
4362 enum resource_types type)
4364 Lisp_Object value;
4366 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4367 attribute, class, type);
4368 if (! NILP (value) && ! EQ (value, Qunbound))
4369 store_frame_param (f, param, value);
4371 return value;
4375 /* Record in frame F the specified or default value according to ALIST
4376 of the parameter named PROP (a Lisp symbol).
4377 If no value is specified for PROP, look for an X default for XPROP
4378 on the frame named NAME.
4379 If that is not found either, use the value DEFLT. */
4381 Lisp_Object
4382 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4383 Lisp_Object deflt, const char *xprop, const char *xclass,
4384 enum resource_types type)
4386 Lisp_Object tem;
4388 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4389 if (EQ (tem, Qunbound))
4390 tem = deflt;
4391 AUTO_FRAME_ARG (arg, prop, tem);
4392 x_set_frame_parameters (f, arg);
4393 return tem;
4397 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4400 * XParseGeometry parses strings of the form
4401 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4402 * width, height, xoffset, and yoffset are unsigned integers.
4403 * Example: "=80x24+300-49"
4404 * The equal sign is optional.
4405 * It returns a bitmask that indicates which of the four values
4406 * were actually found in the string. For each value found,
4407 * the corresponding argument is updated; for each value
4408 * not found, the corresponding argument is left unchanged.
4411 static int
4412 XParseGeometry (char *string,
4413 int *x, int *y,
4414 unsigned int *width, unsigned int *height)
4416 int mask = NoValue;
4417 char *strind;
4418 unsigned long tempWidth UNINIT, tempHeight UNINIT;
4419 long int tempX UNINIT, tempY UNINIT;
4420 char *nextCharacter;
4422 if (string == NULL || *string == '\0')
4423 return mask;
4424 if (*string == '=')
4425 string++; /* ignore possible '=' at beg of geometry spec */
4427 strind = string;
4428 if (*strind != '+' && *strind != '-' && *strind != 'x')
4430 tempWidth = strtoul (strind, &nextCharacter, 10);
4431 if (strind == nextCharacter)
4432 return 0;
4433 strind = nextCharacter;
4434 mask |= WidthValue;
4437 if (*strind == 'x' || *strind == 'X')
4439 strind++;
4440 tempHeight = strtoul (strind, &nextCharacter, 10);
4441 if (strind == nextCharacter)
4442 return 0;
4443 strind = nextCharacter;
4444 mask |= HeightValue;
4447 if (*strind == '+' || *strind == '-')
4449 if (*strind == '-')
4450 mask |= XNegative;
4451 tempX = strtol (strind, &nextCharacter, 10);
4452 if (strind == nextCharacter)
4453 return 0;
4454 strind = nextCharacter;
4455 mask |= XValue;
4456 if (*strind == '+' || *strind == '-')
4458 if (*strind == '-')
4459 mask |= YNegative;
4460 tempY = strtol (strind, &nextCharacter, 10);
4461 if (strind == nextCharacter)
4462 return 0;
4463 strind = nextCharacter;
4464 mask |= YValue;
4468 /* If strind isn't at the end of the string then it's an invalid
4469 geometry specification. */
4471 if (*strind != '\0')
4472 return 0;
4474 if (mask & XValue)
4475 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4476 if (mask & YValue)
4477 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4478 if (mask & WidthValue)
4479 *width = min (tempWidth, UINT_MAX);
4480 if (mask & HeightValue)
4481 *height = min (tempHeight, UINT_MAX);
4482 return mask;
4485 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4488 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4489 make-docfile: the documentation string in ns-win.el was used for
4490 x-parse-geometry even in non-NS builds.
4492 With two definitions of x-parse-geometry in this file, various
4493 things still get confused (eg M-x apropos documentation), so that
4494 it is best if the two definitions just share the same doc-string.
4496 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4497 doc: /* Parse a display geometry string STRING.
4498 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4499 The properties returned may include `top', `left', `height', and `width'.
4500 For X, the value of `left' or `top' may be an integer,
4501 or a list (+ N) meaning N pixels relative to top/left corner,
4502 or a list (- N) meaning -N pixels relative to bottom/right corner.
4503 On Nextstep, this just calls `ns-parse-geometry'. */)
4504 (Lisp_Object string)
4506 int geometry, x, y;
4507 unsigned int width, height;
4508 Lisp_Object result;
4510 CHECK_STRING (string);
4512 #ifdef HAVE_NS
4513 if (strchr (SSDATA (string), ' ') != NULL)
4514 return call1 (Qns_parse_geometry, string);
4515 #endif
4516 geometry = XParseGeometry (SSDATA (string),
4517 &x, &y, &width, &height);
4518 result = Qnil;
4519 if (geometry & XValue)
4521 Lisp_Object element;
4523 if (x >= 0 && (geometry & XNegative))
4524 element = list3 (Qleft, Qminus, make_number (-x));
4525 else if (x < 0 && ! (geometry & XNegative))
4526 element = list3 (Qleft, Qplus, make_number (x));
4527 else
4528 element = Fcons (Qleft, make_number (x));
4529 result = Fcons (element, result);
4532 if (geometry & YValue)
4534 Lisp_Object element;
4536 if (y >= 0 && (geometry & YNegative))
4537 element = list3 (Qtop, Qminus, make_number (-y));
4538 else if (y < 0 && ! (geometry & YNegative))
4539 element = list3 (Qtop, Qplus, make_number (y));
4540 else
4541 element = Fcons (Qtop, make_number (y));
4542 result = Fcons (element, result);
4545 if (geometry & WidthValue)
4546 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4547 if (geometry & HeightValue)
4548 result = Fcons (Fcons (Qheight, make_number (height)), result);
4550 return result;
4554 /* Calculate the desired size and position of frame F.
4555 Return the flags saying which aspects were specified.
4557 Also set the win_gravity and size_hint_flags of F.
4559 Adjust height for toolbar if TOOLBAR_P is 1.
4561 This function does not make the coordinates positive. */
4563 #define DEFAULT_ROWS 36
4564 #define DEFAULT_COLS 80
4566 long
4567 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
4569 Lisp_Object height, width, user_size, top, left, user_position;
4570 long window_prompting = 0;
4571 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4573 /* Default values if we fall through.
4574 Actually, if that happens we should get
4575 window manager prompting. */
4576 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4577 SET_FRAME_COLS (f, DEFAULT_COLS);
4578 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4579 SET_FRAME_LINES (f, DEFAULT_ROWS);
4581 /* Window managers expect that if program-specified
4582 positions are not (0,0), they're intentional, not defaults. */
4583 f->top_pos = 0;
4584 f->left_pos = 0;
4586 /* Calculate a tool bar height so that the user gets a text display
4587 area of the size he specified with -g or via .Xdefaults. Later
4588 changes of the tool bar height don't change the frame size. This
4589 is done so that users can create tall Emacs frames without having
4590 to guess how tall the tool bar will get. */
4591 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4593 if (frame_default_tool_bar_height)
4594 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
4595 else
4597 int margin, relief;
4599 relief = (tool_bar_button_relief >= 0
4600 ? tool_bar_button_relief
4601 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4603 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4604 margin = XFASTINT (Vtool_bar_button_margin);
4605 else if (CONSP (Vtool_bar_button_margin)
4606 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4607 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4608 else
4609 margin = 0;
4611 FRAME_TOOL_BAR_HEIGHT (f)
4612 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4616 /* Ensure that earlier new_width and new_height settings won't
4617 override what we specify below. */
4618 f->new_width = f->new_height = 0;
4620 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4621 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4622 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4624 if (!EQ (width, Qunbound))
4626 if (CONSP (width) && EQ (XCAR (width), Qtext_pixels))
4628 CHECK_NUMBER (XCDR (width));
4629 if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX))
4630 xsignal1 (Qargs_out_of_range, XCDR (width));
4632 SET_FRAME_WIDTH (f, XINT (XCDR (width)));
4633 f->inhibit_horizontal_resize = true;
4634 *x_width = XINT (XCDR (width));
4636 else
4638 CHECK_NUMBER (width);
4639 if ((XINT (width) < 0 || XINT (width) > INT_MAX))
4640 xsignal1 (Qargs_out_of_range, width);
4642 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4646 if (!EQ (height, Qunbound))
4648 if (CONSP (height) && EQ (XCAR (height), Qtext_pixels))
4650 CHECK_NUMBER (XCDR (height));
4651 if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX))
4652 xsignal1 (Qargs_out_of_range, XCDR (height));
4654 SET_FRAME_HEIGHT (f, XINT (XCDR (height)));
4655 f->inhibit_vertical_resize = true;
4656 *x_height = XINT (XCDR (height));
4658 else
4660 CHECK_NUMBER (height);
4661 if ((XINT (height) < 0) || (XINT (height) > INT_MAX))
4662 xsignal1 (Qargs_out_of_range, height);
4664 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4668 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4669 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4670 window_prompting |= USSize;
4671 else
4672 window_prompting |= PSize;
4675 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4676 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4677 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4678 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4680 if (EQ (top, Qminus))
4682 f->top_pos = 0;
4683 window_prompting |= YNegative;
4685 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4686 && CONSP (XCDR (top))
4687 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4689 f->top_pos = - XINT (XCAR (XCDR (top)));
4690 window_prompting |= YNegative;
4692 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4693 && CONSP (XCDR (top))
4694 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4696 f->top_pos = XINT (XCAR (XCDR (top)));
4698 else if (EQ (top, Qunbound))
4699 f->top_pos = 0;
4700 else
4702 CHECK_TYPE_RANGED_INTEGER (int, top);
4703 f->top_pos = XINT (top);
4704 if (f->top_pos < 0)
4705 window_prompting |= YNegative;
4708 if (EQ (left, Qminus))
4710 f->left_pos = 0;
4711 window_prompting |= XNegative;
4713 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4714 && CONSP (XCDR (left))
4715 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4717 f->left_pos = - XINT (XCAR (XCDR (left)));
4718 window_prompting |= XNegative;
4720 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4721 && CONSP (XCDR (left))
4722 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4724 f->left_pos = XINT (XCAR (XCDR (left)));
4726 else if (EQ (left, Qunbound))
4727 f->left_pos = 0;
4728 else
4730 CHECK_TYPE_RANGED_INTEGER (int, left);
4731 f->left_pos = XINT (left);
4732 if (f->left_pos < 0)
4733 window_prompting |= XNegative;
4736 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4737 window_prompting |= USPosition;
4738 else
4739 window_prompting |= PPosition;
4742 if (window_prompting & XNegative)
4744 if (window_prompting & YNegative)
4745 f->win_gravity = SouthEastGravity;
4746 else
4747 f->win_gravity = NorthEastGravity;
4749 else
4751 if (window_prompting & YNegative)
4752 f->win_gravity = SouthWestGravity;
4753 else
4754 f->win_gravity = NorthWestGravity;
4757 f->size_hint_flags = window_prompting;
4759 return window_prompting;
4764 #endif /* HAVE_WINDOW_SYSTEM */
4766 void
4767 frame_make_pointer_invisible (struct frame *f)
4769 if (! NILP (Vmake_pointer_invisible))
4771 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4772 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4774 f->mouse_moved = 0;
4775 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4776 f->pointer_invisible = 1;
4781 void
4782 frame_make_pointer_visible (struct frame *f)
4784 /* We don't check Vmake_pointer_invisible here in case the
4785 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4786 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4787 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4789 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4790 f->pointer_invisible = 0;
4794 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4795 Sframe_pointer_visible_p, 0, 1, 0,
4796 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4797 Otherwise it returns nil. FRAME omitted or nil means the
4798 selected frame. This is useful when `make-pointer-invisible' is set. */)
4799 (Lisp_Object frame)
4801 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4806 /***********************************************************************
4807 Multimonitor data
4808 ***********************************************************************/
4810 #ifdef HAVE_WINDOW_SYSTEM
4812 # if (defined HAVE_NS \
4813 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4814 void
4815 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4817 int i;
4818 for (i = 0; i < n_monitors; ++i)
4819 xfree (monitors[i].name);
4820 xfree (monitors);
4822 # endif
4824 Lisp_Object
4825 make_monitor_attribute_list (struct MonitorInfo *monitors,
4826 int n_monitors,
4827 int primary_monitor,
4828 Lisp_Object monitor_frames,
4829 const char *source)
4831 Lisp_Object attributes_list = Qnil;
4832 Lisp_Object primary_monitor_attributes = Qnil;
4833 int i;
4835 for (i = 0; i < n_monitors; ++i)
4837 Lisp_Object geometry, workarea, attributes = Qnil;
4838 struct MonitorInfo *mi = &monitors[i];
4840 if (mi->geom.width == 0) continue;
4842 workarea = list4i (mi->work.x, mi->work.y,
4843 mi->work.width, mi->work.height);
4844 geometry = list4i (mi->geom.x, mi->geom.y,
4845 mi->geom.width, mi->geom.height);
4846 attributes = Fcons (Fcons (Qsource, build_string (source)),
4847 attributes);
4848 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4849 attributes);
4850 attributes = Fcons (Fcons (Qmm_size,
4851 list2i (mi->mm_width, mi->mm_height)),
4852 attributes);
4853 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4854 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4855 if (mi->name)
4856 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4857 strlen (mi->name))),
4858 attributes);
4860 if (i == primary_monitor)
4861 primary_monitor_attributes = attributes;
4862 else
4863 attributes_list = Fcons (attributes, attributes_list);
4866 if (!NILP (primary_monitor_attributes))
4867 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4868 return attributes_list;
4871 #endif /* HAVE_WINDOW_SYSTEM */
4874 /***********************************************************************
4875 Initialization
4876 ***********************************************************************/
4878 void
4879 syms_of_frame (void)
4881 DEFSYM (Qframep, "framep");
4882 DEFSYM (Qframe_live_p, "frame-live-p");
4883 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4884 DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total");
4885 DEFSYM (Qexplicit_name, "explicit-name");
4886 DEFSYM (Qheight, "height");
4887 DEFSYM (Qicon, "icon");
4888 DEFSYM (Qminibuffer, "minibuffer");
4889 DEFSYM (Qmodeline, "modeline");
4890 DEFSYM (Qonly, "only");
4891 DEFSYM (Qnone, "none");
4892 DEFSYM (Qwidth, "width");
4893 DEFSYM (Qtext_pixels, "text-pixels");
4894 DEFSYM (Qgeometry, "geometry");
4895 DEFSYM (Qicon_left, "icon-left");
4896 DEFSYM (Qicon_top, "icon-top");
4897 DEFSYM (Qtooltip, "tooltip");
4898 DEFSYM (Quser_position, "user-position");
4899 DEFSYM (Quser_size, "user-size");
4900 DEFSYM (Qwindow_id, "window-id");
4901 #ifdef HAVE_X_WINDOWS
4902 DEFSYM (Qouter_window_id, "outer-window-id");
4903 #endif
4904 DEFSYM (Qparent_id, "parent-id");
4905 DEFSYM (Qx, "x");
4906 DEFSYM (Qw32, "w32");
4907 DEFSYM (Qpc, "pc");
4908 DEFSYM (Qns, "ns");
4909 DEFSYM (Qvisible, "visible");
4910 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4911 DEFSYM (Qbuffer_list, "buffer-list");
4912 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4913 DEFSYM (Qdisplay_type, "display-type");
4914 DEFSYM (Qbackground_mode, "background-mode");
4915 DEFSYM (Qnoelisp, "noelisp");
4916 DEFSYM (Qtty_color_mode, "tty-color-mode");
4917 DEFSYM (Qtty, "tty");
4918 DEFSYM (Qtty_type, "tty-type");
4920 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4922 DEFSYM (Qfullwidth, "fullwidth");
4923 DEFSYM (Qfullheight, "fullheight");
4924 DEFSYM (Qfullboth, "fullboth");
4925 DEFSYM (Qmaximized, "maximized");
4926 DEFSYM (Qx_resource_name, "x-resource-name");
4927 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4929 DEFSYM (Qterminal, "terminal");
4931 DEFSYM (Qworkarea, "workarea");
4932 DEFSYM (Qmm_size, "mm-size");
4933 DEFSYM (Qframes, "frames");
4934 DEFSYM (Qsource, "source");
4936 DEFSYM (Qouter_edges, "outer-edges");
4937 DEFSYM (Qouter_position, "outer-position");
4938 DEFSYM (Qouter_size, "outer-size");
4939 DEFSYM (Qnative_edges, "native-edges");
4940 DEFSYM (Qinner_edges, "inner-edges");
4941 DEFSYM (Qexternal_border_size, "external-border-size");
4942 DEFSYM (Qtitle_bar_size, "title-bar-size");
4943 DEFSYM (Qmenu_bar_external, "menu-bar-external");
4944 DEFSYM (Qmenu_bar_size, "menu-bar-size");
4945 DEFSYM (Qtool_bar_external, "tool-bar-external");
4946 DEFSYM (Qtool_bar_size, "tool-bar-size");
4947 /* The following are used for frame_size_history. */
4948 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
4949 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
4950 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
4951 DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
4952 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
4953 DEFSYM (Qset_frame_size, "set-frame-size");
4954 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
4955 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
4956 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
4957 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
4958 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
4959 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
4960 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
4961 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
4962 DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
4963 DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
4964 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
4965 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
4966 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
4967 DEFSYM (Qtb_size_cb, "tb-size-cb");
4968 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
4969 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
4970 DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines");
4971 DEFSYM (Qchange_frame_size, "change-frame-size");
4972 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
4973 DEFSYM (Qset_window_configuration, "set-window-configuration");
4974 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
4975 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
4976 DEFSYM (Qterminal_frame, "terminal-frame");
4978 #ifdef HAVE_NS
4979 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4980 #endif
4982 DEFSYM (Qalpha, "alpha");
4983 DEFSYM (Qauto_lower, "auto-lower");
4984 DEFSYM (Qauto_raise, "auto-raise");
4985 DEFSYM (Qborder_color, "border-color");
4986 DEFSYM (Qborder_width, "border-width");
4987 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
4988 DEFSYM (Qcursor_color, "cursor-color");
4989 DEFSYM (Qcursor_type, "cursor-type");
4990 DEFSYM (Qfont_backend, "font-backend");
4991 DEFSYM (Qfullscreen, "fullscreen");
4992 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
4993 DEFSYM (Qicon_name, "icon-name");
4994 DEFSYM (Qicon_type, "icon-type");
4995 DEFSYM (Qinternal_border_width, "internal-border-width");
4996 DEFSYM (Qleft_fringe, "left-fringe");
4997 DEFSYM (Qline_spacing, "line-spacing");
4998 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
4999 DEFSYM (Qupdate_frame_menubar, "update-frame-menubar");
5000 DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1");
5001 DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2");
5002 DEFSYM (Qmouse_color, "mouse-color");
5003 DEFSYM (Qname, "name");
5004 DEFSYM (Qright_divider_width, "right-divider-width");
5005 DEFSYM (Qright_fringe, "right-fringe");
5006 DEFSYM (Qscreen_gamma, "screen-gamma");
5007 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
5008 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
5009 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
5010 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
5011 DEFSYM (Qsticky, "sticky");
5012 DEFSYM (Qtitle, "title");
5013 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
5014 DEFSYM (Qtool_bar_position, "tool-bar-position");
5015 DEFSYM (Qunsplittable, "unsplittable");
5016 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
5017 DEFSYM (Qvisibility, "visibility");
5018 DEFSYM (Qwait_for_wm, "wait-for-wm");
5019 DEFSYM (Qinhibit_double_buffering, "inhibit-double-buffering");
5022 int i;
5024 for (i = 0; i < ARRAYELTS (frame_parms); i++)
5026 Lisp_Object v = (frame_parms[i].sym < 0
5027 ? intern_c_string (frame_parms[i].name)
5028 : builtin_lisp_symbol (frame_parms[i].sym));
5029 Fput (v, Qx_frame_parameter, make_number (i));
5033 #ifdef HAVE_WINDOW_SYSTEM
5034 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
5035 doc: /* The name Emacs uses to look up X resources.
5036 `x-get-resource' uses this as the first component of the instance name
5037 when requesting resource values.
5038 Emacs initially sets `x-resource-name' to the name under which Emacs
5039 was invoked, or to the value specified with the `-name' or `-rn'
5040 switches, if present.
5042 It may be useful to bind this variable locally around a call
5043 to `x-get-resource'. See also the variable `x-resource-class'. */);
5044 Vx_resource_name = Qnil;
5046 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5047 doc: /* The class Emacs uses to look up X resources.
5048 `x-get-resource' uses this as the first component of the instance class
5049 when requesting resource values.
5051 Emacs initially sets `x-resource-class' to "Emacs".
5053 Setting this variable permanently is not a reasonable thing to do,
5054 but binding this variable locally around a call to `x-get-resource'
5055 is a reasonable practice. See also the variable `x-resource-name'. */);
5056 Vx_resource_class = build_string (EMACS_CLASS);
5058 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5059 doc: /* The lower limit of the frame opacity (alpha transparency).
5060 The value should range from 0 (invisible) to 100 (completely opaque).
5061 You can also use a floating number between 0.0 and 1.0. */);
5062 Vframe_alpha_lower_limit = make_number (20);
5063 #endif
5065 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5066 doc: /* Alist of default values for frame creation.
5067 These may be set in your init file, like this:
5068 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5069 These override values given in window system configuration data,
5070 including X Windows' defaults database.
5071 For values specific to the first Emacs frame, see `initial-frame-alist'.
5072 For window-system specific values, see `window-system-default-frame-alist'.
5073 For values specific to the separate minibuffer frame, see
5074 `minibuffer-frame-alist'.
5075 The `menu-bar-lines' element of the list controls whether new frames
5076 have menu bars; `menu-bar-mode' works by altering this element.
5077 Setting this variable does not affect existing frames, only new ones. */);
5078 Vdefault_frame_alist = Qnil;
5080 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5081 doc: /* Default position of vertical scroll bars on this window-system. */);
5082 #ifdef HAVE_WINDOW_SYSTEM
5083 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5084 /* MS-Windows, macOS, and GTK have scroll bars on the right by
5085 default. */
5086 Vdefault_frame_scroll_bars = Qright;
5087 #else
5088 Vdefault_frame_scroll_bars = Qleft;
5089 #endif
5090 #else
5091 Vdefault_frame_scroll_bars = Qnil;
5092 #endif
5094 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5095 scroll_bar_adjust_thumb_portion_p,
5096 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5097 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5098 even if the end of the buffer is shown (i.e. overscrolling).
5099 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5100 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5101 is visible. In this case you can not overscroll. */);
5102 scroll_bar_adjust_thumb_portion_p = 1;
5104 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5105 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5107 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5108 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5109 `mouse-position' and `mouse-pixel-position' call this function, passing their
5110 usual return value as argument, and return whatever this function returns.
5111 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5112 which need to do mouse handling at the Lisp level. */);
5113 Vmouse_position_function = Qnil;
5115 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5116 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5117 If the value is an integer, highlighting is only shown after moving the
5118 mouse, while keyboard input turns off the highlight even when the mouse
5119 is over the clickable text. However, the mouse shape still indicates
5120 when the mouse is over clickable text. */);
5121 Vmouse_highlight = Qt;
5123 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5124 doc: /* If non-nil, make pointer invisible while typing.
5125 The pointer becomes visible again when the mouse is moved. */);
5126 Vmake_pointer_invisible = Qt;
5128 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5129 doc: /* Normal hook run when a frame gains input focus. */);
5130 Vfocus_in_hook = Qnil;
5132 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5133 doc: /* Normal hook run when a frame loses input focus. */);
5134 Vfocus_out_hook = Qnil;
5136 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5137 doc: /* Functions run before deleting a frame.
5138 The functions are run with one arg, the frame to be deleted.
5139 See `delete-frame'.
5141 Note that functions in this list may be called just before the frame is
5142 actually deleted, or some time later (or even both when an earlier function
5143 in `delete-frame-functions' (indirectly) calls `delete-frame'
5144 recursively). */);
5145 Vdelete_frame_functions = Qnil;
5146 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5148 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5149 doc: /* Non-nil if Menu-Bar mode is enabled.
5150 See the command `menu-bar-mode' for a description of this minor mode.
5151 Setting this variable directly does not take effect;
5152 either customize it (see the info node `Easy Customization')
5153 or call the function `menu-bar-mode'. */);
5154 Vmenu_bar_mode = Qt;
5156 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5157 doc: /* Non-nil if Tool-Bar mode is enabled.
5158 See the command `tool-bar-mode' for a description of this minor mode.
5159 Setting this variable directly does not take effect;
5160 either customize it (see the info node `Easy Customization')
5161 or call the function `tool-bar-mode'. */);
5162 #ifdef HAVE_WINDOW_SYSTEM
5163 Vtool_bar_mode = Qt;
5164 #else
5165 Vtool_bar_mode = Qnil;
5166 #endif
5168 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5169 doc: /* Minibufferless frames use this frame's minibuffer.
5170 Emacs cannot create minibufferless frames unless this is set to an
5171 appropriate surrogate.
5173 Emacs consults this variable only when creating minibufferless
5174 frames; once the frame is created, it sticks with its assigned
5175 minibuffer, no matter what this variable is set to. This means that
5176 this variable doesn't necessarily say anything meaningful about the
5177 current set of frames, or where the minibuffer is currently being
5178 displayed.
5180 This variable is local to the current terminal and cannot be buffer-local. */);
5182 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
5183 doc: /* Non-nil if window system changes focus when you move the mouse.
5184 You should set this variable to tell Emacs how your window manager
5185 handles focus, since there is no way in general for Emacs to find out
5186 automatically. See also `mouse-autoselect-window'. */);
5187 focus_follows_mouse = 0;
5189 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5190 doc: /* Non-nil means resize frames pixelwise.
5191 If this option is nil, resizing a frame rounds its sizes to the frame's
5192 current values of `frame-char-height' and `frame-char-width'. If this
5193 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5194 by one pixel.
5196 With some window managers you may have to set this to non-nil in order
5197 to set the size of a frame in pixels, to maximize frames or to make them
5198 fullscreen. To resize your initial frame pixelwise, set this option to
5199 a non-nil value in your init file. */);
5200 frame_resize_pixelwise = 0;
5202 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5203 doc: /* Whether frames should be resized implicitly.
5204 If this option is nil, setting font, menu bar, tool bar, internal
5205 borders, fringes or scroll bars of a specific frame may resize the frame
5206 in order to preserve the number of columns or lines it displays. If
5207 this option is t, no such resizing is done. Note that the size of
5208 fullscreen and maximized frames, the height of fullheight frames and the
5209 width of fullwidth frames never change implicitly.
5211 The value of this option can be also be a list of frame parameters. In
5212 this case, resizing is inhibited when changing a parameter that appears
5213 in that list. The parameters currently handled by this option include
5214 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5215 `tool-bar-lines'.
5217 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5218 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5219 `right-fringe' is handled as if the frame contained just one live
5220 window. This means, for example, that removing vertical scroll bars on
5221 a frame containing several side by side windows will shrink the frame
5222 width by the width of one scroll bar provided this option is nil and
5223 keep it unchanged if this option is either t or a list containing
5224 `vertical-scroll-bars'.
5226 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
5227 \(which means that adding/removing a tool bar does not change the frame
5228 height), nil on all other window systems including GTK+ (which means
5229 that changing any of the parameters listed above may change the size of
5230 the frame), and t otherwise (which means the frame size never changes
5231 implicitly when there's no window system support).
5233 Note that when a frame is not large enough to accommodate a change of
5234 any of the parameters listed above, Emacs may try to enlarge the frame
5235 even if this option is non-nil. */);
5236 #if defined (HAVE_WINDOW_SYSTEM)
5237 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
5238 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
5239 #else
5240 frame_inhibit_implied_resize = Qnil;
5241 #endif
5242 #else
5243 frame_inhibit_implied_resize = Qt;
5244 #endif
5246 DEFVAR_LISP ("frame-size-history", frame_size_history,
5247 doc: /* History of frame size adjustments.
5248 If non-nil, list recording frame size adjustment. Adjustments are
5249 recorded only if the first element of this list is a positive number.
5250 Adding an adjustment decrements that number by one.
5252 The remaining elements are the adjustments. Each adjustment is a list
5253 of four elements `frame', `function', `sizes' and `more'. `frame' is
5254 the affected frame and `function' the invoking function. `sizes' is
5255 usually a list of four elements `old-width', `old-height', `new-width'
5256 and `new-height' representing the old and new sizes recorded/requested
5257 by `function'. `more' is a list with additional information.
5259 The function `frame--size-history' displays the value of this variable
5260 in a more readable form. */);
5261 frame_size_history = Qnil;
5263 DEFVAR_BOOL ("tooltip-reuse-hidden-frame", tooltip_reuse_hidden_frame,
5264 doc: /* Non-nil means reuse hidden tooltip frames.
5265 When this is nil, delete a tooltip frame when hiding the associated
5266 tooltip. When this is non-nil, make the tooltip frame invisible only,
5267 so it can be reused when the next tooltip is shown.
5269 Setting this to non-nil may drastically reduce the consing overhead
5270 incurred by creating new tooltip frames. However, a value of non-nil
5271 means also that intermittent changes of faces or `default-frame-alist'
5272 are not applied when showing a tooltip in a reused frame.
5274 This variable is effective only with the X toolkit (and there only when
5275 Gtk+ tooltips are not used) and on Windows. */);
5276 tooltip_reuse_hidden_frame = false;
5278 staticpro (&Vframe_list);
5280 defsubr (&Sframep);
5281 defsubr (&Sframe_live_p);
5282 defsubr (&Swindow_system);
5283 defsubr (&Sframe_windows_min_size);
5284 defsubr (&Smake_terminal_frame);
5285 defsubr (&Shandle_switch_frame);
5286 defsubr (&Sselect_frame);
5287 defsubr (&Sselected_frame);
5288 defsubr (&Sframe_list);
5289 defsubr (&Snext_frame);
5290 defsubr (&Sprevious_frame);
5291 defsubr (&Slast_nonminibuf_frame);
5292 defsubr (&Sdelete_frame);
5293 defsubr (&Smouse_position);
5294 defsubr (&Smouse_pixel_position);
5295 defsubr (&Sset_mouse_position);
5296 defsubr (&Sset_mouse_pixel_position);
5297 #if 0
5298 defsubr (&Sframe_configuration);
5299 defsubr (&Srestore_frame_configuration);
5300 #endif
5301 defsubr (&Smake_frame_visible);
5302 defsubr (&Smake_frame_invisible);
5303 defsubr (&Siconify_frame);
5304 defsubr (&Sframe_visible_p);
5305 defsubr (&Svisible_frame_list);
5306 defsubr (&Sraise_frame);
5307 defsubr (&Slower_frame);
5308 defsubr (&Sx_focus_frame);
5309 defsubr (&Sframe_after_make_frame);
5310 defsubr (&Sredirect_frame_focus);
5311 defsubr (&Sframe_focus);
5312 defsubr (&Sframe_parameters);
5313 defsubr (&Sframe_parameter);
5314 defsubr (&Smodify_frame_parameters);
5315 defsubr (&Sframe_char_height);
5316 defsubr (&Sframe_char_width);
5317 defsubr (&Sframe_pixel_height);
5318 defsubr (&Sframe_pixel_width);
5319 defsubr (&Sframe_text_cols);
5320 defsubr (&Sframe_text_lines);
5321 defsubr (&Sframe_total_cols);
5322 defsubr (&Sframe_total_lines);
5323 defsubr (&Sframe_text_width);
5324 defsubr (&Sframe_text_height);
5325 defsubr (&Sscroll_bar_width);
5326 defsubr (&Sscroll_bar_height);
5327 defsubr (&Sfringe_width);
5328 defsubr (&Sborder_width);
5329 defsubr (&Sright_divider_width);
5330 defsubr (&Sbottom_divider_width);
5331 defsubr (&Stool_bar_pixel_width);
5332 defsubr (&Sset_frame_height);
5333 defsubr (&Sset_frame_width);
5334 defsubr (&Sset_frame_size);
5335 defsubr (&Sframe_position);
5336 defsubr (&Sset_frame_position);
5337 defsubr (&Sframe_pointer_visible_p);
5339 #ifdef HAVE_WINDOW_SYSTEM
5340 defsubr (&Sx_get_resource);
5341 defsubr (&Sx_parse_geometry);
5342 #endif