* lisp/emacs-lisp/easy-mmode.el (define-minor-mode): Use mode function
[emacs.git] / src / frame.c
blob501f01a3122aa8c25f198b92730ccca1cc0d64cc
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;
998 tty = get_future_frame_param
999 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1000 ? FRAME_TTY (XFRAME (selected_frame))->name
1001 : NULL));
1002 if (!NILP (tty))
1003 name = xlispstrdupa (tty);
1005 tty_type = get_future_frame_param
1006 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1007 ? FRAME_TTY (XFRAME (selected_frame))->type
1008 : NULL));
1009 if (!NILP (tty_type))
1010 type = xlispstrdupa (tty_type);
1012 t = init_tty (name, type, 0); /* Errors are not fatal. */
1015 f = make_terminal_frame (t);
1018 int width, height;
1019 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1020 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f), 5, 0);
1023 adjust_frame_glyphs (f);
1024 calculate_costs (f);
1025 XSETFRAME (frame, f);
1027 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1028 store_in_alist (&parms, Qtty,
1029 (t->display_info.tty->name
1030 ? build_string (t->display_info.tty->name)
1031 : Qnil));
1032 Fmodify_frame_parameters (frame, parms);
1034 /* Make the frame face alist be frame-specific, so that each
1035 frame could change its face definitions independently. */
1036 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1037 /* Simple Fcopy_alist isn't enough, because we need the contents of
1038 the vectors which are the CDRs of associations in face_alist to
1039 be copied as well. */
1040 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1041 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1042 return frame;
1046 /* Perform the switch to frame FRAME.
1048 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1049 FRAME1 as frame.
1051 If TRACK is non-zero and the frame that currently has the focus
1052 redirects its focus to the selected frame, redirect that focused
1053 frame's focus to FRAME instead.
1055 FOR_DELETION non-zero means that the selected frame is being
1056 deleted, which includes the possibility that the frame's terminal
1057 is dead.
1059 The value of NORECORD is passed as argument to Fselect_window. */
1061 Lisp_Object
1062 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1064 struct frame *sf = SELECTED_FRAME ();
1066 /* If FRAME is a switch-frame event, extract the frame we should
1067 switch to. */
1068 if (CONSP (frame)
1069 && EQ (XCAR (frame), Qswitch_frame)
1070 && CONSP (XCDR (frame)))
1071 frame = XCAR (XCDR (frame));
1073 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1074 a switch-frame event to arrive after a frame is no longer live,
1075 especially when deleting the initial frame during startup. */
1076 CHECK_FRAME (frame);
1077 if (! FRAME_LIVE_P (XFRAME (frame)))
1078 return Qnil;
1080 if (sf == XFRAME (frame))
1081 return frame;
1083 /* If a frame's focus has been redirected toward the currently
1084 selected frame, we should change the redirection to point to the
1085 newly selected frame. This means that if the focus is redirected
1086 from a minibufferless frame to a surrogate minibuffer frame, we
1087 can use `other-window' to switch between all the frames using
1088 that minibuffer frame, and the focus redirection will follow us
1089 around. */
1090 #if 0
1091 /* This is too greedy; it causes inappropriate focus redirection
1092 that's hard to get rid of. */
1093 if (track)
1095 Lisp_Object tail;
1097 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1099 Lisp_Object focus;
1101 if (!FRAMEP (XCAR (tail)))
1102 emacs_abort ();
1104 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1106 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1107 Fredirect_frame_focus (XCAR (tail), frame);
1110 #else /* ! 0 */
1111 /* Instead, apply it only to the frame we're pointing to. */
1112 #ifdef HAVE_WINDOW_SYSTEM
1113 if (track && FRAME_WINDOW_P (XFRAME (frame)))
1115 Lisp_Object focus, xfocus;
1117 xfocus = x_get_focus_frame (XFRAME (frame));
1118 if (FRAMEP (xfocus))
1120 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1121 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1122 Fredirect_frame_focus (xfocus, frame);
1125 #endif /* HAVE_X_WINDOWS */
1126 #endif /* ! 0 */
1128 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1129 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1131 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
1133 struct frame *f = XFRAME (frame);
1134 struct tty_display_info *tty = FRAME_TTY (f);
1135 Lisp_Object top_frame = tty->top_frame;
1137 /* Don't mark the frame garbaged and/or obscured if we are
1138 switching to the frame that is already the top frame of that
1139 TTY. */
1140 if (!EQ (frame, top_frame))
1142 if (FRAMEP (top_frame))
1143 /* Mark previously displayed frame as now obscured. */
1144 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1145 SET_FRAME_VISIBLE (f, 1);
1146 /* If the new TTY frame changed dimensions, we need to
1147 resync term.c's idea of the frame size with the new
1148 frame's data. */
1149 if (FRAME_COLS (f) != FrameCols (tty))
1150 FrameCols (tty) = FRAME_COLS (f);
1151 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1152 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1154 tty->top_frame = frame;
1157 selected_frame = frame;
1158 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1159 last_nonminibuf_frame = XFRAME (selected_frame);
1161 Fselect_window (XFRAME (frame)->selected_window, norecord);
1163 /* We want to make sure that the next event generates a frame-switch
1164 event to the appropriate frame. This seems kludgy to me, but
1165 before you take it out, make sure that evaluating something like
1166 (select-window (frame-root-window (new-frame))) doesn't end up
1167 with your typing being interpreted in the new frame instead of
1168 the one you're actually typing in. */
1169 internal_last_event_frame = Qnil;
1171 return frame;
1174 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1175 doc: /* Select FRAME.
1176 Subsequent editing commands apply to its selected window.
1177 Optional argument NORECORD means to neither change the order of
1178 recently selected windows nor the buffer list.
1180 The selection of FRAME lasts until the next time the user does
1181 something to select a different frame, or until the next time
1182 this function is called. If you are using a window system, the
1183 previously selected frame may be restored as the selected frame
1184 when returning to the command loop, because it still may have
1185 the window system's input focus. On a text terminal, the next
1186 redisplay will display FRAME.
1188 This function returns FRAME, or nil if FRAME has been deleted. */)
1189 (Lisp_Object frame, Lisp_Object norecord)
1191 return do_switch_frame (frame, 1, 0, norecord);
1194 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
1195 doc: /* Handle a switch-frame event EVENT.
1196 Switch-frame events are usually bound to this function.
1197 A switch-frame event tells Emacs that the window manager has requested
1198 that the user's events be directed to the frame mentioned in the event.
1199 This function selects the selected window of the frame of EVENT.
1201 If EVENT is frame object, handle it as if it were a switch-frame event
1202 to that frame. */)
1203 (Lisp_Object event)
1205 /* Preserve prefix arg that the command loop just cleared. */
1206 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1207 Frun_hooks (1, &Qmouse_leave_buffer_hook);
1208 /* `switch-frame' implies a focus in. */
1209 call1 (intern ("handle-focus-in"), event);
1210 return do_switch_frame (event, 0, 0, Qnil);
1213 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1214 doc: /* Return the frame that is now selected. */)
1215 (void)
1217 return selected_frame;
1220 DEFUN ("frame-list", Fframe_list, Sframe_list,
1221 0, 0, 0,
1222 doc: /* Return a list of all live frames. */)
1223 (void)
1225 Lisp_Object frames;
1226 frames = Fcopy_sequence (Vframe_list);
1227 #ifdef HAVE_WINDOW_SYSTEM
1228 if (FRAMEP (tip_frame))
1229 frames = Fdelq (tip_frame, frames);
1230 #endif
1231 return frames;
1234 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1235 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1236 If MINIBUF is nil, do not consider minibuffer-only candidate.
1237 If MINIBUF is `visible', do not consider an invisible candidate.
1238 If MINIBUF is a window, consider only its own frame and candidate now
1239 using that window as the minibuffer.
1240 If MINIBUF is 0, consider candidate if it is visible or iconified.
1241 Otherwise consider any candidate and return nil if CANDIDATE is not
1242 acceptable. */
1244 static Lisp_Object
1245 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1247 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1249 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1250 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1251 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1252 && FRAME_TTY (c) == FRAME_TTY (f)))
1254 if (NILP (minibuf))
1256 if (!FRAME_MINIBUF_ONLY_P (c))
1257 return candidate;
1259 else if (EQ (minibuf, Qvisible))
1261 if (FRAME_VISIBLE_P (c))
1262 return candidate;
1264 else if (WINDOWP (minibuf))
1266 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1267 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1268 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1269 FRAME_FOCUS_FRAME (c)))
1270 return candidate;
1272 else if (XFASTINT (minibuf) == 0)
1274 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1275 return candidate;
1277 else
1278 return candidate;
1280 return Qnil;
1283 /* Return the next frame in the frame list after FRAME. */
1285 static Lisp_Object
1286 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1288 Lisp_Object f, tail;
1289 int passed = 0;
1291 /* There must always be at least one frame in Vframe_list. */
1292 eassert (CONSP (Vframe_list));
1294 while (passed < 2)
1295 FOR_EACH_FRAME (tail, f)
1297 if (passed)
1299 f = candidate_frame (f, frame, minibuf);
1300 if (!NILP (f))
1301 return f;
1303 if (EQ (frame, f))
1304 passed++;
1306 return frame;
1309 /* Return the previous frame in the frame list before FRAME. */
1311 static Lisp_Object
1312 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1314 Lisp_Object f, tail, prev = Qnil;
1316 /* There must always be at least one frame in Vframe_list. */
1317 eassert (CONSP (Vframe_list));
1319 FOR_EACH_FRAME (tail, f)
1321 if (EQ (frame, f) && !NILP (prev))
1322 return prev;
1323 f = candidate_frame (f, frame, minibuf);
1324 if (!NILP (f))
1325 prev = f;
1328 /* We've scanned the entire list. */
1329 if (NILP (prev))
1330 /* We went through the whole frame list without finding a single
1331 acceptable frame. Return the original frame. */
1332 return frame;
1333 else
1334 /* There were no acceptable frames in the list before FRAME; otherwise,
1335 we would have returned directly from the loop. Since PREV is the last
1336 acceptable frame in the list, return it. */
1337 return prev;
1341 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1342 doc: /* Return the next frame in the frame list after FRAME.
1343 It considers only frames on the same terminal as FRAME.
1344 By default, skip minibuffer-only frames.
1345 If omitted, FRAME defaults to the selected frame.
1346 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1347 If MINIFRAME is a window, include only its own frame
1348 and any frame now using that window as the minibuffer.
1349 If MINIFRAME is `visible', include all visible frames.
1350 If MINIFRAME is 0, include all visible and iconified frames.
1351 Otherwise, include all frames. */)
1352 (Lisp_Object frame, Lisp_Object miniframe)
1354 if (NILP (frame))
1355 frame = selected_frame;
1356 CHECK_LIVE_FRAME (frame);
1357 return next_frame (frame, miniframe);
1360 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1361 doc: /* Return the previous frame in the frame list before FRAME.
1362 It considers only frames on the same terminal as FRAME.
1363 By default, skip minibuffer-only frames.
1364 If omitted, FRAME defaults to the selected frame.
1365 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1366 If MINIFRAME is a window, include only its own frame
1367 and any frame now using that window as the minibuffer.
1368 If MINIFRAME is `visible', include all visible frames.
1369 If MINIFRAME is 0, include all visible and iconified frames.
1370 Otherwise, include all frames. */)
1371 (Lisp_Object frame, Lisp_Object miniframe)
1373 if (NILP (frame))
1374 frame = selected_frame;
1375 CHECK_LIVE_FRAME (frame);
1376 return prev_frame (frame, miniframe);
1379 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1380 Slast_nonminibuf_frame, 0, 0, 0,
1381 doc: /* Return last non-minibuffer frame selected. */)
1382 (void)
1384 Lisp_Object frame = Qnil;
1386 if (last_nonminibuf_frame)
1387 XSETFRAME (frame, last_nonminibuf_frame);
1389 return frame;
1392 /* Return 1 if it is ok to delete frame F;
1393 0 if all frames aside from F are invisible.
1394 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1396 static int
1397 other_visible_frames (struct frame *f)
1399 Lisp_Object frames, this;
1401 FOR_EACH_FRAME (frames, this)
1403 if (f == XFRAME (this))
1404 continue;
1406 /* Verify that we can still talk to the frame's X window,
1407 and note any recent change in visibility. */
1408 #ifdef HAVE_X_WINDOWS
1409 if (FRAME_WINDOW_P (XFRAME (this)))
1410 x_sync (XFRAME (this));
1411 #endif
1413 if (FRAME_VISIBLE_P (XFRAME (this))
1414 || FRAME_ICONIFIED_P (XFRAME (this))
1415 /* Allow deleting the terminal frame when at least one X
1416 frame exists. */
1417 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1418 return 1;
1420 return 0;
1423 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1424 window. Preferably use the selected frame's minibuffer window
1425 instead. If the selected frame doesn't have one, get some other
1426 frame's minibuffer window. SELECT non-zero means select the new
1427 minibuffer window. */
1428 static void
1429 check_minibuf_window (Lisp_Object frame, int select)
1431 struct frame *f = decode_live_frame (frame);
1433 XSETFRAME (frame, f);
1435 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1437 Lisp_Object frames, this, window = make_number (0);
1439 if (!EQ (frame, selected_frame)
1440 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1441 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1442 else
1443 FOR_EACH_FRAME (frames, this)
1445 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1447 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1448 break;
1452 /* Don't abort if no window was found (Bug#15247). */
1453 if (WINDOWP (window))
1455 /* Use set_window_buffer instead of Fset_window_buffer (see
1456 discussion of bug#11984, bug#12025, bug#12026). */
1457 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1458 minibuf_window = window;
1460 /* SELECT non-zero usually means that FRAME's minibuffer
1461 window was selected; select the new one. */
1462 if (select)
1463 Fselect_window (minibuf_window, Qnil);
1469 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1470 unconditionally. x_connection_closed and delete_terminal use
1471 this. Any other value of FORCE implements the semantics
1472 described for Fdelete_frame. */
1473 Lisp_Object
1474 delete_frame (Lisp_Object frame, Lisp_Object force)
1476 struct frame *f = decode_any_frame (frame);
1477 struct frame *sf;
1478 struct kboard *kb;
1480 int minibuffer_selected, is_tooltip_frame;
1482 if (! FRAME_LIVE_P (f))
1483 return Qnil;
1485 if (NILP (force) && !other_visible_frames (f))
1486 error ("Attempt to delete the sole visible or iconified frame");
1488 /* x_connection_closed must have set FORCE to `noelisp' in order
1489 to delete the last frame, if it is gone. */
1490 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1491 error ("Attempt to delete the only frame");
1493 XSETFRAME (frame, f);
1495 /* Does this frame have a minibuffer, and is it the surrogate
1496 minibuffer for any other frame? */
1497 if (FRAME_HAS_MINIBUF_P (f))
1499 Lisp_Object frames, this;
1501 FOR_EACH_FRAME (frames, this)
1503 Lisp_Object fminiw;
1505 if (EQ (this, frame))
1506 continue;
1508 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1510 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1512 /* If we MUST delete this frame, delete the other first.
1513 But do this only if FORCE equals `noelisp'. */
1514 if (EQ (force, Qnoelisp))
1515 delete_frame (this, Qnoelisp);
1516 else
1517 error ("Attempt to delete a surrogate minibuffer frame");
1522 is_tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1524 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1525 frame is a tooltip. FORCE is set to `noelisp' when handling
1526 a disconnect from the terminal, so we don't dare call Lisp
1527 code. */
1528 if (NILP (Vrun_hooks) || is_tooltip_frame)
1530 else if (EQ (force, Qnoelisp))
1531 pending_funcalls
1532 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1533 pending_funcalls);
1534 else
1536 #ifdef HAVE_X_WINDOWS
1537 /* Also, save clipboard to the clipboard manager. */
1538 x_clipboard_manager_save_frame (frame);
1539 #endif
1541 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1544 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1545 if (! FRAME_LIVE_P (f))
1546 return Qnil;
1548 /* At this point, we are committed to deleting the frame.
1549 There is no more chance for errors to prevent it. */
1551 minibuffer_selected = EQ (minibuf_window, selected_window);
1552 sf = SELECTED_FRAME ();
1553 /* Don't let the frame remain selected. */
1554 if (f == sf)
1556 Lisp_Object tail;
1557 Lisp_Object frame1 = Qnil;
1559 /* Look for another visible frame on the same terminal.
1560 Do not call next_frame here because it may loop forever.
1561 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1562 FOR_EACH_FRAME (tail, frame1)
1563 if (!EQ (frame, frame1)
1564 && (FRAME_TERMINAL (XFRAME (frame))
1565 == FRAME_TERMINAL (XFRAME (frame1)))
1566 && FRAME_VISIBLE_P (XFRAME (frame1)))
1567 break;
1569 /* If there is none, find *some* other frame. */
1570 if (NILP (frame1) || EQ (frame1, frame))
1572 FOR_EACH_FRAME (tail, frame1)
1574 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1576 /* Do not change a text terminal's top-frame. */
1577 struct frame *f1 = XFRAME (frame1);
1578 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1580 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1581 if (!EQ (top_frame, frame))
1582 frame1 = top_frame;
1584 break;
1588 #ifdef NS_IMPL_COCOA
1589 else
1590 /* Under NS, there is no system mechanism for choosing a new
1591 window to get focus -- it is left to application code.
1592 So the portion of THIS application interfacing with NS
1593 needs to know about it. We call Fraise_frame, but the
1594 purpose is really to transfer focus. */
1595 Fraise_frame (frame1);
1596 #endif
1598 do_switch_frame (frame1, 0, 1, Qnil);
1599 sf = SELECTED_FRAME ();
1602 /* Don't allow minibuf_window to remain on a deleted frame. */
1603 check_minibuf_window (frame, minibuffer_selected);
1605 /* Don't let echo_area_window to remain on a deleted frame. */
1606 if (EQ (f->minibuffer_window, echo_area_window))
1607 echo_area_window = sf->minibuffer_window;
1609 /* Clear any X selections for this frame. */
1610 #ifdef HAVE_X_WINDOWS
1611 if (FRAME_X_P (f))
1612 x_clear_frame_selections (f);
1613 #endif
1615 /* Free glyphs.
1616 This function must be called before the window tree of the
1617 frame is deleted because windows contain dynamically allocated
1618 memory. */
1619 free_glyphs (f);
1621 #ifdef HAVE_WINDOW_SYSTEM
1622 /* Give chance to each font driver to free a frame specific data. */
1623 font_update_drivers (f, Qnil);
1624 #endif
1626 /* Mark all the windows that used to be on FRAME as deleted, and then
1627 remove the reference to them. */
1628 delete_all_child_windows (f->root_window);
1629 fset_root_window (f, Qnil);
1631 Vframe_list = Fdelq (frame, Vframe_list);
1632 SET_FRAME_VISIBLE (f, 0);
1634 /* Allow the vector of menu bar contents to be freed in the next
1635 garbage collection. The frame object itself may not be garbage
1636 collected until much later, because recent_keys and other data
1637 structures can still refer to it. */
1638 fset_menu_bar_vector (f, Qnil);
1640 /* If FRAME's buffer lists contains killed
1641 buffers, this helps GC to reclaim them. */
1642 fset_buffer_list (f, Qnil);
1643 fset_buried_buffer_list (f, Qnil);
1645 free_font_driver_list (f);
1646 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1647 xfree (f->namebuf);
1648 #endif
1649 xfree (f->decode_mode_spec_buffer);
1650 xfree (FRAME_INSERT_COST (f));
1651 xfree (FRAME_DELETEN_COST (f));
1652 xfree (FRAME_INSERTN_COST (f));
1653 xfree (FRAME_DELETE_COST (f));
1655 /* Since some events are handled at the interrupt level, we may get
1656 an event for f at any time; if we zero out the frame's terminal
1657 now, then we may trip up the event-handling code. Instead, we'll
1658 promise that the terminal of the frame must be valid until we
1659 have called the window-system-dependent frame destruction
1660 routine. */
1664 struct terminal *terminal;
1665 block_input ();
1666 if (FRAME_TERMINAL (f)->delete_frame_hook)
1667 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1668 terminal = FRAME_TERMINAL (f);
1669 f->output_data.nothing = 0;
1670 f->terminal = 0; /* Now the frame is dead. */
1671 unblock_input ();
1673 /* If needed, delete the terminal that this frame was on.
1674 (This must be done after the frame is killed.) */
1675 terminal->reference_count--;
1676 #ifdef USE_GTK
1677 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1678 bug.
1679 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1680 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1681 terminal->reference_count = 1;
1682 #endif /* USE_GTK */
1683 if (terminal->reference_count == 0)
1685 Lisp_Object tmp;
1686 XSETTERMINAL (tmp, terminal);
1688 kb = NULL;
1689 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1691 else
1692 kb = terminal->kboard;
1695 /* If we've deleted the last_nonminibuf_frame, then try to find
1696 another one. */
1697 if (f == last_nonminibuf_frame)
1699 Lisp_Object frames, this;
1701 last_nonminibuf_frame = 0;
1703 FOR_EACH_FRAME (frames, this)
1705 f = XFRAME (this);
1706 if (!FRAME_MINIBUF_ONLY_P (f))
1708 last_nonminibuf_frame = f;
1709 break;
1714 /* If there's no other frame on the same kboard, get out of
1715 single-kboard state if we're in it for this kboard. */
1716 if (kb != NULL)
1718 Lisp_Object frames, this;
1719 /* Some frame we found on the same kboard, or nil if there are none. */
1720 Lisp_Object frame_on_same_kboard = Qnil;
1722 FOR_EACH_FRAME (frames, this)
1723 if (kb == FRAME_KBOARD (XFRAME (this)))
1724 frame_on_same_kboard = this;
1726 if (NILP (frame_on_same_kboard))
1727 not_single_kboard_state (kb);
1731 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1732 find another one. Prefer minibuffer-only frames, but also notice
1733 frames with other windows. */
1734 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1736 Lisp_Object frames, this;
1738 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1739 Lisp_Object frame_with_minibuf = Qnil;
1740 /* Some frame we found on the same kboard, or nil if there are none. */
1741 Lisp_Object frame_on_same_kboard = Qnil;
1743 FOR_EACH_FRAME (frames, this)
1745 struct frame *f1 = XFRAME (this);
1747 /* Consider only frames on the same kboard
1748 and only those with minibuffers. */
1749 if (kb == FRAME_KBOARD (f1)
1750 && FRAME_HAS_MINIBUF_P (f1))
1752 frame_with_minibuf = this;
1753 if (FRAME_MINIBUF_ONLY_P (f1))
1754 break;
1757 if (kb == FRAME_KBOARD (f1))
1758 frame_on_same_kboard = this;
1761 if (!NILP (frame_on_same_kboard))
1763 /* We know that there must be some frame with a minibuffer out
1764 there. If this were not true, all of the frames present
1765 would have to be minibufferless, which implies that at some
1766 point their minibuffer frames must have been deleted, but
1767 that is prohibited at the top; you can't delete surrogate
1768 minibuffer frames. */
1769 if (NILP (frame_with_minibuf))
1770 emacs_abort ();
1772 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1774 else
1775 /* No frames left on this kboard--say no minibuffer either. */
1776 kset_default_minibuffer_frame (kb, Qnil);
1779 /* Cause frame titles to update--necessary if we now have just one frame. */
1780 if (!is_tooltip_frame)
1781 update_mode_lines = 15;
1783 return Qnil;
1786 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1787 doc: /* Delete FRAME, permanently eliminating it from use.
1788 FRAME defaults to the selected frame.
1790 A frame may not be deleted if its minibuffer is used by other frames.
1791 Normally, you may not delete a frame if all other frames are invisible,
1792 but if the second optional argument FORCE is non-nil, you may do so.
1794 This function runs `delete-frame-functions' before actually
1795 deleting the frame, unless the frame is a tooltip.
1796 The functions are run with one argument, the frame to be deleted. */)
1797 (Lisp_Object frame, Lisp_Object force)
1799 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1803 /* Return mouse position in character cell units. */
1805 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1806 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1807 The position is given in character cells, where (0, 0) is the
1808 upper-left corner of the frame, X is the horizontal offset, and Y is
1809 the vertical offset.
1810 If Emacs is running on a mouseless terminal or hasn't been programmed
1811 to read the mouse position, it returns the selected frame for FRAME
1812 and nil for X and Y.
1813 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1814 passing the normal return value to that function as an argument,
1815 and returns whatever that function returns. */)
1816 (void)
1818 struct frame *f;
1819 Lisp_Object lispy_dummy;
1820 Lisp_Object x, y, retval;
1821 struct gcpro gcpro1;
1823 f = SELECTED_FRAME ();
1824 x = y = Qnil;
1826 /* It's okay for the hook to refrain from storing anything. */
1827 if (FRAME_TERMINAL (f)->mouse_position_hook)
1829 enum scroll_bar_part party_dummy;
1830 Time time_dummy;
1831 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1832 &lispy_dummy, &party_dummy,
1833 &x, &y,
1834 &time_dummy);
1837 if (! NILP (x))
1839 int col = XINT (x);
1840 int row = XINT (y);
1841 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1842 XSETINT (x, col);
1843 XSETINT (y, row);
1845 XSETFRAME (lispy_dummy, f);
1846 retval = Fcons (lispy_dummy, Fcons (x, y));
1847 GCPRO1 (retval);
1848 if (!NILP (Vmouse_position_function))
1849 retval = call1 (Vmouse_position_function, retval);
1850 RETURN_UNGCPRO (retval);
1853 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1854 Smouse_pixel_position, 0, 0, 0,
1855 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1856 The position is given in pixel units, where (0, 0) is the
1857 upper-left corner of the frame, X is the horizontal offset, and Y is
1858 the vertical offset.
1859 If Emacs is running on a mouseless terminal or hasn't been programmed
1860 to read the mouse position, it returns the selected frame for FRAME
1861 and nil for X and Y. */)
1862 (void)
1864 struct frame *f;
1865 Lisp_Object lispy_dummy;
1866 Lisp_Object x, y;
1868 f = SELECTED_FRAME ();
1869 x = y = Qnil;
1871 /* It's okay for the hook to refrain from storing anything. */
1872 if (FRAME_TERMINAL (f)->mouse_position_hook)
1874 enum scroll_bar_part party_dummy;
1875 Time time_dummy;
1876 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1877 &lispy_dummy, &party_dummy,
1878 &x, &y,
1879 &time_dummy);
1882 XSETFRAME (lispy_dummy, f);
1883 return Fcons (lispy_dummy, Fcons (x, y));
1886 #ifdef HAVE_WINDOW_SYSTEM
1888 /* On frame F, convert character coordinates X and Y to pixel
1889 coordinates *PIX_X and *PIX_Y. */
1891 static void
1892 frame_char_to_pixel_position (struct frame *f, int x, int y,
1893 int *pix_x, int *pix_y)
1895 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
1896 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
1898 if (*pix_x < 0)
1899 *pix_x = 0;
1900 if (*pix_x > FRAME_PIXEL_WIDTH (f))
1901 *pix_x = FRAME_PIXEL_WIDTH (f);
1903 if (*pix_y < 0)
1904 *pix_y = 0;
1905 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
1906 *pix_y = FRAME_PIXEL_HEIGHT (f);
1909 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1911 static void
1912 frame_set_mouse_position (struct frame *f, int x, int y)
1914 int pix_x, pix_y;
1916 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
1917 frame_set_mouse_pixel_position (f, pix_x, pix_y);
1920 #endif /* HAVE_WINDOW_SYSTEM */
1922 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1923 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1924 Coordinates are relative to the frame, not a window,
1925 so the coordinates of the top left character in the frame
1926 may be nonzero due to left-hand scroll bars or the menu bar.
1928 The position is given in character cells, where (0, 0) is the
1929 upper-left corner of the frame, X is the horizontal offset, and Y is
1930 the vertical offset.
1932 This function is a no-op for an X frame that is not visible.
1933 If you have just created a frame, you must wait for it to become visible
1934 before calling this function on it, like this.
1935 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1936 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1938 CHECK_LIVE_FRAME (frame);
1939 CHECK_TYPE_RANGED_INTEGER (int, x);
1940 CHECK_TYPE_RANGED_INTEGER (int, y);
1942 /* I think this should be done with a hook. */
1943 #ifdef HAVE_WINDOW_SYSTEM
1944 if (FRAME_WINDOW_P (XFRAME (frame)))
1945 /* Warping the mouse will cause enternotify and focus events. */
1946 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1947 #else
1948 #if defined (MSDOS)
1949 if (FRAME_MSDOS_P (XFRAME (frame)))
1951 Fselect_frame (frame, Qnil);
1952 mouse_moveto (XINT (x), XINT (y));
1954 #else
1955 #ifdef HAVE_GPM
1957 Fselect_frame (frame, Qnil);
1958 term_mouse_moveto (XINT (x), XINT (y));
1960 #endif
1961 #endif
1962 #endif
1964 return Qnil;
1967 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1968 Sset_mouse_pixel_position, 3, 3, 0,
1969 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1970 The position is given in pixels, where (0, 0) is the upper-left corner
1971 of the frame, X is the horizontal offset, and Y is the vertical offset.
1973 Note, this is a no-op for an X frame that is not visible.
1974 If you have just created a frame, you must wait for it to become visible
1975 before calling this function on it, like this.
1976 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1977 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1979 CHECK_LIVE_FRAME (frame);
1980 CHECK_TYPE_RANGED_INTEGER (int, x);
1981 CHECK_TYPE_RANGED_INTEGER (int, y);
1983 /* I think this should be done with a hook. */
1984 #ifdef HAVE_WINDOW_SYSTEM
1985 if (FRAME_WINDOW_P (XFRAME (frame)))
1986 /* Warping the mouse will cause enternotify and focus events. */
1987 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1988 #else
1989 #if defined (MSDOS)
1990 if (FRAME_MSDOS_P (XFRAME (frame)))
1992 Fselect_frame (frame, Qnil);
1993 mouse_moveto (XINT (x), XINT (y));
1995 #else
1996 #ifdef HAVE_GPM
1998 Fselect_frame (frame, Qnil);
1999 term_mouse_moveto (XINT (x), XINT (y));
2001 #endif
2002 #endif
2003 #endif
2005 return Qnil;
2008 static void make_frame_visible_1 (Lisp_Object);
2010 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2011 0, 1, "",
2012 doc: /* Make the frame FRAME visible (assuming it is an X window).
2013 If omitted, FRAME defaults to the currently selected frame. */)
2014 (Lisp_Object frame)
2016 struct frame *f = decode_live_frame (frame);
2018 /* I think this should be done with a hook. */
2019 #ifdef HAVE_WINDOW_SYSTEM
2020 if (FRAME_WINDOW_P (f))
2021 x_make_frame_visible (f);
2022 #endif
2024 make_frame_visible_1 (f->root_window);
2026 /* Make menu bar update for the Buffers and Frames menus. */
2027 /* windows_or_buffers_changed = 15; FIXME: Why? */
2029 XSETFRAME (frame, f);
2030 return frame;
2033 /* Update the display_time slot of the buffers shown in WINDOW
2034 and all its descendants. */
2036 static void
2037 make_frame_visible_1 (Lisp_Object window)
2039 struct window *w;
2041 for (; !NILP (window); window = w->next)
2043 w = XWINDOW (window);
2044 if (WINDOWP (w->contents))
2045 make_frame_visible_1 (w->contents);
2046 else
2047 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2051 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2052 0, 2, "",
2053 doc: /* Make the frame FRAME invisible.
2054 If omitted, FRAME defaults to the currently selected frame.
2055 On graphical displays, invisible frames are not updated and are
2056 usually not displayed at all, even in a window system's \"taskbar\".
2058 Normally you may not make FRAME invisible if all other frames are invisible,
2059 but if the second optional argument FORCE is non-nil, you may do so.
2061 This function has no effect on text terminal frames. Such frames are
2062 always considered visible, whether or not they are currently being
2063 displayed in the terminal. */)
2064 (Lisp_Object frame, Lisp_Object force)
2066 struct frame *f = decode_live_frame (frame);
2068 if (NILP (force) && !other_visible_frames (f))
2069 error ("Attempt to make invisible the sole visible or iconified frame");
2071 /* Don't allow minibuf_window to remain on an invisible frame. */
2072 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2074 /* I think this should be done with a hook. */
2075 #ifdef HAVE_WINDOW_SYSTEM
2076 if (FRAME_WINDOW_P (f))
2077 x_make_frame_invisible (f);
2078 #endif
2080 /* Make menu bar update for the Buffers and Frames menus. */
2081 windows_or_buffers_changed = 16;
2083 return Qnil;
2086 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2087 0, 1, "",
2088 doc: /* Make the frame FRAME into an icon.
2089 If omitted, FRAME defaults to the currently selected frame. */)
2090 (Lisp_Object frame)
2092 struct frame *f = decode_live_frame (frame);
2094 /* Don't allow minibuf_window to remain on an iconified frame. */
2095 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2097 /* I think this should be done with a hook. */
2098 #ifdef HAVE_WINDOW_SYSTEM
2099 if (FRAME_WINDOW_P (f))
2100 x_iconify_frame (f);
2101 #endif
2103 /* Make menu bar update for the Buffers and Frames menus. */
2104 windows_or_buffers_changed = 17;
2106 return Qnil;
2109 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2110 1, 1, 0,
2111 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2112 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2113 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2114 On graphical displays, invisible frames are not updated and are
2115 usually not displayed at all, even in a window system's \"taskbar\".
2117 If FRAME is a text terminal frame, this always returns t.
2118 Such frames are always considered visible, whether or not they are
2119 currently being displayed on the terminal. */)
2120 (Lisp_Object frame)
2122 CHECK_LIVE_FRAME (frame);
2124 if (FRAME_VISIBLE_P (XFRAME (frame)))
2125 return Qt;
2126 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2127 return Qicon;
2128 return Qnil;
2131 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2132 0, 0, 0,
2133 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2134 (void)
2136 Lisp_Object tail, frame, value = Qnil;
2138 FOR_EACH_FRAME (tail, frame)
2139 if (FRAME_VISIBLE_P (XFRAME (frame)))
2140 value = Fcons (frame, value);
2142 return value;
2146 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2147 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2148 If FRAME is invisible or iconified, make it visible.
2149 If you don't specify a frame, the selected frame is used.
2150 If Emacs is displaying on an ordinary terminal or some other device which
2151 doesn't support multiple overlapping frames, this function selects FRAME. */)
2152 (Lisp_Object frame)
2154 struct frame *f = decode_live_frame (frame);
2156 XSETFRAME (frame, f);
2158 if (FRAME_TERMCAP_P (f))
2159 /* On a text terminal select FRAME. */
2160 Fselect_frame (frame, Qnil);
2161 else
2162 /* Do like the documentation says. */
2163 Fmake_frame_visible (frame);
2165 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2166 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2168 return Qnil;
2171 /* Should we have a corresponding function called Flower_Power? */
2172 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2173 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2174 If you don't specify a frame, the selected frame is used.
2175 If Emacs is displaying on an ordinary terminal or some other device which
2176 doesn't support multiple overlapping frames, this function does nothing. */)
2177 (Lisp_Object frame)
2179 struct frame *f = decode_live_frame (frame);
2181 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2182 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2184 return Qnil;
2188 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2189 1, 2, 0,
2190 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2191 In other words, switch-frame events caused by events in FRAME will
2192 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2193 FOCUS-FRAME after reading an event typed at FRAME.
2195 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2196 frame again receives its own keystrokes.
2198 Focus redirection is useful for temporarily redirecting keystrokes to
2199 a surrogate minibuffer frame when a frame doesn't have its own
2200 minibuffer window.
2202 A frame's focus redirection can be changed by `select-frame'. If frame
2203 FOO is selected, and then a different frame BAR is selected, any
2204 frames redirecting their focus to FOO are shifted to redirect their
2205 focus to BAR. This allows focus redirection to work properly when the
2206 user switches from one frame to another using `select-window'.
2208 This means that a frame whose focus is redirected to itself is treated
2209 differently from a frame whose focus is redirected to nil; the former
2210 is affected by `select-frame', while the latter is not.
2212 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2213 (Lisp_Object frame, Lisp_Object focus_frame)
2215 /* Note that we don't check for a live frame here. It's reasonable
2216 to redirect the focus of a frame you're about to delete, if you
2217 know what other frame should receive those keystrokes. */
2218 struct frame *f = decode_any_frame (frame);
2220 if (! NILP (focus_frame))
2221 CHECK_LIVE_FRAME (focus_frame);
2223 fset_focus_frame (f, focus_frame);
2225 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2226 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2228 return Qnil;
2232 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2233 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2234 If FRAME is omitted or nil, the selected frame is used.
2235 Return nil if FRAME's focus is not redirected.
2236 See `redirect-frame-focus'. */)
2237 (Lisp_Object frame)
2239 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2242 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2243 doc: /* Set the input focus to FRAME.
2244 FRAME nil means use the selected frame.
2245 If there is no window system support, this function does nothing. */)
2246 (Lisp_Object frame)
2248 #ifdef HAVE_WINDOW_SYSTEM
2249 x_focus_frame (decode_window_system_frame (frame));
2250 #endif
2251 return Qnil;
2255 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2257 void
2258 frames_discard_buffer (Lisp_Object buffer)
2260 Lisp_Object frame, tail;
2262 FOR_EACH_FRAME (tail, frame)
2264 fset_buffer_list
2265 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2266 fset_buried_buffer_list
2267 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2271 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2272 If the alist already has an element for PROP, we change it. */
2274 void
2275 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2277 register Lisp_Object tem;
2279 tem = Fassq (prop, *alistptr);
2280 if (EQ (tem, Qnil))
2281 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2282 else
2283 Fsetcdr (tem, val);
2286 static int
2287 frame_name_fnn_p (char *str, ptrdiff_t len)
2289 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2291 char *p = str + 2;
2292 while ('0' <= *p && *p <= '9')
2293 p++;
2294 if (p == str + len)
2295 return 1;
2297 return 0;
2300 /* Set the name of the terminal frame. Also used by MSDOS frames.
2301 Modeled after x_set_name which is used for WINDOW frames. */
2303 static void
2304 set_term_frame_name (struct frame *f, Lisp_Object name)
2306 f->explicit_name = ! NILP (name);
2308 /* If NAME is nil, set the name to F<num>. */
2309 if (NILP (name))
2311 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2313 /* Check for no change needed in this very common case
2314 before we do any consing. */
2315 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2316 return;
2318 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2320 else
2322 CHECK_STRING (name);
2324 /* Don't change the name if it's already NAME. */
2325 if (! NILP (Fstring_equal (name, f->name)))
2326 return;
2328 /* Don't allow the user to set the frame name to F<num>, so it
2329 doesn't clash with the names we generate for terminal frames. */
2330 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2331 error ("Frame names of the form F<num> are usurped by Emacs");
2334 fset_name (f, name);
2335 update_mode_lines = 16;
2338 void
2339 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2341 register Lisp_Object old_alist_elt;
2343 /* The buffer-list parameters are stored in a special place and not
2344 in the alist. All buffers must be live. */
2345 if (EQ (prop, Qbuffer_list))
2347 Lisp_Object list = Qnil;
2348 for (; CONSP (val); val = XCDR (val))
2349 if (!NILP (Fbuffer_live_p (XCAR (val))))
2350 list = Fcons (XCAR (val), list);
2351 fset_buffer_list (f, Fnreverse (list));
2352 return;
2354 if (EQ (prop, Qburied_buffer_list))
2356 Lisp_Object list = Qnil;
2357 for (; CONSP (val); val = XCDR (val))
2358 if (!NILP (Fbuffer_live_p (XCAR (val))))
2359 list = Fcons (XCAR (val), list);
2360 fset_buried_buffer_list (f, Fnreverse (list));
2361 return;
2364 /* If PROP is a symbol which is supposed to have frame-local values,
2365 and it is set up based on this frame, switch to the global
2366 binding. That way, we can create or alter the frame-local binding
2367 without messing up the symbol's status. */
2368 if (SYMBOLP (prop))
2370 struct Lisp_Symbol *sym = XSYMBOL (prop);
2371 start:
2372 switch (sym->redirect)
2374 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2375 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2376 case SYMBOL_LOCALIZED:
2377 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2378 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2379 swap_in_global_binding (sym);
2380 break;
2382 default: emacs_abort ();
2386 /* The tty color needed to be set before the frame's parameter
2387 alist was updated with the new value. This is not true any more,
2388 but we still do this test early on. */
2389 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2390 && f == FRAME_TTY (f)->previous_frame)
2391 /* Force redisplay of this tty. */
2392 FRAME_TTY (f)->previous_frame = NULL;
2394 /* Update the frame parameter alist. */
2395 old_alist_elt = Fassq (prop, f->param_alist);
2396 if (EQ (old_alist_elt, Qnil))
2397 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2398 else
2399 Fsetcdr (old_alist_elt, val);
2401 /* Update some other special parameters in their special places
2402 in addition to the alist. */
2404 if (EQ (prop, Qbuffer_predicate))
2405 fset_buffer_predicate (f, val);
2407 if (! FRAME_WINDOW_P (f))
2409 if (EQ (prop, Qmenu_bar_lines))
2410 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2411 else if (EQ (prop, Qname))
2412 set_term_frame_name (f, val);
2415 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2417 if (! MINI_WINDOW_P (XWINDOW (val)))
2418 error ("Surrogate minibuffer windows must be minibuffer windows");
2420 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2421 && !EQ (val, f->minibuffer_window))
2422 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2424 /* Install the chosen minibuffer window, with proper buffer. */
2425 fset_minibuffer_window (f, val);
2429 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2430 is not an unspecified foreground or background color. */
2432 static Lisp_Object
2433 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2435 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2436 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2437 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2438 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2441 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2442 doc: /* Return the parameters-alist of frame FRAME.
2443 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2444 The meaningful PARMs depend on the kind of frame.
2445 If FRAME is omitted or nil, return information on the currently selected frame. */)
2446 (Lisp_Object frame)
2448 Lisp_Object alist;
2449 struct frame *f = decode_any_frame (frame);
2450 int height, width;
2451 struct gcpro gcpro1;
2453 if (!FRAME_LIVE_P (f))
2454 return Qnil;
2456 alist = Fcopy_alist (f->param_alist);
2457 GCPRO1 (alist);
2459 if (!FRAME_WINDOW_P (f))
2461 Lisp_Object elt;
2463 /* If the frame's parameter alist says the colors are
2464 unspecified and reversed, take the frame's background pixel
2465 for foreground and vice versa. */
2466 elt = Fassq (Qforeground_color, alist);
2467 if (CONSP (elt) && STRINGP (XCDR (elt)))
2469 elt = frame_unspecified_color (f, XCDR (elt));
2470 if (!NILP (elt))
2471 store_in_alist (&alist, Qforeground_color, elt);
2473 else
2474 store_in_alist (&alist, Qforeground_color,
2475 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2476 elt = Fassq (Qbackground_color, alist);
2477 if (CONSP (elt) && STRINGP (XCDR (elt)))
2479 elt = frame_unspecified_color (f, XCDR (elt));
2480 if (!NILP (elt))
2481 store_in_alist (&alist, Qbackground_color, elt);
2483 else
2484 store_in_alist (&alist, Qbackground_color,
2485 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2486 store_in_alist (&alist, intern ("font"),
2487 build_string (FRAME_MSDOS_P (f)
2488 ? "ms-dos"
2489 : FRAME_W32_P (f) ? "w32term"
2490 :"tty"));
2492 store_in_alist (&alist, Qname, f->name);
2493 height = (f->new_height
2494 ? (f->new_pixelwise
2495 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2496 : f->new_height)
2497 : FRAME_LINES (f));
2498 store_in_alist (&alist, Qheight, make_number (height));
2499 width = (f->new_width
2500 ? (f->new_pixelwise
2501 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2502 : f->new_width)
2503 : FRAME_COLS (f));
2504 store_in_alist (&alist, Qwidth, make_number (width));
2505 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2506 store_in_alist (&alist, Qminibuffer,
2507 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2508 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2509 : FRAME_MINIBUF_WINDOW (f)));
2510 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2511 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2512 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2514 /* I think this should be done with a hook. */
2515 #ifdef HAVE_WINDOW_SYSTEM
2516 if (FRAME_WINDOW_P (f))
2517 x_report_frame_params (f, &alist);
2518 else
2519 #endif
2521 /* This ought to be correct in f->param_alist for an X frame. */
2522 Lisp_Object lines;
2523 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2524 store_in_alist (&alist, Qmenu_bar_lines, lines);
2527 UNGCPRO;
2528 return alist;
2532 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2533 doc: /* Return FRAME's value for parameter PARAMETER.
2534 If FRAME is nil, describe the currently selected frame. */)
2535 (Lisp_Object frame, Lisp_Object parameter)
2537 struct frame *f = decode_any_frame (frame);
2538 Lisp_Object value = Qnil;
2540 CHECK_SYMBOL (parameter);
2542 XSETFRAME (frame, f);
2544 if (FRAME_LIVE_P (f))
2546 /* Avoid consing in frequent cases. */
2547 if (EQ (parameter, Qname))
2548 value = f->name;
2549 #ifdef HAVE_X_WINDOWS
2550 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2551 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2552 #endif /* HAVE_X_WINDOWS */
2553 else if (EQ (parameter, Qbackground_color)
2554 || EQ (parameter, Qforeground_color))
2556 value = Fassq (parameter, f->param_alist);
2557 if (CONSP (value))
2559 value = XCDR (value);
2560 /* Fframe_parameters puts the actual fg/bg color names,
2561 even if f->param_alist says otherwise. This is
2562 important when param_alist's notion of colors is
2563 "unspecified". We need to do the same here. */
2564 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2565 value = frame_unspecified_color (f, value);
2567 else
2568 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2570 else if (EQ (parameter, Qdisplay_type)
2571 || EQ (parameter, Qbackground_mode))
2572 value = Fcdr (Fassq (parameter, f->param_alist));
2573 else
2574 /* FIXME: Avoid this code path at all (as well as code duplication)
2575 by sharing more code with Fframe_parameters. */
2576 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2579 return value;
2583 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2584 Smodify_frame_parameters, 2, 2, 0,
2585 doc: /* Modify the parameters of frame FRAME according to ALIST.
2586 If FRAME is nil, it defaults to the selected frame.
2587 ALIST is an alist of parameters to change and their new values.
2588 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2589 The meaningful PARMs depend on the kind of frame.
2590 Undefined PARMs are ignored, but stored in the frame's parameter list
2591 so that `frame-parameters' will return them.
2593 The value of frame parameter FOO can also be accessed
2594 as a frame-local binding for the variable FOO, if you have
2595 enabled such bindings for that variable with `make-variable-frame-local'.
2596 Note that this functionality is obsolete as of Emacs 22.2, and its
2597 use is not recommended. Explicitly check for a frame-parameter instead. */)
2598 (Lisp_Object frame, Lisp_Object alist)
2600 struct frame *f = decode_live_frame (frame);
2601 register Lisp_Object prop, val;
2603 CHECK_LIST (alist);
2605 /* I think this should be done with a hook. */
2606 #ifdef HAVE_WINDOW_SYSTEM
2607 if (FRAME_WINDOW_P (f))
2608 x_set_frame_parameters (f, alist);
2609 else
2610 #endif
2611 #ifdef MSDOS
2612 if (FRAME_MSDOS_P (f))
2613 IT_set_frame_parameters (f, alist);
2614 else
2615 #endif
2618 EMACS_INT length = XFASTINT (Flength (alist));
2619 ptrdiff_t i;
2620 Lisp_Object *parms;
2621 Lisp_Object *values;
2622 USE_SAFE_ALLOCA;
2623 SAFE_ALLOCA_LISP (parms, 2 * length);
2624 values = parms + length;
2626 /* Extract parm names and values into those vectors. */
2628 for (i = 0; CONSP (alist); alist = XCDR (alist))
2630 Lisp_Object elt;
2632 elt = XCAR (alist);
2633 parms[i] = Fcar (elt);
2634 values[i] = Fcdr (elt);
2635 i++;
2638 /* Now process them in reverse of specified order. */
2639 while (--i >= 0)
2641 prop = parms[i];
2642 val = values[i];
2643 store_frame_param (f, prop, val);
2645 if (EQ (prop, Qforeground_color)
2646 || EQ (prop, Qbackground_color))
2647 update_face_from_frame_parameter (f, prop, val);
2650 SAFE_FREE ();
2652 return Qnil;
2655 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2656 0, 1, 0,
2657 doc: /* Height in pixels of a line in the font in frame FRAME.
2658 If FRAME is omitted or nil, the selected frame is used.
2659 For a terminal frame, the value is always 1. */)
2660 (Lisp_Object frame)
2662 #ifdef HAVE_WINDOW_SYSTEM
2663 struct frame *f = decode_any_frame (frame);
2665 if (FRAME_WINDOW_P (f))
2666 return make_number (FRAME_LINE_HEIGHT (f));
2667 else
2668 #endif
2669 return make_number (1);
2673 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2674 0, 1, 0,
2675 doc: /* Width in pixels of characters in the font in frame FRAME.
2676 If FRAME is omitted or nil, the selected frame is used.
2677 On a graphical screen, the width is the standard width of the default font.
2678 For a terminal screen, the value is always 1. */)
2679 (Lisp_Object frame)
2681 #ifdef HAVE_WINDOW_SYSTEM
2682 struct frame *f = decode_any_frame (frame);
2684 if (FRAME_WINDOW_P (f))
2685 return make_number (FRAME_COLUMN_WIDTH (f));
2686 else
2687 #endif
2688 return make_number (1);
2691 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2692 Sframe_pixel_height, 0, 1, 0,
2693 doc: /* Return a FRAME's height in pixels.
2694 If FRAME is omitted or nil, the selected frame is used. The exact value
2695 of the result depends on the window-system and toolkit in use:
2697 In the Gtk+ version of Emacs, it includes only any window (including
2698 the minibuffer or echo area), mode line, and header line. It does not
2699 include the tool bar or menu bar.
2701 With other graphical versions, it also includes the tool bar and the
2702 menu bar.
2704 For a text terminal, it includes the menu bar. In this case, the
2705 result is really in characters rather than pixels (i.e., is identical
2706 to `frame-height'). */)
2707 (Lisp_Object frame)
2709 struct frame *f = decode_any_frame (frame);
2711 #ifdef HAVE_WINDOW_SYSTEM
2712 if (FRAME_WINDOW_P (f))
2713 return make_number (FRAME_PIXEL_HEIGHT (f));
2714 else
2715 #endif
2716 return make_number (FRAME_TOTAL_LINES (f));
2719 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2720 Sframe_pixel_width, 0, 1, 0,
2721 doc: /* Return FRAME's width in pixels.
2722 For a terminal frame, the result really gives the width in characters.
2723 If FRAME is omitted or nil, the selected frame is used. */)
2724 (Lisp_Object frame)
2726 struct frame *f = decode_any_frame (frame);
2728 #ifdef HAVE_WINDOW_SYSTEM
2729 if (FRAME_WINDOW_P (f))
2730 return make_number (FRAME_PIXEL_WIDTH (f));
2731 else
2732 #endif
2733 return make_number (FRAME_TOTAL_COLS (f));
2736 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2737 Stool_bar_pixel_width, 0, 1, 0,
2738 doc: /* Return width in pixels of FRAME's tool bar.
2739 The result is greater than zero only when the tool bar is on the left
2740 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2741 is used. */)
2742 (Lisp_Object frame)
2744 #ifdef FRAME_TOOLBAR_WIDTH
2745 struct frame *f = decode_any_frame (frame);
2747 if (FRAME_WINDOW_P (f))
2748 return make_number (FRAME_TOOLBAR_WIDTH (f));
2749 #endif
2750 return make_number (0);
2753 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2754 doc: /* Return width in columns of FRAME's text area. */)
2755 (Lisp_Object frame)
2757 return make_number (FRAME_COLS (decode_any_frame (frame)));
2760 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2761 doc: /* Return height in lines of FRAME's text area. */)
2762 (Lisp_Object frame)
2764 return make_number (FRAME_LINES (decode_any_frame (frame)));
2767 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2768 doc: /* Return number of total columns of FRAME. */)
2769 (Lisp_Object frame)
2771 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2774 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2775 doc: /* Return number of total lines of FRAME. */)
2776 (Lisp_Object frame)
2778 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2781 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2782 doc: /* Return text area width of FRAME in pixels. */)
2783 (Lisp_Object frame)
2785 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2788 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2789 doc: /* Return text area height of FRAME in pixels. */)
2790 (Lisp_Object frame)
2792 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2795 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2796 doc: /* Return scroll bar width of FRAME in pixels. */)
2797 (Lisp_Object frame)
2799 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2802 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2803 doc: /* Return scroll bar height of FRAME in pixels. */)
2804 (Lisp_Object frame)
2806 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2809 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2810 doc: /* Return fringe width of FRAME in pixels. */)
2811 (Lisp_Object frame)
2813 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2816 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2817 doc: /* Return border width of FRAME in pixels. */)
2818 (Lisp_Object frame)
2820 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2823 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2824 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2825 (Lisp_Object frame)
2827 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2830 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2831 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2832 (Lisp_Object frame)
2834 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2837 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2838 doc: /* Specify that the frame FRAME has HEIGHT text lines.
2839 Optional third arg PRETEND non-nil means that redisplay should use
2840 HEIGHT lines but that the idea of the actual height of the frame should
2841 not be changed. Optional fourth argument PIXELWISE non-nil means that
2842 FRAME should be HEIGHT pixels high. */)
2843 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2845 struct frame *f = decode_live_frame (frame);
2846 int pixel_height;
2848 CHECK_TYPE_RANGED_INTEGER (int, height);
2850 pixel_height = (!NILP (pixelwise)
2851 ? XINT (height)
2852 : XINT (height) * FRAME_LINE_HEIGHT (f));
2853 if (pixel_height != FRAME_TEXT_HEIGHT (f))
2854 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend));
2856 return Qnil;
2859 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2860 doc: /* Specify that the frame FRAME has WIDTH columns.
2861 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2862 columns but that the idea of the actual width of the frame should not
2863 be changed. Optional fourth argument PIXELWISE non-nil means that FRAME
2864 should be WIDTH pixels wide. */)
2865 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2867 struct frame *f = decode_live_frame (frame);
2868 int pixel_width;
2870 CHECK_TYPE_RANGED_INTEGER (int, width);
2872 pixel_width = (!NILP (pixelwise)
2873 ? XINT (width)
2874 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2875 if (pixel_width != FRAME_TEXT_WIDTH (f))
2876 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend));
2878 return Qnil;
2881 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2882 doc: /* Sets size of FRAME to WIDTH by HEIGHT, measured in characters.
2883 Optional argument PIXELWISE non-nil means to measure in pixels. */)
2884 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
2886 struct frame *f = decode_live_frame (frame);
2887 int pixel_width, pixel_height;
2889 CHECK_TYPE_RANGED_INTEGER (int, width);
2890 CHECK_TYPE_RANGED_INTEGER (int, height);
2892 pixel_width = (!NILP (pixelwise)
2893 ? XINT (width)
2894 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2895 pixel_height = (!NILP (pixelwise)
2896 ? XINT (height)
2897 : XINT (height) * FRAME_LINE_HEIGHT (f));
2899 if (pixel_width != FRAME_TEXT_WIDTH (f)
2900 || pixel_height != FRAME_TEXT_HEIGHT (f))
2901 adjust_frame_size (f, pixel_width, pixel_height, 1, 0);
2903 return Qnil;
2906 DEFUN ("set-frame-position", Fset_frame_position,
2907 Sset_frame_position, 3, 3, 0,
2908 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2909 If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2910 actually the position of the upper left corner of the frame. Negative
2911 values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2912 or bottommost possible position (that stays within the screen). */)
2913 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2915 register struct frame *f = decode_live_frame (frame);
2917 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2918 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2920 /* I think this should be done with a hook. */
2921 #ifdef HAVE_WINDOW_SYSTEM
2922 if (FRAME_WINDOW_P (f))
2923 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2924 #endif
2926 return Qt;
2930 /***********************************************************************
2931 Frame Parameters
2932 ***********************************************************************/
2934 /* Connect the frame-parameter names for X frames
2935 to the ways of passing the parameter values to the window system.
2937 The name of a parameter, as a Lisp symbol,
2938 has an `x-frame-parameter' property which is an integer in Lisp
2939 that is an index in this table. */
2941 struct frame_parm_table {
2942 const char *name;
2943 Lisp_Object *variable;
2946 static const struct frame_parm_table frame_parms[] =
2948 {"auto-raise", &Qauto_raise},
2949 {"auto-lower", &Qauto_lower},
2950 {"background-color", 0},
2951 {"border-color", &Qborder_color},
2952 {"border-width", &Qborder_width},
2953 {"cursor-color", &Qcursor_color},
2954 {"cursor-type", &Qcursor_type},
2955 {"font", 0},
2956 {"foreground-color", 0},
2957 {"icon-name", &Qicon_name},
2958 {"icon-type", &Qicon_type},
2959 {"internal-border-width", &Qinternal_border_width},
2960 {"right-divider-width", &Qright_divider_width},
2961 {"bottom-divider-width", &Qbottom_divider_width},
2962 {"menu-bar-lines", &Qmenu_bar_lines},
2963 {"mouse-color", &Qmouse_color},
2964 {"name", &Qname},
2965 {"scroll-bar-width", &Qscroll_bar_width},
2966 {"scroll-bar-height", &Qscroll_bar_height},
2967 {"title", &Qtitle},
2968 {"unsplittable", &Qunsplittable},
2969 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2970 {"horizontal-scroll-bars", &Qhorizontal_scroll_bars},
2971 {"visibility", &Qvisibility},
2972 {"tool-bar-lines", &Qtool_bar_lines},
2973 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2974 {"scroll-bar-background", &Qscroll_bar_background},
2975 {"screen-gamma", &Qscreen_gamma},
2976 {"line-spacing", &Qline_spacing},
2977 {"left-fringe", &Qleft_fringe},
2978 {"right-fringe", &Qright_fringe},
2979 {"wait-for-wm", &Qwait_for_wm},
2980 {"fullscreen", &Qfullscreen},
2981 {"font-backend", &Qfont_backend},
2982 {"alpha", &Qalpha},
2983 {"sticky", &Qsticky},
2984 {"tool-bar-position", &Qtool_bar_position},
2987 #ifdef HAVE_WINDOW_SYSTEM
2989 /* Change the parameters of frame F as specified by ALIST.
2990 If a parameter is not specially recognized, do nothing special;
2991 otherwise call the `x_set_...' function for that parameter.
2992 Except for certain geometry properties, always call store_frame_param
2993 to store the new value in the parameter alist. */
2995 void
2996 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
2998 Lisp_Object tail;
3000 /* If both of these parameters are present, it's more efficient to
3001 set them both at once. So we wait until we've looked at the
3002 entire list before we set them. */
3003 int width, height;
3004 bool width_change = 0, height_change = 0;
3006 /* Same here. */
3007 Lisp_Object left, top;
3009 /* Same with these. */
3010 Lisp_Object icon_left, icon_top;
3012 /* Record in these vectors all the parms specified. */
3013 Lisp_Object *parms;
3014 Lisp_Object *values;
3015 ptrdiff_t i, p;
3016 bool left_no_change = 0, top_no_change = 0;
3017 #ifdef HAVE_X_WINDOWS
3018 bool icon_left_no_change = 0, icon_top_no_change = 0;
3019 #endif
3020 struct gcpro gcpro1, gcpro2;
3022 i = 0;
3023 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3024 i++;
3026 parms = alloca (i * sizeof *parms);
3027 values = alloca (i * sizeof *values);
3029 /* Extract parm names and values into those vectors. */
3031 i = 0;
3032 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3034 Lisp_Object elt;
3036 elt = XCAR (tail);
3037 parms[i] = Fcar (elt);
3038 values[i] = Fcdr (elt);
3039 i++;
3041 /* TAIL and ALIST are not used again below here. */
3042 alist = tail = Qnil;
3044 GCPRO2 (*parms, *values);
3045 gcpro1.nvars = i;
3046 gcpro2.nvars = i;
3048 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
3049 because their values appear in VALUES and strings are not valid. */
3050 top = left = Qunbound;
3051 icon_left = icon_top = Qunbound;
3053 /* Process foreground_color and background_color before anything else.
3054 They are independent of other properties, but other properties (e.g.,
3055 cursor_color) are dependent upon them. */
3056 /* Process default font as well, since fringe widths depends on it. */
3057 for (p = 0; p < i; p++)
3059 Lisp_Object prop, val;
3061 prop = parms[p];
3062 val = values[p];
3063 if (EQ (prop, Qforeground_color)
3064 || EQ (prop, Qbackground_color)
3065 || EQ (prop, Qfont))
3067 register Lisp_Object param_index, old_value;
3069 old_value = get_frame_param (f, prop);
3070 if (NILP (Fequal (val, old_value)))
3072 store_frame_param (f, prop, val);
3074 param_index = Fget (prop, Qx_frame_parameter);
3075 if (NATNUMP (param_index)
3076 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3077 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3078 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3083 /* Now process them in reverse of specified order. */
3084 while (i-- != 0)
3086 Lisp_Object prop, val;
3088 prop = parms[i];
3089 val = values[i];
3091 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
3093 width_change = 1;
3094 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3096 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
3098 height_change = 1;
3099 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3101 else if (EQ (prop, Qtop))
3102 top = val;
3103 else if (EQ (prop, Qleft))
3104 left = val;
3105 else if (EQ (prop, Qicon_top))
3106 icon_top = val;
3107 else if (EQ (prop, Qicon_left))
3108 icon_left = val;
3109 else if (EQ (prop, Qforeground_color)
3110 || EQ (prop, Qbackground_color)
3111 || EQ (prop, Qfont))
3112 /* Processed above. */
3113 continue;
3114 else
3116 register Lisp_Object param_index, old_value;
3118 old_value = get_frame_param (f, prop);
3120 store_frame_param (f, prop, val);
3122 param_index = Fget (prop, Qx_frame_parameter);
3123 if (NATNUMP (param_index)
3124 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3125 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3126 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3130 /* Don't die if just one of these was set. */
3131 if (EQ (left, Qunbound))
3133 left_no_change = 1;
3134 if (f->left_pos < 0)
3135 left = list2 (Qplus, make_number (f->left_pos));
3136 else
3137 XSETINT (left, f->left_pos);
3139 if (EQ (top, Qunbound))
3141 top_no_change = 1;
3142 if (f->top_pos < 0)
3143 top = list2 (Qplus, make_number (f->top_pos));
3144 else
3145 XSETINT (top, f->top_pos);
3148 /* If one of the icon positions was not set, preserve or default it. */
3149 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3151 #ifdef HAVE_X_WINDOWS
3152 icon_left_no_change = 1;
3153 #endif
3154 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3155 if (NILP (icon_left))
3156 XSETINT (icon_left, 0);
3158 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3160 #ifdef HAVE_X_WINDOWS
3161 icon_top_no_change = 1;
3162 #endif
3163 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3164 if (NILP (icon_top))
3165 XSETINT (icon_top, 0);
3168 /* Don't set these parameters unless they've been explicitly
3169 specified. The window might be mapped or resized while we're in
3170 this function, and we don't want to override that unless the lisp
3171 code has asked for it.
3173 Don't set these parameters unless they actually differ from the
3174 window's current parameters; the window may not actually exist
3175 yet. */
3177 Lisp_Object frame;
3179 XSETFRAME (frame, f);
3181 if ((width_change && width != FRAME_TEXT_WIDTH (f))
3182 || (height_change && height != FRAME_TEXT_HEIGHT (f))
3183 || f->new_height || f->new_width)
3185 /* If necessary provide default values for HEIGHT and WIDTH. Do
3186 that here since otherwise a size change implied by an
3187 intermittent font change may get lost as in Bug#17142. */
3188 if (!width_change)
3189 width = (f->new_width
3190 ? (f->new_pixelwise
3191 ? f->new_width
3192 : (f->new_width * FRAME_COLUMN_WIDTH (f)))
3193 : FRAME_TEXT_WIDTH (f));
3195 if (!height_change)
3196 height = (f->new_height
3197 ? (f->new_pixelwise
3198 ? f->new_height
3199 : (f->new_height * FRAME_LINE_HEIGHT (f)))
3200 : FRAME_TEXT_HEIGHT (f));
3202 Fset_frame_size (frame, make_number (width), make_number (height), Qt);
3205 if ((!NILP (left) || !NILP (top))
3206 && ! (left_no_change && top_no_change)
3207 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3208 && NUMBERP (top) && XINT (top) == f->top_pos))
3210 int leftpos = 0;
3211 int toppos = 0;
3213 /* Record the signs. */
3214 f->size_hint_flags &= ~ (XNegative | YNegative);
3215 if (EQ (left, Qminus))
3216 f->size_hint_flags |= XNegative;
3217 else if (TYPE_RANGED_INTEGERP (int, left))
3219 leftpos = XINT (left);
3220 if (leftpos < 0)
3221 f->size_hint_flags |= XNegative;
3223 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3224 && CONSP (XCDR (left))
3225 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3227 leftpos = - XINT (XCAR (XCDR (left)));
3228 f->size_hint_flags |= XNegative;
3230 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3231 && CONSP (XCDR (left))
3232 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3234 leftpos = XINT (XCAR (XCDR (left)));
3237 if (EQ (top, Qminus))
3238 f->size_hint_flags |= YNegative;
3239 else if (TYPE_RANGED_INTEGERP (int, top))
3241 toppos = XINT (top);
3242 if (toppos < 0)
3243 f->size_hint_flags |= YNegative;
3245 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3246 && CONSP (XCDR (top))
3247 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3249 toppos = - XINT (XCAR (XCDR (top)));
3250 f->size_hint_flags |= YNegative;
3252 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3253 && CONSP (XCDR (top))
3254 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3256 toppos = XINT (XCAR (XCDR (top)));
3260 /* Store the numeric value of the position. */
3261 f->top_pos = toppos;
3262 f->left_pos = leftpos;
3264 f->win_gravity = NorthWestGravity;
3266 /* Actually set that position, and convert to absolute. */
3267 x_set_offset (f, leftpos, toppos, -1);
3269 #ifdef HAVE_X_WINDOWS
3270 if ((!NILP (icon_left) || !NILP (icon_top))
3271 && ! (icon_left_no_change && icon_top_no_change))
3272 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3273 #endif /* HAVE_X_WINDOWS */
3276 UNGCPRO;
3280 /* Insert a description of internally-recorded parameters of frame X
3281 into the parameter alist *ALISTPTR that is to be given to the user.
3282 Only parameters that are specific to the X window system
3283 and whose values are not correctly recorded in the frame's
3284 param_alist need to be considered here. */
3286 void
3287 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3289 Lisp_Object tem;
3290 uprintmax_t w;
3291 char buf[INT_BUFSIZE_BOUND (w)];
3293 /* Represent negative positions (off the top or left screen edge)
3294 in a way that Fmodify_frame_parameters will understand correctly. */
3295 XSETINT (tem, f->left_pos);
3296 if (f->left_pos >= 0)
3297 store_in_alist (alistptr, Qleft, tem);
3298 else
3299 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3301 XSETINT (tem, f->top_pos);
3302 if (f->top_pos >= 0)
3303 store_in_alist (alistptr, Qtop, tem);
3304 else
3305 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3307 store_in_alist (alistptr, Qborder_width,
3308 make_number (f->border_width));
3309 store_in_alist (alistptr, Qinternal_border_width,
3310 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3311 store_in_alist (alistptr, Qright_divider_width,
3312 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3313 store_in_alist (alistptr, Qbottom_divider_width,
3314 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3315 store_in_alist (alistptr, Qleft_fringe,
3316 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3317 store_in_alist (alistptr, Qright_fringe,
3318 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3319 store_in_alist (alistptr, Qscroll_bar_width,
3320 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3321 ? make_number (0)
3322 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3323 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3324 /* nil means "use default width"
3325 for non-toolkit scroll bar.
3326 ruler-mode.el depends on this. */
3327 : Qnil));
3328 store_in_alist (alistptr, Qscroll_bar_height,
3329 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3330 ? make_number (0)
3331 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3332 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3333 /* nil means "use default height"
3334 for non-toolkit scroll bar. */
3335 : Qnil));
3336 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3337 MS-Windows it returns a value whose type is HANDLE, which is
3338 actually a pointer. Explicit casting avoids compiler
3339 warnings. */
3340 w = (uintptr_t) FRAME_X_WINDOW (f);
3341 store_in_alist (alistptr, Qwindow_id,
3342 make_formatted_string (buf, "%"pMu, w));
3343 #ifdef HAVE_X_WINDOWS
3344 #ifdef USE_X_TOOLKIT
3345 /* Tooltip frame may not have this widget. */
3346 if (FRAME_X_OUTPUT (f)->widget)
3347 #endif
3348 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3349 store_in_alist (alistptr, Qouter_window_id,
3350 make_formatted_string (buf, "%"pMu, w));
3351 #endif
3352 store_in_alist (alistptr, Qicon_name, f->icon_name);
3353 store_in_alist (alistptr, Qvisibility,
3354 (FRAME_VISIBLE_P (f) ? Qt
3355 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3356 store_in_alist (alistptr, Qdisplay,
3357 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3359 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3360 tem = Qnil;
3361 else
3362 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3363 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3364 store_in_alist (alistptr, Qparent_id, tem);
3365 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3369 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3370 the previous value of that parameter, NEW_VALUE is the new value. */
3372 void
3373 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3375 if (NILP (new_value))
3376 f->want_fullscreen = FULLSCREEN_NONE;
3377 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3378 f->want_fullscreen = FULLSCREEN_BOTH;
3379 else if (EQ (new_value, Qfullwidth))
3380 f->want_fullscreen = FULLSCREEN_WIDTH;
3381 else if (EQ (new_value, Qfullheight))
3382 f->want_fullscreen = FULLSCREEN_HEIGHT;
3383 else if (EQ (new_value, Qmaximized))
3384 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3386 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3387 FRAME_TERMINAL (f)->fullscreen_hook (f);
3391 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3392 the previous value of that parameter, NEW_VALUE is the new value. */
3394 void
3395 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3397 if (NILP (new_value))
3398 f->extra_line_spacing = 0;
3399 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3400 f->extra_line_spacing = XFASTINT (new_value);
3401 else if (FLOATP (new_value))
3403 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3405 if (new_spacing >= 0)
3406 f->extra_line_spacing = new_spacing;
3407 else
3408 signal_error ("Invalid line-spacing", new_value);
3410 else
3411 signal_error ("Invalid line-spacing", new_value);
3412 if (FRAME_VISIBLE_P (f))
3413 redraw_frame (f);
3417 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3418 the previous value of that parameter, NEW_VALUE is the new value. */
3420 void
3421 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3423 Lisp_Object bgcolor;
3425 if (NILP (new_value))
3426 f->gamma = 0;
3427 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3428 /* The value 0.4545 is the normal viewing gamma. */
3429 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3430 else
3431 signal_error ("Invalid screen-gamma", new_value);
3433 /* Apply the new gamma value to the frame background. */
3434 bgcolor = Fassq (Qbackground_color, f->param_alist);
3435 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3437 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3438 if (NATNUMP (parm_index)
3439 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3440 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3441 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3442 (f, bgcolor, Qnil);
3445 Fclear_face_cache (Qnil);
3449 void
3450 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3452 Lisp_Object font_object;
3453 int fontset = -1;
3454 #ifdef HAVE_X_WINDOWS
3455 Lisp_Object font_param = arg;
3456 #endif
3458 /* Set the frame parameter back to the old value because we may
3459 fail to use ARG as the new parameter value. */
3460 store_frame_param (f, Qfont, oldval);
3462 /* ARG is a fontset name, a font name, a cons of fontset name and a
3463 font object, or a font object. In the last case, this function
3464 never fail. */
3465 if (STRINGP (arg))
3467 fontset = fs_query_fontset (arg, 0);
3468 if (fontset < 0)
3470 font_object = font_open_by_name (f, arg);
3471 if (NILP (font_object))
3472 error ("Font `%s' is not defined", SSDATA (arg));
3473 arg = AREF (font_object, FONT_NAME_INDEX);
3475 else if (fontset > 0)
3477 font_object = font_open_by_name (f, fontset_ascii (fontset));
3478 if (NILP (font_object))
3479 error ("Font `%s' is not defined", SDATA (arg));
3480 arg = AREF (font_object, FONT_NAME_INDEX);
3482 else
3483 error ("The default fontset can't be used for a frame font");
3485 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3487 /* This is the case that the ASCII font of F's fontset XCAR
3488 (arg) is changed to the font XCDR (arg) by
3489 `set-fontset-font'. */
3490 fontset = fs_query_fontset (XCAR (arg), 0);
3491 if (fontset < 0)
3492 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3493 font_object = XCDR (arg);
3494 arg = AREF (font_object, FONT_NAME_INDEX);
3495 #ifdef HAVE_X_WINDOWS
3496 font_param = Ffont_get (font_object, QCname);
3497 #endif
3499 else if (FONT_OBJECT_P (arg))
3501 font_object = arg;
3502 #ifdef HAVE_X_WINDOWS
3503 font_param = Ffont_get (font_object, QCname);
3504 #endif
3505 /* This is to store the XLFD font name in the frame parameter for
3506 backward compatibility. We should store the font-object
3507 itself in the future. */
3508 arg = AREF (font_object, FONT_NAME_INDEX);
3509 fontset = FRAME_FONTSET (f);
3510 /* Check if we can use the current fontset. If not, set FONTSET
3511 to -1 to generate a new fontset from FONT-OBJECT. */
3512 if (fontset >= 0)
3514 Lisp_Object ascii_font = fontset_ascii (fontset);
3515 Lisp_Object spec = font_spec_from_name (ascii_font);
3517 if (NILP (spec))
3518 signal_error ("Invalid font name", ascii_font);
3520 if (! font_match_p (spec, font_object))
3521 fontset = -1;
3524 else
3525 signal_error ("Invalid font", arg);
3527 if (! NILP (Fequal (font_object, oldval)))
3528 return;
3530 x_new_font (f, font_object, fontset);
3531 store_frame_param (f, Qfont, arg);
3532 #ifdef HAVE_X_WINDOWS
3533 store_frame_param (f, Qfont_param, font_param);
3534 #endif
3535 /* Recalculate toolbar height. */
3536 f->n_tool_bar_rows = 0;
3538 /* Ensure we redraw it. */
3539 clear_current_matrices (f);
3541 /* Attempt to hunt down bug#16028. */
3542 SET_FRAME_GARBAGED (f);
3544 recompute_basic_faces (f);
3546 do_pending_window_change (0);
3548 /* We used to call face-set-after-frame-default here, but it leads to
3549 recursive calls (since that function can set the `default' face's
3550 font which in turns changes the frame's `font' parameter).
3551 Also I don't know what this call is meant to do, but it seems the
3552 wrong way to do it anyway (it does a lot more work than what seems
3553 reasonable in response to a change to `font'). */
3557 void
3558 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3560 if (! NILP (new_value)
3561 && !CONSP (new_value))
3563 char *p0, *p1;
3565 CHECK_STRING (new_value);
3566 p0 = p1 = SSDATA (new_value);
3567 new_value = Qnil;
3568 while (*p0)
3570 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3571 if (p0 < p1)
3572 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3573 new_value);
3574 if (*p1)
3576 int c;
3578 while ((c = *++p1) && c_isspace (c));
3580 p0 = p1;
3582 new_value = Fnreverse (new_value);
3585 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3586 return;
3588 if (FRAME_FONT (f))
3589 free_all_realized_faces (Qnil);
3591 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3592 if (NILP (new_value))
3594 if (NILP (old_value))
3595 error ("No font backend available");
3596 font_update_drivers (f, old_value);
3597 error ("None of specified font backends are available");
3599 store_frame_param (f, Qfont_backend, new_value);
3601 if (FRAME_FONT (f))
3603 Lisp_Object frame;
3605 XSETFRAME (frame, f);
3606 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3607 ++face_change_count;
3608 windows_or_buffers_changed = 18;
3612 void
3613 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3615 int unit = FRAME_COLUMN_WIDTH (f);
3616 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3617 int new_width;
3619 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3620 ? eabs (XINT (new_value)) : 8);
3622 if (new_width != old_width)
3624 FRAME_LEFT_FRINGE_WIDTH (f) = new_width;
3625 FRAME_FRINGE_COLS (f) /* Round up. */
3626 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3628 if (FRAME_X_WINDOW (f) != 0)
3629 adjust_frame_size (f, -1, -1, 3, 0);
3631 SET_FRAME_GARBAGED (f);
3636 void
3637 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3639 int unit = FRAME_COLUMN_WIDTH (f);
3640 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3641 int new_width;
3643 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3644 ? eabs (XINT (new_value)) : 8);
3646 if (new_width != old_width)
3648 FRAME_RIGHT_FRINGE_WIDTH (f) = new_width;
3649 FRAME_FRINGE_COLS (f) /* Round up. */
3650 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3652 if (FRAME_X_WINDOW (f) != 0)
3653 adjust_frame_size (f, -1, -1, 3, 0);
3655 SET_FRAME_GARBAGED (f);
3660 void
3661 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3663 CHECK_TYPE_RANGED_INTEGER (int, arg);
3665 if (XINT (arg) == f->border_width)
3666 return;
3668 if (FRAME_X_WINDOW (f) != 0)
3669 error ("Cannot change the border width of a frame");
3671 f->border_width = XINT (arg);
3674 void
3675 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3677 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3679 CHECK_TYPE_RANGED_INTEGER (int, arg);
3680 FRAME_RIGHT_DIVIDER_WIDTH (f) = XINT (arg);
3681 if (FRAME_RIGHT_DIVIDER_WIDTH (f) < 0)
3682 FRAME_RIGHT_DIVIDER_WIDTH (f) = 0;
3683 if (FRAME_RIGHT_DIVIDER_WIDTH (f) != old)
3685 adjust_frame_size (f, -1, -1, 4, 0);
3686 adjust_frame_glyphs (f);
3687 SET_FRAME_GARBAGED (f);
3692 void
3693 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3695 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3697 CHECK_TYPE_RANGED_INTEGER (int, arg);
3698 FRAME_BOTTOM_DIVIDER_WIDTH (f) = XINT (arg);
3699 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) < 0)
3700 FRAME_BOTTOM_DIVIDER_WIDTH (f) = 0;
3701 if (FRAME_BOTTOM_DIVIDER_WIDTH (f) != old)
3703 adjust_frame_size (f, -1, -1, 4, 0);
3704 adjust_frame_glyphs (f);
3705 SET_FRAME_GARBAGED (f);
3709 void
3710 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3712 Lisp_Object frame;
3713 XSETFRAME (frame, f);
3715 if (NILP (value))
3716 Fmake_frame_invisible (frame, Qt);
3717 else if (EQ (value, Qicon))
3718 Ficonify_frame (frame);
3719 else
3720 Fmake_frame_visible (frame);
3723 void
3724 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3726 f->auto_raise = !EQ (Qnil, arg);
3729 void
3730 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3732 f->auto_lower = !EQ (Qnil, arg);
3735 void
3736 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3738 f->no_split = !NILP (arg);
3741 void
3742 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3744 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3745 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3746 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3747 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3749 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3750 = (NILP (arg)
3751 ? vertical_scroll_bar_none
3752 : EQ (Qleft, arg)
3753 ? vertical_scroll_bar_left
3754 : EQ (Qright, arg)
3755 ? vertical_scroll_bar_right
3756 : EQ (Qleft, Vdefault_frame_scroll_bars)
3757 ? vertical_scroll_bar_left
3758 : EQ (Qright, Vdefault_frame_scroll_bars)
3759 ? vertical_scroll_bar_right
3760 : vertical_scroll_bar_none);
3762 /* We set this parameter before creating the X window for the
3763 frame, so we can get the geometry right from the start.
3764 However, if the window hasn't been created yet, we shouldn't
3765 call x_set_window_size. */
3766 if (FRAME_X_WINDOW (f))
3767 adjust_frame_size (f, -1, -1, 3, 0);
3769 SET_FRAME_GARBAGED (f);
3773 void
3774 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3776 #if (defined (HAVE_WINDOW_SYSTEM) \
3777 && ((defined (USE_TOOLKIT_SCROLL_BARS) && !defined (HAVE_NS)) \
3778 || defined (HAVE_NTGUI)))
3779 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3780 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3782 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3784 /* We set this parameter before creating the X window for the
3785 frame, so we can get the geometry right from the start.
3786 However, if the window hasn't been created yet, we shouldn't
3787 call x_set_window_size. */
3788 if (FRAME_X_WINDOW (f))
3789 adjust_frame_size (f, -1, -1, 3, 0);
3791 SET_FRAME_GARBAGED (f);
3793 #endif
3796 void
3797 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3799 int unit = FRAME_COLUMN_WIDTH (f);
3801 if (NILP (arg))
3803 x_set_scroll_bar_default_width (f);
3805 if (FRAME_X_WINDOW (f))
3806 adjust_frame_size (f, -1, -1, 3, 0);
3808 SET_FRAME_GARBAGED (f);
3810 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3811 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3813 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3814 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3815 if (FRAME_X_WINDOW (f))
3816 adjust_frame_size (f, -1, -1, 3, 0);
3818 SET_FRAME_GARBAGED (f);
3821 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3822 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3825 void
3826 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3828 #if (defined (HAVE_WINDOW_SYSTEM) \
3829 && ((defined (USE_TOOLKIT_SCROLL_BARS) && !defined (HAVE_NS)) \
3830 || defined (HAVE_NTGUI)))
3831 int unit = FRAME_LINE_HEIGHT (f);
3833 if (NILP (arg))
3835 x_set_scroll_bar_default_height (f);
3837 if (FRAME_X_WINDOW (f))
3838 adjust_frame_size (f, -1, -1, 3, 0);
3840 SET_FRAME_GARBAGED (f);
3842 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3843 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3845 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3846 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3847 if (FRAME_X_WINDOW (f))
3848 adjust_frame_size (f, -1, -1, 3, 0);
3850 SET_FRAME_GARBAGED (f);
3853 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3854 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3855 #endif
3858 void
3859 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3861 double alpha = 1.0;
3862 double newval[2];
3863 int i;
3864 Lisp_Object item;
3866 for (i = 0; i < 2; i++)
3868 newval[i] = 1.0;
3869 if (CONSP (arg))
3871 item = CAR (arg);
3872 arg = CDR (arg);
3874 else
3875 item = arg;
3877 if (NILP (item))
3878 alpha = - 1.0;
3879 else if (FLOATP (item))
3881 alpha = XFLOAT_DATA (item);
3882 if (! (0 <= alpha && alpha <= 1.0))
3883 args_out_of_range (make_float (0.0), make_float (1.0));
3885 else if (INTEGERP (item))
3887 EMACS_INT ialpha = XINT (item);
3888 if (! (0 <= ialpha && alpha <= 100))
3889 args_out_of_range (make_number (0), make_number (100));
3890 alpha = ialpha / 100.0;
3892 else
3893 wrong_type_argument (Qnumberp, item);
3894 newval[i] = alpha;
3897 for (i = 0; i < 2; i++)
3898 f->alpha[i] = newval[i];
3900 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3901 block_input ();
3902 x_set_frame_alpha (f);
3903 unblock_input ();
3904 #endif
3906 return;
3909 #ifndef HAVE_NS
3911 /* Non-zero if mouse is grabbed on DPYINFO
3912 and we know the frame where it is. */
3914 bool x_mouse_grabbed (Display_Info *dpyinfo)
3916 return (dpyinfo->grabbed
3917 && dpyinfo->last_mouse_frame
3918 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
3921 /* Re-highlight something with mouse-face properties
3922 on DPYINFO using saved frame and mouse position. */
3924 void
3925 x_redo_mouse_highlight (Display_Info *dpyinfo)
3927 if (dpyinfo->last_mouse_motion_frame
3928 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
3929 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
3930 dpyinfo->last_mouse_motion_x,
3931 dpyinfo->last_mouse_motion_y);
3934 #endif /* HAVE_NS */
3936 /* Subroutines of creating an X frame. */
3938 /* Make sure that Vx_resource_name is set to a reasonable value.
3939 Fix it up, or set it to `emacs' if it is too hopeless. */
3941 void
3942 validate_x_resource_name (void)
3944 ptrdiff_t len = 0;
3945 /* Number of valid characters in the resource name. */
3946 ptrdiff_t good_count = 0;
3947 /* Number of invalid characters in the resource name. */
3948 ptrdiff_t bad_count = 0;
3949 Lisp_Object new;
3950 ptrdiff_t i;
3952 if (!STRINGP (Vx_resource_class))
3953 Vx_resource_class = build_string (EMACS_CLASS);
3955 if (STRINGP (Vx_resource_name))
3957 unsigned char *p = SDATA (Vx_resource_name);
3959 len = SBYTES (Vx_resource_name);
3961 /* Only letters, digits, - and _ are valid in resource names.
3962 Count the valid characters and count the invalid ones. */
3963 for (i = 0; i < len; i++)
3965 int c = p[i];
3966 if (! ((c >= 'a' && c <= 'z')
3967 || (c >= 'A' && c <= 'Z')
3968 || (c >= '0' && c <= '9')
3969 || c == '-' || c == '_'))
3970 bad_count++;
3971 else
3972 good_count++;
3975 else
3976 /* Not a string => completely invalid. */
3977 bad_count = 5, good_count = 0;
3979 /* If name is valid already, return. */
3980 if (bad_count == 0)
3981 return;
3983 /* If name is entirely invalid, or nearly so, or is so implausibly
3984 large that alloca might not work, use `emacs'. */
3985 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3987 Vx_resource_name = build_string ("emacs");
3988 return;
3991 /* Name is partly valid. Copy it and replace the invalid characters
3992 with underscores. */
3994 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3996 for (i = 0; i < len; i++)
3998 int c = SREF (new, i);
3999 if (! ((c >= 'a' && c <= 'z')
4000 || (c >= 'A' && c <= 'Z')
4001 || (c >= '0' && c <= '9')
4002 || c == '-' || c == '_'))
4003 SSET (new, i, '_');
4007 /* Get specified attribute from resource database RDB.
4008 See Fx_get_resource below for other parameters. */
4010 static Lisp_Object
4011 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4013 register char *value;
4014 char *name_key;
4015 char *class_key;
4017 CHECK_STRING (attribute);
4018 CHECK_STRING (class);
4020 if (!NILP (component))
4021 CHECK_STRING (component);
4022 if (!NILP (subclass))
4023 CHECK_STRING (subclass);
4024 if (NILP (component) != NILP (subclass))
4025 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4027 validate_x_resource_name ();
4029 /* Allocate space for the components, the dots which separate them,
4030 and the final '\0'. Make them big enough for the worst case. */
4031 name_key = alloca (SBYTES (Vx_resource_name)
4032 + (STRINGP (component)
4033 ? SBYTES (component) : 0)
4034 + SBYTES (attribute)
4035 + 3);
4037 class_key = alloca (SBYTES (Vx_resource_class)
4038 + SBYTES (class)
4039 + (STRINGP (subclass)
4040 ? SBYTES (subclass) : 0)
4041 + 3);
4043 /* Start with emacs.FRAMENAME for the name (the specific one)
4044 and with `Emacs' for the class key (the general one). */
4045 strcpy (name_key, SSDATA (Vx_resource_name));
4046 strcpy (class_key, SSDATA (Vx_resource_class));
4048 strcat (class_key, ".");
4049 strcat (class_key, SSDATA (class));
4051 if (!NILP (component))
4053 strcat (class_key, ".");
4054 strcat (class_key, SSDATA (subclass));
4056 strcat (name_key, ".");
4057 strcat (name_key, SSDATA (component));
4060 strcat (name_key, ".");
4061 strcat (name_key, SSDATA (attribute));
4063 value = x_get_string_resource (rdb, name_key, class_key);
4065 if (value && *value)
4066 return build_string (value);
4067 else
4068 return Qnil;
4072 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4073 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4074 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4075 class, where INSTANCE is the name under which Emacs was invoked, or
4076 the name specified by the `-name' or `-rn' command-line arguments.
4078 The optional arguments COMPONENT and SUBCLASS add to the key and the
4079 class, respectively. You must specify both of them or neither.
4080 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4081 and the class is `Emacs.CLASS.SUBCLASS'. */)
4082 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4083 Lisp_Object subclass)
4085 check_window_system (NULL);
4087 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4088 attribute, class, component, subclass);
4091 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4093 Lisp_Object
4094 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4095 Lisp_Object class, Lisp_Object component,
4096 Lisp_Object subclass)
4098 return xrdb_get_resource (dpyinfo->xrdb,
4099 attribute, class, component, subclass);
4102 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
4103 /* Used when C code wants a resource value. */
4104 /* Called from oldXMenu/Create.c. */
4105 char *
4106 x_get_resource_string (const char *attribute, const char *class)
4108 char *result;
4109 struct frame *sf = SELECTED_FRAME ();
4110 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4111 USE_SAFE_ALLOCA;
4113 /* Allocate space for the components, the dots which separate them,
4114 and the final '\0'. */
4115 char *name_key = SAFE_ALLOCA (invocation_namelen + strlen (attribute) + 2);
4116 char *class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2);
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_LISP ("default-frame-horizontal-scroll-bars", Vdefault_frame_horizontal_scroll_bars,
4876 doc: /* Default value for horizontal scroll bars on this window-system. */);
4877 #if (defined (HAVE_WINDOW_SYSTEM) \
4878 && ((defined (USE_TOOLKIT_SCROLL_BARS) && !defined (HAVE_NS)) \
4879 || defined (HAVE_NTGUI)))
4880 Vdefault_frame_horizontal_scroll_bars = Qt;
4881 #else
4882 Vdefault_frame_horizontal_scroll_bars = Qnil;
4883 #endif
4885 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
4886 scroll_bar_adjust_thumb_portion_p,
4887 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
4888 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
4889 even if the end of the buffer is shown (i.e. overscrolling).
4890 Set to nil if you want the thumb to be at the bottom when the end of the buffer
4891 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
4892 is visible. In this case you can not overscroll. */);
4893 scroll_bar_adjust_thumb_portion_p = 1;
4895 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4896 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4898 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4899 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4900 `mouse-position' calls this function, passing its usual return value as
4901 argument, and returns whatever this function returns.
4902 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4903 which need to do mouse handling at the Lisp level. */);
4904 Vmouse_position_function = Qnil;
4906 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4907 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4908 If the value is an integer, highlighting is only shown after moving the
4909 mouse, while keyboard input turns off the highlight even when the mouse
4910 is over the clickable text. However, the mouse shape still indicates
4911 when the mouse is over clickable text. */);
4912 Vmouse_highlight = Qt;
4914 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4915 doc: /* If non-nil, make pointer invisible while typing.
4916 The pointer becomes visible again when the mouse is moved. */);
4917 Vmake_pointer_invisible = Qt;
4919 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
4920 doc: /* Normal hook run when a frame gains input focus. */);
4921 Vfocus_in_hook = Qnil;
4922 DEFSYM (Qfocus_in_hook, "focus-in-hook");
4924 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
4925 doc: /* Normal hook run when a frame loses input focus. */);
4926 Vfocus_out_hook = Qnil;
4927 DEFSYM (Qfocus_out_hook, "focus-out-hook");
4929 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4930 doc: /* Functions run before deleting a frame.
4931 The functions are run with one arg, the frame to be deleted.
4932 See `delete-frame'.
4934 Note that functions in this list may be called just before the frame is
4935 actually deleted, or some time later (or even both when an earlier function
4936 in `delete-frame-functions' (indirectly) calls `delete-frame'
4937 recursively). */);
4938 Vdelete_frame_functions = Qnil;
4939 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4941 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4942 doc: /* Non-nil if Menu-Bar mode is enabled.
4943 See the command `menu-bar-mode' for a description of this minor mode.
4944 Setting this variable directly does not take effect;
4945 either customize it (see the info node `Easy Customization')
4946 or call the function `menu-bar-mode'. */);
4947 Vmenu_bar_mode = Qt;
4949 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4950 doc: /* Non-nil if Tool-Bar mode is enabled.
4951 See the command `tool-bar-mode' for a description of this minor mode.
4952 Setting this variable directly does not take effect;
4953 either customize it (see the info node `Easy Customization')
4954 or call the function `tool-bar-mode'. */);
4955 #ifdef HAVE_WINDOW_SYSTEM
4956 Vtool_bar_mode = Qt;
4957 #else
4958 Vtool_bar_mode = Qnil;
4959 #endif
4961 DEFVAR_LISP ("frame-initial-frame-tool-bar-height", Vframe_initial_frame_tool_bar_height,
4962 doc: /* Height of tool bar of initial frame. */);
4963 Vframe_initial_frame_tool_bar_height = make_number (0);
4965 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4966 doc: /* Minibufferless frames use this frame's minibuffer.
4967 Emacs cannot create minibufferless frames unless this is set to an
4968 appropriate surrogate.
4970 Emacs consults this variable only when creating minibufferless
4971 frames; once the frame is created, it sticks with its assigned
4972 minibuffer, no matter what this variable is set to. This means that
4973 this variable doesn't necessarily say anything meaningful about the
4974 current set of frames, or where the minibuffer is currently being
4975 displayed.
4977 This variable is local to the current terminal and cannot be buffer-local. */);
4979 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4980 doc: /* Non-nil if window system changes focus when you move the mouse.
4981 You should set this variable to tell Emacs how your window manager
4982 handles focus, since there is no way in general for Emacs to find out
4983 automatically. See also `mouse-autoselect-window'. */);
4984 focus_follows_mouse = 0;
4986 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
4987 doc: /* Non-nil means resize frames pixelwise.
4988 If this option is nil, resizing a frame rounds its sizes to the frame's
4989 current values of `frame-char-height' and `frame-char-width'. If this
4990 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
4991 by one pixel.
4993 With some window managers you may have to set this to non-nil in order
4994 to fully maximize frames. To resize your initial frame pixelwise, set
4995 this option to a non-nil value in your init file. */);
4996 frame_resize_pixelwise = 0;
4998 DEFVAR_BOOL ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
4999 doc: /* Non-nil means do not resize frame implicitly.
5000 If this option is nil, setting default font, menubar mode, fringe width,
5001 or scroll bar mode of a specific frame may resize the frame in order to
5002 preserve the number of columns or lines it displays. If this option is
5003 non-nil, no such resizing is done. */);
5004 frame_inhibit_implied_resize = 0;
5006 staticpro (&Vframe_list);
5008 defsubr (&Sframep);
5009 defsubr (&Sframe_live_p);
5010 defsubr (&Swindow_system);
5011 defsubr (&Smake_terminal_frame);
5012 defsubr (&Shandle_switch_frame);
5013 defsubr (&Sselect_frame);
5014 defsubr (&Sselected_frame);
5015 defsubr (&Sframe_list);
5016 defsubr (&Snext_frame);
5017 defsubr (&Sprevious_frame);
5018 defsubr (&Slast_nonminibuf_frame);
5019 defsubr (&Sdelete_frame);
5020 defsubr (&Smouse_position);
5021 defsubr (&Smouse_pixel_position);
5022 defsubr (&Sset_mouse_position);
5023 defsubr (&Sset_mouse_pixel_position);
5024 #if 0
5025 defsubr (&Sframe_configuration);
5026 defsubr (&Srestore_frame_configuration);
5027 #endif
5028 defsubr (&Smake_frame_visible);
5029 defsubr (&Smake_frame_invisible);
5030 defsubr (&Siconify_frame);
5031 defsubr (&Sframe_visible_p);
5032 defsubr (&Svisible_frame_list);
5033 defsubr (&Sraise_frame);
5034 defsubr (&Slower_frame);
5035 defsubr (&Sx_focus_frame);
5036 defsubr (&Sredirect_frame_focus);
5037 defsubr (&Sframe_focus);
5038 defsubr (&Sframe_parameters);
5039 defsubr (&Sframe_parameter);
5040 defsubr (&Smodify_frame_parameters);
5041 defsubr (&Sframe_char_height);
5042 defsubr (&Sframe_char_width);
5043 defsubr (&Sframe_pixel_height);
5044 defsubr (&Sframe_pixel_width);
5045 defsubr (&Sframe_text_cols);
5046 defsubr (&Sframe_text_lines);
5047 defsubr (&Sframe_total_cols);
5048 defsubr (&Sframe_total_lines);
5049 defsubr (&Sframe_text_width);
5050 defsubr (&Sframe_text_height);
5051 defsubr (&Sscroll_bar_width);
5052 defsubr (&Sscroll_bar_height);
5053 defsubr (&Sfringe_width);
5054 defsubr (&Sborder_width);
5055 defsubr (&Sright_divider_width);
5056 defsubr (&Sbottom_divider_width);
5057 defsubr (&Stool_bar_pixel_width);
5058 defsubr (&Sset_frame_height);
5059 defsubr (&Sset_frame_width);
5060 defsubr (&Sset_frame_size);
5061 defsubr (&Sset_frame_position);
5062 defsubr (&Sframe_pointer_visible_p);
5064 #ifdef HAVE_WINDOW_SYSTEM
5065 defsubr (&Sx_get_resource);
5066 defsubr (&Sx_parse_geometry);
5067 #endif