Merge from emacs-24
[emacs.git] / src / frame.c
blobd56b11d962c857a57cdf5abf6a561de17ec5bfdd
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2014 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <errno.h>
24 #include <limits.h>
26 #include <c-ctype.h>
28 #include "lisp.h"
29 #include "character.h"
31 #ifdef HAVE_WINDOW_SYSTEM
32 #include TERM_HEADER
33 #endif /* HAVE_WINDOW_SYSTEM */
35 #include "buffer.h"
36 /* These help us bind and responding to switch-frame events. */
37 #include "commands.h"
38 #include "keyboard.h"
39 #include "frame.h"
40 #include "blockinput.h"
41 #include "termchar.h"
42 #include "termhooks.h"
43 #include "dispextern.h"
44 #include "window.h"
45 #include "font.h"
46 #ifdef HAVE_WINDOW_SYSTEM
47 #include "fontset.h"
48 #endif
49 #include "cm.h"
50 #ifdef MSDOS
51 #include "msdos.h"
52 #include "dosfns.h"
53 #endif
54 #ifdef USE_X_TOOLKIT
55 #include "widget.h"
56 #endif
58 #ifdef HAVE_NS
59 Lisp_Object Qns_parse_geometry;
60 #endif
62 Lisp_Object Qframep, Qframe_live_p;
63 Lisp_Object Qicon, Qmodeline;
64 Lisp_Object Qonly, Qnone;
65 Lisp_Object Qx, Qw32, Qpc, Qns;
66 Lisp_Object Qvisible;
67 Lisp_Object Qdisplay_type;
68 static Lisp_Object Qbackground_mode;
69 Lisp_Object Qnoelisp;
71 static Lisp_Object Qx_frame_parameter;
72 Lisp_Object Qx_resource_name;
73 Lisp_Object Qterminal;
75 /* Frame parameters (set or reported). */
77 Lisp_Object Qauto_raise, Qauto_lower;
78 Lisp_Object Qborder_color, Qborder_width;
79 Lisp_Object Qcursor_color, Qcursor_type;
80 Lisp_Object Qheight, Qwidth;
81 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
82 Lisp_Object Qtooltip;
83 Lisp_Object Qinternal_border_width;
84 Lisp_Object Qright_divider_width, Qbottom_divider_width;
85 Lisp_Object Qmouse_color;
86 Lisp_Object Qminibuffer;
87 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
88 Lisp_Object Qscroll_bar_height, Qhorizontal_scroll_bars;
89 Lisp_Object Qvisibility;
90 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
91 Lisp_Object Qscreen_gamma;
92 Lisp_Object Qline_spacing;
93 static Lisp_Object Quser_position, Quser_size;
94 Lisp_Object Qwait_for_wm;
95 static Lisp_Object Qwindow_id;
96 #ifdef HAVE_X_WINDOWS
97 static Lisp_Object Qouter_window_id;
98 #endif
99 Lisp_Object Qparent_id;
100 Lisp_Object Qtitle, Qname;
101 static Lisp_Object Qexplicit_name;
102 Lisp_Object Qunsplittable;
103 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines, Qtool_bar_position;
104 Lisp_Object Qleft_fringe, Qright_fringe;
105 Lisp_Object Qbuffer_predicate;
106 static Lisp_Object Qbuffer_list, Qburied_buffer_list;
107 Lisp_Object Qtty_color_mode;
108 Lisp_Object Qtty, Qtty_type;
110 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth, Qmaximized;
111 Lisp_Object Qsticky;
112 Lisp_Object Qfont_backend;
113 Lisp_Object Qalpha;
115 Lisp_Object Qface_set_after_frame_default;
117 static Lisp_Object Qfocus_in_hook;
118 static Lisp_Object Qfocus_out_hook;
119 static Lisp_Object Qdelete_frame_functions;
120 static Lisp_Object Qframe_windows_min_size;
121 static Lisp_Object Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource;
123 /* The currently selected frame. */
125 Lisp_Object selected_frame;
127 /* A frame which is not just a mini-buffer, or NULL if there are no such
128 frames. This is usually the most recent such frame that was selected. */
130 static struct frame *last_nonminibuf_frame;
132 /* False means there are no visible garbaged frames. */
133 bool frame_garbaged;
135 #ifdef HAVE_WINDOW_SYSTEM
136 static void x_report_frame_params (struct frame *, Lisp_Object *);
137 #endif
139 /* These setters are used only in this file, so they can be private. */
140 static void
141 fset_buffer_predicate (struct frame *f, Lisp_Object val)
143 f->buffer_predicate = val;
145 static void
146 fset_minibuffer_window (struct frame *f, Lisp_Object val)
148 f->minibuffer_window = val;
151 struct frame *
152 decode_live_frame (register Lisp_Object frame)
154 if (NILP (frame))
155 frame = selected_frame;
156 CHECK_LIVE_FRAME (frame);
157 return XFRAME (frame);
160 struct frame *
161 decode_any_frame (register Lisp_Object frame)
163 if (NILP (frame))
164 frame = selected_frame;
165 CHECK_FRAME (frame);
166 return XFRAME (frame);
169 #ifdef HAVE_WINDOW_SYSTEM
171 bool
172 window_system_available (struct frame *f)
174 return f ? FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f) : x_display_list != NULL;
177 #endif /* HAVE_WINDOW_SYSTEM */
179 struct frame *
180 decode_window_system_frame (Lisp_Object frame)
182 struct frame *f = decode_live_frame (frame);
184 if (!window_system_available (f))
185 error ("Window system frame should be used");
186 return f;
189 void
190 check_window_system (struct frame *f)
192 if (!window_system_available (f))
193 error (f ? "Window system frame should be used"
194 : "Window system is not in use or not initialized");
197 /* Return the value of frame parameter PROP in frame FRAME. */
199 Lisp_Object
200 get_frame_param (register struct frame *frame, Lisp_Object prop)
202 register Lisp_Object tem;
204 tem = Fassq (prop, frame->param_alist);
205 if (EQ (tem, Qnil))
206 return tem;
207 return Fcdr (tem);
210 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
211 state of frame F would be affected by a vertical (horizontal if
212 HORIZONTAL is true) resize. */
213 bool
214 frame_inhibit_resize (struct frame *f, bool horizontal)
217 return (frame_inhibit_implied_resize
218 || !NILP (get_frame_param (f, Qfullscreen))
219 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f));
222 #if 0
223 bool
224 frame_inhibit_resize (struct frame *f, bool horizontal)
226 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
228 return (frame_inhibit_implied_resize
229 || EQ (fullscreen, Qfullboth)
230 || EQ (fullscreen, Qfullscreen)
231 || EQ (fullscreen, Qmaximized)
232 || (horizontal && EQ (fullscreen, Qfullwidth))
233 || (!horizontal && EQ (fullscreen, Qfullheight)));
235 #endif
237 static void
238 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
240 int nlines;
241 int olines = FRAME_MENU_BAR_LINES (f);
243 /* Right now, menu bars don't work properly in minibuf-only frames;
244 most of the commands try to apply themselves to the minibuffer
245 frame itself, and get an error because you can't switch buffers
246 in or split the minibuffer window. */
247 if (FRAME_MINIBUF_ONLY_P (f))
248 return;
250 if (TYPE_RANGED_INTEGERP (int, value))
251 nlines = XINT (value);
252 else
253 nlines = 0;
255 if (nlines != olines)
257 windows_or_buffers_changed = 14;
258 FRAME_MENU_BAR_LINES (f) = nlines;
259 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
260 change_frame_size (f, FRAME_COLS (f),
261 FRAME_LINES (f) + olines - nlines,
262 0, 1, 0, 0);
266 Lisp_Object Vframe_list;
269 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
270 doc: /* Return non-nil if OBJECT is a frame.
271 Value is:
272 t for a termcap frame (a character-only terminal),
273 'x' for an Emacs frame that is really an X window,
274 'w32' for an Emacs frame that is a window on MS-Windows display,
275 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
276 'pc' for a direct-write MS-DOS frame.
277 See also `frame-live-p'. */)
278 (Lisp_Object object)
280 if (!FRAMEP (object))
281 return Qnil;
282 switch (XFRAME (object)->output_method)
284 case output_initial: /* The initial frame is like a termcap frame. */
285 case output_termcap:
286 return Qt;
287 case output_x_window:
288 return Qx;
289 case output_w32:
290 return Qw32;
291 case output_msdos_raw:
292 return Qpc;
293 case output_ns:
294 return Qns;
295 default:
296 emacs_abort ();
300 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
301 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
302 Value is nil if OBJECT is not a live frame. If object is a live
303 frame, the return value indicates what sort of terminal device it is
304 displayed on. See the documentation of `framep' for possible
305 return values. */)
306 (Lisp_Object object)
308 return ((FRAMEP (object)
309 && FRAME_LIVE_P (XFRAME (object)))
310 ? Fframep (object)
311 : Qnil);
314 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
315 doc: /* The name of the window system that FRAME is displaying through.
316 The value is a symbol:
317 nil for a termcap frame (a character-only terminal),
318 'x' for an Emacs frame that is really an X window,
319 'w32' for an Emacs frame that is a window on MS-Windows display,
320 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
321 'pc' for a direct-write MS-DOS frame.
323 FRAME defaults to the currently selected frame.
325 Use of this function as a predicate is deprecated. Instead,
326 use `display-graphic-p' or any of the other `display-*-p'
327 predicates which report frame's specific UI-related capabilities. */)
328 (Lisp_Object frame)
330 Lisp_Object type;
331 if (NILP (frame))
332 frame = selected_frame;
334 type = Fframep (frame);
336 if (NILP (type))
337 wrong_type_argument (Qframep, frame);
339 if (EQ (type, Qt))
340 return Qnil;
341 else
342 return type;
345 static int
346 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal, Lisp_Object pixelwise)
348 return XINT (call3 (Qframe_windows_min_size, frame, horizontal, pixelwise));
352 /* Make sure windows sizes of frame F are OK. new_width and new_height
353 are in pixels. A value of -1 means no change is requested for that
354 size (but the frame may still have to be resized to accommodate
355 windows with their minimum sizes.
357 The argument INHIBIT can assume the following values:
359 0 means to unconditionally call x_set_window_size even if sizes
360 apparently do not change. Fx_create_frame uses this to pass the
361 initial size to the window manager.
363 1 means to call x_set_window_size iff the pixel size really changes.
364 Fset_frame_size, Fset_frame_height, ... use this.
366 2 means to unconditionally call x_set_window_size provided
367 frame_inhibit_resize allows it. The menu bar code uses this.
369 3 means call x_set_window_size iff window minimum sizes must be
370 preserved or frame_inhibit_resize allows it, x_set_left_fringe,
371 x_set_scroll_bar_width, ... use this.
373 4 means call x_set_window_size iff window minimum sizes must be
374 preserved. x_set_tool_bar_lines, x_set_right_divider_width, ... use
375 this. BUT maybe the toolbar code shouldn't ....
377 5 means to never call x_set_window_size. change_frame_size uses
378 this.
380 For 2 and 3 note that if frame_inhibit_resize inhibits resizing and
381 minimum sizes are not violated no internal resizing takes place
382 either. For 2, 3, 4 and 5 note that even if no x_set_window_size
383 call is issued, window sizes may have to be adjusted in order to
384 support minimum size constraints for the frame's windows.
386 PRETEND is as for change_frame_size. */
387 void
388 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit, bool pretend)
390 int unit_width = FRAME_COLUMN_WIDTH (f);
391 int unit_height = FRAME_LINE_HEIGHT (f);
392 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
393 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
394 int new_pixel_width, new_pixel_height;
395 /* The following two values are calculated from the old frame pixel
396 sizes and any "new" settings for tool bar, menu bar and internal
397 borders. We do it this way to detect whether we have to call
398 x_set_window_size as consequence of the new settings. */
399 int windows_width = FRAME_WINDOWS_WIDTH (f);
400 int windows_height = FRAME_WINDOWS_HEIGHT (f);
401 int min_windows_width, min_windows_height;
402 /* These are a bit tedious, maybe we should use a macro. */
403 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
404 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
405 int old_windows_height
406 = (WINDOW_PIXEL_HEIGHT (r)
407 + (FRAME_HAS_MINIBUF_P (f)
408 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
409 : 0));
410 int new_windows_width, new_windows_height;
411 int old_text_width = FRAME_TEXT_WIDTH (f);
412 int old_text_height = FRAME_TEXT_HEIGHT (f);
413 /* If a size is < 0 use the old value. */
414 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
415 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
416 int new_cols, new_lines;
417 bool inhibit_horizontal, inhibit_vertical;
418 Lisp_Object frame;
420 XSETFRAME (frame, f);
421 /* The following two values are calculated from the old window body
422 sizes and any "new" settings for scroll bars, dividers, fringes and
423 margins (though the latter should have been processed already). */
424 min_windows_width = frame_windows_min_size (frame, Qt, Qt);
425 min_windows_height = frame_windows_min_size (frame, Qnil, Qt);
427 if (inhibit >= 2 && inhibit <= 4)
428 /* If INHIBIT is in [2..4] inhibit if the "old" window sizes stay
429 within the limits and either frame_inhibit_resize tells us to do
430 so or INHIBIT equals 4. */
432 inhibit_horizontal = ((windows_width >= min_windows_width
433 && (inhibit == 4 || frame_inhibit_resize (f, true)))
434 ? true : false);
435 inhibit_vertical = ((windows_height >= min_windows_height
436 && (inhibit == 4 || frame_inhibit_resize (f, false)))
437 ? true : false);
439 else
440 /* Otherwise inhibit if INHIBIT equals 5. */
441 inhibit_horizontal = inhibit_vertical = inhibit == 5;
443 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
444 ? old_pixel_width
445 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
446 min_windows_width
447 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
448 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
449 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
450 new_cols = new_text_width / unit_width;
452 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
453 ? old_pixel_height
454 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
455 min_windows_height
456 + FRAME_TOP_MARGIN_HEIGHT (f)
457 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
458 new_windows_height = (new_pixel_height
459 - FRAME_TOP_MARGIN_HEIGHT (f)
460 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
461 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
462 new_lines = new_text_height / unit_height;
464 #ifdef HAVE_WINDOW_SYSTEM
465 if (FRAME_WINDOW_P (f)
466 && f->official
467 && ((!inhibit_horizontal
468 && (new_pixel_width != old_pixel_width
469 || inhibit == 0 || inhibit == 2))
470 || (!inhibit_vertical
471 && (new_pixel_height != old_pixel_height
472 || inhibit == 0 || inhibit == 2))))
473 /* We are either allowed to change the frame size or the minimum
474 sizes request such a change. Do not care for fixing minimum
475 sizes here, we do that eventually when we're called from
476 change_frame_size. */
478 /* Make sure we respect fullheight and fullwidth. */
479 if (inhibit_horizontal)
480 new_text_width = old_text_width;
481 else if (inhibit_vertical)
482 new_text_height = old_text_height;
484 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
485 f->resized_p = true;
487 return;
489 #endif
491 if (new_text_width == old_text_width
492 && new_text_height == old_text_height
493 && new_windows_width == old_windows_width
494 && new_windows_height == old_windows_height
495 && new_pixel_width == old_pixel_width
496 && new_pixel_height == old_pixel_height)
497 /* No change. Sanitize window sizes and return. */
499 sanitize_window_sizes (frame, Qt);
500 sanitize_window_sizes (frame, Qnil);
502 return;
505 block_input ();
507 #ifdef MSDOS
508 /* We only can set screen dimensions to certain values supported
509 by our video hardware. Try to find the smallest size greater
510 or equal to the requested dimensions. */
511 dos_set_window_size (&new_lines, &new_cols);
512 #endif
514 if (new_windows_width != old_windows_width)
516 resize_frame_windows (f, new_windows_width, 1, 1);
518 /* MSDOS frames cannot PRETEND, as they change frame size by
519 manipulating video hardware. */
520 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
521 FrameCols (FRAME_TTY (f)) = new_cols;
523 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
524 if (WINDOWP (f->tool_bar_window))
526 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
527 XWINDOW (f->tool_bar_window)->total_cols
528 = new_windows_width / unit_width;
530 #endif
533 if (new_windows_height != old_windows_height
534 /* When the top margin has changed we have to recalculate the top
535 edges of all windows. No such calculation is necessary for the
536 left edges. */
537 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
539 resize_frame_windows (f, new_windows_height, 0, 1);
541 /* MSDOS frames cannot PRETEND, as they change frame size by
542 manipulating video hardware. */
543 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
544 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
547 /* Assign new sizes. */
548 FRAME_TEXT_WIDTH (f) = new_text_width;
549 FRAME_TEXT_HEIGHT (f) = new_text_height;
550 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
551 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
552 SET_FRAME_COLS (f, new_cols);
553 SET_FRAME_LINES (f, new_lines);
556 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
557 int text_area_x, text_area_y, text_area_width, text_area_height;
559 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
560 &text_area_height);
561 if (w->cursor.x >= text_area_x + text_area_width)
562 w->cursor.hpos = w->cursor.x = 0;
563 if (w->cursor.y >= text_area_y + text_area_height)
564 w->cursor.vpos = w->cursor.y = 0;
567 /* Sanitize window sizes. */
568 sanitize_window_sizes (frame, Qt);
569 sanitize_window_sizes (frame, Qnil);
571 adjust_frame_glyphs (f);
572 calculate_costs (f);
573 SET_FRAME_GARBAGED (f);
575 /* A frame was "resized" if one of its pixelsizes changed, even if its
576 X window wasn't resized at all. */
577 f->resized_p = (new_pixel_width != old_pixel_width
578 || new_pixel_height != old_pixel_height);
580 unblock_input ();
582 run_window_configuration_change_hook (f);
586 struct frame *
587 make_frame (bool mini_p)
589 Lisp_Object frame;
590 register struct frame *f;
591 register struct window *rw, *mw;
592 register Lisp_Object root_window;
593 register Lisp_Object mini_window;
595 f = allocate_frame ();
596 XSETFRAME (frame, f);
598 #ifdef USE_GTK
599 /* Initialize Lisp data. Note that allocate_frame initializes all
600 Lisp data to nil, so do it only for slots which should not be nil. */
601 fset_tool_bar_position (f, Qtop);
602 #endif
604 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
605 non-Lisp data, so do it only for slots which should not be zero.
606 To avoid subtle bugs and for the sake of readability, it's better to
607 initialize enum members explicitly even if their values are zero. */
608 f->wants_modeline = true;
609 f->redisplay = true;
610 f->garbaged = true;
611 f->official = false;
612 f->column_width = 1; /* !FRAME_WINDOW_P value. */
613 f->line_height = 1; /* !FRAME_WINDOW_P value. */
614 #ifdef HAVE_WINDOW_SYSTEM
615 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
616 f->horizontal_scroll_bars = false;
617 f->want_fullscreen = FULLSCREEN_NONE;
618 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
619 f->last_tool_bar_item = -1;
620 #endif
621 #endif
623 root_window = make_window ();
624 rw = XWINDOW (root_window);
625 if (mini_p)
627 mini_window = make_window ();
628 mw = XWINDOW (mini_window);
629 wset_next (rw, mini_window);
630 wset_prev (mw, root_window);
631 mw->mini = 1;
632 wset_frame (mw, frame);
633 fset_minibuffer_window (f, mini_window);
635 else
637 mini_window = Qnil;
638 wset_next (rw, Qnil);
639 fset_minibuffer_window (f, Qnil);
642 wset_frame (rw, frame);
644 /* 10 is arbitrary,
645 just so that there is "something there."
646 Correct size will be set up later with adjust_frame_size. */
648 SET_FRAME_COLS (f, 10);
649 SET_FRAME_LINES (f, 10);
650 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
651 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
653 rw->total_cols = 10;
654 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
655 rw->total_lines = mini_p ? 9 : 10;
656 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
658 if (mini_p)
660 mw->top_line = rw->total_lines;
661 mw->pixel_top = rw->pixel_height;
662 mw->total_cols = rw->total_cols;
663 mw->pixel_width = rw->pixel_width;
664 mw->total_lines = 1;
665 mw->pixel_height = FRAME_LINE_HEIGHT (f);
668 /* Choose a buffer for the frame's root window. */
670 Lisp_Object buf = Fcurrent_buffer ();
672 /* If current buffer is hidden, try to find another one. */
673 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
674 buf = other_buffer_safely (buf);
676 /* Use set_window_buffer, not Fset_window_buffer, and don't let
677 hooks be run by it. The reason is that the whole frame/window
678 arrangement is not yet fully initialized at this point. Windows
679 don't have the right size, glyph matrices aren't initialized
680 etc. Running Lisp functions at this point surely ends in a
681 SEGV. */
682 set_window_buffer (root_window, buf, 0, 0);
683 fset_buffer_list (f, list1 (buf));
686 if (mini_p)
688 set_window_buffer (mini_window,
689 (NILP (Vminibuffer_list)
690 ? get_minibuffer (0)
691 : Fcar (Vminibuffer_list)),
692 0, 0);
693 /* No horizontal scroll bars in minibuffers. */
694 wset_horizontal_scroll_bar (mw, Qnil);
697 fset_root_window (f, root_window);
698 fset_selected_window (f, root_window);
699 /* Make sure this window seems more recently used than
700 a newly-created, never-selected window. */
701 XWINDOW (f->selected_window)->use_time = ++window_select_count;
703 return f;
706 #ifdef HAVE_WINDOW_SYSTEM
707 /* Make a frame using a separate minibuffer window on another frame.
708 MINI_WINDOW is the minibuffer window to use. nil means use the
709 default (the global minibuffer). */
711 struct frame *
712 make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
714 register struct frame *f;
715 struct gcpro gcpro1;
717 if (!NILP (mini_window))
718 CHECK_LIVE_WINDOW (mini_window);
720 if (!NILP (mini_window)
721 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
722 error ("Frame and minibuffer must be on the same terminal");
724 /* Make a frame containing just a root window. */
725 f = make_frame (0);
727 if (NILP (mini_window))
729 /* Use default-minibuffer-frame if possible. */
730 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
731 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
733 Lisp_Object frame_dummy;
735 XSETFRAME (frame_dummy, f);
736 GCPRO1 (frame_dummy);
737 /* If there's no minibuffer frame to use, create one. */
738 kset_default_minibuffer_frame
739 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
740 UNGCPRO;
743 mini_window
744 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
747 fset_minibuffer_window (f, mini_window);
749 /* Make the chosen minibuffer window display the proper minibuffer,
750 unless it is already showing a minibuffer. */
751 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
752 /* Use set_window_buffer instead of Fset_window_buffer (see
753 discussion of bug#11984, bug#12025, bug#12026). */
754 set_window_buffer (mini_window,
755 (NILP (Vminibuffer_list)
756 ? get_minibuffer (0)
757 : Fcar (Vminibuffer_list)), 0, 0);
758 return f;
761 /* Make a frame containing only a minibuffer window. */
763 struct frame *
764 make_minibuffer_frame (void)
766 /* First make a frame containing just a root window, no minibuffer. */
768 register struct frame *f = make_frame (0);
769 register Lisp_Object mini_window;
770 register Lisp_Object frame;
772 XSETFRAME (frame, f);
774 f->auto_raise = 0;
775 f->auto_lower = 0;
776 f->no_split = 1;
777 f->wants_modeline = 0;
779 /* Now label the root window as also being the minibuffer.
780 Avoid infinite looping on the window chain by marking next pointer
781 as nil. */
783 mini_window = f->root_window;
784 fset_minibuffer_window (f, mini_window);
785 XWINDOW (mini_window)->mini = 1;
786 wset_next (XWINDOW (mini_window), Qnil);
787 wset_prev (XWINDOW (mini_window), Qnil);
788 wset_frame (XWINDOW (mini_window), frame);
790 /* Put the proper buffer in that window. */
792 /* Use set_window_buffer instead of Fset_window_buffer (see
793 discussion of bug#11984, bug#12025, bug#12026). */
794 set_window_buffer (mini_window,
795 (NILP (Vminibuffer_list)
796 ? get_minibuffer (0)
797 : Fcar (Vminibuffer_list)), 0, 0);
798 return f;
800 #endif /* HAVE_WINDOW_SYSTEM */
802 /* Construct a frame that refers to a terminal. */
804 static printmax_t tty_frame_count;
806 struct frame *
807 make_initial_frame (void)
809 struct frame *f;
810 struct terminal *terminal;
811 Lisp_Object frame;
813 eassert (initial_kboard);
815 /* The first call must initialize Vframe_list. */
816 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
817 Vframe_list = Qnil;
819 terminal = init_initial_terminal ();
821 f = make_frame (1);
822 XSETFRAME (frame, f);
824 Vframe_list = Fcons (frame, Vframe_list);
826 tty_frame_count = 1;
827 fset_name (f, build_pure_c_string ("F1"));
829 SET_FRAME_VISIBLE (f, 1);
831 f->output_method = terminal->type;
832 f->terminal = terminal;
833 f->terminal->reference_count++;
834 f->output_data.nothing = 0;
836 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
837 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
839 #ifdef HAVE_WINDOW_SYSTEM
840 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
841 f->horizontal_scroll_bars = false;
842 #endif
844 /* The default value of menu-bar-mode is t. */
845 set_menu_bar_lines (f, make_number (1), Qnil);
847 if (!noninteractive)
848 init_frame_faces (f);
850 last_nonminibuf_frame = f;
852 return f;
856 static struct frame *
857 make_terminal_frame (struct terminal *terminal)
859 register struct frame *f;
860 Lisp_Object frame;
861 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
863 if (!terminal->name)
864 error ("Terminal is not live, can't create new frames on it");
866 f = make_frame (1);
868 XSETFRAME (frame, f);
869 Vframe_list = Fcons (frame, Vframe_list);
871 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
873 SET_FRAME_VISIBLE (f, 1);
875 f->terminal = terminal;
876 f->terminal->reference_count++;
877 #ifdef MSDOS
878 f->output_data.tty->display_info = &the_only_display_info;
879 if (!inhibit_window_system
880 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
881 || XFRAME (selected_frame)->output_method == output_msdos_raw))
882 f->output_method = output_msdos_raw;
883 else
884 f->output_method = output_termcap;
885 #else /* not MSDOS */
886 f->output_method = output_termcap;
887 create_tty_output (f);
888 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
889 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
890 #endif /* not MSDOS */
892 #ifdef HAVE_WINDOW_SYSTEM
893 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
894 f->horizontal_scroll_bars = false;
895 #endif
897 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
898 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
899 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
900 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
902 /* Set the top frame to the newly created frame. */
903 if (FRAMEP (FRAME_TTY (f)->top_frame)
904 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
905 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
907 FRAME_TTY (f)->top_frame = frame;
909 if (!noninteractive)
910 init_frame_faces (f);
912 return f;
915 /* Get a suitable value for frame parameter PARAMETER for a newly
916 created frame, based on (1) the user-supplied frame parameter
917 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
919 static Lisp_Object
920 get_future_frame_param (Lisp_Object parameter,
921 Lisp_Object supplied_parms,
922 char *current_value)
924 Lisp_Object result;
926 result = Fassq (parameter, supplied_parms);
927 if (NILP (result))
928 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
929 if (NILP (result) && current_value != NULL)
930 result = build_string (current_value);
931 if (!NILP (result) && !STRINGP (result))
932 result = XCDR (result);
933 if (NILP (result) || !STRINGP (result))
934 result = Qnil;
936 return result;
939 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
940 1, 1, 0,
941 doc: /* Create an additional terminal frame, possibly on another terminal.
942 This function takes one argument, an alist specifying frame parameters.
944 You can create multiple frames on a single text terminal, but only one
945 of them (the selected terminal frame) is actually displayed.
947 In practice, generally you don't need to specify any parameters,
948 except when you want to create a new frame on another terminal.
949 In that case, the `tty' parameter specifies the device file to open,
950 and the `tty-type' parameter specifies the terminal type. Example:
952 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
954 Note that changing the size of one terminal frame automatically
955 affects all frames on the same terminal device. */)
956 (Lisp_Object parms)
958 struct frame *f;
959 struct terminal *t = NULL;
960 Lisp_Object frame, tem;
961 struct frame *sf = SELECTED_FRAME ();
963 #ifdef MSDOS
964 if (sf->output_method != output_msdos_raw
965 && sf->output_method != output_termcap)
966 emacs_abort ();
967 #else /* not MSDOS */
969 #ifdef WINDOWSNT /* This should work now! */
970 if (sf->output_method != output_termcap)
971 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
972 #endif
973 #endif /* not MSDOS */
976 Lisp_Object terminal;
978 terminal = Fassq (Qterminal, parms);
979 if (CONSP (terminal))
981 terminal = XCDR (terminal);
982 t = get_terminal (terminal, 1);
984 #ifdef MSDOS
985 if (t && t != the_only_display_info.terminal)
986 /* msdos.c assumes a single tty_display_info object. */
987 error ("Multiple terminals are not supported on this platform");
988 if (!t)
989 t = the_only_display_info.terminal;
990 #endif
993 if (!t)
995 char *name = 0, *type = 0;
996 Lisp_Object tty, tty_type;
997 USE_SAFE_ALLOCA;
999 tty = get_future_frame_param
1000 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1001 ? FRAME_TTY (XFRAME (selected_frame))->name
1002 : NULL));
1003 if (!NILP (tty))
1004 SAFE_ALLOCA_STRING (name, tty);
1006 tty_type = get_future_frame_param
1007 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1008 ? FRAME_TTY (XFRAME (selected_frame))->type
1009 : NULL));
1010 if (!NILP (tty_type))
1011 SAFE_ALLOCA_STRING (type, tty_type);
1013 t = init_tty (name, type, 0); /* Errors are not fatal. */
1014 SAFE_FREE ();
1017 f = make_terminal_frame (t);
1020 int width, height;
1021 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1022 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f), 5, 0);
1025 adjust_frame_glyphs (f);
1026 calculate_costs (f);
1027 XSETFRAME (frame, f);
1029 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1030 store_in_alist (&parms, Qtty,
1031 (t->display_info.tty->name
1032 ? build_string (t->display_info.tty->name)
1033 : Qnil));
1034 Fmodify_frame_parameters (frame, parms);
1036 /* Make the frame face alist be frame-specific, so that each
1037 frame could change its face definitions independently. */
1038 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1039 /* Simple Fcopy_alist isn't enough, because we need the contents of
1040 the vectors which are the CDRs of associations in face_alist to
1041 be copied as well. */
1042 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1043 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1044 return frame;
1048 /* Perform the switch to frame FRAME.
1050 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1051 FRAME1 as frame.
1053 If TRACK is non-zero and the frame that currently has the focus
1054 redirects its focus to the selected frame, redirect that focused
1055 frame's focus to FRAME instead.
1057 FOR_DELETION non-zero means that the selected frame is being
1058 deleted, which includes the possibility that the frame's terminal
1059 is dead.
1061 The value of NORECORD is passed as argument to Fselect_window. */
1063 Lisp_Object
1064 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1066 struct frame *sf = SELECTED_FRAME ();
1068 /* If FRAME is a switch-frame event, extract the frame we should
1069 switch to. */
1070 if (CONSP (frame)
1071 && EQ (XCAR (frame), Qswitch_frame)
1072 && CONSP (XCDR (frame)))
1073 frame = XCAR (XCDR (frame));
1075 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1076 a switch-frame event to arrive after a frame is no longer live,
1077 especially when deleting the initial frame during startup. */
1078 CHECK_FRAME (frame);
1079 if (! FRAME_LIVE_P (XFRAME (frame)))
1080 return Qnil;
1082 if (sf == XFRAME (frame))
1083 return frame;
1085 /* If a frame's focus has been redirected toward the currently
1086 selected frame, we should change the redirection to point to the
1087 newly selected frame. This means that if the focus is redirected
1088 from a minibufferless frame to a surrogate minibuffer frame, we
1089 can use `other-window' to switch between all the frames using
1090 that minibuffer frame, and the focus redirection will follow us
1091 around. */
1092 #if 0
1093 /* This is too greedy; it causes inappropriate focus redirection
1094 that's hard to get rid of. */
1095 if (track)
1097 Lisp_Object tail;
1099 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1101 Lisp_Object focus;
1103 if (!FRAMEP (XCAR (tail)))
1104 emacs_abort ();
1106 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1108 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1109 Fredirect_frame_focus (XCAR (tail), frame);
1112 #else /* ! 0 */
1113 /* Instead, apply it only to the frame we're pointing to. */
1114 #ifdef HAVE_WINDOW_SYSTEM
1115 if (track && FRAME_WINDOW_P (XFRAME (frame)))
1117 Lisp_Object focus, xfocus;
1119 xfocus = x_get_focus_frame (XFRAME (frame));
1120 if (FRAMEP (xfocus))
1122 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1123 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1124 Fredirect_frame_focus (xfocus, frame);
1127 #endif /* HAVE_X_WINDOWS */
1128 #endif /* ! 0 */
1130 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1131 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1133 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
1135 struct frame *f = XFRAME (frame);
1136 struct tty_display_info *tty = FRAME_TTY (f);
1137 Lisp_Object top_frame = tty->top_frame;
1139 /* Don't mark the frame garbaged and/or obscured if we are
1140 switching to the frame that is already the top frame of that
1141 TTY. */
1142 if (!EQ (frame, top_frame))
1144 if (FRAMEP (top_frame))
1145 /* Mark previously displayed frame as now obscured. */
1146 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1147 SET_FRAME_VISIBLE (f, 1);
1148 /* If the new TTY frame changed dimensions, we need to
1149 resync term.c's idea of the frame size with the new
1150 frame's data. */
1151 if (FRAME_COLS (f) != FrameCols (tty))
1152 FrameCols (tty) = FRAME_COLS (f);
1153 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1154 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1156 tty->top_frame = frame;
1159 selected_frame = frame;
1160 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1161 last_nonminibuf_frame = XFRAME (selected_frame);
1163 Fselect_window (XFRAME (frame)->selected_window, norecord);
1165 /* We want to make sure that the next event generates a frame-switch
1166 event to the appropriate frame. This seems kludgy to me, but
1167 before you take it out, make sure that evaluating something like
1168 (select-window (frame-root-window (new-frame))) doesn't end up
1169 with your typing being interpreted in the new frame instead of
1170 the one you're actually typing in. */
1171 internal_last_event_frame = Qnil;
1173 return frame;
1176 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1177 doc: /* Select FRAME.
1178 Subsequent editing commands apply to its selected window.
1179 Optional argument NORECORD means to neither change the order of
1180 recently selected windows nor the buffer list.
1182 The selection of FRAME lasts until the next time the user does
1183 something to select a different frame, or until the next time
1184 this function is called. If you are using a window system, the
1185 previously selected frame may be restored as the selected frame
1186 when returning to the command loop, because it still may have
1187 the window system's input focus. On a text terminal, the next
1188 redisplay will display FRAME.
1190 This function returns FRAME, or nil if FRAME has been deleted. */)
1191 (Lisp_Object frame, Lisp_Object norecord)
1193 return do_switch_frame (frame, 1, 0, norecord);
1196 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
1197 doc: /* Handle a switch-frame event EVENT.
1198 Switch-frame events are usually bound to this function.
1199 A switch-frame event tells Emacs that the window manager has requested
1200 that the user's events be directed to the frame mentioned in the event.
1201 This function selects the selected window of the frame of EVENT.
1203 If EVENT is frame object, handle it as if it were a switch-frame event
1204 to that frame. */)
1205 (Lisp_Object event)
1207 /* Preserve prefix arg that the command loop just cleared. */
1208 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1209 Frun_hooks (1, &Qmouse_leave_buffer_hook);
1210 /* `switch-frame' implies a focus in. */
1211 call1 (intern ("handle-focus-in"), event);
1212 return do_switch_frame (event, 0, 0, Qnil);
1215 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1216 doc: /* Return the frame that is now selected. */)
1217 (void)
1219 return selected_frame;
1222 DEFUN ("frame-list", Fframe_list, Sframe_list,
1223 0, 0, 0,
1224 doc: /* Return a list of all live frames. */)
1225 (void)
1227 Lisp_Object frames;
1228 frames = Fcopy_sequence (Vframe_list);
1229 #ifdef HAVE_WINDOW_SYSTEM
1230 if (FRAMEP (tip_frame))
1231 frames = Fdelq (tip_frame, frames);
1232 #endif
1233 return frames;
1236 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1237 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1238 If MINIBUF is nil, do not consider minibuffer-only candidate.
1239 If MINIBUF is `visible', do not consider an invisible candidate.
1240 If MINIBUF is a window, consider only its own frame and candidate now
1241 using that window as the minibuffer.
1242 If MINIBUF is 0, consider candidate if it is visible or iconified.
1243 Otherwise consider any candidate and return nil if CANDIDATE is not
1244 acceptable. */
1246 static Lisp_Object
1247 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1249 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1251 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1252 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1253 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1254 && FRAME_TTY (c) == FRAME_TTY (f)))
1256 if (NILP (minibuf))
1258 if (!FRAME_MINIBUF_ONLY_P (c))
1259 return candidate;
1261 else if (EQ (minibuf, Qvisible))
1263 if (FRAME_VISIBLE_P (c))
1264 return candidate;
1266 else if (WINDOWP (minibuf))
1268 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1269 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1270 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1271 FRAME_FOCUS_FRAME (c)))
1272 return candidate;
1274 else if (XFASTINT (minibuf) == 0)
1276 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1277 return candidate;
1279 else
1280 return candidate;
1282 return Qnil;
1285 /* Return the next frame in the frame list after FRAME. */
1287 static Lisp_Object
1288 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1290 Lisp_Object f, tail;
1291 int passed = 0;
1293 /* There must always be at least one frame in Vframe_list. */
1294 eassert (CONSP (Vframe_list));
1296 while (passed < 2)
1297 FOR_EACH_FRAME (tail, f)
1299 if (passed)
1301 f = candidate_frame (f, frame, minibuf);
1302 if (!NILP (f))
1303 return f;
1305 if (EQ (frame, f))
1306 passed++;
1308 return frame;
1311 /* Return the previous frame in the frame list before FRAME. */
1313 static Lisp_Object
1314 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1316 Lisp_Object f, tail, prev = Qnil;
1318 /* There must always be at least one frame in Vframe_list. */
1319 eassert (CONSP (Vframe_list));
1321 FOR_EACH_FRAME (tail, f)
1323 if (EQ (frame, f) && !NILP (prev))
1324 return prev;
1325 f = candidate_frame (f, frame, minibuf);
1326 if (!NILP (f))
1327 prev = f;
1330 /* We've scanned the entire list. */
1331 if (NILP (prev))
1332 /* We went through the whole frame list without finding a single
1333 acceptable frame. Return the original frame. */
1334 return frame;
1335 else
1336 /* There were no acceptable frames in the list before FRAME; otherwise,
1337 we would have returned directly from the loop. Since PREV is the last
1338 acceptable frame in the list, return it. */
1339 return prev;
1343 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1344 doc: /* Return the next frame in the frame list after FRAME.
1345 It considers only frames on the same terminal as FRAME.
1346 By default, skip minibuffer-only frames.
1347 If omitted, FRAME defaults to the selected frame.
1348 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1349 If MINIFRAME is a window, include only its own frame
1350 and any frame now using that window as the minibuffer.
1351 If MINIFRAME is `visible', include all visible frames.
1352 If MINIFRAME is 0, include all visible and iconified frames.
1353 Otherwise, include all frames. */)
1354 (Lisp_Object frame, Lisp_Object miniframe)
1356 if (NILP (frame))
1357 frame = selected_frame;
1358 CHECK_LIVE_FRAME (frame);
1359 return next_frame (frame, miniframe);
1362 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1363 doc: /* Return the previous frame in the frame list before FRAME.
1364 It considers only frames on the same terminal as FRAME.
1365 By default, skip minibuffer-only frames.
1366 If omitted, FRAME defaults to the selected frame.
1367 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1368 If MINIFRAME is a window, include only its own frame
1369 and any frame now using that window as the minibuffer.
1370 If MINIFRAME is `visible', include all visible frames.
1371 If MINIFRAME is 0, include all visible and iconified frames.
1372 Otherwise, include all frames. */)
1373 (Lisp_Object frame, Lisp_Object miniframe)
1375 if (NILP (frame))
1376 frame = selected_frame;
1377 CHECK_LIVE_FRAME (frame);
1378 return prev_frame (frame, miniframe);
1381 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1382 Slast_nonminibuf_frame, 0, 0, 0,
1383 doc: /* Return last non-minibuffer frame selected. */)
1384 (void)
1386 Lisp_Object frame = Qnil;
1388 if (last_nonminibuf_frame)
1389 XSETFRAME (frame, last_nonminibuf_frame);
1391 return frame;
1394 /* Return 1 if it is ok to delete frame F;
1395 0 if all frames aside from F are invisible.
1396 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1398 static int
1399 other_visible_frames (struct frame *f)
1401 Lisp_Object frames, this;
1403 FOR_EACH_FRAME (frames, this)
1405 if (f == XFRAME (this))
1406 continue;
1408 /* Verify that we can still talk to the frame's X window,
1409 and note any recent change in visibility. */
1410 #ifdef HAVE_X_WINDOWS
1411 if (FRAME_WINDOW_P (XFRAME (this)))
1412 x_sync (XFRAME (this));
1413 #endif
1415 if (FRAME_VISIBLE_P (XFRAME (this))
1416 || FRAME_ICONIFIED_P (XFRAME (this))
1417 /* Allow deleting the terminal frame when at least one X
1418 frame exists. */
1419 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1420 return 1;
1422 return 0;
1425 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1426 window. Preferably use the selected frame's minibuffer window
1427 instead. If the selected frame doesn't have one, get some other
1428 frame's minibuffer window. SELECT non-zero means select the new
1429 minibuffer window. */
1430 static void
1431 check_minibuf_window (Lisp_Object frame, int select)
1433 struct frame *f = decode_live_frame (frame);
1435 XSETFRAME (frame, f);
1437 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1439 Lisp_Object frames, this, window = make_number (0);
1441 if (!EQ (frame, selected_frame)
1442 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1443 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1444 else
1445 FOR_EACH_FRAME (frames, this)
1447 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1449 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1450 break;
1454 /* Don't abort if no window was found (Bug#15247). */
1455 if (WINDOWP (window))
1457 /* Use set_window_buffer instead of Fset_window_buffer (see
1458 discussion of bug#11984, bug#12025, bug#12026). */
1459 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1460 minibuf_window = window;
1462 /* SELECT non-zero usually means that FRAME's minibuffer
1463 window was selected; select the new one. */
1464 if (select)
1465 Fselect_window (minibuf_window, Qnil);
1471 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1472 unconditionally. x_connection_closed and delete_terminal use
1473 this. Any other value of FORCE implements the semantics
1474 described for Fdelete_frame. */
1475 Lisp_Object
1476 delete_frame (Lisp_Object frame, Lisp_Object force)
1478 struct frame *f = decode_any_frame (frame);
1479 struct frame *sf;
1480 struct kboard *kb;
1482 int minibuffer_selected, is_tooltip_frame;
1484 if (! FRAME_LIVE_P (f))
1485 return Qnil;
1487 if (NILP (force) && !other_visible_frames (f))
1488 error ("Attempt to delete the sole visible or iconified frame");
1490 /* x_connection_closed must have set FORCE to `noelisp' in order
1491 to delete the last frame, if it is gone. */
1492 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1493 error ("Attempt to delete the only frame");
1495 XSETFRAME (frame, f);
1497 /* Does this frame have a minibuffer, and is it the surrogate
1498 minibuffer for any other frame? */
1499 if (FRAME_HAS_MINIBUF_P (f))
1501 Lisp_Object frames, this;
1503 FOR_EACH_FRAME (frames, this)
1505 Lisp_Object fminiw;
1507 if (EQ (this, frame))
1508 continue;
1510 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1512 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1514 /* If we MUST delete this frame, delete the other first.
1515 But do this only if FORCE equals `noelisp'. */
1516 if (EQ (force, Qnoelisp))
1517 delete_frame (this, Qnoelisp);
1518 else
1519 error ("Attempt to delete a surrogate minibuffer frame");
1524 is_tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1526 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1527 frame is a tooltip. FORCE is set to `noelisp' when handling
1528 a disconnect from the terminal, so we don't dare call Lisp
1529 code. */
1530 if (NILP (Vrun_hooks) || is_tooltip_frame)
1532 else if (EQ (force, Qnoelisp))
1533 pending_funcalls
1534 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1535 pending_funcalls);
1536 else
1538 #ifdef HAVE_X_WINDOWS
1539 /* Also, save clipboard to the clipboard manager. */
1540 x_clipboard_manager_save_frame (frame);
1541 #endif
1543 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1546 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1547 if (! FRAME_LIVE_P (f))
1548 return Qnil;
1550 /* At this point, we are committed to deleting the frame.
1551 There is no more chance for errors to prevent it. */
1553 minibuffer_selected = EQ (minibuf_window, selected_window);
1554 sf = SELECTED_FRAME ();
1555 /* Don't let the frame remain selected. */
1556 if (f == sf)
1558 Lisp_Object tail;
1559 Lisp_Object frame1 = Qnil;
1561 /* Look for another visible frame on the same terminal.
1562 Do not call next_frame here because it may loop forever.
1563 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1564 FOR_EACH_FRAME (tail, frame1)
1565 if (!EQ (frame, frame1)
1566 && (FRAME_TERMINAL (XFRAME (frame))
1567 == FRAME_TERMINAL (XFRAME (frame1)))
1568 && FRAME_VISIBLE_P (XFRAME (frame1)))
1569 break;
1571 /* If there is none, find *some* other frame. */
1572 if (NILP (frame1) || EQ (frame1, frame))
1574 FOR_EACH_FRAME (tail, frame1)
1576 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1578 /* Do not change a text terminal's top-frame. */
1579 struct frame *f1 = XFRAME (frame1);
1580 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1582 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1583 if (!EQ (top_frame, frame))
1584 frame1 = top_frame;
1586 break;
1590 #ifdef NS_IMPL_COCOA
1591 else
1592 /* Under NS, there is no system mechanism for choosing a new
1593 window to get focus -- it is left to application code.
1594 So the portion of THIS application interfacing with NS
1595 needs to know about it. We call Fraise_frame, but the
1596 purpose is really to transfer focus. */
1597 Fraise_frame (frame1);
1598 #endif
1600 do_switch_frame (frame1, 0, 1, Qnil);
1601 sf = SELECTED_FRAME ();
1604 /* Don't allow minibuf_window to remain on a deleted frame. */
1605 check_minibuf_window (frame, minibuffer_selected);
1607 /* Don't let echo_area_window to remain on a deleted frame. */
1608 if (EQ (f->minibuffer_window, echo_area_window))
1609 echo_area_window = sf->minibuffer_window;
1611 /* Clear any X selections for this frame. */
1612 #ifdef HAVE_X_WINDOWS
1613 if (FRAME_X_P (f))
1614 x_clear_frame_selections (f);
1615 #endif
1617 /* Free glyphs.
1618 This function must be called before the window tree of the
1619 frame is deleted because windows contain dynamically allocated
1620 memory. */
1621 free_glyphs (f);
1623 #ifdef HAVE_WINDOW_SYSTEM
1624 /* Give chance to each font driver to free a frame specific data. */
1625 font_update_drivers (f, Qnil);
1626 #endif
1628 /* Mark all the windows that used to be on FRAME as deleted, and then
1629 remove the reference to them. */
1630 delete_all_child_windows (f->root_window);
1631 fset_root_window (f, Qnil);
1633 Vframe_list = Fdelq (frame, Vframe_list);
1634 SET_FRAME_VISIBLE (f, 0);
1636 /* Allow the vector of menu bar contents to be freed in the next
1637 garbage collection. The frame object itself may not be garbage
1638 collected until much later, because recent_keys and other data
1639 structures can still refer to it. */
1640 fset_menu_bar_vector (f, Qnil);
1642 /* If FRAME's buffer lists contains killed
1643 buffers, this helps GC to reclaim them. */
1644 fset_buffer_list (f, Qnil);
1645 fset_buried_buffer_list (f, Qnil);
1647 free_font_driver_list (f);
1648 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1649 xfree (f->namebuf);
1650 #endif
1651 xfree (f->decode_mode_spec_buffer);
1652 xfree (FRAME_INSERT_COST (f));
1653 xfree (FRAME_DELETEN_COST (f));
1654 xfree (FRAME_INSERTN_COST (f));
1655 xfree (FRAME_DELETE_COST (f));
1657 /* Since some events are handled at the interrupt level, we may get
1658 an event for f at any time; if we zero out the frame's terminal
1659 now, then we may trip up the event-handling code. Instead, we'll
1660 promise that the terminal of the frame must be valid until we
1661 have called the window-system-dependent frame destruction
1662 routine. */
1666 struct terminal *terminal;
1667 block_input ();
1668 if (FRAME_TERMINAL (f)->delete_frame_hook)
1669 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1670 terminal = FRAME_TERMINAL (f);
1671 f->output_data.nothing = 0;
1672 f->terminal = 0; /* Now the frame is dead. */
1673 unblock_input ();
1675 /* If needed, delete the terminal that this frame was on.
1676 (This must be done after the frame is killed.) */
1677 terminal->reference_count--;
1678 #ifdef USE_GTK
1679 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1680 bug.
1681 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1682 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1683 terminal->reference_count = 1;
1684 #endif /* USE_GTK */
1685 if (terminal->reference_count == 0)
1687 Lisp_Object tmp;
1688 XSETTERMINAL (tmp, terminal);
1690 kb = NULL;
1691 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1693 else
1694 kb = terminal->kboard;
1697 /* If we've deleted the last_nonminibuf_frame, then try to find
1698 another one. */
1699 if (f == last_nonminibuf_frame)
1701 Lisp_Object frames, this;
1703 last_nonminibuf_frame = 0;
1705 FOR_EACH_FRAME (frames, this)
1707 f = XFRAME (this);
1708 if (!FRAME_MINIBUF_ONLY_P (f))
1710 last_nonminibuf_frame = f;
1711 break;
1716 /* If there's no other frame on the same kboard, get out of
1717 single-kboard state if we're in it for this kboard. */
1718 if (kb != NULL)
1720 Lisp_Object frames, this;
1721 /* Some frame we found on the same kboard, or nil if there are none. */
1722 Lisp_Object frame_on_same_kboard = Qnil;
1724 FOR_EACH_FRAME (frames, this)
1725 if (kb == FRAME_KBOARD (XFRAME (this)))
1726 frame_on_same_kboard = this;
1728 if (NILP (frame_on_same_kboard))
1729 not_single_kboard_state (kb);
1733 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1734 find another one. Prefer minibuffer-only frames, but also notice
1735 frames with other windows. */
1736 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1738 Lisp_Object frames, this;
1740 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1741 Lisp_Object frame_with_minibuf = Qnil;
1742 /* Some frame we found on the same kboard, or nil if there are none. */
1743 Lisp_Object frame_on_same_kboard = Qnil;
1745 FOR_EACH_FRAME (frames, this)
1747 struct frame *f1 = XFRAME (this);
1749 /* Consider only frames on the same kboard
1750 and only those with minibuffers. */
1751 if (kb == FRAME_KBOARD (f1)
1752 && FRAME_HAS_MINIBUF_P (f1))
1754 frame_with_minibuf = this;
1755 if (FRAME_MINIBUF_ONLY_P (f1))
1756 break;
1759 if (kb == FRAME_KBOARD (f1))
1760 frame_on_same_kboard = this;
1763 if (!NILP (frame_on_same_kboard))
1765 /* We know that there must be some frame with a minibuffer out
1766 there. If this were not true, all of the frames present
1767 would have to be minibufferless, which implies that at some
1768 point their minibuffer frames must have been deleted, but
1769 that is prohibited at the top; you can't delete surrogate
1770 minibuffer frames. */
1771 if (NILP (frame_with_minibuf))
1772 emacs_abort ();
1774 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1776 else
1777 /* No frames left on this kboard--say no minibuffer either. */
1778 kset_default_minibuffer_frame (kb, Qnil);
1781 /* Cause frame titles to update--necessary if we now have just one frame. */
1782 if (!is_tooltip_frame)
1783 update_mode_lines = 15;
1785 return Qnil;
1788 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1789 doc: /* Delete FRAME, permanently eliminating it from use.
1790 FRAME defaults to the selected frame.
1792 A frame may not be deleted if its minibuffer is used by other frames.
1793 Normally, you may not delete a frame if all other frames are invisible,
1794 but if the second optional argument FORCE is non-nil, you may do so.
1796 This function runs `delete-frame-functions' before actually
1797 deleting the frame, unless the frame is a tooltip.
1798 The functions are run with one argument, the frame to be deleted. */)
1799 (Lisp_Object frame, Lisp_Object force)
1801 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1805 /* Return mouse position in character cell units. */
1807 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1808 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1809 The position is given in canonical character cells, where (0, 0) is the
1810 upper-left corner of the frame, X is the horizontal offset, and Y is the
1811 vertical offset, measured in units of the frame's default character size.
1812 If Emacs is running on a mouseless terminal or hasn't been programmed
1813 to read the mouse position, it returns the selected frame for FRAME
1814 and nil for X and Y.
1815 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1816 passing the normal return value to that function as an argument,
1817 and returns whatever that function returns. */)
1818 (void)
1820 struct frame *f;
1821 Lisp_Object lispy_dummy;
1822 Lisp_Object x, y, retval;
1823 struct gcpro gcpro1;
1825 f = SELECTED_FRAME ();
1826 x = y = Qnil;
1828 /* It's okay for the hook to refrain from storing anything. */
1829 if (FRAME_TERMINAL (f)->mouse_position_hook)
1831 enum scroll_bar_part party_dummy;
1832 Time time_dummy;
1833 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1834 &lispy_dummy, &party_dummy,
1835 &x, &y,
1836 &time_dummy);
1839 if (! NILP (x))
1841 int col = XINT (x);
1842 int row = XINT (y);
1843 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1844 XSETINT (x, col);
1845 XSETINT (y, row);
1847 XSETFRAME (lispy_dummy, f);
1848 retval = Fcons (lispy_dummy, Fcons (x, y));
1849 GCPRO1 (retval);
1850 if (!NILP (Vmouse_position_function))
1851 retval = call1 (Vmouse_position_function, retval);
1852 RETURN_UNGCPRO (retval);
1855 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1856 Smouse_pixel_position, 0, 0, 0,
1857 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1858 The position is given in pixel units, where (0, 0) is the
1859 upper-left corner of the frame, X is the horizontal offset, and Y is
1860 the vertical offset.
1861 If Emacs is running on a mouseless terminal or hasn't been programmed
1862 to read the mouse position, it returns the selected frame for FRAME
1863 and nil for X and Y. */)
1864 (void)
1866 struct frame *f;
1867 Lisp_Object lispy_dummy;
1868 Lisp_Object x, y;
1870 f = SELECTED_FRAME ();
1871 x = y = Qnil;
1873 /* It's okay for the hook to refrain from storing anything. */
1874 if (FRAME_TERMINAL (f)->mouse_position_hook)
1876 enum scroll_bar_part party_dummy;
1877 Time time_dummy;
1878 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1879 &lispy_dummy, &party_dummy,
1880 &x, &y,
1881 &time_dummy);
1884 XSETFRAME (lispy_dummy, f);
1885 return Fcons (lispy_dummy, Fcons (x, y));
1888 #ifdef HAVE_WINDOW_SYSTEM
1890 /* On frame F, convert character coordinates X and Y to pixel
1891 coordinates *PIX_X and *PIX_Y. */
1893 static void
1894 frame_char_to_pixel_position (struct frame *f, int x, int y,
1895 int *pix_x, int *pix_y)
1897 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
1898 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
1900 if (*pix_x < 0)
1901 *pix_x = 0;
1902 if (*pix_x > FRAME_PIXEL_WIDTH (f))
1903 *pix_x = FRAME_PIXEL_WIDTH (f);
1905 if (*pix_y < 0)
1906 *pix_y = 0;
1907 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
1908 *pix_y = FRAME_PIXEL_HEIGHT (f);
1911 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1913 static void
1914 frame_set_mouse_position (struct frame *f, int x, int y)
1916 int pix_x, pix_y;
1918 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
1919 frame_set_mouse_pixel_position (f, pix_x, pix_y);
1922 #endif /* HAVE_WINDOW_SYSTEM */
1924 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1925 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1926 Coordinates are relative to the frame, not a window,
1927 so the coordinates of the top left character in the frame
1928 may be nonzero due to left-hand scroll bars or the menu bar.
1930 The position is given in canonical character cells, where (0, 0) is
1931 the upper-left corner of the frame, X is the horizontal offset, and
1932 Y is the vertical offset, measured in units of the frame's default
1933 character size.
1935 This function is a no-op for an X frame that is not visible.
1936 If you have just created a frame, you must wait for it to become visible
1937 before calling this function on it, like this.
1938 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1939 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1941 CHECK_LIVE_FRAME (frame);
1942 CHECK_TYPE_RANGED_INTEGER (int, x);
1943 CHECK_TYPE_RANGED_INTEGER (int, y);
1945 /* I think this should be done with a hook. */
1946 #ifdef HAVE_WINDOW_SYSTEM
1947 if (FRAME_WINDOW_P (XFRAME (frame)))
1948 /* Warping the mouse will cause enternotify and focus events. */
1949 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1950 #else
1951 #if defined (MSDOS)
1952 if (FRAME_MSDOS_P (XFRAME (frame)))
1954 Fselect_frame (frame, Qnil);
1955 mouse_moveto (XINT (x), XINT (y));
1957 #else
1958 #ifdef HAVE_GPM
1960 Fselect_frame (frame, Qnil);
1961 term_mouse_moveto (XINT (x), XINT (y));
1963 #endif
1964 #endif
1965 #endif
1967 return Qnil;
1970 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1971 Sset_mouse_pixel_position, 3, 3, 0,
1972 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1973 The position is given in pixels, where (0, 0) is the upper-left corner
1974 of the frame, X is the horizontal offset, and Y is the vertical offset.
1976 Note, this is a no-op for an X frame that is not visible.
1977 If you have just created a frame, you must wait for it to become visible
1978 before calling this function on it, like this.
1979 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1980 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1982 CHECK_LIVE_FRAME (frame);
1983 CHECK_TYPE_RANGED_INTEGER (int, x);
1984 CHECK_TYPE_RANGED_INTEGER (int, y);
1986 /* I think this should be done with a hook. */
1987 #ifdef HAVE_WINDOW_SYSTEM
1988 if (FRAME_WINDOW_P (XFRAME (frame)))
1989 /* Warping the mouse will cause enternotify and focus events. */
1990 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1991 #else
1992 #if defined (MSDOS)
1993 if (FRAME_MSDOS_P (XFRAME (frame)))
1995 Fselect_frame (frame, Qnil);
1996 mouse_moveto (XINT (x), XINT (y));
1998 #else
1999 #ifdef HAVE_GPM
2001 Fselect_frame (frame, Qnil);
2002 term_mouse_moveto (XINT (x), XINT (y));
2004 #endif
2005 #endif
2006 #endif
2008 return Qnil;
2011 static void make_frame_visible_1 (Lisp_Object);
2013 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2014 0, 1, "",
2015 doc: /* Make the frame FRAME visible (assuming it is an X window).
2016 If omitted, FRAME defaults to the currently selected frame. */)
2017 (Lisp_Object frame)
2019 struct frame *f = decode_live_frame (frame);
2021 /* I think this should be done with a hook. */
2022 #ifdef HAVE_WINDOW_SYSTEM
2023 if (FRAME_WINDOW_P (f))
2024 x_make_frame_visible (f);
2025 #endif
2027 make_frame_visible_1 (f->root_window);
2029 /* Make menu bar update for the Buffers and Frames menus. */
2030 /* windows_or_buffers_changed = 15; FIXME: Why? */
2032 XSETFRAME (frame, f);
2033 return frame;
2036 /* Update the display_time slot of the buffers shown in WINDOW
2037 and all its descendants. */
2039 static void
2040 make_frame_visible_1 (Lisp_Object window)
2042 struct window *w;
2044 for (; !NILP (window); window = w->next)
2046 w = XWINDOW (window);
2047 if (WINDOWP (w->contents))
2048 make_frame_visible_1 (w->contents);
2049 else
2050 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2054 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2055 0, 2, "",
2056 doc: /* Make the frame FRAME invisible.
2057 If omitted, FRAME defaults to the currently selected frame.
2058 On graphical displays, invisible frames are not updated and are
2059 usually not displayed at all, even in a window system's \"taskbar\".
2061 Normally you may not make FRAME invisible if all other frames are invisible,
2062 but if the second optional argument FORCE is non-nil, you may do so.
2064 This function has no effect on text terminal frames. Such frames are
2065 always considered visible, whether or not they are currently being
2066 displayed in the terminal. */)
2067 (Lisp_Object frame, Lisp_Object force)
2069 struct frame *f = decode_live_frame (frame);
2071 if (NILP (force) && !other_visible_frames (f))
2072 error ("Attempt to make invisible the sole visible or iconified frame");
2074 /* Don't allow minibuf_window to remain on an invisible frame. */
2075 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2077 /* I think this should be done with a hook. */
2078 #ifdef HAVE_WINDOW_SYSTEM
2079 if (FRAME_WINDOW_P (f))
2080 x_make_frame_invisible (f);
2081 #endif
2083 /* Make menu bar update for the Buffers and Frames menus. */
2084 windows_or_buffers_changed = 16;
2086 return Qnil;
2089 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2090 0, 1, "",
2091 doc: /* Make the frame FRAME into an icon.
2092 If omitted, FRAME defaults to the currently selected frame. */)
2093 (Lisp_Object frame)
2095 struct frame *f = decode_live_frame (frame);
2097 /* Don't allow minibuf_window to remain on an iconified frame. */
2098 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2100 /* I think this should be done with a hook. */
2101 #ifdef HAVE_WINDOW_SYSTEM
2102 if (FRAME_WINDOW_P (f))
2103 x_iconify_frame (f);
2104 #endif
2106 /* Make menu bar update for the Buffers and Frames menus. */
2107 windows_or_buffers_changed = 17;
2109 return Qnil;
2112 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2113 1, 1, 0,
2114 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2115 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2116 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2117 On graphical displays, invisible frames are not updated and are
2118 usually not displayed at all, even in a window system's \"taskbar\".
2120 If FRAME is a text terminal frame, this always returns t.
2121 Such frames are always considered visible, whether or not they are
2122 currently being displayed on the terminal. */)
2123 (Lisp_Object frame)
2125 CHECK_LIVE_FRAME (frame);
2127 if (FRAME_VISIBLE_P (XFRAME (frame)))
2128 return Qt;
2129 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2130 return Qicon;
2131 return Qnil;
2134 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2135 0, 0, 0,
2136 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2137 (void)
2139 Lisp_Object tail, frame, value = Qnil;
2141 FOR_EACH_FRAME (tail, frame)
2142 if (FRAME_VISIBLE_P (XFRAME (frame)))
2143 value = Fcons (frame, value);
2145 return value;
2149 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2150 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2151 If FRAME is invisible or iconified, make it visible.
2152 If you don't specify a frame, the selected frame is used.
2153 If Emacs is displaying on an ordinary terminal or some other device which
2154 doesn't support multiple overlapping frames, this function selects FRAME. */)
2155 (Lisp_Object frame)
2157 struct frame *f = decode_live_frame (frame);
2159 XSETFRAME (frame, f);
2161 if (FRAME_TERMCAP_P (f))
2162 /* On a text terminal select FRAME. */
2163 Fselect_frame (frame, Qnil);
2164 else
2165 /* Do like the documentation says. */
2166 Fmake_frame_visible (frame);
2168 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2169 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2171 return Qnil;
2174 /* Should we have a corresponding function called Flower_Power? */
2175 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2176 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2177 If you don't specify a frame, the selected frame is used.
2178 If Emacs is displaying on an ordinary terminal or some other device which
2179 doesn't support multiple overlapping frames, this function does nothing. */)
2180 (Lisp_Object frame)
2182 struct frame *f = decode_live_frame (frame);
2184 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2185 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2187 return Qnil;
2191 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2192 1, 2, 0,
2193 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2194 In other words, switch-frame events caused by events in FRAME will
2195 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2196 FOCUS-FRAME after reading an event typed at FRAME.
2198 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2199 frame again receives its own keystrokes.
2201 Focus redirection is useful for temporarily redirecting keystrokes to
2202 a surrogate minibuffer frame when a frame doesn't have its own
2203 minibuffer window.
2205 A frame's focus redirection can be changed by `select-frame'. If frame
2206 FOO is selected, and then a different frame BAR is selected, any
2207 frames redirecting their focus to FOO are shifted to redirect their
2208 focus to BAR. This allows focus redirection to work properly when the
2209 user switches from one frame to another using `select-window'.
2211 This means that a frame whose focus is redirected to itself is treated
2212 differently from a frame whose focus is redirected to nil; the former
2213 is affected by `select-frame', while the latter is not.
2215 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2216 (Lisp_Object frame, Lisp_Object focus_frame)
2218 /* Note that we don't check for a live frame here. It's reasonable
2219 to redirect the focus of a frame you're about to delete, if you
2220 know what other frame should receive those keystrokes. */
2221 struct frame *f = decode_any_frame (frame);
2223 if (! NILP (focus_frame))
2224 CHECK_LIVE_FRAME (focus_frame);
2226 fset_focus_frame (f, focus_frame);
2228 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2229 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2231 return Qnil;
2235 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2236 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2237 If FRAME is omitted or nil, the selected frame is used.
2238 Return nil if FRAME's focus is not redirected.
2239 See `redirect-frame-focus'. */)
2240 (Lisp_Object frame)
2242 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2245 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2246 doc: /* Set the input focus to FRAME.
2247 FRAME nil means use the selected frame.
2248 If there is no window system support, this function does nothing. */)
2249 (Lisp_Object frame)
2251 #ifdef HAVE_WINDOW_SYSTEM
2252 x_focus_frame (decode_window_system_frame (frame));
2253 #endif
2254 return Qnil;
2258 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2260 void
2261 frames_discard_buffer (Lisp_Object buffer)
2263 Lisp_Object frame, tail;
2265 FOR_EACH_FRAME (tail, frame)
2267 fset_buffer_list
2268 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2269 fset_buried_buffer_list
2270 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2274 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2275 If the alist already has an element for PROP, we change it. */
2277 void
2278 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2280 register Lisp_Object tem;
2282 tem = Fassq (prop, *alistptr);
2283 if (EQ (tem, Qnil))
2284 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2285 else
2286 Fsetcdr (tem, val);
2289 static int
2290 frame_name_fnn_p (char *str, ptrdiff_t len)
2292 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2294 char *p = str + 2;
2295 while ('0' <= *p && *p <= '9')
2296 p++;
2297 if (p == str + len)
2298 return 1;
2300 return 0;
2303 /* Set the name of the terminal frame. Also used by MSDOS frames.
2304 Modeled after x_set_name which is used for WINDOW frames. */
2306 static void
2307 set_term_frame_name (struct frame *f, Lisp_Object name)
2309 f->explicit_name = ! NILP (name);
2311 /* If NAME is nil, set the name to F<num>. */
2312 if (NILP (name))
2314 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2316 /* Check for no change needed in this very common case
2317 before we do any consing. */
2318 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2319 return;
2321 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2323 else
2325 CHECK_STRING (name);
2327 /* Don't change the name if it's already NAME. */
2328 if (! NILP (Fstring_equal (name, f->name)))
2329 return;
2331 /* Don't allow the user to set the frame name to F<num>, so it
2332 doesn't clash with the names we generate for terminal frames. */
2333 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2334 error ("Frame names of the form F<num> are usurped by Emacs");
2337 fset_name (f, name);
2338 update_mode_lines = 16;
2341 void
2342 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2344 register Lisp_Object old_alist_elt;
2346 /* The buffer-list parameters are stored in a special place and not
2347 in the alist. All buffers must be live. */
2348 if (EQ (prop, Qbuffer_list))
2350 Lisp_Object list = Qnil;
2351 for (; CONSP (val); val = XCDR (val))
2352 if (!NILP (Fbuffer_live_p (XCAR (val))))
2353 list = Fcons (XCAR (val), list);
2354 fset_buffer_list (f, Fnreverse (list));
2355 return;
2357 if (EQ (prop, Qburied_buffer_list))
2359 Lisp_Object list = Qnil;
2360 for (; CONSP (val); val = XCDR (val))
2361 if (!NILP (Fbuffer_live_p (XCAR (val))))
2362 list = Fcons (XCAR (val), list);
2363 fset_buried_buffer_list (f, Fnreverse (list));
2364 return;
2367 /* If PROP is a symbol which is supposed to have frame-local values,
2368 and it is set up based on this frame, switch to the global
2369 binding. That way, we can create or alter the frame-local binding
2370 without messing up the symbol's status. */
2371 if (SYMBOLP (prop))
2373 struct Lisp_Symbol *sym = XSYMBOL (prop);
2374 start:
2375 switch (sym->redirect)
2377 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2378 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2379 case SYMBOL_LOCALIZED:
2380 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2381 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2382 swap_in_global_binding (sym);
2383 break;
2385 default: emacs_abort ();
2389 /* The tty color needed to be set before the frame's parameter
2390 alist was updated with the new value. This is not true any more,
2391 but we still do this test early on. */
2392 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2393 && f == FRAME_TTY (f)->previous_frame)
2394 /* Force redisplay of this tty. */
2395 FRAME_TTY (f)->previous_frame = NULL;
2397 /* Update the frame parameter alist. */
2398 old_alist_elt = Fassq (prop, f->param_alist);
2399 if (EQ (old_alist_elt, Qnil))
2400 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2401 else
2402 Fsetcdr (old_alist_elt, val);
2404 /* Update some other special parameters in their special places
2405 in addition to the alist. */
2407 if (EQ (prop, Qbuffer_predicate))
2408 fset_buffer_predicate (f, val);
2410 if (! FRAME_WINDOW_P (f))
2412 if (EQ (prop, Qmenu_bar_lines))
2413 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2414 else if (EQ (prop, Qname))
2415 set_term_frame_name (f, val);
2418 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2420 if (! MINI_WINDOW_P (XWINDOW (val)))
2421 error ("Surrogate minibuffer windows must be minibuffer windows");
2423 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2424 && !EQ (val, f->minibuffer_window))
2425 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2427 /* Install the chosen minibuffer window, with proper buffer. */
2428 fset_minibuffer_window (f, val);
2432 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2433 is not an unspecified foreground or background color. */
2435 static Lisp_Object
2436 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2438 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2439 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2440 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2441 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2444 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2445 doc: /* Return the parameters-alist of frame FRAME.
2446 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2447 The meaningful PARMs depend on the kind of frame.
2448 If FRAME is omitted or nil, return information on the currently selected frame. */)
2449 (Lisp_Object frame)
2451 Lisp_Object alist;
2452 struct frame *f = decode_any_frame (frame);
2453 int height, width;
2454 struct gcpro gcpro1;
2456 if (!FRAME_LIVE_P (f))
2457 return Qnil;
2459 alist = Fcopy_alist (f->param_alist);
2460 GCPRO1 (alist);
2462 if (!FRAME_WINDOW_P (f))
2464 Lisp_Object elt;
2466 /* If the frame's parameter alist says the colors are
2467 unspecified and reversed, take the frame's background pixel
2468 for foreground and vice versa. */
2469 elt = Fassq (Qforeground_color, alist);
2470 if (CONSP (elt) && STRINGP (XCDR (elt)))
2472 elt = frame_unspecified_color (f, XCDR (elt));
2473 if (!NILP (elt))
2474 store_in_alist (&alist, Qforeground_color, elt);
2476 else
2477 store_in_alist (&alist, Qforeground_color,
2478 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2479 elt = Fassq (Qbackground_color, alist);
2480 if (CONSP (elt) && STRINGP (XCDR (elt)))
2482 elt = frame_unspecified_color (f, XCDR (elt));
2483 if (!NILP (elt))
2484 store_in_alist (&alist, Qbackground_color, elt);
2486 else
2487 store_in_alist (&alist, Qbackground_color,
2488 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2489 store_in_alist (&alist, intern ("font"),
2490 build_string (FRAME_MSDOS_P (f)
2491 ? "ms-dos"
2492 : FRAME_W32_P (f) ? "w32term"
2493 :"tty"));
2495 store_in_alist (&alist, Qname, f->name);
2496 height = (f->new_height
2497 ? (f->new_pixelwise
2498 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2499 : f->new_height)
2500 : FRAME_LINES (f));
2501 store_in_alist (&alist, Qheight, make_number (height));
2502 width = (f->new_width
2503 ? (f->new_pixelwise
2504 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2505 : f->new_width)
2506 : FRAME_COLS (f));
2507 store_in_alist (&alist, Qwidth, make_number (width));
2508 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2509 store_in_alist (&alist, Qminibuffer,
2510 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2511 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2512 : FRAME_MINIBUF_WINDOW (f)));
2513 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2514 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2515 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2517 /* I think this should be done with a hook. */
2518 #ifdef HAVE_WINDOW_SYSTEM
2519 if (FRAME_WINDOW_P (f))
2520 x_report_frame_params (f, &alist);
2521 else
2522 #endif
2524 /* This ought to be correct in f->param_alist for an X frame. */
2525 Lisp_Object lines;
2526 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2527 store_in_alist (&alist, Qmenu_bar_lines, lines);
2530 UNGCPRO;
2531 return alist;
2535 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2536 doc: /* Return FRAME's value for parameter PARAMETER.
2537 If FRAME is nil, describe the currently selected frame. */)
2538 (Lisp_Object frame, Lisp_Object parameter)
2540 struct frame *f = decode_any_frame (frame);
2541 Lisp_Object value = Qnil;
2543 CHECK_SYMBOL (parameter);
2545 XSETFRAME (frame, f);
2547 if (FRAME_LIVE_P (f))
2549 /* Avoid consing in frequent cases. */
2550 if (EQ (parameter, Qname))
2551 value = f->name;
2552 #ifdef HAVE_X_WINDOWS
2553 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2554 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2555 #endif /* HAVE_X_WINDOWS */
2556 else if (EQ (parameter, Qbackground_color)
2557 || EQ (parameter, Qforeground_color))
2559 value = Fassq (parameter, f->param_alist);
2560 if (CONSP (value))
2562 value = XCDR (value);
2563 /* Fframe_parameters puts the actual fg/bg color names,
2564 even if f->param_alist says otherwise. This is
2565 important when param_alist's notion of colors is
2566 "unspecified". We need to do the same here. */
2567 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2568 value = frame_unspecified_color (f, value);
2570 else
2571 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2573 else if (EQ (parameter, Qdisplay_type)
2574 || EQ (parameter, Qbackground_mode))
2575 value = Fcdr (Fassq (parameter, f->param_alist));
2576 else
2577 /* FIXME: Avoid this code path at all (as well as code duplication)
2578 by sharing more code with Fframe_parameters. */
2579 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2582 return value;
2586 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2587 Smodify_frame_parameters, 2, 2, 0,
2588 doc: /* Modify the parameters of frame FRAME according to ALIST.
2589 If FRAME is nil, it defaults to the selected frame.
2590 ALIST is an alist of parameters to change and their new values.
2591 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2592 The meaningful PARMs depend on the kind of frame.
2593 Undefined PARMs are ignored, but stored in the frame's parameter list
2594 so that `frame-parameters' will return them.
2596 The value of frame parameter FOO can also be accessed
2597 as a frame-local binding for the variable FOO, if you have
2598 enabled such bindings for that variable with `make-variable-frame-local'.
2599 Note that this functionality is obsolete as of Emacs 22.2, and its
2600 use is not recommended. Explicitly check for a frame-parameter instead. */)
2601 (Lisp_Object frame, Lisp_Object alist)
2603 struct frame *f = decode_live_frame (frame);
2604 register Lisp_Object prop, val;
2606 CHECK_LIST (alist);
2608 /* I think this should be done with a hook. */
2609 #ifdef HAVE_WINDOW_SYSTEM
2610 if (FRAME_WINDOW_P (f))
2611 x_set_frame_parameters (f, alist);
2612 else
2613 #endif
2614 #ifdef MSDOS
2615 if (FRAME_MSDOS_P (f))
2616 IT_set_frame_parameters (f, alist);
2617 else
2618 #endif
2621 EMACS_INT length = XFASTINT (Flength (alist));
2622 ptrdiff_t i;
2623 Lisp_Object *parms;
2624 Lisp_Object *values;
2625 USE_SAFE_ALLOCA;
2626 SAFE_ALLOCA_LISP (parms, 2 * length);
2627 values = parms + length;
2629 /* Extract parm names and values into those vectors. */
2631 for (i = 0; CONSP (alist); alist = XCDR (alist))
2633 Lisp_Object elt;
2635 elt = XCAR (alist);
2636 parms[i] = Fcar (elt);
2637 values[i] = Fcdr (elt);
2638 i++;
2641 /* Now process them in reverse of specified order. */
2642 while (--i >= 0)
2644 prop = parms[i];
2645 val = values[i];
2646 store_frame_param (f, prop, val);
2648 if (EQ (prop, Qforeground_color)
2649 || EQ (prop, Qbackground_color))
2650 update_face_from_frame_parameter (f, prop, val);
2653 SAFE_FREE ();
2655 return Qnil;
2658 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2659 0, 1, 0,
2660 doc: /* Height in pixels of a line in the font in frame FRAME.
2661 If FRAME is omitted or nil, the selected frame is used.
2662 For a terminal frame, the value is always 1. */)
2663 (Lisp_Object frame)
2665 #ifdef HAVE_WINDOW_SYSTEM
2666 struct frame *f = decode_any_frame (frame);
2668 if (FRAME_WINDOW_P (f))
2669 return make_number (FRAME_LINE_HEIGHT (f));
2670 else
2671 #endif
2672 return make_number (1);
2676 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2677 0, 1, 0,
2678 doc: /* Width in pixels of characters in the font in frame FRAME.
2679 If FRAME is omitted or nil, the selected frame is used.
2680 On a graphical screen, the width is the standard width of the default font.
2681 For a terminal screen, the value is always 1. */)
2682 (Lisp_Object frame)
2684 #ifdef HAVE_WINDOW_SYSTEM
2685 struct frame *f = decode_any_frame (frame);
2687 if (FRAME_WINDOW_P (f))
2688 return make_number (FRAME_COLUMN_WIDTH (f));
2689 else
2690 #endif
2691 return make_number (1);
2694 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2695 Sframe_pixel_height, 0, 1, 0,
2696 doc: /* Return a FRAME's height in pixels.
2697 If FRAME is omitted or nil, the selected frame is used. The exact value
2698 of the result depends on the window-system and toolkit in use:
2700 In the Gtk+ version of Emacs, it includes only any window (including
2701 the minibuffer or echo area), mode line, and header line. It does not
2702 include the tool bar or menu bar.
2704 With other graphical versions, it also includes the tool bar and the
2705 menu bar.
2707 For a text terminal, it includes the menu bar. In this case, the
2708 result is really in characters rather than pixels (i.e., is identical
2709 to `frame-height'). */)
2710 (Lisp_Object frame)
2712 struct frame *f = decode_any_frame (frame);
2714 #ifdef HAVE_WINDOW_SYSTEM
2715 if (FRAME_WINDOW_P (f))
2716 return make_number (FRAME_PIXEL_HEIGHT (f));
2717 else
2718 #endif
2719 return make_number (FRAME_TOTAL_LINES (f));
2722 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2723 Sframe_pixel_width, 0, 1, 0,
2724 doc: /* Return FRAME's width in pixels.
2725 For a terminal frame, the result really gives the width in characters.
2726 If FRAME is omitted or nil, the selected frame is used. */)
2727 (Lisp_Object frame)
2729 struct frame *f = decode_any_frame (frame);
2731 #ifdef HAVE_WINDOW_SYSTEM
2732 if (FRAME_WINDOW_P (f))
2733 return make_number (FRAME_PIXEL_WIDTH (f));
2734 else
2735 #endif
2736 return make_number (FRAME_TOTAL_COLS (f));
2739 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2740 Stool_bar_pixel_width, 0, 1, 0,
2741 doc: /* Return width in pixels of FRAME's tool bar.
2742 The result is greater than zero only when the tool bar is on the left
2743 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2744 is used. */)
2745 (Lisp_Object frame)
2747 #ifdef FRAME_TOOLBAR_WIDTH
2748 struct frame *f = decode_any_frame (frame);
2750 if (FRAME_WINDOW_P (f))
2751 return make_number (FRAME_TOOLBAR_WIDTH (f));
2752 #endif
2753 return make_number (0);
2756 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2757 doc: /* Return width in columns of FRAME's text area. */)
2758 (Lisp_Object frame)
2760 return make_number (FRAME_COLS (decode_any_frame (frame)));
2763 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2764 doc: /* Return height in lines of FRAME's text area. */)
2765 (Lisp_Object frame)
2767 return make_number (FRAME_LINES (decode_any_frame (frame)));
2770 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2771 doc: /* Return number of total columns of FRAME. */)
2772 (Lisp_Object frame)
2774 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2777 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2778 doc: /* Return number of total lines of FRAME. */)
2779 (Lisp_Object frame)
2781 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2784 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2785 doc: /* Return text area width of FRAME in pixels. */)
2786 (Lisp_Object frame)
2788 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2791 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2792 doc: /* Return text area height of FRAME in pixels. */)
2793 (Lisp_Object frame)
2795 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2798 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2799 doc: /* Return scroll bar width of FRAME in pixels. */)
2800 (Lisp_Object frame)
2802 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2805 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2806 doc: /* Return scroll bar height of FRAME in pixels. */)
2807 (Lisp_Object frame)
2809 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2812 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2813 doc: /* Return fringe width of FRAME in pixels. */)
2814 (Lisp_Object frame)
2816 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2819 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2820 doc: /* Return border width of FRAME in pixels. */)
2821 (Lisp_Object frame)
2823 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2826 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2827 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2828 (Lisp_Object frame)
2830 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2833 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2834 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2835 (Lisp_Object frame)
2837 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2840 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2841 doc: /* Specify that the frame FRAME has HEIGHT text lines.
2842 Optional third arg PRETEND non-nil means that redisplay should use
2843 HEIGHT lines but that the idea of the actual height of the frame should
2844 not be changed. Optional fourth argument PIXELWISE non-nil means that
2845 FRAME should be HEIGHT pixels high. */)
2846 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2848 struct frame *f = decode_live_frame (frame);
2849 int pixel_height;
2851 CHECK_TYPE_RANGED_INTEGER (int, height);
2853 pixel_height = (!NILP (pixelwise)
2854 ? XINT (height)
2855 : XINT (height) * FRAME_LINE_HEIGHT (f));
2856 if (pixel_height != FRAME_TEXT_HEIGHT (f))
2857 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend));
2859 return Qnil;
2862 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2863 doc: /* Specify that the frame FRAME has WIDTH columns.
2864 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2865 columns but that the idea of the actual width of the frame should not
2866 be changed. Optional fourth argument PIXELWISE non-nil means that FRAME
2867 should be WIDTH pixels wide. */)
2868 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2870 struct frame *f = decode_live_frame (frame);
2871 int pixel_width;
2873 CHECK_TYPE_RANGED_INTEGER (int, width);
2875 pixel_width = (!NILP (pixelwise)
2876 ? XINT (width)
2877 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2878 if (pixel_width != FRAME_TEXT_WIDTH (f))
2879 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend));
2881 return Qnil;
2884 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2885 doc: /* Sets size of FRAME to WIDTH by HEIGHT, measured in characters.
2886 Optional argument PIXELWISE non-nil means to measure in pixels. */)
2887 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2889 struct frame *f = decode_live_frame (frame);
2890 int pixel_width, pixel_height;
2892 CHECK_TYPE_RANGED_INTEGER (int, width);
2893 CHECK_TYPE_RANGED_INTEGER (int, height);
2895 pixel_width = (!NILP (pixelwise)
2896 ? XINT (width)
2897 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2898 pixel_height = (!NILP (pixelwise)
2899 ? XINT (height)
2900 : XINT (height) * FRAME_LINE_HEIGHT (f));
2902 if (pixel_width != FRAME_TEXT_WIDTH (f)
2903 || pixel_height != FRAME_TEXT_HEIGHT (f))
2904 adjust_frame_size (f, pixel_width, pixel_height, 1, 0);
2906 return Qnil;
2909 DEFUN ("set-frame-position", Fset_frame_position,
2910 Sset_frame_position, 3, 3, 0,
2911 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2912 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2913 actually the position of the upper left corner of the frame. Negative
2914 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2915 or bottommost possible position (that stays within the screen). */)
2916 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2918 register struct frame *f = decode_live_frame (frame);
2920 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2921 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2923 /* I think this should be done with a hook. */
2924 #ifdef HAVE_WINDOW_SYSTEM
2925 if (FRAME_WINDOW_P (f))
2926 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2927 #endif
2929 return Qt;
2933 /***********************************************************************
2934 Frame Parameters
2935 ***********************************************************************/
2937 /* Connect the frame-parameter names for X frames
2938 to the ways of passing the parameter values to the window system.
2940 The name of a parameter, as a Lisp symbol,
2941 has an `x-frame-parameter' property which is an integer in Lisp
2942 that is an index in this table. */
2944 struct frame_parm_table {
2945 const char *name;
2946 Lisp_Object *variable;
2949 static const struct frame_parm_table frame_parms[] =
2951 {"auto-raise", &Qauto_raise},
2952 {"auto-lower", &Qauto_lower},
2953 {"background-color", 0},
2954 {"border-color", &Qborder_color},
2955 {"border-width", &Qborder_width},
2956 {"cursor-color", &Qcursor_color},
2957 {"cursor-type", &Qcursor_type},
2958 {"font", 0},
2959 {"foreground-color", 0},
2960 {"icon-name", &Qicon_name},
2961 {"icon-type", &Qicon_type},
2962 {"internal-border-width", &Qinternal_border_width},
2963 {"right-divider-width", &Qright_divider_width},
2964 {"bottom-divider-width", &Qbottom_divider_width},
2965 {"menu-bar-lines", &Qmenu_bar_lines},
2966 {"mouse-color", &Qmouse_color},
2967 {"name", &Qname},
2968 {"scroll-bar-width", &Qscroll_bar_width},
2969 {"scroll-bar-height", &Qscroll_bar_height},
2970 {"title", &Qtitle},
2971 {"unsplittable", &Qunsplittable},
2972 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2973 {"horizontal-scroll-bars", &Qhorizontal_scroll_bars},
2974 {"visibility", &Qvisibility},
2975 {"tool-bar-lines", &Qtool_bar_lines},
2976 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2977 {"scroll-bar-background", &Qscroll_bar_background},
2978 {"screen-gamma", &Qscreen_gamma},
2979 {"line-spacing", &Qline_spacing},
2980 {"left-fringe", &Qleft_fringe},
2981 {"right-fringe", &Qright_fringe},
2982 {"wait-for-wm", &Qwait_for_wm},
2983 {"fullscreen", &Qfullscreen},
2984 {"font-backend", &Qfont_backend},
2985 {"alpha", &Qalpha},
2986 {"sticky", &Qsticky},
2987 {"tool-bar-position", &Qtool_bar_position},
2990 #ifdef HAVE_WINDOW_SYSTEM
2992 /* Change the parameters of frame F as specified by ALIST.
2993 If a parameter is not specially recognized, do nothing special;
2994 otherwise call the `x_set_...' function for that parameter.
2995 Except for certain geometry properties, always call store_frame_param
2996 to store the new value in the parameter alist. */
2998 void
2999 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3001 Lisp_Object tail;
3003 /* If both of these parameters are present, it's more efficient to
3004 set them both at once. So we wait until we've looked at the
3005 entire list before we set them. */
3006 int width, height IF_LINT (= 0);
3007 bool width_change = 0, height_change = 0;
3009 /* Same here. */
3010 Lisp_Object left, top;
3012 /* Same with these. */
3013 Lisp_Object icon_left, icon_top;
3015 /* Record in these vectors all the parms specified. */
3016 Lisp_Object *parms;
3017 Lisp_Object *values;
3018 ptrdiff_t i, p;
3019 bool left_no_change = 0, top_no_change = 0;
3020 #ifdef HAVE_X_WINDOWS
3021 bool icon_left_no_change = 0, icon_top_no_change = 0;
3022 #endif
3024 i = 0;
3025 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3026 i++;
3028 USE_SAFE_ALLOCA;
3029 SAFE_ALLOCA_LISP (parms, 2 * i);
3030 values = parms + i;
3032 /* Extract parm names and values into those vectors. */
3034 i = 0;
3035 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3037 Lisp_Object elt;
3039 elt = XCAR (tail);
3040 parms[i] = Fcar (elt);
3041 values[i] = Fcdr (elt);
3042 i++;
3044 /* TAIL and ALIST are not used again below here. */
3045 alist = tail = Qnil;
3047 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
3048 because their values appear in VALUES and strings are not valid. */
3049 top = left = Qunbound;
3050 icon_left = icon_top = Qunbound;
3052 /* Process foreground_color and background_color before anything else.
3053 They are independent of other properties, but other properties (e.g.,
3054 cursor_color) are dependent upon them. */
3055 /* Process default font as well, since fringe widths depends on it. */
3056 for (p = 0; p < i; p++)
3058 Lisp_Object prop, val;
3060 prop = parms[p];
3061 val = values[p];
3062 if (EQ (prop, Qforeground_color)
3063 || EQ (prop, Qbackground_color)
3064 || EQ (prop, Qfont))
3066 register Lisp_Object param_index, old_value;
3068 old_value = get_frame_param (f, prop);
3069 if (NILP (Fequal (val, old_value)))
3071 store_frame_param (f, prop, val);
3073 param_index = Fget (prop, Qx_frame_parameter);
3074 if (NATNUMP (param_index)
3075 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3076 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3077 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3082 /* Now process them in reverse of specified order. */
3083 while (i-- != 0)
3085 Lisp_Object prop, val;
3087 prop = parms[i];
3088 val = values[i];
3090 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
3092 width_change = 1;
3093 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3095 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
3097 height_change = 1;
3098 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3100 else if (EQ (prop, Qtop))
3101 top = val;
3102 else if (EQ (prop, Qleft))
3103 left = val;
3104 else if (EQ (prop, Qicon_top))
3105 icon_top = val;
3106 else if (EQ (prop, Qicon_left))
3107 icon_left = val;
3108 else if (EQ (prop, Qforeground_color)
3109 || EQ (prop, Qbackground_color)
3110 || EQ (prop, Qfont))
3111 /* Processed above. */
3112 continue;
3113 else
3115 register Lisp_Object param_index, old_value;
3117 old_value = get_frame_param (f, prop);
3119 store_frame_param (f, prop, val);
3121 param_index = Fget (prop, Qx_frame_parameter);
3122 if (NATNUMP (param_index)
3123 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3124 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3125 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3129 /* Don't die if just one of these was set. */
3130 if (EQ (left, Qunbound))
3132 left_no_change = 1;
3133 if (f->left_pos < 0)
3134 left = list2 (Qplus, make_number (f->left_pos));
3135 else
3136 XSETINT (left, f->left_pos);
3138 if (EQ (top, Qunbound))
3140 top_no_change = 1;
3141 if (f->top_pos < 0)
3142 top = list2 (Qplus, make_number (f->top_pos));
3143 else
3144 XSETINT (top, f->top_pos);
3147 /* If one of the icon positions was not set, preserve or default it. */
3148 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3150 #ifdef HAVE_X_WINDOWS
3151 icon_left_no_change = 1;
3152 #endif
3153 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3154 if (NILP (icon_left))
3155 XSETINT (icon_left, 0);
3157 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3159 #ifdef HAVE_X_WINDOWS
3160 icon_top_no_change = 1;
3161 #endif
3162 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3163 if (NILP (icon_top))
3164 XSETINT (icon_top, 0);
3167 /* Don't set these parameters unless they've been explicitly
3168 specified. The window might be mapped or resized while we're in
3169 this function, and we don't want to override that unless the lisp
3170 code has asked for it.
3172 Don't set these parameters unless they actually differ from the
3173 window's current parameters; the window may not actually exist
3174 yet. */
3176 Lisp_Object frame;
3178 XSETFRAME (frame, f);
3180 if ((width_change && width != FRAME_TEXT_WIDTH (f))
3181 || (height_change && height != FRAME_TEXT_HEIGHT (f))
3182 || f->new_height || f->new_width)
3184 /* If necessary provide default values for HEIGHT and WIDTH. Do
3185 that here since otherwise a size change implied by an
3186 intermittent font change may get lost as in Bug#17142. */
3187 if (!width_change)
3188 width = (f->new_width
3189 ? (f->new_pixelwise
3190 ? f->new_width
3191 : (f->new_width * FRAME_COLUMN_WIDTH (f)))
3192 : FRAME_TEXT_WIDTH (f));
3194 if (!height_change)
3195 height = (f->new_height
3196 ? (f->new_pixelwise
3197 ? f->new_height
3198 : (f->new_height * FRAME_LINE_HEIGHT (f)))
3199 : FRAME_TEXT_HEIGHT (f));
3201 Fset_frame_size (frame, make_number (width), make_number (height), Qt);
3204 if ((!NILP (left) || !NILP (top))
3205 && ! (left_no_change && top_no_change)
3206 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3207 && NUMBERP (top) && XINT (top) == f->top_pos))
3209 int leftpos = 0;
3210 int toppos = 0;
3212 /* Record the signs. */
3213 f->size_hint_flags &= ~ (XNegative | YNegative);
3214 if (EQ (left, Qminus))
3215 f->size_hint_flags |= XNegative;
3216 else if (TYPE_RANGED_INTEGERP (int, left))
3218 leftpos = XINT (left);
3219 if (leftpos < 0)
3220 f->size_hint_flags |= XNegative;
3222 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3223 && CONSP (XCDR (left))
3224 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3226 leftpos = - XINT (XCAR (XCDR (left)));
3227 f->size_hint_flags |= XNegative;
3229 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3230 && CONSP (XCDR (left))
3231 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3233 leftpos = XINT (XCAR (XCDR (left)));
3236 if (EQ (top, Qminus))
3237 f->size_hint_flags |= YNegative;
3238 else if (TYPE_RANGED_INTEGERP (int, top))
3240 toppos = XINT (top);
3241 if (toppos < 0)
3242 f->size_hint_flags |= YNegative;
3244 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3245 && CONSP (XCDR (top))
3246 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3248 toppos = - XINT (XCAR (XCDR (top)));
3249 f->size_hint_flags |= YNegative;
3251 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3252 && CONSP (XCDR (top))
3253 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3255 toppos = XINT (XCAR (XCDR (top)));
3259 /* Store the numeric value of the position. */
3260 f->top_pos = toppos;
3261 f->left_pos = leftpos;
3263 f->win_gravity = NorthWestGravity;
3265 /* Actually set that position, and convert to absolute. */
3266 x_set_offset (f, leftpos, toppos, -1);
3268 #ifdef HAVE_X_WINDOWS
3269 if ((!NILP (icon_left) || !NILP (icon_top))
3270 && ! (icon_left_no_change && icon_top_no_change))
3271 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3272 #endif /* HAVE_X_WINDOWS */
3275 SAFE_FREE ();
3279 /* Insert a description of internally-recorded parameters of frame X
3280 into the parameter alist *ALISTPTR that is to be given to the user.
3281 Only parameters that are specific to the X window system
3282 and whose values are not correctly recorded in the frame's
3283 param_alist need to be considered here. */
3285 void
3286 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3288 Lisp_Object tem;
3289 uprintmax_t w;
3290 char buf[INT_BUFSIZE_BOUND (w)];
3292 /* Represent negative positions (off the top or left screen edge)
3293 in a way that Fmodify_frame_parameters will understand correctly. */
3294 XSETINT (tem, f->left_pos);
3295 if (f->left_pos >= 0)
3296 store_in_alist (alistptr, Qleft, tem);
3297 else
3298 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3300 XSETINT (tem, f->top_pos);
3301 if (f->top_pos >= 0)
3302 store_in_alist (alistptr, Qtop, tem);
3303 else
3304 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3306 store_in_alist (alistptr, Qborder_width,
3307 make_number (f->border_width));
3308 store_in_alist (alistptr, Qinternal_border_width,
3309 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3310 store_in_alist (alistptr, Qright_divider_width,
3311 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3312 store_in_alist (alistptr, Qbottom_divider_width,
3313 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3314 store_in_alist (alistptr, Qleft_fringe,
3315 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3316 store_in_alist (alistptr, Qright_fringe,
3317 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3318 store_in_alist (alistptr, Qscroll_bar_width,
3319 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3320 ? make_number (0)
3321 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3322 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3323 /* nil means "use default width"
3324 for non-toolkit scroll bar.
3325 ruler-mode.el depends on this. */
3326 : Qnil));
3327 store_in_alist (alistptr, Qscroll_bar_height,
3328 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3329 ? make_number (0)
3330 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3331 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3332 /* nil means "use default height"
3333 for non-toolkit scroll bar. */
3334 : Qnil));
3335 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3336 MS-Windows it returns a value whose type is HANDLE, which is
3337 actually a pointer. Explicit casting avoids compiler
3338 warnings. */
3339 w = (uintptr_t) FRAME_X_WINDOW (f);
3340 store_in_alist (alistptr, Qwindow_id,
3341 make_formatted_string (buf, "%"pMu, w));
3342 #ifdef HAVE_X_WINDOWS
3343 #ifdef USE_X_TOOLKIT
3344 /* Tooltip frame may not have this widget. */
3345 if (FRAME_X_OUTPUT (f)->widget)
3346 #endif
3347 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3348 store_in_alist (alistptr, Qouter_window_id,
3349 make_formatted_string (buf, "%"pMu, w));
3350 #endif
3351 store_in_alist (alistptr, Qicon_name, f->icon_name);
3352 store_in_alist (alistptr, Qvisibility,
3353 (FRAME_VISIBLE_P (f) ? Qt
3354 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3355 store_in_alist (alistptr, Qdisplay,
3356 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3358 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3359 tem = Qnil;
3360 else
3361 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3362 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3363 store_in_alist (alistptr, Qparent_id, tem);
3364 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3368 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3369 the previous value of that parameter, NEW_VALUE is the new value. */
3371 void
3372 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3374 if (NILP (new_value))
3375 f->want_fullscreen = FULLSCREEN_NONE;
3376 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3377 f->want_fullscreen = FULLSCREEN_BOTH;
3378 else if (EQ (new_value, Qfullwidth))
3379 f->want_fullscreen = FULLSCREEN_WIDTH;
3380 else if (EQ (new_value, Qfullheight))
3381 f->want_fullscreen = FULLSCREEN_HEIGHT;
3382 else if (EQ (new_value, Qmaximized))
3383 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3385 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3386 FRAME_TERMINAL (f)->fullscreen_hook (f);
3390 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3391 the previous value of that parameter, NEW_VALUE is the new value. */
3393 void
3394 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3396 if (NILP (new_value))
3397 f->extra_line_spacing = 0;
3398 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3399 f->extra_line_spacing = XFASTINT (new_value);
3400 else if (FLOATP (new_value))
3402 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3404 if (new_spacing >= 0)
3405 f->extra_line_spacing = new_spacing;
3406 else
3407 signal_error ("Invalid line-spacing", new_value);
3409 else
3410 signal_error ("Invalid line-spacing", new_value);
3411 if (FRAME_VISIBLE_P (f))
3412 redraw_frame (f);
3416 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3417 the previous value of that parameter, NEW_VALUE is the new value. */
3419 void
3420 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3422 Lisp_Object bgcolor;
3424 if (NILP (new_value))
3425 f->gamma = 0;
3426 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3427 /* The value 0.4545 is the normal viewing gamma. */
3428 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3429 else
3430 signal_error ("Invalid screen-gamma", new_value);
3432 /* Apply the new gamma value to the frame background. */
3433 bgcolor = Fassq (Qbackground_color, f->param_alist);
3434 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3436 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3437 if (NATNUMP (parm_index)
3438 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3439 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3440 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3441 (f, bgcolor, Qnil);
3444 Fclear_face_cache (Qnil);
3448 void
3449 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3451 Lisp_Object font_object;
3452 int fontset = -1;
3453 #ifdef HAVE_X_WINDOWS
3454 Lisp_Object font_param = arg;
3455 #endif
3457 /* Set the frame parameter back to the old value because we may
3458 fail to use ARG as the new parameter value. */
3459 store_frame_param (f, Qfont, oldval);
3461 /* ARG is a fontset name, a font name, a cons of fontset name and a
3462 font object, or a font object. In the last case, this function
3463 never fail. */
3464 if (STRINGP (arg))
3466 fontset = fs_query_fontset (arg, 0);
3467 if (fontset < 0)
3469 font_object = font_open_by_name (f, arg);
3470 if (NILP (font_object))
3471 error ("Font `%s' is not defined", SSDATA (arg));
3472 arg = AREF (font_object, FONT_NAME_INDEX);
3474 else if (fontset > 0)
3476 font_object = font_open_by_name (f, fontset_ascii (fontset));
3477 if (NILP (font_object))
3478 error ("Font `%s' is not defined", SDATA (arg));
3479 arg = AREF (font_object, FONT_NAME_INDEX);
3481 else
3482 error ("The default fontset can't be used for a frame font");
3484 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3486 /* This is the case that the ASCII font of F's fontset XCAR
3487 (arg) is changed to the font XCDR (arg) by
3488 `set-fontset-font'. */
3489 fontset = fs_query_fontset (XCAR (arg), 0);
3490 if (fontset < 0)
3491 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3492 font_object = XCDR (arg);
3493 arg = AREF (font_object, FONT_NAME_INDEX);
3494 #ifdef HAVE_X_WINDOWS
3495 font_param = Ffont_get (font_object, QCname);
3496 #endif
3498 else if (FONT_OBJECT_P (arg))
3500 font_object = arg;
3501 #ifdef HAVE_X_WINDOWS
3502 font_param = Ffont_get (font_object, QCname);
3503 #endif
3504 /* This is to store the XLFD font name in the frame parameter for
3505 backward compatibility. We should store the font-object
3506 itself in the future. */
3507 arg = AREF (font_object, FONT_NAME_INDEX);
3508 fontset = FRAME_FONTSET (f);
3509 /* Check if we can use the current fontset. If not, set FONTSET
3510 to -1 to generate a new fontset from FONT-OBJECT. */
3511 if (fontset >= 0)
3513 Lisp_Object ascii_font = fontset_ascii (fontset);
3514 Lisp_Object spec = font_spec_from_name (ascii_font);
3516 if (NILP (spec))
3517 signal_error ("Invalid font name", ascii_font);
3519 if (! font_match_p (spec, font_object))
3520 fontset = -1;
3523 else
3524 signal_error ("Invalid font", arg);
3526 if (! NILP (Fequal (font_object, oldval)))
3527 return;
3529 x_new_font (f, font_object, fontset);
3530 store_frame_param (f, Qfont, arg);
3531 #ifdef HAVE_X_WINDOWS
3532 store_frame_param (f, Qfont_param, font_param);
3533 #endif
3534 /* Recalculate toolbar height. */
3535 f->n_tool_bar_rows = 0;
3537 /* Ensure we redraw it. */
3538 clear_current_matrices (f);
3540 /* Attempt to hunt down bug#16028. */
3541 SET_FRAME_GARBAGED (f);
3543 recompute_basic_faces (f);
3545 do_pending_window_change (0);
3547 /* We used to call face-set-after-frame-default here, but it leads to
3548 recursive calls (since that function can set the `default' face's
3549 font which in turns changes the frame's `font' parameter).
3550 Also I don't know what this call is meant to do, but it seems the
3551 wrong way to do it anyway (it does a lot more work than what seems
3552 reasonable in response to a change to `font'). */
3556 void
3557 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3559 if (! NILP (new_value)
3560 && !CONSP (new_value))
3562 char *p0, *p1;
3564 CHECK_STRING (new_value);
3565 p0 = p1 = SSDATA (new_value);
3566 new_value = Qnil;
3567 while (*p0)
3569 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3570 if (p0 < p1)
3571 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3572 new_value);
3573 if (*p1)
3575 int c;
3577 while ((c = *++p1) && c_isspace (c));
3579 p0 = p1;
3581 new_value = Fnreverse (new_value);
3584 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3585 return;
3587 if (FRAME_FONT (f))
3588 free_all_realized_faces (Qnil);
3590 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3591 if (NILP (new_value))
3593 if (NILP (old_value))
3594 error ("No font backend available");
3595 font_update_drivers (f, old_value);
3596 error ("None of specified font backends are available");
3598 store_frame_param (f, Qfont_backend, new_value);
3600 if (FRAME_FONT (f))
3602 Lisp_Object frame;
3604 XSETFRAME (frame, f);
3605 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3606 ++face_change_count;
3607 windows_or_buffers_changed = 18;
3611 void
3612 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3614 int unit = FRAME_COLUMN_WIDTH (f);
3615 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3616 int new_width;
3618 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3619 ? eabs (XINT (new_value)) : 8);
3621 if (new_width != old_width)
3623 FRAME_LEFT_FRINGE_WIDTH (f) = new_width;
3624 FRAME_FRINGE_COLS (f) /* Round up. */
3625 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3627 if (FRAME_X_WINDOW (f) != 0)
3628 adjust_frame_size (f, -1, -1, 3, 0);
3630 SET_FRAME_GARBAGED (f);
3635 void
3636 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3638 int unit = FRAME_COLUMN_WIDTH (f);
3639 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3640 int new_width;
3642 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3643 ? eabs (XINT (new_value)) : 8);
3645 if (new_width != old_width)
3647 FRAME_RIGHT_FRINGE_WIDTH (f) = new_width;
3648 FRAME_FRINGE_COLS (f) /* Round up. */
3649 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3651 if (FRAME_X_WINDOW (f) != 0)
3652 adjust_frame_size (f, -1, -1, 3, 0);
3654 SET_FRAME_GARBAGED (f);
3659 void
3660 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3662 CHECK_TYPE_RANGED_INTEGER (int, arg);
3664 if (XINT (arg) == f->border_width)
3665 return;
3667 if (FRAME_X_WINDOW (f) != 0)
3668 error ("Cannot change the border width of a frame");
3670 f->border_width = XINT (arg);
3673 void
3674 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3676 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3678 CHECK_TYPE_RANGED_INTEGER (int, arg);
3679 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3680 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3681 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3682 if (FRAME_RIGHT_DIVIDER_WIDTH (f) != old)
3684 adjust_frame_size (f, -1, -1, 4, 0);
3685 adjust_frame_glyphs (f);
3686 SET_FRAME_GARBAGED (f);
3691 void
3692 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3694 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3696 CHECK_TYPE_RANGED_INTEGER (int, arg);
3697 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3698 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3699 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3700 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) != old)
3702 adjust_frame_size (f, -1, -1, 4, 0);
3703 adjust_frame_glyphs (f);
3704 SET_FRAME_GARBAGED (f);
3708 void
3709 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3711 Lisp_Object frame;
3712 XSETFRAME (frame, f);
3714 if (NILP (value))
3715 Fmake_frame_invisible (frame, Qt);
3716 else if (EQ (value, Qicon))
3717 Ficonify_frame (frame);
3718 else
3719 Fmake_frame_visible (frame);
3722 void
3723 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3725 f->auto_raise = !EQ (Qnil, arg);
3728 void
3729 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3731 f->auto_lower = !EQ (Qnil, arg);
3734 void
3735 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3737 f->no_split = !NILP (arg);
3740 void
3741 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3743 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3744 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3745 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3746 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3748 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3749 = (NILP (arg)
3750 ? vertical_scroll_bar_none
3751 : EQ (Qleft, arg)
3752 ? vertical_scroll_bar_left
3753 : EQ (Qright, arg)
3754 ? vertical_scroll_bar_right
3755 : EQ (Qleft, Vdefault_frame_scroll_bars)
3756 ? vertical_scroll_bar_left
3757 : EQ (Qright, Vdefault_frame_scroll_bars)
3758 ? vertical_scroll_bar_right
3759 : vertical_scroll_bar_none);
3761 /* We set this parameter before creating the X window for the
3762 frame, so we can get the geometry right from the start.
3763 However, if the window hasn't been created yet, we shouldn't
3764 call x_set_window_size. */
3765 if (FRAME_X_WINDOW (f))
3766 adjust_frame_size (f, -1, -1, 3, 0);
3768 SET_FRAME_GARBAGED (f);
3772 void
3773 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3775 #if USE_HORIZONTAL_SCROLL_BARS
3776 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3777 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3779 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3781 /* We set this parameter before creating the X window for the
3782 frame, so we can get the geometry right from the start.
3783 However, if the window hasn't been created yet, we shouldn't
3784 call x_set_window_size. */
3785 if (FRAME_X_WINDOW (f))
3786 adjust_frame_size (f, -1, -1, 3, 0);
3788 SET_FRAME_GARBAGED (f);
3790 #endif
3793 void
3794 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3796 int unit = FRAME_COLUMN_WIDTH (f);
3798 if (NILP (arg))
3800 x_set_scroll_bar_default_width (f);
3802 if (FRAME_X_WINDOW (f))
3803 adjust_frame_size (f, -1, -1, 3, 0);
3805 SET_FRAME_GARBAGED (f);
3807 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3808 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3810 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3811 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3812 if (FRAME_X_WINDOW (f))
3813 adjust_frame_size (f, -1, -1, 3, 0);
3815 SET_FRAME_GARBAGED (f);
3818 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3819 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3822 void
3823 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3825 #if USE_HORIZONTAL_SCROLL_BARS
3826 int unit = FRAME_LINE_HEIGHT (f);
3828 if (NILP (arg))
3830 x_set_scroll_bar_default_height (f);
3832 if (FRAME_X_WINDOW (f))
3833 adjust_frame_size (f, -1, -1, 3, 0);
3835 SET_FRAME_GARBAGED (f);
3837 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3838 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3840 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3841 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3842 if (FRAME_X_WINDOW (f))
3843 adjust_frame_size (f, -1, -1, 3, 0);
3845 SET_FRAME_GARBAGED (f);
3848 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3849 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3850 #endif
3853 void
3854 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3856 double alpha = 1.0;
3857 double newval[2];
3858 int i;
3859 Lisp_Object item;
3861 for (i = 0; i < 2; i++)
3863 newval[i] = 1.0;
3864 if (CONSP (arg))
3866 item = CAR (arg);
3867 arg = CDR (arg);
3869 else
3870 item = arg;
3872 if (NILP (item))
3873 alpha = - 1.0;
3874 else if (FLOATP (item))
3876 alpha = XFLOAT_DATA (item);
3877 if (! (0 <= alpha && alpha <= 1.0))
3878 args_out_of_range (make_float (0.0), make_float (1.0));
3880 else if (INTEGERP (item))
3882 EMACS_INT ialpha = XINT (item);
3883 if (! (0 <= ialpha && alpha <= 100))
3884 args_out_of_range (make_number (0), make_number (100));
3885 alpha = ialpha / 100.0;
3887 else
3888 wrong_type_argument (Qnumberp, item);
3889 newval[i] = alpha;
3892 for (i = 0; i < 2; i++)
3893 f->alpha[i] = newval[i];
3895 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3896 block_input ();
3897 x_set_frame_alpha (f);
3898 unblock_input ();
3899 #endif
3901 return;
3904 #ifndef HAVE_NS
3906 /* Non-zero if mouse is grabbed on DPYINFO
3907 and we know the frame where it is. */
3909 bool x_mouse_grabbed (Display_Info *dpyinfo)
3911 return (dpyinfo->grabbed
3912 && dpyinfo->last_mouse_frame
3913 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
3916 /* Re-highlight something with mouse-face properties
3917 on DPYINFO using saved frame and mouse position. */
3919 void
3920 x_redo_mouse_highlight (Display_Info *dpyinfo)
3922 if (dpyinfo->last_mouse_motion_frame
3923 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
3924 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
3925 dpyinfo->last_mouse_motion_x,
3926 dpyinfo->last_mouse_motion_y);
3929 #endif /* HAVE_NS */
3931 /* Subroutines of creating an X frame. */
3933 /* Make sure that Vx_resource_name is set to a reasonable value.
3934 Fix it up, or set it to `emacs' if it is too hopeless. */
3936 void
3937 validate_x_resource_name (void)
3939 ptrdiff_t len = 0;
3940 /* Number of valid characters in the resource name. */
3941 ptrdiff_t good_count = 0;
3942 /* Number of invalid characters in the resource name. */
3943 ptrdiff_t bad_count = 0;
3944 Lisp_Object new;
3945 ptrdiff_t i;
3947 if (!STRINGP (Vx_resource_class))
3948 Vx_resource_class = build_string (EMACS_CLASS);
3950 if (STRINGP (Vx_resource_name))
3952 unsigned char *p = SDATA (Vx_resource_name);
3954 len = SBYTES (Vx_resource_name);
3956 /* Only letters, digits, - and _ are valid in resource names.
3957 Count the valid characters and count the invalid ones. */
3958 for (i = 0; i < len; i++)
3960 int c = p[i];
3961 if (! ((c >= 'a' && c <= 'z')
3962 || (c >= 'A' && c <= 'Z')
3963 || (c >= '0' && c <= '9')
3964 || c == '-' || c == '_'))
3965 bad_count++;
3966 else
3967 good_count++;
3970 else
3971 /* Not a string => completely invalid. */
3972 bad_count = 5, good_count = 0;
3974 /* If name is valid already, return. */
3975 if (bad_count == 0)
3976 return;
3978 /* If name is entirely invalid, or nearly so, or is so implausibly
3979 large that alloca might not work, use `emacs'. */
3980 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3982 Vx_resource_name = build_string ("emacs");
3983 return;
3986 /* Name is partly valid. Copy it and replace the invalid characters
3987 with underscores. */
3989 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3991 for (i = 0; i < len; i++)
3993 int c = SREF (new, i);
3994 if (! ((c >= 'a' && c <= 'z')
3995 || (c >= 'A' && c <= 'Z')
3996 || (c >= '0' && c <= '9')
3997 || c == '-' || c == '_'))
3998 SSET (new, i, '_');
4002 /* Get specified attribute from resource database RDB.
4003 See Fx_get_resource below for other parameters. */
4005 static Lisp_Object
4006 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4008 CHECK_STRING (attribute);
4009 CHECK_STRING (class);
4011 if (!NILP (component))
4012 CHECK_STRING (component);
4013 if (!NILP (subclass))
4014 CHECK_STRING (subclass);
4015 if (NILP (component) != NILP (subclass))
4016 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4018 validate_x_resource_name ();
4020 /* Allocate space for the components, the dots which separate them,
4021 and the final '\0'. Make them big enough for the worst case. */
4022 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4023 + (STRINGP (component)
4024 ? SBYTES (component) : 0)
4025 + SBYTES (attribute)
4026 + 3);
4028 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4029 + SBYTES (class)
4030 + (STRINGP (subclass)
4031 ? SBYTES (subclass) : 0)
4032 + 3);
4033 USE_SAFE_ALLOCA;
4034 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4035 char *class_key = name_key + name_keysize;
4037 /* Start with emacs.FRAMENAME for the name (the specific one)
4038 and with `Emacs' for the class key (the general one). */
4039 strcpy (name_key, SSDATA (Vx_resource_name));
4040 strcpy (class_key, SSDATA (Vx_resource_class));
4042 strcat (class_key, ".");
4043 strcat (class_key, SSDATA (class));
4045 if (!NILP (component))
4047 strcat (class_key, ".");
4048 strcat (class_key, SSDATA (subclass));
4050 strcat (name_key, ".");
4051 strcat (name_key, SSDATA (component));
4054 strcat (name_key, ".");
4055 strcat (name_key, SSDATA (attribute));
4057 char *value = x_get_string_resource (rdb, name_key, class_key);
4058 SAFE_FREE();
4060 if (value && *value)
4061 return build_string (value);
4062 else
4063 return Qnil;
4067 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4068 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4069 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4070 class, where INSTANCE is the name under which Emacs was invoked, or
4071 the name specified by the `-name' or `-rn' command-line arguments.
4073 The optional arguments COMPONENT and SUBCLASS add to the key and the
4074 class, respectively. You must specify both of them or neither.
4075 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4076 and the class is `Emacs.CLASS.SUBCLASS'. */)
4077 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4078 Lisp_Object subclass)
4080 check_window_system (NULL);
4082 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4083 attribute, class, component, subclass);
4086 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4088 Lisp_Object
4089 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4090 Lisp_Object class, Lisp_Object component,
4091 Lisp_Object subclass)
4093 return xrdb_get_resource (dpyinfo->xrdb,
4094 attribute, class, component, subclass);
4097 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
4098 /* Used when C code wants a resource value. */
4099 /* Called from oldXMenu/Create.c. */
4100 char *
4101 x_get_resource_string (const char *attribute, const char *class)
4103 char *result;
4104 struct frame *sf = SELECTED_FRAME ();
4105 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4106 USE_SAFE_ALLOCA;
4108 /* Allocate space for the components, the dots which separate them,
4109 and the final '\0'. */
4110 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4111 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4112 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4113 char *class_key = name_key + name_keysize;
4115 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4116 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4118 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4119 name_key, class_key);
4120 SAFE_FREE ();
4121 return result;
4123 #endif
4125 /* Return the value of parameter PARAM.
4127 First search ALIST, then Vdefault_frame_alist, then the X defaults
4128 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4130 Convert the resource to the type specified by desired_type.
4132 If no default is specified, return Qunbound. If you call
4133 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4134 and don't let it get stored in any Lisp-visible variables! */
4136 Lisp_Object
4137 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4138 const char *attribute, const char *class, enum resource_types type)
4140 register Lisp_Object tem;
4142 tem = Fassq (param, alist);
4144 if (!NILP (tem))
4146 /* If we find this parm in ALIST, clear it out
4147 so that it won't be "left over" at the end. */
4148 Lisp_Object tail;
4149 XSETCAR (tem, Qnil);
4150 /* In case the parameter appears more than once in the alist,
4151 clear it out. */
4152 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4153 if (CONSP (XCAR (tail))
4154 && EQ (XCAR (XCAR (tail)), param))
4155 XSETCAR (XCAR (tail), Qnil);
4157 else
4158 tem = Fassq (param, Vdefault_frame_alist);
4160 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4161 look in the X resources. */
4162 if (EQ (tem, Qnil))
4164 if (attribute && dpyinfo)
4166 tem = display_x_get_resource
4167 (dpyinfo, build_local_string (attribute),
4168 build_local_string (class), Qnil, Qnil);
4170 if (NILP (tem))
4171 return Qunbound;
4173 switch (type)
4175 case RES_TYPE_NUMBER:
4176 return make_number (atoi (SSDATA (tem)));
4178 case RES_TYPE_BOOLEAN_NUMBER:
4179 if (!strcmp (SSDATA (tem), "on")
4180 || !strcmp (SSDATA (tem), "true"))
4181 return make_number (1);
4182 return make_number (atoi (SSDATA (tem)));
4183 break;
4185 case RES_TYPE_FLOAT:
4186 return make_float (atof (SSDATA (tem)));
4188 case RES_TYPE_BOOLEAN:
4189 tem = Fdowncase (tem);
4190 if (!strcmp (SSDATA (tem), "on")
4191 #ifdef HAVE_NS
4192 || !strcmp (SSDATA (tem), "yes")
4193 #endif
4194 || !strcmp (SSDATA (tem), "true"))
4195 return Qt;
4196 else
4197 return Qnil;
4199 case RES_TYPE_STRING:
4200 return tem;
4202 case RES_TYPE_SYMBOL:
4203 /* As a special case, we map the values `true' and `on'
4204 to Qt, and `false' and `off' to Qnil. */
4206 Lisp_Object lower;
4207 lower = Fdowncase (tem);
4208 if (!strcmp (SSDATA (lower), "on")
4209 #ifdef HAVE_NS
4210 || !strcmp (SSDATA (lower), "yes")
4211 #endif
4212 || !strcmp (SSDATA (lower), "true"))
4213 return Qt;
4214 else if (!strcmp (SSDATA (lower), "off")
4215 #ifdef HAVE_NS
4216 || !strcmp (SSDATA (lower), "no")
4217 #endif
4218 || !strcmp (SSDATA (lower), "false"))
4219 return Qnil;
4220 else
4221 return Fintern (tem, Qnil);
4224 default:
4225 emacs_abort ();
4228 else
4229 return Qunbound;
4231 return Fcdr (tem);
4234 static Lisp_Object
4235 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4236 const char *attribute, const char *class,
4237 enum resource_types type)
4239 return x_get_arg (FRAME_DISPLAY_INFO (f),
4240 alist, param, attribute, class, type);
4243 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4245 Lisp_Object
4246 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4247 Lisp_Object param,
4248 const char *attribute, const char *class,
4249 enum resource_types type)
4251 Lisp_Object value;
4253 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4254 attribute, class, type);
4255 if (! NILP (value) && ! EQ (value, Qunbound))
4256 store_frame_param (f, param, value);
4258 return value;
4262 /* Record in frame F the specified or default value according to ALIST
4263 of the parameter named PROP (a Lisp symbol).
4264 If no value is specified for PROP, look for an X default for XPROP
4265 on the frame named NAME.
4266 If that is not found either, use the value DEFLT. */
4268 Lisp_Object
4269 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4270 Lisp_Object deflt, const char *xprop, const char *xclass,
4271 enum resource_types type)
4273 Lisp_Object tem;
4275 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4276 if (EQ (tem, Qunbound))
4277 tem = deflt;
4278 x_set_frame_parameters (f, FRAME_PARAMETER (prop, tem));
4279 return tem;
4283 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4286 * XParseGeometry parses strings of the form
4287 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4288 * width, height, xoffset, and yoffset are unsigned integers.
4289 * Example: "=80x24+300-49"
4290 * The equal sign is optional.
4291 * It returns a bitmask that indicates which of the four values
4292 * were actually found in the string. For each value found,
4293 * the corresponding argument is updated; for each value
4294 * not found, the corresponding argument is left unchanged.
4297 static int
4298 XParseGeometry (char *string,
4299 int *x, int *y,
4300 unsigned int *width, unsigned int *height)
4302 int mask = NoValue;
4303 char *strind;
4304 unsigned long tempWidth, tempHeight;
4305 long int tempX, tempY;
4306 char *nextCharacter;
4308 if (string == NULL || *string == '\0')
4309 return mask;
4310 if (*string == '=')
4311 string++; /* ignore possible '=' at beg of geometry spec */
4313 strind = string;
4314 if (*strind != '+' && *strind != '-' && *strind != 'x')
4316 tempWidth = strtoul (strind, &nextCharacter, 10);
4317 if (strind == nextCharacter)
4318 return 0;
4319 strind = nextCharacter;
4320 mask |= WidthValue;
4323 if (*strind == 'x' || *strind == 'X')
4325 strind++;
4326 tempHeight = strtoul (strind, &nextCharacter, 10);
4327 if (strind == nextCharacter)
4328 return 0;
4329 strind = nextCharacter;
4330 mask |= HeightValue;
4333 if (*strind == '+' || *strind == '-')
4335 if (*strind == '-')
4336 mask |= XNegative;
4337 tempX = strtol (strind, &nextCharacter, 10);
4338 if (strind == nextCharacter)
4339 return 0;
4340 strind = nextCharacter;
4341 mask |= XValue;
4342 if (*strind == '+' || *strind == '-')
4344 if (*strind == '-')
4345 mask |= YNegative;
4346 tempY = strtol (strind, &nextCharacter, 10);
4347 if (strind == nextCharacter)
4348 return 0;
4349 strind = nextCharacter;
4350 mask |= YValue;
4354 /* If strind isn't at the end of the string then it's an invalid
4355 geometry specification. */
4357 if (*strind != '\0')
4358 return 0;
4360 if (mask & XValue)
4361 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4362 if (mask & YValue)
4363 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4364 if (mask & WidthValue)
4365 *width = min (tempWidth, UINT_MAX);
4366 if (mask & HeightValue)
4367 *height = min (tempHeight, UINT_MAX);
4368 return mask;
4371 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4374 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4375 make-docfile: the documentation string in ns-win.el was used for
4376 x-parse-geometry even in non-NS builds.
4378 With two definitions of x-parse-geometry in this file, various
4379 things still get confused (eg M-x apropos documentation), so that
4380 it is best if the two definitions just share the same doc-string.
4382 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4383 doc: /* Parse a display geometry string STRING.
4384 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4385 The properties returned may include `top', `left', `height', and `width'.
4386 For X, the value of `left' or `top' may be an integer,
4387 or a list (+ N) meaning N pixels relative to top/left corner,
4388 or a list (- N) meaning -N pixels relative to bottom/right corner.
4389 On Nextstep, this just calls `ns-parse-geometry'. */)
4390 (Lisp_Object string)
4392 int geometry, x, y;
4393 unsigned int width, height;
4394 Lisp_Object result;
4396 CHECK_STRING (string);
4398 #ifdef HAVE_NS
4399 if (strchr (SSDATA (string), ' ') != NULL)
4400 return call1 (Qns_parse_geometry, string);
4401 #endif
4402 geometry = XParseGeometry (SSDATA (string),
4403 &x, &y, &width, &height);
4404 result = Qnil;
4405 if (geometry & XValue)
4407 Lisp_Object element;
4409 if (x >= 0 && (geometry & XNegative))
4410 element = list3 (Qleft, Qminus, make_number (-x));
4411 else if (x < 0 && ! (geometry & XNegative))
4412 element = list3 (Qleft, Qplus, make_number (x));
4413 else
4414 element = Fcons (Qleft, make_number (x));
4415 result = Fcons (element, result);
4418 if (geometry & YValue)
4420 Lisp_Object element;
4422 if (y >= 0 && (geometry & YNegative))
4423 element = list3 (Qtop, Qminus, make_number (-y));
4424 else if (y < 0 && ! (geometry & YNegative))
4425 element = list3 (Qtop, Qplus, make_number (y));
4426 else
4427 element = Fcons (Qtop, make_number (y));
4428 result = Fcons (element, result);
4431 if (geometry & WidthValue)
4432 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4433 if (geometry & HeightValue)
4434 result = Fcons (Fcons (Qheight, make_number (height)), result);
4436 return result;
4440 /* Calculate the desired size and position of frame F.
4441 Return the flags saying which aspects were specified.
4443 Also set the win_gravity and size_hint_flags of F.
4445 Adjust height for toolbar if TOOLBAR_P is 1.
4447 This function does not make the coordinates positive. */
4449 #define DEFAULT_ROWS 35
4450 #define DEFAULT_COLS 80
4452 long
4453 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p)
4455 Lisp_Object height, width, user_size, top, left, user_position;
4456 long window_prompting = 0;
4457 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4459 /* Default values if we fall through.
4460 Actually, if that happens we should get
4461 window manager prompting. */
4462 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4463 SET_FRAME_COLS (f, DEFAULT_COLS);
4464 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4465 SET_FRAME_LINES (f, DEFAULT_ROWS);
4467 /* Window managers expect that if program-specified
4468 positions are not (0,0), they're intentional, not defaults. */
4469 f->top_pos = 0;
4470 f->left_pos = 0;
4472 /* Ensure that earlier new_width and new_height settings won't
4473 override what we specify below. */
4474 f->new_width = f->new_height = 0;
4476 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4477 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4478 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4480 if (!EQ (width, Qunbound))
4482 CHECK_NUMBER (width);
4483 if (! (0 <= XINT (width) && XINT (width) <= INT_MAX))
4484 xsignal1 (Qargs_out_of_range, width);
4486 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4489 if (!EQ (height, Qunbound))
4491 CHECK_NUMBER (height);
4492 if (! (0 <= XINT (height) && XINT (height) <= INT_MAX))
4493 xsignal1 (Qargs_out_of_range, height);
4495 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4498 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4499 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4500 window_prompting |= USSize;
4501 else
4502 window_prompting |= PSize;
4505 /* Add a tool bar height to the initial frame height so that the user
4506 gets a text display area of the size he specified with -g or via
4507 .Xdefaults. Later changes of the tool bar height don't change the
4508 frame size. This is done so that users can create tall Emacs
4509 frames without having to guess how tall the tool bar will get. */
4510 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4512 int margin, relief;
4514 relief = (tool_bar_button_relief >= 0
4515 ? tool_bar_button_relief
4516 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4518 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4519 margin = XFASTINT (Vtool_bar_button_margin);
4520 else if (CONSP (Vtool_bar_button_margin)
4521 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4522 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4523 else
4524 margin = 0;
4526 FRAME_TOOL_BAR_HEIGHT (f)
4527 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4528 Vframe_initial_frame_tool_bar_height = make_number (FRAME_TOOL_BAR_HEIGHT (f));
4531 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4532 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4533 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4534 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4536 if (EQ (top, Qminus))
4538 f->top_pos = 0;
4539 window_prompting |= YNegative;
4541 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4542 && CONSP (XCDR (top))
4543 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4545 f->top_pos = - XINT (XCAR (XCDR (top)));
4546 window_prompting |= YNegative;
4548 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4549 && CONSP (XCDR (top))
4550 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4552 f->top_pos = XINT (XCAR (XCDR (top)));
4554 else if (EQ (top, Qunbound))
4555 f->top_pos = 0;
4556 else
4558 CHECK_TYPE_RANGED_INTEGER (int, top);
4559 f->top_pos = XINT (top);
4560 if (f->top_pos < 0)
4561 window_prompting |= YNegative;
4564 if (EQ (left, Qminus))
4566 f->left_pos = 0;
4567 window_prompting |= XNegative;
4569 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4570 && CONSP (XCDR (left))
4571 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4573 f->left_pos = - XINT (XCAR (XCDR (left)));
4574 window_prompting |= XNegative;
4576 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4577 && CONSP (XCDR (left))
4578 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4580 f->left_pos = XINT (XCAR (XCDR (left)));
4582 else if (EQ (left, Qunbound))
4583 f->left_pos = 0;
4584 else
4586 CHECK_TYPE_RANGED_INTEGER (int, left);
4587 f->left_pos = XINT (left);
4588 if (f->left_pos < 0)
4589 window_prompting |= XNegative;
4592 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4593 window_prompting |= USPosition;
4594 else
4595 window_prompting |= PPosition;
4598 if (window_prompting & XNegative)
4600 if (window_prompting & YNegative)
4601 f->win_gravity = SouthEastGravity;
4602 else
4603 f->win_gravity = NorthEastGravity;
4605 else
4607 if (window_prompting & YNegative)
4608 f->win_gravity = SouthWestGravity;
4609 else
4610 f->win_gravity = NorthWestGravity;
4613 f->size_hint_flags = window_prompting;
4615 return window_prompting;
4620 #endif /* HAVE_WINDOW_SYSTEM */
4622 void
4623 frame_make_pointer_invisible (struct frame *f)
4625 if (! NILP (Vmake_pointer_invisible))
4627 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4628 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4630 f->mouse_moved = 0;
4631 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4632 f->pointer_invisible = 1;
4637 void
4638 frame_make_pointer_visible (struct frame *f)
4640 /* We don't check Vmake_pointer_invisible here in case the
4641 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4642 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4643 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4645 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4646 f->pointer_invisible = 0;
4650 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4651 Sframe_pointer_visible_p, 0, 1, 0,
4652 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4653 Otherwise it returns nil. FRAME omitted or nil means the
4654 selected frame. This is useful when `make-pointer-invisible' is set. */)
4655 (Lisp_Object frame)
4657 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4662 /***********************************************************************
4663 Multimonitor data
4664 ***********************************************************************/
4666 #ifdef HAVE_WINDOW_SYSTEM
4668 # if (defined HAVE_NS \
4669 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4670 void
4671 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4673 int i;
4674 for (i = 0; i < n_monitors; ++i)
4675 xfree (monitors[i].name);
4676 xfree (monitors);
4678 # endif
4680 Lisp_Object
4681 make_monitor_attribute_list (struct MonitorInfo *monitors,
4682 int n_monitors,
4683 int primary_monitor,
4684 Lisp_Object monitor_frames,
4685 const char *source)
4687 Lisp_Object attributes_list = Qnil;
4688 Lisp_Object primary_monitor_attributes = Qnil;
4689 int i;
4691 for (i = 0; i < n_monitors; ++i)
4693 Lisp_Object geometry, workarea, attributes = Qnil;
4694 struct MonitorInfo *mi = &monitors[i];
4696 if (mi->geom.width == 0) continue;
4698 workarea = list4i (mi->work.x, mi->work.y,
4699 mi->work.width, mi->work.height);
4700 geometry = list4i (mi->geom.x, mi->geom.y,
4701 mi->geom.width, mi->geom.height);
4702 attributes = Fcons (Fcons (Qsource, build_string (source)),
4703 attributes);
4704 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4705 attributes);
4706 attributes = Fcons (Fcons (Qmm_size,
4707 list2i (mi->mm_width, mi->mm_height)),
4708 attributes);
4709 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4710 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4711 if (mi->name)
4712 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4713 strlen (mi->name))),
4714 attributes);
4716 if (i == primary_monitor)
4717 primary_monitor_attributes = attributes;
4718 else
4719 attributes_list = Fcons (attributes, attributes_list);
4722 if (!NILP (primary_monitor_attributes))
4723 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4724 return attributes_list;
4727 #endif /* HAVE_WINDOW_SYSTEM */
4730 /***********************************************************************
4731 Initialization
4732 ***********************************************************************/
4734 void
4735 syms_of_frame (void)
4737 DEFSYM (Qframep, "framep");
4738 DEFSYM (Qframe_live_p, "frame-live-p");
4739 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4740 DEFSYM (Qexplicit_name, "explicit-name");
4741 DEFSYM (Qheight, "height");
4742 DEFSYM (Qicon, "icon");
4743 DEFSYM (Qminibuffer, "minibuffer");
4744 DEFSYM (Qmodeline, "modeline");
4745 DEFSYM (Qonly, "only");
4746 DEFSYM (Qnone, "none");
4747 DEFSYM (Qwidth, "width");
4748 DEFSYM (Qgeometry, "geometry");
4749 DEFSYM (Qicon_left, "icon-left");
4750 DEFSYM (Qicon_top, "icon-top");
4751 DEFSYM (Qtooltip, "tooltip");
4752 DEFSYM (Quser_position, "user-position");
4753 DEFSYM (Quser_size, "user-size");
4754 DEFSYM (Qwindow_id, "window-id");
4755 #ifdef HAVE_X_WINDOWS
4756 DEFSYM (Qouter_window_id, "outer-window-id");
4757 #endif
4758 DEFSYM (Qparent_id, "parent-id");
4759 DEFSYM (Qx, "x");
4760 DEFSYM (Qw32, "w32");
4761 DEFSYM (Qpc, "pc");
4762 DEFSYM (Qns, "ns");
4763 DEFSYM (Qvisible, "visible");
4764 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4765 DEFSYM (Qbuffer_list, "buffer-list");
4766 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4767 DEFSYM (Qdisplay_type, "display-type");
4768 DEFSYM (Qbackground_mode, "background-mode");
4769 DEFSYM (Qnoelisp, "noelisp");
4770 DEFSYM (Qtty_color_mode, "tty-color-mode");
4771 DEFSYM (Qtty, "tty");
4772 DEFSYM (Qtty_type, "tty-type");
4774 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4776 DEFSYM (Qfullwidth, "fullwidth");
4777 DEFSYM (Qfullheight, "fullheight");
4778 DEFSYM (Qfullboth, "fullboth");
4779 DEFSYM (Qmaximized, "maximized");
4780 DEFSYM (Qx_resource_name, "x-resource-name");
4781 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4783 DEFSYM (Qterminal, "terminal");
4785 DEFSYM (Qgeometry, "geometry");
4786 DEFSYM (Qworkarea, "workarea");
4787 DEFSYM (Qmm_size, "mm-size");
4788 DEFSYM (Qframes, "frames");
4789 DEFSYM (Qsource, "source");
4791 #ifdef HAVE_NS
4792 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4793 #endif
4796 int i;
4798 for (i = 0; i < ARRAYELTS (frame_parms); i++)
4800 Lisp_Object v = intern_c_string (frame_parms[i].name);
4801 if (frame_parms[i].variable)
4803 *frame_parms[i].variable = v;
4804 staticpro (frame_parms[i].variable);
4806 Fput (v, Qx_frame_parameter, make_number (i));
4810 #ifdef HAVE_WINDOW_SYSTEM
4811 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4812 doc: /* The name Emacs uses to look up X resources.
4813 `x-get-resource' uses this as the first component of the instance name
4814 when requesting resource values.
4815 Emacs initially sets `x-resource-name' to the name under which Emacs
4816 was invoked, or to the value specified with the `-name' or `-rn'
4817 switches, if present.
4819 It may be useful to bind this variable locally around a call
4820 to `x-get-resource'. See also the variable `x-resource-class'. */);
4821 Vx_resource_name = Qnil;
4823 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4824 doc: /* The class Emacs uses to look up X resources.
4825 `x-get-resource' uses this as the first component of the instance class
4826 when requesting resource values.
4828 Emacs initially sets `x-resource-class' to "Emacs".
4830 Setting this variable permanently is not a reasonable thing to do,
4831 but binding this variable locally around a call to `x-get-resource'
4832 is a reasonable practice. See also the variable `x-resource-name'. */);
4833 Vx_resource_class = build_string (EMACS_CLASS);
4835 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4836 doc: /* The lower limit of the frame opacity (alpha transparency).
4837 The value should range from 0 (invisible) to 100 (completely opaque).
4838 You can also use a floating number between 0.0 and 1.0. */);
4839 Vframe_alpha_lower_limit = make_number (20);
4840 #endif
4842 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4843 doc: /* Alist of default values for frame creation.
4844 These may be set in your init file, like this:
4845 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4846 These override values given in window system configuration data,
4847 including X Windows' defaults database.
4848 For values specific to the first Emacs frame, see `initial-frame-alist'.
4849 For window-system specific values, see `window-system-default-frame-alist'.
4850 For values specific to the separate minibuffer frame, see
4851 `minibuffer-frame-alist'.
4852 The `menu-bar-lines' element of the list controls whether new frames
4853 have menu bars; `menu-bar-mode' works by altering this element.
4854 Setting this variable does not affect existing frames, only new ones. */);
4855 Vdefault_frame_alist = Qnil;
4857 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4858 doc: /* Default position of vertical scroll bars on this window-system. */);
4859 #ifdef HAVE_WINDOW_SYSTEM
4860 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4861 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4862 default. */
4863 Vdefault_frame_scroll_bars = Qright;
4864 #else
4865 Vdefault_frame_scroll_bars = Qleft;
4866 #endif
4867 #else
4868 Vdefault_frame_scroll_bars = Qnil;
4869 #endif
4871 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
4872 scroll_bar_adjust_thumb_portion_p,
4873 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
4874 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
4875 even if the end of the buffer is shown (i.e. overscrolling).
4876 Set to nil if you want the thumb to be at the bottom when the end of the buffer
4877 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
4878 is visible. In this case you can not overscroll. */);
4879 scroll_bar_adjust_thumb_portion_p = 1;
4881 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4882 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4884 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4885 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4886 `mouse-position' calls this function, passing its usual return value as
4887 argument, and returns whatever this function returns.
4888 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4889 which need to do mouse handling at the Lisp level. */);
4890 Vmouse_position_function = Qnil;
4892 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4893 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4894 If the value is an integer, highlighting is only shown after moving the
4895 mouse, while keyboard input turns off the highlight even when the mouse
4896 is over the clickable text. However, the mouse shape still indicates
4897 when the mouse is over clickable text. */);
4898 Vmouse_highlight = Qt;
4900 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4901 doc: /* If non-nil, make pointer invisible while typing.
4902 The pointer becomes visible again when the mouse is moved. */);
4903 Vmake_pointer_invisible = Qt;
4905 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
4906 doc: /* Normal hook run when a frame gains input focus. */);
4907 Vfocus_in_hook = Qnil;
4908 DEFSYM (Qfocus_in_hook, "focus-in-hook");
4910 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
4911 doc: /* Normal hook run when a frame loses input focus. */);
4912 Vfocus_out_hook = Qnil;
4913 DEFSYM (Qfocus_out_hook, "focus-out-hook");
4915 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4916 doc: /* Functions run before deleting a frame.
4917 The functions are run with one arg, the frame to be deleted.
4918 See `delete-frame'.
4920 Note that functions in this list may be called just before the frame is
4921 actually deleted, or some time later (or even both when an earlier function
4922 in `delete-frame-functions' (indirectly) calls `delete-frame'
4923 recursively). */);
4924 Vdelete_frame_functions = Qnil;
4925 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4927 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4928 doc: /* Non-nil if Menu-Bar mode is enabled.
4929 See the command `menu-bar-mode' for a description of this minor mode.
4930 Setting this variable directly does not take effect;
4931 either customize it (see the info node `Easy Customization')
4932 or call the function `menu-bar-mode'. */);
4933 Vmenu_bar_mode = Qt;
4935 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4936 doc: /* Non-nil if Tool-Bar mode is enabled.
4937 See the command `tool-bar-mode' for a description of this minor mode.
4938 Setting this variable directly does not take effect;
4939 either customize it (see the info node `Easy Customization')
4940 or call the function `tool-bar-mode'. */);
4941 #ifdef HAVE_WINDOW_SYSTEM
4942 Vtool_bar_mode = Qt;
4943 #else
4944 Vtool_bar_mode = Qnil;
4945 #endif
4947 DEFVAR_LISP ("frame-initial-frame-tool-bar-height", Vframe_initial_frame_tool_bar_height,
4948 doc: /* Height of tool bar of initial frame. */);
4949 Vframe_initial_frame_tool_bar_height = make_number (0);
4951 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4952 doc: /* Minibufferless frames use this frame's minibuffer.
4953 Emacs cannot create minibufferless frames unless this is set to an
4954 appropriate surrogate.
4956 Emacs consults this variable only when creating minibufferless
4957 frames; once the frame is created, it sticks with its assigned
4958 minibuffer, no matter what this variable is set to. This means that
4959 this variable doesn't necessarily say anything meaningful about the
4960 current set of frames, or where the minibuffer is currently being
4961 displayed.
4963 This variable is local to the current terminal and cannot be buffer-local. */);
4965 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4966 doc: /* Non-nil if window system changes focus when you move the mouse.
4967 You should set this variable to tell Emacs how your window manager
4968 handles focus, since there is no way in general for Emacs to find out
4969 automatically. See also `mouse-autoselect-window'. */);
4970 focus_follows_mouse = 0;
4972 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
4973 doc: /* Non-nil means resize frames pixelwise.
4974 If this option is nil, resizing a frame rounds its sizes to the frame's
4975 current values of `frame-char-height' and `frame-char-width'. If this
4976 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
4977 by one pixel.
4979 With some window managers you may have to set this to non-nil in order
4980 to fully maximize frames. To resize your initial frame pixelwise, set
4981 this option to a non-nil value in your init file. */);
4982 frame_resize_pixelwise = 0;
4984 DEFVAR_BOOL ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
4985 doc: /* Non-nil means do not resize frame implicitly.
4986 If this option is nil, setting default font, menubar mode, fringe width,
4987 or scroll bar mode of a specific frame may resize the frame in order to
4988 preserve the number of columns or lines it displays. If this option is
4989 non-nil, no such resizing is done. */);
4990 frame_inhibit_implied_resize = 0;
4992 staticpro (&Vframe_list);
4994 defsubr (&Sframep);
4995 defsubr (&Sframe_live_p);
4996 defsubr (&Swindow_system);
4997 defsubr (&Smake_terminal_frame);
4998 defsubr (&Shandle_switch_frame);
4999 defsubr (&Sselect_frame);
5000 defsubr (&Sselected_frame);
5001 defsubr (&Sframe_list);
5002 defsubr (&Snext_frame);
5003 defsubr (&Sprevious_frame);
5004 defsubr (&Slast_nonminibuf_frame);
5005 defsubr (&Sdelete_frame);
5006 defsubr (&Smouse_position);
5007 defsubr (&Smouse_pixel_position);
5008 defsubr (&Sset_mouse_position);
5009 defsubr (&Sset_mouse_pixel_position);
5010 #if 0
5011 defsubr (&Sframe_configuration);
5012 defsubr (&Srestore_frame_configuration);
5013 #endif
5014 defsubr (&Smake_frame_visible);
5015 defsubr (&Smake_frame_invisible);
5016 defsubr (&Siconify_frame);
5017 defsubr (&Sframe_visible_p);
5018 defsubr (&Svisible_frame_list);
5019 defsubr (&Sraise_frame);
5020 defsubr (&Slower_frame);
5021 defsubr (&Sx_focus_frame);
5022 defsubr (&Sredirect_frame_focus);
5023 defsubr (&Sframe_focus);
5024 defsubr (&Sframe_parameters);
5025 defsubr (&Sframe_parameter);
5026 defsubr (&Smodify_frame_parameters);
5027 defsubr (&Sframe_char_height);
5028 defsubr (&Sframe_char_width);
5029 defsubr (&Sframe_pixel_height);
5030 defsubr (&Sframe_pixel_width);
5031 defsubr (&Sframe_text_cols);
5032 defsubr (&Sframe_text_lines);
5033 defsubr (&Sframe_total_cols);
5034 defsubr (&Sframe_total_lines);
5035 defsubr (&Sframe_text_width);
5036 defsubr (&Sframe_text_height);
5037 defsubr (&Sscroll_bar_width);
5038 defsubr (&Sscroll_bar_height);
5039 defsubr (&Sfringe_width);
5040 defsubr (&Sborder_width);
5041 defsubr (&Sright_divider_width);
5042 defsubr (&Sbottom_divider_width);
5043 defsubr (&Stool_bar_pixel_width);
5044 defsubr (&Sset_frame_height);
5045 defsubr (&Sset_frame_width);
5046 defsubr (&Sset_frame_size);
5047 defsubr (&Sset_frame_position);
5048 defsubr (&Sframe_pointer_visible_p);
5050 #ifdef HAVE_WINDOW_SYSTEM
5051 defsubr (&Sx_get_resource);
5052 defsubr (&Sx_parse_geometry);
5053 #endif