src/w32.c (sys_write): Use SAFE_NALLOCA for the NL -> CRLF translation buffer.
[emacs.git] / src / frame.c
blob7077d42dd1b5a7bd2371d354db8cca83c35d2cb8
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 accomodate
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 character cells, where (0, 0) is the
1810 upper-left corner of the frame, X is the horizontal offset, and Y is
1811 the vertical offset.
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 character cells, where (0, 0) is the
1931 upper-left corner of the frame, X is the horizontal offset, and Y is
1932 the vertical offset.
1934 This function is a no-op for an X frame that is not visible.
1935 If you have just created a frame, you must wait for it to become visible
1936 before calling this function on it, like this.
1937 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1938 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1940 CHECK_LIVE_FRAME (frame);
1941 CHECK_TYPE_RANGED_INTEGER (int, x);
1942 CHECK_TYPE_RANGED_INTEGER (int, y);
1944 /* I think this should be done with a hook. */
1945 #ifdef HAVE_WINDOW_SYSTEM
1946 if (FRAME_WINDOW_P (XFRAME (frame)))
1947 /* Warping the mouse will cause enternotify and focus events. */
1948 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1949 #else
1950 #if defined (MSDOS)
1951 if (FRAME_MSDOS_P (XFRAME (frame)))
1953 Fselect_frame (frame, Qnil);
1954 mouse_moveto (XINT (x), XINT (y));
1956 #else
1957 #ifdef HAVE_GPM
1959 Fselect_frame (frame, Qnil);
1960 term_mouse_moveto (XINT (x), XINT (y));
1962 #endif
1963 #endif
1964 #endif
1966 return Qnil;
1969 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1970 Sset_mouse_pixel_position, 3, 3, 0,
1971 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1972 The position is given in pixels, where (0, 0) is the upper-left corner
1973 of the frame, X is the horizontal offset, and Y is the vertical offset.
1975 Note, this is a no-op for an X frame that is not visible.
1976 If you have just created a frame, you must wait for it to become visible
1977 before calling this function on it, like this.
1978 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1979 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1981 CHECK_LIVE_FRAME (frame);
1982 CHECK_TYPE_RANGED_INTEGER (int, x);
1983 CHECK_TYPE_RANGED_INTEGER (int, y);
1985 /* I think this should be done with a hook. */
1986 #ifdef HAVE_WINDOW_SYSTEM
1987 if (FRAME_WINDOW_P (XFRAME (frame)))
1988 /* Warping the mouse will cause enternotify and focus events. */
1989 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1990 #else
1991 #if defined (MSDOS)
1992 if (FRAME_MSDOS_P (XFRAME (frame)))
1994 Fselect_frame (frame, Qnil);
1995 mouse_moveto (XINT (x), XINT (y));
1997 #else
1998 #ifdef HAVE_GPM
2000 Fselect_frame (frame, Qnil);
2001 term_mouse_moveto (XINT (x), XINT (y));
2003 #endif
2004 #endif
2005 #endif
2007 return Qnil;
2010 static void make_frame_visible_1 (Lisp_Object);
2012 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2013 0, 1, "",
2014 doc: /* Make the frame FRAME visible (assuming it is an X window).
2015 If omitted, FRAME defaults to the currently selected frame. */)
2016 (Lisp_Object frame)
2018 struct frame *f = decode_live_frame (frame);
2020 /* I think this should be done with a hook. */
2021 #ifdef HAVE_WINDOW_SYSTEM
2022 if (FRAME_WINDOW_P (f))
2023 x_make_frame_visible (f);
2024 #endif
2026 make_frame_visible_1 (f->root_window);
2028 /* Make menu bar update for the Buffers and Frames menus. */
2029 /* windows_or_buffers_changed = 15; FIXME: Why? */
2031 XSETFRAME (frame, f);
2032 return frame;
2035 /* Update the display_time slot of the buffers shown in WINDOW
2036 and all its descendants. */
2038 static void
2039 make_frame_visible_1 (Lisp_Object window)
2041 struct window *w;
2043 for (; !NILP (window); window = w->next)
2045 w = XWINDOW (window);
2046 if (WINDOWP (w->contents))
2047 make_frame_visible_1 (w->contents);
2048 else
2049 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2053 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2054 0, 2, "",
2055 doc: /* Make the frame FRAME invisible.
2056 If omitted, FRAME defaults to the currently selected frame.
2057 On graphical displays, invisible frames are not updated and are
2058 usually not displayed at all, even in a window system's \"taskbar\".
2060 Normally you may not make FRAME invisible if all other frames are invisible,
2061 but if the second optional argument FORCE is non-nil, you may do so.
2063 This function has no effect on text terminal frames. Such frames are
2064 always considered visible, whether or not they are currently being
2065 displayed in the terminal. */)
2066 (Lisp_Object frame, Lisp_Object force)
2068 struct frame *f = decode_live_frame (frame);
2070 if (NILP (force) && !other_visible_frames (f))
2071 error ("Attempt to make invisible the sole visible or iconified frame");
2073 /* Don't allow minibuf_window to remain on an invisible frame. */
2074 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2076 /* I think this should be done with a hook. */
2077 #ifdef HAVE_WINDOW_SYSTEM
2078 if (FRAME_WINDOW_P (f))
2079 x_make_frame_invisible (f);
2080 #endif
2082 /* Make menu bar update for the Buffers and Frames menus. */
2083 windows_or_buffers_changed = 16;
2085 return Qnil;
2088 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2089 0, 1, "",
2090 doc: /* Make the frame FRAME into an icon.
2091 If omitted, FRAME defaults to the currently selected frame. */)
2092 (Lisp_Object frame)
2094 struct frame *f = decode_live_frame (frame);
2096 /* Don't allow minibuf_window to remain on an iconified frame. */
2097 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2099 /* I think this should be done with a hook. */
2100 #ifdef HAVE_WINDOW_SYSTEM
2101 if (FRAME_WINDOW_P (f))
2102 x_iconify_frame (f);
2103 #endif
2105 /* Make menu bar update for the Buffers and Frames menus. */
2106 windows_or_buffers_changed = 17;
2108 return Qnil;
2111 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2112 1, 1, 0,
2113 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2114 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2115 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2116 On graphical displays, invisible frames are not updated and are
2117 usually not displayed at all, even in a window system's \"taskbar\".
2119 If FRAME is a text terminal frame, this always returns t.
2120 Such frames are always considered visible, whether or not they are
2121 currently being displayed on the terminal. */)
2122 (Lisp_Object frame)
2124 CHECK_LIVE_FRAME (frame);
2126 if (FRAME_VISIBLE_P (XFRAME (frame)))
2127 return Qt;
2128 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2129 return Qicon;
2130 return Qnil;
2133 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2134 0, 0, 0,
2135 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2136 (void)
2138 Lisp_Object tail, frame, value = Qnil;
2140 FOR_EACH_FRAME (tail, frame)
2141 if (FRAME_VISIBLE_P (XFRAME (frame)))
2142 value = Fcons (frame, value);
2144 return value;
2148 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2149 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2150 If FRAME is invisible or iconified, make it visible.
2151 If you don't specify a frame, the selected frame is used.
2152 If Emacs is displaying on an ordinary terminal or some other device which
2153 doesn't support multiple overlapping frames, this function selects FRAME. */)
2154 (Lisp_Object frame)
2156 struct frame *f = decode_live_frame (frame);
2158 XSETFRAME (frame, f);
2160 if (FRAME_TERMCAP_P (f))
2161 /* On a text terminal select FRAME. */
2162 Fselect_frame (frame, Qnil);
2163 else
2164 /* Do like the documentation says. */
2165 Fmake_frame_visible (frame);
2167 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2168 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2170 return Qnil;
2173 /* Should we have a corresponding function called Flower_Power? */
2174 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2175 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2176 If you don't specify a frame, the selected frame is used.
2177 If Emacs is displaying on an ordinary terminal or some other device which
2178 doesn't support multiple overlapping frames, this function does nothing. */)
2179 (Lisp_Object frame)
2181 struct frame *f = decode_live_frame (frame);
2183 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2184 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2186 return Qnil;
2190 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2191 1, 2, 0,
2192 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2193 In other words, switch-frame events caused by events in FRAME will
2194 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2195 FOCUS-FRAME after reading an event typed at FRAME.
2197 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2198 frame again receives its own keystrokes.
2200 Focus redirection is useful for temporarily redirecting keystrokes to
2201 a surrogate minibuffer frame when a frame doesn't have its own
2202 minibuffer window.
2204 A frame's focus redirection can be changed by `select-frame'. If frame
2205 FOO is selected, and then a different frame BAR is selected, any
2206 frames redirecting their focus to FOO are shifted to redirect their
2207 focus to BAR. This allows focus redirection to work properly when the
2208 user switches from one frame to another using `select-window'.
2210 This means that a frame whose focus is redirected to itself is treated
2211 differently from a frame whose focus is redirected to nil; the former
2212 is affected by `select-frame', while the latter is not.
2214 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2215 (Lisp_Object frame, Lisp_Object focus_frame)
2217 /* Note that we don't check for a live frame here. It's reasonable
2218 to redirect the focus of a frame you're about to delete, if you
2219 know what other frame should receive those keystrokes. */
2220 struct frame *f = decode_any_frame (frame);
2222 if (! NILP (focus_frame))
2223 CHECK_LIVE_FRAME (focus_frame);
2225 fset_focus_frame (f, focus_frame);
2227 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2228 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2230 return Qnil;
2234 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2235 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2236 If FRAME is omitted or nil, the selected frame is used.
2237 Return nil if FRAME's focus is not redirected.
2238 See `redirect-frame-focus'. */)
2239 (Lisp_Object frame)
2241 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2244 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2245 doc: /* Set the input focus to FRAME.
2246 FRAME nil means use the selected frame.
2247 If there is no window system support, this function does nothing. */)
2248 (Lisp_Object frame)
2250 #ifdef HAVE_WINDOW_SYSTEM
2251 x_focus_frame (decode_window_system_frame (frame));
2252 #endif
2253 return Qnil;
2257 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2259 void
2260 frames_discard_buffer (Lisp_Object buffer)
2262 Lisp_Object frame, tail;
2264 FOR_EACH_FRAME (tail, frame)
2266 fset_buffer_list
2267 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2268 fset_buried_buffer_list
2269 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2273 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2274 If the alist already has an element for PROP, we change it. */
2276 void
2277 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2279 register Lisp_Object tem;
2281 tem = Fassq (prop, *alistptr);
2282 if (EQ (tem, Qnil))
2283 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2284 else
2285 Fsetcdr (tem, val);
2288 static int
2289 frame_name_fnn_p (char *str, ptrdiff_t len)
2291 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2293 char *p = str + 2;
2294 while ('0' <= *p && *p <= '9')
2295 p++;
2296 if (p == str + len)
2297 return 1;
2299 return 0;
2302 /* Set the name of the terminal frame. Also used by MSDOS frames.
2303 Modeled after x_set_name which is used for WINDOW frames. */
2305 static void
2306 set_term_frame_name (struct frame *f, Lisp_Object name)
2308 f->explicit_name = ! NILP (name);
2310 /* If NAME is nil, set the name to F<num>. */
2311 if (NILP (name))
2313 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2315 /* Check for no change needed in this very common case
2316 before we do any consing. */
2317 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2318 return;
2320 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2322 else
2324 CHECK_STRING (name);
2326 /* Don't change the name if it's already NAME. */
2327 if (! NILP (Fstring_equal (name, f->name)))
2328 return;
2330 /* Don't allow the user to set the frame name to F<num>, so it
2331 doesn't clash with the names we generate for terminal frames. */
2332 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2333 error ("Frame names of the form F<num> are usurped by Emacs");
2336 fset_name (f, name);
2337 update_mode_lines = 16;
2340 void
2341 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2343 register Lisp_Object old_alist_elt;
2345 /* The buffer-list parameters are stored in a special place and not
2346 in the alist. All buffers must be live. */
2347 if (EQ (prop, Qbuffer_list))
2349 Lisp_Object list = Qnil;
2350 for (; CONSP (val); val = XCDR (val))
2351 if (!NILP (Fbuffer_live_p (XCAR (val))))
2352 list = Fcons (XCAR (val), list);
2353 fset_buffer_list (f, Fnreverse (list));
2354 return;
2356 if (EQ (prop, Qburied_buffer_list))
2358 Lisp_Object list = Qnil;
2359 for (; CONSP (val); val = XCDR (val))
2360 if (!NILP (Fbuffer_live_p (XCAR (val))))
2361 list = Fcons (XCAR (val), list);
2362 fset_buried_buffer_list (f, Fnreverse (list));
2363 return;
2366 /* If PROP is a symbol which is supposed to have frame-local values,
2367 and it is set up based on this frame, switch to the global
2368 binding. That way, we can create or alter the frame-local binding
2369 without messing up the symbol's status. */
2370 if (SYMBOLP (prop))
2372 struct Lisp_Symbol *sym = XSYMBOL (prop);
2373 start:
2374 switch (sym->redirect)
2376 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2377 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2378 case SYMBOL_LOCALIZED:
2379 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2380 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2381 swap_in_global_binding (sym);
2382 break;
2384 default: emacs_abort ();
2388 /* The tty color needed to be set before the frame's parameter
2389 alist was updated with the new value. This is not true any more,
2390 but we still do this test early on. */
2391 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2392 && f == FRAME_TTY (f)->previous_frame)
2393 /* Force redisplay of this tty. */
2394 FRAME_TTY (f)->previous_frame = NULL;
2396 /* Update the frame parameter alist. */
2397 old_alist_elt = Fassq (prop, f->param_alist);
2398 if (EQ (old_alist_elt, Qnil))
2399 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2400 else
2401 Fsetcdr (old_alist_elt, val);
2403 /* Update some other special parameters in their special places
2404 in addition to the alist. */
2406 if (EQ (prop, Qbuffer_predicate))
2407 fset_buffer_predicate (f, val);
2409 if (! FRAME_WINDOW_P (f))
2411 if (EQ (prop, Qmenu_bar_lines))
2412 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2413 else if (EQ (prop, Qname))
2414 set_term_frame_name (f, val);
2417 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2419 if (! MINI_WINDOW_P (XWINDOW (val)))
2420 error ("Surrogate minibuffer windows must be minibuffer windows");
2422 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2423 && !EQ (val, f->minibuffer_window))
2424 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2426 /* Install the chosen minibuffer window, with proper buffer. */
2427 fset_minibuffer_window (f, val);
2431 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2432 is not an unspecified foreground or background color. */
2434 static Lisp_Object
2435 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2437 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2438 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2439 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2440 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2443 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2444 doc: /* Return the parameters-alist of frame FRAME.
2445 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2446 The meaningful PARMs depend on the kind of frame.
2447 If FRAME is omitted or nil, return information on the currently selected frame. */)
2448 (Lisp_Object frame)
2450 Lisp_Object alist;
2451 struct frame *f = decode_any_frame (frame);
2452 int height, width;
2453 struct gcpro gcpro1;
2455 if (!FRAME_LIVE_P (f))
2456 return Qnil;
2458 alist = Fcopy_alist (f->param_alist);
2459 GCPRO1 (alist);
2461 if (!FRAME_WINDOW_P (f))
2463 Lisp_Object elt;
2465 /* If the frame's parameter alist says the colors are
2466 unspecified and reversed, take the frame's background pixel
2467 for foreground and vice versa. */
2468 elt = Fassq (Qforeground_color, alist);
2469 if (CONSP (elt) && STRINGP (XCDR (elt)))
2471 elt = frame_unspecified_color (f, XCDR (elt));
2472 if (!NILP (elt))
2473 store_in_alist (&alist, Qforeground_color, elt);
2475 else
2476 store_in_alist (&alist, Qforeground_color,
2477 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2478 elt = Fassq (Qbackground_color, alist);
2479 if (CONSP (elt) && STRINGP (XCDR (elt)))
2481 elt = frame_unspecified_color (f, XCDR (elt));
2482 if (!NILP (elt))
2483 store_in_alist (&alist, Qbackground_color, elt);
2485 else
2486 store_in_alist (&alist, Qbackground_color,
2487 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2488 store_in_alist (&alist, intern ("font"),
2489 build_string (FRAME_MSDOS_P (f)
2490 ? "ms-dos"
2491 : FRAME_W32_P (f) ? "w32term"
2492 :"tty"));
2494 store_in_alist (&alist, Qname, f->name);
2495 height = (f->new_height
2496 ? (f->new_pixelwise
2497 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2498 : f->new_height)
2499 : FRAME_LINES (f));
2500 store_in_alist (&alist, Qheight, make_number (height));
2501 width = (f->new_width
2502 ? (f->new_pixelwise
2503 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2504 : f->new_width)
2505 : FRAME_COLS (f));
2506 store_in_alist (&alist, Qwidth, make_number (width));
2507 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2508 store_in_alist (&alist, Qminibuffer,
2509 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2510 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2511 : FRAME_MINIBUF_WINDOW (f)));
2512 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2513 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2514 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2516 /* I think this should be done with a hook. */
2517 #ifdef HAVE_WINDOW_SYSTEM
2518 if (FRAME_WINDOW_P (f))
2519 x_report_frame_params (f, &alist);
2520 else
2521 #endif
2523 /* This ought to be correct in f->param_alist for an X frame. */
2524 Lisp_Object lines;
2525 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2526 store_in_alist (&alist, Qmenu_bar_lines, lines);
2529 UNGCPRO;
2530 return alist;
2534 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2535 doc: /* Return FRAME's value for parameter PARAMETER.
2536 If FRAME is nil, describe the currently selected frame. */)
2537 (Lisp_Object frame, Lisp_Object parameter)
2539 struct frame *f = decode_any_frame (frame);
2540 Lisp_Object value = Qnil;
2542 CHECK_SYMBOL (parameter);
2544 XSETFRAME (frame, f);
2546 if (FRAME_LIVE_P (f))
2548 /* Avoid consing in frequent cases. */
2549 if (EQ (parameter, Qname))
2550 value = f->name;
2551 #ifdef HAVE_X_WINDOWS
2552 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2553 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2554 #endif /* HAVE_X_WINDOWS */
2555 else if (EQ (parameter, Qbackground_color)
2556 || EQ (parameter, Qforeground_color))
2558 value = Fassq (parameter, f->param_alist);
2559 if (CONSP (value))
2561 value = XCDR (value);
2562 /* Fframe_parameters puts the actual fg/bg color names,
2563 even if f->param_alist says otherwise. This is
2564 important when param_alist's notion of colors is
2565 "unspecified". We need to do the same here. */
2566 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2567 value = frame_unspecified_color (f, value);
2569 else
2570 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2572 else if (EQ (parameter, Qdisplay_type)
2573 || EQ (parameter, Qbackground_mode))
2574 value = Fcdr (Fassq (parameter, f->param_alist));
2575 else
2576 /* FIXME: Avoid this code path at all (as well as code duplication)
2577 by sharing more code with Fframe_parameters. */
2578 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2581 return value;
2585 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2586 Smodify_frame_parameters, 2, 2, 0,
2587 doc: /* Modify the parameters of frame FRAME according to ALIST.
2588 If FRAME is nil, it defaults to the selected frame.
2589 ALIST is an alist of parameters to change and their new values.
2590 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2591 The meaningful PARMs depend on the kind of frame.
2592 Undefined PARMs are ignored, but stored in the frame's parameter list
2593 so that `frame-parameters' will return them.
2595 The value of frame parameter FOO can also be accessed
2596 as a frame-local binding for the variable FOO, if you have
2597 enabled such bindings for that variable with `make-variable-frame-local'.
2598 Note that this functionality is obsolete as of Emacs 22.2, and its
2599 use is not recommended. Explicitly check for a frame-parameter instead. */)
2600 (Lisp_Object frame, Lisp_Object alist)
2602 struct frame *f = decode_live_frame (frame);
2603 register Lisp_Object prop, val;
2605 CHECK_LIST (alist);
2607 /* I think this should be done with a hook. */
2608 #ifdef HAVE_WINDOW_SYSTEM
2609 if (FRAME_WINDOW_P (f))
2610 x_set_frame_parameters (f, alist);
2611 else
2612 #endif
2613 #ifdef MSDOS
2614 if (FRAME_MSDOS_P (f))
2615 IT_set_frame_parameters (f, alist);
2616 else
2617 #endif
2620 EMACS_INT length = XFASTINT (Flength (alist));
2621 ptrdiff_t i;
2622 Lisp_Object *parms;
2623 Lisp_Object *values;
2624 USE_SAFE_ALLOCA;
2625 SAFE_ALLOCA_LISP (parms, 2 * length);
2626 values = parms + length;
2628 /* Extract parm names and values into those vectors. */
2630 for (i = 0; CONSP (alist); alist = XCDR (alist))
2632 Lisp_Object elt;
2634 elt = XCAR (alist);
2635 parms[i] = Fcar (elt);
2636 values[i] = Fcdr (elt);
2637 i++;
2640 /* Now process them in reverse of specified order. */
2641 while (--i >= 0)
2643 prop = parms[i];
2644 val = values[i];
2645 store_frame_param (f, prop, val);
2647 if (EQ (prop, Qforeground_color)
2648 || EQ (prop, Qbackground_color))
2649 update_face_from_frame_parameter (f, prop, val);
2652 SAFE_FREE ();
2654 return Qnil;
2657 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2658 0, 1, 0,
2659 doc: /* Height in pixels of a line in the font in frame FRAME.
2660 If FRAME is omitted or nil, the selected frame is used.
2661 For a terminal frame, the value is always 1. */)
2662 (Lisp_Object frame)
2664 #ifdef HAVE_WINDOW_SYSTEM
2665 struct frame *f = decode_any_frame (frame);
2667 if (FRAME_WINDOW_P (f))
2668 return make_number (FRAME_LINE_HEIGHT (f));
2669 else
2670 #endif
2671 return make_number (1);
2675 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2676 0, 1, 0,
2677 doc: /* Width in pixels of characters in the font in frame FRAME.
2678 If FRAME is omitted or nil, the selected frame is used.
2679 On a graphical screen, the width is the standard width of the default font.
2680 For a terminal screen, the value is always 1. */)
2681 (Lisp_Object frame)
2683 #ifdef HAVE_WINDOW_SYSTEM
2684 struct frame *f = decode_any_frame (frame);
2686 if (FRAME_WINDOW_P (f))
2687 return make_number (FRAME_COLUMN_WIDTH (f));
2688 else
2689 #endif
2690 return make_number (1);
2693 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2694 Sframe_pixel_height, 0, 1, 0,
2695 doc: /* Return a FRAME's height in pixels.
2696 If FRAME is omitted or nil, the selected frame is used. The exact value
2697 of the result depends on the window-system and toolkit in use:
2699 In the Gtk+ version of Emacs, it includes only any window (including
2700 the minibuffer or echo area), mode line, and header line. It does not
2701 include the tool bar or menu bar.
2703 With other graphical versions, it also includes the tool bar and the
2704 menu bar.
2706 For a text terminal, it includes the menu bar. In this case, the
2707 result is really in characters rather than pixels (i.e., is identical
2708 to `frame-height'). */)
2709 (Lisp_Object frame)
2711 struct frame *f = decode_any_frame (frame);
2713 #ifdef HAVE_WINDOW_SYSTEM
2714 if (FRAME_WINDOW_P (f))
2715 return make_number (FRAME_PIXEL_HEIGHT (f));
2716 else
2717 #endif
2718 return make_number (FRAME_TOTAL_LINES (f));
2721 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2722 Sframe_pixel_width, 0, 1, 0,
2723 doc: /* Return FRAME's width in pixels.
2724 For a terminal frame, the result really gives the width in characters.
2725 If FRAME is omitted or nil, the selected frame is used. */)
2726 (Lisp_Object frame)
2728 struct frame *f = decode_any_frame (frame);
2730 #ifdef HAVE_WINDOW_SYSTEM
2731 if (FRAME_WINDOW_P (f))
2732 return make_number (FRAME_PIXEL_WIDTH (f));
2733 else
2734 #endif
2735 return make_number (FRAME_TOTAL_COLS (f));
2738 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2739 Stool_bar_pixel_width, 0, 1, 0,
2740 doc: /* Return width in pixels of FRAME's tool bar.
2741 The result is greater than zero only when the tool bar is on the left
2742 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2743 is used. */)
2744 (Lisp_Object frame)
2746 #ifdef FRAME_TOOLBAR_WIDTH
2747 struct frame *f = decode_any_frame (frame);
2749 if (FRAME_WINDOW_P (f))
2750 return make_number (FRAME_TOOLBAR_WIDTH (f));
2751 #endif
2752 return make_number (0);
2755 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2756 doc: /* Return width in columns of FRAME's text area. */)
2757 (Lisp_Object frame)
2759 return make_number (FRAME_COLS (decode_any_frame (frame)));
2762 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2763 doc: /* Return height in lines of FRAME's text area. */)
2764 (Lisp_Object frame)
2766 return make_number (FRAME_LINES (decode_any_frame (frame)));
2769 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2770 doc: /* Return number of total columns of FRAME. */)
2771 (Lisp_Object frame)
2773 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2776 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2777 doc: /* Return number of total lines of FRAME. */)
2778 (Lisp_Object frame)
2780 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2783 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2784 doc: /* Return text area width of FRAME in pixels. */)
2785 (Lisp_Object frame)
2787 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2790 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2791 doc: /* Return text area height of FRAME in pixels. */)
2792 (Lisp_Object frame)
2794 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2797 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2798 doc: /* Return scroll bar width of FRAME in pixels. */)
2799 (Lisp_Object frame)
2801 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2804 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2805 doc: /* Return scroll bar height of FRAME in pixels. */)
2806 (Lisp_Object frame)
2808 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2811 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2812 doc: /* Return fringe width of FRAME in pixels. */)
2813 (Lisp_Object frame)
2815 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2818 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2819 doc: /* Return border width of FRAME in pixels. */)
2820 (Lisp_Object frame)
2822 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2825 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2826 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2827 (Lisp_Object frame)
2829 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2832 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2833 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2834 (Lisp_Object frame)
2836 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2839 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2840 doc: /* Specify that the frame FRAME has HEIGHT text lines.
2841 Optional third arg PRETEND non-nil means that redisplay should use
2842 HEIGHT lines but that the idea of the actual height of the frame should
2843 not be changed. Optional fourth argument PIXELWISE non-nil means that
2844 FRAME should be HEIGHT pixels high. */)
2845 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2847 struct frame *f = decode_live_frame (frame);
2848 int pixel_height;
2850 CHECK_TYPE_RANGED_INTEGER (int, height);
2852 pixel_height = (!NILP (pixelwise)
2853 ? XINT (height)
2854 : XINT (height) * FRAME_LINE_HEIGHT (f));
2855 if (pixel_height != FRAME_TEXT_HEIGHT (f))
2856 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend));
2858 return Qnil;
2861 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2862 doc: /* Specify that the frame FRAME has WIDTH columns.
2863 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2864 columns but that the idea of the actual width of the frame should not
2865 be changed. Optional fourth argument PIXELWISE non-nil means that FRAME
2866 should be WIDTH pixels wide. */)
2867 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2869 struct frame *f = decode_live_frame (frame);
2870 int pixel_width;
2872 CHECK_TYPE_RANGED_INTEGER (int, width);
2874 pixel_width = (!NILP (pixelwise)
2875 ? XINT (width)
2876 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2877 if (pixel_width != FRAME_TEXT_WIDTH (f))
2878 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend));
2880 return Qnil;
2883 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2884 doc: /* Sets size of FRAME to WIDTH by HEIGHT, measured in characters.
2885 Optional argument PIXELWISE non-nil means to measure in pixels. */)
2886 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2888 struct frame *f = decode_live_frame (frame);
2889 int pixel_width, pixel_height;
2891 CHECK_TYPE_RANGED_INTEGER (int, width);
2892 CHECK_TYPE_RANGED_INTEGER (int, height);
2894 pixel_width = (!NILP (pixelwise)
2895 ? XINT (width)
2896 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2897 pixel_height = (!NILP (pixelwise)
2898 ? XINT (height)
2899 : XINT (height) * FRAME_LINE_HEIGHT (f));
2901 if (pixel_width != FRAME_TEXT_WIDTH (f)
2902 || pixel_height != FRAME_TEXT_HEIGHT (f))
2903 adjust_frame_size (f, pixel_width, pixel_height, 1, 0);
2905 return Qnil;
2908 DEFUN ("set-frame-position", Fset_frame_position,
2909 Sset_frame_position, 3, 3, 0,
2910 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2911 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2912 actually the position of the upper left corner of the frame. Negative
2913 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2914 or bottommost possible position (that stays within the screen). */)
2915 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2917 register struct frame *f = decode_live_frame (frame);
2919 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2920 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2922 /* I think this should be done with a hook. */
2923 #ifdef HAVE_WINDOW_SYSTEM
2924 if (FRAME_WINDOW_P (f))
2925 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2926 #endif
2928 return Qt;
2932 /***********************************************************************
2933 Frame Parameters
2934 ***********************************************************************/
2936 /* Connect the frame-parameter names for X frames
2937 to the ways of passing the parameter values to the window system.
2939 The name of a parameter, as a Lisp symbol,
2940 has an `x-frame-parameter' property which is an integer in Lisp
2941 that is an index in this table. */
2943 struct frame_parm_table {
2944 const char *name;
2945 Lisp_Object *variable;
2948 static const struct frame_parm_table frame_parms[] =
2950 {"auto-raise", &Qauto_raise},
2951 {"auto-lower", &Qauto_lower},
2952 {"background-color", 0},
2953 {"border-color", &Qborder_color},
2954 {"border-width", &Qborder_width},
2955 {"cursor-color", &Qcursor_color},
2956 {"cursor-type", &Qcursor_type},
2957 {"font", 0},
2958 {"foreground-color", 0},
2959 {"icon-name", &Qicon_name},
2960 {"icon-type", &Qicon_type},
2961 {"internal-border-width", &Qinternal_border_width},
2962 {"right-divider-width", &Qright_divider_width},
2963 {"bottom-divider-width", &Qbottom_divider_width},
2964 {"menu-bar-lines", &Qmenu_bar_lines},
2965 {"mouse-color", &Qmouse_color},
2966 {"name", &Qname},
2967 {"scroll-bar-width", &Qscroll_bar_width},
2968 {"scroll-bar-height", &Qscroll_bar_height},
2969 {"title", &Qtitle},
2970 {"unsplittable", &Qunsplittable},
2971 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2972 {"horizontal-scroll-bars", &Qhorizontal_scroll_bars},
2973 {"visibility", &Qvisibility},
2974 {"tool-bar-lines", &Qtool_bar_lines},
2975 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2976 {"scroll-bar-background", &Qscroll_bar_background},
2977 {"screen-gamma", &Qscreen_gamma},
2978 {"line-spacing", &Qline_spacing},
2979 {"left-fringe", &Qleft_fringe},
2980 {"right-fringe", &Qright_fringe},
2981 {"wait-for-wm", &Qwait_for_wm},
2982 {"fullscreen", &Qfullscreen},
2983 {"font-backend", &Qfont_backend},
2984 {"alpha", &Qalpha},
2985 {"sticky", &Qsticky},
2986 {"tool-bar-position", &Qtool_bar_position},
2989 #ifdef HAVE_WINDOW_SYSTEM
2991 /* Change the parameters of frame F as specified by ALIST.
2992 If a parameter is not specially recognized, do nothing special;
2993 otherwise call the `x_set_...' function for that parameter.
2994 Except for certain geometry properties, always call store_frame_param
2995 to store the new value in the parameter alist. */
2997 void
2998 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3000 Lisp_Object tail;
3002 /* If both of these parameters are present, it's more efficient to
3003 set them both at once. So we wait until we've looked at the
3004 entire list before we set them. */
3005 int width, height;
3006 bool width_change = 0, height_change = 0;
3008 /* Same here. */
3009 Lisp_Object left, top;
3011 /* Same with these. */
3012 Lisp_Object icon_left, icon_top;
3014 /* Record in these vectors all the parms specified. */
3015 Lisp_Object *parms;
3016 Lisp_Object *values;
3017 ptrdiff_t i, p;
3018 bool left_no_change = 0, top_no_change = 0;
3019 #ifdef HAVE_X_WINDOWS
3020 bool icon_left_no_change = 0, icon_top_no_change = 0;
3021 #endif
3023 i = 0;
3024 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3025 i++;
3027 USE_SAFE_ALLOCA;
3028 SAFE_ALLOCA_LISP (parms, 2 * i);
3029 values = parms + i;
3031 /* Extract parm names and values into those vectors. */
3033 i = 0;
3034 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3036 Lisp_Object elt;
3038 elt = XCAR (tail);
3039 parms[i] = Fcar (elt);
3040 values[i] = Fcdr (elt);
3041 i++;
3043 /* TAIL and ALIST are not used again below here. */
3044 alist = tail = Qnil;
3046 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
3047 because their values appear in VALUES and strings are not valid. */
3048 top = left = Qunbound;
3049 icon_left = icon_top = Qunbound;
3051 /* Process foreground_color and background_color before anything else.
3052 They are independent of other properties, but other properties (e.g.,
3053 cursor_color) are dependent upon them. */
3054 /* Process default font as well, since fringe widths depends on it. */
3055 for (p = 0; p < i; p++)
3057 Lisp_Object prop, val;
3059 prop = parms[p];
3060 val = values[p];
3061 if (EQ (prop, Qforeground_color)
3062 || EQ (prop, Qbackground_color)
3063 || EQ (prop, Qfont))
3065 register Lisp_Object param_index, old_value;
3067 old_value = get_frame_param (f, prop);
3068 if (NILP (Fequal (val, old_value)))
3070 store_frame_param (f, prop, val);
3072 param_index = Fget (prop, Qx_frame_parameter);
3073 if (NATNUMP (param_index)
3074 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3075 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3076 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3081 /* Now process them in reverse of specified order. */
3082 while (i-- != 0)
3084 Lisp_Object prop, val;
3086 prop = parms[i];
3087 val = values[i];
3089 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
3091 width_change = 1;
3092 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3094 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
3096 height_change = 1;
3097 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3099 else if (EQ (prop, Qtop))
3100 top = val;
3101 else if (EQ (prop, Qleft))
3102 left = val;
3103 else if (EQ (prop, Qicon_top))
3104 icon_top = val;
3105 else if (EQ (prop, Qicon_left))
3106 icon_left = val;
3107 else if (EQ (prop, Qforeground_color)
3108 || EQ (prop, Qbackground_color)
3109 || EQ (prop, Qfont))
3110 /* Processed above. */
3111 continue;
3112 else
3114 register Lisp_Object param_index, old_value;
3116 old_value = get_frame_param (f, prop);
3118 store_frame_param (f, prop, val);
3120 param_index = Fget (prop, Qx_frame_parameter);
3121 if (NATNUMP (param_index)
3122 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3123 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3124 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3128 /* Don't die if just one of these was set. */
3129 if (EQ (left, Qunbound))
3131 left_no_change = 1;
3132 if (f->left_pos < 0)
3133 left = list2 (Qplus, make_number (f->left_pos));
3134 else
3135 XSETINT (left, f->left_pos);
3137 if (EQ (top, Qunbound))
3139 top_no_change = 1;
3140 if (f->top_pos < 0)
3141 top = list2 (Qplus, make_number (f->top_pos));
3142 else
3143 XSETINT (top, f->top_pos);
3146 /* If one of the icon positions was not set, preserve or default it. */
3147 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3149 #ifdef HAVE_X_WINDOWS
3150 icon_left_no_change = 1;
3151 #endif
3152 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3153 if (NILP (icon_left))
3154 XSETINT (icon_left, 0);
3156 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3158 #ifdef HAVE_X_WINDOWS
3159 icon_top_no_change = 1;
3160 #endif
3161 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3162 if (NILP (icon_top))
3163 XSETINT (icon_top, 0);
3166 /* Don't set these parameters unless they've been explicitly
3167 specified. The window might be mapped or resized while we're in
3168 this function, and we don't want to override that unless the lisp
3169 code has asked for it.
3171 Don't set these parameters unless they actually differ from the
3172 window's current parameters; the window may not actually exist
3173 yet. */
3175 Lisp_Object frame;
3177 XSETFRAME (frame, f);
3179 if ((width_change && width != FRAME_TEXT_WIDTH (f))
3180 || (height_change && height != FRAME_TEXT_HEIGHT (f))
3181 || f->new_height || f->new_width)
3183 /* If necessary provide default values for HEIGHT and WIDTH. Do
3184 that here since otherwise a size change implied by an
3185 intermittent font change may get lost as in Bug#17142. */
3186 if (!width_change)
3187 width = (f->new_width
3188 ? (f->new_pixelwise
3189 ? f->new_width
3190 : (f->new_width * FRAME_COLUMN_WIDTH (f)))
3191 : FRAME_TEXT_WIDTH (f));
3193 if (!height_change)
3194 height = (f->new_height
3195 ? (f->new_pixelwise
3196 ? f->new_height
3197 : (f->new_height * FRAME_LINE_HEIGHT (f)))
3198 : FRAME_TEXT_HEIGHT (f));
3200 Fset_frame_size (frame, make_number (width), make_number (height), Qt);
3203 if ((!NILP (left) || !NILP (top))
3204 && ! (left_no_change && top_no_change)
3205 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3206 && NUMBERP (top) && XINT (top) == f->top_pos))
3208 int leftpos = 0;
3209 int toppos = 0;
3211 /* Record the signs. */
3212 f->size_hint_flags &= ~ (XNegative | YNegative);
3213 if (EQ (left, Qminus))
3214 f->size_hint_flags |= XNegative;
3215 else if (TYPE_RANGED_INTEGERP (int, left))
3217 leftpos = XINT (left);
3218 if (leftpos < 0)
3219 f->size_hint_flags |= XNegative;
3221 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3222 && CONSP (XCDR (left))
3223 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3225 leftpos = - XINT (XCAR (XCDR (left)));
3226 f->size_hint_flags |= XNegative;
3228 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3229 && CONSP (XCDR (left))
3230 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3232 leftpos = XINT (XCAR (XCDR (left)));
3235 if (EQ (top, Qminus))
3236 f->size_hint_flags |= YNegative;
3237 else if (TYPE_RANGED_INTEGERP (int, top))
3239 toppos = XINT (top);
3240 if (toppos < 0)
3241 f->size_hint_flags |= YNegative;
3243 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3244 && CONSP (XCDR (top))
3245 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3247 toppos = - XINT (XCAR (XCDR (top)));
3248 f->size_hint_flags |= YNegative;
3250 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3251 && CONSP (XCDR (top))
3252 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3254 toppos = XINT (XCAR (XCDR (top)));
3258 /* Store the numeric value of the position. */
3259 f->top_pos = toppos;
3260 f->left_pos = leftpos;
3262 f->win_gravity = NorthWestGravity;
3264 /* Actually set that position, and convert to absolute. */
3265 x_set_offset (f, leftpos, toppos, -1);
3267 #ifdef HAVE_X_WINDOWS
3268 if ((!NILP (icon_left) || !NILP (icon_top))
3269 && ! (icon_left_no_change && icon_top_no_change))
3270 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3271 #endif /* HAVE_X_WINDOWS */
3274 SAFE_FREE ();
3278 /* Insert a description of internally-recorded parameters of frame X
3279 into the parameter alist *ALISTPTR that is to be given to the user.
3280 Only parameters that are specific to the X window system
3281 and whose values are not correctly recorded in the frame's
3282 param_alist need to be considered here. */
3284 void
3285 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3287 Lisp_Object tem;
3288 uprintmax_t w;
3289 char buf[INT_BUFSIZE_BOUND (w)];
3291 /* Represent negative positions (off the top or left screen edge)
3292 in a way that Fmodify_frame_parameters will understand correctly. */
3293 XSETINT (tem, f->left_pos);
3294 if (f->left_pos >= 0)
3295 store_in_alist (alistptr, Qleft, tem);
3296 else
3297 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3299 XSETINT (tem, f->top_pos);
3300 if (f->top_pos >= 0)
3301 store_in_alist (alistptr, Qtop, tem);
3302 else
3303 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3305 store_in_alist (alistptr, Qborder_width,
3306 make_number (f->border_width));
3307 store_in_alist (alistptr, Qinternal_border_width,
3308 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3309 store_in_alist (alistptr, Qright_divider_width,
3310 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3311 store_in_alist (alistptr, Qbottom_divider_width,
3312 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3313 store_in_alist (alistptr, Qleft_fringe,
3314 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3315 store_in_alist (alistptr, Qright_fringe,
3316 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3317 store_in_alist (alistptr, Qscroll_bar_width,
3318 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3319 ? make_number (0)
3320 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3321 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3322 /* nil means "use default width"
3323 for non-toolkit scroll bar.
3324 ruler-mode.el depends on this. */
3325 : Qnil));
3326 store_in_alist (alistptr, Qscroll_bar_height,
3327 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3328 ? make_number (0)
3329 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3330 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3331 /* nil means "use default height"
3332 for non-toolkit scroll bar. */
3333 : Qnil));
3334 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3335 MS-Windows it returns a value whose type is HANDLE, which is
3336 actually a pointer. Explicit casting avoids compiler
3337 warnings. */
3338 w = (uintptr_t) FRAME_X_WINDOW (f);
3339 store_in_alist (alistptr, Qwindow_id,
3340 make_formatted_string (buf, "%"pMu, w));
3341 #ifdef HAVE_X_WINDOWS
3342 #ifdef USE_X_TOOLKIT
3343 /* Tooltip frame may not have this widget. */
3344 if (FRAME_X_OUTPUT (f)->widget)
3345 #endif
3346 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3347 store_in_alist (alistptr, Qouter_window_id,
3348 make_formatted_string (buf, "%"pMu, w));
3349 #endif
3350 store_in_alist (alistptr, Qicon_name, f->icon_name);
3351 store_in_alist (alistptr, Qvisibility,
3352 (FRAME_VISIBLE_P (f) ? Qt
3353 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3354 store_in_alist (alistptr, Qdisplay,
3355 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3357 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3358 tem = Qnil;
3359 else
3360 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3361 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3362 store_in_alist (alistptr, Qparent_id, tem);
3363 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3367 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3368 the previous value of that parameter, NEW_VALUE is the new value. */
3370 void
3371 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3373 if (NILP (new_value))
3374 f->want_fullscreen = FULLSCREEN_NONE;
3375 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3376 f->want_fullscreen = FULLSCREEN_BOTH;
3377 else if (EQ (new_value, Qfullwidth))
3378 f->want_fullscreen = FULLSCREEN_WIDTH;
3379 else if (EQ (new_value, Qfullheight))
3380 f->want_fullscreen = FULLSCREEN_HEIGHT;
3381 else if (EQ (new_value, Qmaximized))
3382 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3384 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3385 FRAME_TERMINAL (f)->fullscreen_hook (f);
3389 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3390 the previous value of that parameter, NEW_VALUE is the new value. */
3392 void
3393 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3395 if (NILP (new_value))
3396 f->extra_line_spacing = 0;
3397 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3398 f->extra_line_spacing = XFASTINT (new_value);
3399 else if (FLOATP (new_value))
3401 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3403 if (new_spacing >= 0)
3404 f->extra_line_spacing = new_spacing;
3405 else
3406 signal_error ("Invalid line-spacing", new_value);
3408 else
3409 signal_error ("Invalid line-spacing", new_value);
3410 if (FRAME_VISIBLE_P (f))
3411 redraw_frame (f);
3415 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3416 the previous value of that parameter, NEW_VALUE is the new value. */
3418 void
3419 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3421 Lisp_Object bgcolor;
3423 if (NILP (new_value))
3424 f->gamma = 0;
3425 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3426 /* The value 0.4545 is the normal viewing gamma. */
3427 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3428 else
3429 signal_error ("Invalid screen-gamma", new_value);
3431 /* Apply the new gamma value to the frame background. */
3432 bgcolor = Fassq (Qbackground_color, f->param_alist);
3433 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3435 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3436 if (NATNUMP (parm_index)
3437 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3438 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3439 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3440 (f, bgcolor, Qnil);
3443 Fclear_face_cache (Qnil);
3447 void
3448 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3450 Lisp_Object font_object;
3451 int fontset = -1;
3452 #ifdef HAVE_X_WINDOWS
3453 Lisp_Object font_param = arg;
3454 #endif
3456 /* Set the frame parameter back to the old value because we may
3457 fail to use ARG as the new parameter value. */
3458 store_frame_param (f, Qfont, oldval);
3460 /* ARG is a fontset name, a font name, a cons of fontset name and a
3461 font object, or a font object. In the last case, this function
3462 never fail. */
3463 if (STRINGP (arg))
3465 fontset = fs_query_fontset (arg, 0);
3466 if (fontset < 0)
3468 font_object = font_open_by_name (f, arg);
3469 if (NILP (font_object))
3470 error ("Font `%s' is not defined", SSDATA (arg));
3471 arg = AREF (font_object, FONT_NAME_INDEX);
3473 else if (fontset > 0)
3475 font_object = font_open_by_name (f, fontset_ascii (fontset));
3476 if (NILP (font_object))
3477 error ("Font `%s' is not defined", SDATA (arg));
3478 arg = AREF (font_object, FONT_NAME_INDEX);
3480 else
3481 error ("The default fontset can't be used for a frame font");
3483 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3485 /* This is the case that the ASCII font of F's fontset XCAR
3486 (arg) is changed to the font XCDR (arg) by
3487 `set-fontset-font'. */
3488 fontset = fs_query_fontset (XCAR (arg), 0);
3489 if (fontset < 0)
3490 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3491 font_object = XCDR (arg);
3492 arg = AREF (font_object, FONT_NAME_INDEX);
3493 #ifdef HAVE_X_WINDOWS
3494 font_param = Ffont_get (font_object, QCname);
3495 #endif
3497 else if (FONT_OBJECT_P (arg))
3499 font_object = arg;
3500 #ifdef HAVE_X_WINDOWS
3501 font_param = Ffont_get (font_object, QCname);
3502 #endif
3503 /* This is to store the XLFD font name in the frame parameter for
3504 backward compatibility. We should store the font-object
3505 itself in the future. */
3506 arg = AREF (font_object, FONT_NAME_INDEX);
3507 fontset = FRAME_FONTSET (f);
3508 /* Check if we can use the current fontset. If not, set FONTSET
3509 to -1 to generate a new fontset from FONT-OBJECT. */
3510 if (fontset >= 0)
3512 Lisp_Object ascii_font = fontset_ascii (fontset);
3513 Lisp_Object spec = font_spec_from_name (ascii_font);
3515 if (NILP (spec))
3516 signal_error ("Invalid font name", ascii_font);
3518 if (! font_match_p (spec, font_object))
3519 fontset = -1;
3522 else
3523 signal_error ("Invalid font", arg);
3525 if (! NILP (Fequal (font_object, oldval)))
3526 return;
3528 x_new_font (f, font_object, fontset);
3529 store_frame_param (f, Qfont, arg);
3530 #ifdef HAVE_X_WINDOWS
3531 store_frame_param (f, Qfont_param, font_param);
3532 #endif
3533 /* Recalculate toolbar height. */
3534 f->n_tool_bar_rows = 0;
3536 /* Ensure we redraw it. */
3537 clear_current_matrices (f);
3539 /* Attempt to hunt down bug#16028. */
3540 SET_FRAME_GARBAGED (f);
3542 recompute_basic_faces (f);
3544 do_pending_window_change (0);
3546 /* We used to call face-set-after-frame-default here, but it leads to
3547 recursive calls (since that function can set the `default' face's
3548 font which in turns changes the frame's `font' parameter).
3549 Also I don't know what this call is meant to do, but it seems the
3550 wrong way to do it anyway (it does a lot more work than what seems
3551 reasonable in response to a change to `font'). */
3555 void
3556 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3558 if (! NILP (new_value)
3559 && !CONSP (new_value))
3561 char *p0, *p1;
3563 CHECK_STRING (new_value);
3564 p0 = p1 = SSDATA (new_value);
3565 new_value = Qnil;
3566 while (*p0)
3568 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3569 if (p0 < p1)
3570 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3571 new_value);
3572 if (*p1)
3574 int c;
3576 while ((c = *++p1) && c_isspace (c));
3578 p0 = p1;
3580 new_value = Fnreverse (new_value);
3583 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3584 return;
3586 if (FRAME_FONT (f))
3587 free_all_realized_faces (Qnil);
3589 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3590 if (NILP (new_value))
3592 if (NILP (old_value))
3593 error ("No font backend available");
3594 font_update_drivers (f, old_value);
3595 error ("None of specified font backends are available");
3597 store_frame_param (f, Qfont_backend, new_value);
3599 if (FRAME_FONT (f))
3601 Lisp_Object frame;
3603 XSETFRAME (frame, f);
3604 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3605 ++face_change_count;
3606 windows_or_buffers_changed = 18;
3610 void
3611 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3613 int unit = FRAME_COLUMN_WIDTH (f);
3614 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3615 int new_width;
3617 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3618 ? eabs (XINT (new_value)) : 8);
3620 if (new_width != old_width)
3622 FRAME_LEFT_FRINGE_WIDTH (f) = new_width;
3623 FRAME_FRINGE_COLS (f) /* Round up. */
3624 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3626 if (FRAME_X_WINDOW (f) != 0)
3627 adjust_frame_size (f, -1, -1, 3, 0);
3629 SET_FRAME_GARBAGED (f);
3634 void
3635 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3637 int unit = FRAME_COLUMN_WIDTH (f);
3638 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3639 int new_width;
3641 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3642 ? eabs (XINT (new_value)) : 8);
3644 if (new_width != old_width)
3646 FRAME_RIGHT_FRINGE_WIDTH (f) = new_width;
3647 FRAME_FRINGE_COLS (f) /* Round up. */
3648 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3650 if (FRAME_X_WINDOW (f) != 0)
3651 adjust_frame_size (f, -1, -1, 3, 0);
3653 SET_FRAME_GARBAGED (f);
3658 void
3659 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3661 CHECK_TYPE_RANGED_INTEGER (int, arg);
3663 if (XINT (arg) == f->border_width)
3664 return;
3666 if (FRAME_X_WINDOW (f) != 0)
3667 error ("Cannot change the border width of a frame");
3669 f->border_width = XINT (arg);
3672 void
3673 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3675 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3677 CHECK_TYPE_RANGED_INTEGER (int, arg);
3678 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3679 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3680 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3681 if (FRAME_RIGHT_DIVIDER_WIDTH (f) != old)
3683 adjust_frame_size (f, -1, -1, 4, 0);
3684 adjust_frame_glyphs (f);
3685 SET_FRAME_GARBAGED (f);
3690 void
3691 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3693 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3695 CHECK_TYPE_RANGED_INTEGER (int, arg);
3696 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3697 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3698 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3699 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) != old)
3701 adjust_frame_size (f, -1, -1, 4, 0);
3702 adjust_frame_glyphs (f);
3703 SET_FRAME_GARBAGED (f);
3707 void
3708 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3710 Lisp_Object frame;
3711 XSETFRAME (frame, f);
3713 if (NILP (value))
3714 Fmake_frame_invisible (frame, Qt);
3715 else if (EQ (value, Qicon))
3716 Ficonify_frame (frame);
3717 else
3718 Fmake_frame_visible (frame);
3721 void
3722 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3724 f->auto_raise = !EQ (Qnil, arg);
3727 void
3728 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3730 f->auto_lower = !EQ (Qnil, arg);
3733 void
3734 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3736 f->no_split = !NILP (arg);
3739 void
3740 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3742 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3743 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3744 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3745 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3747 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3748 = (NILP (arg)
3749 ? vertical_scroll_bar_none
3750 : EQ (Qleft, arg)
3751 ? vertical_scroll_bar_left
3752 : EQ (Qright, arg)
3753 ? vertical_scroll_bar_right
3754 : EQ (Qleft, Vdefault_frame_scroll_bars)
3755 ? vertical_scroll_bar_left
3756 : EQ (Qright, Vdefault_frame_scroll_bars)
3757 ? vertical_scroll_bar_right
3758 : vertical_scroll_bar_none);
3760 /* We set this parameter before creating the X window for the
3761 frame, so we can get the geometry right from the start.
3762 However, if the window hasn't been created yet, we shouldn't
3763 call x_set_window_size. */
3764 if (FRAME_X_WINDOW (f))
3765 adjust_frame_size (f, -1, -1, 3, 0);
3767 SET_FRAME_GARBAGED (f);
3771 void
3772 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3774 #if (defined (HAVE_WINDOW_SYSTEM) \
3775 && ((defined (USE_TOOLKIT_SCROLL_BARS) && !defined (HAVE_NS)) \
3776 || defined (HAVE_NTGUI)))
3777 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3778 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3780 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3782 /* We set this parameter before creating the X window for the
3783 frame, so we can get the geometry right from the start.
3784 However, if the window hasn't been created yet, we shouldn't
3785 call x_set_window_size. */
3786 if (FRAME_X_WINDOW (f))
3787 adjust_frame_size (f, -1, -1, 3, 0);
3789 SET_FRAME_GARBAGED (f);
3791 #endif
3794 void
3795 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3797 int unit = FRAME_COLUMN_WIDTH (f);
3799 if (NILP (arg))
3801 x_set_scroll_bar_default_width (f);
3803 if (FRAME_X_WINDOW (f))
3804 adjust_frame_size (f, -1, -1, 3, 0);
3806 SET_FRAME_GARBAGED (f);
3808 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3809 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3811 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3812 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3813 if (FRAME_X_WINDOW (f))
3814 adjust_frame_size (f, -1, -1, 3, 0);
3816 SET_FRAME_GARBAGED (f);
3819 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3820 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3823 void
3824 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3826 #if (defined (HAVE_WINDOW_SYSTEM) \
3827 && ((defined (USE_TOOLKIT_SCROLL_BARS) && !defined (HAVE_NS)) \
3828 || defined (HAVE_NTGUI)))
3829 int unit = FRAME_LINE_HEIGHT (f);
3831 if (NILP (arg))
3833 x_set_scroll_bar_default_height (f);
3835 if (FRAME_X_WINDOW (f))
3836 adjust_frame_size (f, -1, -1, 3, 0);
3838 SET_FRAME_GARBAGED (f);
3840 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3841 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3843 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3844 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3845 if (FRAME_X_WINDOW (f))
3846 adjust_frame_size (f, -1, -1, 3, 0);
3848 SET_FRAME_GARBAGED (f);
3851 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3852 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3853 #endif
3856 void
3857 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3859 double alpha = 1.0;
3860 double newval[2];
3861 int i;
3862 Lisp_Object item;
3864 for (i = 0; i < 2; i++)
3866 newval[i] = 1.0;
3867 if (CONSP (arg))
3869 item = CAR (arg);
3870 arg = CDR (arg);
3872 else
3873 item = arg;
3875 if (NILP (item))
3876 alpha = - 1.0;
3877 else if (FLOATP (item))
3879 alpha = XFLOAT_DATA (item);
3880 if (! (0 <= alpha && alpha <= 1.0))
3881 args_out_of_range (make_float (0.0), make_float (1.0));
3883 else if (INTEGERP (item))
3885 EMACS_INT ialpha = XINT (item);
3886 if (! (0 <= ialpha && alpha <= 100))
3887 args_out_of_range (make_number (0), make_number (100));
3888 alpha = ialpha / 100.0;
3890 else
3891 wrong_type_argument (Qnumberp, item);
3892 newval[i] = alpha;
3895 for (i = 0; i < 2; i++)
3896 f->alpha[i] = newval[i];
3898 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3899 block_input ();
3900 x_set_frame_alpha (f);
3901 unblock_input ();
3902 #endif
3904 return;
3907 #ifndef HAVE_NS
3909 /* Non-zero if mouse is grabbed on DPYINFO
3910 and we know the frame where it is. */
3912 bool x_mouse_grabbed (Display_Info *dpyinfo)
3914 return (dpyinfo->grabbed
3915 && dpyinfo->last_mouse_frame
3916 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
3919 /* Re-highlight something with mouse-face properties
3920 on DPYINFO using saved frame and mouse position. */
3922 void
3923 x_redo_mouse_highlight (Display_Info *dpyinfo)
3925 if (dpyinfo->last_mouse_motion_frame
3926 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
3927 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
3928 dpyinfo->last_mouse_motion_x,
3929 dpyinfo->last_mouse_motion_y);
3932 #endif /* HAVE_NS */
3934 /* Subroutines of creating an X frame. */
3936 /* Make sure that Vx_resource_name is set to a reasonable value.
3937 Fix it up, or set it to `emacs' if it is too hopeless. */
3939 void
3940 validate_x_resource_name (void)
3942 ptrdiff_t len = 0;
3943 /* Number of valid characters in the resource name. */
3944 ptrdiff_t good_count = 0;
3945 /* Number of invalid characters in the resource name. */
3946 ptrdiff_t bad_count = 0;
3947 Lisp_Object new;
3948 ptrdiff_t i;
3950 if (!STRINGP (Vx_resource_class))
3951 Vx_resource_class = build_string (EMACS_CLASS);
3953 if (STRINGP (Vx_resource_name))
3955 unsigned char *p = SDATA (Vx_resource_name);
3957 len = SBYTES (Vx_resource_name);
3959 /* Only letters, digits, - and _ are valid in resource names.
3960 Count the valid characters and count the invalid ones. */
3961 for (i = 0; i < len; i++)
3963 int c = p[i];
3964 if (! ((c >= 'a' && c <= 'z')
3965 || (c >= 'A' && c <= 'Z')
3966 || (c >= '0' && c <= '9')
3967 || c == '-' || c == '_'))
3968 bad_count++;
3969 else
3970 good_count++;
3973 else
3974 /* Not a string => completely invalid. */
3975 bad_count = 5, good_count = 0;
3977 /* If name is valid already, return. */
3978 if (bad_count == 0)
3979 return;
3981 /* If name is entirely invalid, or nearly so, or is so implausibly
3982 large that alloca might not work, use `emacs'. */
3983 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3985 Vx_resource_name = build_string ("emacs");
3986 return;
3989 /* Name is partly valid. Copy it and replace the invalid characters
3990 with underscores. */
3992 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3994 for (i = 0; i < len; i++)
3996 int c = SREF (new, i);
3997 if (! ((c >= 'a' && c <= 'z')
3998 || (c >= 'A' && c <= 'Z')
3999 || (c >= '0' && c <= '9')
4000 || c == '-' || c == '_'))
4001 SSET (new, i, '_');
4005 /* Get specified attribute from resource database RDB.
4006 See Fx_get_resource below for other parameters. */
4008 static Lisp_Object
4009 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4011 CHECK_STRING (attribute);
4012 CHECK_STRING (class);
4014 if (!NILP (component))
4015 CHECK_STRING (component);
4016 if (!NILP (subclass))
4017 CHECK_STRING (subclass);
4018 if (NILP (component) != NILP (subclass))
4019 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4021 validate_x_resource_name ();
4023 /* Allocate space for the components, the dots which separate them,
4024 and the final '\0'. Make them big enough for the worst case. */
4025 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4026 + (STRINGP (component)
4027 ? SBYTES (component) : 0)
4028 + SBYTES (attribute)
4029 + 3);
4031 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4032 + SBYTES (class)
4033 + (STRINGP (subclass)
4034 ? SBYTES (subclass) : 0)
4035 + 3);
4036 USE_SAFE_ALLOCA;
4037 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4038 char *class_key = name_key + name_keysize;
4040 /* Start with emacs.FRAMENAME for the name (the specific one)
4041 and with `Emacs' for the class key (the general one). */
4042 strcpy (name_key, SSDATA (Vx_resource_name));
4043 strcpy (class_key, SSDATA (Vx_resource_class));
4045 strcat (class_key, ".");
4046 strcat (class_key, SSDATA (class));
4048 if (!NILP (component))
4050 strcat (class_key, ".");
4051 strcat (class_key, SSDATA (subclass));
4053 strcat (name_key, ".");
4054 strcat (name_key, SSDATA (component));
4057 strcat (name_key, ".");
4058 strcat (name_key, SSDATA (attribute));
4060 char *value = x_get_string_resource (rdb, name_key, class_key);
4061 SAFE_FREE();
4063 if (value && *value)
4064 return build_string (value);
4065 else
4066 return Qnil;
4070 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4071 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4072 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4073 class, where INSTANCE is the name under which Emacs was invoked, or
4074 the name specified by the `-name' or `-rn' command-line arguments.
4076 The optional arguments COMPONENT and SUBCLASS add to the key and the
4077 class, respectively. You must specify both of them or neither.
4078 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4079 and the class is `Emacs.CLASS.SUBCLASS'. */)
4080 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4081 Lisp_Object subclass)
4083 check_window_system (NULL);
4085 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4086 attribute, class, component, subclass);
4089 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4091 Lisp_Object
4092 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4093 Lisp_Object class, Lisp_Object component,
4094 Lisp_Object subclass)
4096 return xrdb_get_resource (dpyinfo->xrdb,
4097 attribute, class, component, subclass);
4100 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
4101 /* Used when C code wants a resource value. */
4102 /* Called from oldXMenu/Create.c. */
4103 char *
4104 x_get_resource_string (const char *attribute, const char *class)
4106 char *result;
4107 struct frame *sf = SELECTED_FRAME ();
4108 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4109 USE_SAFE_ALLOCA;
4111 /* Allocate space for the components, the dots which separate them,
4112 and the final '\0'. */
4113 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4114 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4115 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4116 char *class_key = name_key + name_keysize;
4118 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4119 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4121 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4122 name_key, class_key);
4123 SAFE_FREE ();
4124 return result;
4126 #endif
4128 /* Return the value of parameter PARAM.
4130 First search ALIST, then Vdefault_frame_alist, then the X defaults
4131 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4133 Convert the resource to the type specified by desired_type.
4135 If no default is specified, return Qunbound. If you call
4136 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4137 and don't let it get stored in any Lisp-visible variables! */
4139 Lisp_Object
4140 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4141 const char *attribute, const char *class, enum resource_types type)
4143 register Lisp_Object tem;
4145 tem = Fassq (param, alist);
4147 if (!NILP (tem))
4149 /* If we find this parm in ALIST, clear it out
4150 so that it won't be "left over" at the end. */
4151 Lisp_Object tail;
4152 XSETCAR (tem, Qnil);
4153 /* In case the parameter appears more than once in the alist,
4154 clear it out. */
4155 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4156 if (CONSP (XCAR (tail))
4157 && EQ (XCAR (XCAR (tail)), param))
4158 XSETCAR (XCAR (tail), Qnil);
4160 else
4161 tem = Fassq (param, Vdefault_frame_alist);
4163 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4164 look in the X resources. */
4165 if (EQ (tem, Qnil))
4167 if (attribute && dpyinfo)
4169 tem = display_x_get_resource (dpyinfo,
4170 build_string (attribute),
4171 build_string (class),
4172 Qnil, Qnil);
4174 if (NILP (tem))
4175 return Qunbound;
4177 switch (type)
4179 case RES_TYPE_NUMBER:
4180 return make_number (atoi (SSDATA (tem)));
4182 case RES_TYPE_BOOLEAN_NUMBER:
4183 if (!strcmp (SSDATA (tem), "on")
4184 || !strcmp (SSDATA (tem), "true"))
4185 return make_number (1);
4186 return make_number (atoi (SSDATA (tem)));
4187 break;
4189 case RES_TYPE_FLOAT:
4190 return make_float (atof (SSDATA (tem)));
4192 case RES_TYPE_BOOLEAN:
4193 tem = Fdowncase (tem);
4194 if (!strcmp (SSDATA (tem), "on")
4195 #ifdef HAVE_NS
4196 || !strcmp (SSDATA (tem), "yes")
4197 #endif
4198 || !strcmp (SSDATA (tem), "true"))
4199 return Qt;
4200 else
4201 return Qnil;
4203 case RES_TYPE_STRING:
4204 return tem;
4206 case RES_TYPE_SYMBOL:
4207 /* As a special case, we map the values `true' and `on'
4208 to Qt, and `false' and `off' to Qnil. */
4210 Lisp_Object lower;
4211 lower = Fdowncase (tem);
4212 if (!strcmp (SSDATA (lower), "on")
4213 #ifdef HAVE_NS
4214 || !strcmp (SSDATA (lower), "yes")
4215 #endif
4216 || !strcmp (SSDATA (lower), "true"))
4217 return Qt;
4218 else if (!strcmp (SSDATA (lower), "off")
4219 #ifdef HAVE_NS
4220 || !strcmp (SSDATA (lower), "no")
4221 #endif
4222 || !strcmp (SSDATA (lower), "false"))
4223 return Qnil;
4224 else
4225 return Fintern (tem, Qnil);
4228 default:
4229 emacs_abort ();
4232 else
4233 return Qunbound;
4235 return Fcdr (tem);
4238 static Lisp_Object
4239 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4240 const char *attribute, const char *class,
4241 enum resource_types type)
4243 return x_get_arg (FRAME_DISPLAY_INFO (f),
4244 alist, param, attribute, class, type);
4247 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4249 Lisp_Object
4250 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4251 Lisp_Object param,
4252 const char *attribute, const char *class,
4253 enum resource_types type)
4255 Lisp_Object value;
4257 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4258 attribute, class, type);
4259 if (! NILP (value) && ! EQ (value, Qunbound))
4260 store_frame_param (f, param, value);
4262 return value;
4266 /* Record in frame F the specified or default value according to ALIST
4267 of the parameter named PROP (a Lisp symbol).
4268 If no value is specified for PROP, look for an X default for XPROP
4269 on the frame named NAME.
4270 If that is not found either, use the value DEFLT. */
4272 Lisp_Object
4273 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4274 Lisp_Object deflt, const char *xprop, const char *xclass,
4275 enum resource_types type)
4277 Lisp_Object tem;
4279 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4280 if (EQ (tem, Qunbound))
4281 tem = deflt;
4282 x_set_frame_parameters (f, list1 (Fcons (prop, tem)));
4283 return tem;
4287 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4290 * XParseGeometry parses strings of the form
4291 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4292 * width, height, xoffset, and yoffset are unsigned integers.
4293 * Example: "=80x24+300-49"
4294 * The equal sign is optional.
4295 * It returns a bitmask that indicates which of the four values
4296 * were actually found in the string. For each value found,
4297 * the corresponding argument is updated; for each value
4298 * not found, the corresponding argument is left unchanged.
4301 static int
4302 XParseGeometry (char *string,
4303 int *x, int *y,
4304 unsigned int *width, unsigned int *height)
4306 int mask = NoValue;
4307 char *strind;
4308 unsigned long tempWidth, tempHeight;
4309 long int tempX, tempY;
4310 char *nextCharacter;
4312 if (string == NULL || *string == '\0')
4313 return mask;
4314 if (*string == '=')
4315 string++; /* ignore possible '=' at beg of geometry spec */
4317 strind = string;
4318 if (*strind != '+' && *strind != '-' && *strind != 'x')
4320 tempWidth = strtoul (strind, &nextCharacter, 10);
4321 if (strind == nextCharacter)
4322 return 0;
4323 strind = nextCharacter;
4324 mask |= WidthValue;
4327 if (*strind == 'x' || *strind == 'X')
4329 strind++;
4330 tempHeight = strtoul (strind, &nextCharacter, 10);
4331 if (strind == nextCharacter)
4332 return 0;
4333 strind = nextCharacter;
4334 mask |= HeightValue;
4337 if (*strind == '+' || *strind == '-')
4339 if (*strind == '-')
4340 mask |= XNegative;
4341 tempX = strtol (strind, &nextCharacter, 10);
4342 if (strind == nextCharacter)
4343 return 0;
4344 strind = nextCharacter;
4345 mask |= XValue;
4346 if (*strind == '+' || *strind == '-')
4348 if (*strind == '-')
4349 mask |= YNegative;
4350 tempY = strtol (strind, &nextCharacter, 10);
4351 if (strind == nextCharacter)
4352 return 0;
4353 strind = nextCharacter;
4354 mask |= YValue;
4358 /* If strind isn't at the end of the string then it's an invalid
4359 geometry specification. */
4361 if (*strind != '\0')
4362 return 0;
4364 if (mask & XValue)
4365 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4366 if (mask & YValue)
4367 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4368 if (mask & WidthValue)
4369 *width = min (tempWidth, UINT_MAX);
4370 if (mask & HeightValue)
4371 *height = min (tempHeight, UINT_MAX);
4372 return mask;
4375 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4378 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4379 make-docfile: the documentation string in ns-win.el was used for
4380 x-parse-geometry even in non-NS builds.
4382 With two definitions of x-parse-geometry in this file, various
4383 things still get confused (eg M-x apropos documentation), so that
4384 it is best if the two definitions just share the same doc-string.
4386 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4387 doc: /* Parse a display geometry string STRING.
4388 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4389 The properties returned may include `top', `left', `height', and `width'.
4390 For X, the value of `left' or `top' may be an integer,
4391 or a list (+ N) meaning N pixels relative to top/left corner,
4392 or a list (- N) meaning -N pixels relative to bottom/right corner.
4393 On Nextstep, this just calls `ns-parse-geometry'. */)
4394 (Lisp_Object string)
4396 int geometry, x, y;
4397 unsigned int width, height;
4398 Lisp_Object result;
4400 CHECK_STRING (string);
4402 #ifdef HAVE_NS
4403 if (strchr (SSDATA (string), ' ') != NULL)
4404 return call1 (Qns_parse_geometry, string);
4405 #endif
4406 geometry = XParseGeometry (SSDATA (string),
4407 &x, &y, &width, &height);
4408 result = Qnil;
4409 if (geometry & XValue)
4411 Lisp_Object element;
4413 if (x >= 0 && (geometry & XNegative))
4414 element = list3 (Qleft, Qminus, make_number (-x));
4415 else if (x < 0 && ! (geometry & XNegative))
4416 element = list3 (Qleft, Qplus, make_number (x));
4417 else
4418 element = Fcons (Qleft, make_number (x));
4419 result = Fcons (element, result);
4422 if (geometry & YValue)
4424 Lisp_Object element;
4426 if (y >= 0 && (geometry & YNegative))
4427 element = list3 (Qtop, Qminus, make_number (-y));
4428 else if (y < 0 && ! (geometry & YNegative))
4429 element = list3 (Qtop, Qplus, make_number (y));
4430 else
4431 element = Fcons (Qtop, make_number (y));
4432 result = Fcons (element, result);
4435 if (geometry & WidthValue)
4436 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4437 if (geometry & HeightValue)
4438 result = Fcons (Fcons (Qheight, make_number (height)), result);
4440 return result;
4444 /* Calculate the desired size and position of frame F.
4445 Return the flags saying which aspects were specified.
4447 Also set the win_gravity and size_hint_flags of F.
4449 Adjust height for toolbar if TOOLBAR_P is 1.
4451 This function does not make the coordinates positive. */
4453 #define DEFAULT_ROWS 35
4454 #define DEFAULT_COLS 80
4456 long
4457 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p)
4459 Lisp_Object height, width, user_size, top, left, user_position;
4460 long window_prompting = 0;
4461 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4463 /* Default values if we fall through.
4464 Actually, if that happens we should get
4465 window manager prompting. */
4466 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4467 SET_FRAME_COLS (f, DEFAULT_COLS);
4468 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4469 SET_FRAME_LINES (f, DEFAULT_ROWS);
4471 /* Window managers expect that if program-specified
4472 positions are not (0,0), they're intentional, not defaults. */
4473 f->top_pos = 0;
4474 f->left_pos = 0;
4476 /* Ensure that earlier new_width and new_height settings won't
4477 override what we specify below. */
4478 f->new_width = f->new_height = 0;
4480 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4481 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4482 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4484 if (!EQ (width, Qunbound))
4486 CHECK_NUMBER (width);
4487 if (! (0 <= XINT (width) && XINT (width) <= INT_MAX))
4488 xsignal1 (Qargs_out_of_range, width);
4490 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4493 if (!EQ (height, Qunbound))
4495 CHECK_NUMBER (height);
4496 if (! (0 <= XINT (height) && XINT (height) <= INT_MAX))
4497 xsignal1 (Qargs_out_of_range, height);
4499 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4502 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4503 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4504 window_prompting |= USSize;
4505 else
4506 window_prompting |= PSize;
4509 /* Add a tool bar height to the initial frame height so that the user
4510 gets a text display area of the size he specified with -g or via
4511 .Xdefaults. Later changes of the tool bar height don't change the
4512 frame size. This is done so that users can create tall Emacs
4513 frames without having to guess how tall the tool bar will get. */
4514 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4516 int margin, relief;
4518 relief = (tool_bar_button_relief >= 0
4519 ? tool_bar_button_relief
4520 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4522 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4523 margin = XFASTINT (Vtool_bar_button_margin);
4524 else if (CONSP (Vtool_bar_button_margin)
4525 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4526 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4527 else
4528 margin = 0;
4530 FRAME_TOOL_BAR_HEIGHT (f)
4531 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4532 Vframe_initial_frame_tool_bar_height = make_number (FRAME_TOOL_BAR_HEIGHT (f));
4535 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4536 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4537 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4538 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4540 if (EQ (top, Qminus))
4542 f->top_pos = 0;
4543 window_prompting |= YNegative;
4545 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4546 && CONSP (XCDR (top))
4547 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4549 f->top_pos = - XINT (XCAR (XCDR (top)));
4550 window_prompting |= YNegative;
4552 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4553 && CONSP (XCDR (top))
4554 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4556 f->top_pos = XINT (XCAR (XCDR (top)));
4558 else if (EQ (top, Qunbound))
4559 f->top_pos = 0;
4560 else
4562 CHECK_TYPE_RANGED_INTEGER (int, top);
4563 f->top_pos = XINT (top);
4564 if (f->top_pos < 0)
4565 window_prompting |= YNegative;
4568 if (EQ (left, Qminus))
4570 f->left_pos = 0;
4571 window_prompting |= XNegative;
4573 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4574 && CONSP (XCDR (left))
4575 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4577 f->left_pos = - XINT (XCAR (XCDR (left)));
4578 window_prompting |= XNegative;
4580 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4581 && CONSP (XCDR (left))
4582 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4584 f->left_pos = XINT (XCAR (XCDR (left)));
4586 else if (EQ (left, Qunbound))
4587 f->left_pos = 0;
4588 else
4590 CHECK_TYPE_RANGED_INTEGER (int, left);
4591 f->left_pos = XINT (left);
4592 if (f->left_pos < 0)
4593 window_prompting |= XNegative;
4596 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4597 window_prompting |= USPosition;
4598 else
4599 window_prompting |= PPosition;
4602 if (window_prompting & XNegative)
4604 if (window_prompting & YNegative)
4605 f->win_gravity = SouthEastGravity;
4606 else
4607 f->win_gravity = NorthEastGravity;
4609 else
4611 if (window_prompting & YNegative)
4612 f->win_gravity = SouthWestGravity;
4613 else
4614 f->win_gravity = NorthWestGravity;
4617 f->size_hint_flags = window_prompting;
4619 return window_prompting;
4624 #endif /* HAVE_WINDOW_SYSTEM */
4626 void
4627 frame_make_pointer_invisible (struct frame *f)
4629 if (! NILP (Vmake_pointer_invisible))
4631 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4632 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4634 f->mouse_moved = 0;
4635 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4636 f->pointer_invisible = 1;
4641 void
4642 frame_make_pointer_visible (struct frame *f)
4644 /* We don't check Vmake_pointer_invisible here in case the
4645 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4646 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4647 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4649 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4650 f->pointer_invisible = 0;
4654 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4655 Sframe_pointer_visible_p, 0, 1, 0,
4656 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4657 Otherwise it returns nil. FRAME omitted or nil means the
4658 selected frame. This is useful when `make-pointer-invisible' is set. */)
4659 (Lisp_Object frame)
4661 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4666 /***********************************************************************
4667 Multimonitor data
4668 ***********************************************************************/
4670 #ifdef HAVE_WINDOW_SYSTEM
4672 # if (defined HAVE_NS \
4673 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4674 void
4675 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4677 int i;
4678 for (i = 0; i < n_monitors; ++i)
4679 xfree (monitors[i].name);
4680 xfree (monitors);
4682 # endif
4684 Lisp_Object
4685 make_monitor_attribute_list (struct MonitorInfo *monitors,
4686 int n_monitors,
4687 int primary_monitor,
4688 Lisp_Object monitor_frames,
4689 const char *source)
4691 Lisp_Object attributes_list = Qnil;
4692 Lisp_Object primary_monitor_attributes = Qnil;
4693 int i;
4695 for (i = 0; i < n_monitors; ++i)
4697 Lisp_Object geometry, workarea, attributes = Qnil;
4698 struct MonitorInfo *mi = &monitors[i];
4700 if (mi->geom.width == 0) continue;
4702 workarea = list4i (mi->work.x, mi->work.y,
4703 mi->work.width, mi->work.height);
4704 geometry = list4i (mi->geom.x, mi->geom.y,
4705 mi->geom.width, mi->geom.height);
4706 attributes = Fcons (Fcons (Qsource, build_string (source)),
4707 attributes);
4708 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4709 attributes);
4710 attributes = Fcons (Fcons (Qmm_size,
4711 list2i (mi->mm_width, mi->mm_height)),
4712 attributes);
4713 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4714 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4715 if (mi->name)
4716 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4717 strlen (mi->name))),
4718 attributes);
4720 if (i == primary_monitor)
4721 primary_monitor_attributes = attributes;
4722 else
4723 attributes_list = Fcons (attributes, attributes_list);
4726 if (!NILP (primary_monitor_attributes))
4727 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4728 return attributes_list;
4731 #endif /* HAVE_WINDOW_SYSTEM */
4734 /***********************************************************************
4735 Initialization
4736 ***********************************************************************/
4738 void
4739 syms_of_frame (void)
4741 DEFSYM (Qframep, "framep");
4742 DEFSYM (Qframe_live_p, "frame-live-p");
4743 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4744 DEFSYM (Qexplicit_name, "explicit-name");
4745 DEFSYM (Qheight, "height");
4746 DEFSYM (Qicon, "icon");
4747 DEFSYM (Qminibuffer, "minibuffer");
4748 DEFSYM (Qmodeline, "modeline");
4749 DEFSYM (Qonly, "only");
4750 DEFSYM (Qnone, "none");
4751 DEFSYM (Qwidth, "width");
4752 DEFSYM (Qgeometry, "geometry");
4753 DEFSYM (Qicon_left, "icon-left");
4754 DEFSYM (Qicon_top, "icon-top");
4755 DEFSYM (Qtooltip, "tooltip");
4756 DEFSYM (Quser_position, "user-position");
4757 DEFSYM (Quser_size, "user-size");
4758 DEFSYM (Qwindow_id, "window-id");
4759 #ifdef HAVE_X_WINDOWS
4760 DEFSYM (Qouter_window_id, "outer-window-id");
4761 #endif
4762 DEFSYM (Qparent_id, "parent-id");
4763 DEFSYM (Qx, "x");
4764 DEFSYM (Qw32, "w32");
4765 DEFSYM (Qpc, "pc");
4766 DEFSYM (Qns, "ns");
4767 DEFSYM (Qvisible, "visible");
4768 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4769 DEFSYM (Qbuffer_list, "buffer-list");
4770 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4771 DEFSYM (Qdisplay_type, "display-type");
4772 DEFSYM (Qbackground_mode, "background-mode");
4773 DEFSYM (Qnoelisp, "noelisp");
4774 DEFSYM (Qtty_color_mode, "tty-color-mode");
4775 DEFSYM (Qtty, "tty");
4776 DEFSYM (Qtty_type, "tty-type");
4778 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4780 DEFSYM (Qfullwidth, "fullwidth");
4781 DEFSYM (Qfullheight, "fullheight");
4782 DEFSYM (Qfullboth, "fullboth");
4783 DEFSYM (Qmaximized, "maximized");
4784 DEFSYM (Qx_resource_name, "x-resource-name");
4785 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4787 DEFSYM (Qterminal, "terminal");
4789 DEFSYM (Qgeometry, "geometry");
4790 DEFSYM (Qworkarea, "workarea");
4791 DEFSYM (Qmm_size, "mm-size");
4792 DEFSYM (Qframes, "frames");
4793 DEFSYM (Qsource, "source");
4795 #ifdef HAVE_NS
4796 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4797 #endif
4800 int i;
4802 for (i = 0; i < ARRAYELTS (frame_parms); i++)
4804 Lisp_Object v = intern_c_string (frame_parms[i].name);
4805 if (frame_parms[i].variable)
4807 *frame_parms[i].variable = v;
4808 staticpro (frame_parms[i].variable);
4810 Fput (v, Qx_frame_parameter, make_number (i));
4814 #ifdef HAVE_WINDOW_SYSTEM
4815 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4816 doc: /* The name Emacs uses to look up X resources.
4817 `x-get-resource' uses this as the first component of the instance name
4818 when requesting resource values.
4819 Emacs initially sets `x-resource-name' to the name under which Emacs
4820 was invoked, or to the value specified with the `-name' or `-rn'
4821 switches, if present.
4823 It may be useful to bind this variable locally around a call
4824 to `x-get-resource'. See also the variable `x-resource-class'. */);
4825 Vx_resource_name = Qnil;
4827 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4828 doc: /* The class Emacs uses to look up X resources.
4829 `x-get-resource' uses this as the first component of the instance class
4830 when requesting resource values.
4832 Emacs initially sets `x-resource-class' to "Emacs".
4834 Setting this variable permanently is not a reasonable thing to do,
4835 but binding this variable locally around a call to `x-get-resource'
4836 is a reasonable practice. See also the variable `x-resource-name'. */);
4837 Vx_resource_class = build_string (EMACS_CLASS);
4839 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4840 doc: /* The lower limit of the frame opacity (alpha transparency).
4841 The value should range from 0 (invisible) to 100 (completely opaque).
4842 You can also use a floating number between 0.0 and 1.0. */);
4843 Vframe_alpha_lower_limit = make_number (20);
4844 #endif
4846 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4847 doc: /* Alist of default values for frame creation.
4848 These may be set in your init file, like this:
4849 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4850 These override values given in window system configuration data,
4851 including X Windows' defaults database.
4852 For values specific to the first Emacs frame, see `initial-frame-alist'.
4853 For window-system specific values, see `window-system-default-frame-alist'.
4854 For values specific to the separate minibuffer frame, see
4855 `minibuffer-frame-alist'.
4856 The `menu-bar-lines' element of the list controls whether new frames
4857 have menu bars; `menu-bar-mode' works by altering this element.
4858 Setting this variable does not affect existing frames, only new ones. */);
4859 Vdefault_frame_alist = Qnil;
4861 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4862 doc: /* Default position of vertical scroll bars on this window-system. */);
4863 #ifdef HAVE_WINDOW_SYSTEM
4864 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4865 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4866 default. */
4867 Vdefault_frame_scroll_bars = Qright;
4868 #else
4869 Vdefault_frame_scroll_bars = Qleft;
4870 #endif
4871 #else
4872 Vdefault_frame_scroll_bars = Qnil;
4873 #endif
4875 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
4876 scroll_bar_adjust_thumb_portion_p,
4877 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
4878 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
4879 even if the end of the buffer is shown (i.e. overscrolling).
4880 Set to nil if you want the thumb to be at the bottom when the end of the buffer
4881 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
4882 is visible. In this case you can not overscroll. */);
4883 scroll_bar_adjust_thumb_portion_p = 1;
4885 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4886 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4888 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4889 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4890 `mouse-position' calls this function, passing its usual return value as
4891 argument, and returns whatever this function returns.
4892 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4893 which need to do mouse handling at the Lisp level. */);
4894 Vmouse_position_function = Qnil;
4896 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4897 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4898 If the value is an integer, highlighting is only shown after moving the
4899 mouse, while keyboard input turns off the highlight even when the mouse
4900 is over the clickable text. However, the mouse shape still indicates
4901 when the mouse is over clickable text. */);
4902 Vmouse_highlight = Qt;
4904 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4905 doc: /* If non-nil, make pointer invisible while typing.
4906 The pointer becomes visible again when the mouse is moved. */);
4907 Vmake_pointer_invisible = Qt;
4909 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
4910 doc: /* Normal hook run when a frame gains input focus. */);
4911 Vfocus_in_hook = Qnil;
4912 DEFSYM (Qfocus_in_hook, "focus-in-hook");
4914 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
4915 doc: /* Normal hook run when a frame loses input focus. */);
4916 Vfocus_out_hook = Qnil;
4917 DEFSYM (Qfocus_out_hook, "focus-out-hook");
4919 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4920 doc: /* Functions run before deleting a frame.
4921 The functions are run with one arg, the frame to be deleted.
4922 See `delete-frame'.
4924 Note that functions in this list may be called just before the frame is
4925 actually deleted, or some time later (or even both when an earlier function
4926 in `delete-frame-functions' (indirectly) calls `delete-frame'
4927 recursively). */);
4928 Vdelete_frame_functions = Qnil;
4929 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4931 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4932 doc: /* Non-nil if Menu-Bar mode is enabled.
4933 See the command `menu-bar-mode' for a description of this minor mode.
4934 Setting this variable directly does not take effect;
4935 either customize it (see the info node `Easy Customization')
4936 or call the function `menu-bar-mode'. */);
4937 Vmenu_bar_mode = Qt;
4939 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4940 doc: /* Non-nil if Tool-Bar mode is enabled.
4941 See the command `tool-bar-mode' for a description of this minor mode.
4942 Setting this variable directly does not take effect;
4943 either customize it (see the info node `Easy Customization')
4944 or call the function `tool-bar-mode'. */);
4945 #ifdef HAVE_WINDOW_SYSTEM
4946 Vtool_bar_mode = Qt;
4947 #else
4948 Vtool_bar_mode = Qnil;
4949 #endif
4951 DEFVAR_LISP ("frame-initial-frame-tool-bar-height", Vframe_initial_frame_tool_bar_height,
4952 doc: /* Height of tool bar of initial frame. */);
4953 Vframe_initial_frame_tool_bar_height = make_number (0);
4955 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4956 doc: /* Minibufferless frames use this frame's minibuffer.
4957 Emacs cannot create minibufferless frames unless this is set to an
4958 appropriate surrogate.
4960 Emacs consults this variable only when creating minibufferless
4961 frames; once the frame is created, it sticks with its assigned
4962 minibuffer, no matter what this variable is set to. This means that
4963 this variable doesn't necessarily say anything meaningful about the
4964 current set of frames, or where the minibuffer is currently being
4965 displayed.
4967 This variable is local to the current terminal and cannot be buffer-local. */);
4969 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4970 doc: /* Non-nil if window system changes focus when you move the mouse.
4971 You should set this variable to tell Emacs how your window manager
4972 handles focus, since there is no way in general for Emacs to find out
4973 automatically. See also `mouse-autoselect-window'. */);
4974 focus_follows_mouse = 0;
4976 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
4977 doc: /* Non-nil means resize frames pixelwise.
4978 If this option is nil, resizing a frame rounds its sizes to the frame's
4979 current values of `frame-char-height' and `frame-char-width'. If this
4980 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
4981 by one pixel.
4983 With some window managers you may have to set this to non-nil in order
4984 to fully maximize frames. To resize your initial frame pixelwise, set
4985 this option to a non-nil value in your init file. */);
4986 frame_resize_pixelwise = 0;
4988 DEFVAR_BOOL ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
4989 doc: /* Non-nil means do not resize frame implicitly.
4990 If this option is nil, setting default font, menubar mode, fringe width,
4991 or scroll bar mode of a specific frame may resize the frame in order to
4992 preserve the number of columns or lines it displays. If this option is
4993 non-nil, no such resizing is done. */);
4994 frame_inhibit_implied_resize = 0;
4996 staticpro (&Vframe_list);
4998 defsubr (&Sframep);
4999 defsubr (&Sframe_live_p);
5000 defsubr (&Swindow_system);
5001 defsubr (&Smake_terminal_frame);
5002 defsubr (&Shandle_switch_frame);
5003 defsubr (&Sselect_frame);
5004 defsubr (&Sselected_frame);
5005 defsubr (&Sframe_list);
5006 defsubr (&Snext_frame);
5007 defsubr (&Sprevious_frame);
5008 defsubr (&Slast_nonminibuf_frame);
5009 defsubr (&Sdelete_frame);
5010 defsubr (&Smouse_position);
5011 defsubr (&Smouse_pixel_position);
5012 defsubr (&Sset_mouse_position);
5013 defsubr (&Sset_mouse_pixel_position);
5014 #if 0
5015 defsubr (&Sframe_configuration);
5016 defsubr (&Srestore_frame_configuration);
5017 #endif
5018 defsubr (&Smake_frame_visible);
5019 defsubr (&Smake_frame_invisible);
5020 defsubr (&Siconify_frame);
5021 defsubr (&Sframe_visible_p);
5022 defsubr (&Svisible_frame_list);
5023 defsubr (&Sraise_frame);
5024 defsubr (&Slower_frame);
5025 defsubr (&Sx_focus_frame);
5026 defsubr (&Sredirect_frame_focus);
5027 defsubr (&Sframe_focus);
5028 defsubr (&Sframe_parameters);
5029 defsubr (&Sframe_parameter);
5030 defsubr (&Smodify_frame_parameters);
5031 defsubr (&Sframe_char_height);
5032 defsubr (&Sframe_char_width);
5033 defsubr (&Sframe_pixel_height);
5034 defsubr (&Sframe_pixel_width);
5035 defsubr (&Sframe_text_cols);
5036 defsubr (&Sframe_text_lines);
5037 defsubr (&Sframe_total_cols);
5038 defsubr (&Sframe_total_lines);
5039 defsubr (&Sframe_text_width);
5040 defsubr (&Sframe_text_height);
5041 defsubr (&Sscroll_bar_width);
5042 defsubr (&Sscroll_bar_height);
5043 defsubr (&Sfringe_width);
5044 defsubr (&Sborder_width);
5045 defsubr (&Sright_divider_width);
5046 defsubr (&Sbottom_divider_width);
5047 defsubr (&Stool_bar_pixel_width);
5048 defsubr (&Sset_frame_height);
5049 defsubr (&Sset_frame_width);
5050 defsubr (&Sset_frame_size);
5051 defsubr (&Sset_frame_position);
5052 defsubr (&Sframe_pointer_visible_p);
5054 #ifdef HAVE_WINDOW_SYSTEM
5055 defsubr (&Sx_get_resource);
5056 defsubr (&Sx_parse_geometry);
5057 #endif